Linux 5.7.7
[linux/fpc-iii.git] / arch / arm / nwfpe / double_cpdo.c
blob344bb7c46176f394fc3f71bab0b0a3e61e784481
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 NetWinder Floating Point Emulator
4 (c) Rebel.COM, 1998,1999
6 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
8 */
10 #include "fpa11.h"
11 #include "softfloat.h"
12 #include "fpopcode.h"
14 union float64_components {
15 float64 f64;
16 unsigned int i[2];
19 float64 float64_exp(float64 Fm);
20 float64 float64_ln(float64 Fm);
21 float64 float64_sin(float64 rFm);
22 float64 float64_cos(float64 rFm);
23 float64 float64_arcsin(float64 rFm);
24 float64 float64_arctan(float64 rFm);
25 float64 float64_log(float64 rFm);
26 float64 float64_tan(float64 rFm);
27 float64 float64_arccos(float64 rFm);
28 float64 float64_pow(float64 rFn, float64 rFm);
29 float64 float64_pol(float64 rFn, float64 rFm);
31 static float64 float64_rsf(struct roundingData *roundData, float64 rFn, float64 rFm)
33 return float64_sub(roundData, rFm, rFn);
36 static float64 float64_rdv(struct roundingData *roundData, float64 rFn, float64 rFm)
38 return float64_div(roundData, rFm, rFn);
41 static float64 (*const dyadic_double[16])(struct roundingData*, float64 rFn, float64 rFm) = {
42 [ADF_CODE >> 20] = float64_add,
43 [MUF_CODE >> 20] = float64_mul,
44 [SUF_CODE >> 20] = float64_sub,
45 [RSF_CODE >> 20] = float64_rsf,
46 [DVF_CODE >> 20] = float64_div,
47 [RDF_CODE >> 20] = float64_rdv,
48 [RMF_CODE >> 20] = float64_rem,
50 /* strictly, these opcodes should not be implemented */
51 [FML_CODE >> 20] = float64_mul,
52 [FDV_CODE >> 20] = float64_div,
53 [FRD_CODE >> 20] = float64_rdv,
56 static float64 float64_mvf(struct roundingData *roundData,float64 rFm)
58 return rFm;
61 static float64 float64_mnf(struct roundingData *roundData,float64 rFm)
63 union float64_components u;
65 u.f64 = rFm;
66 #ifdef __ARMEB__
67 u.i[0] ^= 0x80000000;
68 #else
69 u.i[1] ^= 0x80000000;
70 #endif
72 return u.f64;
75 static float64 float64_abs(struct roundingData *roundData,float64 rFm)
77 union float64_components u;
79 u.f64 = rFm;
80 #ifdef __ARMEB__
81 u.i[0] &= 0x7fffffff;
82 #else
83 u.i[1] &= 0x7fffffff;
84 #endif
86 return u.f64;
89 static float64 (*const monadic_double[16])(struct roundingData *, float64 rFm) = {
90 [MVF_CODE >> 20] = float64_mvf,
91 [MNF_CODE >> 20] = float64_mnf,
92 [ABS_CODE >> 20] = float64_abs,
93 [RND_CODE >> 20] = float64_round_to_int,
94 [URD_CODE >> 20] = float64_round_to_int,
95 [SQT_CODE >> 20] = float64_sqrt,
96 [NRM_CODE >> 20] = float64_mvf,
99 unsigned int DoubleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd)
101 FPA11 *fpa11 = GET_FPA11();
102 float64 rFm;
103 unsigned int Fm, opc_mask_shift;
105 Fm = getFm(opcode);
106 if (CONSTANT_FM(opcode)) {
107 rFm = getDoubleConstant(Fm);
108 } else {
109 switch (fpa11->fType[Fm]) {
110 case typeSingle:
111 rFm = float32_to_float64(fpa11->fpreg[Fm].fSingle);
112 break;
114 case typeDouble:
115 rFm = fpa11->fpreg[Fm].fDouble;
116 break;
118 default:
119 return 0;
123 opc_mask_shift = (opcode & MASK_ARITHMETIC_OPCODE) >> 20;
124 if (!MONADIC_INSTRUCTION(opcode)) {
125 unsigned int Fn = getFn(opcode);
126 float64 rFn;
128 switch (fpa11->fType[Fn]) {
129 case typeSingle:
130 rFn = float32_to_float64(fpa11->fpreg[Fn].fSingle);
131 break;
133 case typeDouble:
134 rFn = fpa11->fpreg[Fn].fDouble;
135 break;
137 default:
138 return 0;
141 if (dyadic_double[opc_mask_shift]) {
142 rFd->fDouble = dyadic_double[opc_mask_shift](roundData, rFn, rFm);
143 } else {
144 return 0;
146 } else {
147 if (monadic_double[opc_mask_shift]) {
148 rFd->fDouble = monadic_double[opc_mask_shift](roundData, rFm);
149 } else {
150 return 0;
154 return 1;