Line 0
Link Here
|
|
|
1 |
/* soft-fp x * y + z as ternary operation. |
2 |
Copyright (C) 2006 Free Software Foundation, Inc. |
3 |
This file is part of the GNU C Library. |
4 |
Contributed by Steven Munroe <sjmunroe@us.ibm.com>, 2006. |
5 |
|
6 |
The GNU C Library is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU Lesser General Public |
8 |
License as published by the Free Software Foundation; either |
9 |
version 2.1 of the License, or (at your option) any later version. |
10 |
|
11 |
The GNU C Library is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
Lesser General Public License for more details. |
15 |
|
16 |
In addition to the permissions in the GNU Lesser General Public |
17 |
License, the Free Software Foundation gives you unlimited |
18 |
permission to link the compiled version of this file into |
19 |
combinations with other programs, and to distribute those |
20 |
combinations without any restriction coming from the use of this |
21 |
file. (The Lesser General Public License restrictions do apply in |
22 |
other respects; for example, they cover modification of the file, |
23 |
and distribution when not linked into a combine executable.) |
24 |
|
25 |
You should have received a copy of the GNU Lesser General Public |
26 |
License along with the GNU C Library; if not, write to the Free |
27 |
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
28 |
02111-1307 USA. */ |
29 |
|
30 |
#include "soft-fp.h" |
31 |
#include "double.h" |
32 |
#include "quad.h" |
33 |
|
34 |
/* Compute floating point multiply-add with higher (quad) precision. */ |
35 |
DFtype |
36 |
__fmadf4 (DFtype a, DFtype b, DFtype c) |
37 |
{ |
38 |
FP_DECL_EX; |
39 |
FP_DECL_D(A); |
40 |
FP_DECL_D(B); |
41 |
FP_DECL_D(C); |
42 |
FP_DECL_Q(X); |
43 |
FP_DECL_Q(Y); |
44 |
FP_DECL_Q(Z); |
45 |
FP_DECL_Q(U); |
46 |
FP_DECL_Q(V); |
47 |
FP_DECL_D(R); |
48 |
double r; |
49 |
long double u, x, y, z; |
50 |
|
51 |
FP_INIT_ROUNDMODE; |
52 |
FP_UNPACK_RAW_D (A, a); |
53 |
FP_UNPACK_RAW_D (B, b); |
54 |
FP_UNPACK_RAW_D (C, c); |
55 |
|
56 |
/* Extend double to quad. */ |
57 |
#if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q |
58 |
FP_EXTEND(Q,D,4,2,X,A); |
59 |
FP_EXTEND(Q,D,4,2,Y,B); |
60 |
FP_EXTEND(Q,D,4,2,Z,C); |
61 |
#else |
62 |
FP_EXTEND(Q,D,2,1,X,A); |
63 |
FP_EXTEND(Q,D,2,1,Y,B); |
64 |
FP_EXTEND(Q,D,2,1,Z,C); |
65 |
#endif |
66 |
FP_PACK_RAW_Q(x,X); |
67 |
FP_PACK_RAW_Q(y,Y); |
68 |
FP_PACK_RAW_Q(z,Z); |
69 |
FP_HANDLE_EXCEPTIONS; |
70 |
|
71 |
/* Multiply. |
72 |
Rounding is not an issue as we keep the full 106 bit product. */ |
73 |
FP_UNPACK_Q(X,x); |
74 |
FP_UNPACK_Q(Y,y); |
75 |
FP_MUL_Q(U,X,Y); |
76 |
FP_PACK_Q(u,U); |
77 |
FP_HANDLE_EXCEPTIONS; |
78 |
|
79 |
/* Add without rounding. */ |
80 |
FP_UNPACK_SEMIRAW_Q(U,u); |
81 |
FP_UNPACK_SEMIRAW_Q(Z,z); |
82 |
FP_ADD_Q(V,U,Z); |
83 |
|
84 |
/* Truncate quad to double and round. */ |
85 |
#if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q |
86 |
V_f[3] &= 0x0007ffff; /* SEMIRAW_TO_SEMIRAW(4) */ |
87 |
FP_TRUNC(D,Q,2,4,R,V); |
88 |
#else |
89 |
V_f1 &= 0x0007ffffffffffffL; /* SEMIRAW_TO_SEMIRAW(2) */ |
90 |
FP_TRUNC(D,Q,1,2,R,V); |
91 |
#endif |
92 |
FP_PACK_SEMIRAW_D(r,R); |
93 |
FP_HANDLE_EXCEPTIONS; |
94 |
|
95 |
return r; |
96 |
} |
97 |
|