Alexey Frunze | 84603bf | 2016-10-21 19:54:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * double-to-int |
| 3 | * |
| 4 | * We have to clip values to int min/max per the specification. The |
| 5 | * expected common case is a "reasonable" value that converts directly |
| 6 | * to modest integer. The EABI convert function isn't doing this for us. |
| 7 | */ |
| 8 | /* unop vA, vB */ |
| 9 | GET_OPB(a3) # a3 <- B |
| 10 | GET_OPA4(rOBJ) # rOBJ <- A+ |
| 11 | EAS2(a3, rFP, a3) # a3 <- &fp[B] |
| 12 | LOAD64_F(fa0, fa0f, a3) |
| 13 | FETCH_ADVANCE_INST(1) # advance rPC, load rINST |
Douglas Leung | 200f040 | 2016-02-25 20:05:47 -0800 | [diff] [blame] | 14 | |
Alexey Frunze | 84603bf | 2016-10-21 19:54:43 -0700 | [diff] [blame] | 15 | li t0, INT_MIN_AS_DOUBLE_HIGH |
| 16 | mtc1 zero, fa1 |
| 17 | MOVE_TO_FPU_HIGH(t0, fa1, fa1f) |
Douglas Leung | 200f040 | 2016-02-25 20:05:47 -0800 | [diff] [blame] | 18 | #ifdef MIPS32REVGE6 |
Alexey Frunze | 84603bf | 2016-10-21 19:54:43 -0700 | [diff] [blame] | 19 | /* |
| 20 | * TODO: simplify this when the MIPS64R6 emulator |
| 21 | * supports NAN2008=1. |
| 22 | */ |
| 23 | cmp.le.d ft0, fa1, fa0 |
| 24 | GET_INST_OPCODE(t1) # extract opcode from rINST |
| 25 | bc1nez ft0, 1f # if INT_MIN <= vB, proceed to truncation |
| 26 | cmp.eq.d ft0, fa0, fa0 |
| 27 | selnez.d fa0, fa1, ft0 # fa0 = ordered(vB) ? INT_MIN_AS_DOUBLE : 0 |
Douglas Leung | 200f040 | 2016-02-25 20:05:47 -0800 | [diff] [blame] | 28 | #else |
Douglas Leung | 200f040 | 2016-02-25 20:05:47 -0800 | [diff] [blame] | 29 | c.ole.d fcc0, fa1, fa0 |
Alexey Frunze | 84603bf | 2016-10-21 19:54:43 -0700 | [diff] [blame] | 30 | GET_INST_OPCODE(t1) # extract opcode from rINST |
| 31 | bc1t fcc0, 1f # if INT_MIN <= vB, proceed to truncation |
| 32 | c.eq.d fcc0, fa0, fa0 |
| 33 | mtc1 zero, fa0 |
| 34 | MOVE_TO_FPU_HIGH(zero, fa0, fa0f) |
| 35 | movt.d fa0, fa1, fcc0 # fa0 = ordered(vB) ? INT_MIN_AS_DOUBLE : 0 |
Douglas Leung | 200f040 | 2016-02-25 20:05:47 -0800 | [diff] [blame] | 36 | #endif |
Alexey Frunze | 84603bf | 2016-10-21 19:54:43 -0700 | [diff] [blame] | 37 | 1: |
| 38 | trunc.w.d fa0, fa0 |
| 39 | SET_VREG_F_GOTO(fa0, rOBJ, t1) # vA <- result |