* バイナリサイズ比較
-(by [[K]], 2025.07.26)

** (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);
                 }
             }
         }
     }
 }
-このプログラムではintは32bit以上のビット幅を想定しています。

-wait()関数はミリ秒単位でsleepする関数ですが、sleepに入る前にグラフィックバッファをflushします(そういう仕様なのでコード内にflush関数の呼び出しはありません)。
-ff16Sqrt()やff16Sin()は下記のような動作をする関数です。
 int ff16Sqrt(int x) { return (int) (sqrt(x * (1.0 / 65536)) * 65536); }
 int ff16Sin(int x) { return (int) (sin(x * (2 * 3.14159265358979323 / 65536)) * 65536); }


** (2) 実験手順
 >gcc --version
 gcc (GCC) 3.4.5 (mingw-vista special r3)
 Copyright (C) 2004 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 >gcc -c -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バイト。

-実行ファイルは.textの情報だけからでは構築できないけれども、しかし大雑把には目安になると考えました。

** (3) 結果のまとめ
|RIGHT:124バイト|uck||2025.07.27版|
|||||
|RIGHT:356バイト|ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV) (たぶんThumb)|arm-linux-gnueabihf-gcc -c -Os -o a.o bench.c|arm-linux-gnueabihf-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0|
|RIGHT:425バイト|COFF OBJECT(14c:x86)|cl /O1 /Fobench.obj bench.c|Microsoft(R) C/C++ Optimizing Compiler Version 19.38.33135 for x86|
|RIGHT:504バイト|COFF OBJECT(8664:x64)|cl /O1 /Fobench.obj bench.c|Microsoft(R) C/C++ Optimizing Compiler Version 19.38.33135 for x64|
|RIGHT:521バイト|elf64-x86-64|gcc -m64 -c -Os bench.c|gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0|
|RIGHT:536バイト|pe-i386|gcc -c -Os 3dwave-bench.c|gcc (GCC) 3.4.5 (mingw-vista special r3)|
|RIGHT:544バイト|ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV)|aarch64-linux-gnu-gcc -c -Os -o a.o bench.c|aarch64-linux-gnu-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0|
|RIGHT:610バイト|elf32-i386|gcc -m32 -c -Os bench.c|gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0|

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS