예제 #1
0
        public static void RemoveFullLines(ref Vec256 board, ref int score)
        {
            Vec256 test = board;

            test &= (test << 5);
            test &= (test << 2);
            test &= (test << 1);
            test &= (test << 1);

            if ((test & checkLineMask) == 0)
            {
                return;
            }

            int    scoreBoost    = 1;
            Vec256 lineMask      = fullLine >> width;
            Vec256 underLineMask = fullLine;

            while (lineMask != 0)
            {
                while ((board & lineMask) == lineMask)
                {
                    score       += scoreBoost;
                    scoreBoost <<= 1;
                    board        = (board & underLineMask) | ((board & ~underLineMask & ~lineMask) << width) | emptyLine;
                }

                underLineMask |= lineMask;
                lineMask     >>= width;
            }
        }
예제 #2
0
파일: tv_max.cs 프로젝트: 0xCM/arrows
        public void max256_i32()
        {
            var blocklen = Span256 <int> .BlockLength;
            var lhs      = Random.ReadOnlySpan256 <int>(SampleSize);
            var rhs      = Random.ReadOnlySpan256 <int>(SampleSize);
            var expect   = Span256.AllocBlocks <int>(SampleSize);
            var actual   = Span256.AllocBlocks <int>(SampleSize);

            for (var block = 0; block < SampleSize; block++)
            {
                var offset = block * blocklen;

                Span <int> tmp = stackalloc int[blocklen];
                for (var i = 0; i < blocklen; i++)
                {
                    tmp[i] = gmath.max(lhs[offset + i], rhs[offset + i]);
                }
                var vExpect = Vec256.LoadVector(ref tmp[0]);

                var vX      = lhs.LoadVec256(block);
                var vY      = rhs.LoadVec256(block);
                var vActual = ginx.max <int>(vX, vY);

                Claim.eq(vExpect, vActual);

                vstore(vExpect, ref expect.Block(block));
                vstore(vActual, ref actual.Block(block));
            }
            Claim.eq(expect, actual);
        }
예제 #3
0
        public void swap_256_i32()
        {
            var subject = Vec256.FromParts(2, 4, 6, 8, 10, 12, 14, 16);
            var swapped = dinx.swap(subject, 2, 3);
            var expect  = Vec256.FromParts(2, 4, 8, 6, 10, 12, 14, 16);

            Claim.eq(expect, swapped);
        }
예제 #4
0
        static string GetLine(Vec256 field)
        {
            Vec256 line = field.Shuffle(lineToStringShuffler) & lineToStringValue;

            line = line.Min(Vec256.ONE);
            line = tile.Shuffle(line);

            return(Encoding.ASCII.GetString(line.ToArray <byte>()));
        }
예제 #5
0
        void DescribeShuffle256u32()
        {
            var x = Vec256.FromParts(0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u);

            for (var i = 0; i < 255; i++)
            {
                Trace(DescribeShuffle(x, (byte)i, dinx.shuffle(x, (byte)i)));
            }
        }
예제 #6
0
파일: tv_sllv.cs 프로젝트: 0xCM/arrows
        public void Nonzero()
        {
            Claim.yea(gbits.nonz(Vec256.FromParts(1ul, 2ul, 3ul, 4ul)));
            Claim.yea(gbits.nonz(Vec256.FromParts(1ul, 0ul, 0ul, 0ul)));
            Claim.nea(gbits.nonz(Vec256.FromParts(0ul, 0ul, 0ul, 0ul)));

            Claim.yea(gbits.nonz(Vec128.FromParts(1u, 2u, 3u, 4u)));
            Claim.yea(gbits.nonz(Vec128.FromParts(1u, 0u, 0u, 0u)));
            Claim.nea(gbits.nonz(Vec128.FromParts(0u, 0u, 0u, 0u)));
        }
예제 #7
0
        public void hi_256_u32()
        {
            var x = Vec256.FromParts(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u);
            var y = Vec256.FromParts(10u, 12u, 13u, 14u, 15u, 16u, 17u, 18u);

            var actual = dinx.unpackhi(x, y);
            var expect = Vec256.FromParts(3u, 13u, 4u, 14u, 7u, 17u, 8u, 18u);

            Claim.eq(expect, actual);
        }
