Exemple #1
0
        void pack_roundtrip_check <T>(BitSize bitcount)
            where T : unmanaged
        {
            var src = Random.BitString(bitcount);

            Claim.eq(bitcount, src.Length);

            var x = src.ToBits();

            Claim.eq(bitcount, x.Length);

            var y     = Bits.pack(x);
            var sizeT = size <T>();

            var q     = Math.DivRem(bitcount, 8, out int r);
            var bytes = q + (r == 0 ? 0 : 1);

            Claim.eq(bytes, y.Length);

            var bulk = ByteSpan.ReadValues <T>(y, out Span <byte> rem);

            var merged = rem.Length != 0 ? bulk.Extend(bulk.Length + 1) : bulk;

            if (merged.Length != bulk.Length)
            {
                merged[merged.Length - 1] = rem.TakeScalar <T>();
            }

            var bsOutput = merged.ToBitString().Truncate(bitcount);

            Claim.eq(src, bsOutput);
            Claim.eq((src & ~bsOutput).PopCount(), 0);
        }
Exemple #2
0
        public void bitblock_bitstring()
        {
            var src   = Random.BitString(n8);
            var block = src.ToBitBlock(n8);
            var u     = src.ToBitVector(n8);

            for (var i = 0; i < 8; i++)
            {
                Claim.yea(block[i] == u[i]);
            }
        }
Exemple #3
0
 public void bb_reverse()
 {
     for (var i = 0; i < SampleSize; i++)
     {
         var bs     = Random.BitString(n20);
         var block1 = bs.Replicate().ToBitBlock(n20);
         block1.Reverse();
         bs.Reverse();
         for (var j = 0; j < bs.Length; j++)
         {
             Claim.yea(bs[i] == block1[i]);
         }
     }
 }
Exemple #4
0
        public void bs_truncate()
        {
            for (var i = 0; i < SampleSize; i++)
            {
                var src = Random.BitString(SampleSize);
                Claim.eq(src.Length, SampleSize);

                var len = Random.Next <int>(2, SampleSize - 2);
                var dst = src.Truncate(len);
                Claim.eq(len, dst.Length);
                for (var j = 0; j < len; j++)
                {
                    Claim.eq(src[j], dst[j]);
                }
            }
        }
Exemple #5
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);
        }
Exemple #6
0
 public void bitblock_generic()
 {
     var     srcA = Random.BitString(16).BitSeq;
     var     srcB = Random.BitString(16).BitSeq;
     ref var x    = ref BitBlock.FromSpan(srcA, out BitBlock16 _);