|
|
|
|
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 |
You should have received a copy of the GNU Lesser General Public |
| 17 |
License along with the GNU C Library; if not, write to the Free |
| 18 |
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 |
02111-1307 USA. */ |
| 20 |
|
| 21 |
#include "soft-fp.h" |
| 22 |
#include "double.h" |
| 23 |
#include "quad.h" |
| 24 |
|
| 25 |
/* Compute floating point multiply-add with higher (quad) precision. */ |
| 26 |
DFtype |
| 27 |
__fmadf4 (DFtype a, DFtype b, DFtype c) |
| 28 |
{ |
| 29 |
FP_DECL_EX; |
| 30 |
FP_DECL_D(A); |
| 31 |
FP_DECL_D(B); |
| 32 |
FP_DECL_D(C); |
| 33 |
FP_DECL_Q(X); |
| 34 |
FP_DECL_Q(Y); |
| 35 |
FP_DECL_Q(Z); |
| 36 |
FP_DECL_Q(U); |
| 37 |
FP_DECL_Q(V); |
| 38 |
FP_DECL_D(R); |
| 39 |
double r; |
| 40 |
long double u, x, y, z; |
| 41 |
|
| 42 |
FP_INIT_ROUNDMODE; |
| 43 |
FP_UNPACK_RAW_D (A, a); |
| 44 |
FP_UNPACK_RAW_D (B, b); |
| 45 |
FP_UNPACK_RAW_D (C, c); |
| 46 |
|
| 47 |
/* Extend double to quad. */ |
| 48 |
#if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q |
| 49 |
FP_EXTEND(Q,D,4,2,X,A); |
| 50 |
FP_EXTEND(Q,D,4,2,Y,B); |
| 51 |
FP_EXTEND(Q,D,4,2,Z,C); |
| 52 |
#else |
| 53 |
FP_EXTEND(Q,D,2,1,X,A); |
| 54 |
FP_EXTEND(Q,D,2,1,Y,B); |
| 55 |
FP_EXTEND(Q,D,2,1,Z,C); |
| 56 |
#endif |
| 57 |
FP_PACK_RAW_Q(x,X); |
| 58 |
FP_PACK_RAW_Q(y,Y); |
| 59 |
FP_PACK_RAW_Q(z,Z); |
| 60 |
FP_HANDLE_EXCEPTIONS; |
| 61 |
|
| 62 |
/* Multiply. */ |
| 63 |
FP_INIT_ROUNDMODE; |
| 64 |
FP_UNPACK_Q(X,x); |
| 65 |
FP_UNPACK_Q(Y,y); |
| 66 |
FP_MUL_Q(U,X,Y); |
| 67 |
FP_PACK_Q(u,U); |
| 68 |
FP_HANDLE_EXCEPTIONS; |
| 69 |
|
| 70 |
/* Subtract. */ |
| 71 |
FP_INIT_ROUNDMODE; |
| 72 |
FP_UNPACK_SEMIRAW_Q(U,u); |
| 73 |
FP_UNPACK_SEMIRAW_Q(Z,z); |
| 74 |
FP_ADD_Q(V,U,Z); |
| 75 |
|
| 76 |
/* Truncate quad to double. */ |
| 77 |
#if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q |
| 78 |
V_f[3] &= 0x0007ffff; |
| 79 |
FP_TRUNC(D,Q,2,4,R,V); |
| 80 |
#else |
| 81 |
V_f1 &= 0x0007ffffffffffffL; |
| 82 |
FP_TRUNC(D,Q,1,2,R,V); |
| 83 |
#endif |
| 84 |
FP_PACK_SEMIRAW_D(r,R); |
| 85 |
FP_HANDLE_EXCEPTIONS; |
| 86 |
|
| 87 |
return r; |
| 88 |
} |
| 89 |
|