예제 #8
0
        public void hi_256_u64()
        {
            var x      = Vec256.FromParts(1ul, 2ul, 3ul, 4ul);
            var y      = Vec256.FromParts(5ul, 6ul, 7ul, 8ul);
            var expect = Vec256.FromParts(2ul, 6ul, 4ul, 8ul);

            var actual = dinx.unpackhi(x, y);

            Claim.eq(expect, actual);
        }
예제 #9
0
        static void Solve(Vec256 board, int step, int score)
        {
            processedMoves++;
            if (processedMoves % 1_000_000_000 == 0)
            {
                double millionMovesPerSecond = processedMoves / timer.Elapsed.TotalSeconds / 1000000;
                Console.WriteLine($"Processed {processedMoves:N0} moves at {timer.Elapsed} ({millionMovesPerSecond:0.00} M moves/second)");
            }
            if (step > maxStepFound)
            {
                maxStepFound = step;
                Console.WriteLine($"new max depth={maxStepFound} after processing {processedMoves:N0} moves at {timer.Elapsed}");
            }
            if (step >= pieceOrder.Length)
            {
                return;
            }

            int pieceIndex = pieceOrder[step];

            Vec256[] currentPiece = TetrisOptions.figure[pieceIndex];

            movesLength += 2;
            for (int rotationIndex = 0; rotationIndex < currentPiece.Length; rotationIndex++)
            {
                Vec256 piece = currentPiece[rotationIndex];
                moves[movesLength - 2] = rotationIndex;
                if ((piece & board) != 0)
                {
                    break;
                }
                moves[movesLength - 1] = 0;
                Solve(board, piece, step, score);

                for (int i = 1; i <= 5; i++)
                {
                    moves[movesLength - 1] = i;
                    if (((piece << i) & board) != 0)
                    {
                        break;
                    }
                    Solve(board, piece << i, step, score);
                }
                for (int i = 1; i <= 5; i++)
                {
                    moves[movesLength - 1] = -i;
                    if (((piece >> i) & board) != 0)
                    {
                        break;
                    }
                    Solve(board, piece >> i, step, score);
                }
            }
            movesLength -= 2;
        }
예제 #10
0
        void DescribePerm2x128u8()
        {
            var x = Vec256.FromBytes((byte)0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 29, 30, 31);
            var y = Vec256.FromBytes((byte)32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);

            for (var i = 0; i <= 255; i++)
            {
                var spec = (byte)i;
                var z    = ginx.permute2x128(x, y, spec);
                Trace(Describe2x128Perm(x, y, spec, z));
            }
        }
