mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
dev backend NumCompare
This commit is contained in:
parent
adcdfdbd46
commit
728f982aa5
3 changed files with 71 additions and 26 deletions
|
|
@ -1815,6 +1815,34 @@ impl<
|
|||
);
|
||||
}
|
||||
|
||||
fn build_num_cmp(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
src1: &Symbol,
|
||||
src2: &Symbol,
|
||||
arg_layout: &InLayout<'a>,
|
||||
) {
|
||||
// This implements the expression:
|
||||
// (x != y) as u8 + (x < y) as u8
|
||||
// For x==y: (false as u8) + (false as u8) = 0 = RocOrder::Eq
|
||||
// For x>y: (true as u8) + (false as u8) = 1 = RocOrder::Gt
|
||||
// For x<y: (true as u8) + (true as u8) = 2 = RocOrder::Lt
|
||||
// u8 is represented in the stack machine as i32, but written to memory as 1 byte
|
||||
let not_equal = self.debug_symbol("not_equal");
|
||||
|
||||
self.build_neq(¬_equal, src1, src2, arg_layout);
|
||||
self.build_num_lt(dst, src1, src2, arg_layout);
|
||||
|
||||
let neq_reg = self
|
||||
.storage_manager
|
||||
.load_to_general_reg(&mut self.buf, ¬_equal);
|
||||
let dst_reg = self.storage_manager.load_to_general_reg(&mut self.buf, dst);
|
||||
|
||||
ASM::add_reg64_reg64_reg64(&mut self.buf, dst_reg, dst_reg, neq_reg);
|
||||
|
||||
self.free_symbol(¬_equal);
|
||||
}
|
||||
|
||||
fn build_num_lt(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
|
|
|
|||
|
|
@ -327,18 +327,23 @@ trait Backend<'a> {
|
|||
where
|
||||
I: Iterator<Item = InLayout<'b>>,
|
||||
{
|
||||
use std::fmt::Write;
|
||||
use std::hash::{BuildHasher, Hash, Hasher};
|
||||
|
||||
// NOTE: due to randomness, this will not be consistent between runs
|
||||
let mut state = roc_collections::all::BuildHasher::default().build_hasher();
|
||||
let mut buf = String::with_capacity(1024);
|
||||
|
||||
for a in arguments {
|
||||
a.hash(&mut state);
|
||||
write!(buf, "{:?}", self.interner().dbg_deep(a)).expect("capacity");
|
||||
}
|
||||
|
||||
// lambda set should not matter; it should already be added as an argument
|
||||
// lambda_set.hash(&mut state);
|
||||
|
||||
result.hash(&mut state);
|
||||
write!(buf, "{:?}", self.interner().dbg_deep(result)).expect("capacity");
|
||||
|
||||
// NOTE: due to randomness, this will not be consistent between runs
|
||||
let mut state = roc_collections::all::BuildHasher::default().build_hasher();
|
||||
buf.hash(&mut state);
|
||||
|
||||
let interns = self.interns();
|
||||
let ident_string = symbol.as_str(interns);
|
||||
|
|
@ -1807,6 +1812,10 @@ trait Backend<'a> {
|
|||
);
|
||||
}
|
||||
|
||||
LowLevel::NumCompare => {
|
||||
self.build_num_cmp(sym, &args[0], &args[1], &arg_layouts[0]);
|
||||
}
|
||||
|
||||
x => todo!("low level, {:?}", x),
|
||||
}
|
||||
}
|
||||
|
|
@ -2057,6 +2066,14 @@ trait Backend<'a> {
|
|||
/// build_not stores the result of `!src` into dst.
|
||||
fn build_not(&mut self, dst: &Symbol, src: &Symbol, arg_layout: &InLayout<'a>);
|
||||
|
||||
fn build_num_cmp(
|
||||
&mut self,
|
||||
dst: &Symbol,
|
||||
src1: &Symbol,
|
||||
src2: &Symbol,
|
||||
arg_layout: &InLayout<'a>,
|
||||
);
|
||||
|
||||
/// build_num_lt stores the result of `src1 < src2` into dst.
|
||||
fn build_num_lt(
|
||||
&mut self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue