Repository: dotnet/runtime
File: src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.BitDecrement.cs (C#)

Code before:
                }

                // +0.0 returns -Epsilon
                if (bits == PositiveZeroBits)
                {
                    return unchecked((short)NegativeEpsilonBits);
                }

                // Negative values need to be incremented, positive values need to be decremented
                return (short)(bits < SignMask ? bits - 1 : bits + 1);
            }

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public static Vector128<short> Invoke(Vector128<short> x)
            {
                Vector128<ushort> bits = x.AsUInt16();

                // General case: negative -> increment, positive -> decrement
                Vector128<ushort> isNegative = Vector128.ShiftRightArithmetic(x, 15).AsUInt16();
                Vector128<ushort> result = Vector128.ConditionalSelect(
                    isNegative,
                    bits + Vector128<ushort>.One,
                    bits - Vector128<ushort>.One);

                // Handle special cases with a single conditional select
                Vector128<ushort> isPositiveZero = Vector128.Equals(bits, Vector128<ushort>.Zero);
                Vector128<ushort> specialValue = Vector128.Create(NegativeEpsilonBits) & isPositiveZero;

                // NaN: (bits & 0x7FFF) > 0x7C00 (both positive and negative NaN)
                // -Infinity: bits == 0xFC00
                Vector128<ushort> absValue = bits & Vector128.Create((ushort)0x7FFF);
                Vector128<ushort> isNaN = Vector128.GreaterThan(absValue, Vector128.Create(PositiveInfinityBits));
                Vector128<ushort> isNegInf = Vector128.Equals(bits, Vector128.Create(NegativeInfinityBits));
                Vector128<ushort> isNaNOrNegInf = isNaN | isNegInf;
                specialValue |= bits & isNaNOrNegInf;

                Vector128<ushort> specialMask = isPositiveZero | isNaNOrNegInf;
                return Vector128.ConditionalSelect(specialMask, specialValue, result).AsInt16();
            }

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public static Vector256<short> Invoke(Vector256<short> x)
            {
                Vector256<ushort> bits = x.AsUInt16();

                // General case: negative -> increment, positive -> decrement
                Vector256<ushort> isNegative = Vector256.ShiftRightArithmetic(x, 15).AsUInt16();
                Vector256<ushort> result = Vector256.ConditionalSelect(
                    isNegative,
                    bits + Vector256<ushort>.One,
                    bits - Vector256<ushort>.One);

Review comment (suggestion):
nit:
```suggestion
                Vector128<ushort> isPositiveZero = Vector128.IsZero(bits);
```

Similar premise as before. 

-- It also looks like the general `BitDecrementOperators` has a minor perf nit in that it's doing: `Vector128.IsZero(xFloat).AsUInt32()` (which is true for `+0` and `-0`) when it should be doing `Vector128.IsZero(xFloat.AsUInt32())` so it only checks for `+0`. It's correct in both cases, but the check for just bitwise 0 is cheaper.

Code after:
                    bits - Vector128<ushort>.One);

                // Handle special cases with a single conditional select
                Vector128<ushort> isPositiveZero = Vector128.IsZero(bits);
                Vector128<ushort> specialValue = Vector128.Create(NegativeEpsilonBits) & isPositiveZero;

                // NaN: (bits & 0x7FFF) > 0x7C00 (both positive and negative NaN)
                // -Infinity: bits == 0xFC00
                Vector128<ushort> absValue = bits & Vector128.Create((ushort)0x7FFF);
                Vector128<ushort> isNaN = Vector128.GreaterThan(absValue, Vector128.Create(PositiveInfinityBits));
                Vector128<ushort> isNegInf = Vector128.Equals(bits, Vector128.Create(NegativeInfinityBits));
                Vector128<ushort> isNaNOrNegInf = isNaN | isNegInf;
                specialValue |= bits & isNaNOrNegInf;

                Vector128<ushort> specialMask = isPositiveZero | isNaNOrNegInf;
                return Vector128.ConditionalSelect(specialMask, specialValue, result).AsInt16();
            }

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public static Vector256<short> Invoke(Vector256<short> x)
            {
                Vector256<ushort> bits = x.AsUInt16();

                // General case: negative -> increment, positive -> decrement
                Vector256<ushort> isNegative = Vector256.IsNegative(x).AsUInt16();
                Vector256<ushort> result = Vector256.ConditionalSelect(
                    isNegative,
                    bits + Vector256<ushort>.One,
                    bits - Vector256<ushort>.One);

                // Handle special cases with a single conditional select
                Vector256<ushort> isPositiveZero = Vector256.IsZero(bits);
                Vector256<ushort> specialValue = Vector256.Create(NegativeEpsilonBits) & isPositiveZero;

                // NaN: (bits & 0x7FFF) > 0x7C00 (both positive and negative NaN)
                // -Infinity: bits == 0xFC00
                Vector256<ushort> absValue = bits & Vector256.Create((ushort)0x7FFF);
                Vector256<ushort> isNaN = Vector256.GreaterThan(absValue, Vector256.Create(PositiveInfinityBits));
                Vector256<ushort> isNegInf = Vector256.Equals(bits, Vector256.Create(NegativeInfinityBits));
                Vector256<ushort> isNaNOrNegInf = isNaN | isNegInf;
                specialValue |= bits & isNaNOrNegInf;

                Vector256<ushort> specialMask = isPositiveZero | isNaNOrNegInf;
                return Vector256.ConditionalSelect(specialMask, specialValue, result).AsInt16();
            }

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public static Vector512<short> Invoke(Vector512<short> x)
            {
                Vector512<ushort> bits = x.AsUInt16();