www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/16/12:18:05

From: aho450s AT nic DOT smsu DOT edu (Tony O'Bryan)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Weird problem
Date: Sun, 16 Mar 1997 16:24:36 GMT
Organization: Southwest Missouri State University
Lines: 26
Message-ID: <332c1c1c.1840126@ursa.smsu.edu>
References: <33287185 DOT 892303 AT news DOT flash DOT net> <33287D83 DOT 63AD AT shoreland DOT com> <332aa0d0 DOT 1431214 AT ursa DOT smsu DOT edu> <5ggll4$6pb AT freenet-news DOT carleton DOT ca>
NNTP-Posting-Host: forseti.i71.smsu.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019