Question

I know 1/2/4-byte integers are returned in eax, and 8-byte integers are returned in eax:edx.

By the way, how are 4/8/16-byte floating-point values (Maybe I remember long double might be 16 bytes..) returned in cdecl/stdcall?


Thanks to @MatteoItalia, I know that VC++'s long double is 8-byte; Then, how can I use 16-byte floating-point?

(Don't say me "just use 8 byte!". I really need it.)

Um, I think I should be satisfied with 10-byte floating point...

Was it helpful?

Solution

FP return values are returned in the ST0 x87 register (see e.g. here).

By the way, in VC++ long double (which in x87 is 80 bit) is effectively a synonym for double.

OTHER TIPS

You didn't provide the architecture but x86 returns floating-point values in ST(0) and x86_64 return in XMM0. See x86 calling conventions

But long double in VC for x86 and x86_64 is the same as double and won't provide you any more precision. So on Windows to do 80-bit floating-point operations you need to use another compiler such as GCC, Clang or ICC. Also, 80-bit long double is calculated by x87 so it may perform worse than a good SSE library.

If you need more than 10-byte long double then you must implement your own floating-point library or use some external libraries. GCC 4.3 and above have built-in support for __float128 through a soft library. See long double (GCC specific) and __float128

Another approach is using double-double to implement near-quadruple precision values like in PowerPC or SPARC. It's not IEEE compatible but you can utilize hardware double suport to speedup so it'll be faster than soft __float128

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top