Fix clippy warnings.
This commit fixes the current set of (stable) clippy warnings in the repo.
This commit is contained in:
committed by
Andrew Brown
parent
1176e4f178
commit
9f506692c2
@@ -22,8 +22,7 @@ impl Isa {
|
||||
Isa::all()
|
||||
.iter()
|
||||
.cloned()
|
||||
.filter(|isa| isa.to_string() == name)
|
||||
.next()
|
||||
.find(|isa| isa.to_string() == name)
|
||||
}
|
||||
|
||||
/// Creates isa target from arch.
|
||||
@@ -55,7 +54,7 @@ impl fmt::Display for Isa {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn define(isas: &Vec<Isa>, shared_defs: &mut SharedDefinitions) -> Vec<TargetIsa> {
|
||||
pub(crate) fn define(isas: &[Isa], shared_defs: &mut SharedDefinitions) -> Vec<TargetIsa> {
|
||||
isas.iter()
|
||||
.map(|isa| match isa {
|
||||
Isa::Riscv => riscv::define(shared_defs),
|
||||
|
||||
@@ -56,7 +56,7 @@ impl<'defs> PerCpuModeEncodings<'defs> {
|
||||
|
||||
fn load_bits(funct3: u16) -> u16 {
|
||||
assert!(funct3 <= 0b111);
|
||||
0b00000 | (funct3 << 5)
|
||||
funct3 << 5
|
||||
}
|
||||
|
||||
fn store_bits(funct3: u16) -> u16 {
|
||||
@@ -91,13 +91,13 @@ fn opimm32_bits(funct3: u16, funct7: u16) -> u16 {
|
||||
|
||||
fn op_bits(funct3: u16, funct7: u16) -> u16 {
|
||||
assert!(funct3 <= 0b111);
|
||||
assert!(funct7 <= 0b1111111);
|
||||
assert!(funct7 <= 0b111_1111);
|
||||
0b01100 | (funct3 << 5) | (funct7 << 8)
|
||||
}
|
||||
|
||||
fn op32_bits(funct3: u16, funct7: u16) -> u16 {
|
||||
assert!(funct3 <= 0b111);
|
||||
assert!(funct7 <= 0b1111111);
|
||||
assert!(funct7 <= 0b111_1111);
|
||||
0b01110 | (funct3 << 5) | (funct7 << 8)
|
||||
}
|
||||
|
||||
@@ -177,11 +177,11 @@ pub(crate) fn define<'defs>(
|
||||
|
||||
// Basic arithmetic binary instructions are encoded in an R-type instruction.
|
||||
for &(inst, inst_imm, f3, f7) in &[
|
||||
(iadd, Some(iadd_imm), 0b000, 0b0000000),
|
||||
(isub, None, 0b000, 0b0100000),
|
||||
(bxor, Some(bxor_imm), 0b100, 0b0000000),
|
||||
(bor, Some(bor_imm), 0b110, 0b0000000),
|
||||
(band, Some(band_imm), 0b111, 0b0000000),
|
||||
(iadd, Some(iadd_imm), 0b000, 0b000_0000),
|
||||
(isub, None, 0b000, 0b010_0000),
|
||||
(bxor, Some(bxor_imm), 0b100, 0b000_0000),
|
||||
(bor, Some(bor_imm), 0b110, 0b000_0000),
|
||||
(band, Some(band_imm), 0b111, 0b000_0000),
|
||||
] {
|
||||
e.add32(e.enc(inst.bind(I32), r_r, op_bits(f3, f7)));
|
||||
e.add64(e.enc(inst.bind(I64), r_r, op_bits(f3, f7)));
|
||||
@@ -194,8 +194,8 @@ pub(crate) fn define<'defs>(
|
||||
}
|
||||
|
||||
// 32-bit ops in RV64.
|
||||
e.add64(e.enc(iadd.bind(I32), r_r, op32_bits(0b000, 0b0000000)));
|
||||
e.add64(e.enc(isub.bind(I32), r_r, op32_bits(0b000, 0b0100000)));
|
||||
e.add64(e.enc(iadd.bind(I32), r_r, op32_bits(0b000, 0b000_0000)));
|
||||
e.add64(e.enc(isub.bind(I32), r_r, op32_bits(0b000, 0b010_0000)));
|
||||
// There are no andiw/oriw/xoriw variations.
|
||||
e.add64(e.enc(iadd_imm.bind(I32), r_ii, opimm32_bits(0b000, 0)));
|
||||
|
||||
@@ -208,7 +208,7 @@ pub(crate) fn define<'defs>(
|
||||
for &(inst, inst_imm, f3, f7) in &[
|
||||
(ishl, ishl_imm, 0b1, 0b0),
|
||||
(ushr, ushr_imm, 0b101, 0b0),
|
||||
(sshr, sshr_imm, 0b101, 0b100000),
|
||||
(sshr, sshr_imm, 0b101, 0b10_0000),
|
||||
] {
|
||||
e.add32(e.enc(inst.bind(I32).bind(I32), r_r, op_bits(f3, f7)));
|
||||
e.add64(e.enc(inst.bind(I64).bind(I64), r_r, op_bits(f3, f7)));
|
||||
@@ -246,20 +246,20 @@ pub(crate) fn define<'defs>(
|
||||
let icmp_i32 = icmp.bind(I32);
|
||||
let icmp_i64 = icmp.bind(I64);
|
||||
e.add32(
|
||||
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b010, 0b0000000))
|
||||
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b010, 0b000_0000))
|
||||
.inst_predicate(icmp_instp(&icmp_i32, "slt")),
|
||||
);
|
||||
e.add64(
|
||||
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b010, 0b0000000))
|
||||
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b010, 0b000_0000))
|
||||
.inst_predicate(icmp_instp(&icmp_i64, "slt")),
|
||||
);
|
||||
|
||||
e.add32(
|
||||
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b011, 0b0000000))
|
||||
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b011, 0b000_0000))
|
||||
.inst_predicate(icmp_instp(&icmp_i32, "ult")),
|
||||
);
|
||||
e.add64(
|
||||
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b011, 0b0000000))
|
||||
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b011, 0b000_0000))
|
||||
.inst_predicate(icmp_instp(&icmp_i64, "ult")),
|
||||
);
|
||||
|
||||
@@ -293,15 +293,15 @@ pub(crate) fn define<'defs>(
|
||||
// "M" Standard Extension for Integer Multiplication and Division.
|
||||
// Gated by the `use_m` flag.
|
||||
e.add32(
|
||||
e.enc(imul.bind(I32), r_r, op_bits(0b000, 0b00000001))
|
||||
e.enc(imul.bind(I32), r_r, op_bits(0b000, 0b0000_0001))
|
||||
.isa_predicate(use_m),
|
||||
);
|
||||
e.add64(
|
||||
e.enc(imul.bind(I64), r_r, op_bits(0b000, 0b00000001))
|
||||
e.enc(imul.bind(I64), r_r, op_bits(0b000, 0b0000_0001))
|
||||
.isa_predicate(use_m),
|
||||
);
|
||||
e.add64(
|
||||
e.enc(imul.bind(I32), r_r, op32_bits(0b000, 0b00000001))
|
||||
e.enc(imul.bind(I32), r_r, op32_bits(0b000, 0b0000_0001))
|
||||
.isa_predicate(use_m),
|
||||
);
|
||||
|
||||
|
||||
@@ -33,11 +33,10 @@ impl RecipeGroup {
|
||||
}
|
||||
|
||||
pub fn by_name(&self, name: &str) -> EncodingRecipeNumber {
|
||||
let number = *self
|
||||
*self
|
||||
.name_to_recipe
|
||||
.get(name)
|
||||
.expect(&format!("unknown riscv recipe name {}", name));
|
||||
number
|
||||
.unwrap_or_else(|| panic!("unknown riscv recipe name {}", name))
|
||||
}
|
||||
|
||||
pub fn collect(self) -> Recipes {
|
||||
@@ -97,7 +96,7 @@ pub(crate) fn define(shared_defs: &SharedDefinitions, regs: &IsaRegs) -> RecipeG
|
||||
EncodingRecipeBuilder::new("Iz", &formats.unary_imm, 4)
|
||||
.operands_out(vec![gpr])
|
||||
.inst_predicate(InstructionPredicate::new_is_signed_int(
|
||||
&*&formats.unary_imm,
|
||||
&formats.unary_imm,
|
||||
"imm",
|
||||
12,
|
||||
0,
|
||||
@@ -111,7 +110,7 @@ pub(crate) fn define(shared_defs: &SharedDefinitions, regs: &IsaRegs) -> RecipeG
|
||||
.operands_in(vec![gpr])
|
||||
.operands_out(vec![gpr])
|
||||
.inst_predicate(InstructionPredicate::new_is_signed_int(
|
||||
&*&formats.int_compare_imm,
|
||||
&formats.int_compare_imm,
|
||||
"imm",
|
||||
12,
|
||||
0,
|
||||
@@ -183,7 +182,7 @@ pub(crate) fn define(shared_defs: &SharedDefinitions, regs: &IsaRegs) -> RecipeG
|
||||
EncodingRecipeBuilder::new("U", &formats.unary_imm, 4)
|
||||
.operands_out(vec![gpr])
|
||||
.inst_predicate(InstructionPredicate::new_is_signed_int(
|
||||
&*&formats.unary_imm,
|
||||
&formats.unary_imm,
|
||||
"imm",
|
||||
32,
|
||||
12,
|
||||
|
||||
@@ -70,7 +70,7 @@ impl PerCpuModeEncodings {
|
||||
{
|
||||
let (recipe, bits) = template.build();
|
||||
let recipe_number = self.add_recipe(recipe);
|
||||
let builder = EncodingBuilder::new(inst.into(), recipe_number, bits);
|
||||
let builder = EncodingBuilder::new(inst, recipe_number, bits);
|
||||
builder_closure(builder).build(&self.recipes, &mut self.inst_pred_reg)
|
||||
}
|
||||
|
||||
@@ -367,6 +367,7 @@ impl PerCpuModeEncodings {
|
||||
|
||||
// Definitions.
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
pub(crate) fn define(
|
||||
shared_defs: &SharedDefinitions,
|
||||
settings: &SettingGroup,
|
||||
@@ -1916,7 +1917,7 @@ pub(crate) fn define(
|
||||
|
||||
// SIMD integer addition
|
||||
for (ty, opcodes) in &[(I8, &PADDB), (I16, &PADDW), (I32, &PADDD), (I64, &PADDQ)] {
|
||||
let iadd = iadd.bind(vector(ty.clone(), sse_vector_size));
|
||||
let iadd = iadd.bind(vector(*ty, sse_vector_size));
|
||||
e.enc_32_64(iadd, rec_fa.opcodes(*opcodes));
|
||||
}
|
||||
|
||||
@@ -1940,7 +1941,7 @@ pub(crate) fn define(
|
||||
|
||||
// SIMD integer subtraction
|
||||
for (ty, opcodes) in &[(I8, &PSUBB), (I16, &PSUBW), (I32, &PSUBD), (I64, &PSUBQ)] {
|
||||
let isub = isub.bind(vector(ty.clone(), sse_vector_size));
|
||||
let isub = isub.bind(vector(*ty, sse_vector_size));
|
||||
e.enc_32_64(isub, rec_fa.opcodes(*opcodes));
|
||||
}
|
||||
|
||||
@@ -1968,7 +1969,7 @@ pub(crate) fn define(
|
||||
(I16, &PMULLW[..], None),
|
||||
(I32, &PMULLD[..], Some(use_sse41_simd)),
|
||||
] {
|
||||
let imul = imul.bind(vector(ty.clone(), sse_vector_size));
|
||||
let imul = imul.bind(vector(*ty, sse_vector_size));
|
||||
e.enc_32_64_maybe_isap(imul, rec_fa.opcodes(opcodes), *isap);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::shared::formats::Formats;
|
||||
use crate::shared::immediates::Immediates;
|
||||
use crate::shared::types;
|
||||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
pub(crate) fn define(
|
||||
mut all_instructions: &mut AllInstructions,
|
||||
formats: &Formats,
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::shared::types::Float::F64;
|
||||
use crate::shared::types::Int::{I16, I32, I64};
|
||||
use crate::shared::Definitions as SharedDefinitions;
|
||||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &InstructionGroup) {
|
||||
let mut group = TransformGroupBuilder::new(
|
||||
"x86_expand",
|
||||
@@ -253,7 +254,7 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
|
||||
def!(r = popcnt.I64(x)),
|
||||
vec![
|
||||
def!(qv3 = ushr_imm(x, imm64_1)),
|
||||
def!(qc77 = iconst(Literal::constant(&imm.imm64, 0x7777777777777777))),
|
||||
def!(qc77 = iconst(Literal::constant(&imm.imm64, 0x7777_7777_7777_7777))),
|
||||
def!(qv4 = band(qv3, qc77)),
|
||||
def!(qv5 = isub(x, qv4)),
|
||||
def!(qv6 = ushr_imm(qv4, imm64_1)),
|
||||
@@ -264,9 +265,9 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
|
||||
def!(qv11 = isub(qv8, qv10)),
|
||||
def!(qv12 = ushr_imm(qv11, imm64_4)),
|
||||
def!(qv13 = iadd(qv11, qv12)),
|
||||
def!(qc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F0F0F0F0F0F0F))),
|
||||
def!(qc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F_0F0F_0F0F_0F0F))),
|
||||
def!(qv14 = band(qv13, qc0F)),
|
||||
def!(qc01 = iconst(Literal::constant(&imm.imm64, 0x0101010101010101))),
|
||||
def!(qc01 = iconst(Literal::constant(&imm.imm64, 0x0101_0101_0101_0101))),
|
||||
def!(qv15 = imul(qv14, qc01)),
|
||||
def!(r = ushr_imm(qv15, Literal::constant(&imm.imm64, 56))),
|
||||
],
|
||||
@@ -294,7 +295,7 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
|
||||
def!(r = popcnt.I32(x)),
|
||||
vec![
|
||||
def!(lv3 = ushr_imm(x, imm64_1)),
|
||||
def!(lc77 = iconst(Literal::constant(&imm.imm64, 0x77777777))),
|
||||
def!(lc77 = iconst(Literal::constant(&imm.imm64, 0x7777_7777))),
|
||||
def!(lv4 = band(lv3, lc77)),
|
||||
def!(lv5 = isub(x, lv4)),
|
||||
def!(lv6 = ushr_imm(lv4, imm64_1)),
|
||||
@@ -305,9 +306,9 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
|
||||
def!(lv11 = isub(lv8, lv10)),
|
||||
def!(lv12 = ushr_imm(lv11, imm64_4)),
|
||||
def!(lv13 = iadd(lv11, lv12)),
|
||||
def!(lc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F0F0F))),
|
||||
def!(lc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F_0F0F))),
|
||||
def!(lv14 = band(lv13, lc0F)),
|
||||
def!(lc01 = iconst(Literal::constant(&imm.imm64, 0x01010101))),
|
||||
def!(lc01 = iconst(Literal::constant(&imm.imm64, 0x0101_0101))),
|
||||
def!(lv15 = imul(lv14, lc01)),
|
||||
def!(r = ushr_imm(lv15, Literal::constant(&imm.imm64, 24))),
|
||||
],
|
||||
|
||||
@@ -51,14 +51,14 @@ impl<'builder> RecipeGroup<'builder> {
|
||||
pub fn recipe(&self, name: &str) -> &EncodingRecipe {
|
||||
self.recipes
|
||||
.iter()
|
||||
.find(|recipe| &recipe.name == name)
|
||||
.expect(&format!("unknown recipe name: {}. Try template?", name))
|
||||
.find(|recipe| recipe.name == name)
|
||||
.unwrap_or_else(|| panic!("unknown recipe name: {}. Try template?", name))
|
||||
}
|
||||
pub fn template(&self, name: &str) -> &Template {
|
||||
self.templates
|
||||
.iter()
|
||||
.find(|recipe| recipe.name() == name)
|
||||
.expect(&format!("unknown tail recipe name: {}. Try recipe?", name))
|
||||
.unwrap_or_else(|| panic!("unknown tail recipe name: {}. Try recipe?", name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ impl<'builder> RecipeGroup<'builder> {
|
||||
|
||||
/// Given a sequence of opcode bytes, compute the recipe name prefix and encoding bits.
|
||||
fn decode_opcodes(op_bytes: &[u8], rrr: u16, w: u16) -> (&'static str, u16) {
|
||||
assert!(op_bytes.len() >= 1, "at least one opcode byte");
|
||||
assert!(!op_bytes.is_empty(), "at least one opcode byte");
|
||||
|
||||
let prefix_bytes = &op_bytes[..op_bytes.len() - 1];
|
||||
let (name, mmpp) = match prefix_bytes {
|
||||
@@ -121,7 +121,7 @@ fn decode_opcodes(op_bytes: &[u8], rrr: u16, w: u16) -> (&'static str, u16) {
|
||||
}
|
||||
};
|
||||
|
||||
let opcode_byte = op_bytes[op_bytes.len() - 1] as u16;
|
||||
let opcode_byte = u16::from(op_bytes[op_bytes.len() - 1]);
|
||||
(name, opcode_byte | (mmpp << 8) | (rrr << 12) | w << 15)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ impl<'builder> Template<'builder> {
|
||||
if let Some(prefixed) = &self.when_prefixed {
|
||||
let mut ret = prefixed.rex();
|
||||
// Forward specialized parameters.
|
||||
ret.op_bytes = self.op_bytes.clone();
|
||||
ret.op_bytes = self.op_bytes;
|
||||
ret.w_bit = self.w_bit;
|
||||
ret.rrr_bits = self.rrr_bits;
|
||||
return ret;
|
||||
@@ -266,18 +266,17 @@ impl<'builder> Template<'builder> {
|
||||
self.recipe.base_size += size_addendum;
|
||||
|
||||
// Branch ranges are relative to the end of the instruction.
|
||||
self.recipe
|
||||
.branch_range
|
||||
.as_mut()
|
||||
.map(|range| range.inst_size += size_addendum);
|
||||
if let Some(range) = self.recipe.branch_range.as_mut() {
|
||||
range.inst_size += size_addendum;
|
||||
}
|
||||
|
||||
self.recipe.emit = replace_put_op(self.recipe.emit, &name);
|
||||
self.recipe.name = name + &self.recipe.name;
|
||||
|
||||
if !self.rex {
|
||||
let operands_in = self.recipe.operands_in.unwrap_or(Vec::new());
|
||||
let operands_in = self.recipe.operands_in.unwrap_or_default();
|
||||
self.recipe.operands_in = Some(replace_nonrex_constraints(self.regs, operands_in));
|
||||
let operands_out = self.recipe.operands_out.unwrap_or(Vec::new());
|
||||
let operands_out = self.recipe.operands_out.unwrap_or_default();
|
||||
self.recipe.operands_out = Some(replace_nonrex_constraints(self.regs, operands_out));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user