1%default {"srcdouble":"1","tgtlong":"1"}
2/* On fp to int conversions, Java requires that
3 * if the result > maxint, it should be clamped to maxint.  If it is less
4 * than minint, it should be clamped to minint.  If it is a nan, the result
5 * should be zero.  Further, the rounding mode is to truncate.  This model
6 * differs from what is delivered normally via the x86 fpu, so we have
7 * to play some games.
8 */
9    /* float/double to int/long vA, vB */
10    movzbl    rINSTbl,%ecx       # ecx<- A+
11    sarl      $$4,rINST         # rINST<- B
12    .if $srcdouble
13    fldl     (rFP,rINST,4)       # %st0<- vB
14    .else
15    flds     (rFP,rINST,4)       # %st0<- vB
16    .endif
17    ftst
18    fnstcw   LOCAL0_OFFSET(%ebp)      # remember original rounding mode
19    movzwl   LOCAL0_OFFSET(%ebp),%eax
20    movb     $$0xc,%ah
21    movw     %ax,LOCAL0_OFFSET+2(%ebp)
22    fldcw    LOCAL0_OFFSET+2(%ebp)    # set "to zero" rounding mode
23    andb     $$0xf,%cl                # ecx<- A
24    .if $tgtlong
25    fistpll  (rFP,%ecx,4)             # convert and store
26    .else
27    fistpl   (rFP,%ecx,4)             # convert and store
28    .endif
29    fldcw    LOCAL0_OFFSET(%ebp)      # restore previous rounding mode
30    .if $tgtlong
31    movl     $$0x80000000,%eax
32    xorl     4(rFP,%ecx,4),%eax
33    orl      (rFP,%ecx,4),%eax
34    .else
35    cmpl     $$0x80000000,(rFP,%ecx,4)
36    .endif
37    je       .L${opcode}_special_case # fix up result
38
39.L${opcode}_finish:
40    FETCH_INST_OPCODE 1 %ecx
41    ADVANCE_PC 1
42    GOTO_NEXT_R %ecx
43
44.L${opcode}_special_case:
45    fnstsw   %ax
46    sahf
47    jp       .L${opcode}_isNaN
48    adcl     $$-1,(rFP,%ecx,4)
49    .if $tgtlong
50    adcl     $$-1,4(rFP,%ecx,4)
51    .endif
52   jmp       .L${opcode}_finish
53.L${opcode}_isNaN:
54    movl      $$0,(rFP,%ecx,4)
55    .if $tgtlong
56    movl      $$0,4(rFP,%ecx,4)
57    .endif
58    jmp       .L${opcode}_finish
59