Skip to content

Commit 7de224a

Browse files
committed
fix float to double implicit conversion
1 parent 6253bd1 commit 7de224a

14 files changed

Lines changed: 113 additions & 75 deletions

File tree

core/iwasm/aot/aot_intrinsic.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ aot_intrinsic_sqrt_f64(float64 a)
128128
float32
129129
aot_intrinsic_copysign_f32(float32 a, float32 b)
130130
{
131-
return signbit(b) ? -fabsf(a) : fabsf(a);
131+
return signbitf(b) ? -fabsf(a) : fabsf(a);
132132
}
133133

134134
float64
@@ -140,10 +140,10 @@ aot_intrinsic_copysign_f64(float64 a, float64 b)
140140
float32
141141
aot_intrinsic_fmin_f32(float32 a, float32 b)
142142
{
143-
if (isnan(a) || isnan(b))
143+
if (isnanf(a) || isnanf(b))
144144
return NAN;
145145
else if (a == 0 && a == b)
146-
return signbit(a) ? a : b;
146+
return signbitf(a) ? a : b;
147147
else
148148
return a > b ? b : a;
149149
}
@@ -162,10 +162,10 @@ aot_intrinsic_fmin_f64(float64 a, float64 b)
162162
float32
163163
aot_intrinsic_fmax_f32(float32 a, float32 b)
164164
{
165-
if (isnan(a) || isnan(b))
165+
if (isnanf(a) || isnanf(b))
166166
return NAN;
167167
else if (a == 0 && a == b)
168-
return signbit(a) ? b : a;
168+
return signbitf(a) ? b : a;
169169
else
170170
return a > b ? a : b;
171171
}
@@ -383,10 +383,10 @@ aot_intrinsic_f32_cmp(AOTFloatCond cond, float32 lhs, float32 rhs)
383383
return lhs >= rhs ? 1 : 0;
384384

385385
case FLOAT_NE:
386-
return (isnan(lhs) || isnan(rhs) || lhs != rhs) ? 1 : 0;
386+
return (isnanf(lhs) || isnanf(rhs) || lhs != rhs) ? 1 : 0;
387387

388388
case FLOAT_UNO:
389-
return (isnan(lhs) || isnan(rhs)) ? 1 : 0;
389+
return (isnanf(lhs) || isnanf(rhs)) ? 1 : 0;
390390

391391
default:
392392
break;

