public void RunStructFldScenario(SimpleBinaryOpTest__CompareGreaterThanOrEqualDouble testClass)
            {
                var result = Avx.CompareGreaterThanOrEqual(_fld1, _fld2);

                Unsafe.Write(testClass._dataTable.outArrayPtr, result);
                testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr);
            }
        public void RunClassFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));

            var result = Avx.CompareGreaterThanOrEqual(_fld1, _fld2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr);
        }
        public void RunStructLclFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));

            var test   = TestStruct.Create();
            var result = Avx.CompareGreaterThanOrEqual(test._fld1, test._fld2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
        }
        public void RunClassLclFldScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));

            var test   = new SimpleBinaryOpTest__CompareGreaterThanOrEqualDouble();
            var result = Avx.CompareGreaterThanOrEqual(test._fld1, test._fld2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
        }
        public void RunLclVarScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));

            var op1    = Avx.LoadAlignedVector256((Double *)(_dataTable.inArray1Ptr));
            var op2    = Avx.LoadAlignedVector256((Double *)(_dataTable.inArray2Ptr));
            var result = Avx.CompareGreaterThanOrEqual(op1, op2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(op1, op2, _dataTable.outArrayPtr);
        }
        public void RunLclVarScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));

            var op1    = Unsafe.Read <Vector256 <Double> >(_dataTable.inArray1Ptr);
            var op2    = Unsafe.Read <Vector256 <Double> >(_dataTable.inArray2Ptr);
            var result = Avx.CompareGreaterThanOrEqual(op1, op2);

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(op1, op2, _dataTable.outArrayPtr);
        }
        public void RunBasicScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));

            var result = Avx.CompareGreaterThanOrEqual(
                Avx.LoadVector256((Double *)(_dataTable.inArray1Ptr)),
                Avx.LoadVector256((Double *)(_dataTable.inArray2Ptr))
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
Beispiel #8
0
        public void RunBasicScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));

            var result = Avx.CompareGreaterThanOrEqual(
                Unsafe.Read <Vector256 <Single> >(_dataTable.inArray1Ptr),
                Unsafe.Read <Vector256 <Single> >(_dataTable.inArray2Ptr)
                );

            Unsafe.Write(_dataTable.outArrayPtr, result);
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
            public void RunStructFldScenario_Load(SimpleBinaryOpTest__CompareGreaterThanOrEqualDouble testClass)
            {
                fixed(Vector256 <Double> *pFld1 = &_fld1)
                fixed(Vector256 <Double> *pFld2 = &_fld2)
                {
                    var result = Avx.CompareGreaterThanOrEqual(
                        Avx.LoadVector256((Double *)(pFld1)),
                        Avx.LoadVector256((Double *)(pFld2))
                        );

                    Unsafe.Write(testClass._dataTable.outArrayPtr, result);
                    testClass.ValidateResult(_fld1, _fld2, testClass._dataTable.outArrayPtr);
                }
            }
        public void RunClassFldScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario_Load));

            fixed(Vector256 <Double> *pFld1 = &_fld1)
            fixed(Vector256 <Double> *pFld2 = &_fld2)
            {
                var result = Avx.CompareGreaterThanOrEqual(
                    Avx.LoadVector256((Double *)(pFld1)),
                    Avx.LoadVector256((Double *)(pFld2))
                    );

                Unsafe.Write(_dataTable.outArrayPtr, result);
                ValidateResult(_fld1, _fld2, _dataTable.outArrayPtr);
            }
        }
Beispiel #11
0
        public void RunClsVarScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario_Load));

            fixed(Vector256 <Single> *pClsVar1 = &_clsVar1)
            fixed(Vector256 <Single> *pClsVar2 = &_clsVar2)
            {
                var result = Avx.CompareGreaterThanOrEqual(
                    Avx.LoadVector256((Single *)(pClsVar1)),
                    Avx.LoadVector256((Single *)(pClsVar2))
                    );

                Unsafe.Write(_dataTable.outArrayPtr, result);
                ValidateResult(_clsVar1, _clsVar2, _dataTable.outArrayPtr);
            }
        }
