This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: Idea for code size reduction


Hello everybody,

I have a feature request.


I'd like to (manually) define some byte blocks, eg. as functions with an
identifier.  Then, if GCC would emit exactly these bytes, it puts a JMP
identifier there instead.

This would help by sharing many identical (text/code) byte sequences, to
make a smaller image - like -fmerge-constants does for data - and therefor
helps for cache locality, too.


I wrote some perl scripts to test this.  I took a "alldefconfig" i686
kernel, let objdump disassemble it, and on "iret", "ret", "ljmp" or "jmp"
with a 4 byte address I store the last few bytes.  Another script goes
through these block-ends, and estimates the number of bytes saved, if
identical sequences get changed into a 5 byte opcode (jump with 32bit
address).


The original kernel has
  $ size vmlinux
     text    data     bss     dec     hex  filename
   4802166  446554  606208 5854928  5956d0 vmlinux

and my scripts emit space savings of about 30kB.  Now that's not
that much, but for embedded systems it means another userspace
binary more.
  [ If anyone's interested, I can post my scripts here ... they're not
    that large. ]

And, of course, the same can be used for other binaries too - which could
save other space as well.  (blender-bin, text size 8664025, gives 97KB
savings)


I'd imagine the use that such:
- Built the binary
- Run my scripts, to find some common code sequences
- Give them to gcc
- Rebuild, using the optimizations

I don't know whether some new optimize switch could be used, to do all
that internally in the compiler and linker.


What do you think about that?
[ Please keep at least *me* cc'ed - don't know whether that's that
  interesting for linux-tiny. ]


Regards,

Phil


-- 
Versioning your /etc, /home or even your whole installation?
             Try fsvs (fsvs.tigris.org)!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]