[LLVMdev] Best way to interface with MSVC _ftol2 runtime function for fptoui?

Joe Groff arcata at gmail.com
Thu Jan 19 10:12:53 PST 2012


2012/1/19 Jakob Stoklund Olesen <stoklund at 2pi.dk>:
> How many of these libcalls do you need to implement? What exactly is the calling convention? Which registers are clobbered etc.

There is only one (that I know about so far). The MSVCRT `_ftol2`
function implements floating-point-to-unsigned conversion for i386
targets, and LLVM 3.0 calls it with the cdecl calling convention for
`fptoui to i64` when targeting i386-pc-win32. However, it has its own
calling convention: The input value is taken from ST0 and popped off
of the x87 stack, and the return value is given in EDX:EAX. EAX, EDX,
and ST0 are clobbered (the latter by popping the stack). The function
creates a stack frame. It messes with the x87 control word internally,
but the original control word is restored before returning.

-Joe



More information about the llvm-dev mailing list