コード例 #1
0
ファイル: AsmBranchInfo.cs プロジェクト: 0xCM/arrows
 public AsmBranchInfo(BitSize size, long value, bool near, ulong @base)
 {
     this.Size   = size;
     this.Target = (ulong)value;
     this.Near   = near;
     this.Base   = @base;
 }
コード例 #2
0
ファイル: BitSize.cs プロジェクト: 0xCM/arrows
 /// <summary>
 /// Calculates the (minimum) number of segments required to hold
 /// a contiguous sequence of bits
 /// </summary>
 /// <param name="capacity">The number of bits that comprise each segment</param>
 /// <param name="bitcount">The number of bits</param>
 public static int Segments(BitSize capacity, BitSize bitcount)
 {
     if (capacity >= bitcount)
     {
         return(1);
     }
     else
     {
         var q = Math.DivRem(bitcount, capacity, out int r);
         return(r == 0 ? q : q + 1);
     }
 }
コード例 #3
0
ファイル: BitString.api.cs プロジェクト: 0xCM/arrows
        /// <summary>
        /// Constructs a bitstring from a pattern replicated a specified number of times
        /// </summary>
        /// <param name="src">The source pattern</param>
        /// <param name="reps">The number of times to repeat the pattern</param>
        /// <typeparam name="T">The primal source type</typeparam>
        public static BitString FromPattern <T>(T src, int reps)
            where T : struct
        {
            BitSize     capacity = Unsafe.SizeOf <T>() * 8;
            Span <byte> bitseq   = new byte[capacity * reps];
            var         pattern  = FromScalar(src);

            for (var i = 0; i < reps; i++)
            {
                pattern.BitSeq.CopyTo(bitseq, i * capacity);
            }
            return(FromBitSeq(bitseq));
        }
コード例 #4
0
ファイル: BitMap.cs プロジェクト: 0xCM/arrows
        public static BitMap FromCells(BitSize cellwidth, int cellcount)
        {
            var bitcount = cellcount * cellwidth;
            var indices  = new BitIndex[bitcount];

            for (var cell = 0u; cell < cellcount; cell++)
            {
                for (byte bit = 0; bit < bitcount; bit++)
                {
                    indices[cell * cellwidth + bit] = new BitIndex(cell, bit);
                }
            }
            return(FromIndices(cellcount, cellwidth, indices));
        }
コード例 #5
0
ファイル: BitMap.cs プロジェクト: 0xCM/arrows
        public static BitMap FromBits(BitSize cellwidth, BitSize bitcount)
        {
            var q         = Math.DivRem(bitcount, cellwidth, out int r);
            var cellcount = r == 0 ? q : q + 1;
            var indices   = new BitIndex[cellcount * cellwidth];

            for (var cell = 0u; cell < cellcount; cell++)
            {
                for (byte bit = 0; bit < cellwidth; bit++)
                {
                    indices[cell * cellwidth + bit] = new BitIndex(cell, bit);
                }
            }
            return(new BitMap(cellcount, cellwidth, indices));
        }
コード例 #6
0
ファイル: BitMatrixMNT.cs プロジェクト: 0xCM/arrows
        public static BitMatrix <M, N, T> Ones()
        {
            var dst    = Alloc();
            var data   = dst.data;
            var length = BitSize.Size <T>();

            for (var i = 0; i < data.Length; i++)
            {
                for (var j = 0; j < length; j++)
                {
                    gbits.enable(ref data[i], j);
                }
            }
            return(dst);
        }
コード例 #7
0
ファイル: BitMap.cs プロジェクト: 0xCM/arrows
        /// <summary>
        /// Creates a bitmap over cells of unmanaged parametric type
        /// </summary>
        /// <param name="bitcount">The number of bits to spread over the cells</param>
        /// <typeparam name="T">The cell type</typeparam>
        public static BitMap <T> FromBits <T>(BitSize bitcount)
            where T : unmanaged
        {
            var cellwidth = bitsize <T>();
            var q         = Math.DivRem(bitcount, cellwidth, out int r);
            var cellcount = r == 0 ? q : q + 1;
            var indices   = new BitIndex[bitcount];

            for (var cell = 0u; cell < cellcount; cell++)
            {
                for (byte bit = 0; bit < cellwidth; bit++)
                {
                    indices[cell * cellwidth + bit] = new BitIndex(cell, bit);
                }
            }
            return(new BitMap <T>(FromIndices(cellcount, cellwidth, indices)));
        }
