Skip to content

Commit

Permalink
Faster float min/max, ceil, floor, cast by relaxing strict WebAssembl…
Browse files Browse the repository at this point in the history
…y semantic.
  • Loading branch information
sletz committed Sep 10, 2017
1 parent c7ff7a8 commit a9e2a91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/Runtime/LLVMJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#define PRINT_DISASSEMBLY 0
#else
#define USE_WRITEABLE_JIT_CODE_PAGES 0
#define DUMP_UNOPTIMIZED_MODULE 0
#define DUMP_UNOPTIMIZED_MODULE 1
#define VERIFY_MODULE 0
#define DUMP_OPTIMIZED_MODULE 0
#define DUMP_OPTIMIZED_MODULE 1
#define PRINT_DISASSEMBLY 0
#endif

Expand Down
28 changes: 28 additions & 0 deletions Source/Runtime/WAVMIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "RuntimePrivate.h"

#include <math.h>
#include <cmath>

namespace Runtime
{
Expand All @@ -20,6 +21,9 @@ namespace Runtime
template<typename Float>
Float floatMin(Float left,Float right)
{
// SL
return std::min(left, right);
/*
// If either operand is a NaN, convert it to a quiet NaN and return it.
if(left != left) { return quietNaN(left); }
else if(right != right) { return quietNaN(right); }
Expand All @@ -35,11 +39,15 @@ namespace Runtime
rightComponents.value = right;
return leftComponents.bitcastInt < rightComponents.bitcastInt ? right : left;
}
*/
}

template<typename Float>
Float floatMax(Float left,Float right)
{
// SL
return std::max(left, right);
/*
// If either operand is a NaN, convert it to a quiet NaN and return it.
if(left != left) { return quietNaN(left); }
else if(right != right) { return quietNaN(right); }
Expand All @@ -55,34 +63,51 @@ namespace Runtime
rightComponents.value = right;
return leftComponents.bitcastInt > rightComponents.bitcastInt ? right : left;
}
*/
}

template<typename Float>
Float floatCeil(Float value)
{
// SL
return std::ceil(value);
/*
if(value != value) { return quietNaN(value); }
else { return ceil(value); }
*/
}

template<typename Float>
Float floatFloor(Float value)
{
// SL
return std::floor(value);
/*
if(value != value) { return quietNaN(value); }
else { return floor(value); }
*/
}

template<typename Float>
Float floatTrunc(Float value)
{
// SL
return std::trunc(value);
/*
if(value != value) { return quietNaN(value); }
else { return trunc(value); }
*/
}

template<typename Float>
Float floatNearest(Float value)
{
// SL
return nearbyint(value);
/*
if(value != value) { return quietNaN(value); }
else { return nearbyint(value); }
*/
}

DEFINE_INTRINSIC_FUNCTION2(wavmIntrinsics,floatMin,floatMin,f32,f32,left,f32,right) { return floatMin(left,right); }
Expand All @@ -102,6 +127,8 @@ namespace Runtime
template<typename Dest,typename Source,bool isMinInclusive>
Dest floatToInt(Source sourceValue,Source minValue,Source maxValue)
{
return (Dest)sourceValue;
/*
if(sourceValue != sourceValue)
{
causeException(Exception::Cause::invalidFloatOperation);
Expand All @@ -111,6 +138,7 @@ namespace Runtime
causeException(Exception::Cause::integerDivideByZeroOrIntegerOverflow);
}
return (Dest)sourceValue;
*/
}

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

0 comments on commit a9e2a91

Please sign in to comment.