From: "Anthony Q. Bachler" Newsgroups: comp.os.msdos.djgpp Subject: Re: Weird problem Date: 20 Mar 1997 20:02:28 GMT Organization: Apcad Engineering Lines: 47 Message-ID: <01bc3567$678e1680$LocalHost@anthonyb> References: <199703180157 DOT LAA23908 AT solwarra DOT gbrmpa DOT gov DOT au> NNTP-Posting-Host: 208.16.64.197 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Using int should not require an additional instruction on 80x86's because the processor can directly access the LSW of a 32-bit register directly. The MSW would need (an) extra instruction(s) though. EAX (32 bits)= 16 bits + AX (16 bits) AX = AH (8 bits) + AL (8 bits) To get the upper 16 bits of EAX you have to do either a bit shift (which is the fastest), or a word swap. The bitshift is faster but it is destructive to the lower word. A word swap is slower, but can be repeated to put EAX back in its original state. It is rumored that Intel has an undocumented feature that allows direct access to the upper word, but that they won't tell anybody how to do it except Micro$oft. -- ::-) ---------------------------------------------------------------------------- --- HTTP://vax2.rainis.net/~cwhizard/norn.htm Home of the Sixpak of Norns. To reply to a news posting, remove the anti-SPAM features from my e-mail address. Leath Muller wrote in article <199703180157 DOT LAA23908 AT solwarra DOT gbrmpa DOT gov DOT au>... > > 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? > > If you are running in 32 bit protected mode, any instructions that operate > on 16 bit operands require an instruction prefix and an extra cycle to > execute. If your running is 16 bit protected mode or real mode (not sure > about the real mode bit, never used it! ;) it has the same problem with > 32 bit operands. To make your code faster in 32 bit mode, use 32 bit and > 8 bit values, and in 16 bit code you would use 16 bit and 8 bit operands. > > Leathal. >