Beispiel #12
0
        public void RunClassLclFldScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario_Load));

            var test = new SimpleBinaryOpTest__CompareGreaterThanOrEqualSingle();

            fixed(Vector256 <Single> *pFld1 = &test._fld1)
            fixed(Vector256 <Single> *pFld2 = &test._fld2)
            {
                var result = Avx.CompareGreaterThanOrEqual(
                    Avx.LoadVector256((Single *)(pFld1)),
                    Avx.LoadVector256((Single *)(pFld2))
                    );

                Unsafe.Write(_dataTable.outArrayPtr, result);
                ValidateResult(test._fld1, test._fld2, _dataTable.outArrayPtr);
            }
        }
Beispiel #13
0
    static bool TestAvxCompareGreaterThanOrEqualDouble()
    {
        if (Avx.IsSupported)
        {
            const int expectedResult = 0b1000;

            Vector256 <double> value1 = Vector256.Create(double.NaN, 1.0, 0.0, 2.0);
            Vector256 <double> value2 = Vector256.Create(0.0, 2.0, double.NaN, 1.0);
            Vector256 <double> result = Avx.CompareGreaterThanOrEqual(value1, value2);

            int actualResult = Avx.MoveMask(result);

            if (actualResult != expectedResult)
            {
                Console.WriteLine($"{nameof(Avx)}.{nameof(Avx.CompareGreaterThanOrEqual)}({value1}, {value2}) returned {Convert.ToString(actualResult, 2)}; expected {Convert.ToString(expectedResult, 2)}");
                return(false);
            }
        }
        return(true);
    }
Beispiel #14
0
 public static m32 GreaterThanOrEqual(f32 lhs, f32 rhs) => Avx.CompareGreaterThanOrEqual(lhs, rhs).AsInt32();
