Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM support #133

Closed
wants to merge 9 commits into from
Closed

WASM support #133

wants to merge 9 commits into from

Conversation

jijjijj
Copy link

@jijjijj jijjijj commented Mar 15, 2024

General overview:

  • Added WASM.h that implements the basic functions using wasm_-intrinsics
  • Added auto-detection of WASM availability during compilation via macros
  • Updated CMakeLists for it to automatically detect WASM/Emscripten and exclude/include corresponding files
  • Added FASTNOISE2_SCALAR_ONLY Cmake option in order for consumers to be able to build scalar-only version of library (may be useful for some other exotic platform that doesn't [fully] support SIMD)
  • Updated SIMDUnitTest.cpp to support WASM

Some notes:

  • All test except for InvSqrt_f32 are passing. The InvSqrt_f32 is implemented as full-precision reciprocal of square root, so I guess it's failing tests because of its full precision

    Some of the failing InvSqrt_f32 tests

    InvSqrt_f32 - Base: 1 Testing: 131072
    FastSIMDTest.js:1700 131072 Failed: expected: 31294143183454208.000000 actual: 31310464059179008.000000 index: 0 floats: 0.000000 : 1313019.625000
    FastSIMDTest.js:1700 131072 Failed: expected: 0.000000 actual: 0.000000 index: 1 floats: 8604068347904.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 0.000018 actual: 0.000018 index: 2 floats: 3244607232.000000 : -11488148214748940590763349130583474176.000000
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 3 floats: -1923216266592583265009398455124099072.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 0.001827 actual: 0.001827 index: 4 floats: 299713.687500 : 111849439645889771479512895193088.000000
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 5 floats: -11258954752.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: -0.000000 actual: -nan index: 6 floats: -0.000000 : -0.174112
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 7 floats: -1.335780 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 8 floats: -273326452056742952960.000000 : -2112412712960.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 0.000875 actual: 0.000875 index: 9 floats: 1305859.000000 : -701039232.000000
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 10 floats: -15170661.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 1302237708025856.000000 actual: 1303441506828288.000000 index: 11 floats: 0.000000 : -0.367376
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 12 floats: -96608.437500 : 6807990731479711744.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 194.009384 actual: 194.285385 index: 13 floats: 0.000026 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 0.000000 actual: 0.000000 index: 14 floats: 21103273522822519426383872.000000 : 0.758328
    FastSIMDTest.js:1700 131072 Failed: expected: 49713444.000000 actual: 49768484.000000 index: 15 floats: 0.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: -0.000000 actual: -nan index: 16 floats: -0.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 51243980658049024.000000 actual: 51261894966640640.000000 index: 17 floats: 0.000000 : 0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 218101.359375 actual: 218351.937500 index: 18 floats: 0.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 4310046389305344.000000 actual: 4311402525229056.000000 index: 19 floats: 0.000000 : -150550944.000000
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 20 floats: -10434533376.000000 : 13898.254883
    FastSIMDTest.js:1700 131072 Failed: expected: 0.004411 actual: 0.004413 index: 21 floats: 51358.746094 : 0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 1347171072.000000 actual: 1349515904.000000 index: 22 floats: 0.000000 : 0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 806315.000000 actual: 807561.375000 index: 23 floats: 0.000000 : -0.000003
    FastSIMDTest.js:1700 131072 Failed: expected: 0.000106 actual: 0.000106 index: 24 floats: 88301032.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 25 floats: -501616.906250 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: inf actual: -nan index: 26 floats: -39.919510 : -6267.018555
    FastSIMDTest.js:1700 131072 Failed: expected: -0.000000 actual: -nan index: 27 floats: -0.000000 : 6.684000
    FastSIMDTest.js:1700 131072 Failed: expected: 0.000000 actual: 0.000000 index: 28 floats: 242161749151439070387672872648704.000000 : 0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 0.000001 actual: 0.000001 index: 29 floats: 1274028883968.000000 : -0.000000
    FastSIMDTest.js:1700 131072 Failed: expected: -0.000000 actual: -nan index: 30 floats: -0.004396 : -75414865430546055430144.000000
    FastSIMDTest.js:1700 131072 Failed: expected: 1653474944.000000 actual: 1656043520.000000 index: 31 floats: 0.000000 : 0.000000
    

  • I added target_link_options(FastNoise PRIVATE -sALLOW_MEMORY_GROWTH=1) in the main CMakeLists and the one for tests. Maybe that wasn't a good idea, because a consumer-application may want to control this property

  • At WASM.h:132 I use __f32x4 as underlying type but it's actually an internal type and not a user-facing one. However without it some of the functions won't work as expected

  • I didn't try to compile the NoiseTool, since it's outside of scope of my work, so I don't know if it works

  • The only tests I ran were the ones in "SIMDUnitTest.cpp", let me know if there are other tests I need to check

@jijjijj jijjijj closed this Mar 22, 2024
uriel-4 added a commit to uriel-4/FastNoise2 that referenced this pull request Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant