Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move a floating-point constant value into an xmm register?

Tags:

x86

assembly

sse

Is the only way to move a value into an xmm register by first moving the value into an integer register, dunno what they are called, and then into the xmm register e.g.

mov   [eax], (float)1000   ; store to memory
movss xmm1,[eax]           ; reload

or

mov        eax,  1000       ; move-immediate integer
cvtsi2ss   xmm1,eax         ; and convert

or is there another way? Is there a way to directly move a value into a xmm register, something along the lines of: movss xmm1,(float)1000?

like image 749
JazzEX Avatar asked Dec 22 '17 19:12

JazzEX


2 Answers

There are no instructions to load an SSE register with an immediate. The common idiom is to load the value you need from a global constant:

const   dd 1000.0

...

        movss xmm0,[const]
like image 150
fuz Avatar answered Oct 23 '22 11:10

fuz


It depends on the assembler.

UASM:

LOADSS xmm1,1000.0

ASMC, FASM, POASM, JWasm:

mov eax,1000.0
movd xmm1,eax

NASM:

mov eax,__?float32?__(1000.0)
movd xmm1,eax

MASM, YASM, Sol_Asm:

mov eax,447A0000h
movd xmm1,eax

You can also use a macro which creates constants in the data section. UASM already has a built-in macro FP4:

movss xmm1,FP4(1000.0)

If you use ASMC, POASM, JWasm or MASM, you can define this macro:

FP4 MACRO value
 LOCAL vname
 .const
 align 4
 vname REAL4 value
 .code
 EXITM <vname>
ENDM
like image 40
palota Avatar answered Oct 23 '22 12:10

palota