From cd426cb7bcc81d49a4f06c78e50ab88192543fd2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 9 Sep 2019 16:31:42 -0700 Subject: [PATCH] Rename Uimm128 to V128Imm --- cranelift/codegen/src/ir/immediates.rs | 80 +++++++++++------------ cranelift/codegen/src/write.rs | 10 +-- cranelift/reader/src/parser.rs | 10 +-- cranelift/wasm/src/sections_translator.rs | 4 +- cranelift/wasm/src/translation_utils.rs | 4 +- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/cranelift/codegen/src/ir/immediates.rs b/cranelift/codegen/src/ir/immediates.rs index 2c5ee27c47..371c05bdd9 100644 --- a/cranelift/codegen/src/ir/immediates.rs +++ b/cranelift/codegen/src/ir/immediates.rs @@ -290,13 +290,13 @@ impl FromStr for Uimm32 { } } -/// A 128-bit unsigned integer immediate operand. +/// A 128-bit immediate operand. /// /// This is used as an immediate value in SIMD instructions. #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] -pub struct Uimm128(pub [u8; 16]); +pub struct V128Imm(pub [u8; 16]); -impl Uimm128 { +impl V128Imm { /// Iterate over the bytes in the constant pub fn bytes(&self) -> impl Iterator { self.0.iter() @@ -313,7 +313,7 @@ impl Uimm128 { } } -impl Display for Uimm128 { +impl Display for V128Imm { // Print a 128-bit vector in hexadecimal, e.g. 0x000102030405060708090a0b0c0d0e0f. fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "0x")?; @@ -333,24 +333,24 @@ impl Display for Uimm128 { } } -impl From for Uimm128 { +impl From for V128Imm { fn from(x: u64) -> Self { let mut buffer: [u8; 16] = [0; 16]; // zero-fill (0..8).for_each(|byte| buffer[byte] = (x >> (byte as u64 * 8) & 0xff) as u8); // insert each byte from the u64 into v in little-endian order - Uimm128(buffer) + V128Imm(buffer) } } -impl From<&[u8]> for Uimm128 { +impl From<&[u8]> for V128Imm { fn from(slice: &[u8]) -> Self { assert_eq!(slice.len(), 16); let mut buffer = [0; 16]; buffer.copy_from_slice(slice); - Uimm128(buffer) + V128Imm(buffer) } } -impl FromStr for Uimm128 { +impl FromStr for V128Imm { type Err = &'static str; // parse a 128-bit vector from a hexadecimal string, formatted as above @@ -384,7 +384,7 @@ impl FromStr for Uimm128 { position = position.wrapping_sub(1); // should only wrap on the last iteration } - Ok(Uimm128(buffer)) + Ok(V128Imm(buffer)) } } } @@ -396,7 +396,7 @@ impl FromStr for Uimm128 { /// - this requires the input type (i.e. $ty) to implement ToBytes macro_rules! construct_uimm128_from_iterator_of { ( $ty:ident, $lanes:expr ) => { - impl FromIterator<$ty> for Uimm128 { + impl FromIterator<$ty> for V128Imm { fn from_iter>(iter: T) -> Self { let mut buffer: [u8; 16] = [0; 16]; iter.into_iter() @@ -405,14 +405,14 @@ macro_rules! construct_uimm128_from_iterator_of { .flat_map(|b| b) .enumerate() .for_each(|(i, b)| buffer[i] = b); - Uimm128(buffer) + V128Imm(buffer) } } }; } /// Special case for booleans since we have to decide the bit-width based on the number of items -impl FromIterator for Uimm128 { +impl FromIterator for V128Imm { fn from_iter>(iter: T) -> Self { let bools = Vec::from_iter(iter); let count = bools.len(); @@ -425,7 +425,7 @@ impl FromIterator for Uimm128 { .enumerate() .map(|(i, &b)| (i * step, if b { 1 } else { 0 })) .for_each(|(i, b)| buffer[i] = b); - Uimm128(buffer) + V128Imm(buffer) } } @@ -1069,51 +1069,51 @@ mod tests { #[test] fn format_uimm128() { - assert_eq!(Uimm128::from(0).to_string(), "0x00"); - assert_eq!(Uimm128::from(42).to_string(), "0x2a"); - assert_eq!(Uimm128::from(3735928559).to_string(), "0xdeadbeef"); + assert_eq!(V128Imm::from(0).to_string(), "0x00"); + assert_eq!(V128Imm::from(42).to_string(), "0x2a"); + assert_eq!(V128Imm::from(3735928559).to_string(), "0xdeadbeef"); assert_eq!( - Uimm128::from(0x0102030405060708).to_string(), + V128Imm::from(0x0102030405060708).to_string(), "0x0102030405060708" ); } #[test] fn parse_uimm128() { - parse_ok::("0x00", "0x00"); - parse_ok::("0x00000042", "0x42"); - parse_ok::( + parse_ok::("0x00", "0x00"); + parse_ok::("0x00000042", "0x42"); + parse_ok::( "0x0102030405060708090a0b0c0d0e0f00", "0x0102030405060708090a0b0c0d0e0f00", ); - parse_ok::("0x_0000_0043_21", "0x4321"); + parse_ok::("0x_0000_0043_21", "0x4321"); - parse_err::("", "Expected a hexadecimal string, e.g. 0x1234"); - parse_err::("0x", "Expected a hexadecimal string, e.g. 0x1234"); - parse_err::( + parse_err::("", "Expected a hexadecimal string, e.g. 0x1234"); + parse_err::("0x", "Expected a hexadecimal string, e.g. 0x1234"); + parse_err::( "0x042", "Hexadecimal string must have an even number of digits", ); - parse_err::( + parse_err::( "0x00000000000000000000000000000000000000000000000000", "Hexadecimal string has too many digits to fit in a 128-bit vector", ); - parse_err::("0xrstu", "Unable to parse as hexadecimal"); - parse_err::("0x__", "Hexadecimal string must have some digits"); + parse_err::("0xrstu", "Unable to parse as hexadecimal"); + parse_err::("0x__", "Hexadecimal string must have some digits"); } #[test] fn uimm128_equivalence() { assert_eq!( - "0x01".parse::().unwrap().0, + "0x01".parse::().unwrap().0, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ); assert_eq!( - Uimm128::from_iter(vec![1, 0, 0, 0]).0, + V128Imm::from_iter(vec![1, 0, 0, 0]).0, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ); assert_eq!( - Uimm128::from(1).0, + V128Imm::from(1).0, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ); } @@ -1121,19 +1121,19 @@ mod tests { #[test] fn uimm128_endianness() { assert_eq!( - "0x42".parse::().unwrap().0, + "0x42".parse::().unwrap().0, [0x42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ); assert_eq!( - "0x00".parse::().unwrap().0, + "0x00".parse::().unwrap().0, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ); assert_eq!( - "0x12345678".parse::().unwrap().0, + "0x12345678".parse::().unwrap().0, [0x78, 0x56, 0x34, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ); assert_eq!( - "0x1234_5678".parse::().unwrap().0, + "0x1234_5678".parse::().unwrap().0, [0x78, 0x56, 0x34, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ); } @@ -1141,17 +1141,17 @@ mod tests { #[test] fn uimm128_from_iter() { assert_eq!( - Uimm128::from_iter(vec![4, 3, 2, 1]).0, + V128Imm::from_iter(vec![4, 3, 2, 1]).0, [4, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0] ); assert_eq!( - Uimm128::from_iter(vec![false, true]).0, + V128Imm::from_iter(vec![false, true]).0, [/* false */ 0, 0, 0, 0, 0, 0, 0, 0, /* true */ 1, 0, 0, 0, 0, 0, 0, 0] ); assert_eq!( - Uimm128::from_iter(vec![false, true, false, true, false, true, false, true]).0, + V128Imm::from_iter(vec![false, true, false, true, false, true, false, true]).0, [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0] ); @@ -1160,7 +1160,7 @@ mod tests { 1 as u8, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, ]; assert_eq!( - Uimm128::from_iter(u8s).0, + V128Imm::from_iter(u8s).0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0] ); @@ -1170,7 +1170,7 @@ mod tests { .map(|&f| Ieee32::from(f)) .collect(); assert_eq!( - Uimm128::from_iter(ieee32s).0, + V128Imm::from_iter(ieee32s).0, [ /* 32.4 == */ 0x9a, 0x99, 0x01, 0x42, /* 0 == */ 0, 0, 0, 0, /* 1 == */ 0, 0, 0x80, 0x3f, /* 6.6666 == */ 0xca, 0x54, 0xd5, 0x40, diff --git a/cranelift/codegen/src/write.rs b/cranelift/codegen/src/write.rs index e3c8bdb2fa..8d974c1ec5 100644 --- a/cranelift/codegen/src/write.rs +++ b/cranelift/codegen/src/write.rs @@ -5,7 +5,7 @@ use crate::entity::SecondaryMap; use crate::ir::entities::AnyEntity; -use crate::ir::immediates::Uimm128; +use crate::ir::immediates::V128Imm; use crate::ir::{ DataFlowGraph, DisplayFunctionAnnotations, Ebb, Function, Inst, SigRef, Type, Value, ValueDef, ValueLoc, @@ -509,15 +509,15 @@ pub fn write_operands( constant_handle, .. } => { let data = dfg.constants.get(constant_handle); - let uimm128 = Uimm128::from(&data[..]); - write!(w, " {}", uimm128) + let v128 = V128Imm::from(&data[..]); + write!(w, " {}", v128) } Shuffle { mask, args, .. } => { let data = dfg.immediates.get(mask).expect( "Expected the shuffle mask to already be inserted into the immediates table", ); - let uimm128 = Uimm128::from(&data[..]); - write!(w, " {}, {}, {}", args[0], args[1], uimm128) + let v128 = V128Imm::from(&data[..]); + write!(w, " {}, {}, {}", args[0], args[1], v128) } IntCompare { cond, args, .. } => write!(w, " {} {}, {}", cond, args[0], args[1]), IntCompareImm { cond, arg, imm, .. } => write!(w, " {} {}, {}", cond, arg, imm), diff --git a/cranelift/reader/src/parser.rs b/cranelift/reader/src/parser.rs index bc9436fe0c..711b4d3cc1 100644 --- a/cranelift/reader/src/parser.rs +++ b/cranelift/reader/src/parser.rs @@ -9,7 +9,7 @@ use crate::testfile::{Comment, Details, Feature, TestFile}; use cranelift_codegen::entity::EntityRef; use cranelift_codegen::ir; use cranelift_codegen::ir::entities::AnyEntity; -use cranelift_codegen::ir::immediates::{Ieee32, Ieee64, Imm64, Offset32, Uimm128, Uimm32, Uimm64}; +use cranelift_codegen::ir::immediates::{Ieee32, Ieee64, Imm64, Offset32, Uimm32, Uimm64, V128Imm}; use cranelift_codegen::ir::instructions::{InstructionData, InstructionFormat, VariableArgs}; use cranelift_codegen::ir::types::INVALID; use cranelift_codegen::ir::types::*; @@ -597,7 +597,7 @@ impl<'a> Parser<'a> { // Match and consume a Uimm128 immediate; due to size restrictions on InstructionData, Uimm128 // is boxed in cranelift-codegen/meta/src/shared/immediates.rs - fn match_uimm128(&mut self, err_msg: &str) -> ParseResult { + fn match_uimm128(&mut self, err_msg: &str) -> ParseResult { if let Some(Token::Integer(text)) = self.token() { self.consume(); // Lexer just gives us raw text that looks like hex code. @@ -614,7 +614,7 @@ impl<'a> Parser<'a> { } // Match and consume either a hexadecimal Uimm128 immediate (e.g. 0x000102...) or its literal list form (e.g. [0 1 2...]) - fn match_uimm128_or_literals(&mut self, controlling_type: Type) -> ParseResult { + fn match_uimm128_or_literals(&mut self, controlling_type: Type) -> ParseResult { if self.optional(Token::LBracket) { // parse using a list of values, e.g. vconst.i32x4 [0 1 2 3] let uimm128 = self.parse_literals_to_uimm128(controlling_type)?; @@ -838,7 +838,7 @@ impl<'a> Parser<'a> { } /// Parse a list of literals (i.e. integers, floats, booleans); e.g. - fn parse_literals_to_uimm128(&mut self, ty: Type) -> ParseResult { + fn parse_literals_to_uimm128(&mut self, ty: Type) -> ParseResult { macro_rules! consume { ( $ty:ident, $match_fn:expr ) => {{ assert!($ty.is_vector()); @@ -846,7 +846,7 @@ impl<'a> Parser<'a> { for _ in 0..$ty.lane_count() { v.push($match_fn?); } - Uimm128::from_iter(v) + V128Imm::from_iter(v) }}; } diff --git a/cranelift/wasm/src/sections_translator.rs b/cranelift/wasm/src/sections_translator.rs index 47aeb495cb..c8c66529ad 100644 --- a/cranelift/wasm/src/sections_translator.rs +++ b/cranelift/wasm/src/sections_translator.rs @@ -14,7 +14,7 @@ use crate::translation_utils::{ }; use crate::{wasm_unsupported, HashMap}; use core::convert::TryFrom; -use cranelift_codegen::ir::immediates::Uimm128; +use cranelift_codegen::ir::immediates::V128Imm; use cranelift_codegen::ir::{self, AbiParam, Signature}; use cranelift_entity::EntityRef; use std::vec::Vec; @@ -203,7 +203,7 @@ pub fn parse_global_section( Operator::F32Const { value } => GlobalInit::F32Const(value.bits()), Operator::F64Const { value } => GlobalInit::F64Const(value.bits()), Operator::V128Const { value } => { - GlobalInit::V128Const(Uimm128::from(value.bytes().to_vec().as_slice())) + GlobalInit::V128Const(V128Imm::from(value.bytes().to_vec().as_slice())) } Operator::GetGlobal { global_index } => { GlobalInit::GetGlobal(GlobalIndex::from_u32(global_index)) diff --git a/cranelift/wasm/src/translation_utils.rs b/cranelift/wasm/src/translation_utils.rs index 23d2c2892d..95553c6e48 100644 --- a/cranelift/wasm/src/translation_utils.rs +++ b/cranelift/wasm/src/translation_utils.rs @@ -4,7 +4,7 @@ use crate::wasm_unsupported; use core::u32; use cranelift_codegen::entity::entity_impl; use cranelift_codegen::ir; -use cranelift_codegen::ir::immediates::Uimm128; +use cranelift_codegen::ir::immediates::V128Imm; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use wasmparser; @@ -78,7 +78,7 @@ pub enum GlobalInit { /// An `f64.const`. F64Const(u64), /// A `vconst`. - V128Const(Uimm128), + V128Const(V128Imm), /// A `get_global` of another global. GetGlobal(GlobalIndex), ///< The global is imported from, and thus initialized by, a different module.