1%default {"fp_suffix":"","i_suffix":"","max_const":"","result_reg":"","wide":""}
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.
6 */
7    /* float/double to int/long vA, vB */
8    movl    rINST, %ecx                     # rcx <- A+
9    sarl    $$4, rINST                      # rINST <- B
10    andb    $$0xf, %cl                      # ecx <- A
11    movs${fp_suffix}   VREG_ADDRESS(rINSTq), %xmm0
12    mov${i_suffix}  ${max_const}, ${result_reg}
13    cvtsi2s${fp_suffix}${i_suffix} ${result_reg}, %xmm1
14    comis${fp_suffix}    %xmm1, %xmm0
15    jae     1f
16    jp      2f
17    cvtts${fp_suffix}2si${i_suffix}  %xmm0, ${result_reg}
18    jmp     1f
192:
20    xor${i_suffix}    ${result_reg}, ${result_reg}
211:
22    .if $wide
23    SET_WIDE_VREG ${result_reg}, %rcx
24    .else
25    SET_VREG ${result_reg}, %rcx
26    .endif
27    ADVANCE_PC_FETCH_AND_GOTO_NEXT 1
28