Beispiel #15
0
        public static unsafe float GetScribnerBoardFeetPerAcre(Trees trees)
        {
            // for now, assume all trees are of the same species
            if (trees.Species != FiaCode.PseudotsugaMenziesii)
            {
                throw new NotSupportedException();
            }
            if (trees.Units != Units.English)
            {
                throw new NotSupportedException();
            }

            // Douglas-fir
            #if DEBUG
            Vector128 <float> v6p8 = AvxExtensions.BroadcastScalarToVector128(6.8F);
            Vector128 <float> v10k = AvxExtensions.BroadcastScalarToVector128(10.0F * 1000.0F);
            #endif

            // constants
            Vector128 <float> forestersEnglish = AvxExtensions.BroadcastScalarToVector128(Constant.ForestersEnglish);
            Vector128 <float> one = AvxExtensions.BroadcastScalarToVector128(1.0F);
            Vector128 <float> six = AvxExtensions.BroadcastScalarToVector128(6.0F);

            Vector128 <float> vm3p21809   = AvxExtensions.BroadcastScalarToVector128(-3.21809F); // b4
            Vector128 <float> v0p04948    = AvxExtensions.BroadcastScalarToVector128(0.04948F);
            Vector128 <float> vm0p15664   = AvxExtensions.BroadcastScalarToVector128(-0.15664F);
            Vector128 <float> v2p02132    = AvxExtensions.BroadcastScalarToVector128(2.02132F);
            Vector128 <float> v1p63408    = AvxExtensions.BroadcastScalarToVector128(1.63408F);
            Vector128 <float> vm0p16184   = AvxExtensions.BroadcastScalarToVector128(-0.16184F);
            Vector128 <float> v1p033      = AvxExtensions.BroadcastScalarToVector128(1.033F);
            Vector128 <float> v1p382937   = AvxExtensions.BroadcastScalarToVector128(1.382937F);
            Vector128 <float> vm0p4015292 = AvxExtensions.BroadcastScalarToVector128(-0.4015292F);
            Vector128 <float> v0p087266   = AvxExtensions.BroadcastScalarToVector128(0.087266F);
            Vector128 <float> vm0p174533  = AvxExtensions.BroadcastScalarToVector128(-0.174533F);

            Vector128 <float> vm0p6896598794 = AvxExtensions.BroadcastScalarToVector128(-0.6896598794F); // rc6-rs632
            Vector128 <float> v0p993         = AvxExtensions.BroadcastScalarToVector128(0.993F);
            Vector128 <float> v0p174439      = AvxExtensions.BroadcastScalarToVector128(0.174439F);
            Vector128 <float> v0p117594      = AvxExtensions.BroadcastScalarToVector128(0.117594F);
            Vector128 <float> vm8p210585     = AvxExtensions.BroadcastScalarToVector128(-8.210585F);
            Vector128 <float> v0p236693      = AvxExtensions.BroadcastScalarToVector128(0.236693F);
            Vector128 <float> v0p00001345    = AvxExtensions.BroadcastScalarToVector128(0.00001345F);
            Vector128 <float> v0p00001937    = AvxExtensions.BroadcastScalarToVector128(0.00001937F);
            Vector128 <float> v1p001491      = AvxExtensions.BroadcastScalarToVector128(1.001491F);
            Vector128 <float> vm6p924097     = AvxExtensions.BroadcastScalarToVector128(-6.924097F);
            Vector128 <float> v0p912733      = AvxExtensions.BroadcastScalarToVector128(0.912733F);
            Vector128 <float> v0p00001351    = AvxExtensions.BroadcastScalarToVector128(0.00001351F);

            fixed(float *dbh = &trees.Dbh[0], expansionFactors = &trees.LiveExpansionFactor[0], height = &trees.Height[0])
            {
                Vector128 <float> standBoardFeetPerAcre = Vector128 <float> .Zero;

                for (int treeIndex = 0; treeIndex < trees.Count; treeIndex += Constant.Simd128x4.Width)
                {
                    Vector128 <float> dbhInInches  = Avx.LoadVector128(dbh + treeIndex);
                    Vector128 <float> heightInFeet = Avx.LoadVector128(height + treeIndex);

                    Vector128 <float> logDbhInInches  = MathV.Log10(dbhInInches);
                    Vector128 <float> logHeightInFeet = MathV.Log10(heightInFeet);
                    // FiaCode.PseudotsugaMenziesii => -3.21809F + 0.04948F * logHeightInFeet * logDbhInInches - 0.15664F * logDbhInInches * logDbhInInches +
                    //                                  2.02132F * logDbhInInches + 1.63408F * logHeightInFeet - 0.16184F * logHeightInFeet * logHeightInFeet,
                    Vector128 <float> cvtsl = Avx.Add(vm3p21809, Avx.Multiply(v0p04948, Avx.Multiply(logHeightInFeet, logDbhInInches)));
                    cvtsl = Avx.Add(cvtsl, Avx.Multiply(vm0p15664, Avx.Multiply(logDbhInInches, logDbhInInches)));
                    cvtsl = Avx.Add(cvtsl, Avx.Multiply(v2p02132, logDbhInInches));
                    cvtsl = Avx.Add(cvtsl, Avx.Multiply(v1p63408, logHeightInFeet));
                    cvtsl = Avx.Add(cvtsl, Avx.Multiply(vm0p16184, Avx.Multiply(logHeightInFeet, logHeightInFeet)));
                    Vector128 <float> cubicFeet = MathV.Exp10(cvtsl);

                    Vector128 <float> dbhSquared            = Avx.Multiply(dbhInInches, dbhInInches); // could be consolidated by merging other scaling constants with Forester's constant for basal area
                    Vector128 <float> basalAreaInSquareFeet = Avx.Multiply(forestersEnglish, dbhSquared);
                    // b4 = cubicFeet / (1.033F * (1.0F + 1.382937F * MathV.Exp(-4.015292F * dbhInInches / 10.0F)) * (basalAreaInSquareFeet + 0.087266F) - 0.174533F);
                    Vector128 <float> b4 = Avx.Divide(cubicFeet, Avx.Add(Avx.Multiply(v1p033,
                                                                                      Avx.Multiply(Avx.Add(one, Avx.Multiply(v1p382937,
                                                                                                                             MathV.Exp(Avx.Multiply(vm0p4015292,
                                                                                                                                                    dbhInInches)))),
                                                                                                   Avx.Add(basalAreaInSquareFeet, v0p087266))),
                                                                         vm0p174533));
                    Vector128 <float> cv4 = Avx.Multiply(b4, Avx.Subtract(basalAreaInSquareFeet, v0p087266));

                    // conversion to Scribner volumes for 32 foot trees
                    // Waddell 2014:32
                    // rc6 = 0.993F * (1.0F - MathF.Pow(0.62F, dbhInInches - 6.0F));
                    Vector128 <float> rc6   = Avx.Multiply(v0p993, Avx.Subtract(one, MathV.Exp(Avx.Multiply(vm0p6896598794, Avx.Subtract(dbhInInches, six))))); // log2(0.62) = -0.6896598794
                    Vector128 <float> cv6   = Avx.Multiply(rc6, cv4);
                    Vector128 <float> logB4 = MathV.Log10(b4);
                    // float rs616 = MathF.Pow(10.0F, 0.174439F + 0.117594F * logDbhInInches * logB4 - 8.210585F / (dbhInInches * dbhInInches) + 0.236693F * logB4 - 0.00001345F * b4 * b4 - 0.00001937F * dbhInInches * dbhInInches);
                    Vector128 <float> rs616l = Avx.Add(v0p174439, Avx.Multiply(v0p117594, Avx.Multiply(logDbhInInches, logB4)));
                    rs616l = Avx.Add(rs616l, Avx.Divide(vm8p210585, dbhSquared));
                    rs616l = Avx.Add(rs616l, Avx.Multiply(v0p236693, logB4));
                    rs616l = Avx.Subtract(rs616l, Avx.Multiply(v0p00001345, Avx.Multiply(b4, b4)));
                    rs616l = Avx.Subtract(rs616l, Avx.Multiply(v0p00001937, dbhSquared));
                    Vector128 <float> rs616 = MathV.Exp10(rs616l);
                    Vector128 <float> sv616 = Avx.Multiply(rs616, cv6); // Scribner board foot volume to a 6 inch top for 16 foot logs
                    // float rs632 = 1.001491F - 6.924097F / tarif + 0.00001351F * dbhInInches * dbhInInches;
                    Vector128 <float> rs632 = Avx.Add(v1p001491, Avx.Divide(vm6p924097, Avx.Multiply(v0p912733, b4)));
                    rs632 = Avx.Add(rs632, Avx.Multiply(v0p00001351, dbhSquared));
                    Vector128 <float> zeroVolumeMask = Avx.CompareLessThanOrEqual(dbhInInches, six);
                    Vector128 <float> sv632          = Avx.Multiply(rs632, sv616); // Scribner board foot volume to a 6 inch top for 32 foot logs
                    sv632 = Avx.BlendVariable(sv632, Vector128 <float> .Zero, zeroVolumeMask);

                    #if DEBUG
                    DebugV.Assert(Avx.CompareGreaterThanOrEqual(Avx.BlendVariable(rc6, Vector128 <float> .Zero, zeroVolumeMask), Vector128 <float> .Zero));
                    DebugV.Assert(Avx.CompareLessThanOrEqual(rc6, one));
                    DebugV.Assert(Avx.CompareGreaterThanOrEqual(Avx.BlendVariable(rs616, one, zeroVolumeMask), one));
                    DebugV.Assert(Avx.CompareLessThanOrEqual(Avx.BlendVariable(rs616, Vector128 <float> .Zero, zeroVolumeMask), v6p8));
                    DebugV.Assert(Avx.CompareGreaterThanOrEqual(Avx.BlendVariable(rs632, Vector128 <float> .Zero, zeroVolumeMask), Vector128 <float> .Zero));
                    DebugV.Assert(Avx.CompareLessThanOrEqual(Avx.BlendVariable(rs632, Vector128 <float> .Zero, zeroVolumeMask), one));
                    DebugV.Assert(Avx.CompareGreaterThanOrEqual(Avx.BlendVariable(sv632, Vector128 <float> .Zero, zeroVolumeMask), Vector128 <float> .Zero));
                    DebugV.Assert(Avx.CompareLessThanOrEqual(Avx.BlendVariable(sv632, Vector128 <float> .Zero, zeroVolumeMask), v10k));
                    #endif

                    Vector128 <float> expansionFactor = Avx.LoadVector128(expansionFactors + treeIndex);
                    standBoardFeetPerAcre = Avx.Add(standBoardFeetPerAcre, Avx.Multiply(expansionFactor, sv632));
                }

                standBoardFeetPerAcre = Avx.HorizontalAdd(standBoardFeetPerAcre, standBoardFeetPerAcre);
                standBoardFeetPerAcre = Avx.HorizontalAdd(standBoardFeetPerAcre, standBoardFeetPerAcre);
                return(standBoardFeetPerAcre.ToScalar());
            }
        }