Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(singlepass): use SIMD insts for popcount #4526

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compiler-singlepass/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Compiler for SinglepassCompiler {
generator.finalize(input)
}
Architecture::Aarch64(_) => {
let machine = MachineARM64::new();
let machine = MachineARM64::new(Some(target.clone()));
let mut generator = FuncGen::new(
module,
&self.config,
Expand Down
59 changes: 59 additions & 0 deletions lib/compiler-singlepass/src/emitter_arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ pub trait EmitterARM64 {
dst: Location,
) -> Result<(), CompileError>;

fn emit_fmov(
&mut self,
src_size: Size,
src: Location,
dst_size: Size,
dst: Location,
) -> Result<(), CompileError>;
fn emit_cnt(&mut self, src: NEON, dst: NEON) -> Result<(), CompileError>;
fn emit_addv(&mut self, src: NEON, dst: NEON) -> Result<(), CompileError>;
fn emit_read_fpcr(&mut self, reg: GPR) -> Result<(), CompileError>;
fn emit_write_fpcr(&mut self, reg: GPR) -> Result<(), CompileError>;
fn emit_read_fpsr(&mut self, reg: GPR) -> Result<(), CompileError>;
Expand Down Expand Up @@ -3217,6 +3226,56 @@ impl EmitterARM64 for Assembler {
dynasm!(self ; msr 0b1_011_0100_0100_001, X(reg as u32));
Ok(())
}

fn emit_cnt(&mut self, src: NEON, dst: NEON) -> Result<(), CompileError> {
dynasm!(self ; cnt V(dst.into_index() as u32).B8, V(src.into_index() as u32).B8);
Ok(())
}

fn emit_addv(&mut self, src: NEON, dst: NEON) -> Result<(), CompileError> {
dynasm!(self ; addv B(dst.into_index() as u32), V(src.into_index() as u32).B8);
Ok(())
}

fn emit_fmov(
&mut self,
src_size: Size,
src: Location,
dst_size: Size,
dst: Location,
) -> Result<(), CompileError> {
let res = match (src, dst) {
(AbstractLocation::GPR(src), AbstractLocation::SIMD(dst)) => {
match (src_size, dst_size) {
(Size::S32, Size::S32) => Ok(dynasm!(self ; fmov S(dst as u32), W(src as u32))),
(Size::S64, Size::S64) => Ok(dynasm!(self ; fmov D(dst as u32), X(src as u32))),
_ => Err(()),
}
}
(AbstractLocation::SIMD(src), AbstractLocation::GPR(dst)) => {
match (src_size, dst_size) {
(Size::S32, Size::S32) => Ok(dynasm!(self ; fmov W(dst as u32), S(src as u32))),
(Size::S64, Size::S64) => Ok(dynasm!(self ; fmov X(dst as u32), D(src as u32))),
_ => Err(()),
}
}
// (AbstractLocation::SIMD(src), AbstractLocation::SIMD(dst)) => todo!(),
// (AbstractLocation::SIMD(src), AbstractLocation::Imm32(dst)) => todo!(),
// (AbstractLocation::SIMD(src), AbstractLocation::Imm64(dst)) => todo!(),
_ => Err(()),
};

match res {
Ok(_) => Ok(()),
Err(_) => codegen_error!(
"singlepass can't generate fmov instruction for src_size: {:?}, src: {:?}, dst_size: {:?}, dst: {:?}",
src_size,
src,
dst_size,
dst,
),
}
}
}

pub fn gen_std_trampoline_arm64(
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler-singlepass/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ pub fn gen_std_trampoline(
machine.gen_std_trampoline(sig, calling_convention)
}
Architecture::Aarch64(_) => {
let machine = MachineARM64::new();
let machine = MachineARM64::new(Some(target.clone()));
machine.gen_std_trampoline(sig, calling_convention)
}
_ => Err(CompileError::UnsupportedTarget(
Expand All @@ -2433,7 +2433,7 @@ pub fn gen_std_dynamic_import_trampoline(
machine.gen_std_dynamic_import_trampoline(vmoffsets, sig, calling_convention)
}
Architecture::Aarch64(_) => {
let machine = MachineARM64::new();
let machine = MachineARM64::new(Some(target.clone()));
machine.gen_std_dynamic_import_trampoline(vmoffsets, sig, calling_convention)
}
_ => Err(CompileError::UnsupportedTarget(
Expand All @@ -2455,7 +2455,7 @@ pub fn gen_import_call_trampoline(
machine.gen_import_call_trampoline(vmoffsets, index, sig, calling_convention)
}
Architecture::Aarch64(_) => {
let machine = MachineARM64::new();
let machine = MachineARM64::new(Some(target.clone()));
machine.gen_import_call_trampoline(vmoffsets, index, sig, calling_convention)
}
_ => Err(CompileError::UnsupportedTarget(
Expand Down
Loading
Loading