@@ -857,13 +857,34 @@ compile_op_int_shift(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
857857 return false;
858858}
859859
860+ static bool
861+ is_targeting_soft_float (LLVMTargetMachineRef target_machine )
862+ {
863+ bool ret = false;
864+ char * feature_string ;
865+
866+ if (!(feature_string =
867+ LLVMGetTargetMachineFeatureString (target_machine ))) {
868+ aot_set_last_error ("llvm get target machine feature string fail." );
869+ return false;
870+ }
871+
872+ ret = strstr (feature_string , "+soft-float" ) ? true : false;
873+ LLVMDisposeMessage (feature_string );
874+ return ret ;
875+ }
876+
860877static bool
861878compile_op_float_arithmetic (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx ,
862879 FloatArithmetic arith_op , bool is_f32 )
863880{
864881 switch (arith_op ) {
865882 case FLOAT_ADD :
866- DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
883+ if (is_targeting_soft_float (comp_ctx -> target_machine ))
884+ DEF_FP_BINARY_OP (LLVMBuildFAdd (comp_ctx -> builder , left , right , "fadd" ),
885+ "llvm build fadd fail." );
886+ else
887+ DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
867888 comp_ctx ,
868889 (is_f32
869890 ? "llvm.experimental.constrained.fadd.f32"
@@ -873,10 +894,14 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
873894 right ,
874895 comp_ctx -> fp_rounding_mode ,
875896 comp_ctx -> fp_exception_behavior ),
876- NULL );
897+ NULL );
877898 return true;
878899 case FLOAT_SUB :
879- DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
900+ if (is_targeting_soft_float (comp_ctx -> target_machine ))
901+ DEF_FP_BINARY_OP (LLVMBuildFSub (comp_ctx -> builder , left , right , "fsub" ),
902+ "llvm build fsub fail." );
903+ else
904+ DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
880905 comp_ctx ,
881906 (is_f32
882907 ? "llvm.experimental.constrained.fsub.f32"
@@ -886,10 +911,14 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
886911 right ,
887912 comp_ctx -> fp_rounding_mode ,
888913 comp_ctx -> fp_exception_behavior ),
889- NULL );
914+ NULL );
890915 return true;
891916 case FLOAT_MUL :
892- DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
917+ if (is_targeting_soft_float (comp_ctx -> target_machine ))
918+ DEF_FP_BINARY_OP (LLVMBuildFMul (comp_ctx -> builder , left , right , "fmul" ),
919+ "llvm build fmul fail." );
920+ else
921+ DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
893922 comp_ctx ,
894923 (is_f32
895924 ? "llvm.experimental.constrained.fmul.f32"
@@ -899,10 +928,14 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
899928 right ,
900929 comp_ctx -> fp_rounding_mode ,
901930 comp_ctx -> fp_exception_behavior ),
902- NULL );
931+ NULL );
903932 return true;
904933 case FLOAT_DIV :
905- DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
934+ if (is_targeting_soft_float (comp_ctx -> target_machine ))
935+ DEF_FP_BINARY_OP (LLVMBuildFDiv (comp_ctx -> builder , left , right , "fdiv" ),
936+ "llvm build fdiv fail." );
937+ else
938+ DEF_FP_BINARY_OP (call_llvm_float_expermental_constrained_intrinsic (
906939 comp_ctx ,
907940 (is_f32
908941 ? "llvm.experimental.constrained.fdiv.f32"
@@ -912,7 +945,7 @@ compile_op_float_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
912945 right ,
913946 comp_ctx -> fp_rounding_mode ,
914947 comp_ctx -> fp_exception_behavior ),
915- NULL );
948+ NULL );
916949 return true;
917950 case FLOAT_MIN :
918951 DEF_FP_BINARY_OP (compile_op_float_min_max (comp_ctx ,
@@ -1017,7 +1050,15 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
10171050 NULL );
10181051 return true;
10191052 case FLOAT_SQRT :
1020- DEF_FP_UNARY_OP (call_llvm_libm_expermental_constrained_intrinsic (
1053+ if (is_targeting_soft_float (comp_ctx -> target_machine ))
1054+ DEF_FP_UNARY_OP (call_llvm_float_math_intrinsic (comp_ctx ,
1055+ is_f32 ? "llvm.sqrt.f32" :
1056+ "llvm.sqrt.f64" ,
1057+ is_f32 ,
1058+ operand ),
1059+ NULL );
1060+ else
1061+ DEF_FP_UNARY_OP (call_llvm_libm_expermental_constrained_intrinsic (
10211062 comp_ctx ,
10221063 (is_f32
10231064 ? "llvm.experimental.constrained.sqrt.f32"
@@ -1026,7 +1067,7 @@ compile_op_float_math(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
10261067 operand ,
10271068 comp_ctx -> fp_rounding_mode ,
10281069 comp_ctx -> fp_exception_behavior ),
1029- NULL );
1070+ NULL );
10301071 return true;
10311072 default :
10321073 bh_assert (0 );
0 commit comments