Add Lowlevel::And

This commit is contained in:
Ahmad Sattar 2023-02-16 21:01:12 +01:00
parent 82c0aa083d
commit f8b0a99e6d
No known key found for this signature in database
GPG key ID: 457C18819D9C9570
3 changed files with 41 additions and 0 deletions

View file

@ -1132,6 +1132,22 @@ impl<
} }
} }
fn build_and(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &InLayout<'a>) {
match *arg_layout {
Layout::BOOL => {
let dst_reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
let src1_reg = self
.storage_manager
.load_to_general_reg(&mut self.buf, src1);
let src2_reg = self
.storage_manager
.load_to_general_reg(&mut self.buf, src2);
ASM::and_reg64_reg64_reg64(&mut self.buf, dst_reg, src1_reg, src2_reg);
}
x => todo!("And: layout, {:?}", x),
}
}
fn build_num_lt( fn build_num_lt(
&mut self, &mut self,
dst: &Symbol, dst: &Symbol,

View file

@ -623,6 +623,19 @@ trait Backend<'a> {
); );
self.build_neq(sym, &args[0], &args[1], &arg_layouts[0]) self.build_neq(sym, &args[0], &args[1], &arg_layouts[0])
} }
LowLevel::And => {
debug_assert_eq!(2, args.len(), "And: expected to have exactly two argument");
debug_assert_eq!(
arg_layouts[0], arg_layouts[1],
"And: expected all arguments of to have the same layout"
);
debug_assert_eq!(
Layout::BOOL,
*ret_layout,
"And: expected to have return layout of type Bool"
);
self.build_and(sym, &args[0], &args[1], &arg_layouts[0])
}
LowLevel::NumLt => { LowLevel::NumLt => {
debug_assert_eq!( debug_assert_eq!(
2, 2,
@ -1016,6 +1029,9 @@ trait Backend<'a> {
/// build_neq stores the result of `src1 != src2` into dst. /// build_neq stores the result of `src1 != src2` into dst.
fn build_neq(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &InLayout<'a>); fn build_neq(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &InLayout<'a>);
/// build_and stores the result of `src1 && src2` into dst.
fn build_and(&mut self, dst: &Symbol, src1: &Symbol, src2: &Symbol, arg_layout: &InLayout<'a>);
/// build_num_lt stores the result of `src1 < src2` into dst. /// build_num_lt stores the result of `src1 < src2` into dst.
fn build_num_lt( fn build_num_lt(
&mut self, &mut self,

View file

@ -111,6 +111,15 @@ fn neq_bool_tag() {
); );
} }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn and_bool() {
assert_evals_to!("Bool.true && Bool.true", true, bool);
assert_evals_to!("Bool.true && Bool.false", false, bool);
assert_evals_to!("Bool.false && Bool.true", false, bool);
assert_evals_to!("Bool.false && Bool.false", false, bool);
}
#[test] #[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] #[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn empty_record() { fn empty_record() {