예제 #1
0
파일: ts_bitblock.cs 프로젝트: 0xCM/arrows
        public void bitblock32_spans()
        {
            var x = BitBlock32.Alloc();

            x.Bit0  = 1;
            x.Bit5  = 1;
            x.Bit19 = 1;
            var y = BitBlock.AsSpan(ref x);

            Claim.eq(y[0], x.Bit0);
            Claim.eq(y[5], x.Bit19);

            Claim.eq(x[0], (byte)1);
            Claim.eq(x[5], (byte)1);
            Claim.eq(x[19], (byte)1);

            for (var i = 0; i < SampleSize; i++)
            {
                var src      = Random.Span <byte>(Pow2.T05);
                var dstBlock = BitBlock32.FromSpan(src);
                for (var j = 0; j < src.Length; j++)
                {
                    Claim.eq(src[j], dstBlock[j]);
                }

                var dstSpan = BitBlock.AsSpan(ref dstBlock);
                for (var j = 0; j < dstSpan.Length; j++)
                {
                    Bits.toggle(ref dstSpan[j], 0);
                    Claim.neq(dstBlock[j], src[j]);
                }
            }
        }
예제 #2
0
파일: ts_bitblock.cs 프로젝트: 0xCM/arrows
 public void bitblock32_pack()
 {
     for (var i = 0; i < SampleSize; i++)
     {
         var src   = Random.Next <uint>();
         var block = BitBlock32.Alloc();
         var dst   = 0u;
         BitParts.part32x1(src, ref block);
         BitParts.pack32x1(in block, ref dst);
         Claim.eq(dst, src);
     }
 }
예제 #3
0
파일: Nx1Partition.cs 프로젝트: 0xCM/arrows
        /// <summary>
        /// Partitions 32 bits from the source into 32 target segments of effective width 1
        /// </summary>
        /// <param name="src">The source value</param>
        /// <param name="dst">A target span of sufficient length</param>
        public static ref BitBlock32 part32x1(uint src, ref BitBlock32 dst)
        {
            dst.Bit0  = project <byte>(select(src, Part32x1.Part0), Part32x1.First);
            dst.Bit1  = project <byte>(select(src, Part32x1.Part1), Part32x1.First);
            dst.Bit2  = project <byte>(select(src, Part32x1.Part2), Part32x1.First);
            dst.Bit3  = project <byte>(select(src, Part32x1.Part3), Part32x1.First);
            dst.Bit4  = project <byte>(select(src, Part32x1.Part4), Part32x1.First);
            dst.Bit5  = project <byte>(select(src, Part32x1.Part5), Part32x1.First);
            dst.Bit6  = project <byte>(select(src, Part32x1.Part6), Part32x1.First);
            dst.Bit7  = project <byte>(select(src, Part32x1.Part7), Part32x1.First);
            dst.Bit8  = project <byte>(select(src, Part32x1.Part8), Part32x1.First);
            dst.Bit9  = project <byte>(select(src, Part32x1.Part9), Part32x1.First);
            dst.Bit10 = project <byte>(select(src, Part32x1.Part10), Part32x1.First);
            dst.Bit11 = project <byte>(select(src, Part32x1.Part11), Part32x1.First);
            dst.Bit12 = project <byte>(select(src, Part32x1.Part12), Part32x1.First);
            dst.Bit13 = project <byte>(select(src, Part32x1.Part13), Part32x1.First);
            dst.Bit14 = project <byte>(select(src, Part32x1.Part14), Part32x1.First);
            dst.Bit15 = project <byte>(select(src, Part32x1.Part15), Part32x1.First);
            dst.Bit16 = project <byte>(select(src, Part32x1.Part16), Part32x1.First);
            dst.Bit17 = project <byte>(select(src, Part32x1.Part17), Part32x1.First);
            dst.Bit18 = project <byte>(select(src, Part32x1.Part18), Part32x1.First);
            dst.Bit19 = project <byte>(select(src, Part32x1.Part19), Part32x1.First);
            dst.Bit20 = project <byte>(select(src, Part32x1.Part20), Part32x1.First);
            dst.Bit21 = project <byte>(select(src, Part32x1.Part21), Part32x1.First);
            dst.Bit22 = project <byte>(select(src, Part32x1.Part22), Part32x1.First);
            dst.Bit23 = project <byte>(select(src, Part32x1.Part23), Part32x1.First);
            dst.Bit24 = project <byte>(select(src, Part32x1.Part24), Part32x1.First);
            dst.Bit25 = project <byte>(select(src, Part32x1.Part25), Part32x1.First);
            dst.Bit26 = project <byte>(select(src, Part32x1.Part26), Part32x1.First);
            dst.Bit27 = project <byte>(select(src, Part32x1.Part27), Part32x1.First);
            dst.Bit28 = project <byte>(select(src, Part32x1.Part28), Part32x1.First);
            dst.Bit29 = project <byte>(select(src, Part32x1.Part29), Part32x1.First);
            dst.Bit30 = project <byte>(select(src, Part32x1.Part30), Part32x1.First);
            dst.Bit31 = project <byte>(select(src, Part32x1.Part31), Part32x1.First);

            return(ref dst);
        }
예제 #4
0
        public void bitpart_32x1_bench()
        {
            void bitstring()
            {
                var opname = "part32x1_bitstring";
                var sw     = stopwatch(false);
                var bs     = default(BitString);

                for (var i = 0; i < OpCount; i++)
                {
                    var src = Random.Next <uint>();
                    sw.Start();
                    bs = src.ToBitString();
                    sw.Stop();
                }
                Collect((OpCount, sw, opname));
            }

            void blockstyle()
            {
                var        opname = "part32x1_block32";
                var        sw     = stopwatch(false);
                BitBlock32 last   = default;

                for (var i = 0; i < OpCount; i++)
                {
                    var src = Random.Next <uint>();
                    sw.Start();
                    BitParts.part32x1(src, ref last);
                    sw.Stop();
                }
                Collect((OpCount, sw, opname));
            }

            void spanstyle()
            {
                var         opname = "part32x1";
                var         sw     = stopwatch(false);
                Span <byte> dst    = stackalloc byte[32];

                for (var i = 0; i < OpCount; i++)
                {
                    var src = Random.Next <uint>();
                    sw.Start();
                    BitParts.part32x1(src, dst);
                    sw.Stop();
                }
                Collect((OpCount, sw, opname));
            }

            void bittest()
            {
                var         opname = "part32x1_test";
                var         sw     = stopwatch(false);
                Span <byte> dst    = stackalloc byte[32];

                for (var i = 0; i < OpCount; i++)
                {
                    var src = Random.Next <uint>();
                    sw.Start();
                    part32x1_test(src, dst);
                    sw.Stop();
                }
                Collect((OpCount, sw, opname));
            }

            spanstyle();
        }
예제 #5
0
파일: Nx1Partition.cs 프로젝트: 0xCM/arrows
        public static Span <byte> part32x1(uint src)
        {
            BitBlock32 block = default;

            return(BitBlock.AsSpan(ref part32x1(src, ref block)));
        }