Currently we have Vector{nnn}<T>.Zero type which the JIT recognises and transforms into a xorps or similar. It would be useful to have a .AllBitsSet property, which is the inverse, having all bits set. The JIT could ideally generate this to be
cmpps <dest>, xmm0, xmm0, 0x0 which is recognised as dependency breaking on modern intel architectures for minimal cost. An all-ones value is useful, and can be frequently used for masking and mixing elements alongside the all-zero value.
Rational and Usage
It is commonly used, for example it can be used as Xor(left, AllBitsSet) to implement a Not using SIMD, as well as frequently for masking and mixing elements, e.g with Shuffle/And/Or
Proposed API
public struct Vector64<T> where T : struct
{
public static Vector64<T> AllBitsSet { [Intrinsic] get; }
}
public struct Vector128<T> where T : struct
{
public static Vector128<T> AllBitsSet { [Intrinsic] get; }
}
public struct Vector256<T> where T : struct
{
public static Vector256<T> AllBitsSet { [Intrinsic] get; }
}
Details
It should be implemented as an intrinsic which results in
[v]cmpps xmmN, xmmN, xmmN
which is recognised as dependency breaking on Haswell+ archs. Software fallback is relatively simple, effectively Vector128.Create(-1).As<int, T>()
Open Questions
Is the name ok?
Pull Request
None yet
Updates
Currently we have
Vector{nnn}<T>.Zerotype which the JIT recognises and transforms into axorpsor similar. It would be useful to have a.AllBitsSetproperty, which is the inverse, having all bits set. The JIT could ideally generate this to becmpps <dest>, xmm0, xmm0, 0x0which is recognised as dependency breaking on modern intel architectures for minimal cost. An all-ones value is useful, and can be frequently used for masking and mixing elements alongside the all-zero value.Rational and Usage
It is commonly used, for example it can be used as
Xor(left, AllBitsSet)to implement aNotusing SIMD, as well as frequently for masking and mixing elements, e.g withShuffle/And/OrProposed API
Details
It should be implemented as an intrinsic which results in
which is recognised as dependency breaking on Haswell+ archs. Software fallback is relatively simple, effectively
Vector128.Create(-1).As<int, T>()Open Questions
Is the name ok?
Pull Request
None yet
Updates