Skip to content

Commit bd7d5f6

Browse files
committed
[Cranelift] add imm64 operations
1 parent 511638f commit bd7d5f6

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

cranelift/codegen/src/isle_prelude.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,54 @@ macro_rules! isle_common_prelude_methods {
8989
Some(Imm64::new(result).mask_to_width(type_width))
9090
}
9191

92+
#[inline]
93+
fn imm64_add(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
94+
let ty_mask = self.ty_mask(ty) as i64;
95+
Imm64::new(x.bits().wrapping_add(y.bits()) & ty_mask)
96+
}
97+
98+
#[inline]
99+
fn imm64_sub(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
100+
let ty_mask = self.ty_mask(ty) as i64;
101+
Imm64::new(x.bits().wrapping_sub(y.bits()) & ty_mask)
102+
}
103+
104+
#[inline]
105+
fn imm64_mul(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
106+
let ty_mask = self.ty_mask(ty) as i64;
107+
Imm64::new(x.bits().wrapping_mul(y.bits()) & ty_mask)
108+
}
109+
110+
#[inline]
111+
fn imm64_and(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
112+
let ty_mask = self.ty_mask(ty) as i64;
113+
Imm64::new((x.bits() & y.bits()) & ty_mask)
114+
}
115+
116+
#[inline]
117+
fn imm64_or(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
118+
let ty_mask = self.ty_mask(ty) as i64;
119+
Imm64::new((x.bits() | y.bits()) & ty_mask)
120+
}
121+
122+
#[inline]
123+
fn imm64_xor(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
124+
let ty_mask = self.ty_mask(ty) as i64;
125+
Imm64::new((x.bits() ^ y.bits()) & ty_mask)
126+
}
127+
128+
#[inline]
129+
fn imm64_not(&mut self, ty: Type, x: Imm64) -> Imm64 {
130+
let ty_mask = self.ty_mask(ty) as i64;
131+
Imm64::new((!x.bits()) & ty_mask)
132+
}
133+
134+
#[inline]
135+
fn imm64_neg(&mut self, ty: Type, x: Imm64) -> Imm64 {
136+
let ty_mask = self.ty_mask(ty) as i64;
137+
Imm64::new(x.bits().wrapping_neg() & ty_mask)
138+
}
139+
92140
#[inline]
93141
fn imm64_shl(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
94142
// Mask off any excess shift bits.

cranelift/codegen/src/prelude.isle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@
7676
(decl pure partial imm64_srem (Type Imm64 Imm64) Imm64)
7777
(extern constructor imm64_srem imm64_srem)
7878

79+
(decl pure imm64_add (Type Imm64 Imm64) Imm64)
80+
(extern constructor imm64_add imm64_add)
81+
82+
(decl pure imm64_sub (Type Imm64 Imm64) Imm64)
83+
(extern constructor imm64_sub imm64_sub)
84+
85+
(decl pure imm64_mul (Type Imm64 Imm64) Imm64)
86+
(extern constructor imm64_mul imm64_mul)
87+
88+
(decl pure imm64_and (Type Imm64 Imm64) Imm64)
89+
(extern constructor imm64_and imm64_and)
90+
91+
(decl pure imm64_or (Type Imm64 Imm64) Imm64)
92+
(extern constructor imm64_or imm64_or)
93+
94+
(decl pure imm64_xor (Type Imm64 Imm64) Imm64)
95+
(extern constructor imm64_xor imm64_xor)
96+
97+
(decl pure imm64_not (Type Imm64) Imm64)
98+
(extern constructor imm64_not imm64_not)
99+
100+
(decl pure imm64_neg (Type Imm64) Imm64)
101+
(extern constructor imm64_neg imm64_neg)
102+
79103
(decl pure imm64_shl (Type Imm64 Imm64) Imm64)
80104
(extern constructor imm64_shl imm64_shl)
81105

0 commit comments

Comments
 (0)