Skip to content

Commit

Permalink
riscv64: Use pattern matches on bseti
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Mar 21, 2023
1 parent f8a9e54 commit bcd5533
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
9 changes: 5 additions & 4 deletions cranelift/codegen/src/isa/riscv64/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -814,17 +814,18 @@

;; bseti: Set a single bit in a register, indexed by a constant.
(decl bseti (Reg u64) Reg)
(rule 1 (bseti val bit)
(rule (bseti val bit)
(if-let $false (has_zbs))
(if-let $false (u64_le bit 12))
(let ((const Reg (load_u64_constant (u64_shl 1 bit))))
(alu_rrr (AluOPRRR.Or) val const)))

(rule 2 (bseti val bit)
(rule (bseti val bit)
(if-let $false (has_zbs))
(if (u64_lteq bit 12))
(if-let $true (u64_le bit 12))
(alu_rr_imm12 (AluOPRRI.Ori) val (imm12_const (u64_as_i32 (u64_shl 1 bit)))))

(rule 3 (bseti val bit)
(rule (bseti val bit)
(if-let $true (has_zbs))
(alu_rr_imm12 (AluOPRRI.Bseti) val (imm12_const (u64_as_i32 bit))))

Expand Down
9 changes: 0 additions & 9 deletions cranelift/codegen/src/isle_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,15 +615,6 @@ macro_rules! isle_common_prelude_methods {
}
}

#[inline]
fn u64_lteq(&mut self, a: u64, b: u64) -> Option<()> {
if a <= b {
Some(())
} else {
None
}
}

#[inline]
fn u32_lteq(&mut self, a: u32, b: u32) -> Option<()> {
if a <= b {
Expand Down
5 changes: 0 additions & 5 deletions cranelift/codegen/src/prelude.isle
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
(decl offset32 (u32) Offset32)
(extern extractor infallible offset32 offset32)

;; Pure/fallible constructor that tests if one u64 is less than or
;; equal to another.
(decl pure partial u64_lteq (u64 u64) Unit)
(extern constructor u64_lteq u64_lteq)

;; Pure/fallible constructor that tests if one u32 is less than or
;; equal to another.
(decl pure partial u32_lteq (u32 u32) Unit)
Expand Down

0 comments on commit bcd5533

Please sign in to comment.