public double[] AddSimd()
        {
            var array  = new double[_length];
            var simdOp = VectorOperation.Simdize <double>((a, b, c, d, e) => a + b + c + d + e);

            for (var j = 0; j < _times; ++j)
            {
                simdOp(A, B, C, D, E, array);
            }
            return(array);
        }
예제 #2
0
        public void SimdizeInt2(int length, Expression <Func <int, int, int> > expr)
        {
            var random = new System.Random(1234);
            var x      = Enumerable.Range(0, length).Select(_ => random.Next()).ToArray();
            var y      = Enumerable.Range(0, length).Select(_ => random.Next()).ToArray();

            var func     = expr.Compile();
            var expected = x.Zip(y, func).ToArray();

            // 1st time: compile expression
            // 2nd or later: load from cache
            for (var i = 0; i < 8; ++i)
            {
                var simdFunc = VectorOperation.Simdize(expr);
                var actual   = new int[x.Length];
                simdFunc(x, y, actual);

                Assert.Equal(expected.Length, actual.Length);
                for (var j = 0; j < expected.Length; ++j)
                {
                    Assert.Equal(expected[j], actual[j]);
                }
            }
        }