mathinline.h
001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020: #ifndef _MATH_H
021: # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
022: #endif
023:
024: #include <bits/wordsize.h>
025:
026: #ifndef __extern_always_inline
027: # define __MATH_INLINE __inline
028: #else
029: # define __MATH_INLINE __extern_always_inline
030: #endif
031:
032:
033:
034:
035: #if __GNUC_PREREQ (2, 8) && defined __USE_ISOC99
036: __BEGIN_NAMESPACE_C99
037:
038:
039: __MATH_INLINE int
040: __NTH (__signbitf (float __x))
041: {
042: # if __WORDSIZE == 32
043: __extension__ union { float __f; int __i; } __u = { __f: __x };
044: return __u.__i < 0;
045: # else
046: int __m;
047: __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
048: return __m & 0x8;
049: # endif
050: }
051: __MATH_INLINE int
052: __NTH (__signbit (double __x))
053: {
054: # if __WORDSIZE == 32
055: __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
056: return __u.__i[1] < 0;
057: # else
058: int __m;
059: __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
060: return __m & 0x80;
061: # endif
062: }
063: __MATH_INLINE int
064: __NTH (__signbitl (long double __x))
065: {
066: __extension__ union { long double __l; int __i[3]; } __u = { __l: __x };
067: return (__u.__i[2] & 0x8000) != 0;
068: }
069:
070: __END_NAMESPACE_C99
071: #endif
072:
073:
074: #if (__GNUC_PREREQ (2, 8) && !defined __NO_MATH_INLINES \
075: && defined __OPTIMIZE__)
076:
077: # ifdef __USE_ISOC99
078: __BEGIN_NAMESPACE_C99
079:
080:
081: # if __WORDSIZE == 64 || defined __SSE_MATH__
082: __MATH_INLINE long int
083: __NTH (lrintf (float __x))
084: {
085: long int __res;
086: __asm ("cvtss2si %1, %0" : "=r" (__res) : "xm" (__x));
087: return __res;
088: }
089: # endif
090: # if __WORDSIZE == 64 || defined __SSE2_MATH__
091: __MATH_INLINE long int
092: __NTH (lrint (double __x))
093: {
094: long int __res;
095: __asm ("cvtsd2si %1, %0" : "=r" (__res) : "xm" (__x));
096: return __res;
097: }
098: # endif
099: # if __WORDSIZE == 64
100: __MATH_INLINE long long int
101: __NTH (llrintf (float __x))
102: {
103: long long int __res;
104: __asm ("cvtss2si %1, %0" : "=r" (__res) : "xm" (__x));
105: return __res;
106: }
107: __MATH_INLINE long long int
108: __NTH (llrint (double __x))
109: {
110: long long int __res;
111: __asm ("cvtsd2si %1, %0" : "=r" (__res) : "xm" (__x));
112: return __res;
113: }
114: # endif
115:
116: # if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0 \
117: && (__WORDSIZE == 64 || defined __SSE2_MATH__)
118:
119: __MATH_INLINE float
120: __NTH (fmaxf (float __x, float __y))
121: {
122: __asm ("maxss %1, %0" : "+x" (__x) : "xm" (__y));
123: return __x;
124: }
125: __MATH_INLINE double
126: __NTH (fmax (double __x, double __y))
127: {
128: __asm ("maxsd %1, %0" : "+x" (__x) : "xm" (__y));
129: return __x;
130: }
131:
132:
133: __MATH_INLINE float
134: __NTH (fminf (float __x, float __y))
135: {
136: __asm ("minss %1, %0" : "+x" (__x) : "xm" (__y));
137: return __x;
138: }
139: __MATH_INLINE double
140: __NTH (fmin (double __x, double __y))
141: {
142: __asm ("minsd %1, %0" : "+x" (__x) : "xm" (__y));
143: return __x;
144: }
145: # endif
146:
147: __END_NAMESPACE_C99
148: # endif
149:
150: # if defined __SSE4_1__ && (__WORDSIZE == 64 || defined __SSE2_MATH__)
151: # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
152: __BEGIN_NAMESPACE_C99
153:
154:
155: __MATH_INLINE double
156: __NTH (rint (double __x))
157: {
158: double __res;
159: __asm ("roundsd $4, %1, %0" : "=x" (__res) : "xm" (__x));
160: return __res;
161: }
162: __MATH_INLINE float
163: __NTH (rintf (float __x))
164: {
165: float __res;
166: __asm ("roundss $4, %1, %0" : "=x" (__res) : "xm" (__x));
167: return __res;
168: }
169:
170: # ifdef __USE_ISOC99
171:
172: __MATH_INLINE double
173: __NTH (nearbyint (double __x))
174: {
175: double __res;
176: __asm ("roundsd $0xc, %1, %0" : "=x" (__res) : "xm" (__x));
177: return __res;
178: }
179: __MATH_INLINE float
180: __NTH (nearbyintf (float __x))
181: {
182: float __res;
183: __asm ("roundss $0xc, %1, %0" : "=x" (__res) : "xm" (__x));
184: return __res;
185: }
186: # endif
187:
188: __END_NAMESPACE_C99
189: # endif
190:
191: __BEGIN_NAMESPACE_STD
192:
193: __MATH_INLINE double
194: __NTH (ceil (double __x))
195: {
196: double __res;
197: __asm ("roundsd $2, %1, %0" : "=x" (__res) : "xm" (__x));
198: return __res;
199: }
200: __END_NAMESPACE_STD
201:
202: __BEGIN_NAMESPACE_C99
203: __MATH_INLINE float
204: __NTH (ceilf (float __x))
205: {
206: float __res;
207: __asm ("roundss $2, %1, %0" : "=x" (__res) : "xm" (__x));
208: return __res;
209: }
210: __END_NAMESPACE_C99
211:
212: __BEGIN_NAMESPACE_STD
213:
214: __MATH_INLINE double
215: __NTH (floor (double __x))
216: {
217: double __res;
218: __asm ("roundsd $1, %1, %0" : "=x" (__res) : "xm" (__x));
219: return __res;
220: }
221: __END_NAMESPACE_STD
222:
223: __BEGIN_NAMESPACE_C99
224: __MATH_INLINE float
225: __NTH (floorf (float __x))
226: {
227: float __res;
228: __asm ("roundss $1, %1, %0" : "=x" (__res) : "xm" (__x));
229: return __res;
230: }
231: __END_NAMESPACE_C99
232: # endif
233:
234: #endif
235:
© Andrew Scott 2006 -
2025,
All Rights Reserved