blob: 087e50fe80c33c12375a1dec5d5cd23db858d648 [file] [log] [blame]
Alexey Frunze84603bf2016-10-21 19:54:43 -07001 /*
2 * float-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 GET_VREG_F(fa0, a3)
12 FETCH_ADVANCE_INST(1) # advance rPC, load rINST
Douglas Leung200f0402016-02-25 20:05:47 -080013
Alexey Frunze84603bf2016-10-21 19:54:43 -070014 li t0, INT_MIN_AS_FLOAT
15 mtc1 t0, fa1
Douglas Leung200f0402016-02-25 20:05:47 -080016#ifdef MIPS32REVGE6
Alexey Frunze84603bf2016-10-21 19:54:43 -070017 /*
18 * TODO: simplify this when the MIPS64R6 emulator
19 * supports NAN2008=1.
20 */
21 cmp.le.s ft0, fa1, fa0
22 GET_INST_OPCODE(t1) # extract opcode from rINST
23 bc1nez ft0, 1f # if INT_MIN <= vB, proceed to truncation
24 cmp.eq.s ft0, fa0, fa0
25 selnez.s fa0, fa1, ft0 # fa0 = ordered(vB) ? INT_MIN_AS_FLOAT : 0
Douglas Leung200f0402016-02-25 20:05:47 -080026#else
Douglas Leung200f0402016-02-25 20:05:47 -080027 c.ole.s fcc0, fa1, fa0
Alexey Frunze84603bf2016-10-21 19:54:43 -070028 GET_INST_OPCODE(t1) # extract opcode from rINST
29 bc1t fcc0, 1f # if INT_MIN <= vB, proceed to truncation
30 c.eq.s fcc0, fa0, fa0
31 mtc1 zero, fa0
32 movt.s fa0, fa1, fcc0 # fa0 = ordered(vB) ? INT_MIN_AS_FLOAT : 0
Douglas Leung200f0402016-02-25 20:05:47 -080033#endif
Alexey Frunze84603bf2016-10-21 19:54:43 -0700341:
35 trunc.w.s fa0, fa0
36 SET_VREG_F_GOTO(fa0, rOBJ, t1) # vA <- result