LMMS
Loading...
Searching...
No Matches
FPTruncateMode.h
Go to the documentation of this file.
1/* Copyright 2001-4 tim goetze <tim@quitte.de> -- see 'COPYING'. */
2
3/* Sets the FP rounding mode to 'truncate' in the constructor
4 * and loads the previous FP conrol word in the destructor.
5 *
6 * By directly using the machine instruction to convert float to int
7 * we avoid the performance hit that loading the control word twice for
8 * every (int) cast causes on i386.
9 *
10 * On other architectures this is a no-op.
11 */
12
13#ifndef _DSP_FP_TRUNCATE_MODE_H_
14#define _DSP_FP_TRUNCATE_MODE_H_
15
16#ifdef __i386__
17 #define fstcw(i) \
18 __asm__ __volatile__ ("fstcw %0" : "=m" (i))
19
20 #define fldcw(i) \
21 __asm__ __volatile__ ("fldcw %0" : : "m" (i))
22
23 /* gcc chokes on __volatile__ sometimes. */
24 #define fistp(f,i) \
25 __asm__ ("fistpl %0" : "=m" (i) : "t" (f) : "st")
26#else /* ! __i386__ */
27 #include <cstdint>
28
29 inline void fistp(float f, int32_t& i) { i = static_cast<int32_t>(f); }
30#endif
31
32namespace DSP {
33
35{
36 public:
37#ifdef __i386__
38 int cw0; /* fp control word */
39
41 {
42 fstcw (cw0);
43 const int cw1 = cw0 | 0xC00;
44 fldcw (cw1);
45 }
46
48 {
49 fldcw (cw0);
50 }
51#else
52 // Avoid warnings about unused variables
55#endif
56};
57
58} /* namespace DSP */
59
60#endif /* _DSP_FP_TRUNCATE_MODE_H_ */
void fistp(float f, int32_t &i)
Definition FPTruncateMode.h:29
FPTruncateMode()
Definition FPTruncateMode.h:53
~FPTruncateMode()
Definition FPTruncateMode.h:54
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
int int32_t
Definition mid.cpp:97
Definition BiQuad.h:31
#define void
Definition unzip.h:396