Lines Matching +full:reg +full:- +full:40 +full:h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* multi_arith.h: multi-precision integer arithmetic functions, needed
3 to do extended-precision floating point.
5 (c) 1998 David Huggins-Daines.
7 Somewhat based on arch/alpha/math-emu/ieee-math.c, which is (c)
8 David Mosberger-Tang.
14 These are not general multi-precision math routines. Rather, they
16 multiply, divide, and normalize 128-bit unsigned mantissae. */
21 #include "fp_emu.h"
23 static inline void fp_denormalize(struct fp_ext *reg, unsigned int cnt) in fp_denormalize() argument
25 reg->exp += cnt; in fp_denormalize()
29 reg->lowmant = reg->mant.m32[1] << (8 - cnt); in fp_denormalize()
30 reg->mant.m32[1] = (reg->mant.m32[1] >> cnt) | in fp_denormalize()
31 (reg->mant.m32[0] << (32 - cnt)); in fp_denormalize()
32 reg->mant.m32[0] = reg->mant.m32[0] >> cnt; in fp_denormalize()
35 reg->lowmant = reg->mant.m32[1] >> (cnt - 8); in fp_denormalize()
36 if (reg->mant.m32[1] << (40 - cnt)) in fp_denormalize()
37 reg->lowmant |= 1; in fp_denormalize()
38 reg->mant.m32[1] = (reg->mant.m32[1] >> cnt) | in fp_denormalize()
39 (reg->mant.m32[0] << (32 - cnt)); in fp_denormalize()
40 reg->mant.m32[0] = reg->mant.m32[0] >> cnt; in fp_denormalize()
43 asm volatile ("bfextu %1{%2,#8},%0" : "=d" (reg->lowmant) in fp_denormalize()
44 : "m" (reg->mant.m32[0]), "d" (64 - cnt)); in fp_denormalize()
45 if (reg->mant.m32[1] << (40 - cnt)) in fp_denormalize()
46 reg->lowmant |= 1; in fp_denormalize()
47 reg->mant.m32[1] = reg->mant.m32[0] >> (cnt - 32); in fp_denormalize()
48 reg->mant.m32[0] = 0; in fp_denormalize()
50 case 40 ... 71: in fp_denormalize()
51 reg->lowmant = reg->mant.m32[0] >> (cnt - 40); in fp_denormalize()
52 if ((reg->mant.m32[0] << (72 - cnt)) || reg->mant.m32[1]) in fp_denormalize()
53 reg->lowmant |= 1; in fp_denormalize()
54 reg->mant.m32[1] = reg->mant.m32[0] >> (cnt - 32); in fp_denormalize()
55 reg->mant.m32[0] = 0; in fp_denormalize()
58 reg->lowmant = reg->mant.m32[0] || reg->mant.m32[1]; in fp_denormalize()
59 reg->mant.m32[0] = 0; in fp_denormalize()
60 reg->mant.m32[1] = 0; in fp_denormalize()
65 static inline int fp_overnormalize(struct fp_ext *reg) in fp_overnormalize() argument
69 if (reg->mant.m32[0]) { in fp_overnormalize()
70 asm ("bfffo %1{#0,#32},%0" : "=d" (shift) : "dm" (reg->mant.m32[0])); in fp_overnormalize()
71 reg->mant.m32[0] = (reg->mant.m32[0] << shift) | (reg->mant.m32[1] >> (32 - shift)); in fp_overnormalize()
72 reg->mant.m32[1] = (reg->mant.m32[1] << shift); in fp_overnormalize()
74 asm ("bfffo %1{#0,#32},%0" : "=d" (shift) : "dm" (reg->mant.m32[1])); in fp_overnormalize()
75 reg->mant.m32[0] = (reg->mant.m32[1] << shift); in fp_overnormalize()
76 reg->mant.m32[1] = 0; in fp_overnormalize()
88 asm volatile ("add.b %1,%0" : "=d,g" (dest->lowmant) in fp_addmant()
89 : "g,d" (src->lowmant), "0,0" (dest->lowmant)); in fp_addmant()
90 asm volatile ("addx.l %1,%0" : "=d" (dest->mant.m32[1]) in fp_addmant()
91 : "d" (src->mant.m32[1]), "0" (dest->mant.m32[1])); in fp_addmant()
92 asm volatile ("addx.l %1,%0" : "=d" (dest->mant.m32[0]) in fp_addmant()
93 : "d" (src->mant.m32[0]), "0" (dest->mant.m32[0])); in fp_addmant()
99 static inline int fp_addcarry(struct fp_ext *reg) in fp_addcarry() argument
101 if (++reg->exp == 0x7fff) { in fp_addcarry()
102 if (reg->mant.m64) in fp_addcarry()
104 reg->mant.m64 = 0; in fp_addcarry()
108 reg->lowmant = (reg->mant.m32[1] << 7) | (reg->lowmant ? 1 : 0); in fp_addcarry()
109 reg->mant.m32[1] = (reg->mant.m32[1] >> 1) | in fp_addcarry()
110 (reg->mant.m32[0] << 31); in fp_addcarry()
111 reg->mant.m32[0] = (reg->mant.m32[0] >> 1) | 0x80000000; in fp_addcarry()
120 asm volatile ("sub.b %1,%0" : "=d,g" (dest->lowmant) in fp_submant()
121 : "g,d" (src2->lowmant), "0,0" (src1->lowmant)); in fp_submant()
122 asm volatile ("subx.l %1,%0" : "=d" (dest->mant.m32[1]) in fp_submant()
123 : "d" (src2->mant.m32[1]), "0" (src1->mant.m32[1])); in fp_submant()
124 asm volatile ("subx.l %1,%0" : "=d" (dest->mant.m32[0]) in fp_submant()
125 : "d" (src2->mant.m32[0]), "0" (src1->mant.m32[0])); in fp_submant()
143 asm volatile ("add.l %1,%0" : "=d,g" (dest->m32[2]) \
144 : "g,d" (temp.m32[1]), "0,0" (dest->m32[2])); \
145 asm volatile ("addx.l %1,%0" : "=d" (dest->m32[1]) \
146 : "d" (temp.m32[0]), "0" (dest->m32[1])); \
147 asm volatile ("addx.l %1,%0" : "=d" (dest->m32[0]) \
148 : "d" (0), "0" (dest->m32[0])); \
172 fp_mul64(dest->m32[0], dest->m32[1], src1->mant.m32[0], src2->mant.m32[0]); in fp_multiplymant()
173 fp_mul64(dest->m32[2], dest->m32[3], src1->mant.m32[1], src2->mant.m32[1]); in fp_multiplymant()
175 fp_mul64(temp.m32[0], temp.m32[1], src1->mant.m32[0], src2->mant.m32[1]); in fp_multiplymant()
178 fp_mul64(temp.m32[0], temp.m32[1], src1->mant.m32[1], src2->mant.m32[0]); in fp_multiplymant()
187 unsigned long *mantp = dest->m32; in fp_dividemant()
193 if (src->mant.m64 >= div->mant.m64) { in fp_dividemant()
194 fp_sub64(src->mant, div->mant); in fp_dividemant()
210 dummy = div->mant.m32[1] / div->mant.m32[0] + 1; in fp_dividemant()
213 fix--; in fp_dividemant()
216 if (src->mant.m32[0] == div->mant.m32[0]) { in fp_dividemant()
217 fp_div64(first, rem, 0, src->mant.m32[1], div->mant.m32[0]); in fp_dividemant()
222 fp_div64(first, rem, src->mant.m32[0], src->mant.m32[1], div->mant.m32[0]); in fp_dividemant()
227 fp_mul64(tmp.m32[0], tmp.m32[1], div->mant.m32[0], first - *mantp); in fp_dividemant()
231 fp_mul64(tmp64.m32[0], tmp64.m32[1], *mantp, div->mant.m32[1]); in fp_dividemant()
234 src->mant.m32[0] = tmp.m32[1]; in fp_dividemant()
235 src->mant.m32[1] = tmp.m32[2]; in fp_dividemant()
237 while (!fp_sub96c(tmp, 0, div->mant.m32[0], div->mant.m32[1])) { in fp_dividemant()
238 src->mant.m32[0] = tmp.m32[1]; in fp_dividemant()
239 src->mant.m32[1] = tmp.m32[2]; in fp_dividemant()
252 dest->mant.m64 = src->m64[0]; in fp_putmant128()
253 dest->lowmant = src->m32[2] >> 24; in fp_putmant128()
254 if (src->m32[3] || (src->m32[2] << 8)) in fp_putmant128()
255 dest->lowmant |= 1; in fp_putmant128()
259 : "=d" (tmp) : "0" (src->m32[2])); in fp_putmant128()
261 : "=d" (dest->mant.m32[1]) : "0" (src->m32[1])); in fp_putmant128()
263 : "=d" (dest->mant.m32[0]) : "0" (src->m32[0])); in fp_putmant128()
264 dest->lowmant = tmp >> 24; in fp_putmant128()
265 if (src->m32[3] || (tmp << 8)) in fp_putmant128()
266 dest->lowmant |= 1; in fp_putmant128()
270 : "=d" (dest->mant.m32[0]) in fp_putmant128()
271 : "d" (src->m32[0]), "0" (src->m32[1])); in fp_putmant128()
273 : "=d" (dest->mant.m32[1]) : "0" (src->m32[2])); in fp_putmant128()
275 : "=d" (tmp) : "0" (src->m32[3])); in fp_putmant128()
276 dest->lowmant = tmp >> 24; in fp_putmant128()
277 if (src->m32[3] << 7) in fp_putmant128()
278 dest->lowmant |= 1; in fp_putmant128()
281 dest->mant.m32[0] = src->m32[1]; in fp_putmant128()
282 dest->mant.m32[1] = src->m32[2]; in fp_putmant128()
283 dest->lowmant = src->m32[3] >> 24; in fp_putmant128()
284 if (src->m32[3] << 8) in fp_putmant128()
285 dest->lowmant |= 1; in fp_putmant128()