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

simdjson uses MMX but doesn't clear x87 state #169

Closed
alexey-milovidov opened this issue May 20, 2019 · 3 comments
Closed

simdjson uses MMX but doesn't clear x87 state #169

alexey-milovidov opened this issue May 20, 2019 · 3 comments

Comments

@alexey-milovidov
Copy link
Contributor

milovidov@example:~/ClickHouse/contrib/simdjson$ grep -r '__m64' .
./include/simdjson/numberparsing.h:  __m64 val;
./include/simdjson/numberparsing.h:  __m64 base = _mm_sub_pi8(val,_mm_set1_pi8('0'));
./include/simdjson/numberparsing.h:  __m64 basecmp = _mm_subs_pu8(base,_mm_set1_pi8(9));
./singleheader/simdjson.h:  __m64 val;
./singleheader/simdjson.h:  __m64 base = _mm_sub_pi8(val,_mm_set1_pi8('0'));
./singleheader/simdjson.h:  __m64 basecmp = _mm_subs_pu8(base,_mm_set1_pi8(9));
milovidov@example:~/ClickHouse/contrib/simdjson$ grep -r 'm_empty' .
milovidov@example:~/ClickHouse/contrib/simdjson$

This lead to errors in any subsequent usage of long double type.
Explanation: https://github.com/yandex/ClickHouse/blob/master/dbms/src/Compression/LZ4_decompress_faster.cpp#L78

  * But if we write code this way, it will lead to
  *  extremely weird and extremely non obvious
  *  effects in completely unrelated parts of code.
  *
  * Because using MMX registers alters the mode of operation of x87 FPU,
  *  and then operations with FPU become broken.
@alexey-milovidov alexey-milovidov changed the title simdjson use MMX but doesn't clear x87 state simdjson uses MMX but doesn't clear x87 state May 20, 2019
alexey-milovidov added a commit to alexey-milovidov/simdjson that referenced this issue May 20, 2019
@alexey-milovidov
Copy link
Contributor Author

Solution 1: simply remove MMX code (see the attached PR).
Solution 2: issue _mm_empty() call after parsing.

@lemire
Copy link
Member

lemire commented May 20, 2019

Fascinating.

@lemire
Copy link
Member

lemire commented May 20, 2019

Issue fixed by PR (which removes offending code).

Performance impact is negligible. Alexey Milovidov will be added to our list of contributors.

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

No branches or pull requests

2 participants