Reverse Engineering for Beginners

(avery) #1
CHAPTER 27. WORKING WITH FLOATING POINT NUMBERS USING SIMD CHAPTER 27. WORKING WITH FLOATING POINT NUMBERS USING SIMD

Chapter 27


Working with floating point numbers using SIMD


Of course, theFPUhas remained in x86-compatible processors when theSIMDextensions were added.

TheSIMDextensions (SSE2) offer an easier way to work with floating-point numbers.

The number format remains the same (IEEE 754).

So, modern compilers (including those generating for x86-64) usually useSIMDinstructions instead of FPU ones.
It can be said that it’s good news, because it’s easier to work with them.

We are going to reuse the examples from the FPU section here:17 on page 205.

27.1 Simple example


#include <stdio.h>

double f (double a, double b)
{
return a/3.14 + b*4.1;
};

int main()
{
printf ("%f\n", f(1.2, 3.4));
};

27.1.1 x64


Listing 27.1: Optimizing MSVC 2012 x64
__real@4010666666666666 DQ 04010666666666666r ; 4.1
__real@40091eb851eb851f DQ 040091eb851eb851fr ; 3.14

a$ = 8
b$ = 16
f PROC
divsd xmm0, QWORD PTR __real@40091eb851eb851f
mulsd xmm1, QWORD PTR __real@4010666666666666
addsd xmm0, xmm1
ret 0
f ENDP

The input floating point values are passed in theXMM0-XMM3registers, all the rest—via the stack^1.

ais passed inXMM0,b—viaXMM1. The XMM-registers are 128-bit (as we know from the section aboutSIMD:25 on page 390),
but thedoublevalues are 64 bit, so only lower register half is used.

DIVSDis an SSE-instruction that stands for “Divide Scalar Double-Precision Floating-Point Values”, it just divides one value
of typedoubleby another, stored in the lower halves of operands.

(^1) MSDN: Parameter Passing

Free download pdf