News for hackers. Stuff that matters.
Re:X86 Register Encoding by kr7 on Tuesday November 01, 2016 @03:43PM (#12849411)
> In fact, the average size of each instruction is almost exactly 4 bytes

I was curious about this claim so I wrote a quick and dirty perl script to test it out:

    vmlinuz-linux = 2.71957329365681
    bash          = 3.95324321387071
    firefox       = 3.56640365053712
    geany         = 3.44776119402985
    gzip          = 4.17925462998247
    perl          = 4.10894941634241
    python        = 3.82481751824818
    tar           = 3.93348845041101
    thunar        = 3.82471016115786
    radeon_drv.so = 4.02697782644402
Seems spot on, except for the kernel. I'm not sure why that has shorter instructions on average.

EDIT: I ran it on git too; average was 3.96747336803081. It seems Linus' x86 wizardry does not extend to userspace in this case.

Re:X86 Register Encoding by eloff on Tuesday November 01, 2016 @03:48PM (#12849454)
The kernel is compiled with -Os for code size last I checked (which was long ago) so that might explain the difference.
Re:X86 Register Encoding by a-priori on Tuesday November 01, 2016 @04:35PM (#12849796)
It's been about ten years since I did any kernel work, but last I checked Linux doesn't use most of the fancy features of the CPU to avoid trashing more registers than necessary. If you know you don't do any floating point operations, for example, you know you don't need to save/restore the floating point registers on interrupts. The same might go for things like SSE.

Those instructions tend to be larger, so it may partly explain the difference in average instruction size. The same explanation would apply to why the Radeon driver has a higher average.

Re:X86 Register Encoding by flamedoge on Wednesday November 02, 2016 @04:21AM (#12853015)
I wonder if that flag does anything at the instruction encoding level
Re:X86 Register Encoding by Flow on Wednesday November 02, 2016 @06:04AM (#12853345)
Interesting, would you mind sharing the script or give a short overview how it works?
Re:X86 Register Encoding by kr7 on Wednesday November 02, 2016 @12:46PM (#12856735)
Here it is (warning: Perl): http://pastebin.com/MFmDzY0g

It calls "objdump -d" on the binary, which is binutil's disassembler.

objdump prints each instruction out in the following format:

     5dc:       67 80 7d 00 00          cmpb   $0x0,0x0(%ebp)
The first part is the instruction offset; the second is the bytes that comprise the instruction; the third part is the instruction in AT&T assembly syntax.

The script uses regexs to cut off the front and back, then counts the number of bytes (in hex format) in the second part.

Then it calculates the average for all instructions.

Re:X86 Register Encoding by TheDauthi on Wednesday November 02, 2016 @05:53PM (#12859703)
Might I suggest http://pastebin.com/2PHXi78A instead? It handles a few bugs from the original, and cleans the nested loops.