Example #1
0
        /// <summary>
        /// Tests a bit in the feature flag.
        /// </summary>
        /// <param name="feature">The name of the CPU feature, e.g. "FPU".</param>
        /// <param name="register">The feature register obtained from a query of CPUID.</param>
        /// <param name="result">The register to query, 0 is EAX, to 3 for EDX.</param>
        /// <param name="bit">The bit to test for.</param>
        /// <param name="invert">Inverts the result if <see langword="true"/>, otherwise feature is set if the bit is one.</param>
        protected void TestFeature(string feature, CpuIdRegister register, int result, int bit, bool invert)
        {
            bool value = (register.Result[result] & (1 << bit)) != 0;

            if (invert)
            {
                value = !value;
            }
            Features[feature] = value;

#if DEBUG
            if (!m_MainFunction.Set(register.Function, register.SubFunction, result, 1 << bit))
            {
                throw new InvalidOperationException("Bit was already set");
            }
#endif
        }