public bool IncludedIn(Mask big) { return(((~big.one & one) == 0) && ((~big.zero & zero) == 0)); }
static Mask() { _0 = new Mask(one: 0, zero: ~(ulong)0); _1 = new Mask(one: 1, zero: ~(ulong)1); }
public Mask Union(Mask other) { return(new Mask(one | other.one, zero | other.zero)); }
public Mask Xor(Mask other) { return(new Mask((one & other.zero | zero & other.one), (one & other.one | zero & other.zero))); }
public Mask Or(Mask other) { return(new Mask(one | other.one, zero & other.zero)); }
public Mask And(Mask other) { return(new Mask(one & other.one, zero | other.zero)); }
public static Mask Eval(this byte[] program, Func <byte, Mask[], Mask[], Mask> process, Mask[] variables, Mask missing, int start, int lastIndex, out int offset) { if (start > lastIndex) { offset = start; return(missing); } byte code = program[start]; var st = start + 1; int argsCount = Operations.all[code].argsCount; var items = new Mask[argsCount]; for (int i = 0; i < argsCount; i++) { if (code == 6 && i == 2) { var current = items[1]; var arguments = SplitOnBytes(items[0]); int off = 0; for (int j = 0; j < arguments.Length; ++j) { var arg = arguments[j]; var vars = new Mask[3]; vars[0] = variables[0]; vars[1] = current; vars[2] = arg; Mask next = program.Eval(process, vars, missing, st, lastIndex, out off); if (next.Equals(current)) { while (j < arguments.Length - 1 && arguments[j + 1].Equals(arg)) { ++j; } } current = next; } offset = off; items[i] = current; } else { items[i] = program.Eval(process, variables, missing, st, lastIndex, out offset); } st = offset; } offset = st; return(process(code, items, variables)); }
private static Mask CalcMask(byte f, Mask[] args, Mask x = null) { if (f == 0) { return(Mask._0); } if (f == 1) { return(Mask._1); } if (f == 2) { return(x ?? Mask.X); } //TODO: fold if (f == 5) { if (args[0].CantBeZero()) { return(args[2]); } if (args[0].IsZero()) { return(args[1]); } return(args[1].Union(args[2])); } if (f == 6) { return(args[2]); } if (f == 7) { return(args[0].Not()); } if (f == 8) { return(args[0].ShiftLeft(1)); } if (f == 9) { return(args[0].ShiftRight(1)); } if (f == 10) { return(args[0].ShiftRight(4)); } if (f == 11) { return(args[0].ShiftRight(16)); } if (f == 12) { return(args[0].And(args[1])); } if (f == 13) { return(args[0].Or(args[1])); } if (f == 14) { return(args[0].Xor(args[1])); } if (f == 15) { return(args[0].FastPlus(args[1])); } return(Mask.X); }