Couple macs for size optimization.


;by the Svin.
movri macro reg,imm
if imm EQ 0
xor reg,reg
elseif imm EQ -1
or reg,-1
elseif imm LT -128
mov reg,imm
elseif imm GT 127
mov reg,imm
else
push imm
pop reg
endif
endm
movmi macro mem,imm
if imm EQ 0
and mem,0
elseif imm EQ -1
or mem,-1
else
mov mem,imm
endif
endm
Posted on 2003-09-14 16:46:22 by The Svin
movi macro memreg,imm

if imm EQ 0
if (OPATTR (memreg)) AND 00010000y
xor memreg,memreg
else
and memreg,0
endif
elseif imm EQ -1
or memreg,-1
elseif imm LT -128
mov memreg,imm
elseif imm GT 127
mov memreg,imm
else
push imm
pop memreg
endif
endm
Doesn't work with:
movi DWORD PTR [esp], 4
...but that is a small price.
Posted on 2003-09-14 18:19:15 by bitRAKE
Yeah, I should have added push\pop for mem too.
Saves 2 bytes if sign byte range.
Posted on 2003-09-14 18:39:55 by The Svin

Doesn't work with:
code:

movi DWORD PTR , 4

?!
Why.
push 4
pop
work exactly as mov dword ptr ,4
Posted on 2003-09-15 11:38:22 by The Svin
Hi, Svin and BitRAKE.
I have made a "movi" macro some time ago (same pourpose), but this one is much better. Mind if I add it to my macros.inc file?
Posted on 2003-09-15 17:18:24 by QvasiModo
I don't mind.
I sent it for anybody usage.
Posted on 2003-09-15 17:57:59 by The Svin
Great, thanks! :alright:
Posted on 2003-09-15 18:02:10 by QvasiModo


?!
Why.
push 4
pop
work exactly as mov dword ptr ,4
Yes, it does work. Thank you for the correction. First I was thinking POP would not work and was thinking about other sizes as well, like BYTE/WORD PTR.
Posted on 2003-09-15 20:26:38 by bitRAKE
It's possible to increase range for regs.
push x(-1+1) pop reg inc/dec reg
Though only 1 byte is saved.
What do you think?
Posted on 2003-09-16 12:37:48 by The Svin
Svin, that is certainly a savings, but my own work at size optimization can't include such general macros. I use macros to speed development, but size optimization is a slow process anyhow and must be done at a very low level, imho.
Posted on 2003-09-16 19:28:49 by bitRAKE
OK,
here is new one for regs with increase range
from 128 to -129


movri macro reg,imm

if (imm GT 128) or (imm LT -129)
mov reg,imm
elseif imm EQ 0
xor reg,reg
elseif (imm EQ 128)
push 127
pop reg
inc reg
elseif (imm EQ -129)
push -128
pop reg
dec reg
else
push imm
pop reg
endif

endm
Posted on 2003-09-18 09:03:29 by The Svin