Skip to content

Commit a9e2a91

Browse files
committed
Faster float min/max, ceil, floor, cast by relaxing strict WebAssembly semantic.
1 parent c7ff7a8 commit a9e2a91

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

Source/Runtime/LLVMJIT.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#define PRINT_DISASSEMBLY 0
1515
#else
1616
#define USE_WRITEABLE_JIT_CODE_PAGES 0
17-
#define DUMP_UNOPTIMIZED_MODULE 0
17+
#define DUMP_UNOPTIMIZED_MODULE 1
1818
#define VERIFY_MODULE 0
19-
#define DUMP_OPTIMIZED_MODULE 0
19+
#define DUMP_OPTIMIZED_MODULE 1
2020
#define PRINT_DISASSEMBLY 0
2121
#endif
2222

Source/Runtime/WAVMIntrinsics.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "RuntimePrivate.h"
66

77
#include <math.h>
8+
#include <cmath>
89

910
namespace Runtime
1011
{
@@ -20,6 +21,9 @@ namespace Runtime
2021
template<typename Float>
2122
Float floatMin(Float left,Float right)
2223
{
24+
// SL
25+
return std::min(left, right);
26+
/*
2327
// If either operand is a NaN, convert it to a quiet NaN and return it.
2428
if(left != left) { return quietNaN(left); }
2529
else if(right != right) { return quietNaN(right); }
@@ -35,11 +39,15 @@ namespace Runtime
3539
rightComponents.value = right;
3640
return leftComponents.bitcastInt < rightComponents.bitcastInt ? right : left;
3741
}
42+
*/
3843
}
3944

4045
template<typename Float>
4146
Float floatMax(Float left,Float right)
4247
{
48+
// SL
49+
return std::max(left, right);
50+
/*
4351
// If either operand is a NaN, convert it to a quiet NaN and return it.
4452
if(left != left) { return quietNaN(left); }
4553
else if(right != right) { return quietNaN(right); }
@@ -55,34 +63,51 @@ namespace Runtime
5563
rightComponents.value = right;
5664
return leftComponents.bitcastInt > rightComponents.bitcastInt ? right : left;
5765
}
66+
*/
5867
}
5968

6069
template<typename Float>
6170
Float floatCeil(Float value)
6271
{
72+
// SL
73+
return std::ceil(value);
74+
/*
6375
if(value != value) { return quietNaN(value); }
6476
else { return ceil(value); }
77+
*/
6578
}
6679

6780
template<typename Float>
6881
Float floatFloor(Float value)
6982
{
83+
// SL
84+
return std::floor(value);
85+
/*
7086
if(value != value) { return quietNaN(value); }
7187
else { return floor(value); }
88+
*/
7289
}
7390

7491
template<typename Float>
7592
Float floatTrunc(Float value)
7693
{
94+
// SL
95+
return std::trunc(value);
96+
/*
7797
if(value != value) { return quietNaN(value); }
7898
else { return trunc(value); }
99+
*/
79100
}
80101

81102
template<typename Float>
82103
Float floatNearest(Float value)
83104
{
105+
// SL
106+
return nearbyint(value);
107+
/*
84108
if(value != value) { return quietNaN(value); }
85109
else { return nearbyint(value); }
110+
*/
86111
}
87112

88113
DEFINE_INTRINSIC_FUNCTION2(wavmIntrinsics,floatMin,floatMin,f32,f32,left,f32,right) { return floatMin(left,right); }
@@ -102,6 +127,8 @@ namespace Runtime
102127
template<typename Dest,typename Source,bool isMinInclusive>
103128
Dest floatToInt(Source sourceValue,Source minValue,Source maxValue)
104129
{
130+
return (Dest)sourceValue;
131+
/*
105132
if(sourceValue != sourceValue)
106133
{
107134
causeException(Exception::Cause::invalidFloatOperation);
@@ -111,6 +138,7 @@ namespace Runtime
111138
causeException(Exception::Cause::integerDivideByZeroOrIntegerOverflow);
112139
}
113140
return (Dest)sourceValue;
141+
*/
114142
}
115143

116144
DEFINE_INTRINSIC_FUNCTION1(wavmIntrinsics,floatToSignedInt,floatToSignedInt,i32,f32,source) { return floatToInt<I32,F32,false>(source,(F32)INT32_MIN,-(F32)INT32_MIN); }

0 commit comments

Comments
 (0)