问题描述
在MSVC win32 / win64中,扩展精度浮点(80位值,在某些编译器中也称为long double)转换为double(64位)的最便携和正确方式是什么? MSVC目前(截至2010年)假设long double是double的同义词。
我可能可以在内联asm编写fld / fstp汇编程序对,但内联asm不适用于MSVC中的win64代码。我是否需要将此汇编程序代码移到单独的.asm文件中?这真的是没有好的解决方案吗?
$ b
.686P
.XMM
_TEXT SEGMENT
EXTRN __fltused:DWORD
PUBLIC _cvt80to64
PUBLIC _cvt64to80
_cvt80to64 PROC
mov eax,dword ptr [esp + 4]
fld TBYTE PTR [ eax]
ret 0
_cvt80to64 ENDP
_cvt64to80 PROC
mov eax,DWORD PTR [esp + 12]
fld QWORD PTR [esp + 4]
fstp TBYTE PTR [eax]
ret 0
_cvt64to80 ENDP
ENDIF
_TEXT
END
What is the most portable and "right" way to do conversion from extended precision float (80-bit value, also known as "long double" in some compilers) to double (64-bit) in MSVC win32/win64?
MSVC currently (as of 2010) assumes that "long double" is "double" synonym.
I could probably write fld/fstp assembler pair in inline asm, but inline asm is not available for win64 code in MSVC. Do I need to move this assembler code to separate .asm file? Is that really so there are no good solution?
Just did this in x86 code...
.686P
.XMM
_TEXT SEGMENT
EXTRN __fltused:DWORD
PUBLIC _cvt80to64
PUBLIC _cvt64to80
_cvt80to64 PROC
mov eax, dword ptr [esp+4]
fld TBYTE PTR [eax]
ret 0
_cvt80to64 ENDP
_cvt64to80 PROC
mov eax, DWORD PTR [esp+12]
fld QWORD PTR [esp+4]
fstp TBYTE PTR [eax]
ret 0
_cvt64to80 ENDP
ENDIF
_TEXT ENDS
END
这篇关于MSVC win32:将扩展精度浮点数(80位)转换为双精度(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!