1 // SPDX-License-Identifier: GPL-2.0-or-later
3 NetWinder Floating Point Emulator
4 (c) Rebel.COM, 1998,1999
6 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
11 #include "softfloat.h"
14 floatx80
floatx80_exp(floatx80 Fm
);
15 floatx80
floatx80_ln(floatx80 Fm
);
16 floatx80
floatx80_sin(floatx80 rFm
);
17 floatx80
floatx80_cos(floatx80 rFm
);
18 floatx80
floatx80_arcsin(floatx80 rFm
);
19 floatx80
floatx80_arctan(floatx80 rFm
);
20 floatx80
floatx80_log(floatx80 rFm
);
21 floatx80
floatx80_tan(floatx80 rFm
);
22 floatx80
floatx80_arccos(floatx80 rFm
);
23 floatx80
floatx80_pow(floatx80 rFn
, floatx80 rFm
);
24 floatx80
floatx80_pol(floatx80 rFn
, floatx80 rFm
);
26 static floatx80
floatx80_rsf(struct roundingData
*roundData
, floatx80 rFn
, floatx80 rFm
)
28 return floatx80_sub(roundData
, rFm
, rFn
);
31 static floatx80
floatx80_rdv(struct roundingData
*roundData
, floatx80 rFn
, floatx80 rFm
)
33 return floatx80_div(roundData
, rFm
, rFn
);
36 static floatx80 (*const dyadic_extended
[16])(struct roundingData
*, floatx80 rFn
, floatx80 rFm
) = {
37 [ADF_CODE
>> 20] = floatx80_add
,
38 [MUF_CODE
>> 20] = floatx80_mul
,
39 [SUF_CODE
>> 20] = floatx80_sub
,
40 [RSF_CODE
>> 20] = floatx80_rsf
,
41 [DVF_CODE
>> 20] = floatx80_div
,
42 [RDF_CODE
>> 20] = floatx80_rdv
,
43 [RMF_CODE
>> 20] = floatx80_rem
,
45 /* strictly, these opcodes should not be implemented */
46 [FML_CODE
>> 20] = floatx80_mul
,
47 [FDV_CODE
>> 20] = floatx80_div
,
48 [FRD_CODE
>> 20] = floatx80_rdv
,
51 static floatx80
floatx80_mvf(struct roundingData
*roundData
, floatx80 rFm
)
56 static floatx80
floatx80_mnf(struct roundingData
*roundData
, floatx80 rFm
)
62 static floatx80
floatx80_abs(struct roundingData
*roundData
, floatx80 rFm
)
68 static floatx80 (*const monadic_extended
[16])(struct roundingData
*, floatx80 rFm
) = {
69 [MVF_CODE
>> 20] = floatx80_mvf
,
70 [MNF_CODE
>> 20] = floatx80_mnf
,
71 [ABS_CODE
>> 20] = floatx80_abs
,
72 [RND_CODE
>> 20] = floatx80_round_to_int
,
73 [URD_CODE
>> 20] = floatx80_round_to_int
,
74 [SQT_CODE
>> 20] = floatx80_sqrt
,
75 [NRM_CODE
>> 20] = floatx80_mvf
,
78 unsigned int ExtendedCPDO(struct roundingData
*roundData
, const unsigned int opcode
, FPREG
* rFd
)
80 FPA11
*fpa11
= GET_FPA11();
82 unsigned int Fm
, opc_mask_shift
;
85 if (CONSTANT_FM(opcode
)) {
86 rFm
= getExtendedConstant(Fm
);
88 switch (fpa11
->fType
[Fm
]) {
90 rFm
= float32_to_floatx80(fpa11
->fpreg
[Fm
].fSingle
);
94 rFm
= float64_to_floatx80(fpa11
->fpreg
[Fm
].fDouble
);
98 rFm
= fpa11
->fpreg
[Fm
].fExtended
;
106 opc_mask_shift
= (opcode
& MASK_ARITHMETIC_OPCODE
) >> 20;
107 if (!MONADIC_INSTRUCTION(opcode
)) {
108 unsigned int Fn
= getFn(opcode
);
111 switch (fpa11
->fType
[Fn
]) {
113 rFn
= float32_to_floatx80(fpa11
->fpreg
[Fn
].fSingle
);
117 rFn
= float64_to_floatx80(fpa11
->fpreg
[Fn
].fDouble
);
121 rFn
= fpa11
->fpreg
[Fn
].fExtended
;
128 if (dyadic_extended
[opc_mask_shift
]) {
129 rFd
->fExtended
= dyadic_extended
[opc_mask_shift
](roundData
, rFn
, rFm
);
134 if (monadic_extended
[opc_mask_shift
]) {
135 rFd
->fExtended
= monadic_extended
[opc_mask_shift
](roundData
, rFm
);