Mail Archives: djgpp/1997/03/16/12:18:05
On 16 Mar 1997 11:30:44 GMT, ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) wrote:
>But, an article on optimization informed me that using a 32-bit compiler
>like DJGPP, if you use shorts and such it adds a whole extra instruction
>for every operation in registers on the value in question, and that to
>speed up code use "int" instead. So I guess portability and optimization
>are sometimes exclusive?
In protected mode, the default register and word size are 32-bits. In real
mode, both are 16-bits. The '386+ processors use the same code sequence to
represent ax and eax. They also use the exact same code for 32-bit overrides
(from real mode) and 16-bit overrides (from protected mode). So to access a
16-bit memory address using ax from protected mode, an operand-size override is
needed. This override is 1 byte (66h) long and is included in the processor
prefetch cycle. It causes a delay from the processor's perspective (given that
the processor can see delays 1 nanosecond long *grin*), but won't cause an
appreciable delay for the user.
There is also the consideration of the target machines. If your program is
designed to not ever run in a 16-bit environment, then the whole point is really
pointless. :)
One practice I adopted after seeing it in other source code is to typedef all my
variable types. I change int to INT32, short to INT16, char to INT8, unsigned
int to UINT32, etc. If I ever need to recompile on a different architecture, I
just redefine INT32, UINT32 to whatever works best for the new environment.
- Raw text -