public void RunStructFldScenario(ScalarTernOpBinResTest__MultiplyNoFlagsUInt32 testClass)
            {
                UInt32 buffer = 0;
                var    result = Bmi2.MultiplyNoFlags(_fld1, _fld2, &buffer);

                testClass.ValidateResult(_fld1, _fld2, buffer, result);
            }
示例#2
0
        public static ulong bits_extractparallel(ulong x, ulong mask)
        {
            if (Bmi2.IsBmi2Supported)
            {
                return(Bmi2.pext_u64(x, mask));
            }
            else
            {
                ulong result = 0;

                for (ulong i = 1; mask != 0; i += i)
                {
                    if ((x & bits_extractlowest(mask)) != 0)
                    {
                        result |= i;
                    }
                    else
                    {
                    }

                    mask = bits_resetlowest(mask);
                }
                return(result);
            }
        }
示例#3
0
        public static uint bits_extractparallel(uint x, uint mask)
        {
            if (Bmi2.IsBmi2Supported)
            {
                return(Bmi2.pext_u32(x, mask));
            }
            else
            {
                uint result = 0;

                for (uint i = 1; mask != 0; i += i)
                {
                    if ((x & bits_extractlowest(mask)) != 0)
                    {
                        result |= i;
                    }
                    else
                    {
                    }

                    mask = bits_resetlowest(mask);
                }
                return(result);
            }
        }
示例#4
0
        public void RunStructLclFldScenario()
        {
            var test   = TestStruct.Create();
            var result = Bmi2.ParallelBitExtract(test._fld1, test._fld2);

            ValidateResult(test._fld1, test._fld2, result);
        }
示例#5
0
        public void RunClassLclFldScenario()
        {
            var test   = new ScalarBinaryOpTest__ParallelBitExtractUInt64();
            var result = Bmi2.ParallelBitExtract(test._fld1, test._fld2);

            ValidateResult(test._fld1, test._fld2, result);
        }
示例#6
0
        public void RunLclFldScenario()
        {
            var test   = new ScalarBinaryOpTest__ParallelBitDepositUInt32();
            var result = Bmi2.ParallelBitDeposit(test._fld1, test._fld2);

            ValidateResult(test._fld1, test._fld2, result);
        }