core/iwasm/common/wasm_application.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
454454
case VALUE_TYPE_F32:
455455
{
456456
float32 f32 = strtof(argv[i], &endptr);
457-
if (isnan(f32)) {
457+
if (isnanf(f32)) {
458458
#ifdef _MSC_VER
459459
/*
460460
* Spec tests require the binary representation of NaN to be

core/iwasm/compilation/aot_emit_const.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
7979
}
8080
PUSH_F32(value);
8181
}
82-
else if (!isnan(f32_const)) {
82+
else if (!isnanf(f32_const)) {
8383
value = F32_CONST(f32_const);
8484
CHECK_LLVM_CONST(value);
8585
PUSH_F32(value);

core/iwasm/fast-jit/fe/jit_emit_compare.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jit_compile_op_i64_compare(JitCompContext *cc, IntCond cond)
117117
static int32
118118
float_cmp_eq(float f1, float f2)
119119
{
120-
if (isnan(f1) || isnan(f2))
120+
if (isnanf(f1) || isnanf(f2))
121121
return 0;
122122

123123
return f1 == f2;
@@ -126,7 +126,7 @@ float_cmp_eq(float f1, float f2)
126126
static int32
127127
float_cmp_ne(float f1, float f2)
128128
{
129-
if (isnan(f1) || isnan(f2))
129+
if (isnanf(f1) || isnanf(f2))
130130
return 1;
131131

132132
return f1 != f2;

core/iwasm/fast-jit/fe/jit_emit_conversion.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local_isnan(double x)
4545
static int
4646
local_isnanf(float x)
4747
{
48-
return isnan(x);
48+
return isnanf(x);
4949
}
5050

5151
#define RETURN_IF_NANF(fp) \
@@ -198,7 +198,7 @@ jit_compile_check_value_range(JitCompContext *cc, JitReg value, JitReg min_fp,
198198
float min_fp_f32_const = jit_cc_get_const_F32(cc, min_fp);
199199
float max_fp_f32_const = jit_cc_get_const_F32(cc, max_fp);
200200

201-
if (isnan(value_f32_const)) {
201+
if (isnanf(value_f32_const)) {
202202
/* throw exception if value is nan */
203203
if (!jit_emit_exception(cc, EXCE_INVALID_CONVERSION_TO_INTEGER,
204204
JIT_OP_JMP, 0, NULL))

core/iwasm/fast-jit/fe/jit_emit_numberic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,21 +1541,21 @@ jit_compile_op_f64_math(JitCompContext *cc, FloatMath math_op)
15411541
static float32
15421542
f32_min(float32 a, float32 b)
15431543
{
1544-
if (isnan(a) || isnan(b))
1544+
if (isnanf(a) || isnanf(b))
15451545
return NAN;
15461546
else if (a == 0 && a == b)
1547-
return signbit(a) ? a : b;
1547+
return signbitf(a) ? a : b;
15481548
else
15491549
return a > b ? b : a;
15501550
}
15511551

15521552
static float32
15531553
f32_max(float32 a, float32 b)
15541554
{
1555-
if (isnan(a) || isnan(b))
1555+
if (isnanf(a) || isnanf(b))
15561556
return NAN;
15571557
else if (a == 0 && a == b)
1558-
return signbit(a) ? b : a;
1558+
return signbitf(a) ? b : a;
15591559
else
15601560
return a > b ? a : b;
15611561
}

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,21 @@ rotr64(uint64 n, uint64 c)
200200
static inline float32
201201
f32_min(float32 a, float32 b)
202202
{
203-
if (isnan(a) || isnan(b))
203+
if (isnanf(a) || isnanf(b))
204204
return NAN;
205205
else if (a == 0 && a == b)
206-
return signbit(a) ? a : b;
206+
return signbitf(a) ? a : b;
207207
else
208208
return a > b ? b : a;
209209
}
210210

211211
static inline float32
212212
f32_max(float32 a, float32 b)
213213
{
214-
if (isnan(a) || isnan(b))
214+
if (isnanf(a) || isnanf(b))
215215
return NAN;
216216
else if (a == 0 && a == b)
217-
return signbit(a) ? b : a;
217+
return signbitf(a) ? b : a;
218218
else
219219
return a > b ? a : b;
220220
}
@@ -861,31 +861,31 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame)
861861
PUSH_##src_op_type(method(src_val)); \
862862
} while (0)
863863

864-
#define TRUNC_FUNCTION(func_name, src_type, dst_type, signed_type) \
865-
static dst_type func_name(src_type src_value, src_type src_min, \
866-
src_type src_max, dst_type dst_min, \
867-
dst_type dst_max, bool is_sign) \
868-
{ \
869-
dst_type dst_value = 0; \
870-
if (!isnan(src_value)) { \
871-
if (src_value <= src_min) \
872-
dst_value = dst_min; \
873-
else if (src_value >= src_max) \
874-
dst_value = dst_max; \
875-
else { \
876-
if (is_sign) \
877-
dst_value = (dst_type)(signed_type)src_value; \
878-
else \
879-
dst_value = (dst_type)src_value; \
880-
} \
881-
} \
882-
return dst_value; \
864+
#define TRUNC_FUNCTION(func_name, src_type, dst_type, signed_type, isnan_op) \
865+
static dst_type func_name(src_type src_value, src_type src_min, \
866+
src_type src_max, dst_type dst_min, \
867+
dst_type dst_max, bool is_sign) \
868+
{ \
869+
dst_type dst_value = 0; \
870+
if (!isnan_op(src_value)) { \
871+
if (src_value <= src_min) \
872+
dst_value = dst_min; \
873+
else if (src_value >= src_max) \
874+
dst_value = dst_max; \
875+
else { \
876+
if (is_sign) \
877+
dst_value = (dst_type)(signed_type)src_value; \
878+
else \
879+
dst_value = (dst_type)src_value; \
880+
} \
881+
} \
882+
return dst_value; \
883883
}
884884

885-
TRUNC_FUNCTION(trunc_f32_to_i32, float32, uint32, int32)
886-
TRUNC_FUNCTION(trunc_f32_to_i64, float32, uint64, int64)
887-
TRUNC_FUNCTION(trunc_f64_to_i32, float64, uint32, int32)
888-
TRUNC_FUNCTION(trunc_f64_to_i64, float64, uint64, int64)
885+
TRUNC_FUNCTION(trunc_f32_to_i32, float32, uint32, int32, isnanf)
886+
TRUNC_FUNCTION(trunc_f32_to_i64, float32, uint64, int64, isnanf)
887+
TRUNC_FUNCTION(trunc_f64_to_i32, float64, uint32, int32, isnan)
888+
TRUNC_FUNCTION(trunc_f64_to_i64, float64, uint64, int64, isnan)
889889

890890
static bool
891891
trunc_f32_to_int(WASMModuleInstance *module, uint32 *frame_sp, float32 src_min,
@@ -896,7 +896,7 @@ trunc_f32_to_int(WASMModuleInstance *module, uint32 *frame_sp, float32 src_min,
896896
uint32 dst_value_i32;
897897

898898
if (!saturating) {
899-
if (isnan(src_value)) {
899+
if (isnanf(src_value)) {
900900
wasm_set_exception(module, "invalid conversion to integer");
901901
return false;
902902
}

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,21 @@ rotr64(uint64 n, uint64 c)
141141
static inline float32
142142
f32_min(float32 a, float32 b)
143143
{
144-
if (isnan(a) || isnan(b))
144+
if (isnanf(a) || isnanf(b))
145145
return NAN;
146146
else if (a == 0 && a == b)
147-
return signbit(a) ? a : b;
147+
return signbitf(a) ? a : b;
148148
else
149149
return a > b ? b : a;
150150
}
151151

152152
static inline float32
153153
f32_max(float32 a, float32 b)
154154
{
155-
if (isnan(a) || isnan(b))
155+
if (isnanf(a) || isnanf(b))
156156
return NAN;
157157
else if (a == 0 && a == b)
158-
return signbit(a) ? b : a;
158+
return signbitf(a) ? b : a;
159159
else
160160
return a > b ? a : b;
161161
}
@@ -719,31 +719,31 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame)
719719
frame_ip += 4; \
720720
} while (0)
721721

722-
#define TRUNC_FUNCTION(func_name, src_type, dst_type, signed_type) \
723-
static dst_type func_name(src_type src_value, src_type src_min, \
724-
src_type src_max, dst_type dst_min, \
725-
dst_type dst_max, bool is_sign) \
726-
{ \
727-
dst_type dst_value = 0; \
728-
if (!isnan(src_value)) { \
729-
if (src_value <= src_min) \
730-
dst_value = dst_min; \
731-
else if (src_value >= src_max) \
732-
dst_value = dst_max; \
733-
else { \
734-
if (is_sign) \
735-
dst_value = (dst_type)(signed_type)src_value; \
736-
else \
737-
dst_value = (dst_type)src_value; \
738-
} \
739-
} \
740-
return dst_value; \
722+
#define TRUNC_FUNCTION(func_name, src_type, dst_type, signed_type, isnan_op) \
723+
static dst_type func_name(src_type src_value, src_type src_min, \
724+
src_type src_max, dst_type dst_min, \
725+
dst_type dst_max, bool is_sign) \
726+
{ \
727+
dst_type dst_value = 0; \
728+
if (!isnan_op(src_value)) { \
729+
if (src_value <= src_min) \
730+
dst_value = dst_min; \
731+
else if (src_value >= src_max) \
732+
dst_value = dst_max; \
733+
else { \
734+
if (is_sign) \
735+
dst_value = (dst_type)(signed_type)src_value; \
736+
else \
737+
dst_value = (dst_type)src_value; \
738+
} \
739+
} \
740+
return dst_value; \
741741
}
742742

743-
TRUNC_FUNCTION(trunc_f32_to_i32, float32, uint32, int32)
744-
TRUNC_FUNCTION(trunc_f32_to_i64, float32, uint64, int64)
745-
TRUNC_FUNCTION(trunc_f64_to_i32, float64, uint32, int32)
746-
TRUNC_FUNCTION(trunc_f64_to_i64, float64, uint64, int64)
743+
TRUNC_FUNCTION(trunc_f32_to_i32, float32, uint32, int32, isnanf)
744+
TRUNC_FUNCTION(trunc_f32_to_i64, float32, uint64, int64, isnanf)
745+
TRUNC_FUNCTION(trunc_f64_to_i32, float64, uint32, int32, isnan)
746+
TRUNC_FUNCTION(trunc_f64_to_i64, float64, uint64, int64, isnan)
747747

748748
static bool
749749
trunc_f32_to_int(WASMModuleInstance *module, uint8 *frame_ip, uint32 *frame_lp,
@@ -755,7 +755,7 @@ trunc_f32_to_int(WASMModuleInstance *module, uint8 *frame_ip, uint32 *frame_lp,
755755
uint32 dst_value_i32;
756756

757757
if (!saturating) {
758-
if (isnan(src_value)) {
758+
if (isnanf(src_value)) {
759759
wasm_set_exception(module, "invalid conversion to integer");
760760
return false;
761761
}

core/shared/platform/alios/platform_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ float rintf(float x);
6767
float fabsf(float x);
6868
float truncf(float x);
6969
int signbit(double x);
70+
int signbitf(float x);
7071
int isnan(double x);
72+
int isnanf(float x);
7173
/* clang-format on */
7274

7375
/* The below types are used in platform_api_extension.h,

core/shared/platform/common/math/math.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,21 @@ freebsd_isnan(double d)
10051005
}
10061006
}
10071007

1008+
static int
1009+
freebsd_isnanf(float f)
1010+
{
1011+
if (is_little_endian()) {
1012+
IEEEf2bits_L u;
1013+
u.f = f;
1014+
return (u.bits.exp == 0xff && u.bits.man != 0);
1015+
}
1016+
else {
1017+
IEEEf2bits_B u;
1018+
u.f = f;
1019+
return (u.bits.exp == 0xff && u.bits.man != 0);
1020+
}
1021+
}
1022+
10081023
static float
10091024
freebsd_fabsf(float x)
10101025
{
@@ -1600,6 +1615,12 @@ fabs(double x)
16001615
return freebsd_fabs(x);
16011616
}
16021617

1618+
int
1619+
isnanf(float x)
1620+
{
1621+
return freebsd_isnanf(x);
1622+
}
1623+
16031624
int
16041625
isnan(double x)
16051626
{
@@ -1618,6 +1639,14 @@ signbit(double x)
16181639
return ((__HI(x) & 0x80000000) >> 31);
16191640
}
16201641

1642+
int
1643+
signbitf(float x)
1644+
{
1645+
unsigned int i;
1646+
GET_FLOAT_WORD(i, x);
1647+
return (int)(i >> 31);
1648+
}
1649+
16211650
float
16221651
fabsf(float x)
16231652
{

0 commit comments

Comments
 (0)