]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/fpu/math_private.h
Relax asm requirements for recently added x86-64 math interfaces
[thirdparty/glibc.git] / sysdeps / x86_64 / fpu / math_private.h
1 #ifndef _MATH_PRIVATE_H
2
3 #define math_opt_barrier(x) \
4 ({ __typeof(x) __x; \
5 if (sizeof (x) <= sizeof (double)) \
6 __asm ("" : "=x" (__x) : "0" (x)); \
7 else \
8 __asm ("" : "=t" (__x) : "0" (x)); \
9 __x; })
10 #define math_force_eval(x) \
11 do \
12 { \
13 if (sizeof (x) <= sizeof (double)) \
14 __asm __volatile ("" : : "x" (x)); \
15 else \
16 __asm __volatile ("" : : "f" (x)); \
17 } \
18 while (0)
19
20 #include <math/math_private.h>
21
22 /* We can do a few things better on x86-64. */
23
24 /* Direct movement of float into integer register. */
25 #undef EXTRACT_WORDS64
26 #define EXTRACT_WORDS64(i,d) \
27 do { \
28 long int i_; \
29 asm ("movd %1, %0" : "=rm" (i_) : "x" (d)); \
30 (i) = i_; \
31 } while (0)
32
33 /* And the reverse. */
34 #undef INSERT_WORDS64
35 #define INSERT_WORDS64(d,i) \
36 do { \
37 long int i_ = i; \
38 asm ("movd %1, %0" : "=x" (d) : "rm" (i_)); \
39 } while (0)
40
41 /* Direct movement of float into integer register. */
42 #undef GET_FLOAT_WORD
43 #define GET_FLOAT_WORD(i,d) \
44 do { \
45 int i_; \
46 asm ("movd %1, %0" : "=rm" (i_) : "x" (d)); \
47 (i) = i_; \
48 } while (0)
49
50 /* And the reverse. */
51 #undef SET_FLOAT_WORD
52 #define SET_FLOAT_WORD(d,i) \
53 do { \
54 int i_ = i; \
55 asm ("movd %1, %0" : "=x" (d) : "rm" (i_)); \
56 } while (0)
57
58 #endif
59
60 #define __isnan(d) \
61 ({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
62 (__di & 0x7fffffffffffffffl) > 0x7ff0000000000000l; })
63 #define __isnanf(d) \
64 ({ int __di; GET_FLOAT_WORD (__di, (float) d); \
65 (__di & 0x7fffffff) > 0x7f800000; })
66
67 #define __isinf_ns(d) \
68 ({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
69 (__di & 0x7fffffffffffffffl) == 0x7ff0000000000000l; })
70 #define __isinf_nsf(d) \
71 ({ int __di; GET_FLOAT_WORD (__di, (float) d); \
72 (__di & 0x7fffffff) == 0x7f800000; })
73
74 #define __finite(d) \
75 ({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
76 (__di & 0x7fffffffffffffffl) < 0x7ff0000000000000l; })
77 #define __finitef(d) \
78 ({ int __di; GET_FLOAT_WORD (__di, (float) d); \
79 (__di & 0x7fffffff) < 0x7f800000; })
80
81 #define __ieee754_sqrt(d) \
82 ({ double __res; \
83 asm ("sqrtsd %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
84 __res; })
85 #define __ieee754_sqrtf(d) \
86 ({ float __res; \
87 asm ("sqrtss %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
88 __res; })
89 #define __ieee754_sqrtl(d) \
90 ({ long double __res; \
91 asm ("fsqrt" : "=t" (__res) : "0" ((long double) (d))); \
92 __res; })
93
94 #ifdef __SSE4_1__
95 # ifndef __rint
96 # define __rint(d) \
97 ({ double __res; \
98 asm ("roundsd $4, %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
99 __res; })
100 # endif
101 # ifndef __rintf
102 # define __rintf(d) \
103 ({ float __res; \
104 asm ("roundss $4, %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
105 __res; })
106 # endif
107
108 # ifndef __floor
109 # define __floor(d) \
110 ({ double __res; \
111 asm ("roundsd $1, %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
112 __res; })
113 # endif
114 # ifndef __floorf
115 # define __floorf(d) \
116 ({ float __res; \
117 asm ("roundss $1, %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
118 __res; })
119 # endif
120 #endif