fplib.hh revision 10037:5cac77888310
1/*
2 * Copyright (c) 2012-2013 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 *
37 * Authors: Edmund Grimley Evans
38 *          Thomas Grocutt
39 */
40
41/**
42 * @file
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.
47 */
48
49#ifndef __ARCH_ARM_INSTS_FPLIB_HH__
50#define __ARCH_ARM_INSTS_FPLIB_HH__
51
52#include <stdint.h>
53
54#include "arch/arm/miscregs.hh"
55
56namespace ArmISA
57{
58
59enum FPRounding {
60    FPRounding_TIEEVEN = 0,
61    FPRounding_POSINF = 1,
62    FPRounding_NEGINF = 2,
63    FPRounding_ZERO = 3,
64    FPRounding_TIEAWAY = 4,
65    FPRounding_ODD = 5
66};
67
68static inline FPRounding
69FPCRRounding(FPSCR &fpscr)
70{
71    return (FPRounding)((uint32_t)fpscr >> 22 & 3);
72}
73
74/** Floating-point absolute value. */
75template <class T>
76T fplibAbs(T op);
77/** Floating-point add. */
78template <class T>
79T fplibAdd(T op1, T op2, FPSCR &fpscr);
80/** Floating-point compare (quiet and signaling). */
81template <class T>
82int fplibCompare(T op1, T op2, bool signal_nans, FPSCR &fpscr);
83/** Floating-point compare equal. */
84template <class T>
85bool fplibCompareEQ(T op1, T op2, FPSCR &fpscr);
86/** Floating-point compare greater than or equal. */
87template <class T>
88bool fplibCompareGE(T op1, T op2, FPSCR &fpscr);
89/** Floating-point compare greater than. */
90template <class T>
91bool fplibCompareGT(T op1, T op2, FPSCR &fpscr);
92/** Floating-point convert precision. */
93template <class T1, class T2>
94T2 fplibConvert(T1 op, FPRounding rounding, FPSCR &fpscr);
95/** Floating-point division. */
96template <class T>
97T fplibDiv(T op1, T op2, FPSCR &fpscr);
98/** Floating-point maximum. */
99template <class T>
100T fplibMax(T op1, T op2, FPSCR &fpscr);
101/** Floating-point maximum number. */
102template <class T>
103T fplibMaxNum(T op1, T op2, FPSCR &fpscr);
104/** Floating-point minimum. */
105template <class T>
106T fplibMin(T op1, T op2, FPSCR &fpscr);
107/** Floating-point minimum number. */
108template <class T>
109T fplibMinNum(T op1, T op2, FPSCR &fpscr);
110/** Floating-point multiply. */
111template <class T>
112T fplibMul(T op1, T op2, FPSCR &fpscr);
113/** Floating-point multiply-add. */
114template <class T>
115T fplibMulAdd(T addend, T op1, T op2, FPSCR &fpscr);
116/** Floating-point multiply extended. */
117template <class T>
118T fplibMulX(T op1, T op2, FPSCR &fpscr);
119/** Floating-point negate. */
120template <class T>
121T fplibNeg(T op);
122/** Floating-point reciprocal square root estimate. */
123template <class T>
124T fplibRSqrtEstimate(T op, FPSCR &fpscr);
125/** Floating-point reciprocal square root step. */
126template <class T>
127T fplibRSqrtStepFused(T op1, T op2, FPSCR &fpscr);
128/** Floating-point reciprocal estimate. */
129template <class T>
130T fplibRecipEstimate(T op, FPSCR &fpscr);
131/** Floating-point reciprocal step. */
132template <class T>
133T fplibRecipStepFused(T op1, T op2, FPSCR &fpscr);
134/** Floating-point reciprocal exponent. */
135template <class T>
136T fplibRecpX(T op, FPSCR &fpscr);
137/**  Floating-point convert to integer. */
138template <class T>
139T fplibRoundInt(T op, FPRounding rounding, bool exact, FPSCR &fpscr);
140/** Floating-point square root. */
141template <class T>
142T fplibSqrt(T op, FPSCR &fpscr);
143/** Floating-point subtract. */
144template <class T>
145T fplibSub(T op1, T op2, FPSCR &fpscr);
146/** Floating-point convert to fixed-point. */
147template <class T1, class T2>
148T2 fplibFPToFixed(T1 op, int fbits, bool u, FPRounding rounding, FPSCR &fpscr);
149/** Floating-point convert from fixed-point. */
150template <class T>
151T fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
152                 FPSCR &fpscr);
153
154/* Function specializations... */
155template <>
156uint32_t fplibAbs(uint32_t op);
157template <>
158uint64_t fplibAbs(uint64_t op);
159template <>
160uint32_t fplibAdd(uint32_t op1, uint32_t op2, FPSCR &fpscr);
161template <>
162uint64_t fplibAdd(uint64_t op1, uint64_t op2, FPSCR &fpscr);
163template <>
164int fplibCompare(uint32_t op1, uint32_t op2, bool signal_nans, FPSCR &fpscr);
165template <>
166int fplibCompare(uint64_t op1, uint64_t op2, bool signal_nans, FPSCR &fpscr);
167template <>
168bool fplibCompareEQ(uint32_t op1, uint32_t op2, FPSCR &fpscr);
169template <>
170bool fplibCompareEQ(uint64_t op1, uint64_t op2, FPSCR &fpscr);
171template <>
172bool fplibCompareGE(uint32_t op1, uint32_t op2, FPSCR &fpscr);
173template <>
174bool fplibCompareGE(uint64_t op1, uint64_t op2, FPSCR &fpscr);
175template <>
176bool fplibCompareGT(uint32_t op1, uint32_t op2, FPSCR &fpscr);
177template <>
178bool fplibCompareGT(uint64_t op1, uint64_t op2, FPSCR &fpscr);
179template <>
180uint16_t fplibConvert(uint32_t op, FPRounding rounding, FPSCR &fpscr);
181template <>
182uint16_t fplibConvert(uint64_t op, FPRounding rounding, FPSCR &fpscr);
183template <>
184uint32_t fplibConvert(uint16_t op, FPRounding rounding, FPSCR &fpscr);
185template <>
186uint32_t fplibConvert(uint64_t op, FPRounding rounding, FPSCR &fpscr);
187template <>
188uint64_t fplibConvert(uint16_t op, FPRounding rounding, FPSCR &fpscr);
189template <>
190uint64_t fplibConvert(uint32_t op, FPRounding rounding, FPSCR &fpscr);
191template <>
192uint32_t fplibDiv(uint32_t op1, uint32_t op2, FPSCR &fpscr);
193template <>
194uint64_t fplibDiv(uint64_t op1, uint64_t op2, FPSCR &fpscr);
195template <>
196uint32_t fplibMax(uint32_t op1, uint32_t op2, FPSCR &fpscr);
197template <>
198uint64_t fplibMax(uint64_t op1, uint64_t op2, FPSCR &fpscr);
199template <>
200uint32_t fplibMaxNum(uint32_t op1, uint32_t op2, FPSCR &fpscr);
201template <>
202uint64_t fplibMaxNum(uint64_t op1, uint64_t op2, FPSCR &fpscr);
203template <>
204uint32_t fplibMin(uint32_t op1, uint32_t op2, FPSCR &fpscr);
205template <>
206uint64_t fplibMin(uint64_t op1, uint64_t op2, FPSCR &fpscr);
207template <>
208uint32_t fplibMinNum(uint32_t op1, uint32_t op2, FPSCR &fpscr);
209template <>
210uint64_t fplibMinNum(uint64_t op1, uint64_t op2, FPSCR &fpscr);
211template <>
212uint32_t fplibMul(uint32_t op1, uint32_t op2, FPSCR &fpscr);
213template <>
214uint64_t fplibMul(uint64_t op1, uint64_t op2, FPSCR &fpscr);
215template <>
216uint32_t fplibMulAdd(uint32_t addend, uint32_t op1, uint32_t op2,
217                     FPSCR &fpscr);
218template <>
219uint64_t fplibMulAdd(uint64_t addend, uint64_t op1, uint64_t op2,
220                     FPSCR &fpscr);
221template <>
222uint32_t fplibMulX(uint32_t op1, uint32_t op2, FPSCR &fpscr);
223template <>
224uint64_t fplibMulX(uint64_t op1, uint64_t op2, FPSCR &fpscr);
225template <>
226uint32_t fplibNeg(uint32_t op);
227template <>
228uint64_t fplibNeg(uint64_t op);
229template <>
230uint32_t fplibRSqrtEstimate(uint32_t op, FPSCR &fpscr);
231template<>
232uint64_t fplibRSqrtEstimate(uint64_t op, FPSCR &fpscr);
233template <>
234uint32_t fplibRSqrtStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr);
235template <>
236uint64_t fplibRSqrtStepFused(uint64_t op1, uint64_t op2, FPSCR &fpscr);
237template <>
238uint32_t fplibRecipEstimate(uint32_t op, FPSCR &fpscr);
239template <>
240uint64_t fplibRecipEstimate(uint64_t op, FPSCR &fpscr);
241template <>
242uint32_t fplibRecipStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr);
243template <>
244uint64_t fplibRecipStepFused(uint64_t op1, uint64_t op2, FPSCR &fpscr);
245template <>
246uint32_t fplibRecpX(uint32_t op, FPSCR &fpscr);
247template <>
248uint64_t fplibRecpX(uint64_t op, FPSCR &fpscr);
249template <>
250uint32_t fplibRoundInt(uint32_t op, FPRounding rounding, bool exact,
251                       FPSCR &fpscr);
252template <>
253uint64_t fplibRoundInt(uint64_t op, FPRounding rounding, bool exact,
254                       FPSCR &fpscr);
255template <>
256uint32_t fplibSqrt(uint32_t op, FPSCR &fpscr);
257template <>
258uint64_t fplibSqrt(uint64_t op, FPSCR &fpscr);
259template <>
260uint32_t fplibSub(uint32_t op1, uint32_t op2, FPSCR &fpscr);
261template <>
262uint64_t fplibSub(uint64_t op1, uint64_t op2, FPSCR &fpscr);
263template <>
264uint32_t fplibFPToFixed(uint32_t op, int fbits, bool u, FPRounding rounding,
265                        FPSCR &fpscr);
266template <>
267uint32_t fplibFPToFixed(uint64_t op, int fbits, bool u, FPRounding rounding,
268                        FPSCR &fpscr);
269template <>
270uint64_t fplibFPToFixed(uint32_t op, int fbits, bool u, FPRounding rounding,
271                        FPSCR &fpscr);
272template <>
273uint64_t fplibFPToFixed(uint64_t op, int fbits, bool u, FPRounding rounding,
274                        FPSCR &fpscr);
275template <>
276uint32_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
277                        FPSCR &fpscr);
278template <>
279uint64_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
280                        FPSCR &fpscr);
281}
282
283#endif
284