Skip to content

Commit

Permalink
Implement more float operations
Browse files Browse the repository at this point in the history
  • Loading branch information
aborg-dev committed Feb 21, 2024
1 parent 9bbeabb commit 6c1eb61
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cranelift/codegen/src/isa/zkasm/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,10 @@
;; Generates a bitcast instruction.
;; Args are: src, src_ty, dst_ty
(decl gen_bitcast (Reg Type Type) Reg)
(rule 1 (gen_bitcast r $F32 $I32) (imm $I32 0))
(rule 1 (gen_bitcast r $F64 $I64) (imm $I64 0))
(rule 1 (gen_bitcast r $I32 $F32) (imm $F32 0))
(rule 1 (gen_bitcast r $I64 $F64) (imm $F64 0))
(rule (gen_bitcast r _ _) r)

;; Selects the greatest of two registers as signed values.
Expand Down
2 changes: 0 additions & 2 deletions cranelift/codegen/src/isa/zkasm/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ impl Inst {
const_data as u64,
&mut alloc_tmp,
));
todo!();
insts
}

Expand All @@ -223,7 +222,6 @@ impl Inst {
let mut insts = SmallInstVec::new();
let tmp = alloc_tmp(I64);
insts.extend(Self::load_constant_u64(tmp, const_data, &mut alloc_tmp));
todo!();
insts
}

Expand Down
16 changes: 16 additions & 0 deletions cranelift/codegen/src/isa/zkasm/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,22 @@
(rule 0 (lower (icmp cc x @ (value_type (ty_int ty)) y))
(lower_icmp cc x y ty))

;;;;; Rules for `fcmp`;;;;;;;;;
(rule 0 (lower (fcmp cc x @ (value_type (ty_scalar_float ty)) y))
(imm $I32 0))

;;;;; Rules for `ceil`;;;;;;;;;
(rule 0 (lower (has_type (ty_scalar_float ty) (ceil x)))
(imm $F32 0))

;;;;; Rules for `floor`;;;;;;;;;
(rule 0 (lower (has_type (ty_scalar_float ty) (floor x)))
(imm $F32 0))

;;;;; Rules for `trunc`;;;;;;;;;
(rule 0 (lower (has_type (ty_scalar_float ty) (trunc x)))
(imm $F32 0))

;;;;; Rules for `func_addr`;;;;;;;;;
(rule
(lower (func_addr (func_ref_data _ name _)))
Expand Down
15 changes: 15 additions & 0 deletions cranelift/codegen/src/isa/zkasm/lower/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,32 @@ impl generated_code::Context for ZkAsmIsleContext<'_, '_, MInst, ZkAsmBackend> {
let ty_bits = i16::try_from(ty_bits).unwrap();
let shamt = {
let tmp = self.temp_writable_reg(I64);
let tmp1 = self.temp_writable_reg(I64);
// self.emit(&MInst::AluRRImm12 {
// alu_op: AluOPRRI::Andi,
// rd: tmp,
// rs: shamt.to_reg(),
// imm12: Imm12::from_i16(ty_bits - 1),
// });
self.emit(&MInst::LoadConst64 {
rd: tmp1,
imm: (ty_bits - 1) as u64,
});
self.emit(&MInst::AluRRR {
alu_op: AluOPRRR::And,
rd: tmp,
rs1: shamt.to_reg(),
rs2: tmp1.to_reg(),
});
tmp.to_reg()
};
let len_sub_shamt = {
let tmp = self.temp_writable_reg(I64);
// self.emit(&MInst::load_imm12(tmp, Imm12::from_i16(ty_bits)));
self.emit(&MInst::LoadConst64 {
rd: tmp,
imm: ty_bits as u64,
});
let len_sub_shamt = self.temp_writable_reg(I64);
self.emit(&MInst::AluRRR {
alu_op: AluOPRRR::Sub,
Expand Down

0 comments on commit 6c1eb61

Please sign in to comment.