在 AVX x86 中将 int 转换为 double
Convert int to double in AVX x86
我有一个外部函数:
extern "C" void calculateAreaUnderCurve_(double startPoint, double endPoint, int numberOfTrapezes, double* coefficients, double* result);
我想在我的 .asm 文件中将 numberOfTrapezes
转换为 double
。
我试过:vcvtsi2sd
和 cvtsi2sd
但它不起作用。
编辑:
这是我的 .asm 文件
.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
我的函数调用:
int numberOfTrapezes=100;
//initialize other parameters
calculateAreaUnderCurve_(startPoint,endPoint,numberOfTrapezes, coefficients, &result);
结果我得到了一个奇怪的数字1.0761e+09
vmovsd xmm1,real8 ptr [ebp+8] ;xmm1 = startPoint
vmovsd xmm2,real8 ptr [ebp+16] ;xmm2 = endPoint
mov ebx, [ebp+20] ;ebx = numberOfTrapezez int value
您从错误的地址检索 numberOfTrapezez! endPoint占8个字节,所以把offset从20改成24.
mov ebx, [ebp+24]
还有
cvtsi2sd xmm3,dword [ebp+24] ;convert to double
我有一个外部函数:
extern "C" void calculateAreaUnderCurve_(double startPoint, double endPoint, int numberOfTrapezes, double* coefficients, double* result);
我想在我的 .asm 文件中将 numberOfTrapezes
转换为 double
。
我试过:vcvtsi2sd
和 cvtsi2sd
但它不起作用。
编辑:
这是我的 .asm 文件
.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
我的函数调用:
int numberOfTrapezes=100;
//initialize other parameters
calculateAreaUnderCurve_(startPoint,endPoint,numberOfTrapezes, coefficients, &result);
结果我得到了一个奇怪的数字1.0761e+09
vmovsd xmm1,real8 ptr [ebp+8] ;xmm1 = startPoint vmovsd xmm2,real8 ptr [ebp+16] ;xmm2 = endPoint mov ebx, [ebp+20] ;ebx = numberOfTrapezez int value
您从错误的地址检索 numberOfTrapezez! endPoint占8个字节,所以把offset从20改成24.
mov ebx, [ebp+24]
还有
cvtsi2sd xmm3,dword [ebp+24] ;convert to double