bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SH4 emulation |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 4 | * Copyright (c) 2005 Samuel Tardieu |
| 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 |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 18 | */ |
| 19 | #include <assert.h> |
edgar_igl | 852d481 | 2009-04-01 23:10:46 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
Blue Swirl | 3e45717 | 2011-07-13 12:44:15 +0000 | [diff] [blame] | 21 | #include "cpu.h" |
| 22 | #include "dyngen-exec.h" |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 23 | #include "helper.h" |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 24 | |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 25 | static void cpu_restore_state_from_retaddr(uintptr_t retaddr) |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 26 | { |
| 27 | TranslationBlock *tb; |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 28 | |
| 29 | if (retaddr) { |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 30 | tb = tb_find_pc(retaddr); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 31 | if (tb) { |
| 32 | /* the PC is inside the translated code. It means that we have |
| 33 | a virtual CPU fault */ |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 34 | cpu_restore_state(tb, env, retaddr); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 39 | #ifndef CONFIG_USER_ONLY |
Blue Swirl | 3e45717 | 2011-07-13 12:44:15 +0000 | [diff] [blame] | 40 | #include "softmmu_exec.h" |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 41 | |
| 42 | #define MMUSUFFIX _mmu |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 43 | |
| 44 | #define SHIFT 0 |
| 45 | #include "softmmu_template.h" |
| 46 | |
| 47 | #define SHIFT 1 |
| 48 | #include "softmmu_template.h" |
| 49 | |
| 50 | #define SHIFT 2 |
| 51 | #include "softmmu_template.h" |
| 52 | |
| 53 | #define SHIFT 3 |
| 54 | #include "softmmu_template.h" |
| 55 | |
Andreas Färber | 73e5716 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 56 | void tlb_fill(CPUSH4State *env1, target_ulong addr, int is_write, int mmu_idx, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 57 | uintptr_t retaddr) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 58 | { |
Andreas Färber | 73e5716 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 59 | CPUSH4State *saved_env; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 60 | int ret; |
| 61 | |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 62 | saved_env = env; |
Blue Swirl | bccd9ec | 2011-07-04 20:57:05 +0000 | [diff] [blame] | 63 | env = env1; |
Blue Swirl | 97b348e | 2011-08-01 16:12:17 +0000 | [diff] [blame] | 64 | ret = cpu_sh4_handle_mmu_fault(env, addr, is_write, mmu_idx); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 65 | if (ret) { |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 66 | /* now we have a real cpu fault */ |
| 67 | cpu_restore_state_from_retaddr(retaddr); |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 68 | cpu_loop_exit(env); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 69 | } |
| 70 | env = saved_env; |
| 71 | } |
| 72 | |
| 73 | #endif |
| 74 | |
aurel32 | ea2b542 | 2008-05-09 18:45:55 +0000 | [diff] [blame] | 75 | void helper_ldtlb(void) |
| 76 | { |
| 77 | #ifdef CONFIG_USER_ONLY |
| 78 | /* XXXXX */ |
Blue Swirl | 43dc2a6 | 2010-03-18 18:41:57 +0000 | [diff] [blame] | 79 | cpu_abort(env, "Unhandled ldtlb"); |
aurel32 | ea2b542 | 2008-05-09 18:45:55 +0000 | [diff] [blame] | 80 | #else |
| 81 | cpu_load_tlb(env); |
| 82 | #endif |
| 83 | } |
| 84 | |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 85 | static inline void raise_exception(int index, uintptr_t retaddr) |
Aurelien Jarno | fd4bab1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 86 | { |
| 87 | env->exception_index = index; |
| 88 | cpu_restore_state_from_retaddr(retaddr); |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 89 | cpu_loop_exit(env); |
Aurelien Jarno | fd4bab1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 90 | } |
| 91 | |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 92 | void helper_raise_illegal_instruction(void) |
| 93 | { |
Aurelien Jarno | fd4bab1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 94 | raise_exception(0x180, GETPC()); |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void helper_raise_slot_illegal_instruction(void) |
| 98 | { |
Aurelien Jarno | fd4bab1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 99 | raise_exception(0x1a0, GETPC()); |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 100 | } |
| 101 | |
aurel32 | d8299bc | 2008-12-07 22:46:31 +0000 | [diff] [blame] | 102 | void helper_raise_fpu_disable(void) |
| 103 | { |
Aurelien Jarno | fd4bab1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 104 | raise_exception(0x800, GETPC()); |
aurel32 | d8299bc | 2008-12-07 22:46:31 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void helper_raise_slot_fpu_disable(void) |
| 108 | { |
Aurelien Jarno | fd4bab1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 109 | raise_exception(0x820, GETPC()); |
aurel32 | d8299bc | 2008-12-07 22:46:31 +0000 | [diff] [blame] | 110 | } |
| 111 | |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 112 | void helper_debug(void) |
| 113 | { |
| 114 | env->exception_index = EXCP_DEBUG; |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 115 | cpu_loop_exit(env); |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 116 | } |
| 117 | |
aurel32 | f24f381 | 2008-09-15 06:42:30 +0000 | [diff] [blame] | 118 | void helper_sleep(uint32_t next_pc) |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 119 | { |
| 120 | env->halted = 1; |
Aurelien Jarno | efac415 | 2011-02-24 12:31:41 +0100 | [diff] [blame] | 121 | env->in_sleep = 1; |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 122 | env->exception_index = EXCP_HLT; |
aurel32 | f24f381 | 2008-09-15 06:42:30 +0000 | [diff] [blame] | 123 | env->pc = next_pc; |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 124 | cpu_loop_exit(env); |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void helper_trapa(uint32_t tra) |
| 128 | { |
| 129 | env->tra = tra << 2; |
Aurelien Jarno | fd4bab1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 130 | raise_exception(0x160, GETPC()); |
aurel32 | e6afc2f | 2008-08-29 23:01:41 +0000 | [diff] [blame] | 131 | } |
| 132 | |
edgar_igl | 852d481 | 2009-04-01 23:10:46 +0000 | [diff] [blame] | 133 | void helper_movcal(uint32_t address, uint32_t value) |
| 134 | { |
| 135 | if (cpu_sh4_is_cached (env, address)) |
| 136 | { |
| 137 | memory_content *r = malloc (sizeof(memory_content)); |
| 138 | r->address = address; |
| 139 | r->value = value; |
| 140 | r->next = NULL; |
| 141 | |
| 142 | *(env->movcal_backup_tail) = r; |
| 143 | env->movcal_backup_tail = &(r->next); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void helper_discard_movcal_backup(void) |
| 148 | { |
| 149 | memory_content *current = env->movcal_backup; |
| 150 | |
| 151 | while(current) |
| 152 | { |
| 153 | memory_content *next = current->next; |
| 154 | free (current); |
| 155 | env->movcal_backup = current = next; |
Blue Swirl | b9d38e9 | 2009-09-21 18:11:34 +0000 | [diff] [blame] | 156 | if (current == NULL) |
edgar_igl | 852d481 | 2009-04-01 23:10:46 +0000 | [diff] [blame] | 157 | env->movcal_backup_tail = &(env->movcal_backup); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void helper_ocbi(uint32_t address) |
| 162 | { |
| 163 | memory_content **current = &(env->movcal_backup); |
| 164 | while (*current) |
| 165 | { |
| 166 | uint32_t a = (*current)->address; |
| 167 | if ((a & ~0x1F) == (address & ~0x1F)) |
| 168 | { |
| 169 | memory_content *next = (*current)->next; |
| 170 | stl(a, (*current)->value); |
| 171 | |
Blue Swirl | b9d38e9 | 2009-09-21 18:11:34 +0000 | [diff] [blame] | 172 | if (next == NULL) |
edgar_igl | 852d481 | 2009-04-01 23:10:46 +0000 | [diff] [blame] | 173 | { |
| 174 | env->movcal_backup_tail = current; |
| 175 | } |
| 176 | |
| 177 | free (*current); |
| 178 | *current = next; |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 184 | uint32_t helper_addc(uint32_t arg0, uint32_t arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 185 | { |
| 186 | uint32_t tmp0, tmp1; |
| 187 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 188 | tmp1 = arg0 + arg1; |
| 189 | tmp0 = arg1; |
| 190 | arg1 = tmp1 + (env->sr & 1); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 191 | if (tmp0 > tmp1) |
| 192 | env->sr |= SR_T; |
| 193 | else |
| 194 | env->sr &= ~SR_T; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 195 | if (tmp1 > arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 196 | env->sr |= SR_T; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 197 | return arg1; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 198 | } |
| 199 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 200 | uint32_t helper_addv(uint32_t arg0, uint32_t arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 201 | { |
| 202 | uint32_t dest, src, ans; |
| 203 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 204 | if ((int32_t) arg1 >= 0) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 205 | dest = 0; |
| 206 | else |
| 207 | dest = 1; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 208 | if ((int32_t) arg0 >= 0) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 209 | src = 0; |
| 210 | else |
| 211 | src = 1; |
| 212 | src += dest; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 213 | arg1 += arg0; |
| 214 | if ((int32_t) arg1 >= 0) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 215 | ans = 0; |
| 216 | else |
| 217 | ans = 1; |
| 218 | ans += dest; |
| 219 | if (src == 0 || src == 2) { |
| 220 | if (ans == 1) |
| 221 | env->sr |= SR_T; |
| 222 | else |
| 223 | env->sr &= ~SR_T; |
| 224 | } else |
| 225 | env->sr &= ~SR_T; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 226 | return arg1; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | #define T (env->sr & SR_T) |
| 230 | #define Q (env->sr & SR_Q ? 1 : 0) |
| 231 | #define M (env->sr & SR_M ? 1 : 0) |
| 232 | #define SETT env->sr |= SR_T |
| 233 | #define CLRT env->sr &= ~SR_T |
| 234 | #define SETQ env->sr |= SR_Q |
| 235 | #define CLRQ env->sr &= ~SR_Q |
| 236 | #define SETM env->sr |= SR_M |
| 237 | #define CLRM env->sr &= ~SR_M |
| 238 | |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 239 | uint32_t helper_div1(uint32_t arg0, uint32_t arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 240 | { |
| 241 | uint32_t tmp0, tmp2; |
| 242 | uint8_t old_q, tmp1 = 0xff; |
| 243 | |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 244 | //printf("div1 arg0=0x%08x arg1=0x%08x M=%d Q=%d T=%d\n", arg0, arg1, M, Q, T); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 245 | old_q = Q; |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 246 | if ((0x80000000 & arg1) != 0) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 247 | SETQ; |
| 248 | else |
| 249 | CLRQ; |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 250 | tmp2 = arg0; |
| 251 | arg1 <<= 1; |
| 252 | arg1 |= T; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 253 | switch (old_q) { |
| 254 | case 0: |
| 255 | switch (M) { |
| 256 | case 0: |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 257 | tmp0 = arg1; |
| 258 | arg1 -= tmp2; |
| 259 | tmp1 = arg1 > tmp0; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 260 | switch (Q) { |
| 261 | case 0: |
| 262 | if (tmp1) |
| 263 | SETQ; |
| 264 | else |
| 265 | CLRQ; |
| 266 | break; |
| 267 | case 1: |
| 268 | if (tmp1 == 0) |
| 269 | SETQ; |
| 270 | else |
| 271 | CLRQ; |
| 272 | break; |
| 273 | } |
| 274 | break; |
| 275 | case 1: |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 276 | tmp0 = arg1; |
| 277 | arg1 += tmp2; |
| 278 | tmp1 = arg1 < tmp0; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 279 | switch (Q) { |
| 280 | case 0: |
| 281 | if (tmp1 == 0) |
| 282 | SETQ; |
| 283 | else |
| 284 | CLRQ; |
| 285 | break; |
| 286 | case 1: |
| 287 | if (tmp1) |
| 288 | SETQ; |
| 289 | else |
| 290 | CLRQ; |
| 291 | break; |
| 292 | } |
| 293 | break; |
| 294 | } |
| 295 | break; |
| 296 | case 1: |
| 297 | switch (M) { |
| 298 | case 0: |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 299 | tmp0 = arg1; |
| 300 | arg1 += tmp2; |
| 301 | tmp1 = arg1 < tmp0; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 302 | switch (Q) { |
| 303 | case 0: |
| 304 | if (tmp1) |
| 305 | SETQ; |
| 306 | else |
| 307 | CLRQ; |
| 308 | break; |
| 309 | case 1: |
| 310 | if (tmp1 == 0) |
| 311 | SETQ; |
| 312 | else |
| 313 | CLRQ; |
| 314 | break; |
| 315 | } |
| 316 | break; |
| 317 | case 1: |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 318 | tmp0 = arg1; |
| 319 | arg1 -= tmp2; |
| 320 | tmp1 = arg1 > tmp0; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 321 | switch (Q) { |
| 322 | case 0: |
| 323 | if (tmp1 == 0) |
| 324 | SETQ; |
| 325 | else |
| 326 | CLRQ; |
| 327 | break; |
| 328 | case 1: |
| 329 | if (tmp1) |
| 330 | SETQ; |
| 331 | else |
| 332 | CLRQ; |
| 333 | break; |
| 334 | } |
| 335 | break; |
| 336 | } |
| 337 | break; |
| 338 | } |
| 339 | if (Q == M) |
| 340 | SETT; |
| 341 | else |
| 342 | CLRT; |
aurel32 | 69d6275 | 2008-09-01 13:09:06 +0000 | [diff] [blame] | 343 | //printf("Output: arg1=0x%08x M=%d Q=%d T=%d\n", arg1, M, Q, T); |
| 344 | return arg1; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 345 | } |
| 346 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 347 | void helper_macl(uint32_t arg0, uint32_t arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 348 | { |
| 349 | int64_t res; |
| 350 | |
| 351 | res = ((uint64_t) env->mach << 32) | env->macl; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 352 | res += (int64_t) (int32_t) arg0 *(int64_t) (int32_t) arg1; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 353 | env->mach = (res >> 32) & 0xffffffff; |
| 354 | env->macl = res & 0xffffffff; |
| 355 | if (env->sr & SR_S) { |
| 356 | if (res < 0) |
| 357 | env->mach |= 0xffff0000; |
| 358 | else |
| 359 | env->mach &= 0x00007fff; |
| 360 | } |
| 361 | } |
| 362 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 363 | void helper_macw(uint32_t arg0, uint32_t arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 364 | { |
| 365 | int64_t res; |
| 366 | |
| 367 | res = ((uint64_t) env->mach << 32) | env->macl; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 368 | res += (int64_t) (int16_t) arg0 *(int64_t) (int16_t) arg1; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 369 | env->mach = (res >> 32) & 0xffffffff; |
| 370 | env->macl = res & 0xffffffff; |
| 371 | if (env->sr & SR_S) { |
| 372 | if (res < -0x80000000) { |
| 373 | env->mach = 1; |
| 374 | env->macl = 0x80000000; |
| 375 | } else if (res > 0x000000007fffffff) { |
| 376 | env->mach = 1; |
| 377 | env->macl = 0x7fffffff; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 382 | uint32_t helper_subc(uint32_t arg0, uint32_t arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 383 | { |
| 384 | uint32_t tmp0, tmp1; |
| 385 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 386 | tmp1 = arg1 - arg0; |
| 387 | tmp0 = arg1; |
| 388 | arg1 = tmp1 - (env->sr & SR_T); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 389 | if (tmp0 < tmp1) |
| 390 | env->sr |= SR_T; |
| 391 | else |
| 392 | env->sr &= ~SR_T; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 393 | if (tmp1 < arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 394 | env->sr |= SR_T; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 395 | return arg1; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 396 | } |
| 397 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 398 | uint32_t helper_subv(uint32_t arg0, uint32_t arg1) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 399 | { |
| 400 | int32_t dest, src, ans; |
| 401 | |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 402 | if ((int32_t) arg1 >= 0) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 403 | dest = 0; |
| 404 | else |
| 405 | dest = 1; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 406 | if ((int32_t) arg0 >= 0) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 407 | src = 0; |
| 408 | else |
| 409 | src = 1; |
| 410 | src += dest; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 411 | arg1 -= arg0; |
| 412 | if ((int32_t) arg1 >= 0) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 413 | ans = 0; |
| 414 | else |
| 415 | ans = 1; |
| 416 | ans += dest; |
| 417 | if (src == 1) { |
| 418 | if (ans == 1) |
| 419 | env->sr |= SR_T; |
| 420 | else |
| 421 | env->sr &= ~SR_T; |
| 422 | } else |
| 423 | env->sr &= ~SR_T; |
aurel32 | 6f06939 | 2008-08-30 13:55:14 +0000 | [diff] [blame] | 424 | return arg1; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 425 | } |
| 426 | |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 427 | static inline void set_t(void) |
| 428 | { |
| 429 | env->sr |= SR_T; |
| 430 | } |
| 431 | |
| 432 | static inline void clr_t(void) |
| 433 | { |
| 434 | env->sr &= ~SR_T; |
| 435 | } |
| 436 | |
aurel32 | 390af82 | 2008-08-30 22:07:52 +0000 | [diff] [blame] | 437 | void helper_ld_fpscr(uint32_t val) |
| 438 | { |
Aurelien Jarno | 26ac1ea | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 439 | env->fpscr = val & FPSCR_MASK; |
| 440 | if ((val & FPSCR_RM_MASK) == FPSCR_RM_ZERO) { |
aurel32 | 390af82 | 2008-08-30 22:07:52 +0000 | [diff] [blame] | 441 | set_float_rounding_mode(float_round_to_zero, &env->fp_status); |
Aurelien Jarno | 26ac1ea | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 442 | } else { |
aurel32 | 390af82 | 2008-08-30 22:07:52 +0000 | [diff] [blame] | 443 | set_float_rounding_mode(float_round_nearest_even, &env->fp_status); |
Aurelien Jarno | 26ac1ea | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 444 | } |
Aurelien Jarno | a0d4ac3 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 445 | set_flush_to_zero((val & FPSCR_DN) != 0, &env->fp_status); |
aurel32 | 390af82 | 2008-08-30 22:07:52 +0000 | [diff] [blame] | 446 | } |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 447 | |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 448 | static void update_fpscr(uintptr_t retaddr) |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 449 | { |
| 450 | int xcpt, cause, enable; |
| 451 | |
| 452 | xcpt = get_float_exception_flags(&env->fp_status); |
| 453 | |
| 454 | /* Clear the flag entries */ |
| 455 | env->fpscr &= ~FPSCR_FLAG_MASK; |
| 456 | |
| 457 | if (unlikely(xcpt)) { |
| 458 | if (xcpt & float_flag_invalid) { |
| 459 | env->fpscr |= FPSCR_FLAG_V; |
| 460 | } |
| 461 | if (xcpt & float_flag_divbyzero) { |
| 462 | env->fpscr |= FPSCR_FLAG_Z; |
| 463 | } |
| 464 | if (xcpt & float_flag_overflow) { |
| 465 | env->fpscr |= FPSCR_FLAG_O; |
| 466 | } |
| 467 | if (xcpt & float_flag_underflow) { |
| 468 | env->fpscr |= FPSCR_FLAG_U; |
| 469 | } |
| 470 | if (xcpt & float_flag_inexact) { |
| 471 | env->fpscr |= FPSCR_FLAG_I; |
| 472 | } |
| 473 | |
| 474 | /* Accumulate in cause entries */ |
| 475 | env->fpscr |= (env->fpscr & FPSCR_FLAG_MASK) |
| 476 | << (FPSCR_CAUSE_SHIFT - FPSCR_FLAG_SHIFT); |
| 477 | |
| 478 | /* Generate an exception if enabled */ |
| 479 | cause = (env->fpscr & FPSCR_CAUSE_MASK) >> FPSCR_CAUSE_SHIFT; |
| 480 | enable = (env->fpscr & FPSCR_ENABLE_MASK) >> FPSCR_ENABLE_SHIFT; |
| 481 | if (cause & enable) { |
| 482 | cpu_restore_state_from_retaddr(retaddr); |
| 483 | env->exception_index = 0x120; |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 484 | cpu_loop_exit(env); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 489 | float32 helper_fabs_FT(float32 t0) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 490 | { |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 491 | return float32_abs(t0); |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 494 | float64 helper_fabs_DT(float64 t0) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 495 | { |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 496 | return float64_abs(t0); |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 499 | float32 helper_fadd_FT(float32 t0, float32 t1) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 500 | { |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 501 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 502 | t0 = float32_add(t0, t1, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 503 | update_fpscr(GETPC()); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 504 | return t0; |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 507 | float64 helper_fadd_DT(float64 t0, float64 t1) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 508 | { |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 509 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 510 | t0 = float64_add(t0, t1, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 511 | update_fpscr(GETPC()); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 512 | return t0; |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 515 | void helper_fcmp_eq_FT(float32 t0, float32 t1) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 516 | { |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 517 | int relation; |
aurel32 | 9850d1e | 2008-11-19 18:00:39 +0000 | [diff] [blame] | 518 | |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 519 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 520 | relation = float32_compare(t0, t1, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 521 | if (unlikely(relation == float_relation_unordered)) { |
| 522 | update_fpscr(GETPC()); |
| 523 | } else if (relation == float_relation_equal) { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 524 | set_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 525 | } else { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 526 | clr_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 527 | } |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 530 | void helper_fcmp_eq_DT(float64 t0, float64 t1) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 531 | { |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 532 | int relation; |
aurel32 | 9850d1e | 2008-11-19 18:00:39 +0000 | [diff] [blame] | 533 | |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 534 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 535 | relation = float64_compare(t0, t1, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 536 | if (unlikely(relation == float_relation_unordered)) { |
| 537 | update_fpscr(GETPC()); |
| 538 | } else if (relation == float_relation_equal) { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 539 | set_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 540 | } else { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 541 | clr_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 542 | } |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 545 | void helper_fcmp_gt_FT(float32 t0, float32 t1) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 546 | { |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 547 | int relation; |
aurel32 | 9850d1e | 2008-11-19 18:00:39 +0000 | [diff] [blame] | 548 | |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 549 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 550 | relation = float32_compare(t0, t1, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 551 | if (unlikely(relation == float_relation_unordered)) { |
| 552 | update_fpscr(GETPC()); |
| 553 | } else if (relation == float_relation_greater) { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 554 | set_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 555 | } else { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 556 | clr_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 557 | } |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 560 | void helper_fcmp_gt_DT(float64 t0, float64 t1) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 561 | { |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 562 | int relation; |
aurel32 | 9850d1e | 2008-11-19 18:00:39 +0000 | [diff] [blame] | 563 | |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 564 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 565 | relation = float64_compare(t0, t1, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 566 | if (unlikely(relation == float_relation_unordered)) { |
| 567 | update_fpscr(GETPC()); |
| 568 | } else if (relation == float_relation_greater) { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 569 | set_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 570 | } else { |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 571 | clr_t(); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 572 | } |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 575 | float64 helper_fcnvsd_FT_DT(float32 t0) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 576 | { |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 577 | float64 ret; |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 578 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 579 | ret = float32_to_float64(t0, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 580 | update_fpscr(GETPC()); |
| 581 | return ret; |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 584 | float32 helper_fcnvds_DT_FT(float64 t0) |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 585 | { |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 586 | float32 ret; |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 587 | set_float_exception_flags(0, &env->fp_status); |
Aurelien Jarno | d6c424c | 2011-04-10 21:09:12 +0200 | [diff] [blame] | 588 | ret = float64_to_float32(t0, &env->fp_status); |
| 589 | update_fpscr(GETPC()); |
| 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | float32 helper_fdiv_FT(float32 t0, float32 t1) |
| 594 | { |
| 595 | set_float_exception_flags(0, &env->fp_status); |
| 596 | t0 = float32_div(t0, t1, &env->fp_status); |
| 597 | update_fpscr(GETPC()); |
| 598 | return t0; |
| 599 | } |
| 600 | |
| 601 | float64 helper_fdiv_DT(float64 t0, float64 t1) |
| 602 | { |
| 603 | set_float_exception_flags(0, &env->fp_status); |
| 604 | t0 = float64_div(t0, t1, &env->fp_status); |
| 605 | update_fpscr(GETPC()); |
| 606 | return t0; |
| 607 | } |
| 608 | |
| 609 | float32 helper_float_FT(uint32_t t0) |
| 610 | { |
| 611 | float32 ret; |
| 612 | set_float_exception_flags(0, &env->fp_status); |
| 613 | ret = int32_to_float32(t0, &env->fp_status); |
| 614 | update_fpscr(GETPC()); |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | float64 helper_float_DT(uint32_t t0) |
| 619 | { |
| 620 | float64 ret; |
| 621 | set_float_exception_flags(0, &env->fp_status); |
| 622 | ret = int32_to_float64(t0, &env->fp_status); |
| 623 | update_fpscr(GETPC()); |
| 624 | return ret; |
| 625 | } |
| 626 | |
| 627 | float32 helper_fmac_FT(float32 t0, float32 t1, float32 t2) |
| 628 | { |
| 629 | set_float_exception_flags(0, &env->fp_status); |
| 630 | t0 = float32_mul(t0, t1, &env->fp_status); |
| 631 | t0 = float32_add(t0, t2, &env->fp_status); |
| 632 | update_fpscr(GETPC()); |
| 633 | return t0; |
| 634 | } |
| 635 | |
| 636 | float32 helper_fmul_FT(float32 t0, float32 t1) |
| 637 | { |
| 638 | set_float_exception_flags(0, &env->fp_status); |
| 639 | t0 = float32_mul(t0, t1, &env->fp_status); |
| 640 | update_fpscr(GETPC()); |
| 641 | return t0; |
| 642 | } |
| 643 | |
| 644 | float64 helper_fmul_DT(float64 t0, float64 t1) |
| 645 | { |
| 646 | set_float_exception_flags(0, &env->fp_status); |
| 647 | t0 = float64_mul(t0, t1, &env->fp_status); |
| 648 | update_fpscr(GETPC()); |
| 649 | return t0; |
| 650 | } |
| 651 | |
| 652 | float32 helper_fneg_T(float32 t0) |
| 653 | { |
| 654 | return float32_chs(t0); |
| 655 | } |
| 656 | |
| 657 | float32 helper_fsqrt_FT(float32 t0) |
| 658 | { |
| 659 | set_float_exception_flags(0, &env->fp_status); |
| 660 | t0 = float32_sqrt(t0, &env->fp_status); |
| 661 | update_fpscr(GETPC()); |
| 662 | return t0; |
| 663 | } |
| 664 | |
| 665 | float64 helper_fsqrt_DT(float64 t0) |
| 666 | { |
| 667 | set_float_exception_flags(0, &env->fp_status); |
| 668 | t0 = float64_sqrt(t0, &env->fp_status); |
| 669 | update_fpscr(GETPC()); |
| 670 | return t0; |
| 671 | } |
| 672 | |
| 673 | float32 helper_fsub_FT(float32 t0, float32 t1) |
| 674 | { |
| 675 | set_float_exception_flags(0, &env->fp_status); |
| 676 | t0 = float32_sub(t0, t1, &env->fp_status); |
| 677 | update_fpscr(GETPC()); |
| 678 | return t0; |
| 679 | } |
| 680 | |
| 681 | float64 helper_fsub_DT(float64 t0, float64 t1) |
| 682 | { |
| 683 | set_float_exception_flags(0, &env->fp_status); |
| 684 | t0 = float64_sub(t0, t1, &env->fp_status); |
| 685 | update_fpscr(GETPC()); |
| 686 | return t0; |
| 687 | } |
| 688 | |
| 689 | uint32_t helper_ftrc_FT(float32 t0) |
| 690 | { |
| 691 | uint32_t ret; |
| 692 | set_float_exception_flags(0, &env->fp_status); |
| 693 | ret = float32_to_int32_round_to_zero(t0, &env->fp_status); |
| 694 | update_fpscr(GETPC()); |
| 695 | return ret; |
| 696 | } |
| 697 | |
| 698 | uint32_t helper_ftrc_DT(float64 t0) |
| 699 | { |
| 700 | uint32_t ret; |
| 701 | set_float_exception_flags(0, &env->fp_status); |
| 702 | ret = float64_to_int32_round_to_zero(t0, &env->fp_status); |
Aurelien Jarno | 21829e9 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 703 | update_fpscr(GETPC()); |
| 704 | return ret; |
aurel32 | cc4ba6a | 2008-09-01 22:11:56 +0000 | [diff] [blame] | 705 | } |
Aurelien Jarno | af8c2bd | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 706 | |
| 707 | void helper_fipr(uint32_t m, uint32_t n) |
| 708 | { |
| 709 | int bank, i; |
| 710 | float32 r, p; |
| 711 | |
| 712 | bank = (env->sr & FPSCR_FR) ? 16 : 0; |
| 713 | r = float32_zero; |
| 714 | set_float_exception_flags(0, &env->fp_status); |
| 715 | |
| 716 | for (i = 0 ; i < 4 ; i++) { |
| 717 | p = float32_mul(env->fregs[bank + m + i], |
| 718 | env->fregs[bank + n + i], |
| 719 | &env->fp_status); |
| 720 | r = float32_add(r, p, &env->fp_status); |
| 721 | } |
| 722 | update_fpscr(GETPC()); |
| 723 | |
| 724 | env->fregs[bank + n + 3] = r; |
| 725 | } |
Aurelien Jarno | 17075f1 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 726 | |
| 727 | void helper_ftrv(uint32_t n) |
| 728 | { |
| 729 | int bank_matrix, bank_vector; |
| 730 | int i, j; |
| 731 | float32 r[4]; |
| 732 | float32 p; |
| 733 | |
| 734 | bank_matrix = (env->sr & FPSCR_FR) ? 0 : 16; |
| 735 | bank_vector = (env->sr & FPSCR_FR) ? 16 : 0; |
| 736 | set_float_exception_flags(0, &env->fp_status); |
| 737 | for (i = 0 ; i < 4 ; i++) { |
| 738 | r[i] = float32_zero; |
| 739 | for (j = 0 ; j < 4 ; j++) { |
| 740 | p = float32_mul(env->fregs[bank_matrix + 4 * j + i], |
| 741 | env->fregs[bank_vector + j], |
| 742 | &env->fp_status); |
| 743 | r[i] = float32_add(r[i], p, &env->fp_status); |
| 744 | } |
| 745 | } |
| 746 | update_fpscr(GETPC()); |
| 747 | |
| 748 | for (i = 0 ; i < 4 ; i++) { |
| 749 | env->fregs[bank_vector + i] = r[i]; |
| 750 | } |
| 751 | } |