The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: asmfan on March 06, 2006, 10:09:58 PM

Title: making a constant in a register
Post by: asmfan on March 06, 2006, 10:09:58 PM
hello,
here i would like you to post the different effective ways of setting registers ( ALU, FPU, MMX, XMM or others:) to a constant. as an example
xor R, R  ; set R to a zero (R=0)
or R, -1  ; set all bits in R
pcmpeq MMX, MMX  ; set all bits in mmx register
and all that kind.
everyone experienced is welcomed
Title: Re: making a constant in a register
Post by: zooba on March 07, 2006, 09:54:02 PM
I have found that in some cases,  mov R, -1 is faster than or R, -1. I believe this is since or requires that the the value or R be known which may cause stalls/etc.

Xor doesn't suffer from this because it has been special cased for setting a register to zero (since the original Pentium I think it was...)
Title: Re: making a constant in a register
Post by: dsouza123 on March 08, 2006, 01:04:53 AM
For the FPU from the Floating Point Help file

FLD1      Push 1.0 onto stack
FLDZ      Push 0.0 onto stack
FLDPI      Push pi onto stack
FLDL2E   Push base-2 log of e onto stack
FLDL2T   Push base-2 log of 10 onto stack
FLDLG2   Push base-10 log of 2 onto stack
FLDLN2   Push natural log of 2 onto stack