示例#7
0
        private static uint ExtractCharsFromFourByteSequence(uint value)
        {
            if (BitConverter.IsLittleEndian)
            {
#if NETCOREAPP3_1
                if (Bmi2.IsSupported)
                {
                    // need to reverse endianness for bit manipulation to work correctly
                    value = BinaryPrimitives.ReverseEndianness(value);

                    // value = [ 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx ]
                    // want to return [ 110110wwwwxxxxxx 110111xxxxxxxxxx ]
                    // where wwww = uuuuu - 1

                    uint highSurrogateChar = Bmi2.ParallelBitExtract(value, 0b00000111_00111111_00110000_00000000u);
                    uint lowSurrogateChar  = Bmi2.ParallelBitExtract(value, 0b00000000_00000000_00001111_00111111u);

                    uint combined = (lowSurrogateChar << 16) + highSurrogateChar;
                    combined -= 0x40u;        // wwww = uuuuu - 1
                    combined += 0xDC00_D800u; // add surrogate markers
                    return(combined);
                }
                else
                {
#endif
                // input is UTF8 [ 10xxxxxx 10yyyyyy 10uuzzzz 11110uuu ] = scalar 000uuuuu zzzzyyyy yyxxxxxx
                // want to return UTF16 scalar 000uuuuuzzzzyyyyyyxxxxxx = [ 110111yy yyxxxxxx 110110ww wwzzzzyy ]
                // where wwww = uuuuu - 1
                uint retVal = (uint)(byte)value << 8;   // retVal = [ 00000000 00000000 11110uuu 00000000 ]
                retVal |= (value & 0x0000_3F00u) >> 6;  // retVal = [ 00000000 00000000 11110uuu uuzzzz00 ]
                retVal |= (value & 0x0030_0000u) >> 20; // retVal = [ 00000000 00000000 11110uuu uuzzzzyy ]
                retVal |= (value & 0x3F00_0000u) >> 8;  // retVal = [ 00000000 00xxxxxx 11110uuu uuzzzzyy ]
                retVal |= (value & 0x000F_0000u) << 6;  // retVal = [ 000000yy yyxxxxxx 11110uuu uuzzzzyy ]
                retVal -= 0x0000_0040u;                 // retVal = [ 000000yy yyxxxxxx 111100ww wwzzzzyy ]
                retVal -= 0x0000_2000u;                 // retVal = [ 000000yy yyxxxxxx 110100ww wwzzzzyy ]
                retVal += 0x0000_0800u;                 // retVal = [ 000000yy yyxxxxxx 110110ww wwzzzzyy ]
                retVal += 0xDC00_0000u;                 // retVal = [ 110111yy yyxxxxxx 110110ww wwzzzzyy ]
                return(retVal);

#if NETCOREAPP3_1
            }
#endif
            }
            else
            {
                // input is UTF8 [ 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx ] = scalar 000uuuuu zzzzyyyy yyxxxxxx
                // want to return UTF16 scalar 000uuuuuxxxxxxxxxxxxxxxx = [ 110110wwwwxxxxxx 110111xxxxxxxxx ]
                // where wwww = uuuuu - 1
                uint retVal = value & 0xFF00_0000u;    // retVal = [ 11110uuu 00000000 00000000 00000000 ]
                retVal |= (value & 0x003F_0000u) << 2; // retVal = [ 11110uuu uuzzzz00 00000000 00000000 ]
                retVal |= (value & 0x0000_3000u) << 4; // retVal = [ 11110uuu uuzzzzyy 00000000 00000000 ]
                retVal |= (value & 0x0000_0F00u) >> 2; // retVal = [ 11110uuu uuzzzzyy 000000yy yy000000 ]
                retVal |= (value & 0x0000_003Fu);      // retVal = [ 11110uuu uuzzzzyy 000000yy yyxxxxxx ]
                retVal -= 0x2000_0000u;                // retVal = [ 11010uuu uuzzzzyy 000000yy yyxxxxxx ]
                retVal -= 0x0040_0000u;                // retVal = [ 110100ww wwzzzzyy 000000yy yyxxxxxx ]
                retVal += 0x0000_DC00u;                // retVal = [ 110100ww wwzzzzyy 110111yy yyxxxxxx ]
                retVal += 0x0800_0000u;                // retVal = [ 110110ww wwzzzzyy 110111yy yyxxxxxx ]
                return(retVal);
            }
        }
示例#8
0
        static unsafe uint MultiplyNoFlags4(uint a, uint b)
        {
            uint r;

            r = Bmi2.MultiplyNoFlags(a, b, &r);
            return(r);
        }
示例#9
0
        public void RunClassFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));

            var result = Bmi2.ZeroHighBits(_fld1, _fld2);

            ValidateResult(_fld1, _fld2, result);
        }
示例#10
0
        public void RunClassFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));

            var result = Bmi2.ParallelBitExtract(_fld1, _fld2);

            ValidateResult(_fld1, _fld2, result);
        }
示例#11
0
        public void RunLclVarScenario_UnsafeRead()
        {
            var data1  = Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data1));
            var data2  = Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data2));
            var result = Bmi2.ParallelBitDeposit(data1, data2);

            ValidateResult(data1, data2, result);
        }
 public static uint ParallelBitDeposit(uint x, uint mask)
 {
     if (Bmi2.IsSupported)
     {
         return(Bmi2.ParallelBitDeposit(x, mask));
     }
     return(ParallelBitDepositLogic(x, mask));
 }
        public void RunStructLclFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));

            var test   = TestStruct.Create();
            var result = Bmi2.MultiplyNoFlags(test._fld1, test._fld2, &test._fld3);

            ValidateResult(test._fld1, test._fld2, test._fld3, result);
        }
示例#14
0
        public void RunBasicScenario_UnsafeRead()
        {
            var result = Bmi2.ParallelBitDeposit(
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data1)),
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data2))
                );

            ValidateResult(_data1, _data2, result);
        }
示例#15
0
        public void RunStructLclFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));

            var test   = TestStruct.Create();
            var result = Bmi2.ParallelBitExtract(test._fld1, test._fld2);

            ValidateResult(test._fld1, test._fld2, result);
        }
示例#16
0
        public void RunClsVarScenario()
        {
            var result = Bmi2.ParallelBitDeposit(
                _clsVar1,
                _clsVar2
                );

            ValidateResult(_clsVar1, _clsVar2, result);
        }
