@@ -1337,17 +1337,16 @@ neg(float64 f64)
13371337static bool
13381338compile_op_float_math (JitCompContext * cc , FloatMath math_op , bool is_f32 )
13391339{
1340- JitReg value , res , xmm0 ;
1340+ JitReg value , res ;
13411341 JitInsn * insn = NULL ;
13421342 void * func = NULL ;
13431343
13441344#if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 )
13451345 if (is_f32 ) {
1346- res = xmm0 = jit_codegen_get_hreg_by_name ("xmm0" );
1346+ res = jit_codegen_get_hreg_by_name ("xmm0" );
13471347 }
13481348 else {
13491349 res = jit_codegen_get_hreg_by_name ("xmm0_f64" );
1350- xmm0 = jit_codegen_get_hreg_by_name ("xmm0" );
13511350 }
13521351#else
13531352 if (is_f32 )
@@ -1383,6 +1382,9 @@ compile_op_float_math(JitCompContext *cc, FloatMath math_op, bool is_f32)
13831382 case FLOAT_SQRT :
13841383 func = is_f32 ? (void * )sqrtf : (void * )sqrt ;
13851384 break ;
1385+ default :
1386+ bh_assert (0 );
1387+ goto fail ;
13861388 }
13871389
13881390 insn = GEN_INSN (CALLNATIVE , res , NEW_CONST (PTR , (uintptr_t )func ), 1 );
@@ -1396,9 +1398,6 @@ compile_op_float_math(JitCompContext *cc, FloatMath math_op, bool is_f32)
13961398 else
13971399 PUSH_F64 (res );
13981400
1399- #if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 )
1400- jit_lock_reg_in_insn (cc , insn , xmm0 );
1401- #endif
14021401 return true;
14031402fail :
14041403 return false;
@@ -1416,6 +1415,84 @@ jit_compile_op_f64_math(JitCompContext *cc, FloatMath math_op)
14161415 return compile_op_float_math (cc , math_op , false);
14171416}
14181417
1418+ static float32
1419+ local_minf (float32 f1 , float32 f2 )
1420+ {
1421+ if (isnanf (f1 ))
1422+ return f1 ;
1423+ if (isnanf (f2 ))
1424+ return f2 ;
1425+
1426+ return fminf (f1 , f2 );
1427+ }
1428+
1429+ static float64
1430+ local_min (float64 f1 , float64 f2 )
1431+ {
1432+ if (isnan (f1 ))
1433+ return f1 ;
1434+ if (isnan (f2 ))
1435+ return f2 ;
1436+
1437+ return fmin (f1 , f2 );
1438+ }
1439+
1440+ static float32
1441+ local_maxf (float32 f1 , float32 f2 )
1442+ {
1443+ if (isnanf (f1 ))
1444+ return f1 ;
1445+ if (isnanf (f2 ))
1446+ return f2 ;
1447+
1448+ return fmaxf (f1 , f2 );
1449+ }
1450+
1451+ static float64
1452+ local_max (float64 f1 , float64 f2 )
1453+ {
1454+ if (isnan (f1 ))
1455+ return f1 ;
1456+ if (isnan (f2 ))
1457+ return f2 ;
1458+
1459+ return fmax (f1 , f2 );
1460+ }
1461+
1462+ static bool
1463+ compile_op_float_min_max (JitCompContext * cc , FloatArithmetic arith_op ,
1464+ bool is_f32 , JitReg lhs , JitReg rhs , JitReg * out )
1465+ {
1466+ JitReg res ;
1467+ JitInsn * insn = NULL ;
1468+ #if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 )
1469+ res = jit_codegen_get_hreg_by_name (is_f32 ? "xmm0" : "xmm0_f64" );
1470+ #else
1471+ res = is_f32 ? jit_cc_new_reg_F32 (cc ) : jit_cc_new_reg_F64 (cc );
1472+ #endif
1473+
1474+ if (arith_op == FLOAT_MIN )
1475+ insn = GEN_INSN (CALLNATIVE , res ,
1476+ is_f32 ? NEW_CONST (PTR , (uintptr_t )local_minf )
1477+ : NEW_CONST (PTR , (uintptr_t )local_min ),
1478+ 2 );
1479+ else
1480+ insn = GEN_INSN (CALLNATIVE , res ,
1481+ is_f32 ? NEW_CONST (PTR , (uintptr_t )local_maxf )
1482+ : NEW_CONST (PTR , (uintptr_t )local_max ),
1483+ 2 );
1484+ if (!insn )
1485+ goto fail ;
1486+
1487+ * (jit_insn_opndv (insn , 2 )) = lhs ;
1488+ * (jit_insn_opndv (insn , 3 )) = rhs ;
1489+
1490+ * out = res ;
1491+ return true;
1492+ fail :
1493+ return false;
1494+ }
1495+
14191496static bool
14201497compile_op_float_arithmetic (JitCompContext * cc , FloatArithmetic arith_op ,
14211498 bool is_f32 )
@@ -1456,13 +1533,10 @@ compile_op_float_arithmetic(JitCompContext *cc, FloatArithmetic arith_op,
14561533 break ;
14571534 }
14581535 case FLOAT_MIN :
1459- {
1460- GEN_INSN (MIN , res , lhs , rhs );
1461- break ;
1462- }
14631536 case FLOAT_MAX :
14641537 {
1465- GEN_INSN (MAX , res , lhs , rhs );
1538+ if (!compile_op_float_min_max (cc , arith_op , is_f32 , lhs , rhs , & res ))
1539+ goto fail ;
14661540 break ;
14671541 }
14681542 default :
0 commit comments