if (!this->emitStore(*T, BO))
return false;
return DiscardResult ? this->emitPopPtr(BO) : true;
+ case BO_And:
+ return Discard(this->emitBitAnd(*T, BO));
+ case BO_Or:
+ case BO_LAnd:
+ case BO_LOr:
default:
return this->bail(BO);
}
return false;
}
+ static bool bitAnd(Integral A, Integral B, unsigned OpBits, Integral *R) {
+ *R = Integral(A.V & B.V);
+ return false;
+ }
+
static bool neg(Integral A, Integral *R) {
*R = -A;
return false;
/// 1) Pops the RHS from the stack.
/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS & RHS' on the stack
+template <PrimType Name, class T = typename PrimConv<Name>::T>
+bool BitAnd(InterpState &S, CodePtr OpPC) {
+ const T &RHS = S.Stk.pop<T>();
+ const T &LHS = S.Stk.pop<T>();
+
+ unsigned Bits = RHS.bitWidth();
+ T Result;
+ if (!T::bitAnd(LHS, RHS, Bits, &Result)) {
+ S.Stk.push<T>(Result);
+ return true;
+ }
+ return false;
+}
+
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
/// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
template <PrimType Name, class T = typename PrimConv<Name>::T>
bool Rem(InterpState &S, CodePtr OpPC) {
Uint32, Sint64, Uint64];
}
+def IntegerTypeClass : TypeClass {
+ let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
+ Uint32, Sint64, Uint64];
+}
+
def AluTypeClass : TypeClass {
let Types = !listconcat(NumberTypeClass.Types, [Bool]);
}
let HasGroup = 1;
}
+class IntegerOpcode : Opcode {
+ let Types = [IntegerTypeClass];
+ let HasGroup = 1;
+}
+
//===----------------------------------------------------------------------===//
// Jump opcodes
//===----------------------------------------------------------------------===//
let Types = [NumberTypeClass];
let HasGroup = 1;
}
+def BitAnd : IntegerOpcode;
def Div : Opcode {
let Types = [NumberTypeClass];
let HasGroup = 1;
#endif
};
+
+namespace band {
+ static_assert((10 & 1) == 0, "");
+ static_assert((10 & 10) == 10, "");
+
+ static_assert((1337 & -1) == 1337, "");
+ static_assert((0 & gimme(12)) == 0, "");
+};