blob: c66981d682cfe89d9bbfb01c8d71a0db20938be5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 NetWinder Floating Point Emulator
3 (c) Rebel.COM, 1998,1999
4 (c) Philip Blundell, 2001
5
6 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#include "fpa11.h"
24#include "softfloat.h"
25#include "fpopcode.h"
26
27float32 float32_exp(float32 Fm);
28float32 float32_ln(float32 Fm);
29float32 float32_sin(float32 rFm);
30float32 float32_cos(float32 rFm);
31float32 float32_arcsin(float32 rFm);
32float32 float32_arctan(float32 rFm);
33float32 float32_log(float32 rFm);
34float32 float32_tan(float32 rFm);
35float32 float32_arccos(float32 rFm);
36float32 float32_pow(float32 rFn, float32 rFm);
37float32 float32_pol(float32 rFn, float32 rFm);
38
Richard Purdief148af22005-08-03 19:49:17 +010039static float32 float32_rsf(struct roundingData *roundData, float32 rFn, float32 rFm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Richard Purdief148af22005-08-03 19:49:17 +010041 return float32_sub(roundData, rFm, rFn);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Richard Purdief148af22005-08-03 19:49:17 +010044static float32 float32_rdv(struct roundingData *roundData, float32 rFn, float32 rFm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Richard Purdief148af22005-08-03 19:49:17 +010046 return float32_div(roundData, rFm, rFn);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Richard Purdief148af22005-08-03 19:49:17 +010049static float32 (*const dyadic_single[16])(struct roundingData *, float32 rFn, float32 rFm) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 [ADF_CODE >> 20] = float32_add,
51 [MUF_CODE >> 20] = float32_mul,
52 [SUF_CODE >> 20] = float32_sub,
53 [RSF_CODE >> 20] = float32_rsf,
54 [DVF_CODE >> 20] = float32_div,
55 [RDF_CODE >> 20] = float32_rdv,
56 [RMF_CODE >> 20] = float32_rem,
57
58 [FML_CODE >> 20] = float32_mul,
59 [FDV_CODE >> 20] = float32_div,
60 [FRD_CODE >> 20] = float32_rdv,
61};
62
Richard Purdief148af22005-08-03 19:49:17 +010063static float32 float32_mvf(struct roundingData *roundData, float32 rFm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 return rFm;
66}
67
Richard Purdief148af22005-08-03 19:49:17 +010068static float32 float32_mnf(struct roundingData *roundData, float32 rFm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 return rFm ^ 0x80000000;
71}
72
Richard Purdief148af22005-08-03 19:49:17 +010073static float32 float32_abs(struct roundingData *roundData, float32 rFm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 return rFm & 0x7fffffff;
76}
77
Richard Purdief148af22005-08-03 19:49:17 +010078static float32 (*const monadic_single[16])(struct roundingData*, float32 rFm) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 [MVF_CODE >> 20] = float32_mvf,
80 [MNF_CODE >> 20] = float32_mnf,
81 [ABS_CODE >> 20] = float32_abs,
82 [RND_CODE >> 20] = float32_round_to_int,
83 [URD_CODE >> 20] = float32_round_to_int,
84 [SQT_CODE >> 20] = float32_sqrt,
85 [NRM_CODE >> 20] = float32_mvf,
86};
87
Richard Purdief148af22005-08-03 19:49:17 +010088unsigned int SingleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 FPA11 *fpa11 = GET_FPA11();
91 float32 rFm;
92 unsigned int Fm, opc_mask_shift;
93
94 Fm = getFm(opcode);
95 if (CONSTANT_FM(opcode)) {
96 rFm = getSingleConstant(Fm);
97 } else if (fpa11->fType[Fm] == typeSingle) {
98 rFm = fpa11->fpreg[Fm].fSingle;
99 } else {
100 return 0;
101 }
102
103 opc_mask_shift = (opcode & MASK_ARITHMETIC_OPCODE) >> 20;
104 if (!MONADIC_INSTRUCTION(opcode)) {
105 unsigned int Fn = getFn(opcode);
106 float32 rFn;
107
108 if (fpa11->fType[Fn] == typeSingle &&
109 dyadic_single[opc_mask_shift]) {
110 rFn = fpa11->fpreg[Fn].fSingle;
Richard Purdief148af22005-08-03 19:49:17 +0100111 rFd->fSingle = dyadic_single[opc_mask_shift](roundData, rFn, rFm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 } else {
113 return 0;
114 }
115 } else {
116 if (monadic_single[opc_mask_shift]) {
Richard Purdief148af22005-08-03 19:49:17 +0100117 rFd->fSingle = monadic_single[opc_mask_shift](roundData, rFm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 } else {
119 return 0;
120 }
121 }
122
123 return 1;
124}