バイナリサイズ比較
(1) これをコンパイルして(リンクはしないで).textのサイズを調べる。
//#include "kharc.h"
int openWin(int xsiz, int ysiz);
int isClose(int win);
void wait(int msec);
void fillRect(int w, int xsiz, int ysiz, int x, int y, int col);
void drawLine(int w, int x0, int y0, int x1, int y1, int col);
int ff16Sqrt(int x);
int ff16Sin(int x);
void wave()
{
int w, t, x, y, d, z, x0, y0, x1, y1, y0x0, y0x1, y1x0, y1x1, gx[1764], gy[1764];
w = openWin(640, 480);
for (t = 0; isClose(w) == 0; t++) {
wait(8); fillRect(w, 640, 480, 0, 0, 0x000000);
for (y1 = 0; y1 < 42; y1++) { y0 = y1 - 1; y = y0 - 19;
for (x1 = 0; x1 < 42; x1++) { x0 = x1 - 1; x = x0 - 19;
d = ff16Sqrt((x * x + y * y) * 65536);
z = ff16Sin(((d * 652) >> 12) - 1043 * t) * 50 / (d + 327680);
y0x0 = y0 * 42 + x0; y0x1 = y0 * 42 + x1; y1x0 = y1 * 42 + x0; y1x1 = y1 * 42 + x1;
gx[y1x1] = (x * 2 - y * 2 + z * 0) * 4 + 320;
gy[y1x1] = (x * 2 + y * 2 + z * 1) * 2 + 240;
if (x0 >= 0 && y0 >= 0) {
drawLine(w, gx[y0x0], gy[y0x0], gx[y0x1], gy[y0x1], 0x00ffff);
drawLine(w, gx[y0x0], gy[y0x0], gx[y1x0], gy[y1x0], 0x00ffff);
}
}
}
}
}
(2) 実験方法
>gcc -c -O3 -Os 3dwave-bench.c
>objdump -h 3dwave-bench.o
3dwave-bench.o: file format pe-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000218 00000000 00000000 0000008c 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 00000000 2**2
ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000000 2**2
ALLOC
- この場合、.textのサイズは0x218バイト。つまり536バイト。