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

It's not possible to store bit masks in SIMD register for logical operations. #2840

Closed
juj opened this issue Sep 27, 2014 · 4 comments
Closed
Assignees
Labels

Comments

@juj
Copy link
Collaborator

juj commented Sep 27, 2014

Build the following code:

#include <xmmintrin.h>
#include <stdio.h>
#include <string>

std::string tostr(__m128 m)
{
    unsigned int u[4];
    _mm_store_ps((float*)u, m);
    char str[256];
    sprintf(str, "[%X,%X,%X,%X]", u[3], u[2], u[1], u[0]);
    return str;
}

int main()
{
    unsigned int u[4] = { 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU, 0xFFFFFFFFU };
    __m128 m1 = _mm_load_ps((float*)&u);
    printf("%s\n", tostr(m1).c_str());
}

Running in FF Nightly prints out [7FC00000,7FC00000,7FC00000,7FC00000], whereas it should print [FFFFFFFF,FFFFFFFF,FFFFFFFF,FFFFFFFF].

@sunfishcode
Copy link
Collaborator

Yes, this does look like NaN caonicalization in the polyfill, as you noted in tc39/ecmascript_simd#38 (comment)

The only ways I can think of to fix this in the polyfill involve making float32x4 hold raw bit patterns and convert them to actual float32 values on demand, but that would add a bunch of complexity and slow it down.

Native implementations can avoid this problem because a plain SIMD load won't involve loading scalar values, so it won't require NaN canonicalization.

@juj
Copy link
Collaborator Author

juj commented Jun 20, 2015

Added a test for this in the above commit. This passes in node.js which uses the polyfill, but does not pass in SpiderMonkey, which should not be using the polyfill, so I don't think this is a polyfill issue, but related to SpiderMonkey instead?

juj added a commit to juj/emscripten that referenced this issue Jun 25, 2015
juj added a commit to juj/emscripten that referenced this issue Aug 10, 2015
juj added a commit to juj/emscripten that referenced this issue Aug 15, 2015
juj added a commit to juj/emscripten that referenced this issue Aug 15, 2015
juj added a commit to juj/emscripten that referenced this issue Aug 16, 2015
juj added a commit to juj/emscripten that referenced this issue Aug 17, 2015
@juj
Copy link
Collaborator Author

juj commented Sep 3, 2015

Like said earlier, this is not a polyfill issue. LLVM is failing here.

Building with em++ s.cpp -o s.html -msse -O0, or -O2 or -O3 and running in current Nightly works, but building with O1 does not, and the NaNs get canonicalized. The problem is that LLVM is generating optimizations that break under canonicalization.

@juj juj self-assigned this Sep 3, 2015
juj added a commit to juj/emscripten-fastcomp that referenced this issue Sep 3, 2015
…rns in a SIMD vector, don't attempt to create a float SIMD vector directly out of them, since JS source can't represent NaNs with noncanonical bits. Instead, create a int SIMD vector and cast it to float one to detour to the SIMD vector with correct bits intact. Fixes emscripten-core/emscripten#2840,  emscripten-core/emscripten#3560, emscripten-core/emscripten#3010 and emscripten-core/emscripten#3403.
juj added a commit to juj/emscripten-fastcomp that referenced this issue Sep 3, 2015
…rns in a SIMD vector, don't attempt to create a float SIMD vector directly out of them, since JS source can't represent NaNs with noncanonical bits. Instead, create a int SIMD vector and cast it to float one to detour to the SIMD vector with correct bits intact. Fixes emscripten-core/emscripten#2840,  emscripten-core/emscripten#3560, emscripten-core/emscripten#3010 and emscripten-core/emscripten#3403.
juj added a commit to juj/emscripten-fastcomp that referenced this issue Sep 3, 2015
…rns in a SIMD vector, don't attempt to create a float SIMD vector directly out of them, since JS source can't represent NaNs with noncanonical bits. Instead, create a int SIMD vector and cast it to float one to detour to the SIMD vector with correct bits intact. Fixes emscripten-core/emscripten#2840,  emscripten-core/emscripten#3560, emscripten-core/emscripten#3010 and emscripten-core/emscripten#3403.
@juj
Copy link
Collaborator Author

juj commented Sep 18, 2015

Fixed in the above PR, works in current incoming.

@juj juj closed this as completed Sep 18, 2015
juj added a commit to juj/emscripten-fastcomp that referenced this issue Sep 19, 2015
…rns in a SIMD vector, don't attempt to create a float SIMD vector directly out of them, since JS source can't represent NaNs with noncanonical bits. Instead, create a int SIMD vector and cast it to float one to detour to the SIMD vector with correct bits intact. Fixes emscripten-core/emscripten#2840,  emscripten-core/emscripten#3560, emscripten-core/emscripten#3010 and emscripten-core/emscripten#3403.
juj added a commit to juj/emscripten-fastcomp that referenced this issue Sep 22, 2015
…rns in a SIMD vector, don't attempt to create a float SIMD vector directly out of them, since JS source can't represent NaNs with noncanonical bits. Instead, create a int SIMD vector and cast it to float one to detour to the SIMD vector with correct bits intact. Fixes emscripten-core/emscripten#2840,  emscripten-core/emscripten#3560, emscripten-core/emscripten#3010 and emscripten-core/emscripten#3403.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants