fixed lint

This commit is contained in:
ptitSeb
2021-11-03 10:33:06 +01:00
parent 235b30930b
commit 9710ab8b84
6 changed files with 145 additions and 91 deletions

View File

@@ -1,5 +1,7 @@
use crate::address_map::get_function_address_map;
use crate::{common_decl::*, config::Singlepass, emitter_x64::*, machine_x64::Machine, x64_decl::*};
use crate::{
common_decl::*, config::Singlepass, emitter_x64::*, machine_x64::Machine, x64_decl::*,
};
use dynasmrt::{x64::Assembler, DynamicLabel};
use smallvec::{smallvec, SmallVec};
use std::collections::BTreeMap;
@@ -639,7 +641,8 @@ impl<'a> FuncGen<'a> {
}
Location::Memory(_, _) | Location::GPR(_) => {
op(self, src1, src2, tmp3);
self.assembler.emit_mov(Size::S64, Location::SIMD(tmp3), dst);
self.assembler
.emit_mov(Size::S64, Location::SIMD(tmp3), dst);
}
_ => {
return Err(CodegenError {
@@ -2852,7 +2855,8 @@ impl<'a> FuncGen<'a> {
.emit_vmovaps(XMMOrMemory::XMM(src1), XMMOrMemory::XMM(x));
}
Location::Memory(_, _) | Location::GPR(_) => {
self.assembler.emit_mov(Size::S64, Location::SIMD(src1), ret);
self.assembler
.emit_mov(Size::S64, Location::SIMD(src1), ret);
}
_ => {
return Err(CodegenError {
@@ -3005,7 +3009,8 @@ impl<'a> FuncGen<'a> {
.emit_vmovaps(XMMOrMemory::XMM(src1), XMMOrMemory::XMM(x));
}
Location::Memory(_, _) | Location::GPR(_) => {
self.assembler.emit_mov(Size::S64, Location::SIMD(src1), ret);
self.assembler
.emit_mov(Size::S64, Location::SIMD(src1), ret);
}
_ => {
return Err(CodegenError {
@@ -3342,7 +3347,8 @@ impl<'a> FuncGen<'a> {
.emit_vmovapd(XMMOrMemory::XMM(src1), XMMOrMemory::XMM(x));
}
Location::Memory(_, _) | Location::GPR(_) => {
self.assembler.emit_mov(Size::S64, Location::SIMD(src1), ret);
self.assembler
.emit_mov(Size::S64, Location::SIMD(src1), ret);
}
_ => {
return Err(CodegenError {
@@ -3496,7 +3502,8 @@ impl<'a> FuncGen<'a> {
.emit_vmovaps(XMMOrMemory::XMM(src1), XMMOrMemory::XMM(x));
}
Location::Memory(_, _) | Location::GPR(_) => {
self.assembler.emit_mov(Size::S64, Location::SIMD(src1), ret);
self.assembler
.emit_mov(Size::S64, Location::SIMD(src1), ret);
}
_ => {
return Err(CodegenError {
@@ -3833,7 +3840,12 @@ impl<'a> FuncGen<'a> {
let tmp_out = self.machine.acquire_temp_gpr().unwrap();
let tmp_in = self.machine.acquire_temp_xmm().unwrap();
self.emit_relaxed_binop(Assembler::emit_mov, Size::S32, loc, Location::SIMD(tmp_in));
self.emit_relaxed_binop(
Assembler::emit_mov,
Size::S32,
loc,
Location::SIMD(tmp_in),
);
self.emit_f32_int_conv_check_sat(
tmp_in,
GEF32_LT_U32_MIN,
@@ -3931,7 +3943,12 @@ impl<'a> FuncGen<'a> {
let tmp_out = self.machine.acquire_temp_gpr().unwrap();
let tmp_in = self.machine.acquire_temp_xmm().unwrap();
self.emit_relaxed_binop(Assembler::emit_mov, Size::S32, loc, Location::SIMD(tmp_in));
self.emit_relaxed_binop(
Assembler::emit_mov,
Size::S32,
loc,
Location::SIMD(tmp_in),
);
self.emit_f32_int_conv_check_sat(
tmp_in,
GEF32_LT_I32_MIN,
@@ -4035,7 +4052,12 @@ impl<'a> FuncGen<'a> {
let tmp_out = self.machine.acquire_temp_gpr().unwrap();
let tmp_in = self.machine.acquire_temp_xmm().unwrap();
self.emit_relaxed_binop(Assembler::emit_mov, Size::S32, loc, Location::SIMD(tmp_in));
self.emit_relaxed_binop(
Assembler::emit_mov,
Size::S32,
loc,
Location::SIMD(tmp_in),
);
self.emit_f32_int_conv_check_sat(
tmp_in,
GEF32_LT_I64_MIN,
@@ -4172,7 +4194,12 @@ impl<'a> FuncGen<'a> {
let tmp_out = self.machine.acquire_temp_gpr().unwrap();
let tmp_in = self.machine.acquire_temp_xmm().unwrap();
self.emit_relaxed_binop(Assembler::emit_mov, Size::S32, loc, Location::SIMD(tmp_in));
self.emit_relaxed_binop(
Assembler::emit_mov,
Size::S32,
loc,
Location::SIMD(tmp_in),
);
self.emit_f32_int_conv_check_sat(
tmp_in,
GEF32_LT_U64_MIN,
@@ -4311,7 +4338,12 @@ impl<'a> FuncGen<'a> {
let tmp_out = self.machine.acquire_temp_gpr().unwrap();
let tmp_in = self.machine.acquire_temp_xmm().unwrap();
self.emit_relaxed_binop(Assembler::emit_mov, Size::S64, loc, Location::SIMD(tmp_in));
self.emit_relaxed_binop(
Assembler::emit_mov,
Size::S64,
loc,
Location::SIMD(tmp_in),
);
self.emit_f64_int_conv_check_sat(
tmp_in,
GEF64_LT_U32_MIN,
@@ -4546,7 +4578,12 @@ impl<'a> FuncGen<'a> {
let tmp_out = self.machine.acquire_temp_gpr().unwrap();
let tmp_in = self.machine.acquire_temp_xmm().unwrap();
self.emit_relaxed_binop(Assembler::emit_mov, Size::S64, loc, Location::SIMD(tmp_in));
self.emit_relaxed_binop(
Assembler::emit_mov,
Size::S64,
loc,
Location::SIMD(tmp_in),
);
self.emit_f64_int_conv_check_sat(
tmp_in,
GEF64_LT_I64_MIN,
@@ -4684,7 +4721,12 @@ impl<'a> FuncGen<'a> {
let tmp_out = self.machine.acquire_temp_gpr().unwrap();
let tmp_in = self.machine.acquire_temp_xmm().unwrap();
self.emit_relaxed_binop(Assembler::emit_mov, Size::S64, loc, Location::SIMD(tmp_in));
self.emit_relaxed_binop(
Assembler::emit_mov,
Size::S64,
loc,
Location::SIMD(tmp_in),
);
self.emit_f64_int_conv_check_sat(
tmp_in,
GEF64_LT_U64_MIN,

View File

@@ -1,6 +1,6 @@
pub use crate::x64_decl::{GPR, XMM};
pub use crate::location::Multiplier;
use crate::location::Location as AbstractLocation;
pub use crate::location::Multiplier;
pub use crate::x64_decl::{GPR, XMM};
use dynasm::dynasm;
use dynasmrt::{
x64::X64Relocation, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi, VecAssembler,
@@ -34,7 +34,6 @@ macro_rules! dynasm {
// MemoryAddTriple(GPR, GPR, i32),
//}
pub type Location = AbstractLocation<GPR, XMM>;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
@@ -814,19 +813,35 @@ impl Emitter for Assembler {
(Size::S32, Location::Memory2(src1, src2, mult, disp), Location::GPR(dst)) => {
match mult {
Multiplier::Zero => dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + disp]),
Multiplier::One => dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) + disp]),
Multiplier::Two => dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 2 + disp]),
Multiplier::Four => dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 4 + disp]),
Multiplier::Height => dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 8 + disp]),
Multiplier::One => {
dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) + disp])
}
Multiplier::Two => {
dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 2 + disp])
}
Multiplier::Four => {
dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 4 + disp])
}
Multiplier::Height => {
dynasm!(self ; lea Rd(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 8 + disp])
}
};
}
(Size::S64, Location::Memory2(src1, src2, mult, disp), Location::GPR(dst)) => {
match mult {
Multiplier::Zero => dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + disp]),
Multiplier::One => dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) + disp]),
Multiplier::Two => dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 2 + disp]),
Multiplier::Four => dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 4 + disp]),
Multiplier::Height => dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 8 + disp]),
Multiplier::One => {
dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) + disp])
}
Multiplier::Two => {
dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 2 + disp])
}
Multiplier::Four => {
dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 4 + disp])
}
Multiplier::Height => {
dynasm!(self ; lea Rq(dst as u8), [Rq(src1 as u8) + Rq(src2 as u8) * 8 + disp])
}
};
}
_ => panic!("singlepass can't emit LEA {:?} {:?} {:?}", sz, src, dst),

