xref: /DragonOS/kernel/src/common/math/libm.h (revision 013ffb708fab7760ea999c1edf462c69ac68f0ac)
1 #pragma once
2 #include <common/sys/types.h>
3 
4 // ===== 描述long double 的数据比特结构
5 #if __LDBL_MANT_DIG__ == 53 && __LDBL_MAX_EXP__ == 1024
6 #elif __LDBL_MANT_DIG__ == 64 && __LDBL_MAX_EXP__ == 16384 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
7 union ldshape
8 {
9     long double f;
10     struct
11     {
12         uint64_t m;
13         uint16_t se;
14     } i;
15 };
16 #elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
17 union ldshape
18 {
19     long double f;
20     struct
21     {
22         uint64_t lo;
23         uint32_t mid;
24         uint16_t top;
25         uint16_t se;
26     } i;
27     struct
28     {
29         uint64_t lo;
30         uint64_t hi;
31     } i2;
32 };
33 #elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384 && __BYTE_ORDER__ == __BIG_ENDIAN
34 union ldshape
35 {
36     long double f;
37     struct
38     {
39         uint16_t se;
40         uint16_t top;
41         uint32_t mid;
42         uint64_t lo;
43     } i;
44     struct
45     {
46         uint64_t hi;
47         uint64_t lo;
48     } i2;
49 };
50 #else
51 #error Unsupported long double representation
52 #endif
53 
54 #define FORCE_EVAL(x)                         \
55     do                                        \
56     {                                         \
57         if (sizeof(x) == sizeof(float))       \
58         {                                     \
59             volatile float __x;               \
60             __x = (x);                        \
61             (void)__x;                        \
62         }                                     \
63         else if (sizeof(x) == sizeof(double)) \
64         {                                     \
65             volatile double __x;              \
66             __x = (x);                        \
67             (void)__x;                        \
68         }                                     \
69         else                                  \
70         {                                     \
71             volatile long double __x;         \
72             __x = (x);                        \
73             (void)__x;                        \
74         }                                     \
75     } while (0)
76