2 * Copyright (c) 2012-2013 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Authors: Edmund Grimley Evans
43 * Floating-point library code, which will gradually replace vfp.hh. For
44 * portability, this library does not use floating-point data types. Currently,
45 * C's standard integer types are used in the API, though this could be changed
46 * to something like class Fp32 { uint32_t x; }, etc.
49 #ifndef __ARCH_ARM_INSTS_FPLIB_HH__
50 #define __ARCH_ARM_INSTS_FPLIB_HH__
54 #include "arch/arm/miscregs.hh"
60 FPRounding_TIEEVEN = 0,
61 FPRounding_POSINF = 1,
62 FPRounding_NEGINF = 2,
64 FPRounding_TIEAWAY = 4,
68 static inline FPRounding
69 FPCRRounding(FPSCR &fpscr)
71 return (FPRounding)((uint32_t)fpscr >> 22 & 3);
74 /** Floating-point absolute value. */
77 /** Floating-point add. */
79 T fplibAdd(T op1, T op2, FPSCR &fpscr);
80 /** Floating-point compare (quiet and signaling). */
82 int fplibCompare(T op1, T op2, bool signal_nans, FPSCR &fpscr);
83 /** Floating-point compare equal. */
85 bool fplibCompareEQ(T op1, T op2, FPSCR &fpscr);
86 /** Floating-point compare greater than or equal. */
88 bool fplibCompareGE(T op1, T op2, FPSCR &fpscr);
89 /** Floating-point compare greater than. */
91 bool fplibCompareGT(T op1, T op2, FPSCR &fpscr);
92 /** Floating-point convert precision. */
93 template <class T1, class T2>
94 T2 fplibConvert(T1 op, FPRounding rounding, FPSCR &fpscr);
95 /** Floating-point division. */
97 T fplibDiv(T op1, T op2, FPSCR &fpscr);
98 /** Floating-point maximum. */
100 T fplibMax(T op1, T op2, FPSCR &fpscr);
101 /** Floating-point maximum number. */
103 T fplibMaxNum(T op1, T op2, FPSCR &fpscr);
104 /** Floating-point minimum. */
106 T fplibMin(T op1, T op2, FPSCR &fpscr);
107 /** Floating-point minimum number. */
109 T fplibMinNum(T op1, T op2, FPSCR &fpscr);
110 /** Floating-point multiply. */
112 T fplibMul(T op1, T op2, FPSCR &fpscr);
113 /** Floating-point multiply-add. */
115 T fplibMulAdd(T addend, T op1, T op2, FPSCR &fpscr);
116 /** Floating-point multiply extended. */
118 T fplibMulX(T op1, T op2, FPSCR &fpscr);
119 /** Floating-point negate. */
122 /** Floating-point reciprocal square root estimate. */
124 T fplibRSqrtEstimate(T op, FPSCR &fpscr);
125 /** Floating-point reciprocal square root step. */
127 T fplibRSqrtStepFused(T op1, T op2, FPSCR &fpscr);
128 /** Floating-point reciprocal estimate. */
130 T fplibRecipEstimate(T op, FPSCR &fpscr);
131 /** Floating-point reciprocal step. */
133 T fplibRecipStepFused(T op1, T op2, FPSCR &fpscr);
134 /** Floating-point reciprocal exponent. */
136 T fplibRecpX(T op, FPSCR &fpscr);
137 /** Floating-point convert to integer. */
139 T fplibRoundInt(T op, FPRounding rounding, bool exact, FPSCR &fpscr);
140 /** Floating-point square root. */
142 T fplibSqrt(T op, FPSCR &fpscr);
143 /** Floating-point subtract. */
145 T fplibSub(T op1, T op2, FPSCR &fpscr);
146 /** Floating-point convert to fixed-point. */
147 template <class T1, class T2>
148 T2 fplibFPToFixed(T1 op, int fbits, bool u, FPRounding rounding, FPSCR &fpscr);
149 /** Floating-point convert from fixed-point. */
151 T fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
154 /* Function specializations... */
156 uint32_t fplibAbs(uint32_t op);
158 uint64_t fplibAbs(uint64_t op);
160 uint32_t fplibAdd(uint32_t op1, uint32_t op2, FPSCR &fpscr);
162 uint64_t fplibAdd(uint64_t op1, uint64_t op2, FPSCR &fpscr);
164 int fplibCompare(uint32_t op1, uint32_t op2, bool signal_nans, FPSCR &fpscr);
166 int fplibCompare(uint64_t op1, uint64_t op2, bool signal_nans, FPSCR &fpscr);
168 bool fplibCompareEQ(uint32_t op1, uint32_t op2, FPSCR &fpscr);
170 bool fplibCompareEQ(uint64_t op1, uint64_t op2, FPSCR &fpscr);
172 bool fplibCompareGE(uint32_t op1, uint32_t op2, FPSCR &fpscr);
174 bool fplibCompareGE(uint64_t op1, uint64_t op2, FPSCR &fpscr);
176 bool fplibCompareGT(uint32_t op1, uint32_t op2, FPSCR &fpscr);
178 bool fplibCompareGT(uint64_t op1, uint64_t op2, FPSCR &fpscr);
180 uint16_t fplibConvert(uint32_t op, FPRounding rounding, FPSCR &fpscr);
182 uint16_t fplibConvert(uint64_t op, FPRounding rounding, FPSCR &fpscr);
184 uint32_t fplibConvert(uint16_t op, FPRounding rounding, FPSCR &fpscr);
186 uint32_t fplibConvert(uint64_t op, FPRounding rounding, FPSCR &fpscr);
188 uint64_t fplibConvert(uint16_t op, FPRounding rounding, FPSCR &fpscr);
190 uint64_t fplibConvert(uint32_t op, FPRounding rounding, FPSCR &fpscr);
192 uint32_t fplibDiv(uint32_t op1, uint32_t op2, FPSCR &fpscr);
194 uint64_t fplibDiv(uint64_t op1, uint64_t op2, FPSCR &fpscr);
196 uint32_t fplibMax(uint32_t op1, uint32_t op2, FPSCR &fpscr);
198 uint64_t fplibMax(uint64_t op1, uint64_t op2, FPSCR &fpscr);
200 uint32_t fplibMaxNum(uint32_t op1, uint32_t op2, FPSCR &fpscr);
202 uint64_t fplibMaxNum(uint64_t op1, uint64_t op2, FPSCR &fpscr);
204 uint32_t fplibMin(uint32_t op1, uint32_t op2, FPSCR &fpscr);
206 uint64_t fplibMin(uint64_t op1, uint64_t op2, FPSCR &fpscr);
208 uint32_t fplibMinNum(uint32_t op1, uint32_t op2, FPSCR &fpscr);
210 uint64_t fplibMinNum(uint64_t op1, uint64_t op2, FPSCR &fpscr);
212 uint32_t fplibMul(uint32_t op1, uint32_t op2, FPSCR &fpscr);
214 uint64_t fplibMul(uint64_t op1, uint64_t op2, FPSCR &fpscr);
216 uint32_t fplibMulAdd(uint32_t addend, uint32_t op1, uint32_t op2,
219 uint64_t fplibMulAdd(uint64_t addend, uint64_t op1, uint64_t op2,
222 uint32_t fplibMulX(uint32_t op1, uint32_t op2, FPSCR &fpscr);
224 uint64_t fplibMulX(uint64_t op1, uint64_t op2, FPSCR &fpscr);
226 uint32_t fplibNeg(uint32_t op);
228 uint64_t fplibNeg(uint64_t op);
230 uint32_t fplibRSqrtEstimate(uint32_t op, FPSCR &fpscr);
232 uint64_t fplibRSqrtEstimate(uint64_t op, FPSCR &fpscr);
234 uint32_t fplibRSqrtStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr);
236 uint64_t fplibRSqrtStepFused(uint64_t op1, uint64_t op2, FPSCR &fpscr);
238 uint32_t fplibRecipEstimate(uint32_t op, FPSCR &fpscr);
240 uint64_t fplibRecipEstimate(uint64_t op, FPSCR &fpscr);
242 uint32_t fplibRecipStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr);
244 uint64_t fplibRecipStepFused(uint64_t op1, uint64_t op2, FPSCR &fpscr);
246 uint32_t fplibRecpX(uint32_t op, FPSCR &fpscr);
248 uint64_t fplibRecpX(uint64_t op, FPSCR &fpscr);
250 uint32_t fplibRoundInt(uint32_t op, FPRounding rounding, bool exact,
253 uint64_t fplibRoundInt(uint64_t op, FPRounding rounding, bool exact,
256 uint32_t fplibSqrt(uint32_t op, FPSCR &fpscr);
258 uint64_t fplibSqrt(uint64_t op, FPSCR &fpscr);
260 uint32_t fplibSub(uint32_t op1, uint32_t op2, FPSCR &fpscr);
262 uint64_t fplibSub(uint64_t op1, uint64_t op2, FPSCR &fpscr);
264 uint32_t fplibFPToFixed(uint32_t op, int fbits, bool u, FPRounding rounding,
267 uint32_t fplibFPToFixed(uint64_t op, int fbits, bool u, FPRounding rounding,
270 uint64_t fplibFPToFixed(uint32_t op, int fbits, bool u, FPRounding rounding,
273 uint64_t fplibFPToFixed(uint64_t op, int fbits, bool u, FPRounding rounding,
276 uint32_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
279 uint64_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,