예제 #11
0
        void DescribePerm2x128u16()
        {
            var x = Vec256.FromParts((ushort)0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
            var y = Vec256.FromParts((ushort)16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 29, 30, 31);

            for (var i = 0; i <= 255; i++)
            {
                var spec = (byte)i;
                var z    = ginx.permute2x128(x, y, spec);
                Trace(Describe2x128Perm(x, y, spec, z));
            }
        }
예제 #12
0
        void perm2x128_u32_describe()
        {
            var x = Vec256.FromParts(0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u);
            var y = Vec256.FromParts(8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u);

            for (var i = 0; i <= 255; i++)
            {
                var spec = (byte)i;
                var z    = ginx.permute2x128(x, y, spec);
                Trace(Describe2x128Perm(x, y, spec, z));
            }
        }
예제 #13
0
        void perm2x128_u64_describe()
        {
            var x = Vec256.FromParts(1ul, 2ul, 3ul, 4ul);
            var y = Vec256.FromParts(5ul, 6ul, 7ul, 8ul);

            for (var i = 0; i <= 255; i++)
            {
                var spec = (byte)i;
                var z    = ginx.permute2x128(x, y, spec);
                Trace(Describe2x128Perm(x, y, spec, z));
            }
        }
예제 #14
0
        public void V256_ShiftRight()
        {
            Vec256 y = new Vec256(
                0xF1, 0x18, 0x80, 0x01, 0x18, 0x80, 0x01, 0x18,
                0x80, 0x01, 0x18, 0x80, 0x01, 0x18, 0x80, 0x01,
                0x18, 0x80, 0x01, 0x18, 0x80, 0x01, 0x18, 0x80,
                0x01, 0x18, 0x80, 0x01, 0x18, 0x80, 0xFF, 0x0F);

            Assert.Equal(
                "01 18 80 01 18 80 01 18 80 01 18 80 01 18 80 01 " +
                "18 80 01 18 80 01 18 80 01 18 80 01 F8 FF 00 00",
                (y >> 12).ToString());
        }
예제 #15
0
 void Flip256 <T>()
     where T : unmanaged
 {
     TypeCaseStart <T>();
     for (var i = 0; i < Pow2.T06; i++)
     {
         var src     = Random.CpuVec256 <T>();
         var srcData = src.ToSpan();
         var expect  = Vec256.Load(ref mathspan.flip(srcData)[0]);
         var actual  = gbits.flip(in src);
         Claim.yea(expect.Equals(actual));
     }
     TypeCaseEnd <T>();
 }
예제 #16
0
        void nonzero256_check <T>()
            where T : unmanaged
        {
            TypeCaseStart <T>();
            var src = Random.Span256 <T>(blocks: SampleSize);

            for (var i = 0; i < src.BlockCount; i++)
            {
                var v = Vec256.Load(ref src.Block(i));
                Claim.yea(gbits.nonz(v));
            }

            Claim.nea(gbits.nonz(Vec256.Zero <T>()));
            TypeCaseEnd <T>();
        }
예제 #17
0
파일: tbv_perm.cs 프로젝트: 0xCM/arrows
        public void Experiment()
        {
            //Create an explicit bit pattern
            var pattern = Random.Bits().Select(x => (byte)x).TakeArray(32);

            //Push pattern into a 256-bit vector
            var vPattern = Vec256.Load(pattern);

            //Define permutation
            var perm = Perm.Define <N32>((1, 10), (2, 11), (3, 8));

            var vPerm = Vec256.Load(perm.Terms);

            //var result = dinx.permute(vPattern, vPerm)
        }
예제 #18
0
파일: vstore.cs 프로젝트: 0xCM/arrows
 public static void vstore <T>(Vec256 <T> src, ref T dst)
     where T : struct
 {
     if (typeof(T) == typeof(sbyte))
     {
         vstore(int8(src), ref int8(ref dst));
     }
     else if (typeof(T) == typeof(byte))
     {
         vstore(uint8(src), ref uint8(ref dst));
     }
     else if (typeof(T) == typeof(short))
     {
         vstore(int16(src), ref int16(ref dst));
     }
     else if (typeof(T) == typeof(ushort))
     {
         vstore(uint16(src), ref uint16(ref dst));
     }
     else if (typeof(T) == typeof(int))
     {
         vstore(int32(src), ref int32(ref dst));
     }
     else if (typeof(T) == typeof(uint))
     {
         vstore(uint32(src), ref uint32(ref dst));
     }
     else if (typeof(T) == typeof(long))
     {
         vstore(int64(src), ref int64(ref dst));
     }
     else if (typeof(T) == typeof(ulong))
     {
         vstore(uint64(src), ref uint64(ref dst));
     }
     else if (typeof(T) == typeof(float))
     {
         vstore(float32(src), ref float32(ref dst));
     }
     else if (typeof(T) == typeof(double))
     {
         vstore(float64(src), ref float64(ref dst));
     }
     else
     {
         throw unsupported <T>();
     }
 }
예제 #19
0
        static string DescribeShuffle <T>(Vec256 <T> src, byte spec, Vec256 <T> dst)
            where T : unmanaged
        {
            var xFmt    = src.FormatHexBlocks();
            var specFmt = spec.ToBitString();
            var dstFmt  = dst.FormatHexBlocks();

            var fmt      = sbuild();
            var dataType = typeof(T).DisplayName();

            fmt.AppendLine(new string(AsciSym.Minus, 80));
            fmt.AppendLine($"shuffle256:Vec256<{dataType}> -> spec:byte -> {specFmt}");
            fmt.AppendLine(xFmt);
            fmt.AppendLine(dstFmt);
            return(fmt.ToString());
        }
예제 #20
0
 static void Solve(Vec256 board, Vec256 piece, int step, int score)
 {
     while ((board & (piece << TetrisOptions.width)) == 0)
     {
         piece <<= TetrisOptions.width;
     }
     board |= piece;
     TetrisOptions.RemoveFullLines(ref board, ref score);
     if (score > maxScoreFound)
     {
         maxScoreFound = score;
         Console.WriteLine($"new max score={maxScoreFound} at depth {maxStepFound} after processing {processedMoves:N0} moves at {timer.Elapsed}");
         Console.WriteLine($"  {GetMovesAsString()}");
     }
     Solve(board, step + 1, score);
 }
예제 #21
0
        public void reverse_256_f32()
        {
            var src = Random.CpuVec256Stream <float>().Take(Pow2.T14);

            foreach (var v in src)
            {
                var expect = Vec256.FromParts(v[7], v[6], v[5], v[4], v[3], v[2], v[1], v[0]);
                var actual = dinx.reverse(v);

                if (actual != expect)
                {
                    Trace(actual.FormatHex());
                    Trace(expect.FormatHex());
                }
                Claim.eq(expect, actual);
            }
        }
예제 #22
0
        static string Describe2x128Perm <T>(Vec256 <T> x, Vec256 <T> y, byte spec, Vec256 <T> dst)
            where T : unmanaged
        {
            var xFmt     = x.FormatHexBlocks();
            var yFmt     = y.FormatHexBlocks();
            var dstFmt   = dst.FormatHexBlocks();
            var specFmt  = spec.ToBitString();
            var fmt      = sbuild();
            var dataType = typeof(T).DisplayName();

            fmt.AppendLine(new string(AsciSym.Minus, 80));
            fmt.AppendLine($"permute2x128:Vec256<{dataType}> -> Vec256<{dataType}> -> {specFmt}");
            fmt.AppendLine(xFmt);
            fmt.AppendLine($"{yFmt}");
            fmt.AppendLine(dstFmt);
            return(fmt.ToString());
        }
예제 #23
0
파일: tv_sll.cs 프로젝트: 0xCM/arrows
        static Vec256 <byte> ShuffleIdentityMask()
        {
            Span256 <byte> mask = Span256.Alloc <byte>(1);

            //For the first 128-bit lane
            var half = mask.Length / 2;

            for (byte i = 0; i < half; i++)
            {
                mask[i] = i;
            }

            //For the second 128-bit lane
            for (byte i = 0; i < half; i++)
            {
                mask[i + half] = i;
            }

            return(Vec256.Load(mask));
        }
예제 #24
0
파일: tv_sll.cs 프로젝트: 0xCM/arrows
        static Vec256 <T> BlendAltMask <T>()
            where T : unmanaged
        {
            Span256 <T> mask = Span256.Alloc <T>(1);
            var         no   = PrimalInfo.Get <T>().MaxVal;
            var         yes  = PrimalInfo.Get <T>().Zero;

            for (byte i = 0; i < mask.Length; i++)
            {
                if (i % 2 == 0)
                {
                    mask[i] = yes;
                }
                else
                {
                    mask[i] = no;
                }
            }
            return(Vec256.Load(mask));
        }
예제 #25
0
        static void DisplayField()
        {
            Console.BackgroundColor = ConsoleColor.Blue;
            Console.ForegroundColor = ConsoleColor.White;

            DisplaySystemInfo();

            Console.SetCursorPosition(0, 2);

            Console.ForegroundColor = ConsoleColor.Black;

            Vec256 field = board | FallingPiece;

            while (field != 0)
            {
                Console.WriteLine(GetLine(field));
                field >>= width;
            }

            Console.WriteLine($"\n\n Score: {score} \n");
        }
예제 #26
0
파일: tv_insert.cs 프로젝트: 0xCM/arrows
        void insert128_check <T>()
            where T : unmanaged
        {
            TypeCaseStart <T>();
            for (var i = 0; i < SampleSize; i++)
            {
                var v128Src = Random.CpuVec128 <T>();
                var srcSpan = v128Src.ToSpan();

                var dst = Vec256.Zero <T>();

                var vLo     = ginx.insert(v128Src, dst, 0);
                var vLoSpan = vLo.ToSpan().Slice(0, vLo.Length() / 2);

                var vHi     = ginx.insert(v128Src, dst, 1);
                var vHiSpan = vHi.ToSpan().Slice(vLo.Length() / 2);

                Claim.eq(srcSpan, vLoSpan);
                Claim.eq(srcSpan, vHiSpan);
            }
            TypeCaseEnd <T>();
        }
예제 #27
0
파일: tv_sll.cs 프로젝트: 0xCM/arrows
        OpTime slli256u16Bench(int blocks, int cycles)
        {
            var blocklen   = Vec256 <ushort> .Length;
            var opcount    = blocks * cycles * blocklen;
            var shiftRange = closed <byte>(2, 14);

            var sw      = stopwatch(false);
            var src     = Random.Stream <ushort>();
            var offsets = Random.Stream(shiftRange);

            for (var cycle = 0; cycle < cycles; cycle++)
            {
                for (var block = 0; block < blocks; block++)
                {
                    var x      = Vec256.Load(src.TakeSpan(blocklen));
                    var offset = offsets.First();
                    sw.Start();
                    Bits.sll(x, offset);
                    sw.Stop();
                }
            }
            return(OpTime.Define(opcount, snapshot(sw), "slli16u"));
        }
예제 #28
0
        void VerifyHi256 <T>(int n = Pow2.T12)
            where T : unmanaged
        {
            TypeCaseStart <T>();
            var lhsSrc = Random.Span256 <T>(n);
            var rhsSrc = Random.Span256 <T>(n);

            for (var i = 0; i < n; i++)
            {
                var lhs = lhsSrc.ToCpuVec256(i);
                var rhs = rhsSrc.ToCpuVec256(i);
                var x   = ginx.unpackhi(lhs, rhs);

                var k  = lhs.Length();
                var j  = k / 2;
                var y1 = lhs.ToSpan().Slice(j - 1, j);
                var y2 = rhs.ToSpan().Slice(j - 1, j);
                var y  = Vec256.Load(ref y1.Concat(y2)[0]);

                Claim.eq(x, y);
            }
            TypeCaseEnd <T>();
        }
예제 #29
0
파일: tv_sll.cs 프로젝트: 0xCM/arrows
        // Truncates alternating source vector components
        static Vec256 <T> ShuffleTruncateMask <T>()
            where T : unmanaged

        {
            var mask = Span256.Alloc <T>(1);
            var chop = PrimalInfo.Get <T>().MaxVal;

            //For the first 128-bit lane
            var half = mask.Length / 2;

            for (byte i = 0; i < half; i++)
            {
                if (i % 2 != 0)
                {
                    mask[i] = chop;
                }
                else
                {
                    mask[i] = convert <byte, T>(i);
                }
            }

            //For the second 128-bit lane
            for (byte i = 0; i < half; i++)
            {
                if (i % 2 != 0)
                {
                    mask[i + half] = chop;
                }
                else
                {
                    mask[i + half] = convert <byte, T>(i);
                }
            }

            return(Vec256.Load(mask));
        }
예제 #30
0
        public void blend_256_u8()
        {
            void Test1()
            {
                var v0   = Random.CpuVec256 <byte>();
                var v1   = Random.CpuVec256 <byte>();
                var bits = Random.BitString <N32>();
                var mask = Vec256.Load(bits.Map(x => x ? (byte)0xFF : (byte)0));
                var v3   = dinx.blendv(v0, v1, mask);

                var selection = Span256.AllocBlocks <byte>(1);

                for (var i = 0; i < selection.Length; i++)
                {
                    selection[i] = bits[i] ? v1[i] : v0[i];
                }
                var v4 = selection.ToCpuVec256();

                Claim.eq(v3, v4);
            }

            Verify(Test1);

            var v1      = Vec256.Fill <byte>(3);
            var v2      = Vec256.Fill <byte>(4);
            var control = Vec256Pattern.Alternate <byte>(0, 0xFF);
            var v3      = dinx.blendv(v1, v2, control);
            var block   = Span256.AllocBlocks <byte>(1);

            for (var i = 0; i < 32; i++)
            {
                block[i] = (byte)(even(i) ? 3 : 4);
            }
            var v4 = block.ToCpuVec256();

            Claim.eq(v3, v4);
        }