コード例 #8
0
ファイル: BitSize.cs プロジェクト: 0xCM/arrows
        /// <summary>
        /// Calculates a canonical bijection from a contiguous sequence of bits onto a contiguous sequence of segments
        /// </summary>
        /// <param name="bitcount">The total number of bits to distribute over one or more segments</param>
        public static                  CellIndex <T>[] BitMap <T>(BitSize bitcount)
            where T : struct
        {
            var    dst      = new CellIndex <T> [bitcount];
            var    capacity = bitsize <T>();
            ushort seg      = 0;
            byte   offset   = 0;

            for (var i = 0; i < bitcount; i++)
            {
                if (i != 0)
                {
                    if ((i % capacity) == 0)
                    {
                        seg++;
                        offset = 0;
                    }
                }
                dst[i] = (seg, offset++);
            }
            return(dst);
        }
コード例 #9
0
ファイル: BitMap.cs プロジェクト: 0xCM/arrows
 public static BitMap FromIndices(int cellcount, BitSize cellwidth, params BitIndex[] indices)
 => new BitMap(cellcount, cellwidth, indices);
コード例 #10
0
ファイル: BitMap.cs プロジェクト: 0xCM/arrows
 BitMap(int cellcount, BitSize cellwidth, BitIndex[] indices)
 {
     this.CellCount = cellcount;
     this.CellWidth = cellwidth;
     this.Indices   = indices;
 }
コード例 #11
0
 /// <summary>
 /// Allocates a generic bitvector
 /// </summary>
 /// <param name="len">The length</param>
 /// <param name="fill">The fill value</param>
 /// <typeparam name="N">The length type</typeparam>
 /// <typeparam name="T">The component type</typeparam>
 public static BitVector <T> Alloc <T>(BitSize len, T?fill = null)
     where T : unmanaged
 => BitVector <T> .Alloc(len, fill);
コード例 #12
0
 public static int CellCount <T>(BitSize len)
     where T : unmanaged
 => BitVector <T> .CellCount(len);
コード例 #13
0
 public static BitVectorInfo Define(BitSize capacity)
 => new BitVectorInfo(capacity);
コード例 #14
0
ファイル: BitSize.cs プロジェクト: 0xCM/arrows
 /// <summary>
 /// Calculates the minimum number of segments required to hold a contiguous sequence of bits
 /// </summary>
 /// <param name="segsize">The number of bytes that comprise each segment</param>
 /// <param name="bitcount">The number of bits</param>
 /// <typeparam name="T">The segment type</typeparam>
 public static int Segments <T>(BitSize bitcount)
     where T : struct
 => Segments(bitsize <T>(), bitcount);
コード例 #15
0
 public static bool between <T>(BitSize x, T lhs, T rhs, [Member] string caller = null, [File] string file = null, [Line] int?line = null)
     where T : struct
 => gmath.between(x.Bits.Convert <T>(), lhs, rhs) ? true : throw failed(ClaimOpKind.Between, NotBetween(x.Bits.Convert <T>(), lhs, rhs, caller, file, line));
コード例 #16
0
ファイル: AsmImmInfo.cs プロジェクト: 0xCM/arrows
 public AsmImmInfo(BitSize size, long value)
 {
     this.Size  = size;
     this.Value = (ulong)value;
 }
コード例 #17
0
ファイル: BitString.cs プロジェクト: 0xCM/arrows
        public static BitString BitString(this IPolyrand random, BitSize len)
        {
            var bytes = random.Span <byte>(len.UpperByteCount);

            return(Z0.BitString.FromScalars(bytes, len));
        }
コード例 #18
0
 public static bool between <T>(BitSize x, Interval <T> range, [Member] string caller = null, [File] string file = null, [Line] int?line = null)
     where T : struct
 => range.Contains(x.Bits.Convert <T>()) ? true : throw failed(ClaimOpKind.Between, NotBetween(x.Bits.Convert <T>(), range.Left, range.Right, caller, file, line));
コード例 #19
0
 BitVectorInfo(BitSize capacity)
 {
     this.Capacity = capacity;
 }
コード例 #20
0
 public static BitVector <T> Load <T>(T[] src, BitSize n)
     where T : unmanaged
 => BitVector <T> .Load(src, n);