[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / m68k / math-emu / fp_log.c
blob87b4f0158560492d4ddfb243debbd8a6e4902a38
1 /*
3 fp_trig.c: floating-point math routines for the Linux-m68k
4 floating point emulator.
6 Copyright (c) 1998-1999 David Huggins-Daines / Roman Zippel.
8 I hereby give permission, free of charge, to copy, modify, and
9 redistribute this software, in source or binary form, provided that
10 the above copyright notice and the following disclaimer are included
11 in all such copies.
13 THIS SOFTWARE IS PROVIDED "AS IS", WITH ABSOLUTELY NO WARRANTY, REAL
14 OR IMPLIED.
18 #include "fp_emu.h"
20 static const struct fp_ext fp_one =
22 .exp = 0x3fff,
25 extern struct fp_ext *fp_fadd(struct fp_ext *dest, const struct fp_ext *src);
26 extern struct fp_ext *fp_fdiv(struct fp_ext *dest, const struct fp_ext *src);
27 extern struct fp_ext *fp_fmul(struct fp_ext *dest, const struct fp_ext *src);
29 struct fp_ext *
30 fp_fsqrt(struct fp_ext *dest, struct fp_ext *src)
32 struct fp_ext tmp, src2;
33 int i, exp;
35 dprint(PINSTR, "fsqrt\n");
37 fp_monadic_check(dest, src);
39 if (IS_ZERO(dest))
40 return dest;
42 if (dest->sign) {
43 fp_set_nan(dest);
44 return dest;
46 if (IS_INF(dest))
47 return dest;
50 * sqrt(m) * 2^(p) , if e = 2*p
51 * sqrt(m*2^e) =
52 * sqrt(2*m) * 2^(p) , if e = 2*p + 1
54 * So we use the last bit of the exponent to decide wether to
55 * use the m or 2*m.
57 * Since only the fractional part of the mantissa is stored and
58 * the integer part is assumed to be one, we place a 1 or 2 into
59 * the fixed point representation.
61 exp = dest->exp;
62 dest->exp = 0x3FFF;
63 if (!(exp & 1)) /* lowest bit of exponent is set */
64 dest->exp++;
65 fp_copy_ext(&src2, dest);
68 * The taylor row arround a for sqrt(x) is:
69 * sqrt(x) = sqrt(a) + 1/(2*sqrt(a))*(x-a) + R
70 * With a=1 this gives:
71 * sqrt(x) = 1 + 1/2*(x-1)
72 * = 1/2*(1+x)
74 fp_fadd(dest, &fp_one);
75 dest->exp--; /* * 1/2 */
78 * We now apply the newton rule to the function
79 * f(x) := x^2 - r
80 * which has a null point on x = sqrt(r).
82 * It gives:
83 * x' := x - f(x)/f'(x)
84 * = x - (x^2 -r)/(2*x)
85 * = x - (x - r/x)/2
86 * = (2*x - x + r/x)/2
87 * = (x + r/x)/2
89 for (i = 0; i < 9; i++) {
90 fp_copy_ext(&tmp, &src2);
92 fp_fdiv(&tmp, dest);
93 fp_fadd(dest, &tmp);
94 dest->exp--;
97 dest->exp += (exp - 0x3FFF) / 2;
99 return dest;
102 struct fp_ext *
103 fp_fetoxm1(struct fp_ext *dest, struct fp_ext *src)
105 uprint("fetoxm1\n");
107 fp_monadic_check(dest, src);
109 if (IS_ZERO(dest))
110 return dest;
112 return dest;
115 struct fp_ext *
116 fp_fetox(struct fp_ext *dest, struct fp_ext *src)
118 uprint("fetox\n");
120 fp_monadic_check(dest, src);
122 return dest;
125 struct fp_ext *
126 fp_ftwotox(struct fp_ext *dest, struct fp_ext *src)
128 uprint("ftwotox\n");
130 fp_monadic_check(dest, src);
132 return dest;
135 struct fp_ext *
136 fp_ftentox(struct fp_ext *dest, struct fp_ext *src)
138 uprint("ftentox\n");
140 fp_monadic_check(dest, src);
142 return dest;
145 struct fp_ext *
146 fp_flogn(struct fp_ext *dest, struct fp_ext *src)
148 uprint("flogn\n");
150 fp_monadic_check(dest, src);
152 return dest;
155 struct fp_ext *
156 fp_flognp1(struct fp_ext *dest, struct fp_ext *src)
158 uprint("flognp1\n");
160 fp_monadic_check(dest, src);
162 return dest;
165 struct fp_ext *
166 fp_flog10(struct fp_ext *dest, struct fp_ext *src)
168 uprint("flog10\n");
170 fp_monadic_check(dest, src);
172 return dest;
175 struct fp_ext *
176 fp_flog2(struct fp_ext *dest, struct fp_ext *src)
178 uprint("flog2\n");
180 fp_monadic_check(dest, src);
182 return dest;
185 struct fp_ext *
186 fp_fgetexp(struct fp_ext *dest, struct fp_ext *src)
188 dprint(PINSTR, "fgetexp\n");
190 fp_monadic_check(dest, src);
192 if (IS_INF(dest)) {
193 fp_set_nan(dest);
194 return dest;
196 if (IS_ZERO(dest))
197 return dest;
199 fp_conv_long2ext(dest, (int)dest->exp - 0x3FFF);
201 fp_normalize_ext(dest);
203 return dest;
206 struct fp_ext *
207 fp_fgetman(struct fp_ext *dest, struct fp_ext *src)
209 dprint(PINSTR, "fgetman\n");
211 fp_monadic_check(dest, src);
213 if (IS_ZERO(dest))
214 return dest;
216 if (IS_INF(dest))
217 return dest;
219 dest->exp = 0x3FFF;
221 return dest;