x86-simd-sort 8.0 Adds MSVC Builds on Windows and Preserves Signed Zeros
The article's text, from Joho no Todai's page.
On December 3, 2026, the NumPy project released version 8.0 of x86-simd-sort.
The open-source C++ library sorts numbers faster by using SIMD instructions to process several values at once. It supports AVX-512 and AVX2 and selects an implementation based on the CPU it runs on.
Alongside integers and floating-point numbers, it can sort developer-defined C++ objects using keys of a supported numeric type.
Version 8.0 adds support for building with MSVC. It introduces compiler options for Microsoft Visual C++ (MSVC) and changes how the library detects available CPU instructions at runtime.
Taking advantage of SIMD requires a CPU that supports the instructions and a compiler that can emit them. The new support makes it easier to use the library in Windows C++ software developed with Visual Studio.
The release also fixes a compilation error in the static implementation when only -mavx512f was specified. It can now use the AVX2 implementation if AVX2 is enabled for the build. It also addresses a failure in GCC 16 link-time optimization (LTO) when builds include implementations for multiple instruction sets.
Fixing changes to the sign of zero
Comparing numbers can expose unexpected problems when implementing a fast sort. This release fixes floating-point SIMD sorting to preserve positive and negative zero.
Floating-point positive zero (+0.0) and negative zero (-0.0) compare equal, but have different bit representations.
The developer who made the fix found that sorting four positive zeros and one negative zero with AVX2 produced four negative zeros in ascending order and none in descending order. The number of negative zeros also changed with AVX-512 when the developer reproduced the bug using Intel SDE, which emulates CPU instructions.
The cause was the behavior of x86 floating-point minimum and maximum instructions used in the sort. If the values compare equal, both instructions return the second operand, the second value passed to the instruction.
With positive zero as the first operand and negative zero as the second, both the minimum and maximum come out as negative zero. An operation intended to order two values instead changes positive zero into negative zero.
The fix reverses the order of inputs to the maximum instruction in comparisons between separate registers. That preserves both inputs when they compare equal.
A sorted result can satisfy the numerical ordering while losing details of the original data. The negative-zero fix is a concrete example of that difference.
Choosing where NaNs go
The release also changes how floating-point sorting places NaNs, or “not a number” values.
In functions such as qsort and argsort, setting hasnan to true lets developers use the new trailing_nans option to group NaNs at the beginning or end of the result.
The default puts NaNs at the end. Setting trailing_nans to false puts them at the beginning. The option works independently of whether ordinary numbers are sorted in ascending or descending order. Descending sorts previously put NaNs first, so their default placement changes.
The release also updates argsort, which returns indices ordered by their values, and argselect, which returns indices for a partition around a chosen position. Both now take a const T* argument, treating the data it points to as read-only.
The API's types can now express that these operations do not need to change the original values. That makes it clearer to C++ callers which data is read and which can be modified.
The C API also adds partial sorting of key-value pairs with single-precision floating-point keys and 32-bit integer values.
Fixing partitioning that stalled on some data
AVX-512 key-value sorting also changes how it selects the pivot when splitting the range to be sorted.
The developer who made the change described a problem sorting 32-bit keys and values over ranges of 129 to 256 elements, when the data was heavily skewed toward the minimum.
If the majority of the sampled values were equal to the minimum, the previous code used that minimum as the pivot. Since no value was smaller, the left partition stayed empty and the right partition still held all the elements. If the minimum and maximum differed, the code partitioned the same right-hand range again. The range did not shrink, and at the recursion limit the code fell back to heapsort.
Version 8.0 applies the skew-aware pivot selection already used on large ranges to these smaller ranges as well.
Even if CPU instructions process many values at once, they cannot deliver their full benefit if every partition leaves the same amount of work. Fast sorting depends on both fast instructions and an efficient algorithm.
From Intel to NumPy
x86-simd-sort began at Intel and has been adopted by NumPy and PyTorch. OpenJDK also has a sorting implementation based on it.
After a maintainer left Intel, uncertainty about future development support led to discussions about transferring the project. The move to NumPy was completed in September 2025.
NumPy itself has an issue in which unstable sorting, which does not guarantee the original order of equal values, can change the number of negative zeros. On November 26, a proposal to bring the fixes into NumPy was submitted. It would bring in the individual x86-simd-sort commit for signed zeros and a fix from Highway, another SIMD sorting library.
Once a new library version is released, its improvements reach users when downstream software adopts and distributes the fixes. Bringing in individual fixes first, as this proposal does, is another option.
Code that Intel started to take advantage of CPU features is now maintained by an open-source project that uses it. It has gained support for Windows development tools and a fix that keeps the sign of zero intact in numerical work. Watching a technology keep being used and improve through the work of its users is one of the pleasures of open source.
