summaryrefslogtreecommitdiff
path: root/src/arch/arm/insts/fplib.hh
blob: d3d77908ce813a1121bf0debe0aaf087787f3f38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
 * Copyright (c) 2012-2013, 2017-2018 ARM Limited
 * All rights reserved
 *
 * The license below extends only to copyright in the software and shall
 * not be construed as granting a license to any other intellectual
 * property including but not limited to intellectual property relating
 * to a hardware implementation of the functionality of the software
 * licensed hereunder.  You may use the software subject to the license
 * terms below provided that you ensure that this notice is replicated
 * unmodified and in its entirety in all distributions of the software,
 * modified or unmodified, in source code or in binary form.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Edmund Grimley Evans
 *          Thomas Grocutt
 */

/**
 * @file
 * Floating-point library code, which will gradually replace vfp.hh. For
 * portability, this library does not use floating-point data types.  Currently,
 * C's standard integer types are used in the API, though this could be changed
 * to something like class Fp32 { uint32_t x; }, etc.
 */

#ifndef __ARCH_ARM_INSTS_FPLIB_HH__
#define __ARCH_ARM_INSTS_FPLIB_HH__

#include <stdint.h>

#include "arch/arm/miscregs.hh"

namespace ArmISA
{

enum FPRounding {
    FPRounding_TIEEVEN = 0,
    FPRounding_POSINF = 1,
    FPRounding_NEGINF = 2,
    FPRounding_ZERO = 3,
    FPRounding_TIEAWAY = 4,
    FPRounding_ODD = 5
};

static inline FPRounding
FPCRRounding(FPSCR &fpscr)
{
    return (FPRounding)((uint32_t)fpscr >> 22 & 3);
}

/** Floating-point absolute value. */
template <class T>
T fplibAbs(T op);
/** Floating-point add. */
template <class T>
T fplibAdd(T op1, T op2, FPSCR &fpscr);
/** Floating-point compare (quiet and signaling). */
template <class T>
int fplibCompare(T op1, T op2, bool signal_nans, FPSCR &fpscr);
/** Floating-point compare equal. */
template <class T>
bool fplibCompareEQ(T op1, T op2, FPSCR &fpscr);
/** Floating-point compare greater than or equal. */
template <class T>
bool fplibCompareGE(T op1, T op2, FPSCR &fpscr);
/** Floating-point compare greater than. */
template <class T>
bool fplibCompareGT(T op1, T op2, FPSCR &fpscr);
/** Floating-point compare unordered. */
template <class T>
bool fplibCompareUN(T op1, T op2, FPSCR &fpscr);
/** Floating-point convert precision. */
template <class T1, class T2>
T2 fplibConvert(T1 op, FPRounding rounding, FPSCR &fpscr);
/** Floating-point division. */
template <class T>
T fplibDiv(T op1, T op2, FPSCR &fpscr);
/** Floating-point exponential accelerator. */
template <class T>
T fplibExpA(T op);
/** Floating-point maximum. */
template <class T>
T fplibMax(T op1, T op2, FPSCR &fpscr);
/** Floating-point maximum number. */
template <class T>
T fplibMaxNum(T op1, T op2, FPSCR &fpscr);
/** Floating-point minimum. */
template <class T>
T fplibMin(T op1, T op2, FPSCR &fpscr);
/** Floating-point minimum number. */
template <class T>
T fplibMinNum(T op1, T op2, FPSCR &fpscr);
/** Floating-point multiply. */
template <class T>
T fplibMul(T op1, T op2, FPSCR &fpscr);
/** Floating-point multiply-add. */
template <class T>
T fplibMulAdd(T addend, T op1, T op2, FPSCR &fpscr);
/** Floating-point multiply extended. */
template <class T>
T fplibMulX(T op1, T op2, FPSCR &fpscr);
/** Floating-point negate. */
template <class T>
T fplibNeg(T op);
/** Floating-point reciprocal square root estimate. */
template <class T>
T fplibRSqrtEstimate(T op, FPSCR &fpscr);
/** Floating-point reciprocal square root step. */
template <class T>
T fplibRSqrtStepFused(T op1, T op2, FPSCR &fpscr);
/** Floating-point reciprocal estimate. */
template <class T>
T fplibRecipEstimate(T op, FPSCR &fpscr);
/** Floating-point reciprocal step. */
template <class T>
T fplibRecipStepFused(T op1, T op2, FPSCR &fpscr);
/** Floating-point reciprocal exponent. */
template <class T>
T fplibRecpX(T op, FPSCR &fpscr);
/**  Floating-point convert to integer. */
template <class T>
T fplibRoundInt(T op, FPRounding rounding, bool exact, FPSCR &fpscr);
/** Floating-point adjust exponent. */
template <class T>
T fplibScale(T op1, T op2, FPSCR &fpscr);
/** Floating-point square root. */
template <class T>
T fplibSqrt(T op, FPSCR &fpscr);
/** Floating-point subtract. */
template <class T>
T fplibSub(T op1, T op2, FPSCR &fpscr);
/** Floating-point trigonometric multiply-add coefficient. */
template <class T>
T fplibTrigMulAdd(uint8_t coeff_index, T op1, T op2, FPSCR &fpscr);
/** Floating-point trigonometric starting value. */
template <class T>
T fplibTrigSMul(T op1, T op2, FPSCR &fpscr);
/** Floating-point trigonometric select coefficient. */
template <class T>
T fplibTrigSSel(T op1, T op2, FPSCR &fpscr);
/** Floating-point convert to fixed-point. */
template <class T1, class T2>
T2 fplibFPToFixed(T1 op, int fbits, bool u, FPRounding rounding, FPSCR &fpscr);
/** Floating-point convert from fixed-point. */
template <class T>
T fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
                 FPSCR &fpscr);
