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

Joe Groff arcata at gmail.com
Fri Jan 20 13:58:52 PST 2012


On Thu, Jan 19, 2012 at 10:39 AM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
> Alright.  We definitely don't want to model it as a general call, then.  Normal calls clobber lots of registers.
>
> The options are:
>
> 1. Use a pseudo-instruction that X86FloatingPoint understands and turns into a call after arranging for the argument to be in ST0.
>   You should emit:
>
>   %ST0 = COPY %vreg13; RFP80:%vreg13
>   %EAX, %EDX = FTOL2 %ST0<kill>
>   %vreg16 = COPY %EAX<kill>
>   %vreg17 = COPY %EDX<kill>
>
>   Then teach X86FloatingPoint that FTOL2 pops its argument, like FISTP64m.
>
> 2. Use inline asm. Which is pretty gross. You would need to construct a SelectionDAG node identical to the one produced by real inline asm. There should be some help in include/llvm/InlineAsm.h
>
> I am not sure which is worse, but if there are multiple libcalls like this, you should go with something like 1.
>
> Please investigate if there are other libcalls like this. If so, we should work out a proper solution instead of the inlineasm hack.

The integer runtime functions (_allmul, _alldiv, etc. for 64-bit
integer arithmetic) all appear to be straight-up stdcall. _ftol2 is
the only weird one. (There is an _ftol routine with the same calling
convention as _ftol2, but AFAIK it's only for backward compatibility
with older MSVC runtimes.) I'm far from an MSVC expert, though.

Are there any docs for X86FloatingPoint? At a glance the FISTP etc.
definitions look just like the FIST etc. definitions; where is the
stack handled?

-Joe




More information about the llvm-dev mailing list