]> Git Repo - qemu.git/blob - target/m68k/fpu_helper.c
target-m68k: use floatx80 internally
[qemu.git] / target / m68k / fpu_helper.c
1 /*
2  *  m68k FPU helpers
3  *
4  *  Copyright (c) 2006-2007 CodeSourcery
5  *  Written by Paul Brook
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "qemu/osdep.h"
22 #include "cpu.h"
23 #include "exec/helper-proto.h"
24 #include "exec/exec-all.h"
25
26 int32_t HELPER(reds32)(CPUM68KState *env, FPReg *val)
27 {
28     return floatx80_to_int32(val->d, &env->fp_status);
29 }
30
31 float32 HELPER(redf32)(CPUM68KState *env, FPReg *val)
32 {
33     return floatx80_to_float32(val->d, &env->fp_status);
34 }
35
36 void HELPER(exts32)(CPUM68KState *env, FPReg *res, int32_t val)
37 {
38     res->d = int32_to_floatx80(val, &env->fp_status);
39 }
40
41 void HELPER(extf32)(CPUM68KState *env, FPReg *res, float32 val)
42 {
43     res->d = float32_to_floatx80(val, &env->fp_status);
44 }
45
46 void HELPER(extf64)(CPUM68KState *env, FPReg *res, float64 val)
47 {
48     res->d = float64_to_floatx80(val, &env->fp_status);
49 }
50
51 float64 HELPER(redf64)(CPUM68KState *env, FPReg *val)
52 {
53     return floatx80_to_float64(val->d, &env->fp_status);
54 }
55
56 void HELPER(firound)(CPUM68KState *env, FPReg *res, FPReg *val)
57 {
58     res->d = floatx80_round_to_int(val->d, &env->fp_status);
59 }
60
61 void HELPER(fitrunc)(CPUM68KState *env, FPReg *res, FPReg *val)
62 {
63     res->d = floatx80_round_to_int(val->d, &env->fp_status);
64 }
65
66 void HELPER(fsqrt)(CPUM68KState *env, FPReg *res, FPReg *val)
67 {
68     res->d = floatx80_sqrt(val->d, &env->fp_status);
69 }
70
71 void HELPER(fabs)(CPUM68KState *env, FPReg *res, FPReg *val)
72 {
73     res->d = floatx80_abs(val->d);
74 }
75
76 void HELPER(fchs)(CPUM68KState *env, FPReg *res, FPReg *val)
77 {
78     res->d = floatx80_chs(val->d);
79 }
80
81 void HELPER(fadd)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
82 {
83     res->d = floatx80_add(val0->d, val1->d, &env->fp_status);
84 }
85
86 void HELPER(fsub)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
87 {
88     res->d = floatx80_sub(val1->d, val0->d, &env->fp_status);
89 }
90
91 void HELPER(fmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
92 {
93     res->d = floatx80_mul(val0->d, val1->d, &env->fp_status);
94 }
95
96 void HELPER(fdiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
97 {
98     res->d = floatx80_div(val1->d, val0->d, &env->fp_status);
99 }
100
101 void HELPER(fsub_cmp)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
102 {
103     /* ??? This may incorrectly raise exceptions.  */
104     /* ??? Should flush denormals to zero.  */
105     res->d = floatx80_sub(val0->d, val1->d, &env->fp_status);
106     if (floatx80_is_quiet_nan(res->d, &env->fp_status)) {
107         /* +/-inf compares equal against itself, but sub returns nan.  */
108         if (!floatx80_is_quiet_nan(val0->d, &env->fp_status)
109             && !floatx80_is_quiet_nan(val1->d, &env->fp_status)) {
110             res->d = floatx80_zero;
111             if (floatx80_lt_quiet(val0->d, res->d, &env->fp_status)) {
112                 res->d = floatx80_chs(res->d);
113             }
114         }
115     }
116 }
117
118 uint32_t HELPER(fcompare)(CPUM68KState *env, FPReg *val)
119 {
120     return floatx80_compare_quiet(val->d, floatx80_zero, &env->fp_status);
121 }
This page took 0.028892 seconds and 4 git commands to generate.