バイナリサイズ比較

(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, x1, y1, 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++) { y = y1 - 20;
            for (x1 = 0; x1 < 42; x1++) { x = x1 - 20;
                d = ff16Sqrt((x * x + y * y) * 65536);
                z = ff16Sin(((d * 652) >> 12) - 1043 * t) * 100 / (d + 327680);
                d = y1 * 42 + x1;
                gx[d] = (x * 8 - y * 8 + z * 0) + 320;
                gy[d] = (x * 4 + y * 4 + z * 1) + 240;
                if (x1 >= 1 && y1 >= 1) {
                    drawLine(w, gx[d - 43], gy[d - 43], gx[d - 42], gy[d - 42], 0x00ffff);
                    drawLine(w, gx[d - 43], gy[d - 43], gx[d -  1], gy[d -  1], 0x00ffff);
                }
            }
        }
    }
}

(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         000001e4  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

(3) 結果のまとめ

107バイトuck [ultra compact kharc: 超高密度の自作バイトコード](uckのみ、.textだけではなく全セクションを含んだ実行ファイルサイズ)2025.07.28版
276バイトarc-elf (HS)-g -Os -fno-builtin -fomit-frame-pointer -fno-inlineGNU C17 (GCC) version 11.5.0 (arc-elf)
286バイトthumb2-eabi-mthumb -mthumb-interwork -march=armv7-a -g -Os -fno-builtin -fomit-frame-pointer -fno-inlineGNU C17 (GCC) version 11.5.0 (arm-eabi)
307バイトWCOFF x86アセンブラ手書き →(4)参照(考察)手書きすれば 20% くらい削減できるというめやすを得た。
320バイトbfin-elf-g -Os -fno-builtin -fomit-frame-pointer -fno-inlineGNU C17 (GCC) version 11.5.0 (bfin-elf)
356バイトELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV) (たぶんThumb)arm-linux-gnueabihf-gcc -c -Os -o a.o bench.carm-linux-gnueabihf-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
383バイトi386-elf-OsGNU C17 (GCC) version 11.5.0
404バイトarm-eabi (armv4t)-mcpu=arm7tdmi -marm -march=armv4t -g -Os -fno-builtin -fomit-frame-pointer -fno-inlineGNU C17 (GCC) version 11.5.0 (arm-eabi)
436バイトaarch64-elf (armv8-a+crc)-mcmodel=large -mlittle-endian -mabi=lp64 -g -Os -fno-builtin -fomit-frame-pointer -fno-inlineGNU C17 (GCC) version 11.5.0 (aarch64-elf)
484バイトpe-i386gcc -c -Os 3dwave-bench.cgcc (GCC) 3.4.5 (mingw-vista special r3)
527バイトELF 64-bit LSB relocatable, x86-64, version 1 (SYSV)gcc -m64 -c -Os bench.cgcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
540バイトELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV)aarch64-linux-gnu-gcc -c -Os -o a.o bench.caarch64-linux-gnu-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
601バイトELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV)gcc -m32 -c -Os bench.cgcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
692バイトalpha-linux (ev4)-g -Os -fno-builtin -fomit-frame-pointer -fno-inlineGNU C17 (GCC) version 11.5.0 (alpha-linux)

(4) gccを使わずに、x86アセンブラ手書きで(1)のコードを作ってみた


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS