To view parent comment, click here.
To read all comments associated with this story, please click here.
In languages that don't suck
Ohh, can you show the list here?
it's quite useful to have quick access to various global data structures, often utilized by the runtime.
I don't think this is a clever solution.
Anyway RISCy solution for this is Global Pointer.
Actually the lack of global pointer and absolute addressing forces to use various tricks to enable reentrant code with global variables.
However, the x86-way of handling immediates is a lot cleaner than the typical RISC-y
If you need (most likely) to operate on full register width on x86-64, immediate will be 32 or 64bit, even if only few bits are used.
8B0425 01000000 movl 1, %eax
030425 9CFFFFFF addl -100, %eax
4C8B1425 01000000 movq 1, %r10
4C031425 9CFFFFFF addq -100, %r10
In every case of small immediate, RISC instruction is twice as small.
Edited 2007-05-23 21:47
Ohh, can you show the list here?
ML, Lisp, Smalltalk, dozens of others. Generally, there is a pretty strong correlation between "not sucking" and needing extensive runtime support services.
If you need (most likely) to operate on full register width on x86-64, immediate will be 32 or 64bit, even if only few bits are used.
Most x86 instructions have a form that sign-extends an 8-bit immediate. MOV doesn't, but loading a small immediate is an uncommon operation in an ISA in which almost all arithmetic instructions take general immediate operands.
Your examples are all very poorly encoded. You've got unnecessary modrm and sib bytes in there.
8B0425 01000000 movl 1, %eax
My assembler gives B8 01 00 00 00 (5 bytes)
030425 9CFFFFFF addl -100, %eax
I get 83 C0 9C (3 bytes)
4C8B1425 01000000 movq 1, %r10
My assembler gives 49 BA 01 00 00 00 00 00 00 00 (10 bytes), but there is a 7 byte encoding (I should fix that).
4C031425 9CFFFFFF addq -100, %r10
49 83 C2 9C (4 bytes)







Member since:
2005-07-06
Globals are rarely used in any sane c++ code.
And of course C++ is the only programming language anybody ever uses...
In languages that don't suck, it's quite useful to have quick access to various global data structures, often utilized by the runtime.
That said, full-size immediates are not always needed. However, the x86-way of handling immediates is a lot cleaner than the typical RISC-y "load 13 bits of a register at a time" method.