chore(audit): integrate compiler pipeline and encoder work
This commit is contained in:
commit
da4f00a782
361 files changed
+17972
-17040
No files matched your search
Generated
+9
-1
@@ -1932,7 +1932,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"rustc_apfloat",
|
||||
"serde",
|
||||
"sha2",
|
||||
"stela-fingerprint",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1969,6 +1969,13 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stela-fingerprint"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stela-loader"
|
||||
version = "0.1.0"
|
||||
@@ -2014,6 +2021,7 @@ dependencies = [
|
||||
"smoltcp",
|
||||
"stela-compiler",
|
||||
"stela-drivers",
|
||||
"stela-fingerprint",
|
||||
"tempfile",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
@@ -7,6 +7,7 @@ members = [
|
||||
"crates/stela-compiler",
|
||||
"crates/stela-drivers",
|
||||
"crates/stela-drivers/src/gpu/metal/input",
|
||||
"crates/stela-fingerprint",
|
||||
"crates/stela-runtime",
|
||||
"xtask",
|
||||
]
|
||||
@@ -45,6 +46,7 @@ libc = "0.2"
|
||||
tempfile = "3"
|
||||
stela-boot-core = { path = "crates/stela-boot-core" }
|
||||
stela-compiler = { path = "crates/stela-compiler" }
|
||||
stela-fingerprint = { path = "crates/stela-fingerprint" }
|
||||
stela-drivers = { path = "crates/stela-drivers" }
|
||||
stela-runtime = { path = "crates/stela-runtime" }
|
||||
stela-loader = { path = "crates/stela-loader" }
|
||||
|
||||
Generated
+9
-1
@@ -641,7 +641,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"rustc_apfloat",
|
||||
"serde",
|
||||
"sha2",
|
||||
"stela-fingerprint",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -661,6 +661,13 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stela-fingerprint"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stela-loader"
|
||||
version = "0.1.0"
|
||||
@@ -696,6 +703,7 @@ dependencies = [
|
||||
"smoltcp",
|
||||
"stela-compiler",
|
||||
"stela-drivers",
|
||||
"stela-fingerprint",
|
||||
"tempfile",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
@@ -122,7 +122,7 @@ impl Owner {
|
||||
///
|
||||
/// # Safety
|
||||
/// This is the source-qualified registered RAM for this executor. Its
|
||||
/// all-writer contract is retained. Direct SystemModeV1 guest data writers
|
||||
/// all-writer contract is retained. Direct `SYSTEM_MODE` guest data writers
|
||||
/// must never bypass this all-writer owner, including between checked calls.
|
||||
/// Only the source-qualified checked service and registered host/table
|
||||
/// publishers may touch data; returning to serial execution additionally
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Native host processors for system execution. Firmware identity/capability
|
||||
//! observations are copied before EBS; persistent APs use owned Stela startup
|
||||
//! and processor-local resources afterward. Production shared-memory admission
|
||||
//! is distinct from SystemModeV1's single-agent translation contract.
|
||||
//! is distinct from the direct `SYSTEM_MODE` profile's single-agent translation contract.
|
||||
pub(crate) mod bootstrap;
|
||||
pub(crate) mod canonical;
|
||||
mod context_check;
|
||||
|
||||
@@ -62,8 +62,10 @@ fn compile(words: &[u32]) -> Result<stela_compiler::block::CompiledBlock, &'stat
|
||||
let plan = CompilationPlan::new(
|
||||
&source,
|
||||
GuestAddress(BASE),
|
||||
BlockProfile::CheckedMemory(CheckedMemoryProfile::SpAlignmentDisabled),
|
||||
TargetCpu::Baseline,
|
||||
&stela_compiler::Options::new(
|
||||
BlockProfile::ORDINARY.with_checked_memory(CheckedMemoryProfile::SpAlignmentDisabled),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.map_err(|_| "native context fixture source refused")?;
|
||||
if plan.source_bytes() != source.len() {
|
||||
|
||||
@@ -221,7 +221,7 @@ pub(super) unsafe fn check(
|
||||
)
|
||||
}?;
|
||||
crate::output::arguments(format_args!(
|
||||
"NATIVE COLD source pc={:#x} bytes={code:02x?} warmup=none profile=SystemModeSharedV1\n",
|
||||
"NATIVE COLD source pc={:#x} bytes={code:02x?} warmup=none profile=system-mode+checked-memory\n",
|
||||
source::CODE
|
||||
));
|
||||
// SAFETY: same real one-BSP mount adapter, closed providers and source
|
||||
|
||||
@@ -16,4 +16,4 @@ serde.workspace = true
|
||||
rustc_apfloat.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
sha2.workspace = true
|
||||
stela-fingerprint.workspace = true
|
||||
@@ -1,39 +1,7 @@
|
||||
//! Fingerprint the compiler sources so cached native code is bound to them.
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
const INPUTS: &[&str] = &["Cargo.toml", "src"];
|
||||
|
||||
fn collect(path: &Path, files: &mut Vec<PathBuf>) {
|
||||
if path.is_dir() {
|
||||
for entry in fs::read_dir(path).expect("readable source directory") {
|
||||
collect(&entry.expect("source entry").path(), files);
|
||||
}
|
||||
} else {
|
||||
files.push(path.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut files = Vec::new();
|
||||
for input in INPUTS {
|
||||
println!("cargo:rerun-if-changed={input}");
|
||||
collect(Path::new(input), &mut files);
|
||||
}
|
||||
files.sort();
|
||||
let mut hasher = Sha256::new();
|
||||
for file in files {
|
||||
hasher.update(file.to_string_lossy().as_bytes());
|
||||
hasher.update([0]);
|
||||
hasher.update(fs::read(&file).expect("readable source file"));
|
||||
}
|
||||
let digest: String = hasher
|
||||
.finalize()
|
||||
.iter()
|
||||
.map(|byte| format!("{byte:02x}"))
|
||||
.collect();
|
||||
println!("cargo:rustc-env=STELA_COMPILER_SOURCE_SHA256={digest}");
|
||||
stela_fingerprint::emit(
|
||||
"STELA_COMPILER_SOURCE_SHA256",
|
||||
&["Cargo.toml", "build.rs", "src"],
|
||||
);
|
||||
}
|
||||
@@ -28,6 +28,21 @@ pub mod tag_arithmetic;
|
||||
pub mod tag_memory;
|
||||
pub mod unprivileged;
|
||||
|
||||
/// A word in a decoder's class that the compiler does not translate: a
|
||||
/// reserved encoding, or an allocated form the lifter reports as an
|
||||
/// unsupported instruction. A decoder returns `None` for a word outside its
|
||||
/// class.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Unsupported;
|
||||
|
||||
impl core::fmt::Display for Unsupported {
|
||||
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
formatter.write_str("untranslated A64 encoding")
|
||||
}
|
||||
}
|
||||
|
||||
impl core::error::Error for Unsupported {}
|
||||
|
||||
const CONDITIONAL_BRANCH_MASK: u32 = 0xff00_0000;
|
||||
const CONDITIONAL_BRANCH_CLASS: u32 = 0x5400_0000;
|
||||
|
||||
@@ -111,8 +126,7 @@ pub enum FloatingPointOperation {
|
||||
}
|
||||
|
||||
impl FloatingPointOperation {
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Self, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Self, Unsupported>> {
|
||||
if let Some(result) = simd::arithmetic::decode(word) {
|
||||
Some(result.map(Self::Binary))
|
||||
} else if let Some(result) = simd::fused::decode(word) {
|
||||
@@ -448,7 +462,7 @@ impl Lifter for Decoder {
|
||||
} else if let Some(decoded) = conditional_select::decode_compare(word) {
|
||||
Operation::ConditionalCompare(decoded)
|
||||
} else if let Some(decoded) = crc::decode(word) {
|
||||
Operation::Crc(decoded.map_err(|()| unsupported())?)
|
||||
Operation::Crc(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if let Some(decoded) = checked_pointer::decode(word) {
|
||||
Operation::CheckedPointer(decoded)
|
||||
} else if let Some(decoded) = flags::decode(word) {
|
||||
@@ -462,25 +476,25 @@ impl Lifter for Decoder {
|
||||
} else if let Some(decoded) = tag_arithmetic::decode(word) {
|
||||
Operation::TagArithmetic(decoded)
|
||||
} else if let Some(decoded) = integer_math::decode(word) {
|
||||
Operation::IntegerMath(decoded.map_err(|()| unsupported())?)
|
||||
Operation::IntegerMath(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if simd_fp && let Some(decoded) = FloatingPointOperation::decode(word) {
|
||||
Operation::FloatingPoint(decoded.map_err(|()| unsupported())?)
|
||||
Operation::FloatingPoint(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if let Some(decoded) = ordered::decode(word) {
|
||||
Operation::Ordered(decoded)
|
||||
} else if let Some(decoded) = atomic::decode(word) {
|
||||
Operation::Atomic(decoded.map_err(|()| unsupported())?)
|
||||
Operation::Atomic(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if let Some(decoded) = non_temporal::decode(word) {
|
||||
Operation::MemoryNonTemporal(decoded.map_err(|()| unsupported())?)
|
||||
Operation::MemoryNonTemporal(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if let Some(decoded) = unprivileged::decode(word) {
|
||||
Operation::MemoryUnprivileged(decoded.map_err(|()| unsupported())?)
|
||||
Operation::MemoryUnprivileged(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if let Some(decoded) = prefetch::decode(pc, word) {
|
||||
Operation::Prefetch(decoded.map_err(|()| unsupported())?)
|
||||
Operation::Prefetch(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if let Some(decoded) = literal::decode(pc, word) {
|
||||
Operation::Literal(decoded.map_err(|()| unsupported())?)
|
||||
Operation::Literal(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if simd_fp && let Some(decoded) = simd::decode(word) {
|
||||
Operation::Simd(decoded.map_err(|()| unsupported())?)
|
||||
Operation::Simd(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if let Some(decoded) = register_offset::decode(word) {
|
||||
Operation::MemoryRegisterOffset(decoded.map_err(|()| unsupported())?)
|
||||
Operation::MemoryRegisterOffset(decoded.map_err(|Unsupported| unsupported())?)
|
||||
} else if word & 0x3e000000 == 0x28000000 {
|
||||
// Integer LDP/STP/LDPSW. SIMD, non-temporal pairs, tagged
|
||||
// stores and reserved opcodes are not interchangeable with these accesses.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! LSE atomics: LDADD/LDCLR/LDEOR/LDSET/LDSMAX/LDSMIN/LDUMAX/LDUMIN, SWP, CAS and CASP.
|
||||
use super::{Register, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const CAS_MASK: u32 = 0x3fa07c00;
|
||||
const CAS_CLASS: u32 = 0x08a07c00;
|
||||
@@ -92,15 +93,14 @@ pub struct Operand {
|
||||
}
|
||||
|
||||
/// Reserved RMW operations and odd CASP first registers are errors.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let source = register((word >> SOURCE_SHIFT) & REGISTER_MASK, false);
|
||||
let destination = register(word & REGISTER_MASK, false);
|
||||
let (kind, order, bytes) = if word & CASP_MASK == CASP_CLASS {
|
||||
let first_compare = (word >> SOURCE_SHIFT) & REGISTER_MASK;
|
||||
let first_source = word & REGISTER_MASK;
|
||||
if (first_compare | first_source) & PAIR_FIRST_ODD_BIT != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
(
|
||||
Kind::CompareExchangePair {
|
||||
@@ -130,7 +130,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
UNSIGNED_MAX_OPCODE => Rmw::UnsignedMax,
|
||||
UNSIGNED_MIN_OPCODE => Rmw::UnsignedMin,
|
||||
SWAP_OPCODE => Rmw::Swap,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
(
|
||||
Kind::ReadModifyWrite {
|
||||
@@ -228,7 +228,7 @@ mod tests {
|
||||
| if release { CAS_RELEASE } else { 0 };
|
||||
let decoded = decode(word).unwrap();
|
||||
if (compare | source) & PAIR_FIRST_ODD_BIT != 0 {
|
||||
assert_eq!(decoded, Err(()));
|
||||
assert_eq!(decoded, Err(Unsupported));
|
||||
} else {
|
||||
assert_eq!(
|
||||
decoded,
|
||||
@@ -264,7 +264,7 @@ mod tests {
|
||||
for operation in 9..=RMW_OPERATION_MASK {
|
||||
assert_eq!(
|
||||
decode(RMW_CLASS | (operation << RMW_OPERATION_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
for word in [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! CRC32 and CRC32C.
|
||||
use super::{Register, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const CLASS_MASK: u32 = 0x7fe0e000;
|
||||
const CLASS_VALUE: u32 = 0x1ac04000;
|
||||
@@ -53,8 +54,7 @@ pub struct Operand {
|
||||
}
|
||||
|
||||
/// Register 31 is ZR in every role; sf is set exactly for doubleword data.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & CLASS_MASK != CLASS_VALUE {
|
||||
return None;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
_ => DataSize::Doubleword,
|
||||
};
|
||||
if (word & DOUBLEWORD_BIT != 0) != (size == DataSize::Doubleword) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
size,
|
||||
@@ -128,7 +128,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(decode(base ^ DOUBLEWORD_BIT), Some(Err(())));
|
||||
assert_eq!(decode(base ^ DOUBLEWORD_BIT), Some(Err(Unsupported)));
|
||||
for bit in 0..32 {
|
||||
if CLASS_MASK & (1 << bit) != 0 {
|
||||
assert!(decode(base ^ (1 << bit)).is_none());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Integer data processing: MADD/MSUB, SMADDL/SMSUBL/UMADDL/UMSUBL, SMULH/UMULH,
|
||||
//! SDIV/UDIV, LSLV/LSRV/ASRV/RORV, EXTR, CLZ, CLS, RBIT and REV*. Register 31 is ZR.
|
||||
use super::{Register, Shift, Width, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Kind {
|
||||
@@ -29,8 +30,7 @@ pub struct Operand {
|
||||
/// Match scalar SDIV/UDIV and the product three-source class. Reserved product class
|
||||
/// members return Err, so they cannot accidentally become a nearby multiply.
|
||||
/// MUL/MNEG and long aliases are represented by an ordinary ZR accumulator.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let width = if word >> 31 == 0 {
|
||||
Width::W32
|
||||
} else {
|
||||
@@ -49,7 +49,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
} else if word & 0x7fa00000 == 0x13800000 {
|
||||
let amount = ((word >> 10) & 63) as u8;
|
||||
if ((word >> 22) & 1) != word >> 31 || (width == Width::W32 && amount >= 32) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Kind::Extract { width, amount })
|
||||
} else {
|
||||
@@ -134,7 +134,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
(5, true, _) => Kind::Long { signed: false },
|
||||
(2, true, false) => Kind::High { signed: true },
|
||||
(6, true, false) => Kind::High { signed: false },
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
kind,
|
||||
@@ -190,7 +190,7 @@ mod tests {
|
||||
for amount in 0..64 {
|
||||
let decoded = decode(base | (amount << 10) | (31 << 16) | (31 << 5) | 31).unwrap();
|
||||
if width == Width::W32 && amount >= 32 {
|
||||
assert_eq!(decoded, Err(()));
|
||||
assert_eq!(decoded, Err(Unsupported));
|
||||
} else {
|
||||
let operand = decoded.unwrap();
|
||||
assert_eq!(
|
||||
@@ -206,7 +206,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
assert_eq!(decode(base ^ (1 << 22)), Some(Err(()))); // N must match sf.
|
||||
assert_eq!(decode(base ^ (1 << 22)), Some(Err(Unsupported))); // N must match sf.
|
||||
assert!(decode(base | (1 << 21)).is_none()); // fixed o0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! PC-relative literal loads: LDR (literal), LDRSW (literal) and PRFM (literal).
|
||||
use super::{Register, Width, register};
|
||||
use crate::GuestAddress;
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const CLASS_MASK: u32 = 0x3b000000;
|
||||
const LITERAL_CLASS: u32 = 0x18000000;
|
||||
@@ -39,8 +40,7 @@ pub struct Operand {
|
||||
|
||||
/// PRFM (literal) and reserved SIMD opcode 11 are unsupported. The address
|
||||
/// wraps at 64 bits and uses this instruction's guest PC.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(pc: GuestAddress, word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(pc: GuestAddress, word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & CLASS_MASK != LITERAL_CLASS {
|
||||
return None;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ pub fn decode(pc: GuestAddress, word: u32) -> Option<Result<Operand, ()>> {
|
||||
_ => unreachable!("literal SIMD form is matched above"),
|
||||
},
|
||||
},
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let immediate = i64::from((word >> IMMEDIATE_SHIFT) & IMMEDIATE_MASK);
|
||||
let signed = (immediate << IMMEDIATE_SIGN_SHIFT) >> IMMEDIATE_SIGN_SHIFT;
|
||||
@@ -126,7 +126,7 @@ mod tests {
|
||||
#[test]
|
||||
fn prefetch_reserved_and_neighboring_classes_do_not_become_loads() {
|
||||
for unsupported in [0xd8000000, 0xdc000000] {
|
||||
assert_eq!(decode(GuestAddress(0), unsupported), Some(Err(())));
|
||||
assert_eq!(decode(GuestAddress(0), unsupported), Some(Err(Unsupported)));
|
||||
}
|
||||
for bit in [24, 25, 27, 28, 29] {
|
||||
assert!(decode(GuestAddress(0), LDR_W ^ (1 << bit)).is_none());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! LDNP and STNP, integer and SIMD.
|
||||
use super::{Register, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const CLASS_MASK: u32 = 0x3b800000;
|
||||
const NON_TEMPORAL_PAIR_CLASS: u32 = 0x28000000;
|
||||
@@ -42,8 +43,7 @@ pub struct Operand {
|
||||
|
||||
/// Only signed-offset forms match (there is no writeback). Reserved sizes and
|
||||
/// duplicate LDNP destinations are errors; STNP may repeat a source.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & CLASS_MASK != NON_TEMPORAL_PAIR_CLASS {
|
||||
return None;
|
||||
}
|
||||
@@ -58,14 +58,14 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
LDNP_D => (true, QWORD_BYTES, true),
|
||||
STNP_Q => (false, VECTOR_BYTES, true),
|
||||
LDNP_Q => (true, VECTOR_BYTES, true),
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let first = word & REGISTER_MASK;
|
||||
let second = (word >> SECOND_DATA_SHIFT) & REGISTER_MASK;
|
||||
// LDPOVERLAP allows UNKNOWN/UNDEF/NOP, rather than two ordinary writes.
|
||||
// Decline even two ZRs or two V31s, matching the shared LDP boundary.
|
||||
if load && first == second {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let immediate = ((word >> IMMEDIATE_SHIFT) & IMMEDIATE_MASK) as i32;
|
||||
let signed = (immediate << IMMEDIATE_SIGN_SHIFT) >> IMMEDIATE_SIGN_SHIFT;
|
||||
@@ -114,7 +114,7 @@ mod tests {
|
||||
for base in 0..=REGISTER_MASK {
|
||||
let result = decode(word(form, 0, [first, second], base)).unwrap();
|
||||
if load && first == second {
|
||||
assert_eq!(result, Err(()));
|
||||
assert_eq!(result, Err(Unsupported));
|
||||
continue;
|
||||
}
|
||||
assert_eq!(
|
||||
@@ -153,7 +153,10 @@ mod tests {
|
||||
for form in [
|
||||
0x68000000, 0x68400000, 0xe8000000, 0xe8400000, 0xec000000, 0xec400000,
|
||||
] {
|
||||
assert_eq!(decode(form | (1 << SECOND_DATA_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(form | (1 << SECOND_DATA_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
for (form, _, _, _) in FORMS {
|
||||
for fixed_bit in [23, 24, 25, 27, 28, 29] {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! PRFM and PRFUM.
|
||||
use super::{Register, register, register_offset::IndexExtend};
|
||||
use crate::GuestAddress;
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const HINT_MASK: u32 = 31;
|
||||
const REGISTER_SHIFT: u32 = 5;
|
||||
@@ -62,8 +63,7 @@ pub struct Operand {
|
||||
/// No prefetch form checks SP alignment or updates registers. AddressAdd is
|
||||
/// modulo 64 bits in the ordinary-RAM profile with checked arithmetic disabled.
|
||||
/// Register Rt=11xxx belongs to RPRFM, whose metadata semantics stay unsupported.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(pc: GuestAddress, word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(pc: GuestAddress, word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let base = register((word >> REGISTER_SHIFT) & HINT_MASK, true);
|
||||
let address = if word & UNSIGNED_MASK == UNSIGNED_FORM {
|
||||
Address::Immediate {
|
||||
@@ -84,7 +84,7 @@ pub fn decode(pc: GuestAddress, word: u32) -> Option<Result<Operand, ()>> {
|
||||
return None;
|
||||
}
|
||||
let Some(extend) = IndexExtend::decode((word >> EXTEND_SHIFT) & EXTEND_MASK) else {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
};
|
||||
Address::Register {
|
||||
base,
|
||||
@@ -176,7 +176,7 @@ mod tests {
|
||||
if hint >= 24 {
|
||||
assert_eq!(decoded, None);
|
||||
} else if option & 2 == 0 {
|
||||
assert_eq!(decoded, Some(Err(())));
|
||||
assert_eq!(decoded, Some(Err(Unsupported)));
|
||||
} else {
|
||||
let operand = decoded.unwrap().unwrap();
|
||||
assert_eq!(operand.hint.encoding(), hint as u8);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Integer loads and stores with register-offset addressing.
|
||||
use super::{MemoryTransfer, Register, Width, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum IndexExtend {
|
||||
@@ -38,8 +39,7 @@ pub struct Operand {
|
||||
|
||||
/// None means another encoding class; Err means a reserved/unsupported form
|
||||
/// within the scalar register-offset class. SIMD and atomics never match.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & 0x3f200c00 != 0x38200800 {
|
||||
return None;
|
||||
}
|
||||
@@ -58,10 +58,10 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
signed: true,
|
||||
width: Width::W32,
|
||||
},
|
||||
_ => return Some(Err(())), // PRFM and reserved signed sizes
|
||||
_ => return Some(Err(Unsupported)), // PRFM and reserved signed sizes
|
||||
};
|
||||
let Some(extend) = IndexExtend::decode((word >> 13) & 7) else {
|
||||
return Some(Err(())); // sub-word index extensions are undefined
|
||||
return Some(Err(Unsupported)); // sub-word index extensions are undefined
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
transfer,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! AdvSIMD and FP: register transfers (LDR/STR/LDUR/STUR/LDP/STP), MOVI and the
|
||||
//! shared operand types of the SIMD families.
|
||||
use super::{AddressMode, Register, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
pub mod aes;
|
||||
pub mod arithmetic;
|
||||
pub mod bfloat16;
|
||||
@@ -126,8 +127,7 @@ pub enum Operand {
|
||||
|
||||
/// None means another encoding class; Err means an unsupported or reserved
|
||||
/// member.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if let Some(operand) = lut::decode(word) {
|
||||
return Some(Ok(Operand::Lut(operand)));
|
||||
}
|
||||
@@ -207,7 +207,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
return None;
|
||||
}
|
||||
if !scalar && !q && size == 3 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Compare {
|
||||
operation,
|
||||
@@ -258,7 +258,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
1 << ((word >> 22) & 3)
|
||||
};
|
||||
if vector_math.is_some() && !q && lane_bytes == 8 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Integer {
|
||||
operation,
|
||||
@@ -275,17 +275,17 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
1 => AddressMode::PostIndex,
|
||||
2 => AddressMode::Offset,
|
||||
3 => AddressMode::PreIndex,
|
||||
_ => return Some(Err(())), // non-temporal pairs are a separate class
|
||||
_ => return Some(Err(Unsupported)), // non-temporal pairs are a separate class
|
||||
};
|
||||
if opcode == 3 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let load = word & (1 << 22) != 0;
|
||||
let vectors = [(word & 31) as u8, ((word >> 10) & 31) as u8];
|
||||
// LDPOVERLAP allows UNKNOWN, UNDEFINED or NOP, never two ordinary
|
||||
// writes, so every duplicate destination is refused (V31 included).
|
||||
if load && vectors[0] == vectors[1] {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let bytes = 4u8 << opcode;
|
||||
let immediate = ((word >> 15) & 127) as i32;
|
||||
@@ -320,7 +320,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let opcode = (word >> 22) & 3;
|
||||
// opc[1] selects Q, whose size field must be 00.
|
||||
if opcode & 2 != 0 && size != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let scale = if opcode & 2 != 0 { 4 } else { size };
|
||||
let (displacement, mode) = if unsigned {
|
||||
@@ -330,7 +330,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
0 => AddressMode::Offset,
|
||||
1 => AddressMode::PostIndex,
|
||||
3 => AddressMode::PreIndex,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let immediate = ((word >> 12) & 511) as i32;
|
||||
((immediate << 23) >> 23, mode)
|
||||
@@ -345,6 +345,23 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
/// The scalar FP `ftype` field and its values.
|
||||
const FORMAT_SHIFT: u32 = 22;
|
||||
const FORMAT_SINGLE: u32 = 0;
|
||||
const FORMAT_DOUBLE: u32 = 1;
|
||||
const FORMAT_HALF: u32 = 3;
|
||||
|
||||
/// A scalar FP instruction's format from its `ftype` field (bits 22-23).
|
||||
fn scalar_format(word: u32) -> Result<crate::aarch64::floating::Format, Unsupported> {
|
||||
use crate::aarch64::floating::Format;
|
||||
match (word >> FORMAT_SHIFT) & 3 {
|
||||
FORMAT_SINGLE => Ok(Format::Single),
|
||||
FORMAT_DOUBLE => Ok(Format::Double),
|
||||
FORMAT_HALF => Ok(Format::Half),
|
||||
_ => Err(Unsupported),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -368,7 +385,7 @@ mod tests {
|
||||
| if unary { 0 } else { 31 << 16 };
|
||||
let decoded = decode(word).unwrap();
|
||||
if q == 0 && size == 3 {
|
||||
assert_eq!(decoded, Err(()));
|
||||
assert_eq!(decoded, Err(Unsupported));
|
||||
} else if let Ok(Operand::Integer {
|
||||
destination,
|
||||
left,
|
||||
@@ -429,7 +446,7 @@ mod tests {
|
||||
if scalar != 0 && (q == 0 || size != 3) {
|
||||
assert!(!matches!(decode(word), Some(Ok(Operand::Compare { .. }))));
|
||||
} else if scalar == 0 && q == 0 && size == 3 {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
} else if let Some(Ok(Operand::Compare {
|
||||
destination,
|
||||
left,
|
||||
@@ -597,11 +614,11 @@ mod tests {
|
||||
fn reserved_sizes_and_adjacent_memory_classes_decline() {
|
||||
for size in 1..4 {
|
||||
for prefix in [0x3d800000, 0x3dc00000, 0x3c800000, 0x3cc00000] {
|
||||
assert_eq!(decode(prefix | (size << 30)), Some(Err(())));
|
||||
assert_eq!(decode(prefix | (size << 30)), Some(Err(Unsupported)));
|
||||
}
|
||||
}
|
||||
assert_eq!(decode(0x3cc00800), Some(Err(()))); // unprivileged/reserved SIMD mode
|
||||
assert_eq!(decode(0x3ce00800), Some(Err(()))); // register offset with reserved option 000
|
||||
assert_eq!(decode(0x3cc00800), Some(Err(Unsupported))); // unprivileged/reserved SIMD mode
|
||||
assert_eq!(decode(0x3ce00800), Some(Err(Unsupported))); // register offset with reserved option 000
|
||||
for word in [0xfd000000 ^ (1 << 26), 0x9c000000, 0xc85f7c00] {
|
||||
assert!(decode(word).is_none());
|
||||
}
|
||||
@@ -632,7 +649,7 @@ mod tests {
|
||||
| (first << 5)
|
||||
| first;
|
||||
let expected = if load && first == second {
|
||||
Err(())
|
||||
Err(Unsupported)
|
||||
} else {
|
||||
Ok(Operand::MemoryPair {
|
||||
load,
|
||||
@@ -661,10 +678,10 @@ mod tests {
|
||||
for load in [false, true] {
|
||||
for opcode in 0..4 {
|
||||
let prefix = (opcode << 30) | 0x2c000400 | (u32::from(load) << 22);
|
||||
assert_eq!(decode(prefix), Some(Err(()))); // mode00: STNP/LDNP
|
||||
assert_eq!(decode(prefix), Some(Err(Unsupported))); // mode00: STNP/LDNP
|
||||
for mode in 1..4 {
|
||||
if opcode == 3 {
|
||||
assert_eq!(decode(prefix | (mode << 23)), Some(Err(())));
|
||||
assert_eq!(decode(prefix | (mode << 23)), Some(Err(Unsupported)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! AESE, AESD, AESMC and AESIMC.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const FORM_MASK: u32 = 0xffff_fc00;
|
||||
const AESE: u32 = 0x4e28_4800;
|
||||
@@ -25,8 +26,7 @@ pub struct Operand {
|
||||
|
||||
/// Only the exact .16B encodings are accepted. Other classes and reserved size
|
||||
/// encodings decline and retain the shared decoder's unsupported failure.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let kind = match word & FORM_MASK {
|
||||
AESE => Kind::Encrypt,
|
||||
AESD => Kind::Decrypt,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FP arithmetic: scalar, vector, indexed and pairwise FADD/FSUB/FMUL/FDIV/FMULX/FABD.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{BinaryOperation, Format};
|
||||
|
||||
const SCALAR_MASK: u32 = 0xff20_fc00;
|
||||
@@ -132,8 +133,7 @@ fn vector_shape(word: u32) -> Shape {
|
||||
/// None is another family; Err is reserved scalar ftype, vector1D, Half scalar
|
||||
/// pair size or indexed Double/L. All ordinary V0–V31 roles are data; indexed
|
||||
/// Half Vm permits only V0–V15 and all eight source indices, including under Q=0.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
decode_scalar(word)
|
||||
.or_else(|| decode_vector(word))
|
||||
.or_else(|| decode_simd_scalar(word))
|
||||
@@ -141,7 +141,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
.or_else(|| decode_indexed(word))
|
||||
}
|
||||
|
||||
fn decode_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_scalar(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let operation = match word & SCALAR_MASK {
|
||||
FADD => BinaryOperation::Add,
|
||||
FSUB => BinaryOperation::Subtract,
|
||||
@@ -154,7 +154,7 @@ fn decode_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
FORMAT_SINGLE => Format::Single,
|
||||
FORMAT_DOUBLE => Format::Double,
|
||||
FORMAT_HALF => Format::Half,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
operation,
|
||||
@@ -165,7 +165,7 @@ fn decode_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_vector(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (operation, half, pairwise) = match word & VECTOR_HALF_MASK {
|
||||
VECTOR_HALF_FADD => (BinaryOperation::Add, true, false),
|
||||
VECTOR_HALF_FSUB => (BinaryOperation::Subtract, true, false),
|
||||
@@ -194,7 +194,7 @@ fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
Format::Single
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
operation,
|
||||
@@ -212,7 +212,7 @@ fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_simd_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_simd_scalar(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (operation, half) = match word & SIMD_SCALAR_HALF_MASK {
|
||||
SCALAR_HALF_FABD => (BinaryOperation::AbsoluteDifference, true),
|
||||
SCALAR_HALF_FMULX => (BinaryOperation::MultiplyExtended, true),
|
||||
@@ -238,7 +238,7 @@ fn decode_simd_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_pairwise_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_pairwise_scalar(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let format = match word & PAIR_SCALAR_MASK {
|
||||
SCALAR_FADDP => {
|
||||
if word & VECTOR_DOUBLE == 0 {
|
||||
@@ -249,7 +249,7 @@ fn decode_pairwise_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}
|
||||
SCALAR_HALF_FADDP => {
|
||||
if word & VECTOR_DOUBLE != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Format::Half
|
||||
}
|
||||
@@ -266,7 +266,7 @@ fn decode_pairwise_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_indexed(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_indexed(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (half, shape) = if word & INDEXED_SCALAR_HALF_MASK == INDEXED_SCALAR_HALF {
|
||||
(true, Shape::Scalar)
|
||||
} else if word & INDEXED_SCALAR_MASK == INDEXED_SCALAR {
|
||||
@@ -295,7 +295,7 @@ fn decode_indexed(word: u32) -> Option<Result<Operand, ()>> {
|
||||
)
|
||||
} else {
|
||||
if low != 0 || shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
(Format::Double, register(word, RIGHT_SHIFT), high)
|
||||
};
|
||||
@@ -372,7 +372,7 @@ mod tests {
|
||||
for destination in 0..=REGISTER_MASK {
|
||||
for left in 0..=REGISTER_MASK {
|
||||
for right in 0..=REGISTER_MASK {
|
||||
let expected = format.map_or(Err(()), |format| {
|
||||
let expected = format.map_or(Err(Unsupported), |format| {
|
||||
Ok(Operand {
|
||||
operation,
|
||||
format,
|
||||
@@ -424,7 +424,7 @@ mod tests {
|
||||
| destination;
|
||||
let expected =
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
Err(())
|
||||
Err(Unsupported)
|
||||
} else {
|
||||
let inputs = if ordinary == VECTOR_FADDP {
|
||||
Inputs::Pairwise {
|
||||
@@ -530,7 +530,7 @@ mod tests {
|
||||
| destination
|
||||
| (source << LEFT_SHIFT)
|
||||
),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -635,9 +635,12 @@ mod tests {
|
||||
| (right << RIGHT_SHIFT)
|
||||
| destination
|
||||
| (left << LEFT_SHIFT);
|
||||
assert_eq!(decode(word | (1 << INDEX_L_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(word | (1 << INDEX_L_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
if base == INDEXED_VECTOR {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! AdvSIMD BF16: BFCVT, BFCVTN, BFDOT, BFMMLA and BFMLAL.
|
||||
use super::arithmetic::Shape;
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const SCALAR_MASK: u32 = 0xffff_fc00;
|
||||
const BFCVT: u32 = 0x1e63_4000;
|
||||
@@ -103,8 +104,7 @@ pub enum Operand {
|
||||
|
||||
/// The masks match only this family's formats. Indexed multiplies accept only
|
||||
/// V0-V15.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
decode_conversion(word)
|
||||
.or_else(|| decode_dot(word))
|
||||
.or_else(|| decode_multiply(word))
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
//! FCMP/FCCMP and AdvSIMD FCMEQ/FCMGE/FCMGT/FACGE/FACGT.
|
||||
use super::scalar_format;
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, comparison::Predicate};
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -6,11 +8,6 @@ use super::arithmetic::Shape;
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
const LEFT_SHIFT: u32 = 5;
|
||||
const RIGHT_SHIFT: u32 = 16;
|
||||
const FORMAT_SHIFT: u32 = 22;
|
||||
const FORMAT_MASK: u32 = 3;
|
||||
const FORMAT_SINGLE: u32 = 0;
|
||||
const FORMAT_DOUBLE: u32 = 1;
|
||||
const FORMAT_HALF: u32 = 3;
|
||||
const VECTOR_Q: u32 = 1 << 30;
|
||||
const SIMD_DOUBLE: u32 = 1 << 22;
|
||||
const SIMD_SCALAR_PREFIX: u32 = 0x50000000;
|
||||
@@ -92,20 +89,10 @@ fn register(word: u32, shift: u32) -> u8 {
|
||||
((word >> shift) & REGISTER_MASK) as u8
|
||||
}
|
||||
|
||||
fn scalar_format(word: u32) -> Result<Format, ()> {
|
||||
match (word >> FORMAT_SHIFT) & FORMAT_MASK {
|
||||
FORMAT_SINGLE => Ok(Format::Single),
|
||||
FORMAT_DOUBLE => Ok(Format::Double),
|
||||
FORMAT_HALF => Ok(Format::Half),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// None denotes another family; Err denotes reserved scalar ftype or vector1D.
|
||||
/// Every register field is an ordinary V register, including V31. The Rm field
|
||||
/// remains unconstrained and ignored in FCMP/FCMPE zero encodings.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & FLAGS_MASK == FCMP {
|
||||
return Some(scalar_format(word).map(|format| Operand::Flags {
|
||||
format,
|
||||
@@ -144,7 +131,7 @@ fn predicate(opcode: u32, zero: bool) -> Option<Predicate> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_predicate(word: u32, zero: bool) -> Option<Result<Operand, ()>> {
|
||||
fn decode_predicate(word: u32, zero: bool) -> Option<Result<Operand, Unsupported>> {
|
||||
let (scalar_mask, vector_mask, scalar_half_mask, vector_half_mask, half_adjustment) = if zero {
|
||||
(
|
||||
ZERO_SCALAR_MASK,
|
||||
@@ -191,7 +178,7 @@ fn decode_predicate(word: u32, zero: bool) -> Option<Result<Operand, ()>> {
|
||||
Shape::Vector128
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Predicate {
|
||||
operation,
|
||||
@@ -212,6 +199,7 @@ fn decode_predicate(word: u32, zero: bool) -> Option<Result<Operand, ()>> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::aarch64::simd::{FORMAT_DOUBLE, FORMAT_HALF, FORMAT_SHIFT, FORMAT_SINGLE};
|
||||
|
||||
const FORMATS: [(u32, Format); 3] = [
|
||||
(FORMAT_SINGLE, Format::Single),
|
||||
@@ -372,12 +360,12 @@ mod tests {
|
||||
for signal in [0, SIGNAL_ALL_NANS] {
|
||||
assert_eq!(
|
||||
decode(opcode | signal | (RESERVED_FORMAT << FORMAT_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
for (opcode, _) in REGISTER_OPERATIONS.into_iter().chain(ZERO_OPERATIONS) {
|
||||
assert_eq!(decode(opcode | SIMD_DOUBLE), Some(Err(())));
|
||||
assert_eq!(decode(opcode | SIMD_DOUBLE), Some(Err(Unsupported)));
|
||||
}
|
||||
for (opcode, _) in ZERO_OPERATIONS {
|
||||
for right in 1..=REGISTER_MASK {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FCADD and FCMLA.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, complex::Rotation};
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -57,8 +58,7 @@ pub struct Operand {
|
||||
|
||||
/// None denotes another family; Err denotes reserved size, width or pair index.
|
||||
/// All register fields, including indexed Half Vm, denote ordinary V0..V31.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (kind, rotation, indexed) = if word & ADD_MASK == FCADD {
|
||||
(
|
||||
Kind::Add,
|
||||
@@ -93,7 +93,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
SIZE_HALF => Format::Half,
|
||||
SIZE_SINGLE => Format::Single,
|
||||
SIZE_DOUBLE if !indexed && shape == Shape::Vector128 => Format::Double,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let right = register(word, RIGHT_SHIFT);
|
||||
let right = if indexed {
|
||||
@@ -103,12 +103,12 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
// size 01; the decoder follows the specification as written.
|
||||
let index = if format == Format::Half {
|
||||
if shape == Shape::Vector64 && high != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
(high << HALF_PAIR_INDEX_HIGH_SHIFT) | low
|
||||
} else {
|
||||
if shape == Shape::Vector64 || low != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
high
|
||||
};
|
||||
@@ -300,9 +300,15 @@ mod tests {
|
||||
for (q, _) in SHAPES {
|
||||
for right in 0..=REGISTER_MASK {
|
||||
let base = encoding | q | (right << RIGHT_SHIFT) | REGISTER_MASK;
|
||||
assert_eq!(decode(base | (SIZE_RESERVED << SIZE_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(base | (SIZE_RESERVED << SIZE_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
if encoding == INDEXED_FCMLA || q == 0 {
|
||||
assert_eq!(decode(base | (SIZE_DOUBLE << SIZE_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(base | (SIZE_DOUBLE << SIZE_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,18 +318,18 @@ mod tests {
|
||||
let indexes = (high << INDEX_H_SHIFT) | (low << INDEX_L_SHIFT);
|
||||
assert_eq!(
|
||||
decode(INDEXED_FCMLA | (SIZE_SINGLE << SIZE_SHIFT) | indexes),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
if low != 0 {
|
||||
assert_eq!(
|
||||
decode(INDEXED_FCMLA | (SIZE_SINGLE << SIZE_SHIFT) | VECTOR_Q | indexes),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
if high != 0 {
|
||||
assert_eq!(
|
||||
decode(INDEXED_FCMLA | (SIZE_HALF << SIZE_SHIFT) | indexes),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Scalar and AdvSIMD conversions between H/S/D and integers (FCVT*, SCVTF, UCVTF).
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::{
|
||||
Register,
|
||||
floating::{
|
||||
@@ -199,12 +200,12 @@ fn general_register(value: u8) -> Register {
|
||||
}
|
||||
}
|
||||
|
||||
fn format(field: u32) -> Result<Format, ()> {
|
||||
fn format(field: u32) -> Result<Format, Unsupported> {
|
||||
match field {
|
||||
FORMAT_SINGLE => Ok(Format::Single),
|
||||
FORMAT_DOUBLE => Ok(Format::Double),
|
||||
FORMAT_HALF => Ok(Format::Half),
|
||||
_ => Err(()),
|
||||
_ => Err(Unsupported),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,8 +228,7 @@ fn integer_width(format: Format) -> IntegerWidth {
|
||||
/// None denotes another family, including FPRCVT/FP8. Err denotes a reserved
|
||||
/// field combination in a recognized classic conversion class. All GPR 31
|
||||
/// operands are ZR; all SIMD 31 operands are ordinary V31.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
decode_precision(word)
|
||||
.or_else(|| decode_general(word))
|
||||
.or_else(|| decode_simd(word))
|
||||
@@ -242,21 +242,21 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_precision(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_precision(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & SCALAR_EXACT_MASK == BFCVT {
|
||||
return None;
|
||||
}
|
||||
let mode = if word & SCALAR_PRECISION_MASK == SCALAR_FCVT {
|
||||
let source = match format((word >> FORMAT_SHIFT) & FORMAT_MASK) {
|
||||
Ok(format) => format,
|
||||
Err(()) => return Some(Err(())),
|
||||
Err(Unsupported) => return Some(Err(Unsupported)),
|
||||
};
|
||||
let destination = match format((word >> DESTINATION_FORMAT_SHIFT) & FORMAT_MASK) {
|
||||
Ok(format) => format,
|
||||
Err(()) => return Some(Err(())),
|
||||
Err(Unsupported) => return Some(Err(Unsupported)),
|
||||
};
|
||||
if source == destination {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
PrecisionMode::Scalar {
|
||||
source,
|
||||
@@ -313,7 +313,7 @@ fn general_direction(opcode: u32) -> Option<Direction> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_general(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_general(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (direction, fixed) = if let Some(direction) = general_direction(word & GENERAL_INTEGER_MASK)
|
||||
{
|
||||
(direction, false)
|
||||
@@ -326,13 +326,13 @@ fn decode_general(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
let format = match format((word >> FORMAT_SHIFT) & FORMAT_MASK) {
|
||||
Ok(format) => format,
|
||||
Err(()) => return Some(Err(())),
|
||||
Err(Unsupported) => return Some(Err(Unsupported)),
|
||||
};
|
||||
let wide = word & GENERAL_WIDE != 0;
|
||||
let frac_bits = if fixed {
|
||||
let scale = (word >> SCALE_SHIFT) & SCALE_MASK;
|
||||
if !wide && scale < IMMEDIATE_SINGLE_MINIMUM {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
(SCALE_BIAS - scale) as u8
|
||||
} else {
|
||||
@@ -374,7 +374,7 @@ fn simd_direction(opcode: u32) -> Option<Direction> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_simd(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_simd(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
for (mask, adjustment, scalar, half) in [
|
||||
(SIMD_SCALAR_MASK, SIMD_SCALAR_PREFIX, true, false),
|
||||
(SIMD_VECTOR_MASK, 0, false, false),
|
||||
@@ -417,7 +417,7 @@ fn decode_simd(word: u32) -> Option<Result<Operand, ()>> {
|
||||
IMMEDIATE_DOUBLE_MINIMUM..=IMMEDIATE_MASK => Format::Double,
|
||||
IMMEDIATE_SINGLE_MINIMUM..IMMEDIATE_DOUBLE_MINIMUM => Format::Single,
|
||||
IMMEDIATE_HALF_MINIMUM..IMMEDIATE_SINGLE_MINIMUM => Format::Half,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let frac_bits = (2 * format.bits() - immediate) as u8;
|
||||
return Some(simd_operand(word, direction, format, scalar, frac_bits));
|
||||
@@ -431,14 +431,14 @@ fn simd_operand(
|
||||
format: Format,
|
||||
scalar: bool,
|
||||
frac_bits: u8,
|
||||
) -> Result<Operand, ()> {
|
||||
) -> Result<Operand, Unsupported> {
|
||||
let shape = if scalar {
|
||||
Shape::Scalar
|
||||
} else {
|
||||
vector_shape(word)
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let destination = vector_register(word, 0);
|
||||
let source = vector_register(word, SOURCE_SHIFT);
|
||||
@@ -598,7 +598,7 @@ mod tests {
|
||||
| (source_field << FORMAT_SHIFT)
|
||||
| (destination_field << DESTINATION_FORMAT_SHIFT);
|
||||
if source == destination {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
} else {
|
||||
precision(
|
||||
word,
|
||||
@@ -800,7 +800,7 @@ mod tests {
|
||||
for wide in [0, GENERAL_WIDE] {
|
||||
assert_eq!(
|
||||
decode(opcode | signed | wide | (FORMAT_RESERVED << FORMAT_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -813,21 +813,24 @@ mod tests {
|
||||
decode(
|
||||
opcode | signed | (field << FORMAT_SHIFT) | (scale << SCALE_SHIFT)
|
||||
),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
for wide in [0, GENERAL_WIDE] {
|
||||
assert_eq!(
|
||||
decode(opcode | signed | wide | (FORMAT_RESERVED << FORMAT_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (opcode, _) in SIMD_OPERATIONS {
|
||||
for signed in [0, SIMD_UNSIGNED] {
|
||||
assert_eq!(decode(opcode | signed | SIMD_DOUBLE), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(opcode | signed | SIMD_DOUBLE),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
for opcode in [SIMD_FIXED_SCVTF, SIMD_FIXED_FCVTZS] {
|
||||
@@ -842,14 +845,14 @@ mod tests {
|
||||
for immediate in IMMEDIATE_SHIFT_CLASS_MINIMUM..IMMEDIATE_HALF_MINIMUM {
|
||||
assert_eq!(
|
||||
decode(opcode | signed | prefix | (immediate << IMMEDIATE_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
for immediate in IMMEDIATE_DOUBLE_MINIMUM..=IMMEDIATE_MASK {
|
||||
assert_eq!(
|
||||
decode(opcode | signed | (immediate << IMMEDIATE_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -861,7 +864,7 @@ mod tests {
|
||||
| (FORMAT_RESERVED << FORMAT_SHIFT)
|
||||
| (destination << DESTINATION_FORMAT_SHIFT)
|
||||
),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -890,7 +893,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn modified_immediates_keep_their_existing_decoder_and_compiler_paths() {
|
||||
use crate::{GuestAddress, Lifter, aarch64, block};
|
||||
use crate::{GuestAddress, Lifter, aarch64};
|
||||
|
||||
const MODIFIED_IMMEDIATE: u32 = 0x0f000400;
|
||||
const CMODE_SHIFT: u32 = 12;
|
||||
@@ -941,11 +944,11 @@ mod tests {
|
||||
let mut source = word.to_le_bytes().to_vec();
|
||||
source.extend(RETURN_X30.to_le_bytes());
|
||||
assert!(
|
||||
crate::compile(&source, BASE).is_ok(),
|
||||
crate::testing::leaf(&source, BASE).is_ok(),
|
||||
"word={word:08x}"
|
||||
);
|
||||
assert!(
|
||||
block::compile(&source, BASE).is_ok(),
|
||||
crate::testing::block(&source, BASE).is_ok(),
|
||||
"word={word:08x}"
|
||||
);
|
||||
compiled += 1;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FRECPE, FRSQRTE and FRECPX.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::Format;
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -67,8 +68,7 @@ fn vector_shape(word: u32) -> Shape {
|
||||
|
||||
/// None denotes another family; Err denotes floating vector1D or unsigned sz1.
|
||||
/// FRECPX is scalar only. All registers, including V31, are ordinary vector data.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let unsigned = match word & VECTOR_MASK {
|
||||
URECPE => Some(Kind::UnsignedReciprocal),
|
||||
URSQRTE => Some(Kind::UnsignedReciprocalSquareRoot),
|
||||
@@ -76,7 +76,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
if let Some(kind) = unsigned {
|
||||
if word & DOUBLE_SIZE != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(operand(word, kind, Format::Single, vector_shape(word))));
|
||||
}
|
||||
@@ -110,7 +110,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
vector_shape(word)
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(operand(word, kind, format, shape)));
|
||||
}
|
||||
@@ -176,7 +176,7 @@ mod tests {
|
||||
continue;
|
||||
}
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
continue;
|
||||
}
|
||||
check_registers(word, kind, format, shape);
|
||||
@@ -202,7 +202,7 @@ mod tests {
|
||||
decode(
|
||||
opcode | q | DOUBLE_SIZE | destination | (source << SOURCE_SHIFT)
|
||||
),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ mod tests {
|
||||
for source in 0..=REGISTER_MASK {
|
||||
assert_eq!(
|
||||
decode(opcode | DOUBLE_SIZE | destination | (source << SOURCE_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! AdvSIMD FAMIN/FAMAX (FEAT_FAMINMAX) and FSCALE (FEAT_FP8).
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, absolute_minmax::AbsoluteMinMaxOperation};
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -35,8 +36,7 @@ pub struct Operand {
|
||||
|
||||
/// V31 is ordinary data in every position. Q=0 writes clear the upper 64 bits.
|
||||
/// The one-double arrangement is reserved; scalar/pairwise neighbors decline.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
for (mask, half) in [(HALF_MASK, true), (ORDINARY_MASK, false)] {
|
||||
let kind = match (word & mask, half) {
|
||||
(HALF_FAMAX, true) | (FAMAX, false) => Kind::Absolute(AbsoluteMinMaxOperation::Maximum),
|
||||
@@ -57,7 +57,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
Shape::Vector128
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand {
|
||||
kind,
|
||||
@@ -109,7 +109,7 @@ mod tests {
|
||||
let word =
|
||||
base | q | destination | (left << LEFT_SHIFT) | (right << RIGHT_SHIFT);
|
||||
let expected = if format == Format::Double && shape == Shape::Vector64 {
|
||||
Err(())
|
||||
Err(Unsupported)
|
||||
} else {
|
||||
Ok(Operand {
|
||||
kind,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FCSEL, FABS and FNEG, including FPCR.AH/NEP behavior.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SignOperation {
|
||||
@@ -37,17 +38,16 @@ const VECTOR_FLOAT_MASK: u32 = 0xbfbf_fc00;
|
||||
const VECTOR_FLOAT_ABS: u32 = 0x0ea0_f800;
|
||||
const VECTOR_FLOAT_NEG: u32 = 0x2ea0_f800;
|
||||
|
||||
fn scalar_lane(word: u32) -> Result<u8, ()> {
|
||||
fn scalar_lane(word: u32) -> Result<u8, Unsupported> {
|
||||
match (word >> 22) & 3 {
|
||||
0 => Ok(4),
|
||||
1 => Ok(8),
|
||||
3 => Ok(2),
|
||||
_ => Err(()),
|
||||
_ => Err(Unsupported),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let destination = (word & 31) as u8;
|
||||
let source = ((word >> 5) & 31) as u8;
|
||||
if word & SELECT_MASK == SELECT {
|
||||
@@ -92,7 +92,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
4 << ((word >> 22) & 1)
|
||||
};
|
||||
if lane_bytes == 8 && bytes == 8 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand::Sign {
|
||||
operation,
|
||||
@@ -143,10 +143,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
for base in [SELECT, SCALAR_ABS, SCALAR_NEG] {
|
||||
assert_eq!(decode(base | (2 << 22)), Some(Err(())));
|
||||
assert_eq!(decode(base | (2 << 22)), Some(Err(Unsupported)));
|
||||
}
|
||||
for base in [VECTOR_FLOAT_ABS, VECTOR_FLOAT_NEG] {
|
||||
assert_eq!(decode(base | (1 << 22)), Some(Err(())));
|
||||
assert_eq!(decode(base | (1 << 22)), Some(Err(Unsupported)));
|
||||
assert!(matches!(
|
||||
decode(base | (1 << 22) | (1 << 30)),
|
||||
Some(Ok(Operand::Sign {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FMADD/FMSUB/FNMADD/FNMSUB and AdvSIMD FMLA/FMLS.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, fused::FusedOperation};
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -58,8 +59,7 @@ pub struct Operand {
|
||||
|
||||
/// None is another family; Err is reserved scalar ftype, vector 1D or indexed D/L.
|
||||
/// Register fields denote ordinary V registers; indexed H permits only V0–V15.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
decode_scalar(word)
|
||||
.or_else(|| decode_vector(word))
|
||||
.or_else(|| decode_indexed(word))
|
||||
@@ -77,7 +77,7 @@ fn vector_shape(word: u32) -> Shape {
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_scalar(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let operation = match word & SCALAR_MASK {
|
||||
FMADD => FusedOperation::Add,
|
||||
FMSUB => FusedOperation::Subtract,
|
||||
@@ -89,7 +89,7 @@ fn decode_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
FORMAT_SINGLE => Format::Single,
|
||||
FORMAT_DOUBLE => Format::Double,
|
||||
FORMAT_HALF => Format::Half,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
operation,
|
||||
@@ -103,7 +103,7 @@ fn decode_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_vector(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let half_operation = match word & VECTOR_HALF_MASK {
|
||||
VECTOR_HALF_FMLA => Some(FusedOperation::Add),
|
||||
VECTOR_HALF_FMLS => Some(FusedOperation::Subtract),
|
||||
@@ -122,7 +122,7 @@ fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
Format::Single
|
||||
} else {
|
||||
if shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Format::Double
|
||||
};
|
||||
@@ -141,7 +141,7 @@ fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_indexed(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_indexed(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (half, shape) = if word & INDEXED_SCALAR_HALF_MASK == INDEXED_SCALAR_HALF {
|
||||
(true, Shape::Scalar)
|
||||
} else if word & INDEXED_SCALAR_MASK == INDEXED_SCALAR {
|
||||
@@ -170,7 +170,7 @@ fn decode_indexed(word: u32) -> Option<Result<Operand, ()>> {
|
||||
)
|
||||
} else {
|
||||
if low != 0 || shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
(Format::Double, register(word, RIGHT_SHIFT), high)
|
||||
};
|
||||
@@ -229,7 +229,7 @@ mod tests {
|
||||
| (addend << ADDEND_SHIFT)
|
||||
| (left << LEFT_SHIFT)
|
||||
| destination;
|
||||
let expected = format.map_or(Err(()), |format| {
|
||||
let expected = format.map_or(Err(Unsupported), |format| {
|
||||
Ok(Operand {
|
||||
operation,
|
||||
format,
|
||||
@@ -272,7 +272,7 @@ mod tests {
|
||||
| destination;
|
||||
let expected =
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
Err(())
|
||||
Err(Unsupported)
|
||||
} else {
|
||||
Ok(Operand {
|
||||
operation,
|
||||
@@ -347,7 +347,7 @@ mod tests {
|
||||
let expected = if format == Format::Double
|
||||
&& (l != 0 || shape == Shape::Vector64)
|
||||
{
|
||||
Err(())
|
||||
Err(Unsupported)
|
||||
} else {
|
||||
Ok(Operand {
|
||||
operation,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Halving arithmetic (SHADD, URHADD, ...), narrowing and pairwise widening.
|
||||
use crate::aarch64::Unsupported;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Kind {
|
||||
Half {
|
||||
@@ -51,8 +52,7 @@ const UNSIGNED_ACC_PAIR_LONG: u32 = 0x2e206800;
|
||||
const TRUNCATE: u32 = 0x0e212800;
|
||||
const SHIFT_LONG: u32 = 0x2e213800;
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let q = word & (1 << 30) != 0;
|
||||
let opcode = word & SAME_MASK;
|
||||
let kind = match opcode {
|
||||
@@ -88,7 +88,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
})?;
|
||||
let size = (word >> 22) & 3;
|
||||
if size == 3 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let bytes = if matches!(kind, Kind::HighNarrow { .. } | Kind::Truncate { .. })
|
||||
|| (!q && !matches!(kind, Kind::ShiftLong { .. }))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! FEAT_I8MM: SMMLA, UMMLA, USMMLA, USDOT and SUDOT.
|
||||
use super::arithmetic::Shape;
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
const DESTINATION_SHIFT: u32 = 0;
|
||||
@@ -115,8 +116,7 @@ impl Encoding {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (_, _, kind, indexed) = Encoding::ALL
|
||||
.iter()
|
||||
.map(|encoding| encoding.facts())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Modified immediates (MOVI, MVNI, ORR, BIC, FMOV) and FP register moves.
|
||||
use super::super::register;
|
||||
use super::rearrange::{LaneSource, Operand as LaneMove};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ConstantOperation {
|
||||
@@ -58,8 +59,7 @@ fn float_immediate(imm: u8, bytes: u8) -> u64 {
|
||||
| (u64::from(imm & 15) << (fraction_bits - 4))
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let d = (word & 31) as u8;
|
||||
let n = ((word >> 5) & 31) as u8;
|
||||
let scalar_float = match word & SCALAR_FLOAT_MASK {
|
||||
@@ -145,7 +145,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let bytes = if q { 16 } else { 8 };
|
||||
if half {
|
||||
if op || cmode != 15 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Constant {
|
||||
destination: d,
|
||||
@@ -159,7 +159,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
} // Existing D/2D MOVI byte-mask lowering.
|
||||
if cmode == 15 {
|
||||
if op && !q {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let lane = if op { 8 } else { 4 };
|
||||
return Some(Ok(Operand::Constant {
|
||||
@@ -219,7 +219,7 @@ mod tests {
|
||||
}))
|
||||
);
|
||||
}
|
||||
assert_eq!(decode(0x2f00f400), Some(Err(()))); // vector double requires Q=1
|
||||
assert_eq!(decode(0x2f00f400), Some(Err(Unsupported))); // vector double requires Q=1
|
||||
assert!(decode(0x1ea01000).is_none()); // reserved scalar ftype
|
||||
assert!(decode(0x9e260000).is_none()); // numerical conversion is not a bit move
|
||||
}
|
||||
@@ -231,7 +231,7 @@ mod tests {
|
||||
if cmode == 14 && op == 1 {
|
||||
assert!(decode(word).is_none());
|
||||
} else if cmode == 15 && op == 1 {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
} else {
|
||||
assert!(decode(word).unwrap().is_ok());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SIMD/FP register-offset loads and stores.
|
||||
use super::super::{Register, register, register_offset::IndexExtend};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const REGISTER_OFFSET_MASK: u32 = 0x3f20_0c00;
|
||||
const REGISTER_OFFSET_CLASS: u32 = 0x3c20_0800;
|
||||
@@ -28,8 +29,7 @@ pub struct Operand {
|
||||
}
|
||||
|
||||
/// None is a different class; Err is an undefined size or index extension.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & REGISTER_OFFSET_MASK != REGISTER_OFFSET_CLASS {
|
||||
return None;
|
||||
}
|
||||
@@ -37,14 +37,14 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let opcode = (word >> OPCODE_SHIFT) & OPCODE_MASK;
|
||||
let scale = if opcode & Q_OPCODE_BIT != 0 {
|
||||
if size != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Q_SCALE
|
||||
} else {
|
||||
size
|
||||
};
|
||||
let Some(extend) = IndexExtend::decode((word >> EXTENSION_SHIFT) & EXTENSION_MASK) else {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
load: opcode & LOAD_OPCODE_BIT != 0,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
//! FP min/max: scalar, vector, pairwise and across-lane forms.
|
||||
use super::scalar_format;
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, minmax::MinMaxOperation};
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -6,11 +8,6 @@ use super::arithmetic::Shape;
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
const LEFT_SHIFT: u32 = 5;
|
||||
const RIGHT_SHIFT: u32 = 16;
|
||||
const FORMAT_SHIFT: u32 = 22;
|
||||
const FORMAT_MASK: u32 = 3;
|
||||
const FORMAT_SINGLE: u32 = 0;
|
||||
const FORMAT_DOUBLE: u32 = 1;
|
||||
const FORMAT_HALF: u32 = 3;
|
||||
const VECTOR_Q: u32 = 1 << 30;
|
||||
const SIMD_DOUBLE: u32 = 1 << 22;
|
||||
const VECTOR_PAIRWISE: u32 = 1 << 29;
|
||||
@@ -102,15 +99,6 @@ fn register(word: u32, shift: u32) -> u8 {
|
||||
((word >> shift) & REGISTER_MASK) as u8
|
||||
}
|
||||
|
||||
fn scalar_format(word: u32) -> Result<Format, ()> {
|
||||
match (word >> FORMAT_SHIFT) & FORMAT_MASK {
|
||||
FORMAT_SINGLE => Ok(Format::Single),
|
||||
FORMAT_DOUBLE => Ok(Format::Double),
|
||||
FORMAT_HALF => Ok(Format::Half),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
fn vector_shape(word: u32) -> Shape {
|
||||
if word & VECTOR_Q == 0 {
|
||||
Shape::Vector64
|
||||
@@ -122,15 +110,14 @@ fn vector_shape(word: u32) -> Shape {
|
||||
/// None denotes another family; Err denotes reserved scalar ftype, vector1D,
|
||||
/// half scalar-pair size or ordinary reduction size/Q. Registers denote V31
|
||||
/// normally; pairwise scalar H consumes only the source's first two H lanes.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
decode_scalar(word)
|
||||
.or_else(|| decode_vector(word))
|
||||
.or_else(|| decode_pairwise_scalar(word))
|
||||
.or_else(|| decode_reduction(word))
|
||||
}
|
||||
|
||||
fn decode_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_scalar(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let operation = match word & SCALAR_MASK {
|
||||
SCALAR_FMAX => MinMaxOperation::Maximum,
|
||||
SCALAR_FMIN => MinMaxOperation::Minimum,
|
||||
@@ -159,7 +146,7 @@ fn vector_operation(opcode: u32) -> Option<MinMaxOperation> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_vector(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
for (mask, adjustment, half) in [
|
||||
(VECTOR_MASK, 0, false),
|
||||
(VECTOR_HALF_MASK, HALF_REGISTER_ADJUSTMENT, true),
|
||||
@@ -176,7 +163,7 @@ fn decode_vector(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
let shape = vector_shape(word);
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Binary {
|
||||
operation,
|
||||
@@ -205,13 +192,13 @@ fn pair_operation(opcode: u32) -> Option<MinMaxOperation> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_pairwise_scalar(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_pairwise_scalar(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
for (adjustment, half) in [(0, false), (HALF_PAIR_ADJUSTMENT, true)] {
|
||||
let Some(operation) = pair_operation((word & PAIR_SCALAR_MASK) ^ adjustment) else {
|
||||
continue;
|
||||
};
|
||||
if half && word & SIMD_DOUBLE != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let format = if half {
|
||||
Format::Half
|
||||
@@ -240,7 +227,7 @@ fn reduction_operation(opcode: u32) -> Option<MinMaxOperation> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_reduction(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_reduction(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
for (mask, adjustment, half) in [
|
||||
(REDUCTION_MASK, 0, false),
|
||||
(REDUCTION_HALF_MASK, HALF_PAIR_ADJUSTMENT, true),
|
||||
@@ -249,7 +236,7 @@ fn decode_reduction(word: u32) -> Option<Result<Operand, ()>> {
|
||||
continue;
|
||||
};
|
||||
if !half && (word & SIMD_DOUBLE != 0 || word & VECTOR_Q == 0) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Reduction {
|
||||
operation,
|
||||
@@ -265,6 +252,7 @@ fn decode_reduction(word: u32) -> Option<Result<Operand, ()>> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::aarch64::simd::{FORMAT_DOUBLE, FORMAT_HALF, FORMAT_SHIFT, FORMAT_SINGLE};
|
||||
|
||||
const SCALAR_OPERATIONS: [(u32, MinMaxOperation); 4] = [
|
||||
(SCALAR_FMAX, MinMaxOperation::Maximum),
|
||||
@@ -466,24 +454,27 @@ mod tests {
|
||||
for (opcode, _) in SCALAR_OPERATIONS {
|
||||
assert_eq!(
|
||||
decode(opcode | (RESERVED_FORMAT << FORMAT_SHIFT)),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
for (opcode, _) in VECTOR_OPERATIONS {
|
||||
for pairwise in [0, VECTOR_PAIRWISE] {
|
||||
assert_eq!(decode(opcode | SIMD_DOUBLE | pairwise), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(opcode | SIMD_DOUBLE | pairwise),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
for (opcode, _) in PAIR_OPERATIONS {
|
||||
assert_eq!(
|
||||
decode((opcode ^ HALF_PAIR_ADJUSTMENT) | SIMD_DOUBLE),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
for (opcode, _) in REDUCTION_OPERATIONS {
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
for q in [0, VECTOR_Q] {
|
||||
assert_eq!(decode(opcode | SIMD_DOUBLE | q), Some(Err(())));
|
||||
assert_eq!(decode(opcode | SIMD_DOUBLE | q), Some(Err(Unsupported)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Integer multiplies and widening arithmetic (MUL, MLA, SMULL, UADDL, ...).
|
||||
use crate::aarch64::Unsupported;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Accumulate {
|
||||
None,
|
||||
@@ -100,8 +101,7 @@ encodings! {
|
||||
Uabal => (0x2e205000,Difference {signed:false,widen:true,accumulate:true}),
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if let Some(decoded) = decode_dot(word) {
|
||||
return Some(decoded);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
.find(|(value, _)| *value == opcode)?;
|
||||
let size = (word >> 22) & 3;
|
||||
if size == 3 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let q = word & (1 << 30) != 0;
|
||||
let widen = kind.widened();
|
||||
@@ -181,15 +181,14 @@ impl IndexedProductEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
fn decode_indexed_product(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_indexed_product(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (_, kind) = IndexedProductEncoding::ALL
|
||||
.iter()
|
||||
.map(|e| e.facts())
|
||||
.find(|(opcode, _)| word & 0xbf00f400 == *opcode)?;
|
||||
let size = (word >> 22) & 3;
|
||||
if !matches!(size, 1 | 2) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let q = word & (1 << 30) != 0;
|
||||
let h = ((word >> 11) & 1) as u8;
|
||||
@@ -292,8 +291,7 @@ impl DotEncoding {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
fn decode_dot(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_dot(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
const REGISTER_MASK: u32 = 0xbf20fc00;
|
||||
const INDEXED_MASK: u32 = 0xbf00f400;
|
||||
const DWORD_SIZE: u32 = 2;
|
||||
@@ -304,7 +302,7 @@ fn decode_dot(word: u32) -> Option<Result<Operand, ()>> {
|
||||
word & REGISTER_MASK == *register || word & INDEXED_MASK == *indexed
|
||||
})?;
|
||||
if (word >> 22) & 3 != DWORD_SIZE {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
kind: Kind::Dot { signed },
|
||||
@@ -318,8 +316,7 @@ fn decode_dot(word: u32) -> Option<Result<Operand, ()>> {
|
||||
.then_some((((word >> 11) & 1) << 1 | ((word >> 21) & 1)) as u8),
|
||||
}))
|
||||
}
|
||||
#[allow(clippy::result_unit_err)]
|
||||
fn decode_special(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_special(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let scalar = word & (1 << 28) != 0;
|
||||
let q = word & (1 << 30) != 0;
|
||||
let normalized = word & !(1 << 28);
|
||||
@@ -329,12 +326,12 @@ fn decode_special(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let kind =
|
||||
if !scalar && word & 0xbf20fc00 == PolynomialEncoding::Multiply.opcode() {
|
||||
if size != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Kind::Polynomial { widen: false }
|
||||
} else if !scalar && word & 0xbf20fc00 == PolynomialEncoding::MultiplyLong.opcode() {
|
||||
if size != 0 && size != 3 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Kind::Polynomial { widen: true }
|
||||
} else {
|
||||
@@ -344,7 +341,7 @@ fn decode_special(word: u32) -> Option<Result<Operand, ()>> {
|
||||
},
|
||||
)?;
|
||||
if !matches!(size, 1 | 2) || scalar && !q {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
if normalized & 0xbf00f400 == indexed {
|
||||
let h = ((word >> 11) & 1) as u8;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Lane movement and permutes: DUP, INS, SMOV, UMOV, EXT, REV16/32/64,
|
||||
//! ZIP/UZP/TRN, TBL and TBX.
|
||||
use super::super::{Register, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum LaneSource {
|
||||
@@ -77,8 +78,7 @@ encodings! {
|
||||
Table => (0xbfe08c00, 0x0e000000),
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
use Encoding::*;
|
||||
let d = (word & 31) as u8;
|
||||
let n = ((word >> 5) & 31) as u8;
|
||||
@@ -99,7 +99,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
{
|
||||
let imm5 = ((word >> 16) & 31) as u8;
|
||||
if imm5 & 15 == 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let size = (imm5 & 15).trailing_zeros();
|
||||
let lane_bytes = 1 << size;
|
||||
@@ -107,7 +107,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
if SignedMove.matches(word) || UnsignedMove.matches(word) {
|
||||
let signed = SignedMove.matches(word);
|
||||
if (signed && lane_bytes >= (4 << q)) || (!signed && ((q == 1) != (lane_bytes == 8))) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Extract {
|
||||
destination: register(u32::from(d), false),
|
||||
@@ -141,7 +141,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}
|
||||
let scalar = DupScalar.matches(word);
|
||||
if !scalar && q == 0 && lane_bytes == 8 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand::Duplicate {
|
||||
destination: d,
|
||||
@@ -164,7 +164,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
if ExtractBytes.matches(word) {
|
||||
let offset = ((word >> 11) & 15) as u8;
|
||||
if offset >= bytes {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
for i in 0..bytes {
|
||||
let source = i + offset;
|
||||
@@ -187,7 +187,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
let lane = 1 << ((word >> 22) & 3);
|
||||
if lane >= container {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
for i in 0..bytes {
|
||||
selection[usize::from(i)] =
|
||||
@@ -200,7 +200,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
{
|
||||
let lane = 1 << ((word >> 22) & 3);
|
||||
if lane == 8 && q == 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let elements = bytes / lane;
|
||||
let part = ((word >> 14) & 1) as u8;
|
||||
@@ -258,8 +258,8 @@ mod tests {
|
||||
}
|
||||
// INS ignores low imm4 bits below the selected element size.
|
||||
assert_eq!(decode(0x6e080400), decode(0x6e083c00));
|
||||
assert_eq!(decode(0x2e004000), Some(Err(()))); // EXT 8B offset 8
|
||||
assert_eq!(decode(0x0e601800), Some(Err(()))); // REV16 halfword
|
||||
assert_eq!(decode(0x2e004000), Some(Err(Unsupported))); // EXT 8B offset 8
|
||||
assert_eq!(decode(0x0e601800), Some(Err(Unsupported))); // REV16 halfword
|
||||
assert!(decode(0x0e800000).is_none()); // adjacent table fixed bit
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Integer across-lane reductions, pairwise combines and per-lane bit counts.
|
||||
use crate::aarch64::Unsupported;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Combine {
|
||||
Add,
|
||||
@@ -62,8 +63,7 @@ encodings! {
|
||||
Not => (0xbffffc00,0x2e205800),
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
use Encoding::*;
|
||||
let q = word & (1 << 30) != 0;
|
||||
let size = ((word >> 22) & 3) as u8;
|
||||
@@ -97,7 +97,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
if (kind == BitCount::Population && size != 0)
|
||||
|| (matches!(kind, BitCount::LeadingZeros | BitCount::LeadingSign) && size == 3)
|
||||
{
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
if matches!(kind, BitCount::Reverse | BitCount::Not) {
|
||||
operand.lane_bytes = 1;
|
||||
@@ -177,7 +177,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
if (size == 3 && !(operation == Combine::Add && shape == Shape::Pairs && q))
|
||||
|| (shape == Shape::Across && size == 2 && !q)
|
||||
{
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
operand.kind = Kind::Combine { operation, shape };
|
||||
Some(Ok(operand))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FRECPS and FRSQRTS.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::Format;
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -43,8 +44,7 @@ fn kind(opcode: u32) -> Option<Kind> {
|
||||
|
||||
/// None denotes another family; Err denotes reserved vector1D. Every register
|
||||
/// field is ordinary V data, including V31 and all source/destination aliases.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
for (mask, adjustment, scalar, half) in [
|
||||
(SCALAR_MASK, SCALAR_PREFIX, true, false),
|
||||
(VECTOR_MASK, 0, false, false),
|
||||
@@ -74,7 +74,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
Shape::Vector128
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return Some(Ok(Operand {
|
||||
kind,
|
||||
@@ -111,7 +111,7 @@ mod tests {
|
||||
] {
|
||||
let word = (opcode ^ size) | prefix;
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
continue;
|
||||
}
|
||||
for destination in 0..=REGISTER_MASK {
|
||||
@@ -157,7 +157,7 @@ mod tests {
|
||||
| (left << LEFT_SHIFT)
|
||||
| (right << RIGHT_SHIFT)
|
||||
),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Scalar and AdvSIMD FRINT*.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, rounding::RoundingOperation};
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -86,14 +87,13 @@ fn vector_operation(opcode: u32) -> Option<RoundingOperation> {
|
||||
|
||||
/// None denotes another family; Err denotes reserved scalar ftype, bounded H
|
||||
/// or vector1D. Every register field denotes ordinary V data, including V31.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (operation, format, shape) = if let Some(operation) = scalar_operation(word & SCALAR_MASK) {
|
||||
let format = match (word >> FORMAT_SHIFT) & FORMAT_MASK {
|
||||
FORMAT_SINGLE => Format::Single,
|
||||
FORMAT_DOUBLE => Format::Double,
|
||||
FORMAT_HALF if operation.signed_width().is_none() => Format::Half,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
(operation, format, Shape::Scalar)
|
||||
} else {
|
||||
@@ -119,7 +119,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
Shape::Vector128
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
(operation, format, shape)
|
||||
};
|
||||
@@ -207,7 +207,10 @@ mod tests {
|
||||
(FORMAT_HALF, Format::Half),
|
||||
] {
|
||||
if format == Format::Half && operation.signed_width().is_some() {
|
||||
assert_eq!(decode(scalar | (field << FORMAT_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(scalar | (field << FORMAT_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
continue;
|
||||
}
|
||||
check_registers(
|
||||
@@ -238,7 +241,7 @@ mod tests {
|
||||
continue;
|
||||
}
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
continue;
|
||||
}
|
||||
check_registers(word, operation, format, shape);
|
||||
@@ -258,13 +261,16 @@ mod tests {
|
||||
let registers = destination | (source << SOURCE_SHIFT);
|
||||
assert_eq!(
|
||||
decode(scalar | (RESERVED_FORMAT << FORMAT_SHIFT) | registers),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
assert_eq!(
|
||||
decode(vector | VECTOR_DOUBLE | registers),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
assert_eq!(decode(vector | VECTOR_DOUBLE | registers), Some(Err(())));
|
||||
if operation.signed_width().is_some() {
|
||||
assert_eq!(
|
||||
decode(scalar | (FORMAT_HALF << FORMAT_SHIFT) | registers),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Saturating integer arithmetic, which sets FPSR.QC.
|
||||
use crate::aarch64::Unsupported;
|
||||
/// Architectural cumulative saturation bit; unrelated FPSR bits stay unchanged.
|
||||
pub use crate::aarch64::floating::FPSR_QC;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -47,8 +48,7 @@ const SIGNED_NARROW: u32 = 0x0e214800;
|
||||
const UNSIGNED_NARROW: u32 = 0x2e214800;
|
||||
const SIGNED_TO_UNSIGNED_NARROW: u32 = 0x2e212800;
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let scalar = word & SCALAR != 0;
|
||||
let q = word & Q != 0;
|
||||
let normalized = word & !SCALAR;
|
||||
@@ -91,7 +91,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let lane_bytes = 1 << ((word >> 22) & 3);
|
||||
let narrow = matches!(kind, Kind::Narrow { .. });
|
||||
if (narrow && lane_bytes == 8) || (!narrow && !scalar && !q && lane_bytes == 8) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
kind,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! EOR3, BCAX, RAX1 and XAR.
|
||||
use crate::aarch64::Unsupported;
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
const DESTINATION_SHIFT: u32 = 0;
|
||||
const LEFT_SHIFT: u32 = 5;
|
||||
@@ -58,8 +59,7 @@ impl Encoding {
|
||||
|
||||
/// Every register and immediate within the four exact fixed-bit masks is valid.
|
||||
/// Same-named SVE forms remain another encoding class and receive no support here.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = Encoding::ALL.iter().copied().find(|encoding| {
|
||||
let (mask, value) = encoding.facts();
|
||||
word & mask == value
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SHA512H, SHA512H2, SHA512SU0 and SHA512SU1.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Kind {
|
||||
@@ -30,8 +31,7 @@ const RIGHT_SHIFT: u32 = 16;
|
||||
|
||||
/// Exact allocated forms only: all register aliases are legal and no size/Q
|
||||
/// variants exist. Other members of the crypto classes belong to other families.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let kind = if word & TWO_REGISTER_MASK == SCHEDULE0 {
|
||||
Kind::Schedule0
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! AdvSIMD shifts by immediate and register: same-width, narrowing and widening.
|
||||
use crate::aarch64::Unsupported;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Kind {
|
||||
Register {
|
||||
@@ -86,8 +87,7 @@ const ROUND_NARROW: u32 = 1 << 11;
|
||||
const SHIFT_WIDEN_SIGNED: u32 = 0x0f00a400;
|
||||
const SHIFT_WIDEN_UNSIGNED: u32 = 0x2f00a400;
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let scalar = word & SCALAR != 0;
|
||||
let q = word & Q != 0;
|
||||
if let Some(result) = decode_register(word, scalar, q) {
|
||||
@@ -164,7 +164,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
|| (changes_width && lane_bytes == 8)
|
||||
|| (!scalar && !changes_width && !q && lane_bytes == 8)
|
||||
{
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let bits = lane_bytes * 8;
|
||||
let amount = if matches!(
|
||||
@@ -191,7 +191,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn decode_register(word: u32, scalar: bool, q: bool) -> Option<Result<Operand, ()>> {
|
||||
fn decode_register(word: u32, scalar: bool, q: bool) -> Option<Result<Operand, Unsupported>> {
|
||||
let opcode = (word & !SCALAR) & REGISTER_SHIFT_MASK;
|
||||
if ![
|
||||
REGISTER_SHIFT_SIGNED,
|
||||
@@ -210,7 +210,7 @@ fn decode_register(word: u32, scalar: bool, q: bool) -> Option<Result<Operand, (
|
||||
let saturating = word & (1 << 11) != 0;
|
||||
let lane_bytes = 1 << ((word >> 22) & 3);
|
||||
if (scalar && (!q || (!saturating && lane_bytes != 8))) || (!scalar && !q && lane_bytes == 8) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
kind: Kind::Register {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Scalar and AdvSIMD FSQRT.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::Format;
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -29,14 +30,13 @@ pub struct Operand {
|
||||
|
||||
/// None denotes another family; Err denotes reserved scalar ftype or vector1D.
|
||||
/// Every register field denotes ordinary V data, including V31.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (format, shape) = if word & SCALAR_MASK == SCALAR_FSQRT {
|
||||
let format = match (word >> FORMAT_SHIFT) & FORMAT_MASK {
|
||||
FORMAT_SINGLE => Format::Single,
|
||||
FORMAT_DOUBLE => Format::Double,
|
||||
FORMAT_HALF => Format::Half,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
(format, Shape::Scalar)
|
||||
} else {
|
||||
@@ -57,7 +57,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
Shape::Vector128
|
||||
};
|
||||
if format == Format::Double && shape == Shape::Vector64 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
(format, shape)
|
||||
};
|
||||
@@ -124,11 +124,11 @@ mod tests {
|
||||
let registers = destination | (source << SOURCE_SHIFT);
|
||||
assert_eq!(
|
||||
decode(SCALAR_FSQRT | (FORMAT_RESERVED << FORMAT_SHIFT) | registers),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
assert_eq!(
|
||||
decode(VECTOR_FSQRT | VECTOR_DOUBLE | registers),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Structured AdvSIMD loads and stores (LD1-4, ST1-4, LD1R-4R), in architectural
|
||||
//! access order, with post-index writeback.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::{Register, register};
|
||||
|
||||
mod multiple;
|
||||
@@ -135,8 +136,7 @@ fn decode_addressing(word: u32) -> (Register, PostIndex) {
|
||||
(base, post_index)
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
multiple::decode(word).or_else(|| single::decode(word))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! LD1-4 and ST1-4 (multiple structures).
|
||||
use super::{Direction, Layout, Operand, decode_addressing};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const CLASS_MASK: u32 = 0xbf20_0000;
|
||||
const CLASS: u32 = 0x0c00_0000;
|
||||
@@ -21,12 +22,12 @@ const TWO_STRUCTURES: u32 = 0b1000;
|
||||
const TWO_REGISTERS: u32 = 0b1010;
|
||||
|
||||
/// None denotes a different instruction class; Err denotes a reserved encoding.
|
||||
pub(super) fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub(super) fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & CLASS_MASK != CLASS {
|
||||
return None;
|
||||
}
|
||||
if word & POST_INDEX_BIT == 0 && word & INDEX_MASK != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let (repetitions, structures) = match (word >> OPCODE_SHIFT) & OPCODE_MASK {
|
||||
FOUR_STRUCTURES => (1, 4),
|
||||
@@ -36,12 +37,12 @@ pub(super) fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
ONE_REGISTER => (1, 1),
|
||||
TWO_STRUCTURES => (1, 2),
|
||||
TWO_REGISTERS => (2, 1),
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let size = (word >> SIZE_SHIFT) & SIZE_MASK;
|
||||
let vector_bytes = if word & Q_BIT == 0 { 8 } else { 16 };
|
||||
if structures != 1 && vector_bytes == 8 && size == SIZE_MASK {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let (base, post_index) = decode_addressing(word);
|
||||
Some(Ok(Operand {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! LD1-4 and ST1-4 (single lane) and LD1R-4R (replicate).
|
||||
use super::{Direction, Layout, Operand, decode_addressing};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const SINGLE_STRUCTURE_MASK: u32 = 0xbf00_0000;
|
||||
const SINGLE_STRUCTURE_CLASS: u32 = 0x0d00_0000;
|
||||
@@ -21,13 +22,12 @@ const DOUBLEWORD_SCALE: u8 = 3;
|
||||
const LOW_VECTOR_BYTES: u8 = 8;
|
||||
|
||||
/// None denotes a different class; Err denotes a reserved single structure.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub(super) fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub(super) fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & SINGLE_STRUCTURE_MASK != SINGLE_STRUCTURE_CLASS {
|
||||
return None;
|
||||
}
|
||||
if word & POST_INDEX_BIT == 0 && word & OFFSET_REGISTER_MASK != 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let opcode = ((word >> OPCODE_SHIFT) & OPCODE_MASK) as u8;
|
||||
let structures = ((opcode & 1) << 1) + ((word >> STRUCTURE_LOW_BIT_SHIFT) & 1) as u8 + 1;
|
||||
@@ -75,7 +75,7 @@ pub(super) fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
vector_bytes: LOW_VECTOR_BYTES << q,
|
||||
},
|
||||
),
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let (base, post_index) = decode_addressing(word);
|
||||
Some(Ok(Operand {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FMLAL and FMLSL (half to single).
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, widening::WideningOperation};
|
||||
|
||||
use super::arithmetic::Shape;
|
||||
@@ -59,8 +60,7 @@ pub struct Operand {
|
||||
|
||||
/// Exact fixed bits keep sz=1 and adjacent FP8/SME forms outside this family.
|
||||
/// All registers are ordinary V registers; indexed Vm is limited to V0..V15.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (operation, part) = match word & VECTOR_MASK {
|
||||
VECTOR_FMLAL => (WideningOperation::Add, Part::Lower),
|
||||
VECTOR_FMLAL2 => (WideningOperation::Add, Part::Upper),
|
||||
@@ -103,7 +103,7 @@ fn operand(
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_indexed(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_indexed(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (operation, part) = match word & INDEXED_MASK {
|
||||
INDEXED_FMLAL => (WideningOperation::Add, Part::Lower),
|
||||
INDEXED_FMLAL2 => (WideningOperation::Add, Part::Upper),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SME operands. Callers check streaming mode, ZA state and features.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
pub mod extrema_scale;
|
||||
pub mod fp8_conversion;
|
||||
@@ -26,8 +27,7 @@ pub enum Operand {
|
||||
LutV2(lut_v2::Operand),
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if let Some(operand) = lut_v2::decode(word) {
|
||||
return Some(Ok(Operand::LutV2(operand)));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SME2 multi-vector integer arithmetic and narrowing. Saturation does not set
|
||||
//! FPSR.QC.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{BITS_PER_BYTE, ElementSize, VECTOR_REGISTER_COUNT};
|
||||
|
||||
const SIZE_SHIFT: u32 = 22;
|
||||
@@ -668,7 +669,7 @@ fn element(size: u32) -> ElementSize {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
for encoding in &ARITHMETIC_ENCODINGS {
|
||||
if word & encoding.mask != encoding.opcode {
|
||||
continue;
|
||||
@@ -717,7 +718,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
if encoding.rounded_shift {
|
||||
let size = (word >> NARROW_SHIFT_SIZE_SHIFT) & SIZE_MASK;
|
||||
let destination_bits = match size {
|
||||
0 => return Some(Err(())),
|
||||
0 => return Some(Err(Unsupported)),
|
||||
1 => ElementSize::Byte.bits(),
|
||||
_ => ElementSize::Halfword.bits(),
|
||||
} as u8;
|
||||
@@ -871,7 +872,7 @@ mod tests {
|
||||
| (size << NARROW_SHIFT_SIZE_SHIFT)
|
||||
| (immediate << NARROW_IMMEDIATE_SHIFT);
|
||||
if size == 0 {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
continue;
|
||||
}
|
||||
let Operand::Narrow(narrow) = decode(word).unwrap().unwrap() else {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE operands shared by the SVE instruction families.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
pub mod address;
|
||||
pub mod dot;
|
||||
@@ -56,8 +57,7 @@ pub enum Operand {
|
||||
Tables(tables::Operand),
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
tables::decode(word)
|
||||
.map(|operand| operand.map(Operand::Tables))
|
||||
.or_else(|| address::decode(word).map(|operand| operand.map(Operand::Address)))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! ADDVL/ADDPL/RDVL and predicate counts (CNTP, INC/DEC by element count).
|
||||
use super::super::{Register, register, scalable::ElementSize};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const LENGTH_MASK: u32 = 0xffe0_f800;
|
||||
const READ_LENGTH_MASK: u32 = 0xffff_f800;
|
||||
@@ -98,8 +99,7 @@ pub struct Operand {
|
||||
pub kind: Kind,
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let d = word & REGISTER_MASK;
|
||||
let scalar = |bits| Destination::Scalar {
|
||||
register: register(d, false),
|
||||
@@ -160,7 +160,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
),
|
||||
INC_VECTOR | DEC_VECTOR | SQINC_VECTOR | UQINC_VECTOR | SQDEC_VECTOR | UQDEC_VECTOR => {
|
||||
if element == ElementSize::Byte {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let opcode = word & PATTERN_MASK;
|
||||
let subtract = matches!(opcode, DEC_VECTOR | SQDEC_VECTOR | UQDEC_VECTOR);
|
||||
@@ -228,7 +228,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
if matches!(destination, Destination::Vector(_)) && element == ElementSize::Byte
|
||||
{
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
adjust(destination, predicate, subtract, saturation)
|
||||
}
|
||||
@@ -304,7 +304,7 @@ mod tests {
|
||||
SQDECP_VECTOR,
|
||||
UQDECP_VECTOR,
|
||||
] {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SVE integer and complex dot products, half-precision FDOT and widening
|
||||
//! multiply-add. Indexed sources select within each 128-bit segment.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
@@ -364,8 +365,7 @@ const ENCODINGS: &[Encoding] = &[
|
||||
|
||||
/// Feature and execution-mode validation belongs to the enclosing SVE profile.
|
||||
/// These instructions have no predicate operand; every output lane is active.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = ENCODINGS
|
||||
.iter()
|
||||
.find(|encoding| word & encoding.mask == encoding.value)?;
|
||||
@@ -375,7 +375,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
SizeShape::Variable => match (word >> SIZE_SHIFT) & SIZE_MASK {
|
||||
2 => ElementSize::Word,
|
||||
3 => ElementSize::Doubleword,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
},
|
||||
};
|
||||
let kind = if let Kind::Complex { .. } = encoding.kind {
|
||||
@@ -417,13 +417,12 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
|
||||
/// Integer-only admission shares allocation checks with the numerical decoder.
|
||||
/// Half dot and widening arithmetic remain separate numerical operations.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode_integer(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode_integer(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
match decode(word)? {
|
||||
Ok(operand) if matches!(operand.kind, Kind::Integer { .. } | Kind::Complex { .. }) => {
|
||||
Some(Ok(operand))
|
||||
}
|
||||
Err(()) => Some(Err(())),
|
||||
Err(Unsupported) => Some(Err(Unsupported)),
|
||||
Ok(_) => None,
|
||||
}
|
||||
}
|
||||
@@ -451,7 +450,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
const CDOT_RESERVED_BYTE: u32 = 0x4400_1000;
|
||||
assert_eq!(decode_integer(CDOT_RESERVED_BYTE), Some(Err(())));
|
||||
assert_eq!(decode_integer(CDOT_RESERVED_BYTE), Some(Err(Unsupported)));
|
||||
assert_eq!(decode_integer(0), None);
|
||||
}
|
||||
|
||||
@@ -555,7 +554,10 @@ mod tests {
|
||||
#[test]
|
||||
fn complex_reserved_sizes_decline_and_rotations_keep_exact_components() {
|
||||
for size in 0..2 {
|
||||
assert_eq!(decode(0x44001000 | (size << SIZE_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(0x44001000 | (size << SIZE_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
for (rotation, expected) in [
|
||||
(Rotation::Zero, (0, 1, true)),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE floating-point families.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
pub mod arithmetic;
|
||||
pub mod bfloat16;
|
||||
@@ -76,8 +77,7 @@ impl Operation {
|
||||
FeatureRequirement::all(required)
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Self, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Self, Unsupported>> {
|
||||
if let Some(result) = fp8::decode(word) {
|
||||
return Some(result.map(Self::Fp8));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE floating-point arithmetic operands.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::{
|
||||
floating::{
|
||||
BinaryOperation, Format, complex::Rotation, fused::FusedOperation, minmax::MinMaxOperation,
|
||||
@@ -221,16 +222,14 @@ fn core_binary_encoding(encoding: &Encoding) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
decode_encoding(word, matching_encoding(word)?)
|
||||
}
|
||||
|
||||
/// Supported subset: forward predicated ADD/SUB/MUL/DIV and unpredicated
|
||||
/// ADD/SUB/MUL, for H/S/D. The direction comes from the encoding, since
|
||||
/// reversed forms with aliased registers decode to identical operands.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode_core_binary(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode_core_binary(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = matching_encoding(word)?;
|
||||
if !core_binary_encoding(encoding) {
|
||||
return None;
|
||||
@@ -240,8 +239,7 @@ pub fn decode_core_binary(word: u32) -> Option<Result<Operand, ()>> {
|
||||
|
||||
/// Arithmetic decoding uses the shared encoding table; FABS/FNEG keep their own
|
||||
/// decoder and emitter.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode_numerical(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode_numerical(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = matching_encoding(word)?;
|
||||
if matches!(encoding.kind, Kind::Absolute | Kind::Negate) {
|
||||
return None;
|
||||
@@ -249,13 +247,13 @@ pub fn decode_numerical(word: u32) -> Option<Result<Operand, ()>> {
|
||||
decode_encoding(word, encoding)
|
||||
}
|
||||
|
||||
fn decode_encoding(word: u32, encoding: &Encoding) -> Option<Result<Operand, ()>> {
|
||||
fn decode_encoding(word: u32, encoding: &Encoding) -> Option<Result<Operand, Unsupported>> {
|
||||
let format = match encoding.layout {
|
||||
Layout::IndexedBinary(f) | Layout::IndexedFused(f) | Layout::ComplexIndexed(f) => f,
|
||||
Layout::Logb => format(word, LOGB_SIZE_SHIFT)?,
|
||||
Layout::UnsignedEstimate => {
|
||||
if (word >> SIZE_SHIFT) & SIZE_MASK != SINGLE_SIZE_ENCODING {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Format::Single
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SVE BF16 arithmetic, dot products and widening multiply-add. Non-widening
|
||||
//! arithmetic rounds to BF16 and reports exceptions. Predicated forms merge.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::aarch64::sve::dot::{RightOperand, VectorPart};
|
||||
|
||||
@@ -266,8 +267,7 @@ const ENCODINGS: &[Encoding] = &[
|
||||
|
||||
/// Exact fixed-bit forms contain no additional reserved register/index values.
|
||||
/// The enclosing decoder validates guest feature availability and streaming mode.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = ENCODINGS
|
||||
.iter()
|
||||
.find(|encoding| word & encoding.mask == encoding.value)?;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE FCM* and FAC* comparisons into predicates.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::flags::{NZCV_V, NZCV_Z};
|
||||
use crate::aarch64::floating::{
|
||||
Format, UnsupportedControl,
|
||||
@@ -99,8 +100,7 @@ pub fn evaluate(
|
||||
|
||||
/// All Z registers and P destinations are ordinary storage. Pg is P0..P7;
|
||||
/// Pd is P0..P15. An allocated byte-size encoding is architecturally reserved.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (kind, right) = match word & REGISTER_COMPARE_MASK {
|
||||
FCMEQ_REG => (
|
||||
Kind::Equal,
|
||||
@@ -147,7 +147,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
1 => Format::Half,
|
||||
2 => Format::Single,
|
||||
3 => Format::Double,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
kind,
|
||||
@@ -174,7 +174,7 @@ mod tests {
|
||||
(FACGE_REG, Kind::AbsoluteGreaterEqual),
|
||||
(FACGT_REG, Kind::AbsoluteGreater),
|
||||
] {
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
for (size, format) in [(1, Format::Half), (2, Format::Single), (3, Format::Double)] {
|
||||
for governing in 0..=GOVERNING_MASK {
|
||||
for destination in 0..=PREDICATE_MASK {
|
||||
@@ -206,7 +206,7 @@ mod tests {
|
||||
for opcode in [
|
||||
FCMEQ_ZERO, FCMGE_ZERO, FCMGT_ZERO, FCMLE_ZERO, FCMLT_ZERO, FCMNE_ZERO,
|
||||
] {
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
assert!(
|
||||
decode(opcode | (2 << SIZE_SHIFT) | (31 << SOURCE_SHIFT) | 15)
|
||||
.unwrap()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE predicated conversions (FCVT, FCVTZS/U, SCVTF/UCVTF, ...).
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::aarch64::floating::{
|
||||
Format,
|
||||
@@ -155,8 +156,7 @@ pub struct Operand {
|
||||
}
|
||||
|
||||
/// Decodes exactly 28 integer, 12 precision and 2 BF16 forms.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let kind = match word & CONVERSION_MASK {
|
||||
BFCVT_Z_P_Z_S2BF => Kind::Bfloat16 { upper: false },
|
||||
BFCVTNT_Z_P_Z_S2BF => Kind::Bfloat16 { upper: true },
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE predicated FAMIN and FAMAX.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, absolute_minmax::AbsoluteMinMaxOperation};
|
||||
|
||||
const FORM_MASK: u32 = 0xff3f_e000;
|
||||
@@ -22,8 +23,7 @@ pub struct Operand {
|
||||
}
|
||||
|
||||
/// Size 00 is reserved.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let operation = match word & FORM_MASK {
|
||||
FAMAX => AbsoluteMinMaxOperation::Maximum,
|
||||
FAMIN => AbsoluteMinMaxOperation::Minimum,
|
||||
@@ -33,7 +33,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
1 => Format::Half,
|
||||
2 => Format::Single,
|
||||
3 => Format::Double,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
operation,
|
||||
@@ -54,7 +54,7 @@ mod tests {
|
||||
(FAMAX, AbsoluteMinMaxOperation::Maximum),
|
||||
(FAMIN, AbsoluteMinMaxOperation::Minimum),
|
||||
] {
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
for (size, format) in [(1, Format::Half), (2, Format::Single), (3, Format::Double)] {
|
||||
for governing in 0..=GOVERNING_MASK {
|
||||
for destination in 0..=REGISTER_MASK {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE FP8 conversions.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
const SOURCE_SHIFT: u32 = 5;
|
||||
@@ -170,8 +171,7 @@ pub fn canonical_id(word: u32) -> Option<&'static str> {
|
||||
encoding(word).map(|encoding| encoding.id)
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = encoding(word)?;
|
||||
let source_mask = match encoding.kind {
|
||||
Kind::Widen { .. } => REGISTER_MASK,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE predicated FRINT*.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::floating::{Format, rounding::RoundingOperation};
|
||||
|
||||
const OPCODE_MASK: u32 = 0xff3f_e000;
|
||||
@@ -27,8 +28,7 @@ pub struct Operand {
|
||||
|
||||
/// Merging forms only. The FEAT_SVE2p2 zeroing forms and the bounded FRINT
|
||||
/// forms are not decoded.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let operation = match word & OPCODE_MASK {
|
||||
FRINTN => RoundingOperation::NearestEven,
|
||||
FRINTP => RoundingOperation::TowardPositive,
|
||||
@@ -43,7 +43,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
1 => Format::Half,
|
||||
2 => Format::Single,
|
||||
3 => Format::Double,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
operation,
|
||||
@@ -61,7 +61,7 @@ mod tests {
|
||||
#[test]
|
||||
fn all_operations_widths_predicates_and_vector_aliases() {
|
||||
for opcode in [FRINTN, FRINTP, FRINTM, FRINTZ, FRINTA, FRINTX, FRINTI] {
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
for (size, format) in [(1, Format::Half), (2, Format::Single), (3, Format::Double)] {
|
||||
for governing in 0..=GOVERNING_MASK {
|
||||
for register in 0..=REGISTER_MASK {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! FCPY (merging) and FDUP.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::aarch64::floating::Format;
|
||||
|
||||
@@ -43,8 +44,7 @@ fn expand_immediate(format: Format, immediate: u8) -> u64 {
|
||||
| (u64::from(fraction) << (fraction_bits - IMMEDIATE_FRACTION_BITS))
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let governing = if word & FCPY_MASK == FCPY {
|
||||
Some(((word >> COPY_GOVERNING_SHIFT) & COPY_GOVERNING_MASK) as u8)
|
||||
} else if word & FDUP_MASK == FDUP {
|
||||
@@ -56,7 +56,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
1 => Format::Half,
|
||||
2 => Format::Single,
|
||||
3 => Format::Double,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
format,
|
||||
@@ -89,8 +89,8 @@ mod tests {
|
||||
assert_eq!(decode(word).unwrap().unwrap().governing, None);
|
||||
}
|
||||
}
|
||||
assert_eq!(decode(FCPY), Some(Err(())));
|
||||
assert_eq!(decode(FDUP), Some(Err(())));
|
||||
assert_eq!(decode(FCPY), Some(Err(Unsupported)));
|
||||
assert_eq!(decode(FDUP), Some(Err(Unsupported)));
|
||||
// VFP imm8 0x70 is exactly +1.0 in every destination format.
|
||||
assert_eq!(expand_immediate(Format::Half, 0x70), 0x3c00);
|
||||
assert_eq!(expand_immediate(Format::Single, 0x70), 0x3f80_0000);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE integer arithmetic, widening and carry operations.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{ElementSize, Predication};
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
const SOURCE_SHIFT: u32 = 5;
|
||||
@@ -127,8 +128,7 @@ const USUBLT_Z_ZZ: u32 = 0x4500_1c00;
|
||||
const USUBWB_Z_ZZ: u32 = 0x4500_5800;
|
||||
const USUBWT_Z_ZZ: u32 = 0x4500_5c00;
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let destination = (word & REGISTER_MASK) as u8;
|
||||
let source = ((word >> SOURCE_SHIFT) & REGISTER_MASK) as u8;
|
||||
let right = ((word >> RIGHT_SHIFT) & REGISTER_MASK) as u8;
|
||||
@@ -188,7 +188,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
if let Some(operation) = operation {
|
||||
if matches!(operation, Binary::Divide { .. }) && element_bytes < 4 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return operand(
|
||||
element_bytes,
|
||||
@@ -225,7 +225,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
if let Some(operation) = operation {
|
||||
let shifted = word & IMMEDIATE_SHIFT_FLAG != 0;
|
||||
if element_bytes == 1 && shifted {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let value = i64::from(immediate) << if shifted { IMMEDIATE_SHIFT } else { 0 };
|
||||
return operand(
|
||||
@@ -304,7 +304,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
if let Some((unsigned, subtract, wide_left, left_top, right_top)) = widening {
|
||||
if element_bytes == 1 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
return operand(
|
||||
element_bytes,
|
||||
@@ -326,15 +326,14 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
impl Operand {
|
||||
/// MOVPRFX requirements of the follower, determined before destructive
|
||||
/// operands are normalized.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
original_word: u32,
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, Unsupported> {
|
||||
use crate::aarch64::sve::prefix::{PredicatedPrefixRequirement, PrefixRequirement};
|
||||
|
||||
if decode(original_word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let predicated = match self.predication {
|
||||
Predication::Merging(predicate) => Some(PredicatedPrefixRequirement {
|
||||
@@ -715,33 +714,33 @@ mod tests {
|
||||
let operand = decode(word).unwrap().unwrap();
|
||||
let mut forged = operand;
|
||||
forged.destination = 32;
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
let mut forged = operand;
|
||||
forged.element_size = ElementSize::Doubleword;
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
let mut forged = operand;
|
||||
forged.predication = Predication::Merging(7);
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
let mut forged = operand;
|
||||
forged.kind = Kind::Binary {
|
||||
operation: Binary::Add,
|
||||
left: 3,
|
||||
right: Source::Vector(3),
|
||||
};
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(0), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(SADDLB_Z_ZZ), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(SDIV_Z_P_ZZ), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
assert_eq!(operand.prefix_requirement(0), Err(Unsupported));
|
||||
assert_eq!(operand.prefix_requirement(SADDLB_Z_ZZ), Err(Unsupported));
|
||||
assert_eq!(operand.prefix_requirement(SDIV_Z_P_ZZ), Err(Unsupported));
|
||||
assert_eq!(
|
||||
operand.prefix_requirement(ADD_Z_ZI | IMMEDIATE_SHIFT_FLAG),
|
||||
Err(())
|
||||
Err(Unsupported)
|
||||
);
|
||||
// The same binary kind cannot authorize a constructive ADD; its exact
|
||||
// word and unpredicated role must remain distinct from the merging form.
|
||||
let constructive = ADD_Z_ZZ | (3 << SOURCE_SHIFT) | (5 << RIGHT_SHIFT) | 3;
|
||||
let constructive_operand = decode(constructive).unwrap().unwrap();
|
||||
assert_eq!(constructive_operand.kind, operand.kind);
|
||||
assert_eq!(operand.prefix_requirement(constructive), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(constructive), Err(Unsupported));
|
||||
assert_eq!(
|
||||
constructive_operand.prefix_requirement(constructive),
|
||||
Ok(Some(PrefixRequirement::Forbidden))
|
||||
@@ -812,7 +811,7 @@ mod tests {
|
||||
let word = opcode | (size << SIZE_SHIFT) | destination;
|
||||
let result = decode(word).unwrap();
|
||||
if (widening && size == 0) || (division && size < 2) {
|
||||
assert_eq!(result, Err(()));
|
||||
assert_eq!(result, Err(Unsupported));
|
||||
continue;
|
||||
}
|
||||
let operand = result.unwrap();
|
||||
@@ -837,7 +836,10 @@ mod tests {
|
||||
#[test]
|
||||
fn immediate_byte_shift_is_reserved_and_signed_minmax_extend_imm8() {
|
||||
for opcode in [ADD_Z_ZI, SUB_Z_ZI, SUBR_Z_ZI] {
|
||||
assert_eq!(decode(opcode | IMMEDIATE_SHIFT_FLAG), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(opcode | IMMEDIATE_SHIFT_FLAG),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
assert!(
|
||||
decode(opcode | (1 << SIZE_SHIFT) | IMMEDIATE_SHIFT_FLAG)
|
||||
.unwrap()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE predicated bit operations: CLS, CLZ, CNT, RBIT and REVB/REVH/REVW.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{ElementSize, Predication};
|
||||
|
||||
const OPCODE_MASK: u32 = 0xff3f_e000;
|
||||
@@ -34,8 +35,7 @@ pub struct Operand {
|
||||
pub predication: Predication,
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
use ElementSize::{Byte, Halfword, Word};
|
||||
use Kind::{LeadingSignBits, LeadingZeros, PopulationCount, ReverseBits, ReverseGroups};
|
||||
let kind = match word & OPCODE_MASK {
|
||||
@@ -52,12 +52,12 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
let bytes = 1usize << ((word >> SIZE_SHIFT) & SIZE_MASK);
|
||||
let Some(element_size) = ElementSize::from_bytes(bytes) else {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
};
|
||||
if let ReverseGroups { group_size } = kind
|
||||
&& element_size <= group_size
|
||||
{
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
kind,
|
||||
@@ -115,7 +115,7 @@ mod tests {
|
||||
}))
|
||||
);
|
||||
} else {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE integer comparisons into predicates (CMP*).
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
const SIZE_SHIFT: u32 = 22;
|
||||
@@ -241,13 +242,13 @@ const ENCODINGS: [Encoding; 26] = [
|
||||
},
|
||||
];
|
||||
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = ENCODINGS
|
||||
.iter()
|
||||
.find(|entry| word & entry.mask == entry.value)?;
|
||||
let element_bytes = 1 << ((word >> SIZE_SHIFT) & SIZE_MASK);
|
||||
if encoding.source == SourceKind::WideVector && element_bytes == 8 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let right = match encoding.source {
|
||||
SourceKind::Immediate => {
|
||||
@@ -300,7 +301,7 @@ mod tests {
|
||||
| destination;
|
||||
let operand = decode(word);
|
||||
if encoding.source == SourceKind::WideVector && size == SIZE_MASK {
|
||||
assert_eq!(operand, Some(Err(())));
|
||||
assert_eq!(operand, Some(Err(Unsupported)));
|
||||
} else {
|
||||
let operand = operand.unwrap().unwrap();
|
||||
assert_eq!(operand.relation, encoding.relation);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SVE vector Boolean operations, copies and prefix moves.
|
||||
use super::super::{Register, Width, logical_mask, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{ElementSize, Predication};
|
||||
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
@@ -125,8 +126,7 @@ pub struct Operand {
|
||||
pub kind: Kind,
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let destination = (word & REGISTER_MASK) as u8;
|
||||
let source = ((word >> SOURCE_SHIFT) & REGISTER_MASK) as u8;
|
||||
let right = ((word >> RIGHT_SHIFT) & REGISTER_MASK) as u8;
|
||||
@@ -202,7 +202,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
(encoded >> BITMASK_ROTATION_SHIFT) & BITMASK_FIELD_MASK,
|
||||
encoded & BITMASK_FIELD_MASK,
|
||||
) else {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
};
|
||||
operand.element_size = ElementSize::Doubleword;
|
||||
operand.kind = Kind::Immediate { operation, value };
|
||||
@@ -240,7 +240,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
) {
|
||||
let shifted = word & COPY_SHIFT_FLAG != 0;
|
||||
if element_size == ElementSize::Byte && shifted {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let value = ((word >> SOURCE_SHIFT) & COPY_IMMEDIATE_MASK_BITS) as u8 as i8;
|
||||
let predicate = ((word >> COPY_PREDICATE_SHIFT) & WIDE_PREDICATE_MASK) as u8;
|
||||
@@ -290,15 +290,14 @@ pub fn decode_prefix(word: u32) -> Option<Operand> {
|
||||
impl Operand {
|
||||
/// MOVPRFX requirements of the follower word. The typed operand is checked
|
||||
/// again so that normalized kinds cannot admit another encoding.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
word: u32,
|
||||
) -> Result<Option<super::prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<super::prefix::PrefixRequirement>, Unsupported> {
|
||||
use super::prefix::{PredicatedPrefixRequirement, PrefixRequirement};
|
||||
|
||||
if decode(word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let predicated = match self.predication {
|
||||
Predication::Merging(predicate) => Some(PredicatedPrefixRequirement {
|
||||
@@ -543,7 +542,7 @@ mod tests {
|
||||
| if shifted { COPY_SHIFT_FLAG } else { 0 };
|
||||
let result = decode(word).unwrap();
|
||||
if size == 0 && shifted {
|
||||
assert_eq!(result, Err(()));
|
||||
assert_eq!(result, Err(Unsupported));
|
||||
} else {
|
||||
let operand = result.unwrap();
|
||||
assert_eq!(operand.predication, Predication::Zeroing(predicate as u8));
|
||||
@@ -567,7 +566,10 @@ mod tests {
|
||||
#[test]
|
||||
fn reserved_logical_immediates_decline_and_zeroing_unary_is_outside_inventory() {
|
||||
for opcode in [AND_IMMEDIATE, ORR_IMMEDIATE, EOR_IMMEDIATE] {
|
||||
assert_eq!(decode(opcode | (63 << SOURCE_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(opcode | (63 << SOURCE_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
assert!(decode(opcode).unwrap().is_ok());
|
||||
}
|
||||
assert_eq!(decode(NOT_PREDICATED ^ (1 << 20)), None);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! PMOV between predicates and vector bitmaps.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
const DESTINATION_MASK: u32 = 31;
|
||||
@@ -24,8 +25,7 @@ pub struct Operand {
|
||||
pub portion: u8,
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (element_size, portion) = if word & BYTE_MASK == BYTE {
|
||||
(ElementSize::Byte, 0)
|
||||
} else if word & HALFWORD_MASK == HALFWORD {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE integer multiplies. Saturation does not set FPSR.QC.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{ElementSize, Predication};
|
||||
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
@@ -235,7 +236,7 @@ enum Format {
|
||||
IndexedComplexWord,
|
||||
}
|
||||
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (kind, format) = classify(word)?;
|
||||
let element_size = match format {
|
||||
Format::IndexedHalfword | Format::IndexedComplexHalfword => ElementSize::Halfword,
|
||||
@@ -251,11 +252,11 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
},
|
||||
};
|
||||
if kind.widening() && element_size == ElementSize::Byte {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
if matches!(kind, Kind::Polynomial { widening: true, .. }) && element_size == ElementSize::Word
|
||||
{
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let destination = (word & REGISTER_MASK) as u8;
|
||||
let source_field = ((word >> SOURCE_SHIFT) & REGISTER_MASK) as u8;
|
||||
@@ -645,15 +646,14 @@ fn classify(word: u32) -> Option<(Kind, Format)> {
|
||||
impl Operand {
|
||||
/// MOVPRFX requirements of the follower word, independent of the normalized
|
||||
/// kind. Unlisted encodings are refused.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
original_word: u32,
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, Unsupported> {
|
||||
use crate::aarch64::sve::prefix::{PredicatedPrefixRequirement, PrefixRequirement};
|
||||
|
||||
if decode(original_word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let source_bit = |register: u8| 1_u32 << register;
|
||||
let multiplier_mask = match self.multiplier {
|
||||
@@ -693,7 +693,7 @@ impl Operand {
|
||||
) {
|
||||
return Ok(Some(vector(
|
||||
predicated,
|
||||
multiplier_mask | source_bit(self.accumulator.ok_or(())?),
|
||||
multiplier_mask | source_bit(self.accumulator.ok_or(Unsupported)?),
|
||||
)));
|
||||
}
|
||||
if matches!(
|
||||
@@ -928,7 +928,7 @@ mod tests {
|
||||
SQDMULLB_Z_ZZ,
|
||||
SQDMULLT_Z_ZZ,
|
||||
] {
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
}
|
||||
let cross = decode(SQDMLALBT_Z_ZZZ | (1 << SIZE_SHIFT))
|
||||
.unwrap()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SVE saturating, halving and absolute-difference arithmetic. Saturation does
|
||||
//! not set FPSR.QC.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::aarch64::scalable::{ElementSize, Predication};
|
||||
|
||||
@@ -146,8 +147,7 @@ fn difference(signedness: Signedness, widening: Option<Half>, accumulate: bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
use Arithmetic::{Add, ReverseSubtract, Subtract};
|
||||
use Half::{Bottom, Top};
|
||||
use Signedness::{Signed, Unsigned};
|
||||
@@ -214,7 +214,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
if let Some(kind) = immediate {
|
||||
let scaled = word & IMMEDIATE_SCALE_FLAG != 0;
|
||||
if element_size == ElementSize::Byte && scaled {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let immediate = ((word >> SOURCE_SHIFT) & IMMEDIATE_MASK)
|
||||
<< if scaled { IMMEDIATE_SCALE_SHIFT } else { 0 };
|
||||
@@ -264,7 +264,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
}
|
||||
) && element_size == ElementSize::Byte
|
||||
{
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
destination,
|
||||
@@ -279,15 +279,14 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
impl Operand {
|
||||
/// MOVPRFX requirements of the follower word. Call before normalizing
|
||||
/// destructive operands; the typed operand must still match the word.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
original_word: u32,
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, Unsupported> {
|
||||
use crate::aarch64::sve::prefix::{PredicatedPrefixRequirement, PrefixRequirement};
|
||||
|
||||
if decode(original_word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let vector = |predicated, other_vector_sources| PrefixRequirement::Vector {
|
||||
destination: self.destination,
|
||||
@@ -319,12 +318,12 @@ impl Operand {
|
||||
| USQADD_Z_P_ZZ
|
||||
) {
|
||||
let Predication::Merging(predicate) = self.predication else {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
};
|
||||
let source = match self.right {
|
||||
Input::None => self.left,
|
||||
Input::Vector(source) => source,
|
||||
Input::Immediate(_) => return Err(()),
|
||||
Input::Immediate(_) => return Err(Unsupported),
|
||||
};
|
||||
// All twenty forms use equal destination and first-source widths.
|
||||
return Ok(Some(vector(
|
||||
@@ -343,14 +342,14 @@ impl Operand {
|
||||
}
|
||||
if original_word & COMPLEX_OPCODE_MASK == SQCADD_Z_ZZ {
|
||||
let Input::Vector(source) = self.right else {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
};
|
||||
return Ok(Some(vector(None, source_bit(source))));
|
||||
}
|
||||
let requirement = match original_word & REGISTER_OPCODE_MASK {
|
||||
SABA_Z_ZZZ | SABALB_Z_ZZZ | SABALT_Z_ZZZ | UABA_Z_ZZZ | UABALB_Z_ZZZ | UABALT_Z_ZZZ => {
|
||||
let Input::Vector(right) = self.right else {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
};
|
||||
Some(vector(None, source_bit(self.left) | source_bit(right)))
|
||||
}
|
||||
@@ -850,32 +849,35 @@ mod tests {
|
||||
let operand = decode(word).unwrap().unwrap();
|
||||
let mut forged = operand;
|
||||
forged.destination = 4;
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
forged = operand;
|
||||
forged.left ^= 1;
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
forged = operand;
|
||||
forged.right = match operand.right {
|
||||
Input::Vector(v) => Input::Vector(v ^ 1),
|
||||
Input::Immediate(v) => Input::Immediate(v ^ 1),
|
||||
Input::None => Input::Vector(0),
|
||||
};
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
forged = operand;
|
||||
forged.element_size = ElementSize::Quadword;
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
forged = operand;
|
||||
forged.predication = Predication::Zeroing(2);
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
forged = operand;
|
||||
forged.kind = if operand.kind == Kind::Absolute {
|
||||
Kind::Negate
|
||||
} else {
|
||||
Kind::Absolute
|
||||
};
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(word ^ (1 << 31)), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(0), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
assert_eq!(
|
||||
operand.prefix_requirement(word ^ (1 << 31)),
|
||||
Err(Unsupported)
|
||||
);
|
||||
assert_eq!(operand.prefix_requirement(0), Err(Unsupported));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -892,9 +894,9 @@ mod tests {
|
||||
| 31
|
||||
| if shifted { 1 << 13 } else { 0 };
|
||||
if size == 0 && shifted {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
let operand = decode(fact.word).unwrap().unwrap();
|
||||
assert_eq!(operand.prefix_requirement(word), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(word), Err(Unsupported));
|
||||
} else {
|
||||
let operand = decode(word).unwrap().unwrap();
|
||||
assert_eq!(
|
||||
@@ -911,9 +913,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
if fact.minimum_size == 1 {
|
||||
assert_eq!(decode(fact.word), Some(Err(())));
|
||||
assert_eq!(decode(fact.word), Some(Err(Unsupported)));
|
||||
let operand = decode(fact.word | (1 << 22)).unwrap().unwrap();
|
||||
assert_eq!(operand.prefix_requirement(fact.word), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(fact.word), Err(Unsupported));
|
||||
}
|
||||
}
|
||||
for size in 0..4 {
|
||||
@@ -933,7 +935,7 @@ mod tests {
|
||||
for zeroing in [0x440aa000, 0x440ba000] {
|
||||
assert_eq!(decode(zeroing), None);
|
||||
let operand = decode(0x4408a000).unwrap().unwrap();
|
||||
assert_eq!(operand.prefix_requirement(zeroing), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(zeroing), Err(Unsupported));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1049,7 +1051,10 @@ mod tests {
|
||||
#[test]
|
||||
fn immediate_scaling_and_widening_reserved_sizes_are_explicit() {
|
||||
for opcode in [SQADD_Z_ZI, UQADD_Z_ZI, SQSUB_Z_ZI, UQSUB_Z_ZI] {
|
||||
assert_eq!(decode(opcode | IMMEDIATE_SCALE_FLAG), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(opcode | IMMEDIATE_SCALE_FLAG),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
for size in 1..=SIZE_MASK {
|
||||
let operand = decode(
|
||||
opcode
|
||||
@@ -1072,7 +1077,7 @@ mod tests {
|
||||
UABALB_Z_ZZZ,
|
||||
UABALT_Z_ZZZ,
|
||||
] {
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
for size in 1..=SIZE_MASK {
|
||||
assert!(decode(opcode | (size << SIZE_SHIFT)).unwrap().is_ok());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! staged in full, so a fault leaves it unchanged.
|
||||
use super::super::register;
|
||||
use super::memory::{Address, Extension, Offset, Scale};
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
@@ -60,7 +61,7 @@ pub struct Operand {
|
||||
pub tag_checked: bool,
|
||||
}
|
||||
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & WHOLE_VECTOR_MASK == WHOLE_VECTOR {
|
||||
return Some(Ok(whole(word, Kind::WholeVector)));
|
||||
}
|
||||
@@ -94,7 +95,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
} else {
|
||||
let index = (word >> INDEX_SHIFT) & REGISTER_MASK;
|
||||
if index == REGISTER_MASK {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Offset::Register {
|
||||
index: register(index, false),
|
||||
@@ -222,7 +223,7 @@ const LD1RSW_S64: u32 = 0x84c08000;
|
||||
const LD1RW_U32: u32 = 0x8540c000;
|
||||
const LD1RW_U64: u32 = 0x8540e000;
|
||||
|
||||
fn decode_replicate(word: u32) -> Option<Result<Operand, ()>> {
|
||||
fn decode_replicate(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let quad_immediate = word & QUAD_IMMEDIATE_MASK == QUAD_IMMEDIATE;
|
||||
let quad_register = word & QUAD_REGISTER_MASK == QUAD_REGISTER;
|
||||
let (kind, memory_bytes, element_bytes, extension) = if quad_immediate || quad_register {
|
||||
@@ -258,7 +259,7 @@ fn decode_replicate(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let offset = if quad_register {
|
||||
let index = (word >> INDEX_SHIFT) & REGISTER_MASK;
|
||||
if index == REGISTER_MASK {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Offset::Register {
|
||||
index: register(index, false),
|
||||
@@ -866,7 +867,10 @@ mod tests {
|
||||
..
|
||||
}
|
||||
));
|
||||
assert_eq!(decode(word | (REGISTER_MASK << INDEX_SHIFT)), Some(Err(())));
|
||||
assert_eq!(
|
||||
decode(word | (REGISTER_MASK << INDEX_SHIFT)),
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! SME2/SVE2.1 multi-vector loads and stores governed by predicate-as-counter.
|
||||
use super::super::{Register, register};
|
||||
use super::memory::{Address, Offset, Scale};
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{
|
||||
ElementSize,
|
||||
execution::{GuestMemoryQuantity, ScalableAccessCheck, ScalableAccessRequirements},
|
||||
@@ -62,15 +63,14 @@ pub(crate) const fn guest_memory_quantity(operand: &Operand) -> GuestMemoryQuant
|
||||
}
|
||||
|
||||
/// Reserved tuple alignment and immediate fields decline without another decode.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & CLASS_MASK != CLASS_VALUE {
|
||||
return None;
|
||||
}
|
||||
let immediate = word & IMMEDIATE_ADDRESS != 0;
|
||||
let quad = word & FOUR_REGISTERS != 0;
|
||||
if (immediate && word & IMMEDIATE_RESERVED != 0) || (quad && word & QUAD_RESERVED != 0) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let offset = if immediate {
|
||||
let raw = ((word >> OFFSET_SHIFT) & IMMEDIATE_MASK) as i8;
|
||||
@@ -195,11 +195,11 @@ mod tests {
|
||||
fn reserved_fields_are_explicit_and_other_classes_do_not_match() {
|
||||
assert_eq!(
|
||||
decode(CLASS_VALUE | FOUR_REGISTERS | QUAD_RESERVED),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
assert_eq!(
|
||||
decode(CLASS_VALUE | IMMEDIATE_ADDRESS | IMMEDIATE_RESERVED),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
for bit in 23..32 {
|
||||
assert_eq!(decode(CLASS_VALUE ^ (1 << bit)), None);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! SVE contiguous and whole-register stores, and PRF* hints. Structured source
|
||||
//! tuples wrap modulo 32.
|
||||
use super::memory::{Address, Offset, Scale};
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::{
|
||||
register,
|
||||
scalable::{
|
||||
@@ -231,7 +232,7 @@ const FORMS: &[Form] = &[
|
||||
];
|
||||
|
||||
/// None means another allocation; Err marks a recognized unallocated operand.
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if let Some(form) = grouped_form(word) {
|
||||
return Some(decode_store(word, form).map(Operand::Store));
|
||||
}
|
||||
@@ -277,19 +278,19 @@ fn base(word: u32) -> crate::aarch64::Register {
|
||||
register((word >> BASE_SHIFT) & REGISTER_MASK, true)
|
||||
}
|
||||
|
||||
fn decode_store(word: u32, form: Form) -> Result<Store, ()> {
|
||||
fn decode_store(word: u32, form: Form) -> Result<Store, Unsupported> {
|
||||
let element_bytes = match form.element {
|
||||
Element::Encoded => BYTE_BYTES << ((word >> SIZE_SHIFT) & SIZE_MASK),
|
||||
Element::Word => WORD_BYTES << ((word >> SIZE_SHIFT) & WORD_SIZE_MASK),
|
||||
Element::Fixed(bytes) => bytes,
|
||||
};
|
||||
if element_bytes < form.memory_bytes {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let offset = if form.register_offset {
|
||||
let index = (word >> OFFSET_SHIFT) & REGISTER_MASK;
|
||||
if index == REGISTER_MASK {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
Offset::Register {
|
||||
index: register(index, false),
|
||||
@@ -352,7 +353,7 @@ fn decode_whole(word: u32) -> Option<WholeStore> {
|
||||
})
|
||||
}
|
||||
|
||||
fn decode_prefetch(word: u32) -> Option<Result<Prefetch, ()>> {
|
||||
fn decode_prefetch(word: u32) -> Option<Result<Prefetch, Unsupported>> {
|
||||
let (offset, size_shift) = if word & PREFETCH_IMMEDIATE_MASK == PREFETCH_IMMEDIATE_CLASS {
|
||||
let offset_mask = (1 << PREFETCH_OFFSET_BITS) - 1;
|
||||
(
|
||||
@@ -368,7 +369,7 @@ fn decode_prefetch(word: u32) -> Option<Result<Prefetch, ()>> {
|
||||
} else if word & PREFETCH_REGISTER_MASK == PREFETCH_REGISTER_CLASS {
|
||||
let index = (word >> OFFSET_SHIFT) & REGISTER_MASK;
|
||||
if index == REGISTER_MASK {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let shift = ((word >> REGISTER_SIZE_SHIFT) & SIZE_MASK) as u8;
|
||||
(
|
||||
@@ -452,7 +453,7 @@ mod tests {
|
||||
| (offset << OFFSET_SHIFT);
|
||||
let result = decode(word).expect("owned store class");
|
||||
if form.register_offset && offset == REGISTER_MASK {
|
||||
assert_eq!(result, Err(()));
|
||||
assert_eq!(result, Err(Unsupported));
|
||||
continue;
|
||||
}
|
||||
let Operand::Store(store) = result.expect("allocated operands") else {
|
||||
@@ -489,7 +490,7 @@ mod tests {
|
||||
#[test]
|
||||
fn narrowing_halfword_rejects_byte_source_elements() {
|
||||
for class in [0xe480_e000, 0xe480_4000] {
|
||||
assert_eq!(decode(class), Some(Err(())));
|
||||
assert_eq!(decode(class), Some(Err(Unsupported)));
|
||||
assert!(matches!(
|
||||
decode(class | (1 << SIZE_SHIFT)),
|
||||
Some(Ok(Operand::Store(_)))
|
||||
@@ -571,7 +572,7 @@ mod tests {
|
||||
| hint
|
||||
| (size << REGISTER_SIZE_SHIFT)
|
||||
| (REGISTER_MASK << OFFSET_SHIFT);
|
||||
assert_eq!(decode(reserved), Some(Err(())));
|
||||
assert_eq!(decode(reserved), Some(Err(Unsupported)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SVE LD2, LD3 and LD4, including 128-bit elements.
|
||||
use super::memory::{Address, Offset, Scale};
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::{
|
||||
register,
|
||||
scalable::{
|
||||
@@ -58,7 +59,7 @@ impl Operand {
|
||||
/// Predicates select bit `element_index * element_bytes`; inactive lanes zero.
|
||||
/// Base31 denotes SP. Register-offset forms always enable architectural tag
|
||||
/// checks, whereas immediate-offset forms enable them only for a GPR base.
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (immediate, quadword) = match word {
|
||||
_ if word & IMMEDIATE_MASK == IMMEDIATE_CLASS => (true, false),
|
||||
_ if word & REGISTER_MASK == REGISTER_CLASS => (false, false),
|
||||
@@ -94,7 +95,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
} else {
|
||||
let index = (word >> OFFSET_SHIFT) & REGISTER_FIELD_MASK;
|
||||
if index == REGISTER_FIELD_MASK {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Offset::Register {
|
||||
index: register(index, false),
|
||||
@@ -218,7 +219,7 @@ mod tests {
|
||||
} else {
|
||||
assert_eq!(
|
||||
decode(class | REGISTER_FIELD_MASK << OFFSET_SHIFT),
|
||||
Some(Err(()))
|
||||
Some(Err(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Predicate generation: PTRUE, PFALSE, WHILE*, BRK* and PNEXT. PN registers are
|
||||
//! P8-P15.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
pub use basic::BasicOperand;
|
||||
pub use breaks::{Boundary, BreakKind, BreakOperand};
|
||||
@@ -28,7 +29,7 @@ impl Operand {
|
||||
|
||||
/// None means another decoder owns the word; Err means an owned but invalid
|
||||
/// operand.
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if let Some(result) = basic::decode_basic(word) {
|
||||
return Some(result.map(Operand::Basic));
|
||||
}
|
||||
@@ -41,7 +42,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
mod basic {
|
||||
//! Basic predicate generation. Predicate indices are packed architectural P registers.
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
use crate::aarch64::{Register, Width, register};
|
||||
use crate::aarch64::{Register, Unsupported, Width, register};
|
||||
|
||||
const PREDICATE_MASK: u32 = 15;
|
||||
const SCALAR_REGISTER_MASK: u32 = 31;
|
||||
@@ -108,7 +109,7 @@ mod basic {
|
||||
|
||||
/// No basic form has reserved operand encodings. Unnamed five-bit PTRUE patterns
|
||||
/// execute with zero active elements; they are not decoder errors. GPR31 is ZR.
|
||||
pub fn decode_basic(word: u32) -> Option<Result<BasicOperand, ()>> {
|
||||
pub fn decode_basic(word: u32) -> Option<Result<BasicOperand, Unsupported>> {
|
||||
let destination = (word & PREDICATE_MASK) as u8;
|
||||
let element = ElementSize::from_bytes(1 << ((word >> SIZE_SHIFT) & SIZE_MASK))?;
|
||||
let near_source = ((word >> FIRST_SOURCE_SHIFT) & PREDICATE_MASK) as u8;
|
||||
@@ -253,6 +254,8 @@ mod basic {
|
||||
|
||||
mod breaks {
|
||||
//! Predicate breaks decode operand roles without state-layout assumptions.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Boundary {
|
||||
Before,
|
||||
@@ -298,7 +301,7 @@ mod breaks {
|
||||
((word >> shift) & PREDICATE_FIELD_MASK) as u8
|
||||
}
|
||||
|
||||
pub fn decode(word: u32) -> Option<Result<BreakOperand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<BreakOperand, Unsupported>> {
|
||||
let previous_source = predicate(word, PREVIOUS_SOURCE_SHIFT);
|
||||
let (kind, set_flags) = match word & BREAK_FLAGS_MASK {
|
||||
BRKAS => (
|
||||
@@ -434,7 +437,7 @@ mod whiles {
|
||||
const PAIR_DESTINATION_MASK: u32 = 14;
|
||||
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
use crate::aarch64::{Register, Width, register};
|
||||
use crate::aarch64::{Register, Unsupported, Width, register};
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Comparison {
|
||||
SignedLt,
|
||||
@@ -638,7 +641,7 @@ mod whiles {
|
||||
}
|
||||
/// All matching operand fields are allocated; mode/feature checks belong to the caller.
|
||||
/// Scalar sources31 are ZR, never SP. Pair destinations are encoded even first registers.
|
||||
pub fn decode(word: u32) -> Option<Result<WhileOperand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<WhileOperand, Unsupported>> {
|
||||
let form = FORMS.iter().find(|form| word & form.mask == form.class)?;
|
||||
let element =
|
||||
ElementSize::from_bytes(1 << ((word >> ELEMENT_SIZE_SHIFT) & ELEMENT_SIZE_MASK))?;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Predicate Boolean operations, permutes and predicate-as-counter extraction.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
@@ -128,8 +129,7 @@ pub struct Operand {
|
||||
}
|
||||
|
||||
/// Feature and streaming-mode checks belong to the shared SVE decode boundary.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let destination = (word & PREDICATE_MASK) as u8;
|
||||
let left = ((word >> SOURCE_SHIFT) & PREDICATE_MASK) as u8;
|
||||
let right = ((word >> RIGHT_SHIFT) & PREDICATE_MASK) as u8;
|
||||
@@ -194,7 +194,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let size_encoding =
|
||||
(((word >> PSEL_SIZE_HIGH_SHIFT) & 1) << 3) | ((word >> PSEL_SIZE_LOW_SHIFT) & 7);
|
||||
if size_encoding == 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let size = size_encoding.trailing_zeros();
|
||||
let immediate =
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE permutes and vector generation (INDEX, DUP, ZIP, UZP, TRN, REV, TBL, ...).
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
use crate::aarch64::{Register, Width, logical_mask};
|
||||
|
||||
@@ -169,7 +170,7 @@ fn index_register(encoded: u8) -> IndexOperand {
|
||||
}
|
||||
|
||||
/// None is another allocation; Err is an allocated class with reserved operands.
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let destination = (word & REGISTER_MASK) as u8;
|
||||
let source = ((word >> SOURCE_SHIFT) & REGISTER_MASK) as u8;
|
||||
let second = ((word >> SECOND_SHIFT) & REGISTER_MASK) as u8;
|
||||
@@ -183,7 +184,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let operand = if word & DUPQ_Z_ZI_MASK == DUPQ_Z_ZI_CLASS {
|
||||
let tsz = (word >> SECOND_SHIFT) & SEGMENT_IMMEDIATE_MASK;
|
||||
if tsz == 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let low_bit = tsz.trailing_zeros();
|
||||
let element_size = ElementSize::from_bytes(1 << low_bit).expect("nonzero four-bit tsz");
|
||||
@@ -407,7 +408,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
immediate & LOGICAL_FIELD_MASK,
|
||||
) {
|
||||
Some(mask) => mask,
|
||||
None => return Some(Err(())),
|
||||
None => return Some(Err(Unsupported)),
|
||||
};
|
||||
Operand::DuplicateMask { destination, mask }
|
||||
} else if word & INDEX_Z_II_MASK == INDEX_Z_II_CLASS {
|
||||
@@ -447,15 +448,14 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
impl Operand {
|
||||
/// MOVPRFX follower requirements from the specification. Other encodings
|
||||
/// are refused even when their typed operand matches.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
original_word: u32,
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, Unsupported> {
|
||||
use crate::aarch64::sve::prefix::PrefixRequirement;
|
||||
|
||||
if decode(original_word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let permitted = match self {
|
||||
Self::Extract {
|
||||
@@ -624,7 +624,7 @@ mod tests {
|
||||
DUPM_Z_I_CLASS | (LOGICAL_IMMEDIATE_MASK << SOURCE_SHIFT),
|
||||
REVD_Z_P_Z_M_CLASS | (1 << SIZE_SHIFT),
|
||||
] {
|
||||
assert_eq!(decoded.prefix_requirement(other), Err(()));
|
||||
assert_eq!(decoded.prefix_requirement(other), Err(Unsupported));
|
||||
}
|
||||
let forged = Operand::Extract {
|
||||
destination: DESTINATION,
|
||||
@@ -633,7 +633,7 @@ mod tests {
|
||||
byte_offset: 0,
|
||||
segment: false,
|
||||
};
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -813,7 +813,7 @@ mod tests {
|
||||
for encoded in 0..=REGISTER_MASK {
|
||||
let decoded = decode(DUPQ_Z_ZI_CLASS | (encoded << SECOND_SHIFT));
|
||||
if encoded & SEGMENT_IMMEDIATE_MASK == 0 {
|
||||
assert_eq!(decoded, Some(Err(())));
|
||||
assert_eq!(decoded, Some(Err(Unsupported)));
|
||||
} else {
|
||||
let Some(Ok(Operand::DuplicateSegment {
|
||||
element_size,
|
||||
@@ -843,7 +843,7 @@ mod tests {
|
||||
Operand::DuplicateMask { mask, .. } => mask,
|
||||
_ => panic!("wrong duplicate allocation"),
|
||||
})),
|
||||
Some(expected.ok_or(()))
|
||||
Some(expected.ok_or(Unsupported))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE element extraction, broadcast and insertion (LAST*, CLAST*, INSR, ...).
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
use crate::aarch64::{Register, register};
|
||||
|
||||
@@ -84,8 +85,8 @@ fn element_size(word: u32) -> ElementSize {
|
||||
}
|
||||
}
|
||||
|
||||
/// None is outside this family; Some(Err(())) is a reserved family encoding.
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
/// None is outside this family; Some(Err(Unsupported)) is a reserved family encoding.
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let mut element_size = element_size(word);
|
||||
let destination_index = (word & REGISTER_MASK) as u8;
|
||||
let source_index = ((word >> SOURCE_SHIFT) & REGISTER_MASK) as u8;
|
||||
@@ -135,7 +136,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
} else if word & DUP_IMMEDIATE_MASK == DUP_IMMEDIATE {
|
||||
let shifted = word & SHIFT_FLAG != 0;
|
||||
if element_size == ElementSize::Byte && shifted {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let immediate = ((word >> IMMEDIATE_SHIFT) & IMMEDIATE_MASK) as u8 as i8 as i16;
|
||||
(
|
||||
@@ -154,7 +155,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
} else if word & DUP_INDEX_MASK == DUP_INDEX {
|
||||
let size = (word >> INDEX_SIZE_SHIFT) & INDEX_SIZE_MASK;
|
||||
if size == 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let lowest = size.trailing_zeros();
|
||||
element_size = ElementSize::from_bytes(1 << lowest)?;
|
||||
@@ -189,15 +190,14 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
impl Operand {
|
||||
/// Canonical-word MOVPRFX requirements for the four documented followers.
|
||||
/// Scalar V sources share Z storage; general-register sources do not.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
original_word: u32,
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<crate::aarch64::sve::prefix::PrefixRequirement>, Unsupported> {
|
||||
use crate::aarch64::sve::prefix::PrefixRequirement;
|
||||
|
||||
if decode(original_word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let Destination::Vector(destination) = self.destination else {
|
||||
return Ok(None);
|
||||
@@ -415,7 +415,7 @@ mod tests {
|
||||
let word = word(INSR_SCALAR, SOURCE, DESTINATION);
|
||||
let decoded = operand(word);
|
||||
for other in [word ^ 1, 0, DUP_INDEX, DUP_IMMEDIATE | SHIFT_FLAG] {
|
||||
assert_eq!(decoded.prefix_requirement(other), Err(()));
|
||||
assert_eq!(decoded.prefix_requirement(other), Err(Unsupported));
|
||||
}
|
||||
for forged in [
|
||||
Operand {
|
||||
@@ -431,7 +431,7 @@ mod tests {
|
||||
..decoded
|
||||
},
|
||||
] {
|
||||
assert_eq!(forged.prefix_requirement(word), Err(()));
|
||||
assert_eq!(forged.prefix_requirement(word), Err(Unsupported));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,7 +585,7 @@ mod tests {
|
||||
| (immediate << IMMEDIATE_SHIFT)
|
||||
| if shifted { SHIFT_FLAG } else { 0 };
|
||||
if size == 0 && shifted {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
} else {
|
||||
let signed = immediate as u8 as i8 as i16;
|
||||
let expected = if shifted {
|
||||
@@ -607,7 +607,7 @@ mod tests {
|
||||
for high in 0..=INDEX_HIGH_MASK {
|
||||
let word = DUP_INDEX | (size << INDEX_SIZE_SHIFT) | (high << INDEX_HIGH_SHIFT);
|
||||
if size == 0 {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
continue;
|
||||
}
|
||||
let lowest = size.trailing_zeros();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE unpacks, pairwise arithmetic and high-narrowing operations.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{ElementSize, Predication};
|
||||
|
||||
const SIZE_SHIFT: u32 = 22;
|
||||
@@ -104,15 +105,14 @@ pub struct Operand {
|
||||
|
||||
impl Operand {
|
||||
/// MOVPRFX follower requirements from the specification.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
original_word: u32,
|
||||
) -> Result<Option<super::prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<super::prefix::PrefixRequirement>, Unsupported> {
|
||||
use super::prefix::{PredicatedPrefixRequirement, PrefixRequirement};
|
||||
|
||||
if decode(original_word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
let (source, predicated) = match (original_word & PREDICATED_MASK, self.kind) {
|
||||
(ADDP | SMAXP | UMAXP | SMINP | UMINP, Kind::Pair { right, .. }) => (right, None),
|
||||
@@ -121,7 +121,7 @@ impl Operand {
|
||||
Kind::Extend { source, .. } | Kind::PairAccumulate { source, .. },
|
||||
) => {
|
||||
let Predication::Merging(predicate) = self.predication else {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
};
|
||||
(
|
||||
source,
|
||||
@@ -145,8 +145,7 @@ impl Operand {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
use Arithmetic::{Add, Subtract};
|
||||
use Half::{Bottom, Top};
|
||||
use Signedness::{Signed, Unsigned};
|
||||
@@ -303,7 +302,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
_ => ElementSize::Halfword.bits(),
|
||||
};
|
||||
if element_size.bits() < minimum_bits {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let predication = match kind {
|
||||
Kind::Extend { .. } | Kind::Pair { .. } | Kind::PairAccumulate { .. } => {
|
||||
@@ -635,7 +634,7 @@ mod tests {
|
||||
..operand
|
||||
},
|
||||
] {
|
||||
assert_eq!(changed.prefix_requirement(original), Err(()));
|
||||
assert_eq!(changed.prefix_requirement(original), Err(Unsupported));
|
||||
}
|
||||
if let Kind::NarrowHigh {
|
||||
left,
|
||||
@@ -655,15 +654,18 @@ mod tests {
|
||||
},
|
||||
..operand
|
||||
};
|
||||
assert_eq!(changed.prefix_requirement(original), Err(()));
|
||||
assert_eq!(changed.prefix_requirement(original), Err(Unsupported));
|
||||
}
|
||||
for invalid_original in [0, u32::MAX, original ^ 1] {
|
||||
assert_eq!(operand.prefix_requirement(invalid_original), Err(()));
|
||||
assert_eq!(
|
||||
operand.prefix_requirement(invalid_original),
|
||||
Err(Unsupported)
|
||||
);
|
||||
}
|
||||
for size in 0..first_size {
|
||||
let reserved = encoding | size << SIZE_SHIFT;
|
||||
assert_eq!(decode(reserved), Some(Err(())));
|
||||
assert_eq!(operand.prefix_requirement(reserved), Err(()));
|
||||
assert_eq!(decode(reserved), Some(Err(Unsupported)));
|
||||
assert_eq!(operand.prefix_requirement(reserved), Err(Unsupported));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! SVE predicated integer reductions to a scalar or 128-bit result.
|
||||
use super::prefix;
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
const REDUCTION_MASK: u32 = 0xff3f_e000;
|
||||
@@ -60,13 +61,12 @@ pub struct Operand {
|
||||
impl Operand {
|
||||
/// The scalar and quadword reductions allow no MOVPRFX; the word is
|
||||
/// re-checked before returning that.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn prefix_requirement(
|
||||
self,
|
||||
original_word: u32,
|
||||
) -> Result<Option<prefix::PrefixRequirement>, ()> {
|
||||
) -> Result<Option<prefix::PrefixRequirement>, Unsupported> {
|
||||
if decode(original_word) != Some(Ok(self)) {
|
||||
return Err(());
|
||||
return Err(Unsupported);
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
@@ -83,7 +83,7 @@ impl Operand {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let (kind, output) = match word & REDUCTION_MASK {
|
||||
AND_CLASS => (Kind::And, Output::Scalar),
|
||||
OR_CLASS => (Kind::Or, Output::Scalar),
|
||||
@@ -108,7 +108,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let element_size =
|
||||
ElementSize::from_bytes(element_bytes).expect("two-bit SVE reduction element size");
|
||||
if kind == Kind::SignedAdd && element_size == ElementSize::Doubleword {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
Some(Ok(Operand {
|
||||
kind,
|
||||
@@ -181,7 +181,7 @@ mod tests {
|
||||
| source << SOURCE_SHIFT
|
||||
| destination;
|
||||
if kind == Kind::SignedAdd && size == SIZE_MASK {
|
||||
assert_eq!(decode(word), Some(Err(())));
|
||||
assert_eq!(decode(word), Some(Err(Unsupported)));
|
||||
} else {
|
||||
let operand = decode(word).unwrap().unwrap();
|
||||
assert_eq!(operand.kind, kind);
|
||||
@@ -288,9 +288,9 @@ mod tests {
|
||||
..operand
|
||||
},
|
||||
] {
|
||||
assert_eq!(changed.prefix_requirement(word), Err(()));
|
||||
assert_eq!(changed.prefix_requirement(word), Err(Unsupported));
|
||||
}
|
||||
assert_eq!(operand.prefix_requirement(word ^ 1), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(word ^ 1), Err(Unsupported));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ mod tests {
|
||||
for word in [AND_CLASS, QUADWORD_AND_CLASS] {
|
||||
let operand = decode(word).unwrap().unwrap();
|
||||
for original_word in [0, u32::MAX, reserved] {
|
||||
assert_eq!(operand.prefix_requirement(original_word), Err(()));
|
||||
assert_eq!(operand.prefix_requirement(original_word), Err(Unsupported));
|
||||
}
|
||||
}
|
||||
let forged_reserved = Operand {
|
||||
@@ -311,7 +311,10 @@ mod tests {
|
||||
governing: 0,
|
||||
source: 0,
|
||||
};
|
||||
assert_eq!(forged_reserved.prefix_requirement(reserved), Err(()));
|
||||
assert_eq!(
|
||||
forged_reserved.prefix_requirement(reserved),
|
||||
Err(Unsupported)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE shifts, shift-accumulates, shift-inserts and XAR.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::{ElementSize, Predication};
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Kind {
|
||||
@@ -395,8 +396,7 @@ const ENCODINGS: &[Encoding] = &[
|
||||
},
|
||||
];
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = ENCODINGS
|
||||
.iter()
|
||||
.find(|entry| word & entry.mask == entry.value)?;
|
||||
@@ -429,7 +429,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
};
|
||||
let tsize = (size << 2) | ((word >> size_low_shift) & SIZE_MASK);
|
||||
if tsize == 0 {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let element_bits = BYTE_BITS << (u32::BITS - 1 - tsize.leading_zeros());
|
||||
let encoded = ((tsize << 3) | ((word >> immediate_shift) & IMMEDIATE_MASK)) as u8;
|
||||
@@ -453,7 +453,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
Format::PredicatedDoublewords | Format::Doublewords
|
||||
);
|
||||
if wide && size == SIZE_MASK {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let register_shift = if matches!(encoding.format, Format::Doublewords) {
|
||||
WIDE_SOURCE_SHIFT
|
||||
@@ -477,7 +477,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
let second_source = matches!(encoding.format, Format::XorRotate)
|
||||
.then_some(((word >> SOURCE_SHIFT) & REGISTER_MASK) as u8);
|
||||
let Some(element_size) = ElementSize::from_bytes(usize::from(element_bits / BYTE_BITS)) else {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
};
|
||||
let predication = predicate.map_or(Predication::Unpredicated, Predication::Merging);
|
||||
Some(Ok(Operand {
|
||||
@@ -520,7 +520,7 @@ mod tests {
|
||||
| REGISTER_MASK;
|
||||
let result = decode(word).expect("owned immediate encoding");
|
||||
if tsize == 0 {
|
||||
assert_eq!(result, Err(()));
|
||||
assert_eq!(result, Err(Unsupported));
|
||||
continue;
|
||||
}
|
||||
let operand = result.unwrap();
|
||||
@@ -580,7 +580,7 @@ mod tests {
|
||||
};
|
||||
let result = decode(word).expect("owned register encoding");
|
||||
if wide && size == SIZE_MASK {
|
||||
assert_eq!(result, Err(()));
|
||||
assert_eq!(result, Err(Unsupported));
|
||||
continue;
|
||||
}
|
||||
let operand = result.unwrap();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE2 unpredicated widening and narrowing shifts with bottom/top placement.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -257,15 +258,14 @@ const ENCODINGS: &[Encoding] = &[
|
||||
},
|
||||
];
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let encoding = ENCODINGS
|
||||
.iter()
|
||||
.find(|entry| word & entry.mask == entry.value)?;
|
||||
let tsize = (((word >> TSIZE_HIGH_SHIFT) & 1) << TSIZE_HIGH_OFFSET)
|
||||
| ((word >> TSIZE_LOW_SHIFT) & TSIZE_LOW_MASK);
|
||||
if tsize == 0 || (encoding.kind.is_extract() && !tsize.is_power_of_two()) {
|
||||
return Some(Err(()));
|
||||
return Some(Err(Unsupported));
|
||||
}
|
||||
let size_log = u32::BITS - 1 - tsize.leading_zeros();
|
||||
let element_bits = BYTE_BITS << size_log;
|
||||
@@ -304,7 +304,7 @@ mod tests {
|
||||
| (immediate << IMMEDIATE_SHIFT);
|
||||
let result = decode(word).expect("owned encoding");
|
||||
if tsize == 0 || (encoding.kind.is_extract() && !tsize.is_power_of_two()) {
|
||||
assert_eq!(result, Err(()));
|
||||
assert_eq!(result, Err(Unsupported));
|
||||
continue;
|
||||
}
|
||||
let operand = result.unwrap();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE predicated FABS and FNEG.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::aarch64::floating::Format;
|
||||
|
||||
@@ -30,8 +31,7 @@ pub struct Operand {
|
||||
pub predicate: u8,
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let kind = match word & OPCODE_MASK {
|
||||
ABSOLUTE_OPCODE => Kind::Absolute,
|
||||
NEGATE_OPCODE => Kind::Negate,
|
||||
@@ -41,7 +41,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
HALF_SIZE => Format::Half,
|
||||
SINGLE_SIZE => Format::Single,
|
||||
DOUBLE_SIZE => Format::Double,
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
Some(Ok(Operand {
|
||||
kind,
|
||||
@@ -76,7 +76,7 @@ mod tests {
|
||||
(31, 31, 7)
|
||||
);
|
||||
}
|
||||
assert_eq!(decode(opcode), Some(Err(())));
|
||||
assert_eq!(decode(opcode), Some(Err(Unsupported)));
|
||||
}
|
||||
assert_eq!(decode(0x6580_8000), None);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! SVE LUTI2 and LUTI4.
|
||||
use crate::aarch64::Unsupported;
|
||||
use crate::aarch64::scalable::ElementSize;
|
||||
|
||||
const REGISTER_MASK: u32 = 31;
|
||||
@@ -50,8 +51,7 @@ impl Operand {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
let high_part = ((word >> PART_SHIFT) & 3) as u8;
|
||||
let (element, index_bits, part, table_registers) = if word & LUTI2_BYTE_MASK == LUTI2_BYTE {
|
||||
(ElementSize::Byte, 2, high_part, 1)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Unprivileged loads and stores (LDTR*, STTR*). Native code supports EL0 on
|
||||
//! directly mapped RAM only.
|
||||
use super::{MemoryTransfer, Register, Width, register};
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
const CLASS_MASK: u32 = 0x3f20_0c00;
|
||||
const UNPRIVILEGED_CLASS: u32 = 0x3800_0800;
|
||||
@@ -31,8 +32,7 @@ pub struct Operand {
|
||||
|
||||
/// None denotes another encoding class; Err denotes a reserved size/opcode.
|
||||
/// This class has neither writeback nor register-overlap restrictions.
|
||||
#[allow(clippy::result_unit_err)]
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
pub fn decode(word: u32) -> Option<Result<Operand, Unsupported>> {
|
||||
if word & CLASS_MASK != UNPRIVILEGED_CLASS {
|
||||
return None;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ pub fn decode(word: u32) -> Option<Result<Operand, ()>> {
|
||||
signed: true,
|
||||
width: Width::W32,
|
||||
},
|
||||
_ => return Some(Err(())),
|
||||
_ => return Some(Err(Unsupported)),
|
||||
};
|
||||
let immediate = ((word >> IMMEDIATE_SHIFT) & IMMEDIATE_MASK) as i32;
|
||||
Some(Ok(Operand {
|
||||
|
||||
+582
-597
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
//! Block boundaries, static successors and dynamic edges, found without emitting code.
|
||||
use super::{
|
||||
BlockProfile, ClockInstruction, ExitKind, MAX_BLOCK_INSTRUCTIONS, NOP_ENCODING,
|
||||
BlockProfile, ClockInstruction, ExitKind, Features, MAX_BLOCK_INSTRUCTIONS, NOP_ENCODING,
|
||||
PointerAuthentication, PointerAuthenticationOperation, SynchronousTrap, SystemInstruction,
|
||||
Terminator, ThreadRegisterInstruction, decode_clock_instruction, decode_pointer_authentication,
|
||||
decode_system_instruction, decode_terminator, decode_thread_register_instruction, memory,
|
||||
@@ -77,7 +77,7 @@ pub struct BlockAnalysis {
|
||||
/// continuations are candidates, since the callee may not return; dynamic
|
||||
/// targets and trap resumption are resolved at run time.
|
||||
pub fn analyze(source: &[u8], base: GuestAddress) -> Result<BlockAnalysis, BlockAnalysisError> {
|
||||
analyze_with_profile(source, base, BlockProfile::Ordinary)
|
||||
analyze_with_profile(source, base, BlockProfile::ORDINARY)
|
||||
}
|
||||
|
||||
pub fn analyze_with_profile(
|
||||
@@ -243,7 +243,7 @@ pub(super) fn parse(
|
||||
})?);
|
||||
source_bytes += 4;
|
||||
let word = u32::from_le_bytes(*bytes);
|
||||
if profile.supports_full_system() {
|
||||
if profile.has(Features::FULL_SYSTEM) {
|
||||
// PAuth hints share the hint space, so they are matched first.
|
||||
if let Some(decoded) =
|
||||
decode_pointer_authentication(pc, word).map_err(|error| BlockAnalysisError {
|
||||
@@ -273,7 +273,7 @@ pub(super) fn parse(
|
||||
// maintenance, exception entry and return, ends its block and
|
||||
// completes in the engine, which recomputes what derives from
|
||||
// it before the next fetch. The shared lane's PEs keep it.
|
||||
if profile == BlockProfile::SystemModeV1
|
||||
if profile == BlockProfile::new(Features::SYSTEM_MODE)
|
||||
&& matches!(
|
||||
crate::aarch64::system::synchronization::decode(word),
|
||||
Some(
|
||||
@@ -297,7 +297,8 @@ pub(super) fn parse(
|
||||
{
|
||||
// The shared lane executes these through the existing typed
|
||||
// all-writer memory service, not the single-agent CPU monitor.
|
||||
let checked = matches!(profile, BlockProfile::SystemModeSharedV1(_))
|
||||
let checked = (profile.has(Features::FULL_SYSTEM)
|
||||
&& profile.checked_memory().is_some())
|
||||
&& matches!(decoded.operation, system::SystemOperation::Exclusive(Ok(_)));
|
||||
if !checked {
|
||||
terminal = Some((pc, Terminator::System(decoded)));
|
||||
@@ -305,14 +306,14 @@ pub(super) fn parse(
|
||||
}
|
||||
}
|
||||
}
|
||||
if profile.supports_system()
|
||||
&& !profile.supports_full_system()
|
||||
if profile.has(Features::SYSTEM)
|
||||
&& !profile.has(Features::FULL_SYSTEM)
|
||||
&& let Some(decoded) =
|
||||
decode_system_instruction(pc, word).map_err(|error| BlockAnalysisError {
|
||||
pc,
|
||||
detail: error.0,
|
||||
})?
|
||||
&& (profile.supports_system_registers()
|
||||
&& (profile.has(Features::SYSTEM_REGISTERS)
|
||||
|| !matches!(
|
||||
decoded.operation,
|
||||
system::SystemOperation::Register(_)
|
||||
@@ -322,7 +323,7 @@ pub(super) fn parse(
|
||||
terminal = Some((pc, Terminator::System(decoded)));
|
||||
break;
|
||||
}
|
||||
if profile.supports_pointer_authentication()
|
||||
if profile.has(Features::POINTER_AUTHENTICATION)
|
||||
&& let Some(decoded) =
|
||||
decode_pointer_authentication(pc, word).map_err(|error| BlockAnalysisError {
|
||||
pc,
|
||||
@@ -332,7 +333,7 @@ pub(super) fn parse(
|
||||
terminal = Some((pc, Terminator::PointerAuthentication(decoded)));
|
||||
break;
|
||||
}
|
||||
if profile.supports_clock()
|
||||
if profile.has(Features::CLOCK)
|
||||
&& let Some(decoded) =
|
||||
decode_clock_instruction(pc, word).map_err(|error| BlockAnalysisError {
|
||||
pc,
|
||||
@@ -342,7 +343,7 @@ pub(super) fn parse(
|
||||
terminal = Some((pc, Terminator::Clock(decoded)));
|
||||
break;
|
||||
}
|
||||
if profile.supports_thread_registers()
|
||||
if profile.has(Features::THREAD_REGISTERS)
|
||||
&& let Some(decoded) =
|
||||
decode_thread_register_instruction(pc, word).map_err(|error| {
|
||||
BlockAnalysisError {
|
||||
@@ -354,7 +355,7 @@ pub(super) fn parse(
|
||||
terminal = Some((pc, Terminator::ThreadRegister(decoded)));
|
||||
break;
|
||||
}
|
||||
if profile.supports_amx()
|
||||
if profile.has(Features::AMX)
|
||||
&& let Some(decoded) =
|
||||
crate::amx::decode(pc, word).map_err(|error| BlockAnalysisError {
|
||||
pc,
|
||||
@@ -384,9 +385,9 @@ pub(super) fn parse(
|
||||
detail: "unadmitted original NOP provenance in checked memory profile".into(),
|
||||
});
|
||||
}
|
||||
if profile.supports_system()
|
||||
&& !profile.supports_full_system()
|
||||
&& !crate::extended::ordinary_permitted(&instruction.operation)
|
||||
if profile.has(Features::SYSTEM)
|
||||
&& !profile.has(Features::FULL_SYSTEM)
|
||||
&& !crate::scalable_context::ordinary_permitted(&instruction.operation)
|
||||
{
|
||||
return Err(BlockAnalysisError {
|
||||
pc,
|
||||
@@ -394,7 +395,7 @@ pub(super) fn parse(
|
||||
});
|
||||
}
|
||||
if let Operation::FloatingPoint(operand) = &instruction.operation
|
||||
&& (matches!(profile, BlockProfile::SystemModeSharedV1(_))
|
||||
&& ((profile.has(Features::FULL_SYSTEM) && profile.checked_memory().is_some())
|
||||
|| crate::x86_64::numerical_always_exits(operand))
|
||||
{
|
||||
// The checked full-system prefix has no inline numerical recipe.
|
||||
@@ -426,7 +427,7 @@ pub(super) fn parse(
|
||||
/// Validate and identify the consumed prefix without generating native code.
|
||||
/// Uses the same semantic lift and transfer boundaries as [`compile`].
|
||||
pub fn source_bytes(source: &[u8], base: GuestAddress) -> Result<usize, CompileError> {
|
||||
source_bytes_with_profile(source, base, BlockProfile::Ordinary)
|
||||
source_bytes_with_profile(source, base, BlockProfile::ORDINARY)
|
||||
}
|
||||
|
||||
pub fn source_bytes_with_profile(
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
//! Guest services a compiled function provides, and the ABI identity derived
|
||||
//! from them.
|
||||
use super::CheckedMemoryProfile;
|
||||
use crate::CompileError;
|
||||
use alloc::{format, string::String};
|
||||
use serde::{Serialize, Serializer, ser::SerializeSeq};
|
||||
|
||||
/// Shared by every compiled function; the features follow it in the identity.
|
||||
const ABI_PREFIX: &str = "x86_64-sysv-guest-state-v4";
|
||||
|
||||
/// A set of guest services. Each member admits the instructions that need the
|
||||
/// service, as runtime exits or native completions, and names itself in the
|
||||
/// ABI identity.
|
||||
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
pub struct Features(u16);
|
||||
|
||||
impl Features {
|
||||
pub const NONE: Self = Self(0);
|
||||
/// Software pointer authentication through helper exits. Keys and the PAuth
|
||||
/// version are chosen at run time, so cached code contains neither.
|
||||
pub const POINTER_AUTHENTICATION: Self = Self(1 << 0);
|
||||
/// CNTVCT_EL0 reads and ISB through the clock exit.
|
||||
pub const CLOCK: Self = Self(1 << 1);
|
||||
/// Thread-register reads and writes through the thread exit.
|
||||
pub const THREAD_REGISTERS: Self = Self(1 << 2);
|
||||
/// Apple AMX instructions through the AMX exit, against per-thread or per-PE
|
||||
/// state.
|
||||
pub const AMX: Self = Self(1 << 3);
|
||||
/// Restricted context-independent prefixes and checked System exits. This
|
||||
/// identifies a service boundary, not CPU feature availability.
|
||||
pub const SYSTEM: Self = Self(1 << 4);
|
||||
/// System-register accesses through the System exit.
|
||||
pub const SYSTEM_REGISTERS: Self = Self(1 << 5);
|
||||
/// The system-mode engine: guest VAs are native addresses through shadow
|
||||
/// paging, `GuestState` is exact at every instruction boundary, and every
|
||||
/// System-class instruction exits with kind 11. Other PEs run concurrently,
|
||||
/// so atomics are locked and barriers fence.
|
||||
pub const FULL_SYSTEM: Self = Self(1 << 6);
|
||||
/// Non-faulting self-loops stay resident, counted by a
|
||||
/// [`super::loop_budget::LoopBudget`].
|
||||
pub const RESIDENT_LOOPS: Self = Self(1 << 7);
|
||||
/// The two-argument entry with an [`crate::context::ExecutionContext`] in
|
||||
/// RSI, kept in R15, and a scalable specialization.
|
||||
pub const CONTEXT: Self = Self(1 << 8);
|
||||
/// The function returns at the guest's RET X30 instead of exiting to the
|
||||
/// dispatcher.
|
||||
pub const LEAF: Self = Self(1 << 9);
|
||||
|
||||
/// The system-mode engine's services.
|
||||
pub const SYSTEM_MODE: Self = Self::FULL_SYSTEM
|
||||
.union(Self::SYSTEM)
|
||||
.union(Self::SYSTEM_REGISTERS)
|
||||
.union(Self::POINTER_AUTHENTICATION)
|
||||
.union(Self::AMX);
|
||||
/// The process helpers a checked-memory block can call.
|
||||
pub const PROCESS_HELPERS: Self = Self::POINTER_AUTHENTICATION
|
||||
.union(Self::CLOCK)
|
||||
.union(Self::THREAD_REGISTERS);
|
||||
|
||||
const NAMES: [(Self, &'static str); 10] = [
|
||||
(Self::CONTEXT, "context"),
|
||||
(Self::POINTER_AUTHENTICATION, "pointer-authentication"),
|
||||
(Self::CLOCK, "clock"),
|
||||
(Self::THREAD_REGISTERS, "thread-registers"),
|
||||
(Self::AMX, "amx"),
|
||||
(Self::SYSTEM, "system"),
|
||||
(Self::SYSTEM_REGISTERS, "system-registers"),
|
||||
(Self::FULL_SYSTEM, "full-system"),
|
||||
(Self::RESIDENT_LOOPS, "resident-loops"),
|
||||
(Self::LEAF, "leaf"),
|
||||
];
|
||||
|
||||
pub const fn union(self, other: Self) -> Self {
|
||||
Self(self.0 | other.0)
|
||||
}
|
||||
pub const fn difference(self, other: Self) -> Self {
|
||||
Self(self.0 & !other.0)
|
||||
}
|
||||
pub const fn contains(self, other: Self) -> bool {
|
||||
self.0 & other.0 == other.0
|
||||
}
|
||||
pub const fn is_empty(self) -> bool {
|
||||
self.0 == 0
|
||||
}
|
||||
fn names(self) -> impl Iterator<Item = &'static str> {
|
||||
Self::NAMES
|
||||
.into_iter()
|
||||
.filter(move |(feature, _)| self.contains(*feature))
|
||||
.map(|(_, name)| name)
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitOr for Features {
|
||||
type Output = Self;
|
||||
fn bitor(self, other: Self) -> Self {
|
||||
self.union(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for Features {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.write_str("Features(")?;
|
||||
for (index, name) in self.names().enumerate() {
|
||||
if index > 0 {
|
||||
f.write_str("|")?;
|
||||
}
|
||||
f.write_str(name)?;
|
||||
}
|
||||
f.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Features {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
let mut names = serializer.serialize_seq(None)?;
|
||||
for name in self.names() {
|
||||
names.serialize_element(name)?;
|
||||
}
|
||||
names.end()
|
||||
}
|
||||
}
|
||||
|
||||
/// The services a compiled function provides and how its memory accesses are
|
||||
/// checked. Without checked memory, accesses go directly to guest RAM.
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
pub struct BlockProfile {
|
||||
features: Features,
|
||||
checked: Option<CheckedMemoryProfile>,
|
||||
}
|
||||
|
||||
impl BlockProfile {
|
||||
/// A direct-RAM block that exits to the dispatcher at every transfer.
|
||||
pub const ORDINARY: Self = Self::new(Features::NONE);
|
||||
|
||||
pub const fn new(features: Features) -> Self {
|
||||
Self {
|
||||
features,
|
||||
checked: None,
|
||||
}
|
||||
}
|
||||
/// The same services with every memory access through the checked memory
|
||||
/// service.
|
||||
pub const fn with_checked_memory(self, checked: CheckedMemoryProfile) -> Self {
|
||||
Self {
|
||||
checked: Some(checked),
|
||||
..self
|
||||
}
|
||||
}
|
||||
pub const fn features(self) -> Features {
|
||||
self.features
|
||||
}
|
||||
/// Whether the profile provides every service in `features`.
|
||||
pub const fn has(self, features: Features) -> bool {
|
||||
self.features.contains(features)
|
||||
}
|
||||
pub const fn checked_memory(self) -> Option<CheckedMemoryProfile> {
|
||||
self.checked
|
||||
}
|
||||
|
||||
/// The identity cached code is keyed by: one name per feature, then the
|
||||
/// checked memory profile.
|
||||
pub fn abi(self) -> String {
|
||||
let mut abi = String::from(ABI_PREFIX);
|
||||
abi.push_str(if self.has(Features::LEAF) {
|
||||
"-leaf"
|
||||
} else {
|
||||
"-block-exit"
|
||||
});
|
||||
for name in self.features.difference(Features::LEAF).names() {
|
||||
abi.push('+');
|
||||
abi.push_str(name);
|
||||
}
|
||||
if let Some(checked) = self.checked {
|
||||
abi.push('+');
|
||||
abi.push_str(checked.id());
|
||||
}
|
||||
abi
|
||||
}
|
||||
|
||||
/// Refuse the combinations no emitter implements.
|
||||
pub fn validate(self) -> Result<(), CompileError> {
|
||||
use Features as F;
|
||||
let features = self.features;
|
||||
let direct = self.checked.is_none();
|
||||
let valid = if features.contains(F::LEAF) || features.contains(F::CONTEXT) {
|
||||
direct && features.difference(F::LEAF | F::CONTEXT).is_empty()
|
||||
} else if features.contains(F::FULL_SYSTEM) {
|
||||
// The shared full-system lane checks SP alignment only.
|
||||
features == F::SYSTEM_MODE
|
||||
&& !matches!(self.checked, Some(CheckedMemoryProfile::AddressChecks(_)))
|
||||
} else if features.contains(F::SYSTEM) {
|
||||
direct
|
||||
&& features
|
||||
.difference(F::SYSTEM | F::SYSTEM_REGISTERS)
|
||||
.is_empty()
|
||||
} else if features.contains(F::RESIDENT_LOOPS) {
|
||||
direct && features == F::RESIDENT_LOOPS
|
||||
} else if !direct {
|
||||
features.is_empty() || features == F::PROCESS_HELPERS
|
||||
} else {
|
||||
// The clock exit shares the PAuth helper interface, and AMX state is
|
||||
// per guest thread.
|
||||
features.difference(F::PROCESS_HELPERS | F::AMX).is_empty()
|
||||
&& (!features.contains(F::CLOCK) || features.contains(F::POINTER_AUTHENTICATION))
|
||||
&& features.contains(F::THREAD_REGISTERS) == features.contains(F::AMX)
|
||||
};
|
||||
if valid {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(CompileError(format!("no emitter implements {self:?}")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use CheckedMemoryProfile::{SpAlignmentDisabled, SpAlignmentEnabled};
|
||||
use Features as F;
|
||||
|
||||
#[test]
|
||||
fn the_abi_names_each_feature_and_the_checked_profile() {
|
||||
assert_eq!(
|
||||
BlockProfile::ORDINARY.abi(),
|
||||
"x86_64-sysv-guest-state-v4-block-exit"
|
||||
);
|
||||
assert_eq!(
|
||||
BlockProfile::new(F::LEAF | F::CONTEXT).abi(),
|
||||
"x86_64-sysv-guest-state-v4-leaf+context"
|
||||
);
|
||||
assert_eq!(
|
||||
BlockProfile::new(F::PROCESS_HELPERS)
|
||||
.with_checked_memory(SpAlignmentEnabled)
|
||||
.abi(),
|
||||
"x86_64-sysv-guest-state-v4-block-exit+pointer-authentication+clock\
|
||||
+thread-registers+checked-gpr-memory-sa0-on-normal-wb-v4"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn profiles_have_distinct_abis() {
|
||||
let mut profiles = alloc::vec![
|
||||
BlockProfile::ORDINARY,
|
||||
BlockProfile::new(F::LEAF),
|
||||
BlockProfile::new(F::LEAF | F::CONTEXT),
|
||||
BlockProfile::new(F::CONTEXT),
|
||||
BlockProfile::new(F::RESIDENT_LOOPS),
|
||||
BlockProfile::new(F::SYSTEM),
|
||||
BlockProfile::new(F::SYSTEM | F::SYSTEM_REGISTERS),
|
||||
BlockProfile::new(F::SYSTEM_MODE),
|
||||
BlockProfile::new(F::POINTER_AUTHENTICATION),
|
||||
BlockProfile::new(F::POINTER_AUTHENTICATION | F::CLOCK),
|
||||
BlockProfile::new(F::THREAD_REGISTERS | F::AMX),
|
||||
BlockProfile::new(F::POINTER_AUTHENTICATION | F::THREAD_REGISTERS | F::AMX),
|
||||
BlockProfile::new(F::PROCESS_HELPERS | F::AMX),
|
||||
];
|
||||
for checked in [SpAlignmentEnabled, SpAlignmentDisabled] {
|
||||
profiles.push(BlockProfile::ORDINARY.with_checked_memory(checked));
|
||||
profiles.push(BlockProfile::new(F::PROCESS_HELPERS).with_checked_memory(checked));
|
||||
profiles.push(BlockProfile::new(F::SYSTEM_MODE).with_checked_memory(checked));
|
||||
}
|
||||
let mut abis = alloc::collections::BTreeSet::new();
|
||||
for profile in &profiles {
|
||||
assert_eq!(profile.validate(), Ok(()), "{profile:?}");
|
||||
assert!(abis.insert(profile.abi()), "{profile:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn combinations_without_an_emitter_are_refused() {
|
||||
for profile in [
|
||||
BlockProfile::new(F::CLOCK),
|
||||
BlockProfile::new(F::THREAD_REGISTERS),
|
||||
BlockProfile::new(F::AMX),
|
||||
BlockProfile::new(F::SYSTEM_REGISTERS),
|
||||
BlockProfile::new(F::FULL_SYSTEM),
|
||||
BlockProfile::new(F::LEAF | F::POINTER_AUTHENTICATION),
|
||||
BlockProfile::new(F::RESIDENT_LOOPS | F::POINTER_AUTHENTICATION),
|
||||
BlockProfile::new(F::SYSTEM | F::POINTER_AUTHENTICATION),
|
||||
BlockProfile::new(F::POINTER_AUTHENTICATION).with_checked_memory(SpAlignmentEnabled),
|
||||
BlockProfile::new(F::LEAF).with_checked_memory(SpAlignmentEnabled),
|
||||
BlockProfile::new(F::SYSTEM).with_checked_memory(SpAlignmentEnabled),
|
||||
] {
|
||||
assert!(profile.validate().is_err(), "{profile:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
//! Per-invocation iteration budget for resident blocks.
|
||||
|
||||
pub const RESIDENT_BLOCK_ABI: &str =
|
||||
"x86_64-sysv-guest-state-v2-block-exit-direct-ram-resident-budget-v1";
|
||||
|
||||
/// Native code counts the basic blocks it completes, including internal back
|
||||
/// edges. The caller keeps this context alive until native return.
|
||||
#[repr(C)]
|
||||
|
||||
@@ -68,46 +68,7 @@ impl CheckedMemoryProfile {
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn abi(self) -> &'static str {
|
||||
match self {
|
||||
Self::AddressChecks(_) => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-checked-memory-address-v5"
|
||||
}
|
||||
Self::SpAlignmentEnabled => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-checked-gpr-memory-sa0-on-normal-wb-v4"
|
||||
}
|
||||
Self::SpAlignmentDisabled => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-checked-gpr-memory-sa0-off-normal-wb-v4"
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Immutable identity for the distinct all-writer full-system lane.
|
||||
/// Preparation rejects other specializations before native emission.
|
||||
pub const fn shared_system_abi(self) -> &'static str {
|
||||
match self {
|
||||
Self::SpAlignmentEnabled => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-system-shared-normal-wb-sa-on-v1"
|
||||
}
|
||||
Self::SpAlignmentDisabled => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-system-shared-normal-wb-sa-off-v1"
|
||||
}
|
||||
_ => "unadmitted-system-shared-memory-specialization-v1",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn process_helpers_abi(self) -> &'static str {
|
||||
match self {
|
||||
Self::AddressChecks(_) => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-checked-memory-address-pauth-clock-thread-v3"
|
||||
}
|
||||
Self::SpAlignmentEnabled => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-checked-gpr-memory-sa0-on-normal-wb-pauth-clock-thread-v2"
|
||||
}
|
||||
Self::SpAlignmentDisabled => {
|
||||
"x86_64-sysv-guest-state-v3-context-block-exit-checked-gpr-memory-sa0-off-normal-wb-pauth-clock-thread-v2"
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The profile's name in a checked block's ABI identity.
|
||||
pub const fn id(self) -> &'static str {
|
||||
match self {
|
||||
Self::AddressChecks(_) => "checked-memory-address-v5",
|
||||
@@ -167,8 +128,8 @@ impl CheckedPlan {
|
||||
profile: CheckedMemoryProfile,
|
||||
outer: super::BlockProfile,
|
||||
) -> Result<Self, CompileError> {
|
||||
let process_helpers = outer.supports_checked_process_helpers();
|
||||
let system_helpers = matches!(outer, super::BlockProfile::SystemModeSharedV1(_));
|
||||
let process_helpers = outer.has(super::Features::PROCESS_HELPERS);
|
||||
let system_helpers = outer.has(super::Features::FULL_SYSTEM);
|
||||
if system_helpers
|
||||
&& !matches!(
|
||||
profile,
|
||||
@@ -250,6 +211,7 @@ impl CheckedPlan {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::block::Features;
|
||||
use alloc::vec::Vec;
|
||||
#[test]
|
||||
fn checked_process_helpers_use_distinct_immutable_abi_and_exact_terminals() {
|
||||
@@ -259,25 +221,31 @@ mod tests {
|
||||
CheckedMemoryProfile::SpAlignmentEnabled,
|
||||
CheckedMemoryProfile::SpAlignmentDisabled,
|
||||
] {
|
||||
let selected = BlockProfile::CheckedMemoryPauthClockThread(recipe);
|
||||
assert_ne!(selected.abi(), BlockProfile::CheckedMemory(recipe).abi());
|
||||
let selected = BlockProfile::new(Features::PROCESS_HELPERS).with_checked_memory(recipe);
|
||||
assert_ne!(
|
||||
selected.abi(),
|
||||
BlockProfile::AppleArm64eSoftwarePauthClockThreadV1.abi()
|
||||
BlockProfile::ORDINARY.with_checked_memory(recipe).abi()
|
||||
);
|
||||
assert!(selected.supports_pointer_authentication());
|
||||
assert!(selected.supports_clock());
|
||||
assert!(selected.supports_thread_registers());
|
||||
assert!(!selected.supports_system());
|
||||
assert_ne!(
|
||||
selected.abi(),
|
||||
BlockProfile::new(Features::PROCESS_HELPERS.union(Features::AMX)).abi()
|
||||
);
|
||||
assert!(selected.has(Features::POINTER_AUTHENTICATION));
|
||||
assert!(selected.has(Features::CLOCK));
|
||||
assert!(selected.has(Features::THREAD_REGISTERS));
|
||||
assert!(!selected.has(Features::SYSTEM));
|
||||
for terminal in [0xd503237fu32, 0xd53be040, 0xd5033fdf, 0xd53bd061] {
|
||||
// Original MOV X3,#0x44 prefix must survive before the helper.
|
||||
let source: Vec<_> = [0xd2800883u32, terminal, 0xd65f03c0]
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.collect();
|
||||
let plan =
|
||||
CompilationPlan::new(&source, base, selected, crate::TargetCpu::Baseline)
|
||||
.unwrap();
|
||||
let plan = CompilationPlan::new(
|
||||
&source,
|
||||
base,
|
||||
&crate::Options::new(selected, crate::TargetCpu::Baseline),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(plan.source_bytes(), 8);
|
||||
assert!(plan.memory_requirements().is_some());
|
||||
let compiled = plan.compile().unwrap();
|
||||
@@ -287,8 +255,10 @@ mod tests {
|
||||
CompilationPlan::new(
|
||||
&source,
|
||||
base,
|
||||
BlockProfile::CheckedMemory(recipe),
|
||||
crate::TargetCpu::Baseline
|
||||
&crate::Options::new(
|
||||
BlockProfile::ORDINARY.with_checked_memory(recipe),
|
||||
crate::TargetCpu::Baseline
|
||||
)
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
@@ -296,7 +266,12 @@ mod tests {
|
||||
// Authenticated data loads still need the helper reader.
|
||||
let load = 0xf8200400u32.to_le_bytes();
|
||||
assert!(
|
||||
CompilationPlan::new(&load, base, selected, crate::TargetCpu::Baseline).is_err()
|
||||
CompilationPlan::new(
|
||||
&load,
|
||||
base,
|
||||
&crate::Options::new(selected, crate::TargetCpu::Baseline)
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -315,8 +290,11 @@ mod tests {
|
||||
let plan = crate::block::CompilationPlan::new(
|
||||
&source,
|
||||
GuestAddress(0x1000),
|
||||
crate::block::BlockProfile::CheckedMemoryPauthClockThread(profile),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
crate::block::BlockProfile::new(Features::PROCESS_HELPERS)
|
||||
.with_checked_memory(profile),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let required = plan.memory_requirements().unwrap();
|
||||
@@ -352,8 +330,11 @@ mod tests {
|
||||
let plan = crate::block::CompilationPlan::new(
|
||||
&source,
|
||||
GuestAddress(0x1000),
|
||||
crate::block::BlockProfile::SystemModeSharedV1(specialization),
|
||||
target,
|
||||
&crate::Options::new(
|
||||
crate::block::BlockProfile::new(Features::SYSTEM_MODE)
|
||||
.with_checked_memory(specialization),
|
||||
target,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let required = plan.memory_requirements().unwrap();
|
||||
@@ -417,8 +398,11 @@ mod tests {
|
||||
let plan = crate::block::CompilationPlan::new(
|
||||
&source,
|
||||
GuestAddress(pc),
|
||||
crate::block::BlockProfile::SystemModeSharedV1(profile),
|
||||
target,
|
||||
&crate::Options::new(
|
||||
crate::block::BlockProfile::new(Features::SYSTEM_MODE)
|
||||
.with_checked_memory(profile),
|
||||
target,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let requirements = plan.memory_requirements().unwrap();
|
||||
@@ -506,8 +490,10 @@ mod tests {
|
||||
let plan = crate::block::CompilationPlan::new(
|
||||
&source,
|
||||
GuestAddress(0x1000),
|
||||
crate::block::BlockProfile::CheckedMemory(recipe),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
crate::block::BlockProfile::ORDINARY.with_checked_memory(recipe),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let requirements = plan
|
||||
|
||||
@@ -159,8 +159,10 @@ mod tests {
|
||||
let legacy = CompilationPlan::new(
|
||||
&bytes,
|
||||
SOURCE_PC,
|
||||
BlockProfile::CheckedMemory(original),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
BlockProfile::ORDINARY.with_checked_memory(original),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
@@ -175,8 +177,10 @@ mod tests {
|
||||
let specialized = CompilationPlan::new(
|
||||
&bytes,
|
||||
SOURCE_PC,
|
||||
BlockProfile::CheckedMemory(selected),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
BlockProfile::ORDINARY.with_checked_memory(selected),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let required = specialized
|
||||
@@ -208,8 +212,10 @@ mod tests {
|
||||
let plan = CompilationPlan::new(
|
||||
&bytes,
|
||||
SOURCE_PC,
|
||||
BlockProfile::CheckedMemory(profile),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
BlockProfile::ORDINARY.with_checked_memory(profile),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let required = plan.memory_requirements().unwrap().required_address_checks;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//! FEAT_CPA arithmetic within checked memory plans.
|
||||
use crate::x86_64::asm::Code;
|
||||
|
||||
use crate::{
|
||||
CompileError, GuestAddress, TargetCpu,
|
||||
aarch64::{Instruction, Operation},
|
||||
context::{memory::MemoryRequirements, pointer::PointerArithmeticRequirement},
|
||||
extended::Decoded,
|
||||
scalable_context::Decoded,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
@@ -79,7 +80,7 @@ impl CheckedOperation {
|
||||
|
||||
pub(crate) fn emit(
|
||||
&self,
|
||||
code: &mut Vec<u8>,
|
||||
code: &mut Code,
|
||||
pc: GuestAddress,
|
||||
target: TargetCpu,
|
||||
fixups: &mut Vec<(GuestAddress, GuestAddress, usize)>,
|
||||
@@ -160,8 +161,10 @@ mod tests {
|
||||
let plan = CompilationPlan::new(
|
||||
&bytes,
|
||||
SOURCE_PC,
|
||||
BlockProfile::CheckedMemory(profile(mode)),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
BlockProfile::ORDINARY.with_checked_memory(profile(mode)),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let requirements = plan.memory_requirements().unwrap();
|
||||
@@ -202,8 +205,10 @@ mod tests {
|
||||
CompilationPlan::new(
|
||||
&bytes,
|
||||
SOURCE_PC,
|
||||
BlockProfile::CheckedMemory(profile),
|
||||
TargetCpu::Baseline
|
||||
&crate::Options::new(
|
||||
BlockProfile::ORDINARY.with_checked_memory(profile),
|
||||
TargetCpu::Baseline
|
||||
)
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
@@ -214,8 +219,11 @@ mod tests {
|
||||
let plan = CompilationPlan::new(
|
||||
&bytes,
|
||||
SOURCE_PC,
|
||||
BlockProfile::CheckedMemory(profile(EffectivePointerChecks::Unchecked)),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
BlockProfile::ORDINARY
|
||||
.with_checked_memory(profile(EffectivePointerChecks::Unchecked)),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
@@ -251,13 +259,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn combined_profile_keeps_exact_raw_nop_provenance() {
|
||||
let profile = BlockProfile::CheckedMemory(profile(EffectivePointerChecks::Addition));
|
||||
let profile =
|
||||
BlockProfile::ORDINARY.with_checked_memory(profile(EffectivePointerChecks::Addition));
|
||||
assert!(
|
||||
CompilationPlan::new(
|
||||
&source(&[NOP, ADDPT_X0_X1_X2, RET_X30]),
|
||||
SOURCE_PC,
|
||||
profile,
|
||||
TargetCpu::Baseline
|
||||
&crate::Options::new(profile, TargetCpu::Baseline)
|
||||
)
|
||||
.is_ok()
|
||||
);
|
||||
@@ -265,8 +273,7 @@ mod tests {
|
||||
CompilationPlan::new(
|
||||
&source(&[LDP_X0_X0_X9_16, ADDPT_X0_X1_X2, RET_X30]),
|
||||
SOURCE_PC,
|
||||
profile,
|
||||
TargetCpu::Baseline
|
||||
&crate::Options::new(profile, TargetCpu::Baseline)
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
|
||||
@@ -143,7 +143,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
GuestAddress, TargetCpu,
|
||||
block::{BlockProfile, CheckedMemoryProfile, CompilationPlan},
|
||||
block::{BlockProfile, CheckedMemoryProfile, CompilationPlan, Features},
|
||||
};
|
||||
use alloc::vec;
|
||||
|
||||
@@ -156,10 +156,14 @@ mod tests {
|
||||
CheckedMemoryProfile::SpAlignmentEnabled,
|
||||
CheckedMemoryProfile::SpAlignmentDisabled,
|
||||
] {
|
||||
let profile = BlockProfile::SystemModeSharedV1(memory);
|
||||
let profile = BlockProfile::new(Features::SYSTEM_MODE).with_checked_memory(memory);
|
||||
let plan = || {
|
||||
CompilationPlan::new(&source, GuestAddress(0x4000), profile, TargetCpu::Baseline)
|
||||
.unwrap()
|
||||
CompilationPlan::new(
|
||||
&source,
|
||||
GuestAddress(0x4000),
|
||||
&crate::Options::new(profile, TargetCpu::Baseline),
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
let baseline = plan().compile().unwrap();
|
||||
let (actual, metadata) = plan().compile_profiled().unwrap();
|
||||
@@ -224,8 +228,11 @@ mod tests {
|
||||
let (_, metadata) = CompilationPlan::new(
|
||||
&source,
|
||||
GuestAddress(0x4000),
|
||||
BlockProfile::SystemModeSharedV1(CheckedMemoryProfile::SpAlignmentEnabled),
|
||||
TargetCpu::Baseline,
|
||||
&crate::Options::new(
|
||||
BlockProfile::new(Features::SYSTEM_MODE)
|
||||
.with_checked_memory(CheckedMemoryProfile::SpAlignmentEnabled),
|
||||
TargetCpu::Baseline,
|
||||
),
|
||||
)
|
||||
.unwrap()
|
||||
.compile_profiled()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Scalable numerical instructions that exit to a runtime service.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::{
|
||||
CompileError, GuestAddress,
|
||||
@@ -9,7 +10,7 @@ use crate::{
|
||||
sme::{extrema_scale, fp_matrix, fp_vector, fp8_conversion, fp8_matrix},
|
||||
sve::floating,
|
||||
},
|
||||
extended::ScalableProfile,
|
||||
scalable_context::ScalableProfile,
|
||||
};
|
||||
use alloc::format;
|
||||
|
||||
@@ -215,8 +216,8 @@ pub fn decode_scalable_numerical_instruction(
|
||||
} else if let Some(operand) = extrema_scale::decode(word) {
|
||||
ScalableNumericalOperation::SmeExtremaScale(operand)
|
||||
} else if let Some(result) = floating::Operation::decode(word) {
|
||||
let operand =
|
||||
result.map_err(|()| CompileError("reserved scalable numerical encoding".into()))?;
|
||||
let operand = result
|
||||
.map_err(|Unsupported| CompileError("reserved scalable numerical encoding".into()))?;
|
||||
if !operand.requires_numerical_completion() {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -250,8 +251,6 @@ mod tests {
|
||||
use crate::{
|
||||
TargetCpu,
|
||||
aarch64::scalable::{ScalableMode, VectorLength, profile::ScalableControls},
|
||||
block::BlockProfile,
|
||||
extended::block::{ExtendedBlockProfile, compile_for_profile},
|
||||
};
|
||||
|
||||
const PC: GuestAddress = GuestAddress(0x1000);
|
||||
@@ -342,10 +341,11 @@ mod tests {
|
||||
admit_scalable_numerical_instruction(decoded, profile, numerical).unwrap();
|
||||
assert_eq!(admitted.word(), word);
|
||||
assert_eq!(admitted.next_pc(), GuestAddress(0x1004));
|
||||
let compiled = compile_for_profile(
|
||||
let compiled = crate::testing::context_block(
|
||||
&word.to_le_bytes(),
|
||||
PC,
|
||||
ExtendedBlockProfile::new(profile, BlockProfile::Ordinary, numerical),
|
||||
profile,
|
||||
numerical,
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -378,14 +378,11 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(admitted.word(), word, "{id}");
|
||||
assert_eq!(admitted.next_pc(), GuestAddress(0x1004), "{id}");
|
||||
let compiled = compile_for_profile(
|
||||
let compiled = crate::testing::context_block(
|
||||
&word.to_le_bytes(),
|
||||
PC,
|
||||
ExtendedBlockProfile::new(
|
||||
profile,
|
||||
BlockProfile::Ordinary,
|
||||
NumericalFeatures::default(),
|
||||
),
|
||||
profile,
|
||||
NumericalFeatures::default(),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//!
|
||||
//! Native blocks return only the instruction's PC and exit kind; the runtime
|
||||
//! re-decodes the source word before applying the effect.
|
||||
use crate::aarch64::Unsupported;
|
||||
|
||||
use crate::{
|
||||
CompileError, GuestAddress,
|
||||
@@ -345,7 +346,7 @@ pub fn decode_system_mode_instruction(
|
||||
// Reserved sizes and opcodes stay with the ordinary decoder.
|
||||
match decoded {
|
||||
Ok(operand) => SystemOperation::Unprivileged(operand),
|
||||
Err(()) => return Ok(None),
|
||||
Err(Unsupported) => return Ok(None),
|
||||
}
|
||||
} else if let Some(access) = registers::decode_sys(word) {
|
||||
SystemOperation::Maintenance(access)
|
||||
|
||||
@@ -66,7 +66,7 @@ mod tests {
|
||||
fn shared_parser_requires_thread_profile_and_stops_before_unknown_successor() {
|
||||
use crate::{
|
||||
Lifter,
|
||||
block::{self, BlockProfile, SuccessorKind},
|
||||
block::{self, BlockProfile, Features, SuccessorKind},
|
||||
};
|
||||
use alloc::collections::BTreeSet;
|
||||
let base = GuestAddress(0x1000);
|
||||
@@ -77,12 +77,16 @@ mod tests {
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.collect();
|
||||
let profiles = [
|
||||
BlockProfile::Ordinary,
|
||||
BlockProfile::AppleArm64eSoftwarePauthV1,
|
||||
BlockProfile::AppleArm64eSoftwarePauthClockV1,
|
||||
BlockProfile::DarwinArm64ThreadV1,
|
||||
BlockProfile::AppleArm64eSoftwarePauthThreadV1,
|
||||
BlockProfile::AppleArm64eSoftwarePauthClockThreadV1,
|
||||
BlockProfile::ORDINARY,
|
||||
BlockProfile::new(Features::POINTER_AUTHENTICATION),
|
||||
BlockProfile::new(Features::POINTER_AUTHENTICATION.union(Features::CLOCK)),
|
||||
BlockProfile::new(Features::THREAD_REGISTERS.union(Features::AMX)),
|
||||
BlockProfile::new(
|
||||
Features::POINTER_AUTHENTICATION
|
||||
.union(Features::THREAD_REGISTERS)
|
||||
.union(Features::AMX),
|
||||
),
|
||||
BlockProfile::new(Features::PROCESS_HELPERS.union(Features::AMX)),
|
||||
];
|
||||
let mut abis = BTreeSet::new();
|
||||
for profile in profiles {
|
||||
@@ -91,8 +95,8 @@ mod tests {
|
||||
"cache ABI identities must be distinct"
|
||||
);
|
||||
let analyzed = block::analyze_with_profile(&source, base, profile);
|
||||
let compiled = block::compile_with_profile(&source, base, profile);
|
||||
if !profile.supports_thread_registers() {
|
||||
let compiled = crate::testing::block_with(&source, base, profile);
|
||||
if !profile.has(Features::THREAD_REGISTERS) {
|
||||
assert_eq!(analyzed.unwrap_err().pc.0, base.0 + INSTRUCTION_BYTES);
|
||||
assert!(compiled.is_err());
|
||||
continue;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Execution context passed to native code using the extended ABI.
|
||||
//! Execution context passed to native code using the context ABI.
|
||||
|
||||
pub mod memory;
|
||||
pub mod pointer;
|
||||
@@ -6,9 +6,6 @@ use core::ffi::c_void;
|
||||
|
||||
pub const EXECUTION_CONTEXT_VERSION: u32 = 1;
|
||||
pub const EXECUTION_CONTEXT_BYTES: u32 = 32;
|
||||
pub const CONTEXT_LEAF_ABI: &str = "x86_64-sysv-guest-state-v3-context-memory-v2-direct-ram";
|
||||
pub const CONTEXT_BLOCK_ABI: &str =
|
||||
"x86_64-sysv-guest-state-v3-context-memory-v2-block-exit-direct-ram";
|
||||
pub const SCALABLE_STATE_VIEW_BYTES: usize = 72;
|
||||
pub const EXECUTION_CONTEXT_MEMORY_OFFSET: u32 = 8;
|
||||
pub const EXECUTION_CONTEXT_SCALABLE_OFFSET: u32 = 16;
|
||||
|
||||
@@ -1,486 +0,0 @@
|
||||
//! Blocks compiled with an execution context. A service exit returns the PC of
|
||||
//! the instruction still to execute.
|
||||
|
||||
use super::{Decoded, INSTRUCTION_BYTES, ScalableProfile, context_wrapper, decode};
|
||||
use crate::{
|
||||
CompileError, GuestAddress, Lifter, NativeBlock, TargetCpu,
|
||||
aarch64::{Decoder, Operation, floating::features::NumericalFeatures},
|
||||
block::{
|
||||
self, BlockProfile, CompiledBlock, ExitKind, MAX_BLOCK_INSTRUCTIONS,
|
||||
scalable::{
|
||||
AdmittedScalableNumericalInstruction, ScalableNumericalOperation,
|
||||
admit_scalable_numerical_instruction, decode_scalable_numerical_instruction,
|
||||
},
|
||||
},
|
||||
context::memory::MemoryRequirements,
|
||||
x86_64,
|
||||
};
|
||||
use alloc::format;
|
||||
use alloc::string::ToString;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
const MOV_RAX_IMMEDIATE: &[u8] = &[0x48, 0xb8];
|
||||
const MOV_EDX_IMMEDIATE: u8 = 0xba;
|
||||
const RETURN: u8 = 0xc3;
|
||||
|
||||
/// Guest services and numerical feature availability remain distinct from host
|
||||
/// capabilities and the set of instruction mappings currently implemented.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct ExtendedBlockProfile {
|
||||
scalable: ScalableProfile,
|
||||
services: BlockProfile,
|
||||
numerical_features: NumericalFeatures,
|
||||
}
|
||||
|
||||
impl ExtendedBlockProfile {
|
||||
pub const fn new(
|
||||
scalable: ScalableProfile,
|
||||
services: BlockProfile,
|
||||
numerical_features: NumericalFeatures,
|
||||
) -> Self {
|
||||
Self {
|
||||
scalable,
|
||||
services,
|
||||
numerical_features,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn scalable(self) -> ScalableProfile {
|
||||
self.scalable
|
||||
}
|
||||
pub const fn services(self) -> BlockProfile {
|
||||
self.services
|
||||
}
|
||||
pub const fn numerical_features(self) -> NumericalFeatures {
|
||||
self.numerical_features
|
||||
}
|
||||
}
|
||||
|
||||
enum Terminal {
|
||||
Shared(CompiledBlock),
|
||||
Numerical(AdmittedScalableNumericalInstruction),
|
||||
}
|
||||
|
||||
/// Existing Ordinary traps remain ordinary boundaries. Other typed services
|
||||
/// cannot acquire permission from a successful decode or memory-effect result.
|
||||
fn reject_unavailable_service(pc: GuestAddress, word: u32) -> Result<(), CompileError> {
|
||||
if block::decode_trap(pc, word)?.is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
if block::decode_system_instruction(pc, word)?.is_some()
|
||||
|| block::decode_pointer_authentication(pc, word)?.is_some()
|
||||
|| block::decode_clock_instruction(pc, word)?.is_some()
|
||||
|| block::decode_thread_register_instruction(pc, word)?.is_some()
|
||||
|| crate::amx::decode(pc, word)?.is_some()
|
||||
{
|
||||
return Err(CompileError(format!(
|
||||
"context block service is not integrated at {:#x}",
|
||||
pc.0
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn shared_terminal(
|
||||
bytes: &[u8; INSTRUCTION_BYTES],
|
||||
pc: GuestAddress,
|
||||
profile: BlockProfile,
|
||||
target: TargetCpu,
|
||||
) -> Result<Option<CompiledBlock>, CompileError> {
|
||||
if let Ok(instruction) = Decoder.lift(pc, u32::from_le_bytes(*bytes))
|
||||
&& matches!(instruction.operation, Operation::FloatingPoint(_))
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let analysis = block::analyze_with_profile(bytes, pc, profile)
|
||||
.map_err(|error| CompileError(error.to_string()))?;
|
||||
// The ordinary scalar numerical boundary is deliberately excluded until
|
||||
// its low-V/upper-Z effects have been integrated in context mode.
|
||||
let permitted = analysis.trap.is_some()
|
||||
|| analysis.dynamic_edge.is_some()
|
||||
|| (analysis.terminator_pc.is_some() && !analysis.static_successors.is_empty());
|
||||
if permitted {
|
||||
block::compile_for_target(bytes, pc, profile, target).map(Some)
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_transfer(operation: &Operation) -> bool {
|
||||
matches!(
|
||||
operation,
|
||||
Operation::Branch { .. }
|
||||
| Operation::BranchCondition { .. }
|
||||
| Operation::BranchZero { .. }
|
||||
| Operation::BranchBit { .. }
|
||||
| Operation::Return
|
||||
)
|
||||
}
|
||||
|
||||
/// Compile a block prefix. Direct RAM, AdvSIMD/FP, mode writes and MOVPRFX are
|
||||
/// refused as in the context leaf compiler. `NumericalFeatures` must match the
|
||||
/// guest identity the runtime uses for completion.
|
||||
pub fn compile_for_profile(
|
||||
source: &[u8],
|
||||
base: GuestAddress,
|
||||
profile: ExtendedBlockProfile,
|
||||
target: TargetCpu,
|
||||
) -> Result<CompiledBlock, CompileError> {
|
||||
if profile.services != BlockProfile::Ordinary {
|
||||
return Err(CompileError(
|
||||
"context block services are not integrated".into(),
|
||||
));
|
||||
}
|
||||
if source.is_empty()
|
||||
|| !source.len().is_multiple_of(INSTRUCTION_BYTES)
|
||||
|| !base.0.is_multiple_of(INSTRUCTION_BYTES as u64)
|
||||
|| source.len() / INSTRUCTION_BYTES > MAX_BLOCK_INSTRUCTIONS
|
||||
{
|
||||
return Err(CompileError(
|
||||
"context block input must be aligned, nonempty and bounded".into(),
|
||||
));
|
||||
}
|
||||
let mut instructions = Vec::new();
|
||||
let mut terminal = None;
|
||||
let mut next_pc = base;
|
||||
let mut source_bytes = 0;
|
||||
for bytes in source.as_chunks::<INSTRUCTION_BYTES>().0 {
|
||||
let pc = next_pc;
|
||||
next_pc = GuestAddress(
|
||||
pc.0.checked_add(INSTRUCTION_BYTES as u64)
|
||||
.ok_or_else(|| CompileError("context block guest address overflow".into()))?,
|
||||
);
|
||||
source_bytes += INSTRUCTION_BYTES;
|
||||
let word = u32::from_le_bytes(*bytes);
|
||||
reject_unavailable_service(pc, word)?;
|
||||
if let Some(numerical) = decode_scalable_numerical_instruction(pc, word)? {
|
||||
let admitted = admit_scalable_numerical_instruction(
|
||||
numerical,
|
||||
profile.scalable,
|
||||
profile.numerical_features,
|
||||
)?;
|
||||
terminal = Some(Terminal::Numerical(admitted));
|
||||
break;
|
||||
}
|
||||
match decode(pc, word, profile.scalable, target) {
|
||||
Ok(instruction)
|
||||
if instruction.memory_requirements() != MemoryRequirements::default() =>
|
||||
{
|
||||
return Err(CompileError(format!(
|
||||
"context block memory entry is not integrated at {:#x}",
|
||||
pc.0
|
||||
)));
|
||||
}
|
||||
Ok(Decoded::Ordinary(instruction)) if is_transfer(&instruction.operation) => {
|
||||
terminal =
|
||||
shared_terminal(bytes, pc, profile.services, target)?.map(Terminal::Shared);
|
||||
debug_assert!(
|
||||
terminal.is_some(),
|
||||
"ordinary transfer has a shared boundary"
|
||||
);
|
||||
break;
|
||||
}
|
||||
Ok(instruction) => instructions.push((pc, instruction)),
|
||||
Err(error) => {
|
||||
if let Some(shared) = shared_terminal(bytes, pc, profile.services, target)? {
|
||||
terminal = Some(Terminal::Shared(shared));
|
||||
break;
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut code = context_wrapper();
|
||||
let mut source_map = Vec::with_capacity(instructions.len() + usize::from(terminal.is_some()));
|
||||
let mut fixups = Vec::new();
|
||||
for (pc, instruction) in instructions {
|
||||
source_map.push((pc, code.len()));
|
||||
super::emit_decoded(
|
||||
&mut code,
|
||||
pc,
|
||||
instruction,
|
||||
profile.scalable,
|
||||
target,
|
||||
&mut fixups,
|
||||
)?;
|
||||
}
|
||||
debug_assert!(fixups.is_empty(), "context block prefix cannot transfer");
|
||||
match terminal {
|
||||
Some(Terminal::Shared(shared)) => {
|
||||
let offset = code.len();
|
||||
source_map.extend(
|
||||
shared
|
||||
.native
|
||||
.source_map
|
||||
.into_iter()
|
||||
.map(|(pc, at)| (pc, at + offset)),
|
||||
);
|
||||
code.extend(shared.native.x86_64_code);
|
||||
}
|
||||
Some(Terminal::Numerical(instruction)) => {
|
||||
let pc = instruction.instruction_pc();
|
||||
source_map.push((pc, code.len()));
|
||||
let emitted = match *instruction.operation() {
|
||||
ScalableNumericalOperation::Sve(operation) => x86_64::sve::floating::emit(
|
||||
&mut code,
|
||||
instruction.word(),
|
||||
operation,
|
||||
profile.scalable.vector_length(),
|
||||
profile.numerical_features,
|
||||
pc,
|
||||
target,
|
||||
)?,
|
||||
ScalableNumericalOperation::SmeExtremaScale(operand) => {
|
||||
x86_64::sme::extrema_scale::emit(
|
||||
&mut code,
|
||||
operand,
|
||||
profile.scalable.vector_length(),
|
||||
profile.numerical_features,
|
||||
pc,
|
||||
target,
|
||||
)?
|
||||
}
|
||||
ScalableNumericalOperation::SmeVector(_)
|
||||
| ScalableNumericalOperation::SmeMatrix(_)
|
||||
| ScalableNumericalOperation::FixedFp8Conversion(_)
|
||||
| ScalableNumericalOperation::SmeFp8Conversion(_)
|
||||
| ScalableNumericalOperation::SmeFp8Matrix(_) => false,
|
||||
};
|
||||
if emitted {
|
||||
// The guarded family mapping owns the exact-PC cold exit.
|
||||
// Only its committed fast path reaches the continuation.
|
||||
code.extend(
|
||||
x86_64::block::emit_for_target(
|
||||
&[],
|
||||
None,
|
||||
instruction.next_pc(),
|
||||
target,
|
||||
x86_64::MemoryChecks::DEFAULT,
|
||||
)
|
||||
.x86_64_code,
|
||||
);
|
||||
} else {
|
||||
code.extend(MOV_RAX_IMMEDIATE);
|
||||
code.extend(pc.0.to_le_bytes());
|
||||
code.push(MOV_EDX_IMMEDIATE);
|
||||
code.extend((ExitKind::ScalableNumerical as u32).to_le_bytes());
|
||||
code.push(RETURN);
|
||||
}
|
||||
}
|
||||
None => code.extend(
|
||||
x86_64::block::emit_for_target(
|
||||
&[],
|
||||
None,
|
||||
next_pc,
|
||||
target,
|
||||
x86_64::MemoryChecks::DEFAULT,
|
||||
)
|
||||
.x86_64_code,
|
||||
),
|
||||
}
|
||||
Ok(CompiledBlock {
|
||||
native: NativeBlock {
|
||||
x86_64_code: code,
|
||||
source_map,
|
||||
},
|
||||
source_bytes,
|
||||
direct_exits: Vec::new(),
|
||||
fault_recovery: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::aarch64::scalable::{ScalableMode, VectorLength};
|
||||
use alloc::format;
|
||||
use alloc::string::ToString;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
const BASE: GuestAddress = GuestAddress(0x1000);
|
||||
const ADD_X5_ONE: u32 = 0x9100_04a5;
|
||||
const FADD_Z0_SINGLE: u32 = 0x6580_8020;
|
||||
const SVC: u32 = 0xd400_0001;
|
||||
const BRK: u32 = 0xd420_0000;
|
||||
const ERET: u32 = 0xd69f_03e0;
|
||||
const IRG: u32 = 0x9ac0_1000;
|
||||
const PACIBSP: u32 = 0xd503_237f;
|
||||
const CNTVCT: u32 = 0xd53b_e040;
|
||||
const TPIDRRO: u32 = 0xd53b_d060;
|
||||
const RET: u32 = 0xd65f_03c0;
|
||||
const PACGA_X1_X2_X3: u32 = 0x9ac3_3041;
|
||||
const LDRAA_X1_X2: u32 = 0xf820_0441;
|
||||
const LDRAB_X1_X2: u32 = 0xf8a0_0441;
|
||||
const SERVICE_WORDS: &[u32] = &[
|
||||
ERET,
|
||||
IRG,
|
||||
PACIBSP,
|
||||
CNTVCT,
|
||||
TPIDRRO,
|
||||
PACGA_X1_X2_X3,
|
||||
LDRAA_X1_X2,
|
||||
LDRAB_X1_X2,
|
||||
];
|
||||
|
||||
fn source(words: &[u32]) -> Vec<u8> {
|
||||
words.iter().flat_map(|word| word.to_le_bytes()).collect()
|
||||
}
|
||||
|
||||
fn profile(services: BlockProfile) -> ExtendedBlockProfile {
|
||||
ExtendedBlockProfile::new(
|
||||
ScalableProfile::new(
|
||||
VectorLength::from_bytes(16).unwrap(),
|
||||
ScalableMode::new(true, false),
|
||||
),
|
||||
services,
|
||||
NumericalFeatures::default(),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_entry_declines_every_nonordinary_service_profile() {
|
||||
for services in [
|
||||
BlockProfile::SystemV1,
|
||||
BlockProfile::AppleArm64eSoftwarePauthV1,
|
||||
BlockProfile::AppleArm64eSoftwarePauthClockV1,
|
||||
BlockProfile::DarwinArm64ThreadV1,
|
||||
BlockProfile::AppleArm64eSoftwarePauthThreadV1,
|
||||
BlockProfile::AppleArm64eSoftwarePauthClockThreadV1,
|
||||
] {
|
||||
let error = compile_for_profile(
|
||||
&source(&[RET]),
|
||||
BASE,
|
||||
profile(services),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("services are not integrated"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordinary_trap_extent_stays_distinct_from_forbidden_system_completion() {
|
||||
for trap in [SVC, BRK] {
|
||||
let compiled = compile_for_profile(
|
||||
&source(&[ADD_X5_ONE, trap, ERET]),
|
||||
BASE,
|
||||
profile(BlockProfile::Ordinary),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(compiled.source_bytes, 2 * INSTRUCTION_BYTES);
|
||||
assert_eq!(
|
||||
compiled
|
||||
.native
|
||||
.source_map
|
||||
.iter()
|
||||
.map(|row| row.0)
|
||||
.collect::<Vec<_>>(),
|
||||
[BASE, GuestAddress(BASE.0 + INSTRUCTION_BYTES as u64)]
|
||||
);
|
||||
}
|
||||
for &service in SERVICE_WORDS {
|
||||
for words in [vec![service, RET], vec![ADD_X5_ONE, service, RET]] {
|
||||
let offset = if words[0] == ADD_X5_ONE {
|
||||
INSTRUCTION_BYTES
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let error = compile_for_profile(
|
||||
&source(&words),
|
||||
BASE,
|
||||
profile(BlockProfile::Ordinary),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("service is not integrated"));
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains(&format!("{:#x}", BASE.0 + offset as u64))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unconsumed_service_after_numerical_boundary_does_not_expand_extent() {
|
||||
for &service in SERVICE_WORDS {
|
||||
let compiled = compile_for_profile(
|
||||
&source(&[ADD_X5_ONE, FADD_Z0_SINGLE, service]),
|
||||
BASE,
|
||||
profile(BlockProfile::Ordinary),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(compiled.source_bytes, 2 * INSTRUCTION_BYTES);
|
||||
assert_eq!(compiled.native.source_map.len(), 2);
|
||||
assert_eq!(
|
||||
compiled.native.source_map[1].0,
|
||||
GuestAddress(BASE.0 + INSTRUCTION_BYTES as u64)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strict_ordinary_ram_atomic_legacy_fp_and_prefix_declines_stay_explicit() {
|
||||
const LDR_X0_X1: u32 = 0xf940_0020;
|
||||
const CAS_X0_X1_X2: u32 = 0xc8a0_7c41;
|
||||
const FADD_S0_S1_S2: u32 = 0x1e22_2820;
|
||||
const MOVPRFX_Z0_Z1: u32 = 0x0420_bc20;
|
||||
for word in [LDR_X0_X1, CAS_X0_X1_X2, FADD_S0_S1_S2, MOVPRFX_Z0_Z1] {
|
||||
assert!(
|
||||
compile_for_profile(
|
||||
&source(&[ADD_X5_ONE, word, RET]),
|
||||
BASE,
|
||||
profile(BlockProfile::Ordinary),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn movprfx_pairs_remain_leaf_only_and_numerical_followers_decline() {
|
||||
const UNPREDICATED_PREFIX: u32 = 0x0420_bc20;
|
||||
const ZEROING_PREFIX: u32 = 0x0410_2020;
|
||||
const MERGING_PREFIX: u32 = 0x0411_2020;
|
||||
const AND_DESTRUCTIVE: u32 = 0x041a_0040;
|
||||
let block_profile = profile(BlockProfile::Ordinary);
|
||||
for prefix in [UNPREDICATED_PREFIX, ZEROING_PREFIX, MERGING_PREFIX] {
|
||||
let bytes = source(&[prefix, AND_DESTRUCTIVE, RET]);
|
||||
let leaf = crate::extended::compile_for_profile(
|
||||
&bytes,
|
||||
BASE,
|
||||
block_profile.scalable(),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
leaf.source_map.iter().map(|row| row.0).collect::<Vec<_>>(),
|
||||
[
|
||||
BASE,
|
||||
GuestAddress(BASE.0 + INSTRUCTION_BYTES as u64),
|
||||
GuestAddress(BASE.0 + 2 * INSTRUCTION_BYTES as u64),
|
||||
]
|
||||
);
|
||||
let error =
|
||||
compile_for_profile(&bytes, BASE, block_profile, TargetCpu::Baseline).unwrap_err();
|
||||
assert!(error.to_string().contains(&format!("{:#x}", BASE.0)));
|
||||
}
|
||||
let error = crate::extended::compile_for_profile(
|
||||
&source(&[UNPREDICATED_PREFIX, FADD_Z0_SINGLE, RET]),
|
||||
BASE,
|
||||
block_profile.scalable(),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("unsupported follower"));
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains(&format!("{:#x}", BASE.0 + INSTRUCTION_BYTES as u64))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,20 @@ extern crate std;
|
||||
|
||||
use alloc::format;
|
||||
use alloc::string::String;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
pub mod aarch64;
|
||||
pub mod amx;
|
||||
pub mod block;
|
||||
pub mod context;
|
||||
pub mod extended;
|
||||
pub mod scalable_context;
|
||||
mod state;
|
||||
mod target;
|
||||
#[cfg(test)]
|
||||
mod testing;
|
||||
pub mod wkdm;
|
||||
pub mod x86_64;
|
||||
|
||||
pub use state::{GuestState, NATIVE_ABI};
|
||||
pub use state::GuestState;
|
||||
pub use target::TargetCpu;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -84,44 +85,138 @@ impl core::fmt::Display for CompileError {
|
||||
}
|
||||
impl core::error::Error for CompileError {}
|
||||
|
||||
/// Compile one raw ARM64 leaf region ending in RET X30.
|
||||
/// Input addresses are retained in the output map. No Mach-O loading, external
|
||||
/// calls, PAC, privileged operations, or arbitrary RET targets.
|
||||
pub fn compile(code: &[u8], base: GuestAddress) -> Result<NativeBlock, CompileError> {
|
||||
compile_for_target(code, base, TargetCpu::Baseline)
|
||||
}
|
||||
pub fn compile_for_target(
|
||||
code: &[u8],
|
||||
base: GuestAddress,
|
||||
/// What [`compile`] translates for: the guest services and memory checks of a
|
||||
/// [`block::BlockProfile`], the host's [`TargetCpu`], and the guest's scalable
|
||||
/// and numerical specialization for the context ABI.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Options {
|
||||
profile: block::BlockProfile,
|
||||
target: TargetCpu,
|
||||
) -> Result<NativeBlock, CompileError> {
|
||||
if code.is_empty() || !code.len().is_multiple_of(4) || !base.0.is_multiple_of(4) {
|
||||
return Err(CompileError(
|
||||
"input and guest base must be nonempty/aligned to 4 bytes".into(),
|
||||
));
|
||||
scalable: Option<scalable_context::ScalableProfile>,
|
||||
numerical: aarch64::floating::features::NumericalFeatures,
|
||||
checks: x86_64::MemoryChecks,
|
||||
native: x86_64::NativeSystem,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub const fn new(profile: block::BlockProfile, target: TargetCpu) -> Self {
|
||||
Self {
|
||||
profile,
|
||||
target,
|
||||
scalable: None,
|
||||
numerical: aarch64::floating::features::NumericalFeatures::new(false, false, false),
|
||||
checks: x86_64::MemoryChecks::DEFAULT,
|
||||
native: x86_64::NativeSystem::NONE,
|
||||
}
|
||||
}
|
||||
let mut instructions = vec![];
|
||||
for (index, bytes) in code.as_chunks::<4>().0.iter().enumerate() {
|
||||
let pc = GuestAddress(
|
||||
base.0
|
||||
.checked_add((index as u64) * 4)
|
||||
.ok_or_else(|| CompileError("guest address overflow".into()))?,
|
||||
);
|
||||
let encoding = u32::from_le_bytes(*bytes);
|
||||
let instruction = aarch64::Decoder
|
||||
.lift(pc, encoding)
|
||||
.map_err(|e| CompileError(format!("unsupported ARM64 semantics: {e:?}")))?;
|
||||
instructions.push(instruction);
|
||||
/// The guest's scalable specialization, which [`block::Features::CONTEXT`]
|
||||
/// requires.
|
||||
pub const fn with_scalable(self, scalable: scalable_context::ScalableProfile) -> Self {
|
||||
Self {
|
||||
scalable: Some(scalable),
|
||||
..self
|
||||
}
|
||||
}
|
||||
if !matches!(
|
||||
instructions.last().unwrap().operation,
|
||||
aarch64::Operation::Return
|
||||
) {
|
||||
return Err(CompileError("leaf region must end in RET X30".into()));
|
||||
/// The numerical features a context block's numerical completions assume;
|
||||
/// they must match the guest identity the runtime completes with.
|
||||
pub const fn with_numerical_features(
|
||||
self,
|
||||
numerical: aarch64::floating::features::NumericalFeatures,
|
||||
) -> Self {
|
||||
Self { numerical, ..self }
|
||||
}
|
||||
x86_64::Emitter
|
||||
.emit_for_target(&instructions, target)
|
||||
.map_err(|e| CompileError(format!("x86 emission failed: {e:?}")))
|
||||
/// Emit the memory checks of the regime's SCTLR_ELx: the system-mode engine
|
||||
/// compiles separate blocks for SA (or SA0 at EL0) clear, where an access
|
||||
/// through a misaligned SP proceeds; for A set, where any access not
|
||||
/// aligned to its elements faults; and for nAA set, where an ordered access
|
||||
/// may cross its 16-byte granule. Only the direct system-mode profile admits
|
||||
/// checks other than [`x86_64::MemoryChecks::DEFAULT`], and a host without
|
||||
/// the capability an unchecked SP then needs refuses.
|
||||
pub const fn with_memory_checks(self, checks: x86_64::MemoryChecks) -> Self {
|
||||
Self { checks, ..self }
|
||||
}
|
||||
/// Complete a terminal DC ZVA or DC clean operation natively
|
||||
/// ([`x86_64::NativeSystem`]): the system-mode engine compiles separate
|
||||
/// blocks for the contexts where those operations neither trap nor are
|
||||
/// UNDEFINED. Only the direct system-mode profile admits them.
|
||||
pub const fn with_native_system(self, native: x86_64::NativeSystem) -> Self {
|
||||
Self { native, ..self }
|
||||
}
|
||||
|
||||
pub const fn profile(&self) -> block::BlockProfile {
|
||||
self.profile
|
||||
}
|
||||
pub const fn target(&self) -> TargetCpu {
|
||||
self.target
|
||||
}
|
||||
pub const fn scalable(&self) -> Option<scalable_context::ScalableProfile> {
|
||||
self.scalable
|
||||
}
|
||||
pub const fn numerical_features(&self) -> aarch64::floating::features::NumericalFeatures {
|
||||
self.numerical
|
||||
}
|
||||
pub const fn memory_checks(&self) -> x86_64::MemoryChecks {
|
||||
self.checks
|
||||
}
|
||||
pub const fn native_system(&self) -> x86_64::NativeSystem {
|
||||
self.native
|
||||
}
|
||||
|
||||
/// Refuse options no emitter implements.
|
||||
pub fn validate(&self) -> Result<(), CompileError> {
|
||||
use block::Features;
|
||||
self.profile.validate()?;
|
||||
let context = self.profile.has(Features::CONTEXT);
|
||||
if context != self.scalable.is_some() {
|
||||
return Err(CompileError(format!(
|
||||
"{:?} {} a scalable specialization",
|
||||
self.profile,
|
||||
if context { "requires" } else { "takes no" }
|
||||
)));
|
||||
}
|
||||
let system_mode = self.profile == block::BlockProfile::new(Features::SYSTEM_MODE);
|
||||
if self.checks != x86_64::MemoryChecks::DEFAULT && !system_mode {
|
||||
return Err(CompileError(format!(
|
||||
"{:?} makes only the default memory checks",
|
||||
self.profile
|
||||
)));
|
||||
}
|
||||
if let Some(bytes) = self.native.zero_block {
|
||||
use x86_64::zero_block::{MAX_BYTES, MIN_BYTES};
|
||||
if !system_mode {
|
||||
return Err(CompileError(format!(
|
||||
"{:?} keeps DC ZVA's System exit",
|
||||
self.profile
|
||||
)));
|
||||
}
|
||||
if !bytes.is_power_of_two() || !(MIN_BYTES..=MAX_BYTES).contains(&bytes) {
|
||||
return Err(CompileError(format!(
|
||||
"a {bytes}-byte DC ZVA block is not a DCZID_EL0.BS size"
|
||||
)));
|
||||
}
|
||||
}
|
||||
if !self.native.cache_clean.is_empty() && !system_mode {
|
||||
return Err(CompileError(format!(
|
||||
"{:?} keeps the DC clean operations' System exit",
|
||||
self.profile
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Translate the guest code at `source`, whose first instruction is at
|
||||
/// `base`, for `options`: one validated decode, then the emitters its
|
||||
/// profile's features select. A block ends at its first transfer, trap or
|
||||
/// runtime exit, or at the input boundary, and bytes after it are unconsumed;
|
||||
/// a [`block::Features::LEAF`] function translates the whole input, which ends
|
||||
/// in RET X30. Unknown semantics are compile errors.
|
||||
pub fn compile(
|
||||
source: &[u8],
|
||||
base: GuestAddress,
|
||||
options: &Options,
|
||||
) -> Result<block::CompiledBlock, CompileError> {
|
||||
block::CompilationPlan::new(source, base, options)?.compile()
|
||||
}
|
||||
|
||||
pub trait Backend<I> {
|
||||
@@ -147,8 +242,49 @@ pub mod platform {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::x86_64::asm::Code;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
#[test]
|
||||
fn options_without_an_emitter_are_refused() {
|
||||
use aarch64::scalable::{ScalableMode, VectorLength};
|
||||
use block::{BlockProfile, Features};
|
||||
let scalable = scalable_context::ScalableProfile::new(
|
||||
VectorLength::from_bytes(16).unwrap(),
|
||||
ScalableMode::new(true, false),
|
||||
);
|
||||
let options = |features| Options::new(BlockProfile::new(features), TargetCpu::Baseline);
|
||||
let unaligned = x86_64::MemoryChecks {
|
||||
stack_alignment: false,
|
||||
..x86_64::MemoryChecks::DEFAULT
|
||||
};
|
||||
let zero = |bytes| x86_64::NativeSystem {
|
||||
zero_block: Some(bytes),
|
||||
..x86_64::NativeSystem::NONE
|
||||
};
|
||||
for valid in [
|
||||
options(Features::NONE),
|
||||
options(Features::LEAF),
|
||||
options(Features::CONTEXT).with_scalable(scalable),
|
||||
options(Features::SYSTEM_MODE).with_memory_checks(unaligned),
|
||||
options(Features::SYSTEM_MODE).with_native_system(zero(64)),
|
||||
] {
|
||||
assert_eq!(valid.validate(), Ok(()), "{valid:?}");
|
||||
}
|
||||
for invalid in [
|
||||
options(Features::CONTEXT),
|
||||
options(Features::NONE).with_scalable(scalable),
|
||||
options(Features::NONE).with_memory_checks(unaligned),
|
||||
options(Features::NONE).with_native_system(zero(64)),
|
||||
options(Features::SYSTEM_MODE).with_native_system(zero(48)),
|
||||
options(Features::CLOCK),
|
||||
] {
|
||||
assert!(invalid.validate().is_err(), "{invalid:?}");
|
||||
assert!(compile(&0xd65f_03c0_u32.to_le_bytes(), GuestAddress(0), &invalid).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polynomial64_lowering_requires_independent_pclmul_and_selects_original_halves() {
|
||||
use x86_64::isa::SimdOpcode;
|
||||
@@ -157,7 +293,7 @@ mod tests {
|
||||
assert!(!TargetCpu::Sse42.supports(opcode.requires()));
|
||||
assert!(
|
||||
std::panic::catch_unwind(|| {
|
||||
opcode.register(&mut Vec::new(), 0, 1, TargetCpu::Sse42);
|
||||
opcode.register(&mut Code::new(), 0, 1, TargetCpu::Sse42);
|
||||
})
|
||||
.is_err()
|
||||
);
|
||||
@@ -166,13 +302,14 @@ mod tests {
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.collect();
|
||||
let baseline = compile(&source, GuestAddress(0x1000)).unwrap();
|
||||
let baseline = crate::testing::leaf(&source, GuestAddress(0x1000)).unwrap();
|
||||
let sse42 =
|
||||
compile_for_target(&source, GuestAddress(0x1000), TargetCpu::Sse42).unwrap();
|
||||
crate::testing::leaf_for(&source, GuestAddress(0x1000), TargetCpu::Sse42).unwrap();
|
||||
assert_eq!(baseline.x86_64_code, sse42.x86_64_code);
|
||||
let pclmul =
|
||||
compile_for_target(&source, GuestAddress(0x1000), TargetCpu::Pclmulqdq).unwrap();
|
||||
let combined = compile_for_target(
|
||||
crate::testing::leaf_for(&source, GuestAddress(0x1000), TargetCpu::Pclmulqdq)
|
||||
.unwrap();
|
||||
let combined = crate::testing::leaf_for(
|
||||
&source,
|
||||
GuestAddress(0x1000),
|
||||
TargetCpu::Sse42.with_pclmulqdq(),
|
||||
@@ -195,8 +332,10 @@ mod tests {
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.collect();
|
||||
assert_eq!(
|
||||
compile(&source, GuestAddress(0x1000)).unwrap().x86_64_code,
|
||||
compile_for_target(&source, GuestAddress(0x1000), TargetCpu::Pclmulqdq)
|
||||
crate::testing::leaf(&source, GuestAddress(0x1000))
|
||||
.unwrap()
|
||||
.x86_64_code,
|
||||
crate::testing::leaf_for(&source, GuestAddress(0x1000), TargetCpu::Pclmulqdq)
|
||||
.unwrap()
|
||||
.x86_64_code,
|
||||
);
|
||||
@@ -210,16 +349,18 @@ mod tests {
|
||||
.flat_map(|word| word.to_le_bytes())
|
||||
.collect();
|
||||
assert!(
|
||||
compile(&source, GuestAddress(0))
|
||||
crate::testing::leaf(&source, GuestAddress(0))
|
||||
.unwrap_err()
|
||||
.0
|
||||
.contains("HostCapabilityRequired")
|
||||
);
|
||||
assert!(compile_for_target(&source, GuestAddress(0), TargetCpu::AtomicLoad16).is_ok());
|
||||
let blocked = block::compile(&source, GuestAddress(0)).unwrap_err();
|
||||
assert!(
|
||||
crate::testing::leaf_for(&source, GuestAddress(0), TargetCpu::AtomicLoad16).is_ok()
|
||||
);
|
||||
let blocked = crate::testing::block(&source, GuestAddress(0)).unwrap_err();
|
||||
assert!(blocked.0.contains("HostCapabilityRequired"));
|
||||
assert!(
|
||||
block::compile_for_target(
|
||||
crate::testing::block_for(
|
||||
&source,
|
||||
GuestAddress(0),
|
||||
block::BlockProfile::default(),
|
||||
@@ -233,7 +374,7 @@ mod tests {
|
||||
.iter()
|
||||
.flat_map(|word| word.to_le_bytes())
|
||||
.collect();
|
||||
assert!(compile(&source, GuestAddress(0)).is_ok());
|
||||
assert!(crate::testing::leaf(&source, GuestAddress(0)).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,8 +395,8 @@ mod tests {
|
||||
TargetCpu::Cx16,
|
||||
] {
|
||||
let permitted = !requires_cx16 || target.supports(TargetCpu::Cx16);
|
||||
let leaf = compile_for_target(&source, GuestAddress(0), target);
|
||||
let block = block::compile_for_target(
|
||||
let leaf = crate::testing::leaf_for(&source, GuestAddress(0), target);
|
||||
let block = crate::testing::block_for(
|
||||
&source,
|
||||
GuestAddress(0),
|
||||
block::BlockProfile::default(),
|
||||
@@ -290,14 +431,14 @@ mod tests {
|
||||
vec![0xd65f0000],
|
||||
] {
|
||||
let bytes: Vec<_> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
|
||||
assert!(compile(&bytes, GuestAddress(0)).is_err());
|
||||
assert!(crate::testing::leaf(&bytes, GuestAddress(0)).is_err());
|
||||
}
|
||||
assert!(compile(&[0, 0, 0], GuestAddress(0)).is_err());
|
||||
assert!(compile(&0xd65f03c0u32.to_le_bytes(), GuestAddress(1)).is_err());
|
||||
assert!(crate::testing::leaf(&[0, 0, 0], GuestAddress(0)).is_err());
|
||||
assert!(crate::testing::leaf(&0xd65f03c0u32.to_le_bytes(), GuestAddress(1)).is_err());
|
||||
let code: Vec<_> = [0xd503201fu32, 0xd65f03c0]
|
||||
.iter()
|
||||
.flat_map(|w| w.to_le_bytes())
|
||||
.collect();
|
||||
assert!(compile(&code, GuestAddress(u64::MAX - 3)).is_err());
|
||||
assert!(crate::testing::leaf(&code, GuestAddress(u64::MAX - 3)).is_err());
|
||||
}
|
||||
}
|
||||
+499
-372
File diff suppressed because it is too large.
Load diff
+9
-4
@@ -1,4 +1,5 @@
|
||||
//! Decoding one instruction and admitting it under a scalable profile.
|
||||
use crate::aarch64::Unsupported;
|
||||
use alloc::{format, vec::Vec};
|
||||
|
||||
use super::{Decoded, ScalableProfile, ordinary_permitted};
|
||||
@@ -69,8 +70,12 @@ impl Admission<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn operand<T>(&self, decoded: Result<T, ()>, encoding: &str) -> Result<T, CompileError> {
|
||||
decoded.map_err(|()| self.error(&format!("reserved {encoding} encoding")))
|
||||
fn operand<T>(
|
||||
&self,
|
||||
decoded: Result<T, Unsupported>,
|
||||
encoding: &str,
|
||||
) -> Result<T, CompileError> {
|
||||
decoded.map_err(|Unsupported| self.error(&format!("reserved {encoding} encoding")))
|
||||
}
|
||||
|
||||
fn require(&mut self, features: ScalableFeatures) -> Result<(), CompileError> {
|
||||
@@ -89,7 +94,7 @@ impl Admission<'_> {
|
||||
/// The common streaming SVE admission: a valid operand, streaming mode and SME.
|
||||
fn streaming_sme<T>(
|
||||
&mut self,
|
||||
decoded: Result<T, ()>,
|
||||
decoded: Result<T, Unsupported>,
|
||||
encoding: &str,
|
||||
) -> Result<T, CompileError> {
|
||||
let operand = self.operand(decoded, encoding)?;
|
||||
@@ -273,7 +278,7 @@ pub(super) fn decode_recording_features(
|
||||
if let Some(decoded) = integer_products::decode(word) {
|
||||
let operand = check.streaming_sme(decoded, "streaming integer product")?;
|
||||
x86_64::sve::integer_products::validate(operand)
|
||||
.map_err(|()| check.error("invalid streaming integer product operand"))?;
|
||||
.map_err(|Unsupported| check.error("invalid streaming integer product operand"))?;
|
||||
return Ok(Decoded::IntegerProducts(operand));
|
||||
}
|
||||
if let Some(operand) = integer_dots::decode(word) {
|
||||
@@ -0,0 +1,469 @@
|
||||
//! Blocks compiled with an execution context. A service exit returns the PC of
|
||||
//! the instruction still to execute.
|
||||
use super::{Decoded, INSTRUCTION_BYTES, ScalableProfile, context_wrapper, decode};
|
||||
use crate::{
|
||||
CompileError, GuestAddress, Lifter, NativeBlock, Options, TargetCpu,
|
||||
aarch64::{Decoder, Operation, floating::features::NumericalFeatures},
|
||||
block::{
|
||||
self, BlockProfile, CompilationPlan, CompiledBlock, ExitKind, MAX_BLOCK_INSTRUCTIONS,
|
||||
scalable::{
|
||||
AdmittedScalableNumericalInstruction, ScalableNumericalOperation,
|
||||
admit_scalable_numerical_instruction, decode_scalable_numerical_instruction,
|
||||
},
|
||||
},
|
||||
context::memory::MemoryRequirements,
|
||||
x86_64,
|
||||
};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::format;
|
||||
use alloc::string::ToString;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
enum Terminal {
|
||||
/// An ordinary block of the one terminal instruction.
|
||||
Shared(Box<CompilationPlan>),
|
||||
Numerical(AdmittedScalableNumericalInstruction),
|
||||
}
|
||||
|
||||
/// Existing Ordinary traps remain ordinary boundaries. Other typed services
|
||||
/// cannot acquire permission from a successful decode or memory-effect result.
|
||||
fn reject_unavailable_service(pc: GuestAddress, word: u32) -> Result<(), CompileError> {
|
||||
if block::decode_trap(pc, word)?.is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
if block::decode_system_instruction(pc, word)?.is_some()
|
||||
|| block::decode_pointer_authentication(pc, word)?.is_some()
|
||||
|| block::decode_clock_instruction(pc, word)?.is_some()
|
||||
|| block::decode_thread_register_instruction(pc, word)?.is_some()
|
||||
|| crate::amx::decode(pc, word)?.is_some()
|
||||
{
|
||||
return Err(CompileError(format!(
|
||||
"context block service is not integrated at {:#x}",
|
||||
pc.0
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn shared_terminal(
|
||||
bytes: &[u8; INSTRUCTION_BYTES],
|
||||
pc: GuestAddress,
|
||||
target: TargetCpu,
|
||||
) -> Result<Option<CompilationPlan>, CompileError> {
|
||||
if let Ok(instruction) = Decoder.lift(pc, u32::from_le_bytes(*bytes))
|
||||
&& matches!(instruction.operation, Operation::FloatingPoint(_))
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let analysis = block::analyze_with_profile(bytes, pc, BlockProfile::ORDINARY)
|
||||
.map_err(|error| CompileError(error.to_string()))?;
|
||||
// The ordinary scalar numerical boundary is deliberately excluded until
|
||||
// its low-V/upper-Z effects have been integrated in context mode.
|
||||
let permitted = analysis.trap.is_some()
|
||||
|| analysis.dynamic_edge.is_some()
|
||||
|| (analysis.terminator_pc.is_some() && !analysis.static_successors.is_empty());
|
||||
if permitted {
|
||||
CompilationPlan::new(bytes, pc, &Options::new(BlockProfile::ORDINARY, target)).map(Some)
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_transfer(operation: &Operation) -> bool {
|
||||
matches!(
|
||||
operation,
|
||||
Operation::Branch { .. }
|
||||
| Operation::BranchCondition { .. }
|
||||
| Operation::BranchZero { .. }
|
||||
| Operation::BranchBit { .. }
|
||||
| Operation::Return
|
||||
)
|
||||
}
|
||||
|
||||
/// A decoded context block prefix. Direct RAM, AdvSIMD/FP, mode writes and
|
||||
/// MOVPRFX are refused as in the context leaf compiler.
|
||||
pub struct Prefix {
|
||||
instructions: Vec<(GuestAddress, Decoded)>,
|
||||
terminal: Option<Terminal>,
|
||||
next_pc: GuestAddress,
|
||||
source_bytes: usize,
|
||||
scalable: ScalableProfile,
|
||||
numerical: NumericalFeatures,
|
||||
target: TargetCpu,
|
||||
}
|
||||
|
||||
impl Prefix {
|
||||
/// Decode a block prefix. `numerical` must match the guest identity the
|
||||
/// runtime uses for completion.
|
||||
pub(crate) fn decode(
|
||||
source: &[u8],
|
||||
base: GuestAddress,
|
||||
scalable: ScalableProfile,
|
||||
numerical: NumericalFeatures,
|
||||
target: TargetCpu,
|
||||
) -> Result<Self, CompileError> {
|
||||
if source.is_empty()
|
||||
|| !source.len().is_multiple_of(INSTRUCTION_BYTES)
|
||||
|| !base.0.is_multiple_of(INSTRUCTION_BYTES as u64)
|
||||
|| source.len() / INSTRUCTION_BYTES > MAX_BLOCK_INSTRUCTIONS
|
||||
{
|
||||
return Err(CompileError(
|
||||
"context block input must be aligned, nonempty and bounded".into(),
|
||||
));
|
||||
}
|
||||
let mut instructions = Vec::new();
|
||||
let mut terminal = None;
|
||||
let mut next_pc = base;
|
||||
let mut source_bytes = 0;
|
||||
for bytes in source.as_chunks::<INSTRUCTION_BYTES>().0 {
|
||||
let pc = next_pc;
|
||||
next_pc = GuestAddress(
|
||||
pc.0.checked_add(INSTRUCTION_BYTES as u64)
|
||||
.ok_or_else(|| CompileError("context block guest address overflow".into()))?,
|
||||
);
|
||||
source_bytes += INSTRUCTION_BYTES;
|
||||
let word = u32::from_le_bytes(*bytes);
|
||||
reject_unavailable_service(pc, word)?;
|
||||
if let Some(numerical_instruction) = decode_scalable_numerical_instruction(pc, word)? {
|
||||
let admitted = admit_scalable_numerical_instruction(
|
||||
numerical_instruction,
|
||||
scalable,
|
||||
numerical,
|
||||
)?;
|
||||
terminal = Some(Terminal::Numerical(admitted));
|
||||
break;
|
||||
}
|
||||
match decode(pc, word, scalable, target) {
|
||||
Ok(instruction)
|
||||
if instruction.memory_requirements() != MemoryRequirements::default() =>
|
||||
{
|
||||
return Err(CompileError(format!(
|
||||
"context block memory entry is not integrated at {:#x}",
|
||||
pc.0
|
||||
)));
|
||||
}
|
||||
Ok(Decoded::Ordinary(instruction)) if is_transfer(&instruction.operation) => {
|
||||
terminal = shared_terminal(bytes, pc, target)?
|
||||
.map(|plan| Terminal::Shared(Box::new(plan)));
|
||||
debug_assert!(
|
||||
terminal.is_some(),
|
||||
"ordinary transfer has a shared boundary"
|
||||
);
|
||||
break;
|
||||
}
|
||||
Ok(instruction) => instructions.push((pc, instruction)),
|
||||
Err(error) => {
|
||||
if let Some(shared) = shared_terminal(bytes, pc, target)? {
|
||||
terminal = Some(Terminal::Shared(Box::new(shared)));
|
||||
break;
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Self {
|
||||
instructions,
|
||||
terminal,
|
||||
next_pc,
|
||||
source_bytes,
|
||||
scalable,
|
||||
numerical,
|
||||
target,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) const fn source_bytes(&self) -> usize {
|
||||
self.source_bytes
|
||||
}
|
||||
|
||||
pub(crate) fn emit(self) -> Result<CompiledBlock, CompileError> {
|
||||
let target = self.target;
|
||||
let vector_length = self.scalable.vector_length();
|
||||
let mut code = context_wrapper();
|
||||
let mut source_map =
|
||||
Vec::with_capacity(self.instructions.len() + usize::from(self.terminal.is_some()));
|
||||
let mut fixups = Vec::new();
|
||||
for (pc, instruction) in self.instructions {
|
||||
source_map.push((pc, code.len()));
|
||||
super::emit_decoded(
|
||||
&mut code,
|
||||
pc,
|
||||
instruction,
|
||||
self.scalable,
|
||||
target,
|
||||
&mut fixups,
|
||||
)?;
|
||||
}
|
||||
debug_assert!(fixups.is_empty(), "context block prefix cannot transfer");
|
||||
match self.terminal {
|
||||
Some(Terminal::Shared(plan)) => {
|
||||
let shared = plan.compile()?;
|
||||
let offset = code.len();
|
||||
source_map.extend(
|
||||
shared
|
||||
.native
|
||||
.source_map
|
||||
.into_iter()
|
||||
.map(|(pc, at)| (pc, at + offset)),
|
||||
);
|
||||
code.extend(shared.native.x86_64_code);
|
||||
}
|
||||
Some(Terminal::Numerical(instruction)) => {
|
||||
let pc = instruction.instruction_pc();
|
||||
source_map.push((pc, code.len()));
|
||||
let emitted = match *instruction.operation() {
|
||||
ScalableNumericalOperation::Sve(operation) => x86_64::sve::floating::emit(
|
||||
&mut code,
|
||||
instruction.word(),
|
||||
operation,
|
||||
vector_length,
|
||||
self.numerical,
|
||||
pc,
|
||||
target,
|
||||
)?,
|
||||
ScalableNumericalOperation::SmeExtremaScale(operand) => {
|
||||
x86_64::sme::extrema_scale::emit(
|
||||
&mut code,
|
||||
operand,
|
||||
vector_length,
|
||||
self.numerical,
|
||||
pc,
|
||||
target,
|
||||
)?
|
||||
}
|
||||
ScalableNumericalOperation::SmeVector(_)
|
||||
| ScalableNumericalOperation::SmeMatrix(_)
|
||||
| ScalableNumericalOperation::FixedFp8Conversion(_)
|
||||
| ScalableNumericalOperation::SmeFp8Conversion(_)
|
||||
| ScalableNumericalOperation::SmeFp8Matrix(_) => false,
|
||||
};
|
||||
if emitted {
|
||||
// The guarded family mapping owns the exact-PC cold exit.
|
||||
// Only its committed fast path reaches the continuation.
|
||||
x86_64::block::direct_exit(
|
||||
&mut code,
|
||||
instruction.next_pc(),
|
||||
ExitKind::Fallthrough,
|
||||
);
|
||||
} else {
|
||||
x86_64::block::direct_exit(&mut code, pc, ExitKind::ScalableNumerical);
|
||||
}
|
||||
}
|
||||
None => x86_64::block::direct_exit(&mut code, self.next_pc, ExitKind::Fallthrough),
|
||||
}
|
||||
Ok(CompiledBlock {
|
||||
native: NativeBlock {
|
||||
x86_64_code: code.into_bytes(),
|
||||
source_map,
|
||||
},
|
||||
source_bytes: self.source_bytes,
|
||||
direct_exits: Vec::new(),
|
||||
fault_recovery: Vec::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::aarch64::scalable::{ScalableMode, VectorLength};
|
||||
use crate::block::Features;
|
||||
use alloc::format;
|
||||
use alloc::string::ToString;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
const BASE: GuestAddress = GuestAddress(0x1000);
|
||||
const ADD_X5_ONE: u32 = 0x9100_04a5;
|
||||
const FADD_Z0_SINGLE: u32 = 0x6580_8020;
|
||||
const SVC: u32 = 0xd400_0001;
|
||||
const BRK: u32 = 0xd420_0000;
|
||||
const ERET: u32 = 0xd69f_03e0;
|
||||
const IRG: u32 = 0x9ac0_1000;
|
||||
const PACIBSP: u32 = 0xd503_237f;
|
||||
const CNTVCT: u32 = 0xd53b_e040;
|
||||
const TPIDRRO: u32 = 0xd53b_d060;
|
||||
const RET: u32 = 0xd65f_03c0;
|
||||
const PACGA_X1_X2_X3: u32 = 0x9ac3_3041;
|
||||
const LDRAA_X1_X2: u32 = 0xf820_0441;
|
||||
const LDRAB_X1_X2: u32 = 0xf8a0_0441;
|
||||
const SERVICE_WORDS: &[u32] = &[
|
||||
ERET,
|
||||
IRG,
|
||||
PACIBSP,
|
||||
CNTVCT,
|
||||
TPIDRRO,
|
||||
PACGA_X1_X2_X3,
|
||||
LDRAA_X1_X2,
|
||||
LDRAB_X1_X2,
|
||||
];
|
||||
|
||||
fn source(words: &[u32]) -> Vec<u8> {
|
||||
words.iter().flat_map(|word| word.to_le_bytes()).collect()
|
||||
}
|
||||
|
||||
const CONTEXT_BLOCK: BlockProfile = BlockProfile::new(Features::CONTEXT);
|
||||
|
||||
fn scalable() -> ScalableProfile {
|
||||
ScalableProfile::new(
|
||||
VectorLength::from_bytes(16).unwrap(),
|
||||
ScalableMode::new(true, false),
|
||||
)
|
||||
}
|
||||
|
||||
fn context_block(
|
||||
source: &[u8],
|
||||
base: GuestAddress,
|
||||
profile: BlockProfile,
|
||||
target: TargetCpu,
|
||||
) -> Result<CompiledBlock, CompileError> {
|
||||
crate::compile(
|
||||
source,
|
||||
base,
|
||||
&Options::new(profile, target)
|
||||
.with_scalable(scalable())
|
||||
.with_numerical_features(NumericalFeatures::default()),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_blocks_refuse_other_services() {
|
||||
for services in [
|
||||
BlockProfile::new(Features::SYSTEM),
|
||||
BlockProfile::new(Features::POINTER_AUTHENTICATION),
|
||||
BlockProfile::new(Features::POINTER_AUTHENTICATION.union(Features::CLOCK)),
|
||||
BlockProfile::new(Features::THREAD_REGISTERS.union(Features::AMX)),
|
||||
BlockProfile::new(
|
||||
Features::POINTER_AUTHENTICATION
|
||||
.union(Features::THREAD_REGISTERS)
|
||||
.union(Features::AMX),
|
||||
),
|
||||
BlockProfile::new(Features::PROCESS_HELPERS.union(Features::AMX)),
|
||||
] {
|
||||
let error = context_block(
|
||||
&source(&[RET]),
|
||||
BASE,
|
||||
BlockProfile::new(Features::CONTEXT | services.features()),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("no emitter implements"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordinary_trap_extent_stays_distinct_from_forbidden_system_completion() {
|
||||
for trap in [SVC, BRK] {
|
||||
let compiled = context_block(
|
||||
&source(&[ADD_X5_ONE, trap, ERET]),
|
||||
BASE,
|
||||
CONTEXT_BLOCK,
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(compiled.source_bytes, 2 * INSTRUCTION_BYTES);
|
||||
assert_eq!(
|
||||
compiled
|
||||
.native
|
||||
.source_map
|
||||
.iter()
|
||||
.map(|row| row.0)
|
||||
.collect::<Vec<_>>(),
|
||||
[BASE, GuestAddress(BASE.0 + INSTRUCTION_BYTES as u64)]
|
||||
);
|
||||
}
|
||||
for &service in SERVICE_WORDS {
|
||||
for words in [vec![service, RET], vec![ADD_X5_ONE, service, RET]] {
|
||||
let offset = if words[0] == ADD_X5_ONE {
|
||||
INSTRUCTION_BYTES
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let error =
|
||||
context_block(&source(&words), BASE, CONTEXT_BLOCK, TargetCpu::Baseline)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("service is not integrated"));
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains(&format!("{:#x}", BASE.0 + offset as u64))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unconsumed_service_after_numerical_boundary_does_not_expand_extent() {
|
||||
for &service in SERVICE_WORDS {
|
||||
let compiled = context_block(
|
||||
&source(&[ADD_X5_ONE, FADD_Z0_SINGLE, service]),
|
||||
BASE,
|
||||
CONTEXT_BLOCK,
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(compiled.source_bytes, 2 * INSTRUCTION_BYTES);
|
||||
assert_eq!(compiled.native.source_map.len(), 2);
|
||||
assert_eq!(
|
||||
compiled.native.source_map[1].0,
|
||||
GuestAddress(BASE.0 + INSTRUCTION_BYTES as u64)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strict_ordinary_ram_atomic_legacy_fp_and_prefix_declines_stay_explicit() {
|
||||
const LDR_X0_X1: u32 = 0xf940_0020;
|
||||
const CAS_X0_X1_X2: u32 = 0xc8a0_7c41;
|
||||
const FADD_S0_S1_S2: u32 = 0x1e22_2820;
|
||||
const MOVPRFX_Z0_Z1: u32 = 0x0420_bc20;
|
||||
for word in [LDR_X0_X1, CAS_X0_X1_X2, FADD_S0_S1_S2, MOVPRFX_Z0_Z1] {
|
||||
assert!(
|
||||
context_block(
|
||||
&source(&[ADD_X5_ONE, word, RET]),
|
||||
BASE,
|
||||
CONTEXT_BLOCK,
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn movprfx_pairs_remain_leaf_only_and_numerical_followers_decline() {
|
||||
const UNPREDICATED_PREFIX: u32 = 0x0420_bc20;
|
||||
const ZEROING_PREFIX: u32 = 0x0410_2020;
|
||||
const MERGING_PREFIX: u32 = 0x0411_2020;
|
||||
const AND_DESTRUCTIVE: u32 = 0x041a_0040;
|
||||
let block_profile = CONTEXT_BLOCK;
|
||||
for prefix in [UNPREDICATED_PREFIX, ZEROING_PREFIX, MERGING_PREFIX] {
|
||||
let bytes = source(&[prefix, AND_DESTRUCTIVE, RET]);
|
||||
let leaf = crate::testing::context_leaf(&bytes, BASE, scalable(), TargetCpu::Baseline)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
leaf.source_map.iter().map(|row| row.0).collect::<Vec<_>>(),
|
||||
[
|
||||
BASE,
|
||||
GuestAddress(BASE.0 + INSTRUCTION_BYTES as u64),
|
||||
GuestAddress(BASE.0 + 2 * INSTRUCTION_BYTES as u64),
|
||||
]
|
||||
);
|
||||
let error =
|
||||
context_block(&bytes, BASE, block_profile, TargetCpu::Baseline).unwrap_err();
|
||||
assert!(error.to_string().contains(&format!("{:#x}", BASE.0)));
|
||||
}
|
||||
let error = crate::testing::context_leaf(
|
||||
&source(&[UNPREDICATED_PREFIX, FADD_Z0_SINGLE, RET]),
|
||||
BASE,
|
||||
scalable(),
|
||||
TargetCpu::Baseline,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("unsupported follower"));
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains(&format!("{:#x}", BASE.0 + INSTRUCTION_BYTES as u64))
|
||||
);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 361 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user