Repository navigation
Conversation
The generic fallback a - Masked( mask, -1 ) costs a zero-masked move plus the add/sub on compilers that do not fold it (MSVC). Use _mm512_mask_sub/add with a -1 broadcast instead; arithmetic is identical in every lane. f32x16 keeps the generic version: with MSVC 19.51 the merge-masked float form made SuperSimplex 3D/4D and Simplex 3D slower and changed the results of the surrounding float maths, and MaskedDecrement would keep -0 in masked off lanes where the generic a + Masked( mask, -1 ) gives +0.
This was referenced Oct 17, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
MaskedIncrementandMaskedDecrementhave no AVX512 overload, soi32<16>uses the generica - Masked( mask, Register( -1 ) )fromGeneric/Functions.h. MSVC compiles that as written: a zero-masked move of the -1 constant (vmovdqa32 zmm {k}{z}), thenvpsubd, with one more register live. GCC 16 converts the mask withvpmovm2dand then subtracts. Clang already turns both forms intovpmovm2d+vpsubdin most places.FastNoise2 uses the int versions in its grid loops (
AxisReset), the 4D Simplex rank counting and the Simplex domain warps.Change
Add
i32x16overloads next toMaskedAdd:_mm512_mask_sub_epi32( a, mask, a, set1( -1 ) )for increment and_mm512_mask_add_epi32( a, mask, a, set1( -1 ) )for decrement. Each is one merge-masked add/sub with a broadcast constant. The result is the same in every lane. 1024-bit registers still split in the generic code, and each half now uses the new overload.f32x16stays on the generic version. I tried the same float overloads, and they weren't worth it:MaskedDecrementwould keep -0 in masked off lanes, where the generica + Masked( m, -1 )gives +0. Thef32 masked decrementtest checks for +0.Effect
I built FastNoise2 master (8c2d080) against this branch and against FastSIMD master, then timed both on a Ryzen 9 7950X. Both builds are loaded in one process and timed interleaved on one pinned core. Each figure is the median of 3-5 processes with alternating order, over the default 63 node/dimension cases of the AVX512 feature set. AVX2 is unchanged and serves as a control. The numbers are new/old time:
Most of the MSVC gain comes from fewer stack spills. With 19.51:
GenUniformGrid3D/4D has 610 → 576 and 664 → 613 stack references.Genhas 1041 → 970 instructions, with 357 → 310 stack references.In the whole FastNoise2 DLL:
vpsubd/vpadddfrom 184 to 286.vpmovm2dgoes from 114 to 12.vpmovm2dgoes from 154 to 130, and only 3 functions change.On a FastNoise2 development branch with restructured grid and Simplex loops, MSVC 19.51 measured 1.002 with these overloads (on a busy machine). So the gain depends on how much register pressure the caller has.
Testing
i32 masked increment,i32 masked increment int maskandi32 masked decrementat 512 and 1024 bit.i32 masked decrementtests then fail on AVX512 and AVX512 RELAXED.x86/512/i32x16.hchanges, so ARM and WASM builds aren't affected.Other PRs
i32x16.h.