blob: 3b4496433318bcc76f82addb2867a18079386388 [file] [log] [blame]
Alexey Frunze84603bf2016-10-21 19:54:43 -07001 /*
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 Leung200f0402016-02-25 20:05:47 -080014
Alexey Frunze84603bf2016-10-21 19:54:43 -070015 li t0, INT_MIN_AS_DOUBLE_HIGH
16 mtc1 zero, fa1
17 MOVE_TO_FPU_HIGH(t0, fa1, fa1f)
Douglas Leung200f0402016-02-25 20:05:47 -080018#ifdef MIPS32REVGE6
Alexey Frunze84603bf2016-10-21 19:54:43 -070019 /*
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 Leung200f0402016-02-25 20:05:47 -080028#else
Douglas Leung200f0402016-02-25 20:05:47 -080029 c.ole.d fcc0, fa1, fa0
Alexey Frunze84603bf2016-10-21 19:54:43 -070030 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 Leung200f0402016-02-25 20:05:47 -080036#endif
Alexey Frunze84603bf2016-10-21 19:54:43 -0700371:
38 trunc.w.d fa0, fa0
39 SET_VREG_F_GOTO(fa0, rOBJ, t1) # vA <- result