/** Floating-point value for +/- infinity. */
template <class T>
T fplibInfinity(int sgn);
/** Foating-point value for default NaN. */
template <class T>
T fplibDefaultNaN();

/* Function specializations... */
template <>
uint16_t fplibAbs(uint16_t op);
template <>
uint32_t fplibAbs(uint32_t op);
template <>
uint64_t fplibAbs(uint64_t op);
template <>
uint16_t fplibAdd(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibAdd(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibAdd(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
int fplibCompare(uint16_t op1, uint16_t op2, bool signal_nans, FPSCR &fpscr);
template <>
int fplibCompare(uint32_t op1, uint32_t op2, bool signal_nans, FPSCR &fpscr);
template <>
int fplibCompare(uint64_t op1, uint64_t op2, bool signal_nans, FPSCR &fpscr);
template <>
bool fplibCompareEQ(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
bool fplibCompareEQ(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
bool fplibCompareEQ(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
bool fplibCompareGE(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
bool fplibCompareGE(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
bool fplibCompareGE(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
bool fplibCompareGT(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
bool fplibCompareGT(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
bool fplibCompareGT(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
bool fplibCompareUN(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
bool fplibCompareUN(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
bool fplibCompareUN(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibConvert(uint32_t op, FPRounding rounding, FPSCR &fpscr);
template <>
uint16_t fplibConvert(uint64_t op, FPRounding rounding, FPSCR &fpscr);
template <>
uint32_t fplibConvert(uint16_t op, FPRounding rounding, FPSCR &fpscr);
template <>
uint32_t fplibConvert(uint64_t op, FPRounding rounding, FPSCR &fpscr);
template <>
uint64_t fplibConvert(uint16_t op, FPRounding rounding, FPSCR &fpscr);
template <>
uint64_t fplibConvert(uint32_t op, FPRounding rounding, FPSCR &fpscr);
template <>
uint16_t fplibDiv(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibDiv(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibDiv(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibExpA(uint16_t op);
template <>
uint32_t fplibExpA(uint32_t op);
template <>
uint64_t fplibExpA(uint64_t op);
template <>
uint16_t fplibMax(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibMax(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibMax(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibMaxNum(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibMaxNum(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibMaxNum(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibMin(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibMin(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibMin(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibMinNum(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibMinNum(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibMinNum(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibMul(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibMul(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibMul(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibMulAdd(uint16_t addend, uint16_t op1, uint16_t op2,
                     FPSCR &fpscr);
template <>
uint32_t fplibMulAdd(uint32_t addend, uint32_t op1, uint32_t op2,
                     FPSCR &fpscr);
template <>
uint64_t fplibMulAdd(uint64_t addend, uint64_t op1, uint64_t op2,
                     FPSCR &fpscr);
template <>
uint16_t fplibMulX(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibMulX(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibMulX(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibNeg(uint16_t op);
template <>
uint32_t fplibNeg(uint32_t op);
template <>
uint64_t fplibNeg(uint64_t op);
template <>
uint16_t fplibRSqrtEstimate(uint16_t op, FPSCR &fpscr);
template <>
uint32_t fplibRSqrtEstimate(uint32_t op, FPSCR &fpscr);
template<>
uint64_t fplibRSqrtEstimate(uint64_t op, FPSCR &fpscr);
template <>
uint16_t fplibRSqrtStepFused(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibRSqrtStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibRSqrtStepFused(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibRecipEstimate(uint16_t op, FPSCR &fpscr);
template <>
uint32_t fplibRecipEstimate(uint32_t op, FPSCR &fpscr);
template <>
uint64_t fplibRecipEstimate(uint64_t op, FPSCR &fpscr);
template <>
uint16_t fplibRecipStepFused(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibRecipStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibRecipStepFused(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibRecpX(uint16_t op, FPSCR &fpscr);
template <>
uint32_t fplibRecpX(uint32_t op, FPSCR &fpscr);
template <>
uint64_t fplibRecpX(uint64_t op, FPSCR &fpscr);
template <>
uint16_t fplibRoundInt(uint16_t op, FPRounding rounding, bool exact,
                       FPSCR &fpscr);
template <>
uint32_t fplibRoundInt(uint32_t op, FPRounding rounding, bool exact,
                       FPSCR &fpscr);
template <>
uint64_t fplibRoundInt(uint64_t op, FPRounding rounding, bool exact,
                       FPSCR &fpscr);
template <>
uint16_t fplibScale(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibScale(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibScale(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibSqrt(uint16_t op, FPSCR &fpscr);
template <>
uint32_t fplibSqrt(uint32_t op, FPSCR &fpscr);
template <>
uint64_t fplibSqrt(uint64_t op, FPSCR &fpscr);
template <>
uint16_t fplibSub(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibSub(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibSub(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibTrigMulAdd(uint8_t coeff_index, uint16_t op1, uint16_t op2,
                       FPSCR &fpscr);
template <>
uint32_t fplibTrigMulAdd(uint8_t coeff_index, uint32_t op1, uint32_t op2,
                         FPSCR &fpscr);
template <>
uint64_t fplibTrigMulAdd(uint8_t coeff_index, uint64_t op1, uint64_t op2,
                         FPSCR &fpscr);
template <>
uint16_t fplibTrigSMul(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibTrigSMul(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibTrigSMul(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibTrigSSel(uint16_t op1, uint16_t op2, FPSCR &fpscr);
template <>
uint32_t fplibTrigSSel(uint32_t op1, uint32_t op2, FPSCR &fpscr);
template <>
uint64_t fplibTrigSSel(uint64_t op1, uint64_t op2, FPSCR &fpscr);
template <>
uint16_t fplibFPToFixed(uint16_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint32_t fplibFPToFixed(uint16_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint32_t fplibFPToFixed(uint32_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint32_t fplibFPToFixed(uint64_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint64_t fplibFPToFixed(uint16_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint64_t fplibFPToFixed(uint32_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint64_t fplibFPToFixed(uint64_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint16_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint32_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint64_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding,
                        FPSCR &fpscr);
template <>
uint16_t fplibInfinity(int sgn);
template <>
uint32_t fplibInfinity(int sgn);
template <>
uint64_t fplibInfinity(int sgn);
template <>
uint16_t fplibDefaultNaN();
template <>
uint32_t fplibDefaultNaN();
template <>
uint64_t fplibDefaultNaN();
}

#endif