[SM91] Update to Spidermonkey 91.1.3 APIs
[0ad.git] / libraries / source / spidermonkey / FixFpNormIssue.diff
blobef4d4d96b6bbc7c9d031f6aff4c2668f2b62eef4
1 --- a/modules/fdlibm/src/math_private.h
2 +++ b/modules/fdlibm/src/math_private.h
3 @@ -30,8 +30,13 @@
4 * Adapted from https://github.com/freebsd/freebsd-src/search?q=__double_t
5 */
7 +#if defined __FLT_EVAL_METHOD__ && (__FLT_EVAL_METHOD__ == 2)
8 +typedef long double __double_t;
9 +#else
10 typedef double __double_t;
11 +#endif
12 typedef __double_t double_t;
13 +typedef float __float_t;
16 * The original fdlibm code used statements like:
17 @@ -630,6 +634,53 @@
18 return ((double)(x + 0x1.8p52) - 0x1.8p52);
21 +static inline float
22 +rnintf(__float_t x)
24 + /*
25 + * As for rnint(), except we could just call that to handle the
26 + * extra precision case, usually without losing efficiency.
27 + */
28 + return ((float)(x + 0x1.8p23F) - 0x1.8p23F);
31 +#ifdef LDBL_MANT_DIG
32 +/*
33 + * The complications for extra precision are smaller for rnintl() since it
34 + * can safely assume that the rounding precision has been increased from
35 + * its default to FP_PE on x86. We don't exploit that here to get small
36 + * optimizations from limiting the rangle to double. We just need it for
37 + * the magic number to work with long doubles. ld128 callers should use
38 + * rnint() instead of this if possible. ld80 callers should prefer
39 + * rnintl() since for amd64 this avoids swapping the register set, while
40 + * for i386 it makes no difference (assuming FP_PE), and for other arches
41 + * it makes little difference.
42 + */
44 +static inline long double
45 +rnintl(long double x)
47 + /* The WRAPPED__CONCAT() macro below is required for non-FreeBSD targets
48 + which don't have a multi-level CONCAT macro implementation. On those
49 + targets the hexadecimal floating-point values being created don't expand
50 + properly resulting in code that cannot be compiled.
52 + The extra level provided by this macro should not affect FreeBSD, should
53 + this code be used there.
55 + See the following for more details:
57 + https://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_3.html#SEC32
58 + https://sources.debian.org/src/glibc/2.32-3/misc/sys/cdefs.h/
59 + https://github.com/freebsd/freebsd-src/blob/main/sys/sys/cdefs.h
60 + */
61 + #define WRAPPED__CONCAT(x,y) __CONCAT(x,y)
63 + return (x + WRAPPED__CONCAT(0x1.8p, LDBL_MANT_DIG) / 2 -
64 + WRAPPED__CONCAT(0x1.8p, LDBL_MANT_DIG) / 2);
66 +#endif /* LDBL_MANT_DIG */
69 * irint() and i64rint() give the same result as casting to their integer
70 * return type provided their arg is a floating point integer. They can
71 @@ -646,6 +697,39 @@
72 #define irint(x) ((int)(x))
73 #endif
75 +#define i64rint(x) ((int64_t)(x)) /* only needed for ld128 so not opt. */
77 +#if defined(__i386__) && defined(__GNUCLIKE_ASM)
78 +static __inline int
79 +irintf(float x)
81 + int n;
83 + __asm("fistl %0" : "=m" (n) : "t" (x));
84 + return (n);
87 +static __inline int
88 +irintd(double x)
90 + int n;
92 + __asm("fistl %0" : "=m" (n) : "t" (x));
93 + return (n);
95 +#endif
97 +#if (defined(__amd64__) || defined(__i386__)) && defined(__GNUCLIKE_ASM)
98 +static __inline int
99 +irintl(long double x)
101 + int n;
103 + __asm("fistl %0" : "=m" (n) : "t" (x));
104 + return (n);
106 +#endif
108 #ifdef DEBUG
109 #if defined(__amd64__) || defined(__i386__)
110 #define breakpoint() asm("int $3")