Skip to content

Commit 2722fd3

Browse files
committed
[Cranelift] implement udiv
1 parent 9732540 commit 2722fd3

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

cranelift/codegen/src/isle_prelude.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ macro_rules! isle_common_prelude_methods {
7474
Some(Imm64::new(result).mask_to_width(type_width))
7575
}
7676

77+
#[inline]
78+
fn imm64_udiv(&mut self, ty: Type, x: Imm64, y: Imm64) -> Option<Imm64> {
79+
let type_width = ty.bits();
80+
assert!(type_width <= 64);
81+
let mask = self.ty_mask(ty);
82+
let x = (x.bits() as u64) & mask;
83+
let y = (y.bits() as u64) & mask;
84+
let result = x.checked_div(y)?;
85+
Some(Imm64::new(result as i64).mask_to_width(type_width))
86+
}
87+
7788
#[inline]
7889
fn imm64_srem(&mut self, ty: Type, x: Imm64, y: Imm64) -> Option<Imm64> {
7990
// Sign extend `x` and `y`.

cranelift/codegen/src/prelude.isle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
(decl pure partial imm64_sdiv (Type Imm64 Imm64) Imm64)
7474
(extern constructor imm64_sdiv imm64_sdiv)
7575

76+
(decl pure partial imm64_udiv (Type Imm64 Imm64) Imm64)
77+
(extern constructor imm64_udiv imm64_udiv)
78+
7679
(decl pure partial imm64_srem (Type Imm64 Imm64) Imm64)
7780
(extern constructor imm64_srem imm64_srem)
7881

0 commit comments

Comments
 (0)