annotate src/build-msvctools/math/truncf.c @ 3061:f8299bb6c872

Initial support for native MSVC compilation. * add MSVC support files: compiler wrappers and support libraries * adapt libiconv to work with MSVC * adapt gettext to work with MSVC
author Michael Goffioul <michael.goffioul@gmail.com>
date Mon, 17 Jun 2013 22:43:11 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3061
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1 #include <fenv.h>
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2 #include <math.h>
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4 float
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
5 truncf (float _x)
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
6 {
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
7 float retval;
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
8 unsigned short saved_cw;
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
9 unsigned short tmp_cw;
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
10 __asm__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
11 tmp_cw = (saved_cw & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO))
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
12 | FE_TOWARDZERO;
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
13 __asm__ ("fldcw %0;" : : "m" (tmp_cw));
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
14 __asm__ ("frndint;" : "=t" (retval) : "0" (_x)); /* round towards zero */
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
15 __asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
16 return retval;
f8299bb6c872 Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
17 }