Skip to content

Commit

Permalink
Fix failing FMA on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Apr 27, 2024
1 parent 396d9c8 commit 52d5875
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
target_compile_options(FastSIMD PUBLIC "-msimd128")
target_compile_options(FastSIMD PUBLIC -msimd128)
endif()

target_include_directories(FastSIMD PUBLIC
Expand Down
4 changes: 2 additions & 2 deletions include/FastSIMD/ToolSet/WASM/128/f32x4.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ namespace FS
template<FastSIMD::FeatureSet SIMD, typename = EnableIfNative<f32<4, SIMD>>, typename = EnableIfRelaxed<SIMD>()>
FS_FORCEINLINE f32<4, SIMD> FMulAdd( const f32<4, SIMD>& a, const f32<4, SIMD>& b, const f32<4, SIMD>& c )
{
return wasm_f32x4_relaxed_madd( c.native, a.native, b.native );
return wasm_f32x4_relaxed_madd( a.native, b.native, c.native );
}

template<FastSIMD::FeatureSet SIMD, typename = EnableIfNative<f32<4, SIMD>>, typename = EnableIfRelaxed<SIMD>()>
FS_FORCEINLINE f32<4, SIMD> FNMulAdd( const f32<4, SIMD>& a, const f32<4, SIMD>& b, const f32<4, SIMD>& c )
{
return wasm_f32x4_relaxed_nmadd( c.native, a.native, b.native );
return wasm_f32x4_relaxed_nmadd( a.native, b.native, c.native );
}
}
9 changes: 5 additions & 4 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct TestRunner

for( size_t idx = 0; idx < TestCount; idx += RegisterBytes / sizeof( int ) )
{
bool failed = false;
int failed = 0;

for( size_t testIdx = 0; testIdx < tests.size(); testIdx++ )
{
Expand Down Expand Up @@ -260,14 +260,15 @@ struct TestRunner
if( !CompareOutputs( testNameRelaxed, test.featureSet, test.returnType, accuracy, outputCount, scalarResults, simdResults ) )
{
std::cerr << "Inputs: " << tests[0].inputsFunc( idx, rndInts, rndFloats ) << std::endl;
failed = true;
failed++;
}
}
}

if( failed )
if( failed >= 3 )
{
std::cin.ignore();
std::cerr << "Skipping test, fail limit reached" << std::endl;
break;
}
}

Expand Down
10 changes: 4 additions & 6 deletions tests/test.inl
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,10 @@ class FastSIMD::DispatchClass<TestFastSIMD<RegisterBytes, Relaxed>, SIMD> : publ

if constexpr( !( SIMD & FeatureFlag::AVX512_F ) )
{
RegisterTest( tests, "f32 cast to m32", []( TestRegf32 a ) { return FS_BIND_INTRINSIC( FS::Cast<FS::Mask<32>> )( a ); } );
RegisterTest( tests, "i32 cast to m32", []( TestRegi32 a ) { return FS_BIND_INTRINSIC( FS::Cast<FS::Mask<32>> )( a ); } );
RegisterTest( tests, "m32 cast to i32", []( TestRegm32 a ) { return FS_BIND_INTRINSIC( FS::Cast<int32_t> )( a ) ; } );
RegisterTest( tests, "m32 cast to f32", []( TestRegm32 a ) { return FS_BIND_INTRINSIC( FS::Cast<float> )( a ); } );
RegisterTest( tests, "m32i cast to i32", []( TestRegm32i a ) { return FS_BIND_INTRINSIC( FS::Cast<int32_t> )( a ); } );
RegisterTest( tests, "m32i cast to f32", []( TestRegm32i a ) { return FS_BIND_INTRINSIC( FS::Cast<float> )( a ); } );
RegisterTest( tests, "m32 cast to i32", []( TestRegm32 a ) { return FS_BIND_INTRINSIC( FS::Cast<FS::Mask<32>> )( FS_BIND_INTRINSIC( FS::Cast<int32_t> )( a ) ); } );
RegisterTest( tests, "m32 cast to f32", []( TestRegm32 a ) { return FS_BIND_INTRINSIC( FS::Cast<FS::Mask<32>> )( FS_BIND_INTRINSIC( FS::Cast<float> )( a ) ); } );
RegisterTest( tests, "m32i cast to i32", []( TestRegm32i a ) { return FS_BIND_INTRINSIC( FS::Cast<typename TestRegm32i::ElementType> )( FS_BIND_INTRINSIC( FS::Cast<int32_t> )( a ) ); } );
RegisterTest( tests, "m32i cast to f32", []( TestRegm32i a ) { return FS_BIND_INTRINSIC( FS::Cast<typename TestRegm32i::ElementType> )( FS_BIND_INTRINSIC( FS::Cast<float> )( a ) ); } );
}
return tests;
}
Expand Down

0 comments on commit 52d5875

Please sign in to comment.