Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * FPU op helpers |
| 3 | * |
| 4 | * Copyright (c) 2003-2005 Fabrice Bellard |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "cpu.h" |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 21 | #include "helper.h" |
| 22 | |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 23 | #define QT0 (env->qt0) |
| 24 | #define QT1 (env->qt1) |
| 25 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 26 | static void check_ieee_exceptions(CPUSPARCState *env) |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 27 | { |
| 28 | target_ulong status; |
| 29 | |
| 30 | status = get_float_exception_flags(&env->fp_status); |
| 31 | if (status) { |
| 32 | /* Copy IEEE 754 flags into FSR */ |
| 33 | if (status & float_flag_invalid) { |
| 34 | env->fsr |= FSR_NVC; |
| 35 | } |
| 36 | if (status & float_flag_overflow) { |
| 37 | env->fsr |= FSR_OFC; |
| 38 | } |
| 39 | if (status & float_flag_underflow) { |
| 40 | env->fsr |= FSR_UFC; |
| 41 | } |
| 42 | if (status & float_flag_divbyzero) { |
| 43 | env->fsr |= FSR_DZC; |
| 44 | } |
| 45 | if (status & float_flag_inexact) { |
| 46 | env->fsr |= FSR_NXC; |
| 47 | } |
| 48 | |
| 49 | if ((env->fsr & FSR_CEXC_MASK) & ((env->fsr & FSR_TEM_MASK) >> 23)) { |
| 50 | /* Unmasked exception, generate a trap */ |
| 51 | env->fsr |= FSR_FTT_IEEE_EXCP; |
| 52 | helper_raise_exception(env, TT_FP_EXCP); |
| 53 | } else { |
| 54 | /* Accumulate exceptions */ |
| 55 | env->fsr |= (env->fsr & FSR_CEXC_MASK) << 5; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 60 | static inline void clear_float_exceptions(CPUSPARCState *env) |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 61 | { |
| 62 | set_float_exception_flags(0, &env->fp_status); |
| 63 | } |
| 64 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 65 | #define F_HELPER(name, p) void helper_f##name##p(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 66 | |
| 67 | #define F_BINOP(name) \ |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 68 | float32 helper_f ## name ## s (CPUSPARCState *env, float32 src1, \ |
Blue Swirl | 2e2f4ad | 2011-07-03 10:42:23 +0000 | [diff] [blame] | 69 | float32 src2) \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 70 | { \ |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 71 | float32 ret; \ |
| 72 | clear_float_exceptions(env); \ |
| 73 | ret = float32_ ## name (src1, src2, &env->fp_status); \ |
| 74 | check_ieee_exceptions(env); \ |
| 75 | return ret; \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 76 | } \ |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 77 | float64 helper_f ## name ## d (CPUSPARCState * env, float64 src1,\ |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 78 | float64 src2) \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 79 | { \ |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 80 | float64 ret; \ |
| 81 | clear_float_exceptions(env); \ |
| 82 | ret = float64_ ## name (src1, src2, &env->fp_status); \ |
| 83 | check_ieee_exceptions(env); \ |
| 84 | return ret; \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 85 | } \ |
| 86 | F_HELPER(name, q) \ |
| 87 | { \ |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 88 | clear_float_exceptions(env); \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 89 | QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \ |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 90 | check_ieee_exceptions(env); \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | F_BINOP(add); |
| 94 | F_BINOP(sub); |
| 95 | F_BINOP(mul); |
| 96 | F_BINOP(div); |
| 97 | #undef F_BINOP |
| 98 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 99 | float64 helper_fsmuld(CPUSPARCState *env, float32 src1, float32 src2) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 100 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 101 | float64 ret; |
| 102 | clear_float_exceptions(env); |
| 103 | ret = float64_mul(float32_to_float64(src1, &env->fp_status), |
| 104 | float32_to_float64(src2, &env->fp_status), |
| 105 | &env->fp_status); |
| 106 | check_ieee_exceptions(env); |
| 107 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 110 | void helper_fdmulq(CPUSPARCState *env, float64 src1, float64 src2) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 111 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 112 | clear_float_exceptions(env); |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 113 | QT0 = float128_mul(float64_to_float128(src1, &env->fp_status), |
| 114 | float64_to_float128(src2, &env->fp_status), |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 115 | &env->fp_status); |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 116 | check_ieee_exceptions(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | float32 helper_fnegs(float32 src) |
| 120 | { |
| 121 | return float32_chs(src); |
| 122 | } |
| 123 | |
| 124 | #ifdef TARGET_SPARC64 |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 125 | float64 helper_fnegd(float64 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 126 | { |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 127 | return float64_chs(src); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | F_HELPER(neg, q) |
| 131 | { |
| 132 | QT0 = float128_chs(QT1); |
| 133 | } |
| 134 | #endif |
| 135 | |
| 136 | /* Integer to float conversion. */ |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 137 | float32 helper_fitos(CPUSPARCState *env, int32_t src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 138 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 139 | /* Inexact error possible converting int to float. */ |
| 140 | float32 ret; |
| 141 | clear_float_exceptions(env); |
| 142 | ret = int32_to_float32(src, &env->fp_status); |
| 143 | check_ieee_exceptions(env); |
| 144 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 147 | float64 helper_fitod(CPUSPARCState *env, int32_t src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 148 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 149 | /* No possible exceptions converting int to double. */ |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 150 | return int32_to_float64(src, &env->fp_status); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 153 | void helper_fitoq(CPUSPARCState *env, int32_t src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 154 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 155 | /* No possible exceptions converting int to long double. */ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 156 | QT0 = int32_to_float128(src, &env->fp_status); |
| 157 | } |
| 158 | |
| 159 | #ifdef TARGET_SPARC64 |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 160 | float32 helper_fxtos(CPUSPARCState *env, int64_t src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 161 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 162 | float32 ret; |
| 163 | clear_float_exceptions(env); |
| 164 | ret = int64_to_float32(src, &env->fp_status); |
| 165 | check_ieee_exceptions(env); |
| 166 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 169 | float64 helper_fxtod(CPUSPARCState *env, int64_t src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 170 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 171 | float64 ret; |
| 172 | clear_float_exceptions(env); |
| 173 | ret = int64_to_float64(src, &env->fp_status); |
| 174 | check_ieee_exceptions(env); |
| 175 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 178 | void helper_fxtoq(CPUSPARCState *env, int64_t src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 179 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 180 | /* No possible exceptions converting long long to long double. */ |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 181 | QT0 = int64_to_float128(src, &env->fp_status); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 182 | } |
| 183 | #endif |
| 184 | #undef F_HELPER |
| 185 | |
| 186 | /* floating point conversion */ |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 187 | float32 helper_fdtos(CPUSPARCState *env, float64 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 188 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 189 | float32 ret; |
| 190 | clear_float_exceptions(env); |
| 191 | ret = float64_to_float32(src, &env->fp_status); |
| 192 | check_ieee_exceptions(env); |
| 193 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 196 | float64 helper_fstod(CPUSPARCState *env, float32 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 197 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 198 | float64 ret; |
| 199 | clear_float_exceptions(env); |
| 200 | ret = float32_to_float64(src, &env->fp_status); |
| 201 | check_ieee_exceptions(env); |
| 202 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 205 | float32 helper_fqtos(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 206 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 207 | float32 ret; |
| 208 | clear_float_exceptions(env); |
| 209 | ret = float128_to_float32(QT1, &env->fp_status); |
| 210 | check_ieee_exceptions(env); |
| 211 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 214 | void helper_fstoq(CPUSPARCState *env, float32 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 215 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 216 | clear_float_exceptions(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 217 | QT0 = float32_to_float128(src, &env->fp_status); |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 218 | check_ieee_exceptions(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 221 | float64 helper_fqtod(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 222 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 223 | float64 ret; |
| 224 | clear_float_exceptions(env); |
| 225 | ret = float128_to_float64(QT1, &env->fp_status); |
| 226 | check_ieee_exceptions(env); |
| 227 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 230 | void helper_fdtoq(CPUSPARCState *env, float64 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 231 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 232 | clear_float_exceptions(env); |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 233 | QT0 = float64_to_float128(src, &env->fp_status); |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 234 | check_ieee_exceptions(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* Float to integer conversion. */ |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 238 | int32_t helper_fstoi(CPUSPARCState *env, float32 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 239 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 240 | int32_t ret; |
| 241 | clear_float_exceptions(env); |
| 242 | ret = float32_to_int32_round_to_zero(src, &env->fp_status); |
| 243 | check_ieee_exceptions(env); |
| 244 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 247 | int32_t helper_fdtoi(CPUSPARCState *env, float64 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 248 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 249 | int32_t ret; |
| 250 | clear_float_exceptions(env); |
| 251 | ret = float64_to_int32_round_to_zero(src, &env->fp_status); |
| 252 | check_ieee_exceptions(env); |
| 253 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 256 | int32_t helper_fqtoi(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 257 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 258 | int32_t ret; |
| 259 | clear_float_exceptions(env); |
| 260 | ret = float128_to_int32_round_to_zero(QT1, &env->fp_status); |
| 261 | check_ieee_exceptions(env); |
| 262 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | #ifdef TARGET_SPARC64 |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 266 | int64_t helper_fstox(CPUSPARCState *env, float32 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 267 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 268 | int64_t ret; |
| 269 | clear_float_exceptions(env); |
| 270 | ret = float32_to_int64_round_to_zero(src, &env->fp_status); |
| 271 | check_ieee_exceptions(env); |
| 272 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 275 | int64_t helper_fdtox(CPUSPARCState *env, float64 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 276 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 277 | int64_t ret; |
| 278 | clear_float_exceptions(env); |
| 279 | ret = float64_to_int64_round_to_zero(src, &env->fp_status); |
| 280 | check_ieee_exceptions(env); |
| 281 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 284 | int64_t helper_fqtox(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 285 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 286 | int64_t ret; |
| 287 | clear_float_exceptions(env); |
| 288 | ret = float128_to_int64_round_to_zero(QT1, &env->fp_status); |
| 289 | check_ieee_exceptions(env); |
| 290 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 291 | } |
| 292 | #endif |
| 293 | |
| 294 | float32 helper_fabss(float32 src) |
| 295 | { |
| 296 | return float32_abs(src); |
| 297 | } |
| 298 | |
| 299 | #ifdef TARGET_SPARC64 |
Richard Henderson | f027c3b | 2011-10-19 14:56:43 -0700 | [diff] [blame] | 300 | float64 helper_fabsd(float64 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 301 | { |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 302 | return float64_abs(src); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 305 | void helper_fabsq(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 306 | { |
| 307 | QT0 = float128_abs(QT1); |
| 308 | } |
| 309 | #endif |
| 310 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 311 | float32 helper_fsqrts(CPUSPARCState *env, float32 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 312 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 313 | float32 ret; |
| 314 | clear_float_exceptions(env); |
| 315 | ret = float32_sqrt(src, &env->fp_status); |
| 316 | check_ieee_exceptions(env); |
| 317 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 320 | float64 helper_fsqrtd(CPUSPARCState *env, float64 src) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 321 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 322 | float64 ret; |
| 323 | clear_float_exceptions(env); |
| 324 | ret = float64_sqrt(src, &env->fp_status); |
| 325 | check_ieee_exceptions(env); |
| 326 | return ret; |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 329 | void helper_fsqrtq(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 330 | { |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 331 | clear_float_exceptions(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 332 | QT0 = float128_sqrt(QT1, &env->fp_status); |
Richard Henderson | 4451677 | 2011-10-17 11:25:56 -0700 | [diff] [blame] | 333 | check_ieee_exceptions(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | #define GEN_FCMP(name, size, reg1, reg2, FS, E) \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 337 | void glue(helper_, name) (CPUSPARCState *env) \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 338 | { \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 339 | int ret; \ |
| 340 | clear_float_exceptions(env); \ |
| 341 | if (E) { \ |
| 342 | ret = glue(size, _compare)(reg1, reg2, &env->fp_status); \ |
| 343 | } else { \ |
| 344 | ret = glue(size, _compare_quiet)(reg1, reg2, \ |
| 345 | &env->fp_status); \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 346 | } \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 347 | check_ieee_exceptions(env); \ |
| 348 | switch (ret) { \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 349 | case float_relation_unordered: \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 350 | env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \ |
| 351 | env->fsr |= FSR_NVA; \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 352 | break; \ |
| 353 | case float_relation_less: \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 354 | env->fsr &= ~(FSR_FCC1) << FS; \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 355 | env->fsr |= FSR_FCC0 << FS; \ |
| 356 | break; \ |
| 357 | case float_relation_greater: \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 358 | env->fsr &= ~(FSR_FCC0) << FS; \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 359 | env->fsr |= FSR_FCC1 << FS; \ |
| 360 | break; \ |
| 361 | default: \ |
| 362 | env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \ |
| 363 | break; \ |
| 364 | } \ |
| 365 | } |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 366 | #define GEN_FCMP_T(name, size, FS, E) \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 367 | void glue(helper_, name)(CPUSPARCState *env, size src1, size src2) \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 368 | { \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 369 | int ret; \ |
| 370 | clear_float_exceptions(env); \ |
| 371 | if (E) { \ |
| 372 | ret = glue(size, _compare)(src1, src2, &env->fp_status); \ |
| 373 | } else { \ |
| 374 | ret = glue(size, _compare_quiet)(src1, src2, \ |
| 375 | &env->fp_status); \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 376 | } \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 377 | check_ieee_exceptions(env); \ |
| 378 | switch (ret) { \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 379 | case float_relation_unordered: \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 380 | env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 381 | break; \ |
| 382 | case float_relation_less: \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 383 | env->fsr &= ~(FSR_FCC1 << FS); \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 384 | env->fsr |= FSR_FCC0 << FS; \ |
| 385 | break; \ |
| 386 | case float_relation_greater: \ |
Aurelien Jarno | 5acfc83 | 2012-09-07 17:13:28 +0200 | [diff] [blame] | 387 | env->fsr &= ~(FSR_FCC0 << FS); \ |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 388 | env->fsr |= FSR_FCC1 << FS; \ |
| 389 | break; \ |
| 390 | default: \ |
| 391 | env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \ |
| 392 | break; \ |
| 393 | } \ |
| 394 | } |
| 395 | |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 396 | GEN_FCMP_T(fcmps, float32, 0, 0); |
| 397 | GEN_FCMP_T(fcmpd, float64, 0, 0); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 398 | |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 399 | GEN_FCMP_T(fcmpes, float32, 0, 1); |
| 400 | GEN_FCMP_T(fcmped, float64, 0, 1); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 401 | |
| 402 | GEN_FCMP(fcmpq, float128, QT0, QT1, 0, 0); |
| 403 | GEN_FCMP(fcmpeq, float128, QT0, QT1, 0, 1); |
| 404 | |
| 405 | #ifdef TARGET_SPARC64 |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 406 | GEN_FCMP_T(fcmps_fcc1, float32, 22, 0); |
| 407 | GEN_FCMP_T(fcmpd_fcc1, float64, 22, 0); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 408 | GEN_FCMP(fcmpq_fcc1, float128, QT0, QT1, 22, 0); |
| 409 | |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 410 | GEN_FCMP_T(fcmps_fcc2, float32, 24, 0); |
| 411 | GEN_FCMP_T(fcmpd_fcc2, float64, 24, 0); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 412 | GEN_FCMP(fcmpq_fcc2, float128, QT0, QT1, 24, 0); |
| 413 | |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 414 | GEN_FCMP_T(fcmps_fcc3, float32, 26, 0); |
| 415 | GEN_FCMP_T(fcmpd_fcc3, float64, 26, 0); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 416 | GEN_FCMP(fcmpq_fcc3, float128, QT0, QT1, 26, 0); |
| 417 | |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 418 | GEN_FCMP_T(fcmpes_fcc1, float32, 22, 1); |
| 419 | GEN_FCMP_T(fcmped_fcc1, float64, 22, 1); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 420 | GEN_FCMP(fcmpeq_fcc1, float128, QT0, QT1, 22, 1); |
| 421 | |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 422 | GEN_FCMP_T(fcmpes_fcc2, float32, 24, 1); |
| 423 | GEN_FCMP_T(fcmped_fcc2, float64, 24, 1); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 424 | GEN_FCMP(fcmpeq_fcc2, float128, QT0, QT1, 24, 1); |
| 425 | |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 426 | GEN_FCMP_T(fcmpes_fcc3, float32, 26, 1); |
| 427 | GEN_FCMP_T(fcmped_fcc3, float64, 26, 1); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 428 | GEN_FCMP(fcmpeq_fcc3, float128, QT0, QT1, 26, 1); |
| 429 | #endif |
Richard Henderson | 03fb8cf | 2011-10-15 10:20:20 -0700 | [diff] [blame] | 430 | #undef GEN_FCMP_T |
| 431 | #undef GEN_FCMP |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 432 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 433 | static inline void set_fsr(CPUSPARCState *env) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 434 | { |
| 435 | int rnd_mode; |
| 436 | |
| 437 | switch (env->fsr & FSR_RD_MASK) { |
| 438 | case FSR_RD_NEAREST: |
| 439 | rnd_mode = float_round_nearest_even; |
| 440 | break; |
| 441 | default: |
| 442 | case FSR_RD_ZERO: |
| 443 | rnd_mode = float_round_to_zero; |
| 444 | break; |
| 445 | case FSR_RD_POS: |
| 446 | rnd_mode = float_round_up; |
| 447 | break; |
| 448 | case FSR_RD_NEG: |
| 449 | rnd_mode = float_round_down; |
| 450 | break; |
| 451 | } |
| 452 | set_float_rounding_mode(rnd_mode, &env->fp_status); |
| 453 | } |
| 454 | |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 455 | void helper_ldfsr(CPUSPARCState *env, uint32_t new_fsr) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 456 | { |
| 457 | env->fsr = (new_fsr & FSR_LDFSR_MASK) | (env->fsr & FSR_LDFSR_OLDMASK); |
Blue Swirl | 2e2f4ad | 2011-07-03 10:42:23 +0000 | [diff] [blame] | 458 | set_fsr(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | #ifdef TARGET_SPARC64 |
Andreas Färber | c5f9864 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 462 | void helper_ldxfsr(CPUSPARCState *env, uint64_t new_fsr) |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 463 | { |
| 464 | env->fsr = (new_fsr & FSR_LDXFSR_MASK) | (env->fsr & FSR_LDXFSR_OLDMASK); |
Blue Swirl | 2e2f4ad | 2011-07-03 10:42:23 +0000 | [diff] [blame] | 465 | set_fsr(env); |
Blue Swirl | 1bccec2 | 2011-08-01 07:37:45 +0000 | [diff] [blame] | 466 | } |
| 467 | #endif |