1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #ifndef _FP_EMU_H
39 #define _FP_EMU_H
40
41 #ifdef __ASSEMBLY__
42 #include <asm/asm-offsets.h>
43 #endif
44 #include <asm/math-emu.h>
45
46 #ifndef __ASSEMBLY__
47
48 #define IS_INF(a) ((a)->exp == 0x7fff)
49 #define IS_ZERO(a) ((a)->mant.m64 == 0)
50
51
52 #define fp_set_sr(bit) ({ \
53 FPDATA->fpsr |= 1 << (bit); \
54 })
55
56 #define fp_set_quotient(quotient) ({ \
57 FPDATA->fpsr &= 0xff00ffff; \
58 FPDATA->fpsr |= ((quotient) & 0xff) << 16; \
59 })
60
61
62
63
64 #define fp_normalize_ext(fpreg) ({ \
65 register struct fp_ext *reg asm ("a0") = fpreg; \
66 register int res asm ("d0"); \
67 \
68 asm volatile ("jsr fp_conv_ext2ext" \
69 : "=d" (res) : "a" (reg) \
70 : "a1", "d1", "d2", "memory"); \
71 res; \
72 })
73
74 #define fp_copy_ext(dest, src) ({ \
75 *dest = *src; \
76 })
77
78 #define fp_monadic_check(dest, src) ({ \
79 fp_copy_ext(dest, src); \
80 if (!fp_normalize_ext(dest)) \
81 return dest; \
82 })
83
84 #define fp_dyadic_check(dest, src) ({ \
85 if (!fp_normalize_ext(dest)) \
86 return dest; \
87 if (!fp_normalize_ext(src)) { \
88 fp_copy_ext(dest, src); \
89 return dest; \
90 } \
91 })
92
93 extern const struct fp_ext fp_QNaN;
94 extern const struct fp_ext fp_Inf;
95
96 #define fp_set_nan(dest) ({ \
97 fp_set_sr(FPSR_EXC_OPERR); \
98 *dest = fp_QNaN; \
99 })
100
101
102 #define fp_set_ovrflw(dest) ({ \
103 fp_set_sr(FPSR_EXC_OVFL); \
104 dest->exp = 0x7fff; \
105 dest->mant.m64 = 0; \
106 })
107
108 #define fp_conv_ext2long(src) ({ \
109 register struct fp_ext *__src asm ("a0") = src; \
110 register int __res asm ("d0"); \
111 \
112 asm volatile ("jsr fp_conv_ext2long" \
113 : "=d" (__res) : "a" (__src) \
114 : "a1", "d1", "d2", "memory"); \
115 __res; \
116 })
117
118 #define fp_conv_long2ext(dest, src) ({ \
119 register struct fp_ext *__dest asm ("a0") = dest; \
120 register int __src asm ("d0") = src; \
121 \
122 asm volatile ("jsr fp_conv_ext2long" \
123 : : "d" (__src), "a" (__dest) \
124 : "a1", "d1", "d2", "memory"); \
125 })
126
127 #else
128
129
130
131
132 .macro fp_set_sr bit
133 bset #(\bit&7),(FPD_FPSR+3-(\bit/8),FPDATA)
134 .endm
135
136 .macro fp_clr_sr bit
137 bclr #(\bit&7),(FPD_FPSR+3-(\bit/8),FPDATA)
138 .endm
139
140 .macro fp_tst_sr bit
141 btst #(\bit&7),(FPD_FPSR+3-(\bit/8),FPDATA)
142 .endm
143
144 #endif
145
146 #endif