示例#1
0
        public void RunClassFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));

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

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

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

            ValidateResult(test._fld1, test._fld2, result);
        }
示例#3
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);
        }
示例#4
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.ZeroHighBits(data1, data2);

            ValidateResult(data1, data2, result);
        }
示例#5
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));
        }
示例#6
0
        public void RunClsVarScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));

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

            ValidateResult(_clsVar1, _clsVar2, result);
        }
示例#7
0
        public int Divide(int value)
        {
            uint strategy = (uint)Strategy;

            if (strategy != (uint)SignedDivisorStrategy.Branch)
            {
                int  eax;
                uint r9d;
                if ((strategy & 0b100u) > 0)
                {
                    long rax        = value;
                    long multiplier = Multiplier;
                    int  shift      = Shift;
                    r9d  = strategy & 0b1;
                    rax *= multiplier;
                    eax  = (int)((ulong)rax >> 32);
                    if ((strategy & 0b010u) > 0)
                    {
                        value = (value ^ -(int)r9d) + (int)r9d;
                        eax  += value;
                    }
                    r9d   = (uint)eax;
                    r9d >>= 31;
                    eax >>= shift;
                    return(eax + (int)r9d);
                }
                else
                {
                    eax = value >> 31;
                    int shift = Shift;
                    strategy &= 0b1u;
#if NETCOREAPP3_1_OR_GREATER
                    if (Bmi2.IsSupported)
                    {
                        eax = (int)Bmi2.ZeroHighBits((uint)eax, (uint)shift);
                    }
                    else
                    {
                        int mask = (int)~(~0u << shift);
                        eax &= mask;
                    }
#else
                    int mask = (int)~(~0u << shift);
                    eax &= mask;
#endif
                    eax  += value;
                    eax >>= shift;
                    return((eax ^ -(int)strategy) + (int)strategy);  //negate eax when strategy is 1
                }
            }
示例#8
0
        public static uint ExtractLowBytes(uint value, int numBytes)
        {
            Debug.Assert(numBytes >= 0);
            Debug.Assert(numBytes <= 4);

            #if NETCOREAPP3_0
            if (Bmi2.IsSupported)
            {
                return(Bmi2.ZeroHighBits(value, (uint)(numBytes * 8)));
            }
            else
            {
                return(value & ~(0xffffffff << (8 * numBytes)));
            }
            #else
            return(value & ~(0xffffffff << (8 * numBytes)));
            #endif
        }
示例#9
0
        public override ulong Run(CancellationToken cancellationToken)
        {
            if (!Bmi2.IsSupported)
            {
                return(0uL);
            }

            var iterations = 0uL;
            var zhb        = randomInt;

            while (!cancellationToken.IsCancellationRequested)
            {
                for (var i = 0; i < LENGTH; i++)
                {
                    zhb = Bmi2.ZeroHighBits(zhb, 17);
                }

                iterations++;
            }

            return(iterations + zhb - zhb);
        }
示例#10
0
            public void RunStructFldScenario(ScalarBinaryOpTest__ZeroHighBitsUInt32 testClass)
            {
                var result = Bmi2.ZeroHighBits(_fld1, _fld2);

                testClass.ValidateResult(_fld1, _fld2, result);
            }