Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this x86 assembly instruction do (addsd xmm0, ds:__xmm@41f00000000000000000000000000000[edx*8])?

Tags:

x86

assembly

sse

Can someone explain what the following code does?

addsd   xmm0, ds:__xmm@41f00000000000000000000000000000[edx*8]

I figured that some value is added to float register xmm0, but what is the meaning of __xmm@41f00000000000000000000000000000 constant? Is there any documentation where I can read about it?

Here's the full fragment of code that I'm trying to understand:

cvtsi2sd xmm0, [ebp+var_2C8]
mov     edx, [ebp+var_2C8]
shr     edx, 1Fh
addsd   xmm0, ds:__xmm@41f00000000000000000000000000000[edx*8]

ebp+var_2C8 is unsigned integer value.

  1. ebp+var_2C8 is converted to float and moved to xmm0 register
  2. ebp+var_2C8 is moved to edx and right shifted by 31 bit
  3. something derived from this shifting is added to xmm0.

What exactly is added to xmm0? Is there a possible purpose to this calculation?

Update.
Here's the raw disassembly for this code:

cvtsi2sd    xmm0,dword ptr [ebp-2C8h]  
mov         edx,dword ptr [ebp-2C8h]  
shr         edx,1Fh  
addsd       xmm0,mmword ptr [edx*8+2685CC0h]  

Looks like some double value from array of constants is added to xmm0...

like image 697
leo Avatar asked Dec 16 '15 19:12

leo


People also ask

What is x86 assembly used for?

x86 assembly language is the name for the family of assembly languages which provide some level of backward compatibility with CPUs back to the Intel 8008 microprocessor, which was launched in April 1972. It is used to produce object code for the x86 class of processors.

What is MOV instruction x86?

mov — Move (Opcodes: 88, 89, 8A, 8B, 8C, 8E, ...) The mov instruction copies the data item referred to by its second operand (i.e. register contents, memory contents, or a constant value) into the location referred to by its first operand (i.e. a register or memory).

What does (% RBP mean in assembly?

%rbp is the base pointer, which points to the base of the current stack frame, and %rsp is the stack pointer, which points to the top of the current stack frame.

What is push in assembly language?

"push" stores a constant or 64-bit register out onto the stack. The 64-bit registers are the ones like "rax" or "r8", not the 32-bit registers like "eax" or "r8d". ("push eax" gives an error "instruction not supported in 64-bit mode"; use "push rax" instead.) "pop" retrieves the last value pushed from the stack.


1 Answers

This is the conversion of unsigned integer to double.

How it works is it first converts it as signed, meaning that the sign bit has a weight of -231, but it should be unsigned where the top bit has a weight of +231. So if the sign is set, it adds +232 = 4294967296.0 (41f0000000000000 as double) to compensate. It does so by shifting right, putting the top bit in the bottom bit and clearing everything else, and then it uses that as a table index into a table containing 0 and 4294967296.0.

like image 119
harold Avatar answered Sep 24 '22 15:09

harold