-
Notifications
You must be signed in to change notification settings - Fork 171
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
Fixed Kenneth's PHP bug in max/min - was an aliasing bug in sse #56
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5be9d83
made it compile in VC
rrrlasse 509e913
Fixed Kenneth's PHP bug in max/min - was an aliasing bug in sse
rrrlasse a1ac430
added description of aliasing bug fix
rrrlasse 07dca9c
added more explanation
rrrlasse f100f34
Merge branch 'master' of https://github.com/rrrlasse/tightdb into que…
rrrlasse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -843,7 +843,7 @@ template <bool find_max, size_t w> bool Array::minmax(int64_t& result, size_t st | |
if ((w == 8 || w == 16 || w == 32) && end - start > 2 * sizeof(__m128i) * 8 / NO0(w)) { | ||
__m128i *data = (__m128i *)(m_data + start * w / 8); | ||
__m128i state = data[0]; | ||
__m128i state2; | ||
char state2[sizeof(state)]; | ||
|
||
size_t chunks = (end - start) * w / 8 / sizeof(__m128i); | ||
for (size_t t = 0; t < chunks; t++) { | ||
|
@@ -857,8 +857,14 @@ template <bool find_max, size_t w> bool Array::minmax(int64_t& result, size_t st | |
start += sizeof(__m128i) * 8 / NO0(w); | ||
} | ||
|
||
// prevent taking address of 'state' to make the compiler keep it in SSE register in above loop (vc2010/gcc4.6) | ||
state2 = state; | ||
// Todo: prevent taking address of 'state' to make the compiler keep it in SSE register in above loop (vc2010/gcc4.6) | ||
|
||
// We originally had declared '__m128i state2' and did an 'state2 = state' assignment. When we read from state2 through int16_t, int32_t or int64_t in GetUniversal(), | ||
// the compiler thinks it cannot alias state2 and hence reorders the read and assignment. | ||
|
||
// In this fixed version using memcpy, we have char-read-access from __m128i (OK aliasing) and char-write-access to char-array, and finally int8/16/32/64 | ||
// read access from char-array (OK aliasing). | ||
memcpy(&state2, &state, sizeof(state)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding to my previous comment, I believe that if the memcpy() was changed to
then the aliasing bug would be reintroduced. My point is that it is not the type of the accessed memory that matters, but rather the (possibly punned) type through which that memory is accessed. |
||
for (size_t t = 0; t < sizeof(__m128i) * 8 / NO0(w); ++t) { | ||
const int64_t v = GetUniversal<w>(((const char *)&state2), t); | ||
if (find_max ? v > m : v < m) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that changing the type of state2 has no effect on the aliasing issue. I believe what fixes the aliasing bug is the fact that memcpy() modifies state2 as though it was a character array. I would love to see what happens when reverting state2 back to __m128i. Hopefully nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ignore my comments on aliasing. My theory turned out to be wrong.