View File

@@ -14,10 +14,10 @@ mod common_decl;
mod compiler;
mod config;
mod emitter_x64;
mod location;
mod machine;
mod machine_x64;
mod x64_decl;
mod location;
pub use crate::compiler::SinglepassCompiler;
pub use crate::config::Singlepass;

View File

@@ -1,61 +1,61 @@
use crate::machine::*;
use std::fmt::Debug;
#[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Multiplier {
Zero = 0,
One = 1,
Two = 2,
Four = 4,
Height = 8,
}
#[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Location<R, S> {
GPR(R),
SIMD(S),
Memory(R, i32),
Memory2(R, R, Multiplier, i32), // R + R*Multiplier + i32
Imm8(u8),
Imm32(u32),
Imm64(u64),
None,
}
impl<R, S> MaybeImmediate for Location<R, S> {
fn imm_value(&self) -> Option<Value> {
match *self {
Location::Imm8(imm) => Some(Value::I8(imm as i8)),
Location::Imm32(imm) => Some(Value::I32(imm as i32)),
Location::Imm64(imm) => Some(Value::I64(imm as i64)),
_ => None,
}
}
}
pub trait Reg: Copy + Clone + Eq + PartialEq + Debug {
fn is_callee_save(self) -> bool;
fn is_reserved(self) -> bool;
fn into_index(self) -> usize;
fn from_index(i: usize) -> Result<Self, ()>;
}
pub trait Descriptor<R: Reg, S: Reg> {
const FP: R;
const VMCTX: R;
const GPR_COUNT: usize;
const SIMD_COUNT: usize;
const WORD_SIZE: usize;
const STACK_GROWS_DOWN: bool;
const FP_STACK_ARG_OFFSET: i32;
const ARG_REG_COUNT: usize;
fn callee_save_gprs() -> Vec<R>;
fn caller_save_gprs() -> Vec<R>;
fn callee_save_simd() -> Vec<S>;
fn caller_save_simd() -> Vec<S>;
fn callee_param_location(n: usize) -> Location<R, S>;
fn caller_arg_location(n: usize) -> Location<R, S>;
fn return_location() -> Location<R, S>;
}
use crate::machine::*;
use std::fmt::Debug;
#[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Multiplier {
Zero = 0,
One = 1,
Two = 2,
Four = 4,
Height = 8,
}
#[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Location<R, S> {
GPR(R),
SIMD(S),
Memory(R, i32),
Memory2(R, R, Multiplier, i32), // R + R*Multiplier + i32
Imm8(u8),
Imm32(u32),
Imm64(u64),
None,
}
impl<R, S> MaybeImmediate for Location<R, S> {
fn imm_value(&self) -> Option<Value> {
match *self {
Location::Imm8(imm) => Some(Value::I8(imm as i8)),
Location::Imm32(imm) => Some(Value::I32(imm as i32)),
Location::Imm64(imm) => Some(Value::I64(imm as i64)),
_ => None,
}
}
}
pub trait Reg: Copy + Clone + Eq + PartialEq + Debug {
fn is_callee_save(self) -> bool;
fn is_reserved(self) -> bool;
fn into_index(self) -> usize;
fn from_index(i: usize) -> Result<Self, ()>;
}
pub trait Descriptor<R: Reg, S: Reg> {
const FP: R;
const VMCTX: R;
const GPR_COUNT: usize;
const SIMD_COUNT: usize;
const WORD_SIZE: usize;
const STACK_GROWS_DOWN: bool;
const FP_STACK_ARG_OFFSET: i32;
const ARG_REG_COUNT: usize;
fn callee_save_gprs() -> Vec<R>;
fn caller_save_gprs() -> Vec<R>;
fn callee_save_simd() -> Vec<S>;
fn caller_save_simd() -> Vec<S>;
fn callee_param_location(n: usize) -> Location<R, S>;
fn caller_arg_location(n: usize) -> Location<R, S>;
fn return_location() -> Location<R, S>;
}

View File

@@ -1,6 +1,4 @@
#[allow(dead_code)]
#[derive(Clone, PartialEq)]
pub enum Value {
I8(i8),
@@ -16,4 +14,3 @@ pub trait MaybeImmediate {
self.imm_value().is_some()
}
}

View File

@@ -94,8 +94,8 @@ impl AbstractReg for GPR {
impl AbstractReg for XMM {
fn is_callee_save(self) -> bool {
const IS_CALLEE_SAVE: [bool; 16] = [
false, false, false, false, false, false, false, false,
true, true, true, true, true, true, true, true,
false, false, false, false, false, false, false, false, true, true, true, true, true,
true, true, true,
];
IS_CALLEE_SAVE[self as usize]
}