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

Add defensive EMMS instructions to each SIMD sort function #183

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/avx512-16bit-qsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ avx512_qsort_fp16(uint16_t *arr,
}
replace_inf_with_nan(arr, arrsize, nan_count, descending);
}

#ifdef __MMX__
// Workaround for compiler bug generating MMX instructions without emms
_mm_empty();
#endif
}

[[maybe_unused]] X86_SIMD_SORT_INLINE void
Expand Down Expand Up @@ -605,6 +610,11 @@ avx512_qselect_fp16(uint16_t *arr,
2 * (arrsize_t)log2(indx_last_elem));
}
}

#ifdef __MMX__
// Workaround for compiler bug generating MMX instructions without emms
_mm_empty();
#endif
}

[[maybe_unused]] X86_SIMD_SORT_INLINE void
Expand Down
10 changes: 10 additions & 0 deletions src/xss-common-keyvaluesort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ X86_SIMD_SORT_INLINE void xss_qsort_kv(
std::reverse(indexes, indexes + arrsize);
}
}

#ifdef __MMX__
// Workaround for compiler bug generating MMX instructions without emms
_mm_empty();
#endif
}

template <typename T1,
Expand Down Expand Up @@ -712,6 +717,11 @@ X86_SIMD_SORT_INLINE void xss_select_kv(T1 *keys,
std::reverse(indexes, indexes + arrsize);
}
}

#ifdef __MMX__
// Workaround for compiler bug generating MMX instructions without emms
_mm_empty();
#endif
}

template <typename T1,
Expand Down
10 changes: 10 additions & 0 deletions src/xss-common-qsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ X86_SIMD_SORT_INLINE void xss_qsort(T *arr, arrsize_t arrsize, bool hasnan)

replace_inf_with_nan(arr, arrsize, nan_count, descending);
}

#ifdef __MMX__
// Workaround for compiler bug generating MMX instructions without emms
_mm_empty();
#endif
}

// Quick select methods
Expand Down Expand Up @@ -666,6 +671,11 @@ xss_qselect(T *arr, arrsize_t k, arrsize_t arrsize, bool hasnan)
index_last_elem,
2 * (arrsize_t)log2(arrsize));
}

#ifdef __MMX__
// Workaround for compiler bug generating MMX instructions without emms
_mm_empty();
#endif
}

// Partial sort methods:
Expand Down