0

I have an external function:

extern "C" void calculateAreaUnderCurve_(double startPoint, double endPoint, int numberOfTrapezes, double* coefficients, double* result);

I'd like to convert numberOfTrapezes to a double in my .asm file.

I tried with: vcvtsi2sd and cvtsi2sd but It doesn't work.

Edit:

Here is my .asm file

.model flat,c    
.code

;   Function declatation:
;   int calculateAreaUnderCurve_(double startPoint, double endPoint, 
;   int numberOfTrapezes, double* coefficients, double* result);

calculateAreaUnderCurve_ proc
        push ebp
        mov ebp,esp

;   Load argument values
        vmovsd  xmm1,real8 ptr [ebp+8]      ;xmm1 = startPoint
        vmovsd  xmm2,real8 ptr [ebp+16]     ;xmm2 = endPoint
        mov     ebx, [ebp+20]               ;ebx  = numberOfTrapezez int value
        mov     eax, [ebp+28]               ;eax  = pointer to coefficients array
        mov     ecx, [ebp+32]               ;ecx  = pointer to result

        cvtsi2sd xmm3,dword [ebp+20]        ;convert to double
        movsd real8 ptr [ecx],xmm3          ;save result
        pop ebp
        ret
calculateAreaUnderCurve_ endp
        end

And my function call:

int numberOfTrapezes=100;
//initialize other parameters
calculateAreaUnderCurve_(startPoint,endPoint,numberOfTrapezes, coefficients, &result);

As a result i get strange number 1.0761e+09

kstanisz
  • 207
  • 3
  • 15
  • You probably crash from clobbering ebx. Just use `vcvtsi2sd` with a memory operand, if you're writing code for a crappy calling convention like 32bit x86 that passes args on the stack. – Peter Cordes May 28 '16 at 01:36
  • What CPU are you using ? `vcvtsi2sd` is AVX-512, not AVX. – Paul R May 28 '16 at 07:54
  • 1
    @PaulR I'd have another look at the instruction set reference if I were you. – EOF May 28 '16 at 09:58
  • I have updated my question with the full .asm file code and function call. – kstanisz May 28 '16 at 12:59
  • 1
    @EOF: hmm - must be a bug in the online intrinsics guide then: https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=vcvtsi2sd – Paul R May 28 '16 at 13:55
  • 1
    @PaulR: `vcvtsi2sd` is just the VEX-encoding [of the SSE2 instruction](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=cvtsi2sd). For some reason there are new intrinsics for the EVEX encoding of it without the rounding-control override, even though they still haven't changed the stupid semantics (merge into an existing reg, instead of zeroing the upper half to break the dependency chain for the common scalar use-case). – Peter Cordes May 28 '16 at 14:05

1 Answers1

7
vmovsd  xmm1,real8 ptr [ebp+8]      ;xmm1 = startPoint
vmovsd  xmm2,real8 ptr [ebp+16]     ;xmm2 = endPoint
mov     ebx, [ebp+20]               ;ebx  = numberOfTrapezez int value

You are retrieving the numberOfTrapezez from the wrong address! The endPoint occupies 8 bytes, so change the offset from 20 to 24.

mov ebx, [ebp+24]

and also

cvtsi2sd xmm3,dword [ebp+24]        ;convert to double
Fifoernik
  • 9,779
  • 1
  • 21
  • 27