public AsmBranchInfo(BitSize size, long value, bool near, ulong @base) { this.Size = size; this.Target = (ulong)value; this.Near = near; this.Base = @base; }
/// <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); } }
/// <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)); }
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)); }
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)); }
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); }
/// <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))); }
/// <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); }
public static BitMap FromIndices(int cellcount, BitSize cellwidth, params BitIndex[] indices) => new BitMap(cellcount, cellwidth, indices);
BitMap(int cellcount, BitSize cellwidth, BitIndex[] indices) { this.CellCount = cellcount; this.CellWidth = cellwidth; this.Indices = indices; }
/// <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);
public static int CellCount <T>(BitSize len) where T : unmanaged => BitVector <T> .CellCount(len);
public static BitVectorInfo Define(BitSize capacity) => new BitVectorInfo(capacity);
/// <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);
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));
public AsmImmInfo(BitSize size, long value) { this.Size = size; this.Value = (ulong)value; }
public static BitString BitString(this IPolyrand random, BitSize len) { var bytes = random.Span <byte>(len.UpperByteCount); return(Z0.BitString.FromScalars(bytes, len)); }
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));
BitVectorInfo(BitSize capacity) { this.Capacity = capacity; }
public static BitVector <T> Load <T>(T[] src, BitSize n) where T : unmanaged => BitVector <T> .Load(src, n);