update for HEAD-2003050101
[reactos.git] / lib / ntdll / rtl / i386 / ftol.c
1 /* $Id$
2  *
3  * COPYRIGHT:         See COPYING in the top level directory
4  * PROJECT:           ReactOS kernel
5  * PURPOSE:           Security manager
6  * FILE:              lib/ntdll/rtl/i386/ftol.c
7  * PROGRAMER:         Ge van Geldorp (ge@gse.nl)
8  * REVISION HISTORY:  2003/04/24 Created
9  */
10
11 /*
12  * This routine is called by MSVC-generated code to convert from floating point
13  * to integer representation. The floating point number to be converted is
14  * on the top of the floating point stack.
15  */
16 long long __cdecl _ftol(void)
17 {
18   unsigned short cw_orig;
19   unsigned short cw_round_chop;
20   long long ll;
21
22   /* Set "round towards zero" mode */
23   __asm__("fstcw %0\n\t" : "=m" (cw_orig));
24   __asm__("fwait\n\t");
25   cw_round_chop = cw_orig | 0x0c00;
26   __asm__("fldcw %0\n\t" : : "m" (cw_round_chop));
27
28   /* Do the actual conversion */
29   __asm__("fistpq %0\n\t" : "=m" (ll) );
30
31   /* And restore the rounding mode */
32   __asm__("fldcw %0\n\t" : : "m" (cw_orig));
33
34   return ll;
35 }