1%include "mips/funopWide.S" {"instr":"b d2l_doconv", "st_result":"SET_VREG64(rRESULT0, rRESULT1, rOBJ)"}
2%break
3
4d2l_doconv:
5#ifdef MIPS32REVGE6
6    la        t0, .LDOUBLE_TO_LONG_max
7    LOAD64_F(fa1, fa1f, t0)
8    cmp.ule.d ft2, fa1, fa0
9    la        t0, .LDOUBLE_TO_LONG_ret_max
10    LOAD64(rRESULT0, rRESULT1, t0)
11    bc1nez    ft2, .L${opcode}_set_vreg
12
13    la        t0, .LDOUBLE_TO_LONG_min
14    LOAD64_F(fa1, fa1f, t0)
15    cmp.ule.d ft2, fa0, fa1
16    la        t0, .LDOUBLE_TO_LONG_ret_min
17    LOAD64(rRESULT0, rRESULT1, t0)
18    bc1nez    ft2, .L${opcode}_set_vreg
19
20    mov.d     fa1, fa0
21    cmp.un.d  ft2, fa0, fa1
22    li        rRESULT0, 0
23    li        rRESULT1, 0
24    bc1nez    ft2, .L${opcode}_set_vreg
25#else
26    la        t0, .LDOUBLE_TO_LONG_max
27    LOAD64_F(fa1, fa1f, t0)
28    c.ole.d   fcc0, fa1, fa0
29    la        t0, .LDOUBLE_TO_LONG_ret_max
30    LOAD64(rRESULT0, rRESULT1, t0)
31    bc1t      .L${opcode}_set_vreg
32
33    la        t0, .LDOUBLE_TO_LONG_min
34    LOAD64_F(fa1, fa1f, t0)
35    c.ole.d   fcc0, fa0, fa1
36    la        t0, .LDOUBLE_TO_LONG_ret_min
37    LOAD64(rRESULT0, rRESULT1, t0)
38    bc1t      .L${opcode}_set_vreg
39
40    mov.d     fa1, fa0
41    c.un.d    fcc0, fa0, fa1
42    li        rRESULT0, 0
43    li        rRESULT1, 0
44    bc1t      .L${opcode}_set_vreg
45#endif
46    JAL(__fixdfdi)
47    b         .L${opcode}_set_vreg
48
49.LDOUBLE_TO_LONG_max:
50    .dword 0x43e0000000000000              #  maxlong, as a double (high word)
51.LDOUBLE_TO_LONG_min:
52    .dword 0xc3e0000000000000              #  minlong, as a double (high word)
53.LDOUBLE_TO_LONG_ret_max:
54    .dword 0x7fffffffffffffff
55.LDOUBLE_TO_LONG_ret_min:
56    .dword 0x8000000000000000
57