示例#17
0
        public void RunClassLclFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));

            var test   = new ScalarBinaryOpTest__ParallelBitExtractUInt32();
            var result = Bmi2.ParallelBitExtract(test._fld1, test._fld2);

            ValidateResult(test._fld1, test._fld2, result);
        }
示例#18
0
        public void RunClassLclFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));

            var test   = new ScalarBinaryOpTest__ZeroHighBitsUInt32();
            var result = Bmi2.ZeroHighBits(test._fld1, test._fld2);

            ValidateResult(test._fld1, test._fld2, result);
        }
示例#19
0
        /// <summary>
        /// Sets the bits of <paramref name="value"/> higher than specified <paramref name="index"/> to 0.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static uint ZeroHighBits(int index, uint value)
        {
#if NETCOREAPP3_1_OR_GREATER
            if (Bmi2.IsSupported)
            {
                return(Bmi2.ZeroHighBits(value, (uint)index));
            }
#endif
            return(value & ~(~0u << index));
        }
        public void RunClassFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));

            UInt32 buffer = 0;

            var result = Bmi2.MultiplyNoFlags(_fld1, _fld2, &buffer);

            ValidateResult(_fld1, _fld2, buffer, result);
        }
示例#21
0
        public void RunLclVarScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));

            var data1  = Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data1));
            var data2  = Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data2));
            var result = Bmi2.ParallelBitExtract(data1, data2);

            ValidateResult(data1, data2, result);
        }
        private static uint UInt16ToUpperHexWithBmi2(uint value)
        {
            Debug.Assert(Bmi2.IsSupported, "This code path shouldn't have gotten hit unless BMI2 was supported.");

            // Convert 0x0000WXYZ to 0x0W0X0Y0Z.
            value = Bmi2.ParallelBitDeposit(value, 0x0F0F0F0Fu);

            // From WriteHexByte, must document better
            return((((0x89898989u - value) & 0x70707070u) >> 4) + value + 0x30303030u);
        }
示例#23
0
        public void RunBasicScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));

            var result = Bmi2.ZeroHighBits(
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data1)),
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data2))
                );

            ValidateResult(_data1, _data2, result);
        }
        public void RunLclVarScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));

            var data1  = Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data1));
            var data2  = Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data2));
            var data3  = Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data3));
            var result = Bmi2.MultiplyNoFlags(data1, data2, &data3);

            ValidateResult(data1, data2, data3, result);
        }
        public void RunClassLclFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));

            UInt32 buffer = 0;

            var test   = new ScalarTernOpBinResTest__MultiplyNoFlagsUInt32();
            var result = Bmi2.MultiplyNoFlags(test._fld1, test._fld2, &buffer);

            ValidateResult(test._fld1, test._fld2, buffer, result);
        }
示例#26
0
        public void RunClsVarScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));

            var result = Bmi2.ParallelBitExtract(
                _clsVar1,
                _clsVar2
                );

            ValidateResult(_clsVar1, _clsVar2, result);
        }
示例#27
0
 public static ulong bits_zerohigh(ulong x, int startIndex)
 {
     if (Bmi2.IsBmi2Supported)
     {
         return(Bmi2.bzhi_u64(x, (uint)startIndex));
     }
     else
     {
         return(andnot(x, ulong.MaxValue << startIndex));
     }
 }
示例#28
0
        public void RunClsVarScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));

            var result = Bmi2.ZeroHighBits(
                _clsVar1,
                _clsVar2
                );

            ValidateResult(_clsVar1, _clsVar2, result);
        }
示例#29
0
        public void RunBasicScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));

            var result = Bmi2.ParallelBitExtract(
                Unsafe.ReadUnaligned <UInt64>(ref Unsafe.As <UInt64, byte>(ref _data1)),
                Unsafe.ReadUnaligned <UInt64>(ref Unsafe.As <UInt64, byte>(ref _data2))
                );

            ValidateResult(_data1, _data2, result);
        }
        public void RunBasicScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));

            UInt32 buffer = 0;

            var result = Bmi2.MultiplyNoFlags(
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data1)),
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data2)),
                &buffer
                );

            ValidateResult(_data1, _data2, buffer, result);
        }