From 726c68ea3428771fc947cdb42aeb015e966bc266 Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Mon, 16 Nov 2026 14:35:05 +0000 Subject: [PATCH 1/8] Add empty clazel-x64 and clazel-a64 crates for the JIT's instruction-set sources (J.2) Co-Authored-By: Claude Sonnet 5.5 --- Cargo.lock | 8 ++++++++ crates/clazel-a64/.gitattributes | 3 +++ crates/clazel-a64/Cargo.toml | 21 +++++++++++++++++++++ crates/clazel-a64/src/lib.rs | 8 ++++++++ crates/clazel-x64/.gitattributes | 3 +++ crates/clazel-x64/Cargo.toml | 21 +++++++++++++++++++++ crates/clazel-x64/src/lib.rs | 8 ++++++++ xtask/src/status.rs | 3 +++ 8 files changed, 75 insertions(+) create mode 100644 crates/clazel-a64/.gitattributes create mode 100644 crates/clazel-a64/Cargo.toml create mode 100644 crates/clazel-a64/src/lib.rs create mode 100644 crates/clazel-x64/.gitattributes create mode 100644 crates/clazel-x64/Cargo.toml create mode 100644 crates/clazel-x64/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 4819e7bfa..20d498734 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,6 +188,10 @@ dependencies = [ "rustls", ] +[[package]] +name = "clazel-a64" +version = "0.0.0" + [[package]] name = "clazel-base64" version = "0.0.0" @@ -609,6 +613,10 @@ dependencies = [ "webpki-root-certs", ] +[[package]] +name = "clazel-x64" +version = "0.0.0" + [[package]] name = "codespan-reporting" version = "0.13.1" diff --git a/crates/clazel-a64/.gitattributes b/crates/clazel-a64/.gitattributes new file mode 100644 index 000000000..fcbb06aca --- /dev/null +++ b/crates/clazel-a64/.gitattributes @@ -0,0 +1,3 @@ +# Vendored data is compared byte for byte (see the root attributes file); the +# upstream files' line endings are part of what they test. +tests/data/** -text diff --git a/crates/clazel-a64/Cargo.toml b/crates/clazel-a64/Cargo.toml new file mode 100644 index 000000000..cffb002c5 --- /dev/null +++ b/crates/clazel-a64/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "clazel-a64" +version = "0.0.0" +edition.workspace = true +license.workspace = true +publish.workspace = true +description = "The A64 (64-bit Arm) instruction-set subset the JIT emits (docs/phases/jit.md item J.4): semantics, encoder and decoder. Empty until then; it holds the vendored instruction-set sources." + +# No dependencies yet: jit.md item J.2 only vendors this crate's test data and +# inputs. The specification and implementation arrive with the item named in +# src/lib.rs. + +# Verification tier (docs/VERIFICATION.md). `tier` is what is proven about the +# shipped code today (nothing: the crate is empty); `target-tier` is what +# jit.md's "Crates" table sets. The contracts come first (rule 3). +[package.metadata.clazel] +tier = 0 +target-tier = 2 + +[lints] +workspace = true diff --git a/crates/clazel-a64/src/lib.rs b/crates/clazel-a64/src/lib.rs new file mode 100644 index 000000000..6eefce323 --- /dev/null +++ b/crates/clazel-a64/src/lib.rs @@ -0,0 +1,8 @@ +//! The A64 (64-bit Arm) instruction-set subset the JIT emits (docs/phases/jit.md item J.4). +//! +//! Empty for now: item J.2 only creates the crate, so that the instruction-set +//! sources (`tests/data/`) have a home. The spec (semantics as a `spec fn`) +//! and its contracts come first (CLAUDE.md rule 3), then the encoder and +//! decoder. +//! +//! Tier: see `[package.metadata.clazel]` in `Cargo.toml` and `docs/VERIFICATION.md`. diff --git a/crates/clazel-x64/.gitattributes b/crates/clazel-x64/.gitattributes new file mode 100644 index 000000000..fcbb06aca --- /dev/null +++ b/crates/clazel-x64/.gitattributes @@ -0,0 +1,3 @@ +# Vendored data is compared byte for byte (see the root attributes file); the +# upstream files' line endings are part of what they test. +tests/data/** -text diff --git a/crates/clazel-x64/Cargo.toml b/crates/clazel-x64/Cargo.toml new file mode 100644 index 000000000..524bfa9ab --- /dev/null +++ b/crates/clazel-x64/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "clazel-x64" +version = "0.0.0" +edition.workspace = true +license.workspace = true +publish.workspace = true +description = "The x86-64 instruction-set subset the JIT emits (docs/phases/jit.md item J.3): semantics, encoder and decoder. Empty until then; it holds the vendored instruction-set sources." + +# No dependencies yet: jit.md item J.2 only vendors this crate's test data and +# inputs. The specification and implementation arrive with the item named in +# src/lib.rs. + +# Verification tier (docs/VERIFICATION.md). `tier` is what is proven about the +# shipped code today (nothing: the crate is empty); `target-tier` is what +# jit.md's "Crates" table sets. The contracts come first (rule 3). +[package.metadata.clazel] +tier = 0 +target-tier = 2 + +[lints] +workspace = true diff --git a/crates/clazel-x64/src/lib.rs b/crates/clazel-x64/src/lib.rs new file mode 100644 index 000000000..8aeeb94c5 --- /dev/null +++ b/crates/clazel-x64/src/lib.rs @@ -0,0 +1,8 @@ +//! The x86-64 instruction-set subset the JIT emits (docs/phases/jit.md item J.3). +//! +//! Empty for now: item J.2 only creates the crate, so that the instruction-set +//! sources (`tests/data/`) have a home. The spec (semantics as a `spec fn`) +//! and its contracts come first (CLAUDE.md rule 3), then the encoder and +//! decoder. +//! +//! Tier: see `[package.metadata.clazel]` in `Cargo.toml` and `docs/VERIFICATION.md`. diff --git a/xtask/src/status.rs b/xtask/src/status.rs index eb413c0db..932ab956d 100644 --- a/xtask/src/status.rs +++ b/xtask/src/status.rs @@ -86,6 +86,9 @@ const PLACES: &[(&str, Place)] = &[ ("clazel-percent", Place::Primitive), ("clazel-base64", Place::Primitive), ("clazel-mime", Place::Primitive), + // The JIT's instruction-set layer (docs/phases/jit.md item J.2 creates them empty). + ("clazel-x64", Place::Primitive), + ("clazel-a64", Place::Primitive), ("clazel-ipc", Place::Primitive), ("clazel-sandbox", Place::Os), ("clazel-sys", Place::Os), From 62cd9cb9ee78d5b8d0d7ffc5eb774bd830c3b3a7 Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Mon, 16 Nov 2026 14:39:54 +0000 Subject: [PATCH 2/8] xtask: add converters for the JIT's instruction-set sources (J.2) Inventories for the vendored trees, and a table of pins for files that are named but not held. Co-Authored-By: Claude Sonnet 5.5 --- xtask/src/testdata.rs | 19 ++- xtask/src/testdata/inventory.rs | 13 +- xtask/src/testdata/isa.rs | 217 ++++++++++++++++++++++++++++++++ 3 files changed, 244 insertions(+), 5 deletions(-) create mode 100644 xtask/src/testdata/isa.rs diff --git a/xtask/src/testdata.rs b/xtask/src/testdata.rs index ab380f606..3c6536380 100644 --- a/xtask/src/testdata.rs +++ b/xtask/src/testdata.rs @@ -22,6 +22,7 @@ mod html5lib_tree; mod http_state_dates; mod http_state_parser; mod inventory; +mod isa; mod js; mod llhttp; mod nist_cavp_sigver; @@ -203,13 +204,29 @@ const CONVERTERS: &[(&str, Convert, &[&str])] = &[ inventory::WEBREF_IDL_FILES, ), ("ucd-regexp", inventory::convert_ucd, inventory::UCD_FILES), + // JIT item J.2: instruction-set sources (see isa.rs). + ("acl2-x86isa", isa::convert_acl2_x86isa, &[]), + ("sail-x86-from-acl2", isa::convert_sail_x86_from_acl2, &[]), + ("sail-x86-shina", isa::convert_sail_x86_shina, &[]), + ("intel-sdm", isa::convert_intel_sdm, &[]), + ("sail-arm", isa::convert_sail_arm, &[]), + ("arm-mrs", isa::convert_arm_mrs, &[]), ]; /// Suites whose directory is a tree of upstream paths, not a flat list: the /// converter walks it and lists what it finds (its inventory is then the /// record of which files exist), and the directory is checked for /// `SOURCE.md` and `LICENSE.md` only. -const TREE_SUITES: &[&str] = &["wpt-web", "todomvc", "test262"]; +const TREE_SUITES: &[&str] = &[ + "wpt-web", + "todomvc", + "test262", + "acl2-x86isa", + "sail-x86-from-acl2", + "sail-x86-shina", + "sail-arm", + "arm-mrs", +]; /// A converter for a binary artefact written beside a suite's Rust table. type ConvertBytes = fn(&Path) -> Result, String>; diff --git a/xtask/src/testdata/inventory.rs b/xtask/src/testdata/inventory.rs index b1e38c76e..a1837ce3b 100644 --- a/xtask/src/testdata/inventory.rs +++ b/xtask/src/testdata/inventory.rs @@ -101,7 +101,7 @@ const IDNA_DATA: &str = "crates/clazel-idna/data/unicode-18.0.0"; const SHARED_WITH_IDNA: &[&str] = &["UnicodeData.txt", "DerivedNormalizationProps.txt"]; /// One vendored file. -struct Entry { +pub(super) struct Entry { path: String, size: usize, sha256: String, @@ -155,7 +155,7 @@ fn under(path: &str, root: &str) -> bool { /// The inventory of `dir`, every file of which must lie under one of /// `roots` (the suite's own `LICENSE.md` is always allowed). Every root must /// hold at least one file. -fn inventory(dir: &Path, roots: &[&str]) -> Result, String> { +pub(super) fn inventory(dir: &Path, roots: &[&str]) -> Result, String> { let mut files = Vec::new(); walk(dir, "", &mut files)?; files.sort_by(|a, b| a.path.cmp(&b.path)); @@ -182,7 +182,12 @@ fn inventory(dir: &Path, roots: &[&str]) -> Result, String> { } /// The generated Rust file for `files`. -fn render(suite: &str, converter: &str, what: &str, files: &[Entry]) -> Result { +pub(super) fn render( + suite: &str, + converter: &str, + what: &str, + files: &[Entry], +) -> Result { let mut out = String::new(); let total: usize = files.iter().map(|f| f.size).sum(); let w = |r: std::fmt::Result| r.map_err(|e| e.to_string()); @@ -257,7 +262,7 @@ pub fn convert_webref_idl(dir: &Path) -> Result { } /// The `SHA-256: ` lines of a `SOURCE.md`, as (file, hash). -fn listed_hashes(source: &str) -> Vec<(String, String)> { +pub(super) fn listed_hashes(source: &str) -> Vec<(String, String)> { source .lines() .filter_map(|l| { diff --git a/xtask/src/testdata/isa.rs b/xtask/src/testdata/isa.rs new file mode 100644 index 000000000..4e900015b --- /dev/null +++ b/xtask/src/testdata/isa.rs @@ -0,0 +1,217 @@ +//! JIT item J.2: the instruction-set sources `clazel-x64` and `clazel-a64` +//! will be written against (docs/phases/jit.md). +//! +//! Nothing reads these yet, so each suite is an inventory (paths, sizes and +//! SHA-256, as in `inventory.rs`). Two sources are not redistributable, or +//! are too large to vendor, so they are **pinned** instead: `SOURCE.md` +//! names the file by URL, size and SHA-256, and the generated table lists +//! those pins. A reader (item J.3 or J.4) fetches the file and checks the +//! hash. +//! +//! - `acl2-x86isa` (`clazel-x64`): the ACL2 x86isa model, the files the +//! subset of item J.3 reads. +//! - `sail-x86-from-acl2` (`clazel-x64`): the Sail model that is a +//! mechanical translation of the one above (see the crate's README: it is +//! not independent of it). +//! - `sail-x86-shina` (`clazel-x64`): a Sail model written from the Intel +//! manuals, the candidate second source. +//! - `intel-sdm` (`clazel-x64`): Intel's SDM volume 2, pinned only. +//! - `sail-arm` (`clazel-a64`): the Sail Arm model, the A64 base +//! instructions and the shared pseudocode they call. +//! - `arm-mrs` (`clazel-a64`): Arm's machine-readable specification, the +//! licence and README vendored, `Instructions.json` (117 MB) pinned. + +use std::fmt::Write as _; +use std::path::Path; + +use super::inventory::{inventory, listed_hashes, render}; + +/// The ACL2 checkout's `books/projects/x86isa` paths vendored. +pub const ACL2_X86ISA_ROOTS: &[&str] = &["README", "portcullis", "utils", "machine"]; +/// The translated Sail model's roots. +pub const SAIL_X86_FROM_ACL2_ROOTS: &[&str] = &["README.md", "LICENCE", "model"]; +/// The Intel-manual-based Sail model's roots. +pub const SAIL_X86_SHINA_ROOTS: &[&str] = &["README.md", "docs", "model"]; +/// The Sail Arm model's roots. +pub const SAIL_ARM_ROOTS: &[&str] = &["README.md", "src"]; +/// The files of Arm's package that are vendored. +pub const ARM_MRS_ROOTS: &[&str] = &["README.md", "notice.html"]; + +/// One file the suite names but does not hold. +struct Pin { + file: String, + size: u64, + sha256: String, +} + +fn tree(dir: &Path, suite: &str, roots: &[&str], what: &str) -> Result { + let files = inventory(dir, roots)?; + render(suite, "isa", what, &files) +} + +/// `acl2-x86isa`. +pub fn convert_acl2_x86isa(dir: &Path) -> Result { + tree( + dir, + "acl2-x86isa", + ACL2_X86ISA_ROOTS, + "ACL2 x86isa model files for the subset of jit.md item J.3.", + ) +} + +/// `sail-x86-from-acl2`. +pub fn convert_sail_x86_from_acl2(dir: &Path) -> Result { + tree( + dir, + "sail-x86-from-acl2", + SAIL_X86_FROM_ACL2_ROOTS, + "Sail x86 model translated from the ACL2 one (jit.md item J.2); not independent of it.", + ) +} + +/// `sail-x86-shina`. +pub fn convert_sail_x86_shina(dir: &Path) -> Result { + tree( + dir, + "sail-x86-shina", + SAIL_X86_SHINA_ROOTS, + "Sail x86 model written from the Intel manuals (jit.md item J.2), the candidate second source.", + ) +} + +/// `sail-arm`. +pub fn convert_sail_arm(dir: &Path) -> Result { + tree( + dir, + "sail-arm", + SAIL_ARM_ROOTS, + "Sail Armv9.4-A model, A64 base instructions (jit.md item J.2).", + ) +} + +/// The `Size: ` lines of a `SOURCE.md`, as (file, bytes). +fn listed_sizes(source: &str) -> Vec<(String, u64)> { + source + .lines() + .filter_map(|l| { + let rest = l.trim().strip_prefix("Size:")?.trim(); + let (size, name) = rest.split_once(char::is_whitespace)?; + Some(( + name.trim().trim_matches('`').to_owned(), + size.parse::().ok()?, + )) + }) + .collect() +} + +/// The pins `SOURCE.md` makes: every `SHA-256: ` line needs a +/// `Size: ` line, and a hash of 64 hex digits. +fn pins(dir: &Path) -> Result, String> { + let source = + std::fs::read_to_string(dir.join("SOURCE.md")).map_err(|e| format!("SOURCE.md: {e}"))?; + let sizes = listed_sizes(&source); + let mut out = Vec::new(); + for (file, hash) in listed_hashes(&source) { + if hash.len() != 64 || !hash.chars().all(|c| c.is_ascii_hexdigit()) { + return Err(format!( + "SOURCE.md: the SHA-256 of {file} is not 64 hex digits" + )); + } + let Some((_, size)) = sizes.iter().find(|(n, _)| *n == file) else { + return Err(format!("SOURCE.md: no \"Size: {file}\" line")); + }; + out.push(Pin { + file, + size: *size, + sha256: hash, + }); + } + if out.is_empty() { + return Err("SOURCE.md: no \"SHA-256: \" line".to_owned()); + } + Ok(out) +} + +fn render_pins(suite: &str, what: &str, pins: &[Pin], with_header: bool) -> Result { + let w = |r: std::fmt::Result| r.map_err(|e| e.to_string()); + let mut out = String::new(); + if with_header { + w(write!( + out, + "// @generated by `cargo xtask testdata` from tests/data/{suite}/.\n\ + // Do not edit: `cargo xtask verify` fails if this differs from what the\n\ + // converter (xtask/src/testdata/isa.rs) produces.\n\ + // Source, pins and license: tests/data/{suite}/SOURCE.md.\n\ + //\n\ + // {what}\n\ + \n" + ))?; + } else { + out.push('\n'); + } + w(write!( + out, + "/// A file the suite pins but does not vendor.\n\ + #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n\ + pub struct Pin {{\n\ + \x20 /// The file's name in `SOURCE.md`.\n\ + \x20 pub file: &'static str,\n\ + \x20 /// Its size in bytes.\n\ + \x20 pub size: u64,\n\ + \x20 /// Its SHA-256, in lower-case hex.\n\ + \x20 pub sha256: &'static str,\n\ + }}\n\ + \n\ + /// Every pinned file.\n\ + pub const PINS: &[Pin] = &[\n" + ))?; + for p in pins { + w(writeln!( + out, + " Pin {{ file: {:?}, size: {}, sha256: \"{}\" }},", + p.file, p.size, p.sha256 + ))?; + } + out.push_str("];\n"); + Ok(out) +} + +/// `intel-sdm`: nothing vendored, one pin. The directory holds `SOURCE.md` +/// and `LICENSE.md` only (checked by `testdata.rs`). +pub fn convert_intel_sdm(dir: &Path) -> Result { + let pins = pins(dir)?; + render_pins( + "intel-sdm", + "Intel SDM volume 2, pinned by URL and SHA-256 (Intel's terms do not allow redistribution).", + &pins, + true, + ) +} + +/// `arm-mrs`: the licence notice and README as an inventory, and the +/// `Instructions.json` the notice covers as a pin. +pub fn convert_arm_mrs(dir: &Path) -> Result { + let mut out = tree( + dir, + "arm-mrs", + ARM_MRS_ROOTS, + "Arm machine-readable specification: licence and README vendored, Instructions.json pinned.", + )?; + let pins = pins(dir)?; + out.push_str(&render_pins("arm-mrs", "", &pins, false)?); + Ok(out) +} + +#[cfg(test)] +mod tests { + use super::listed_sizes; + + #[test] + fn sizes_are_read_from_source_md() { + let s = "Size: 11294447 sdm.pdf\nSize: x bad.pdf\nnoise\n"; + assert_eq!( + listed_sizes(s), + vec![("sdm.pdf".to_owned(), 11_294_447_u64)] + ); + } +} From 00fc6ac164602bd5047ba60b6cd3c324573b558d Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Mon, 16 Nov 2026 14:39:56 +0000 Subject: [PATCH 3/8] Vendor and pin the instruction-set sources for clazel-x64 and clazel-a64 (J.2) ACL2 x86isa, the Sail x86 models, Sail Arm and Arm's machine-readable specification, each with SOURCE.md and licence; the Intel SDM and Arm's Instructions.json pinned by SHA-256. The READMEs record that the Sail x86 model is a translation of the ACL2 one and the Sail Arm model derives from Arm's ASL. Co-Authored-By: Claude Sonnet 5.5 --- crates/clazel-a64/README.md | 36 + .../clazel-a64/tests/data/arm-mrs/LICENSE.md | 31 + .../clazel-a64/tests/data/arm-mrs/README.md | 30 + .../clazel-a64/tests/data/arm-mrs/SOURCE.md | 30 + .../clazel-a64/tests/data/arm-mrs/notice.html | 75 + .../clazel-a64/tests/data/sail-arm/LICENSE.md | 37 + .../clazel-a64/tests/data/sail-arm/README.md | 63 + .../clazel-a64/tests/data/sail-arm/SOURCE.md | 34 + .../tests/data/sail-arm/src/builtins.sail | 208 + .../tests/data/sail-arm/src/decode_end.sail | 111 + .../tests/data/sail-arm/src/decode_start.sail | 89 + .../data/sail-arm/src/event_clauses.sail | 138 + .../tests/data/sail-arm/src/fetch.sail | 389 + .../tests/data/sail-arm/src/instrs64.sail | 53106 ++++++++++++++ .../tests/data/sail-arm/src/interface.sail | 199 + .../tests/data/sail-arm/src/map_clauses.sail | 465 + .../tests/data/sail-arm/src/mem.sail | 232 + .../tests/data/sail-arm/src/prelude.sail | 374 + .../sail-arm/src/termination_measures.sail | 116 + .../tests/data/sail-arm/src/v8_base.sail | 57139 ++++++++++++++++ crates/clazel-a64/tests/generated/arm_mrs.rs | 42 + crates/clazel-a64/tests/generated/sail_arm.rs | 37 + crates/clazel-a64/tests/vendored_sources.rs | 56 + crates/clazel-x64/README.md | 71 + .../tests/data/acl2-x86isa/LICENSE.md | 39 + .../clazel-x64/tests/data/acl2-x86isa/README | 20 + .../tests/data/acl2-x86isa/SOURCE.md | 37 + .../machine/application-level-memory.lisp | 1349 + .../machine/decoding-and-spec-utils.lisp | 2615 + .../acl2-x86isa/machine/dispatch-creator.lisp | 503 + .../acl2-x86isa/machine/dispatch-macros.lisp | 346 + .../acl2-x86isa/machine/get-prefixes.lisp | 909 + .../acl2-x86isa/machine/guard-helpers.lisp | 541 + .../acl2-x86isa/machine/inst-listing.lisp | 21961 ++++++ .../acl2-x86isa/machine/inst-structs.lisp | 1150 + .../machine/instructions/add-spec.lisp | 486 + .../machine/instructions/and-spec.lisp | 150 + .../instructions/arith-and-logic-spec.lisp | 137 + .../machine/instructions/arith-and-logic.lisp | 1018 + .../machine/instructions/conditional.lisp | 563 + .../machine/instructions/flags.lisp | 188 + .../machine/instructions/fp/add-mul-spec.lisp | 195 + .../machine/instructions/fp/arith-spec.lisp | 318 + .../machine/instructions/fp/arithmetic.lisp | 721 + .../machine/instructions/fp/base.lisp | 407 + .../machine/instructions/fp/cmp-spec.lisp | 294 + .../machine/instructions/fp/convert.lisp | 537 + .../machine/instructions/fp/cvt-spec.lisp | 569 + .../machine/instructions/fp/mxcsr.lisp | 141 + .../machine/instructions/fp/sqrt-spec.lisp | 158 + .../machine/instructions/fp/top.lisp | 90 + .../machine/instructions/jump-and-loop.lisp | 1013 + .../machine/instructions/logical.lisp | 395 + .../machine/instructions/move-sse.lisp | 1494 + .../machine/instructions/move.lisp | 1181 + .../machine/instructions/multiply-spec.lisp | 329 + .../machine/instructions/multiply.lisp | 545 + .../machine/instructions/or-spec.lisp | 148 + .../instructions/rotate-and-shift.lisp | 625 + .../machine/instructions/shifts-spec.lisp | 1724 + .../machine/instructions/signextend.lisp | 137 + .../machine/instructions/sub-spec.lisp | 290 + .../machine/instructions/subroutine.lisp | 917 + .../acl2-x86isa/machine/instructions/top.lisp | 167 + .../machine/instructions/xor-spec.lisp | 147 + .../acl2-x86isa/machine/linear-memory.lisp | 6904 ++ .../tests/data/acl2-x86isa/machine/modes.lisp | 200 + .../acl2-x86isa/machine/physical-memory.lisp | 671 + .../machine/prefix-modrm-sib-decoding.lisp | 2524 + .../machine/register-readers-and-writers.lisp | 1831 + .../data/acl2-x86isa/machine/rflags-spec.lisp | 866 + .../tests/data/acl2-x86isa/machine/state.lisp | 993 + .../machine/three-byte-opcodes-dispatch.lisp | 276 + .../acl2-x86isa/machine/top-level-memory.lisp | 1982 + .../machine/two-byte-opcodes-dispatch.lisp | 245 + .../tests/data/acl2-x86isa/machine/x86.lisp | 893 + .../data/acl2-x86isa/portcullis/package.lsp | 107 + .../acl2-x86isa/portcullis/portcullis.lisp | 42 + .../portcullis/sharp-dot-constants.lisp | 661 + .../portcullis/sharp-dot-defuns.lisp | 323 + .../data/acl2-x86isa/portcullis/utils.lisp | 76 + .../data/acl2-x86isa/utils/basic-structs.lisp | 74 + .../data/acl2-x86isa/utils/fp-structures.lisp | 124 + .../acl2-x86isa/utils/paging-structures.lisp | 288 + .../data/acl2-x86isa/utils/records-0.lisp | 425 + .../utils/segmentation-structures.lisp | 400 + .../data/acl2-x86isa/utils/structures.lisp | 823 + .../data/acl2-x86isa/utils/utilities.lisp | 485 + .../tests/data/intel-sdm/LICENSE.md | 10 + .../clazel-x64/tests/data/intel-sdm/SOURCE.md | 28 + .../tests/data/sail-x86-from-acl2/LICENCE | 37 + .../tests/data/sail-x86-from-acl2/LICENSE.md | 81 + .../tests/data/sail-x86-from-acl2/README.md | 68 + .../tests/data/sail-x86-from-acl2/SOURCE.md | 39 + .../data/sail-x86-from-acl2/model/LICENSE | 81 + .../data/sail-x86-from-acl2/model/Makefile | 58 + .../sail-x86-from-acl2/model/add_spec.sail | 141 + .../sail-x86-from-acl2/model/and_spec.sail | 56 + .../model/application_level_memory.sail | 30 + .../model/arith_and_logic.sail | 282 + .../model/arith_and_logic_spec.sail | 108 + .../sail-x86-from-acl2/model/auxiliary.sail | 36 + .../sail-x86-from-acl2/model/conditional.sail | 148 + .../data/sail-x86-from-acl2/model/config.sail | 33 + .../model/decoding_and_spec_utils.sail | 963 + .../model/dispatch_macros.sail | 17 + .../sail-x86-from-acl2/model/environment.sail | 1 + .../data/sail-x86-from-acl2/model/init.sail | 8 + .../model/jump_and_loop.sail | 304 + .../model/linear_memory.sail | 428 + .../sail-x86-from-acl2/model/logging.sail | 65 + .../data/sail-x86-from-acl2/model/main.sail | 60 + .../model/memory_accessors.sail | 113 + .../data/sail-x86-from-acl2/model/modes.sail | 37 + .../data/sail-x86-from-acl2/model/mov.sail | 292 + .../data/sail-x86-from-acl2/model/move.sail | 357 + .../sail-x86-from-acl2/model/multiply.sail | 235 + .../model/multiply_spec.sail | 136 + .../sail-x86-from-acl2/model/opcode_ext.sail | 81 + .../sail-x86-from-acl2/model/or_spec.sail | 56 + .../model/physical_memory.sail | 57 + .../model/prefix_modrm_sib_decoding.sail | 185 + .../sail-x86-from-acl2/model/prelude.sail | 711 + .../model/register_accessors.sail | 35 + .../model/register_readers_and_writers.sail | 614 + .../model/register_types.sail | 12 + .../sail-x86-from-acl2/model/registers.sail | 154 + .../sail-x86-from-acl2/model/rflags_spec.sail | 327 + .../model/rotate_and_shift.sail | 202 + .../sail-x86-from-acl2/model/shifts_spec.sail | 914 + .../model/shuffle_and_unpack.sail | 182 + .../sail-x86-from-acl2/model/signextend.sail | 37 + .../data/sail-x86-from-acl2/model/step.sail | 2493 + .../sail-x86-from-acl2/model/structures.sail | 248 + .../sail-x86-from-acl2/model/sub_spec.sail | 132 + .../sail-x86-from-acl2/model/subroutine.sail | 123 + .../model/three_byte_opcodes_dispatch.sail | 1 + .../data/sail-x86-from-acl2/model/top.sail | 99 + .../model/top_level_memory.sail | 491 + .../model/two_byte_opcodes_dispatch.sail | 2805 + .../sail-x86-from-acl2/model/xor_spec.sail | 56 + .../tests/data/sail-x86-shina/LICENSE.md | 21 + .../tests/data/sail-x86-shina/README.md | 116 + .../tests/data/sail-x86-shina/SOURCE.md | 40 + .../docs/x86-64-completeness-checklist.md | 1152 + .../data/sail-x86-shina/model/branchless.sail | 415 + .../data/sail-x86-shina/model/core_types.sail | 130 + .../data/sail-x86-shina/model/exceptions.sail | 140 + .../data/sail-x86-shina/model/extern.sail | 489 + .../sail-x86-shina/model/fetch_execute.sail | 261 + .../data/sail-x86-shina/model/insn_alu.sail | 100 + .../sail-x86-shina/model/insn_baseline.sail | 2551 + .../sail-x86-shina/model/insn_dispatch.sail | 2358 + .../sail-x86-shina/model/insn_groups.sail | 501 + .../data/sail-x86-shina/model/insn_modrm.sail | 496 + .../sail-x86-shina/model/insn_prefixes.sail | 112 + .../data/sail-x86-shina/model/insn_simd.sail | 698 + .../sail-x86-shina/model/insn_sse_fp.sail | 893 + .../tests/data/sail-x86-shina/model/mem.sail | 755 + .../data/sail-x86-shina/model/operands.sail | 418 + .../data/sail-x86-shina/model/paging.sail | 481 + .../data/sail-x86-shina/model/prelude.sail | 126 + .../tests/data/sail-x86-shina/model/regs.sail | 1184 + .../data/sail-x86-shina/model/rflags.sail | 222 + .../sail-x86-shina/model/x86.sail_project | 66 + .../clazel-x64/tests/generated/acl2_x86isa.rs | 86 + .../clazel-x64/tests/generated/intel_sdm.rs | 22 + .../tests/generated/sail_x86_from_acl2.rs | 73 + .../tests/generated/sail_x86_shina.rs | 46 + crates/clazel-x64/tests/vendored_sources.rs | 77 + 170 files changed, 207171 insertions(+) create mode 100644 crates/clazel-a64/README.md create mode 100644 crates/clazel-a64/tests/data/arm-mrs/LICENSE.md create mode 100644 crates/clazel-a64/tests/data/arm-mrs/README.md create mode 100644 crates/clazel-a64/tests/data/arm-mrs/SOURCE.md create mode 100644 crates/clazel-a64/tests/data/arm-mrs/notice.html create mode 100644 crates/clazel-a64/tests/data/sail-arm/LICENSE.md create mode 100644 crates/clazel-a64/tests/data/sail-arm/README.md create mode 100644 crates/clazel-a64/tests/data/sail-arm/SOURCE.md create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/builtins.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/decode_end.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/decode_start.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/event_clauses.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/fetch.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/instrs64.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/interface.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/map_clauses.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/mem.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/prelude.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/termination_measures.sail create mode 100644 crates/clazel-a64/tests/data/sail-arm/src/v8_base.sail create mode 100644 crates/clazel-a64/tests/generated/arm_mrs.rs create mode 100644 crates/clazel-a64/tests/generated/sail_arm.rs create mode 100644 crates/clazel-a64/tests/vendored_sources.rs create mode 100644 crates/clazel-x64/README.md create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/LICENSE.md create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/README create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/application-level-memory.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/decoding-and-spec-utils.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-creator.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-macros.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/get-prefixes.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/guard-helpers.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-listing.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-structs.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/add-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/and-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/conditional.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/flags.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/add-mul-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arith-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arithmetic.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/base.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cmp-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/convert.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cvt-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/mxcsr.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/sqrt-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/top.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/jump-and-loop.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/logical.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move-sse.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/or-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/rotate-and-shift.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/shifts-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/signextend.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/sub-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/subroutine.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/top.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/xor-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/linear-memory.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/modes.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/physical-memory.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/prefix-modrm-sib-decoding.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/register-readers-and-writers.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/rflags-spec.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/state.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/three-byte-opcodes-dispatch.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/top-level-memory.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/two-byte-opcodes-dispatch.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/x86.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/portcullis/package.lsp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/portcullis/portcullis.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-constants.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-defuns.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/portcullis/utils.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/utils/basic-structs.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/utils/fp-structures.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/utils/paging-structures.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/utils/records-0.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/utils/segmentation-structures.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/utils/structures.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/utils/utilities.lisp create mode 100644 crates/clazel-x64/tests/data/intel-sdm/LICENSE.md create mode 100644 crates/clazel-x64/tests/data/intel-sdm/SOURCE.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENCE create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENSE.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/README.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/LICENSE create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/Makefile create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/add_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/and_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/application_level_memory.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/auxiliary.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/conditional.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/config.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/decoding_and_spec_utils.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/dispatch_macros.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/environment.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/init.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/jump_and_loop.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/linear_memory.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/logging.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/main.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/memory_accessors.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/modes.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/mov.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/move.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/opcode_ext.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/or_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/physical_memory.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prefix_modrm_sib_decoding.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prelude.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_accessors.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_readers_and_writers.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_types.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/registers.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rflags_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rotate_and_shift.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shifts_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shuffle_and_unpack.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/signextend.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/step.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/structures.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/sub_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/subroutine.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/three_byte_opcodes_dispatch.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top_level_memory.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/two_byte_opcodes_dispatch.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-from-acl2/model/xor_spec.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/README.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail create mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project create mode 100644 crates/clazel-x64/tests/generated/acl2_x86isa.rs create mode 100644 crates/clazel-x64/tests/generated/intel_sdm.rs create mode 100644 crates/clazel-x64/tests/generated/sail_x86_from_acl2.rs create mode 100644 crates/clazel-x64/tests/generated/sail_x86_shina.rs create mode 100644 crates/clazel-x64/tests/vendored_sources.rs diff --git a/crates/clazel-a64/README.md b/crates/clazel-a64/README.md new file mode 100644 index 000000000..635617dac --- /dev/null +++ b/crates/clazel-a64/README.md @@ -0,0 +1,36 @@ +# clazel-a64 + +Part of [Clazel](../../README.md). The A64 (64-bit Arm) subset the JIT emits: +its semantics, encoder and decoder ([jit.md](../../docs/phases/jit.md) item +J.4). + +Nothing is implemented yet (tier 0, target tier 2). Item J.2 vendored or +pinned the sources the semantics will be written against, in `tests/data/`: + +| Suite | What | Held as | +|---|---|---| +| `sail-arm` | the Sail Armv9.4-A model: A64 base instructions and shared pseudocode (BSD-3-Clause-Clear) | 3.9 MB, vendored | +| `arm-mrs` | Arm's machine-readable specification, 2026-09 release (BSD-3-Clause) | licence and README vendored; `Instructions.json` (116,678,333 bytes) pinned by SHA-256 | + +Each has a `SOURCE.md` with the upstream, the commit (or the SHA-256) and the +licence. The tables in `tests/generated/` list every file's size and hash. + +## Are the two A64 sources independent? No. + +The Sail Arm model's README says its Sail files "are derived from the 2023-03 +version of Arm's ASL specification using the automatic ASL-to-Sail +translation tool". Arm's machine-readable specification (`Instructions.json`) +carries the same ASL as the operation of each instruction. So the two are one +source in two syntaxes (the Sail model is from the 2023-03 ASL, the JSON from +2026-09), and they share Arm's own errors, if any. jit.md items J.2 and J.4 +say each semantics is transcribed from independent sources; for A64 no +second, independent formal source was found. The Arm Architecture Reference +Manual's prose and the hardware differential tests on the macOS runner (exit +criterion 3) are independent evidence; a person should decide whether the +second A64 transcription is made from the prose, and what the crate header +says. + +The `arm-mrs` JSON is also the only machine-readable encoding table +(`Instructions.json` has every encoding with its fixed and variable bits), so +the decoder differential against `yaxpeax-arm` can be checked against it as +well. diff --git a/crates/clazel-a64/tests/data/arm-mrs/LICENSE.md b/crates/clazel-a64/tests/data/arm-mrs/LICENSE.md new file mode 100644 index 000000000..a3b7eb59d --- /dev/null +++ b/crates/clazel-a64/tests/data/arm-mrs/LICENSE.md @@ -0,0 +1,31 @@ +# Licence of Arm's AARCHMRS open-source package + +Transcribed from `docs/notice.html` of the package (ARM Machine Readable +Schema 2.9.6; the original is `notice.html` beside this file). + +Copyright 2010-2026 Arm Limited or its affiliates. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/clazel-a64/tests/data/arm-mrs/README.md b/crates/clazel-a64/tests/data/arm-mrs/README.md new file mode 100644 index 000000000..c894bd881 --- /dev/null +++ b/crates/clazel-a64/tests/data/arm-mrs/README.md @@ -0,0 +1,30 @@ +# AARCHMRS containing the JSON files for A-profile Architecture + +## Introduction + +This is the Arm Architecture Machine Readable Specification containing +JSON files representing the architecture as a machine readable format. + +This package contains a subset of the information provided in the packages +with Arm proprietary licenses. Content that is not currently in a machine-readable +format, as well as all descriptive content, is omitted. + +The [notice](docs/notice.html) gives details of the license terms and conditions +under which this package is provided. + +## Package contents + + - `Features.json` contains the architecture feature constraints. + - `Instructions.json` contains the A64, A32, and T32 Instruction Set Architecture. + - `Registers.json` contains the AArch32, AArch64, and MemoryMapped + System Registers and System instructions. + - [`schema`](schema/) contains JSON schema for the data. + - [`docs`](docs/index.html) contains the rendered view of the schema + as well as user guides to help understand the data above. + +## Package quality + + - The architectural content contained within the data files has the same quality + as the equivalent XML releases. + - The schema is still under development and is subject to change. + diff --git a/crates/clazel-a64/tests/data/arm-mrs/SOURCE.md b/crates/clazel-a64/tests/data/arm-mrs/SOURCE.md new file mode 100644 index 000000000..405e06129 --- /dev/null +++ b/crates/clazel-a64/tests/data/arm-mrs/SOURCE.md @@ -0,0 +1,30 @@ +# Arm's open-source machine-readable specification of the A-profile architecture (README and licence vendored, Instructions.json pinned) + +Upstream: https://kernel.googlesource.com/pub/scm/linux/kernel/git/maz/AARCHMRS/+/1346b16d47619400448f3cb6d4f22d62d3b76848 +Commit: 1346b16d47619400448f3cb6d4f22d62d3b76848 +SHA-256: ef75f3ec02df1b9b9c0612f4ea259d6710ac3de686b097d8f9c83d1d97aa800a Instructions.json +Size: 116678333 Instructions.json +License: BSD-3-Clause (Arm Limited), as stated in `notice.html` (the package's own notice; `LICENSE.md` is its text). Redistribution is allowed. + +Arm publishes the package as `AARCHMRS_OPENSOURCE_A_profile_FAT-2026-09` on its +developer site (the "Exploration Tools" page of the A-profile architecture; the +site redirected our client to support.arm.com and was not fetched). The commit +above is a mirror of that release in a git repository (Marc Zyngier's +AARCHMRS repository at kernel.googlesource.com, whose commit message is the +release name, 2026-10-15). The mirror is third-party: a person should compare +its hashes with the tarball from Arm's site before relying on it. + +Vendored, byte for byte: `README.md` and `notice.html` (the licence; schema +2.9.6). + +**`Instructions.json` is pinned, not vendored.** It holds the A64, A32 and T32 +instruction sets with their encodings and their ASL operations, and it is +116,678,333 bytes (116 MB), far over this suite's size budget, and it cannot +be cut to the A64 base instructions without rewriting it. The pin above is +the SHA-256 of the file as stored in the commit (LF line endings). A reader +(jit.md item J.4) fetches the commit, takes `Instructions.json` and checks the +hash. `Features.json` and `Registers.json` are not needed for the subset. + +`xtask/src/testdata/isa.rs` writes `tests/generated/arm_mrs.rs`, the inventory +of the two vendored files and the table of the pin. Nothing reads the +specification yet. The Sail model derived from the same ASL is `sail-arm`. diff --git a/crates/clazel-a64/tests/data/arm-mrs/notice.html b/crates/clazel-a64/tests/data/arm-mrs/notice.html new file mode 100644 index 000000000..97baa37e6 --- /dev/null +++ b/crates/clazel-a64/tests/data/arm-mrs/notice.html @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + ARM Machine Readable Schema - 2.9.6 + + + + + + + +
+
+
+

AARCHMRS Schema 2.9.6

+ +
+
+ +
+ + +
+

Copyright 2010-2026 Arm Limited or its affiliates.

+

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

+
    +
  1. +

    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

    +
  2. +
  3. +

    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

    +
  4. +
  5. +

    Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

    +
  6. +
+

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+
+ +
+ +
+ +
+ + + + + + + + + + diff --git a/crates/clazel-a64/tests/data/sail-arm/LICENSE.md b/crates/clazel-a64/tests/data/sail-arm/LICENSE.md new file mode 100644 index 000000000..3f867c7ca --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/LICENSE.md @@ -0,0 +1,37 @@ +BSD 3-clause Clear License + +Copyright (c) 2023 + Arm Limited (or its affiliates), + Thomas Bauereiss, + Brian Campbell, + Alasdair Armstrong, + Alastair Reid, + Peter Sewell + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the +disclaimer below) provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of ARM Limited nor the names of its contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED +BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/clazel-a64/tests/data/sail-arm/README.md b/crates/clazel-a64/tests/data/sail-arm/README.md new file mode 100644 index 000000000..b3db669f4 --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/README.md @@ -0,0 +1,63 @@ +# Armv9-A Sail specification + +This repository contains a Sail version of the [Armv9-A ISA +specification][ARM_ARM]. + +The file `v8_base.sail` in the `src` directory contains the Sail translation of +the shared pseudocode in [Arm's ASL specification][ARM_ASL], and the files +`instrs{32,64}*.sail` contain specifications of the AArch32 instructions, the +AArch64 base instructions, as well as the AArch64 SVE and SME instructions. + +These Sail files are derived from the 2023-03 version of [Arm's ASL +specification][ARM_ASL] using the automatic [ASL-to-Sail][asl_to_sail] +translation tool. This was done using a snapshot of ASL files provided by Arm; +compared to the version of the specification [available on the Arm +website][ARM_ASL], this snapshot consists of plain ASL files rather than XML +files, and it contains automatically generated glue code connecting system +register accessors and system operations to the instruction semantics (e.g. +`AArch64_AutoGen_SysRegRead` in `sysregs_autogen.sail`). + +It also contains code that is not part of the official architecture, but allows +the generation of an executable emulator. In particular, `fetch.sail` contains +a simple top-level fetch-decode-execute function, and `impdefs.sail` and +`reset.sail` contain some default choices for implementation-defined behaviour +and initial values of system registers. + +There are also handwritten Sail files that were not translated from ASL, like +the `devices.sail` file providing the timer interrupts required by the Linux +kernel, or the `mem.sail` and `interface.sail` files connecting ASL's memory +accessor functions to the Sail memory interface. + +## Building + +To build artifacts derived from the Sail specification, make sure that a recent +version of [Sail][sail] is installed (last tested using Sail version 0.17.1), +and use the Makefile target `gen_c` to generate an emulator, and `gen_isa` or +`gen_coq` to generate a model for the Isabelle or Coq theorem prover, +respectively. + +The `boot/boot.sh` script downloads, builds, and runs a version of the Linux +kernel above the C emulator. + +## License + +The files in this repository are licensed under the BSD 3-Clause Clear license +in `LICENSE`. + +Copyright (c) 2023 Arm Limited (or its affiliates), Thomas Bauereiss, Brian +Campbell, Alasdair Armstrong, Alastair Reid, Peter Sewell + +## Funding + +This project has received funding from the European Research Council (ERC) +under the European Union’s Horizon 2020 research and innovation programme +(grant agreement No 789108, ELVER). +This work was supported by the UK Industrial Strategy Challenge Fund (ISCF) +under the Digital Security by Design (DSbD) Programme, to deliver a DSbDtech +enabled digital platform (grant 105694). +This work was supported by Arm and Google. + +[ARM_ARM]: https://developer.arm.com/documentation/ddi0487/latest +[ARM_ASL]: https://developer.arm.com/downloads/-/exploration-tools +[asl_to_sail]: https://github.com/rems-project/asl_to_sail +[sail]: https://github.com/rems-project/sail diff --git a/crates/clazel-a64/tests/data/sail-arm/SOURCE.md b/crates/clazel-a64/tests/data/sail-arm/SOURCE.md new file mode 100644 index 000000000..777929814 --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/SOURCE.md @@ -0,0 +1,34 @@ +# The Sail model of the Armv9.4-A architecture: the A64 base instructions and the shared pseudocode (a subset of its files) + +Upstream: https://github.com/rems-project/sail-arm/tree/5416ef6b43e9527c38dc71fb752259c1d01a47e1/arm-v9.4-a +Commit: 5416ef6b43e9527c38dc71fb752259c1d01a47e1 +License: BSD-3-Clause-Clear (Arm Limited, Thomas Bauereiss, Brian Campbell, Alasdair Armstrong, Alastair Reid, Peter Sewell). `LICENSE.md` is `arm-v9.4-a/LICENSE` at this commit, copied unchanged. + +The commit is the tip of `master` of rems-project/sail-arm on 2026-11-16 +("Import tweaks for Lean output", 2026-11-09). Copied byte for byte from +`arm-v9.4-a/`, the paths relative to it kept: + +- `README.md`, `LICENSE.md` (the repository's `LICENSE`); +- `src/instrs64.sail`: the AArch64 base instructions (2.1 MB), one file, so + the subset of jit.md item J.4 is a part of it; +- `src/v8_base.sail`: the shared pseudocode they call (1.7 MB); +- `src/prelude.sail`, `builtins.sail`, `decode_start.sail`, `decode_end.sail`, + `map_clauses.sail`, `event_clauses.sail`, `termination_measures.sail`, + `interface.sail`, `mem.sail`, `fetch.sail`. + +Not vendored: the AArch32 instructions (`instrs32.sail`), SVE and SME +(`instrs64_sve.sail`, `instrs64_sme.sail`, 5 MB together), the generated +system-register glue (`sysregs_autogen.sail`, 8 MB), the Coq, Isabelle, Lean +and C snapshots, and the other versions (`arm-v8.5-a`, `arm-v9.3-a`). + +**This model is derived from Arm's own ASL.** Its README says the Sail files +"are derived from the 2023-03 version of Arm's ASL specification using the +automatic ASL-to-Sail translation tool" and that the ASL came as a snapshot +provided by Arm. So it is not independent of Arm's machine-readable +specification (`arm-mrs`, Arm's 2026-09 release of the same ASL): see +`crates/clazel-a64/README.md`. + +To update, copy the files from a newer commit, change the commit above, and +run `cargo xtask testdata`. `xtask/src/testdata/isa.rs` writes +`tests/generated/sail_arm.rs`, the inventory of paths, sizes and hashes. +Nothing reads the model yet. diff --git a/crates/clazel-a64/tests/data/sail-arm/src/builtins.sail b/crates/clazel-a64/tests/data/sail-arm/src/builtins.sail new file mode 100644 index 000000000..ee666c798 --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/builtins.sail @@ -0,0 +1,208 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +val __SetConfig : forall 'value_name. (string, int('value_name)) -> unit + +val __Reset : forall ('cold : Bool). bool('cold) -> unit + +val __EndCycle : unit -> unit + +val __ListConfig : unit -> unit + +val EndOfInstruction : unit -> unit + +function EndOfInstruction () = { + throw(Error_ExceptionTaken()) +} + +val EncodingSpecificOperations : unit -> unit + +function EncodingSpecificOperations () = { + return() +} + +val IsZeroBit : forall 'N, 'N >= 0. bits('N) -> bits(1) + +function IsZeroBit x = { + return(if IsZero(x) then 0b1 else 0b0) +} + +val LSL_C : forall 'N 'shift. (bits('N), int('shift)) -> (bits('N), bits(1)) + +function LSL_C (x, shift) = { + let carry_out = if shift > 0 & shift <= 'N then x['N - shift] else bitzero; + (sail_shiftleft(x, shift), [carry_out]) +} + +overload LSL = {sail_shiftleft} + +val LSR_C : forall 'N 'shift. (bits('N), int('shift)) -> (bits('N), bits(1)) + +function LSR_C (x, shift) = { + let carry_out = if shift > 0 & shift <= 'N then x[shift - 1] else bitzero; + (sail_shiftright(x, shift), [carry_out]) +} + +overload LSR = {sail_shiftright} + +val ASR_C : forall 'N 'shift, ('N >= 0 & 'shift >= 0). + (bits('N), int('shift)) -> (bits('N), bits(1)) + +function ASR_C (x, shift) = { + let carry_out = if shift == 0 | 'N == 0 then bitzero else + if shift >= 'N then x['N - 1] else x['shift - 1]; + (sail_arith_shiftright(x, shift), [carry_out]) +} + +overload ASR = {sail_arith_shiftright} + +val ROR_C : forall 'N 'shift, 'N > 0. + (bits('N), int('shift)) -> (bits('N), bits(1)) + +function ROR_C (x, shift) = { + assert(shift > 0); + let 'm = MOD(shift, 'N); + let result : bits('N) = LSR(x, m) | LSL(x, 'N - m); + let carry_out : bits(1) = [result['N - 1]]; + return((result, carry_out)) +} + +val ROR : forall 'N 'shift, ('N > 0 & 'shift >= 0). + (bits('N), int('shift)) -> bits('N) + +function ROR (x, shift) = { + if shift == 0 then x else + let 'm = MOD(shift, 'N) in LSR(x, m) | LSL(x, 'N - m) +} + +val Extend : forall 'M 'N ('is_unsigned : Bool), + ('M >= 0 & 'N >= 0). + (bits('M), int('N), bool('is_unsigned)) -> bits('N) + +function Extend (x, N, is_unsigned) = { + return(if is_unsigned then { + assert(constraint(('M >= 0 & 'N >= 'M))); + ZeroExtend(x, N) + } else { + assert(constraint(('M > 0 & 'N >= 'M))); + SignExtend(x, N) + }) +} + +val asl_Int : forall 'N ('is_unsigned : Bool), 'N >= 0. + (bits('N), bool('is_unsigned)) -> int + +function asl_Int (x, is_unsigned) = { + let 'result = if is_unsigned then UInt(x) else { + assert(constraint('N > 0)); + SInt(x) + }; + return(result) +} + +val LowestSetBit : forall 'N, 'N >= 0. bits('N) -> int + +function LowestSetBit x = { + foreach (i from 0 to ('N - 1) by 1 in inc) { + if [x[i]] == 0b1 then { + return(i) + }; + () + }; + return('N) +} + +val HighestSetBit : forall 'N, 'N >= 0. bits('N) -> int + +function HighestSetBit x = { + foreach (i from ('N - 1) to 0 by 1 in dec) { + if [x[i]] == 0b1 then { + return(i) + }; + () + }; + return(negate(1)) +} + +val BitCount : forall 'N, 'N >= 0. bits('N) -> int + +function BitCount x = { + result : int = 0; + foreach (i from 0 to ('N - 1) by 1 in inc) { + if [x[i]] == 0b1 then { + result = result + 1 + }; + () + }; + let 'result = result; + return(result) +} + +val CountLeadingZeroBits : forall 'N, 'N >= 0. bits('N) -> int + +function CountLeadingZeroBits x = { + return('N - (HighestSetBit(x) + 1)) +} + +val CountLeadingSignBits : forall 'N, 1 <= 'N - 1. bits('N) -> int + +function CountLeadingSignBits x = { + return(CountLeadingZeroBits(EOR(x['N - 1 .. 1], x['N - 2 .. 0]))) +} + +val Elem_read : forall 'N 'e 'size, + 'N >= 0 & 'size >= 0 & ('e * 'size <= 'e * 'size + 'size - 1 | not(('e >= 0 & ('e + 1) * 'size <= 'N))). + (bits('N), int('e), int('size)) -> bits('size) + +function Elem_read (vector_name, e, size) = { + assert(e >= 0 & (e + 1) * size <= 'N); + return(vector_name[e * size + size - 1 .. e * size]) +} + +val Elem_set : forall 'N 'e 'size, + 'N >= 0 & 'size >= 0 & ('e * 'size <= ('e + 1) * 'size - 1 | not(('e >= 0 & ('e + 1) * 'size <= 'N))). + (bits('N), int('e), int('size), bits('size)) -> bits('N) + +function Elem_set (vector_name__arg, e, size, value_name) = { + vector_name : bits('N) = vector_name__arg; + assert(e >= 0 & (e + 1) * size <= 'N); + vector_name[(e + 1) * size - 1 .. e * size] = value_name; + return(vector_name) +} diff --git a/crates/clazel-a64/tests/data/sail-arm/src/decode_end.sail b/crates/clazel-a64/tests/data/sail-arm/src/decode_end.sail new file mode 100644 index 000000000..20add577c --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/decode_end.sail @@ -0,0 +1,111 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +function clause __DecodeA64_Reserved(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_SME(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_Unallocated1(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_SVE(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_Unallocated2(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_DataProcImm(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_BranchExcSys(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_LoadStore(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_DataProcReg(_, _) = throw (Error_Undefined()) +function clause __DecodeA64_DataProcFPSIMD(_, _) = throw (Error_Undefined()) + +function clause __DecodeA32_Unconditional(_, _) = throw (Error_Undefined()) +function clause __DecodeA32_DataProMisc(_, _) = throw (Error_Undefined()) +function clause __DecodeA32_LoadStoreImmLit(_, _) = throw (Error_Undefined()) +function clause __DecodeA32_LoadStoreReg(_, _) = throw (Error_Undefined()) +function clause __DecodeA32_Media(_, _) = throw (Error_Undefined()) +function clause __DecodeA32_BranchBlock(_, _) = throw (Error_Undefined()) +function clause __DecodeA32_SysASIMDFP(_, _) = throw (Error_Undefined()) + +function clause __DecodeT32(_, _) = throw (Error_Undefined()) +function clause __DecodeT16(_, _) = throw (Error_Undefined()) + +end __DecodeA64_Reserved +end __DecodeA64_SME +end __DecodeA64_Unallocated1 +end __DecodeA64_SVE +end __DecodeA64_Unallocated2 +end __DecodeA64_DataProcImm +end __DecodeA64_BranchExcSys +end __DecodeA64_LoadStore +end __DecodeA64_DataProcReg +end __DecodeA64_DataProcFPSIMD + +end __DecodeA32_Unconditional +end __DecodeA32_DataProMisc +end __DecodeA32_LoadStoreImmLit +end __DecodeA32_LoadStoreReg +end __DecodeA32_Media +end __DecodeA32_BranchBlock +end __DecodeA32_SysASIMDFP + +end __DecodeT32 +end __DecodeT16 + +function clause __DecodeA64(pc, opcode) = + match opcode { + [bitzero, _, _] @ 0x0 @ _ => __DecodeA64_Reserved(pc, opcode), + [bitone, _ ,_] @ 0x0 @ _ => __DecodeA64_SME(pc, opcode), + [_, _, _] @ 0x1 @ _ => __DecodeA64_Unallocated1(pc, opcode), + [_, _, _] @ 0x2 @ _ => __DecodeA64_SVE(pc, opcode), + [_, _, _] @ 0x3 @ _ => __DecodeA64_Unallocated2(pc, opcode), + [_, _, _] @ 0b100 @ _ => __DecodeA64_DataProcImm(pc, opcode), + [_, _, _] @ 0b101 @ _ => __DecodeA64_BranchExcSys(pc, opcode), + [_, _, _, _, bitone, _, bitzero] @ _ => __DecodeA64_LoadStore(pc, opcode), + [_, _, _, _] @ 0b101 @ _ => __DecodeA64_DataProcReg(pc, opcode), + [_, _, _, _] @ 0b111 @ _ => __DecodeA64_DataProcFPSIMD(pc, opcode), + } + +function clause __DecodeA32(pc, opcode) = + match opcode { + 0b11110 @ _ => __DecodeA32_Unconditional(pc, opcode), + [_, _, _, _] @ 0b00 @ _ => __DecodeA32_DataProMisc(pc, opcode), + [_, _, _, _] @ 0b010 @ _ => __DecodeA32_LoadStoreImmLit(pc, opcode), + [_, _, _, _] @ 0b011 @ _ @ 0b0 @ (_ : bits(4)) => __DecodeA32_LoadStoreReg(pc, opcode), + [_, _, _, _] @ 0b011 @ _ @ 0b1 @ (_ : bits(4)) => __DecodeA32_Media(pc, opcode), + [_, _, _, _] @ 0b10 @ _ => __DecodeA32_BranchBlock(pc, opcode), + [_, _, _, _] @ 0b11 @ _ => __DecodeA32_SysASIMDFP(pc, opcode), + } + +end __DecodeA64 +end __DecodeA32 diff --git a/crates/clazel-a64/tests/data/sail-arm/src/decode_start.sail b/crates/clazel-a64/tests/data/sail-arm/src/decode_start.sail new file mode 100644 index 000000000..932ea84cd --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/decode_start.sail @@ -0,0 +1,89 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +register SEE : int + +val __DecodeA64 : (int, bits(32)) -> unit +val __DecodeA32 : (int, bits(32)) -> unit +val __DecodeT32 : (int, bits(32)) -> unit +val __DecodeT16 : (int, bits(16)) -> unit + +val __DecodeA64_Reserved : (int, bits(32)) -> unit +val __DecodeA64_SME : (int, bits(32)) -> unit +val __DecodeA64_Unallocated1 : (int, bits(32)) -> unit +val __DecodeA64_SVE : (int, bits(32)) -> unit +val __DecodeA64_Unallocated2 : (int, bits(32)) -> unit +val __DecodeA64_DataProcImm : (int, bits(32)) -> unit +val __DecodeA64_BranchExcSys : (int, bits(32)) -> unit +val __DecodeA64_LoadStore : (int, bits(32)) -> unit +val __DecodeA64_DataProcReg : (int, bits(32)) -> unit +val __DecodeA64_DataProcFPSIMD : (int, bits(32)) -> unit + +val __DecodeA32_Unconditional : (int, bits(32)) -> unit +val __DecodeA32_DataProMisc : (int, bits(32)) -> unit +val __DecodeA32_LoadStoreImmLit : (int, bits(32)) -> unit +val __DecodeA32_LoadStoreReg : (int, bits(32)) -> unit +val __DecodeA32_Media : (int, bits(32)) -> unit +val __DecodeA32_BranchBlock : (int, bits(32)) -> unit +val __DecodeA32_SysASIMDFP : (int, bits(32)) -> unit + +scattered function __DecodeA64_Reserved +scattered function __DecodeA64_SME +scattered function __DecodeA64_Unallocated1 +scattered function __DecodeA64_SVE +scattered function __DecodeA64_Unallocated2 +scattered function __DecodeA64_DataProcImm +scattered function __DecodeA64_BranchExcSys +scattered function __DecodeA64_LoadStore +scattered function __DecodeA64_DataProcReg +scattered function __DecodeA64_DataProcFPSIMD + +scattered function __DecodeA32_Unconditional +scattered function __DecodeA32_DataProMisc +scattered function __DecodeA32_LoadStoreImmLit +scattered function __DecodeA32_LoadStoreReg +scattered function __DecodeA32_Media +scattered function __DecodeA32_BranchBlock +scattered function __DecodeA32_SysASIMDFP + +scattered function __DecodeA64 +scattered function __DecodeA32 +scattered function __DecodeT32 +scattered function __DecodeT16 diff --git a/crates/clazel-a64/tests/data/sail-arm/src/event_clauses.sail b/crates/clazel-a64/tests/data/sail-arm/src/event_clauses.sail new file mode 100644 index 000000000..5445ac41c --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/event_clauses.sail @@ -0,0 +1,138 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +function __EndCycle () = { + { + __cycle_count = __cycle_count + 1 + } +} + +function __ListConfig () = { + { + print_endline("cpu.has_arm_v8-1=0 (bool) default = '0'\\n : Implement the ARMv8.1 Extension.\\n"); + print_endline("cpu.has_arm_v8-2=0 (bool) default = '0'\\n : Implement the ARMv8.2 Extension.\\n"); + print_endline("cpu.has_arm_v8-3=0 (bool) default = '0'\\n : Implement the ARMv8.3 Extension.\\n"); + print_endline("cpu.has_arm_v8-4=0 (bool) default = '0'\\n : Implement the ARMv8.4 Extension. This feature is incomplete and under development.\\n"); + print_endline("cpu.num_loregions=0x0 (int) default = '0x0' \\n : Number of Limited Ordering Regions implemented excluding background region (if ARM v8.1 extensions are implemented) : [0x0..0xFF]\\n"); + print_endline("cpu.num_loregion_descriptors=0x0 (int) default = '0x0'\\n : Number of Limited Ordering Region descriptors implemented (if ARM v8.1 extensions are implemented) : [0x0..0xFF]\\n"); + print_endline("cpu.PA_SIZE=0x30 (int) default = '0x30'\\n : Physical address range supported. For ARMv8.0 and ARMv8.1 this is limited to 48 bits. : [0x20..0x34]\\n"); + print_endline("counter_addr=0x0 (int) default = '0x0'\\n : Address for memory-mapped system counter block. 0 means the counter is not mapped, otherwise the address must be 4KB aligned.\\n"); + print_endline("cpu.ext_abort_normal_cacheable_read_is_sync=1 (bool) default = '1' \\n : Synchronous reporting of normal write-back cacheable-read External aborts\\n"); + print_endline("cpu.ext_abort_normal_noncacheable_read_is_sync=1 (bool) default = '1'\\n : Synchronous reporting of normal noncacheable-read External aborts\\n"); + print_endline("cpu.ext_abort_device_read_is_sync=1 (bool) default = '1'\\n : Synchronous reporting of device-nGnRE read External aborts\\n"); + print_endline("cpu.ext_abort_so_read_is_sync=1 (bool) default = '1'\\n : Synchronous reporting of device-nGnRnE read External aborts\\n"); + print_endline("cpu.ext_abort_so_write_is_sync=1 (bool) default = '1'\\n : Synchronous reporting of device-nGnRnE write External aborts\\n"); + print_endline("cpu.ext_abort_prefetch_is_sync=1 (bool) default = '1'\\n : Behavior of External aborts generated by normal writeback cacheable instruction fetches.\\n [0, 1], 0: asynchronous abort, 1: synchronous abort.\\n"); + print_endline("cpu.ext_abort_ttw_cacheable_read_is_sync=1 (bool) default = '1'\\n : Synchronous reporting of TTW cacheable read External aborts\\n"); + print_endline("cpu.ext_abort_ttw_noncacheable_read_is_sync=1 (bool) default = '1'\\n : Synchronous reporting of TTW noncacheable read External aborts\\n"); + print_endline("cpu.ext_abort_normal_cacheable_write_is_sync=0 (bool) default = '0'\\n : Synchronous reporting of normal write-back cacheable write External aborts\\n"); + print_endline("cpu.ext_abort_normal_noncacheable_write_is_sync=0 (bool) default = '0'\\n : Synchronous reporting of normal noncacheable write External aborts\\n"); + print_endline("cpu.ext_abort_device_write_is_sync=0 (bool) default = '0'\\n : Synchronous reporting of device-nGnRE write External aborts\\n"); + print_endline("cpu.unpred_tsize_aborts=0 (bool) default = '0'\\n : Behavior when TSize is out of range.\\n [0, 1], 0: force into range. 1: translation fault, forces unpred_tsize_pamax_aborts to 1.\\n"); + print_endline("cpu.isb_is_branch=1 (bool) default='1'\\n : ISB is treated as branch"); + print_endline("cpu.cpu0.enable_crc32=0x0 (int) default = '0x0'\\n : CRC32 instructions supported.\\n [0, 1], 0: CRC32 not implemented. 1: CRC32 instructions implemented.\\n"); + print_endline("cpu.has_pstate_pan=0x1 (int) default = '0x1' \\n : Implement the PSTATE.PAN (Privileged Access Never) control from ARMv8.1.\\n [0, 1], 0: not implemented. 1: Implemented\\n"); + print_endline("cpu.has_16bit_vmids=0x1 (int) default = '0x1'\\n : Implement support for 16-bit VMIDs from ARMv8.1\\n [0, 1], 0: Not enabled, 1: Implemented\\n"); + print_endline("cpu.has_dot_product=0x1 (int) default = '0x1' \\n : Implement the dot product (UDOT, SDOT) instructions from ARMv8.4\\n [0, 1], 0: Not implemnetd, 1: Implemnetd\\n"); + print_endline("cpu.has_fp16=0x1 (int) default = '0x1' \\n : Implement the half-precision floating-point data processing instructions from ARMv8.2.\\n [0, 1] 0: feature is not enabled. 1: feature is implemented\\n"); + print_endline("cpu.has_aarch32_hpd=0 (bool) default = '0'\\n : If true then hierarchical permission disable is supported in AArch32\\n"); + print_endline("cpu.has_tlb=0x1 (bool) default = '1'\\n : If true then TLB is enabled\\n"); + print_endline("cpu.has_trickbox=0x1 (bool) default = '1'\\n : If true then Trickbox and abort region checks are enabled\\n"); + print_endline("cpu.VAL_ignore_rvbar_in_aarch32=0 default = '0'\\n : If '1', ignore RVBAR while determining reset vector in AArch32. This is required for ACK tests \\n"); + print_endline("SVE.ScalableVectorExtension.sme_veclens_implemented=7 (int) default = '0x7'\\n : Implies which SME vector lengths are implemented: represented as a bitfield where bit[n]==1 implies SME vector length of 128*2^n bits is implemented \\n"); + print_endline("SVE.ScalableVectorExtension.veclen=0x20 (int) default = '0x20'\\n : Implies which non streaming SVE vector lengths are implemented: size of vector in uints of 64 bits \\n"); + print_endline("SVE.ScalableVectorExtension.has_sme=1 (bool) default = '1'\\n : If SME is implemented or not\\n"); + print_endline("SVE.ScalableVectorExtension.sme_only=0 (bool) default = '0'\\n : Where SME is implemented, whether SVE functionality is available only when SM=1 \\n"); + print_endline("SVE.ScalableVectorExtension.has_sme_priority_control=1 (bool) default = '1'\\n : Whether SME prioirty Control is implemented \\n"); + print_endline("SVE.ScalableVectorExtension.has_sme_f64f64=1 (bool) default = '1'\\n : Where SME is implemented, whether double precision FMOPA and FMOPS are implemented \\n"); + print_endline("SVE.ScalableVectorExtension.has_sme_i16i64=1 (bool) default = '1'\\n : Where SME is implemented, whether instructions that accumulate 16-bit integer outer products into 64-bit integer tiles are implemented \\n"); + print_endline("SVE.ScalableVectorExtension.has_sve_extended_bf16=0x2 (int) default = '0x2'\\n : Whether Extended BFloat16 instructions are implemented: 0 - Disabled, 1 - Enabled, 2 - Enabled if SME is implemented \\n"); + print_endline("cpu.has_extended_recp_estimate=0x0 (int) default = '0x1'\\n : Whether increased Reciprocal Estimate and Square Root Estimate precision is supported: 0 - Disabled, 1 - Enabled \\n"); + print_endline("cpu.has_mpam=1 (bool) default = 0\\n : Implement the MPAM extension.\\n [0, 1] 0: FALSE, not implemented. 1: TRUE, implemented.\\n"); + print_endline("cpu.has_mpamhcr=1 (bool) default = 1\\n : If MPAM is implemented, also implement the MPAM virtualization features.\\n [0, 1] 0: FALSE, not implemented. 1: TRUE, implemented.\\n"); + print_endline("cpu.mpam_partid_max=127 (int) default = 0\\n : [0 .. 65535] Maximum MPAM PARTID supported by the implementation."); + print_endline("cpu.mpam_pmg_max=3 (int) default = 0\\n : [0 .. 255] Maximum MPAM PMG supported by the implementation.\\n"); + print_endline("cpu.mpam_vpmr_max=2 (int) default = 0\\n : [0 .. 7] Maximum MPAM virtual PARTID mapping register implemented.\\n"); + print_endline("cpu.mpam_has_altsp=1 (int) default = 1\\n : [0, 1] Whether MPAMIDR_EL1.HAS_ALTSP is set or cleared.\\n"); + print_endline("cpu.has_empam=1 (bool) default = 0\\n : Implement the Enhanced MPAM extension.\\n [0, 1] 0: FALSE, not implemented. 1: TRUE, implemented.\\n"); + print_endline("cpu.empam_has_tidr (bool) default = 0\\n : Implement the MPAM2_EL2.TIDR bit to trap MPAMIDR_EL1.\\n [0, 1] 0: FALSE, not implemented. 1: TRUE, implemented.\\n"); + print_endline("cpu.empam_has_sdeflt (bool) default = 0\\n : Implement the MPAM3_EL3.SDEFLT bit to generate only the default PARTID in Secure execution.\\n [0, 1] 0: FALSE, not implemented. 1: TRUE, implemented.\\n"); + print_endline("cpu.empam_has_force_ns (bool) default = 0\\n : Implement the MPAMe_EL3.FORCE_NS bit to generate Non-secure PARTIDs in Secure execution.\\n [0, 1] 0: FALSE, not implemented. 1: TRUE, implemented.\\n"); + print_endline("cpu.empam_force_ns_RAO (bool) default = 0\\n : Implement the MPAM3_EL3.FORCE_NS bit as Read-as-One.\\n [0, 1] 0: FALSE, not implemented. 1: TRUE, implemented.\\n"); + print_endline("cpu.cpu0.crypto_aes=0x2 (int) default = '0x2'\\n : AES and 128 bit PMULL instructions supported.\\n [0, 1, 2], 0: AES instruction not implemented. 1: AES instruction implemented. 2: AES plus 128bit PMULL instruction implemented\\n"); + print_endline("cpu.cpu0.crypto_sha1=0x1 (int) default = '0x1'\\n : SHA1 instructions supported.\\n [0, 1], 0: SHA1 not implemented. 1: SHA1 instructions implemented.\\n"); + print_endline("cpu.cpu0.crypto_sha256=0x1 (int) default = '0x1'\\n : SHA256 instructions supported.\\n [0, 1], 0: SHA256 not implemented. 1: SHA256 instructions implemented.\\n"); + print_endline("cpu.cpu0.crypto_sha512=0x0 (int) default = '0x0'\\n : SHA512 instructions supported.\\n [0, 1], 0: SHA512 not implemented. 1: SHA512 instructions implemented.\\n"); + print_endline("cpu.cpu0.crypto_sha3=0x0 (int) default = '0x0'\\n : SHA3 instructions supported.\\n [0, 1], 0: SHA3 not implemented. 1: SHA3 instructions implemented.\\n"); + print_endline("cpu.cpu0.crypto_sm3=0x0 (int) default = '0x0'\\n : SM3 instructions supported.\\n [0, 1], 0: SM3 not implemented. 1: SM3 instructions implemented.\\n"); + print_endline("cpu.cpu0.crypto_sm4=0x0 (int) default = '0x0'\\n : SM4 instructions supported.\\n [0, 1], 0: SM4 not implemented. 1: SM4 instructions implemented.\\n"); + print_endline("cpu.cpu0.number-of-breakpoints=0x10 (int) default='0x10'\\n : [1 .. 16] Number of breakpoints.\\n"); + print_endline("cpu.cpu0.number-of-context-breakpoints=0x10 (int) default='0x10'\\n : [1 .. 16] Number of breakpoints that are context aware.\\n"); + print_endline("cpu.cpu0.number-of-watchpoints=0x10 (int) default='0x10'\\n : [1 .. 16] Number of watchpoints.\\n"); + print_endline("cpu.pmu-num_counters=0x1f (int) default='0x1f'\\n : [1 .. 16] Number of event counters.\\n"); + print_endline("cpu.has_brbe=0x1 (int) default='0x1'\\n : Branch Record Buffer Extension supported.\\n [0, 1], 0 Not implemented, 1: Implemented\\n"); + print_endline("cpu.cpu0.number-of-branch-records=0x40 (int) default='0x40'\\n : [16, 32, 48, 64] Number of BRB records.\\n"); + print_endline("cpu.has_mops_option=0x1 (int) default='0x1'\\n : FEAT_MOPS uses option A or B. \\n [1, 2], 1 FEAT_MOPS uses option A, 2 FEAT_MOPS uses option B\\n"); + print_endline("cpu.mops_cpy_default_dir=0 (int) default='0x0'\\n : CPY* instructions copy in forward/backward direction in non-overlapping case,\\n [0, 1], 0 forward direction, 1 backward direction.\\n"); + print_endline("cpu.has_brbe_v9_3=0x1 (int) default='0x1'\\n :if 1, implements FEAT_BRBEv1p1.\\n"); + print_endline("spe.pseudo_cycles=0 (bool) default=0 \\n :if 1, extra cycles are generated on memory reads and writes.\\n"); + print_endline("ZCR_EL3.LEN=0xf (int) default=UNKNOWN \\n :Specify the vector size of VL at EL3.\\n"); + print_endline("CPTR_EL3.EZ=0x1 (int) default=UNKNOWN \\n :Enable Trap for non-streaming mode SVE instructions.\\n"); + print_endline("CPTR_EL3.ESM=0x1 (int) default=UNKNOWN \\n :Enable Trap for SME instructions.\\n"); + print_endline("SMCR_EL3.LEN=0xf (int) default=UNKNOWN \\n :Specify the effective streaming vector length.\\n") + } +} + +function __Reset cold = { + { + __last_cycle_count = 0 + }; + { + __last_branch_valid = false + }; + { + sp_rel_access_pc = Ones(64) + }; + { + __cycle_count = 0 + } +} + +function __WakeupRequest () = () diff --git a/crates/clazel-a64/tests/data/sail-arm/src/fetch.sail b/crates/clazel-a64/tests/data/sail-arm/src/fetch.sail new file mode 100644 index 000000000..efdf97ebc --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/fetch.sail @@ -0,0 +1,389 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +function AArch32_CurrentCond () = { + return(__currentCond) +} + +function UnallocatedA32_Instruction instr = { + nop : bool = undefined; + match instr { + [_, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => { + let cond : bits(4) = instr[31 .. 28]; + nop = cond != 0b1111 + }, + [bitone, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => { + nop = true + }, + [bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, _, _, _, _] => { + nop = true + }, + _ => { + nop = false + } + }; + if not_bool(nop) & ConditionHolds(AArch32_CurrentCond()) then { + AArch32_UndefinedFault() + }; + () +} + +function UnallocatedT32_32_Instruction instr = { + nop : bool = undefined; + match instr { + [bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, bitone, bitzero, _, bitzero, _, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _] => { + nop = true + }, + [bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _] => { + nop = true + }, + [bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _] => { + nop = true + }, + [bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _] => { + nop = true + }, + [bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, _, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _] => { + nop = true + }, + _ => { + nop = false + } + }; + let nop = nop; + if not_bool(nop) & ConditionHolds(AArch32_CurrentCond()) then { + AArch32_UndefinedFault() + }; + () +} + +function UnallocatedT32_16_Instruction instr = { + nop : bool = undefined; + match instr { + [bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, bitzero, bitzero, bitzero, bitzero] => { + let hint : bits(4) = instr[7 .. 4]; + match hint { + [bitzero, bitone, bitone, _] => { + nop = true + }, + [bitone, _, _, _] => { + nop = true + }, + _ => { + nop = false + } + } + }, + _ => { + nop = false + } + }; + if not_bool(nop) & ConditionHolds(AArch32_CurrentCond()) then { + AArch32_UndefinedFault() + }; + () +} + +function __DefaultCond enc = { + cond : bits(4) = undefined; + if (enc == __A64 | enc == __A32) | PSTATE.IT[3 .. 0] == Zeros(4) then { + cond = 0xE + } else { + cond = PSTATE.IT[7 .. 4] + }; + return(cond) +} + +function __SetThisInstrDetails (enc, opcode, cond) = { + __ThisInstrEnc = enc; + __ThisInstr = opcode; + __currentCond = cond; + return() +} + +function ExecuteA64 instr = { + if Halted() then { + try { + __SetThisInstrDetails(__A64, instr, __DefaultCond(__A64)); + __DecodeA64(UInt(_PC), instr) + } catch { + exn if IsExceptionTaken(exn) => (), + exn if (IsSEE(exn) | IsUNDEFINED(exn)) | IsUNPREDICTABLE(exn) => { + AArch64_UndefinedFault() + } + } + } else { + __DecodeA64(UInt(_PC), instr) + } +} + +function ExecuteA32 instr = { + __DecodeA32(UInt(_PC), instr) +} + +function ExecuteT32__1 instr = { + if Halted() then { + try { + __SetThisInstrDetails(__T32, instr, __DefaultCond(__T32)); + __DecodeT32(UInt(_PC), instr) + } catch { + exn if IsExceptionTaken(exn) => (), + exn if (IsSEE(exn) | IsUNDEFINED(exn)) | IsUNPREDICTABLE(exn) => { + UnallocatedT32_32_Instruction(instr) + } + } + } else { + __DecodeT32(UInt(_PC), instr) + } +} + +function ExecuteT16 instr = { + __DecodeT16(UInt(_PC), instr) +} + +function ThisInstr () = { + return(__ThisInstr) +} + +function ThisInstrLength () = { + return(if __ThisInstrEnc == __T16 then 16 else 32) +} + +function NextInstrAddr N = { + assert(constraint((0 <= 'N - 1 & 'N - 1 < 64))); + return((_PC + DIV(ThisInstrLength(), 8))[N - 1 .. 0]) +} + +function __FetchInstr pc = { + hw1 : bits(16) = undefined; + hw2 : bits(16) = undefined; + isT16 : bool = undefined; + enc : __InstrEnc = undefined; + instr : bits(32) = undefined; + let accdesc : AccessDescriptor = CreateAccDescIFetch(); + SetBTypeCompatible(false); + CheckSoftwareStep(); + if PSTATE.nRW == 0b0 then { + AArch64_CheckPCAlignment(); + enc = __A64; + instr = AArch64_MemSingle_read(PC_read(), 4, accdesc, true); + AArch64_CheckIllegalState() + } else { + AArch32_CheckPCAlignment(); + if PSTATE.T == 0b1 then { + let hw1 : bits(16) = AArch32_MemSingle_read(pc[31 .. 0], 2, accdesc, true); + let isT16 : bool = UInt(hw1[15 .. 11]) < UInt(0b11101); + if isT16 then { + enc = __T16; + instr = Zeros(16) @ hw1 + } else { + let hw2 : bits(16) = AArch32_MemSingle_read(pc[31 .. 0] + 2, 2, accdesc, true); + enc = __T32; + instr = hw1 @ hw2 + } + } else { + enc = __A32; + instr = AArch32_MemSingle_read(pc[31 .. 0], 4, accdesc, true) + }; + AArch32_CheckIllegalState() + }; + return((enc, instr)) +} + +val __TryDecodeExecute : (__InstrEnc, bits(32)) -> unit + +function __TryDecodeExecute (enc, instr) = { + match enc { + __A64 => { + ExecuteA64(instr) + }, + __A32 => { + ExecuteA32(instr) + }, + __T16 => { + ExecuteT16(instr[15 .. 0]) + }, + __T32 => { + ExecuteT32__1(instr) + } + }; + return() +} + +function __DecodeExecute (enc, instr) = { + // SEE is handled in the Sail model by throwing a specific Sail exception + // after recording the instruction we just tried in a global variable, so + // that we can then retry decodings that we haven't tried yet. + try { + __TryDecodeExecute(enc, instr) + } catch { + exn if IsSEE(exn) => { + // Retry decode in case of SEE; retrying once seems enough in practice + __TryDecodeExecute(enc, instr) + }, + exn => throw(exn) // Pass through other kinds of exceptions + } +} + +register __emulator_termination_opcode : option(bits(32)) = None() + +val __CheckForEmulatorTermination : (__InstrEnc, bits(32)) -> unit + +function __CheckForEmulatorTermination(enc, instr) = { + // Check for magic opcode to terminate the emulator + match __emulator_termination_opcode { + Some(magic) => + if instr == magic then { + print("[Sail] Terminating emulation at opcode " ++ bits_str(magic) ++ "\n"); + exit() + }, + None() => () + } +} + +function __InstructionExecute () = { + enc : __InstrEnc = undefined; + instr : bits(32) = undefined; + EDSCR_write() = [EDSCR_read() with PipeAdv = 0b1]; + if not_bool(IsZero(EDESR.bits)) then { + CheckPendingOSUnlockCatch(); + CheckPendingResetCatch(); + CheckPendingExceptionCatch(true) + }; + try { + ShouldAdvanceIT = PSTATE.nRW == 0b1 & PSTATE.T == 0b1; + ShouldAdvanceSS = true; + let pc : bits(64) = ThisInstrAddr(64); + (enc, instr) = __FetchInstr(pc); + __CheckForEmulatorTermination(enc, instr); + PMUEvent(PMU_EVENT_INST_SPEC); + __BranchTaken = false; + __ExclusiveMonitorSet = false; + __SetThisInstrDetails(enc, instr, __DefaultCond(enc)); + SPEPreExecution(); + __DecodeExecute(enc, instr); + PMUEvent(PMU_EVENT_INST_RETIRED) + } catch { + exn if (IsSEE(exn) | IsUNDEFINED(exn)) | IsUNPREDICTABLE(exn) => { + if UsingAArch32() then { + match enc { + __A32 => { + UnallocatedA32_Instruction(instr) + }, + __T16 => { + UnallocatedT32_16_Instruction(instr[15 .. 0]) + }, + __T32 => { + UnallocatedT32_32_Instruction(instr) + }, + _ => { + Unreachable() + } + } + } else { + AArch64_UndefinedFault() + } + }, + exn if IsExceptionTaken(exn) => () + }; + SPEPostExecution(); + InGuardedPage = false; + if not_bool(AArch64_ExecutingERETInstr()) then { + PSTATE.BTYPE = BTypeNext + }; + if not_bool(__BranchTaken) then { + _PC = (_PC + DIV(ThisInstrLength(), 8))[63 .. 0] + }; + if ShouldAdvanceIT then { + AArch32_ITAdvance() + }; + if ShouldAdvanceSS then { + SSAdvance() + }; + return() +} + +function __TopLevel () = { + interrupt_taken : bool = undefined; + if Halted() then { + return() + }; + interrupt_req : InterruptReq = undefined; + interrupt_req.take_SE = true; + interrupt_req.take_vSE = true; + interrupt_req.take_IRQ = true; + interrupt_req.take_vIRQ = true; + interrupt_req.take_FIQ = true; + interrupt_req.take_vFIQ = true; + try { + let interrupt_taken : bool = TakePendingInterrupts(interrupt_req); + if not_bool(interrupt_taken) then { + if Branchtypetaken == BranchType_RESET then { + CheckResetCatch(); + Branchtypetaken = BranchType_UNKNOWN + }; + __InstructionExecute() + }; + () + } catch { + Error_SError(iesb_req) => { + // Take physical SError exception + // (see TakeUnmaskedPhysicalSErrorInterrupts) + if UsingAArch32() then { + AArch32_TakePhysicalSErrorException(iesb_req) + } else { + AArch64_TakePhysicalSErrorException(iesb_req) + } + }, + Error_ExceptionTaken() => (), // Exception setup should have been done by AArch{32,64}_TakeException + e => throw(e) // Pass through other exceptions + } +} + +function __CycleEnd () = { + SPECycle(); + __UpdateSystemCounter(); + if UsingAArch32() then { + AArch32_PMUCycle() + } else { + AArch64_PMUCycle() + }; + __EndCycle() +} diff --git a/crates/clazel-a64/tests/data/sail-arm/src/instrs64.sail b/crates/clazel-a64/tests/data/sail-arm/src/instrs64.sail new file mode 100644 index 000000000..4a4aea22c --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/instrs64.sail @@ -0,0 +1,53106 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +val execute_aarch64_instrs_integer_arithmetic_unary_abs : forall 'd 'datasize 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_unary_abs (d, datasize, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let 'result = Abs(SInt(operand1)); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_abs_aarch64_instrs_integer_arithmetic_unary_abs : (bits(5), bits(5), bits(1)) -> unit + +function decode_abs_aarch64_instrs_integer_arithmetic_unary_abs (Rd, Rn, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'd = UInt(Rd); + execute_aarch64_instrs_integer_arithmetic_unary_abs(d, datasize, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1) = { + SEE = 1; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sf = Slice(__opcode, 31, 1); + decode_abs_aarch64_instrs_integer_arithmetic_unary_abs(Rd, Rn, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd : forall 'd 'datasize 'elements 'esize 'n ('neg : Bool), + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), bool('neg)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd (d, datasize, elements, esize, n, neg) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = SInt(Elem_read(operand, e, esize)); + if neg then { + element = negate(element) + } else { + element = Abs(element) + }; + result = Elem_set(result, e, esize, element[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_abs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_abs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 2) = { + SEE = 2; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_abs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd(Rd, Rn, size, U) +} + +val decode_abs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_abs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 3) = { + SEE = 3; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_abs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_simd(Rd, Rn, size, U, Q) +} + +val decode_neg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_neg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 4) = { + SEE = 4; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_neg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd(Rd, Rn, size, U) +} + +val decode_neg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_neg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 5) = { + SEE = 5; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_neg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_int_simd(Rd, Rn, size, U, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_add_sub_carry : forall 'd 'datasize 'm 'n ('setflags : Bool) ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n), bool('setflags), bool('sub_op)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_add_sub_carry (d, datasize, m, n, setflags, sub_op) = { + result : bits('datasize) = undefined; + let operand1 : bits('datasize) = X_read(n, datasize); + operand2 : bits('datasize) = X_read(m, datasize); + nzcv : bits(4) = undefined; + if sub_op then { + operand2 = not_vec(operand2) + }; + (result, nzcv) = AddWithCarry(operand1, operand2, PSTATE.C); + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + X_set(d, datasize) = result +} + +val decode_adc_aarch64_instrs_integer_arithmetic_add_sub_carry : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_adc_aarch64_instrs_integer_arithmetic_add_sub_carry (Rd, Rn, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + execute_aarch64_instrs_integer_arithmetic_add_sub_carry(d, datasize, m, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 6) = { + SEE = 6; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_adc_aarch64_instrs_integer_arithmetic_add_sub_carry(Rd, Rn, Rm, S, op, sf) +} + +val decode_adcs_aarch64_instrs_integer_arithmetic_add_sub_carry : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_adcs_aarch64_instrs_integer_arithmetic_add_sub_carry (Rd, Rn, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + execute_aarch64_instrs_integer_arithmetic_add_sub_carry(d, datasize, m, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 7) = { + SEE = 7; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_adcs_aarch64_instrs_integer_arithmetic_add_sub_carry(Rd, Rn, Rm, S, op, sf) +} + +val decode_sbc_aarch64_instrs_integer_arithmetic_add_sub_carry : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_sbc_aarch64_instrs_integer_arithmetic_add_sub_carry (Rd, Rn, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + execute_aarch64_instrs_integer_arithmetic_add_sub_carry(d, datasize, m, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 8) = { + SEE = 8; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_sbc_aarch64_instrs_integer_arithmetic_add_sub_carry(Rd, Rn, Rm, S, op, sf) +} + +val decode_sbcs_aarch64_instrs_integer_arithmetic_add_sub_carry : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_sbcs_aarch64_instrs_integer_arithmetic_add_sub_carry (Rd, Rn, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + execute_aarch64_instrs_integer_arithmetic_add_sub_carry(d, datasize, m, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 9) = { + SEE = 9; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_sbcs_aarch64_instrs_integer_arithmetic_add_sub_carry(Rd, Rn, Rm, S, op, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd : forall 'd 'datasize 'elements 'esize 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd (d, datasize, elements, esize, m, n, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + if sub_op then { + result = Elem_set(result, e, esize, element1 - element2) + } else { + result = Elem_set(result, e, esize, element1 + element2) + } + }; + V_set(d, datasize) = result +} + +val decode_add_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_add_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let sub_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 10) = { + SEE = 10; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_add_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd(Rd, Rn, Rm, size, U) +} + +val decode_add_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_add_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 11) = { + SEE = 11; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_add_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_simd(Rd, Rn, Rm, size, U, Q) +} + +val decode_sub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let sub_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 12) = { + SEE = 12; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd(Rd, Rn, Rm, size, U) +} + +val decode_sub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_sisd(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 13) = { + SEE = 13; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_single_simd(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg : forall 'd 'datasize 'm 'n ('setflags : Bool) 'shift_amount ('sub_op : Bool), + (0 <= 'shift_amount & 'shift_amount <= 63 & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n), bool('setflags), int('shift_amount), ShiftType, bool('sub_op)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg (d, datasize, m, n, setflags, shift_amount, shift_type, sub_op) = { + result : bits('datasize) = undefined; + let operand1 : bits('datasize) = X_read(n, datasize); + operand2 : bits('datasize) = ShiftReg(m, shift_type, shift_amount, datasize); + nzcv : bits(4) = undefined; + carry_in : bits(1) = undefined; + if sub_op then { + operand2 = not_vec(operand2); + carry_in = 0b1 + } else { + carry_in = 0b0 + }; + (result, nzcv) = AddWithCarry(operand1, operand2, carry_in); + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + X_set(d, datasize) = result +} + +val decode_add_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(2), bits(1), bits(1), bits(1)) -> unit + +function decode_add_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg (Rd, Rn, imm6, Rm, shift, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + if shift == 0b11 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + execute_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(d, datasize, m, n, setflags, shift_amount, shift_type, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 14) = { + SEE = 14; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let shift = Slice(__opcode, 22, 2); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_add_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(Rd, Rn, imm6, Rm, shift, S, op, sf) +} + +val decode_adds_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(2), bits(1), bits(1), bits(1)) -> unit + +function decode_adds_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg (Rd, Rn, imm6, Rm, shift, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + if shift == 0b11 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + execute_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(d, datasize, m, n, setflags, shift_amount, shift_type, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitone, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 15) = { + SEE = 15; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let shift = Slice(__opcode, 22, 2); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_adds_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(Rd, Rn, imm6, Rm, shift, S, op, sf) +} + +val decode_sub_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(2), bits(1), bits(1), bits(1)) -> unit + +function decode_sub_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg (Rd, Rn, imm6, Rm, shift, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + if shift == 0b11 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + execute_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(d, datasize, m, n, setflags, shift_amount, shift_type, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 16) = { + SEE = 16; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let shift = Slice(__opcode, 22, 2); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_sub_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(Rd, Rn, imm6, Rm, shift, S, op, sf) +} + +val decode_subs_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(2), bits(1), bits(1), bits(1)) -> unit + +function decode_subs_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg (Rd, Rn, imm6, Rm, shift, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + if shift == 0b11 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + execute_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(d, datasize, m, n, setflags, shift_amount, shift_type, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 17) = { + SEE = 17; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let shift = Slice(__opcode, 22, 2); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_subs_addsub_shift_aarch64_instrs_integer_arithmetic_add_sub_shiftedreg(Rd, Rn, imm6, Rm, shift, S, op, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_add_sub_immediate : forall 'd 'datasize 'n ('setflags : Bool) ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bits('datasize), int('n), bool('setflags), bool('sub_op)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_add_sub_immediate (d, datasize, imm, n, setflags, sub_op) = { + result : bits('datasize) = undefined; + let operand1 : bits('datasize) = if n == 31 then + SP_read()[datasize - 1 .. 0] + else + X_read(n, datasize); + operand2 : bits('datasize) = imm; + nzcv : bits(4) = undefined; + carry_in : bits(1) = undefined; + if sub_op then { + operand2 = not_vec(operand2); + carry_in = 0b1 + } else { + carry_in = 0b0 + }; + (result, nzcv) = AddWithCarry(operand1, operand2, carry_in); + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + if d == 31 & not_bool(setflags) then { + SP_set() = ZeroExtend(result, 64) + } else { + X_set(d, datasize) = result + } +} + +val decode_add_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate : (bits(5), bits(5), bits(12), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_add_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate (Rd, Rn, imm12, sh, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + imm : bits('datasize) = undefined; + match sh { + 0b0 => { + imm = ZeroExtend(imm12, datasize) + }, + 0b1 => { + imm = ZeroExtend(imm12 @ Zeros(12), datasize) + } + }; + let imm = imm; + execute_aarch64_instrs_integer_arithmetic_add_sub_immediate(d, datasize, imm, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 18) = { + SEE = 18; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let sh = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_add_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate(Rd, Rn, imm12, sh, S, op, sf) +} + +val decode_adds_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate : (bits(5), bits(5), bits(12), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_adds_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate (Rd, Rn, imm12, sh, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + imm : bits('datasize) = undefined; + match sh { + 0b0 => { + imm = ZeroExtend(imm12, datasize) + }, + 0b1 => { + imm = ZeroExtend(imm12 @ Zeros(12), datasize) + } + }; + let imm = imm; + execute_aarch64_instrs_integer_arithmetic_add_sub_immediate(d, datasize, imm, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 19) = { + SEE = 19; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let sh = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_adds_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate(Rd, Rn, imm12, sh, S, op, sf) +} + +val decode_sub_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate : (bits(5), bits(5), bits(12), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_sub_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate (Rd, Rn, imm12, sh, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + imm : bits('datasize) = undefined; + match sh { + 0b0 => { + imm = ZeroExtend(imm12, datasize) + }, + 0b1 => { + imm = ZeroExtend(imm12 @ Zeros(12), datasize) + } + }; + let imm = imm; + execute_aarch64_instrs_integer_arithmetic_add_sub_immediate(d, datasize, imm, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 20) = { + SEE = 20; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let sh = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_sub_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate(Rd, Rn, imm12, sh, S, op, sf) +} + +val decode_subs_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate : (bits(5), bits(5), bits(12), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_subs_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate (Rd, Rn, imm12, sh, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + imm : bits('datasize) = undefined; + match sh { + 0b0 => { + imm = ZeroExtend(imm12, datasize) + }, + 0b1 => { + imm = ZeroExtend(imm12 @ Zeros(12), datasize) + } + }; + let imm = imm; + execute_aarch64_instrs_integer_arithmetic_add_sub_immediate(d, datasize, imm, n, setflags, sub_op) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 21) = { + SEE = 21; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let sh = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_subs_addsub_imm_aarch64_instrs_integer_arithmetic_add_sub_immediate(Rd, Rn, imm12, sh, S, op, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_add_sub_extendedreg : forall 'd 'datasize 'm 'n ('setflags : Bool) 'shift ('sub_op : Bool), + ('shift in {0, 1, 2, 3, 4, 5, 6, 7} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), ExtendType, int('m), int('n), bool('setflags), int('shift), bool('sub_op)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_add_sub_extendedreg (d, datasize, extend_type, m, n, setflags, shift, sub_op) = { + result : bits('datasize) = undefined; + let operand1 : bits('datasize) = if n == 31 then + SP_read()[datasize - 1 .. 0] + else + X_read(n, datasize); + operand2 : bits('datasize) = ExtendReg(m, extend_type, shift, datasize); + nzcv : bits(4) = undefined; + carry_in : bits(1) = undefined; + if sub_op then { + operand2 = not_vec(operand2); + carry_in = 0b1 + } else { + carry_in = 0b0 + }; + (result, nzcv) = AddWithCarry(operand1, operand2, carry_in); + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + if d == 31 & not_bool(setflags) then { + SP_set() = ZeroExtend(result, 64) + } else { + X_set(d, datasize) = result + } +} + +val decode_add_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg : (bits(5), bits(5), bits(3), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_add_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg (Rd, Rn, imm3, option_name, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = UInt(imm3); + if shift > 4 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(d, datasize, extend_type, m, n, setflags, shift, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 22) = { + SEE = 22; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm3 = Slice(__opcode, 10, 3); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_add_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(Rd, Rn, imm3, option_name, Rm, S, op, sf) +} + +val decode_adds_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg : (bits(5), bits(5), bits(3), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_adds_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg (Rd, Rn, imm3, option_name, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = UInt(imm3); + if shift > 4 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(d, datasize, extend_type, m, n, setflags, shift, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 23) = { + SEE = 23; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm3 = Slice(__opcode, 10, 3); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_adds_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(Rd, Rn, imm3, option_name, Rm, S, op, sf) +} + +val decode_sub_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg : (bits(5), bits(5), bits(3), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_sub_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg (Rd, Rn, imm3, option_name, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = UInt(imm3); + if shift > 4 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(d, datasize, extend_type, m, n, setflags, shift, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 24) = { + SEE = 24; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm3 = Slice(__opcode, 10, 3); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_sub_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(Rd, Rn, imm3, option_name, Rm, S, op, sf) +} + +val decode_subs_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg : (bits(5), bits(5), bits(3), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_subs_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg (Rd, Rn, imm3, option_name, Rm, S, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let setflags : bool = S == 0b1; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = UInt(imm3); + if shift > 4 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(d, datasize, extend_type, m, n, setflags, shift, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 25) = { + SEE = 25; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm3 = Slice(__opcode, 10, 3); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let S = Slice(__opcode, 29, 1); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_subs_addsub_ext_aarch64_instrs_integer_arithmetic_add_sub_extendedreg(Rd, Rn, imm3, option_name, Rm, S, op, sf) +} + +val execute_aarch64_instrs_integer_tags_mcaddtag : forall ('ADD : Bool) 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (bool('ADD), int('d), int('n), bits(64), bits(4)) -> unit + +function execute_aarch64_instrs_integer_tags_mcaddtag (ADD, d, n, offset, tag_offset) = { + let operand1 : bits(64) = if n == 31 then SP_read() else X_read(n, 64); + let start_tag : bits(4) = AArch64_AllocationTagFromAddress(operand1); + let exclude : bits(16) = GCR_EL1[Exclude]; + result : bits(64) = undefined; + rtag : bits(4) = undefined; + if AArch64_AllocationTagAccessIsEnabled(PSTATE.EL) then { + rtag = AArch64_ChooseNonExcludedTag(start_tag, tag_offset, exclude) + } else { + rtag = 0b0000 + }; + if ADD then { + let (__tup_0 : bits(64), _) = AddWithCarry(operand1, offset, 0b0); + result = __tup_0 + } else { + let (__tup_0 : bits(64), _) = AddWithCarry(operand1, not_vec(offset), 0b1); + result = __tup_0 + }; + let result : bits(64) = AArch64_AddressWithAllocationTag(result, rtag); + if d == 31 then { + SP_set() = result + } else { + X_set(d, 64) = result + } +} + +val decode_addg_aarch64_instrs_integer_tags_mcaddtag : (bits(5), bits(5), bits(4), bits(2), bits(6)) -> unit + +function decode_addg_aarch64_instrs_integer_tags_mcaddtag (Xd, Xn, uimm4, op3, uimm6) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Xd); + let 'n = UInt(Xn); + let tag_offset : bits(4) = uimm4; + let offset : bits(64) = LSL(ZeroExtend(uimm6, 64), LOG2_TAG_GRANULE); + let ADD : bool = true; + execute_aarch64_instrs_integer_tags_mcaddtag(ADD, d, n, offset, tag_offset) +} + +function clause __DecodeA64_DataProcImm ((pc, ([bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 26) = { + SEE = 26; + let Xd = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let uimm4 = Slice(__opcode, 10, 4); + let op3 = Slice(__opcode, 14, 2); + let uimm6 = Slice(__opcode, 16, 6); + if [__opcode[14]] != 0b0 | [__opcode[15]] != 0b0 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_addg_aarch64_instrs_integer_tags_mcaddtag(Xd, Xn, uimm4, op3, uimm6) + } +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow : forall 'd 'datasize 'elements 'esize 'm 'n 'part ('round : Bool) ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('round), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow (d, datasize, elements, esize, m, n, part, round, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits(2 * 'datasize) = V_read(n, 2 * datasize); + let operand2 : bits(2 * 'datasize) = V_read(m, 2 * datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + sum : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = UInt(Elem_read(operand1, e, 2 * esize)); + element2 = UInt(Elem_read(operand2, e, 2 * esize)); + if sub_op then { + sum = element1 - element2 + } else { + sum = element1 + element2 + }; + sum = RShr(sum, esize, round); + result = Elem_set(result, e, esize, sum[esize - 1 .. 0]) + }; + Vpart_set(d, part, datasize) = result +} + +val decode_addhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_addhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let round : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(d, datasize, elements, esize, m, n, part, round, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 27) = { + SEE = 27; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_addhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_raddhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_raddhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let round : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(d, datasize, elements, esize, m, n, part, round, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 28) = { + SEE = 28; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_raddhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_rsubhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_rsubhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let round : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(d, datasize, elements, esize, m, n, part, round, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 29) = { + SEE = 29; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_rsubhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_subhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_subhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let round : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(d, datasize, elements, esize, m, n, part, round, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 30) = { + SEE = 30; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_subhn_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_narrow(Rd, Rn, o1, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_pair : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_pair (d, datasize, elements, esize, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + let concat : bits(2 * 'datasize) = operand2 @ operand1; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(concat, 2 * e, esize); + element2 = Elem_read(concat, 2 * e + 1, esize); + result = Elem_set(result, e, esize, element1 + element2) + }; + V_set(d, datasize) = result +} + +val decode_addp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_pair : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_addp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_pair (Rd, Rn, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_pair(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 31) = { + SEE = 31; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_addp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_wrapping_pair(Rd, Rn, Rm, size, Q) +} + +val execute_aarch64_instrs_vector_reduce_add_sisd : forall 'd 'datasize 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('n), ReduceOp) -> unit + +function execute_aarch64_instrs_vector_reduce_add_sisd (d, datasize, esize, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + assert(constraint('datasize >= 'esize)); + V_set(d, esize) = Reduce(op, operand, esize) +} + +val decode_addp_advsimd_pair_aarch64_instrs_vector_reduce_add_sisd : (bits(5), bits(5), bits(2)) -> unit + +function decode_addp_advsimd_pair_aarch64_instrs_vector_reduce_add_sisd (Rd, Rn, size) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = ReduceOp_ADD; + execute_aarch64_instrs_vector_reduce_add_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 32) = { + SEE = 32; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + decode_addp_advsimd_pair_aarch64_instrs_vector_reduce_add_sisd(Rd, Rn, size) +} + +val execute_aarch64_instrs_vector_reduce_add_simd : forall 'd 'datasize 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('n), ReduceOp) -> unit + +function execute_aarch64_instrs_vector_reduce_add_simd (d, datasize, esize, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + V_set(d, esize) = Reduce(op, operand, esize) +} + +val decode_addv_advsimd_aarch64_instrs_vector_reduce_add_simd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_addv_advsimd_aarch64_instrs_vector_reduce_add_simd (Rd, Rn, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b100 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = ReduceOp_ADD; + execute_aarch64_instrs_vector_reduce_add_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 33) = { + SEE = 33; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_addv_advsimd_aarch64_instrs_vector_reduce_add_simd(Rd, Rn, size, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_address_pc_rel : forall 'd ('page : Bool), (0 <= 'd & 'd <= 31). + (int('d), bits(64), bool('page)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_address_pc_rel (d, imm, page) = { + base : bits(64) = PC_read(); + if page then { + base[11 .. 0] = Zeros(12) + }; + X_set(d, 64) = base + imm +} + +val decode_adr_aarch64_instrs_integer_arithmetic_address_pc_rel : (bits(5), bits(19), bits(2), bits(1)) -> unit + +function decode_adr_aarch64_instrs_integer_arithmetic_address_pc_rel (Rd, immhi, immlo, op) = { + let 'd = UInt(Rd); + let page : bool = op == 0b1; + imm : bits(64) = undefined; + if page then { + imm = SignExtend((immhi @ immlo) @ Zeros(12), 64) + } else { + imm = SignExtend(immhi @ immlo, 64) + }; + execute_aarch64_instrs_integer_arithmetic_address_pc_rel(d, imm, page) +} + +function clause __DecodeA64_DataProcImm ((pc, ([bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 34) = { + SEE = 34; + let Rd = Slice(__opcode, 0, 5); + let immhi = Slice(__opcode, 5, 19); + let immlo = Slice(__opcode, 29, 2); + let op = Slice(__opcode, 31, 1); + decode_adr_aarch64_instrs_integer_arithmetic_address_pc_rel(Rd, immhi, immlo, op) +} + +val decode_adrp_aarch64_instrs_integer_arithmetic_address_pc_rel : (bits(5), bits(19), bits(2), bits(1)) -> unit + +function decode_adrp_aarch64_instrs_integer_arithmetic_address_pc_rel (Rd, immhi, immlo, op) = { + let 'd = UInt(Rd); + let page : bool = op == 0b1; + imm : bits(64) = undefined; + if page then { + imm = SignExtend((immhi @ immlo) @ Zeros(12), 64) + } else { + imm = SignExtend(immhi @ immlo, 64) + }; + execute_aarch64_instrs_integer_arithmetic_address_pc_rel(d, imm, page) +} + +function clause __DecodeA64_DataProcImm ((pc, ([bitone, _, _, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 35) = { + SEE = 35; + let Rd = Slice(__opcode, 0, 5); + let immhi = Slice(__opcode, 5, 19); + let immlo = Slice(__opcode, 29, 2); + let op = Slice(__opcode, 31, 1); + decode_adrp_aarch64_instrs_integer_arithmetic_address_pc_rel(Rd, immhi, immlo, op) +} + +val execute_aarch64_instrs_vector_crypto_aes_round : forall 'd ('decrypt : Bool) 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), bool('decrypt), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_aes_round (d, decrypt, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let operand1 : bits(128) = V_read(d, 128); + let operand2 : bits(128) = V_read(n, 128); + result : bits(128) = EOR(operand1, operand2); + if decrypt then { + result = AESInvSubBytes(AESInvShiftRows(result)) + } else { + result = AESSubBytes(AESShiftRows(result)) + }; + V_set(d, 128) = result +} + +val decode_aesd_advsimd_aarch64_instrs_vector_crypto_aes_round : (bits(5), bits(5), bits(1)) -> unit + +function decode_aesd_advsimd_aarch64_instrs_vector_crypto_aes_round (Rd, Rn, D) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HaveAESExt()) then { + throw(Error_Undefined()) + }; + let decrypt : bool = D == 0b1; + execute_aarch64_instrs_vector_crypto_aes_round(d, decrypt, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 36) = { + SEE = 36; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let D = Slice(__opcode, 12, 1); + decode_aesd_advsimd_aarch64_instrs_vector_crypto_aes_round(Rd, Rn, D) +} + +val decode_aese_advsimd_aarch64_instrs_vector_crypto_aes_round : (bits(5), bits(5), bits(1)) -> unit + +function decode_aese_advsimd_aarch64_instrs_vector_crypto_aes_round (Rd, Rn, D) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HaveAESExt()) then { + throw(Error_Undefined()) + }; + let decrypt : bool = D == 0b1; + execute_aarch64_instrs_vector_crypto_aes_round(d, decrypt, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 37) = { + SEE = 37; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let D = Slice(__opcode, 12, 1); + decode_aese_advsimd_aarch64_instrs_vector_crypto_aes_round(Rd, Rn, D) +} + +val execute_aarch64_instrs_vector_crypto_aes_mix : forall 'd ('decrypt : Bool) 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), bool('decrypt), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_aes_mix (d, decrypt, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let operand : bits(128) = V_read(n, 128); + result : bits(128) = undefined; + if decrypt then { + result = AESInvMixColumns(operand) + } else { + result = AESMixColumns(operand) + }; + V_set(d, 128) = result +} + +val decode_aesimc_advsimd_aarch64_instrs_vector_crypto_aes_mix : (bits(5), bits(5), bits(1)) -> unit + +function decode_aesimc_advsimd_aarch64_instrs_vector_crypto_aes_mix (Rd, Rn, D) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HaveAESExt()) then { + throw(Error_Undefined()) + }; + let decrypt : bool = D == 0b1; + execute_aarch64_instrs_vector_crypto_aes_mix(d, decrypt, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 38) = { + SEE = 38; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let D = Slice(__opcode, 12, 1); + decode_aesimc_advsimd_aarch64_instrs_vector_crypto_aes_mix(Rd, Rn, D) +} + +val decode_aesmc_advsimd_aarch64_instrs_vector_crypto_aes_mix : (bits(5), bits(5), bits(1)) -> unit + +function decode_aesmc_advsimd_aarch64_instrs_vector_crypto_aes_mix (Rd, Rn, D) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HaveAESExt()) then { + throw(Error_Undefined()) + }; + let decrypt : bool = D == 0b1; + execute_aarch64_instrs_vector_crypto_aes_mix(d, decrypt, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 39) = { + SEE = 39; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let D = Slice(__opcode, 12, 1); + decode_aesmc_advsimd_aarch64_instrs_vector_crypto_aes_mix(Rd, Rn, D) +} + +val execute_aarch64_instrs_integer_logical_immediate : forall 'd 'datasize 'n ('setflags : Bool), + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bits('datasize), int('n), LogicalOp, bool('setflags)) -> unit + +function execute_aarch64_instrs_integer_logical_immediate (d, datasize, imm, n, op, setflags) = { + result : bits('datasize) = undefined; + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = imm; + match op { + LogicalOp_AND => { + result = operand1 & operand2 + }, + LogicalOp_ORR => { + result = operand1 | operand2 + }, + LogicalOp_EOR => { + result = EOR(operand1, operand2) + } + }; + let result = result; + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = ([result[datasize - 1]] @ IsZeroBit(result)) @ 0b00 + }; + if d == 31 & not_bool(setflags) then { + SP_set() = ZeroExtend(result, 64) + } else { + X_set(d, datasize) = result + } +} + +val decode_and_log_imm_aarch64_instrs_integer_logical_immediate : (bits(5), bits(5), bits(6), bits(6), bits(1), bits(2), bits(1)) -> unit + +function decode_and_log_imm_aarch64_instrs_integer_logical_immediate (Rd, Rn, imms, immr, N, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + imm : bits('datasize) = undefined; + if sf == 0b0 & N != 0b0 then { + throw(Error_Undefined()) + }; + let (__tup_0 : bits('datasize), _) = + DecodeBitMasks(N, imms, immr, true, datasize) + in + { + imm = __tup_0 + }; + execute_aarch64_instrs_integer_logical_immediate(d, datasize, imm, n, op, setflags) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 40) = { + SEE = 40; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let immr = Slice(__opcode, 16, 6); + let N = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_and_log_imm_aarch64_instrs_integer_logical_immediate(Rd, Rn, imms, immr, N, opc, sf) +} + +val decode_ands_log_imm_aarch64_instrs_integer_logical_immediate : (bits(5), bits(5), bits(6), bits(6), bits(1), bits(2), bits(1)) -> unit + +function decode_ands_log_imm_aarch64_instrs_integer_logical_immediate (Rd, Rn, imms, immr, N, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + imm : bits('datasize) = undefined; + if sf == 0b0 & N != 0b0 then { + throw(Error_Undefined()) + }; + let (__tup_0 : bits('datasize), _) = + DecodeBitMasks(N, imms, immr, true, datasize) + in + { + imm = __tup_0 + }; + execute_aarch64_instrs_integer_logical_immediate(d, datasize, imm, n, op, setflags) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 41) = { + SEE = 41; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let immr = Slice(__opcode, 16, 6); + let N = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_ands_log_imm_aarch64_instrs_integer_logical_immediate(Rd, Rn, imms, immr, N, opc, sf) +} + +val decode_eor_log_imm_aarch64_instrs_integer_logical_immediate : (bits(5), bits(5), bits(6), bits(6), bits(1), bits(2), bits(1)) -> unit + +function decode_eor_log_imm_aarch64_instrs_integer_logical_immediate (Rd, Rn, imms, immr, N, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + imm : bits('datasize) = undefined; + if sf == 0b0 & N != 0b0 then { + throw(Error_Undefined()) + }; + let (__tup_0 : bits('datasize), _) = + DecodeBitMasks(N, imms, immr, true, datasize) + in + { + imm = __tup_0 + }; + execute_aarch64_instrs_integer_logical_immediate(d, datasize, imm, n, op, setflags) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 42) = { + SEE = 42; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let immr = Slice(__opcode, 16, 6); + let N = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_eor_log_imm_aarch64_instrs_integer_logical_immediate(Rd, Rn, imms, immr, N, opc, sf) +} + +val decode_orr_log_imm_aarch64_instrs_integer_logical_immediate : (bits(5), bits(5), bits(6), bits(6), bits(1), bits(2), bits(1)) -> unit + +function decode_orr_log_imm_aarch64_instrs_integer_logical_immediate (Rd, Rn, imms, immr, N, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + imm : bits('datasize) = undefined; + if sf == 0b0 & N != 0b0 then { + throw(Error_Undefined()) + }; + let (__tup_0 : bits('datasize), _) = + DecodeBitMasks(N, imms, immr, true, datasize) + in + { + imm = __tup_0 + }; + execute_aarch64_instrs_integer_logical_immediate(d, datasize, imm, n, op, setflags) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 43) = { + SEE = 43; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let immr = Slice(__opcode, 16, 6); + let N = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_orr_log_imm_aarch64_instrs_integer_logical_immediate(Rd, Rn, imms, immr, N, opc, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr : forall 'd 'datasize ('invert : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bool('invert), int('m), int('n), LogicalOp) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr (d, datasize, invert, m, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + if invert then { + operand2 = not_vec(operand2) + }; + match op { + LogicalOp_AND => { + result = operand1 & operand2 + }, + LogicalOp_ORR => { + result = operand1 | operand2 + }, + _ => () + }; + V_set(d, datasize) = result +} + +val decode_and_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_and_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr (Rd, Rn, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let invert : bool = [size[0]] == 0b1; + let op : LogicalOp = if [size[1]] == 0b1 then LogicalOp_ORR else + LogicalOp_AND; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(d, datasize, invert, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 44) = { + SEE = 44; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_and_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(Rd, Rn, Rm, size, Q) +} + +val decode_bic_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_bic_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr (Rd, Rn, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let invert : bool = [size[0]] == 0b1; + let op : LogicalOp = if [size[1]] == 0b1 then LogicalOp_ORR else + LogicalOp_AND; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(d, datasize, invert, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 45) = { + SEE = 45; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_bic_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(Rd, Rn, Rm, size, Q) +} + +val decode_orn_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_orn_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr (Rd, Rn, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let invert : bool = [size[0]] == 0b1; + let op : LogicalOp = if [size[1]] == 0b1 then LogicalOp_ORR else + LogicalOp_AND; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(d, datasize, invert, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 46) = { + SEE = 46; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_orn_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(Rd, Rn, Rm, size, Q) +} + +val decode_orr_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_orr_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr (Rd, Rn, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let invert : bool = [size[0]] == 0b1; + let op : LogicalOp = if [size[1]] == 0b1 then LogicalOp_ORR else + LogicalOp_AND; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(d, datasize, invert, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 47) = { + SEE = 47; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_orr_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_logical_and_orr(Rd, Rn, Rm, size, Q) +} + +val execute_aarch64_instrs_integer_logical_shiftedreg : forall 'd 'datasize ('invert : Bool) 'm 'n ('setflags : Bool) 'shift_amount, + (0 <= 'shift_amount & 'shift_amount <= 63 & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bool('invert), int('m), int('n), LogicalOp, bool('setflags), int('shift_amount), ShiftType) -> unit + +function execute_aarch64_instrs_integer_logical_shiftedreg (d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) = { + let operand1 : bits('datasize) = X_read(n, datasize); + operand2 : bits('datasize) = ShiftReg(m, shift_type, shift_amount, datasize); + result : bits('datasize) = undefined; + if invert then { + operand2 = not_vec(operand2) + }; + match op { + LogicalOp_AND => { + result = operand1 & operand2 + }, + LogicalOp_ORR => { + result = operand1 | operand2 + }, + LogicalOp_EOR => { + result = EOR(operand1, operand2) + } + }; + let result = result; + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = ([result[datasize - 1]] @ IsZeroBit(result)) @ 0b00 + }; + X_set(d, datasize) = result +} + +val decode_and_log_shift_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_and_log_shift_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 48) = { + SEE = 48; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_and_log_shift_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val decode_ands_log_shift_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_ands_log_shift_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 49) = { + SEE = 49; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_ands_log_shift_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val decode_bic_log_shift_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_bic_log_shift_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 50) = { + SEE = 50; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_bic_log_shift_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val decode_bics_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_bics_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 51) = { + SEE = 51; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_bics_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val decode_eon_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_eon_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 52) = { + SEE = 52; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_eon_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val decode_eor_log_shift_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_eor_log_shift_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 53) = { + SEE = 53; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_eor_log_shift_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val decode_orn_log_shift_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_orn_log_shift_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 54) = { + SEE = 54; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_orn_log_shift_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val decode_orr_log_shift_aarch64_instrs_integer_logical_shiftedreg : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(2), bits(2), bits(1)) -> unit + +function decode_orr_log_shift_aarch64_instrs_integer_logical_shiftedreg (Rd, Rn, imm6, Rm, N, shift, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + setflags : bool = undefined; + op : LogicalOp = undefined; + match opc { + 0b00 => { + op = LogicalOp_AND; + setflags = false + }, + 0b01 => { + op = LogicalOp_ORR; + setflags = false + }, + 0b10 => { + op = LogicalOp_EOR; + setflags = false + }, + 0b11 => { + op = LogicalOp_AND; + setflags = true + } + }; + let op = op; + let setflags = setflags; + if sf == 0b0 & [imm6[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let shift_type : ShiftType = DecodeShift(shift); + let 'shift_amount = UInt(imm6); + let invert : bool = N == 0b1; + execute_aarch64_instrs_integer_logical_shiftedreg(d, datasize, invert, m, n, op, setflags, shift_amount, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 55) = { + SEE = 55; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 21, 1); + let shift = Slice(__opcode, 22, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_orr_log_shift_aarch64_instrs_integer_logical_shiftedreg(Rd, Rn, imm6, Rm, N, shift, opc, sf) +} + +val execute_aarch64_instrs_integer_shift_variable : forall 'd 'datasize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n), ShiftType) -> unit + +function execute_aarch64_instrs_integer_shift_variable (d, datasize, m, n, shift_type) = { + let operand2 : bits('datasize) = X_read(m, datasize); + let result : bits('datasize) = ShiftReg(n, shift_type, MOD(UInt(operand2), datasize), datasize); + X_set(d, datasize) = result +} + +val decode_asrv_aarch64_instrs_integer_shift_variable : (bits(5), bits(5), bits(2), bits(5), bits(1)) -> unit + +function decode_asrv_aarch64_instrs_integer_shift_variable (Rd, Rn, op2, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let shift_type : ShiftType = DecodeShift(op2); + execute_aarch64_instrs_integer_shift_variable(d, datasize, m, n, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 56) = { + SEE = 56; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 10, 2); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_asrv_aarch64_instrs_integer_shift_variable(Rd, Rn, op2, Rm, sf) +} + +val decode_lslv_aarch64_instrs_integer_shift_variable : (bits(5), bits(5), bits(2), bits(5), bits(1)) -> unit + +function decode_lslv_aarch64_instrs_integer_shift_variable (Rd, Rn, op2, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let shift_type : ShiftType = DecodeShift(op2); + execute_aarch64_instrs_integer_shift_variable(d, datasize, m, n, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 57) = { + SEE = 57; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 10, 2); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_lslv_aarch64_instrs_integer_shift_variable(Rd, Rn, op2, Rm, sf) +} + +val decode_lsrv_aarch64_instrs_integer_shift_variable : (bits(5), bits(5), bits(2), bits(5), bits(1)) -> unit + +function decode_lsrv_aarch64_instrs_integer_shift_variable (Rd, Rn, op2, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let shift_type : ShiftType = DecodeShift(op2); + execute_aarch64_instrs_integer_shift_variable(d, datasize, m, n, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 58) = { + SEE = 58; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 10, 2); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_lsrv_aarch64_instrs_integer_shift_variable(Rd, Rn, op2, Rm, sf) +} + +val decode_rorv_aarch64_instrs_integer_shift_variable : (bits(5), bits(5), bits(2), bits(5), bits(1)) -> unit + +function decode_rorv_aarch64_instrs_integer_shift_variable (Rd, Rn, op2, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let shift_type : ShiftType = DecodeShift(op2); + execute_aarch64_instrs_integer_shift_variable(d, datasize, m, n, shift_type) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 59) = { + SEE = 59; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 10, 2); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_rorv_aarch64_instrs_integer_shift_variable(Rd, Rn, op2, Rm, sf) +} + +val execute_aarch64_instrs_integer_pac_autda_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_autda_dp_1src (d, n, source_is_sp) = { + let auth_then_branch : bool = false; + if HavePACExt() then { + if source_is_sp then { + X_set(d, 64) = AuthDA(X_read(d, 64), SP_read(), auth_then_branch) + } else { + X_set(d, 64) = AuthDA(X_read(d, 64), X_read(n, 64), auth_then_branch) + } + }; + () +} + +val decode_autda_aarch64_instrs_integer_pac_autda_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_autda_aarch64_instrs_integer_pac_autda_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_autda_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 60) = { + SEE = 60; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_autda_aarch64_instrs_integer_pac_autda_dp_1src(Rd, Rn, Z) +} + +val execute_aarch64_instrs_integer_pac_autdb_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_autdb_dp_1src (d, n, source_is_sp) = { + let auth_then_branch : bool = false; + if HavePACExt() then { + if source_is_sp then { + X_set(d, 64) = AuthDB(X_read(d, 64), SP_read(), auth_then_branch) + } else { + X_set(d, 64) = AuthDB(X_read(d, 64), X_read(n, 64), auth_then_branch) + } + }; + () +} + +val decode_autdb_aarch64_instrs_integer_pac_autdb_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_autdb_aarch64_instrs_integer_pac_autdb_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_autdb_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 61) = { + SEE = 61; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_autdb_aarch64_instrs_integer_pac_autdb_dp_1src(Rd, Rn, Z) +} + +val execute_aarch64_instrs_integer_pac_autia_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_autia_dp_1src (d, n, source_is_sp) = { + let auth_then_branch : bool = false; + if HavePACExt() then { + if source_is_sp then { + X_set(d, 64) = AuthIA(X_read(d, 64), SP_read(), auth_then_branch) + } else { + X_set(d, 64) = AuthIA(X_read(d, 64), X_read(n, 64), auth_then_branch) + } + }; + () +} + +val decode_autia_aarch64_instrs_integer_pac_autia_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_autia_aarch64_instrs_integer_pac_autia_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_autia_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 62) = { + SEE = 62; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_autia_aarch64_instrs_integer_pac_autia_dp_1src(Rd, Rn, Z) +} + +val decode_autia_aarch64_instrs_integer_pac_autia_hint : (bits(3), bits(4)) -> unit + +function decode_autia_aarch64_instrs_integer_pac_autia_hint (op2, CRm) = { + d : {17, 30} = 17; + n : int = undefined; + source_is_sp : bool = false; + match CRm @ op2 { + 0b0011100 => { + d = 30; + n = 31 + }, + 0b0011101 => { + d = 30; + source_is_sp = true + }, + 0b0001100 => { + d = 17; + n = 16 + }, + 0b0001000 => { + throw(Error_See("PACIA")) + }, + 0b0001010 => { + throw(Error_See("PACIB")) + }, + 0b0001110 => { + throw(Error_See("AUTIB")) + }, + [bitzero, bitzero, bitone, bitone, bitzero, bitzero, _] => { + throw(Error_See("PACIA")) + }, + [bitzero, bitzero, bitone, bitone, bitzero, bitone, _] => { + throw(Error_See("PACIB")) + }, + [bitzero, bitzero, bitone, bitone, bitone, bitone, _] => { + throw(Error_See("AUTIB")) + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + _ => { + throw(Error_See("HINT")) + } + }; + let 'n = n; + let 'd = d; + assert(constraint((0 <= 'n & 'n <= 31))); + execute_aarch64_instrs_integer_pac_autia_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, bitone, bitone, bitzero, _, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 63) = { + SEE = 63; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_autia_aarch64_instrs_integer_pac_autia_hint(op2, CRm) +} + +val execute_aarch64_instrs_integer_pac_autib_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_autib_dp_1src (d, n, source_is_sp) = { + let auth_then_branch : bool = false; + if HavePACExt() then { + if source_is_sp then { + X_set(d, 64) = AuthIB(X_read(d, 64), SP_read(), auth_then_branch) + } else { + X_set(d, 64) = AuthIB(X_read(d, 64), X_read(n, 64), auth_then_branch) + } + }; + () +} + +val decode_autib_aarch64_instrs_integer_pac_autib_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_autib_aarch64_instrs_integer_pac_autib_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_autib_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 64) = { + SEE = 64; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_autib_aarch64_instrs_integer_pac_autib_dp_1src(Rd, Rn, Z) +} + +val decode_autib_aarch64_instrs_integer_pac_autib_hint : (bits(3), bits(4)) -> unit + +function decode_autib_aarch64_instrs_integer_pac_autib_hint (op2, CRm) = { + d : {17, 30} = 17; + n : int = undefined; + source_is_sp : bool = false; + match CRm @ op2 { + 0b0011110 => { + d = 30; + n = 31 + }, + 0b0011111 => { + d = 30; + source_is_sp = true + }, + 0b0001110 => { + d = 17; + n = 16 + }, + 0b0001000 => { + throw(Error_See("PACIA")) + }, + 0b0001010 => { + throw(Error_See("PACIB")) + }, + 0b0001100 => { + throw(Error_See("AUTIA")) + }, + [bitzero, bitzero, bitone, bitone, bitzero, bitzero, _] => { + throw(Error_See("PACIA")) + }, + [bitzero, bitzero, bitone, bitone, bitzero, bitone, _] => { + throw(Error_See("PACIB")) + }, + [bitzero, bitzero, bitone, bitone, bitone, bitzero, _] => { + throw(Error_See("AUTIA")) + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + _ => { + throw(Error_See("HINT")) + } + }; + let 'n = n; + let 'd = d; + assert(constraint((0 <= 'n & 'n <= 31))); + execute_aarch64_instrs_integer_pac_autib_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, bitone, bitone, bitone, _, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 65) = { + SEE = 65; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_autib_aarch64_instrs_integer_pac_autib_hint(op2, CRm) +} + +val execute_aarch64_instrs_integer_flags_axflag : unit -> unit + +function execute_aarch64_instrs_integer_flags_axflag () = { + let n : bits(1) = 0b0; + let z : bits(1) = PSTATE.Z | PSTATE.V; + let c : bits(1) = PSTATE.C & not_vec(PSTATE.V); + let v : bits(1) = 0b0; + PSTATE.N = n; + PSTATE.Z = z; + PSTATE.C = c; + PSTATE.V = v +} + +val decode_axflag_aarch64_instrs_integer_flags_axflag : bits(4) -> unit + +function decode_axflag_aarch64_instrs_integer_flags_axflag CRm = { + if not_bool(HaveFlagFormatExt()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_flags_axflag() +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000000100000001011111 as __opcode)) if SEE < 66) = { + SEE = 66; + let CRm = Slice(__opcode, 8, 4); + if (([__opcode[8]] != 0b0 | [__opcode[9]] != 0b0) | [__opcode[10]] != 0b0) | [__opcode[11]] != 0b0 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_axflag_aarch64_instrs_integer_flags_axflag(CRm) + } +} + +val execute_aarch64_instrs_branch_unconditional_immediate : (BranchType, bits(64)) -> unit + +function execute_aarch64_instrs_branch_unconditional_immediate (branch_type, offset) = { + if branch_type == BranchType_DIRCALL then { + if HaveGCS() & GCSPCREnabled(PSTATE.EL) then { + AddGCSRecord(PC_read() + 4) + }; + X_set(30, 64) = PC_read() + 4 + }; + let branch_conditional : bool = false; + BranchTo(PC_read() + offset, branch_type, branch_conditional) +} + +val decode_b_uncond_aarch64_instrs_branch_unconditional_immediate : (bits(26), bits(1)) -> unit + +function decode_b_uncond_aarch64_instrs_branch_unconditional_immediate (imm26, op) = { + let branch_type : BranchType = if op == 0b1 then BranchType_DIRCALL else + BranchType_DIR; + let offset : bits(64) = SignExtend(imm26 @ 0b00, 64); + execute_aarch64_instrs_branch_unconditional_immediate(branch_type, offset) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 67) = { + SEE = 67; + let imm26 = Slice(__opcode, 0, 26); + let op = Slice(__opcode, 31, 1); + decode_b_uncond_aarch64_instrs_branch_unconditional_immediate(imm26, op) +} + +val decode_bl_aarch64_instrs_branch_unconditional_immediate : (bits(26), bits(1)) -> unit + +function decode_bl_aarch64_instrs_branch_unconditional_immediate (imm26, op) = { + let branch_type : BranchType = if op == 0b1 then BranchType_DIRCALL else + BranchType_DIR; + let offset : bits(64) = SignExtend(imm26 @ 0b00, 64); + execute_aarch64_instrs_branch_unconditional_immediate(branch_type, offset) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 68) = { + SEE = 68; + let imm26 = Slice(__opcode, 0, 26); + let op = Slice(__opcode, 31, 1); + decode_bl_aarch64_instrs_branch_unconditional_immediate(imm26, op) +} + +val execute_aarch64_instrs_branch_conditional_cond : (bits(4), bits(64)) -> unit + +function execute_aarch64_instrs_branch_conditional_cond (condition, offset) = { + let branch_conditional : bool = true; + if ConditionHolds(condition) then { + BranchTo(PC_read() + offset, BranchType_DIR, branch_conditional) + } else { + BranchNotTaken(BranchType_DIR, branch_conditional) + } +} + +val decode_b_cond_aarch64_instrs_branch_conditional_cond : (bits(4), bits(19)) -> unit + +function decode_b_cond_aarch64_instrs_branch_conditional_cond (cond, imm19) = { + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + let condition : bits(4) = cond; + execute_aarch64_instrs_branch_conditional_cond(condition, offset) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, _, _, _, _] as __opcode)) if SEE < 69) = { + SEE = 69; + let cond = Slice(__opcode, 0, 4); + let imm19 = Slice(__opcode, 5, 19); + decode_b_cond_aarch64_instrs_branch_conditional_cond(cond, imm19) +} + +val execute_aarch64_instrs_branch_conditional_hinted : (bits(4), bits(64)) -> unit + +function execute_aarch64_instrs_branch_conditional_hinted (condition, offset) = { + let branch_conditional : bool = true; + if ConditionHolds(condition) then { + BranchTo(PC_read() + offset, BranchType_DIR, branch_conditional) + } else { + BranchNotTaken(BranchType_DIR, branch_conditional) + } +} + +val decode_bc_cond_aarch64_instrs_branch_conditional_hinted : (bits(4), bits(19)) -> unit + +function decode_bc_cond_aarch64_instrs_branch_conditional_hinted (cond, imm19) = { + if not_bool(HaveFeatHBC()) then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + let condition : bits(4) = cond; + execute_aarch64_instrs_branch_conditional_hinted(condition, offset) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitone, _, _, _, _] as __opcode)) if SEE < 70) = { + SEE = 70; + let cond = Slice(__opcode, 0, 4); + let imm19 = Slice(__opcode, 5, 19); + decode_bc_cond_aarch64_instrs_branch_conditional_hinted(cond, imm19) +} + +val execute_aarch64_instrs_vector_crypto_sha3_bcax : forall 'a 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31 & 0 <= 'a & 'a <= 31). + (int('a), int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3_bcax (a, d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Va : bits(128) = V_read(a, 128); + V_set(d, 128) = EOR(Vn, Vm & not_vec(Va)) +} + +val decode_bcax_advsimd_aarch64_instrs_vector_crypto_sha3_bcax : (bits(5), bits(5), bits(5), bits(5)) -> unit + +function decode_bcax_advsimd_aarch64_instrs_vector_crypto_sha3_bcax (Rd, Rn, Ra, Rm) = { + if not_bool(HaveSHA3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + execute_aarch64_instrs_vector_crypto_sha3_bcax(a, d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 71) = { + SEE = 71; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let Rm = Slice(__opcode, 16, 5); + decode_bcax_advsimd_aarch64_instrs_vector_crypto_sha3_bcax(Rd, Rn, Ra, Rm) +} + +val execute_aarch64_instrs_vector_cvt_bf16_scalar : forall 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n)) -> unit + +function execute_aarch64_instrs_vector_cvt_bf16_scalar (d, n) = { + CheckFPEnabled64(); + let operand : bits(32) = V_read(n, 32); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + result = Elem_set(result, 0, 16, FPConvertBF__1(operand, fpcr)); + V_set(d, 128) = result +} + +val decode_bfcvt_float_aarch64_instrs_vector_cvt_bf16_scalar : (bits(5), bits(5)) -> unit + +function decode_bfcvt_float_aarch64_instrs_vector_cvt_bf16_scalar (Rd, Rn) = { + if not_bool(HaveBF16Ext()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 'd = UInt(Rd); + execute_aarch64_instrs_vector_cvt_bf16_scalar(d, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 72) = { + SEE = 72; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_bfcvt_float_aarch64_instrs_vector_cvt_bf16_scalar(Rd, Rn) +} + +val execute_aarch64_instrs_vector_cvt_bf16_vector : forall 'd 'elements 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'elements == 4 & 0 <= 'd & 'd <= 31). + (int('d), int('elements), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_cvt_bf16_vector (d, elements, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits(128) = V_read(n, 128); + result : bits(64) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + result = Elem_set(result, e, 16, FPConvertBF__1(Elem_read(operand, e, 32), FPCR_read())) + }; + Vpart_set(d, part, 64) = result +} + +val decode_bfcvtn_advsimd_aarch64_instrs_vector_cvt_bf16_vector : (bits(5), bits(5), bits(1)) -> unit + +function decode_bfcvtn_advsimd_aarch64_instrs_vector_cvt_bf16_vector (Rd, Rn, Q) = { + if not_bool(HaveBF16Ext()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 'd = UInt(Rd); + let 'part = UInt(Q); + let 'elements = DIV(64, 16); + execute_aarch64_instrs_vector_cvt_bf16_vector(d, elements, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 73) = { + SEE = 73; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Q = Slice(__opcode, 30, 1); + decode_bfcvtn_advsimd_aarch64_instrs_vector_cvt_bf16_vector(Rd, Rn, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_bfdot : forall 'd 'datasize 'elements 'i 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'i in {0, 1, 2, 3} & 'elements in {2, 4} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('i), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_bfdot (d, datasize, elements, i, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits(128) = V_read(m, 128); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + let elt1_a : bits(16) = Elem_read(operand1, 2 * e + 0, 16); + let elt1_b : bits(16) = Elem_read(operand1, 2 * e + 1, 16); + let elt2_a : bits(16) = Elem_read(operand2, 2 * i + 0, 16); + let elt2_b : bits(16) = Elem_read(operand2, 2 * i + 1, 16); + sum : bits(32) = Elem_read(operand3, e, 32); + let sum : bits(32) = BFDotAdd(sum, elt1_a, elt1_b, elt2_a, elt2_b, FPCR_read()); + result = Elem_set(result, e, 32, sum) + }; + V_set(d, datasize) = result +} + +val decode_bfdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_bfdot : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_bfdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_bfdot (Rd, Rn, H, Rm, M, L, Q) = { + if not_bool(HaveBF16Ext()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 'm = UInt(M @ Rm); + let 'd = UInt(Rd); + let 'i = UInt(H @ L); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 32); + execute_aarch64_instrs_vector_arithmetic_binary_element_bfdot(d, datasize, elements, i, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, bitone, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 74) = { + SEE = 74; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let Q = Slice(__opcode, 30, 1); + decode_bfdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_bfdot(Rd, Rn, H, Rm, M, L, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_bfdot : forall 'd 'datasize 'elements 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'elements in {2, 4} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_bfdot (d, datasize, elements, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + let elt1_a : bits(16) = Elem_read(operand1, 2 * e + 0, 16); + let elt1_b : bits(16) = Elem_read(operand1, 2 * e + 1, 16); + let elt2_a : bits(16) = Elem_read(operand2, 2 * e + 0, 16); + let elt2_b : bits(16) = Elem_read(operand2, 2 * e + 1, 16); + sum : bits(32) = Elem_read(operand3, e, 32); + let sum : bits(32) = BFDotAdd(sum, elt1_a, elt1_b, elt2_a, elt2_b, FPCR_read()); + result = Elem_set(result, e, 32, sum) + }; + V_set(d, datasize) = result +} + +val decode_bfdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_bfdot : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_bfdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_bfdot (Rd, Rn, Rm, Q) = { + if not_bool(HaveBF16Ext()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 32); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_bfdot(d, datasize, elements, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 75) = { + SEE = 75; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_bfdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_bfdot(Rd, Rn, Rm, Q) +} + +val execute_aarch64_instrs_integer_bitfield : forall 'd 'datasize ('extend : Bool) ('inzero : Bool) 'n 'r 's, + (0 <= 's & 's <= 63 & 0 <= 'r & 'r <= 63 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bool('extend), bool('inzero), int('n), int('r), int('s), bits('datasize), bits('datasize)) -> unit + +function execute_aarch64_instrs_integer_bitfield (d, datasize, extend, inzero, n, r, s, tmask, wmask) = { + let dst : bits('datasize) = if inzero then Zeros(datasize) else + X_read(d, datasize); + let src : bits('datasize) = X_read(n, datasize); + let bot : bits('datasize) = dst & not_vec(wmask) | ROR(src, r) & wmask; + let top : bits('datasize) = if extend then { + assert(constraint((0 <= 's & 's < 'datasize))); + Replicate([src[s]], datasize) + } else dst; + X_set(d, datasize) = top & not_vec(tmask) | bot & tmask +} + +val decode_bfm_aarch64_instrs_integer_bitfield : (bits(5), bits(5), bits(6), bits(6), bits(1), bits(2), bits(1)) -> unit + +function decode_bfm_aarch64_instrs_integer_bitfield (Rd, Rn, imms, immr, N, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + inzero : bool = undefined; + extend : bool = undefined; + wmask : bits('datasize) = undefined; + tmask : bits('datasize) = undefined; + match opc { + 0b00 => { + inzero = true; + extend = true + }, + 0b01 => { + inzero = false; + extend = false + }, + 0b10 => { + inzero = true; + extend = false + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let extend = extend; + let inzero = inzero; + if sf == 0b1 & N != 0b1 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & ((N != 0b0 | [immr[5]] != 0b0) | [imms[5]] != 0b0) then { + throw(Error_Undefined()) + }; + let 'r = UInt(immr); + let 's = UInt(imms); + (wmask, tmask) = DecodeBitMasks(N, imms, immr, false, datasize); + execute_aarch64_instrs_integer_bitfield(d, datasize, extend, inzero, n, r, s, tmask, wmask) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 76) = { + SEE = 76; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let immr = Slice(__opcode, 16, 6); + let N = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_bfm_aarch64_instrs_integer_bitfield(Rd, Rn, imms, immr, N, opc, sf) +} + +val decode_sbfm_aarch64_instrs_integer_bitfield : (bits(5), bits(5), bits(6), bits(6), bits(1), bits(2), bits(1)) -> unit + +function decode_sbfm_aarch64_instrs_integer_bitfield (Rd, Rn, imms, immr, N, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + inzero : bool = undefined; + extend : bool = undefined; + wmask : bits('datasize) = undefined; + tmask : bits('datasize) = undefined; + match opc { + 0b00 => { + inzero = true; + extend = true + }, + 0b01 => { + inzero = false; + extend = false + }, + 0b10 => { + inzero = true; + extend = false + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let extend = extend; + let inzero = inzero; + if sf == 0b1 & N != 0b1 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & ((N != 0b0 | [immr[5]] != 0b0) | [imms[5]] != 0b0) then { + throw(Error_Undefined()) + }; + let 'r = UInt(immr); + let 's = UInt(imms); + (wmask, tmask) = DecodeBitMasks(N, imms, immr, false, datasize); + execute_aarch64_instrs_integer_bitfield(d, datasize, extend, inzero, n, r, s, tmask, wmask) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 77) = { + SEE = 77; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let immr = Slice(__opcode, 16, 6); + let N = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_sbfm_aarch64_instrs_integer_bitfield(Rd, Rn, imms, immr, N, opc, sf) +} + +val decode_ubfm_aarch64_instrs_integer_bitfield : (bits(5), bits(5), bits(6), bits(6), bits(1), bits(2), bits(1)) -> unit + +function decode_ubfm_aarch64_instrs_integer_bitfield (Rd, Rn, imms, immr, N, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + inzero : bool = undefined; + extend : bool = undefined; + wmask : bits('datasize) = undefined; + tmask : bits('datasize) = undefined; + match opc { + 0b00 => { + inzero = true; + extend = true + }, + 0b01 => { + inzero = false; + extend = false + }, + 0b10 => { + inzero = true; + extend = false + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let extend = extend; + let inzero = inzero; + if sf == 0b1 & N != 0b1 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & ((N != 0b0 | [immr[5]] != 0b0) | [imms[5]] != 0b0) then { + throw(Error_Undefined()) + }; + let 'r = UInt(immr); + let 's = UInt(imms); + (wmask, tmask) = DecodeBitMasks(N, imms, immr, false, datasize); + execute_aarch64_instrs_integer_bitfield(d, datasize, extend, inzero, n, r, s, tmask, wmask) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 78) = { + SEE = 78; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let immr = Slice(__opcode, 16, 6); + let N = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_ubfm_aarch64_instrs_integer_bitfield(Rd, Rn, imms, immr, N, opc, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_bf16_long : forall 'd 'elements 'index 'm 'n 'sel, + ('sel in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'elements == 4 & 0 <= 'd & 'd <= 31). + (int('d), int('elements), int('index), int('m), int('n), int('sel)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_bf16_long (d, elements, index, m, n, sel) = { + CheckFPAdvSIMDEnabled64(); + result : bits(128) = undefined; + let operand1 : bits(128) = V_read(n, 128); + let operand2 : bits(128) = V_read(m, 128); + let operand3 : bits(128) = V_read(d, 128); + let element2 : bits(16) = Elem_read(operand2, index, 16); + foreach (e from 0 to (elements - 1) by 1 in inc) { + let element1 : bits(16) = Elem_read(operand1, 2 * e + sel, 16); + let addend : bits(32) = Elem_read(operand3, e, 32); + result = Elem_set(result, e, 32, BFMulAddH(addend, element1, element2, FPCR_read())) + }; + V_set(d, 128) = result +} + +val decode_bfmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_bf16_long : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_bfmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_bf16_long (Rd, Rn, H, Rm, M, L, Q) = { + if not_bool(HaveBF16Ext()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 'm = UInt(0b0 @ Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'elements = DIV(128, 32); + let 'sel = UInt(Q); + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_bf16_long(d, elements, index, m, n, sel) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, bitone, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 79) = { + SEE = 79; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let Q = Slice(__opcode, 30, 1); + decode_bfmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_bf16_long(Rd, Rn, H, Rm, M, L, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_acc_bf16_long : forall 'd 'elements 'm 'n 'sel, + ('sel in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'elements == 4 & 0 <= 'd & 'd <= 31). + (int('d), int('elements), int('m), int('n), int('sel)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_acc_bf16_long (d, elements, m, n, sel) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits(128) = V_read(n, 128); + let operand2 : bits(128) = V_read(m, 128); + let operand3 : bits(128) = V_read(d, 128); + result : bits(128) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + let element1 : bits(16) = Elem_read(operand1, 2 * e + sel, 16); + let element2 : bits(16) = Elem_read(operand2, 2 * e + sel, 16); + let addend : bits(32) = Elem_read(operand3, e, 32); + result = Elem_set(result, e, 32, BFMulAddH(addend, element1, element2, FPCR_read())) + }; + V_set(d, 128) = result +} + +val decode_bfmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_acc_bf16_long : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_bfmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_acc_bf16_long (Rd, Rn, Rm, Q) = { + if not_bool(HaveBF16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'elements = DIV(128, 32); + let 'sel = UInt(Q); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_acc_bf16_long(d, elements, m, n, sel) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 80) = { + SEE = 80; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_bfmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_acc_bf16_long(Rd, Rn, Rm, Q) +} + +val execute_aarch64_instrs_vector_bfmmla : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_bfmmla (d, m, n) = { + CheckFPAdvSIMDEnabled64(); + let op1 : bits(128) = V_read(n, 128); + let op2 : bits(128) = V_read(m, 128); + let acc : bits(128) = V_read(d, 128); + V_set(d, 128) = BFMatMulAdd(acc, op1, op2) +} + +val decode_bfmmla_advsimd_aarch64_instrs_vector_bfmmla : (bits(5), bits(5), bits(5)) -> unit + +function decode_bfmmla_advsimd_aarch64_instrs_vector_bfmmla (Rd, Rn, Rm) = { + if not_bool(HaveBF16Ext()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_vector_bfmmla(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 81) = { + SEE = 81; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_bfmmla_advsimd_aarch64_instrs_vector_bfmmla(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_logical : forall 'datasize 'rd, + (0 <= 'rd & 'rd <= 31 & 'datasize in {64, 128}). + (int('datasize), bits('datasize), ImmediateOp, int('rd)) -> unit + +function execute_aarch64_instrs_vector_logical (datasize, imm, operation, rd) = { + CheckFPAdvSIMDEnabled64(); + operand : bits('datasize) = undefined; + result : bits('datasize) = undefined; + match operation { + ImmediateOp_MOVI => { + result = imm + }, + ImmediateOp_MVNI => { + result = not_vec(imm) + }, + ImmediateOp_ORR => { + let operand : bits('datasize) = V_read(rd, datasize); + result = operand | imm + }, + ImmediateOp_BIC => { + let operand : bits('datasize) = V_read(rd, datasize); + result = operand & not_vec(imm) + } + }; + V_set(rd, datasize) = result +} + +val decode_bic_advsimd_imm_aarch64_instrs_vector_logical : (bits(5), bits(1), bits(1), bits(1), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_bic_advsimd_imm_aarch64_instrs_vector_logical (Rd, h, g, f, e, d, cmode, c, b, a, op, Q) = { + let 'rd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + operation : ImmediateOp = undefined; + match cmode @ op { + [bitzero, _, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitzero, _, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitzero, _, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitzero, _, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitzero, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitzero, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitzero, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitone, bitzero, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitone, bitzero, _, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitone, bitzero, _, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitone, bitone, bitzero, _] => { + operation = ImmediateOp_MOVI + }, + 0b11110 => { + operation = ImmediateOp_MOVI + }, + 0b11111 => { + if Q == 0b0 then { + throw(Error_Undefined()) + }; + operation = ImmediateOp_MOVI + } + }; + let operation = operation; + let imm64 : bits(64) = AdvSIMDExpandImm(op, cmode, ((((((a @ b) @ c) @ d) @ e) @ f) @ g) @ h); + let imm : bits('datasize) = Replicate(imm64, DIV(datasize, 64)); + execute_aarch64_instrs_vector_logical(datasize, imm, operation, rd) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 82) = { + SEE = 82; + let Rd = Slice(__opcode, 0, 5); + let h = Slice(__opcode, 5, 1); + let g = Slice(__opcode, 6, 1); + let f = Slice(__opcode, 7, 1); + let e = Slice(__opcode, 8, 1); + let d = Slice(__opcode, 9, 1); + let cmode = Slice(__opcode, 12, 4); + let c = Slice(__opcode, 16, 1); + let b = Slice(__opcode, 17, 1); + let a = Slice(__opcode, 18, 1); + let op = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_bic_advsimd_imm_aarch64_instrs_vector_logical(Rd, h, g, f, e, d, cmode, c, b, a, op, Q) +} + +val decode_movi_advsimd_aarch64_instrs_vector_logical : (bits(5), bits(1), bits(1), bits(1), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_movi_advsimd_aarch64_instrs_vector_logical (Rd, h, g, f, e, d, cmode, c, b, a, op, Q) = { + let 'rd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + operation : ImmediateOp = undefined; + match cmode @ op { + [bitzero, _, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitzero, _, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitzero, _, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitzero, _, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitzero, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitzero, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitzero, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitone, bitzero, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitone, bitzero, _, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitone, bitzero, _, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitone, bitone, bitzero, _] => { + operation = ImmediateOp_MOVI + }, + 0b11110 => { + operation = ImmediateOp_MOVI + }, + 0b11111 => { + if Q == 0b0 then { + throw(Error_Undefined()) + }; + operation = ImmediateOp_MOVI + } + }; + let operation = operation; + let imm64 : bits(64) = AdvSIMDExpandImm(op, cmode, ((((((a @ b) @ c) @ d) @ e) @ f) @ g) @ h); + let imm : bits('datasize) = Replicate(imm64, DIV(datasize, 64)); + execute_aarch64_instrs_vector_logical(datasize, imm, operation, rd) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, _, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 83) = { + SEE = 83; + let Rd = Slice(__opcode, 0, 5); + let h = Slice(__opcode, 5, 1); + let g = Slice(__opcode, 6, 1); + let f = Slice(__opcode, 7, 1); + let e = Slice(__opcode, 8, 1); + let d = Slice(__opcode, 9, 1); + let cmode = Slice(__opcode, 12, 4); + let c = Slice(__opcode, 16, 1); + let b = Slice(__opcode, 17, 1); + let a = Slice(__opcode, 18, 1); + let op = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_movi_advsimd_aarch64_instrs_vector_logical(Rd, h, g, f, e, d, cmode, c, b, a, op, Q) +} + +val decode_mvni_advsimd_aarch64_instrs_vector_logical : (bits(5), bits(1), bits(1), bits(1), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_mvni_advsimd_aarch64_instrs_vector_logical (Rd, h, g, f, e, d, cmode, c, b, a, op, Q) = { + let 'rd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + operation : ImmediateOp = undefined; + match cmode @ op { + [bitzero, _, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitzero, _, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitzero, _, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitzero, _, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitzero, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitzero, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitzero, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitone, bitzero, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitone, bitzero, _, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitone, bitzero, _, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitone, bitone, bitzero, _] => { + operation = ImmediateOp_MOVI + }, + 0b11110 => { + operation = ImmediateOp_MOVI + }, + 0b11111 => { + if Q == 0b0 then { + throw(Error_Undefined()) + }; + operation = ImmediateOp_MOVI + } + }; + let operation = operation; + let imm64 : bits(64) = AdvSIMDExpandImm(op, cmode, ((((((a @ b) @ c) @ d) @ e) @ f) @ g) @ h); + let imm : bits('datasize) = Replicate(imm64, DIV(datasize, 64)); + execute_aarch64_instrs_vector_logical(datasize, imm, operation, rd) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 84) = { + SEE = 84; + let Rd = Slice(__opcode, 0, 5); + let h = Slice(__opcode, 5, 1); + let g = Slice(__opcode, 6, 1); + let f = Slice(__opcode, 7, 1); + let e = Slice(__opcode, 8, 1); + let d = Slice(__opcode, 9, 1); + let cmode = Slice(__opcode, 12, 4); + let c = Slice(__opcode, 16, 1); + let b = Slice(__opcode, 17, 1); + let a = Slice(__opcode, 18, 1); + let op = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_mvni_advsimd_aarch64_instrs_vector_logical(Rd, h, g, f, e, d, cmode, c, b, a, op, Q) +} + +val decode_orr_advsimd_imm_aarch64_instrs_vector_logical : (bits(5), bits(1), bits(1), bits(1), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_orr_advsimd_imm_aarch64_instrs_vector_logical (Rd, h, g, f, e, d, cmode, c, b, a, op, Q) = { + let 'rd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + operation : ImmediateOp = undefined; + match cmode @ op { + [bitzero, _, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitzero, _, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitzero, _, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitzero, _, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitzero, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitzero, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitzero, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitone, bitzero, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitone, bitzero, _, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitone, bitzero, _, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitone, bitone, bitzero, _] => { + operation = ImmediateOp_MOVI + }, + 0b11110 => { + operation = ImmediateOp_MOVI + }, + 0b11111 => { + if Q == 0b0 then { + throw(Error_Undefined()) + }; + operation = ImmediateOp_MOVI + } + }; + let operation = operation; + let imm64 : bits(64) = AdvSIMDExpandImm(op, cmode, ((((((a @ b) @ c) @ d) @ e) @ f) @ g) @ h); + let imm : bits('datasize) = Replicate(imm64, DIV(datasize, 64)); + execute_aarch64_instrs_vector_logical(datasize, imm, operation, rd) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 85) = { + SEE = 85; + let Rd = Slice(__opcode, 0, 5); + let h = Slice(__opcode, 5, 1); + let g = Slice(__opcode, 6, 1); + let f = Slice(__opcode, 7, 1); + let e = Slice(__opcode, 8, 1); + let d = Slice(__opcode, 9, 1); + let cmode = Slice(__opcode, 12, 4); + let c = Slice(__opcode, 16, 1); + let b = Slice(__opcode, 17, 1); + let a = Slice(__opcode, 18, 1); + let op = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_orr_advsimd_imm_aarch64_instrs_vector_logical(Rd, h, g, f, e, d, cmode, c, b, a, op, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor : forall 'd 'datasize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n), VBitOp) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor (d, datasize, m, n, op) = { + CheckFPAdvSIMDEnabled64(); + operand1 : bits('datasize) = undefined; + operand2 : bits('datasize) = undefined; + operand3 : bits('datasize) = undefined; + let operand4 : bits('datasize) = V_read(n, datasize); + match op { + VBitOp_VEOR => { + operand1 = V_read(m, datasize); + operand2 = Zeros(datasize); + operand3 = Ones(datasize) + }, + VBitOp_VBSL => { + operand1 = V_read(m, datasize); + operand2 = operand1; + operand3 = V_read(d, datasize) + }, + VBitOp_VBIT => { + operand1 = V_read(d, datasize); + operand2 = operand1; + operand3 = V_read(m, datasize) + }, + VBitOp_VBIF => { + operand1 = V_read(d, datasize); + operand2 = operand1; + operand3 = not_vec(V_read(m, datasize)) + } + }; + let operand3 = operand3; + let operand2 = operand2; + let operand1 = operand1; + V_set(d, datasize) = EOR(operand1, EOR(operand2, operand4) & operand3) +} + +val decode_bif_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_bif_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor (Rd, Rn, Rm, opc2, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + op : VBitOp = undefined; + match opc2 { + 0b00 => { + op = VBitOp_VEOR + }, + 0b01 => { + op = VBitOp_VBSL + }, + 0b10 => { + op = VBitOp_VBIT + }, + 0b11 => { + op = VBitOp_VBIF + } + }; + let op = op; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(d, datasize, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 86) = { + SEE = 86; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let opc2 = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_bif_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(Rd, Rn, Rm, opc2, Q) +} + +val decode_bit_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_bit_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor (Rd, Rn, Rm, opc2, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + op : VBitOp = undefined; + match opc2 { + 0b00 => { + op = VBitOp_VEOR + }, + 0b01 => { + op = VBitOp_VBSL + }, + 0b10 => { + op = VBitOp_VBIT + }, + 0b11 => { + op = VBitOp_VBIF + } + }; + let op = op; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(d, datasize, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 87) = { + SEE = 87; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let opc2 = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_bit_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(Rd, Rn, Rm, opc2, Q) +} + +val decode_bsl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_bsl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor (Rd, Rn, Rm, opc2, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + op : VBitOp = undefined; + match opc2 { + 0b00 => { + op = VBitOp_VEOR + }, + 0b01 => { + op = VBitOp_VBSL + }, + 0b10 => { + op = VBitOp_VBIT + }, + 0b11 => { + op = VBitOp_VBIF + } + }; + let op = op; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(d, datasize, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 88) = { + SEE = 88; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let opc2 = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_bsl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(Rd, Rn, Rm, opc2, Q) +} + +val decode_eor_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_eor_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor (Rd, Rn, Rm, opc2, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + op : VBitOp = undefined; + match opc2 { + 0b00 => { + op = VBitOp_VEOR + }, + 0b01 => { + op = VBitOp_VBSL + }, + 0b10 => { + op = VBitOp_VBIT + }, + 0b11 => { + op = VBitOp_VBIF + } + }; + let op = op; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(d, datasize, m, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 89) = { + SEE = 89; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let opc2 = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_eor_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_logical_bsl_eor(Rd, Rn, Rm, opc2, Q) +} + +val execute_aarch64_instrs_branch_unconditional_register : forall 'm 'n ('pac : Bool) ('source_is_sp : Bool) ('use_key_a : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31). + (BranchType, int('m), int('n), bool('pac), bool('source_is_sp), bool('use_key_a)) -> unit + +function execute_aarch64_instrs_branch_unconditional_register (branch_type, m, n, pac, source_is_sp, use_key_a) = { + inst_type : GCSInstruction = undefined; + target : bits(64) = X_read(n, 64); + let auth_then_branch : bool = true; + if pac then { + let modifier : bits(64) = if source_is_sp then SP_read() else + X_read(m, 64); + if use_key_a then { + target = AuthIA(target, modifier, auth_then_branch) + } else { + target = AuthIB(target, modifier, auth_then_branch) + } + }; + if (branch_type == BranchType_RET & HaveGCS()) & GCSPCREnabled(PSTATE.EL) then { + if not_bool(pac) then { + inst_type = GCSInstType_PRET + } else { + if use_key_a then { + inst_type = GCSInstType_PRETAA + } else { + inst_type = GCSInstType_PRETAB + } + }; + target = LoadCheckGCSRecord(target, inst_type); + SetCurrentGCSPointer(GetCurrentGCSPointer() + 8) + }; + if branch_type == BranchType_INDCALL then { + if HaveGCS() & GCSPCREnabled(PSTATE.EL) then { + AddGCSRecord(PC_read() + 4) + }; + X_set(30, 64) = PC_read() + 4 + }; + match branch_type { + BranchType_INDIR => { + if InGuardedPage then { + if n == 16 | n == 17 then { + BTypeNext = 0b01 + } else { + BTypeNext = 0b11 + } + } else { + BTypeNext = 0b01 + } + }, + BranchType_INDCALL => { + BTypeNext = 0b10 + }, + BranchType_RET => { + BTypeNext = 0b00 + }, + _ => () + }; + let branch_conditional : bool = false; + BranchTo(target, branch_type, branch_conditional) +} + +val decode_blr_aarch64_instrs_branch_unconditional_register : (bits(5), bits(5), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_blr_aarch64_instrs_branch_unconditional_register (Rm, Rn, M, A, op, Z) = { + n : range(0, 31) = UInt(Rn); + branch_type : BranchType = undefined; + let 'm = UInt(Rm); + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + source_is_sp : bool = Z == 0b1 & m == 31; + if not_bool(pac) & m != 0 then { + throw(Error_Undefined()) + } else if pac & not_bool(HavePACExt()) then { + throw(Error_Undefined()) + } else (); + match op { + 0b00 => { + branch_type = BranchType_INDIR + }, + 0b01 => { + branch_type = BranchType_INDCALL + }, + 0b10 => { + branch_type = BranchType_RET + }, + _ => { + throw(Error_Undefined()) + } + }; + let branch_type = branch_type; + if pac then { + if Z == 0b0 & m != 31 then { + throw(Error_Undefined()) + }; + if branch_type == BranchType_RET then { + if n != 31 then { + throw(Error_Undefined()) + }; + n = 30; + source_is_sp = true + }; + () + }; + let 'n = n; + execute_aarch64_instrs_branch_unconditional_register(branch_type, m, n, pac, source_is_sp, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero] as __opcode)) if SEE < 90) = { + SEE = 90; + let Rm = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 21, 2); + let Z = Slice(__opcode, 24, 1); + decode_blr_aarch64_instrs_branch_unconditional_register(Rm, Rn, M, A, op, Z) +} + +val decode_blra_aarch64_instrs_branch_unconditional_register : (bits(5), bits(5), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_blra_aarch64_instrs_branch_unconditional_register (Rm, Rn, M, A, op, Z) = { + n : range(0, 31) = UInt(Rn); + branch_type : BranchType = undefined; + let 'm = UInt(Rm); + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + source_is_sp : bool = Z == 0b1 & m == 31; + if not_bool(pac) & m != 0 then { + throw(Error_Undefined()) + } else if pac & not_bool(HavePACExt()) then { + throw(Error_Undefined()) + } else (); + match op { + 0b00 => { + branch_type = BranchType_INDIR + }, + 0b01 => { + branch_type = BranchType_INDCALL + }, + 0b10 => { + branch_type = BranchType_RET + }, + _ => { + throw(Error_Undefined()) + } + }; + let branch_type = branch_type; + if pac then { + if Z == 0b0 & m != 31 then { + throw(Error_Undefined()) + }; + if branch_type == BranchType_RET then { + if n != 31 then { + throw(Error_Undefined()) + }; + n = 30; + source_is_sp = true + }; + () + }; + let 'n = n; + execute_aarch64_instrs_branch_unconditional_register(branch_type, m, n, pac, source_is_sp, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 91) = { + SEE = 91; + let Rm = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 21, 2); + let Z = Slice(__opcode, 24, 1); + decode_blra_aarch64_instrs_branch_unconditional_register(Rm, Rn, M, A, op, Z) +} + +val decode_br_aarch64_instrs_branch_unconditional_register : (bits(5), bits(5), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_br_aarch64_instrs_branch_unconditional_register (Rm, Rn, M, A, op, Z) = { + n : range(0, 31) = UInt(Rn); + branch_type : BranchType = undefined; + let 'm = UInt(Rm); + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + source_is_sp : bool = Z == 0b1 & m == 31; + if not_bool(pac) & m != 0 then { + throw(Error_Undefined()) + } else if pac & not_bool(HavePACExt()) then { + throw(Error_Undefined()) + } else (); + match op { + 0b00 => { + branch_type = BranchType_INDIR + }, + 0b01 => { + branch_type = BranchType_INDCALL + }, + 0b10 => { + branch_type = BranchType_RET + }, + _ => { + throw(Error_Undefined()) + } + }; + let branch_type = branch_type; + if pac then { + if Z == 0b0 & m != 31 then { + throw(Error_Undefined()) + }; + if branch_type == BranchType_RET then { + if n != 31 then { + throw(Error_Undefined()) + }; + n = 30; + source_is_sp = true + }; + () + }; + let 'n = n; + execute_aarch64_instrs_branch_unconditional_register(branch_type, m, n, pac, source_is_sp, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero] as __opcode)) if SEE < 92) = { + SEE = 92; + let Rm = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 21, 2); + let Z = Slice(__opcode, 24, 1); + decode_br_aarch64_instrs_branch_unconditional_register(Rm, Rn, M, A, op, Z) +} + +val decode_bra_aarch64_instrs_branch_unconditional_register : (bits(5), bits(5), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_bra_aarch64_instrs_branch_unconditional_register (Rm, Rn, M, A, op, Z) = { + n : range(0, 31) = UInt(Rn); + branch_type : BranchType = undefined; + let 'm = UInt(Rm); + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + source_is_sp : bool = Z == 0b1 & m == 31; + if not_bool(pac) & m != 0 then { + throw(Error_Undefined()) + } else if pac & not_bool(HavePACExt()) then { + throw(Error_Undefined()) + } else (); + match op { + 0b00 => { + branch_type = BranchType_INDIR + }, + 0b01 => { + branch_type = BranchType_INDCALL + }, + 0b10 => { + branch_type = BranchType_RET + }, + _ => { + throw(Error_Undefined()) + } + }; + let branch_type = branch_type; + if pac then { + if Z == 0b0 & m != 31 then { + throw(Error_Undefined()) + }; + if branch_type == BranchType_RET then { + if n != 31 then { + throw(Error_Undefined()) + }; + n = 30; + source_is_sp = true + }; + () + }; + let 'n = n; + execute_aarch64_instrs_branch_unconditional_register(branch_type, m, n, pac, source_is_sp, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 93) = { + SEE = 93; + let Rm = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 21, 2); + let Z = Slice(__opcode, 24, 1); + decode_bra_aarch64_instrs_branch_unconditional_register(Rm, Rn, M, A, op, Z) +} + +val decode_ret_aarch64_instrs_branch_unconditional_register : (bits(5), bits(5), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_ret_aarch64_instrs_branch_unconditional_register (Rm, Rn, M, A, op, Z) = { + n : range(0, 31) = UInt(Rn); + branch_type : BranchType = undefined; + let 'm = UInt(Rm); + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + source_is_sp : bool = Z == 0b1 & m == 31; + if not_bool(pac) & m != 0 then { + throw(Error_Undefined()) + } else if pac & not_bool(HavePACExt()) then { + throw(Error_Undefined()) + } else (); + match op { + 0b00 => { + branch_type = BranchType_INDIR + }, + 0b01 => { + branch_type = BranchType_INDCALL + }, + 0b10 => { + branch_type = BranchType_RET + }, + _ => { + throw(Error_Undefined()) + } + }; + let branch_type = branch_type; + if pac then { + if Z == 0b0 & m != 31 then { + throw(Error_Undefined()) + }; + if branch_type == BranchType_RET then { + if n != 31 then { + throw(Error_Undefined()) + }; + n = 30; + source_is_sp = true + }; + () + }; + let 'n = n; + execute_aarch64_instrs_branch_unconditional_register(branch_type, m, n, pac, source_is_sp, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero] as __opcode)) if SEE < 94) = { + SEE = 94; + let Rm = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 21, 2); + let Z = Slice(__opcode, 24, 1); + decode_ret_aarch64_instrs_branch_unconditional_register(Rm, Rn, M, A, op, Z) +} + +val decode_reta_aarch64_instrs_branch_unconditional_register : (bits(5), bits(5), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_reta_aarch64_instrs_branch_unconditional_register (Rm, Rn, M, A, op, Z) = { + n : range(0, 31) = UInt(Rn); + branch_type : BranchType = undefined; + let 'm = UInt(Rm); + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + source_is_sp : bool = Z == 0b1 & m == 31; + if not_bool(pac) & m != 0 then { + throw(Error_Undefined()) + } else if pac & not_bool(HavePACExt()) then { + throw(Error_Undefined()) + } else (); + match op { + 0b00 => { + branch_type = BranchType_INDIR + }, + 0b01 => { + branch_type = BranchType_INDCALL + }, + 0b10 => { + branch_type = BranchType_RET + }, + _ => { + throw(Error_Undefined()) + } + }; + let branch_type = branch_type; + if pac then { + if Z == 0b0 & m != 31 then { + throw(Error_Undefined()) + }; + if branch_type == BranchType_RET then { + if n != 31 then { + throw(Error_Undefined()) + }; + n = 30; + source_is_sp = true + }; + () + }; + let 'n = n; + execute_aarch64_instrs_branch_unconditional_register(branch_type, m, n, pac, source_is_sp, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 95) = { + SEE = 95; + let Rm = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 21, 2); + let Z = Slice(__opcode, 24, 1); + decode_reta_aarch64_instrs_branch_unconditional_register(Rm, Rn, M, A, op, Z) +} + +val execute_aarch64_instrs_system_exceptions_debug_breakpoint : bits(16) -> unit + +function execute_aarch64_instrs_system_exceptions_debug_breakpoint comment = { + AArch64_SoftwareBreakpoint(comment) +} + +val decode_brk_aarch64_instrs_system_exceptions_debug_breakpoint : bits(16) -> unit + +function decode_brk_aarch64_instrs_system_exceptions_debug_breakpoint imm16 = { + let comment : bits(16) = imm16; + if HaveBTIExt() then { + SetBTypeCompatible(true) + }; + execute_aarch64_instrs_system_exceptions_debug_breakpoint(comment) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero] as __opcode)) if SEE < 96) = { + SEE = 96; + let imm16 = Slice(__opcode, 5, 16); + decode_brk_aarch64_instrs_system_exceptions_debug_breakpoint(imm16) +} + +val execute_aarch64_instrs_system_hints : SystemHintOp -> unit + +function execute_aarch64_instrs_system_hints op = { + match op { + SystemHintOp_YIELD => { + Hint_Yield() + }, + SystemHintOp_DGH => { + Hint_DGH() + }, + SystemHintOp_WFE => { + let 'localtimeout = (1 << 64); + Hint_WFE(localtimeout, WFxType_WFE) + }, + SystemHintOp_WFI => { + let 'localtimeout = (1 << 64); + Hint_WFI(localtimeout, WFxType_WFI) + }, + SystemHintOp_SEV => { + SendEvent() + }, + SystemHintOp_SEVL => { + SendEventLocal() + }, + SystemHintOp_ESB => { + if HaveTME() & TSTATE.depth > 0 then { + FailTransaction(TMFailure_ERR, false) + }; + SynchronizeErrors(); + AArch64_ESBOperation(); + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled() then { + AArch64_vESBOperation() + }; + TakeUnmaskedSErrorInterrupts() + }, + SystemHintOp_PSB => { + ProfilingSynchronizationBarrier() + }, + SystemHintOp_TSB => { + TraceSynchronizationBarrier() + }, + SystemHintOp_GCSB => { + GCSSynchronizationBarrier() + }, + SystemHintOp_CHKFEAT => { + X_set(16, 64) = AArch64_ChkFeat(X_read(16, 64)) + }, + SystemHintOp_CSDB => { + ConsumptionOfSpeculativeDataBarrier() + }, + SystemHintOp_CLRBHB => { + Hint_CLRBHB() + }, + SystemHintOp_BTI => { + SetBTypeNext(0b00) + }, + SystemHintOp_NOP => { + return() + }, + _ => { + Unreachable() + } + } +} + +val decode_bti_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_bti_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, bitzero, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 97) = { + SEE = 97; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_bti_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_chkfeat_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_chkfeat_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010010100011111 as __opcode)) if SEE < 98) = { + SEE = 98; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_chkfeat_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_clrbhb_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_clrbhb_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010001011011111 as __opcode)) if SEE < 99) = { + SEE = 99; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_clrbhb_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_csdb_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_csdb_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010001010011111 as __opcode)) if SEE < 100) = { + SEE = 100; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_csdb_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_dgh_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_dgh_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000011011111 as __opcode)) if SEE < 101) = { + SEE = 101; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_dgh_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_esb_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_esb_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010001000011111 as __opcode)) if SEE < 102) = { + SEE = 102; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_esb_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_gcsb_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_gcsb_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010001001111111 as __opcode)) if SEE < 103) = { + SEE = 103; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_gcsb_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_hint_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_hint_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 104) = { + SEE = 104; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_hint_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_nop_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_nop_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000000011111 as __opcode)) if SEE < 105) = { + SEE = 105; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_nop_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_psb_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_psb_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010001000111111 as __opcode)) if SEE < 106) = { + SEE = 106; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_psb_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_sev_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_sev_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000010011111 as __opcode)) if SEE < 107) = { + SEE = 107; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_sev_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_sevl_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_sevl_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000010111111 as __opcode)) if SEE < 108) = { + SEE = 108; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_sevl_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_tsb_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_tsb_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010001001011111 as __opcode)) if SEE < 109) = { + SEE = 109; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_tsb_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_wfe_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_wfe_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000001011111 as __opcode)) if SEE < 110) = { + SEE = 110; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_wfe_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_wfi_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_wfi_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000001111111 as __opcode)) if SEE < 111) = { + SEE = 111; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_wfi_aarch64_instrs_system_hints(op2, CRm) +} + +val decode_yield_aarch64_instrs_system_hints : (bits(3), bits(4)) -> unit + +function decode_yield_aarch64_instrs_system_hints (op2, CRm) = { + op : SystemHintOp = undefined; + match CRm @ op2 { + 0b0000000 => { + op = SystemHintOp_NOP + }, + 0b0000001 => { + op = SystemHintOp_YIELD + }, + 0b0000010 => { + op = SystemHintOp_WFE + }, + 0b0000011 => { + op = SystemHintOp_WFI + }, + 0b0000100 => { + op = SystemHintOp_SEV + }, + 0b0000101 => { + op = SystemHintOp_SEVL + }, + 0b0000110 => { + if not_bool(HaveDGHExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_DGH + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + [bitzero, bitzero, bitzero, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIA1716")) + }, + 0b010 => { + throw(Error_See("PACIB1716")) + }, + 0b100 => { + throw(Error_See("AUTIA1716")) + }, + 0b110 => { + throw(Error_See("AUTIB1716")) + }, + _ => { + EndOfInstruction() + } + } + }, + 0b0010000 => { + if not_bool(HaveRASExt()) then { + EndOfInstruction() + }; + op = SystemHintOp_ESB + }, + 0b0010001 => { + if not_bool(HaveStatisticalProfiling()) then { + EndOfInstruction() + }; + op = SystemHintOp_PSB + }, + 0b0010010 => { + if not_bool(HaveSelfHostedTrace()) then { + EndOfInstruction() + }; + op = SystemHintOp_TSB + }, + 0b0010011 => { + if not_bool(IsFeatureImplemented(FEAT_GCS)) then { + EndOfInstruction() + }; + op = SystemHintOp_GCSB + }, + 0b0010100 => { + op = SystemHintOp_CSDB + }, + 0b0010110 => { + if not_bool(HaveFeatCLRBHB()) then { + EndOfInstruction() + }; + op = SystemHintOp_CLRBHB + }, + [bitzero, bitzero, bitone, bitone, _, _, _] => { + match op2 { + 0b000 => { + throw(Error_See("PACIAZ")) + }, + 0b001 => { + throw(Error_See("PACIASP")) + }, + 0b010 => { + throw(Error_See("PACIBZ")) + }, + 0b011 => { + throw(Error_See("PACIBSP")) + }, + 0b100 => { + throw(Error_See("AUTIAZ")) + }, + 0b101 => { + throw(Error_See("AUTIASP")) + }, + 0b110 => { + throw(Error_See("AUTIBZ")) + }, + 0b111 => { + throw(Error_See("AUTIBSP")) + } + } + }, + [bitzero, bitone, bitzero, bitzero, _, _, bitzero] => { + op = SystemHintOp_BTI; + SetBTypeCompatible(BTypeCompatible_BTI(op2[2 .. 1])) + }, + 0b0101000 => { + if not_bool(IsFeatureImplemented(FEAT_CHK)) then { + EndOfInstruction() + }; + op = SystemHintOp_CHKFEAT + }, + _ => { + EndOfInstruction() + } + }; + execute_aarch64_instrs_system_hints(op) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000000111111 as __opcode)) if SEE < 112) = { + SEE = 112; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_yield_aarch64_instrs_system_hints(op2, CRm) +} + +val execute_aarch64_instrs_memory_atomicops_cas_single : forall ('acquire : Bool) 'datasize 'n 'regsize ('release : Bool) 's 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (bool('acquire), int('datasize), int('n), int('regsize), bool('release), int('s), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_cas_single (acquire, datasize, n, regsize, release, s, t, tagchecked) = { + address : bits(64) = undefined; + let accdesc : AccessDescriptor = CreateAccDescAtomicOp(MemAtomicOp_CAS, acquire, release, tagchecked); + let comparevalue : bits('datasize) = X_read(s, datasize); + let newvalue : bits('datasize) = X_read(t, datasize); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let data : bits('datasize) = MemAtomic(address, comparevalue, newvalue, accdesc); + assert(constraint('regsize >= 'datasize)); + X_set(s, regsize) = ZeroExtend(data, regsize); + if SPESampleInFlight then { + let ar : bits(1) = if acquire | release then 0b1 else 0b0; + let excl : bits(1) = 0b0; + let at : bits(1) = 0b1; + let is_load : bool = true; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_cas_aarch64_instrs_memory_atomicops_cas_single : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_cas_aarch64_instrs_memory_atomicops_cas_single (Rt, Rn, o0, Rs, L, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = L == 0b1; + let release : bool = o0 == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_cas_single(acquire, datasize, n, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, bitone, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 113) = { + SEE = 113; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + decode_cas_aarch64_instrs_memory_atomicops_cas_single(Rt, Rn, o0, Rs, L, size) +} + +val decode_casb_aarch64_instrs_memory_atomicops_cas_single : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_casb_aarch64_instrs_memory_atomicops_cas_single (Rt, Rn, o0, Rs, L, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = L == 0b1; + let release : bool = o0 == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_cas_single(acquire, datasize, n, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, bitone, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 114) = { + SEE = 114; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + decode_casb_aarch64_instrs_memory_atomicops_cas_single(Rt, Rn, o0, Rs, L, size) +} + +val decode_cash_aarch64_instrs_memory_atomicops_cas_single : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_cash_aarch64_instrs_memory_atomicops_cas_single (Rt, Rn, o0, Rs, L, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = L == 0b1; + let release : bool = o0 == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_cas_single(acquire, datasize, n, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, bitone, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 115) = { + SEE = 115; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + decode_cash_aarch64_instrs_memory_atomicops_cas_single(Rt, Rn, o0, Rs, L, size) +} + +val execute_aarch64_instrs_memory_atomicops_cas_pair : forall ('acquire : Bool) 'datasize 'n ('release : Bool) 's 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64}). + (bool('acquire), int('datasize), int('n), bool('release), int('s), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_cas_pair (acquire, datasize, n, release, s, t, tagchecked) = { + address : bits(64) = undefined; + let s1 : bits('datasize) = X_read(s, datasize); + let s2 : bits('datasize) = X_read(s + 1, datasize); + let t1 : bits('datasize) = X_read(t, datasize); + let t2 : bits('datasize) = X_read(t + 1, datasize); + let accdesc : AccessDescriptor = CreateAccDescAtomicOp(MemAtomicOp_CAS, acquire, release, tagchecked); + let comparevalue : bits(2 * 'datasize) = if BigEndian(accdesc.acctype) then + s1 @ s2 + else + s2 @ s1; + let newvalue : bits(2 * 'datasize) = if BigEndian(accdesc.acctype) then + t1 @ t2 + else + t2 @ t1; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let data : bits(2 * 'datasize) = MemAtomic(address, comparevalue, newvalue, accdesc); + if BigEndian(accdesc.acctype) then { + X_set(s, datasize) = data[2 * datasize - 1 .. datasize]; + X_set(s + 1, datasize) = data[datasize - 1 .. 0] + } else { + X_set(s, datasize) = data[datasize - 1 .. 0]; + X_set(s + 1, datasize) = data[2 * datasize - 1 .. datasize] + }; + if SPESampleInFlight then { + let ar : bits(1) = if acquire | release then 0b1 else 0b0; + let excl : bits(1) = 0b0; + let at : bits(1) = 0b1; + let is_load : bool = true; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_casp_aarch64_instrs_memory_atomicops_cas_pair : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_casp_aarch64_instrs_memory_atomicops_cas_pair (Rt, Rn, Rt2, o0, Rs, L, sz) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + if [Rs[0]] == 0b1 then { + throw(Error_Undefined()) + }; + if [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 's = UInt(Rs); + let 'datasize = (32 << UInt(sz)); + let 'regsize = datasize; + let acquire : bool = L == 0b1; + let release : bool = o0 == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_cas_pair(acquire, datasize, n, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, bitone, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 116) = { + SEE = 116; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let sz = Slice(__opcode, 30, 1); + decode_casp_aarch64_instrs_memory_atomicops_cas_pair(Rt, Rn, Rt2, o0, Rs, L, sz) +} + +val execute_aarch64_instrs_branch_conditional_compare : forall 'datasize ('iszero : Bool) 't, + (0 <= 't & 't <= 31 & 'datasize in {32, 64}). + (int('datasize), bool('iszero), bits(64), int('t)) -> unit + +function execute_aarch64_instrs_branch_conditional_compare (datasize, iszero, offset, t) = { + let operand1 : bits('datasize) = X_read(t, datasize); + let branch_conditional : bool = true; + if IsZero(operand1) == iszero then { + BranchTo(PC_read() + offset, BranchType_DIR, branch_conditional) + } else { + BranchNotTaken(BranchType_DIR, branch_conditional) + } +} + +val decode_cbnz_aarch64_instrs_branch_conditional_compare : (bits(5), bits(19), bits(1), bits(1)) -> unit + +function decode_cbnz_aarch64_instrs_branch_conditional_compare (Rt, imm19, op, sf) = { + let 't = UInt(Rt); + let 'datasize = if sf == 0b1 then 64 else 32; + let iszero : bool = op == 0b0; + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + execute_aarch64_instrs_branch_conditional_compare(datasize, iszero, offset, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([_, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 117) = { + SEE = 117; + let Rt = Slice(__opcode, 0, 5); + let imm19 = Slice(__opcode, 5, 19); + let op = Slice(__opcode, 24, 1); + let sf = Slice(__opcode, 31, 1); + decode_cbnz_aarch64_instrs_branch_conditional_compare(Rt, imm19, op, sf) +} + +val decode_cbz_aarch64_instrs_branch_conditional_compare : (bits(5), bits(19), bits(1), bits(1)) -> unit + +function decode_cbz_aarch64_instrs_branch_conditional_compare (Rt, imm19, op, sf) = { + let 't = UInt(Rt); + let 'datasize = if sf == 0b1 then 64 else 32; + let iszero : bool = op == 0b0; + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + execute_aarch64_instrs_branch_conditional_compare(datasize, iszero, offset, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([_, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 118) = { + SEE = 118; + let Rt = Slice(__opcode, 0, 5); + let imm19 = Slice(__opcode, 5, 19); + let op = Slice(__opcode, 24, 1); + let sf = Slice(__opcode, 31, 1); + decode_cbz_aarch64_instrs_branch_conditional_compare(Rt, imm19, op, sf) +} + +val execute_aarch64_instrs_integer_conditional_compare_register : forall 'datasize 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64}). + (bits(4), int('datasize), bits(4), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_integer_conditional_compare_register (condition, datasize, flags__arg, m, n, sub_op) = { + flags : bits(4) = flags__arg; + taken : bool = false; + if ConditionHolds(condition) then { + let operand1 : bits('datasize) = X_read(n, datasize); + operand2 : bits('datasize) = X_read(m, datasize); + carry_in : bits(1) = 0b0; + if sub_op then { + operand2 = not_vec(operand2); + carry_in = 0b1 + }; + let (_, __tup_1 : bits(4)) = AddWithCarry(operand1, operand2, carry_in) + in + { + flags = __tup_1 + }; + taken = true + }; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = flags; + if SPESampleInFlight then { + let conditional : bool = true; + SPESampleAddOpOther(conditional, taken) + }; + () +} + +val decode_ccmn_reg_aarch64_instrs_integer_conditional_compare_register : (bits(4), bits(5), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ccmn_reg_aarch64_instrs_integer_conditional_compare_register (nzcv, Rn, cond, Rm, op, sf) = { + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let condition : bits(4) = cond; + let flags : bits(4) = nzcv; + execute_aarch64_instrs_integer_conditional_compare_register(condition, datasize, flags, m, n, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, _, _] as __opcode)) if SEE < 119) = { + SEE = 119; + let nzcv = Slice(__opcode, 0, 4); + let Rn = Slice(__opcode, 5, 5); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_ccmn_reg_aarch64_instrs_integer_conditional_compare_register(nzcv, Rn, cond, Rm, op, sf) +} + +val decode_ccmp_reg_aarch64_instrs_integer_conditional_compare_register : (bits(4), bits(5), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ccmp_reg_aarch64_instrs_integer_conditional_compare_register (nzcv, Rn, cond, Rm, op, sf) = { + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let condition : bits(4) = cond; + let flags : bits(4) = nzcv; + execute_aarch64_instrs_integer_conditional_compare_register(condition, datasize, flags, m, n, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, _, _] as __opcode)) if SEE < 120) = { + SEE = 120; + let nzcv = Slice(__opcode, 0, 4); + let Rn = Slice(__opcode, 5, 5); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_ccmp_reg_aarch64_instrs_integer_conditional_compare_register(nzcv, Rn, cond, Rm, op, sf) +} + +val execute_aarch64_instrs_integer_conditional_compare_immediate : forall 'datasize 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64}). + (bits(4), int('datasize), bits(4), bits('datasize), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_integer_conditional_compare_immediate (condition, datasize, flags__arg, imm, n, sub_op) = { + flags : bits(4) = flags__arg; + taken : bool = false; + if ConditionHolds(condition) then { + let operand1 : bits('datasize) = X_read(n, datasize); + operand2 : bits('datasize) = imm; + carry_in : bits(1) = 0b0; + if sub_op then { + operand2 = not_vec(operand2); + carry_in = 0b1 + }; + let (_, __tup_1 : bits(4)) = AddWithCarry(operand1, operand2, carry_in) + in + { + flags = __tup_1 + }; + taken = true + }; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = flags; + if SPESampleInFlight then { + let conditional : bool = true; + SPESampleAddOpOther(conditional, taken) + }; + () +} + +val decode_ccmn_imm_aarch64_instrs_integer_conditional_compare_immediate : (bits(4), bits(5), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ccmn_imm_aarch64_instrs_integer_conditional_compare_immediate (nzcv, Rn, cond, imm5, op, sf) = { + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let condition : bits(4) = cond; + let flags : bits(4) = nzcv; + let imm : bits('datasize) = ZeroExtend(imm5, datasize); + execute_aarch64_instrs_integer_conditional_compare_immediate(condition, datasize, flags, imm, n, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, bitzero, _, _, _, _] as __opcode)) if SEE < 121) = { + SEE = 121; + let nzcv = Slice(__opcode, 0, 4); + let Rn = Slice(__opcode, 5, 5); + let cond = Slice(__opcode, 12, 4); + let imm5 = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_ccmn_imm_aarch64_instrs_integer_conditional_compare_immediate(nzcv, Rn, cond, imm5, op, sf) +} + +val decode_ccmp_imm_aarch64_instrs_integer_conditional_compare_immediate : (bits(4), bits(5), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ccmp_imm_aarch64_instrs_integer_conditional_compare_immediate (nzcv, Rn, cond, imm5, op, sf) = { + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let sub_op : bool = op == 0b1; + let condition : bits(4) = cond; + let flags : bits(4) = nzcv; + let imm : bits('datasize) = ZeroExtend(imm5, datasize); + execute_aarch64_instrs_integer_conditional_compare_immediate(condition, datasize, flags, imm, n, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, bitzero, _, _, _, _] as __opcode)) if SEE < 122) = { + SEE = 122; + let nzcv = Slice(__opcode, 0, 4); + let Rn = Slice(__opcode, 5, 5); + let cond = Slice(__opcode, 12, 4); + let imm5 = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_ccmp_imm_aarch64_instrs_integer_conditional_compare_immediate(nzcv, Rn, cond, imm5, op, sf) +} + +val execute_aarch64_instrs_integer_flags_cfinv : unit -> unit + +function execute_aarch64_instrs_integer_flags_cfinv () = { + PSTATE.C = not_vec(PSTATE.C) +} + +val decode_cfinv_aarch64_instrs_integer_flags_cfinv : bits(4) -> unit + +function decode_cfinv_aarch64_instrs_integer_flags_cfinv CRm = { + if not_bool(HaveFlagManipulateExt()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_flags_cfinv() +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000000100000000011111 as __opcode)) if SEE < 123) = { + SEE = 123; + let CRm = Slice(__opcode, 8, 4); + if (([__opcode[8]] != 0b0 | [__opcode[9]] != 0b0) | [__opcode[10]] != 0b0) | [__opcode[11]] != 0b0 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_cfinv_aarch64_instrs_integer_flags_cfinv(CRm) + } +} + +val execute_aarch64_instrs_system_monitors : unit -> unit + +function execute_aarch64_instrs_system_monitors () = { + ClearExclusiveLocal(ProcessorID()) +} + +val decode_clrex_aarch64_instrs_system_monitors : bits(4) -> unit + +function decode_clrex_aarch64_instrs_system_monitors CRm = { + execute_aarch64_instrs_system_monitors() +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 124) = { + SEE = 124; + let CRm = Slice(__opcode, 8, 4); + decode_clrex_aarch64_instrs_system_monitors(CRm) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_clsz : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (CountOp, int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_clsz (countop, d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + count : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + if countop == CountOp_CLS then { + count = CountLeadingSignBits(Elem_read(operand, e, esize)) + } else { + count = CountLeadingZeroBits(Elem_read(operand, e, esize)) + }; + result = Elem_set(result, e, esize, count[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_cls_advsimd_aarch64_instrs_vector_arithmetic_unary_clsz : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_cls_advsimd_aarch64_instrs_vector_arithmetic_unary_clsz (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let countop : CountOp = if U == 0b1 then CountOp_CLZ else CountOp_CLS; + execute_aarch64_instrs_vector_arithmetic_unary_clsz(countop, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 125) = { + SEE = 125; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cls_advsimd_aarch64_instrs_vector_arithmetic_unary_clsz(Rd, Rn, size, U, Q) +} + +val decode_clz_advsimd_aarch64_instrs_vector_arithmetic_unary_clsz : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_clz_advsimd_aarch64_instrs_vector_arithmetic_unary_clsz (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let countop : CountOp = if U == 0b1 then CountOp_CLZ else CountOp_CLS; + execute_aarch64_instrs_vector_arithmetic_unary_clsz(countop, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 126) = { + SEE = 126; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_clz_advsimd_aarch64_instrs_vector_arithmetic_unary_clsz(Rd, Rn, size, U, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_cnt : forall 'd 'datasize 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('n), CountOp) -> unit + +function execute_aarch64_instrs_integer_arithmetic_cnt (d, datasize, n, opcode) = { + result : int = undefined; + let operand1 : bits('datasize) = X_read(n, datasize); + if opcode == CountOp_CLZ then { + result = CountLeadingZeroBits(operand1) + } else { + result = CountLeadingSignBits(operand1) + }; + let 'result = result; + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_cls_int_aarch64_instrs_integer_arithmetic_cnt : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_cls_int_aarch64_instrs_integer_arithmetic_cnt (Rd, Rn, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let opcode : CountOp = if op == 0b0 then CountOp_CLZ else CountOp_CLS; + execute_aarch64_instrs_integer_arithmetic_cnt(d, datasize, n, opcode) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 127) = { + SEE = 127; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 10, 1); + let sf = Slice(__opcode, 31, 1); + decode_cls_int_aarch64_instrs_integer_arithmetic_cnt(Rd, Rn, op, sf) +} + +val decode_clz_int_aarch64_instrs_integer_arithmetic_cnt : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_clz_int_aarch64_instrs_integer_arithmetic_cnt (Rd, Rn, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + let opcode : CountOp = if op == 0b0 then CountOp_CLZ else CountOp_CLS; + execute_aarch64_instrs_integer_arithmetic_cnt(d, datasize, n, opcode) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 128) = { + SEE = 128; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 10, 1); + let sf = Slice(__opcode, 31, 1); + decode_clz_int_aarch64_instrs_integer_arithmetic_cnt(Rd, Rn, op, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (CompareOp, int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd (comparison, d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : int = undefined; + test_passed : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = SInt(Elem_read(operand, e, esize)); + match comparison { + CompareOp_GT => { + test_passed = element > 0 + }, + CompareOp_GE => { + test_passed = element >= 0 + }, + CompareOp_EQ => { + test_passed = element == 0 + }, + CompareOp_LE => { + test_passed = element <= 0 + }, + CompareOp_LT => { + test_passed = element < 0 + } + }; + result = Elem_set(result, e, esize, if test_passed then Ones(esize) else + Zeros(esize)) + }; + V_set(d, datasize) = result +} + +val decode_cmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd : (bits(5), bits(5), bits(1), bits(2), bits(1)) -> unit + +function decode_cmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd (Rd, Rn, op, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 129) = { + SEE = 129; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(Rd, Rn, op, size, U) +} + +val decode_cmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_cmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 130) = { + SEE = 130; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd(Rd, Rn, op, size, U, Q) +} + +val decode_cmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd : (bits(5), bits(5), bits(1), bits(2), bits(1)) -> unit + +function decode_cmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd (Rd, Rn, op, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 131) = { + SEE = 131; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(Rd, Rn, op, size, U) +} + +val decode_cmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_cmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 132) = { + SEE = 132; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd(Rd, Rn, op, size, U, Q) +} + +val decode_cmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd : (bits(5), bits(5), bits(1), bits(2), bits(1)) -> unit + +function decode_cmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd (Rd, Rn, op, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 133) = { + SEE = 133; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(Rd, Rn, op, size, U) +} + +val decode_cmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_cmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 134) = { + SEE = 134; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd(Rd, Rn, op, size, U, Q) +} + +val decode_cmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd : (bits(5), bits(5), bits(1), bits(2), bits(1)) -> unit + +function decode_cmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd (Rd, Rn, op, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 135) = { + SEE = 135; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(Rd, Rn, op, size, U) +} + +val decode_cmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_cmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 136) = { + SEE = 136; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_bulk_simd(Rd, Rn, op, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd : forall ('and_test : Bool) 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (bool('and_test), int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd (and_test, d, datasize, elements, esize, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + test_passed : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + if and_test then { + test_passed = not_bool(IsZero(element1 & element2)) + } else { + test_passed = element1 == element2 + }; + result = Elem_set(result, e, esize, if test_passed then Ones(esize) else + Zeros(esize)) + }; + V_set(d, datasize) = result +} + +val decode_cmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_cmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let and_test : bool = U == 0b0; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd(and_test, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 137) = { + SEE = 137; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd(Rd, Rn, Rm, size, U) +} + +val decode_cmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_cmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let and_test : bool = U == 0b0; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd(and_test, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 138) = { + SEE = 138; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_simd(Rd, Rn, Rm, size, U, Q) +} + +val decode_cmtst_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_cmtst_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let and_test : bool = U == 0b0; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd(and_test, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 139) = { + SEE = 139; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmtst_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd(Rd, Rn, Rm, size, U) +} + +val decode_cmtst_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_cmtst_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let and_test : bool = U == 0b0; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_sisd(and_test, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 140) = { + SEE = 140; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmtst_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_bitwise_simd(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd : forall ('cmp_eq : Bool) 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (bool('cmp_eq), int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd (cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + test_passed : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + test_passed = if cmp_eq then element1 >= element2 else + element1 > element2; + result = Elem_set(result, e, esize, if test_passed then Ones(esize) else + Zeros(esize)) + }; + V_set(d, datasize) = result +} + +val decode_cmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_cmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd (Rd, Rn, eq, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 141) = { + SEE = 141; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(Rd, Rn, eq, Rm, size, U) +} + +val decode_cmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_cmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd (Rd, Rn, eq, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 142) = { + SEE = 142; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd(Rd, Rn, eq, Rm, size, U, Q) +} + +val decode_cmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_cmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd (Rd, Rn, eq, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 143) = { + SEE = 143; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(Rd, Rn, eq, Rm, size, U) +} + +val decode_cmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_cmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd (Rd, Rn, eq, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 144) = { + SEE = 144; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd(Rd, Rn, eq, Rm, size, U, Q) +} + +val decode_cmhi_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_cmhi_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd (Rd, Rn, eq, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 145) = { + SEE = 145; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmhi_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(Rd, Rn, eq, Rm, size, U) +} + +val decode_cmhi_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_cmhi_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd (Rd, Rn, eq, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 146) = { + SEE = 146; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmhi_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd(Rd, Rn, eq, Rm, size, U, Q) +} + +val decode_cmhs_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_cmhs_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd (Rd, Rn, eq, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 147) = { + SEE = 147; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_cmhs_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(Rd, Rn, eq, Rm, size, U) +} + +val decode_cmhs_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_cmhs_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd (Rd, Rn, eq, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let cmp_eq : bool = eq == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_sisd(cmp_eq, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 148) = { + SEE = 148; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let eq = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_cmhs_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_int_simd(Rd, Rn, eq, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_sisd : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (CompareOp, int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_sisd (comparison, d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : int = undefined; + test_passed : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = SInt(Elem_read(operand, e, esize)); + match comparison { + CompareOp_GT => { + test_passed = element > 0 + }, + CompareOp_GE => { + test_passed = element >= 0 + }, + CompareOp_EQ => { + test_passed = element == 0 + }, + CompareOp_LE => { + test_passed = element <= 0 + }, + CompareOp_LT => { + test_passed = element < 0 + } + }; + result = Elem_set(result, e, esize, if test_passed then Ones(esize) else + Zeros(esize)) + }; + V_set(d, datasize) = result +} + +val decode_cmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_sisd : (bits(5), bits(5), bits(2)) -> unit + +function decode_cmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_sisd (Rd, Rn, size) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let comparison : CompareOp = CompareOp_LT; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 149) = { + SEE = 149; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + decode_cmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_sisd(Rd, Rn, size) +} + +val decode_cmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_simd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_cmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_simd (Rd, Rn, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let comparison : CompareOp = CompareOp_LT; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 150) = { + SEE = 150; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_cmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_int_lessthan_simd(Rd, Rn, size, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_unary_cnt : forall 'd 'datasize 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_unary_cnt (d, datasize, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let 'result = BitCount(operand1); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_cnt_aarch64_instrs_integer_arithmetic_unary_cnt : (bits(5), bits(5), bits(1)) -> unit + +function decode_cnt_aarch64_instrs_integer_arithmetic_unary_cnt (Rd, Rn, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'd = UInt(Rd); + execute_aarch64_instrs_integer_arithmetic_unary_cnt(d, datasize, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 151) = { + SEE = 151; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sf = Slice(__opcode, 31, 1); + decode_cnt_aarch64_instrs_integer_arithmetic_unary_cnt(Rd, Rn, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_cnt : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize == 8 & 'elements in {8, 16} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_cnt (d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + count : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + count = BitCount(Elem_read(operand, e, esize)); + result = Elem_set(result, e, esize, count[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_cnt_advsimd_aarch64_instrs_vector_arithmetic_unary_cnt : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_cnt_advsimd_aarch64_instrs_vector_arithmetic_unary_cnt (Rd, Rn, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size != 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 8); + execute_aarch64_instrs_vector_arithmetic_unary_cnt(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 152) = { + SEE = 152; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_cnt_advsimd_aarch64_instrs_vector_arithmetic_unary_cnt(Rd, Rn, size, Q) +} + +val execute_aarch64_instrs_memory_mcpymset_cpy : forall 'd 'n 's, + (0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bits(4), int('s), MOPSStage) -> unit + +function execute_aarch64_instrs_memory_mcpymset_cpy (d, n, options_name, s, stage) = { + let 'N = MaxBlockSizeCopiedBytes(); + toaddress : bits(64) = X_read(d, 64); + fromaddress : bits(64) = X_read(s, 64); + cpysize : bits(64) = X_read(n, 64); + nzcv : bits(4) = PSTATE.N @ (PSTATE.Z @ (PSTATE.C @ PSTATE.V)); + stagecpysize : bits(64) = undefined; + readdata : bits(8 * 'N) = undefined; + B : int = undefined; + let supports_option_a : bool = CPYOptionA(); + let rprivileged : bool = if [options_name[1]] == 0b1 then + AArch64_IsUnprivAccessPriv() + else + PSTATE.EL != EL0; + let wprivileged : bool = if [options_name[0]] == 0b1 then + AArch64_IsUnprivAccessPriv() + else + PSTATE.EL != EL0; + let rnontemporal : bool = [options_name[3]] == 0b1; + let wnontemporal : bool = [options_name[2]] == 0b1; + let raccdesc : AccessDescriptor = CreateAccDescMOPS(MemOp_LOAD, rprivileged, rnontemporal); + let waccdesc : AccessDescriptor = CreateAccDescMOPS(MemOp_STORE, wprivileged, wnontemporal); + if stage == MOPSStage_Prologue then { + if cpysize[63 .. 55] != 0b000000000 then { + cpysize = 0x007FFFFFFFFFFFFF + }; + forward : bool = undefined; + if UInt(fromaddress[55 .. 0]) > UInt(toaddress[55 .. 0]) & UInt(fromaddress[55 .. 0]) < UInt(toaddress[55 .. 0] + cpysize[55 .. 0]) then { + forward = true + } else if UInt(fromaddress[55 .. 0]) < UInt(toaddress[55 .. 0]) & UInt(fromaddress[55 .. 0] + cpysize[55 .. 0]) > UInt(toaddress[55 .. 0]) then { + forward = false + } else { + forward = MemCpyDirectionChoice(fromaddress, toaddress, cpysize) + }; + if supports_option_a then { + nzcv = 0b0000; + if forward then { + toaddress = toaddress + cpysize; + fromaddress = fromaddress + cpysize; + cpysize = Zeros(64) - cpysize + }; + () + } else { + if not_bool(forward) then { + toaddress = toaddress + cpysize; + fromaddress = fromaddress + cpysize; + nzcv = 0b1010 + } else { + nzcv = 0b0010 + } + }; + stagecpysize = CPYPreSizeChoice(toaddress, fromaddress, cpysize); + assert([stagecpysize[63]] == [cpysize[63]] | stagecpysize == Zeros(64)); + if SInt(cpysize) > 0 then { + assert(SInt(stagecpysize) <= SInt(cpysize)) + } else { + assert(SInt(stagecpysize) >= SInt(cpysize)) + } + } else { + let zero_size_exceptions : bool = MemCpyZeroSizeCheck(); + if zero_size_exceptions | SInt(cpysize) != 0 then { + if supports_option_a then { + if [nzcv[1]] == 0b1 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } else { + if [nzcv[1]] == 0b0 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } + }; + let postsize : bits(64) = CPYPostSizeChoice(toaddress, fromaddress, cpysize); + assert([postsize[63]] == [cpysize[63]] | SInt(postsize) == 0); + if stage == MOPSStage_Main then { + stagecpysize = cpysize - postsize; + if MemCpyParametersIllformedM(toaddress, fromaddress, cpysize) then { + let wrong_option : bool = false; + let from_epilogue : bool = false; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } else { + stagecpysize = postsize; + if cpysize != postsize | MemCpyParametersIllformedE(toaddress, fromaddress, cpysize) then { + let wrong_option : bool = false; + let from_epilogue : bool = true; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } + }; + if SPESampleInFlight then { + SPESampleMemCopy() + }; + if supports_option_a then { + while SInt(stagecpysize) != 0 do { + B = CPYSizeChoice(toaddress, fromaddress, cpysize); + let 'B = B in + { + if SInt(cpysize) < 0 then { + assert(B <= negate(1) * SInt(stagecpysize)); + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + readdata[B * 8 - 1 .. 0] = Mem_read(fromaddress + cpysize, B, raccdesc); + Mem_set(toaddress + cpysize, B, waccdesc) = readdata[B * 8 - 1 .. 0]; + cpysize = cpysize + B; + stagecpysize = stagecpysize + B + } else { + assert(B <= SInt(stagecpysize)); + cpysize = cpysize - B; + stagecpysize = stagecpysize - B; + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + readdata[B * 8 - 1 .. 0] = Mem_read(fromaddress + cpysize, B, raccdesc); + Mem_set(toaddress + cpysize, B, waccdesc) = readdata[B * 8 - 1 .. 0] + } + }; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = cpysize + }; + () + } + } else { + while UInt(stagecpysize) > 0 do { + B = CPYSizeChoice(toaddress, fromaddress, cpysize); + assert(B <= UInt(stagecpysize)); + let 'B = B in + { + if [nzcv[3]] == 0b0 then { + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + readdata[B * 8 - 1 .. 0] = Mem_read(fromaddress, B, raccdesc); + Mem_set(toaddress, B, waccdesc) = readdata[B * 8 - 1 .. 0]; + fromaddress = fromaddress + B; + toaddress = toaddress + B + } else { + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + readdata[B * 8 - 1 .. 0] = Mem_read(fromaddress - B, B, raccdesc); + Mem_set(toaddress - B, B, waccdesc) = readdata[B * 8 - 1 .. 0]; + fromaddress = fromaddress - B; + toaddress = toaddress - B + } + }; + cpysize = cpysize - B; + stagecpysize = stagecpysize - B; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = cpysize; + X_set(d, 64) = toaddress; + X_set(s, 64) = fromaddress + }; + () + } + }; + if stage == MOPSStage_Prologue then { + X_set(n, 64) = cpysize; + X_set(d, 64) = toaddress; + X_set(s, 64) = fromaddress; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + () +} + +val decode_cpyp_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyp_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 153) = { + SEE = 153; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyp_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpypn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpypn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 154) = { + SEE = 154; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpypn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyprn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyprn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 155) = { + SEE = 155; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyprn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyprt_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyprt_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 156) = { + SEE = 156; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyprt_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyprtn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyprtn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 157) = { + SEE = 157; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyprtn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyprtrn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyprtrn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 158) = { + SEE = 158; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyprtrn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyprtwn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyprtwn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 159) = { + SEE = 159; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyprtwn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpypt_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpypt_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 160) = { + SEE = 160; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpypt_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyptn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyptn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 161) = { + SEE = 161; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyptn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyptrn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyptrn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 162) = { + SEE = 162; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyptrn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyptwn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyptwn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 163) = { + SEE = 163; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyptwn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpypwn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpypwn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 164) = { + SEE = 164; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpypwn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpypwt_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpypwt_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 165) = { + SEE = 165; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpypwt_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpypwtn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpypwtn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 166) = { + SEE = 166; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpypwtn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpypwtrn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpypwtrn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 167) = { + SEE = 167; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpypwtrn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpypwtwn_aarch64_instrs_memory_mcpymset_cpy : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpypwtwn_aarch64_instrs_memory_mcpymset_cpy (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpy(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 168) = { + SEE = 168; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpypwtwn_aarch64_instrs_memory_mcpymset_cpy(Rd, Rn, op2, Rs, op1, sz) +} + +val execute_aarch64_instrs_memory_mcpymset_cpyf : forall 'd 'n 's, + (0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bits(4), int('s), MOPSStage) -> unit + +function execute_aarch64_instrs_memory_mcpymset_cpyf (d, n, options_name, s, stage) = { + let 'N = MaxBlockSizeCopiedBytes(); + toaddress : bits(64) = X_read(d, 64); + fromaddress : bits(64) = X_read(s, 64); + cpysize : bits(64) = X_read(n, 64); + nzcv : bits(4) = PSTATE.N @ (PSTATE.Z @ (PSTATE.C @ PSTATE.V)); + stagecpysize : bits(64) = undefined; + readdata : bits(8 * 'N) = undefined; + B : int = undefined; + let supports_option_a : bool = CPYFOptionA(); + let rprivileged : bool = if [options_name[1]] == 0b1 then + AArch64_IsUnprivAccessPriv() + else + PSTATE.EL != EL0; + let wprivileged : bool = if [options_name[0]] == 0b1 then + AArch64_IsUnprivAccessPriv() + else + PSTATE.EL != EL0; + let rnontemporal : bool = [options_name[3]] == 0b1; + let wnontemporal : bool = [options_name[2]] == 0b1; + let raccdesc : AccessDescriptor = CreateAccDescMOPS(MemOp_LOAD, rprivileged, rnontemporal); + let waccdesc : AccessDescriptor = CreateAccDescMOPS(MemOp_STORE, wprivileged, wnontemporal); + if stage == MOPSStage_Prologue then { + if [cpysize[63]] == 0b1 then { + cpysize = 0x7FFFFFFFFFFFFFFF + }; + if supports_option_a then { + nzcv = 0b0000; + toaddress = toaddress + cpysize; + fromaddress = fromaddress + cpysize; + cpysize = Zeros(64) - cpysize + } else { + nzcv = 0b0010 + }; + stagecpysize = CPYPreSizeChoice(toaddress, fromaddress, cpysize); + assert([stagecpysize[63]] == [cpysize[63]] | stagecpysize == Zeros(64)); + if SInt(cpysize) > 0 then { + assert(SInt(stagecpysize) <= SInt(cpysize)) + } else { + assert(SInt(stagecpysize) >= SInt(cpysize)) + } + } else { + let zero_size_exceptions : bool = MemCpyZeroSizeCheck(); + if zero_size_exceptions | SInt(cpysize) != 0 then { + if supports_option_a then { + if [nzcv[1]] == 0b1 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } else { + if [nzcv[1]] == 0b0 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } + }; + let postsize : bits(64) = CPYPostSizeChoice(toaddress, fromaddress, cpysize); + assert([postsize[63]] == [cpysize[63]] | SInt(postsize) == 0); + if stage == MOPSStage_Main then { + stagecpysize = cpysize - postsize; + if MemCpyParametersIllformedM(toaddress, fromaddress, cpysize) then { + let wrong_option : bool = false; + let from_epilogue : bool = false; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } else { + stagecpysize = postsize; + if cpysize != postsize | MemCpyParametersIllformedE(toaddress, fromaddress, cpysize) then { + let wrong_option : bool = false; + let from_epilogue : bool = true; + MismatchedMemCpyException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name) + }; + () + } + }; + if SPESampleInFlight then { + SPESampleMemCopy() + }; + if supports_option_a then { + while SInt(stagecpysize) != 0 do { + B = CPYSizeChoice(toaddress, fromaddress, cpysize); + assert(B <= negate(1) * SInt(stagecpysize)); + let 'B = B in + { + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + readdata[B * 8 - 1 .. 0] = Mem_read(fromaddress + cpysize, B, raccdesc) + }; + let 'B = B in + { + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + Mem_set(toaddress + cpysize, B, waccdesc) = readdata[B * 8 - 1 .. 0] + }; + cpysize = cpysize + B; + stagecpysize = stagecpysize + B; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = cpysize + }; + () + } + } else { + while UInt(stagecpysize) > 0 do { + B = CPYSizeChoice(toaddress, fromaddress, cpysize); + assert(B <= UInt(stagecpysize)); + let 'B = B in + { + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + readdata[B * 8 - 1 .. 0] = Mem_read(fromaddress, B, raccdesc) + }; + let 'B = B in + { + assert(constraint((0 <= 'B * 8 - 1 & 'B * 8 - 1 < 8 * 'N))); + Mem_set(toaddress, B, waccdesc) = readdata[B * 8 - 1 .. 0] + }; + fromaddress = fromaddress + B; + toaddress = toaddress + B; + cpysize = cpysize - B; + stagecpysize = stagecpysize - B; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = cpysize; + X_set(d, 64) = toaddress; + X_set(s, 64) = fromaddress + }; + () + } + }; + if stage == MOPSStage_Prologue then { + X_set(n, 64) = cpysize; + X_set(d, 64) = toaddress; + X_set(s, 64) = fromaddress; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + () +} + +val decode_cpyfp_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfp_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 169) = { + SEE = 169; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfp_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfpn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfpn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 170) = { + SEE = 170; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfpn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfprn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfprn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 171) = { + SEE = 171; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfprn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfprt_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfprt_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 172) = { + SEE = 172; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfprt_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfprtn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfprtn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 173) = { + SEE = 173; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfprtn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfprtrn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfprtrn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 174) = { + SEE = 174; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfprtrn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfprtwn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfprtwn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 175) = { + SEE = 175; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfprtwn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfpt_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfpt_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 176) = { + SEE = 176; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfpt_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfptn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfptn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 177) = { + SEE = 177; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfptn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfptrn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfptrn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 178) = { + SEE = 178; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfptrn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfptwn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfptwn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 179) = { + SEE = 179; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfptwn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfpwn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfpwn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 180) = { + SEE = 180; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfpwn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfpwt_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfpwt_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 181) = { + SEE = 181; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfpwt_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfpwtn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfpwtn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 182) = { + SEE = 182; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfpwtn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfpwtrn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfpwtrn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 183) = { + SEE = 183; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfpwtrn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val decode_cpyfpwtwn_aarch64_instrs_memory_mcpymset_cpyf : (bits(5), bits(5), bits(4), bits(5), bits(2), bits(2)) -> unit + +function decode_cpyfpwtwn_aarch64_instrs_memory_mcpymset_cpyf (Rd, Rn, op2, Rs, op1, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(4) = op2; + stage : MOPSStage = undefined; + match op1 { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_See("Memory Copy and Memory Set")) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if ((((s == n | s == d) | n == d) | d == 31) | s == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_cpyf(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 184) = { + SEE = 184; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let op1 = Slice(__opcode, 22, 2); + let sz = Slice(__opcode, 30, 2); + decode_cpyfpwtwn_aarch64_instrs_memory_mcpymset_cpyf(Rd, Rn, op2, Rs, op1, sz) +} + +val execute_aarch64_instrs_integer_crc : forall ('crc32c : Bool) 'd 'm 'n 'size, + ('size in {8, 16, 32, 64} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (bool('crc32c), int('d), int('m), int('n), int('size)) -> unit + +function execute_aarch64_instrs_integer_crc (crc32c, d, m, n, size) = { + let acc : bits(32) = X_read(n, 32); + let val_name : bits('size) = X_read(m, size); + let poly : bits(32) = (if crc32c then UInt(0x1EDC6F41) else UInt(0x04C11DB7))[31 .. 0]; + let tempacc : bits(32 + 'size) = BitReverse(acc) @ Zeros(size); + let tempval : bits('size + 32) = BitReverse(val_name) @ Zeros(32); + X_set(d, 32) = BitReverse(Poly32Mod2(EOR(tempacc, tempval), poly)) +} + +val decode_crc32_aarch64_instrs_integer_crc : (bits(5), bits(5), bits(2), bits(1), bits(5), bits(1)) -> unit + +function decode_crc32_aarch64_instrs_integer_crc (Rd, Rn, sz, C, Rm, sf) = { + if not_bool(HaveCRCExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if sf == 0b1 & sz != 0b11 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & sz == 0b11 then { + throw(Error_Undefined()) + }; + let 'size = (8 << UInt(sz)); + let crc32c : bool = C == 0b1; + execute_aarch64_instrs_integer_crc(crc32c, d, m, n, size) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 185) = { + SEE = 185; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 10, 2); + let C = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_crc32_aarch64_instrs_integer_crc(Rd, Rn, sz, C, Rm, sf) +} + +val decode_crc32c_aarch64_instrs_integer_crc : (bits(5), bits(5), bits(2), bits(1), bits(5), bits(1)) -> unit + +function decode_crc32c_aarch64_instrs_integer_crc (Rd, Rn, sz, C, Rm, sf) = { + if not_bool(HaveCRCExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if sf == 0b1 & sz != 0b11 then { + throw(Error_Undefined()) + }; + if sf == 0b0 & sz == 0b11 then { + throw(Error_Undefined()) + }; + let 'size = (8 << UInt(sz)); + let crc32c : bool = C == 0b1; + execute_aarch64_instrs_integer_crc(crc32c, d, m, n, size) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 186) = { + SEE = 186; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 10, 2); + let C = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_crc32c_aarch64_instrs_integer_crc(Rd, Rn, sz, C, Rm, sf) +} + +val execute_aarch64_instrs_integer_conditional_select : forall 'd 'datasize ('else_inc : Bool) ('else_inv : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (bits(4), int('d), int('datasize), bool('else_inc), bool('else_inv), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_conditional_select (condition, d, datasize, else_inc, else_inv, m, n) = { + taken : bool = false; + result : bits('datasize) = undefined; + if ConditionHolds(condition) then { + result = X_read(n, datasize); + taken = true + } else { + result = X_read(m, datasize); + if else_inv then { + result = not_vec(result) + }; + if else_inc then { + result = result + 1 + }; + () + }; + X_set(d, datasize) = result; + if SPESampleInFlight then { + let conditional : bool = true; + SPESampleAddOpOther(conditional, taken) + }; + () +} + +val decode_csel_aarch64_instrs_integer_conditional_select : (bits(5), bits(5), bits(1), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_csel_aarch64_instrs_integer_conditional_select (Rd, Rn, o2, cond, Rm, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let condition : bits(4) = cond; + let else_inv : bool = op == 0b1; + let else_inc : bool = o2 == 0b1; + execute_aarch64_instrs_integer_conditional_select(condition, d, datasize, else_inc, else_inv, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 187) = { + SEE = 187; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o2 = Slice(__opcode, 10, 1); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_csel_aarch64_instrs_integer_conditional_select(Rd, Rn, o2, cond, Rm, op, sf) +} + +val decode_csinc_aarch64_instrs_integer_conditional_select : (bits(5), bits(5), bits(1), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_csinc_aarch64_instrs_integer_conditional_select (Rd, Rn, o2, cond, Rm, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let condition : bits(4) = cond; + let else_inv : bool = op == 0b1; + let else_inc : bool = o2 == 0b1; + execute_aarch64_instrs_integer_conditional_select(condition, d, datasize, else_inc, else_inv, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 188) = { + SEE = 188; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o2 = Slice(__opcode, 10, 1); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_csinc_aarch64_instrs_integer_conditional_select(Rd, Rn, o2, cond, Rm, op, sf) +} + +val decode_csinv_aarch64_instrs_integer_conditional_select : (bits(5), bits(5), bits(1), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_csinv_aarch64_instrs_integer_conditional_select (Rd, Rn, o2, cond, Rm, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let condition : bits(4) = cond; + let else_inv : bool = op == 0b1; + let else_inc : bool = o2 == 0b1; + execute_aarch64_instrs_integer_conditional_select(condition, d, datasize, else_inc, else_inv, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 189) = { + SEE = 189; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o2 = Slice(__opcode, 10, 1); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_csinv_aarch64_instrs_integer_conditional_select(Rd, Rn, o2, cond, Rm, op, sf) +} + +val decode_csneg_aarch64_instrs_integer_conditional_select : (bits(5), bits(5), bits(1), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_csneg_aarch64_instrs_integer_conditional_select (Rd, Rn, o2, cond, Rm, op, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let condition : bits(4) = cond; + let else_inv : bool = op == 0b1; + let else_inc : bool = o2 == 0b1; + execute_aarch64_instrs_integer_conditional_select(condition, d, datasize, else_inc, else_inv, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 190) = { + SEE = 190; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o2 = Slice(__opcode, 10, 1); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let op = Slice(__opcode, 30, 1); + let sf = Slice(__opcode, 31, 1); + decode_csneg_aarch64_instrs_integer_conditional_select(Rd, Rn, o2, cond, Rm, op, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_unary_ctz : forall 'd 'datasize 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_unary_ctz (d, datasize, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let 'result = CountLeadingZeroBits(BitReverse(operand1)); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_ctz_aarch64_instrs_integer_arithmetic_unary_ctz : (bits(5), bits(5), bits(1)) -> unit + +function decode_ctz_aarch64_instrs_integer_arithmetic_unary_ctz (Rd, Rn, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'd = UInt(Rd); + execute_aarch64_instrs_integer_arithmetic_unary_ctz(d, datasize, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 191) = { + SEE = 191; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sf = Slice(__opcode, 31, 1); + decode_ctz_aarch64_instrs_integer_arithmetic_unary_ctz(Rd, Rn, sf) +} + +val execute_aarch64_instrs_system_exceptions_debug_exception : bits(2) -> unit + +function execute_aarch64_instrs_system_exceptions_debug_exception target_level = { + DCPSInstruction(target_level) +} + +val decode_dcps1_aarch64_instrs_system_exceptions_debug_exception : (bits(2), bits(16)) -> unit + +function decode_dcps1_aarch64_instrs_system_exceptions_debug_exception (LL, imm16) = { + let target_level : bits(2) = LL; + if LL == 0b00 then { + throw(Error_Undefined()) + }; + if not_bool(Halted()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_system_exceptions_debug_exception(target_level) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone] as __opcode)) if SEE < 192) = { + SEE = 192; + let LL = Slice(__opcode, 0, 2); + let imm16 = Slice(__opcode, 5, 16); + decode_dcps1_aarch64_instrs_system_exceptions_debug_exception(LL, imm16) +} + +val decode_dcps2_aarch64_instrs_system_exceptions_debug_exception : (bits(2), bits(16)) -> unit + +function decode_dcps2_aarch64_instrs_system_exceptions_debug_exception (LL, imm16) = { + let target_level : bits(2) = LL; + if LL == 0b00 then { + throw(Error_Undefined()) + }; + if not_bool(Halted()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_system_exceptions_debug_exception(target_level) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero] as __opcode)) if SEE < 193) = { + SEE = 193; + let LL = Slice(__opcode, 0, 2); + let imm16 = Slice(__opcode, 5, 16); + decode_dcps2_aarch64_instrs_system_exceptions_debug_exception(LL, imm16) +} + +val decode_dcps3_aarch64_instrs_system_exceptions_debug_exception : (bits(2), bits(16)) -> unit + +function decode_dcps3_aarch64_instrs_system_exceptions_debug_exception (LL, imm16) = { + let target_level : bits(2) = LL; + if LL == 0b00 then { + throw(Error_Undefined()) + }; + if not_bool(Halted()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_system_exceptions_debug_exception(target_level) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone] as __opcode)) if SEE < 194) = { + SEE = 194; + let LL = Slice(__opcode, 0, 2); + let imm16 = Slice(__opcode, 5, 16); + decode_dcps3_aarch64_instrs_system_exceptions_debug_exception(LL, imm16) +} + +val execute_aarch64_instrs_system_barriers_dmb : (MBReqDomain, MBReqTypes) -> unit + +function execute_aarch64_instrs_system_barriers_dmb (domain, types) = { + DataMemoryBarrier(domain, types) +} + +val decode_dmb_aarch64_instrs_system_barriers_dmb : (bits(2), bits(4)) -> unit + +function decode_dmb_aarch64_instrs_system_barriers_dmb (opc, CRm) = { + domain : MBReqDomain = undefined; + types : MBReqTypes = undefined; + match CRm[3 .. 2] { + 0b00 => { + domain = MBReqDomain_OuterShareable + }, + 0b01 => { + domain = MBReqDomain_Nonshareable + }, + 0b10 => { + domain = MBReqDomain_InnerShareable + }, + 0b11 => { + domain = MBReqDomain_FullSystem + } + }; + match CRm[1 .. 0] { + 0b00 => { + types = MBReqTypes_All; + domain = MBReqDomain_FullSystem + }, + 0b01 => { + types = MBReqTypes_Reads + }, + 0b10 => { + types = MBReqTypes_Writes + }, + 0b11 => { + types = MBReqTypes_All + } + }; + let types = types; + execute_aarch64_instrs_system_barriers_dmb(domain, types) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 195) = { + SEE = 195; + let opc = Slice(__opcode, 5, 2); + let CRm = Slice(__opcode, 8, 4); + decode_dmb_aarch64_instrs_system_barriers_dmb(opc, CRm) +} + +val execute_aarch64_instrs_branch_unconditional_dret : unit -> unit + +function execute_aarch64_instrs_branch_unconditional_dret () = { + DRPSInstruction() +} + +val decode_drps_aarch64_instrs_branch_unconditional_dret : unit -> unit + +function decode_drps_aarch64_instrs_branch_unconditional_dret () = { + if not_bool(Halted()) | PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_branch_unconditional_dret() +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010110101111110000001111100000 as __opcode)) if SEE < 196) = { + SEE = 196; + decode_drps_aarch64_instrs_branch_unconditional_dret() +} + +val execute_aarch64_instrs_system_barriers_dsb : forall ('nXS : Bool). + (DSBAlias, MBReqDomain, bool('nXS), MBReqTypes) -> unit + +function execute_aarch64_instrs_system_barriers_dsb (alias, domain, nXS__arg, types) = { + nXS : bool = nXS__arg; + match alias { + DSBAlias_SSBB => { + SpeculativeStoreBypassBarrierToVA() + }, + DSBAlias_PSSBB => { + SpeculativeStoreBypassBarrierToPA() + }, + DSBAlias_DSB => { + if HaveTME() & TSTATE.depth > 0 then { + FailTransaction(TMFailure_ERR, false) + }; + if not_bool(nXS) & HaveFeatXS() then { + nXS = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & IsHCRXEL2Enabled()) & HCRX_EL2[FnXS] == 0b1 + }; + DataSynchronizationBarrier(domain, types, nXS) + }, + _ => { + Unreachable() + } + } +} + +val decode_dsb_aarch64_instrs_system_barriers_dsb : (bits(2), bits(4)) -> unit + +function decode_dsb_aarch64_instrs_system_barriers_dsb (opc, CRm) = { + let nXS : bool = false; + alias : DSBAlias = undefined; + match CRm { + 0b0000 => { + alias = DSBAlias_SSBB + }, + 0b0100 => { + alias = DSBAlias_PSSBB + }, + _ => { + alias = DSBAlias_DSB + } + }; + let alias = alias; + domain : MBReqDomain = undefined; + match CRm[3 .. 2] { + 0b00 => { + domain = MBReqDomain_OuterShareable + }, + 0b01 => { + domain = MBReqDomain_Nonshareable + }, + 0b10 => { + domain = MBReqDomain_InnerShareable + }, + 0b11 => { + domain = MBReqDomain_FullSystem + } + }; + types : MBReqTypes = undefined; + match CRm[1 .. 0] { + 0b00 => { + types = MBReqTypes_All; + domain = MBReqDomain_FullSystem + }, + 0b01 => { + types = MBReqTypes_Reads + }, + 0b10 => { + types = MBReqTypes_Writes + }, + 0b11 => { + types = MBReqTypes_All + } + }; + execute_aarch64_instrs_system_barriers_dsb(alias, domain, nXS, types) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 197) = { + SEE = 197; + let opc = Slice(__opcode, 5, 2); + let CRm = Slice(__opcode, 8, 4); + decode_dsb_aarch64_instrs_system_barriers_dsb(opc, CRm) +} + +val decode_dsb_aarch64_instrs_system_barriers_dsb_nxs : bits(2) -> unit + +function decode_dsb_aarch64_instrs_system_barriers_dsb_nxs imm2 = { + if not_bool(HaveFeatXS()) then { + throw(Error_Undefined()) + }; + let types : MBReqTypes = MBReqTypes_All; + let nXS : bool = true; + let alias : DSBAlias = DSBAlias_DSB; + domain : MBReqDomain = undefined; + match imm2 { + 0b00 => { + domain = MBReqDomain_OuterShareable + }, + 0b01 => { + domain = MBReqDomain_Nonshareable + }, + 0b10 => { + domain = MBReqDomain_InnerShareable + }, + 0b11 => { + domain = MBReqDomain_FullSystem + } + }; + let domain = domain; + execute_aarch64_instrs_system_barriers_dsb(alias, domain, nXS, types) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 198) = { + SEE = 198; + let imm2 = Slice(__opcode, 10, 2); + decode_dsb_aarch64_instrs_system_barriers_dsb_nxs(imm2) +} + +val execute_aarch64_instrs_vector_transfer_vector_cpy_dup_sisd : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'n, + (0 <= 'n & 'n <= 31 & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64, 128, 256} & 'datasize in {8, 16, 32, 64, 128, 256} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('n)) -> unit + +function execute_aarch64_instrs_vector_transfer_vector_cpy_dup_sisd (d, datasize, elements, esize, idxdsize, index, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('idxdsize) = V_read(n, idxdsize); + result : bits('datasize) = undefined; + let element : bits('esize) = Elem_read(operand, index, esize); + foreach (e from 0 to (elements - 1) by 1 in inc) { + result = Elem_set(result, e, esize, element) + }; + assert(constraint('datasize in {8, 16, 32, 64, 128})); + V_set(d, datasize) = result +} + +val decode_dup_advsimd_elt_aarch64_instrs_vector_transfer_vector_cpy_dup_sisd : (bits(5), bits(5), bits(5)) -> unit + +function decode_dup_advsimd_elt_aarch64_instrs_vector_transfer_vector_cpy_dup_sisd (Rd, Rn, imm5) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'size = LowestSetBit(imm5); + if size > 3 then { + throw(Error_Undefined()) + }; + assert(constraint(0 <= 'size + 1)); + let 'index = UInt(imm5[4 .. size + 1]); + let 'idxdsize = if [imm5[4]] == 0b1 then 128 else 64; + let 'esize = (8 << size); + let 'datasize = esize; + let 'elements = 1; + assert(constraint(('esize in {8, 16, 32, 64, 128, 256} & 'datasize in {8, 16, 32, 64, 128, 256}))); + execute_aarch64_instrs_vector_transfer_vector_cpy_dup_sisd(d, datasize, elements, esize, idxdsize, index, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 199) = { + SEE = 199; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm5 = Slice(__opcode, 16, 5); + decode_dup_advsimd_elt_aarch64_instrs_vector_transfer_vector_cpy_dup_sisd(Rd, Rn, imm5) +} + +val decode_dup_advsimd_elt_aarch64_instrs_vector_transfer_vector_cpy_dup_simd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_dup_advsimd_elt_aarch64_instrs_vector_transfer_vector_cpy_dup_simd (Rd, Rn, imm5, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'size = LowestSetBit(imm5); + if size > 3 then { + throw(Error_Undefined()) + }; + assert(constraint(0 <= 'size + 1)); + let 'index = UInt(imm5[4 .. size + 1]); + let 'idxdsize = if [imm5[4]] == 0b1 then 128 else 64; + if size == 3 & Q == 0b0 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << size); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + assert(constraint('esize in {8, 16, 32, 64, 128, 256})); + execute_aarch64_instrs_vector_transfer_vector_cpy_dup_sisd(d, datasize, elements, esize, idxdsize, index, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 200) = { + SEE = 200; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm5 = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_dup_advsimd_elt_aarch64_instrs_vector_transfer_vector_cpy_dup_simd(Rd, Rn, imm5, Q) +} + +val execute_aarch64_instrs_vector_transfer_integer_dup : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64, 128, 256} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_transfer_integer_dup (d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + assert(constraint('esize in {8, 16, 32, 64})); + let element : bits('esize) = X_read(n, esize); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + result = Elem_set(result, e, esize, element) + }; + V_set(d, datasize) = result +} + +val decode_dup_advsimd_gen_aarch64_instrs_vector_transfer_integer_dup : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_dup_advsimd_gen_aarch64_instrs_vector_transfer_integer_dup (Rd, Rn, imm5, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'size = LowestSetBit(imm5); + if size > 3 then { + throw(Error_Undefined()) + }; + if size == 3 & Q == 0b0 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << size); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + assert(constraint('esize in {8, 16, 32, 64, 128, 256})); + execute_aarch64_instrs_vector_transfer_integer_dup(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 201) = { + SEE = 201; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm5 = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_dup_advsimd_gen_aarch64_instrs_vector_transfer_integer_dup(Rd, Rn, imm5, Q) +} + +val execute_aarch64_instrs_vector_crypto_sha3_eor3 : forall 'a 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31 & 0 <= 'a & 'a <= 31). + (int('a), int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3_eor3 (a, d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Va : bits(128) = V_read(a, 128); + V_set(d, 128) = EOR(EOR(Vn, Vm), Va) +} + +val decode_eor3_advsimd_aarch64_instrs_vector_crypto_sha3_eor3 : (bits(5), bits(5), bits(5), bits(5)) -> unit + +function decode_eor3_advsimd_aarch64_instrs_vector_crypto_sha3_eor3 (Rd, Rn, Ra, Rm) = { + if not_bool(HaveSHA3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + execute_aarch64_instrs_vector_crypto_sha3_eor3(a, d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 202) = { + SEE = 202; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let Rm = Slice(__opcode, 16, 5); + decode_eor3_advsimd_aarch64_instrs_vector_crypto_sha3_eor3(Rd, Rn, Ra, Rm) +} + +val execute_aarch64_instrs_branch_unconditional_eret : forall ('pac : Bool) ('use_key_a : Bool). + (bool('pac), bool('use_key_a)) -> unit + +function execute_aarch64_instrs_branch_unconditional_eret (pac, use_key_a) = { + AArch64_CheckForERetTrap(pac, use_key_a); + target : bits(64) = ELR_read__1(); + let modifier : bits(64) = SP_read(); + let auth_then_branch : bool = true; + if pac then { + if use_key_a then { + target = AuthIA(target, modifier, auth_then_branch) + } else { + target = AuthIB(target, modifier, auth_then_branch) + } + }; + return_exception(target[55 .. 0]); + AArch64_ExceptionReturn(target, SPSR_read(64)) +} + +val decode_eret_aarch64_instrs_branch_unconditional_eret : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_eret_aarch64_instrs_branch_unconditional_eret (op4, Rn, M, A) = { + if PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + if not_bool(pac) & op4 != 0b00000 then { + throw(Error_Undefined()) + } else if pac & (not_bool(HavePACExt()) | op4 != 0b11111) then { + throw(Error_Undefined()) + } else (); + if Rn != 0b11111 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_branch_unconditional_eret(pac, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010110100111110000001111100000 as __opcode)) if SEE < 203) = { + SEE = 203; + let op4 = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + decode_eret_aarch64_instrs_branch_unconditional_eret(op4, Rn, M, A) +} + +val decode_ereta_aarch64_instrs_branch_unconditional_eret : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_ereta_aarch64_instrs_branch_unconditional_eret (op4, Rn, M, A) = { + if PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + let pac : bool = A == 0b1; + let use_key_a : bool = M == 0b0; + if not_bool(pac) & op4 != 0b00000 then { + throw(Error_Undefined()) + } else if pac & (not_bool(HavePACExt()) | op4 != 0b11111) then { + throw(Error_Undefined()) + } else (); + if Rn != 0b11111 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_branch_unconditional_eret(pac, use_key_a) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 204) = { + SEE = 204; + let op4 = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let M = Slice(__opcode, 10, 1); + let A = Slice(__opcode, 11, 1); + decode_ereta_aarch64_instrs_branch_unconditional_eret(op4, Rn, M, A) +} + +val execute_aarch64_instrs_vector_transfer_vector_extract : forall 'd 'datasize 'm 'n 'position, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n), int('position)) -> unit + +function execute_aarch64_instrs_vector_transfer_vector_extract (d, datasize, m, n, position) = { + CheckFPAdvSIMDEnabled64(); + let hi : bits('datasize) = V_read(m, datasize); + let lo : bits('datasize) = V_read(n, datasize); + let concat : bits('datasize * 2) = hi @ lo; + assert(constraint((0 <= 'position & 'position + 'datasize - 1 < 'datasize * 2))); + V_set(d, datasize) = concat[position + datasize - 1 .. position] +} + +val decode_ext_advsimd_aarch64_instrs_vector_transfer_vector_extract : (bits(5), bits(5), bits(4), bits(5), bits(1)) -> unit + +function decode_ext_advsimd_aarch64_instrs_vector_transfer_vector_extract (Rd, Rn, imm4, Rm, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if Q == 0b0 & [imm4[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'position = (UInt(imm4) << 3); + execute_aarch64_instrs_vector_transfer_vector_extract(d, datasize, m, n, position) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 205) = { + SEE = 205; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm4 = Slice(__opcode, 11, 4); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_ext_advsimd_aarch64_instrs_vector_transfer_vector_extract(Rd, Rn, imm4, Rm, Q) +} + +val execute_aarch64_instrs_integer_ins_ext_extract_immediate : forall 'd 'datasize 'lsb 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'lsb & 'lsb <= 63 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('lsb), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_ins_ext_extract_immediate (d, datasize, lsb, m, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let concat : bits(2 * 'datasize) = operand1 @ operand2; + assert(constraint('lsb + 'datasize - 1 < 2 * 'datasize)); + let result : bits('datasize) = concat[lsb + datasize - 1 .. lsb]; + X_set(d, datasize) = result +} + +val decode_extr_aarch64_instrs_integer_ins_ext_extract_immediate : (bits(5), bits(5), bits(6), bits(5), bits(1), bits(1)) -> unit + +function decode_extr_aarch64_instrs_integer_ins_ext_extract_immediate (Rd, Rn, imms, Rm, N, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + if N != sf then { + throw(Error_Undefined()) + }; + if sf == 0b0 & [imms[5]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'lsb = UInt(imms); + execute_aarch64_instrs_integer_ins_ext_extract_immediate(d, datasize, lsb, m, n) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 206) = { + SEE = 206; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imms = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + let N = Slice(__opcode, 22, 1); + let sf = Slice(__opcode, 31, 1); + decode_extr_aarch64_instrs_integer_ins_ext_extract_immediate(Rd, Rn, imms, Rm, N, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd : forall ('abs : Bool) 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (bool('abs), int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd (abs, d, datasize, elements, esize, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + diff : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + diff = FPSub(element1, element2, fpcr); + result = Elem_set(result, e, esize, if abs then FPAbs(diff) else diff) + }; + V_set(d, 128) = result +} + +val decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd : (bits(5), bits(5), bits(5)) -> unit + +function decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd (Rd, Rn, Rm) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let abs : bool = true; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd(abs, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 207) = { + SEE = 207; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd(Rd, Rn, Rm) +} + +val decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_sisd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_sisd (Rd, Rn, Rm, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let abs : bool = true; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd(abs, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 208) = { + SEE = 208; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_sisd(Rd, Rn, Rm, sz) +} + +val decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd (Rd, Rn, Rm, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let abs : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd(abs, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 209) = { + SEE = 209; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd(Rd, Rn, Rm, U, Q) +} + +val decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_simd : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_simd (Rd, Rn, Rm, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let abs : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_sisd(abs, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 210) = { + SEE = 210; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_simd(Rd, Rn, Rm, sz, U, Q) +} + +val execute_aarch64_instrs_float_arithmetic_unary : forall 'd 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), FPUnaryOp, int('n)) -> unit + +function execute_aarch64_instrs_float_arithmetic_unary (d, esize, fpop, n) = { + CheckFPEnabled64(); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = fpop != FPUnaryOp_MOV & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else 0[127 .. 0]; + let operand : bits('esize) = V_read(n, esize); + match fpop { + FPUnaryOp_MOV => { + result = Elem_set(result, 0, esize, operand) + }, + FPUnaryOp_ABS => { + result = Elem_set(result, 0, esize, FPAbs(operand)) + }, + FPUnaryOp_NEG => { + result = Elem_set(result, 0, esize, FPNeg(operand)) + }, + FPUnaryOp_SQRT => { + result = Elem_set(result, 0, esize, FPSqrt(operand, fpcr)) + } + }; + V_set(d, 128) = result +} + +val decode_fabs_float_aarch64_instrs_float_arithmetic_unary : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_fabs_float_aarch64_instrs_float_arithmetic_unary (Rd, Rn, opc, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + fpop : FPUnaryOp = undefined; + match opc { + 0b00 => { + fpop = FPUnaryOp_MOV + }, + 0b01 => { + fpop = FPUnaryOp_ABS + }, + 0b10 => { + fpop = FPUnaryOp_NEG + }, + 0b11 => { + fpop = FPUnaryOp_SQRT + } + }; + let fpop = fpop; + execute_aarch64_instrs_float_arithmetic_unary(d, esize, fpop, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 211) = { + SEE = 211; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_fabs_float_aarch64_instrs_float_arithmetic_unary(Rd, Rn, opc, ftype) +} + +val decode_fmov_float_aarch64_instrs_float_arithmetic_unary : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_fmov_float_aarch64_instrs_float_arithmetic_unary (Rd, Rn, opc, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + fpop : FPUnaryOp = undefined; + match opc { + 0b00 => { + fpop = FPUnaryOp_MOV + }, + 0b01 => { + fpop = FPUnaryOp_ABS + }, + 0b10 => { + fpop = FPUnaryOp_NEG + }, + 0b11 => { + fpop = FPUnaryOp_SQRT + } + }; + let fpop = fpop; + execute_aarch64_instrs_float_arithmetic_unary(d, esize, fpop, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 212) = { + SEE = 212; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_fmov_float_aarch64_instrs_float_arithmetic_unary(Rd, Rn, opc, ftype) +} + +val decode_fneg_float_aarch64_instrs_float_arithmetic_unary : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_fneg_float_aarch64_instrs_float_arithmetic_unary (Rd, Rn, opc, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + fpop : FPUnaryOp = undefined; + match opc { + 0b00 => { + fpop = FPUnaryOp_MOV + }, + 0b01 => { + fpop = FPUnaryOp_ABS + }, + 0b10 => { + fpop = FPUnaryOp_NEG + }, + 0b11 => { + fpop = FPUnaryOp_SQRT + } + }; + let fpop = fpop; + execute_aarch64_instrs_float_arithmetic_unary(d, esize, fpop, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 213) = { + SEE = 213; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_fneg_float_aarch64_instrs_float_arithmetic_unary(Rd, Rn, opc, ftype) +} + +val decode_fsqrt_float_aarch64_instrs_float_arithmetic_unary : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_fsqrt_float_aarch64_instrs_float_arithmetic_unary (Rd, Rn, opc, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + fpop : FPUnaryOp = undefined; + match opc { + 0b00 => { + fpop = FPUnaryOp_MOV + }, + 0b01 => { + fpop = FPUnaryOp_ABS + }, + 0b10 => { + fpop = FPUnaryOp_NEG + }, + 0b11 => { + fpop = FPUnaryOp_SQRT + } + }; + let fpop = fpop; + execute_aarch64_instrs_float_arithmetic_unary(d, esize, fpop, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 214) = { + SEE = 214; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_fsqrt_float_aarch64_instrs_float_arithmetic_unary(Rd, Rn, opc, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16 : forall 'd 'datasize 'elements 'esize 'n ('neg : Bool), + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), bool('neg)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16 (d, datasize, elements, esize, n, neg) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + if neg then { + element = FPNeg(element) + } else { + element = FPAbs(element) + }; + result = Elem_set(result, e, esize, element) + }; + V_set(d, datasize) = result +} + +val decode_fabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16 : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16 (Rd, Rn, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 215) = { + SEE = 215; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16(Rd, Rn, U, Q) +} + +val decode_fabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_float : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_float (Rd, Rn, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 216) = { + SEE = 216; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_float(Rd, Rn, sz, U, Q) +} + +val decode_fneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16 : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16 (Rd, Rn, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 217) = { + SEE = 217; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16(Rd, Rn, U, Q) +} + +val decode_fneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_float : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_float (Rd, Rn, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_fp16(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 218) = { + SEE = 218; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_float(Rd, Rn, sz, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd : forall ('abs : Bool) 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (bool('abs), CompareOp, int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd (abs, cmp, d, datasize, elements, esize, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + test_passed : bool = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(m, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + if abs then { + element1 = FPAbs(element1); + element2 = FPAbs(element2) + }; + match cmp { + CompareOp_EQ => { + test_passed = FPCompareEQ(element1, element2, fpcr) + }, + CompareOp_GE => { + test_passed = FPCompareGE(element1, element2, fpcr) + }, + CompareOp_GT => { + test_passed = FPCompareGT(element1, element2, fpcr) + }, + _ => () + }; + result = Elem_set(result, e, esize, if test_passed then Ones(esize) else + Zeros(esize)) + }; + V_set(d, 128) = result +} + +val decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd (Rd, Rn, ac, Rm, E, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 219) = { + SEE = 219; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(Rd, Rn, ac, Rm, E, U) +} + +val decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd (Rd, Rn, ac, Rm, sz, E, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 220) = { + SEE = 220; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd(Rd, Rn, ac, Rm, sz, E, U) +} + +val decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd (Rd, Rn, ac, Rm, E, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 221) = { + SEE = 221; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd(Rd, Rn, ac, Rm, E, U, Q) +} + +val decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd (Rd, Rn, ac, Rm, sz, E, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 222) = { + SEE = 222; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_facge_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd(Rd, Rn, ac, Rm, sz, E, U, Q) +} + +val decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd (Rd, Rn, ac, Rm, E, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 223) = { + SEE = 223; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(Rd, Rn, ac, Rm, E, U) +} + +val decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd (Rd, Rn, ac, Rm, sz, E, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 224) = { + SEE = 224; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd(Rd, Rn, ac, Rm, sz, E, U) +} + +val decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd (Rd, Rn, ac, Rm, E, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 225) = { + SEE = 225; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd(Rd, Rn, ac, Rm, E, U, Q) +} + +val decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd (Rd, Rn, ac, Rm, sz, E, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 226) = { + SEE = 226; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_facgt_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd(Rd, Rn, ac, Rm, sz, E, U, Q) +} + +val decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd (Rd, Rn, ac, Rm, E, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 227) = { + SEE = 227; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(Rd, Rn, ac, Rm, E, U) +} + +val decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd (Rd, Rn, ac, Rm, sz, E, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 228) = { + SEE = 228; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd(Rd, Rn, ac, Rm, sz, E, U) +} + +val decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd (Rd, Rn, ac, Rm, E, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 229) = { + SEE = 229; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd(Rd, Rn, ac, Rm, E, U, Q) +} + +val decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd (Rd, Rn, ac, Rm, sz, E, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 230) = { + SEE = 230; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmeq_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd(Rd, Rn, ac, Rm, sz, E, U, Q) +} + +val decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd (Rd, Rn, ac, Rm, E, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 231) = { + SEE = 231; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(Rd, Rn, ac, Rm, E, U) +} + +val decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd (Rd, Rn, ac, Rm, sz, E, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 232) = { + SEE = 232; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd(Rd, Rn, ac, Rm, sz, E, U) +} + +val decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd (Rd, Rn, ac, Rm, E, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 233) = { + SEE = 233; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd(Rd, Rn, ac, Rm, E, U, Q) +} + +val decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd (Rd, Rn, ac, Rm, sz, E, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 234) = { + SEE = 234; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmge_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd(Rd, Rn, ac, Rm, sz, E, U, Q) +} + +val decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd (Rd, Rn, ac, Rm, E, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 235) = { + SEE = 235; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(Rd, Rn, ac, Rm, E, U) +} + +val decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd (Rd, Rn, ac, Rm, sz, E, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 236) = { + SEE = 236; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_sisd(Rd, Rn, ac, Rm, sz, E, U) +} + +val decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd (Rd, Rn, ac, Rm, E, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 237) = { + SEE = 237; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_simd(Rd, Rn, ac, Rm, E, U, Q) +} + +val decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd : (bits(5), bits(5), bits(1), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd (Rd, Rn, ac, Rm, sz, E, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + cmp : CompareOp = undefined; + abs : bool = undefined; + match (E @ U) @ ac { + 0b000 => { + cmp = CompareOp_EQ; + abs = false + }, + 0b010 => { + cmp = CompareOp_GE; + abs = false + }, + 0b011 => { + cmp = CompareOp_GE; + abs = true + }, + 0b110 => { + cmp = CompareOp_GT; + abs = false + }, + 0b111 => { + cmp = CompareOp_GT; + abs = true + }, + _ => { + throw(Error_Undefined()) + } + }; + let abs = abs; + let cmp = cmp; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp16_sisd(abs, cmp, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 238) = { + SEE = 238; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let E = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmgt_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_cmp_fp_simd(Rd, Rn, ac, Rm, sz, E, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16 : forall 'd 'datasize 'elements 'esize 'm 'n ('pair : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('pair)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16 (d, datasize, elements, esize, m, n, pair) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + let concat : bits(2 * 'datasize) = operand2 @ operand1; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + if pair then { + element1 = Elem_read(concat, 2 * e, esize); + element2 = Elem_read(concat, 2 * e + 1, esize) + } else { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize) + }; + result = Elem_set(result, e, esize, FPAdd(element1, element2, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16 : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16 (Rd, Rn, Rm, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16(d, datasize, elements, esize, m, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 239) = { + SEE = 239; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16(Rd, Rn, Rm, U, Q) +} + +val decode_fadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp (Rd, Rn, Rm, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16(d, datasize, elements, esize, m, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 240) = { + SEE = 240; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp(Rd, Rn, Rm, sz, U, Q) +} + +val decode_faddp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16 : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_faddp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16 (Rd, Rn, Rm, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16(d, datasize, elements, esize, m, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 241) = { + SEE = 241; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_faddp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16(Rd, Rn, Rm, U, Q) +} + +val decode_faddp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_faddp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp (Rd, Rn, Rm, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp16(d, datasize, elements, esize, m, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 242) = { + SEE = 242; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_faddp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp(Rd, Rn, Rm, sz, U, Q) +} + +val execute_aarch64_instrs_float_arithmetic_add_sub : forall 'd 'esize 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_float_arithmetic_add_sub (d, esize, m, n, sub_op) = { + CheckFPEnabled64(); + let operand1 : bits('esize) = V_read(n, esize); + let operand2 : bits('esize) = V_read(m, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + if sub_op then { + result = Elem_set(result, 0, esize, FPSub(operand1, operand2, fpcr)) + } else { + result = Elem_set(result, 0, esize, FPAdd(operand1, operand2, fpcr)) + }; + V_set(d, 128) = result +} + +val decode_fadd_float_aarch64_instrs_float_arithmetic_add_sub : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_fadd_float_aarch64_instrs_float_arithmetic_add_sub (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let sub_op : bool = op == 0b1; + execute_aarch64_instrs_float_arithmetic_add_sub(d, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 243) = { + SEE = 243; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fadd_float_aarch64_instrs_float_arithmetic_add_sub(Rd, Rn, op, Rm, ftype) +} + +val decode_fsub_float_aarch64_instrs_float_arithmetic_add_sub : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_fsub_float_aarch64_instrs_float_arithmetic_add_sub (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let sub_op : bool = op == 0b1; + execute_aarch64_instrs_float_arithmetic_add_sub(d, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 244) = { + SEE = 244; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fsub_float_aarch64_instrs_float_arithmetic_add_sub(Rd, Rn, op, Rm, ftype) +} + +val execute_aarch64_instrs_vector_reduce_fp16_add_sisd : forall 'd 'datasize 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('n), ReduceOp) -> unit + +function execute_aarch64_instrs_vector_reduce_fp16_add_sisd (d, datasize, esize, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + assert(constraint('datasize >= 'esize)); + V_set(d, esize) = Reduce(op, operand, esize) +} + +val decode_faddp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_add_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_faddp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_add_sisd (Rd, Rn, sz) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = ReduceOp_FADD; + execute_aarch64_instrs_vector_reduce_fp16_add_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 245) = { + SEE = 245; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + decode_faddp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_add_sisd(Rd, Rn, sz) +} + +val decode_faddp_advsimd_pair_aarch64_instrs_vector_reduce_fp_add_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_faddp_advsimd_pair_aarch64_instrs_vector_reduce_fp_add_sisd (Rd, Rn, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = ReduceOp_FADD; + execute_aarch64_instrs_vector_reduce_fp16_add_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 246) = { + SEE = 246; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + decode_faddp_advsimd_pair_aarch64_instrs_vector_reduce_fp_add_sisd(Rd, Rn, sz) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp_complex : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bits(1)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp_complex (d, datasize, elements, esize, m, n, rot) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element3 : bits('esize) = undefined; + foreach (e from 0 to (DIV(elements, 2) - 1) by 1 in inc) { + match rot { + 0b0 => { + assert(constraint('esize in {16, 32, 64})); + element1 = FPNeg(Elem_read(operand2, e * 2 + 1, esize)); + element3 = Elem_read(operand2, e * 2, esize) + }, + 0b1 => { + element1 = Elem_read(operand2, e * 2 + 1, esize); + assert(constraint('esize in {16, 32, 64})); + element3 = FPNeg(Elem_read(operand2, e * 2, esize)) + } + }; + assert(constraint('esize in {16, 32, 64})); + result = Elem_set(result, e * 2, esize, FPAdd(Elem_read(operand1, e * 2, esize), element1, FPCR_read())); + result = Elem_set(result, e * 2 + 1, esize, FPAdd(Elem_read(operand1, e * 2 + 1, esize), element3, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fcadd_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp_complex : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_fcadd_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp_complex (Rd, Rn, rot, Rm, size, Q) = { + if not_bool(HaveFCADDExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 then { + throw(Error_Undefined()) + }; + if Q == 0b0 & size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + if not_bool(HaveFP16Ext()) & esize == 16 then { + throw(Error_Undefined()) + }; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp_complex(d, datasize, elements, esize, m, n, rot) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitone, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 247) = { + SEE = 247; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rot = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_fcadd_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_add_fp_complex(Rd, Rn, rot, Rm, size, Q) +} + +val execute_aarch64_instrs_float_compare_cond : forall 'datasize 'm 'n ('signal_all_nans : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {16, 32, 64}). + (bits(4), int('datasize), bits(4), int('m), int('n), bool('signal_all_nans)) -> unit + +function execute_aarch64_instrs_float_compare_cond (condition, datasize, flags__arg, m, n, signal_all_nans) = { + flags : bits(4) = flags__arg; + CheckFPEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + taken : bool = false; + if ConditionHolds(condition) then { + flags = FPCompare(operand1, operand2, signal_all_nans, FPCR_read()); + taken = true + }; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = flags; + if SPESampleInFlight then { + let conditional : bool = true; + SPESampleAddOpOther(conditional, taken) + }; + () +} + +val decode_fccmp_float_aarch64_instrs_float_compare_cond : (bits(4), bits(1), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_fccmp_float_aarch64_instrs_float_compare_cond (nzcv, op, Rn, cond, Rm, ftype) = { + let 'n = UInt(Rn); + let 'm = UInt(Rm); + datasize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + datasize = 32 + }, + 0b01 => { + datasize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + datasize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'datasize = datasize; + let signal_all_nans : bool = op == 0b1; + let condition : bits(4) = cond; + let flags : bits(4) = nzcv; + execute_aarch64_instrs_float_compare_cond(condition, datasize, flags, m, n, signal_all_nans) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, bitzero, _, _, _, _] as __opcode)) if SEE < 248) = { + SEE = 248; + let nzcv = Slice(__opcode, 0, 4); + let op = Slice(__opcode, 4, 1); + let Rn = Slice(__opcode, 5, 5); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fccmp_float_aarch64_instrs_float_compare_cond(nzcv, op, Rn, cond, Rm, ftype) +} + +val decode_fccmpe_float_aarch64_instrs_float_compare_cond : (bits(4), bits(1), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_fccmpe_float_aarch64_instrs_float_compare_cond (nzcv, op, Rn, cond, Rm, ftype) = { + let 'n = UInt(Rn); + let 'm = UInt(Rm); + datasize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + datasize = 32 + }, + 0b01 => { + datasize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + datasize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'datasize = datasize; + let signal_all_nans : bool = op == 0b1; + let condition : bits(4) = cond; + let flags : bits(4) = nzcv; + execute_aarch64_instrs_float_compare_cond(condition, datasize, flags, m, n, signal_all_nans) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, bitone, _, _, _, _] as __opcode)) if SEE < 249) = { + SEE = 249; + let nzcv = Slice(__opcode, 0, 4); + let op = Slice(__opcode, 4, 1); + let Rn = Slice(__opcode, 5, 5); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fccmpe_float_aarch64_instrs_float_compare_cond(nzcv, op, Rn, cond, Rm, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (CompareOp, int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd (comparison, d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + let zero : bits('esize) = FPZero(0b0, esize); + element : bits('esize) = undefined; + test_passed : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + match comparison { + CompareOp_GT => { + test_passed = FPCompareGT(element, zero, FPCR_read()) + }, + CompareOp_GE => { + test_passed = FPCompareGE(element, zero, FPCR_read()) + }, + CompareOp_EQ => { + test_passed = FPCompareEQ(element, zero, FPCR_read()) + }, + CompareOp_LE => { + test_passed = FPCompareGE(zero, element, FPCR_read()) + }, + CompareOp_LT => { + test_passed = FPCompareGT(zero, element, FPCR_read()) + } + }; + result = Elem_set(result, e, esize, if test_passed then Ones(esize) else + Zeros(esize)) + }; + V_set(d, datasize) = result +} + +val decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd (Rd, Rn, op, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 250) = { + SEE = 250; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(Rd, Rn, op, U) +} + +val decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd (Rd, Rn, op, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 251) = { + SEE = 251; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd(Rd, Rn, op, sz, U) +} + +val decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd (Rd, Rn, op, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 252) = { + SEE = 252; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd(Rd, Rn, op, U, Q) +} + +val decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd (Rd, Rn, op, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 253) = { + SEE = 253; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmeq_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd(Rd, Rn, op, sz, U, Q) +} + +val decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd (Rd, Rn, op, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 254) = { + SEE = 254; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(Rd, Rn, op, U) +} + +val decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd (Rd, Rn, op, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 255) = { + SEE = 255; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd(Rd, Rn, op, sz, U) +} + +val decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd (Rd, Rn, op, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 256) = { + SEE = 256; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd(Rd, Rn, op, U, Q) +} + +val decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd (Rd, Rn, op, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 257) = { + SEE = 257; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmge_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd(Rd, Rn, op, sz, U, Q) +} + +val decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd (Rd, Rn, op, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 258) = { + SEE = 258; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(Rd, Rn, op, U) +} + +val decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd (Rd, Rn, op, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 259) = { + SEE = 259; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd(Rd, Rn, op, sz, U) +} + +val decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd (Rd, Rn, op, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 260) = { + SEE = 260; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd(Rd, Rn, op, U, Q) +} + +val decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd (Rd, Rn, op, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 261) = { + SEE = 261; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmgt_advsimd_zero_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd(Rd, Rn, op, sz, U, Q) +} + +val decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd (Rd, Rn, op, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 262) = { + SEE = 262; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(Rd, Rn, op, U) +} + +val decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd (Rd, Rn, op, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 263) = { + SEE = 263; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_sisd(Rd, Rn, op, sz, U) +} + +val decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd (Rd, Rn, op, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 264) = { + SEE = 264; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_simd(Rd, Rn, op, U, Q) +} + +val decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd (Rd, Rn, op, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + comparison : CompareOp = undefined; + match op @ U { + 0b00 => { + comparison = CompareOp_GT + }, + 0b01 => { + comparison = CompareOp_GE + }, + 0b10 => { + comparison = CompareOp_EQ + }, + 0b11 => { + comparison = CompareOp_LE + } + }; + let comparison = comparison; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_bulk_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 265) = { + SEE = 265; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmle_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_bulk_simd(Rd, Rn, op, sz, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_complex : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bits(2)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_complex (d, datasize, elements, esize, m, n, rot) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + element3 : bits('esize) = undefined; + element4 : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + foreach (e from 0 to (DIV(elements, 2) - 1) by 1 in inc) { + match rot { + 0b00 => { + element1 = Elem_read(operand2, e * 2, esize); + element2 = Elem_read(operand1, e * 2, esize); + element3 = Elem_read(operand2, e * 2 + 1, esize); + element4 = Elem_read(operand1, e * 2, esize) + }, + 0b01 => { + assert(constraint('esize in {16, 32, 64})); + element1 = FPNeg(Elem_read(operand2, e * 2 + 1, esize)); + element2 = Elem_read(operand1, e * 2 + 1, esize); + element3 = Elem_read(operand2, e * 2, esize); + element4 = Elem_read(operand1, e * 2 + 1, esize) + }, + 0b10 => { + assert(constraint('esize in {16, 32, 64})); + element1 = FPNeg(Elem_read(operand2, e * 2, esize)); + element2 = Elem_read(operand1, e * 2, esize); + element3 = FPNeg(Elem_read(operand2, e * 2 + 1, esize)); + element4 = Elem_read(operand1, e * 2, esize) + }, + 0b11 => { + element1 = Elem_read(operand2, e * 2 + 1, esize); + element2 = Elem_read(operand1, e * 2 + 1, esize); + assert(constraint('esize in {16, 32, 64})); + element3 = FPNeg(Elem_read(operand2, e * 2, esize)); + element4 = Elem_read(operand1, e * 2 + 1, esize) + } + }; + assert(constraint('esize in {16, 32, 64})); + result = Elem_set(result, e * 2, esize, FPMulAdd(Elem_read(operand3, e * 2, esize), element2, element1, fpcr)); + result = Elem_set(result, e * 2 + 1, esize, FPMulAdd(Elem_read(operand3, e * 2 + 1, esize), element4, element3, fpcr)) + }; + V_set(d, datasize) = result +} + +val decode_fcmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_complex : (bits(5), bits(5), bits(2), bits(5), bits(2), bits(1)) -> unit + +function decode_fcmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_complex (Rd, Rn, rot, Rm, size, Q) = { + if not_bool(HaveFCADDExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 then { + throw(Error_Undefined()) + }; + if Q == 0b0 & size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + if not_bool(HaveFP16Ext()) & esize == 16 then { + throw(Error_Undefined()) + }; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_complex(d, datasize, elements, esize, m, n, rot) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 266) = { + SEE = 266; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rot = Slice(__opcode, 11, 2); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_fcmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_complex(Rd, Rn, rot, Rm, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_complex : forall 'd 'datasize 'elements 'esize 'index 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3} & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('index), int('m), int('n), bits(2)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_complex (d, datasize, elements, esize, index, m, n, rot) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + let fpcr : FPCRType = FPCR_read(); + foreach (e from 0 to (DIV(elements, 2) - 1) by 1 in inc) { + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + element3 : bits('esize) = undefined; + element4 : bits('esize) = undefined; + match rot { + 0b00 => { + element1 = Elem_read(operand2, index * 2, esize); + element2 = Elem_read(operand1, e * 2, esize); + element3 = Elem_read(operand2, index * 2 + 1, esize); + element4 = Elem_read(operand1, e * 2, esize) + }, + 0b01 => { + assert(constraint('esize in {16, 32, 64})); + element1 = FPNeg(Elem_read(operand2, index * 2 + 1, esize)); + element2 = Elem_read(operand1, e * 2 + 1, esize); + element3 = Elem_read(operand2, index * 2, esize); + element4 = Elem_read(operand1, e * 2 + 1, esize) + }, + 0b10 => { + assert(constraint('esize in {16, 32, 64})); + element1 = FPNeg(Elem_read(operand2, index * 2, esize)); + element2 = Elem_read(operand1, e * 2, esize); + element3 = FPNeg(Elem_read(operand2, index * 2 + 1, esize)); + element4 = Elem_read(operand1, e * 2, esize) + }, + 0b11 => { + element1 = Elem_read(operand2, index * 2 + 1, esize); + element2 = Elem_read(operand1, e * 2 + 1, esize); + assert(constraint('esize in {16, 32, 64})); + element3 = FPNeg(Elem_read(operand2, index * 2, esize)); + element4 = Elem_read(operand1, e * 2 + 1, esize) + } + }; + let element4 = element4; + let element3 = element3; + let element2 = element2; + let element1 = element1; + assert(constraint('esize in {16, 32, 64})); + result = Elem_set(result, e * 2, esize, FPMulAdd(Elem_read(operand3, e * 2, esize), element2, element1, fpcr)); + result = Elem_set(result, e * 2 + 1, esize, FPMulAdd(Elem_read(operand3, e * 2 + 1, esize), element4, element3, fpcr)) + }; + V_set(d, datasize) = result +} + +val decode_fcmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_complex : (bits(5), bits(5), bits(1), bits(2), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_fcmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_complex (Rd, Rn, H, rot, Rm, M, L, size, Q) = { + if not_bool(HaveFCADDExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(M @ Rm); + index : int = undefined; + if size == 0b00 | size == 0b11 then { + throw(Error_Undefined()) + }; + if size == 0b01 then { + index = UInt(H @ L) + }; + if size == 0b10 then { + index = UInt(H) + }; + let 'index = index; + let 'esize = (8 << UInt(size)); + if not_bool(HaveFP16Ext()) & esize == 16 then { + throw(Error_Undefined()) + }; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + if size == 0b10 & (L == 0b1 | Q == 0b0) then { + throw(Error_Undefined()) + }; + if (size == 0b01 & H == 0b1) & Q == 0b0 then { + throw(Error_Undefined()) + }; + assert(constraint('index in {0, 1, 2, 3})); + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_complex(d, datasize, elements, esize, index, m, n, rot) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, _, _, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 267) = { + SEE = 267; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let rot = Slice(__opcode, 13, 2); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_fcmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_complex(Rd, Rn, H, rot, Rm, M, L, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (CompareOp, int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd (comparison, d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + let zero : bits('esize) = FPZero(0b0, esize); + element : bits('esize) = undefined; + test_passed : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + match comparison { + CompareOp_GT => { + test_passed = FPCompareGT(element, zero, FPCR_read()) + }, + CompareOp_GE => { + test_passed = FPCompareGE(element, zero, FPCR_read()) + }, + CompareOp_EQ => { + test_passed = FPCompareEQ(element, zero, FPCR_read()) + }, + CompareOp_LE => { + test_passed = FPCompareGE(zero, element, FPCR_read()) + }, + CompareOp_LT => { + test_passed = FPCompareGT(zero, element, FPCR_read()) + } + }; + result = Elem_set(result, e, esize, if test_passed then Ones(esize) else + Zeros(esize)) + }; + V_set(d, datasize) = result +} + +val decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd : (bits(5), bits(5)) -> unit + +function decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd (Rd, Rn) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let comparison : CompareOp = CompareOp_LT; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 268) = { + SEE = 268; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd(Rd, Rn) +} + +val decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_lessthan_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_lessthan_sisd (Rd, Rn, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let comparison : CompareOp = CompareOp_LT; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 269) = { + SEE = 269; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_lessthan_sisd(Rd, Rn, sz) +} + +val decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_simd : (bits(5), bits(5), bits(1)) -> unit + +function decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_simd (Rd, Rn, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let comparison : CompareOp = CompareOp_LT; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 270) = { + SEE = 270; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Q = Slice(__opcode, 30, 1); + decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_simd(Rd, Rn, Q) +} + +val decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_lessthan_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_lessthan_simd (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let comparison : CompareOp = CompareOp_LT; + execute_aarch64_instrs_vector_arithmetic_unary_cmp_fp16_lessthan_sisd(comparison, d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 271) = { + SEE = 271; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcmlt_advsimd_aarch64_instrs_vector_arithmetic_unary_cmp_float_lessthan_simd(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_float_compare_uncond : forall ('cmp_with_zero : Bool) 'datasize 'm 'n ('signal_all_nans : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {16, 32, 64}). + (bool('cmp_with_zero), int('datasize), int('m), int('n), bool('signal_all_nans)) -> unit + +function execute_aarch64_instrs_float_compare_uncond (cmp_with_zero, datasize, m, n, signal_all_nans) = { + CheckFPEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = if cmp_with_zero then FPZero(0b0, datasize) + else + V_read(m, datasize); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = FPCompare(operand1, operand2, signal_all_nans, FPCR_read()) +} + +val decode_fcmp_float_aarch64_instrs_float_compare_uncond : (bits(2), bits(5), bits(5), bits(2)) -> unit + +function decode_fcmp_float_aarch64_instrs_float_compare_uncond (opc, Rn, Rm, ftype) = { + let 'n = UInt(Rn); + let 'm = UInt(Rm); + datasize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + datasize = 32 + }, + 0b01 => { + datasize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + datasize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'datasize = datasize; + let signal_all_nans : bool = [opc[1]] == 0b1; + let cmp_with_zero : bool = [opc[0]] == 0b1; + execute_aarch64_instrs_float_compare_uncond(cmp_with_zero, datasize, m, n, signal_all_nans) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, _, bitzero, bitzero, bitzero] as __opcode)) if SEE < 272) = { + SEE = 272; + let opc = Slice(__opcode, 3, 2); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fcmp_float_aarch64_instrs_float_compare_uncond(opc, Rn, Rm, ftype) +} + +val decode_fcmpe_float_aarch64_instrs_float_compare_uncond : (bits(2), bits(5), bits(5), bits(2)) -> unit + +function decode_fcmpe_float_aarch64_instrs_float_compare_uncond (opc, Rn, Rm, ftype) = { + let 'n = UInt(Rn); + let 'm = UInt(Rm); + datasize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + datasize = 32 + }, + 0b01 => { + datasize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + datasize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'datasize = datasize; + let signal_all_nans : bool = [opc[1]] == 0b1; + let cmp_with_zero : bool = [opc[0]] == 0b1; + execute_aarch64_instrs_float_compare_uncond(cmp_with_zero, datasize, m, n, signal_all_nans) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, bitone, _, bitzero, bitzero, bitzero] as __opcode)) if SEE < 273) = { + SEE = 273; + let opc = Slice(__opcode, 3, 2); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fcmpe_float_aarch64_instrs_float_compare_uncond(opc, Rn, Rm, ftype) +} + +val execute_aarch64_instrs_float_move_fp_select : forall 'd 'datasize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (bits(4), int('d), int('datasize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_float_move_fp_select (condition, d, datasize, m, n) = { + CheckFPEnabled64(); + let result : bits('datasize) = if ConditionHolds(condition) then + V_read(n, datasize) + else + V_read(m, datasize); + V_set(d, datasize) = result +} + +val decode_fcsel_float_aarch64_instrs_float_move_fp_select : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_fcsel_float_aarch64_instrs_float_move_fp_select (Rd, Rn, cond, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + datasize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + datasize = 32 + }, + 0b01 => { + datasize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + datasize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'datasize = datasize; + let condition : bits(4) = cond; + execute_aarch64_instrs_float_move_fp_select(condition, d, datasize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 274) = { + SEE = 274; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let cond = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fcsel_float_aarch64_instrs_float_move_fp_select(Rd, Rn, cond, Rm, ftype) +} + +val execute_aarch64_instrs_float_convert_fp : forall 'd 'dstsize 'n 'srcsize, + ('srcsize in {16, 32, 64} & 0 <= 'n & 'n <= 31 & 'dstsize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('dstsize), int('n), int('srcsize)) -> unit + +function execute_aarch64_instrs_float_convert_fp (d, dstsize, n, srcsize) = { + CheckFPEnabled64(); + let operand : bits('srcsize) = V_read(n, srcsize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + result = Elem_set(result, 0, dstsize, FPConvert__1(operand, fpcr, dstsize)); + V_set(d, 128) = result +} + +val decode_fcvt_float_aarch64_instrs_float_convert_fp : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_fcvt_float_aarch64_instrs_float_convert_fp (Rd, Rn, opc, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + srcsize : {16, 32, 64} = 16; + dstsize : {16, 32, 64} = 16; + if ftype == opc then { + throw(Error_Undefined()) + }; + match ftype { + 0b00 => { + srcsize = 32 + }, + 0b01 => { + srcsize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + srcsize = 16 + } + }; + let 'srcsize = srcsize; + match opc { + 0b00 => { + dstsize = 32 + }, + 0b01 => { + dstsize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + dstsize = 16 + } + }; + let 'dstsize = dstsize; + execute_aarch64_instrs_float_convert_fp(d, dstsize, n, srcsize) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitone, _, _, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 275) = { + SEE = 275; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_fcvt_float_aarch64_instrs_float_convert_fp(Rd, Rn, opc, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), FPRounding, bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd (d, datasize, elements, esize, n, rounding, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + element : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPToFixed(element, 0, is_unsigned, fpcr, rounding, esize)) + }; + V_set(d, 128) = result +} + +val decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd (Rd, Rn, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 276) = { + SEE = 276; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(Rd, Rn, U) +} + +val decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_sisd (Rd, Rn, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 277) = { + SEE = 277; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_sisd(Rd, Rn, sz, U) +} + +val decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_simd (Rd, Rn, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 278) = { + SEE = 278; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_simd(Rd, Rn, U, Q) +} + +val decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_simd (Rd, Rn, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 279) = { + SEE = 279; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtas_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_simd(Rd, Rn, sz, U, Q) +} + +val decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd (Rd, Rn, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 280) = { + SEE = 280; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(Rd, Rn, U) +} + +val decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_sisd (Rd, Rn, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 281) = { + SEE = 281; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_sisd(Rd, Rn, sz, U) +} + +val decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_simd (Rd, Rn, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 282) = { + SEE = 282; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_simd(Rd, Rn, U, Q) +} + +val decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_simd (Rd, Rn, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPRounding_TIEAWAY; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_tieaway_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 283) = { + SEE = 283; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtau_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_tieaway_simd(Rd, Rn, sz, U, Q) +} + +val execute_aarch64_instrs_float_convert_int : forall 'd 'fltsize 'intsize ('is_unsigned : Bool) 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'intsize in {32, 64} & 'fltsize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('fltsize), int('intsize), int('n), FPConvOp, int('part), FPRounding, bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_float_convert_int (d, fltsize, intsize, n, op, part, rounding, is_unsigned) = { + if op == FPConvOp_CVT_FtoI_JS then { + CheckFPAdvSIMDEnabled64() + } else { + CheckFPEnabled64() + }; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + let 'fsize = if op == FPConvOp_CVT_ItoF & merge then 128 else fltsize; + fltval : bits('fsize) = undefined; + intval : bits('intsize) = undefined; + match op { + FPConvOp_CVT_FtoI => { + let fltval : bits('fsize) = V_read(n, fsize); + assert(constraint(('fsize in {16, 32, 64} & 'intsize in {16, 32, 64}))); + let intval : bits('intsize) = FPToFixed(fltval, 0, is_unsigned, fpcr, rounding, intsize); + X_set(d, intsize) = intval + }, + FPConvOp_CVT_ItoF => { + let intval : bits('intsize) = X_read(n, intsize); + fltval : bits('fsize) = if merge then V_read(d, fsize) else + Zeros(fsize); + assert(constraint(('fltsize in {16, 32, 64} & 'intsize in {16, 32, 64}))); + fltval = Elem_set(fltval, 0, fltsize, FixedToFP(intval, 0, is_unsigned, fpcr, rounding, fltsize)); + V_set(d, fsize) = fltval + }, + FPConvOp_MOV_FtoI => { + let fltval : bits('fsize) = Vpart_read(n, part, fsize); + assert(constraint(('fsize >= 0 & 'intsize >= 'fsize))); + let intval : bits('intsize) = ZeroExtend(fltval, intsize); + X_set(d, intsize) = intval + }, + FPConvOp_MOV_ItoF => { + let intval : bits('intsize) = X_read(n, intsize); + assert(constraint((0 <= 'fsize - 1 & 'fsize - 1 < 'intsize))); + let fltval : bits('fsize) = intval[fsize - 1 .. 0]; + Vpart_set(d, part, fsize) = fltval + }, + FPConvOp_CVT_FtoI_JS => { + z : bits(1) = undefined; + let fltval : bits('fsize) = V_read(n, fsize); + assert(constraint('fsize == 64)); + assert(constraint('intsize == 32)); + (intval, z) = FPToFixedJS(fltval, fpcr, true, intsize); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = (0b0 @ z) @ 0b00; + X_set(d, intsize) = intval + } + } +} + +val decode_fcvtas_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtas_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 284) = { + SEE = 284; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtas_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtau_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtau_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 285) = { + SEE = 285; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtau_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtms_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtms_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 286) = { + SEE = 286; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtms_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtmu_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtmu_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 287) = { + SEE = 287; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtmu_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtns_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtns_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 288) = { + SEE = 288; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtns_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtnu_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtnu_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 289) = { + SEE = 289; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtnu_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtps_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtps_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 290) = { + SEE = 290; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtps_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtpu_float_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtpu_float_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 291) = { + SEE = 291; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtpu_float_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtzs_float_int_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtzs_float_int_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 292) = { + SEE = 292; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtzs_float_int_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fcvtzu_float_int_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtzu_float_int_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 293) = { + SEE = 293; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtzu_float_int_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fjcvtzs_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fjcvtzs_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 294) = { + SEE = 294; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fjcvtzs_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_fmov_float_gen_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fmov_float_gen_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, _, bitone, bitone, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 295) = { + SEE = 295; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fmov_float_gen_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_scvtf_float_int_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_scvtf_float_int_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 296) = { + SEE = 296; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_scvtf_float_int_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val decode_ucvtf_float_int_aarch64_instrs_float_convert_int : (bits(5), bits(5), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_ucvtf_float_int_aarch64_instrs_float_convert_int (Rd, Rn, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64, 128} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + part : {0, 1} = 0; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + if (opcode[2 .. 1] @ rmode) != 0b1101 then { + throw(Error_Undefined()) + }; + fltsize = 128 + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + match opcode[2 .. 1] @ rmode { + [bitzero, bitzero, _, _] => { + rounding = FPDecodeRounding(rmode); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + 0b1000 => { + rounding = FPRounding_TIEAWAY; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b1100 => { + if fltsize != 16 & fltsize != intsize then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 0 + }, + 0b1101 => { + if intsize != 64 | fltsize != 128 then { + throw(Error_Undefined()) + }; + op = if [opcode[0]] == 0b1 then FPConvOp_MOV_ItoF else + FPConvOp_MOV_FtoI; + part = 1; + fltsize = 64 + }, + 0b1111 => { + if not_bool(HaveFJCVTZSExt()) then { + throw(Error_Undefined()) + }; + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI_JS + }, + _ => { + throw(Error_Undefined()) + } + }; + let op = op; + let 'part = part; + let 'fltsize = fltsize; + match fltsize { + 16 => { + execute_aarch64_instrs_float_convert_int(d, 16, intsize, n, op, part, rounding, is_unsigned) + }, + 32 => { + execute_aarch64_instrs_float_convert_int(d, 32, intsize, n, op, part, rounding, is_unsigned) + }, + 64 => { + execute_aarch64_instrs_float_convert_int(d, 64, intsize, n, op, part, rounding, is_unsigned) + }, + 128 => { + execute_aarch64_instrs_float_convert_int(d, 128, intsize, n, op, part, rounding, is_unsigned) + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 297) = { + SEE = 297; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_ucvtf_float_int_aarch64_instrs_float_convert_int(Rd, Rn, opcode, rmode, ftype, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_float_widen : forall 'd 'datasize 'elements 'esize 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {16, 32} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_float_widen (d, datasize, elements, esize, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = Vpart_read(n, part, datasize); + result : bits(2 * 'datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + result = Elem_set(result, e, 2 * esize, FPConvert__1(Elem_read(operand, e, esize), FPCR_read(), 2 * esize)) + }; + V_set(d, 2 * datasize) = result +} + +val decode_fcvtl_advsimd_aarch64_instrs_vector_arithmetic_unary_float_widen : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcvtl_advsimd_aarch64_instrs_vector_arithmetic_unary_float_widen (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (16 << UInt(sz)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + assert(constraint('esize in {16, 32})); + execute_aarch64_instrs_vector_arithmetic_unary_float_widen(d, datasize, elements, esize, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 298) = { + SEE = 298; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtl_advsimd_aarch64_instrs_vector_arithmetic_unary_float_widen(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), FPRounding, bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (d, datasize, elements, esize, n, rounding, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + element : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPToFixed(element, 0, is_unsigned, fpcr, rounding, esize)) + }; + V_set(d, 128) = result +} + +val decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 299) = { + SEE = 299; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 300) = { + SEE = 300; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 301) = { + SEE = 301; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 302) = { + SEE = 302; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtms_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 303) = { + SEE = 303; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 304) = { + SEE = 304; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 305) = { + SEE = 305; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 306) = { + SEE = 306; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtmu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 307) = { + SEE = 307; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 308) = { + SEE = 308; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 309) = { + SEE = 309; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 310) = { + SEE = 310; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtns_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 311) = { + SEE = 311; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 312) = { + SEE = 312; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 313) = { + SEE = 313; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 314) = { + SEE = 314; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtnu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 315) = { + SEE = 315; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 316) = { + SEE = 316; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 317) = { + SEE = 317; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 318) = { + SEE = 318; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtps_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 319) = { + SEE = 319; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 320) = { + SEE = 320; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 321) = { + SEE = 321; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 322) = { + SEE = 322; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtpu_advsimd_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 323) = { + SEE = 323; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 324) = { + SEE = 324; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 325) = { + SEE = 325; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 326) = { + SEE = 326; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtzs_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd (Rd, Rn, o1, o2, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 327) = { + SEE = 327; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(Rd, Rn, o1, o2, U) +} + +val decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd (Rd, Rn, o1, sz, o2, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 328) = { + SEE = 328; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_sisd(Rd, Rn, o1, sz, o2, U) +} + +val decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 329) = { + SEE = 329; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_simd(Rd, Rn, o1, o2, U, Q) +} + +val decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : FPRounding = FPDecodeRounding(o1 @ o2); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_float_bulk_sisd(d, datasize, elements, esize, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 330) = { + SEE = 330; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtzu_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_float_bulk_simd(Rd, Rn, o1, sz, o2, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_float_narrow : forall 'd 'datasize 'elements 'esize 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {16, 32} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_float_narrow (d, datasize, elements, esize, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits(2 * 'datasize) = V_read(n, 2 * datasize); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + result = Elem_set(result, e, esize, FPConvert__1(Elem_read(operand, e, 2 * esize), FPCR_read(), esize)) + }; + Vpart_set(d, part, datasize) = result +} + +val decode_fcvtn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_narrow : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcvtn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_narrow (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (16 << UInt(sz)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + assert(constraint('esize in {16, 32})); + execute_aarch64_instrs_vector_arithmetic_unary_float_narrow(d, datasize, elements, esize, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 331) = { + SEE = 331; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_narrow(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_float_xtn_sisd : forall 'd 'datasize 'elements 'esize 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize == 32 & 'elements in {1, 2} & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_float_xtn_sisd (d, datasize, elements, esize, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits(2 * 'datasize) = V_read(n, 2 * datasize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + result = Elem_set(result, e, esize, FPConvert(Elem_read(operand, e, 2 * esize), fpcr, FPRounding_ODD, esize)) + }; + if merge then { + V_set(d, 128) = result + } else { + Vpart_set(d, part, datasize) = Elem_read(result, 0, datasize) + } +} + +val decode_fcvtxn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_xtn_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_fcvtxn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_xtn_sisd (Rd, Rn, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if sz == 0b0 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + execute_aarch64_instrs_vector_arithmetic_unary_float_xtn_sisd(d, datasize, elements, esize, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 332) = { + SEE = 332; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + decode_fcvtxn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_xtn_sisd(Rd, Rn, sz) +} + +val decode_fcvtxn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_xtn_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fcvtxn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_xtn_simd (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if sz == 0b0 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = 64; + let 'elements = 2; + let 'part = UInt(Q); + execute_aarch64_instrs_vector_arithmetic_unary_float_xtn_sisd(d, datasize, elements, esize, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 333) = { + SEE = 333; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtxn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_xtn_simd(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_float_convert_fix : forall 'd 'fltsize 'fracbits 'intsize ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'intsize in {32, 64} & 1 <= 'fracbits & 'fracbits <= 64 & 'fltsize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('fltsize), int('fracbits), int('intsize), int('n), FPConvOp, FPRounding, bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_float_convert_fix (d, fltsize, fracbits, intsize, n, op, rounding, is_unsigned) = { + CheckFPEnabled64(); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + let 'fsize = if op == FPConvOp_CVT_ItoF & merge then 128 else fltsize; + fltval : bits('fsize) = undefined; + intval : bits('intsize) = undefined; + match op { + FPConvOp_CVT_FtoI => { + let fltval : bits('fsize) = V_read(n, fsize); + assert(constraint(('fsize in {16, 32, 64} & 'intsize in {16, 32, 64}))); + let intval : bits('intsize) = FPToFixed(fltval, fracbits, is_unsigned, fpcr, rounding, intsize); + X_set(d, intsize) = intval + }, + FPConvOp_CVT_ItoF => { + let intval : bits('intsize) = X_read(n, intsize); + fltval : bits('fsize) = if merge then V_read(d, fsize) else + Zeros(fsize); + fltval = Elem_set(fltval, 0, fltsize, FixedToFP(intval, fracbits, is_unsigned, fpcr, rounding, fltsize)); + V_set(d, fsize) = fltval + }, + _ => () + } +} + +val decode_fcvtzs_float_fix_aarch64_instrs_float_convert_fix : (bits(5), bits(5), bits(6), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtzs_float_fix_aarch64_instrs_float_convert_fix (Rd, Rn, scale, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'fltsize = fltsize; + if sf == 0b0 & [scale[5]] == 0b0 then { + throw(Error_Undefined()) + }; + let 'fracbits = 64 - UInt(scale); + match opcode[2 .. 1] @ rmode { + 0b0011 => { + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + _ => { + throw(Error_Undefined()) + } + }; + execute_aarch64_instrs_float_convert_fix(d, fltsize, fracbits, intsize, n, op, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 334) = { + SEE = 334; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let scale = Slice(__opcode, 10, 6); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtzs_float_fix_aarch64_instrs_float_convert_fix(Rd, Rn, scale, opcode, rmode, ftype, sf) +} + +val decode_fcvtzu_float_fix_aarch64_instrs_float_convert_fix : (bits(5), bits(5), bits(6), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_fcvtzu_float_fix_aarch64_instrs_float_convert_fix (Rd, Rn, scale, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'fltsize = fltsize; + if sf == 0b0 & [scale[5]] == 0b0 then { + throw(Error_Undefined()) + }; + let 'fracbits = 64 - UInt(scale); + match opcode[2 .. 1] @ rmode { + 0b0011 => { + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + _ => { + throw(Error_Undefined()) + } + }; + execute_aarch64_instrs_float_convert_fix(d, fltsize, fracbits, intsize, n, op, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 335) = { + SEE = 335; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let scale = Slice(__opcode, 10, 6); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_fcvtzu_float_fix_aarch64_instrs_float_convert_fix(Rd, Rn, scale, opcode, rmode, ftype, sf) +} + +val decode_scvtf_float_fix_aarch64_instrs_float_convert_fix : (bits(5), bits(5), bits(6), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_scvtf_float_fix_aarch64_instrs_float_convert_fix (Rd, Rn, scale, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'fltsize = fltsize; + if sf == 0b0 & [scale[5]] == 0b0 then { + throw(Error_Undefined()) + }; + let 'fracbits = 64 - UInt(scale); + match opcode[2 .. 1] @ rmode { + 0b0011 => { + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + _ => { + throw(Error_Undefined()) + } + }; + execute_aarch64_instrs_float_convert_fix(d, fltsize, fracbits, intsize, n, op, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 336) = { + SEE = 336; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let scale = Slice(__opcode, 10, 6); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_scvtf_float_fix_aarch64_instrs_float_convert_fix(Rd, Rn, scale, opcode, rmode, ftype, sf) +} + +val decode_ucvtf_float_fix_aarch64_instrs_float_convert_fix : (bits(5), bits(5), bits(6), bits(3), bits(2), bits(2), bits(1)) -> unit + +function decode_ucvtf_float_fix_aarch64_instrs_float_convert_fix (Rd, Rn, scale, opcode, rmode, ftype, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'intsize = if sf == 0b1 then 64 else 32; + fltsize : {16, 32, 64} = 16; + op : FPConvOp = undefined; + rounding : FPRounding = undefined; + is_unsigned : bool = undefined; + match ftype { + 0b00 => { + fltsize = 32 + }, + 0b01 => { + fltsize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + fltsize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'fltsize = fltsize; + if sf == 0b0 & [scale[5]] == 0b0 then { + throw(Error_Undefined()) + }; + let 'fracbits = 64 - UInt(scale); + match opcode[2 .. 1] @ rmode { + 0b0011 => { + rounding = FPRounding_ZERO; + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_FtoI + }, + 0b0100 => { + rounding = FPRoundingMode(FPCR_read()); + is_unsigned = [opcode[0]] == 0b1; + op = FPConvOp_CVT_ItoF + }, + _ => { + throw(Error_Undefined()) + } + }; + execute_aarch64_instrs_float_convert_fix(d, fltsize, fracbits, intsize, n, op, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([_, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 337) = { + SEE = 337; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let scale = Slice(__opcode, 10, 6); + let opcode = Slice(__opcode, 16, 3); + let rmode = Slice(__opcode, 19, 2); + let ftype = Slice(__opcode, 22, 2); + let sf = Slice(__opcode, 31, 1); + decode_ucvtf_float_fix_aarch64_instrs_float_convert_fix(Rd, Rn, scale, opcode, rmode, ftype, sf) +} + +val execute_aarch64_instrs_vector_shift_conv_float_sisd : forall 'd 'datasize 'elements 'esize 'fracbits ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('fracbits), int('n), FPRounding, bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_shift_conv_float_sisd (d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + element : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPToFixed(element, fracbits, is_unsigned, fpcr, rounding, esize)) + }; + V_set(d, 128) = result +} + +val decode_fcvtzs_advsimd_fix_aarch64_instrs_vector_shift_conv_float_sisd : (bits(5), bits(5), bits(3), bits(4), bits(1)) -> unit + +function decode_fcvtzs_advsimd_fix_aarch64_instrs_vector_shift_conv_float_sisd (Rd, Rn, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = esize; + let 'elements = 1; + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRounding_ZERO; + execute_aarch64_instrs_vector_shift_conv_float_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 338) = { + SEE = 338; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_fcvtzs_advsimd_fix_aarch64_instrs_vector_shift_conv_float_sisd(Rd, Rn, immb, immh, U) +} + +val decode_fcvtzs_advsimd_fix_aarch64_instrs_vector_shift_conv_float_simd : (bits(5), bits(5), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_fcvtzs_advsimd_fix_aarch64_instrs_vector_shift_conv_float_simd (Rd, Rn, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRounding_ZERO; + execute_aarch64_instrs_vector_shift_conv_float_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 339) = { + SEE = 339; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtzs_advsimd_fix_aarch64_instrs_vector_shift_conv_float_simd(Rd, Rn, immb, immh, U, Q) +} + +val decode_fcvtzu_advsimd_fix_aarch64_instrs_vector_shift_conv_float_sisd : (bits(5), bits(5), bits(3), bits(4), bits(1)) -> unit + +function decode_fcvtzu_advsimd_fix_aarch64_instrs_vector_shift_conv_float_sisd (Rd, Rn, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = esize; + let 'elements = 1; + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRounding_ZERO; + execute_aarch64_instrs_vector_shift_conv_float_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 340) = { + SEE = 340; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_fcvtzu_advsimd_fix_aarch64_instrs_vector_shift_conv_float_sisd(Rd, Rn, immb, immh, U) +} + +val decode_fcvtzu_advsimd_fix_aarch64_instrs_vector_shift_conv_float_simd : (bits(5), bits(5), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_fcvtzu_advsimd_fix_aarch64_instrs_vector_shift_conv_float_simd (Rd, Rn, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRounding_ZERO; + execute_aarch64_instrs_vector_shift_conv_float_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 341) = { + SEE = 341; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fcvtzu_advsimd_fix_aarch64_instrs_vector_shift_conv_float_simd(Rd, Rn, immb, immh, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_div_fp16 : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_div_fp16 (d, datasize, elements, esize, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + result = Elem_set(result, e, esize, FPDiv(element1, element2, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fdiv_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_div_fp16 : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_fdiv_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_div_fp16 (Rd, Rn, Rm, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_div_fp16(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 342) = { + SEE = 342; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_fdiv_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_div_fp16(Rd, Rn, Rm, Q) +} + +val decode_fdiv_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_div : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fdiv_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_div (Rd, Rn, Rm, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_div_fp16(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 343) = { + SEE = 343; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fdiv_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_div(Rd, Rn, Rm, sz, Q) +} + +val execute_aarch64_instrs_float_arithmetic_div : forall 'd 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_float_arithmetic_div (d, esize, m, n) = { + CheckFPEnabled64(); + let operand1 : bits('esize) = V_read(n, esize); + let operand2 : bits('esize) = V_read(m, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + result = Elem_set(result, 0, esize, FPDiv(operand1, operand2, FPCR_read())); + V_set(d, 128) = result +} + +val decode_fdiv_float_aarch64_instrs_float_arithmetic_div : (bits(5), bits(5), bits(5), bits(2)) -> unit + +function decode_fdiv_float_aarch64_instrs_float_arithmetic_div (Rd, Rn, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + execute_aarch64_instrs_float_arithmetic_div(d, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 344) = { + SEE = 344; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fdiv_float_aarch64_instrs_float_arithmetic_div(Rd, Rn, Rm, ftype) +} + +val execute_aarch64_instrs_float_arithmetic_mul_add_sub : forall 'a 'd 'esize 'm 'n ('op1_neg : Bool) ('opa_neg : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31 & 0 <= 'a & 'a <= 31). + (int('a), int('d), int('esize), int('m), int('n), bool('op1_neg), bool('opa_neg)) -> unit + +function execute_aarch64_instrs_float_arithmetic_mul_add_sub (a, d, esize, m, n, op1_neg, opa_neg) = { + CheckFPEnabled64(); + operanda : bits('esize) = V_read(a, esize); + operand1 : bits('esize) = V_read(n, esize); + let operand2 : bits('esize) = V_read(m, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(a, 128) else Zeros(128); + if opa_neg then { + operanda = FPNeg(operanda) + }; + if op1_neg then { + operand1 = FPNeg(operand1) + }; + result = Elem_set(result, 0, esize, FPMulAdd(operanda, operand1, operand2, fpcr)); + V_set(d, 128) = result +} + +val decode_fmadd_float_aarch64_instrs_float_arithmetic_mul_add_sub : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_fmadd_float_aarch64_instrs_float_arithmetic_mul_add_sub (Rd, Rn, Ra, o0, Rm, o1, ftype) = { + let 'd = UInt(Rd); + let 'a = UInt(Ra); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let opa_neg : bool = o1 == 0b1; + let op1_neg : bool = o0 != o1; + execute_aarch64_instrs_float_arithmetic_mul_add_sub(a, d, esize, m, n, op1_neg, opa_neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, bitzero, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 345) = { + SEE = 345; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 21, 1); + let ftype = Slice(__opcode, 22, 2); + decode_fmadd_float_aarch64_instrs_float_arithmetic_mul_add_sub(Rd, Rn, Ra, o0, Rm, o1, ftype) +} + +val decode_fmsub_float_aarch64_instrs_float_arithmetic_mul_add_sub : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_fmsub_float_aarch64_instrs_float_arithmetic_mul_add_sub (Rd, Rn, Ra, o0, Rm, o1, ftype) = { + let 'd = UInt(Rd); + let 'a = UInt(Ra); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let opa_neg : bool = o1 == 0b1; + let op1_neg : bool = o0 != o1; + execute_aarch64_instrs_float_arithmetic_mul_add_sub(a, d, esize, m, n, op1_neg, opa_neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, bitzero, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 346) = { + SEE = 346; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 21, 1); + let ftype = Slice(__opcode, 22, 2); + decode_fmsub_float_aarch64_instrs_float_arithmetic_mul_add_sub(Rd, Rn, Ra, o0, Rm, o1, ftype) +} + +val decode_fnmadd_float_aarch64_instrs_float_arithmetic_mul_add_sub : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_fnmadd_float_aarch64_instrs_float_arithmetic_mul_add_sub (Rd, Rn, Ra, o0, Rm, o1, ftype) = { + let 'd = UInt(Rd); + let 'a = UInt(Ra); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let opa_neg : bool = o1 == 0b1; + let op1_neg : bool = o0 != o1; + execute_aarch64_instrs_float_arithmetic_mul_add_sub(a, d, esize, m, n, op1_neg, opa_neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, bitone, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 347) = { + SEE = 347; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 21, 1); + let ftype = Slice(__opcode, 22, 2); + decode_fnmadd_float_aarch64_instrs_float_arithmetic_mul_add_sub(Rd, Rn, Ra, o0, Rm, o1, ftype) +} + +val decode_fnmsub_float_aarch64_instrs_float_arithmetic_mul_add_sub : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_fnmsub_float_aarch64_instrs_float_arithmetic_mul_add_sub (Rd, Rn, Ra, o0, Rm, o1, ftype) = { + let 'd = UInt(Rd); + let 'a = UInt(Ra); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let opa_neg : bool = o1 == 0b1; + let op1_neg : bool = o0 != o1; + execute_aarch64_instrs_float_arithmetic_mul_add_sub(a, d, esize, m, n, op1_neg, opa_neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, bitone, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 348) = { + SEE = 348; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 21, 1); + let ftype = Slice(__opcode, 22, 2); + decode_fnmsub_float_aarch64_instrs_float_arithmetic_mul_add_sub(Rd, Rn, Ra, o0, Rm, o1, ftype) +} + +val execute_aarch64_instrs_float_arithmetic_max_min : forall 'd 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), int('m), int('n), FPMaxMinOp) -> unit + +function execute_aarch64_instrs_float_arithmetic_max_min (d, esize, m, n, operation) = { + CheckFPEnabled64(); + let operand1 : bits('esize) = V_read(n, esize); + let operand2 : bits('esize) = V_read(m, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + match operation { + FPMaxMinOp_MAX => { + result = Elem_set(result, 0, esize, FPMax(operand1, operand2, fpcr)) + }, + FPMaxMinOp_MIN => { + result = Elem_set(result, 0, esize, FPMin(operand1, operand2, fpcr)) + }, + FPMaxMinOp_MAXNUM => { + result = Elem_set(result, 0, esize, FPMaxNum(operand1, operand2, fpcr)) + }, + FPMaxMinOp_MINNUM => { + result = Elem_set(result, 0, esize, FPMinNum(operand1, operand2, fpcr)) + } + }; + V_set(d, 128) = result +} + +val decode_fmax_float_aarch64_instrs_float_arithmetic_max_min : (bits(5), bits(5), bits(2), bits(5), bits(2)) -> unit + +function decode_fmax_float_aarch64_instrs_float_arithmetic_max_min (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + operation : FPMaxMinOp = undefined; + match op { + 0b00 => { + operation = FPMaxMinOp_MAX + }, + 0b01 => { + operation = FPMaxMinOp_MIN + }, + 0b10 => { + operation = FPMaxMinOp_MAXNUM + }, + 0b11 => { + operation = FPMaxMinOp_MINNUM + } + }; + let operation = operation; + execute_aarch64_instrs_float_arithmetic_max_min(d, esize, m, n, operation) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 349) = { + SEE = 349; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fmax_float_aarch64_instrs_float_arithmetic_max_min(Rd, Rn, op, Rm, ftype) +} + +val decode_fmaxnm_float_aarch64_instrs_float_arithmetic_max_min : (bits(5), bits(5), bits(2), bits(5), bits(2)) -> unit + +function decode_fmaxnm_float_aarch64_instrs_float_arithmetic_max_min (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + operation : FPMaxMinOp = undefined; + match op { + 0b00 => { + operation = FPMaxMinOp_MAX + }, + 0b01 => { + operation = FPMaxMinOp_MIN + }, + 0b10 => { + operation = FPMaxMinOp_MAXNUM + }, + 0b11 => { + operation = FPMaxMinOp_MINNUM + } + }; + let operation = operation; + execute_aarch64_instrs_float_arithmetic_max_min(d, esize, m, n, operation) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 350) = { + SEE = 350; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fmaxnm_float_aarch64_instrs_float_arithmetic_max_min(Rd, Rn, op, Rm, ftype) +} + +val decode_fmin_float_aarch64_instrs_float_arithmetic_max_min : (bits(5), bits(5), bits(2), bits(5), bits(2)) -> unit + +function decode_fmin_float_aarch64_instrs_float_arithmetic_max_min (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + operation : FPMaxMinOp = undefined; + match op { + 0b00 => { + operation = FPMaxMinOp_MAX + }, + 0b01 => { + operation = FPMaxMinOp_MIN + }, + 0b10 => { + operation = FPMaxMinOp_MAXNUM + }, + 0b11 => { + operation = FPMaxMinOp_MINNUM + } + }; + let operation = operation; + execute_aarch64_instrs_float_arithmetic_max_min(d, esize, m, n, operation) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 351) = { + SEE = 351; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fmin_float_aarch64_instrs_float_arithmetic_max_min(Rd, Rn, op, Rm, ftype) +} + +val decode_fminnm_float_aarch64_instrs_float_arithmetic_max_min : (bits(5), bits(5), bits(2), bits(5), bits(2)) -> unit + +function decode_fminnm_float_aarch64_instrs_float_arithmetic_max_min (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + operation : FPMaxMinOp = undefined; + match op { + 0b00 => { + operation = FPMaxMinOp_MAX + }, + 0b01 => { + operation = FPMaxMinOp_MIN + }, + 0b10 => { + operation = FPMaxMinOp_MAXNUM + }, + 0b11 => { + operation = FPMaxMinOp_MINNUM + } + }; + let operation = operation; + execute_aarch64_instrs_float_arithmetic_max_min(d, esize, m, n, operation) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 352) = { + SEE = 352; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fminnm_float_aarch64_instrs_float_arithmetic_max_min(Rd, Rn, op, Rm, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 : forall 'd 'datasize 'elements 'esize 'm ('minimum : Bool) 'n ('pair : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), bool('minimum), int('n), bool('pair)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 (d, datasize, elements, esize, m, minimum, n, pair) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + let concat : bits(2 * 'datasize) = operand2 @ operand1; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + if pair then { + element1 = Elem_read(concat, 2 * e, esize); + element2 = Elem_read(concat, 2 * e + 1, esize) + } else { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize) + }; + if minimum then { + result = Elem_set(result, e, esize, FPMin(element1, element2, FPCR_read())) + } else { + result = Elem_set(result, e, esize, FPMax(element1, element2, FPCR_read())) + } + }; + V_set(d, datasize) = result +} + +val decode_fmax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 (Rd, Rn, Rm, o1, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 353) = { + SEE = 353; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(Rd, Rn, Rm, o1, U, Q) +} + +val decode_fmax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 354) = { + SEE = 354; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985(Rd, Rn, Rm, sz, o1, U, Q) +} + +val decode_fmaxp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 (Rd, Rn, Rm, o1, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 355) = { + SEE = 355; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(Rd, Rn, Rm, o1, U, Q) +} + +val decode_fmaxp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 356) = { + SEE = 356; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985(Rd, Rn, Rm, sz, o1, U, Q) +} + +val decode_fmin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 (Rd, Rn, Rm, o1, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 357) = { + SEE = 357; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(Rd, Rn, Rm, o1, U, Q) +} + +val decode_fmin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 358) = { + SEE = 358; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985(Rd, Rn, Rm, sz, o1, U, Q) +} + +val decode_fminp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fminp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985 (Rd, Rn, Rm, o1, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 359) = { + SEE = 359; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(Rd, Rn, Rm, o1, U, Q) +} + +val decode_fminp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fminp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_1985(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 360) = { + SEE = 360; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_1985(Rd, Rn, Rm, sz, o1, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 : forall 'd 'datasize 'elements 'esize 'm ('minimum : Bool) 'n ('pair : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), bool('minimum), int('n), bool('pair)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 (d, datasize, elements, esize, m, minimum, n, pair) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + let concat : bits(2 * 'datasize) = operand2 @ operand1; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + if pair then { + element1 = Elem_read(concat, 2 * e, esize); + element2 = Elem_read(concat, 2 * e + 1, esize) + } else { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize) + }; + if minimum then { + result = Elem_set(result, e, esize, FPMinNum(element1, element2, FPCR_read())) + } else { + result = Elem_set(result, e, esize, FPMaxNum(element1, element2, FPCR_read())) + } + }; + V_set(d, datasize) = result +} + +val decode_fmaxnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 (Rd, Rn, Rm, a, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = a == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 361) = { + SEE = 361; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let a = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(Rd, Rn, Rm, a, U, Q) +} + +val decode_fmaxnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 362) = { + SEE = 362; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008(Rd, Rn, Rm, sz, o1, U, Q) +} + +val decode_fmaxnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 (Rd, Rn, Rm, a, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = a == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 363) = { + SEE = 363; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let a = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(Rd, Rn, Rm, a, U, Q) +} + +val decode_fmaxnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 364) = { + SEE = 364; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008(Rd, Rn, Rm, sz, o1, U, Q) +} + +val decode_fminnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fminnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 (Rd, Rn, Rm, a, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = a == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 365) = { + SEE = 365; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let a = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(Rd, Rn, Rm, a, U, Q) +} + +val decode_fminnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fminnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 366) = { + SEE = 366; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminnm_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008(Rd, Rn, Rm, sz, o1, U, Q) +} + +val decode_fminnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fminnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008 (Rd, Rn, Rm, a, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = a == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 367) = { + SEE = 367; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let a = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(Rd, Rn, Rm, a, U, Q) +} + +val decode_fminnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fminnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008 (Rd, Rn, Rm, sz, o1, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let pair : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp16_2008(d, datasize, elements, esize, m, minimum, n, pair) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 368) = { + SEE = 368; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminnmp_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_fp_2008(Rd, Rn, Rm, sz, o1, U, Q) +} + +val execute_aarch64_instrs_vector_reduce_fp16_maxnm_sisd : forall 'd 'datasize 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('n), ReduceOp) -> unit + +function execute_aarch64_instrs_vector_reduce_fp16_maxnm_sisd (d, datasize, esize, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + let altfp : bool = false; + assert(constraint('datasize >= 'esize)); + V_set(d, esize) = Reduce__1(op, operand, esize, altfp) +} + +val decode_fmaxnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_maxnm_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmaxnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_maxnm_sisd (Rd, Rn, sz, o1) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 369) = { + SEE = 369; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fmaxnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_maxnm_sisd(Rd, Rn, sz, o1) +} + +val decode_fmaxnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp_maxnm_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmaxnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp_maxnm_sisd (Rd, Rn, sz, o1) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 370) = { + SEE = 370; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fmaxnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp_maxnm_sisd(Rd, Rn, sz, o1) +} + +val decode_fminnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_maxnm_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fminnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_maxnm_sisd (Rd, Rn, sz, o1) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 371) = { + SEE = 371; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fminnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_maxnm_sisd(Rd, Rn, sz, o1) +} + +val decode_fminnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp_maxnm_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fminnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp_maxnm_sisd (Rd, Rn, sz, o1) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 372) = { + SEE = 372; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fminnmp_advsimd_pair_aarch64_instrs_vector_reduce_fp_maxnm_sisd(Rd, Rn, sz, o1) +} + +val execute_aarch64_instrs_vector_reduce_fp16_maxnm_simd : forall 'd 'datasize 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('n), ReduceOp) -> unit + +function execute_aarch64_instrs_vector_reduce_fp16_maxnm_simd (d, datasize, esize, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + let altfp : bool = false; + V_set(d, esize) = Reduce__1(op, operand, esize, altfp) +} + +val decode_fmaxnmv_advsimd_aarch64_instrs_vector_reduce_fp16_maxnm_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmaxnmv_advsimd_aarch64_instrs_vector_reduce_fp16_maxnm_simd (Rd, Rn, o1, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 373) = { + SEE = 373; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxnmv_advsimd_aarch64_instrs_vector_reduce_fp16_maxnm_simd(Rd, Rn, o1, Q) +} + +val decode_fmaxnmv_advsimd_aarch64_instrs_vector_reduce_fp_maxnm_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxnmv_advsimd_aarch64_instrs_vector_reduce_fp_maxnm_simd (Rd, Rn, sz, o1, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) != 0b01 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 374) = { + SEE = 374; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxnmv_advsimd_aarch64_instrs_vector_reduce_fp_maxnm_simd(Rd, Rn, sz, o1, Q) +} + +val decode_fminnmv_advsimd_aarch64_instrs_vector_reduce_fp16_maxnm_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fminnmv_advsimd_aarch64_instrs_vector_reduce_fp16_maxnm_simd (Rd, Rn, o1, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 375) = { + SEE = 375; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminnmv_advsimd_aarch64_instrs_vector_reduce_fp16_maxnm_simd(Rd, Rn, o1, Q) +} + +val decode_fminnmv_advsimd_aarch64_instrs_vector_reduce_fp_maxnm_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fminnmv_advsimd_aarch64_instrs_vector_reduce_fp_maxnm_simd (Rd, Rn, sz, o1, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) != 0b01 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMINNUM else ReduceOp_FMAXNUM; + execute_aarch64_instrs_vector_reduce_fp16_maxnm_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 376) = { + SEE = 376; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminnmv_advsimd_aarch64_instrs_vector_reduce_fp_maxnm_simd(Rd, Rn, sz, o1, Q) +} + +val execute_aarch64_instrs_vector_reduce_fp16_max_sisd : forall 'd 'datasize 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('n), ReduceOp) -> unit + +function execute_aarch64_instrs_vector_reduce_fp16_max_sisd (d, datasize, esize, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + assert(constraint('datasize >= 'esize)); + V_set(d, esize) = Reduce(op, operand, esize) +} + +val decode_fmaxp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_max_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmaxp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_max_sisd (Rd, Rn, sz, o1) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 377) = { + SEE = 377; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fmaxp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_max_sisd(Rd, Rn, sz, o1) +} + +val decode_fmaxp_advsimd_pair_aarch64_instrs_vector_reduce_fp_max_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmaxp_advsimd_pair_aarch64_instrs_vector_reduce_fp_max_sisd (Rd, Rn, sz, o1) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 378) = { + SEE = 378; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fmaxp_advsimd_pair_aarch64_instrs_vector_reduce_fp_max_sisd(Rd, Rn, sz, o1) +} + +val decode_fminp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_max_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fminp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_max_sisd (Rd, Rn, sz, o1) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 379) = { + SEE = 379; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fminp_advsimd_pair_aarch64_instrs_vector_reduce_fp16_max_sisd(Rd, Rn, sz, o1) +} + +val decode_fminp_advsimd_pair_aarch64_instrs_vector_reduce_fp_max_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fminp_advsimd_pair_aarch64_instrs_vector_reduce_fp_max_sisd (Rd, Rn, sz, o1) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize * 2; + let 'elements = 2; + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_sisd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 380) = { + SEE = 380; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + decode_fminp_advsimd_pair_aarch64_instrs_vector_reduce_fp_max_sisd(Rd, Rn, sz, o1) +} + +val execute_aarch64_instrs_vector_reduce_fp16_max_simd : forall 'd 'datasize 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('n), ReduceOp) -> unit + +function execute_aarch64_instrs_vector_reduce_fp16_max_simd (d, datasize, esize, n, op) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + V_set(d, esize) = Reduce(op, operand, esize) +} + +val decode_fmaxv_advsimd_aarch64_instrs_vector_reduce_fp16_max_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmaxv_advsimd_aarch64_instrs_vector_reduce_fp16_max_simd (Rd, Rn, o1, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 381) = { + SEE = 381; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxv_advsimd_aarch64_instrs_vector_reduce_fp16_max_simd(Rd, Rn, o1, Q) +} + +val decode_fmaxv_advsimd_aarch64_instrs_vector_reduce_fp_max_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmaxv_advsimd_aarch64_instrs_vector_reduce_fp_max_simd (Rd, Rn, sz, o1, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) != 0b01 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 382) = { + SEE = 382; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmaxv_advsimd_aarch64_instrs_vector_reduce_fp_max_simd(Rd, Rn, sz, o1, Q) +} + +val decode_fminv_advsimd_aarch64_instrs_vector_reduce_fp16_max_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fminv_advsimd_aarch64_instrs_vector_reduce_fp16_max_simd (Rd, Rn, o1, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 383) = { + SEE = 383; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminv_advsimd_aarch64_instrs_vector_reduce_fp16_max_simd(Rd, Rn, o1, Q) +} + +val decode_fminv_advsimd_aarch64_instrs_vector_reduce_fp_max_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fminv_advsimd_aarch64_instrs_vector_reduce_fp_max_simd (Rd, Rn, sz, o1, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) != 0b01 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let op : ReduceOp = if o1 == 0b1 then ReduceOp_FMIN else ReduceOp_FMAX; + execute_aarch64_instrs_vector_reduce_fp16_max_simd(d, datasize, esize, n, op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 384) = { + SEE = 384; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let o1 = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fminv_advsimd_aarch64_instrs_vector_reduce_fp_max_simd(Rd, Rn, sz, o1, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd (d, datasize, elements, esize, idxdsize, index, m, n, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + let operand3 : bits('datasize) = V_read(d, datasize); + element1 : bits('esize) = undefined; + let element2 : bits('esize) = Elem_read(operand2, index, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + if sub_op then { + element1 = FPNeg(element1) + }; + result = Elem_set(result, e, esize, FPMulAdd(Elem_read(operand3, e, esize), element1, element2, fpcr)) + }; + V_set(d, 128) = result +} + +val decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1)) -> unit + +function decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd (Rd, Rn, H, o2, Rm, M, L) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 385) = { + SEE = 385; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(Rd, Rn, H, o2, Rm, M, L) +} + +val decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_sisd (Rd, Rn, H, o2, Rm, M, L, sz) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 386) = { + SEE = 386; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_sisd(Rd, Rn, H, o2, Rm, M, L, sz) +} + +val decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_simd (Rd, Rn, H, o2, Rm, M, L, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 387) = { + SEE = 387; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_simd(Rd, Rn, H, o2, Rm, M, L, Q) +} + +val decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_simd (Rd, Rn, H, o2, Rm, M, L, sz, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 388) = { + SEE = 388; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_simd(Rd, Rn, H, o2, Rm, M, L, sz, Q) +} + +val decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1)) -> unit + +function decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd (Rd, Rn, H, o2, Rm, M, L) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 389) = { + SEE = 389; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(Rd, Rn, H, o2, Rm, M, L) +} + +val decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_sisd (Rd, Rn, H, o2, Rm, M, L, sz) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 390) = { + SEE = 390; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_sisd(Rd, Rn, H, o2, Rm, M, L, sz) +} + +val decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_simd (Rd, Rn, H, o2, Rm, M, L, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 391) = { + SEE = 391; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_simd(Rd, Rn, H, o2, Rm, M, L, Q) +} + +val decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_simd (Rd, Rn, H, o2, Rm, M, L, sz, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 392) = { + SEE = 392; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_fp_simd(Rd, Rn, H, o2, Rm, M, L, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused : forall 'd 'datasize 'elements 'esize 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused (d, datasize, elements, esize, m, n, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + if sub_op then { + element1 = FPNeg(element1) + }; + result = Elem_set(result, e, esize, FPMulAdd(Elem_read(operand3, e, esize), element1, element2, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused (Rd, Rn, Rm, a, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = a == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 393) = { + SEE = 393; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let a = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused(Rd, Rn, Rm, a, Q) +} + +val decode_fmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_fused : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_fused (Rd, Rn, Rm, sz, op, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = op == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 394) = { + SEE = 394; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let op = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_fused(Rd, Rn, Rm, sz, op, Q) +} + +val decode_fmls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused (Rd, Rn, Rm, a, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = a == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 395) = { + SEE = 395; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let a = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused(Rd, Rn, Rm, a, Q) +} + +val decode_fmls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_fused : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_fused (Rd, Rn, Rm, sz, op, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = op == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_fused(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 396) = { + SEE = 396; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let op = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_fused(Rd, Rn, Rm, sz, op, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower : forall 'd 'datasize 'elements 'esize 'index 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'esize == 32 & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('index), int('m), int('n), int('part), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower (d, datasize, elements, esize, index, m, n, part, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits(div('datasize, 2)) = Vpart_read(n, part, DIV(datasize, 2)); + let operand2 : bits(128) = V_read(m, 128); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : bits(div('esize, 2)) = undefined; + let element2 : bits(div('esize, 2)) = Elem_read(operand2, index, DIV(esize, 2)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, DIV(esize, 2)); + if sub_op then { + element1 = FPNeg(element1) + }; + result = Elem_set(result, e, esize, FPMulAddH(Elem_read(operand3, e, esize), element1, element2, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower (Rd, Rn, H, S, Rm, M, L, sz, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(0b0 @ Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'index = UInt((H @ L) @ M); + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 0; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower(d, datasize, elements, esize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 397) = { + SEE = 397; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower(Rd, Rn, H, S, Rm, M, L, sz, Q) +} + +val decode_fmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_upper : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_upper (Rd, Rn, H, S, Rm, M, L, sz, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(0b0 @ Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'index = UInt((H @ L) @ M); + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower(d, datasize, elements, esize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 398) = { + SEE = 398; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_upper(Rd, Rn, H, S, Rm, M, L, sz, Q) +} + +val decode_fmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower (Rd, Rn, H, S, Rm, M, L, sz, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(0b0 @ Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'index = UInt((H @ L) @ M); + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 0; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower(d, datasize, elements, esize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 399) = { + SEE = 399; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower(Rd, Rn, H, S, Rm, M, L, sz, Q) +} + +val decode_fmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_upper : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_upper (Rd, Rn, H, S, Rm, M, L, sz, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(0b0 @ Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'index = UInt((H @ L) @ M); + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_lower(d, datasize, elements, esize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, bitone, bitone, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 400) = { + SEE = 400; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_mul_norounding_i_upper(Rd, Rn, H, S, Rm, M, L, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower : forall 'd 'datasize 'elements 'esize 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize == 32 & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower (d, datasize, elements, esize, m, n, part, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits(div('datasize, 2)) = Vpart_read(n, part, DIV(datasize, 2)); + let operand2 : bits(div('datasize, 2)) = Vpart_read(m, part, DIV(datasize, 2)); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : bits(div('esize, 2)) = undefined; + element2 : bits(div('esize, 2)) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, DIV(esize, 2)); + element2 = Elem_read(operand2, e, DIV(esize, 2)); + if sub_op then { + element1 = FPNeg(element1) + }; + result = Elem_set(result, e, esize, FPMulAddH(Elem_read(operand3, e, esize), element1, element2, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower (Rd, Rn, Rm, sz, S, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 0; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 401) = { + SEE = 401; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower(Rd, Rn, Rm, sz, S, Q) +} + +val decode_fmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_upper : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_upper (Rd, Rn, Rm, sz, S, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 402) = { + SEE = 402; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_upper(Rd, Rn, Rm, sz, S, Q) +} + +val decode_fmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower (Rd, Rn, Rm, sz, S, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 0; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 403) = { + SEE = 403; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower(Rd, Rn, Rm, sz, S, Q) +} + +val decode_fmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_upper : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_upper (Rd, Rn, Rm, sz, S, Q) = { + if not_bool(HaveFP16MulNoRoundingToFP32Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = S == 0b1; + let 'part = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_lower(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 404) = { + SEE = 404; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let S = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_mul_norounding_upper(Rd, Rn, Rm, sz, S, Q) +} + +val execute_aarch64_instrs_vector_fp16_movi : forall 'datasize 'rd, + (0 <= 'rd & 'rd <= 31 & 'datasize in {64, 128}). + (int('datasize), bits('datasize), int('rd)) -> unit + +function execute_aarch64_instrs_vector_fp16_movi (datasize, imm, rd) = { + CheckFPAdvSIMDEnabled64(); + V_set(rd, datasize) = imm +} + +val decode_fmov_advsimd_aarch64_instrs_vector_fp16_movi : (bits(5), bits(1), bits(1), bits(1), bits(1), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmov_advsimd_aarch64_instrs_vector_fp16_movi (Rd, h, g, f, e, d, c, b, a, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'rd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + let imm8 : bits(8) = ((((((a @ b) @ c) @ d) @ e) @ f) @ g) @ h; + let imm16 : bits(16) = ((([imm8[7]] @ not_vec([imm8[6]])) @ Replicate([imm8[6]], 2)) @ imm8[5 .. 0]) @ Zeros(6); + let imm : bits('datasize) = Replicate(imm16, DIV(datasize, 16)); + execute_aarch64_instrs_vector_fp16_movi(datasize, imm, rd) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 405) = { + SEE = 405; + let Rd = Slice(__opcode, 0, 5); + let h = Slice(__opcode, 5, 1); + let g = Slice(__opcode, 6, 1); + let f = Slice(__opcode, 7, 1); + let e = Slice(__opcode, 8, 1); + let d = Slice(__opcode, 9, 1); + let c = Slice(__opcode, 16, 1); + let b = Slice(__opcode, 17, 1); + let a = Slice(__opcode, 18, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmov_advsimd_aarch64_instrs_vector_fp16_movi(Rd, h, g, f, e, d, c, b, a, Q) +} + +val decode_fmov_advsimd_aarch64_instrs_vector_logical : (bits(5), bits(1), bits(1), bits(1), bits(1), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmov_advsimd_aarch64_instrs_vector_logical (Rd, h, g, f, e, d, cmode, c, b, a, op, Q) = { + let 'rd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + operation : ImmediateOp = undefined; + match cmode @ op { + [bitzero, _, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitzero, _, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitzero, _, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitzero, _, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitzero, _, bitzero, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitzero, _, bitzero, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitzero, _, bitone, bitzero] => { + operation = ImmediateOp_ORR + }, + [bitone, bitzero, _, bitone, bitone] => { + operation = ImmediateOp_BIC + }, + [bitone, bitone, bitzero, _, bitzero] => { + operation = ImmediateOp_MOVI + }, + [bitone, bitone, bitzero, _, bitone] => { + operation = ImmediateOp_MVNI + }, + [bitone, bitone, bitone, bitzero, _] => { + operation = ImmediateOp_MOVI + }, + 0b11110 => { + operation = ImmediateOp_MOVI + }, + 0b11111 => { + if Q == 0b0 then { + throw(Error_Undefined()) + }; + operation = ImmediateOp_MOVI + } + }; + let operation = operation; + let imm64 : bits(64) = AdvSIMDExpandImm(op, cmode, ((((((a @ b) @ c) @ d) @ e) @ f) @ g) @ h); + let imm : bits('datasize) = Replicate(imm64, DIV(datasize, 64)); + execute_aarch64_instrs_vector_fp16_movi(datasize, imm, rd) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, _, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 406) = { + SEE = 406; + let Rd = Slice(__opcode, 0, 5); + let h = Slice(__opcode, 5, 1); + let g = Slice(__opcode, 6, 1); + let f = Slice(__opcode, 7, 1); + let e = Slice(__opcode, 8, 1); + let d = Slice(__opcode, 9, 1); + let cmode = Slice(__opcode, 12, 4); + let c = Slice(__opcode, 16, 1); + let b = Slice(__opcode, 17, 1); + let a = Slice(__opcode, 18, 1); + let op = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmov_advsimd_aarch64_instrs_vector_logical(Rd, h, g, f, e, d, cmode, c, b, a, op, Q) +} + +val execute_aarch64_instrs_float_move_fp_imm : forall 'd 'datasize, + ('datasize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bits('datasize)) -> unit + +function execute_aarch64_instrs_float_move_fp_imm (d, datasize, imm) = { + CheckFPEnabled64(); + V_set(d, datasize) = imm +} + +val decode_fmov_float_imm_aarch64_instrs_float_move_fp_imm : (bits(5), bits(8), bits(2)) -> unit + +function decode_fmov_float_imm_aarch64_instrs_float_move_fp_imm (Rd, imm8, ftype) = { + let 'd = UInt(Rd); + datasize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + datasize = 32 + }, + 0b01 => { + datasize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + datasize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'datasize = datasize; + let imm : bits('datasize) = VFPExpandImm(imm8, datasize); + execute_aarch64_instrs_float_move_fp_imm(d, datasize, imm) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _] as __opcode)) if SEE < 407) = { + SEE = 407; + let Rd = Slice(__opcode, 0, 5); + let imm8 = Slice(__opcode, 13, 8); + let ftype = Slice(__opcode, 22, 2); + decode_fmov_float_imm_aarch64_instrs_float_move_fp_imm(Rd, imm8, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_product : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_product (d, datasize, elements, esize, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + result = Elem_set(result, e, esize, FPMul(element1, element2, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fmul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_product : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_fmul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_product (Rd, Rn, Rm, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_product(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 408) = { + SEE = 408; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_fmul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_product(Rd, Rn, Rm, Q) +} + +val decode_fmul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_product : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_product (Rd, Rn, Rm, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_product(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 409) = { + SEE = 409; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_product(Rd, Rn, Rm, sz, Q) +} + +val execute_aarch64_instrs_float_arithmetic_mul_product : forall 'd 'esize 'm 'n ('negated : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), int('m), int('n), bool('negated)) -> unit + +function execute_aarch64_instrs_float_arithmetic_mul_product (d, esize, m, n, negated) = { + CheckFPEnabled64(); + let operand1 : bits('esize) = V_read(n, esize); + let operand2 : bits('esize) = V_read(m, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + product : bits('esize) = FPMul(operand1, operand2, fpcr); + if negated then { + product = FPNeg(product) + }; + result = Elem_set(result, 0, esize, product); + V_set(d, 128) = result +} + +val decode_fmul_float_aarch64_instrs_float_arithmetic_mul_product : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_fmul_float_aarch64_instrs_float_arithmetic_mul_product (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let negated : bool = op == 0b1; + execute_aarch64_instrs_float_arithmetic_mul_product(d, esize, m, n, negated) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 410) = { + SEE = 410; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fmul_float_aarch64_instrs_float_arithmetic_mul_product(Rd, Rn, op, Rm, ftype) +} + +val decode_fnmul_float_aarch64_instrs_float_arithmetic_mul_product : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_fnmul_float_aarch64_instrs_float_arithmetic_mul_product (Rd, Rn, op, Rm, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + let negated : bool = op == 0b1; + execute_aarch64_instrs_float_arithmetic_mul_product(d, esize, m, n, negated) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 411) = { + SEE = 411; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let ftype = Slice(__opcode, 22, 2); + decode_fnmul_float_aarch64_instrs_float_arithmetic_mul_product(Rd, Rn, op, Rm, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm ('mulx_op : Bool) 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), bool('mulx_op), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd (d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + element1 : bits('esize) = undefined; + let element2 : bits('esize) = Elem_read(operand2, index, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + if mulx_op then { + result = Elem_set(result, e, esize, FPMulX(element1, element2, fpcr)) + } else { + result = Elem_set(result, e, esize, FPMul(element1, element2, fpcr)) + } + }; + V_set(d, 128) = result +} + +val decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd (Rd, Rn, H, Rm, M, L, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 412) = { + SEE = 412; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let U = Slice(__opcode, 29, 1); + decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(Rd, Rn, H, Rm, M, L, U) +} + +val decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_sisd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_sisd (Rd, Rn, H, Rm, M, L, sz, U) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 413) = { + SEE = 413; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_sisd(Rd, Rn, H, Rm, M, L, sz, U) +} + +val decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_simd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_simd (Rd, Rn, H, Rm, M, L, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 414) = { + SEE = 414; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_simd(Rd, Rn, H, Rm, M, L, U, Q) +} + +val decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_simd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_simd (Rd, Rn, H, Rm, M, L, sz, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 415) = { + SEE = 415; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_simd(Rd, Rn, H, Rm, M, L, sz, U, Q) +} + +val decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1)) -> unit + +function decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd (Rd, Rn, H, Rm, M, L, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 416) = { + SEE = 416; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let U = Slice(__opcode, 29, 1); + decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(Rd, Rn, H, Rm, M, L, U) +} + +val decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_sisd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_sisd (Rd, Rn, H, Rm, M, L, sz, U) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 417) = { + SEE = 417; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_sisd(Rd, Rn, H, Rm, M, L, sz, U) +} + +val decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_simd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_simd (Rd, Rn, H, Rm, M, L, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'index = UInt((H @ L) @ M); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 418) = { + SEE = 418; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_simd(Rd, Rn, H, Rm, M, L, U, Q) +} + +val decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_simd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_simd (Rd, Rn, H, Rm, M, L, sz, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 3) = undefined; + let Rmhi : bits(1) = M; + match sz @ L { + [bitzero, _] => { + index = UInt(H @ L) + }, + 0b10 => { + index = UInt(H) + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let mulx_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_fp16_sisd(d, datasize, elements, esize, idxdsize, index, m, mulx_op, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 419) = { + SEE = 419; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmulx_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_fp_simd(Rd, Rn, H, Rm, M, L, sz, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd (d, datasize, elements, esize, m, n) = { + if elements == 1 then { + CheckFPEnabled64() + } else { + CheckFPAdvSIMDEnabled64() + }; + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + result = Elem_set(result, e, esize, FPMulX(element1, element2, fpcr)) + }; + V_set(d, 128) = result +} + +val decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd : (bits(5), bits(5), bits(5)) -> unit + +function decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd (Rd, Rn, Rm) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 420) = { + SEE = 420; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd(Rd, Rn, Rm) +} + +val decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_extended_sisd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_extended_sisd (Rd, Rn, Rm, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 421) = { + SEE = 421; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_extended_sisd(Rd, Rn, Rm, sz) +} + +val decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_simd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_simd (Rd, Rn, Rm, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 422) = { + SEE = 422; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_simd(Rd, Rn, Rm, Q) +} + +val decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_extended_simd : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_extended_simd (Rd, Rn, Rm, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp16_extended_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 423) = { + SEE = 423; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fmulx_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_fp_extended_simd(Rd, Rn, Rm, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd (d, datasize, elements, esize, n) = { + if elements == 1 then { + CheckFPEnabled64() + } else { + CheckFPAdvSIMDEnabled64() + }; + let operand : bits('datasize) = V_read(n, datasize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + element : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPRecipEstimate(element, FPCR_read())) + }; + V_set(d, 128) = result +} + +val decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd : (bits(5), bits(5)) -> unit + +function decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd (Rd, Rn) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 424) = { + SEE = 424; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd(Rd, Rn) +} + +val decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_float_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_float_sisd (Rd, Rn, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 425) = { + SEE = 425; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_float_sisd(Rd, Rn, sz) +} + +val decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_simd : (bits(5), bits(5), bits(1)) -> unit + +function decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_simd (Rd, Rn, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 426) = { + SEE = 426; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Q = Slice(__opcode, 30, 1); + decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_simd(Rd, Rn, Q) +} + +val decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_float_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_float_simd (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_recip_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 427) = { + SEE = 427; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_frecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_float_simd(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd (d, datasize, elements, esize, m, n) = { + if elements == 1 then { + CheckFPEnabled64() + } else { + CheckFPAdvSIMDEnabled64() + }; + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + result = Elem_set(result, e, esize, FPRecipStepFused(element1, element2)) + }; + V_set(d, 128) = result +} + +val decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd : (bits(5), bits(5), bits(5)) -> unit + +function decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd (Rd, Rn, Rm) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 428) = { + SEE = 428; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd(Rd, Rn, Rm) +} + +val decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_sisd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_sisd (Rd, Rn, Rm, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 429) = { + SEE = 429; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_sisd(Rd, Rn, Rm, sz) +} + +val decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_simd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_simd (Rd, Rn, Rm, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 430) = { + SEE = 430; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_simd(Rd, Rn, Rm, Q) +} + +val decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_simd : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_simd (Rd, Rn, Rm, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_recps_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 431) = { + SEE = 431; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_frecps_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_recps_simd(Rd, Rn, Rm, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_special_frecpx_fp16 : forall 'd 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_special_frecpx_fp16 (d, esize, n) = { + CheckFPEnabled64(); + let operand : bits('esize) = V_read(n, esize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + result = Elem_set(result, 0, esize, FPRecpX(operand, fpcr)); + V_set(d, 128) = result +} + +val decode_frecpx_advsimd_aarch64_instrs_vector_arithmetic_unary_special_frecpx_fp16 : (bits(5), bits(5)) -> unit + +function decode_frecpx_advsimd_aarch64_instrs_vector_arithmetic_unary_special_frecpx_fp16 (Rd, Rn) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + execute_aarch64_instrs_vector_arithmetic_unary_special_frecpx_fp16(d, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 432) = { + SEE = 432; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_frecpx_advsimd_aarch64_instrs_vector_arithmetic_unary_special_frecpx_fp16(Rd, Rn) +} + +val decode_frecpx_advsimd_aarch64_instrs_vector_arithmetic_unary_special_frecpx : (bits(5), bits(5), bits(1)) -> unit + +function decode_frecpx_advsimd_aarch64_instrs_vector_arithmetic_unary_special_frecpx (Rd, Rn, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + execute_aarch64_instrs_vector_arithmetic_unary_special_frecpx_fp16(d, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 433) = { + SEE = 433; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + decode_frecpx_advsimd_aarch64_instrs_vector_arithmetic_unary_special_frecpx(Rd, Rn, sz) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 : forall 'd 'datasize 'elements 'esize 'intsize 'n, + (0 <= 'n & 'n <= 31 & 'intsize in {32, 64} & 'esize in {32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('intsize), int('n), FPRounding) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 (d, datasize, elements, esize, intsize, n, rounding) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPRoundIntN(element, FPCR_read(), rounding, intsize)) + }; + V_set(d, datasize) = result +} + +val decode_frint32x_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frint32x_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 (Rd, Rn, op, sz, U, Q) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'intsize = if op == 0b0 then 32 else 64; + let rounding : FPRounding = if U == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(d, datasize, elements, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 434) = { + SEE = 434; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frint32x_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(Rd, Rn, op, sz, U, Q) +} + +val decode_frint32z_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frint32z_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 (Rd, Rn, op, sz, U, Q) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'intsize = if op == 0b0 then 32 else 64; + let rounding : FPRounding = if U == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(d, datasize, elements, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 435) = { + SEE = 435; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frint32z_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(Rd, Rn, op, sz, U, Q) +} + +val decode_frint64x_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frint64x_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 (Rd, Rn, op, sz, U, Q) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'intsize = if op == 0b0 then 32 else 64; + let rounding : FPRounding = if U == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(d, datasize, elements, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 436) = { + SEE = 436; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frint64x_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(Rd, Rn, op, sz, U, Q) +} + +val decode_frint64z_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frint64z_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64 (Rd, Rn, op, sz, U, Q) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'intsize = if op == 0b0 then 32 else 64; + let rounding : FPRounding = if U == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(d, datasize, elements, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 437) = { + SEE = 437; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frint64z_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round_frint_32_64(Rd, Rn, op, sz, U, Q) +} + +val execute_aarch64_instrs_float_arithmetic_round_frint_32_64 : forall 'd 'esize 'intsize 'n, + (0 <= 'n & 'n <= 31 & 'intsize in {32, 64} & 'esize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), int('intsize), int('n), FPRounding) -> unit + +function execute_aarch64_instrs_float_arithmetic_round_frint_32_64 (d, esize, intsize, n, rounding) = { + CheckFPEnabled64(); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + let operand : bits('esize) = V_read(n, esize); + result = Elem_set(result, 0, esize, FPRoundIntN(operand, fpcr, rounding, intsize)); + V_set(d, 128) = result +} + +val decode_frint32x_float_aarch64_instrs_float_arithmetic_round_frint_32_64 : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_frint32x_float_aarch64_instrs_float_arithmetic_round_frint_32_64 (Rd, Rn, op, ftype) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {32, 64} = 32; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + [bitone, _] => { + throw(Error_Undefined()) + } + }; + let 'esize = esize; + let 'intsize = if [op[1]] == 0b0 then 32 else 64; + let rounding : FPRounding = if [op[0]] == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_float_arithmetic_round_frint_32_64(d, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 438) = { + SEE = 438; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_frint32x_float_aarch64_instrs_float_arithmetic_round_frint_32_64(Rd, Rn, op, ftype) +} + +val decode_frint32z_float_aarch64_instrs_float_arithmetic_round_frint_32_64 : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_frint32z_float_aarch64_instrs_float_arithmetic_round_frint_32_64 (Rd, Rn, op, ftype) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {32, 64} = 32; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + [bitone, _] => { + throw(Error_Undefined()) + } + }; + let 'esize = esize; + let 'intsize = if [op[1]] == 0b0 then 32 else 64; + let rounding : FPRounding = if [op[0]] == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_float_arithmetic_round_frint_32_64(d, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 439) = { + SEE = 439; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_frint32z_float_aarch64_instrs_float_arithmetic_round_frint_32_64(Rd, Rn, op, ftype) +} + +val decode_frint64x_float_aarch64_instrs_float_arithmetic_round_frint_32_64 : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_frint64x_float_aarch64_instrs_float_arithmetic_round_frint_32_64 (Rd, Rn, op, ftype) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {32, 64} = 32; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + [bitone, _] => { + throw(Error_Undefined()) + } + }; + let 'esize = esize; + let 'intsize = if [op[1]] == 0b0 then 32 else 64; + let rounding : FPRounding = if [op[0]] == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_float_arithmetic_round_frint_32_64(d, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 440) = { + SEE = 440; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_frint64x_float_aarch64_instrs_float_arithmetic_round_frint_32_64(Rd, Rn, op, ftype) +} + +val decode_frint64z_float_aarch64_instrs_float_arithmetic_round_frint_32_64 : (bits(5), bits(5), bits(2), bits(2)) -> unit + +function decode_frint64z_float_aarch64_instrs_float_arithmetic_round_frint_32_64 (Rd, Rn, op, ftype) = { + if not_bool(HaveFrintExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {32, 64} = 32; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + [bitone, _] => { + throw(Error_Undefined()) + } + }; + let 'esize = esize; + let 'intsize = if [op[1]] == 0b0 then 32 else 64; + let rounding : FPRounding = if [op[0]] == 0b0 then FPRounding_ZERO else + FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_float_arithmetic_round_frint_32_64(d, esize, intsize, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 441) = { + SEE = 441; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 15, 2); + let ftype = Slice(__opcode, 22, 2); + decode_frint64z_float_aarch64_instrs_float_arithmetic_round_frint_32_64(Rd, Rn, op, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_fp16_round : forall 'd 'datasize 'elements 'esize ('exact : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), bool('exact), int('n), FPRounding) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_fp16_round (d, datasize, elements, esize, exact, n, rounding) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPRoundInt(element, FPCR_read(), rounding, exact)) + }; + V_set(d, datasize) = result +} + +val decode_frinta_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frinta_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 442) = { + SEE = 442; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frinta_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round(Rd, Rn, o1, o2, U, Q) +} + +val decode_frinta_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frinta_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 443) = { + SEE = 443; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frinta_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_frinti_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frinti_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 444) = { + SEE = 444; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frinti_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round(Rd, Rn, o1, o2, U, Q) +} + +val decode_frinti_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frinti_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 445) = { + SEE = 445; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frinti_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_frintm_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintm_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 446) = { + SEE = 446; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintm_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round(Rd, Rn, o1, o2, U, Q) +} + +val decode_frintm_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintm_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 447) = { + SEE = 447; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintm_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_frintn_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintn_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 448) = { + SEE = 448; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintn_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round(Rd, Rn, o1, o2, U, Q) +} + +val decode_frintn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 449) = { + SEE = 449; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintn_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_frintp_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintp_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 450) = { + SEE = 450; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintp_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round(Rd, Rn, o1, o2, U, Q) +} + +val decode_frintp_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintp_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 451) = { + SEE = 451; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintp_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_frintx_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintx_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 452) = { + SEE = 452; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintx_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round(Rd, Rn, o1, o2, U, Q) +} + +val decode_frintx_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintx_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 453) = { + SEE = 453; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintx_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round(Rd, Rn, o1, sz, o2, U, Q) +} + +val decode_frintz_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintz_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round (Rd, Rn, o1, o2, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 454) = { + SEE = 454; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintz_advsimd_aarch64_instrs_vector_arithmetic_unary_fp16_round(Rd, Rn, o1, o2, U, Q) +} + +val decode_frintz_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round : (bits(5), bits(5), bits(1), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_frintz_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round (Rd, Rn, o1, sz, o2, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + exact : bool = false; + rounding : FPRounding = undefined; + match (U @ o1) @ o2 { + [bitzero, _, _] => { + rounding = FPDecodeRounding(o1 @ o2) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_round(d, datasize, elements, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 455) = { + SEE = 455; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 12, 1); + let sz = Slice(__opcode, 22, 1); + let o2 = Slice(__opcode, 23, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_frintz_advsimd_aarch64_instrs_vector_arithmetic_unary_float_round(Rd, Rn, o1, sz, o2, U, Q) +} + +val execute_aarch64_instrs_float_arithmetic_round_frint : forall 'd 'esize ('exact : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('esize), bool('exact), int('n), FPRounding) -> unit + +function execute_aarch64_instrs_float_arithmetic_round_frint (d, esize, exact, n, rounding) = { + CheckFPEnabled64(); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + let operand : bits('esize) = V_read(n, esize); + result = Elem_set(result, 0, esize, FPRoundInt(operand, fpcr, rounding, exact)); + V_set(d, 128) = result +} + +val decode_frinta_float_aarch64_instrs_float_arithmetic_round_frint : (bits(5), bits(5), bits(3), bits(2)) -> unit + +function decode_frinta_float_aarch64_instrs_float_arithmetic_round_frint (Rd, Rn, rmode, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + exact : bool = false; + rounding : FPRounding = undefined; + match rmode { + [bitzero, _, _] => { + rounding = FPDecodeRounding(rmode[1 .. 0]) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_float_arithmetic_round_frint(d, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 456) = { + SEE = 456; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rmode = Slice(__opcode, 15, 3); + let ftype = Slice(__opcode, 22, 2); + decode_frinta_float_aarch64_instrs_float_arithmetic_round_frint(Rd, Rn, rmode, ftype) +} + +val decode_frinti_float_aarch64_instrs_float_arithmetic_round_frint : (bits(5), bits(5), bits(3), bits(2)) -> unit + +function decode_frinti_float_aarch64_instrs_float_arithmetic_round_frint (Rd, Rn, rmode, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + exact : bool = false; + rounding : FPRounding = undefined; + match rmode { + [bitzero, _, _] => { + rounding = FPDecodeRounding(rmode[1 .. 0]) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_float_arithmetic_round_frint(d, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 457) = { + SEE = 457; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rmode = Slice(__opcode, 15, 3); + let ftype = Slice(__opcode, 22, 2); + decode_frinti_float_aarch64_instrs_float_arithmetic_round_frint(Rd, Rn, rmode, ftype) +} + +val decode_frintm_float_aarch64_instrs_float_arithmetic_round_frint : (bits(5), bits(5), bits(3), bits(2)) -> unit + +function decode_frintm_float_aarch64_instrs_float_arithmetic_round_frint (Rd, Rn, rmode, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + exact : bool = false; + rounding : FPRounding = undefined; + match rmode { + [bitzero, _, _] => { + rounding = FPDecodeRounding(rmode[1 .. 0]) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_float_arithmetic_round_frint(d, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 458) = { + SEE = 458; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rmode = Slice(__opcode, 15, 3); + let ftype = Slice(__opcode, 22, 2); + decode_frintm_float_aarch64_instrs_float_arithmetic_round_frint(Rd, Rn, rmode, ftype) +} + +val decode_frintn_float_aarch64_instrs_float_arithmetic_round_frint : (bits(5), bits(5), bits(3), bits(2)) -> unit + +function decode_frintn_float_aarch64_instrs_float_arithmetic_round_frint (Rd, Rn, rmode, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + exact : bool = false; + rounding : FPRounding = undefined; + match rmode { + [bitzero, _, _] => { + rounding = FPDecodeRounding(rmode[1 .. 0]) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_float_arithmetic_round_frint(d, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 459) = { + SEE = 459; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rmode = Slice(__opcode, 15, 3); + let ftype = Slice(__opcode, 22, 2); + decode_frintn_float_aarch64_instrs_float_arithmetic_round_frint(Rd, Rn, rmode, ftype) +} + +val decode_frintp_float_aarch64_instrs_float_arithmetic_round_frint : (bits(5), bits(5), bits(3), bits(2)) -> unit + +function decode_frintp_float_aarch64_instrs_float_arithmetic_round_frint (Rd, Rn, rmode, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + exact : bool = false; + rounding : FPRounding = undefined; + match rmode { + [bitzero, _, _] => { + rounding = FPDecodeRounding(rmode[1 .. 0]) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_float_arithmetic_round_frint(d, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 460) = { + SEE = 460; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rmode = Slice(__opcode, 15, 3); + let ftype = Slice(__opcode, 22, 2); + decode_frintp_float_aarch64_instrs_float_arithmetic_round_frint(Rd, Rn, rmode, ftype) +} + +val decode_frintx_float_aarch64_instrs_float_arithmetic_round_frint : (bits(5), bits(5), bits(3), bits(2)) -> unit + +function decode_frintx_float_aarch64_instrs_float_arithmetic_round_frint (Rd, Rn, rmode, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + exact : bool = false; + rounding : FPRounding = undefined; + match rmode { + [bitzero, _, _] => { + rounding = FPDecodeRounding(rmode[1 .. 0]) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_float_arithmetic_round_frint(d, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 461) = { + SEE = 461; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rmode = Slice(__opcode, 15, 3); + let ftype = Slice(__opcode, 22, 2); + decode_frintx_float_aarch64_instrs_float_arithmetic_round_frint(Rd, Rn, rmode, ftype) +} + +val decode_frintz_float_aarch64_instrs_float_arithmetic_round_frint : (bits(5), bits(5), bits(3), bits(2)) -> unit + +function decode_frintz_float_aarch64_instrs_float_arithmetic_round_frint (Rd, Rn, rmode, ftype) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + esize : {16, 32, 64} = 16; + match ftype { + 0b00 => { + esize = 32 + }, + 0b01 => { + esize = 64 + }, + 0b10 => { + throw(Error_Undefined()) + }, + 0b11 => { + if HaveFP16Ext() then { + esize = 16 + } else { + throw(Error_Undefined()) + } + } + }; + let 'esize = esize; + exact : bool = false; + rounding : FPRounding = undefined; + match rmode { + [bitzero, _, _] => { + rounding = FPDecodeRounding(rmode[1 .. 0]) + }, + 0b100 => { + rounding = FPRounding_TIEAWAY + }, + 0b101 => { + throw(Error_Undefined()) + }, + 0b110 => { + rounding = FPRoundingMode(FPCR_read()); + exact = true + }, + 0b111 => { + rounding = FPRoundingMode(FPCR_read()) + } + }; + let rounding = rounding; + execute_aarch64_instrs_float_arithmetic_round_frint(d, esize, exact, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 462) = { + SEE = 462; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let rmode = Slice(__opcode, 15, 3); + let ftype = Slice(__opcode, 22, 2); + decode_frintz_float_aarch64_instrs_float_arithmetic_round_frint(Rd, Rn, rmode, ftype) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd (d, datasize, elements, esize, n) = { + if elements == 1 then { + CheckFPEnabled64() + } else { + CheckFPAdvSIMDEnabled64() + }; + let operand : bits('datasize) = V_read(n, datasize); + element : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPRSqrtEstimate(element, fpcr)) + }; + V_set(d, 128) = result +} + +val decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd : (bits(5), bits(5)) -> unit + +function decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd (Rd, Rn) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 463) = { + SEE = 463; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd(Rd, Rn) +} + +val decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_float_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_float_sisd (Rd, Rn, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 464) = { + SEE = 464; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_float_sisd(Rd, Rn, sz) +} + +val decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_simd : (bits(5), bits(5), bits(1)) -> unit + +function decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_simd (Rd, Rn, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 465) = { + SEE = 465; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Q = Slice(__opcode, 30, 1); + decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_simd(Rd, Rn, Q) +} + +val decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_float_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_float_simd (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_fp16_sisd(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 466) = { + SEE = 466; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_frsqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_float_simd(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd : forall 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd (d, datasize, elements, esize, m, n) = { + if elements == 1 then { + CheckFPEnabled64() + } else { + CheckFPAdvSIMDEnabled64() + }; + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(n, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + result = Elem_set(result, e, esize, FPRSqrtStepFused(element1, element2)) + }; + V_set(d, 128) = result +} + +val decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd : (bits(5), bits(5), bits(5)) -> unit + +function decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd (Rd, Rn, Rm) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 467) = { + SEE = 467; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd(Rd, Rn, Rm) +} + +val decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_sisd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_sisd (Rd, Rn, Rm, sz) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 468) = { + SEE = 468; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_sisd(Rd, Rn, Rm, sz) +} + +val decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_simd : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_simd (Rd, Rn, Rm, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 469) = { + SEE = 469; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_simd(Rd, Rn, Rm, Q) +} + +val decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_simd : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_simd (Rd, Rn, Rm, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_fp16_sisd(d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 470) = { + SEE = 470; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_frsqrts_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_rsqrts_simd(Rd, Rn, Rm, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_fp16 : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_fp16 (d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FPSqrt(element, FPCR_read())) + }; + V_set(d, datasize) = result +} + +val decode_fsqrt_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_fp16 : (bits(5), bits(5), bits(1)) -> unit + +function decode_fsqrt_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_fp16 (Rd, Rn, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_fp16(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 471) = { + SEE = 471; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Q = Slice(__opcode, 30, 1); + decode_fsqrt_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_fp16(Rd, Rn, Q) +} + +val decode_fsqrt_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fsqrt_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_fp16(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 472) = { + SEE = 472; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_fsqrt_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd : forall ('abs : Bool) 'd 'datasize 'elements 'esize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (bool('abs), int('d), int('datasize), int('elements), int('esize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd (abs, d, datasize, elements, esize, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + diff : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + diff = FPSub(element1, element2, fpcr); + result = Elem_set(result, e, esize, if abs then FPAbs(diff) else diff) + }; + V_set(d, datasize) = result +} + +val decode_fsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd : (bits(5), bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_fsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd (Rd, Rn, Rm, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let abs : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd(abs, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 473) = { + SEE = 473; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd(Rd, Rn, Rm, U, Q) +} + +val decode_fsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_simd : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_fsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_simd (Rd, Rn, Rm, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let abs : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp16_simd(abs, d, datasize, elements, esize, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 474) = { + SEE = 474; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_fsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_fp_simd(Rd, Rn, Rm, sz, U, Q) +} + +val execute_aarch64_instrs_memory_gcs_general_register : forall ('is_gcssttr : Bool) 'n 't, + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('is_gcssttr), int('n), int('t)) -> unit + +function execute_aarch64_instrs_memory_gcs_general_register (is_gcssttr, n, t) = { + address : bits(64) = undefined; + let effective_el : bits(2) = if not_bool(is_gcssttr) | AArch64_IsUnprivAccessPriv() then + PSTATE.EL + else + EL0; + if effective_el == PSTATE.EL then { + CheckGCSSTREnabled() + }; + let accdesc : AccessDescriptor = CreateAccDescGCS(effective_el, MemOp_STORE); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let data : bits(64) = X_read(t, 64); + Mem_set(address, 8, accdesc) = data +} + +val decode_gcsstr_aarch64_instrs_memory_gcs_general_register : (bits(5), bits(5), bits(3)) -> unit + +function decode_gcsstr_aarch64_instrs_memory_gcs_general_register (Rt, Rn, opc) = { + if not_bool(HaveGCS()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let is_gcssttr : bool = opc == 0b001; + execute_aarch64_instrs_memory_gcs_general_register(is_gcssttr, n, t) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 475) = { + SEE = 475; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + decode_gcsstr_aarch64_instrs_memory_gcs_general_register(Rt, Rn, opc) +} + +val decode_gcssttr_aarch64_instrs_memory_gcs_general_register : (bits(5), bits(5), bits(3)) -> unit + +function decode_gcssttr_aarch64_instrs_memory_gcs_general_register (Rt, Rn, opc) = { + if not_bool(HaveGCS()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let is_gcssttr : bool = opc == 0b001; + execute_aarch64_instrs_memory_gcs_general_register(is_gcssttr, n, t) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 476) = { + SEE = 476; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + decode_gcssttr_aarch64_instrs_memory_gcs_general_register(Rt, Rn, opc) +} + +val execute_aarch64_instrs_integer_tags_mcinserttagmask : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_tags_mcinserttagmask (d, m, n) = { + let address : bits(64) = if n == 31 then SP_read() else X_read(n, 64); + mask : bits(64) = X_read(m, 64); + let tag : bits(4) = AArch64_AllocationTagFromAddress(address); + mask[UInt(tag)] = Bit(0b1); + X_set(d, 64) = mask +} + +val decode_gmi_aarch64_instrs_integer_tags_mcinserttagmask : (bits(5), bits(5), bits(5)) -> unit + +function decode_gmi_aarch64_instrs_integer_tags_mcinserttagmask (Xd, Xn, Xm) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Xd); + let 'n = UInt(Xn); + let 'm = UInt(Xm); + execute_aarch64_instrs_integer_tags_mcinserttagmask(d, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 477) = { + SEE = 477; + let Xd = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let Xm = Slice(__opcode, 16, 5); + decode_gmi_aarch64_instrs_integer_tags_mcinserttagmask(Xd, Xn, Xm) +} + +val execute_aarch64_instrs_system_exceptions_debug_halt : unit -> unit + +function execute_aarch64_instrs_system_exceptions_debug_halt () = { + let is_async : bool = false; + Halt__1(DebugHalt_HaltInstruction, is_async) +} + +val decode_hlt_aarch64_instrs_system_exceptions_debug_halt : bits(16) -> unit + +function decode_hlt_aarch64_instrs_system_exceptions_debug_halt imm16 = { + if EDSCR_read()[HDE] == 0b0 | not_bool(HaltingAllowed()) then { + throw(Error_Undefined()) + }; + if HaveBTIExt() then { + SetBTypeCompatible(true) + }; + execute_aarch64_instrs_system_exceptions_debug_halt() +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero] as __opcode)) if SEE < 478) = { + SEE = 478; + let imm16 = Slice(__opcode, 5, 16); + decode_hlt_aarch64_instrs_system_exceptions_debug_halt(imm16) +} + +val execute_aarch64_instrs_system_exceptions_runtime_hvc : bits(16) -> unit + +function execute_aarch64_instrs_system_exceptions_runtime_hvc imm = { + if (not_bool(HaveEL(EL2)) | PSTATE.EL == EL0) | PSTATE.EL == EL1 & not_bool(EL2Enabled()) then { + throw(Error_Undefined()) + }; + let hvc_enable : bits(1) = if HaveEL(EL3) then SCR_EL3[HCE] else + not_vec(HCR_EL2[HCD]); + if hvc_enable == 0b0 then { + throw(Error_Undefined()) + } else { + AArch64_CallHypervisor(imm) + } +} + +val decode_hvc_aarch64_instrs_system_exceptions_runtime_hvc : bits(16) -> unit + +function decode_hvc_aarch64_instrs_system_exceptions_runtime_hvc imm16 = { + let imm : bits(16) = imm16; + execute_aarch64_instrs_system_exceptions_runtime_hvc(imm) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero] as __opcode)) if SEE < 479) = { + SEE = 479; + let imm16 = Slice(__opcode, 5, 16); + decode_hvc_aarch64_instrs_system_exceptions_runtime_hvc(imm16) +} + +val execute_aarch64_instrs_vector_transfer_vector_insert : forall 'd 'dst_index 'esize 'idxdsize 'n 'src_index, + (0 <= 'n & 'n <= 31 & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64, 128, 256} & 0 <= 'd & 'd <= 31). + (int('d), int('dst_index), int('esize), int('idxdsize), int('n), int('src_index)) -> unit + +function execute_aarch64_instrs_vector_transfer_vector_insert (d, dst_index, esize, idxdsize, n, src_index) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('idxdsize) = V_read(n, idxdsize); + result : bits(128) = V_read(d, 128); + result = Elem_set(result, dst_index, esize, Elem_read(operand, src_index, esize)); + V_set(d, 128) = result +} + +val decode_ins_advsimd_elt_aarch64_instrs_vector_transfer_vector_insert : (bits(5), bits(5), bits(4), bits(5)) -> unit + +function decode_ins_advsimd_elt_aarch64_instrs_vector_transfer_vector_insert (Rd, Rn, imm4, imm5) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'size = LowestSetBit(imm5); + if size > 3 then { + throw(Error_Undefined()) + }; + assert(constraint(0 <= 'size + 1)); + let 'dst_index = UInt(imm5[4 .. size + 1]); + assert(constraint(0 <= 'size)); + let 'src_index = UInt(imm4[3 .. size]); + let 'idxdsize = if [imm4[3]] == 0b1 then 128 else 64; + let 'esize = (8 << size); + match esize { + 8 => { + match idxdsize { + 64 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 8, 64, n, src_index) + }, + 128 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 8, 128, n, src_index) + }, + _ => { + assert(false) + } + } + }, + 16 => { + match idxdsize { + 64 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 16, 64, n, src_index) + }, + 128 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 16, 128, n, src_index) + }, + _ => { + assert(false) + } + } + }, + 32 => { + match idxdsize { + 64 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 32, 64, n, src_index) + }, + 128 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 32, 128, n, src_index) + }, + _ => { + assert(false) + } + } + }, + 64 => { + match idxdsize { + 64 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 64, 64, n, src_index) + }, + 128 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 64, 128, n, src_index) + }, + _ => { + assert(false) + } + } + }, + 128 => { + match idxdsize { + 64 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 128, 64, n, src_index) + }, + 128 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 128, 128, n, src_index) + }, + _ => { + assert(false) + } + } + }, + 256 => { + match idxdsize { + 64 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 256, 64, n, src_index) + }, + 128 => { + execute_aarch64_instrs_vector_transfer_vector_insert(d, dst_index, 256, 128, n, src_index) + }, + _ => { + assert(false) + } + } + }, + _ => { + assert(false) + } + } +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 480) = { + SEE = 480; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm4 = Slice(__opcode, 11, 4); + let imm5 = Slice(__opcode, 16, 5); + decode_ins_advsimd_elt_aarch64_instrs_vector_transfer_vector_insert(Rd, Rn, imm4, imm5) +} + +val execute_aarch64_instrs_vector_transfer_integer_insert : forall 'd 'datasize 'esize 'index 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64, 128, 256} & 'datasize == 128 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('index), int('n)) -> unit + +function execute_aarch64_instrs_vector_transfer_integer_insert (d, datasize, esize, index, n) = { + CheckFPAdvSIMDEnabled64(); + assert(constraint('esize in {8, 16, 32, 64})); + let element : bits('esize) = X_read(n, esize); + result : bits('datasize) = V_read(d, datasize); + result = Elem_set(result, index, esize, element); + V_set(d, datasize) = result +} + +val decode_ins_advsimd_gen_aarch64_instrs_vector_transfer_integer_insert : (bits(5), bits(5), bits(5)) -> unit + +function decode_ins_advsimd_gen_aarch64_instrs_vector_transfer_integer_insert (Rd, Rn, imm5) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'size = LowestSetBit(imm5); + if size > 3 then { + throw(Error_Undefined()) + }; + assert(constraint(0 <= 'size + 1)); + let 'index = UInt(imm5[4 .. size + 1]); + let 'esize = (8 << size); + let 'datasize = 128; + assert(constraint('esize in {8, 16, 32, 64, 128, 256})); + execute_aarch64_instrs_vector_transfer_integer_insert(d, datasize, esize, index, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 481) = { + SEE = 481; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm5 = Slice(__opcode, 16, 5); + decode_ins_advsimd_gen_aarch64_instrs_vector_transfer_integer_insert(Rd, Rn, imm5) +} + +val execute_aarch64_instrs_integer_tags_mcinsertrandomtag : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_tags_mcinsertrandomtag (d, m, n) = { + let operand : bits(64) = if n == 31 then SP_read() else X_read(n, 64); + let exclude_reg : bits(64) = X_read(m, 64); + let exclude : bits(16) = exclude_reg[15 .. 0] | GCR_EL1[Exclude]; + rtag : bits(4) = undefined; + if AArch64_AllocationTagAccessIsEnabled(PSTATE.EL) then { + if GCR_EL1[RRND] == 0b1 then { + if IsOnes(exclude) then { + rtag = 0b0000 + } else { + rtag = ChooseRandomNonExcludedTag(exclude) + } + } else { + let start_tag : bits(4) = RGSR_EL1[TAG]; + let offset : bits(4) = AArch64_RandomTag(); + rtag = AArch64_ChooseNonExcludedTag(start_tag, offset, exclude); + RGSR_EL1[TAG] = rtag + } + } else { + rtag = 0b0000 + }; + let result : bits(64) = AArch64_AddressWithAllocationTag(operand, rtag); + if d == 31 then { + SP_set() = result + } else { + X_set(d, 64) = result + } +} + +val decode_irg_aarch64_instrs_integer_tags_mcinsertrandomtag : (bits(5), bits(5), bits(5)) -> unit + +function decode_irg_aarch64_instrs_integer_tags_mcinsertrandomtag (Xd, Xn, Xm) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Xd); + let 'n = UInt(Xn); + let 'm = UInt(Xm); + execute_aarch64_instrs_integer_tags_mcinsertrandomtag(d, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 482) = { + SEE = 482; + let Xd = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let Xm = Slice(__opcode, 16, 5); + decode_irg_aarch64_instrs_integer_tags_mcinsertrandomtag(Xd, Xn, Xm) +} + +val execute_aarch64_instrs_system_barriers_isb : unit -> unit + +function execute_aarch64_instrs_system_barriers_isb () = { + InstructionSynchronizationBarrier(); + if HaveBRBExt() & BRBEBranchOnISB() then { + BRBEISB() + }; + if HaveStatisticalProfiling() then { + SPEISB() + }; + () +} + +val decode_isb_aarch64_instrs_system_barriers_isb : (bits(2), bits(4)) -> unit + +function decode_isb_aarch64_instrs_system_barriers_isb (opc, CRm) = { + execute_aarch64_instrs_system_barriers_isb() +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 483) = { + SEE = 483; + let opc = Slice(__opcode, 5, 2); + let CRm = Slice(__opcode, 8, 4); + decode_isb_aarch64_instrs_system_barriers_isb(opc, CRm) +} + +val execute_aarch64_instrs_memory_vector_single_no_wb : forall 'datasize 'esize 'index 'm 'n ('nontemporal : Bool) ('replicate : Bool) 'selem 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'selem in {1, 2, 3, 4} & 0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128}). + (int('datasize), int('esize), int('index), int('m), MemOp, int('n), bool('nontemporal), bool('replicate), int('selem), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_vector_single_no_wb (datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t__arg, tagchecked, wback) = { + t : int = t__arg; + CheckFPAdvSIMDEnabled64(); + address : bits(64) = undefined; + rval : bits(128) = undefined; + element : bits('esize) = undefined; + let 'ebytes = DIV(esize, 8); + let accdesc : AccessDescriptor = CreateAccDescASIMD(memop, nontemporal, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + offs : bits(64) = Zeros(64); + if replicate then { + foreach (s from 0 to (selem - 1) by 1 in inc) { + element = Mem_read(address + offs, ebytes, accdesc); + V_set(t, datasize) = Replicate(element, DIV(datasize, esize)); + offs = offs + ebytes; + t = MOD(t + 1, 32) + } + } else { + foreach (s from 0 to (selem - 1) by 1 in inc) { + rval = V_read(t, 128); + if memop == MemOp_LOAD then { + rval = Elem_set(rval, index, esize, Mem_read(address + offs, ebytes, accdesc)); + V_set(t, 128) = rval + } else { + Mem_set(address + offs, ebytes, accdesc) = Elem_read(rval, index, esize) + }; + offs = offs + ebytes; + t = MOD(t + 1, 32) + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + if wback then { + if m != 31 then { + offs = X_read(m, 64) + }; + if n == 31 then { + SP_set() = address + offs + } else { + X_set(n, 64) = address + offs + } + }; + () +} + +val decode_ld1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 484) = { + SEE = 484; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld1_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld1_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 485) = { + SEE = 485; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld1_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_ld1r_advsimd_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld1r_advsimd_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 486) = { + SEE = 486; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld1r_advsimd_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld1r_advsimd_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld1r_advsimd_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 487) = { + SEE = 487; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld1r_advsimd_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_ld2_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld2_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 488) = { + SEE = 488; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld2_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld2_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld2_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 489) = { + SEE = 489; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld2_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_ld2r_advsimd_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld2r_advsimd_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 490) = { + SEE = 490; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld2r_advsimd_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld2r_advsimd_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld2r_advsimd_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 491) = { + SEE = 491; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld2r_advsimd_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_ld3_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld3_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 492) = { + SEE = 492; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld3_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld3_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld3_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 493) = { + SEE = 493; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld3_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_ld3r_advsimd_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld3r_advsimd_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 494) = { + SEE = 494; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld3r_advsimd_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld3r_advsimd_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld3r_advsimd_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 495) = { + SEE = 495; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld3r_advsimd_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_ld4_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld4_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 496) = { + SEE = 496; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld4_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld4_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld4_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 497) = { + SEE = 497; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld4_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_ld4r_advsimd_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_ld4r_advsimd_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 498) = { + SEE = 498; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld4r_advsimd_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_ld4r_advsimd_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ld4r_advsimd_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 499) = { + SEE = 499; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld4r_advsimd_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_st1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_st1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 500) = { + SEE = 500; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_st1_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_st1_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 501) = { + SEE = 501; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st1_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_st2_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_st2_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 502) = { + SEE = 502; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st2_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_st2_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_st2_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 503) = { + SEE = 503; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st2_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_st3_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_st3_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 504) = { + SEE = 504; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st3_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_st3_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_st3_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 505) = { + SEE = 505; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st3_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val decode_st4_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_st4_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb (Rt, Rn, size, S, opcode, o2, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 506) = { + SEE = 506; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let o2 = Slice(__opcode, 16, 1); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st4_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb(Rt, Rn, size, S, opcode, o2, R, L, Q) +} + +val decode_st4_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_st4_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc (Rt, Rn, size, S, opcode, Rm, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb(datasize, esize, index, m, memop, n, nontemporal, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 507) = { + SEE = 507; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st4_advsimd_sngl_aarch64_instrs_memory_vector_single_post_inc(Rt, Rn, size, S, opcode, Rm, R, L, Q) +} + +val execute_aarch64_instrs_memory_vector_multiple_no_wb : forall 'datasize 'elements 'esize 'm 'n ('nontemporal : Bool) 'rpt 'selem 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'selem in {1, 2, 3, 4} & 'rpt in {1, 2, 3, 4} & 0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128}). + (int('datasize), int('elements), int('esize), int('m), MemOp, int('n), bool('nontemporal), int('rpt), int('selem), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_vector_multiple_no_wb (datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) = { + CheckFPAdvSIMDEnabled64(); + address : bits(64) = undefined; + rval : bits('datasize) = undefined; + tt : int = undefined; + let 'ebytes = DIV(esize, 8); + let accdesc : AccessDescriptor = CreateAccDescASIMD(memop, nontemporal, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + offs : bits(64) = Zeros(64); + foreach (r from 0 to (rpt - 1) by 1 in inc) { + foreach (e from 0 to (elements - 1) by 1 in inc) { + tt = MOD(t + r, 32); + foreach (s from 0 to (selem - 1) by 1 in inc) { + let 'tt = tt in + { + rval = V_read(tt, datasize) + }; + let 'tt = tt in + { + if memop == MemOp_LOAD then { + rval = Elem_set(rval, e, esize, Mem_read(address + offs, ebytes, accdesc)); + V_set(tt, datasize) = rval + } else { + Mem_set(address + offs, ebytes, accdesc) = Elem_read(rval, e, esize) + } + }; + offs = offs + ebytes; + tt = MOD(tt + 1, 32) + } + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + if wback then { + if m != 31 then { + offs = X_read(m, 64) + }; + if n == 31 then { + SP_set() = address + offs + } else { + X_set(n, 64) = address + offs + } + }; + () +} + +val decode_ld1_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_ld1_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 508) = { + SEE = 508; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld1_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_ld1_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ld1_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 509) = { + SEE = 509; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld1_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val decode_ld2_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_ld2_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 510) = { + SEE = 510; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld2_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_ld2_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ld2_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 511) = { + SEE = 511; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld2_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val decode_ld3_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_ld3_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 512) = { + SEE = 512; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld3_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_ld3_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ld3_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 513) = { + SEE = 513; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld3_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val decode_ld4_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_ld4_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 514) = { + SEE = 514; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld4_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_ld4_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_ld4_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 515) = { + SEE = 515; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ld4_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val decode_st1_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_st1_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 516) = { + SEE = 516; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st1_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_st1_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_st1_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 517) = { + SEE = 517; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st1_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val decode_st2_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_st2_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 518) = { + SEE = 518; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st2_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_st2_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_st2_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 519) = { + SEE = 519; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st2_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val decode_st3_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_st3_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 520) = { + SEE = 520; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st3_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_st3_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_st3_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 521) = { + SEE = 521; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st3_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val decode_st4_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb : (bits(5), bits(5), bits(2), bits(4), bits(1), bits(1)) -> unit + +function decode_st4_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb (Rt, Rn, size, opcode, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 522) = { + SEE = 522; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st4_advsimd_mult_aarch64_instrs_memory_vector_multiple_no_wb(Rt, Rn, size, opcode, L, Q) +} + +val decode_st4_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc : (bits(5), bits(5), bits(2), bits(4), bits(5), bits(1), bits(1)) -> unit + +function decode_st4_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc (Rt, Rn, size, opcode, Rm, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let wback : bool = true; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << UInt(size)); + let 'elements = DIV(datasize, esize); + rpt : {1, 2, 3, 4} = 1; + selem : {1, 2, 3, 4} = 1; + match opcode { + 0b0000 => { + rpt = 1; + selem = 4 + }, + 0b0010 => { + rpt = 4; + selem = 1 + }, + 0b0100 => { + rpt = 1; + selem = 3 + }, + 0b0110 => { + rpt = 3; + selem = 1 + }, + 0b0111 => { + rpt = 1; + selem = 1 + }, + 0b1000 => { + rpt = 1; + selem = 2 + }, + 0b1010 => { + rpt = 2; + selem = 1 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'selem = selem; + let 'rpt = rpt; + if (size @ Q) == 0b110 & selem != 1 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_memory_vector_multiple_no_wb(datasize, elements, esize, m, memop, n, nontemporal, rpt, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 523) = { + SEE = 523; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let opcode = Slice(__opcode, 12, 4); + let Rm = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_st4_advsimd_mult_aarch64_instrs_memory_vector_multiple_post_inc(Rt, Rn, size, opcode, Rm, L, Q) +} + +val execute_aarch64_instrs_memory_atomicops_ld_acc : forall 'n 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bits(2), MemOp, int('n), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_ld_acc (lst, memop, n, t, tagchecked) = { + CheckLDST64BEnabled(); + address : bits(64) = undefined; + value_name : bits(64) = undefined; + let accdesc : AccessDescriptor = CreateAccDescLS64(memop, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + SetLoadStoreType(lst); + AArch64_SetLSInstructionSyndrome(64, false, t, true, false); + let data : bits(512) = MemLoad64B(address, accdesc); + foreach (i from 0 to 7 by 1 in inc) { + value_name = data[63 + 64 * i .. 64 * i]; + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + X_set(t + i, 64) = value_name + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ld64b_aarch64_instrs_memory_atomicops_ld_acc : (bits(5), bits(5)) -> unit + +function decode_ld64b_aarch64_instrs_memory_atomicops_ld_acc (Rt, Rn) = { + if not_bool(HaveFeatLS64()) then { + throw(Error_Undefined()) + }; + if Rt[4 .. 3] == 0b11 | [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let memop : MemOp = MemOp_LOAD; + let tagchecked : bool = n != 31; + let lst : bits(2) = lst_64b; + execute_aarch64_instrs_memory_atomicops_ld_acc(lst, memop, n, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 524) = { + SEE = 524; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_ld64b_aarch64_instrs_memory_atomicops_ld_acc(Rt, Rn) +} + +val execute_aarch64_instrs_memory_atomicops_ld : forall ('acquire : Bool) 'datasize ('is_load : Bool) 'n 'regsize ('release : Bool) 's 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (bool('acquire), int('datasize), bool('is_load), int('n), MemAtomicOp, int('regsize), bool('release), int('s), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_ld (acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) = { + address : bits(64) = undefined; + let accdesc : AccessDescriptor = CreateAccDescAtomicOp(op, acquire, release, tagchecked); + let value_name : bits('datasize) = X_read(s, datasize); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let comparevalue : bits('datasize) = __UNKNOWN_bits(datasize); + let data : bits('datasize) = MemAtomic(address, comparevalue, value_name, accdesc); + if t != 31 then { + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + }; + if SPESampleInFlight then { + let ar : bits(1) = if acquire | release then 0b1 else 0b0; + let excl : bits(1) = 0b0; + let at : bits(1) = 0b1; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_ldadd_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldadd_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 525) = { + SEE = 525; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldadd_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldaddb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldaddb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 526) = { + SEE = 526; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldaddb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldaddh_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldaddh_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 527) = { + SEE = 527; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldaddh_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldclr_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldclr_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 528) = { + SEE = 528; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldclr_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldclrb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldclrb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 529) = { + SEE = 529; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldclrb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldclrh_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldclrh_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 530) = { + SEE = 530; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldclrh_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldeor_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldeor_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 531) = { + SEE = 531; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldeor_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldeorb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldeorb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 532) = { + SEE = 532; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldeorb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldeorh_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldeorh_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 533) = { + SEE = 533; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldeorh_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldset_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldset_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 534) = { + SEE = 534; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldset_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldsetb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldsetb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 535) = { + SEE = 535; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldsetb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldseth_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldseth_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 536) = { + SEE = 536; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldseth_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldsmax_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldsmax_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 537) = { + SEE = 537; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldsmax_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldsmaxb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldsmaxb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 538) = { + SEE = 538; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldsmaxb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldsmaxh_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldsmaxh_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 539) = { + SEE = 539; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldsmaxh_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldsmin_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldsmin_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 540) = { + SEE = 540; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldsmin_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldsminb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldsminb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 541) = { + SEE = 541; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldsminb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldsminh_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldsminh_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 542) = { + SEE = 542; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldsminh_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldumax_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldumax_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 543) = { + SEE = 543; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldumax_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldumaxb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldumaxb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 544) = { + SEE = 544; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldumaxb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldumaxh_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldumaxh_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 545) = { + SEE = 545; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldumaxh_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_ldumin_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_ldumin_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 546) = { + SEE = 546; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldumin_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_lduminb_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_lduminb_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 547) = { + SEE = 547; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_lduminb_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val decode_lduminh_aarch64_instrs_memory_atomicops_ld : (bits(5), bits(5), bits(3), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_lduminh_aarch64_instrs_memory_atomicops_ld (Rt, Rn, opc, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let is_load : bool = Rt != 0b11111; + let release : bool = R == 0b1; + op : MemAtomicOp = undefined; + match opc { + 0b000 => { + op = MemAtomicOp_ADD + }, + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b010 => { + op = MemAtomicOp_EOR + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + 0b100 => { + op = MemAtomicOp_SMAX + }, + 0b101 => { + op = MemAtomicOp_SMIN + }, + 0b110 => { + op = MemAtomicOp_UMAX + }, + 0b111 => { + op = MemAtomicOp_UMIN + } + }; + let op = op; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld(acquire, datasize, is_load, n, op, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 548) = { + SEE = 548; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_lduminh_aarch64_instrs_memory_atomicops_ld(Rt, Rn, opc, Rs, R, A, size) +} + +val execute_aarch64_instrs_memory_vector_single_no_wb_ordered : forall 'datasize 'esize 'index 'm 'n ('replicate : Bool) 'selem 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'selem in {1, 2, 3, 4} & 0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128}). + (int('datasize), int('esize), int('index), int('m), MemOp, int('n), bool('replicate), int('selem), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_vector_single_no_wb_ordered (datasize, esize, index, m, memop, n, replicate, selem, t__arg, tagchecked, wback) = { + t : int = t__arg; + CheckFPAdvSIMDEnabled64(); + address : bits(64) = undefined; + rval : bits(128) = undefined; + element : bits('esize) = undefined; + let 'ebytes = DIV(esize, 8); + let accdesc : AccessDescriptor = CreateAccDescASIMDAcqRel(memop, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + offs : bits(64) = Zeros(64); + if replicate then { + foreach (s from 0 to (selem - 1) by 1 in inc) { + element = Mem_read(address + offs, ebytes, accdesc); + V_set(t, datasize) = Replicate(element, DIV(datasize, esize)); + offs = offs + ebytes; + t = MOD(t + 1, 32) + } + } else { + foreach (s from 0 to (selem - 1) by 1 in inc) { + rval = V_read(t, 128); + if memop == MemOp_LOAD then { + rval = Elem_set(rval, index, esize, Mem_read(address + offs, ebytes, accdesc)); + V_set(t, 128) = rval + } else { + Mem_set(address + offs, ebytes, accdesc) = Elem_read(rval, index, esize) + }; + offs = offs + ebytes; + t = MOD(t + 1, 32) + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + if wback then { + if m != 31 then { + offs = X_read(m, 64) + }; + if n == 31 then { + SP_set() = address + offs + } else { + X_set(n, 64) = address + offs + } + }; + () +} + +val decode_ldap1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb_ordered : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1)) -> unit + +function decode_ldap1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb_ordered (Rt, Rn, size, S, opcode, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb_ordered(datasize, esize, index, m, memop, n, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 549) = { + SEE = 549; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ldap1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb_ordered(Rt, Rn, size, S, opcode, R, L, Q) +} + +val decode_stl1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb_ordered : (bits(5), bits(5), bits(2), bits(1), bits(3), bits(1), bits(1), bits(1)) -> unit + +function decode_stl1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb_ordered (Rt, Rn, size, S, opcode, R, L, Q) = { + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 'm = __UNKNOWN_integer(); + let wback : bool = false; + let nontemporal : bool = false; + let tagchecked : bool = wback | n != 31; + let 'init_scale = UInt(opcode[2 .. 1]); + scale : int = init_scale; + let 'selem = UInt([opcode[0]] @ R) + 1; + replicate : bool = false; + index : int = undefined; + match scale { + 3 => { + if L == 0b0 | S == 0b1 then { + throw(Error_Undefined()) + }; + scale = UInt(size); + replicate = true + }, + 0 => { + index = UInt((Q @ S) @ size) + }, + 1 => { + if [size[0]] == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt((Q @ S) @ [size[1]]) + }, + 2 => { + if [size[1]] == 0b1 then { + throw(Error_Undefined()) + }; + if [size[0]] == 0b0 then { + index = UInt(Q @ S) + } else { + if S == 0b1 then { + throw(Error_Undefined()) + }; + index = UInt(Q); + scale = 3 + } + }, + _ => () + }; + let 'scale = scale; + let 'index = index; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'esize = (8 << scale); + assert(constraint('esize in {8, 16, 32, 64})); + execute_aarch64_instrs_memory_vector_single_no_wb_ordered(datasize, esize, index, m, memop, n, replicate, selem, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 550) = { + SEE = 550; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 10, 2); + let S = Slice(__opcode, 12, 1); + let opcode = Slice(__opcode, 13, 3); + let R = Slice(__opcode, 21, 1); + let L = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_stl1_advsimd_sngl_aarch64_instrs_memory_vector_single_no_wb_ordered(Rt, Rn, size, S, opcode, R, L, Q) +} + +val execute_aarch64_instrs_memory_ordered_rcpc : forall 'datasize 'n 'offset 'regsize 't ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'regsize in {32, 64} & 'offset in {0, 1, 2, 4, 8} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), int('n), int('offset), int('regsize), int('t), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_ordered_rcpc (datasize, n, offset, regsize, t, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + let 'dbytes = DIV(datasize, 8); + let accdesc : AccessDescriptor = CreateAccDescLDAcqPC(tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let data : bits('datasize) = Mem_read(address, dbytes, accdesc); + assert(constraint('regsize >= 'datasize)); + X_set(t, regsize) = ZeroExtend(data, regsize); + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + let ar : bits(1) = 0b1; + let excl : bits(1) = 0b0; + let at : bits(1) = 0b0; + let is_load : bool = true; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_ldapr_aarch64_instrs_memory_ordered_rcpc : (bits(5), bits(5), bits(5), bits(2)) -> unit + +function decode_ldapr_aarch64_instrs_memory_ordered_rcpc (Rt, Rn, Rs, size) = { + let wback : bool = false; + let 'offset = 0; + let wb_unknown : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 's = UInt(Rs); + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered_rcpc(datasize, n, offset, regsize, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 551) = { + SEE = 551; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[16]] != 0b1 | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldapr_aarch64_instrs_memory_ordered_rcpc(Rt, Rn, Rs, size) + } +} + +val decode_ldapr_aarch64_instrs_memory_ordered_rcpc_writeback : (bits(5), bits(5), bits(2)) -> unit + +function decode_ldapr_aarch64_instrs_memory_ordered_rcpc_writeback (Rt, Rn, size) = { + wback : bool = true; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'regsize = if size == 0b11 then 64 else 32; + let 'datasize = (8 << UInt(size)); + let 'offset = (1 << UInt(size)); + let tagchecked : bool = wback | n != 31; + wb_unknown : bool = false; + if (wback & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_ordered_rcpc(datasize, n, offset, regsize, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 552) = { + SEE = 552; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 30, 2); + decode_ldapr_aarch64_instrs_memory_ordered_rcpc_writeback(Rt, Rn, size) +} + +val decode_ldaprb_aarch64_instrs_memory_ordered_rcpc : (bits(5), bits(5), bits(5), bits(2)) -> unit + +function decode_ldaprb_aarch64_instrs_memory_ordered_rcpc (Rt, Rn, Rs, size) = { + let wback : bool = false; + let 'offset = 0; + let wb_unknown : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 's = UInt(Rs); + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered_rcpc(datasize, n, offset, regsize, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 553) = { + SEE = 553; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[16]] != 0b1 | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldaprb_aarch64_instrs_memory_ordered_rcpc(Rt, Rn, Rs, size) + } +} + +val decode_ldaprh_aarch64_instrs_memory_ordered_rcpc : (bits(5), bits(5), bits(5), bits(2)) -> unit + +function decode_ldaprh_aarch64_instrs_memory_ordered_rcpc (Rt, Rn, Rs, size) = { + let wback : bool = false; + let 'offset = 0; + let wb_unknown : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 's = UInt(Rs); + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered_rcpc(datasize, n, offset, regsize, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 554) = { + SEE = 554; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[16]] != 0b1 | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldaprh_aarch64_instrs_memory_ordered_rcpc(Rt, Rn, Rs, size) + } +} + +val execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : forall 'datasize ('is_signed : Bool) 'n ('postindex : Bool) 'regsize ('rt_unknown : Bool) 't ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), MemOp, int('n), bits(64), bool('postindex), int('regsize), bool('rt_unknown), bool('is_signed), int('t), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + accdesc : AccessDescriptor = undefined; + if memop == MemOp_LOAD then { + accdesc = CreateAccDescLDAcqPC(tagchecked) + } else if memop == MemOp_STORE then { + accdesc = CreateAccDescAcqRel(memop, tagchecked) + } else (); + if n == 31 then { + if memop != MemOp_PREFETCH then { + CheckSPAlignment() + }; + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else { + data = X_read(t, datasize) + }; + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), false, t, regsize == 64, false) + }; + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), is_signed, t, regsize == 64, false) + }; + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + if is_signed then { + assert(constraint(('datasize > 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = SignExtend(data, regsize) + } else { + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + MemOp_PREFETCH => { + Prefetch(address, t[4 .. 0]) + } + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldapur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldapur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 555) = { + SEE = 555; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldapur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_ldapurb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldapurb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 556) = { + SEE = 556; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldapurb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_ldapurh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldapurh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 557) = { + SEE = 557; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldapurh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_ldapursb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldapursb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 558) = { + SEE = 558; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldapursb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_ldapursh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldapursh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 559) = { + SEE = 559; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldapursh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_ldapursw_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldapursw_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 560) = { + SEE = 560; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldapursw_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_stlur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_stlur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 561) = { + SEE = 561; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_stlur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_stlurb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_stlurb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 562) = { + SEE = 562; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_stlurb_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val decode_stlurh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_stlurh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(datasize, memop, n, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 563) = { + SEE = 563; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_stlurh_aarch64_instrs_memory_single_general_immediate_signed_offset_lda_stl(Rt, Rn, imm9, opc, size) +} + +val execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered : forall 'datasize 'n ('postindex : Bool) 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64, 128, 256, 512, 1024}). + (int('datasize), MemOp, int('n), bits(64), bool('postindex), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered (datasize, memop, n, offset, postindex, t, tagchecked, wback) = { + CheckFPAdvSIMDEnabled64(); + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let accdesc : AccessDescriptor = CreateAccDescASIMDAcqRel(memop, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let data : bits('datasize) = V_read(t, datasize); + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + V_set(t, datasize) = data + }, + _ => () + }; + if wback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + () +} + +val decode_ldapur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldapur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered (Rt, Rn, imm9, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered(datasize, memop, n, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 564) = { + SEE = 564; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldapur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered(Rt, Rn, imm9, opc, size) +} + +val decode_stlur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_stlur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered (Rt, Rn, imm9, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered(datasize, memop, n, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 565) = { + SEE = 565; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_stlur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_ordered(Rt, Rn, imm9, opc, size) +} + +val execute_aarch64_instrs_memory_ordered : forall 'datasize ('limitedordered : Bool) 'n 'offset 'regsize ('rt_unknown : Bool) 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), bool('limitedordered), MemOp, int('n), int('offset), int('regsize), bool('rt_unknown), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_ordered (datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + accdesc : AccessDescriptor = undefined; + if limitedordered then { + accdesc = CreateAccDescLOR(memop, tagchecked) + } else { + accdesc = CreateAccDescAcqRel(memop, tagchecked) + }; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + match memop { + MemOp_STORE => { + let address : bits(64) = address + offset; + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else { + data = X_read(t, datasize) + }; + AArch64_SetLSInstructionSyndrome(dbytes, false, t, regsize == 64, true); + Mem_set(address, dbytes, accdesc) = data; + if wback then { + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + () + }, + MemOp_LOAD => { + AArch64_SetLSInstructionSyndrome(dbytes, false, t, regsize == 64, true); + let data : bits('datasize) = Mem_read(address, dbytes, accdesc); + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + }, + _ => () + }; + if SPESampleInFlight then { + let ar : bits(1) = 0b1; + let excl : bits(1) = 0b0; + let at : bits(1) = 0b0; + let is_load : bool = memop == MemOp_LOAD; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_ldar_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldar_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 566) = { + SEE = 566; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldar_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldarb_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldarb_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 567) = { + SEE = 567; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldarb_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldarh_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldarh_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 568) = { + SEE = 568; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldarh_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldlar_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldlar_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 569) = { + SEE = 569; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldlar_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldlarb_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldlarb_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 570) = { + SEE = 570; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldlarb_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldlarh_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldlarh_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 571) = { + SEE = 571; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldlarh_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stllr_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stllr_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 572) = { + SEE = 572; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stllr_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stllrb_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stllrb_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 573) = { + SEE = 573; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stllrb_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stllrh_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stllrh_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 574) = { + SEE = 574; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stllrh_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stlr_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stlr_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 575) = { + SEE = 575; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stlr_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stlr_aarch64_instrs_memory_ordered_writeback : (bits(5), bits(5), bits(2)) -> unit + +function decode_stlr_aarch64_instrs_memory_ordered_writeback (Rt, Rn, size) = { + let wback : bool = true; + let memop : MemOp = MemOp_STORE; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let limitedordered : bool = false; + let 'regsize = if size == 0b11 then 64 else 32; + let 'datasize = (8 << UInt(size)); + let 'offset = negate(1) * (1 << UInt(size)); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if (wback & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 576) = { + SEE = 576; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 30, 2); + decode_stlr_aarch64_instrs_memory_ordered_writeback(Rt, Rn, size) +} + +val decode_stlrb_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stlrb_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 577) = { + SEE = 577; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stlrb_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stlrh_aarch64_instrs_memory_ordered : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stlrh_aarch64_instrs_memory_ordered (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let wback : bool = false; + let 'offset = 0; + let rt_unknown : bool = false; + let limitedordered : bool = o0 == 0b0; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = elsize; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_ordered(datasize, limitedordered, memop, n, offset, regsize, rt_unknown, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 578) = { + SEE = 578; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stlrh_aarch64_instrs_memory_ordered(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val execute_aarch64_instrs_memory_exclusive_pair : forall ('acqrel : Bool) 'datasize 'elsize 'n ('pair : Bool) 'regsize ('rn_unknown : Bool) ('rt_unknown : Bool) 's 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'elsize in {32, 64} & 'datasize in {32, 64, 128}). + (bool('acqrel), int('datasize), int('elsize), MemOp, int('n), bool('pair), int('regsize), bool('rn_unknown), bool('rt_unknown), int('s), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_exclusive_pair (acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let accdesc : AccessDescriptor = CreateAccDescExLDST(memop, acqrel, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else if rn_unknown then { + address = __UNKNOWN_bits(64) + } else { + address = X_read(n, 64) + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else if pair then { + let el1 : bits(div('datasize, 2)) = X_read(t, DIV(datasize, 2)); + let el2 : bits(div('datasize, 2)) = X_read(t2, DIV(datasize, 2)); + data = if BigEndian(accdesc.acctype) then el1 @ el2 else el2 @ el1 + } else { + assert(constraint('datasize in {8, 16, 32, 64})); + data = X_read(t, datasize) + }; + status : bits(1) = 0b1; + if AArch64_ExclusiveMonitorsPass(address, dbytes) then { + Mem_set(address, dbytes, accdesc) = data; + status = ExclusiveMonitorsStatus() + } else if SPESampleInFlight then { + SPESetDataVirtualAddress(address) + } else (); + X_set(s, 32) = ZeroExtend(status, 32) + }, + MemOp_LOAD => { + AArch64_SetExclusiveMonitors(address, dbytes); + if pair then { + if rt_unknown then { + assert(constraint('datasize in {32, 64})); + X_set(t, datasize) = __UNKNOWN_bits(datasize) + } else if elsize == 32 then { + let data : bits('datasize) = Mem_read(address, dbytes, accdesc); + if BigEndian(accdesc.acctype) then { + assert(constraint((0 <= 'elsize & 'elsize <= 'datasize - 1 & 'datasize - 1 < 'datasize))); + assert(constraint(('datasize - 'elsize == 32 | 'datasize - 'elsize == 64))); + X_set(t, datasize - elsize) = data[datasize - 1 .. elsize]; + X_set(t2, elsize) = data[elsize - 1 .. 0] + } else { + X_set(t, elsize) = data[elsize - 1 .. 0]; + assert(constraint((0 <= 'elsize & 'elsize <= 'datasize - 1 & 'datasize - 1 < 'datasize))); + assert(constraint(('datasize - 'elsize == 32 | 'datasize - 'elsize == 64))); + X_set(t2, datasize - elsize) = data[datasize - 1 .. elsize] + } + } else { + if not_bool(IsAligned__1(address, dbytes)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + X_set(t, 64) = Mem_read(address + 0, 8, accdesc); + X_set(t2, 64) = Mem_read(address + 8, 8, accdesc) + } + } else { + let data : bits('datasize) = Mem_read(address, dbytes, accdesc); + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + _ => () + }; + if SPESampleInFlight then { + let ar : bits(1) = if acqrel then 0b1 else 0b0; + let excl : bits(1) = 0b1; + let at : bits(1) = 0b0; + let is_load : bool = memop == MemOp_LOAD; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_ldaxp_aarch64_instrs_memory_exclusive_pair : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_ldaxp_aarch64_instrs_memory_exclusive_pair (Rt, Rn, Rt2, o0, Rs, L, sz) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (32 << UInt(sz)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_pair(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 579) = { + SEE = 579; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let sz = Slice(__opcode, 30, 1); + if ((([__opcode[16]] != 0b1 | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldaxp_aarch64_instrs_memory_exclusive_pair(Rt, Rn, Rt2, o0, Rs, L, sz) + } +} + +val decode_ldxp_aarch64_instrs_memory_exclusive_pair : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_ldxp_aarch64_instrs_memory_exclusive_pair (Rt, Rn, Rt2, o0, Rs, L, sz) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (32 << UInt(sz)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_pair(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 580) = { + SEE = 580; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let sz = Slice(__opcode, 30, 1); + if ((([__opcode[16]] != 0b1 | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldxp_aarch64_instrs_memory_exclusive_pair(Rt, Rn, Rt2, o0, Rs, L, sz) + } +} + +val decode_stlxp_aarch64_instrs_memory_exclusive_pair : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_stlxp_aarch64_instrs_memory_exclusive_pair (Rt, Rn, Rt2, o0, Rs, L, sz) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (32 << UInt(sz)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_pair(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 581) = { + SEE = 581; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let sz = Slice(__opcode, 30, 1); + decode_stlxp_aarch64_instrs_memory_exclusive_pair(Rt, Rn, Rt2, o0, Rs, L, sz) +} + +val decode_stxp_aarch64_instrs_memory_exclusive_pair : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(1)) -> unit + +function decode_stxp_aarch64_instrs_memory_exclusive_pair (Rt, Rn, Rt2, o0, Rs, L, sz) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (32 << UInt(sz)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_pair(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 582) = { + SEE = 582; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let sz = Slice(__opcode, 30, 1); + decode_stxp_aarch64_instrs_memory_exclusive_pair(Rt, Rn, Rt2, o0, Rs, L, sz) +} + +val execute_aarch64_instrs_memory_exclusive_single : forall ('acqrel : Bool) 'datasize 'elsize 'n ('pair : Bool) 'regsize ('rn_unknown : Bool) ('rt_unknown : Bool) 's 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'elsize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128}). + (bool('acqrel), int('datasize), int('elsize), MemOp, int('n), bool('pair), int('regsize), bool('rn_unknown), bool('rt_unknown), int('s), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_exclusive_single (acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let accdesc : AccessDescriptor = CreateAccDescExLDST(memop, acqrel, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else if rn_unknown then { + address = __UNKNOWN_bits(64) + } else { + address = X_read(n, 64) + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else if pair then { + assert(constraint((div('datasize, 2) == 8 | div('datasize, 2) == 16 | div('datasize, 2) == 32 | div('datasize, 2) == 64))); + let el1 : bits(div('datasize, 2)) = X_read(t, DIV(datasize, 2)); + let el2 : bits(div('datasize, 2)) = X_read(t2, DIV(datasize, 2)); + data = if BigEndian(accdesc.acctype) then el1 @ el2 else el2 @ el1 + } else { + assert(constraint('datasize in {8, 16, 32, 64})); + data = X_read(t, datasize) + }; + status : bits(1) = 0b1; + if AArch64_ExclusiveMonitorsPass(address, dbytes) then { + Mem_set(address, dbytes, accdesc) = data; + status = ExclusiveMonitorsStatus() + } else if SPESampleInFlight then { + SPESetDataVirtualAddress(address) + } else (); + X_set(s, 32) = ZeroExtend(status, 32) + }, + MemOp_LOAD => { + AArch64_SetExclusiveMonitors(address, dbytes); + if pair then { + if rt_unknown then { + assert(constraint('datasize in {32, 64})); + X_set(t, datasize) = __UNKNOWN_bits(datasize) + } else if elsize == 32 then { + let data : bits('datasize) = Mem_read(address, dbytes, accdesc); + if BigEndian(accdesc.acctype) then { + assert(constraint((0 <= 'elsize & 'elsize <= 'datasize - 1 & 'datasize - 1 < 'datasize))); + assert(constraint(('datasize - 'elsize == 32 | 'datasize - 'elsize == 64))); + X_set(t, datasize - elsize) = data[datasize - 1 .. elsize]; + X_set(t2, elsize) = data[elsize - 1 .. 0] + } else { + assert(constraint((0 <= 'elsize - 1 & 'elsize - 1 < 'datasize))); + X_set(t, elsize) = data[elsize - 1 .. 0]; + assert(constraint((0 <= 'elsize & 'elsize <= 'datasize - 1 & 'datasize - 1 < 'datasize))); + assert(constraint(('datasize - 'elsize == 32 | 'datasize - 'elsize == 64))); + X_set(t2, datasize - elsize) = data[datasize - 1 .. elsize] + } + } else { + if not_bool(IsAligned__1(address, dbytes)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + X_set(t, 64) = Mem_read(address + 0, 8, accdesc); + X_set(t2, 64) = Mem_read(address + 8, 8, accdesc) + } + } else { + let data : bits('datasize) = Mem_read(address, dbytes, accdesc); + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + _ => () + }; + if SPESampleInFlight then { + let ar : bits(1) = if acqrel then 0b1 else 0b0; + let excl : bits(1) = 0b1; + let at : bits(1) = 0b0; + let is_load : bool = memop == MemOp_LOAD; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_ldaxr_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldaxr_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 583) = { + SEE = 583; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldaxr_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldaxrb_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldaxrb_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 584) = { + SEE = 584; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldaxrb_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldaxrh_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldaxrh_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 585) = { + SEE = 585; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldaxrh_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldxr_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldxr_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 586) = { + SEE = 586; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldxr_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldxrb_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldxrb_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 587) = { + SEE = 587; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldxrb_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_ldxrh_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_ldxrh_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 588) = { + SEE = 588; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if (((((((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1) | [__opcode[16]] != 0b1) | [__opcode[17]] != 0b1) | [__opcode[18]] != 0b1) | [__opcode[19]] != 0b1) | [__opcode[20]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_ldxrh_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stlxr_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stlxr_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 589) = { + SEE = 589; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stlxr_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stlxrb_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stlxrb_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 590) = { + SEE = 590; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stlxrb_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stlxrh_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stlxrh_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 591) = { + SEE = 591; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stlxrh_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stxr_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stxr_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 592) = { + SEE = 592; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stxr_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stxrb_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stxrb_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 593) = { + SEE = 593; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stxrb_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val decode_stxrh_aarch64_instrs_memory_exclusive_single : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1), bits(2)) -> unit + +function decode_stxrh_aarch64_instrs_memory_exclusive_single (Rt, Rn, Rt2, o0, Rs, L, size) = { + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 's = UInt(Rs); + let acqrel : bool = o0 == 0b1; + let pair : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'elsize = (8 << UInt(size)); + let 'regsize = if elsize == 64 then 64 else 32; + let 'datasize = if pair then elsize * 2 else elsize; + let tagchecked : bool = n != 31; + rt_unknown : bool = false; + rn_unknown : bool = false; + if (memop == MemOp_LOAD & pair) & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_STORE then { + if s == t | pair & s == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DATAOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if s == n & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_BASEOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rn_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + () + }; + execute_aarch64_instrs_memory_exclusive_single(acqrel, datasize, elsize, memop, n, pair, regsize, rn_unknown, rt_unknown, s, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 594) = { + SEE = 594; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_stxrh_aarch64_instrs_memory_exclusive_single(Rt, Rn, Rt2, o0, Rs, L, size) + } +} + +val execute_aarch64_instrs_memory_atomicops_ld_128_ldclrp : forall ('acquire : Bool) 'n ('release : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_ld_128_ldclrp (acquire, n, op, release, t, t2, tagchecked) = { + address : bits(64) = undefined; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let accdesc : AccessDescriptor = CreateAccDescAtomicOp(op, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let store_value : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let comparevalue : bits(128) = __UNKNOWN_bits(128); + let data : bits(128) = MemAtomic(address, comparevalue, store_value, accdesc); + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = data[127 .. 64]; + X_set(t2, 64) = data[63 .. 0] + } else { + X_set(t, 64) = data[63 .. 0]; + X_set(t2, 64) = data[127 .. 64] + } +} + +val decode_ldclrp_aarch64_instrs_memory_atomicops_ld_128_ldclrp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ldclrp_aarch64_instrs_memory_atomicops_ld_128_ldclrp (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(HaveLSE128()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + op : MemAtomicOp = undefined; + match opc { + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + _ => () + }; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld_128_ldclrp(acquire, n, op, release, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 595) = { + SEE = 595; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_ldclrp_aarch64_instrs_memory_atomicops_ld_128_ldclrp(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_integer_tags_mcgettag : forall 'n 't, + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), bits(64), int('t)) -> unit + +function execute_aarch64_instrs_integer_tags_mcgettag (n, offset, t) = { + address : bits(64) = undefined; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + address : bits(64) = address + offset; + let address : bits(64) = Align(address, TAG_GRANULE); + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_LOAD); + let tag : bits(4) = AArch64_MemTag_read(address, accdesc); + X_set(t, 64) = AArch64_AddressWithAllocationTag(X_read(t, 64), tag) +} + +val decode_ldg_aarch64_instrs_integer_tags_mcgettag : (bits(5), bits(5), bits(9)) -> unit + +function decode_ldg_aarch64_instrs_integer_tags_mcgettag (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Xt); + let 'n = UInt(Xn); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + execute_aarch64_instrs_integer_tags_mcgettag(n, offset, t) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 596) = { + SEE = 596; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_ldg_aarch64_instrs_integer_tags_mcgettag(Xt, Xn, imm9) +} + +val execute_aarch64_instrs_integer_tags_mcgettagarray : forall 'n 't, + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), int('t)) -> unit + +function execute_aarch64_instrs_integer_tags_mcgettagarray (n, t) = { + if PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + data : bits(64) = Zeros(64); + address : bits(64) = undefined; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let 'size = 4 * pow2(UInt(GMID_EL1[BS])); + address : bits(64) = Align(address, size); + let 'count = (size >> LOG2_TAG_GRANULE); + index : int = UInt(address[LOG2_TAG_GRANULE + 3 .. LOG2_TAG_GRANULE]); + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_LOAD); + foreach (i from 0 to (count - 1) by 1 in inc) { + let tag : bits(4) = AArch64_MemTag_read(address, accdesc); + let 'index = index in + { + assert(constraint((0 <= 'index * 4 & 'index * 4 + 3 < 64))); + data[index * 4 + 3 .. index * 4] = tag + }; + address = address + TAG_GRANULE; + index = index + 1 + }; + X_set(t, 64) = data +} + +val decode_ldgm_aarch64_instrs_integer_tags_mcgettagarray : (bits(5), bits(5)) -> unit + +function decode_ldgm_aarch64_instrs_integer_tags_mcgettagarray (Xt, Xn) = { + if not_bool(HaveMTE2Ext()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Xt); + let 'n = UInt(Xn); + execute_aarch64_instrs_integer_tags_mcgettagarray(n, t) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 597) = { + SEE = 597; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + decode_ldgm_aarch64_instrs_integer_tags_mcgettagarray(Xt, Xn) +} + +val execute_aarch64_instrs_memory_ordered_pair_ldiapp : forall 'datasize 'n 'offset ('postindex : Bool) ('rt_unknown : Bool) 't 't2 ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64}). + (int('datasize), MemOp, int('n), int('offset), bool('postindex), bool('rt_unknown), int('t), int('t2), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_ordered_pair_ldiapp (datasize, memop, n, offset, postindex, rt_unknown, t, t2, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data1 : bits('datasize) = undefined; + data2 : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let accdesc : AccessDescriptor = CreateAccDescAcqRel(memop, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown & t == n then { + data1 = __UNKNOWN_bits(datasize) + } else { + data1 = X_read(t, datasize) + }; + if rt_unknown & t2 == n then { + data2 = __UNKNOWN_bits(datasize) + } else { + data2 = X_read(t2, datasize) + }; + if HaveLSE2Ext() then { + full_data : bits(2 * 'datasize) = undefined; + if BigEndian(accdesc.acctype) then { + full_data = data1 @ data2 + } else { + full_data = data2 @ data1 + }; + let ispair : bool = true; + let highestAddressfirst : bool = not_bool(postindex) & offset < 0; + Mem_set__2(address, 2 * dbytes, accdesc, ispair, highestAddressfirst) = full_data + } else { + if not_bool(postindex) & offset < 0 then { + Mem_set(address + dbytes, dbytes, accdesc) = data2; + Mem_set(address + 0, dbytes, accdesc) = data1 + } else { + Mem_set(address + 0, dbytes, accdesc) = data1; + Mem_set(address + dbytes, dbytes, accdesc) = data2 + } + } + }, + MemOp_LOAD => { + if HaveLSE2Ext() then { + let ispair : bool = true; + let full_data : bits(2 * 'datasize) = Mem_read__1(address, 2 * dbytes, accdesc, ispair); + if BigEndian(accdesc.acctype) then { + data2 = full_data[datasize - 1 .. 0]; + data1 = full_data[2 * datasize - 1 .. datasize] + } else { + data1 = full_data[datasize - 1 .. 0]; + data2 = full_data[2 * datasize - 1 .. datasize] + } + } else { + data1 = Mem_read(address + 0, dbytes, accdesc); + data2 = Mem_read(address + dbytes, dbytes, accdesc) + }; + if rt_unknown then { + data1 = __UNKNOWN_bits(datasize); + data2 = __UNKNOWN_bits(datasize) + }; + X_set(t, datasize) = data1; + X_set(t2, datasize) = data2 + }, + _ => () + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldiapp_aarch64_instrs_memory_ordered_pair_ldiapp : (bits(5), bits(5), bits(4), bits(5), bits(1), bits(2)) -> unit + +function decode_ldiapp_aarch64_instrs_memory_ordered_pair_ldiapp (Rt, Rn, opc2, Rt2, L, size) = { + let postindex : bool = [opc2[0]] == 0b0; + wback : bool = [opc2[0]] == 0b0; + offset : int = undefined; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'scale = 2 + UInt([size[0]]); + let 'datasize = (8 << scale); + memop : MemOp = undefined; + if L == 0b1 then { + memop = MemOp_LOAD; + offset = if [opc2[0]] == 0b0 then (2 << scale) else 0 + } else { + memop = MemOp_STORE; + offset = if [opc2[0]] == 0b0 then negate(1) * (2 << scale) else 0 + }; + let 'offset = offset; + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_ordered_pair_ldiapp(datasize, memop, n, offset, postindex, rt_unknown, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 598) = { + SEE = 598; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc2 = Slice(__opcode, 12, 4); + let Rt2 = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + decode_ldiapp_aarch64_instrs_memory_ordered_pair_ldiapp(Rt, Rn, opc2, Rt2, L, size) +} + +val execute_aarch64_instrs_memory_pair_general_no_alloc : forall 'datasize 'n ('nontemporal : Bool) ('postindex : Bool) ('rt_unknown : Bool) 't 't2 ('tagchecked : Bool) ('wback : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), bool('rt_unknown), int('t), int('t2), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_pair_general_no_alloc (datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) = { + address : bits(64) = undefined; + data1 : bits('datasize) = undefined; + data2 : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let privileged : bool = PSTATE.EL != EL0; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown & t == n then { + data1 = __UNKNOWN_bits(datasize) + } else { + data1 = X_read(t, datasize) + }; + if rt_unknown & t2 == n then { + data2 = __UNKNOWN_bits(datasize) + } else { + data2 = X_read(t2, datasize) + }; + Mem_set(address + 0, dbytes, accdesc) = data1; + Mem_set(address + dbytes, dbytes, accdesc) = data2 + }, + MemOp_LOAD => { + if HaveLSE2Ext() then { + let ispair : bool = true; + let full_data : bits(2 * 'datasize) = Mem_read__1(address, 2 * dbytes, accdesc, ispair); + if BigEndian(accdesc.acctype) then { + data2 = full_data[datasize - 1 .. 0]; + data1 = full_data[2 * datasize - 1 .. datasize] + } else { + data1 = full_data[datasize - 1 .. 0]; + data2 = full_data[2 * datasize - 1 .. datasize] + } + } else { + data1 = Mem_read(address + 0, dbytes, accdesc); + data2 = Mem_read(address + dbytes, dbytes, accdesc) + }; + if rt_unknown then { + data1 = __UNKNOWN_bits(datasize); + data2 = __UNKNOWN_bits(datasize) + }; + X_set(t, datasize) = data1; + X_set(t2, datasize) = data2 + }, + _ => () + }; + if wback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldnp_gen_aarch64_instrs_memory_pair_general_no_alloc : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldnp_gen_aarch64_instrs_memory_pair_general_no_alloc (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_no_alloc(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 599) = { + SEE = 599; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldnp_gen_aarch64_instrs_memory_pair_general_no_alloc(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stnp_gen_aarch64_instrs_memory_pair_general_no_alloc : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stnp_gen_aarch64_instrs_memory_pair_general_no_alloc (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_no_alloc(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 600) = { + SEE = 600; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stnp_gen_aarch64_instrs_memory_pair_general_no_alloc(Rt, Rn, Rt2, imm7, L, opc) +} + +val execute_aarch64_instrs_memory_pair_simdfp_no_alloc : forall 'datasize 'n ('nontemporal : Bool) ('postindex : Bool) ('rt_unknown : Bool) 't 't2 ('tagchecked : Bool) ('wback : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64, 128, 256}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), bool('rt_unknown), int('t), int('t2), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_pair_simdfp_no_alloc (datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) = { + CheckFPEnabled64(); + address : bits(64) = undefined; + data1 : bits('datasize) = undefined; + data2 : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let accdesc : AccessDescriptor = CreateAccDescASIMD(memop, nontemporal, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let data1 : bits('datasize) = V_read(t, datasize); + let data2 : bits('datasize) = V_read(t2, datasize); + Mem_set(address + 0, dbytes, accdesc) = data1; + Mem_set(address + dbytes, dbytes, accdesc) = data2 + }, + MemOp_LOAD => { + data1 : bits('datasize) = Mem_read(address + 0, dbytes, accdesc); + data2 : bits('datasize) = Mem_read(address + dbytes, dbytes, accdesc); + if rt_unknown then { + data1 = __UNKNOWN_bits(datasize); + data2 = __UNKNOWN_bits(datasize) + }; + assert(constraint('datasize in {8, 16, 32, 64, 128})); + V_set(t, datasize) = data1; + V_set(t2, datasize) = data2 + }, + _ => () + }; + if wback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + () +} + +val decode_ldnp_fpsimd_aarch64_instrs_memory_pair_simdfp_no_alloc : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldnp_fpsimd_aarch64_instrs_memory_pair_simdfp_no_alloc (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_no_alloc(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 601) = { + SEE = 601; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldnp_fpsimd_aarch64_instrs_memory_pair_simdfp_no_alloc(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stnp_fpsimd_aarch64_instrs_memory_pair_simdfp_no_alloc : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stnp_fpsimd_aarch64_instrs_memory_pair_simdfp_no_alloc (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = true; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_no_alloc(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 602) = { + SEE = 602; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stnp_fpsimd_aarch64_instrs_memory_pair_simdfp_no_alloc(Rt, Rn, Rt2, imm7, L, opc) +} + +val execute_aarch64_instrs_memory_pair_simdfp_post_idx : forall 'datasize 'n ('nontemporal : Bool) ('postindex : Bool) ('rt_unknown : Bool) 't 't2 ('tagchecked : Bool) ('wback : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64, 128, 256}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), bool('rt_unknown), int('t), int('t2), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_pair_simdfp_post_idx (datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) = { + CheckFPEnabled64(); + address : bits(64) = undefined; + data1 : bits('datasize) = undefined; + data2 : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let accdesc : AccessDescriptor = CreateAccDescASIMD(memop, nontemporal, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let data1 : bits('datasize) = V_read(t, datasize); + let data2 : bits('datasize) = V_read(t2, datasize); + Mem_set(address + 0, dbytes, accdesc) = data1; + Mem_set(address + dbytes, dbytes, accdesc) = data2 + }, + MemOp_LOAD => { + data1 : bits('datasize) = Mem_read(address + 0, dbytes, accdesc); + data2 : bits('datasize) = Mem_read(address + dbytes, dbytes, accdesc); + if rt_unknown then { + data1 = __UNKNOWN_bits(datasize); + data2 = __UNKNOWN_bits(datasize) + }; + assert(constraint('datasize in {8, 16, 32, 64, 128})); + V_set(t, datasize) = data1; + V_set(t2, datasize) = data2 + }, + _ => () + }; + if wback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + () +} + +val decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_post_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_post_idx (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = true; + let postindex : bool = true; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 603) = { + SEE = 603; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_post_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_pre_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_pre_idx (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = true; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 604) = { + SEE = 604; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_pre_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_offset : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_offset (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 605) = { + SEE = 605; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldp_fpsimd_aarch64_instrs_memory_pair_simdfp_offset(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_post_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_post_idx (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = true; + let postindex : bool = true; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 606) = { + SEE = 606; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_post_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_pre_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_pre_idx (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = true; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 607) = { + SEE = 607; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_pre_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_offset : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_offset (Rt, Rn, Rt2, imm7, L, opc) = { + let wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if opc == 0b11 then { + throw(Error_Undefined()) + }; + let 'scale = 2 + UInt(opc); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64, 128, 256})); + execute_aarch64_instrs_memory_pair_simdfp_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, t, t2, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 608) = { + SEE = 608; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stp_fpsimd_aarch64_instrs_memory_pair_simdfp_offset(Rt, Rn, Rt2, imm7, L, opc) +} + +val execute_aarch64_instrs_memory_pair_general_post_idx : forall 'datasize ('is_signed : Bool) 'n ('nontemporal : Bool) ('postindex : Bool) ('rt_unknown : Bool) 't 't2 ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), bool('rt_unknown), bool('is_signed), int('t), int('t2), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_pair_general_post_idx (datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data1 : bits('datasize) = undefined; + data2 : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let privileged : bool = PSTATE.EL != EL0; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown & t == n then { + data1 = __UNKNOWN_bits(datasize) + } else { + data1 = X_read(t, datasize) + }; + if rt_unknown & t2 == n then { + data2 = __UNKNOWN_bits(datasize) + } else { + data2 = X_read(t2, datasize) + }; + if HaveLSE2Ext() then { + full_data : bits(2 * 'datasize) = undefined; + if BigEndian(accdesc.acctype) then { + full_data = data1 @ data2 + } else { + full_data = data2 @ data1 + }; + let ispair : bool = true; + Mem_set__1(address, 2 * dbytes, accdesc, ispair) = full_data + } else { + Mem_set(address + 0, dbytes, accdesc) = data1; + Mem_set(address + dbytes, dbytes, accdesc) = data2 + } + }, + MemOp_LOAD => { + if HaveLSE2Ext() & not_bool(is_signed) then { + let ispair : bool = true; + let full_data : bits(2 * 'datasize) = Mem_read__1(address, 2 * dbytes, accdesc, ispair); + if BigEndian(accdesc.acctype) then { + data2 = full_data[datasize - 1 .. 0]; + data1 = full_data[2 * datasize - 1 .. datasize] + } else { + data1 = full_data[datasize - 1 .. 0]; + data2 = full_data[2 * datasize - 1 .. datasize] + } + } else { + data1 = Mem_read(address + 0, dbytes, accdesc); + data2 = Mem_read(address + dbytes, dbytes, accdesc) + }; + if rt_unknown then { + data1 = __UNKNOWN_bits(datasize); + data2 = __UNKNOWN_bits(datasize) + }; + if is_signed then { + X_set(t, 64) = SignExtend(data1, 64); + X_set(t2, 64) = SignExtend(data2, 64) + } else { + X_set(t, datasize) = data1; + X_set(t2, datasize) = data2 + } + }, + _ => () + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldp_gen_aarch64_instrs_memory_pair_general_post_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldp_gen_aarch64_instrs_memory_pair_general_post_idx (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = true; + let postindex : bool = true; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 609) = { + SEE = 609; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldp_gen_aarch64_instrs_memory_pair_general_post_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_ldp_gen_aarch64_instrs_memory_pair_general_pre_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldp_gen_aarch64_instrs_memory_pair_general_pre_idx (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = true; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 610) = { + SEE = 610; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldp_gen_aarch64_instrs_memory_pair_general_pre_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_ldp_gen_aarch64_instrs_memory_pair_general_offset : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldp_gen_aarch64_instrs_memory_pair_general_offset (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 611) = { + SEE = 611; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldp_gen_aarch64_instrs_memory_pair_general_offset(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_ldpsw_aarch64_instrs_memory_pair_general_post_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldpsw_aarch64_instrs_memory_pair_general_post_idx (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = true; + let postindex : bool = true; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 612) = { + SEE = 612; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldpsw_aarch64_instrs_memory_pair_general_post_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_ldpsw_aarch64_instrs_memory_pair_general_pre_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldpsw_aarch64_instrs_memory_pair_general_pre_idx (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = true; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 613) = { + SEE = 613; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldpsw_aarch64_instrs_memory_pair_general_pre_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_ldpsw_aarch64_instrs_memory_pair_general_offset : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_ldpsw_aarch64_instrs_memory_pair_general_offset (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 614) = { + SEE = 614; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_ldpsw_aarch64_instrs_memory_pair_general_offset(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stp_gen_aarch64_instrs_memory_pair_general_post_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stp_gen_aarch64_instrs_memory_pair_general_post_idx (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = true; + let postindex : bool = true; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 615) = { + SEE = 615; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stp_gen_aarch64_instrs_memory_pair_general_post_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stp_gen_aarch64_instrs_memory_pair_general_pre_idx : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stp_gen_aarch64_instrs_memory_pair_general_pre_idx (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = true; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 616) = { + SEE = 616; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stp_gen_aarch64_instrs_memory_pair_general_pre_idx(Rt, Rn, Rt2, imm7, L, opc) +} + +val decode_stp_gen_aarch64_instrs_memory_pair_general_offset : (bits(5), bits(5), bits(5), bits(7), bits(1), bits(2)) -> unit + +function decode_stp_gen_aarch64_instrs_memory_pair_general_offset (Rt, Rn, Rt2, imm7, L, opc) = { + wback : bool = false; + let postindex : bool = false; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let nontemporal : bool = false; + let memop : MemOp = if L == 0b1 then MemOp_LOAD else MemOp_STORE; + if (L @ [opc[0]]) == 0b01 | opc == 0b11 then { + throw(Error_Undefined()) + }; + let is_signed : bool = [opc[0]] != 0b0; + let 'scale = 2 + UInt([opc[1]]); + let 'datasize = (8 << scale); + let offset : bits(64) = LSL(SignExtend(imm7, 64), scale); + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_pair_general_post_idx(datasize, memop, n, nontemporal, offset, postindex, rt_unknown, is_signed, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 617) = { + SEE = 617; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rt2 = Slice(__opcode, 10, 5); + let imm7 = Slice(__opcode, 15, 7); + let L = Slice(__opcode, 22, 1); + let opc = Slice(__opcode, 30, 2); + decode_stp_gen_aarch64_instrs_memory_pair_general_offset(Rt, Rn, Rt2, imm7, L, opc) +} + +val execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx : forall 'datasize 'n ('nontemporal : Bool) ('postindex : Bool) 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64, 128, 256, 512, 1024}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx (datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) = { + CheckFPEnabled64(); + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let accdesc : AccessDescriptor = CreateAccDescASIMD(memop, nontemporal, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let data : bits('datasize) = V_read(t, datasize); + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + V_set(t, datasize) = data + }, + _ => () + }; + if wback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + () +} + +val decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + let wback : bool = true; + let postindex : bool = true; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 618) = { + SEE = 618; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + let wback : bool = true; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 619) = { + SEE = 619; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 620) = { + SEE = 620; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + let wback : bool = true; + let postindex : bool = true; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 621) = { + SEE = 621; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + let wback : bool = true; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 622) = { + SEE = 622; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 623) = { + SEE = 623; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_imm_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val execute_aarch64_instrs_memory_literal_general : forall ('is_signed : Bool) ('nontemporal : Bool) 'size 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 'size in {4, 8}). + (MemOp, bool('nontemporal), bits(64), bool('is_signed), int('size), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_literal_general (memop, nontemporal, offset, is_signed, size, t, tagchecked) = { + let address : bits(64) = PC_read() + offset; + data : bits('size * 8) = undefined; + let privileged : bool = PSTATE.EL != EL0; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + match memop { + MemOp_LOAD => { + let data : bits('size * 8) = Mem_read(address, size, accdesc); + if is_signed then { + X_set(t, 64) = SignExtend(data, 64) + } else { + X_set(t, size * 8) = data + } + }, + MemOp_PREFETCH => { + Prefetch(address, t[4 .. 0]) + }, + _ => () + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldr_lit_gen_aarch64_instrs_memory_literal_general : (bits(5), bits(19), bits(2)) -> unit + +function decode_ldr_lit_gen_aarch64_instrs_memory_literal_general (Rt, imm19, opc) = { + let 't = UInt(Rt); + memop : MemOp = MemOp_LOAD; + is_signed : bool = false; + let nontemporal : bool = false; + size : {4, 8} = 4; + match opc { + 0b00 => { + size = 4 + }, + 0b01 => { + size = 8 + }, + 0b10 => { + size = 4; + is_signed = true + }, + 0b11 => { + memop = MemOp_PREFETCH + } + }; + let 'size = size; + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + let tagchecked : bool = false; + execute_aarch64_instrs_memory_literal_general(memop, nontemporal, offset, is_signed, size, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 624) = { + SEE = 624; + let Rt = Slice(__opcode, 0, 5); + let imm19 = Slice(__opcode, 5, 19); + let opc = Slice(__opcode, 30, 2); + decode_ldr_lit_gen_aarch64_instrs_memory_literal_general(Rt, imm19, opc) +} + +val decode_ldrsw_lit_aarch64_instrs_memory_literal_general : (bits(5), bits(19), bits(2)) -> unit + +function decode_ldrsw_lit_aarch64_instrs_memory_literal_general (Rt, imm19, opc) = { + let 't = UInt(Rt); + memop : MemOp = MemOp_LOAD; + is_signed : bool = false; + let nontemporal : bool = false; + size : {4, 8} = 4; + match opc { + 0b00 => { + size = 4 + }, + 0b01 => { + size = 8 + }, + 0b10 => { + size = 4; + is_signed = true + }, + 0b11 => { + memop = MemOp_PREFETCH + } + }; + let 'size = size; + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + let tagchecked : bool = false; + execute_aarch64_instrs_memory_literal_general(memop, nontemporal, offset, is_signed, size, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 625) = { + SEE = 625; + let Rt = Slice(__opcode, 0, 5); + let imm19 = Slice(__opcode, 5, 19); + let opc = Slice(__opcode, 30, 2); + decode_ldrsw_lit_aarch64_instrs_memory_literal_general(Rt, imm19, opc) +} + +val decode_prfm_lit_aarch64_instrs_memory_literal_general : (bits(5), bits(19), bits(2)) -> unit + +function decode_prfm_lit_aarch64_instrs_memory_literal_general (Rt, imm19, opc) = { + let 't = UInt(Rt); + memop : MemOp = MemOp_LOAD; + is_signed : bool = false; + let nontemporal : bool = false; + size : {4, 8} = 4; + match opc { + 0b00 => { + size = 4 + }, + 0b01 => { + size = 8 + }, + 0b10 => { + size = 4; + is_signed = true + }, + 0b11 => { + memop = MemOp_PREFETCH + } + }; + let 'size = size; + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + let tagchecked : bool = false; + execute_aarch64_instrs_memory_literal_general(memop, nontemporal, offset, is_signed, size, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 626) = { + SEE = 626; + let Rt = Slice(__opcode, 0, 5); + let imm19 = Slice(__opcode, 5, 19); + let opc = Slice(__opcode, 30, 2); + decode_prfm_lit_aarch64_instrs_memory_literal_general(Rt, imm19, opc) +} + +val execute_aarch64_instrs_memory_literal_simdfp : forall ('nontemporal : Bool) 'size 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 'size in {4, 8, 16}). + (bool('nontemporal), bits(64), int('size), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_literal_simdfp (nontemporal, offset, size, t, tagchecked) = { + let address : bits(64) = PC_read() + offset; + let privileged : bool = PSTATE.EL != EL0; + CheckFPEnabled64(); + let accdesc : AccessDescriptor = CreateAccDescASIMD(MemOp_LOAD, nontemporal, tagchecked); + let data : bits('size * 8) = Mem_read(address, size, accdesc); + V_set(t, size * 8) = data; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + () +} + +val decode_ldr_lit_fpsimd_aarch64_instrs_memory_literal_simdfp : (bits(5), bits(19), bits(2)) -> unit + +function decode_ldr_lit_fpsimd_aarch64_instrs_memory_literal_simdfp (Rt, imm19, opc) = { + let 't = UInt(Rt); + let nontemporal : bool = false; + size : {4, 8, 16} = 4; + match opc { + 0b00 => { + size = 4 + }, + 0b01 => { + size = 8 + }, + 0b10 => { + size = 16 + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let 'size = size; + let offset : bits(64) = SignExtend(imm19 @ 0b00, 64); + let tagchecked : bool = false; + execute_aarch64_instrs_memory_literal_simdfp(nontemporal, offset, size, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 627) = { + SEE = 627; + let Rt = Slice(__opcode, 0, 5); + let imm19 = Slice(__opcode, 5, 19); + let opc = Slice(__opcode, 30, 2); + decode_ldr_lit_fpsimd_aarch64_instrs_memory_literal_simdfp(Rt, imm19, opc) +} + +val execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx : forall 'datasize ('is_signed : Bool) 'n ('nontemporal : Bool) ('postindex : Bool) 'regsize ('rt_unknown : Bool) 't ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), int('regsize), bool('rt_unknown), bool('is_signed), int('t), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx (datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let privileged : bool = PSTATE.EL != EL0; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if n == 31 then { + if memop != MemOp_PREFETCH then { + CheckSPAlignment() + }; + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else { + data = X_read(t, datasize) + }; + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), false, t, regsize == 64, false) + }; + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), is_signed, t, regsize == 64, false) + }; + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + if is_signed then { + assert(constraint(('datasize > 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = SignExtend(data, regsize) + } else { + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + MemOp_PREFETCH => { + Prefetch(address, t[4 .. 0]) + } + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 628) = { + SEE = 628; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 629) = { + SEE = 629; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 630) = { + SEE = 630; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_imm_gen_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 631) = { + SEE = 631; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 632) = { + SEE = 632; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 633) = { + SEE = 633; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrb_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 634) = { + SEE = 634; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 635) = { + SEE = 635; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 636) = { + SEE = 636; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrh_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 637) = { + SEE = 637; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 638) = { + SEE = 638; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 639) = { + SEE = 639; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsb_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 640) = { + SEE = 640; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 641) = { + SEE = 641; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 642) = { + SEE = 642; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsh_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 643) = { + SEE = 643; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 644) = { + SEE = 644; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 645) = { + SEE = 645; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsw_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 646) = { + SEE = 646; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 647) = { + SEE = 647; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 648) = { + SEE = 648; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_imm_gen_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_strb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_strb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 649) = { + SEE = 649; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strb_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_strb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_strb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 650) = { + SEE = 650; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strb_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_strb_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_strb_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 651) = { + SEE = 651; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strb_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val decode_strh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_strh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = true; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 652) = { + SEE = 652; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strh_imm_aarch64_instrs_memory_single_general_immediate_signed_post_idx(Rt, Rn, imm9, opc, size) +} + +val decode_strh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_strh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx (Rt, Rn, imm9, opc, size) = { + wback : bool = true; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 653) = { + SEE = 653; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strh_imm_aarch64_instrs_memory_single_general_immediate_signed_pre_idx(Rt, Rn, imm9, opc, size) +} + +val decode_strh_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_strh_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_post_idx(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 654) = { + SEE = 654; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strh_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val execute_aarch64_instrs_memory_single_general_register : forall 'datasize ('is_signed : Bool) 'm 'n ('nontemporal : Bool) ('postindex : Bool) 'regsize ('rt_unknown : Bool) 'shift 't ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'shift in {0, 1, 2, 3} & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), ExtendType, int('m), MemOp, int('n), bool('nontemporal), bool('postindex), int('regsize), bool('rt_unknown), int('shift), bool('is_signed), int('t), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_general_register (datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) = { + let offset : bits(64) = ExtendReg(m, extend_type, shift, 64); + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let privileged : bool = PSTATE.EL != EL0; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if n == 31 then { + if memop != MemOp_PREFETCH then { + CheckSPAlignment() + }; + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else { + data = X_read(t, datasize) + }; + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), false, t, regsize == 64, false) + }; + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), is_signed, t, regsize == 64, false) + }; + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + if is_signed then { + assert(constraint(('datasize > 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = SignExtend(data, regsize) + } else { + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + MemOp_PREFETCH => { + Prefetch(address, t[4 .. 0]) + } + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldr_reg_gen_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_ldr_reg_gen_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 655) = { + SEE = 655; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_reg_gen_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_ldrb_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_ldrb_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 656) = { + SEE = 656; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrb_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_ldrh_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_ldrh_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 657) = { + SEE = 657; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrh_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_ldrsb_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_ldrsb_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 658) = { + SEE = 658; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsb_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_ldrsh_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_ldrsh_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 659) = { + SEE = 659; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsh_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_ldrsw_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_ldrsw_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 660) = { + SEE = 660; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldrsw_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_prfm_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_prfm_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + assert(not_bool((match Rt { + [bitone, bitone, _, _, _] => true, + _ => false + }) : bool)); + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, bitone, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if not_bool((match Slice(__opcode, 0, 5) { + [bitone, bitone, _, _, _] => true, + _ => false +}) : bool) & SEE < 661) = { + SEE = 661; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_prfm_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_str_reg_gen_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_str_reg_gen_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 662) = { + SEE = 662; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_reg_gen_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_strb_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_strb_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 663) = { + SEE = 663; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strb_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_strh_reg_aarch64_instrs_memory_single_general_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_strh_reg_aarch64_instrs_memory_single_general_register (Rt, Rn, S, option_name, Rm, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_register(datasize, extend_type, m, memop, n, nontemporal, postindex, regsize, rt_unknown, shift, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 664) = { + SEE = 664; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_strh_reg_aarch64_instrs_memory_single_general_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val execute_aarch64_instrs_memory_single_simdfp_register : forall 'datasize 'm 'n ('nontemporal : Bool) ('postindex : Bool) 'shift 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'shift in {0, 1, 2, 3, 4, 5, 6, 7} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {8, 16, 32, 64, 128, 256, 512, 1024}). + (int('datasize), ExtendType, int('m), MemOp, int('n), bool('nontemporal), bool('postindex), int('shift), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_simdfp_register (datasize, extend_type, m, memop, n, nontemporal, postindex, shift, t, tagchecked, wback) = { + let offset : bits(64) = ExtendReg(m, extend_type, shift, 64); + CheckFPEnabled64(); + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let accdesc : AccessDescriptor = CreateAccDescASIMD(memop, nontemporal, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let data : bits('datasize) = V_read(t, datasize); + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + V_set(t, datasize) = data + }, + _ => () + }; + if wback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + () +} + +val decode_ldr_reg_fpsimd_aarch64_instrs_memory_single_simdfp_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_ldr_reg_fpsimd_aarch64_instrs_memory_single_simdfp_register (Rt, Rn, S, option_name, Rm, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_register(datasize, extend_type, m, memop, n, nontemporal, postindex, shift, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 665) = { + SEE = 665; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldr_reg_fpsimd_aarch64_instrs_memory_single_simdfp_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val decode_str_reg_fpsimd_aarch64_instrs_memory_single_simdfp_register : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_str_reg_fpsimd_aarch64_instrs_memory_single_simdfp_register (Rt, Rn, S, option_name, Rm, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + if [option_name[1]] == 0b0 then { + throw(Error_Undefined()) + }; + let extend_type : ExtendType = DecodeRegExtend(option_name); + let 'shift = if S == 0b1 then scale else 0; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 'm = UInt(Rm); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH; + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_register(datasize, extend_type, m, memop, n, nontemporal, postindex, shift, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 666) = { + SEE = 666; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_str_reg_fpsimd_aarch64_instrs_memory_single_simdfp_register(Rt, Rn, S, option_name, Rm, opc, size) +} + +val execute_aarch64_instrs_memory_single_general_immediate_signed_pac : forall 'n ('nontemporal : Bool) 't ('tagchecked : Bool) ('use_key_a : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (MemOp, int('n), bool('nontemporal), bits(64), int('t), bool('tagchecked), bool('use_key_a), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_general_immediate_signed_pac (memop, n, nontemporal, offset, t, tagchecked, use_key_a, wback__arg) = { + wback : bool = wback__arg; + address : bits(64) = undefined; + let privileged : bool = PSTATE.EL != EL0; + wb_unknown : bool = false; + let auth_then_branch : bool = true; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if (wback & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if n == 31 then { + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(8, false, t, true, false) + }; + if use_key_a then { + address = AuthDA(address, X_read(31, 64), auth_then_branch) + } else { + address = AuthDB(address, X_read(31, 64), auth_then_branch) + }; + if n == 31 then { + CheckSPAlignment() + }; + address : bits(64) = address + offset; + let data : bits(64) = Mem_read(address, 8, accdesc); + X_set(t, 64) = data; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldra_aarch64_instrs_memory_single_general_immediate_signed_pac : (bits(5), bits(5), bits(1), bits(9), bits(1), bits(1), bits(2)) -> unit + +function decode_ldra_aarch64_instrs_memory_single_general_immediate_signed_pac (Rt, Rn, W, imm9, S, M, size) = { + if not_bool(HavePACExt()) | size != 0b11 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let wback : bool = W == 0b1; + let use_key_a : bool = M == 0b0; + let S10 : bits(10) = S @ imm9; + let 'scale = 3; + let offset : bits(64) = LSL(SignExtend(S10, 64), scale); + let nontemporal : bool = false; + let memop : MemOp = MemOp_LOAD; + let tagchecked : bool = wback | n != 31; + execute_aarch64_instrs_memory_single_general_immediate_signed_pac(memop, n, nontemporal, offset, t, tagchecked, use_key_a, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 667) = { + SEE = 667; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let W = Slice(__opcode, 11, 1); + let imm9 = Slice(__opcode, 12, 9); + let S = Slice(__opcode, 22, 1); + let M = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_ldra_aarch64_instrs_memory_single_general_immediate_signed_pac(Rt, Rn, W, imm9, S, M, size) +} + +val execute_aarch64_instrs_memory_atomicops_ld_128_ldsetp : forall ('acquire : Bool) 'n ('release : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_ld_128_ldsetp (acquire, n, op, release, t, t2, tagchecked) = { + address : bits(64) = undefined; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let accdesc : AccessDescriptor = CreateAccDescAtomicOp(op, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let store_value : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let comparevalue : bits(128) = __UNKNOWN_bits(128); + let data : bits(128) = MemAtomic(address, comparevalue, store_value, accdesc); + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = data[127 .. 64]; + X_set(t2, 64) = data[63 .. 0] + } else { + X_set(t, 64) = data[63 .. 0]; + X_set(t2, 64) = data[127 .. 64] + } +} + +val decode_ldsetp_aarch64_instrs_memory_atomicops_ld_128_ldsetp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ldsetp_aarch64_instrs_memory_atomicops_ld_128_ldsetp (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(HaveLSE128()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + op : MemAtomicOp = undefined; + match opc { + 0b001 => { + op = MemAtomicOp_BIC + }, + 0b011 => { + op = MemAtomicOp_ORR + }, + _ => () + }; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_ld_128_ldsetp(acquire, n, op, release, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 668) = { + SEE = 668; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_ldsetp_aarch64_instrs_memory_atomicops_ld_128_ldsetp(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : forall 'datasize ('is_signed : Bool) 'n ('nontemporal : Bool) ('postindex : Bool) 'regsize ('rt_unknown : Bool) 't ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), int('regsize), bool('rt_unknown), bool('is_signed), int('t), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let privileged : bool = AArch64_IsUnprivAccessPriv(); + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if n == 31 then { + if memop != MemOp_PREFETCH then { + CheckSPAlignment() + }; + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else { + data = X_read(t, datasize) + }; + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), false, t, regsize == 64, false) + }; + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), is_signed, t, regsize == 64, false) + }; + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + if is_signed then { + assert(constraint(('datasize > 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = SignExtend(data, regsize) + } else { + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + MemOp_PREFETCH => { + Prefetch(address, t[4 .. 0]) + } + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldtr_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldtr_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 669) = { + SEE = 669; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldtr_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_ldtrb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldtrb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 670) = { + SEE = 670; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldtrb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_ldtrh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldtrh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 671) = { + SEE = 671; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldtrh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_ldtrsb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldtrsb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 672) = { + SEE = 672; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldtrsb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_ldtrsh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldtrsh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 673) = { + SEE = 673; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldtrsh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_ldtrsw_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldtrsw_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 674) = { + SEE = 674; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldtrsw_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_sttr_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_sttr_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 675) = { + SEE = 675; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_sttr_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_sttrb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_sttrb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 676) = { + SEE = 676; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_sttrb_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val decode_sttrh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_sttrh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + throw(Error_Undefined()) + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 677) = { + SEE = 677; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_sttrh_aarch64_instrs_memory_single_general_immediate_signed_offset_unpriv(Rt, Rn, imm9, opc, size) +} + +val execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal : forall 'datasize 'n ('nontemporal : Bool) ('postindex : Bool) 't ('tagchecked : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64, 128, 256, 512, 1024}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), int('t), bool('tagchecked), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal (datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) = { + CheckFPEnabled64(); + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let accdesc : AccessDescriptor = CreateAccDescASIMD(memop, nontemporal, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let data : bits('datasize) = V_read(t, datasize); + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + V_set(t, datasize) = data + }, + _ => () + }; + if wback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleSIMDFPLoadStore() + }; + () +} + +val decode_ldur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 678) = { + SEE = 678; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_stur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_stur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + let wback : bool = false; + let postindex : bool = false; + let 'scale = UInt([opc[1]] @ size); + if scale > 4 then { + throw(Error_Undefined()) + }; + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + let memop : MemOp = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + assert(constraint('datasize in {8, 16, 32, 64, 128, 256, 512, 1024})); + execute_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, t, tagchecked, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 679) = { + SEE = 679; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_stur_fpsimd_aarch64_instrs_memory_single_simdfp_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : forall 'datasize ('is_signed : Bool) 'n ('nontemporal : Bool) ('postindex : Bool) 'regsize ('rt_unknown : Bool) 't ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), int('regsize), bool('rt_unknown), bool('is_signed), int('t), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let privileged : bool = PSTATE.EL != EL0; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if n == 31 then { + if memop != MemOp_PREFETCH then { + CheckSPAlignment() + }; + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else { + data = X_read(t, datasize) + }; + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), false, t, regsize == 64, false) + }; + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), is_signed, t, regsize == 64, false) + }; + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + if is_signed then { + assert(constraint(('datasize > 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = SignExtend(data, regsize) + } else { + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + MemOp_PREFETCH => { + Prefetch(address, t[4 .. 0]) + } + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_ldur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 680) = { + SEE = 680; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_ldurb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldurb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 681) = { + SEE = 681; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldurb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_ldurh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldurh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 682) = { + SEE = 682; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldurh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_ldursb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldursb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 683) = { + SEE = 683; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldursb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_ldursh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldursh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 684) = { + SEE = 684; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldursh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_ldursw_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_ldursw_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 685) = { + SEE = 685; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_ldursw_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_prfum_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_prfum_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 686) = { + SEE = 686; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_prfum_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_stur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_stur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 687) = { + SEE = 687; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_stur_gen_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_sturb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_sturb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 688) = { + SEE = 688; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_sturb_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val decode_sturh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal : (bits(5), bits(5), bits(9), bits(2), bits(2)) -> unit + +function decode_sturh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal (Rt, Rn, imm9, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = SignExtend(imm9, 64); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 689) = { + SEE = 689; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_sturh_aarch64_instrs_memory_single_general_immediate_signed_offset_normal(Rt, Rn, imm9, opc, size) +} + +val execute_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub : forall 'a 'd 'datasize 'destsize 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'destsize in {32, 64} & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31 & 0 <= 'a & 'a <= 31). + (int('a), int('d), int('datasize), int('destsize), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub (a, d, datasize, destsize, m, n, sub_op) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let operand3 : bits('destsize) = X_read(a, destsize); + result : int = undefined; + if sub_op then { + result = UInt(operand3) - UInt(operand1) * UInt(operand2) + } else { + result = UInt(operand3) + UInt(operand1) * UInt(operand2) + }; + let 'result = result; + X_set(d, destsize) = result[destsize - 1 .. 0] +} + +val decode_madd_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_madd_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub (Rd, Rn, Ra, o0, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = if sf == 0b1 then 64 else 32; + let 'datasize = destsize; + let sub_op : bool = o0 == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub(a, d, datasize, destsize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 690) = { + SEE = 690; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_madd_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub(Rd, Rn, Ra, o0, Rm, sf) +} + +val decode_msub_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_msub_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub (Rd, Rn, Ra, o0, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = if sf == 0b1 then 64 else 32; + let 'datasize = destsize; + let sub_op : bool = o0 == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub(a, d, datasize, destsize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 691) = { + SEE = 691; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_msub_aarch64_instrs_integer_arithmetic_mul_uniform_add_sub(Rd, Rn, Ra, o0, Rm, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum : forall 'd 'datasize 'elements 'esize 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum (d, datasize, elements, esize, m, n, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + product : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + product = (UInt(element1) * UInt(element2))[esize - 1 .. 0]; + if sub_op then { + result = Elem_set(result, e, esize, Elem_read(operand3, e, esize) - product) + } else { + result = Elem_set(result, e, esize, Elem_read(operand3, e, esize) + product) + } + }; + V_set(d, datasize) = result +} + +val decode_mla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_mla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 692) = { + SEE = 692; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_mla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum(Rd, Rn, Rm, size, U, Q) +} + +val decode_mls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_mls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum(d, datasize, elements, esize, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 693) = { + SEE = 693; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_mls_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_accum(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int (d, datasize, elements, esize, idxdsize, index, m, n, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + product : bits('esize) = undefined; + let 'element2 = UInt(Elem_read(operand2, index, esize)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = UInt(Elem_read(operand1, e, esize)); + product = (element1 * element2)[esize - 1 .. 0]; + if sub_op then { + result = Elem_set(result, e, esize, Elem_read(operand3, e, esize) - product) + } else { + result = Elem_set(result, e, esize, Elem_read(operand3, e, esize) + product) + } + }; + V_set(d, datasize) = result +} + +val decode_mla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_mla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int (Rd, Rn, H, o2, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 694) = { + SEE = 694; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_mla_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int(Rd, Rn, H, o2, Rm, M, L, size, Q) +} + +val decode_mls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_mls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int (Rd, Rn, H, o2, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int(d, datasize, elements, esize, idxdsize, index, m, n, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 695) = { + SEE = 695; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_mls_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_int(Rd, Rn, H, o2, Rm, M, L, size, Q) +} + +val execute_aarch64_instrs_integer_ins_ext_insert_movewide : forall 'd 'datasize 'pos, + (0 <= 'pos & 'pos <= 63 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bits(16), MoveWideOp, int('pos)) -> unit + +function execute_aarch64_instrs_integer_ins_ext_insert_movewide (d, datasize, imm, opcode, pos) = { + result : bits('datasize) = undefined; + if opcode == MoveWideOp_K then { + result = X_read(d, datasize) + } else { + result = Zeros(datasize) + }; + assert(constraint('pos + 15 < 'datasize)); + result[pos + 15 .. pos] = imm; + if opcode == MoveWideOp_N then { + result = not_vec(result) + }; + let result = result; + X_set(d, datasize) = result +} + +val decode_movk_aarch64_instrs_integer_ins_ext_insert_movewide : (bits(5), bits(16), bits(2), bits(2), bits(1)) -> unit + +function decode_movk_aarch64_instrs_integer_ins_ext_insert_movewide (Rd, imm16, hw, opc, sf) = { + let 'd = UInt(Rd); + let 'datasize = if sf == 0b1 then 64 else 32; + let imm : bits(16) = imm16; + opcode : MoveWideOp = undefined; + match opc { + 0b00 => { + opcode = MoveWideOp_N + }, + 0b10 => { + opcode = MoveWideOp_Z + }, + 0b11 => { + opcode = MoveWideOp_K + }, + _ => { + throw(Error_Undefined()) + } + }; + let opcode = opcode; + if sf == 0b0 & [hw[1]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'pos = UInt(hw @ 0b0000); + execute_aarch64_instrs_integer_ins_ext_insert_movewide(d, datasize, imm, opcode, pos) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 696) = { + SEE = 696; + let Rd = Slice(__opcode, 0, 5); + let imm16 = Slice(__opcode, 5, 16); + let hw = Slice(__opcode, 21, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_movk_aarch64_instrs_integer_ins_ext_insert_movewide(Rd, imm16, hw, opc, sf) +} + +val decode_movn_aarch64_instrs_integer_ins_ext_insert_movewide : (bits(5), bits(16), bits(2), bits(2), bits(1)) -> unit + +function decode_movn_aarch64_instrs_integer_ins_ext_insert_movewide (Rd, imm16, hw, opc, sf) = { + let 'd = UInt(Rd); + let 'datasize = if sf == 0b1 then 64 else 32; + let imm : bits(16) = imm16; + opcode : MoveWideOp = undefined; + match opc { + 0b00 => { + opcode = MoveWideOp_N + }, + 0b10 => { + opcode = MoveWideOp_Z + }, + 0b11 => { + opcode = MoveWideOp_K + }, + _ => { + throw(Error_Undefined()) + } + }; + let opcode = opcode; + if sf == 0b0 & [hw[1]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'pos = UInt(hw @ 0b0000); + execute_aarch64_instrs_integer_ins_ext_insert_movewide(d, datasize, imm, opcode, pos) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 697) = { + SEE = 697; + let Rd = Slice(__opcode, 0, 5); + let imm16 = Slice(__opcode, 5, 16); + let hw = Slice(__opcode, 21, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_movn_aarch64_instrs_integer_ins_ext_insert_movewide(Rd, imm16, hw, opc, sf) +} + +val decode_movz_aarch64_instrs_integer_ins_ext_insert_movewide : (bits(5), bits(16), bits(2), bits(2), bits(1)) -> unit + +function decode_movz_aarch64_instrs_integer_ins_ext_insert_movewide (Rd, imm16, hw, opc, sf) = { + let 'd = UInt(Rd); + let 'datasize = if sf == 0b1 then 64 else 32; + let imm : bits(16) = imm16; + opcode : MoveWideOp = undefined; + match opc { + 0b00 => { + opcode = MoveWideOp_N + }, + 0b10 => { + opcode = MoveWideOp_Z + }, + 0b11 => { + opcode = MoveWideOp_K + }, + _ => { + throw(Error_Undefined()) + } + }; + let opcode = opcode; + if sf == 0b0 & [hw[1]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'pos = UInt(hw @ 0b0000); + execute_aarch64_instrs_integer_ins_ext_insert_movewide(d, datasize, imm, opcode, pos) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 698) = { + SEE = 698; + let Rd = Slice(__opcode, 0, 5); + let imm16 = Slice(__opcode, 5, 16); + let hw = Slice(__opcode, 21, 2); + let opc = Slice(__opcode, 29, 2); + let sf = Slice(__opcode, 31, 1); + decode_movz_aarch64_instrs_integer_ins_ext_insert_movewide(Rd, imm16, hw, opc, sf) +} + +val execute_aarch64_instrs_system_register_system_128 : forall ('read : Bool) 'sys_crm 'sys_crn 'sys_op0 'sys_op1 'sys_op2 't 't2, + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 'sys_op2 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op1 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op0 in {2, 3} & 0 <= 'sys_crn & 'sys_crn <= 15 & 0 <= 'sys_crm & 'sys_crm <= 15). + (bool('read), int('sys_crm), int('sys_crn), int('sys_op0), int('sys_op1), int('sys_op2), int('t), int('t2)) -> unit + +function execute_aarch64_instrs_system_register_system_128 (read, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t, t2) = { + if read then { + AArch64_SysRegRead128(sys_op0, sys_op1, sys_crn, sys_crm, sys_op2, t, t2) + } else { + AArch64_SysRegWrite128(sys_op0, sys_op1, sys_crn, sys_crm, sys_op2, t, t2) + } +} + +val decode_mrrs_aarch64_instrs_system_register_system_128 : (bits(5), bits(3), bits(4), bits(4), bits(3), bits(1), bits(1)) -> unit + +function decode_mrrs_aarch64_instrs_system_register_system_128 (Rt, op2, CRm, CRn, op1, o0, L) = { + if not_bool(HaveSysReg128()) then { + throw(Error_Undefined()) + }; + if [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + AArch64_CheckSystemAccess(0b1 @ o0, op1, CRn, CRm, op2, Rt, L); + let 't = UInt(Rt); + let 't2 = UInt(Rt + 1); + let 'sys_op0 = 2 + UInt(o0); + let 'sys_op1 = UInt(op1); + let 'sys_op2 = UInt(op2); + let 'sys_crn = UInt(CRn); + let 'sys_crm = UInt(CRm); + let read : bool = L == 0b1; + execute_aarch64_instrs_system_register_system_128(read, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t, t2) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 699) = { + SEE = 699; + let Rt = Slice(__opcode, 0, 5); + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let CRn = Slice(__opcode, 12, 4); + let op1 = Slice(__opcode, 16, 3); + let o0 = Slice(__opcode, 19, 1); + let L = Slice(__opcode, 21, 1); + decode_mrrs_aarch64_instrs_system_register_system_128(Rt, op2, CRm, CRn, op1, o0, L) +} + +val decode_msrr_aarch64_instrs_system_register_system_128 : (bits(5), bits(3), bits(4), bits(4), bits(3), bits(1), bits(1)) -> unit + +function decode_msrr_aarch64_instrs_system_register_system_128 (Rt, op2, CRm, CRn, op1, o0, L) = { + if not_bool(HaveSysReg128()) then { + throw(Error_Undefined()) + }; + if [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + AArch64_CheckSystemAccess(0b1 @ o0, op1, CRn, CRm, op2, Rt, L); + let 't = UInt(Rt); + let 't2 = UInt(Rt + 1); + let 'sys_op0 = 2 + UInt(o0); + let 'sys_op1 = UInt(op1); + let 'sys_op2 = UInt(op2); + let 'sys_crn = UInt(CRn); + let 'sys_crm = UInt(CRm); + let read : bool = L == 0b1; + execute_aarch64_instrs_system_register_system_128(read, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t, t2) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 700) = { + SEE = 700; + let Rt = Slice(__opcode, 0, 5); + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let CRn = Slice(__opcode, 12, 4); + let op1 = Slice(__opcode, 16, 3); + let o0 = Slice(__opcode, 19, 1); + let L = Slice(__opcode, 21, 1); + decode_msrr_aarch64_instrs_system_register_system_128(Rt, op2, CRm, CRn, op1, o0, L) +} + +val execute_aarch64_instrs_system_register_system : forall ('read : Bool) 'sys_crm 'sys_crn 'sys_op0 'sys_op1 'sys_op2 't, + (0 <= 't & 't <= 31 & 'sys_op2 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op1 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op0 in {2, 3} & 0 <= 'sys_crn & 'sys_crn <= 15 & 0 <= 'sys_crm & 'sys_crm <= 15). + (bool('read), int('sys_crm), int('sys_crn), int('sys_op0), int('sys_op1), int('sys_op2), int('t)) -> unit + +function execute_aarch64_instrs_system_register_system (read, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t) = { + if read then { + AArch64_SysRegRead(sys_op0, sys_op1, sys_crn, sys_crm, sys_op2, t) + } else { + AArch64_SysRegWrite(sys_op0, sys_op1, sys_crn, sys_crm, sys_op2, t) + } +} + +val decode_mrs_aarch64_instrs_system_register_system : (bits(5), bits(3), bits(4), bits(4), bits(3), bits(1), bits(1)) -> unit + +function decode_mrs_aarch64_instrs_system_register_system (Rt, op2, CRm, CRn, op1, o0, L) = { + AArch64_CheckSystemAccess(0b1 @ o0, op1, CRn, CRm, op2, Rt, L); + let 't = UInt(Rt); + let 'sys_op0 = 2 + UInt(o0); + let 'sys_op1 = UInt(op1); + let 'sys_op2 = UInt(op2); + let 'sys_crn = UInt(CRn); + let 'sys_crm = UInt(CRm); + let read : bool = L == 0b1; + execute_aarch64_instrs_system_register_system(read, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 701) = { + SEE = 701; + let Rt = Slice(__opcode, 0, 5); + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let CRn = Slice(__opcode, 12, 4); + let op1 = Slice(__opcode, 16, 3); + let o0 = Slice(__opcode, 19, 1); + let L = Slice(__opcode, 21, 1); + decode_mrs_aarch64_instrs_system_register_system(Rt, op2, CRm, CRn, op1, o0, L) +} + +val decode_msr_reg_aarch64_instrs_system_register_system : (bits(5), bits(3), bits(4), bits(4), bits(3), bits(1), bits(1)) -> unit + +function decode_msr_reg_aarch64_instrs_system_register_system (Rt, op2, CRm, CRn, op1, o0, L) = { + AArch64_CheckSystemAccess(0b1 @ o0, op1, CRn, CRm, op2, Rt, L); + let 't = UInt(Rt); + let 'sys_op0 = 2 + UInt(o0); + let 'sys_op1 = UInt(op1); + let 'sys_op2 = UInt(op2); + let 'sys_crn = UInt(CRn); + let 'sys_crm = UInt(CRm); + let read : bool = L == 0b1; + execute_aarch64_instrs_system_register_system(read, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 702) = { + SEE = 702; + let Rt = Slice(__opcode, 0, 5); + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let CRn = Slice(__opcode, 12, 4); + let op1 = Slice(__opcode, 16, 3); + let o0 = Slice(__opcode, 19, 1); + let L = Slice(__opcode, 21, 1); + decode_msr_reg_aarch64_instrs_system_register_system(Rt, op2, CRm, CRn, op1, o0, L) +} + +val execute_aarch64_instrs_system_register_cpsr : (PSTATEField, bits(4)) -> unit + +function execute_aarch64_instrs_system_register_cpsr (field, operand) = { + match field { + PSTATEField_SSBS => { + PSTATE.SSBS = [operand[0]] + }, + PSTATEField_SP => { + PSTATE.SP = [operand[0]] + }, + PSTATEField_DAIFSet => { + PSTATE.D = PSTATE.D | [operand[3]]; + PSTATE.A = PSTATE.A | [operand[2]]; + PSTATE.I = PSTATE.I | [operand[1]]; + PSTATE.F = PSTATE.F | [operand[0]] + }, + PSTATEField_DAIFClr => { + PSTATE.D = PSTATE.D & not_vec([operand[3]]); + PSTATE.A = PSTATE.A & not_vec([operand[2]]); + PSTATE.I = PSTATE.I & not_vec([operand[1]]); + PSTATE.F = PSTATE.F & not_vec([operand[0]]) + }, + PSTATEField_PAN => { + PSTATE.PAN = [operand[0]] + }, + PSTATEField_UAO => { + PSTATE.UAO = [operand[0]] + }, + PSTATEField_DIT => { + PSTATE.DIT = [operand[0]] + }, + PSTATEField_TCO => { + PSTATE.TCO = [operand[0]] + }, + PSTATEField_ALLINT => { + if ((PSTATE.EL == EL1 & IsHCRXEL2Enabled()) & HCRX_EL2[TALLINT] == 0b1) & [operand[0]] == 0b1 then { + AArch64_SystemAccessTrap(EL2, UInt(0x18)) + }; + PSTATE.ALLINT = [operand[0]] + }, + PSTATEField_SVCRSM => { + CheckSMEAccess(); + SetPSTATE_SM([operand[0]]) + }, + PSTATEField_SVCRZA => { + CheckSMEAccess(); + SetPSTATE_ZA([operand[0]]) + }, + PSTATEField_SVCRSMZA => { + CheckSMEAccess(); + SetPSTATE_SM([operand[0]]); + SetPSTATE_ZA([operand[0]]) + }, + PSTATEField_PM => { + PSTATE.PM = [operand[0]] + } + } +} + +val decode_msr_imm_aarch64_instrs_system_register_cpsr : (bits(3), bits(4), bits(3)) -> unit + +function decode_msr_imm_aarch64_instrs_system_register_cpsr (op2, CRm, op1) = { + if op1 == 0b000 & op2 == 0b000 then { + throw(Error_See("CFINV")) + }; + if op1 == 0b000 & op2 == 0b001 then { + throw(Error_See("XAFLAG")) + }; + if op1 == 0b000 & op2 == 0b010 then { + throw(Error_See("AXFLAG")) + }; + AArch64_CheckSystemAccess(0b00, op1, 0b0100, CRm, op2, 0b11111, 0b0); + min_EL : bits(2) = undefined; + need_secure : bool = false; + match op1 { + [bitzero, bitzero, _] => { + min_EL = EL1 + }, + 0b010 => { + min_EL = EL1 + }, + 0b011 => { + min_EL = EL0 + }, + 0b100 => { + min_EL = EL2 + }, + 0b101 => { + if not_bool(HaveVirtHostExt()) then { + throw(Error_Undefined()) + }; + min_EL = EL2 + }, + 0b110 => { + min_EL = EL3 + }, + 0b111 => { + min_EL = EL1; + need_secure = true + } + }; + let min_EL = min_EL; + if UInt(PSTATE.EL) < UInt(min_EL) | need_secure & CurrentSecurityState() != SS_Secure then { + throw(Error_Undefined()) + }; + let operand : bits(4) = CRm; + field : PSTATEField = undefined; + match op1 @ op2 { + 0b000011 => { + if not_bool(HaveUAOExt()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_UAO + }, + 0b000100 => { + if not_bool(HavePANExt()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_PAN + }, + 0b000101 => { + field = PSTATEField_SP + }, + 0b001000 => { + match CRm { + [bitzero, bitzero, bitzero, _] => { + if not_bool(HaveFeatNMI()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_ALLINT + }, + [bitzero, bitzero, bitone, _] => { + if not_bool(HaveFeatEBEP()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_PM + }, + _ => { + throw(Error_Undefined()) + } + } + }, + 0b011010 => { + if not_bool(HaveDITExt()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_DIT + }, + 0b011011 => { + match CRm { + [bitzero, bitzero, bitone, _] => { + if not_bool(HaveSME()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_SVCRSM + }, + [bitzero, bitone, bitzero, _] => { + if not_bool(HaveSME()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_SVCRZA + }, + [bitzero, bitone, bitone, _] => { + if not_bool(HaveSME()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_SVCRSMZA + }, + _ => { + throw(Error_Undefined()) + } + } + }, + 0b011100 => { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_TCO + }, + 0b011110 => { + field = PSTATEField_DAIFSet + }, + 0b011111 => { + field = PSTATEField_DAIFClr + }, + 0b011001 => { + if not_bool(HaveSSBSExt()) then { + throw(Error_Undefined()) + }; + field = PSTATEField_SSBS + }, + _ => { + throw(Error_Undefined()) + } + }; + if PSTATE.EL == EL0 & (field == PSTATEField_DAIFSet | field == PSTATEField_DAIFClr) then { + if IsInHost() | SCTLR_EL1[UMA] == 0b0 then { + if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + AArch64_SystemAccessTrap(EL2, UInt(0x18)) + } else { + AArch64_SystemAccessTrap(EL1, UInt(0x18)) + } + }; + () + }; + execute_aarch64_instrs_system_register_cpsr(field, operand) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 703) = { + SEE = 703; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let op1 = Slice(__opcode, 16, 3); + decode_msr_imm_aarch64_instrs_system_register_cpsr(op2, CRm, op1) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product : forall 'd 'datasize 'elements 'esize 'm 'n ('poly : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('poly)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product (d, datasize, elements, esize, m, n, poly) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + product : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + if poly then { + product = PolynomialMult(element1, element2)[esize - 1 .. 0] + } else { + product = (UInt(element1) * UInt(element2))[esize - 1 .. 0] + }; + result = Elem_set(result, e, esize, product) + }; + V_set(d, datasize) = result +} + +val decode_mul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_mul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if U == 0b1 & size != 0b00 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let poly : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product(d, datasize, elements, esize, m, n, poly) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 704) = { + SEE = 704; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_mul_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product(Rd, Rn, Rm, size, U, Q) +} + +val decode_pmul_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_pmul_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if U == 0b1 & size != 0b00 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let poly : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product(d, datasize, elements, esize, m, n, poly) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 705) = { + SEE = 705; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_pmul_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_product(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_int : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_int (d, datasize, elements, esize, idxdsize, index, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + result : bits('datasize) = undefined; + element1 : int = undefined; + product : bits('esize) = undefined; + let 'element2 = UInt(Elem_read(operand2, index, esize)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = UInt(Elem_read(operand1, e, esize)); + product = (element1 * element2)[esize - 1 .. 0]; + result = Elem_set(result, e, esize, product) + }; + V_set(d, datasize) = result +} + +val decode_mul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_int : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_mul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_int (Rd, Rn, H, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_int(d, datasize, elements, esize, idxdsize, index, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 706) = { + SEE = 706; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_mul_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_int(Rd, Rn, H, Rm, M, L, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_not : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize == 8 & 'elements in {8, 16} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_not (d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, not_vec(element)) + }; + V_set(d, datasize) = result +} + +val decode_not_advsimd_aarch64_instrs_vector_arithmetic_unary_not : (bits(5), bits(5), bits(1)) -> unit + +function decode_not_advsimd_aarch64_instrs_vector_arithmetic_unary_not (Rd, Rn, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 8); + execute_aarch64_instrs_vector_arithmetic_unary_not(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 707) = { + SEE = 707; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Q = Slice(__opcode, 30, 1); + decode_not_advsimd_aarch64_instrs_vector_arithmetic_unary_not(Rd, Rn, Q) +} + +val execute_aarch64_instrs_integer_pac_pacda_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_pacda_dp_1src (d, n, source_is_sp) = { + if source_is_sp then { + X_set(d, 64) = AddPACDA(X_read(d, 64), SP_read()) + } else { + X_set(d, 64) = AddPACDA(X_read(d, 64), X_read(n, 64)) + } +} + +val decode_pacda_aarch64_instrs_integer_pac_pacda_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_pacda_aarch64_instrs_integer_pac_pacda_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_pacda_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 708) = { + SEE = 708; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_pacda_aarch64_instrs_integer_pac_pacda_dp_1src(Rd, Rn, Z) +} + +val execute_aarch64_instrs_integer_pac_pacdb_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_pacdb_dp_1src (d, n, source_is_sp) = { + if source_is_sp then { + X_set(d, 64) = AddPACDB(X_read(d, 64), SP_read()) + } else { + X_set(d, 64) = AddPACDB(X_read(d, 64), X_read(n, 64)) + } +} + +val decode_pacdb_aarch64_instrs_integer_pac_pacdb_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_pacdb_aarch64_instrs_integer_pac_pacdb_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_pacdb_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 709) = { + SEE = 709; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_pacdb_aarch64_instrs_integer_pac_pacdb_dp_1src(Rd, Rn, Z) +} + +val execute_aarch64_instrs_integer_pac_pacga_dp_2src : forall 'd 'm 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_pacga_dp_2src (d, m, n, source_is_sp) = { + if source_is_sp then { + X_set(d, 64) = AddPACGA(X_read(n, 64), SP_read()) + } else { + X_set(d, 64) = AddPACGA(X_read(n, 64), X_read(m, 64)) + } +} + +val decode_pacga_aarch64_instrs_integer_pac_pacga_dp_2src : (bits(5), bits(5), bits(5)) -> unit + +function decode_pacga_aarch64_instrs_integer_pac_pacga_dp_2src (Rd, Rn, Rm) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if m == 31 then { + source_is_sp = true + }; + execute_aarch64_instrs_integer_pac_pacga_dp_2src(d, m, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 710) = { + SEE = 710; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_pacga_aarch64_instrs_integer_pac_pacga_dp_2src(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_integer_pac_pacia_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_pacia_dp_1src (d, n, source_is_sp) = { + if HavePACExt() then { + if source_is_sp then { + X_set(d, 64) = AddPACIA(X_read(d, 64), SP_read()) + } else { + X_set(d, 64) = AddPACIA(X_read(d, 64), X_read(n, 64)) + } + }; + () +} + +val decode_pacia_aarch64_instrs_integer_pac_pacia_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_pacia_aarch64_instrs_integer_pac_pacia_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_pacia_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 711) = { + SEE = 711; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_pacia_aarch64_instrs_integer_pac_pacia_dp_1src(Rd, Rn, Z) +} + +val decode_pacia_aarch64_instrs_integer_pac_pacia_hint : (bits(3), bits(4)) -> unit + +function decode_pacia_aarch64_instrs_integer_pac_pacia_hint (op2, CRm) = { + d : {17, 30} = 17; + n : int = undefined; + source_is_sp : bool = false; + match CRm @ op2 { + 0b0011000 => { + d = 30; + n = 31 + }, + 0b0011001 => { + d = 30; + source_is_sp = true; + if HaveBTIExt() then { + SetBTypeCompatible(BTypeCompatible_PACIXSP()) + }; + () + }, + 0b0001000 => { + d = 17; + n = 16 + }, + 0b0001010 => { + throw(Error_See("PACIB")) + }, + 0b0001100 => { + throw(Error_See("AUTIA")) + }, + 0b0001110 => { + throw(Error_See("AUTIB")) + }, + [bitzero, bitzero, bitone, bitone, bitzero, bitone, _] => { + throw(Error_See("PACIB")) + }, + [bitzero, bitzero, bitone, bitone, bitone, bitzero, _] => { + throw(Error_See("AUTIA")) + }, + [bitzero, bitzero, bitone, bitone, bitone, bitone, _] => { + throw(Error_See("AUTIB")) + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + _ => { + throw(Error_See("HINT")) + } + }; + let 'n = n; + let 'd = d; + assert(constraint((0 <= 'n & 'n <= 31))); + execute_aarch64_instrs_integer_pac_pacia_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, bitone, bitzero, bitzero, _, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 712) = { + SEE = 712; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_pacia_aarch64_instrs_integer_pac_pacia_hint(op2, CRm) +} + +val execute_aarch64_instrs_integer_pac_pacib_dp_1src : forall 'd 'n ('source_is_sp : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bool('source_is_sp)) -> unit + +function execute_aarch64_instrs_integer_pac_pacib_dp_1src (d, n, source_is_sp) = { + if HavePACExt() then { + if source_is_sp then { + X_set(d, 64) = AddPACIB(X_read(d, 64), SP_read()) + } else { + X_set(d, 64) = AddPACIB(X_read(d, 64), X_read(n, 64)) + } + }; + () +} + +val decode_pacib_aarch64_instrs_integer_pac_pacib_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_pacib_aarch64_instrs_integer_pac_pacib_dp_1src (Rd, Rn, Z) = { + source_is_sp : bool = false; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if Z == 0b0 then { + if n == 31 then { + source_is_sp = true + }; + () + } else { + if n != 31 then { + throw(Error_Undefined()) + }; + () + }; + execute_aarch64_instrs_integer_pac_pacib_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 713) = { + SEE = 713; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Z = Slice(__opcode, 13, 1); + decode_pacib_aarch64_instrs_integer_pac_pacib_dp_1src(Rd, Rn, Z) +} + +val decode_pacib_aarch64_instrs_integer_pac_pacib_hint : (bits(3), bits(4)) -> unit + +function decode_pacib_aarch64_instrs_integer_pac_pacib_hint (op2, CRm) = { + d : {17, 30} = 17; + n : int = undefined; + source_is_sp : bool = false; + match CRm @ op2 { + 0b0011010 => { + d = 30; + n = 31 + }, + 0b0011011 => { + d = 30; + source_is_sp = true; + if HaveBTIExt() then { + SetBTypeCompatible(BTypeCompatible_PACIXSP()) + }; + () + }, + 0b0001010 => { + d = 17; + n = 16 + }, + 0b0001000 => { + throw(Error_See("PACIA")) + }, + 0b0001100 => { + throw(Error_See("AUTIA")) + }, + 0b0001110 => { + throw(Error_See("AUTIB")) + }, + [bitzero, bitzero, bitone, bitone, bitzero, bitzero, _] => { + throw(Error_See("PACIA")) + }, + [bitzero, bitzero, bitone, bitone, bitone, bitzero, _] => { + throw(Error_See("AUTIA")) + }, + [bitzero, bitzero, bitone, bitone, bitone, bitone, _] => { + throw(Error_See("AUTIB")) + }, + 0b0000111 => { + throw(Error_See("XPACLRI")) + }, + _ => { + throw(Error_See("HINT")) + } + }; + let 'n = n; + let 'd = d; + assert(constraint((0 <= 'n & 'n <= 31))); + execute_aarch64_instrs_integer_pac_pacib_dp_1src(d, n, source_is_sp) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, bitone, bitzero, bitone, _, bitone, bitone, bitone, bitone, bitone] as __opcode)) if SEE < 714) = { + SEE = 714; + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + decode_pacib_aarch64_instrs_integer_pac_pacib_hint(op2, CRm) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_poly : forall 'd 'datasize 'elements 'esize 'm 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_poly (d, datasize, elements, esize, m, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + result : bits(2 * 'datasize) = undefined; + element1 : bits('esize) = undefined; + element2 : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = Elem_read(operand1, e, esize); + element2 = Elem_read(operand2, e, esize); + result = Elem_set(result, e, 2 * esize, PolynomialMult(element1, element2)) + }; + V_set(d, 2 * datasize) = result +} + +val decode_pmull_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_mul_poly : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_pmull_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_mul_poly (Rd, Rn, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b01 | size == 0b10 then { + throw(Error_Undefined()) + }; + if size == 0b11 & not_bool(HaveBit128PMULLExt()) then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_poly(d, datasize, elements, esize, m, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 715) = { + SEE = 715; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_pmull_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_mul_poly(Rd, Rn, Rm, size, Q) +} + +val execute_aarch64_instrs_memory_single_general_immediate_unsigned : forall 'datasize ('is_signed : Bool) 'n ('nontemporal : Bool) ('postindex : Bool) 'regsize ('rt_unknown : Bool) 't ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't & 't <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (int('datasize), MemOp, int('n), bool('nontemporal), bits(64), bool('postindex), int('regsize), bool('rt_unknown), bool('is_signed), int('t), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_single_general_immediate_unsigned (datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data : bits('datasize) = undefined; + let privileged : bool = PSTATE.EL != EL0; + let accdesc : AccessDescriptor = CreateAccDescGPR(memop, nontemporal, privileged, tagchecked); + if n == 31 then { + if memop != MemOp_PREFETCH then { + CheckSPAlignment() + }; + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown then { + data = __UNKNOWN_bits(datasize) + } else { + data = X_read(t, datasize) + }; + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), false, t, regsize == 64, false) + }; + Mem_set(address, DIV(datasize, 8), accdesc) = data + }, + MemOp_LOAD => { + if not_bool(wback) then { + AArch64_SetLSInstructionSyndrome(DIV(datasize, 8), is_signed, t, regsize == 64, false) + }; + let data : bits('datasize) = Mem_read(address, DIV(datasize, 8), accdesc); + if is_signed then { + assert(constraint(('datasize > 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = SignExtend(data, regsize) + } else { + assert(constraint(('datasize >= 0 & 'regsize >= 'datasize))); + X_set(t, regsize) = ZeroExtend(data, regsize) + } + }, + MemOp_PREFETCH => { + Prefetch(address, t[4 .. 0]) + } + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_prfm_imm_aarch64_instrs_memory_single_general_immediate_unsigned : (bits(5), bits(5), bits(12), bits(2), bits(2)) -> unit + +function decode_prfm_imm_aarch64_instrs_memory_single_general_immediate_unsigned (Rt, Rn, imm12, opc, size) = { + wback : bool = false; + let postindex : bool = false; + let 'scale = UInt(size); + let offset : bits(64) = LSL(ZeroExtend(imm12, 64), scale); + let 'n = UInt(Rn); + let 't = UInt(Rt); + let nontemporal : bool = false; + memop : MemOp = undefined; + is_signed : bool = undefined; + regsize : {32, 64} = 32; + if [opc[1]] == 0b0 then { + memop = if [opc[0]] == 0b1 then MemOp_LOAD else MemOp_STORE; + regsize = if size == 0b11 then 64 else 32; + is_signed = false + } else { + if size == 0b11 then { + memop = MemOp_PREFETCH; + if [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + () + } else { + memop = MemOp_LOAD; + if size == 0b10 & [opc[0]] == 0b1 then { + throw(Error_Undefined()) + }; + regsize = if [opc[0]] == 0b1 then 32 else 64; + is_signed = true + } + }; + let 'regsize = regsize; + let 'datasize = (8 << scale); + let tagchecked : bool = memop != MemOp_PREFETCH & (wback | n != 31); + wb_unknown : bool = false; + rt_unknown : bool = false; + c : Constraint = undefined; + if ((memop == MemOp_LOAD & wback) & n == t) & n != 31 then { + c = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & n == t) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_single_general_immediate_unsigned(datasize, memop, n, nontemporal, offset, postindex, regsize, rt_unknown, is_signed, t, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 716) = { + SEE = 716; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm12 = Slice(__opcode, 10, 12); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_prfm_imm_aarch64_instrs_memory_single_general_immediate_unsigned(Rt, Rn, imm12, opc, size) +} + +val execute_aarch64_instrs_vector_crypto_sha3_rax1 : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3_rax1 (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + V_set(d, 128) = EOR(Vn, ROL(Vm[127 .. 64], 1) @ ROL(Vm[63 .. 0], 1)) +} + +val decode_rax1_advsimd_aarch64_instrs_vector_crypto_sha3_rax1 : (bits(5), bits(5), bits(5)) -> unit + +function decode_rax1_advsimd_aarch64_instrs_vector_crypto_sha3_rax1 (Rd, Rn, Rm) = { + if not_bool(HaveSHA3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sha3_rax1(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 717) = { + SEE = 717; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_rax1_advsimd_aarch64_instrs_vector_crypto_sha3_rax1(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_rbit : forall 'd 'datasize 'elements 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize == 8 & 'elements in {8, 16} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_rbit (d, datasize, elements, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits('esize) = undefined; + rev : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + foreach (i from 0 to (esize - 1) by 1 in inc) { + rev[esize - 1 - i] = Bit([element[i]]) + }; + result = Elem_set(result, e, esize, rev) + }; + V_set(d, datasize) = result +} + +val decode_rbit_advsimd_aarch64_instrs_vector_arithmetic_unary_rbit : (bits(5), bits(5), bits(1)) -> unit + +function decode_rbit_advsimd_aarch64_instrs_vector_arithmetic_unary_rbit (Rd, Rn, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 8; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 8); + execute_aarch64_instrs_vector_arithmetic_unary_rbit(d, datasize, elements, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 718) = { + SEE = 718; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Q = Slice(__opcode, 30, 1); + decode_rbit_advsimd_aarch64_instrs_vector_arithmetic_unary_rbit(Rd, Rn, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_rbit : forall 'd 'datasize 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_rbit (d, datasize, n) = { + let operand : bits('datasize) = X_read(n, datasize); + result : bits('datasize) = undefined; + foreach (i from 0 to (datasize - 1) by 1 in inc) { + result[datasize - 1 - i] = Bit([operand[i]]) + }; + X_set(d, datasize) = result +} + +val decode_rbit_int_aarch64_instrs_integer_arithmetic_rbit : (bits(5), bits(5), bits(1)) -> unit + +function decode_rbit_int_aarch64_instrs_integer_arithmetic_rbit (Rd, Rn, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + execute_aarch64_instrs_integer_arithmetic_rbit(d, datasize, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 719) = { + SEE = 719; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sf = Slice(__opcode, 31, 1); + decode_rbit_int_aarch64_instrs_integer_arithmetic_rbit(Rd, Rn, sf) +} + +val execute_aarch64_instrs_memory_rcw_cas : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_cas (acquire, n, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(t, 64); + let compdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_CAS, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(s, 64) = readdata +} + +val decode_rcwcas_aarch64_instrs_memory_rcw_cas : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwcas_aarch64_instrs_memory_rcw_cas (Rt, Rn, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = false; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_cas(acquire, n, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 720) = { + SEE = 720; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwcas_aarch64_instrs_memory_rcw_cas(Rt, Rn, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcw_cas_128 : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_cas_128 (acquire, n, release, s, soft, t, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let s1 : bits(64) = X_read(s, 64); + let s2 : bits(64) = X_read(s + 1, 64); + let t1 : bits(64) = X_read(t, 64); + let t2 : bits(64) = X_read(t + 1, 64); + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_CAS, soft, acquire, release, tagchecked); + let compdata : bits(128) = if BigEndian(accdesc.acctype) then s1 @ s2 else + s2 @ s1; + let newdata : bits(128) = if BigEndian(accdesc.acctype) then t1 @ t2 else + t2 @ t1; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(s, 64) = readdata[127 .. 64]; + X_set(s + 1, 64) = readdata[63 .. 0] + } else { + X_set(s, 64) = readdata[63 .. 0]; + X_set(s + 1, 64) = readdata[127 .. 64] + } +} + +val decode_rcwcasp_aarch64_instrs_memory_rcw_cas_128 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwcasp_aarch64_instrs_memory_rcw_cas_128 (Rt, Rn, Rs, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if [Rs[0]] == 0b1 then { + throw(Error_Undefined()) + }; + if [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = false; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_cas_128(acquire, n, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 721) = { + SEE = 721; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwcasp_aarch64_instrs_memory_rcw_cas_128(Rt, Rn, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcw_ld_rcwclr : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_ld_rcwclr (acquire, n, op, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let compdata : bits(64) = __UNKNOWN_bits(64); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(t, 64) = readdata +} + +val decode_rcwclr_aarch64_instrs_memory_rcw_ld_rcwclr : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwclr_aarch64_instrs_memory_rcw_ld_rcwclr (Rt, Rn, opc, o3, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = false; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_ld_rcwclr(acquire, n, op, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 722) = { + SEE = 722; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwclr_aarch64_instrs_memory_rcw_ld_rcwclr(Rt, Rn, opc, o3, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcw_ld_128_rcwclrp : forall ('acquire : Bool) 'n ('release : Bool) ('soft : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), bool('soft), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_ld_128_rcwclrp (acquire, n, op, release, soft, t, t2, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let newdata : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let compdata : bits(128) = __UNKNOWN_bits(128); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = readdata[127 .. 64]; + X_set(t2, 64) = readdata[63 .. 0] + } else { + X_set(t, 64) = readdata[63 .. 0]; + X_set(t2, 64) = readdata[127 .. 64] + } +} + +val decode_rcwclrp_aarch64_instrs_memory_rcw_ld_128_rcwclrp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwclrp_aarch64_instrs_memory_rcw_ld_128_rcwclrp (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + let soft : bool = false; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_ld_128_rcwclrp(acquire, n, op, release, soft, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 723) = { + SEE = 723; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwclrp_aarch64_instrs_memory_rcw_ld_128_rcwclrp(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_cas : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_cas (acquire, n, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(t, 64); + let compdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_CAS, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(s, 64) = readdata +} + +val decode_rcwscas_aarch64_instrs_memory_rcws_cas : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwscas_aarch64_instrs_memory_rcws_cas (Rt, Rn, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = true; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_cas(acquire, n, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 724) = { + SEE = 724; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwscas_aarch64_instrs_memory_rcws_cas(Rt, Rn, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_cas_128 : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_cas_128 (acquire, n, release, s, soft, t, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let s1 : bits(64) = X_read(s, 64); + let s2 : bits(64) = X_read(s + 1, 64); + let t1 : bits(64) = X_read(t, 64); + let t2 : bits(64) = X_read(t + 1, 64); + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_CAS, soft, acquire, release, tagchecked); + let compdata : bits(128) = if BigEndian(accdesc.acctype) then s1 @ s2 else + s2 @ s1; + let newdata : bits(128) = if BigEndian(accdesc.acctype) then t1 @ t2 else + t2 @ t1; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(s, 64) = readdata[127 .. 64]; + X_set(s + 1, 64) = readdata[63 .. 0] + } else { + X_set(s, 64) = readdata[63 .. 0]; + X_set(s + 1, 64) = readdata[127 .. 64] + } +} + +val decode_rcwscasp_aarch64_instrs_memory_rcws_cas_128 : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwscasp_aarch64_instrs_memory_rcws_cas_128 (Rt, Rn, Rs, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if [Rs[0]] == 0b1 then { + throw(Error_Undefined()) + }; + if [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = true; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_cas_128(acquire, n, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 725) = { + SEE = 725; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwscasp_aarch64_instrs_memory_rcws_cas_128(Rt, Rn, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_ld_rcwsclr : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_ld_rcwsclr (acquire, n, op, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let compdata : bits(64) = __UNKNOWN_bits(64); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(t, 64) = readdata +} + +val decode_rcwsclr_aarch64_instrs_memory_rcws_ld_rcwsclr : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwsclr_aarch64_instrs_memory_rcws_ld_rcwsclr (Rt, Rn, opc, o3, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = true; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_ld_rcwsclr(acquire, n, op, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 726) = { + SEE = 726; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwsclr_aarch64_instrs_memory_rcws_ld_rcwsclr(Rt, Rn, opc, o3, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_ld_128_rcwsclrp : forall ('acquire : Bool) 'n ('release : Bool) ('soft : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), bool('soft), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_ld_128_rcwsclrp (acquire, n, op, release, soft, t, t2, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let newdata : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let compdata : bits(128) = __UNKNOWN_bits(128); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = readdata[127 .. 64]; + X_set(t2, 64) = readdata[63 .. 0] + } else { + X_set(t, 64) = readdata[63 .. 0]; + X_set(t2, 64) = readdata[127 .. 64] + } +} + +val decode_rcwsclrp_aarch64_instrs_memory_rcws_ld_128_rcwsclrp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwsclrp_aarch64_instrs_memory_rcws_ld_128_rcwsclrp (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + let soft : bool = true; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_ld_128_rcwsclrp(acquire, n, op, release, soft, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 727) = { + SEE = 727; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwsclrp_aarch64_instrs_memory_rcws_ld_128_rcwsclrp(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_memory_rcw_ld_rcwset : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_ld_rcwset (acquire, n, op, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let compdata : bits(64) = __UNKNOWN_bits(64); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(t, 64) = readdata +} + +val decode_rcwset_aarch64_instrs_memory_rcw_ld_rcwset : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwset_aarch64_instrs_memory_rcw_ld_rcwset (Rt, Rn, opc, o3, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = false; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_ld_rcwset(acquire, n, op, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 728) = { + SEE = 728; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwset_aarch64_instrs_memory_rcw_ld_rcwset(Rt, Rn, opc, o3, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcw_ld_128_rcwsetp : forall ('acquire : Bool) 'n ('release : Bool) ('soft : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), bool('soft), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_ld_128_rcwsetp (acquire, n, op, release, soft, t, t2, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let newdata : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let compdata : bits(128) = __UNKNOWN_bits(128); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = readdata[127 .. 64]; + X_set(t2, 64) = readdata[63 .. 0] + } else { + X_set(t, 64) = readdata[63 .. 0]; + X_set(t2, 64) = readdata[127 .. 64] + } +} + +val decode_rcwsetp_aarch64_instrs_memory_rcw_ld_128_rcwsetp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwsetp_aarch64_instrs_memory_rcw_ld_128_rcwsetp (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + let soft : bool = false; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_ld_128_rcwsetp(acquire, n, op, release, soft, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 729) = { + SEE = 729; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwsetp_aarch64_instrs_memory_rcw_ld_128_rcwsetp(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_ld_rcwsset : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_ld_rcwsset (acquire, n, op, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let compdata : bits(64) = __UNKNOWN_bits(64); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(t, 64) = readdata +} + +val decode_rcwsset_aarch64_instrs_memory_rcws_ld_rcwsset : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwsset_aarch64_instrs_memory_rcws_ld_rcwsset (Rt, Rn, opc, o3, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = true; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_ld_rcwsset(acquire, n, op, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 730) = { + SEE = 730; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwsset_aarch64_instrs_memory_rcws_ld_rcwsset(Rt, Rn, opc, o3, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_ld_128_rcwssetp : forall ('acquire : Bool) 'n ('release : Bool) ('soft : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), MemAtomicOp, bool('release), bool('soft), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_ld_128_rcwssetp (acquire, n, op, release, soft, t, t2, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(op, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let newdata : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let compdata : bits(128) = __UNKNOWN_bits(128); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = readdata[127 .. 64]; + X_set(t2, 64) = readdata[63 .. 0] + } else { + X_set(t, 64) = readdata[63 .. 0]; + X_set(t2, 64) = readdata[127 .. 64] + } +} + +val decode_rcwssetp_aarch64_instrs_memory_rcws_ld_128_rcwssetp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwssetp_aarch64_instrs_memory_rcws_ld_128_rcwssetp (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + let soft : bool = true; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let op : MemAtomicOp = if opc == 0b001 then MemAtomicOp_BIC else + MemAtomicOp_ORR; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_ld_128_rcwssetp(acquire, n, op, release, soft, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 731) = { + SEE = 731; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwssetp_aarch64_instrs_memory_rcws_ld_128_rcwssetp(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_swp : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_swp (acquire, n, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_SWP, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let compdata : bits(64) = __UNKNOWN_bits(64); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(t, 64) = readdata +} + +val decode_rcwsswp_aarch64_instrs_memory_rcws_swp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwsswp_aarch64_instrs_memory_rcws_swp (Rt, Rn, opc, o3, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = true; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_swp(acquire, n, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 732) = { + SEE = 732; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwsswp_aarch64_instrs_memory_rcws_swp(Rt, Rn, opc, o3, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcws_swp_128 : forall ('acquire : Bool) 'n ('release : Bool) ('soft : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), bool('soft), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcws_swp_128 (acquire, n, release, soft, t, t2, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_SWP, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let newdata : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let compdata : bits(128) = __UNKNOWN_bits(128); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = readdata[127 .. 64]; + X_set(t2, 64) = readdata[63 .. 0] + } else { + X_set(t, 64) = readdata[63 .. 0]; + X_set(t2, 64) = readdata[127 .. 64] + } +} + +val decode_rcwsswpp_aarch64_instrs_memory_rcws_swp_128 : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwsswpp_aarch64_instrs_memory_rcws_swp_128 (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + let soft : bool = true; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcws_swp_128(acquire, n, release, soft, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 733) = { + SEE = 733; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwsswpp_aarch64_instrs_memory_rcws_swp_128(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_memory_rcw_swp : forall ('acquire : Bool) 'n ('release : Bool) 's ('soft : Bool) 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), int('s), bool('soft), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_swp (acquire, n, release, s, soft, t, tagchecked) = { + if IsD128Enabled(PSTATE.EL) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + let newdata : bits(64) = X_read(s, 64); + readdata : bits(64) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_SWP, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let compdata : bits(64) = __UNKNOWN_bits(64); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + X_set(t, 64) = readdata +} + +val decode_rcwswp_aarch64_instrs_memory_rcw_swp : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwswp_aarch64_instrs_memory_rcw_swp (Rt, Rn, opc, o3, Rs, R, A, S) = { + if not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let soft : bool = false; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_swp(acquire, n, release, s, soft, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 734) = { + SEE = 734; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwswp_aarch64_instrs_memory_rcw_swp(Rt, Rn, opc, o3, Rs, R, A, S) +} + +val execute_aarch64_instrs_memory_rcw_swp_128 : forall ('acquire : Bool) 'n ('release : Bool) ('soft : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), bool('soft), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_rcw_swp_128 (acquire, n, release, soft, t, t2, tagchecked) = { + if not_bool(IsD128Enabled(PSTATE.EL)) then { + throw(Error_Undefined()) + }; + address : bits(64) = undefined; + readdata : bits(128) = undefined; + nzcv : bits(4) = undefined; + let accdesc : AccessDescriptor = CreateAccDescRCW(MemAtomicOp_SWP, soft, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let newdata : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let compdata : bits(128) = __UNKNOWN_bits(128); + (nzcv, readdata) = MemAtomicRCW(address, compdata, newdata, accdesc); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv; + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = readdata[127 .. 64]; + X_set(t2, 64) = readdata[63 .. 0] + } else { + X_set(t, 64) = readdata[63 .. 0]; + X_set(t2, 64) = readdata[127 .. 64] + } +} + +val decode_rcwswpp_aarch64_instrs_memory_rcw_swp_128 : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_rcwswpp_aarch64_instrs_memory_rcw_swp_128 (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(Have128BitDescriptorExt()) | not_bool(HaveTHExt()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + let soft : bool = false; + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_rcw_swp_128(acquire, n, release, soft, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 735) = { + SEE = 735; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_rcwswpp_aarch64_instrs_memory_rcw_swp_128(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_integer_arithmetic_rev : forall 'container_size 'd 'datasize 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31 & 'container_size in {16, 32, 64}). + (int('container_size), int('d), int('datasize), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_rev (container_size, d, datasize, n) = { + let operand : bits('datasize) = X_read(n, datasize); + result : bits('datasize) = undefined; + let 'containers = DIV(datasize, container_size); + let 'elements_per_container = DIV(container_size, 8); + index : int = 0; + rev_index : int = undefined; + foreach (c from 0 to (containers - 1) by 1 in inc) { + rev_index = index + (elements_per_container - 1) * 8; + foreach (e from 0 to (elements_per_container - 1) by 1 in inc) { + let 'rev_index = rev_index in + { + let 'index = index; + assert(constraint((0 <= 'rev_index & 'rev_index + 7 < 'datasize))); + assert(constraint((0 <= 'index & 'index + 7 < 'datasize))); + result[rev_index + 7 .. rev_index] = operand[index + 7 .. index] + }; + index = index + 8; + rev_index = rev_index - 8 + } + }; + X_set(d, datasize) = result +} + +val decode_rev_aarch64_instrs_integer_arithmetic_rev : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_rev_aarch64_instrs_integer_arithmetic_rev (Rd, Rn, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + container_size : {16, 32, 64} = 16; + match opc { + 0b00 => { + Unreachable() + }, + 0b01 => { + container_size = 16 + }, + 0b10 => { + container_size = 32 + }, + 0b11 => { + if sf == 0b0 then { + throw(Error_Undefined()) + }; + container_size = 64 + } + }; + let 'container_size = container_size; + execute_aarch64_instrs_integer_arithmetic_rev(container_size, d, datasize, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 736) = { + SEE = 736; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 10, 2); + let sf = Slice(__opcode, 31, 1); + decode_rev_aarch64_instrs_integer_arithmetic_rev(Rd, Rn, opc, sf) +} + +val decode_rev16_int_aarch64_instrs_integer_arithmetic_rev : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_rev16_int_aarch64_instrs_integer_arithmetic_rev (Rd, Rn, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + container_size : {16, 32, 64} = 16; + match opc { + 0b00 => { + Unreachable() + }, + 0b01 => { + container_size = 16 + }, + 0b10 => { + container_size = 32 + }, + 0b11 => { + if sf == 0b0 then { + throw(Error_Undefined()) + }; + container_size = 64 + } + }; + let 'container_size = container_size; + execute_aarch64_instrs_integer_arithmetic_rev(container_size, d, datasize, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 737) = { + SEE = 737; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 10, 2); + let sf = Slice(__opcode, 31, 1); + decode_rev16_int_aarch64_instrs_integer_arithmetic_rev(Rd, Rn, opc, sf) +} + +val decode_rev32_int_aarch64_instrs_integer_arithmetic_rev : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_rev32_int_aarch64_instrs_integer_arithmetic_rev (Rd, Rn, opc, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'datasize = if sf == 0b1 then 64 else 32; + container_size : {16, 32, 64} = 16; + match opc { + 0b00 => { + Unreachable() + }, + 0b01 => { + container_size = 16 + }, + 0b10 => { + container_size = 32 + }, + 0b11 => { + if sf == 0b0 then { + throw(Error_Undefined()) + }; + container_size = 64 + } + }; + let 'container_size = container_size; + execute_aarch64_instrs_integer_arithmetic_rev(container_size, d, datasize, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 738) = { + SEE = 738; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 10, 2); + let sf = Slice(__opcode, 31, 1); + decode_rev32_int_aarch64_instrs_integer_arithmetic_rev(Rd, Rn, opc, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_rev : forall 'containers 'd 'datasize 'elements_per_container 'esize 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('containers), int('d), int('datasize), int('elements_per_container), int('esize), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_rev (containers, d, datasize, elements_per_container, esize, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : int = 0; + rev_element : int = undefined; + foreach (c from 0 to (containers - 1) by 1 in inc) { + rev_element = element + elements_per_container - 1; + foreach (e from 0 to (elements_per_container - 1) by 1 in inc) { + let 'rev_element = rev_element in + { + let 'element = element; + result = Elem_set(result, rev_element, esize, Elem_read(operand, element, esize)) + }; + element = element + 1; + rev_element = rev_element - 1 + } + }; + V_set(d, datasize) = result +} + +val decode_rev16_advsimd_aarch64_instrs_vector_arithmetic_unary_rev : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_rev16_advsimd_aarch64_instrs_vector_arithmetic_unary_rev (Rd, Rn, o0, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let op : bits(2) = o0 @ U; + if UInt(op) + UInt(size) >= 3 then { + throw(Error_Undefined()) + }; + container_size : {16, 32, 64} = 16; + match op { + 0b10 => { + container_size = 16 + }, + 0b01 => { + container_size = 32 + }, + 0b00 => { + container_size = 64 + }, + _ => () + }; + let 'container_size = container_size; + let 'containers = DIV(datasize, container_size); + let 'elements_per_container = DIV(container_size, esize); + execute_aarch64_instrs_vector_arithmetic_unary_rev(containers, d, datasize, elements_per_container, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 739) = { + SEE = 739; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_rev16_advsimd_aarch64_instrs_vector_arithmetic_unary_rev(Rd, Rn, o0, size, U, Q) +} + +val decode_rev32_advsimd_aarch64_instrs_vector_arithmetic_unary_rev : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_rev32_advsimd_aarch64_instrs_vector_arithmetic_unary_rev (Rd, Rn, o0, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let op : bits(2) = o0 @ U; + if UInt(op) + UInt(size) >= 3 then { + throw(Error_Undefined()) + }; + container_size : {16, 32, 64} = 16; + match op { + 0b10 => { + container_size = 16 + }, + 0b01 => { + container_size = 32 + }, + 0b00 => { + container_size = 64 + }, + _ => () + }; + let 'container_size = container_size; + let 'containers = DIV(datasize, container_size); + let 'elements_per_container = DIV(container_size, esize); + execute_aarch64_instrs_vector_arithmetic_unary_rev(containers, d, datasize, elements_per_container, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 740) = { + SEE = 740; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_rev32_advsimd_aarch64_instrs_vector_arithmetic_unary_rev(Rd, Rn, o0, size, U, Q) +} + +val decode_rev64_advsimd_aarch64_instrs_vector_arithmetic_unary_rev : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_rev64_advsimd_aarch64_instrs_vector_arithmetic_unary_rev (Rd, Rn, o0, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let op : bits(2) = o0 @ U; + if UInt(op) + UInt(size) >= 3 then { + throw(Error_Undefined()) + }; + container_size : {16, 32, 64} = 16; + match op { + 0b10 => { + container_size = 16 + }, + 0b01 => { + container_size = 32 + }, + 0b00 => { + container_size = 64 + }, + _ => () + }; + let 'container_size = container_size; + let 'containers = DIV(datasize, container_size); + let 'elements_per_container = DIV(container_size, esize); + execute_aarch64_instrs_vector_arithmetic_unary_rev(containers, d, datasize, elements_per_container, esize, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 741) = { + SEE = 741; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_rev64_advsimd_aarch64_instrs_vector_arithmetic_unary_rev(Rd, Rn, o0, size, U, Q) +} + +val execute_aarch64_instrs_integer_flags_rmif : forall 'lsb 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'lsb & 'lsb <= 63). + (int('lsb), bits(4), int('n)) -> unit + +function execute_aarch64_instrs_integer_flags_rmif (lsb, mask, n) = { + let tmpreg : bits(64) = X_read(n, 64); + let tmp : bits(4) = (tmpreg @ tmpreg)[lsb + 3 .. lsb]; + if [mask[3]] == 0b1 then { + PSTATE.N = [tmp[3]] + }; + if [mask[2]] == 0b1 then { + PSTATE.Z = [tmp[2]] + }; + if [mask[1]] == 0b1 then { + PSTATE.C = [tmp[1]] + }; + if [mask[0]] == 0b1 then { + PSTATE.V = [tmp[0]] + }; + () +} + +val decode_rmif_aarch64_instrs_integer_flags_rmif : (bits(4), bits(5), bits(6), bits(1)) -> unit + +function decode_rmif_aarch64_instrs_integer_flags_rmif (mask, Rn, imm6, sf) = { + if not_bool(HaveFlagManipulateExt()) | sf != 0b1 then { + throw(Error_Undefined()) + }; + let 'lsb = UInt(imm6); + let 'n = UInt(Rn); + execute_aarch64_instrs_integer_flags_rmif(lsb, mask, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitzero, _, _, _, _] as __opcode)) if SEE < 742) = { + SEE = 742; + let mask = Slice(__opcode, 0, 4); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 15, 6); + let sf = Slice(__opcode, 31, 1); + decode_rmif_aarch64_instrs_integer_flags_rmif(mask, Rn, imm6, sf) +} + +val execute_aarch64_instrs_memory_single_general_range : forall 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31). + (int('m), int('n), bits(6)) -> unit + +function execute_aarch64_instrs_memory_single_general_range (m, n, operation) = { + let address : bits(64) = if n == 31 then SP_read() else X_read(n, 64); + let metadata : bits(64) = X_read(m, 64); + let 'stride = SInt(metadata[59 .. 38]); + let 'count = UInt(metadata[37 .. 22]) + 1; + let 'length = SInt(metadata[21 .. 0]); + reuse : int = undefined; + if metadata[63 .. 60] == 0b0000 then { + reuse = negate(1) + } else { + reuse = (32768 << (15 - UInt(metadata[63 .. 60]))) + }; + let 'reuse = reuse; + Hint_RangePrefetch(address, length, stride, count, reuse, operation) +} + +val decode_rprfm_reg_aarch64_instrs_memory_single_general_range : (bits(5), bits(5), bits(1), bits(3), bits(5), bits(2), bits(2)) -> unit + +function decode_rprfm_reg_aarch64_instrs_memory_single_general_range (Rt, Rn, S, option_name, Rm, opc, size) = { + let operation : bits(6) = (([option_name[2]] @ [option_name[0]]) @ S) @ Rt[2 .. 0]; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_memory_single_general_range(m, n, operation) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, bitone, _, _, bitone, bitzero, _, _, _, _, _, bitone, bitone, _, _, _] as __opcode)) if SEE < 743) = { + SEE = 743; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 12, 1); + let option_name = Slice(__opcode, 13, 3); + let Rm = Slice(__opcode, 16, 5); + let opc = Slice(__opcode, 22, 2); + let size = Slice(__opcode, 30, 2); + decode_rprfm_reg_aarch64_instrs_memory_single_general_range(Rt, Rn, S, option_name, Rm, opc, size) +} + +val execute_aarch64_instrs_vector_shift_right_narrow_logical : forall 'd 'datasize 'elements 'esize 'n 'part ('round : Bool) 'shift, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {4, 8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part), bool('round), int('shift)) -> unit + +function execute_aarch64_instrs_vector_shift_right_narrow_logical (d, datasize, elements, esize, n, part, round, shift) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize * 2) = V_read(n, datasize * 2); + result : bits('datasize) = undefined; + element : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = RShr(UInt(Elem_read(operand, e, 2 * esize)), shift, round); + result = Elem_set(result, e, esize, element[esize - 1 .. 0]) + }; + Vpart_set(d, part, datasize) = result +} + +val decode_rshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_logical : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_rshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_logical (Rd, Rn, op, immb, immh, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_logical(d, datasize, elements, esize, n, part, round, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 744) = { + SEE = 744; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let Q = Slice(__opcode, 30, 1); + decode_rshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_logical(Rd, Rn, op, immb, immh, Q) +} + +val decode_shrn_advsimd_aarch64_instrs_vector_shift_right_narrow_logical : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_shrn_advsimd_aarch64_instrs_vector_shift_right_narrow_logical (Rd, Rn, op, immb, immh, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_logical(d, datasize, elements, esize, n, part, round, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 745) = { + SEE = 745; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let Q = Slice(__opcode, 30, 1); + decode_shrn_advsimd_aarch64_instrs_vector_shift_right_narrow_logical(Rd, Rn, op, immb, immh, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_diff : forall ('accumulate : Bool) 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (bool('accumulate), int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_diff (accumulate, d, datasize, elements, esize, m, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + element1 : int = undefined; + element2 : int = undefined; + absdiff : bits('esize) = undefined; + result : bits('datasize) = if accumulate then V_read(d, datasize) else + Zeros(datasize); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + absdiff = Abs(element1 - element2)[esize - 1 .. 0]; + result = Elem_set(result, e, esize, Elem_read(result, e, esize) + absdiff) + }; + V_set(d, datasize) = result +} + +val decode_saba_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_saba_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff (Rd, Rn, ac, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let accumulate : bool = ac == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_diff(accumulate, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 746) = { + SEE = 746; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_saba_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff(Rd, Rn, ac, Rm, size, U, Q) +} + +val decode_sabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff (Rd, Rn, ac, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let accumulate : bool = ac == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_diff(accumulate, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 747) = { + SEE = 747; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff(Rd, Rn, ac, Rm, size, U, Q) +} + +val decode_uaba_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uaba_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff (Rd, Rn, ac, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let accumulate : bool = ac == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_diff(accumulate, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 748) = { + SEE = 748; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uaba_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff(Rd, Rn, ac, Rm, size, U, Q) +} + +val decode_uabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff (Rd, Rn, ac, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let accumulate : bool = ac == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_diff(accumulate, d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 749) = { + SEE = 749; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let ac = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uabd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_diff(Rd, Rn, ac, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_diff : forall ('accumulate : Bool) 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (bool('accumulate), int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_diff (accumulate, d, datasize, elements, esize, m, n, part, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + element1 : int = undefined; + element2 : int = undefined; + absdiff : bits(2 * 'esize) = undefined; + result : bits(2 * 'datasize) = if accumulate then V_read(d, 2 * datasize) + else + Zeros(2 * datasize); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + absdiff = Abs(element1 - element2)[2 * esize - 1 .. 0]; + result = Elem_set(result, e, 2 * esize, Elem_read(result, e, 2 * esize) + absdiff) + }; + V_set(d, 2 * datasize) = result +} + +val decode_sabal_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sabal_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff (Rd, Rn, op, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let accumulate : bool = op == 0b0; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_diff(accumulate, d, datasize, elements, esize, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 750) = { + SEE = 750; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sabal_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff(Rd, Rn, op, Rm, size, U, Q) +} + +val decode_sabdl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sabdl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff (Rd, Rn, op, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let accumulate : bool = op == 0b0; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_diff(accumulate, d, datasize, elements, esize, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 751) = { + SEE = 751; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sabdl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff(Rd, Rn, op, Rm, size, U, Q) +} + +val decode_uabal_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uabal_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff (Rd, Rn, op, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let accumulate : bool = op == 0b0; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_diff(accumulate, d, datasize, elements, esize, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 752) = { + SEE = 752; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uabal_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff(Rd, Rn, op, Rm, size, U, Q) +} + +val decode_uabdl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uabdl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff (Rd, Rn, op, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let accumulate : bool = op == 0b0; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_diff(accumulate, d, datasize, elements, esize, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 753) = { + SEE = 753; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uabdl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_diff(Rd, Rn, op, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_add_pairwise : forall ('acc : Bool) 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (bool('acc), int('d), int('datasize), int('elements), int('esize), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_add_pairwise (acc, d, datasize, elements, esize, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + sum : bits(2 * 'esize) = undefined; + op1 : int = undefined; + op2 : int = undefined; + if acc then { + result = V_read(d, datasize) + }; + foreach (e from 0 to (elements - 1) by 1 in inc) { + op1 = asl_Int(Elem_read(operand, 2 * e + 0, esize), is_unsigned); + op2 = asl_Int(Elem_read(operand, 2 * e + 1, esize), is_unsigned); + sum = (op1 + op2)[2 * esize - 1 .. 0]; + if acc then { + result = Elem_set(result, e, 2 * esize, Elem_read(result, e, 2 * esize) + sum) + } else { + result = Elem_set(result, e, 2 * esize, sum) + } + }; + V_set(d, datasize) = result +} + +val decode_sadalp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_sadalp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 2 * esize); + let acc : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_pairwise(acc, d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 754) = { + SEE = 754; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sadalp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise(Rd, Rn, op, size, U, Q) +} + +val decode_saddlp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_saddlp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 2 * esize); + let acc : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_pairwise(acc, d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 755) = { + SEE = 755; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_saddlp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise(Rd, Rn, op, size, U, Q) +} + +val decode_uadalp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_uadalp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 2 * esize); + let acc : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_pairwise(acc, d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 756) = { + SEE = 756; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uadalp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise(Rd, Rn, op, size, U, Q) +} + +val decode_uaddlp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_uaddlp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 2 * esize); + let acc : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_pairwise(acc, d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 757) = { + SEE = 757; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uaddlp_advsimd_aarch64_instrs_vector_arithmetic_unary_add_pairwise(Rd, Rn, op, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('sub_op), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long (d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + sum : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + if sub_op then { + sum = element1 - element2 + } else { + sum = element1 + element2 + }; + result = Elem_set(result, e, 2 * esize, sum[2 * esize - 1 .. 0]) + }; + V_set(d, 2 * datasize) = result +} + +val decode_saddl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_saddl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 758) = { + SEE = 758; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_saddl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_ssubl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_ssubl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 759) = { + SEE = 759; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ssubl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_uaddl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uaddl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 760) = { + SEE = 760; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uaddl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_usubl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_usubl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 761) = { + SEE = 761; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_usubl_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_long(Rd, Rn, o1, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_reduce_add_long : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_reduce_add_long (d, datasize, elements, esize, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + sum : int = asl_Int(Elem_read(operand, 0, esize), is_unsigned); + foreach (e from 1 to (elements - 1) by 1 in inc) { + sum = sum + asl_Int(Elem_read(operand, e, esize), is_unsigned) + }; + let 'sum = sum; + V_set(d, 2 * esize) = sum[2 * esize - 1 .. 0] +} + +val decode_saddlv_advsimd_aarch64_instrs_vector_reduce_add_long : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_saddlv_advsimd_aarch64_instrs_vector_reduce_add_long (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b100 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_reduce_add_long(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 762) = { + SEE = 762; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_saddlv_advsimd_aarch64_instrs_vector_reduce_add_long(Rd, Rn, size, U, Q) +} + +val decode_uaddlv_advsimd_aarch64_instrs_vector_reduce_add_long : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uaddlv_advsimd_aarch64_instrs_vector_reduce_add_long (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b100 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_reduce_add_long(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 763) = { + SEE = 763; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uaddlv_advsimd_aarch64_instrs_vector_reduce_add_long(Rd, Rn, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('sub_op), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide (d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits(2 * 'datasize) = V_read(n, 2 * datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + sum : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, 2 * esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + if sub_op then { + sum = element1 - element2 + } else { + sum = element1 + element2 + }; + result = Elem_set(result, e, 2 * esize, sum[2 * esize - 1 .. 0]) + }; + V_set(d, 2 * datasize) = result +} + +val decode_saddw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_saddw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 764) = { + SEE = 764; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_saddw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_ssubw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_ssubw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 765) = { + SEE = 765; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ssubw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_uaddw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uaddw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 766) = { + SEE = 766; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uaddw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_usubw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_usubw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 767) = { + SEE = 767; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_usubw_advsimd_aarch64_instrs_vector_arithmetic_binary_disparate_add_sub_wide(Rd, Rn, o1, Rm, size, U, Q) +} + +val execute_aarch64_instrs_system_barriers_sb : unit -> unit + +function execute_aarch64_instrs_system_barriers_sb () = { + SpeculationBarrier() +} + +val decode_sb_aarch64_instrs_system_barriers_sb : (bits(2), bits(4)) -> unit + +function decode_sb_aarch64_instrs_system_barriers_sb (opc, CRm) = { + if not_bool(HaveSBExt()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_system_barriers_sb() +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110011000011111111 as __opcode)) if SEE < 768) = { + SEE = 768; + let opc = Slice(__opcode, 5, 2); + let CRm = Slice(__opcode, 8, 4); + if (([__opcode[8]] != 0b0 | [__opcode[9]] != 0b0) | [__opcode[10]] != 0b0) | [__opcode[11]] != 0b0 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_sb_aarch64_instrs_system_barriers_sb(opc, CRm) + } +} + +val execute_aarch64_instrs_vector_shift_conv_int_sisd : forall 'd 'datasize 'elements 'esize 'fracbits ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('fracbits), int('n), FPRounding, bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_shift_conv_int_sisd (d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + element : bits('esize) = undefined; + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FixedToFP(element, fracbits, is_unsigned, fpcr, rounding, esize)) + }; + V_set(d, 128) = result +} + +val decode_scvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_sisd : (bits(5), bits(5), bits(3), bits(4), bits(1)) -> unit + +function decode_scvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_sisd (Rd, Rn, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = esize; + let 'elements = 1; + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_shift_conv_int_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 769) = { + SEE = 769; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_scvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_sisd(Rd, Rn, immb, immh, U) +} + +val decode_scvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_simd : (bits(5), bits(5), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_scvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_simd (Rd, Rn, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_shift_conv_int_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 770) = { + SEE = 770; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_scvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_simd(Rd, Rn, immb, immh, U, Q) +} + +val decode_ucvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_sisd : (bits(5), bits(5), bits(3), bits(4), bits(1)) -> unit + +function decode_ucvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_sisd (Rd, Rn, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = esize; + let 'elements = 1; + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_shift_conv_int_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 771) = { + SEE = 771; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_ucvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_sisd(Rd, Rn, immb, immh, U) +} + +val decode_ucvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_simd : (bits(5), bits(5), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_ucvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_simd (Rd, Rn, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if (match immh { + [bitzero, bitzero, bitzero, _] => true, + _ => false + }) : bool | (match immh { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool & not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = if (match immh { + [bitone, _, _, _] => true, + _ => false + }) : bool then + 64 + else + if (match immh { + [bitzero, bitone, _, _] => true, + _ => false + }) : bool then + 32 + else + 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'fracbits = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let rounding : FPRounding = FPRoundingMode(FPCR_read()); + execute_aarch64_instrs_vector_shift_conv_int_sisd(d, datasize, elements, esize, fracbits, n, rounding, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 772) = { + SEE = 772; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ucvtf_advsimd_fix_aarch64_instrs_vector_shift_conv_int_simd(Rd, Rn, immb, immh, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {16, 32, 64} & 'datasize in {16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd (d, datasize, elements, esize, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + let fpcr : FPCRType = FPCR_read(); + let merge : bool = elements == 1 & IsMerging(fpcr); + result : bits(128) = if merge then V_read(d, 128) else Zeros(128); + let rounding : FPRounding = FPRoundingMode(fpcr); + element : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, esize); + result = Elem_set(result, e, esize, FixedToFP(element, 0, is_unsigned, fpcr, rounding, esize)) + }; + V_set(d, 128) = result +} + +val decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd (Rd, Rn, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 773) = { + SEE = 773; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(Rd, Rn, U) +} + +val decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_sisd (Rd, Rn, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 774) = { + SEE = 774; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_sisd(Rd, Rn, sz, U) +} + +val decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_simd (Rd, Rn, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 775) = { + SEE = 775; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_simd(Rd, Rn, U, Q) +} + +val decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_simd (Rd, Rn, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 776) = { + SEE = 776; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_scvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_simd(Rd, Rn, sz, U, Q) +} + +val decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd : (bits(5), bits(5), bits(1)) -> unit + +function decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd (Rd, Rn, U) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 777) = { + SEE = 777; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(Rd, Rn, U) +} + +val decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_sisd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_sisd (Rd, Rn, sz, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (32 << UInt(sz)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 778) = { + SEE = 778; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_sisd(Rd, Rn, sz, U) +} + +val decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_simd : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_simd (Rd, Rn, U, Q) = { + if not_bool(HaveFP16Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = 16; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 779) = { + SEE = 779; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_simd(Rd, Rn, U, Q) +} + +val decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_simd : (bits(5), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_simd (Rd, Rn, sz, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (sz @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (32 << UInt(sz)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_fp16_conv_int_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 780) = { + SEE = 780; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ucvtf_advsimd_int_aarch64_instrs_vector_arithmetic_unary_float_conv_int_simd(Rd, Rn, sz, U, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_div : forall 'd 'datasize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_div (d, datasize, m, n, is_unsigned) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + result : int = undefined; + if IsZero(operand2) then { + result = 0 + } else { + result = RoundTowardsZero(Real(asl_Int(operand1, is_unsigned)) / Real(asl_Int(operand2, is_unsigned))) + }; + let 'result = result; + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_sdiv_aarch64_instrs_integer_arithmetic_div : (bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_sdiv_aarch64_instrs_integer_arithmetic_div (Rd, Rn, o1, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let is_unsigned : bool = o1 == 0b0; + execute_aarch64_instrs_integer_arithmetic_div(d, datasize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 781) = { + SEE = 781; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 10, 1); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_sdiv_aarch64_instrs_integer_arithmetic_div(Rd, Rn, o1, Rm, sf) +} + +val decode_udiv_aarch64_instrs_integer_arithmetic_div : (bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_udiv_aarch64_instrs_integer_arithmetic_div (Rd, Rn, o1, Rm, sf) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if sf == 0b1 then 64 else 32; + let is_unsigned : bool = o1 == 0b0; + execute_aarch64_instrs_integer_arithmetic_div(d, datasize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 782) = { + SEE = 782; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 10, 1); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_udiv_aarch64_instrs_integer_arithmetic_div(Rd, Rn, o1, Rm, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp : forall 'd 'datasize 'elements 'esize ('is_signed : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_signed)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp (d, datasize, elements, esize, m, n, is_signed) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = V_read(d, datasize); + foreach (e from 0 to (elements - 1) by 1 in inc) { + res : int = 0; + element1 : int = undefined; + element2 : int = undefined; + foreach (i from 0 to 3 by 1 in inc) { + if is_signed then { + element1 = SInt(Elem_read(operand1, 4 * e + i, DIV(esize, 4))); + element2 = SInt(Elem_read(operand2, 4 * e + i, DIV(esize, 4))) + } else { + element1 = UInt(Elem_read(operand1, 4 * e + i, DIV(esize, 4))); + element2 = UInt(Elem_read(operand2, 4 * e + i, DIV(esize, 4))) + }; + res = res + element1 * element2 + }; + let 'res = res; + result = Elem_set(result, e, esize, Elem_read(result, e, esize) + res) + }; + V_set(d, datasize) = result +} + +val decode_sdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp (Rd, Rn, Rm, size, U, Q) = { + if not_bool(HaveDOTPExt()) then { + throw(Error_Undefined()) + }; + if size != 0b10 then { + throw(Error_Undefined()) + }; + let is_signed : bool = U == 0b0; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp(d, datasize, elements, esize, m, n, is_signed) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 783) = { + SEE = 783; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp(Rd, Rn, Rm, size, U, Q) +} + +val decode_udot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_udot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp (Rd, Rn, Rm, size, U, Q) = { + if not_bool(HaveDOTPExt()) then { + throw(Error_Undefined()) + }; + if size != 0b10 then { + throw(Error_Undefined()) + }; + let is_signed : bool = U == 0b0; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp(d, datasize, elements, esize, m, n, is_signed) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 784) = { + SEE = 784; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_udot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_dotp(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_dotp : forall 'd 'datasize 'elements 'esize 'index ('is_signed : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3} & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('index), int('m), int('n), bool('is_signed)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_dotp (d, datasize, elements, esize, index, m, n, is_signed) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits(128) = V_read(m, 128); + result : bits('datasize) = V_read(d, datasize); + foreach (e from 0 to (elements - 1) by 1 in inc) { + res : int = 0; + element1 : int = undefined; + element2 : int = undefined; + foreach (i from 0 to 3 by 1 in inc) { + if is_signed then { + element1 = SInt(Elem_read(operand1, 4 * e + i, DIV(esize, 4))); + element2 = SInt(Elem_read(operand2, 4 * index + i, DIV(esize, 4))) + } else { + element1 = UInt(Elem_read(operand1, 4 * e + i, DIV(esize, 4))); + element2 = UInt(Elem_read(operand2, 4 * index + i, DIV(esize, 4))) + }; + res = res + element1 * element2 + }; + let 'res = res; + result = Elem_set(result, e, esize, Elem_read(result, e, esize) + res) + }; + V_set(d, datasize) = result +} + +val decode_sdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_dotp : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_sdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_dotp (Rd, Rn, H, Rm, M, L, size, U, Q) = { + if not_bool(HaveDOTPExt()) then { + throw(Error_Undefined()) + }; + if size != 0b10 then { + throw(Error_Undefined()) + }; + let is_signed : bool = U == 0b0; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(M @ Rm); + let 'index = UInt(H @ L); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_element_dotp(d, datasize, elements, esize, index, m, n, is_signed) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 785) = { + SEE = 785; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_dotp(Rd, Rn, H, Rm, M, L, size, U, Q) +} + +val decode_udot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_dotp : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_udot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_dotp (Rd, Rn, H, Rm, M, L, size, U, Q) = { + if not_bool(HaveDOTPExt()) then { + throw(Error_Undefined()) + }; + if size != 0b10 then { + throw(Error_Undefined()) + }; + let is_signed : bool = U == 0b0; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(M @ Rm); + let 'index = UInt(H @ L); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_element_dotp(d, datasize, elements, esize, index, m, n, is_signed) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 786) = { + SEE = 786; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_udot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_dotp(Rd, Rn, H, Rm, M, L, size, U, Q) +} + +val execute_aarch64_instrs_memory_mcpymset_set : forall 'd 'n 's, + (0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bits(2), int('s), MOPSStage) -> unit + +function execute_aarch64_instrs_memory_mcpymset_set (d, n, options_name, s, stage) = { + toaddress : bits(64) = X_read(d, 64); + setsize : bits(64) = X_read(n, 64); + let data : bits(8) = X_read(s, 8); + nzcv : bits(4) = PSTATE.N @ (PSTATE.Z @ (PSTATE.C @ PSTATE.V)); + stagesetsize : bits(64) = undefined; + let is_setg : bool = false; + B : int = undefined; + let supports_option_a : bool = SETOptionA(); + let privileged : bool = if [options_name[0]] == 0b1 then + AArch64_IsUnprivAccessPriv() + else + PSTATE.EL != EL0; + let nontemporal : bool = [options_name[1]] == 0b1; + let accdesc : AccessDescriptor = CreateAccDescMOPS(MemOp_STORE, privileged, nontemporal); + if stage == MOPSStage_Prologue then { + if [setsize[63]] == 0b1 then { + setsize = 0x7FFFFFFFFFFFFFFF + }; + if supports_option_a then { + nzcv = 0b0000; + toaddress = toaddress + setsize; + setsize = Zeros(64) - setsize + } else { + nzcv = 0b0010 + }; + stagesetsize = SETPreSizeChoice(toaddress, setsize, is_setg); + assert([stagesetsize[63]] == [setsize[63]] | stagesetsize == Zeros(64)); + if SInt(setsize) > 0 then { + assert(SInt(stagesetsize) <= SInt(setsize)) + } else { + assert(SInt(stagesetsize) >= SInt(setsize)) + } + } else { + let postsize : bits(64) = SETPostSizeChoice(toaddress, setsize, is_setg); + assert([postsize[63]] == [setsize[63]] | postsize == Zeros(64)); + let zero_size_exceptions : bool = MemSetZeroSizeCheck(); + if zero_size_exceptions | SInt(setsize) != 0 then { + if supports_option_a then { + if [nzcv[1]] == 0b1 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + } else { + if [nzcv[1]] == 0b0 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + } + }; + if stage == MOPSStage_Main then { + stagesetsize = setsize - postsize; + if MemSetParametersIllformedM(toaddress, setsize, is_setg) then { + let wrong_option : bool = false; + let from_epilogue : bool = false; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + } else { + stagesetsize = postsize; + if setsize != postsize | MemSetParametersIllformedE(toaddress, setsize, is_setg) then { + let wrong_option : bool = false; + let from_epilogue : bool = true; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + } + }; + if SPESampleInFlight then { + SPESampleMemSet() + }; + if supports_option_a then { + while SInt(stagesetsize) < 0 do { + B = SETSizeChoice(toaddress, setsize, 1); + assert(B <= negate(1) * SInt(stagesetsize)); + let 'B = B in + { + assert(constraint('B * 8 >= 0)); + Mem_set(toaddress + setsize, B, accdesc) = Replicate(data, B) + }; + setsize = setsize + B; + stagesetsize = stagesetsize + B; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = setsize + }; + () + } + } else { + while UInt(stagesetsize) > 0 do { + B = SETSizeChoice(toaddress, setsize, 1); + assert(B <= UInt(stagesetsize)); + let 'B = B in + { + assert(constraint('B * 8 >= 0)); + Mem_set(toaddress, B, accdesc) = Replicate(data, B) + }; + toaddress = toaddress + B; + setsize = setsize - B; + stagesetsize = stagesetsize - B; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = setsize; + X_set(d, 64) = toaddress + }; + () + } + }; + if stage == MOPSStage_Prologue then { + X_set(n, 64) = setsize; + X_set(d, 64) = toaddress; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + () +} + +val decode_setp_aarch64_instrs_memory_mcpymset_set : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setp_aarch64_instrs_memory_mcpymset_set (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_set(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 787) = { + SEE = 787; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setp_aarch64_instrs_memory_mcpymset_set(Rd, Rn, op2, Rs, sz) +} + +val decode_setpn_aarch64_instrs_memory_mcpymset_set : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setpn_aarch64_instrs_memory_mcpymset_set (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_set(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 788) = { + SEE = 788; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setpn_aarch64_instrs_memory_mcpymset_set(Rd, Rn, op2, Rs, sz) +} + +val decode_setpt_aarch64_instrs_memory_mcpymset_set : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setpt_aarch64_instrs_memory_mcpymset_set (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_set(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 789) = { + SEE = 789; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setpt_aarch64_instrs_memory_mcpymset_set(Rd, Rn, op2, Rs, sz) +} + +val decode_setptn_aarch64_instrs_memory_mcpymset_set : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setptn_aarch64_instrs_memory_mcpymset_set (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_set(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 790) = { + SEE = 790; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setptn_aarch64_instrs_memory_mcpymset_set(Rd, Rn, op2, Rs, sz) +} + +val execute_aarch64_instrs_integer_flags_setf : forall 'msb 'n, + (0 <= 'n & 'n <= 31 & 'msb in {7, 15}). + (int('msb), int('n)) -> unit + +function execute_aarch64_instrs_integer_flags_setf (msb, n) = { + let tmpreg : bits(32) = X_read(n, 32); + PSTATE.N = [tmpreg[msb]]; + PSTATE.Z = if tmpreg[msb .. 0] == Zeros(msb + 1) then 0b1 else 0b0; + PSTATE.V = EOR([tmpreg[msb + 1]], [tmpreg[msb]]) +} + +val decode_setf_aarch64_instrs_integer_flags_setf : (bits(5), bits(1), bits(1)) -> unit + +function decode_setf_aarch64_instrs_integer_flags_setf (Rn, sz, sf) = { + if not_bool(HaveFlagManipulateExt()) | sf != 0b0 then { + throw(Error_Undefined()) + }; + let 'msb = if sz == 0b1 then 15 else 7; + let 'n = UInt(Rn); + execute_aarch64_instrs_integer_flags_setf(msb, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitone] as __opcode)) if SEE < 791) = { + SEE = 791; + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 14, 1); + let sf = Slice(__opcode, 31, 1); + decode_setf_aarch64_instrs_integer_flags_setf(Rn, sz, sf) +} + +val execute_aarch64_instrs_memory_mcpymset_setg : forall 'd 'n 's, + (0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n), bits(2), int('s), MOPSStage) -> unit + +function execute_aarch64_instrs_memory_mcpymset_setg (d, n, options_name, s, stage) = { + toaddress : bits(64) = X_read(d, 64); + setsize : bits(64) = X_read(n, 64); + let data : bits(8) = X_read(s, 8); + nzcv : bits(4) = PSTATE.N @ (PSTATE.Z @ (PSTATE.C @ PSTATE.V)); + stagesetsize : bits(64) = undefined; + let is_setg : bool = true; + B : int = undefined; + let supports_option_a : bool = SETGOptionA(); + let privileged : bool = if [options_name[0]] == 0b1 then + AArch64_IsUnprivAccessPriv() + else + PSTATE.EL != EL0; + let nontemporal : bool = [options_name[1]] == 0b1; + let accdesc : AccessDescriptor = CreateAccDescSTGMOPS(privileged, nontemporal); + if stage == MOPSStage_Prologue then { + if [setsize[63]] == 0b1 then { + setsize = 0x7FFFFFFFFFFFFFF0 + }; + if setsize != Zeros(64) & not_bool(IsAligned__1(toaddress, TAG_GRANULE)) then { + AArch64_Abort(toaddress, AlignmentFault(accdesc)) + }; + if not_bool(IsAligned__1(setsize, TAG_GRANULE)) then { + AArch64_Abort(toaddress, AlignmentFault(accdesc)) + }; + if supports_option_a then { + nzcv = 0b0000; + toaddress = toaddress + setsize; + setsize = Zeros(64) - setsize + } else { + nzcv = 0b0010 + }; + stagesetsize = SETPreSizeChoice(toaddress, setsize, is_setg); + assert([stagesetsize[63]] == [setsize[63]] | stagesetsize == Zeros(64)); + assert(stagesetsize[3 .. 0] == 0b0000); + if SInt(setsize) > 0 then { + assert(SInt(stagesetsize) <= SInt(setsize)) + } else { + assert(SInt(stagesetsize) >= SInt(setsize)) + } + } else { + let postsize : bits(64) = SETPostSizeChoice(toaddress, setsize, is_setg); + assert([postsize[63]] == [setsize[63]] | postsize == Zeros(64)); + assert(postsize[3 .. 0] == 0b0000); + let zero_size_exceptions : bool = MemSetZeroSizeCheck(); + if zero_size_exceptions | SInt(setsize) != 0 then { + if supports_option_a then { + if [nzcv[1]] == 0b1 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + } else { + if [nzcv[1]] == 0b0 then { + let wrong_option : bool = true; + let from_epilogue : bool = stage == MOPSStage_Epilogue; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + } + }; + if stage == MOPSStage_Main then { + stagesetsize = setsize - postsize; + if MemSetParametersIllformedM(toaddress, setsize, is_setg) then { + let wrong_option : bool = false; + let from_epilogue : bool = false; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + } else { + stagesetsize = postsize; + if setsize != postsize | MemSetParametersIllformedE(toaddress, setsize, is_setg) then { + let wrong_option : bool = false; + let from_epilogue : bool = true; + MismatchedMemSetException(supports_option_a, d, s, n, wrong_option, from_epilogue, options_name, is_setg) + }; + () + }; + if setsize != Zeros(64) & not_bool(IsAligned__1(toaddress, TAG_GRANULE)) then { + AArch64_Abort(toaddress, AlignmentFault(accdesc)) + }; + if not_bool(IsAligned__1(setsize, TAG_GRANULE)) then { + AArch64_Abort(toaddress, AlignmentFault(accdesc)) + }; + () + }; + tagstep : int = undefined; + tag : bits(4) = undefined; + tagaddr : bits(64) = undefined; + if SPESampleInFlight then { + SPESampleMemSet() + }; + if supports_option_a then { + while SInt(stagesetsize) < 0 do { + B = SETSizeChoice(toaddress, setsize, 16); + assert(B <= negate(1) * SInt(stagesetsize)); + assert(B[3 .. 0] == 0b0000); + let 'B = B in + { + assert(constraint('B * 8 >= 0)); + Mem_set(toaddress + setsize, B, accdesc) = Replicate(data, B) + }; + tagstep = DIV(B, 16); + tag = AArch64_AllocationTagFromAddress(toaddress + setsize); + while tagstep > 0 do { + tagaddr = toaddress + setsize + (tagstep - 1) * 16; + AArch64_MemTag_set(tagaddr, accdesc) = tag; + tagstep = tagstep - 1 + }; + setsize = setsize + B; + stagesetsize = stagesetsize + B; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = setsize + }; + () + } + } else { + while UInt(stagesetsize) > 0 do { + B = SETSizeChoice(toaddress, setsize, 16); + assert(B <= UInt(stagesetsize)); + assert(B[3 .. 0] == 0b0000); + let 'B = B in + { + assert(constraint('B * 8 >= 0)); + Mem_set(toaddress, B, accdesc) = Replicate(data, B) + }; + tagstep = DIV(B, 16); + tag = AArch64_AllocationTagFromAddress(toaddress); + while tagstep > 0 do { + tagaddr = toaddress + (tagstep - 1) * 16; + AArch64_MemTag_set(tagaddr, accdesc) = tag; + tagstep = tagstep - 1 + }; + toaddress = toaddress + B; + setsize = setsize - B; + stagesetsize = stagesetsize - B; + if stage != MOPSStage_Prologue then { + X_set(n, 64) = setsize; + X_set(d, 64) = toaddress + }; + () + } + }; + if stage == MOPSStage_Prologue then { + X_set(n, 64) = setsize; + X_set(d, 64) = toaddress; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + () +} + +val decode_setgp_aarch64_instrs_memory_mcpymset_setg : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setgp_aarch64_instrs_memory_mcpymset_setg (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_setg(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 792) = { + SEE = 792; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setgp_aarch64_instrs_memory_mcpymset_setg(Rd, Rn, op2, Rs, sz) +} + +val decode_setgpn_aarch64_instrs_memory_mcpymset_setg : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setgpn_aarch64_instrs_memory_mcpymset_setg (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_setg(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 793) = { + SEE = 793; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setgpn_aarch64_instrs_memory_mcpymset_setg(Rd, Rn, op2, Rs, sz) +} + +val decode_setgpt_aarch64_instrs_memory_mcpymset_setg : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setgpt_aarch64_instrs_memory_mcpymset_setg (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_setg(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 794) = { + SEE = 794; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setgpt_aarch64_instrs_memory_mcpymset_setg(Rd, Rn, op2, Rs, sz) +} + +val decode_setgptn_aarch64_instrs_memory_mcpymset_setg : (bits(5), bits(5), bits(4), bits(5), bits(2)) -> unit + +function decode_setgptn_aarch64_instrs_memory_mcpymset_setg (Rd, Rn, op2, Rs, sz) = { + if not_bool(HaveFeatMOPS()) then { + throw(Error_Undefined()) + }; + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + if sz != 0b00 then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 's = UInt(Rs); + let 'n = UInt(Rn); + let options_name : bits(2) = op2[1 .. 0]; + stage : MOPSStage = undefined; + match op2[3 .. 2] { + 0b00 => { + stage = MOPSStage_Prologue + }, + 0b01 => { + stage = MOPSStage_Main + }, + 0b10 => { + stage = MOPSStage_Epilogue + }, + _ => { + throw(Error_Undefined()) + } + }; + let stage = stage; + CheckMOPSEnabled(); + if (((s == n | s == d) | n == d) | d == 31) | n == 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP31); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + execute_aarch64_instrs_memory_mcpymset_setg(d, n, options_name, s, stage) +} + +function clause __DecodeA64_LoadStore ((pc, ([_, _, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 795) = { + SEE = 795; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op2 = Slice(__opcode, 12, 4); + let Rs = Slice(__opcode, 16, 5); + let sz = Slice(__opcode, 30, 2); + decode_setgptn_aarch64_instrs_memory_mcpymset_setg(Rd, Rn, op2, Rs, sz) +} + +val execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_choose : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_choose (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + x : bits(128) = V_read(d, 128); + y : bits(32) = V_read(n, 32); + let w : bits(128) = V_read(m, 128); + t : bits(32) = undefined; + foreach (e from 0 to 3 by 1 in inc) { + t = SHAchoose(x[63 .. 32], x[95 .. 64], x[127 .. 96]); + y = y + ROL(x[31 .. 0], 5) + t + Elem_read(w, e, 32); + x[63 .. 32] = ROL(x[63 .. 32], 30); + (y @ x) = ROL(y @ x, 32) + }; + V_set(d, 128) = x +} + +val decode_sha1c_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_choose : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha1c_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_choose (Rd, Rn, Rm) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HaveSHA1Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_choose(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 796) = { + SEE = 796; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha1c_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_choose(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha2op_sha1_hash : forall 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha2op_sha1_hash (d, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let operand : bits(32) = V_read(n, 32); + V_set(d, 32) = ROL(operand, 30) +} + +val decode_sha1h_advsimd_aarch64_instrs_vector_crypto_sha2op_sha1_hash : (bits(5), bits(5)) -> unit + +function decode_sha1h_advsimd_aarch64_instrs_vector_crypto_sha2op_sha1_hash (Rd, Rn) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HaveSHA1Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha2op_sha1_hash(d, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 797) = { + SEE = 797; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_sha1h_advsimd_aarch64_instrs_vector_crypto_sha2op_sha1_hash(Rd, Rn) +} + +val execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_majority : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_majority (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + x : bits(128) = V_read(d, 128); + y : bits(32) = V_read(n, 32); + let w : bits(128) = V_read(m, 128); + t : bits(32) = undefined; + foreach (e from 0 to 3 by 1 in inc) { + t = SHAmajority(x[63 .. 32], x[95 .. 64], x[127 .. 96]); + y = y + ROL(x[31 .. 0], 5) + t + Elem_read(w, e, 32); + x[63 .. 32] = ROL(x[63 .. 32], 30); + (y @ x) = ROL(y @ x, 32) + }; + V_set(d, 128) = x +} + +val decode_sha1m_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_majority : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha1m_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_majority (Rd, Rn, Rm) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HaveSHA1Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_majority(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 798) = { + SEE = 798; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha1m_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_majority(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_parity : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_parity (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + x : bits(128) = V_read(d, 128); + y : bits(32) = V_read(n, 32); + let w : bits(128) = V_read(m, 128); + t : bits(32) = undefined; + foreach (e from 0 to 3 by 1 in inc) { + t = SHAparity(x[63 .. 32], x[95 .. 64], x[127 .. 96]); + y = y + ROL(x[31 .. 0], 5) + t + Elem_read(w, e, 32); + x[63 .. 32] = ROL(x[63 .. 32], 30); + (y @ x) = ROL(y @ x, 32) + }; + V_set(d, 128) = x +} + +val decode_sha1p_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_parity : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha1p_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_parity (Rd, Rn, Rm) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HaveSHA1Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha3op_sha1_hash_parity(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 799) = { + SEE = 799; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha1p_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_hash_parity(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha3op_sha1_sched0 : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3op_sha1_sched0 (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let operand1 : bits(128) = V_read(d, 128); + let operand2 : bits(128) = V_read(n, 128); + let operand3 : bits(128) = V_read(m, 128); + result : bits(128) = operand2[63 .. 0] @ operand1[127 .. 64]; + let result : bits(128) = EOR(EOR(result, operand1), operand3); + V_set(d, 128) = result +} + +val decode_sha1su0_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_sched0 : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha1su0_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_sched0 (Rd, Rn, Rm) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HaveSHA1Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha3op_sha1_sched0(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 800) = { + SEE = 800; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha1su0_advsimd_aarch64_instrs_vector_crypto_sha3op_sha1_sched0(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha2op_sha1_sched1 : forall 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha2op_sha1_sched1 (d, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let operand1 : bits(128) = V_read(d, 128); + let operand2 : bits(128) = V_read(n, 128); + result : bits(128) = undefined; + let T : bits(128) = EOR(operand1, LSR(operand2, 32)); + result[31 .. 0] = ROL(T[31 .. 0], 1); + result[63 .. 32] = ROL(T[63 .. 32], 1); + result[95 .. 64] = ROL(T[95 .. 64], 1); + result[127 .. 96] = EOR(ROL(T[127 .. 96], 1), ROL(T[31 .. 0], 2)); + V_set(d, 128) = result +} + +val decode_sha1su1_advsimd_aarch64_instrs_vector_crypto_sha2op_sha1_sched1 : (bits(5), bits(5)) -> unit + +function decode_sha1su1_advsimd_aarch64_instrs_vector_crypto_sha2op_sha1_sched1 (Rd, Rn) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HaveSHA1Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha2op_sha1_sched1(d, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 801) = { + SEE = 801; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_sha1su1_advsimd_aarch64_instrs_vector_crypto_sha2op_sha1_sched1(Rd, Rn) +} + +val execute_aarch64_instrs_vector_crypto_sha3op_sha256_hash : forall 'd 'm 'n ('part1 : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n), bool('part1)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3op_sha256_hash (d, m, n, part1) = { + AArch64_CheckFPAdvSIMDEnabled(); + result : bits(128) = undefined; + if part1 then { + result = SHA256hash(V_read(d, 128), V_read(n, 128), V_read(m, 128), true) + } else { + result = SHA256hash(V_read(n, 128), V_read(d, 128), V_read(m, 128), false) + }; + V_set(d, 128) = result +} + +val decode_sha256h_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_hash : (bits(5), bits(5), bits(1), bits(5)) -> unit + +function decode_sha256h_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_hash (Rd, Rn, P, Rm) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HaveSHA256Ext()) then { + throw(Error_Undefined()) + }; + let part1 : bool = P == 0b0; + execute_aarch64_instrs_vector_crypto_sha3op_sha256_hash(d, m, n, part1) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 802) = { + SEE = 802; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let P = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + decode_sha256h_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_hash(Rd, Rn, P, Rm) +} + +val decode_sha256h2_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_hash : (bits(5), bits(5), bits(1), bits(5)) -> unit + +function decode_sha256h2_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_hash (Rd, Rn, P, Rm) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HaveSHA256Ext()) then { + throw(Error_Undefined()) + }; + let part1 : bool = P == 0b0; + execute_aarch64_instrs_vector_crypto_sha3op_sha256_hash(d, m, n, part1) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 803) = { + SEE = 803; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let P = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + decode_sha256h2_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_hash(Rd, Rn, P, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha2op_sha256_sched0 : forall 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha2op_sha256_sched0 (d, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let operand1 : bits(128) = V_read(d, 128); + let operand2 : bits(128) = V_read(n, 128); + result : bits(128) = undefined; + let T : bits(128) = operand2[31 .. 0] @ operand1[127 .. 32]; + elt : bits(32) = undefined; + foreach (e from 0 to 3 by 1 in inc) { + elt = Elem_read(T, e, 32); + elt = EOR(EOR(ROR(elt, 7), ROR(elt, 18)), LSR(elt, 3)); + result = Elem_set(result, e, 32, elt + Elem_read(operand1, e, 32)) + }; + V_set(d, 128) = result +} + +val decode_sha256su0_advsimd_aarch64_instrs_vector_crypto_sha2op_sha256_sched0 : (bits(5), bits(5)) -> unit + +function decode_sha256su0_advsimd_aarch64_instrs_vector_crypto_sha2op_sha256_sched0 (Rd, Rn) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HaveSHA256Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha2op_sha256_sched0(d, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 804) = { + SEE = 804; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_sha256su0_advsimd_aarch64_instrs_vector_crypto_sha2op_sha256_sched0(Rd, Rn) +} + +val execute_aarch64_instrs_vector_crypto_sha3op_sha256_sched1 : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3op_sha256_sched1 (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let operand1 : bits(128) = V_read(d, 128); + let operand2 : bits(128) = V_read(n, 128); + let operand3 : bits(128) = V_read(m, 128); + result : bits(128) = undefined; + let T0 : bits(128) = operand3[31 .. 0] @ operand2[127 .. 32]; + elt : bits(32) = undefined; + T1 : bits(64) = operand3[127 .. 64]; + foreach (e from 0 to 1 by 1 in inc) { + elt = Elem_read(T1, e, 32); + elt = EOR(EOR(ROR(elt, 17), ROR(elt, 19)), LSR(elt, 10)); + elt = elt + Elem_read(operand1, e, 32) + Elem_read(T0, e, 32); + result = Elem_set(result, e, 32, elt) + }; + let T1 : bits(64) = result[63 .. 0]; + foreach (e from 2 to 3 by 1 in inc) { + elt = Elem_read(T1, e - 2, 32); + elt = EOR(EOR(ROR(elt, 17), ROR(elt, 19)), LSR(elt, 10)); + elt = elt + Elem_read(operand1, e, 32) + Elem_read(T0, e, 32); + result = Elem_set(result, e, 32, elt) + }; + V_set(d, 128) = result +} + +val decode_sha256su1_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_sched1 : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha256su1_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_sched1 (Rd, Rn, Rm) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if not_bool(HaveSHA256Ext()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_crypto_sha3op_sha256_sched1(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 805) = { + SEE = 805; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha256su1_advsimd_aarch64_instrs_vector_crypto_sha3op_sha256_sched1(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha512_sha512h : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha512_sha512h (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + Vtmp : bits(128) = undefined; + let x : bits(128) = V_read(n, 128); + let y : bits(128) = V_read(m, 128); + let w : bits(128) = V_read(d, 128); + MSigma1 : bits(64) = EOR(EOR(ROR(y[127 .. 64], 14), ROR(y[127 .. 64], 18)), ROR(y[127 .. 64], 41)); + Vtmp[127 .. 64] = EOR(y[127 .. 64] & x[63 .. 0], not_vec(y[127 .. 64]) & x[127 .. 64]); + Vtmp[127 .. 64] = Vtmp[127 .. 64] + MSigma1 + w[127 .. 64]; + let tmp : bits(64) = Vtmp[127 .. 64] + y[63 .. 0]; + let MSigma1 : bits(64) = EOR(EOR(ROR(tmp, 14), ROR(tmp, 18)), ROR(tmp, 41)); + Vtmp[63 .. 0] = EOR(tmp & y[127 .. 64], not_vec(tmp) & x[63 .. 0]); + Vtmp[63 .. 0] = Vtmp[63 .. 0] + MSigma1 + w[63 .. 0]; + V_set(d, 128) = Vtmp +} + +val decode_sha512h_advsimd_aarch64_instrs_vector_crypto_sha512_sha512h : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha512h_advsimd_aarch64_instrs_vector_crypto_sha512_sha512h (Rd, Rn, Rm) = { + if not_bool(HaveSHA512Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sha512_sha512h(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 806) = { + SEE = 806; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha512h_advsimd_aarch64_instrs_vector_crypto_sha512_sha512h(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha512_sha512h2 : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha512_sha512h2 (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + Vtmp : bits(128) = undefined; + let x : bits(128) = V_read(n, 128); + let y : bits(128) = V_read(m, 128); + let w : bits(128) = V_read(d, 128); + NSigma0 : bits(64) = EOR(EOR(ROR(y[63 .. 0], 28), ROR(y[63 .. 0], 34)), ROR(y[63 .. 0], 39)); + Vtmp[127 .. 64] = EOR(EOR(x[63 .. 0] & y[127 .. 64], x[63 .. 0] & y[63 .. 0]), y[127 .. 64] & y[63 .. 0]); + Vtmp[127 .. 64] = Vtmp[127 .. 64] + NSigma0 + w[127 .. 64]; + let NSigma0 : bits(64) = EOR(EOR(ROR(Vtmp[127 .. 64], 28), ROR(Vtmp[127 .. 64], 34)), ROR(Vtmp[127 .. 64], 39)); + Vtmp[63 .. 0] = EOR(EOR(Vtmp[127 .. 64] & y[63 .. 0], Vtmp[127 .. 64] & y[127 .. 64]), y[127 .. 64] & y[63 .. 0]); + Vtmp[63 .. 0] = Vtmp[63 .. 0] + NSigma0 + w[63 .. 0]; + V_set(d, 128) = Vtmp +} + +val decode_sha512h2_advsimd_aarch64_instrs_vector_crypto_sha512_sha512h2 : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha512h2_advsimd_aarch64_instrs_vector_crypto_sha512_sha512h2 (Rd, Rn, Rm) = { + if not_bool(HaveSHA512Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sha512_sha512h2(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 807) = { + SEE = 807; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha512h2_advsimd_aarch64_instrs_vector_crypto_sha512_sha512h2(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sha512_sha512su0 : forall 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha512_sha512su0 (d, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + Vtmp : bits(128) = undefined; + let x : bits(128) = V_read(n, 128); + let w : bits(128) = V_read(d, 128); + sig0 : bits(64) = EOR(EOR(ROR(w[127 .. 64], 1), ROR(w[127 .. 64], 8)), 0b0000000 @ w[127 .. 71]); + Vtmp[63 .. 0] = w[63 .. 0] + sig0; + let sig0 : bits(64) = EOR(EOR(ROR(x[63 .. 0], 1), ROR(x[63 .. 0], 8)), 0b0000000 @ x[63 .. 7]); + Vtmp[127 .. 64] = w[127 .. 64] + sig0; + V_set(d, 128) = Vtmp +} + +val decode_sha512su0_advsimd_aarch64_instrs_vector_crypto_sha512_sha512su0 : (bits(5), bits(5)) -> unit + +function decode_sha512su0_advsimd_aarch64_instrs_vector_crypto_sha512_sha512su0 (Rd, Rn) = { + if not_bool(HaveSHA512Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + execute_aarch64_instrs_vector_crypto_sha512_sha512su0(d, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 808) = { + SEE = 808; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_sha512su0_advsimd_aarch64_instrs_vector_crypto_sha512_sha512su0(Rd, Rn) +} + +val execute_aarch64_instrs_vector_crypto_sha512_sha512su1 : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha512_sha512su1 (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + Vtmp : bits(128) = undefined; + let x : bits(128) = V_read(n, 128); + let y : bits(128) = V_read(m, 128); + let w : bits(128) = V_read(d, 128); + sig1 : bits(64) = EOR(EOR(ROR(x[127 .. 64], 19), ROR(x[127 .. 64], 61)), 0b000000 @ x[127 .. 70]); + Vtmp[127 .. 64] = w[127 .. 64] + sig1 + y[127 .. 64]; + let sig1 : bits(64) = EOR(EOR(ROR(x[63 .. 0], 19), ROR(x[63 .. 0], 61)), 0b000000 @ x[63 .. 6]); + Vtmp[63 .. 0] = w[63 .. 0] + sig1 + y[63 .. 0]; + V_set(d, 128) = Vtmp +} + +val decode_sha512su1_advsimd_aarch64_instrs_vector_crypto_sha512_sha512su1 : (bits(5), bits(5), bits(5)) -> unit + +function decode_sha512su1_advsimd_aarch64_instrs_vector_crypto_sha512_sha512su1 (Rd, Rn, Rm) = { + if not_bool(HaveSHA512Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sha512_sha512su1(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 809) = { + SEE = 809; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sha512su1_advsimd_aarch64_instrs_vector_crypto_sha512_sha512su1(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating (d, datasize, elements, esize, m, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + sum : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + sum = ((element1 + element2) >> 1); + result = Elem_set(result, e, esize, sum[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_shadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_shadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 810) = { + SEE = 810; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_shadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating(Rd, Rn, Rm, size, U, Q) +} + +val decode_uhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 811) = { + SEE = 811; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_truncating(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_shift_left_sisd : forall 'd 'datasize 'elements 'esize 'n 'shift, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('shift)) -> unit + +function execute_aarch64_instrs_vector_shift_left_sisd (d, datasize, elements, esize, n, shift) = { + CheckFPAdvSIMDEnabled64(); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + assert(constraint('esize >= 0)); + assert(constraint(('loop_e * 'esize <= 'loop_e * 'esize + 'esize - 1 | not(('loop_e >= 0 & ('loop_e + 1) * 'esize <= 'datasize)) | not('datasize in {8, 16, 32, 64, 128})))); + result = Elem_set(result, e, esize, LSL(Elem_read(operand, e, esize), shift)) + }; + V_set(d, datasize) = result +} + +val decode_shl_advsimd_aarch64_instrs_vector_shift_left_sisd : (bits(5), bits(5), bits(3), bits(4)) -> unit + +function decode_shl_advsimd_aarch64_instrs_vector_shift_left_sisd (Rd, Rn, immb, immh) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = UInt(immh @ immb) - esize; + execute_aarch64_instrs_vector_shift_left_sisd(d, datasize, elements, esize, n, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 812) = { + SEE = 812; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + decode_shl_advsimd_aarch64_instrs_vector_shift_left_sisd(Rd, Rn, immb, immh) +} + +val decode_shl_advsimd_aarch64_instrs_vector_shift_left_simd : (bits(5), bits(5), bits(3), bits(4), bits(1)) -> unit + +function decode_shl_advsimd_aarch64_instrs_vector_shift_left_simd (Rd, Rn, immb, immh, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = UInt(immh @ immb) - esize; + execute_aarch64_instrs_vector_shift_left_sisd(d, datasize, elements, esize, n, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 813) = { + SEE = 813; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let Q = Slice(__opcode, 30, 1); + decode_shl_advsimd_aarch64_instrs_vector_shift_left_simd(Rd, Rn, immb, immh, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_shift : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n 'part 'shift, + ('shift in {8, 16, 32, 64} & 'part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part), int('shift), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_shift (d, datasize, elements, esize, n, part, shift, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = Vpart_read(n, part, datasize); + result : bits(2 * 'datasize) = undefined; + element : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = (asl_Int(Elem_read(operand, e, esize), is_unsigned) << shift); + result = Elem_set(result, e, 2 * esize, element[2 * esize - 1 .. 0]) + }; + V_set(d, 2 * datasize) = result +} + +val decode_shll_advsimd_aarch64_instrs_vector_arithmetic_unary_shift : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_shll_advsimd_aarch64_instrs_vector_arithmetic_unary_shift (Rd, Rn, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = esize; + let is_unsigned : bool = false; + execute_aarch64_instrs_vector_arithmetic_unary_shift(d, datasize, elements, esize, n, part, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 814) = { + SEE = 814; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_shll_advsimd_aarch64_instrs_vector_arithmetic_unary_shift(Rd, Rn, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int (d, datasize, elements, esize, m, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + diff : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + diff = ((element1 - element2) >> 1); + result = Elem_set(result, e, esize, diff[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_shsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_shsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 815) = { + SEE = 815; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_shsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int(Rd, Rn, Rm, size, U, Q) +} + +val decode_uhsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uhsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 816) = { + SEE = 816; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uhsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_int(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_shift_left_insert_sisd : forall 'd 'datasize 'elements 'esize 'n 'shift, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('shift)) -> unit + +function execute_aarch64_instrs_vector_shift_left_insert_sisd (d, datasize, elements, esize, n, shift) = { + CheckFPAdvSIMDEnabled64(); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let operand : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + assert(constraint('esize >= 0)); + let mask : bits('esize) = LSL(Ones(esize), shift); + shifted : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + assert(constraint(('loop_e * 'esize <= 'loop_e * 'esize + 'esize - 1 | not(('loop_e >= 0 & ('loop_e + 1) * 'esize <= 'datasize)) | not('esize >= 0) | not('datasize in {8, 16, 32, 64, 128})))); + shifted = LSL(Elem_read(operand, e, esize), shift); + result = Elem_set(result, e, esize, Elem_read(operand2, e, esize) & not_vec(mask) | shifted) + }; + V_set(d, datasize) = result +} + +val decode_sli_advsimd_aarch64_instrs_vector_shift_left_insert_sisd : (bits(5), bits(5), bits(3), bits(4)) -> unit + +function decode_sli_advsimd_aarch64_instrs_vector_shift_left_insert_sisd (Rd, Rn, immb, immh) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = UInt(immh @ immb) - esize; + execute_aarch64_instrs_vector_shift_left_insert_sisd(d, datasize, elements, esize, n, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 817) = { + SEE = 817; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + decode_sli_advsimd_aarch64_instrs_vector_shift_left_insert_sisd(Rd, Rn, immb, immh) +} + +val decode_sli_advsimd_aarch64_instrs_vector_shift_left_insert_simd : (bits(5), bits(5), bits(3), bits(4), bits(1)) -> unit + +function decode_sli_advsimd_aarch64_instrs_vector_shift_left_insert_simd (Rd, Rn, immb, immh, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = UInt(immh @ immb) - esize; + execute_aarch64_instrs_vector_shift_left_insert_sisd(d, datasize, elements, esize, n, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 818) = { + SEE = 818; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let Q = Slice(__opcode, 30, 1); + decode_sli_advsimd_aarch64_instrs_vector_shift_left_insert_simd(Rd, Rn, immb, immh, Q) +} + +val execute_aarch64_instrs_vector_crypto_sm3_sm3partw1 : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm3_sm3partw1 (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Vd : bits(128) = V_read(d, 128); + result : bits(128) = undefined; + result[95 .. 0] = EOR(EOR(Vd, Vn)[95 .. 0], (ROL(Vm[127 .. 96], 15) @ ROL(Vm[95 .. 64], 15)) @ ROL(Vm[63 .. 32], 15)); + foreach (i from 0 to 3 by 1 in inc) { + if i == 3 then { + result[127 .. 96] = EOR(EOR(Vd, Vn)[127 .. 96], ROL(result[31 .. 0], 15)) + }; + result[32 * i + 31 .. 32 * i] = EOR(EOR(result[32 * i + 31 .. 32 * i], ROL(result[32 * i + 31 .. 32 * i], 15)), ROL(result[32 * i + 31 .. 32 * i], 23)) + }; + V_set(d, 128) = result +} + +val decode_sm3partw1_advsimd_aarch64_instrs_vector_crypto_sm3_sm3partw1 : (bits(5), bits(5), bits(5)) -> unit + +function decode_sm3partw1_advsimd_aarch64_instrs_vector_crypto_sm3_sm3partw1 (Rd, Rn, Rm) = { + if not_bool(HaveSM3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sm3_sm3partw1(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 819) = { + SEE = 819; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sm3partw1_advsimd_aarch64_instrs_vector_crypto_sm3_sm3partw1(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sm3_sm3partw2 : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm3_sm3partw2 (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Vd : bits(128) = V_read(d, 128); + result : bits(128) = undefined; + tmp : bits(128) = undefined; + tmp[127 .. 0] = EOR(Vn, ((ROL(Vm[127 .. 96], 7) @ ROL(Vm[95 .. 64], 7)) @ ROL(Vm[63 .. 32], 7)) @ ROL(Vm[31 .. 0], 7)); + result[127 .. 0] = EOR(Vd[127 .. 0], tmp[127 .. 0]); + tmp2 : bits(32) = ROL(tmp[31 .. 0], 15); + let tmp2 : bits(32) = EOR(EOR(tmp2, ROL(tmp2, 15)), ROL(tmp2, 23)); + result[127 .. 96] = EOR(result[127 .. 96], tmp2); + V_set(d, 128) = result +} + +val decode_sm3partw2_advsimd_aarch64_instrs_vector_crypto_sm3_sm3partw2 : (bits(5), bits(5), bits(5)) -> unit + +function decode_sm3partw2_advsimd_aarch64_instrs_vector_crypto_sm3_sm3partw2 (Rd, Rn, Rm) = { + if not_bool(HaveSM3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sm3_sm3partw2(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 820) = { + SEE = 820; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sm3partw2_advsimd_aarch64_instrs_vector_crypto_sm3_sm3partw2(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sm3_sm3ss1 : forall 'a 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31 & 0 <= 'a & 'a <= 31). + (int('a), int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm3_sm3ss1 (a, d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Va : bits(128) = V_read(a, 128); + result : bits(128) = undefined; + result[127 .. 96] = ROL(ROL(Vn[127 .. 96], 12) + Vm[127 .. 96] + Va[127 .. 96], 7); + result[95 .. 0] = Zeros(96); + V_set(d, 128) = result +} + +val decode_sm3ss1_advsimd_aarch64_instrs_vector_crypto_sm3_sm3ss1 : (bits(5), bits(5), bits(5), bits(5)) -> unit + +function decode_sm3ss1_advsimd_aarch64_instrs_vector_crypto_sm3_sm3ss1 (Rd, Rn, Ra, Rm) = { + if not_bool(HaveSM3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + execute_aarch64_instrs_vector_crypto_sm3_sm3ss1(a, d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 821) = { + SEE = 821; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sm3ss1_advsimd_aarch64_instrs_vector_crypto_sm3_sm3ss1(Rd, Rn, Ra, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sm3_sm3tt1a : forall 'd 'i 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'i in {0, 1, 2, 3} & 0 <= 'd & 'd <= 31). + (int('d), int('i), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm3_sm3tt1a (d, i, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Vd : bits(128) = V_read(d, 128); + result : bits(128) = undefined; + let WjPrime : bits(32) = Elem_read(Vm, i, 32); + let SS2 : bits(32) = EOR(Vn[127 .. 96], ROL(Vd[127 .. 96], 12)); + TT1 : bits(32) = EOR(Vd[63 .. 32], EOR(Vd[127 .. 96], Vd[95 .. 64])); + let TT1 : bits(32) = (TT1 + Vd[31 .. 0] + SS2 + WjPrime)[31 .. 0]; + result[31 .. 0] = Vd[63 .. 32]; + result[63 .. 32] = ROL(Vd[95 .. 64], 9); + result[95 .. 64] = Vd[127 .. 96]; + result[127 .. 96] = TT1; + V_set(d, 128) = result +} + +val decode_sm3tt1a_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt1a : (bits(5), bits(5), bits(2), bits(5)) -> unit + +function decode_sm3tt1a_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt1a (Rd, Rn, imm2, Rm) = { + if not_bool(HaveSM3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'i = UInt(imm2); + execute_aarch64_instrs_vector_crypto_sm3_sm3tt1a(d, i, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitone, bitzero, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 822) = { + SEE = 822; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm2 = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + decode_sm3tt1a_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt1a(Rd, Rn, imm2, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sm3_sm3tt1b : forall 'd 'i 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'i in {0, 1, 2, 3} & 0 <= 'd & 'd <= 31). + (int('d), int('i), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm3_sm3tt1b (d, i, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Vd : bits(128) = V_read(d, 128); + result : bits(128) = undefined; + let WjPrime : bits(32) = Elem_read(Vm, i, 32); + let SS2 : bits(32) = EOR(Vn[127 .. 96], ROL(Vd[127 .. 96], 12)); + TT1 : bits(32) = (Vd[127 .. 96] & Vd[63 .. 32] | Vd[127 .. 96] & Vd[95 .. 64]) | Vd[63 .. 32] & Vd[95 .. 64]; + let TT1 : bits(32) = (TT1 + Vd[31 .. 0] + SS2 + WjPrime)[31 .. 0]; + result[31 .. 0] = Vd[63 .. 32]; + result[63 .. 32] = ROL(Vd[95 .. 64], 9); + result[95 .. 64] = Vd[127 .. 96]; + result[127 .. 96] = TT1; + V_set(d, 128) = result +} + +val decode_sm3tt1b_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt1b : (bits(5), bits(5), bits(2), bits(5)) -> unit + +function decode_sm3tt1b_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt1b (Rd, Rn, imm2, Rm) = { + if not_bool(HaveSM3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'i = UInt(imm2); + execute_aarch64_instrs_vector_crypto_sm3_sm3tt1b(d, i, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitone, bitzero, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 823) = { + SEE = 823; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm2 = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + decode_sm3tt1b_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt1b(Rd, Rn, imm2, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sm3_sm3tt2a : forall 'd 'i 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'i in {0, 1, 2, 3} & 0 <= 'd & 'd <= 31). + (int('d), int('i), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm3_sm3tt2a (d, i, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Vd : bits(128) = V_read(d, 128); + result : bits(128) = undefined; + let Wj : bits(32) = Elem_read(Vm, i, 32); + TT2 : bits(32) = EOR(Vd[63 .. 32], EOR(Vd[127 .. 96], Vd[95 .. 64])); + let TT2 : bits(32) = (TT2 + Vd[31 .. 0] + Vn[127 .. 96] + Wj)[31 .. 0]; + result[31 .. 0] = Vd[63 .. 32]; + result[63 .. 32] = ROL(Vd[95 .. 64], 19); + result[95 .. 64] = Vd[127 .. 96]; + result[127 .. 96] = EOR(EOR(TT2, ROL(TT2, 9)), ROL(TT2, 17)); + V_set(d, 128) = result +} + +val decode_sm3tt2a_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt2a : (bits(5), bits(5), bits(2), bits(5)) -> unit + +function decode_sm3tt2a_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt2a (Rd, Rn, imm2, Rm) = { + if not_bool(HaveSM3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'i = UInt(imm2); + execute_aarch64_instrs_vector_crypto_sm3_sm3tt2a(d, i, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitone, bitzero, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 824) = { + SEE = 824; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm2 = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + decode_sm3tt2a_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt2a(Rd, Rn, imm2, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sm3_sm3tt2b : forall 'd 'i 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'i in {0, 1, 2, 3} & 0 <= 'd & 'd <= 31). + (int('d), int('i), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm3_sm3tt2b (d, i, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let Vd : bits(128) = V_read(d, 128); + result : bits(128) = undefined; + let Wj : bits(32) = Elem_read(Vm, i, 32); + TT2 : bits(32) = Vd[127 .. 96] & Vd[95 .. 64] | not_vec(Vd[127 .. 96]) & Vd[63 .. 32]; + let TT2 : bits(32) = (TT2 + Vd[31 .. 0] + Vn[127 .. 96] + Wj)[31 .. 0]; + result[31 .. 0] = Vd[63 .. 32]; + result[63 .. 32] = ROL(Vd[95 .. 64], 19); + result[95 .. 64] = Vd[127 .. 96]; + result[127 .. 96] = EOR(EOR(TT2, ROL(TT2, 9)), ROL(TT2, 17)); + V_set(d, 128) = result +} + +val decode_sm3tt2b_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt2b : (bits(5), bits(5), bits(2), bits(5)) -> unit + +function decode_sm3tt2b_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt2b (Rd, Rn, imm2, Rm) = { + if not_bool(HaveSM3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'i = UInt(imm2); + execute_aarch64_instrs_vector_crypto_sm3_sm3tt2b(d, i, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, bitone, bitzero, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 825) = { + SEE = 825; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm2 = Slice(__opcode, 12, 2); + let Rm = Slice(__opcode, 16, 5); + decode_sm3tt2b_advsimd_aarch64_instrs_vector_crypto_sm3_sm3tt2b(Rd, Rn, imm2, Rm) +} + +val execute_aarch64_instrs_vector_crypto_sm4_sm4enc : forall 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm4_sm4enc (d, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vn : bits(128) = V_read(n, 128); + intval : bits(32) = undefined; + roundkey : bits(32) = undefined; + roundresult : bits(128) = V_read(d, 128); + foreach (index from 0 to 3 by 1 in inc) { + roundkey = Elem_read(Vn, index, 32); + intval = EOR(EOR(EOR(roundresult[127 .. 96], roundresult[95 .. 64]), roundresult[63 .. 32]), roundkey); + foreach (i from 0 to 3 by 1 in inc) { + intval = Elem_set(intval, i, 8, Sbox(Elem_read(intval, i, 8))) + }; + intval = EOR(EOR(EOR(EOR(intval, ROL(intval, 2)), ROL(intval, 10)), ROL(intval, 18)), ROL(intval, 24)); + intval = EOR(intval, roundresult[31 .. 0]); + roundresult[31 .. 0] = roundresult[63 .. 32]; + roundresult[63 .. 32] = roundresult[95 .. 64]; + roundresult[95 .. 64] = roundresult[127 .. 96]; + roundresult[127 .. 96] = intval + }; + V_set(d, 128) = roundresult +} + +val decode_sm4e_advsimd_aarch64_instrs_vector_crypto_sm4_sm4enc : (bits(5), bits(5)) -> unit + +function decode_sm4e_advsimd_aarch64_instrs_vector_crypto_sm4_sm4enc (Rd, Rn) = { + if not_bool(HaveSM4Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + execute_aarch64_instrs_vector_crypto_sm4_sm4enc(d, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 826) = { + SEE = 826; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_sm4e_advsimd_aarch64_instrs_vector_crypto_sm4_sm4enc(Rd, Rn) +} + +val execute_aarch64_instrs_vector_crypto_sm4_sm4enckey : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sm4_sm4enckey (d, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + intval : bits(32) = undefined; + const : bits(32) = undefined; + roundresult : bits(128) = V_read(n, 128); + foreach (index from 0 to 3 by 1 in inc) { + const = Elem_read(Vm, index, 32); + intval = EOR(EOR(EOR(roundresult[127 .. 96], roundresult[95 .. 64]), roundresult[63 .. 32]), const); + foreach (i from 0 to 3 by 1 in inc) { + intval = Elem_set(intval, i, 8, Sbox(Elem_read(intval, i, 8))) + }; + intval = EOR(EOR(intval, ROL(intval, 13)), ROL(intval, 23)); + intval = EOR(intval, roundresult[31 .. 0]); + roundresult[31 .. 0] = roundresult[63 .. 32]; + roundresult[63 .. 32] = roundresult[95 .. 64]; + roundresult[95 .. 64] = roundresult[127 .. 96]; + roundresult[127 .. 96] = intval + }; + V_set(d, 128) = roundresult +} + +val decode_sm4ekey_advsimd_aarch64_instrs_vector_crypto_sm4_sm4enckey : (bits(5), bits(5), bits(5)) -> unit + +function decode_sm4ekey_advsimd_aarch64_instrs_vector_crypto_sm4_sm4enckey (Rd, Rn, Rm) = { + if not_bool(HaveSM4Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sm4_sm4enckey(d, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 827) = { + SEE = 827; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + decode_sm4ekey_advsimd_aarch64_instrs_vector_crypto_sm4_sm4enckey(Rd, Rn, Rm) +} + +val execute_aarch64_instrs_integer_arithmetic_mul_widening_32_64 : forall 'a 'd 'datasize 'destsize ('is_unsigned : Bool) 'm 'n ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'destsize == 64 & 'datasize == 32 & 0 <= 'd & 'd <= 31 & 0 <= 'a & 'a <= 31). + (int('a), int('d), int('datasize), int('destsize), int('m), int('n), bool('sub_op), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_mul_widening_32_64 (a, d, datasize, destsize, m, n, sub_op, is_unsigned) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let operand3 : bits('destsize) = X_read(a, destsize); + result : int = undefined; + if sub_op then { + result = asl_Int(operand3, is_unsigned) - asl_Int(operand1, is_unsigned) * asl_Int(operand2, is_unsigned) + } else { + result = asl_Int(operand3, is_unsigned) + asl_Int(operand1, is_unsigned) * asl_Int(operand2, is_unsigned) + }; + let 'result = result; + X_set(d, 64) = result[63 .. 0] +} + +val decode_smaddl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_smaddl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 (Rd, Rn, Ra, o0, Rm, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = 64; + let 'datasize = 32; + let sub_op : bool = o0 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_widening_32_64(a, d, datasize, destsize, m, n, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 828) = { + SEE = 828; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 23, 1); + decode_smaddl_aarch64_instrs_integer_arithmetic_mul_widening_32_64(Rd, Rn, Ra, o0, Rm, U) +} + +val decode_smsubl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_smsubl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 (Rd, Rn, Ra, o0, Rm, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = 64; + let 'datasize = 32; + let sub_op : bool = o0 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_widening_32_64(a, d, datasize, destsize, m, n, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 829) = { + SEE = 829; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 23, 1); + decode_smsubl_aarch64_instrs_integer_arithmetic_mul_widening_32_64(Rd, Rn, Ra, o0, Rm, U) +} + +val decode_umaddl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_umaddl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 (Rd, Rn, Ra, o0, Rm, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = 64; + let 'datasize = 32; + let sub_op : bool = o0 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_widening_32_64(a, d, datasize, destsize, m, n, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 830) = { + SEE = 830; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 23, 1); + decode_umaddl_aarch64_instrs_integer_arithmetic_mul_widening_32_64(Rd, Rn, Ra, o0, Rm, U) +} + +val decode_umsubl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 : (bits(5), bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_umsubl_aarch64_instrs_integer_arithmetic_mul_widening_32_64 (Rd, Rn, Ra, o0, Rm, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = 64; + let 'datasize = 32; + let sub_op : bool = o0 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_widening_32_64(a, d, datasize, destsize, m, n, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 831) = { + SEE = 831; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let o0 = Slice(__opcode, 15, 1); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 23, 1); + decode_umsubl_aarch64_instrs_integer_arithmetic_mul_widening_32_64(Rd, Rn, Ra, o0, Rm, U) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_smax_imm : forall 'd 'datasize 'imm 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('imm), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_smax_imm (d, datasize, imm, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let 'result = Max(SInt(operand1), imm); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_smax_imm_aarch64_instrs_integer_arithmetic_max_min_smax_imm : (bits(5), bits(5), bits(8), bits(1)) -> unit + +function decode_smax_imm_aarch64_instrs_integer_arithmetic_max_min_smax_imm (Rd, Rn, imm8, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'd = UInt(Rd); + let 'imm = SInt(imm8); + execute_aarch64_instrs_integer_arithmetic_max_min_smax_imm(d, datasize, imm, n) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 832) = { + SEE = 832; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm8 = Slice(__opcode, 10, 8); + let sf = Slice(__opcode, 31, 1); + decode_smax_imm_aarch64_instrs_integer_arithmetic_max_min_smax_imm(Rd, Rn, imm8, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_smax_reg : forall 'd 'datasize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_smax_reg (d, datasize, m, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let 'result = Max(SInt(operand1), SInt(operand2)); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_smax_reg_aarch64_instrs_integer_arithmetic_max_min_smax_reg : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_smax_reg_aarch64_instrs_integer_arithmetic_max_min_smax_reg (Rd, Rn, Rm, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_integer_arithmetic_max_min_smax_reg(d, datasize, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 833) = { + SEE = 833; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_smax_reg_aarch64_instrs_integer_arithmetic_max_min_smax_reg(Rd, Rn, Rm, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm ('minimum : Bool) 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), bool('minimum), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single (d, datasize, elements, esize, m, minimum, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + maxmin : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + maxmin = if minimum then Min(element1, element2) else + Max(element1, element2); + result = Elem_set(result, e, esize, maxmin[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_smax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_smax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 834) = { + SEE = 834; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_smin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_smin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 835) = { + SEE = 835; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_umax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_umax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 836) = { + SEE = 836; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umax_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_umin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_umin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 837) = { + SEE = 837; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umin_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_single(Rd, Rn, o1, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm ('minimum : Bool) 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), bool('minimum), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair (d, datasize, elements, esize, m, minimum, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + let concat : bits(2 * 'datasize) = operand2 @ operand1; + element1 : int = undefined; + element2 : int = undefined; + maxmin : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(concat, 2 * e, esize), is_unsigned); + element2 = asl_Int(Elem_read(concat, 2 * e + 1, esize), is_unsigned); + maxmin = if minimum then Min(element1, element2) else + Max(element1, element2); + result = Elem_set(result, e, esize, maxmin[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_smaxp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_smaxp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 838) = { + SEE = 838; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smaxp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_sminp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sminp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 839) = { + SEE = 839; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sminp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_umaxp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_umaxp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 840) = { + SEE = 840; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umaxp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_uminp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uminp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let minimum : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(d, datasize, elements, esize, m, minimum, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 841) = { + SEE = 841; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uminp_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_max_min_pair(Rd, Rn, o1, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_reduce_int_max : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) ('min : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), bool('min), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_reduce_int_max (d, datasize, elements, esize, min, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + element : int = undefined; + maxmin : int = asl_Int(Elem_read(operand, 0, esize), is_unsigned); + foreach (e from 1 to (elements - 1) by 1 in inc) { + element = asl_Int(Elem_read(operand, e, esize), is_unsigned); + maxmin = if min then Min(maxmin, element) else Max(maxmin, element) + }; + let 'maxmin = maxmin; + V_set(d, esize) = maxmin[esize - 1 .. 0] +} + +val decode_smaxv_advsimd_aarch64_instrs_vector_reduce_int_max : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_smaxv_advsimd_aarch64_instrs_vector_reduce_int_max (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b100 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let min : bool = op == 0b1; + execute_aarch64_instrs_vector_reduce_int_max(d, datasize, elements, esize, min, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 842) = { + SEE = 842; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 16, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smaxv_advsimd_aarch64_instrs_vector_reduce_int_max(Rd, Rn, op, size, U, Q) +} + +val decode_sminv_advsimd_aarch64_instrs_vector_reduce_int_max : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_sminv_advsimd_aarch64_instrs_vector_reduce_int_max (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b100 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let min : bool = op == 0b1; + execute_aarch64_instrs_vector_reduce_int_max(d, datasize, elements, esize, min, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 843) = { + SEE = 843; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 16, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sminv_advsimd_aarch64_instrs_vector_reduce_int_max(Rd, Rn, op, size, U, Q) +} + +val decode_umaxv_advsimd_aarch64_instrs_vector_reduce_int_max : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_umaxv_advsimd_aarch64_instrs_vector_reduce_int_max (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b100 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let min : bool = op == 0b1; + execute_aarch64_instrs_vector_reduce_int_max(d, datasize, elements, esize, min, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 844) = { + SEE = 844; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 16, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umaxv_advsimd_aarch64_instrs_vector_reduce_int_max(Rd, Rn, op, size, U, Q) +} + +val decode_uminv_advsimd_aarch64_instrs_vector_reduce_int_max : (bits(5), bits(5), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_uminv_advsimd_aarch64_instrs_vector_reduce_int_max (Rd, Rn, op, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b100 then { + throw(Error_Undefined()) + }; + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let min : bool = op == 0b1; + execute_aarch64_instrs_vector_reduce_int_max(d, datasize, elements, esize, min, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 845) = { + SEE = 845; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 16, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uminv_advsimd_aarch64_instrs_vector_reduce_int_max(Rd, Rn, op, size, U, Q) +} + +val execute_aarch64_instrs_system_exceptions_runtime_smc : bits(16) -> unit + +function execute_aarch64_instrs_system_exceptions_runtime_smc imm = { + AArch64_CheckForSMCUndefOrTrap(imm); + AArch64_CallSecureMonitor(imm) +} + +val decode_smc_aarch64_instrs_system_exceptions_runtime_smc : bits(16) -> unit + +function decode_smc_aarch64_instrs_system_exceptions_runtime_smc imm16 = { + let imm : bits(16) = imm16; + execute_aarch64_instrs_system_exceptions_runtime_smc(imm) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone] as __opcode)) if SEE < 846) = { + SEE = 846; + let imm16 = Slice(__opcode, 5, 16); + decode_smc_aarch64_instrs_system_exceptions_runtime_smc(imm16) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_smin_imm : forall 'd 'datasize 'imm 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('imm), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_smin_imm (d, datasize, imm, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let 'result = Min(SInt(operand1), imm); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_smin_imm_aarch64_instrs_integer_arithmetic_max_min_smin_imm : (bits(5), bits(5), bits(8), bits(1)) -> unit + +function decode_smin_imm_aarch64_instrs_integer_arithmetic_max_min_smin_imm (Rd, Rn, imm8, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'd = UInt(Rd); + let 'imm = SInt(imm8); + execute_aarch64_instrs_integer_arithmetic_max_min_smin_imm(d, datasize, imm, n) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 847) = { + SEE = 847; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm8 = Slice(__opcode, 10, 8); + let sf = Slice(__opcode, 31, 1); + decode_smin_imm_aarch64_instrs_integer_arithmetic_max_min_smin_imm(Rd, Rn, imm8, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_smin_reg : forall 'd 'datasize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_smin_reg (d, datasize, m, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let 'result = Min(SInt(operand1), SInt(operand2)); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_smin_reg_aarch64_instrs_integer_arithmetic_max_min_smin_reg : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_smin_reg_aarch64_instrs_integer_arithmetic_max_min_smin_reg (Rd, Rn, Rm, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_integer_arithmetic_max_min_smin_reg(d, datasize, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 848) = { + SEE = 848; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_smin_reg_aarch64_instrs_integer_arithmetic_max_min_smin_reg(Rd, Rn, Rm, sf) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('sub_op), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum (d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + let operand3 : bits(2 * 'datasize) = V_read(d, 2 * datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + product : bits(2 * 'esize) = undefined; + accum : bits(2 * 'esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + product = (element1 * element2)[2 * esize - 1 .. 0]; + if sub_op then { + accum = Elem_read(operand3, e, 2 * esize) - product + } else { + accum = Elem_read(operand3, e, 2 * esize) + product + }; + result = Elem_set(result, e, 2 * esize, accum) + }; + V_set(d, 2 * datasize) = result +} + +val decode_smlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_smlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 849) = { + SEE = 849; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_smlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_smlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 850) = { + SEE = 850; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_umlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_umlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 851) = { + SEE = 851; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(Rd, Rn, o1, Rm, size, U, Q) +} + +val decode_umlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_umlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum (Rd, Rn, o1, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(d, datasize, elements, esize, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 852) = { + SEE = 852; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_accum(Rd, Rn, o1, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long : forall 'd 'datasize 'elements 'esize 'idxdsize 'index ('is_unsigned : Bool) 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), int('part), bool('sub_op), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long (d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + let operand3 : bits(2 * 'datasize) = V_read(d, 2 * datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + product : bits(2 * 'esize) = undefined; + let 'element2 = asl_Int(Elem_read(operand2, index, esize), is_unsigned); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + product = (element1 * element2)[2 * esize - 1 .. 0]; + if sub_op then { + result = Elem_set(result, e, 2 * esize, Elem_read(operand3, e, 2 * esize) - product) + } else { + result = Elem_set(result, e, 2 * esize, Elem_read(operand3, e, 2 * esize) + product) + } + }; + V_set(d, 2 * datasize) = result +} + +val decode_smlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_smlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long (Rd, Rn, H, o2, Rm, M, L, size, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 853) = { + SEE = 853; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(Rd, Rn, H, o2, Rm, M, L, size, U, Q) +} + +val decode_smlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_smlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long (Rd, Rn, H, o2, Rm, M, L, size, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 854) = { + SEE = 854; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(Rd, Rn, H, o2, Rm, M, L, size, U, Q) +} + +val decode_umlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_umlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long (Rd, Rn, H, o2, Rm, M, L, size, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 855) = { + SEE = 855; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(Rd, Rn, H, o2, Rm, M, L, size, U, Q) +} + +val decode_umlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_umlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long (Rd, Rn, H, o2, Rm, M, L, size, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 856) = { + SEE = 856; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_long(Rd, Rn, H, o2, Rm, M, L, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla : forall 'd 'm 'n ('op1_unsigned : Bool) ('op2_unsigned : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n), bool('op1_unsigned), bool('op2_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla (d, m, n, op1_unsigned, op2_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits(128) = V_read(n, 128); + let operand2 : bits(128) = V_read(m, 128); + let addend : bits(128) = V_read(d, 128); + V_set(d, 128) = MatMulAdd(addend, operand1, operand2, op1_unsigned, op2_unsigned) +} + +val decode_smmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla : (bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_smmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla (Rd, Rn, B, Rm, U) = { + if not_bool(HaveInt8MatMulExt()) then { + throw(Error_Undefined()) + }; + op1_unsigned : bool = undefined; + op2_unsigned : bool = undefined; + match B @ U { + 0b00 => { + op1_unsigned = false; + op2_unsigned = false + }, + 0b01 => { + op1_unsigned = true; + op2_unsigned = true + }, + 0b10 => { + op1_unsigned = true; + op2_unsigned = false + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let op2_unsigned = op2_unsigned; + let op1_unsigned = op1_unsigned; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla(d, m, n, op1_unsigned, op2_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 857) = { + SEE = 857; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let B = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 29, 1); + decode_smmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla(Rd, Rn, B, Rm, U) +} + +val decode_ummla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla : (bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_ummla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla (Rd, Rn, B, Rm, U) = { + if not_bool(HaveInt8MatMulExt()) then { + throw(Error_Undefined()) + }; + op1_unsigned : bool = undefined; + op2_unsigned : bool = undefined; + match B @ U { + 0b00 => { + op1_unsigned = false; + op2_unsigned = false + }, + 0b01 => { + op1_unsigned = true; + op2_unsigned = true + }, + 0b10 => { + op1_unsigned = true; + op2_unsigned = false + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let op2_unsigned = op2_unsigned; + let op1_unsigned = op1_unsigned; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla(d, m, n, op1_unsigned, op2_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 858) = { + SEE = 858; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let B = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 29, 1); + decode_ummla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla(Rd, Rn, B, Rm, U) +} + +val decode_usmmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla : (bits(5), bits(5), bits(1), bits(5), bits(1)) -> unit + +function decode_usmmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla (Rd, Rn, B, Rm, U) = { + if not_bool(HaveInt8MatMulExt()) then { + throw(Error_Undefined()) + }; + op1_unsigned : bool = undefined; + op2_unsigned : bool = undefined; + match B @ U { + 0b00 => { + op1_unsigned = false; + op2_unsigned = false + }, + 0b01 => { + op1_unsigned = true; + op2_unsigned = true + }, + 0b10 => { + op1_unsigned = true; + op2_unsigned = false + }, + 0b11 => { + throw(Error_Undefined()) + } + }; + let op2_unsigned = op2_unsigned; + let op1_unsigned = op1_unsigned; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla(d, m, n, op1_unsigned, op2_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 859) = { + SEE = 859; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let B = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 29, 1); + decode_usmmla_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_mla(Rd, Rn, B, Rm, U) +} + +val execute_aarch64_instrs_vector_transfer_integer_move_signed : forall 'd 'datasize 'esize 'idxdsize 'index 'n, + (0 <= 'n & 'n <= 31 & 'idxdsize in {64, 128} & 'esize in {8, 16, 32} & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('idxdsize), int('index), int('n)) -> unit + +function execute_aarch64_instrs_vector_transfer_integer_move_signed (d, datasize, esize, idxdsize, index, n) = { + if index == 0 then { + CheckFPEnabled64() + } else { + CheckFPAdvSIMDEnabled64() + }; + let operand : bits('idxdsize) = V_read(n, idxdsize); + X_set(d, datasize) = SignExtend(Elem_read(operand, index, esize), datasize) +} + +val decode_smov_advsimd_aarch64_instrs_vector_transfer_integer_move_signed : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_smov_advsimd_aarch64_instrs_vector_transfer_integer_move_signed (Rd, Rn, imm5, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + size : {0, 1, 2} = 0; + match Q @ imm5 { + [_, _, _, _, _, bitone] => { + size = 0 + }, + [_, _, _, _, bitone, bitzero] => { + size = 1 + }, + [bitone, _, _, bitone, bitzero, bitzero] => { + size = 2 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'size = size; + let 'idxdsize = if [imm5[4]] == 0b1 then 128 else 64; + let 'index = UInt(imm5[4 .. size + 1]); + let 'esize = (8 << size); + let 'datasize = if Q == 0b1 then 64 else 32; + assert(constraint('esize in {8, 16, 32})); + execute_aarch64_instrs_vector_transfer_integer_move_signed(d, datasize, esize, idxdsize, index, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 860) = { + SEE = 860; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm5 = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_smov_advsimd_aarch64_instrs_vector_transfer_integer_move_signed(Rd, Rn, imm5, Q) +} + +val execute_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi : forall 'd 'datasize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi (d, datasize, m, n, is_unsigned) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let 'result = asl_Int(operand1, is_unsigned) * asl_Int(operand2, is_unsigned); + X_set(d, 64) = result[127 .. 64] +} + +val decode_smulh_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi : (bits(5), bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_smulh_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi (Rd, Rn, Ra, Rm, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = 64; + let 'datasize = destsize; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi(d, datasize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 861) = { + SEE = 861; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 23, 1); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_smulh_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi(Rd, Rn, Ra, Rm, U) + } +} + +val decode_umulh_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi : (bits(5), bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_umulh_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi (Rd, Rn, Ra, Rm, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'a = UInt(Ra); + let 'destsize = 64; + let 'datasize = destsize; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi(d, datasize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 862) = { + SEE = 862; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Ra = Slice(__opcode, 10, 5); + let Rm = Slice(__opcode, 16, 5); + let U = Slice(__opcode, 23, 1); + if ((([__opcode[10]] != 0b1 | [__opcode[11]] != 0b1) | [__opcode[12]] != 0b1) | [__opcode[13]] != 0b1) | [__opcode[14]] != 0b1 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_umulh_aarch64_instrs_integer_arithmetic_mul_widening_64_128hi(Rd, Rn, Ra, Rm, U) + } +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product (d, datasize, elements, esize, m, n, part, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + result = Elem_set(result, e, 2 * esize, (element1 * element2)[2 * esize - 1 .. 0]) + }; + V_set(d, 2 * datasize) = result +} + +val decode_smull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_smull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product(d, datasize, elements, esize, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 863) = { + SEE = 863; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product(Rd, Rn, Rm, size, U, Q) +} + +val decode_umull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_umull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product(d, datasize, elements, esize, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 864) = { + SEE = 864; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_product(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_long : forall 'd 'datasize 'elements 'esize 'idxdsize 'index ('is_unsigned : Bool) 'm 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), int('part), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_long (d, datasize, elements, esize, idxdsize, index, m, n, part, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + product : bits(2 * 'esize) = undefined; + let 'element2 = asl_Int(Elem_read(operand2, index, esize), is_unsigned); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + product = (element1 * element2)[2 * esize - 1 .. 0]; + result = Elem_set(result, e, 2 * esize, product) + }; + V_set(d, 2 * datasize) = result +} + +val decode_smull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_long : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_smull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_long (Rd, Rn, H, Rm, M, L, size, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_long(d, datasize, elements, esize, idxdsize, index, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitzero, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 865) = { + SEE = 865; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_smull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_long(Rd, Rn, H, Rm, M, L, size, U, Q) +} + +val decode_umull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_long : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1), bits(1)) -> unit + +function decode_umull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_long (Rd, Rn, H, Rm, M, L, size, U, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_long(d, datasize, elements, esize, idxdsize, index, m, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitzero, bitone, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 866) = { + SEE = 866; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_umull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_long(Rd, Rn, H, Rm, M, L, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd : forall 'd 'datasize 'elements 'esize 'n ('neg : Bool), + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), bool('neg)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd (d, datasize, elements, esize, n, neg) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = SInt(Elem_read(operand, e, esize)); + if neg then { + element = negate(element) + } else { + element = Abs(element) + }; + let (__tup_0 : bits('esize), __tup_1 : bool) = + SignedSatQ(element, esize) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 867) = { + SEE = 867; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd(Rd, Rn, size, U) +} + +val decode_sqabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 868) = { + SEE = 868; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqabs_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_simd(Rd, Rn, size, U, Q) +} + +val decode_sqneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 869) = { + SEE = 869; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd(Rd, Rn, size, U) +} + +val decode_sqneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let neg : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_sisd(d, datasize, elements, esize, n, neg) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 870) = { + SEE = 870; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqneg_advsimd_aarch64_instrs_vector_arithmetic_unary_diff_neg_sat_simd(Rd, Rn, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd (d, datasize, elements, esize, m, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + sum : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + sum = element1 + element2; + let (__tup_0 : bits('esize), __tup_1 : bool) = + SatQ(sum, esize, is_unsigned) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 871) = { + SEE = 871; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd(Rd, Rn, Rm, size, U) +} + +val decode_sqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 872) = { + SEE = 872; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_simd(Rd, Rn, Rm, size, U, Q) +} + +val decode_uqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_uqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 873) = { + SEE = 873; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_uqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd(Rd, Rn, Rm, size, U) +} + +val decode_uqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 874) = { + SEE = 874; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_saturating_simd(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), int('part), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd (d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + let operand3 : bits(2 * 'datasize) = V_read(d, 2 * datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + product : bits(2 * 'esize) = undefined; + accum : int = undefined; + sat1 : bool = undefined; + sat2 : bool = undefined; + let 'element2 = SInt(Elem_read(operand2, index, esize)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + (product, sat1) = SignedSatQ(2 * element1 * element2, 2 * esize); + if sub_op then { + accum = SInt(Elem_read(operand3, e, 2 * esize)) - SInt(product) + } else { + accum = SInt(Elem_read(operand3, e, 2 * esize)) + SInt(product) + }; + let (__tup_0 : bits(2 * 'esize), __tup_1 : bool) = + SignedSatQ(accum, 2 * esize) + in + { + result = Elem_set(result, e, 2 * esize, __tup_0); + sat2 = __tup_1 + }; + if sat1 | sat2 then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, 2 * datasize) = result +} + +val decode_sqdmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2)) -> unit + +function decode_sqdmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd (Rd, Rn, H, o2, Rm, M, L, size) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 875) = { + SEE = 875; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + decode_sqdmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd(Rd, Rn, H, o2, Rm, M, L, size) +} + +val decode_sqdmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_sqdmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_simd (Rd, Rn, H, o2, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 876) = { + SEE = 876; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqdmlal_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_simd(Rd, Rn, H, o2, Rm, M, L, size, Q) +} + +val decode_sqdmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2)) -> unit + +function decode_sqdmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd (Rd, Rn, H, o2, Rm, M, L, size) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 877) = { + SEE = 877; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + decode_sqdmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd(Rd, Rn, H, o2, Rm, M, L, size) +} + +val decode_sqdmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_sqdmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_simd (Rd, Rn, H, o2, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o2 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_sisd(d, datasize, elements, esize, idxdsize, index, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 878) = { + SEE = 878; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let o2 = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqdmlsl_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_double_simd(Rd, Rn, H, o2, Rm, M, L, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd : forall 'd 'datasize 'elements 'esize 'm 'n 'part ('sub_op : Bool), + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd (d, datasize, elements, esize, m, n, part, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + let operand3 : bits(2 * 'datasize) = V_read(d, 2 * datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + product : bits(2 * 'esize) = undefined; + accum : int = undefined; + sat1 : bool = undefined; + sat2 : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + element2 = SInt(Elem_read(operand2, e, esize)); + (product, sat1) = SignedSatQ(2 * element1 * element2, 2 * esize); + if sub_op then { + accum = SInt(Elem_read(operand3, e, 2 * esize)) - SInt(product) + } else { + accum = SInt(Elem_read(operand3, e, 2 * esize)) + SInt(product) + }; + let (__tup_0 : bits(2 * 'esize), __tup_1 : bool) = + SignedSatQ(accum, 2 * esize) + in + { + result = Elem_set(result, e, 2 * esize, __tup_0); + sat2 = __tup_1 + }; + if sat1 | sat2 then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, 2 * datasize) = result +} + +val decode_sqdmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_sqdmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd (Rd, Rn, o1, Rm, size) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 | size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let sub_op : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 879) = { + SEE = 879; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + decode_sqdmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd(Rd, Rn, o1, Rm, size) +} + +val decode_sqdmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_sqdmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_simd (Rd, Rn, o1, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 | size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 880) = { + SEE = 880; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqdmlal_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_simd(Rd, Rn, o1, Rm, size, Q) +} + +val decode_sqdmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_sqdmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd (Rd, Rn, o1, Rm, size) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 | size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let sub_op : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 881) = { + SEE = 881; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + decode_sqdmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd(Rd, Rn, o1, Rm, size) +} + +val decode_sqdmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_sqdmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_simd (Rd, Rn, o1, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 | size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let sub_op : bool = o1 == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_sisd(d, datasize, elements, esize, m, n, part, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 882) = { + SEE = 882; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o1 = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqdmlsl_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_dmacc_simd(Rd, Rn, o1, Rm, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd : forall 'd 'datasize 'elements 'esize 'm 'n ('rounding : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('rounding)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd (d, datasize, elements, esize, m, n, rounding) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + product : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + element2 = SInt(Elem_read(operand2, e, esize)); + product = 2 * element1 * element2; + product = RShr(product, esize, rounding); + let (__tup_0 : bits('esize), __tup_1 : bool) = + SignedSatQ(product, esize) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let rounding : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd(d, datasize, elements, esize, m, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 883) = { + SEE = 883; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd(Rd, Rn, Rm, size, U) +} + +val decode_sqdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd(d, datasize, elements, esize, m, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 884) = { + SEE = 884; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_simd(Rd, Rn, Rm, size, U, Q) +} + +val decode_sqrdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqrdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let rounding : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd(d, datasize, elements, esize, m, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 885) = { + SEE = 885; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqrdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd(Rd, Rn, Rm, size, U) +} + +val decode_sqrdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqrdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_sisd(d, datasize, elements, esize, m, n, rounding) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 886) = { + SEE = 886; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqrdmulh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_simd(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm 'n ('round : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), bool('round)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd (d, datasize, elements, esize, idxdsize, index, m, n, round) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + result : bits('datasize) = undefined; + element1 : int = undefined; + product : int = undefined; + sat : bool = undefined; + let 'element2 = SInt(Elem_read(operand2, index, esize)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + product = 2 * element1 * element2; + product = RShr(product, esize, round); + let (__tup_0 : bits('esize), __tup_1 : bool) = + SignedSatQ(product, esize) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2)) -> unit + +function decode_sqdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd (Rd, Rn, H, op, Rm, M, L, size) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let round : bool = op == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, round) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 887) = { + SEE = 887; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + decode_sqdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd(Rd, Rn, H, op, Rm, M, L, size) +} + +val decode_sqdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_sqdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_simd (Rd, Rn, H, op, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let round : bool = op == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, round) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitzero, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 888) = { + SEE = 888; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_simd(Rd, Rn, H, op, Rm, M, L, size, Q) +} + +val decode_sqrdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2)) -> unit + +function decode_sqrdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd (Rd, Rn, H, op, Rm, M, L, size) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let round : bool = op == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, round) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 889) = { + SEE = 889; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + decode_sqrdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd(Rd, Rn, H, op, Rm, M, L, size) +} + +val decode_sqrdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_sqrdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_simd (Rd, Rn, H, op, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let round : bool = op == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, round) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 890) = { + SEE = 890; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let op = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqrdmulh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_high_simd(Rd, Rn, H, op, Rm, M, L, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_sisd : forall 'd 'datasize 'elements 'esize 'm 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_sisd (d, datasize, elements, esize, m, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('datasize) = Vpart_read(m, part, datasize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + product : bits(2 * 'esize) = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + element2 = SInt(Elem_read(operand2, e, esize)); + (product, sat) = SignedSatQ(2 * element1 * element2, 2 * esize); + result = Elem_set(result, e, 2 * esize, product); + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, 2 * datasize) = result +} + +val decode_sqdmull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_sisd : (bits(5), bits(5), bits(5), bits(2)) -> unit + +function decode_sqdmull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_sisd (Rd, Rn, Rm, size) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 | size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_sisd(d, datasize, elements, esize, m, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 891) = { + SEE = 891; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + decode_sqdmull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_sisd(Rd, Rn, Rm, size) +} + +val decode_sqdmull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_simd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqdmull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_simd (Rd, Rn, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b00 | size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_sisd(d, datasize, elements, esize, m, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 892) = { + SEE = 892; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqdmull_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_disparate_mul_double_simd(Rd, Rn, Rm, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_double_sisd : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_double_sisd (d, datasize, elements, esize, idxdsize, index, m, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = Vpart_read(n, part, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + result : bits(2 * 'datasize) = undefined; + element1 : int = undefined; + product : bits(2 * 'esize) = undefined; + sat : bool = undefined; + let 'element2 = SInt(Elem_read(operand2, index, esize)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + (product, sat) = SignedSatQ(2 * element1 * element2, 2 * esize); + result = Elem_set(result, e, 2 * esize, product); + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, 2 * datasize) = result +} + +val decode_sqdmull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_double_sisd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(2)) -> unit + +function decode_sqdmull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_double_sisd (Rd, Rn, H, Rm, M, L, size) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_double_sisd(d, datasize, elements, esize, idxdsize, index, m, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitzero, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 893) = { + SEE = 893; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + decode_sqdmull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_double_sisd(Rd, Rn, H, Rm, M, L, size) +} + +val decode_sqdmull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_double_simd : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_sqdmull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_double_simd (Rd, Rn, H, Rm, M, L, size, Q) = { + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_double_sisd(d, datasize, elements, esize, idxdsize, index, m, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitzero, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 894) = { + SEE = 894; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqdmull_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_double_simd(Rd, Rn, H, Rm, M, L, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd : forall 'd 'datasize 'elements 'esize 'm 'n ('rounding : Bool) ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('rounding), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd (d, datasize, elements, esize, m, n, rounding, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + element3 : int = undefined; + accum : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + element2 = SInt(Elem_read(operand2, e, esize)); + element3 = SInt(Elem_read(operand3, e, esize)); + if sub_op then { + accum = (element3 << esize) - 2 * (element1 * element2) + } else { + accum = (element3 << esize) + 2 * (element1 * element2) + }; + accum = RShr(accum, esize, rounding); + let (__tup_0 : bits('esize), __tup_1 : bool) = SignedSatQ(accum, esize) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqrdmlah_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_sqrdmlah_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd (Rd, Rn, S, Rm, size) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd(d, datasize, elements, esize, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 895) = { + SEE = 895; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + decode_sqrdmlah_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd(Rd, Rn, S, Rm, size) +} + +val decode_sqrdmlah_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_sqrdmlah_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_simd (Rd, Rn, S, Rm, size, Q) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd(d, datasize, elements, esize, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 896) = { + SEE = 896; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqrdmlah_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_simd(Rd, Rn, S, Rm, size, Q) +} + +val decode_sqrdmlsh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd : (bits(5), bits(5), bits(1), bits(5), bits(2)) -> unit + +function decode_sqrdmlsh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd (Rd, Rn, S, Rm, size) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd(d, datasize, elements, esize, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 897) = { + SEE = 897; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + decode_sqrdmlsh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd(Rd, Rn, S, Rm, size) +} + +val decode_sqrdmlsh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_simd : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_sqrdmlsh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_simd (Rd, Rn, S, Rm, size, Q) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 | size == 0b00 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_sisd(d, datasize, elements, esize, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 898) = { + SEE = 898; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqrdmlsh_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mul_int_doubling_accum_simd(Rd, Rn, S, Rm, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd : forall 'd 'datasize 'elements 'esize 'idxdsize 'index 'm 'n ('rounding : Bool) ('sub_op : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'index in {0, 1, 2, 3, 4, 5, 6, 7} & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('idxdsize), int('index), int('m), int('n), bool('rounding), bool('sub_op)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd (d, datasize, elements, esize, idxdsize, index, m, n, rounding, sub_op) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('idxdsize) = V_read(m, idxdsize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element3 : int = undefined; + accum : int = undefined; + sat : bool = undefined; + let 'element2 = SInt(Elem_read(operand2, index, esize)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = SInt(Elem_read(operand1, e, esize)); + element3 = SInt(Elem_read(operand3, e, esize)); + if sub_op then { + accum = (element3 << esize) - 2 * (element1 * element2) + } else { + accum = (element3 << esize) + 2 * (element1 * element2) + }; + accum = RShr(accum, esize, rounding); + let (__tup_0 : bits('esize), __tup_1 : bool) = SignedSatQ(accum, esize) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqrdmlah_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2)) -> unit + +function decode_sqrdmlah_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd (Rd, Rn, H, S, Rm, M, L, size) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 899) = { + SEE = 899; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + decode_sqrdmlah_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd(Rd, Rn, H, S, Rm, M, L, size) +} + +val decode_sqrdmlah_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_sqrdmlah_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_simd (Rd, Rn, H, S, Rm, M, L, size, Q) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitzero, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 900) = { + SEE = 900; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqrdmlah_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_simd(Rd, Rn, H, S, Rm, M, L, size, Q) +} + +val decode_sqrdmlsh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2)) -> unit + +function decode_sqrdmlsh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd (Rd, Rn, H, S, Rm, M, L, size) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 901) = { + SEE = 901; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + decode_sqrdmlsh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd(Rd, Rn, H, S, Rm, M, L, size) +} + +val decode_sqrdmlsh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_simd : (bits(5), bits(5), bits(1), bits(1), bits(4), bits(1), bits(1), bits(2), bits(1)) -> unit + +function decode_sqrdmlsh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_simd (Rd, Rn, H, S, Rm, M, L, size, Q) = { + if not_bool(HaveQRDMLAHExt()) then { + throw(Error_Undefined()) + }; + let 'idxdsize = if H == 0b1 then 128 else 64; + index : range(0, 7) = undefined; + Rmhi : bits(1) = undefined; + match size { + 0b01 => { + index = UInt((H @ L) @ M); + Rmhi = 0b0 + }, + 0b10 => { + index = UInt(H @ L); + Rmhi = M + }, + _ => { + throw(Error_Undefined()) + } + }; + let Rmhi = Rmhi; + let 'index = index; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rmhi @ Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let rounding : bool = true; + let sub_op : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_sisd(d, datasize, elements, esize, idxdsize, index, m, n, rounding, sub_op) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, bitone, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 902) = { + SEE = 902; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let S = Slice(__opcode, 13, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqrdmlsh_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mul_acc_high_simd(Rd, Rn, H, S, Rm, M, L, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n ('rounding : Bool) ('saturating : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('rounding), bool('saturating), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element : int = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + shift : int = SInt(Elem_read(operand2, e, esize)[7 .. 0]); + if shift >= 0 then { + element = (element << shift) + } else { + let 'shift = negate(shift); + element = RShr(element, shift, rounding) + }; + let 'element = element; + if saturating then { + let (__tup_0 : bits('esize), __tup_1 : bool) = + SatQ(element, esize, is_unsigned) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + } else { + result = Elem_set(result, e, esize, element[esize - 1 .. 0]) + } + }; + V_set(d, datasize) = result +} + +val decode_sqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_sqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 903) = { + SEE = 903; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_sqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 904) = { + SEE = 904; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val decode_sqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_sqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 905) = { + SEE = 905; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_sqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 906) = { + SEE = 906; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val decode_srshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_srshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 907) = { + SEE = 907; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_srshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_srshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_srshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 908) = { + SEE = 908; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_srshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val decode_sshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_sshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 909) = { + SEE = 909; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_sshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 910) = { + SEE = 910; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val decode_uqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_uqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 911) = { + SEE = 911; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_uqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_uqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 912) = { + SEE = 912; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqrshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val decode_uqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_uqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 913) = { + SEE = 913; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_uqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_uqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 914) = { + SEE = 914; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqshl_advsimd_reg_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val decode_urshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_urshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 915) = { + SEE = 915; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_urshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_urshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_urshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 916) = { + SEE = 916; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_urshl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val decode_ushl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_ushl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd (Rd, Rn, S, R, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + if S == 0b0 & size != 0b11 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 917) = { + SEE = 917; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_ushl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(Rd, Rn, S, R, Rm, size, U) +} + +val decode_ushl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd : (bits(5), bits(5), bits(1), bits(1), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_ushl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd (Rd, Rn, S, R, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + let rounding : bool = R == 0b1; + let saturating : bool = S == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_shift_sisd(d, datasize, elements, esize, m, n, rounding, saturating, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 918) = { + SEE = 918; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let S = Slice(__opcode, 11, 1); + let R = Slice(__opcode, 12, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ushl_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_shift_simd(Rd, Rn, S, R, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n 'part ('round : Bool) 'shift, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part), bool('round), int('shift), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd (d, datasize, elements, esize, n, part, round, shift, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize * 2) = V_read(n, datasize * 2); + result : bits('datasize) = undefined; + element : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = RShr(asl_Int(Elem_read(operand, e, 2 * esize), is_unsigned), shift, round); + let (__tup_0 : bits('esize), __tup_1 : bool) = + SatQ(element, esize, is_unsigned) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + Vpart_set(d, part, datasize) = result +} + +val decode_sqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_sqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd (Rd, Rn, op, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64}))); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 919) = { + SEE = 919; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_sqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(Rd, Rn, op, immb, immh, U) +} + +val decode_sqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_sqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd (Rd, Rn, op, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 920) = { + SEE = 920; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd(Rd, Rn, op, immb, immh, U, Q) +} + +val decode_sqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_sqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd (Rd, Rn, op, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64}))); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 921) = { + SEE = 921; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_sqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(Rd, Rn, op, immb, immh, U) +} + +val decode_sqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_sqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd (Rd, Rn, op, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 922) = { + SEE = 922; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd(Rd, Rn, op, immb, immh, U, Q) +} + +val decode_uqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_uqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd (Rd, Rn, op, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64}))); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 923) = { + SEE = 923; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_uqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(Rd, Rn, op, immb, immh, U) +} + +val decode_uqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_uqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd (Rd, Rn, op, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 924) = { + SEE = 924; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqrshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd(Rd, Rn, op, immb, immh, U, Q) +} + +val decode_uqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_uqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd (Rd, Rn, op, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64}))); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 925) = { + SEE = 925; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_uqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(Rd, Rn, op, immb, immh, U) +} + +val decode_uqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_uqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd (Rd, Rn, op, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + let is_unsigned : bool = U == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_uniform_sisd(d, datasize, elements, esize, n, part, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 926) = { + SEE = 926; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqshrn_advsimd_aarch64_instrs_vector_shift_right_narrow_uniform_simd(Rd, Rn, op, immb, immh, U, Q) +} + +val execute_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd : forall 'd 'datasize 'elements 'esize 'n 'part ('round : Bool) 'shift, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part), bool('round), int('shift)) -> unit + +function execute_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd (d, datasize, elements, esize, n, part, round, shift) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize * 2) = V_read(n, datasize * 2); + result : bits('datasize) = undefined; + element : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = RShr(SInt(Elem_read(operand, e, 2 * esize)), shift, round); + let (__tup_0 : bits('esize), __tup_1 : bool) = + UnsignedSatQ(element, esize) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + Vpart_set(d, part, datasize) = result +} + +val decode_sqrshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4)) -> unit + +function decode_sqrshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd (Rd, Rn, op, immb, immh) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64}))); + execute_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd(d, datasize, elements, esize, n, part, round, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 927) = { + SEE = 927; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + decode_sqrshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd(Rd, Rn, op, immb, immh) +} + +val decode_sqrshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_sqrshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_simd (Rd, Rn, op, immb, immh, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd(d, datasize, elements, esize, n, part, round, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 928) = { + SEE = 928; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let Q = Slice(__opcode, 30, 1); + decode_sqrshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_simd(Rd, Rn, op, immb, immh, Q) +} + +val decode_sqshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4)) -> unit + +function decode_sqshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd (Rd, Rn, op, immb, immh) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'part = 0; + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64}))); + execute_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd(d, datasize, elements, esize, n, part, round, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 929) = { + SEE = 929; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + decode_sqshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd(Rd, Rn, op, immb, immh) +} + +val decode_sqshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_sqshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_simd (Rd, Rn, op, immb, immh, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = 2 * esize - UInt(immh @ immb); + let round : bool = op == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_right_narrow_nonuniform_sisd(d, datasize, elements, esize, n, part, round, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 930) = { + SEE = 930; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 11, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let Q = Slice(__opcode, 30, 1); + decode_sqshrun_advsimd_aarch64_instrs_vector_shift_right_narrow_nonuniform_simd(Rd, Rn, op, immb, immh, Q) +} + +val execute_aarch64_instrs_vector_shift_left_sat_sisd : forall 'd 'datasize ('dst_unsigned : Bool) 'elements 'esize 'n 'shift ('src_unsigned : Bool), + (0 <= 'n & 'n <= 31 & 'esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), bool('dst_unsigned), int('elements), int('esize), int('n), int('shift), bool('src_unsigned)) -> unit + +function execute_aarch64_instrs_vector_shift_left_sat_sisd (d, datasize, dst_unsigned, elements, esize, n, shift, src_unsigned) = { + CheckFPAdvSIMDEnabled64(); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = (asl_Int(Elem_read(operand, e, esize), src_unsigned) << shift); + let (__tup_0 : bits('esize), __tup_1 : bool) = + SatQ(element, esize, dst_unsigned) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_sqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_sisd (Rd, Rn, op, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'shift = UInt(immh @ immb) - esize; + src_unsigned : bool = undefined; + dst_unsigned : bool = undefined; + match op @ U { + 0b00 => { + throw(Error_Undefined()) + }, + 0b01 => { + src_unsigned = false; + dst_unsigned = true + }, + 0b10 => { + src_unsigned = false; + dst_unsigned = false + }, + 0b11 => { + src_unsigned = true; + dst_unsigned = true + } + }; + let dst_unsigned = dst_unsigned; + let src_unsigned = src_unsigned; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64, 128}))); + execute_aarch64_instrs_vector_shift_left_sat_sisd(d, datasize, dst_unsigned, elements, esize, n, shift, src_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 931) = { + SEE = 931; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_sqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_sisd(Rd, Rn, op, immb, immh, U) +} + +val decode_sqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_sqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_simd (Rd, Rn, op, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = UInt(immh @ immb) - esize; + src_unsigned : bool = undefined; + dst_unsigned : bool = undefined; + match op @ U { + 0b00 => { + throw(Error_Undefined()) + }, + 0b01 => { + src_unsigned = false; + dst_unsigned = true + }, + 0b10 => { + src_unsigned = false; + dst_unsigned = false + }, + 0b11 => { + src_unsigned = true; + dst_unsigned = true + } + }; + let dst_unsigned = dst_unsigned; + let src_unsigned = src_unsigned; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_left_sat_sisd(d, datasize, dst_unsigned, elements, esize, n, shift, src_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 932) = { + SEE = 932; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_simd(Rd, Rn, op, immb, immh, U, Q) +} + +val decode_sqshlu_advsimd_aarch64_instrs_vector_shift_left_sat_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_sqshlu_advsimd_aarch64_instrs_vector_shift_left_sat_sisd (Rd, Rn, op, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'shift = UInt(immh @ immb) - esize; + src_unsigned : bool = undefined; + dst_unsigned : bool = undefined; + match op @ U { + 0b00 => { + throw(Error_Undefined()) + }, + 0b01 => { + src_unsigned = false; + dst_unsigned = true + }, + 0b10 => { + src_unsigned = false; + dst_unsigned = false + }, + 0b11 => { + src_unsigned = true; + dst_unsigned = true + } + }; + let dst_unsigned = dst_unsigned; + let src_unsigned = src_unsigned; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64, 128}))); + execute_aarch64_instrs_vector_shift_left_sat_sisd(d, datasize, dst_unsigned, elements, esize, n, shift, src_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 933) = { + SEE = 933; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_sqshlu_advsimd_aarch64_instrs_vector_shift_left_sat_sisd(Rd, Rn, op, immb, immh, U) +} + +val decode_sqshlu_advsimd_aarch64_instrs_vector_shift_left_sat_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_sqshlu_advsimd_aarch64_instrs_vector_shift_left_sat_simd (Rd, Rn, op, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = UInt(immh @ immb) - esize; + src_unsigned : bool = undefined; + dst_unsigned : bool = undefined; + match op @ U { + 0b00 => { + throw(Error_Undefined()) + }, + 0b01 => { + src_unsigned = false; + dst_unsigned = true + }, + 0b10 => { + src_unsigned = false; + dst_unsigned = false + }, + 0b11 => { + src_unsigned = true; + dst_unsigned = true + } + }; + let dst_unsigned = dst_unsigned; + let src_unsigned = src_unsigned; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_left_sat_sisd(d, datasize, dst_unsigned, elements, esize, n, shift, src_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 934) = { + SEE = 934; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqshlu_advsimd_aarch64_instrs_vector_shift_left_sat_simd(Rd, Rn, op, immb, immh, U, Q) +} + +val decode_uqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_sisd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_uqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_sisd (Rd, Rn, op, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = esize; + let 'elements = 1; + let 'shift = UInt(immh @ immb) - esize; + src_unsigned : bool = undefined; + dst_unsigned : bool = undefined; + match op @ U { + 0b00 => { + throw(Error_Undefined()) + }, + 0b01 => { + src_unsigned = false; + dst_unsigned = true + }, + 0b10 => { + src_unsigned = false; + dst_unsigned = false + }, + 0b11 => { + src_unsigned = true; + dst_unsigned = true + } + }; + let dst_unsigned = dst_unsigned; + let src_unsigned = src_unsigned; + assert(constraint(('esize in {4, 8, 16, 32, 64} & 'datasize in {4, 8, 16, 32, 64, 128}))); + execute_aarch64_instrs_vector_shift_left_sat_sisd(d, datasize, dst_unsigned, elements, esize, n, shift, src_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 935) = { + SEE = 935; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_uqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_sisd(Rd, Rn, op, immb, immh, U) +} + +val decode_uqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_simd : (bits(5), bits(5), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_uqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_simd (Rd, Rn, op, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = UInt(immh @ immb) - esize; + src_unsigned : bool = undefined; + dst_unsigned : bool = undefined; + match op @ U { + 0b00 => { + throw(Error_Undefined()) + }, + 0b01 => { + src_unsigned = false; + dst_unsigned = true + }, + 0b10 => { + src_unsigned = false; + dst_unsigned = false + }, + 0b11 => { + src_unsigned = true; + dst_unsigned = true + } + }; + let dst_unsigned = dst_unsigned; + let src_unsigned = src_unsigned; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_left_sat_sisd(d, datasize, dst_unsigned, elements, esize, n, shift, src_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 936) = { + SEE = 936; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqshl_advsimd_imm_aarch64_instrs_vector_shift_left_sat_simd(Rd, Rn, op, immb, immh, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd (d, datasize, elements, esize, m, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + diff : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + diff = element1 - element2; + let (__tup_0 : bits('esize), __tup_1 : bool) = + SatQ(diff, esize, is_unsigned) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_sqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 937) = { + SEE = 937; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd(Rd, Rn, Rm, size, U) +} + +val decode_sqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 938) = { + SEE = 938; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_simd(Rd, Rn, Rm, size, U, Q) +} + +val decode_uqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd : (bits(5), bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_uqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd (Rd, Rn, Rm, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 939) = { + SEE = 939; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_uqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd(Rd, Rn, Rm, size, U) +} + +val decode_uqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_simd : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_simd (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_sisd(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 940) = { + SEE = 940; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqsub_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_sub_saturating_simd(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd (d, datasize, elements, esize, n, part, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits(2 * 'datasize) = V_read(n, 2 * datasize); + result : bits('datasize) = undefined; + element : bits(2 * 'esize) = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, 2 * esize); + let (__tup_0 : bits('esize), __tup_1 : bool) = + SatQ(asl_Int(element, is_unsigned), esize, is_unsigned) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + Vpart_set(d, part, datasize) = result +} + +val decode_sqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'part = 0; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd(d, datasize, elements, esize, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 941) = { + SEE = 941; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_sqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd(Rd, Rn, size, U) +} + +val decode_sqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_sqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd(d, datasize, elements, esize, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 942) = { + SEE = 942; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_simd(Rd, Rn, size, U, Q) +} + +val decode_uqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_uqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'part = 0; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd(d, datasize, elements, esize, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 943) = { + SEE = 943; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_uqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd(Rd, Rn, size, U) +} + +val decode_uqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_uqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_extract_sat_sisd(d, datasize, elements, esize, n, part, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 944) = { + SEE = 944; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_uqxtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sat_simd(Rd, Rn, size, U, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_sisd : forall 'd 'datasize 'elements 'esize 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_sisd (d, datasize, elements, esize, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits(2 * 'datasize) = V_read(n, 2 * datasize); + result : bits('datasize) = undefined; + element : bits(2 * 'esize) = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, 2 * esize); + let (__tup_0 : bits('esize), __tup_1 : bool) = + UnsignedSatQ(SInt(element), esize) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + Vpart_set(d, part, datasize) = result +} + +val decode_sqxtun_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_sisd : (bits(5), bits(5), bits(2)) -> unit + +function decode_sqxtun_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_sisd (Rd, Rn, size) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'part = 0; + let 'elements = 1; + execute_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_sisd(d, datasize, elements, esize, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 945) = { + SEE = 945; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + decode_sqxtun_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_sisd(Rd, Rn, size) +} + +val decode_sqxtun_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_simd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_sqxtun_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_simd (Rd, Rn, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_sisd(d, datasize, elements, esize, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 946) = { + SEE = 946; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_sqxtun_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_sqxtun_simd(Rd, Rn, size, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding (d, datasize, elements, esize, m, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + element1 : int = undefined; + element2 : int = undefined; + sum : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element1 = asl_Int(Elem_read(operand1, e, esize), is_unsigned); + element2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + sum = ((element1 + element2 + 1) >> 1); + result = Elem_set(result, e, esize, sum[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_srhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_srhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 947) = { + SEE = 947; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_srhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding(Rd, Rn, Rm, size, U, Q) +} + +val decode_urhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding : (bits(5), bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_urhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding (Rd, Rn, Rm, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding(d, datasize, elements, esize, m, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 948) = { + SEE = 948; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_urhadd_advsimd_aarch64_instrs_vector_arithmetic_binary_uniform_add_halving_rounding(Rd, Rn, Rm, size, U, Q) +} + +val execute_aarch64_instrs_vector_shift_right_insert_sisd : forall 'd 'datasize 'elements 'esize 'n 'shift, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('shift)) -> unit + +function execute_aarch64_instrs_vector_shift_right_insert_sisd (d, datasize, elements, esize, n, shift) = { + CheckFPAdvSIMDEnabled64(); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let operand : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + assert(constraint('esize >= 0)); + let mask : bits('esize) = LSR(Ones(esize), shift); + shifted : bits('esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + assert(constraint(('loop_e * 'esize <= 'loop_e * 'esize + 'esize - 1 | not(('loop_e >= 0 & ('loop_e + 1) * 'esize <= 'datasize)) | not('esize >= 0) | not('datasize in {8, 16, 32, 64, 128})))); + shifted = LSR(Elem_read(operand, e, esize), shift); + result = Elem_set(result, e, esize, Elem_read(operand2, e, esize) & not_vec(mask) | shifted) + }; + V_set(d, datasize) = result +} + +val decode_sri_advsimd_aarch64_instrs_vector_shift_right_insert_sisd : (bits(5), bits(5), bits(3), bits(4)) -> unit + +function decode_sri_advsimd_aarch64_instrs_vector_shift_right_insert_sisd (Rd, Rn, immb, immh) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + execute_aarch64_instrs_vector_shift_right_insert_sisd(d, datasize, elements, esize, n, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 949) = { + SEE = 949; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + decode_sri_advsimd_aarch64_instrs_vector_shift_right_insert_sisd(Rd, Rn, immb, immh) +} + +val decode_sri_advsimd_aarch64_instrs_vector_shift_right_insert_simd : (bits(5), bits(5), bits(3), bits(4), bits(1)) -> unit + +function decode_sri_advsimd_aarch64_instrs_vector_shift_right_insert_simd (Rd, Rn, immb, immh, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + execute_aarch64_instrs_vector_shift_right_insert_sisd(d, datasize, elements, esize, n, shift) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 950) = { + SEE = 950; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let Q = Slice(__opcode, 30, 1); + decode_sri_advsimd_aarch64_instrs_vector_shift_right_insert_simd(Rd, Rn, immb, immh, Q) +} + +val execute_aarch64_instrs_vector_shift_right_sisd : forall ('accumulate : Bool) 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n ('round : Bool) 'shift, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (bool('accumulate), int('d), int('datasize), int('elements), int('esize), int('n), bool('round), int('shift), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_shift_right_sisd (accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + assert(constraint('datasize in {8, 16, 32, 64, 128})); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : int = undefined; + let operand2 : bits('datasize) = if accumulate then V_read(d, datasize) else + Zeros(datasize); + foreach (e from 0 to (elements - 1) by 1 in inc) { + assert(constraint('esize >= 0)); + assert(constraint(('loop_e * 'esize <= 'loop_e * 'esize + 'esize - 1 | not(('loop_e >= 0 & ('loop_e + 1) * 'esize <= 'datasize)) | not('datasize in {8, 16, 32, 64, 128})))); + element = RShr(asl_Int(Elem_read(operand, e, esize), is_unsigned), shift, round); + result = Elem_set(result, e, esize, Elem_read(operand2, e, esize) + element[esize - 1 .. 0]) + }; + V_set(d, datasize) = result +} + +val decode_srshr_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_srshr_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 951) = { + SEE = 951; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_srshr_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_srshr_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_srshr_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 952) = { + SEE = 952; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_srshr_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val decode_srsra_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_srsra_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 953) = { + SEE = 953; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_srsra_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_srsra_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_srsra_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 954) = { + SEE = 954; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_srsra_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val decode_sshr_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_sshr_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 955) = { + SEE = 955; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_sshr_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_sshr_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_sshr_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 956) = { + SEE = 956; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sshr_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val decode_ssra_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_ssra_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 957) = { + SEE = 957; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_ssra_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_ssra_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_ssra_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 958) = { + SEE = 958; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ssra_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val decode_urshr_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_urshr_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 959) = { + SEE = 959; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_urshr_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_urshr_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_urshr_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 960) = { + SEE = 960; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_urshr_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val decode_ursra_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_ursra_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 961) = { + SEE = 961; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_ursra_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_ursra_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_ursra_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 962) = { + SEE = 962; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ursra_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val decode_ushr_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_ushr_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 963) = { + SEE = 963; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_ushr_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_ushr_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_ushr_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 964) = { + SEE = 964; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ushr_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val decode_usra_advsimd_aarch64_instrs_vector_shift_right_sisd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1)) -> unit + +function decode_usra_advsimd_aarch64_instrs_vector_shift_right_sisd (Rd, Rn, o0, o1, immb, immh, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if [immh[3]] != 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << 3); + let 'datasize = esize; + let 'elements = 1; + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 965) = { + SEE = 965; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + decode_usra_advsimd_aarch64_instrs_vector_shift_right_sisd(Rd, Rn, o0, o1, immb, immh, U) +} + +val decode_usra_advsimd_aarch64_instrs_vector_shift_right_simd : (bits(5), bits(5), bits(1), bits(1), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_usra_advsimd_aarch64_instrs_vector_shift_right_simd (Rd, Rn, o0, o1, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if ([immh[3]] @ Q) == 0b10 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'shift = esize * 2 - UInt(immh @ immb); + let is_unsigned : bool = U == 0b1; + let round : bool = o1 == 0b1; + let accumulate : bool = o0 == 0b1; + execute_aarch64_instrs_vector_shift_right_sisd(accumulate, d, datasize, elements, esize, n, round, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 966) = { + SEE = 966; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let o0 = Slice(__opcode, 12, 1); + let o1 = Slice(__opcode, 13, 1); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_usra_advsimd_aarch64_instrs_vector_shift_right_simd(Rd, Rn, o0, o1, immb, immh, U, Q) +} + +val execute_aarch64_instrs_vector_shift_left_long : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n 'part 'shift, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {4, 8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part), int('shift), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_shift_left_long (d, datasize, elements, esize, n, part, shift, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = Vpart_read(n, part, datasize); + result : bits('datasize * 2) = undefined; + element : int = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = (asl_Int(Elem_read(operand, e, esize), is_unsigned) << shift); + result = Elem_set(result, e, 2 * esize, element[2 * esize - 1 .. 0]) + }; + V_set(d, datasize * 2) = result +} + +val decode_sshll_advsimd_aarch64_instrs_vector_shift_left_long : (bits(5), bits(5), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_sshll_advsimd_aarch64_instrs_vector_shift_left_long (Rd, Rn, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = UInt(immh @ immb) - esize; + let is_unsigned : bool = U == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_left_long(d, datasize, elements, esize, n, part, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 967) = { + SEE = 967; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_sshll_advsimd_aarch64_instrs_vector_shift_left_long(Rd, Rn, immb, immh, U, Q) +} + +val decode_ushll_advsimd_aarch64_instrs_vector_shift_left_long : (bits(5), bits(5), bits(3), bits(4), bits(1), bits(1)) -> unit + +function decode_ushll_advsimd_aarch64_instrs_vector_shift_left_long (Rd, Rn, immb, immh, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if immh == 0b0000 then { + throw(Error_See("asimdimm")) + }; + if [immh[3]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << HighestSetBit(immh)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + let 'shift = UInt(immh @ immb) - esize; + let is_unsigned : bool = U == 0b1; + assert(constraint('esize in {4, 8, 16, 32, 64})); + execute_aarch64_instrs_vector_shift_left_long(d, datasize, elements, esize, n, part, shift, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 968) = { + SEE = 968; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let immb = Slice(__opcode, 16, 3); + let immh = Slice(__opcode, 19, 4); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_ushll_advsimd_aarch64_instrs_vector_shift_left_long(Rd, Rn, immb, immh, U, Q) +} + +val execute_aarch64_instrs_integer_tags_mcsettagpairpost : forall 'n ('postindex : Bool) 't ('writeback : Bool) ('zero_data : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), bits(64), bool('postindex), int('t), bool('writeback), bool('zero_data)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsettagpairpost (n, offset, postindex, t, writeback, zero_data) = { + address : bits(64) = undefined; + let data : bits(64) = if t == 31 then SP_read() else X_read(t, 64); + let tag : bits(4) = AArch64_AllocationTagFromAddress(data); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_STORE); + if zero_data then { + if not_bool(IsAligned__1(address, TAG_GRANULE)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + Mem_set(address, TAG_GRANULE, accdesc) = Zeros(TAG_GRANULE * 8); + Mem_set(address + TAG_GRANULE, TAG_GRANULE, accdesc) = Zeros(TAG_GRANULE * 8) + }; + AArch64_MemTag_set(address, accdesc) = tag; + AArch64_MemTag_set(address + TAG_GRANULE, accdesc) = tag; + if writeback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + () +} + +val decode_st2g_aarch64_instrs_integer_tags_mcsettagpairpost : (bits(5), bits(5), bits(9)) -> unit + +function decode_st2g_aarch64_instrs_integer_tags_mcsettagpairpost (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = true; + let zero_data : bool = false; + execute_aarch64_instrs_integer_tags_mcsettagpairpost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 969) = { + SEE = 969; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_st2g_aarch64_instrs_integer_tags_mcsettagpairpost(Xt, Xn, imm9) +} + +val decode_st2g_aarch64_instrs_integer_tags_mcsettagpairpre : (bits(5), bits(5), bits(9)) -> unit + +function decode_st2g_aarch64_instrs_integer_tags_mcsettagpairpre (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = false; + let zero_data : bool = false; + execute_aarch64_instrs_integer_tags_mcsettagpairpost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 970) = { + SEE = 970; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_st2g_aarch64_instrs_integer_tags_mcsettagpairpre(Xt, Xn, imm9) +} + +val decode_st2g_aarch64_instrs_integer_tags_mcsettagpair : (bits(5), bits(5), bits(9)) -> unit + +function decode_st2g_aarch64_instrs_integer_tags_mcsettagpair (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = false; + let postindex : bool = false; + let zero_data : bool = false; + execute_aarch64_instrs_integer_tags_mcsettagpairpost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 971) = { + SEE = 971; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_st2g_aarch64_instrs_integer_tags_mcsettagpair(Xt, Xn, imm9) +} + +val execute_aarch64_instrs_memory_atomicops_st_acc_st64b : forall 'n 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bits(2), MemOp, int('n), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_st_acc_st64b (lst, memop, n, t, tagchecked) = { + CheckLDST64BEnabled(); + data : bits(512) = undefined; + address : bits(64) = undefined; + value_name : bits(64) = undefined; + let accdesc : AccessDescriptor = CreateAccDescLS64(memop, tagchecked); + foreach (i from 0 to 7 by 1 in inc) { + value_name = X_read(t + i, 64); + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + data[63 + 64 * i .. 64 * i] = value_name + }; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + SetLoadStoreType(lst); + AArch64_SetLSInstructionSyndrome(64, false, t, true, false); + MemStore64B(address, data, accdesc); + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_st64b_aarch64_instrs_memory_atomicops_st_acc_st64b : (bits(5), bits(5)) -> unit + +function decode_st64b_aarch64_instrs_memory_atomicops_st_acc_st64b (Rt, Rn) = { + if not_bool(HaveFeatLS64()) then { + throw(Error_Undefined()) + }; + if Rt[4 .. 3] == 0b11 | [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let memop : MemOp = MemOp_STORE; + let tagchecked : bool = n != 31; + let lst : bits(2) = lst_64b; + execute_aarch64_instrs_memory_atomicops_st_acc_st64b(lst, memop, n, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 972) = { + SEE = 972; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + decode_st64b_aarch64_instrs_memory_atomicops_st_acc_st64b(Rt, Rn) +} + +val execute_aarch64_instrs_memory_atomicops_st_acc_st64bv : forall 'n 's 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bits(5), bits(2), MemOp, int('n), int('s), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_st_acc_st64bv (Rs, lst, memop, n, s, t, tagchecked) = { + CheckST64BVEnabled(); + data : bits(512) = undefined; + address : bits(64) = undefined; + value_name : bits(64) = undefined; + let accdesc : AccessDescriptor = CreateAccDescLS64(memop, tagchecked); + foreach (i from 0 to 7 by 1 in inc) { + value_name = X_read(t + i, 64); + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + data[63 + 64 * i .. 64 * i] = value_name + }; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + SetLoadStoreType(lst); + AArch64_SetLSInstructionSyndrome(64, false, t, true, false); + SetIss2(Rs); + let status : bits(64) = MemStore64BWithRet(address, data, accdesc); + if s != 31 then { + X_set(s, 64) = status + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_st64bv_aarch64_instrs_memory_atomicops_st_acc_st64bv : (bits(5), bits(5), bits(5)) -> unit + +function decode_st64bv_aarch64_instrs_memory_atomicops_st_acc_st64bv (Rt, Rn, Rs) = { + if not_bool(HaveFeatLS64_V()) then { + throw(Error_Undefined()) + }; + if Rt[4 .. 3] == 0b11 | [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let memop : MemOp = MemOp_STORE; + let 's = UInt(Rs); + let tagchecked : bool = n != 31; + let lst : bits(2) = lst_64bv; + execute_aarch64_instrs_memory_atomicops_st_acc_st64bv(Rs, lst, memop, n, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 973) = { + SEE = 973; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + decode_st64bv_aarch64_instrs_memory_atomicops_st_acc_st64bv(Rt, Rn, Rs) +} + +val execute_aarch64_instrs_memory_atomicops_st_acc_st64bv0 : forall 'n 's 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 0 <= 'n & 'n <= 31). + (bits(5), bits(2), MemOp, int('n), int('s), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_st_acc_st64bv0 (Rs, lst, memop, n, s, t, tagchecked) = { + CheckST64BV0Enabled(); + data : bits(512) = undefined; + address : bits(64) = undefined; + value_name : bits(64) = undefined; + let accdesc : AccessDescriptor = CreateAccDescLS64(memop, tagchecked); + let Xt : bits(64) = X_read(t, 64); + value_name[31 .. 0] = ACCDATA_EL1.bits[31 .. 0]; + value_name[63 .. 32] = Xt[63 .. 32]; + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + data[63 .. 0] = value_name; + foreach (i from 1 to 7 by 1 in inc) { + value_name = X_read(t + i, 64); + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + data[63 + 64 * i .. 64 * i] = value_name + }; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + SetLoadStoreType(lst); + AArch64_SetLSInstructionSyndrome(64, false, t, true, false); + SetIss2(Rs); + let status : bits(64) = MemStore64BWithRet(address, data, accdesc); + if s != 31 then { + X_set(s, 64) = status + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_st64bv0_aarch64_instrs_memory_atomicops_st_acc_st64bv0 : (bits(5), bits(5), bits(5)) -> unit + +function decode_st64bv0_aarch64_instrs_memory_atomicops_st_acc_st64bv0 (Rt, Rn, Rs) = { + if not_bool(HaveFeatLS64_ACCDATA()) then { + throw(Error_Undefined()) + }; + if Rt[4 .. 3] == 0b11 | [Rt[0]] == 0b1 then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let memop : MemOp = MemOp_STORE; + let 's = UInt(Rs); + let tagchecked : bool = n != 31; + let lst : bits(2) = lst_64bv0; + execute_aarch64_instrs_memory_atomicops_st_acc_st64bv0(Rs, lst, memop, n, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 974) = { + SEE = 974; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + decode_st64bv0_aarch64_instrs_memory_atomicops_st_acc_st64bv0(Rt, Rn, Rs) +} + +val execute_aarch64_instrs_integer_tags_mcsettagpost : forall 'n ('postindex : Bool) 't ('writeback : Bool) ('zero_data : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), bits(64), bool('postindex), int('t), bool('writeback), bool('zero_data)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsettagpost (n, offset, postindex, t, writeback, zero_data) = { + address : bits(64) = undefined; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_STORE); + if zero_data then { + if not_bool(IsAligned__1(address, TAG_GRANULE)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + Mem_set(address, TAG_GRANULE, accdesc) = Zeros(TAG_GRANULE * 8) + }; + let data : bits(64) = if t == 31 then SP_read() else X_read(t, 64); + let tag : bits(4) = AArch64_AllocationTagFromAddress(data); + AArch64_MemTag_set(address, accdesc) = tag; + if writeback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + () +} + +val decode_stg_aarch64_instrs_integer_tags_mcsettagpost : (bits(5), bits(5), bits(9)) -> unit + +function decode_stg_aarch64_instrs_integer_tags_mcsettagpost (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = true; + let zero_data : bool = false; + execute_aarch64_instrs_integer_tags_mcsettagpost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 975) = { + SEE = 975; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stg_aarch64_instrs_integer_tags_mcsettagpost(Xt, Xn, imm9) +} + +val decode_stg_aarch64_instrs_integer_tags_mcsettagpre : (bits(5), bits(5), bits(9)) -> unit + +function decode_stg_aarch64_instrs_integer_tags_mcsettagpre (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = false; + let zero_data : bool = false; + execute_aarch64_instrs_integer_tags_mcsettagpost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 976) = { + SEE = 976; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stg_aarch64_instrs_integer_tags_mcsettagpre(Xt, Xn, imm9) +} + +val decode_stg_aarch64_instrs_integer_tags_mcsettag : (bits(5), bits(5), bits(9)) -> unit + +function decode_stg_aarch64_instrs_integer_tags_mcsettag (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = false; + let postindex : bool = false; + let zero_data : bool = false; + execute_aarch64_instrs_integer_tags_mcsettagpost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 977) = { + SEE = 977; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stg_aarch64_instrs_integer_tags_mcsettag(Xt, Xn, imm9) +} + +val execute_aarch64_instrs_integer_tags_mcsettagarray : forall 'n 't, + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), int('t)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsettagarray (n, t) = { + if PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + let data : bits(64) = X_read(t, 64); + address : bits(64) = undefined; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let 'size = 4 * pow2(UInt(GMID_EL1[BS])); + address : bits(64) = Align(address, size); + let 'count = (size >> LOG2_TAG_GRANULE); + index : int = UInt(address[LOG2_TAG_GRANULE + 3 .. LOG2_TAG_GRANULE]); + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_STORE); + foreach (i from 0 to (count - 1) by 1 in inc) { + let tag : bits(4) = let 'index = index in + { + assert(constraint((0 <= 'index * 4 & 'index * 4 + 3 < 64))); + data[index * 4 + 3 .. index * 4] + }; + AArch64_MemTag_set(address, accdesc) = tag; + address = address + TAG_GRANULE; + index = index + 1 + } +} + +val decode_stgm_aarch64_instrs_integer_tags_mcsettagarray : (bits(5), bits(5)) -> unit + +function decode_stgm_aarch64_instrs_integer_tags_mcsettagarray (Xt, Xn) = { + if not_bool(HaveMTE2Ext()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Xt); + let 'n = UInt(Xn); + execute_aarch64_instrs_integer_tags_mcsettagarray(n, t) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 978) = { + SEE = 978; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + decode_stgm_aarch64_instrs_integer_tags_mcsettagarray(Xt, Xn) +} + +val execute_aarch64_instrs_integer_tags_mcsettaganddatapairpost : forall 'n ('postindex : Bool) 't 't2 ('writeback : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), bits(64), bool('postindex), int('t), int('t2), bool('writeback)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsettaganddatapairpost (n, offset, postindex, t, t2, writeback) = { + address : bits(64) = undefined; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let data1 : bits(64) = X_read(t, 64); + let data2 : bits(64) = X_read(t2, 64); + if not_bool(postindex) then { + address = address + offset + }; + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_STORE); + if not_bool(IsAligned__1(address, TAG_GRANULE)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + Mem_set(address, 8, accdesc) = data1; + Mem_set(address + 8, 8, accdesc) = data2; + AArch64_MemTag_set(address, accdesc) = AArch64_AllocationTagFromAddress(address); + if writeback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + () +} + +val decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapairpost : (bits(5), bits(5), bits(5), bits(7)) -> unit + +function decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapairpost (Xt, Xn, Xt2, simm7) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let 't2 = UInt(Xt2); + let offset : bits(64) = LSL(SignExtend(simm7, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = true; + execute_aarch64_instrs_integer_tags_mcsettaganddatapairpost(n, offset, postindex, t, t2, writeback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 979) = { + SEE = 979; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let Xt2 = Slice(__opcode, 10, 5); + let simm7 = Slice(__opcode, 15, 7); + decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapairpost(Xt, Xn, Xt2, simm7) +} + +val decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapairpre : (bits(5), bits(5), bits(5), bits(7)) -> unit + +function decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapairpre (Xt, Xn, Xt2, simm7) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let 't2 = UInt(Xt2); + let offset : bits(64) = LSL(SignExtend(simm7, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = false; + execute_aarch64_instrs_integer_tags_mcsettaganddatapairpost(n, offset, postindex, t, t2, writeback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 980) = { + SEE = 980; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let Xt2 = Slice(__opcode, 10, 5); + let simm7 = Slice(__opcode, 15, 7); + decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapairpre(Xt, Xn, Xt2, simm7) +} + +val decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapair : (bits(5), bits(5), bits(5), bits(7)) -> unit + +function decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapair (Xt, Xn, Xt2, simm7) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let 't2 = UInt(Xt2); + let offset : bits(64) = LSL(SignExtend(simm7, 64), LOG2_TAG_GRANULE); + let writeback : bool = false; + let postindex : bool = false; + execute_aarch64_instrs_integer_tags_mcsettaganddatapairpost(n, offset, postindex, t, t2, writeback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 981) = { + SEE = 981; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let Xt2 = Slice(__opcode, 10, 5); + let simm7 = Slice(__opcode, 15, 7); + decode_stgp_aarch64_instrs_integer_tags_mcsettaganddatapair(Xt, Xn, Xt2, simm7) +} + +val execute_aarch64_instrs_memory_ordered_pair_stilp : forall 'datasize 'n 'offset ('postindex : Bool) ('rt_unknown : Bool) 't 't2 ('tagchecked : Bool) ('wb_unknown : Bool) ('wback : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31 & 'datasize in {32, 64}). + (int('datasize), MemOp, int('n), int('offset), bool('postindex), bool('rt_unknown), int('t), int('t2), bool('tagchecked), bool('wb_unknown), bool('wback)) -> unit + +function execute_aarch64_instrs_memory_ordered_pair_stilp (datasize, memop, n, offset, postindex, rt_unknown, t, t2, tagchecked, wb_unknown, wback) = { + address : bits(64) = undefined; + data1 : bits('datasize) = undefined; + data2 : bits('datasize) = undefined; + let 'dbytes = DIV(datasize, 8); + let accdesc : AccessDescriptor = CreateAccDescAcqRel(memop, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + match memop { + MemOp_STORE => { + if rt_unknown & t == n then { + data1 = __UNKNOWN_bits(datasize) + } else { + data1 = X_read(t, datasize) + }; + if rt_unknown & t2 == n then { + data2 = __UNKNOWN_bits(datasize) + } else { + data2 = X_read(t2, datasize) + }; + if HaveLSE2Ext() then { + full_data : bits(2 * 'datasize) = undefined; + if BigEndian(accdesc.acctype) then { + full_data = data1 @ data2 + } else { + full_data = data2 @ data1 + }; + let ispair : bool = true; + let highestAddressfirst : bool = not_bool(postindex) & offset < 0; + Mem_set__2(address, 2 * dbytes, accdesc, ispair, highestAddressfirst) = full_data + } else { + if not_bool(postindex) & offset < 0 then { + Mem_set(address + dbytes, dbytes, accdesc) = data2; + Mem_set(address + 0, dbytes, accdesc) = data1 + } else { + Mem_set(address + 0, dbytes, accdesc) = data1; + Mem_set(address + dbytes, dbytes, accdesc) = data2 + } + } + }, + MemOp_LOAD => { + if HaveLSE2Ext() then { + let ispair : bool = true; + let full_data : bits(2 * 'datasize) = Mem_read__1(address, 2 * dbytes, accdesc, ispair); + if BigEndian(accdesc.acctype) then { + data2 = full_data[datasize - 1 .. 0]; + data1 = full_data[2 * datasize - 1 .. datasize] + } else { + data1 = full_data[datasize - 1 .. 0]; + data2 = full_data[2 * datasize - 1 .. datasize] + } + } else { + data1 = Mem_read(address + 0, dbytes, accdesc); + data2 = Mem_read(address + dbytes, dbytes, accdesc) + }; + if rt_unknown then { + data1 = __UNKNOWN_bits(datasize); + data2 = __UNKNOWN_bits(datasize) + }; + X_set(t, datasize) = data1; + X_set(t2, datasize) = data2 + }, + _ => () + }; + if wback then { + if wb_unknown then { + address = __UNKNOWN_bits(64) + } else if postindex then { + address = address + offset + } else (); + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + if SPESampleInFlight then { + SPESampleGeneralPurposeLoadStore() + }; + () +} + +val decode_stilp_aarch64_instrs_memory_ordered_pair_stilp : (bits(5), bits(5), bits(4), bits(5), bits(1), bits(2)) -> unit + +function decode_stilp_aarch64_instrs_memory_ordered_pair_stilp (Rt, Rn, opc2, Rt2, L, size) = { + let postindex : bool = false; + wback : bool = [opc2[0]] == 0b0; + offset : int = undefined; + let 'n = UInt(Rn); + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'scale = 2 + UInt([size[0]]); + let 'datasize = (8 << scale); + memop : MemOp = undefined; + if L == 0b1 then { + memop = MemOp_LOAD; + offset = if [opc2[0]] == 0b0 then (2 << scale) else 0 + } else { + memop = MemOp_STORE; + offset = if [opc2[0]] == 0b0 then negate(1) * (2 << scale) else 0 + }; + let 'offset = offset; + let tagchecked : bool = wback | n != 31; + rt_unknown : bool = false; + wb_unknown : bool = false; + if ((memop == MemOp_LOAD & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPLD); + assert(c == Constraint_WBSUPPRESS | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_WBSUPPRESS => { + wback = false + }, + Constraint_UNKNOWN => { + wb_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if ((memop == MemOp_STORE & wback) & (t == n | t2 == n)) & n != 31 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_WBOVERLAPST); + assert(c == Constraint_NONE | c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_NONE => { + rt_unknown = false + }, + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + if memop == MemOp_LOAD & t == t2 then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LDPOVERLAP); + assert(c == Constraint_UNKNOWN | c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNKNOWN => { + rt_unknown = true + }, + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + }; + assert(constraint('datasize in {32, 64})); + execute_aarch64_instrs_memory_ordered_pair_stilp(datasize, memop, n, offset, postindex, rt_unknown, t, t2, tagchecked, wb_unknown, wback) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 982) = { + SEE = 982; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc2 = Slice(__opcode, 12, 4); + let Rt2 = Slice(__opcode, 16, 5); + let L = Slice(__opcode, 22, 1); + let size = Slice(__opcode, 30, 2); + decode_stilp_aarch64_instrs_memory_ordered_pair_stilp(Rt, Rn, opc2, Rt2, L, size) +} + +val execute_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost : forall 'n ('postindex : Bool) 't ('writeback : Bool) ('zero_data : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), bits(64), bool('postindex), int('t), bool('writeback), bool('zero_data)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost (n, offset, postindex, t, writeback, zero_data) = { + address : bits(64) = undefined; + let data : bits(64) = if t == 31 then SP_read() else X_read(t, 64); + let tag : bits(4) = AArch64_AllocationTagFromAddress(data); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_STORE); + if zero_data then { + if not_bool(IsAligned__1(address, TAG_GRANULE)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + Mem_set(address, TAG_GRANULE, accdesc) = Zeros(TAG_GRANULE * 8); + Mem_set(address + TAG_GRANULE, TAG_GRANULE, accdesc) = Zeros(TAG_GRANULE * 8) + }; + AArch64_MemTag_set(address, accdesc) = tag; + AArch64_MemTag_set(address + TAG_GRANULE, accdesc) = tag; + if writeback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + () +} + +val decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost : (bits(5), bits(5), bits(9)) -> unit + +function decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = true; + let zero_data : bool = true; + execute_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 983) = { + SEE = 983; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost(Xt, Xn, imm9) +} + +val decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodatapre : (bits(5), bits(5), bits(9)) -> unit + +function decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodatapre (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = false; + let zero_data : bool = true; + execute_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 984) = { + SEE = 984; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodatapre(Xt, Xn, imm9) +} + +val decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodata : (bits(5), bits(5), bits(9)) -> unit + +function decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodata (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = false; + let postindex : bool = false; + let zero_data : bool = true; + execute_aarch64_instrs_integer_tags_mcsettagpairandzerodatapost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 985) = { + SEE = 985; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stz2g_aarch64_instrs_integer_tags_mcsettagpairandzerodata(Xt, Xn, imm9) +} + +val execute_aarch64_instrs_integer_tags_mcsettagandzerodatapost : forall 'n ('postindex : Bool) 't ('writeback : Bool) ('zero_data : Bool), + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), bits(64), bool('postindex), int('t), bool('writeback), bool('zero_data)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsettagandzerodatapost (n, offset, postindex, t, writeback, zero_data) = { + address : bits(64) = undefined; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + if not_bool(postindex) then { + address = address + offset + }; + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_STORE); + if zero_data then { + if not_bool(IsAligned__1(address, TAG_GRANULE)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + Mem_set(address, TAG_GRANULE, accdesc) = Zeros(TAG_GRANULE * 8) + }; + let data : bits(64) = if t == 31 then SP_read() else X_read(t, 64); + let tag : bits(4) = AArch64_AllocationTagFromAddress(data); + AArch64_MemTag_set(address, accdesc) = tag; + if writeback then { + if postindex then { + address = address + offset + }; + if n == 31 then { + SP_set() = address + } else { + X_set(n, 64) = address + } + }; + () +} + +val decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodatapost : (bits(5), bits(5), bits(9)) -> unit + +function decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodatapost (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = true; + let zero_data : bool = true; + execute_aarch64_instrs_integer_tags_mcsettagandzerodatapost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 986) = { + SEE = 986; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodatapost(Xt, Xn, imm9) +} + +val decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodatapre : (bits(5), bits(5), bits(9)) -> unit + +function decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodatapre (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = true; + let postindex : bool = false; + let zero_data : bool = true; + execute_aarch64_instrs_integer_tags_mcsettagandzerodatapost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 987) = { + SEE = 987; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodatapre(Xt, Xn, imm9) +} + +val decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodata : (bits(5), bits(5), bits(9)) -> unit + +function decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodata (Xt, Xn, imm9) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Xn); + let 't = UInt(Xt); + let offset : bits(64) = LSL(SignExtend(imm9, 64), LOG2_TAG_GRANULE); + let writeback : bool = false; + let postindex : bool = false; + let zero_data : bool = true; + execute_aarch64_instrs_integer_tags_mcsettagandzerodatapost(n, offset, postindex, t, writeback, zero_data) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 988) = { + SEE = 988; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let imm9 = Slice(__opcode, 12, 9); + decode_stzg_aarch64_instrs_integer_tags_mcsettagandzerodata(Xt, Xn, imm9) +} + +val execute_aarch64_instrs_integer_tags_mcsettagandzeroarray : forall 'n 't, + (0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (int('n), int('t)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsettagandzeroarray (n, t) = { + if PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + let data : bits(64) = X_read(t, 64); + let tag : bits(4) = data[3 .. 0]; + address : bits(64) = undefined; + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let 'size = 4 * pow2(UInt(DCZID_EL0[BS])); + address : bits(64) = Align(address, size); + let 'count = (size >> LOG2_TAG_GRANULE); + let accdesc : AccessDescriptor = CreateAccDescLDGSTG(MemOp_STORE); + foreach (i from 0 to (count - 1) by 1 in inc) { + AArch64_MemTag_set(address, accdesc) = tag; + Mem_set(address, TAG_GRANULE, accdesc) = Zeros(8 * TAG_GRANULE); + address = address + TAG_GRANULE + } +} + +val decode_stzgm_aarch64_instrs_integer_tags_mcsettagandzeroarray : (bits(5), bits(5)) -> unit + +function decode_stzgm_aarch64_instrs_integer_tags_mcsettagandzeroarray (Xt, Xn) = { + if not_bool(HaveMTE2Ext()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Xt); + let 'n = UInt(Xn); + execute_aarch64_instrs_integer_tags_mcsettagandzeroarray(n, t) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 989) = { + SEE = 989; + let Xt = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + decode_stzgm_aarch64_instrs_integer_tags_mcsettagandzeroarray(Xt, Xn) +} + +val execute_aarch64_instrs_integer_tags_mcsubtag : forall ('ADD : Bool) 'd 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'd & 'd <= 31). + (bool('ADD), int('d), int('n), bits(64), bits(4)) -> unit + +function execute_aarch64_instrs_integer_tags_mcsubtag (ADD, d, n, offset, tag_offset) = { + let operand1 : bits(64) = if n == 31 then SP_read() else X_read(n, 64); + let start_tag : bits(4) = AArch64_AllocationTagFromAddress(operand1); + let exclude : bits(16) = GCR_EL1[Exclude]; + result : bits(64) = undefined; + rtag : bits(4) = undefined; + if AArch64_AllocationTagAccessIsEnabled(PSTATE.EL) then { + rtag = AArch64_ChooseNonExcludedTag(start_tag, tag_offset, exclude) + } else { + rtag = 0b0000 + }; + if ADD then { + let (__tup_0 : bits(64), _) = AddWithCarry(operand1, offset, 0b0); + result = __tup_0 + } else { + let (__tup_0 : bits(64), _) = AddWithCarry(operand1, not_vec(offset), 0b1); + result = __tup_0 + }; + let result : bits(64) = AArch64_AddressWithAllocationTag(result, rtag); + if d == 31 then { + SP_set() = result + } else { + X_set(d, 64) = result + } +} + +val decode_subg_aarch64_instrs_integer_tags_mcsubtag : (bits(5), bits(5), bits(4), bits(2), bits(6)) -> unit + +function decode_subg_aarch64_instrs_integer_tags_mcsubtag (Xd, Xn, uimm4, op3, uimm6) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Xd); + let 'n = UInt(Xn); + let tag_offset : bits(4) = uimm4; + let offset : bits(64) = LSL(ZeroExtend(uimm6, 64), LOG2_TAG_GRANULE); + let ADD : bool = false; + execute_aarch64_instrs_integer_tags_mcsubtag(ADD, d, n, offset, tag_offset) +} + +function clause __DecodeA64_DataProcImm ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 990) = { + SEE = 990; + let Xd = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let uimm4 = Slice(__opcode, 10, 4); + let op3 = Slice(__opcode, 14, 2); + let uimm6 = Slice(__opcode, 16, 6); + if [__opcode[14]] != 0b0 | [__opcode[15]] != 0b0 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_subg_aarch64_instrs_integer_tags_mcsubtag(Xd, Xn, uimm4, op3, uimm6) + } +} + +val execute_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddress : forall 'd 'm 'n ('setflags : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n), bool('setflags)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddress (d, m, n, setflags) = { + operand1 : bits(64) = if n == 31 then SP_read() else X_read(n, 64); + operand2 : bits(64) = if m == 31 then SP_read() else X_read(m, 64); + let operand1 : bits(64) = SignExtend(operand1[55 .. 0], 64); + operand2 : bits(64) = SignExtend(operand2[55 .. 0], 64); + result : bits(64) = undefined; + nzcv : bits(4) = undefined; + let operand2 : bits(64) = not_vec(operand2); + (result, nzcv) = AddWithCarry(operand1, operand2, 0b1); + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + X_set(d, 64) = result +} + +val decode_subp_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddress : (bits(5), bits(5), bits(5)) -> unit + +function decode_subp_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddress (Xd, Xn, Xm) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Xd); + let 'n = UInt(Xn); + let 'm = UInt(Xm); + let setflags : bool = false; + execute_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddress(d, m, n, setflags) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 991) = { + SEE = 991; + let Xd = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let Xm = Slice(__opcode, 16, 5); + decode_subp_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddress(Xd, Xn, Xm) +} + +val execute_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddresssetflags : forall 'd 'm 'n ('setflags : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), int('m), int('n), bool('setflags)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddresssetflags (d, m, n, setflags) = { + operand1 : bits(64) = if n == 31 then SP_read() else X_read(n, 64); + operand2 : bits(64) = if m == 31 then SP_read() else X_read(m, 64); + let operand1 : bits(64) = SignExtend(operand1[55 .. 0], 64); + operand2 : bits(64) = SignExtend(operand2[55 .. 0], 64); + result : bits(64) = undefined; + nzcv : bits(4) = undefined; + let operand2 : bits(64) = not_vec(operand2); + (result, nzcv) = AddWithCarry(operand1, operand2, 0b1); + if setflags then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = nzcv + }; + X_set(d, 64) = result +} + +val decode_subps_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddresssetflags : (bits(5), bits(5), bits(5)) -> unit + +function decode_subps_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddresssetflags (Xd, Xn, Xm) = { + if not_bool(HaveMTEExt()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Xd); + let 'n = UInt(Xn); + let 'm = UInt(Xm); + let setflags : bool = true; + execute_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddresssetflags(d, m, n, setflags) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 992) = { + SEE = 992; + let Xd = Slice(__opcode, 0, 5); + let Xn = Slice(__opcode, 5, 5); + let Xm = Slice(__opcode, 16, 5); + decode_subps_aarch64_instrs_integer_arithmetic_pointer_mcsubtracttaggedaddresssetflags(Xd, Xn, Xm) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp : forall 'd 'datasize 'elements 'i 'm 'n ('op1_unsigned : Bool) ('op2_unsigned : Bool), + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'i in {0, 1, 2, 3} & 'elements in {2, 4} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('i), int('m), int('n), bool('op1_unsigned), bool('op2_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp (d, datasize, elements, i, m, n, op1_unsigned, op2_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits(128) = V_read(m, 128); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + res : bits(32) = Elem_read(operand3, e, 32); + foreach (b from 0 to 3 by 1 in inc) { + let 'element1 = asl_Int(Elem_read(operand1, 4 * e + b, 8), op1_unsigned); + let 'element2 = asl_Int(Elem_read(operand2, 4 * i + b, 8), op2_unsigned); + res = res + element1 * element2 + }; + result = Elem_set(result, e, 32, res) + }; + V_set(d, datasize) = result +} + +val decode_sudot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_sudot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp (Rd, Rn, H, Rm, M, L, US, Q) = { + if not_bool(HaveInt8MatMulExt()) then { + throw(Error_Undefined()) + }; + let op1_unsigned : bool = US == 0b1; + let op2_unsigned : bool = US == 0b0; + let 'n = UInt(Rn); + let 'm = UInt(M @ Rm); + let 'd = UInt(Rd); + let 'i = UInt(H @ L); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 32); + execute_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp(d, datasize, elements, i, m, n, op1_unsigned, op2_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, _, _, _, _, _, _, bitone, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 993) = { + SEE = 993; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let US = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_sudot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp(Rd, Rn, H, Rm, M, L, US, Q) +} + +val decode_usdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp : (bits(5), bits(5), bits(1), bits(4), bits(1), bits(1), bits(1), bits(1)) -> unit + +function decode_usdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp (Rd, Rn, H, Rm, M, L, US, Q) = { + if not_bool(HaveInt8MatMulExt()) then { + throw(Error_Undefined()) + }; + let op1_unsigned : bool = US == 0b1; + let op2_unsigned : bool = US == 0b0; + let 'n = UInt(Rn); + let 'm = UInt(M @ Rm); + let 'd = UInt(Rd); + let 'i = UInt(H @ L); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 32); + execute_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp(d, datasize, elements, i, m, n, op1_unsigned, op2_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, bitone, bitone, bitone, bitone, _, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 994) = { + SEE = 994; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let H = Slice(__opcode, 11, 1); + let Rm = Slice(__opcode, 16, 4); + let M = Slice(__opcode, 20, 1); + let L = Slice(__opcode, 21, 1); + let US = Slice(__opcode, 23, 1); + let Q = Slice(__opcode, 30, 1); + decode_usdot_advsimd_elt_aarch64_instrs_vector_arithmetic_binary_element_mat_mul_int_dotp(Rd, Rn, H, Rm, M, L, US, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd : forall 'd 'datasize 'elements 'esize ('is_unsigned : Bool) 'n, + (0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {8, 16, 32, 64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), bool('is_unsigned)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd (d, datasize, elements, esize, n, is_unsigned) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + let operand2 : bits('datasize) = V_read(d, datasize); + op1 : int = undefined; + op2 : int = undefined; + sat : bool = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + op1 = asl_Int(Elem_read(operand, e, esize), not_bool(is_unsigned)); + op2 = asl_Int(Elem_read(operand2, e, esize), is_unsigned); + let (__tup_0 : bits('esize), __tup_1 : bool) = + SatQ(op1 + op2, esize, is_unsigned) + in + { + result = Elem_set(result, e, esize, __tup_0); + sat = __tup_1 + }; + if sat then { + FPSR[QC] = 0b1 + }; + () + }; + V_set(d, datasize) = result +} + +val decode_suqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_suqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 995) = { + SEE = 995; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_suqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd(Rd, Rn, size, U) +} + +val decode_suqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_suqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 996) = { + SEE = 996; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_suqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_simd(Rd, Rn, size, U, Q) +} + +val decode_usqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_usqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd (Rd, Rn, size, U) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'esize = (8 << UInt(size)); + let 'datasize = esize; + let 'elements = 1; + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 997) = { + SEE = 997; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + decode_usqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd(Rd, Rn, size, U) +} + +val decode_usqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_simd : (bits(5), bits(5), bits(2), bits(1), bits(1)) -> unit + +function decode_usqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_simd (Rd, Rn, size, U, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let is_unsigned : bool = U == 0b1; + execute_aarch64_instrs_vector_arithmetic_unary_add_saturating_sisd(d, datasize, elements, esize, n, is_unsigned) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 998) = { + SEE = 998; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let U = Slice(__opcode, 29, 1); + let Q = Slice(__opcode, 30, 1); + decode_usqadd_advsimd_aarch64_instrs_vector_arithmetic_unary_add_saturating_simd(Rd, Rn, size, U, Q) +} + +val execute_aarch64_instrs_system_exceptions_runtime_svc : bits(16) -> unit + +function execute_aarch64_instrs_system_exceptions_runtime_svc imm = { + AArch64_CheckForSVCTrap(imm); + AArch64_CallSupervisor(imm) +} + +val decode_svc_aarch64_instrs_system_exceptions_runtime_svc : bits(16) -> unit + +function decode_svc_aarch64_instrs_system_exceptions_runtime_svc imm16 = { + let imm : bits(16) = imm16; + execute_aarch64_instrs_system_exceptions_runtime_svc(imm) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitone] as __opcode)) if SEE < 999) = { + SEE = 999; + let imm16 = Slice(__opcode, 5, 16); + decode_svc_aarch64_instrs_system_exceptions_runtime_svc(imm16) +} + +val execute_aarch64_instrs_memory_atomicops_swp : forall ('acquire : Bool) 'datasize 'n 'regsize ('release : Bool) 's 't ('tagchecked : Bool), + (0 <= 't & 't <= 31 & 0 <= 's & 's <= 31 & 'regsize in {32, 64} & 0 <= 'n & 'n <= 31 & 'datasize in {8, 16, 32, 64}). + (bool('acquire), int('datasize), int('n), int('regsize), bool('release), int('s), int('t), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_swp (acquire, datasize, n, regsize, release, s, t, tagchecked) = { + address : bits(64) = undefined; + let accdesc : AccessDescriptor = CreateAccDescAtomicOp(MemAtomicOp_SWP, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let store_value : bits('datasize) = X_read(s, datasize); + let comparevalue : bits('datasize) = __UNKNOWN_bits(datasize); + let data : bits('datasize) = MemAtomic(address, comparevalue, store_value, accdesc); + assert(constraint('regsize >= 'datasize)); + X_set(t, regsize) = ZeroExtend(data, regsize); + if SPESampleInFlight then { + let ar : bits(1) = if acquire | release then 0b1 else 0b0; + let excl : bits(1) = 0b0; + let at : bits(1) = 0b1; + let is_load : bool = true; + SPESampleExtendedLoadStore(ar, excl, at, is_load) + }; + () +} + +val decode_swp_aarch64_instrs_memory_atomicops_swp : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_swp_aarch64_instrs_memory_atomicops_swp (Rt, Rn, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_swp(acquire, datasize, n, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitone, _, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1000) = { + SEE = 1000; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_swp_aarch64_instrs_memory_atomicops_swp(Rt, Rn, Rs, R, A, size) +} + +val decode_swpb_aarch64_instrs_memory_atomicops_swp : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_swpb_aarch64_instrs_memory_atomicops_swp (Rt, Rn, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_swp(acquire, datasize, n, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1001) = { + SEE = 1001; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_swpb_aarch64_instrs_memory_atomicops_swp(Rt, Rn, Rs, R, A, size) +} + +val decode_swph_aarch64_instrs_memory_atomicops_swp : (bits(5), bits(5), bits(5), bits(1), bits(1), bits(2)) -> unit + +function decode_swph_aarch64_instrs_memory_atomicops_swp (Rt, Rn, Rs, R, A, size) = { + if not_bool(HaveAtomicExt()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 'n = UInt(Rn); + let 's = UInt(Rs); + let 'datasize = (8 << UInt(size)); + let 'regsize = if datasize == 64 then 64 else 32; + let acquire : bool = A == 0b1 & Rt != 0b11111; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_swp(acquire, datasize, n, regsize, release, s, t, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitone, bitone, bitone, bitone, bitzero, bitzero, bitzero, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1002) = { + SEE = 1002; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rs = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let size = Slice(__opcode, 30, 2); + decode_swph_aarch64_instrs_memory_atomicops_swp(Rt, Rn, Rs, R, A, size) +} + +val execute_aarch64_instrs_memory_atomicops_swp_128 : forall ('acquire : Bool) 'n ('release : Bool) 't 't2 ('tagchecked : Bool), + (0 <= 't2 & 't2 <= 31 & 0 <= 't & 't <= 31 & 0 <= 'n & 'n <= 31). + (bool('acquire), int('n), bool('release), int('t), int('t2), bool('tagchecked)) -> unit + +function execute_aarch64_instrs_memory_atomicops_swp_128 (acquire, n, release, t, t2, tagchecked) = { + address : bits(64) = undefined; + let value1_name : bits(64) = X_read(t, 64); + let value2_name : bits(64) = X_read(t2, 64); + let accdesc : AccessDescriptor = CreateAccDescAtomicOp(MemAtomicOp_SWP, acquire, release, tagchecked); + if n == 31 then { + CheckSPAlignment(); + address = SP_read() + } else { + address = X_read(n, 64) + }; + let store_value : bits(128) = if BigEndian(accdesc.acctype) then + value1_name @ value2_name + else + value2_name @ value1_name; + let comparevalue : bits(128) = __UNKNOWN_bits(128); + let data : bits(128) = MemAtomic(address, comparevalue, store_value, accdesc); + if BigEndian(accdesc.acctype) then { + X_set(t, 64) = data[127 .. 64]; + X_set(t2, 64) = data[63 .. 0] + } else { + X_set(t, 64) = data[63 .. 0]; + X_set(t2, 64) = data[127 .. 64] + } +} + +val decode_swpp_aarch64_instrs_memory_atomicops_swp_128 : (bits(5), bits(5), bits(3), bits(1), bits(5), bits(1), bits(1), bits(1)) -> unit + +function decode_swpp_aarch64_instrs_memory_atomicops_swp_128 (Rt, Rn, opc, o3, Rt2, R, A, S) = { + if not_bool(HaveLSE128()) then { + throw(Error_Undefined()) + }; + if Rt == 0b11111 then { + throw(Error_Undefined()) + }; + if Rt2 == 0b11111 then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + let 't2 = UInt(Rt2); + let 'n = UInt(Rn); + let acquire : bool = A == 0b1; + let release : bool = R == 0b1; + let tagchecked : bool = n != 31; + execute_aarch64_instrs_memory_atomicops_swp_128(acquire, n, release, t, t2, tagchecked) +} + +function clause __DecodeA64_LoadStore ((pc, ([bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1003) = { + SEE = 1003; + let Rt = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let opc = Slice(__opcode, 12, 3); + let o3 = Slice(__opcode, 15, 1); + let Rt2 = Slice(__opcode, 16, 5); + let R = Slice(__opcode, 22, 1); + let A = Slice(__opcode, 23, 1); + let S = Slice(__opcode, 30, 1); + decode_swpp_aarch64_instrs_memory_atomicops_swp_128(Rt, Rn, opc, o3, Rt2, R, A, S) +} + +val execute_aarch64_instrs_system_sysops : forall ('has_result : Bool) 'sys_crm 'sys_crn 'sys_op0 'sys_op1 'sys_op2 't, + (0 <= 't & 't <= 31 & 'sys_op2 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op1 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op0 == 1 & 0 <= 'sys_crn & 'sys_crn <= 15 & 0 <= 'sys_crm & 'sys_crm <= 15). + (bool('has_result), int('sys_crm), int('sys_crn), int('sys_op0), int('sys_op1), int('sys_op2), int('t)) -> unit + +function execute_aarch64_instrs_system_sysops (has_result, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t) = { + if has_result then { + AArch64_SysInstrWithResult(sys_op0, sys_op1, sys_crn, sys_crm, sys_op2, t) + } else { + AArch64_SysInstr(sys_op0, sys_op1, sys_crn, sys_crm, sys_op2, t) + } +} + +val decode_sys_aarch64_instrs_system_sysops : (bits(5), bits(3), bits(4), bits(4), bits(3), bits(1)) -> unit + +function decode_sys_aarch64_instrs_system_sysops (Rt, op2, CRm, CRn, op1, L) = { + AArch64_CheckSystemAccess(0b01, op1, CRn, CRm, op2, Rt, L); + let 't = UInt(Rt); + let 'sys_op0 = 1; + let 'sys_op1 = UInt(op1); + let 'sys_op2 = UInt(op2); + let 'sys_crn = UInt(CRn); + let 'sys_crm = UInt(CRm); + let has_result : bool = L == 0b1; + execute_aarch64_instrs_system_sysops(has_result, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1004) = { + SEE = 1004; + let Rt = Slice(__opcode, 0, 5); + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let CRn = Slice(__opcode, 12, 4); + let op1 = Slice(__opcode, 16, 3); + let L = Slice(__opcode, 21, 1); + decode_sys_aarch64_instrs_system_sysops(Rt, op2, CRm, CRn, op1, L) +} + +val decode_sysl_aarch64_instrs_system_sysops : (bits(5), bits(3), bits(4), bits(4), bits(3), bits(1)) -> unit + +function decode_sysl_aarch64_instrs_system_sysops (Rt, op2, CRm, CRn, op1, L) = { + AArch64_CheckSystemAccess(0b01, op1, CRn, CRm, op2, Rt, L); + let 't = UInt(Rt); + let 'sys_op0 = 1; + let 'sys_op1 = UInt(op1); + let 'sys_op2 = UInt(op2); + let 'sys_crn = UInt(CRn); + let 'sys_crm = UInt(CRm); + let has_result : bool = L == 0b1; + execute_aarch64_instrs_system_sysops(has_result, sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1005) = { + SEE = 1005; + let Rt = Slice(__opcode, 0, 5); + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let CRn = Slice(__opcode, 12, 4); + let op1 = Slice(__opcode, 16, 3); + let L = Slice(__opcode, 21, 1); + decode_sysl_aarch64_instrs_system_sysops(Rt, op2, CRm, CRn, op1, L) +} + +val execute_aarch64_instrs_system_sysops_128 : forall 'sys_crm 'sys_crn 'sys_op0 'sys_op1 'sys_op2 't 't2, + (1 <= 't2 & 't2 <= 32 & 0 <= 't & 't <= 31 & 'sys_op2 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op1 in {0, 1, 2, 3, 4, 5, 6, 7} & 'sys_op0 == 1 & 0 <= 'sys_crn & 'sys_crn <= 15 & 0 <= 'sys_crm & 'sys_crm <= 15). + (int('sys_crm), int('sys_crn), int('sys_op0), int('sys_op1), int('sys_op2), int('t), int('t2)) -> unit + +function execute_aarch64_instrs_system_sysops_128 (sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t, t2) = { + AArch64_SysInstr128(sys_op0, sys_op1, sys_crn, sys_crm, sys_op2, t, t2) +} + +val decode_sysp_aarch64_instrs_system_sysops_128 : (bits(5), bits(3), bits(4), bits(4), bits(3), bits(1)) -> unit + +function decode_sysp_aarch64_instrs_system_sysops_128 (Rt, op2, CRm, CRn, op1, L) = { + if not_bool(HaveSysInstr128()) then { + throw(Error_Undefined()) + }; + if [Rt[0]] == 0b1 & Rt != 0b11111 then { + throw(Error_Undefined()) + }; + AArch64_CheckSystemAccess(0b01, op1, CRn, CRm, op2, Rt, L); + let 't = UInt(Rt); + let 't2 = if t == 31 then 31 else 't + 1; + let 'sys_op0 = 1; + let 'sys_op1 = UInt(op1); + let 'sys_op2 = UInt(op2); + let 'sys_crn = UInt(CRn); + let 'sys_crm = UInt(CRm); + execute_aarch64_instrs_system_sysops_128(sys_crm, sys_crn, sys_op0, sys_op1, sys_op2, t, t2) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1006) = { + SEE = 1006; + let Rt = Slice(__opcode, 0, 5); + let op2 = Slice(__opcode, 5, 3); + let CRm = Slice(__opcode, 8, 4); + let CRn = Slice(__opcode, 12, 4); + let op1 = Slice(__opcode, 16, 3); + let L = Slice(__opcode, 21, 1); + decode_sysp_aarch64_instrs_system_sysops_128(Rt, op2, CRm, CRn, op1, L) +} + +val execute_aarch64_instrs_vector_transfer_vector_table : forall 'd 'datasize 'elements ('is_tbl : Bool) 'm 'n 'regs, + ('regs in {1, 2, 3, 4} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'elements in {8, 16} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), bool('is_tbl), int('m), int('n), int('regs)) -> unit + +function execute_aarch64_instrs_vector_transfer_vector_table (d, datasize, elements, is_tbl, m, n__arg, regs) = { + n : int = n__arg; + CheckFPAdvSIMDEnabled64(); + let indices : bits('datasize) = V_read(m, datasize); + table : bits(128 * 'regs) = Zeros(128 * regs); + index : int = undefined; + foreach (i from 0 to (regs - 1) by 1 in inc) { + table[128 * i + 127 .. 128 * i] = V_read(n, 128); + n = MOD(n + 1, 32) + }; + result : bits('datasize) = if is_tbl then Zeros(datasize) else + V_read(d, datasize); + foreach (i from 0 to (elements - 1) by 1 in inc) { + index = UInt(Elem_read(indices, i, 8)); + let 'index = index; + if index < 16 * regs then { + result = Elem_set(result, i, 8, Elem_read(table, index, 8)) + }; + () + }; + V_set(d, datasize) = result +} + +val decode_tbl_advsimd_aarch64_instrs_vector_transfer_vector_table : (bits(5), bits(5), bits(1), bits(2), bits(5), bits(1)) -> unit + +function decode_tbl_advsimd_aarch64_instrs_vector_transfer_vector_table (Rd, Rn, op, len, Rm, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 8); + let 'regs = UInt(len) + 1; + let is_tbl : bool = op == 0b0; + execute_aarch64_instrs_vector_transfer_vector_table(d, datasize, elements, is_tbl, m, n, regs) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1007) = { + SEE = 1007; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let len = Slice(__opcode, 13, 2); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_tbl_advsimd_aarch64_instrs_vector_transfer_vector_table(Rd, Rn, op, len, Rm, Q) +} + +val decode_tbx_advsimd_aarch64_instrs_vector_transfer_vector_table : (bits(5), bits(5), bits(1), bits(2), bits(5), bits(1)) -> unit + +function decode_tbx_advsimd_aarch64_instrs_vector_transfer_vector_table (Rd, Rn, op, len, Rm, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 8); + let 'regs = UInt(len) + 1; + let is_tbl : bool = op == 0b0; + execute_aarch64_instrs_vector_transfer_vector_table(d, datasize, elements, is_tbl, m, n, regs) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, _, _, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1008) = { + SEE = 1008; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 12, 1); + let len = Slice(__opcode, 13, 2); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_tbx_advsimd_aarch64_instrs_vector_transfer_vector_table(Rd, Rn, op, len, Rm, Q) +} + +val execute_aarch64_instrs_branch_conditional_test : forall 'bit_pos 'datasize 't, + (0 <= 't & 't <= 31 & 'datasize in {32, 64} & 0 <= 'bit_pos & 'bit_pos <= 63). + (int('bit_pos), bits(1), int('datasize), bits(64), int('t)) -> unit + +function execute_aarch64_instrs_branch_conditional_test (bit_pos, bit_val, datasize, offset, t) = { + let operand : bits('datasize) = X_read(t, datasize); + let branch_conditional : bool = true; + assert(constraint('bit_pos < 'datasize)); + if [operand[bit_pos]] == bit_val then { + BranchTo(PC_read() + offset, BranchType_DIR, branch_conditional) + } else { + BranchNotTaken(BranchType_DIR, branch_conditional) + } +} + +val decode_tbnz_aarch64_instrs_branch_conditional_test : (bits(5), bits(14), bits(5), bits(1), bits(1)) -> unit + +function decode_tbnz_aarch64_instrs_branch_conditional_test (Rt, imm14, b40, op, b5) = { + let 't = UInt(Rt); + let 'datasize = if b5 == 0b1 then 64 else 32; + let 'bit_pos = UInt(b5 @ b40); + let bit_val : bits(1) = op; + let offset : bits(64) = SignExtend(imm14 @ 0b00, 64); + execute_aarch64_instrs_branch_conditional_test(bit_pos, bit_val, datasize, offset, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([_, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1009) = { + SEE = 1009; + let Rt = Slice(__opcode, 0, 5); + let imm14 = Slice(__opcode, 5, 14); + let b40 = Slice(__opcode, 19, 5); + let op = Slice(__opcode, 24, 1); + let b5 = Slice(__opcode, 31, 1); + decode_tbnz_aarch64_instrs_branch_conditional_test(Rt, imm14, b40, op, b5) +} + +val decode_tbz_aarch64_instrs_branch_conditional_test : (bits(5), bits(14), bits(5), bits(1), bits(1)) -> unit + +function decode_tbz_aarch64_instrs_branch_conditional_test (Rt, imm14, b40, op, b5) = { + let 't = UInt(Rt); + let 'datasize = if b5 == 0b1 then 64 else 32; + let 'bit_pos = UInt(b5 @ b40); + let bit_val : bits(1) = op; + let offset : bits(64) = SignExtend(imm14 @ 0b00, 64); + execute_aarch64_instrs_branch_conditional_test(bit_pos, bit_val, datasize, offset, t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([_, bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1010) = { + SEE = 1010; + let Rt = Slice(__opcode, 0, 5); + let imm14 = Slice(__opcode, 5, 14); + let b40 = Slice(__opcode, 19, 5); + let op = Slice(__opcode, 24, 1); + let b5 = Slice(__opcode, 31, 1); + decode_tbz_aarch64_instrs_branch_conditional_test(Rt, imm14, b40, op, b5) +} + +val execute_aarch64_instrs_system_tme_tcancel : forall ('retry : Bool). + (bits(15), bool('retry)) -> unit + +function execute_aarch64_instrs_system_tme_tcancel (reason, retry) = { + if not_bool(IsTMEEnabled()) then { + throw(Error_Undefined()) + }; + if TSTATE.depth > 0 then { + FailTransaction__1(TMFailure_CNCL, retry, false, reason) + }; + () +} + +val decode_tcancel_aarch64_instrs_system_tme_tcancel : bits(16) -> unit + +function decode_tcancel_aarch64_instrs_system_tme_tcancel imm16 = { + if not_bool(HaveTME()) then { + throw(Error_Undefined()) + }; + let retry : bool = [imm16[15]] == 0b1; + let reason : bits(15) = imm16[14 .. 0]; + execute_aarch64_instrs_system_tme_tcancel(reason, retry) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, bitzero, bitzero, bitzero, bitzero, bitzero] as __opcode)) if SEE < 1011) = { + SEE = 1011; + let imm16 = Slice(__opcode, 5, 16); + decode_tcancel_aarch64_instrs_system_tme_tcancel(imm16) +} + +val execute_aarch64_instrs_system_tme_tcommit : unit -> unit + +function execute_aarch64_instrs_system_tme_tcommit () = { + if not_bool(IsTMEEnabled()) then { + throw(Error_Undefined()) + }; + if TSTATE.depth == 0 then { + throw(Error_Undefined()) + }; + if TSTATE.depth == 1 then { + CommitTransactionalWrites(); + ClearExclusiveLocal(ProcessorID()) + }; + TSTATE.depth = TSTATE.depth - 1 +} + +val decode_tcommit_aarch64_instrs_system_tme_tcommit : unit -> unit + +function decode_tcommit_aarch64_instrs_system_tme_tcommit () = { + if not_bool(HaveTME()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_system_tme_tcommit() +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110011000001111111 as __opcode)) if SEE < 1012) = { + SEE = 1012; + decode_tcommit_aarch64_instrs_system_tme_tcommit() +} + +val execute_aarch64_instrs_vector_transfer_vector_permute_transpose : forall 'd 'datasize 'esize 'm 'n 'pairs 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('m), int('n), int('pairs), int('part)) -> unit + +function execute_aarch64_instrs_vector_transfer_vector_permute_transpose (d, datasize, esize, m, n, pairs, part) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + foreach (p from 0 to (pairs - 1) by 1 in inc) { + result = Elem_set(result, 2 * p + 0, esize, Elem_read(operand1, 2 * p + part, esize)); + result = Elem_set(result, 2 * p + 1, esize, Elem_read(operand2, 2 * p + part, esize)) + }; + V_set(d, datasize) = result +} + +val decode_trn1_advsimd_aarch64_instrs_vector_transfer_vector_permute_transpose : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_trn1_advsimd_aarch64_instrs_vector_transfer_vector_permute_transpose (Rd, Rn, op, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'part = UInt(op); + let 'pairs = DIV(elements, 2); + execute_aarch64_instrs_vector_transfer_vector_permute_transpose(d, datasize, esize, m, n, pairs, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1013) = { + SEE = 1013; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_trn1_advsimd_aarch64_instrs_vector_transfer_vector_permute_transpose(Rd, Rn, op, Rm, size, Q) +} + +val decode_trn2_advsimd_aarch64_instrs_vector_transfer_vector_permute_transpose : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_trn2_advsimd_aarch64_instrs_vector_transfer_vector_permute_transpose (Rd, Rn, op, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'part = UInt(op); + let 'pairs = DIV(elements, 2); + execute_aarch64_instrs_vector_transfer_vector_permute_transpose(d, datasize, esize, m, n, pairs, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1014) = { + SEE = 1014; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_trn2_advsimd_aarch64_instrs_vector_transfer_vector_permute_transpose(Rd, Rn, op, Rm, size, Q) +} + +val execute_aarch64_instrs_system_tme_tstart : forall 'VL 't, + (0 <= 't & 't <= 31 & is_VL('VL)). + (int('VL), int('t)) -> unit + +function execute_aarch64_instrs_system_tme_tstart (VL, t) = { + if not_bool(IsTMEEnabled()) then { + throw(Error_Undefined()) + }; + IsEL1Regime : bool = undefined; + tme : bits(1) = undefined; + tmt : bits(1) = undefined; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + if IsEL1Regime then { + tme = SCTLR_EL1[TME0]; + tmt = SCTLR_EL1[TMT0] + } else { + tme = SCTLR_EL2[TME0]; + tmt = SCTLR_EL2[TMT0] + } + }, + ? if ? == EL1 => { + tme = SCTLR_EL1[TME]; + tmt = SCTLR_EL1[TMT] + }, + ? if ? == EL2 => { + tme = SCTLR_EL2[TME]; + tmt = SCTLR_EL2[TMT] + }, + ? if ? == EL3 => { + tme = SCTLR_EL3[TME]; + tmt = SCTLR_EL3[TMT] + }, + _ => { + Unreachable() + } + }; + let enable : bool = tme == 0b1; + let trivial : bool = tmt == 0b1; + if not_bool(enable) then { + TransactionStartTrap(t) + } else if trivial then { + TSTATE.nPC = NextInstrAddr(64); + TSTATE.Rt = t; + FailTransaction(TMFailure_TRIVIAL, false) + } else if HaveSME() & PSTATE.SM == 0b1 then { + FailTransaction(TMFailure_ERR, false) + } else if TSTATE.depth == 255 then { + FailTransaction(TMFailure_NEST, false) + } else if TSTATE.depth == 0 then { + TSTATE.nPC = NextInstrAddr(64); + TSTATE.Rt = t; + ClearExclusiveLocal(ProcessorID()); + TakeTransactionCheckpoint(VL, DIV(VL, 8)); + StartTrackingTransactionalReadsWrites() + } else (); + TSTATE.depth = TSTATE.depth + 1; + X_set(t, 64) = Zeros(64) +} + +val decode_tstart_aarch64_instrs_system_tme_tstart : bits(5) -> unit + +function decode_tstart_aarch64_instrs_system_tme_tstart Rt = { + let 'VL = CurrentVL_read(); + if not_bool(HaveTME()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + match VL { + 128 => { + execute_aarch64_instrs_system_tme_tstart(128, t) + }, + 256 => { + execute_aarch64_instrs_system_tme_tstart(256, t) + }, + 512 => { + execute_aarch64_instrs_system_tme_tstart(512, t) + }, + 1024 => { + execute_aarch64_instrs_system_tme_tstart(1024, t) + }, + 2048 => { + execute_aarch64_instrs_system_tme_tstart(2048, t) + }, + _ => () + } +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, _, _, _, _, _] as __opcode)) if SEE < 1015) = { + SEE = 1015; + let Rt = Slice(__opcode, 0, 5); + decode_tstart_aarch64_instrs_system_tme_tstart(Rt) +} + +val execute_aarch64_instrs_system_tme_ttest : forall 't, (0 <= 't & 't <= 31). + int('t) -> unit + +function execute_aarch64_instrs_system_tme_ttest t = { + if not_bool(IsTMEEnabled()) then { + throw(Error_Undefined()) + }; + X_set(t, 64) = TSTATE.depth[63 .. 0] +} + +val decode_ttest_aarch64_instrs_system_tme_ttest : bits(5) -> unit + +function decode_ttest_aarch64_instrs_system_tme_ttest Rt = { + if not_bool(HaveTME()) then { + throw(Error_Undefined()) + }; + let 't = UInt(Rt); + execute_aarch64_instrs_system_tme_ttest(t) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitone, _, _, _, _, _] as __opcode)) if SEE < 1016) = { + SEE = 1016; + let Rt = Slice(__opcode, 0, 5); + decode_ttest_aarch64_instrs_system_tme_ttest(Rt) +} + +val execute_aarch64_instrs_udf : unit -> unit + +function execute_aarch64_instrs_udf () = { + () +} + +val decode_udf_perm_undef_aarch64_instrs_udf : bits(16) -> unit + +function decode_udf_perm_undef_aarch64_instrs_udf imm16 = { + throw(Error_Undefined()); + execute_aarch64_instrs_udf() +} + +function clause __DecodeA64_Reserved ((pc, ([bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1017) = { + SEE = 1017; + let imm16 = Slice(__opcode, 0, 16); + decode_udf_perm_undef_aarch64_instrs_udf(imm16) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_umax_imm : forall 'd 'datasize 'imm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'imm & 'imm <= 255 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('imm), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_umax_imm (d, datasize, imm, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let 'result = Max(UInt(operand1), imm); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_umax_imm_aarch64_instrs_integer_arithmetic_max_min_umax_imm : (bits(5), bits(5), bits(8), bits(1)) -> unit + +function decode_umax_imm_aarch64_instrs_integer_arithmetic_max_min_umax_imm (Rd, Rn, imm8, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'd = UInt(Rd); + let 'imm = UInt(imm8); + execute_aarch64_instrs_integer_arithmetic_max_min_umax_imm(d, datasize, imm, n) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1018) = { + SEE = 1018; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm8 = Slice(__opcode, 10, 8); + let sf = Slice(__opcode, 31, 1); + decode_umax_imm_aarch64_instrs_integer_arithmetic_max_min_umax_imm(Rd, Rn, imm8, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_umax_reg : forall 'd 'datasize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_umax_reg (d, datasize, m, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let 'result = Max(UInt(operand1), UInt(operand2)); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_umax_reg_aarch64_instrs_integer_arithmetic_max_min_umax_reg : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_umax_reg_aarch64_instrs_integer_arithmetic_max_min_umax_reg (Rd, Rn, Rm, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_integer_arithmetic_max_min_umax_reg(d, datasize, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1019) = { + SEE = 1019; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_umax_reg_aarch64_instrs_integer_arithmetic_max_min_umax_reg(Rd, Rn, Rm, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_umin_reg : forall 'd 'datasize 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('m), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_umin_reg (d, datasize, m, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let operand2 : bits('datasize) = X_read(m, datasize); + let 'result = Min(UInt(operand1), UInt(operand2)); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_umin_reg_aarch64_instrs_integer_arithmetic_max_min_umin_reg : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_umin_reg_aarch64_instrs_integer_arithmetic_max_min_umin_reg (Rd, Rn, Rm, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + execute_aarch64_instrs_integer_arithmetic_max_min_umin_reg(d, datasize, m, n) +} + +function clause __DecodeA64_DataProcReg ((pc, ([_, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1020) = { + SEE = 1020; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let sf = Slice(__opcode, 31, 1); + decode_umin_reg_aarch64_instrs_integer_arithmetic_max_min_umin_reg(Rd, Rn, Rm, sf) +} + +val execute_aarch64_instrs_integer_arithmetic_max_min_umin_imm : forall 'd 'datasize 'imm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'imm & 'imm <= 255 & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('imm), int('n)) -> unit + +function execute_aarch64_instrs_integer_arithmetic_max_min_umin_imm (d, datasize, imm, n) = { + let operand1 : bits('datasize) = X_read(n, datasize); + let 'result = Min(UInt(operand1), imm); + X_set(d, datasize) = result[datasize - 1 .. 0] +} + +val decode_umin_imm_aarch64_instrs_integer_arithmetic_max_min_umin_imm : (bits(5), bits(5), bits(8), bits(1)) -> unit + +function decode_umin_imm_aarch64_instrs_integer_arithmetic_max_min_umin_imm (Rd, Rn, imm8, sf) = { + if not_bool(HaveCSSC()) then { + throw(Error_Undefined()) + }; + let 'datasize = (32 << UInt(sf)); + let 'n = UInt(Rn); + let 'd = UInt(Rd); + let 'imm = UInt(imm8); + execute_aarch64_instrs_integer_arithmetic_max_min_umin_imm(d, datasize, imm, n) +} + +function clause __DecodeA64_DataProcImm ((pc, ([_, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1021) = { + SEE = 1021; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm8 = Slice(__opcode, 10, 8); + let sf = Slice(__opcode, 31, 1); + decode_umin_imm_aarch64_instrs_integer_arithmetic_max_min_umin_imm(Rd, Rn, imm8, sf) +} + +val execute_aarch64_instrs_vector_transfer_integer_move_unsigned : forall 'd 'datasize 'esize 'idxdsize 'index 'n, + (0 <= 'n & 'n <= 31 & 'idxdsize in {64, 128} & 'esize in {8, 16, 32, 64} & 'datasize in {32, 64} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('idxdsize), int('index), int('n)) -> unit + +function execute_aarch64_instrs_vector_transfer_integer_move_unsigned (d, datasize, esize, idxdsize, index, n) = { + if index == 0 then { + CheckFPEnabled64() + } else { + CheckFPAdvSIMDEnabled64() + }; + let operand : bits('idxdsize) = V_read(n, idxdsize); + assert(constraint('datasize >= 'esize)); + X_set(d, datasize) = ZeroExtend(Elem_read(operand, index, esize), datasize) +} + +val decode_umov_advsimd_aarch64_instrs_vector_transfer_integer_move_unsigned : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_umov_advsimd_aarch64_instrs_vector_transfer_integer_move_unsigned (Rd, Rn, imm5, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + size : {0, 1, 2, 3} = 0; + match Q @ imm5 { + [bitzero, _, _, _, _, bitone] => { + size = 0 + }, + [bitzero, _, _, _, bitone, bitzero] => { + size = 1 + }, + [bitzero, _, _, bitone, bitzero, bitzero] => { + size = 2 + }, + [bitone, _, bitone, bitzero, bitzero, bitzero] => { + size = 3 + }, + _ => { + throw(Error_Undefined()) + } + }; + let 'size = size; + let 'idxdsize = if [imm5[4]] == 0b1 then 128 else 64; + let 'index = UInt(imm5[4 .. size + 1]); + let 'esize = (8 << size); + let 'datasize = if Q == 0b1 then 64 else 32; + execute_aarch64_instrs_vector_transfer_integer_move_unsigned(d, datasize, esize, idxdsize, index, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1022) = { + SEE = 1022; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm5 = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_umov_advsimd_aarch64_instrs_vector_transfer_integer_move_unsigned(Rd, Rn, imm5, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_special_recip_int : forall 'd 'datasize 'elements 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_special_recip_int (d, datasize, elements, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits(32) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, 32); + result = Elem_set(result, e, 32, UnsignedRecipEstimate(element)) + }; + V_set(d, datasize) = result +} + +val decode_urecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_int : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_urecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_int (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_recip_int(d, datasize, elements, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1023) = { + SEE = 1023; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_urecpe_advsimd_aarch64_instrs_vector_arithmetic_unary_special_recip_int(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_int : forall 'd 'datasize 'elements 'n, + (0 <= 'n & 'n <= 31 & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_int (d, datasize, elements, n) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits('datasize) = V_read(n, datasize); + result : bits('datasize) = undefined; + element : bits(32) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, 32); + result = Elem_set(result, e, 32, UnsignedRSqrtEstimate(element)) + }; + V_set(d, datasize) = result +} + +val decode_ursqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_int : (bits(5), bits(5), bits(1), bits(1)) -> unit + +function decode_ursqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_int (Rd, Rn, sz, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if sz == 0b1 then { + throw(Error_Undefined()) + }; + let 'esize = 32; + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_int(d, datasize, elements, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitone, bitzero, bitone, bitone, bitone, bitzero, bitone, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1024) = { + SEE = 1024; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let sz = Slice(__opcode, 22, 1); + let Q = Slice(__opcode, 30, 1); + decode_ursqrte_advsimd_aarch64_instrs_vector_arithmetic_unary_special_sqrt_est_int(Rd, Rn, sz, Q) +} + +val execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_usdot : forall 'd 'datasize 'elements 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'elements in {2, 4} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_usdot (d, datasize, elements, m, n) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + let operand3 : bits('datasize) = V_read(d, datasize); + result : bits('datasize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + res : bits(32) = Elem_read(operand3, e, 32); + foreach (b from 0 to 3 by 1 in inc) { + let 'element1 = UInt(Elem_read(operand1, 4 * e + b, 8)); + let 'element2 = SInt(Elem_read(operand2, 4 * e + b, 8)); + res = res + element1 * element2 + }; + result = Elem_set(result, e, 32, res) + }; + V_set(d, datasize) = result +} + +val decode_usdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_usdot : (bits(5), bits(5), bits(5), bits(1)) -> unit + +function decode_usdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_usdot (Rd, Rn, Rm, Q) = { + if not_bool(HaveInt8MatMulExt()) then { + throw(Error_Undefined()) + }; + let 'n = UInt(Rn); + let 'm = UInt(Rm); + let 'd = UInt(Rd); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, 32); + execute_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_usdot(d, datasize, elements, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, bitone, bitzero, bitzero, bitone, bitone, bitone, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1025) = { + SEE = 1025; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let Rm = Slice(__opcode, 16, 5); + let Q = Slice(__opcode, 30, 1); + decode_usdot_advsimd_vec_aarch64_instrs_vector_arithmetic_binary_uniform_mat_mul_int_usdot(Rd, Rn, Rm, Q) +} + +val execute_aarch64_instrs_vector_transfer_vector_permute_unzip : forall 'd 'datasize 'elements 'esize 'm 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('m), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_transfer_vector_permute_unzip (d, datasize, elements, esize, m, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operandl : bits('datasize) = V_read(n, datasize); + let operandh : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + let zipped : bits('datasize * 2) = operandh @ operandl; + foreach (e from 0 to (elements - 1) by 1 in inc) { + result = Elem_set(result, e, esize, Elem_read(zipped, 2 * e + part, esize)) + }; + V_set(d, datasize) = result +} + +val decode_uzp1_advsimd_aarch64_instrs_vector_transfer_vector_permute_unzip : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_uzp1_advsimd_aarch64_instrs_vector_transfer_vector_permute_unzip (Rd, Rn, op, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'part = UInt(op); + execute_aarch64_instrs_vector_transfer_vector_permute_unzip(d, datasize, elements, esize, m, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1026) = { + SEE = 1026; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_uzp1_advsimd_aarch64_instrs_vector_transfer_vector_permute_unzip(Rd, Rn, op, Rm, size, Q) +} + +val decode_uzp2_advsimd_aarch64_instrs_vector_transfer_vector_permute_unzip : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_uzp2_advsimd_aarch64_instrs_vector_transfer_vector_permute_unzip (Rd, Rn, op, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'part = UInt(op); + execute_aarch64_instrs_vector_transfer_vector_permute_unzip(d, datasize, elements, esize, m, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitzero, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1027) = { + SEE = 1027; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_uzp2_advsimd_aarch64_instrs_vector_transfer_vector_permute_unzip(Rd, Rn, op, Rm, size, Q) +} + +val execute_aarch64_instrs_system_sysinstwithreg_wfet : forall 'd, (0 <= 'd & 'd <= 31). + int('d) -> unit + +function execute_aarch64_instrs_system_sysinstwithreg_wfet d = { + let 'localtimeout = UInt(X_read(d, 64)); + if Halted() & ConstrainUnpredictableBool(Unpredictable_WFxTDEBUG) then { + EndOfInstruction() + }; + Hint_WFE(localtimeout, WFxType_WFET) +} + +val decode_wfet_aarch64_instrs_system_sysinstwithreg_wfet : bits(5) -> unit + +function decode_wfet_aarch64_instrs_system_sysinstwithreg_wfet Rd = { + if not_bool(HaveFeatWFxT()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + execute_aarch64_instrs_system_sysinstwithreg_wfet(d) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, _, _, _, _, _] as __opcode)) if SEE < 1028) = { + SEE = 1028; + let Rd = Slice(__opcode, 0, 5); + decode_wfet_aarch64_instrs_system_sysinstwithreg_wfet(Rd) +} + +val execute_aarch64_instrs_system_sysinstwithreg_wfit : forall 'd, (0 <= 'd & 'd <= 31). + int('d) -> unit + +function execute_aarch64_instrs_system_sysinstwithreg_wfit d = { + let 'localtimeout = UInt(X_read(d, 64)); + if Halted() & ConstrainUnpredictableBool(Unpredictable_WFxTDEBUG) then { + EndOfInstruction() + }; + Hint_WFI(localtimeout, WFxType_WFIT) +} + +val decode_wfit_aarch64_instrs_system_sysinstwithreg_wfit : bits(5) -> unit + +function decode_wfit_aarch64_instrs_system_sysinstwithreg_wfit Rd = { + if not_bool(HaveFeatWFxT()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + execute_aarch64_instrs_system_sysinstwithreg_wfit(d) +} + +function clause __DecodeA64_BranchExcSys ((pc, ([bitone, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, _, _, _, _, _] as __opcode)) if SEE < 1029) = { + SEE = 1029; + let Rd = Slice(__opcode, 0, 5); + decode_wfit_aarch64_instrs_system_sysinstwithreg_wfit(Rd) +} + +val execute_aarch64_instrs_integer_flags_xaflag : unit -> unit + +function execute_aarch64_instrs_integer_flags_xaflag () = { + let n : bits(1) = not_vec(PSTATE.C) & not_vec(PSTATE.Z); + let z : bits(1) = PSTATE.Z & PSTATE.C; + let c : bits(1) = PSTATE.C | PSTATE.Z; + let v : bits(1) = not_vec(PSTATE.C) & PSTATE.Z; + PSTATE.N = n; + PSTATE.Z = z; + PSTATE.C = c; + PSTATE.V = v +} + +val decode_xaflag_aarch64_instrs_integer_flags_xaflag : bits(4) -> unit + +function decode_xaflag_aarch64_instrs_integer_flags_xaflag CRm = { + if not_bool(HaveFlagFormatExt()) then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_flags_xaflag() +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000000100000000111111 as __opcode)) if SEE < 1030) = { + SEE = 1030; + let CRm = Slice(__opcode, 8, 4); + if (([__opcode[8]] != 0b0 | [__opcode[9]] != 0b0) | [__opcode[10]] != 0b0) | [__opcode[11]] != 0b0 then { + throw(Error_ConstrainedUnpredictable()) + } else { + decode_xaflag_aarch64_instrs_integer_flags_xaflag(CRm) + } +} + +val execute_aarch64_instrs_vector_crypto_sha3_xar : forall 'd 'm 'n, + (0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 0 <= 'd & 'd <= 31). + (int('d), bits(6), int('m), int('n)) -> unit + +function execute_aarch64_instrs_vector_crypto_sha3_xar (d, imm6, m, n) = { + AArch64_CheckFPAdvSIMDEnabled(); + let Vm : bits(128) = V_read(m, 128); + let Vn : bits(128) = V_read(n, 128); + let tmp : bits(128) = EOR(Vn, Vm); + V_set(d, 128) = ROR(tmp[127 .. 64], UInt(imm6)) @ ROR(tmp[63 .. 0], UInt(imm6)) +} + +val decode_xar_advsimd_aarch64_instrs_vector_crypto_sha3_xar : (bits(5), bits(5), bits(6), bits(5)) -> unit + +function decode_xar_advsimd_aarch64_instrs_vector_crypto_sha3_xar (Rd, Rn, imm6, Rm) = { + if not_bool(HaveSHA3Ext()) then { + throw(Error_Undefined()) + }; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + execute_aarch64_instrs_vector_crypto_sha3_xar(d, imm6, m, n) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1031) = { + SEE = 1031; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let imm6 = Slice(__opcode, 10, 6); + let Rm = Slice(__opcode, 16, 5); + decode_xar_advsimd_aarch64_instrs_vector_crypto_sha3_xar(Rd, Rn, imm6, Rm) +} + +val execute_aarch64_instrs_integer_pac_strip_dp_1src : forall 'd ('data : Bool), (0 <= 'd & 'd <= 31). + (int('d), bool('data)) -> unit + +function execute_aarch64_instrs_integer_pac_strip_dp_1src (d, data) = { + if HavePACExt() then { + X_set(d, 64) = Strip(X_read(d, 64), data) + }; + () +} + +val decode_xpac_aarch64_instrs_integer_pac_strip_dp_1src : (bits(5), bits(5), bits(1)) -> unit + +function decode_xpac_aarch64_instrs_integer_pac_strip_dp_1src (Rd, Rn, D) = { + let data : bool = D == 0b1; + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if not_bool(HavePACExt()) then { + throw(Error_Undefined()) + }; + if n != 31 then { + throw(Error_Undefined()) + }; + execute_aarch64_instrs_integer_pac_strip_dp_1src(d, data) +} + +function clause __DecodeA64_DataProcReg ((pc, ([bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitone, bitzero, bitzero, bitzero, _, bitone, bitone, bitone, bitone, bitone, _, _, _, _, _] as __opcode)) if SEE < 1032) = { + SEE = 1032; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let D = Slice(__opcode, 10, 1); + decode_xpac_aarch64_instrs_integer_pac_strip_dp_1src(Rd, Rn, D) +} + +val decode_xpac_aarch64_instrs_integer_pac_strip_hint : unit -> unit + +function decode_xpac_aarch64_instrs_integer_pac_strip_hint () = { + let 'd = 30; + let data : bool = false; + execute_aarch64_instrs_integer_pac_strip_dp_1src(d, data) +} + +function clause __DecodeA64_BranchExcSys ((pc, (0b11010101000000110010000011111111 as __opcode)) if SEE < 1033) = { + SEE = 1033; + decode_xpac_aarch64_instrs_integer_pac_strip_hint() +} + +val execute_aarch64_instrs_vector_arithmetic_unary_extract_nosat : forall 'd 'datasize 'elements 'esize 'n 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 'esize in {8, 16, 32, 64} & 'datasize == 64 & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('elements), int('esize), int('n), int('part)) -> unit + +function execute_aarch64_instrs_vector_arithmetic_unary_extract_nosat (d, datasize, elements, esize, n, part) = { + CheckFPAdvSIMDEnabled64(); + let operand : bits(2 * 'datasize) = V_read(n, 2 * datasize); + result : bits('datasize) = undefined; + element : bits(2 * 'esize) = undefined; + foreach (e from 0 to (elements - 1) by 1 in inc) { + element = Elem_read(operand, e, 2 * esize); + result = Elem_set(result, e, esize, element[esize - 1 .. 0]) + }; + Vpart_set(d, part, datasize) = result +} + +val decode_xtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_nosat : (bits(5), bits(5), bits(2), bits(1)) -> unit + +function decode_xtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_nosat (Rd, Rn, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + if size == 0b11 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = 64; + let 'part = UInt(Q); + let 'elements = DIV(datasize, esize); + execute_aarch64_instrs_vector_arithmetic_unary_extract_nosat(d, datasize, elements, esize, n, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1034) = { + SEE = 1034; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_xtn_advsimd_aarch64_instrs_vector_arithmetic_unary_extract_nosat(Rd, Rn, size, Q) +} + +val execute_aarch64_instrs_vector_transfer_vector_permute_zip : forall 'd 'datasize 'esize 'm 'n 'pairs 'part, + ('part in {0, 1} & 0 <= 'n & 'n <= 31 & 0 <= 'm & 'm <= 31 & 'esize in {8, 16, 32, 64} & 'datasize in {64, 128} & 0 <= 'd & 'd <= 31). + (int('d), int('datasize), int('esize), int('m), int('n), int('pairs), int('part)) -> unit + +function execute_aarch64_instrs_vector_transfer_vector_permute_zip (d, datasize, esize, m, n, pairs, part) = { + CheckFPAdvSIMDEnabled64(); + let operand1 : bits('datasize) = V_read(n, datasize); + let operand2 : bits('datasize) = V_read(m, datasize); + result : bits('datasize) = undefined; + let 'base = part * pairs; + foreach (p from 0 to (pairs - 1) by 1 in inc) { + result = Elem_set(result, 2 * p + 0, esize, Elem_read(operand1, base + p, esize)); + result = Elem_set(result, 2 * p + 1, esize, Elem_read(operand2, base + p, esize)) + }; + V_set(d, datasize) = result +} + +val decode_zip1_advsimd_aarch64_instrs_vector_transfer_vector_permute_zip : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_zip1_advsimd_aarch64_instrs_vector_transfer_vector_permute_zip (Rd, Rn, op, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'part = UInt(op); + let 'pairs = DIV(elements, 2); + execute_aarch64_instrs_vector_transfer_vector_permute_zip(d, datasize, esize, m, n, pairs, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1035) = { + SEE = 1035; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_zip1_advsimd_aarch64_instrs_vector_transfer_vector_permute_zip(Rd, Rn, op, Rm, size, Q) +} + +val decode_zip2_advsimd_aarch64_instrs_vector_transfer_vector_permute_zip : (bits(5), bits(5), bits(1), bits(5), bits(2), bits(1)) -> unit + +function decode_zip2_advsimd_aarch64_instrs_vector_transfer_vector_permute_zip (Rd, Rn, op, Rm, size, Q) = { + let 'd = UInt(Rd); + let 'n = UInt(Rn); + let 'm = UInt(Rm); + if (size @ Q) == 0b110 then { + throw(Error_Undefined()) + }; + let 'esize = (8 << UInt(size)); + let 'datasize = if Q == 0b1 then 128 else 64; + let 'elements = DIV(datasize, esize); + let 'part = UInt(op); + let 'pairs = DIV(elements, 2); + execute_aarch64_instrs_vector_transfer_vector_permute_zip(d, datasize, esize, m, n, pairs, part) +} + +function clause __DecodeA64_DataProcFPSIMD ((pc, ([bitzero, _, bitzero, bitzero, bitone, bitone, bitone, bitzero, _, _, bitzero, _, _, _, _, _, bitzero, bitone, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _, _, _, _] as __opcode)) if SEE < 1036) = { + SEE = 1036; + let Rd = Slice(__opcode, 0, 5); + let Rn = Slice(__opcode, 5, 5); + let op = Slice(__opcode, 14, 1); + let Rm = Slice(__opcode, 16, 5); + let size = Slice(__opcode, 22, 2); + let Q = Slice(__opcode, 30, 1); + decode_zip2_advsimd_aarch64_instrs_vector_transfer_vector_permute_zip(Rd, Rn, op, Rm, size, Q) +} diff --git a/crates/clazel-a64/tests/data/sail-arm/src/interface.sail b/crates/clazel-a64/tests/data/sail-arm/src/interface.sail new file mode 100644 index 000000000..c3fb6440c --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/interface.sail @@ -0,0 +1,199 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +$include +$include +$include +$include +$include + +// This the set of all Arm access types that are not covered by the generic +// interface access type. +union arm_acc_type = { + // Software ASIMD extension load/store instructions + SAcc_ASIMD : /* streaming access :*/ bool, + // Software SVE load/store instructions + SAcc_SVE : /* streaming access :*/ bool, + // Software SME load/store instructions + SAcc_SME : /* streaming access :*/ bool, + // Sysop IC + SAcc_IC : unit, + // Sysop DC (not DC {Z,G,GZ}VA) + SAcc_DC : unit, + // Sysop DC {Z,G,GZ}VA + SAcc_DCZero : unit, + // Sysop AT + SAcc_AT : unit, + // NV2 memory redirected access + SAcc_NV2 : unit, + // Statistical Profiling buffer access + SAcc_SPE : unit, + // Guarded Control Stack access + SAcc_GCS : unit, + // Granule Protection Table Walk + SAcc_GPTW : unit +} + +function AccessDescriptor_to_Access_kind(accdesc : AccessDescriptor) -> Access_kind(arm_acc_type) = { + // TODO + match accdesc.acctype { + AccessType_IFETCH => AK_ifetch(), + AccessType_GPR => + let variety = + if accdesc.exclusive then AV_exclusive + else if accdesc.atomicop then AV_atomic_rmw + else AV_plain + in + let strength = + if accdesc.acqpc then AS_acq_rcpc + else if accdesc.acqsc | accdesc.relsc then AS_rel_or_acq + else AS_normal + in + AK_explicit(struct { variety, strength }), + AccessType_TTW => AK_ttw(), + AccessType_ASIMD => AK_arch(SAcc_ASIMD(accdesc.streamingsve)), + AccessType_SVE => AK_arch(SAcc_SVE(accdesc.streamingsve)), + AccessType_SME => AK_arch(SAcc_SME(accdesc.streamingsve)), + AccessType_IC => AK_arch(SAcc_IC()), + AccessType_DC => AK_arch(SAcc_DC()), + AccessType_DCZero => AK_arch(SAcc_DCZero()), + AccessType_AT => AK_arch(SAcc_AT()), + AccessType_NV2 => AK_arch(SAcc_NV2()), + AccessType_SPE => AK_arch(SAcc_SPE()), + AccessType_GCS => AK_arch(SAcc_GCS()), + AccessType_GPTW => AK_arch(SAcc_GPTW()) + } +} + +val pa_bits : bits(56) -> bits(64) + +function pa_bits(bv) = sail_zero_extend(bv, 64) + +instantiation sail_mem_read with + 'pa = bits(56), + 'translation_summary = option(TranslationInfo), + 'arch_ak = arm_acc_type, + 'abort = Fault, + pa_bits = pa_bits + +val read_request : forall 'n, 'n > 0. (AccessDescriptor, option(TranslationInfo), int('n), bits(64), bits(56)) -> Mem_read_request('n, 64, bits(56), option(TranslationInfo), arm_acc_type) + +function read_request(accdesc, ti, size, va, pa) = struct { + access_kind = AccessDescriptor_to_Access_kind(accdesc), + va = Some(va), + pa = pa, + translation = ti, + size = size, + tag = false +} + +instantiation sail_mem_write with + 'pa = bits(56), + 'translation_summary = option(TranslationInfo), + 'arch_ak = arm_acc_type, + 'abort = Fault, + pa_bits = pa_bits + +val write_request : forall 'n, 'n > 0. (AccessDescriptor, option(TranslationInfo), int('n), bits(64), bits(56), bits(8 * 'n)) -> Mem_write_request('n, 64, bits(56), option(TranslationInfo), arm_acc_type) + +function write_request(accdesc, ti, size, va, pa, value) = struct { + access_kind = AccessDescriptor_to_Access_kind(accdesc), + va = Some(va), + pa = pa, + translation = ti, + size = size, + value = Some(value), + tag = None(), +} + +instantiation sail_translation_start with + 'trans_start = TranslationStartInfo + +function start_translation(tsi) = sail_translation_start(tsi) + +instantiation sail_translation_end with + 'trans_end = AddressDescriptor + +function end_translation(desc) = sail_translation_end(desc) + +struct TLBIInfo = { + rec: TLBIRecord, + shareability : Shareability, +} + +instantiation sail_tlbi with + 'tlbi = TLBIInfo + +function report_tlbi(r, s) = sail_tlbi(struct { rec = r, shareability = s }) + +// The details of a data memory/synchonisation barrier +struct DxB = { + domain : MBReqDomain, + types : MBReqTypes, + nXS : bool +} + +// An Arm barrier +union Barrier = { + Barrier_DSB : DxB, + Barrier_DMB : DxB, // The nXS field is ignored from DMBs + Barrier_ISB : unit, + Barrier_SSBB : unit, + Barrier_PSSBB : unit, + Barrier_SB : unit, +} + +instantiation sail_cache_op with + 'cache_op = CacheRecord + +function CACHE_OP(r) = sail_cache_op(r) + +instantiation sail_barrier with + 'barrier = Barrier + +instantiation sail_return_exception + +instantiation sail_take_exception with + 'fault = option(FaultRecord) + +val return_exception : bits(56) -> unit + +function return_exception(x) = sail_return_exception(x) +function take_exception(fault) = sail_take_exception(fault) diff --git a/crates/clazel-a64/tests/data/sail-arm/src/map_clauses.sail b/crates/clazel-a64/tests/data/sail-arm/src/map_clauses.sail new file mode 100644 index 000000000..b8a5a4f20 --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/map_clauses.sail @@ -0,0 +1,465 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +function __SetConfig ((arg, value_name) if arg == "ZCR_EL3.LEN") = { + if value_name >= 0 & value_name <= UInt(0xF) then { + ZCR_EL3_LEN_VALUE = value_name + } else { + let msg : string = (" can accept a value between 0 and 15. Value provided is " ++ DecStr(value_name)); + println((arg ++ msg)); + assert(false) + } +} +and __SetConfig ((arg, value_name) if arg == "CPTR_EL3.EZ") = { + if value_name >= 0 & value_name <= UInt(0x1) then { + CPTR_EL3_EZ_VALUE = value_name + } else { + let msg : string = (" can accept a value between 0 and 1. Value provided is " ++ DecStr(value_name)); + println((arg ++ msg)); + assert(false) + } +} +and __SetConfig ((arg, value_name) if arg == "CPTR_EL3.ESM") = { + if value_name >= 0 & value_name <= UInt(0x1) then { + CPTR_EL3_ESM_VALUE = value_name + } else { + let msg : string = (" can accept a value between 0 and 1. Value provided is " ++ DecStr(value_name)); + println((arg ++ msg)); + assert(false) + } +} +and __SetConfig ((arg, value_name) if arg == "SMCR_EL3.LEN") = { + if value_name >= 0 & value_name <= UInt(0xF) then { + SMCR_EL3_LEN_VALUE = value_name + } else { + let msg : string = (" can accept a value between 0 and 1. Value provided is " ++ DecStr(value_name)); + println((arg ++ msg)); + assert(false) + } +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-1") = { + __ConfigureV81(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-2") = { + __ConfigureV82(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-3") = { + __ConfigureV83(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-4") = { + __ConfigureV84(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-5") = { + __ConfigureV85(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-6") = { + __ConfigureV86(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-7") = { + __ConfigureV87(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-8") = { + __ConfigureV88(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v8-9") = { + __ConfigureV89(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v9-0") = { + __ConfigureV90(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v9-1") = { + __ConfigureV91(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v9-2") = { + __ConfigureV92(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v9-3") = { + __ConfigureV93(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_arm_v9-4") = { + __ConfigureV94(value_name == 1) +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.CONFIG64") = { + CFG_RMR_AA64 = [value_name[0]] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.RVBAR") = { + CFG_RVBAR = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.num_loregions") = { + LORID_EL1[LR] = value_name[7 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.num_loregion_descriptors") = { + LORID_EL1[LD] = value_name[7 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpy_mops_option") = { + __cpy_mops_option_a_supported = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpyf_mops_option") = { + __cpyf_mops_option_a_supported = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.set_mops_option") = { + __set_mops_option_a_supported = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.setg_mops_option") = { + __setg_mops_option_a_supported = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mops_cpy_default_dir") = { + __mops_forward_copy = value_name == 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_pstate_pan") = { + FEAT_PAN_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_16bit_vmids") = { + FEAT_VMID16_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.enable_crc32") = { + FEAT_CRC32_IMPLEMENTED = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_dot_product") = { + FEAT_DotProd_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_fp16") = { + FEAT_FP16_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_aarch32_hpd") = { + FEAT_AA32HPD_IMPLEMENTED = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.crypto_aes") = { + FEAT_AES_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.crypto_sha1") = { + FEAT_SHA1_IMPLEMENTED = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.crypto_sha256") = { + FEAT_SHA256_IMPLEMENTED = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.crypto_sha512") = { + FEAT_SHA512_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.crypto_sha3") = { + FEAT_SHA3_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.crypto_sm3") = { + FEAT_SM3_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.crypto_sm4") = { + FEAT_SM4_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.BBM") = { + __block_bbm_implemented = value_name +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.number-of-breakpoints") = { + NUM_BREAKPOINTS = value_name +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.number-of-watchpoints") = { + NUM_WATCHPOINTS = value_name +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.number-of-context-breakpoints") = { + __num_ctx_breakpoints = value_name +} +and __SetConfig ((arg, value_name) if arg == "cpu.pmu-num_counters") = { + NUM_PMU_COUNTERS = value_name +} +and __SetConfig ((arg, value_name) if arg == "cpu.PA_SIZE") = { + __supported_pa_size = value_name +} +and __SetConfig ((arg, value_name) if arg == "cpu.VA_SIZE") = { + __supported_va_size = value_name +} +and __SetConfig ((arg, value_name) if arg == "ctiBase") = { + __CTIBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "counter_addr") = { + __CNTControlBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cntReadBase") = { + __CNTReadBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cntBaseN") = { + __CNTBaseN = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cntEL0BaseN") = { + __CNTEL0BaseN = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cntCTLBase") = { + __CNTCTLBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "ExtDebugBase") = { + __ExtDebugBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.PERIPHBASE") = { + __GICCPUInterfaceBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "gic_distributor.reg-base") = { + __GICDistBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "rdBase") = { + __RD_base = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "sgiBase") = { + __SGI_base = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "vlpiBase") = { + __VLPI_base = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "gic_distributor.ITS0-base") = { + __GICITSControlBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "pmuBase") = { + __PMUBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "dbg_rom_addr") = { + __DBG_ROM_ADDR = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "etmBase") = { + __ETEBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "trbeBase") = { + __TRBEBase = value_name[56 - 1 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "globalcounter.base_frequency") = { + __CNTbase_frequency = value_name[31 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_normal_cacheable_read_is_sync") = { + __syncAbortOnReadNormCache = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_normal_noncacheable_read_is_sync") = { + __syncAbortOnReadNormNonCache = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_device_read_is_sync") = { + __syncAbortOnDeviceRead = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_so_read_is_sync") = { + __syncAbortOnSoRead = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_so_write_is_sync") = { + __syncAbortOnSoWrite = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_prefetch_is_sync") = { + __syncAbortOnPrefetch = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_ttw_cacheable_read_is_sync") = { + __syncAbortOnTTWCache = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_ttw_noncacheable_read_is_sync") = { + __syncAbortOnTTWNonCache = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_normal_cacheable_write_is_sync") = { + __syncAbortOnWriteNormCache = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_normal_noncacheable_write_is_sync") = { + __syncAbortOnWriteNormNonCache = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.ext_abort_device_write_is_sync") = { + __syncAbortOnDeviceWrite = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_mpam") = { + FEAT_MPAM_IMPLEMENTED = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpam_has_hcr") = { + __mpam_has_hcr = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpam_max_partid") = { + __mpam_partid_max = value_name[15 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpam_max_pmg") = { + __mpam_pmg_max = value_name[7 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpam_max_vpmr") = { + __mpam_vpmr_max = value_name[2 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpam_has_altsp") = { + __mpam_has_altsp = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpamidr_has_tidr") = { + __empam_tidr_implemented = value_name > 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpamidr_has_sdeflt") = { + __empam_sdeflt_implemented = value_name > 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpamidr_has_force_ns") = { + __empam_force_ns_implemented = value_name > 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpam_force_ns_rao") = { + __empam_force_ns_RAO = value_name > 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.mpam_frac") = { + __mpam_frac = value_name[3 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L1I_override") = { + __ICACHE_CCSIDR_RESET[0] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L1D_override") = { + __DCACHE_CCSIDR_RESET[0] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L2_override") = { + __DCACHE_CCSIDR_RESET[1] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L3_override") = { + __DCACHE_CCSIDR_RESET[2] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L4_override") = { + __DCACHE_CCSIDR_RESET[3] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L5_override") = { + __DCACHE_CCSIDR_RESET[4] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L6_override") = { + __DCACHE_CCSIDR_RESET[5] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.CCSIDR-L7_override") = { + __DCACHE_CCSIDR_RESET[6] = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.DCZID-log2-block-size") = { + __dczid_log2_block_size = value_name +} +and __SetConfig ((arg, value_name) if arg == "cpu.GMID-log2-block-size") = { + __gmid_log2_block_size = value_name +} +and __SetConfig ((arg, value_name) if arg == "exclusive_monitor.log2_granule_size") = { + __exclusive_granule_size = value_name[3 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.unpred_tsize_aborts") = { + __unpred_tsize_aborts = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.CONFIG64") = { + CFG_RMR_AA64 = [value_name[0]] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.RVBAR") = { + CFG_RVBAR = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.VAL_ignore_rvbar_in_aarch32") = { + __ignore_rvbar_in_aarch32 = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_tlb") = { + __tlb_enabled = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_trickbox") = { + __trickbox_enabled = value_name == 1 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.MPIDR-override") = { + CFG_MPIDR = value_name[31 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.semihosting-heap_base") = { + HEAP_BASE = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.semihosting-heap_limit") = { + HEAP_LIMIT = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.semihosting-stack_base") = { + STACK_BASE = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.semihosting-stack_limit") = { + STACK_LIMIT = value_name[63 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_qarma3_pac") = { + if value_name != 0 then { + FEAT_PACQARMA3_IMPLEMENTED = true; + FEAT_PACQARMA5_IMPLEMENTED = false + }; + () +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_const_pac") = { + FEAT_CONSTPACFIELD_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_rme") = { + FEAT_RME_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.rme_l0pgtsz") = { + __rme_l0gptsz = value_name[3 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_brbe") = { + FEAT_BRBE_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.cpu0.number-of-branch-records") = { + NUM_BRBE_RECORDS = 16 * DIV(value_name, 16) +} +and __SetConfig ((arg, value_name) if arg == "cpu.isb_is_branch") = { + __isb_is_branch = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_brbe_v9_3") = { + FEAT_BRBEv1p1_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.has_sme_f64f64") = { + FEAT_SME_F64F64_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.has_sme_priority_control") = { + __has_sme_priority_control = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.has_sme_i16i64") = { + FEAT_SME_I16I64_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.sme_veclens_implemented") = { + __max_implemented_smeveclen = decode_max_smeveclen(value_name) +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.has_sve_extended_bf16") = { + __has_sve_extended_bf16 = UInt(value_name[1 .. 0]) +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.has_sme") = { + FEAT_SME_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.sme_only") = { + __sme_only = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "SVE.ScalableVectorExtension.veclen") = { + __max_implemented_sveveclen = decode_max_sveveclen(value_name) +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_extended_recp_estimate") = { + __feat_rpres = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "spe.pseudo_cycles") = { + __has_spe_pseudo_cycles = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_nested_virtualization") = { + FEAT_NV_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_rndr") = { + FEAT_RNG_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.has_enhanced_pan") = { + FEAT_PAN3_IMPLEMENTED = value_name != 0 +} +and __SetConfig ((arg, value_name) if arg == "cpu.rme_mecid_width") = { + __mecid_width = (value_name - 1)[3 .. 0] +} +and __SetConfig ((arg, value_name) if arg == "emulator.termination_opcode") = { + __emulator_termination_opcode = Some(value_name[31 .. 0]) +} +and __SetConfig (arg, value_name) = () diff --git a/crates/clazel-a64/tests/data/sail-arm/src/mem.sail b/crates/clazel-a64/tests/data/sail-arm/src/mem.sail new file mode 100644 index 000000000..e25de6cb5 --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/mem.sail @@ -0,0 +1,232 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +// Redirect memory primitives to Sail builtins + +$ifndef _CONCURRENCY_INTERFACE_READ_WRITE +val __ReadMem + = { ocaml: "Platform.read_mem", c: "platform_read_mem", _: "read_mem" } + : forall 'n (constant 'addrsize : Int), 'n > 0 & 'addrsize in {32, 64}. + (read_kind, int('addrsize), bits('addrsize), int('n)) -> bits(8 * 'n) effect {rmem} + +val __ReadTaggedMem + = { lem: "read_memt", coq: "read_memt" } + : forall 'n (constant 'addrsize : Int), 'n > 0 & 'addrsize in {32, 64}. + (read_kind, bits('addrsize), int('n)) -> (bits(8 * 'n), bit) effect {rmemt} + +val __WriteMem + = { lem: "write_mem", coq: "write_mem" } + : forall 'n (constant 'addrsize : Int), 'n > 0 & 'addrsize in {32, 64}. + (write_kind, int('addrsize), bits('addrsize), int('n), bits(8 * 'n)) -> bool effect {wmv} + +function __WriteMem(wk, addrsize, addr, size, data) = { + match('addrsize) { + 32 => __write_mem(wk, 32, addr, size, data), + 64 => __write_mem(wk, 64, addr, size, data) + } +} + +val acctype_to_read_kind : AccessType -> read_kind + +function acctype_to_read_kind(acctype) = { + match acctype { + AccessType_IFETCH => Read_ifetch, + // TODO + // AccessType_NORMAL => Read_plain, + // AccessType_ORDERED => Read_acquire, + // AccessType_ATOMIC => Read_exclusive, + // AccessType_ATOMICRW => Read_exclusive, + // AccessType_ORDEREDATOMIC => Read_exclusive_acquire, + // AccessType_ORDEREDATOMICRW => Read_exclusive_acquire, + _ => Read_plain + } +} + +val _Mem_read : forall 'size, 'size > 0. (AddressDescriptor, int('size), AccessDescriptor) -> bits(8 * 'size) + +$ifdef HAVE_DEVICES +function _Mem_read (desc, size, accdesc) = { + let paddress = desc.paddress.address; + if (size >= 4 & paddress[(length(paddress) - 1) .. 16] == ZeroExtend(GIC_BASE)) then { + // TODO: Pass read kind? + ZeroExtend(__ReadGIC(paddress[15 .. 0]), 8 * size); + } else if (paddress[(length(paddress) - 1) .. 16] == ZeroExtend(UART_BASE)) then { + __ReadUART(paddress[15 .. 0], size); + } else { + __ReadMem(acctype_to_read_kind(accdesc.acctype), 64, ZeroExtend(paddress, 64), size) + } +} +$else +function _Mem_read (desc, size, accdesc) = { + __ReadMem(acctype_to_read_kind(accdesc.acctype), 64, ZeroExtend(desc.paddress.address, 64), size) +} +$endif + +val acctype_to_write_kind : AccessType -> write_kind + +function acctype_to_write_kind(acctype) = { + match acctype { + // TODO + // AccType_ORDERED => Write_release, + // AccType_ATOMIC => Write_exclusive, + // AccType_ATOMICRW => Write_exclusive, + // AccType_ORDEREDATOMIC => Write_exclusive_release, + // AccType_ORDEREDATOMICRW => Write_exclusive_release, + _ => Write_plain + } +} + +val _Mem_set : forall 'size, 'size > 0. (AddressDescriptor, int('size), AccessDescriptor, bits(8 * 'size)) -> unit + +$ifdef HAVE_DEVICES +function _Mem_set (desc, size, accdesc, data) = { + let paddress = desc.paddress.address; + if (size == 4 & paddress[(length(paddress) - 1) .. 16] == ZeroExtend(GIC_BASE)) then { + __WriteGIC(paddress[15 .. 0], data) + } else if (paddress[(length(paddress) - 1) .. 16] == ZeroExtend(UART_BASE)) then { + __WriteUART(paddress[15 .. 0], size, data) + } else { + let _ = __WriteMem(acctype_to_write_kind(accdesc.acctype), 64, ZeroExtend(paddress, 64), size, data); + () + } +} +$else +function _Mem_set (desc, size, accdesc, data) = { + let _ = __WriteMem(acctype_to_write_kind(accdesc.acctype), 64, ZeroExtend(desc.paddress.address, 64), size, data); + () +} +$endif + +function PhysMemTagWrite (desc, accdesc, data) = { + // TODO + return undefined; +} + +function PhysMemTagRead (desc, accdesc) = { + // TODO + return (undefined, undefined); +} + +val CreatePhysMemRetStatus : Fault -> PhysMemRetStatus + +function CreatePhysMemRetStatus (fault) = struct { statuscode = fault, extflag = 0b0, merrorstate = ErrorState_Uncategorized, store64bstatus = Zeros() } + +function PhysMemRead (desc, size, accdesc) = { + return (CreatePhysMemRetStatus(Fault_None), _Mem_read(desc, size, accdesc)); +} + +function PhysMemWrite (desc, size, accdesc, data) = { + _Mem_set(desc, size, accdesc, data); + return CreatePhysMemRetStatus(Fault_None); +} +$else + + +function PhysMemTagWrite (desc, accdesc, data) = { + // TODO + return undefined; +} + +function PhysMemTagRead (desc, accdesc) = { + // TODO + return (undefined, undefined); +} + +val CreatePhysMemRetStatus : Fault -> PhysMemRetStatus + +function CreatePhysMemRetStatus (fault) = struct { statuscode = fault, extflag = 0b0, merrorstate = ErrorState_Uncategorized, store64bstatus = Zeros() } + +$ifdef HAVE_DEVICES +function PhysMemRead (desc, size, accdesc, translation_info) = { + let paddress = desc.paddress.address; + if (size >= 4 & paddress[(length(paddress) - 1) .. 16] == ZeroExtend(GIC_BASE)) then { + // TODO: Pass read kind? + (CreatePhysMemRetStatus(Fault_None), ZeroExtend(__ReadGIC(paddress[15 .. 0]), 8 * size)) + } else if (paddress[(length(paddress) - 1) .. 16] == ZeroExtend(UART_BASE)) then { + (CreatePhysMemRetStatus(Fault_None), __ReadUART(paddress[15 .. 0], size)) + } else { + match sail_mem_read(read_request(accdesc, translation_info, size, desc.vaddress, desc.paddress.address)) { + Ok((value, _)) => (CreatePhysMemRetStatus(Fault_None), value), + Err(statuscode) => (CreatePhysMemRetStatus(statuscode), sail_zeros(8 * size)) + } + } +} +$else +function PhysMemRead (desc, size, accdesc, translation_info) = { + match sail_mem_read(read_request(accdesc, translation_info, size, desc.vaddress, desc.paddress.address)) { + Ok((value, _)) => (CreatePhysMemRetStatus(Fault_None), value), + Err(statuscode) => (CreatePhysMemRetStatus(statuscode), sail_zeros(8 * size)) + } +} +$endif + +$ifdef HAVE_DEVICES +function PhysMemWrite (desc, size, accdesc, translation_info, data) = { + let paddress = desc.paddress.address; + if (size == 4 & paddress[(length(paddress) - 1) .. 16] == ZeroExtend(GIC_BASE)) then { + __WriteGIC(paddress[15 .. 0], data); + CreatePhysMemRetStatus(Fault_None) + } else if (paddress[(length(paddress) - 1) .. 16] == ZeroExtend(UART_BASE)) then { + __WriteUART(paddress[15 .. 0], size, data); + CreatePhysMemRetStatus(Fault_None) + } else { + if size > 0 then { + match sail_mem_write(write_request(accdesc, translation_info, size, desc.vaddress, desc.paddress.address, data)) { + Ok(_) => CreatePhysMemRetStatus(Fault_None), + Err(statuscode) => CreatePhysMemRetStatus(statuscode) + } + } else { + CreatePhysMemRetStatus(Fault_None) + } + } +} +$else +function PhysMemWrite (desc, size, accdesc, translation_info, data) = { + if size > 0 then { + match sail_mem_write(write_request(accdesc, translation_info, size, desc.vaddress, desc.paddress.address, data)) { + Ok(_) => CreatePhysMemRetStatus(Fault_None), + Err(statuscode) => CreatePhysMemRetStatus(statuscode) + } + } else { + CreatePhysMemRetStatus(Fault_None) + } +} +$endif +$endif diff --git a/crates/clazel-a64/tests/data/sail-arm/src/prelude.sail b/crates/clazel-a64/tests/data/sail-arm/src/prelude.sail new file mode 100644 index 000000000..76dc94a72 --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/prelude.sail @@ -0,0 +1,374 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +default Order dec + +$include +$include +$include +$include +$include +$include +$include +$include +$include +$include + +/* These could be given refined types, if necessary */ +val implies : (bool, bool) -> bool +function implies(p,q) = not_bool(p) | q +infixr 1 --> +overload operator --> = {implies} + +val iff : (bool, bool) -> bool +function iff(p,q) = implies(p,q) & implies(q,p) +infix 1 <--> +overload operator <--> = {iff} + +val eq_any = pure {ocaml: "(fun (x, y) -> x = y)", interpreter: "eq_anything", lem: "eq", coq: "generic_eq", lean: "BEq.beq", c: "eq_anything"} : forall ('a : Type). ('a, 'a) -> bool + +val eq_bits_int : forall 'n 'm, 'n >= 0 & 'm >= 0. (bits('n), int('m)) -> bool +function eq_bits_int (x, y) = (unsigned(x) == y) + +overload operator == = {eq_any, eq_bits_int} + +val neq_any = pure {lem: "neq", coq: "generic_neq", lean: "bne"} : forall ('a : Type). ('a, 'a) -> bool +function neq_any(x, y) = not_bool(x == y) + +overload operator != = {neq_any} + +val in_range : forall 'n 'i 'j. (int('n), int('i), int('j)) -> bool(('i < 'j & 'i <= 'n <= 'j) | ('i >= 'j & 'j <= 'n <= 'i)) +function in_range(n, i, j) = if i < j then (i <= n & n <= j) else (j <= n & n <= i) + +val min_real : (real, real) -> real +function min_real(n, m) = (if n <= m then n else m) + +overload Min = {min_int, min_real} + +val max_int : forall 'n 'm. (int('n), int('m)) -> {'o, ('n <= 'm & 'o == 'm) | ('n > 'm & 'o == 'n). int('o)} +function max_int(n, m) = (if n <= m then m else n) + +val max_real : (real, real) -> real +function max_real(n, m) = (if n <= m then m else n) + +overload Max = {max_int, max_real} + +overload Abs = {abs_int_atom, abs_int_plain, abs_real} + +val ediv_nat = pure { + ocaml: "quotient", + interpreter: "quotient", + lem: "integerDiv", + c: "ediv_int", + coq: "ZEuclid.div", + lean: "Int.ediv" +} : forall 'n 'm, 'n >= 0 & 'm > 0. (int('n), int('m)) -> int(div('n, 'm)) + +val emod_nat = pure { + ocaml: "modulus", + interpreter: "modulus", + lem: "integerMod", + c: "emod_int", + coq: "ZEuclid.modulo", + lean: "Nat.mod" +} : forall 'n 'm, 'n >= 0 & 'm > 0. (int('n), int('m)) -> int(mod('n, 'm)) + +overload DIV = {ediv_nat, fdiv_int} +overload MOD = {emod_nat, fmod_int} +overload QUOT = {tdiv_int} +overload REM = {tmod_int} + +val pow2 = pure "pow2" : forall 'n, 'n >= 0. int('n) -> int(2 ^ 'n) + +overload operator ^ = {pow_real} + +overload Real = {to_real} + +val UInt0 = pure { + ocaml: "uint", + lem: "uint", + interpreter: "uint", + c: "sail_unsigned", + coq: "uint", + lean: "BitVec.toNat", +} : forall 'n. bits('n) -> {'m, 0 <= 'm < 2 ^ 'n. int('m)} + +val UInt1 = pure { coq: "uint" } : forall 'n. (int('n), bits('n)) -> {'m, 0 <= 'm < 2 ^ 'n. int('m)} +function UInt1(n, x) = unsigned(x) + +overload UInt = {UInt0, UInt1} + +val SInt0 = pure { + c: "sail_signed", + lean: "BitVec.toInt", + _: "sint" +} : forall 'n, 'n > 0. bits('n) -> {'m, - (2 ^ ('n - 1)) <= 'm < 2 ^ ('n - 1). int('m)} + +val SInt1 : forall 'n, 'n > 0. (int('n), bits('n)) -> {'m, - (2 ^ ('n - 1)) <= 'm < 2 ^ ('n - 1). int('m)} +function SInt1(n, x) = signed(x) + +overload SInt = {SInt0, SInt1} + +val Replicate__1 : forall 'n 'm, 'n >= 0 & 'm > 0 & mod('n, 'm) == 0. (implicit('n), bits('m)) -> bits('n) +function Replicate__1(n, x) = replicate_bits(x, ediv_int(n, 'm)) + +overload Replicate = {replicate_bits, Replicate__1} + +val Ones : forall 'n, 'n >= 0. implicit('n) -> bits('n) +function Ones(n) = sail_ones(n) + +val Zeros : forall 'n, 'n >= 0. implicit('n) -> bits('n) +function Zeros(n) = sail_zeros(n) + +val IsZero : forall 'n, 'n >= 0. bits('n) -> bool +function IsZero(x) = (x == sail_zeros('n)) + +val IsOnes : forall 'n, 'n >= 0. bits('n) -> bool +function IsOnes(x) = (x == sail_ones('n)) + +val Bit : bits(1) -> bit +function Bit(b) = b[0] + +val Bits : bit -> bits(1) +function Bits(b) = (if b == bitone then 0b1 else 0b0) + +val integer_subrange : forall 'hi 'lo, 'lo <= 'hi. (int, int('hi), int('lo)) -> bits('hi - 'lo + 1) +function integer_subrange(i, hi, lo) = get_slice_int(hi - lo + 1, i, lo) + +overload vector_subrange = {integer_subrange} + +val integer_access : forall 'n. (int, int('n)) -> bit +function integer_access(i, n) = (integer_subrange(i, n, n))[0] + +overload vector_access = {integer_access} + +val integer_update_subrange : forall 'm 'o, 0 <= 'o <= 'm. (int, int('m), int('o), bits('m - 'o + 1)) -> int +function integer_update_subrange(i, hi, lo, x) = set_slice_int(hi - lo + 1, i, lo, x) + +overload vector_update_subrange = {integer_update_subrange} + +val array_access = pure { + ocaml: "access", + interpreter: "access", + lem: "access_list_inc", + coq: "vec_access_inc", + lean: "GetElem?.getElem!", + c: "vector_access", +} : forall ('n : Int) ('m : Int) ('a : Type), 0 <= 'm < 'n. (vector('n, inc, 'a), int('m)) -> 'a + +overload vector_access = {array_access} + +val array_update = pure { + ocaml: "update", + interpreter: "update", + lem: "update_list_inc", + coq: "vec_update_inc", + lean: "BitVec.update", + c: "vector_update" +} : forall 'n 'm ('a : Type), 0 <= 'm < 'n. (vector('n, inc, 'a), int('m), 'a) -> vector('n, inc, 'a) + +overload vector_update = {array_update} + +val sub_bits_int = pure {c:"sub_bits_int", lean: "BitVec.subInt", _: "sub_vec_int"} : forall 'n, 'n > 0. (bits('n), int) -> bits('n) + +overload operator - = {sub_bits, sub_bits_int} + +overload AND = {and_vec} +overload OR = {or_vec} +overload EOR = {xor_vec} + +val SignExtend0 = pure "sign_extend" : forall 'n 'm, 'n > 0 & 'm >= 'n. + (bits('n), int('m)) -> bits('m) + +val SignExtend1 : forall 'n 'm, 'n > 0 & 'm >= 'n. + (implicit('m), bits('n)) -> bits('m) +function SignExtend1(m, x) = SignExtend0(x, m) + +overload SignExtend = {SignExtend0, SignExtend1} + +val ZeroExtend0 = pure { lean: "Sail.BitVec.zeroExtend", _: "zero_extend" } : forall 'n 'm, 'n >= 0 & 'm >= 'n. + (bits('n), int('m)) -> bits('m) + +val ZeroExtend1 : forall 'n 'm, 'n >= 0 & 'm >= 'n. + (implicit('m), bits('n)) -> bits('m) +function ZeroExtend1(m, x) = ZeroExtend0(x, m) + +overload ZeroExtend = {ZeroExtend0, ZeroExtend1} + +val Slice_int : forall 'w, 'w >= 0. (int, int, int('w)) -> bits('w) +function Slice_int(i, l, n) = get_slice_int(n, i, l) + +overload Slice = {slice, Slice_int} + +overload SetSlice = {set_slice_bits} + +overload RoundDown = {floor} + +overload RoundUp = {ceil} + +val Align_int = pure { lem: "align_int" } : (int, int) -> int +function Align_int(x, y) = (DIV(x, y) * y) + +val Align_bits = pure { lem: "align_bits" } : forall 'n, 'n >= 0. (bits('n), int) -> bits('n) +function Align_bits(x, y) = Slice(Align_int(unsigned(x), y), 0, sizeof('n)) + +overload Align = {Align_bits, Align_int} + +val RoundTowardsZero : real -> int +function RoundTowardsZero(r) = if r < to_real(0) then RoundUp(r) else RoundDown(r) + +enum signal = LOW | HIGH + +infix 7 >> +infix 7 << + +overload operator << = {sail_shiftleft, _shl1, _shl8, _shl32, _shl_int, _shl_int_general} +overload operator >> = {sail_shiftright, _shr32, _shr_int, _shr_int_general} + +union exception = { + Error_Undefined : unit, + Error_See : string, + Error_ImplementationDefined : string, + Error_ReservedEncoding : unit, + Error_ExceptionTaken : unit, + Error_Unpredictable : unit, + Error_ConstrainedUnpredictable : unit, + Error_SError : bool +} + +val IsUNDEFINED : exception -> bool +val IsUNPREDICTABLE : exception -> bool +val IsSEE : exception -> bool +val IsExceptionTaken : exception -> bool +val IsSError : exception -> bool + +function IsUNDEFINED ex = match ex { Error_Undefined() => true, _ => false } +function IsUNPREDICTABLE ex = match ex { Error_Unpredictable() => true, _ => false } +function IsSEE ex = match ex { Error_See(_) => true, _ => false } +function IsExceptionTaken ex = match ex { Error_ExceptionTaken() => true, _ => false } +function IsSError ex = match ex { Error_SError(_) => true, _ => false } + +val ThrowSError : bool -> unit +function ThrowSError(iesb_req) = throw(Error_SError(iesb_req)) + +val ReservedEncoding : unit -> unit +function ReservedEncoding() = throw(Error_ReservedEncoding()) + +val DecStr = pure "dec_str" : int -> string + +val HexStr = pure "hex_str" : int -> string + +val BoolStr : bool -> string +function BoolStr b = match b { true => "true", false => "false" } + +val append_str = pure {ocaml: "concat_str", interpreter: "concat_str", lem: "stringAppend", c: "concat_str", coq: "String.append", lean: "String.append" } : + (string, string) -> string + +function append_int(str: string, n: int) -> string = { + append_str(str, DecStr(n)) +} + +function append_bool(str: string, b: bool) -> string = { + append_str(str, if b then "true" else "false") +} + +infixl 4 ++ + +overload operator ++ = {append_int, append_bool, append_str} + +val print_integer : int -> unit +function print_integer(i) = print_int("", i) + +val print_newline : unit -> unit +function print_newline () = print_endline("") + +overload println = {print_endline, print_newline} + +val putchar = pure { + ocaml: "putchar", + lem: "putchar", + interpreter: "putchar", + c: "sail_putchar", + coq: "putchar", + lean: "putchar" +} : int -> unit + +val __IMPDEF_boolean : string -> bool +val __IMPDEF_integer : string -> int + +val __UNKNOWN_bits : forall 'n, 'n >= 0. int('n) -> bits('n) +function __UNKNOWN_bits(n) = undefined + +function __UNKNOWN_integer() : unit -> int = undefined +function __UNKNOWN_boolean() : unit -> bool = undefined +function __UNKNOWN_real() : unit -> real = undefined +function __UNKNOWN_string() : unit -> string = undefined +function __UNKNOWN_bit() : unit -> bits(1) = undefined +function __UNKNOWN_signal() : unit -> signal = undefined + +/* From A1.4 ("Supported data types") of ARM DDI 0487J.a: + "An SVE scalable vector register has an IMPLEMENTATION DEFINED width that + is a power of two, from a minimum of 128 bits up to a maximum of 2048 bits." */ +type is_VL('vl : Int) -> Bool = ('vl in {128, 256, 512, 1024, 2048}) +/* "An SVE predicate register has an IMPLEMENTATION DEFINED width that is a + power of two, from a minimum of 16 bits up to a maximum of 256 bits." */ +type is_PL('pl : Int) -> Bool = ('pl in {16, 32, 64, 128, 256}) + +type vector_length = {'vl, is_VL('vl). int('vl)} +type predicate_length = {'pl, is_PL('pl). int('pl)} + +val PL_of_VL : forall 'vl, 'vl >= 0. int('vl) -> int(div('vl, 8)) + +function PL_of_VL(vl) = DIV(vl, 8) + +val __SleepRequest = monadic {ocaml: "sleep_request", lem: "sleep_request", smt: "sleep_request", interpreter: "sleep_request", c: "sleep_request", lean: "sleep_request"}: unit -> unit + +val __WakeupRequest = monadic {ocaml: "wakeup_request", lem: "wakeup_request", smt: "wakeup_request", interpreter: "wakeup_request", c: "wakeup_request", lean: "wakeup_request"}: unit -> unit + +/* C emulator support functions */ + +val __GetVerbosity = monadic {c: "sail_get_verbosity"} : unit -> bits(64) +function __GetVerbosity() = 0x0000_0000_0000_0000 + +val check_cycle_count = monadic { c: "cycle_count", lean: "cycle_count" } : unit -> unit +function check_cycle_count() = () + +val get_cycle_count = monadic { c: "get_cycle_count", lean: "get_cycle_count" } : unit -> int +function get_cycle_count() = 0 diff --git a/crates/clazel-a64/tests/data/sail-arm/src/termination_measures.sail b/crates/clazel-a64/tests/data/sail-arm/src/termination_measures.sail new file mode 100644 index 000000000..be0b9537d --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/termination_measures.sail @@ -0,0 +1,116 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +termination_measure Reduce__1(op,input,esize,altfp) = 'N + +$iftarget coq + +termination_measure BranchEncCycleCount + while cc + +termination_measure DiscardTransactionalWrites + while __tm_wset_size +/* Actually + while __tm_wset_next +but we don't support a register read there. */ + +termination_measure FloorPow2 + while x - pow2(n) + +termination_measure ImplementedSVEVectorLength + while nbits + +termination_measure ImplementedSMEVectorLength + while nbits, while maxbits - nbits + +termination_measure RecipSqrtEstimate + while pow2(28) - b + +termination_measure FPRoundBase__1 + while RoundUp(Real(1) / mantissa), /* should be a base-2 log */ + while RoundUp(mantissa) + +termination_measure FPRSqrtEstimate + while 64 + exp + +termination_measure AArch64_ChooseNonExcludedTag + while 32 - UInt(tag), while UInt(offset), while 32 - UInt(tag) + +termination_measure ChooseRandomNonExcludedTag + while 32 - UInt(tag) + +termination_measure FPLogB + while RoundUp(Real(1) / value_name), + while RoundUp(value_name) + +termination_measure BFRound + while RoundUp(Real(1) / mantissa), /* should be a base-2 log */ + while RoundUp(mantissa) + +termination_measure execute_PNEXT_P_P_P__ + while elements - next + +termination_measure execute_aarch64_instrs_memory_mcpymset_cpy + while abs_int(SInt(stagecpysize)), + while UInt(stagecpysize) +termination_measure execute_aarch64_instrs_memory_mcpymset_cpyf + while abs_int(SInt(stagecpysize)), + while UInt(stagecpysize) +termination_measure execute_aarch64_instrs_memory_mcpymset_set + while abs_int(SInt(stagesetsize)), + while UInt(stagesetsize) +termination_measure execute_aarch64_instrs_memory_mcpymset_setg + while abs_int(SInt(stagesetsize)), while tagstep, + while UInt(stagesetsize), while tagstep + +/* Just put a limit in for now. Probably 4 is more likely... */ +termination_measure AArch64_S2Walk repeat 100, repeat 100 // TODO: Not clear the inner loop terminates +termination_measure AArch64_S2Translate repeat 100 +termination_measure AArch64_S1Walk repeat 100, repeat 100 // TODO: Not clear the inner loop terminates +termination_measure AArch64_S1Translate repeat 100 +termination_measure AArch32_S2Walk repeat 100 +termination_measure AArch32_S1WalkLD repeat 100 +termination_measure AArch32_S1WalkSD repeat 100 + +termination_measure decode_max_smeveclen while svl + +termination_measure SPEConstructRecord while 64 + +$endif diff --git a/crates/clazel-a64/tests/data/sail-arm/src/v8_base.sail b/crates/clazel-a64/tests/data/sail-arm/src/v8_base.sail new file mode 100644 index 000000000..6c65c139f --- /dev/null +++ b/crates/clazel-a64/tests/data/sail-arm/src/v8_base.sail @@ -0,0 +1,57139 @@ +/******************************************************************************/ +/* BSD 3-clause Clear License */ +/* */ +/* Copyright (c) 2023 */ +/* Arm Limited (or its affiliates), */ +/* Thomas Bauereiss, */ +/* Brian Campbell, */ +/* Alasdair Armstrong, */ +/* Alastair Reid, */ +/* Peter Sewell */ +/* */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted (subject to the limitations in the */ +/* disclaimer below) provided that the following conditions are met: */ +/* */ +/* * Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* * Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ +/* * Neither the name of ARM Limited nor the names of its contributors */ +/* may be used to endorse or promote products derived from this */ +/* software without specific prior written permission. */ +/* */ +/* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED */ +/* BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ +/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, */ +/* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND */ +/* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ +/* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */ +/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF */ +/* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ +/* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF */ +/* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/******************************************************************************/ + +bitfield Configuration_Type : bits(32) = + { + Cp15SDisable2 : 25, + disableNIDebug : 24, + CfgNMFI : 23, + ExceptInit : 22, + Cp15SDisable : 20, + disableSPNIDebug : 19, + disableSPIDebug : 18, + CONFIG64 : 14, + CFGEND : 2, + RW : 1, + HIVECS : 0 + } + +bitfield DormantCtl_Type : bits(32) = + { + dbgrstreq : 12, + dbgpwrupreq : 11, + standbywfe : 10, + etmpwrdwnreq : 8, + etmpwrupreq : 7, + ResetCatchStatus : 6, + TestResetCatch : 5, + PowerDownStatusSupport : 4, + nPU : 3, + nDbgpwrdwnreq : 2, + Dbgnopwrdwn : 1, + standbywfi : 0 + } + +enum Feature = { + FEAT_AA32EL0, + FEAT_AA32EL1, + FEAT_AA32EL2, + FEAT_AA32EL3, + FEAT_AA64EL0, + FEAT_AA64EL1, + FEAT_AA64EL2, + FEAT_AA64EL3, + FEAT_EL0, + FEAT_EL1, + FEAT_EL2, + FEAT_EL3, + FEAT_AES, + FEAT_AdvSIMD, + FEAT_CSV2_1p1, + FEAT_CSV2_1p2, + FEAT_CSV2_2, + FEAT_CSV2_3, + FEAT_DoubleLock, + FEAT_ETMv4, + FEAT_ETMv4p1, + FEAT_ETMv4p2, + FEAT_ETMv4p3, + FEAT_ETMv4p4, + FEAT_ETMv4p5, + FEAT_ETMv4p6, + FEAT_ETS2, + FEAT_FP, + FEAT_GICv3, + FEAT_GICv3_LEGACY, + FEAT_GICv3_TDIR, + FEAT_GICv3p1, + FEAT_GICv4, + FEAT_GICv4p1, + FEAT_IVIPT, + FEAT_PCSRv8, + FEAT_PMULL, + FEAT_PMUv3, + FEAT_PMUv3_EXT, + FEAT_PMUv3_EXT32, + FEAT_SHA1, + FEAT_SHA256, + FEAT_TRC_EXT, + FEAT_TRC_SR, + FEAT_nTLBPA, + FEAT_CRC32, + FEAT_Debugv8p1, + FEAT_HAFDBS, + FEAT_HPDS, + FEAT_LOR, + FEAT_LSE, + FEAT_PAN, + FEAT_PMUv3p1, + FEAT_RDM, + FEAT_VHE, + FEAT_VMID16, + FEAT_AA32BF16, + FEAT_AA32HPD, + FEAT_AA32I8MM, + FEAT_ASMv8p2, + FEAT_DPB, + FEAT_Debugv8p2, + FEAT_EDHSR, + FEAT_F32MM, + FEAT_F64MM, + FEAT_FP16, + FEAT_HPDS2, + FEAT_I8MM, + FEAT_IESB, + FEAT_LPA, + FEAT_LSMAOC, + FEAT_LVA, + FEAT_MPAM, + FEAT_PAN2, + FEAT_PCSRv8p2, + FEAT_RAS, + FEAT_SHA3, + FEAT_SHA512, + FEAT_SM3, + FEAT_SM4, + FEAT_SPE, + FEAT_SVE, + FEAT_TTCNP, + FEAT_UAO, + FEAT_VPIPT, + FEAT_XNX, + FEAT_CCIDX, + FEAT_CONSTPACFIELD, + FEAT_EPAC, + FEAT_FCMA, + FEAT_FPAC, + FEAT_FPACCOMBINE, + FEAT_JSCVT, + FEAT_LRCPC, + FEAT_NV, + FEAT_PACIMP, + FEAT_PACQARMA3, + FEAT_PACQARMA5, + FEAT_PAuth, + FEAT_SPEv1p1, + FEAT_AMUv1, + FEAT_BBM, + FEAT_CNTSC, + FEAT_DIT, + FEAT_Debugv8p4, + FEAT_DotProd, + FEAT_DoubleFault, + FEAT_FHM, + FEAT_FlagM, + FEAT_IDST, + FEAT_LRCPC2, + FEAT_LSE2, + FEAT_NV2, + FEAT_PMUv3p4, + FEAT_RASSAv1p1, + FEAT_RASv1p1, + FEAT_S2FWB, + FEAT_SEL2, + FEAT_TLBIOS, + FEAT_TLBIRANGE, + FEAT_TRF, + FEAT_TTL, + FEAT_TTST, + FEAT_BTI, + FEAT_CSV2, + FEAT_CSV3, + FEAT_DPB2, + FEAT_E0PD, + FEAT_EVT, + FEAT_ExS, + FEAT_FRINTTS, + FEAT_FlagM2, + FEAT_GTG, + FEAT_MTE, + FEAT_MTE2, + FEAT_PMUv3p5, + FEAT_RNG, + FEAT_RNG_TRAP, + FEAT_SB, + FEAT_SPECRES, + FEAT_SSBS, + FEAT_SSBS2, + FEAT_AMUv1p1, + FEAT_BF16, + FEAT_DGH, + FEAT_ECV, + FEAT_FGT, + FEAT_HPMN0, + FEAT_MPAMv0p1, + FEAT_MPAMv1p1, + FEAT_MTPMU, + FEAT_PAuth2, + FEAT_TWED, + FEAT_AFP, + FEAT_EBF16, + FEAT_HCX, + FEAT_LPA2, + FEAT_LS64, + FEAT_LS64_ACCDATA, + FEAT_LS64_V, + FEAT_MTE3, + FEAT_PAN3, + FEAT_PMUv3p7, + FEAT_RPRES, + FEAT_SPEv1p2, + FEAT_WFxT, + FEAT_XS, + FEAT_CMOW, + FEAT_Debugv8p8, + FEAT_GICv3_NMI, + FEAT_HBC, + FEAT_MOPS, + FEAT_NMI, + FEAT_PMUv3_EXT64, + FEAT_PMUv3_TH, + FEAT_PMUv3p8, + FEAT_SCTLR2, + FEAT_SPEv1p3, + FEAT_TCR2, + FEAT_TIDCP1, + FEAT_ADERR, + FEAT_AIE, + FEAT_ANERR, + FEAT_CLRBHB, + FEAT_CSSC, + FEAT_Debugv8p9, + FEAT_DoubleFault2, + FEAT_ECBHB, + FEAT_FGT2, + FEAT_HAFT, + FEAT_LRCPC3, + FEAT_MTE4, + FEAT_MTE_ASYM_FAULT, + FEAT_MTE_ASYNC, + FEAT_MTE_CANONICAL_TAGS, + FEAT_MTE_NO_ADDRESS_TAGS, + FEAT_MTE_PERM, + FEAT_MTE_STORE_ONLY, + FEAT_MTE_TAGGED_FAR, + FEAT_PCSRv8p9, + FEAT_PFAR, + FEAT_PMUv3_EDGE, + FEAT_PMUv3_ICNTR, + FEAT_PMUv3_SS, + FEAT_PMUv3p9, + FEAT_PRFMSLC, + FEAT_RASSAv2, + FEAT_RASv2, + FEAT_RPRFM, + FEAT_S1PIE, + FEAT_S1POE, + FEAT_S2PIE, + FEAT_S2POE, + FEAT_SPECRES2, + FEAT_SPE_CRR, + FEAT_SPE_FDS, + FEAT_SPEv1p4, + FEAT_SPMU, + FEAT_THE, + FEAT_DoPD, + FEAT_ETE, + FEAT_SVE2, + FEAT_SVE_AES, + FEAT_SVE_BitPerm, + FEAT_SVE_PMULL128, + FEAT_SVE_SHA3, + FEAT_SVE_SM4, + FEAT_TME, + FEAT_TRBE, + FEAT_ETEv1p1, + FEAT_BRBE, + FEAT_ETEv1p2, + FEAT_RME, + FEAT_SME, + FEAT_SME_F64F64, + FEAT_SME_FA64, + FEAT_SME_I16I64, + FEAT_BRBEv1p1, + FEAT_MEC, + FEAT_SME2, + FEAT_ABLE, + FEAT_CHK, + FEAT_D128, + FEAT_EBEP, + FEAT_ETEv1p3, + FEAT_GCS, + FEAT_ITE, + FEAT_LSE128, + FEAT_LVA3, + FEAT_SEBEP, + FEAT_SME2p1, + FEAT_SME_F16F16, + FEAT_SVE2p1, + FEAT_SVE_B16B16, + FEAT_SYSINSTR128, + FEAT_SYSREG128, + FEAT_TRBE_EXT, + FEAT_TRBE_MPAM +} + +enum ArchVersion = { + v8Ap0, + v8Ap1, + v8Ap2, + v8Ap3, + v8Ap4, + v8Ap5, + v8Ap6, + v8Ap7, + v8Ap8, + v8Ap9, + v9Ap0, + v9Ap1, + v9Ap2, + v9Ap3, + v9Ap4 +} + +register FEAT_AA32EL0_IMPLEMENTED : bool = true + +register FEAT_AA32EL1_IMPLEMENTED : bool = false + +register FEAT_AA32EL2_IMPLEMENTED : bool = false + +register FEAT_AA32EL3_IMPLEMENTED : bool = false + +register FEAT_AA64EL0_IMPLEMENTED : bool = true + +register FEAT_AA64EL1_IMPLEMENTED : bool = true + +register FEAT_AA64EL2_IMPLEMENTED : bool = true + +register FEAT_AA64EL3_IMPLEMENTED : bool = true + +register FEAT_EL0_IMPLEMENTED : bool = true + +register FEAT_EL1_IMPLEMENTED : bool = true + +register FEAT_EL2_IMPLEMENTED : bool = true + +register FEAT_EL3_IMPLEMENTED : bool = true + +register FEAT_AES_IMPLEMENTED : bool = true + +register FEAT_AdvSIMD_IMPLEMENTED : bool = true + +register FEAT_CSV2_1p1_IMPLEMENTED : bool = true + +register FEAT_CSV2_1p2_IMPLEMENTED : bool = true + +register FEAT_CSV2_2_IMPLEMENTED : bool = true + +register FEAT_CSV2_3_IMPLEMENTED : bool = true + +register FEAT_DoubleLock_IMPLEMENTED : bool = true + +register FEAT_ETMv4_IMPLEMENTED : bool = false + +register FEAT_ETMv4p1_IMPLEMENTED : bool = true + +register FEAT_ETMv4p2_IMPLEMENTED : bool = true + +register FEAT_ETMv4p3_IMPLEMENTED : bool = true + +register FEAT_ETMv4p4_IMPLEMENTED : bool = true + +register FEAT_ETMv4p5_IMPLEMENTED : bool = true + +register FEAT_ETMv4p6_IMPLEMENTED : bool = true + +register FEAT_ETS2_IMPLEMENTED : bool = true + +register FEAT_FP_IMPLEMENTED : bool = true + +register FEAT_GICv3_IMPLEMENTED : bool = true + +register FEAT_GICv3_LEGACY_IMPLEMENTED : bool = true + +register FEAT_GICv3_TDIR_IMPLEMENTED : bool = true + +register FEAT_GICv3p1_IMPLEMENTED : bool = true + +register FEAT_GICv4_IMPLEMENTED : bool = true + +register FEAT_GICv4p1_IMPLEMENTED : bool = true + +register FEAT_IVIPT_IMPLEMENTED : bool = true + +register FEAT_PCSRv8_IMPLEMENTED : bool = true + +register FEAT_PMULL_IMPLEMENTED : bool = true + +register FEAT_PMUv3_IMPLEMENTED : bool = true + +register FEAT_PMUv3_EXT_IMPLEMENTED : bool = true + +register FEAT_PMUv3_EXT32_IMPLEMENTED : bool = true + +register FEAT_SHA1_IMPLEMENTED : bool = true + +register FEAT_SHA256_IMPLEMENTED : bool = true + +register FEAT_TRC_EXT_IMPLEMENTED : bool = true + +register FEAT_TRC_SR_IMPLEMENTED : bool = true + +register FEAT_nTLBPA_IMPLEMENTED : bool = true + +register FEAT_CRC32_IMPLEMENTED : bool = true + +register FEAT_Debugv8p1_IMPLEMENTED : bool = true + +register FEAT_HAFDBS_IMPLEMENTED : bool = true + +register FEAT_HPDS_IMPLEMENTED : bool = true + +register FEAT_LOR_IMPLEMENTED : bool = true + +register FEAT_LSE_IMPLEMENTED : bool = true + +register FEAT_PAN_IMPLEMENTED : bool = true + +register FEAT_PMUv3p1_IMPLEMENTED : bool = true + +register FEAT_RDM_IMPLEMENTED : bool = true + +register FEAT_VHE_IMPLEMENTED : bool = true + +register FEAT_VMID16_IMPLEMENTED : bool = true + +register FEAT_AA32BF16_IMPLEMENTED : bool = true + +register FEAT_AA32HPD_IMPLEMENTED : bool = true + +register FEAT_AA32I8MM_IMPLEMENTED : bool = true + +register FEAT_ASMv8p2_IMPLEMENTED : bool = true + +register FEAT_DPB_IMPLEMENTED : bool = true + +register FEAT_Debugv8p2_IMPLEMENTED : bool = true + +register FEAT_EDHSR_IMPLEMENTED : bool = true + +register FEAT_F32MM_IMPLEMENTED : bool = true + +register FEAT_F64MM_IMPLEMENTED : bool = true + +register FEAT_FP16_IMPLEMENTED : bool = true + +register FEAT_HPDS2_IMPLEMENTED : bool = true + +register FEAT_I8MM_IMPLEMENTED : bool = true + +register FEAT_IESB_IMPLEMENTED : bool = true + +register FEAT_LPA_IMPLEMENTED : bool = true + +register FEAT_LSMAOC_IMPLEMENTED : bool = true + +register FEAT_LVA_IMPLEMENTED : bool = true + +register FEAT_MPAM_IMPLEMENTED : bool = true + +register FEAT_PAN2_IMPLEMENTED : bool = true + +register FEAT_PCSRv8p2_IMPLEMENTED : bool = true + +register FEAT_RAS_IMPLEMENTED : bool = true + +register FEAT_SHA3_IMPLEMENTED : bool = true + +register FEAT_SHA512_IMPLEMENTED : bool = true + +register FEAT_SM3_IMPLEMENTED : bool = true + +register FEAT_SM4_IMPLEMENTED : bool = true + +register FEAT_SPE_IMPLEMENTED : bool = true + +register FEAT_SVE_IMPLEMENTED : bool = true + +register FEAT_TTCNP_IMPLEMENTED : bool = true + +register FEAT_UAO_IMPLEMENTED : bool = true + +register FEAT_VPIPT_IMPLEMENTED : bool = true + +register FEAT_XNX_IMPLEMENTED : bool = true + +register FEAT_CCIDX_IMPLEMENTED : bool = true + +register FEAT_CONSTPACFIELD_IMPLEMENTED : bool = false + +register FEAT_EPAC_IMPLEMENTED : bool = false + +register FEAT_FCMA_IMPLEMENTED : bool = true + +register FEAT_FPAC_IMPLEMENTED : bool = true + +register FEAT_FPACCOMBINE_IMPLEMENTED : bool = true + +register FEAT_JSCVT_IMPLEMENTED : bool = true + +register FEAT_LRCPC_IMPLEMENTED : bool = true + +register FEAT_NV_IMPLEMENTED : bool = true + +register FEAT_PACIMP_IMPLEMENTED : bool = false + +register FEAT_PACQARMA3_IMPLEMENTED : bool = false + +register FEAT_PACQARMA5_IMPLEMENTED : bool = true + +register FEAT_PAuth_IMPLEMENTED : bool = true + +register FEAT_SPEv1p1_IMPLEMENTED : bool = true + +register FEAT_AMUv1_IMPLEMENTED : bool = true + +register FEAT_BBM_IMPLEMENTED : bool = true + +register FEAT_CNTSC_IMPLEMENTED : bool = true + +register FEAT_DIT_IMPLEMENTED : bool = true + +register FEAT_Debugv8p4_IMPLEMENTED : bool = true + +register FEAT_DotProd_IMPLEMENTED : bool = true + +register FEAT_DoubleFault_IMPLEMENTED : bool = true + +register FEAT_FHM_IMPLEMENTED : bool = true + +register FEAT_FlagM_IMPLEMENTED : bool = true + +register FEAT_IDST_IMPLEMENTED : bool = true + +register FEAT_LRCPC2_IMPLEMENTED : bool = true + +register FEAT_LSE2_IMPLEMENTED : bool = true + +register FEAT_NV2_IMPLEMENTED : bool = true + +register FEAT_PMUv3p4_IMPLEMENTED : bool = true + +register FEAT_RASSAv1p1_IMPLEMENTED : bool = true + +register FEAT_RASv1p1_IMPLEMENTED : bool = true + +register FEAT_S2FWB_IMPLEMENTED : bool = true + +register FEAT_SEL2_IMPLEMENTED : bool = true + +register FEAT_TLBIOS_IMPLEMENTED : bool = true + +register FEAT_TLBIRANGE_IMPLEMENTED : bool = true + +register FEAT_TRF_IMPLEMENTED : bool = true + +register FEAT_TTL_IMPLEMENTED : bool = true + +register FEAT_TTST_IMPLEMENTED : bool = true + +register FEAT_BTI_IMPLEMENTED : bool = true + +register FEAT_CSV2_IMPLEMENTED : bool = true + +register FEAT_CSV3_IMPLEMENTED : bool = true + +register FEAT_DPB2_IMPLEMENTED : bool = true + +register FEAT_E0PD_IMPLEMENTED : bool = true + +register FEAT_EVT_IMPLEMENTED : bool = true + +register FEAT_ExS_IMPLEMENTED : bool = true + +register FEAT_FRINTTS_IMPLEMENTED : bool = true + +register FEAT_FlagM2_IMPLEMENTED : bool = true + +register FEAT_GTG_IMPLEMENTED : bool = true + +register FEAT_MTE_IMPLEMENTED : bool = true + +register FEAT_MTE2_IMPLEMENTED : bool = true + +register FEAT_PMUv3p5_IMPLEMENTED : bool = true + +register FEAT_RNG_IMPLEMENTED : bool = true + +register FEAT_RNG_TRAP_IMPLEMENTED : bool = true + +register FEAT_SB_IMPLEMENTED : bool = true + +register FEAT_SPECRES_IMPLEMENTED : bool = true + +register FEAT_SSBS_IMPLEMENTED : bool = true + +register FEAT_SSBS2_IMPLEMENTED : bool = true + +register FEAT_AMUv1p1_IMPLEMENTED : bool = true + +register FEAT_BF16_IMPLEMENTED : bool = true + +register FEAT_DGH_IMPLEMENTED : bool = true + +register FEAT_ECV_IMPLEMENTED : bool = true + +register FEAT_FGT_IMPLEMENTED : bool = true + +register FEAT_HPMN0_IMPLEMENTED : bool = true + +register FEAT_MPAMv0p1_IMPLEMENTED : bool = true + +register FEAT_MPAMv1p1_IMPLEMENTED : bool = true + +register FEAT_MTPMU_IMPLEMENTED : bool = true + +register FEAT_PAuth2_IMPLEMENTED : bool = true + +register FEAT_TWED_IMPLEMENTED : bool = true + +register FEAT_AFP_IMPLEMENTED : bool = true + +register FEAT_EBF16_IMPLEMENTED : bool = true + +register FEAT_HCX_IMPLEMENTED : bool = true + +register FEAT_LPA2_IMPLEMENTED : bool = true + +register FEAT_LS64_IMPLEMENTED : bool = true + +register FEAT_LS64_ACCDATA_IMPLEMENTED : bool = true + +register FEAT_LS64_V_IMPLEMENTED : bool = true + +register FEAT_MTE3_IMPLEMENTED : bool = true + +register FEAT_PAN3_IMPLEMENTED : bool = true + +register FEAT_PMUv3p7_IMPLEMENTED : bool = true + +register FEAT_RPRES_IMPLEMENTED : bool = true + +register FEAT_SPEv1p2_IMPLEMENTED : bool = true + +register FEAT_WFxT_IMPLEMENTED : bool = true + +register FEAT_XS_IMPLEMENTED : bool = true + +register FEAT_CMOW_IMPLEMENTED : bool = true + +register FEAT_Debugv8p8_IMPLEMENTED : bool = true + +register FEAT_GICv3_NMI_IMPLEMENTED : bool = true + +register FEAT_HBC_IMPLEMENTED : bool = true + +register FEAT_MOPS_IMPLEMENTED : bool = true + +register FEAT_NMI_IMPLEMENTED : bool = true + +register FEAT_PMUv3_EXT64_IMPLEMENTED : bool = true + +register FEAT_PMUv3_TH_IMPLEMENTED : bool = true + +register FEAT_PMUv3p8_IMPLEMENTED : bool = true + +register FEAT_SCTLR2_IMPLEMENTED : bool = true + +register FEAT_SPEv1p3_IMPLEMENTED : bool = true + +register FEAT_TCR2_IMPLEMENTED : bool = true + +register FEAT_TIDCP1_IMPLEMENTED : bool = true + +register FEAT_ADERR_IMPLEMENTED : bool = true + +register FEAT_AIE_IMPLEMENTED : bool = true + +register FEAT_ANERR_IMPLEMENTED : bool = true + +register FEAT_CLRBHB_IMPLEMENTED : bool = true + +register FEAT_CSSC_IMPLEMENTED : bool = true + +register FEAT_Debugv8p9_IMPLEMENTED : bool = true + +register FEAT_DoubleFault2_IMPLEMENTED : bool = true + +register FEAT_ECBHB_IMPLEMENTED : bool = true + +register FEAT_FGT2_IMPLEMENTED : bool = true + +register FEAT_HAFT_IMPLEMENTED : bool = true + +register FEAT_LRCPC3_IMPLEMENTED : bool = true + +register FEAT_MTE4_IMPLEMENTED : bool = true + +register FEAT_MTE_ASYM_FAULT_IMPLEMENTED : bool = true + +register FEAT_MTE_ASYNC_IMPLEMENTED : bool = true + +register FEAT_MTE_CANONICAL_TAGS_IMPLEMENTED : bool = true + +register FEAT_MTE_NO_ADDRESS_TAGS_IMPLEMENTED : bool = true + +register FEAT_MTE_PERM_IMPLEMENTED : bool = true + +register FEAT_MTE_STORE_ONLY_IMPLEMENTED : bool = true + +register FEAT_MTE_TAGGED_FAR_IMPLEMENTED : bool = true + +register FEAT_PCSRv8p9_IMPLEMENTED : bool = true + +register FEAT_PFAR_IMPLEMENTED : bool = true + +register FEAT_PMUv3_EDGE_IMPLEMENTED : bool = true + +register FEAT_PMUv3_ICNTR_IMPLEMENTED : bool = true + +register FEAT_PMUv3_SS_IMPLEMENTED : bool = true + +register FEAT_PMUv3p9_IMPLEMENTED : bool = true + +register FEAT_PRFMSLC_IMPLEMENTED : bool = true + +register FEAT_RASSAv2_IMPLEMENTED : bool = true + +register FEAT_RASv2_IMPLEMENTED : bool = true + +register FEAT_RPRFM_IMPLEMENTED : bool = true + +register FEAT_S1PIE_IMPLEMENTED : bool = true + +register FEAT_S1POE_IMPLEMENTED : bool = true + +register FEAT_S2PIE_IMPLEMENTED : bool = true + +register FEAT_S2POE_IMPLEMENTED : bool = true + +register FEAT_SPECRES2_IMPLEMENTED : bool = true + +register FEAT_SPE_CRR_IMPLEMENTED : bool = true + +register FEAT_SPE_FDS_IMPLEMENTED : bool = true + +register FEAT_SPEv1p4_IMPLEMENTED : bool = true + +register FEAT_SPMU_IMPLEMENTED : bool = true + +register FEAT_THE_IMPLEMENTED : bool = true + +register FEAT_DoPD_IMPLEMENTED : bool = true + +register FEAT_ETE_IMPLEMENTED : bool = true + +register FEAT_SVE2_IMPLEMENTED : bool = true + +register FEAT_SVE_AES_IMPLEMENTED : bool = true + +register FEAT_SVE_BitPerm_IMPLEMENTED : bool = true + +register FEAT_SVE_PMULL128_IMPLEMENTED : bool = true + +register FEAT_SVE_SHA3_IMPLEMENTED : bool = true + +register FEAT_SVE_SM4_IMPLEMENTED : bool = true + +register FEAT_TME_IMPLEMENTED : bool = true + +register FEAT_TRBE_IMPLEMENTED : bool = true + +register FEAT_ETEv1p1_IMPLEMENTED : bool = true + +register FEAT_BRBE_IMPLEMENTED : bool = true + +register FEAT_ETEv1p2_IMPLEMENTED : bool = true + +register FEAT_RME_IMPLEMENTED : bool = true + +register FEAT_SME_IMPLEMENTED : bool = true + +register FEAT_SME_F64F64_IMPLEMENTED : bool = true + +register FEAT_SME_FA64_IMPLEMENTED : bool = true + +register FEAT_SME_I16I64_IMPLEMENTED : bool = true + +register FEAT_BRBEv1p1_IMPLEMENTED : bool = true + +register FEAT_MEC_IMPLEMENTED : bool = true + +register FEAT_SME2_IMPLEMENTED : bool = true + +register FEAT_ABLE_IMPLEMENTED : bool = true + +register FEAT_CHK_IMPLEMENTED : bool = true + +register FEAT_D128_IMPLEMENTED : bool = true + +register FEAT_EBEP_IMPLEMENTED : bool = true + +register FEAT_ETEv1p3_IMPLEMENTED : bool = true + +register FEAT_GCS_IMPLEMENTED : bool = true + +register FEAT_ITE_IMPLEMENTED : bool = true + +register FEAT_LSE128_IMPLEMENTED : bool = true + +register FEAT_LVA3_IMPLEMENTED : bool = true + +register FEAT_SEBEP_IMPLEMENTED : bool = true + +register FEAT_SME2p1_IMPLEMENTED : bool = true + +register FEAT_SME_F16F16_IMPLEMENTED : bool = true + +register FEAT_SVE2p1_IMPLEMENTED : bool = true + +register FEAT_SVE_B16B16_IMPLEMENTED : bool = true + +register FEAT_SYSINSTR128_IMPLEMENTED : bool = true + +register FEAT_SYSREG128_IMPLEMENTED : bool = true + +register FEAT_TRBE_EXT_IMPLEMENTED : bool = true + +register FEAT_TRBE_MPAM_IMPLEMENTED : bool = true + +register v8Ap0_IMPLEMENTED : bool = true + +register v8Ap1_IMPLEMENTED : bool = true + +register v8Ap2_IMPLEMENTED : bool = true + +register v8Ap3_IMPLEMENTED : bool = true + +register v8Ap4_IMPLEMENTED : bool = true + +register v8Ap5_IMPLEMENTED : bool = true + +register v8Ap6_IMPLEMENTED : bool = true + +register v8Ap7_IMPLEMENTED : bool = true + +register v8Ap8_IMPLEMENTED : bool = true + +register v8Ap9_IMPLEMENTED : bool = true + +register v9Ap0_IMPLEMENTED : bool = true + +register v9Ap1_IMPLEMENTED : bool = true + +register v9Ap2_IMPLEMENTED : bool = true + +register v9Ap3_IMPLEMENTED : bool = true + +register v9Ap4_IMPLEMENTED : bool = true + +register FeatureImpl : vector(259, bool) + +val InitFeatureImpl : unit -> unit + +function InitFeatureImpl () = { + FeatureImpl[num_of_Feature(FEAT_AA32EL0)] = FEAT_AA32EL0_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA32EL1)] = FEAT_AA32EL1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA32EL2)] = FEAT_AA32EL2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA32EL3)] = FEAT_AA32EL3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA64EL0)] = FEAT_AA64EL0_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA64EL1)] = FEAT_AA64EL1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA64EL2)] = FEAT_AA64EL2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA64EL3)] = FEAT_AA64EL3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EL0)] = FEAT_EL0_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EL1)] = FEAT_EL1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EL2)] = FEAT_EL2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EL3)] = FEAT_EL3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AES)] = FEAT_AES_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AdvSIMD)] = FEAT_AdvSIMD_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CSV2_1p1)] = FEAT_CSV2_1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CSV2_1p2)] = FEAT_CSV2_1p2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CSV2_2)] = FEAT_CSV2_2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CSV2_3)] = FEAT_CSV2_3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DoubleLock)] = FEAT_DoubleLock_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETMv4)] = FEAT_ETMv4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETMv4p1)] = FEAT_ETMv4p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETMv4p2)] = FEAT_ETMv4p2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETMv4p3)] = FEAT_ETMv4p3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETMv4p4)] = FEAT_ETMv4p4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETMv4p5)] = FEAT_ETMv4p5_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETMv4p6)] = FEAT_ETMv4p6_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETS2)] = FEAT_ETS2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FP)] = FEAT_FP_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GICv3)] = FEAT_GICv3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GICv3_LEGACY)] = FEAT_GICv3_LEGACY_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GICv3_TDIR)] = FEAT_GICv3_TDIR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GICv3p1)] = FEAT_GICv3p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GICv4)] = FEAT_GICv4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GICv4p1)] = FEAT_GICv4p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_IVIPT)] = FEAT_IVIPT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PCSRv8)] = FEAT_PCSRv8_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMULL)] = FEAT_PMULL_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3)] = FEAT_PMUv3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3_EXT)] = FEAT_PMUv3_EXT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3_EXT32)] = FEAT_PMUv3_EXT32_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SHA1)] = FEAT_SHA1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SHA256)] = FEAT_SHA256_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TRC_EXT)] = FEAT_TRC_EXT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TRC_SR)] = FEAT_TRC_SR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_nTLBPA)] = FEAT_nTLBPA_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CRC32)] = FEAT_CRC32_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_Debugv8p1)] = FEAT_Debugv8p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_HAFDBS)] = FEAT_HAFDBS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_HPDS)] = FEAT_HPDS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LOR)] = FEAT_LOR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LSE)] = FEAT_LSE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PAN)] = FEAT_PAN_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3p1)] = FEAT_PMUv3p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RDM)] = FEAT_RDM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_VHE)] = FEAT_VHE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_VMID16)] = FEAT_VMID16_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA32BF16)] = FEAT_AA32BF16_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA32HPD)] = FEAT_AA32HPD_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AA32I8MM)] = FEAT_AA32I8MM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ASMv8p2)] = FEAT_ASMv8p2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DPB)] = FEAT_DPB_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_Debugv8p2)] = FEAT_Debugv8p2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EDHSR)] = FEAT_EDHSR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_F32MM)] = FEAT_F32MM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_F64MM)] = FEAT_F64MM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FP16)] = FEAT_FP16_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_HPDS2)] = FEAT_HPDS2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_I8MM)] = FEAT_I8MM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_IESB)] = FEAT_IESB_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LPA)] = FEAT_LPA_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LSMAOC)] = FEAT_LSMAOC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LVA)] = FEAT_LVA_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MPAM)] = FEAT_MPAM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PAN2)] = FEAT_PAN2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PCSRv8p2)] = FEAT_PCSRv8p2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RAS)] = FEAT_RAS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SHA3)] = FEAT_SHA3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SHA512)] = FEAT_SHA512_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SM3)] = FEAT_SM3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SM4)] = FEAT_SM4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPE)] = FEAT_SPE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE)] = FEAT_SVE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TTCNP)] = FEAT_TTCNP_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_UAO)] = FEAT_UAO_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_VPIPT)] = FEAT_VPIPT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_XNX)] = FEAT_XNX_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CCIDX)] = FEAT_CCIDX_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CONSTPACFIELD)] = FEAT_CONSTPACFIELD_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EPAC)] = FEAT_EPAC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FCMA)] = FEAT_FCMA_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FPAC)] = FEAT_FPAC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FPACCOMBINE)] = FEAT_FPACCOMBINE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_JSCVT)] = FEAT_JSCVT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LRCPC)] = FEAT_LRCPC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_NV)] = FEAT_NV_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PACIMP)] = FEAT_PACIMP_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PACQARMA3)] = FEAT_PACQARMA3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PACQARMA5)] = FEAT_PACQARMA5_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PAuth)] = FEAT_PAuth_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPEv1p1)] = FEAT_SPEv1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AMUv1)] = FEAT_AMUv1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_BBM)] = FEAT_BBM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CNTSC)] = FEAT_CNTSC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DIT)] = FEAT_DIT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_Debugv8p4)] = FEAT_Debugv8p4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DotProd)] = FEAT_DotProd_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DoubleFault)] = FEAT_DoubleFault_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FHM)] = FEAT_FHM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FlagM)] = FEAT_FlagM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_IDST)] = FEAT_IDST_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LRCPC2)] = FEAT_LRCPC2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LSE2)] = FEAT_LSE2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_NV2)] = FEAT_NV2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3p4)] = FEAT_PMUv3p4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RASSAv1p1)] = FEAT_RASSAv1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RASv1p1)] = FEAT_RASv1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_S2FWB)] = FEAT_S2FWB_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SEL2)] = FEAT_SEL2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TLBIOS)] = FEAT_TLBIOS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TLBIRANGE)] = FEAT_TLBIRANGE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TRF)] = FEAT_TRF_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TTL)] = FEAT_TTL_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TTST)] = FEAT_TTST_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_BTI)] = FEAT_BTI_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CSV2)] = FEAT_CSV2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CSV3)] = FEAT_CSV3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DPB2)] = FEAT_DPB2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_E0PD)] = FEAT_E0PD_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EVT)] = FEAT_EVT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ExS)] = FEAT_ExS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FRINTTS)] = FEAT_FRINTTS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FlagM2)] = FEAT_FlagM2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GTG)] = FEAT_GTG_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE)] = FEAT_MTE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE2)] = FEAT_MTE2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3p5)] = FEAT_PMUv3p5_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RNG)] = FEAT_RNG_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RNG_TRAP)] = FEAT_RNG_TRAP_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SB)] = FEAT_SB_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPECRES)] = FEAT_SPECRES_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SSBS)] = FEAT_SSBS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SSBS2)] = FEAT_SSBS2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AMUv1p1)] = FEAT_AMUv1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_BF16)] = FEAT_BF16_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DGH)] = FEAT_DGH_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ECV)] = FEAT_ECV_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FGT)] = FEAT_FGT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_HPMN0)] = FEAT_HPMN0_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MPAMv0p1)] = FEAT_MPAMv0p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MPAMv1p1)] = FEAT_MPAMv1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTPMU)] = FEAT_MTPMU_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PAuth2)] = FEAT_PAuth2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TWED)] = FEAT_TWED_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AFP)] = FEAT_AFP_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EBF16)] = FEAT_EBF16_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_HCX)] = FEAT_HCX_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LPA2)] = FEAT_LPA2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LS64)] = FEAT_LS64_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LS64_ACCDATA)] = FEAT_LS64_ACCDATA_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LS64_V)] = FEAT_LS64_V_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE3)] = FEAT_MTE3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PAN3)] = FEAT_PAN3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3p7)] = FEAT_PMUv3p7_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RPRES)] = FEAT_RPRES_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPEv1p2)] = FEAT_SPEv1p2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_WFxT)] = FEAT_WFxT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_XS)] = FEAT_XS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CMOW)] = FEAT_CMOW_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_Debugv8p8)] = FEAT_Debugv8p8_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GICv3_NMI)] = FEAT_GICv3_NMI_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_HBC)] = FEAT_HBC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MOPS)] = FEAT_MOPS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_NMI)] = FEAT_NMI_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3_EXT64)] = FEAT_PMUv3_EXT64_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3_TH)] = FEAT_PMUv3_TH_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3p8)] = FEAT_PMUv3p8_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SCTLR2)] = FEAT_SCTLR2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPEv1p3)] = FEAT_SPEv1p3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TCR2)] = FEAT_TCR2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TIDCP1)] = FEAT_TIDCP1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ADERR)] = FEAT_ADERR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_AIE)] = FEAT_AIE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ANERR)] = FEAT_ANERR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CLRBHB)] = FEAT_CLRBHB_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CSSC)] = FEAT_CSSC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_Debugv8p9)] = FEAT_Debugv8p9_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DoubleFault2)] = FEAT_DoubleFault2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ECBHB)] = FEAT_ECBHB_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_FGT2)] = FEAT_FGT2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_HAFT)] = FEAT_HAFT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LRCPC3)] = FEAT_LRCPC3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE4)] = FEAT_MTE4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE_ASYM_FAULT)] = FEAT_MTE_ASYM_FAULT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE_ASYNC)] = FEAT_MTE_ASYNC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE_CANONICAL_TAGS)] = FEAT_MTE_CANONICAL_TAGS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE_NO_ADDRESS_TAGS)] = FEAT_MTE_NO_ADDRESS_TAGS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE_PERM)] = FEAT_MTE_PERM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE_STORE_ONLY)] = FEAT_MTE_STORE_ONLY_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MTE_TAGGED_FAR)] = FEAT_MTE_TAGGED_FAR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PCSRv8p9)] = FEAT_PCSRv8p9_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PFAR)] = FEAT_PFAR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3_EDGE)] = FEAT_PMUv3_EDGE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3_ICNTR)] = FEAT_PMUv3_ICNTR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3_SS)] = FEAT_PMUv3_SS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PMUv3p9)] = FEAT_PMUv3p9_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_PRFMSLC)] = FEAT_PRFMSLC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RASSAv2)] = FEAT_RASSAv2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RASv2)] = FEAT_RASv2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RPRFM)] = FEAT_RPRFM_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_S1PIE)] = FEAT_S1PIE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_S1POE)] = FEAT_S1POE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_S2PIE)] = FEAT_S2PIE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_S2POE)] = FEAT_S2POE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPECRES2)] = FEAT_SPECRES2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPE_CRR)] = FEAT_SPE_CRR_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPE_FDS)] = FEAT_SPE_FDS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPEv1p4)] = FEAT_SPEv1p4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SPMU)] = FEAT_SPMU_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_THE)] = FEAT_THE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_DoPD)] = FEAT_DoPD_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETE)] = FEAT_ETE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE2)] = FEAT_SVE2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE_AES)] = FEAT_SVE_AES_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE_BitPerm)] = FEAT_SVE_BitPerm_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE_PMULL128)] = FEAT_SVE_PMULL128_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE_SHA3)] = FEAT_SVE_SHA3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE_SM4)] = FEAT_SVE_SM4_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TME)] = FEAT_TME_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TRBE)] = FEAT_TRBE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETEv1p1)] = FEAT_ETEv1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_BRBE)] = FEAT_BRBE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETEv1p2)] = FEAT_ETEv1p2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_RME)] = FEAT_RME_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SME)] = FEAT_SME_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SME_F64F64)] = FEAT_SME_F64F64_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SME_FA64)] = FEAT_SME_FA64_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SME_I16I64)] = FEAT_SME_I16I64_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_BRBEv1p1)] = FEAT_BRBEv1p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_MEC)] = FEAT_MEC_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SME2)] = FEAT_SME2_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ABLE)] = FEAT_ABLE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_CHK)] = FEAT_CHK_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_D128)] = FEAT_D128_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_EBEP)] = FEAT_EBEP_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ETEv1p3)] = FEAT_ETEv1p3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_GCS)] = FEAT_GCS_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_ITE)] = FEAT_ITE_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LSE128)] = FEAT_LSE128_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_LVA3)] = FEAT_LVA3_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SEBEP)] = FEAT_SEBEP_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SME2p1)] = FEAT_SME2p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SME_F16F16)] = FEAT_SME_F16F16_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE2p1)] = FEAT_SVE2p1_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SVE_B16B16)] = FEAT_SVE_B16B16_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SYSINSTR128)] = FEAT_SYSINSTR128_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_SYSREG128)] = FEAT_SYSREG128_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TRBE_EXT)] = FEAT_TRBE_EXT_IMPLEMENTED; + FeatureImpl[num_of_Feature(FEAT_TRBE_MPAM)] = FEAT_TRBE_MPAM_IMPLEMENTED; + return() +} + +register VariantImplemented : vector(16, bool) + +val InitVariantImplemented : unit -> unit + +function InitVariantImplemented () = { + VariantImplemented[num_of_ArchVersion(v8Ap0)] = v8Ap0_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap1)] = v8Ap1_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap2)] = v8Ap2_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap3)] = v8Ap3_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap4)] = v8Ap4_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap5)] = v8Ap5_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap6)] = v8Ap6_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap7)] = v8Ap7_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap8)] = v8Ap8_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v8Ap9)] = v8Ap9_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v9Ap0)] = v9Ap0_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v9Ap1)] = v9Ap1_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v9Ap2)] = v9Ap2_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v9Ap3)] = v9Ap3_IMPLEMENTED; + VariantImplemented[num_of_ArchVersion(v9Ap4)] = v9Ap4_IMPLEMENTED; + return() +} + +val IsFeatureImplemented : Feature -> bool + +function IsFeatureImplemented feat = { + return(FeatureImpl[num_of_Feature(feat)]) +} + +register NUM_AMU_COUNTER_GROUPS : int = 2 + +register NUM_AMU_CG0_MONITORS : int = 4 + +register NUM_AMU_CG1_MONITORS : int = 16 + +register NUM_PMU_COUNTERS : int = 31 + +register NUM_BRBE_RECORDS : int = 64 + +register NUM_GIC_PREEMPTION_BITS : int = 5 + +register NUM_GIC_PRIORITY_BITS : int = 5 + +register NUM_GIC_LIST_REGS : int = 16 + +register NUM_BREAKPOINTS : int = negate(1) + +register NUM_WATCHPOINTS : int = negate(1) + +bitfield SCRType : bits(64) = + { + NS : 0, + IRQ : 1, + FIQ : 2, + EA : 3, + FW : 4, + AW : 5, + nET : 6, + SCD : 7, + SMD : 7, + HCE : 8, + SIF : 9, + RW : 10, + ST : 11, + TWI : 12, + TWE : 13 + } + +bitfield SCTLRType : bits(64) = + { + M : 0, + A : 1, + C : 2, + SA : 3, + SA0 : 4, + CP15BEN : 5, + nAA : 6, + ITD : 7, + SED : 8, + UMA : 9, + I : 12, + DZE : 14, + UCT : 15, + nTWI : 16, + nTWE : 18, + WXN : 19, + TSCXT : 20, + IESB : 21, + SPAN : 23, + E0E : 24, + EE : 25, + UCI : 26, + DSSBS : 44, + TMT0 : 50, + TMT : 51, + TME0 : 52, + TME : 53, + EPAN : 57, + NMI : 61, + SPINTMASK : 62, + TIDCP : 63 + } + +bitfield MAIRType : bits(64) = + { + Attr0 : 7..0, + Attr1 : 15..8, + Attr2 : 23..16, + Attr3 : 31..24, + Attr4 : 39..32, + Attr5 : 47..40, + Attr6 : 55..48, + Attr7 : 63..56 + } + +bitfield S1PIRType : bits(64) = + { + Perm0 : 3..0, + Perm1 : 7..4, + Perm2 : 11..8, + Perm3 : 15..12, + Perm4 : 19..16, + Perm5 : 23..20, + Perm6 : 27..24, + Perm7 : 31..28, + Perm8 : 35..32, + Perm9 : 39..36, + Perm10 : 43..40, + Perm11 : 47..44, + Perm12 : 51..48, + Perm13 : 55..52, + Perm14 : 59..56, + Perm15 : 63..60 + } + +bitfield S1PORType : bits(64) = + { + Perm0 : 3..0, + Perm1 : 7..4, + Perm2 : 11..8, + Perm3 : 15..12, + Perm4 : 19..16, + Perm5 : 23..20, + Perm6 : 27..24, + Perm7 : 31..28, + Perm8 : 35..32, + Perm9 : 39..36, + Perm10 : 43..40, + Perm11 : 47..44, + Perm12 : 51..48, + Perm13 : 55..52, + Perm14 : 59..56, + Perm15 : 63..60 + } + +bitfield S2PIRType : bits(64) = + { + Perm0 : 3..0, + Perm1 : 7..4, + Perm2 : 11..8, + Perm3 : 15..12, + Perm4 : 19..16, + Perm5 : 23..20, + Perm6 : 27..24, + Perm7 : 31..28, + Perm8 : 35..32, + Perm9 : 39..36, + Perm10 : 43..40, + Perm11 : 47..44, + Perm12 : 51..48, + Perm13 : 55..52, + Perm14 : 59..56, + Perm15 : 63..60 + } + +bitfield ESRType : bits(64) = {ISS : 24..0, IL : 25, EC : 31..26} + +bitfield FPCRType : bits(64) = + { + FIZ : 0, + AH : 1, + NEP : 2, + IOE : 8, + DZE : 9, + OFE : 10, + UFE : 11, + IXE : 12, + EBF : 13, + IDE : 15, + length : 18..16, + FZ16 : 19, + Stride : 21..20, + RMode : 23..22, + FZ : 24, + DN : 25, + AHP : 26, + IOC : 32, + DZC : 33, + OFC : 34 + } + +bitfield BRBSRCType : bits(64) = {ADDRESS : 63..0} + +bitfield BRBTGTType : bits(64) = {ADDRESS : 63..0} + +bitfield BRBINFType : bits(64) = + { + CCU : 46, + CC : 45..32, + LASTFAILED : 17, + T : 16, + TYPE : 13..8, + EL : 7..6, + MPRED : 5, + VALID : 1..0 + } + +enum Signal = {Signal_Low, Signal_High} + +register __trcclaim_tags : bits(32) + +register __cycle_count : int + +register CP15SDISABLE : Signal + +register CP15SDISABLE2 : Signal + +register IsWFIsleep : bool + +register IsWFEsleep : bool + +register _ConfigReg : Configuration_Type + +register _DormantCtlReg : DormantCtl_Type + +register PMUEventAccumulator : vector(31, int) + +register PMULastThresholdValue : vector(31, bool) + +let CYCLE_COUNTER_ID : int(31) = 31 + +let INSTRUCTION_COUNTER_ID : int(32) = 32 + +register __clock_divider : int + +let PMU_EVENT_SW_INCR : bits(16) = 0x0000 + +let PMU_EVENT_L1D_CACHE_REFILL : bits(16) = 0x0003 + +let PMU_EVENT_L1D_CACHE : bits(16) = 0x0004 + +let PMU_EVENT_INST_RETIRED : bits(16) = 0x0008 + +let PMU_EVENT_EXC_TAKEN : bits(16) = 0x0009 + +let PMU_EVENT_BR_MIS_PRED : bits(16) = 0x0010 + +let PMU_EVENT_CPU_CYCLES : bits(16) = 0x0011 + +let PMU_EVENT_INST_SPEC : bits(16) = 0x001B + +let PMU_EVENT_CHAIN : bits(16) = 0x001E + +let PMU_EVENT_BR_MIS_PRED_RETIRED : bits(16) = 0x0022 + +let PMU_EVENT_L1D_TLB : bits(16) = 0x0025 + +let PMU_EVENT_REMOTE_ACCESS : bits(16) = 0x0031 + +let PMU_EVENT_LL_CACHE : bits(16) = 0x0032 + +let PMU_EVENT_LL_CACHE_MISS : bits(16) = 0x0033 + +let PMU_EVENT_DTLB_WALK : bits(16) = 0x0034 + +let PMU_EVENT_L1D_CACHE_LMISS_RD : bits(16) = 0x0039 + +let PMU_EVENT_L2D_CACHE_RD : bits(16) = 0x0050 + +let PMU_EVENT_SAMPLE_POP : bits(16) = 0x4000 + +let PMU_EVENT_SAMPLE_FEED : bits(16) = 0x4001 + +let PMU_EVENT_SAMPLE_FILTRATE : bits(16) = 0x4002 + +let PMU_EVENT_SAMPLE_COLLISION : bits(16) = 0x4003 + +let PMU_EVENT_L2D_CACHE_LMISS_RD : bits(16) = 0x4009 + +let PMU_EVENT_LDST_ALIGN_LAT : bits(16) = 0x4020 + +let PMU_EVENT_SVE_PRED_EMPTY_SPEC : bits(16) = 0x8075 + +let PMU_EVENT_SVE_PRED_PARTIAL_SPEC : bits(16) = 0x8077 + +let PMU_EVENT_BRB_FILTRATE : bits(16) = 0x811F + +let PMU_EVENT_SAMPLE_WRAP : bits(16) = 0x8123 + +let PMU_EVENT_SAMPLE_FEED_BR : bits(16) = 0x812A + +let PMU_EVENT_SAMPLE_FEED_LD : bits(16) = 0x812B + +let PMU_EVENT_SAMPLE_FEED_ST : bits(16) = 0x812C + +let PMU_EVENT_SAMPLE_FEED_OP : bits(16) = 0x812D + +let PMU_EVENT_SAMPLE_FEED_EVENT : bits(16) = 0x812E + +let PMU_EVENT_SAMPLE_FEED_LAT : bits(16) = 0x812F + +let PMU_EVENT_DSNP_HIT_RD : bits(16) = 0x8194 + +let PMU_EVENT_L1D_CACHE_HITM_RD : bits(16) = 0x8214 + +let PMU_EVENT_L2D_CACHE_HITM_RD : bits(16) = 0x8215 + +let PMU_EVENT_L3D_CACHE_HITM_RD : bits(16) = 0x8216 + +let PMU_EVENT_LL_CACHE_HITM_RD : bits(16) = 0x8217 + +let PMU_EVENT_L1D_LFB_HIT_RD : bits(16) = 0x8244 + +let PMU_EVENT_L2D_LFB_HIT_RD : bits(16) = 0x8245 + +let PMU_EVENT_L3D_LFB_HIT_RD : bits(16) = 0x8246 + +let PMU_EVENT_LL_LFB_HIT_RD : bits(16) = 0x8247 + +enum SecurityState = {SS_NonSecure, SS_Root, SS_Realm, SS_Secure} + +let M32_User : bits(5) = 0b10000 + +let M32_FIQ : bits(5) = 0b10001 + +let M32_IRQ : bits(5) = 0b10010 + +let M32_Svc : bits(5) = 0b10011 + +let M32_Monitor : bits(5) = 0b10110 + +let M32_Abort : bits(5) = 0b10111 + +let M32_Hyp : bits(5) = 0b11010 + +let M32_Undef : bits(5) = 0b11011 + +let M32_System : bits(5) = 0b11111 + +let EL3 : bits(2) = 0b11 + +let EL2 : bits(2) = 0b10 + +let EL1 : bits(2) = 0b01 + +let EL0 : bits(2) = 0b00 + +struct ProcState = { + N : bits(1), + Z : bits(1), + C : bits(1), + V : bits(1), + D : bits(1), + A : bits(1), + I : bits(1), + F : bits(1), + EXLOCK : bits(1), + PAN : bits(1), + UAO : bits(1), + DIT : bits(1), + TCO : bits(1), + PM : bits(1), + PPEND : bits(1), + BTYPE : bits(2), + ZA : bits(1), + SM : bits(1), + ALLINT : bits(1), + SS : bits(1), + IL : bits(1), + EL : bits(2), + nRW : bits(1), + SP : bits(1), + Q : bits(1), + GE : bits(4), + SSBS : bits(1), + IT : bits(8), + J : bits(1), + T : bits(1), + E : bits(1), + M : bits(5) +} + +register PSTATE : ProcState + +register ShouldAdvanceIT : bool + +register ShouldAdvanceSS : bool + +enum PrivilegeLevel = {PL3, PL2, PL1, PL0} + +enum InstrSet = {InstrSet_A64, InstrSet_A32, InstrSet_T32} + +enum DSBAlias = {DSBAlias_SSBB, DSBAlias_PSSBB, DSBAlias_DSB} + +enum WFxType = {WFxType_WFE, WFxType_WFI, WFxType_WFET, WFxType_WFIT} + +register EventRegister : bits(1) + +enum ExceptionalOccurrenceTargetState = { + AArch32_NonDebugState, + AArch64_NonDebugState, + DebugState +} + +type PARTIDtype = bits(16) + +val __UNKNOWN_PARTIDtype : unit -> bits(16) + +function __UNKNOWN_PARTIDtype () = undefined + +type PMGtype = bits(8) + +val __UNKNOWN_PMGtype : unit -> bits(8) + +function __UNKNOWN_PMGtype () = undefined + +enum PARTIDspaceType = { + PIdSpace_Secure, + PIdSpace_Root, + PIdSpace_Realm, + PIdSpace_NonSecure +} + +struct MPAMinfo = { + mpam_sp : PARTIDspaceType, + partid : PARTIDtype, + pmg : PMGtype +} + +enum AccessType = { + AccessType_IFETCH, + AccessType_GPR, + AccessType_ASIMD, + AccessType_SVE, + AccessType_SME, + AccessType_IC, + AccessType_DC, + AccessType_DCZero, + AccessType_AT, + AccessType_NV2, + AccessType_SPE, + AccessType_GCS, + AccessType_GPTW, + AccessType_TTW +} + +enum MemOp = {MemOp_LOAD, MemOp_STORE, MemOp_PREFETCH} + +enum VARange = {VARange_LOWER, VARange_UPPER} + +val __UNKNOWN_VARange : unit -> VARange + +function __UNKNOWN_VARange () = undefined + +enum MemAtomicOp = { + MemAtomicOp_GCSSS1, + MemAtomicOp_ADD, + MemAtomicOp_BIC, + MemAtomicOp_EOR, + MemAtomicOp_ORR, + MemAtomicOp_SMAX, + MemAtomicOp_SMIN, + MemAtomicOp_UMAX, + MemAtomicOp_UMIN, + MemAtomicOp_SWP, + MemAtomicOp_CAS +} + +enum CacheOp = {CacheOp_Clean, CacheOp_Invalidate, CacheOp_CleanInvalidate} + +enum CacheOpScope = { + CacheOpScope_SetWay, + CacheOpScope_PoU, + CacheOpScope_PoC, + CacheOpScope_PoE, + CacheOpScope_PoP, + CacheOpScope_PoDP, + CacheOpScope_PoPA, + CacheOpScope_ALLU, + CacheOpScope_ALLUIS +} + +enum CacheType = { + CacheType_Data, + CacheType_Tag, + CacheType_Data_Tag, + CacheType_Instruction +} + +enum CachePASpace = { + CPAS_NonSecure, + CPAS_Any, + CPAS_RealmNonSecure, + CPAS_Realm, + CPAS_Root, + CPAS_SecureNonSecure, + CPAS_Secure +} + +struct AccessDescriptor = { + acctype : AccessType, + el : bits(2), + ss : SecurityState, + acqsc : bool, + acqpc : bool, + relsc : bool, + limitedordered : bool, + exclusive : bool, + atomicop : bool, + modop : MemAtomicOp, + nontemporal : bool, + read : bool, + write : bool, + cacheop : CacheOp, + opscope : CacheOpScope, + cachetype : CacheType, + pan : bool, + transactional : bool, + nonfault : bool, + firstfault : bool, + first : bool, + contiguous : bool, + streamingsve : bool, + ls64 : bool, + mops : bool, + rcw : bool, + rcws : bool, + toplevel : bool, + varange : VARange, + a32lsmd : bool, + tagchecked : bool, + tagaccess : bool, + mpam : MPAMinfo +} + +val __UNKNOWN_AccessDescriptor : unit -> AccessDescriptor + +function __UNKNOWN_AccessDescriptor () = undefined + +enum MemType = {MemType_Normal, MemType_Device} + +enum DeviceType = { + DeviceType_GRE, + DeviceType_nGRE, + DeviceType_nGnRE, + DeviceType_nGnRnE +} + +struct MemAttrHints = {attrs : bits(2), hints : bits(2), transient : bool} + +let LOG2_TAG_GRANULE : int(4) = 4 + +let MemAttr_NC : bits(2) = 0b00 + +let MemAttr_WT : bits(2) = 0b10 + +let MemAttr_WB : bits(2) = 0b11 + +let MemHint_No : bits(2) = 0b00 + +let MemHint_WA : bits(2) = 0b01 + +let MemHint_RA : bits(2) = 0b10 + +let MemHint_RWA : bits(2) = 0b11 + +enum Shareability = {Shareability_NSH, Shareability_ISH, Shareability_OSH} + +val __UNKNOWN_Shareability : unit -> Shareability + +function __UNKNOWN_Shareability () = undefined + +enum MemTagType = { + MemTag_Untagged, + MemTag_AllocationTagged, + MemTag_CanonicallyTagged +} + +struct MemoryAttributes = { + memtype : MemType, + device : DeviceType, + inner : MemAttrHints, + outer : MemAttrHints, + shareability : Shareability, + tags : MemTagType, + notagaccess : bool, + xs : bits(1) +} + +val __UNKNOWN_MemoryAttributes : unit -> MemoryAttributes + +function __UNKNOWN_MemoryAttributes () = undefined + +enum PASpace = {PAS_NonSecure, PAS_Secure, PAS_Root, PAS_Realm} + +val __UNKNOWN_PASpace : unit -> PASpace + +function __UNKNOWN_PASpace () = undefined + +struct FullAddress = {paspace : PASpace, address : bits(56)} + +val __UNKNOWN_FullAddress : unit -> FullAddress + +function __UNKNOWN_FullAddress () = undefined + +enum GPCF = {GPCF_None, GPCF_AddressSize, GPCF_Walk, GPCF_EABT, GPCF_Fail} + +struct GPCFRecord = {gpf : GPCF, level : int} + +enum Fault = { + Fault_None, + Fault_AccessFlag, + Fault_Alignment, + Fault_Background, + Fault_Domain, + Fault_Permission, + Fault_Translation, + Fault_AddressSize, + Fault_SyncExternal, + Fault_SyncExternalOnWalk, + Fault_SyncParity, + Fault_SyncParityOnWalk, + Fault_GPCFOnWalk, + Fault_GPCFOnOutput, + Fault_AsyncParity, + Fault_AsyncExternal, + Fault_TagCheck, + Fault_Debug, + Fault_TLBConflict, + Fault_BranchTarget, + Fault_HWUpdateAccessFlag, + Fault_Lockdown, + Fault_Exclusive, + Fault_ICacheMaint +} + +enum ErrorState = { + ErrorState_UC, + ErrorState_UEU, + ErrorState_UEO, + ErrorState_UER, + ErrorState_CE, + ErrorState_Uncategorized, + ErrorState_IMPDEF +} + +struct FaultRecord = { + statuscode : Fault, + access : AccessDescriptor, + ipaddress : FullAddress, + gpcf : GPCFRecord, + paddress : FullAddress, + gpcfs2walk : bool, + s2fs1walk : bool, + write : bool, + s1tagnotdata : bool, + tagaccess : bool, + level : int, + extflag : bits(1), + secondstage : bool, + assuredonly : bool, + toplevel : bool, + overlay : bool, + dirtybit : bool, + domain : bits(4), + merrorstate : ErrorState, + debugmoe : bits(4) +} + +val __UNKNOWN_FaultRecord : unit -> FaultRecord + +function __UNKNOWN_FaultRecord () = undefined + +struct PhysMemRetStatus = { + statuscode : Fault, + extflag : bits(1), + merrorstate : ErrorState, + store64bstatus : bits(64) +} + +val __UNKNOWN_PhysMemRetStatus : unit -> PhysMemRetStatus + +function __UNKNOWN_PhysMemRetStatus () = undefined + +struct Permissions = { + ap_table : bits(2), + xn_table : bits(1), + pxn_table : bits(1), + uxn_table : bits(1), + ap : bits(3), + xn : bits(1), + uxn : bits(1), + pxn : bits(1), + ppi : bits(4), + upi : bits(4), + ndirty : bits(1), + s2pi : bits(4), + s2dirty : bits(1), + po_index : bits(4), + s2po_index : bits(4), + s2ap : bits(2), + s2tag_na : bits(1), + s2xnx : bits(1), + s2xn : bits(1) +} + +struct S1AccessControls = { + r : bits(1), + w : bits(1), + x : bits(1), + gcs : bits(1), + overlay : bool, + or : bits(1), + ow : bits(1), + ox : bits(1), + wxn : bits(1) +} + +struct S2AccessControls = { + r : bits(1), + w : bits(1), + x : bits(1), + r_rcw : bits(1), + w_rcw : bits(1), + r_mmu : bits(1), + w_mmu : bits(1), + toplevel0 : bits(1), + toplevel1 : bits(1), + overlay : bool, + or : bits(1), + ow : bits(1), + ox : bits(1), + or_rcw : bits(1), + ow_rcw : bits(1), + or_mmu : bits(1), + ow_mmu : bits(1) +} + +enum MBReqDomain = { + MBReqDomain_Nonshareable, + MBReqDomain_InnerShareable, + MBReqDomain_OuterShareable, + MBReqDomain_FullSystem +} + +enum MBReqTypes = {MBReqTypes_Reads, MBReqTypes_Writes, MBReqTypes_All} + +enum PrefetchHint = {Prefetch_READ, Prefetch_WRITE, Prefetch_EXEC} + +enum Unpredictable = { + Unpredictable_VMSR, + Unpredictable_WBOVERLAPLD, + Unpredictable_WBOVERLAPST, + Unpredictable_LDPOVERLAP, + Unpredictable_BASEOVERLAP, + Unpredictable_DATAOVERLAP, + Unpredictable_DEVPAGE2, + Unpredictable_INSTRDEVICE, + Unpredictable_RESCPACR, + Unpredictable_RESMAIR, + Unpredictable_S1CTAGGED, + Unpredictable_S2RESMEMATTR, + Unpredictable_RESTEXCB, + Unpredictable_RESPRRR, + Unpredictable_RESDACR, + Unpredictable_RESVTCRS, + Unpredictable_RESTnSZ, + Unpredictable_RESTCF, + Unpredictable_DEVICETAGSTORE, + Unpredictable_OORTnSZ, + Unpredictable_LARGEIPA, + Unpredictable_ESRCONDPASS, + Unpredictable_ILZEROIT, + Unpredictable_ILZEROT, + Unpredictable_BPVECTORCATCHPRI, + Unpredictable_VCMATCHHALF, + Unpredictable_VCMATCHDAPA, + Unpredictable_WPMASKANDBAS, + Unpredictable_WPBASCONTIGUOUS, + Unpredictable_RESWPMASK, + Unpredictable_WPMASKEDBITS, + Unpredictable_RESBPWPCTRL, + Unpredictable_BPNOTIMPL, + Unpredictable_RESBPTYPE, + Unpredictable_RESMDSELR, + Unpredictable_BPNOTCTXCMP, + Unpredictable_BPMATCHHALF, + Unpredictable_BPMISMATCHHALF, + Unpredictable_BPLINKINGDISABLED, + Unpredictable_RESBPMASK, + Unpredictable_BPMASK, + Unpredictable_BPMASKEDBITS, + Unpredictable_BPLINKEDADDRMATCH, + Unpredictable_RESTARTALIGNPC, + Unpredictable_RESTARTZEROUPPERPC, + Unpredictable_ZEROUPPER, + Unpredictable_ERETZEROUPPERPC, + Unpredictable_A32FORCEALIGNPC, + Unpredictable_SMD, + Unpredictable_NONFAULT, + Unpredictable_SVEZEROUPPER, + Unpredictable_SVELDNFDATA, + Unpredictable_SVELDNFZERO, + Unpredictable_CHECKSPNONEACTIVE, + Unpredictable_SMEZEROUPPER, + Unpredictable_NVNV1, + Unpredictable_Shareability, + Unpredictable_AFUPDATE, + Unpredictable_DBUPDATE, + Unpredictable_IESBinDebug, + Unpredictable_BADPMSFCR, + Unpredictable_ZEROBTYPE, + Unpredictable_EL2TIMESTAMP, + Unpredictable_EL1TIMESTAMP, + Unpredictable_RESERVEDNSxB, + Unpredictable_WFxTDEBUG, + Unpredictable_LS64UNSUPPORTED, + Unpredictable_MISALIGNEDATOMIC, + Unpredictable_CLEARERRITEZERO, + Unpredictable_ALUEXCEPTIONRETURN, + Unpredictable_IGNORETRAPINDEBUG, + Unpredictable_DBGxVR_RESS, + Unpredictable_PMUEVENTCOUNTER, + Unpredictable_PMSCR_PCT, + Unpredictable_CounterReservedForEL2, + Unpredictable_BRBFILTRATE, + Unpredictable_MOPSOVERLAP31, + Unpredictable_STOREONLYTAGCHECKEDCAS, + Unpredictable_RESTC +} + +enum Constraint = { + Constraint_NONE, + Constraint_UNKNOWN, + Constraint_UNDEF, + Constraint_UNDEFEL0, + Constraint_NOP, + Constraint_TRUE, + Constraint_FALSE, + Constraint_DISABLED, + Constraint_UNCOND, + Constraint_COND, + Constraint_ADDITIONAL_DECODE, + Constraint_WBSUPPRESS, + Constraint_FAULT, + Constraint_LIMITED_ATOMICITY, + Constraint_NVNV1_00, + Constraint_NVNV1_01, + Constraint_NVNV1_11, + Constraint_EL1TIMESTAMP, + Constraint_EL2TIMESTAMP, + Constraint_OSH, + Constraint_ISH, + Constraint_NSH, + Constraint_NC, + Constraint_WT, + Constraint_WB, + Constraint_FORCE, + Constraint_FORCENOSLCHECK, + Constraint_MAPTOALLOCATED, + Constraint_PMSCR_PCT_VIRT +} + +val __UNKNOWN_Constraint : unit -> Constraint + +function __UNKNOWN_Constraint () = undefined + +struct CacheRecord = { + acctype : AccessType, + cacheop : CacheOp, + opscope : CacheOpScope, + cachetype : CacheType, + regval : bits(64), + paddress : FullAddress, + vaddress : bits(64), + setnum : int, + waynum : int, + level : int, + shareability : Shareability, + translated : bool, + is_vmid_valid : bool, + vmid : bits(16), + is_asid_valid : bool, + asid : bits(16), + security : SecurityState, + cpas : CachePASpace +} + +enum RestrictType = { + RestrictType_DataValue, + RestrictType_ControlFlow, + RestrictType_CachePrefetch, + RestrictType_Other +} + +struct ExecutionCntxt = { + is_vmid_valid : bool, + all_vmid : bool, + vmid : bits(16), + is_asid_valid : bool, + all_asid : bool, + asid : bits(16), + target_el : bits(2), + security : SecurityState, + restriction : RestrictType +} + +enum FPExc = { + FPExc_InvalidOp, + FPExc_DivideByZero, + FPExc_Overflow, + FPExc_Underflow, + FPExc_Inexact, + FPExc_InputDenorm +} + +enum FPRounding = { + FPRounding_TIEEVEN, + FPRounding_POSINF, + FPRounding_NEGINF, + FPRounding_ZERO, + FPRounding_TIEAWAY, + FPRounding_ODD +} + +enum FPType = { + FPType_Zero, + FPType_Denormal, + FPType_Nonzero, + FPType_Infinity, + FPType_QNaN, + FPType_SNaN +} + +/* register _R : vector(31, inc, bits(64)) */ + +register R0 : bits(64) +register R1 : bits(64) +register R2 : bits(64) +register R3 : bits(64) +register R4 : bits(64) +register R5 : bits(64) +register R6 : bits(64) +register R7 : bits(64) +register R8 : bits(64) +register R9 : bits(64) +register R10 : bits(64) +register R11 : bits(64) +register R12 : bits(64) +register R13 : bits(64) +register R14 : bits(64) +register R15 : bits(64) +register R16 : bits(64) +register R17 : bits(64) +register R18 : bits(64) +register R19 : bits(64) +register R20 : bits(64) +register R21 : bits(64) +register R22 : bits(64) +register R23 : bits(64) +register R24 : bits(64) +register R25 : bits(64) +register R26 : bits(64) +register R27 : bits(64) +register R28 : bits(64) +register R29 : bits(64) +register R30 : bits(64) + +val read_gpr : forall 'n, 0 <= 'n <= 30. int('n) -> bits(64) effect {rreg} + +function read_gpr(n) = { + match n { + 0 => R0, + 1 => R1, + 2 => R2, + 3 => R3, + 4 => R4, + 5 => R5, + 6 => R6, + 7 => R7, + 8 => R8, + 9 => R9, + 10 => R10, + 11 => R11, + 12 => R12, + 13 => R13, + 14 => R14, + 15 => R15, + 16 => R16, + 17 => R17, + 18 => R18, + 19 => R19, + 20 => R20, + 21 => R21, + 22 => R22, + 23 => R23, + 24 => R24, + 25 => R25, + 26 => R26, + 27 => R27, + 28 => R28, + 29 => R29, + _ => R30 + } +} + +val write_gpr_bits : forall 'n 'lo 'hi, 0 <= 'n <= 30 & 0 <= 'lo <= 'hi <= 63. + (int('n), int('hi), int('lo), bits(('hi - 'lo) + 1)) -> unit effect {wreg} + +function write_gpr_bits(n, hi, lo, v) = { + match n { + 0 => R0[hi .. lo] = v, + 1 => R1[hi .. lo] = v, + 2 => R2[hi .. lo] = v, + 3 => R3[hi .. lo] = v, + 4 => R4[hi .. lo] = v, + 5 => R5[hi .. lo] = v, + 6 => R6[hi .. lo] = v, + 7 => R7[hi .. lo] = v, + 8 => R8[hi .. lo] = v, + 9 => R9[hi .. lo] = v, + 10 => R10[hi .. lo] = v, + 11 => R11[hi .. lo] = v, + 12 => R12[hi .. lo] = v, + 13 => R13[hi .. lo] = v, + 14 => R14[hi .. lo] = v, + 15 => R15[hi .. lo] = v, + 16 => R16[hi .. lo] = v, + 17 => R17[hi .. lo] = v, + 18 => R18[hi .. lo] = v, + 19 => R19[hi .. lo] = v, + 20 => R20[hi .. lo] = v, + 21 => R21[hi .. lo] = v, + 22 => R22[hi .. lo] = v, + 23 => R23[hi .. lo] = v, + 24 => R24[hi .. lo] = v, + 25 => R25[hi .. lo] = v, + 26 => R26[hi .. lo] = v, + 27 => R27[hi .. lo] = v, + 28 => R28[hi .. lo] = v, + 29 => R29[hi .. lo] = v, + _ => R30[hi .. lo] = v + } +} + +val write_gpr : forall 'n, 0 <= 'n <= 30. (int('n), bits(64)) -> unit effect {wreg} + +function write_gpr(n, v) = { + match n { + 0 => R0 = v, + 1 => R1 = v, + 2 => R2 = v, + 3 => R3 = v, + 4 => R4 = v, + 5 => R5 = v, + 6 => R6 = v, + 7 => R7 = v, + 8 => R8 = v, + 9 => R9 = v, + 10 => R10 = v, + 11 => R11 = v, + 12 => R12 = v, + 13 => R13 = v, + 14 => R14 = v, + 15 => R15 = v, + 16 => R16 = v, + 17 => R17 = v, + 18 => R18 = v, + 19 => R19 = v, + 20 => R20 = v, + 21 => R21 = v, + 22 => R22 = v, + 23 => R23 = v, + 24 => R24 = v, + 25 => R25 = v, + 26 => R26 = v, + 27 => R27 = v, + 28 => R28 = v, + 29 => R29 = v, + _ => R30 = v + } +} + +$ifdef SYMBOLIC +let GPRs : vector(31, dec, register(bits(64))) = [ + ref R30, + ref R29, + ref R28, + ref R27, + ref R26, + ref R25, + ref R24, + ref R23, + ref R22, + ref R21, + ref R20, + ref R19, + ref R18, + ref R17, + ref R16, + ref R15, + ref R14, + ref R13, + ref R12, + ref R11, + ref R10, + ref R9, + ref R8, + ref R7, + ref R6, + ref R5, + ref R4, + ref R3, + ref R2, + ref R1, + ref R0 +] + +register __isla_vector_gpr: bool = false + +val read_gpr_from_vector = monadic "read_register_from_vector" : forall 'n, 0 <= 'n <= 30. (int('n), vector(31, dec, register(bits(64)))) -> bits(64) + +val get_R : forall 'n, 0 <= 'n <= 30. int('n) -> bits(64) effect {rreg} + +function get_R(n) = if __isla_vector_gpr then read_gpr_from_vector(n, GPRs) else read_gpr(n) + +val write_gpr_from_vector = monadic "write_register_from_vector" : forall 'n, 0 <= 'n <= 30. (int('n), bits(64), vector(31, dec, register(bits(64)))) -> unit + +val set_R_bits : forall 'n 'lo 'hi, 0 <= 'n <= 30 & 0 <= 'lo <= 'hi <= 63. + (int('n), int('hi), int('lo), bits(('hi - 'lo) + 1)) -> unit effect {wreg} + +function set_R_bits(n, hi, lo, v) = { + if __isla_vector_gpr then { + let all_bits = read_gpr_from_vector(n, GPRs); + write_gpr_from_vector(n, SetSlice((hi - lo) + 1, all_bits, lo, v), GPRs) + } else { + write_gpr_bits(n, hi, lo, v) + } +} + +val set_R : forall 'n, 0 <= 'n <= 30. (int('n), bits(64)) -> unit effect {wreg} + +function set_R(n, v) = { + if __isla_vector_gpr then write_gpr_from_vector(n, v, GPRs) else write_gpr(n, v) +} +$else +val get_R : forall 'n, 0 <= 'n <= 30. int('n) -> bits(64) effect {rreg} + +function get_R(n) = read_gpr(n) + +val set_R : forall 'n, 0 <= 'n <= 30. (int('n), bits(64)) -> unit effect {wreg} + +function set_R(n, v) = write_gpr(n, v) + +val set_R_bits : forall 'n 'lo 'hi, 0 <= 'n <= 30 & 0 <= 'lo <= 'hi <= 63. + (int('n), int('hi), int('lo), bits(('hi - 'lo) + 1)) -> unit effect {wreg} + +function set_R_bits(n, hi, lo, v) = { + write_gpr_bits(n, hi, lo, v) +} +$endif + +overload _R = {get_R, set_R, set_R_bits} + +val register_ref : forall 'n, 0 <= 'n <= 30. int('n) -> register(bits(64)) + +function register_ref(n) = { + match n { + 0 => ref R0, + 1 => ref R1, + 2 => ref R2, + 3 => ref R3, + 4 => ref R4, + 5 => ref R5, + 6 => ref R6, + 7 => ref R7, + 8 => ref R8, + 9 => ref R9, + 10 => ref R10, + 11 => ref R11, + 12 => ref R12, + 13 => ref R13, + 14 => ref R14, + 15 => ref R15, + 16 => ref R16, + 17 => ref R17, + 18 => ref R18, + 19 => ref R19, + 20 => ref R20, + 21 => ref R21, + 22 => ref R22, + 23 => ref R23, + 24 => ref R24, + 25 => ref R25, + 26 => ref R26, + 27 => ref R27, + 28 => ref R28, + 29 => ref R29, + _ => ref R30 + } +} + +val ignore_data_dependency : forall 'n, 0 <= 'n <= 31. int('n) -> unit + +function ignore_data_dependency(n) = { + if n <= 30 then { + sail_ignore_write_to(register_ref(n)) + } +} + +val ignore_dependency_edge : forall 'n 'm, 0 <= 'n <= 31 & 0 <= 'm <= 31. (int('n), int('m)) -> unit + +function ignore_dependency_edge(n, m) = { + if n <= 30 & m <= 30 then { + sail_mark_register_pair(register_ref(n), register_ref(m), "ignore_edge") + } +} + +register _PC : bits(64) + +enum BranchType = { + BranchType_DIRCALL, + BranchType_INDCALL, + BranchType_ERET, + BranchType_DBGEXIT, + BranchType_RET, + BranchType_DIR, + BranchType_INDIR, + BranchType_EXCEPTION, + BranchType_TMFAIL, + BranchType_RESET, + BranchType_UNKNOWN +} + +register PhysicalCount : bits(88) + +enum InterruptID = { + InterruptID_PMUIRQ, + InterruptID_COMMIRQ, + InterruptID_CTIIRQ, + InterruptID_COMMRX, + InterruptID_COMMTX, + InterruptID_CNTP, + InterruptID_CNTHP, + InterruptID_CNTHPS, + InterruptID_CNTPS, + InterruptID_CNTV, + InterruptID_CNTHV, + InterruptID_CNTHVS, + InterruptID_PMBIRQ +} + +let DefaultPARTID : PARTIDtype = 0[15 .. 0] + +let DefaultPMG : PMGtype = 0[7 .. 0] + +enum Exception = { + Exception_Uncategorized, + Exception_WFxTrap, + Exception_CP15RTTrap, + Exception_CP15RRTTrap, + Exception_CP14RTTrap, + Exception_CP14DTTrap, + Exception_CP14RRTTrap, + Exception_AdvSIMDFPAccessTrap, + Exception_FPIDTrap, + Exception_LDST64BTrap, + Exception_PACTrap, + Exception_IllegalState, + Exception_SupervisorCall, + Exception_HypervisorCall, + Exception_MonitorCall, + Exception_SystemRegisterTrap, + Exception_ERetTrap, + Exception_InstructionAbort, + Exception_PCAlignment, + Exception_DataAbort, + Exception_NV2DataAbort, + Exception_PACFail, + Exception_SPAlignment, + Exception_FPTrappedException, + Exception_SError, + Exception_Breakpoint, + Exception_SoftwareStep, + Exception_Watchpoint, + Exception_NV2Watchpoint, + Exception_SoftwareBreakpoint, + Exception_VectorCatch, + Exception_IRQ, + Exception_SVEAccessTrap, + Exception_SMEAccessTrap, + Exception_TSTARTAccessTrap, + Exception_GPC, + Exception_BranchTarget, + Exception_MemCpyMemSet, + Exception_GCSFail, + Exception_SystemRegister128Trap, + Exception_FIQ +} + +struct ExceptionRecord = { + exceptype : Exception, + syndrome : bits(25), + syndrome2 : bits(24), + paddress : FullAddress, + vaddress : bits(64), + ipavalid : bool, + pavalid : bool, + NS : bits(1), + ipaddress : bits(56), + trappedsyscallinst : bool +} + +enum TranslationStage = {TranslationStage_1, TranslationStage_12} + +enum ATAccess = { + ATAccess_Read, + ATAccess_Write, + ATAccess_ReadPAN, + ATAccess_WritePAN +} + +enum Regime = {Regime_EL3, Regime_EL30, Regime_EL2, Regime_EL20, Regime_EL10} + +enum TGx = {TGx_4KB, TGx_16KB, TGx_64KB} + +enum DescriptorType = { + DescriptorType_Table, + DescriptorType_Leaf, + DescriptorType_Invalid +} + +let Domain_NoAccess : bits(2) = 0b00 + +let Domain_Client : bits(2) = 0b01 + +enum SDFType = { + SDFType_Table, + SDFType_Invalid, + SDFType_Supersection, + SDFType_Section, + SDFType_LargePage, + SDFType_SmallPage +} + +val __UNKNOWN_SDFType : unit -> SDFType + +function __UNKNOWN_SDFType () = undefined + +struct TTWState = { + istable : bool, + level : int, + baseaddress : FullAddress, + contiguous : bits(1), + s1assured : bool, + s2assuredonly : bits(1), + disch : bits(1), + nG : bits(1), + guardedpage : bits(1), + sdftype : SDFType, + domain : bits(4), + memattrs : MemoryAttributes, + permissions : Permissions +} + +val __UNKNOWN_TTWState : unit -> TTWState + +function __UNKNOWN_TTWState () = undefined + +struct S1TTWParams = { + ha : bits(1), + hd : bits(1), + tbi : bits(1), + tbid : bits(1), + nfd : bits(1), + e0pd : bits(1), + d128 : bits(1), + aie : bits(1), + mair2 : MAIRType, + ds : bits(1), + ps : bits(3), + txsz : bits(6), + epan : bits(1), + dct : bits(1), + nv1 : bits(1), + cmow : bits(1), + pnch : bits(1), + disch : bits(1), + haft : bits(1), + mtx : bits(1), + skl : bits(2), + pie : bits(1), + pir : S1PIRType, + pire0 : S1PIRType, + emec : bits(1), + amec : bits(1), + t0sz : bits(3), + t1sz : bits(3), + uwxn : bits(1), + tgx : TGx, + irgn : bits(2), + orgn : bits(2), + sh : bits(2), + hpd : bits(1), + ee : bits(1), + wxn : bits(1), + ntlsmd : bits(1), + dc : bits(1), + sif : bits(1), + mair : MAIRType +} + +struct S2TTWParams = { + ha : bits(1), + hd : bits(1), + sl2 : bits(1), + ds : bits(1), + d128 : bits(1), + sw : bits(1), + nsw : bits(1), + sa : bits(1), + nsa : bits(1), + ps : bits(3), + txsz : bits(6), + fwb : bits(1), + cmow : bits(1), + skl : bits(2), + s2pie : bits(1), + s2pir : S2PIRType, + tl0 : bits(1), + tl1 : bits(1), + assuredonly : bits(1), + haft : bits(1), + emec : bits(1), + s : bits(1), + t0sz : bits(4), + tgx : TGx, + sl0 : bits(2), + irgn : bits(2), + orgn : bits(2), + sh : bits(2), + ee : bits(1), + ptw : bits(1), + vm : bits(1) +} + +struct TLBContext = { + ss : SecurityState, + regime : Regime, + vmid : bits(16), + asid : bits(16), + nG : bits(1), + ipaspace : PASpace, + includes_s1_name : bool, + includes_s2_name : bool, + includes_gpt_name : bool, + ia : bits(64), + tg : TGx, + cnp : bits(1), + level : int, + isd128 : bool, + xs : bits(1) +} + +struct TLBRecord = { + context : TLBContext, + walkstate : TTWState, + blocksize : int, + contigsize : int, + s1descriptor : bits(128), + s2descriptor : bits(128) +} + +struct AddressDescriptor = { + fault : FaultRecord, + memattrs : MemoryAttributes, + paddress : FullAddress, + tlbcontext : TLBContext, + s1assured : bool, + s2fs1mro : bool, + mecid : bits(16), + vaddress : bits(64) +} + +val __UNKNOWN_AddressDescriptor : unit -> AddressDescriptor + +function __UNKNOWN_AddressDescriptor () = undefined + +struct TranslationInfo = { + regime : Regime, + vmid : option(bits(16)), + asid : option(bits(16)), + va : bits(64), + s1level : option(int), + s2info : option((bits(64), int)), + s1params : option(S1TTWParams), + s2params : option(S2TTWParams), + memattrs : MemoryAttributes +} + +struct TranslationStartInfo = { + ss : SecurityState, + regime : Regime, + vmid : bits(16), + asid : bits(16), + va : bits(64), + cnp : bits(1), + accdesc : AccessDescriptor, + size : int +} + +val start_translation : TranslationStartInfo -> unit + +val end_translation : AddressDescriptor -> unit + +let FINAL_LEVEL : int(3) = 3 + +register RC : vector(5, bits(64)) + +register InGuardedPage : bool + +register BTypeNext : bits(2) + +register BTypeCompatible : bool + +enum SVECmp = {Cmp_EQ, Cmp_NE, Cmp_GE, Cmp_GT, Cmp_LT, Cmp_LE, Cmp_UN} + +let MAX_VL : int(2048) = 2048 + +type MAX_VL : Int = 2048 + +let MAX_PL : int(256) = 256 + +type MAX_PL : Int = 256 + +let ZT0_LEN : int(512) = 512 + +register _Z : vector(32, bits(MAX_VL)) + +register _P : vector(16, bits(MAX_PL)) + +register _FFR : bits(MAX_PL) + +enum SMEExceptionType = { + SMEExceptionType_AccessTrap, + SMEExceptionType_Streaming, + SMEExceptionType_NotStreaming, + SMEExceptionType_InactiveZA, + SMEExceptionType_InaccessibleZT0 +} + +register _ZA : vector(256, bits(MAX_VL)) + +register _ZT0 : bits(512) + +enum GCSInstruction = { + GCSInstType_PRET, + GCSInstType_POPM, + GCSInstType_PRETAA, + GCSInstType_PRETAB, + GCSInstType_SS1, + GCSInstType_SS2, + GCSInstType_POPCX, + GCSInstType_POPX +} + +enum MOPSStage = {MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue} + +let DEFAULT_MECID : bits(16) = Zeros(16) + +bitfield FPCR_Type : bits(64) = + { + AHP : 26..26, + DN : 25..25, + FZ : 24..24, + RMode : 23..22, + Stride : 21..20, + FZ16 : 19..19, + length : 18..16, + IDE : 15..15, + EBF : 13..13, + IXE : 12..12, + UFE : 11..11, + OFE : 10..10, + DZE : 9..9, + IOE : 8..8, + NEP : 2..2, + AH : 1..1, + FIZ : 0..0 + } + +register FPCR : FPCR_Type + +bitfield FPSR_Type : bits(64) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + QC : 27..27, + IDC : 7..7, + IXC : 4..4, + UFC : 3..3, + OFC : 2..2, + DZC : 1..1, + IOC : 0..0 + } + +register FPSR : FPSR_Type + +bitfield ICC_PMR_EL1_Type : bits(64) = {Priority : 7..0} + +register ICC_PMR_EL1 : ICC_PMR_EL1_Type + +struct TMState = { + depth : int, + Rt : int, + nPC : bits(64), + X : vector(31, bits(64)), + Z : vector(32, bits(MAX_VL)), + P : vector(16, bits(MAX_PL)), + FFR : bits(MAX_PL), + SP : bits(64), + FPCR : bits(64), + FPSR : bits(64), + ICC_PMR_EL1 : bits(64), + GCSPR_ELx : bits(64), + nzcv : bits(4), + D : bits(1), + A : bits(1), + I : bits(1), + F : bits(1) +} + +register TSTATE : TMState + +enum TMFailure = { + TMFailure_CNCL, + TMFailure_DBG, + TMFailure_ERR, + TMFailure_NEST, + TMFailure_SIZE, + TMFailure_MEM, + TMFailure_TRIVIAL, + TMFailure_IMP +} + +enum PGSe = {PGS_4KB, PGS_16KB, PGS_64KB} + +let GPT_NoAccess : bits(4) = 0b0000 + +let GPT_Table : bits(4) = 0b0011 + +let GPT_Block : bits(4) = 0b0001 + +let GPT_Contig : bits(4) = 0b0001 + +let GPT_Secure : bits(4) = 0b1000 + +let GPT_NonSecure : bits(4) = 0b1001 + +let GPT_Root : bits(4) = 0b1010 + +let GPT_Realm : bits(4) = 0b1011 + +let GPT_Any : bits(4) = 0b1111 + +let GPTRange_4KB : int(12) = 12 + +let GPTRange_16KB : int(14) = 14 + +let GPTRange_64KB : int(16) = 16 + +let GPTRange_2MB : int(21) = 21 + +let GPTRange_32MB : int(25) = 25 + +let GPTRange_512MB : int(29) = 29 + +let GPTRange_1GB : int(30) = 30 + +let GPTRange_16GB : int(34) = 34 + +let GPTRange_64GB : int(36) = 36 + +let GPTRange_512GB : int(39) = 39 + +struct GPTTable = {address : bits(56)} + +val __UNKNOWN_GPTTable : unit -> GPTTable + +function __UNKNOWN_GPTTable () = undefined + +struct GPTEntry = { + gpi : bits(4), + size : int, + contig_size : int, + level : int, + pa : bits(56) +} + +val __UNKNOWN_GPTEntry : unit -> GPTEntry + +function __UNKNOWN_GPTEntry () = undefined + +let SPEMaxAddrs : int(32) = 32 + +let SPEMaxCounters : int(32) = 32 + +let SPEMaxRecordSize : int(64) = 64 + +enum TimeStamp = { + TimeStamp_None, + TimeStamp_CoreSight, + TimeStamp_Physical, + TimeStamp_OffsetPhysical, + TimeStamp_Virtual +} + +enum OpType = { + OpType_Load, + OpType_Store, + OpType_LoadAtomic, + OpType_Branch, + OpType_Other +} + +let SPEAddrPosPCVirtual : int(0) = 0 + +let SPEAddrPosBranchTarget : int(1) = 1 + +let SPEAddrPosDataVirtual : int(2) = 2 + +let SPEAddrPosDataPhysical : int(3) = 3 + +let SPEAddrPosPrevBranchTarget : int(4) = 4 + +let SPECounterPosTotalLatency : int(0) = 0 + +let SPECounterPosIssueLatency : int(1) = 1 + +let SPECounterPosTranslationLatency : int(2) = 2 + +register SPESampleInFlight : bool + +register SPESampleContextEL1 : bits(32) + +register SPESampleContextEL1Valid : bool + +register SPESampleContextEL2 : bits(32) + +register SPESampleContextEL2Valid : bool + +register SPESampleInstIsNV2 : bool + +register SPESamplePreviousBranchAddress : bits(64) + +register SPESamplePreviousBranchAddressValid : bool + +register SPESampleDataSource : bits(16) + +register SPESampleDataSourceValid : bool + +register SPESampleOpType : OpType + +register SPESampleClass : bits(2) + +register SPESampleSubclass : bits(8) + +register SPESampleSubclassValid : bool + +register SPESampleTimestamp : bits(64) + +register SPESampleTimestampValid : bool + +register SPESampleEvents : bits(64) + +register __SPE_LFSR : bits(24) + +register __SPE_LFSR_initialized : bool + +register SPERecordSize : int + +register __last_cycle_count : int + +register __last_branch_valid : bool + +enum CountOp = {CountOp_CLZ, CountOp_CLS, CountOp_CNT} + +enum ExtendType = { + ExtendType_SXTB, + ExtendType_SXTH, + ExtendType_SXTW, + ExtendType_SXTX, + ExtendType_UXTB, + ExtendType_UXTH, + ExtendType_UXTW, + ExtendType_UXTX +} + +enum FPMaxMinOp = { + FPMaxMinOp_MAX, + FPMaxMinOp_MIN, + FPMaxMinOp_MAXNUM, + FPMaxMinOp_MINNUM +} + +enum FPUnaryOp = {FPUnaryOp_ABS, FPUnaryOp_MOV, FPUnaryOp_NEG, FPUnaryOp_SQRT} + +enum FPConvOp = { + FPConvOp_CVT_FtoI, + FPConvOp_CVT_ItoF, + FPConvOp_MOV_FtoI, + FPConvOp_MOV_ItoF, + FPConvOp_CVT_FtoI_JS +} + +enum MoveWideOp = {MoveWideOp_N, MoveWideOp_Z, MoveWideOp_K} + +enum ShiftType = {ShiftType_LSL, ShiftType_LSR, ShiftType_ASR, ShiftType_ROR} + +enum LogicalOp = {LogicalOp_AND, LogicalOp_EOR, LogicalOp_ORR} + +enum SystemHintOp = { + SystemHintOp_NOP, + SystemHintOp_YIELD, + SystemHintOp_WFE, + SystemHintOp_WFI, + SystemHintOp_SEV, + SystemHintOp_SEVL, + SystemHintOp_DGH, + SystemHintOp_ESB, + SystemHintOp_PSB, + SystemHintOp_TSB, + SystemHintOp_BTI, + SystemHintOp_WFET, + SystemHintOp_WFIT, + SystemHintOp_CLRBHB, + SystemHintOp_GCSB, + SystemHintOp_CHKFEAT, + SystemHintOp_CSDB +} + +enum PSTATEField = { + PSTATEField_DAIFSet, + PSTATEField_DAIFClr, + PSTATEField_PAN, + PSTATEField_UAO, + PSTATEField_DIT, + PSTATEField_SSBS, + PSTATEField_TCO, + PSTATEField_SVCRSM, + PSTATEField_SVCRZA, + PSTATEField_SVCRSMZA, + PSTATEField_ALLINT, + PSTATEField_PM, + PSTATEField_SP +} + +let VMID_NONE : bits(16) = Zeros(16) + +enum TLBILevel = {TLBILevel_Any, TLBILevel_Last} + +enum TLBIOp = { + TLBIOp_DALL, + TLBIOp_DASID, + TLBIOp_DVA, + TLBIOp_IALL, + TLBIOp_IASID, + TLBIOp_IVA, + TLBIOp_ALL, + TLBIOp_ASID, + TLBIOp_IPAS2, + TLBIPOp_IPAS2, + TLBIOp_VAA, + TLBIOp_VA, + TLBIPOp_VAA, + TLBIPOp_VA, + TLBIOp_VMALL, + TLBIOp_VMALLS12, + TLBIOp_RIPAS2, + TLBIPOp_RIPAS2, + TLBIOp_RVAA, + TLBIOp_RVA, + TLBIPOp_RVAA, + TLBIPOp_RVA, + TLBIOp_RPA, + TLBIOp_PAALL +} + +enum TLBIMemAttr = {TLBI_AllAttr, TLBI_ExcludeXS} + +struct TLBIRecord = { + op : TLBIOp, + from_aarch64 : bool, + security : SecurityState, + regime : Regime, + vmid : bits(16), + asid : bits(16), + level : TLBILevel, + attr : TLBIMemAttr, + ipaspace : PASpace, + address : bits(64), + end_address_name : bits(64), + d64 : bool, + d128 : bool, + ttl : bits(4), + tg : bits(2) +} + +let MAX_ZERO_BLOCK_SIZE : int(2048) = 2048 + +enum VBitOp = {VBitOp_VBIF, VBitOp_VBIT, VBitOp_VBSL, VBitOp_VEOR} + +enum CompareOp = { + CompareOp_GT, + CompareOp_GE, + CompareOp_EQ, + CompareOp_LE, + CompareOp_LT +} + +enum ImmediateOp = { + ImmediateOp_MOVI, + ImmediateOp_MVNI, + ImmediateOp_ORR, + ImmediateOp_BIC +} + +enum ReduceOp = { + ReduceOp_FMINNUM, + ReduceOp_FMAXNUM, + ReduceOp_FMIN, + ReduceOp_FMAX, + ReduceOp_FADD, + ReduceOp_ADD +} + +register DBGEN : Signal + +register NIDEN : Signal + +register SPIDEN : Signal + +register SPNIDEN : Signal + +register RLPIDEN : Signal + +register RTPIDEN : Signal + +enum CrossTriggerIn = { + CrossTriggerIn_CrossHalt, + CrossTriggerIn_PMUOverflow, + CrossTriggerIn_RSVD2, + CrossTriggerIn_RSVD3, + CrossTriggerIn_TraceExtOut0, + CrossTriggerIn_TraceExtOut1, + CrossTriggerIn_TraceExtOut2, + CrossTriggerIn_TraceExtOut3 +} + +let DebugHalt_Breakpoint : bits(6) = 0b000111 + +let DebugHalt_EDBGRQ : bits(6) = 0b010011 + +let DebugHalt_Step_Normal : bits(6) = 0b011011 + +let DebugHalt_Step_Exclusive : bits(6) = 0b011111 + +let DebugHalt_OSUnlockCatch : bits(6) = 0b100011 + +let DebugHalt_ResetCatch : bits(6) = 0b100111 + +let DebugHalt_Watchpoint : bits(6) = 0b101011 + +let DebugHalt_HaltInstruction : bits(6) = 0b101111 + +let DebugHalt_SoftwareAccess : bits(6) = 0b110011 + +let DebugHalt_ExceptionCatch : bits(6) = 0b110111 + +let DebugHalt_Step_NoSyndrome : bits(6) = 0b111011 + +struct TLBLine = {tlbrecord : TLBRecord, valid_name : bool} + +val __UNKNOWN_TLBLine : unit -> TLBLine + +function __UNKNOWN_TLBLine () = undefined + +struct GPTTLBLine = {gpt_entry : GPTEntry, valid_name : bool} + +val __UNKNOWN_GPTTLBLine : unit -> GPTTLBLine + +function __UNKNOWN_GPTTLBLine () = undefined + +let RCW64_PROTECTED_BIT : int(52) = 52 + +let RCW128_PROTECTED_BIT : int(114) = 114 + +register __InstructionStep : bool + +struct InterruptReq = { + take_SE : bool, + take_vSE : bool, + take_IRQ : bool, + take_vIRQ : bool, + take_FIQ : bool, + take_vFIQ : bool, + iesb_req : bool +} + +register __CNTReadBase : bits(56) + +register __CNTBaseN : bits(56) + +register __CNTEL0BaseN : bits(56) + +register __CNTCTLBase : bits(56) + +register __RD_base : bits(56) + +register __SGI_base : bits(56) + +register __VLPI_base : bits(56) + +register __ETEBase : bits(56) + +enum __InstrEnc = {__A64, __A32, __T16, __T32} + +register __ThisInstr : bits(32) + +register __ThisInstrEnc : __InstrEnc + +register __currentCond : bits(4) + +register Branchtypetaken : BranchType + +register __BranchTaken : bool + +register __ExclusiveMonitorSet : bool + +let lst_64bv : bits(2) = 0b01 + +let lst_64b : bits(2) = 0b10 + +let lst_64bv0 : bits(2) = 0b11 + +register __highest_el_aarch32 : bool + +register __ICACHE_CCSIDR_RESET : vector(7, bits(64)) + +register __DCACHE_CCSIDR_RESET : vector(7, bits(64)) + +let CFG_ID_AA64PFR0_EL1_EL0 : bits(4) = 0b0010 + +let CFG_ID_AA64PFR0_EL1_EL1 : bits(4) = 0b0001 + +let CFG_ID_AA64PFR0_EL1_EL2 : bits(4) = 0b0001 + +let CFG_ID_AA64PFR0_EL1_EL3 : bits(4) = 0b0001 + +let CFG_PMCR_IDCODE : bits(8) = 0b00000000 + +let CFG_MPAM_none : bits(4) = 0b0000 + +let CFG_MPAM_v0p1 : bits(4) = 0b0000 + +let CFG_MPAM_v1p1 : bits(4) = 0b0001 + +let CFG_MPAM_frac_none : bits(4) = 0b0000 + +let CFG_MPAM_frac_v0p1 : bits(4) = 0b0001 + +let CFG_MPAM_frac_v1p1 : bits(4) = 0b0001 + +register sp_rel_access_pc : bits(64) + +enum SRType = {SRType_LSL, SRType_LSR, SRType_ASR, SRType_ROR, SRType_RRX} + +enum VCGEType = {VCGEType_signed, VCGEType_unsigned, VCGEType_fp} + +enum VFPNegMul = {VFPNegMul_VNMLA, VFPNegMul_VNMLS, VFPNegMul_VNMUL} + +enum VCGTtype = {VCGTtype_signed, VCGTtype_unsigned, VCGTtype_fp} + +enum VBitOps = {VBitOps_VBIF, VBitOps_VBIT, VBitOps_VBSL} + +register SP_mon : bits(32) + +register LR_mon : bits(32) + +register _Dclone : vector(32, bits(64)) + +let DebugException_Breakpoint : bits(4) = 0b0001 + +let DebugException_BKPT : bits(4) = 0b0011 + +let DebugException_VectorCatch : bits(4) = 0b0101 + +let DebugException_Watchpoint : bits(4) = 0b1010 + +bitfield HCR_EL2_Type : bits(64) = + { + TWEDEL : 63..60, + TWEDEn : 59..59, + TID5 : 58..58, + DCT : 57..57, + ATA : 56..56, + TTLBOS : 55..55, + TTLBIS : 54..54, + EnSCXT : 53..53, + TOCU : 52..52, + AMVOFFEN : 51..51, + TICAB : 50..50, + TID4 : 49..49, + GPF : 48..48, + FIEN : 47..47, + FWB : 46..46, + NV2 : 45..45, + AT : 44..44, + NV1 : 43..43, + NV : 42..42, + API : 41..41, + APK : 40..40, + TME : 39..39, + MIOCNCE : 38..38, + TEA : 37..37, + TERR : 36..36, + TLOR : 35..35, + E2H : 34..34, + ID : 33..33, + CD : 32..32, + RW : 31..31, + TRVM : 30..30, + HCD : 29..29, + TDZ : 28..28, + TGE : 27..27, + TVM : 26..26, + TTLB : 25..25, + TPU : 24..24, + TPCP : 23..23, + TPC : 23..23, + TSW : 22..22, + TACR : 21..21, + TIDCP : 20..20, + TSC : 19..19, + TID3 : 18..18, + TID2 : 17..17, + TID1 : 16..16, + TID0 : 15..15, + TWE : 14..14, + TWI : 13..13, + DC : 12..12, + BSU : 11..10, + FB : 9..9, + VSE : 8..8, + VI : 7..7, + VF : 6..6, + AMO : 5..5, + IMO : 4..4, + FMO : 3..3, + PTW : 2..2, + SWIO : 1..1, + VM : 0..0 + } + +register HCR_EL2 : HCR_EL2_Type + +val HaveAArch32EL : bits(2) -> bool + +val HaveAArch64 : unit -> bool + +function HaveAArch64 () = { + return(((IsFeatureImplemented(FEAT_AA64EL0) | IsFeatureImplemented(FEAT_AA64EL1)) | IsFeatureImplemented(FEAT_AA64EL2)) | IsFeatureImplemented(FEAT_AA64EL3)) +} + +val HaveEL : bits(2) -> bool + +val HaveSecureEL2Ext : unit -> bool + +function HaveSecureEL2Ext () = { + return(IsFeatureImplemented(FEAT_SEL2)) +} + +val HaveVirtHostExt : unit -> bool + +function HaveVirtHostExt () = { + return(IsFeatureImplemented(FEAT_VHE)) +} + +bitfield SCR_EL3_Type : bits(64) = + { + NSE : 62..62, + FGTEn2 : 59..59, + EnIDCP128 : 55..55, + PFAREn : 53..53, + TWERR : 52..52, + TMEA : 51..51, + MECEn : 49..49, + GPF : 48..48, + D128En : 47..47, + AIEn : 46..46, + PIEn : 45..45, + SCTLR2En : 44..44, + TCR2En : 43..43, + RCWMASKEn : 42..42, + EnTP2 : 41..41, + TRNDR : 40..40, + GCSEn : 39..39, + HXEn : 38..38, + ADEn : 37..37, + EnAS0 : 36..36, + AMVOFFEN : 35..35, + TME : 34..34, + TWEDEL : 33..30, + TWEDEn : 29..29, + ECVEn : 28..28, + FGTEn : 27..27, + ATA : 26..26, + EnSCXT : 25..25, + FIEN : 21..21, + NMEA : 20..20, + EASE : 19..19, + EEL2 : 18..18, + API : 17..17, + APK : 16..16, + TERR : 15..15, + TLOR : 14..14, + TWE : 13..13, + TWI : 12..12, + ST : 11..11, + RW : 10..10, + SIF : 9..9, + HCE : 8..8, + SMD : 7..7, + EA : 3..3, + FIQ : 2..2, + IRQ : 1..1, + NS : 0..0 + } + +register SCR_EL3 : SCR_EL3_Type + +val ELStateUsingAArch32K : forall ('secure : Bool). + (bits(2), bool('secure)) -> (bool, bool) + +function ELStateUsingAArch32K (el, secure) = { + if not_bool(HaveAArch32EL(el)) then { + return((true, false)) + } else if secure & el == EL2 then { + return((true, false)) + } else if not_bool(HaveAArch64()) then { + return((true, true)) + } else (); + aarch32 : bool = __UNKNOWN_boolean(); + known : bool = true; + let aarch32_below_el3 : bool = (HaveEL(EL3) & ((not_bool(secure) | not_bool(HaveSecureEL2Ext())) | SCR_EL3[EEL2] == 0b0)) & SCR_EL3[RW] == 0b0; + let aarch32_at_el1 : bool = aarch32_below_el3 | ((HaveEL(EL2) & (not_bool(secure) | HaveSecureEL2Ext() & SCR_EL3[EEL2] == 0b1)) & not_bool(HaveVirtHostExt() & (HCR_EL2[E2H] @ HCR_EL2[TGE]) == 0b11)) & HCR_EL2[RW] == 0b0; + if el == EL0 & not_bool(aarch32_at_el1) then { + if PSTATE.EL == EL0 then { + aarch32 = PSTATE.nRW == 0b1 + } else { + known = false + } + } else { + aarch32 = aarch32_below_el3 & el != EL3 | aarch32_at_el1 & (el == EL1 | el == EL0) + }; + if not_bool(known) then { + aarch32 = __UNKNOWN_boolean() + }; + return((known, aarch32)) +} + +val ELStateUsingAArch32 : forall ('secure : Bool). + (bits(2), bool('secure)) -> bool + +function ELStateUsingAArch32 (el, secure) = { + aarch32 : bool = undefined; + known : bool = undefined; + (known, aarch32) = ELStateUsingAArch32K(el, secure); + assert(known); + return(aarch32) +} + +bitfield SCR_Type : bits(32) = + { + TERR : 15..15, + TWE : 13..13, + TWI : 12..12, + SIF : 9..9, + HCE : 8..8, + SCD : 7..7, + nET : 6..6, + AW : 5..5, + FW : 4..4, + EA : 3..3, + FIQ : 2..2, + IRQ : 1..1, + NS : 0..0 + } + +register SCR : SCR_Type + +val SCR_GEN_read : unit -> SCRType + +function SCR_GEN_read () = { + assert(HaveEL(EL3)); + r : bits(64) = undefined; + if not_bool(HaveAArch64()) then { + r = ZeroExtend(SCR.bits, 64) + } else { + r = SCR_EL3.bits + }; + return(Mk_SCRType(r)) +} + +val HasArchVersion : ArchVersion -> bool + +val HaveStatisticalProfilingv1p2 : unit -> bool + +function HaveStatisticalProfilingv1p2 () = { + return(IsFeatureImplemented(FEAT_SPEv1p2)) +} + +val HighestEL : unit -> bits(2) + +function HighestEL () = { + if HaveEL(EL3) then { + return(EL3) + } else if HaveEL(EL2) then { + return(EL2) + } else { + return(EL1) + } +} + +register __apply_effective_shareability : bool = true + +register __cpy_mops_option_a_supported : bool = true + +register __cpyf_mops_option_a_supported : bool = true + +register __empam_force_ns_RAO : bool = false + +register __empam_force_ns_implemented : bool = false + +register __empam_sdeflt_implemented : bool = false + +register __empam_tidr_implemented : bool = false + +register __feat_rpres : bool = true + +register __has_sme_priority_control : bool = true + +register __isb_is_branch : bool = true + +register __mpam_frac : bits(4) = CFG_MPAM_frac_none + +register __mpam_major : bits(4) = CFG_MPAM_none + +register __mte_implemented : bits(4) = 0b0010 + +register __set_mops_option_a_supported : bool = true + +register __setg_mops_option_a_supported : bool = true + +register __sme_only : bool = false + +val ELUsingAArch32 : bits(2) -> bool + +val IsSecureBelowEL3 : unit -> bool + +function ELUsingAArch32 el = { + return(ELStateUsingAArch32(el, IsSecureBelowEL3())) +} + +function IsSecureBelowEL3 () = { + if HaveEL(EL3) then { + return(SCR_GEN_read()[NS] == 0b0) + } else if HaveEL(EL2) & (not_bool(HaveSecureEL2Ext()) | not_bool(HaveAArch64())) then { + return(false) + } else { + return(__IMPDEF_boolean("Secure-only implementation")) + } +} + +val __get_FPCR : FPCR_Type -> FPCR_Type + +function __get_FPCR value_name = { + tmp : FPCR_Type = value_name; + tmp : FPCR_Type = Mk_FPCR_Type(tmp.bits & not_vec(0xfffffffff80040f8)); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Invalid Operation floating-point exceptions")) then { + tmp = Mk_FPCR_Type(tmp.bits & not_vec(ZeroExtend(0x100, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Divide by Zero floating-point exceptions")) then { + tmp = Mk_FPCR_Type(tmp.bits & not_vec(ZeroExtend(0x200, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Overflow floating-point exceptions")) then { + tmp = Mk_FPCR_Type(tmp.bits & not_vec(ZeroExtend(0x400, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Underflow floating-point exceptions")) then { + tmp = Mk_FPCR_Type(tmp.bits & not_vec(ZeroExtend(0x800, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Inexact floating-point exceptions")) then { + tmp = Mk_FPCR_Type(tmp.bits & not_vec(ZeroExtend(0x1000, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Input Denormal floating-point exceptions")) then { + tmp = Mk_FPCR_Type(tmp.bits & not_vec(ZeroExtend(0x8000, 64))) + }; + if __IMPDEF_boolean("IMPLEMENTED_FPSCR.LEN,STRIDE as RAZ") then { + tmp = Mk_FPCR_Type(tmp.bits & not_vec(ZeroExtend(0x370000, 64))) + }; + return(tmp) +} + +val FPCR_read : unit -> FPCRType + +function FPCR_read () = { + let r : bits(64) = __get_FPCR(FPCR).bits; + return(Mk_FPCRType(r)) +} + +bitfield FPSCR_Type : bits(32) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + QC : 27..27, + AHP : 26..26, + DN : 25..25, + FZ : 24..24, + RMode : 23..22, + Stride : 21..20, + FZ16 : 19..19, + length : 18..16, + IDE : 15..15, + IXE : 12..12, + UFE : 11..11, + OFE : 10..10, + DZE : 9..9, + IOE : 8..8, + IDC : 7..7, + IXC : 4..4, + UFC : 3..3, + OFC : 2..2, + DZC : 1..1, + IOC : 0..0 + } + +register _FPSCR : FPSCR_Type + +val __get_FPSCR : FPSCR_Type -> FPSCR_Type + +function __get_FPSCR value_name = { + tmp : FPSCR_Type = value_name; + tmp : FPSCR_Type = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x6060, 32))); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Invalid Operation floating-point exceptions")) then { + tmp = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x100, 32))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Divide by Zero floating-point exceptions")) then { + tmp = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x200, 32))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Overflow floating-point exceptions")) then { + tmp = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x400, 32))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Underflow floating-point exceptions")) then { + tmp = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x800, 32))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Inexact floating-point exceptions")) then { + tmp = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x1000, 32))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Input Denormal floating-point exceptions")) then { + tmp = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x8000, 32))) + }; + if __IMPDEF_boolean("IMPLEMENTED_FPSCR.LEN,STRIDE as RAZ") then { + tmp = Mk_FPSCR_Type(tmp.bits & not_vec(ZeroExtend(0x370000, 32))) + }; + return(tmp) +} + +val FPSCR_read : unit -> FPCRType + +val FPSCR_read__1 : unit -> FPSCR_Type + +function FPSCR_read__1 () = { + r : FPSCR_Type = _FPSCR; + r.bits[31 .. 27] = Slice(FPSR.bits, 27, 5); + r.bits[7] = Bit(Slice(FPSR.bits, 7, 1)); + r.bits[4 .. 0] = Slice(FPSR.bits, 0, 5); + r.bits[26 .. 15] = Slice(FPCR.bits, 15, 12); + r.bits[12 .. 8] = Slice(FPCR.bits, 8, 5); + return(r) +} + +function FPSCR_read () = { + let r : bits(64) = Zeros(32) @ __get_FPSCR(FPSCR_read__1()).bits; + return(Mk_FPCRType(r)) +} + +register RVBAR : bits(32) + +bitfield ERRnFR_ElemType : bits(64) = + { + CE : 54..53, + DE : 52..52, + UEO : 51..51, + UER : 50..50, + UEU : 49..49, + UC : 48..48, + FRX : 31..31, + TS : 25..24, + CI : 23..22, + INJ : 21..20, + CEO : 19..18, + DUI : 17..16, + RP : 15..15, + CEC : 14..12, + CFI : 11..10, + UE : 9..8, + FI : 7..6, + UI : 5..4, + ED : 1..0 + } + +register ERRnFR : vector(4, ERRnFR_ElemType) + +val SPMEVCNTR_EL0_read : forall 'n 's. (int('s), int('n)) -> bits(64) + +val SPMEVCNTR_EL0_set : forall 'n 's. (int('s), int('n), bits(64)) -> unit + +val SPMEVTYPER_EL0_read : forall 'n 's. (int('s), int('n)) -> bits(64) + +val SPMEVTYPER_EL0_set : forall 'n 's. (int('s), int('n), bits(64)) -> unit + +val SPMEVFILTR_EL0_read : forall 'n 's. (int('s), int('n)) -> bits(64) + +val SPMEVFILTR_EL0_set : forall 'n 's. (int('s), int('n), bits(64)) -> unit + +val SPMEVFILT2R_EL0_read : forall 'n 's. (int('s), int('n)) -> bits(64) + +val SPMEVFILT2R_EL0_set : forall 'n 's. (int('s), int('n), bits(64)) -> unit + +val SPMOVSCLR_EL0_read : forall 's. int('s) -> bits(64) + +val SPMOVSCLR_EL0_set : forall 's. (int('s), bits(64)) -> unit + +val SPMCFGR_EL1_read : forall 's. int('s) -> bits(64) + +val SPMCGCR_EL1_read : forall 's. int('s) -> bits(64) + +val SPMCNTENCLR_EL0_read : forall 's. int('s) -> bits(64) + +val SPMCNTENCLR_EL0_set : forall 's. (int('s), bits(64)) -> unit + +val SPMCNTENSET_EL0_read : forall 's. int('s) -> bits(64) + +val SPMCNTENSET_EL0_set : forall 's. (int('s), bits(64)) -> unit + +val SPMCR_EL0_read : forall 's. int('s) -> bits(64) + +val SPMCR_EL0_set : forall 's. (int('s), bits(64)) -> unit + +val SPMDEVAFF_EL1_read : forall 's. int('s) -> bits(64) + +val SPMDEVARCH_EL1_read : forall 's. int('s) -> bits(64) + +val SPMIIDR_EL1_read : forall 's. int('s) -> bits(64) + +val SPMINTENCLR_EL1_read : forall 's. int('s) -> bits(64) + +val SPMINTENCLR_EL1_set : forall 's. (int('s), bits(64)) -> unit + +val SPMINTENSET_EL1_read : forall 's. int('s) -> bits(64) + +val SPMINTENSET_EL1_set : forall 's. (int('s), bits(64)) -> unit + +val SPMOVSSET_EL0_read : forall 's. int('s) -> bits(64) + +val SPMOVSSET_EL0_set : forall 's. (int('s), bits(64)) -> unit + +val SPMROOTCR_EL3_read : forall 's. int('s) -> bits(64) + +val SPMROOTCR_EL3_set : forall 's. (int('s), bits(64)) -> unit + +val SPMSCR_EL1_read : forall 's. int('s) -> bits(64) + +val SPMSCR_EL1_set : forall 's. (int('s), bits(64)) -> unit + +val getISR : unit -> bits(32) + +val genRandomNum : forall ('isRNDRRS : Bool). bool('isRNDRRS) -> bits(64) + +val getCacheID : forall ('data_cache : Bool) 'level. + (int('level), bool('data_cache)) -> bits(64) + +val CacheConfigRead : bits(4) -> bits(64) + +val AArch64_SysRegRead : forall 'crm 'crn 'op0 'op1 'op2 't. + (int('op0), int('op1), int('crn), int('crm), int('op2), int('t)) -> unit + +val AArch64_SysRegWrite : forall 'crm 'crn 'op0 'op1 'op2 't. + (int('op0), int('op1), int('crn), int('crm), int('op2), int('t)) -> unit + +val AArch64_SysInstr : forall 'crm 'crn 'op0 'op1 'op2 't. + (int('op0), int('op1), int('crn), int('crm), int('op2), int('t)) -> unit + +val AArch64_SysInstrWithResult : forall 'crm 'crn 'op0 'op1 'op2 't. + (int('op0), int('op1), int('crn), int('crm), int('op2), int('t)) -> unit + +val AArch64_UnallocatedSysRegAccess : forall ('read : Bool) 't. + (bits(2), bits(3), bits(4), bits(3), bits(4), bool('read), int('t)) -> unit + +val AArch64_SysRegRead128 : forall 'crm 'crn 'op0 'op1 'op2 't 't2. + (int('op0), int('op1), int('crn), int('crm), int('op2), int('t), int('t2)) -> unit + +val AArch64_SysRegWrite128 : forall 'crm 'crn 'op0 'op1 'op2 't 't2. + (int('op0), int('op1), int('crn), int('crm), int('op2), int('t), int('t2)) -> unit + +val AArch64_SysInstr128 : forall 'crm 'crn 'op0 'op1 'op2 't 't2. + (int('op0), int('op1), int('crn), int('crm), int('op2), int('t), int('t2)) -> unit + +val AArch32_SysRegRead : forall 'cp_num. + (int('cp_num), bits(32), bits(32)) -> unit + +val AArch32_SysRegRead__1 : forall 'cp_num 't. + (int('cp_num), bits(32), int('t)) -> unit + +val AArch32_SysRegWriteM : forall 'cp_num. + (int('cp_num), bits(32), bits(32)) -> unit + +val AArch32_SysRegRead64 : forall 'cp_num 't 't2. + (int('cp_num), bits(32), int('t), int('t2)) -> unit + +val AArch32_SysRegWrite : forall 'cp_num 't. + (int('cp_num), bits(32), int('t)) -> unit + +val AArch32_SysRegWrite64 : forall 'cp_num 't 't2. + (int('cp_num), bits(32), int('t), int('t2)) -> unit + +val GetNreg : unit -> int + +val AArch32_UnallocatedSysRegAccess : forall ('read : Bool) 't. + (bits(4), bits(3), bits(4), bits(3), bits(4), bool('read), int('t)) -> unit + +val AArch64_ImpDefSysRegRead : forall 't. + (bits(2), bits(3), bits(4), bits(4), bits(3), int('t)) -> unit + +val AArch64_ImpDefSysRegWrite : forall 't. + (bits(2), bits(3), bits(4), bits(4), bits(3), int('t)) -> unit + +val AArch64_ImpDefSysRegRead128 : forall 't 't2. + (bits(2), bits(3), bits(4), bits(4), bits(3), int('t), int('t2)) -> unit + +val AArch64_ImpDefSysRegWrite128 : forall 't 't2. + (bits(2), bits(3), bits(4), bits(4), bits(3), int('t), int('t2)) -> unit + +val AArch64_ImpDefSysInstr128 : forall 'el 't 't2. + (int('el), bits(3), bits(4), bits(4), bits(3), int('t), int('t2)) -> unit + +val VirtualIRQPending : unit -> bool + +val VirtualFIQPending : unit -> bool + +val IsPhysicalSErrorPending : unit -> bool + +val ClearPendingPhysicalSError : unit -> unit + +val FIQPending : unit -> (bool, bool) + +val IRQPending : unit -> (bool, bool) + +bitfield CTR_EL0_Type : bits(64) = + { + TminLine : 37..32, + DIC : 29..29, + IDC : 28..28, + CWG : 27..24, + ERG : 23..20, + DminLine : 19..16, + L1Ip : 15..14, + IminLine : 3..0 + } + +register CTR_EL0 : CTR_EL0_Type + +register __block_bbm_implemented : int = UInt(0x2) + +register __has_sve_extended_bf16 : int = 2 + +register __max_implemented_smeveclen : int = 512 + +register __max_implemented_sveveclen : int = 2048 + +register __supported_pa_size : int = 56 + +val getNumBreakpoints : unit -> int + +val getNumCtxBreakpoints : unit -> int + +val getNumWatchpoints : unit -> int + +val GetNumEventCounters : unit -> int + +function GetNumEventCounters () = { + return(__IMPDEF_integer("Number of event counters")) +} + +val ConstrainUnpredictableInteger : forall 'high 'low. + (int('low), int('high), Unpredictable) -> (Constraint, int) + +val SecureOnlyImplementation : unit -> bool + +function SecureOnlyImplementation () = { + return(__IMPDEF_boolean("Secure-only implementation")) +} + +val IsSecureEL2Enabled : unit -> bool + +function IsSecureEL2Enabled () = { + if HaveEL(EL2) & HaveSecureEL2Ext() then { + if HaveEL(EL3) then { + if not_bool(ELUsingAArch32(EL3)) & SCR_EL3[EEL2] == 0b1 then { + return(true) + } else { + return(false) + } + } else { + return(SecureOnlyImplementation()) + } + } else { + return(false) + } +} + +val EL2Enabled : unit -> bool + +function EL2Enabled () = { + return(HaveEL(EL2) & ((not_bool(HaveEL(EL3)) | SCR_GEN_read()[NS] == 0b1) | IsSecureEL2Enabled())) +} + +bitfield HDCR_Type : bits(32) = + { + HPMFZO : 29..29, + MTPME : 28..28, + TDCC : 27..27, + HLP : 26..26, + HCCD : 23..23, + TTRF : 19..19, + HPMD : 17..17, + TDRA : 11..11, + TDOSA : 10..10, + TDA : 9..9, + TDE : 8..8, + HPME : 7..7, + TPM : 6..6, + TPMCR : 5..5, + HPMN : 4..0 + } + +bitfield MDCR_EL2_Type : bits(64) = + { + EBWE : 43..43, + PMEE : 41..40, + HPMFZS : 36..36, + PMSSE : 31..30, + HPMFZO : 29..29, + MTPME : 28..28, + TDCC : 27..27, + HLP : 26..26, + HCCD : 23..23, + TTRF : 19..19, + HPMD : 17..17, + EnSPM : 15..15, + TPMS : 14..14, + E2PB : 13..12, + TDRA : 11..11, + TDOSA : 10..10, + TDA : 9..9, + TDE : 8..8, + HPME : 7..7, + TPM : 6..6, + TPMCR : 5..5, + HPMN : 4..0 + } + +register MDCR_EL2 : MDCR_EL2_Type + +register _HDCR : HDCR_Type + +val HDCR_read : unit -> HDCR_Type + +function HDCR_read () = { + r : HDCR_Type = _HDCR; + r.bits[31 .. 0] = Slice(MDCR_EL2.bits, 0, 32); + return(r) +} + +val HaveFeatHPMN0 : unit -> bool + +function HaveFeatHPMN0 () = { + return(IsFeatureImplemented(FEAT_HPMN0)) +} + +val AArch32_GetNumEventCountersAccessible : unit -> int + +function AArch32_GetNumEventCountersAccessible () = { + n : int = undefined; + let 'total_counters = GetNumEventCounters(); + if (PSTATE.EL == EL1 | PSTATE.EL == EL0) & EL2Enabled() then { + n = UInt(if not_bool(ELUsingAArch32(EL2)) then MDCR_EL2[HPMN] else + HDCR_read()[HPMN]); + if n > total_counters | not_bool(HaveFeatHPMN0()) & n == 0 then { + let (_, __tup_1 : int) = ConstrainUnpredictableInteger(0, total_counters, Unpredictable_PMUEVENTCOUNTER); + n = __tup_1 + }; + () + } else { + n = total_counters + }; + let 'n = n; + return(n) +} + +val AArch64_GetNumEventCountersAccessible : unit -> int + +function AArch64_GetNumEventCountersAccessible () = { + n : int = undefined; + let 'total_counters = GetNumEventCounters(); + if (PSTATE.EL == EL1 | PSTATE.EL == EL0) & EL2Enabled() then { + n = UInt(MDCR_EL2[HPMN]); + if n > total_counters | not_bool(HaveFeatHPMN0()) & n == 0 then { + let (_, __tup_1 : int) = ConstrainUnpredictableInteger(0, total_counters, Unpredictable_PMUEVENTCOUNTER); + n = __tup_1 + }; + () + } else { + n = total_counters + }; + let 'n = n; + return(n) +} + +val HavePMUv3ICNTR : unit -> bool + +function HavePMUv3ICNTR () = { + return(IsFeatureImplemented(FEAT_PMUv3_ICNTR)) +} + +val HaveAArch32 : unit -> bool + +val UsingAArch32 : unit -> bool + +function UsingAArch32 () = { + let aarch32 : bool = PSTATE.nRW == 0b1; + if not_bool(HaveAArch32()) then { + assert(not_bool(aarch32)) + }; + if not_bool(HaveAArch64()) then { + assert(aarch32) + }; + return(aarch32) +} + +val PMUCounterMask : unit -> bits(64) + +function PMUCounterMask () = { + n : int = undefined; + if UsingAArch32() then { + n = AArch32_GetNumEventCountersAccessible() + } else { + n = AArch64_GetNumEventCountersAccessible() + }; + let 'n = n; + assert(constraint('n >= 0)); + assert(constraint(64 >= 'n)); + mask : bits(64) = ZeroExtend(Ones(n), 64); + mask[CYCLE_COUNTER_ID] = Bit(0b1); + if HaveAArch64() & HavePMUv3ICNTR() then { + mask[INSTRUCTION_COUNTER_ID] = Bit(0b1) + }; + return(mask) +} + +val HavePMUv3 : unit -> bool + +function HavePMUv3 () = { + return(IsFeatureImplemented(FEAT_PMUv3)) +} + +val HaveRME : unit -> bool + +function HaveRME () = { + return(IsFeatureImplemented(FEAT_RME)) +} + +val HaveSecureState : unit -> bool + +function HaveSecureState () = { + if not_bool(HaveEL(EL3)) then { + return(SecureOnlyImplementation()) + }; + if HaveRME() & not_bool(HaveSecureEL2Ext()) then { + return(false) + }; + return(true) +} + +val EffectiveSCR_EL3_NS : unit -> bits(1) + +function EffectiveSCR_EL3_NS () = { + if not_bool(HaveSecureState()) then { + return(0b1) + } else if not_bool(HaveEL(EL3)) then { + return(0b0) + } else { + return(SCR_EL3[NS]) + } +} + +val Unreachable : unit -> unit + +function Unreachable () = { + assert(false) +} + +val SecurityStateAtEL : bits(2) -> SecurityState + +function SecurityStateAtEL EL = { + effective_nse_ns : bits(2) = undefined; + if HaveRME() then { + if EL == EL3 then { + return(SS_Root) + }; + let effective_nse_ns : bits(2) = SCR_EL3[NSE] @ EffectiveSCR_EL3_NS(); + match effective_nse_ns { + 0b00 => { + if HaveSecureEL2Ext() then { + return(SS_Secure) + } else { + Unreachable() + } + }, + 0b01 => { + return(SS_NonSecure) + }, + 0b11 => { + return(SS_Realm) + }, + _ => { + Unreachable() + } + } + }; + if not_bool(HaveEL(EL3)) then { + if SecureOnlyImplementation() then { + return(SS_Secure) + } else { + return(SS_NonSecure) + } + } else if EL == EL3 then { + return(SS_Secure) + } else { + assert(EL != EL2 | EL2Enabled()); + if not_bool(ELUsingAArch32(EL3)) then { + return(if SCR_EL3[NS] == 0b1 then SS_NonSecure else SS_Secure) + } else { + return(if SCR[NS] == 0b1 then SS_NonSecure else SS_Secure) + } + } +} + +val CurrentSecurityState : unit -> SecurityState + +function CurrentSecurityState () = { + return(SecurityStateAtEL(PSTATE.EL)) +} + +val ExternalInvasiveDebugEnabled : unit -> bool + +function ExternalInvasiveDebugEnabled () = { + return(DBGEN == Signal_High) +} + +val HaveNoninvasiveDebugAuth : unit -> bool + +function HaveNoninvasiveDebugAuth () = { + return(not_bool(IsFeatureImplemented(FEAT_Debugv8p4))) +} + +val ExternalNoninvasiveDebugEnabled : unit -> bool + +function ExternalNoninvasiveDebugEnabled () = { + return((not_bool(HaveNoninvasiveDebugAuth()) | ExternalInvasiveDebugEnabled()) | NIDEN == Signal_High) +} + +val ExternalSecureInvasiveDebugEnabled : unit -> bool + +function ExternalSecureInvasiveDebugEnabled () = { + if not_bool(HaveEL(EL3)) & not_bool(SecureOnlyImplementation()) then { + return(false) + }; + return(ExternalInvasiveDebugEnabled() & SPIDEN == Signal_High) +} + +val ExternalSecureNoninvasiveDebugEnabled : unit -> bool + +function ExternalSecureNoninvasiveDebugEnabled () = { + if not_bool(HaveEL(EL3)) & not_bool(SecureOnlyImplementation()) then { + return(false) + }; + if HaveNoninvasiveDebugAuth() then { + return(ExternalNoninvasiveDebugEnabled() & (SPIDEN == Signal_High | SPNIDEN == Signal_High)) + } else { + return(ExternalSecureInvasiveDebugEnabled()) + } +} + +bitfield EDSCR_Type : bits(32) = + { + TFO : 31..31, + RXfull : 30..30, + TXfull : 29..29, + ITO : 28..28, + RXO : 27..27, + TXU : 26..26, + PipeAdv : 25..25, + ITE : 24..24, + INTdis : 23..22, + TDA : 21..21, + MA : 20..20, + SC2 : 19..19, + NS : 18..18, + SDD : 16..16, + NSE : 15..15, + HDE : 14..14, + RW : 13..10, + EL : 9..8, + A : 7..7, + ERR : 6..6, + STATUS : 5..0 + } + +bitfield MDCCSR_EL0_Type : bits(64) = {RXfull : 30..30, TXfull : 29..29} + +register MDCCSR_EL0 : MDCCSR_EL0_Type + +register _EDSCR : EDSCR_Type + +val EDSCR_read : unit -> EDSCR_Type + +function EDSCR_read () = { + r : EDSCR_Type = _EDSCR; + r.bits[30 .. 29] = Slice(MDCCSR_EL0.bits, 29, 2); + return(r) +} + +val Halted : unit -> bool + +function Halted () = { + return(not_bool(EDSCR_read()[STATUS] == 0b000001 | EDSCR_read()[STATUS] == 0b000010)) +} + +val HaveHPMDExt : unit -> bool + +function HaveHPMDExt () = { + return(IsFeatureImplemented(FEAT_PMUv3p1)) +} + +val HaveNoSecurePMUDisableOverride : unit -> bool + +function HaveNoSecurePMUDisableOverride () = { + return(IsFeatureImplemented(FEAT_Debugv8p2)) +} + +val HavePMUv3p5 : unit -> bool + +function HavePMUv3p5 () = { + return(IsFeatureImplemented(FEAT_PMUv3p5)) +} + +val HavePMUv3p7 : unit -> bool + +function HavePMUv3p7 () = { + return(IsFeatureImplemented(FEAT_PMUv3p7)) +} + +bitfield PMCNTENCLR_EL0_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMCNTENCLR_EL0 : PMCNTENCLR_EL0_Type + +bitfield PMCNTENCLR_Type : bits(32) = + { + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMCNTENCLR : PMCNTENCLR_Type + +val PMCNTENCLR_read : unit -> PMCNTENCLR_Type + +function PMCNTENCLR_read () = { + r : PMCNTENCLR_Type = _PMCNTENCLR; + r.bits[31 .. 0] = Slice(PMCNTENCLR_EL0.bits, 0, 32); + return(r) +} + +bitfield PMCR_EL0_Type : bits(64) = + { + FZS : 32..32, + IMP : 31..24, + IDCODE : 23..16, + N : 15..11, + FZO : 9..9, + LP : 7..7, + LC : 6..6, + DP : 5..5, + X : 4..4, + D : 3..3, + C : 2..2, + P : 1..1, + E : 0..0 + } + +register PMCR_EL0 : PMCR_EL0_Type + +bitfield PMCR_Type : bits(32) = + { + IMP : 31..24, + IDCODE : 23..16, + N : 15..11, + FZO : 9..9, + LP : 7..7, + LC : 6..6, + DP : 5..5, + X : 4..4, + D : 3..3, + C : 2..2, + P : 1..1, + E : 0..0 + } + +register _PMCR : PMCR_Type + +val PMCR_read : unit -> PMCR_Type + +function PMCR_read () = { + r : PMCR_Type = _PMCR; + r.bits[31 .. 0] = Slice(PMCR_EL0.bits, 0, 32); + return(r) +} + +bitfield PMINTENCLR_EL1_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMINTENCLR_EL1 : PMINTENCLR_EL1_Type + +bitfield PMINTENCLR_Type : bits(32) = + { + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMINTENCLR : PMINTENCLR_Type + +val PMINTENCLR_read : unit -> PMINTENCLR_Type + +function PMINTENCLR_read () = { + r : PMINTENCLR_Type = _PMINTENCLR; + r.bits[31 .. 0] = Slice(PMINTENCLR_EL1.bits, 0, 32); + return(r) +} + +bitfield PMOVSCLR_EL0_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMOVSCLR_EL0 : PMOVSCLR_EL0_Type + +bitfield PMOVSR_Type : bits(32) = + { + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMOVSR : PMOVSR_Type + +val PMOVSR_read : unit -> PMOVSR_Type + +function PMOVSR_read () = { + r : PMOVSR_Type = _PMOVSR; + r.bits[31 .. 0] = Slice(PMOVSCLR_EL0.bits, 0, 32); + return(r) +} + +val ConstrainUnpredictableBool : Unpredictable -> bool + +val PMUCounterIsHyp : forall 'n. int('n) -> bool + +function PMUCounterIsHyp n = { + if n == INSTRUCTION_COUNTER_ID then { + return(false) + }; + if n == CYCLE_COUNTER_ID then { + return(false) + }; + resvd_for_el2 : bool = undefined; + if HaveEL(EL2) then { + let hpmn_bits : bits(5) = if HaveAArch64() then MDCR_EL2[HPMN] else + HDCR_read()[HPMN]; + resvd_for_el2 = n >= UInt(hpmn_bits); + if UInt(hpmn_bits) > GetNumEventCounters() | not_bool(HaveFeatHPMN0()) & IsZero(hpmn_bits) then { + resvd_for_el2 = ConstrainUnpredictableBool(Unpredictable_CounterReservedForEL2) + }; + () + } else { + resvd_for_el2 = false + }; + return(resvd_for_el2) +} + +val PMUOverflowCondition : forall ('check_cnten : Bool) ('check_e : Bool) ('check_inten : Bool) ('exclude_cyc : Bool) ('exclude_sync : Bool) ('include_hi_name : Bool) ('include_lo_name : Bool). + (bool('check_e), bool('check_cnten), bool('check_inten), bool('include_hi_name), bool('include_lo_name), bool('exclude_cyc), bool('exclude_sync)) -> bool + +function PMUOverflowCondition (check_e, check_cnten, check_inten, include_hi_name, include_lo_name, exclude_cyc, exclude_sync) = { + let 'counters = GetNumEventCounters(); + ovsf : bits(64) = undefined; + if HaveAArch64() then { + ovsf = PMOVSCLR_EL0.bits; + ovsf[63 .. 33] = Zeros(31); + if not_bool(HavePMUv3ICNTR()) then { + ovsf[INSTRUCTION_COUNTER_ID] = Bit(0b0) + }; + () + } else { + ovsf = ZeroExtend(PMOVSR_read().bits, 64) + }; + if counters < 31 then { + assert(constraint((0 <= 'counters & 'counters <= 30))); + ovsf[30 .. counters] = Zeros(31 - counters) + }; + foreach (idx from 0 to (counters - 1) by 1 in inc) { + E : bits(1) = undefined; + let is_hyp : bool = PMUCounterIsHyp(idx); + if HaveAArch64() then { + E = if is_hyp then MDCR_EL2[HPME] else PMCR_EL0[E] + } else { + E = if is_hyp then HDCR_read()[HPME] else PMCR_read()[E] + }; + if check_e then { + assert(constraint((0 <= 'loop_idx & 'loop_idx < 64))); + ovsf[idx] = Bit([ovsf[idx]] & E) + }; + if not_bool(is_hyp) & not_bool(include_lo_name) | is_hyp & not_bool(include_hi_name) then { + assert(constraint((0 <= 'loop_idx & 'loop_idx < 64))); + ovsf[idx] = Bit(0b0) + }; + () + }; + if exclude_cyc | not_bool(include_lo_name) then { + ovsf[CYCLE_COUNTER_ID] = Bit(0b0) + }; + if check_e then { + ovsf[CYCLE_COUNTER_ID] = Bit([ovsf[CYCLE_COUNTER_ID]] & PMCR_EL0[E]) + }; + if HaveAArch64() & HavePMUv3ICNTR() then { + if not_bool(include_lo_name) then { + ovsf[INSTRUCTION_COUNTER_ID] = Bit(0b0) + }; + if check_e then { + ovsf[INSTRUCTION_COUNTER_ID] = Bit([ovsf[INSTRUCTION_COUNTER_ID]] & PMCR_EL0[E]) + }; + () + }; + if check_cnten then { + let cnten : bits(64) = if HaveAArch64() then PMCNTENCLR_EL0.bits else + ZeroExtend(PMCNTENCLR_read().bits, 64); + ovsf = ovsf & cnten + }; + if check_inten then { + let inten : bits(64) = if HaveAArch64() then PMINTENCLR_EL1.bits else + ZeroExtend(PMINTENCLR_read().bits, 64); + ovsf = ovsf & inten + }; + return(not_bool(IsZero(ovsf))) +} + +val HiLoPMUOverflow : forall ('resvd_for_el2 : Bool). + bool('resvd_for_el2) -> bool + +function HiLoPMUOverflow resvd_for_el2 = { + let check_cnten : bool = false; + let check_e : bool = false; + let check_inten : bool = false; + let include_lo_name : bool = not_bool(resvd_for_el2); + let include_hi_name : bool = resvd_for_el2; + let exclude_cyc : bool = false; + let exclude_sync : bool = false; + let overflow : bool = PMUOverflowCondition(check_e, check_cnten, check_inten, include_hi_name, include_lo_name, exclude_cyc, exclude_sync); + return(overflow) +} + +bitfield MDCR_EL3_Type : bits(64) = + { + EPMSSAD : 46..45, + EnPMSS : 44..44, + EBWE : 43..43, + EnPMS3 : 42..42, + PMEE : 41..40, + E3BREC : 38..38, + E3BREW : 37..37, + EnPMSN : 36..36, + MPMX : 35..35, + MCCD : 34..34, + SBRBE : 33..32, + PMSSE : 31..30, + MTPME : 28..28, + TDCC : 27..27, + SCCD : 23..23, + EPMAD : 21..21, + EDAD : 20..20, + TTRF : 19..19, + STE : 18..18, + SPME : 17..17, + SDD : 16..16, + SPD32 : 15..14, + NSPB : 13..12, + NSPBE : 11..11, + TDOSA : 10..10, + TDA : 9..9, + EnPM2 : 7..7, + TPM : 6..6, + EDADE : 4..4, + EPMADE : 2..2, + RLTE : 0..0 + } + +register MDCR_EL3 : MDCR_EL3_Type + +bitfield PMCCFILTR_EL0_Type : bits(64) = + { + P : 31..31, + U : 30..30, + NSK : 29..29, + NSU : 28..28, + NSH : 27..27, + M : 26..26, + SH : 24..24, + T : 23..23, + RLK : 22..22, + RLU : 21..21, + RLH : 20..20 + } + +register PMCCFILTR_EL0 : PMCCFILTR_EL0_Type + +bitfield PMCCFILTR_Type : bits(32) = + { + P : 31..31, + U : 30..30, + NSK : 29..29, + NSU : 28..28, + NSH : 27..27, + RLU : 21..21 + } + +register _PMCCFILTR : PMCCFILTR_Type + +val PMCCFILTR_read : unit -> PMCCFILTR_Type + +function PMCCFILTR_read () = { + r : PMCCFILTR_Type = _PMCCFILTR; + r.bits[31 .. 0] = Slice(PMCCFILTR_EL0.bits, 0, 32); + return(r) +} + +bitfield PMCNTENSET_EL0_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMCNTENSET_EL0 : PMCNTENSET_EL0_Type + +bitfield PMCNTENSET_Type : bits(32) = + { + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMCNTENSET : PMCNTENSET_Type + +val PMCNTENSET_read : unit -> PMCNTENSET_Type + +function PMCNTENSET_read () = { + r : PMCNTENSET_Type = _PMCNTENSET; + r.bits[31 .. 0] = Slice(PMCNTENSET_EL0.bits, 0, 32); + return(r) +} + +bitfield PMEVTYPER_EL0_Type : bits(64) = + { + TC : 63..61, + TE : 60..60, + SYNC : 58..58, + TH : 43..32, + P : 31..31, + U : 30..30, + NSK : 29..29, + NSU : 28..28, + NSH : 27..27, + M : 26..26, + MT : 25..25, + SH : 24..24, + T : 23..23, + RLK : 22..22, + RLU : 21..21, + RLH : 20..20, + evtCount : (15..10 @ 9..0) + } + +register PMEVTYPER_EL0 : vector(32, PMEVTYPER_EL0_Type) + +bitfield PMEVTYPER_Type : bits(32) = + { + P : 31..31, + U : 30..30, + NSK : 29..29, + NSU : 28..28, + NSH : 27..27, + MT : 25..25, + RLU : 21..21, + evtCount : (15..10 @ 9..0) + } + +register _PMEVTYPER : vector(31, PMEVTYPER_Type) + +val PMEVTYPER_read : forall 'n, (0 <= 'n & 'n < 31). int('n) -> PMEVTYPER_Type + +function PMEVTYPER_read n = { + r : PMEVTYPER_Type = _PMEVTYPER[n]; + r.bits[31 .. 0] = Slice(PMEVTYPER_EL0[n].bits, 0, 32); + return(r) +} + +bitfield PMICFILTR_EL0_Type : bits(64) = + { + SYNC : 58..58, + P : 31..31, + U : 30..30, + NSK : 29..29, + NSU : 28..28, + NSH : 27..27, + M : 26..26, + SH : 24..24, + T : 23..23, + RLK : 22..22, + RLU : 21..21, + RLH : 20..20, + evtCount : 15..0 + } + +register PMICFILTR_EL0 : PMICFILTR_EL0_Type + +bitfield SDCR_Type : bits(32) = + { + MTPME : 28..28, + TDCC : 27..27, + SCCD : 23..23, + EPMAD : 21..21, + EDAD : 20..20, + TTRF : 19..19, + STE : 18..18, + SPME : 17..17, + SPD : 15..14 + } + +register SDCR : SDCR_Type + +bitfield SDER32_EL2_Type : bits(64) = {SUNIDEN : 1..1, SUIDEN : 0..0} + +register SDER32_EL2 : SDER32_EL2_Type + +bitfield SDER32_EL3_Type : bits(64) = {SUNIDEN : 1..1, SUIDEN : 0..0} + +register _SDER32_EL3 : SDER32_EL3_Type + +val SDER32_EL3_read : unit -> SDER32_EL3_Type + +function SDER32_EL3_read () = { + r : SDER32_EL3_Type = _SDER32_EL3; + r.bits[63 .. 0] = Slice(SDER32_EL2.bits, 0, 64); + return(r) +} + +bitfield SDER_Type : bits(32) = {SUNIDEN : 1..1, SUIDEN : 0..0} + +register _SDER : SDER_Type + +val SDER_read : unit -> SDER_Type + +function SDER_read () = { + r : SDER_Type = _SDER; + if HaveEL(EL3) then { + r.bits[31 .. 0] = Slice(SDER32_EL3_read().bits, 0, 32) + } else { + r.bits[31 .. 0] = Slice(SDER32_EL2.bits, 0, 32) + }; + return(r) +} + +val CountPMUEvents : forall 'idx, (0 <= 'idx & 'idx <= 32). int('idx) -> bool + +function CountPMUEvents idx = { + dp : bits(1) = undefined; + hccd : bits(1) = undefined; + hpmd : bits(1) = undefined; + sccd : bits(1) = undefined; + let 'num_counters = GetNumEventCounters(); + assert((idx == CYCLE_COUNTER_ID | idx < num_counters) | idx == INSTRUCTION_COUNTER_ID & HavePMUv3ICNTR()); + enabled : bool = undefined; + filtered : bool = undefined; + E : bits(1) = undefined; + let debug : bool = Halted(); + let resvd_for_el2 : bool = PMUCounterIsHyp(idx); + ss : SecurityState = CurrentSecurityState(); + match idx { + ? if ? == INSTRUCTION_COUNTER_ID => { + assert(HaveAArch64()); + enabled = PMCR_EL0[E] == 0b1 & PMCNTENSET_EL0[F0] == 0b1 + }, + ? if ? == CYCLE_COUNTER_ID => { + if HaveAArch64() then { + enabled = PMCR_EL0[E] == 0b1 & PMCNTENSET_EL0[C] == 0b1 + } else { + enabled = PMCR_read()[E] == 0b1 & PMCNTENSET_read()[C] == 0b1 + } + }, + _ => { + if resvd_for_el2 then { + E = if HaveAArch64() then MDCR_EL2[HPME] else HDCR_read()[HPME] + } else { + E = if HaveAArch64() then PMCR_EL0[E] else PMCR_read()[E] + }; + if HaveAArch64() then { + enabled = E == 0b1 & [PMCNTENSET_EL0.bits[idx]] == 0b1 + } else { + assert(constraint((0 <= 'idx & 'idx < 32))); + enabled = E == 0b1 & [PMCNTENSET_read().bits[idx]] == 0b1 + } + } + }; + prohibited : bool = false; + if HaveEL(EL3) & ss == SS_Secure then { + if not_bool(ELUsingAArch32(EL3)) then { + prohibited = (MDCR_EL3[SPME] == 0b0 & HavePMUv3p7()) & MDCR_EL3[MPMX] == 0b0 + } else { + prohibited = SDCR[SPME] == 0b0 + }; + if prohibited & PSTATE.EL == EL0 then { + if ELUsingAArch32(EL3) then { + prohibited = SDER_read()[SUNIDEN] == 0b0 + } else if ELUsingAArch32(EL1) then { + prohibited = SDER32_EL3_read()[SUNIDEN] == 0b0 + } else () + }; + () + }; + if ((not_bool(prohibited) & HavePMUv3p7()) & PSTATE.EL == EL3) & HaveAArch64() then { + prohibited = MDCR_EL3[MPMX] == 0b1 & (MDCR_EL3[SPME] == 0b0 | not_bool(resvd_for_el2)) + }; + if ((not_bool(prohibited) & PSTATE.EL == EL2) & HaveHPMDExt()) & not_bool(resvd_for_el2) then { + let hpmd : bits(1) = if HaveAArch64() then MDCR_EL2[HPMD] else + HDCR_read()[HPMD]; + prohibited = hpmd == 0b1 + }; + if prohibited & not_bool(HaveNoSecurePMUDisableOverride()) then { + prohibited = not_bool(ExternalSecureNoninvasiveDebugEnabled()) + }; + frozen : bool = false; + if HavePMUv3p7() then { + FZ : bits(1) = undefined; + if resvd_for_el2 then { + FZ = if HaveAArch64() then MDCR_EL2[HPMFZO] else HDCR_read()[HPMFZO] + } else { + FZ = if HaveAArch64() then PMCR_EL0[FZO] else PMCR_read()[FZO] + }; + frozen = FZ == 0b1 & HiLoPMUOverflow(resvd_for_el2) + }; + if (prohibited | frozen) & idx == CYCLE_COUNTER_ID then { + let dp : bits(1) = if HaveAArch64() then PMCR_EL0[DP] else + PMCR_read()[DP]; + enabled = enabled & dp == 0b0; + prohibited = false; + frozen = false + }; + if HavePMUv3p5() & idx == CYCLE_COUNTER_ID then { + if HaveEL(EL3) & ss == SS_Secure then { + let sccd : bits(1) = if HaveAArch64() then MDCR_EL3[SCCD] else + SDCR[SCCD]; + if sccd == 0b1 then { + prohibited = true + }; + () + }; + if PSTATE.EL == EL2 then { + let hccd : bits(1) = if HaveAArch64() then MDCR_EL2[HCCD] else + HDCR_read()[HCCD]; + if hccd == 0b1 then { + prohibited = true + }; + () + }; + () + }; + if HavePMUv3p7() & idx == CYCLE_COUNTER_ID then { + if (PSTATE.EL == EL3 & HaveAArch64()) & MDCR_EL3[MCCD] == 0b1 then { + prohibited = true + }; + () + }; + filter : bits(32) = undefined; + match idx { + ? if ? == INSTRUCTION_COUNTER_ID => { + filter = PMICFILTR_EL0.bits[31 .. 0] + }, + ? if ? == CYCLE_COUNTER_ID => { + filter = if HaveAArch64() then PMCCFILTR_EL0.bits[31 .. 0] else + PMCCFILTR_read().bits + }, + _ => { + filter = if HaveAArch64() then { + assert(constraint((0 <= 'idx & 'idx < 32))); + PMEVTYPER_EL0[idx].bits[31 .. 0] + } else { + assert(constraint((0 <= 'idx & 'idx < 31))); + PMEVTYPER_read(idx).bits + } + } + }; + let filter = filter; + let P : bits(1) = [filter[31]]; + let U : bits(1) = [filter[30]]; + let NSK : bits(1) = if HaveEL(EL3) then [filter[29]] else 0b0; + let NSU : bits(1) = if HaveEL(EL3) then [filter[28]] else 0b0; + let NSH : bits(1) = if HaveEL(EL2) then [filter[27]] else 0b0; + let M : bits(1) = if HaveEL(EL3) & HaveAArch64() then [filter[26]] else 0b0; + let SH : bits(1) = if HaveEL(EL3) & HaveSecureEL2Ext() then [filter[24]] + else + 0b0; + let RLK : bits(1) = if HaveRME() then [filter[22]] else 0b0; + let RLU : bits(1) = if HaveRME() then [filter[21]] else 0b0; + let RLH : bits(1) = if HaveRME() then [filter[20]] else 0b0; + let ss : SecurityState = CurrentSecurityState(); + match PSTATE.EL { + ? if ? == EL0 => { + match ss { + SS_NonSecure => { + filtered = U != NSU + }, + SS_Secure => { + filtered = U == 0b1 + }, + SS_Realm => { + filtered = U != RLU + }, + _ => () + } + }, + ? if ? == EL1 => { + match ss { + SS_NonSecure => { + filtered = P != NSK + }, + SS_Secure => { + filtered = P == 0b1 + }, + SS_Realm => { + filtered = P != RLK + }, + _ => () + } + }, + ? if ? == EL2 => { + match ss { + SS_NonSecure => { + filtered = NSH == 0b0 + }, + SS_Secure => { + filtered = NSH == SH + }, + SS_Realm => { + filtered = NSH == RLH + }, + _ => () + } + }, + ? if ? == EL3 => { + if HaveAArch64() then { + filtered = M != P + } else { + filtered = P == 0b1 + } + }, + _ => () + }; + return((((not_bool(debug) & enabled) & not_bool(prohibited)) & not_bool(filtered)) & not_bool(frozen)) +} + +bitfield PMICNTR_EL0_Type : bits(64) = {ICNT : 63..0} + +register PMICNTR_EL0 : PMICNTR_EL0_Type + +bitfield PMOVSSET_EL0_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMOVSSET_EL0 : PMOVSSET_EL0_Type + +val IncrementInstructionCounter : forall 'increment_name. + int('increment_name) -> unit + +function IncrementInstructionCounter increment_name = { + if CountPMUEvents(INSTRUCTION_COUNTER_ID) then { + let 'old_value = UInt(PMICNTR_EL0.bits); + let 'new_value = old_value + increment_name; + PMICNTR_EL0 = Mk_PMICNTR_EL0_Type(new_value[63 .. 0]); + if [old_value[64]] != [new_value[64]] then { + PMOVSSET_EL0[F0] = 0b1; + PMOVSCLR_EL0[F0] = 0b1 + }; + () + }; + () +} + +val HaveStatisticalProfilingv1p1 : unit -> bool + +function HaveStatisticalProfilingv1p1 () = { + return(IsFeatureImplemented(FEAT_SPEv1p1)) +} + +val HaveStatisticalProfilingv1p4 : unit -> bool + +function HaveStatisticalProfilingv1p4 () = { + return(IsFeatureImplemented(FEAT_SPEv1p4)) +} + +val SPEEvent : bits(16) -> unit + +function SPEEvent pmuevent = { + match pmuevent { + ? if ? == PMU_EVENT_DSNP_HIT_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[23] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L1D_LFB_HIT_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[22] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L2D_LFB_HIT_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[22] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L3D_LFB_HIT_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[22] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_LL_LFB_HIT_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[22] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L1D_CACHE_HITM_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[21] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L2D_CACHE_HITM_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[21] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L3D_CACHE_HITM_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[21] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_LL_CACHE_HITM_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[21] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L2D_CACHE_LMISS_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[20] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L2D_CACHE_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[19] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_SVE_PRED_EMPTY_SPEC => { + if HaveStatisticalProfilingv1p1() then { + SPESampleEvents[18] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_SVE_PRED_PARTIAL_SPEC => { + if HaveStatisticalProfilingv1p1() then { + SPESampleEvents[17] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_LDST_ALIGN_LAT => { + if HaveStatisticalProfilingv1p1() then { + SPESampleEvents[11] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_REMOTE_ACCESS => { + SPESampleEvents[10] = Bit(0b1) + }, + ? if ? == PMU_EVENT_LL_CACHE_MISS => { + SPESampleEvents[9] = Bit(0b1) + }, + ? if ? == PMU_EVENT_LL_CACHE => { + SPESampleEvents[8] = Bit(0b1) + }, + ? if ? == PMU_EVENT_BR_MIS_PRED => { + SPESampleEvents[7] = Bit(0b1) + }, + ? if ? == PMU_EVENT_BR_MIS_PRED_RETIRED => { + SPESampleEvents[7] = Bit(0b1) + }, + ? if ? == PMU_EVENT_DTLB_WALK => { + SPESampleEvents[5] = Bit(0b1) + }, + ? if ? == PMU_EVENT_L1D_TLB => { + SPESampleEvents[4] = Bit(0b1) + }, + ? if ? == PMU_EVENT_L1D_CACHE_REFILL => { + if not_bool(HaveStatisticalProfilingv1p4()) then { + SPESampleEvents[3] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L1D_CACHE_LMISS_RD => { + if HaveStatisticalProfilingv1p4() then { + SPESampleEvents[3] = Bit(0b1) + }; + () + }, + ? if ? == PMU_EVENT_L1D_CACHE => { + SPESampleEvents[2] = Bit(0b1) + }, + ? if ? == PMU_EVENT_INST_RETIRED => { + SPESampleEvents[1] = Bit(0b1) + }, + ? if ? == PMU_EVENT_EXC_TAKEN => { + SPESampleEvents[0] = Bit(0b1) + }, + _ => { + return() + } + }; + return() +} + +val PMUEvent : bits(16) -> unit + +val PMUEvent__1 : forall 'increment_name. + (bits(16), int('increment_name)) -> unit + +val PMUEvent__2 : forall 'idx 'increment_name. + (bits(16), int('increment_name), int('idx)) -> unit + +function PMUEvent pmuevent = { + PMUEvent__1(pmuevent, 1) +} + +function PMUEvent__1 (pmuevent, increment_name) = { + if SPESampleInFlight then { + SPEEvent(pmuevent) + }; + if PMCR_EL0[E] == 0b0 & MDCR_EL2[HPME] == 0b0 then { + return() + }; + let 'counters = GetNumEventCounters(); + if counters != 0 then { + foreach (idx from 0 to (counters - 1) by 1 in inc) { + PMUEvent__2(pmuevent, increment_name, idx) + } + }; + if (HaveAArch64() & HavePMUv3ICNTR()) & pmuevent == PMU_EVENT_INST_RETIRED then { + IncrementInstructionCounter(increment_name) + }; + () +} + +function PMUEvent__2 (pmuevent, increment_name, idx) = { + if not_bool(HavePMUv3()) then { + return() + }; + if UsingAArch32() then { + assert(constraint((0 <= 'idx & 'idx < 31))); + if PMEVTYPER_read(idx)[evtCount] == pmuevent then { + PMUEventAccumulator[idx] = PMUEventAccumulator[idx] + increment_name + }; + () + } else { + assert(constraint((0 <= 'idx & 'idx < 32))); + if PMEVTYPER_EL0[idx][evtCount] == pmuevent then { + assert(constraint((0 <= 'idx & 'idx < 31))); + PMUEventAccumulator[idx] = PMUEventAccumulator[idx] + increment_name + }; + () + } +} + +val HasElapsed64Cycles : unit -> bool + +function HasElapsed64Cycles () = { + if __clock_divider == 63 then { + __clock_divider = 0; + return(true) + } else { + __clock_divider = __clock_divider + 1; + return(false) + } +} + +val ConstrainUnpredictableBits : forall 'width, 'width >= 0. + (Unpredictable, int('width)) -> (Constraint, bits('width)) + +val HavePMUv3EDGE : unit -> bool + +function HavePMUv3EDGE () = { + return(IsFeatureImplemented(FEAT_PMUv3_EDGE)) +} + +val HavePMUv3TH : unit -> bool + +function HavePMUv3TH () = { + return(IsFeatureImplemented(FEAT_PMUv3_TH)) +} + +val PMUCountValue : forall 'Vb 'n, (0 <= 'n & 'n < 31). + (int('n), int('Vb)) -> int + +function PMUCountValue (n, Vb) = { + Vp : bool = undefined; + tc : bits(2) = undefined; + if not_bool(HavePMUv3TH()) | not_bool(HaveAArch64()) then { + return(Vb) + }; + let 'T = UInt(PMEVTYPER_EL0[n][TH]); + Vc : bool = undefined; + match PMEVTYPER_EL0[n][TC][2 .. 1] { + 0b00 => { + Vc = Vb != T + }, + 0b01 => { + Vc = Vb == T + }, + 0b10 => { + Vc = Vb >= T + }, + 0b11 => { + Vc = Vb < T + }, + _ => () + }; + Vt : int = undefined; + if [PMEVTYPER_EL0[n][TC][0]] == 0b0 then { + Vt = if Vc then Vb else 0 + } else { + Vt = if Vc then 1 else 0 + }; + let 'Vt = Vt; + v : int = undefined; + if HavePMUv3EDGE() & PMEVTYPER_EL0[n][TE] == 0b1 then { + assert(constraint((0 <= 'n & 'n < 31))); + let Vp : bool = PMULastThresholdValue[n]; + tc : bits(2) = PMEVTYPER_EL0[n][TC][1 .. 0]; + if tc == 0b00 then { + c : Constraint = undefined; + (c, tc) = ConstrainUnpredictableBits(Unpredictable_RESTC, 2); + if c == Constraint_DISABLED then { + tc = 0b00 + }; + () + }; + match tc { + 0b00 => { + v = Vt + }, + 0b10 => { + v = if Vp != Vc then 1 else 0 + }, + [_, bitone] => { + v = if not_bool(Vp) & Vc then 1 else 0 + } + } + } else { + v = Vt + }; + let 'v = v; + PMULastThresholdValue[n] = Vc; + return(v) +} + +bitfield BRBCR_EL1_Type : bits(64) = + { + EXCEPTION : 23..23, + ERTN : 22..22, + FZPSS : 9..9, + FZP : 8..8, + TS : 6..5, + MPRED : 4..4, + CC : 3..3, + E1BRE : 1..1, + E0BRE : 0..0 + } + +register BRBCR_EL1 : BRBCR_EL1_Type + +bitfield BRBCR_EL2_Type : bits(64) = + { + EXCEPTION : 23..23, + ERTN : 22..22, + FZPSS : 9..9, + FZP : 8..8, + TS : 6..5, + MPRED : 4..4, + CC : 3..3, + E2BRE : 1..1, + E0HBRE : 0..0 + } + +register BRBCR_EL2 : BRBCR_EL2_Type + +val HaveECVExt : unit -> bool + +function HaveECVExt () = { + return(IsFeatureImplemented(FEAT_ECV)) +} + +val BRBETimeStamp : unit -> TimeStamp + +function BRBETimeStamp () = { + TS_el2 : bits(2) = undefined; + if HaveEL(EL2) then { + TS_el2 : bits(2) = BRBCR_EL2[TS]; + if not_bool(HaveECVExt()) & TS_el2 == 0b10 then { + let (_, __tup_1 : bits(2)) = ConstrainUnpredictableBits(Unpredictable_EL2TIMESTAMP, 2); + TS_el2 = __tup_1 + }; + match TS_el2 { + 0b00 => (), + 0b01 => { + return(TimeStamp_Virtual) + }, + 0b10 => { + assert(HaveECVExt()); + return(TimeStamp_OffsetPhysical) + }, + 0b11 => { + return(TimeStamp_Physical) + } + } + }; + let TS_el2 = TS_el2; + TS_el1 : bits(2) = BRBCR_EL1[TS]; + if TS_el1 == 0b00 | not_bool(HaveECVExt()) & TS_el1 == 0b10 then { + let (_, __tup_1 : bits(2)) = ConstrainUnpredictableBits(Unpredictable_EL1TIMESTAMP, 2); + TS_el1 = __tup_1 + }; + match TS_el1 { + 0b01 => { + return(TimeStamp_Virtual) + }, + 0b10 => { + return(TimeStamp_OffsetPhysical) + }, + 0b11 => { + return(TimeStamp_Physical) + }, + _ => { + Unreachable(); + return(undefined : TimeStamp) + } + } +} + +bitfield BRBFCR_EL1_Type : bits(64) = + { + BANK : 29..28, + CONDDIR : 22..22, + DIRCALL : 21..21, + INDCALL : 20..20, + RTN : 19..19, + INDIRECT : 18..18, + DIRECT : 17..17, + EnI : 16..16, + PAUSED : 7..7, + LASTFAILED : 6..6 + } + +register BRBFCR_EL1 : BRBFCR_EL1_Type + +bitfield BRBTS_EL1_Type : bits(64) = {TS : 63..0} + +register BRBTS_EL1 : BRBTS_EL1_Type + +type CNTPOFF_EL2_Type = bits(64) + +register CNTPOFF_EL2 : CNTPOFF_EL2_Type + +type CNTVOFF_EL2_Type = bits(64) + +register CNTVOFF_EL2 : CNTVOFF_EL2_Type + +val PhysicalCountInt : unit -> bits(64) + +function PhysicalCountInt () = { + return(PhysicalCount[87 .. 24]) +} + +bitfield CNTHCTL_EL2_Type : bits(64) = + { + CNTPMASK : 19..19, + CNTVMASK : 18..18, + EVNTIS : 17..17, + EL1NVVCT : 16..16, + EL1NVPCT : 15..15, + EL1TVCT : 14..14, + EL1TVT : 13..13, + ECV : 12..12, + EL1PTEN : 11..11, + EL0PTEN : 9..9, + EL0VTEN : 8..8, + EVNTI : 7..4, + EVNTDIR : 3..3, + EVNTEN : 2..2, + EL1PCEN : 1..1, + EL0VCTEN : 1..1, + EL0PCTEN : 0..0 + } + +register CNTHCTL_EL2 : CNTHCTL_EL2_Type + +val EffectiveSCR_EL3_RW : unit -> bits(1) + +function EffectiveSCR_EL3_RW () = { + if not_bool(HaveAArch64()) then { + return(0b0) + }; + if not_bool(HaveAArch32EL(EL2)) & not_bool(HaveAArch32EL(EL1)) then { + return(0b1) + }; + if HaveAArch32EL(EL1) then { + if not_bool(HaveAArch32EL(EL2)) & SCR_EL3[NS] == 0b1 then { + return(0b1) + }; + if (HaveSecureEL2Ext() & SCR_EL3[EEL2] == 0b1) & SCR_EL3[NS] == 0b0 then { + return(0b1) + }; + () + }; + return(SCR_EL3[RW]) +} + +val PhysicalOffsetIsValid : unit -> bool + +function PhysicalOffsetIsValid () = { + if not_bool(HaveAArch64()) then { + return(false) + } else if not_bool(HaveEL(EL2)) | not_bool(HaveECVExt()) then { + return(false) + } else if (HaveEL(EL3) & SCR_EL3[NS] == 0b1) & EffectiveSCR_EL3_RW() == 0b0 then { + return(false) + } else if HaveEL(EL3) & SCR_EL3[ECVEn] == 0b0 then { + return(false) + } else if CNTHCTL_EL2[ECV] == 0b0 then { + return(false) + } else { + return(true) + } +} + +register CFG_RVBAR : bits(64) = ZeroExtend(0x0, 64) + +register __impdef_TG0 : bits(2) = 0b00 + +register __impdef_TG1 : bits(2) = 0b10 + +register __mpam_has_hcr : bool = true + +register __mpam_partid_max : bits(16) = Zeros(16) + +register __mpam_pmg_max : bits(8) = Zeros(8) + +register __mpam_vpmr_max : bits(3) = Zeros(3) + +val __IMPDEF_bits : forall 'N, 'N >= 0. (int('N), string) -> bits('N) + +val GetTimestamp : TimeStamp -> bits(64) + +function GetTimestamp timeStampType = { + match timeStampType { + TimeStamp_Physical => { + return(PhysicalCountInt()) + }, + TimeStamp_Virtual => { + return(PhysicalCountInt() - CNTVOFF_EL2) + }, + TimeStamp_OffsetPhysical => { + let physoff : bits(64) = if PhysicalOffsetIsValid() then CNTPOFF_EL2 + else + Zeros(64); + return(PhysicalCountInt() - physoff) + }, + TimeStamp_None => { + return(Zeros(64)) + }, + TimeStamp_CoreSight => { + return(__IMPDEF_bits(64, "CoreSight timestamp")) + }, + _ => { + Unreachable(); + return(undefined : bits(64)) + } + } +} + +val BRBEFreeze : unit -> unit + +function BRBEFreeze () = { + BRBFCR_EL1[PAUSED] = 0b1; + BRBTS_EL1 = Mk_BRBTS_EL1_Type(GetTimestamp(BRBETimeStamp())) +} + +val CTI_SetEventLevel : (CrossTriggerIn, Signal) -> unit + +bitfield EDECR_Type : bits(32) = + {PME : 4..4, SS : 2..2, RCE : 1..1, OSUCE : 0..0} + +register EDECR : EDECR_Type + +val CTI_SignalEvent : CrossTriggerIn -> unit + +type DLR_EL0_Type = bits(64) + +register DLR_EL0 : DLR_EL0_Type + +type DLR_Type = bits(32) + +register _DLR : DLR_Type + +val DLR_write : DLR_Type -> unit + +function DLR_write value_name = { + let r : DLR_Type = value_name; + DLR_EL0[31 .. 0] = Slice(r, 0, 32); + _DLR = r; + return() +} + +bitfield DSPSR_EL0_Type : bits(64) = + { + EXLOCK : 34..34, + PPEND : 33..33, + PM : 32..32, + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + TCO : 25..25, + DIT : 24..24, + UAO : 23..23, + PAN : 22..22, + SS : 21..21, + IL : 20..20, + GE : 19..16, + ALLINT : 13..13, + BTYPE : 11..10, + IT : (15..10 @ 26..25), + D : 9..9, + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5 + } + +register DSPSR_EL0 : DSPSR_EL0_Type + +bitfield DSPSR_Type : bits(32) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + DIT : 24..24, + SSBS : 23..23, + PAN : 22..22, + SS : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register _DSPSR : DSPSR_Type + +val DSPSR_write : DSPSR_Type -> unit + +function DSPSR_write value_name = { + let r : DSPSR_Type = value_name; + DSPSR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DSPSR = r; + return() +} + +bitfield DSPSR2_Type : bits(32) = {PPEND : 1..1} + +register _DSPSR2 : DSPSR2_Type + +val DSPSR2_write : DSPSR2_Type -> unit + +function DSPSR2_write value_name = { + let r : DSPSR2_Type = value_name; + DSPSR_EL0.bits[63 .. 32] = Slice(r.bits, 0, 32); + _DSPSR2 = r; + return() +} + +val EDSCR_write : EDSCR_Type -> unit + +function EDSCR_write value_name = { + let r : EDSCR_Type = value_name; + MDCCSR_EL0.bits[30 .. 29] = Slice(r.bits, 29, 2); + _EDSCR = r; + return() +} + +val ExternalRealmInvasiveDebugEnabled : unit -> bool + +function ExternalRealmInvasiveDebugEnabled () = { + if not_bool(HaveRME()) then { + return(false) + }; + return(ExternalInvasiveDebugEnabled() & RLPIDEN == Signal_High) +} + +val ExternalRootInvasiveDebugEnabled : unit -> bool + +function ExternalRootInvasiveDebugEnabled () = { + if not_bool(HaveRME()) then { + return(false) + }; + return(((ExternalInvasiveDebugEnabled() & (not_bool(HaveSecureEL2Ext()) | ExternalSecureInvasiveDebugEnabled())) & ExternalRealmInvasiveDebugEnabled()) & RTPIDEN == Signal_High) +} + +val HaveBRBEv1p1 : unit -> bool + +function HaveBRBEv1p1 () = { + return(IsFeatureImplemented(FEAT_BRBEv1p1)) +} + +val BranchRecordAllowed : bits(2) -> bool + +function BranchRecordAllowed el = { + if ELUsingAArch32(el) then { + return(false) + }; + if BRBFCR_EL1[PAUSED] == 0b1 then { + return(false) + }; + if el == EL3 & HaveBRBEv1p1() then { + return(MDCR_EL3[E3BREC] != MDCR_EL3[E3BREW]) + }; + if HaveEL(EL3) & (MDCR_EL3[SBRBE] == 0b00 | CurrentSecurityState() == SS_Secure & MDCR_EL3[SBRBE] == 0b01) then { + return(false) + }; + match el { + ? if ? == EL3 => { + return(false) + }, + ? if ? == EL2 => { + return(BRBCR_EL2[E2BRE] == 0b1) + }, + ? if ? == EL1 => { + return(BRBCR_EL1[E1BRE] == 0b1) + }, + ? if ? == EL0 => { + if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + return(BRBCR_EL2[E0HBRE] == 0b1) + } else { + return(BRBCR_EL1[E0BRE] == 0b1) + } + }, + _ => { + return(undefined : bool) + } + } +} + +val ELIsInHost : bits(2) -> bool + +function ELIsInHost el = { + if not_bool(HaveVirtHostExt()) | ELUsingAArch32(EL2) then { + return(false) + }; + match el { + ? if ? == EL3 => { + return(false) + }, + ? if ? == EL2 => { + return(EL2Enabled() & HCR_EL2[E2H] == 0b1) + }, + ? if ? == EL1 => { + return(false) + }, + ? if ? == EL0 => { + return(EL2Enabled() & (HCR_EL2[E2H] @ HCR_EL2[TGE]) == 0b11) + }, + _ => { + Unreachable(); + return(undefined : bool) + } + } +} + +val HavePACExt : unit -> bool + +function HavePACExt () = { + return(IsFeatureImplemented(FEAT_PAuth)) +} + +val S1TranslationRegime : bits(2) -> bits(2) + +val S1TranslationRegime__1 : unit -> bits(2) + +function S1TranslationRegime el = { + if el != EL0 then { + return(el) + } else if (HaveEL(EL3) & ELUsingAArch32(EL3)) & SCR[NS] == 0b0 then { + return(EL3) + } else if HaveVirtHostExt() & ELIsInHost(el) then { + return(EL2) + } else { + return(EL1) + } +} + +function S1TranslationRegime__1 () = { + return(S1TranslationRegime(PSTATE.EL)) +} + +bitfield TCR_EL1_Type : bits(64) = + { + MTX1 : 61..61, + MTX0 : 60..60, + DS : 59..59, + TCMA1 : 58..58, + TCMA0 : 57..57, + E0PD1 : 56..56, + E0PD0 : 55..55, + NFD1 : 54..54, + NFD0 : 53..53, + TBID1 : 52..52, + TBID0 : 51..51, + HWU162 : 50..50, + HWU161 : 49..49, + HWU160 : 48..48, + HWU159 : 47..47, + HWU062 : 46..46, + HWU061 : 45..45, + HWU060 : 44..44, + HWU059 : 43..43, + HPD1 : 42..42, + HPD0 : 41..41, + HD : 40..40, + HA : 39..39, + TBI1 : 38..38, + TBI0 : 37..37, + AS : 36..36, + IPS : 34..32, + TG1 : 31..30, + SH1 : 29..28, + ORGN1 : 27..26, + IRGN1 : 25..24, + EPD1 : 23..23, + A1 : 22..22, + T1SZ : 21..16, + TG0 : 15..14, + SH0 : 13..12, + ORGN0 : 11..10, + IRGN0 : 9..8, + EPD0 : 7..7, + T0SZ : 5..0 + } + +register TCR_EL1 : TCR_EL1_Type + +bitfield TCR_EL2_Type : bits(64) = + { + MTX1 : 61..61, + MTX0 : 60..60, + TCMA1 : 58..58, + TCMA0 : 57..57, + E0PD1 : 56..56, + E0PD0 : 55..55, + NFD1 : 54..54, + NFD0 : 53..53, + TBID1 : 52..52, + TBID0 : 51..51, + HWU162 : 50..50, + HWU161 : 49..49, + HWU160 : 48..48, + HWU159 : 47..47, + HWU062 : 46..46, + HWU061 : 45..45, + HWU060 : 44..44, + HWU059 : 43..43, + HPD1 : 42..42, + HPD0 : 41..41, + TBI1 : 38..38, + TBI0 : 37..37, + AS : 36..36, + MTX : 33..33, + IPS : 34..32, + TG1 : 31..30, + TCMA : 30..30, + TBID : 29..29, + SH1 : 29..28, + HWU62 : 28..28, + HWU61 : 27..27, + ORGN1 : 27..26, + HWU60 : 26..26, + HWU59 : 25..25, + IRGN1 : 25..24, + HPD : 24..24, + EPD1 : 23..23, + A1 : 22..22, + TBI : 20..20, + T1SZ : 21..16, + PS : 18..16, + TG0 : 15..14, + SH0 : 13..12, + ORGN0 : 11..10, + IRGN0 : 9..8, + EPD0 : 7..7, + T0SZ : 5..0 + } + +register TCR_EL2 : TCR_EL2_Type + +bitfield TCR_EL3_Type : bits(64) = + { + DisCH0 : 43..43, + HAFT : 42..42, + PTTWI : 41..41, + D128 : 38..38, + AIE : 37..37, + POE : 36..36, + PIE : 35..35, + PnCH : 34..34, + MTX : 33..33, + DS : 32..32, + TCMA : 30..30, + TBID : 29..29, + HWU62 : 28..28, + HWU61 : 27..27, + HWU60 : 26..26, + HWU59 : 25..25, + HPD : 24..24, + HD : 22..22, + HA : 21..21, + TBI : 20..20, + PS : 18..16, + TG0 : 15..14, + SH0 : 13..12, + ORGN0 : 11..10, + IRGN0 : 9..8, + T0SZ : 5..0 + } + +register TCR_EL3 : TCR_EL3_Type + +val EffectiveTBI : forall ('IsInstr : Bool). + (bits(64), bool('IsInstr), bits(2)) -> bits(1) + +function EffectiveTBI (address, IsInstr, el) = { + tbi : bits(1) = undefined; + tbid : bits(1) = undefined; + assert(HaveEL(el)); + let regime : bits(2) = S1TranslationRegime(el); + assert(not_bool(ELUsingAArch32(regime))); + match regime { + ? if ? == EL1 => { + tbi = if [address[55]] == 0b1 then TCR_EL1[TBI1] else TCR_EL1[TBI0]; + if HavePACExt() then { + tbid = if [address[55]] == 0b1 then TCR_EL1[TBID1] else + TCR_EL1[TBID0] + }; + () + }, + ? if ? == EL2 => { + if HaveVirtHostExt() & ELIsInHost(el) then { + tbi = if [address[55]] == 0b1 then TCR_EL2[TBI1] else + TCR_EL2[TBI0]; + if HavePACExt() then { + tbid = if [address[55]] == 0b1 then TCR_EL2[TBID1] else + TCR_EL2[TBID0] + }; + () + } else { + tbi = TCR_EL2[TBI]; + if HavePACExt() then { + tbid = TCR_EL2[TBID] + }; + () + } + }, + ? if ? == EL3 => { + tbi = TCR_EL3[TBI]; + if HavePACExt() then { + tbid = TCR_EL3[TBID] + }; + () + }, + _ => () + }; + return(if tbi == 0b1 & ((not_bool(HavePACExt()) | tbid == 0b0) | not_bool(IsInstr)) then + 0b1 + else + 0b0) +} + +val AddrTop : forall ('IsInstr : Bool). + (bits(64), bool('IsInstr), bits(2)) -> int + +function AddrTop (address, IsInstr, el) = { + assert(HaveEL(el)); + let regime : bits(2) = S1TranslationRegime(el); + if ELUsingAArch32(regime) then { + return(31) + } else { + if EffectiveTBI(address, IsInstr, el) == 0b1 then { + return(55) + } else { + return(63) + } + } +} + +val IsInHost : unit -> bool + +function IsInHost () = { + return(ELIsInHost(PSTATE.EL)) +} + +val AArch64_BranchAddr : (bits(64), bits(2)) -> bits(64) + +function AArch64_BranchAddr (vaddress, el) = { + assert(not_bool(UsingAArch32())); + let 'msbit = AddrTop(vaddress, true, el); + if msbit == 63 then { + return(vaddress) + } else { + assert(constraint((0 <= 'msbit & 'msbit < 64))); + if ((el == EL0 | el == EL1) | IsInHost()) & [vaddress[msbit]] == 0b1 then { + return(SignExtend(vaddress[msbit .. 0], 64)) + } else { + return(ZeroExtend(vaddress[msbit .. 0], 64)) + } + } +} + +val BRBEMispredictAllowed : unit -> bool + +function BRBEMispredictAllowed () = { + if HaveEL(EL2) & BRBCR_EL2[MPRED] == 0b0 then { + return(false) + }; + if BRBCR_EL1[MPRED] == 0b0 then { + return(false) + }; + return(true) +} + +val BRBCycleCountingEnabled : unit -> bool + +function BRBCycleCountingEnabled () = { + if HaveEL(EL2) & BRBCR_EL2[CC] == 0b0 then { + return(false) + }; + if BRBCR_EL1[CC] == 0b0 then { + return(false) + }; + return(true) +} + +val BranchRawCycleCount : unit -> int + +function BranchRawCycleCount () = { + let 'diff = __cycle_count - __last_cycle_count; + __last_cycle_count = __cycle_count; + return(diff) +} + +val FirstBranchAfterProhibited : unit -> bool + +function FirstBranchAfterProhibited () = { + return(not_bool(__last_branch_valid)) +} + +val BranchEncCycleCount : unit -> (bits(1), bits(14)) + +function BranchEncCycleCount () = { + cc : int = BranchRawCycleCount(); + if not_bool(BRBCycleCountingEnabled()) | FirstBranchAfterProhibited() then { + return((0b1, Zeros(14))) + }; + E : bits(6) = undefined; + M : bits(8) = undefined; + if cc < pow2(8) then { + E = Zeros(6); + M = cc[7 .. 0] + } else if cc >= pow2(20) then { + E = Ones(6); + M = Ones(8) + } else { + E = 1[5 .. 0]; + while cc >= pow2(9) do { + E = E + 1; + cc = DIV(cc, 2) + }; + let 'cc = cc; + M = cc[7 .. 0] + }; + return((0b0, E @ M)) +} + +val BranchMispredict : unit -> bool + +function BranchMispredict () = { + return(false) +} + +val FilterBranchRecord : forall ('cond : Bool). + (BranchType, bool('cond)) -> bool + +function FilterBranchRecord (br, cond) = { + match br { + BranchType_DIRCALL => { + return(BRBFCR_EL1[DIRCALL] != BRBFCR_EL1[EnI]) + }, + BranchType_INDCALL => { + return(BRBFCR_EL1[INDCALL] != BRBFCR_EL1[EnI]) + }, + BranchType_RET => { + return(BRBFCR_EL1[RTN] != BRBFCR_EL1[EnI]) + }, + BranchType_DIR => { + if cond then { + return(BRBFCR_EL1[CONDDIR] != BRBFCR_EL1[EnI]) + } else { + return(BRBFCR_EL1[DIRECT] != BRBFCR_EL1[EnI]) + } + }, + BranchType_INDIR => { + return(BRBFCR_EL1[INDIRECT] != BRBFCR_EL1[EnI]) + }, + _ => { + Unreachable() + } + }; + return(false) +} + +val HaveTME : unit -> bool + +function HaveTME () = { + return(IsFeatureImplemented(FEAT_TME)) +} + +val CurrentInstrSet : unit -> InstrSet + +function CurrentInstrSet () = { + result : InstrSet = undefined; + if UsingAArch32() then { + result = if PSTATE.T == 0b0 then InstrSet_A32 else InstrSet_T32 + } else { + result = InstrSet_A64 + }; + return(result) +} + +val BadMode : bits(5) -> bool + +function BadMode mode = { + valid_name : bool = undefined; + match mode { + ? if ? == M32_Monitor => { + valid_name = HaveAArch32EL(EL3) + }, + ? if ? == M32_Hyp => { + valid_name = HaveAArch32EL(EL2) + }, + ? if ? == M32_FIQ => { + valid_name = HaveAArch32EL(EL1) + }, + ? if ? == M32_IRQ => { + valid_name = HaveAArch32EL(EL1) + }, + ? if ? == M32_Svc => { + valid_name = HaveAArch32EL(EL1) + }, + ? if ? == M32_Abort => { + valid_name = HaveAArch32EL(EL1) + }, + ? if ? == M32_Undef => { + valid_name = HaveAArch32EL(EL1) + }, + ? if ? == M32_System => { + valid_name = HaveAArch32EL(EL1) + }, + ? if ? == M32_User => { + valid_name = HaveAArch32EL(EL0) + }, + _ => { + valid_name = false + } + }; + let valid_name = valid_name; + return(not_bool(valid_name)) +} + +val RBankSelect : forall 'usr 'fiq 'irq 'svc 'abt 'und 'hyp. + (bits(5), int('usr), int('fiq), int('irq), int('svc), int('abt), int('und), int('hyp)) -> {'n, ('n == 'usr | 'n == 'fiq | 'n == 'irq | 'n == 'svc | 'n == 'abt | 'n == 'und | 'n == 'hyp). int('n)} + +function RBankSelect (mode, usr, fiq, irq, svc, abt, und, hyp) = { + match mode { + ? if ? == M32_User => usr, + ? if ? == M32_FIQ => fiq, + ? if ? == M32_IRQ => irq, + ? if ? == M32_Svc => svc, + ? if ? == M32_Abort => abt, + ? if ? == M32_Hyp => hyp, + ? if ? == M32_Undef => und, + ? if ? == M32_System => usr + } +} + +val LookUpRIndex : forall 'n, ('n >= 0 & 'n <= 15). + (int('n), bits(5)) -> {'m, (0 <= 'm & 'm <= 30). int('m)} + +function LookUpRIndex (n, mode) = { + assert(n >= 0 & n <= 14); + match n { + 8 => { + return(RBankSelect(mode, 8, 24, 8, 8, 8, 8, 8)) + }, + 9 => { + return(RBankSelect(mode, 9, 25, 9, 9, 9, 9, 9)) + }, + 10 => { + return(RBankSelect(mode, 10, 26, 10, 10, 10, 10, 10)) + }, + 11 => { + return(RBankSelect(mode, 11, 27, 11, 11, 11, 11, 11)) + }, + 12 => { + return(RBankSelect(mode, 12, 28, 12, 12, 12, 12, 12)) + }, + 13 => { + return(RBankSelect(mode, 13, 29, 17, 19, 21, 23, 15)) + }, + 14 => { + return(RBankSelect(mode, 14, 30, 16, 18, 20, 22, 14)) + }, + _ => { + return(n) + } + } +} + +val Rmode_read : forall 'n. (int('n), bits(5)) -> bits(32) + +function Rmode_read (n, mode) = { + assert(n >= 0 & n <= 14); + if CurrentSecurityState() != SS_Secure then { + assert(mode != M32_Monitor) + }; + assert(not_bool(BadMode(mode))); + if mode == M32_Monitor then { + if n == 13 then { + return(SP_mon) + } else if n == 14 then { + return(LR_mon) + } else { + return(_R(n)[31 .. 0]) + } + } else { + return(_R(LookUpRIndex(n, mode))[31 .. 0]) + } +} + +val R_read : forall 'n. int('n) -> bits(32) + +function R_read n = { + offset : int = undefined; + if n == 15 then { + let 'offset = if CurrentInstrSet() == InstrSet_A32 then 8 else 4; + return(_PC[31 .. 0] + offset) + } else { + return(Rmode_read(n, PSTATE.M)) + } +} + +val PC_read : unit -> bits(64) + +val PC_read__1 : unit -> bits(32) + +function PC_read () = { + return(_PC) +} + +function PC_read__1 () = { + return(R_read(15)) +} + +bitfield BRBIDR0_EL1_Type : bits(64) = + {CC : 15..12, FORMAT : 11..8, NUMREC : 7..0} + +register BRBIDR0_EL1 : BRBIDR0_EL1_Type + +val GetBRBENumRecords : unit -> int + +function GetBRBENumRecords () = { + assert(UInt(BRBIDR0_EL1[NUMREC]) == UInt(0x08) | UInt(BRBIDR0_EL1[NUMREC]) == UInt(0x10) | UInt(BRBIDR0_EL1[NUMREC]) == UInt(0x20) | UInt(BRBIDR0_EL1[NUMREC]) == UInt(0x40)); + return(__IMPDEF_integer("Number of BRB records")) +} + +register Records_INF : vector(64, BRBINFType) + +register Records_SRC : vector(64, BRBSRCType) + +register Records_TGT : vector(64, BRBTGTType) + +val UpdateBranchRecordBuffer : (bits(1), bits(14), bits(1), bits(1), bits(6), bits(2), bits(1), bits(2), bits(64), bits(64)) -> unit + +function UpdateBranchRecordBuffer (ccu, cc, lastfailed, transactional, branch_type, el, mispredict, valid_name, source_address, target_address) = { + foreach (i from (GetBRBENumRecords() - 1) to 1 by 1 in dec) { + assert(constraint('loop_i < 64)); + Records_SRC[i] = Records_SRC[i - 1]; + Records_TGT[i] = Records_TGT[i - 1]; + Records_INF[i] = Records_INF[i - 1] + }; + Records_INF[0][CCU] = ccu; + Records_INF[0][CC] = cc; + Records_INF[0][EL] = el; + Records_INF[0][VALID] = valid_name; + Records_INF[0][T] = transactional; + Records_INF[0][LASTFAILED] = lastfailed; + Records_INF[0][MPRED] = mispredict; + Records_INF[0][TYPE] = branch_type; + Records_SRC[0] = Mk_BRBSRCType(source_address); + Records_TGT[0] = Mk_BRBTGTType(target_address); + return() +} + +val BRBEBranch : forall ('cond : Bool). + (BranchType, bool('cond), bits(64)) -> unit + +function BRBEBranch (br_type, cond, target_address) = { + let branch_valid : bool = BranchRecordAllowed(PSTATE.EL); + if branch_valid & FilterBranchRecord(br_type, cond) then { + branch_type : bits(6) = undefined; + match br_type { + BranchType_DIR => { + branch_type = if cond then 0b001000 else 0b000000 + }, + BranchType_INDIR => { + branch_type = 0b000001 + }, + BranchType_DIRCALL => { + branch_type = 0b000010 + }, + BranchType_INDCALL => { + branch_type = 0b000011 + }, + BranchType_RET => { + branch_type = 0b000101 + }, + _ => { + Unreachable() + } + }; + ccu : bits(1) = undefined; + cc : bits(14) = undefined; + (ccu, cc) = BranchEncCycleCount(); + let lastfailed : bits(1) = if HaveTME() then BRBFCR_EL1[LASTFAILED] else + 0b0; + let transactional : bits(1) = if HaveTME() & TSTATE.depth > 0 then 0b1 + else + 0b0; + let el : bits(2) = PSTATE.EL; + let mispredict : bits(1) = if BRBEMispredictAllowed() & BranchMispredict() then + 0b1 + else + 0b0; + UpdateBranchRecordBuffer(ccu, cc, lastfailed, transactional, branch_type, el, mispredict, 0b11, PC_read(), target_address); + BRBFCR_EL1[LASTFAILED] = 0b0; + PMUEvent(PMU_EVENT_BRB_FILTRATE) + }; + __last_branch_valid = branch_valid; + return() +} + +val HaveBRBExt : unit -> bool + +function HaveBRBExt () = { + return(IsFeatureImplemented(FEAT_BRBE)) +} + +val HaveStatisticalProfiling : unit -> bool + +function HaveStatisticalProfiling () = { + return(IsFeatureImplemented(FEAT_SPE)) +} + +val Hint_Branch : BranchType -> unit + +bitfield PMSIDR_EL1_Type : bits(64) = + { + CRR : 25..25, + PBT : 24..24, + Format : 23..20, + CountSize : 19..16, + MaxSize : 15..12, + Interval : 11..8, + FDS : 7..7, + FnE : 6..6, + ERnd : 5..5, + LDS : 4..4, + ArchInst : 3..3, + FL : 2..2, + FT : 1..1, + FE : 0..0 + } + +register PMSIDR_EL1 : PMSIDR_EL1_Type + +register SPESampleAddress : vector(32, bits(64)) + +register SPESampleAddressValid : vector(32, bool) + +bitfield PMSCR_EL1_Type : bits(64) = + {PCT : 7..6, TS : 5..5, PA : 4..4, CX : 3..3, E1SPE : 1..1, E0SPE : 0..0} + +register PMSCR_EL1 : PMSCR_EL1_Type + +bitfield PMSCR_EL2_Type : bits(64) = + {PCT : 7..6, TS : 5..5, PA : 4..4, CX : 3..3, E2SPE : 1..1, E0HSPE : 0..0} + +register PMSCR_EL2 : PMSCR_EL2_Type + +bitfield PMBLIMITR_EL1_Type : bits(64) = + {LIMIT : 63..12, PMFZ : 5..5, FM : 2..1, E : 0..0} + +register PMBLIMITR_EL1 : PMBLIMITR_EL1_Type + +bitfield PMBSR_EL1_Type : bits(64) = + { + AssuredOnly : 39..39, + Overlay : 38..38, + DirtyBit : 37..37, + EC : 31..26, + DL : 19..19, + EA : 18..18, + S : 17..17, + COLL : 16..16, + MSS : 15..0 + } + +register PMBSR_EL1 : PMBSR_EL1_Type + +val ProfilingBufferOwner : unit -> (SecurityState, bits(2)) + +function ProfilingBufferOwner () = { + owning_ss : SecurityState = undefined; + if HaveEL(EL3) then { + state_bits : bits(3) = undefined; + if HaveRME() then { + state_bits = MDCR_EL3[NSPBE] @ MDCR_EL3[NSPB]; + if (match state_bits { + [bitone, bitzero, _] => true, + _ => false + }) : bool | not_bool(HaveSecureEL2Ext()) & (match state_bits { + [bitzero, bitzero, _] => true, + _ => false + }) : bool then { + let (_, __tup_1 : bits(3)) = ConstrainUnpredictableBits(Unpredictable_RESERVEDNSxB, 3); + state_bits = __tup_1 + }; + () + } else { + state_bits = 0b0 @ MDCR_EL3[NSPB] + }; + match state_bits { + [bitzero, bitzero, _] => { + owning_ss = SS_Secure + }, + [bitzero, bitone, _] => { + owning_ss = SS_NonSecure + }, + [bitone, bitone, _] => { + owning_ss = SS_Realm + }, + _ => () + } + } else { + owning_ss = if SecureOnlyImplementation() then SS_Secure else + SS_NonSecure + }; + owning_el : bits(2) = undefined; + if HaveEL(EL2) & (owning_ss != SS_Secure | IsSecureEL2Enabled()) then { + owning_el = if MDCR_EL2[E2PB] == 0b00 then EL2 else EL1 + } else { + owning_el = EL1 + }; + return((owning_ss, owning_el)) +} + +val ProfilingBufferEnabled : unit -> bool + +function ProfilingBufferEnabled () = { + owning_el : bits(2) = undefined; + owning_ss : SecurityState = undefined; + if not_bool(HaveStatisticalProfiling()) then { + return(false) + }; + (owning_ss, owning_el) = ProfilingBufferOwner(); + state_bits : bits(2) = undefined; + if HaveRME() then { + state_bits = SCR_EL3[NSE] @ EffectiveSCR_EL3_NS() + } else { + state_bits = 0b0 @ SCR_EL3[NS] + }; + state_match : bool = undefined; + match owning_ss { + SS_Secure => { + state_match = state_bits == 0b00 + }, + SS_NonSecure => { + state_match = state_bits == 0b01 + }, + SS_Realm => { + state_match = state_bits == 0b11 + }, + _ => () + }; + return(((not_bool(ELUsingAArch32(owning_el)) & state_match) & PMBLIMITR_EL1[E] == 0b1) & PMBSR_EL1[S] == 0b0) +} + +val StatisticalProfilingEnabled : unit -> bool + +val StatisticalProfilingEnabled__1 : bits(2) -> bool + +function StatisticalProfilingEnabled () = { + return(StatisticalProfilingEnabled__1(PSTATE.EL)) +} + +function StatisticalProfilingEnabled__1 el = { + owning_el : bits(2) = undefined; + owning_ss : SecurityState = undefined; + if (not_bool(HaveStatisticalProfiling()) | UsingAArch32()) | not_bool(ProfilingBufferEnabled()) then { + return(false) + }; + let tge_set : bool = EL2Enabled() & HCR_EL2[TGE] == 0b1; + (owning_ss, owning_el) = ProfilingBufferOwner(); + if (UInt(owning_el) < UInt(el) | tge_set & owning_el == EL1) | owning_ss != SecurityStateAtEL(el) then { + return(false) + }; + spe_bit : bits(1) = undefined; + match el { + ? if ? == EL3 => { + Unreachable() + }, + ? if ? == EL2 => { + spe_bit = PMSCR_EL2[E2SPE] + }, + ? if ? == EL1 => { + spe_bit = PMSCR_EL1[E1SPE] + }, + ? if ? == EL0 => { + spe_bit = if tge_set then PMSCR_EL2[E0HSPE] else PMSCR_EL1[E0SPE] + }, + _ => () + }; + return(spe_bit == 0b1) +} + +val SPEBranch : forall 'N ('conditional : Bool) ('taken_flag : Bool), + 'N >= 0. + (bits('N), BranchType, bool('conditional), bool('taken_flag)) -> unit + +val SPEBranch__1 : forall 'N ('conditional : Bool) ('is_isb : Bool) ('taken_flag : Bool), + 'N >= 0. + (bits('N), BranchType, bool('conditional), bool('taken_flag), bool('is_isb)) -> unit + +function SPEBranch (target, branch_type, conditional, taken_flag) = { + let is_isb : bool = false; + SPEBranch__1(target, branch_type, conditional, taken_flag, is_isb) +} + +function SPEBranch__1 (target, branch_type, conditional, taken_flag, is_isb) = { + is_direct : bool = undefined; + collect_prev_br : bool = undefined; + let collect_prev_br_eret : bool = __IMPDEF_boolean("SPE prev br on eret"); + let collect_prev_br_exception : bool = __IMPDEF_boolean("SPE prev br on exception"); + let collect_prev_br_isb : bool = __IMPDEF_boolean("SPE prev br on isb"); + match branch_type { + BranchType_EXCEPTION => { + collect_prev_br = collect_prev_br_exception + }, + BranchType_ERET => { + collect_prev_br = collect_prev_br_eret + }, + _ => { + collect_prev_br = not_bool(is_isb) | collect_prev_br_isb + } + }; + let collect_prev_br = collect_prev_br; + if ((taken_flag & not_bool(IsZero(PMSIDR_EL1[PBT]))) & StatisticalProfilingEnabled()) & collect_prev_br then { + if SPESampleInFlight then { + let previous_target : bits(64) = SPESamplePreviousBranchAddress; + SPESampleAddress[SPEAddrPosPrevBranchTarget][63 .. 0] = previous_target[63 .. 0]; + let previous_branch_valid : bool = SPESamplePreviousBranchAddressValid; + SPESampleAddressValid[SPEAddrPosPrevBranchTarget] = previous_branch_valid + }; + assert(constraint(55 < 'N)); + SPESamplePreviousBranchAddress[55 .. 0] = target[55 .. 0]; + ns : bits(1) = undefined; + nse : bits(1) = undefined; + match CurrentSecurityState() { + SS_Secure => { + ns = 0b0; + nse = 0b0 + }, + SS_NonSecure => { + ns = 0b1; + nse = 0b0 + }, + SS_Realm => { + ns = 0b1; + nse = 0b1 + }, + _ => { + Unreachable() + } + }; + SPESamplePreviousBranchAddress[63] = Bit(ns); + SPESamplePreviousBranchAddress[60] = Bit(nse); + SPESamplePreviousBranchAddress[62 .. 61] = PSTATE.EL; + SPESamplePreviousBranchAddressValid = true + }; + if not_bool(StatisticalProfilingEnabled()) then { + if taken_flag then { + SPESamplePreviousBranchAddressValid = false + }; + return() + }; + if SPESampleInFlight then { + let is_direct : bool = branch_type == BranchType_DIR | branch_type == BranchType_DIRCALL; + SPESampleClass = 0b10; + SPESampleSubclass[1] = Bit(if is_direct then 0b0 else 0b1); + SPESampleSubclass[0] = Bit(if conditional then 0b1 else 0b0); + SPESampleOpType = OpType_Branch; + if taken_flag then { + assert(constraint(55 < 'N)); + SPESampleAddress[SPEAddrPosBranchTarget][55 .. 0] = target[55 .. 0]; + ns : bits(1) = undefined; + nse : bits(1) = undefined; + match CurrentSecurityState() { + SS_Secure => { + ns = 0b0; + nse = 0b0 + }, + SS_NonSecure => { + ns = 0b1; + nse = 0b0 + }, + SS_Realm => { + ns = 0b1; + nse = 0b1 + }, + _ => { + Unreachable() + } + }; + SPESampleAddress[SPEAddrPosBranchTarget][63] = Bit(ns); + SPESampleAddress[SPEAddrPosBranchTarget][60] = Bit(nse); + SPESampleAddress[SPEAddrPosBranchTarget][62 .. 61] = PSTATE.EL; + SPESampleAddressValid[SPEAddrPosBranchTarget] = true + }; + SPESampleEvents[6] = Bit(if not_bool(taken_flag) then 0b1 else 0b0) + }; + () +} + +val BranchTo : forall 'N ('branch_conditional : Bool), 'N >= 0. + (bits('N), BranchType, bool('branch_conditional)) -> unit + +function BranchTo (target, branch_type, branch_conditional) = { + Hint_Branch(branch_type); + if 'N == 32 then { + assert(UsingAArch32()); + _PC = ZeroExtend(target, 64) + } else { + assert('N == 64 & not_bool(UsingAArch32())); + let target_vaddress : bits(64) = AArch64_BranchAddr(target[63 .. 0], PSTATE.EL); + if HaveBRBExt() & (branch_type == BranchType_DIR | branch_type == BranchType_INDIR | branch_type == BranchType_DIRCALL | branch_type == BranchType_INDCALL | branch_type == BranchType_RET) then { + BRBEBranch(branch_type, branch_conditional, target_vaddress) + }; + let branch_taken : bool = true; + if HaveStatisticalProfiling() then { + SPEBranch(target, branch_type, branch_conditional, branch_taken) + }; + sail_branch_announce(64, target_vaddress); + _PC = target_vaddress + }; + __BranchTaken = true; + return() +} + +val ClearExclusiveLocal : forall 'processorid. int('processorid) -> unit + +val DiscardTransactionalWrites : unit -> unit + +val ProcessorID : unit -> int + +val FloorPow2 : forall 'x. int('x) -> nat + +function FloorPow2 x = { + assert(x >= 0); + n : {'n, 'n > 0. int('n)} = 1; + if x == 0 then { + return(0) + }; + while x >= pow2(n) do { + n = n + 1 + }; + let 'n = n; + let r = 2 ^ (n - 1); + assert(r >= 0); + return(r) +} + +val CeilPow2 : forall 'x. int('x) -> nat + +function CeilPow2 x = { + if x == 0 then { + return(0) + }; + if x == 1 then { + return(2) + }; + return(FloorPow2(x - 1) * 2) +} + +val IsPow2 : forall 'x. int('x) -> bool + +function IsPow2 x = { + if x <= 0 then { + return(false) + }; + return(FloorPow2(x) == CeilPow2(x)) +} + +val MaxImplementedVL : unit -> int + +val ImplementedSVEVectorLength : int -> vector_length + +function ImplementedSVEVectorLength nbits_in = { + let 'maxbits = MaxImplementedVL(); + assert((128 <= maxbits & maxbits <= 2048) & IsPow2(maxbits)); + nbits : int = Min(nbits_in, maxbits); + assert((128 <= nbits & nbits <= 2048) & Align(nbits, 128) == nbits); + while nbits > 128 do { + if IsPow2(nbits) then { + let 'nbits = nbits; + assert(constraint(is_VL('nbits))); + return(nbits) + }; + nbits = nbits - 128 + }; + let 'nbits = nbits; + assert(constraint(is_VL('nbits))); + return(nbits) +} + +bitfield ZCR_EL1_Type : bits(64) = {LEN : 3..0} + +register ZCR_EL1 : ZCR_EL1_Type + +bitfield ZCR_EL2_Type : bits(64) = {LEN : 3..0} + +register ZCR_EL2 : ZCR_EL2_Type + +bitfield ZCR_EL3_Type : bits(64) = {LEN : 3..0} + +register ZCR_EL3 : ZCR_EL3_Type + +val CurrentNSVL_read : unit -> vector_length + +function CurrentNSVL_read () = { + vl : int = undefined; + if PSTATE.EL == EL1 | PSTATE.EL == EL0 & not_bool(IsInHost()) then { + vl = UInt(ZCR_EL1[LEN]) + }; + if PSTATE.EL == EL2 | PSTATE.EL == EL0 & IsInHost() then { + vl = UInt(ZCR_EL2[LEN]) + } else if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled() then { + vl = Min(vl, UInt(ZCR_EL2[LEN])) + } else (); + if PSTATE.EL == EL3 then { + vl = UInt(ZCR_EL3[LEN]) + } else if HaveEL(EL3) then { + vl = Min(vl, UInt(ZCR_EL3[LEN])) + } else (); + vl : int = (vl + 1) * 128; + let 'vl = ImplementedSVEVectorLength(vl); + return(vl) +} + +val MaxImplementedSVL : unit -> int + +val SupportedPowerTwoSVL : forall 'nbits. int('nbits) -> bool + +val ImplementedSMEVectorLength : forall 'nbits_in. + int('nbits_in) -> vector_length + +function ImplementedSMEVectorLength nbits_in = { + let 'maxbits = MaxImplementedSVL(); + assert(constraint(is_VL('maxbits))); + nbits : int = Min(nbits_in, maxbits); + assert((128 <= nbits & nbits <= 2048) & Align(nbits, 128) == nbits); + while nbits > 128 do { + if IsPow2(nbits) & SupportedPowerTwoSVL(nbits) then { + let 'nbits = nbits; + assert(constraint(is_VL('nbits))); + return(nbits) + }; + nbits = nbits - 128 + }; + nbits : int = 128; + while nbits < maxbits do { + if SupportedPowerTwoSVL(nbits) then { + let 'nbits = nbits; + assert(constraint(is_VL('nbits))); + return(nbits) + }; + nbits = nbits * 2 + }; + return(maxbits) +} + +bitfield SMCR_EL1_Type : bits(64) = {FA64 : 31..31, EZT0 : 30..30, LEN : 3..0} + +register SMCR_EL1 : SMCR_EL1_Type + +bitfield SMCR_EL2_Type : bits(64) = {FA64 : 31..31, EZT0 : 30..30, LEN : 3..0} + +register SMCR_EL2 : SMCR_EL2_Type + +bitfield SMCR_EL3_Type : bits(64) = {FA64 : 31..31, EZT0 : 30..30, LEN : 3..0} + +register SMCR_EL3 : SMCR_EL3_Type + +val CurrentSVL_read : unit -> vector_length + +function CurrentSVL_read () = { + vl : int = undefined; + if PSTATE.EL == EL1 | PSTATE.EL == EL0 & not_bool(IsInHost()) then { + vl = UInt(SMCR_EL1[LEN]) + }; + if PSTATE.EL == EL2 | PSTATE.EL == EL0 & IsInHost() then { + vl = UInt(SMCR_EL2[LEN]) + } else if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled() then { + vl = Min(vl, UInt(SMCR_EL2[LEN])) + } else (); + if PSTATE.EL == EL3 then { + vl = UInt(SMCR_EL3[LEN]) + } else if HaveEL(EL3) then { + vl = Min(vl, UInt(SMCR_EL3[LEN])) + } else (); + vl : int = (vl + 1) * 128; + let 'vl = ImplementedSMEVectorLength(vl); + return(vl) +} + +val HaveSME : unit -> bool + +function HaveSME () = { + return(IsFeatureImplemented(FEAT_SME)) +} + +val CurrentVL_read : unit -> vector_length + +function CurrentVL_read () = { + let 'SVL = CurrentSVL_read(); + return(if HaveSME() & PSTATE.SM == 0b1 then SVL else CurrentNSVL_read()) +} + +val FFR_set : forall 'width, 'width >= 0. (int('width), bits('width)) -> unit + +function FFR_set (width, value_name) = { + let 'VL = CurrentVL_read(); + assert(width == DIV(VL, 8)); + if ConstrainUnpredictableBool(Unpredictable_SVEZEROUPPER) then { + _FFR = ZeroExtend(value_name, MAX_PL) + } else { + _FFR[width - 1 .. 0] = value_name + } +} + +bitfield GCSPR_EL0_Type : bits(64) = {PTR : 63..3} + +register GCSPR_EL0 : GCSPR_EL0_Type + +bitfield GCSPR_EL1_Type : bits(64) = {PTR : 63..3} + +register GCSPR_EL1 : GCSPR_EL1_Type + +bitfield GCSPR_EL2_Type : bits(64) = {PTR : 63..3} + +register GCSPR_EL2 : GCSPR_EL2_Type + +bitfield GCSPR_EL3_Type : bits(64) = {PTR : 63..3} + +register GCSPR_EL3 : GCSPR_EL3_Type + +val HaveGCS : unit -> bool + +function HaveGCS () = { + return(IsFeatureImplemented(FEAT_GCS)) +} + +bitfield CPACR_EL1_Type : bits(64) = + {E0POE : 29..29, TTA : 28..28, SMEN : 25..24, FPEN : 21..20, ZEN : 17..16} + +register CPACR_EL1 : CPACR_EL1_Type + +bitfield CPTR_EL2_Type : bits(64) = + { + TCPAC : 31..31, + TAM : 30..30, + E0POE : 29..29, + SMEN : 25..24, + FPEN : 21..20, + ZEN : 17..16, + TSM : 12..12, + TFP : 10..10, + TZ : 8..8 + } + +register CPTR_EL2 : CPTR_EL2_Type + +bitfield CPTR_EL3_Type : bits(64) = + { + TCPAC : 31..31, + TAM : 30..30, + TTA : 20..20, + ESM : 12..12, + TFP : 10..10, + EZ : 8..8 + } + +register CPTR_EL3 : CPTR_EL3_Type + +val AArch64_IsFPEnabled : bits(2) -> bool + +function AArch64_IsFPEnabled el = { + if (el == EL0 | el == EL1) & not_bool(IsInHost()) then { + disabled : bool = undefined; + match CPACR_EL1[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = el == EL0 + }, + 0b11 => { + disabled = false + } + }; + let disabled = disabled; + if disabled then { + return(false) + }; + () + }; + if (el == EL0 | el == EL1 | el == EL2) & EL2Enabled() then { + if HaveVirtHostExt() & HCR_EL2[E2H] == 0b1 then { + disabled : bool = undefined; + match CPTR_EL2[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = el == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + let disabled = disabled; + if disabled then { + return(false) + }; + () + } else { + if CPTR_EL2[TFP] == 0b1 then { + return(false) + }; + () + } + }; + if HaveEL(EL3) then { + if CPTR_EL3[TFP] == 0b1 then { + return(false) + }; + () + }; + return(true) +} + +bitfield CPACR_Type : bits(32) = + {ASEDIS : 31..31, TRCDIS : 28..28, cp11 : 23..22, cp10 : 21..20} + +register _CPACR : CPACR_Type + +val CPACR_read__1 : unit -> CPACR_Type + +function CPACR_read__1 () = { + r : CPACR_Type = _CPACR; + r.bits[31 .. 0] = Slice(CPACR_EL1.bits, 0, 32); + return(r) +} + +bitfield HCPTR_Type : bits(32) = + { + TCPAC : 31..31, + TAM : 30..30, + TTA : 20..20, + TASE : 15..15, + TCP11 : 11..11, + TCP10 : 10..10 + } + +register _HCPTR : HCPTR_Type + +val HCPTR_read : unit -> HCPTR_Type + +function HCPTR_read () = { + r : HCPTR_Type = _HCPTR; + r.bits[31 .. 0] = Slice(CPTR_EL2.bits, 0, 32); + return(r) +} + +bitfield NSACR_Type : bits(32) = + {NSTRCDIS : 20..20, NSASEDIS : 15..15, cp11 : 11..11, cp10 : 10..10} + +register NSACR : NSACR_Type + +val AArch32_IsFPEnabled : bits(2) -> bool + +function AArch32_IsFPEnabled el = { + if el == EL0 & not_bool(ELUsingAArch32(EL1)) then { + return(AArch64_IsFPEnabled(el)) + }; + if (HaveEL(EL3) & ELUsingAArch32(EL3)) & CurrentSecurityState() == SS_NonSecure then { + if NSACR[cp10] == 0b0 then { + return(false) + }; + () + }; + if el == EL0 | el == EL1 then { + disabled : bool = undefined; + match CPACR_read__1()[cp10] { + 0b00 => { + disabled = true + }, + 0b01 => { + disabled = el == EL0 + }, + 0b10 => { + disabled = ConstrainUnpredictableBool(Unpredictable_RESCPACR) + }, + 0b11 => { + disabled = false + } + }; + let disabled = disabled; + if disabled then { + return(false) + }; + () + }; + if (el == EL0 | el == EL1 | el == EL2) & EL2Enabled() then { + if not_bool(ELUsingAArch32(EL2)) then { + return(AArch64_IsFPEnabled(EL2)) + }; + if HCPTR_read()[TCP10] == 0b1 then { + return(false) + }; + () + }; + if HaveEL(EL3) & not_bool(ELUsingAArch32(EL3)) then { + if CPTR_EL3[TFP] == 0b1 then { + return(false) + }; + () + }; + return(true) +} + +val IsFPEnabled : bits(2) -> bool + +function IsFPEnabled el = { + if ELUsingAArch32(el) then { + return(AArch32_IsFPEnabled(el)) + } else { + return(AArch64_IsFPEnabled(el)) + } +} + +val HaveSVE : unit -> bool + +function HaveSVE () = { + return(IsFeatureImplemented(FEAT_SVE)) +} + +val IsOriginalSVEEnabled : bits(2) -> bool + +function IsOriginalSVEEnabled el = { + disabled : bool = undefined; + if ELUsingAArch32(el) then { + return(false) + }; + if (el == EL0 | el == EL1) & not_bool(IsInHost()) then { + match CPACR_EL1[ZEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = el == EL0 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + return(false) + }; + () + }; + if (el == EL0 | el == EL1 | el == EL2) & EL2Enabled() then { + if HaveVirtHostExt() & HCR_EL2[E2H] == 0b1 then { + match CPTR_EL2[ZEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = el == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + return(false) + }; + () + } else { + if CPTR_EL2[TZ] == 0b1 then { + return(false) + }; + () + } + }; + if HaveEL(EL3) then { + if CPTR_EL3[EZ] == 0b0 then { + return(false) + }; + () + }; + return(true) +} + +val IsSMEEnabled : bits(2) -> bool + +function IsSMEEnabled el = { + disabled : bool = undefined; + if ELUsingAArch32(el) then { + return(false) + }; + if (el == EL0 | el == EL1) & not_bool(IsInHost()) then { + match CPACR_EL1[SMEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = el == EL0 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + return(false) + }; + () + }; + if (el == EL0 | el == EL1 | el == EL2) & EL2Enabled() then { + if HaveVirtHostExt() & HCR_EL2[E2H] == 0b1 then { + match CPTR_EL2[SMEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = el == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + return(false) + }; + () + } else { + if CPTR_EL2[TSM] == 0b1 then { + return(false) + }; + () + } + }; + if HaveEL(EL3) then { + if CPTR_EL3[ESM] == 0b0 then { + return(false) + }; + () + }; + return(true) +} + +val IsSVEEnabled : bits(2) -> bool + +function IsSVEEnabled el = { + if HaveSME() & PSTATE.SM == 0b1 then { + return(IsSMEEnabled(el)) + } else if HaveSVE() then { + return(IsOriginalSVEEnabled(el)) + } else { + return(false) + } +} + +val P_set : forall 'n 'width, 'width >= 0. + (int('n), int('width), bits('width)) -> unit + +function P_set (n, width, value_name) = { + let 'VL = CurrentVL_read(); + assert(n >= 0 & n <= 31); + assert(width == DIV(VL, 8)); + if ConstrainUnpredictableBool(Unpredictable_SVEZEROUPPER) then { + assert(constraint((0 <= 'n & 'n < 16))); + _P[n] = ZeroExtend(value_name, MAX_PL) + } else { + assert(constraint((0 <= 'n & 'n < 16))); + _P[n][width - 1 .. 0] = value_name + } +} + +type SP_EL0_Type = bits(64) + +register SP_EL0 : SP_EL0_Type + +type SP_EL1_Type = bits(64) + +register SP_EL1 : SP_EL1_Type + +type SP_EL2_Type = bits(64) + +register SP_EL2 : SP_EL2_Type + +type SP_EL3_Type = bits(64) + +register SP_EL3 : SP_EL3_Type + +val SP_set : bits(64) -> unit + +function SP_set value_name = { + if PSTATE.SP == 0b0 then { + SP_EL0 = value_name + } else { + match PSTATE.EL { + ? if ? == EL0 => { + SP_EL0 = value_name + }, + ? if ? == EL1 => { + SP_EL1 = value_name + }, + ? if ? == EL2 => { + SP_EL2 = value_name + }, + ? if ? == EL3 => { + SP_EL3 = value_name + }, + _ => () + } + }; + return() +} + +val V_set : forall 'n 'width, + 'width in {8, 16, 32, 64, 128}. + (int('n), int('width), bits('width)) -> unit + +function V_set (n, width, value_name) = { + let 'VL = CurrentVL_read(); + assert(n >= 0 & n <= 31); + assert(width == 8 | width == 16 | width == 32 | width == 64 | width == 128); + let 'vlen = if IsSVEEnabled(PSTATE.EL) then VL else 128; + if ConstrainUnpredictableBool(Unpredictable_SVEZEROUPPER) then { + _Z[n] = ZeroExtend(value_name, MAX_VL) + } else { + _Z[n][vlen - 1 .. 0] = ZeroExtend(value_name, vlen) + } +} + +val X_set : forall 'n 'width, + 'width in {32, 64}. + (int('n), int('width), bits('width)) -> unit + +function X_set (n, width, value_name) = { + assert(n >= 0 & n <= 31); + assert(width == 32 | width == 64); + if n != 31 then { + _R(n) = ZeroExtend(value_name, 64) + }; + return() +} + +val Z_set : forall 'n 'width, 'width >= 0. + (int('n), int('width), bits('width)) -> unit + +function Z_set (n, width, value_name) = { + let 'VL = CurrentVL_read(); + assert(n >= 0 & n <= 31); + assert(width == VL); + if ConstrainUnpredictableBool(Unpredictable_SVEZEROUPPER) then { + _Z[n] = ZeroExtend(value_name, MAX_VL) + } else { + _Z[n][width - 1 .. 0] = value_name + } +} + +val RestoreTransactionCheckpointParameterised : forall 'pl 'vl, (is_VL('vl) & is_PL('pl)). + (int('vl), int('pl)) -> unit + +function RestoreTransactionCheckpointParameterised (vl, pl) = { + assert(((((((((((((((vl == 128 | vl == 256) | vl == 384) | vl == 512) | vl == 640) | vl == 768) | vl == 896) | vl == 1024) | vl == 1152) | vl == 1280) | vl == 1408) | vl == 1536) | vl == 1664) | vl == 1792) | vl == 1920) | vl == 2048); + SP_set() = TSTATE.SP; + ICC_PMR_EL1 = Mk_ICC_PMR_EL1_Type(TSTATE.ICC_PMR_EL1); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = TSTATE.nzcv; + (PSTATE.D @ PSTATE.A @ PSTATE.I @ PSTATE.F) = TSTATE.D @ (TSTATE.A @ (TSTATE.I @ TSTATE.F)); + foreach (n from 0 to 30 by 1 in inc) { + X_set(n, 64) = TSTATE.X[n] + }; + if IsFPEnabled(PSTATE.EL) then { + if IsSVEEnabled(PSTATE.EL) then { + foreach (n from 0 to 31 by 1 in inc) { + Z_set(n, vl) = TSTATE.Z[n][vl - 1 .. 0] + }; + foreach (n from 0 to 15 by 1 in inc) { + P_set(n, pl) = TSTATE.P[n][pl - 1 .. 0] + }; + FFR_set(pl) = TSTATE.FFR[pl - 1 .. 0] + } else { + foreach (n from 0 to 31 by 1 in inc) { + V_set(n, 128) = TSTATE.Z[n][127 .. 0] + } + }; + FPCR = Mk_FPCR_Type(TSTATE.FPCR); + FPSR = Mk_FPSR_Type(TSTATE.FPSR) + }; + if HaveGCS() then { + match PSTATE.EL { + ? if ? == EL0 => { + GCSPR_EL0 = Mk_GCSPR_EL0_Type(TSTATE.GCSPR_ELx) + }, + ? if ? == EL1 => { + GCSPR_EL1 = Mk_GCSPR_EL1_Type(TSTATE.GCSPR_ELx) + }, + ? if ? == EL2 => { + GCSPR_EL2 = Mk_GCSPR_EL2_Type(TSTATE.GCSPR_ELx) + }, + ? if ? == EL3 => { + GCSPR_EL3 = Mk_GCSPR_EL3_Type(TSTATE.GCSPR_ELx) + }, + _ => () + } + }; + return() +} + +val RestoreTransactionCheckpoint : unit -> unit + +function RestoreTransactionCheckpoint () = { + let 'VL = CurrentVL_read(); + let 'VL = VL; + match VL { + 128 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 256 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 384 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 512 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 640 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 768 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 896 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1024 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1152 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1280 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1408 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1536 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1664 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1792 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 1920 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + 2048 => { + RestoreTransactionCheckpointParameterised(VL, DIV(VL, 8)) + }, + _ => { + assert(false) + } + } +} + +val FailTransaction : forall ('retry : Bool). (TMFailure, bool('retry)) -> unit + +val FailTransaction__1 : forall ('interrupt : Bool) ('retry : Bool). + (TMFailure, bool('retry), bool('interrupt), bits(15)) -> unit + +function FailTransaction (cause, retry) = { + FailTransaction__1(cause, retry, false, Zeros(15)); + return() +} + +function FailTransaction__1 (cause, retry, interrupt, reason) = { + assert(not_bool(retry) | not_bool(interrupt)); + if HaveBRBExt() & BranchRecordAllowed(PSTATE.EL) then { + BRBFCR_EL1[LASTFAILED] = 0b1 + }; + DiscardTransactionalWrites(); + if cause != TMFailure_TRIVIAL then { + RestoreTransactionCheckpoint() + }; + ClearExclusiveLocal(ProcessorID()); + result : bits(64) = Zeros(64); + result[23] = Bit(if interrupt then 0b1 else 0b0); + result[15] = Bit(if retry & not_bool(interrupt) then 0b1 else 0b0); + match cause { + TMFailure_TRIVIAL => { + result[24] = Bit(0b1) + }, + TMFailure_DBG => { + result[22] = Bit(0b1) + }, + TMFailure_NEST => { + result[21] = Bit(0b1) + }, + TMFailure_SIZE => { + result[20] = Bit(0b1) + }, + TMFailure_ERR => { + result[19] = Bit(0b1) + }, + TMFailure_IMP => { + result[18] = Bit(0b1) + }, + TMFailure_MEM => { + result[17] = Bit(0b1) + }, + TMFailure_CNCL => { + result[16] = Bit(0b1); + result[14 .. 0] = reason + } + }; + TSTATE.depth = 0; + X_set(TSTATE.Rt, 64) = result; + let branch_conditional : bool = false; + BranchTo(TSTATE.nPC, BranchType_TMFAIL, branch_conditional); + EndOfInstruction(); + return() +} + +val HaveBTIExt : unit -> bool + +function HaveBTIExt () = { + return(IsFeatureImplemented(FEAT_BTI)) +} + +val HaveDITExt : unit -> bool + +function HaveDITExt () = { + return(IsFeatureImplemented(FEAT_DIT)) +} + +val HaveFeatNMI : unit -> bool + +function HaveFeatNMI () = { + return(IsFeatureImplemented(FEAT_NMI)) +} + +val HaveMTEExt : unit -> bool + +function HaveMTEExt () = { + return(IsFeatureImplemented(FEAT_MTE)) +} + +val HavePANExt : unit -> bool + +function HavePANExt () = { + return(IsFeatureImplemented(FEAT_PAN)) +} + +val HaveSSBSExt : unit -> bool + +function HaveSSBSExt () = { + return(IsFeatureImplemented(FEAT_SSBS)) +} + +val HaveUAOExt : unit -> bool + +function HaveUAOExt () = { + return(IsFeatureImplemented(FEAT_UAO)) +} + +val GetPSRFromPSTATE : forall 'N, 'N in {32, 64}. + (ExceptionalOccurrenceTargetState, int('N)) -> bits('N) + +function GetPSRFromPSTATE (targetELState, N) = { + if UsingAArch32() & targetELState == AArch32_NonDebugState then { + assert(N == 32) + } else { + assert(N == 64) + }; + spsr : bits('N) = Zeros(N); + spsr[31 .. 28] = PSTATE.N @ (PSTATE.Z @ (PSTATE.C @ PSTATE.V)); + if HavePANExt() then { + spsr[22] = Bit(PSTATE.PAN) + }; + spsr[20] = Bit(PSTATE.IL); + if PSTATE.nRW == 0b1 then { + spsr[27] = Bit(PSTATE.Q); + spsr[26 .. 25] = PSTATE.IT[1 .. 0]; + if HaveSSBSExt() then { + spsr[23] = Bit(PSTATE.SSBS) + }; + if HaveDITExt() then { + if targetELState == AArch32_NonDebugState then { + spsr[21] = Bit(PSTATE.DIT) + } else { + spsr[24] = Bit(PSTATE.DIT) + } + }; + if targetELState == AArch64_NonDebugState | targetELState == DebugState then { + spsr[21] = Bit(PSTATE.SS) + }; + spsr[19 .. 16] = PSTATE.GE; + spsr[15 .. 10] = PSTATE.IT[7 .. 2]; + spsr[9] = Bit(PSTATE.E); + spsr[8 .. 6] = PSTATE.A @ (PSTATE.I @ PSTATE.F); + spsr[5] = Bit(PSTATE.T); + assert([PSTATE.M[4]] == PSTATE.nRW); + spsr[4 .. 0] = PSTATE.M + } else { + if HaveMTEExt() then { + spsr[25] = Bit(PSTATE.TCO) + }; + if HaveGCS() then { + assert(constraint(34 < 'N)); + spsr[34] = Bit(PSTATE.EXLOCK) + }; + if HaveDITExt() then { + spsr[24] = Bit(PSTATE.DIT) + }; + if HaveUAOExt() then { + spsr[23] = Bit(PSTATE.UAO) + }; + spsr[21] = Bit(PSTATE.SS); + if HaveFeatNMI() then { + spsr[13] = Bit(PSTATE.ALLINT) + }; + if HaveSSBSExt() then { + spsr[12] = Bit(PSTATE.SSBS) + }; + if HaveBTIExt() then { + spsr[11 .. 10] = PSTATE.BTYPE + }; + spsr[9 .. 6] = PSTATE.D @ (PSTATE.A @ (PSTATE.I @ PSTATE.F)); + spsr[4] = Bit(PSTATE.nRW); + spsr[3 .. 2] = PSTATE.EL; + spsr[0] = Bit(PSTATE.SP) + }; + return(spsr) +} + +val Havev8p9Debug : unit -> bool + +function Havev8p9Debug () = { + return(IsFeatureImplemented(FEAT_Debugv8p9)) +} + +val StopInstructionPrefetchAndEnableITR : unit -> unit + +val ThisInstrAddr : forall 'N, 'N >= 0. int('N) -> bits('N) + +function ThisInstrAddr N = { + assert(N == 64 | N == 32 & UsingAArch32()); + return(_PC[N - 1 .. 0]) +} + +val UpdateEDSCRFields : unit -> unit + +function UpdateEDSCRFields () = { + ss : SecurityState = undefined; + if not_bool(Halted()) then { + EDSCR_write() = [EDSCR_read() with EL = 0b00]; + if HaveRME() then { + EDSCR_write() = [EDSCR_read() with SDD = if ExternalRootInvasiveDebugEnabled() then + 0b0 + else + 0b1]; + { + __tmp : EDSCR_Type = EDSCR_read(); + (__tmp[NSE] @ __tmp[NS]) = __UNKNOWN_bits(2); + EDSCR_write() = __tmp + } + } else { + EDSCR_write() = [EDSCR_read() with SDD = if ExternalSecureInvasiveDebugEnabled() then + 0b0 + else + 0b1]; + EDSCR_write() = [EDSCR_read() with NS = __UNKNOWN_bit()] + }; + EDSCR_write() = [EDSCR_read() with RW = 0b1111] + } else { + EDSCR_write() = [EDSCR_read() with EL = PSTATE.EL]; + let ss : SecurityState = CurrentSecurityState(); + if HaveRME() then { + match ss { + SS_Secure => { + { + __tmp : EDSCR_Type = EDSCR_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b00; + EDSCR_write() = __tmp + } + }, + SS_NonSecure => { + { + __tmp : EDSCR_Type = EDSCR_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b01; + EDSCR_write() = __tmp + } + }, + SS_Root => { + { + __tmp : EDSCR_Type = EDSCR_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b10; + EDSCR_write() = __tmp + } + }, + SS_Realm => { + { + __tmp : EDSCR_Type = EDSCR_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b11; + EDSCR_write() = __tmp + } + } + } + } else { + EDSCR_write() = [EDSCR_read() with NS = if ss == SS_Secure then 0b0 + else + 0b1] + }; + RW : bits(4) = undefined; + RW[1] = Bit(if ELUsingAArch32(EL1) then 0b0 else 0b1); + if PSTATE.EL != EL0 then { + RW[0] = Bit([RW[1]]) + } else { + RW[0] = Bit(if UsingAArch32() then 0b0 else 0b1) + }; + if not_bool(HaveEL(EL2)) | (HaveEL(EL3) & SCR_GEN_read()[NS] == 0b0) & not_bool(IsSecureEL2Enabled()) then { + RW[2] = Bit([RW[1]]) + } else { + RW[2] = Bit(if ELUsingAArch32(EL2) then 0b0 else 0b1) + }; + if not_bool(HaveEL(EL3)) then { + RW[3] = Bit([RW[2]]) + } else { + RW[3] = Bit(if ELUsingAArch32(EL3) then 0b0 else 0b1) + }; + if [RW[3]] == 0b0 then { + RW[2 .. 0] = __UNKNOWN_bits(3) + } else if [RW[2]] == 0b0 then { + RW[1 .. 0] = __UNKNOWN_bits(2) + } else if [RW[1]] == 0b0 then { + RW[0] = Bit(__UNKNOWN_bit()) + } else (); + EDSCR_write() = [EDSCR_read() with RW] + }; + return() +} + +val Halt : bits(6) -> unit + +val Halt__1 : forall ('is_async : Bool). (bits(6), bool('is_async)) -> unit + +function Halt reason = { + let is_async : bool = false; + Halt__1(reason, is_async) +} + +function Halt__1 (reason, is_async) = { + if HaveTME() & TSTATE.depth > 0 then { + FailTransaction(TMFailure_DBG, false) + }; + CTI_SignalEvent(CrossTriggerIn_CrossHalt); + let preferred_restart_address : bits(64) = ThisInstrAddr(64); + spsr : bits(64) = GetPSRFromPSTATE(DebugState, 64); + if ((HaveBTIExt() & not_bool(is_async)) & not_bool(reason == DebugHalt_Step_Normal | reason == DebugHalt_Step_Exclusive | reason == DebugHalt_Step_NoSyndrome | reason == DebugHalt_Breakpoint | reason == DebugHalt_HaltInstruction)) & ConstrainUnpredictableBool(Unpredictable_ZEROBTYPE) then { + spsr[11 .. 10] = 0b00 + }; + if UsingAArch32() then { + DLR_write() = preferred_restart_address[31 .. 0]; + DSPSR_write() = Mk_DSPSR_Type(spsr[31 .. 0]); + if Havev8p9Debug() then { + DSPSR2_write() = Mk_DSPSR2_Type(spsr[63 .. 32]) + }; + () + } else { + DLR_EL0 = preferred_restart_address; + DSPSR_EL0 = Mk_DSPSR_EL0_Type(spsr) + }; + EDSCR_write() = [EDSCR_read() with ITE = 0b1]; + EDSCR_write() = [EDSCR_read() with ITO = 0b0]; + if HaveRME() then { + if PSTATE.EL == EL3 then { + EDSCR_write() = [EDSCR_read() with SDD = 0b0] + } else { + EDSCR_write() = [EDSCR_read() with SDD = if ExternalRootInvasiveDebugEnabled() then + 0b0 + else + 0b1] + } + } else if CurrentSecurityState() == SS_Secure then { + EDSCR_write() = [EDSCR_read() with SDD = 0b0] + } else if HaveEL(EL3) then { + EDSCR_write() = [EDSCR_read() with SDD = if ExternalSecureInvasiveDebugEnabled() then + 0b0 + else + 0b1] + } else { + EDSCR_write() = [EDSCR_read() with SDD = 0b1] + }; + EDSCR_write() = [EDSCR_read() with MA = 0b0]; + if UsingAArch32() then { + (PSTATE.IT @ PSTATE.SS @ PSTATE.SSBS @ PSTATE.A @ PSTATE.I @ PSTATE.F @ PSTATE.T) = __UNKNOWN_bits(14) + } else { + (PSTATE.SS @ PSTATE.SSBS @ PSTATE.D @ PSTATE.A @ PSTATE.I @ PSTATE.F) = __UNKNOWN_bits(6); + PSTATE.TCO = 0b1; + PSTATE.BTYPE = 0b00 + }; + PSTATE.IL = 0b0; + StopInstructionPrefetchAndEnableITR(); + EDSCR_write() = [EDSCR_read() with STATUS = reason]; + UpdateEDSCRFields(); + if not_bool(is_async) then { + EndOfInstruction() + }; + return() +} + +bitfield DBGOSDLR_Type : bits(32) = {DLK : 0..0} + +bitfield OSDLR_EL1_Type : bits(64) = {DLK : 0..0} + +register OSDLR_EL1 : OSDLR_EL1_Type + +register _DBGOSDLR : DBGOSDLR_Type + +val DBGOSDLR_read : unit -> DBGOSDLR_Type + +function DBGOSDLR_read () = { + r : DBGOSDLR_Type = _DBGOSDLR; + r.bits[31 .. 0] = Slice(OSDLR_EL1.bits, 0, 32); + return(r) +} + +bitfield DBGPRCR_EL1_Type : bits(64) = {CORENPDRQ : 0..0} + +register DBGPRCR_EL1 : DBGPRCR_EL1_Type + +bitfield DBGPRCR_Type : bits(32) = {CORENPDRQ : 0..0} + +register _DBGPRCR : DBGPRCR_Type + +val DBGPRCR_read : unit -> DBGPRCR_Type + +function DBGPRCR_read () = { + r : DBGPRCR_Type = _DBGPRCR; + r.bits[31 .. 0] = Slice(DBGPRCR_EL1.bits, 0, 32); + return(r) +} + +val HaveDoubleLock : unit -> bool + +function HaveDoubleLock () = { + return(IsFeatureImplemented(FEAT_DoubleLock)) +} + +val DoubleLockStatus : unit -> bool + +function DoubleLockStatus () = { + if not_bool(HaveDoubleLock()) then { + return(false) + } else if ELUsingAArch32(EL1) then { + return((DBGOSDLR_read()[DLK] == 0b1 & DBGPRCR_read()[CORENPDRQ] == 0b0) & not_bool(Halted())) + } else { + return((OSDLR_EL1[DLK] == 0b1 & DBGPRCR_EL1[CORENPDRQ] == 0b0) & not_bool(Halted())) + } +} + +val HaltingAllowed : unit -> bool + +function HaltingAllowed () = { + if Halted() | DoubleLockStatus() then { + return(false) + }; + let ss : SecurityState = CurrentSecurityState(); + match ss { + SS_NonSecure => { + return(ExternalInvasiveDebugEnabled()) + }, + SS_Secure => { + return(ExternalSecureInvasiveDebugEnabled()) + }, + SS_Root => { + return(ExternalRootInvasiveDebugEnabled()) + }, + SS_Realm => { + return(ExternalRealmInvasiveDebugEnabled()) + }, + _ => { + return(undefined : bool) + } + } +} + +val HavePMUv3p9 : unit -> bool + +function HavePMUv3p9 () = { + return(IsFeatureImplemented(FEAT_PMUv3p9)) +} + +val SetInterruptRequestLevel : (InterruptID, Signal) -> unit + +val ShouldBRBEFreeze : unit -> bool + +function ShouldBRBEFreeze () = { + if not_bool(BranchRecordAllowed(PSTATE.EL)) then { + return(false) + }; + let check_e : bool = false; + let check_cnten : bool = false; + let check_inten : bool = false; + let exclude_sync : bool = false; + let exclude_cyc : bool = true; + include_lo_name : bool = undefined; + include_hi_name : bool = undefined; + if HaveEL(EL2) then { + include_lo_name = BRBCR_EL1[FZP] == 0b1; + include_hi_name = BRBCR_EL2[FZP] == 0b1 + } else { + include_lo_name = true; + include_hi_name = true + }; + return(PMUOverflowCondition(check_e, check_cnten, check_inten, include_hi_name, include_lo_name, exclude_cyc, exclude_sync)) +} + +val CheckForPMUOverflow : unit -> unit + +function CheckForPMUOverflow () = { + let check_cnten : bool = false; + let check_e : bool = true; + let check_inten : bool = true; + let include_lo_name : bool = true; + let include_hi_name : bool = true; + let exclude_cyc : bool = false; + let exclude_sync : bool = false; + let pmuirq : bool = PMUOverflowCondition(check_e, check_cnten, check_inten, include_hi_name, include_lo_name, exclude_cyc, exclude_sync); + SetInterruptRequestLevel(InterruptID_PMUIRQ, if pmuirq then Signal_High else + Signal_Low); + CTI_SetEventLevel(CrossTriggerIn_PMUOverflow, if pmuirq then Signal_High + else + Signal_Low); + if HavePMUv3p9() & Havev8p9Debug() then { + if (pmuirq & HaltingAllowed()) & EDECR[PME] == 0b1 then { + Halt(DebugHalt_EDBGRQ) + }; + () + }; + if ShouldBRBEFreeze() then { + BRBEFreeze() + }; + return() +} + +val IsAligned__1 : forall 'N 'y, 'N >= 0. (bits('N), int('y)) -> bool + +function IsAligned__1 (x, y) = { + return(x == Align(x, y)) +} + +val Split : forall 'M 'N, + 'M > 'N & 'M >= 0 & 0 <= 'N - 1. + (bits('M), int('N)) -> (bits('M - 'N), bits('N)) + +function Split (value_name, N) = { + assert('M > N); + return((value_name['M - 1 .. N], value_name[N - 1 .. 0])) +} + +val RShr : forall ('round : Bool) 'shift 'value_name. + (int('value_name), int('shift), bool('round)) -> int + +function RShr (value_name, shift, round) = { + assert(shift > 0); + if round then { + return(((value_name + (1 << (shift - 1))) >> shift)) + } else { + return((value_name >> shift)) + } +} + +val IsHighestEL : bits(2) -> bool + +function IsHighestEL el = { + return(HighestEL() == el) +} + +val HaveFP16Ext : unit -> bool + +val EffectiveSCR_EL3_NSE : unit -> bits(1) + +function EffectiveSCR_EL3_NSE () = { + return(if not_bool(HaveRME()) then 0b0 else SCR_EL3[NSE]) +} + +val ELFromM32 : bits(5) -> (bool, bits(2)) + +function ELFromM32 mode = { + el : bits(2) = undefined; + valid_name : bool = not_bool(BadMode(mode)); + let effective_nse_ns : bits(2) = EffectiveSCR_EL3_NSE() @ EffectiveSCR_EL3_NS(); + match mode { + ? if ? == M32_Monitor => { + el = EL3 + }, + ? if ? == M32_Hyp => { + el = EL2 + }, + ? if ? == M32_FIQ => { + el = if (HaveEL(EL3) & not_bool(HaveAArch64())) & SCR[NS] == 0b0 then + EL3 + else + EL1 + }, + ? if ? == M32_IRQ => { + el = if (HaveEL(EL3) & not_bool(HaveAArch64())) & SCR[NS] == 0b0 then + EL3 + else + EL1 + }, + ? if ? == M32_Svc => { + el = if (HaveEL(EL3) & not_bool(HaveAArch64())) & SCR[NS] == 0b0 then + EL3 + else + EL1 + }, + ? if ? == M32_Abort => { + el = if (HaveEL(EL3) & not_bool(HaveAArch64())) & SCR[NS] == 0b0 then + EL3 + else + EL1 + }, + ? if ? == M32_Undef => { + el = if (HaveEL(EL3) & not_bool(HaveAArch64())) & SCR[NS] == 0b0 then + EL3 + else + EL1 + }, + ? if ? == M32_System => { + el = if (HaveEL(EL3) & not_bool(HaveAArch64())) & SCR[NS] == 0b0 then + EL3 + else + EL1 + }, + ? if ? == M32_User => { + el = EL0 + }, + _ => { + valid_name = false + } + }; + if ((valid_name & el == EL2) & HaveEL(EL3)) & SCR_GEN_read()[NS] == 0b0 then { + valid_name = false + } else if (valid_name & HaveRME()) & effective_nse_ns == 0b10 then { + valid_name = false + } else (); + if not_bool(valid_name) then { + el = __UNKNOWN_bits(2) + }; + let el = el; + return((valid_name, el)) +} + +val ELFromSPSR : forall 'N, 4 < 'N. bits('N) -> (bool, bits(2)) + +function ELFromSPSR spsr = { + el : bits(2) = undefined; + valid_name : bool = undefined; + effective_nse_ns : bits(2) = undefined; + if [spsr[4]] == 0b0 then { + el = spsr[3 .. 2]; + let effective_nse_ns : bits(2) = EffectiveSCR_EL3_NSE() @ EffectiveSCR_EL3_NS(); + if not_bool(HaveAArch64()) then { + valid_name = false + } else if not_bool(HaveEL(el)) then { + valid_name = false + } else if [spsr[1]] == 0b1 then { + valid_name = false + } else if el == EL0 & [spsr[0]] == 0b1 then { + valid_name = false + } else if (HaveRME() & el != EL3) & effective_nse_ns == 0b10 then { + valid_name = false + } else if ((el == EL2 & HaveEL(EL3)) & not_bool(IsSecureEL2Enabled())) & SCR_EL3[NS] == 0b0 then { + valid_name = false + } else { + valid_name = true + } + } else if HaveAArch32() then { + (valid_name, el) = ELFromM32(spsr[4 .. 0]) + } else { + valid_name = false + }; + if not_bool(valid_name) then { + el = __UNKNOWN_bits(2) + }; + let el = el; + return((valid_name, el)) +} + +val ELUsingAArch32K : bits(2) -> (bool, bool) + +function ELUsingAArch32K el = { + return(ELStateUsingAArch32K(el, IsSecureBelowEL3())) +} + +bitfield GCSCR_EL1_Type : bits(64) = + {STREn : 9..9, PUSHMEn : 8..8, EXLOCKEN : 6..6, RVCHKEN : 5..5, PCRSEL : 0..0} + +register GCSCR_EL1 : GCSCR_EL1_Type + +bitfield GCSCR_EL2_Type : bits(64) = + {STREn : 9..9, PUSHMEn : 8..8, EXLOCKEN : 6..6, RVCHKEN : 5..5, PCRSEL : 0..0} + +register GCSCR_EL2 : GCSCR_EL2_Type + +bitfield GCSCR_EL3_Type : bits(64) = + {STREn : 9..9, PUSHMEn : 8..8, EXLOCKEN : 6..6, RVCHKEN : 5..5, PCRSEL : 0..0} + +register GCSCR_EL3 : GCSCR_EL3_Type + +val GetCurrentEXLOCKEN : unit -> bool + +function GetCurrentEXLOCKEN () = { + match PSTATE.EL { + ? if ? == EL0 => { + Unreachable(); + return(undefined : bool) + }, + ? if ? == EL1 => { + return(GCSCR_EL1[EXLOCKEN] == 0b1) + }, + ? if ? == EL2 => { + return(GCSCR_EL2[EXLOCKEN] == 0b1) + }, + ? if ? == EL3 => { + return(GCSCR_EL3[EXLOCKEN] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val IllegalExceptionReturn : forall 'N, 4 < 'N. bits('N) -> bool + +function IllegalExceptionReturn spsr = { + known : bool = undefined; + target : bits(2) = undefined; + target_el_is_aarch32 : bool = undefined; + valid_name : bool = undefined; + (valid_name, target) = ELFromSPSR(spsr); + if not_bool(valid_name) then { + return(true) + }; + if UInt(target) > UInt(PSTATE.EL) then { + return(true) + }; + let spsr_mode_is_aarch32 : bool = [spsr[4]] == 0b1; + (known, target_el_is_aarch32) = ELUsingAArch32K(target); + assert(known | target == EL0 & not_bool(ELUsingAArch32(EL1))); + if known & spsr_mode_is_aarch32 != target_el_is_aarch32 then { + return(true) + }; + if UsingAArch32() & not_bool(spsr_mode_is_aarch32) then { + return(true) + }; + if (HaveEL(EL2) & target == EL1) & HCR_EL2[TGE] == 0b1 then { + if not_bool(IsSecureBelowEL3()) | IsSecureEL2Enabled() then { + return(true) + }; + () + }; + if (((HaveGCS() & PSTATE.EXLOCK == 0b0) & PSTATE.EL == target) & GetCurrentEXLOCKEN()) & not_bool(Halted()) then { + return(true) + }; + return(false) +} + +val AArch32_WriteMode : bits(5) -> unit + +function AArch32_WriteMode mode = { + el : bits(2) = undefined; + valid_name : bool = undefined; + (valid_name, el) = ELFromM32(mode); + assert(valid_name); + PSTATE.M = mode; + PSTATE.EL = el; + PSTATE.nRW = 0b1; + PSTATE.SP = if mode == M32_User | mode == M32_System then 0b0 else 0b1; + return() +} + +val NonSecureOnlyImplementation : unit -> bool + +function NonSecureOnlyImplementation () = { + return(__IMPDEF_boolean("Non-secure only implementation")) +} + +val AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled : unit -> bool + +function AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled () = { + if not_bool(HaveEL(EL3)) & NonSecureOnlyImplementation() then { + return(false) + }; + return(DBGEN == Signal_High & SPIDEN == Signal_High) +} + +bitfield MDSCR_EL1_Type : bits(64) = + { + EHBWE : 35..35, + EnSPM : 34..34, + EMBWE : 32..32, + TFO : 31..31, + RXfull : 30..30, + TXfull : 29..29, + RXO : 27..27, + TXU : 26..26, + INTdis : 23..22, + TDA : 21..21, + SC2 : 19..19, + MDE : 15..15, + HDE : 14..14, + KDE : 13..13, + TDCC : 12..12, + ERR : 6..6, + SS : 0..0 + } + +register MDSCR_EL1 : MDSCR_EL1_Type + +bitfield OSLSR_EL1_Type : bits(64) = + {OSLM : (3..3 @ 0..0), nTT : 2..2, OSLK : 1..1} + +register OSLSR_EL1 : OSLSR_EL1_Type + +val AArch64_GenerateDebugExceptionsFrom : (bits(2), SecurityState, bits(1)) -> bool + +function AArch64_GenerateDebugExceptionsFrom (from_el, from_state, mask) = { + if (OSLSR_EL1[OSLK] == 0b1 | DoubleLockStatus()) | Halted() then { + return(false) + }; + let route_to_el2 : bool = (HaveEL(EL2) & (from_state != SS_Secure | IsSecureEL2Enabled())) & (HCR_EL2[TGE] == 0b1 | MDCR_EL2[TDE] == 0b1); + let target : bits(2) = if route_to_el2 then EL2 else EL1; + enabled : bool = undefined; + if HaveEL(EL3) & from_state == SS_Secure then { + enabled = MDCR_EL3[SDD] == 0b0; + if from_el == EL0 & ELUsingAArch32(EL1) then { + enabled = enabled | SDER32_EL3_read()[SUIDEN] == 0b1 + }; + () + } else { + enabled = true + }; + if from_el == target then { + enabled = (enabled & MDSCR_EL1[KDE] == 0b1) & mask == 0b0 + } else { + enabled = enabled & UInt(target) > UInt(from_el) + }; + return(enabled) +} + +bitfield DBGOSLSR_Type : bits(32) = + {OSLM : (3..3 @ 0..0), nTT : 2..2, OSLK : 1..1} + +register _DBGOSLSR : DBGOSLSR_Type + +val DBGOSLSR_read : unit -> DBGOSLSR_Type + +function DBGOSLSR_read () = { + r : DBGOSLSR_Type = _DBGOSLSR; + r.bits[31 .. 0] = Slice(OSLSR_EL1.bits, 0, 32); + return(r) +} + +bitfield HCR_Type : bits(32) = + { + TRVM : 30..30, + HCD : 29..29, + TGE : 27..27, + TVM : 26..26, + TTLB : 25..25, + TPU : 24..24, + TPC : 23..23, + TSW : 22..22, + TAC : 21..21, + TIDCP : 20..20, + TSC : 19..19, + TID3 : 18..18, + TID2 : 17..17, + TID1 : 16..16, + TID0 : 15..15, + TWE : 14..14, + TWI : 13..13, + DC : 12..12, + BSU : 11..10, + FB : 9..9, + VA : 8..8, + VI : 7..7, + VF : 6..6, + AMO : 5..5, + IMO : 4..4, + FMO : 3..3, + PTW : 2..2, + SWIO : 1..1, + VM : 0..0 + } + +register _HCR : HCR_Type + +val HCR_read : unit -> HCR_Type + +function HCR_read () = { + r : HCR_Type = _HCR; + r.bits[31 .. 0] = Slice(HCR_EL2.bits, 0, 32); + return(r) +} + +val DebugTargetFrom : SecurityState -> bits(2) + +function DebugTargetFrom from_state = { + route_to_el2 : bool = undefined; + if HaveEL(EL2) & (from_state != SS_Secure | HaveSecureEL2Ext() & (not_bool(HaveEL(EL3)) | SCR_EL3[EEL2] == 0b1)) then { + if ELUsingAArch32(EL2) then { + route_to_el2 = HDCR_read()[TDE] == 0b1 | HCR_read()[TGE] == 0b1 + } else { + route_to_el2 = MDCR_EL2[TDE] == 0b1 | HCR_EL2[TGE] == 0b1 + } + } else { + route_to_el2 = false + }; + target : bits(2) = undefined; + if route_to_el2 then { + target = EL2 + } else if (HaveEL(EL3) & not_bool(HaveAArch64())) & from_state == SS_Secure then { + target = EL3 + } else { + target = EL1 + }; + return(target) +} + +val AArch32_GenerateDebugExceptionsFrom : (bits(2), SecurityState) -> bool + +function AArch32_GenerateDebugExceptionsFrom (from_el, from_state) = { + mask : bits(1) = undefined; + spd : bits(2) = undefined; + if not_bool(ELUsingAArch32(DebugTargetFrom(from_state))) then { + let mask : bits(1) = 0b0; + return(AArch64_GenerateDebugExceptionsFrom(from_el, from_state, mask)) + }; + if (DBGOSLSR_read()[OSLK] == 0b1 | DoubleLockStatus()) | Halted() then { + return(false) + }; + enabled : bool = undefined; + if HaveEL(EL3) & from_state == SS_Secure then { + assert(from_el != EL2); + if IsSecureEL2Enabled() then { + enabled = MDCR_EL3[SDD] == 0b0 + } else { + let spd : bits(2) = if ELUsingAArch32(EL3) then SDCR[SPD] else + MDCR_EL3[SPD32]; + if [spd[1]] == 0b1 then { + enabled = [spd[0]] == 0b1 + } else { + enabled = AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled() + } + }; + if from_el == EL0 then { + enabled = enabled | SDER_read()[SUIDEN] == 0b1 + }; + () + } else { + enabled = from_el != EL2 + }; + return(enabled) +} + +val AArch32_GenerateDebugExceptions : unit -> bool + +function AArch32_GenerateDebugExceptions () = { + let ss : SecurityState = CurrentSecurityState(); + return(AArch32_GenerateDebugExceptionsFrom(PSTATE.EL, ss)) +} + +val AArch64_GenerateDebugExceptions : unit -> bool + +function AArch64_GenerateDebugExceptions () = { + let ss : SecurityState = CurrentSecurityState(); + return(AArch64_GenerateDebugExceptionsFrom(PSTATE.EL, ss, PSTATE.D)) +} + +val Restarting : unit -> bool + +function Restarting () = { + return(EDSCR_read()[STATUS] == 0b000001) +} + +val DebugExceptionReturnSS : forall 'N, 4 < 'N. bits('N) -> bits(1) + +function DebugExceptionReturnSS spsr = { + assert((Halted() | Restarting()) | PSTATE.EL != EL0); + enabled_at_source : bool = undefined; + if Restarting() then { + enabled_at_source = false + } else if UsingAArch32() then { + enabled_at_source = AArch32_GenerateDebugExceptions() + } else { + enabled_at_source = AArch64_GenerateDebugExceptions() + }; + valid_name : bool = undefined; + dest_el : bits(2) = undefined; + if IllegalExceptionReturn(spsr) then { + dest_el = PSTATE.EL + } else { + (valid_name, dest_el) = ELFromSPSR(spsr); + assert(valid_name) + }; + let dest_ss : SecurityState = SecurityStateAtEL(dest_el); + mask : bits(1) = undefined; + enabled_at_dest : bool = undefined; + let dest_using_32 : bool = if dest_el == EL0 then [spsr[4]] == 0b1 else + ELUsingAArch32(dest_el); + if dest_using_32 then { + enabled_at_dest = AArch32_GenerateDebugExceptionsFrom(dest_el, dest_ss) + } else { + assert(constraint(9 < 'N)); + let mask : bits(1) = [spsr[9]]; + enabled_at_dest = AArch64_GenerateDebugExceptionsFrom(dest_el, dest_ss, mask) + }; + let ELd : bits(2) = DebugTargetFrom(dest_ss); + SS_bit : bits(1) = undefined; + if ((not_bool(ELUsingAArch32(ELd)) & MDSCR_EL1[SS] == 0b1) & not_bool(enabled_at_source)) & enabled_at_dest then { + assert(constraint(21 < 'N)); + SS_bit = [spsr[21]] + } else { + SS_bit = 0b0 + }; + return(SS_bit) +} + +bitfield HSCTLR_Type : bits(32) = + { + DSSBS : 31..31, + TE : 30..30, + EE : 25..25, + WXN : 19..19, + I : 12..12, + SED : 8..8, + ITD : 7..7, + CP15BEN : 5..5, + LSMAOE : 4..4, + nTLSMD : 3..3, + C : 2..2, + A : 1..1, + M : 0..0 + } + +bitfield SCTLR_EL2_Type : bits(64) = + { + TIDCP : 63..63, + SPINTMASK : 62..62, + NMI : 61..61, + EnTP2 : 60..60, + TCSO : 59..59, + TCSO0 : 58..58, + EPAN : 57..57, + EnALS : 56..56, + EnAS0 : 55..55, + EnASR : 54..54, + TME : 53..53, + TME0 : 52..52, + TMT : 51..51, + TMT0 : 50..50, + TWEDEL : 49..46, + TWEDEn : 45..45, + DSSBS : 44..44, + ATA : 43..43, + ATA0 : 42..42, + TCF : 41..40, + TCF0 : 39..38, + ITFSB : 37..37, + BT : 36..36, + BT0 : 35..35, + MSCEn : 33..33, + CMOW : 32..32, + EnIA : 31..31, + EnIB : 30..30, + LSMAOE : 29..29, + nTLSMD : 28..28, + EnDA : 27..27, + UCI : 26..26, + EE : 25..25, + E0E : 24..24, + SPAN : 23..23, + EIS : 22..22, + IESB : 21..21, + TSCXT : 20..20, + WXN : 19..19, + nTWE : 18..18, + nTWI : 16..16, + UCT : 15..15, + DZE : 14..14, + EnDB : 13..13, + I : 12..12, + EOS : 11..11, + EnRCTX : 10..10, + SED : 8..8, + ITD : 7..7, + nAA : 6..6, + CP15BEN : 5..5, + SA0 : 4..4, + SA : 3..3, + C : 2..2, + A : 1..1, + M : 0..0 + } + +register SCTLR_EL2 : SCTLR_EL2_Type + +register _HSCTLR : HSCTLR_Type + +val HSCTLR_read : unit -> HSCTLR_Type + +function HSCTLR_read () = { + r : HSCTLR_Type = _HSCTLR; + r.bits[31 .. 0] = Slice(SCTLR_EL2.bits, 0, 32); + return(r) +} + +bitfield SCTLR_EL1_Type : bits(64) = + { + TIDCP : 63..63, + SPINTMASK : 62..62, + NMI : 61..61, + EnTP2 : 60..60, + TCSO : 59..59, + TCSO0 : 58..58, + EPAN : 57..57, + EnALS : 56..56, + EnAS0 : 55..55, + EnASR : 54..54, + TME : 53..53, + TME0 : 52..52, + TMT : 51..51, + TMT0 : 50..50, + TWEDEL : 49..46, + TWEDEn : 45..45, + DSSBS : 44..44, + ATA : 43..43, + ATA0 : 42..42, + TCF : 41..40, + TCF0 : 39..38, + ITFSB : 37..37, + BT1 : 36..36, + BT0 : 35..35, + MSCEn : 33..33, + CMOW : 32..32, + EnIA : 31..31, + EnIB : 30..30, + LSMAOE : 29..29, + nTLSMD : 28..28, + EnDA : 27..27, + UCI : 26..26, + EE : 25..25, + E0E : 24..24, + SPAN : 23..23, + EIS : 22..22, + IESB : 21..21, + TSCXT : 20..20, + WXN : 19..19, + nTWE : 18..18, + nTWI : 16..16, + UCT : 15..15, + DZE : 14..14, + EnDB : 13..13, + I : 12..12, + EOS : 11..11, + EnRCTX : 10..10, + UMA : 9..9, + SED : 8..8, + ITD : 7..7, + nAA : 6..6, + CP15BEN : 5..5, + SA0 : 4..4, + SA : 3..3, + C : 2..2, + A : 1..1, + M : 0..0 + } + +register SCTLR_EL1 : SCTLR_EL1_Type + +bitfield SCTLR_EL3_Type : bits(64) = + { + SPINTMASK : 62..62, + NMI : 61..61, + TCSO : 59..59, + TME : 53..53, + TMT : 51..51, + DSSBS : 44..44, + ATA : 43..43, + TCF : 41..40, + ITFSB : 37..37, + BT : 36..36, + EnIA : 31..31, + EnIB : 30..30, + EnDA : 27..27, + EE : 25..25, + EIS : 22..22, + IESB : 21..21, + WXN : 19..19, + EnDB : 13..13, + I : 12..12, + EOS : 11..11, + nAA : 6..6, + SA : 3..3, + C : 2..2, + A : 1..1, + M : 0..0 + } + +register SCTLR_EL3 : SCTLR_EL3_Type + +bitfield SCTLR_Type : bits(32) = + { + DSSBS : 31..31, + TE : 30..30, + AFE : 29..29, + TRE : 28..28, + EE : 25..25, + SPAN : 23..23, + UWXN : 20..20, + WXN : 19..19, + nTWE : 18..18, + nTWI : 16..16, + V : 13..13, + I : 12..12, + EnRCTX : 10..10, + SED : 8..8, + ITD : 7..7, + UNK : 6..6, + CP15BEN : 5..5, + LSMAOE : 4..4, + nTLSMD : 3..3, + C : 2..2, + A : 1..1, + M : 0..0 + } + +register _SCTLR_NS : SCTLR_Type + +val SCTLR_NS_read : unit -> SCTLR_Type + +function SCTLR_NS_read () = { + r : SCTLR_Type = _SCTLR_NS; + r.bits[31 .. 0] = Slice(SCTLR_EL1.bits, 0, 32); + return(r) +} + +register SCTLR_S : SCTLR_Type + +val SCTLR_read : bits(2) -> SCTLRType + +val SCTLR_read__1 : unit -> SCTLRType + +val SCTLR_read__2 : unit -> SCTLR_Type + +function SCTLR_read__2 () = { + r : SCTLR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = SCTLR_S; + r.bits[11] = Bit(0b1); + r.bits[22] = Bit(0b1) + } else { + r = SCTLR_NS_read(); + r.bits[11] = Bit(0b1); + r.bits[22] = Bit(0b1) + }; + return(r) +} + +function SCTLR_read regime = { + r : bits(64) = undefined; + match regime { + ? if ? == EL1 => { + r = SCTLR_EL1.bits + }, + ? if ? == EL2 => { + r = SCTLR_EL2.bits + }, + ? if ? == EL3 => { + r = SCTLR_EL3.bits + }, + _ => { + Unreachable() + } + }; + return(Mk_SCTLRType(r)) +} + +function SCTLR_read__1 () = { + return(SCTLR_read(S1TranslationRegime__1())) +} + +val RestoredITBits : forall 'N, 26 < 'N. bits('N) -> bits(8) + +function RestoredITBits spsr = { + let it : bits(8) = spsr[15 .. 10] @ spsr[26 .. 25]; + if PSTATE.IL == 0b1 then { + if ConstrainUnpredictableBool(Unpredictable_ILZEROIT) then { + return(0b00000000) + } else { + return(it) + } + }; + if not_bool(IsZero(it[7 .. 4])) & IsZero(it[3 .. 0]) then { + return(0b00000000) + }; + let itd : bits(1) = if PSTATE.EL == EL2 then HSCTLR_read()[ITD] else + SCTLR_read__2()[ITD]; + if [spsr[5]] == 0b0 & not_bool(IsZero(it)) | itd == 0b1 & not_bool(IsZero(it[2 .. 0])) then { + return(0b00000000) + } else { + return(it) + } +} + +val SetPSTATEFromPSR : forall 'N, 31 < 'N. bits('N) -> unit + +val SetPSTATEFromPSR__1 : forall 'N ('illegal_psr_state : Bool), 31 < 'N. + (bits('N), bool('illegal_psr_state)) -> unit + +function SetPSTATEFromPSR spsr = { + let illegal_psr_state : bool = IllegalExceptionReturn(spsr); + SetPSTATEFromPSR__1(spsr, illegal_psr_state) +} + +function SetPSTATEFromPSR__1 (spsr_in, illegal_psr_state) = { + spsr : bits('N) = spsr_in; + let from_aarch64 : bool = not_bool(UsingAArch32()); + PSTATE.SS = DebugExceptionReturnSS(spsr); + ShouldAdvanceSS = false; + if illegal_psr_state then { + PSTATE.IL = 0b1; + if HaveSSBSExt() then { + PSTATE.SSBS = __UNKNOWN_bit() + }; + if HaveBTIExt() then { + PSTATE.BTYPE = __UNKNOWN_bits(2) + }; + if HaveUAOExt() then { + PSTATE.UAO = __UNKNOWN_bit() + }; + if HaveDITExt() then { + PSTATE.DIT = __UNKNOWN_bit() + }; + if HaveMTEExt() then { + PSTATE.TCO = __UNKNOWN_bit() + }; + () + } else { + assert(constraint(20 < 'N)); + PSTATE.IL = [spsr[20]]; + if [spsr[4]] == 0b1 then { + AArch32_WriteMode(spsr[4 .. 0]); + if HaveSSBSExt() then { + assert(constraint(23 < 'N)); + PSTATE.SSBS = [spsr[23]] + }; + () + } else { + PSTATE.nRW = 0b0; + PSTATE.EL = spsr[3 .. 2]; + PSTATE.SP = [spsr[0]]; + if HaveBTIExt() then { + PSTATE.BTYPE = spsr[11 .. 10] + }; + if HaveSSBSExt() then { + PSTATE.SSBS = [spsr[12]] + }; + if HaveUAOExt() then { + assert(constraint(23 < 'N)); + PSTATE.UAO = [spsr[23]] + }; + if HaveDITExt() then { + assert(constraint(24 < 'N)); + PSTATE.DIT = [spsr[24]] + }; + if HaveMTEExt() then { + assert(constraint(25 < 'N)); + PSTATE.TCO = [spsr[25]] + }; + if HaveGCS() then { + assert(constraint(34 < 'N)); + PSTATE.EXLOCK = [spsr[34]] + }; + () + } + }; + if PSTATE.IL == 0b1 & PSTATE.nRW == 0b1 then { + if ConstrainUnpredictableBool(Unpredictable_ILZEROT) then { + assert(constraint(5 < 'N)); + spsr[5] = Bit(0b0) + }; + () + }; + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V) = spsr[31 .. 28]; + if HavePANExt() then { + PSTATE.PAN = [spsr[22]] + }; + if PSTATE.nRW == 0b1 then { + PSTATE.Q = [spsr[27]]; + PSTATE.IT = RestoredITBits(spsr); + ShouldAdvanceIT = false; + if HaveDITExt() then { + PSTATE.DIT = if Restarting() | from_aarch64 then [spsr[24]] else + [spsr[21]] + }; + PSTATE.GE = spsr[19 .. 16]; + PSTATE.E = [spsr[9]]; + (PSTATE.A @ PSTATE.I @ PSTATE.F) = spsr[8 .. 6]; + PSTATE.T = [spsr[5]] + } else { + if HaveFeatNMI() then { + PSTATE.ALLINT = [spsr[13]] + }; + (PSTATE.D @ PSTATE.A @ PSTATE.I @ PSTATE.F) = spsr[9 .. 6] + }; + return() +} + +val PLOfEL : bits(2) -> PrivilegeLevel + +function PLOfEL el = { + match el { + ? if ? == EL3 => { + return(if not_bool(HaveAArch64()) then PL1 else PL3) + }, + ? if ? == EL2 => { + return(PL2) + }, + ? if ? == EL1 => { + return(PL1) + }, + ? if ? == EL0 => { + return(PL0) + }, + _ => { + return(undefined : PrivilegeLevel) + } + } +} + +val IsCurrentSecurityState : SecurityState -> bool + +function IsCurrentSecurityState ss = { + return(CurrentSecurityState() == ss) +} + +val ConditionHolds : bits(4) -> bool + +function ConditionHolds cond = { + result : bool = undefined; + match cond[3 .. 1] { + 0b000 => { + result = PSTATE.Z == 0b1 + }, + 0b001 => { + result = PSTATE.C == 0b1 + }, + 0b010 => { + result = PSTATE.N == 0b1 + }, + 0b011 => { + result = PSTATE.V == 0b1 + }, + 0b100 => { + result = PSTATE.C == 0b1 & PSTATE.Z == 0b0 + }, + 0b101 => { + result = PSTATE.N == PSTATE.V + }, + 0b110 => { + result = PSTATE.N == PSTATE.V & PSTATE.Z == 0b0 + }, + 0b111 => { + result = true + } + }; + if [cond[0]] == 0b1 & cond != 0b1111 then { + result = not_bool(result) + }; + return(result) +} + +val AArch64_MaybeZeroRegisterUppers : unit -> unit + +function AArch64_MaybeZeroRegisterUppers () = { + assert(UsingAArch32()); + first : {'first, 'first == 0. int('first)} = 0; + last : {14, 30} = 14; + include_R15_name : bool = undefined; + if PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)) then { + first = 0; + last = 14; + include_R15_name = false + } else if ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & not_bool(ELUsingAArch32(EL2)) then { + first = 0; + last = 30; + include_R15_name = false + } else { + first = 0; + last = 30; + include_R15_name = true + }; + let 'last = last; + let 'first = first; + foreach (n from first to last by 1 in inc) { + if (n != 15 | include_R15_name) & ConstrainUnpredictableBool(Unpredictable_ZEROUPPER) then { + _R(n, 63, 32) = Zeros(32) + }; + () + }; + return() +} + +val ThisInstrLength : unit -> int + +val AArch64_ExceptionClass : (Exception, bits(2)) -> (int, bits(1)) + +function AArch64_ExceptionClass (exceptype, target_el) = { + il_is_valid : bool = true; + let from_32 : bool = UsingAArch32(); + ec : int = undefined; + match exceptype { + Exception_Uncategorized => { + ec = UInt(0x00); + il_is_valid = false + }, + Exception_WFxTrap => { + ec = UInt(0x01) + }, + Exception_CP15RTTrap => { + ec = UInt(0x03); + assert(from_32) + }, + Exception_CP15RRTTrap => { + ec = UInt(0x04); + assert(from_32) + }, + Exception_CP14RTTrap => { + ec = UInt(0x05); + assert(from_32) + }, + Exception_CP14DTTrap => { + ec = UInt(0x06); + assert(from_32) + }, + Exception_AdvSIMDFPAccessTrap => { + ec = UInt(0x07) + }, + Exception_FPIDTrap => { + ec = UInt(0x08) + }, + Exception_PACTrap => { + ec = UInt(0x09) + }, + Exception_LDST64BTrap => { + ec = UInt(0x0A) + }, + Exception_TSTARTAccessTrap => { + ec = UInt(0x1B) + }, + Exception_GPC => { + ec = UInt(0x1E) + }, + Exception_CP14RRTTrap => { + ec = UInt(0x0C); + assert(from_32) + }, + Exception_BranchTarget => { + ec = UInt(0x0D) + }, + Exception_IllegalState => { + ec = UInt(0x0E); + il_is_valid = false + }, + Exception_SupervisorCall => { + ec = UInt(0x11) + }, + Exception_HypervisorCall => { + ec = UInt(0x12) + }, + Exception_MonitorCall => { + ec = UInt(0x13) + }, + Exception_SystemRegisterTrap => { + ec = UInt(0x18); + assert(not_bool(from_32)) + }, + Exception_SystemRegister128Trap => { + ec = UInt(0x14); + assert(not_bool(from_32)) + }, + Exception_SVEAccessTrap => { + ec = UInt(0x19); + assert(not_bool(from_32)) + }, + Exception_ERetTrap => { + ec = UInt(0x1A); + assert(not_bool(from_32)) + }, + Exception_PACFail => { + ec = UInt(0x1C); + assert(not_bool(from_32)) + }, + Exception_SMEAccessTrap => { + ec = UInt(0x1D); + assert(not_bool(from_32)) + }, + Exception_InstructionAbort => { + ec = UInt(0x20); + il_is_valid = false + }, + Exception_PCAlignment => { + ec = UInt(0x22); + il_is_valid = false + }, + Exception_DataAbort => { + ec = UInt(0x24) + }, + Exception_NV2DataAbort => { + ec = UInt(0x25) + }, + Exception_SPAlignment => { + ec = UInt(0x26); + il_is_valid = false; + assert(not_bool(from_32)) + }, + Exception_MemCpyMemSet => { + ec = UInt(0x27) + }, + Exception_GCSFail => { + ec = UInt(0x2D); + assert(not_bool(from_32)) + }, + Exception_FPTrappedException => { + ec = UInt(0x28) + }, + Exception_SError => { + ec = UInt(0x2F); + il_is_valid = false + }, + Exception_Breakpoint => { + ec = UInt(0x30); + il_is_valid = false + }, + Exception_SoftwareStep => { + ec = UInt(0x32); + il_is_valid = false + }, + Exception_Watchpoint => { + ec = UInt(0x34); + il_is_valid = false + }, + Exception_NV2Watchpoint => { + ec = UInt(0x35); + il_is_valid = false + }, + Exception_SoftwareBreakpoint => { + ec = UInt(0x38) + }, + Exception_VectorCatch => { + ec = UInt(0x3A); + il_is_valid = false; + assert(from_32) + }, + _ => { + Unreachable() + } + }; + if (ec == UInt(0x20) | ec == UInt(0x24) | ec == UInt(0x30) | ec == UInt(0x32) | ec == UInt(0x34)) & target_el == PSTATE.EL then { + ec = ec + 1 + }; + if (ec == UInt(0x11) | ec == UInt(0x12) | ec == UInt(0x13) | ec == UInt(0x28) | ec == UInt(0x38)) & not_bool(from_32) then { + ec = ec + 4 + }; + let 'ec = ec; + il : bits(1) = undefined; + if il_is_valid then { + il = if ThisInstrLength() == 32 then 0b1 else 0b0 + } else { + il = 0b1 + }; + assert(from_32 | il == 0b1); + return((ec, il)) +} + +bitfield ESR_EL1_Type : bits(64) = + {ISS2 : 55..32, EC : 31..26, IL : 25..25, ISS : 24..0} + +register ESR_EL1 : ESR_EL1_Type + +bitfield ESR_EL2_Type : bits(64) = + {ISS2 : 55..32, EC : 31..26, IL : 25..25, ISS : 24..0} + +register ESR_EL2 : ESR_EL2_Type + +bitfield ESR_EL3_Type : bits(64) = + {ISS2 : 55..32, EC : 31..26, IL : 25..25, ISS : 24..0} + +register ESR_EL3 : ESR_EL3_Type + +val ESR_set : (bits(2), ESRType) -> unit + +val ESR_set__1 : ESRType -> unit + +function ESR_set (regime, value_name) = { + let r : bits(64) = value_name.bits; + match regime { + ? if ? == EL1 => { + ESR_EL1 = Mk_ESR_EL1_Type(r) + }, + ? if ? == EL2 => { + ESR_EL2 = Mk_ESR_EL2_Type(r) + }, + ? if ? == EL3 => { + ESR_EL3 = Mk_ESR_EL3_Type(r) + }, + _ => { + Unreachable() + } + }; + return() +} + +function ESR_set__1 value_name = { + ESR_set(S1TranslationRegime__1()) = value_name +} + +type FAR_EL1_Type = bits(64) + +register FAR_EL1 : FAR_EL1_Type + +type FAR_EL2_Type = bits(64) + +register FAR_EL2 : FAR_EL2_Type + +type FAR_EL3_Type = bits(64) + +register FAR_EL3 : FAR_EL3_Type + +val FAR_set : (bits(2), bits(64)) -> unit + +function FAR_set (regime, value_name) = { + let r : bits(64) = value_name; + match regime { + ? if ? == EL1 => { + FAR_EL1 = r + }, + ? if ? == EL2 => { + FAR_EL2 = r + }, + ? if ? == EL3 => { + FAR_EL3 = r + }, + _ => { + Unreachable() + } + }; + return() +} + +bitfield HPFAR_EL2_Type : bits(64) = {NS : 63..63, FIPA : 47..4} + +register HPFAR_EL2 : HPFAR_EL2_Type + +val HavePFAR : unit -> bool + +function HavePFAR () = { + return(IsFeatureImplemented(FEAT_PFAR)) +} + +bitfield MFAR_EL3_Type : bits(64) = + { + NS : 63..63, + NSE : 62..62, + PA : (55..52 @ (51..48 @ 47..0)), + FPA : (55..52 @ (51..48 @ 47..12)) + } + +register MFAR_EL3 : MFAR_EL3_Type + +bitfield PFAR_EL1_Type : bits(64) = + {NS : 63..63, NSE : 62..62, PA : (55..52 @ (51..48 @ 47..0))} + +register PFAR_EL1 : PFAR_EL1_Type + +bitfield PFAR_EL2_Type : bits(64) = + {NS : 63..63, NSE : 62..62, PA : (55..52 @ (51..48 @ 47..0))} + +register PFAR_EL2 : PFAR_EL2_Type + +val PFAR_set : (bits(2), bits(64)) -> unit + +function PFAR_set (regime, value_name) = { + let r : bits(64) = value_name; + assert(HavePFAR() | HaveRME() & regime == EL3); + match regime { + ? if ? == EL1 => { + PFAR_EL1 = Mk_PFAR_EL1_Type(r) + }, + ? if ? == EL2 => { + PFAR_EL2 = Mk_PFAR_EL2_Type(r) + }, + ? if ? == EL3 => { + MFAR_EL3 = Mk_MFAR_EL3_Type(r) + }, + _ => { + Unreachable() + } + }; + return() +} + +val AArch64_ReportException : (ExceptionRecord, bits(2)) -> unit + +function AArch64_ReportException (except, target_el) = { + ec : int = undefined; + il : bits(1) = undefined; + let exceptype : Exception = except.exceptype; + (ec, il) = AArch64_ExceptionClass(exceptype, target_el); + let 'ec = ec; + let iss : bits(25) = except.syndrome; + let iss2 : bits(24) = except.syndrome2; + if (ec == UInt(0x24) | ec == UInt(0x25)) & [iss[24]] == 0b0 then { + il = 0b1 + }; + let il = il; + ESR_set(target_el) = Mk_ESRType((((Zeros(8) @ iss2) @ ec[5 .. 0]) @ il) @ iss); + if exceptype == Exception_InstructionAbort | exceptype == Exception_PCAlignment | exceptype == Exception_DataAbort | exceptype == Exception_NV2DataAbort | exceptype == Exception_NV2Watchpoint | exceptype == Exception_GPC | exceptype == Exception_Watchpoint then { + FAR_set(target_el) = except.vaddress + } else { + FAR_set(target_el) = __UNKNOWN_bits(64) + }; + if except.ipavalid then { + HPFAR_EL2.bits[47 .. 4] = except.ipaddress[55 .. 12]; + if IsSecureEL2Enabled() & CurrentSecurityState() == SS_Secure then { + HPFAR_EL2[NS] = except.NS + } else { + HPFAR_EL2[NS] = 0b0 + } + } else if target_el == EL2 then { + HPFAR_EL2.bits[47 .. 4] = __UNKNOWN_bits(44) + } else (); + if except.pavalid then { + faultaddr : bits(64) = ZeroExtend(except.paddress.address, 64); + if HaveRME() then { + match except.paddress.paspace { + PAS_Secure => { + faultaddr[63 .. 62] = 0b00 + }, + PAS_NonSecure => { + faultaddr[63 .. 62] = 0b10 + }, + PAS_Root => { + faultaddr[63 .. 62] = 0b01 + }, + PAS_Realm => { + faultaddr[63 .. 62] = 0b11 + } + }; + if exceptype == Exception_GPC then { + faultaddr[11 .. 0] = Zeros(12) + }; + () + } else { + faultaddr[63] = Bit(if except.paddress.paspace == PAS_NonSecure then + 0b1 + else + 0b0) + }; + PFAR_set(target_el) = faultaddr + } else if HavePFAR() | HaveRME() & target_el == EL3 then { + PFAR_set(target_el) = __UNKNOWN_bits(64) + } else (); + return() +} + +type ELR_EL1_Type = bits(64) + +register ELR_EL1 : ELR_EL1_Type + +type ELR_EL2_Type = bits(64) + +register ELR_EL2 : ELR_EL2_Type + +type ELR_EL3_Type = bits(64) + +register ELR_EL3 : ELR_EL3_Type + +val ELR_set : (bits(2), bits(64)) -> unit + +val ELR_set__1 : bits(64) -> unit + +function ELR_set (el, value_name) = { + let r : bits(64) = value_name; + match el { + ? if ? == EL1 => { + ELR_EL1 = r + }, + ? if ? == EL2 => { + ELR_EL2 = r + }, + ? if ? == EL3 => { + ELR_EL3 = r + }, + _ => { + Unreachable() + } + }; + return() +} + +function ELR_set__1 value_name = { + assert(PSTATE.EL != EL0); + ELR_set(PSTATE.EL) = value_name; + return() +} + +val HaveDoubleFaultExt : unit -> bool + +function HaveDoubleFaultExt () = { + return(IsFeatureImplemented(FEAT_DoubleFault)) +} + +val HaveIESB : unit -> bool + +function HaveIESB () = { + return(IsFeatureImplemented(FEAT_IESB)) +} + +val MaybeZeroSVEUppers : bits(2) -> unit + +function MaybeZeroSVEUppers target_el = { + let 'SVL = CurrentSVL_read(); + let 'VL = CurrentVL_read(); + lower_enabled : bool = undefined; + if UInt(target_el) <= UInt(PSTATE.EL) | not_bool(IsSVEEnabled(target_el)) then { + return() + }; + if target_el == EL3 then { + if EL2Enabled() then { + lower_enabled = IsFPEnabled(EL2) + } else { + lower_enabled = IsFPEnabled(EL1) + } + } else if target_el == EL2 then { + assert(not_bool(ELUsingAArch32(EL2))); + if HCR_EL2[TGE] == 0b0 then { + lower_enabled = IsFPEnabled(EL1) + } else { + lower_enabled = IsFPEnabled(EL0) + } + } else { + assert(target_el == EL1 & not_bool(ELUsingAArch32(EL1))); + lower_enabled = IsFPEnabled(EL0) + }; + if lower_enabled then { + let 'VL = if IsSVEEnabled(PSTATE.EL) then VL else 128; + let 'PL = DIV(VL, 8); + foreach (n from 0 to 31 by 1 in inc) { + if ConstrainUnpredictableBool(Unpredictable_SVEZEROUPPER) then { + _Z[n] = ZeroExtend(_Z[n][VL - 1 .. 0], MAX_VL) + }; + () + }; + foreach (n from 0 to 15 by 1 in inc) { + if ConstrainUnpredictableBool(Unpredictable_SVEZEROUPPER) then { + _P[n] = ZeroExtend(_P[n][PL - 1 .. 0], MAX_PL) + }; + () + }; + if ConstrainUnpredictableBool(Unpredictable_SVEZEROUPPER) then { + _FFR = ZeroExtend(_FFR[PL - 1 .. 0], MAX_PL) + }; + if HaveSME() & PSTATE.ZA == 0b1 then { + let 'SVL = SVL; + let 'accessiblevecs = DIV(SVL, 8); + let 'allvecs = DIV(MaxImplementedSVL(), 8); + foreach (n from 0 to (accessiblevecs - 1) by 1 in inc) { + if ConstrainUnpredictableBool(Unpredictable_SMEZEROUPPER) then { + _ZA[n] = ZeroExtend(_ZA[n][SVL - 1 .. 0], MAX_VL) + }; + () + }; + foreach (n from accessiblevecs to (allvecs - 1) by 1 in inc) { + if ConstrainUnpredictableBool(Unpredictable_SMEZEROUPPER) then { + assert(constraint((0 <= 'loop_n & 'loop_n < 256))); + _ZA[n] = Zeros(MAX_VL) + }; + () + } + }; + () + }; + () +} + +val ResetSVEState : unit -> unit + +function ResetSVEState () = { + foreach (n from 0 to 31 by 1 in inc) { + _Z[n] = Zeros(MAX_VL) + }; + foreach (n from 0 to 15 by 1 in inc) { + _P[n] = Zeros(MAX_PL) + }; + _FFR = Zeros(MAX_PL); + FPSR = Mk_FPSR_Type(ZeroExtend(0x0800009f, 64)) +} + +bitfield SPSR_EL1_Type : bits(64) = + { + EXLOCK : 34..34, + PPEND : 33..33, + PM : 32..32, + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + TCO : 25..25, + DIT : 24..24, + UAO : 23..23, + PAN : 22..22, + SS : 21..21, + IL : 20..20, + GE : 19..16, + ALLINT : 13..13, + BTYPE : 11..10, + IT : (15..10 @ 26..25), + D : 9..9, + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5 + } + +register SPSR_EL1 : SPSR_EL1_Type + +bitfield SPSR_EL2_Type : bits(64) = + { + EXLOCK : 34..34, + PPEND : 33..33, + PM : 32..32, + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + TCO : 25..25, + DIT : 24..24, + UAO : 23..23, + PAN : 22..22, + SS : 21..21, + IL : 20..20, + GE : 19..16, + ALLINT : 13..13, + BTYPE : 11..10, + IT : (15..10 @ 26..25), + D : 9..9, + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5 + } + +register SPSR_EL2 : SPSR_EL2_Type + +bitfield SPSR_EL3_Type : bits(64) = + { + EXLOCK : 34..34, + PPEND : 33..33, + PM : 32..32, + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + TCO : 25..25, + DIT : 24..24, + UAO : 23..23, + PAN : 22..22, + SS : 21..21, + IL : 20..20, + GE : 19..16, + ALLINT : 13..13, + BTYPE : 11..10, + IT : (15..10 @ 26..25), + D : 9..9, + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5 + } + +register SPSR_EL3 : SPSR_EL3_Type + +bitfield SPSR_abt_Type : bits(64) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + J : 24..24, + SSBS : 23..23, + PAN : 22..22, + DIT : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register SPSR_abt : SPSR_abt_Type + +bitfield SPSR_fiq_Type : bits(64) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + J : 24..24, + SSBS : 23..23, + PAN : 22..22, + DIT : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register SPSR_fiq : SPSR_fiq_Type + +bitfield SPSR_hyp_Type : bits(32) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + J : 24..24, + SSBS : 23..23, + PAN : 22..22, + DIT : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register _SPSR_hyp : SPSR_hyp_Type + +val SPSR_hyp_read : unit -> SPSR_hyp_Type + +function SPSR_hyp_read () = { + r : SPSR_hyp_Type = _SPSR_hyp; + r.bits[31 .. 0] = Slice(SPSR_EL2.bits, 0, 32); + return(r) +} + +val SPSR_hyp_write : SPSR_hyp_Type -> unit + +function SPSR_hyp_write value_name = { + let r : SPSR_hyp_Type = value_name; + SPSR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _SPSR_hyp = r; + return() +} + +bitfield SPSR_irq_Type : bits(64) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + J : 24..24, + SSBS : 23..23, + PAN : 22..22, + DIT : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register SPSR_irq : SPSR_irq_Type + +bitfield SPSR_mon_Type : bits(32) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + J : 24..24, + SSBS : 23..23, + PAN : 22..22, + DIT : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register SPSR_mon : SPSR_mon_Type + +bitfield SPSR_svc_Type : bits(32) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + J : 24..24, + SSBS : 23..23, + PAN : 22..22, + DIT : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register _SPSR_svc : SPSR_svc_Type + +val SPSR_svc_read : unit -> SPSR_svc_Type + +function SPSR_svc_read () = { + r : SPSR_svc_Type = _SPSR_svc; + r.bits[31 .. 0] = Slice(SPSR_EL1.bits, 0, 32); + return(r) +} + +val SPSR_svc_write : SPSR_svc_Type -> unit + +function SPSR_svc_write value_name = { + let r : SPSR_svc_Type = value_name; + SPSR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _SPSR_svc = r; + return() +} + +bitfield SPSR_und_Type : bits(64) = + { + N : 31..31, + Z : 30..30, + C : 29..29, + V : 28..28, + Q : 27..27, + J : 24..24, + SSBS : 23..23, + PAN : 22..22, + DIT : 21..21, + IL : 20..20, + GE : 19..16, + IT : (15..10 @ 26..25), + E : 9..9, + A : 8..8, + I : 7..7, + F : 6..6, + T : 5..5, + M : 4..0 + } + +register SPSR_und : SPSR_und_Type + +val SPSR_set : forall 'N, 'N >= 0. (implicit('N), bits('N)) -> unit + +function SPSR_set (N, value_name) = { + if UsingAArch32() then { + assert(N == 32); + match PSTATE.M { + ? if ? == M32_FIQ => { + SPSR_fiq.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + ? if ? == M32_IRQ => { + SPSR_irq.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + ? if ? == M32_Svc => { + SPSR_svc_write() = Mk_SPSR_svc_Type([SPSR_svc_read().bits with (N - 1) .. 0 = value_name[N - 1 .. 0]]) + }, + ? if ? == M32_Monitor => { + SPSR_mon.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + ? if ? == M32_Abort => { + SPSR_abt.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + ? if ? == M32_Hyp => { + SPSR_hyp_write() = Mk_SPSR_hyp_Type([SPSR_hyp_read().bits with (N - 1) .. 0 = value_name[N - 1 .. 0]]) + }, + ? if ? == M32_Undef => { + SPSR_und.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + _ => { + Unreachable() + } + } + } else { + assert(N == 64); + match PSTATE.EL { + ? if ? == EL1 => { + SPSR_EL1.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + ? if ? == EL2 => { + SPSR_EL2.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + ? if ? == EL3 => { + SPSR_EL3.bits[N - 1 .. 0] = value_name[N - 1 .. 0] + }, + _ => { + Unreachable() + } + } + }; + return() +} + +val SynchronizeContext : unit -> unit + +val SynchronizeErrors : unit -> unit + +val AArch64_TakeExceptionInDebugState : (bits(2), ExceptionRecord) -> unit + +function AArch64_TakeExceptionInDebugState (target_el, exception_in) = { + assert((HaveEL(target_el) & not_bool(ELUsingAArch32(target_el))) & UInt(target_el) >= UInt(PSTATE.EL)); + assert(target_el != EL3 | EDSCR_read()[SDD] == 0b0); + let except : ExceptionRecord = exception_in; + sync_errors : bool = undefined; + if HaveIESB() then { + sync_errors = SCTLR_read(target_el)[IESB] == 0b1; + if HaveDoubleFaultExt() then { + sync_errors = sync_errors | (SCR_EL3[EA] @ SCR_EL3[NMEA]) == 0b11 & target_el == EL3 + }; + if not_bool(ConstrainUnpredictableBool(Unpredictable_IESBinDebug)) then { + sync_errors = false + }; + () + } else { + sync_errors = false + }; + if HaveTME() & TSTATE.depth > 0 then { + cause : TMFailure = undefined; + match except.exceptype { + Exception_SoftwareBreakpoint => { + cause = TMFailure_DBG + }, + Exception_Breakpoint => { + cause = TMFailure_DBG + }, + Exception_Watchpoint => { + cause = TMFailure_DBG + }, + Exception_SoftwareStep => { + cause = TMFailure_DBG + }, + _ => { + cause = TMFailure_ERR + } + }; + let cause = cause; + FailTransaction(cause, false) + }; + SynchronizeContext(); + let from_32 : bool = UsingAArch32(); + if from_32 then { + AArch64_MaybeZeroRegisterUppers() + }; + if (from_32 & HaveSME()) & PSTATE.SM == 0b1 then { + ResetSVEState() + } else { + MaybeZeroSVEUppers(target_el) + }; + AArch64_ReportException(except, target_el); + if HaveGCS() then { + PSTATE.EXLOCK = 0b0 + }; + PSTATE.EL = target_el; + PSTATE.nRW = 0b0; + PSTATE.SP = 0b1; + SPSR_set(64) = __UNKNOWN_bits(64); + ELR_set__1() = __UNKNOWN_bits(64); + (PSTATE.SS @ PSTATE.D @ PSTATE.A @ PSTATE.I @ PSTATE.F) = __UNKNOWN_bits(5); + PSTATE.IL = 0b0; + if from_32 then { + PSTATE.IT = 0b00000000; + PSTATE.T = 0b0 + }; + if (HavePANExt() & (PSTATE.EL == EL1 | PSTATE.EL == EL2 & ELIsInHost(EL0))) & SCTLR_read__1()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + }; + if HaveUAOExt() then { + PSTATE.UAO = 0b0 + }; + if HaveBTIExt() then { + PSTATE.BTYPE = 0b00 + }; + if HaveSSBSExt() then { + PSTATE.SSBS = __UNKNOWN_bit() + }; + if HaveMTEExt() then { + PSTATE.TCO = 0b1 + }; + DLR_EL0 = __UNKNOWN_bits(64); + DSPSR_EL0 = Mk_DSPSR_EL0_Type(__UNKNOWN_bits(64)); + EDSCR_write() = [EDSCR_read() with ERR = 0b1]; + UpdateEDSCRFields(); + if sync_errors then { + SynchronizeErrors() + }; + EndOfInstruction() +} + +val BRBEException : forall ('trappedsyscallinst : Bool). + (ExceptionRecord, bits(64), bits(64), bits(2), bool('trappedsyscallinst)) -> unit + +function BRBEException (erec, preferred_exception_return, target_address_in, target_el, trappedsyscallinst) = { + target_address : bits(64) = target_address_in; + let except : Exception = erec.exceptype; + let iss : bits(25) = erec.syndrome; + match target_el { + ? if ? == EL3 => { + if not_bool(HaveBRBEv1p1()) | MDCR_EL3[E3BREC] == MDCR_EL3[E3BREW] then { + return() + }; + () + }, + ? if ? == EL2 => { + if BRBCR_EL2[EXCEPTION] == 0b0 then { + return() + }; + () + }, + ? if ? == EL1 => { + if BRBCR_EL1[EXCEPTION] == 0b0 then { + return() + }; + () + }, + _ => () + }; + let source_valid : bool = BranchRecordAllowed(PSTATE.EL); + let target_valid : bool = BranchRecordAllowed(target_el); + let branch_valid : bool = source_valid | target_valid; + if branch_valid then { + branch_type : bits(6) = undefined; + match except { + Exception_Uncategorized => { + branch_type = 0b100011 + }, + Exception_WFxTrap => { + branch_type = 0b100011 + }, + Exception_CP15RTTrap => { + branch_type = 0b100011 + }, + Exception_CP15RRTTrap => { + branch_type = 0b100011 + }, + Exception_CP14RTTrap => { + branch_type = 0b100011 + }, + Exception_CP14DTTrap => { + branch_type = 0b100011 + }, + Exception_AdvSIMDFPAccessTrap => { + branch_type = 0b100011 + }, + Exception_FPIDTrap => { + branch_type = 0b100011 + }, + Exception_PACTrap => { + branch_type = 0b100011 + }, + Exception_TSTARTAccessTrap => { + branch_type = 0b100011 + }, + Exception_CP14RRTTrap => { + branch_type = 0b100011 + }, + Exception_BranchTarget => { + branch_type = 0b101011 + }, + Exception_IllegalState => { + branch_type = 0b100011 + }, + Exception_SupervisorCall => { + if not_bool(trappedsyscallinst) then { + branch_type = 0b100010 + } else { + branch_type = 0b100011 + } + }, + Exception_HypervisorCall => { + branch_type = 0b100010 + }, + Exception_MonitorCall => { + if not_bool(trappedsyscallinst) then { + branch_type = 0b100010 + } else { + branch_type = 0b100011 + } + }, + Exception_SystemRegisterTrap => { + branch_type = 0b100011 + }, + Exception_SystemRegister128Trap => { + branch_type = 0b100011 + }, + Exception_SVEAccessTrap => { + branch_type = 0b100011 + }, + Exception_SMEAccessTrap => { + branch_type = 0b100011 + }, + Exception_ERetTrap => { + branch_type = 0b100011 + }, + Exception_PACFail => { + branch_type = 0b101100 + }, + Exception_InstructionAbort => { + branch_type = 0b101011 + }, + Exception_PCAlignment => { + branch_type = 0b101010 + }, + Exception_DataAbort => { + branch_type = 0b101100 + }, + Exception_NV2DataAbort => { + branch_type = 0b101100 + }, + Exception_SPAlignment => { + branch_type = 0b101010 + }, + Exception_FPTrappedException => { + branch_type = 0b100011 + }, + Exception_SError => { + branch_type = 0b100100 + }, + Exception_Breakpoint => { + branch_type = 0b100110 + }, + Exception_SoftwareStep => { + branch_type = 0b100110 + }, + Exception_Watchpoint => { + branch_type = 0b100111 + }, + Exception_NV2Watchpoint => { + branch_type = 0b100111 + }, + Exception_SoftwareBreakpoint => { + branch_type = 0b100110 + }, + Exception_IRQ => { + branch_type = 0b101110 + }, + Exception_FIQ => { + branch_type = 0b101111 + }, + Exception_MemCpyMemSet => { + branch_type = 0b100011 + }, + Exception_GCSFail => { + if iss[23 .. 20] == 0b0000 then { + branch_type = 0b101100 + } else if iss[23 .. 20] == 0b0001 then { + branch_type = 0b101011 + } else if iss[23 .. 20] == 0b0010 then { + branch_type = 0b100011 + } else { + Unreachable() + } + }, + _ => { + Unreachable() + } + }; + ccu : bits(1) = undefined; + cc : bits(14) = undefined; + (ccu, cc) = BranchEncCycleCount(); + let lastfailed : bits(1) = if HaveTME() then BRBFCR_EL1[LASTFAILED] else + 0b0; + let transactional : bits(1) = if (source_valid & HaveTME()) & TSTATE.depth > 0 then + 0b1 + else + 0b0; + let el : bits(2) = if target_valid then target_el else 0b00; + let mispredict : bits(1) = 0b0; + let sv : bits(1) = if source_valid then 0b1 else 0b0; + let tv : bits(1) = if target_valid then 0b1 else 0b0; + let source_address : bits(64) = if source_valid then + preferred_exception_return + else + Zeros(64); + if not_bool(target_valid) then { + target_address = Zeros(64) + } else { + target_address = AArch64_BranchAddr(target_address, target_el) + }; + UpdateBranchRecordBuffer(ccu, cc, lastfailed, transactional, branch_type, el, mispredict, sv @ tv, source_address, target_address); + BRBFCR_EL1[LASTFAILED] = 0b0; + PMUEvent(PMU_EVENT_BRB_FILTRATE) + }; + __last_branch_valid = branch_valid; + return() +} + +bitfield EDECCR_Type : bits(32) = + { + RLR2 : 22..22, + RLR1 : 21..21, + RLR0 : 20..20, + RLE2 : 18..18, + RLE1 : 17..17, + RLE0 : 16..16, + NSR3 : 15..15, + NSR2 : 14..14, + NSR1 : 13..13, + NSR0 : 12..12, + SR3 : 11..11, + SR2 : 10..10, + SR1 : 9..9, + SR0 : 8..8, + NSE3 : 7..7, + NSE2 : 6..6, + NSE1 : 5..5, + NSE0 : 4..4, + SE3 : 3..3, + SE2 : 2..2, + SE1 : 1..1, + SE0 : 0..0 + } + +bitfield OSECCR_EL1_Type : bits(64) = {EDECCR : 31..0} + +register OSECCR_EL1 : OSECCR_EL1_Type + +register _EDECCR : EDECCR_Type + +val EDECCR_read : unit -> EDECCR_Type + +function EDECCR_read () = { + r : EDECCR_Type = _EDECCR; + r.bits[31 .. 0] = Slice(OSECCR_EL1.bits, 0, 32); + return(r) +} + +bitfield EDESR_Type : bits(32) = {EC : 3..3, SS : 2..2, RC : 1..1, OSUC : 0..0} + +register EDESR : EDESR_Type + +val HaveExtendedECDebugEvents : unit -> bool + +function HaveExtendedECDebugEvents () = { + return(IsFeatureImplemented(FEAT_Debugv8p2)) +} + +val Havev8p8Debug : unit -> bool + +function Havev8p8Debug () = { + return(IsFeatureImplemented(FEAT_Debugv8p8)) +} + +val CheckExceptionCatch : forall ('exception_entry : Bool). + bool('exception_entry) -> unit + +function CheckExceptionCatch exception_entry = { + ctrl : bits(2) = undefined; + exception_exit : bool = undefined; + increment_name : int = undefined; + let ss : SecurityState = SecurityStateAtEL(PSTATE.EL); + base : {0, 4, 16} = 0; + match ss { + SS_Secure => { + base = 0 + }, + SS_NonSecure => { + base = 4 + }, + SS_Realm => { + base = 16 + }, + SS_Root => { + base = 0 + } + }; + let 'base = base; + if HaltingAllowed() then { + halt : bool = undefined; + if HaveExtendedECDebugEvents() then { + let exception_exit : bool = not_bool(exception_entry); + let 'increment_name = if ss == SS_Realm then 4 else 8; + let ctrl : bits(2) = [EDECCR_read().bits[UInt(PSTATE.EL) + base + increment_name]] @ [EDECCR_read().bits[UInt(PSTATE.EL) + base]]; + match ctrl { + 0b00 => { + halt = false + }, + 0b01 => { + halt = true + }, + 0b10 => { + halt = exception_exit == true + }, + 0b11 => { + halt = exception_entry == true + } + } + } else { + halt = [EDECCR_read().bits[UInt(PSTATE.EL) + base]] == 0b1 + }; + if halt then { + if Havev8p8Debug() & exception_entry then { + EDESR[EC] = 0b1 + } else { + Halt(DebugHalt_ExceptionCatch) + } + }; + () + }; + () +} + +val HaveNV2Ext : unit -> bool + +function HaveNV2Ext () = { + return(IsFeatureImplemented(FEAT_NV2)) +} + +val HaveNVExt : unit -> bool + +function HaveNVExt () = { + return(IsFeatureImplemented(FEAT_NV)) +} + +val InsertIESBBeforeException : bits(2) -> bool + +function InsertIESBBeforeException el = { + return(HaveIESB() & __IMPDEF_boolean("Has Implicit Error Synchronization Barrier before Exception")) +} + +val TakeUnmaskedPhysicalSErrorInterrupts : forall ('iesb_req : Bool). + bool('iesb_req) -> unit + +type VBAR_EL1_Type = bits(64) + +register VBAR_EL1 : VBAR_EL1_Type + +type VBAR_EL2_Type = bits(64) + +register VBAR_EL2 : VBAR_EL2_Type + +type VBAR_EL3_Type = bits(64) + +register VBAR_EL3 : VBAR_EL3_Type + +type VBAR_Type = bits(32) + +register _VBAR_NS : VBAR_Type + +val VBAR_NS_read : unit -> VBAR_Type + +function VBAR_NS_read () = { + r : VBAR_Type = _VBAR_NS; + r[31 .. 0] = Slice(VBAR_EL1, 0, 32); + return(r) +} + +register VBAR_S : VBAR_Type + +val VBAR_read : bits(2) -> bits(64) + +val VBAR_read__1 : unit -> bits(64) + +val VBAR_read__2 : unit -> VBAR_Type + +function VBAR_read__2 () = { + r : VBAR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = VBAR_S + } else { + r = VBAR_NS_read() + }; + return(r) +} + +function VBAR_read regime = { + r : bits(64) = undefined; + match regime { + ? if ? == EL1 => { + r = VBAR_EL1 + }, + ? if ? == EL2 => { + r = VBAR_EL2 + }, + ? if ? == EL3 => { + r = VBAR_EL3 + }, + _ => { + Unreachable() + } + }; + return(r) +} + +function VBAR_read__1 () = { + return(VBAR_read(S1TranslationRegime__1())) +} + +val AArch64_TakeException : forall 'vect_offset_in. + (bits(2), ExceptionRecord, bits(64), int('vect_offset_in)) -> unit + +function AArch64_TakeException (target_el, exception_in, preferred_exception_return, vect_offset_in) = { + assert((HaveEL(target_el) & not_bool(ELUsingAArch32(target_el))) & UInt(target_el) >= UInt(PSTATE.EL)); + if Halted() then { + AArch64_TakeExceptionInDebugState(target_el, exception_in); + return() + }; + except : ExceptionRecord = exception_in; + sync_errors : bool = undefined; + iesb_req : bool = undefined; + if HaveIESB() then { + sync_errors = SCTLR_read(target_el)[IESB] == 0b1; + if HaveDoubleFaultExt() then { + sync_errors = sync_errors | (SCR_EL3[EA] @ SCR_EL3[NMEA]) == 0b11 & target_el == EL3 + }; + if sync_errors & InsertIESBBeforeException(target_el) then { + SynchronizeErrors(); + iesb_req = false; + sync_errors = false; + TakeUnmaskedPhysicalSErrorInterrupts(iesb_req) + }; + () + } else { + sync_errors = false + }; + if HaveTME() & TSTATE.depth > 0 then { + cause : TMFailure = undefined; + match except.exceptype { + Exception_SoftwareBreakpoint => { + cause = TMFailure_DBG + }, + Exception_Breakpoint => { + cause = TMFailure_DBG + }, + Exception_Watchpoint => { + cause = TMFailure_DBG + }, + Exception_SoftwareStep => { + cause = TMFailure_DBG + }, + _ => { + cause = TMFailure_ERR + } + }; + let cause = cause; + FailTransaction(cause, false) + }; + SynchronizeContext(); + let from_32 : bool = UsingAArch32(); + if from_32 then { + AArch64_MaybeZeroRegisterUppers() + }; + if (from_32 & HaveSME()) & PSTATE.SM == 0b1 then { + ResetSVEState() + } else { + MaybeZeroSVEUppers(target_el) + }; + vect_offset : int = vect_offset_in; + if UInt(target_el) > UInt(PSTATE.EL) then { + lower_32 : bool = undefined; + if target_el == EL3 then { + if EL2Enabled() then { + lower_32 = ELUsingAArch32(EL2) + } else { + lower_32 = ELUsingAArch32(EL1) + } + } else if (IsInHost() & PSTATE.EL == EL0) & target_el == EL2 then { + lower_32 = ELUsingAArch32(EL0) + } else { + lower_32 = ELUsingAArch32(target_el - 1) + }; + vect_offset = vect_offset + (if lower_32 then UInt(0x600) else + UInt(0x400)) + } else if PSTATE.SP == 0b1 then { + vect_offset = vect_offset + UInt(0x200) + } else (); + let 'vect_offset = vect_offset; + spsr : bits(64) = GetPSRFromPSTATE(AArch64_NonDebugState, 64); + if (PSTATE.EL == EL1 & target_el == EL1) & EL2Enabled() then { + if HaveNV2Ext() & ((HCR_EL2[NV] @ (HCR_EL2[NV1] @ HCR_EL2[NV2])) == 0b100 | (HCR_EL2[NV] @ (HCR_EL2[NV1] @ HCR_EL2[NV2])) == 0b111) then { + spsr[3 .. 2] = 0b10 + } else { + if HaveNVExt() & (HCR_EL2[NV] @ HCR_EL2[NV1]) == 0b10 then { + spsr[3 .. 2] = 0b10 + }; + () + } + }; + if HaveBTIExt() & not_bool(UsingAArch32()) then { + zero_btype : bool = undefined; + if except.exceptype == Exception_SError | except.exceptype == Exception_IRQ | except.exceptype == Exception_FIQ | except.exceptype == Exception_SoftwareStep | except.exceptype == Exception_PCAlignment | except.exceptype == Exception_InstructionAbort | except.exceptype == Exception_Breakpoint | except.exceptype == Exception_VectorCatch | except.exceptype == Exception_SoftwareBreakpoint | except.exceptype == Exception_IllegalState | except.exceptype == Exception_BranchTarget then { + zero_btype = false + } else { + zero_btype = ConstrainUnpredictableBool(Unpredictable_ZEROBTYPE) + }; + if zero_btype then { + spsr[11 .. 10] = 0b00 + }; + () + }; + if (HaveNV2Ext() & except.exceptype == Exception_NV2DataAbort) & target_el == EL3 then { + except.exceptype = Exception_DataAbort + }; + if not_bool(except.exceptype == Exception_IRQ | except.exceptype == Exception_FIQ) then { + AArch64_ReportException(except, target_el) + }; + if HaveBRBExt() then { + BRBEException(except, preferred_exception_return, VBAR_read(target_el)[63 .. 11] @ vect_offset[10 .. 0], target_el, except.trappedsyscallinst) + }; + if HaveGCS() then { + if PSTATE.EL == target_el then { + if GetCurrentEXLOCKEN() then { + PSTATE.EXLOCK = 0b1 + } else { + PSTATE.EXLOCK = 0b0 + } + } else { + PSTATE.EXLOCK = 0b0 + } + }; + PSTATE.EL = target_el; + PSTATE.nRW = 0b0; + PSTATE.SP = 0b1; + SPSR_set(64) = spsr; + ELR_set__1() = preferred_exception_return; + PSTATE.SS = 0b0; + if HaveFeatNMI() & not_bool(ELUsingAArch32(target_el)) then { + PSTATE.ALLINT = not_vec(SCTLR_read__1()[SPINTMASK]) + }; + (PSTATE.D @ PSTATE.A @ PSTATE.I @ PSTATE.F) = 0b1111; + PSTATE.IL = 0b0; + if from_32 then { + PSTATE.IT = 0b00000000; + PSTATE.T = 0b0 + }; + if (HavePANExt() & (PSTATE.EL == EL1 | PSTATE.EL == EL2 & ELIsInHost(EL0))) & SCTLR_read__1()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + }; + if HaveUAOExt() then { + PSTATE.UAO = 0b0 + }; + if HaveBTIExt() then { + PSTATE.BTYPE = 0b00 + }; + if HaveSSBSExt() then { + PSTATE.SSBS = SCTLR_read__1()[DSSBS] + }; + if HaveMTEExt() then { + PSTATE.TCO = 0b1 + }; + let branch_conditional : bool = false; + BranchTo(VBAR_read__1()[63 .. 11] @ vect_offset[10 .. 0], BranchType_EXCEPTION, branch_conditional); + CheckExceptionCatch(true); + if sync_errors then { + SynchronizeErrors(); + let iesb_req : bool = true; + TakeUnmaskedPhysicalSErrorInterrupts(iesb_req) + }; + EndOfInstruction() +} + +val ExceptionSyndrome : Exception -> ExceptionRecord + +function ExceptionSyndrome exceptype = { + r : ExceptionRecord = undefined; + r.exceptype = exceptype; + r.syndrome = Zeros(25); + r.syndrome2 = Zeros(24); + r.vaddress = Zeros(64); + r.ipavalid = false; + r.NS = 0b0; + r.ipaddress = Zeros(56); + r.paddress.paspace = __UNKNOWN_PASpace(); + r.paddress.address = __UNKNOWN_bits(56); + r.trappedsyscallinst = false; + return(r) +} + +val AArch64_BranchTargetException : bits(52) -> unit + +function AArch64_BranchTargetException vaddress = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_BranchTarget); + except.syndrome[1 .. 0] = PSTATE.BTYPE; + except.syndrome[24 .. 2] = Zeros(23); + target_el : bits(2) = EL1; + if UInt(PSTATE.EL) > UInt(EL1) then { + target_el = PSTATE.EL + } else if (PSTATE.EL == EL0 & EL2Enabled()) & HCR_EL2[TGE] == 0b1 then { + target_el = EL2 + } else (); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val ThisInstr : unit -> bits(32) + +val AArch64_ExecutingBROrBLROrRetInstr : unit -> bool + +function AArch64_ExecutingBROrBLROrRetInstr () = { + opc : bits(4) = undefined; + if not_bool(HaveBTIExt()) then { + return(false) + }; + let instr : bits(32) = ThisInstr(); + if instr[31 .. 25] == 0b1101011 & instr[20 .. 16] == 0b11111 then { + let opc : bits(4) = instr[24 .. 21]; + return(opc != 0b0101) + } else { + return(false) + } +} + +val AArch64_ExecutingBTIInstr : unit -> bool + +function AArch64_ExecutingBTIInstr () = { + CRm : bits(4) = undefined; + op2 : bits(3) = undefined; + if not_bool(HaveBTIExt()) then { + return(false) + }; + let instr : bits(32) = ThisInstr(); + if (instr[31 .. 22] == 0b1101010100 & instr[21 .. 12] == 0b0000110010) & instr[4 .. 0] == 0b11111 then { + let CRm : bits(4) = instr[11 .. 8]; + let op2 : bits(3) = instr[7 .. 5]; + return(CRm == 0b0100 & [op2[0]] == 0b0) + } else { + return(false) + } +} + +val BranchTargetCheck : unit -> unit + +function BranchTargetCheck () = { + assert(HaveBTIExt() & not_bool(UsingAArch32())); + if ((InGuardedPage & PSTATE.BTYPE != 0b00) & not_bool(BTypeCompatible)) & not_bool(Halted()) then { + let pc : bits(64) = ThisInstrAddr(64); + AArch64_BranchTargetException(pc[51 .. 0]) + }; + let branch_instr : bool = AArch64_ExecutingBROrBLROrRetInstr(); + let bti_instr : bool = AArch64_ExecutingBTIInstr(); + if not_bool(branch_instr | bti_instr) then { + BTypeNext = 0b00 + }; + () +} + +val Hint_Yield : unit -> unit + +val Hint_DGH : unit -> unit + +val Hint_CLRBHB : unit -> unit + +val AArch32_CurrentCond : unit -> bits(4) + +val ConditionSyndrome : unit -> bits(5) + +function ConditionSyndrome () = { + cond : bits(4) = undefined; + syndrome : bits(5) = undefined; + if UsingAArch32() then { + let cond : bits(4) = AArch32_CurrentCond(); + if PSTATE.T == 0b0 then { + syndrome[4] = Bit(0b1); + if ConditionHolds(cond) & ConstrainUnpredictableBool(Unpredictable_ESRCONDPASS) then { + syndrome[3 .. 0] = 0b1110 + } else { + syndrome[3 .. 0] = cond + } + } else { + if __IMPDEF_boolean("Condition valid for trapped T32") then { + syndrome[4] = Bit(0b1); + syndrome[3 .. 0] = cond + } else { + syndrome[4] = Bit(0b0); + syndrome[3 .. 0] = __UNKNOWN_bits(4) + } + } + } else { + syndrome[4] = Bit(0b1); + syndrome[3 .. 0] = 0b1110 + }; + return(syndrome) +} + +val AArch64_WFxTrap : (WFxType, bits(2)) -> unit + +function AArch64_WFxTrap (wfxtype, target_el) = { + assert(UInt(target_el) > UInt(PSTATE.EL)); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_WFxTrap); + except.syndrome[24 .. 20] = ConditionSyndrome(); + match wfxtype { + WFxType_WFI => { + except.syndrome[1 .. 0] = 0b00 + }, + WFxType_WFE => { + except.syndrome[1 .. 0] = 0b01 + }, + WFxType_WFIT => { + except.syndrome[1 .. 0] = 0b10; + except.syndrome[2] = Bit(0b1); + except.syndrome[9 .. 5] = ThisInstr()[4 .. 0] + }, + WFxType_WFET => { + except.syndrome[1 .. 0] = 0b11; + except.syndrome[2] = Bit(0b1); + except.syndrome[9 .. 5] = ThisInstr()[4 .. 0] + } + }; + if (target_el == EL1 & EL2Enabled()) & HCR_EL2[TGE] == 0b1 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) + } +} + +val AArch64_CheckForWFxTrap : (bits(2), WFxType) -> unit + +function AArch64_CheckForWFxTrap (target_el, wfxtype) = { + assert(HaveEL(target_el)); + let is_wfe : bool = wfxtype == WFxType_WFE | wfxtype == WFxType_WFET; + trap : bool = undefined; + match target_el { + ? if ? == EL1 => { + trap = (if is_wfe then SCTLR_read__1()[nTWE] else + SCTLR_read__1()[nTWI]) == 0b0 + }, + ? if ? == EL2 => { + trap = (if is_wfe then HCR_EL2[TWE] else HCR_EL2[TWI]) == 0b1 + }, + ? if ? == EL3 => { + trap = (if is_wfe then SCR_EL3[TWE] else SCR_EL3[TWI]) == 0b1 + }, + _ => () + }; + if trap then { + AArch64_WFxTrap(wfxtype, target_el) + }; + () +} + +val ClearEventRegister : unit -> unit + +function ClearEventRegister () = { + EventRegister = 0b0; + return() +} + +val HaveFeatWFxT : unit -> bool + +function HaveFeatWFxT () = { + return(IsFeatureImplemented(FEAT_WFxT)) +} + +val HaveTWEDExt : unit -> bool + +function HaveTWEDExt () = { + return(IsFeatureImplemented(FEAT_TWED)) +} + +val IsEventRegisterSet : unit -> bool + +function IsEventRegisterSet () = { + return(EventRegister == 0b1) +} + +val LocalTimeoutEvent : forall 'localtimeout. int('localtimeout) -> bool + +val WFETrapDelay : bits(2) -> (bool, int) + +function WFETrapDelay target_el = { + delay_enabled : bool = undefined; + delay : int = undefined; + match target_el { + ? if ? == EL1 => { + if not_bool(IsInHost()) then { + delay_enabled = SCTLR_EL1[TWEDEn] == 0b1; + delay = (1 << (UInt(SCTLR_EL1[TWEDEL]) + 8)) + } else { + delay_enabled = SCTLR_EL2[TWEDEn] == 0b1; + delay = (1 << (UInt(SCTLR_EL2[TWEDEL]) + 8)) + } + }, + ? if ? == EL2 => { + assert(EL2Enabled()); + delay_enabled = HCR_EL2[TWEDEn] == 0b1; + delay = (1 << (UInt(HCR_EL2[TWEDEL]) + 8)) + }, + ? if ? == EL3 => { + delay_enabled = SCR_EL3[TWEDEn] == 0b1; + delay = (1 << (UInt(SCR_EL3[TWEDEL]) + 8)) + }, + _ => () + }; + let 'delay = delay; + return((delay_enabled, delay)) +} + +val EnterLowPowerState : unit -> unit + +val WaitForEvent : forall 'localtimeout. int('localtimeout) -> unit + +function WaitForEvent localtimeout = { + if not_bool(IsEventRegisterSet() | HaveFeatWFxT() & LocalTimeoutEvent(localtimeout)) then { + IsWFEsleep = true; + _DormantCtlReg[standbywfe] = 0b1; + EnterLowPowerState() + }; + return() +} + +val WaitForEventUntilDelay : forall 'delay ('delay_enabled : Bool). + (bool('delay_enabled), int('delay)) -> bool + +val Hint_WFE : forall 'localtimeout. (int('localtimeout), WFxType) -> unit + +function Hint_WFE (localtimeout, wfxtype) = { + delay : int = undefined; + delay_enabled : bool = undefined; + sctlr : SCTLRType = undefined; + trap : bool = undefined; + if IsEventRegisterSet() then { + ClearEventRegister() + } else if HaveFeatWFxT() & LocalTimeoutEvent(localtimeout) then { + EndOfInstruction() + } else { + target_el : bits(2) = undefined; + trap : bool = false; + if PSTATE.EL == EL0 then { + if HaveTWEDExt() then { + let sctlr : SCTLRType = SCTLR_read__1(); + trap = sctlr[nTWE] == 0b0; + target_el = EL1 + } else { + AArch64_CheckForWFxTrap(EL1, wfxtype) + } + }; + if ((not_bool(trap) & (PSTATE.EL == EL0 | PSTATE.EL == EL1)) & EL2Enabled()) & not_bool(IsInHost()) then { + if HaveTWEDExt() then { + trap = HCR_EL2[TWE] == 0b1; + target_el = EL2 + } else { + AArch64_CheckForWFxTrap(EL2, wfxtype) + } + }; + if (not_bool(trap) & HaveEL(EL3)) & PSTATE.EL != EL3 then { + if HaveTWEDExt() then { + trap = SCR_EL3[TWE] == 0b1; + target_el = EL3 + } else { + AArch64_CheckForWFxTrap(EL3, wfxtype) + } + }; + if trap & PSTATE.EL != EL3 then { + (delay_enabled, delay) = WFETrapDelay(target_el); + let 'delay = delay; + if not_bool(WaitForEventUntilDelay(delay_enabled, delay)) then { + AArch64_WFxTrap(wfxtype, target_el) + }; + () + } else { + WaitForEvent(localtimeout) + } + } +} + +val IsVirtualSErrorPending : unit -> bool + +function IsVirtualSErrorPending () = { + if ELUsingAArch32(EL2) then { + return(HCR_read()[VA] == 0b1) + } else { + return(HCR_EL2[VSE] == 0b1) + } +} + +val InterruptPending : unit -> bool + +function InterruptPending () = { + fiq_pending : bool = undefined; + irq_pending : bool = undefined; + pending_virtual_interrupt : bool = false; + let (__tup_0 : bool, _) = IRQPending() in + { + irq_pending = __tup_0 + }; + let (__tup_0 : bool, _) = FIQPending() in + { + fiq_pending = __tup_0 + }; + let pending_physical_interrupt : bool = (irq_pending | fiq_pending) | IsPhysicalSErrorPending(); + if (EL2Enabled() & (PSTATE.EL == EL0 | PSTATE.EL == EL1)) & HCR_EL2[TGE] == 0b0 then { + let virq_pending : bool = HCR_EL2[IMO] == 0b1 & (VirtualIRQPending() | HCR_EL2[VI] == 0b1); + let vfiq_pending : bool = HCR_EL2[FMO] == 0b1 & (VirtualFIQPending() | HCR_EL2[VF] == 0b1); + let vsei_pending : bool = HCR_EL2[AMO] == 0b1 & (IsVirtualSErrorPending() | HCR_EL2[VSE] == 0b1); + pending_virtual_interrupt = (vsei_pending | virq_pending) | vfiq_pending + }; + return(pending_physical_interrupt | pending_virtual_interrupt) +} + +val WaitForInterrupt : forall 'localtimeout. int('localtimeout) -> unit + +function WaitForInterrupt localtimeout = { + if not_bool(HaveFeatWFxT() & LocalTimeoutEvent(localtimeout)) then { + IsWFIsleep = true; + _DormantCtlReg[standbywfi] = 0b1; + EnterLowPowerState() + }; + return() +} + +val Hint_WFI : forall 'localtimeout. (int('localtimeout), WFxType) -> unit + +function Hint_WFI (localtimeout, wfxtype) = { + if HaveTME() & TSTATE.depth > 0 then { + FailTransaction(TMFailure_ERR, false) + }; + if InterruptPending() | HaveFeatWFxT() & LocalTimeoutEvent(localtimeout) then { + EndOfInstruction() + } else { + if PSTATE.EL == EL0 then { + AArch64_CheckForWFxTrap(EL1, wfxtype) + }; + if ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & not_bool(IsInHost()) then { + AArch64_CheckForWFxTrap(EL2, wfxtype) + }; + if HaveEL(EL3) & PSTATE.EL != EL3 then { + AArch64_CheckForWFxTrap(EL3, wfxtype) + }; + WaitForInterrupt(localtimeout) + } +} + +val SendEvent : unit -> unit + +val SendEventLocal : unit -> unit + +function SendEventLocal () = { + EventRegister = 0b1; + return() +} + +val InstructionSynchronizationBarrier : unit -> unit + +val SpeculationBarrier : unit -> unit + +val ConsumptionOfSpeculativeDataBarrier : unit -> unit + +val TakeUnmaskedSErrorInterrupts : unit -> unit + +val IsASEInstruction : unit -> bool + +val GetAccumulatedFPExceptions : unit -> bits(8) + +val SetAccumulatedFPExceptions : bits(8) -> unit + +val EffectiveEA : unit -> bits(1) + +function EffectiveEA () = { + if Halted() & EDSCR_read()[SDD] == 0b0 then { + return(0b0) + } else { + return(if HaveAArch64() then SCR_EL3[EA] else SCR[EA]) + } +} + +val EL3SDDUndefPriority : unit -> bool + +function EL3SDDUndefPriority () = { + return((Halted() & EDSCR_read()[SDD] == 0b1) & __IMPDEF_boolean("EL3 trap priority when SDD == '1'")) +} + +val EL3SDDUndef : unit -> bool + +function EL3SDDUndef () = { + return(Halted() & EDSCR_read()[SDD] == 0b1) +} + +val GetLoadStoreType : unit -> bits(2) + +bitfield GCSCRE0_EL1_Type : bits(64) = + {nTR : 10..10, STREn : 9..9, PUSHMEn : 8..8, RVCHKEN : 5..5, PCRSEL : 0..0} + +register GCSCRE0_EL1 : GCSCRE0_EL1_Type + +val GCSPCRSelected : bits(2) -> bool + +function GCSPCRSelected el = { + match el { + ? if ? == EL0 => { + return(GCSCRE0_EL1[PCRSEL] == 0b1) + }, + ? if ? == EL1 => { + return(GCSCR_EL1[PCRSEL] == 0b1) + }, + ? if ? == EL2 => { + return(GCSCR_EL2[PCRSEL] == 0b1) + }, + ? if ? == EL3 => { + return(GCSCR_EL3[PCRSEL] == 0b1) + }, + _ => () + }; + Unreachable(); + return(true) +} + +bitfield HCRX_EL2_Type : bits(64) = + { + GCSEn : 22..22, + EnIDCP128 : 21..21, + EnSDERR : 20..20, + TMEA : 19..19, + EnSNERR : 18..18, + D128En : 17..17, + PTTWI : 16..16, + SCTLR2En : 15..15, + TCR2En : 14..14, + MSCEn : 11..11, + MCE2 : 10..10, + CMOW : 9..9, + VFNMI : 8..8, + VINMI : 7..7, + TALLINT : 6..6, + SMPME : 5..5, + FGTnXS : 4..4, + FnXS : 3..3, + EnASR : 2..2, + EnALS : 1..1, + EnAS0 : 0..0 + } + +register HCRX_EL2 : HCRX_EL2_Type + +val HaveFeatHCX : unit -> bool + +function HaveFeatHCX () = { + return(IsFeatureImplemented(FEAT_HCX)) +} + +val IsHCRXEL2Enabled : unit -> bool + +function IsHCRXEL2Enabled () = { + if not_bool(HaveFeatHCX()) then { + return(false) + }; + if HaveEL(EL3) & SCR_EL3[HXEn] == 0b0 then { + return(false) + }; + return(EL2Enabled()) +} + +val GCSEnabled : bits(2) -> bool + +function GCSEnabled el = { + if UsingAArch32() then { + return(false) + }; + if (HaveEL(EL3) & el != EL3) & SCR_EL3[GCSEn] == 0b0 then { + return(false) + }; + if (((el == EL0 | el == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0)) & (not_bool(IsHCRXEL2Enabled()) | HCRX_EL2[GCSEn] == 0b0) then { + return(false) + }; + return(GCSPCRSelected(el)) +} + +val AArch64_ChkFeat : bits(64) -> bits(64) + +function AArch64_ChkFeat feat_select = { + feat_en : bits(64) = Zeros(64); + feat_en[0] = Bit(if HaveGCS() & GCSEnabled(PSTATE.EL) then 0b1 else 0b0); + return(feat_select & not_vec(feat_en)) +} + +let TAG_GRANULE : int(16) = 16 + +val DataSynchronizationBarrier : forall ('nXS : Bool). + (MBReqDomain, MBReqTypes, bool('nXS)) -> unit + +val DataMemoryBarrier : (MBReqDomain, MBReqTypes) -> unit + +val SpeculativeStoreBypassBarrierToVA : unit -> unit + +val SpeculativeStoreBypassBarrierToPA : unit -> unit + +val Hint_Prefetch : forall ('stream : Bool) 'target. + (bits(64), PrefetchHint, int('target), bool('stream)) -> unit + +val Hint_RangePrefetch : forall 'count 'length 'reuse 'stride. + (bits(64), int('length), int('stride), int('count), int('reuse), bits(6)) -> unit + +val BigEndian : AccessType -> bool + +function BigEndian acctype = { + bigend : bool = undefined; + if HaveNV2Ext() & acctype == AccessType_NV2 then { + return(SCTLR_EL2[EE] == 0b1) + }; + if UsingAArch32() then { + bigend = PSTATE.E != 0b0 + } else if PSTATE.EL == EL0 then { + bigend = SCTLR_read__1()[E0E] != 0b0 + } else { + bigend = SCTLR_read__1()[EE] != 0b0 + }; + return(bigend) +} + +val IsDataAccess : AccessType -> bool + +function IsDataAccess acctype = { + return(not_bool(acctype == AccessType_IFETCH | acctype == AccessType_TTW | acctype == AccessType_DC | acctype == AccessType_IC | acctype == AccessType_AT)) +} + +val EffectiveTCMA : (bits(64), bits(2)) -> bits(1) + +function EffectiveTCMA (address, el) = { + tcma : bits(1) = undefined; + assert(HaveEL(el)); + let regime : bits(2) = S1TranslationRegime(el); + assert(not_bool(ELUsingAArch32(regime))); + match regime { + ? if ? == EL1 => { + tcma = if [address[55]] == 0b1 then TCR_EL1[TCMA1] else TCR_EL1[TCMA0] + }, + ? if ? == EL2 => { + if HaveVirtHostExt() & ELIsInHost(el) then { + tcma = if [address[55]] == 0b1 then TCR_EL2[TCMA1] else + TCR_EL2[TCMA0] + } else { + tcma = TCR_EL2[TCMA] + } + }, + ? if ? == EL3 => { + tcma = TCR_EL3[TCMA] + }, + _ => () + }; + return(tcma) +} + +val HaveMTE4Ext : unit -> bool + +function HaveMTE4Ext () = { + return(IsFeatureImplemented(FEAT_MTE4)) +} + +val EffectiveMTX : forall ('is_instr : Bool). + (bits(64), bool('is_instr), bits(2)) -> bits(1) + +function EffectiveMTX (address, is_instr, el) = { + mtx : bits(1) = undefined; + assert(HaveEL(el)); + let regime : bits(2) = S1TranslationRegime(el); + assert(not_bool(ELUsingAArch32(regime))); + if not_bool(HaveMTE4Ext()) | is_instr then { + mtx = 0b0 + } else { + match regime { + ? if ? == EL1 => { + mtx = if [address[55]] == 0b1 then TCR_EL1[MTX1] else + TCR_EL1[MTX0] + }, + ? if ? == EL2 => { + if HaveVirtHostExt() & ELIsInHost(el) then { + mtx = if [address[55]] == 0b1 then TCR_EL2[MTX1] else + TCR_EL2[MTX0] + } else { + mtx = TCR_EL2[MTX] + } + }, + ? if ? == EL3 => { + mtx = TCR_EL3[MTX] + }, + _ => () + } + }; + return(mtx) +} + +val PhysMemRead : forall 'size, 'size > 0. + (AddressDescriptor, int('size), AccessDescriptor, option(TranslationInfo)) -> (PhysMemRetStatus, bits(8 * 'size)) + +val PhysMemWrite : forall 'size, 'size > 0. + (AddressDescriptor, int('size), AccessDescriptor, option(TranslationInfo), bits(8 * 'size)) -> PhysMemRetStatus + +overload BigEndianReverse = {reverse_endianness} + +bitfield MPAM2_EL2_Type : bits(64) = + { + MPAMEN : 63..63, + TIDR : 58..58, + ALTSP_HFC : 56..56, + ALTSP_EL2 : 55..55, + ALTSP_FRCD : 54..54, + EnMPAMSM : 50..50, + TRAPMPAM0EL1 : 49..49, + TRAPMPAM1EL1 : 48..48, + PMG_D : 47..40, + PMG_I : 39..32, + PARTID_D : 31..16, + PARTID_I : 15..0 + } + +register MPAM2_EL2 : MPAM2_EL2_Type + +bitfield MPAM3_EL3_Type : bits(64) = + { + MPAMEN : 63..63, + TRAPLOWER : 62..62, + SDEFLT : 61..61, + FORCE_NS : 60..60, + ALTSP_HEN : 57..57, + ALTSP_HFC : 56..56, + ALTSP_EL3 : 55..55, + RT_ALTSP_NS : 52..52, + PMG_D : 47..40, + PMG_I : 39..32, + PARTID_D : 31..16, + PARTID_I : 15..0 + } + +register _MPAM3_EL3 : MPAM3_EL3_Type + +val MPAM3_EL3_read : unit -> MPAM3_EL3_Type + +function MPAM3_EL3_read () = { + r : MPAM3_EL3_Type = _MPAM3_EL3; + r.bits[63] = Bit(Slice(MPAM2_EL2.bits, 63, 1)); + return(r) +} + +bitfield MPAM1_EL1_Type : bits(64) = + { + MPAMEN : 63..63, + FORCED_NS : 60..60, + ALTSP_FRCD : 54..54, + PMG_D : 47..40, + PMG_I : 39..32, + PARTID_D : 31..16, + PARTID_I : 15..0 + } + +register _MPAM1_EL1 : MPAM1_EL1_Type + +val MPAM1_EL1_read : unit -> MPAM1_EL1_Type + +function MPAM1_EL1_read () = { + r : MPAM1_EL1_Type = _MPAM1_EL1; + if HaveEL(EL3) then { + r.bits[63] = Bit(Slice(MPAM3_EL3_read().bits, 63, 1)) + } else { + r.bits[63] = Bit(Slice(MPAM2_EL2.bits, 63, 1)) + }; + return(r) +} + +val MPAMisEnabled : unit -> bool + +function MPAMisEnabled () = { + let el : bits(2) = HighestEL(); + match el { + ? if ? == EL3 => { + return(MPAM3_EL3_read()[MPAMEN] == 0b1) + }, + ? if ? == EL2 => { + return(MPAM2_EL2[MPAMEN] == 0b1) + }, + ? if ? == EL1 => { + return(MPAM1_EL1_read()[MPAMEN] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val UsePrimarySpaceEL10 : unit -> bool + +function UsePrimarySpaceEL10 () = { + if MPAM3_EL3_read()[ALTSP_HEN] == 0b0 then { + return(MPAM3_EL3_read()[ALTSP_HFC] == 0b0) + }; + return((not_bool(MPAMisEnabled()) | not_bool(EL2Enabled())) | MPAM2_EL2[ALTSP_HFC] == 0b0) +} + +val UsePrimarySpaceEL2 : unit -> bool + +function UsePrimarySpaceEL2 () = { + if MPAM3_EL3_read()[ALTSP_HEN] == 0b0 then { + return(MPAM3_EL3_read()[ALTSP_HFC] == 0b0) + }; + return(not_bool(MPAMisEnabled()) | MPAM2_EL2[ALTSP_EL2] == 0b0) +} + +val AltPIdRealm : (bits(2), PARTIDspaceType) -> PARTIDspaceType + +function AltPIdRealm (el, primaryPIdSpace) = { + PIdSpace : PARTIDspaceType = primaryPIdSpace; + match el { + ? if ? == EL0 => { + if ELIsInHost(EL0) then { + if not_bool(UsePrimarySpaceEL2()) then { + PIdSpace = PIdSpace_NonSecure + }; + () + } else if not_bool(UsePrimarySpaceEL10()) then { + PIdSpace = PIdSpace_NonSecure + } else () + }, + ? if ? == EL1 => { + if not_bool(UsePrimarySpaceEL10()) then { + PIdSpace = PIdSpace_NonSecure + }; + () + }, + ? if ? == EL2 => { + if not_bool(UsePrimarySpaceEL2()) then { + PIdSpace = PIdSpace_NonSecure + }; + () + }, + _ => { + Unreachable() + } + }; + return(PIdSpace) +} + +val AltPIdSecure : (bits(2), PARTIDspaceType) -> PARTIDspaceType + +function AltPIdSecure (el, primaryPIdSpace) = { + PIdSpace : PARTIDspaceType = primaryPIdSpace; + let el2en : bool = EL2Enabled(); + match el { + ? if ? == EL0 => { + if el2en then { + if ELIsInHost(EL0) then { + if not_bool(UsePrimarySpaceEL2()) then { + PIdSpace = PIdSpace_NonSecure + }; + () + } else if not_bool(UsePrimarySpaceEL10()) then { + PIdSpace = PIdSpace_NonSecure + } else () + } else if MPAM3_EL3_read()[ALTSP_HEN] == 0b0 & MPAM3_EL3_read()[ALTSP_HFC] == 0b1 then { + PIdSpace = PIdSpace_NonSecure + } else () + }, + ? if ? == EL1 => { + if el2en then { + if not_bool(UsePrimarySpaceEL10()) then { + PIdSpace = PIdSpace_NonSecure + }; + () + } else if MPAM3_EL3_read()[ALTSP_HEN] == 0b0 & MPAM3_EL3_read()[ALTSP_HFC] == 0b1 then { + PIdSpace = PIdSpace_NonSecure + } else () + }, + ? if ? == EL2 => { + if not_bool(UsePrimarySpaceEL2()) then { + PIdSpace = PIdSpace_NonSecure + }; + () + }, + _ => { + Unreachable() + } + }; + return(PIdSpace) +} + +val AltPARTIDspace : (bits(2), SecurityState, PARTIDspaceType) -> PARTIDspaceType + +function AltPARTIDspace (el, security, primaryPIdSpace) = { + match security { + SS_NonSecure => { + assert(el != EL3); + return(primaryPIdSpace) + }, + SS_Secure => { + assert(el != EL3); + if primaryPIdSpace == PIdSpace_NonSecure then { + return(primaryPIdSpace) + }; + return(AltPIdSecure(el, primaryPIdSpace)) + }, + SS_Root => { + assert(el == EL3); + if MPAM3_EL3_read()[ALTSP_EL3] == 0b1 then { + if MPAM3_EL3_read()[RT_ALTSP_NS] == 0b1 then { + return(PIdSpace_NonSecure) + } else { + return(PIdSpace_Secure) + } + } else { + return(primaryPIdSpace) + } + }, + SS_Realm => { + assert(el != EL3); + return(AltPIdRealm(el, primaryPIdSpace)) + }, + _ => { + Unreachable(); + return(undefined : PARTIDspaceType) + } + } +} + +val DefaultMPAMinfo : PARTIDspaceType -> MPAMinfo + +function DefaultMPAMinfo partidspace = { + DefaultInfo : MPAMinfo = undefined; + DefaultInfo.mpam_sp = partidspace; + DefaultInfo.partid = DefaultPARTID; + DefaultInfo.pmg = DefaultPMG; + return(DefaultInfo) +} + +val HaveMPAMv0p1Ext : unit -> bool + +function HaveMPAMv0p1Ext () = { + return(IsFeatureImplemented(FEAT_MPAMv0p1)) +} + +val HaveMPAMv1p1Ext : unit -> bool + +function HaveMPAMv1p1Ext () = { + return(IsFeatureImplemented(FEAT_MPAMv1p1)) +} + +bitfield MPAMIDR_EL1_Type : bits(64) = + { + HAS_SDEFLT : 61..61, + HAS_FORCE_NS : 60..60, + SP4 : 59..59, + HAS_TIDR : 58..58, + HAS_ALTSP : 57..57, + PMG_MAX : 39..32, + VPMR_MAX : 20..18, + HAS_HCR : 17..17, + PARTID_MAX : 15..0 + } + +register MPAMIDR_EL1 : MPAMIDR_EL1_Type + +val PARTIDspaceFromSS : SecurityState -> PARTIDspaceType + +function PARTIDspaceFromSS security = { + match security { + SS_NonSecure => { + return(PIdSpace_NonSecure) + }, + SS_Root => { + return(PIdSpace_Root) + }, + SS_Realm => { + return(PIdSpace_Realm) + }, + SS_Secure => { + return(PIdSpace_Secure) + }, + _ => { + Unreachable(); + return(undefined : PARTIDspaceType) + } + } +} + +bitfield MPAMHCR_EL2_Type : bits(64) = + { + TRAP_MPAMIDR_EL1 : 31..31, + GSTAPP_PLK : 8..8, + EL1_VPMEN : 1..1, + EL0_VPMEN : 0..0 + } + +register MPAMHCR_EL2 : MPAMHCR_EL2_Type + +bitfield MPAMVPM0_EL2_Type : bits(64) = + { + PhyPARTID3 : 63..48, + PhyPARTID2 : 47..32, + PhyPARTID1 : 31..16, + PhyPARTID0 : 15..0 + } + +register MPAMVPM0_EL2 : MPAMVPM0_EL2_Type + +bitfield MPAMVPMV_EL2_Type : bits(64) = + { + VPM_V31 : 31..31, + VPM_V30 : 30..30, + VPM_V29 : 29..29, + VPM_V28 : 28..28, + VPM_V27 : 27..27, + VPM_V26 : 26..26, + VPM_V25 : 25..25, + VPM_V24 : 24..24, + VPM_V23 : 23..23, + VPM_V22 : 22..22, + VPM_V21 : 21..21, + VPM_V20 : 20..20, + VPM_V19 : 19..19, + VPM_V18 : 18..18, + VPM_V17 : 17..17, + VPM_V16 : 16..16, + VPM_V15 : 15..15, + VPM_V14 : 14..14, + VPM_V13 : 13..13, + VPM_V12 : 12..12, + VPM_V11 : 11..11, + VPM_V10 : 10..10, + VPM_V9 : 9..9, + VPM_V8 : 8..8, + VPM_V7 : 7..7, + VPM_V6 : 6..6, + VPM_V5 : 5..5, + VPM_V4 : 4..4, + VPM_V3 : 3..3, + VPM_V2 : 2..2, + VPM_V1 : 1..1, + VPM_V0 : 0..0 + } + +register MPAMVPMV_EL2 : MPAMVPMV_EL2_Type + +bitfield MPAMVPM1_EL2_Type : bits(64) = + { + PhyPARTID7 : 63..48, + PhyPARTID6 : 47..32, + PhyPARTID5 : 31..16, + PhyPARTID4 : 15..0 + } + +register MPAMVPM1_EL2 : MPAMVPM1_EL2_Type + +bitfield MPAMVPM2_EL2_Type : bits(64) = + { + PhyPARTID11 : 63..48, + PhyPARTID10 : 47..32, + PhyPARTID9 : 31..16, + PhyPARTID8 : 15..0 + } + +register MPAMVPM2_EL2 : MPAMVPM2_EL2_Type + +bitfield MPAMVPM3_EL2_Type : bits(64) = + { + PhyPARTID15 : 63..48, + PhyPARTID14 : 47..32, + PhyPARTID13 : 31..16, + PhyPARTID12 : 15..0 + } + +register MPAMVPM3_EL2 : MPAMVPM3_EL2_Type + +bitfield MPAMVPM4_EL2_Type : bits(64) = + { + PhyPARTID19 : 63..48, + PhyPARTID18 : 47..32, + PhyPARTID17 : 31..16, + PhyPARTID16 : 15..0 + } + +register MPAMVPM4_EL2 : MPAMVPM4_EL2_Type + +bitfield MPAMVPM5_EL2_Type : bits(64) = + { + PhyPARTID23 : 63..48, + PhyPARTID22 : 47..32, + PhyPARTID21 : 31..16, + PhyPARTID20 : 15..0 + } + +register MPAMVPM5_EL2 : MPAMVPM5_EL2_Type + +bitfield MPAMVPM6_EL2_Type : bits(64) = + { + PhyPARTID27 : 63..48, + PhyPARTID26 : 47..32, + PhyPARTID25 : 31..16, + PhyPARTID24 : 15..0 + } + +register MPAMVPM6_EL2 : MPAMVPM6_EL2_Type + +bitfield MPAMVPM7_EL2_Type : bits(64) = + { + PhyPARTID31 : 63..48, + PhyPARTID30 : 47..32, + PhyPARTID29 : 31..16, + PhyPARTID28 : 15..0 + } + +register MPAMVPM7_EL2 : MPAMVPM7_EL2_Type + +val mapvpmw : forall 'vpartid. int('vpartid) -> PARTIDtype + +function mapvpmw vpartid = { + vpmw : bits(64) = undefined; + let 'wd = DIV(vpartid, 4); + match wd { + 0 => { + vpmw = MPAMVPM0_EL2.bits + }, + 1 => { + vpmw = MPAMVPM1_EL2.bits + }, + 2 => { + vpmw = MPAMVPM2_EL2.bits + }, + 3 => { + vpmw = MPAMVPM3_EL2.bits + }, + 4 => { + vpmw = MPAMVPM4_EL2.bits + }, + 5 => { + vpmw = MPAMVPM5_EL2.bits + }, + 6 => { + vpmw = MPAMVPM6_EL2.bits + }, + 7 => { + vpmw = MPAMVPM7_EL2.bits + }, + _ => { + vpmw = Zeros(64) + } + }; + let vpmw = vpmw; + let 'vpme_lsb = MOD(vpartid, 4) * 16; + return(Slice(vpmw, vpme_lsb, 16)) +} + +val MAP_vPARTID : PARTIDtype -> (PARTIDtype, bool) + +function MAP_vPARTID vpartid = { + ret : PARTIDtype = undefined; + err : bool = undefined; + virt : int = UInt(vpartid); + let 'vpmrmax = UInt(MPAMIDR_EL1[VPMR_MAX]); + let 'vpartid_max = (vpmrmax << 2) + 3; + if UInt(vpartid) > vpartid_max then { + virt = MOD(virt, vpartid_max + 1) + }; + let 'virt = virt; + assert(constraint((0 <= 'virt & 'virt < 64))); + if [MPAMVPMV_EL2.bits[virt]] == 0b1 then { + ret = mapvpmw(virt); + err = false + } else if [MPAMVPMV_EL2.bits[0]] == 0b1 then { + ret = Slice(MPAMVPM0_EL2.bits, 0, 16); + err = false + } else { + ret = DefaultPARTID; + err = true + }; + let 'partid_max = UInt(MPAMIDR_EL1[PARTID_MAX]); + if UInt(ret) > partid_max then { + ret = DefaultPARTID; + err = true + }; + let err = err; + let ret = ret; + return((ret, err)) +} + +val MPAMisVirtual : bits(2) -> bool + +function MPAMisVirtual el = { + return((MPAMIDR_EL1[HAS_HCR] == 0b1 & EL2Enabled()) & ((el == EL0 & MPAMHCR_EL2[EL0_VPMEN] == 0b1) & (HCR_EL2[E2H] == 0b0 | HCR_EL2[TGE] == 0b0) | el == EL1 & MPAMHCR_EL2[EL1_VPMEN] == 0b1)) +} + +bitfield MPAM0_EL1_Type : bits(64) = + {PMG_D : 47..40, PMG_I : 39..32, PARTID_D : 31..16, PARTID_I : 15..0} + +register MPAM0_EL1 : MPAM0_EL1_Type + +bitfield MPAMSM_EL1_Type : bits(64) = {PMG_D : 47..40, PARTID_D : 31..16} + +register MPAMSM_EL1 : MPAMSM_EL1_Type + +val getMPAM_PARTID : forall ('InD : Bool) ('InSM : Bool). + (bits(2), bool('InD), bool('InSM)) -> PARTIDtype + +function getMPAM_PARTID (MPAMn, InD, InSM) = { + partid : PARTIDtype = undefined; + let el2avail : bool = EL2Enabled(); + if InSM then { + partid = MPAMSM_EL1[PARTID_D]; + return(partid) + }; + if InD then { + match MPAMn { + 0b11 => { + partid = MPAM3_EL3_read()[PARTID_I] + }, + 0b10 => { + partid = if el2avail then MPAM2_EL2[PARTID_I] else Zeros(16) + }, + 0b01 => { + partid = MPAM1_EL1_read()[PARTID_I] + }, + 0b00 => { + partid = MPAM0_EL1[PARTID_I] + }, + _ => { + partid = __UNKNOWN_PARTIDtype() + } + } + } else { + match MPAMn { + 0b11 => { + partid = MPAM3_EL3_read()[PARTID_D] + }, + 0b10 => { + partid = if el2avail then MPAM2_EL2[PARTID_D] else Zeros(16) + }, + 0b01 => { + partid = MPAM1_EL1_read()[PARTID_D] + }, + 0b00 => { + partid = MPAM0_EL1[PARTID_D] + }, + _ => { + partid = __UNKNOWN_PARTIDtype() + } + } + }; + return(partid) +} + +val genPARTID : forall ('InD : Bool) ('InSM : Bool). + (bits(2), bool('InD), bool('InSM)) -> (PARTIDtype, bool) + +function genPARTID (el, InD, InSM) = { + let partidel : PARTIDtype = getMPAM_PARTID(el, InD, InSM); + let partid_max : PARTIDtype = MPAMIDR_EL1[PARTID_MAX]; + if UInt(partidel) > UInt(partid_max) then { + return((DefaultPARTID, true)) + }; + if MPAMisVirtual(el) then { + return(MAP_vPARTID(partidel)) + } else { + return((partidel, false)) + } +} + +val getMPAM_PMG : forall ('InD : Bool) ('InSM : Bool). + (bits(2), bool('InD), bool('InSM)) -> PMGtype + +function getMPAM_PMG (MPAMn, InD, InSM) = { + pmg : PMGtype = undefined; + let el2avail : bool = EL2Enabled(); + if InSM then { + pmg = MPAMSM_EL1[PMG_D]; + return(pmg) + }; + if InD then { + match MPAMn { + 0b11 => { + pmg = MPAM3_EL3_read()[PMG_I] + }, + 0b10 => { + pmg = if el2avail then MPAM2_EL2[PMG_I] else Zeros(8) + }, + 0b01 => { + pmg = MPAM1_EL1_read()[PMG_I] + }, + 0b00 => { + pmg = MPAM0_EL1[PMG_I] + }, + _ => { + pmg = __UNKNOWN_PMGtype() + } + } + } else { + match MPAMn { + 0b11 => { + pmg = MPAM3_EL3_read()[PMG_D] + }, + 0b10 => { + pmg = if el2avail then MPAM2_EL2[PMG_D] else Zeros(8) + }, + 0b01 => { + pmg = MPAM1_EL1_read()[PMG_D] + }, + 0b00 => { + pmg = MPAM0_EL1[PMG_D] + }, + _ => { + pmg = __UNKNOWN_PMGtype() + } + } + }; + return(pmg) +} + +val genPMG : forall ('InD : Bool) ('InSM : Bool) ('partid_err : Bool). + (bits(2), bool('InD), bool('InSM), bool('partid_err)) -> PMGtype + +function genPMG (el, InD, InSM, partid_err) = { + let 'pmg_max = UInt(MPAMIDR_EL1[PMG_MAX]); + if partid_err then { + return(DefaultPMG) + }; + let groupel : PMGtype = getMPAM_PMG(el, InD, InSM); + if UInt(groupel) <= pmg_max then { + return(groupel) + }; + return(DefaultPMG) +} + +val genMPAM : forall ('InD : Bool) ('InSM : Bool). + (bits(2), bool('InD), bool('InSM), PARTIDspaceType) -> MPAMinfo + +function genMPAM (el, InD, InSM, pspace) = { + returninfo : MPAMinfo = undefined; + partidel : PARTIDtype = undefined; + perr : bool = undefined; + let gstplk : bool = ((el == EL0 & EL2Enabled()) & MPAMHCR_EL2[GSTAPP_PLK] == 0b1) & HCR_EL2[TGE] == 0b0; + let eff_el : bits(2) = if gstplk then EL1 else el; + (partidel, perr) = genPARTID(eff_el, InD, InSM); + let groupel : PMGtype = genPMG(eff_el, InD, InSM, perr); + returninfo.mpam_sp = pspace; + returninfo.partid = partidel; + returninfo.pmg = groupel; + return(returninfo) +} + +val GenMPAMatEL : (AccessType, bits(2)) -> MPAMinfo + +function GenMPAMatEL (acctype, el) = { + mpamEL : bits(2) = undefined; + validEL_name : bool = false; + let security : SecurityState = SecurityStateAtEL(el); + InD : bool = false; + InSM : bool = false; + pspace : PARTIDspaceType = PARTIDspaceFromSS(security); + if pspace == PIdSpace_NonSecure & not_bool(MPAMisEnabled()) then { + return(DefaultMPAMinfo(pspace)) + }; + if UsingAArch32() then { + (validEL_name, mpamEL) = ELFromM32(PSTATE.M) + } else { + mpamEL = if acctype == AccessType_NV2 then EL2 else el; + validEL_name = true + }; + match acctype { + AccessType_IFETCH => { + InD = true + }, + AccessType_IC => { + InD = true + }, + AccessType_SME => { + InSM = __IMPDEF_boolean("Shared SMCU") | __IMPDEF_boolean("MPAMSM_EL1 label precedence") + }, + AccessType_ASIMD => { + InSM = (HaveSME() & PSTATE.SM == 0b1) & (__IMPDEF_boolean("Shared SMCU") | __IMPDEF_boolean("MPAMSM_EL1 label precedence")) + }, + AccessType_SVE => { + InSM = (HaveSME() & PSTATE.SM == 0b1) & (__IMPDEF_boolean("Shared SMCU") | __IMPDEF_boolean("MPAMSM_EL1 label precedence")) + }, + _ => { + InD = false + } + }; + if not_bool(validEL_name) then { + return(DefaultMPAMinfo(pspace)) + } else if HaveRME() & MPAMIDR_EL1[HAS_ALTSP] == 0b1 then { + pspace = AltPARTIDspace(mpamEL, security, pspace) + } else (); + if HaveMPAMv0p1Ext() & MPAMIDR_EL1[HAS_FORCE_NS] == 0b1 then { + if MPAM3_EL3_read()[FORCE_NS] == 0b1 & security == SS_Secure then { + pspace = PIdSpace_NonSecure + }; + () + }; + if (HaveMPAMv0p1Ext() | HaveMPAMv1p1Ext()) & MPAMIDR_EL1[HAS_SDEFLT] == 0b1 then { + if MPAM3_EL3_read()[SDEFLT] == 0b1 & security == SS_Secure then { + return(DefaultMPAMinfo(pspace)) + }; + () + }; + if not_bool(MPAMisEnabled()) then { + return(DefaultMPAMinfo(pspace)) + } else { + return(genMPAM(mpamEL, InD, InSM, pspace)) + } +} + +val GenMPAMcurEL : AccessType -> MPAMinfo + +function GenMPAMcurEL acctype = { + return(GenMPAMatEL(acctype, PSTATE.EL)) +} + +val NewAccDesc : AccessType -> AccessDescriptor + +function NewAccDesc acctype = { + accdesc : AccessDescriptor = undefined; + accdesc.acctype = acctype; + accdesc.el = PSTATE.EL; + accdesc.ss = SecurityStateAtEL(PSTATE.EL); + accdesc.acqsc = false; + accdesc.acqpc = false; + accdesc.relsc = false; + accdesc.limitedordered = false; + accdesc.exclusive = false; + accdesc.rcw = false; + accdesc.rcws = false; + accdesc.atomicop = false; + accdesc.nontemporal = false; + accdesc.read = false; + accdesc.write = false; + accdesc.pan = false; + accdesc.nonfault = false; + accdesc.firstfault = false; + accdesc.first = false; + accdesc.contiguous = false; + accdesc.streamingsve = false; + accdesc.ls64 = false; + accdesc.mops = false; + accdesc.a32lsmd = false; + accdesc.tagchecked = false; + accdesc.tagaccess = false; + accdesc.transactional = false; + accdesc.mpam = GenMPAMcurEL(acctype); + return(accdesc) +} + +val CreateAccDescIFetch : unit -> AccessDescriptor + +function CreateAccDescIFetch () = { + let accdesc : AccessDescriptor = NewAccDesc(AccessType_IFETCH); + return(accdesc) +} + +val CreateAccDescGPR : forall ('nontemporal : Bool) ('privileged : Bool) ('tagchecked : Bool). + (MemOp, bool('nontemporal), bool('privileged), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescGPR (memop, nontemporal, privileged, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.el = if not_bool(privileged) then EL0 else PSTATE.EL; + accdesc.nontemporal = nontemporal; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescExLDST : forall ('acqrel : Bool) ('tagchecked : Bool). + (MemOp, bool('acqrel), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescExLDST (memop, acqrel, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.acqsc = acqrel & memop == MemOp_LOAD; + accdesc.relsc = acqrel & memop == MemOp_STORE; + accdesc.exclusive = true; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescLDGSTG : MemOp -> AccessDescriptor + +function CreateAccDescLDGSTG memop = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.tagaccess = true; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescMOPS : forall ('nontemporal : Bool) ('privileged : Bool). + (MemOp, bool('privileged), bool('nontemporal)) -> AccessDescriptor + +function CreateAccDescMOPS (memop, privileged, nontemporal) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.el = if not_bool(privileged) then EL0 else PSTATE.EL; + accdesc.nontemporal = nontemporal; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.mops = true; + accdesc.tagchecked = true; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescSTGMOPS : forall ('nontemporal : Bool) ('privileged : Bool). + (bool('privileged), bool('nontemporal)) -> AccessDescriptor + +function CreateAccDescSTGMOPS (privileged, nontemporal) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.el = if not_bool(privileged) then EL0 else PSTATE.EL; + accdesc.nontemporal = nontemporal; + accdesc.write = true; + accdesc.pan = true; + accdesc.mops = true; + accdesc.tagaccess = true; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescAtomicOp : forall ('acquire : Bool) ('release : Bool) ('tagchecked : Bool). + (MemAtomicOp, bool('acquire), bool('release), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescAtomicOp (modop, acquire, release, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.acqsc = acquire; + accdesc.relsc = release; + accdesc.atomicop = true; + accdesc.modop = modop; + accdesc.read = true; + accdesc.write = true; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescRCW : forall ('acquire : Bool) ('release : Bool) ('soft : Bool) ('tagchecked : Bool). + (MemAtomicOp, bool('soft), bool('acquire), bool('release), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescRCW (modop, soft, acquire, release, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.acqsc = acquire; + accdesc.relsc = release; + accdesc.rcw = true; + accdesc.rcws = soft; + accdesc.atomicop = true; + accdesc.modop = modop; + accdesc.read = true; + accdesc.write = true; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescAcqRel : forall ('tagchecked : Bool). + (MemOp, bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescAcqRel (memop, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.acqsc = memop == MemOp_LOAD; + accdesc.relsc = memop == MemOp_STORE; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescLOR : forall ('tagchecked : Bool). + (MemOp, bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescLOR (memop, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.acqsc = memop == MemOp_LOAD; + accdesc.relsc = memop == MemOp_STORE; + accdesc.limitedordered = true; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescLDAcqPC : forall ('tagchecked : Bool). + bool('tagchecked) -> AccessDescriptor + +function CreateAccDescLDAcqPC tagchecked = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.acqpc = true; + accdesc.read = true; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescA32LSMD : MemOp -> AccessDescriptor + +function CreateAccDescA32LSMD memop = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.a32lsmd = true; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescLS64 : forall ('tagchecked : Bool). + (MemOp, bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescLS64 (memop, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPR); + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.ls64 = true; + accdesc.tagchecked = tagchecked; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val InStreamingMode : unit -> bool + +function InStreamingMode () = { + return(HaveSME() & PSTATE.SM == 0b1) +} + +val CreateAccDescASIMD : forall ('nontemporal : Bool) ('tagchecked : Bool). + (MemOp, bool('nontemporal), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescASIMD (memop, nontemporal, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_ASIMD); + accdesc.nontemporal = nontemporal; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.streamingsve = InStreamingMode(); + if accdesc.streamingsve & __IMPDEF_boolean("No tag checking of SIMD&FP loads and stores in Streaming SVE mode") then { + accdesc.tagchecked = false + } else { + accdesc.tagchecked = tagchecked + }; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescASIMDAcqRel : forall ('tagchecked : Bool). + (MemOp, bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescASIMDAcqRel (memop, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_ASIMD); + accdesc.acqpc = memop == MemOp_LOAD; + accdesc.relsc = memop == MemOp_STORE; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.streamingsve = InStreamingMode(); + if accdesc.streamingsve & __IMPDEF_boolean("No tag checking of SIMD&FP loads and stores in Streaming SVE mode") then { + accdesc.tagchecked = false + } else { + accdesc.tagchecked = tagchecked + }; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescIC : CacheRecord -> AccessDescriptor + +function CreateAccDescIC cache = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_IC); + accdesc.cacheop = cache.cacheop; + accdesc.cachetype = cache.cachetype; + accdesc.opscope = cache.opscope; + return(accdesc) +} + +val CreateAccDescDC : CacheRecord -> AccessDescriptor + +function CreateAccDescDC cache = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_DC); + accdesc.cacheop = cache.cacheop; + accdesc.cachetype = cache.cachetype; + accdesc.opscope = cache.opscope; + return(accdesc) +} + +val CreateAccDescDCZero : forall ('tagaccess : Bool) ('tagchecked : Bool). + (bool('tagaccess), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescDCZero (tagaccess, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_DCZero); + accdesc.write = true; + accdesc.pan = true; + accdesc.tagchecked = tagchecked; + accdesc.tagaccess = tagaccess; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescAT : forall ('pan : Bool) ('write : Bool). + (SecurityState, bits(2), bool('write), bool('pan)) -> AccessDescriptor + +function CreateAccDescAT (ss, el, write, pan) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_AT); + accdesc.el = el; + accdesc.ss = ss; + accdesc.read = not_bool(write); + accdesc.write = write; + accdesc.pan = pan; + return(accdesc) +} + +val CreateAccDescTTEUpdate : AccessDescriptor -> AccessDescriptor + +function CreateAccDescTTEUpdate accdesc_in = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_TTW); + accdesc.el = accdesc_in.el; + accdesc.ss = accdesc_in.ss; + accdesc.atomicop = true; + accdesc.modop = MemAtomicOp_CAS; + accdesc.read = true; + accdesc.write = true; + accdesc.mpam = accdesc_in.mpam; + return(accdesc) +} + +val CreateAccDescS1TTW : forall ('toplevel : Bool). + (bool('toplevel), VARange, AccessDescriptor) -> AccessDescriptor + +function CreateAccDescS1TTW (toplevel, varange, accdesc_in) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_TTW); + accdesc.el = accdesc_in.el; + accdesc.ss = accdesc_in.ss; + accdesc.read = true; + accdesc.toplevel = toplevel; + accdesc.varange = varange; + accdesc.mpam = accdesc_in.mpam; + return(accdesc) +} + +val CreateAccDescS2TTW : AccessDescriptor -> AccessDescriptor + +function CreateAccDescS2TTW accdesc_in = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_TTW); + accdesc.el = accdesc_in.el; + accdesc.ss = accdesc_in.ss; + accdesc.read = true; + accdesc.mpam = accdesc_in.mpam; + return(accdesc) +} + +val CreateAccDescSVENF : forall ('contiguous : Bool) ('tagchecked : Bool). + (bool('contiguous), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescSVENF (contiguous, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_SVE); + accdesc.read = true; + accdesc.pan = true; + accdesc.nonfault = true; + accdesc.contiguous = contiguous; + accdesc.streamingsve = InStreamingMode(); + if accdesc.streamingsve & __IMPDEF_boolean("No tag checking of SIMD&FP loads and stores in Streaming SVE mode") then { + accdesc.tagchecked = false + } else { + accdesc.tagchecked = tagchecked + }; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescSVEFF : forall ('contiguous : Bool) ('tagchecked : Bool). + (bool('contiguous), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescSVEFF (contiguous, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_SVE); + accdesc.read = true; + accdesc.pan = true; + accdesc.firstfault = true; + accdesc.first = true; + accdesc.contiguous = contiguous; + accdesc.streamingsve = InStreamingMode(); + if accdesc.streamingsve & __IMPDEF_boolean("No tag checking of SIMD&FP loads and stores in Streaming SVE mode") then { + accdesc.tagchecked = false + } else { + accdesc.tagchecked = tagchecked + }; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescSVE : forall ('contiguous : Bool) ('nontemporal : Bool) ('tagchecked : Bool). + (MemOp, bool('nontemporal), bool('contiguous), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescSVE (memop, nontemporal, contiguous, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_SVE); + accdesc.nontemporal = nontemporal; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.contiguous = contiguous; + accdesc.streamingsve = InStreamingMode(); + if accdesc.streamingsve & __IMPDEF_boolean("No tag checking of SIMD&FP loads and stores in Streaming SVE mode") then { + accdesc.tagchecked = false + } else { + accdesc.tagchecked = tagchecked + }; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescSME : forall ('contiguous : Bool) ('nontemporal : Bool) ('tagchecked : Bool). + (MemOp, bool('nontemporal), bool('contiguous), bool('tagchecked)) -> AccessDescriptor + +function CreateAccDescSME (memop, nontemporal, contiguous, tagchecked) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_SME); + accdesc.nontemporal = nontemporal; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.pan = true; + accdesc.contiguous = contiguous; + accdesc.streamingsve = true; + if __IMPDEF_boolean("No tag checking of SME LDR & STR instructions") then { + accdesc.tagchecked = false + } else { + accdesc.tagchecked = tagchecked + }; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescNV2 : MemOp -> AccessDescriptor + +function CreateAccDescNV2 memop = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_NV2); + accdesc.el = EL2; + accdesc.ss = SecurityStateAtEL(EL2); + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + accdesc.transactional = HaveTME() & TSTATE.depth > 0; + return(accdesc) +} + +val CreateAccDescSPE : (SecurityState, bits(2)) -> AccessDescriptor + +function CreateAccDescSPE (owning_ss, owning_el) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_SPE); + accdesc.el = owning_el; + accdesc.ss = owning_ss; + accdesc.write = true; + accdesc.mpam = GenMPAMatEL(AccessType_SPE, owning_el); + return(accdesc) +} + +val CreateAccDescGPTW : AccessDescriptor -> AccessDescriptor + +function CreateAccDescGPTW accdesc_in = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GPTW); + accdesc.el = accdesc_in.el; + accdesc.ss = accdesc_in.ss; + accdesc.read = true; + accdesc.mpam = accdesc_in.mpam; + return(accdesc) +} + +val CreateAccDescGCS : (bits(2), MemOp) -> AccessDescriptor + +function CreateAccDescGCS (el, memop) = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GCS); + accdesc.el = el; + accdesc.read = memop == MemOp_LOAD; + accdesc.write = memop == MemOp_STORE; + return(accdesc) +} + +val CreateAccDescGCSSS1 : bits(2) -> AccessDescriptor + +function CreateAccDescGCSSS1 el = { + accdesc : AccessDescriptor = NewAccDesc(AccessType_GCS); + accdesc.el = el; + accdesc.atomicop = true; + accdesc.modop = MemAtomicOp_GCSSS1; + accdesc.read = true; + accdesc.write = true; + return(accdesc) +} + +val TranslationRegime : bits(2) -> Regime + +function TranslationRegime el = { + if el == EL3 then { + return(if ELUsingAArch32(EL3) then Regime_EL30 else Regime_EL3) + } else if el == EL2 then { + return(if ELIsInHost(EL2) then Regime_EL20 else Regime_EL2) + } else if el == EL1 then { + return(Regime_EL10) + } else if el == EL0 then { + if CurrentSecurityState() == SS_Secure & ELUsingAArch32(EL3) then { + return(Regime_EL30) + } else if ELIsInHost(EL0) then { + return(Regime_EL20) + } else { + return(Regime_EL10) + } + } else { + Unreachable(); + return(undefined : Regime) + } +} + +val AlignmentEnforced : unit -> bool + +function AlignmentEnforced () = { + let regime : Regime = TranslationRegime(PSTATE.EL); + A : bits(1) = undefined; + match regime { + Regime_EL3 => { + A = SCTLR_EL3[A] + }, + Regime_EL30 => { + A = SCTLR_read__2()[A] + }, + Regime_EL2 => { + A = if ELUsingAArch32(EL2) then HSCTLR_read()[A] else SCTLR_EL2[A] + }, + Regime_EL20 => { + A = SCTLR_EL2[A] + }, + Regime_EL10 => { + A = if ELUsingAArch32(EL1) then SCTLR_read__2()[A] else SCTLR_EL1[A] + }, + _ => { + Unreachable() + } + }; + return(A == 0b1) +} + +val IsExclusiveLocal : forall 'processorid 'size. + (FullAddress, int('processorid), int('size)) -> bool + +val IsExclusiveGlobal : forall 'processorid 'size. + (FullAddress, int('processorid), int('size)) -> bool + +val MarkExclusiveLocal : forall 'processorid 'size. + (FullAddress, int('processorid), int('size)) -> unit + +val MarkExclusiveGlobal : forall 'processorid 'size. + (FullAddress, int('processorid), int('size)) -> unit + +val ClearExclusiveByAddress : forall 'processorid 'size. + (FullAddress, int('processorid), int('size)) -> unit + +val ExclusiveMonitorsStatus : unit -> bits(1) + +val ConstrainUnpredictable : Unpredictable -> Constraint + +val ConstrainUnpredictableProcedure : Unpredictable -> unit + +val CPASAtPAS : PASpace -> CachePASpace + +function CPASAtPAS pas = { + match pas { + PAS_NonSecure => { + return(CPAS_NonSecure) + }, + PAS_Secure => { + return(CPAS_Secure) + }, + PAS_Root => { + return(CPAS_Root) + }, + PAS_Realm => { + return(CPAS_Realm) + }, + _ => { + return(undefined : CachePASpace) + } + } +} + +val CPASAtSecurityState : SecurityState -> CachePASpace + +function CPASAtSecurityState ss = { + match ss { + SS_NonSecure => { + return(CPAS_NonSecure) + }, + SS_Secure => { + return(CPAS_SecureNonSecure) + }, + SS_Root => { + return(CPAS_Any) + }, + SS_Realm => { + return(CPAS_RealmNonSecure) + }, + _ => { + return(undefined : CachePASpace) + } + } +} + +val ICInstNeedsTranslation : CacheOpScope -> bool + +function ICInstNeedsTranslation opscope = { + return(__IMPDEF_boolean("Instruction Cache needs translation")) +} + +bitfield CLIDR_EL1_Type : bits(64) = + { + Ttype7 : 46..45, + Ttype6 : 44..43, + Ttype5 : 42..41, + Ttype4 : 40..39, + Ttype3 : 38..37, + Ttype2 : 36..35, + Ttype1 : 34..33, + ICB : 32..30, + LoUU : 29..27, + LoC : 26..24, + LoUIS : 23..21, + Ctype7 : 20..18, + Ctype6 : 17..15, + Ctype5 : 14..12, + Ctype4 : 11..9, + Ctype3 : 8..6, + Ctype2 : 5..3, + Ctype1 : 2..0 + } + +register CLIDR_EL1 : CLIDR_EL1_Type + +val DCInstNeedsTranslation : CacheOpScope -> bool + +function DCInstNeedsTranslation opscope = { + if opscope == CacheOpScope_PoE then { + return(false) + }; + if opscope == CacheOpScope_PoPA then { + return(false) + }; + if CLIDR_EL1[LoC] == 0b000 then { + return(not_bool(__IMPDEF_boolean("No fault generated for DC operations if PoC is before any level of cache"))) + }; + if CLIDR_EL1[LoUU] == 0b000 & opscope == CacheOpScope_PoU then { + return(not_bool(__IMPDEF_boolean("No fault generated for DC operations if PoU is before any level of cache"))) + }; + return(true) +} + +val GetCacheInfo : forall 'level. (int('level), CacheType) -> (int, int, int) + +val DecodeSW : (bits(64), CacheType) -> (int, int, int) + +function DecodeSW (regval, cachetype) = { + linesize : int = undefined; + setnum : int = undefined; + waynum : int = undefined; + let 'level = UInt(regval[3 .. 1]); + (setnum, waynum, linesize) = GetCacheInfo(level, cachetype); + let 'waynum = waynum; + let 'setnum = setnum; + return((setnum, waynum, level)) +} + +val CACHE_OP : CacheRecord -> unit + +val HaveCRCExt : unit -> bool + +function HaveCRCExt () = { + return(IsFeatureImplemented(FEAT_CRC32)) +} + +val BitReverse : forall 'N, 'N >= 0. bits('N) -> bits('N) + +function BitReverse data = { + result : bits('N) = undefined; + foreach (i from 0 to ('N - 1) by 1 in inc) { + result['N - i - 1] = Bit([data[i]]) + }; + return(result) +} + +val Poly32Mod2 : forall 'N, 'N > 32. (bits('N), bits(32)) -> bits(32) + +function Poly32Mod2 (data_in, poly) = { + assert('N > 32); + data : bits('N) = data_in; + foreach (i from ('N - 1) to 32 by 1 in dec) { + if [data[i]] == 0b1 then { + data[i - 1 .. 0] = EOR(data[i - 1 .. 0], poly @ Zeros(i - 32)) + }; + () + }; + return(data[31 .. 0]) +} + +val HaveAESExt : unit -> bool + +function HaveAESExt () = { + return(IsFeatureImplemented(FEAT_AES)) +} + +val HaveBit128PMULLExt : unit -> bool + +function HaveBit128PMULLExt () = { + return(IsFeatureImplemented(FEAT_PMULL)) +} + +val HaveSHA1Ext : unit -> bool + +function HaveSHA1Ext () = { + return(IsFeatureImplemented(FEAT_SHA1)) +} + +val HaveSHA256Ext : unit -> bool + +function HaveSHA256Ext () = { + return(IsFeatureImplemented(FEAT_SHA256)) +} + +val HaveSHA512Ext : unit -> bool + +function HaveSHA512Ext () = { + return(IsFeatureImplemented(FEAT_SHA512)) +} + +val HaveSHA3Ext : unit -> bool + +function HaveSHA3Ext () = { + return(IsFeatureImplemented(FEAT_SHA3)) +} + +val HaveSM3Ext : unit -> bool + +function HaveSM3Ext () = { + return(IsFeatureImplemented(FEAT_SM3)) +} + +val HaveSM4Ext : unit -> bool + +function HaveSM4Ext () = { + return(IsFeatureImplemented(FEAT_SM4)) +} + +val ROL : forall 'N 'shift, 'N >= 0. (bits('N), int('shift)) -> bits('N) + +function ROL (x, shift) = { + assert(shift >= 0 & shift <= 'N); + if shift == 0 then { + return(x) + }; + return(ROR(x, 'N - shift)) +} + +val AESShiftRows : bits(128) -> bits(128) + +function AESShiftRows op = { + return(((((((((((((((op[95 .. 88] @ op[55 .. 48]) @ op[15 .. 8]) @ op[103 .. 96]) @ op[63 .. 56]) @ op[23 .. 16]) @ op[111 .. 104]) @ op[71 .. 64]) @ op[31 .. 24]) @ op[119 .. 112]) @ op[79 .. 72]) @ op[39 .. 32]) @ op[127 .. 120]) @ op[87 .. 80]) @ op[47 .. 40]) @ op[7 .. 0]) +} + +val AESInvShiftRows : bits(128) -> bits(128) + +function AESInvShiftRows op = { + return(((((((((((((((op[31 .. 24] @ op[55 .. 48]) @ op[79 .. 72]) @ op[103 .. 96]) @ op[127 .. 120]) @ op[23 .. 16]) @ op[47 .. 40]) @ op[71 .. 64]) @ op[95 .. 88]) @ op[119 .. 112]) @ op[15 .. 8]) @ op[39 .. 32]) @ op[63 .. 56]) @ op[87 .. 80]) @ op[111 .. 104]) @ op[7 .. 0]) +} + +val AESSubBytes : bits(128) -> bits(128) + +function AESSubBytes op = { + let GF2 : bits(2048) = ((((((((((((((0x16bb54b00f2d99416842e6bf0d89a18c @ 0xdf2855cee9871e9b948ed9691198f8e1) @ 0x9e1dc186b95735610ef6034866b53e70) @ 0x8a8bbd4b1f74dde8c6b4a61c2e2578ba) @ 0x08ae7a65eaf4566ca94ed58d6d37c8e7) @ 0x79e4959162acd3c25c2406490a3a32e0) @ 0xdb0b5ede14b8ee4688902a22dc4f8160) @ 0x73195d643d7ea7c41744975fec130ccd) @ 0xd2f3ff1021dab6bcf5389d928f40a351) @ 0xa89f3c507f02f94585334d43fbaaefd0) @ 0xcf584c4a39becb6a5bb1fc20ed00d153) @ 0x842fe329b3d63b52a05a6e1b1a2c8309) @ 0x75b227ebe28012079a059618c323c704) @ 0x1531d871f1e5a534ccf73f362693fdb7) @ 0xc072a49cafa2d4adf04759fa7dc982ca) @ 0x76abd7fe2b670130c56f6bf27b777c63; + out : bits(128) = undefined; + foreach (i from 0 to 15 by 1 in inc) { + out = SetSlice(8, out, i * 8, Slice(GF2, UInt(Slice(op, i * 8, 8)) * 8, 8)) + }; + return(out) +} + +val AESInvSubBytes : bits(128) -> bits(128) + +function AESInvSubBytes op = { + let GF2_inv : bits(2048) = ((((((((((((((0x7d0c2155631469e126d677ba7e042b17 @ 0x619953833cbbebc8b0f52aae4d3be0a0) @ 0xef9cc9939f7ae52d0d4ab519a97f5160) @ 0x5fec8027591012b131c7078833a8dd1f) @ 0xf45acd78fec0db9a2079d2c64b3e56fc) @ 0x1bbe18aa0e62b76f89c5291d711af147) @ 0x6edf751ce837f9e28535ade72274ac96) @ 0x73e6b4f0cecff297eadc674f4111913a) @ 0x6b8a130103bdafc1020f3fca8f1e2cd0) @ 0x0645b3b80558e4f70ad3bc8c00abd890) @ 0x849d8da75746155edab9edfd5048706c) @ 0x92b6655dcc5ca4d41698688664f6f872) @ 0x25d18b6d49a25b76b224d92866a12e08) @ 0x4ec3fa420b954cee3d23c2a632947b54) @ 0xcbe9dec444438e3487ff2f9b8239e37c) @ 0xfbd7f3819ea340bf38a53630d56a0952; + out : bits(128) = undefined; + foreach (i from 0 to 15 by 1 in inc) { + out = SetSlice(8, out, i * 8, Slice(GF2_inv, UInt(Slice(op, i * 8, 8)) * 8, 8)) + }; + return(out) +} + +val FFmul02 : bits(8) -> bits(8) + +function FFmul02 b = { + let FFmul_02 : bits(2048) = ((((((((((((((0xE5E7E1E3EDEFE9EBF5F7F1F3FDFFF9FB @ 0xC5C7C1C3CDCFC9CBD5D7D1D3DDDFD9DB) @ 0xA5A7A1A3ADAFA9ABB5B7B1B3BDBFB9BB) @ 0x858781838D8F898B959791939D9F999B) @ 0x656761636D6F696B757771737D7F797B) @ 0x454741434D4F494B555751535D5F595B) @ 0x252721232D2F292B353731333D3F393B) @ 0x050701030D0F090B151711131D1F191B) @ 0xFEFCFAF8F6F4F2F0EEECEAE8E6E4E2E0) @ 0xDEDCDAD8D6D4D2D0CECCCAC8C6C4C2C0) @ 0xBEBCBAB8B6B4B2B0AEACAAA8A6A4A2A0) @ 0x9E9C9A98969492908E8C8A8886848280) @ 0x7E7C7A78767472706E6C6A6866646260) @ 0x5E5C5A58565452504E4C4A4846444240) @ 0x3E3C3A38363432302E2C2A2826242220) @ 0x1E1C1A18161412100E0C0A0806040200; + return(Slice(FFmul_02, UInt(b) * 8, 8)) +} + +val FFmul03 : bits(8) -> bits(8) + +function FFmul03 b = { + let FFmul_03 : bits(2048) = ((((((((((((((0x1A191C1F16151013020104070E0D080B @ 0x2A292C2F26252023323134373E3D383B) @ 0x7A797C7F76757073626164676E6D686B) @ 0x4A494C4F46454043525154575E5D585B) @ 0xDAD9DCDFD6D5D0D3C2C1C4C7CECDC8CB) @ 0xEAE9ECEFE6E5E0E3F2F1F4F7FEFDF8FB) @ 0xBAB9BCBFB6B5B0B3A2A1A4A7AEADA8AB) @ 0x8A898C8F86858083929194979E9D989B) @ 0x818287848D8E8B88999A9F9C95969390) @ 0xB1B2B7B4BDBEBBB8A9AAAFACA5A6A3A0) @ 0xE1E2E7E4EDEEEBE8F9FAFFFCF5F6F3F0) @ 0xD1D2D7D4DDDEDBD8C9CACFCCC5C6C3C0) @ 0x414247444D4E4B48595A5F5C55565350) @ 0x717277747D7E7B78696A6F6C65666360) @ 0x212227242D2E2B28393A3F3C35363330) @ 0x111217141D1E1B18090A0F0C05060300; + return(Slice(FFmul_03, UInt(b) * 8, 8)) +} + +val FFmul09 : bits(8) -> bits(8) + +function FFmul09 b = { + let FFmul_09 : bits(2048) = ((((((((((((((0x464F545D626B70790E071C152A233831 @ 0xD6DFC4CDF2FBE0E99E978C85BAB3A8A1) @ 0x7D746F6659504B42353C272E1118030A) @ 0xEDE4FFF6C9C0DBD2A5ACB7BE8188939A) @ 0x3039222B141D060F78716A635C554E47) @ 0xA0A9B2BB848D969FE8E1FAF3CCC5DED7) @ 0x0B0219102F263D34434A5158676E757C) @ 0x9B928980BFB6ADA4D3DAC1C8F7FEE5EC) @ 0xAAA3B8B18E879C95E2EBF0F9C6CFD4DD) @ 0x3A3328211E170C05727B6069565F444D) @ 0x9198838AB5BCA7AED9D0CBC2FDF4EFE6) @ 0x0108131A252C373E49405B526D647F76) @ 0xDCD5CEC7F8F1EAE3949D868FB0B9A2AB) @ 0x4C455E5768617A73040D161F2029323B) @ 0xE7EEF5FCC3CAD1D8AFA6BDB48B829990) @ 0x777E656C535A41483F362D241B120900; + return(Slice(FFmul_09, UInt(b) * 8, 8)) +} + +val FFmul0B : bits(8) -> bits(8) + +function FFmul0B b = { + let FFmul_0B : bits(2048) = ((((((((((((((0xA3A8B5BE8F849992FBF0EDE6D7DCC1CA @ 0x1318050E3F3429224B405D56676C717A) @ 0xD8D3CEC5F4FFE2E9808B969DACA7BAB1) @ 0x68637E75444F5259303B262D1C170A01) @ 0x555E434879726F640D061B10212A373C) @ 0xE5EEF3F8C9C2DFD4BDB6ABA0919A878C) @ 0x2E2538330209141F767D606B5A514C47) @ 0x9E958883B2B9A4AFC6CDD0DBEAE1FCF7) @ 0x545F424978736E650C071A11202B363D) @ 0xE4EFF2F9C8C3DED5BCB7AAA1909B868D) @ 0x2F2439320308151E777C616A5B504D46) @ 0x9F948982B3B8A5AEC7CCD1DAEBE0FDF6) @ 0xA2A9B4BF8E859893FAF1ECE7D6DDC0CB) @ 0x1219040F3E3528234A415C57666D707B) @ 0xD9D2CFC4F5FEE3E8818A979CADA6BBB0) @ 0x69627F74454E5358313A272C1D160B00; + return(Slice(FFmul_0B, UInt(b) * 8, 8)) +} + +val FFmul0D : bits(8) -> bits(8) + +function FFmul0D b = { + let FFmul_0D : bits(2048) = ((((((((((((((0x979A8D80A3AEB9B4FFF2E5E8CBC6D1DC @ 0x474A5D50737E69642F2235381B16010C) @ 0x2C21363B1815020F44495E53707D6A67) @ 0xFCF1E6EBC8C5D2DF94998E83A0ADBAB7) @ 0xFAF7E0EDCEC3D4D9929F8885A6ABBCB1) @ 0x2A27303D1E130409424F5855767B6C61) @ 0x414C5B5675786F622924333E1D10070A) @ 0x919C8B86A5A8BFB2F9F4E3EECDC0D7DA) @ 0x4D40575A7974636E25283F32111C0B06) @ 0x9D90878AA9A4B3BEF5F8EFE2C1CCDBD6) @ 0xF6FBECE1C2CFD8D59E938489AAA7B0BD) @ 0x262B3C31121F08054E4354597A77606D) @ 0x202D3A3714190E034845525F7C71666B) @ 0xF0FDEAE7C4C9DED39895828FACA1B6BB) @ 0x9B96818CAFA2B5B8F3FEE9E4C7CADDD0) @ 0x4B46515C7F726568232E3934171A0D00; + return(Slice(FFmul_0D, UInt(b) * 8, 8)) +} + +val FFmul0E : bits(8) -> bits(8) + +function FFmul0E b = { + let FFmul_0E : bits(2048) = ((((((((((((((0x8D83919FB5BBA9A7FDF3E1EFC5CBD9D7 @ 0x6D63717F555B49471D13010F252B3937) @ 0x56584A446E60727C26283A341E10020C) @ 0xB6B8AAA48E80929CC6C8DAD4FEF0E2EC) @ 0x202E3C321816040A505E4C426866747A) @ 0xC0CEDCD2F8F6E4EAB0BEACA28886949A) @ 0xFBF5E7E9C3CDDFD18B859799B3BDAFA1) @ 0x1B150709232D3F316B657779535D4F41) @ 0xCCC2D0DEF4FAE8E6BCB2A0AE848A9896) @ 0x2C22303E141A08065C52404E646A7876) @ 0x17190B052F21333D67697B755F51434D) @ 0xF7F9EBE5CFC1D3DD87899B95BFB1A3AD) @ 0x616F7D735957454B111F0D032927353B) @ 0x818F9D93B9B7A5ABF1FFEDE3C9C7D5DB) @ 0xBAB4A6A8828C9E90CAC4D6D8F2FCEEE0) @ 0x5A544648626C7E702A243638121C0E00; + return(Slice(FFmul_0E, UInt(b) * 8, 8)) +} + +val AESMixColumns : bits(128) -> bits(128) + +function AESMixColumns op = { + let in0 : bits(32) = ((Slice(op, 96, 8) @ Slice(op, 64, 8)) @ Slice(op, 32, 8)) @ Slice(op, 0, 8); + let in1 : bits(32) = ((Slice(op, 104, 8) @ Slice(op, 72, 8)) @ Slice(op, 40, 8)) @ Slice(op, 8, 8); + let in2 : bits(32) = ((Slice(op, 112, 8) @ Slice(op, 80, 8)) @ Slice(op, 48, 8)) @ Slice(op, 16, 8); + let in3 : bits(32) = ((Slice(op, 120, 8) @ Slice(op, 88, 8)) @ Slice(op, 56, 8)) @ Slice(op, 24, 8); + out0 : bits(32) = undefined; + out1 : bits(32) = undefined; + out2 : bits(32) = undefined; + out3 : bits(32) = undefined; + foreach (c from 0 to 3 by 1 in inc) { + out0 = SetSlice(8, out0, c * 8, EOR(EOR(EOR(FFmul02(Slice(in0, c * 8, 8)), FFmul03(Slice(in1, c * 8, 8))), Slice(in2, c * 8, 8)), Slice(in3, c * 8, 8))); + out1 = SetSlice(8, out1, c * 8, EOR(EOR(EOR(FFmul02(Slice(in1, c * 8, 8)), FFmul03(Slice(in2, c * 8, 8))), Slice(in3, c * 8, 8)), Slice(in0, c * 8, 8))); + out2 = SetSlice(8, out2, c * 8, EOR(EOR(EOR(FFmul02(Slice(in2, c * 8, 8)), FFmul03(Slice(in3, c * 8, 8))), Slice(in0, c * 8, 8)), Slice(in1, c * 8, 8))); + out3 = SetSlice(8, out3, c * 8, EOR(EOR(EOR(FFmul02(Slice(in3, c * 8, 8)), FFmul03(Slice(in0, c * 8, 8))), Slice(in1, c * 8, 8)), Slice(in2, c * 8, 8))) + }; + return(((((((((((((((Slice(out3, 3 * 8, 8) @ Slice(out2, 3 * 8, 8)) @ Slice(out1, 3 * 8, 8)) @ Slice(out0, 3 * 8, 8)) @ Slice(out3, 2 * 8, 8)) @ Slice(out2, 2 * 8, 8)) @ Slice(out1, 2 * 8, 8)) @ Slice(out0, 2 * 8, 8)) @ Slice(out3, 1 * 8, 8)) @ Slice(out2, 1 * 8, 8)) @ Slice(out1, 1 * 8, 8)) @ Slice(out0, 1 * 8, 8)) @ Slice(out3, 0 * 8, 8)) @ Slice(out2, 0 * 8, 8)) @ Slice(out1, 0 * 8, 8)) @ Slice(out0, 0 * 8, 8)) +} + +val AESInvMixColumns : bits(128) -> bits(128) + +function AESInvMixColumns op = { + let in0 : bits(32) = ((Slice(op, 96, 8) @ Slice(op, 64, 8)) @ Slice(op, 32, 8)) @ Slice(op, 0, 8); + let in1 : bits(32) = ((Slice(op, 104, 8) @ Slice(op, 72, 8)) @ Slice(op, 40, 8)) @ Slice(op, 8, 8); + let in2 : bits(32) = ((Slice(op, 112, 8) @ Slice(op, 80, 8)) @ Slice(op, 48, 8)) @ Slice(op, 16, 8); + let in3 : bits(32) = ((Slice(op, 120, 8) @ Slice(op, 88, 8)) @ Slice(op, 56, 8)) @ Slice(op, 24, 8); + out0 : bits(32) = undefined; + out1 : bits(32) = undefined; + out2 : bits(32) = undefined; + out3 : bits(32) = undefined; + foreach (c from 0 to 3 by 1 in inc) { + out0 = SetSlice(8, out0, c * 8, EOR(EOR(EOR(FFmul0E(Slice(in0, c * 8, 8)), FFmul0B(Slice(in1, c * 8, 8))), FFmul0D(Slice(in2, c * 8, 8))), FFmul09(Slice(in3, c * 8, 8)))); + out1 = SetSlice(8, out1, c * 8, EOR(EOR(EOR(FFmul09(Slice(in0, c * 8, 8)), FFmul0E(Slice(in1, c * 8, 8))), FFmul0B(Slice(in2, c * 8, 8))), FFmul0D(Slice(in3, c * 8, 8)))); + out2 = SetSlice(8, out2, c * 8, EOR(EOR(EOR(FFmul0D(Slice(in0, c * 8, 8)), FFmul09(Slice(in1, c * 8, 8))), FFmul0E(Slice(in2, c * 8, 8))), FFmul0B(Slice(in3, c * 8, 8)))); + out3 = SetSlice(8, out3, c * 8, EOR(EOR(EOR(FFmul0B(Slice(in0, c * 8, 8)), FFmul0D(Slice(in1, c * 8, 8))), FFmul09(Slice(in2, c * 8, 8))), FFmul0E(Slice(in3, c * 8, 8)))) + }; + return(((((((((((((((Slice(out3, 3 * 8, 8) @ Slice(out2, 3 * 8, 8)) @ Slice(out1, 3 * 8, 8)) @ Slice(out0, 3 * 8, 8)) @ Slice(out3, 2 * 8, 8)) @ Slice(out2, 2 * 8, 8)) @ Slice(out1, 2 * 8, 8)) @ Slice(out0, 2 * 8, 8)) @ Slice(out3, 1 * 8, 8)) @ Slice(out2, 1 * 8, 8)) @ Slice(out1, 1 * 8, 8)) @ Slice(out0, 1 * 8, 8)) @ Slice(out3, 0 * 8, 8)) @ Slice(out2, 0 * 8, 8)) @ Slice(out1, 0 * 8, 8)) @ Slice(out0, 0 * 8, 8)) +} + +val SHAchoose : (bits(32), bits(32), bits(32)) -> bits(32) + +function SHAchoose (x, y, z) = { + return(EOR(EOR(y, z) & x, z)) +} + +val SHAparity : (bits(32), bits(32), bits(32)) -> bits(32) + +function SHAparity (x, y, z) = { + return(EOR(EOR(x, y), z)) +} + +val SHAmajority : (bits(32), bits(32), bits(32)) -> bits(32) + +function SHAmajority (x, y, z) = { + return(x & y | (x | y) & z) +} + +val SHAhashSIGMA0 : bits(32) -> bits(32) + +function SHAhashSIGMA0 x = { + return(EOR(EOR(ROR(x, 2), ROR(x, 13)), ROR(x, 22))) +} + +val SHAhashSIGMA1 : bits(32) -> bits(32) + +function SHAhashSIGMA1 x = { + return(EOR(EOR(ROR(x, 6), ROR(x, 11)), ROR(x, 25))) +} + +val SHA256hash : forall ('part1 : Bool). + (bits(128), bits(128), bits(128), bool('part1)) -> bits(128) + +function SHA256hash (x_in, y_in, w, part1) = { + chs : bits(32) = undefined; + maj : bits(32) = undefined; + t : bits(32) = undefined; + x : bits(128) = x_in; + y : bits(128) = y_in; + foreach (e from 0 to 3 by 1 in inc) { + chs = SHAchoose(y[31 .. 0], y[63 .. 32], y[95 .. 64]); + maj = SHAmajority(x[31 .. 0], x[63 .. 32], x[95 .. 64]); + t = y[127 .. 96] + SHAhashSIGMA1(y[31 .. 0]) + chs + Elem_read(w, e, 32); + x[127 .. 96] = t + x[127 .. 96]; + y[127 .. 96] = t + SHAhashSIGMA0(x[31 .. 0]) + maj; + (y @ x) = ROL(y @ x, 32) + }; + return(if part1 then x else y) +} + +val Sbox : bits(8) -> bits(8) + +function Sbox sboxin = { + let sboxstring : bits(2048) = 0xd690e9fecce13db716b614c228fb2c052b679a762abe04c3aa441326498606999c4250f491ef987a33540b43edcfac62e4b31ca9c908e89580df94fa758f3fa64707a7fcf37317ba83593c19e6854fa8686b81b27164da8bf8eb0f4b70569d351e240e5e6358d1a225227c3b01217887d40046579fd327524c3602e7a0c4c89eeabf8ad240c738b5a3f7f2cef96115a1e0ae5da49b341a55ad933230f58cb1e31df6e22e8266ca60c02923ab0d534e6fd5db3745defd8e2f03ff6a726d6c5b518d1baf92bbddbc7f11d95c411f105ad80ac13188a5cd7bbd2d74d012b8e5b4b08969974a0c96777e65b9f109c56ec68418f07dec3adc4d2079ee5f3ed7cb3948; + let sboxin = UInt(sboxin); + let sboxout : bits(8) = sboxstring[(255 - sboxin) * 8 + 7 .. (255 - sboxin) * 8]; + return(sboxout) +} + +val TargetSecurityState : (bits(1), bits(1)) -> SecurityState + +function TargetSecurityState (NS, NSE) = { + let curr_ss : SecurityState = SecurityStateAtEL(PSTATE.EL); + if curr_ss == SS_NonSecure then { + return(SS_NonSecure) + } else if curr_ss == SS_Secure then { + match NS { + 0b0 => { + return(SS_Secure) + }, + 0b1 => { + return(SS_NonSecure) + }, + _ => { + return(undefined : SecurityState) + } + } + } else if HaveRME() then { + if curr_ss == SS_Root then { + match NSE @ NS { + 0b00 => { + return(SS_Secure) + }, + 0b01 => { + return(SS_NonSecure) + }, + 0b11 => { + return(SS_Realm) + }, + 0b10 => { + return(SS_Root) + }, + _ => { + return(undefined : SecurityState) + } + } + } else if curr_ss == SS_Realm then { + return(SS_Realm) + } else { + return(undefined : SecurityState) + } + } else { + return(undefined : SecurityState) + } +} + +val RESTRICT_PREDICTIONS : ExecutionCntxt -> unit + +function RESTRICT_PREDICTIONS c = { + return() +} + +bitfield CONTEXTIDR_EL1_Type : bits(64) = {PROCID : 31..0} + +register CONTEXTIDR_EL1 : CONTEXTIDR_EL1_Type + +bitfield TTBCR_Type : bits(32) = + { + EAE : 31..31, + SH1 : 29..28, + ORGN1 : 27..26, + IRGN1 : 25..24, + EPD1 : 23..23, + A1 : 22..22, + T1SZ : 18..16, + SH0 : 13..12, + ORGN0 : 11..10, + IRGN0 : 9..8, + EPD0 : 7..7, + T2E : 6..6, + PD1 : 5..5, + PD0 : 4..4, + T0SZ : 2..0, + N : 2..0 + } + +register _TTBCR_NS : TTBCR_Type + +val TTBCR_NS_read : unit -> TTBCR_Type + +function TTBCR_NS_read () = { + r : TTBCR_Type = _TTBCR_NS; + r.bits[31 .. 0] = Slice(TCR_EL1.bits, 0, 32); + return(r) +} + +register TTBCR_S : TTBCR_Type + +val TTBCR_read : unit -> TTBCR_Type + +function TTBCR_read () = { + r : TTBCR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = TTBCR_S + } else { + r = TTBCR_NS_read() + }; + return(r) +} + +val EAEisOne : unit -> bool + +function EAEisOne () = { + return(TTBCR_read()[EAE] == 0b1) +} + +bitfield CONTEXTIDR_Type : bits(32) = {ASID : 7..0} + +register _CONTEXTIDR_NS : CONTEXTIDR_Type + +val CONTEXTIDR_NS_read : unit -> CONTEXTIDR_Type + +function CONTEXTIDR_NS_read () = { + r : CONTEXTIDR_Type = _CONTEXTIDR_NS; + r.bits[31 .. 0] = Slice(CONTEXTIDR_EL1.bits, 0, 32); + return(r) +} + +register CONTEXTIDR_S : CONTEXTIDR_Type + +val CONTEXTIDR_read : unit -> CONTEXTIDR_Type + +function CONTEXTIDR_read () = { + r : CONTEXTIDR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = CONTEXTIDR_S + } else { + r = CONTEXTIDR_NS_read() + }; + return(r) +} + +bitfield TTBR0_Type : bits(64) = + { + ASID : 55..48, + TTB0 : 31..7, + NOS : 5..5, + RGN : 4..3, + IMP : 2..2, + BADDR : 47..1, + S : 1..1, + CnP : 0..0, + IRGN : (0..0 @ 6..6) + } + +register TTBR0_NS : TTBR0_Type + +register TTBR0_S : TTBR0_Type + +val TTBR0_read : unit -> TTBR0_Type + +function TTBR0_read () = { + r : TTBR0_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = TTBR0_S + } else { + r = TTBR0_NS + }; + return(r) +} + +bitfield TTBR0_EL1_Type : bits(128) = {ASID : 63..48, SKL : 2..1, CnP : 0..0} + +register _TTBR0_EL1 : TTBR0_EL1_Type + +val TTBR0_EL1_read : unit -> TTBR0_EL1_Type + +function TTBR0_EL1_read () = { + r : TTBR0_EL1_Type = _TTBR0_EL1; + r.bits[63 .. 0] = Slice(TTBR0_read().bits, 0, 64); + return(r) +} + +bitfield HTTBR_Type : bits(64) = {BADDR : 47..1, CnP : 0..0} + +register HTTBR : HTTBR_Type + +bitfield TTBR0_EL2_Type : bits(128) = {ASID : 63..48, SKL : 2..1, CnP : 0..0} + +register _TTBR0_EL2 : TTBR0_EL2_Type + +val TTBR0_EL2_read : unit -> TTBR0_EL2_Type + +function TTBR0_EL2_read () = { + r : TTBR0_EL2_Type = _TTBR0_EL2; + r.bits[47 .. 1] = Slice(HTTBR.bits, 1, 47); + return(r) +} + +bitfield TTBR1_Type : bits(64) = + { + ASID : 55..48, + TTB1 : 31..7, + IRGN : (6..6 @ 0..0), + NOS : 5..5, + RGN : 4..3, + IMP : 2..2, + BADDR : 47..1, + S : 1..1, + CnP : 0..0 + } + +register TTBR1_NS : TTBR1_Type + +register TTBR1_S : TTBR1_Type + +val TTBR1_read : unit -> TTBR1_Type + +function TTBR1_read () = { + r : TTBR1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = TTBR1_S + } else { + r = TTBR1_NS + }; + return(r) +} + +bitfield TTBR1_EL1_Type : bits(128) = {ASID : 63..48, SKL : 2..1, CnP : 0..0} + +register _TTBR1_EL1 : TTBR1_EL1_Type + +val TTBR1_EL1_read : unit -> TTBR1_EL1_Type + +function TTBR1_EL1_read () = { + r : TTBR1_EL1_Type = _TTBR1_EL1; + r.bits[63 .. 0] = Slice(TTBR1_read().bits, 0, 64); + return(r) +} + +bitfield TTBR1_EL2_Type : bits(128) = {ASID : 63..48, SKL : 2..1, CnP : 0..0} + +register TTBR1_EL2 : TTBR1_EL2_Type + +val ASID_read : unit -> bits(16) + +function ASID_read () = { + if (EL2Enabled() & not_bool(ELUsingAArch32(EL2))) & (HCR_EL2[E2H] @ HCR_EL2[TGE]) == 0b11 then { + if TCR_EL2[A1] == 0b1 then { + return(TTBR1_EL2[ASID]) + } else { + return(TTBR0_EL2_read()[ASID]) + } + } else if not_bool(ELUsingAArch32(EL1)) then { + if TCR_EL1[A1] == 0b1 then { + return(TTBR1_EL1_read()[ASID]) + } else { + return(TTBR0_EL1_read()[ASID]) + } + } else { + if TTBCR_read()[EAE] == 0b0 then { + return(ZeroExtend(CONTEXTIDR_read()[ASID], 16)) + } else { + if TTBCR_read()[A1] == 0b1 then { + return(ZeroExtend(TTBR1_read()[ASID], 16)) + } else { + return(ZeroExtend(TTBR0_read()[ASID], 16)) + } + } + } +} + +val RecipEstimate : forall 'a_in ('increasedprecision_name : Bool). + (int('a_in), bool('increasedprecision_name)) -> int + +function RecipEstimate (a_in, increasedprecision_name) = { + a : int = a_in; + r : int = undefined; + if not_bool(increasedprecision_name) then { + assert(256 <= a & a < 512); + let 'a = a * 2 + 1; + let 'b = DIV(2 ^ 19, a); + r = DIV(b + 1, 2); + assert(256 <= r & r < 512) + } else { + assert(2048 <= a & a < 4096); + let 'a = a * 2 + 1; + let real_val : real = Real(2 ^ 25) / Real(a); + r = RoundDown(real_val); + let error : real = real_val - Real(r); + let round_up : bool = error > 0.5; + if round_up then { + r = r + 1 + }; + assert(4096 <= r & r < 8192) + }; + let 'r = r; + return(r) +} + +val UnsignedRecipEstimate : forall 'N, 'N == 32. bits('N) -> bits('N) + +function UnsignedRecipEstimate operand = { + estimate : int = undefined; + increasedprecision_name : bool = undefined; + assert('N == 32); + result : bits('N) = undefined; + if [operand['N - 1]] == 0b0 then { + result = Ones('N) + } else { + let increasedprecision_name : bool = false; + let 'estimate = RecipEstimate(UInt(operand[31 .. 23]), increasedprecision_name); + result = estimate[8 .. 0] @ Zeros('N - 9) + }; + return(result) +} + +val RecipSqrtEstimate : forall 'a_in ('increasedprecision_name : Bool). + (int('a_in), bool('increasedprecision_name)) -> int + +function RecipSqrtEstimate (a_in, increasedprecision_name) = { + round_up : bool = undefined; + a : int = a_in; + r : int = undefined; + if not_bool(increasedprecision_name) then { + assert(128 <= a & a < 512); + if a < 256 then { + a = a * 2 + 1 + } else { + a = (((a >> 1)) << 1); + a = (a + 1) * 2 + }; + let 'a = a; + b : int = 512; + while a * (b + 1) * (b + 1) < pow2(28) do { + b = b + 1 + }; + let 'b = b; + r = DIV(b + 1, 2); + assert(256 <= r & r < 512) + } else { + assert(1024 <= a & a < 4096); + real_val : real = undefined; + if a < 2048 then { + let 'a = a * 2 + 1; + real_val = Real(a) / 2.0 + } else { + a : int = (((a >> 1)) << 1); + let 'a = a + 1; + real_val = Real(a) + }; + real_val : real = sqrt(real_val); + real_val : real = real_val * Real(2 ^ 47); + int_val : int = RoundDown(real_val); + error : real = real_val - Real(int_val); + round_up : bool = error > 0.5; + if round_up then { + int_val = int_val + 1 + }; + let real_val : real = Real(2 ^ 65) / Real(int_val); + int_val : int = RoundDown(real_val); + let error : real = real_val - Real(int_val); + let round_up : bool = error > 0.5 | error == 0.5 & [int_val[0]] == 0b1; + if round_up then { + int_val = int_val + 1 + }; + let 'int_val = int_val; + r = int_val; + assert(4096 <= r & r < 8192) + }; + let 'r = r; + return(r) +} + +val UnsignedRSqrtEstimate : forall 'N, 'N == 32. bits('N) -> bits('N) + +function UnsignedRSqrtEstimate operand = { + estimate : int = undefined; + increasedprecision_name : bool = undefined; + assert('N == 32); + result : bits('N) = undefined; + if operand['N - 1 .. 'N - 2] == 0b00 then { + result = Ones('N) + } else { + let increasedprecision_name : bool = false; + let 'estimate = RecipSqrtEstimate(UInt(operand[31 .. 23]), increasedprecision_name); + result = estimate[8 .. 0] @ Zeros('N - 9) + }; + return(result) +} + +val SignedSatQ : forall 'N 'i, 0 <= 'N - 1. + (int('i), int('N)) -> (bits('N), bool) + +function SignedSatQ (i, N) = { + result : int = undefined; + saturated : bool = undefined; + if i > pow2(N - 1) - 1 then { + result = pow2(N - 1) - 1; + saturated = true + } else if i < negate(2 ^ (N - 1)) then { + result = negate(2 ^ (N - 1)); + saturated = true + } else { + result = i; + saturated = false + }; + let 'result = result; + return((result[N - 1 .. 0], saturated)) +} + +val UnsignedSatQ : forall 'N 'i, 0 <= 'N - 1. + (int('i), int('N)) -> (bits('N), bool) + +function UnsignedSatQ (i, N) = { + result : int = undefined; + saturated : bool = undefined; + if i > pow2(N) - 1 then { + result = pow2(N) - 1; + saturated = true + } else if i < 0 then { + result = 0; + saturated = true + } else { + result = i; + saturated = false + }; + let 'result = result; + return((result[N - 1 .. 0], saturated)) +} + +val SatQ : forall 'N 'i ('is_unsigned : Bool), + 'N >= 0. + (int('i), int('N), bool('is_unsigned)) -> (bits('N), bool) + +function SatQ (i, N, is_unsigned) = { + result : bits('N) = undefined; + sat : bool = undefined; + (result, sat) = if is_unsigned then { + assert(constraint(0 <= 'N - 1)); + UnsignedSatQ(i, N) + } else { + assert(constraint(0 <= 'N - 1)); + SignedSatQ(i, N) + }; + return((result, sat)) +} + +val AdvSIMDExpandImm : (bits(1), bits(4), bits(8)) -> bits(64) + +function AdvSIMDExpandImm (op, cmode, imm8) = { + imm32 : bits(32) = undefined; + imm8a : bits(8) = undefined; + imm8b : bits(8) = undefined; + imm8c : bits(8) = undefined; + imm8d : bits(8) = undefined; + imm8e : bits(8) = undefined; + imm8f : bits(8) = undefined; + imm8g : bits(8) = undefined; + imm8h : bits(8) = undefined; + imm64 : bits(64) = undefined; + match cmode[3 .. 1] { + 0b000 => { + imm64 = Replicate(Zeros(24) @ imm8, 2) + }, + 0b001 => { + imm64 = Replicate((Zeros(16) @ imm8) @ Zeros(8), 2) + }, + 0b010 => { + imm64 = Replicate((Zeros(8) @ imm8) @ Zeros(16), 2) + }, + 0b011 => { + imm64 = Replicate(imm8 @ Zeros(24), 2) + }, + 0b100 => { + imm64 = Replicate(Zeros(8) @ imm8, 4) + }, + 0b101 => { + imm64 = Replicate(imm8 @ Zeros(8), 4) + }, + 0b110 => { + if [cmode[0]] == 0b0 then { + imm64 = Replicate((Zeros(16) @ imm8) @ Ones(8), 2) + } else { + imm64 = Replicate((Zeros(8) @ imm8) @ Ones(16), 2) + } + }, + 0b111 => { + if [cmode[0]] == 0b0 & op == 0b0 then { + imm64 = Replicate(imm8, 8) + }; + if [cmode[0]] == 0b0 & op == 0b1 then { + let imm8a : bits(8) = Replicate([imm8[7]], 8); + let imm8b : bits(8) = Replicate([imm8[6]], 8); + let imm8c : bits(8) = Replicate([imm8[5]], 8); + let imm8d : bits(8) = Replicate([imm8[4]], 8); + let imm8e : bits(8) = Replicate([imm8[3]], 8); + let imm8f : bits(8) = Replicate([imm8[2]], 8); + let imm8g : bits(8) = Replicate([imm8[1]], 8); + let imm8h : bits(8) = Replicate([imm8[0]], 8); + imm64 = ((((((imm8a @ imm8b) @ imm8c) @ imm8d) @ imm8e) @ imm8f) @ imm8g) @ imm8h + }; + if [cmode[0]] == 0b1 & op == 0b0 then { + let imm32 : bits(32) = ((([imm8[7]] @ not_vec([imm8[6]])) @ Replicate([imm8[6]], 5)) @ imm8[5 .. 0]) @ Zeros(19); + imm64 = Replicate(imm32, 2) + }; + if [cmode[0]] == 0b1 & op == 0b1 then { + if UsingAArch32() then { + ReservedEncoding() + }; + imm64 = ((([imm8[7]] @ not_vec([imm8[6]])) @ Replicate([imm8[6]], 8)) @ imm8[5 .. 0]) @ Zeros(48) + }; + () + } + }; + return(imm64) +} + +val PolynomialMult : forall 'M 'N, ('M >= 0 & 'N >= 0). + (bits('M), bits('N)) -> bits('M + 'N) + +function PolynomialMult (op1, op2) = { + result : bits('M + 'N) = Zeros('M + 'N); + let extended_op2 : bits('M + 'N) = ZeroExtend(op2, 'M + 'N); + foreach (i from 0 to ('M - 1) by 1 in inc) { + if [op1[i]] == 0b1 then { + result = EOR(result, LSL(extended_op2, i)) + }; + () + }; + return(result) +} + +val MatMulAdd : forall 'N ('op1_unsigned : Bool) ('op2_unsigned : Bool), + 'N == 128. + (bits('N), bits('N), bits('N), bool('op1_unsigned), bool('op2_unsigned)) -> bits('N) + +function MatMulAdd (addend, op1, op2, op1_unsigned, op2_unsigned) = { + assert('N == 128); + result : bits('N) = undefined; + sum : bits(32) = undefined; + prod : int = undefined; + foreach (i from 0 to 1 by 1 in inc) { + foreach (j from 0 to 1 by 1 in inc) { + sum = Elem_read(addend, 2 * i + j, 32); + foreach (k from 0 to 7 by 1 in inc) { + prod = asl_Int(Elem_read(op1, 8 * i + k, 8), op1_unsigned) * asl_Int(Elem_read(op2, 8 * j + k, 8), op2_unsigned); + sum = sum + prod + }; + result = Elem_set(result, 2 * i + j, 32, sum) + } + }; + return(result) +} + +val AddWithCarry : forall 'N, 'N > 0. + (bits('N), bits('N), bits(1)) -> (bits('N), bits(4)) + +function AddWithCarry (x, y, carry_in) = { + let 'unsigned_sum = UInt(x) + UInt(y) + UInt(carry_in); + let 'signed_sum = SInt(x) + SInt(y) + UInt(carry_in); + let result : bits('N) = unsigned_sum['N - 1 .. 0]; + let n : bits(1) = [result['N - 1]]; + let z : bits(1) = if IsZero(result) then 0b1 else 0b0; + let c : bits(1) = if UInt(result) == unsigned_sum then 0b0 else 0b1; + let v : bits(1) = if SInt(result) == signed_sum then 0b0 else 0b1; + return((result, ((n @ z) @ c) @ v)) +} + +val HaveRASExt : unit -> bool + +function HaveRASExt () = { + return(IsFeatureImplemented(FEAT_RAS)) +} + +val IsExternalAbortTakenSynchronously : forall ('iswrite : Bool) 'size. + (PhysMemRetStatus, bool('iswrite), AddressDescriptor, int('size), AccessDescriptor) -> bool + +val IsExternalSyncAbort : Fault -> bool + +val IsExternalSyncAbort__1 : FaultRecord -> bool + +function IsExternalSyncAbort statuscode = { + assert(statuscode != Fault_None); + return(statuscode == Fault_SyncExternal | statuscode == Fault_SyncParity | statuscode == Fault_SyncExternalOnWalk | statuscode == Fault_SyncParityOnWalk) +} + +function IsExternalSyncAbort__1 fault = { + return(IsExternalSyncAbort(fault.statuscode) | fault.gpcf.gpf == GPCF_EABT) +} + +val PendSErrorInterrupt : FaultRecord -> unit + +val HandleExternalTTWAbort : forall ('iswrite : Bool) 'size. + (PhysMemRetStatus, bool('iswrite), AddressDescriptor, AccessDescriptor, int('size), FaultRecord) -> FaultRecord + +function HandleExternalTTWAbort (memretstatus, iswrite, memaddrdesc, accdesc, size, input_fault) = { + output_fault : FaultRecord = input_fault; + output_fault.extflag = memretstatus.extflag; + output_fault.statuscode = memretstatus.statuscode; + if IsExternalSyncAbort__1(output_fault) & not_bool(IsExternalAbortTakenSynchronously(memretstatus, iswrite, memaddrdesc, size, accdesc)) then { + if output_fault.statuscode == Fault_SyncParity then { + output_fault.statuscode = Fault_AsyncParity + } else { + output_fault.statuscode = Fault_AsyncExternal + } + }; + if IsExternalSyncAbort__1(output_fault) then { + if output_fault.statuscode == Fault_SyncParity then { + output_fault.statuscode = Fault_SyncParityOnWalk + } else { + output_fault.statuscode = Fault_SyncExternalOnWalk + } + }; + if HaveRASExt() then { + output_fault.merrorstate = memretstatus.merrorstate + }; + if not_bool(IsExternalSyncAbort__1(output_fault)) then { + PendSErrorInterrupt(output_fault); + output_fault.statuscode = Fault_None + }; + return(output_fault) +} + +val AArch32_EncodeAsyncErrorSyndrome : ErrorState -> bits(2) + +function AArch32_EncodeAsyncErrorSyndrome errorstate = { + match errorstate { + ErrorState_UC => { + return(0b00) + }, + ErrorState_UEU => { + return(0b01) + }, + ErrorState_UEO => { + return(0b10) + }, + ErrorState_UER => { + return(0b11) + }, + _ => { + Unreachable(); + return(undefined : bits(2)) + } + } +} + +val ActionRequired : unit -> bool + +val ErrorIsContained : unit -> bool + +val ErrorIsSynchronized : unit -> bool + +val ReportErrorAsUC : unit -> bool + +val ReportErrorAsUER : unit -> bool + +val ReportErrorAsUEU : unit -> bool + +val StateIsRecoverable : unit -> bool + +val AArch32_PEErrorState : FaultRecord -> ErrorState + +function AArch32_PEErrorState fault = { + if (not_bool(ErrorIsContained()) | not_bool(ErrorIsSynchronized()) & not_bool(StateIsRecoverable())) | ReportErrorAsUC() then { + return(ErrorState_UC) + }; + if not_bool(StateIsRecoverable()) | ReportErrorAsUEU() then { + return(ErrorState_UEU) + }; + if ActionRequired() | ReportErrorAsUER() then { + return(ErrorState_UER) + }; + return(ErrorState_UEO) +} + +val Have52BitIPAAndPASpaceExt : unit -> bool + +function Have52BitIPAAndPASpaceExt () = { + return(IsFeatureImplemented(FEAT_LPA2)) +} + +val Have56BitPAExt : unit -> bool + +function Have56BitPAExt () = { + return(IsFeatureImplemented(FEAT_D128)) +} + +val HaveMTE2Ext : unit -> bool + +function HaveMTE2Ext () = { + return(IsFeatureImplemented(FEAT_MTE2)) +} + +val EncodeLDFSC : forall 'level. (Fault, int('level)) -> bits(6) + +function EncodeLDFSC (statuscode, level) = { + result : bits(6) = undefined; + if level == negate(2) then { + assert(Have56BitPAExt()); + match statuscode { + Fault_AddressSize => { + result = 0b101100 + }, + Fault_Translation => { + result = 0b101010 + }, + Fault_SyncExternalOnWalk => { + result = 0b010010 + }, + Fault_SyncParityOnWalk => { + result = 0b011010; + assert(not_bool(HaveRASExt())) + }, + Fault_GPCFOnWalk => { + result = 0b100010 + }, + _ => { + Unreachable() + } + }; + return(result) + }; + if level == negate(1) then { + assert(Have52BitIPAAndPASpaceExt()); + match statuscode { + Fault_AddressSize => { + result = 0b101001 + }, + Fault_Translation => { + result = 0b101011 + }, + Fault_SyncExternalOnWalk => { + result = 0b010011 + }, + Fault_SyncParityOnWalk => { + result = 0b011011; + assert(not_bool(HaveRASExt())) + }, + Fault_GPCFOnWalk => { + result = 0b100011 + }, + _ => { + Unreachable() + } + }; + return(result) + }; + match statuscode { + Fault_AddressSize => { + result = 0b0000 @ level[1 .. 0]; + assert(level == 0 | level == 1 | level == 2 | level == 3) + }, + Fault_AccessFlag => { + result = 0b0010 @ level[1 .. 0]; + assert(level == 0 | level == 1 | level == 2 | level == 3) + }, + Fault_Permission => { + result = 0b0011 @ level[1 .. 0]; + assert(level == 0 | level == 1 | level == 2 | level == 3) + }, + Fault_Translation => { + result = 0b0001 @ level[1 .. 0]; + assert(level == 0 | level == 1 | level == 2 | level == 3) + }, + Fault_SyncExternal => { + result = 0b010000 + }, + Fault_SyncExternalOnWalk => { + result = 0b0101 @ level[1 .. 0]; + assert(level == 0 | level == 1 | level == 2 | level == 3) + }, + Fault_SyncParity => { + result = 0b011000 + }, + Fault_SyncParityOnWalk => { + result = 0b0111 @ level[1 .. 0]; + assert(level == 0 | level == 1 | level == 2 | level == 3) + }, + Fault_AsyncParity => { + result = 0b011001 + }, + Fault_AsyncExternal => { + result = 0b010001; + assert(UsingAArch32()) + }, + Fault_TagCheck => { + result = 0b010001; + assert(HaveMTE2Ext()) + }, + Fault_Alignment => { + result = 0b100001 + }, + Fault_Debug => { + result = 0b100010 + }, + Fault_GPCFOnWalk => { + result = 0b1001 @ level[1 .. 0]; + assert(level == 0 | level == 1 | level == 2 | level == 3) + }, + Fault_GPCFOnOutput => { + result = 0b101000 + }, + Fault_TLBConflict => { + result = 0b110000 + }, + Fault_HWUpdateAccessFlag => { + result = 0b110001 + }, + Fault_Lockdown => { + result = 0b110100 + }, + Fault_Exclusive => { + result = 0b110101 + }, + _ => { + Unreachable() + } + }; + return(result) +} + +val IsAsyncAbort : Fault -> bool + +val IsAsyncAbort__1 : FaultRecord -> bool + +function IsAsyncAbort statuscode = { + assert(statuscode != Fault_None); + return(statuscode == Fault_AsyncExternal | statuscode == Fault_AsyncParity) +} + +function IsAsyncAbort__1 fault = { + return(IsAsyncAbort(fault.statuscode)) +} + +val IsExternalAbort : Fault -> bool + +val IsExternalAbort__1 : FaultRecord -> bool + +function IsExternalAbort statuscode = { + assert(statuscode != Fault_None); + return(statuscode == Fault_SyncExternal | statuscode == Fault_SyncParity | statuscode == Fault_SyncExternalOnWalk | statuscode == Fault_SyncParityOnWalk | statuscode == Fault_AsyncExternal | statuscode == Fault_AsyncParity) +} + +function IsExternalAbort__1 fault = { + return(IsExternalAbort(fault.statuscode) | fault.gpcf.gpf == GPCF_EABT) +} + +val IsSecondStage : FaultRecord -> bool + +function IsSecondStage fault = { + assert(fault.statuscode != Fault_None); + return(fault.secondstage) +} + +val LSInstructionSyndrome : unit -> bits(11) + +val AArch32_FaultSyndrome : forall ('d_side : Bool). + (bool('d_side), FaultRecord) -> bits(25) + +function AArch32_FaultSyndrome (d_side, fault) = { + assert(fault.statuscode != Fault_None); + iss : bits(25) = Zeros(25); + let iss2 : bits(24) = Zeros(24); + if HaveRASExt() & IsAsyncAbort__1(fault) then { + let errstate : ErrorState = AArch32_PEErrorState(fault); + iss[11 .. 10] = AArch32_EncodeAsyncErrorSyndrome(errstate) + }; + if d_side then { + if (IsSecondStage(fault) & not_bool(fault.s2fs1walk)) & (not_bool(IsExternalSyncAbort__1(fault)) | (not_bool(HaveRASExt()) & fault.access.acctype == AccessType_TTW) & __IMPDEF_boolean("ISV on second stage translation table walk")) then { + iss[24 .. 14] = LSInstructionSyndrome() + }; + if fault.access.acctype == AccessType_DC | fault.access.acctype == AccessType_IC | fault.access.acctype == AccessType_AT then { + iss[8] = Bit(0b1) + }; + if fault.access.acctype == AccessType_DC | fault.access.acctype == AccessType_IC | fault.access.acctype == AccessType_AT then { + iss[6] = Bit(0b1) + } else if fault.statuscode == Fault_HWUpdateAccessFlag | fault.statuscode == Fault_Exclusive then { + iss[6] = Bit(__UNKNOWN_bit()) + } else if fault.access.atomicop & IsExternalAbort__1(fault) then { + iss[6] = Bit(__UNKNOWN_bit()) + } else { + iss[6] = Bit(if fault.write then 0b1 else 0b0) + } + }; + if IsExternalAbort__1(fault) then { + iss[9] = Bit(fault.extflag) + }; + iss[7] = Bit(if fault.s2fs1walk then 0b1 else 0b0); + iss[5 .. 0] = EncodeLDFSC(fault.statuscode, fault.level); + return(iss) +} + +val IPAValid : FaultRecord -> bool + +function IPAValid fault = { + assert(fault.statuscode != Fault_None); + if fault.gpcf.gpf != GPCF_None then { + return(fault.secondstage) + } else if fault.s2fs1walk then { + return(fault.statuscode == Fault_AccessFlag | fault.statuscode == Fault_Permission | fault.statuscode == Fault_Translation | fault.statuscode == Fault_AddressSize) + } else if fault.secondstage then { + return(fault.statuscode == Fault_AccessFlag | fault.statuscode == Fault_Translation | fault.statuscode == Fault_AddressSize) + } else { + return(false) + } +} + +val AArch32_AbortSyndrome : (Exception, FaultRecord, bits(32), bits(2)) -> ExceptionRecord + +function AArch32_AbortSyndrome (exceptype, fault, vaddress, target_el) = { + except : ExceptionRecord = ExceptionSyndrome(exceptype); + let d_side : bool = exceptype == Exception_DataAbort; + except.syndrome = AArch32_FaultSyndrome(d_side, fault); + except.vaddress = ZeroExtend(vaddress, 64); + if IPAValid(fault) then { + except.ipavalid = true; + except.NS = if fault.ipaddress.paspace == PAS_NonSecure then 0b1 else + 0b0; + except.ipaddress = ZeroExtend(fault.ipaddress.address, 56) + } else { + except.ipavalid = false + }; + return(except) +} + +val AArch32_ExceptionClass : Exception -> (int, bits(1)) + +function AArch32_ExceptionClass exceptype = { + il_is_valid : bool = true; + ec : int = undefined; + match exceptype { + Exception_Uncategorized => { + ec = UInt(0x00); + il_is_valid = false + }, + Exception_WFxTrap => { + ec = UInt(0x01) + }, + Exception_CP15RTTrap => { + ec = UInt(0x03) + }, + Exception_CP15RRTTrap => { + ec = UInt(0x04) + }, + Exception_CP14RTTrap => { + ec = UInt(0x05) + }, + Exception_CP14DTTrap => { + ec = UInt(0x06) + }, + Exception_AdvSIMDFPAccessTrap => { + ec = UInt(0x07) + }, + Exception_FPIDTrap => { + ec = UInt(0x08) + }, + Exception_PACTrap => { + ec = UInt(0x09) + }, + Exception_TSTARTAccessTrap => { + ec = UInt(0x1B) + }, + Exception_GPC => { + ec = UInt(0x1E) + }, + Exception_CP14RRTTrap => { + ec = UInt(0x0C) + }, + Exception_BranchTarget => { + ec = UInt(0x0D) + }, + Exception_IllegalState => { + ec = UInt(0x0E); + il_is_valid = false + }, + Exception_SupervisorCall => { + ec = UInt(0x11) + }, + Exception_HypervisorCall => { + ec = UInt(0x12) + }, + Exception_MonitorCall => { + ec = UInt(0x13) + }, + Exception_InstructionAbort => { + ec = UInt(0x20); + il_is_valid = false + }, + Exception_PCAlignment => { + ec = UInt(0x22); + il_is_valid = false + }, + Exception_DataAbort => { + ec = UInt(0x24) + }, + Exception_NV2DataAbort => { + ec = UInt(0x25) + }, + Exception_FPTrappedException => { + ec = UInt(0x28) + }, + _ => { + Unreachable() + } + }; + if (ec == UInt(0x20) | ec == UInt(0x24)) & PSTATE.EL == EL2 then { + ec = ec + 1 + }; + let 'ec = ec; + il : bits(1) = undefined; + if il_is_valid then { + il = if ThisInstrLength() == 32 then 0b1 else 0b0 + } else { + il = 0b1 + }; + return((ec, il)) +} + +type HDFAR_Type = bits(32) + +register _HDFAR : HDFAR_Type + +val HDFAR_write : HDFAR_Type -> unit + +function HDFAR_write value_name = { + let r : HDFAR_Type = value_name; + FAR_EL2[31 .. 0] = Slice(r, 0, 32); + _HDFAR = r; + return() +} + +type HIFAR_Type = bits(32) + +register _HIFAR : HIFAR_Type + +val HIFAR_write : HIFAR_Type -> unit + +function HIFAR_write value_name = { + let r : HIFAR_Type = value_name; + FAR_EL2[63 .. 32] = Slice(r, 0, 32); + _HIFAR = r; + return() +} + +bitfield HPFAR_Type : bits(32) = {FIPA : 31..4} + +register _HPFAR : HPFAR_Type + +val HPFAR_read : unit -> HPFAR_Type + +function HPFAR_read () = { + r : HPFAR_Type = _HPFAR; + r.bits[31 .. 0] = Slice(HPFAR_EL2.bits, 0, 32); + return(r) +} + +val HPFAR_write : HPFAR_Type -> unit + +function HPFAR_write value_name = { + let r : HPFAR_Type = value_name; + HPFAR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HPFAR = r; + return() +} + +bitfield HSR_Type : bits(32) = {EC : 31..26, IL : 25..25, ISS : 24..0} + +register _HSR : HSR_Type + +val HSR_write : HSR_Type -> unit + +function HSR_write value_name = { + let r : HSR_Type = value_name; + ESR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HSR = r; + return() +} + +val AArch32_ReportHypEntry : ExceptionRecord -> unit + +function AArch32_ReportHypEntry except = { + ec : int = undefined; + il : bits(1) = undefined; + let exceptype : Exception = except.exceptype; + (ec, il) = AArch32_ExceptionClass(exceptype); + let 'ec = ec; + let iss : bits(25) = except.syndrome; + let iss2 : bits(24) = except.syndrome2; + if (ec == UInt(0x24) | ec == UInt(0x25)) & [iss[24]] == 0b0 then { + il = 0b1 + }; + let il = il; + HSR_write() = Mk_HSR_Type((ec[5 .. 0] @ il) @ iss); + if exceptype == Exception_InstructionAbort | exceptype == Exception_PCAlignment then { + HIFAR_write() = except.vaddress[31 .. 0]; + HDFAR_write() = __UNKNOWN_bits(32) + } else if exceptype == Exception_DataAbort then { + HIFAR_write() = __UNKNOWN_bits(32); + HDFAR_write() = except.vaddress[31 .. 0] + } else (); + if except.ipavalid then { + HPFAR_write() = Mk_HPFAR_Type([HPFAR_read().bits with 31 .. 4 = except.ipaddress[39 .. 12]]) + } else { + HPFAR_write() = Mk_HPFAR_Type([HPFAR_read().bits with 31 .. 4 = __UNKNOWN_bits(28)]) + }; + return() +} + +type ELR_hyp_Type = bits(32) + +register _ELR_hyp : ELR_hyp_Type + +val ELR_hyp_write : ELR_hyp_Type -> unit + +function ELR_hyp_write value_name = { + let r : ELR_hyp_Type = value_name; + ELR_EL2[31 .. 0] = Slice(r, 0, 32); + _ELR_hyp = r; + return() +} + +val AArch32_EnterHypModeInDebugState : ExceptionRecord -> unit + +function AArch32_EnterHypModeInDebugState except = { + SynchronizeContext(); + assert((HaveEL(EL2) & CurrentSecurityState() == SS_NonSecure) & ELUsingAArch32(EL2)); + AArch32_ReportHypEntry(except); + AArch32_WriteMode(M32_Hyp); + SPSR_set(32) = __UNKNOWN_bits(32); + ELR_hyp_write() = __UNKNOWN_bits(32); + PSTATE.T = 0b1; + (PSTATE.SS @ PSTATE.A @ PSTATE.I @ PSTATE.F) = __UNKNOWN_bits(4); + DLR_write() = __UNKNOWN_bits(32); + DSPSR_write() = Mk_DSPSR_Type(__UNKNOWN_bits(32)); + PSTATE.E = HSCTLR_read()[EE]; + PSTATE.IL = 0b0; + PSTATE.IT = 0b00000000; + if HaveSSBSExt() then { + PSTATE.SSBS = __UNKNOWN_bit() + }; + EDSCR_write() = [EDSCR_read() with ERR = 0b1]; + UpdateEDSCRFields(); + EndOfInstruction() +} + +type HVBAR_Type = bits(32) + +register _HVBAR : HVBAR_Type + +val HVBAR_read : unit -> HVBAR_Type + +function HVBAR_read () = { + r : HVBAR_Type = _HVBAR; + r[31 .. 0] = Slice(VBAR_EL2, 0, 32); + return(r) +} + +val AArch32_EnterHypMode : forall 'vect_offset. + (ExceptionRecord, bits(32), int('vect_offset)) -> unit + +function AArch32_EnterHypMode (except, preferred_exception_return, vect_offset) = { + SynchronizeContext(); + assert((HaveEL(EL2) & CurrentSecurityState() == SS_NonSecure) & ELUsingAArch32(EL2)); + if Halted() then { + AArch32_EnterHypModeInDebugState(except); + return() + }; + let spsr : bits(32) = GetPSRFromPSTATE(AArch32_NonDebugState, 32); + if not_bool(except.exceptype == Exception_IRQ | except.exceptype == Exception_FIQ) then { + AArch32_ReportHypEntry(except) + }; + AArch32_WriteMode(M32_Hyp); + SPSR_set(32) = spsr; + ELR_hyp_write() = preferred_exception_return; + PSTATE.T = HSCTLR_read()[TE]; + PSTATE.SS = 0b0; + if not_bool(HaveEL(EL3)) | SCR_GEN_read()[EA] == 0b0 then { + PSTATE.A = 0b1 + }; + if not_bool(HaveEL(EL3)) | SCR_GEN_read()[IRQ] == 0b0 then { + PSTATE.I = 0b1 + }; + if not_bool(HaveEL(EL3)) | SCR_GEN_read()[FIQ] == 0b0 then { + PSTATE.F = 0b1 + }; + PSTATE.E = HSCTLR_read()[EE]; + PSTATE.IL = 0b0; + PSTATE.IT = 0b00000000; + if HaveSSBSExt() then { + PSTATE.SSBS = HSCTLR_read()[DSSBS] + }; + let branch_conditional : bool = false; + BranchTo(HVBAR_read()[31 .. 5] @ vect_offset[4 .. 0], BranchType_EXCEPTION, branch_conditional); + CheckExceptionCatch(true); + EndOfInstruction() +} + +val Rmode_set : forall 'n. (int('n), bits(5), bits(32)) -> unit + +function Rmode_set (n, mode, value_name) = { + assert(n >= 0 & n <= 14); + if CurrentSecurityState() != SS_Secure then { + assert(mode != M32_Monitor) + }; + assert(not_bool(BadMode(mode))); + if mode == M32_Monitor then { + if n == 13 then { + SP_mon = value_name + } else if n == 14 then { + LR_mon = value_name + } else { + _R(n, 31, 0) = value_name + } + } else { + if HaveAArch64() & ConstrainUnpredictableBool(Unpredictable_ZEROUPPER) then { + _R(LookUpRIndex(n, mode)) = ZeroExtend(value_name, 64) + } else { + _R(LookUpRIndex(n, mode), 31, 0) = value_name + } + }; + return() +} + +val R_set : forall 'n. (int('n), bits(32)) -> unit + +function R_set (n, value_name) = { + Rmode_set(n, PSTATE.M) = value_name; + return() +} + +val AArch32_EnterModeInDebugState : bits(5) -> unit + +function AArch32_EnterModeInDebugState target_mode = { + SynchronizeContext(); + assert(ELUsingAArch32(EL1) & PSTATE.EL != EL2); + if PSTATE.M == M32_Monitor then { + SCR[NS] = 0b0 + }; + AArch32_WriteMode(target_mode); + SPSR_set(32) = __UNKNOWN_bits(32); + R_set(14) = __UNKNOWN_bits(32); + PSTATE.T = 0b1; + (PSTATE.SS @ PSTATE.A @ PSTATE.I @ PSTATE.F) = __UNKNOWN_bits(4); + DLR_write() = __UNKNOWN_bits(32); + DSPSR_write() = Mk_DSPSR_Type(__UNKNOWN_bits(32)); + PSTATE.E = SCTLR_read__2()[EE]; + PSTATE.IL = 0b0; + PSTATE.IT = 0b00000000; + if HavePANExt() & SCTLR_read__2()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + }; + if HaveSSBSExt() then { + PSTATE.SSBS = __UNKNOWN_bit() + }; + EDSCR_write() = [EDSCR_read() with ERR = 0b1]; + UpdateEDSCRFields(); + EndOfInstruction() +} + +val ExcVectorBase : unit -> bits(32) + +function ExcVectorBase () = { + if SCTLR_read__2()[V] == 0b1 then { + return(Ones(16) @ Zeros(16)) + } else { + return(VBAR_read__2()[31 .. 5] @ Zeros(5)) + } +} + +val AArch32_EnterMode : forall 'lr_offset 'vect_offset. + (bits(5), bits(32), int('lr_offset), int('vect_offset)) -> unit + +function AArch32_EnterMode (target_mode, preferred_exception_return, lr_offset, vect_offset) = { + SynchronizeContext(); + assert(ELUsingAArch32(EL1) & PSTATE.EL != EL2); + if Halted() then { + AArch32_EnterModeInDebugState(target_mode); + return() + }; + let spsr : bits(32) = GetPSRFromPSTATE(AArch32_NonDebugState, 32); + if PSTATE.M == M32_Monitor then { + SCR[NS] = 0b0 + }; + AArch32_WriteMode(target_mode); + SPSR_set(32) = spsr; + R_set(14) = preferred_exception_return + lr_offset; + PSTATE.T = SCTLR_read__2()[TE]; + PSTATE.SS = 0b0; + if target_mode == M32_FIQ then { + (PSTATE.A @ PSTATE.I @ PSTATE.F) = 0b111 + } else if target_mode == M32_Abort | target_mode == M32_IRQ then { + (PSTATE.A @ PSTATE.I) = 0b11 + } else { + PSTATE.I = 0b1 + }; + PSTATE.E = SCTLR_read__2()[EE]; + PSTATE.IL = 0b0; + PSTATE.IT = 0b00000000; + if HavePANExt() & SCTLR_read__2()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + }; + if HaveSSBSExt() then { + PSTATE.SSBS = SCTLR_read__2()[DSSBS] + }; + let branch_conditional : bool = false; + BranchTo(ExcVectorBase()[31 .. 5] @ vect_offset[4 .. 0], BranchType_EXCEPTION, branch_conditional); + CheckExceptionCatch(true); + EndOfInstruction() +} + +val AArch32_EnterMonitorModeInDebugState : unit -> unit + +function AArch32_EnterMonitorModeInDebugState () = { + SynchronizeContext(); + assert(HaveEL(EL3) & ELUsingAArch32(EL3)); + let from_secure : bool = CurrentSecurityState() == SS_Secure; + if PSTATE.M == M32_Monitor then { + SCR[NS] = 0b0 + }; + AArch32_WriteMode(M32_Monitor); + SPSR_set(32) = __UNKNOWN_bits(32); + R_set(14) = __UNKNOWN_bits(32); + PSTATE.T = 0b1; + (PSTATE.SS @ PSTATE.A @ PSTATE.I @ PSTATE.F) = __UNKNOWN_bits(4); + PSTATE.E = SCTLR_read__2()[EE]; + PSTATE.IL = 0b0; + PSTATE.IT = 0b00000000; + if HavePANExt() then { + if not_bool(from_secure) then { + PSTATE.PAN = 0b0 + } else if SCTLR_read__2()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + } else () + }; + if HaveSSBSExt() then { + PSTATE.SSBS = __UNKNOWN_bit() + }; + DLR_write() = __UNKNOWN_bits(32); + DSPSR_write() = Mk_DSPSR_Type(__UNKNOWN_bits(32)); + EDSCR_write() = [EDSCR_read() with ERR = 0b1]; + UpdateEDSCRFields(); + EndOfInstruction() +} + +bitfield MVBAR_Type : bits(32) = {Reserved : 4..0} + +register MVBAR : MVBAR_Type + +val AArch32_EnterMonitorMode : forall 'lr_offset 'vect_offset. + (bits(32), int('lr_offset), int('vect_offset)) -> unit + +function AArch32_EnterMonitorMode (preferred_exception_return, lr_offset, vect_offset) = { + SynchronizeContext(); + assert(HaveEL(EL3) & ELUsingAArch32(EL3)); + let from_secure : bool = CurrentSecurityState() == SS_Secure; + if Halted() then { + AArch32_EnterMonitorModeInDebugState(); + return() + }; + let spsr : bits(32) = GetPSRFromPSTATE(AArch32_NonDebugState, 32); + if PSTATE.M == M32_Monitor then { + SCR[NS] = 0b0 + }; + AArch32_WriteMode(M32_Monitor); + SPSR_set(32) = spsr; + R_set(14) = preferred_exception_return + lr_offset; + PSTATE.T = SCTLR_read__2()[TE]; + PSTATE.SS = 0b0; + (PSTATE.A @ PSTATE.I @ PSTATE.F) = 0b111; + PSTATE.E = SCTLR_read__2()[EE]; + PSTATE.IL = 0b0; + PSTATE.IT = 0b00000000; + if HavePANExt() then { + if not_bool(from_secure) then { + PSTATE.PAN = 0b0 + } else if SCTLR_read__2()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + } else () + }; + if HaveSSBSExt() then { + PSTATE.SSBS = SCTLR_read__2()[DSSBS] + }; + let branch_conditional : bool = false; + BranchTo(MVBAR.bits[31 .. 5] @ vect_offset[4 .. 0], BranchType_EXCEPTION, branch_conditional); + CheckExceptionCatch(true); + EndOfInstruction() +} + +val EncodeSDFSC : forall 'level. (Fault, int('level)) -> bits(5) + +function EncodeSDFSC (statuscode, level) = { + result : bits(5) = undefined; + match statuscode { + Fault_AccessFlag => { + assert(level == 1 | level == 2); + result = if level == 1 then 0b00011 else 0b00110 + }, + Fault_Alignment => { + result = 0b00001 + }, + Fault_Permission => { + assert(level == 1 | level == 2); + result = if level == 1 then 0b01101 else 0b01111 + }, + Fault_Domain => { + assert(level == 1 | level == 2); + result = if level == 1 then 0b01001 else 0b01011 + }, + Fault_Translation => { + assert(level == 1 | level == 2); + result = if level == 1 then 0b00101 else 0b00111 + }, + Fault_SyncExternal => { + result = 0b01000 + }, + Fault_SyncExternalOnWalk => { + assert(level == 1 | level == 2); + result = if level == 1 then 0b01100 else 0b01110 + }, + Fault_SyncParity => { + result = 0b11001 + }, + Fault_SyncParityOnWalk => { + assert(level == 1 | level == 2); + result = if level == 1 then 0b11100 else 0b11110 + }, + Fault_AsyncParity => { + result = 0b11000 + }, + Fault_AsyncExternal => { + result = 0b10110 + }, + Fault_Debug => { + result = 0b00010 + }, + Fault_TLBConflict => { + result = 0b10000 + }, + Fault_Lockdown => { + result = 0b10100 + }, + Fault_Exclusive => { + result = 0b10101 + }, + Fault_ICacheMaint => { + result = 0b00100 + }, + _ => { + Unreachable() + } + }; + return(result) +} + +val AArch32_CommonFaultStatus : forall ('long_format : Bool). + (FaultRecord, bool('long_format)) -> bits(32) + +function AArch32_CommonFaultStatus (fault, long_format) = { + target : bits(32) = Zeros(32); + if HaveRASExt() & IsAsyncAbort__1(fault) then { + let errstate : ErrorState = AArch32_PEErrorState(fault); + target[15 .. 14] = AArch32_EncodeAsyncErrorSyndrome(errstate) + }; + if IsExternalAbort__1(fault) then { + target[12] = Bit(fault.extflag) + }; + target[9] = Bit(if long_format then 0b1 else 0b0); + if long_format then { + target[5 .. 0] = EncodeLDFSC(fault.statuscode, fault.level) + } else { + (target[10 .. 10] @ target[3 .. 0]) = EncodeSDFSC(fault.statuscode, fault.level) + }; + return(target) +} + +type DFAR_Type = bits(32) + +register _DFAR_NS : DFAR_Type + +val DFAR_NS_write : DFAR_Type -> unit + +function DFAR_NS_write value_name = { + let r : DFAR_Type = value_name; + FAR_EL1[31 .. 0] = Slice(r, 0, 32); + _DFAR_NS = r; + return() +} + +val HDFAR_read : unit -> HDFAR_Type + +function HDFAR_read () = { + r : HDFAR_Type = _HDFAR; + r[31 .. 0] = Slice(FAR_EL2, 0, 32); + return(r) +} + +register _DFAR_S : DFAR_Type + +val DFAR_S_write : DFAR_Type -> unit + +function DFAR_S_write value_name = { + let r : DFAR_Type = value_name; + HDFAR_write() = SetSlice(32, HDFAR_read(), 0, Slice(r, 0, 32)); + _DFAR_S = r; + return() +} + +val DFAR_write : DFAR_Type -> unit + +function DFAR_write value_name = { + let r : DFAR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + DFAR_S_write() = r + } else { + DFAR_NS_write() = r + }; + return() +} + +bitfield DFSR_Type : bits(32) = + { + FnV : 16..16, + AET : 15..14, + CM : 13..13, + ExT : 12..12, + WnR : 11..11, + FS : (10..10 @ 3..0), + LPAE : 9..9, + Domain : 7..4, + STATUS : 5..0 + } + +register _DFSR_NS : DFSR_Type + +val DFSR_NS_write : DFSR_Type -> unit + +function DFSR_NS_write value_name = { + let r : DFSR_Type = value_name; + ESR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DFSR_NS = r; + return() +} + +register DFSR_S : DFSR_Type + +val DFSR_write : DFSR_Type -> unit + +function DFSR_write value_name = { + let r : DFSR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + DFSR_S = r + } else { + DFSR_NS_write() = r + }; + return() +} + +bitfield IFSR32_EL2_Type : bits(64) = + {FnV : 16..16, ExT : 12..12, FS : (10..10 @ 3..0), LPAE : 9..9, STATUS : 5..0} + +register IFSR32_EL2 : IFSR32_EL2_Type + +bitfield IFSR_Type : bits(32) = + {FnV : 16..16, ExT : 12..12, FS : (10..10 @ 3..0), LPAE : 9..9, STATUS : 5..0} + +register _IFSR_NS : IFSR_Type + +val IFSR_NS_write : IFSR_Type -> unit + +function IFSR_NS_write value_name = { + let r : IFSR_Type = value_name; + IFSR32_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _IFSR_NS = r; + return() +} + +register IFSR_S : IFSR_Type + +val IFSR_write : IFSR_Type -> unit + +function IFSR_write value_name = { + let r : IFSR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + IFSR_S = r + } else { + IFSR_NS_write() = r + }; + return() +} + +val AArch32_ReportDataAbort : forall ('route_to_monitor : Bool). + (bool('route_to_monitor), FaultRecord, bits(32)) -> unit + +function AArch32_ReportDataAbort (route_to_monitor, fault, vaddress) = { + long_format : bool = undefined; + if route_to_monitor & CurrentSecurityState() != SS_Secure then { + long_format = TTBCR_S[EAE] == 0b1 | IsExternalSyncAbort__1(fault) & ((PSTATE.EL == EL2 | TTBCR_read()[EAE] == 0b1) | fault.secondstage & __IMPDEF_boolean("Report abort using Long-descriptor format")) + } else { + long_format = TTBCR_read()[EAE] == 0b1 + }; + syndrome : bits(32) = AArch32_CommonFaultStatus(fault, long_format); + if fault.access.acctype == AccessType_DC | fault.access.acctype == AccessType_IC | fault.access.acctype == AccessType_AT then { + syndrome[13] = Bit(0b1); + syndrome[11] = Bit(0b1) + } else { + syndrome[11] = Bit(if fault.write then 0b1 else 0b0) + }; + if not_bool(long_format) then { + syndrome[7 .. 4] = fault.domain + }; + if fault.access.acctype == AccessType_IC then { + i_syndrome : bits(32) = undefined; + if not_bool(long_format) & __IMPDEF_boolean("Report I-cache maintenance fault in IFSR") then { + i_syndrome = syndrome; + (syndrome[10 .. 10] @ syndrome[3 .. 0]) = EncodeSDFSC(Fault_ICacheMaint, 1) + } else { + i_syndrome = __UNKNOWN_bits(32) + }; + if route_to_monitor then { + IFSR_S = Mk_IFSR_Type(i_syndrome) + } else { + IFSR_write() = Mk_IFSR_Type(i_syndrome) + } + }; + if route_to_monitor then { + DFSR_S = Mk_DFSR_Type(syndrome); + DFAR_S_write() = vaddress + } else { + DFSR_write() = Mk_DFSR_Type(syndrome); + DFAR_write() = vaddress + }; + return() +} + +bitfield DBGDSCRext_Type : bits(32) = + { + TFO : 31..31, + RXfull : 30..30, + TXfull : 29..29, + RXO : 27..27, + TXU : 26..26, + INTdis : 23..22, + TDA : 21..21, + SC2 : 19..19, + NS : 18..18, + SPNIDdis : 17..17, + SPIDdis : 16..16, + MDBGen : 15..15, + HDE : 14..14, + UDCCdis : 12..12, + ERR : 6..6, + MOE : 5..2 + } + +bitfield DBGDSCRint_Type : bits(32) = + { + RXfull : 30..30, + TXfull : 29..29, + NS : 18..18, + SPNIDdis : 17..17, + SPIDdis : 16..16, + MDBGen : 15..15, + UDCCdis : 12..12, + MOE : 5..2 + } + +register _DBGDSCRint : DBGDSCRint_Type + +val DBGDSCRint_read : unit -> DBGDSCRint_Type + +function DBGDSCRint_read () = { + r : DBGDSCRint_Type = _DBGDSCRint; + r.bits[30 .. 29] = Slice(MDCCSR_EL0.bits, 29, 2); + r.bits[15] = Bit(Slice(MDSCR_EL1.bits, 15, 1)); + r.bits[12] = Bit(Slice(MDSCR_EL1.bits, 12, 1)); + r.bits[5 .. 2] = Slice(MDSCR_EL1.bits, 2, 4); + return(r) +} + +register _DBGDSCRext : DBGDSCRext_Type + +val DBGDSCRext_read : unit -> DBGDSCRext_Type + +function DBGDSCRext_read () = { + r : DBGDSCRext_Type = _DBGDSCRext; + r.bits[31 .. 0] = Slice(MDSCR_EL1.bits, 0, 32); + r.bits[15] = Bit(Slice(DBGDSCRint_read().bits, 15, 1)); + r.bits[12] = Bit(Slice(DBGDSCRint_read().bits, 12, 1)); + r.bits[5 .. 2] = Slice(DBGDSCRint_read().bits, 2, 4); + return(r) +} + +val DBGDSCRint_write : DBGDSCRint_Type -> unit + +function DBGDSCRint_write value_name = { + let r : DBGDSCRint_Type = value_name; + MDCCSR_EL0.bits[30 .. 29] = Slice(r.bits, 29, 2); + MDSCR_EL1.bits[15] = Bit(Slice(r.bits, 15, 1)); + MDSCR_EL1.bits[12] = Bit(Slice(r.bits, 12, 1)); + MDSCR_EL1.bits[5 .. 2] = Slice(r.bits, 2, 4); + _DBGDSCRint = r; + return() +} + +val DBGDSCRext_write : DBGDSCRext_Type -> unit + +function DBGDSCRext_write value_name = { + let r : DBGDSCRext_Type = value_name; + MDSCR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + DBGDSCRint_write() = Mk_DBGDSCRint_Type(SetSlice(1, DBGDSCRint_read().bits, 15, Slice(r.bits, 15, 1))); + DBGDSCRint_write() = Mk_DBGDSCRint_Type(SetSlice(1, DBGDSCRint_read().bits, 12, Slice(r.bits, 12, 1))); + DBGDSCRint_write() = Mk_DBGDSCRint_Type(SetSlice(4, DBGDSCRint_read().bits, 2, Slice(r.bits, 2, 4))); + _DBGDSCRext = r; + return() +} + +bitfield HCR2_Type : bits(32) = + { + TTLBIS : 22..22, + TOCU : 20..20, + TICAB : 18..18, + TID4 : 17..17, + MIOCNCE : 6..6, + TEA : 5..5, + TERR : 4..4, + ID : 1..1, + CD : 0..0 + } + +register _HCR2 : HCR2_Type + +val HCR2_read : unit -> HCR2_Type + +function HCR2_read () = { + r : HCR2_Type = _HCR2; + r.bits[31 .. 0] = Slice(HCR_EL2.bits, 32, 32); + return(r) +} + +val IsDebugException : FaultRecord -> bool + +function IsDebugException fault = { + assert(fault.statuscode != Fault_None); + return(fault.statuscode == Fault_Debug) +} + +val AArch32_TakeDataAbortException : (bits(32), FaultRecord) -> unit + +function AArch32_TakeDataAbortException (vaddress, fault) = { + except : ExceptionRecord = undefined; + let route_to_monitor : bool = (HaveEL(EL3) & EffectiveEA() == 0b1) & IsExternalAbort__1(fault); + let route_to_hyp : bool = (EL2Enabled() & (PSTATE.EL == EL0 | PSTATE.EL == EL1)) & (((HCR_read()[TGE] == 0b1 | (HaveRASExt() & HCR2_read()[TEA] == 0b1) & IsExternalAbort__1(fault)) | IsDebugException(fault) & HDCR_read()[TDE] == 0b1) | IsSecondStage(fault)); + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x10); + let 'lr_offset = 8; + if IsDebugException(fault) then { + DBGDSCRext_write() = [DBGDSCRext_read() with MOE = fault.debugmoe] + }; + if route_to_monitor then { + AArch32_ReportDataAbort(route_to_monitor, fault, vaddress); + AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset) + } else if PSTATE.EL == EL2 | route_to_hyp then { + let except : ExceptionRecord = AArch32_AbortSyndrome(Exception_DataAbort, fault, vaddress, EL2); + if PSTATE.EL == EL2 then { + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterHypMode(except, preferred_exception_return, UInt(0x14)) + } + } else { + AArch32_ReportDataAbort(route_to_monitor, fault, vaddress); + AArch32_EnterMode(M32_Abort, preferred_exception_return, lr_offset, vect_offset) + } +} + +type IFAR_Type = bits(32) + +register _IFAR_NS : IFAR_Type + +val IFAR_NS_write : IFAR_Type -> unit + +function IFAR_NS_write value_name = { + let r : IFAR_Type = value_name; + FAR_EL1[63 .. 32] = Slice(r, 0, 32); + _IFAR_NS = r; + return() +} + +val HIFAR_read : unit -> HIFAR_Type + +function HIFAR_read () = { + r : HIFAR_Type = _HIFAR; + r[31 .. 0] = Slice(FAR_EL2, 32, 32); + return(r) +} + +register _IFAR_S : IFAR_Type + +val IFAR_S_write : IFAR_Type -> unit + +function IFAR_S_write value_name = { + let r : IFAR_Type = value_name; + if HaveEL(EL2) then { + FAR_EL2[63 .. 32] = Slice(r, 0, 32) + } else { + HIFAR_write() = SetSlice(32, HIFAR_read(), 0, Slice(r, 0, 32)) + }; + _IFAR_S = r; + return() +} + +val IFAR_write : IFAR_Type -> unit + +function IFAR_write value_name = { + let r : IFAR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + IFAR_S_write() = r + } else { + IFAR_NS_write() = r + }; + return() +} + +val AArch32_ReportPrefetchAbort : forall ('route_to_monitor : Bool). + (bool('route_to_monitor), FaultRecord, bits(32)) -> unit + +function AArch32_ReportPrefetchAbort (route_to_monitor, fault, vaddress) = { + long_format : bool = false; + if route_to_monitor & CurrentSecurityState() != SS_Secure then { + long_format = (TTBCR_S[EAE] == 0b1 | PSTATE.EL == EL2) | TTBCR_read()[EAE] == 0b1 + } else { + long_format = TTBCR_read()[EAE] == 0b1 + }; + let fsr : bits(32) = AArch32_CommonFaultStatus(fault, long_format); + if route_to_monitor then { + IFSR_S = Mk_IFSR_Type(fsr); + IFAR_S_write() = vaddress + } else { + IFSR_write() = Mk_IFSR_Type(fsr); + IFAR_write() = vaddress + }; + return() +} + +val AArch32_TakePrefetchAbortException : (bits(32), FaultRecord) -> unit + +function AArch32_TakePrefetchAbortException (vaddress, fault) = { + let route_to_monitor : bool = (HaveEL(EL3) & EffectiveEA() == 0b1) & IsExternalAbort__1(fault); + let route_to_hyp : bool = (EL2Enabled() & (PSTATE.EL == EL0 | PSTATE.EL == EL1)) & (((HCR_read()[TGE] == 0b1 | (HaveRASExt() & HCR2_read()[TEA] == 0b1) & IsExternalAbort__1(fault)) | IsDebugException(fault) & HDCR_read()[TDE] == 0b1) | IsSecondStage(fault)); + except : ExceptionRecord = undefined; + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x0C); + let 'lr_offset = 4; + if IsDebugException(fault) then { + DBGDSCRext_write() = [DBGDSCRext_read() with MOE = fault.debugmoe] + }; + if route_to_monitor then { + AArch32_ReportPrefetchAbort(route_to_monitor, fault, vaddress); + AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset) + } else if PSTATE.EL == EL2 | route_to_hyp then { + if fault.statuscode == Fault_Alignment then { + except = ExceptionSyndrome(Exception_PCAlignment); + except.vaddress = ThisInstrAddr(64) + } else { + except = AArch32_AbortSyndrome(Exception_InstructionAbort, fault, vaddress, EL2) + }; + if PSTATE.EL == EL2 then { + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterHypMode(except, preferred_exception_return, UInt(0x14)) + } + } else { + AArch32_ReportPrefetchAbort(route_to_monitor, fault, vaddress); + AArch32_EnterMode(M32_Abort, preferred_exception_return, lr_offset, vect_offset) + } +} + +val AArch64_EncodeSyncErrorSyndrome : ErrorState -> bits(2) + +function AArch64_EncodeSyncErrorSyndrome errorstate = { + match errorstate { + ErrorState_UC => { + return(0b10) + }, + ErrorState_UEO => { + return(0b11) + }, + ErrorState_UER => { + return(0b00) + }, + _ => { + Unreachable(); + return(undefined : bits(2)) + } + } +} + +val ExtAbortToA64 : FaultRecord -> bool + +function ExtAbortToA64 fault = { + route_to_aarch64 : bool = PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)); + if (not_bool(route_to_aarch64) & EL2Enabled()) & not_bool(ELUsingAArch32(EL2)) then { + route_to_aarch64 = ((HCR_EL2[TGE] == 0b1 | IsSecondStage(fault)) | (HaveRASExt() & HCR_EL2[TEA] == 0b1) & IsExternalAbort__1(fault)) | IsDebugException(fault) & MDCR_EL2[TDE] == 0b1 + }; + if (not_bool(route_to_aarch64) & HaveEL(EL3)) & not_bool(ELUsingAArch32(EL3)) then { + route_to_aarch64 = SCR_GEN_read()[EA] == 0b1 & IsExternalAbort__1(fault) + }; + return(route_to_aarch64 & IsExternalSyncAbort(fault.statuscode)) +} + +val FaultIsCorrected : unit -> bool + +val ReportErrorAsIMPDEF : unit -> bool + +val ReportErrorAsUncategorized : unit -> bool + +val AArch64_PEErrorState : FaultRecord -> ErrorState + +function AArch64_PEErrorState fault = { + if not_bool(IsExternalSyncAbort__1(fault)) & ExtAbortToA64(fault) then { + if ReportErrorAsUncategorized() then { + return(ErrorState_Uncategorized) + }; + if ReportErrorAsIMPDEF() then { + return(ErrorState_IMPDEF) + }; + () + }; + assert(not_bool(FaultIsCorrected())); + if (not_bool(ErrorIsContained()) | not_bool(ErrorIsSynchronized()) & not_bool(StateIsRecoverable())) | ReportErrorAsUC() then { + return(ErrorState_UC) + }; + if not_bool(StateIsRecoverable()) | ReportErrorAsUEU() then { + if IsExternalSyncAbort__1(fault) then { + return(ErrorState_UC) + } else { + return(ErrorState_UEU) + } + }; + if ActionRequired() | ReportErrorAsUER() then { + return(ErrorState_UER) + }; + return(ErrorState_UEO) +} + +val HaveFeatLS64 : unit -> bool + +function HaveFeatLS64 () = { + return(IsFeatureImplemented(FEAT_LS64)) +} + +val LS64InstructionSyndrome : unit -> (bits(24), bits(11)) + +val AArch64_FaultSyndrome : forall ('d_side : Bool) ('pavalid : Bool). + (bool('d_side), FaultRecord, bool('pavalid)) -> (bits(25), bits(24)) + +function AArch64_FaultSyndrome (d_side, fault, pavalid) = { + assert(fault.statuscode != Fault_None); + iss : bits(25) = Zeros(25); + iss2 : bits(24) = Zeros(24); + if HaveRASExt() & fault.statuscode == Fault_SyncExternal then { + let errstate : ErrorState = AArch64_PEErrorState(fault); + iss[12 .. 11] = AArch64_EncodeSyncErrorSyndrome(errstate) + }; + if d_side then { + if fault.access.acctype == AccessType_GCS then { + iss2[8] = Bit(0b1) + }; + if HaveFeatLS64() & fault.access.ls64 then { + if fault.statuscode == Fault_AccessFlag | fault.statuscode == Fault_Translation | fault.statuscode == Fault_Permission then { + (iss2, iss[24 .. 14]) = LS64InstructionSyndrome() + }; + () + } else if (IsSecondStage(fault) & not_bool(fault.s2fs1walk)) & (not_bool(IsExternalSyncAbort__1(fault)) | (not_bool(HaveRASExt()) & fault.access.acctype == AccessType_TTW) & __IMPDEF_boolean("ISV on second stage translation table walk")) then { + iss[24 .. 14] = LSInstructionSyndrome() + } else (); + if HaveNV2Ext() & fault.access.acctype == AccessType_NV2 then { + iss[13] = Bit(0b1) + }; + if HaveFeatLS64() & (fault.statuscode == Fault_AccessFlag | fault.statuscode == Fault_Translation | fault.statuscode == Fault_Permission) then { + iss[12 .. 11] = GetLoadStoreType() + }; + if fault.access.acctype == AccessType_DC | fault.access.acctype == AccessType_IC | fault.access.acctype == AccessType_AT then { + iss[8] = Bit(0b1) + }; + if fault.access.acctype == AccessType_DC | fault.access.acctype == AccessType_IC | fault.access.acctype == AccessType_AT then { + iss[6] = Bit(0b1) + } else if fault.statuscode == Fault_HWUpdateAccessFlag | fault.statuscode == Fault_Exclusive then { + iss[6] = Bit(__UNKNOWN_bit()) + } else if fault.access.atomicop & IsExternalAbort__1(fault) then { + iss[6] = Bit(__UNKNOWN_bit()) + } else { + iss[6] = Bit(if fault.write then 0b1 else 0b0) + }; + if fault.statuscode == Fault_Permission then { + iss2[5] = Bit(if fault.dirtybit then 0b1 else 0b0); + iss2[6] = Bit(if fault.overlay then 0b1 else 0b0); + if [iss[24]] == 0b0 then { + iss[21] = Bit(if fault.toplevel then 0b1 else 0b0) + }; + iss2[7] = Bit(if fault.assuredonly then 0b1 else 0b0); + iss2[9] = Bit(if fault.tagaccess then 0b1 else 0b0); + iss2[10] = Bit(if fault.s1tagnotdata then 0b1 else 0b0) + }; + () + } else { + if fault.access.acctype == AccessType_IFETCH & fault.statuscode == Fault_Permission then { + iss2[5] = Bit(if fault.dirtybit then 0b1 else 0b0); + iss[21] = Bit(if fault.toplevel then 0b1 else 0b0); + iss2[7] = Bit(if fault.assuredonly then 0b1 else 0b0); + iss2[6] = Bit(if fault.overlay then 0b1 else 0b0) + }; + () + }; + if IsExternalAbort__1(fault) then { + iss[9] = Bit(fault.extflag) + }; + iss[7] = Bit(if fault.s2fs1walk then 0b1 else 0b0); + iss[5 .. 0] = EncodeLDFSC(fault.statuscode, fault.level); + return((iss, iss2)) +} + +val AArch64_AbortSyndrome : (Exception, FaultRecord, bits(64), bits(2)) -> ExceptionRecord + +function AArch64_AbortSyndrome (exceptype, fault, vaddress, target_el) = { + except : ExceptionRecord = ExceptionSyndrome(exceptype); + let d_side : bool = exceptype == Exception_DataAbort | exceptype == Exception_NV2DataAbort | exceptype == Exception_Watchpoint | exceptype == Exception_NV2Watchpoint; + if (not_bool(HavePFAR()) | not_bool(IsExternalSyncAbort__1(fault))) | (EL2Enabled() & HCR_EL2[VM] == 0b1) & target_el == EL1 then { + except.pavalid = false + } else { + except.pavalid = __IMPDEF_boolean("PFAR_ELx is valid") + }; + (except.syndrome, except.syndrome2) = AArch64_FaultSyndrome(d_side, fault, except.pavalid); + if fault.statuscode == Fault_TagCheck then { + if HaveMTE4Ext() then { + except.vaddress = ZeroExtend(vaddress, 64) + } else { + except.vaddress = __UNKNOWN_bits(4) @ vaddress[59 .. 0] + } + } else { + except.vaddress = ZeroExtend(vaddress, 64) + }; + if IPAValid(fault) then { + except.ipavalid = true; + except.NS = if fault.ipaddress.paspace == PAS_NonSecure then 0b1 else + 0b0; + except.ipaddress = fault.ipaddress.address + } else { + except.ipavalid = false + }; + return(except) +} + +val AArch64_BreakpointException : FaultRecord -> unit + +function AArch64_BreakpointException fault = { + assert(PSTATE.EL != EL3); + let route_to_el2 : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b1 | MDCR_EL2[TDE] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let target_el : bits(2) = if PSTATE.EL == EL2 | route_to_el2 then EL2 else + EL1; + let vaddress : bits(64) = __UNKNOWN_bits(64); + let except : ExceptionRecord = AArch64_AbortSyndrome(Exception_Breakpoint, fault, vaddress, target_el); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val HaveDoubleFault2Ext : unit -> bool + +function HaveDoubleFault2Ext () = { + return(IsFeatureImplemented(FEAT_DoubleFault2)) +} + +val HaveFeatSCTLR2 : unit -> bool + +function HaveFeatSCTLR2 () = { + return(IsFeatureImplemented(FEAT_SCTLR2)) +} + +val IsSCTLR2EL1Enabled : unit -> bool + +function IsSCTLR2EL1Enabled () = { + if not_bool(HaveFeatSCTLR2()) then { + return(false) + }; + if HaveEL(EL3) & SCR_EL3[SCTLR2En] == 0b0 then { + return(false) + } else if EL2Enabled() & (not_bool(IsHCRXEL2Enabled()) | HCRX_EL2[SCTLR2En] == 0b0) then { + return(false) + } else { + return(true) + } +} + +val IsSCTLR2EL2Enabled : unit -> bool + +function IsSCTLR2EL2Enabled () = { + if not_bool(HaveFeatSCTLR2()) then { + return(false) + }; + if HaveEL(EL3) & SCR_EL3[SCTLR2En] == 0b0 then { + return(false) + }; + return(EL2Enabled()) +} + +bitfield SCTLR2_EL1_Type : bits(64) = + {EnIDCP128 : 6..6, EASE : 5..5, EnANERR : 4..4, EnADERR : 3..3, NMEA : 2..2} + +register SCTLR2_EL1 : SCTLR2_EL1_Type + +bitfield SCTLR2_EL2_Type : bits(64) = + { + EnIDCP128 : 6..6, + EASE : 5..5, + EnANERR : 4..4, + EnADERR : 3..3, + NMEA : 2..2, + EMEC : 1..1 + } + +register SCTLR2_EL2 : SCTLR2_EL2_Type + +val AArch64_RouteToSErrorOffset : bits(2) -> bool + +function AArch64_RouteToSErrorOffset target_el = { + if not_bool(HaveDoubleFaultExt()) then { + return(false) + }; + ease_bit : bits(1) = undefined; + match target_el { + ? if ? == EL3 => { + ease_bit = SCR_EL3[EASE] + }, + ? if ? == EL2 => { + if HaveDoubleFault2Ext() & IsSCTLR2EL2Enabled() then { + ease_bit = SCTLR2_EL2[EASE] + } else { + ease_bit = 0b0 + } + }, + ? if ? == EL1 => { + if HaveDoubleFault2Ext() & IsSCTLR2EL1Enabled() then { + ease_bit = SCTLR2_EL1[EASE] + } else { + ease_bit = 0b0 + } + }, + _ => () + }; + return(ease_bit == 0b1) +} + +val AArch64_SyncExternalAbortTarget : FaultRecord -> bits(2) + +function AArch64_SyncExternalAbortTarget fault = { + route_to_el3 : bool = undefined; + if PSTATE.EL != EL3 then { + route_to_el3 = HaveEL(EL3) & EffectiveEA() == 0b1 + } else { + route_to_el3 = false + }; + let tea_bit : bits(1) = if HaveRASExt() then HCR_EL2[TEA] else 0b0; + route_to_el2 : bool = undefined; + if (not_bool(route_to_el3) & EL2Enabled()) & PSTATE.EL == EL1 then { + route_to_el2 = (tea_bit == 0b1 | fault.access.acctype == AccessType_NV2) | IsSecondStage(fault) + } else if (not_bool(route_to_el3) & EL2Enabled()) & PSTATE.EL == EL0 then { + route_to_el2 = not_bool(IsInHost()) & ((HCR_EL2[TGE] == 0b1 | tea_bit == 0b1) | IsSecondStage(fault)) + } else { + route_to_el2 = false + }; + route_masked_to_el3 : bool = undefined; + route_masked_to_el2 : bool = undefined; + if HaveDoubleFault2Ext() then { + route_masked_to_el2 = (((EL2Enabled() & not_bool(route_to_el3)) & PSTATE.EL == EL1 & PSTATE.A == 0b1) & IsHCRXEL2Enabled()) & HCRX_EL2[TMEA] == 0b1; + route_masked_to_el3 = ((HaveEL(EL3) & not_bool(route_to_el2 | route_masked_to_el2)) & (PSTATE.EL == EL2 | PSTATE.EL == EL1) & PSTATE.A == 0b1) & SCR_EL3[TMEA] == 0b1 + } else { + route_masked_to_el2 = false; + route_masked_to_el3 = false + }; + let take_in_el3 : bool = PSTATE.EL == EL3; + let take_in_el2_0 : bool = (PSTATE.EL == EL2 | IsInHost()) & not_bool(route_to_el3 | route_masked_to_el3); + let take_in_el1_0 : bool = ((PSTATE.EL == EL1 | PSTATE.EL == EL0 & not_bool(IsInHost())) & not_bool(route_to_el2 | route_masked_to_el2)) & not_bool(route_to_el3 | route_masked_to_el3); + target_el : bits(2) = undefined; + if (take_in_el3 | route_to_el3) | route_masked_to_el3 then { + target_el = EL3 + } else if (take_in_el2_0 | route_to_el2) | route_masked_to_el2 then { + target_el = EL2 + } else if take_in_el1_0 then { + target_el = EL1 + } else { + assert(false) + }; + return(target_el) +} + +val take_exception : option(FaultRecord) -> unit + +val AArch64_DataAbort : (bits(64), FaultRecord) -> unit + +function AArch64_DataAbort (vaddress, fault) = { + route_to_el2 : bool = undefined; + target_el : bits(2) = undefined; + if IsExternalAbort__1(fault) then { + target_el = AArch64_SyncExternalAbortTarget(fault) + } else { + let route_to_el2 : bool = (EL2Enabled() & (PSTATE.EL == EL0 | PSTATE.EL == EL1)) & (((HCR_EL2[TGE] == 0b1 | (HaveRME() & fault.gpcf.gpf == GPCF_Fail) & HCR_EL2[GPF] == 0b1) | HaveNV2Ext() & fault.access.acctype == AccessType_NV2) | IsSecondStage(fault)); + if PSTATE.EL == EL3 then { + target_el = EL3 + } else if PSTATE.EL == EL2 | route_to_el2 then { + target_el = EL2 + } else { + target_el = EL1 + } + }; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + vect_offset : int = undefined; + if IsExternalAbort__1(fault) & AArch64_RouteToSErrorOffset(target_el) then { + vect_offset = UInt(0x180) + } else { + vect_offset = UInt(0x0) + }; + let 'vect_offset = vect_offset; + except : ExceptionRecord = undefined; + if HaveNV2Ext() & fault.access.acctype == AccessType_NV2 then { + except = AArch64_AbortSyndrome(Exception_NV2DataAbort, fault, vaddress, target_el) + } else { + except = AArch64_AbortSyndrome(Exception_DataAbort, fault, vaddress, target_el) + }; + take_exception(Some(fault)); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AArch64_InstructionAbort : (bits(64), FaultRecord) -> unit + +function AArch64_InstructionAbort (vaddress, fault) = { + route_to_el2 : bool = undefined; + if HaveDoubleFaultExt() then { + assert(fault.statuscode != Fault_AsyncExternal) + }; + target_el : bits(2) = undefined; + if IsExternalAbort__1(fault) then { + target_el = AArch64_SyncExternalAbortTarget(fault) + } else { + let route_to_el2 : bool = (EL2Enabled() & (PSTATE.EL == EL0 | PSTATE.EL == EL1)) & ((HCR_EL2[TGE] == 0b1 | (HaveRME() & fault.gpcf.gpf == GPCF_Fail) & HCR_EL2[GPF] == 0b1) | IsSecondStage(fault)); + if PSTATE.EL == EL3 then { + target_el = EL3 + } else if PSTATE.EL == EL2 | route_to_el2 then { + target_el = EL2 + } else { + target_el = EL1 + } + }; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + vect_offset : int = undefined; + if IsExternalAbort__1(fault) & AArch64_RouteToSErrorOffset(target_el) then { + vect_offset = UInt(0x180) + } else { + vect_offset = UInt(0x0) + }; + let 'vect_offset = vect_offset; + let except : ExceptionRecord = AArch64_AbortSyndrome(Exception_InstructionAbort, fault, vaddress, target_el); + take_exception(Some(fault)); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AArch64_VectorCatchException : FaultRecord -> unit + +function AArch64_VectorCatchException fault = { + assert(PSTATE.EL != EL2); + assert(EL2Enabled() & (HCR_EL2[TGE] == 0b1 | MDCR_EL2[TDE] == 0b1)); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let vaddress : bits(64) = __UNKNOWN_bits(64); + let except : ExceptionRecord = AArch64_AbortSyndrome(Exception_VectorCatch, fault, vaddress, EL2); + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) +} + +val AArch64_WatchpointException : (bits(64), FaultRecord) -> unit + +function AArch64_WatchpointException (vaddress, fault) = { + assert(PSTATE.EL != EL3); + let route_to_el2 : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b1 | MDCR_EL2[TDE] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let target_el : bits(2) = if PSTATE.EL == EL2 | route_to_el2 then EL2 else + EL1; + except : ExceptionRecord = undefined; + if HaveNV2Ext() & fault.access.acctype == AccessType_NV2 then { + except = AArch64_AbortSyndrome(Exception_NV2Watchpoint, fault, vaddress, target_el) + } else { + except = AArch64_AbortSyndrome(Exception_Watchpoint, fault, vaddress, target_el) + }; + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val ReportAsGPCException : FaultRecord -> bool + +function ReportAsGPCException fault = { + assert(HaveRME()); + assert(fault.statuscode == Fault_GPCFOnWalk | fault.statuscode == Fault_GPCFOnOutput); + assert(fault.gpcf.gpf != GPCF_None); + match fault.gpcf.gpf { + GPCF_Walk => { + return(true) + }, + GPCF_AddressSize => { + return(true) + }, + GPCF_EABT => { + return(true) + }, + GPCF_Fail => { + return(SCR_EL3[GPF] == 0b1 & PSTATE.EL != EL3) + }, + _ => { + return(undefined : bool) + } + } +} + +val EncodeGPCSC : GPCFRecord -> bits(6) + +function EncodeGPCSC gpcf = { + assert(gpcf.level == 0 | gpcf.level == 1); + match gpcf.gpf { + GPCF_AddressSize => { + return(0b00000 @ [gpcf.level[0]]) + }, + GPCF_Walk => { + return(0b00010 @ [gpcf.level[0]]) + }, + GPCF_Fail => { + return(0b00110 @ [gpcf.level[0]]) + }, + GPCF_EABT => { + return(0b01010 @ [gpcf.level[0]]) + }, + _ => { + return(undefined : bits(6)) + } + } +} + +val HaveAccessFlagUpdateExt : unit -> bool + +function HaveAccessFlagUpdateExt () = { + return(IsFeatureImplemented(FEAT_HAFDBS)) +} + +val HaveAtomicExt : unit -> bool + +function HaveAtomicExt () = { + return(IsFeatureImplemented(FEAT_LSE)) +} + +val HaveDirtyBitModifierExt : unit -> bool + +function HaveDirtyBitModifierExt () = { + return(IsFeatureImplemented(FEAT_HAFDBS)) +} + +val TakeGPCException : (bits(64), FaultRecord) -> unit + +function TakeGPCException (vaddress, fault) = { + assert(HaveRME()); + assert(HaveAtomicExt()); + assert(HaveAccessFlagUpdateExt()); + assert(HaveDirtyBitModifierExt()); + assert(HaveDoubleFaultExt()); + except : ExceptionRecord = undefined; + except.exceptype = Exception_GPC; + except.vaddress = ZeroExtend(vaddress, 64); + except.paddress = fault.paddress; + except.pavalid = true; + if IPAValid(fault) then { + except.ipavalid = true; + except.NS = if fault.ipaddress.paspace == PAS_NonSecure then 0b1 else + 0b0; + except.ipaddress = fault.ipaddress.address + } else { + except.ipavalid = false + }; + if fault.access.acctype == AccessType_GCS then { + except.syndrome2[8] = Bit(0b1) + }; + except.syndrome[24 .. 22] = Zeros(3); + except.syndrome[21] = Bit(if fault.gpcfs2walk then 0b1 else 0b0); + if fault.access.acctype == AccessType_IFETCH then { + except.syndrome[20] = Bit(0b1) + } else { + except.syndrome[20] = Bit(0b0) + }; + except.syndrome[19 .. 14] = EncodeGPCSC(fault.gpcf); + if HaveNV2Ext() & fault.access.acctype == AccessType_NV2 then { + except.syndrome[13] = Bit(0b1) + } else { + except.syndrome[13] = Bit(0b0) + }; + except.syndrome[12 .. 11] = 0b00; + except.syndrome[10 .. 9] = 0b00; + if fault.access.acctype == AccessType_DC | fault.access.acctype == AccessType_IC | fault.access.acctype == AccessType_AT then { + except.syndrome[8] = Bit(0b1) + } else { + except.syndrome[8] = Bit(0b0) + }; + except.syndrome[7] = Bit(if fault.s2fs1walk then 0b1 else 0b0); + if fault.access.acctype == AccessType_DC | fault.access.acctype == AccessType_IC | fault.access.acctype == AccessType_AT then { + except.syndrome[6] = Bit(0b1) + } else if fault.statuscode == Fault_HWUpdateAccessFlag | fault.statuscode == Fault_Exclusive then { + except.syndrome[6] = Bit(__UNKNOWN_bit()) + } else if fault.access.atomicop & IsExternalAbort__1(fault) then { + except.syndrome[6] = Bit(__UNKNOWN_bit()) + } else { + except.syndrome[6] = Bit(if fault.write then 0b1 else 0b0) + }; + except.syndrome[5 .. 0] = EncodeLDFSC(fault.statuscode, fault.level); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let target_el : bits(2) = EL3; + vect_offset : int = undefined; + if IsExternalAbort__1(fault) & AArch64_RouteToSErrorOffset(target_el) then { + vect_offset = UInt(0x180) + } else { + vect_offset = UInt(0x0) + }; + let 'vect_offset = vect_offset; + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AArch64_Abort : (bits(64), FaultRecord) -> unit + +function AArch64_Abort (vaddress, fault) = { + if IsDebugException(fault) then { + if fault.access.acctype == AccessType_IFETCH then { + if UsingAArch32() & fault.debugmoe == DebugException_VectorCatch then { + AArch64_VectorCatchException(fault) + } else { + AArch64_BreakpointException(fault) + } + } else { + AArch64_WatchpointException(vaddress, fault) + } + } else if fault.gpcf.gpf != GPCF_None & ReportAsGPCException(fault) then { + TakeGPCException(vaddress, fault) + } else if fault.access.acctype == AccessType_IFETCH then { + AArch64_InstructionAbort(vaddress, fault) + } else { + AArch64_DataAbort(vaddress, fault) + } +} + +val AArch32_Abort : (bits(32), FaultRecord) -> unit + +function AArch32_Abort (vaddress, fault) = { + route_to_aarch64 : bool = PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)); + if (not_bool(route_to_aarch64) & EL2Enabled()) & not_bool(ELUsingAArch32(EL2)) then { + route_to_aarch64 = ((HCR_EL2[TGE] == 0b1 | IsSecondStage(fault)) | (HaveRASExt() & HCR_EL2[TEA] == 0b1) & IsExternalAbort__1(fault)) | IsDebugException(fault) & MDCR_EL2[TDE] == 0b1 + }; + if (not_bool(route_to_aarch64) & HaveEL(EL3)) & not_bool(ELUsingAArch32(EL3)) then { + route_to_aarch64 = EffectiveEA() == 0b1 & IsExternalAbort__1(fault) + }; + if route_to_aarch64 then { + AArch64_Abort(ZeroExtend(vaddress, 64), fault) + } else if fault.access.acctype == AccessType_IFETCH then { + AArch32_TakePrefetchAbortException(vaddress, fault) + } else { + AArch32_TakeDataAbortException(vaddress, fault) + } +} + +val GPCNoFault : unit -> GPCFRecord + +function GPCNoFault () = { + result : GPCFRecord = undefined; + result.gpf = GPCF_None; + return(result) +} + +val NoFault : unit -> FaultRecord + +val NoFault__1 : AccessDescriptor -> FaultRecord + +function NoFault () = { + fault : FaultRecord = undefined; + fault.statuscode = Fault_None; + fault.access = __UNKNOWN_AccessDescriptor(); + fault.secondstage = false; + fault.s2fs1walk = false; + fault.dirtybit = false; + fault.overlay = false; + fault.toplevel = false; + fault.assuredonly = false; + fault.s1tagnotdata = false; + fault.tagaccess = false; + fault.gpcfs2walk = false; + fault.gpcf = GPCNoFault(); + return(fault) +} + +function NoFault__1 accdesc = { + fault : FaultRecord = undefined; + fault.statuscode = Fault_None; + fault.access = accdesc; + fault.secondstage = false; + fault.s2fs1walk = false; + fault.dirtybit = false; + fault.overlay = false; + fault.toplevel = false; + fault.assuredonly = false; + fault.s1tagnotdata = false; + fault.tagaccess = false; + fault.write = not_bool(accdesc.read) & accdesc.write; + fault.gpcfs2walk = false; + fault.gpcf = GPCNoFault(); + return(fault) +} + +val HandleExternalAbort : forall ('iswrite : Bool) 'size. + (PhysMemRetStatus, bool('iswrite), AddressDescriptor, int('size), AccessDescriptor) -> unit + +function HandleExternalAbort (memretstatus, iswrite, memaddrdesc, size, accdesc) = { + assert((memretstatus.statuscode == Fault_SyncExternal | memretstatus.statuscode == Fault_AsyncExternal) | not_bool(HaveRASExt()) & (memretstatus.statuscode == Fault_SyncParity | memretstatus.statuscode == Fault_AsyncParity)); + fault : FaultRecord = NoFault__1(accdesc); + fault.statuscode = memretstatus.statuscode; + fault.write = iswrite; + fault.extflag = memretstatus.extflag; + if IsExternalSyncAbort__1(fault) & not_bool(IsExternalAbortTakenSynchronously(memretstatus, iswrite, memaddrdesc, size, accdesc)) then { + if fault.statuscode == Fault_SyncParity then { + fault.statuscode = Fault_AsyncParity + } else { + fault.statuscode = Fault_AsyncExternal + } + }; + if HaveRASExt() then { + fault.merrorstate = memretstatus.merrorstate + }; + if IsExternalSyncAbort__1(fault) then { + if UsingAArch32() then { + AArch32_Abort(memaddrdesc.vaddress[31 .. 0], fault) + } else { + AArch64_Abort(memaddrdesc.vaddress, fault) + } + } else { + PendSErrorInterrupt(fault) + } +} + +val HandleExternalReadAbort : forall 'size. + (PhysMemRetStatus, AddressDescriptor, int('size), AccessDescriptor) -> unit + +function HandleExternalReadAbort (memstatus, memaddrdesc, size, accdesc) = { + let iswrite : bool = false; + HandleExternalAbort(memstatus, iswrite, memaddrdesc, size, accdesc) +} + +val HandleExternalWriteAbort : forall 'size. + (PhysMemRetStatus, AddressDescriptor, int('size), AccessDescriptor) -> unit + +function HandleExternalWriteAbort (memstatus, memaddrdesc, size, accdesc) = { + let iswrite : bool = true; + HandleExternalAbort(memstatus, iswrite, memaddrdesc, size, accdesc) +} + +val IsSynchronizablePhysicalSErrorPending : unit -> bool + +val GetPendingPhysicalSError : unit -> FaultRecord + +val HCR_write : HCR_Type -> unit + +function HCR_write value_name = { + let r : HCR_Type = value_name; + HCR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HCR = r; + return() +} + +val ClearPendingVirtualSError : unit -> unit + +function ClearPendingVirtualSError () = { + if ELUsingAArch32(EL2) then { + HCR_write() = [HCR_read() with VA = 0b0] + } else { + HCR_EL2[VSE] = 0b0 + } +} + +val IsSErrorEdgeTriggered : unit -> bool + +function IsSErrorEdgeTriggered () = { + if HaveDoubleFaultExt() then { + return(true) + } else { + return(__IMPDEF_boolean("Edge-triggered SError")) + } +} + +val FPInfinity : forall 'N, 'N in {16, 32, 64}. (bits(1), int('N)) -> bits('N) + +function FPInfinity (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits('E) = Ones(E); + let frac : bits('F) = Zeros(F); + return((sign @ exp) @ frac) +} + +val FPMaxNormal : forall 'N, 'N in {16, 32, 64}. (bits(1), int('N)) -> bits('N) + +function FPMaxNormal (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits('E) = Ones(E - 1) @ 0b0; + let frac : bits('F) = Ones(F); + return((sign @ exp) @ frac) +} + +val AArch32_GeneralExceptionsToAArch64 : unit -> bool + +function AArch32_GeneralExceptionsToAArch64 () = { + return(PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)) | (EL2Enabled() & not_bool(ELUsingAArch32(EL2))) & HCR_EL2[TGE] == 0b1) +} + +val AArch32_TakeUndefInstrException : unit -> unit + +val AArch32_TakeUndefInstrException__1 : ExceptionRecord -> unit + +function AArch32_TakeUndefInstrException () = { + let except : ExceptionRecord = ExceptionSyndrome(Exception_Uncategorized); + AArch32_TakeUndefInstrException__1(except) +} + +function AArch32_TakeUndefInstrException__1 except = { + let route_to_hyp : bool = (PSTATE.EL == EL0 & EL2Enabled()) & HCR_read()[TGE] == 0b1; + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x04); + let 'lr_offset = if CurrentInstrSet() == InstrSet_A32 then 4 else 2; + if PSTATE.EL == EL2 then { + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else if route_to_hyp then { + AArch32_EnterHypMode(except, preferred_exception_return, UInt(0x14)) + } else { + AArch32_EnterMode(M32_Undef, preferred_exception_return, lr_offset, vect_offset) + } +} + +val AArch64_FPTrappedException : forall ('is_ase : Bool). + (bool('is_ase), bits(8)) -> unit + +function AArch64_FPTrappedException (is_ase, accumulated_exceptions) = { + except : ExceptionRecord = ExceptionSyndrome(Exception_FPTrappedException); + if is_ase then { + if __IMPDEF_boolean("vector instructions set TFV to 1") then { + except.syndrome[23] = Bit(0b1) + } else { + except.syndrome[23] = Bit(0b0) + } + } else { + except.syndrome[23] = Bit(0b1) + }; + except.syndrome[10 .. 8] = __UNKNOWN_bits(3); + if [except.syndrome[23]] == 0b1 then { + (except.syndrome[7 .. 7] @ except.syndrome[4 .. 0]) = [accumulated_exceptions[7]] @ accumulated_exceptions[4 .. 0] + } else { + (except.syndrome[7 .. 7] @ except.syndrome[4 .. 0]) = __UNKNOWN_bits(6) + }; + let route_to_el2 : bool = EL2Enabled() & HCR_EL2[TGE] == 0b1; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + if UInt(PSTATE.EL) > UInt(EL1) then { + AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset) + } else if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +bitfield FPEXC32_EL2_Type : bits(64) = + { + EX : 31..31, + EN : 30..30, + DEX : 29..29, + FP2V : 28..28, + VV : 27..27, + TFV : 26..26, + VECITR : 10..8, + IDF : 7..7, + IXF : 4..4, + UFF : 3..3, + OFF : 2..2, + DZF : 1..1, + IOF : 0..0 + } + +register FPEXC32_EL2 : FPEXC32_EL2_Type + +bitfield FPEXC_Type : bits(32) = + { + EX : 31..31, + EN : 30..30, + DEX : 29..29, + FP2V : 28..28, + VV : 27..27, + TFV : 26..26, + VECITR : 10..8, + IDF : 7..7, + IXF : 4..4, + UFF : 3..3, + OFF : 2..2, + DZF : 1..1, + IOF : 0..0 + } + +register _FPEXC : FPEXC_Type + +val FPEXC_read : unit -> FPEXC_Type + +function FPEXC_read () = { + r : FPEXC_Type = _FPEXC; + r.bits[31 .. 0] = Slice(FPEXC32_EL2.bits, 0, 32); + return(r) +} + +val FPEXC_write : FPEXC_Type -> unit + +function FPEXC_write value_name = { + let r : FPEXC_Type = value_name; + FPEXC32_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _FPEXC = r; + return() +} + +val AArch32_FPTrappedException : bits(8) -> unit + +function AArch32_FPTrappedException accumulated_exceptions = { + element : int = undefined; + is_ase : bool = undefined; + if AArch32_GeneralExceptionsToAArch64() then { + let is_ase : bool = false; + element = 0; + AArch64_FPTrappedException(is_ase, accumulated_exceptions) + }; + FPEXC_write() = [FPEXC_read() with DEX = 0b1]; + FPEXC_write() = [FPEXC_read() with TFV = 0b1]; + FPEXC_write() = Mk_FPEXC_Type([FPEXC_read().bits with 7 .. 7 = Slice([accumulated_exceptions[7]] @ accumulated_exceptions[4 .. 0], 5, 1)]); + FPEXC_write() = Mk_FPEXC_Type([FPEXC_read().bits with 4 .. 0 = Slice([accumulated_exceptions[7]] @ accumulated_exceptions[4 .. 0], 0, 5)]); + FPEXC_write() = Mk_FPEXC_Type([FPEXC_read().bits with 10 .. 8 = 0b111]); + AArch32_TakeUndefInstrException() +} + +val FPSCR_write : FPSCR_Type -> unit + +function FPSCR_write value_name = { + let r : FPSCR_Type = value_name; + FPSR.bits[31 .. 27] = Slice(r.bits, 27, 5); + FPSR.bits[7] = Bit(Slice(r.bits, 7, 1)); + FPSR.bits[4 .. 0] = Slice(r.bits, 0, 5); + FPCR.bits[26 .. 15] = Slice(r.bits, 15, 12); + FPCR.bits[12 .. 8] = Slice(r.bits, 8, 5); + return() +} + +val HaveSMEFullA64 : unit -> bool + +function HaveSMEFullA64 () = { + return(IsFeatureImplemented(FEAT_SME_FA64)) +} + +val IsFullA64Enabled : unit -> bool + +function IsFullA64Enabled () = { + if not_bool(HaveSMEFullA64()) then { + return(false) + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & not_bool(IsInHost()) then { + if SMCR_EL1[FA64] == 0b0 then { + return(false) + }; + () + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1 | PSTATE.EL == EL2) & EL2Enabled() then { + if SMCR_EL2[FA64] == 0b0 then { + return(false) + }; + () + }; + if HaveEL(EL3) then { + if SMCR_EL3[FA64] == 0b0 then { + return(false) + }; + () + }; + return(true) +} + +val FPProcessException : (FPExc, FPCRType) -> unit + +function FPProcessException (except, fpcr) = { + is_ase : bool = undefined; + cumul : {0, 1, 2, 3, 4, 7} = 0; + match except { + FPExc_InvalidOp => { + cumul = 0 + }, + FPExc_DivideByZero => { + cumul = 1 + }, + FPExc_Overflow => { + cumul = 2 + }, + FPExc_Underflow => { + cumul = 3 + }, + FPExc_Inexact => { + cumul = 4 + }, + FPExc_InputDenorm => { + cumul = 7 + } + }; + let 'cumul = cumul; + let 'enable = cumul + 8; + if [fpcr.bits[enable]] == 0b1 & ((not_bool(HaveSME()) | PSTATE.SM == 0b0) | IsFullA64Enabled()) then { + accumulated_exceptions : bits(8) = GetAccumulatedFPExceptions(); + accumulated_exceptions[cumul] = Bit(0b1); + if __IMPDEF_boolean("Support trapping of floating-point exceptions") then { + if UsingAArch32() then { + AArch32_FPTrappedException(accumulated_exceptions) + } else { + let is_ase : bool = IsASEInstruction(); + AArch64_FPTrappedException(is_ase, accumulated_exceptions) + } + } else { + SetAccumulatedFPExceptions(accumulated_exceptions) + } + } else if UsingAArch32() then { + FPSCR_write() = Mk_FPSCR_Type([FPSCR_read__1().bits with cumul .. cumul = 0b1]) + } else { + FPSR.bits[cumul] = Bit(0b1) + }; + return() +} + +val FPZero : forall 'N, 'N in {16, 32, 64}. (bits(1), int('N)) -> bits('N) + +function FPZero (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits('E) = Zeros(E); + let frac : bits('F) = Zeros(F); + let result : bits(1 + 'E + 'F) = (sign @ exp) @ frac; + return(result) +} + +val HaveAltFP : unit -> bool + +function HaveAltFP () = { + return(IsFeatureImplemented(FEAT_AFP)) +} + +val FPRoundBase__1 : forall 'N ('fpexc : Bool) ('isbfloat16 : Bool), + 'N in {16, 32, 64}. + (real, FPCRType, FPRounding, bool('isbfloat16), bool('fpexc), int('N)) -> bits('N) + +function FPRoundBase__1 (op, fpcr, rounding, isbfloat16, fpexc, N) = { + assert(N == 16 | N == 32 | N == 64); + assert(op != 0.0); + assert(rounding != FPRounding_TIEAWAY); + result : bits('N) = undefined; + minimum_exp : int = undefined; + F : {7, 10, 23, 52} = 7; + E : {5, 8, 11} = 5; + if N == 16 then { + minimum_exp = negate(14); + E = 5; + F = 10 + } else if N == 32 & isbfloat16 then { + minimum_exp = negate(126); + E = 8; + F = 7 + } else if N == 32 then { + minimum_exp = negate(126); + E = 8; + F = 23 + } else { + minimum_exp = negate(1022); + E = 11; + F = 52 + }; + let 'minimum_exp = minimum_exp; + let 'F = F; + let 'E = E; + sign : bits(1) = undefined; + mantissa : real = undefined; + if op < 0.0 then { + sign = 0b1; + mantissa = neg_real(op) + } else { + sign = 0b0; + mantissa = op + }; + exponent : int = 0; + while mantissa < 1.0 do { + mantissa = mantissa * 2.0; + exponent = exponent - 1 + }; + while mantissa >= 2.0 do { + mantissa = mantissa / 2.0; + exponent = exponent + 1 + }; + let 'exponent = exponent; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + if (not_bool(altfp) & (fpcr[FZ] == 0b1 & N != 16 | fpcr[FZ16] == 0b1 & N == 16)) & exponent < minimum_exp then { + if UsingAArch32() then { + FPSCR_write() = [FPSCR_read__1() with UFC = 0b1] + } else { + if fpexc then { + FPSR[UFC] = 0b1 + }; + () + }; + return(FPZero(sign, N)) + }; + biased_exp_unconstrained : int = exponent - minimum_exp + 1; + int_mant_unconstrained : int = RoundDown(mantissa * 2.0 ^ F); + let error_unconstrained : real = mantissa * 2.0 ^ F - Real(int_mant_unconstrained); + biased_exp : int = Max(exponent - minimum_exp + 1, 0); + if biased_exp == 0 then { + mantissa = mantissa / 2.0 ^ (minimum_exp - exponent) + }; + let mantissa = mantissa; + int_mant : int = RoundDown(mantissa * 2.0 ^ F); + error : real = mantissa * 2.0 ^ F - Real(int_mant); + let trapped_UF : bool = fpcr[UFE] == 0b1 & (not_bool(InStreamingMode()) | IsFullA64Enabled()); + if (not_bool(altfp) & biased_exp == 0) & (error != 0.0 | trapped_UF) then { + if fpexc then { + FPProcessException(FPExc_Underflow, fpcr) + }; + () + }; + round_up_unconstrained : bool = undefined; + round_up : bool = undefined; + overflow_to_inf : bool = undefined; + if altfp then { + match rounding { + FPRounding_TIEEVEN => { + round_up_unconstrained = error_unconstrained > 0.5 | error_unconstrained == 0.5 & [int_mant_unconstrained[0]] == 0b1; + round_up = error > 0.5 | error == 0.5 & [int_mant[0]] == 0b1; + overflow_to_inf = true + }, + FPRounding_POSINF => { + round_up_unconstrained = error_unconstrained != 0.0 & sign == 0b0; + round_up = error != 0.0 & sign == 0b0; + overflow_to_inf = sign == 0b0 + }, + FPRounding_NEGINF => { + round_up_unconstrained = error_unconstrained != 0.0 & sign == 0b1; + round_up = error != 0.0 & sign == 0b1; + overflow_to_inf = sign == 0b1 + }, + FPRounding_ZERO => { + round_up_unconstrained = false; + round_up = false; + overflow_to_inf = false + }, + FPRounding_ODD => { + round_up_unconstrained = false; + round_up = false; + overflow_to_inf = false + }, + _ => () + }; + if round_up_unconstrained then { + int_mant_unconstrained = int_mant_unconstrained + 1; + if int_mant_unconstrained == pow2(F + 1) then { + biased_exp_unconstrained = biased_exp_unconstrained + 1; + int_mant_unconstrained = DIV(int_mant_unconstrained, 2) + }; + () + }; + let 'int_mant_unconstrained = int_mant_unconstrained; + let 'biased_exp_unconstrained = biased_exp_unconstrained; + if biased_exp_unconstrained < 1 & int_mant_unconstrained != 0 then { + if fpcr[FZ] == 0b1 & N != 16 | fpcr[FZ16] == 0b1 & N == 16 then { + if fpexc then { + FPSR[UFC] = 0b1; + FPProcessException(FPExc_Inexact, fpcr) + }; + return(FPZero(sign, N)) + } else if error != 0.0 | trapped_UF then { + if fpexc then { + FPProcessException(FPExc_Underflow, fpcr) + }; + () + } else () + }; + () + } else { + match rounding { + FPRounding_TIEEVEN => { + round_up = error > 0.5 | error == 0.5 & [int_mant[0]] == 0b1; + overflow_to_inf = true + }, + FPRounding_POSINF => { + round_up = error != 0.0 & sign == 0b0; + overflow_to_inf = sign == 0b0 + }, + FPRounding_NEGINF => { + round_up = error != 0.0 & sign == 0b1; + overflow_to_inf = sign == 0b1 + }, + FPRounding_ZERO => { + round_up = false; + overflow_to_inf = false + }, + FPRounding_ODD => { + round_up = false; + overflow_to_inf = false + }, + _ => () + } + }; + if round_up then { + int_mant = int_mant + 1; + if int_mant == pow2(F) then { + biased_exp = 1 + }; + if int_mant == pow2(F + 1) then { + biased_exp = biased_exp + 1; + int_mant = DIV(int_mant, 2) + }; + () + }; + let 'biased_exp = biased_exp; + if error != 0.0 & rounding == FPRounding_ODD then { + int_mant = [int_mant with 0 .. 0 = 0b1] + }; + let 'int_mant = int_mant; + if N != 16 | fpcr[AHP] == 0b0 then { + if biased_exp >= pow2(E) - 1 then { + result = if overflow_to_inf then FPInfinity(sign, N) else + FPMaxNormal(sign, N); + if fpexc then { + FPProcessException(FPExc_Overflow, fpcr) + }; + error = 1.0 + } else { + assert(constraint('N - ('E + 'F + 1) >= 0)); + result = ((sign @ biased_exp[E - 1 .. 0]) @ int_mant[F - 1 .. 0]) @ Zeros(N - (E + F + 1)) + } + } else { + if biased_exp >= pow2(E) then { + result = sign @ Ones(N - 1); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + error = 0.0 + } else { + assert(constraint('N - ('E + 'F + 1) >= 0)); + result = ((sign @ biased_exp[E - 1 .. 0]) @ int_mant[F - 1 .. 0]) @ Zeros(N - (E + F + 1)) + } + }; + if error != 0.0 then { + if fpexc then { + FPProcessException(FPExc_Inexact, fpcr) + }; + () + }; + return(result) +} + +val FPDecodeRounding : bits(2) -> FPRounding + +function FPDecodeRounding rmode = { + match rmode { + 0b00 => { + return(FPRounding_TIEEVEN) + }, + 0b01 => { + return(FPRounding_POSINF) + }, + 0b10 => { + return(FPRounding_NEGINF) + }, + 0b11 => { + return(FPRounding_ZERO) + }, + _ => { + return(undefined : FPRounding) + } + } +} + +val FPRoundingMode : FPCRType -> FPRounding + +function FPRoundingMode fpcr = { + return(FPDecodeRounding(fpcr[RMode])) +} + +val FPRound : forall 'N, 'N in {16, 32, 64}. + (real, FPCRType, int('N)) -> bits('N) + +val FPRound__1 : forall 'N, 'N in {16, 32, 64}. + (real, FPCRType, FPRounding, int('N)) -> bits('N) + +val FPRound__2 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (real, FPCRType, FPRounding, bool('fpexc), int('N)) -> bits('N) + +function FPRound (op, fpcr, N) = { + return(FPRound__1(op, fpcr, FPRoundingMode(fpcr), N)) +} + +function FPRound__1 (op, fpcr_in, rounding, N) = { + let fpexc : bool = true; + return(FPRound__2(op, fpcr_in, rounding, fpexc, N)) +} + +function FPRound__2 (op, fpcr_in, rounding, fpexc, N) = { + fpcr : FPCRType = fpcr_in; + fpcr[AHP] = 0b0; + let isbfloat16 : bool = false; + return(FPRoundBase__1(op, fpcr, rounding, isbfloat16, fpexc, N)) +} + +val FixedToFP : forall 'M 'N 'fbits ('is_unsigned : Bool), + ('N in {16, 32, 64} & 'M in {16, 32, 64}). + (bits('M), int('fbits), bool('is_unsigned), FPCRType, FPRounding, int('N)) -> bits('N) + +function FixedToFP (op, fbits, is_unsigned, fpcr, rounding, N) = { + assert(N == 16 | N == 32 | N == 64); + assert('M == 16 | 'M == 32 | 'M == 64); + result : bits('N) = undefined; + assert(fbits >= 0); + assert(rounding != FPRounding_ODD); + let 'int_operand = asl_Int(op, is_unsigned); + let real_operand : real = Real(int_operand) / 2.0 ^ fbits; + if real_operand == 0.0 then { + result = FPZero(0b0, N) + } else { + result = FPRound__1(real_operand, fpcr, rounding, N) + }; + return(result) +} + +val FPUnpackBase : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (bits('N), FPCRType, bool('fpexc)) -> (FPType, bits(1), real) + +val FPUnpackBase__1 : forall 'N ('fpexc : Bool) ('isbfloat16 : Bool), + 'N in {16, 32, 64}. + (bits('N), FPCRType, bool('fpexc), bool('isbfloat16)) -> (FPType, bits(1), real) + +function FPUnpackBase (fpval, fpcr, fpexc) = { + fp_type : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + let isbfloat16 : bool = false; + (fp_type, sign, value_name) = FPUnpackBase__1(fpval, fpcr, fpexc, isbfloat16); + return((fp_type, sign, value_name)) +} + +function FPUnpackBase__1 (fpval, fpcr_in, fpexc, isbfloat16) = { + exp16 : bits(5) = undefined; + exp64 : bits(11) = undefined; + frac16 : bits(10) = undefined; + frac64 : bits(52) = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + let fpcr : FPCRType = fpcr_in; + let altfp : bool = HaveAltFP() & not_bool(UsingAArch32()); + let fiz : bool = altfp & fpcr[FIZ] == 0b1; + let fz : bool = fpcr[FZ] == 0b1 & not_bool(altfp & fpcr[AH] == 0b1); + value_name : real = undefined; + sign : bits(1) = undefined; + fptype : FPType = undefined; + if 'N == 16 & not_bool(isbfloat16) then { + sign = [fpval[15]]; + let exp16 : bits(5) = fpval[14 .. 10]; + let frac16 : bits(10) = fpval[9 .. 0]; + if IsZero(exp16) then { + if IsZero(frac16) | fpcr[FZ16] == 0b1 then { + fptype = FPType_Zero; + value_name = 0.0 + } else { + fptype = FPType_Denormal; + value_name = 2.0 ^ negate(14) * (Real(UInt(frac16)) * 2.0 ^ negate(10)) + } + } else if IsOnes(exp16) & fpcr[AHP] == 0b0 then { + if IsZero(frac16) then { + fptype = FPType_Infinity; + value_name = 2.0 ^ 1000000 + } else { + fptype = if [frac16[9]] == 0b1 then FPType_QNaN else FPType_SNaN; + value_name = 0.0 + } + } else { + fptype = FPType_Nonzero; + value_name = 2.0 ^ (UInt(exp16) - 15) * (1.0 + Real(UInt(frac16)) * 2.0 ^ negate(10)) + } + } else if 'N == 32 | isbfloat16 then { + exp32 : bits(8) = undefined; + frac32 : bits(23) = undefined; + if isbfloat16 then { + sign = [fpval[15]]; + exp32 = fpval[14 .. 7]; + frac32 = fpval[6 .. 0] @ Zeros(16) + } else { + sign = [fpval[31]]; + exp32 = fpval[30 .. 23]; + frac32 = fpval[22 .. 0] + }; + if IsZero(exp32) then { + if IsZero(frac32) then { + fptype = FPType_Zero; + value_name = 0.0 + } else if fz | fiz then { + fptype = FPType_Zero; + value_name = 0.0; + if fz then { + if fpexc then { + FPProcessException(FPExc_InputDenorm, fpcr) + }; + () + }; + () + } else { + fptype = FPType_Denormal; + value_name = 2.0 ^ negate(126) * (Real(UInt(frac32)) * 2.0 ^ negate(23)) + } + } else if IsOnes(exp32) then { + if IsZero(frac32) then { + fptype = FPType_Infinity; + value_name = 2.0 ^ 1000000 + } else { + fptype = if [frac32[22]] == 0b1 then FPType_QNaN else + FPType_SNaN; + value_name = 0.0 + } + } else { + fptype = FPType_Nonzero; + value_name = 2.0 ^ (UInt(exp32) - 127) * (1.0 + Real(UInt(frac32)) * 2.0 ^ negate(23)) + } + } else { + sign = [fpval[63]]; + let exp64 : bits(11) = fpval[62 .. 52]; + let frac64 : bits(52) = fpval[51 .. 0]; + if IsZero(exp64) then { + if IsZero(frac64) then { + fptype = FPType_Zero; + value_name = 0.0 + } else if fz | fiz then { + fptype = FPType_Zero; + value_name = 0.0; + if fz then { + if fpexc then { + FPProcessException(FPExc_InputDenorm, fpcr) + }; + () + }; + () + } else { + fptype = FPType_Denormal; + value_name = 2.0 ^ negate(1022) * (Real(UInt(frac64)) * 2.0 ^ negate(52)) + } + } else if IsOnes(exp64) then { + if IsZero(frac64) then { + fptype = FPType_Infinity; + value_name = 2.0 ^ 1000000 + } else { + fptype = if [frac64[51]] == 0b1 then FPType_QNaN else + FPType_SNaN; + value_name = 0.0 + } + } else { + fptype = FPType_Nonzero; + value_name = 2.0 ^ (UInt(exp64) - 1023) * (1.0 + Real(UInt(frac64)) * 2.0 ^ negate(52)) + } + }; + if sign == 0b1 then { + value_name = neg_real(value_name) + }; + let value_name = value_name; + return((fptype, sign, value_name)) +} + +val FPUnpack : forall 'N, 'N in {16, 32, 64}. + (bits('N), FPCRType) -> (FPType, bits(1), real) + +val FPUnpack__1 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (bits('N), FPCRType, bool('fpexc)) -> (FPType, bits(1), real) + +function FPUnpack (fpval, fpcr_in) = { + fp_type : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + fpcr : FPCRType = fpcr_in; + fpcr[AHP] = 0b0; + let fpexc : bool = true; + (fp_type, sign, value_name) = FPUnpackBase(fpval, fpcr, fpexc); + return((fp_type, sign, value_name)) +} + +function FPUnpack__1 (fpval, fpcr_in, fpexc) = { + fp_type : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + fpcr : FPCRType = fpcr_in; + fpcr[AHP] = 0b0; + (fp_type, sign, value_name) = FPUnpackBase(fpval, fpcr, fpexc); + return((fp_type, sign, value_name)) +} + +val FPAbs : forall 'N, 'N in {16, 32, 64}. bits('N) -> bits('N) + +function FPAbs op = { + fptype : FPType = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + if not_bool(UsingAArch32()) & HaveAltFP() then { + let fpcr : FPCRType = FPCR_read(); + if fpcr[AH] == 0b1 then { + let (__tup_0 : FPType, _, _) = FPUnpack__1(op, fpcr, false) in + { + fptype = __tup_0 + }; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + return(op) + }; + () + }; + () + }; + return(0b0 @ op['N - 2 .. 0]) +} + +val FPDefaultNaN : forall 'N, 'N in {16, 32, 64}. int('N) -> bits('N) + +val FPDefaultNaN__1 : forall 'N, 'N in {16, 32, 64}. + (FPCRType, int('N)) -> bits('N) + +function FPDefaultNaN N = { + let fpcr : FPCRType = FPCR_read(); + return(FPDefaultNaN__1(fpcr, N)) +} + +function FPDefaultNaN__1 (fpcr, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let sign : bits(1) = if HaveAltFP() & not_bool(UsingAArch32()) then fpcr[AH] + else + 0b0; + let exp : bits('E) = Ones(E); + let frac : bits('F) = 0b1 @ Zeros(F - 1); + return((sign @ exp) @ frac) +} + +val FPProcessDenorms : forall 'N. (FPType, FPType, int('N), FPCRType) -> unit + +function FPProcessDenorms (type1, type2, N, fpcr) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + if (altfp & N != 16) & (type1 == FPType_Denormal | type2 == FPType_Denormal) then { + FPProcessException(FPExc_InputDenorm, fpcr) + }; + () +} + +val FPProcessNaN : forall 'N, 'N in {16, 32, 64}. + (FPType, bits('N), FPCRType) -> bits('N) + +val FPProcessNaN__1 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (FPType, bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function FPProcessNaN (fptype, op, fpcr) = { + let fpexc : bool = true; + return(FPProcessNaN__1(fptype, op, fpcr, fpexc)) +} + +function FPProcessNaN__1 (fptype, op, fpcr, fpexc) = { + assert('N == 16 | 'N == 32 | 'N == 64); + assert(fptype == FPType_QNaN | fptype == FPType_SNaN); + topfrac : {9, 22, 51} = 9; + match 'N { + 16 => { + topfrac = 9 + }, + 32 => { + topfrac = 22 + }, + 64 => { + topfrac = 51 + }, + _ => () + }; + let 'topfrac = topfrac; + result : bits('N) = op; + if fptype == FPType_SNaN then { + assert(constraint((0 <= 'topfrac & 'topfrac < 'N))); + result[topfrac] = Bit(0b1); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + }; + if fpcr[DN] == 0b1 then { + result = FPDefaultNaN__1(fpcr, 'N) + }; + return(result) +} + +val FPProcessNaNs : forall 'N, 'N in {16, 32, 64}. + (FPType, FPType, bits('N), bits('N), FPCRType) -> (bool, bits('N)) + +val FPProcessNaNs__1 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (FPType, FPType, bits('N), bits('N), FPCRType, bool('fpexc)) -> (bool, bits('N)) + +function FPProcessNaNs (type1, type2, op1, op2, fpcr) = { + let fpexc : bool = true; + return(FPProcessNaNs__1(type1, type2, op1, op2, fpcr, fpexc)) +} + +function FPProcessNaNs__1 (type1, type2, op1, op2, fpcr, fpexc) = { + assert('N == 16 | 'N == 32 | 'N == 64); + done : bool = undefined; + result : bits('N) = undefined; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let op1_nan : bool = type1 == FPType_SNaN | type1 == FPType_QNaN; + let op2_nan : bool = type2 == FPType_SNaN | type2 == FPType_QNaN; + let any_snan : bool = type1 == FPType_SNaN | type2 == FPType_SNaN; + let type_nan : FPType = if any_snan then FPType_SNaN else FPType_QNaN; + if (altfp & op1_nan) & op2_nan then { + done = true; + result = FPProcessNaN__1(type_nan, op1, fpcr, fpexc) + } else if type1 == FPType_SNaN then { + done = true; + result = FPProcessNaN__1(type1, op1, fpcr, fpexc) + } else if type2 == FPType_SNaN then { + done = true; + result = FPProcessNaN__1(type2, op2, fpcr, fpexc) + } else if type1 == FPType_QNaN then { + done = true; + result = FPProcessNaN__1(type1, op1, fpcr, fpexc) + } else if type2 == FPType_QNaN then { + done = true; + result = FPProcessNaN__1(type2, op2, fpcr, fpexc) + } else { + done = false; + result = Zeros('N) + }; + return((done, result)) +} + +val FPAdd : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +val FPAdd__1 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function FPAdd (op1, op2, fpcr) = { + let fpexc : bool = true; + return(FPAdd__1(op1, op2, fpcr, fpexc)) +} + +function FPAdd__1 (op1, op2, fpcr, fpexc) = { + done : bool = undefined; + inf1 : bool = undefined; + inf2 : bool = undefined; + result : bits('N) = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + let rounding : FPRounding = FPRoundingMode(fpcr); + (type1, sign1, value1_name) = FPUnpack__1(op1, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2, fpcr, fpexc); + (done, result) = FPProcessNaNs__1(type1, type2, op1, op2, fpcr, fpexc); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if (inf1 & inf2) & sign1 == not_vec(sign2) then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if inf1 & sign1 == 0b0 | inf2 & sign2 == 0b0 then { + result = FPInfinity(0b0, 'N) + } else if inf1 & sign1 == 0b1 | inf2 & sign2 == 0b1 then { + result = FPInfinity(0b1, 'N) + } else if (zero1 & zero2) & sign1 == sign2 then { + result = FPZero(sign1, 'N) + } else { + let result_value : real = value1_name + value2_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 'N) + } else { + result = FPRound__2(result_value, fpcr, rounding, fpexc, 'N) + } + }; + if fpexc then { + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + () + }; + return(result) +} + +val FPAdd_ZA : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPAdd_ZA (op1, op2, fpcr_in) = { + fpcr : FPCRType = fpcr_in; + let fpexc : bool = false; + fpcr[DN] = 0b1; + return(FPAdd__1(op1, op2, fpcr, fpexc)) +} + +val FPCompare : forall 'N ('signal_nans : Bool), + 'N in {16, 32, 64}. + (bits('N), bits('N), bool('signal_nans), FPCRType) -> bits(4) + +function FPCompare (op1, op2, signal_nans, fpcr) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + result : bits(4) = undefined; + if (type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN then { + result = 0b0011; + if (type1 == FPType_SNaN | type2 == FPType_SNaN) | signal_nans then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else { + if value1_name == value2_name then { + result = 0b0110 + } else if value1_name < value2_name then { + result = 0b1000 + } else { + result = 0b0010 + }; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPCompareEQ : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bool + +function FPCompareEQ (op1, op2, fpcr) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + result : bool = undefined; + if (type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN then { + result = false; + if type1 == FPType_SNaN | type2 == FPType_SNaN then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else { + result = value1_name == value2_name; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPCompareGE : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bool + +function FPCompareGE (op1, op2, fpcr) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + result : bool = undefined; + if (type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN then { + result = false; + FPProcessException(FPExc_InvalidOp, fpcr) + } else { + result = value1_name >= value2_name; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPCompareGT : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bool + +function FPCompareGT (op1, op2, fpcr) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + result : bool = undefined; + if (type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN then { + result = false; + FPProcessException(FPExc_InvalidOp, fpcr) + } else { + result = value1_name > value2_name; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPConvertNaN : forall 'M 'N, + ('N in {16, 32, 64} & 'M in {16, 32, 64}). + (bits('N), int('M)) -> bits('M) + +function FPConvertNaN (op, M) = { + assert('N == 16 | 'N == 32 | 'N == 64); + assert(M == 16 | M == 32 | M == 64); + result : bits('M) = undefined; + frac : bits(51) = undefined; + let sign : bits(1) = [op['N - 1]]; + match 'N { + 64 => { + frac = op[50 .. 0] + }, + 32 => { + frac = op[21 .. 0] @ Zeros(29) + }, + 16 => { + frac = op[8 .. 0] @ Zeros(42) + }, + _ => () + }; + match M { + 64 => { + result = (sign @ Ones(M - 52)) @ frac + }, + 32 => { + result = (sign @ Ones(M - 23)) @ frac[50 .. 29] + }, + 16 => { + result = (sign @ Ones(M - 10)) @ frac[50 .. 42] + }, + _ => () + }; + return(result) +} + +val FPProcessDenorm : forall 'N. (FPType, int('N), FPCRType) -> unit + +function FPProcessDenorm (fptype, N, fpcr) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + if (altfp & N != 16) & fptype == FPType_Denormal then { + FPProcessException(FPExc_InputDenorm, fpcr) + }; + () +} + +val FPRoundCV : forall 'N, 'N in {16, 32, 64}. + (real, FPCRType, FPRounding, int('N)) -> bits('N) + +function FPRoundCV (op, fpcr_in, rounding, N) = { + fpcr : FPCRType = fpcr_in; + fpcr[FZ16] = 0b0; + let fpexc : bool = true; + let isbfloat16 : bool = false; + return(FPRoundBase__1(op, fpcr, rounding, isbfloat16, fpexc, N)) +} + +val FPUnpackCV : forall 'N, 'N in {16, 32, 64}. + (bits('N), FPCRType) -> (FPType, bits(1), real) + +function FPUnpackCV (fpval, fpcr_in) = { + fp_type : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + fpcr : FPCRType = fpcr_in; + fpcr[FZ16] = 0b0; + let fpexc : bool = true; + (fp_type, sign, value_name) = FPUnpackBase(fpval, fpcr, fpexc); + return((fp_type, sign, value_name)) +} + +val FPConvert : forall 'M 'N, + ('M in {16, 32, 64} & 'N in {16, 32, 64}). + (bits('N), FPCRType, FPRounding, int('M)) -> bits('M) + +val FPConvert__1 : forall 'M 'N, + ('M in {16, 32, 64} & 'N in {16, 32, 64}). + (bits('N), FPCRType, int('M)) -> bits('M) + +function FPConvert (op, fpcr, rounding, M) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert(M == 16 | M == 32 | M == 64); + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('M) = undefined; + (fptype, sign, value_name) = FPUnpackCV(op, fpcr); + let alt_hp : bool = M == 16 & fpcr[AHP] == 0b1; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + if alt_hp then { + result = FPZero(sign, M) + } else if fpcr[DN] == 0b1 then { + result = FPDefaultNaN__1(fpcr, M) + } else { + result = FPConvertNaN(op, M) + }; + if fptype == FPType_SNaN | alt_hp then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if fptype == FPType_Infinity then { + if alt_hp then { + result = sign @ Ones(M - 1); + FPProcessException(FPExc_InvalidOp, fpcr) + } else { + result = FPInfinity(sign, M) + } + } else if fptype == FPType_Zero then { + result = FPZero(sign, M) + } else { + result = FPRoundCV(value_name, fpcr, rounding, M); + FPProcessDenorm(fptype, 'N, fpcr) + }; + return(result) +} + +function FPConvert__1 (op, fpcr, M) = { + return(FPConvert(op, fpcr, FPRoundingMode(fpcr), M)) +} + +val FPDecodeRM : bits(2) -> FPRounding + +function FPDecodeRM rm = { + result : FPRounding = undefined; + match rm { + 0b00 => { + result = FPRounding_TIEAWAY + }, + 0b01 => { + result = FPRounding_TIEEVEN + }, + 0b10 => { + result = FPRounding_POSINF + }, + 0b11 => { + result = FPRounding_NEGINF + } + }; + let result = result; + return(result) +} + +val FPDiv : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPDiv (op1, op2, fpcr) = { + done : bool = undefined; + inf1 : bool = undefined; + inf2 : bool = undefined; + result : bits('N) = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if inf1 & inf2 | zero1 & zero2 then { + result = FPDefaultNaN__1(fpcr, 'N); + FPProcessException(FPExc_InvalidOp, fpcr) + } else if inf1 | zero2 then { + result = FPInfinity(EOR(sign1, sign2), 'N); + if not_bool(inf1) then { + FPProcessException(FPExc_DivideByZero, fpcr) + }; + () + } else if zero1 | inf2 then { + result = FPZero(EOR(sign1, sign2), 'N) + } else { + result = FPRound(value1_name / value2_name, fpcr, 'N) + }; + if not_bool(zero2) then { + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + () + }; + return(result) +} + +val FPMax : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +val FPMax__1 : forall 'N ('altfp : Bool), + 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType, bool('altfp)) -> bits('N) + +function FPMax (op1, op2, fpcr) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + return(FPMax__1(op1, op2, fpcr, altfp)) +} + +function FPMax__1 (op1, op2, fpcr_in, altfp) = { + rounding : FPRounding = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + done : bool = undefined; + result : bits('N) = undefined; + fpcr : FPCRType = fpcr_in; + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + if ((altfp & type1 == FPType_Zero) & type2 == FPType_Zero) & sign1 != sign2 then { + return(FPZero(sign2, 'N)) + } else if altfp & ((type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN) then { + FPProcessException(FPExc_InvalidOp, fpcr); + return(if type2 == FPType_Zero then FPZero(sign2, 'N) else op2) + } else (); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + if value1_name > value2_name then { + (fptype, sign, value_name) = (type1, sign1, value1_name) + } else { + (fptype, sign, value_name) = (type2, sign2, value2_name) + }; + if fptype == FPType_Infinity then { + result = FPInfinity(sign, 'N) + } else if fptype == FPType_Zero then { + let sign : bits(1) = sign1 & sign2; + result = FPZero(sign, 'N) + } else { + let rounding : FPRounding = FPRoundingMode(fpcr); + if altfp then { + fpcr[FZ] = 0b0; + fpcr[FZ16] = 0b0 + }; + result = FPRound__2(value_name, fpcr, rounding, true, 'N) + }; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPMaxNum : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPMaxNum (op1_in, op2_in, fpcr) = { + type1 : FPType = undefined; + type2 : FPType = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + op1 : bits('N) = op1_in; + op2 : bits('N) = op2_in; + let (__tup_0 : FPType, _, _) = FPUnpack(op1, fpcr) in + { + type1 = __tup_0 + }; + let (__tup_0 : FPType, _, _) = FPUnpack(op2, fpcr) in + { + type2 = __tup_0 + }; + let type1_nan : bool = type1 == FPType_QNaN | type1 == FPType_SNaN; + let type2_nan : bool = type2 == FPType_QNaN | type2 == FPType_SNaN; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + if not_bool((altfp & type1_nan) & type2_nan) then { + if type1 == FPType_QNaN & type2 != FPType_QNaN then { + op1 = FPInfinity(0b1, 'N) + } else if type1 != FPType_QNaN & type2 == FPType_QNaN then { + op2 = FPInfinity(0b1, 'N) + } else () + }; + let altfmaxfmin : bool = false; + let result : bits('N) = FPMax__1(op1, op2, fpcr, altfmaxfmin); + return(result) +} + +val IsMerging : FPCRType -> bool + +function IsMerging fpcr = { + let nep : bits(1) = if (HaveSME() & PSTATE.SM == 0b1) & not_bool(IsFullA64Enabled()) then + 0b0 + else + fpcr[NEP]; + return((HaveAltFP() & not_bool(UsingAArch32())) & nep == 0b1) +} + +val FPMin : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +val FPMin__1 : forall 'N ('altfp : Bool), + 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType, bool('altfp)) -> bits('N) + +function FPMin (op1, op2, fpcr) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + return(FPMin__1(op1, op2, fpcr, altfp)) +} + +function FPMin__1 (op1, op2, fpcr_in, altfp) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + done : bool = undefined; + result : bits('N) = undefined; + fpcr : FPCRType = fpcr_in; + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + if ((altfp & type1 == FPType_Zero) & type2 == FPType_Zero) & sign1 != sign2 then { + return(FPZero(sign2, 'N)) + } else if altfp & ((type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN) then { + FPProcessException(FPExc_InvalidOp, fpcr); + return(if type2 == FPType_Zero then FPZero(sign2, 'N) else op2) + } else (); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + rounding : FPRounding = undefined; + if value1_name < value2_name then { + (fptype, sign, value_name) = (type1, sign1, value1_name) + } else { + (fptype, sign, value_name) = (type2, sign2, value2_name) + }; + if fptype == FPType_Infinity then { + result = FPInfinity(sign, 'N) + } else if fptype == FPType_Zero then { + let sign : bits(1) = sign1 | sign2; + result = FPZero(sign, 'N) + } else { + let rounding : FPRounding = FPRoundingMode(fpcr); + if altfp then { + fpcr[FZ] = 0b0; + fpcr[FZ16] = 0b0 + }; + result = FPRound__2(value_name, fpcr, rounding, true, 'N) + }; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPMinNum : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPMinNum (op1_in, op2_in, fpcr) = { + type1 : FPType = undefined; + type2 : FPType = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + op1 : bits('N) = op1_in; + op2 : bits('N) = op2_in; + let (__tup_0 : FPType, _, _) = FPUnpack(op1, fpcr) in + { + type1 = __tup_0 + }; + let (__tup_0 : FPType, _, _) = FPUnpack(op2, fpcr) in + { + type2 = __tup_0 + }; + let type1_nan : bool = type1 == FPType_QNaN | type1 == FPType_SNaN; + let type2_nan : bool = type2 == FPType_QNaN | type2 == FPType_SNaN; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + if not_bool((altfp & type1_nan) & type2_nan) then { + if type1 == FPType_QNaN & type2 != FPType_QNaN then { + op1 = FPInfinity(0b0, 'N) + } else if type1 != FPType_QNaN & type2 == FPType_QNaN then { + op2 = FPInfinity(0b0, 'N) + } else () + }; + let altfmaxfmin : bool = false; + let result : bits('N) = FPMin__1(op1, op2, fpcr, altfmaxfmin); + return(result) +} + +val FPMul : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPMul (op1, op2, fpcr) = { + done : bool = undefined; + inf1 : bool = undefined; + inf2 : bool = undefined; + result : bits('N) = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if inf1 & zero2 | zero1 & inf2 then { + result = FPDefaultNaN__1(fpcr, 'N); + FPProcessException(FPExc_InvalidOp, fpcr) + } else if inf1 | inf2 then { + result = FPInfinity(EOR(sign1, sign2), 'N) + } else if zero1 | zero2 then { + result = FPZero(EOR(sign1, sign2), 'N) + } else { + result = FPRound(value1_name * value2_name, fpcr, 'N) + }; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPProcessDenorms3 : forall 'N. + (FPType, FPType, FPType, int('N), FPCRType) -> unit + +function FPProcessDenorms3 (type1, type2, type3, N, fpcr) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + if (altfp & N != 16) & ((type1 == FPType_Denormal | type2 == FPType_Denormal) | type3 == FPType_Denormal) then { + FPProcessException(FPExc_InputDenorm, fpcr) + }; + () +} + +val FPProcessNaNs3__1 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (FPType, FPType, FPType, bits('N), bits('N), bits('N), FPCRType, bool('fpexc)) -> (bool, bits('N)) + +function FPProcessNaNs3__1 (type1, type2, type3, op1, op2, op3, fpcr, fpexc) = { + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('N) = undefined; + let op1_nan : bool = type1 == FPType_SNaN | type1 == FPType_QNaN; + let op2_nan : bool = type2 == FPType_SNaN | type2 == FPType_QNaN; + let op3_nan : bool = type3 == FPType_SNaN | type3 == FPType_QNaN; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + type_nan : FPType = undefined; + if altfp then { + if (type1 == FPType_SNaN | type2 == FPType_SNaN) | type3 == FPType_SNaN then { + type_nan = FPType_SNaN + } else { + type_nan = FPType_QNaN + } + }; + done : bool = undefined; + if ((altfp & op1_nan) & op2_nan) & op3_nan then { + done = true; + result = FPProcessNaN__1(type_nan, op2, fpcr, fpexc) + } else if (altfp & op2_nan) & (op1_nan | op3_nan) then { + done = true; + result = FPProcessNaN__1(type_nan, op2, fpcr, fpexc) + } else if (altfp & op3_nan) & op1_nan then { + done = true; + result = FPProcessNaN__1(type_nan, op3, fpcr, fpexc) + } else if type1 == FPType_SNaN then { + done = true; + result = FPProcessNaN__1(type1, op1, fpcr, fpexc) + } else if type2 == FPType_SNaN then { + done = true; + result = FPProcessNaN__1(type2, op2, fpcr, fpexc) + } else if type3 == FPType_SNaN then { + done = true; + result = FPProcessNaN__1(type3, op3, fpcr, fpexc) + } else if type1 == FPType_QNaN then { + done = true; + result = FPProcessNaN__1(type1, op1, fpcr, fpexc) + } else if type2 == FPType_QNaN then { + done = true; + result = FPProcessNaN__1(type2, op2, fpcr, fpexc) + } else if type3 == FPType_QNaN then { + done = true; + result = FPProcessNaN__1(type3, op3, fpcr, fpexc) + } else { + done = false; + result = Zeros('N) + }; + return((done, result)) +} + +val FPMulAdd : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), bits('N), FPCRType) -> bits('N) + +val FPMulAdd__1 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (bits('N), bits('N), bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function FPMulAdd (addend, op1, op2, fpcr) = { + let fpexc : bool = true; + return(FPMulAdd__1(addend, op1, op2, fpcr, fpexc)) +} + +function FPMulAdd__1 (addend, op1, op2, fpcr, fpexc) = { + done : bool = undefined; + infA : bool = undefined; + infP : bool = undefined; + invalidop : bool = undefined; + result : bits('N) = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + signA : bits(1) = undefined; + signP : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + typeA : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + valueA_name : real = undefined; + zeroA : bool = undefined; + zeroP : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (typeA, signA, valueA_name) = FPUnpack__1(addend, fpcr, fpexc); + (type1, sign1, value1_name) = FPUnpack__1(op1, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2, fpcr, fpexc); + let rounding : FPRounding = FPRoundingMode(fpcr); + let inf1 : bool = type1 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let inf2 : bool = type2 == FPType_Infinity; + let zero2 : bool = type2 == FPType_Zero; + (done, result) = FPProcessNaNs3__1(typeA, type1, type2, addend, op1, op2, fpcr, fpexc); + if not_bool((HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1) then { + if typeA == FPType_QNaN & (inf1 & zero2 | zero1 & inf2) then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + }; + () + }; + if not_bool(done) then { + let infA : bool = typeA == FPType_Infinity; + let zeroA : bool = typeA == FPType_Zero; + let signP : bits(1) = EOR(sign1, sign2); + let infP : bool = inf1 | inf2; + let zeroP : bool = zero1 | zero2; + let invalidop : bool = (inf1 & zero2 | zero1 & inf2) | (infA & infP) & signA != signP; + if invalidop then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if infA & signA == 0b0 | infP & signP == 0b0 then { + result = FPInfinity(0b0, 'N) + } else if infA & signA == 0b1 | infP & signP == 0b1 then { + result = FPInfinity(0b1, 'N) + } else if (zeroA & zeroP) & signA == signP then { + result = FPZero(signA, 'N) + } else { + let result_value : real = valueA_name + value1_name * value2_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 'N) + } else { + result = FPRound__2(result_value, fpcr, rounding, fpexc, 'N) + } + }; + if not_bool(invalidop) & fpexc then { + FPProcessDenorms3(typeA, type1, type2, 'N, fpcr) + }; + () + }; + return(result) +} + +val FPMulAdd_ZA : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), bits('N), FPCRType) -> bits('N) + +function FPMulAdd_ZA (addend, op1, op2, fpcr_in) = { + fpcr : FPCRType = fpcr_in; + let fpexc : bool = false; + fpcr[DN] = 0b1; + return(FPMulAdd__1(addend, op1, op2, fpcr, fpexc)) +} + +val FPTwo : forall 'N, 'N in {16, 32, 64}. (bits(1), int('N)) -> bits('N) + +function FPTwo (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits(1 + ('E - 1)) = 0b1 @ Zeros(E - 1); + let frac : bits('F) = Zeros(F); + let result : bits(1 + (1 + ('E - 1)) + 'F) = (sign @ exp) @ frac; + return(result) +} + +val FPMulX : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPMulX (op1, op2, fpcr) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('N) = undefined; + done : bool = undefined; + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if inf1 & zero2 | zero1 & inf2 then { + result = FPTwo(EOR(sign1, sign2), 'N) + } else if inf1 | inf2 then { + result = FPInfinity(EOR(sign1, sign2), 'N) + } else if zero1 | zero2 then { + result = FPZero(EOR(sign1, sign2), 'N) + } else { + result = FPRound(value1_name * value2_name, fpcr, 'N) + }; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPProcessNaNs3H : forall 'N ('fpexc : Bool), 'N in {32, 64}. + (FPType, FPType, FPType, bits('N), bits(div('N, 2)), bits(div('N, 2)), FPCRType, bool('fpexc)) -> (bool, bits('N)) + +function FPProcessNaNs3H (type1, type2, type3, op1, op2, op3, fpcr, fpexc) = { + assert('N == 32 | 'N == 64); + result : bits('N) = undefined; + type_nan : FPType = undefined; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let op1_nan : bool = type1 == FPType_SNaN | type1 == FPType_QNaN; + let op2_nan : bool = type2 == FPType_SNaN | type2 == FPType_QNaN; + let op3_nan : bool = type3 == FPType_SNaN | type3 == FPType_QNaN; + if altfp then { + if (type1 == FPType_SNaN | type2 == FPType_SNaN) | type3 == FPType_SNaN then { + type_nan = FPType_SNaN + } else { + type_nan = FPType_QNaN + } + }; + done : bool = undefined; + if ((altfp & op1_nan) & op2_nan) & op3_nan then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type_nan, op2, fpcr, fpexc), 'N) + } else if (altfp & op2_nan) & (op1_nan | op3_nan) then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type_nan, op2, fpcr, fpexc), 'N) + } else if (altfp & op3_nan) & op1_nan then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type_nan, op3, fpcr, fpexc), 'N) + } else if type1 == FPType_SNaN then { + done = true; + result = FPProcessNaN__1(type1, op1, fpcr, fpexc) + } else if type2 == FPType_SNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type2, op2, fpcr, fpexc), 'N) + } else if type3 == FPType_SNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type3, op3, fpcr, fpexc), 'N) + } else if type1 == FPType_QNaN then { + done = true; + result = FPProcessNaN__1(type1, op1, fpcr, fpexc) + } else if type2 == FPType_QNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type2, op2, fpcr, fpexc), 'N) + } else if type3 == FPType_QNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type3, op3, fpcr, fpexc), 'N) + } else { + done = false; + result = Zeros('N) + }; + return((done, result)) +} + +val FPMulAddH : forall 'N, 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), FPCRType) -> bits('N) + +val FPMulAddH__1 : forall 'N ('fpexc : Bool), 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), FPCRType, bool('fpexc)) -> bits('N) + +function FPMulAddH (addend, op1, op2, fpcr) = { + let fpexc : bool = true; + return(FPMulAddH__1(addend, op1, op2, fpcr, fpexc)) +} + +function FPMulAddH__1 (addend, op1, op2, fpcr, fpexc) = { + done : bool = undefined; + infA : bool = undefined; + infP : bool = undefined; + invalidop : bool = undefined; + result : bits('N) = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + signA : bits(1) = undefined; + signP : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + typeA : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + valueA_name : real = undefined; + zeroA : bool = undefined; + zeroP : bool = undefined; + assert('N == 32); + let rounding : FPRounding = FPRoundingMode(fpcr); + (typeA, signA, valueA_name) = FPUnpack__1(addend, fpcr, fpexc); + (type1, sign1, value1_name) = FPUnpack__1(op1, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2, fpcr, fpexc); + let inf1 : bool = type1 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let inf2 : bool = type2 == FPType_Infinity; + let zero2 : bool = type2 == FPType_Zero; + (done, result) = FPProcessNaNs3H(typeA, type1, type2, addend, op1, op2, fpcr, fpexc); + if not_bool((HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1) then { + if typeA == FPType_QNaN & (inf1 & zero2 | zero1 & inf2) then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + }; + () + }; + if not_bool(done) then { + let infA : bool = typeA == FPType_Infinity; + let zeroA : bool = typeA == FPType_Zero; + let signP : bits(1) = EOR(sign1, sign2); + let infP : bool = inf1 | inf2; + let zeroP : bool = zero1 | zero2; + let invalidop : bool = (inf1 & zero2 | zero1 & inf2) | (infA & infP) & signA != signP; + if invalidop then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if infA & signA == 0b0 | infP & signP == 0b0 then { + result = FPInfinity(0b0, 'N) + } else if infA & signA == 0b1 | infP & signP == 0b1 then { + result = FPInfinity(0b1, 'N) + } else if (zeroA & zeroP) & signA == signP then { + result = FPZero(signA, 'N) + } else { + let result_value : real = valueA_name + value1_name * value2_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 'N) + } else { + result = FPRound__2(result_value, fpcr, rounding, fpexc, 'N) + } + }; + if not_bool(invalidop) & fpexc then { + FPProcessDenorm(typeA, 'N, fpcr) + }; + () + }; + return(result) +} + +val FPMulAddH_ZA : forall 'N, 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), FPCRType) -> bits('N) + +function FPMulAddH_ZA (addend, op1, op2, fpcr_in) = { + fpcr : FPCRType = fpcr_in; + let fpexc : bool = false; + fpcr[DN] = 0b1; + return(FPMulAddH__1(addend, op1, op2, fpcr, fpexc)) +} + +val FPNeg : forall 'N, 'N in {16, 32, 64}. bits('N) -> bits('N) + +function FPNeg op = { + fptype : FPType = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + if not_bool(UsingAArch32()) & HaveAltFP() then { + let fpcr : FPCRType = FPCR_read(); + if fpcr[AH] == 0b1 then { + let (__tup_0 : FPType, _, _) = FPUnpack__1(op, fpcr, false) in + { + fptype = __tup_0 + }; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + return(op) + }; + () + }; + () + }; + return(not_vec([op['N - 1]]) @ op['N - 2 .. 0]) +} + +val FPOnePointFive : forall 'N, 'N in {16, 32, 64}. + (bits(1), int('N)) -> bits('N) + +function FPOnePointFive (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits(1 + ('E - 1)) = 0b0 @ Ones(E - 1); + let frac : bits(1 + ('F - 1)) = 0b1 @ Zeros(F - 1); + let result : bits(1 + (1 + ('E - 1)) + (1 + ('F - 1))) = (sign @ exp) @ frac; + return(result) +} + +val HaveFeatRPRES : unit -> bool + +function HaveFeatRPRES () = { + return(IsFeatureImplemented(FEAT_RPRES)) +} + +val FPRecipEstimate : forall 'N, 'N in {16, 32, 64}. + (bits('N), FPCRType) -> bits('N) + +function FPRecipEstimate (operand, fpcr_in) = { + estimate : int = undefined; + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + fpcr : FPCRType = fpcr_in; + result : bits('N) = undefined; + overflow_to_inf : bool = undefined; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + if altfp then { + (fpcr[FIZ] @ fpcr[FZ]) = 0b11 + }; + if altfp then { + fpcr[RMode] = 0b00 + }; + (fptype, sign, value_name) = FPUnpack__1(operand, fpcr, fpexc); + let rounding : FPRounding = FPRoundingMode(fpcr); + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + result = FPProcessNaN__1(fptype, operand, fpcr, fpexc) + } else if fptype == FPType_Infinity then { + result = FPZero(sign, 'N) + } else if fptype == FPType_Zero then { + result = FPInfinity(sign, 'N); + if fpexc then { + FPProcessException(FPExc_DivideByZero, fpcr) + }; + () + } else if ('N == 16 & Abs(value_name) < 2.0 ^ negate(16) | 'N == 32 & Abs(value_name) < 2.0 ^ negate(128)) | 'N == 64 & Abs(value_name) < 2.0 ^ negate(1024) then { + match rounding { + FPRounding_TIEEVEN => { + overflow_to_inf = true + }, + FPRounding_POSINF => { + overflow_to_inf = sign == 0b0 + }, + FPRounding_NEGINF => { + overflow_to_inf = sign == 0b1 + }, + FPRounding_ZERO => { + overflow_to_inf = false + }, + _ => () + }; + result = if overflow_to_inf then FPInfinity(sign, 'N) else + FPMaxNormal(sign, 'N); + if fpexc then { + FPProcessException(FPExc_Overflow, fpcr); + FPProcessException(FPExc_Inexact, fpcr) + }; + () + } else if (fpcr[FZ] == 0b1 & 'N != 16 | fpcr[FZ16] == 0b1 & 'N == 16) & (('N == 16 & Abs(value_name) >= 2.0 ^ 14 | 'N == 32 & Abs(value_name) >= 2.0 ^ 126) | 'N == 64 & Abs(value_name) >= 2.0 ^ 1022) then { + result = FPZero(sign, 'N); + if UsingAArch32() then { + FPSCR_write() = [FPSCR_read__1() with UFC = 0b1] + } else { + if fpexc then { + FPSR[UFC] = 0b1 + }; + () + } + } else { + fraction : bits(52) = undefined; + exp : int = undefined; + match 'N { + 16 => { + fraction = operand[9 .. 0] @ Zeros(42); + exp = UInt(operand[14 .. 10]) + }, + 32 => { + fraction = operand[22 .. 0] @ Zeros(29); + exp = UInt(operand[30 .. 23]) + }, + 64 => { + fraction = operand[51 .. 0]; + exp = UInt(operand[62 .. 52]) + }, + _ => () + }; + if exp == 0 then { + if [fraction[51]] == 0b0 then { + exp = negate(1); + fraction = fraction[49 .. 0] @ 0b00 + } else { + fraction = fraction[50 .. 0] @ 0b0 + } + }; + let 'exp = exp; + scaled : range(0, 4095) = undefined; + let increasedprecision_name : bool = ('N == 32 & HaveFeatRPRES()) & altfp; + if not_bool(increasedprecision_name) then { + scaled = UInt(0b1 @ fraction[51 .. 44]) + } else { + scaled = UInt(0b1 @ fraction[51 .. 41]) + }; + let 'scaled = scaled; + result_exp : int = undefined; + match 'N { + 16 => { + result_exp = 29 - exp + }, + 32 => { + result_exp = 253 - exp + }, + 64 => { + result_exp = 2045 - exp + }, + _ => () + }; + let 'estimate = RecipEstimate(scaled, increasedprecision_name); + if not_bool(increasedprecision_name) then { + fraction = estimate[7 .. 0] @ Zeros(44) + } else { + fraction = estimate[11 .. 0] @ Zeros(40) + }; + if result_exp == 0 then { + fraction = 0b1 @ fraction[51 .. 1] + } else if result_exp == negate(1) then { + fraction = 0b01 @ fraction[51 .. 2]; + result_exp = 0 + } else (); + let 'result_exp = result_exp; + match 'N { + 16 => { + result = (sign @ result_exp['N - 12 .. 0]) @ fraction[51 .. 42] + }, + 32 => { + result = (sign @ result_exp['N - 25 .. 0]) @ fraction[51 .. 29] + }, + 64 => { + result = (sign @ result_exp['N - 54 .. 0]) @ fraction[51 .. 0] + }, + _ => () + } + }; + return(result) +} + +val FPRecpX : forall 'N, 'N in {16, 32, 64}. (bits('N), FPCRType) -> bits('N) + +function FPRecpX (op, fpcr_in) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + fpcr : FPCRType = fpcr_in; + esize : {5, 8, 11} = 5; + match 'N { + 16 => { + esize = 5 + }, + 32 => { + esize = 8 + }, + 64 => { + esize = 11 + }, + _ => () + }; + let 'esize = esize; + result : bits('N) = undefined; + exp : bits('esize) = undefined; + let frac : bits('N - ('esize + 1)) = Zeros('N - (esize + 1)); + let altfp : bool = HaveAltFP() & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + if altfp then { + (fpcr[FIZ] @ fpcr[FZ]) = 0b11 + }; + (fptype, sign, value_name) = FPUnpack__1(op, fpcr, fpexc); + match 'N { + 16 => { + assert(constraint((10 <= 10 + 'esize - 1 & 10 + 'esize - 1 < 'N))); + exp = op[10 + esize - 1 .. 10] + }, + 32 => { + assert(constraint((23 <= 23 + 'esize - 1 & 23 + 'esize - 1 < 'N))); + exp = op[23 + esize - 1 .. 23] + }, + 64 => { + exp = op[52 + esize - 1 .. 52] + }, + _ => () + }; + let max_exp : bits('esize) = Ones(esize) - 1; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + result = FPProcessNaN__1(fptype, op, fpcr, fpexc) + } else { + if IsZero(exp) then { + result = (sign @ max_exp) @ frac + } else { + result = (sign @ not_vec(exp)) @ frac + } + }; + return(result) +} + +val FPRoundInt : forall 'N ('exact : Bool), + 'N in {16, 32, 64}. + (bits('N), FPCRType, FPRounding, bool('exact)) -> bits('N) + +function FPRoundInt (op, fpcr, rounding, exact) = { + error : real = undefined; + fptype : FPType = undefined; + int_result : int = undefined; + real_result : real = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert(rounding != FPRounding_ODD); + assert('N == 16 | 'N == 32 | 'N == 64); + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + (fptype, sign, value_name) = FPUnpack__1(op, fpcr, fpexc); + result : bits('N) = undefined; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + result = FPProcessNaN(fptype, op, fpcr) + } else if fptype == FPType_Infinity then { + result = FPInfinity(sign, 'N) + } else if fptype == FPType_Zero then { + result = FPZero(sign, 'N) + } else { + int_result : int = RoundDown(value_name); + let error : real = value_name - Real(int_result); + round_up : bool = undefined; + match rounding { + FPRounding_TIEEVEN => { + round_up = error > 0.5 | error == 0.5 & [int_result[0]] == 0b1 + }, + FPRounding_POSINF => { + round_up = error != 0.0 + }, + FPRounding_NEGINF => { + round_up = false + }, + FPRounding_ZERO => { + round_up = error != 0.0 & int_result < 0 + }, + FPRounding_TIEAWAY => { + round_up = error > 0.5 | error == 0.5 & int_result >= 0 + }, + _ => () + }; + if round_up then { + int_result = int_result + 1 + }; + let 'int_result = int_result; + let real_result : real = Real(int_result); + if real_result == 0.0 then { + result = FPZero(sign, 'N) + } else { + result = FPRound__1(real_result, fpcr, FPRounding_ZERO, 'N) + }; + if error != 0.0 & exact then { + FPProcessException(FPExc_Inexact, fpcr) + }; + () + }; + return(result) +} + +val FPRoundIntN : forall 'N 'intsize, 'N in {32, 64}. + (bits('N), FPCRType, FPRounding, int('intsize)) -> bits('N) + +function FPRoundIntN (op, fpcr, rounding, intsize) = { + error : real = undefined; + fptype : FPType = undefined; + int_result : int = undefined; + overflow : bool = undefined; + real_result : real = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert(rounding != FPRounding_ODD); + assert('N == 32 | 'N == 64); + assert(intsize == 32 | intsize == 64); + exp : int = undefined; + result : bits('N) = undefined; + round_up : bool = undefined; + let 'E = if 'N == 32 then 8 else 11; + let 'F = 'N - (E + 1); + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + (fptype, sign, value_name) = FPUnpack__1(op, fpcr, fpexc); + if fptype == FPType_SNaN | fptype == FPType_QNaN | fptype == FPType_Infinity then { + if 'N == 32 then { + let 'exp = 126 + intsize; + result = (0b1 @ exp[E - 1 .. 0]) @ Zeros(F) + } else { + let 'exp = 1022 + intsize; + result = (0b1 @ exp[E - 1 .. 0]) @ Zeros(F) + }; + FPProcessException(FPExc_InvalidOp, fpcr) + } else if fptype == FPType_Zero then { + result = FPZero(sign, 'N) + } else { + int_result : int = RoundDown(value_name); + error : real = value_name - Real(int_result); + match rounding { + FPRounding_TIEEVEN => { + round_up = error > 0.5 | error == 0.5 & [int_result[0]] == 0b1 + }, + FPRounding_POSINF => { + round_up = error != 0.0 + }, + FPRounding_NEGINF => { + round_up = false + }, + FPRounding_ZERO => { + round_up = error != 0.0 & int_result < 0 + }, + FPRounding_TIEAWAY => { + round_up = error > 0.5 | error == 0.5 & int_result >= 0 + }, + _ => () + }; + if round_up then { + int_result = int_result + 1 + }; + let 'int_result = int_result; + let overflow : bool = int_result > pow2(intsize - 1) - 1 | int_result < negate(1) * pow2(intsize - 1); + if overflow then { + if 'N == 32 then { + let 'exp = 126 + intsize; + result = (0b1 @ exp[E - 1 .. 0]) @ Zeros(F) + } else { + let 'exp = 1022 + intsize; + result = (0b1 @ exp[E - 1 .. 0]) @ Zeros(F) + }; + FPProcessException(FPExc_InvalidOp, fpcr); + error = 0.0 + } else { + let real_result : real = Real(int_result); + if real_result == 0.0 then { + result = FPZero(sign, 'N) + } else { + result = FPRound__1(real_result, fpcr, FPRounding_ZERO, 'N) + } + }; + if error != 0.0 then { + FPProcessException(FPExc_Inexact, fpcr) + }; + () + }; + return(result) +} + +val FPRSqrtEstimate : forall 'N, 'N in {16, 32, 64}. + (bits('N), FPCRType) -> bits('N) + +function FPRSqrtEstimate (operand, fpcr_in) = { + estimate : int = undefined; + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + fpcr : FPCRType = fpcr_in; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + if altfp then { + (fpcr[FIZ] @ fpcr[FZ]) = 0b11 + }; + (fptype, sign, value_name) = FPUnpack__1(operand, fpcr, fpexc); + result : bits('N) = undefined; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + result = FPProcessNaN__1(fptype, operand, fpcr, fpexc) + } else if fptype == FPType_Zero then { + result = FPInfinity(sign, 'N); + if fpexc then { + FPProcessException(FPExc_DivideByZero, fpcr) + }; + () + } else if sign == 0b1 then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if fptype == FPType_Infinity then { + result = FPZero(0b0, 'N) + } else { + fraction : bits(52) = undefined; + exp : int = undefined; + match 'N { + 16 => { + fraction = operand[9 .. 0] @ Zeros(42); + exp = UInt(operand[14 .. 10]) + }, + 32 => { + fraction = operand[22 .. 0] @ Zeros(29); + exp = UInt(operand[30 .. 23]) + }, + 64 => { + fraction = operand[51 .. 0]; + exp = UInt(operand[62 .. 52]) + }, + _ => () + }; + if exp == 0 then { + while [fraction[51]] == 0b0 do { + fraction = fraction[50 .. 0] @ 0b0; + exp = exp - 1 + }; + fraction = fraction[50 .. 0] @ 0b0 + }; + let fraction = fraction; + let 'exp = exp; + scaled : range(0, 4095) = undefined; + let increasedprecision_name : bool = ('N == 32 & HaveFeatRPRES()) & altfp; + if not_bool(increasedprecision_name) then { + if [exp[0]] == 0b0 then { + scaled = UInt(0b1 @ fraction[51 .. 44]) + } else { + scaled = UInt(0b01 @ fraction[51 .. 45]) + } + } else { + if [exp[0]] == 0b0 then { + scaled = UInt(0b1 @ fraction[51 .. 41]) + } else { + scaled = UInt(0b01 @ fraction[51 .. 42]) + } + }; + let 'scaled = scaled; + result_exp : int = undefined; + match 'N { + 16 => { + result_exp = DIV(44 - exp, 2) + }, + 32 => { + result_exp = DIV(380 - exp, 2) + }, + 64 => { + result_exp = DIV(3068 - exp, 2) + }, + _ => () + }; + let 'result_exp = result_exp; + let 'estimate = RecipSqrtEstimate(scaled, increasedprecision_name); + match 'N { + 16 => { + result = ((0b0 @ result_exp['N - 12 .. 0]) @ estimate[7 .. 0]) @ Zeros(2) + }, + 32 => { + if not_bool(increasedprecision_name) then { + result = ((0b0 @ result_exp['N - 25 .. 0]) @ estimate[7 .. 0]) @ Zeros(15) + } else { + result = ((0b0 @ result_exp['N - 25 .. 0]) @ estimate[11 .. 0]) @ Zeros(11) + } + }, + 64 => { + result = ((0b0 @ result_exp['N - 54 .. 0]) @ estimate[7 .. 0]) @ Zeros(44) + }, + _ => () + } + }; + return(result) +} + +val FPSqrt : forall 'N, 'N in {16, 32, 64}. (bits('N), FPCRType) -> bits('N) + +function FPSqrt (op, fpcr) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (fptype, sign, value_name) = FPUnpack(op, fpcr); + result : bits('N) = undefined; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + result = FPProcessNaN(fptype, op, fpcr) + } else if fptype == FPType_Zero then { + result = FPZero(sign, 'N) + } else if fptype == FPType_Infinity & sign == 0b0 then { + result = FPInfinity(sign, 'N) + } else if sign == 0b1 then { + result = FPDefaultNaN__1(fpcr, 'N); + FPProcessException(FPExc_InvalidOp, fpcr) + } else { + result = FPRound(sqrt(value_name), fpcr, 'N); + FPProcessDenorm(fptype, 'N, fpcr) + }; + return(result) +} + +val FPSub : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +val FPSub__1 : forall 'N ('fpexc : Bool), + 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function FPSub (op1, op2, fpcr) = { + let fpexc : bool = true; + return(FPSub__1(op1, op2, fpcr, fpexc)) +} + +function FPSub__1 (op1, op2, fpcr, fpexc) = { + done : bool = undefined; + inf1 : bool = undefined; + inf2 : bool = undefined; + result : bits('N) = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + let rounding : FPRounding = FPRoundingMode(fpcr); + (type1, sign1, value1_name) = FPUnpack__1(op1, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2, fpcr, fpexc); + (done, result) = FPProcessNaNs__1(type1, type2, op1, op2, fpcr, fpexc); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if (inf1 & inf2) & sign1 == sign2 then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if inf1 & sign1 == 0b0 | inf2 & sign2 == 0b1 then { + result = FPInfinity(0b0, 'N) + } else if inf1 & sign1 == 0b1 | inf2 & sign2 == 0b0 then { + result = FPInfinity(0b1, 'N) + } else if (zero1 & zero2) & sign1 == not_vec(sign2) then { + result = FPZero(sign1, 'N) + } else { + let result_value : real = value1_name - value2_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 'N) + } else { + result = FPRound__2(result_value, fpcr, rounding, fpexc, 'N) + } + }; + if fpexc then { + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + () + }; + return(result) +} + +val FPSub_ZA : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPSub_ZA (op1, op2, fpcr_in) = { + fpcr : FPCRType = fpcr_in; + let fpexc : bool = false; + fpcr[DN] = 0b1; + return(FPSub__1(op1, op2, fpcr, fpexc)) +} + +val FPThree : forall 'N, 'N in {16, 32, 64}. (bits(1), int('N)) -> bits('N) + +function FPThree (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits(1 + ('E - 1)) = 0b1 @ Zeros(E - 1); + let frac : bits(1 + ('F - 1)) = 0b1 @ Zeros(F - 1); + let result : bits(1 + (1 + ('E - 1)) + (1 + ('F - 1))) = (sign @ exp) @ frac; + return(result) +} + +val FPToFixed : forall 'M 'N 'fbits ('is_unsigned : Bool), + ('N in {16, 32, 64} & 'M in {16, 32, 64}). + (bits('N), int('fbits), bool('is_unsigned), FPCRType, FPRounding, int('M)) -> bits('M) + +function FPToFixed (op, fbits, is_unsigned, fpcr, rounding, M) = { + fptype : FPType = undefined; + overflow : bool = undefined; + result : bits('M) = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + assert(M == 16 | M == 32 | M == 64); + assert(fbits >= 0); + assert(rounding != FPRounding_ODD); + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + (fptype, sign, value_name) = FPUnpack__1(op, fpcr, fpexc); + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + let value_name : real = value_name * 2.0 ^ fbits; + int_result : int = RoundDown(value_name); + let error : real = value_name - Real(int_result); + round_up : bool = undefined; + match rounding { + FPRounding_TIEEVEN => { + round_up = error > 0.5 | error == 0.5 & [int_result[0]] == 0b1 + }, + FPRounding_POSINF => { + round_up = error != 0.0 + }, + FPRounding_NEGINF => { + round_up = false + }, + FPRounding_ZERO => { + round_up = error != 0.0 & int_result < 0 + }, + FPRounding_TIEAWAY => { + round_up = error > 0.5 | error == 0.5 & int_result >= 0 + }, + _ => () + }; + if round_up then { + int_result = int_result + 1 + }; + let 'int_result = int_result; + (result, overflow) = SatQ(int_result, M, is_unsigned); + if overflow then { + FPProcessException(FPExc_InvalidOp, fpcr) + } else if error != 0.0 then { + FPProcessException(FPExc_Inexact, fpcr) + } else (); + return(result) +} + +val FPToFixedJS : forall ('Is64 : Bool) 'M 'N, + ('M == 64 & 'N == 32). + (bits('M), FPCRType, bool('Is64), int('N)) -> (bits('N), bits(1)) + +function FPToFixedJS (op, fpcr, Is64, N) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('M == 64 & N == 32); + let fpexc_idenorm : bool = not_bool((HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1); + (fptype, sign, value_name) = FPUnpack__1(op, fpcr, fpexc_idenorm); + z : bits(1) = 0b1; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + FPProcessException(FPExc_InvalidOp, fpcr); + z = 0b0 + }; + int_result : int = RoundDown(value_name); + let error : real = value_name - Real(int_result); + let round_it_up : bool = error != 0.0 & int_result < 0; + if round_it_up then { + int_result = int_result + 1 + }; + let 'int_result = int_result; + result : int = undefined; + if int_result < 0 then { + result = int_result - pow2(32) * RoundUp(Real(int_result) / Real(2 ^ 32)) + } else { + result = int_result - pow2(32) * RoundDown(Real(int_result) / Real(2 ^ 32)) + }; + if int_result < negate(2 ^ 31) | int_result > pow2(31) - 1 then { + FPProcessException(FPExc_InvalidOp, fpcr); + z = 0b0 + } else if error != 0.0 then { + FPProcessException(FPExc_Inexact, fpcr); + z = 0b0 + } else if sign == 0b1 & value_name == 0.0 then { + z = 0b0 + } else if (sign == 0b0 & value_name == 0.0) & not_bool(IsZero(op[51 .. 0])) then { + z = 0b0 + } else (); + if fptype == FPType_Infinity then { + result = 0 + }; + let 'result = result; + return((result[N - 1 .. 0], z)) +} + +val VFPExpandImm : forall 'N, 'N in {16, 32, 64}. (bits(8), int('N)) -> bits('N) + +function VFPExpandImm (imm8, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - E - 1; + let sign : bits(1) = [imm8[7]]; + let exp : bits(1 + ('E - 3) + 2) = (not_vec([imm8[6]]) @ Replicate([imm8[6]], E - 3)) @ imm8[5 .. 4]; + let frac : bits(4 + ('F - 4)) = imm8[3 .. 0] @ Zeros(F - 4); + let result : bits(1 + (1 + ('E - 3) + 2) + (4 + ('F - 4))) = (sign @ exp) @ frac; + return(result) +} + +val SPSR_read : forall 'N, 'N >= 0. implicit('N) -> bits('N) + +function SPSR_read N = { + result : bits('N) = undefined; + if UsingAArch32() then { + assert(N == 32); + match PSTATE.M { + ? if ? == M32_FIQ => { + result = SPSR_fiq.bits[N - 1 .. 0] + }, + ? if ? == M32_IRQ => { + result = SPSR_irq.bits[N - 1 .. 0] + }, + ? if ? == M32_Svc => { + result = SPSR_svc_read().bits[N - 1 .. 0] + }, + ? if ? == M32_Monitor => { + result = SPSR_mon.bits[N - 1 .. 0] + }, + ? if ? == M32_Abort => { + result = SPSR_abt.bits[N - 1 .. 0] + }, + ? if ? == M32_Hyp => { + result = SPSR_hyp_read().bits[N - 1 .. 0] + }, + ? if ? == M32_Undef => { + result = SPSR_und.bits[N - 1 .. 0] + }, + _ => { + Unreachable() + } + } + } else { + assert(N == 64); + match PSTATE.EL { + ? if ? == EL1 => { + result = SPSR_EL1.bits[N - 1 .. 0] + }, + ? if ? == EL2 => { + result = SPSR_EL2.bits[N - 1 .. 0] + }, + ? if ? == EL3 => { + result = SPSR_EL3.bits[N - 1 .. 0] + }, + _ => { + Unreachable() + } + } + }; + return(result) +} + +val BranchToAddr : forall 'N, 'N >= 0. (bits('N), BranchType) -> unit + +function BranchToAddr (target, branch_type) = { + Hint_Branch(branch_type); + if 'N == 32 then { + assert(UsingAArch32()); + sail_branch_announce(64, ZeroExtend(64, target)); + _PC = ZeroExtend(target, 64) + } else { + assert('N == 64 & not_bool(UsingAArch32())); + sail_branch_announce(64, target[63 .. 0]); + _PC = target[63 .. 0] + }; + __BranchTaken = true; + return() +} + +val NextInstrAddr : forall 'N, 'N >= 0. int('N) -> bits('N) + +val ResetExternalDebugRegisters : forall ('cold_reset : Bool). + bool('cold_reset) -> unit + +val IsFault : AddressDescriptor -> bool + +val IsFault__1 : Fault -> bool + +val IsFault__2 : PhysMemRetStatus -> bool + +function IsFault addrdesc = { + return(addrdesc.fault.statuscode != Fault_None) +} + +function IsFault__1 fault = { + return(fault != Fault_None) +} + +function IsFault__2 retstatus = { + return(retstatus.statuscode != Fault_None) +} + +bitfield CNTHP_CTL_EL2_Type : bits(64) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register CNTHP_CTL_EL2 : CNTHP_CTL_EL2_Type + +bitfield CNTHP_CTL_Type : bits(32) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register _CNTHP_CTL : CNTHP_CTL_Type + +val CNTHP_CTL_read : unit -> CNTHP_CTL_Type + +function CNTHP_CTL_read () = { + r : CNTHP_CTL_Type = _CNTHP_CTL; + r.bits[31 .. 0] = Slice(CNTHP_CTL_EL2.bits, 0, 32); + return(r) +} + +val CNTHP_CTL_write : CNTHP_CTL_Type -> unit + +function CNTHP_CTL_write value_name = { + let r : CNTHP_CTL_Type = value_name; + CNTHP_CTL_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTHP_CTL = r; + return() +} + +bitfield CNTHP_CVAL_EL2_Type : bits(64) = {CompareValue : 63..0} + +register CNTHP_CVAL_EL2 : CNTHP_CVAL_EL2_Type + +bitfield CNTHP_CVAL_Type : bits(64) = {CompareValue : 63..0} + +register _CNTHP_CVAL : CNTHP_CVAL_Type + +val CNTHP_CVAL_read : unit -> CNTHP_CVAL_Type + +function CNTHP_CVAL_read () = { + r : CNTHP_CVAL_Type = _CNTHP_CVAL; + r.bits[63 .. 0] = Slice(CNTHP_CVAL_EL2.bits, 0, 64); + return(r) +} + +bitfield CNTP_CTL_EL0_Type : bits(64) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register CNTP_CTL_EL0 : CNTP_CTL_EL0_Type + +bitfield CNTP_CTL_Type : bits(32) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register _CNTP_CTL_NS : CNTP_CTL_Type + +val CNTP_CTL_NS_read : unit -> CNTP_CTL_Type + +function CNTP_CTL_NS_read () = { + r : CNTP_CTL_Type = _CNTP_CTL_NS; + r.bits[31 .. 0] = Slice(CNTP_CTL_EL0.bits, 0, 32); + return(r) +} + +register CNTP_CTL_S : CNTP_CTL_Type + +val CNTP_CTL_read : unit -> CNTP_CTL_Type + +function CNTP_CTL_read () = { + r : CNTP_CTL_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = CNTP_CTL_S + } else { + r = CNTP_CTL_NS_read() + }; + return(r) +} + +val CNTP_CTL_NS_write : CNTP_CTL_Type -> unit + +function CNTP_CTL_NS_write value_name = { + let r : CNTP_CTL_Type = value_name; + CNTP_CTL_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTP_CTL_NS = r; + return() +} + +val CNTP_CTL_write : CNTP_CTL_Type -> unit + +function CNTP_CTL_write value_name = { + let r : CNTP_CTL_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + CNTP_CTL_S = r + } else { + CNTP_CTL_NS_write() = r + }; + return() +} + +bitfield CNTP_CVAL_EL0_Type : bits(64) = {CompareValue : 63..0} + +register CNTP_CVAL_EL0 : CNTP_CVAL_EL0_Type + +bitfield CNTP_CVAL_Type : bits(64) = {CompareValue : 63..0} + +register _CNTP_CVAL_NS : CNTP_CVAL_Type + +val CNTP_CVAL_NS_read : unit -> CNTP_CVAL_Type + +function CNTP_CVAL_NS_read () = { + r : CNTP_CVAL_Type = _CNTP_CVAL_NS; + r.bits[63 .. 0] = Slice(CNTP_CVAL_EL0.bits, 0, 64); + return(r) +} + +register CNTP_CVAL_S : CNTP_CVAL_Type + +val CNTP_CVAL_read : unit -> CNTP_CVAL_Type + +function CNTP_CVAL_read () = { + r : CNTP_CVAL_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = CNTP_CVAL_S + } else { + r = CNTP_CVAL_NS_read() + }; + return(r) +} + +bitfield CNTV_CTL_EL0_Type : bits(64) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register CNTV_CTL_EL0 : CNTV_CTL_EL0_Type + +bitfield CNTV_CVAL_EL0_Type : bits(64) = {CompareValue : 63..0} + +register CNTV_CVAL_EL0 : CNTV_CVAL_EL0_Type + +val IsTimerConditionMet : (bits(64), bits(64), bits(1), InterruptID) -> bool + +function IsTimerConditionMet (offset, compare_value, imask, intid) = { + let condition_met : bool = UInt(PhysicalCountInt() - offset) - UInt(compare_value) >= 0; + let level : Signal = if condition_met & imask == 0b0 then Signal_High else + Signal_Low; + SetInterruptRequestLevel(intid, level); + return(condition_met) +} + +val AArch32_CheckTimerConditions : unit -> unit + +function AArch32_CheckTimerConditions () = { + status : bool = undefined; + let offset : bits(64) = Zeros(64); + assert(not_bool(HaveAArch64())); + if HaveEL(EL3) then { + if CNTP_CTL_S[ENABLE] == 0b1 then { + status = IsTimerConditionMet(offset, CNTP_CVAL_S.bits, CNTP_CTL_S[IMASK], InterruptID_CNTPS); + CNTP_CTL_S[ISTATUS] = if status then 0b1 else 0b0 + }; + if CNTP_CTL_NS_read()[ENABLE] == 0b1 then { + status = IsTimerConditionMet(offset, CNTP_CVAL_NS_read().bits, CNTP_CTL_NS_read()[IMASK], InterruptID_CNTP); + CNTP_CTL_NS_write() = [CNTP_CTL_NS_read() with ISTATUS = if status then + 0b1 + else + 0b0] + }; + () + } else { + if CNTP_CTL_read()[ENABLE] == 0b1 then { + status = IsTimerConditionMet(offset, CNTP_CVAL_read().bits, CNTP_CTL_read()[IMASK], InterruptID_CNTP); + CNTP_CTL_write() = [CNTP_CTL_read() with ISTATUS = if status then + 0b1 + else + 0b0] + }; + () + }; + if HaveEL(EL2) & CNTHP_CTL_read()[ENABLE] == 0b1 then { + status = IsTimerConditionMet(offset, CNTHP_CVAL_read().bits, CNTHP_CTL_read()[IMASK], InterruptID_CNTHP); + CNTHP_CTL_write() = [CNTHP_CTL_read() with ISTATUS = if status then 0b1 + else + 0b0] + }; + if CNTV_CTL_EL0[ENABLE] == 0b1 then { + let status : bool = IsTimerConditionMet(CNTVOFF_EL2, CNTV_CVAL_EL0.bits, CNTV_CTL_EL0[IMASK], InterruptID_CNTV); + CNTV_CTL_EL0[ISTATUS] = if status then 0b1 else 0b0 + }; + return() +} + +bitfield CNTHPS_CTL_EL2_Type : bits(64) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register CNTHPS_CTL_EL2 : CNTHPS_CTL_EL2_Type + +bitfield CNTHPS_CVAL_EL2_Type : bits(64) = {CompareValue : 63..0} + +register CNTHPS_CVAL_EL2 : CNTHPS_CVAL_EL2_Type + +bitfield CNTHVS_CTL_EL2_Type : bits(64) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register CNTHVS_CTL_EL2 : CNTHVS_CTL_EL2_Type + +bitfield CNTHVS_CVAL_EL2_Type : bits(64) = {CompareValue : 63..0} + +register CNTHVS_CVAL_EL2 : CNTHVS_CVAL_EL2_Type + +bitfield CNTHV_CTL_EL2_Type : bits(64) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register CNTHV_CTL_EL2 : CNTHV_CTL_EL2_Type + +bitfield CNTHV_CVAL_EL2_Type : bits(64) = {CompareValue : 63..0} + +register CNTHV_CVAL_EL2 : CNTHV_CVAL_EL2_Type + +bitfield CNTPS_CTL_EL1_Type : bits(64) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register CNTPS_CTL_EL1 : CNTPS_CTL_EL1_Type + +bitfield CNTPS_CVAL_EL1_Type : bits(64) = {CompareValue : 63..0} + +register CNTPS_CVAL_EL1 : CNTPS_CVAL_EL1_Type + +val AArch64_CheckTimerConditions : unit -> unit + +function AArch64_CheckTimerConditions () = { + status : bool = undefined; + offset : bits(64) = undefined; + imask : bits(1) = undefined; + let ss : SecurityState = CurrentSecurityState(); + ecv : bool = false; + if HaveECVExt() then { + ecv = (CNTHCTL_EL2[ECV] == 0b1 & SCR_EL3[ECVEn] == 0b1) & EL2Enabled() + }; + if ecv then { + offset = CNTPOFF_EL2 + } else { + offset = Zeros(64) + }; + if CNTP_CTL_EL0[ENABLE] == 0b1 then { + imask = CNTP_CTL_EL0[IMASK]; + if (HaveRME() & (ss == SS_Root | ss == SS_Realm)) & CNTHCTL_EL2[CNTPMASK] == 0b1 then { + imask = 0b1 + }; + status = IsTimerConditionMet(offset, CNTP_CVAL_EL0.bits, imask, InterruptID_CNTP); + CNTP_CTL_EL0[ISTATUS] = if status then 0b1 else 0b0 + }; + if (HaveEL(EL3) | HaveEL(EL2) & not_bool(HaveSecureEL2Ext())) & CNTHP_CTL_EL2[ENABLE] == 0b1 then { + status = IsTimerConditionMet(Zeros(64), CNTHP_CVAL_EL2.bits, CNTHP_CTL_EL2[IMASK], InterruptID_CNTHP); + CNTHP_CTL_EL2[ISTATUS] = if status then 0b1 else 0b0 + }; + if (HaveEL(EL2) & HaveSecureEL2Ext()) & CNTHPS_CTL_EL2[ENABLE] == 0b1 then { + status = IsTimerConditionMet(Zeros(64), CNTHPS_CVAL_EL2.bits, CNTHPS_CTL_EL2[IMASK], InterruptID_CNTHPS); + CNTHPS_CTL_EL2[ISTATUS] = if status then 0b1 else 0b0 + }; + if CNTPS_CTL_EL1[ENABLE] == 0b1 then { + status = IsTimerConditionMet(offset, CNTPS_CVAL_EL1.bits, CNTPS_CTL_EL1[IMASK], InterruptID_CNTPS); + CNTPS_CTL_EL1[ISTATUS] = if status then 0b1 else 0b0 + }; + if CNTV_CTL_EL0[ENABLE] == 0b1 then { + imask : bits(1) = CNTV_CTL_EL0[IMASK]; + if (HaveRME() & (ss == SS_Root | ss == SS_Realm)) & CNTHCTL_EL2[CNTVMASK] == 0b1 then { + imask = 0b1 + }; + status = IsTimerConditionMet(CNTVOFF_EL2, CNTV_CVAL_EL0.bits, imask, InterruptID_CNTV); + CNTV_CTL_EL0[ISTATUS] = if status then 0b1 else 0b0 + }; + if (HaveVirtHostExt() & (HaveEL(EL3) | not_bool(HaveSecureEL2Ext()))) & CNTHV_CTL_EL2[ENABLE] == 0b1 then { + status = IsTimerConditionMet(Zeros(64), CNTHV_CVAL_EL2.bits, CNTHV_CTL_EL2[IMASK], InterruptID_CNTHV); + CNTHV_CTL_EL2[ISTATUS] = if status then 0b1 else 0b0 + }; + if (HaveSecureEL2Ext() & HaveVirtHostExt()) & CNTHVS_CTL_EL2[ENABLE] == 0b1 then { + let status : bool = IsTimerConditionMet(Zeros(64), CNTHVS_CVAL_EL2.bits, CNTHVS_CTL_EL2[IMASK], InterruptID_CNTHVS); + CNTHVS_CTL_EL2[ISTATUS] = if status then 0b1 else 0b0 + }; + return() +} + +bitfield CNTCR_Type : bits(32) = + {FCREQ : 17..8, SCEN : 2..2, HDBG : 1..1, EN : 0..0} + +register CNTCR : CNTCR_Type + +bitfield CNTSCR_Type : bits(32) = {ScaleVal : 31..0} + +register CNTSCR : CNTSCR_Type + +val HaveCNTSCExt : unit -> bool + +function HaveCNTSCExt () = { + return(IsFeatureImplemented(FEAT_CNTSC)) +} + +val SetEventRegister : unit -> unit + +function SetEventRegister () = { + EventRegister = 0b1; + __WakeupRequest(); + return() +} + +val TestEventCNTP : (bits(64), bits(64)) -> unit + +function TestEventCNTP (prev_physical_count, current_physical_count) = { + n : int = undefined; + offset : bits(64) = undefined; + previousbit : bits(1) = undefined; + samplebit : bits(1) = undefined; + if CNTHCTL_EL2[EVNTEN] == 0b1 then { + n : int = UInt(CNTHCTL_EL2[EVNTI]); + if HaveECVExt() & CNTHCTL_EL2[EVNTIS] == 0b1 then { + n = n + 8 + }; + let 'n = n; + ecv : bool = false; + if HaveECVExt() then { + let ecv : bool = (EL2Enabled() & CNTHCTL_EL2[ECV] == 0b1) & SCR_EL3[ECVEn] == 0b1; + offset = if ecv then CNTPOFF_EL2 else Zeros(64) + }; + assert(constraint((0 <= 'n & 'n < 64))); + let samplebit : bits(1) = [(current_physical_count - offset)[n]]; + let previousbit : bits(1) = [(prev_physical_count - offset)[n]]; + if CNTHCTL_EL2[EVNTDIR] == 0b0 then { + if previousbit == 0b0 & samplebit == 0b1 then { + SetEventRegister() + }; + () + } else { + if previousbit == 0b1 & samplebit == 0b0 then { + SetEventRegister() + }; + () + } + }; + let n = n; + return() +} + +bitfield CNTKCTL_EL1_Type : bits(64) = + { + EVNTIS : 17..17, + EL0PTEN : 9..9, + EL0VTEN : 8..8, + EVNTI : 7..4, + EVNTDIR : 3..3, + EVNTEN : 2..2, + EL0VCTEN : 1..1, + EL0PCTEN : 0..0 + } + +register CNTKCTL_EL1 : CNTKCTL_EL1_Type + +val TestEventCNTV : (bits(64), bits(64)) -> unit + +function TestEventCNTV (prev_physical_count, current_physical_count) = { + n : int = undefined; + offset : bits(64) = undefined; + previousbit : bits(1) = undefined; + samplebit : bits(1) = undefined; + if not_bool(HaveVirtHostExt() & (HCR_EL2[E2H] @ HCR_EL2[TGE]) == 0b11) & CNTKCTL_EL1[EVNTEN] == 0b1 then { + n : int = UInt(CNTKCTL_EL1[EVNTI]); + if HaveECVExt() & CNTKCTL_EL1[EVNTIS] == 0b1 then { + n = n + 8 + }; + let 'n = n; + if HaveEL(EL2) & (not_bool(EL2Enabled()) | (HCR_EL2[E2H] @ HCR_EL2[TGE]) != 0b11) then { + offset = CNTVOFF_EL2 + } else { + offset = Zeros(64) + }; + assert(constraint((0 <= 'n & 'n < 64))); + let samplebit : bits(1) = [(current_physical_count - offset)[n]]; + let previousbit : bits(1) = [(prev_physical_count - offset)[n]]; + if CNTKCTL_EL1[EVNTDIR] == 0b0 then { + if previousbit == 0b0 & samplebit == 0b1 then { + SetEventRegister() + }; + () + } else { + if previousbit == 0b1 & samplebit == 0b0 then { + SetEventRegister() + }; + () + } + }; + let n = n; + return() +} + +val GenericCounterTick : unit -> unit + +function GenericCounterTick () = { + if CNTCR[EN] == 0b0 then { + if not_bool(HaveAArch64()) then { + AArch32_CheckTimerConditions() + } else { + AArch64_CheckTimerConditions() + }; + return() + }; + let prev_physical_count : bits(64) = PhysicalCountInt(); + if HaveCNTSCExt() & CNTCR[SCEN] == 0b1 then { + PhysicalCount = PhysicalCount + ZeroExtend(CNTSCR.bits, 88) + } else { + PhysicalCount[87 .. 24] = PhysicalCount[87 .. 24] + 1 + }; + if not_bool(HaveAArch64()) then { + AArch32_CheckTimerConditions() + } else { + AArch64_CheckTimerConditions() + }; + TestEventCNTP(prev_physical_count, PhysicalCountInt()); + TestEventCNTV(prev_physical_count, PhysicalCountInt()); + return() +} + +val HaveMPAMExt : unit -> bool + +function HaveMPAMExt () = { + return(IsFeatureImplemented(FEAT_MPAM)) +} + +val Have16bitVMID : unit -> bool + +function Have16bitVMID () = { + return(IsFeatureImplemented(FEAT_VMID16)) +} + +val AArch64_HaveHPDExt : unit -> bool + +function AArch64_HaveHPDExt () = { + return(IsFeatureImplemented(FEAT_HPDS)) +} + +val HaveQRDMLAHExt : unit -> bool + +function HaveQRDMLAHExt () = { + return(IsFeatureImplemented(FEAT_RDM)) +} + +val HaveCommonNotPrivateTransExt : unit -> bool + +function HaveCommonNotPrivateTransExt () = { + return(IsFeatureImplemented(FEAT_TTCNP)) +} + +val HaveExtendedExecuteNeverExt : unit -> bool + +function HaveExtendedExecuteNeverExt () = { + return(IsFeatureImplemented(FEAT_XNX)) +} + +val AArch32_HaveHPDExt : unit -> bool + +function AArch32_HaveHPDExt () = { + return(IsFeatureImplemented(FEAT_AA32HPD)) +} + +val Have52BitVAExt : unit -> bool + +function Have52BitVAExt () = { + return(IsFeatureImplemented(FEAT_LVA)) +} + +val Have52BitPAExt : unit -> bool + +function Have52BitPAExt () = { + return(IsFeatureImplemented(FEAT_LPA)) +} + +val HaveV82Debug : unit -> bool + +function HaveV82Debug () = { + return(IsFeatureImplemented(FEAT_Debugv8p2)) +} + +val HaveTrapLoadStoreMultipleDeviceExt : unit -> bool + +function HaveTrapLoadStoreMultipleDeviceExt () = { + return(IsFeatureImplemented(FEAT_LSMAOC)) +} + +val HaveFJCVTZSExt : unit -> bool + +function HaveFJCVTZSExt () = { + return(IsFeatureImplemented(FEAT_JSCVT)) +} + +val HaveFCADDExt : unit -> bool + +function HaveFCADDExt () = { + return(IsFeatureImplemented(FEAT_FCMA)) +} + +val HaveDOTPExt : unit -> bool + +function HaveDOTPExt () = { + return(IsFeatureImplemented(FEAT_DotProd)) +} + +val HaveSmallTranslationTableExt : unit -> bool + +function HaveSmallTranslationTableExt () = { + return(IsFeatureImplemented(FEAT_TTST)) +} + +val HaveLSE2Ext : unit -> bool + +function HaveLSE2Ext () = { + return(IsFeatureImplemented(FEAT_LSE2)) +} + +val HaveFP16MulNoRoundingToFP32Ext : unit -> bool + +function HaveFP16MulNoRoundingToFP32Ext () = { + return(IsFeatureImplemented(FEAT_FHM)) +} + +val HaveFlagManipulateExt : unit -> bool + +function HaveFlagManipulateExt () = { + return(IsFeatureImplemented(FEAT_FlagM)) +} + +val HaveFlagFormatExt : unit -> bool + +function HaveFlagFormatExt () = { + return(IsFeatureImplemented(FEAT_FlagM2)) +} + +val HaveSelfHostedTrace : unit -> bool + +function HaveSelfHostedTrace () = { + return(IsFeatureImplemented(FEAT_TRF)) +} + +val HaveBlockBBM : unit -> bool + +function HaveBlockBBM () = { + return(IsFeatureImplemented(FEAT_BBM)) +} + +val Havev8p4Debug : unit -> bool + +function Havev8p4Debug () = { + return(IsFeatureImplemented(FEAT_Debugv8p4)) +} + +val HaveStage2MemAttrControl : unit -> bool + +function HaveStage2MemAttrControl () = { + return(IsFeatureImplemented(FEAT_S2FWB)) +} + +val HaveIDSExt : unit -> bool + +function HaveIDSExt () = { + return(IsFeatureImplemented(FEAT_IDST)) +} + +val HaveFrintExt : unit -> bool + +function HaveFrintExt () = { + return(IsFeatureImplemented(FEAT_FRINTTS)) +} + +val HaveE0PDExt : unit -> bool + +function HaveE0PDExt () = { + return(IsFeatureImplemented(FEAT_E0PD)) +} + +val HaveGTGExt : unit -> bool + +function HaveGTGExt () = { + return(IsFeatureImplemented(FEAT_GTG)) +} + +val HaveSBExt : unit -> bool + +function HaveSBExt () = { + return(IsFeatureImplemented(FEAT_SB)) +} + +val HaveMTEAsyncExt : unit -> bool + +function HaveMTEAsyncExt () = { + return(IsFeatureImplemented(FEAT_MTE4)) +} + +val HaveMTEPermExt : unit -> bool + +function HaveMTEPermExt () = { + return(IsFeatureImplemented(FEAT_MTE_PERM)) +} + +val HaveDGHExt : unit -> bool + +function HaveDGHExt () = { + return(IsFeatureImplemented(FEAT_DGH)) +} + +val HaveBF16Ext : unit -> bool + +function HaveBF16Ext () = { + return(IsFeatureImplemented(FEAT_BF16)) +} + +val HaveEBF16 : unit -> bool + +function HaveEBF16 () = { + return(IsFeatureImplemented(FEAT_EBF16)) +} + +val HaveAArch32BF16Ext : unit -> bool + +function HaveAArch32BF16Ext () = { + return(IsFeatureImplemented(FEAT_AA32BF16)) +} + +val HaveFGTExt : unit -> bool + +function HaveFGTExt () = { + return(IsFeatureImplemented(FEAT_FGT)) +} + +val HaveInt8MatMulExt : unit -> bool + +function HaveInt8MatMulExt () = { + return(IsFeatureImplemented(FEAT_I8MM)) +} + +val HaveAArch32Int8MatMulExt : unit -> bool + +function HaveAArch32Int8MatMulExt () = { + return(IsFeatureImplemented(FEAT_AA32I8MM)) +} + +val HavePMUv3p4 : unit -> bool + +function HavePMUv3p4 () = { + return(IsFeatureImplemented(FEAT_PMUv3p4)) +} + +val HaveDoPD : unit -> bool + +function HaveDoPD () = { + return(IsFeatureImplemented(FEAT_DoPD)) +} + +val Have56BitVAExt : unit -> bool + +function Have56BitVAExt () = { + return(IsFeatureImplemented(FEAT_LVA3)) +} + +val Have128BitDescriptorExt : unit -> bool + +function Have128BitDescriptorExt () = { + return(IsFeatureImplemented(FEAT_D128)) +} + +val HaveAIEExt : unit -> bool + +function HaveAIEExt () = { + return(IsFeatureImplemented(FEAT_AIE)) +} + +val HaveFeatTCR2 : unit -> bool + +function HaveFeatTCR2 () = { + return(IsFeatureImplemented(FEAT_TCR2)) +} + +val HavePAN3Ext : unit -> bool + +function HavePAN3Ext () = { + return(IsFeatureImplemented(FEAT_PAN3)) +} + +val HaveMTEAsymFaultExt : unit -> bool + +function HaveMTEAsymFaultExt () = { + return(IsFeatureImplemented(FEAT_MTE4)) +} + +val HaveFeatLS64_V : unit -> bool + +function HaveFeatLS64_V () = { + return(IsFeatureImplemented(FEAT_LS64_V)) +} + +val HaveFeatLS64_ACCDATA : unit -> bool + +function HaveFeatLS64_ACCDATA () = { + return(IsFeatureImplemented(FEAT_LS64_ACCDATA)) +} + +val HaveFeatXS : unit -> bool + +function HaveFeatXS () = { + return(IsFeatureImplemented(FEAT_XS)) +} + +val HaveFeatEBEP : unit -> bool + +function HaveFeatEBEP () = { + return(IsFeatureImplemented(FEAT_EBEP)) +} + +val HaveStatisticalProfilingFDS : unit -> bool + +function HaveStatisticalProfilingFDS () = { + return(IsFeatureImplemented(FEAT_SPE_FDS)) +} + +val HaveFeatHBC : unit -> bool + +function HaveFeatHBC () = { + return(IsFeatureImplemented(FEAT_HBC)) +} + +val HaveFeatMOPS : unit -> bool + +function HaveFeatMOPS () = { + return(IsFeatureImplemented(FEAT_MOPS)) +} + +val HaveFeatTIDCP1 : unit -> bool + +function HaveFeatTIDCP1 () = { + return(IsFeatureImplemented(FEAT_TIDCP1)) +} + +val HaveFeatCMOW : unit -> bool + +function HaveFeatCMOW () = { + return(IsFeatureImplemented(FEAT_CMOW)) +} + +val HaveMTECanonicalTagCheckingExt : unit -> bool + +function HaveMTECanonicalTagCheckingExt () = { + return(IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) +} + +val HaveLRCPC3Ext : unit -> bool + +function HaveLRCPC3Ext () = { + return(IsFeatureImplemented(FEAT_LRCPC3)) +} + +val HaveMTEStoreOnlyExt : unit -> bool + +function HaveMTEStoreOnlyExt () = { + return(IsFeatureImplemented(FEAT_MTE_STORE_ONLY)) +} + +val HaveCSSC : unit -> bool + +function HaveCSSC () = { + return(IsFeatureImplemented(FEAT_CSSC)) +} + +val HaveS1PIExt : unit -> bool + +function HaveS1PIExt () = { + return(IsFeatureImplemented(FEAT_S1PIE)) +} + +val HaveS1POExt : unit -> bool + +function HaveS1POExt () = { + return(IsFeatureImplemented(FEAT_S1POE)) +} + +val HaveS2PIExt : unit -> bool + +function HaveS2PIExt () = { + return(IsFeatureImplemented(FEAT_S2PIE)) +} + +val HaveS2POExt : unit -> bool + +function HaveS2POExt () = { + return(IsFeatureImplemented(FEAT_S2POE)) +} + +val HaveFeatCLRBHB : unit -> bool + +function HaveFeatCLRBHB () = { + return(IsFeatureImplemented(FEAT_CLRBHB)) +} + +val HaveTHExt : unit -> bool + +function HaveTHExt () = { + return(IsFeatureImplemented(FEAT_THE)) +} + +val HaveLSE128 : unit -> bool + +function HaveLSE128 () = { + return(IsFeatureImplemented(FEAT_LSE128)) +} + +val HaveSysReg128 : unit -> bool + +function HaveSysReg128 () = { + return(IsFeatureImplemented(FEAT_SYSREG128)) +} + +val HaveSysInstr128 : unit -> bool + +function HaveSysInstr128 () = { + return(IsFeatureImplemented(FEAT_SYSINSTR128)) +} + +val IsG1ActivityMonitorImplemented : forall 'i. int('i) -> bool + +val IsG1ActivityMonitorOffsetImplemented : forall 'i. int('i) -> bool + +val HaveRASv2Ext : unit -> bool + +function HaveRASv2Ext () = { + return(IsFeatureImplemented(FEAT_RASv2)) +} + +val HaveFeatMEC : unit -> bool + +function HaveFeatMEC () = { + return(IsFeatureImplemented(FEAT_MEC)) +} + +val HaveAccessFlagUpdateForTableExt : unit -> bool + +function HaveAccessFlagUpdateForTableExt () = { + return(IsFeatureImplemented(FEAT_HAFT)) +} + +val HaveFeatABLE : unit -> bool + +function HaveFeatABLE () = { + return(IsFeatureImplemented(FEAT_ABLE)) +} + +val PAREncodeShareability : MemoryAttributes -> bits(2) + +function PAREncodeShareability memattrs = { + if memattrs.memtype == MemType_Device | memattrs.inner.attrs == MemAttr_NC & memattrs.outer.attrs == MemAttr_NC then { + return(0b10) + }; + match memattrs.shareability { + Shareability_NSH => { + return(0b00) + }, + Shareability_ISH => { + return(0b11) + }, + Shareability_OSH => { + return(0b10) + }, + _ => { + return(undefined : bits(2)) + } + } +} + +val EncodePARAttrs : MemoryAttributes -> bits(8) + +function EncodePARAttrs memattrs = { + result : bits(8) = undefined; + if HaveMTEExt() & memattrs.tags == MemTag_AllocationTagged then { + if HaveMTEPermExt() & memattrs.notagaccess then { + result[7 .. 0] = 0b11100000 + } else { + result[7 .. 0] = 0b11110000 + }; + return(result) + }; + if memattrs.memtype == MemType_Device then { + result[7 .. 4] = 0b0000; + match memattrs.device { + DeviceType_nGnRnE => { + result[3 .. 0] = 0b0000 + }, + DeviceType_nGnRE => { + result[3 .. 0] = 0b0100 + }, + DeviceType_nGRE => { + result[3 .. 0] = 0b1000 + }, + DeviceType_GRE => { + result[3 .. 0] = 0b1100 + }, + _ => { + Unreachable() + } + }; + result[0] = Bit(not_vec(memattrs.xs)) + } else { + if memattrs.xs == 0b0 then { + if ((memattrs.outer.attrs == MemAttr_WT & memattrs.inner.attrs == MemAttr_WT) & not_bool(memattrs.outer.transient)) & memattrs.outer.hints == MemHint_RA then { + return(0b10100000) + } else if memattrs.outer.attrs == MemAttr_NC & memattrs.inner.attrs == MemAttr_NC then { + return(0b01000000) + } else () + }; + if memattrs.outer.attrs == MemAttr_WT then { + result[7 .. 6] = if memattrs.outer.transient then 0b00 else 0b10; + result[5 .. 4] = memattrs.outer.hints + } else if memattrs.outer.attrs == MemAttr_WB then { + result[7 .. 6] = if memattrs.outer.transient then 0b01 else 0b11; + result[5 .. 4] = memattrs.outer.hints + } else { + result[7 .. 4] = 0b0100 + }; + if memattrs.inner.attrs == MemAttr_WT then { + result[3 .. 2] = if memattrs.inner.transient then 0b00 else 0b10; + result[1 .. 0] = memattrs.inner.hints + } else if memattrs.inner.attrs == MemAttr_WB then { + result[3 .. 2] = if memattrs.inner.transient then 0b01 else 0b11; + result[1 .. 0] = memattrs.inner.hints + } else { + result[3 .. 0] = 0b0100 + } + }; + return(result) +} + +val ReportedPARAttrs : bits(8) -> bits(8) + +val ReportedPARShareability : bits(2) -> bits(2) + +val DecodeShareability : bits(2) -> Shareability + +function DecodeShareability sh = { + match sh { + 0b10 => { + return(Shareability_OSH) + }, + 0b11 => { + return(Shareability_ISH) + }, + 0b00 => { + return(Shareability_NSH) + }, + _ => { + match ConstrainUnpredictable(Unpredictable_Shareability) { + Constraint_OSH => { + return(Shareability_OSH) + }, + Constraint_ISH => { + return(Shareability_ISH) + }, + Constraint_NSH => { + return(Shareability_NSH) + }, + _ => { + return(undefined : Shareability) + } + } + } + } +} + +val S2CombineS1Shareability : (Shareability, Shareability) -> Shareability + +function S2CombineS1Shareability (s1_shareability, s2_shareability) = { + if s1_shareability == Shareability_OSH | s2_shareability == Shareability_OSH then { + return(Shareability_OSH) + } else if s1_shareability == Shareability_ISH | s2_shareability == Shareability_ISH then { + return(Shareability_ISH) + } else { + return(Shareability_NSH) + } +} + +val EffectiveShareability : MemoryAttributes -> Shareability + +function EffectiveShareability memattrs = { + if memattrs.memtype == MemType_Device | memattrs.inner.attrs == MemAttr_NC & memattrs.outer.attrs == MemAttr_NC then { + return(Shareability_OSH) + } else { + return(memattrs.shareability) + } +} + +val DecodeDevice : bits(2) -> DeviceType + +function DecodeDevice device = { + match device { + 0b00 => { + return(DeviceType_nGnRnE) + }, + 0b01 => { + return(DeviceType_nGnRE) + }, + 0b10 => { + return(DeviceType_nGRE) + }, + 0b11 => { + return(DeviceType_GRE) + }, + _ => { + return(undefined : DeviceType) + } + } +} + +val S2CombineS1Device : (DeviceType, DeviceType) -> DeviceType + +function S2CombineS1Device (s1_device, s2_device) = { + if s1_device == DeviceType_nGnRnE | s2_device == DeviceType_nGnRnE then { + return(DeviceType_nGnRnE) + } else if s1_device == DeviceType_nGnRE | s2_device == DeviceType_nGnRE then { + return(DeviceType_nGnRE) + } else if s1_device == DeviceType_nGRE | s2_device == DeviceType_nGRE then { + return(DeviceType_nGRE) + } else { + return(DeviceType_GRE) + } +} + +val DecodeSDFAttr : bits(2) -> MemAttrHints + +function DecodeSDFAttr rgn = { + sdfattr : MemAttrHints = undefined; + match rgn { + 0b00 => { + sdfattr.attrs = MemAttr_NC + }, + 0b01 => { + sdfattr.attrs = MemAttr_WB; + sdfattr.hints = MemHint_RWA + }, + 0b10 => { + sdfattr.attrs = MemAttr_WT; + sdfattr.hints = MemHint_RA + }, + 0b11 => { + sdfattr.attrs = MemAttr_WB; + sdfattr.hints = MemHint_RA + } + }; + sdfattr.transient = false; + return(sdfattr) +} + +val DecodeLDFAttr : bits(4) -> MemAttrHints + +function DecodeLDFAttr attr = { + ldfattr : MemAttrHints = undefined; + if (match attr { + [_, bitzero, _, _] => true, + _ => false + }) : bool then { + ldfattr.attrs = MemAttr_WT + } else if attr == 0b0100 then { + ldfattr.attrs = MemAttr_NC + } else if (match attr { + [_, bitone, _, _] => true, + _ => false + }) : bool then { + ldfattr.attrs = MemAttr_WB + } else { + Unreachable() + }; + if ldfattr.attrs != MemAttr_NC then { + match attr[1 .. 0] { + 0b00 => { + ldfattr.hints = MemHint_No + }, + 0b01 => { + ldfattr.hints = MemHint_WA + }, + 0b10 => { + ldfattr.hints = MemHint_RA + }, + 0b11 => { + ldfattr.hints = MemHint_RWA + } + } + }; + if ldfattr.attrs != MemAttr_NC & ldfattr.hints != MemHint_No then { + ldfattr.transient = [attr[3]] == 0b0 + }; + return(ldfattr) +} + +val S2DecodeCacheability : bits(2) -> MemAttrHints + +function S2DecodeCacheability attr = { + s2attr : MemAttrHints = undefined; + match attr { + 0b01 => { + s2attr.attrs = MemAttr_NC + }, + 0b10 => { + s2attr.attrs = MemAttr_WT + }, + 0b11 => { + s2attr.attrs = MemAttr_WB + }, + _ => { + match ConstrainUnpredictable(Unpredictable_S2RESMEMATTR) { + Constraint_NC => { + s2attr.attrs = MemAttr_NC + }, + Constraint_WT => { + s2attr.attrs = MemAttr_WT + }, + Constraint_WB => { + s2attr.attrs = MemAttr_WB + }, + _ => () + } + } + }; + s2attr.hints = __UNKNOWN_bits(2); + s2attr.transient = __UNKNOWN_boolean(); + return(s2attr) +} + +val S2CombineS1AttrHints : (MemAttrHints, MemAttrHints) -> MemAttrHints + +function S2CombineS1AttrHints (s1_attrhints, s2_attrhints) = { + attrhints : MemAttrHints = undefined; + if s1_attrhints.attrs == MemAttr_NC | s2_attrhints.attrs == MemAttr_NC then { + attrhints.attrs = MemAttr_NC + } else if s1_attrhints.attrs == MemAttr_WT | s2_attrhints.attrs == MemAttr_WT then { + attrhints.attrs = MemAttr_WT + } else { + attrhints.attrs = MemAttr_WB + }; + if attrhints.attrs != MemAttr_NC then { + attrhints.hints = s1_attrhints.hints; + attrhints.transient = s1_attrhints.transient + }; + return(attrhints) +} + +val WalkMemAttrs : (bits(2), bits(2), bits(2)) -> MemoryAttributes + +function WalkMemAttrs (sh, irgn, orgn) = { + walkmemattrs : MemoryAttributes = undefined; + walkmemattrs.memtype = MemType_Normal; + walkmemattrs.shareability = DecodeShareability(sh); + walkmemattrs.inner = DecodeSDFAttr(irgn); + walkmemattrs.outer = DecodeSDFAttr(orgn); + walkmemattrs.tags = MemTag_Untagged; + if walkmemattrs.inner.attrs == MemAttr_WB & walkmemattrs.outer.attrs == MemAttr_WB then { + walkmemattrs.xs = 0b0 + } else { + walkmemattrs.xs = 0b1 + }; + walkmemattrs.notagaccess = false; + return(walkmemattrs) +} + +val NormalNCMemAttr : unit -> MemoryAttributes + +function NormalNCMemAttr () = { + non_cacheable : MemAttrHints = undefined; + non_cacheable.attrs = MemAttr_NC; + nc_memattrs : MemoryAttributes = undefined; + nc_memattrs.memtype = MemType_Normal; + nc_memattrs.outer = non_cacheable; + nc_memattrs.inner = non_cacheable; + nc_memattrs.shareability = Shareability_OSH; + nc_memattrs.tags = MemTag_Untagged; + nc_memattrs.notagaccess = false; + return(nc_memattrs) +} + +val S1ConstrainUnpredictableRESMAIR : forall ('s1aarch64 : Bool). + (bits(8), bool('s1aarch64)) -> bool + +function S1ConstrainUnpredictableRESMAIR (attr, s1aarch64) = { + match attr { + [bitzero, bitzero, bitzero, bitzero, _, _, bitzero, bitone] => { + return(not_bool(s1aarch64 & HaveFeatXS())) + }, + [bitzero, bitzero, bitzero, bitzero, _, _, _, _] => { + return(attr[1 .. 0] != 0b00) + }, + 0b01000000 => { + return(not_bool(s1aarch64 & HaveFeatXS())) + }, + 0b10100000 => { + return(not_bool(s1aarch64 & HaveFeatXS())) + }, + 0b11110000 => { + return(not_bool(s1aarch64 & HaveMTE2Ext())) + }, + [_, _, _, _, bitzero, bitzero, bitzero, bitzero] => { + return(true) + }, + _ => { + return(false) + } + } +} + +val S1DecodeMemAttrs : forall ('s1aarch64 : Bool). + (bits(8), bits(2), bool('s1aarch64), S1TTWParams) -> MemoryAttributes + +function S1DecodeMemAttrs (attr_in, sh, s1aarch64, walkparams) = { + attr : bits(8) = attr_in; + if S1ConstrainUnpredictableRESMAIR(attr, s1aarch64) then { + let (_, __tup_1 : bits(8)) = ConstrainUnpredictableBits(Unpredictable_RESMAIR, 8); + attr = __tup_1 + }; + memattrs : MemoryAttributes = undefined; + match attr { + [bitzero, bitzero, bitzero, bitzero, _, _, _, _] => { + memattrs.memtype = MemType_Device; + memattrs.device = DecodeDevice(attr[3 .. 2]); + memattrs.xs = if s1aarch64 then not_vec([attr[0]]) else 0b1 + }, + 0b01000000 => { + assert(s1aarch64 & HaveFeatXS()); + memattrs.memtype = MemType_Normal; + memattrs.outer.attrs = MemAttr_NC; + memattrs.inner.attrs = MemAttr_NC; + memattrs.xs = 0b0 + }, + 0b10100000 => { + assert(s1aarch64 & HaveFeatXS()); + memattrs.memtype = MemType_Normal; + memattrs.outer.attrs = MemAttr_WT; + memattrs.outer.hints = MemHint_RA; + memattrs.outer.transient = false; + memattrs.inner.attrs = MemAttr_WT; + memattrs.inner.hints = MemHint_RA; + memattrs.inner.transient = false; + memattrs.xs = 0b0 + }, + 0b11110000 => { + assert(s1aarch64 & HaveMTE2Ext()); + memattrs.memtype = MemType_Normal; + memattrs.outer.attrs = MemAttr_WB; + memattrs.outer.hints = MemHint_RWA; + memattrs.outer.transient = false; + memattrs.inner.attrs = MemAttr_WB; + memattrs.inner.hints = MemHint_RWA; + memattrs.inner.transient = false; + memattrs.xs = 0b0 + }, + _ => { + memattrs.memtype = MemType_Normal; + memattrs.outer = DecodeLDFAttr(attr[7 .. 4]); + memattrs.inner = DecodeLDFAttr(attr[3 .. 0]); + if memattrs.inner.attrs == MemAttr_WB & memattrs.outer.attrs == MemAttr_WB then { + memattrs.xs = 0b0 + } else { + memattrs.xs = 0b1 + } + } + }; + if s1aarch64 & attr == 0b11110000 then { + memattrs.tags = MemTag_AllocationTagged + } else if s1aarch64 & walkparams.mtx == 0b1 then { + memattrs.tags = MemTag_CanonicallyTagged + } else { + memattrs.tags = MemTag_Untagged + }; + memattrs.notagaccess = false; + memattrs.shareability = DecodeShareability(sh); + return(memattrs) +} + +val S2MemTagType : (MemoryAttributes, MemTagType) -> MemTagType + +function S2MemTagType (s2_memattrs, s1_tagtype) = { + if not_bool(HaveMTE2Ext()) then { + return(MemTag_Untagged) + }; + if ((((((s1_tagtype == MemTag_AllocationTagged & s2_memattrs.memtype == MemType_Normal) & s2_memattrs.inner.attrs == MemAttr_WB) & s2_memattrs.inner.hints == MemHint_RWA) & not_bool(s2_memattrs.inner.transient)) & s2_memattrs.outer.attrs == MemAttr_WB) & s2_memattrs.outer.hints == MemHint_RWA) & not_bool(s2_memattrs.outer.transient) then { + return(MemTag_AllocationTagged) + }; + if s1_tagtype != MemTag_AllocationTagged then { + return(s1_tagtype) + }; + return(MemTag_Untagged) +} + +val S2DecodeMemAttrs : forall ('s2aarch64 : Bool). + (bits(4), bits(2), bool('s2aarch64)) -> MemoryAttributes + +function S2DecodeMemAttrs (attr, sh, s2aarch64) = { + memattrs : MemoryAttributes = undefined; + match attr { + [bitzero, bitzero, _, _] => { + memattrs.memtype = MemType_Device; + memattrs.device = DecodeDevice(attr[1 .. 0]) + }, + 0b0100 => { + if s2aarch64 & HaveMTEPermExt() then { + memattrs.memtype = MemType_Normal; + memattrs.outer = S2DecodeCacheability(0b11); + memattrs.inner = S2DecodeCacheability(0b11) + } else { + memattrs.memtype = MemType_Normal; + memattrs.outer = S2DecodeCacheability(attr[3 .. 2]); + memattrs.inner = S2DecodeCacheability(attr[1 .. 0]) + } + }, + _ => { + memattrs.memtype = MemType_Normal; + memattrs.outer = S2DecodeCacheability(attr[3 .. 2]); + memattrs.inner = S2DecodeCacheability(attr[1 .. 0]) + } + }; + memattrs.shareability = DecodeShareability(sh); + if s2aarch64 & HaveMTEPermExt() then { + memattrs.notagaccess = attr == 0b0100 + } else { + memattrs.notagaccess = false + }; + return(memattrs) +} + +val S2CombineS1MemAttrs : forall ('s2aarch64 : Bool). + (MemoryAttributes, MemoryAttributes, bool('s2aarch64)) -> MemoryAttributes + +function S2CombineS1MemAttrs (s1_memattrs, s2_memattrs, s2aarch64) = { + memattrs : MemoryAttributes = undefined; + if s1_memattrs.memtype == MemType_Device & s2_memattrs.memtype == MemType_Device then { + memattrs.memtype = MemType_Device; + memattrs.device = S2CombineS1Device(s1_memattrs.device, s2_memattrs.device) + } else if s1_memattrs.memtype == MemType_Device then { + memattrs = s1_memattrs + } else if s2_memattrs.memtype == MemType_Device then { + memattrs = s2_memattrs + } else { + memattrs.memtype = MemType_Normal; + memattrs.inner = S2CombineS1AttrHints(s1_memattrs.inner, s2_memattrs.inner); + memattrs.outer = S2CombineS1AttrHints(s1_memattrs.outer, s2_memattrs.outer) + }; + memattrs.tags = S2MemTagType(memattrs, s1_memattrs.tags); + if not_bool(HaveMTEPermExt()) then { + memattrs.notagaccess = false + } else { + memattrs.notagaccess = s2_memattrs.notagaccess & s1_memattrs.tags == MemTag_AllocationTagged + }; + memattrs.shareability = S2CombineS1Shareability(s1_memattrs.shareability, s2_memattrs.shareability); + if (memattrs.memtype == MemType_Normal & memattrs.inner.attrs == MemAttr_WB) & memattrs.outer.attrs == MemAttr_WB then { + memattrs.xs = 0b0 + } else if s2aarch64 then { + memattrs.xs = s2_memattrs.xs & s1_memattrs.xs + } else { + memattrs.xs = s1_memattrs.xs + }; + memattrs.shareability = EffectiveShareability(memattrs); + return(memattrs) +} + +bitfield GPCCR_EL3_Type : bits(64) = + { + L0GPTSZ : 23..20, + GPCP : 17..17, + GPC : 16..16, + PGS : 15..14, + SH : 13..12, + ORGN : 11..10, + IRGN : 9..8, + PPS : 2..0 + } + +register GPCCR_EL3 : GPCCR_EL3_Type + +val DecodePPS : unit -> int + +function DecodePPS () = { + match GPCCR_EL3[PPS] { + 0b000 => { + return(32) + }, + 0b001 => { + return(36) + }, + 0b010 => { + return(40) + }, + 0b011 => { + return(42) + }, + 0b100 => { + return(44) + }, + 0b101 => { + return(48) + }, + 0b110 => { + return(52) + }, + _ => { + Unreachable(); + return(undefined : int) + } + } +} + +val AbovePPS : bits(56) -> bool + +function AbovePPS address = { + let 'pps = DecodePPS(); + if pps >= 56 then { + return(false) + }; + return(not_bool(is_zero_subrange(address, 55, pps))) +} + +val GPCFault : forall 'level. (GPCF, int('level)) -> GPCFRecord + +function GPCFault (gpf, level) = { + fault : GPCFRecord = undefined; + fault.gpf = gpf; + fault.level = level; + return(fault) +} + +val AArch64_PAMax : unit -> {32, 36, 40, 42, 44, 48, 52, 56} + +function AArch64_PAMax () = { + let 'pamax = __IMPDEF_integer("Maximum Physical Address Size"); + assert(pamax == 32 | pamax == 36 | pamax == 40 | pamax == 42 | pamax == 44 | pamax == 48 | pamax == 52 | pamax == 56); + return(pamax) +} + +val GPCRegistersConsistent : unit -> bool + +function GPCRegistersConsistent () = { + if GPCCR_EL3[PPS] == 0b111 | DecodePPS() > AArch64_PAMax() then { + return(false) + }; + if GPCCR_EL3[PGS] == 0b11 then { + return(false) + }; + if GPCCR_EL3[SH] == 0b01 then { + return(false) + }; + if (GPCCR_EL3[ORGN] @ GPCCR_EL3[IRGN]) == 0b0000 & GPCCR_EL3[SH] != 0b10 then { + return(false) + }; + return(true) +} + +val GPICheck : (PASpace, bits(4)) -> bool + +function GPICheck (paspace, gpi) = { + match gpi { + ? if ? == GPT_NoAccess => { + return(false) + }, + ? if ? == GPT_Secure => { + assert(HaveSecureEL2Ext()); + return(paspace == PAS_Secure) + }, + ? if ? == GPT_NonSecure => { + return(paspace == PAS_NonSecure) + }, + ? if ? == GPT_Root => { + return(paspace == PAS_Root) + }, + ? if ? == GPT_Realm => { + return(paspace == PAS_Realm) + }, + ? if ? == GPT_Any => { + return(true) + }, + _ => { + Unreachable(); + return(undefined : bool) + } + } +} + +bitfield GPTBR_EL3_Type : bits(64) = {BADDR : 39..0} + +register GPTBR_EL3 : GPTBR_EL3_Type + +val GPIValid : bits(4) -> bool + +function GPIValid gpi = { + if gpi == GPT_Secure then { + return(HaveSecureEL2Ext()) + }; + return(gpi == GPT_NoAccess | gpi == GPT_NonSecure | gpi == GPT_Root | gpi == GPT_Realm | gpi == GPT_Any) +} + +val GPTL0Size : unit -> int + +function GPTL0Size () = { + match GPCCR_EL3[L0GPTSZ] { + 0b0000 => { + return(GPTRange_1GB) + }, + 0b0100 => { + return(GPTRange_16GB) + }, + 0b0110 => { + return(GPTRange_64GB) + }, + 0b1001 => { + return(GPTRange_512GB) + }, + _ => { + Unreachable() + } + }; + return(30) +} + +val DecodeGPTBlock : (PGSe, bits(64)) -> (GPCF, GPTEntry) + +function DecodeGPTBlock (pgs, entry) = { + assert(entry[3 .. 0] == GPT_Block); + result : GPTEntry = undefined; + if not_bool(IsZero(entry[63 .. 8])) then { + return((GPCF_Walk, __UNKNOWN_GPTEntry())) + }; + if not_bool(GPIValid(entry[7 .. 4])) then { + return((GPCF_Walk, __UNKNOWN_GPTEntry())) + }; + result.gpi = entry[7 .. 4]; + result.level = 0; + match pgs { + PGS_4KB => { + result.size = GPTRange_4KB + }, + PGS_16KB => { + result.size = GPTRange_16KB + }, + PGS_64KB => { + result.size = GPTRange_64KB + }, + _ => { + Unreachable() + } + }; + result.contig_size = GPTL0Size(); + return((GPCF_None, result)) +} + +val DecodeGPTContiguous : (PGSe, bits(64)) -> (GPCF, GPTEntry) + +function DecodeGPTContiguous (pgs, entry) = { + assert(entry[3 .. 0] == GPT_Contig); + result : GPTEntry = undefined; + if not_bool(IsZero(entry[63 .. 10])) then { + return((GPCF_Walk, result)) + }; + result.gpi = entry[7 .. 4]; + if not_bool(GPIValid(result.gpi)) then { + return((GPCF_Walk, result)) + }; + match pgs { + PGS_4KB => { + result.size = GPTRange_4KB + }, + PGS_16KB => { + result.size = GPTRange_16KB + }, + PGS_64KB => { + result.size = GPTRange_64KB + }, + _ => { + Unreachable() + } + }; + match entry[9 .. 8] { + 0b01 => { + result.contig_size = GPTRange_2MB + }, + 0b10 => { + result.contig_size = GPTRange_32MB + }, + 0b11 => { + result.contig_size = GPTRange_512MB + }, + _ => { + return((GPCF_Walk, __UNKNOWN_GPTEntry())) + } + }; + result.level = 1; + return((GPCF_None, result)) +} + +val DecodeGPTGranules : forall 'index. + (PGSe, int('index), bits(64)) -> (GPCF, GPTEntry) + +function DecodeGPTGranules (pgs, index, entry) = { + result : GPTEntry = undefined; + foreach (i from 0 to 15 by 1 in inc) { + if not_bool(GPIValid(Slice(entry, i * 4, 4))) then { + return((GPCF_Walk, result)) + }; + () + }; + result.gpi = Slice(entry, index * 4, 4); + match pgs { + PGS_4KB => { + result.size = GPTRange_4KB + }, + PGS_16KB => { + result.size = GPTRange_16KB + }, + PGS_64KB => { + result.size = GPTRange_64KB + }, + _ => { + Unreachable() + } + }; + result.contig_size = result.size; + result.level = 1; + return((GPCF_None, result)) +} + +val DecodeGPTTable : (PGSe, bits(64)) -> (GPCF, GPTTable) + +function DecodeGPTTable (pgs, entry) = { + assert(entry[3 .. 0] == GPT_Table); + result : GPTTable = undefined; + if not_bool(IsZero(entry[63 .. 52] @ entry[11 .. 4])) then { + return((GPCF_Walk, __UNKNOWN_GPTTable())) + }; + let 'l0sz = GPTL0Size(); + p : {12, 14, 16} = 12; + match pgs { + PGS_4KB => { + p = 12 + }, + PGS_16KB => { + p = 14 + }, + PGS_64KB => { + p = 16 + }, + _ => { + Unreachable() + } + }; + let 'p = p; + if not_bool(is_zero_subrange(entry, l0sz - p - 2, 12)) then { + return((GPCF_Walk, __UNKNOWN_GPTTable())) + }; + match pgs { + PGS_4KB => { + result.address = entry[55 .. 17] @ Zeros(17) + }, + PGS_16KB => { + result.address = entry[55 .. 15] @ Zeros(15) + }, + PGS_64KB => { + result.address = entry[55 .. 13] @ Zeros(13) + }, + _ => { + Unreachable() + } + }; + if AbovePPS(result.address) then { + return((GPCF_AddressSize, __UNKNOWN_GPTTable())) + }; + return((GPCF_None, result)) +} + +val DecodePGS : bits(2) -> PGSe + +function DecodePGS pgs = { + match pgs { + 0b00 => { + return(PGS_4KB) + }, + 0b10 => { + return(PGS_16KB) + }, + 0b01 => { + return(PGS_64KB) + }, + _ => { + Unreachable(); + return(undefined : PGSe) + } + } +} + +val GPIIndex : bits(56) -> int + +function GPIIndex pa = { + match DecodePGS(GPCCR_EL3[PGS]) { + PGS_4KB => { + return(UInt(pa[15 .. 12])) + }, + PGS_16KB => { + return(UInt(pa[17 .. 14])) + }, + PGS_64KB => { + return(UInt(pa[19 .. 16])) + }, + _ => { + Unreachable(); + return(undefined : int) + } + } +} + +val GPTLevel0Index : bits(56) -> int + +function GPTLevel0Index pa = { + let 'pps = DecodePPS(); + let 'l0sz = GPTL0Size(); + if pps <= l0sz then { + return(0) + }; + assert(constraint((0 <= 'l0sz & 'pps - 1 < 56))); + return(UInt(pa[pps - 1 .. l0sz])) +} + +val GPTLevel1Index : bits(56) -> int + +function GPTLevel1Index pa = { + let 'l0sz = GPTL0Size(); + match DecodePGS(GPCCR_EL3[PGS]) { + PGS_4KB => { + assert(constraint((16 <= 'l0sz - 1 & 'l0sz - 1 < 56))); + return(UInt(pa[l0sz - 1 .. 16])) + }, + PGS_16KB => { + assert(constraint((18 <= 'l0sz - 1 & 'l0sz - 1 < 56))); + return(UInt(pa[l0sz - 1 .. 18])) + }, + PGS_64KB => { + assert(constraint((20 <= 'l0sz - 1 & 'l0sz - 1 < 56))); + return(UInt(pa[l0sz - 1 .. 20])) + }, + _ => { + Unreachable(); + return(undefined : int) + } + } +} + +val GPTTLBCache : (PGSe, GPTEntry) -> unit + +val GPTTLBLookup : (bits(56), PGSe) -> GPTTLBLine + +register __tlb_enabled : bool = false + +val GPTWalk : (bits(56), AccessDescriptor) -> (GPCFRecord, GPTEntry) + +function GPTWalk (pa, accdesc) = { + gpi_index : int = undefined; + gpttlbline : GPTTLBLine = undefined; + let pgs : PGSe = DecodePGS(GPCCR_EL3[PGS]); + if __tlb_enabled then { + let gpttlbline : GPTTLBLine = GPTTLBLookup(pa, pgs); + if gpttlbline.valid_name then { + return((GPCNoFault(), gpttlbline.gpt_entry)) + }; + () + }; + base : bits(56) = ZeroExtend(GPTBR_EL3[BADDR] @ Zeros(12), 56); + let 'pps = DecodePPS(); + let 'l0sz = GPTL0Size(); + let 'alignment = Max(pps - l0sz + 3, 12); + assert(constraint(56 >= 'alignment)); + let base : bits(56) = base & not_vec(ZeroExtend(Ones(alignment), 56)); + let gptaccdesc : AccessDescriptor = CreateAccDescGPTW(accdesc); + gptaddrdesc : AddressDescriptor = undefined; + gptaddrdesc.memattrs = WalkMemAttrs(GPCCR_EL3[SH], GPCCR_EL3[ORGN], GPCCR_EL3[IRGN]); + gptaddrdesc.fault = NoFault__1(gptaccdesc); + gptaddrdesc.paddress.paspace = PAS_Root; + gptaddrdesc.paddress.address = base + GPTLevel0Index(pa) * 8; + level_0_entry : bits(64) = undefined; + memstatus : PhysMemRetStatus = undefined; + (memstatus, level_0_entry) = PhysMemRead(gptaddrdesc, 8, gptaccdesc, None()); + if IsFault__2(memstatus) then { + return((GPCFault(GPCF_EABT, 0), __UNKNOWN_GPTEntry())) + }; + result : GPTEntry = undefined; + table : GPTTable = undefined; + gpf : GPCF = undefined; + match level_0_entry[3 .. 0] { + ? if ? == GPT_Block => { + (gpf, result) = DecodeGPTBlock(pgs, level_0_entry); + result.pa = pa; + if __tlb_enabled & gpf == GPCF_None then { + GPTTLBCache(pgs, result) + }; + return((GPCFault(gpf, 0), result)) + }, + ? if ? == GPT_Table => { + (gpf, table) = DecodeGPTTable(pgs, level_0_entry); + if gpf != GPCF_None then { + return((GPCFault(gpf, 0), __UNKNOWN_GPTEntry())) + }; + () + }, + _ => { + return((GPCFault(GPCF_Walk, 0), __UNKNOWN_GPTEntry())) + } + }; + assert(level_0_entry[3 .. 0] == GPT_Table); + let 'offset = GPTLevel1Index(pa) * 8; + gptaddrdesc.paddress.address = table.address + offset; + level_1_entry : bits(64) = undefined; + (memstatus, level_1_entry) = PhysMemRead(gptaddrdesc, 8, gptaccdesc, None()); + if IsFault__2(memstatus) then { + return((GPCFault(GPCF_EABT, 1), __UNKNOWN_GPTEntry())) + }; + match level_1_entry[3 .. 0] { + ? if ? == GPT_Contig => { + (gpf, result) = DecodeGPTContiguous(pgs, level_1_entry) + }, + _ => { + let 'gpi_index = GPIIndex(pa); + (gpf, result) = DecodeGPTGranules(pgs, gpi_index, level_1_entry) + } + }; + if gpf != GPCF_None then { + return((GPCFault(gpf, 1), __UNKNOWN_GPTEntry())) + }; + result.pa = pa; + if __tlb_enabled then { + GPTTLBCache(pgs, result) + }; + return((GPCNoFault(), result)) +} + +val SetTLBIncludesGPT : forall 'gpt_range. (TLBContext, int('gpt_range)) -> unit + +val TLBIncludesGPT : TLBContext -> bool + +val GranuleProtectionCheck : (AddressDescriptor, AccessDescriptor) -> GPCFRecord + +function GranuleProtectionCheck (addrdesc, accdesc) = { + gpcf : GPCFRecord = undefined; + gpt_entry : GPTEntry = undefined; + assert(HaveRME()); + if __tlb_enabled & accdesc.acctype != AccessType_TTW then { + if TLBIncludesGPT(addrdesc.tlbcontext) then { + return(GPCNoFault()) + }; + () + }; + let address : FullAddress = addrdesc.paddress; + if GPCCR_EL3[GPC] == 0b0 then { + if __tlb_enabled then { + SetTLBIncludesGPT(addrdesc.tlbcontext, 56) + }; + return(GPCNoFault()) + }; + if not_bool(GPCRegistersConsistent()) then { + return(GPCFault(GPCF_Walk, 0)) + }; + if AbovePPS(address.address) then { + if address.paspace == PAS_NonSecure then { + if __tlb_enabled & accdesc.acctype != AccessType_TTW then { + SetTLBIncludesGPT(addrdesc.tlbcontext, 56) + }; + return(GPCNoFault()) + } else { + return(GPCFault(GPCF_Fail, 0)) + } + }; + let gpt_base : bits(56) = ZeroExtend(GPTBR_EL3[BADDR] @ Zeros(12), 56); + if AbovePPS(gpt_base) then { + return(GPCFault(GPCF_AddressSize, 0)) + }; + (gpcf, gpt_entry) = GPTWalk(address.address, accdesc); + if gpcf.gpf != GPCF_None then { + return(gpcf) + }; + let permitted : bool = GPICheck(address.paspace, gpt_entry.gpi); + if not_bool(permitted) then { + let gpcf : GPCFRecord = GPCFault(GPCF_Fail, gpt_entry.level); + return(gpcf) + }; + if __tlb_enabled & accdesc.acctype != AccessType_TTW then { + SetTLBIncludesGPT(addrdesc.tlbcontext, gpt_entry.contig_size) + }; + return(GPCNoFault()) +} + +val FetchDescriptor : forall 'N, 'N in {32, 64, 128}. + (bits(1), AddressDescriptor, AccessDescriptor, FaultRecord, int('N), TranslationInfo) -> (FaultRecord, bits('N)) + +function FetchDescriptor (ee, walkaddress, walkaccess, fault_in, N, translation_info) = { + assert((N == 32 | N == 64) | N == 128); + descriptor : bits('N) = undefined; + fault : FaultRecord = fault_in; + if HaveRME() then { + fault.gpcf = GranuleProtectionCheck(walkaddress, walkaccess); + if fault.gpcf.gpf != GPCF_None then { + fault.statuscode = Fault_GPCFOnWalk; + fault.paddress = walkaddress.paddress; + fault.gpcfs2walk = fault.secondstage; + return((fault, __UNKNOWN_bits(N))) + }; + () + }; + memstatus : PhysMemRetStatus = undefined; + (memstatus, descriptor) = PhysMemRead(walkaddress, DIV(N, 8), walkaccess, Some(translation_info)); + if IsFault__2(memstatus) then { + let iswrite : bool = false; + fault = HandleExternalTTWAbort(memstatus, iswrite, walkaddress, walkaccess, DIV(N, 8), fault); + if IsFault__1(fault.statuscode) then { + return((fault, __UNKNOWN_bits(N))) + }; + () + }; + if ee == 0b1 then { + descriptor = BigEndianReverse(descriptor) + }; + let descriptor = descriptor; + return((fault, descriptor)) +} + +val ContiguousSize : forall 'level. (bits(1), TGx, int('level)) -> int + +function ContiguousSize (d128, tgx, level) = { + if d128 == 0b1 then { + match tgx { + TGx_4KB => { + assert(level == 1 | level == 2 | level == 3); + return(if level == 1 then 2 else 4) + }, + TGx_16KB => { + assert(level == 1 | level == 2 | level == 3); + if level == 1 then { + return(2) + } else if level == 2 then { + return(4) + } else { + return(6) + } + }, + TGx_64KB => { + assert(level == 2 | level == 3); + return(if level == 2 then 6 else 4) + }, + _ => { + return(undefined : int) + } + } + } else { + match tgx { + TGx_4KB => { + assert(level == 1 | level == 2 | level == 3); + return(4) + }, + TGx_16KB => { + assert(level == 2 | level == 3); + return(if level == 2 then 5 else 7) + }, + TGx_64KB => { + assert(level == 2 | level == 3); + return(5) + }, + _ => { + return(undefined : int) + } + } + } +} + +val TGxGranuleBits : TGx -> int + +function TGxGranuleBits tgx = { + match tgx { + TGx_4KB => { + return(12) + }, + TGx_16KB => { + return(14) + }, + TGx_64KB => { + return(16) + }, + _ => { + return(undefined : int) + } + } +} + +val TranslationSize : forall 'level. (bits(1), TGx, int('level)) -> int + +function TranslationSize (d128, tgx, level) = { + let 'granulebits = TGxGranuleBits(tgx); + let 'descsizelog2 = if d128 == 0b1 then 4 else 3; + let 'blockbits = (FINAL_LEVEL - level) * (granulebits - descsizelog2); + return(granulebits + blockbits) +} + +val StageOA : (bits(64), bits(1), TGx, TTWState) -> FullAddress + +function StageOA (ia, d128, tgx, walkstate) = { + oa : FullAddress = undefined; + csize : int = undefined; + let 'tsize = TranslationSize(d128, tgx, walkstate.level); + if walkstate.contiguous == 0b1 then { + csize = ContiguousSize(d128, tgx, walkstate.level) + } else { + csize = 0 + }; + let 'csize = csize; + let 'ia_msb = tsize + csize; + oa.paspace = walkstate.baseaddress.paspace; + assert(constraint((0 <= 'ia_msb & 'ia_msb <= 55))); + assert(constraint(0 <= 'ia_msb - 1)); + oa.address = walkstate.baseaddress.address[55 .. ia_msb] @ ia[ia_msb - 1 .. 0]; + return(oa) +} + +val RegimeUsingAArch32 : Regime -> bool + +function RegimeUsingAArch32 regime = { + match regime { + Regime_EL10 => { + return(ELUsingAArch32(EL1)) + }, + Regime_EL30 => { + return(true) + }, + Regime_EL20 => { + return(false) + }, + Regime_EL2 => { + return(ELUsingAArch32(EL2)) + }, + Regime_EL3 => { + return(false) + }, + _ => { + return(undefined : bool) + } + } +} + +val SecurityStateForRegime : Regime -> SecurityState + +function SecurityStateForRegime regime = { + match regime { + Regime_EL3 => { + return(SecurityStateAtEL(EL3)) + }, + Regime_EL30 => { + return(SS_Secure) + }, + Regime_EL2 => { + return(SecurityStateAtEL(EL2)) + }, + Regime_EL20 => { + return(SecurityStateAtEL(EL2)) + }, + Regime_EL10 => { + return(SecurityStateAtEL(EL1)) + }, + _ => { + return(undefined : SecurityState) + } + } +} + +val DecodePASpace : (bits(1), bits(1)) -> PASpace + +function DecodePASpace (nse, ns) = { + match nse @ ns { + 0b00 => { + return(PAS_Secure) + }, + 0b01 => { + return(PAS_NonSecure) + }, + 0b10 => { + return(PAS_Root) + }, + 0b11 => { + return(PAS_Realm) + }, + _ => { + return(undefined : PASpace) + } + } +} + +val HasUnprivileged : Regime -> bool + +function HasUnprivileged regime = { + return(regime == Regime_EL20 | regime == Regime_EL30 | regime == Regime_EL10) +} + +val CreateAddressDescriptor : (bits(64), FullAddress, MemoryAttributes) -> AddressDescriptor + +function CreateAddressDescriptor (va, pa, memattrs) = { + addrdesc : AddressDescriptor = undefined; + addrdesc.paddress = pa; + addrdesc.vaddress = va; + addrdesc.memattrs = memattrs; + addrdesc.fault = NoFault(); + addrdesc.s1assured = false; + return(addrdesc) +} + +val CreateFaultyAddressDescriptor : (bits(64), FaultRecord) -> AddressDescriptor + +function CreateFaultyAddressDescriptor (va, fault) = { + addrdesc : AddressDescriptor = undefined; + addrdesc.vaddress = va; + addrdesc.fault = fault; + return(addrdesc) +} + +val AlignmentFault : AccessDescriptor -> FaultRecord + +function AlignmentFault accdesc = { + fault : FaultRecord = undefined; + fault.statuscode = Fault_Alignment; + fault.access = accdesc; + fault.secondstage = false; + fault.s2fs1walk = false; + fault.write = not_bool(accdesc.read) & accdesc.write; + fault.gpcfs2walk = false; + fault.gpcf = GPCNoFault(); + return(fault) +} + +val ExclusiveFault : AccessDescriptor -> FaultRecord + +function ExclusiveFault accdesc = { + fault : FaultRecord = undefined; + fault.statuscode = Fault_Exclusive; + fault.access = accdesc; + fault.secondstage = false; + fault.s2fs1walk = false; + fault.write = not_bool(accdesc.read) & accdesc.write; + fault.gpcfs2walk = false; + fault.gpcf = GPCNoFault(); + return(fault) +} + +val AArch64_MaxTxSZ : TGx -> int + +function AArch64_MaxTxSZ tgx = { + if HaveSmallTranslationTableExt() then { + match tgx { + TGx_4KB => { + return(48) + }, + TGx_16KB => { + return(48) + }, + TGx_64KB => { + return(47) + } + } + }; + return(39) +} + +val AArch64_S1MinTxSZ : (Regime, bits(1), bits(1), TGx) -> int + +function AArch64_S1MinTxSZ (regime, d128, ds, tgx) = { + if Have56BitVAExt() & d128 == 0b1 then { + if HasUnprivileged(regime) then { + return(9) + } else { + return(8) + } + }; + if Have52BitVAExt() & tgx == TGx_64KB | ds == 0b1 then { + return(12) + }; + return(16) +} + +val AArch64_S1TxSZFaults : (Regime, S1TTWParams) -> bool + +function AArch64_S1TxSZFaults (regime, walkparams) = { + let 'mintxsz = AArch64_S1MinTxSZ(regime, walkparams.d128, walkparams.ds, walkparams.tgx); + let 'maxtxsz = AArch64_MaxTxSZ(walkparams.tgx); + if UInt(walkparams.txsz) < mintxsz then { + return(Have52BitVAExt() | __IMPDEF_boolean("Fault on TxSZ value below minimum")) + }; + if UInt(walkparams.txsz) > maxtxsz then { + return(__IMPDEF_boolean("Fault on TxSZ value above maximum")) + }; + return(false) +} + +val AArch64_PACEffectiveTxSZ : (Regime, S1TTWParams) -> bits(6) + +function AArch64_PACEffectiveTxSZ (regime, walkparams) = { + let 's1maxtxsz = AArch64_MaxTxSZ(walkparams.tgx); + let 's1mintxsz = AArch64_S1MinTxSZ(regime, walkparams.d128, walkparams.ds, walkparams.tgx); + if AArch64_S1TxSZFaults(regime, walkparams) then { + if ConstrainUnpredictable(Unpredictable_RESTnSZ) == Constraint_FORCE then { + if UInt(walkparams.txsz) < s1mintxsz then { + return(s1mintxsz[5 .. 0]) + }; + if UInt(walkparams.txsz) > s1maxtxsz then { + return(s1maxtxsz[5 .. 0]) + }; + () + }; + () + } else if UInt(walkparams.txsz) < s1mintxsz then { + return(s1mintxsz[5 .. 0]) + } else if UInt(walkparams.txsz) > s1maxtxsz then { + return(s1maxtxsz[5 .. 0]) + } else (); + return(walkparams.txsz) +} + +val AArch64_GetVARange : bits(64) -> VARange + +function AArch64_GetVARange va = { + if [va[55]] == 0b0 then { + return(VARange_LOWER) + } else { + return(VARange_UPPER) + } +} + +val AArch64_HaveS1TG : TGx -> bool + +function AArch64_HaveS1TG tgx = { + match tgx { + TGx_4KB => { + return(__IMPDEF_boolean("Has 4K Translation Granule")) + }, + TGx_16KB => { + return(__IMPDEF_boolean("Has 16K Translation Granule")) + }, + TGx_64KB => { + return(__IMPDEF_boolean("Has 64K Translation Granule")) + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch64_S1DecodeTG0 : bits(2) -> TGx + +function AArch64_S1DecodeTG0 tg0_in = { + tg0 : bits(2) = tg0_in; + tgx : TGx = undefined; + if tg0 == 0b11 then { + tg0 = __IMPDEF_bits(2, "TG0 encoded granule size") + }; + match tg0 { + 0b00 => { + tgx = TGx_4KB + }, + 0b01 => { + tgx = TGx_64KB + }, + 0b10 => { + tgx = TGx_16KB + }, + _ => () + }; + if not_bool(AArch64_HaveS1TG(tgx)) then { + match __IMPDEF_bits(2, "TG0 encoded granule size") { + 0b00 => { + tgx = TGx_4KB + }, + 0b01 => { + tgx = TGx_64KB + }, + 0b10 => { + tgx = TGx_16KB + }, + _ => () + } + }; + return(tgx) +} + +val AArch64_S1DecodeTG1 : bits(2) -> TGx + +function AArch64_S1DecodeTG1 tg1_in = { + tg1 : bits(2) = tg1_in; + tgx : TGx = undefined; + if tg1 == 0b00 then { + tg1 = __IMPDEF_bits(2, "TG1 encoded granule size") + }; + match tg1 { + 0b10 => { + tgx = TGx_4KB + }, + 0b11 => { + tgx = TGx_64KB + }, + 0b01 => { + tgx = TGx_16KB + }, + _ => () + }; + if not_bool(AArch64_HaveS1TG(tgx)) then { + match __IMPDEF_bits(2, "TG1 encoded granule size") { + 0b10 => { + tgx = TGx_4KB + }, + 0b11 => { + tgx = TGx_64KB + }, + 0b01 => { + tgx = TGx_16KB + }, + _ => () + } + }; + return(tgx) +} + +val IsTCR2EL1Enabled : unit -> bool + +function IsTCR2EL1Enabled () = { + if not_bool(HaveFeatTCR2()) then { + return(false) + }; + if HaveEL(EL3) & SCR_EL3[TCR2En] == 0b0 then { + return(false) + } else if EL2Enabled() & (not_bool(IsHCRXEL2Enabled()) | HCRX_EL2[TCR2En] == 0b0) then { + return(false) + } else { + return(true) + } +} + +bitfield MAIR2_EL1_Type : bits(64) = + { + Attr7 : 63..56, + Attr6 : 55..48, + Attr5 : 47..40, + Attr4 : 39..32, + Attr3 : 31..24, + Attr2 : 23..16, + Attr1 : 15..8, + Attr0 : 7..0 + } + +register MAIR2_EL1 : MAIR2_EL1_Type + +bitfield MAIR_EL1_Type : bits(64) = + { + Attr7 : 63..56, + Attr6 : 55..48, + Attr5 : 47..40, + Attr4 : 39..32, + Attr3 : 31..24, + Attr2 : 23..16, + Attr1 : 15..8, + Attr0 : 7..0 + } + +register MAIR_EL1 : MAIR_EL1_Type + +bitfield PIRE0_EL1_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register PIRE0_EL1 : PIRE0_EL1_Type + +bitfield PIR_EL1_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register PIR_EL1 : PIR_EL1_Type + +bitfield TCR2_EL1_Type : bits(64) = + { + DisCH1 : 15..15, + DisCH0 : 14..14, + HAFT : 11..11, + PTTWI : 10..10, + D128 : 5..5, + AIE : 4..4, + POE : 3..3, + E0POE : 2..2, + PIE : 1..1, + PnCH : 0..0 + } + +register TCR2_EL1 : TCR2_EL1_Type + +val AArch64_S1TTWParamsEL10 : VARange -> S1TTWParams + +function AArch64_S1TTWParamsEL10 varange = { + walkparams : S1TTWParams = undefined; + if Have128BitDescriptorExt() & IsTCR2EL1Enabled() then { + walkparams.d128 = TCR2_EL1[D128] + } else { + walkparams.d128 = 0b0 + }; + if varange == VARange_LOWER then { + walkparams.tgx = AArch64_S1DecodeTG0(TCR_EL1[TG0]); + walkparams.txsz = TCR_EL1[T0SZ]; + walkparams.irgn = TCR_EL1[IRGN0]; + walkparams.orgn = TCR_EL1[ORGN0]; + walkparams.sh = TCR_EL1[SH0]; + walkparams.tbi = TCR_EL1[TBI0]; + walkparams.nfd = if HaveSVE() | HaveTME() then TCR_EL1[NFD0] else 0b0; + walkparams.tbid = if HavePACExt() then TCR_EL1[TBID0] else 0b0; + walkparams.e0pd = if HaveE0PDExt() then TCR_EL1[E0PD0] else 0b0; + walkparams.hpd = if AArch64_HaveHPDExt() then TCR_EL1[HPD0] else 0b0; + walkparams.mtx = if HaveMTE4Ext() then TCR_EL1[MTX0] else 0b0; + walkparams.skl = if walkparams.d128 == 0b1 then TTBR0_EL1_read()[SKL] + else + 0b00; + walkparams.disch = if walkparams.d128 == 0b1 then TCR2_EL1[DisCH0] else + 0b0 + } else { + walkparams.tgx = AArch64_S1DecodeTG1(TCR_EL1[TG1]); + walkparams.txsz = TCR_EL1[T1SZ]; + walkparams.irgn = TCR_EL1[IRGN1]; + walkparams.orgn = TCR_EL1[ORGN1]; + walkparams.sh = TCR_EL1[SH1]; + walkparams.tbi = TCR_EL1[TBI1]; + walkparams.nfd = if HaveSVE() | HaveTME() then TCR_EL1[NFD1] else 0b0; + walkparams.tbid = if HavePACExt() then TCR_EL1[TBID1] else 0b0; + walkparams.e0pd = if HaveE0PDExt() then TCR_EL1[E0PD1] else 0b0; + walkparams.hpd = if AArch64_HaveHPDExt() then TCR_EL1[HPD1] else 0b0; + walkparams.mtx = if HaveMTE4Ext() then TCR_EL1[MTX1] else 0b0; + walkparams.skl = if walkparams.d128 == 0b1 then TTBR1_EL1_read()[SKL] + else + 0b00; + walkparams.disch = if walkparams.d128 == 0b1 then TCR2_EL1[DisCH1] else + 0b0 + }; + walkparams.mair = Mk_MAIRType(MAIR_EL1.bits); + if HaveAIEExt() then { + walkparams.mair2 = Mk_MAIRType(MAIR2_EL1.bits) + }; + walkparams.aie = if HaveAIEExt() & IsTCR2EL1Enabled() then TCR2_EL1[AIE] + else + 0b0; + walkparams.wxn = SCTLR_EL1[WXN]; + walkparams.ps = TCR_EL1[IPS]; + walkparams.ee = SCTLR_EL1[EE]; + if HaveEL(EL3) & (not_bool(HaveRME()) | HaveSecureEL2Ext()) then { + walkparams.sif = SCR_EL3[SIF] + } else { + walkparams.sif = 0b0 + }; + if EL2Enabled() then { + walkparams.dc = HCR_EL2[DC]; + walkparams.dct = if HaveMTE2Ext() then HCR_EL2[DCT] else 0b0 + }; + if HaveTrapLoadStoreMultipleDeviceExt() then { + walkparams.ntlsmd = SCTLR_EL1[nTLSMD] + } else { + walkparams.ntlsmd = 0b1 + }; + if EL2Enabled() then { + if (HCR_EL2[NV] @ HCR_EL2[NV1]) == 0b01 then { + match ConstrainUnpredictable(Unpredictable_NVNV1) { + Constraint_NVNV1_00 => { + walkparams.nv1 = 0b0 + }, + Constraint_NVNV1_01 => { + walkparams.nv1 = 0b1 + }, + Constraint_NVNV1_11 => { + walkparams.nv1 = 0b1 + }, + _ => () + } + } else { + walkparams.nv1 = HCR_EL2[NV1] + } + } else { + walkparams.nv1 = 0b0 + }; + walkparams.cmow = if HaveFeatCMOW() then SCTLR_EL1[CMOW] else 0b0; + walkparams.ha = if HaveAccessFlagUpdateExt() then TCR_EL1[HA] else 0b0; + walkparams.hd = if HaveDirtyBitModifierExt() then TCR_EL1[HD] else 0b0; + if (walkparams.tgx == TGx_4KB | walkparams.tgx == TGx_16KB) & Have52BitIPAAndPASpaceExt() then { + walkparams.ds = TCR_EL1[DS] + } else { + walkparams.ds = 0b0 + }; + if walkparams.d128 == 0b1 then { + walkparams.pie = 0b1 + } else { + walkparams.pie = if HaveS1PIExt() & IsTCR2EL1Enabled() then + TCR2_EL1[PIE] + else + 0b0 + }; + if HaveS1PIExt() then { + walkparams.pir = Mk_S1PIRType(PIR_EL1.bits); + if walkparams.nv1 != 0b1 then { + walkparams.pire0 = Mk_S1PIRType(PIRE0_EL1.bits) + }; + () + }; + if HavePAN3Ext() then { + walkparams.epan = if walkparams.pie == 0b0 then SCTLR_EL1[EPAN] else 0b1 + } else { + walkparams.epan = 0b0 + }; + if (HaveTHExt() & walkparams.d128 == 0b0) & IsTCR2EL1Enabled() then { + walkparams.pnch = TCR2_EL1[PnCH] + } else { + walkparams.pnch = 0b0 + }; + if (HaveAccessFlagUpdateForTableExt() & walkparams.ha == 0b1) & IsTCR2EL1Enabled() then { + walkparams.haft = TCR2_EL1[HAFT] + } else { + walkparams.haft = 0b0 + }; + walkparams.emec = if HaveFeatMEC() & IsSCTLR2EL2Enabled() then + SCTLR2_EL2[EMEC] + else + 0b0; + return(walkparams) +} + +val IsTCR2EL2Enabled : unit -> bool + +function IsTCR2EL2Enabled () = { + if not_bool(HaveFeatTCR2()) then { + return(false) + }; + if HaveEL(EL3) & SCR_EL3[TCR2En] == 0b0 then { + return(false) + }; + return(EL2Enabled()) +} + +bitfield MAIR2_EL2_Type : bits(64) = + { + Attr7 : 63..56, + Attr6 : 55..48, + Attr5 : 47..40, + Attr4 : 39..32, + Attr3 : 31..24, + Attr2 : 23..16, + Attr1 : 15..8, + Attr0 : 7..0 + } + +register MAIR2_EL2 : MAIR2_EL2_Type + +bitfield MAIR_EL2_Type : bits(64) = + { + Attr7 : 63..56, + Attr6 : 55..48, + Attr5 : 47..40, + Attr4 : 39..32, + Attr3 : 31..24, + Attr2 : 23..16, + Attr1 : 15..8, + Attr0 : 7..0 + } + +register MAIR_EL2 : MAIR_EL2_Type + +bitfield PIR_EL2_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register PIR_EL2 : PIR_EL2_Type + +bitfield TCR2_EL2_Type : bits(64) = + { + DisCH1 : 15..15, + DisCH0 : 14..14, + AMEC1 : 13..13, + AMEC0 : 12..12, + HAFT : 11..11, + PTTWI : 10..10, + SKL1 : 9..8, + SKL0 : 7..6, + D128 : 5..5, + AIE : 4..4, + POE : 3..3, + E0POE : 2..2, + PIE : 1..1, + PnCH : 0..0 + } + +register TCR2_EL2 : TCR2_EL2_Type + +val AArch64_S1TTWParamsEL2 : SecurityState -> S1TTWParams + +function AArch64_S1TTWParamsEL2 ss = { + walkparams : S1TTWParams = undefined; + walkparams.tgx = AArch64_S1DecodeTG0(TCR_EL2[TG0]); + walkparams.txsz = TCR_EL2[T0SZ]; + walkparams.ps = TCR_EL2[PS]; + walkparams.irgn = TCR_EL2[IRGN0]; + walkparams.orgn = TCR_EL2[ORGN0]; + walkparams.sh = TCR_EL2[SH0]; + walkparams.tbi = TCR_EL2[TBI]; + walkparams.mair = Mk_MAIRType(MAIR_EL2.bits); + if HaveAIEExt() then { + walkparams.mair2 = Mk_MAIRType(MAIR2_EL2.bits) + }; + walkparams.aie = if HaveAIEExt() & IsTCR2EL2Enabled() then TCR2_EL2[AIE] + else + 0b0; + walkparams.wxn = SCTLR_EL2[WXN]; + walkparams.ee = SCTLR_EL2[EE]; + if HaveEL(EL3) & (not_bool(HaveRME()) | HaveSecureEL2Ext()) then { + walkparams.sif = SCR_EL3[SIF] + } else { + walkparams.sif = 0b0 + }; + walkparams.tbid = if HavePACExt() then TCR_EL2[TBID] else 0b0; + walkparams.hpd = if AArch64_HaveHPDExt() then TCR_EL2[HPD] else 0b0; + walkparams.ha = if HaveAccessFlagUpdateExt() then + Slice(TCR_EL2.bits, if HCR_EL2[E2H] == 0b0 then 21 else 39, 1) + else + 0b0; + walkparams.hd = if HaveDirtyBitModifierExt() then + Slice(TCR_EL2.bits, if HCR_EL2[E2H] == 0b0 then 22 else 40, 1) + else + 0b0; + if (walkparams.tgx == TGx_4KB | walkparams.tgx == TGx_16KB) & Have52BitIPAAndPASpaceExt() then { + walkparams.ds = Slice(TCR_EL2.bits, if HCR_EL2[E2H] == 0b0 then 32 else + 59, 1) + } else { + walkparams.ds = 0b0 + }; + walkparams.pie = if HaveS1PIExt() & IsTCR2EL2Enabled() then TCR2_EL2[PIE] + else + 0b0; + if HaveS1PIExt() then { + walkparams.pir = Mk_S1PIRType(PIR_EL2.bits) + }; + walkparams.mtx = if HaveMTE4Ext() then TCR_EL2[MTX] else 0b0; + walkparams.pnch = if HaveTHExt() & IsTCR2EL2Enabled() then TCR2_EL2[PnCH] + else + 0b0; + if (HaveAccessFlagUpdateForTableExt() & walkparams.ha == 0b1) & IsTCR2EL2Enabled() then { + walkparams.haft = TCR2_EL2[HAFT] + } else { + walkparams.haft = 0b0 + }; + walkparams.emec = if HaveFeatMEC() & IsSCTLR2EL2Enabled() then + SCTLR2_EL2[EMEC] + else + 0b0; + if (HaveFeatMEC() & ss == SS_Realm) & IsTCR2EL2Enabled() then { + walkparams.amec = TCR2_EL2[AMEC0] + } else { + walkparams.amec = 0b0 + }; + return(walkparams) +} + +bitfield PIRE0_EL2_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register PIRE0_EL2 : PIRE0_EL2_Type + +val AArch64_S1TTWParamsEL20 : (SecurityState, VARange) -> S1TTWParams + +function AArch64_S1TTWParamsEL20 (ss, varange) = { + walkparams : S1TTWParams = undefined; + if Have128BitDescriptorExt() & IsTCR2EL2Enabled() then { + walkparams.d128 = TCR2_EL2[D128] + } else { + walkparams.d128 = 0b0 + }; + if varange == VARange_LOWER then { + walkparams.tgx = AArch64_S1DecodeTG0(TCR_EL2[TG0]); + walkparams.txsz = TCR_EL2[T0SZ]; + walkparams.irgn = TCR_EL2[IRGN0]; + walkparams.orgn = TCR_EL2[ORGN0]; + walkparams.sh = TCR_EL2[SH0]; + walkparams.tbi = TCR_EL2[TBI0]; + walkparams.nfd = if HaveSVE() | HaveTME() then TCR_EL2[NFD0] else 0b0; + walkparams.tbid = if HavePACExt() then TCR_EL2[TBID0] else 0b0; + walkparams.e0pd = if HaveE0PDExt() then TCR_EL2[E0PD0] else 0b0; + walkparams.hpd = if AArch64_HaveHPDExt() then TCR_EL2[HPD0] else 0b0; + walkparams.mtx = if HaveMTE4Ext() then TCR_EL2[MTX0] else 0b0; + walkparams.skl = if walkparams.d128 == 0b1 then TTBR0_EL2_read()[SKL] + else + 0b00; + walkparams.disch = if walkparams.d128 == 0b1 then TCR2_EL2[DisCH0] else + 0b0 + } else { + walkparams.tgx = AArch64_S1DecodeTG1(TCR_EL2[TG1]); + walkparams.txsz = TCR_EL2[T1SZ]; + walkparams.irgn = TCR_EL2[IRGN1]; + walkparams.orgn = TCR_EL2[ORGN1]; + walkparams.sh = TCR_EL2[SH1]; + walkparams.tbi = TCR_EL2[TBI1]; + walkparams.nfd = if HaveSVE() | HaveTME() then TCR_EL2[NFD1] else 0b0; + walkparams.tbid = if HavePACExt() then TCR_EL2[TBID1] else 0b0; + walkparams.e0pd = if HaveE0PDExt() then TCR_EL2[E0PD1] else 0b0; + walkparams.hpd = if AArch64_HaveHPDExt() then TCR_EL2[HPD1] else 0b0; + walkparams.mtx = if HaveMTE4Ext() then TCR_EL2[MTX1] else 0b0; + walkparams.skl = if walkparams.d128 == 0b1 then TTBR1_EL2[SKL] else 0b00; + walkparams.disch = if walkparams.d128 == 0b1 then TCR2_EL2[DisCH1] else + 0b0 + }; + walkparams.mair = Mk_MAIRType(MAIR_EL2.bits); + if HaveAIEExt() then { + walkparams.mair2 = Mk_MAIRType(MAIR2_EL2.bits) + }; + walkparams.aie = if HaveAIEExt() & IsTCR2EL2Enabled() then TCR2_EL2[AIE] + else + 0b0; + walkparams.wxn = SCTLR_EL2[WXN]; + walkparams.ps = TCR_EL2[IPS]; + walkparams.ee = SCTLR_EL2[EE]; + if HaveEL(EL3) & (not_bool(HaveRME()) | HaveSecureEL2Ext()) then { + walkparams.sif = SCR_EL3[SIF] + } else { + walkparams.sif = 0b0 + }; + if HaveTrapLoadStoreMultipleDeviceExt() then { + walkparams.ntlsmd = SCTLR_EL2[nTLSMD] + } else { + walkparams.ntlsmd = 0b1 + }; + walkparams.cmow = if HaveFeatCMOW() then SCTLR_EL2[CMOW] else 0b0; + walkparams.ha = if HaveAccessFlagUpdateExt() then + Slice(TCR_EL2.bits, if HCR_EL2[E2H] == 0b0 then 21 else 39, 1) + else + 0b0; + walkparams.hd = if HaveDirtyBitModifierExt() then + Slice(TCR_EL2.bits, if HCR_EL2[E2H] == 0b0 then 22 else 40, 1) + else + 0b0; + if (walkparams.tgx == TGx_4KB | walkparams.tgx == TGx_16KB) & Have52BitIPAAndPASpaceExt() then { + walkparams.ds = Slice(TCR_EL2.bits, if HCR_EL2[E2H] == 0b0 then 32 else + 59, 1) + } else { + walkparams.ds = 0b0 + }; + if walkparams.d128 == 0b1 then { + walkparams.pie = 0b1 + } else { + walkparams.pie = if HaveS1PIExt() & IsTCR2EL2Enabled() then + TCR2_EL2[PIE] + else + 0b0 + }; + if HaveS1PIExt() then { + walkparams.pir = Mk_S1PIRType(PIR_EL2.bits); + walkparams.pire0 = Mk_S1PIRType(PIRE0_EL2.bits) + }; + if HavePAN3Ext() then { + walkparams.epan = if walkparams.pie == 0b0 then SCTLR_EL2[EPAN] else 0b1 + } else { + walkparams.epan = 0b0 + }; + if (HaveTHExt() & walkparams.d128 == 0b0) & IsTCR2EL2Enabled() then { + walkparams.pnch = TCR2_EL2[PnCH] + } else { + walkparams.pnch = 0b0 + }; + if (HaveAccessFlagUpdateForTableExt() & walkparams.ha == 0b1) & IsTCR2EL2Enabled() then { + walkparams.haft = TCR2_EL2[HAFT] + } else { + walkparams.haft = 0b0 + }; + walkparams.emec = if HaveFeatMEC() & IsSCTLR2EL2Enabled() then + SCTLR2_EL2[EMEC] + else + 0b0; + if (HaveFeatMEC() & ss == SS_Realm) & IsTCR2EL2Enabled() then { + walkparams.amec = if varange == VARange_LOWER then TCR2_EL2[AMEC0] else + TCR2_EL2[AMEC1] + } else { + walkparams.amec = 0b0 + }; + return(walkparams) +} + +bitfield MAIR2_EL3_Type : bits(64) = + { + Attr7 : 63..56, + Attr6 : 55..48, + Attr5 : 47..40, + Attr4 : 39..32, + Attr3 : 31..24, + Attr2 : 23..16, + Attr1 : 15..8, + Attr0 : 7..0 + } + +register MAIR2_EL3 : MAIR2_EL3_Type + +bitfield MAIR_EL3_Type : bits(64) = + { + Attr7 : 63..56, + Attr6 : 55..48, + Attr5 : 47..40, + Attr4 : 39..32, + Attr3 : 31..24, + Attr2 : 23..16, + Attr1 : 15..8, + Attr0 : 7..0 + } + +register MAIR_EL3 : MAIR_EL3_Type + +bitfield PIR_EL3_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register PIR_EL3 : PIR_EL3_Type + +bitfield SCTLR2_EL3_Type : bits(64) = + {EnANERR : 4..4, EnADERR : 3..3, EMEC : 1..1} + +register SCTLR2_EL3 : SCTLR2_EL3_Type + +bitfield TTBR0_EL3_Type : bits(64) = {SKL : 2..1, CnP : 0..0} + +register TTBR0_EL3 : TTBR0_EL3_Type + +val AArch64_S1TTWParamsEL3 : unit -> S1TTWParams + +function AArch64_S1TTWParamsEL3 () = { + walkparams : S1TTWParams = undefined; + walkparams.tgx = AArch64_S1DecodeTG0(TCR_EL3[TG0]); + walkparams.txsz = TCR_EL3[T0SZ]; + walkparams.ps = TCR_EL3[PS]; + walkparams.irgn = TCR_EL3[IRGN0]; + walkparams.orgn = TCR_EL3[ORGN0]; + walkparams.sh = TCR_EL3[SH0]; + walkparams.tbi = TCR_EL3[TBI]; + walkparams.mair = Mk_MAIRType(MAIR_EL3.bits); + if HaveAIEExt() then { + walkparams.mair2 = Mk_MAIRType(MAIR2_EL3.bits) + }; + walkparams.aie = if HaveAIEExt() then TCR_EL3[AIE] else 0b0; + walkparams.wxn = SCTLR_EL3[WXN]; + walkparams.ee = SCTLR_EL3[EE]; + walkparams.sif = if not_bool(HaveRME()) | HaveSecureEL2Ext() then + SCR_EL3[SIF] + else + 0b0; + walkparams.tbid = if HavePACExt() then TCR_EL3[TBID] else 0b0; + walkparams.hpd = if AArch64_HaveHPDExt() then TCR_EL3[HPD] else 0b0; + walkparams.ha = if HaveAccessFlagUpdateExt() then TCR_EL3[HA] else 0b0; + walkparams.hd = if HaveDirtyBitModifierExt() then TCR_EL3[HD] else 0b0; + if (walkparams.tgx == TGx_4KB | walkparams.tgx == TGx_16KB) & Have52BitIPAAndPASpaceExt() then { + walkparams.ds = TCR_EL3[DS] + } else { + walkparams.ds = 0b0 + }; + walkparams.d128 = if Have128BitDescriptorExt() then TCR_EL3[D128] else 0b0; + walkparams.skl = if walkparams.d128 == 0b1 then TTBR0_EL3[SKL] else 0b00; + walkparams.disch = if walkparams.d128 == 0b1 then TCR_EL3[DisCH0] else 0b0; + if walkparams.d128 == 0b1 then { + walkparams.pie = 0b1 + } else { + walkparams.pie = if HaveS1PIExt() then TCR_EL3[PIE] else 0b0 + }; + if HaveS1PIExt() then { + walkparams.pir = Mk_S1PIRType(PIR_EL3.bits) + }; + walkparams.mtx = if HaveMTE4Ext() then TCR_EL3[MTX] else 0b0; + if HaveTHExt() & walkparams.d128 == 0b0 then { + walkparams.pnch = TCR_EL3[PnCH] + } else { + walkparams.pnch = 0b0 + }; + if HaveAccessFlagUpdateForTableExt() & walkparams.ha == 0b1 then { + walkparams.haft = TCR_EL3[HAFT] + } else { + walkparams.haft = 0b0 + }; + walkparams.emec = if HaveFeatMEC() then SCTLR2_EL3[EMEC] else 0b0; + return(walkparams) +} + +val AArch64_GetS1TTWParams : (Regime, SecurityState, bits(64)) -> S1TTWParams + +function AArch64_GetS1TTWParams (regime, ss, va) = { + walkparams : S1TTWParams = undefined; + let varange : VARange = AArch64_GetVARange(va); + match regime { + Regime_EL3 => { + walkparams = AArch64_S1TTWParamsEL3() + }, + Regime_EL2 => { + walkparams = AArch64_S1TTWParamsEL2(ss) + }, + Regime_EL20 => { + walkparams = AArch64_S1TTWParamsEL20(ss, varange) + }, + Regime_EL10 => { + walkparams = AArch64_S1TTWParamsEL10(varange) + }, + _ => () + }; + return(walkparams) +} + +val CalculateBottomPACBit : bits(1) -> int + +function CalculateBottomPACBit top_bit = { + let regime : Regime = TranslationRegime(PSTATE.EL); + let ss : SecurityState = CurrentSecurityState(); + let walkparams : S1TTWParams = AArch64_GetS1TTWParams(regime, ss, Replicate(top_bit, 64)); + let 'bottom_PAC_bit = 64 - UInt(AArch64_PACEffectiveTxSZ(regime, walkparams)); + return(bottom_PAC_bit) +} + +val HaveEnhancedPAC : unit -> bool + +function HaveEnhancedPAC () = { + return(IsFeatureImplemented(FEAT_EPAC)) +} + +val HaveEnhancedPAC2 : unit -> bool + +function HaveEnhancedPAC2 () = { + return(IsFeatureImplemented(FEAT_PAuth2)) +} + +val HaveFPAC : unit -> bool + +function HaveFPAC () = { + return(IsFeatureImplemented(FEAT_FPAC)) +} + +val HaveFPACCombined : unit -> bool + +function HaveFPACCombined () = { + return(IsFeatureImplemented(FEAT_FPACCOMBINE)) +} + +val ConstPACField : unit -> bool + +function ConstPACField () = { + return(IsFeatureImplemented(FEAT_CONSTPACFIELD)) +} + +val HavePACQARMA3Generic : unit -> bool + +function HavePACQARMA3Generic () = { + return(IsFeatureImplemented(FEAT_PACQARMA3)) +} + +val HavePACQARMA3Auth : unit -> bool + +function HavePACQARMA3Auth () = { + return(IsFeatureImplemented(FEAT_PACQARMA3)) +} + +val HavePACQARMA5Generic : unit -> bool + +function HavePACQARMA5Generic () = { + return(IsFeatureImplemented(FEAT_PACQARMA5)) +} + +val HavePACQARMA5Auth : unit -> bool + +function HavePACQARMA5Auth () = { + return(IsFeatureImplemented(FEAT_PACQARMA5)) +} + +val HavePACIMPGeneric : unit -> bool + +function HavePACIMPGeneric () = { + return(IsFeatureImplemented(FEAT_PACIMP)) +} + +val HavePACIMPAuth : unit -> bool + +function HavePACIMPAuth () = { + return(IsFeatureImplemented(FEAT_PACIMP)) +} + +val PtrHasUpperAndLowerAddRanges : unit -> bool + +function PtrHasUpperAndLowerAddRanges () = { + let regime : Regime = TranslationRegime(PSTATE.EL); + return(HasUnprivileged(regime)) +} + +val ComputePACIMPDEF : (bits(64), bits(64), bits(64), bits(64)) -> bits(64) + +val PACCellInvShuffle : bits(64) -> bits(64) + +function PACCellInvShuffle indata = { + outdata : bits(64) = undefined; + outdata[3 .. 0] = indata[15 .. 12]; + outdata[7 .. 4] = indata[27 .. 24]; + outdata[11 .. 8] = indata[51 .. 48]; + outdata[15 .. 12] = indata[39 .. 36]; + outdata[19 .. 16] = indata[59 .. 56]; + outdata[23 .. 20] = indata[47 .. 44]; + outdata[27 .. 24] = indata[7 .. 4]; + outdata[31 .. 28] = indata[19 .. 16]; + outdata[35 .. 32] = indata[35 .. 32]; + outdata[39 .. 36] = indata[55 .. 52]; + outdata[43 .. 40] = indata[31 .. 28]; + outdata[47 .. 44] = indata[11 .. 8]; + outdata[51 .. 48] = indata[23 .. 20]; + outdata[55 .. 52] = indata[3 .. 0]; + outdata[59 .. 56] = indata[43 .. 40]; + outdata[63 .. 60] = indata[63 .. 60]; + return(outdata) +} + +val PACCellShuffle : bits(64) -> bits(64) + +function PACCellShuffle indata = { + outdata : bits(64) = undefined; + outdata[3 .. 0] = indata[55 .. 52]; + outdata[7 .. 4] = indata[27 .. 24]; + outdata[11 .. 8] = indata[47 .. 44]; + outdata[15 .. 12] = indata[3 .. 0]; + outdata[19 .. 16] = indata[31 .. 28]; + outdata[23 .. 20] = indata[51 .. 48]; + outdata[27 .. 24] = indata[7 .. 4]; + outdata[31 .. 28] = indata[43 .. 40]; + outdata[35 .. 32] = indata[35 .. 32]; + outdata[39 .. 36] = indata[15 .. 12]; + outdata[43 .. 40] = indata[59 .. 56]; + outdata[47 .. 44] = indata[23 .. 20]; + outdata[51 .. 48] = indata[11 .. 8]; + outdata[55 .. 52] = indata[39 .. 36]; + outdata[59 .. 56] = indata[19 .. 16]; + outdata[63 .. 60] = indata[63 .. 60]; + return(outdata) +} + +val PACInvSub : bits(64) -> bits(64) + +function PACInvSub Tinput = { + Toutput : bits(64) = undefined; + foreach (i from 0 to 15 by 1 in inc) { + match Tinput[4 * i + 3 .. 4 * i] { + 0b0000 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0101 + }, + 0b0001 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1110 + }, + 0b0010 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1101 + }, + 0b0011 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1000 + }, + 0b0100 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1010 + }, + 0b0101 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1011 + }, + 0b0110 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0001 + }, + 0b0111 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1001 + }, + 0b1000 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0010 + }, + 0b1001 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0110 + }, + 0b1010 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1111 + }, + 0b1011 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0000 + }, + 0b1100 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0100 + }, + 0b1101 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1100 + }, + 0b1110 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0111 + }, + 0b1111 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0011 + }, + _ => () + } + }; + return(Toutput) +} + +val RotCell : forall 'amount, + (0 <= 4 - 'amount & 7 - 'amount < 8). + (bits(4), int('amount)) -> bits(4) + +function RotCell (incell_name, amount) = { + tmp : bits(8) = undefined; + tmp[7 .. 0] = incell_name[3 .. 0] @ incell_name[3 .. 0]; + let outcell : bits(4) = tmp[7 - amount .. 4 - amount]; + return(outcell) +} + +val PACMult : bits(64) -> bits(64) + +function PACMult Sinput = { + t0 : bits(4) = undefined; + t1 : bits(4) = undefined; + t2 : bits(4) = undefined; + t3 : bits(4) = undefined; + Soutput : bits(64) = undefined; + foreach (i from 0 to 3 by 1 in inc) { + t0[3 .. 0] = EOR(RotCell(Sinput[4 * (i + 8) + 3 .. 4 * (i + 8)], 1), RotCell(Sinput[4 * (i + 4) + 3 .. 4 * (i + 4)], 2)); + t0[3 .. 0] = EOR(t0[3 .. 0], RotCell(Sinput[4 * i + 3 .. 4 * i], 1)); + t1[3 .. 0] = EOR(RotCell(Sinput[4 * (i + 12) + 3 .. 4 * (i + 12)], 1), RotCell(Sinput[4 * (i + 4) + 3 .. 4 * (i + 4)], 1)); + t1[3 .. 0] = EOR(t1[3 .. 0], RotCell(Sinput[4 * i + 3 .. 4 * i], 2)); + t2[3 .. 0] = EOR(RotCell(Sinput[4 * (i + 12) + 3 .. 4 * (i + 12)], 2), RotCell(Sinput[4 * (i + 8) + 3 .. 4 * (i + 8)], 1)); + t2[3 .. 0] = EOR(t2[3 .. 0], RotCell(Sinput[4 * i + 3 .. 4 * i], 1)); + t3[3 .. 0] = EOR(RotCell(Sinput[4 * (i + 12) + 3 .. 4 * (i + 12)], 1), RotCell(Sinput[4 * (i + 8) + 3 .. 4 * (i + 8)], 2)); + t3[3 .. 0] = EOR(t3[3 .. 0], RotCell(Sinput[4 * (i + 4) + 3 .. 4 * (i + 4)], 1)); + Soutput[4 * i + 3 .. 4 * i] = t3[3 .. 0]; + Soutput[4 * (i + 4) + 3 .. 4 * (i + 4)] = t2[3 .. 0]; + Soutput[4 * (i + 8) + 3 .. 4 * (i + 8)] = t1[3 .. 0]; + Soutput[4 * (i + 12) + 3 .. 4 * (i + 12)] = t0[3 .. 0] + }; + return(Soutput) +} + +val PACSub : bits(64) -> bits(64) + +function PACSub Tinput = { + Toutput : bits(64) = undefined; + foreach (i from 0 to 15 by 1 in inc) { + match Tinput[4 * i + 3 .. 4 * i] { + 0b0000 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1011 + }, + 0b0001 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0110 + }, + 0b0010 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1000 + }, + 0b0011 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1111 + }, + 0b0100 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1100 + }, + 0b0101 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0000 + }, + 0b0110 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1001 + }, + 0b0111 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1110 + }, + 0b1000 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0011 + }, + 0b1001 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0111 + }, + 0b1010 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0100 + }, + 0b1011 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0101 + }, + 0b1100 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1101 + }, + 0b1101 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0010 + }, + 0b1110 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0001 + }, + 0b1111 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1010 + }, + _ => () + } + }; + return(Toutput) +} + +val PACSub1 : bits(64) -> bits(64) + +function PACSub1 Tinput = { + Toutput : bits(64) = undefined; + foreach (i from 0 to 15 by 1 in inc) { + match Tinput[4 * i + 3 .. 4 * i] { + 0b0000 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1010 + }, + 0b0001 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1101 + }, + 0b0010 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1110 + }, + 0b0011 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0110 + }, + 0b0100 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1111 + }, + 0b0101 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0111 + }, + 0b0110 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0011 + }, + 0b0111 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0101 + }, + 0b1000 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1001 + }, + 0b1001 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1000 + }, + 0b1010 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0000 + }, + 0b1011 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1100 + }, + 0b1100 => { + Toutput[4 * i + 3 .. 4 * i] = 0b1011 + }, + 0b1101 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0001 + }, + 0b1110 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0010 + }, + 0b1111 => { + Toutput[4 * i + 3 .. 4 * i] = 0b0100 + }, + _ => () + } + }; + return(Toutput) +} + +val TweakCellInvRot : bits(4) -> bits(4) + +function TweakCellInvRot incell_name = { + outcell : bits(4) = undefined; + outcell[3] = Bit([incell_name[2]]); + outcell[2] = Bit([incell_name[1]]); + outcell[1] = Bit([incell_name[0]]); + outcell[0] = Bit(EOR([incell_name[0]], [incell_name[3]])); + return(outcell) +} + +val TweakInvShuffle : bits(64) -> bits(64) + +function TweakInvShuffle indata = { + outdata : bits(64) = undefined; + outdata[3 .. 0] = TweakCellInvRot(indata[51 .. 48]); + outdata[7 .. 4] = indata[55 .. 52]; + outdata[11 .. 8] = indata[23 .. 20]; + outdata[15 .. 12] = indata[27 .. 24]; + outdata[19 .. 16] = indata[3 .. 0]; + outdata[23 .. 20] = indata[7 .. 4]; + outdata[27 .. 24] = TweakCellInvRot(indata[11 .. 8]); + outdata[31 .. 28] = indata[15 .. 12]; + outdata[35 .. 32] = TweakCellInvRot(indata[31 .. 28]); + outdata[39 .. 36] = TweakCellInvRot(indata[63 .. 60]); + outdata[43 .. 40] = TweakCellInvRot(indata[59 .. 56]); + outdata[47 .. 44] = TweakCellInvRot(indata[19 .. 16]); + outdata[51 .. 48] = indata[35 .. 32]; + outdata[55 .. 52] = indata[39 .. 36]; + outdata[59 .. 56] = indata[43 .. 40]; + outdata[63 .. 60] = TweakCellInvRot(indata[47 .. 44]); + return(outdata) +} + +val TweakCellRot : bits(4) -> bits(4) + +function TweakCellRot incell_name = { + outcell : bits(4) = undefined; + outcell[3] = Bit(EOR([incell_name[0]], [incell_name[1]])); + outcell[2] = Bit([incell_name[3]]); + outcell[1] = Bit([incell_name[2]]); + outcell[0] = Bit([incell_name[1]]); + return(outcell) +} + +val TweakShuffle : bits(64) -> bits(64) + +function TweakShuffle indata = { + outdata : bits(64) = undefined; + outdata[3 .. 0] = indata[19 .. 16]; + outdata[7 .. 4] = indata[23 .. 20]; + outdata[11 .. 8] = TweakCellRot(indata[27 .. 24]); + outdata[15 .. 12] = indata[31 .. 28]; + outdata[19 .. 16] = TweakCellRot(indata[47 .. 44]); + outdata[23 .. 20] = indata[11 .. 8]; + outdata[27 .. 24] = indata[15 .. 12]; + outdata[31 .. 28] = TweakCellRot(indata[35 .. 32]); + outdata[35 .. 32] = indata[51 .. 48]; + outdata[39 .. 36] = indata[55 .. 52]; + outdata[43 .. 40] = indata[59 .. 56]; + outdata[47 .. 44] = TweakCellRot(indata[63 .. 60]); + outdata[51 .. 48] = TweakCellRot(indata[3 .. 0]); + outdata[55 .. 52] = indata[7 .. 4]; + outdata[59 .. 56] = TweakCellRot(indata[43 .. 40]); + outdata[63 .. 60] = TweakCellRot(indata[39 .. 36]); + return(outdata) +} + +val ComputePACQARMA : forall ('isqarma3 : Bool). + (bits(64), bits(64), bits(64), bits(64), bool('isqarma3)) -> bits(64) + +function ComputePACQARMA (data, modifier, key0, key1, isqarma3) = { + roundkey : bits(64) = undefined; + let Alpha : bits(64) = 0xC0AC29B7C97C50DD; + iterations : {2, 4} = 2; + RC[0] = 0x0000000000000000; + RC[1] = 0x13198A2E03707344; + RC[2] = 0xA4093822299F31D0; + if isqarma3 then { + iterations = 2 + } else { + iterations = 4; + RC[3] = 0x082EFA98EC4E6C89; + RC[4] = 0x452821E638D01377 + }; + let 'iterations = iterations; + let modk0 : bits(64) = ([key0[0]] @ key0[63 .. 2]) @ EOR([key0[63]], [key0[1]]); + runningmod : bits(64) = modifier; + workingval : bits(64) = EOR(data, key0); + foreach (i from 0 to iterations by 1 in inc) { + roundkey = EOR(key1, runningmod); + workingval = EOR(workingval, roundkey); + workingval = EOR(workingval, RC[i]); + if i > 0 then { + workingval = PACCellShuffle(workingval); + workingval = PACMult(workingval) + }; + if isqarma3 then { + workingval = PACSub1(workingval) + } else { + workingval = PACSub(workingval) + }; + runningmod = TweakShuffle(runningmod[63 .. 0]) + }; + roundkey : bits(64) = EOR(modk0, runningmod); + workingval : bits(64) = EOR(workingval, roundkey); + workingval : bits(64) = PACCellShuffle(workingval); + workingval : bits(64) = PACMult(workingval); + if isqarma3 then { + workingval = PACSub1(workingval) + } else { + workingval = PACSub(workingval) + }; + workingval : bits(64) = PACCellShuffle(workingval); + workingval : bits(64) = PACMult(workingval); + workingval : bits(64) = EOR(key1, workingval); + workingval : bits(64) = PACCellInvShuffle(workingval); + if isqarma3 then { + workingval = PACSub1(workingval) + } else { + workingval = PACInvSub(workingval) + }; + workingval : bits(64) = PACMult(workingval); + workingval : bits(64) = PACCellInvShuffle(workingval); + workingval : bits(64) = EOR(workingval, key0); + workingval : bits(64) = EOR(workingval, runningmod); + foreach (i from 0 to iterations by 1 in inc) { + if isqarma3 then { + workingval = PACSub1(workingval) + } else { + workingval = PACInvSub(workingval) + }; + if i < iterations then { + workingval = PACMult(workingval); + workingval = PACCellInvShuffle(workingval) + }; + runningmod = TweakInvShuffle(runningmod[63 .. 0]); + roundkey = EOR(key1, runningmod); + workingval = EOR(workingval, RC[iterations - i]); + workingval = EOR(workingval, roundkey); + workingval = EOR(workingval, Alpha) + }; + let workingval : bits(64) = EOR(workingval, modk0); + return(workingval) +} + +val UsePACIMP : forall ('isgeneric : Bool). bool('isgeneric) -> bool + +function UsePACIMP isgeneric = { + return(if isgeneric then HavePACIMPGeneric() else HavePACIMPAuth()) +} + +val UsePACQARMA3 : forall ('isgeneric : Bool). bool('isgeneric) -> bool + +function UsePACQARMA3 isgeneric = { + return(if isgeneric then HavePACQARMA3Generic() else HavePACQARMA3Auth()) +} + +val UsePACQARMA5 : forall ('isgeneric : Bool). bool('isgeneric) -> bool + +function UsePACQARMA5 isgeneric = { + return(if isgeneric then HavePACQARMA5Generic() else HavePACQARMA5Auth()) +} + +val ComputePAC : forall ('isgeneric : Bool). + (bits(64), bits(64), bits(64), bits(64), bool('isgeneric)) -> bits(64) + +function ComputePAC (data, modifier, key0, key1, isgeneric) = { + if UsePACIMP(isgeneric) then { + return(ComputePACIMPDEF(data, modifier, key0, key1)) + }; + if UsePACQARMA3(isgeneric) then { + let isqarma3 : bool = true; + return(ComputePACQARMA(data, modifier, key0, key1, isqarma3)) + }; + if UsePACQARMA5(isgeneric) then { + let isqarma3 : bool = false; + return(ComputePACQARMA(data, modifier, key0, key1, isqarma3)) + } else { + return(undefined : bits(64)) + } +} + +val Strip : forall ('data : Bool). (bits(64), bool('data)) -> bits(64) + +function Strip (A, data) = { + original_ptr : bits(64) = undefined; + let tbi : bool = EffectiveTBI(A, not_bool(data), PSTATE.EL) == 0b1; + let mtx : bool = EffectiveMTX(A, not_bool(data), PSTATE.EL) == 0b1; + let 'bottom_PAC_bit = CalculateBottomPACBit([A[55]]); + let extfield : bits(64) = Replicate([A[55]], 64); + if tbi & bottom_PAC_bit >= 55 then { + return(A) + }; + if tbi then { + assert(constraint((0 <= 56 - 'bottom_PAC_bit - 1 & 56 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + original_ptr = (A[63 .. 56] @ extfield[56 - bottom_PAC_bit - 1 .. 0]) @ A[bottom_PAC_bit - 1 .. 0] + } else if mtx then { + assert(constraint((0 <= 56 - 'bottom_PAC_bit - 1 & 56 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + original_ptr = ((extfield[63 .. 60] @ A[59 .. 56]) @ extfield[56 - bottom_PAC_bit - 1 .. 0]) @ A[bottom_PAC_bit - 1 .. 0] + } else { + assert(constraint((0 <= 64 - 'bottom_PAC_bit - 1 & 64 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + original_ptr = extfield[64 - bottom_PAC_bit - 1 .. 0] @ A[bottom_PAC_bit - 1 .. 0] + }; + return(original_ptr) +} + +val AArch64_PACFailException : bits(2) -> unit + +function AArch64_PACFailException syndrome = { + let route_to_el2 : bool = (PSTATE.EL == EL0 & EL2Enabled()) & HCR_EL2[TGE] == 0b1; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_PACFail); + except.syndrome[1 .. 0] = syndrome; + except.syndrome[24 .. 2] = Zeros(23); + if UInt(PSTATE.EL) > UInt(EL0) then { + AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset) + } else if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +val Auth : forall ('data : Bool) ('is_combined : Bool). + (bits(64), bits(64), bits(128), bool('data), bits(1), bool('is_combined)) -> bits(64) + +function Auth (ptr, modifier, K, data, key_number, is_combined) = { + result : bits(64) = undefined; + original_ptr : bits(64) = undefined; + error_code : bits(2) = undefined; + let isgeneric : bool = false; + let tbi : bool = EffectiveTBI(ptr, not_bool(data), PSTATE.EL) == 0b1; + let mtx : bool = EffectiveMTX(ptr, not_bool(data), PSTATE.EL) == 0b1; + let 'bottom_PAC_bit = CalculateBottomPACBit([ptr[55]]); + let extfield : bits(64) = Replicate([ptr[55]], 64); + if tbi & bottom_PAC_bit >= 55 then { + return(ptr) + }; + if tbi then { + assert(constraint((0 <= 56 - 'bottom_PAC_bit - 1 & 56 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + original_ptr = (ptr[63 .. 56] @ extfield[56 - bottom_PAC_bit - 1 .. 0]) @ ptr[bottom_PAC_bit - 1 .. 0] + } else if mtx then { + assert(constraint((0 <= 56 - 'bottom_PAC_bit - 1 & 56 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + original_ptr = ((extfield[63 .. 60] @ ptr[59 .. 56]) @ extfield[56 - bottom_PAC_bit - 1 .. 0]) @ ptr[bottom_PAC_bit - 1 .. 0] + } else { + assert(constraint((0 <= 64 - 'bottom_PAC_bit - 1 & 64 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + original_ptr = extfield[64 - bottom_PAC_bit - 1 .. 0] @ ptr[bottom_PAC_bit - 1 .. 0] + }; + let PAC : bits(64) = ComputePAC(original_ptr, modifier, K[127 .. 64], K[63 .. 0], isgeneric); + if tbi then { + if not_bool(HaveEnhancedPAC2()) then { + assert(constraint((0 <= 'bottom_PAC_bit & 'bottom_PAC_bit <= 54))); + if PAC[54 .. bottom_PAC_bit] == ptr[54 .. bottom_PAC_bit] then { + result = original_ptr + } else { + let error_code : bits(2) = key_number @ not_vec(key_number); + result = (original_ptr[63 .. 55] @ error_code) @ original_ptr[52 .. 0] + } + } else { + result = ptr; + assert(constraint((0 <= 'bottom_PAC_bit & 'bottom_PAC_bit <= 54))); + result[54 .. bottom_PAC_bit] = EOR(result[54 .. bottom_PAC_bit], PAC[54 .. bottom_PAC_bit]); + if HaveFPACCombined() | HaveFPAC() & not_bool(is_combined) then { + if result[54 .. bottom_PAC_bit] != Replicate([result[55]], 55 - bottom_PAC_bit) then { + let error_code : bits(2) = (if data then 0b1 else 0b0) @ key_number; + AArch64_PACFailException(error_code) + }; + () + }; + () + } + } else if mtx then { + assert(HaveEnhancedPAC2()); + result = ptr; + assert(constraint((0 <= 'bottom_PAC_bit & 'bottom_PAC_bit <= 54))); + result[54 .. bottom_PAC_bit] = EOR(result[54 .. bottom_PAC_bit], PAC[54 .. bottom_PAC_bit]); + result[63 .. 60] = EOR(result[63 .. 60], PAC[63 .. 60]); + if HaveFPACCombined() | HaveFPAC() & not_bool(is_combined) then { + if result[54 .. bottom_PAC_bit] != Replicate([result[55]], 55 - bottom_PAC_bit) | result[63 .. 60] != Replicate([result[55]], 4) then { + let error_code : bits(2) = (if data then 0b1 else 0b0) @ key_number; + AArch64_PACFailException(error_code) + }; + () + }; + () + } else { + if not_bool(HaveEnhancedPAC2()) then { + assert(constraint((0 <= 'bottom_PAC_bit & 'bottom_PAC_bit <= 54))); + if PAC[54 .. bottom_PAC_bit] == ptr[54 .. bottom_PAC_bit] & PAC[63 .. 56] == ptr[63 .. 56] then { + result = original_ptr + } else { + let error_code : bits(2) = key_number @ not_vec(key_number); + result = ([original_ptr[63]] @ error_code) @ original_ptr[60 .. 0] + } + } else { + result = ptr; + assert(constraint((0 <= 'bottom_PAC_bit & 'bottom_PAC_bit <= 54))); + result[54 .. bottom_PAC_bit] = EOR(result[54 .. bottom_PAC_bit], PAC[54 .. bottom_PAC_bit]); + result[63 .. 56] = EOR(result[63 .. 56], PAC[63 .. 56]); + if HaveFPACCombined() | HaveFPAC() & not_bool(is_combined) then { + if result[63 .. bottom_PAC_bit] != Replicate([result[55]], 64 - bottom_PAC_bit) then { + let error_code : bits(2) = (if data then 0b1 else 0b0) @ key_number; + AArch64_PACFailException(error_code) + }; + () + }; + () + } + }; + return(result) +} + +val TrapPACUse : bits(2) -> unit + +function TrapPACUse target_el = { + assert((HaveEL(target_el) & target_el != EL0) & UInt(target_el) >= UInt(PSTATE.EL)); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = 0; + let except : ExceptionRecord = ExceptionSyndrome(Exception_PACTrap); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AddPAC : forall ('data : Bool). + (bits(64), bits(64), bits(128), bool('data)) -> bits(64) + +function AddPAC (ptr, modifier, K, data) = { + result : bits(64) = undefined; + ext_ptr : bits(64) = undefined; + selbit : bits(1) = undefined; + let isgeneric : bool = false; + let tbi : bool = EffectiveTBI(ptr, not_bool(data), PSTATE.EL) == 0b1; + let mtx : bool = EffectiveMTX(ptr, not_bool(data), PSTATE.EL) == 0b1; + let 'top_bit = if tbi then 55 else 63; + if PtrHasUpperAndLowerAddRanges() then { + assert(S1TranslationRegime__1() == EL1 | S1TranslationRegime__1() == EL2); + if S1TranslationRegime__1() == EL1 then { + if data then { + if TCR_EL1[TBI1] == 0b1 | TCR_EL1[TBI0] == 0b1 then { + selbit = [ptr[55]] + } else { + selbit = [ptr[63]] + } + } else { + if TCR_EL1[TBI1] == 0b1 & TCR_EL1[TBID1] == 0b0 | TCR_EL1[TBI0] == 0b1 & TCR_EL1[TBID0] == 0b0 then { + selbit = [ptr[55]] + } else { + selbit = [ptr[63]] + } + } + } else { + if data then { + if TCR_EL2[TBI1] == 0b1 | TCR_EL2[TBI0] == 0b1 then { + selbit = [ptr[55]] + } else { + selbit = [ptr[63]] + } + } else { + if TCR_EL2[TBI1] == 0b1 & TCR_EL2[TBID1] == 0b0 | TCR_EL2[TBI0] == 0b1 & TCR_EL2[TBID0] == 0b0 then { + selbit = [ptr[55]] + } else { + selbit = [ptr[63]] + } + } + } + } else { + selbit = if tbi then [ptr[55]] else [ptr[63]] + }; + if HaveEnhancedPAC2() & ConstPACField() then { + selbit = [ptr[55]] + }; + let selbit = selbit; + let 'bottom_PAC_bit = CalculateBottomPACBit(selbit); + if tbi & bottom_PAC_bit >= 55 then { + return(ptr) + }; + let extfield : bits(64) = Replicate(selbit, 64); + if tbi then { + assert(constraint((0 <= 56 - 'bottom_PAC_bit - 1 & 56 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + ext_ptr = (ptr[63 .. 56] @ extfield[56 - bottom_PAC_bit - 1 .. 0]) @ ptr[bottom_PAC_bit - 1 .. 0] + } else if mtx then { + assert(constraint((0 <= 56 - 'bottom_PAC_bit - 1 & 56 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + ext_ptr = ((extfield[63 .. 60] @ ptr[59 .. 56]) @ extfield[56 - bottom_PAC_bit - 1 .. 0]) @ ptr[bottom_PAC_bit - 1 .. 0] + } else { + assert(constraint((0 <= 64 - 'bottom_PAC_bit - 1 & 64 - 'bottom_PAC_bit - 1 < 64))); + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + ext_ptr = extfield[64 - bottom_PAC_bit - 1 .. 0] @ ptr[bottom_PAC_bit - 1 .. 0] + }; + PAC : bits(64) = ComputePAC(ext_ptr, modifier, K[127 .. 64], K[63 .. 0], isgeneric); + unusedbits_mask : bits(64) = Zeros(64); + assert(constraint((0 <= 'bottom_PAC_bit & 'bottom_PAC_bit <= 54))); + unusedbits_mask[54 .. bottom_PAC_bit] = Ones(54 - bottom_PAC_bit + 1); + if tbi then { + unusedbits_mask[63 .. 56] = Ones(8) + } else if mtx then { + unusedbits_mask[63 .. 60] = Ones(4) + } else (); + if not_bool(IsZero(ptr & unusedbits_mask)) & (ptr & unusedbits_mask) != unusedbits_mask then { + if HaveEnhancedPAC() then { + PAC = 0x0000000000000000 + } else if not_bool(HaveEnhancedPAC2()) then { + PAC[top_bit - 1] = Bit(not_vec([PAC[top_bit - 1]])) + } else () + }; + if not_bool(HaveEnhancedPAC2()) then { + if tbi then { + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + result = ((ptr[63 .. 56] @ selbit) @ PAC[54 .. bottom_PAC_bit]) @ ptr[bottom_PAC_bit - 1 .. 0] + } else { + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + result = ((PAC[63 .. 56] @ selbit) @ PAC[54 .. bottom_PAC_bit]) @ ptr[bottom_PAC_bit - 1 .. 0]; + assert(not_bool(mtx)) + } + } else { + if tbi then { + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + result = ((ptr[63 .. 56] @ selbit) @ EOR(ptr[54 .. bottom_PAC_bit], PAC[54 .. bottom_PAC_bit])) @ ptr[bottom_PAC_bit - 1 .. 0] + } else if mtx then { + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + result = (((EOR(ptr[63 .. 60], PAC[63 .. 60]) @ ptr[59 .. 56]) @ selbit) @ EOR(ptr[54 .. bottom_PAC_bit], PAC[54 .. bottom_PAC_bit])) @ ptr[bottom_PAC_bit - 1 .. 0] + } else { + assert(constraint((0 <= 'bottom_PAC_bit - 1 & 'bottom_PAC_bit - 1 < 64))); + result = ((EOR(ptr[63 .. 56], PAC[63 .. 56]) @ selbit) @ EOR(ptr[54 .. bottom_PAC_bit], PAC[54 .. bottom_PAC_bit])) @ ptr[bottom_PAC_bit - 1 .. 0] + } + }; + return(result) +} + +type APIAKeyHi_EL1_Type = bits(64) + +register APIAKeyHi_EL1 : APIAKeyHi_EL1_Type + +type APIAKeyLo_EL1_Type = bits(64) + +register APIAKeyLo_EL1 : APIAKeyLo_EL1_Type + +val AddPACIA : (bits(64), bits(64)) -> bits(64) + +function AddPACIA (x, y) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1[63 .. 0] @ APIAKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnIA] else SCTLR_EL2[EnIA]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnIA]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnIA]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnIA]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(AddPAC(x, y, APIAKey_EL1, false)) + } +} + +type APIBKeyHi_EL1_Type = bits(64) + +register APIBKeyHi_EL1 : APIBKeyHi_EL1_Type + +type APIBKeyLo_EL1_Type = bits(64) + +register APIBKeyLo_EL1 : APIBKeyLo_EL1_Type + +val AddPACIB : (bits(64), bits(64)) -> bits(64) + +function AddPACIB (x, y) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1[63 .. 0] @ APIBKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnIB] else SCTLR_EL2[EnIB]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnIB]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnIB]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnIB]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(AddPAC(x, y, APIBKey_EL1, false)) + } +} + +type APDAKeyHi_EL1_Type = bits(64) + +register APDAKeyHi_EL1 : APDAKeyHi_EL1_Type + +type APDAKeyLo_EL1_Type = bits(64) + +register APDAKeyLo_EL1 : APDAKeyLo_EL1_Type + +val AddPACDA : (bits(64), bits(64)) -> bits(64) + +function AddPACDA (x, y) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APDAKey_EL1 : bits(128) = APDAKeyHi_EL1[63 .. 0] @ APDAKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnDA] else SCTLR_EL2[EnDA]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnDA]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnDA]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnDA]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(AddPAC(x, y, APDAKey_EL1, true)) + } +} + +type APDBKeyHi_EL1_Type = bits(64) + +register APDBKeyHi_EL1 : APDBKeyHi_EL1_Type + +type APDBKeyLo_EL1_Type = bits(64) + +register APDBKeyLo_EL1 : APDBKeyLo_EL1_Type + +val AddPACDB : (bits(64), bits(64)) -> bits(64) + +function AddPACDB (x, y) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APDBKey_EL1 : bits(128) = APDBKeyHi_EL1[63 .. 0] @ APDBKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnDB] else SCTLR_EL2[EnDB]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnDB]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnDB]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnDB]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(AddPAC(x, y, APDBKey_EL1, true)) + } +} + +type APGAKeyHi_EL1_Type = bits(64) + +register APGAKeyHi_EL1 : APGAKeyHi_EL1_Type + +type APGAKeyLo_EL1_Type = bits(64) + +register APGAKeyLo_EL1 : APGAKeyLo_EL1_Type + +val AddPACGA : (bits(64), bits(64)) -> bits(64) + +function AddPACGA (x, y) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + let isgeneric : bool = true; + let APGAKey_EL1 : bits(128) = APGAKeyHi_EL1[63 .. 0] @ APGAKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(ComputePAC(x, y, APGAKey_EL1[127 .. 64], APGAKey_EL1[63 .. 0], isgeneric)[63 .. 32] @ Zeros(32)) + } +} + +val AuthIA : forall ('is_combined : Bool). + (bits(64), bits(64), bool('is_combined)) -> bits(64) + +function AuthIA (x, y, is_combined) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1[63 .. 0] @ APIAKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnIA] else SCTLR_EL2[EnIA]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnIA]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnIA]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnIA]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(Auth(x, y, APIAKey_EL1, false, 0b0, is_combined)) + } +} + +val AuthIB : forall ('is_combined : Bool). + (bits(64), bits(64), bool('is_combined)) -> bits(64) + +function AuthIB (x, y, is_combined) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1[63 .. 0] @ APIBKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnIB] else SCTLR_EL2[EnIB]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnIB]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnIB]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnIB]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(Auth(x, y, APIBKey_EL1, false, 0b1, is_combined)) + } +} + +val AuthDA : forall ('is_combined : Bool). + (bits(64), bits(64), bool('is_combined)) -> bits(64) + +function AuthDA (x, y, is_combined) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APDAKey_EL1 : bits(128) = APDAKeyHi_EL1[63 .. 0] @ APDAKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnDA] else SCTLR_EL2[EnDA]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnDA]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnDA]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnDA]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(Auth(x, y, APDAKey_EL1, true, 0b0, is_combined)) + } +} + +val AuthDB : forall ('is_combined : Bool). + (bits(64), bits(64), bool('is_combined)) -> bits(64) + +function AuthDB (x, y, is_combined) = { + TrapEL2 : bool = undefined; + TrapEL3 : bool = undefined; + Enable : bits(1) = undefined; + let APDBKey_EL1 : bits(128) = APDBKeyHi_EL1[63 .. 0] @ APDBKeyLo_EL1[63 .. 0]; + match PSTATE.EL { + ? if ? == EL0 => { + let IsEL1Regime : bool = S1TranslationRegime__1() == EL1; + Enable = if IsEL1Regime then SCTLR_EL1[EnDB] else SCTLR_EL2[EnDB]; + TrapEL2 = (EL2Enabled() & HCR_EL2[API] == 0b0) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0); + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL1 => { + Enable = SCTLR_EL1[EnDB]; + TrapEL2 = EL2Enabled() & HCR_EL2[API] == 0b0; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL2 => { + Enable = SCTLR_EL2[EnDB]; + TrapEL2 = false; + TrapEL3 = HaveEL(EL3) & SCR_EL3[API] == 0b0 + }, + ? if ? == EL3 => { + Enable = SCTLR_EL3[EnDB]; + TrapEL2 = false; + TrapEL3 = false + }, + _ => () + }; + if Enable == 0b0 then { + return(x) + } else if TrapEL3 & EL3SDDUndefPriority() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else if TrapEL2 then { + TrapPACUse(EL2); + return(undefined : bits(64)) + } else if TrapEL3 then { + if EL3SDDUndef() then { + throw(Error_Undefined()); + return(undefined : bits(64)) + } else { + TrapPACUse(EL3); + return(undefined : bits(64)) + } + } else { + return(Auth(x, y, APDBKey_EL1, true, 0b1, is_combined)) + } +} + +val X_read : forall 'n 'width, + 'width in {8, 16, 32, 64}. + (int('n), int('width)) -> bits('width) + +function X_read (n, width) = { + assert(n >= 0 & n <= 31); + assert(width == 8 | width == 16 | width == 32 | width == 64); + if n != 31 then { + return(_R(n)[width - 1 .. 0]) + } else { + return(Zeros(width)) + } +} + +val V_read : forall 'n 'width, + 'width in {8, 16, 32, 64, 128}. + (int('n), int('width)) -> bits('width) + +function V_read (n, width) = { + assert(n >= 0 & n <= 31); + assert(width == 8 | width == 16 | width == 32 | width == 64 | width == 128); + return(_Z[n][width - 1 .. 0]) +} + +val Vpart_read : forall 'n 'part 'width, + 'width >= 0. + (int('n), int('part), int('width)) -> bits('width) + +function Vpart_read (n, part, width) = { + assert(n >= 0 & n <= 31); + assert(part == 0 | part == 1); + if part == 0 then { + assert(width < 128); + assert(constraint('width in {8, 16, 32, 64, 128})); + return(V_read(n, width)) + } else { + assert(width == 32 | width == 64); + let vreg : bits(128) = V_read(n, 128); + return(vreg[width * 2 - 1 .. width]) + } +} + +val Vpart_set : forall 'n 'part 'width, + 'width >= 0. + (int('n), int('part), int('width), bits('width)) -> unit + +function Vpart_set (n, part, width, value_name) = { + assert(n >= 0 & n <= 31); + assert(part == 0 | part == 1); + if part == 0 then { + assert(width < 128); + assert(constraint('width in {8, 16, 32, 64, 128})); + V_set(n, width) = value_name + } else { + assert(width == 64); + let vreg : bits(64) = V_read(n, 64); + V_set(n, 128) = value_name[63 .. 0] @ vreg + } +} + +val AArch64_ResetGeneralRegisters : unit -> unit + +function AArch64_ResetGeneralRegisters () = { + foreach (i from 0 to 30 by 1 in inc) { + X_set(i, 64) = __UNKNOWN_bits(64) + }; + return() +} + +val AArch64_ResetSIMDFPRegisters : unit -> unit + +function AArch64_ResetSIMDFPRegisters () = { + foreach (i from 0 to 31 by 1 in inc) { + V_set(i, 128) = __UNKNOWN_bits(128) + }; + return() +} + +val AArch64_ResetSpecialRegisters : unit -> unit + +function AArch64_ResetSpecialRegisters () = { + SP_EL0 = __UNKNOWN_bits(64); + SP_EL1 = __UNKNOWN_bits(64); + SPSR_EL1 = Mk_SPSR_EL1_Type(__UNKNOWN_bits(64)); + ELR_EL1 = __UNKNOWN_bits(64); + if HaveEL(EL2) then { + SP_EL2 = __UNKNOWN_bits(64); + SPSR_EL2 = Mk_SPSR_EL2_Type(__UNKNOWN_bits(64)); + ELR_EL2 = __UNKNOWN_bits(64) + }; + if HaveEL(EL3) then { + SP_EL3 = __UNKNOWN_bits(64); + SPSR_EL3 = Mk_SPSR_EL3_Type(__UNKNOWN_bits(64)); + ELR_EL3 = __UNKNOWN_bits(64) + }; + if HaveAArch32EL(EL1) then { + SPSR_fiq.bits[31 .. 0] = __UNKNOWN_bits(32); + SPSR_irq.bits[31 .. 0] = __UNKNOWN_bits(32); + SPSR_abt.bits[31 .. 0] = __UNKNOWN_bits(32); + SPSR_und.bits[31 .. 0] = __UNKNOWN_bits(32) + }; + DLR_EL0 = __UNKNOWN_bits(64); + DSPSR_EL0 = Mk_DSPSR_EL0_Type(__UNKNOWN_bits(64)); + return() +} + +val ELR_read : bits(2) -> bits(64) + +val ELR_read__1 : unit -> bits(64) + +function ELR_read el = { + r : bits(64) = undefined; + match el { + ? if ? == EL1 => { + r = ELR_EL1 + }, + ? if ? == EL2 => { + r = ELR_EL2 + }, + ? if ? == EL3 => { + r = ELR_EL3 + }, + _ => { + Unreachable() + } + }; + return(r) +} + +function ELR_read__1 () = { + assert(PSTATE.EL != EL0); + return(ELR_read(PSTATE.EL)) +} + +bitfield CNTKCTL_Type : bits(32) = + { + EVNTIS : 17..17, + PL0PTEN : 9..9, + PL0VTEN : 8..8, + EVNTI : 7..4, + EVNTDIR : 3..3, + EVNTEN : 2..2, + PL0VCTEN : 1..1, + PL0PCTEN : 0..0 + } + +register _CNTKCTL : CNTKCTL_Type + +val CNTKCTL_read__1 : unit -> CNTKCTL_Type + +function CNTKCTL_read__1 () = { + r : CNTKCTL_Type = _CNTKCTL; + r.bits[31 .. 0] = Slice(CNTKCTL_EL1.bits, 0, 32); + return(r) +} + +val CheckTransactionalSystemAccess : (bits(2), bits(3), bits(4), bits(4), bits(3), bits(1)) -> bool + +function CheckTransactionalSystemAccess (op0, op1, crn, crm, op2, read) = { + match ((((read @ op0) @ op1) @ crn) @ crm) @ op2 { + [bitzero, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, bitone, bitone, _] => { + return(true) + }, + 0b00101101110100001 => { + return(true) + }, + [bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, _] => { + return(true) + }, + [bitzero, bitone, bitone, bitzero, bitone, bitone, bitzero, bitone, bitzero, bitzero, bitzero, bitone, bitzero, bitzero, bitzero, bitzero, _] => { + return(true) + }, + 0b01100001000110000 => { + return(true) + }, + 0b01101110011100100 => { + return(true) + }, + 0b11101100100101001 => { + return(PSTATE.EL == EL0) + }, + 0b11100000100101001 => { + return(PSTATE.EL == EL1 | PSTATE.EL == EL2 & HCR_EL2[E2H] == 0b1) + }, + 0b11110000100101001 => { + return(PSTATE.EL == EL2 & HCR_EL2[E2H] == 0b0) + }, + 0b11111000100101001 => { + return(PSTATE.EL == EL3) + }, + 0b00101101110111000 => { + return(true) + }, + 0b10101101110111001 => { + return(true) + }, + 0b00101101110111010 => { + return(true) + }, + 0b10101101110111011 => { + return(true) + }, + 0b00100001110111110 => { + return(true) + }, + 0b11110100100101001 => { + return(false) + }, + 0b11100000100101010 => { + return(false) + }, + 0b11100000100101000 => { + return(false) + }, + 0b11110100100101000 => { + return(false) + }, + 0b11110000100101000 => { + return(false) + }, + 0b11111000100101000 => { + return(false) + }, + [bitone, bitone, bitone, _, _, _, bitzero, _, _, _, _, _, _, _, _, _, _] => { + return(true) + }, + [bitone, bitone, bitone, _, _, _, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _] => { + return(true) + }, + [bitone, bitone, bitone, _, _, _, bitone, bitzero, bitone, bitzero, _, _, _, _, _, _, _] => { + return(true) + }, + [bitone, bitone, bitone, bitzero, bitzero, bitzero, bitone, bitone, bitzero, bitzero, bitone, _, bitzero, bitzero, bitzero, bitone, bitzero] => { + return(true) + }, + 0b11100011001011011 => { + return(true) + }, + [bitone, bitone, bitone, _, _, _, bitone, bitone, bitzero, bitone, _, _, _, _, _, _, _] => { + return(true) + }, + [bitone, bitone, bitone, _, _, _, bitone, bitone, bitone, bitzero, _, _, _, _, _, _, _] => { + return(true) + }, + 0b00101101110011111 => { + return(true) + }, + [bitzero, bitzero, bitone, bitzero, bitone, bitone, bitzero, bitone, bitone, bitone, bitzero, bitzero, bitone, bitone, bitone, bitzero, _] => { + return(true) + }, + [_, bitone, bitone, _, _, _, bitone, _, bitone, bitone, _, _, _, _, _, _, _] => { + return(__IMPDEF_boolean("")) + }, + _ => { + return(false) + } + } +} + +val AArch64_CheckSystemAccess : (bits(2), bits(3), bits(4), bits(4), bits(3), bits(5), bits(1)) -> unit + +function AArch64_CheckSystemAccess (op0, op1, crn, crm, op2, rt, read) = { + if HaveBTIExt() then { + BranchTargetCheck() + }; + if (HaveTME() & TSTATE.depth > 0) & not_bool(CheckTransactionalSystemAccess(op0, op1, crn, crm, op2, read)) then { + FailTransaction(TMFailure_ERR, false) + }; + return() +} + +val SetInGuardedPage : forall ('guardedpage : Bool). bool('guardedpage) -> unit + +function SetInGuardedPage guardedpage = { + InGuardedPage = guardedpage +} + +val BTypeCompatible_BTI : bits(2) -> bool + +function BTypeCompatible_BTI hintcode = { + match hintcode { + 0b00 => { + return(false) + }, + 0b01 => { + return(PSTATE.BTYPE != 0b11) + }, + 0b10 => { + return(PSTATE.BTYPE != 0b10) + }, + 0b11 => { + return(true) + }, + _ => { + return(undefined : bool) + } + } +} + +val BTypeCompatible_PACIXSP : unit -> bool + +function BTypeCompatible_PACIXSP () = { + index : int = undefined; + if PSTATE.BTYPE == 0b01 | PSTATE.BTYPE == 0b10 then { + return(true) + } else if PSTATE.BTYPE == 0b11 then { + let 'index = if PSTATE.EL == EL0 then 35 else 36; + return([SCTLR_read__1().bits[index]] == 0b0) + } else { + return(false) + } +} + +val AArch64_ExecutingERETInstr : unit -> bool + +function AArch64_ExecutingERETInstr () = { + let instr : bits(32) = ThisInstr(); + return(instr[31 .. 12] == 0b11010110100111110000) +} + +val SetBTypeCompatible : forall ('x : Bool). bool('x) -> unit + +function SetBTypeCompatible x = { + BTypeCompatible = x +} + +val SetBTypeNext : bits(2) -> unit + +function SetBTypeNext x = { + BTypeNext = x +} + +val AArch64_AllocationTagAccessIsEnabled : bits(2) -> bool + +function AArch64_AllocationTagAccessIsEnabled el = { + if SCR_EL3[ATA] == 0b0 & (el == EL0 | el == EL1 | el == EL2) then { + return(false) + }; + if ((HCR_EL2[ATA] == 0b0 & (el == EL0 | el == EL1)) & EL2Enabled()) & (HCR_EL2[E2H] @ HCR_EL2[TGE]) != 0b11 then { + return(false) + }; + let regime : Regime = TranslationRegime(el); + match regime { + Regime_EL3 => { + return(SCTLR_EL3[ATA] == 0b1) + }, + Regime_EL2 => { + return(SCTLR_EL2[ATA] == 0b1) + }, + Regime_EL20 => { + return(if el == EL0 then SCTLR_EL2[ATA0] == 0b1 else + SCTLR_EL2[ATA] == 0b1) + }, + Regime_EL10 => { + return(if el == EL0 then SCTLR_EL1[ATA0] == 0b1 else + SCTLR_EL1[ATA] == 0b1) + }, + _ => { + Unreachable(); + return(undefined : bool) + } + } +} + +bitfield GCR_EL1_Type : bits(64) = {RRND : 16..16, Exclude : 15..0} + +register GCR_EL1 : GCR_EL1_Type + +bitfield RGSR_EL1_Type : bits(64) = {SEED : 55..8, TAG : 3..0} + +register RGSR_EL1 : RGSR_EL1_Type + +val AArch64_NextRandomTagBit : unit -> bits(1) + +function AArch64_NextRandomTagBit () = { + assert(GCR_EL1[RRND] == 0b0); + let lfsr : bits(16) = RGSR_EL1[SEED][15 .. 0]; + let top : bits(1) = EOR(EOR(EOR([lfsr[5]], [lfsr[3]]), [lfsr[2]]), [lfsr[0]]); + RGSR_EL1[SEED][15 .. 0] = top @ lfsr[15 .. 1]; + return(top) +} + +val AArch64_RandomTag : unit -> bits(4) + +function AArch64_RandomTag () = { + tag : bits(4) = undefined; + foreach (i from 0 to 3 by 1 in inc) { + tag[i] = Bit(AArch64_NextRandomTagBit()) + }; + return(tag) +} + +val AArch64_ChooseNonExcludedTag : (bits(4), bits(4), bits(16)) -> bits(4) + +function AArch64_ChooseNonExcludedTag (tag_in, offset_in, exclude) = { + tag : bits(4) = tag_in; + offset : bits(4) = offset_in; + if IsOnes(exclude) then { + return(0b0000) + }; + if offset == 0b0000 then { + while [exclude[UInt(tag)]] == 0b1 do { + tag = tag + 0b0001 + } + }; + while offset != 0b0000 do { + offset = offset - 0b0001; + tag = tag + 0b0001; + while [exclude[UInt(tag)]] == 0b1 do { + tag = tag + 0b0001 + } + }; + return(tag) +} + +val ChooseRandomNonExcludedTag : bits(16) -> bits(4) + +val AllInAlignedQuantity : forall 'alignment 'size. + (bits(64), int('size), int('alignment)) -> bool + +function AllInAlignedQuantity (address, size, alignment) = { + assert(size <= alignment); + return(Align(address + size - 1, alignment) == Align(address, alignment)) +} + +val AArch64_SPAlignmentFault : unit -> unit + +function AArch64_SPAlignmentFault () = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let except : ExceptionRecord = ExceptionSyndrome(Exception_SPAlignment); + target_el : bits(2) = EL1; + if UInt(PSTATE.EL) > UInt(EL1) then { + target_el = PSTATE.EL + } else if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + target_el = EL2 + } else (); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val SP_read : unit -> bits(64) + +function SP_read () = { + if PSTATE.SP == 0b0 then { + return(SP_EL0) + } else { + match PSTATE.EL { + ? if ? == EL0 => { + return(SP_EL0) + }, + ? if ? == EL1 => { + return(SP_EL1) + }, + ? if ? == EL2 => { + return(SP_EL2) + }, + ? if ? == EL3 => { + return(SP_EL3) + }, + _ => { + return(undefined : bits(64)) + } + } + } +} + +val CheckSPAlignment : unit -> unit + +function CheckSPAlignment () = { + let sp : bits(64) = SP_read(); + stack_align_check : bool = undefined; + if PSTATE.EL == EL0 then { + stack_align_check = SCTLR_read__1()[SA0] != 0b0 + } else { + stack_align_check = SCTLR_read__1()[SA] != 0b0 + }; + if stack_align_check & sp != Align(sp, 16) then { + AArch64_SPAlignmentFault() + }; + return() +} + +val AArch64_UnalignedAccessFaults : forall 'size. + (AccessDescriptor, bits(64), int('size)) -> bool + +function AArch64_UnalignedAccessFaults (accdesc, address, size) = { + if AlignmentEnforced() then { + return(true) + } else if accdesc.acctype == AccessType_GCS then { + return(true) + } else if accdesc.rcw then { + return(true) + } else if accdesc.ls64 then { + return(true) + } else if accdesc.exclusive | accdesc.atomicop then { + return(not_bool(HaveLSE2Ext()) | not_bool(AllInAlignedQuantity(address, size, 16))) + } else if (accdesc.acqsc | accdesc.acqpc) | accdesc.relsc then { + return(not_bool(HaveLSE2Ext()) | SCTLR_read__1()[nAA] == 0b0 & not_bool(AllInAlignedQuantity(address, size, 16))) + } else { + return(false) + } +} + +val StoreOnlyTagCheckingEnabled : bits(2) -> bool + +function StoreOnlyTagCheckingEnabled el = { + assert(HaveMTEStoreOnlyExt()); + tcso : bits(1) = undefined; + match el { + ? if ? == EL0 => { + if not_bool(ELIsInHost(el)) then { + tcso = SCTLR_EL1[TCSO0] + } else { + tcso = SCTLR_EL2[TCSO0] + } + }, + ? if ? == EL1 => { + tcso = SCTLR_EL1[TCSO] + }, + ? if ? == EL2 => { + tcso = SCTLR_EL2[TCSO] + }, + _ => { + tcso = SCTLR_EL3[TCSO] + } + }; + return(tcso == 0b1) +} + +val AArch64_AccessIsTagChecked : (bits(64), AccessDescriptor) -> bool + +function AArch64_AccessIsTagChecked (vaddr, accdesc) = { + assert(accdesc.tagchecked); + if UsingAArch32() then { + return(false) + }; + let is_instr : bool = false; + if EffectiveMTX(vaddr, is_instr, PSTATE.EL) == 0b0 & EffectiveTBI(vaddr, is_instr, PSTATE.EL) == 0b0 then { + return(false) + }; + if EffectiveTCMA(vaddr, PSTATE.EL) == 0b1 & (vaddr[59 .. 55] == 0b00000 | vaddr[59 .. 55] == 0b11111) then { + return(false) + }; + if not_bool(AArch64_AllocationTagAccessIsEnabled(accdesc.el)) then { + return(false) + }; + if PSTATE.TCO == 0b1 then { + return(false) + }; + if (HaveMTEStoreOnlyExt() & not_bool(accdesc.write)) & StoreOnlyTagCheckingEnabled(accdesc.el) then { + return(false) + }; + return(true) +} + +val PhysMemTagRead : (AddressDescriptor, AccessDescriptor) -> (PhysMemRetStatus, bits(4)) + +val AArch64_AllocationTagCheck : (AddressDescriptor, AccessDescriptor, bits(4)) -> bool + +function AArch64_AllocationTagCheck (memaddrdesc, accdesc, ptag) = { + memstatus : PhysMemRetStatus = undefined; + readtag : bits(4) = undefined; + if memaddrdesc.memattrs.tags == MemTag_AllocationTagged then { + (memstatus, readtag) = PhysMemTagRead(memaddrdesc, accdesc); + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, 1, accdesc) + }; + return(ptag == readtag) + } else { + return(true) + } +} + +val AArch64_CanonicalTagCheck : (AddressDescriptor, bits(4)) -> bool + +function AArch64_CanonicalTagCheck (memaddrdesc, ptag) = { + let expected_tag : bits(4) = if [memaddrdesc.vaddress[55]] == 0b0 then + 0b0000 + else + 0b1111; + return(ptag == expected_tag) +} + +val AArch64_CheckTag : (AddressDescriptor, AccessDescriptor, bits(4)) -> bool + +function AArch64_CheckTag (memaddrdesc, accdesc, ptag) = { + if memaddrdesc.memattrs.tags == MemTag_AllocationTagged then { + return(AArch64_AllocationTagCheck(memaddrdesc, accdesc, ptag)) + } else if memaddrdesc.memattrs.tags == MemTag_CanonicallyTagged then { + return(AArch64_CanonicalTagCheck(memaddrdesc, ptag)) + } else { + return(true) + } +} + +val AArch64_PhysicalTag : bits(64) -> bits(4) + +function AArch64_PhysicalTag vaddr = { + return(vaddr[59 .. 56]) +} + +val AArch64_EffectiveTCF : bits(2) -> bits(2) + +function AArch64_EffectiveTCF el = { + tcf : bits(2) = undefined; + let regime : Regime = TranslationRegime(el); + match regime { + Regime_EL3 => { + tcf = SCTLR_EL3[TCF] + }, + Regime_EL2 => { + tcf = SCTLR_EL2[TCF] + }, + Regime_EL20 => { + tcf = if el == EL0 then SCTLR_EL2[TCF0] else SCTLR_EL2[TCF] + }, + Regime_EL10 => { + tcf = if el == EL0 then SCTLR_EL1[TCF0] else SCTLR_EL1[TCF] + }, + _ => { + Unreachable() + } + }; + if tcf == 0b11 then { + if not_bool(HaveMTEAsymFaultExt()) then { + let (_, __tup_1 : bits(2)) = ConstrainUnpredictableBits(Unpredictable_RESTCF, 2); + tcf = __tup_1 + }; + () + }; + return(tcf) +} + +val AArch64_RaiseTagCheckFault : (bits(64), FaultRecord) -> unit + +function AArch64_RaiseTagCheckFault (va, fault) = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + target_el : bits(2) = EL1; + if UInt(PSTATE.EL) > UInt(EL1) then { + target_el = PSTATE.EL + } else if (PSTATE.EL == EL0 & EL2Enabled()) & HCR_EL2[TGE] == 0b1 then { + target_el = EL2 + } else (); + let except : ExceptionRecord = AArch64_AbortSyndrome(Exception_DataAbort, fault, va, target_el); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +bitfield TFSRE0_EL1_Type : bits(64) = {TF1 : 1..1, TF0 : 0..0} + +register TFSRE0_EL1 : TFSRE0_EL1_Type + +bitfield TFSR_EL1_Type : bits(64) = {TF1 : 1..1, TF0 : 0..0} + +register TFSR_EL1 : TFSR_EL1_Type + +bitfield TFSR_EL2_Type : bits(64) = {TF1 : 1..1, TF0 : 0..0} + +register TFSR_EL2 : TFSR_EL2_Type + +bitfield TFSR_EL3_Type : bits(64) = {TF0 : 0..0} + +register TFSR_EL3 : TFSR_EL3_Type + +val AArch64_ReportTagCheckFault : (bits(2), bits(1)) -> unit + +function AArch64_ReportTagCheckFault (el, ttbr) = { + match el { + ? if ? == EL3 => { + assert(ttbr == 0b0); + TFSR_EL3[TF0] = 0b1 + }, + ? if ? == EL2 => { + if ttbr == 0b0 then { + TFSR_EL2[TF0] = 0b1 + } else { + TFSR_EL2[TF1] = 0b1 + } + }, + ? if ? == EL1 => { + if ttbr == 0b0 then { + TFSR_EL1[TF0] = 0b1 + } else { + TFSR_EL1[TF1] = 0b1 + } + }, + ? if ? == EL0 => { + if ttbr == 0b0 then { + TFSRE0_EL1[TF0] = 0b1 + } else { + TFSRE0_EL1[TF1] = 0b1 + } + }, + _ => () + } +} + +val AArch64_TagCheckFault : (bits(64), AccessDescriptor) -> unit + +function AArch64_TagCheckFault (vaddress, accdesc) = { + let tcf : bits(2) = AArch64_EffectiveTCF(accdesc.el); + fault : FaultRecord = NoFault__1(accdesc); + fault.statuscode = Fault_TagCheck; + match tcf { + 0b00 => { + return() + }, + 0b01 => { + AArch64_RaiseTagCheckFault(vaddress, fault) + }, + 0b10 => { + if HaveMTEAsyncExt() then { + AArch64_ReportTagCheckFault(accdesc.el, [vaddress[55]]) + } else { + return() + } + }, + 0b11 => { + if HaveMTEAsymFaultExt() then { + if accdesc.read then { + AArch64_RaiseTagCheckFault(vaddress, fault) + } else { + AArch64_ReportTagCheckFault(accdesc.el, [vaddress[55]]) + } + } else { + return() + } + } + } +} + +val NumBreakpointsImplemented : unit -> int + +function NumBreakpointsImplemented () = { + return(__IMPDEF_integer("Number of breakpoints")) +} + +val NumContextAwareBreakpointsImplemented : unit -> int + +function NumContextAwareBreakpointsImplemented () = { + return(__IMPDEF_integer("Number of context-aware breakpoints")) +} + +val AArch64_ReservedBreakpointType : forall 'n. + (int('n), bits(1), bits(4)) -> (Constraint, bits(1), bits(4)) + +function AArch64_ReservedBreakpointType (n, bt2_in, bt_in) = { + bt2 : bits(1) = bt2_in; + bt : bits(4) = bt_in; + reserved : bool = false; + let context_aware : bool = n >= NumBreakpointsImplemented() - NumContextAwareBreakpointsImplemented(); + if bt2 == 0b0 then { + if not_bool((match bt { + [bitzero, _, bitzero, _] => true, + _ => false + }) : bool) & not_bool(context_aware) then { + reserved = true + }; + if (match bt { + [bitone, _, _, _] => true, + _ => false + }) : bool & not_bool(HaveEL(EL2)) then { + reserved = true + }; + if ((match bt { + [bitzero, bitone, bitone, _] => true, + [bitone, bitone, _, _] => true, + _ => false + }) : bool & not_bool(HaveVirtHostExt())) & not_bool(HaveV82Debug()) then { + reserved = true + }; + if ((match bt { + [bitzero, bitone, bitzero, _] => true, + _ => false + }) : bool & not_bool(HaveFeatABLE())) & not_bool(HaveAArch32EL(EL1)) then { + reserved = true + }; + () + } else { + if not_bool((match bt { + [bitzero, _, bitzero, _] => true, + _ => false + }) : bool) then { + reserved = true + }; + () + }; + if reserved then { + c : Constraint = undefined; + (c, (bt2 @ bt)) = ConstrainUnpredictableBits(Unpredictable_RESBPTYPE, 5); + assert(c == Constraint_DISABLED | c == Constraint_UNKNOWN); + if c == Constraint_DISABLED then { + return((c, __UNKNOWN_bit(), __UNKNOWN_bits(4))) + }; + () + }; + return((Constraint_NONE, bt2, bt)) +} + +bitfield CONTEXTIDR_EL2_Type : bits(64) = {PROCID : 31..0} + +register CONTEXTIDR_EL2 : CONTEXTIDR_EL2_Type + +bitfield DBGBCR_EL1_Type : bits(64) = + { + LBNX : 31..30, + SSCE : 29..29, + MASK : 28..24, + BT : 23..20, + LBN : 19..16, + SSC : 15..14, + HMC : 13..13, + BAS : 8..5, + BT2 : 3..3, + PMC : 2..1, + E : 0..0 + } + +register DBGBCR_EL1 : vector(64, DBGBCR_EL1_Type) + +bitfield DBGBVR_EL1_Type : bits(64) = + { + RESS : (63..57 @ (56..53 @ 52..49)), + VA : (56..53 @ (52..49 @ 48..2)), + VMID : (47..40 @ 39..32), + ContextID2 : 63..32, + ContextID : 31..0 + } + +register DBGBVR_EL1 : vector(64, DBGBVR_EL1_Type) + +val DebugAddrTop : unit -> int + +function DebugAddrTop () = { + if Have56BitVAExt() then { + return(55) + } else if Have52BitVAExt() then { + return(52) + } else { + return(48) + } +} + +bitfield EDSCR2_Type : bits(32) = {EHBWE : 3..3} + +register _EDSCR2 : EDSCR2_Type + +val EDSCR2_read : unit -> EDSCR2_Type + +function EDSCR2_read () = { + r : EDSCR2_Type = _EDSCR2; + r.bits[31 .. 0] = Slice(MDSCR_EL1.bits, 32, 32); + return(r) +} + +val HaltOnBreakpointOrWatchpoint : unit -> bool + +function HaltOnBreakpointOrWatchpoint () = { + return((HaltingAllowed() & EDSCR_read()[HDE] == 0b1) & OSLSR_EL1[OSLK] == 0b0) +} + +val NumWatchpointsImplemented : unit -> int + +function NumWatchpointsImplemented () = { + return(__IMPDEF_integer("Number of watchpoints")) +} + +val SelfHostedExtendedBPWPEnabled : unit -> bool + +function SelfHostedExtendedBPWPEnabled () = { + if NumBreakpointsImplemented() <= 16 & NumWatchpointsImplemented() <= 16 then { + return(false) + }; + if HaveEL(EL3) & MDCR_EL3[EBWE] == 0b0 | EL2Enabled() & MDCR_EL2[EBWE] == 0b0 then { + return(false) + }; + return(MDSCR_EL1[EMBWE] == 0b1) +} + +val IsBreakpointEnabled : forall 'n, (0 <= 'n & 'n < 64). int('n) -> bool + +function IsBreakpointEnabled n = { + if n > 15 & (not_bool(HaltOnBreakpointOrWatchpoint()) & not_bool(SelfHostedExtendedBPWPEnabled()) | HaltOnBreakpointOrWatchpoint() & EDSCR2_read()[EHBWE] == 0b0) then { + return(false) + }; + return(DBGBCR_EL1[n][E] == 0b1) +} + +bitfield VTCR_EL2_Type : bits(64) = + { + HAFT : 44..44, + TL0 : 41..41, + GCSH : 40..40, + D128 : 38..38, + S2POE : 37..37, + S2PIE : 36..36, + TL1 : 35..35, + AssuredOnly : 34..34, + SL2 : 33..33, + DS : 32..32, + NSA : 30..30, + NSW : 29..29, + HWU62 : 28..28, + HWU61 : 27..27, + HWU60 : 26..26, + HWU59 : 25..25, + HD : 22..22, + HA : 21..21, + VS : 19..19, + PS : 18..16, + TG0 : 15..14, + SH0 : 13..12, + ORGN0 : 11..10, + IRGN0 : 9..8, + SL0 : 7..6, + T0SZ : 5..0 + } + +register VTCR_EL2 : VTCR_EL2_Type + +bitfield VTTBR_Type : bits(64) = {VMID : 55..48, BADDR : 47..1, CnP : 0..0} + +register VTTBR : VTTBR_Type + +bitfield VTTBR_EL2_Type : bits(128) = {VMID : 63..48, SKL : 2..1, CnP : 0..0} + +register _VTTBR_EL2 : VTTBR_EL2_Type + +val VTTBR_EL2_read : unit -> VTTBR_EL2_Type + +function VTTBR_EL2_read () = { + r : VTTBR_EL2_Type = _VTTBR_EL2; + r.bits[63 .. 0] = Slice(VTTBR.bits, 0, 64); + return(r) +} + +val AArch64_BreakpointValueMatch : forall ('isbreakpnt : Bool) ('linked_to : Bool) 'n_in. + (int('n_in), bits(64), bool('linked_to), bool('isbreakpnt)) -> (bool, bool) + +function AArch64_BreakpointValueMatch (n_in, vaddress, linked_to, isbreakpnt) = { + n : int = n_in; + c : Constraint = undefined; + if n >= NumBreakpointsImplemented() then { + (c, n) = ConstrainUnpredictableInteger(0, NumBreakpointsImplemented() - 1, Unpredictable_BPNOTIMPL); + assert(c == Constraint_DISABLED | c == Constraint_UNKNOWN); + if c == Constraint_DISABLED then { + return((false, false)) + }; + () + }; + let 'n = n; + assert(constraint((0 <= 'n & 'n < 64))); + if not_bool(IsBreakpointEnabled(n)) then { + return((false, false)) + }; + dbgtype : bits(4) = DBGBCR_EL1[n][BT]; + bt2 : bits(1) = if HaveFeatABLE() then DBGBCR_EL1[n][BT2] else 0b0; + (c, bt2, dbgtype) = AArch64_ReservedBreakpointType(n, bt2, dbgtype); + if c == Constraint_DISABLED then { + return((false, false)) + }; + let match_addr : bool = (match dbgtype { + [bitzero, _, bitzero, _] => true, + _ => false + }) : bool; + let mismatch : bool = (match dbgtype { + [bitzero, bitone, bitzero, _] => true, + _ => false + }) : bool; + let match_vmid : bool = (match dbgtype { + [bitone, bitzero, _, _] => true, + _ => false + }) : bool; + let match_cid : bool = (match dbgtype { + [bitzero, bitzero, bitone, _] => true, + _ => false + }) : bool; + let match_cid1 : bool = (match dbgtype { + [bitone, bitzero, bitone, _] => true, + [_, bitone, bitone, _] => true, + _ => false + }) : bool; + let match_cid2 : bool = (match dbgtype { + [bitone, bitone, _, _] => true, + _ => false + }) : bool; + let linking_enabled : bool = (match dbgtype { + [_, _, bitone, bitone] => true, + [bitone, _, _, bitone] => true, + _ => false + }) : bool | bt2 == 0b1; + if linked_to & not_bool(linking_enabled) then { + return((false, false)) + }; + if (not_bool(linked_to) & linking_enabled) & not_bool(match_addr) then { + return((false, false)) + }; + if (linked_to & match_addr) & isbreakpnt then { + if not_bool(ConstrainUnpredictableBool(Unpredictable_BPLINKEDADDRMATCH)) then { + return((false, false)) + }; + () + }; + if mismatch & UsingAArch32() then { + return((false, false)) + }; + bvr_match : bool = false; + bxvr_match : bool = false; + mask : int = undefined; + if HaveFeatABLE() then { + mask = UInt(DBGBCR_EL1[n][MASK]); + if mask == 1 | mask == 2 then { + (c, mask) = ConstrainUnpredictableInteger(3, 31, Unpredictable_RESBPMASK); + assert(c == Constraint_DISABLED | c == Constraint_NONE | c == Constraint_UNKNOWN); + match c { + Constraint_DISABLED => { + return((false, false)) + }, + Constraint_NONE => { + mask = 0 + }, + _ => () + } + }; + if mask != 0 then { + if ((match_cid | match_cid1) | match_cid2) | DBGBCR_EL1[n][BAS] != 0b1111 & HaveAArch32() then { + if not_bool(ConstrainUnpredictableBool(Unpredictable_BPMASK)) then { + return((false, false)) + }; + () + }; + () + } else { + if mismatch then { + return((false, false)) + }; + () + } + } else { + mask = 0 + }; + let 'mask = mask; + if match_addr then { + byte_select_match : bool = undefined; + let 'byte = UInt(vaddress[1 .. 0]); + if HaveAArch32() then { + assert(byte == 0 | byte == 2); + byte_select_match = [DBGBCR_EL1[n][BAS][byte]] == 0b1 + } else { + assert(byte == 0); + byte_select_match = true + }; + top : int = DebugAddrTop(); + let 'bottom = 2; + if ((top < 55 & not_bool(is_ones_subrange(DBGBVR_EL1[n].bits, 63, top))) & not_bool(is_zero_subrange(DBGBVR_EL1[n].bits, 63, top))) & ConstrainUnpredictableBool(Unpredictable_DBGxVR_RESS) then { + top = 63 + }; + let 'top = top; + if mask > bottom then { + assert(constraint((0 <= 'mask & 'mask <= 'top & 'top < 64))); + bvr_match = vaddress[top .. mask] == DBGBVR_EL1[n].bits[top .. mask] & byte_select_match; + if bvr_match & not_bool(is_zero_subrange(DBGBVR_EL1[n].bits, mask - 1, bottom)) then { + bvr_match = ConstrainUnpredictableBool(Unpredictable_BPMASKEDBITS) + }; + () + } else { + assert(constraint((0 <= 'bottom & 'bottom <= 'top & 'top < 64))); + bvr_match = vaddress[top .. bottom] == DBGBVR_EL1[n].bits[top .. bottom] & byte_select_match + } + } else if match_cid then { + if IsInHost() then { + bvr_match = CONTEXTIDR_EL2.bits[31 .. 0] == DBGBVR_EL1[n].bits[31 .. 0] + } else { + bvr_match = (PSTATE.EL == EL0 | PSTATE.EL == EL1) & CONTEXTIDR_EL1.bits[31 .. 0] == DBGBVR_EL1[n].bits[31 .. 0] + } + } else if match_cid1 then { + bvr_match = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & not_bool(IsInHost())) & CONTEXTIDR_EL1.bits[31 .. 0] == DBGBVR_EL1[n].bits[31 .. 0] + } else (); + if match_vmid then { + vmid : bits(16) = undefined; + bvr_vmid : bits(16) = undefined; + if not_bool(Have16bitVMID()) | VTCR_EL2[VS] == 0b0 then { + vmid = ZeroExtend(VTTBR_EL2_read()[VMID][7 .. 0], 16); + bvr_vmid = ZeroExtend(DBGBVR_EL1[n].bits[39 .. 32], 16) + } else { + vmid = VTTBR_EL2_read()[VMID]; + bvr_vmid = DBGBVR_EL1[n].bits[47 .. 32] + }; + bxvr_match = (((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & not_bool(IsInHost())) & vmid == bvr_vmid + } else if match_cid2 then { + bxvr_match = (PSTATE.EL != EL3 & EL2Enabled()) & DBGBVR_EL1[n].bits[63 .. 32] == CONTEXTIDR_EL2.bits[31 .. 0] + } else (); + let bvr_match_valid : bool = (match_addr | match_cid) | match_cid1; + let bxvr_match_valid : bool = match_vmid | match_cid2; + let value_match_name : bool = (not_bool(bxvr_match_valid) | bxvr_match) & (not_bool(bvr_match_valid) | bvr_match); + return((value_match_name, mismatch)) +} + +val CheckValidStateMatch : forall ('isbreakpnt : Bool). + (bits(2), bits(1), bits(1), bits(2), bool('isbreakpnt)) -> (Constraint, bits(2), bits(1), bits(1), bits(2)) + +function CheckValidStateMatch (ssc_in, ssce_in, hmc_in, pxc_in, isbreakpnt) = { + if not_bool(HaveRME()) then { + assert(ssce_in == 0b0) + }; + reserved : bool = false; + ssc : bits(2) = ssc_in; + ssce : bits(1) = ssce_in; + hmc : bits(1) = hmc_in; + pxc : bits(2) = pxc_in; + match ((hmc @ ssce) @ ssc) @ pxc { + 0b001110 => { + reserved = true + }, + [bitzero, bitzero, bitone, _, _, _] => { + reserved = not_bool(HaveSecureState()) + }, + [bitone, bitzero, bitzero, bitzero, _, bitzero] => { + reserved = true + }, + 0b100110 => { + reserved = true + }, + [bitone, bitzero, bitone, _, bitone, bitzero] => { + reserved = true + }, + [_, bitone, _, _, _, _] => { + reserved = ssc != 0b01 | (hmc @ pxc) == 0b000 | (hmc @ pxc) == 0b110 + }, + _ => { + reserved = false + } + }; + if ((not_bool(isbreakpnt) | not_bool(HaveAArch32EL(EL1))) & (hmc @ pxc) == 0b000) & ssc != 0b11 then { + reserved = true + }; + if (not_bool(HaveEL(EL3)) & not_bool(HaveEL(EL2))) & (hmc != 0b0 | ssc != 0b00) then { + reserved = true + }; + if (not_bool(HaveEL(EL3)) & (ssc == 0b01 | ssc == 0b10)) & ((hmc @ ssc) @ pxc) != 0b10100 then { + reserved = true + }; + if (not_bool(HaveEL(EL3)) | not_bool(HaveAArch64())) & ((hmc @ ssc) @ pxc) == 0b11000 then { + reserved = true + }; + if not_bool(HaveEL(EL2)) & ((hmc @ ssc) @ pxc) == 0b11100 then { + reserved = true + }; + if not_bool(HaveSecureEL2Ext()) & (match (hmc @ ssc) @ pxc { + 0b01100 => true, + 0b10100 => true, + [_, bitone, bitone, _, bitone] => true, + _ => false + }) : bool then { + reserved = true + }; + if reserved then { + c : Constraint = undefined; + (c, (hmc @ ssc @ ssce @ pxc)) = ConstrainUnpredictableBits(Unpredictable_RESBPWPCTRL, 6); + assert(c == Constraint_DISABLED | c == Constraint_UNKNOWN); + if c == Constraint_DISABLED then { + return((c, __UNKNOWN_bits(2), __UNKNOWN_bit(), __UNKNOWN_bit(), __UNKNOWN_bits(2))) + }; + () + }; + return((Constraint_NONE, ssc, ssce, hmc, pxc)) +} + +val ContextMatchingBreakpointRange : unit -> (int, int) + +function ContextMatchingBreakpointRange () = { + let 'b = NumBreakpointsImplemented(); + let 'c = NumContextAwareBreakpointsImplemented(); + if b <= 16 then { + return((b - c, b - 1)) + } else if c <= 16 then { + return((16 - c, 15)) + } else { + return((0, c - 1)) + } +} + +val IsContextMatchingBreakpoint : forall 'n. int('n) -> bool + +function IsContextMatchingBreakpoint n = { + lower : int = undefined; + upper : int = undefined; + (lower, upper) = ContextMatchingBreakpointRange(); + let 'upper = upper; + let 'lower = lower; + return(n >= lower & n <= upper) +} + +val AArch64_StateMatch : forall ('isbreakpnt : Bool) ('linked_in : Bool) 'linked_n_in. + (bits(2), bits(1), bits(1), bits(2), bool('linked_in), int('linked_n_in), bool('isbreakpnt), bits(64), AccessDescriptor) -> bool + +function AArch64_StateMatch (ssc_in, ssce_in, hmc_in, pxc_in, linked_in, linked_n_in, isbreakpnt, vaddress, accdesc) = { + first_ctx_cmp : int = undefined; + last_ctx_cmp : int = undefined; + linked_to : bool = undefined; + if not_bool(HaveRME()) then { + assert(ssce_in == 0b0) + }; + ssc : bits(2) = ssc_in; + ssce : bits(1) = ssce_in; + hmc : bits(1) = hmc_in; + pxc : bits(2) = pxc_in; + linked : bool = linked_in; + linked_n : int = linked_n_in; + c : Constraint = undefined; + (c, ssc, ssce, hmc, pxc) = CheckValidStateMatch(ssc, ssce, hmc, pxc, isbreakpnt); + if c == Constraint_DISABLED then { + return(false) + }; + let EL3_match : bool = (HaveEL(EL3) & hmc == 0b1) & [ssc[0]] == 0b0; + let EL2_match : bool = HaveEL(EL2) & (hmc == 0b1 & (ssc @ pxc) != 0b1000 | ssc == 0b11); + let EL1_match : bool = [pxc[0]] == 0b1; + let EL0_match : bool = [pxc[1]] == 0b1; + priv_match : bool = undefined; + match accdesc.el { + ? if ? == EL3 => { + priv_match = EL3_match + }, + ? if ? == EL2 => { + priv_match = EL2_match + }, + ? if ? == EL1 => { + priv_match = EL1_match + }, + ? if ? == EL0 => { + priv_match = EL0_match + }, + _ => () + }; + ss_match : bool = undefined; + match ssce @ ssc { + 0b000 => { + ss_match = hmc == 0b1 | accdesc.ss != SS_Root + }, + 0b001 => { + ss_match = accdesc.ss == SS_NonSecure + }, + 0b010 => { + ss_match = hmc == 0b1 & accdesc.ss == SS_Root | accdesc.ss == SS_Secure + }, + 0b011 => { + ss_match = hmc == 0b1 & accdesc.ss != SS_Root | accdesc.ss == SS_Secure + }, + 0b101 => { + ss_match = accdesc.ss == SS_Realm + }, + _ => () + }; + linked_match : bool = false; + is_linked_mismatch : bool = false; + if linked then { + if not_bool(IsContextMatchingBreakpoint(linked_n)) then { + (first_ctx_cmp, last_ctx_cmp) = ContextMatchingBreakpointRange(); + let 'last_ctx_cmp = last_ctx_cmp; + let 'first_ctx_cmp = first_ctx_cmp; + (c, linked_n) = ConstrainUnpredictableInteger(first_ctx_cmp, last_ctx_cmp, Unpredictable_BPNOTCTXCMP); + assert(c == Constraint_DISABLED | c == Constraint_NONE | c == Constraint_UNKNOWN); + match c { + Constraint_DISABLED => { + return(false) + }, + Constraint_NONE => { + linked = false + }, + _ => () + } + }; + () + }; + let 'linked_n = linked_n; + if linked then { + let linked_to : bool = true; + (linked_match, is_linked_mismatch) = AArch64_BreakpointValueMatch(linked_n, vaddress, linked_to, isbreakpnt) + }; + return((priv_match & ss_match) & ((not_bool(linked) | not_bool(is_linked_mismatch) & linked_match) | is_linked_mismatch & not_bool(linked_match))) +} + +val AArch64_BreakpointMatch : forall 'n 'size, (0 <= 'n & 'n < 64). + (int('n), bits(64), AccessDescriptor, int('size)) -> (bool, bool) + +function AArch64_BreakpointMatch (n, vaddress, accdesc, size) = { + match_i : bool = undefined; + valid_mismatch_name : bool = undefined; + value_match_name : bool = undefined; + assert(not_bool(ELUsingAArch32(S1TranslationRegime__1()))); + assert(n < NumBreakpointsImplemented()); + let linking_enabled : bool = (match DBGBCR_EL1[n][BT] { + [bitzero, _, bitone, bitone] => true, + [bitone, _, _, bitone] => true, + _ => false + }) : bool | HaveFeatABLE() & DBGBCR_EL1[n][BT2] == 0b1; + if linking_enabled then { + return((false, false)) + }; + let enabled : bool = IsBreakpointEnabled(n); + let linked : bool = (match DBGBCR_EL1[n][BT] { + [bitzero, _, bitzero, bitone] => true, + _ => false + }) : bool; + let isbreakpnt : bool = true; + let linked_to : bool = false; + let lbnx : bits(2) = if Havev8p9Debug() then DBGBCR_EL1[n][LBNX] else 0b00; + let 'linked_n = UInt(lbnx @ DBGBCR_EL1[n][LBN]); + let ssce : bits(1) = if HaveRME() then DBGBCR_EL1[n][SSCE] else 0b0; + let state_match : bool = AArch64_StateMatch(DBGBCR_EL1[n][SSC], ssce, DBGBCR_EL1[n][HMC], DBGBCR_EL1[n][PMC], linked, linked_n, isbreakpnt, vaddress, accdesc); + (value_match_name, valid_mismatch_name) = AArch64_BreakpointValueMatch(n, vaddress, linked_to, isbreakpnt); + if HaveAArch32() & size == 4 then { + let (__tup_0 : bool, _) = + AArch64_BreakpointValueMatch(n, vaddress + 2, linked_to, isbreakpnt) + in + { + match_i = __tup_0 + }; + if not_bool(value_match_name) & match_i then { + value_match_name = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF) + }; + () + }; + if [vaddress[1]] == 0b1 & DBGBCR_EL1[n][BAS] == 0b1111 then { + if value_match_name then { + value_match_name = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF) + }; + () + }; + let val_match : bool = (value_match_name & state_match) & enabled; + let is_mismatch : bool = (valid_mismatch_name & state_match) & enabled; + return((val_match, is_mismatch)) +} + +val AArch64_CheckBreakpoint : forall 'size. + (FaultRecord, bits(64), AccessDescriptor, int('size)) -> FaultRecord + +function AArch64_CheckBreakpoint (fault_in, vaddress, accdesc, size) = { + is_mismatch_i : bool = undefined; + match_i : bool = undefined; + reason : bits(6) = undefined; + assert(not_bool(ELUsingAArch32(S1TranslationRegime__1()))); + assert(UsingAArch32() & (size == 2 | size == 4) | size == 4); + fault : FaultRecord = fault_in; + val_match : bool = false; + mismatch : bool = true; + mismatch_bp : bool = false; + foreach (i from 0 to (NumBreakpointsImplemented() - 1) by 1 in inc) { + assert(constraint(('loop_i < 64 | not('size in {2, 4, 4})))); + (match_i, is_mismatch_i) = AArch64_BreakpointMatch(i, vaddress, accdesc, size); + if is_mismatch_i then { + mismatch_bp = true; + mismatch = mismatch & not_bool(match_i) + } else { + val_match = val_match | match_i + } + }; + if val_match | mismatch & mismatch_bp then { + fault.statuscode = Fault_Debug; + if HaltOnBreakpointOrWatchpoint() then { + let reason : bits(6) = DebugHalt_Breakpoint; + Halt(reason) + }; + () + }; + return(fault) +} + +bitfield DBGWCR_EL1_Type : bits(64) = + { + LBNX : 31..30, + SSCE : 29..29, + MASK : 28..24, + WT : 20..20, + LBN : 19..16, + SSC : 15..14, + HMC : 13..13, + BAS : 12..5, + LSC : 4..3, + PAC : 2..1, + E : 0..0 + } + +register DBGWCR_EL1 : vector(64, DBGWCR_EL1_Type) + +bitfield DBGWVR_EL1_Type : bits(64) = + {RESS : (63..57 @ (56..53 @ 52..49)), VA : (56..53 @ (52..49 @ 48..2))} + +register DBGWVR_EL1 : vector(64, DBGWVR_EL1_Type) + +val AArch64_WatchpointByteMatch : forall 'n, (0 <= 'n & 'n < 64). + (int('n), bits(64)) -> bool + +function AArch64_WatchpointByteMatch (n, vaddress) = { + LSB : bits(8) = undefined; + MSB : bits(8) = undefined; + top : int = DebugAddrTop(); + bottom : {2, 3} = if [DBGWVR_EL1[n].bits[2]] == 0b1 then 2 else 3; + byte_select_match : bool = let 'bottom = bottom in + { + [DBGWCR_EL1[n][BAS][UInt(vaddress[bottom - 1 .. 0])]] != 0b0 + }; + mask : int = UInt(DBGWCR_EL1[n][MASK]); + if mask > 0 & not_bool(IsOnes(DBGWCR_EL1[n][BAS])) then { + byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPMASKANDBAS) + } else { + let LSB : bits(8) = DBGWCR_EL1[n][BAS] & not_vec(DBGWCR_EL1[n][BAS] - 1); + let MSB : bits(8) = DBGWCR_EL1[n][BAS] + LSB; + if not_bool(IsZero(MSB & MSB - 1)) then { + byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPBASCONTIGUOUS); + bottom = 3 + }; + () + }; + let 'bottom = bottom; + if mask > 0 & mask <= 2 then { + c : Constraint = undefined; + (c, mask) = ConstrainUnpredictableInteger(3, 31, Unpredictable_RESWPMASK); + assert(c == Constraint_DISABLED | c == Constraint_NONE | c == Constraint_UNKNOWN); + match c { + Constraint_DISABLED => { + return(false) + }, + Constraint_NONE => { + mask = 0 + }, + _ => () + } + }; + let 'mask = mask; + if ((top < 55 & not_bool(is_ones_subrange(DBGWVR_EL1[n].bits, 63, top))) & not_bool(is_zero_subrange(DBGWVR_EL1[n].bits, 63, top))) & ConstrainUnpredictableBool(Unpredictable_DBGxVR_RESS) then { + top = 63 + }; + let 'top = top; + WVR_match : bool = undefined; + if mask > bottom then { + assert(constraint((0 <= 'mask & 'mask <= 'top & 'top < 64))); + WVR_match = vaddress[top .. mask] == DBGWVR_EL1[n].bits[top .. mask]; + if WVR_match & not_bool(is_zero_subrange(DBGWVR_EL1[n].bits, mask - 1, bottom)) then { + WVR_match = ConstrainUnpredictableBool(Unpredictable_WPMASKEDBITS) + }; + () + } else { + assert(constraint((0 <= 'bottom & 'bottom <= 'top & 'top < 64))); + WVR_match = vaddress[top .. bottom] == DBGWVR_EL1[n].bits[top .. bottom] + }; + return(WVR_match & byte_select_match) +} + +val IsWatchpointEnabled : forall 'n, (0 <= 'n & 'n < 64). int('n) -> bool + +function IsWatchpointEnabled n = { + if n > 15 & (not_bool(HaltOnBreakpointOrWatchpoint()) & not_bool(SelfHostedExtendedBPWPEnabled()) | HaltOnBreakpointOrWatchpoint() & EDSCR2_read()[EHBWE] == 0b0) then { + return(false) + }; + return(DBGWCR_EL1[n][E] == 0b1) +} + +val AArch64_WatchpointMatch : forall 'n 'size, (0 <= 'n & 'n < 64). + (int('n), bits(64), int('size), AccessDescriptor) -> bool + +function AArch64_WatchpointMatch (n, vaddress, size, accdesc) = { + assert(not_bool(ELUsingAArch32(S1TranslationRegime__1()))); + assert(n < NumWatchpointsImplemented()); + let enabled : bool = IsWatchpointEnabled(n); + let linked : bool = DBGWCR_EL1[n][WT] == 0b1; + let isbreakpnt : bool = false; + let lbnx : bits(2) = if Havev8p9Debug() then DBGWCR_EL1[n][LBNX] else 0b00; + let 'linked_n = UInt(lbnx @ DBGWCR_EL1[n][LBN]); + let ssce : bits(1) = if HaveRME() then DBGWCR_EL1[n][SSCE] else 0b0; + let state_match : bool = AArch64_StateMatch(DBGWCR_EL1[n][SSC], ssce, DBGWCR_EL1[n][HMC], DBGWCR_EL1[n][PAC], linked, linked_n, isbreakpnt, PC_read(), accdesc); + ls_match : bool = undefined; + match DBGWCR_EL1[n][LSC][1 .. 0] { + 0b00 => { + ls_match = false + }, + 0b01 => { + ls_match = accdesc.read + }, + 0b10 => { + ls_match = accdesc.write | accdesc.acctype == AccessType_DC + }, + 0b11 => { + ls_match = true + }, + _ => () + }; + value_match_name : bool = false; + foreach (byte from 0 to (size - 1) by 1 in inc) { + value_match_name = value_match_name | AArch64_WatchpointByteMatch(n, vaddress + byte) + }; + return(((value_match_name & state_match) & ls_match) & enabled) +} + +type EDWAR_Type = bits(64) + +register EDWAR : EDWAR_Type + +val AArch64_CheckWatchpoint : forall 'size. + (FaultRecord, bits(64), AccessDescriptor, int('size)) -> FaultRecord + +function AArch64_CheckWatchpoint (fault_in, vaddress, accdesc, size) = { + reason : bits(6) = undefined; + assert(not_bool(ELUsingAArch32(S1TranslationRegime__1()))); + fault : FaultRecord = fault_in; + if accdesc.acctype == AccessType_DC then { + if accdesc.cacheop != CacheOp_Invalidate then { + return(fault) + }; + () + } else if not_bool(IsDataAccess(accdesc.acctype)) then { + return(fault) + } else (); + foreach (i from 0 to (NumWatchpointsImplemented() - 1) by 1 in inc) { + assert(constraint('loop_i < 64)); + if AArch64_WatchpointMatch(i, vaddress, size, accdesc) then { + fault.statuscode = Fault_Debug; + if [DBGWCR_EL1[i][LSC][0]] == 0b1 & accdesc.read then { + fault.write = false + } else if [DBGWCR_EL1[i][LSC][1]] == 0b1 & accdesc.write then { + fault.write = true + } else () + }; + () + }; + if ((fault.statuscode == Fault_Debug & HaltOnBreakpointOrWatchpoint()) & not_bool(accdesc.nonfault)) & not_bool(accdesc.firstfault & not_bool(accdesc.first)) then { + let reason : bits(6) = DebugHalt_Watchpoint; + EDWAR = vaddress; + Halt(reason) + }; + return(fault) +} + +val AArch64_CheckDebug : forall 'size. + (bits(64), AccessDescriptor, int('size)) -> FaultRecord + +function AArch64_CheckDebug (vaddress, accdesc, size) = { + mask : bits(1) = undefined; + ss : SecurityState = undefined; + fault : FaultRecord = NoFault__1(accdesc); + generate_exception : bool = undefined; + let d_side : bool = IsDataAccess(accdesc.acctype) | accdesc.acctype == AccessType_DC; + let i_side : bool = accdesc.acctype == AccessType_IFETCH; + if accdesc.acctype == AccessType_NV2 then { + let mask : bits(1) = 0b0; + let ss : SecurityState = CurrentSecurityState(); + generate_exception = AArch64_GenerateDebugExceptionsFrom(EL2, ss, mask) & MDSCR_EL1[MDE] == 0b1 + } else { + generate_exception = AArch64_GenerateDebugExceptions() & MDSCR_EL1[MDE] == 0b1 + }; + let halt : bool = HaltOnBreakpointOrWatchpoint(); + if generate_exception | halt then { + if d_side then { + fault = AArch64_CheckWatchpoint(fault, vaddress, accdesc, size) + } else if i_side then { + fault = AArch64_CheckBreakpoint(fault, vaddress, accdesc, size) + } else () + }; + return(fault) +} + +val AArch64_MemSwapTableDesc : forall 'N, 'N in {64, 128}. + (FaultRecord, bits('N), bits('N), bits(1), AccessDescriptor, AddressDescriptor, TranslationInfo) -> (FaultRecord, bits('N)) + +function AArch64_MemSwapTableDesc (fault_in, prev_desc, new_desc, ee, descaccess, descpaddr, translation_info) = { + ordered_new_desc : bits('N) = undefined; + fault : FaultRecord = fault_in; + iswrite : bool = undefined; + if HaveRME() then { + fault.gpcf = GranuleProtectionCheck(descpaddr, descaccess); + if fault.gpcf.gpf != GPCF_None then { + fault.statuscode = Fault_GPCFOnWalk; + fault.paddress = descpaddr.paddress; + fault.gpcfs2walk = fault.secondstage; + return((fault, __UNKNOWN_bits('N))) + }; + () + }; + mem_desc : bits('N) = undefined; + memstatus : PhysMemRetStatus = undefined; + (memstatus, mem_desc) = PhysMemRead(descpaddr, DIV('N, 8), descaccess, Some(translation_info)); + if ee == 0b1 then { + mem_desc = BigEndianReverse(mem_desc) + }; + if IsFault__2(memstatus) then { + iswrite = false; + fault = HandleExternalTTWAbort(memstatus, iswrite, descpaddr, descaccess, DIV('N, 8), fault); + if IsFault__1(fault.statuscode) then { + return((fault, __UNKNOWN_bits('N))) + }; + () + }; + if mem_desc == prev_desc then { + let ordered_new_desc : bits('N) = if ee == 0b1 then + BigEndianReverse(new_desc) + else + new_desc; + let memstatus : PhysMemRetStatus = PhysMemWrite(descpaddr, DIV('N, 8), descaccess, Some(translation_info), ordered_new_desc); + if IsFault__2(memstatus) then { + let iswrite : bool = true; + fault = HandleExternalTTWAbort(memstatus, iswrite, descpaddr, descaccess, DIV('N, 8), fault); + if IsFault__1(fault.statuscode) then { + return((fault, __UNKNOWN_bits('N))) + }; + () + }; + mem_desc = new_desc + }; + return((fault, mem_desc)) +} + +val AArch64_S1DirectBasePermissions : (Regime, TTWState, S1TTWParams, AccessDescriptor) -> S1AccessControls + +function AArch64_S1DirectBasePermissions (regime, walkstate, walkparams, accdesc) = { + r : bits(1) = undefined; + w : bits(1) = undefined; + x : bits(1) = undefined; + pr : bits(1) = undefined; + pw : bits(1) = undefined; + px : bits(1) = undefined; + ur : bits(1) = undefined; + uw : bits(1) = undefined; + ux : bits(1) = undefined; + let permissions : Permissions = walkstate.permissions; + s1perms : S1AccessControls = undefined; + if HasUnprivileged(regime) then { + match permissions.ap[2 .. 1] { + 0b00 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b0, 0b0) + }, + 0b01 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b1, 0b1) + }, + 0b10 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b0, 0b0) + }, + 0b11 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b1, 0b0) + } + }; + match permissions.ap_table { + 0b00 => { + (pr, pw, ur, uw) = (pr, pw, ur, uw) + }, + 0b01 => { + (pr, pw, ur, uw) = (pr, pw, 0b0, 0b0) + }, + 0b10 => { + (pr, pw, ur, uw) = (pr, 0b0, ur, 0b0) + }, + 0b11 => { + (pr, pw, ur, uw) = (pr, 0b0, 0b0, 0b0) + } + }; + px = not_vec((permissions.pxn | permissions.pxn_table) | uw); + ux = not_vec(permissions.uxn | permissions.uxn_table); + if (HavePANExt() & accdesc.pan) & not_bool(regime == Regime_EL10 & walkparams.nv1 == 0b1) then { + if ((__IMPDEF_boolean("SCR_EL3.SIF affects EPAN") & accdesc.ss == SS_Secure) & walkstate.baseaddress.paspace == PAS_NonSecure) & walkparams.sif == 0b1 then { + ux = 0b0 + }; + if ((__IMPDEF_boolean("Realm EL2&0 regime affects EPAN") & accdesc.ss == SS_Realm) & regime == Regime_EL20) & walkstate.baseaddress.paspace != PAS_Realm then { + ux = 0b0 + }; + let pan : bits(1) = PSTATE.PAN & ((ur | uw) | walkparams.epan & ux); + pr = pr & not_vec(pan); + pw = pw & not_vec(pan) + }; + () + } else { + match [permissions.ap[2]] { + 0b0 => { + (pr, pw) = (0b1, 0b1) + }, + 0b1 => { + (pr, pw) = (0b1, 0b0) + } + }; + match [permissions.ap_table[1]] { + 0b0 => { + (pr, pw) = (pr, pw) + }, + 0b1 => { + (pr, pw) = (pr, 0b0) + } + }; + px = not_vec(permissions.xn | permissions.xn_table) + }; + (r, w, x) = if accdesc.el == EL0 then (ur, uw, ux) else (pr, pw, px); + let wxn : bits(1) = (walkparams.wxn & w) & x; + if accdesc.ss == SS_Secure & walkstate.baseaddress.paspace == PAS_NonSecure then { + x = x & not_vec(walkparams.sif) + }; + if accdesc.ss == SS_Root & walkstate.baseaddress.paspace != PAS_Root then { + x = 0b0 + }; + if (accdesc.ss == SS_Realm & (regime == Regime_EL2 | regime == Regime_EL20)) & walkstate.baseaddress.paspace != PAS_Realm then { + x = 0b0 + }; + let x = x; + s1perms.r = r; + s1perms.w = w; + s1perms.x = x; + s1perms.gcs = 0b0; + s1perms.wxn = wxn; + s1perms.overlay = true; + return(s1perms) +} + +val AArch64_S1E0POEnabled : (Regime, bits(1)) -> bool + +function AArch64_S1E0POEnabled (regime, nv1) = { + assert(HasUnprivileged(regime)); + if not_bool(HaveS1POExt()) then { + return(false) + }; + match regime { + Regime_EL20 => { + return(IsTCR2EL2Enabled() & TCR2_EL2[E0POE] == 0b1) + }, + Regime_EL10 => { + return((IsTCR2EL1Enabled() & nv1 == 0b0) & TCR2_EL1[E0POE] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch64_S1IndirectBasePermissions : (Regime, TTWState, S1TTWParams, AccessDescriptor) -> S1AccessControls + +function AArch64_S1IndirectBasePermissions (regime, walkstate, walkparams, accdesc) = { + gcs : bits(1) = undefined; + overlay : bits(1) = undefined; + r : bits(1) = undefined; + w : bits(1) = undefined; + wxn : bits(1) = undefined; + x : bits(1) = undefined; + pgcs : bits(1) = undefined; + pr : bits(1) = undefined; + pw : bits(1) = undefined; + px : bits(1) = undefined; + u_overlay : bits(1) = undefined; + ugcs : bits(1) = undefined; + ur : bits(1) = undefined; + uw : bits(1) = undefined; + uwxn : bits(1) = undefined; + ux : bits(1) = undefined; + let permissions : Permissions = walkstate.permissions; + s1perms : S1AccessControls = undefined; + match permissions.ppi { + 0b0000 => { + (pr, pw, px, pgcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b0001 => { + (pr, pw, px, pgcs) = (0b1, 0b0, 0b0, 0b0) + }, + 0b0010 => { + (pr, pw, px, pgcs) = (0b0, 0b0, 0b1, 0b0) + }, + 0b0011 => { + (pr, pw, px, pgcs) = (0b1, 0b0, 0b1, 0b0) + }, + 0b0100 => { + (pr, pw, px, pgcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b0101 => { + (pr, pw, px, pgcs) = (0b1, 0b1, 0b0, 0b0) + }, + 0b0110 => { + (pr, pw, px, pgcs) = (0b1, 0b1, 0b1, 0b0) + }, + 0b0111 => { + (pr, pw, px, pgcs) = (0b1, 0b1, 0b1, 0b0) + }, + 0b1000 => { + (pr, pw, px, pgcs) = (0b1, 0b0, 0b0, 0b0) + }, + 0b1001 => { + (pr, pw, px, pgcs) = (0b1, 0b0, 0b0, 0b1) + }, + 0b1010 => { + (pr, pw, px, pgcs) = (0b1, 0b0, 0b1, 0b0) + }, + 0b1011 => { + (pr, pw, px, pgcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b1100 => { + (pr, pw, px, pgcs) = (0b1, 0b1, 0b0, 0b0) + }, + 0b1101 => { + (pr, pw, px, pgcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b1110 => { + (pr, pw, px, pgcs) = (0b1, 0b1, 0b1, 0b0) + }, + 0b1111 => { + (pr, pw, px, pgcs) = (0b0, 0b0, 0b0, 0b0) + } + }; + let p_overlay : bits(1) = not_vec([permissions.ppi[3]]); + let pwxn : bits(1) = if permissions.ppi == 0b0110 then 0b1 else 0b0; + if HasUnprivileged(regime) then { + match permissions.upi { + 0b0000 => { + (ur, uw, ux, ugcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b0001 => { + (ur, uw, ux, ugcs) = (0b1, 0b0, 0b0, 0b0) + }, + 0b0010 => { + (ur, uw, ux, ugcs) = (0b0, 0b0, 0b1, 0b0) + }, + 0b0011 => { + (ur, uw, ux, ugcs) = (0b1, 0b0, 0b1, 0b0) + }, + 0b0100 => { + (ur, uw, ux, ugcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b0101 => { + (ur, uw, ux, ugcs) = (0b1, 0b1, 0b0, 0b0) + }, + 0b0110 => { + (ur, uw, ux, ugcs) = (0b1, 0b1, 0b1, 0b0) + }, + 0b0111 => { + (ur, uw, ux, ugcs) = (0b1, 0b1, 0b1, 0b0) + }, + 0b1000 => { + (ur, uw, ux, ugcs) = (0b1, 0b0, 0b0, 0b0) + }, + 0b1001 => { + (ur, uw, ux, ugcs) = (0b1, 0b0, 0b0, 0b1) + }, + 0b1010 => { + (ur, uw, ux, ugcs) = (0b1, 0b0, 0b1, 0b0) + }, + 0b1011 => { + (ur, uw, ux, ugcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b1100 => { + (ur, uw, ux, ugcs) = (0b1, 0b1, 0b0, 0b0) + }, + 0b1101 => { + (ur, uw, ux, ugcs) = (0b0, 0b0, 0b0, 0b0) + }, + 0b1110 => { + (ur, uw, ux, ugcs) = (0b1, 0b1, 0b1, 0b0) + }, + 0b1111 => { + (ur, uw, ux, ugcs) = (0b0, 0b0, 0b0, 0b0) + } + }; + u_overlay = not_vec([permissions.upi[3]]); + uwxn = if permissions.upi == 0b0110 then 0b1 else 0b0; + if (px == 0b1 | pgcs == 0b1) & (uw == 0b1 | ugcs == 0b1) then { + (pr, pw, px, pgcs) = (0b0, 0b0, 0b0, 0b0); + (ur, uw, ux, ugcs) = (0b0, 0b0, 0b0, 0b0) + }; + if (HavePANExt() & accdesc.pan) & not_bool(regime == Regime_EL10 & walkparams.nv1 == 0b1) then { + if PSTATE.PAN == 0b1 & permissions.upi != 0b0000 then { + (pr, pw) = (0b0, 0b0) + }; + () + }; + () + }; + let uwxn = uwxn; + let u_overlay = u_overlay; + if accdesc.el == EL0 then { + (r, w, x, gcs, wxn, overlay) = (ur, uw, ux, ugcs, uwxn, u_overlay) + } else { + (r, w, x, gcs, wxn, overlay) = (pr, pw, px, pgcs, pwxn, p_overlay) + }; + if accdesc.ss == SS_Secure & walkstate.baseaddress.paspace == PAS_NonSecure then { + x = x & not_vec(walkparams.sif); + gcs = 0b0 + }; + if accdesc.ss == SS_Root & walkstate.baseaddress.paspace != PAS_Root then { + x = 0b0; + gcs = 0b0 + }; + if (accdesc.ss == SS_Realm & (regime == Regime_EL2 | regime == Regime_EL20)) & walkstate.baseaddress.paspace != PAS_Realm then { + x = 0b0; + gcs = 0b0 + }; + let x = x; + let gcs = gcs; + s1perms.r = r; + s1perms.w = w; + s1perms.x = x; + s1perms.gcs = gcs; + s1perms.wxn = wxn; + s1perms.overlay = overlay == 0b1; + return(s1perms) +} + +bitfield POR_EL1_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register POR_EL1 : POR_EL1_Type + +bitfield POR_EL2_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register POR_EL2 : POR_EL2_Type + +bitfield POR_EL3_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register POR_EL3 : POR_EL3_Type + +val AArch64_S1POR : Regime -> S1PORType + +function AArch64_S1POR regime = { + match regime { + Regime_EL3 => { + return(Mk_S1PORType(POR_EL3.bits)) + }, + Regime_EL2 => { + return(Mk_S1PORType(POR_EL2.bits)) + }, + Regime_EL20 => { + return(Mk_S1PORType(POR_EL2.bits)) + }, + Regime_EL10 => { + return(Mk_S1PORType(POR_EL1.bits)) + }, + _ => { + return(undefined : S1PORType) + } + } +} + +bitfield POR_EL0_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register POR_EL0 : POR_EL0_Type + +val AArch64_S1OverlayPermissions : (Regime, TTWState, AccessDescriptor) -> S1AccessControls + +function AArch64_S1OverlayPermissions (regime, walkstate, accdesc) = { + r : bits(1) = undefined; + w : bits(1) = undefined; + x : bits(1) = undefined; + pr : bits(1) = undefined; + pw : bits(1) = undefined; + px : bits(1) = undefined; + ur : bits(1) = undefined; + uw : bits(1) = undefined; + ux : bits(1) = undefined; + let permissions : Permissions = walkstate.permissions; + s1overlay_perms : S1AccessControls = undefined; + let por : S1PORType = AArch64_S1POR(regime); + let 'bit_index = 4 * UInt(permissions.po_index); + let ppo : bits(4) = por.bits[bit_index + 3 .. bit_index]; + match ppo { + 0b0000 => { + (pr, pw, px) = (0b0, 0b0, 0b0) + }, + 0b0001 => { + (pr, pw, px) = (0b1, 0b0, 0b0) + }, + 0b0010 => { + (pr, pw, px) = (0b0, 0b0, 0b1) + }, + 0b0011 => { + (pr, pw, px) = (0b1, 0b0, 0b1) + }, + 0b0100 => { + (pr, pw, px) = (0b0, 0b1, 0b0) + }, + 0b0101 => { + (pr, pw, px) = (0b1, 0b1, 0b0) + }, + 0b0110 => { + (pr, pw, px) = (0b0, 0b1, 0b1) + }, + 0b0111 => { + (pr, pw, px) = (0b1, 0b1, 0b1) + }, + [bitone, _, _, _] => { + (pr, pw, px) = (0b0, 0b0, 0b0) + } + }; + if HasUnprivileged(regime) then { + let upo : bits(4) = POR_EL0.bits[bit_index + 3 .. bit_index]; + match upo { + 0b0000 => { + (ur, uw, ux) = (0b0, 0b0, 0b0) + }, + 0b0001 => { + (ur, uw, ux) = (0b1, 0b0, 0b0) + }, + 0b0010 => { + (ur, uw, ux) = (0b0, 0b0, 0b1) + }, + 0b0011 => { + (ur, uw, ux) = (0b1, 0b0, 0b1) + }, + 0b0100 => { + (ur, uw, ux) = (0b0, 0b1, 0b0) + }, + 0b0101 => { + (ur, uw, ux) = (0b1, 0b1, 0b0) + }, + 0b0110 => { + (ur, uw, ux) = (0b0, 0b1, 0b1) + }, + 0b0111 => { + (ur, uw, ux) = (0b1, 0b1, 0b1) + }, + [bitone, _, _, _] => { + (ur, uw, ux) = (0b0, 0b0, 0b0) + } + } + }; + (r, w, x) = if accdesc.el == EL0 then (ur, uw, ux) else (pr, pw, px); + s1overlay_perms.or = r; + s1overlay_perms.ow = w; + s1overlay_perms.ox = x; + return(s1overlay_perms) +} + +val AArch64_S1POEnabled : Regime -> bool + +function AArch64_S1POEnabled regime = { + if not_bool(HaveS1POExt()) then { + return(false) + }; + match regime { + Regime_EL3 => { + return(TCR_EL3[POE] == 0b1) + }, + Regime_EL2 => { + return(IsTCR2EL2Enabled() & TCR2_EL2[POE] == 0b1) + }, + Regime_EL20 => { + return(IsTCR2EL2Enabled() & TCR2_EL2[POE] == 0b1) + }, + Regime_EL10 => { + return(IsTCR2EL1Enabled() & TCR2_EL1[POE] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch64_S1ComputePermissions : (Regime, TTWState, S1TTWParams, AccessDescriptor) -> S1AccessControls + +function AArch64_S1ComputePermissions (regime, walkstate, walkparams, accdesc) = { + s1overlay_perms : S1AccessControls = undefined; + let permissions : Permissions = walkstate.permissions; + s1perms : S1AccessControls = undefined; + if walkparams.pie == 0b1 then { + s1perms = AArch64_S1IndirectBasePermissions(regime, walkstate, walkparams, accdesc) + } else { + s1perms = AArch64_S1DirectBasePermissions(regime, walkstate, walkparams, accdesc) + }; + if accdesc.el == EL0 & not_bool(AArch64_S1E0POEnabled(regime, walkparams.nv1)) then { + s1perms.overlay = false + } else if accdesc.el != EL0 & not_bool(AArch64_S1POEnabled(regime)) then { + s1perms.overlay = false + } else (); + if s1perms.overlay then { + let s1overlay_perms : S1AccessControls = AArch64_S1OverlayPermissions(regime, walkstate, accdesc); + s1perms.or = s1overlay_perms.or; + s1perms.ow = s1overlay_perms.ow; + s1perms.ox = s1overlay_perms.ox + }; + if (s1perms.overlay & s1perms.wxn == 0b1) & s1perms.ox == 0b1 then { + s1perms.ow = 0b0 + } else if s1perms.wxn == 0b1 then { + s1perms.x = 0b0 + } else (); + return(s1perms) +} + +val AArch64_S1CheckPermissions : (FaultRecord, Regime, TTWState, S1TTWParams, AccessDescriptor) -> FaultRecord + +function AArch64_S1CheckPermissions (fault_in, regime, walkstate, walkparams, accdesc) = { + fault : FaultRecord = fault_in; + let permissions : Permissions = walkstate.permissions; + let s1perms : S1AccessControls = AArch64_S1ComputePermissions(regime, walkstate, walkparams, accdesc); + if accdesc.acctype == AccessType_IFETCH then { + if s1perms.overlay & s1perms.ox == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if walkstate.memattrs.memtype == MemType_Device & ConstrainUnpredictable(Unpredictable_INSTRDEVICE) == Constraint_FAULT then { + fault.statuscode = Fault_Permission + } else if s1perms.x == 0b0 then { + fault.statuscode = Fault_Permission + } else () + } else if accdesc.acctype == AccessType_DC then { + if accdesc.cacheop == CacheOp_Invalidate then { + if s1perms.overlay & s1perms.ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if s1perms.w == 0b0 then { + fault.statuscode = Fault_Permission + } else () + } else if accdesc.el == EL0 then { + if s1perms.overlay & s1perms.or == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if (((walkparams.cmow == 0b1 & accdesc.opscope == CacheOpScope_PoC) & accdesc.cacheop == CacheOp_CleanInvalidate) & s1perms.overlay) & s1perms.ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if s1perms.r == 0b0 then { + fault.statuscode = Fault_Permission + } else if ((walkparams.cmow == 0b1 & accdesc.opscope == CacheOpScope_PoC) & accdesc.cacheop == CacheOp_CleanInvalidate) & s1perms.w == 0b0 then { + fault.statuscode = Fault_Permission + } else () + } else () + } else if accdesc.acctype == AccessType_IC then { + if accdesc.el == EL0 then { + if (s1perms.overlay & s1perms.or == 0b0) & __IMPDEF_boolean("Permission fault on EL0 IC_IVAU execution") then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if (walkparams.cmow == 0b1 & s1perms.overlay) & s1perms.ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if s1perms.r == 0b0 & __IMPDEF_boolean("Permission fault on EL0 IC_IVAU execution") then { + fault.statuscode = Fault_Permission + } else if walkparams.cmow == 0b1 & s1perms.w == 0b0 then { + fault.statuscode = Fault_Permission + } else () + }; + () + } else if HaveGCS() & accdesc.acctype == AccessType_GCS then { + if s1perms.gcs == 0b0 then { + fault.statuscode = Fault_Permission + } else if (accdesc.write & (walkparams.ha @ walkparams.hd) != 0b11) & permissions.ndirty == 0b1 then { + fault.statuscode = Fault_Permission; + fault.dirtybit = true; + fault.write = true + } else () + } else if (accdesc.read & s1perms.overlay) & s1perms.or == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true; + fault.write = false + } else if (accdesc.write & s1perms.overlay) & s1perms.ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true; + fault.write = true + } else if accdesc.read & s1perms.r == 0b0 then { + fault.statuscode = Fault_Permission; + fault.write = false + } else if accdesc.write & s1perms.w == 0b0 then { + fault.statuscode = Fault_Permission; + fault.write = true + } else if (accdesc.write & accdesc.tagaccess) & walkstate.memattrs.tags == MemTag_CanonicallyTagged then { + fault.statuscode = Fault_Permission; + fault.write = true; + fault.s1tagnotdata = true + } else if ((accdesc.write & not_bool((walkparams.ha @ walkparams.hd) == 0b11)) & walkparams.pie == 0b1) & permissions.ndirty == 0b1 then { + fault.statuscode = Fault_Permission; + fault.dirtybit = true; + fault.write = true + } else (); + return(fault) +} + +val AArch64_S1DCacheEnabled : Regime -> bool + +function AArch64_S1DCacheEnabled regime = { + match regime { + Regime_EL3 => { + return(SCTLR_EL3[C] == 0b1) + }, + Regime_EL2 => { + return(SCTLR_EL2[C] == 0b1) + }, + Regime_EL20 => { + return(SCTLR_EL2[C] == 0b1) + }, + Regime_EL10 => { + return(SCTLR_EL1[C] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch64_AddrTop : (bits(1), AccessType, bits(1)) -> int + +function AArch64_AddrTop (tbid, acctype, tbi) = { + if tbid == 0b1 & acctype == AccessType_IFETCH then { + return(63) + }; + if tbi == 0b1 then { + return(55) + } else { + return(63) + } +} + +bitfield MECID_P0_EL2_Type : bits(64) = {MECID : 15..0} + +register MECID_P0_EL2 : MECID_P0_EL2_Type + +bitfield VMECID_P_EL2_Type : bits(64) = {MECID : 15..0} + +register VMECID_P_EL2 : VMECID_P_EL2_Type + +val AArch64_S1DisabledOutputMECID : (S1TTWParams, Regime, PASpace) -> bits(16) + +function AArch64_S1DisabledOutputMECID (walkparams, regime, paspace) = { + if walkparams.emec == 0b0 then { + return(DEFAULT_MECID) + }; + if not_bool(regime == Regime_EL2 | regime == Regime_EL20 | regime == Regime_EL10) then { + return(DEFAULT_MECID) + }; + if paspace != PAS_Realm then { + return(DEFAULT_MECID) + }; + if regime == Regime_EL10 then { + return(VMECID_P_EL2[MECID]) + } else { + return(MECID_P0_EL2[MECID]) + } +} + +val AArch64_S1HasAlignmentFault : forall ('aligned : Bool). + (AccessDescriptor, bool('aligned), bits(1), MemoryAttributes) -> bool + +function AArch64_S1HasAlignmentFault (accdesc, aligned, ntlsmd, memattrs) = { + if accdesc.acctype == AccessType_IFETCH then { + return(false) + } else if (HaveMTEExt() & accdesc.tagaccess) & accdesc.write then { + return(memattrs.memtype == MemType_Device & ConstrainUnpredictable(Unpredictable_DEVICETAGSTORE) == Constraint_FAULT) + } else if accdesc.a32lsmd & ntlsmd == 0b0 then { + return(memattrs.memtype == MemType_Device & memattrs.device != DeviceType_GRE) + } else if accdesc.acctype == AccessType_DCZero then { + return(memattrs.memtype == MemType_Device) + } else { + return(memattrs.memtype == MemType_Device & not_bool(aligned)) + } +} + +val AArch64_S1ICacheEnabled : Regime -> bool + +function AArch64_S1ICacheEnabled regime = { + match regime { + Regime_EL3 => { + return(SCTLR_EL3[I] == 0b1) + }, + Regime_EL2 => { + return(SCTLR_EL2[I] == 0b1) + }, + Regime_EL20 => { + return(SCTLR_EL2[I] == 0b1) + }, + Regime_EL10 => { + return(SCTLR_EL1[I] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch64_S1DisabledOutput : forall ('aligned : Bool). + (FaultRecord, Regime, bits(64), AccessDescriptor, bool('aligned)) -> (FaultRecord, AddressDescriptor) + +function AArch64_S1DisabledOutput (fault_in, regime, va_in, accdesc, aligned) = { + ipa : AddressDescriptor = undefined; + va : bits(64) = va_in; + let walkparams : S1TTWParams = AArch64_GetS1TTWParams(regime, accdesc.ss, va); + fault : FaultRecord = fault_in; + SetInGuardedPage(false); + oa : FullAddress = undefined; + oa.address = va[55 .. 0]; + match accdesc.ss { + SS_Secure => { + oa.paspace = PAS_Secure + }, + SS_NonSecure => { + oa.paspace = PAS_NonSecure + }, + SS_Root => { + oa.paspace = PAS_Root + }, + SS_Realm => { + oa.paspace = PAS_Realm + } + }; + memattrs : MemoryAttributes = undefined; + if (regime == Regime_EL10 & EL2Enabled()) & walkparams.dc == 0b1 then { + default_cacheability : MemAttrHints = undefined; + default_cacheability.attrs = MemAttr_WB; + default_cacheability.hints = MemHint_RWA; + default_cacheability.transient = false; + memattrs.memtype = MemType_Normal; + memattrs.outer = default_cacheability; + memattrs.inner = default_cacheability; + memattrs.shareability = Shareability_NSH; + if walkparams.dct == 0b1 then { + memattrs.tags = MemTag_AllocationTagged + } else if walkparams.mtx == 0b1 then { + memattrs.tags = MemTag_CanonicallyTagged; + if walkparams.tbi == 0b0 then { + va[59 .. 56] = Replicate([va[55]], 4) + }; + () + } else { + memattrs.tags = MemTag_Untagged + }; + memattrs.xs = 0b0 + } else if accdesc.acctype == AccessType_IFETCH then { + i_cache_attr : MemAttrHints = undefined; + if AArch64_S1ICacheEnabled(regime) then { + i_cache_attr.attrs = MemAttr_WT; + i_cache_attr.hints = MemHint_RA; + i_cache_attr.transient = false + } else { + i_cache_attr.attrs = MemAttr_NC + }; + memattrs.memtype = MemType_Normal; + memattrs.outer = i_cache_attr; + memattrs.inner = i_cache_attr; + memattrs.shareability = Shareability_OSH; + if walkparams.mtx == 0b1 then { + memattrs.tags = MemTag_CanonicallyTagged + } else { + memattrs.tags = MemTag_Untagged + }; + memattrs.xs = 0b1 + } else { + memattrs.memtype = MemType_Device; + memattrs.device = DeviceType_nGnRnE; + memattrs.shareability = Shareability_OSH; + if walkparams.mtx == 0b1 then { + memattrs.tags = MemTag_CanonicallyTagged; + if walkparams.tbi == 0b0 then { + if HasUnprivileged(regime) then { + va[59 .. 56] = Replicate([va[55]], 4) + } else { + va[59 .. 56] = 0b0000 + } + }; + () + } else { + memattrs.tags = MemTag_Untagged + }; + memattrs.xs = 0b1 + }; + memattrs.notagaccess = false; + fault.level = 0; + let 'addrtop = AArch64_AddrTop(walkparams.tbid, accdesc.acctype, walkparams.tbi); + if not_bool(is_zero_subrange(va, addrtop, AArch64_PAMax())) then { + fault.statuscode = Fault_AddressSize + } else if AArch64_S1HasAlignmentFault(accdesc, aligned, walkparams.ntlsmd, memattrs) then { + fault.statuscode = Fault_Alignment + } else (); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + } else { + ipa : AddressDescriptor = CreateAddressDescriptor(va_in, oa, memattrs); + ipa.mecid = AArch64_S1DisabledOutputMECID(walkparams, regime, ipa.paddress.paspace); + return((fault, ipa)) + } +} + +val AArch64_S1Enabled : (Regime, AccessType) -> bool + +function AArch64_S1Enabled (regime, acctype) = { + match regime { + Regime_EL3 => { + return(SCTLR_EL3[M] == 0b1) + }, + Regime_EL2 => { + return(SCTLR_EL2[M] == 0b1) + }, + Regime_EL20 => { + return(SCTLR_EL2[M] == 0b1) + }, + Regime_EL10 => { + return((not_bool(EL2Enabled()) | (HCR_EL2[DC] @ HCR_EL2[TGE]) == 0b00) & SCTLR_EL1[M] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +bitfield MECID_A0_EL2_Type : bits(64) = {MECID : 15..0} + +register MECID_A0_EL2 : MECID_A0_EL2_Type + +bitfield MECID_A1_EL2_Type : bits(64) = {MECID : 15..0} + +register MECID_A1_EL2 : MECID_A1_EL2_Type + +bitfield MECID_P1_EL2_Type : bits(64) = {MECID : 15..0} + +register MECID_P1_EL2 : MECID_P1_EL2_Type + +bitfield MECID_RL_A_EL3_Type : bits(64) = {MECID : 15..0} + +register MECID_RL_A_EL3 : MECID_RL_A_EL3_Type + +val AArch64_S1OutputMECID : forall 'N, 'N in {64, 128}. + (S1TTWParams, Regime, VARange, PASpace, bits('N)) -> bits(16) + +function AArch64_S1OutputMECID (walkparams, regime, varange, paspace, descriptor) = { + assert('N == 64 | 'N == 128); + if walkparams.emec == 0b0 then { + return(DEFAULT_MECID) + }; + if paspace != PAS_Realm then { + return(DEFAULT_MECID) + }; + let descriptor_amec : bits(1) = if walkparams.d128 == 0b1 then { + assert(constraint(103 < 'N)); + [descriptor[103]] + } else [descriptor[63]]; + match regime { + Regime_EL3 => { + return(MECID_RL_A_EL3[MECID]) + }, + Regime_EL2 => { + if descriptor_amec == 0b0 then { + return(MECID_P0_EL2[MECID]) + } else { + return(MECID_A0_EL2[MECID]) + } + }, + Regime_EL20 => { + if varange == VARange_LOWER then { + if descriptor_amec == 0b0 then { + return(MECID_P0_EL2[MECID]) + } else { + return(MECID_A0_EL2[MECID]) + } + } else { + if descriptor_amec == 0b0 then { + return(MECID_P1_EL2[MECID]) + } else { + return(MECID_A1_EL2[MECID]) + } + } + }, + Regime_EL10 => { + return(VMECID_P_EL2[MECID]) + }, + _ => { + return(undefined : bits(16)) + } + } +} + +val AArch64_BlockBBMSupportLevel : unit -> int + +function AArch64_BlockBBMSupportLevel () = { + if not_bool(HaveBlockBBM()) then { + return(__UNKNOWN_integer()) + } else { + return(__IMPDEF_integer("Block BBM support level")) + } +} + +val AArch64_BlocknTFaults : forall 'N, 'N >= 0. (bits(1), bits('N)) -> bool + +function AArch64_BlocknTFaults (d128, descriptor) = { + if not_bool(HaveBlockBBM()) then { + return(false) + }; + let nT : bits(1) = if d128 == 0b1 then { + assert(constraint(6 < 'N)); + [descriptor[6]] + } else { + assert(constraint(16 < 'N)); + [descriptor[16]] + }; + let 'bbm_level = AArch64_BlockBBMSupportLevel(); + let nT_faults : bool = __IMPDEF_boolean("BBM level 1 or 2 support nT bit causes Translation Fault"); + return(((bbm_level == 1 | bbm_level == 2) & nT == 0b1) & nT_faults) +} + +val AArch64_IASize : bits(6) -> int + +function AArch64_IASize txsz = { + return(64 - UInt(txsz)) +} + +val AArch64_ContiguousBitFaults : forall 'level. + (bits(1), bits(6), TGx, int('level)) -> bool + +function AArch64_ContiguousBitFaults (d128, txsz, tgx, level) = { + let 'iasize = AArch64_IASize(txsz); + let 'tsize = TranslationSize(d128, tgx, level) + ContiguousSize(d128, tgx, level); + return(tsize > iasize & __IMPDEF_boolean("Translation fault on misprogrammed contiguous bit")) +} + +val AArch64_BlockDescSupported : forall 'level. + (bits(1), bits(1), TGx, int('level)) -> bool + +function AArch64_BlockDescSupported (d128, ds, tgx, level) = { + match tgx { + TGx_4KB => { + return((level == 0 & (ds == 0b1 | d128 == 0b1) | level == 1) | level == 2) + }, + TGx_16KB => { + return(level == 1 & (ds == 0b1 | d128 == 0b1) | level == 2) + }, + TGx_64KB => { + return(level == 1 & (d128 == 0b1 | AArch64_PAMax() >= 52) | level == 2) + } + }; + return(false) +} + +val AArch64_DecodeDescriptorType : forall 'N 'level, 0 < 'N. + (bits('N), bits(1), bits(1), TGx, int('level)) -> DescriptorType + +function AArch64_DecodeDescriptorType (descriptor, d128, ds, tgx, level) = { + if [descriptor[0]] == 0b0 then { + return(DescriptorType_Invalid) + } else if d128 == 0b1 then { + assert(constraint(110 < 'N)); + let skl : bits(2) = descriptor[110 .. 109]; + if (tgx == TGx_16KB | tgx == TGx_64KB) & UInt(skl) == 3 then { + return(DescriptorType_Invalid) + }; + let 'effective_level = level + UInt(skl); + if effective_level > FINAL_LEVEL then { + return(DescriptorType_Invalid) + } else if effective_level == FINAL_LEVEL then { + return(DescriptorType_Leaf) + } else { + return(DescriptorType_Table) + } + } else { + assert(constraint(1 < 'N)); + if [descriptor[1]] == 0b1 then { + if level == FINAL_LEVEL then { + return(DescriptorType_Leaf) + } else { + return(DescriptorType_Table) + } + } else if [descriptor[1]] == 0b0 then { + if AArch64_BlockDescSupported(d128, ds, tgx, level) then { + return(DescriptorType_Leaf) + } else { + return(DescriptorType_Invalid) + } + } else { + return(undefined : DescriptorType) + } + } +} + +val VMID_read : unit -> bits(16) + +function VMID_read () = { + if EL2Enabled() then { + if not_bool(ELUsingAArch32(EL2)) then { + if Have16bitVMID() & VTCR_EL2[VS] == 0b1 then { + return(VTTBR_EL2_read()[VMID]) + } else { + return(ZeroExtend(VTTBR_EL2_read()[VMID][7 .. 0], 16)) + } + } else { + return(ZeroExtend(VTTBR[VMID], 16)) + } + } else if HaveEL(EL2) & HaveSecureEL2Ext() then { + return(Zeros(16)) + } else { + return(VMID_NONE) + } +} + +val AArch64_TLBContextEL10 : (SecurityState, bits(64), TGx) -> TLBContext + +function AArch64_TLBContextEL10 (ss, va, tg) = { + tlbcontext : TLBContext = undefined; + tlbcontext.ss = ss; + tlbcontext.regime = Regime_EL10; + tlbcontext.vmid = VMID_read(); + tlbcontext.asid = if TCR_EL1[A1] == 0b0 then TTBR0_EL1_read()[ASID] else + TTBR1_EL1_read()[ASID]; + if TCR_EL1[AS] == 0b0 then { + tlbcontext.asid[15 .. 8] = Zeros(8) + }; + tlbcontext.tg = tg; + tlbcontext.ia = va; + if HaveCommonNotPrivateTransExt() then { + if AArch64_GetVARange(va) == VARange_LOWER then { + tlbcontext.cnp = TTBR0_EL1_read()[CnP] + } else { + tlbcontext.cnp = TTBR1_EL1_read()[CnP] + } + } else { + tlbcontext.cnp = 0b0 + }; + return(tlbcontext) +} + +val AArch64_TLBContextEL2 : (SecurityState, bits(64), TGx) -> TLBContext + +function AArch64_TLBContextEL2 (ss, va, tg) = { + tlbcontext : TLBContext = undefined; + tlbcontext.ss = ss; + tlbcontext.regime = Regime_EL2; + tlbcontext.tg = tg; + tlbcontext.ia = va; + tlbcontext.cnp = if HaveCommonNotPrivateTransExt() then + TTBR0_EL2_read()[CnP] + else + 0b0; + return(tlbcontext) +} + +val AArch64_TLBContextEL20 : (SecurityState, bits(64), TGx) -> TLBContext + +function AArch64_TLBContextEL20 (ss, va, tg) = { + tlbcontext : TLBContext = undefined; + tlbcontext.ss = ss; + tlbcontext.regime = Regime_EL20; + tlbcontext.asid = if TCR_EL2[A1] == 0b0 then TTBR0_EL2_read()[ASID] else + TTBR1_EL2[ASID]; + if TCR_EL2[AS] == 0b0 then { + tlbcontext.asid[15 .. 8] = Zeros(8) + }; + tlbcontext.tg = tg; + tlbcontext.ia = va; + if HaveCommonNotPrivateTransExt() then { + if AArch64_GetVARange(va) == VARange_LOWER then { + tlbcontext.cnp = TTBR0_EL2_read()[CnP] + } else { + tlbcontext.cnp = TTBR1_EL2[CnP] + } + } else { + tlbcontext.cnp = 0b0 + }; + return(tlbcontext) +} + +val AArch64_TLBContextEL3 : (SecurityState, bits(64), TGx) -> TLBContext + +function AArch64_TLBContextEL3 (ss, va, tg) = { + tlbcontext : TLBContext = undefined; + tlbcontext.ss = ss; + tlbcontext.regime = Regime_EL3; + tlbcontext.tg = tg; + tlbcontext.ia = va; + tlbcontext.cnp = if HaveCommonNotPrivateTransExt() then TTBR0_EL3[CnP] else + 0b0; + return(tlbcontext) +} + +val AArch64_GetS1TLBContext : (Regime, SecurityState, bits(64), TGx) -> TLBContext + +function AArch64_GetS1TLBContext (regime, ss, va, tg) = { + tlbcontext : TLBContext = undefined; + match regime { + Regime_EL3 => { + tlbcontext = AArch64_TLBContextEL3(ss, va, tg) + }, + Regime_EL2 => { + tlbcontext = AArch64_TLBContextEL2(ss, va, tg) + }, + Regime_EL20 => { + tlbcontext = AArch64_TLBContextEL20(ss, va, tg) + }, + Regime_EL10 => { + tlbcontext = AArch64_TLBContextEL10(ss, va, tg) + }, + _ => () + }; + tlbcontext.includes_s1_name = true; + tlbcontext.includes_s2_name = false; + tlbcontext.includes_gpt_name = false; + return(tlbcontext) +} + +val AArch64_GetTranslationStartInfo : (Regime, SecurityState, AccessDescriptor, bits(64), int) -> TranslationStartInfo + +function AArch64_GetTranslationStartInfo (regime, ss, accdesc, va, size) = { + let tlbcontext : TLBContext = AArch64_GetS1TLBContext(regime, ss, va, undefined /* TGx unused */); + let tsi : TranslationStartInfo = struct { + ss = ss, + regime = regime, + vmid = tlbcontext.vmid, + asid = tlbcontext.asid, + va = va, + cnp = tlbcontext.cnp, + accdesc = accdesc, + size = size + }; + return(tsi) +} + +val AArch64_PhysicalAddressSize : (bits(1), bits(3), TGx) -> int + +function AArch64_PhysicalAddressSize (d128, encoded_ps, tgx) = { + ps : {32, 36, 40, 42, 44, 48, 52, 56} = 32; + max_ps : int = undefined; + match encoded_ps { + 0b000 => { + ps = 32 + }, + 0b001 => { + ps = 36 + }, + 0b010 => { + ps = 40 + }, + 0b011 => { + ps = 42 + }, + 0b100 => { + ps = 44 + }, + 0b101 => { + ps = 48 + }, + 0b110 => { + ps = 52 + }, + 0b111 => { + ps = 56 + } + }; + let 'ps = ps; + if not_bool(Have56BitPAExt()) | d128 == 0b0 then { + if tgx != TGx_64KB & not_bool(Have52BitIPAAndPASpaceExt()) then { + max_ps = Min(48, AArch64_PAMax()) + } else if not_bool(Have52BitPAExt()) then { + max_ps = Min(48, AArch64_PAMax()) + } else { + max_ps = Min(52, AArch64_PAMax()) + } + } else { + max_ps = AArch64_PAMax() + }; + let 'max_ps = max_ps; + return(Min(ps, max_ps)) +} + +val AArch64_OAOutOfRange : (bits(56), bits(1), bits(3), TGx) -> bool + +function AArch64_OAOutOfRange (address, d128, ps, tgx) = { + let 'oasize = AArch64_PhysicalAddressSize(d128, ps, tgx); + if oasize < 56 then { + return(not_bool(is_zero_subrange(address, 55, oasize))) + } else { + return(false) + } +} + +val AArch64_S1AMECFault : forall 'N, 'N in {64, 128}. + (S1TTWParams, PASpace, Regime, bits('N)) -> bool + +function AArch64_S1AMECFault (walkparams, paspace, regime, descriptor) = { + assert('N == 64 | 'N == 128); + let descriptor_amec : bits(1) = if walkparams.d128 == 0b1 then { + assert(constraint(103 < 'N)); + [descriptor[103]] + } else [descriptor[63]]; + return((((walkparams.emec @ walkparams.amec) == 0b10 & (regime == Regime_EL2 | regime == Regime_EL20)) & paspace == PAS_Realm) & descriptor_amec == 0b1) +} + +val AArch64_S1EPD : (Regime, bits(64)) -> bits(1) + +function AArch64_S1EPD (regime, va) = { + assert(HasUnprivileged(regime)); + let varange : VARange = AArch64_GetVARange(va); + match regime { + Regime_EL20 => { + return(if varange == VARange_LOWER then TCR_EL2[EPD0] else + TCR_EL2[EPD1]) + }, + Regime_EL10 => { + return(if varange == VARange_LOWER then TCR_EL1[EPD0] else + TCR_EL1[EPD1]) + }, + _ => { + return(undefined : bits(1)) + } + } +} + +val AArch64_S1StartLevel : S1TTWParams -> int + +function AArch64_S1StartLevel walkparams = { + let 'iasize = AArch64_IASize(walkparams.txsz); + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'descsizelog2 = if walkparams.d128 == 0b1 then 4 else 3; + let 'stride = granulebits - descsizelog2; + s1startlevel : int = FINAL_LEVEL - DIV(iasize - 1 - granulebits, stride); + if walkparams.d128 == 0b1 then { + s1startlevel = s1startlevel + UInt(walkparams.skl) + }; + let 's1startlevel = s1startlevel; + return(s1startlevel) +} + +val AArch64_S1TTBR : (Regime, bits(64)) -> bits(128) + +function AArch64_S1TTBR (regime, va) = { + let varange : VARange = AArch64_GetVARange(va); + match regime { + Regime_EL3 => { + return(ZeroExtend(TTBR0_EL3.bits, 128)) + }, + Regime_EL2 => { + return(ZeroExtend(TTBR0_EL2_read().bits, 128)) + }, + Regime_EL20 => { + if varange == VARange_LOWER then { + return(ZeroExtend(TTBR0_EL2_read().bits, 128)) + } else { + return(ZeroExtend(TTBR1_EL2.bits, 128)) + } + }, + Regime_EL10 => { + if varange == VARange_LOWER then { + return(ZeroExtend(TTBR0_EL1_read().bits, 128)) + } else { + return(ZeroExtend(TTBR1_EL1_read().bits, 128)) + } + }, + _ => { + return(undefined : bits(128)) + } + } +} + +val AArch64_S1TTBaseAddress : forall 'N, 'N >= 0. + (S1TTWParams, Regime, bits('N)) -> bits(56) + +function AArch64_S1TTBaseAddress (walkparams, regime, ttbr) = { + tablebase : bits(56) = Zeros(56); + let 'iasize = AArch64_IASize(walkparams.txsz); + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'descsizelog2 = if walkparams.d128 == 0b1 then 4 else 3; + let 'stride = granulebits - descsizelog2; + let 'startlevel = AArch64_S1StartLevel(walkparams); + let 'levels = FINAL_LEVEL - startlevel; + tsize : int = iasize - (levels * stride + granulebits) + descsizelog2; + if Have56BitPAExt() & walkparams.d128 == 0b1 then { + tsize = Max(tsize, 5); + if regime == Regime_EL3 then { + assert(constraint(55 < 'N)); + tablebase[55 .. 5] = ttbr[55 .. 5] + } else { + assert(constraint(87 < 'N)); + tablebase[55 .. 5] = ttbr[87 .. 80] @ ttbr[47 .. 5] + } + } else if (Have52BitPAExt() & walkparams.tgx == TGx_64KB) & walkparams.ps == 0b110 | walkparams.ds == 0b1 then { + tsize = Max(tsize, 6); + assert(constraint(5 < 'N)); + assert(constraint(47 < 'N)); + tablebase[51 .. 6] = ttbr[5 .. 2] @ ttbr[47 .. 6] + } else { + assert(constraint(47 < 'N)); + tablebase[47 .. 1] = ttbr[47 .. 1] + }; + let 'tsize = tsize; + let tablebase : bits(56) = Align(tablebase, (1 << tsize)); + return(tablebase) +} + +val AArch64_S1InitialTTWState : (S1TTWParams, bits(64), Regime, SecurityState) -> TTWState + +function AArch64_S1InitialTTWState (walkparams, va, regime, ss) = { + walkstate : TTWState = undefined; + tablebase : FullAddress = undefined; + permissions : Permissions = undefined; + let ttbr : bits(128) = AArch64_S1TTBR(regime, va); + match ss { + SS_Secure => { + tablebase.paspace = PAS_Secure + }, + SS_NonSecure => { + tablebase.paspace = PAS_NonSecure + }, + SS_Root => { + tablebase.paspace = PAS_Root + }, + SS_Realm => { + tablebase.paspace = PAS_Realm + } + }; + tablebase.address = AArch64_S1TTBaseAddress(walkparams, regime, ttbr); + permissions.ap_table = 0b00; + if HasUnprivileged(regime) then { + permissions.uxn_table = 0b0; + permissions.pxn_table = 0b0 + } else { + permissions.xn_table = 0b0 + }; + walkstate.baseaddress = tablebase; + walkstate.level = AArch64_S1StartLevel(walkparams); + walkstate.istable = true; + walkstate.nG = if HasUnprivileged(regime) then 0b1 else 0b0; + walkstate.memattrs = WalkMemAttrs(walkparams.sh, walkparams.irgn, walkparams.orgn); + walkstate.permissions = permissions; + if walkparams.d128 == 0b1 | walkparams.pnch == 0b1 then { + walkstate.s1assured = true + } else { + walkstate.s1assured = false + }; + walkstate.disch = walkparams.disch; + return(walkstate) +} + +val AArch64_ContiguousBit : forall 'N 'level, 52 < 'N. + (TGx, bits(1), int('level), bits('N)) -> bits(1) + +function AArch64_ContiguousBit (tgx, d128, level, descriptor) = { + if d128 == 0b1 then { + if tgx == TGx_64KB & level == 1 | tgx == TGx_4KB & level == 0 then { + return(0b0) + } else { + assert(constraint(111 < 'N)); + return([descriptor[111]]) + } + }; + if tgx == TGx_64KB & level == 1 then { + return(0b0) + }; + if tgx == TGx_16KB & level == 1 then { + return(0b0) + }; + if tgx == TGx_4KB & level == 0 then { + return(0b0) + }; + return([descriptor[52]]) +} + +val AArch64_LeafBase : forall 'N 'level, 'N >= 0. + (bits('N), bits(1), bits(1), TGx, int('level)) -> bits(56) + +function AArch64_LeafBase (descriptor, d128, ds, tgx, level) = { + leafbase : bits(56) = Zeros(56); + let 'granulebits = TGxGranuleBits(tgx); + let 'descsizelog2 = if d128 == 0b1 then 4 else 3; + let 'stride = granulebits - descsizelog2; + let 'leafsize = granulebits + stride * (FINAL_LEVEL - level); + assert(constraint((0 <= 'leafsize & 'leafsize <= 47 & 47 < 'N))); + leafbase[47 .. 0] = descriptor[47 .. leafsize] @ Zeros(leafsize); + if Have56BitPAExt() & d128 == 0b1 then { + assert(constraint(55 < 'N)); + leafbase[55 .. 48] = descriptor[55 .. 48]; + return(leafbase) + }; + if Have52BitPAExt() & tgx == TGx_64KB then { + leafbase[51 .. 48] = descriptor[15 .. 12] + } else if ds == 0b1 then { + assert(constraint(49 < 'N)); + leafbase[51 .. 48] = descriptor[9 .. 8] @ descriptor[49 .. 48] + } else (); + return(leafbase) +} + +val AArch64_MAIRAttr : forall 'index. + (int('index), MAIRType, MAIRType) -> bits(8) + +function AArch64_MAIRAttr (index, mair2, mair) = { + bit_index : int = 8 * index; + assert(index < 8 | HaveAIEExt() & index < 16); + if index > 7 then { + let 'bit_index = bit_index - 64; + assert(constraint((0 <= 'bit_index & 'bit_index <= 'bit_index + 7 & 'bit_index + 7 < 64))); + return(mair2.bits[bit_index + 7 .. bit_index]) + } else { + let 'bit_index = bit_index; + assert(constraint((0 <= 'bit_index & 'bit_index <= 'bit_index + 7 & 'bit_index + 7 < 64))); + return(mair.bits[bit_index + 7 .. bit_index]) + } +} + +val AArch64_S1ApplyOutputPerms : forall 'N, 'N >= 0. + (Permissions, bits('N), Regime, S1TTWParams) -> Permissions + +function AArch64_S1ApplyOutputPerms (permissions_in, descriptor, regime, walkparams) = { + bit_index : int = undefined; + permissions : Permissions = permissions_in; + pi_index : bits(4) = undefined; + if walkparams.pie == 0b1 then { + if walkparams.d128 == 0b1 then { + assert(constraint(118 < 'N)); + pi_index = descriptor[118 .. 115] + } else { + assert(constraint(54 < 'N)); + pi_index = (descriptor[54 .. 53] @ [descriptor[51]]) @ [descriptor[6]] + }; + let 'bit_index = 4 * UInt(pi_index); + permissions.ppi = walkparams.pir.bits[bit_index + 3 .. bit_index]; + permissions.upi = walkparams.pire0.bits[bit_index + 3 .. bit_index]; + assert(constraint(7 < 'N)); + permissions.ndirty = [descriptor[7]] + } else { + if (regime == Regime_EL10 & EL2Enabled()) & walkparams.nv1 == 0b1 then { + assert(constraint(7 < 'N)); + permissions.ap[2 .. 1] = [descriptor[7]] @ 0b0; + assert(constraint(54 < 'N)); + permissions.pxn = [descriptor[54]] + } else if HasUnprivileged(regime) then { + assert(constraint(7 < 'N)); + permissions.ap[2 .. 1] = descriptor[7 .. 6]; + assert(constraint(54 < 'N)); + permissions.uxn = [descriptor[54]]; + permissions.pxn = [descriptor[53]] + } else { + assert(constraint(7 < 'N)); + permissions.ap[2 .. 1] = [descriptor[7]] @ 0b1; + assert(constraint(54 < 'N)); + permissions.xn = [descriptor[54]] + }; + assert(constraint(51 < 'N)); + if (walkparams.ha == 0b1 & walkparams.hd == 0b1) & [descriptor[51]] == 0b1 then { + permissions.ap[2] = Bit(0b0) + }; + () + }; + let poe : bool = AArch64_S1POEnabled(regime); + let e0poe : bool = HasUnprivileged(regime) & AArch64_S1E0POEnabled(regime, walkparams.nv1); + if poe | e0poe then { + if walkparams.d128 == 0b1 then { + assert(constraint(124 < 'N)); + permissions.po_index = descriptor[124 .. 121] + } else { + assert(constraint(62 < 'N)); + permissions.po_index = 0b0 @ descriptor[62 .. 60] + } + }; + return(permissions) +} + +val AArch64_S1NextWalkStateLeaf : forall 'N ('s2fs1mro : Bool), 'N >= 0. + (TTWState, bool('s2fs1mro), Regime, SecurityState, S1TTWParams, bits('N)) -> TTWState + +function AArch64_S1NextWalkStateLeaf (currentstate, s2fs1mro, regime, ss, walkparams, descriptor) = { + nextstate : TTWState = undefined; + baseaddress : FullAddress = undefined; + baseaddress.address = AArch64_LeafBase(descriptor, walkparams.d128, walkparams.ds, walkparams.tgx, currentstate.level); + if currentstate.baseaddress.paspace == PAS_Secure then { + let ns : bits(1) = if walkparams.d128 == 0b1 then { + assert(constraint(127 < 'N)); + [descriptor[127]] + } else { + assert(constraint(5 < 'N)); + [descriptor[5]] + }; + baseaddress.paspace = if ns == 0b0 then PAS_Secure else PAS_NonSecure + } else if currentstate.baseaddress.paspace == PAS_Root then { + nse : bits(1) = undefined; + ns : bits(1) = undefined; + (nse @ ns) = if walkparams.d128 == 0b1 then { + assert(constraint(11 < 'N)); + assert(constraint(127 < 'N)); + [descriptor[11]] @ [descriptor[127]] + } else { + assert(constraint(11 < 'N)); + [descriptor[11]] @ [descriptor[5]] + }; + baseaddress.paspace = DecodePASpace(nse, ns); + if baseaddress.paspace == PAS_Secure & not_bool(HaveSecureState()) then { + baseaddress.paspace = PAS_NonSecure + }; + () + } else if currentstate.baseaddress.paspace == PAS_Realm & (regime == Regime_EL2 | regime == Regime_EL20) then { + let ns : bits(1) = if walkparams.d128 == 0b1 then { + assert(constraint(127 < 'N)); + [descriptor[127]] + } else { + assert(constraint(5 < 'N)); + [descriptor[5]] + }; + baseaddress.paspace = if ns == 0b0 then PAS_Realm else PAS_NonSecure + } else if currentstate.baseaddress.paspace == PAS_Realm then { + baseaddress.paspace = PAS_Realm + } else { + baseaddress.paspace = PAS_NonSecure + }; + nextstate.istable = false; + nextstate.level = currentstate.level; + nextstate.baseaddress = baseaddress; + attrindx : bits(4) = undefined; + if walkparams.aie == 0b1 then { + if walkparams.d128 == 0b1 then { + assert(constraint(5 < 'N)); + attrindx = descriptor[5 .. 2] + } else { + assert(constraint(59 < 'N)); + attrindx = [descriptor[59]] @ descriptor[4 .. 2] + } + } else { + assert(constraint(4 < 'N)); + attrindx = 0b0 @ descriptor[4 .. 2] + }; + sh : bits(2) = undefined; + if walkparams.d128 == 0b1 then { + assert(constraint(9 < 'N)); + sh = descriptor[9 .. 8] + } else if walkparams.ds == 0b1 then { + sh = walkparams.sh + } else { + assert(constraint(9 < 'N)); + sh = descriptor[9 .. 8] + }; + let attr : bits(8) = AArch64_MAIRAttr(UInt(attrindx), walkparams.mair2, walkparams.mair); + let s1aarch64 : bool = true; + nextstate.memattrs = S1DecodeMemAttrs(attr, sh, s1aarch64, walkparams); + nextstate.permissions = AArch64_S1ApplyOutputPerms(currentstate.permissions, descriptor, regime, walkparams); + protectedbit : bits(1) = undefined; + if walkparams.d128 == 0b1 then { + assert(constraint(114 < 'N)); + protectedbit = [descriptor[114]] + } else { + protectedbit = if walkparams.pnch == 0b1 then { + assert(constraint(52 < 'N)); + [descriptor[52]] + } else 0b0 + }; + if (currentstate.s1assured & s2fs1mro) & protectedbit == 0b1 then { + nextstate.s1assured = true + } else { + nextstate.s1assured = false + }; + if walkparams.pnch == 0b1 | currentstate.disch == 0b1 then { + nextstate.contiguous = 0b0 + } else { + assert(constraint(52 < 'N)); + nextstate.contiguous = AArch64_ContiguousBit(walkparams.tgx, walkparams.d128, currentstate.level, descriptor) + }; + if not_bool(HasUnprivileged(regime)) then { + nextstate.nG = 0b0 + } else if ss == SS_Secure & currentstate.baseaddress.paspace == PAS_NonSecure then { + nextstate.nG = 0b1 + } else { + assert(constraint(11 < 'N)); + nextstate.nG = [descriptor[11]] + }; + if walkparams.d128 == 0b1 then { + assert(constraint(113 < 'N)); + nextstate.guardedpage = [descriptor[113]] + } else { + assert(constraint(50 < 'N)); + nextstate.guardedpage = [descriptor[50]] + }; + return(nextstate) +} + +val AArch64_NextTableBase : forall 'N, 'N >= 0. + (bits('N), bits(1), bits(1), TGx) -> bits(56) + +function AArch64_NextTableBase (descriptor, d128, ds, tgx) = { + tablebase : bits(56) = Zeros(56); + match tgx { + TGx_4KB => { + assert(constraint(47 < 'N)); + tablebase[47 .. 12] = descriptor[47 .. 12] + }, + TGx_16KB => { + assert(constraint(47 < 'N)); + tablebase[47 .. 14] = descriptor[47 .. 14] + }, + TGx_64KB => { + assert(constraint(47 < 'N)); + tablebase[47 .. 16] = descriptor[47 .. 16] + } + }; + if Have56BitPAExt() & d128 == 0b1 then { + assert(constraint(55 < 'N)); + tablebase[55 .. 48] = descriptor[55 .. 48]; + return(tablebase) + }; + if Have52BitPAExt() & tgx == TGx_64KB then { + assert(constraint(15 < 'N)); + tablebase[51 .. 48] = descriptor[15 .. 12]; + return(tablebase) + }; + if ds == 0b1 then { + assert(constraint(9 < 'N)); + assert(constraint(49 < 'N)); + tablebase[51 .. 48] = descriptor[9 .. 8] @ descriptor[49 .. 48]; + return(tablebase) + }; + return(tablebase) +} + +val AArch64_S1ApplyTablePerms : forall 'N, 'N >= 0. + (Permissions, bits('N), Regime, S1TTWParams) -> Permissions + +function AArch64_S1ApplyTablePerms (permissions_in, descriptor, regime, walkparams) = { + permissions : Permissions = permissions_in; + ap_table : bits(2) = undefined; + pxn_table : bits(1) = undefined; + uxn_table : bits(1) = undefined; + xn_table : bits(1) = undefined; + if (regime == Regime_EL10 & EL2Enabled()) & walkparams.nv1 == 0b1 then { + if walkparams.d128 == 0b1 then { + assert(constraint(126 < 'N)); + ap_table = [descriptor[126]] @ 0b0; + pxn_table = [descriptor[124]] + } else { + assert(constraint(62 < 'N)); + ap_table = [descriptor[62]] @ 0b0; + pxn_table = [descriptor[60]] + }; + permissions.ap_table = permissions.ap_table | ap_table; + permissions.pxn_table = permissions.pxn_table | pxn_table + } else if HasUnprivileged(regime) then { + if walkparams.d128 == 0b1 then { + assert(constraint(126 < 'N)); + ap_table = descriptor[126 .. 125]; + uxn_table = [descriptor[124]]; + pxn_table = [descriptor[123]] + } else { + assert(constraint(62 < 'N)); + ap_table = descriptor[62 .. 61]; + uxn_table = [descriptor[60]]; + pxn_table = [descriptor[59]] + }; + permissions.ap_table = permissions.ap_table | ap_table; + permissions.uxn_table = permissions.uxn_table | uxn_table; + permissions.pxn_table = permissions.pxn_table | pxn_table + } else { + if walkparams.d128 == 0b1 then { + assert(constraint(126 < 'N)); + ap_table = [descriptor[126]] @ 0b0; + xn_table = [descriptor[124]] + } else { + assert(constraint(62 < 'N)); + ap_table = [descriptor[62]] @ 0b0; + xn_table = [descriptor[60]] + }; + permissions.ap_table = permissions.ap_table | ap_table; + permissions.xn_table = permissions.xn_table | xn_table + }; + return(permissions) +} + +val AArch64_S1NextWalkStateTable : forall 'N ('s2fs1mro : Bool), 'N >= 0. + (TTWState, bool('s2fs1mro), Regime, S1TTWParams, bits('N)) -> TTWState + +function AArch64_S1NextWalkStateTable (currentstate, s2fs1mro, regime, walkparams, descriptor) = { + skl : bits(2) = undefined; + nextstate : TTWState = undefined; + tablebase : FullAddress = undefined; + tablebase.address = AArch64_NextTableBase(descriptor, walkparams.d128, walkparams.ds, walkparams.tgx); + if currentstate.baseaddress.paspace == PAS_Secure then { + let nstable : bits(1) = if walkparams.d128 == 0b1 then { + assert(constraint(127 < 'N)); + [descriptor[127]] + } else { + assert(constraint(63 < 'N)); + [descriptor[63]] + }; + tablebase.paspace = if nstable == 0b0 then PAS_Secure else PAS_NonSecure + } else { + tablebase.paspace = currentstate.baseaddress.paspace + }; + nextstate.istable = true; + nextstate.nG = currentstate.nG; + if walkparams.d128 == 0b1 then { + assert(constraint(110 < 'N)); + let skl : bits(2) = descriptor[110 .. 109]; + nextstate.level = currentstate.level + UInt(skl) + 1 + } else { + nextstate.level = currentstate.level + 1 + }; + nextstate.baseaddress = tablebase; + nextstate.memattrs = currentstate.memattrs; + if walkparams.hpd == 0b0 & walkparams.pie == 0b0 then { + nextstate.permissions = AArch64_S1ApplyTablePerms(currentstate.permissions, descriptor, regime, walkparams) + } else { + nextstate.permissions = currentstate.permissions + }; + protectedbit : bits(1) = undefined; + if walkparams.d128 == 0b1 then { + assert(constraint(114 < 'N)); + protectedbit = [descriptor[114]] + } else { + protectedbit = if walkparams.pnch == 0b1 then { + assert(constraint(52 < 'N)); + [descriptor[52]] + } else 0b0 + }; + if (currentstate.s1assured & s2fs1mro) & protectedbit == 0b1 then { + nextstate.s1assured = true + } else { + nextstate.s1assured = false + }; + nextstate.disch = if walkparams.d128 == 0b1 then { + assert(constraint(112 < 'N)); + [descriptor[112]] + } else 0b0; + return(nextstate) +} + +val AArch64_S1SLTTEntryAddress : forall 'level. + (int('level), S1TTWParams, bits(64), FullAddress) -> FullAddress + +function AArch64_S1SLTTEntryAddress (level, walkparams, ia, tablebase) = { + let 'iasize = AArch64_IASize(walkparams.txsz); + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'descsizelog2 = if walkparams.d128 == 0b1 then 4 else 3; + let 'stride = granulebits - descsizelog2; + let 'levels = FINAL_LEVEL - level; + let 'lsb = levels * stride + granulebits; + let 'msb = iasize - 1; + assert(constraint((0 <= 'lsb & 'lsb <= 'msb & 'msb < 64))); + assert(constraint(56 >= 'msb - 'lsb + 1 + 'descsizelog2)); + let index : bits(56) = ZeroExtend(ia[msb .. lsb] @ Zeros(descsizelog2), 56); + descaddress : FullAddress = undefined; + descaddress.address = tablebase.address | index; + descaddress.paspace = tablebase.paspace; + return(descaddress) +} + +val AArch64_HaveS2TG : TGx -> bool + +function AArch64_HaveS2TG tgx = { + assert(HaveEL(EL2)); + if HaveGTGExt() then { + match tgx { + TGx_4KB => { + return(__IMPDEF_boolean("Has Stage 2 4K Translation Granule")) + }, + TGx_16KB => { + return(__IMPDEF_boolean("Has Stage 2 16K Translation Granule")) + }, + TGx_64KB => { + return(__IMPDEF_boolean("Has Stage 2 64K Translation Granule")) + }, + _ => { + return(undefined : bool) + } + } + } else { + return(AArch64_HaveS1TG(tgx)) + } +} + +val AArch64_S2DecodeTG0 : bits(2) -> TGx + +function AArch64_S2DecodeTG0 tg0_in = { + tg0 : bits(2) = tg0_in; + tgx : TGx = undefined; + if tg0 == 0b11 then { + tg0 = __IMPDEF_bits(2, "TG0 encoded granule size") + }; + match tg0 { + 0b00 => { + tgx = TGx_4KB + }, + 0b01 => { + tgx = TGx_64KB + }, + 0b10 => { + tgx = TGx_16KB + }, + _ => () + }; + if not_bool(AArch64_HaveS2TG(tgx)) then { + match __IMPDEF_bits(2, "TG0 encoded granule size") { + 0b00 => { + tgx = TGx_4KB + }, + 0b01 => { + tgx = TGx_64KB + }, + 0b10 => { + tgx = TGx_16KB + }, + _ => () + } + }; + return(tgx) +} + +bitfield S2PIR_EL2_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register S2PIR_EL2 : S2PIR_EL2_Type + +val AArch64_NSS2TTWParams : forall ('s1aarch64 : Bool). + bool('s1aarch64) -> S2TTWParams + +function AArch64_NSS2TTWParams s1aarch64 = { + walkparams : S2TTWParams = undefined; + walkparams.vm = HCR_EL2[VM] | HCR_EL2[DC]; + walkparams.tgx = AArch64_S2DecodeTG0(VTCR_EL2[TG0]); + walkparams.txsz = VTCR_EL2[T0SZ]; + walkparams.ps = VTCR_EL2[PS]; + walkparams.irgn = VTCR_EL2[IRGN0]; + walkparams.orgn = VTCR_EL2[ORGN0]; + walkparams.sh = VTCR_EL2[SH0]; + walkparams.ee = SCTLR_EL2[EE]; + walkparams.d128 = if Have128BitDescriptorExt() then VTCR_EL2[D128] else 0b0; + if walkparams.d128 == 0b1 then { + walkparams.skl = VTTBR_EL2_read()[SKL] + } else { + walkparams.sl0 = VTCR_EL2[SL0] + }; + walkparams.ptw = if HCR_EL2[TGE] == 0b0 then HCR_EL2[PTW] else 0b0; + walkparams.fwb = if HaveStage2MemAttrControl() then HCR_EL2[FWB] else 0b0; + walkparams.ha = if HaveAccessFlagUpdateExt() then VTCR_EL2[HA] else 0b0; + walkparams.hd = if HaveDirtyBitModifierExt() then VTCR_EL2[HD] else 0b0; + if (walkparams.tgx == TGx_4KB | walkparams.tgx == TGx_16KB) & Have52BitIPAAndPASpaceExt() then { + walkparams.ds = VTCR_EL2[DS] + } else { + walkparams.ds = 0b0 + }; + if walkparams.tgx == TGx_4KB & Have52BitIPAAndPASpaceExt() then { + walkparams.sl2 = VTCR_EL2[SL2] & VTCR_EL2[DS] + } else { + walkparams.sl2 = 0b0 + }; + walkparams.cmow = if HaveFeatCMOW() & IsHCRXEL2Enabled() then HCRX_EL2[CMOW] + else + 0b0; + if walkparams.d128 == 0b1 then { + walkparams.s2pie = 0b1 + } else { + walkparams.s2pie = if HaveS2PIExt() then VTCR_EL2[S2PIE] else 0b0 + }; + walkparams.s2pir = if HaveS2PIExt() then Mk_S2PIRType(S2PIR_EL2.bits) else + Mk_S2PIRType(Zeros(64)); + if HaveTHExt() & walkparams.d128 != 0b1 then { + walkparams.assuredonly = VTCR_EL2[AssuredOnly] + } else { + walkparams.assuredonly = 0b0 + }; + walkparams.tl0 = if HaveTHExt() then VTCR_EL2[TL0] else 0b0; + walkparams.tl1 = if HaveTHExt() then VTCR_EL2[TL1] else 0b0; + if HaveAccessFlagUpdateForTableExt() & walkparams.ha == 0b1 then { + walkparams.haft = VTCR_EL2[HAFT] + } else { + walkparams.haft = 0b0 + }; + return(walkparams) +} + +val AArch64_RLS2TTWParams : forall ('s1aarch64 : Bool). + bool('s1aarch64) -> S2TTWParams + +function AArch64_RLS2TTWParams s1aarch64 = { + walkparams : S2TTWParams = AArch64_NSS2TTWParams(s1aarch64); + walkparams.emec = if HaveFeatMEC() & IsSCTLR2EL2Enabled() then + SCTLR2_EL2[EMEC] + else + 0b0; + return(walkparams) +} + +bitfield VSTCR_EL2_Type : bits(64) = + { + SL2 : 33..33, + SA : 30..30, + SW : 29..29, + TG0 : 15..14, + SL0 : 7..6, + T0SZ : 5..0 + } + +register VSTCR_EL2 : VSTCR_EL2_Type + +bitfield VSTTBR_EL2_Type : bits(64) = {SKL : 2..1, CnP : 0..0} + +register VSTTBR_EL2 : VSTTBR_EL2_Type + +val AArch64_SS2TTWParams : forall ('s1aarch64 : Bool). + (PASpace, bool('s1aarch64)) -> S2TTWParams + +function AArch64_SS2TTWParams (ipaspace, s1aarch64) = { + walkparams : S2TTWParams = undefined; + walkparams.d128 = if Have128BitDescriptorExt() then VTCR_EL2[D128] else 0b0; + if ipaspace == PAS_Secure then { + walkparams.tgx = AArch64_S2DecodeTG0(VSTCR_EL2[TG0]); + walkparams.txsz = VSTCR_EL2[T0SZ]; + if walkparams.d128 == 0b1 then { + walkparams.skl = VSTTBR_EL2[SKL] + } else { + walkparams.sl0 = VSTCR_EL2[SL0] + }; + if walkparams.tgx == TGx_4KB & Have52BitIPAAndPASpaceExt() then { + walkparams.sl2 = VSTCR_EL2[SL2] & VTCR_EL2[DS] + } else { + walkparams.sl2 = 0b0 + } + } else if ipaspace == PAS_NonSecure then { + walkparams.tgx = AArch64_S2DecodeTG0(VTCR_EL2[TG0]); + walkparams.txsz = VTCR_EL2[T0SZ]; + if walkparams.d128 == 0b1 then { + walkparams.skl = VTTBR_EL2_read()[SKL] + } else { + walkparams.sl0 = VTCR_EL2[SL0] + }; + if walkparams.tgx == TGx_4KB & Have52BitIPAAndPASpaceExt() then { + walkparams.sl2 = VTCR_EL2[SL2] & VTCR_EL2[DS] + } else { + walkparams.sl2 = 0b0 + } + } else { + Unreachable() + }; + walkparams.sw = VSTCR_EL2[SW]; + walkparams.nsw = VTCR_EL2[NSW]; + walkparams.sa = VSTCR_EL2[SA]; + walkparams.nsa = VTCR_EL2[NSA]; + walkparams.vm = HCR_EL2[VM] | HCR_EL2[DC]; + walkparams.ps = VTCR_EL2[PS]; + walkparams.irgn = VTCR_EL2[IRGN0]; + walkparams.orgn = VTCR_EL2[ORGN0]; + walkparams.sh = VTCR_EL2[SH0]; + walkparams.ee = SCTLR_EL2[EE]; + walkparams.ptw = if HCR_EL2[TGE] == 0b0 then HCR_EL2[PTW] else 0b0; + walkparams.fwb = if HaveStage2MemAttrControl() then HCR_EL2[FWB] else 0b0; + walkparams.ha = if HaveAccessFlagUpdateExt() then VTCR_EL2[HA] else 0b0; + walkparams.hd = if HaveDirtyBitModifierExt() then VTCR_EL2[HD] else 0b0; + if (walkparams.tgx == TGx_4KB | walkparams.tgx == TGx_16KB) & Have52BitIPAAndPASpaceExt() then { + walkparams.ds = VTCR_EL2[DS] + } else { + walkparams.ds = 0b0 + }; + walkparams.cmow = if HaveFeatCMOW() & IsHCRXEL2Enabled() then HCRX_EL2[CMOW] + else + 0b0; + if walkparams.d128 == 0b1 then { + walkparams.s2pie = 0b1 + } else { + walkparams.s2pie = if HaveS2PIExt() then VTCR_EL2[S2PIE] else 0b0 + }; + walkparams.s2pir = if HaveS2PIExt() then Mk_S2PIRType(S2PIR_EL2.bits) else + Mk_S2PIRType(Zeros(64)); + if HaveTHExt() & walkparams.d128 != 0b1 then { + walkparams.assuredonly = VTCR_EL2[AssuredOnly] + } else { + walkparams.assuredonly = 0b0 + }; + walkparams.tl0 = if HaveTHExt() then VTCR_EL2[TL0] else 0b0; + walkparams.tl1 = if HaveTHExt() then VTCR_EL2[TL1] else 0b0; + if HaveAccessFlagUpdateForTableExt() & walkparams.ha == 0b1 then { + walkparams.haft = VTCR_EL2[HAFT] + } else { + walkparams.haft = 0b0 + }; + walkparams.emec = 0b0; + return(walkparams) +} + +val AArch64_GetS2TTWParams : forall ('s1aarch64 : Bool). + (SecurityState, PASpace, bool('s1aarch64)) -> S2TTWParams + +function AArch64_GetS2TTWParams (ss, ipaspace, s1aarch64) = { + walkparams : S2TTWParams = undefined; + if ss == SS_NonSecure then { + walkparams = AArch64_NSS2TTWParams(s1aarch64) + } else if HaveSecureEL2Ext() & ss == SS_Secure then { + walkparams = AArch64_SS2TTWParams(ipaspace, s1aarch64) + } else if ss == SS_Realm then { + walkparams = AArch64_RLS2TTWParams(s1aarch64) + } else { + Unreachable() + }; + return(walkparams) +} + +val AArch64_IPAIsOutOfRange : (bits(56), S2TTWParams) -> bool + +function AArch64_IPAIsOutOfRange (ipa, walkparams) = { + let 'iasize = AArch64_IASize(walkparams.txsz); + if iasize < 56 then { + return(not_bool(is_zero_subrange(ipa, 55, iasize))) + } else { + return(false) + } +} + +val AArch64_S2DirectBasePermissions : (Permissions, AccessDescriptor) -> S2AccessControls + +function AArch64_S2DirectBasePermissions (permissions, accdesc) = { + s2perms : S2AccessControls = undefined; + let r : bits(1) = [permissions.s2ap[0]]; + let w : bits(1) = [permissions.s2ap[1]]; + px : bits(1) = undefined; + ux : bits(1) = undefined; + match permissions.s2xn @ permissions.s2xnx { + 0b00 => { + (px, ux) = (0b1, 0b1) + }, + 0b01 => { + (px, ux) = (0b0, 0b1) + }, + 0b10 => { + (px, ux) = (0b0, 0b0) + }, + 0b11 => { + (px, ux) = (0b1, 0b0) + } + }; + let x : bits(1) = if accdesc.el == EL0 then ux else px; + s2perms.r = r; + s2perms.w = w; + s2perms.x = x; + s2perms.r_rcw = r; + s2perms.w_rcw = w; + s2perms.r_mmu = r; + s2perms.w_mmu = w; + return(s2perms) +} + +val AArch64_S2IndirectBasePermissions : (Permissions, AccessDescriptor) -> S2AccessControls + +function AArch64_S2IndirectBasePermissions (permissions, accdesc) = { + r : bits(1) = undefined; + w : bits(1) = undefined; + r_rcw : bits(1) = undefined; + w_rcw : bits(1) = undefined; + r_mmu : bits(1) = undefined; + w_mmu : bits(1) = undefined; + px : bits(1) = undefined; + ux : bits(1) = undefined; + toplevel0 : bits(1) = undefined; + toplevel1 : bits(1) = undefined; + s2perms : S2AccessControls = undefined; + let s2pi : bits(4) = permissions.s2pi; + match s2pi { + 0b0000 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b0001 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b0010 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b0011 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b0100 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b1, 0b0, 0b0, 0b0, 0b0) + }, + 0b0101 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b0110 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b0111 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b1000 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b1001 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b1, 0b0, 0b0) + }, + 0b1010 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b1, 0b0, 0b0, 0b0) + }, + 0b1011 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b1, 0b1, 0b0, 0b0) + }, + 0b1100 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b0, 0b0, 0b1, 0b1) + }, + 0b1101 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b0, 0b1, 0b1, 0b1) + }, + 0b1110 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b1, 0b0, 0b1, 0b1) + }, + 0b1111 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b1, 0b1, 0b1, 0b1) + } + }; + let x : bits(1) = if accdesc.el == EL0 then ux else px; + (r_rcw, r_mmu) = (r, r); + match s2pi { + 0b0110 => { + (toplevel0, toplevel1) = (0b1, 0b0) + }, + 0b0011 => { + (toplevel0, toplevel1) = (0b0, 0b1) + }, + 0b0111 => { + (toplevel0, toplevel1) = (0b1, 0b1) + }, + _ => { + (toplevel0, toplevel1) = (0b0, 0b0) + } + }; + s2perms.r = r; + s2perms.w = w; + s2perms.x = x; + s2perms.r_rcw = r_rcw; + s2perms.r_mmu = r_mmu; + s2perms.w_rcw = w_rcw; + s2perms.w_mmu = w_mmu; + s2perms.toplevel0 = toplevel0; + s2perms.toplevel1 = toplevel1; + return(s2perms) +} + +bitfield S2POR_EL1_Type : bits(64) = + { + Perm15 : 63..60, + Perm14 : 59..56, + Perm13 : 55..52, + Perm12 : 51..48, + Perm11 : 47..44, + Perm10 : 43..40, + Perm9 : 39..36, + Perm8 : 35..32, + Perm7 : 31..28, + Perm6 : 27..24, + Perm5 : 23..20, + Perm4 : 19..16, + Perm3 : 15..12, + Perm2 : 11..8, + Perm1 : 7..4, + Perm0 : 3..0 + } + +register S2POR_EL1 : S2POR_EL1_Type + +val AArch64_S2OverlayPermissions : (Permissions, AccessDescriptor) -> S2AccessControls + +function AArch64_S2OverlayPermissions (permissions, accdesc) = { + r : bits(1) = undefined; + w : bits(1) = undefined; + r_rcw : bits(1) = undefined; + w_rcw : bits(1) = undefined; + r_mmu : bits(1) = undefined; + w_mmu : bits(1) = undefined; + px : bits(1) = undefined; + ux : bits(1) = undefined; + toplevel0 : bits(1) = undefined; + toplevel1 : bits(1) = undefined; + s2overlay_perms : S2AccessControls = undefined; + let 'index = 4 * UInt(permissions.s2po_index); + let s2po : bits(4) = S2POR_EL1.bits[index + 3 .. index]; + match s2po { + 0b0000 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b0001 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b0010 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b0011 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b0100 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b1, 0b0, 0b0, 0b0, 0b0) + }, + 0b0101 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b0, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b0110 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b0111 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b1, 0b1) + }, + 0b1000 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b0, 0b0, 0b0) + }, + 0b1001 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b0, 0b1, 0b0, 0b0) + }, + 0b1010 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b1, 0b0, 0b0, 0b0) + }, + 0b1011 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b0, 0b1, 0b1, 0b0, 0b0) + }, + 0b1100 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b0, 0b0, 0b1, 0b1) + }, + 0b1101 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b0, 0b1, 0b1, 0b1) + }, + 0b1110 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b1, 0b0, 0b1, 0b1) + }, + 0b1111 => { + (r, w, px, ux, w_rcw, w_mmu) = (0b1, 0b1, 0b1, 0b1, 0b1, 0b1) + } + }; + let x : bits(1) = if accdesc.el == EL0 then ux else px; + (r_rcw, r_mmu) = (r, r); + match s2po { + 0b0110 => { + (toplevel0, toplevel1) = (0b1, 0b0) + }, + 0b0011 => { + (toplevel0, toplevel1) = (0b0, 0b1) + }, + 0b0111 => { + (toplevel0, toplevel1) = (0b1, 0b1) + }, + _ => { + (toplevel0, toplevel1) = (0b0, 0b0) + } + }; + s2overlay_perms.or = r; + s2overlay_perms.ow = w; + s2overlay_perms.ox = x; + s2overlay_perms.or_rcw = r_rcw; + s2overlay_perms.ow_rcw = w_rcw; + s2overlay_perms.or_mmu = r_mmu; + s2overlay_perms.ow_mmu = w_mmu; + s2overlay_perms.toplevel0 = toplevel0; + s2overlay_perms.toplevel1 = toplevel1; + return(s2overlay_perms) +} + +val AArch64_S2ComputePermissions : (Permissions, S2TTWParams, AccessDescriptor) -> S2AccessControls + +function AArch64_S2ComputePermissions (permissions, walkparams, accdesc) = { + s2overlay_perms : S2AccessControls = undefined; + s2perms : S2AccessControls = undefined; + if walkparams.s2pie == 0b1 then { + s2perms = AArch64_S2IndirectBasePermissions(permissions, accdesc); + s2perms.overlay = HaveS2POExt() & VTCR_EL2[S2POE] == 0b1; + if s2perms.overlay then { + let s2overlay_perms : S2AccessControls = AArch64_S2OverlayPermissions(permissions, accdesc); + s2perms.or = s2overlay_perms.or; + s2perms.ow = s2overlay_perms.ow; + s2perms.ox = s2overlay_perms.ox; + s2perms.or_rcw = s2overlay_perms.or_rcw; + s2perms.ow_rcw = s2overlay_perms.ow_rcw; + s2perms.or_mmu = s2overlay_perms.or_mmu; + s2perms.ow_mmu = s2overlay_perms.ow_mmu; + if ((s2perms.w @ (s2perms.w_rcw @ s2perms.w_mmu)) & (s2perms.ow @ (s2perms.ow_rcw @ s2perms.ow_mmu))) == 0b011 then { + s2perms.toplevel0 = s2perms.toplevel0 | s2overlay_perms.toplevel0; + s2perms.toplevel1 = s2perms.toplevel1 | s2overlay_perms.toplevel1 + } else { + s2perms.toplevel0 = 0b0; + s2perms.toplevel1 = 0b0 + } + }; + () + } else { + s2perms = AArch64_S2DirectBasePermissions(permissions, accdesc) + }; + return(s2perms) +} + +val AArch64_S2CheckPermissions : (FaultRecord, TTWState, S2TTWParams, AddressDescriptor, AccessDescriptor) -> (FaultRecord, bool) + +function AArch64_S2CheckPermissions (fault_in, walkstate, walkparams, ipa, accdesc) = { + let memtype : MemType = walkstate.memattrs.memtype; + let permissions : Permissions = walkstate.permissions; + fault : FaultRecord = fault_in; + let s2perms : S2AccessControls = AArch64_S2ComputePermissions(permissions, walkparams, accdesc); + r : bits(1) = undefined; + w : bits(1) = undefined; + or : bits(1) = undefined; + ow : bits(1) = undefined; + if accdesc.acctype == AccessType_TTW then { + r = s2perms.r_mmu; + w = s2perms.w_mmu; + or = s2perms.or_mmu; + ow = s2perms.ow_mmu + } else if accdesc.rcw then { + r = s2perms.r_rcw; + w = s2perms.w_rcw; + or = s2perms.or_rcw; + ow = s2perms.ow_rcw + } else { + r = s2perms.r; + w = s2perms.w; + or = s2perms.or; + ow = s2perms.ow + }; + if accdesc.acctype == AccessType_TTW then { + if (accdesc.toplevel & accdesc.varange == VARange_LOWER) & (walkparams.tl0 == 0b1 & s2perms.toplevel0 == 0b0 | walkparams.tl1 == 0b1 & (s2perms.toplevel1 @ s2perms.toplevel0) == 0b10) then { + fault.statuscode = Fault_Permission; + fault.toplevel = true + } else if (accdesc.toplevel & accdesc.varange == VARange_UPPER) & (walkparams.tl1 == 0b1 & s2perms.toplevel1 == 0b0 | walkparams.tl0 == 0b1 & (s2perms.toplevel1 @ s2perms.toplevel0) == 0b01) then { + fault.statuscode = Fault_Permission; + fault.toplevel = true + } else if walkparams.ptw == 0b1 & memtype == MemType_Device then { + fault.statuscode = Fault_Permission + } else if s2perms.overlay & or == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if (accdesc.write & s2perms.overlay) & ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if accdesc.ss == SS_Realm & walkstate.baseaddress.paspace != PAS_Realm then { + fault.statuscode = Fault_Permission + } else if r == 0b0 then { + fault.statuscode = Fault_Permission + } else if accdesc.write & w == 0b0 then { + fault.statuscode = Fault_Permission + } else if ((accdesc.write & not_bool((walkparams.ha @ walkparams.hd) == 0b11)) & walkparams.s2pie == 0b1) & permissions.s2dirty == 0b0 then { + fault.statuscode = Fault_Permission; + fault.dirtybit = true + } else () + } else if walkstate.s2assuredonly == 0b1 & not_bool(ipa.s1assured) | (((walkstate.s2assuredonly != 0b1 & HaveGCS()) & VTCR_EL2[GCSH] == 0b1) & accdesc.acctype == AccessType_GCS) & accdesc.el != EL0 then { + fault.statuscode = Fault_Permission; + fault.assuredonly = true + } else if accdesc.acctype == AccessType_IFETCH then { + if s2perms.overlay & s2perms.ox == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if memtype == MemType_Device & ConstrainUnpredictable(Unpredictable_INSTRDEVICE) == Constraint_FAULT then { + fault.statuscode = Fault_Permission + } else if accdesc.ss == SS_Realm & walkstate.baseaddress.paspace != PAS_Realm then { + fault.statuscode = Fault_Permission + } else if s2perms.x == 0b0 then { + fault.statuscode = Fault_Permission + } else () + } else if accdesc.acctype == AccessType_DC then { + if accdesc.cacheop == CacheOp_Invalidate then { + if (not_bool(ELUsingAArch32(EL1)) & s2perms.overlay) & ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + }; + if not_bool(ELUsingAArch32(EL1)) & w == 0b0 then { + fault.statuscode = Fault_Permission + }; + () + } else if ((not_bool(ELUsingAArch32(EL1)) & accdesc.el == EL0) & s2perms.overlay) & or == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if (((walkparams.cmow == 0b1 & accdesc.opscope == CacheOpScope_PoC) & accdesc.cacheop == CacheOp_CleanInvalidate) & s2perms.overlay) & ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if (not_bool(ELUsingAArch32(EL1)) & accdesc.el == EL0) & r == 0b0 then { + fault.statuscode = Fault_Permission + } else if ((walkparams.cmow == 0b1 & accdesc.opscope == CacheOpScope_PoC) & accdesc.cacheop == CacheOp_CleanInvalidate) & w == 0b0 then { + fault.statuscode = Fault_Permission + } else () + } else if accdesc.acctype == AccessType_IC then { + if (((not_bool(ELUsingAArch32(EL1)) & accdesc.el == EL0) & s2perms.overlay) & or == 0b0) & __IMPDEF_boolean("Permission fault on EL0 IC_IVAU execution") then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if (walkparams.cmow == 0b1 & s2perms.overlay) & ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true + } else if ((not_bool(ELUsingAArch32(EL1)) & accdesc.el == EL0) & r == 0b0) & __IMPDEF_boolean("Permission fault on EL0 IC_IVAU execution") then { + fault.statuscode = Fault_Permission + } else if walkparams.cmow == 0b1 & w == 0b0 then { + fault.statuscode = Fault_Permission + } else () + } else if (accdesc.read & s2perms.overlay) & or == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true; + fault.write = false + } else if (accdesc.write & s2perms.overlay) & ow == 0b0 then { + fault.statuscode = Fault_Permission; + fault.overlay = true; + fault.write = true + } else if accdesc.read & r == 0b0 then { + fault.statuscode = Fault_Permission; + fault.write = false + } else if accdesc.write & w == 0b0 then { + fault.statuscode = Fault_Permission; + fault.write = true + } else if ((accdesc.tagaccess | accdesc.tagchecked) & ipa.memattrs.tags == MemTag_AllocationTagged) & permissions.s2tag_na == 0b1 then { + fault.statuscode = Fault_Permission; + fault.tagaccess = true; + fault.write = accdesc.tagaccess & accdesc.write + } else if ((accdesc.write & not_bool((walkparams.ha @ walkparams.hd) == 0b11)) & walkparams.s2pie == 0b1) & permissions.s2dirty == 0b0 then { + fault.statuscode = Fault_Permission; + fault.dirtybit = true; + fault.write = true + } else (); + mro : bool = undefined; + if s2perms.overlay then { + mro = ((s2perms.w @ (s2perms.w_rcw @ s2perms.w_mmu)) & (s2perms.ow @ (s2perms.ow_rcw @ s2perms.ow_mmu))) == 0b011 + } else { + mro = (s2perms.w @ (s2perms.w_rcw @ s2perms.w_mmu)) == 0b011 + }; + return((fault, mro)) +} + +val AArch64_S2HasAlignmentFault : forall ('aligned : Bool). + (AccessDescriptor, bool('aligned), MemoryAttributes) -> bool + +function AArch64_S2HasAlignmentFault (accdesc, aligned, memattrs) = { + if accdesc.acctype == AccessType_IFETCH then { + return(false) + } else if (HaveMTEExt() & accdesc.tagaccess) & accdesc.write then { + return(memattrs.memtype == MemType_Device & ConstrainUnpredictable(Unpredictable_DEVICETAGSTORE) == Constraint_FAULT) + } else if accdesc.acctype == AccessType_DCZero then { + return(memattrs.memtype == MemType_Device) + } else { + return(memattrs.memtype == MemType_Device & not_bool(aligned)) + } +} + +val AArch64_S2StartLevel : S2TTWParams -> int + +function AArch64_S2StartLevel walkparams = { + descsizelog2 : int = undefined; + granulebits : int = undefined; + iasize : int = undefined; + s2startlevel : int = undefined; + stride : int = undefined; + if walkparams.d128 == 0b1 then { + let 'iasize = AArch64_IASize(walkparams.txsz); + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'descsizelog2 = 4; + let 'stride = granulebits - descsizelog2; + s2startlevel : int = FINAL_LEVEL - DIV(iasize - 1 - granulebits, stride); + let 's2startlevel = s2startlevel + UInt(walkparams.skl); + return(s2startlevel) + }; + match walkparams.tgx { + TGx_4KB => { + match walkparams.sl2 @ walkparams.sl0 { + 0b000 => { + return(2) + }, + 0b001 => { + return(1) + }, + 0b010 => { + return(0) + }, + 0b011 => { + return(3) + }, + 0b100 => { + return(negate(1)) + }, + _ => { + return(undefined : int) + } + } + }, + TGx_16KB => { + match walkparams.sl0 { + 0b00 => { + return(3) + }, + 0b01 => { + return(2) + }, + 0b10 => { + return(1) + }, + 0b11 => { + return(0) + }, + _ => { + return(undefined : int) + } + } + }, + TGx_64KB => { + match walkparams.sl0 { + 0b00 => { + return(3) + }, + 0b01 => { + return(2) + }, + 0b10 => { + return(1) + }, + _ => { + return(undefined : int) + } + } + }, + _ => { + return(undefined : int) + } + } +} + +val AArch64_S2InconsistentSL : S2TTWParams -> bool + +function AArch64_S2InconsistentSL walkparams = { + let 'startlevel = AArch64_S2StartLevel(walkparams); + let 'levels = FINAL_LEVEL - startlevel; + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'descsizelog2 = 3; + let 'stride = granulebits - descsizelog2; + let 'sl_min_iasize = levels * stride + granulebits + 1; + let 'sl_max_iasize = sl_min_iasize + (stride - 1) + 4; + let 'iasize = AArch64_IASize(walkparams.txsz); + return(iasize < sl_min_iasize | iasize > sl_max_iasize) +} + +val AArch64_S2InvalidSL : S2TTWParams -> bool + +function AArch64_S2InvalidSL walkparams = { + match walkparams.tgx { + TGx_4KB => { + match walkparams.sl2 @ walkparams.sl0 { + [bitone, _, bitone] => { + return(true) + }, + [bitone, bitone, _] => { + return(true) + }, + 0b010 => { + return(AArch64_PAMax() < 44) + }, + 0b011 => { + return(not_bool(HaveSmallTranslationTableExt())) + }, + _ => { + return(false) + } + } + }, + TGx_16KB => { + match walkparams.sl0 { + 0b11 => { + return(walkparams.ds == 0b0) + }, + 0b10 => { + return(AArch64_PAMax() < 42) + }, + _ => { + return(false) + } + } + }, + TGx_64KB => { + match walkparams.sl0 { + 0b11 => { + return(true) + }, + 0b10 => { + return(AArch64_PAMax() < 44) + }, + _ => { + return(false) + } + } + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch64_S2MinTxSZ : forall ('s1aarch64 : Bool). + (bits(1), bits(1), TGx, bool('s1aarch64)) -> int + +function AArch64_S2MinTxSZ (d128, ds, tgx, s1aarch64) = { + ips : int = AArch64_PAMax(); + if d128 == 0b0 then { + if (Have52BitPAExt() & tgx != TGx_64KB) & ds == 0b0 then { + ips = Min(48, AArch64_PAMax()) + } else { + ips = Min(52, AArch64_PAMax()) + } + }; + let 'ips = ips; + min_txsz : int = 64 - ips; + if not_bool(s1aarch64) then { + min_txsz = Min(min_txsz, 24) + }; + let 'min_txsz = min_txsz; + return(min_txsz) +} + +bitfield VMECID_A_EL2_Type : bits(64) = {MECID : 15..0} + +register VMECID_A_EL2 : VMECID_A_EL2_Type + +val AArch64_S2OutputMECID : forall 'N, 'N in {64, 128}. + (S2TTWParams, PASpace, bits('N)) -> bits(16) + +function AArch64_S2OutputMECID (walkparams, paspace, descriptor) = { + assert('N == 64 | 'N == 128); + if walkparams.emec == 0b0 then { + return(DEFAULT_MECID) + }; + if paspace != PAS_Realm then { + return(DEFAULT_MECID) + }; + let descriptor_amec : bits(1) = if walkparams.d128 == 0b1 then { + assert(constraint(103 < 'N)); + [descriptor[103]] + } else [descriptor[63]]; + if descriptor_amec == 0b0 then { + return(VMECID_P_EL2[MECID]) + } else { + return(VMECID_A_EL2[MECID]) + } +} + +val AArch64_S2TxSZFaults : forall ('s1aarch64 : Bool). + (S2TTWParams, bool('s1aarch64)) -> bool + +function AArch64_S2TxSZFaults (walkparams, s1aarch64) = { + let 'mintxsz = AArch64_S2MinTxSZ(walkparams.d128, walkparams.ds, walkparams.tgx, s1aarch64); + let 'maxtxsz = AArch64_MaxTxSZ(walkparams.tgx); + if UInt(walkparams.txsz) < mintxsz then { + return(Have52BitPAExt() | __IMPDEF_boolean("Fault on TxSZ value below minimum")) + }; + if UInt(walkparams.txsz) > maxtxsz then { + return(__IMPDEF_boolean("Fault on TxSZ value above maximum")) + }; + return(false) +} + +val AArch64_GetS2TLBContext : (SecurityState, FullAddress, TGx) -> TLBContext + +function AArch64_GetS2TLBContext (ss, ipa, tg) = { + assert(EL2Enabled()); + tlbcontext : TLBContext = undefined; + tlbcontext.ss = ss; + tlbcontext.regime = Regime_EL10; + tlbcontext.ipaspace = ipa.paspace; + tlbcontext.vmid = VMID_read(); + tlbcontext.tg = tg; + tlbcontext.ia = ZeroExtend(ipa.address, 64); + if HaveCommonNotPrivateTransExt() then { + tlbcontext.cnp = if ipa.paspace == PAS_Secure then VSTTBR_EL2[CnP] else + VTTBR_EL2_read()[CnP] + } else { + tlbcontext.cnp = 0b0 + }; + tlbcontext.includes_s1_name = false; + tlbcontext.includes_s2_name = true; + tlbcontext.includes_gpt_name = false; + return(tlbcontext) +} + +val AArch64_S2ApplyFWBMemAttrs : forall 'N, 11 < 'N. + (MemoryAttributes, S2TTWParams, bits('N)) -> MemoryAttributes + +function AArch64_S2ApplyFWBMemAttrs (s1_memattrs, walkparams, descriptor) = { + s2_device : DeviceType = undefined; + memattrs : MemoryAttributes = undefined; + let s2_attr : bits(4) = descriptor[5 .. 2]; + let s2_sh : bits(2) = if walkparams.ds == 0b1 then walkparams.sh else { + assert(constraint(9 < 'N)); + descriptor[9 .. 8] + }; + let s2_fnxs : bits(1) = [descriptor[11]]; + if [s2_attr[2]] == 0b0 then { + let s2_device : DeviceType = DecodeDevice(s2_attr[1 .. 0]); + memattrs.memtype = MemType_Device; + if s1_memattrs.memtype == MemType_Device then { + memattrs.device = S2CombineS1Device(s1_memattrs.device, s2_device) + } else { + memattrs.device = s2_device + }; + memattrs.xs = s1_memattrs.xs + } else if s2_attr[1 .. 0] == 0b11 then { + memattrs = s1_memattrs + } else if s2_attr[1 .. 0] == 0b10 then { + memattrs.memtype = MemType_Normal; + memattrs.inner.attrs = MemAttr_WB; + memattrs.outer.attrs = MemAttr_WB; + if s1_memattrs.memtype == MemType_Normal & s1_memattrs.inner.attrs != MemAttr_NC then { + memattrs.inner.hints = s1_memattrs.inner.hints; + memattrs.inner.transient = s1_memattrs.inner.transient + } else { + memattrs.inner.hints = MemHint_RWA; + memattrs.inner.transient = false + }; + if s1_memattrs.memtype == MemType_Normal & s1_memattrs.outer.attrs != MemAttr_NC then { + memattrs.outer.hints = s1_memattrs.outer.hints; + memattrs.outer.transient = s1_memattrs.outer.transient + } else { + memattrs.outer.hints = MemHint_RWA; + memattrs.outer.transient = false + }; + memattrs.xs = 0b0 + } else { + if s1_memattrs.memtype == MemType_Device then { + memattrs = s1_memattrs + } else { + cacheability_attr : MemAttrHints = undefined; + cacheability_attr.attrs = MemAttr_NC; + memattrs.memtype = MemType_Normal; + memattrs.inner = cacheability_attr; + memattrs.outer = cacheability_attr; + memattrs.xs = s1_memattrs.xs + } + }; + let s2_shareability : Shareability = DecodeShareability(s2_sh); + memattrs.shareability = S2CombineS1Shareability(s1_memattrs.shareability, s2_shareability); + memattrs.tags = S2MemTagType(memattrs, s1_memattrs.tags); + memattrs.notagaccess = s2_attr[3 .. 1] == 0b111 & memattrs.tags == MemTag_AllocationTagged; + if s2_fnxs == 0b1 then { + memattrs.xs = 0b0 + }; + memattrs.shareability = EffectiveShareability(memattrs); + return(memattrs) +} + +val AArch64_S2TTBaseAddress : forall 'N, 'N >= 0. + (S2TTWParams, PASpace, bits('N)) -> bits(56) + +function AArch64_S2TTBaseAddress (walkparams, paspace, ttbr) = { + tablebase : bits(56) = Zeros(56); + let 'iasize = AArch64_IASize(walkparams.txsz); + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'descsizelog2 = if walkparams.d128 == 0b1 then 4 else 3; + let 'stride = granulebits - descsizelog2; + let 'startlevel = AArch64_S2StartLevel(walkparams); + let 'levels = FINAL_LEVEL - startlevel; + tsize : int = iasize - (levels * stride + granulebits) + descsizelog2; + if Have56BitPAExt() & walkparams.d128 == 0b1 then { + tsize = Max(tsize, 5); + if paspace == PAS_Secure then { + assert(constraint(55 < 'N)); + tablebase[55 .. 5] = ttbr[55 .. 5] + } else { + assert(constraint(87 < 'N)); + tablebase[55 .. 5] = ttbr[87 .. 80] @ ttbr[47 .. 5] + } + } else if (Have52BitPAExt() & walkparams.tgx == TGx_64KB) & walkparams.ps == 0b110 | walkparams.ds == 0b1 then { + tsize = Max(tsize, 6); + assert(constraint(5 < 'N)); + assert(constraint(47 < 'N)); + tablebase[51 .. 6] = ttbr[5 .. 2] @ ttbr[47 .. 6] + } else { + assert(constraint(47 < 'N)); + tablebase[47 .. 1] = ttbr[47 .. 1] + }; + let 'tsize = tsize; + let tablebase : bits(56) = Align(tablebase, (1 << tsize)); + return(tablebase) +} + +val AArch64_S2InitialTTWState : (SecurityState, S2TTWParams) -> TTWState + +function AArch64_S2InitialTTWState (ss, walkparams) = { + walkstate : TTWState = undefined; + tablebase : FullAddress = undefined; + let ttbr : bits(128) = ZeroExtend(VTTBR_EL2_read().bits, 128); + match ss { + SS_NonSecure => { + tablebase.paspace = PAS_NonSecure + }, + SS_Realm => { + tablebase.paspace = PAS_Realm + }, + _ => () + }; + tablebase.address = AArch64_S2TTBaseAddress(walkparams, tablebase.paspace, ttbr); + walkstate.baseaddress = tablebase; + walkstate.level = AArch64_S2StartLevel(walkparams); + walkstate.istable = true; + walkstate.memattrs = WalkMemAttrs(walkparams.sh, walkparams.irgn, walkparams.orgn); + return(walkstate) +} + +val AArch64_S2ApplyOutputPerms : forall 'N, 'N >= 0. + (bits('N), S2TTWParams) -> Permissions + +function AArch64_S2ApplyOutputPerms (descriptor, walkparams) = { + bit_index : int = undefined; + permissions : Permissions = undefined; + s2pi_index : bits(4) = undefined; + if walkparams.s2pie == 0b1 then { + if walkparams.d128 == 0b1 then { + assert(constraint(118 < 'N)); + s2pi_index = descriptor[118 .. 115] + } else { + assert(constraint(54 < 'N)); + s2pi_index = descriptor[54 .. 53] @ ([descriptor[51]] @ [descriptor[6]]) + }; + let 'bit_index = 4 * UInt(s2pi_index); + permissions.s2pi = walkparams.s2pir.bits[bit_index + 3 .. bit_index]; + assert(constraint(7 < 'N)); + permissions.s2dirty = [descriptor[7]] + } else { + assert(constraint(7 < 'N)); + permissions.s2ap = descriptor[7 .. 6]; + if walkparams.d128 == 0b1 then { + assert(constraint(118 < 'N)); + permissions.s2xn = [descriptor[118]] + } else { + assert(constraint(54 < 'N)); + permissions.s2xn = [descriptor[54]] + }; + if HaveExtendedExecuteNeverExt() then { + if walkparams.d128 == 0b1 then { + assert(constraint(117 < 'N)); + permissions.s2xnx = [descriptor[117]] + } else { + assert(constraint(53 < 'N)); + permissions.s2xnx = [descriptor[53]] + } + } else { + permissions.s2xnx = 0b0 + }; + desc_dbm : bits(1) = undefined; + if walkparams.d128 == 0b1 then { + assert(constraint(115 < 'N)); + desc_dbm = [descriptor[115]] + } else { + assert(constraint(51 < 'N)); + desc_dbm = [descriptor[51]] + }; + if (walkparams.ha == 0b1 & walkparams.hd == 0b1) & desc_dbm == 0b1 then { + permissions.s2ap[1] = Bit(0b1) + }; + () + }; + if (walkparams.s2pie == 0b1 & HaveS2POExt()) & VTCR_EL2[S2POE] == 0b1 then { + if walkparams.d128 == 0b1 then { + assert(constraint(124 < 'N)); + permissions.s2po_index = descriptor[124 .. 121] + } else { + assert(constraint(62 < 'N)); + permissions.s2po_index = descriptor[62 .. 59] + } + }; + return(permissions) +} + +val AArch64_SS2OutputPASpace : (S2TTWParams, PASpace) -> PASpace + +function AArch64_SS2OutputPASpace (walkparams, ipaspace) = { + if ipaspace == PAS_Secure then { + if (walkparams.sw @ walkparams.sa) == 0b00 then { + return(PAS_Secure) + } else { + return(PAS_NonSecure) + } + } else { + if (walkparams.sw @ (walkparams.sa @ (walkparams.nsw @ walkparams.nsa))) == 0b0000 then { + return(PAS_Secure) + } else { + return(PAS_NonSecure) + } + } +} + +val AArch64_S2NextWalkStateLeaf : forall 'N, 52 < 'N. + (TTWState, SecurityState, S2TTWParams, AddressDescriptor, bits('N)) -> TTWState + +function AArch64_S2NextWalkStateLeaf (currentstate, ss, walkparams, ipa, descriptor) = { + s2aarch64 : bool = undefined; + nextstate : TTWState = undefined; + baseaddress : FullAddress = undefined; + if ss == SS_Secure then { + baseaddress.paspace = AArch64_SS2OutputPASpace(walkparams, ipa.paddress.paspace) + } else if ss == SS_Realm then { + let ns : bits(1) = if walkparams.d128 == 0b1 then { + assert(constraint(127 < 'N)); + [descriptor[127]] + } else { + assert(constraint(55 < 'N)); + [descriptor[55]] + }; + baseaddress.paspace = if ns == 0b1 then PAS_NonSecure else PAS_Realm + } else { + baseaddress.paspace = PAS_NonSecure + }; + baseaddress.address = AArch64_LeafBase(descriptor, walkparams.d128, walkparams.ds, walkparams.tgx, currentstate.level); + nextstate.istable = false; + nextstate.level = currentstate.level; + nextstate.baseaddress = baseaddress; + nextstate.permissions = AArch64_S2ApplyOutputPerms(descriptor, walkparams); + let s2_attr : bits(4) = descriptor[5 .. 2]; + let s2_sh : bits(2) = if walkparams.ds == 0b1 then walkparams.sh else { + assert(constraint(9 < 'N)); + descriptor[9 .. 8] + }; + let s2_fnxs : bits(1) = [descriptor[11]]; + if walkparams.fwb == 0b1 then { + nextstate.memattrs = AArch64_S2ApplyFWBMemAttrs(ipa.memattrs, walkparams, descriptor); + if s2_attr[3 .. 1] == 0b111 then { + nextstate.permissions.s2tag_na = 0b1 + } else { + nextstate.permissions.s2tag_na = 0b0 + } + } else { + let s2aarch64 : bool = true; + nextstate.memattrs = S2DecodeMemAttrs(s2_attr, s2_sh, s2aarch64); + nextstate.memattrs.xs = not_vec(s2_fnxs); + if s2_attr == 0b0100 then { + nextstate.permissions.s2tag_na = 0b1 + } else { + nextstate.permissions.s2tag_na = 0b0 + } + }; + nextstate.contiguous = AArch64_ContiguousBit(walkparams.tgx, walkparams.d128, currentstate.level, descriptor); + if walkparams.d128 == 0b1 then { + assert(constraint(114 < 'N)); + nextstate.s2assuredonly = [descriptor[114]] + } else { + nextstate.s2assuredonly = if walkparams.assuredonly == 0b1 then { + assert(constraint(58 < 'N)); + [descriptor[58]] + } else 0b0 + }; + return(nextstate) +} + +val AArch64_S2NextWalkStateTable : forall 'N, 'N >= 0. + (TTWState, S2TTWParams, bits('N)) -> TTWState + +function AArch64_S2NextWalkStateTable (currentstate, walkparams, descriptor) = { + skl : bits(2) = undefined; + nextstate : TTWState = undefined; + tablebase : FullAddress = undefined; + tablebase.address = AArch64_NextTableBase(descriptor, walkparams.d128, walkparams.ds, walkparams.tgx); + tablebase.paspace = currentstate.baseaddress.paspace; + nextstate.istable = true; + if walkparams.d128 == 0b1 then { + assert(constraint(110 < 'N)); + let skl : bits(2) = descriptor[110 .. 109]; + nextstate.level = currentstate.level + UInt(skl) + 1 + } else { + nextstate.level = currentstate.level + 1 + }; + nextstate.baseaddress = tablebase; + nextstate.memattrs = currentstate.memattrs; + return(nextstate) +} + +val AArch64_S2SLTTEntryAddress : (S2TTWParams, bits(56), FullAddress) -> FullAddress + +function AArch64_S2SLTTEntryAddress (walkparams, ipa, tablebase) = { + let 'startlevel = AArch64_S2StartLevel(walkparams); + let 'iasize = AArch64_IASize(walkparams.txsz); + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'descsizelog2 = if walkparams.d128 == 0b1 then 4 else 3; + let 'stride = granulebits - descsizelog2; + let 'levels = FINAL_LEVEL - startlevel; + let 'lsb = levels * stride + granulebits; + let 'msb = iasize - 1; + assert(constraint((0 <= 'lsb & 'lsb <= 'msb & 'msb < 56))); + assert(constraint(56 >= 'msb - 'lsb + 1 + 'descsizelog2)); + let index : bits(56) = ZeroExtend(ipa[msb .. lsb] @ Zeros(descsizelog2), 56); + descaddress : FullAddress = undefined; + descaddress.address = tablebase.address | index; + descaddress.paspace = tablebase.paspace; + return(descaddress) +} + +val AArch64_SS2InitialTTWState : (S2TTWParams, PASpace) -> TTWState + +function AArch64_SS2InitialTTWState (walkparams, ipaspace) = { + walkstate : TTWState = undefined; + tablebase : FullAddress = undefined; + ttbr : bits(128) = undefined; + if ipaspace == PAS_Secure then { + ttbr = ZeroExtend(VSTTBR_EL2.bits, 128) + } else { + ttbr = ZeroExtend(VTTBR_EL2_read().bits, 128) + }; + if ipaspace == PAS_Secure then { + if walkparams.sw == 0b0 then { + tablebase.paspace = PAS_Secure + } else { + tablebase.paspace = PAS_NonSecure + } + } else { + if walkparams.nsw == 0b0 then { + tablebase.paspace = PAS_Secure + } else { + tablebase.paspace = PAS_NonSecure + } + }; + tablebase.address = AArch64_S2TTBaseAddress(walkparams, tablebase.paspace, ttbr); + walkstate.baseaddress = tablebase; + walkstate.level = AArch64_S2StartLevel(walkparams); + walkstate.istable = true; + walkstate.memattrs = WalkMemAttrs(walkparams.sh, walkparams.irgn, walkparams.orgn); + return(walkstate) +} + +val AArch64_TTEntryAddress : forall 'level. + (int('level), bits(1), bits(2), TGx, bits(6), bits(64), FullAddress) -> FullAddress + +function AArch64_TTEntryAddress (level, d128, skl, tgx, txsz, ia, tablebase) = { + let 'iasize = AArch64_IASize(txsz); + let 'granulebits = TGxGranuleBits(tgx); + let 'descsizelog2 = if d128 == 0b1 then 4 else 3; + let 'stride = granulebits - descsizelog2; + let 'levels = FINAL_LEVEL - level; + msb : int = undefined; + let 'lsb = levels * stride + granulebits; + if d128 == 0b1 then { + msb = lsb + stride * (1 + UInt(skl)) - 1 + } else { + msb = lsb + stride - 1 + }; + let 'msb = msb; + assert(constraint((0 <= 'lsb & 'lsb <= 'msb & 'msb < 64))); + assert(constraint(56 >= 'msb - 'lsb + 1 + 'descsizelog2)); + let index : bits(56) = ZeroExtend(ia[msb .. lsb] @ Zeros(descsizelog2), 56); + descaddress : FullAddress = undefined; + descaddress.address = tablebase.address | index; + descaddress.paspace = tablebase.paspace; + return(descaddress) +} + +val AArch64_TTWalkMECID : (bits(1), Regime, SecurityState) -> bits(16) + +function AArch64_TTWalkMECID (emec, regime, ss) = { + if emec == 0b0 then { + return(DEFAULT_MECID) + }; + if ss != SS_Realm then { + return(DEFAULT_MECID) + }; + match regime { + Regime_EL2 => { + return(MECID_P0_EL2[MECID]) + }, + Regime_EL20 => { + if TCR_EL2[A1] == 0b0 then { + return(MECID_P1_EL2[MECID]) + } else { + return(MECID_P0_EL2[MECID]) + } + }, + Regime_EL10 => { + return(VMECID_P_EL2[MECID]) + }, + _ => { + Unreachable(); + return(undefined : bits(16)) + } + } +} + +val S2TLBCache : TLBRecord -> unit + +val S2TLBLookup : TLBContext -> TLBLine + +val AArch64_S2Walk : forall 'N, 'N in {32, 64, 128}. + (FaultRecord, AddressDescriptor, S2TTWParams, AccessDescriptor, option(int), int('N)) -> (FaultRecord, AddressDescriptor, TTWState, bits('N)) + +function AArch64_S2Walk (fault_in, ipa, walkparams, accdesc, s1level, N) = { + fault : FaultRecord = fault_in; + let ipa_64 : bits(64) = ZeroExtend(ipa.paddress.address, 64); + tlbcontext : TLBContext = undefined; + tlbrecord : TLBRecord = undefined; + if __tlb_enabled then { + tlbcontext = AArch64_GetS2TLBContext(accdesc.ss, ipa.paddress, walkparams.tgx); + let tlbentry : TLBLine = S2TLBLookup(tlbcontext); + tlbrecord = tlbentry.tlbrecord; + let oa : FullAddress = StageOA(ipa_64, walkparams.d128, walkparams.tgx, tlbrecord.walkstate); + if (tlbentry.valid_name & not_bool(AArch64_OAOutOfRange(oa.address, walkparams.d128, walkparams.ps, walkparams.tgx))) & not_bool(((((walkparams.ha @ walkparams.hd) == 0b11 & (walkparams.s2pie == 0b1 | [tlbrecord.s2descriptor[51]] == 0b1)) & [tlbrecord.s2descriptor[7]] == 0b0) & accdesc.write) & not_bool(accdesc.acctype == AccessType_AT | accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC)) then { + if walkparams.fwb == 0b1 then { + tlbrecord.walkstate.memattrs = AArch64_S2ApplyFWBMemAttrs(ipa.memattrs, walkparams, tlbrecord.s2descriptor); + if tlbrecord.s2descriptor[5 .. 3] == 0b111 then { + tlbrecord.walkstate.permissions.s2tag_na = 0b1 + } else { + tlbrecord.walkstate.permissions.s2tag_na = 0b0 + } + }; + fault.level = tlbrecord.walkstate.level; + return((fault, __UNKNOWN_AddressDescriptor(), tlbrecord.walkstate, tlbrecord.s2descriptor[N - 1 .. 0])) + }; + () + }; + walkstate : TTWState = undefined; + if accdesc.ss == SS_Secure then { + walkstate = AArch64_SS2InitialTTWState(walkparams, ipa.paddress.paspace) + } else { + walkstate = AArch64_S2InitialTTWState(accdesc.ss, walkparams) + }; + let 'startlevel = walkstate.level; + descriptor : bits('N) = undefined; + let walkaccess : AccessDescriptor = CreateAccDescS2TTW(accdesc); + walkaddress : AddressDescriptor = undefined; + skl : bits(2) = 0b00; + walkaddress.vaddress = ipa.vaddress; + walkaddress.mecid = AArch64_TTWalkMECID(walkparams.emec, Regime_EL10, accdesc.ss); + if HCR_EL2[CD] == 0b1 then { + walkaddress.memattrs = NormalNCMemAttr(); + walkaddress.memattrs.xs = walkstate.memattrs.xs + } else { + walkaddress.memattrs = walkstate.memattrs + }; + walkaddress.memattrs.shareability = EffectiveShareability(walkaddress.memattrs); + walkaddress.tlbcontext = tlbcontext; + desctype : DescriptorType = undefined; + descaddress : FullAddress = AArch64_S2SLTTEntryAddress(walkparams, ipa.paddress.address, walkstate.baseaddress); + if AArch64_OAOutOfRange(descaddress.address, walkparams.d128, walkparams.ps, walkparams.tgx) then { + fault.statuscode = Fault_AddressSize; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + repeat { + fault.level = walkstate.level; + walkaddress.paddress = descaddress; + let translation_info : TranslationInfo = struct { + regime = Regime_EL10, + vmid = Some(VMID_read()), // TODO? + asid = None(), + va = walkaddress.vaddress, + s1level = s1level, + s2info = Some((ipa_64, walkstate.level)), + s1params = None(), + s2params = Some(walkparams), + memattrs = walkaddress.memattrs + }; + (fault, descriptor) = FetchDescriptor(walkparams.ee, walkaddress, walkaccess, fault, N, translation_info); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + new_descriptor : bits('N) = undefined; + repeat { + new_descriptor = descriptor; + desctype = AArch64_DecodeDescriptorType(descriptor, walkparams.d128, walkparams.ds, walkparams.tgx, walkstate.level); + match desctype { + DescriptorType_Table => { + walkstate = AArch64_S2NextWalkStateTable(walkstate, walkparams, descriptor); + skl = if walkparams.d128 == 0b1 then { + assert(constraint(110 < 'N)); + descriptor[110 .. 109] + } else 0b00; + descaddress = AArch64_TTEntryAddress(walkstate.level, walkparams.d128, skl, walkparams.tgx, walkparams.txsz, ipa_64, walkstate.baseaddress); + if AArch64_OAOutOfRange(descaddress.address, walkparams.d128, walkparams.ps, walkparams.tgx) then { + fault.statuscode = Fault_AddressSize; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + if walkparams.haft == 0b1 then { + new_descriptor[10] = Bit(0b1) + }; + if (walkparams.d128 == 0b1 & skl != 0b00) & AArch64_BlocknTFaults(walkparams.d128, descriptor) then { + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + () + }, + DescriptorType_Leaf => { + assert(constraint(52 < 'N)); + walkstate = AArch64_S2NextWalkStateLeaf(walkstate, accdesc.ss, walkparams, ipa, descriptor) + }, + DescriptorType_Invalid => { + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }, + _ => { + Unreachable() + } + }; + if new_descriptor != descriptor then { + let descaccess : AccessDescriptor = CreateAccDescTTEUpdate(accdesc); + assert(constraint('N in {64, 128})); + (fault, descriptor) = AArch64_MemSwapTableDesc(fault, descriptor, new_descriptor, walkparams.ee, descaccess, walkaddress, translation_info); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + () + }; + () + } until new_descriptor == descriptor + } until desctype == DescriptorType_Leaf; + let oa : FullAddress = StageOA(ipa_64, walkparams.d128, walkparams.tgx, walkstate); + if walkstate.contiguous == 0b1 & AArch64_ContiguousBitFaults(walkparams.d128, walkparams.txsz, walkparams.tgx, walkstate.level) then { + fault.statuscode = Fault_Translation + } else if (desctype == DescriptorType_Leaf & walkstate.level < FINAL_LEVEL) & AArch64_BlocknTFaults(walkparams.d128, descriptor) then { + fault.statuscode = Fault_Translation + } else if AArch64_OAOutOfRange(oa.address, walkparams.d128, walkparams.ps, walkparams.tgx) then { + fault.statuscode = Fault_AddressSize + } else if ([descriptor[10]] == 0b0 & walkparams.ha == 0b0) & not_bool((accdesc.acctype == AccessType_DC | accdesc.acctype == AccessType_IC) & not_bool(__IMPDEF_boolean("Generate access flag fault on IC/DC operations"))) then { + fault.statuscode = Fault_AccessFlag + } else (); + if (__tlb_enabled & fault.statuscode == Fault_None) & [descriptor[10]] == 0b1 then { + tlbcontext.xs = walkstate.memattrs.xs; + tlbcontext.level = walkstate.level; + tlbcontext.isd128 = walkparams.d128 == 0b1; + tlbrecord.context = tlbcontext; + tlbrecord.walkstate = walkstate; + tlbrecord.blocksize = TranslationSize(walkparams.d128, walkparams.tgx, walkstate.level); + if walkparams.d128 == 0b1 then { + assert(constraint(127 < 'N)); + tlbrecord.s2descriptor = descriptor[127 .. 0] + } else { + assert(constraint(63 < 'N)); + tlbrecord.s2descriptor[63 .. 0] = descriptor[63 .. 0]; + tlbrecord.s2descriptor[127 .. 64] = Zeros(64) + }; + if walkstate.contiguous == 0b1 then { + tlbrecord.contigsize = ContiguousSize(walkparams.d128, walkparams.tgx, walkstate.level) + } else { + tlbrecord.contigsize = 0 + }; + S2TLBCache(tlbrecord) + }; + return((fault, walkaddress, walkstate, descriptor)) +} + +val AArch64_SettingAccessFlagPermitted : FaultRecord -> bool + +function AArch64_SettingAccessFlagPermitted fault = { + if fault.statuscode == Fault_None then { + return(true) + } else if fault.statuscode == Fault_Alignment | fault.statuscode == Fault_Permission then { + return(ConstrainUnpredictableBool(Unpredictable_AFUPDATE)) + } else { + return(false) + } +} + +val AArch64_SettingDirtyStatePermitted : FaultRecord -> bool + +function AArch64_SettingDirtyStatePermitted fault = { + if fault.statuscode == Fault_None then { + return(true) + } else if fault.statuscode == Fault_Alignment then { + return(ConstrainUnpredictableBool(Unpredictable_DBUPDATE)) + } else { + return(false) + } +} + +val AArch64_S2Translate : forall ('aligned : Bool) ('s1aarch64 : Bool). + (FaultRecord, AddressDescriptor, bool('s1aarch64), option(int), bool('aligned), AccessDescriptor) -> (FaultRecord, AddressDescriptor) + +function AArch64_S2Translate (fault_in, ipa, s1aarch64, s1level, aligned, accdesc) = { + walkparams : S2TTWParams = AArch64_GetS2TTWParams(accdesc.ss, ipa.paddress.paspace, s1aarch64); + fault : FaultRecord = fault_in; + s2fs1mro : bool = undefined; + fault.statuscode = Fault_None; + fault.secondstage = true; + fault.s2fs1walk = accdesc.acctype == AccessType_TTW; + fault.ipaddress = ipa.paddress; + if walkparams.vm != 0b1 then { + return((fault, ipa)) + }; + let 's2mintxsz = AArch64_S2MinTxSZ(walkparams.d128, walkparams.ds, walkparams.tgx, s1aarch64); + let 's2maxtxsz = AArch64_MaxTxSZ(walkparams.tgx); + if AArch64_S2TxSZFaults(walkparams, s1aarch64) then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + } else if UInt(walkparams.txsz) < s2mintxsz then { + walkparams.txsz = s2mintxsz[5 .. 0] + } else if UInt(walkparams.txsz) > s2maxtxsz then { + walkparams.txsz = s2maxtxsz[5 .. 0] + } else (); + if walkparams.d128 == 0b0 & (AArch64_S2InvalidSL(walkparams) | AArch64_S2InconsistentSL(walkparams)) then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + if AArch64_IPAIsOutOfRange(ipa.paddress.address, walkparams) then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + descpaddr : AddressDescriptor = undefined; + walkstate : TTWState = undefined; + descriptor : bits(128) = undefined; + new_desc : bits(128) = undefined; + mem_desc : bits(128) = undefined; + repeat { + if walkparams.d128 == 0b1 then { + (fault, descpaddr, walkstate, descriptor) = AArch64_S2Walk(fault, ipa, walkparams, accdesc, s1level, 128) + } else { + (fault, descpaddr, walkstate, descriptor[63 .. 0]) = AArch64_S2Walk(fault, ipa, walkparams, accdesc, s1level, 64); + descriptor[127 .. 64] = Zeros(64) + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + }; + if AArch64_S2HasAlignmentFault(accdesc, aligned, walkstate.memattrs) then { + fault.statuscode = Fault_Alignment + }; + if fault.statuscode == Fault_None then { + (fault, s2fs1mro) = AArch64_S2CheckPermissions(fault, walkstate, walkparams, ipa, accdesc) + }; + new_desc = descriptor; + if walkparams.ha == 0b1 & AArch64_SettingAccessFlagPermitted(fault) then { + new_desc[10] = Bit(0b1) + }; + if ((((AArch64_SettingDirtyStatePermitted(fault) & walkparams.ha == 0b1) & walkparams.hd == 0b1) & (walkparams.s2pie == 0b1 | [descriptor[51]] == 0b1)) & accdesc.write) & not_bool(accdesc.acctype == AccessType_AT | accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC) then { + new_desc[7] = Bit(0b1) + }; + if new_desc != descriptor then { + let descaccess : AccessDescriptor = CreateAccDescTTEUpdate(accdesc); + let translation_info : TranslationInfo = struct { + regime = Regime_EL10, + vmid = Some(VMID_read()), // TODO? + asid = None(), + va = ipa.vaddress, + s1level = s1level, + s2info = Some((ZeroExtend(ipa.paddress.address, 64), walkstate.level)), + s1params = None(), + s2params = Some(walkparams), + memattrs = walkstate.memattrs + }; + if walkparams.d128 == 0b1 then { + (fault, mem_desc) = AArch64_MemSwapTableDesc(fault, descriptor, new_desc, walkparams.ee, descaccess, descpaddr, translation_info) + } else { + (fault, mem_desc[63 .. 0]) = AArch64_MemSwapTableDesc(fault, descriptor[63 .. 0], new_desc[63 .. 0], walkparams.ee, descaccess, descpaddr, translation_info); + mem_desc[127 .. 64] = Zeros(64) + } + }; + () + } until new_desc == descriptor | mem_desc == new_desc; + if (__tlb_enabled & new_desc != descriptor) & [mem_desc[10]] == 0b1 then { + tlbrecord : TLBRecord = undefined; + if [descriptor[10]] == 0b1 then { + let tlbentry : TLBLine = S2TLBLookup(descpaddr.tlbcontext); + assert(tlbentry.valid_name); + tlbrecord = tlbentry.tlbrecord + } else { + tlbrecord.context = descpaddr.tlbcontext; + tlbrecord.context.xs = walkstate.memattrs.xs; + tlbrecord.context.level = walkstate.level; + tlbrecord.context.includes_s2_name = true; + tlbrecord.context.isd128 = walkparams.d128 == 0b1; + tlbrecord.walkstate = walkstate; + tlbrecord.blocksize = TranslationSize(walkparams.d128, walkparams.tgx, walkstate.level); + if walkstate.contiguous == 0b1 then { + tlbrecord.contigsize = ContiguousSize(walkparams.d128, walkparams.tgx, walkstate.level) + } else { + tlbrecord.contigsize = 0 + } + }; + if walkparams.d128 == 0b1 then { + tlbrecord.s2descriptor = mem_desc + } else { + tlbrecord.s2descriptor[63 .. 0] = mem_desc[63 .. 0]; + tlbrecord.s2descriptor[127 .. 64] = Zeros(64) + }; + S2TLBCache(tlbrecord) + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + }; + let ipa_64 : bits(64) = ZeroExtend(ipa.paddress.address, 64); + let oa : FullAddress = StageOA(ipa_64, walkparams.d128, walkparams.tgx, walkstate); + s2_memattrs : MemoryAttributes = undefined; + if ((accdesc.acctype == AccessType_TTW & walkstate.memattrs.memtype == MemType_Device) & walkparams.ptw == 0b0 | accdesc.acctype == AccessType_IFETCH & (walkstate.memattrs.memtype == MemType_Device | HCR_EL2[ID] == 0b1)) | (accdesc.acctype != AccessType_IFETCH & walkstate.memattrs.memtype == MemType_Normal) & HCR_EL2[CD] == 0b1 then { + s2_memattrs = NormalNCMemAttr(); + s2_memattrs.xs = walkstate.memattrs.xs + } else { + s2_memattrs = walkstate.memattrs + }; + if accdesc.ls64 & s2_memattrs.memtype == MemType_Normal then { + if s2_memattrs.inner.attrs != MemAttr_NC | s2_memattrs.outer.attrs != MemAttr_NC then { + fault.statuscode = Fault_Exclusive; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + () + }; + let s2aarch64 : bool = true; + memattrs : MemoryAttributes = undefined; + if walkparams.fwb == 0b0 then { + memattrs = S2CombineS1MemAttrs(ipa.memattrs, s2_memattrs, s2aarch64) + } else { + memattrs = s2_memattrs + }; + pa : AddressDescriptor = CreateAddressDescriptor(ipa.vaddress, oa, memattrs); + pa.tlbcontext = descpaddr.tlbcontext; + pa.s2fs1mro = s2fs1mro; + pa.mecid = AArch64_S2OutputMECID(walkparams, pa.paddress.paspace, descriptor); + return((fault, pa)) +} + +val S1TLBCache : TLBRecord -> unit + +val S1TLBLookup : TLBContext -> TLBLine + +val AArch64_S1Walk : forall 'N, 10 < 'N. + (FaultRecord, S1TTWParams, bits(64), Regime, AccessDescriptor, int('N)) -> (FaultRecord, AddressDescriptor, TTWState, bits('N)) + +function AArch64_S1Walk (fault_in, walkparams, va, regime, accdesc, N) = { + fault : FaultRecord = fault_in; + s1aarch64 : bool = undefined; + aligned : bool = undefined; + tlbcontext : TLBContext = undefined; + tlbrecord : TLBRecord = undefined; + if __tlb_enabled then { + tlbcontext = AArch64_GetS1TLBContext(regime, accdesc.ss, va, walkparams.tgx); + let tlbentry : TLBLine = S1TLBLookup(tlbcontext); + tlbrecord = tlbentry.tlbrecord; + let oa : FullAddress = StageOA(va, walkparams.d128, walkparams.tgx, tlbrecord.walkstate); + if (tlbentry.valid_name & not_bool(AArch64_OAOutOfRange(oa.address, walkparams.d128, walkparams.ps, walkparams.tgx))) & not_bool(((((walkparams.ha @ walkparams.hd) == 0b11 & (walkparams.pie == 0b1 | [tlbrecord.s1descriptor[51]] == 0b1)) & [tlbrecord.s1descriptor[7]] == 0b1) & accdesc.write) & not_bool(accdesc.acctype == AccessType_AT | accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC)) then { + fault.level = tlbrecord.walkstate.level; + assert(constraint((0 <= 'N - 1 & 'N - 1 < 128))); + return((fault, __UNKNOWN_AddressDescriptor(), tlbrecord.walkstate, tlbrecord.s1descriptor[N - 1 .. 0])) + }; + () + }; + if HasUnprivileged(regime) & AArch64_S1EPD(regime, va) == 0b1 then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + walkstate : TTWState = AArch64_S1InitialTTWState(walkparams, va, regime, accdesc.ss); + let 'startlevel = walkstate.level; + descriptor : bits('N) = undefined; + walkaddress : AddressDescriptor = undefined; + skl : bits(2) = 0b00; + walkaddress.vaddress = va; + walkaddress.mecid = AArch64_TTWalkMECID(walkparams.emec, regime, accdesc.ss); + if not_bool(AArch64_S1DCacheEnabled(regime)) then { + walkaddress.memattrs = NormalNCMemAttr(); + walkaddress.memattrs.xs = walkstate.memattrs.xs + } else { + walkaddress.memattrs = walkstate.memattrs + }; + if ((regime == Regime_EL10 & EL2Enabled()) & HCR_EL2[VM] == 0b1) & not_bool(__IMPDEF_boolean("Apply effective shareability at stage 1")) then { + walkaddress.memattrs.shareability = walkstate.memattrs.shareability + } else { + walkaddress.memattrs.shareability = EffectiveShareability(walkaddress.memattrs) + }; + walkaddress.tlbcontext = tlbcontext; + s2fs1mro : bool = false; + desctype : DescriptorType = undefined; + descaddress : FullAddress = AArch64_S1SLTTEntryAddress(walkstate.level, walkparams, va, walkstate.baseaddress); + if AArch64_OAOutOfRange(descaddress.address, walkparams.d128, walkparams.ps, walkparams.tgx) then { + fault.statuscode = Fault_AddressSize; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + repeat { + fault.level = walkstate.level; + walkaddress.paddress = descaddress; + let toplevel : bool = walkstate.level == startlevel; + let varange : VARange = AArch64_GetVARange(va); + let walkaccess : AccessDescriptor = CreateAccDescS1TTW(toplevel, varange, accdesc); + let translation_info : TranslationInfo = struct { + regime = regime, + vmid = None(), // TODO: if regime == Regime_EL10 then Some(VMID_read()) else None(), + asid = None(), // TODO + va = walkaddress.vaddress, + s1level = Some(walkstate.level), + s2info = None(), + s1params = Some(walkparams), + s2params = None(), + memattrs = walkaddress.memattrs + }; + s2fault : FaultRecord = undefined; + s2walkaddress : AddressDescriptor = undefined; + if regime == Regime_EL10 & EL2Enabled() then { + s1aarch64 = true; + aligned = true; + (s2fault, s2walkaddress) = AArch64_S2Translate(fault, walkaddress, s1aarch64, Some(walkstate.level), aligned, walkaccess); + if s2fault.statuscode != Fault_None then { + return((s2fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + s2fs1mro = s2walkaddress.s2fs1mro; + assert(constraint('N in {32, 64, 128})); + (fault, descriptor) = FetchDescriptor(walkparams.ee, s2walkaddress, walkaccess, fault, N, translation_info) + } else { + assert(constraint('N in {32, 64, 128})); + (fault, descriptor) = FetchDescriptor(walkparams.ee, walkaddress, walkaccess, fault, N, translation_info) + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + new_descriptor : bits('N) = undefined; + repeat { + new_descriptor = descriptor; + desctype = AArch64_DecodeDescriptorType(descriptor, walkparams.d128, walkparams.ds, walkparams.tgx, walkstate.level); + match desctype { + DescriptorType_Table => { + walkstate = AArch64_S1NextWalkStateTable(walkstate, s2fs1mro, regime, walkparams, descriptor); + skl = if walkparams.d128 == 0b1 then { + assert(constraint(110 < 'N)); + descriptor[110 .. 109] + } else 0b00; + descaddress = AArch64_TTEntryAddress(walkstate.level, walkparams.d128, skl, walkparams.tgx, walkparams.txsz, va, walkstate.baseaddress); + if AArch64_OAOutOfRange(descaddress.address, walkparams.d128, walkparams.ps, walkparams.tgx) then { + fault.statuscode = Fault_AddressSize; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + if walkparams.haft == 0b1 then { + assert(constraint(10 < 'N)); + new_descriptor[10] = Bit(0b1) + }; + if (walkparams.d128 == 0b1 & skl != 0b00) & AArch64_BlocknTFaults(walkparams.d128, descriptor) then { + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + () + }, + DescriptorType_Leaf => { + walkstate = AArch64_S1NextWalkStateLeaf(walkstate, s2fs1mro, regime, accdesc.ss, walkparams, descriptor) + }, + DescriptorType_Invalid => { + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }, + _ => { + Unreachable() + } + }; + if new_descriptor != descriptor then { + descpaddr : AddressDescriptor = undefined; + let descaccess : AccessDescriptor = CreateAccDescTTEUpdate(accdesc); + if regime == Regime_EL10 & EL2Enabled() then { + s1aarch64 = true; + aligned = true; + (s2fault, descpaddr) = AArch64_S2Translate(fault, walkaddress, s1aarch64, Some(walkstate.level), aligned, descaccess); + if s2fault.statuscode != Fault_None then { + return((s2fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + () + } else { + descpaddr = walkaddress + }; + assert(constraint('N in {64, 128})); + (fault, descriptor) = AArch64_MemSwapTableDesc(fault, descriptor, new_descriptor, walkparams.ee, descaccess, descpaddr, translation_info); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + () + }; + () + } until new_descriptor == descriptor + } until desctype == DescriptorType_Leaf; + let oa : FullAddress = StageOA(va, walkparams.d128, walkparams.tgx, walkstate); + if walkstate.contiguous == 0b1 & AArch64_ContiguousBitFaults(walkparams.d128, walkparams.txsz, walkparams.tgx, walkstate.level) then { + fault.statuscode = Fault_Translation + } else if (desctype == DescriptorType_Leaf & walkstate.level < FINAL_LEVEL) & AArch64_BlocknTFaults(walkparams.d128, descriptor) then { + fault.statuscode = Fault_Translation + } else { + assert(constraint('N in {64, 128})); + if AArch64_S1AMECFault(walkparams, walkstate.baseaddress.paspace, regime, descriptor) then { + fault.statuscode = Fault_Translation + } else if AArch64_OAOutOfRange(oa.address, walkparams.d128, walkparams.ps, walkparams.tgx) then { + fault.statuscode = Fault_AddressSize + } else if ([descriptor[10]] == 0b0 & walkparams.ha == 0b0) & not_bool((accdesc.acctype == AccessType_DC | accdesc.acctype == AccessType_IC) & not_bool(__IMPDEF_boolean("Generate access flag fault on IC/DC operations"))) then { + fault.statuscode = Fault_AccessFlag + } else () + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_TTWState(), __UNKNOWN_bits(N))) + }; + if (__tlb_enabled & fault.statuscode == Fault_None) & [descriptor[10]] == 0b1 then { + tlbcontext.xs = walkstate.memattrs.xs; + tlbcontext.level = walkstate.level; + tlbcontext.nG = walkstate.nG; + tlbcontext.isd128 = walkparams.d128 == 0b1; + tlbrecord.context = tlbcontext; + tlbrecord.walkstate = walkstate; + tlbrecord.blocksize = TranslationSize(walkparams.d128, walkparams.tgx, walkstate.level); + if walkparams.d128 == 0b1 then { + assert(constraint(127 < 'N)); + tlbrecord.s1descriptor = descriptor[127 .. 0] + } else { + assert(constraint(63 < 'N)); + tlbrecord.s1descriptor[63 .. 0] = descriptor[63 .. 0]; + tlbrecord.s1descriptor[127 .. 64] = Zeros(64) + }; + if walkstate.contiguous == 0b1 then { + tlbrecord.contigsize = ContiguousSize(walkparams.d128, walkparams.tgx, walkstate.level) + } else { + tlbrecord.contigsize = 0 + }; + S1TLBCache(tlbrecord) + }; + return((fault, walkaddress, walkstate, descriptor)) +} + +val AArch64_VAIsOutOfRange : (bits(64), AccessType, Regime, S1TTWParams) -> bool + +function AArch64_VAIsOutOfRange (va_in, acctype, regime, walkparams) = { + va : bits(64) = va_in; + let 'addrtop = AArch64_AddrTop(walkparams.tbid, acctype, walkparams.tbi); + if walkparams.mtx == 0b1 then { + va[59 .. 56] = if AArch64_GetVARange(va) == VARange_UPPER then 0b1111 + else + 0b0000 + }; + let 'iasize = AArch64_IASize(walkparams.txsz); + if addrtop < iasize then { + return(false) + }; + if HasUnprivileged(regime) then { + if AArch64_GetVARange(va) == VARange_LOWER then { + return(not_bool(is_zero_subrange(va, addrtop, iasize))) + } else { + return(not_bool(is_ones_subrange(va, addrtop, iasize))) + } + } else { + return(not_bool(is_zero_subrange(va, addrtop, iasize))) + } +} + +val AArch64_S1Translate : forall ('aligned : Bool). + (FaultRecord, Regime, bits(64), bool('aligned), AccessDescriptor) -> (FaultRecord, AddressDescriptor) + +function AArch64_S1Translate (fault_in, regime, va, aligned, accdesc) = { + descaccess : AccessDescriptor = undefined; + s1aarch64 : bool = undefined; + s2aligned : bool = undefined; + tlbentry : TLBLine = undefined; + fault : FaultRecord = fault_in; + fault.secondstage = false; + fault.s2fs1walk = false; + if not_bool(AArch64_S1Enabled(regime, accdesc.acctype)) then { + return(AArch64_S1DisabledOutput(fault, regime, va, accdesc, aligned)) + }; + walkparams : S1TTWParams = AArch64_GetS1TTWParams(regime, accdesc.ss, va); + let 's1mintxsz = AArch64_S1MinTxSZ(regime, walkparams.d128, walkparams.ds, walkparams.tgx); + let 's1maxtxsz = AArch64_MaxTxSZ(walkparams.tgx); + if AArch64_S1TxSZFaults(regime, walkparams) then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + } else if UInt(walkparams.txsz) < s1mintxsz then { + walkparams.txsz = s1mintxsz[5 .. 0] + } else if UInt(walkparams.txsz) > s1maxtxsz then { + walkparams.txsz = s1maxtxsz[5 .. 0] + } else (); + if AArch64_VAIsOutOfRange(va, accdesc.acctype, regime, walkparams) then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + if accdesc.el == EL0 & walkparams.e0pd == 0b1 then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + if ((HaveTME() & accdesc.el == EL0) & walkparams.nfd == 0b1) & accdesc.transactional then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + if ((HaveSVE() & accdesc.el == EL0) & walkparams.nfd == 0b1) & (accdesc.nonfault & accdesc.contiguous | (accdesc.firstfault & not_bool(accdesc.first)) & not_bool(accdesc.contiguous)) then { + fault.statuscode = Fault_Translation; + fault.level = 0; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + descipaddr : AddressDescriptor = undefined; + walkstate : TTWState = undefined; + descriptor : bits(128) = undefined; + new_desc : bits(128) = undefined; + mem_desc : bits(128) = undefined; + repeat { + if walkparams.d128 == 0b1 then { + (fault, descipaddr, walkstate, descriptor) = AArch64_S1Walk(fault, walkparams, va, regime, accdesc, 128) + } else { + (fault, descipaddr, walkstate, descriptor[63 .. 0]) = AArch64_S1Walk(fault, walkparams, va, regime, accdesc, 64); + descriptor[127 .. 64] = Zeros(64) + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + }; + if accdesc.acctype == AccessType_IFETCH then { + SetInGuardedPage(walkstate.guardedpage == 0b1) + }; + if AArch64_S1HasAlignmentFault(accdesc, aligned, walkparams.ntlsmd, walkstate.memattrs) then { + fault.statuscode = Fault_Alignment + }; + if fault.statuscode == Fault_None then { + fault = AArch64_S1CheckPermissions(fault, regime, walkstate, walkparams, accdesc) + }; + new_desc = descriptor; + if walkparams.ha == 0b1 & AArch64_SettingAccessFlagPermitted(fault) then { + new_desc[10] = Bit(0b1) + }; + if ((((AArch64_SettingDirtyStatePermitted(fault) & walkparams.ha == 0b1) & walkparams.hd == 0b1) & (walkparams.pie == 0b1 | [descriptor[51]] == 0b1)) & accdesc.write) & not_bool(accdesc.acctype == AccessType_AT | accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC) then { + new_desc[7] = Bit(0b0) + }; + if new_desc != descriptor then { + descpaddr : AddressDescriptor = undefined; + descaccess = CreateAccDescTTEUpdate(accdesc); + if regime == Regime_EL10 & EL2Enabled() then { + s2fault : FaultRecord = undefined; + s1aarch64 = true; + s2aligned = true; + (s2fault, descpaddr) = AArch64_S2Translate(fault, descipaddr, s1aarch64, None(), s2aligned, descaccess); + if s2fault.statuscode != Fault_None then { + return((s2fault, __UNKNOWN_AddressDescriptor())) + }; + () + } else { + descpaddr = descipaddr + }; + let translation_info : TranslationInfo = struct { + regime = regime, + vmid = None(), // TODO: if regime == Regime_EL10 then Some(VMID_read()) else None(), + asid = None(), // TODO + va = va, + s1level = Some(walkstate.level), + s2info = None(), + s1params = Some(walkparams), + s2params = None(), + memattrs = walkstate.memattrs + }; + if walkparams.d128 == 0b1 then { + (fault, mem_desc) = AArch64_MemSwapTableDesc(fault, descriptor, new_desc, walkparams.ee, descaccess, descpaddr, translation_info) + } else { + (fault, mem_desc[63 .. 0]) = AArch64_MemSwapTableDesc(fault, descriptor[63 .. 0], new_desc[63 .. 0], walkparams.ee, descaccess, descpaddr, translation_info); + mem_desc[127 .. 64] = Zeros(64) + } + }; + () + } until new_desc == descriptor | mem_desc == new_desc; + if (__tlb_enabled & new_desc != descriptor) & [mem_desc[10]] == 0b1 then { + tlbrecord : TLBRecord = undefined; + if [descriptor[10]] == 0b1 then { + let tlbentry : TLBLine = S1TLBLookup(descipaddr.tlbcontext); + assert(tlbentry.valid_name); + tlbrecord = tlbentry.tlbrecord + } else { + tlbrecord.context = descipaddr.tlbcontext; + tlbrecord.context.xs = walkstate.memattrs.xs; + tlbrecord.context.level = walkstate.level; + tlbrecord.context.nG = walkstate.nG; + tlbrecord.context.isd128 = walkparams.d128 == 0b1; + tlbrecord.walkstate = walkstate; + tlbrecord.blocksize = TranslationSize(walkparams.d128, walkparams.tgx, walkstate.level); + if walkstate.contiguous == 0b1 then { + tlbrecord.contigsize = ContiguousSize(walkparams.d128, walkparams.tgx, walkstate.level) + } else { + tlbrecord.contigsize = 0 + } + }; + if walkparams.d128 == 0b1 then { + tlbrecord.s1descriptor = mem_desc + } else { + tlbrecord.s1descriptor[63 .. 0] = mem_desc[63 .. 0]; + tlbrecord.s1descriptor[127 .. 64] = Zeros(64) + }; + S1TLBCache(tlbrecord) + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + }; + let oa : FullAddress = StageOA(va, walkparams.d128, walkparams.tgx, walkstate); + memattrs : MemoryAttributes = undefined; + if accdesc.acctype == AccessType_IFETCH & (walkstate.memattrs.memtype == MemType_Device | not_bool(AArch64_S1ICacheEnabled(regime))) then { + memattrs = NormalNCMemAttr(); + memattrs.xs = walkstate.memattrs.xs + } else if (accdesc.acctype != AccessType_IFETCH & not_bool(AArch64_S1DCacheEnabled(regime))) & walkstate.memattrs.memtype == MemType_Normal then { + memattrs = NormalNCMemAttr(); + memattrs.xs = walkstate.memattrs.xs; + if (HaveMTE2Ext() & walkstate.memattrs.tags == MemTag_AllocationTagged) & not_bool(ConstrainUnpredictableBool(Unpredictable_S1CTAGGED)) then { + memattrs.tags = MemTag_Untagged + }; + () + } else { + memattrs = walkstate.memattrs + }; + if ((regime == Regime_EL10 & EL2Enabled()) & HCR_EL2[VM] == 0b1) & not_bool(__IMPDEF_boolean("Apply effective shareability at stage 1")) then { + memattrs.shareability = walkstate.memattrs.shareability + } else { + memattrs.shareability = EffectiveShareability(memattrs) + }; + if accdesc.ls64 & memattrs.memtype == MemType_Normal then { + if memattrs.inner.attrs != MemAttr_NC | memattrs.outer.attrs != MemAttr_NC then { + fault.statuscode = Fault_Exclusive; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + () + }; + ipa : AddressDescriptor = CreateAddressDescriptor(va, oa, memattrs); + ipa.tlbcontext = descipaddr.tlbcontext; + ipa.s1assured = walkstate.s1assured; + let varange : VARange = AArch64_GetVARange(va); + ipa.mecid = AArch64_S1OutputMECID(walkparams, regime, varange, ipa.paddress.paspace, descriptor); + return((fault, ipa)) +} + +val AArch64_FullTranslate : forall ('aligned : Bool). + (bits(64), AccessDescriptor, bool('aligned)) -> AddressDescriptor + +function AArch64_FullTranslate (va, accdesc, aligned) = { + s1aarch64 : bool = undefined; + let regime : Regime = TranslationRegime(accdesc.el); + fault : FaultRecord = NoFault__1(accdesc); + ipa : AddressDescriptor = undefined; + (fault, ipa) = AArch64_S1Translate(fault, regime, va, aligned, accdesc); + if fault.statuscode != Fault_None then { + return(CreateFaultyAddressDescriptor(va, fault)) + }; + assert(((accdesc.ss == SS_Realm) --> EL2Enabled())); + if regime == Regime_EL10 & EL2Enabled() then { + let s1aarch64 : bool = true; + pa : AddressDescriptor = undefined; + (fault, pa) = AArch64_S2Translate(fault, ipa, s1aarch64, None(), aligned, accdesc); + if fault.statuscode != Fault_None then { + return(CreateFaultyAddressDescriptor(va, fault)) + } else { + return(pa) + } + } else { + return(ipa) + } +} + +register SPESampleCounterPending : vector(32, bool) + +val SPEStartCounter : forall 'counter_index, + (0 <= 'counter_index | not('counter_index < 32)). + int('counter_index) -> unit + +function SPEStartCounter counter_index = { + assert(counter_index < SPEMaxCounters); + SPESampleCounterPending[counter_index] = true +} + +register SPESampleCounterValid : vector(32, bool) + +val SPEStopCounter : forall 'counter_index, + (0 <= 'counter_index & 'counter_index < 32). + int('counter_index) -> unit + +function SPEStopCounter counter_index = { + SPESampleCounterValid[counter_index] = true; + SPESampleCounterPending[counter_index] = false +} + +val AArch64_TranslateAddress : forall ('aligned : Bool) 'size. + (bits(64), AccessDescriptor, bool('aligned), int('size)) -> AddressDescriptor + +function AArch64_TranslateAddress (va, accdesc, aligned, size) = { + if SPESampleInFlight & not_bool(accdesc.acctype == AccessType_IFETCH | accdesc.acctype == AccessType_SPE) then { + SPEStartCounter(SPECounterPosTranslationLatency) + }; + // Determine translation context and announce translation start + let regime : Regime = TranslationRegime(accdesc.el); + let tsi = AArch64_GetTranslationStartInfo(regime, accdesc.ss, accdesc, va, size); + start_translation(tsi); + // + result : AddressDescriptor = AArch64_FullTranslate(va, accdesc, aligned); + if not_bool(IsFault(result)) & accdesc.acctype != AccessType_IFETCH then { + result.fault = AArch64_CheckDebug(va, accdesc, size) + }; + if (HaveRME() & not_bool(IsFault(result))) & (accdesc.acctype != AccessType_DC | __IMPDEF_boolean("GPC Fault on DC operations")) then { + result.fault.gpcf = GranuleProtectionCheck(result, accdesc); + if result.fault.gpcf.gpf != GPCF_None then { + result.fault.statuscode = Fault_GPCFOnOutput; + result.fault.paddress = result.paddress + }; + () + }; + if not_bool(IsFault(result)) & accdesc.acctype == AccessType_IFETCH then { + result.fault = AArch64_CheckDebug(va, accdesc, size) + }; + if SPESampleInFlight & not_bool(accdesc.acctype == AccessType_IFETCH | accdesc.acctype == AccessType_SPE) then { + SPEStopCounter(SPECounterPosTranslationLatency) + }; + result.vaddress = ZeroExtend(va, 64); + // Announce result + end_translation(result); + // + return(result) +} + +val MemHasTransactionalAccess : MemoryAttributes -> bool + +function MemHasTransactionalAccess memattrs = { + if (((((((memattrs.shareability == Shareability_ISH | memattrs.shareability == Shareability_OSH) & memattrs.memtype == MemType_Normal) & memattrs.inner.attrs == MemAttr_WB) & memattrs.inner.hints == MemHint_RWA) & memattrs.inner.transient == false) & memattrs.outer.hints == MemHint_RWA) & memattrs.outer.attrs == MemAttr_WB) & memattrs.outer.transient == false then { + return(true) + } else { + return(__IMPDEF_boolean("Memory Region does not support Transactional access")) + } +} + +val CollectPhysicalAddress : unit -> bool + +function CollectPhysicalAddress () = { + owning_el : bits(2) = undefined; + owning_ss : SecurityState = undefined; + if not_bool(StatisticalProfilingEnabled()) then { + return(false) + }; + (owning_ss, owning_el) = ProfilingBufferOwner(); + if HaveEL(EL2) & (owning_ss != SS_Secure | IsSecureEL2Enabled()) then { + return(PMSCR_EL2[PA] == 0b1 & (owning_el == EL2 | PMSCR_EL1[PA] == 0b1)) + } else { + return(PMSCR_EL1[PA] == 0b1) + } +} + +val SPESetDataPhysicalAddress : (AddressDescriptor, AccessDescriptor) -> unit + +function SPESetDataPhysicalAddress (addrdesc, accdesc) = { + ns : bits(1) = undefined; + nse : bits(1) = undefined; + match addrdesc.paddress.paspace { + PAS_Secure => { + ns = 0b0; + nse = 0b0 + }, + PAS_NonSecure => { + ns = 0b1; + nse = 0b0 + }, + PAS_Realm => { + ns = 0b1; + nse = 0b1 + }, + _ => { + Unreachable() + } + }; + if HaveMTE2Ext() then { + pat : bits(4) = undefined; + if accdesc.tagchecked then { + SPESampleAddress[SPEAddrPosDataPhysical][62] = Bit(0b1); + pat = AArch64_PhysicalTag(addrdesc.vaddress) + } else { + let zero_unchecked : bool = __IMPDEF_boolean("SPE PAT for tag unchecked access zero"); + if not_bool(zero_unchecked) then { + pat = AArch64_PhysicalTag(addrdesc.vaddress) + } else { + pat = Zeros(4) + } + }; + SPESampleAddress[SPEAddrPosDataPhysical][59 .. 56] = pat + }; + let paddr : bits(56) = addrdesc.paddress.address; + SPESampleAddress[SPEAddrPosDataPhysical][56 - 1 .. 0] = paddr; + SPESampleAddress[SPEAddrPosDataPhysical][63] = Bit(ns); + SPESampleAddress[SPEAddrPosDataPhysical][60] = Bit(nse); + SPESampleAddressValid[SPEAddrPosDataPhysical] = true +} + +val SPESetDataVirtualAddress : bits(64) -> unit + +function SPESetDataVirtualAddress vaddress = { + let tbi : bits(1) = EffectiveTBI(vaddress, false, PSTATE.EL); + let non_tbi_is_zeros : bool = __IMPDEF_boolean("SPE non-tbi tag is zero"); + if tbi == 0b1 | not_bool(non_tbi_is_zeros) then { + SPESampleAddress[SPEAddrPosDataVirtual][63 .. 0] = vaddress[63 .. 0] + } else { + SPESampleAddress[SPEAddrPosDataVirtual][63 .. 56] = Zeros(8); + SPESampleAddress[SPEAddrPosDataVirtual][55 .. 0] = vaddress[55 .. 0] + }; + SPESampleAddressValid[SPEAddrPosDataVirtual] = true +} + +val SPESampleLoadStore : forall ('is_load : Bool). + (bool('is_load), AccessDescriptor, AddressDescriptor) -> unit + +function SPESampleLoadStore (is_load, accdesc, addrdesc) = { + if accdesc.acctype == AccessType_SPE | accdesc.acctype == AccessType_IFETCH | accdesc.acctype == AccessType_DC | accdesc.acctype == AccessType_TTW | accdesc.acctype == AccessType_AT then { + return() + }; + let sample_loads : bool = [SPESampleSubclass[0]] == 0b0 & SPESampleSubclassValid; + let sample_stores : bool = [SPESampleSubclass[0]] == 0b1 & SPESampleSubclassValid; + if (not_bool(SPESampleSubclassValid) | sample_loads & is_load) | sample_stores & not_bool(is_load) then { + SPESetDataVirtualAddress(addrdesc.vaddress); + if CollectPhysicalAddress() then { + SPESetDataPhysicalAddress(addrdesc, accdesc) + }; + () + }; + if not_bool(SPESampleSubclassValid) then { + SPESampleClass = 0b01; + SPESampleSubclassValid = true; + SPESampleSubclass[7 .. 1] = 0b0001000; + SPESampleSubclass[0] = Bit(if is_load then 0b0 else 0b1); + SPESampleOpType = if is_load then OpType_Load else OpType_Store; + if accdesc.acctype == AccessType_NV2 then { + SPESampleSubclass[7 .. 1] = 0b0011000; + SPESampleInstIsNV2 = true + }; + () + }; + () +} + +val AArch64_MemSingle_read : forall ('aligned : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(64), int('size), AccessDescriptor, bool('aligned)) -> bits('size * 8) + +val AArch64_MemSingle_read__1 : forall ('aligned : Bool) ('ispair : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(64), int('size), AccessDescriptor, bool('aligned), bool('ispair)) -> bits('size * 8) + +function AArch64_MemSingle_read (address, size, accdesc, aligned) = { + let ispair : bool = false; + return(AArch64_MemSingle_read__1(address, size, accdesc, aligned, ispair)) +} + +function AArch64_MemSingle_read__1 (address, size, accdesc_in, aligned, ispair) = { + assert(size == 1 | size == 2 | size == 4 | size == 8 | size == 16); + value_name : bits('size * 8) = undefined; + accdesc : AccessDescriptor = accdesc_in; + if HaveLSE2Ext() then { + assert(AllInAlignedQuantity(address, size, 16)) + } else { + assert(IsAligned__1(address, size)) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if HaveTME() then { + if accdesc.transactional & not_bool(MemHasTransactionalAccess(memaddrdesc.memattrs)) then { + FailTransaction(TMFailure_IMP, false) + }; + () + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + if SPESampleInFlight then { + let is_load : bool = true; + SPESampleLoadStore(is_load, accdesc, memaddrdesc) + }; + atomic : bool = undefined; + if (memaddrdesc.memattrs.memtype == MemType_Normal & memaddrdesc.memattrs.inner.attrs == MemAttr_WB) & memaddrdesc.memattrs.outer.attrs == MemAttr_WB then { + atomic = true + } else if (((accdesc.exclusive | accdesc.atomicop) | accdesc.acqsc) | accdesc.acqpc) | accdesc.relsc then { + if not_bool(aligned) & not_bool(ConstrainUnpredictableBool(Unpredictable_MISALIGNEDATOMIC)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + } else { + atomic = true + } + } else if aligned then { + atomic = not_bool(ispair) + } else { + atomic = __IMPDEF_boolean("FEAT_LSE2: access is atomic") + }; + memstatus : PhysMemRetStatus = undefined; + if atomic then { + (memstatus, value_name) = PhysMemRead(memaddrdesc, size, accdesc, None()); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, size, accdesc) + }; + () + } else if aligned & ispair then { + assert(size == 8 | size == 16); + let 'halfsize = DIV(size, 2); + highhalf : bits('halfsize * 8) = undefined; + lowhalf : bits('halfsize * 8) = undefined; + (memstatus, lowhalf) = PhysMemRead(memaddrdesc, halfsize, accdesc, None()); + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, halfsize, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + halfsize; + (memstatus, highhalf) = PhysMemRead(memaddrdesc, halfsize, accdesc, None()); + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, halfsize, accdesc) + }; + value_name = highhalf @ lowhalf + } else { + foreach (i from 0 to (size - 1) by 1 in inc) { + (memstatus, value_name[8 * i + 7 .. 8 * i]) = PhysMemRead(memaddrdesc, 1, accdesc, None()); + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, 1, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1 + } + }; + return(value_name) +} + +val AArch64_MemSingle_set : forall ('aligned : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(64), int('size), AccessDescriptor, bool('aligned), bits('size * 8)) -> unit + +val AArch64_MemSingle_set__1 : forall ('aligned : Bool) ('ispair : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(64), int('size), AccessDescriptor, bool('aligned), bool('ispair), bits('size * 8)) -> unit + +function AArch64_MemSingle_set (address, size, accdesc, aligned, value_name) = { + let ispair : bool = false; + AArch64_MemSingle_set__1(address, size, accdesc, aligned, ispair) = value_name; + return() +} + +function AArch64_MemSingle_set__1 (address, size, accdesc_in, aligned, ispair, value_name) = { + assert(size == 1 | size == 2 | size == 4 | size == 8 | size == 16); + accdesc : AccessDescriptor = accdesc_in; + if HaveLSE2Ext() then { + assert(AllInAlignedQuantity(address, size, 16)) + } else { + assert(IsAligned__1(address, size)) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), size) + }; + if HaveTME() then { + if accdesc.transactional & not_bool(MemHasTransactionalAccess(memaddrdesc.memattrs)) then { + FailTransaction(TMFailure_IMP, false) + }; + () + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + if SPESampleInFlight then { + let is_load : bool = false; + SPESampleLoadStore(is_load, accdesc, memaddrdesc) + }; + memstatus : PhysMemRetStatus = undefined; + atomic : bool = undefined; + if (memaddrdesc.memattrs.memtype == MemType_Normal & memaddrdesc.memattrs.inner.attrs == MemAttr_WB) & memaddrdesc.memattrs.outer.attrs == MemAttr_WB then { + atomic = true + } else if (((accdesc.exclusive | accdesc.atomicop) | accdesc.acqsc) | accdesc.acqpc) | accdesc.relsc then { + if not_bool(aligned) & not_bool(ConstrainUnpredictableBool(Unpredictable_MISALIGNEDATOMIC)) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + } else { + atomic = true + } + } else if aligned then { + atomic = not_bool(ispair) + } else { + atomic = __IMPDEF_boolean("FEAT_LSE2: access is atomic") + }; + if atomic then { + let memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, size, accdesc, None(), value_name); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, size, accdesc) + }; + () + } else if aligned & ispair then { + assert(size == 8 | size == 16); + let 'halfsize = DIV(size, 2); + highhalf : bits('halfsize * 8) = undefined; + lowhalf : bits('halfsize * 8) = undefined; + (highhalf @ lowhalf) = value_name; + memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, halfsize, accdesc, None(), lowhalf); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, halfsize, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + halfsize; + let memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, halfsize, accdesc, None(), highhalf); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, halfsize, accdesc) + }; + () + } else { + foreach (i from 0 to (size - 1) by 1 in inc) { + memstatus = PhysMemWrite(memaddrdesc, 1, accdesc, None(), value_name[8 * i + 7 .. 8 * i]); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, 1, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1 + } + }; + return() +} + +val Mem_read : forall 'size, 'size * 8 >= 0. + (bits(64), int('size), AccessDescriptor) -> bits('size * 8) + +val Mem_read__1 : forall ('ispair : Bool) 'size, 'size * 8 >= 0. + (bits(64), int('size), AccessDescriptor, bool('ispair)) -> bits('size * 8) + +val Mem_read__2 : forall ('highestAddressfirst : Bool) ('ispair : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(64), int('size), AccessDescriptor, bool('ispair), bool('highestAddressfirst)) -> bits('size * 8) + +function Mem_read (address, size, accdesc) = { + let ispair : bool = false; + let highestAddressfirst : bool = false; + assert(constraint('size in {1, 2, 4, 8, 16})); + return(Mem_read__2(address, size, accdesc, ispair, highestAddressfirst)) +} + +function Mem_read__1 (address, size, accdesc, ispair) = { + let highestAddressfirst : bool = false; + assert(constraint('size in {1, 2, 4, 8, 16})); + return(Mem_read__2(address, size, accdesc, ispair, highestAddressfirst)) +} + +function Mem_read__2 (address, size, accdesc, ispair, highestAddressfirst) = { + c : Constraint = undefined; + let 'halfsize = DIV(size, 2); + value_name : bits('size * 8) = undefined; + let 'alignment = if ispair then halfsize else size; + aligned : bool = IsAligned__1(address, alignment); + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, size) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + if (accdesc.acctype == AccessType_ASIMD & size == 16) & IsAligned__1(address, 8) then { + let lowhalf : bits('halfsize * 8) = AArch64_MemSingle_read__1(address, halfsize, accdesc, aligned, ispair); + let highhalf : bits('halfsize * 8) = AArch64_MemSingle_read__1(address + halfsize, halfsize, accdesc, aligned, ispair); + value_name = highhalf @ lowhalf + } else if HaveLSE2Ext() & AllInAlignedQuantity(address, size, 16) then { + value_name = AArch64_MemSingle_read__1(address, size, accdesc, aligned, ispair) + } else if ispair & aligned then { + assert(constraint('halfsize in {1, 2, 4, 8})); + highhalf : bits('halfsize * 8) = undefined; + lowhalf : bits('halfsize * 8) = undefined; + if HaveLRCPC3Ext() & highestAddressfirst then { + highhalf = AArch64_MemSingle_read(address + halfsize, halfsize, accdesc, aligned); + lowhalf = AArch64_MemSingle_read(address, halfsize, accdesc, aligned) + } else { + lowhalf = AArch64_MemSingle_read(address, halfsize, accdesc, aligned); + highhalf = AArch64_MemSingle_read(address + halfsize, halfsize, accdesc, aligned) + }; + value_name = highhalf @ lowhalf + } else if aligned then { + value_name = AArch64_MemSingle_read__1(address, size, accdesc, aligned, ispair) + } else { + assert(size > 1); + assert(constraint('halfsize in {1, 2, 4, 8})); + highhalf : bits('halfsize * 8) = undefined; + lowhalf : bits('halfsize * 8) = undefined; + if (HaveLRCPC3Ext() & ispair) & highestAddressfirst then { + foreach (i from 0 to (halfsize - 1) by 1 in inc) { + highhalf[8 * i + 7 .. 8 * i] = AArch64_MemSingle_read(address + halfsize + i, 1, accdesc, aligned) + }; + foreach (i from 0 to (halfsize - 1) by 1 in inc) { + lowhalf[8 * i + 7 .. 8 * i] = AArch64_MemSingle_read(address + i, 1, accdesc, aligned) + }; + value_name = highhalf @ lowhalf + } else { + value_name[7 .. 0] = AArch64_MemSingle_read(address, 1, accdesc, aligned); + let c : Constraint = ConstrainUnpredictable(Unpredictable_DEVPAGE2); + assert(c == Constraint_FAULT | c == Constraint_NONE); + if c == Constraint_NONE then { + aligned = true + }; + foreach (i from 1 to (size - 1) by 1 in inc) { + value_name[8 * i + 7 .. 8 * i] = AArch64_MemSingle_read(address + i, 1, accdesc, aligned) + } + } + }; + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + let value_name = value_name; + return(value_name) +} + +val Mem_set : forall 'size, 'size * 8 >= 0. + (bits(64), int('size), AccessDescriptor, bits('size * 8)) -> unit + +val Mem_set__1 : forall ('ispair : Bool) 'size, 'size * 8 >= 0. + (bits(64), int('size), AccessDescriptor, bool('ispair), bits('size * 8)) -> unit + +val Mem_set__2 : forall ('highestAddressfirst : Bool) ('ispair : Bool) 'size, + 'size * 8 >= 0. + (bits(64), int('size), AccessDescriptor, bool('ispair), bool('highestAddressfirst), bits('size * 8)) -> unit + +function Mem_set (address, size, accdesc, value_in_name) = { + let ispair : bool = false; + let highestAddressfirst : bool = false; + Mem_set__2(address, size, accdesc, ispair, highestAddressfirst) = value_in_name +} + +function Mem_set__1 (address, size, accdesc, ispair, value_in_name) = { + let highestAddressfirst : bool = false; + Mem_set__2(address, size, accdesc, ispair, highestAddressfirst) = value_in_name +} + +function Mem_set__2 (address, size, accdesc, ispair, highestAddressfirst, value_in_name) = { + c : Constraint = undefined; + joinedpair : bool = undefined; + let 'halfsize = DIV(size, 2); + value_name : bits('size * 8) = value_in_name; + let 'alignment = if ispair then halfsize else size; + aligned : bool = IsAligned__1(address, alignment); + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, size) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + if BigEndian(accdesc.acctype) then { + assert(constraint(('size * 8 == 8 | 'size * 8 == 16 | 'size * 8 == 32 | 'size * 8 == 64 | 'size * 8 == 128))); + value_name = BigEndianReverse(value_name) + }; + if (accdesc.acctype == AccessType_ASIMD & size == 16) & IsAligned__1(address, 8) then { + assert(halfsize > 0); + highhalf : bits('halfsize * 8) = undefined; + lowhalf : bits('halfsize * 8) = undefined; + (highhalf @ lowhalf) = value_name; + AArch64_MemSingle_set__1(address, halfsize, accdesc, aligned, ispair) = lowhalf; + AArch64_MemSingle_set__1(address + halfsize, halfsize, accdesc, aligned, ispair) = highhalf + } else if HaveLSE2Ext() & AllInAlignedQuantity(address, size, 16) then { + assert(constraint('size in {1, 2, 4, 8, 16})); + AArch64_MemSingle_set__1(address, size, accdesc, aligned, ispair) = value_name + } else if ispair & aligned then { + let joinedpair : bool = false; + assert(halfsize > 0); + highhalf : bits('halfsize * 8) = undefined; + lowhalf : bits('halfsize * 8) = undefined; + assert(constraint('size * 8 == 'halfsize * 8 + 'halfsize * 8)); + (highhalf @ lowhalf) = value_name; + if HaveLRCPC3Ext() & highestAddressfirst then { + assert(constraint('halfsize in {1, 2, 4, 8, 16})); + AArch64_MemSingle_set__1(address + halfsize, halfsize, accdesc, aligned, joinedpair) = highhalf; + AArch64_MemSingle_set__1(address, halfsize, accdesc, aligned, joinedpair) = lowhalf + } else { + assert(constraint('halfsize in {1, 2, 4, 8, 16})); + AArch64_MemSingle_set__1(address, halfsize, accdesc, aligned, joinedpair) = lowhalf; + AArch64_MemSingle_set__1(address + halfsize, halfsize, accdesc, aligned, joinedpair) = highhalf + } + } else if aligned then { + assert(constraint('size in {1, 2, 4, 8, 16})); + AArch64_MemSingle_set__1(address, size, accdesc, aligned, ispair) = value_name + } else { + assert(size > 1); + highhalf : bits('halfsize * 8) = undefined; + lowhalf : bits('halfsize * 8) = undefined; + if (HaveLRCPC3Ext() & ispair) & highestAddressfirst then { + assert(constraint('size * 8 == 'halfsize * 8 + 'halfsize * 8)); + (highhalf @ lowhalf) = value_name; + foreach (i from 0 to (halfsize - 1) by 1 in inc) { + AArch64_MemSingle_set(address + halfsize + i, 1, accdesc, aligned) = highhalf[8 * i + 7 .. 8 * i] + }; + foreach (i from 0 to (halfsize - 1) by 1 in inc) { + AArch64_MemSingle_set(address + i, 1, accdesc, aligned) = lowhalf[8 * i + 7 .. 8 * i] + } + } else { + AArch64_MemSingle_set(address, 1, accdesc, aligned) = value_name[7 .. 0]; + let c : Constraint = ConstrainUnpredictable(Unpredictable_DEVPAGE2); + assert(c == Constraint_FAULT | c == Constraint_NONE); + if c == Constraint_NONE then { + aligned = true + }; + foreach (i from 1 to (size - 1) by 1 in inc) { + AArch64_MemSingle_set(address + i, 1, accdesc, aligned) = value_name[8 * i + 7 .. 8 * i] + } + } + }; + return() +} + +val MemAtomic : forall 'size, 'size >= 0. + (bits(64), bits('size), bits('size), AccessDescriptor) -> bits('size) + +function MemAtomic (address, cmpoperand, operand, accdesc_in) = { + assert(accdesc_in.atomicop); + let 'bytes = DIV('size, 8); + assert(bytes == 1 | bytes == 2 | bytes == 4 | bytes == 8 | bytes == 16); + newvalue : bits('size) = undefined; + oldvalue : bits('size) = undefined; + accdesc : AccessDescriptor = accdesc_in; + let aligned : bool = IsAligned__1(address, bytes); + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, bytes) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, 'size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), 'size) + }; + if (HaveMTE2Ext() & accdesc.tagchecked) & (not_bool(HaveMTEStoreOnlyExt()) | not_bool(StoreOnlyTagCheckingEnabled(accdesc.el))) then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + memstatus : PhysMemRetStatus = undefined; + assert(constraint(8 * 'bytes == 'size)); + (memstatus, oldvalue) = PhysMemRead(memaddrdesc, bytes, accdesc, None()); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, bytes, accdesc) + }; + if BigEndian(accdesc.acctype) then { + oldvalue = BigEndianReverse(oldvalue) + }; + let oldvalue = oldvalue; + cmpfail : bool = false; + match accdesc.modop { + MemAtomicOp_ADD => { + newvalue = oldvalue + operand + }, + MemAtomicOp_BIC => { + newvalue = oldvalue & not_vec(operand) + }, + MemAtomicOp_EOR => { + newvalue = EOR(oldvalue, operand) + }, + MemAtomicOp_ORR => { + newvalue = oldvalue | operand + }, + MemAtomicOp_SMAX => { + newvalue = Max(SInt(oldvalue), SInt(operand))['size - 1 .. 0] + }, + MemAtomicOp_SMIN => { + newvalue = Min(SInt(oldvalue), SInt(operand))['size - 1 .. 0] + }, + MemAtomicOp_UMAX => { + newvalue = Max(UInt(oldvalue), UInt(operand))['size - 1 .. 0] + }, + MemAtomicOp_UMIN => { + newvalue = Min(UInt(oldvalue), UInt(operand))['size - 1 .. 0] + }, + MemAtomicOp_SWP => { + newvalue = operand + }, + MemAtomicOp_CAS => { + newvalue = operand; + cmpfail = cmpoperand != oldvalue + }, + MemAtomicOp_GCSSS1 => { + newvalue = operand; + cmpfail = cmpoperand != oldvalue + }, + _ => () + }; + if HaveMTEStoreOnlyExt() & StoreOnlyTagCheckingEnabled(accdesc.el) then { + if accdesc.tagchecked & cmpfail then { + accdesc.tagchecked = ConstrainUnpredictableBool(Unpredictable_STOREONLYTAGCHECKEDCAS) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + accdesc.read = false; + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + () + }; + if not_bool(cmpfail) then { + if BigEndian(accdesc.acctype) then { + newvalue = BigEndianReverse(newvalue) + }; + let memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, bytes, accdesc, None(), newvalue); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, bytes, accdesc) + }; + () + }; + if SPESampleInFlight then { + let is_load : bool = false; + SPESampleLoadStore(is_load, accdesc, memaddrdesc) + }; + return(oldvalue) +} + +val IsD128Enabled : bits(2) -> bool + +function IsD128Enabled el = { + d128enabled : bool = undefined; + if Have128BitDescriptorExt() then { + match el { + ? if ? == EL0 => { + if not_bool(ELIsInHost(EL0)) then { + d128enabled = IsTCR2EL1Enabled() & TCR2_EL1[D128] == 0b1 + } else { + d128enabled = IsTCR2EL2Enabled() & TCR2_EL2[D128] == 0b1 + } + }, + ? if ? == EL1 => { + d128enabled = IsTCR2EL1Enabled() & TCR2_EL1[D128] == 0b1 + }, + ? if ? == EL2 => { + d128enabled = (IsTCR2EL2Enabled() & HCR_EL2[E2H] == 0b1) & TCR2_EL2[D128] == 0b1 + }, + ? if ? == EL3 => { + d128enabled = TCR_EL3[D128] == 0b1 + }, + _ => () + } + } else { + d128enabled = false + }; + return(d128enabled) +} + +val ProtectionEnabled : bits(2) -> bool + +function ProtectionEnabled el = { + assert(HaveEL(el)); + let regime : bits(2) = S1TranslationRegime(el); + assert(not_bool(ELUsingAArch32(regime))); + if not_bool(IsD128Enabled(el)) then { + match regime { + ? if ? == EL1 => { + return(IsTCR2EL1Enabled() & TCR2_EL1[PnCH] == 0b1) + }, + ? if ? == EL2 => { + return(IsTCR2EL2Enabled() & TCR2_EL2[PnCH] == 0b1) + }, + ? if ? == EL3 => { + return(TCR_EL3[PnCH] == 0b1) + }, + _ => () + } + } else { + return(true) + }; + return(false) +} + +bitfield RCWMASK_EL1_Type : bits(128) = {Mask : 127..0} + +register RCWMASK_EL1 : RCWMASK_EL1_Type + +bitfield RCWSMASK_EL1_Type : bits(128) = {Software_Mask : 127..0} + +register RCWSMASK_EL1 : RCWSMASK_EL1_Type + +val RCWCheck : forall 'N ('soft : Bool), 'N in {64, 128}. + (bits('N), bits('N), bool('soft)) -> bits(4) + +function RCWCheck (old, new, soft) = { + assert('N == 64 | 'N == 128); + let 'protectedbit = if 'N == 128 then RCW128_PROTECTED_BIT else + RCW64_PROTECTED_BIT; + rcw_fail : bool = false; + rcws_fail : bool = false; + rcw_state_fail : bool = false; + rcws_state_fail : bool = false; + rcw_mask_fail : bool = false; + rcws_mask_fail : bool = false; + rcwmask : bits('N) = RCWMASK_EL1.bits['N - 1 .. 0]; + if 'N == 64 then { + rcwmask[49 .. 18] = Replicate([rcwmask[17]], 32); + rcwmask[0] = Bit(0b0) + } else { + rcwmask[55 .. 17] = Replicate([rcwmask[16]], 39); + (rcwmask[126 .. 125] @ rcwmask[120 .. 119] @ rcwmask[107 .. 101] @ rcwmask[90 .. 56] @ rcwmask[1 .. 0]) = Zeros(48) + }; + rcwsoftmask : bits('N) = RCWSMASK_EL1.bits['N - 1 .. 0]; + if 'N == 64 then { + rcwsoftmask[49 .. 18] = Replicate([rcwsoftmask[17]], 32); + rcwsoftmask[0] = Bit(0b0); + if ProtectionEnabled(PSTATE.EL) then { + rcwsoftmask[52] = Bit(0b0) + }; + () + } else { + rcwsoftmask[55 .. 17] = Replicate([rcwsoftmask[16]], 39); + (rcwsoftmask[126 .. 125] @ rcwsoftmask[120 .. 119] @ rcwsoftmask[107 .. 101] @ rcwsoftmask[90 .. 56] @ rcwsoftmask[1 .. 0]) = Zeros(48); + rcwsoftmask[114] = Bit(0b0) + }; + if ProtectionEnabled(PSTATE.EL) then { + assert(constraint((0 <= 'protectedbit & 'protectedbit < 'N))); + if [old[protectedbit]] == 0b1 then { + rcw_state_fail = ([new[protectedbit]] @ [new[0]]) != ([old[protectedbit]] @ [old[0]]) + } else if [old[protectedbit]] == 0b0 then { + rcw_state_fail = [new[protectedbit]] != [old[protectedbit]] + } else () + }; + if ProtectionEnabled(PSTATE.EL) then { + assert(constraint((0 <= 'protectedbit & 'protectedbit < 'N))); + if ([old[protectedbit]] @ [old[0]]) == 0b11 then { + rcw_mask_fail = not_bool(IsZero(EOR(new, old) & not_vec(rcwmask))) + }; + () + }; + if soft then { + if [old[0]] == 0b1 then { + rcws_state_fail = [new[0]] != [old[0]] + } else { + assert(constraint((0 <= 'protectedbit & 'protectedbit < 'N))); + if not_bool(ProtectionEnabled(PSTATE.EL)) | ProtectionEnabled(PSTATE.EL) & [old[protectedbit]] == 0b0 then { + rcws_state_fail = [new[0]] != [old[0]] + }; + () + }; + if [old[0]] == 0b1 then { + rcws_mask_fail = not_bool(IsZero(EOR(new, old) & not_vec(rcwsoftmask))) + }; + () + }; + let rcw_fail : bool = rcw_state_fail | rcw_mask_fail; + let rcws_fail : bool = rcws_state_fail | rcws_mask_fail; + let n : bits(1) = 0b0; + let z : bits(1) = if rcw_fail then 0b1 else 0b0; + let c : bits(1) = if rcws_fail then 0b0 else 0b1; + let v : bits(1) = 0b0; + return(((n @ z) @ c) @ v) +} + +val MemAtomicRCW : forall 'size, 'size >= 0. + (bits(64), bits('size), bits('size), AccessDescriptor) -> (bits(4), bits('size)) + +function MemAtomicRCW (address, cmpoperand, operand, accdesc_in) = { + assert(accdesc_in.atomicop); + assert(accdesc_in.rcw); + let 'bytes = DIV('size, 8); + assert(bytes == 8 | bytes == 16); + nzcv : bits(4) = undefined; + oldvalue : bits('size) = undefined; + newvalue : bits('size) = undefined; + accdesc : AccessDescriptor = accdesc_in; + let aligned : bool = IsAligned__1(address, bytes); + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, bytes) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, 'size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), 'size) + }; + if (HaveMTE2Ext() & accdesc.tagchecked) & (not_bool(HaveMTEStoreOnlyExt()) | not_bool(StoreOnlyTagCheckingEnabled(accdesc.el))) then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + memstatus : PhysMemRetStatus = undefined; + assert(constraint(8 * 'bytes == 'size)); + (memstatus, oldvalue) = PhysMemRead(memaddrdesc, bytes, accdesc, None()); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, bytes, accdesc) + }; + if BigEndian(accdesc.acctype) then { + oldvalue = BigEndianReverse(oldvalue) + }; + let oldvalue = oldvalue; + cmpfail : bool = false; + match accdesc.modop { + MemAtomicOp_BIC => { + newvalue = oldvalue & not_vec(operand) + }, + MemAtomicOp_ORR => { + newvalue = oldvalue | operand + }, + MemAtomicOp_SWP => { + newvalue = operand + }, + MemAtomicOp_CAS => { + newvalue = operand; + cmpfail = oldvalue != cmpoperand + }, + _ => () + }; + if cmpfail then { + nzcv = 0b1010 + } else { + nzcv = RCWCheck(oldvalue, newvalue, accdesc.rcws) + }; + if HaveMTEStoreOnlyExt() & StoreOnlyTagCheckingEnabled(accdesc.el) then { + if accdesc.tagchecked & cmpfail then { + accdesc.tagchecked = ConstrainUnpredictableBool(Unpredictable_STOREONLYTAGCHECKEDCAS) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + accdesc.read = false; + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + () + }; + if nzcv == 0b0010 then { + if BigEndian(accdesc.acctype) then { + newvalue = BigEndianReverse(newvalue) + }; + let memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, bytes, accdesc, None(), newvalue); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, bytes, accdesc) + }; + () + }; + return((nzcv, oldvalue)) +} + +val AArch64_AddressWithAllocationTag : (bits(64), bits(4)) -> bits(64) + +function AArch64_AddressWithAllocationTag (address, allocation_tag) = { + result : bits(64) = address; + tag : bits(4) = undefined; + if AArch64_AllocationTagAccessIsEnabled(PSTATE.EL) then { + tag = allocation_tag + } else { + tag = 0b0000 + }; + result[59 .. 56] = tag; + return(result) +} + +val AArch64_AllocationTagFromAddress : bits(64) -> bits(4) + +function AArch64_AllocationTagFromAddress tagged_address = { + return(tagged_address[59 .. 56]) +} + +val AArch64_MemTag_read : (bits(64), AccessDescriptor) -> bits(4) + +function AArch64_MemTag_read (address, accdesc_in) = { + memstatus : PhysMemRetStatus = undefined; + tag : bits(4) = undefined; + assert(accdesc_in.tagaccess & not_bool(accdesc_in.tagchecked)); + accdesc : AccessDescriptor = accdesc_in; + let aligned : bool = true; + if HaveMTE2Ext() then { + accdesc.tagaccess = AArch64_AllocationTagAccessIsEnabled(accdesc.el) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, TAG_GRANULE); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if accdesc.tagaccess & memaddrdesc.memattrs.tags == MemTag_AllocationTagged then { + (memstatus, tag) = PhysMemTagRead(memaddrdesc, accdesc); + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, 1, accdesc) + }; + return(tag) + } else if (HaveMTECanonicalTagCheckingExt() & accdesc.tagaccess) & memaddrdesc.memattrs.tags == MemTag_CanonicallyTagged then { + return(if [address[55]] == 0b0 then 0b0000 else 0b1111) + } else { + return(0b0000) + } +} + +val PhysMemTagWrite : (AddressDescriptor, AccessDescriptor, bits(4)) -> PhysMemRetStatus + +val AArch64_MemTag_set : (bits(64), AccessDescriptor, bits(4)) -> unit + +function AArch64_MemTag_set (address, accdesc_in, value_name) = { + memstatus : PhysMemRetStatus = undefined; + assert(accdesc_in.tagaccess & not_bool(accdesc_in.tagchecked)); + accdesc : AccessDescriptor = accdesc_in; + let aligned : bool = IsAligned__1(address, TAG_GRANULE); + if not_bool(aligned) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + if HaveMTE2Ext() then { + accdesc.tagaccess = AArch64_AllocationTagAccessIsEnabled(accdesc.el) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, TAG_GRANULE); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if accdesc.tagaccess & memaddrdesc.memattrs.tags == MemTag_AllocationTagged then { + let memstatus : PhysMemRetStatus = PhysMemTagWrite(memaddrdesc, accdesc, value_name); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, 1, accdesc) + }; + () + }; + () +} + +bitfield VNCR_EL2_Type : bits(64) = {RESS : 63..57, BADDR : 56..12} + +register VNCR_EL2 : VNCR_EL2_Type + +val NVMem_read : forall 'offset. int('offset) -> bits(64) + +val NVMem_read__1 : forall 'N 'offset, 'N in {64, 128}. + (int('offset), int('N)) -> bits('N) + +function NVMem_read offset = { + assert(offset > 0); + let 'size = 64; + return(NVMem_read__1(offset, size)) +} + +function NVMem_read__1 (offset, N) = { + assert(offset > 0); + assert(N == 64 | N == 128); + let address : bits(64) = SignExtend(VNCR_EL2[BADDR] @ offset[11 .. 0], 64); + let accdesc : AccessDescriptor = CreateAccDescNV2(MemOp_LOAD); + return(Mem_read(address, DIV(N, 8), accdesc)) +} + +val NVMem_set : forall 'offset. (int('offset), bits(64)) -> unit + +val NVMem_set__1 : forall 'N 'offset, 'N in {64, 128}. + (int('offset), int('N), bits('N)) -> unit + +function NVMem_set (offset, value_name) = { + assert(offset > 0); + let 'size = 64; + NVMem_set__1(offset, size) = value_name; + return() +} + +function NVMem_set__1 (offset, N, value_name) = { + assert(offset > 0); + assert(N == 64 | N == 128); + let address : bits(64) = SignExtend(VNCR_EL2[BADDR] @ offset[11 .. 0], 64); + let accdesc : AccessDescriptor = CreateAccDescNV2(MemOp_STORE); + Mem_set(address, DIV(N, 8), accdesc) = value_name; + return() +} + +val AddressSupportsLS64 : bits(56) -> bool + +val MemStore64B : (bits(64), bits(512), AccessDescriptor) -> unit + +function MemStore64B (address, value_name, accdesc_in) = { + c : Constraint = undefined; + let 'size = 64; + accdesc : AccessDescriptor = accdesc_in; + let aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, size) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), 64) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + memstatus : PhysMemRetStatus = undefined; + if not_bool(AddressSupportsLS64(memaddrdesc.paddress.address)) then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LS64UNSUPPORTED); + assert(c == Constraint_LIMITED_ATOMICITY | c == Constraint_FAULT); + if c == Constraint_FAULT then { + AArch64_Abort(address, ExclusiveFault(accdesc)) + } else { + foreach (i from 0 to (size - 1) by 1 in inc) { + memstatus = PhysMemWrite(memaddrdesc, 1, accdesc, None(), value_name[8 * i + 7 .. 8 * i]); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, 1, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1 + } + } + } else { + let memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, size, accdesc, None(), value_name); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, size, accdesc) + }; + () + }; + return() +} + +val MemStore64BWithRet : (bits(64), bits(512), AccessDescriptor) -> bits(64) + +function MemStore64BWithRet (address, value_name, accdesc_in) = { + let 'size = 64; + accdesc : AccessDescriptor = accdesc_in; + let aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, size) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault); + return(ZeroExtend(0b1, 64)) + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), 64) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + AArch64_TagCheckFault(address, accdesc); + return(ZeroExtend(0b1, 64)) + }; + () + }; + let memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, size, accdesc, None(), value_name); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, size, accdesc) + }; + return(memstatus.store64bstatus) +} + +val MemLoad64B : (bits(64), AccessDescriptor) -> bits(512) + +function MemLoad64B (address, accdesc_in) = { + c : Constraint = undefined; + data : bits(512) = undefined; + let 'size = 64; + accdesc : AccessDescriptor = accdesc_in; + let aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, size) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), size) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + AArch64_TagCheckFault(address, accdesc) + }; + () + }; + if not_bool(AddressSupportsLS64(memaddrdesc.paddress.address)) then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_LS64UNSUPPORTED); + assert(c == Constraint_LIMITED_ATOMICITY | c == Constraint_FAULT); + if c == Constraint_FAULT then { + AArch64_Abort(address, ExclusiveFault(accdesc)) + } else { + foreach (i from 0 to (size - 1) by 1 in inc) { + memstatus : PhysMemRetStatus = undefined; + (memstatus, data[8 * i + 7 .. 8 * i]) = PhysMemRead(memaddrdesc, 1, accdesc, None()); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, 1, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1 + } + } + } else { + memstatus : PhysMemRetStatus = undefined; + (memstatus, data) = PhysMemRead(memaddrdesc, size, accdesc, None()); + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, size, accdesc) + }; + () + }; + return(data) +} + +val AArch64_IsUnprivAccessPriv : unit -> bool + +function AArch64_IsUnprivAccessPriv () = { + privileged : bool = undefined; + match PSTATE.EL { + ? if ? == EL0 => { + privileged = false + }, + ? if ? == EL1 => { + privileged = (EL2Enabled() & HaveNVExt()) & (HCR_EL2[NV] @ HCR_EL2[NV1]) == 0b11 + }, + ? if ? == EL2 => { + privileged = not_bool(HaveVirtHostExt() & (HCR_EL2[E2H] @ HCR_EL2[TGE]) == 0b11) + }, + ? if ? == EL3 => { + privileged = true + }, + _ => () + }; + if HaveUAOExt() & PSTATE.UAO == 0b1 then { + privileged = PSTATE.EL != EL0 + }; + let privileged = privileged; + return(privileged) +} + +val AArch64_DataMemZero : forall 'size. + (bits(64), bits(64), AccessDescriptor, int('size)) -> unit + +function AArch64_DataMemZero (regval, vaddress, accdesc_in, size) = { + memstatus : PhysMemRetStatus = undefined; + accdesc : AccessDescriptor = accdesc_in; + if HaveMTE2Ext() & accdesc.tagaccess then { + accdesc.tagaccess = AArch64_AllocationTagAccessIsEnabled(accdesc.el) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(vaddress, accdesc) + }; + let aligned : bool = true; + memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(vaddress, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + if IsDebugException(memaddrdesc.fault) then { + AArch64_Abort(vaddress, memaddrdesc.fault) + } else { + AArch64_Abort(regval, memaddrdesc.fault) + } + }; + if HaveTME() then { + if accdesc.transactional & not_bool(MemHasTransactionalAccess(memaddrdesc.memattrs)) then { + FailTransaction(TMFailure_IMP, false) + }; + () + }; + foreach (i from 0 to (size - 1) by 1 in inc) { + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(vaddress); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + if __IMPDEF_boolean("DC_ZVA tag fault reported with lowest faulting address") then { + AArch64_TagCheckFault(vaddress, accdesc) + } else { + AArch64_TagCheckFault(regval, accdesc) + } + }; + () + }; + memstatus = PhysMemWrite(memaddrdesc, 1, accdesc, None(), Zeros(8)); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, 1, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1 + }; + return() +} + +val AArch64_TagMemZero : forall 'size. + (bits(64), bits(64), AccessDescriptor, int('size)) -> unit + +function AArch64_TagMemZero (regval, vaddress, accdesc_in, size) = { + memstatus : PhysMemRetStatus = undefined; + assert(accdesc_in.tagaccess & not_bool(accdesc_in.tagchecked)); + accdesc : AccessDescriptor = accdesc_in; + let 'count = (size >> LOG2_TAG_GRANULE); + let tag : bits(4) = AArch64_AllocationTagFromAddress(vaddress); + let aligned : bool = IsAligned__1(vaddress, TAG_GRANULE); + if not_bool(aligned) then { + AArch64_Abort(vaddress, AlignmentFault(accdesc)) + }; + if HaveMTE2Ext() then { + accdesc.tagaccess = AArch64_AllocationTagAccessIsEnabled(accdesc.el) + }; + memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(vaddress, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + if IsDebugException(memaddrdesc.fault) then { + AArch64_Abort(vaddress, memaddrdesc.fault) + } else { + AArch64_Abort(regval, memaddrdesc.fault) + } + }; + if not_bool(accdesc.tagaccess) | memaddrdesc.memattrs.tags != MemTag_AllocationTagged then { + return() + }; + foreach (i from 0 to (count - 1) by 1 in inc) { + memstatus = PhysMemTagWrite(memaddrdesc, accdesc, tag); + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, 1, accdesc) + }; + memaddrdesc.paddress.address = memaddrdesc.paddress.address + TAG_GRANULE + }; + return() +} + +val AArch64_IsExclusiveVA : forall 'processorid 'size. + (bits(64), int('processorid), int('size)) -> bool + +val AArch64_MarkExclusiveVA : forall 'processorid 'size. + (bits(64), int('processorid), int('size)) -> unit + +val AArch64_SetExclusiveMonitors : forall 'size. (bits(64), int('size)) -> unit + +function AArch64_SetExclusiveMonitors (address, size) = { + __ExclusiveMonitorSet = true; + let acqrel : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescExLDST(MemOp_LOAD, acqrel, tagchecked); + let aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, size) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + return() + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + MarkExclusiveGlobal(memaddrdesc.paddress, ProcessorID(), size) + }; + MarkExclusiveLocal(memaddrdesc.paddress, ProcessorID(), size); + AArch64_MarkExclusiveVA(address, ProcessorID(), size) +} + +val AArch64_ExclusiveMonitorsPass : forall 'size. (bits(64), int('size)) -> bool + +function AArch64_ExclusiveMonitorsPass (address, size) = { + let acqrel : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescExLDST(MemOp_STORE, acqrel, tagchecked); + let aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) & AArch64_UnalignedAccessFaults(accdesc, address, size) then { + AArch64_Abort(address, AlignmentFault(accdesc)) + }; + if not_bool(AArch64_IsExclusiveVA(address, ProcessorID(), size)) then { + return(false) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(address, memaddrdesc.fault) + }; + passed : bool = IsExclusiveLocal(memaddrdesc.paddress, ProcessorID(), size); + ClearExclusiveLocal(ProcessorID()); + if passed & memaddrdesc.memattrs.shareability != Shareability_NSH then { + passed = IsExclusiveGlobal(memaddrdesc.paddress, ProcessorID(), size) + }; + return(passed) +} + +val FPRecipStepFused : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N)) -> bits('N) + +function FPRecipStepFused (op1_in, op2) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + result_value : real = undefined; + sign : bits(1) = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + op1 : bits('N) = op1_in; + result : bits('N) = undefined; + done : bool = undefined; + fpcr : FPCRType = FPCR_read(); + let op1 : bits('N) = FPNeg(op1); + let altfp : bool = HaveAltFP() & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + if altfp then { + (fpcr[FIZ] @ fpcr[FZ]) = 0b11 + }; + if altfp then { + fpcr[RMode] = 0b00 + }; + (type1, sign1, value1_name) = FPUnpack__1(op1, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2, fpcr, fpexc); + (done, result) = FPProcessNaNs__1(type1, type2, op1, op2, fpcr, fpexc); + let rounding : FPRounding = FPRoundingMode(fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if inf1 & zero2 | zero1 & inf2 then { + result = FPTwo(0b0, 'N) + } else if inf1 | inf2 then { + result = FPInfinity(EOR(sign1, sign2), 'N) + } else { + let result_value : real = 2.0 + value1_name * value2_name; + if result_value == 0.0 then { + let sign : bits(1) = if rounding == FPRounding_NEGINF then 0b1 + else + 0b0; + result = FPZero(sign, 'N) + } else { + result = FPRound__2(result_value, fpcr, rounding, fpexc, 'N) + } + } + }; + return(result) +} + +val FPRSqrtStepFused : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N)) -> bits('N) + +function FPRSqrtStepFused (op1_in, op2) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + result_value : real = undefined; + sign : bits(1) = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('N) = undefined; + op1 : bits('N) = op1_in; + done : bool = undefined; + fpcr : FPCRType = FPCR_read(); + let op1 : bits('N) = FPNeg(op1); + let altfp : bool = HaveAltFP() & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + if altfp then { + (fpcr[FIZ] @ fpcr[FZ]) = 0b11 + }; + if altfp then { + fpcr[RMode] = 0b00 + }; + (type1, sign1, value1_name) = FPUnpack__1(op1, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2, fpcr, fpexc); + (done, result) = FPProcessNaNs__1(type1, type2, op1, op2, fpcr, fpexc); + let rounding : FPRounding = FPRoundingMode(fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if inf1 & zero2 | zero1 & inf2 then { + result = FPOnePointFive(0b0, 'N) + } else if inf1 | inf2 then { + result = FPInfinity(EOR(sign1, sign2), 'N) + } else { + let result_value : real = (3.0 + value1_name * value2_name) / 2.0; + if result_value == 0.0 then { + let sign : bits(1) = if rounding == FPRounding_NEGINF then 0b1 + else + 0b0; + result = FPZero(sign, 'N) + } else { + result = FPRound__2(result_value, fpcr, rounding, fpexc, 'N) + } + } + }; + return(result) +} + +val AArch64_AdvSIMDFPAccessTrap : bits(2) -> unit + +function AArch64_AdvSIMDFPAccessTrap target_el = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + except : ExceptionRecord = undefined; + let 'vect_offset = UInt(0x0); + let route_to_el2 : bool = (target_el == EL1 & EL2Enabled()) & HCR_EL2[TGE] == 0b1; + if route_to_el2 then { + let except : ExceptionRecord = ExceptionSyndrome(Exception_Uncategorized); + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + except : ExceptionRecord = ExceptionSyndrome(Exception_AdvSIMDFPAccessTrap); + except.syndrome[24 .. 20] = ConditionSyndrome(); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) + }; + return() +} + +val SVEAccessTrap : bits(2) -> unit + +function SVEAccessTrap target_el = { + assert((UInt(target_el) >= UInt(PSTATE.EL) & target_el != EL0) & HaveEL(target_el)); + let route_to_el2 : bool = (target_el == EL1 & EL2Enabled()) & HCR_EL2[TGE] == 0b1; + let except : ExceptionRecord = ExceptionSyndrome(Exception_SVEAccessTrap); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) + } +} + +val CheckOriginalSVEEnabled : unit -> unit + +function CheckOriginalSVEEnabled () = { + assert(HaveSVE()); + disabled : bool = undefined; + if (HaveEL(EL3) & (CPTR_EL3[EZ] == 0b0 | CPTR_EL3[TFP] == 0b1)) & EL3SDDUndefPriority() then { + throw(Error_Undefined()) + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & not_bool(IsInHost()) then { + match CPACR_EL1[ZEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + SVEAccessTrap(EL1) + }; + match CPACR_EL1[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + AArch64_AdvSIMDFPAccessTrap(EL1) + }; + () + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1 | PSTATE.EL == EL2) & EL2Enabled() then { + if HaveVirtHostExt() & HCR_EL2[E2H] == 0b1 then { + match CPTR_EL2[ZEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + SVEAccessTrap(EL2) + }; + match CPTR_EL2[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + AArch64_AdvSIMDFPAccessTrap(EL2) + }; + () + } else { + if CPTR_EL2[TZ] == 0b1 then { + SVEAccessTrap(EL2) + }; + if CPTR_EL2[TFP] == 0b1 then { + AArch64_AdvSIMDFPAccessTrap(EL2) + }; + () + } + }; + if HaveEL(EL3) then { + if CPTR_EL3[EZ] == 0b0 then { + if EL3SDDUndef() then { + throw(Error_Undefined()) + } else { + SVEAccessTrap(EL3) + } + }; + if CPTR_EL3[TFP] == 0b1 then { + if EL3SDDUndef() then { + throw(Error_Undefined()) + } else { + AArch64_AdvSIMDFPAccessTrap(EL3) + } + }; + () + }; + () +} + +val SMEAccessTrap : (SMEExceptionType, bits(2)) -> unit + +function SMEAccessTrap (etype, target_el_in) = { + target_el : bits(2) = target_el_in; + assert(UInt(target_el) >= UInt(PSTATE.EL)); + if target_el == EL0 then { + target_el = EL1 + }; + let route_to_el2 : bool = ((PSTATE.EL == EL0 & target_el == EL1) & EL2Enabled()) & HCR_EL2[TGE] == 0b1; + except : ExceptionRecord = ExceptionSyndrome(Exception_SMEAccessTrap); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + match etype { + SMEExceptionType_AccessTrap => { + except.syndrome[2 .. 0] = 0b000 + }, + SMEExceptionType_Streaming => { + except.syndrome[2 .. 0] = 0b001 + }, + SMEExceptionType_NotStreaming => { + except.syndrome[2 .. 0] = 0b010 + }, + SMEExceptionType_InactiveZA => { + except.syndrome[2 .. 0] = 0b011 + }, + SMEExceptionType_InaccessibleZT0 => { + except.syndrome[2 .. 0] = 0b100 + } + }; + if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) + } +} + +val CheckSMEEnabled : unit -> unit + +function CheckSMEEnabled () = { + disabled : bool = undefined; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & not_bool(IsInHost()) then { + match CPACR_EL1[SMEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL1) + }; + match CPACR_EL1[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + AArch64_AdvSIMDFPAccessTrap(EL1) + }; + () + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1 | PSTATE.EL == EL2) & EL2Enabled() then { + if HaveVirtHostExt() & HCR_EL2[E2H] == 0b1 then { + match CPTR_EL2[SMEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL2) + }; + match CPTR_EL2[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + AArch64_AdvSIMDFPAccessTrap(EL2) + }; + () + } else { + if CPTR_EL2[TSM] == 0b1 then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL2) + }; + if CPTR_EL2[TFP] == 0b1 then { + AArch64_AdvSIMDFPAccessTrap(EL2) + }; + () + } + }; + if HaveEL(EL3) then { + if CPTR_EL3[ESM] == 0b0 then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL3) + }; + if CPTR_EL3[TFP] == 0b1 then { + AArch64_AdvSIMDFPAccessTrap(EL3) + }; + () + }; + () +} + +val CheckStreamingSVEEnabled : unit -> unit + +function CheckStreamingSVEEnabled () = { + CheckSMEEnabled(); + if PSTATE.SM == 0b0 then { + SMEAccessTrap(SMEExceptionType_NotStreaming, PSTATE.EL) + }; + () +} + +val CheckSVEEnabled : unit -> unit + +function CheckSVEEnabled () = { + if HaveSME() & PSTATE.SM == 0b1 then { + CheckSMEEnabled() + } else if HaveSME() & not_bool(HaveSVE()) then { + CheckStreamingSVEEnabled() + } else { + CheckOriginalSVEEnabled() + } +} + +val CheckSMEAndZAEnabled : unit -> unit + +function CheckSMEAndZAEnabled () = { + CheckSMEEnabled(); + if PSTATE.ZA == 0b0 then { + SMEAccessTrap(SMEExceptionType_InactiveZA, PSTATE.EL) + }; + () +} + +val CheckNonStreamingSVEEnabled : unit -> unit + +function CheckNonStreamingSVEEnabled () = { + CheckSVEEnabled(); + if (HaveSME() & PSTATE.SM == 0b1) & not_bool(IsFullA64Enabled()) then { + SMEAccessTrap(SMEExceptionType_Streaming, PSTATE.EL) + }; + () +} + +val CheckStreamingSVEAndZAEnabled : unit -> unit + +function CheckStreamingSVEAndZAEnabled () = { + CheckStreamingSVEEnabled(); + if PSTATE.ZA == 0b0 then { + SMEAccessTrap(SMEExceptionType_InactiveZA, PSTATE.EL) + }; + () +} + +val CheckSMEZT0Enabled : unit -> unit + +function CheckSMEZT0Enabled () = { + if PSTATE.ZA == 0b0 then { + SMEAccessTrap(SMEExceptionType_InactiveZA, PSTATE.EL) + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & not_bool(IsInHost()) then { + if SMCR_EL1[EZT0] == 0b0 then { + SMEAccessTrap(SMEExceptionType_InaccessibleZT0, EL1) + }; + () + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1 | PSTATE.EL == EL2) & EL2Enabled() then { + if SMCR_EL2[EZT0] == 0b0 then { + SMEAccessTrap(SMEExceptionType_InaccessibleZT0, EL2) + }; + () + }; + if HaveEL(EL3) then { + if SMCR_EL3[EZT0] == 0b0 then { + SMEAccessTrap(SMEExceptionType_InaccessibleZT0, EL3) + }; + () + }; + () +} + +val CheckSMEAccess : unit -> unit + +function CheckSMEAccess () = { + disabled : bool = undefined; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & not_bool(IsInHost()) then { + match CPACR_EL1[SMEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL1) + }; + () + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1 | PSTATE.EL == EL2) & EL2Enabled() then { + if HaveVirtHostExt() & HCR_EL2[E2H] == 0b1 then { + match CPTR_EL2[SMEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + if disabled then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL2) + }; + () + } else { + if CPTR_EL2[TSM] == 0b1 then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL2) + }; + () + } + }; + if HaveEL(EL3) then { + if CPTR_EL3[ESM] == 0b0 then { + SMEAccessTrap(SMEExceptionType_AccessTrap, EL3) + }; + () + }; + () +} + +val ResetSMEState : unit -> unit + +function ResetSMEState () = { + let 'vectors_name = DIV(MAX_VL, 8); + foreach (n from 0 to (vectors_name - 1) by 1 in inc) { + _ZA[n] = Zeros(MAX_VL) + }; + _ZT0 = Zeros(ZT0_LEN) +} + +val SetPSTATE_SM : bits(1) -> unit + +function SetPSTATE_SM value_name = { + if PSTATE.SM != value_name then { + ResetSVEState(); + PSTATE.SM = value_name + }; + () +} + +val SetPSTATE_ZA : bits(1) -> unit + +function SetPSTATE_ZA value_name = { + if PSTATE.ZA != value_name then { + ResetSMEState(); + PSTATE.ZA = value_name + }; + () +} + +val SetPSTATE_SVCR : bits(32) -> unit + +function SetPSTATE_SVCR svcr = { + SetPSTATE_SM([svcr[0]]); + SetPSTATE_ZA([svcr[1]]) +} + +val Z_read : forall 'n 'width, 'width >= 0. + (int('n), int('width)) -> bits('width) + +function Z_read (n, width) = { + let 'VL = CurrentVL_read(); + assert(n >= 0 & n <= 31); + assert(width == VL); + return(_Z[n][width - 1 .. 0]) +} + +val P_read : forall 'n 'width, + 'width >= 0 & ('n < 16 | not(('n >= 0 & 'n <= 31))). + (int('n), int('width)) -> bits('width) + +function P_read (n, width) = { + let 'VL = CurrentVL_read(); + assert(n >= 0 & n <= 31); + assert(width == DIV(VL, 8)); + return(_P[n][width - 1 .. 0]) +} + +val FFR_read : forall 'width, 'width >= 0. int('width) -> bits('width) + +function FFR_read width = { + let 'VL = CurrentVL_read(); + assert(width == DIV(VL, 8)); + return(_FFR[width - 1 .. 0]) +} + +val MemSingleNF_read : forall ('aligned : Bool) 'size, 'size > 0. + (bits(64), int('size), AccessDescriptor, bool('aligned)) -> (bits(8 * 'size), bool) + +function MemSingleNF_read (address, size, accdesc_in, aligned) = { + assert(accdesc_in.acctype == AccessType_SVE); + assert(accdesc_in.nonfault | accdesc_in.firstfault & not_bool(accdesc_in.first)); + value_name : bits(8 * 'size) = undefined; + memstatus : PhysMemRetStatus = undefined; + accdesc : AccessDescriptor = accdesc_in; + fault : FaultRecord = NoFault__1(accdesc); + if ConstrainUnpredictableBool(Unpredictable_NONFAULT) then { + return((__UNKNOWN_bits(8 * size), true)) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc) + }; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size); + if memaddrdesc.memattrs.memtype == MemType_Device then { + return((__UNKNOWN_bits(8 * size), true)) + }; + if IsFault(memaddrdesc) then { + return((__UNKNOWN_bits(8 * size), true)) + }; + if HaveMTE2Ext() & accdesc.tagchecked then { + let ptag : bits(4) = AArch64_PhysicalTag(address); + if not_bool(AArch64_CheckTag(memaddrdesc, accdesc, ptag)) then { + return((__UNKNOWN_bits(8 * size), true)) + }; + () + }; + (memstatus, value_name) = PhysMemRead(memaddrdesc, size, accdesc, None()); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + let iswrite : bool = false; + if IsExternalAbortTakenSynchronously(memstatus, iswrite, memaddrdesc, size, accdesc) then { + return((__UNKNOWN_bits(8 * size), true)) + }; + fault.merrorstate = memstatus.merrorstate; + fault.extflag = memstatus.extflag; + fault.statuscode = memstatus.statuscode; + PendSErrorInterrupt(fault) + }; + return((value_name, false)) +} + +val MemNF_read : forall 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(64), int('size), AccessDescriptor) -> (bits(8 * 'size), bool) + +function MemNF_read (address, size, accdesc) = { + c : Constraint = undefined; + assert(size == 1 | size == 2 | size == 4 | size == 8 | size == 16); + value_name : bits(8 * 'size) = undefined; + bad : bool = undefined; + aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) & AlignmentEnforced() then { + return((__UNKNOWN_bits(8 * size), true)) + }; + let atomic : bool = aligned | size == 1; + if not_bool(atomic) then { + (value_name[7 .. 0], bad) = MemSingleNF_read(address, 1, accdesc, aligned); + if bad then { + return((__UNKNOWN_bits(8 * size), true)) + }; + if not_bool(aligned) then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_DEVPAGE2); + assert(c == Constraint_FAULT | c == Constraint_NONE); + if c == Constraint_NONE then { + aligned = true + }; + () + }; + foreach (i from 1 to (size - 1) by 1 in inc) { + (value_name[8 * i + 7 .. 8 * i], bad) = MemSingleNF_read(address + i, 1, accdesc, aligned); + if bad then { + return((__UNKNOWN_bits(8 * size), true)) + }; + () + } + } else { + (value_name, bad) = MemSingleNF_read(address, size, accdesc, aligned); + if bad then { + return((__UNKNOWN_bits(8 * size), true)) + }; + () + }; + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + let value_name = value_name; + return((value_name, false)) +} + +val ActivePredicateElement : forall 'N 'e 'esize, 'N >= 0. + (bits('N), int('e), int('esize)) -> bool + +function ActivePredicateElement (pred, e, esize) = { + assert(esize == 8 | esize == 16 | esize == 32 | esize == 64 | esize == 128); + let 'n = e * DIV(esize, 8); + assert(n >= 0 & n < 'N); + return([pred[n]] == 0b1) +} + +val PredicateElement : forall 'N 'e 'esize, 'N >= 0. + (bits('N), int('e), int('esize)) -> bits(1) + +function PredicateElement (pred, e, esize) = { + assert(esize == 8 | esize == 16 | esize == 32 | esize == 64 | esize == 128); + let 'n = e * DIV(esize, 8); + assert(n >= 0 & n < 'N); + return([pred[n]]) +} + +val FirstActive : forall 'N 'esize, 'N >= 0. + (bits('N), bits('N), int('esize)) -> bits(1) + +function FirstActive (mask, x, esize) = { + let 'elements = DIV('N, DIV(esize, 8)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + if ActivePredicateElement(mask, e, esize) then { + return(PredicateElement(x, e, esize)) + }; + () + }; + return(0b0) +} + +val LastActive : forall 'N 'esize, 'N >= 0. + (bits('N), bits('N), int('esize)) -> bits(1) + +function LastActive (mask, x, esize) = { + let 'elements = DIV('N, DIV(esize, 8)); + foreach (e from (elements - 1) to 0 by 1 in dec) { + if ActivePredicateElement(mask, e, esize) then { + return(PredicateElement(x, e, esize)) + }; + () + }; + return(0b0) +} + +val NoneActive : forall 'N 'esize, 'N >= 0. + (bits('N), bits('N), int('esize)) -> bits(1) + +function NoneActive (mask, x, esize) = { + let 'elements = DIV('N, DIV(esize, 8)); + foreach (e from 0 to (elements - 1) by 1 in inc) { + if ActivePredicateElement(mask, e, esize) & ActivePredicateElement(x, e, esize) then { + return(0b0) + }; + () + }; + return(0b1) +} + +val ElemFFR_read : forall 'e 'esize. (int('e), int('esize)) -> bits(1) + +function ElemFFR_read (e, esize) = { + return(PredicateElement(_FFR, e, esize)) +} + +val ElemFFR_set : forall 'e 'esize. (int('e), int('esize), bits(1)) -> unit + +function ElemFFR_set (e, esize, value_name) = { + let 'VL = CurrentVL_read(); + let 'psize = DIV(esize, 8); + let 'n = e * psize; + assert(n >= 0 & n + psize <= DIV(VL, 8)); + assert(constraint('n <= 'n + 'psize - 1)); + _FFR[n + psize - 1 .. n] = ZeroExtend(value_name, psize); + return() +} + +val LastActiveElement : forall 'N 'esize, 'N >= 0. + (bits('N), int('esize)) -> int + +function LastActiveElement (mask, esize) = { + let 'elements = DIV('N, DIV(esize, 8)); + foreach (e from (elements - 1) to 0 by 1 in dec) { + if ActivePredicateElement(mask, e, esize) then { + return(e) + }; + () + }; + return(negate(1)) +} + +val AnyActiveElement : forall 'N 'esize, 'N >= 0. + (bits('N), int('esize)) -> bool + +function AnyActiveElement (mask, esize) = { + return(LastActiveElement(mask, esize) >= 0) +} + +val FPCompareUN : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bool + +function FPCompareUN (op1, op2, fpcr) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + if type1 == FPType_SNaN | type2 == FPType_SNaN then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + let result : bool = (type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN; + if not_bool(result) then { + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPCompareNE : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bool + +function FPCompareNE (op1, op2, fpcr) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + result : bool = undefined; + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + let op1_nan : bool = type1 == FPType_SNaN | type1 == FPType_QNaN; + let op2_nan : bool = type2 == FPType_SNaN | type2 == FPType_QNaN; + if op1_nan | op2_nan then { + result = true; + if type1 == FPType_SNaN | type2 == FPType_SNaN then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else { + result = value1_name != value2_name; + FPProcessDenorms(type1, type2, 'N, fpcr) + }; + return(result) +} + +val FPOne : forall 'N, 'N in {16, 32, 64}. (bits(1), int('N)) -> bits('N) + +function FPOne (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits(1 + ('E - 1)) = 0b0 @ Ones(E - 1); + let frac : bits('F) = Zeros(F); + return((sign @ exp) @ frac) +} + +val FPPointFive : forall 'N, 'N in {16, 32, 64}. (bits(1), int('N)) -> bits('N) + +function FPPointFive (sign, N) = { + assert(N == 16 | N == 32 | N == 64); + let 'E = if N == 16 then 5 else if N == 32 then 8 else 11; + let 'F = N - (E + 1); + let exp : bits(1 + ('E - 2) + 1) = (0b0 @ Ones(E - 2)) @ 0b0; + let frac : bits('F) = Zeros(F); + return((sign @ exp) @ frac) +} + +val GetOptimizedScale : forall 'N 'scale_in, 'N >= 0. + (bits('N), int('scale_in), int('N)) -> int + +function GetOptimizedScale (op, scale_in, N) = { + scale : int = scale_in; + if N == 16 then { + let 'exp16 = UInt(op[14 .. 10]); + scale = if scale + exp16 < negate(11) then negate(11) - exp16 else scale; + scale = if scale + exp16 > 43 then 43 - exp16 else scale + } else if N == 32 then { + let 'exp32 = UInt(op[30 .. 23]); + scale = if scale + exp32 < negate(24) then negate(24) - exp32 else scale; + scale = if scale + exp32 > 280 then 280 - exp32 else scale + } else if N == 64 then { + let 'exp64 = UInt(op[62 .. 52]); + scale = if scale + exp64 < negate(53) then negate(53) - exp64 else scale; + scale = if scale + exp64 > 2101 then 2101 - exp64 else scale + } else (); + let 'scale = scale; + return(scale) +} + +val FPScale : forall 'N 'scale, + 'N in {16, 32, 64}. + (bits('N), int('scale), FPCRType) -> bits('N) + +function FPScale (op, scale, fpcr) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('N) = undefined; + (fptype, sign, value_name) = FPUnpack(op, fpcr); + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + result = FPProcessNaN(fptype, op, fpcr) + } else if fptype == FPType_Zero then { + result = FPZero(sign, 'N) + } else if fptype == FPType_Infinity then { + result = FPInfinity(sign, 'N) + } else { + let 'scale_opt = GetOptimizedScale(op, scale, 'N); + result = FPRound(value_name * 2.0 ^ scale_opt, fpcr, 'N); + FPProcessDenorm(fptype, 'N, fpcr) + }; + return(result) +} + +val Reverse : forall 'M 'N, 'N >= 0. (bits('N), int('M)) -> bits('N) + +function Reverse (word, M) = { + result : bits('N) = undefined; + let 'sw = DIV('N, M); + assert('N == sw * M); + foreach (s from 0 to (sw - 1) by 1 in inc) { + assert(constraint(('loop_s * 'M <= 'loop_s * 'M + 'M - 1 | not(('loop_s >= 0 & ('loop_s + 1) * 'M <= 'N))))); + result = Elem_set(result, sw - 1 - s, M, Elem_read(word, s, M)) + }; + return(result) +} + +val FPTrigSMul : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPTrigSMul (op1, op2, fpcr) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('N) = FPMul(op1, op1, fpcr); + let fpexc : bool = false; + (fptype, sign, value_name) = FPUnpack__1(result, fpcr, fpexc); + if not_bool(fptype == FPType_QNaN | fptype == FPType_SNaN) then { + result['N - 1] = Bit([op2[0]]) + }; + return(result) +} + +val FPTrigSSel : forall 'N, 'N in {16, 32, 64}. (bits('N), bits('N)) -> bits('N) + +function FPTrigSSel (op1, op2) = { + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('N) = undefined; + if [op2[0]] == 0b1 then { + result = FPOne([op2[1]], 'N) + } else if [op2[1]] == 0b1 then { + result = FPNeg(op1) + } else { + result = op1 + }; + return(result) +} + +val FPTrigMAddCoefficient_read : forall 'N 'index, + 'N in {16, 32, 64}. + (int('index), int('N)) -> bits('N) + +function FPTrigMAddCoefficient_read (index, N) = { + assert(N == 16 | N == 32 | N == 64); + result : int = undefined; + if N == 16 then { + match index { + 0 => { + result = UInt(0x3c00) + }, + 1 => { + result = UInt(0xb155) + }, + 2 => { + result = UInt(0x2030) + }, + 3 => { + result = UInt(0x0000) + }, + 4 => { + result = UInt(0x0000) + }, + 5 => { + result = UInt(0x0000) + }, + 6 => { + result = UInt(0x0000) + }, + 7 => { + result = UInt(0x0000) + }, + 8 => { + result = UInt(0x3c00) + }, + 9 => { + result = UInt(0xb800) + }, + 10 => { + result = UInt(0x293a) + }, + 11 => { + result = UInt(0x0000) + }, + 12 => { + result = UInt(0x0000) + }, + 13 => { + result = UInt(0x0000) + }, + 14 => { + result = UInt(0x0000) + }, + 15 => { + result = UInt(0x0000) + }, + _ => () + } + } else if N == 32 then { + match index { + 0 => { + result = UInt(0x3f800000) + }, + 1 => { + result = UInt(0xbe2aaaab) + }, + 2 => { + result = UInt(0x3c088886) + }, + 3 => { + result = UInt(0xb95008b9) + }, + 4 => { + result = UInt(0x36369d6d) + }, + 5 => { + result = UInt(0x00000000) + }, + 6 => { + result = UInt(0x00000000) + }, + 7 => { + result = UInt(0x00000000) + }, + 8 => { + result = UInt(0x3f800000) + }, + 9 => { + result = UInt(0xbf000000) + }, + 10 => { + result = UInt(0x3d2aaaa6) + }, + 11 => { + result = UInt(0xbab60705) + }, + 12 => { + result = UInt(0x37cd37cc) + }, + 13 => { + result = UInt(0x00000000) + }, + 14 => { + result = UInt(0x00000000) + }, + 15 => { + result = UInt(0x00000000) + }, + _ => () + } + } else { + match index { + 0 => { + result = UInt(0x3ff0000000000000) + }, + 1 => { + result = UInt(0xbfc5555555555543) + }, + 2 => { + result = UInt(0x3f8111111110f30c) + }, + 3 => { + result = UInt(0xbf2a01a019b92fc6) + }, + 4 => { + result = UInt(0x3ec71de351f3d22b) + }, + 5 => { + result = UInt(0xbe5ae5e2b60f7b91) + }, + 6 => { + result = UInt(0x3de5d8408868552f) + }, + 7 => { + result = UInt(0x0000000000000000) + }, + 8 => { + result = UInt(0x3ff0000000000000) + }, + 9 => { + result = UInt(0xbfe0000000000000) + }, + 10 => { + result = UInt(0x3fa5555555555536) + }, + 11 => { + result = UInt(0xbf56c16c16c13a0b) + }, + 12 => { + result = UInt(0x3efa01a019b1e8d8) + }, + 13 => { + result = UInt(0xbe927e4f7282f468) + }, + 14 => { + result = UInt(0x3e21ee96d2641b13) + }, + 15 => { + result = UInt(0xbda8f76380fbb401) + }, + _ => () + } + }; + let 'result = result; + return(result[N - 1 .. 0]) +} + +val FPTrigMAdd : forall 'N 'x_in, + 'N in {16, 32, 64}. + (int('x_in), bits('N), bits('N), FPCRType) -> bits('N) + +function FPTrigMAdd (x_in, op1, op2_in, fpcr) = { + assert('N == 16 | 'N == 32 | 'N == 64); + op2 : bits('N) = op2_in; + x : int = x_in; + assert(x >= 0); + assert(x < 8); + if [op2['N - 1]] == 0b1 then { + x = x + 8 + }; + let 'x = x; + let coeff : bits('N) = FPTrigMAddCoefficient_read(x, 'N); + let op2 : bits('N) = FPAbs(op2); + let result : bits('N) = FPMulAdd(coeff, op1, op2, fpcr); + return(result) +} + +val FPExpCoefficient_read : forall 'N 'index, + 'N in {16, 32, 64}. + (int('index), int('N)) -> bits('N) + +function FPExpCoefficient_read (index, N) = { + assert(N == 16 | N == 32 | N == 64); + result : int = undefined; + if N == 16 then { + match index { + 0 => { + result = UInt(0x0000) + }, + 1 => { + result = UInt(0x0016) + }, + 2 => { + result = UInt(0x002d) + }, + 3 => { + result = UInt(0x0045) + }, + 4 => { + result = UInt(0x005d) + }, + 5 => { + result = UInt(0x0075) + }, + 6 => { + result = UInt(0x008e) + }, + 7 => { + result = UInt(0x00a8) + }, + 8 => { + result = UInt(0x00c2) + }, + 9 => { + result = UInt(0x00dc) + }, + 10 => { + result = UInt(0x00f8) + }, + 11 => { + result = UInt(0x0114) + }, + 12 => { + result = UInt(0x0130) + }, + 13 => { + result = UInt(0x014d) + }, + 14 => { + result = UInt(0x016b) + }, + 15 => { + result = UInt(0x0189) + }, + 16 => { + result = UInt(0x01a8) + }, + 17 => { + result = UInt(0x01c8) + }, + 18 => { + result = UInt(0x01e8) + }, + 19 => { + result = UInt(0x0209) + }, + 20 => { + result = UInt(0x022b) + }, + 21 => { + result = UInt(0x024e) + }, + 22 => { + result = UInt(0x0271) + }, + 23 => { + result = UInt(0x0295) + }, + 24 => { + result = UInt(0x02ba) + }, + 25 => { + result = UInt(0x02e0) + }, + 26 => { + result = UInt(0x0306) + }, + 27 => { + result = UInt(0x032e) + }, + 28 => { + result = UInt(0x0356) + }, + 29 => { + result = UInt(0x037f) + }, + 30 => { + result = UInt(0x03a9) + }, + 31 => { + result = UInt(0x03d4) + }, + _ => () + } + } else if N == 32 then { + match index { + 0 => { + result = UInt(0x000000) + }, + 1 => { + result = UInt(0x0164d2) + }, + 2 => { + result = UInt(0x02cd87) + }, + 3 => { + result = UInt(0x043a29) + }, + 4 => { + result = UInt(0x05aac3) + }, + 5 => { + result = UInt(0x071f62) + }, + 6 => { + result = UInt(0x08980f) + }, + 7 => { + result = UInt(0x0a14d5) + }, + 8 => { + result = UInt(0x0b95c2) + }, + 9 => { + result = UInt(0x0d1adf) + }, + 10 => { + result = UInt(0x0ea43a) + }, + 11 => { + result = UInt(0x1031dc) + }, + 12 => { + result = UInt(0x11c3d3) + }, + 13 => { + result = UInt(0x135a2b) + }, + 14 => { + result = UInt(0x14f4f0) + }, + 15 => { + result = UInt(0x16942d) + }, + 16 => { + result = UInt(0x1837f0) + }, + 17 => { + result = UInt(0x19e046) + }, + 18 => { + result = UInt(0x1b8d3a) + }, + 19 => { + result = UInt(0x1d3eda) + }, + 20 => { + result = UInt(0x1ef532) + }, + 21 => { + result = UInt(0x20b051) + }, + 22 => { + result = UInt(0x227043) + }, + 23 => { + result = UInt(0x243516) + }, + 24 => { + result = UInt(0x25fed7) + }, + 25 => { + result = UInt(0x27cd94) + }, + 26 => { + result = UInt(0x29a15b) + }, + 27 => { + result = UInt(0x2b7a3a) + }, + 28 => { + result = UInt(0x2d583f) + }, + 29 => { + result = UInt(0x2f3b79) + }, + 30 => { + result = UInt(0x3123f6) + }, + 31 => { + result = UInt(0x3311c4) + }, + 32 => { + result = UInt(0x3504f3) + }, + 33 => { + result = UInt(0x36fd92) + }, + 34 => { + result = UInt(0x38fbaf) + }, + 35 => { + result = UInt(0x3aff5b) + }, + 36 => { + result = UInt(0x3d08a4) + }, + 37 => { + result = UInt(0x3f179a) + }, + 38 => { + result = UInt(0x412c4d) + }, + 39 => { + result = UInt(0x4346cd) + }, + 40 => { + result = UInt(0x45672a) + }, + 41 => { + result = UInt(0x478d75) + }, + 42 => { + result = UInt(0x49b9be) + }, + 43 => { + result = UInt(0x4bec15) + }, + 44 => { + result = UInt(0x4e248c) + }, + 45 => { + result = UInt(0x506334) + }, + 46 => { + result = UInt(0x52a81e) + }, + 47 => { + result = UInt(0x54f35b) + }, + 48 => { + result = UInt(0x5744fd) + }, + 49 => { + result = UInt(0x599d16) + }, + 50 => { + result = UInt(0x5bfbb8) + }, + 51 => { + result = UInt(0x5e60f5) + }, + 52 => { + result = UInt(0x60ccdf) + }, + 53 => { + result = UInt(0x633f89) + }, + 54 => { + result = UInt(0x65b907) + }, + 55 => { + result = UInt(0x68396a) + }, + 56 => { + result = UInt(0x6ac0c7) + }, + 57 => { + result = UInt(0x6d4f30) + }, + 58 => { + result = UInt(0x6fe4ba) + }, + 59 => { + result = UInt(0x728177) + }, + 60 => { + result = UInt(0x75257d) + }, + 61 => { + result = UInt(0x77d0df) + }, + 62 => { + result = UInt(0x7a83b3) + }, + 63 => { + result = UInt(0x7d3e0c) + }, + _ => () + } + } else { + match index { + 0 => { + result = UInt(0x0000000000000) + }, + 1 => { + result = UInt(0x02C9A3E778061) + }, + 2 => { + result = UInt(0x059B0D3158574) + }, + 3 => { + result = UInt(0x0874518759BC8) + }, + 4 => { + result = UInt(0x0B5586CF9890F) + }, + 5 => { + result = UInt(0x0E3EC32D3D1A2) + }, + 6 => { + result = UInt(0x11301D0125B51) + }, + 7 => { + result = UInt(0x1429AAEA92DE0) + }, + 8 => { + result = UInt(0x172B83C7D517B) + }, + 9 => { + result = UInt(0x1A35BEB6FCB75) + }, + 10 => { + result = UInt(0x1D4873168B9AA) + }, + 11 => { + result = UInt(0x2063B88628CD6) + }, + 12 => { + result = UInt(0x2387A6E756238) + }, + 13 => { + result = UInt(0x26B4565E27CDD) + }, + 14 => { + result = UInt(0x29E9DF51FDEE1) + }, + 15 => { + result = UInt(0x2D285A6E4030B) + }, + 16 => { + result = UInt(0x306FE0A31B715) + }, + 17 => { + result = UInt(0x33C08B26416FF) + }, + 18 => { + result = UInt(0x371A7373AA9CB) + }, + 19 => { + result = UInt(0x3A7DB34E59FF7) + }, + 20 => { + result = UInt(0x3DEA64C123422) + }, + 21 => { + result = UInt(0x4160A21F72E2A) + }, + 22 => { + result = UInt(0x44E086061892D) + }, + 23 => { + result = UInt(0x486A2B5C13CD0) + }, + 24 => { + result = UInt(0x4BFDAD5362A27) + }, + 25 => { + result = UInt(0x4F9B2769D2CA7) + }, + 26 => { + result = UInt(0x5342B569D4F82) + }, + 27 => { + result = UInt(0x56F4736B527DA) + }, + 28 => { + result = UInt(0x5AB07DD485429) + }, + 29 => { + result = UInt(0x5E76F15AD2148) + }, + 30 => { + result = UInt(0x6247EB03A5585) + }, + 31 => { + result = UInt(0x6623882552225) + }, + 32 => { + result = UInt(0x6A09E667F3BCD) + }, + 33 => { + result = UInt(0x6DFB23C651A2F) + }, + 34 => { + result = UInt(0x71F75E8EC5F74) + }, + 35 => { + result = UInt(0x75FEB564267C9) + }, + 36 => { + result = UInt(0x7A11473EB0187) + }, + 37 => { + result = UInt(0x7E2F336CF4E62) + }, + 38 => { + result = UInt(0x82589994CCE13) + }, + 39 => { + result = UInt(0x868D99B4492ED) + }, + 40 => { + result = UInt(0x8ACE5422AA0DB) + }, + 41 => { + result = UInt(0x8F1AE99157736) + }, + 42 => { + result = UInt(0x93737B0CDC5E5) + }, + 43 => { + result = UInt(0x97D829FDE4E50) + }, + 44 => { + result = UInt(0x9C49182A3F090) + }, + 45 => { + result = UInt(0xA0C667B5DE565) + }, + 46 => { + result = UInt(0xA5503B23E255D) + }, + 47 => { + result = UInt(0xA9E6B5579FDBF) + }, + 48 => { + result = UInt(0xAE89F995AD3AD) + }, + 49 => { + result = UInt(0xB33A2B84F15FB) + }, + 50 => { + result = UInt(0xB7F76F2FB5E47) + }, + 51 => { + result = UInt(0xBCC1E904BC1D2) + }, + 52 => { + result = UInt(0xC199BDD85529C) + }, + 53 => { + result = UInt(0xC67F12E57D14B) + }, + 54 => { + result = UInt(0xCB720DCEF9069) + }, + 55 => { + result = UInt(0xD072D4A07897C) + }, + 56 => { + result = UInt(0xD5818DCFBA487) + }, + 57 => { + result = UInt(0xDA9E603DB3285) + }, + 58 => { + result = UInt(0xDFC97337B9B5F) + }, + 59 => { + result = UInt(0xE502EE78B3FF6) + }, + 60 => { + result = UInt(0xEA4AFA2A490DA) + }, + 61 => { + result = UInt(0xEFA1BEE615A27) + }, + 62 => { + result = UInt(0xF50765B6E4540) + }, + 63 => { + result = UInt(0xFA7C1819E90D8) + }, + _ => () + } + }; + let 'result = result; + return(result[N - 1 .. 0]) +} + +val FPExpA : forall 'N, 'N in {16, 32, 64}. bits('N) -> bits('N) + +function FPExpA op = { + assert('N == 16 | 'N == 32 | 'N == 64); + result : bits('N) = undefined; + let 'idx = if 'N == 16 then UInt(op[4 .. 0]) else UInt(op[5 .. 0]); + let coeff : bits('N) = FPExpCoefficient_read(idx, 'N); + if 'N == 16 then { + result[15 .. 0] = (0b0 @ op[9 .. 5]) @ coeff[9 .. 0] + } else if 'N == 32 then { + result[31 .. 0] = (0b0 @ op[13 .. 6]) @ coeff[22 .. 0] + } else { + result[63 .. 0] = (0b0 @ op[16 .. 6]) @ coeff[51 .. 0] + }; + return(result) +} + +val PredTest : forall 'N 'esize, 'N >= 0. + (bits('N), bits('N), int('esize)) -> bits(4) + +function PredTest (mask, result, esize) = { + let n : bits(1) = FirstActive(mask, result, esize); + let z : bits(1) = NoneActive(mask, result, esize); + let c : bits(1) = not_vec(LastActive(mask, result, esize)); + let v : bits(1) = 0b0; + return(((n @ z) @ c) @ v) +} + +val DecodePredCount : forall 'esize. (bits(5), int('esize)) -> int + +function DecodePredCount (pattern, esize) = { + let 'VL = CurrentVL_read(); + let 'elements = DIV(VL, esize); + numElem : int = undefined; + match pattern { + 0b00000 => { + numElem = FloorPow2(elements) + }, + 0b00001 => { + numElem = if elements >= 1 then 1 else 0 + }, + 0b00010 => { + numElem = if elements >= 2 then 2 else 0 + }, + 0b00011 => { + numElem = if elements >= 3 then 3 else 0 + }, + 0b00100 => { + numElem = if elements >= 4 then 4 else 0 + }, + 0b00101 => { + numElem = if elements >= 5 then 5 else 0 + }, + 0b00110 => { + numElem = if elements >= 6 then 6 else 0 + }, + 0b00111 => { + numElem = if elements >= 7 then 7 else 0 + }, + 0b01000 => { + numElem = if elements >= 8 then 8 else 0 + }, + 0b01001 => { + numElem = if elements >= 16 then 16 else 0 + }, + 0b01010 => { + numElem = if elements >= 32 then 32 else 0 + }, + 0b01011 => { + numElem = if elements >= 64 then 64 else 0 + }, + 0b01100 => { + numElem = if elements >= 128 then 128 else 0 + }, + 0b01101 => { + numElem = if elements >= 256 then 256 else 0 + }, + 0b11101 => { + numElem = elements - MOD(elements, 4) + }, + 0b11110 => { + numElem = elements - MOD(elements, 3) + }, + 0b11111 => { + numElem = elements + }, + _ => { + numElem = 0 + } + }; + let 'numElem = numElem; + return(numElem) +} + +val Reduce : forall 'N 'esize, + ('N in {8, 16, 32, 64, 128, 256, 512, 1024, 2048} & 'esize in {8, 16, 32, 64} & 'N >= 'esize). + (ReduceOp, bits('N), int('esize)) -> bits('esize) + +val Reduce__1 : forall 'N 'esize, + ('N in {8, 16, 32, 64, 128, 256, 512, 1024, 2048} & 'esize in {8, 16, 32, 64} & 'N >= 'esize). + (ReduceOp, bits('N), int('esize), bool) -> bits('esize) + +function Reduce (op, input, esize) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & FPCR[AH] == 0b1; + return(Reduce__1(op, input, esize, altfp)) +} + +function Reduce__1 (op, input, esize, altfp) = { + assert(esize == 8 | esize == 16 | esize == 32 | esize == 64); + result : bits('esize) = undefined; + if 'N == esize then { + return(input[esize - 1 .. 0]) + }; + let 'half = DIV('N, 2); + let hi : bits('esize) = Reduce__1(op, input['N - 1 .. half], esize, altfp); + let lo : bits('esize) = Reduce__1(op, input[half - 1 .. 0], esize, altfp); + match op { + ReduceOp_FMINNUM => { + assert(constraint('esize in {16, 32, 64})); + result = FPMinNum(lo, hi, FPCR_read()) + }, + ReduceOp_FMAXNUM => { + assert(constraint('esize in {16, 32, 64})); + result = FPMaxNum(lo, hi, FPCR_read()) + }, + ReduceOp_FMIN => { + assert(constraint('esize in {16, 32, 64})); + result = FPMin__1(lo, hi, FPCR_read(), altfp) + }, + ReduceOp_FMAX => { + assert(constraint('esize in {16, 32, 64})); + result = FPMax__1(lo, hi, FPCR_read(), altfp) + }, + ReduceOp_FADD => { + assert(constraint('esize in {16, 32, 64})); + result = FPAdd(lo, hi, FPCR_read()) + }, + ReduceOp_ADD => { + result = lo + hi + } + }; + let result = result; + return(result) +} + +val ReducePredicated : forall 'M 'N 'esize, + ('N >= 0 & 'M >= 0 & 'esize >= 0). + (ReduceOp, bits('N), bits('M), bits('esize)) -> bits('esize) + +function ReducePredicated (op, input, mask, identity) = { + assert('N == 'M * 8); + let 'p2bits = CeilPow2('N); + operand : bits('p2bits) = undefined; + let 'elements = DIV(p2bits, 'esize); + foreach (e from 0 to (elements - 1) by 1 in inc) { + if e * 'esize < 'N & ActivePredicateElement(mask, e, 'esize) then { + assert(constraint('N >= 0)); + assert(constraint('esize >= 0)); + assert(constraint(('loop_e * 'esize <= 'loop_e * 'esize + 'esize - 1 | not(('loop_e >= 0 & ('loop_e + 1) * 'esize <= 'N))))); + operand = Elem_set(operand, e, 'esize, Elem_read(input, e, 'esize)) + } else { + assert(constraint('p2bits >= 0)); + assert(constraint('esize >= 0)); + assert(constraint(('loop_e * 'esize <= ('loop_e + 1) * 'esize - 1 | not(('loop_e >= 0 & ('loop_e + 1) * 'esize <= 'p2bits))))); + operand = Elem_set(operand, e, 'esize, identity) + } + }; + assert(constraint(('p2bits in {16, 32, 64, 128, 256, 512, 1024, 2048} & 'esize in {8, 16, 32, 64} & 'p2bits >= 'esize | not('N == 'M * 8)))); + return(Reduce(op, operand, 'esize)) +} + +val DecodeBitMasks : forall 'M ('immediate : Bool), 'M >= 0. + (bits(1), bits(6), bits(6), bool('immediate), int('M)) -> (bits('M), bits('M)) + +function DecodeBitMasks (immN, imms, immr, immediate, M) = { + let 'len = HighestSetBit(immN @ not_vec(imms)); + if len < 1 then { + throw(Error_Undefined()) + }; + assert(M >= (1 << len)); + assert(constraint(6 >= 'len)); + let levels : bits(6) = ZeroExtend(Ones(len), 6); + if immediate & (imms & levels) == levels then { + throw(Error_Undefined()) + }; + let 's = UInt(imms & levels); + let 'r = UInt(immr & levels); + let 'diff = s - r; + let 'esize = (1 << len); + let 'd = UInt(diff[len - 1 .. 0]); + assert(constraint('esize >= 's + 1)); + let welem : bits('esize) = ZeroExtend(Ones(s + 1), esize); + assert(constraint('esize >= 'd + 1)); + let telem : bits('esize) = ZeroExtend(Ones(d + 1), esize); + assert(constraint('esize * div('M, 'esize) == 'M)); + let wmask : bits('M) = Replicate(ROR(welem, r), DIV(M, esize)); + let tmask : bits('M) = Replicate(telem, DIV(M, esize)); + return((wmask, tmask)) +} + +val FPConvertSVE : forall 'M 'N, + ('M in {16, 32, 64} & 'N in {16, 32, 64}). + (bits('N), FPCRType, FPRounding, int('M)) -> bits('M) + +val FPConvertSVE__1 : forall 'M 'N, + ('M in {16, 32, 64} & 'N in {16, 32, 64}). + (bits('N), FPCRType, int('M)) -> bits('M) + +function FPConvertSVE (op, fpcr_in, rounding, M) = { + fpcr : FPCRType = fpcr_in; + fpcr[AHP] = 0b0; + return(FPConvert(op, fpcr, rounding, M)) +} + +function FPConvertSVE__1 (op, fpcr_in, M) = { + fpcr : FPCRType = fpcr_in; + fpcr[AHP] = 0b0; + return(FPConvert(op, fpcr, FPRoundingMode(fpcr), M)) +} + +val IsEven : forall 'val_name. int('val_name) -> bool + +function IsEven val_name = { + return(MOD(val_name, 2) == 0) +} + +val HaveSVEFP32MatMulExt : unit -> bool + +function HaveSVEFP32MatMulExt () = { + return(IsFeatureImplemented(FEAT_F32MM)) +} + +val HaveSVEFP64MatMulExt : unit -> bool + +function HaveSVEFP64MatMulExt () = { + return(IsFeatureImplemented(FEAT_F64MM)) +} + +val HaveSVE2 : unit -> bool + +function HaveSVE2 () = { + return(IsFeatureImplemented(FEAT_SVE2)) +} + +val HaveSVE2AES : unit -> bool + +function HaveSVE2AES () = { + return(IsFeatureImplemented(FEAT_SVE_AES)) +} + +val HaveSVE2PMULL128 : unit -> bool + +function HaveSVE2PMULL128 () = { + return(IsFeatureImplemented(FEAT_SVE_PMULL128)) +} + +val HaveSVE2SHA3 : unit -> bool + +function HaveSVE2SHA3 () = { + return(IsFeatureImplemented(FEAT_SVE_SHA3)) +} + +val HaveSVE2SM4 : unit -> bool + +function HaveSVE2SM4 () = { + return(IsFeatureImplemented(FEAT_SVE_SM4)) +} + +val HaveSVE2BitPerm : unit -> bool + +function HaveSVE2BitPerm () = { + return(IsFeatureImplemented(FEAT_SVE_BitPerm)) +} + +val HaveSVE2p1 : unit -> bool + +function HaveSVE2p1 () = { + return(IsFeatureImplemented(FEAT_SVE2p1)) +} + +val HaveSVEB16B16 : unit -> bool + +function HaveSVEB16B16 () = { + return(IsFeatureImplemented(FEAT_SVE_B16B16)) +} + +val ShiftSat : forall 'esize 'shift. (int('shift), int('esize)) -> int + +function ShiftSat (shift, esize) = { + if shift > esize + 1 then { + return(esize + 1) + } else if shift < negate(esize + 1) then { + return(negate(esize + 1)) + } else (); + return(shift) +} + +val BitDeposit : forall 'N, 'N >= 0. (bits('N), bits('N)) -> bits('N) + +function BitDeposit (data, mask) = { + res : bits('N) = Zeros('N); + db : int = 0; + foreach (rb from 0 to ('N - 1) by 1 in inc) { + if [mask[rb]] == 0b1 then { + let 'db = db in + { + assert(constraint((0 <= 'db & 'db < 'N))); + res[rb] = Bit([data[db]]) + }; + db = db + 1 + }; + () + }; + return(res) +} + +val BitExtract : forall 'N, 'N >= 0. (bits('N), bits('N)) -> bits('N) + +function BitExtract (data, mask) = { + res : bits('N) = Zeros('N); + rb : int = 0; + foreach (db from 0 to ('N - 1) by 1 in inc) { + if [mask[db]] == 0b1 then { + let 'rb = rb in + { + assert(constraint((0 <= 'rb & 'rb < 'N))); + res[rb] = Bit([data[db]]) + }; + rb = rb + 1 + }; + () + }; + return(res) +} + +val BitGroup : forall 'N, 'N >= 0. (bits('N), bits('N)) -> bits('N) + +function BitGroup (data, mask) = { + res : bits('N) = undefined; + rb : int = 0; + foreach (db from 0 to ('N - 1) by 1 in inc) { + if [mask[db]] == 0b1 then { + let 'rb = rb in + { + assert(constraint((0 <= 'rb & 'rb < 'N))); + res[rb] = Bit([data[db]]) + }; + rb = rb + 1 + }; + () + }; + foreach (db from 0 to ('N - 1) by 1 in inc) { + if [mask[db]] == 0b0 then { + let 'rb = rb in + { + assert(constraint((0 <= 'rb & 'rb < 'N))); + res[rb] = Bit([data[db]]) + }; + rb = rb + 1 + }; + () + }; + return(res) +} + +val FPLogB : forall 'N, 'N in {16, 32, 64}. (bits('N), FPCRType) -> bits('N) + +function FPLogB (op, fpcr) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + result : int = undefined; + (fptype, sign, value_name) = FPUnpack(op, fpcr); + if (fptype == FPType_SNaN | fptype == FPType_QNaN) | fptype == FPType_Zero then { + FPProcessException(FPExc_InvalidOp, fpcr); + result = negate(2 ^ ('N - 1)) + } else if fptype == FPType_Infinity then { + result = pow2('N - 1) - 1 + } else { + value_name : real = Abs(value_name); + result = 0; + while value_name < 1.0 do { + value_name = value_name * 2.0; + result = result - 1 + }; + while value_name >= 2.0 do { + value_name = value_name / 2.0; + result = result + 1 + }; + FPProcessDenorm(fptype, 'N, fpcr) + }; + let 'result = result; + return(result['N - 1 .. 0]) +} + +val HaveSMEF64F64 : unit -> bool + +function HaveSMEF64F64 () = { + return(IsFeatureImplemented(FEAT_SME_F64F64)) +} + +val HaveSMEI16I64 : unit -> bool + +function HaveSMEI16I64 () = { + return(IsFeatureImplemented(FEAT_SME_I16I64)) +} + +val ZAvector_read : forall 'index 'width, 'width >= 0. + (int('index), int('width)) -> bits('width) + +function ZAvector_read (index, width) = { + let 'SVL = CurrentSVL_read(); + assert(width == SVL); + assert(index >= 0 & index < DIV(width, 8)); + return(_ZA[index][width - 1 .. 0]) +} + +val ZAvector_set : forall 'index 'width, 'width >= 0. + (int('index), int('width), bits('width)) -> unit + +function ZAvector_set (index, width, value_name) = { + let 'SVL = CurrentSVL_read(); + assert(width == SVL); + assert(index >= 0 & index < DIV(width, 8)); + if ConstrainUnpredictableBool(Unpredictable_SMEZEROUPPER) then { + _ZA[index] = ZeroExtend(value_name, MAX_VL) + } else { + _ZA[index][width - 1 .. 0] = value_name + } +} + +val ZAhslice_read : forall 'esize 'slice_name 'tile 'width, + 'width >= 0. + (int('tile), int('esize), int('slice_name), int('width)) -> bits('width) + +function ZAhslice_read (tile, esize, slice_name, width) = { + let 'SVL = CurrentSVL_read(); + assert(esize == 8 | esize == 16 | esize == 32 | esize == 64 | esize == 128); + let 'tiles = DIV(esize, 8); + assert(tile >= 0 & tile < tiles); + let 'slices = DIV(SVL, esize); + assert(slice_name >= 0 & slice_name < slices); + return(ZAvector_read(tile + slice_name * tiles, width)) +} + +val ZAhslice_set : forall 'esize 'slice_name 'tile 'width, + 'width >= 0. + (int('tile), int('esize), int('slice_name), int('width), bits('width)) -> unit + +function ZAhslice_set (tile, esize, slice_name, width, value_name) = { + let 'SVL = CurrentSVL_read(); + assert(esize == 8 | esize == 16 | esize == 32 | esize == 64 | esize == 128); + let 'tiles = DIV(esize, 8); + assert(tile >= 0 & tile < tiles); + let 'slices = DIV(SVL, esize); + assert(slice_name >= 0 & slice_name < slices); + ZAvector_set(tile + slice_name * tiles, width) = value_name +} + +val ZAvslice_read : forall 'esize 'slice_name 'tile 'width, + 'width >= 0 & 'esize >= 0 & ('slice_name * 'esize <= 'slice_name * 'esize + 'esize - 1 | not(('slice_name >= 0 & ('slice_name + 1) * 'esize <= 'width))). + (int('tile), int('esize), int('slice_name), int('width)) -> bits('width) + +function ZAvslice_read (tile, esize, slice_name, width) = { + let 'SVL = CurrentSVL_read(); + let 'slices = DIV(SVL, esize); + result : bits('width) = undefined; + foreach (s from 0 to (slices - 1) by 1 in inc) { + let hslice : bits('width) = ZAhslice_read(tile, esize, s, width); + assert(constraint(('loop_s * 'esize <= ('loop_s + 1) * 'esize - 1 | not(('loop_s >= 0 & ('loop_s + 1) * 'esize <= 'width))))); + result = Elem_set(result, s, esize, Elem_read(hslice, slice_name, esize)) + }; + return(result) +} + +val ZAvslice_set : forall 'esize 'slice_name 'tile 'width, + 'width >= 0 & 'esize >= 0. + (int('tile), int('esize), int('slice_name), int('width), bits('width)) -> unit + +function ZAvslice_set (tile, esize, slice_name, width, value_name) = { + let 'SVL = CurrentSVL_read(); + let 'slices = DIV(SVL, esize); + foreach (s from 0 to (slices - 1) by 1 in inc) { + hslice : bits('width) = ZAhslice_read(tile, esize, s, width); + assert(constraint(('loop_s * 'esize <= 'loop_s * 'esize + 'esize - 1 | not(('loop_s >= 0 & ('loop_s + 1) * 'esize <= 'width))))); + hslice = Elem_set(hslice, slice_name, esize, Elem_read(value_name, s, esize)); + ZAhslice_set(tile, esize, s, width) = hslice + } +} + +val ZAslice_read : forall 'esize 'slice_name 'tile ('vertical : Bool) 'width, + 'width >= 0. + (int('tile), int('esize), bool('vertical), int('slice_name), int('width)) -> bits('width) + +function ZAslice_read (tile, esize, vertical, slice_name, width) = { + result : bits('width) = undefined; + if vertical then { + assert(constraint('width >= 0)); + assert(constraint('esize >= 0)); + assert(constraint(('slice_name * 'esize <= 'slice_name * 'esize + 'esize - 1 | not(('slice_name >= 0 & ('slice_name + 1) * 'esize <= 'width))))); + result = ZAvslice_read(tile, esize, slice_name, width) + } else { + result = ZAhslice_read(tile, esize, slice_name, width) + }; + return(result) +} + +val ZAslice_set : forall 'esize 'slice_name 'tile ('vertical : Bool) 'width, + 'width >= 0. + (int('tile), int('esize), bool('vertical), int('slice_name), int('width), bits('width)) -> unit + +function ZAslice_set (tile, esize, vertical, slice_name, width, value_name) = { + if vertical then { + assert(constraint('width >= 0)); + assert(constraint('esize >= 0)); + ZAvslice_set(tile, esize, slice_name, width) = value_name + } else { + ZAhslice_set(tile, esize, slice_name, width) = value_name + } +} + +val ZAtile_read : forall 'SVL 'esize 'tile 'width, + 'width >= 0. + (int('SVL), int('tile), int('esize), int('width)) -> bits('width) + +function ZAtile_read (SVL, tile, esize, width) = { + let 'slices = DIV(SVL, esize); + assert(width == SVL * slices); + result : bits('width) = undefined; + foreach (slice_name from 0 to (slices - 1) by 1 in inc) { + assert(constraint(('loop_slice_name * 'SVL <= ('loop_slice_name + 1) * 'SVL - 1 | not(('loop_slice_name >= 0 & ('loop_slice_name + 1) * 'SVL <= 'width))))); + result = Elem_set(result, slice_name, SVL, ZAhslice_read(tile, esize, slice_name, SVL)) + }; + return(result) +} + +val ZAtile_set : forall 'SVL 'esize 'tile 'width, + 'width >= 0. + (int('SVL), int('tile), int('esize), int('width), bits('width)) -> unit + +function ZAtile_set (SVL, tile, esize, width, value_name) = { + let 'slices = DIV(SVL, esize); + assert(width == SVL * slices); + foreach (slice_name from 0 to (slices - 1) by 1 in inc) { + assert(constraint(('loop_slice_name * 'SVL <= 'loop_slice_name * 'SVL + 'SVL - 1 | not(('loop_slice_name >= 0 & ('loop_slice_name + 1) * 'SVL <= 'width))))); + ZAhslice_set(tile, esize, slice_name, SVL) = Elem_read(value_name, slice_name, SVL) + } +} + +val HaveSME2 : unit -> bool + +function HaveSME2 () = { + return(IsFeatureImplemented(FEAT_SME2)) +} + +val HaveSME2p1 : unit -> bool + +function HaveSME2p1 () = { + return(IsFeatureImplemented(FEAT_SME2p1)) +} + +val HaveSMEB16B16 : unit -> bool + +function HaveSMEB16B16 () = { + return(IsFeatureImplemented(FEAT_SVE_B16B16)) +} + +val HaveSMEF16F16 : unit -> bool + +function HaveSMEF16F16 () = { + return(IsFeatureImplemented(FEAT_SME_F16F16)) +} + +val ZT0_read : forall 'width, 'width == 512. int('width) -> bits('width) + +function ZT0_read width = { + assert(width == 512); + return(_ZT0[width - 1 .. 0]) +} + +val ZT0_set : forall 'width, 'width == 512. (int('width), bits('width)) -> unit + +function ZT0_set (width, value_name) = { + assert(width == 512); + _ZT0[width - 1 .. 0] = value_name +} + +val CounterToPredicate : forall 'width, 'width >= 0. + (bits(16), int('width)) -> bits('width) + +function CounterToPredicate (pred, width) = { + let 'VL = CurrentVL_read(); + count : int = undefined; + esize : {8, 16, 32, 64} = 8; + let 'VL = VL; + let 'PL = DIV(VL, 8); + let 'maxbit = HighestSetBit(CeilPow2(PL * 4)[15 .. 0]); + assert(maxbit <= 14); + let invert : bool = [pred[15]] == 0b1; + assert(((width == PL | width == PL * 2) | width == PL * 3) | width == PL * 4); + if IsZero(pred[3 .. 0]) then { + return(Zeros(width)) + }; + match pred[3 .. 0] { + [_, _, _, bitone] => { + assert(constraint((1 <= 'maxbit & 'maxbit < 16))); + count = UInt(pred[maxbit .. 1]); + esize = 8 + }, + [_, _, bitone, bitzero] => { + assert(constraint((2 <= 'maxbit & 'maxbit < 16))); + count = UInt(pred[maxbit .. 2]); + esize = 16 + }, + [_, bitone, bitzero, bitzero] => { + assert(constraint((3 <= 'maxbit & 'maxbit < 16))); + count = UInt(pred[maxbit .. 3]); + esize = 32 + }, + 0b1000 => { + assert(constraint((4 <= 'maxbit & 'maxbit < 16))); + count = UInt(pred[maxbit .. 4]); + esize = 64 + }, + _ => () + }; + let 'esize = esize; + let 'count = count; + let 'elements = DIV(VL * 4, esize); + result : bits('PL * 4) = Zeros(PL * 4); + let 'psize = DIV(esize, 8); + foreach (e from 0 to (elements - 1) by 1 in inc) { + pbit : bits(1) = if e < count then 0b1 else 0b0; + if invert then { + pbit = not_vec(pbit) + }; + result = Elem_set(result, e, psize, ZeroExtend(pbit, psize)) + }; + return(result[width - 1 .. 0]) +} + +val EncodePredCount : forall 'count_in 'elements 'esize ('invert_in : Bool) 'width, + 'width >= 0. + (int('esize), int('elements), int('count_in), bool('invert_in), int('width)) -> bits('width) + +function EncodePredCount (esize, elements, count_in, invert_in, width) = { + let 'VL = CurrentVL_read(); + count : int = count_in; + invert : bool = invert_in; + let 'PL = DIV(VL, 8); + assert(width == PL); + assert(esize == 8 | esize == 16 | esize == 32 | esize == 64); + assert(count >= 0 & count <= elements); + pred : bits(16) = undefined; + if count == 0 then { + return(Zeros(width)) + }; + if invert then { + count = elements - count + } else if count == elements then { + count = 0; + invert = true + } else (); + let 'count = count; + let inv : bits(1) = if invert then 0b1 else 0b0; + match esize { + 8 => { + pred = (inv @ count[13 .. 0]) @ 0b1 + }, + 16 => { + pred = (inv @ count[12 .. 0]) @ 0b10 + }, + 32 => { + pred = (inv @ count[11 .. 0]) @ 0b100 + }, + 64 => { + pred = (inv @ count[10 .. 0]) @ 0b1000 + }, + _ => () + }; + return(ZeroExtend(pred, width)) +} + +val PredCountTest : forall 'count 'elements ('invert : Bool). + (int('elements), int('count), bool('invert)) -> bits(4) + +function PredCountTest (elements, count, invert) = { + c : bits(1) = undefined; + n : bits(1) = undefined; + let z : bits(1) = if count == 0 then 0b1 else 0b0; + if not_bool(invert) then { + n = if count != 0 then 0b1 else 0b0; + c = if count == elements then 0b0 else 0b1 + } else { + n = if count == elements then 0b1 else 0b0; + c = if count != 0 then 0b0 else 0b1 + }; + let v : bits(1) = 0b0; + return(((n @ z) @ c) @ v) +} + +val GCSSynchronizationBarrier : unit -> unit + +function GCSSynchronizationBarrier () = { + return() +} + +val GCSPCREnabled : bits(2) -> bool + +function GCSPCREnabled el = { + return(GCSPCRSelected(el) & GCSEnabled(el)) +} + +val GCSReturnValueCheckEnabled : bits(2) -> bool + +function GCSReturnValueCheckEnabled el = { + if UsingAArch32() then { + return(false) + }; + match el { + ? if ? == EL0 => { + return(GCSCRE0_EL1[RVCHKEN] == 0b1) + }, + ? if ? == EL1 => { + return(GCSCR_EL1[RVCHKEN] == 0b1) + }, + ? if ? == EL2 => { + return(GCSCR_EL2[RVCHKEN] == 0b1) + }, + ? if ? == EL3 => { + return(GCSCR_EL3[RVCHKEN] == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val GetCurrentGCSPointer : unit -> bits(64) + +function GetCurrentGCSPointer () = { + ptr : bits(64) = undefined; + match PSTATE.EL { + ? if ? == EL0 => { + ptr = GCSPR_EL0[PTR] @ 0b000 + }, + ? if ? == EL1 => { + ptr = GCSPR_EL1[PTR] @ 0b000 + }, + ? if ? == EL2 => { + ptr = GCSPR_EL2[PTR] @ 0b000 + }, + ? if ? == EL3 => { + ptr = GCSPR_EL3[PTR] @ 0b000 + }, + _ => () + }; + return(ptr) +} + +val SetCurrentGCSPointer : bits(64) -> unit + +function SetCurrentGCSPointer ptr = { + match PSTATE.EL { + ? if ? == EL0 => { + GCSPR_EL0[PTR] = ptr[63 .. 3] + }, + ? if ? == EL1 => { + GCSPR_EL1[PTR] = ptr[63 .. 3] + }, + ? if ? == EL2 => { + GCSPR_EL2[PTR] = ptr[63 .. 3] + }, + ? if ? == EL3 => { + GCSPR_EL3[PTR] = ptr[63 .. 3] + }, + _ => () + }; + return() +} + +val AddGCSRecord : bits(64) -> unit + +function AddGCSRecord vaddress = { + let accdesc : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_STORE); + ptr : bits(64) = GetCurrentGCSPointer(); + Mem_set(ptr - 8, 8, accdesc) = vaddress; + let ptr : bits(64) = ptr - 8; + SetCurrentGCSPointer(ptr); + return() +} + +val AddGCSExRecord : (bits(64), bits(64), bits(64)) -> unit + +function AddGCSExRecord (elr, spsr, lr) = { + let accdesc : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_STORE); + ptr : bits(64) = GetCurrentGCSPointer(); + Mem_set(ptr - 8, 8, accdesc) = lr; + Mem_set(ptr - 16, 8, accdesc) = spsr; + Mem_set(ptr - 24, 8, accdesc) = elr; + Mem_set(ptr - 32, 8, accdesc) = Zeros(60) @ 0b1001; + let ptr : bits(64) = ptr - 32; + SetCurrentGCSPointer(ptr); + return() +} + +val GCSDataCheckException : GCSInstruction -> unit + +function GCSDataCheckException gcsinst_type = { + target_el : bits(2) = undefined; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + rn_unknown : bool = false; + is_ret : bool = false; + if PSTATE.EL == EL0 then { + target_el = if HCR_EL2[TGE] == 0b0 then EL1 else EL2 + } else { + target_el = PSTATE.EL + }; + except : ExceptionRecord = ExceptionSyndrome(Exception_GCSFail); + match gcsinst_type { + GCSInstType_PRET => { + except.syndrome[4 .. 0] = 0b00000; + is_ret = true + }, + GCSInstType_POPM => { + except.syndrome[4 .. 0] = 0b00001 + }, + GCSInstType_PRETAA => { + except.syndrome[4 .. 0] = 0b00010; + is_ret = true + }, + GCSInstType_PRETAB => { + except.syndrome[4 .. 0] = 0b00011; + is_ret = true + }, + GCSInstType_SS1 => { + except.syndrome[4 .. 0] = 0b00100 + }, + GCSInstType_SS2 => { + except.syndrome[4 .. 0] = 0b00101; + rn_unknown = true + }, + GCSInstType_POPCX => { + rn_unknown = true; + except.syndrome[4 .. 0] = 0b01000 + }, + GCSInstType_POPX => { + except.syndrome[4 .. 0] = 0b01001 + } + }; + if rn_unknown == true then { + except.syndrome[9 .. 5] = __UNKNOWN_bits(5) + } else if is_ret == true then { + except.syndrome[9 .. 5] = ThisInstr()[9 .. 5] + } else { + except.syndrome[9 .. 5] = ThisInstr()[4 .. 0] + }; + except.syndrome[24 .. 10] = Zeros(); + except.vaddress = __UNKNOWN_bits(64); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val LoadCheckGCSRecord : (bits(64), GCSInstruction) -> bits(64) + +function LoadCheckGCSRecord (vaddress, gcsinst_type) = { + let accdesc : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_LOAD); + let ptr : bits(64) = GetCurrentGCSPointer(); + let recorded_va : bits(64) = Mem_read(ptr, 8, accdesc); + if GCSReturnValueCheckEnabled(PSTATE.EL) & recorded_va != vaddress then { + GCSDataCheckException(gcsinst_type) + }; + return(recorded_va) +} + +val CheckGCSExRecord : (bits(64), bits(64), bits(64), GCSInstruction) -> unit + +function CheckGCSExRecord (elr, spsr, lr, gcsinst_type) = { + let accdesc : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_LOAD); + ptr : bits(64) = GetCurrentGCSPointer(); + let recorded_first_dword : bits(64) = Mem_read(ptr, 8, accdesc); + if recorded_first_dword != (Zeros(60) @ 0b1001) then { + GCSDataCheckException(gcsinst_type) + }; + let recorded_elr : bits(64) = Mem_read(ptr + 8, 8, accdesc); + if recorded_elr != elr then { + GCSDataCheckException(gcsinst_type) + }; + let recorded_spsr : bits(64) = Mem_read(ptr + 16, 8, accdesc); + if recorded_spsr != spsr then { + GCSDataCheckException(gcsinst_type) + }; + let recorded_lr : bits(64) = Mem_read(ptr + 24, 8, accdesc); + if recorded_lr != lr then { + GCSDataCheckException(gcsinst_type) + }; + let ptr : bits(64) = ptr + 32; + SetCurrentGCSPointer(ptr); + return() +} + +val EXLOCKException : unit -> unit + +function EXLOCKException () = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_GCSFail); + except.syndrome[24] = Bit(Zeros()); + except.syndrome[23 .. 20] = 0b0001; + except.syndrome[19 .. 0] = Zeros(); + AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset) +} + +val GCSSTRTrapException : bits(2) -> unit + +function GCSSTRTrapException target_el = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_GCSFail); + except.syndrome[24] = Bit(Zeros()); + except.syndrome[23 .. 20] = 0b0010; + except.syndrome[19 .. 15] = Zeros(); + except.syndrome[14 .. 10] = ThisInstr()[9 .. 5]; + except.syndrome[9 .. 5] = ThisInstr()[4 .. 0]; + except.syndrome[4 .. 0] = Zeros(); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val GCSSS1 : bits(64) -> unit + +function GCSSS1 incoming_pointer_name = { + if not_bool(GCSEnabled(PSTATE.EL)) then { + EndOfInstruction() + }; + let accdesc : AccessDescriptor = CreateAccDescGCSSS1(PSTATE.EL); + let outgoing_pointer : bits(64) = GetCurrentGCSPointer(); + let cmpoperand : bits(64) = incoming_pointer_name[63 .. 12] @ 0b000000000001; + let operand : bits(64) = outgoing_pointer[63 .. 3] @ 0b101; + let data : bits(64) = MemAtomic(incoming_pointer_name, cmpoperand, operand, accdesc); + if data == cmpoperand then { + SetCurrentGCSPointer(incoming_pointer_name[63 .. 3] @ 0b000) + } else { + GCSDataCheckException(GCSInstType_SS1) + }; + return() +} + +val GCSSS2 : unit -> bits(64) + +function GCSSS2 () = { + outgoing_pointer : bits(64) = undefined; + let accdesc_ld : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_LOAD); + let accdesc_st : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_STORE); + if not_bool(GCSEnabled(PSTATE.EL)) then { + EndOfInstruction() + }; + let incoming_pointer_name : bits(64) = GetCurrentGCSPointer(); + outgoing_value : bits(64) = Mem_read(incoming_pointer_name, 8, accdesc_ld); + if outgoing_value[2 .. 0] == 0b101 then { + outgoing_pointer[63 .. 3] = outgoing_value[63 .. 3] - 1; + outgoing_pointer[2 .. 0] = 0b000; + let outgoing_value : bits(64) = outgoing_pointer[63 .. 12] @ 0b000000000001; + Mem_set(outgoing_pointer, 8, accdesc_st) = outgoing_value; + SetCurrentGCSPointer(incoming_pointer_name + 8); + GCSSynchronizationBarrier() + } else { + GCSDataCheckException(GCSInstType_SS2) + }; + return(outgoing_pointer) +} + +val GCSPUSHM : bits(64) -> unit + +function GCSPUSHM value_name = { + if not_bool(GCSEnabled(PSTATE.EL)) then { + EndOfInstruction() + }; + AddGCSRecord(value_name); + return() +} + +val GCSPOPM : unit -> bits(64) + +function GCSPOPM () = { + let accdesc : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_LOAD); + if not_bool(GCSEnabled(PSTATE.EL)) then { + EndOfInstruction() + }; + ptr : bits(64) = GetCurrentGCSPointer(); + let entry : bits(64) = Mem_read(ptr, 8, accdesc); + if entry[1 .. 0] != 0b00 then { + GCSDataCheckException(GCSInstType_POPM) + }; + let ptr : bits(64) = ptr + 8; + SetCurrentGCSPointer(ptr); + return(entry) +} + +val GCSPUSHX : unit -> unit + +function GCSPUSHX () = { + let spsr : bits(64) = SPSR_read(64); + if not_bool(GCSEnabled(PSTATE.EL)) then { + EndOfInstruction() + }; + AddGCSExRecord(ELR_read__1(), spsr, X_read(30, 64)); + PSTATE.EXLOCK = 0b0; + return() +} + +val GCSPOPCX : unit -> unit + +function GCSPOPCX () = { + let spsr : bits(64) = SPSR_read(64); + if not_bool(GCSEnabled(PSTATE.EL)) then { + EndOfInstruction() + }; + CheckGCSExRecord(ELR_read__1(), spsr, X_read(30, 64), GCSInstType_POPCX); + PSTATE.EXLOCK = if GetCurrentEXLOCKEN() then 0b1 else 0b0; + return() +} + +val GCSPOPX : unit -> unit + +function GCSPOPX () = { + if not_bool(GCSEnabled(PSTATE.EL)) then { + EndOfInstruction() + }; + let accdesc : AccessDescriptor = CreateAccDescGCS(PSTATE.EL, MemOp_LOAD); + ptr : bits(64) = GetCurrentGCSPointer(); + let recorded_first_dword : bits(64) = Mem_read(ptr, 8, accdesc); + if recorded_first_dword != (Zeros(60) @ 0b1001) then { + GCSDataCheckException(GCSInstType_POPX) + }; + let recorded_elr : bits(64) = Mem_read(ptr + 8, 8, accdesc); + let recorded_spsr : bits(64) = Mem_read(ptr + 16, 8, accdesc); + let recorded_lr : bits(64) = Mem_read(ptr + 24, 8, accdesc); + let ptr : bits(64) = ptr + 32; + SetCurrentGCSPointer(ptr); + return() +} + +bitfield HFGITR_EL2_Type : bits(64) = + { + COSPRCTX : 60..60, + nGCSEPP : 59..59, + nGCSSTR_EL1 : 58..58, + nGCSPUSHM_EL1 : 57..57, + nBRBIALL : 56..56, + nBRBINJ : 55..55, + DCCVAC : 54..54, + SVC_EL1 : 53..53, + SVC_EL0 : 52..52, + ERET : 51..51, + CPPRCTX : 50..50, + DVPRCTX : 49..49, + CFPRCTX : 48..48, + TLBIVAALE1 : 47..47, + TLBIVALE1 : 46..46, + TLBIVAAE1 : 45..45, + TLBIASIDE1 : 44..44, + TLBIVAE1 : 43..43, + TLBIVMALLE1 : 42..42, + TLBIRVAALE1 : 41..41, + TLBIRVALE1 : 40..40, + TLBIRVAAE1 : 39..39, + TLBIRVAE1 : 38..38, + TLBIRVAALE1IS : 37..37, + TLBIRVALE1IS : 36..36, + TLBIRVAAE1IS : 35..35, + TLBIRVAE1IS : 34..34, + TLBIVAALE1IS : 33..33, + TLBIVALE1IS : 32..32, + TLBIVAAE1IS : 31..31, + TLBIASIDE1IS : 30..30, + TLBIVAE1IS : 29..29, + TLBIVMALLE1IS : 28..28, + TLBIRVAALE1OS : 27..27, + TLBIRVALE1OS : 26..26, + TLBIRVAAE1OS : 25..25, + TLBIRVAE1OS : 24..24, + TLBIVAALE1OS : 23..23, + TLBIVALE1OS : 22..22, + TLBIVAAE1OS : 21..21, + TLBIASIDE1OS : 20..20, + TLBIVAE1OS : 19..19, + TLBIVMALLE1OS : 18..18, + ATS1E1WP : 17..17, + ATS1E1RP : 16..16, + ATS1E0W : 15..15, + ATS1E0R : 14..14, + ATS1E1W : 13..13, + ATS1E1R : 12..12, + DCZVA : 11..11, + DCCIVAC : 10..10, + DCCVADP : 9..9, + DCCVAP : 8..8, + DCCVAU : 7..7, + DCCISW : 6..6, + DCCSW : 5..5, + DCISW : 4..4, + DCIVAC : 3..3, + ICIVAU : 2..2, + ICIALLU : 1..1, + ICIALLUIS : 0..0 + } + +register HFGITR_EL2 : HFGITR_EL2_Type + +val CheckGCSSTREnabled : unit -> unit + +function CheckGCSSTREnabled () = { + match PSTATE.EL { + ? if ? == EL0 => { + if GCSCRE0_EL1[STREn] == 0b0 then { + if HCR_EL2[TGE] == 0b0 then { + GCSSTRTrapException(EL1) + } else { + GCSSTRTrapException(EL2) + } + }; + () + }, + ? if ? == EL1 => { + if GCSCR_EL1[STREn] == 0b0 then { + GCSSTRTrapException(EL1) + } else if (EL2Enabled() & (not_bool(HaveEL(EL3)) | SCR_EL3[FGTEn] == 0b1)) & HFGITR_EL2[nGCSSTR_EL1] == 0b0 then { + GCSSTRTrapException(EL2) + } else () + }, + ? if ? == EL2 => { + if GCSCR_EL2[STREn] == 0b0 then { + GCSSTRTrapException(EL2) + }; + () + }, + ? if ? == EL3 => { + if GCSCR_EL3[STREn] == 0b0 then { + GCSSTRTrapException(EL3) + }; + () + }, + _ => () + }; + return() +} + +val CheckMOPSEnabled : unit -> unit + +function CheckMOPSEnabled () = { + if (((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b0 | HCR_EL2[E2H] == 0b0)) & (not_bool(IsHCRXEL2Enabled()) | HCRX_EL2[MSCEn] == 0b0) then { + throw(Error_Undefined()) + }; + if (PSTATE.EL == EL0 & SCTLR_EL1[MSCEn] == 0b0) & ((not_bool(EL2Enabled()) | HCR_EL2[TGE] == 0b0) | HCR_EL2[E2H] == 0b0) then { + throw(Error_Undefined()) + }; + if (PSTATE.EL == EL0 & IsInHost()) & SCTLR_EL2[MSCEn] == 0b0 then { + throw(Error_Undefined()) + }; + () +} + +val MismatchedCpySetTargetEL : unit -> bits(2) + +function MismatchedCpySetTargetEL () = { + target_el : bits(2) = undefined; + if UInt(PSTATE.EL) > UInt(EL1) then { + target_el = PSTATE.EL + } else if (PSTATE.EL == EL0 & EL2Enabled()) & HCR_EL2[TGE] == 0b1 then { + target_el = EL2 + } else if ((PSTATE.EL == EL1 & EL2Enabled()) & IsHCRXEL2Enabled()) & HCRX_EL2[MCE2] == 0b1 then { + target_el = EL2 + } else { + target_el = EL1 + }; + return(target_el) +} + +val MismatchedMemCpyException : forall 'destreg ('from_epilogue : Bool) ('option_a_name : Bool) 'sizereg 'srcreg ('wrong_option : Bool). + (bool('option_a_name), int('destreg), int('srcreg), int('sizereg), bool('wrong_option), bool('from_epilogue), bits(4)) -> unit + +function MismatchedMemCpyException (option_a_name, destreg, srcreg, sizereg, wrong_option, from_epilogue, options_name) = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let target_el : bits(2) = MismatchedCpySetTargetEL(); + except : ExceptionRecord = ExceptionSyndrome(Exception_MemCpyMemSet); + except.syndrome[24] = Bit(0b0); + except.syndrome[23] = Bit(0b0); + except.syndrome[22 .. 19] = options_name; + except.syndrome[18] = Bit(if from_epilogue then 0b1 else 0b0); + except.syndrome[17] = Bit(if wrong_option then 0b1 else 0b0); + except.syndrome[16] = Bit(if option_a_name then 0b1 else 0b0); + except.syndrome[14 .. 10] = destreg[4 .. 0]; + except.syndrome[9 .. 5] = srcreg[4 .. 0]; + except.syndrome[4 .. 0] = sizereg[4 .. 0]; + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val MismatchedMemSetException : forall 'datareg 'destreg ('from_epilogue : Bool) ('is_SETG : Bool) ('option_a_name : Bool) 'sizereg ('wrong_option : Bool). + (bool('option_a_name), int('destreg), int('datareg), int('sizereg), bool('wrong_option), bool('from_epilogue), bits(2), bool('is_SETG)) -> unit + +function MismatchedMemSetException (option_a_name, destreg, datareg, sizereg, wrong_option, from_epilogue, options_name, is_SETG) = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let target_el : bits(2) = MismatchedCpySetTargetEL(); + except : ExceptionRecord = ExceptionSyndrome(Exception_MemCpyMemSet); + except.syndrome[24] = Bit(0b1); + except.syndrome[23] = Bit(if is_SETG then 0b1 else 0b0); + except.syndrome[20 .. 19] = options_name; + except.syndrome[18] = Bit(if from_epilogue then 0b1 else 0b0); + except.syndrome[17] = Bit(if wrong_option then 0b1 else 0b0); + except.syndrome[16] = Bit(if option_a_name then 0b1 else 0b0); + except.syndrome[14 .. 10] = destreg[4 .. 0]; + except.syndrome[9 .. 5] = datareg[4 .. 0]; + except.syndrome[4 .. 0] = sizereg[4 .. 0]; + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val CPYOptionA : unit -> bool + +function CPYOptionA () = { + return(__IMPDEF_boolean("CPY* instructions use Option A")) +} + +val CPYFOptionA : unit -> bool + +function CPYFOptionA () = { + return(__IMPDEF_boolean("CPYF* instructions use Option A")) +} + +val SETOptionA : unit -> bool + +function SETOptionA () = { + return(__IMPDEF_boolean("SET* instructions use Option A")) +} + +val SETGOptionA : unit -> bool + +function SETGOptionA () = { + return(__IMPDEF_boolean("SETG* instructions use Option A")) +} + +val MaxBlockSizeCopiedBytes : unit -> nat + +function MaxBlockSizeCopiedBytes () = { + let 'nbytes = __IMPDEF_integer("Maximum bytes used in a single block of a copy"); + assert(nbytes >= 0); + return(nbytes) +} + +val CPYPreSizeChoice : (bits(64), bits(64), bits(64)) -> bits(64) + +val CPYPostSizeChoice : (bits(64), bits(64), bits(64)) -> bits(64) + +val CPYSizeChoice : (bits(64), bits(64), bits(64)) -> int + +val MemCpyParametersIllformedM : (bits(64), bits(64), bits(64)) -> bool + +val MemCpyParametersIllformedE : (bits(64), bits(64), bits(64)) -> bool + +val SETPreSizeChoice : forall ('IsSETGP : Bool). + (bits(64), bits(64), bool('IsSETGP)) -> bits(64) + +val SETPostSizeChoice : forall ('IsSETGE : Bool). + (bits(64), bits(64), bool('IsSETGE)) -> bits(64) + +val SETSizeChoice : forall 'AlignSize. + (bits(64), bits(64), int('AlignSize)) -> int + +val MemSetParametersIllformedM : forall ('IsSETGM : Bool). + (bits(64), bits(64), bool('IsSETGM)) -> bool + +val MemSetParametersIllformedE : forall ('IsSETGE : Bool). + (bits(64), bits(64), bool('IsSETGE)) -> bool + +val MemCpyDirectionChoice : (bits(64), bits(64), bits(64)) -> bool + +val MemCpyZeroSizeCheck : unit -> bool + +val MemSetZeroSizeCheck : unit -> bool + +val BFRound : forall 'N, 'N == 32. (real, int('N)) -> bits('N) + +function BFRound (op, N) = { + assert(N == 32); + assert(op != 0.0); + result : bits('N) = undefined; + let 'minimum_exp = negate(126); + let 'E = 8; + let 'F = 23; + sign : bits(1) = undefined; + mantissa : real = undefined; + if op < 0.0 then { + sign = 0b1; + mantissa = neg_real(op) + } else { + sign = 0b0; + mantissa = op + }; + exponent : int = 0; + while mantissa < 1.0 do { + mantissa = mantissa * 2.0; + exponent = exponent - 1 + }; + while mantissa >= 2.0 do { + mantissa = mantissa / 2.0; + exponent = exponent + 1 + }; + let 'exponent = exponent; + if exponent < minimum_exp then { + return(FPZero(sign, N)) + }; + let 'biased_exp = Max(exponent - minimum_exp + 1, 0); + if biased_exp == 0 then { + mantissa = mantissa / 2.0 ^ (minimum_exp - exponent) + }; + let mantissa = mantissa; + int_mant : int = RoundDown(mantissa * 2.0 ^ F); + let error : real = mantissa * 2.0 ^ F - Real(int_mant); + if error != 0.0 then { + int_mant = [int_mant with 0 .. 0 = 0b1] + }; + let 'int_mant = int_mant; + if biased_exp >= pow2(E) - 1 then { + result = FPInfinity(sign, N) + } else { + result = (sign @ biased_exp[N - 2 - F .. 0]) @ int_mant[F - 1 .. 0] + }; + return(result) +} + +val BFUnpack : forall 'N, 'N in {16, 32}. bits('N) -> (FPType, bits(1), real) + +function BFUnpack fpval = { + assert('N == 16 | 'N == 32); + sign : bits(1) = undefined; + exp : bits(8) = undefined; + frac : bits(23) = undefined; + if 'N == 16 then { + sign = [fpval[15]]; + exp = fpval[14 .. 7]; + frac = fpval[6 .. 0] @ Zeros(16) + } else { + sign = [fpval[31]]; + exp = fpval[30 .. 23]; + frac = fpval[22 .. 0] + }; + fptype : FPType = undefined; + value_name : real = undefined; + if IsZero(exp) then { + fptype = FPType_Zero; + value_name = 0.0 + } else if IsOnes(exp) then { + if IsZero(frac) then { + fptype = FPType_Infinity; + value_name = 2.0 ^ 1000000 + } else { + fptype = FPType_QNaN; + value_name = 0.0 + } + } else { + fptype = FPType_Nonzero; + value_name = 2.0 ^ (UInt(exp) - 127) * (1.0 + Real(UInt(frac)) * 2.0 ^ negate(23)) + }; + if sign == 0b1 then { + value_name = neg_real(value_name) + }; + let value_name = value_name; + return((fptype, sign, value_name)) +} + +val BFMulH : forall 'N, 'N == 16. (bits('N), bits('N)) -> bits(2 * 'N) + +function BFMulH (op1, op2) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16); + result : bits(2 * 'N) = undefined; + let fpcr : FPCRType = FPCR_read(); + (type1, sign1, value1_name) = BFUnpack(op1); + (type2, sign2, value2_name) = BFUnpack(op2); + if type1 == FPType_QNaN | type2 == FPType_QNaN then { + result = FPDefaultNaN__1(fpcr, 2 * 'N) + } else { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if inf1 & zero2 | zero1 & inf2 then { + result = FPDefaultNaN__1(fpcr, 2 * 'N) + } else if inf1 | inf2 then { + result = FPInfinity(EOR(sign1, sign2), 2 * 'N) + } else if zero1 | zero2 then { + result = FPZero(EOR(sign1, sign2), 2 * 'N) + } else { + result = BFRound(value1_name * value2_name, 2 * 'N) + } + }; + return(result) +} + +val FPAdd_BF16 : forall 'N, 'N == 32. (bits('N), bits('N)) -> bits('N) + +function FPAdd_BF16 (op1, op2) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 32); + result : bits('N) = undefined; + let fpcr : FPCRType = FPCR_read(); + (type1, sign1, value1_name) = BFUnpack(op1); + (type2, sign2, value2_name) = BFUnpack(op2); + if type1 == FPType_QNaN | type2 == FPType_QNaN then { + result = FPDefaultNaN__1(fpcr, 'N) + } else { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if (inf1 & inf2) & sign1 == not_vec(sign2) then { + result = FPDefaultNaN__1(fpcr, 'N) + } else if inf1 & sign1 == 0b0 | inf2 & sign2 == 0b0 then { + result = FPInfinity(0b0, 'N) + } else if inf1 & sign1 == 0b1 | inf2 & sign2 == 0b1 then { + result = FPInfinity(0b1, 'N) + } else if (zero1 & zero2) & sign1 == sign2 then { + result = FPZero(sign1, 'N) + } else { + let result_value : real = value1_name + value2_name; + if result_value == 0.0 then { + result = FPZero(0b0, 'N) + } else { + result = BFRound(result_value, 'N) + } + } + }; + return(result) +} + +val BFMulAddH : forall 'N, 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), FPCRType) -> bits('N) + +function BFMulAddH (addend, op1, op2, fpcr_in) = { + assert('N == 32); + let value1_name : bits('N) = op1 @ Zeros(DIV('N, 2)); + let value2_name : bits('N) = op2 @ Zeros(DIV('N, 2)); + fpcr : FPCRType = fpcr_in; + let altfp : bool = HaveAltFP() & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + if altfp then { + (fpcr[FIZ] @ fpcr[FZ]) = 0b11 + }; + if altfp then { + fpcr[RMode] = 0b00 + }; + return(FPMulAdd__1(addend, value1_name, value2_name, fpcr, fpexc)) +} + +val BFMulAddH_ZA : forall 'N, 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), FPCRType) -> bits('N) + +function BFMulAddH_ZA (addend, op1, op2, fpcr) = { + assert('N == 32); + let value1_name : bits('N) = op1 @ Zeros(DIV('N, 2)); + let value2_name : bits('N) = op2 @ Zeros(DIV('N, 2)); + return(FPMulAdd_ZA(addend, value1_name, value2_name, fpcr)) +} + +val FPRoundBF : forall 'N ('fpexc : Bool), 'N == 32. + (real, FPCRType, FPRounding, bool('fpexc), int('N)) -> bits('N) + +function FPRoundBF (op, fpcr, rounding, fpexc, N) = { + assert(N == 32); + let isbfloat16 : bool = true; + return(FPRoundBase__1(op, fpcr, rounding, isbfloat16, fpexc, N)) +} + +val FPConvertBF : forall 'N, 'N == 32. + (bits('N), FPCRType, FPRounding) -> bits(div('N, 2)) + +val FPConvertBF__1 : forall 'N, 'N == 32. + (bits('N), FPCRType) -> bits(div('N, 2)) + +function FPConvertBF (op, fpcr_in, rounding_in) = { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + assert('N == 32); + let 'halfsize = DIV('N, 2); + fpcr : FPCRType = fpcr_in; + rounding : FPRounding = rounding_in; + result : bits('N) = undefined; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let fpexc : bool = not_bool(altfp); + if altfp then { + (fpcr[FIZ] @ fpcr[FZ]) = 0b11 + }; + if altfp then { + rounding = FPRounding_TIEEVEN + }; + (fptype, sign, value_name) = FPUnpack__1(op, fpcr, fpexc); + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + if fpcr[DN] == 0b1 then { + result = FPDefaultNaN__1(fpcr, 'N) + } else { + result = FPConvertNaN(op, 'N) + }; + if fptype == FPType_SNaN then { + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + }; + () + } else if fptype == FPType_Infinity then { + result = FPInfinity(sign, 'N) + } else if fptype == FPType_Zero then { + result = FPZero(sign, 'N) + } else { + result = FPRoundBF(value_name, fpcr, rounding, fpexc, 'N) + }; + return(result[2 * halfsize - 1 .. halfsize]) +} + +function FPConvertBF__1 (op, fpcr) = { + return(FPConvertBF(op, fpcr, FPRoundingMode(fpcr))) +} + +val FPProcessNaNs4 : forall 'N ('fpexc : Bool), 'N == 32. + (FPType, FPType, FPType, FPType, bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), FPCRType, bool('fpexc)) -> (bool, bits('N)) + +function FPProcessNaNs4 (type1, type2, type3, type4, op1, op2, op3, op4, fpcr, fpexc) = { + assert('N == 32); + result : bits('N) = undefined; + done : bool = undefined; + if type1 == FPType_SNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type1, op1, fpcr, fpexc), 'N) + } else if type2 == FPType_SNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type2, op2, fpcr, fpexc), 'N) + } else if type3 == FPType_SNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type3, op3, fpcr, fpexc), 'N) + } else if type4 == FPType_SNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type4, op4, fpcr, fpexc), 'N) + } else if type1 == FPType_QNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type1, op1, fpcr, fpexc), 'N) + } else if type2 == FPType_QNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type2, op2, fpcr, fpexc), 'N) + } else if type3 == FPType_QNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type3, op3, fpcr, fpexc), 'N) + } else if type4 == FPType_QNaN then { + done = true; + result = FPConvertNaN(FPProcessNaN__1(type4, op4, fpcr, fpexc), 'N) + } else { + done = false; + result = Zeros('N) + }; + return((done, result)) +} + +val FPDot__1 : forall 'N ('fpexc : Bool) ('isbfloat16 : Bool), + 'N == 32. + (bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), FPCRType, bool('isbfloat16), bool('fpexc)) -> bits('N) + +function FPDot__1 (op1_a, op1_b, op2_a, op2_b, fpcr_in, isbfloat16, fpexc) = { + infPa : bool = undefined; + infPb : bool = undefined; + invalidop : bool = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1_a : bits(1) = undefined; + sign1_b : bits(1) = undefined; + sign2_a : bits(1) = undefined; + sign2_b : bits(1) = undefined; + signPa : bits(1) = undefined; + signPb : bits(1) = undefined; + type1_a : FPType = undefined; + type1_b : FPType = undefined; + type2_a : FPType = undefined; + type2_b : FPType = undefined; + value1_a_name : real = undefined; + value1_b_name : real = undefined; + value2_a_name : real = undefined; + value2_b_name : real = undefined; + zeroPa : bool = undefined; + zeroPb : bool = undefined; + fpcr : FPCRType = fpcr_in; + assert('N == 32); + result : bits('N) = undefined; + done : bool = undefined; + fpcr[AHP] = 0b0; + let rounding : FPRounding = FPRoundingMode(fpcr); + (type1_a, sign1_a, value1_a_name) = FPUnpackBase__1(op1_a, fpcr, fpexc, isbfloat16); + (type1_b, sign1_b, value1_b_name) = FPUnpackBase__1(op1_b, fpcr, fpexc, isbfloat16); + (type2_a, sign2_a, value2_a_name) = FPUnpackBase__1(op2_a, fpcr, fpexc, isbfloat16); + (type2_b, sign2_b, value2_b_name) = FPUnpackBase__1(op2_b, fpcr, fpexc, isbfloat16); + let inf1_a : bool = type1_a == FPType_Infinity; + let zero1_a : bool = type1_a == FPType_Zero; + let inf1_b : bool = type1_b == FPType_Infinity; + let zero1_b : bool = type1_b == FPType_Zero; + let inf2_a : bool = type2_a == FPType_Infinity; + let zero2_a : bool = type2_a == FPType_Zero; + let inf2_b : bool = type2_b == FPType_Infinity; + let zero2_b : bool = type2_b == FPType_Zero; + (done, result) = FPProcessNaNs4(type1_a, type1_b, type2_a, type2_b, op1_a, op1_b, op2_a, op2_b, fpcr, fpexc); + if (inf1_a & zero2_a | zero1_a & inf2_a) & (inf1_b & zero2_b | zero1_b & inf2_b) then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + }; + if not_bool(done) then { + let signPa : bits(1) = EOR(sign1_a, sign2_a); + let signPb : bits(1) = EOR(sign1_b, sign2_b); + let infPa : bool = inf1_a | inf2_a; + let infPb : bool = inf1_b | inf2_b; + let zeroPa : bool = zero1_a | zero2_a; + let zeroPb : bool = zero1_b | zero2_b; + let invalidop : bool = (((inf1_a & zero2_a | zero1_a & inf2_a) | inf1_b & zero2_b) | zero1_b & inf2_b) | (infPa & infPb) & signPa != signPb; + if invalidop then { + result = FPDefaultNaN__1(fpcr, 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if infPa & signPa == 0b0 | infPb & signPb == 0b0 then { + result = FPInfinity(0b0, 'N) + } else if infPa & signPa == 0b1 | infPb & signPb == 0b1 then { + result = FPInfinity(0b1, 'N) + } else if (zeroPa & zeroPb) & signPa == signPb then { + result = FPZero(signPa, 'N) + } else { + let result_value : real = value1_a_name * value2_a_name + value1_b_name * value2_b_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 'N) + } else { + result = FPRound__2(result_value, fpcr, rounding, fpexc, 'N) + } + } + }; + return(result) +} + +val BFDotAdd : forall 'N, 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), FPCRType) -> bits('N) + +function BFDotAdd (addend, op1_a, op1_b, op2_a, op2_b, fpcr_in) = { + assert('N == 32); + fpcr : FPCRType = fpcr_in; + prod : bits('N) = undefined; + result : bits('N) = undefined; + if not_bool(HaveEBF16()) | fpcr[EBF] == 0b0 then { + let prod : bits('N) = FPAdd_BF16(BFMulH(op1_a, op2_a), BFMulH(op1_b, op2_b)); + result = FPAdd_BF16(addend, prod) + } else { + let isbfloat16 : bool = true; + let fpexc : bool = false; + fpcr[DN] = 0b1; + let prod : bits('N) = FPDot__1(op1_a, op1_b, op2_a, op2_b, fpcr, isbfloat16, fpexc); + result = FPAdd__1(addend, prod, fpcr, fpexc) + }; + return(result) +} + +val BFMatMulAdd : forall 'N, 'N == 128. + (bits('N), bits('N), bits('N)) -> bits('N) + +function BFMatMulAdd (addend, op1, op2) = { + assert('N == 128); + result : bits('N) = undefined; + sum : bits(32) = undefined; + foreach (i from 0 to 1 by 1 in inc) { + foreach (j from 0 to 1 by 1 in inc) { + sum = Elem_read(addend, 2 * i + j, 32); + foreach (k from 0 to 1 by 1 in inc) { + let elt1_a : bits(16) = Elem_read(op1, 4 * i + 2 * k + 0, 16); + let elt1_b : bits(16) = Elem_read(op1, 4 * i + 2 * k + 1, 16); + let elt2_a : bits(16) = Elem_read(op2, 4 * j + 2 * k + 0, 16); + let elt2_b : bits(16) = Elem_read(op2, 4 * j + 2 * k + 1, 16); + sum = BFDotAdd(sum, elt1_a, elt1_b, elt2_a, elt2_b, FPCR_read()) + }; + result = Elem_set(result, 2 * i + j, 32, sum) + } + }; + return(result) +} + +val BFNeg : forall 'N, 'N == 16. bits('N) -> bits('N) + +val BFNeg__1 : forall 'N ('honor_altfp : Bool), 'N == 16. + (bits('N), bool('honor_altfp)) -> bits('N) + +function BFNeg op = { + assert('N == 16); + let honor_altfp : bool = true; + return(BFNeg__1(op, honor_altfp)) +} + +function BFNeg__1 (op, honor_altfp) = { + fptype : FPType = undefined; + assert('N == 16); + if (honor_altfp & not_bool(UsingAArch32())) & HaveAltFP() then { + let fpcr : FPCRType = FPCR_read(); + if fpcr[AH] == 0b1 then { + let fpexc : bool = false; + let isbfloat16 : bool = true; + let (__tup_0 : FPType, _, _) = + FPUnpackBase__1(op, fpcr, fpexc, isbfloat16) + in + { + fptype = __tup_0 + }; + if fptype == FPType_SNaN | fptype == FPType_QNaN then { + return(op) + }; + () + }; + () + }; + return(not_vec([op['N - 1]]) @ op['N - 2 .. 0]) +} + +val BFInfinity : forall 'N, 'N == 16. (bits(1), int('N)) -> bits('N) + +function BFInfinity (sign, N) = { + assert(N == 16); + let 'E = 8; + let 'F = N - (E + 1); + return((sign @ Ones(E)) @ Zeros(F)) +} + +val BFZero : forall 'N, 'N == 16. (bits(1), int('N)) -> bits('N) + +function BFZero (sign, N) = { + assert(N == 16); + let 'E = 8; + let 'F = N - (E + 1); + return((sign @ Zeros(E)) @ Zeros(F)) +} + +val BFAdd : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +val BFAdd__1 : forall 'N ('fpexc : Bool), 'N == 16. + (bits('N), bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function BFAdd (op1, op2, fpcr) = { + let fpexc : bool = true; + return(BFAdd__1(op1, op2, fpcr, fpexc)) +} + +function BFAdd__1 (op1, op2, fpcr, fpexc) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16); + let rounding : FPRounding = FPRoundingMode(fpcr); + done : bool = undefined; + result : bits(2 * 'N) = undefined; + let op1_s : bits(2 * 'N) = op1 @ Zeros('N); + let op2_s : bits(2 * 'N) = op2 @ Zeros('N); + (type1, sign1, value1_name) = FPUnpack__1(op1_s, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2_s, fpcr, fpexc); + (done, result) = FPProcessNaNs__1(type1, type2, op1_s, op2_s, fpcr, fpexc); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if (inf1 & inf2) & sign1 == not_vec(sign2) then { + result = FPDefaultNaN__1(fpcr, 2 * 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if inf1 & sign1 == 0b0 | inf2 & sign2 == 0b0 then { + result = FPInfinity(0b0, 2 * 'N) + } else if inf1 & sign1 == 0b1 | inf2 & sign2 == 0b1 then { + result = FPInfinity(0b1, 2 * 'N) + } else if (zero1 & zero2) & sign1 == sign2 then { + result = FPZero(sign1, 2 * 'N) + } else { + let result_value : real = value1_name + value2_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 2 * 'N) + } else { + result = FPRoundBF(result_value, fpcr, rounding, fpexc, 2 * 'N) + } + }; + if fpexc then { + FPProcessDenorms(type1, type2, 2 * 'N, fpcr) + }; + () + }; + return(result[2 * 'N - 1 .. 'N]) +} + +val BFAdd_ZA : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +function BFAdd_ZA (op1, op2, fpcr_in) = { + let fpexc : bool = false; + fpcr : FPCRType = fpcr_in; + fpcr[DN] = 0b1; + return(BFAdd__1(op1, op2, fpcr, fpexc)) +} + +val BFSub : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +val BFSub__1 : forall 'N ('fpexc : Bool), 'N == 16. + (bits('N), bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function BFSub (op1, op2, fpcr) = { + let fpexc : bool = true; + return(BFSub__1(op1, op2, fpcr, fpexc)) +} + +function BFSub__1 (op1, op2, fpcr, fpexc) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16); + let rounding : FPRounding = FPRoundingMode(fpcr); + done : bool = undefined; + result : bits(2 * 'N) = undefined; + let op1_s : bits(2 * 'N) = op1 @ Zeros('N); + let op2_s : bits(2 * 'N) = op2 @ Zeros('N); + (type1, sign1, value1_name) = FPUnpack__1(op1_s, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2_s, fpcr, fpexc); + (done, result) = FPProcessNaNs__1(type1, type2, op1_s, op2_s, fpcr, fpexc); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if (inf1 & inf2) & sign1 == sign2 then { + result = FPDefaultNaN__1(fpcr, 2 * 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if inf1 & sign1 == 0b0 | inf2 & sign2 == 0b1 then { + result = FPInfinity(0b0, 2 * 'N) + } else if inf1 & sign1 == 0b1 | inf2 & sign2 == 0b0 then { + result = FPInfinity(0b1, 2 * 'N) + } else if (zero1 & zero2) & sign1 == not_vec(sign2) then { + result = FPZero(sign1, 2 * 'N) + } else { + let result_value : real = value1_name - value2_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 2 * 'N) + } else { + result = FPRoundBF(result_value, fpcr, rounding, fpexc, 2 * 'N) + } + }; + if fpexc then { + FPProcessDenorms(type1, type2, 2 * 'N, fpcr) + }; + () + }; + return(result[2 * 'N - 1 .. 'N]) +} + +val BFSub_ZA : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +function BFSub_ZA (op1, op2, fpcr_in) = { + let fpexc : bool = false; + fpcr : FPCRType = fpcr_in; + fpcr[DN] = 0b1; + return(BFSub__1(op1, op2, fpcr, fpexc)) +} + +val BFMulAdd : forall 'N, 'N == 16. + (bits('N), bits('N), bits('N), FPCRType) -> bits('N) + +val BFMulAdd__1 : forall 'N ('fpexc : Bool), 'N == 16. + (bits('N), bits('N), bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function BFMulAdd (addend, op1, op2, fpcr) = { + let fpexc : bool = true; + return(BFMulAdd__1(addend, op1, op2, fpcr, fpexc)) +} + +function BFMulAdd__1 (addend, op1, op2, fpcr, fpexc) = { + infA : bool = undefined; + infP : bool = undefined; + invalidop : bool = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + signA : bits(1) = undefined; + signP : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + typeA : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + valueA_name : real = undefined; + zeroA : bool = undefined; + zeroP : bool = undefined; + assert('N == 16); + let rounding : FPRounding = FPRoundingMode(fpcr); + done : bool = undefined; + result : bits(2 * 'N) = undefined; + let addend_s : bits(2 * 'N) = addend @ Zeros('N); + let op1_s : bits(2 * 'N) = op1 @ Zeros('N); + let op2_s : bits(2 * 'N) = op2 @ Zeros('N); + (typeA, signA, valueA_name) = FPUnpack__1(addend_s, fpcr, fpexc); + (type1, sign1, value1_name) = FPUnpack__1(op1_s, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2_s, fpcr, fpexc); + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + (done, result) = FPProcessNaNs3__1(typeA, type1, type2, addend_s, op1_s, op2_s, fpcr, fpexc); + if not_bool((HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1) then { + if typeA == FPType_QNaN & (inf1 & zero2 | zero1 & inf2) then { + result = FPDefaultNaN__1(fpcr, 2 * 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + }; + () + }; + if not_bool(done) then { + let infA : bool = typeA == FPType_Infinity; + let zeroA : bool = typeA == FPType_Zero; + let signP : bits(1) = EOR(sign1, sign2); + let infP : bool = inf1 | inf2; + let zeroP : bool = zero1 | zero2; + let invalidop : bool = (inf1 & zero2 | zero1 & inf2) | (infA & infP) & signA != signP; + if invalidop then { + result = FPDefaultNaN__1(fpcr, 2 * 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if infA & signA == 0b0 | infP & signP == 0b0 then { + result = FPInfinity(0b0, 2 * 'N) + } else if infA & signA == 0b1 | infP & signP == 0b1 then { + result = FPInfinity(0b1, 2 * 'N) + } else if (zeroA & zeroP) & signA == signP then { + result = FPZero(signA, 2 * 'N) + } else { + let result_value : real = valueA_name + value1_name * value2_name; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 2 * 'N) + } else { + result = FPRoundBF(result_value, fpcr, rounding, fpexc, 2 * 'N) + } + }; + if not_bool(invalidop) & fpexc then { + FPProcessDenorms3(typeA, type1, type2, 2 * 'N, fpcr) + }; + () + }; + return(result[2 * 'N - 1 .. 'N]) +} + +val BFMulAdd_ZA : forall 'N, 'N == 16. + (bits('N), bits('N), bits('N), FPCRType) -> bits('N) + +function BFMulAdd_ZA (addend, op1, op2, fpcr_in) = { + let fpexc : bool = false; + fpcr : FPCRType = fpcr_in; + fpcr[DN] = 0b1; + return(BFMulAdd__1(addend, op1, op2, fpcr, fpexc)) +} + +val BFMul : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +val BFMul__1 : forall 'N ('fpexc : Bool), 'N == 16. + (bits('N), bits('N), FPCRType, bool('fpexc)) -> bits('N) + +function BFMul (op1, op2, fpcr) = { + let fpexc : bool = true; + return(BFMul__1(op1, op2, fpcr, fpexc)) +} + +function BFMul__1 (op1, op2, fpcr, fpexc) = { + inf1 : bool = undefined; + inf2 : bool = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16); + let rounding : FPRounding = FPRoundingMode(fpcr); + done : bool = undefined; + result : bits(2 * 'N) = undefined; + let op1_s : bits(2 * 'N) = op1 @ Zeros('N); + let op2_s : bits(2 * 'N) = op2 @ Zeros('N); + (type1, sign1, value1_name) = FPUnpack__1(op1_s, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2_s, fpcr, fpexc); + (done, result) = FPProcessNaNs__1(type1, type2, op1_s, op2_s, fpcr, fpexc); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if inf1 & zero2 | zero1 & inf2 then { + result = FPDefaultNaN__1(fpcr, 2 * 'N); + if fpexc then { + FPProcessException(FPExc_InvalidOp, fpcr) + }; + () + } else if inf1 | inf2 then { + result = FPInfinity(EOR(sign1, sign2), 2 * 'N) + } else if zero1 | zero2 then { + result = FPZero(EOR(sign1, sign2), 2 * 'N) + } else { + result = FPRoundBF(value1_name * value2_name, fpcr, rounding, fpexc, 2 * 'N) + }; + if fpexc then { + FPProcessDenorms(type1, type2, 2 * 'N, fpcr) + }; + () + }; + return(result[2 * 'N - 1 .. 'N]) +} + +val BFMin : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +val BFMin__1 : forall 'N ('altfp : Bool), 'N == 16. + (bits('N), bits('N), FPCRType, bool('altfp)) -> bits('N) + +function BFMin (op1, op2, fpcr) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + return(BFMin__1(op1, op2, fpcr, altfp)) +} + +function BFMin__1 (op1, op2, fpcr_in, altfp) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16); + fpcr : FPCRType = fpcr_in; + let fpexc : bool = true; + let rounding : FPRounding = FPRoundingMode(fpcr); + done : bool = undefined; + result : bits(2 * 'N) = undefined; + let op1_s : bits(2 * 'N) = op1 @ Zeros('N); + let op2_s : bits(2 * 'N) = op2 @ Zeros('N); + (type1, sign1, value1_name) = FPUnpack__1(op1_s, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2_s, fpcr, fpexc); + if ((altfp & type1 == FPType_Zero) & type2 == FPType_Zero) & sign1 != sign2 then { + return(BFZero(sign2, 'N)) + } else if altfp & ((type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN) then { + FPProcessException(FPExc_InvalidOp, fpcr); + return(if type2 == FPType_Zero then BFZero(sign2, 'N) else op2) + } else (); + (done, result) = FPProcessNaNs(type1, type2, op1_s, op2_s, fpcr); + if not_bool(done) then { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + if value1_name < value2_name then { + (fptype, sign, value_name) = (type1, sign1, value1_name) + } else { + (fptype, sign, value_name) = (type2, sign2, value2_name) + }; + if fptype == FPType_Infinity then { + result = FPInfinity(sign, 2 * 'N) + } else if fptype == FPType_Zero then { + let sign : bits(1) = sign1 | sign2; + result = FPZero(sign, 2 * 'N) + } else { + if altfp then { + fpcr[FZ] = 0b0 + }; + result = FPRoundBF(value_name, fpcr, rounding, fpexc, 2 * 'N) + }; + if fpexc then { + FPProcessDenorms(type1, type2, 2 * 'N, fpcr) + }; + () + }; + return(result[2 * 'N - 1 .. 'N]) +} + +val BFMinNum : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +function BFMinNum (op1_in, op2_in, fpcr) = { + type1 : FPType = undefined; + type2 : FPType = undefined; + assert('N == 16); + let fpexc : bool = true; + let isbfloat16 : bool = true; + op1 : bits('N) = op1_in; + op2 : bits('N) = op2_in; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let (__tup_0 : FPType, _, _) = FPUnpackBase__1(op1, fpcr, fpexc, isbfloat16) + in + { + type1 = __tup_0 + }; + let (__tup_0 : FPType, _, _) = FPUnpackBase__1(op2, fpcr, fpexc, isbfloat16) + in + { + type2 = __tup_0 + }; + let type1_nan : bool = type1 == FPType_QNaN | type1 == FPType_SNaN; + let type2_nan : bool = type2 == FPType_QNaN | type2 == FPType_SNaN; + if not_bool((altfp & type1_nan) & type2_nan) then { + if type1 == FPType_QNaN & type2 != FPType_QNaN then { + op1 = BFInfinity(0b0, 'N) + } else if type1 != FPType_QNaN & type2 == FPType_QNaN then { + op2 = BFInfinity(0b0, 'N) + } else () + }; + let altfmaxfmin : bool = false; + let result : bits('N) = BFMin__1(op1, op2, fpcr, altfmaxfmin); + return(result) +} + +val BFMax : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +val BFMax__1 : forall 'N ('altfp : Bool), 'N == 16. + (bits('N), bits('N), FPCRType, bool('altfp)) -> bits('N) + +function BFMax (op1, op2, fpcr) = { + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + return(BFMax__1(op1, op2, fpcr, altfp)) +} + +function BFMax__1 (op1, op2, fpcr_in, altfp) = { + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + assert('N == 16); + fpcr : FPCRType = fpcr_in; + let fpexc : bool = true; + let rounding : FPRounding = FPRoundingMode(fpcr); + done : bool = undefined; + result : bits(2 * 'N) = undefined; + let op1_s : bits(2 * 'N) = op1 @ Zeros('N); + let op2_s : bits(2 * 'N) = op2 @ Zeros('N); + (type1, sign1, value1_name) = FPUnpack__1(op1_s, fpcr, fpexc); + (type2, sign2, value2_name) = FPUnpack__1(op2_s, fpcr, fpexc); + if ((altfp & type1 == FPType_Zero) & type2 == FPType_Zero) & sign1 != sign2 then { + return(BFZero(sign2, 'N)) + } else if altfp & ((type1 == FPType_SNaN | type1 == FPType_QNaN) | type2 == FPType_SNaN | type2 == FPType_QNaN) then { + FPProcessException(FPExc_InvalidOp, fpcr); + return(if type2 == FPType_Zero then BFZero(sign2, 'N) else op2) + } else (); + (done, result) = FPProcessNaNs(type1, type2, op1_s, op2_s, fpcr); + if not_bool(done) then { + fptype : FPType = undefined; + sign : bits(1) = undefined; + value_name : real = undefined; + if value1_name > value2_name then { + (fptype, sign, value_name) = (type1, sign1, value1_name) + } else { + (fptype, sign, value_name) = (type2, sign2, value2_name) + }; + if fptype == FPType_Infinity then { + result = FPInfinity(sign, 2 * 'N) + } else if fptype == FPType_Zero then { + let sign : bits(1) = sign1 & sign2; + result = FPZero(sign, 2 * 'N) + } else { + if altfp then { + fpcr[FZ] = 0b0 + }; + result = FPRoundBF(value_name, fpcr, rounding, fpexc, 2 * 'N) + }; + if fpexc then { + FPProcessDenorms(type1, type2, 2 * 'N, fpcr) + }; + () + }; + return(result[2 * 'N - 1 .. 'N]) +} + +val BFMaxNum : forall 'N, 'N == 16. (bits('N), bits('N), FPCRType) -> bits('N) + +function BFMaxNum (op1_in, op2_in, fpcr) = { + type1 : FPType = undefined; + type2 : FPType = undefined; + assert('N == 16); + let fpexc : bool = true; + let isbfloat16 : bool = true; + op1 : bits('N) = op1_in; + op2 : bits('N) = op2_in; + let altfp : bool = (HaveAltFP() & not_bool(UsingAArch32())) & fpcr[AH] == 0b1; + let (__tup_0 : FPType, _, _) = FPUnpackBase__1(op1, fpcr, fpexc, isbfloat16) + in + { + type1 = __tup_0 + }; + let (__tup_0 : FPType, _, _) = FPUnpackBase__1(op2, fpcr, fpexc, isbfloat16) + in + { + type2 = __tup_0 + }; + let type1_nan : bool = type1 == FPType_QNaN | type1 == FPType_SNaN; + let type2_nan : bool = type2 == FPType_QNaN | type2 == FPType_SNaN; + if not_bool((altfp & type1_nan) & type2_nan) then { + if type1 == FPType_QNaN & type2 != FPType_QNaN then { + op1 = BFInfinity(0b1, 'N) + } else if type1 != FPType_QNaN & type2 == FPType_QNaN then { + op2 = BFInfinity(0b1, 'N) + } else () + }; + let altfmaxfmin : bool = false; + let result : bits('N) = BFMax__1(op1, op2, fpcr, altfmaxfmin); + return(result) +} + +val FPMatMulAdd : forall 'N 'esize, + 'N >= 0 & ('esize == 16 | 'esize == 32 | 'esize == 64 | not('N == 'esize * 2 * 2)). + (bits('N), bits('N), bits('N), int('esize), FPCRType) -> bits('N) + +function FPMatMulAdd (addend, op1, op2, esize, fpcr) = { + assert('N == esize * 2 * 2); + result : bits('N) = undefined; + prod0 : bits('esize) = undefined; + prod1 : bits('esize) = undefined; + sum : bits('esize) = undefined; + foreach (i from 0 to 1 by 1 in inc) { + foreach (j from 0 to 1 by 1 in inc) { + assert(constraint(((2 * 'loop_i + 'loop_j) * 'esize <= (2 * 'loop_i + 'loop_j) * 'esize + 'esize - 1 | not((2 * 'loop_i + 'loop_j >= 0 & (2 * 'loop_i + 'loop_j + 1) * 'esize <= 'N)) | not('N == 'esize * 2 * 2)))); + sum = Elem_read(addend, 2 * i + j, esize); + prod0 = FPMul(Elem_read(op1, 2 * i + 0, esize), Elem_read(op2, 2 * j + 0, esize), fpcr); + prod1 = FPMul(Elem_read(op1, 2 * i + 1, esize), Elem_read(op2, 2 * j + 1, esize), fpcr); + sum = FPAdd(sum, FPAdd(prod0, prod1, fpcr), fpcr); + result = Elem_set(result, 2 * i + j, esize, sum) + } + }; + return(result) +} + +val FPDotAdd : forall 'N, 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), FPCRType) -> bits('N) + +function FPDotAdd (addend, op1_a, op1_b, op2_a, op2_b, fpcr) = { + assert('N == 32); + let isbfloat16 : bool = false; + let fpexc : bool = true; + let prod : bits('N) = FPDot__1(op1_a, op1_b, op2_a, op2_b, fpcr, isbfloat16, fpexc); + let result : bits('N) = FPAdd__1(addend, prod, fpcr, fpexc); + return(result) +} + +val FPDotAdd_ZA : forall 'N, 'N == 32. + (bits('N), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), bits(div('N, 2)), FPCRType) -> bits('N) + +function FPDotAdd_ZA (addend, op1_a, op1_b, op2_a, op2_b, fpcr_in) = { + fpcr : FPCRType = fpcr_in; + assert('N == 32); + let isbfloat16 : bool = false; + let fpexc : bool = false; + fpcr[DN] = 0b1; + let prod : bits('N) = FPDot__1(op1_a, op1_b, op2_a, op2_b, fpcr, isbfloat16, fpexc); + let result : bits('N) = FPAdd__1(addend, prod, fpcr, fpexc); + return(result) +} + +val AArch32_PhysicalSErrorSyndrome : unit -> bits(16) + +function AArch32_PhysicalSErrorSyndrome () = { + syndrome : bits(32) = Zeros(32); + let fault : FaultRecord = GetPendingPhysicalSError(); + if PSTATE.EL == EL2 then { + let errstate : ErrorState = AArch32_PEErrorState(fault); + syndrome[11 .. 10] = AArch32_EncodeAsyncErrorSyndrome(errstate); + syndrome[9] = Bit(fault.extflag); + syndrome[5 .. 0] = 0b010001 + } else { + let long_format : bool = TTBCR_read()[EAE] == 0b1; + syndrome = AArch32_CommonFaultStatus(fault, long_format) + }; + return(syndrome[15 .. 0]) +} + +val AArch64_EncodeAsyncErrorSyndrome : ErrorState -> bits(3) + +function AArch64_EncodeAsyncErrorSyndrome errorstate = { + match errorstate { + ErrorState_UC => { + return(0b000) + }, + ErrorState_UEU => { + return(0b001) + }, + ErrorState_UEO => { + return(0b010) + }, + ErrorState_UER => { + return(0b011) + }, + ErrorState_CE => { + return(0b110) + }, + _ => { + Unreachable(); + return(undefined : bits(3)) + } + } +} + +val AArch64_PhysicalSErrorSyndrome : forall ('implicit_esb : Bool). + bool('implicit_esb) -> bits(25) + +function AArch64_PhysicalSErrorSyndrome implicit_esb = { + syndrome : bits(25) = Zeros(25); + let fault : FaultRecord = GetPendingPhysicalSError(); + let errorstate : ErrorState = AArch64_PEErrorState(fault); + if errorstate == ErrorState_Uncategorized then { + syndrome = Zeros(25) + } else if errorstate == ErrorState_IMPDEF then { + syndrome[24] = Bit(0b1); + syndrome[23 .. 0] = __IMPDEF_bits(24, "IMPDEF ErrorState") + } else { + syndrome[24] = Bit(0b0); + syndrome[13] = Bit(if implicit_esb then 0b1 else 0b0); + syndrome[12 .. 10] = AArch64_EncodeAsyncErrorSyndrome(errorstate); + syndrome[9] = Bit(fault.extflag); + syndrome[5 .. 0] = 0b010001 + }; + return(syndrome) +} + +val AArch64_PhysicalSErrorTarget : unit -> (bool, bits(2)) + +function AArch64_PhysicalSErrorTarget () = { + route_to_el3 : bool = undefined; + route_to_el2 : bool = undefined; + if PSTATE.EL != EL3 then { + route_to_el3 = HaveEL(EL3) & EffectiveEA() == 0b1 + } else { + route_to_el3 = false + }; + if (not_bool(route_to_el3) & EL2Enabled()) & PSTATE.EL == EL1 then { + route_to_el2 = HCR_EL2[AMO] == 0b1 + } else if (not_bool(route_to_el3) & EL2Enabled()) & PSTATE.EL == EL0 then { + route_to_el2 = not_bool(IsInHost()) & (HCR_EL2[TGE] @ HCR_EL2[AMO]) != 0b00 + } else { + route_to_el2 = false + }; + masked : bool = undefined; + match PSTATE.EL { + ? if ? == EL3 => { + masked = EffectiveEA() == 0b0 | PSTATE.A == 0b1 + }, + ? if ? == EL2 => { + masked = not_bool(route_to_el3) & ((HCR_EL2[TGE] @ HCR_EL2[AMO]) == 0b00 | PSTATE.A == 0b1) + }, + ? if ? == EL1 => { + masked = (not_bool(route_to_el3) & not_bool(route_to_el2)) & PSTATE.A == 0b1 + }, + ? if ? == EL0 => { + masked = (not_bool(route_to_el3) & not_bool(route_to_el2)) & PSTATE.A == 0b1 + }, + _ => () + }; + if HaveDoubleFault2Ext() then { + nmea_bit : bits(1) = undefined; + match PSTATE.EL { + ? if ? == EL3 => { + nmea_bit = SCR_EL3[NMEA] + }, + ? if ? == EL2 => { + nmea_bit = if IsSCTLR2EL2Enabled() then SCTLR2_EL2[NMEA] else 0b0 + }, + ? if ? == EL1 => { + nmea_bit = if IsSCTLR2EL1Enabled() then SCTLR2_EL1[NMEA] else 0b0 + }, + ? if ? == EL0 => { + if IsInHost() then { + nmea_bit = if IsSCTLR2EL2Enabled() then SCTLR2_EL2[NMEA] else + 0b0 + } else { + nmea_bit = if IsSCTLR2EL1Enabled() then SCTLR2_EL1[NMEA] else + 0b0 + } + }, + _ => () + }; + masked = masked & nmea_bit == 0b0 + } else if HaveDoubleFaultExt() & PSTATE.EL == EL3 then { + let nmea_bit : bits(1) = SCR_EL3[NMEA] & EffectiveEA(); + masked = masked & nmea_bit == 0b0 + } else (); + route_masked_to_el3 : bool = undefined; + route_masked_to_el2 : bool = undefined; + if HaveDoubleFault2Ext() then { + route_masked_to_el2 = (((EL2Enabled() & not_bool(route_to_el3)) & IsHCRXEL2Enabled()) & HCRX_EL2[TMEA] == 0b1) & (PSTATE.EL == EL1 & (PSTATE.A == 0b1 | masked) | (PSTATE.EL == EL0 & masked) & not_bool(IsInHost())); + route_masked_to_el3 = ((HaveEL(EL3) & SCR_EL3[TMEA] == 0b1) & not_bool(route_to_el2 | route_masked_to_el2)) & ((PSTATE.EL == EL2 | PSTATE.EL == EL1) & (PSTATE.A == 0b1 | masked) | PSTATE.EL == EL0 & masked) + } else { + route_masked_to_el2 = false; + route_masked_to_el3 = false + }; + let take_in_el3 : bool = PSTATE.EL == EL3 & not_bool(masked); + let take_in_el2_0 : bool = ((PSTATE.EL == EL2 | IsInHost()) & not_bool(route_to_el3 | route_masked_to_el3)) & not_bool(masked); + let take_in_el1_0 : bool = (((PSTATE.EL == EL1 | PSTATE.EL == EL0 & not_bool(IsInHost())) & not_bool(route_to_el2 | route_masked_to_el2)) & not_bool(route_to_el3 | route_masked_to_el3)) & not_bool(masked); + target_el : bits(2) = undefined; + if (take_in_el3 | route_to_el3) | route_masked_to_el3 then { + masked = false; + target_el = EL3 + } else if (take_in_el2_0 | route_to_el2) | route_masked_to_el2 then { + masked = false; + target_el = EL2 + } else if take_in_el1_0 then { + masked = false; + target_el = EL1 + } else { + masked = true; + target_el = __UNKNOWN_bits(2) + }; + return((masked, target_el)) +} + +bitfield DISR_EL1_Type : bits(64) = + {A : 31..31, IDS : 24..24, AET : 12..10, EA : 9..9, ISS : 23..0, DFSC : 5..0} + +register DISR_EL1 : DISR_EL1_Type + +bitfield DISR_Type : bits(32) = + { + A : 31..31, + ExT : 12..12, + FS : (10..10 @ 3..0), + LPAE : 9..9, + EA : 9..9, + STATUS : 5..0, + DFSC : 5..0 + } + +register _DISR : DISR_Type + +val DISR_write : DISR_Type -> unit + +function DISR_write value_name = { + let r : DISR_Type = value_name; + DISR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DISR = r; + return() +} + +val ExternalDebugInterruptsDisabled : bits(2) -> bool + +function ExternalDebugInterruptsDisabled target = { + int_dis : bool = undefined; + let ss : SecurityState = SecurityStateAtEL(target); + if Havev8p4Debug() then { + if [EDSCR_read()[INTdis][0]] == 0b1 then { + match ss { + SS_NonSecure => { + int_dis = ExternalInvasiveDebugEnabled() + }, + SS_Secure => { + int_dis = ExternalSecureInvasiveDebugEnabled() + }, + SS_Realm => { + int_dis = ExternalRealmInvasiveDebugEnabled() + }, + SS_Root => { + int_dis = ExternalRootInvasiveDebugEnabled() + } + } + } else { + int_dis = false + } + } else { + match target { + ? if ? == EL3 => { + int_dis = EDSCR_read()[INTdis] == 0b11 & ExternalSecureInvasiveDebugEnabled() + }, + ? if ? == EL2 => { + int_dis = (match EDSCR_read()[INTdis] { + [bitone, _] => true, + _ => false + }) : bool & ExternalInvasiveDebugEnabled() + }, + ? if ? == EL1 => { + if ss == SS_Secure then { + int_dis = (match EDSCR_read()[INTdis] { + [bitone, _] => true, + _ => false + }) : bool & ExternalSecureInvasiveDebugEnabled() + } else { + int_dis = EDSCR_read()[INTdis] != 0b00 & ExternalInvasiveDebugEnabled() + } + }, + _ => () + } + }; + return(int_dis) +} + +val AArch64_ESBOperation : unit -> unit + +function AArch64_ESBOperation () = { + implicit_esb : bool = undefined; + target_el : bits(2) = undefined; + masked : bool = undefined; + (masked, target_el) = AArch64_PhysicalSErrorTarget(); + let intdis : bool = Halted() | ExternalDebugInterruptsDisabled(target_el); + let masked : bool = masked | intdis; + if masked & IsSynchronizablePhysicalSErrorPending() then { + if ELUsingAArch32(S1TranslationRegime__1()) then { + syndrome : bits(32) = Zeros(32); + syndrome[31] = Bit(0b1); + syndrome[15 .. 0] = AArch32_PhysicalSErrorSyndrome(); + DISR_write() = Mk_DISR_Type(syndrome) + } else { + let implicit_esb : bool = false; + syndrome : bits(64) = Zeros(64); + syndrome[31] = Bit(0b1); + syndrome[24 .. 0] = AArch64_PhysicalSErrorSyndrome(implicit_esb); + DISR_EL1 = Mk_DISR_EL1_Type(syndrome) + }; + ClearPendingPhysicalSError() + }; + return() +} + +bitfield VDFSR_Type : bits(32) = {AET : 15..14, ExT : 12..12} + +bitfield VSESR_EL2_Type : bits(64) = + {IDS : 24..24, AET : 15..14, ExT : 12..12, ISS : 23..0} + +register VSESR_EL2 : VSESR_EL2_Type + +register _VDFSR : VDFSR_Type + +val VDFSR_read : unit -> VDFSR_Type + +function VDFSR_read () = { + r : VDFSR_Type = _VDFSR; + r.bits[31 .. 0] = Slice(VSESR_EL2.bits, 0, 32); + return(r) +} + +bitfield VDISR_EL2_Type : bits(64) = + { + A : 31..31, + IDS : 24..24, + AET : 15..14, + ExT : 12..12, + FS : (10..10 @ 3..0), + LPAE : 9..9, + STATUS : 5..0, + ISS : 23..0 + } + +register VDISR_EL2 : VDISR_EL2_Type + +bitfield VDISR_Type : bits(32) = + { + A : 31..31, + AET : 15..14, + ExT : 12..12, + FS : (10..10 @ 3..0), + LPAE : 9..9, + STATUS : 5..0 + } + +register _VDISR : VDISR_Type + +val VDISR_write : VDISR_Type -> unit + +function VDISR_write value_name = { + let r : VDISR_Type = value_name; + VDISR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _VDISR = r; + return() +} + +val AArch64_vESBOperation : unit -> unit + +function AArch64_vESBOperation () = { + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + let vSEI_enabled : bool = HCR_EL2[TGE] == 0b0 & HCR_EL2[AMO] == 0b1; + let vSEI_pending : bool = vSEI_enabled & HCR_EL2[VSE] == 0b1; + let vintdis : bool = Halted() | ExternalDebugInterruptsDisabled(EL1); + let vmasked : bool = vintdis | PSTATE.A == 0b1; + if vSEI_pending & vmasked then { + if ELUsingAArch32(EL1) then { + target : bits(32) = Zeros(32); + target[31] = Bit(0b1); + target[15 .. 14] = VDFSR_read().bits[15 .. 14]; + target[12] = Bit([VDFSR_read().bits[12]]); + target[9] = Bit(TTBCR_read()[EAE]); + if TTBCR_read()[EAE] == 0b1 then { + target[5 .. 0] = 0b010001 + } else { + (target[10 .. 10] @ target[3 .. 0]) = 0b10110 + }; + VDISR_write() = Mk_VDISR_Type(target) + } else { + target : bits(64) = Zeros(64); + target[31] = Bit(0b1); + target[24 .. 0] = VSESR_EL2.bits[24 .. 0]; + VDISR_EL2 = Mk_VDISR_EL2_Type(target) + }; + HCR_EL2[VSE] = 0b0 + }; + return() +} + +val StartTrackingTransactionalReadsWrites : unit -> unit + +val CommitTransactionalWrites : unit -> unit + +val TakeTransactionCheckpoint : forall 'pl 'vl. (int('vl), int('pl)) -> unit + +function TakeTransactionCheckpoint (vl, pl) = { + TSTATE.SP = SP_read(); + TSTATE.ICC_PMR_EL1 = ICC_PMR_EL1.bits; + TSTATE.nzcv = PSTATE.N @ (PSTATE.Z @ (PSTATE.C @ PSTATE.V)); + (TSTATE.D @ TSTATE.A @ TSTATE.I @ TSTATE.F) = PSTATE.D @ (PSTATE.A @ (PSTATE.I @ PSTATE.F)); + foreach (n from 0 to 30 by 1 in inc) { + TSTATE.X[n] = X_read(n, 64) + }; + if IsFPEnabled(PSTATE.EL) then { + if IsSVEEnabled(PSTATE.EL) then { + foreach (n from 0 to 31 by 1 in inc) { + assert(constraint((0 <= 'vl - 1 & 'vl - 1 < 2048))); + TSTATE.Z[n][vl - 1 .. 0] = Z_read(n, vl) + }; + foreach (n from 0 to 15 by 1 in inc) { + assert(constraint((0 <= 'pl - 1 & 'pl - 1 < 256))); + TSTATE.P[n][pl - 1 .. 0] = P_read(n, pl) + }; + assert(constraint((0 <= 'pl - 1 & 'pl - 1 < 256))); + TSTATE.FFR[pl - 1 .. 0] = FFR_read(pl) + } else { + foreach (n from 0 to 31 by 1 in inc) { + TSTATE.Z[n][127 .. 0] = V_read(n, 128) + } + }; + TSTATE.FPCR = FPCR.bits; + TSTATE.FPSR = FPSR.bits + }; + if HaveGCS() then { + match PSTATE.EL { + ? if ? == EL0 => { + TSTATE.GCSPR_ELx = GCSPR_EL0.bits + }, + ? if ? == EL1 => { + TSTATE.GCSPR_ELx = GCSPR_EL1.bits + }, + ? if ? == EL2 => { + TSTATE.GCSPR_ELx = GCSPR_EL2.bits + }, + ? if ? == EL3 => { + TSTATE.GCSPR_ELx = GCSPR_EL3.bits + }, + _ => () + } + }; + return() +} + +val IsTMEEnabled : unit -> bool + +function IsTMEEnabled () = { + if (PSTATE.EL == EL0 | PSTATE.EL == EL1 | PSTATE.EL == EL2) & HaveEL(EL3) then { + if SCR_EL3[TME] == 0b0 then { + return(false) + }; + () + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled() then { + if HCR_EL2[TME] == 0b0 then { + return(false) + }; + () + }; + return(true) +} + +val TransactionStartTrap : forall 'dreg. int('dreg) -> unit + +function TransactionStartTrap dreg = { + targetEL : bits(2) = undefined; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_TSTARTAccessTrap); + except.syndrome[9 .. 5] = dreg[4 .. 0]; + if UInt(PSTATE.EL) > UInt(EL1) then { + targetEL = PSTATE.EL + } else if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + targetEL = EL2 + } else { + targetEL = EL1 + }; + AArch64_TakeException(targetEL, except, preferred_exception_return, vect_offset) +} + +val AArch64_ResetControlRegisters : forall ('cold_reset : Bool). + bool('cold_reset) -> unit + +bitfield RVBAR_EL1_Type : bits(64) = {ResetAddress : 63..0} + +register RVBAR_EL1 : RVBAR_EL1_Type + +bitfield RVBAR_EL2_Type : bits(64) = {ResetAddress : 63..0} + +register RVBAR_EL2 : RVBAR_EL2_Type + +bitfield RVBAR_EL3_Type : bits(64) = {ResetAddress : 63..0} + +register RVBAR_EL3 : RVBAR_EL3_Type + +val AArch64_TakeReset : forall ('cold_reset : Bool). bool('cold_reset) -> unit + +function AArch64_TakeReset cold_reset = { + assert(HaveAArch64()); + PSTATE.nRW = 0b0; + if HaveEL(EL3) then { + PSTATE.EL = EL3 + } else if HaveEL(EL2) then { + PSTATE.EL = EL2 + } else { + PSTATE.EL = EL1 + }; + AArch64_ResetControlRegisters(cold_reset); + PSTATE.SP = 0b1; + (PSTATE.D @ PSTATE.A @ PSTATE.I @ PSTATE.F) = 0b1111; + PSTATE.SS = 0b0; + PSTATE.DIT = 0b0; + PSTATE.IL = 0b0; + if HaveTME() then { + TSTATE.depth = 0 + }; + AArch64_ResetGeneralRegisters(); + AArch64_ResetSIMDFPRegisters(); + AArch64_ResetSpecialRegisters(); + ResetExternalDebugRegisters(cold_reset); + rv : bits(64) = undefined; + if HaveEL(EL3) then { + rv = RVBAR_EL3.bits + } else if HaveEL(EL2) then { + rv = RVBAR_EL2.bits + } else { + rv = RVBAR_EL1.bits + }; + assert(is_zero_subrange(rv, 63, AArch64_PAMax()) & IsZero(rv[1 .. 0])); + let branch_conditional : bool = false; + BranchTo(rv, BranchType_RESET, branch_conditional) +} + +val AArch32_ITAdvance : unit -> unit + +function AArch32_ITAdvance () = { + if PSTATE.IT[2 .. 0] == 0b000 then { + PSTATE.IT = 0b00000000 + } else { + PSTATE.IT[4 .. 0] = LSL(PSTATE.IT[4 .. 0], 1) + }; + return() +} + +val DebugTarget : unit -> bits(2) + +function DebugTarget () = { + let ss : SecurityState = CurrentSecurityState(); + return(DebugTargetFrom(ss)) +} + +val SSAdvance : unit -> unit + +function SSAdvance () = { + let target : bits(2) = DebugTarget(); + let step_enabled : bool = not_bool(ELUsingAArch32(target)) & MDSCR_EL1[SS] == 0b1; + let active_not_pending : bool = step_enabled & PSTATE.SS == 0b1; + if active_not_pending then { + PSTATE.SS = 0b0 + }; + return() +} + +val AArch64_CallSecureMonitor : bits(16) -> unit + +function AArch64_CallSecureMonitor immediate = { + assert(HaveEL(EL3) & not_bool(ELUsingAArch32(EL3))); + if UsingAArch32() then { + AArch32_ITAdvance() + }; + SSAdvance(); + let preferred_exception_return : bits(64) = NextInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_MonitorCall); + except.syndrome[15 .. 0] = immediate; + AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset) +} + +val AArch64_CallHypervisor : bits(16) -> unit + +function AArch64_CallHypervisor immediate = { + assert(HaveEL(EL2)); + if UsingAArch32() then { + AArch32_ITAdvance() + }; + SSAdvance(); + let preferred_exception_return : bits(64) = NextInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_HypervisorCall); + except.syndrome[15 .. 0] = immediate; + if PSTATE.EL == EL3 then { + AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } +} + +val AArch64_CallSupervisor : bits(16) -> unit + +function AArch64_CallSupervisor immediate_in = { + let immediate : bits(16) = immediate_in; + if UsingAArch32() then { + AArch32_ITAdvance() + }; + SSAdvance(); + let route_to_el2 : bool = (PSTATE.EL == EL0 & EL2Enabled()) & HCR_EL2[TGE] == 0b1; + let preferred_exception_return : bits(64) = NextInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_SupervisorCall); + except.syndrome[15 .. 0] = immediate; + if UInt(PSTATE.EL) > UInt(EL1) then { + AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset) + } else if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +val AArch64_UndefinedFault : unit -> unit + +function AArch64_UndefinedFault () = { + let route_to_el2 : bool = (PSTATE.EL == EL0 & EL2Enabled()) & HCR_EL2[TGE] == 0b1; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let except : ExceptionRecord = ExceptionSyndrome(Exception_Uncategorized); + if UInt(PSTATE.EL) > UInt(EL1) then { + AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset) + } else if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +val AArch64_CheckIllegalState : unit -> unit + +function AArch64_CheckIllegalState () = { + except : ExceptionRecord = undefined; + route_to_el2 : bool = undefined; + vect_offset : int = undefined; + if PSTATE.IL == 0b1 then { + let route_to_el2 : bool = (PSTATE.EL == EL0 & EL2Enabled()) & HCR_EL2[TGE] == 0b1; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let except : ExceptionRecord = ExceptionSyndrome(Exception_IllegalState); + if UInt(PSTATE.EL) > UInt(EL1) then { + AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset) + } else if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } + }; + () +} + +val LDST64BTrap : (bits(2), bits(25)) -> unit + +function LDST64BTrap (target_el, iss) = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_LDST64BTrap); + except.syndrome = iss; + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset); + return() +} + +val CheckLDST64BEnabled : unit -> unit + +function CheckLDST64BEnabled () = { + trap : bool = false; + let iss : bits(25) = ZeroExtend(0b10, 25); + target_el : bits(2) = undefined; + if PSTATE.EL == EL0 then { + if not_bool(IsInHost()) then { + trap = SCTLR_EL1[EnALS] == 0b0; + target_el = if EL2Enabled() & HCR_EL2[TGE] == 0b1 then EL2 else EL1 + } else { + trap = SCTLR_EL2[EnALS] == 0b0; + target_el = EL2 + } + } else { + target_el = EL1 + }; + if (not_bool(trap) & EL2Enabled()) & (PSTATE.EL == EL0 & not_bool(IsInHost()) | PSTATE.EL == EL1) then { + trap = not_bool(IsHCRXEL2Enabled()) | HCRX_EL2[EnALS] == 0b0; + target_el = EL2 + }; + let target_el = target_el; + if trap then { + LDST64BTrap(target_el, iss) + }; + () +} + +val CheckST64BVEnabled : unit -> unit + +function CheckST64BVEnabled () = { + trap : bool = false; + let iss : bits(25) = Zeros(25); + target_el : bits(2) = undefined; + if PSTATE.EL == EL0 then { + if not_bool(IsInHost()) then { + trap = SCTLR_EL1[EnASR] == 0b0; + target_el = if EL2Enabled() & HCR_EL2[TGE] == 0b1 then EL2 else EL1 + } else { + trap = SCTLR_EL2[EnASR] == 0b0; + target_el = EL2 + } + }; + if (not_bool(trap) & EL2Enabled()) & (PSTATE.EL == EL0 & not_bool(IsInHost()) | PSTATE.EL == EL1) then { + trap = not_bool(IsHCRXEL2Enabled()) | HCRX_EL2[EnASR] == 0b0; + target_el = EL2 + }; + let target_el = target_el; + if trap then { + LDST64BTrap(target_el, iss) + }; + () +} + +val CheckST64BV0Enabled : unit -> unit + +function CheckST64BV0Enabled () = { + trap : bool = false; + let iss : bits(25) = ZeroExtend(0b1, 25); + target_el : bits(2) = undefined; + if ((PSTATE.EL != EL3 & HaveEL(EL3)) & SCR_EL3[EnAS0] == 0b0) & EL3SDDUndefPriority() then { + throw(Error_Undefined()) + }; + if PSTATE.EL == EL0 then { + if not_bool(IsInHost()) then { + trap = SCTLR_EL1[EnAS0] == 0b0; + target_el = if EL2Enabled() & HCR_EL2[TGE] == 0b1 then EL2 else EL1 + } else { + trap = SCTLR_EL2[EnAS0] == 0b0; + target_el = EL2 + } + }; + if (not_bool(trap) & EL2Enabled()) & (PSTATE.EL == EL0 & not_bool(IsInHost()) | PSTATE.EL == EL1) then { + trap = not_bool(IsHCRXEL2Enabled()) | HCRX_EL2[EnAS0] == 0b0; + target_el = EL2 + }; + if not_bool(trap) & PSTATE.EL != EL3 then { + trap = HaveEL(EL3) & SCR_EL3[EnAS0] == 0b0; + target_el = EL3 + }; + if trap then { + if target_el == EL3 & EL3SDDUndef() then { + throw(Error_Undefined()) + } else { + LDST64BTrap(target_el, iss) + } + }; + () +} + +val AArch64_CheckForERetTrap : forall ('eret_with_pac : Bool) ('pac_uses_key_a : Bool). + (bool('eret_with_pac), bool('pac_uses_key_a)) -> unit + +function AArch64_CheckForERetTrap (eret_with_pac, pac_uses_key_a) = { + vect_offset : int = undefined; + route_to_el2 : bool = false; + let route_to_el2 : bool = (PSTATE.EL == EL1 & EL2Enabled()) & (HaveNVExt() & HCR_EL2[NV] == 0b1 | (HaveFGTExt() & (not_bool(HaveEL(EL3)) | SCR_EL3[FGTEn] == 0b1)) & HFGITR_EL2[ERET] == 0b1); + if route_to_el2 then { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_ERetTrap); + if not_bool(eret_with_pac) then { + except.syndrome[1] = Bit(0b0); + except.syndrome[0] = Bit(0b0) + } else { + except.syndrome[1] = Bit(0b1); + if pac_uses_key_a then { + except.syndrome[0] = Bit(0b0) + } else { + except.syndrome[0] = Bit(0b1) + } + }; + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + }; + () +} + +val AArch64_CheckForSVCTrap : bits(16) -> unit + +function AArch64_CheckForSVCTrap immediate = { + except : ExceptionRecord = undefined; + route_to_el2 : bool = undefined; + vect_offset : int = undefined; + if HaveFGTExt() then { + route_to_el2 : bool = false; + if PSTATE.EL == EL0 then { + route_to_el2 = (((not_bool(UsingAArch32()) & not_bool(ELUsingAArch32(EL1))) & EL2Enabled()) & HFGITR_EL2[SVC_EL0] == 0b1) & (HCR_EL2[E2H] @ HCR_EL2[TGE]) != 0b11 & (not_bool(HaveEL(EL3)) | SCR_EL3[FGTEn] == 0b1) + } else if PSTATE.EL == EL1 then { + route_to_el2 = (EL2Enabled() & HFGITR_EL2[SVC_EL1] == 0b1) & (not_bool(HaveEL(EL3)) | SCR_EL3[FGTEn] == 0b1) + } else (); + if route_to_el2 then { + except : ExceptionRecord = ExceptionSyndrome(Exception_SupervisorCall); + except.syndrome[15 .. 0] = immediate; + except.trappedsyscallinst = true; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + }; + () + }; + let route_to_el2 = route_to_el2; + () +} + +val AArch64_CheckForSMCUndefOrTrap : bits(16) -> unit + +function AArch64_CheckForSMCUndefOrTrap imm = { + except : ExceptionRecord = undefined; + vect_offset : int = undefined; + if PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + if (not_bool((PSTATE.EL == EL1 & EL2Enabled()) & HCR_EL2[TSC] == 0b1) & HaveEL(EL3)) & SCR_EL3[SMD] == 0b1 then { + throw(Error_Undefined()) + }; + route_to_el2 : bool = false; + if not_bool(HaveEL(EL3)) then { + if PSTATE.EL == EL1 & EL2Enabled() then { + if (HaveNVExt() & HCR_EL2[NV] == 0b1) & HCR_EL2[TSC] == 0b1 then { + route_to_el2 = true + } else { + throw(Error_Undefined()) + } + } else { + throw(Error_Undefined()) + } + } else { + route_to_el2 = (PSTATE.EL == EL1 & EL2Enabled()) & HCR_EL2[TSC] == 0b1 + }; + if route_to_el2 then { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_MonitorCall); + except.syndrome[15 .. 0] = imm; + except.trappedsyscallinst = true; + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + }; + () +} + +val AArch64_MonitorModeTrap : unit -> unit + +function AArch64_MonitorModeTrap () = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let except : ExceptionRecord = ExceptionSyndrome(Exception_Uncategorized); + if IsSecureEL2Enabled() then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + }; + AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset) +} + +val AArch64_SystemAccessTrapSyndrome : forall 'ec. + (bits(32), int('ec)) -> ExceptionRecord + +function AArch64_SystemAccessTrapSyndrome (instr_in, ec) = { + except : ExceptionRecord = undefined; + instr : bits(32) = instr_in; + match ec { + 0 => { + except = ExceptionSyndrome(Exception_Uncategorized) + }, + 7 => { + except = ExceptionSyndrome(Exception_AdvSIMDFPAccessTrap); + except.syndrome[24 .. 20] = ConditionSyndrome() + }, + 20 => { + except = ExceptionSyndrome(Exception_SystemRegister128Trap); + let instr : bits(32) = ThisInstr(); + except.syndrome[21 .. 20] = instr[20 .. 19]; + except.syndrome[19 .. 17] = instr[7 .. 5]; + except.syndrome[16 .. 14] = instr[18 .. 16]; + except.syndrome[13 .. 10] = instr[15 .. 12]; + except.syndrome[9 .. 6] = instr[4 .. 1]; + except.syndrome[4 .. 1] = instr[11 .. 8]; + except.syndrome[0] = Bit([instr[21]]) + }, + 24 => { + except = ExceptionSyndrome(Exception_SystemRegisterTrap); + let instr : bits(32) = ThisInstr(); + except.syndrome[21 .. 20] = instr[20 .. 19]; + except.syndrome[19 .. 17] = instr[7 .. 5]; + except.syndrome[16 .. 14] = instr[18 .. 16]; + except.syndrome[13 .. 10] = instr[15 .. 12]; + except.syndrome[9 .. 5] = instr[4 .. 0]; + except.syndrome[4 .. 1] = instr[11 .. 8]; + except.syndrome[0] = Bit([instr[21]]) + }, + 25 => { + except = ExceptionSyndrome(Exception_SVEAccessTrap) + }, + 29 => { + except = ExceptionSyndrome(Exception_SMEAccessTrap) + }, + _ => { + Unreachable() + } + }; + return(except) +} + +val AArch64_SystemAccessTrap : forall 'ec. (bits(2), int('ec)) -> unit + +function AArch64_SystemAccessTrap (target_el, ec) = { + assert((HaveEL(target_el) & target_el != EL0) & UInt(target_el) >= UInt(PSTATE.EL)); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let except : ExceptionRecord = AArch64_SystemAccessTrapSyndrome(ThisInstr(), ec); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AArch64_AArch32SystemAccessTrapSyndrome : forall 'ec. + (bits(32), int('ec)) -> ExceptionRecord + +function AArch64_AArch32SystemAccessTrapSyndrome (instr, ec) = { + except : ExceptionRecord = undefined; + match ec { + 0 => { + except = ExceptionSyndrome(Exception_Uncategorized) + }, + 3 => { + except = ExceptionSyndrome(Exception_CP15RTTrap) + }, + 4 => { + except = ExceptionSyndrome(Exception_CP15RRTTrap) + }, + 5 => { + except = ExceptionSyndrome(Exception_CP14RTTrap) + }, + 6 => { + except = ExceptionSyndrome(Exception_CP14DTTrap) + }, + 7 => { + except = ExceptionSyndrome(Exception_AdvSIMDFPAccessTrap) + }, + 8 => { + except = ExceptionSyndrome(Exception_FPIDTrap) + }, + 12 => { + except = ExceptionSyndrome(Exception_CP14RRTTrap) + }, + _ => { + Unreachable() + } + }; + iss : bits(20) = Zeros(20); + if except.exceptype == Exception_Uncategorized then { + return(except) + } else if except.exceptype == Exception_FPIDTrap | except.exceptype == Exception_CP14RTTrap | except.exceptype == Exception_CP15RTTrap then { + if except.exceptype != Exception_FPIDTrap then { + iss[19 .. 17] = instr[7 .. 5]; + iss[16 .. 14] = instr[23 .. 21]; + iss[13 .. 10] = instr[19 .. 16]; + iss[4 .. 1] = instr[3 .. 0] + } else { + iss[19 .. 17] = 0b000; + iss[16 .. 14] = 0b111; + iss[13 .. 10] = instr[19 .. 16]; + iss[4 .. 1] = 0b0000 + }; + if [instr[20]] == 0b1 & instr[15 .. 12] == 0b1111 then { + iss[9 .. 5] = 0b11111 + } else if [instr[20]] == 0b0 & instr[15 .. 12] == 0b1111 then { + iss[9 .. 5] = __UNKNOWN_bits(5) + } else { + iss[9 .. 5] = LookUpRIndex(UInt(instr[15 .. 12]), PSTATE.M)[4 .. 0] + } + } else if except.exceptype == Exception_CP14RRTTrap | except.exceptype == Exception_AdvSIMDFPAccessTrap | except.exceptype == Exception_CP15RRTTrap then { + iss[19 .. 16] = instr[7 .. 4]; + if instr[19 .. 16] == 0b1111 then { + iss[14 .. 10] = __UNKNOWN_bits(5) + } else { + iss[14 .. 10] = LookUpRIndex(UInt(instr[19 .. 16]), PSTATE.M)[4 .. 0] + }; + if instr[15 .. 12] == 0b1111 then { + iss[9 .. 5] = __UNKNOWN_bits(5) + } else { + iss[9 .. 5] = LookUpRIndex(UInt(instr[15 .. 12]), PSTATE.M)[4 .. 0] + }; + iss[4 .. 1] = instr[3 .. 0] + } else if except.exceptype == Exception_CP14DTTrap then { + iss[19 .. 12] = instr[7 .. 0]; + iss[4] = Bit([instr[23]]); + iss[2 .. 1] = [instr[24]] @ [instr[21]]; + if instr[19 .. 16] == 0b1111 then { + iss[9 .. 5] = __UNKNOWN_bits(5); + iss[3] = Bit(0b1) + }; + () + } else (); + iss[0] = Bit([instr[20]]); + except.syndrome[24 .. 20] = ConditionSyndrome(); + except.syndrome[19 .. 0] = iss; + return(except) +} + +val AArch64_AArch32SystemAccessTrap : forall 'ec. (bits(2), int('ec)) -> unit + +function AArch64_AArch32SystemAccessTrap (target_el, ec) = { + assert((HaveEL(target_el) & target_el != EL0) & UInt(target_el) >= UInt(PSTATE.EL)); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + let except : ExceptionRecord = AArch64_AArch32SystemAccessTrapSyndrome(ThisInstr(), ec); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AArch64_CheckFPAdvSIMDTrap : unit -> unit + +function AArch64_CheckFPAdvSIMDTrap () = { + if (HaveEL(EL3) & CPTR_EL3[TFP] == 0b1) & EL3SDDUndefPriority() then { + throw(Error_Undefined()) + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1 | PSTATE.EL == EL2) & EL2Enabled() then { + if HaveVirtHostExt() & HCR_EL2[E2H] == 0b1 then { + disabled : bool = undefined; + match CPTR_EL2[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 & HCR_EL2[TGE] == 0b1 + }, + 0b11 => { + disabled = false + } + }; + let disabled = disabled; + if disabled then { + AArch64_AdvSIMDFPAccessTrap(EL2) + }; + () + } else { + if CPTR_EL2[TFP] == 0b1 then { + AArch64_AdvSIMDFPAccessTrap(EL2) + }; + () + } + }; + if HaveEL(EL3) then { + if CPTR_EL3[TFP] == 0b1 then { + if EL3SDDUndef() then { + throw(Error_Undefined()) + } else { + AArch64_AdvSIMDFPAccessTrap(EL3) + } + }; + () + }; + () +} + +val AArch64_CheckFPEnabled : unit -> unit + +function AArch64_CheckFPEnabled () = { + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & not_bool(IsInHost()) then { + disabled : bool = undefined; + match CPACR_EL1[FPEN] { + [_, bitzero] => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 + }, + 0b11 => { + disabled = false + } + }; + let disabled = disabled; + if disabled then { + AArch64_AdvSIMDFPAccessTrap(EL1) + }; + () + }; + AArch64_CheckFPAdvSIMDTrap() +} + +val AArch64_CheckFPAdvSIMDEnabled : unit -> unit + +function AArch64_CheckFPAdvSIMDEnabled () = { + AArch64_CheckFPEnabled(); + if (HaveSME() & PSTATE.SM == 0b1) & not_bool(IsFullA64Enabled()) then { + SMEAccessTrap(SMEExceptionType_Streaming, PSTATE.EL) + }; + () +} + +bitfield HSTR_EL2_Type : bits(64) = + { + T15 : 15..15, + T13 : 13..13, + T12 : 12..12, + T11 : 11..11, + T10 : 10..10, + T9 : 9..9, + T8 : 8..8, + T7 : 7..7, + T6 : 6..6, + T5 : 5..5, + T3 : 3..3, + T2 : 2..2, + T1 : 1..1, + T0 : 0..0 + } + +register HSTR_EL2 : HSTR_EL2_Type + +val AArch64_CheckCP15InstrCoarseTraps : forall 'CRm 'CRn 'nreg. + (int('CRn), int('nreg), int('CRm)) -> unit + +function AArch64_CheckCP15InstrCoarseTraps (CRn, nreg, CRm) = { + major : int = undefined; + let trapped_encoding : bool = (CRn == 9 & (CRm == 0 | CRm == 1 | CRm == 2 | CRm == 5 | CRm == 6 | CRm == 7 | CRm == 8) | CRn == 10 & (CRm == 0 | CRm == 1 | CRm == 4 | CRm == 8)) | CRn == 11 & (CRm == 0 | CRm == 1 | CRm == 2 | CRm == 3 | CRm == 4 | CRm == 5 | CRm == 6 | CRm == 7 | CRm == 8 | CRm == 15); + if ((((HaveFeatTIDCP1() & PSTATE.EL == EL0) & not_bool(IsInHost())) & not_bool(ELUsingAArch32(EL1))) & SCTLR_EL1[TIDCP] == 0b1) & trapped_encoding then { + if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + AArch64_AArch32SystemAccessTrap(EL2, UInt(0x3)) + } else { + AArch64_AArch32SystemAccessTrap(EL1, UInt(0x3)) + } + }; + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled() then { + if (((HaveFeatTIDCP1() & PSTATE.EL == EL0) & IsInHost()) & SCTLR_EL2[TIDCP] == 0b1) & trapped_encoding then { + AArch64_AArch32SystemAccessTrap(EL2, UInt(0x3)) + }; + let 'major = if nreg == 1 then CRn else CRm; + assert(constraint((0 <= 'major & 'major < 64))); + if (not_bool(IsInHost()) & not_bool(major == 4 | major == 14)) & [HSTR_EL2.bits[major]] == 0b1 | (HCR_EL2[TIDCP] == 0b1 & nreg == 1) & trapped_encoding then { + if PSTATE.EL == EL0 & __IMPDEF_boolean("UNDEF unallocated CP15 access at EL0") then { + throw(Error_Undefined()) + }; + AArch64_AArch32SystemAccessTrap(EL2, UInt(0x3)) + }; + () + }; + () +} + +val CheckFPEnabled64 : unit -> unit + +function CheckFPEnabled64 () = { + AArch64_CheckFPEnabled() +} + +val CheckFPAdvSIMDEnabled64 : unit -> unit + +function CheckFPAdvSIMDEnabled64 () = { + AArch64_CheckFPAdvSIMDEnabled() +} + +val AArch64_TakePhysicalSErrorException : forall ('implicit_esb : Bool). + bool('implicit_esb) -> unit + +function AArch64_TakePhysicalSErrorException implicit_esb = { + let route_to_el3 : bool = HaveEL(EL3) & SCR_EL3[EA] == 0b1; + let route_to_el2 : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b1 | not_bool(IsInHost()) & HCR_EL2[AMO] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x180); + target_el : bits(2) = undefined; + if PSTATE.EL == EL3 | route_to_el3 then { + target_el = EL3 + } else if PSTATE.EL == EL2 | route_to_el2 then { + target_el = EL2 + } else { + target_el = EL1 + }; + except : ExceptionRecord = ExceptionSyndrome(Exception_SError); + let syndrome : bits(25) = AArch64_PhysicalSErrorSyndrome(implicit_esb); + if IsSErrorEdgeTriggered() then { + ClearPendingPhysicalSError() + }; + except.syndrome = syndrome; + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AArch64_TakeVirtualSErrorException : unit -> unit + +function AArch64_TakeVirtualSErrorException () = { + impdef_syndrome : bool = undefined; + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + assert(HCR_EL2[TGE] == 0b0 & HCR_EL2[AMO] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x180); + except : ExceptionRecord = ExceptionSyndrome(Exception_SError); + if HaveRASExt() then { + except.syndrome[24] = Bit(VSESR_EL2[IDS]); + except.syndrome[23 .. 0] = VSESR_EL2[ISS] + } else { + let syndrome : bits(25) = __IMPDEF_bits(25, "Virtual SError syndrome"); + let impdef_syndrome : bool = [syndrome[24]] == 0b1; + if impdef_syndrome then { + except.syndrome = syndrome + }; + () + }; + ClearPendingVirtualSError(); + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) +} + +val AArch64_TakePhysicalIRQException : unit -> unit + +function AArch64_TakePhysicalIRQException () = { + let route_to_el3 : bool = HaveEL(EL3) & SCR_EL3[IRQ] == 0b1; + let route_to_el2 : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b1 | HCR_EL2[IMO] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x80); + let except : ExceptionRecord = ExceptionSyndrome(Exception_IRQ); + if route_to_el3 then { + AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset) + } else if PSTATE.EL == EL2 | route_to_el2 then { + assert(PSTATE.EL != EL3); + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + assert(PSTATE.EL == EL0 | PSTATE.EL == EL1); + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +val AArch64_TakeVirtualIRQException : unit -> unit + +function AArch64_TakeVirtualIRQException () = { + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + assert(HCR_EL2[TGE] == 0b0 & HCR_EL2[IMO] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x80); + let except : ExceptionRecord = ExceptionSyndrome(Exception_IRQ); + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) +} + +val AArch64_TakePhysicalFIQException : unit -> unit + +function AArch64_TakePhysicalFIQException () = { + let route_to_el3 : bool = HaveEL(EL3) & SCR_EL3[FIQ] == 0b1; + let route_to_el2 : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b1 | HCR_EL2[FMO] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x100); + let except : ExceptionRecord = ExceptionSyndrome(Exception_FIQ); + if route_to_el3 then { + AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset) + } else if PSTATE.EL == EL2 | route_to_el2 then { + assert(PSTATE.EL != EL3); + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + assert(PSTATE.EL == EL0 | PSTATE.EL == EL1); + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +val AArch64_TakeVirtualFIQException : unit -> unit + +function AArch64_TakeVirtualFIQException () = { + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + assert(HCR_EL2[TGE] == 0b0 & HCR_EL2[FMO] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x100); + let except : ExceptionRecord = ExceptionSyndrome(Exception_FIQ); + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) +} + +val AArch64_SoftwareBreakpoint : bits(16) -> unit + +function AArch64_SoftwareBreakpoint immediate = { + let route_to_el2 : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b1 | MDCR_EL2[TDE] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_SoftwareBreakpoint); + except.syndrome[15 .. 0] = immediate; + if UInt(PSTATE.EL) > UInt(EL1) then { + AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset) + } else if route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +val SoftwareStep_DidNotStep : unit -> bool + +val SoftwareStep_SteppedEX : unit -> bool + +val AArch64_SoftwareStepException : unit -> unit + +function AArch64_SoftwareStepException () = { + assert(PSTATE.EL != EL3); + let route_to_el2 : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[TGE] == 0b1 | MDCR_EL2[TDE] == 0b1); + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_SoftwareStep); + if SoftwareStep_DidNotStep() then { + except.syndrome[24] = Bit(0b0) + } else { + except.syndrome[24] = Bit(0b1); + except.syndrome[6] = Bit(if SoftwareStep_SteppedEX() then 0b1 else 0b0) + }; + except.syndrome[5 .. 0] = 0b100010; + if PSTATE.EL == EL2 | route_to_el2 then { + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + } else { + AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset) + } +} + +val AArch64_PCAlignmentFault : unit -> unit + +function AArch64_PCAlignmentFault () = { + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + except : ExceptionRecord = ExceptionSyndrome(Exception_PCAlignment); + except.vaddress = ThisInstrAddr(64); + target_el : bits(2) = EL1; + if UInt(PSTATE.EL) > UInt(EL1) then { + target_el = PSTATE.EL + } else if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + target_el = EL2 + } else (); + AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset) +} + +val AArch64_CheckPCAlignment : unit -> unit + +function AArch64_CheckPCAlignment () = { + let pc : bits(64) = ThisInstrAddr(64); + if pc[1 .. 0] != 0b00 then { + AArch64_PCAlignmentFault() + }; + () +} + +bitfield MDSELR_EL1_Type : bits(64) = {BANK : 5..4} + +register MDSELR_EL1 : MDSELR_EL1_Type + +val EffectiveMDSELR_EL1_BANK : unit -> bits(2) + +function EffectiveMDSELR_EL1_BANK () = { + let 'num_bp = NumBreakpointsImplemented(); + let 'num_wp = NumWatchpointsImplemented(); + if num_bp <= 16 & num_wp <= 16 then { + return(0b00) + }; + if (HaveEL(EL3) & MDCR_EL3[EBWE] == 0b0 | (PSTATE.EL != EL3 & EL2Enabled()) & MDCR_EL2[EBWE] == 0b0) | PSTATE.EL == EL1 & MDSCR_EL1[EMBWE] == 0b0 then { + return(0b00) + }; + bank : bits(2) = MDSELR_EL1[BANK]; + if (bank == 0b11 & num_bp <= 48) & num_wp <= 48 | (bank == 0b10 & num_bp <= 32) & num_wp <= 32 then { + let (_, __tup_1 : bits(2)) = ConstrainUnpredictableBits(Unpredictable_RESMDSELR, 2); + bank = __tup_1 + }; + return(bank) +} + +type PMEVCNTR_EL0_Type = bits(64) + +register PMEVCNTR_EL0 : vector(32, PMEVCNTR_EL0_Type) + +val AArch64_IncrementEventCounter : forall 'idx 'increment_name, + 0 <= 'idx & 'idx < 31. + (int('idx), int('increment_name)) -> unit + +function AArch64_IncrementEventCounter (idx, increment_name) = { + ovflw : {32, 64} = 32; + let 'old_value = UInt(PMEVCNTR_EL0[idx]); + let 'new_value = old_value + PMUCountValue(idx, increment_name); + lp : bits(1) = undefined; + if HavePMUv3p5() then { + PMEVCNTR_EL0[idx] = new_value[63 .. 0]; + lp = if PMUCounterIsHyp(idx) then MDCR_EL2[HLP] else PMCR_EL0[LP]; + ovflw = if lp == 0b1 then 64 else 32 + } else { + PMEVCNTR_EL0[idx] = ZeroExtend(new_value[31 .. 0], 64); + ovflw = 32 + }; + let 'ovflw = ovflw; + if old_value[64 .. ovflw] != new_value[64 .. ovflw] then { + PMOVSSET_EL0.bits[idx] = Bit(0b1); + PMOVSCLR_EL0.bits[idx] = Bit(0b1); + if ([idx[0]] == 0b0 & idx + 1 < GetNumEventCounters()) & (not_bool(HavePMUv3p5()) | lp == 0b0) then { + PMUEvent__2(PMU_EVENT_CHAIN, 1, idx + 1) + }; + () + }; + () +} + +val AArch64_ClearEventCounters : unit -> unit + +function AArch64_ClearEventCounters () = { + let 'counters = AArch64_GetNumEventCountersAccessible(); + if counters != 0 then { + foreach (idx from 0 to (counters - 1) by 1 in inc) { + assert(constraint((0 <= 'loop_idx & 'loop_idx < 32))); + PMEVCNTR_EL0[idx] = Zeros(64) + } + }; + () +} + +val AArch64_PMUSwIncrement : bits(32) -> unit + +function AArch64_PMUSwIncrement sw_incr = { + if PMCR_EL0[E] == 0b0 & MDCR_EL2[HPME] == 0b0 then { + return() + }; + let 'counters = AArch64_GetNumEventCountersAccessible(); + if counters != 0 then { + foreach (idx from 0 to (counters - 1) by 1 in inc) { + assert(constraint((0 <= 'loop_idx & 'loop_idx < 32))); + if [sw_incr[idx]] == 0b1 then { + PMUEvent__2(PMU_EVENT_SW_INCR, 1, idx) + }; + () + } + }; + () +} + +bitfield PMCCNTR_EL0_Type : bits(64) = {CCNT : 63..0} + +register PMCCNTR_EL0 : PMCCNTR_EL0_Type + +val AArch64_IncrementCycleCounter : unit -> unit + +function AArch64_IncrementCycleCounter () = { + if CountPMUEvents(CYCLE_COUNTER_ID) & (((not_bool(HaveAArch32()) | PMCR_EL0[LC] == 0b1) | PMCR_EL0[D] == 0b0) | HasElapsed64Cycles()) then { + let 'old_value = UInt(PMCCNTR_EL0.bits); + let 'new_value = old_value + 1; + PMCCNTR_EL0 = Mk_PMCCNTR_EL0_Type(new_value[63 .. 0]); + ovflw : {32, 64} = 32; + if HaveAArch32() then { + ovflw = if PMCR_EL0[LC] == 0b1 then 64 else 32 + } else { + ovflw = 64 + }; + let 'ovflw = ovflw; + if old_value[64 .. ovflw] != new_value[64 .. ovflw] then { + PMOVSSET_EL0[C] = 0b1; + PMOVSCLR_EL0[C] = 0b1 + }; + () + }; + () +} + +val AArch64_PMUCycle : unit -> unit + +function AArch64_PMUCycle () = { + if PMCR_EL0[E] == 0b0 & MDCR_EL2[HPME] == 0b0 then { + if ShouldBRBEFreeze() then { + BRBEFreeze() + }; + return() + }; + if not_bool(HavePMUv3()) then { + return() + }; + PMUEvent(PMU_EVENT_CPU_CYCLES); + let 'counters = GetNumEventCounters(); + if counters != 0 then { + foreach (idx from 0 to (counters - 1) by 1 in inc) { + assert(constraint((0 <= 'loop_idx & 'loop_idx <= 32))); + if CountPMUEvents(idx) then { + assert(constraint((0 <= 'loop_idx & 'loop_idx < 31))); + let 'accumulated = PMUEventAccumulator[idx]; + AArch64_IncrementEventCounter(idx, accumulated) + }; + assert(constraint((0 <= 'loop_idx & 'loop_idx < 31))); + PMUEventAccumulator[idx] = 0 + } + }; + AArch64_IncrementCycleCounter(); + CheckForPMUOverflow() +} + +val ProfilingSynchronizationBarrier : unit -> unit + +val SPESampleAddAddressPCVirtual : unit -> unit + +function SPESampleAddAddressPCVirtual () = { + let this_address : bits(64) = ThisInstrAddr(64); + SPESampleAddress[SPEAddrPosPCVirtual][55 .. 0] = this_address[55 .. 0]; + ns : bits(1) = undefined; + nse : bits(1) = undefined; + match CurrentSecurityState() { + SS_Secure => { + ns = 0b0; + nse = 0b0 + }, + SS_NonSecure => { + ns = 0b1; + nse = 0b0 + }, + SS_Realm => { + ns = 0b1; + nse = 0b1 + }, + _ => { + Unreachable() + } + }; + let el : bits(2) = PSTATE.EL; + SPESampleAddress[SPEAddrPosPCVirtual][63 .. 56] = ((ns @ el) @ nse) @ Zeros(4); + SPESampleAddressValid[SPEAddrPosPCVirtual] = true +} + +val CollectContextIDR1 : unit -> bool + +function CollectContextIDR1 () = { + if not_bool(StatisticalProfilingEnabled()) then { + return(false) + }; + if PSTATE.EL == EL2 then { + return(false) + }; + if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + return(false) + }; + return(PMSCR_EL1[CX] == 0b1) +} + +val CollectContextIDR2 : unit -> bool + +function CollectContextIDR2 () = { + if not_bool(StatisticalProfilingEnabled()) then { + return(false) + }; + if not_bool(EL2Enabled()) then { + return(false) + }; + return(PMSCR_EL2[CX] == 0b1) +} + +val SPESampleAddContext : unit -> unit + +function SPESampleAddContext () = { + if CollectContextIDR1() then { + SPESampleContextEL1 = CONTEXTIDR_EL1.bits[31 .. 0]; + SPESampleContextEL1Valid = true + }; + if CollectContextIDR2() then { + SPESampleContextEL2 = CONTEXTIDR_EL2.bits[31 .. 0]; + SPESampleContextEL2Valid = true + }; + () +} + +val SPESampleAddOpOther : forall ('conditional : Bool) ('taken : Bool). + (bool('conditional), bool('taken)) -> unit + +val SPESampleAddOpOther__1 : forall ('conditional : Bool). + bool('conditional) -> unit + +function SPESampleAddOpOther (conditional, taken) = { + SPESampleEvents[6] = Bit(if conditional & not_bool(taken) then 0b1 else 0b0); + SPESampleAddOpOther__1(conditional) +} + +function SPESampleAddOpOther__1 conditional = { + SPESampleClass = 0b00; + SPESampleSubclass[0] = Bit(if conditional then 0b1 else 0b0); + SPESampleOpType = OpType_Other +} + +val CollectTimeStamp : unit -> TimeStamp + +function CollectTimeStamp () = { + owning_el : bits(2) = undefined; + if not_bool(StatisticalProfilingEnabled()) then { + return(TimeStamp_None) + }; + let (_, __tup_1 : bits(2)) = ProfilingBufferOwner() in + { + owning_el = __tup_1 + }; + if owning_el == EL2 then { + if PMSCR_EL2[TS] == 0b0 then { + return(TimeStamp_None) + }; + () + } else { + if PMSCR_EL1[TS] == 0b0 then { + return(TimeStamp_None) + }; + () + }; + PCT_el1 : bits(2) = undefined; + if not_bool(HaveECVExt()) then { + PCT_el1 = 0b0 @ [PMSCR_EL1[PCT][0]] + } else { + PCT_el1 = PMSCR_EL1[PCT]; + if PCT_el1 == 0b10 then { + let (_, __tup_1 : bits(2)) = ConstrainUnpredictableBits(Unpredictable_PMSCR_PCT, 2); + PCT_el1 = __tup_1 + }; + () + }; + if EL2Enabled() then { + PCT_el2 : bits(2) = undefined; + if not_bool(HaveECVExt()) then { + PCT_el2 = 0b0 @ [PMSCR_EL2[PCT][0]] + } else { + PCT_el2 = PMSCR_EL2[PCT]; + if PCT_el2 == 0b10 then { + let (_, __tup_1 : bits(2)) = ConstrainUnpredictableBits(Unpredictable_PMSCR_PCT, 2); + PCT_el2 = __tup_1 + }; + () + }; + match PCT_el2 { + 0b00 => { + return(if IsInHost() then TimeStamp_Physical else + TimeStamp_Virtual) + }, + 0b01 => { + if owning_el == EL2 then { + return(TimeStamp_Physical) + }; + () + }, + 0b11 => { + assert(HaveECVExt()); + if owning_el == EL1 & PCT_el1 == 0b00 then { + return(if IsInHost() then TimeStamp_Physical else + TimeStamp_Virtual) + } else { + return(TimeStamp_OffsetPhysical) + } + }, + _ => { + Unreachable() + } + } + }; + match PCT_el1 { + 0b00 => { + return(if IsInHost() then TimeStamp_Physical else TimeStamp_Virtual) + }, + 0b01 => { + return(TimeStamp_Physical) + }, + 0b11 => { + assert(HaveECVExt()); + return(TimeStamp_OffsetPhysical) + }, + _ => { + Unreachable(); + return(undefined : TimeStamp) + } + } +} + +val SPESampleAddTimeStamp : unit -> unit + +function SPESampleAddTimeStamp () = { + let timestamp : TimeStamp = CollectTimeStamp(); + match timestamp { + TimeStamp_None => { + SPESampleTimestampValid = false + }, + _ => { + SPESampleTimestampValid = true; + SPESampleTimestamp = GetTimestamp(timestamp) + } + } +} + +bitfield PMSICR_EL1_Type : bits(64) = {ECOUNT : 63..56, COUNT : 31..0} + +register PMSICR_EL1 : PMSICR_EL1_Type + +bitfield PMSIRR_EL1_Type : bits(64) = {INTERVAL : 31..8, RND : 0..0} + +register PMSIRR_EL1 : PMSIRR_EL1_Type + +val SPEGetRandomInterval : unit -> bits(8) + +function SPEGetRandomInterval () = { + new_byte : bits(8) = undefined; + if not_bool(__SPE_LFSR_initialized) then { + __SPE_LFSR_initialized = true; + __SPE_LFSR = PC_read__1()[23 .. 0]; + foreach (i from 7 to 0 by 1 in dec) { + new_byte = EOR(EOR(__SPE_LFSR[16 .. 9], __SPE_LFSR[21 .. 14]), __SPE_LFSR[22 .. 15]); + new_byte = EOR(new_byte, __SPE_LFSR[23 .. 16]); + __SPE_LFSR = __SPE_LFSR[15 .. 0] @ new_byte + } + } else { + new_byte : bits(8) = EOR(EOR(__SPE_LFSR[16 .. 9], __SPE_LFSR[21 .. 14]), __SPE_LFSR[22 .. 15]); + let new_byte : bits(8) = EOR(new_byte, __SPE_LFSR[23 .. 16]); + __SPE_LFSR = __SPE_LFSR[15 .. 0] @ new_byte + }; + return(__SPE_LFSR[23 .. 16]) +} + +val SPEResetSampleCounter : unit -> unit + +function SPEResetSampleCounter () = { + PMSICR_EL1[COUNT][31 .. 8] = PMSIRR_EL1[INTERVAL]; + if PMSIRR_EL1[RND] == 0b1 & PMSIDR_EL1[ERnd] == 0b0 then { + PMSICR_EL1[COUNT][7 .. 0] = SPEGetRandomInterval() + } else { + PMSICR_EL1[COUNT][7 .. 0] = Zeros(8) + } +} + +val SPEToCollectSample : unit -> bool + +function SPEToCollectSample () = { + if IsZero(PMSICR_EL1[COUNT]) then { + SPEResetSampleCounter() + } else { + PMSICR_EL1[COUNT] = PMSICR_EL1[COUNT] - 1; + if IsZero(PMSICR_EL1[COUNT]) then { + if PMSIRR_EL1[RND] == 0b1 & PMSIDR_EL1[ERnd] == 0b1 then { + PMSICR_EL1[ECOUNT] = SPEGetRandomInterval() + } else { + return(true) + } + }; + () + }; + if UInt(PMSICR_EL1[ECOUNT]) != 0 then { + PMSICR_EL1[ECOUNT] = PMSICR_EL1[ECOUNT] - 1; + if IsZero(PMSICR_EL1[ECOUNT]) then { + return(true) + }; + () + }; + return(false) +} + +val SPEPreExecution : unit -> unit + +function SPEPreExecution () = { + if StatisticalProfilingEnabled() then { + PMUEvent(PMU_EVENT_SAMPLE_POP); + if SPEToCollectSample() then { + if not_bool(SPESampleInFlight) then { + SPESampleInFlight = true; + SPEStartCounter(SPECounterPosTotalLatency); + SPEStartCounter(SPECounterPosIssueLatency); + SPESampleAddContext(); + SPESampleAddAddressPCVirtual(); + SPESampleAddTimeStamp() + } else { + PMUEvent(PMU_EVENT_SAMPLE_COLLISION); + PMBSR_EL1[COLL] = 0b1 + }; + SPESampleAddOpOther__1(false) + }; + () + }; + () +} + +val SPEBufferFilled : unit -> unit + +function SPEBufferFilled () = { + if IsZero(PMBSR_EL1[S]) then { + PMBSR_EL1[S] = 0b1; + PMBSR_EL1[EC] = 0b000000; + PMBSR_EL1[MSS] = ZeroExtend(0b000001, 16) + }; + PMUEvent(PMU_EVENT_SAMPLE_WRAP) +} + +bitfield PMBPTR_EL1_Type : bits(64) = {PTR : 63..0} + +register PMBPTR_EL1 : PMBPTR_EL1_Type + +val SPEBufferIsFull : unit -> bool + +function SPEBufferIsFull () = { + let 'write_pointer_limit = UInt(PMBLIMITR_EL1[LIMIT] @ Zeros(12)); + let 'current_write_pointer = UInt(PMBPTR_EL1.bits); + let 'record_max_size = (1 << UInt(PMSIDR_EL1[MaxSize])); + return(current_write_pointer > write_pointer_limit - record_max_size) +} + +bitfield PMSDSFR_EL1_Type : bits(64) = + { + S63 : 63..63, + S62 : 62..62, + S61 : 61..61, + S60 : 60..60, + S59 : 59..59, + S58 : 58..58, + S57 : 57..57, + S56 : 56..56, + S55 : 55..55, + S54 : 54..54, + S53 : 53..53, + S52 : 52..52, + S51 : 51..51, + S50 : 50..50, + S49 : 49..49, + S48 : 48..48, + S47 : 47..47, + S46 : 46..46, + S45 : 45..45, + S44 : 44..44, + S43 : 43..43, + S42 : 42..42, + S41 : 41..41, + S40 : 40..40, + S39 : 39..39, + S38 : 38..38, + S37 : 37..37, + S36 : 36..36, + S35 : 35..35, + S34 : 34..34, + S33 : 33..33, + S32 : 32..32, + S31 : 31..31, + S30 : 30..30, + S29 : 29..29, + S28 : 28..28, + S27 : 27..27, + S26 : 26..26, + S25 : 25..25, + S24 : 24..24, + S23 : 23..23, + S22 : 22..22, + S21 : 21..21, + S20 : 20..20, + S19 : 19..19, + S18 : 18..18, + S17 : 17..17, + S16 : 16..16, + S15 : 15..15, + S14 : 14..14, + S13 : 13..13, + S12 : 12..12, + S11 : 11..11, + S10 : 10..10, + S9 : 9..9, + S8 : 8..8, + S7 : 7..7, + S6 : 6..6, + S5 : 5..5, + S4 : 4..4, + S3 : 3..3, + S2 : 2..2, + S1 : 1..1, + S0 : 0..0 + } + +register PMSDSFR_EL1 : PMSDSFR_EL1_Type + +bitfield PMSEVFR_EL1_Type : bits(64) = + { + E63 : 63..63, + E62 : 62..62, + E61 : 61..61, + E60 : 60..60, + E59 : 59..59, + E58 : 58..58, + E57 : 57..57, + E56 : 56..56, + E55 : 55..55, + E54 : 54..54, + E53 : 53..53, + E52 : 52..52, + E51 : 51..51, + E50 : 50..50, + E49 : 49..49, + E48 : 48..48, + E31 : 31..31, + E30 : 30..30, + E29 : 29..29, + E28 : 28..28, + E27 : 27..27, + E26 : 26..26, + E25 : 25..25, + E24 : 24..24, + E23 : 23..23, + E22 : 22..22, + E21 : 21..21, + E20 : 20..20, + E19 : 19..19, + E18 : 18..18, + E17 : 17..17, + E16 : 16..16, + E15 : 15..15, + E14 : 14..14, + E13 : 13..13, + E12 : 12..12, + E11 : 11..11, + E10 : 10..10, + E9 : 9..9, + E8 : 8..8, + E7 : 7..7, + E6 : 6..6, + E5 : 5..5, + E4 : 4..4, + E3 : 3..3, + E2 : 2..2, + E1 : 1..1 + } + +register PMSEVFR_EL1 : PMSEVFR_EL1_Type + +bitfield PMSFCR_EL1_Type : bits(64) = + { + ST : 18..18, + LD : 17..17, + B : 16..16, + FDS : 4..4, + FnE : 3..3, + FL : 2..2, + FT : 1..1, + FE : 0..0 + } + +register PMSFCR_EL1 : PMSFCR_EL1_Type + +bitfield PMSLATFR_EL1_Type : bits(64) = {MINLAT : 15..0} + +register PMSLATFR_EL1 : PMSLATFR_EL1_Type + +bitfield PMSNEVFR_EL1_Type : bits(64) = + { + E63 : 63..63, + E62 : 62..62, + E61 : 61..61, + E60 : 60..60, + E59 : 59..59, + E58 : 58..58, + E57 : 57..57, + E56 : 56..56, + E55 : 55..55, + E54 : 54..54, + E53 : 53..53, + E52 : 52..52, + E51 : 51..51, + E50 : 50..50, + E49 : 49..49, + E48 : 48..48, + E31 : 31..31, + E30 : 30..30, + E29 : 29..29, + E28 : 28..28, + E27 : 27..27, + E26 : 26..26, + E25 : 25..25, + E24 : 24..24, + E23 : 23..23, + E22 : 22..22, + E21 : 21..21, + E20 : 20..20, + E19 : 19..19, + E18 : 18..18, + E17 : 17..17, + E16 : 16..16, + E15 : 15..15, + E14 : 14..14, + E13 : 13..13, + E12 : 12..12, + E11 : 11..11, + E10 : 10..10, + E9 : 9..9, + E8 : 8..8, + E7 : 7..7, + E6 : 6..6, + E5 : 5..5, + E4 : 4..4, + E3 : 3..3, + E2 : 2..2, + E1 : 1..1 + } + +register PMSNEVFR_EL1 : PMSNEVFR_EL1_Type + +val SPECollectRecord : forall 'total_latency. + (bits(64), int('total_latency), OpType) -> bool + +function SPECollectRecord (events, total_latency, optype) = { + assert(StatisticalProfilingEnabled()); + mask : bits(64) = ZeroExtend(0xAA, 64); + m : bits(64) = undefined; + if HaveSVE() then { + mask[18 .. 17] = 0b11 + }; + if HaveTME() then { + mask[16] = Bit(0b1) + }; + if HaveStatisticalProfilingv1p1() then { + mask[11] = Bit(0b1) + }; + if HaveStatisticalProfilingv1p2() then { + mask[6] = Bit(0b1) + }; + if HaveStatisticalProfilingv1p4() then { + (mask[10 .. 8] @ mask[4 .. 4] @ mask[2 .. 2]) = 0b11111 + } else { + let impdef_mask : bits(5) = __IMPDEF_bits(5, "SPE mask 10:8,4,2"); + (mask[10 .. 8] @ mask[4 .. 4] @ mask[2 .. 2]) = impdef_mask + }; + mask[63 .. 48] = __IMPDEF_bits(16, "SPE mask 63:48"); + mask[31 .. 24] = __IMPDEF_bits(8, "SPE mask 31:24"); + mask[15 .. 12] = __IMPDEF_bits(4, "SPE mask 15:12"); + let e : bits(64) = events & mask; + is_rejected_nevent : bool = false; + is_nevt : bool = undefined; + if HaveStatisticalProfilingv1p2() then { + m = PMSNEVFR_EL1.bits & mask; + is_nevt = IsZero(e & m); + if PMSFCR_EL1[FnE] == 0b1 then { + if not_bool(IsZero(m)) then { + is_rejected_nevent = not_bool(is_nevt) + } else { + is_rejected_nevent = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR) + } + }; + () + } else { + is_nevt = true + }; + is_rejected_event : bool = false; + let m : bits(64) = PMSEVFR_EL1.bits & mask; + let is_evt : bool = IsZero(not_vec(e) & m); + if PMSFCR_EL1[FE] == 0b1 then { + if not_bool(IsZero(m)) then { + is_rejected_event = not_bool(is_evt) + } else { + is_rejected_event = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR) + } + }; + if (HaveStatisticalProfilingv1p2() & (PMSFCR_EL1[FnE] @ PMSFCR_EL1[FE]) == 0b11) & not_bool(IsZero((PMSEVFR_EL1.bits & PMSNEVFR_EL1.bits) & mask)) then { + is_rejected_nevent = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR); + is_rejected_event = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR) + }; + if is_evt & is_nevt then { + PMUEvent(PMU_EVENT_SAMPLE_FEED_EVENT) + }; + is_op_br : bool = false; + is_op_ld : bool = false; + is_op_st : bool = false; + let is_op_br : bool = optype == OpType_Branch; + let is_op_ld : bool = optype == OpType_Load | optype == OpType_LoadAtomic; + let is_op_st : bool = optype == OpType_Store | optype == OpType_LoadAtomic; + if is_op_br then { + PMUEvent(PMU_EVENT_SAMPLE_FEED_BR) + }; + if is_op_ld then { + PMUEvent(PMU_EVENT_SAMPLE_FEED_LD) + }; + if is_op_st then { + PMUEvent(PMU_EVENT_SAMPLE_FEED_ST) + }; + let is_op : bool = (is_op_br & PMSFCR_EL1[B] == 0b1 | is_op_ld & PMSFCR_EL1[LD] == 0b1) | is_op_st & PMSFCR_EL1[ST] == 0b1; + if is_op then { + PMUEvent(PMU_EVENT_SAMPLE_FEED_OP) + }; + is_rejected_type : bool = false; + if PMSFCR_EL1[FT] == 0b1 then { + if not_bool(IsZero(PMSFCR_EL1[B] @ (PMSFCR_EL1[LD] @ PMSFCR_EL1[ST]))) then { + is_rejected_type = not_bool(is_op) + } else { + is_rejected_type = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR) + } + }; + is_rejected_latency : bool = false; + let is_lat : bool = total_latency < UInt(PMSLATFR_EL1[MINLAT]); + if is_lat then { + PMUEvent(PMU_EVENT_SAMPLE_FEED_LAT) + }; + if PMSFCR_EL1[FL] == 0b1 then { + if not_bool(IsZero(PMSLATFR_EL1[MINLAT])) then { + is_rejected_latency = not_bool(is_lat) + } else { + is_rejected_latency = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR) + } + }; + is_rejected_data_source : bool = undefined; + if ((HaveStatisticalProfilingFDS() & PMSFCR_EL1[FDS] == 0b1) & is_op_ld) & SPESampleDataSourceValid then { + let data_source : bits(16) = SPESampleDataSource; + let 'index = UInt(data_source[5 .. 0]); + is_rejected_data_source = [PMSDSFR_EL1.bits[index]] == 0b0 + } else { + is_rejected_data_source = false + }; + let return_value : bool = not_bool(((is_rejected_nevent | is_rejected_event) | is_rejected_type) | is_rejected_latency); + if return_value then { + PMUEvent(PMU_EVENT_SAMPLE_FILTRATE) + }; + return(return_value) +} + +bitfield PMBIDR_EL1_Type : bits(64) = + {EA : 11..8, F : 5..5, P : 4..4, Align : 3..0} + +register PMBIDR_EL1 : PMBIDR_EL1_Type + +register SPERecordData : vector(64, bits(8)) + +val SPEAddByteToRecord : bits(8) -> unit + +function SPEAddByteToRecord b = { + let size = SPERecordSize; + assert(0 <= size & size < SPEMaxRecordSize); + SPERecordData[size] = b; + SPERecordSize = size + 1 +} + +val SPEAddPacketToRecord : forall 'N, 'N in {8, 16, 32, 64}. + (bits(2), bits(4), bits('N)) -> unit + +function SPEAddPacketToRecord (header_hi, header_lo, payload) = { + assert(MOD('N, 8) == 0); + sz : bits(2) = undefined; + match 'N { + 8 => { + sz = 0b00 + }, + 16 => { + sz = 0b01 + }, + 32 => { + sz = 0b10 + }, + 64 => { + sz = 0b11 + }, + _ => { + Unreachable() + } + }; + let header : bits(8) = (header_hi @ sz) @ header_lo; + SPEAddByteToRecord(header); + foreach (i from 0 to (DIV('N, 8) - 1) by 1 in inc) { + SPEAddByteToRecord(payload[i * 8 + 7 .. i * 8]) + } +} + +val SPEEmptyRecord : unit -> unit + +function SPEEmptyRecord () = { + SPERecordSize = 0; + foreach (i from 0 to (SPEMaxRecordSize - 1) by 1 in inc) { + SPERecordData[i] = Zeros(8) + } +} + +val SPEGetDataSourcePayloadSize : unit -> int + +function SPEGetDataSourcePayloadSize () = { + return(__IMPDEF_integer("SPE Data Source packet payload size")) +} + +val SPEGetEventsPayloadSize : unit -> int + +function SPEGetEventsPayloadSize () = { + let 'size = __IMPDEF_integer("SPE Events packet payload size"); + return(size) +} + +register SPESampleCounter : vector(32, int) + +val DebugMemWrite : forall ('aligned : Bool). + (bits(64), AccessDescriptor, bool('aligned), bits(8)) -> (PhysMemRetStatus, AddressDescriptor) + +function DebugMemWrite (vaddress, accdesc, aligned, data) = { + memstatus : PhysMemRetStatus = __UNKNOWN_PhysMemRetStatus(); + let 'size = 1; + let addrdesc : AddressDescriptor = AArch64_TranslateAddress(vaddress, accdesc, aligned, size); + if IsFault(addrdesc) then { + return((memstatus, addrdesc)) + }; + let memstatus : PhysMemRetStatus = PhysMemWrite(addrdesc, 1, accdesc, None(), data); // TODO: TranslationInfo + return((memstatus, addrdesc)) +} + +val DebugWriteExternalAbort : (PhysMemRetStatus, AddressDescriptor, bits(64)) -> unit + +function DebugWriteExternalAbort (memstatus, addrdesc, start_vaddr) = { + let iswrite : bool = true; + handle_as_SError : bool = false; + async_external_abort : bool = false; + syndrome : bits(64) = undefined; + match addrdesc.fault.access.acctype { + AccessType_SPE => { + handle_as_SError = __IMPDEF_boolean("SPE SyncExternal as SError"); + async_external_abort = __IMPDEF_boolean("SPE async External abort"); + syndrome = PMBSR_EL1.bits[63 .. 0] + }, + _ => { + Unreachable() + } + }; + let ttw_abort : bool = addrdesc.fault.statuscode == Fault_SyncExternalOnWalk | addrdesc.fault.statuscode == Fault_SyncParityOnWalk; + let statuscode : Fault = if ttw_abort then addrdesc.fault.statuscode else + memstatus.statuscode; + let extflag : bits(1) = if ttw_abort then addrdesc.fault.extflag else + memstatus.extflag; + if (statuscode == Fault_AsyncExternal | statuscode == Fault_AsyncParity) | handle_as_SError then { + fault : FaultRecord = NoFault(); + let parity : bool = statuscode == Fault_SyncParity | statuscode == Fault_AsyncParity | statuscode == Fault_SyncParityOnWalk; + fault.statuscode = if parity then Fault_AsyncParity else + Fault_AsyncExternal; + if HaveRASExt() then { + fault.merrorstate = memstatus.merrorstate + }; + fault.extflag = extflag; + fault.access.acctype = addrdesc.fault.access.acctype; + PendSErrorInterrupt(fault) + } else { + syndrome[18] = Bit(0b1); + if addrdesc.fault.access.acctype == AccessType_SPE & (async_external_abort | start_vaddr != addrdesc.vaddress) then { + syndrome[19] = Bit(0b1) + }; + if IsZero([syndrome[17]]) then { + syndrome[17] = Bit(0b1); + ec : bits(6) = undefined; + if (HaveRME() & addrdesc.fault.gpcf.gpf != GPCF_None) & addrdesc.fault.gpcf.gpf != GPCF_Fail then { + ec = 0b011110 + } else { + ec = if addrdesc.fault.secondstage then 0b100101 else 0b100100 + }; + syndrome[31 .. 26] = ec; + if async_external_abort then { + syndrome[15 .. 0] = Zeros(10) @ 0b010001 + } else { + syndrome[15 .. 0] = Zeros(10) @ EncodeLDFSC(statuscode, addrdesc.fault.level) + } + }; + match addrdesc.fault.access.acctype { + AccessType_SPE => { + PMBSR_EL1.bits[63 .. 0] = syndrome + }, + _ => { + Unreachable() + } + } + } +} + +val DebugWriteFault : (bits(64), FaultRecord) -> unit + +function DebugWriteFault (vaddress, fault) = { + syndrome : bits(64) = undefined; + match fault.access.acctype { + AccessType_SPE => { + syndrome = PMBSR_EL1.bits[63 .. 0] + }, + _ => { + Unreachable() + } + }; + syndrome[15 .. 0] = Zeros(10) @ EncodeLDFSC(fault.statuscode, fault.level); + syndrome[55 .. 32] = Zeros(24); + ec : bits(6) = undefined; + if (HaveRME() & fault.gpcf.gpf != GPCF_None) & fault.gpcf.gpf != GPCF_Fail then { + ec = 0b011110 + } else { + ec = if fault.secondstage then 0b100101 else 0b100100 + }; + syndrome[31 .. 26] = ec; + syndrome[17] = Bit(0b1); + if fault.statuscode == Fault_Permission then { + syndrome[39] = Bit(if fault.assuredonly then 0b1 else 0b0); + syndrome[38] = Bit(if fault.overlay then 0b1 else 0b0); + syndrome[37] = Bit(if fault.dirtybit then 0b1 else 0b0) + }; + match fault.access.acctype { + AccessType_SPE => { + PMBSR_EL1.bits[63 .. 0] = syndrome + }, + _ => { + Unreachable() + } + }; + return() +} + +val SPEWriteToBuffer : unit -> unit + +function SPEWriteToBuffer () = { + assert(ProfilingBufferEnabled()); + let aligned : bool = is_zero_subrange(PMBPTR_EL1[PTR], UInt(PMBIDR_EL1[Align]) - 1, 0); + let ttw_fault_as_external_abort : bool = __IMPDEF_boolean("SPE TTW fault External abort"); + fault : FaultRecord = undefined; + memstatus : PhysMemRetStatus = undefined; + addrdesc : AddressDescriptor = undefined; + owning_ss : SecurityState = undefined; + owning_el : bits(2) = undefined; + (owning_ss, owning_el) = ProfilingBufferOwner(); + let accdesc : AccessDescriptor = CreateAccDescSPE(owning_ss, owning_el); + let start_vaddr : bits(64) = PMBPTR_EL1.bits[63 .. 0]; + foreach (i from 0 to (SPERecordSize - 1) by 1 in inc) { + if PMBSR_EL1[S] == 0b0 then { + assert(constraint((0 <= 'loop_i & 'loop_i < 64))); + (memstatus, addrdesc) = DebugMemWrite(PMBPTR_EL1.bits[63 .. 0], accdesc, aligned, SPERecordData[i]); + fault = addrdesc.fault; + let ttw_fault : bool = fault.statuscode == Fault_SyncExternalOnWalk | fault.statuscode == Fault_SyncParityOnWalk; + if IsFault__1(fault.statuscode) & not_bool(ttw_fault & ttw_fault_as_external_abort) then { + DebugWriteFault(PMBPTR_EL1.bits[63 .. 0], fault) + } else if IsFault__2(memstatus) | ttw_fault & ttw_fault_as_external_abort then { + DebugWriteExternalAbort(memstatus, addrdesc, start_vaddr) + } else (); + if IsZero(PMBSR_EL1[S]) then { + PMBPTR_EL1 = Mk_PMBPTR_EL1_Type(PMBPTR_EL1.bits + 1) + }; + () + }; + () + }; + return() +} + +val SPEConstructRecord : unit -> unit + +function SPEConstructRecord () = { + payload_size : int = undefined; + SPEEmptyRecord(); + if SPESampleContextEL1Valid then { + SPEAddPacketToRecord(0b01, 0b0100, SPESampleContextEL1) + }; + if SPESampleContextEL2Valid then { + SPEAddPacketToRecord(0b01, 0b0101, SPESampleContextEL2) + }; + foreach (counter_index from 0 to (SPEMaxCounters - 1) by 1 in inc) { + if SPESampleCounterValid[counter_index] then { + if counter_index >= 8 then { + SPEAddByteToRecord(0b001000 @ counter_index[4 .. 3]) + }; + let large_counters : bool = __IMPDEF_boolean("SPE 16bit counters"); + if SPESampleCounter[counter_index] > UInt(0xFFFF) & large_counters then { + SPESampleCounter[counter_index] = UInt(0xFFFF) + } else if SPESampleCounter[counter_index] > UInt(0xFFF) then { + SPESampleCounter[counter_index] = UInt(0xFFF) + } else (); + SPEAddPacketToRecord(0b10, 0b1 @ counter_index[2 .. 0], SPESampleCounter[counter_index][15 .. 0]) + }; + () + }; + if HaveStatisticalProfilingv1p2() then { + let include_prev_br_name : bool = __IMPDEF_boolean("SPE get prev br if not br"); + if SPESampleOpType != OpType_Branch & not_bool(include_prev_br_name) then { + SPESampleAddressValid[SPEAddrPosPrevBranchTarget] = false + }; + () + }; + if not_bool(StatisticalProfilingEnabled__1(EL2)) & SPESampleInstIsNV2 then { + SPESampleAddressValid[SPEAddrPosDataVirtual] = false + }; + foreach (address_index from 0 to (SPEMaxAddrs - 1) by 1 in inc) { + if SPESampleAddressValid[address_index] then { + if address_index >= 8 then { + SPEAddByteToRecord(0b001000 @ address_index[4 .. 3]) + }; + SPEAddPacketToRecord(0b10, 0b0 @ address_index[2 .. 0], SPESampleAddress[address_index]) + }; + () + }; + if SPESampleDataSourceValid then { + payload_size = SPEGetDataSourcePayloadSize(); + let 'payload_size = payload_size; + assert(constraint((0 <= 8 * 'payload_size - 1 & 8 * 'payload_size - 1 < 16))); + SPEAddPacketToRecord(0b01, 0b0011, SPESampleDataSource[8 * payload_size - 1 .. 0]) + }; + SPEAddPacketToRecord(0b01, 0b10 @ SPESampleClass, SPESampleSubclass); + let 'payload_size = SPEGetEventsPayloadSize(); + assert(constraint((0 <= 8 * 'payload_size - 1 & 8 * 'payload_size - 1 < 64))); + assert(constraint((8 * 'payload_size - 1 - 0 + 1 == 8 | 8 * 'payload_size - 1 - 0 + 1 == 16 | 8 * 'payload_size - 1 - 0 + 1 == 32 | 8 * 'payload_size - 1 - 0 + 1 == 64))); + SPEAddPacketToRecord(0b01, 0b0010, SPESampleEvents[8 * payload_size - 1 .. 0]); + if SPESampleTimestampValid then { + SPEAddPacketToRecord(0b01, 0b0001, SPESampleTimestamp) + } else { + SPEAddByteToRecord(0b00000001) + }; + while MOD(SPERecordSize, (1 << UInt(PMBIDR_EL1[Align]))) != 0 do { + SPEAddByteToRecord(Zeros(8)) + }; + SPEWriteToBuffer() +} + +val SPEResetSampleStorage : unit -> unit + +function SPEResetSampleStorage () = { + SPESampleContextEL1 = Zeros(32); + SPESampleContextEL1Valid = false; + SPESampleContextEL2 = Zeros(32); + SPESampleContextEL2Valid = false; + foreach (i from 0 to (SPEMaxCounters - 1) by 1 in inc) { + SPESampleCounter[i] = 0; + SPESampleCounterValid[i] = false; + SPESampleCounterPending[i] = false + }; + foreach (i from 0 to (SPEMaxAddrs - 1) by 1 in inc) { + SPESampleAddressValid[i] = false; + SPESampleAddress[i] = Zeros(64) + }; + SPESampleDataSource = Zeros(16); + SPESampleDataSourceValid = false; + SPESampleClass = Zeros(2); + SPESampleSubclass = Zeros(8); + SPESampleSubclassValid = false; + SPESampleTimestamp = Zeros(64); + SPESampleTimestampValid = false; + SPESampleEvents[63 .. 48] = __IMPDEF_bits(16, "SPE EVENTS 63_48"); + SPESampleEvents[47 .. 32] = Zeros(16); + SPESampleEvents[31 .. 24] = __IMPDEF_bits(8, "SPE EVENTS 31_24"); + SPESampleEvents[23 .. 16] = Zeros(8); + SPESampleEvents[15 .. 12] = __IMPDEF_bits(4, "SPE EVENTS 15_12"); + SPESampleEvents[11 .. 0] = Zeros(12); + SPESampleInstIsNV2 = false +} + +val SPEPostExecution : unit -> unit + +function SPEPostExecution () = { + if SPESampleInFlight then { + SPESampleInFlight = false; + PMUEvent(PMU_EVENT_SAMPLE_FEED); + foreach (counter_index from 0 to (SPEMaxCounters - 1) by 1 in inc) { + if SPESampleCounterPending[counter_index] then { + SPEStopCounter(counter_index) + }; + () + }; + discard : bool = false; + if HaveStatisticalProfilingv1p2() then { + discard = PMBLIMITR_EL1[FM] == 0b10 + }; + if SPECollectRecord(SPESampleEvents, SPESampleCounter[SPECounterPosTotalLatency], SPESampleOpType) & not_bool(discard) then { + SPEConstructRecord(); + if SPEBufferIsFull() then { + SPEBufferFilled() + }; + () + }; + SPEResetSampleStorage() + }; + () +} + +val SPECycle : unit -> unit + +function SPECycle () = { + if not_bool(HaveStatisticalProfiling()) then { + return() + }; + if SPESampleInFlight then { + foreach (i from 0 to (SPEMaxCounters - 1) by 1 in inc) { + if SPESampleCounterPending[i] then { + SPESampleCounter[i] = SPESampleCounter[i] + 1 + }; + () + } + }; + SetInterruptRequestLevel(InterruptID_PMBIRQ, if PMBSR_EL1[S] == 0b1 then + Signal_High + else + Signal_Low) +} + +val SPEGetRandomBoolean : unit -> bool + +function SPEGetRandomBoolean () = { + return([SPEGetRandomInterval()[0]] == 0b1) +} + +val SPE_PMBIDR_P_Read : unit -> bits(1) + +function SPE_PMBIDR_P_Read () = { + owning_ss : SecurityState = undefined; + owning_el : bits(2) = undefined; + (owning_ss, owning_el) = ProfilingBufferOwner(); + if UInt(owning_el) > UInt(PSTATE.EL) | PSTATE.EL != EL3 & owning_ss != CurrentSecurityState() then { + return(0b1) + } else { + return(0b0) + } +} + +val SPESampleExtendedLoadStore : forall ('is_load : Bool). + (bits(1), bits(1), bits(1), bool('is_load)) -> unit + +function SPESampleExtendedLoadStore (ar, excl, at, is_load) = { + SPESampleClass = 0b01; + let ldst : bits(1) = if is_load then 0b0 else 0b1; + SPESampleSubclass = ((((0b000 @ ar) @ excl) @ at) @ 0b1) @ ldst; + SPESampleSubclassValid = true; + if is_load then { + if at == 0b1 then { + SPESampleOpType = OpType_LoadAtomic + } else { + SPESampleOpType = OpType_Load + } + } else { + SPESampleOpType = OpType_Store + } +} + +val SPESampleGeneralPurposeLoadStore : unit -> unit + +function SPESampleGeneralPurposeLoadStore () = { + SPESampleClass = 0b01; + SPESampleSubclass[7 .. 1] = Zeros(7); + SPESampleSubclassValid = true +} + +val SPESampleSIMDFPLoadStore : unit -> unit + +function SPESampleSIMDFPLoadStore () = { + SPESampleClass = 0b01; + SPESampleSubclass[7 .. 1] = 0b0000010; + SPESampleSubclassValid = true +} + +val SPESampleMemCopy : unit -> unit + +function SPESampleMemCopy () = { + let loads_pass_filter : bool = PMSFCR_EL1[FT] == 0b1 & PMSFCR_EL1[LD] == 0b1; + let stores_pass_filter : bool = PMSFCR_EL1[FT] == 0b1 & PMSFCR_EL1[ST] == 0b1; + record_load : bool = undefined; + if loads_pass_filter & not_bool(stores_pass_filter) then { + record_load = true + } else if not_bool(loads_pass_filter) & stores_pass_filter then { + record_load = false + } else { + record_load = SPEGetRandomBoolean() + }; + SPESampleClass = 0b01; + let ldst : bits(1) = if record_load then 0b0 else 0b1; + SPESampleSubclass[7 .. 0] = 0b0010000 @ ldst; + SPESampleSubclassValid = true; + SPESampleOpType = if record_load then OpType_Load else OpType_Store +} + +val SPESampleMemSet : unit -> unit + +function SPESampleMemSet () = { + SPESampleClass = 0b01; + SPESampleSubclass[7 .. 0] = 0b00100101; + SPESampleSubclassValid = true; + SPESampleOpType = OpType_Store +} + +val SPEISB : unit -> unit + +function SPEISB () = { + let address : bits(64) = PC_read() + 4; + let branch_type : BranchType = BranchType_DIR; + let branch_conditional : bool = false; + let taken : bool = false; + let is_isb : bool = true; + SPEBranch__1(address, branch_type, branch_conditional, taken, is_isb) +} + +val BRBEExceptionReturn : (bits(64), bits(2)) -> unit + +function BRBEExceptionReturn (target_address_in, source_el) = { + target_address : bits(64) = target_address_in; + match source_el { + ? if ? == EL3 => { + if not_bool(HaveBRBEv1p1()) | MDCR_EL3[E3BREC] == MDCR_EL3[E3BREW] then { + return() + }; + () + }, + ? if ? == EL2 => { + if BRBCR_EL2[ERTN] == 0b0 then { + return() + }; + () + }, + ? if ? == EL1 => { + if BRBCR_EL1[ERTN] == 0b0 then { + return() + }; + () + }, + _ => () + }; + let source_valid : bool = BranchRecordAllowed(source_el); + let target_valid : bool = BranchRecordAllowed(PSTATE.EL); + let branch_valid : bool = source_valid | target_valid; + if branch_valid then { + let branch_type : bits(6) = 0b000111; + ccu : bits(1) = undefined; + cc : bits(14) = undefined; + (ccu, cc) = BranchEncCycleCount(); + let lastfailed : bits(1) = if HaveTME() then BRBFCR_EL1[LASTFAILED] else + 0b0; + let transactional : bits(1) = if (source_valid & HaveTME()) & TSTATE.depth > 0 then + 0b1 + else + 0b0; + let el : bits(2) = if target_valid then PSTATE.EL else 0b00; + let mispredict : bits(1) = if (source_valid & BRBEMispredictAllowed()) & BranchMispredict() then + 0b1 + else + 0b0; + let sv : bits(1) = if source_valid then 0b1 else 0b0; + let tv : bits(1) = if target_valid then 0b1 else 0b0; + let source_address : bits(64) = if source_valid then PC_read() else + Zeros(64); + if not_bool(target_valid) then { + target_address = Zeros(64) + }; + UpdateBranchRecordBuffer(ccu, cc, lastfailed, transactional, branch_type, el, mispredict, sv @ tv, source_address, target_address); + BRBFCR_EL1[LASTFAILED] = 0b0; + PMUEvent(PMU_EVENT_BRB_FILTRATE) + }; + __last_branch_valid = branch_valid; + return() +} + +bitfield BRBINFINJ_EL1_Type : bits(64) = + { + CCU : 46..46, + CC : 45..32, + LASTFAILED : 17..17, + T : 16..16, + TYPE : 13..8, + EL : 7..6, + MPRED : 5..5, + VALID : 1..0 + } + +register BRBINFINJ_EL1 : BRBINFINJ_EL1_Type + +bitfield BRBSRCINJ_EL1_Type : bits(64) = {ADDRESS : 63..0} + +register BRBSRCINJ_EL1 : BRBSRCINJ_EL1_Type + +bitfield BRBTGTINJ_EL1_Type : bits(64) = {ADDRESS : 63..0} + +register BRBTGTINJ_EL1 : BRBTGTINJ_EL1_Type + +val BRB_INJ : unit -> unit + +function BRB_INJ () = { + UpdateBranchRecordBuffer(BRBINFINJ_EL1[CCU], BRBINFINJ_EL1[CC], BRBINFINJ_EL1[LASTFAILED], BRBINFINJ_EL1[T], BRBINFINJ_EL1[TYPE], BRBINFINJ_EL1[EL], BRBINFINJ_EL1[MPRED], BRBINFINJ_EL1[VALID], BRBSRCINJ_EL1[ADDRESS], BRBTGTINJ_EL1[ADDRESS]); + BRBINFINJ_EL1 = Mk_BRBINFINJ_EL1_Type(__UNKNOWN_bits(64)); + BRBSRCINJ_EL1 = Mk_BRBSRCINJ_EL1_Type(__UNKNOWN_bits(64)); + BRBTGTINJ_EL1 = Mk_BRBTGTINJ_EL1_Type(__UNKNOWN_bits(64)); + if ConstrainUnpredictableBool(Unpredictable_BRBFILTRATE) then { + PMUEvent(PMU_EVENT_BRB_FILTRATE) + }; + () +} + +val BRB_IALL : unit -> unit + +function BRB_IALL () = { + foreach (i from 0 to (GetBRBENumRecords() - 1) by 1 in inc) { + assert(constraint('loop_i < 64)); + Records_SRC[i] = Mk_BRBSRCType(Zeros(64)); + Records_TGT[i] = Mk_BRBTGTType(Zeros(64)); + Records_INF[i] = Mk_BRBINFType(Zeros(64)) + } +} + +val BRBEBranchOnISB : unit -> bool + +function BRBEBranchOnISB () = { + return(__IMPDEF_boolean("ISB generates Branch records")) +} + +val BRBEISB : unit -> unit + +function BRBEISB () = { + let branch_conditional : bool = false; + BRBEBranch(BranchType_DIR, branch_conditional, PC_read() + 4) +} + +val BranchNotTaken : forall ('branch_conditional : Bool). + (BranchType, bool('branch_conditional)) -> unit + +function BranchNotTaken (branchtype, branch_conditional) = { + let branchtaken : bool = false; + if HaveStatisticalProfiling() then { + SPEBranch(__UNKNOWN_bits(64), branchtype, branch_conditional, branchtaken) + }; + return() +} + +val AArch64_ExceptionReturn : (bits(64), bits(64)) -> unit + +function AArch64_ExceptionReturn (new_pc_in, spsr) = { + iesb_req : bool = undefined; + sync_errors : bool = undefined; + new_pc : bits(64) = new_pc_in; + if HaveTME() & TSTATE.depth > 0 then { + FailTransaction(TMFailure_ERR, false) + }; + if HaveIESB() then { + sync_errors : bool = SCTLR_read__1()[IESB] == 0b1; + if HaveDoubleFaultExt() then { + sync_errors = sync_errors | (SCR_EL3[EA] @ SCR_EL3[NMEA]) == 0b11 & PSTATE.EL == EL3 + }; + if sync_errors then { + SynchronizeErrors(); + let iesb_req : bool = true; + TakeUnmaskedPhysicalSErrorInterrupts(iesb_req) + }; + () + }; + let sync_errors = sync_errors; + SynchronizeContext(); + __InstructionStep = false; + let source_el : bits(2) = PSTATE.EL; + let illegal_psr_state : bool = IllegalExceptionReturn(spsr); + SetPSTATEFromPSR__1(spsr, illegal_psr_state); + ClearExclusiveLocal(ProcessorID()); + SendEventLocal(); + if illegal_psr_state & [spsr[4]] == 0b1 then { + new_pc[63 .. 32] = __UNKNOWN_bits(32); + new_pc[1 .. 0] = __UNKNOWN_bits(2) + } else if UsingAArch32() then { + if PSTATE.T == 0b1 then { + new_pc[0] = Bit(0b0) + } else { + new_pc[1 .. 0] = 0b00 + } + } else { + new_pc = AArch64_BranchAddr(new_pc, PSTATE.EL) + }; + if HaveBRBExt() then { + BRBEExceptionReturn(new_pc, source_el) + }; + if UsingAArch32() then { + if HaveSME() & PSTATE.SM == 0b1 then { + ResetSVEState() + }; + let branch_conditional : bool = false; + BranchTo(new_pc[31 .. 0], BranchType_ERET, branch_conditional) + } else { + BranchToAddr(new_pc, BranchType_ERET) + }; + CheckExceptionCatch(false) +} + +val DecodeRegExtend : bits(3) -> ExtendType + +function DecodeRegExtend op = { + match op { + 0b000 => { + return(ExtendType_UXTB) + }, + 0b001 => { + return(ExtendType_UXTH) + }, + 0b010 => { + return(ExtendType_UXTW) + }, + 0b011 => { + return(ExtendType_UXTX) + }, + 0b100 => { + return(ExtendType_SXTB) + }, + 0b101 => { + return(ExtendType_SXTH) + }, + 0b110 => { + return(ExtendType_SXTW) + }, + 0b111 => { + return(ExtendType_SXTX) + }, + _ => { + return(undefined : ExtendType) + } + } +} + +val ExtendReg : forall 'N 'reg 'shift, + 'N >= 0 & ('N == 8 | 'N == 16 | 'N == 32 | 'N == 64 | not(('shift >= 0 & 'shift <= 4))). + (int('reg), ExtendType, int('shift), int('N)) -> bits('N) + +function ExtendReg (reg, exttype, shift, N) = { + assert(shift >= 0 & shift <= 4); + let val_name : bits('N) = X_read(reg, N); + is_unsigned : bool = undefined; + len : int = undefined; + match exttype { + ExtendType_SXTB => { + is_unsigned = false; + len = 8 + }, + ExtendType_SXTH => { + is_unsigned = false; + len = 16 + }, + ExtendType_SXTW => { + is_unsigned = false; + len = 32 + }, + ExtendType_SXTX => { + is_unsigned = false; + len = 64 + }, + ExtendType_UXTB => { + is_unsigned = true; + len = 8 + }, + ExtendType_UXTH => { + is_unsigned = true; + len = 16 + }, + ExtendType_UXTW => { + is_unsigned = true; + len = 32 + }, + ExtendType_UXTX => { + is_unsigned = true; + len = 64 + } + }; + let is_unsigned = is_unsigned; + let 'len = Min(len, N - shift); + assert(constraint((0 <= 'len - 1 | not(('shift >= 0 & 'shift <= 4))))); + return(Extend(val_name[len - 1 .. 0] @ Zeros(shift), N, is_unsigned)) +} + +val DecodeShift : bits(2) -> ShiftType + +function DecodeShift op = { + match op { + 0b00 => { + return(ShiftType_LSL) + }, + 0b01 => { + return(ShiftType_LSR) + }, + 0b10 => { + return(ShiftType_ASR) + }, + 0b11 => { + return(ShiftType_ROR) + }, + _ => { + return(undefined : ShiftType) + } + } +} + +val ShiftReg : forall 'N 'amount 'reg, + 'N in {8, 16, 32, 64}. + (int('reg), ShiftType, int('amount), int('N)) -> bits('N) + +function ShiftReg (reg, shiftype, amount, N) = { + result : bits('N) = X_read(reg, N); + match shiftype { + ShiftType_LSL => { + result = LSL(result, amount) + }, + ShiftType_LSR => { + result = LSR(result, amount) + }, + ShiftType_ASR => { + result = ASR(result, amount) + }, + ShiftType_ROR => { + assert(constraint(('N > 0 & 'amount >= 0))); + result = ROR(result, amount) + } + }; + return(result) +} + +val Prefetch : (bits(64), bits(5)) -> unit + +function Prefetch (address, prfop) = { + hint : PrefetchHint = undefined; + match prfop[4 .. 3] { + 0b00 => { + hint = Prefetch_READ + }, + 0b01 => { + hint = Prefetch_EXEC + }, + 0b10 => { + hint = Prefetch_WRITE + }, + 0b11 => { + return() + } + }; + let 'target = UInt(prfop[2 .. 1]); + let stream : bool = [prfop[0]] != 0b0; + Hint_Prefetch(address, hint, target, stream); + return() +} + +val _TLBInvalidate : unit -> unit + +val report_tlbi : (TLBIRecord, Shareability) -> unit + +val TLBI : (TLBIRecord, Shareability) -> unit + +function TLBI (r, s) = { + report_tlbi(r, s); + _TLBInvalidate() +} + +val Broadcast : (Shareability, TLBIRecord) -> unit + +function Broadcast (shareability, r) = { + return() +} + +val AArch64_TLBI_ALL : (SecurityState, Regime, Shareability, TLBIMemAttr) -> unit + +function AArch64_TLBI_ALL (security, regime, shareability, attr) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2); + r : TLBIRecord = undefined; + r.op = TLBIOp_ALL; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.level = TLBILevel_Any; + r.attr = attr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_VMALL : (SecurityState, Regime, bits(16), Shareability, TLBIMemAttr) -> unit + +function AArch64_TLBI_VMALL (security, regime, vmid, shareability, attr) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VMALL; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.level = TLBILevel_Any; + r.vmid = vmid; + r.attr = attr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_VMALLS12 : (SecurityState, Regime, bits(16), Shareability, TLBIMemAttr) -> unit + +function AArch64_TLBI_VMALLS12 (security, regime, vmid, shareability, attr) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2); + r : TLBIRecord = undefined; + r.op = TLBIOp_VMALLS12; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.level = TLBILevel_Any; + r.vmid = vmid; + r.attr = attr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_ASID : (SecurityState, Regime, bits(16), Shareability, TLBIMemAttr, bits(64)) -> unit + +function AArch64_TLBI_ASID (security, regime, vmid, shareability, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_ASID; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = TLBILevel_Any; + r.attr = attr; + r.asid = Xt[63 .. 48]; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_VA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(64)) -> unit + +function AArch64_TLBI_VA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.asid = Xt[63 .. 48]; + r.ttl = Xt[47 .. 44]; + r.address = ZeroExtend(Xt[43 .. 0] @ Zeros(12), 64); + r.d64 = true; + r.d128 = (match r.ttl { + [bitzero, bitzero, _, _] => true, + _ => false + }) : bool; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBIP_VA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(128)) -> unit + +function AArch64_TLBIP_VA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.asid = Xt[63 .. 48]; + r.ttl = Xt[47 .. 44]; + r.address = ZeroExtend(Xt[107 .. 64] @ Zeros(12), 64); + r.d64 = (match r.ttl { + [bitzero, bitzero, _, _] => true, + _ => false + }) : bool; + r.d128 = true; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_VAA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(64)) -> unit + +function AArch64_TLBI_VAA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VAA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl = Xt[47 .. 44]; + r.address = ZeroExtend(Xt[43 .. 0] @ Zeros(12), 64); + r.d64 = true; + r.d128 = (match r.ttl { + [bitzero, bitzero, _, _] => true, + _ => false + }) : bool; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBIP_VAA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(128)) -> unit + +function AArch64_TLBIP_VAA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VAA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl = Xt[47 .. 44]; + r.address = ZeroExtend(Xt[107 .. 64] @ Zeros(12), 64); + r.d64 = (match r.ttl { + [bitzero, bitzero, _, _] => true, + _ => false + }) : bool; + r.d128 = true; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_IPAS2 : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(64)) -> unit + +function AArch64_TLBI_IPAS2 (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2); + r : TLBIRecord = undefined; + r.op = TLBIOp_IPAS2; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl = Xt[47 .. 44]; + r.address = ZeroExtend(Xt[39 .. 0] @ Zeros(12), 64); + r.d64 = true; + r.d128 = (match r.ttl { + [bitzero, bitzero, _, _] => true, + _ => false + }) : bool; + match security { + SS_NonSecure => { + r.ipaspace = PAS_NonSecure + }, + SS_Secure => { + r.ipaspace = if [Xt[63]] == 0b1 then PAS_NonSecure else PAS_Secure + }, + SS_Realm => { + r.ipaspace = PAS_Realm + }, + _ => { + Unreachable() + } + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBIP_IPAS2 : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(128)) -> unit + +function AArch64_TLBIP_IPAS2 (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2); + r : TLBIRecord = undefined; + r.op = TLBIOp_IPAS2; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl = Xt[47 .. 44]; + r.address = ZeroExtend(Xt[107 .. 64] @ Zeros(12), 64); + r.d64 = (match r.ttl { + [bitzero, bitzero, _, _] => true, + _ => false + }) : bool; + r.d128 = true; + match security { + SS_NonSecure => { + r.ipaspace = PAS_NonSecure + }, + SS_Secure => { + r.ipaspace = if [Xt[63]] == 0b1 then PAS_NonSecure else PAS_Secure + }, + SS_Realm => { + r.ipaspace = PAS_Realm + }, + _ => { + Unreachable() + } + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val HasLargeAddress : Regime -> bool + +function HasLargeAddress regime = { + if not_bool(Have52BitIPAAndPASpaceExt()) then { + return(false) + }; + match regime { + Regime_EL3 => { + return([TCR_EL3.bits[32]] == 0b1) + }, + Regime_EL2 => { + return([TCR_EL2.bits[32]] == 0b1) + }, + Regime_EL20 => { + return([TCR_EL2.bits[59]] == 0b1) + }, + Regime_EL10 => { + return([TCR_EL1.bits[59]] == 0b1) + }, + _ => { + Unreachable(); + return(undefined : bool) + } + } +} + +val TLBIRange : (Regime, bits(64)) -> (bool, bits(2), bits(64), bits(64)) + +function TLBIRange (regime, Xt) = { + let valid_name : bool = true; + start_address : bits(64) = Zeros(64); + end_address_name : bits(64) = Zeros(64); + let tg : bits(2) = Xt[47 .. 46]; + let 'scale = UInt(Xt[45 .. 44]); + let 'num = UInt(Xt[43 .. 39]); + tg_bits : {12, 14, 16} = 12; + if tg == 0b00 then { + return((false, tg, start_address, end_address_name)) + }; + match tg { + 0b01 => { + tg_bits = 12; + if HasLargeAddress(regime) then { + start_address[52 .. 16] = Xt[36 .. 0]; + start_address[63 .. 53] = Replicate([Xt[36]], 11) + } else { + start_address[48 .. 12] = Xt[36 .. 0]; + start_address[63 .. 49] = Replicate([Xt[36]], 15) + } + }, + 0b10 => { + tg_bits = 14; + if HasLargeAddress(regime) then { + start_address[52 .. 16] = Xt[36 .. 0]; + start_address[63 .. 53] = Replicate([Xt[36]], 11) + } else { + start_address[50 .. 14] = Xt[36 .. 0]; + start_address[63 .. 51] = Replicate([Xt[36]], 13) + } + }, + 0b11 => { + tg_bits = 16; + start_address[52 .. 16] = Xt[36 .. 0]; + start_address[63 .. 53] = Replicate([Xt[36]], 11) + }, + _ => { + Unreachable() + } + }; + let 'tg_bits = tg_bits; + let 'range = ((num + 1) << (5 * scale + 1 + tg_bits)); + end_address_name : bits(64) = start_address + range[63 .. 0]; + if [end_address_name[52]] != [start_address[52]] then { + end_address_name = Replicate([start_address[52]], 64 - 52) @ Ones(52) + }; + return((valid_name, tg, start_address, end_address_name)) +} + +val TLBIPRange : (Regime, bits(128)) -> (bool, bits(2), bits(64), bits(64)) + +function TLBIPRange (regime, Xt) = { + let valid_name : bool = true; + start_address : bits(64) = Zeros(64); + end_address_name : bits(64) = Zeros(64); + let tg : bits(2) = Xt[47 .. 46]; + let 'scale = UInt(Xt[45 .. 44]); + let 'num = UInt(Xt[43 .. 39]); + tg_bits : {12, 14, 16} = 12; + if tg == 0b00 then { + return((false, tg, start_address, end_address_name)) + }; + match tg { + 0b01 => { + tg_bits = 12; + start_address[55 .. 12] = Xt[107 .. 64]; + start_address[63 .. 56] = Replicate([Xt[107]], 8) + }, + 0b10 => { + tg_bits = 14; + start_address[55 .. 14] = Xt[107 .. 66]; + start_address[63 .. 56] = Replicate([Xt[107]], 8) + }, + 0b11 => { + tg_bits = 16; + start_address[55 .. 16] = Xt[107 .. 68]; + start_address[63 .. 56] = Replicate([Xt[107]], 8) + }, + _ => { + Unreachable() + } + }; + let 'tg_bits = tg_bits; + let 'range = ((num + 1) << (5 * scale + 1 + tg_bits)); + end_address_name : bits(64) = start_address + range[63 .. 0]; + if [end_address_name[55]] != [start_address[55]] then { + end_address_name = Replicate([start_address[55]], 64 - 55) @ Ones(55) + }; + return((valid_name, tg, start_address, end_address_name)) +} + +val AArch64_TLBI_RVA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(64)) -> unit + +function AArch64_TLBI_RVA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_RVA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.asid = Xt[63 .. 48]; + r.ttl[1 .. 0] = Xt[38 .. 37]; + r.d64 = true; + r.d128 = r.ttl[1 .. 0] == 0b00; + valid_name : bool = undefined; + (valid_name, r.tg, r.address, r.end_address_name) = TLBIRange(regime, Xt); + if not_bool(valid_name) then { + return() + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBIP_RVA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(128)) -> unit + +function AArch64_TLBIP_RVA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_RVA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.asid = Xt[63 .. 48]; + r.ttl[1 .. 0] = Xt[38 .. 37]; + r.d64 = r.ttl[1 .. 0] == 0b00; + r.d128 = true; + valid_name : bool = undefined; + (valid_name, r.tg, r.address, r.end_address_name) = TLBIPRange(regime, Xt); + if not_bool(valid_name) then { + return() + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_RVAA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(64)) -> unit + +function AArch64_TLBI_RVAA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_RVAA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl[1 .. 0] = Xt[38 .. 37]; + r.d64 = true; + r.d128 = r.ttl[1 .. 0] == 0b00; + let tg : bits(2) = Xt[47 .. 46]; + let 'scale = UInt(Xt[45 .. 44]); + let 'num = UInt(Xt[43 .. 39]); + let 'baseaddr = SInt(Xt[36 .. 0]); + valid_name : bool = undefined; + (valid_name, r.tg, r.address, r.end_address_name) = TLBIRange(regime, Xt); + if not_bool(valid_name) then { + return() + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBIP_RVAA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(128)) -> unit + +function AArch64_TLBIP_RVAA (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_RVAA; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl[1 .. 0] = Xt[38 .. 37]; + r.d64 = r.ttl[1 .. 0] == 0b00; + r.d128 = true; + let tg : bits(2) = Xt[47 .. 46]; + let 'scale = UInt(Xt[45 .. 44]); + let 'num = UInt(Xt[43 .. 39]); + let 'baseaddr = SInt(Xt[36 .. 0]); + valid_name : bool = undefined; + (valid_name, r.tg, r.address, r.end_address_name) = TLBIPRange(regime, Xt); + if not_bool(valid_name) then { + return() + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_RIPAS2 : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(64)) -> unit + +function AArch64_TLBI_RIPAS2 (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_RIPAS2; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl[1 .. 0] = Xt[38 .. 37]; + r.d64 = true; + r.d128 = r.ttl[1 .. 0] == 0b00; + let tg : bits(2) = Xt[47 .. 46]; + let 'scale = UInt(Xt[45 .. 44]); + let 'num = UInt(Xt[43 .. 39]); + let 'baseaddr = SInt(Xt[36 .. 0]); + valid_name : bool = undefined; + (valid_name, r.tg, r.address, r.end_address_name) = TLBIRange(regime, Xt); + if not_bool(valid_name) then { + return() + }; + match security { + SS_NonSecure => { + r.ipaspace = PAS_NonSecure + }, + SS_Secure => { + r.ipaspace = if [Xt[63]] == 0b1 then PAS_NonSecure else PAS_Secure + }, + SS_Realm => { + r.ipaspace = PAS_Realm + }, + _ => { + Unreachable() + } + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBIP_RIPAS2 : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(128)) -> unit + +function AArch64_TLBIP_RIPAS2 (security, regime, vmid, shareability, level, attr, Xt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_RIPAS2; + r.from_aarch64 = true; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.ttl[1 .. 0] = Xt[38 .. 37]; + r.d64 = r.ttl[1 .. 0] == 0b00; + r.d128 = true; + let tg : bits(2) = Xt[47 .. 46]; + let 'scale = UInt(Xt[45 .. 44]); + let 'num = UInt(Xt[43 .. 39]); + let 'baseaddr = SInt(Xt[36 .. 0]); + valid_name : bool = undefined; + (valid_name, r.tg, r.address, r.end_address_name) = TLBIPRange(regime, Xt); + if not_bool(valid_name) then { + return() + }; + match security { + SS_NonSecure => { + r.ipaspace = PAS_NonSecure + }, + SS_Secure => { + r.ipaspace = if [Xt[63]] == 0b1 then PAS_NonSecure else PAS_Secure + }, + SS_Realm => { + r.ipaspace = PAS_Realm + }, + _ => { + Unreachable() + } + }; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_TLBI_RPA : (TLBILevel, bits(64), Shareability) -> unit + +function AArch64_TLBI_RPA (level, Xt, shareability) = { + assert(HaveRME() & PSTATE.EL == EL3); + r : TLBIRecord = undefined; + range_bits : int = undefined; + p : {12, 14, 16} = 12; + r.op = TLBIOp_RPA; + r.level = level; + r.attr = TLBI_AllAttr; + match Xt[47 .. 44] { + 0b0000 => { + range_bits = 12 + }, + 0b0001 => { + range_bits = 14 + }, + 0b0010 => { + range_bits = 16 + }, + 0b0011 => { + range_bits = 21 + }, + 0b0100 => { + range_bits = 25 + }, + 0b0101 => { + range_bits = 29 + }, + 0b0110 => { + range_bits = 30 + }, + 0b0111 => { + range_bits = 34 + }, + 0b1000 => { + range_bits = 36 + }, + 0b1001 => { + range_bits = 39 + }, + _ => { + range_bits = 0 + } + }; + match DecodePGS(GPCCR_EL3[PGS]) { + PGS_4KB => { + p = 12 + }, + PGS_16KB => { + p = 14 + }, + PGS_64KB => { + p = 16 + } + }; + let 'p = p; + if range_bits < p then { + range_bits = p + }; + let 'range_bits = range_bits; + BaseADDR : bits(52) = Zeros(52); + match GPCCR_EL3[PGS] { + 0b00 => { + BaseADDR[51 .. 12] = Xt[39 .. 0] + }, + 0b10 => { + BaseADDR[51 .. 14] = Xt[39 .. 2] + }, + 0b01 => { + BaseADDR[51 .. 16] = Xt[39 .. 4] + }, + _ => () + }; + assert(constraint('range_bits >= 0)); + assert(constraint(52 >= 'range_bits)); + let start_addr : bits(52) = BaseADDR & not_vec(ZeroExtend(Ones(range_bits), 52)); + let end_addr_name : bits(52) = start_addr + ZeroExtend(Ones(range_bits), 52); + r.address = ZeroExtend(start_addr, 64); + r.end_address_name = ZeroExtend(end_addr_name, 64); + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + () +} + +val AArch64_TLBI_PAALL : Shareability -> unit + +function AArch64_TLBI_PAALL shareability = { + assert(HaveRME() & PSTATE.EL == EL3); + r : TLBIRecord = undefined; + r.op = TLBIOp_PAALL; + r.level = TLBILevel_Any; + r.attr = TLBI_AllAttr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch64_DC : (bits(64), CacheType, CacheOp, CacheOpScope) -> unit + +function AArch64_DC (regval, cachetype, cacheop, opscope_in) = { + ss : SecurityState = undefined; + opscope : CacheOpScope = opscope_in; + cache : CacheRecord = undefined; + cache.acctype = AccessType_DC; + cache.cachetype = cachetype; + cache.cacheop = cacheop; + cache.opscope = opscope; + if opscope == CacheOpScope_SetWay then { + let ss : SecurityState = SecurityStateAtEL(PSTATE.EL); + cache.cpas = CPASAtSecurityState(ss); + cache.shareability = Shareability_NSH; + (cache.setnum, cache.waynum, cache.level) = DecodeSW(regval, cachetype); + if ((cacheop == CacheOp_Invalidate & PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[SWIO] == 0b1 | (HCR_EL2[DC] @ HCR_EL2[VM]) != 0b00) then { + cache.cacheop = CacheOp_CleanInvalidate + }; + CACHE_OP(cache); + return() + }; + if EL2Enabled() & not_bool(IsInHost()) then { + if PSTATE.EL == EL0 | PSTATE.EL == EL1 then { + cache.is_vmid_valid = true; + cache.vmid = VMID_read() + } else { + cache.is_vmid_valid = false + } + } else { + cache.is_vmid_valid = false + }; + if PSTATE.EL == EL0 then { + cache.is_asid_valid = true; + cache.asid = ASID_read() + } else { + cache.is_asid_valid = false + }; + if opscope == CacheOpScope_PoDP & __IMPDEF_boolean("Memory system does not supports PoDP") then { + opscope = CacheOpScope_PoP + }; + if opscope == CacheOpScope_PoP & __IMPDEF_boolean("Memory system does not supports PoP") then { + opscope = CacheOpScope_PoC + }; + vaddress : bits(64) = regval; + size : int = 0; + if cacheop == CacheOp_Invalidate then { + size = __IMPDEF_integer("Data Cache Invalidate Watchpoint Size"); + assert(size >= 4 * pow2(UInt(CTR_EL0[DminLine])) & size <= 2048); + assert(UInt(size[32 .. 0] & (size - 1)[32 .. 0]) == 0); + vaddress = Align(regval, size) + }; + let 'size = size; + if DCInstNeedsTranslation(opscope) then { + cache.vaddress = vaddress; + let aligned : bool = true; + let accdesc : AccessDescriptor = CreateAccDescDC(cache); + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(vaddress, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(regval, memaddrdesc.fault) + }; + cache.translated = true; + cache.paddress = memaddrdesc.paddress; + cache.cpas = CPASAtPAS(memaddrdesc.paddress.paspace); + if opscope == CacheOpScope_PoC | opscope == CacheOpScope_PoP | opscope == CacheOpScope_PoDP then { + cache.shareability = memaddrdesc.memattrs.shareability + } else { + cache.shareability = Shareability_NSH + } + } else if opscope == CacheOpScope_PoE then { + cache.translated = true; + cache.shareability = Shareability_OSH; + cache.paddress.address = regval[55 .. 0]; + cache.paddress.paspace = DecodePASpace([regval[62]], [regval[63]]); + cache.cpas = CPASAtPAS(cache.paddress.paspace); + if cache.paddress.paspace != PAS_Realm then { + EndOfInstruction() + }; + if __IMPDEF_boolean("Apply granule protection check on DC to PoE") then { + memaddrdesc : AddressDescriptor = undefined; + let accdesc : AccessDescriptor = CreateAccDescDC(cache); + memaddrdesc.paddress = cache.paddress; + memaddrdesc.fault.gpcf = GranuleProtectionCheck(memaddrdesc, accdesc); + if memaddrdesc.fault.gpcf.gpf != GPCF_None then { + memaddrdesc.fault.statuscode = Fault_GPCFOnOutput; + memaddrdesc.fault.paddress = memaddrdesc.paddress; + AArch64_Abort(__UNKNOWN_bits(64), memaddrdesc.fault) + }; + () + }; + () + } else if opscope == CacheOpScope_PoPA then { + cache.translated = true; + cache.shareability = Shareability_OSH; + cache.paddress.address = regval[55 .. 0]; + cache.paddress.paspace = DecodePASpace([regval[62]], [regval[63]]); + cache.cpas = CPASAtPAS(cache.paddress.paspace) + } else { + cache.vaddress = vaddress; + cache.translated = false; + cache.shareability = __UNKNOWN_Shareability(); + cache.paddress = __UNKNOWN_FullAddress() + }; + if ((cacheop == CacheOp_Invalidate & PSTATE.EL == EL1) & EL2Enabled()) & (HCR_EL2[DC] @ HCR_EL2[VM]) != 0b00 then { + cache.cacheop = CacheOp_CleanInvalidate + }; + if (cache.translated & cache.cpas == CPAS_Secure) & not_bool(HaveSecureState()) then { + return() + }; + CACHE_OP(cache); + return() +} + +bitfield DCZID_EL0_Type : bits(64) = {DZP : 4..4, BS : 3..0} + +register DCZID_EL0 : DCZID_EL0_Type + +val AArch64_MemZero : (bits(64), CacheType) -> unit + +function AArch64_MemZero (regval, cachetype) = { + let 'size = 4 * pow2(UInt(DCZID_EL0[BS])); + assert(size <= MAX_ZERO_BLOCK_SIZE); + if HaveMTE2Ext() then { + assert(size >= TAG_GRANULE) + }; + let vaddress : bits(64) = Align(regval, size); + let tagaccess : bool = cachetype == CacheType_Tag | cachetype == CacheType_Data_Tag; + let tagchecked : bool = cachetype == CacheType_Data; + let accdesc : AccessDescriptor = CreateAccDescDCZero(tagaccess, tagchecked); + if cachetype == CacheType_Tag | cachetype == CacheType_Data_Tag then { + AArch64_TagMemZero(regval, vaddress, accdesc, size) + }; + if cachetype == CacheType_Data | cachetype == CacheType_Data_Tag then { + AArch64_DataMemZero(regval, vaddress, accdesc, size) + }; + return() +} + +val AArch64_IC : CacheOpScope -> unit + +val AArch64_IC__1 : (bits(64), CacheOpScope) -> unit + +function AArch64_IC opscope = { + let regval : bits(64) = __UNKNOWN_bits(64); + AArch64_IC__1(regval, opscope) +} + +function AArch64_IC__1 (regval, opscope) = { + ss : SecurityState = undefined; + cache : CacheRecord = undefined; + cache.acctype = AccessType_IC; + cache.cachetype = CacheType_Instruction; + cache.cacheop = CacheOp_Invalidate; + cache.opscope = opscope; + if opscope == CacheOpScope_ALLU | opscope == CacheOpScope_ALLUIS then { + let ss : SecurityState = SecurityStateAtEL(PSTATE.EL); + cache.cpas = CPASAtSecurityState(ss); + if opscope == CacheOpScope_ALLUIS | ((opscope == CacheOpScope_ALLU & PSTATE.EL == EL1) & EL2Enabled()) & HCR_EL2[FB] == 0b1 then { + cache.shareability = Shareability_ISH + } else { + cache.shareability = Shareability_NSH + }; + cache.regval = regval; + CACHE_OP(cache) + } else { + assert(opscope == CacheOpScope_PoU); + if EL2Enabled() & not_bool(IsInHost()) then { + if PSTATE.EL == EL0 | PSTATE.EL == EL1 then { + cache.is_vmid_valid = true; + cache.vmid = VMID_read() + } else { + cache.is_vmid_valid = false + } + } else { + cache.is_vmid_valid = false + }; + if PSTATE.EL == EL0 then { + cache.is_asid_valid = true; + cache.asid = ASID_read() + } else { + cache.is_asid_valid = false + }; + let vaddress : bits(64) = regval; + let need_translate : bool = ICInstNeedsTranslation(opscope); + cache.vaddress = regval; + cache.shareability = Shareability_NSH; + cache.translated = need_translate; + if not_bool(need_translate) then { + cache.paddress = __UNKNOWN_FullAddress(); + CACHE_OP(cache); + return() + }; + let accdesc : AccessDescriptor = CreateAccDescIC(cache); + let aligned : bool = true; + let 'size = 0; + let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(vaddress, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch64_Abort(regval, memaddrdesc.fault) + }; + cache.cpas = CPASAtPAS(memaddrdesc.paddress.paspace); + cache.paddress = memaddrdesc.paddress; + CACHE_OP(cache) + }; + return() +} + +val AArch64_RestrictPrediction : (bits(64), RestrictType) -> unit + +function AArch64_RestrictPrediction (val_name, restriction) = { + c : ExecutionCntxt = undefined; + let target_el : bits(2) = val_name[25 .. 24]; + if not_bool(HaveEL(target_el)) | UInt(target_el) > UInt(PSTATE.EL) then { + EndOfInstruction() + }; + let ns : bits(1) = [val_name[26]]; + let nse : bits(1) = [val_name[27]]; + let ss : SecurityState = TargetSecurityState(ns, nse); + if ss == SS_Root & target_el != EL3 then { + EndOfInstruction() + }; + if (not_bool(HaveRME()) & target_el == EL3) & ss != SS_Secure then { + EndOfInstruction() + }; + c.security = ss; + c.target_el = target_el; + if EL2Enabled() then { + if PSTATE.EL == EL0 & not_bool(IsInHost()) | PSTATE.EL == EL1 then { + c.is_vmid_valid = true; + c.all_vmid = false; + c.vmid = VMID_read() + } else if target_el == EL0 & not_bool(ELIsInHost(target_el)) | target_el == EL1 then { + c.is_vmid_valid = true; + c.all_vmid = [val_name[48]] == 0b1; + c.vmid = val_name[47 .. 32] + } else { + c.is_vmid_valid = false + } + } else { + c.is_vmid_valid = false + }; + if PSTATE.EL == EL0 then { + c.is_asid_valid = true; + c.all_asid = false; + c.asid = ASID_read() + } else if target_el == EL0 then { + c.is_asid_valid = true; + c.all_asid = [val_name[16]] == 0b1; + c.asid = val_name[15 .. 0] + } else { + c.is_asid_valid = false + }; + c.restriction = restriction; + RESTRICT_PREDICTIONS(c) +} + +val AArch32_EL2Enabled : SecurityState -> bool + +function AArch32_EL2Enabled ss = { + if ss == SS_Secure then { + if not_bool(HaveEL(EL2) & HaveSecureEL2Ext()) then { + return(false) + } else if HaveEL(EL3) then { + return(SCR_EL3[EEL2] == 0b1) + } else { + return(__IMPDEF_boolean("Secure-only implementation")) + } + } else { + return(HaveEL(EL2)) + } +} + +val AArch32_S1IASize : bits(3) -> int + +function AArch32_S1IASize txsz = { + return(32 - UInt(txsz)) +} + +val AArch32_GetVARange : (bits(32), bits(3), bits(3)) -> VARange + +function AArch32_GetVARange (va, t0sz, t1sz) = { + let 'lo_iasize = AArch32_S1IASize(t0sz); + let 'up_iasize = AArch32_S1IASize(t1sz); + if t1sz == 0b000 & t0sz == 0b000 then { + return(VARange_LOWER) + } else if t1sz == 0b000 then { + return(if is_zero_subrange(va, 31, lo_iasize) then VARange_LOWER else + VARange_UPPER) + } else if t0sz == 0b000 then { + return(if is_ones_subrange(va, 31, up_iasize) then VARange_UPPER else + VARange_LOWER) + } else if is_zero_subrange(va, 31, lo_iasize) then { + return(VARange_LOWER) + } else if is_ones_subrange(va, 31, up_iasize) then { + return(VARange_UPPER) + } else { + return(__UNKNOWN_VARange()) + } +} + +bitfield MAIR0_Type : bits(32) = + {Attr3 : 31..24, Attr2 : 23..16, Attr1 : 15..8, Attr0 : 7..0} + +bitfield PRRR_Type : bits(32) = + { + NOS7 : 31..31, + NOS6 : 30..30, + NOS5 : 29..29, + NOS4 : 28..28, + NOS3 : 27..27, + NOS2 : 26..26, + NOS1 : 25..25, + NOS0 : 24..24, + NS1 : 19..19, + NS0 : 18..18, + DS1 : 17..17, + DS0 : 16..16, + TR7 : 15..14, + TR6 : 13..12, + TR5 : 11..10, + TR4 : 9..8, + TR3 : 7..6, + TR2 : 5..4, + TR1 : 3..2, + TR0 : 1..0 + } + +register _PRRR_NS : PRRR_Type + +val PRRR_NS_read : unit -> PRRR_Type + +function PRRR_NS_read () = { + r : PRRR_Type = _PRRR_NS; + r.bits[31 .. 0] = Slice(MAIR_EL1.bits, 0, 32); + return(r) +} + +register PRRR_S : PRRR_Type + +val PRRR_read : unit -> PRRR_Type + +function PRRR_read () = { + r : PRRR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = PRRR_S + } else { + r = PRRR_NS_read() + }; + return(r) +} + +register _MAIR0_NS : MAIR0_Type + +val MAIR0_NS_read : unit -> MAIR0_Type + +function MAIR0_NS_read () = { + r : MAIR0_Type = _MAIR0_NS; + if ELUsingAArch32(EL3) then { + r.bits[31 .. 0] = Slice(PRRR_NS_read().bits, 0, 32) + } else { + if not_bool(HaveEL(EL3)) | not_bool(ELUsingAArch32(EL3)) then { + r.bits[31 .. 0] = Slice(MAIR_EL1.bits, 0, 32) + } else { + r.bits[31 .. 0] = Slice(PRRR_read().bits, 0, 32) + } + }; + return(r) +} + +register _MAIR0_S : MAIR0_Type + +val MAIR0_S_read : unit -> MAIR0_Type + +function MAIR0_S_read () = { + r : MAIR0_Type = _MAIR0_S; + r.bits[31 .. 0] = Slice(PRRR_S.bits, 0, 32); + return(r) +} + +val MAIR0_read : unit -> MAIR0_Type + +function MAIR0_read () = { + r : MAIR0_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = MAIR0_S_read() + } else { + r = MAIR0_NS_read() + }; + return(r) +} + +bitfield MAIR1_Type : bits(32) = + {Attr7 : 31..24, Attr6 : 23..16, Attr5 : 15..8, Attr4 : 7..0} + +bitfield NMRR_Type : bits(32) = + { + OR7 : 31..30, + OR6 : 29..28, + OR5 : 27..26, + OR4 : 25..24, + OR3 : 23..22, + OR2 : 21..20, + OR1 : 19..18, + OR0 : 17..16, + IR7 : 15..14, + IR6 : 13..12, + IR5 : 11..10, + IR4 : 9..8, + IR3 : 7..6, + IR2 : 5..4, + IR1 : 3..2, + IR0 : 1..0 + } + +register _NMRR_NS : NMRR_Type + +val NMRR_NS_read : unit -> NMRR_Type + +function NMRR_NS_read () = { + r : NMRR_Type = _NMRR_NS; + r.bits[31 .. 0] = Slice(MAIR_EL1.bits, 32, 32); + return(r) +} + +register NMRR_S : NMRR_Type + +val NMRR_read : unit -> NMRR_Type + +function NMRR_read () = { + r : NMRR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = NMRR_S + } else { + r = NMRR_NS_read() + }; + return(r) +} + +register _MAIR1_NS : MAIR1_Type + +val MAIR1_NS_read : unit -> MAIR1_Type + +function MAIR1_NS_read () = { + r : MAIR1_Type = _MAIR1_NS; + if ELUsingAArch32(EL3) then { + r.bits[31 .. 0] = Slice(NMRR_NS_read().bits, 0, 32) + } else { + if not_bool(HaveEL(EL3)) | not_bool(ELUsingAArch32(EL3)) then { + r.bits[31 .. 0] = Slice(MAIR_EL1.bits, 32, 32) + } else { + r.bits[31 .. 0] = Slice(NMRR_read().bits, 0, 32) + } + }; + return(r) +} + +register _MAIR1_S : MAIR1_Type + +val MAIR1_S_read : unit -> MAIR1_Type + +function MAIR1_S_read () = { + r : MAIR1_Type = _MAIR1_S; + r.bits[31 .. 0] = Slice(NMRR_S.bits, 0, 32); + return(r) +} + +val MAIR1_read : unit -> MAIR1_Type + +function MAIR1_read () = { + r : MAIR1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = MAIR1_S_read() + } else { + r = MAIR1_NS_read() + }; + return(r) +} + +bitfield TTBCR2_Type : bits(32) = + { + HWU162 : 18..18, + HWU161 : 17..17, + HWU160 : 16..16, + HWU159 : 15..15, + HWU062 : 14..14, + HWU061 : 13..13, + HWU060 : 12..12, + HWU059 : 11..11, + HPD1 : 10..10, + HPD0 : 9..9 + } + +register _TTBCR2_NS : TTBCR2_Type + +val TTBCR2_NS_read : unit -> TTBCR2_Type + +function TTBCR2_NS_read () = { + r : TTBCR2_Type = _TTBCR2_NS; + r.bits[31 .. 0] = Slice(TCR_EL1.bits, 32, 32); + return(r) +} + +register TTBCR2_S : TTBCR2_Type + +val TTBCR2_read : unit -> TTBCR2_Type + +function TTBCR2_read () = { + r : TTBCR2_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = TTBCR2_S + } else { + r = TTBCR2_NS_read() + }; + return(r) +} + +val AArch32_S1TTWParamsEL10 : bits(32) -> S1TTWParams + +function AArch32_S1TTWParamsEL10 va = { + mair : bits(64) = undefined; + sif : bits(1) = undefined; + ttbcr : TTBCR_Type = undefined; + ttbcr2 : TTBCR2_Type = undefined; + sctlr : SCTLR_Type = undefined; + if ELUsingAArch32(EL3) then { + ttbcr = TTBCR_NS_read(); + ttbcr2 = TTBCR2_NS_read(); + sctlr = SCTLR_NS_read(); + mair = MAIR1_NS_read().bits @ MAIR0_NS_read().bits; + sif = SCR[SIF] + } else { + ttbcr = TTBCR_read(); + ttbcr2 = TTBCR2_read(); + sctlr = SCTLR_read__2(); + mair = MAIR1_read().bits @ MAIR0_read().bits; + sif = if HaveEL(EL3) then SCR_EL3[SIF] else 0b0 + }; + assert(ttbcr[EAE] == 0b1); + walkparams : S1TTWParams = undefined; + walkparams.t0sz = ttbcr[T0SZ]; + walkparams.t1sz = ttbcr[T1SZ]; + walkparams.ee = sctlr[EE]; + walkparams.wxn = sctlr[WXN]; + walkparams.uwxn = sctlr[UWXN]; + walkparams.ntlsmd = if HaveTrapLoadStoreMultipleDeviceExt() then + sctlr[nTLSMD] + else + 0b1; + walkparams.mair = Mk_MAIRType(mair); + walkparams.sif = sif; + let varange : VARange = AArch32_GetVARange(va, walkparams.t0sz, walkparams.t1sz); + if varange == VARange_LOWER then { + walkparams.sh = ttbcr[SH0]; + walkparams.irgn = ttbcr[IRGN0]; + walkparams.orgn = ttbcr[ORGN0]; + walkparams.hpd = if AArch32_HaveHPDExt() then ttbcr[T2E] & ttbcr2[HPD0] + else + 0b0 + } else { + walkparams.sh = ttbcr[SH1]; + walkparams.irgn = ttbcr[IRGN1]; + walkparams.orgn = ttbcr[ORGN1]; + walkparams.hpd = if AArch32_HaveHPDExt() then ttbcr[T2E] & ttbcr2[HPD1] + else + 0b0 + }; + return(walkparams) +} + +bitfield HMAIR0_Type : bits(32) = + {Attr3 : 31..24, Attr2 : 23..16, Attr1 : 15..8, Attr0 : 7..0} + +register _HMAIR0 : HMAIR0_Type + +val HMAIR0_read : unit -> HMAIR0_Type + +function HMAIR0_read () = { + r : HMAIR0_Type = _HMAIR0; + r.bits[31 .. 0] = Slice(MAIR_EL2.bits, 0, 32); + return(r) +} + +bitfield HMAIR1_Type : bits(32) = + {Attr7 : 31..24, Attr6 : 23..16, Attr5 : 15..8, Attr4 : 7..0} + +register _HMAIR1 : HMAIR1_Type + +val HMAIR1_read : unit -> HMAIR1_Type + +function HMAIR1_read () = { + r : HMAIR1_Type = _HMAIR1; + r.bits[31 .. 0] = Slice(MAIR_EL2.bits, 32, 32); + return(r) +} + +bitfield HTCR_Type : bits(32) = + { + HWU62 : 28..28, + HWU61 : 27..27, + HWU60 : 26..26, + HWU59 : 25..25, + HPD : 24..24, + SH0 : 13..12, + ORGN0 : 11..10, + IRGN0 : 9..8, + T0SZ : 2..0 + } + +register _HTCR : HTCR_Type + +val HTCR_read : unit -> HTCR_Type + +function HTCR_read () = { + r : HTCR_Type = _HTCR; + r.bits[31 .. 0] = Slice(TCR_EL2.bits, 0, 32); + return(r) +} + +val AArch32_S1TTWParamsEL2 : unit -> S1TTWParams + +function AArch32_S1TTWParamsEL2 () = { + walkparams : S1TTWParams = undefined; + walkparams.tgx = TGx_4KB; + walkparams.t0sz = HTCR_read()[T0SZ]; + walkparams.irgn = HTCR_read()[SH0]; + walkparams.orgn = HTCR_read()[IRGN0]; + walkparams.sh = HTCR_read()[ORGN0]; + walkparams.hpd = if AArch32_HaveHPDExt() then HTCR_read()[HPD] else 0b0; + walkparams.ee = HSCTLR_read()[EE]; + walkparams.wxn = HSCTLR_read()[WXN]; + if HaveTrapLoadStoreMultipleDeviceExt() then { + walkparams.ntlsmd = HSCTLR_read()[nTLSMD] + } else { + walkparams.ntlsmd = 0b1 + }; + walkparams.mair = Mk_MAIRType(HMAIR1_read().bits @ HMAIR0_read().bits); + return(walkparams) +} + +val AArch32_S1TTWParamsEL30 : bits(32) -> S1TTWParams + +function AArch32_S1TTWParamsEL30 va = { + assert(TTBCR_S[EAE] == 0b1); + walkparams : S1TTWParams = undefined; + walkparams.t0sz = TTBCR_S[T0SZ]; + walkparams.t1sz = TTBCR_S[T1SZ]; + walkparams.ee = SCTLR_S[EE]; + walkparams.wxn = SCTLR_S[WXN]; + walkparams.uwxn = SCTLR_S[UWXN]; + walkparams.ntlsmd = if HaveTrapLoadStoreMultipleDeviceExt() then + SCTLR_S[nTLSMD] + else + 0b1; + walkparams.mair = Mk_MAIRType(MAIR1_S_read().bits @ MAIR0_S_read().bits); + walkparams.sif = SCR[SIF]; + let varange : VARange = AArch32_GetVARange(va, walkparams.t0sz, walkparams.t1sz); + if varange == VARange_LOWER then { + walkparams.sh = TTBCR_S[SH0]; + walkparams.irgn = TTBCR_S[IRGN0]; + walkparams.orgn = TTBCR_S[ORGN0]; + walkparams.hpd = if AArch32_HaveHPDExt() then + TTBCR_S[T2E] & TTBCR2_S[HPD0] + else + 0b0 + } else { + walkparams.sh = TTBCR_S[SH1]; + walkparams.irgn = TTBCR_S[IRGN1]; + walkparams.orgn = TTBCR_S[ORGN1]; + walkparams.hpd = if AArch32_HaveHPDExt() then + TTBCR_S[T2E] & TTBCR2_S[HPD1] + else + 0b0 + }; + return(walkparams) +} + +val AArch32_GetS1TTWParams : (Regime, bits(32)) -> S1TTWParams + +function AArch32_GetS1TTWParams (regime, va) = { + walkparams : S1TTWParams = undefined; + match regime { + Regime_EL2 => { + walkparams = AArch32_S1TTWParamsEL2() + }, + Regime_EL10 => { + walkparams = AArch32_S1TTWParamsEL10(va) + }, + Regime_EL30 => { + walkparams = AArch32_S1TTWParamsEL30(va) + }, + _ => () + }; + return(walkparams) +} + +val AArch32_S1DCacheEnabled : Regime -> bool + +function AArch32_S1DCacheEnabled regime = { + match regime { + Regime_EL30 => { + return(SCTLR_S[C] == 0b1) + }, + Regime_EL2 => { + return(HSCTLR_read()[C] == 0b1) + }, + Regime_EL10 => { + return((if HaveAArch32EL(EL3) then SCTLR_NS_read()[C] else + SCTLR_read__2()[C]) == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch32_S1HasAlignmentFault : forall ('aligned : Bool). + (AccessDescriptor, bool('aligned), bits(1), MemoryAttributes) -> bool + +function AArch32_S1HasAlignmentFault (accdesc, aligned, ntlsmd, memattrs) = { + if accdesc.acctype == AccessType_IFETCH then { + return(false) + } else if accdesc.a32lsmd & ntlsmd == 0b0 then { + return(memattrs.memtype == MemType_Device & memattrs.device != DeviceType_GRE) + } else if accdesc.acctype == AccessType_DCZero then { + return(memattrs.memtype == MemType_Device) + } else { + return(memattrs.memtype == MemType_Device & not_bool(aligned)) + } +} + +val AArch32_S1ICacheEnabled : Regime -> bool + +function AArch32_S1ICacheEnabled regime = { + match regime { + Regime_EL30 => { + return(SCTLR_S[I] == 0b1) + }, + Regime_EL2 => { + return(HSCTLR_read()[I] == 0b1) + }, + Regime_EL10 => { + return((if HaveAArch32EL(EL3) then SCTLR_NS_read()[I] else + SCTLR_read__2()[I]) == 0b1) + }, + _ => { + return(undefined : bool) + } + } +} + +val AArch32_S1DisabledOutput : forall ('aligned : Bool). + (FaultRecord, Regime, bits(32), bool('aligned), AccessDescriptor) -> (FaultRecord, AddressDescriptor) + +function AArch32_S1DisabledOutput (fault_in, regime, va, aligned, accdesc) = { + fault : FaultRecord = fault_in; + SetInGuardedPage(false); + memattrs : MemoryAttributes = undefined; + default_cacheable : bits(1) = undefined; + if regime == Regime_EL10 & AArch32_EL2Enabled(accdesc.ss) then { + if ELStateUsingAArch32(EL2, accdesc.ss == SS_Secure) then { + default_cacheable = HCR_read()[DC] + } else { + default_cacheable = HCR_EL2[DC] + } + } else { + default_cacheable = 0b0 + }; + if default_cacheable == 0b1 then { + memattrs.memtype = MemType_Normal; + memattrs.inner.attrs = MemAttr_WB; + memattrs.inner.hints = MemHint_RWA; + memattrs.outer.attrs = MemAttr_WB; + memattrs.outer.hints = MemHint_RWA; + memattrs.shareability = Shareability_NSH; + if (not_bool(ELStateUsingAArch32(EL2, accdesc.ss == SS_Secure)) & HaveMTE2Ext()) & HCR_EL2[DCT] == 0b1 then { + memattrs.tags = MemTag_AllocationTagged + } else { + memattrs.tags = MemTag_Untagged + }; + memattrs.xs = 0b0 + } else if accdesc.acctype == AccessType_IFETCH then { + memattrs.memtype = MemType_Normal; + memattrs.shareability = Shareability_OSH; + memattrs.tags = MemTag_Untagged; + if AArch32_S1ICacheEnabled(regime) then { + memattrs.inner.attrs = MemAttr_WT; + memattrs.inner.hints = MemHint_RA; + memattrs.outer.attrs = MemAttr_WT; + memattrs.outer.hints = MemHint_RA + } else { + memattrs.inner.attrs = MemAttr_NC; + memattrs.outer.attrs = MemAttr_NC + }; + memattrs.xs = 0b1 + } else { + memattrs.memtype = MemType_Device; + memattrs.device = DeviceType_nGnRnE; + memattrs.shareability = Shareability_OSH; + memattrs.tags = MemTag_Untagged; + memattrs.xs = 0b1 + }; + ntlsmd : bits(1) = undefined; + if HaveTrapLoadStoreMultipleDeviceExt() then { + match regime { + Regime_EL30 => { + ntlsmd = SCTLR_S[nTLSMD] + }, + Regime_EL2 => { + ntlsmd = HSCTLR_read()[nTLSMD] + }, + Regime_EL10 => { + ntlsmd = if HaveAArch32EL(EL3) then SCTLR_NS_read()[nTLSMD] else + SCTLR_read__2()[nTLSMD] + }, + _ => () + } + } else { + ntlsmd = 0b1 + }; + if AArch32_S1HasAlignmentFault(accdesc, aligned, ntlsmd, memattrs) then { + fault.statuscode = Fault_Alignment; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + oa : FullAddress = undefined; + oa.address = ZeroExtend(va, 56); + oa.paspace = if accdesc.ss == SS_Secure then PAS_Secure else PAS_NonSecure; + let ipa : AddressDescriptor = CreateAddressDescriptor(ZeroExtend(va, 64), oa, memattrs); + return((fault, ipa)) +} + +val AArch32_S1Enabled : (Regime, SecurityState) -> bool + +function AArch32_S1Enabled (regime, ss) = { + if regime == Regime_EL2 then { + return(HSCTLR_read()[M] == 0b1) + } else if regime == Regime_EL30 then { + return(SCTLR_S[M] == 0b1) + } else if not_bool(AArch32_EL2Enabled(ss)) then { + return((if HaveAArch32EL(EL3) then SCTLR_NS_read()[M] else + SCTLR_read__2()[M]) == 0b1) + } else if ELStateUsingAArch32(EL2, ss == SS_Secure) then { + return((HCR_read()[TGE] @ HCR_read()[DC]) == 0b00 & (if HaveAArch32EL(EL3) then + SCTLR_NS_read()[M] + else + SCTLR_read__2()[M]) == 0b1) + } else { + return((HCR_EL2[TGE] @ HCR_EL2[DC]) == 0b00 & SCTLR_read__2()[M] == 0b1) + } +} + +val AArch32_S1LDHasPermissionsFault : (Regime, S1TTWParams, Permissions, MemType, PASpace, AccessDescriptor) -> bool + +function AArch32_S1LDHasPermissionsFault (regime, walkparams, perms, memtype, paspace, accdesc) = { + constraint_name : Constraint = undefined; + pan : bits(1) = undefined; + px : bits(1) = undefined; + pxn : bits(1) = undefined; + ux : bits(1) = undefined; + r : bits(1) = undefined; + w : bits(1) = undefined; + x : bits(1) = undefined; + pr : bits(1) = undefined; + pw : bits(1) = undefined; + ur : bits(1) = undefined; + uw : bits(1) = undefined; + xn : bits(1) = undefined; + if HasUnprivileged(regime) then { + match perms.ap[2 .. 1] { + 0b00 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b0, 0b0) + }, + 0b01 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b1, 0b1) + }, + 0b10 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b0, 0b0) + }, + 0b11 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b1, 0b0) + } + }; + match perms.ap_table { + 0b00 => { + (pr, pw, ur, uw) = (pr, pw, ur, uw) + }, + 0b01 => { + (pr, pw, ur, uw) = (pr, pw, 0b0, 0b0) + }, + 0b10 => { + (pr, pw, ur, uw) = (pr, 0b0, ur, 0b0) + }, + 0b11 => { + (pr, pw, ur, uw) = (pr, 0b0, 0b0, 0b0) + } + }; + let xn : bits(1) = perms.xn | perms.xn_table; + let pxn : bits(1) = perms.pxn | perms.pxn_table; + let ux : bits(1) = ur & not_vec(xn | uw & walkparams.wxn); + let px : bits(1) = pr & not_vec(((xn | pxn) | pw & walkparams.wxn) | uw & walkparams.uwxn); + if HavePANExt() & accdesc.pan then { + let pan : bits(1) = PSTATE.PAN & (ur | uw); + pr = pr & not_vec(pan); + pw = pw & not_vec(pan) + }; + (r, w, x) = if accdesc.el == EL0 then (ur, uw, ux) else (pr, pw, px); + if accdesc.ss == SS_Secure & paspace == PAS_NonSecure then { + x = x & not_vec(walkparams.sif) + }; + () + } else { + match [perms.ap[2]] { + 0b0 => { + (r, w) = (0b1, 0b1) + }, + 0b1 => { + (r, w) = (0b1, 0b0) + } + }; + match [perms.ap_table[1]] { + 0b0 => { + (r, w) = (r, w) + }, + 0b1 => { + (r, w) = (r, 0b0) + } + }; + let xn : bits(1) = perms.xn | perms.xn_table; + x = not_vec(xn | w & walkparams.wxn) + }; + if accdesc.acctype == AccessType_IFETCH then { + let constraint_name : Constraint = ConstrainUnpredictable(Unpredictable_INSTRDEVICE); + if constraint_name == Constraint_FAULT & memtype == MemType_Device then { + return(true) + } else { + return(x == 0b0) + } + } else if accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC then { + return(false) + } else if accdesc.write then { + return(w == 0b0) + } else { + return(r == 0b0) + } +} + +val AArch32_DecodeDescriptorTypeLD : forall 'level. + (bits(64), int('level)) -> DescriptorType + +function AArch32_DecodeDescriptorTypeLD (descriptor, level) = { + if descriptor[1 .. 0] == 0b11 & level == FINAL_LEVEL then { + return(DescriptorType_Leaf) + } else if descriptor[1 .. 0] == 0b11 then { + return(DescriptorType_Table) + } else if descriptor[1 .. 0] == 0b01 & level != FINAL_LEVEL then { + return(DescriptorType_Leaf) + } else { + return(DescriptorType_Invalid) + } +} + +val AArch32_TLBContextEL10 : (SecurityState, bits(32)) -> TLBContext + +function AArch32_TLBContextEL10 (ss, va) = { + tlbcontext : TLBContext = undefined; + ttbcr : TTBCR_Type = undefined; + ttbr0 : TTBR0_Type = undefined; + ttbr1 : TTBR1_Type = undefined; + contextidr : CONTEXTIDR_Type = undefined; + if HaveAArch32EL(EL3) then { + ttbcr = TTBCR_NS_read(); + ttbr0 = TTBR0_NS; + ttbr1 = TTBR1_NS; + contextidr = CONTEXTIDR_NS_read() + } else { + ttbcr = TTBCR_read(); + ttbr0 = TTBR0_read(); + ttbr1 = TTBR1_read(); + contextidr = CONTEXTIDR_read() + }; + tlbcontext.ss = ss; + tlbcontext.regime = Regime_EL10; + if AArch32_EL2Enabled(ss) then { + tlbcontext.vmid = ZeroExtend(VTTBR[VMID], 16) + }; + if ttbcr[EAE] == 0b1 then { + tlbcontext.asid = ZeroExtend(if ttbcr[A1] == 0b0 then ttbr0[ASID] else + ttbr1[ASID], 16) + } else { + tlbcontext.asid = ZeroExtend(contextidr[ASID], 16) + }; + tlbcontext.tg = TGx_4KB; + tlbcontext.ia = ZeroExtend(va, 64); + if HaveCommonNotPrivateTransExt() & ttbcr[EAE] == 0b1 then { + if AArch32_GetVARange(va, ttbcr[T0SZ], ttbcr[T1SZ]) == VARange_LOWER then { + tlbcontext.cnp = ttbr0[CnP] + } else { + tlbcontext.cnp = ttbr1[CnP] + } + } else { + tlbcontext.cnp = 0b0 + }; + return(tlbcontext) +} + +val AArch32_TLBContextEL2 : bits(32) -> TLBContext + +function AArch32_TLBContextEL2 va = { + tlbcontext : TLBContext = undefined; + tlbcontext.ss = SS_NonSecure; + tlbcontext.regime = Regime_EL2; + tlbcontext.ia = ZeroExtend(va, 64); + tlbcontext.tg = TGx_4KB; + tlbcontext.cnp = if HaveCommonNotPrivateTransExt() then HTTBR[CnP] else 0b0; + return(tlbcontext) +} + +val AArch32_TLBContextEL30 : bits(32) -> TLBContext + +function AArch32_TLBContextEL30 va = { + tlbcontext : TLBContext = undefined; + tlbcontext.ss = SS_Secure; + tlbcontext.regime = Regime_EL30; + if TTBCR_S[EAE] == 0b1 then { + tlbcontext.asid = ZeroExtend(if TTBCR_S[A1] == 0b0 then TTBR0_S[ASID] + else + TTBR1_S[ASID], 16) + } else { + tlbcontext.asid = ZeroExtend(CONTEXTIDR_S[ASID], 16) + }; + tlbcontext.tg = TGx_4KB; + tlbcontext.ia = ZeroExtend(va, 64); + if HaveCommonNotPrivateTransExt() & TTBCR_S[EAE] == 0b1 then { + if AArch32_GetVARange(va, TTBCR_S[T0SZ], TTBCR_S[T1SZ]) == VARange_LOWER then { + tlbcontext.cnp = TTBR0_S[CnP] + } else { + tlbcontext.cnp = TTBR1_S[CnP] + } + } else { + tlbcontext.cnp = 0b0 + }; + return(tlbcontext) +} + +val AArch32_GetS1TLBContext : (Regime, SecurityState, bits(32)) -> TLBContext + +function AArch32_GetS1TLBContext (regime, ss, va) = { + tlbcontext : TLBContext = undefined; + match regime { + Regime_EL2 => { + tlbcontext = AArch32_TLBContextEL2(va) + }, + Regime_EL10 => { + tlbcontext = AArch32_TLBContextEL10(ss, va) + }, + Regime_EL30 => { + tlbcontext = AArch32_TLBContextEL30(va) + }, + _ => () + }; + tlbcontext.includes_s1_name = true; + tlbcontext.includes_s2_name = false; + return(tlbcontext) +} + +val AArch32_GetTranslationStartInfo : (Regime, SecurityState, AccessDescriptor, bits(32), int) -> TranslationStartInfo + +function AArch32_GetTranslationStartInfo (regime, ss, accdesc, va, size) = { + let tlbcontext : TLBContext = AArch32_GetS1TLBContext(regime, ss, va); + let tsi : TranslationStartInfo = struct { + ss = ss, + regime = regime, + vmid = tlbcontext.vmid, + asid = tlbcontext.asid, + va = ZeroExtend(va, 64), + cnp = tlbcontext.cnp, + accdesc = accdesc, + size = size + }; + return(tsi) +} + +val AArch32_MAIRAttr : forall 'index. (int('index), MAIRType) -> bits(8) + +function AArch32_MAIRAttr (index, mair) = { + assert(index < 8); + let 'bit_index = 8 * index; + assert(constraint((0 <= 'bit_index | not('index < 8)))); + return(mair.bits[bit_index + 7 .. bit_index]) +} + +bitfield VTCR_Type : bits(32) = + { + HWU62 : 28..28, + HWU61 : 27..27, + HWU60 : 26..26, + HWU59 : 25..25, + SH0 : 13..12, + ORGN0 : 11..10, + IRGN0 : 9..8, + SL0 : 7..6, + S : 4..4, + T0SZ : 3..0 + } + +register _VTCR : VTCR_Type + +val VTCR_read : unit -> VTCR_Type + +function VTCR_read () = { + r : VTCR_Type = _VTCR; + r.bits[31 .. 0] = Slice(VTCR_EL2.bits, 0, 32); + return(r) +} + +val AArch32_GetS2TTWParams : unit -> S2TTWParams + +function AArch32_GetS2TTWParams () = { + walkparams : S2TTWParams = undefined; + walkparams.tgx = TGx_4KB; + walkparams.s = VTCR_read()[S]; + walkparams.t0sz = VTCR_read()[T0SZ]; + walkparams.sl0 = VTCR_read()[SL0]; + walkparams.irgn = VTCR_read()[IRGN0]; + walkparams.orgn = VTCR_read()[ORGN0]; + walkparams.sh = VTCR_read()[SH0]; + walkparams.ee = HSCTLR_read()[EE]; + walkparams.ptw = HCR_read()[PTW]; + walkparams.vm = HCR_read()[VM] | HCR_read()[DC]; + if walkparams.s != [walkparams.t0sz[3]] then { + let (_, __tup_1 : bitvector(4)) = ConstrainUnpredictableBits(Unpredictable_RESVTCRS, 4); + walkparams.t0sz = __tup_1 + }; + return(walkparams) +} + +val AArch32_S2IASize : bits(4) -> int + +function AArch32_S2IASize t0sz = { + return(32 - SInt(t0sz)) +} + +val AArch32_IPAIsOutOfRange : (S2TTWParams, bits(40)) -> bool + +function AArch32_IPAIsOutOfRange (walkparams, ipa) = { + let 'iasize = AArch32_S2IASize(walkparams.t0sz); + return(iasize < 40 & not_bool(is_zero_subrange(ipa, 39, iasize))) +} + +val AArch32_S2HasAlignmentFault : forall ('aligned : Bool). + (AccessDescriptor, bool('aligned), MemoryAttributes) -> bool + +function AArch32_S2HasAlignmentFault (accdesc, aligned, memattrs) = { + if accdesc.acctype == AccessType_IFETCH then { + return(false) + } else if accdesc.acctype == AccessType_DCZero then { + return(memattrs.memtype == MemType_Device) + } else { + return(memattrs.memtype == MemType_Device & not_bool(aligned)) + } +} + +val AArch32_S2HasPermissionsFault : (S2TTWParams, Permissions, MemType, AccessDescriptor) -> bool + +function AArch32_S2HasPermissionsFault (walkparams, perms, memtype, accdesc) = { + constraint_name : Constraint = undefined; + px : bits(1) = undefined; + ux : bits(1) = undefined; + let r : bits(1) = [perms.s2ap[0]]; + let w : bits(1) = [perms.s2ap[1]]; + x : bits(1) = undefined; + if HaveExtendedExecuteNeverExt() then { + match perms.s2xn @ perms.s2xnx { + 0b00 => { + (px, ux) = (r, r) + }, + 0b01 => { + (px, ux) = (0b0, r) + }, + 0b10 => { + (px, ux) = (0b0, 0b0) + }, + 0b11 => { + (px, ux) = (r, 0b0) + } + }; + x = if accdesc.el == EL0 then ux else px + } else { + x = r & not_vec(perms.s2xn) + }; + if accdesc.acctype == AccessType_TTW then { + return(walkparams.ptw == 0b1 & memtype == MemType_Device | r == 0b0) + } else if accdesc.acctype == AccessType_IFETCH then { + let constraint_name : Constraint = ConstrainUnpredictable(Unpredictable_INSTRDEVICE); + return(constraint_name == Constraint_FAULT & memtype == MemType_Device | x == 0b0) + } else if accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC then { + return(false) + } else if accdesc.write then { + return(w == 0b0) + } else { + return(r == 0b0) + } +} + +val AArch32_GetS2TLBContext : FullAddress -> TLBContext + +function AArch32_GetS2TLBContext ipa = { + assert(ipa.paspace == PAS_NonSecure); + tlbcontext : TLBContext = undefined; + tlbcontext.ss = SS_NonSecure; + tlbcontext.regime = Regime_EL10; + tlbcontext.ipaspace = ipa.paspace; + tlbcontext.vmid = ZeroExtend(VTTBR[VMID], 16); + tlbcontext.tg = TGx_4KB; + tlbcontext.includes_s1_name = false; + tlbcontext.includes_s2_name = true; + tlbcontext.ia = ZeroExtend(ipa.address, 64); + tlbcontext.cnp = if HaveCommonNotPrivateTransExt() then VTTBR[CnP] else 0b0; + return(tlbcontext) +} + +val AArch32_S2StartLevel : bits(2) -> int + +function AArch32_S2StartLevel sl0 = { + return(2 - UInt(sl0)) +} + +val AArch32_S2InconsistentSL : S2TTWParams -> bool + +function AArch32_S2InconsistentSL walkparams = { + let 'startlevel = AArch32_S2StartLevel(walkparams.sl0); + let 'levels = FINAL_LEVEL - startlevel; + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'stride = granulebits - 3; + let 'sl_min_iasize = levels * stride + granulebits + 1; + let 'sl_max_iasize = sl_min_iasize + (stride - 1) + 4; + let 'iasize = AArch32_S2IASize(walkparams.t0sz); + return(iasize < sl_min_iasize | iasize > sl_max_iasize) +} + +val AArch32_S2Walk : (FaultRecord, S2TTWParams, option(int), AccessDescriptor, AddressDescriptor) -> (FaultRecord, TTWState) + +function AArch32_S2Walk (fault_in, walkparams, s1level, accdesc, ipa) = { + finalwalkstate : TTWState = undefined; + fault : FaultRecord = fault_in; + tlbcontext : TLBContext = undefined; + if __tlb_enabled then { + tlbcontext = AArch32_GetS2TLBContext(ipa.paddress); + let tlbentry : TLBLine = S2TLBLookup(tlbcontext); + if tlbentry.valid_name then { + let finalwalkstate : TTWState = tlbentry.tlbrecord.walkstate; + fault.level = finalwalkstate.level; + return((fault, finalwalkstate)) + }; + () + }; + if (match walkparams.sl0 { + [bitone, _] => true, + _ => false + }) : bool | AArch32_S2InconsistentSL(walkparams) then { + fault.statuscode = Fault_Translation; + fault.level = 1; + return((fault, __UNKNOWN_TTWState())) + }; + let 'iasize = AArch32_S2IASize(walkparams.t0sz); + let 'startlevel = AArch32_S2StartLevel(walkparams.sl0); + let 'levels = FINAL_LEVEL - startlevel; + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'stride = granulebits - 3; + if not_bool(IsZero(VTTBR.bits[47 .. 40])) then { + fault.statuscode = Fault_AddressSize; + fault.level = 0; + return((fault, __UNKNOWN_TTWState())) + }; + baseaddress : FullAddress = undefined; + let 'baselsb = iasize - (levels * stride + granulebits) + 3; + baseaddress.paspace = PAS_NonSecure; + assert(constraint((0 <= 'baselsb & 'baselsb <= 39))); + baseaddress.address = ZeroExtend(VTTBR.bits[39 .. baselsb] @ Zeros(baselsb), 56); + walkstate : TTWState = undefined; + walkstate.baseaddress = baseaddress; + walkstate.level = startlevel; + walkstate.istable = true; + walkstate.memattrs = WalkMemAttrs(walkparams.sh, walkparams.irgn, walkparams.orgn); + indexmsb : int = iasize - 1; + descriptor : bits(64) = undefined; + let walkaccess : AccessDescriptor = CreateAccDescS2TTW(accdesc); + walkaddress : AddressDescriptor = undefined; + walkaddress.vaddress = ipa.vaddress; + if HCR2_read()[CD] == 0b1 then { + walkaddress.memattrs = NormalNCMemAttr(); + walkaddress.memattrs.xs = walkstate.memattrs.xs + } else { + walkaddress.memattrs = walkstate.memattrs + }; + walkaddress.memattrs.shareability = EffectiveShareability(walkaddress.memattrs); + indexlsb : int = undefined; + desctype : DescriptorType = undefined; + repeat { + fault.level = walkstate.level; + indexlsb = (FINAL_LEVEL - walkstate.level) * stride + granulebits; + let index : bits(40) = let 'indexmsb = indexmsb in + { + let 'indexlsb = indexlsb; + assert(constraint((0 <= 'indexlsb & 'indexlsb <= 'indexmsb & 'indexmsb < 56))); + assert(constraint(40 >= 'indexmsb - 'indexlsb + 1 + 3)); + ZeroExtend(ipa.paddress.address[indexmsb .. indexlsb] @ 0b000, 40) + }; + walkaddress.paddress.address = walkstate.baseaddress.address | ZeroExtend(index, 56); + walkaddress.paddress.paspace = walkstate.baseaddress.paspace; + let translation_info : TranslationInfo = struct { + regime = Regime_EL10, + vmid = None(), + asid = None(), + va = walkaddress.vaddress, + s1level = s1level, + s2info = Some((ZeroExtend(ipa.paddress.address, 64), walkstate.level)), + s1params = None(), + s2params = Some(walkparams), + memattrs = walkaddress.memattrs + }; + (fault, descriptor) = FetchDescriptor(walkparams.ee, walkaddress, walkaccess, fault, 64, translation_info); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_TTWState())) + }; + desctype = AArch32_DecodeDescriptorTypeLD(descriptor, walkstate.level); + match desctype { + DescriptorType_Table => { + if not_bool(IsZero(descriptor[47 .. 40])) then { + fault.statuscode = Fault_AddressSize; + return((fault, __UNKNOWN_TTWState())) + }; + walkstate.baseaddress.address = ZeroExtend(descriptor[39 .. 12] @ Zeros(12), 56); + walkstate.level = walkstate.level + 1; + indexmsb = indexlsb - 1 + }, + DescriptorType_Invalid => { + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_TTWState())) + }, + DescriptorType_Leaf => { + walkstate.istable = false + } + } + } until desctype == DescriptorType_Leaf; + let 'indexlsb = indexlsb; + if not_bool(IsZero(descriptor[47 .. 40])) then { + fault.statuscode = Fault_AddressSize; + return((fault, __UNKNOWN_TTWState())) + }; + if [descriptor[10]] == 0b0 then { + fault.statuscode = Fault_AccessFlag; + return((fault, __UNKNOWN_TTWState())) + }; + assert(constraint((0 <= 'indexlsb & 'indexlsb <= 39))); + walkstate.baseaddress.address = ZeroExtend(descriptor[39 .. indexlsb] @ Zeros(indexlsb), 56); + walkstate.permissions.s2ap = descriptor[7 .. 6]; + walkstate.permissions.s2xn = [descriptor[54]]; + if HaveExtendedExecuteNeverExt() then { + walkstate.permissions.s2xnx = [descriptor[53]] + } else { + walkstate.permissions.s2xnx = 0b0 + }; + let memattr : bits(4) = descriptor[5 .. 2]; + let sh : bits(2) = descriptor[9 .. 8]; + let s2aarch64 : bool = false; + walkstate.memattrs = S2DecodeMemAttrs(memattr, sh, s2aarch64); + walkstate.contiguous = [descriptor[52]]; + if __tlb_enabled then { + tlbcontext.xs = walkstate.memattrs.xs; + tlbcontext.level = walkstate.level; + tlbrecord : TLBRecord = undefined; + tlbrecord.context = tlbcontext; + tlbrecord.walkstate = walkstate; + tlbrecord.blocksize = TranslationSize(walkparams.d128, walkparams.tgx, walkstate.level); + if walkstate.contiguous == 0b1 then { + tlbrecord.contigsize = ContiguousSize(walkparams.d128, walkparams.tgx, walkstate.level) + } else { + tlbrecord.contigsize = 0 + }; + S2TLBCache(tlbrecord) + }; + return((fault, walkstate)) +} + +val AArch32_S2Translate : forall ('aligned : Bool). + (FaultRecord, AddressDescriptor, option(int), bool('aligned), AccessDescriptor) -> (FaultRecord, AddressDescriptor) + +function AArch32_S2Translate (fault_in, ipa, s1level, aligned, accdesc) = { + s1aarch64 : bool = undefined; + fault : FaultRecord = fault_in; + assert(IsZero(ipa.paddress.address[55 .. 40])); + if not_bool(ELStateUsingAArch32(EL2, accdesc.ss == SS_Secure)) then { + let s1aarch64 : bool = false; + return(AArch64_S2Translate(fault, ipa, s1aarch64, None(), aligned, accdesc)) + }; + fault.statuscode = Fault_None; + fault.secondstage = true; + fault.s2fs1walk = accdesc.acctype == AccessType_TTW; + fault.ipaddress = ipa.paddress; + let walkparams : S2TTWParams = AArch32_GetS2TTWParams(); + if walkparams.vm == 0b0 then { + return((fault, ipa)) + }; + if AArch32_IPAIsOutOfRange(walkparams, ipa.paddress.address[39 .. 0]) then { + fault.statuscode = Fault_Translation; + fault.level = 1; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + walkstate : TTWState = undefined; + (fault, walkstate) = AArch32_S2Walk(fault, walkparams, s1level, accdesc, ipa); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + }; + if AArch32_S2HasAlignmentFault(accdesc, aligned, walkstate.memattrs) then { + fault.statuscode = Fault_Alignment + } else if AArch32_S2HasPermissionsFault(walkparams, walkstate.permissions, walkstate.memattrs.memtype, accdesc) then { + fault.statuscode = Fault_Permission + } else (); + s2_memattrs : MemoryAttributes = undefined; + if (accdesc.acctype == AccessType_TTW & walkstate.memattrs.memtype == MemType_Device | accdesc.acctype == AccessType_IFETCH & (walkstate.memattrs.memtype == MemType_Device | HCR2_read()[ID] == 0b1)) | (accdesc.acctype != AccessType_IFETCH & walkstate.memattrs.memtype == MemType_Normal) & HCR2_read()[CD] == 0b1 then { + s2_memattrs = NormalNCMemAttr(); + s2_memattrs.xs = walkstate.memattrs.xs + } else { + s2_memattrs = walkstate.memattrs + }; + let s2aarch64 : bool = false; + let memattrs : MemoryAttributes = S2CombineS1MemAttrs(ipa.memattrs, s2_memattrs, s2aarch64); + let ipa_64 : bits(64) = ZeroExtend(ipa.paddress.address[39 .. 0], 64); + let oa : FullAddress = StageOA(ipa_64, walkparams.d128, walkparams.tgx, walkstate); + let pa : AddressDescriptor = CreateAddressDescriptor(ipa.vaddress, oa, memattrs); + return((fault, pa)) +} + +val AArch32_S1WalkLD : (FaultRecord, Regime, S1TTWParams, AccessDescriptor, bits(32)) -> (FaultRecord, TTWState) + +function AArch32_S1WalkLD (fault_in, regime, walkparams, accdesc, va) = { + finalwalkstate : TTWState = undefined; + s2aligned : bool = undefined; + s2fault : FaultRecord = undefined; + s2walkaddress : AddressDescriptor = undefined; + fault : FaultRecord = fault_in; + tlbcontext : TLBContext = undefined; + if __tlb_enabled then { + tlbcontext = AArch32_GetS1TLBContext(regime, accdesc.ss, va); + let tlbentry : TLBLine = S1TLBLookup(tlbcontext); + if tlbentry.valid_name then { + let finalwalkstate : TTWState = tlbentry.tlbrecord.walkstate; + fault.level = finalwalkstate.level; + return((fault, finalwalkstate)) + }; + () + }; + txsz : bits(3) = undefined; + ttbr : bits(64) = undefined; + epd : bits(1) = undefined; + varange : VARange = undefined; + if regime == Regime_EL2 then { + ttbr = HTTBR.bits; + txsz = walkparams.t0sz; + varange = VARange_LOWER + } else { + varange = AArch32_GetVARange(va, walkparams.t0sz, walkparams.t1sz); + ttbr0 : bits(64) = undefined; + ttbr1 : bits(64) = undefined; + ttbcr : TTBCR_Type = undefined; + if regime == Regime_EL30 then { + ttbcr = TTBCR_S; + ttbr0 = TTBR0_S.bits; + ttbr1 = TTBR1_S.bits + } else if HaveAArch32EL(EL3) then { + ttbcr = TTBCR_NS_read(); + ttbr0 = TTBR0_NS.bits; + ttbr1 = TTBR1_NS.bits + } else { + ttbcr = TTBCR_read(); + ttbr0 = TTBR0_read().bits; + ttbr1 = TTBR1_read().bits + }; + assert(ttbcr[EAE] == 0b1); + if varange == VARange_LOWER then { + txsz = walkparams.t0sz; + ttbr = ttbr0; + epd = ttbcr[EPD0] + } else { + txsz = walkparams.t1sz; + ttbr = ttbr1; + epd = ttbcr[EPD1] + } + }; + if regime != Regime_EL2 & epd == 0b1 then { + fault.level = 1; + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_TTWState())) + }; + let 'iasize = AArch32_S1IASize(txsz); + let 'granulebits = TGxGranuleBits(walkparams.tgx); + let 'stride = granulebits - 3; + let 'startlevel = FINAL_LEVEL - DIV(iasize - 1 - granulebits, stride); + let 'levels = FINAL_LEVEL - startlevel; + if not_bool(IsZero(ttbr[47 .. 40])) then { + fault.statuscode = Fault_AddressSize; + fault.level = 0; + return((fault, __UNKNOWN_TTWState())) + }; + baseaddress : FullAddress = undefined; + let 'baselsb = iasize - (levels * stride + granulebits) + 3; + baseaddress.paspace = if accdesc.ss == SS_Secure then PAS_Secure else + PAS_NonSecure; + assert(constraint((0 <= 'baselsb & 'baselsb <= 39))); + baseaddress.address = ZeroExtend(ttbr[39 .. baselsb] @ Zeros(baselsb), 56); + walkstate : TTWState = undefined; + walkstate.baseaddress = baseaddress; + walkstate.level = startlevel; + walkstate.istable = true; + walkstate.nG = if HasUnprivileged(regime) then 0b1 else 0b0; + walkstate.memattrs = WalkMemAttrs(walkparams.sh, walkparams.irgn, walkparams.orgn); + walkstate.permissions.ap_table = 0b00; + walkstate.permissions.xn_table = 0b0; + walkstate.permissions.pxn_table = 0b0; + indexmsb : int = iasize - 1; + descriptor : bits(64) = undefined; + walkaddress : AddressDescriptor = undefined; + walkaddress.vaddress = ZeroExtend(va, 64); + if not_bool(AArch32_S1DCacheEnabled(regime)) then { + walkaddress.memattrs = NormalNCMemAttr(); + walkaddress.memattrs.xs = walkstate.memattrs.xs + } else { + walkaddress.memattrs = walkstate.memattrs + }; + if ((regime == Regime_EL10 & AArch32_EL2Enabled(accdesc.ss)) & (if ELStateUsingAArch32(EL2, accdesc.ss == SS_Secure) then + HCR_read()[VM] + else + HCR_EL2[VM]) == 0b1) & not_bool(__IMPDEF_boolean("Apply effective shareability at stage 1")) then { + walkaddress.memattrs.shareability = walkstate.memattrs.shareability + } else { + walkaddress.memattrs.shareability = EffectiveShareability(walkaddress.memattrs) + }; + indexlsb : int = undefined; + desctype : DescriptorType = undefined; + repeat { + fault.level = walkstate.level; + indexlsb = (FINAL_LEVEL - walkstate.level) * stride + granulebits; + let index : bits(40) = let 'indexmsb = indexmsb in + { + let 'indexlsb = indexlsb; + assert(constraint((0 <= 'indexlsb & 'indexlsb <= 'indexmsb & 'indexmsb < 32))); + ZeroExtend(va[indexmsb .. indexlsb] @ 0b000, 40) + }; + walkaddress.paddress.address = walkstate.baseaddress.address | ZeroExtend(index, 56); + walkaddress.paddress.paspace = walkstate.baseaddress.paspace; + let toplevel : bool = walkstate.level == startlevel; + let walkaccess : AccessDescriptor = CreateAccDescS1TTW(toplevel, varange, accdesc); + let translation_info : TranslationInfo = struct { + regime = regime, + vmid = None(), // TODO: if regime == Regime_EL10 then Some(VMID_read()) else None(), + asid = None(), // TODO + va = walkaddress.vaddress, + s1level = Some(walkstate.level), + s2info = None(), + s1params = Some(walkparams), + s2params = None(), + memattrs = walkaddress.memattrs + }; + if regime == Regime_EL10 & AArch32_EL2Enabled(accdesc.ss) then { + s2aligned = true; + (s2fault, s2walkaddress) = AArch32_S2Translate(fault, walkaddress, Some(walkstate.level), s2aligned, walkaccess); + if s2fault.statuscode != Fault_None then { + return((s2fault, __UNKNOWN_TTWState())) + }; + (fault, descriptor) = FetchDescriptor(walkparams.ee, s2walkaddress, walkaccess, fault, 64, translation_info) + } else { + (fault, descriptor) = FetchDescriptor(walkparams.ee, walkaddress, walkaccess, fault, 64, translation_info) + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_TTWState())) + }; + desctype = AArch32_DecodeDescriptorTypeLD(descriptor, walkstate.level); + match desctype { + DescriptorType_Table => { + if not_bool(IsZero(descriptor[47 .. 40])) then { + fault.statuscode = Fault_AddressSize; + return((fault, __UNKNOWN_TTWState())) + }; + walkstate.baseaddress.address = ZeroExtend(descriptor[39 .. 12] @ Zeros(12), 56); + if walkstate.baseaddress.paspace == PAS_Secure & [descriptor[63]] == 0b1 then { + walkstate.baseaddress.paspace = PAS_NonSecure + }; + if walkparams.hpd == 0b0 then { + walkstate.permissions.xn_table = walkstate.permissions.xn_table | [descriptor[60]]; + walkstate.permissions.ap_table = walkstate.permissions.ap_table | descriptor[62 .. 61]; + walkstate.permissions.pxn_table = walkstate.permissions.pxn_table | [descriptor[59]] + }; + walkstate.level = walkstate.level + 1; + indexmsb = indexlsb - 1 + }, + DescriptorType_Invalid => { + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_TTWState())) + }, + DescriptorType_Leaf => { + walkstate.istable = false + } + } + } until desctype == DescriptorType_Leaf; + let 'indexlsb = indexlsb; + if not_bool(IsZero(descriptor[47 .. 40])) then { + fault.statuscode = Fault_AddressSize; + return((fault, __UNKNOWN_TTWState())) + }; + if [descriptor[10]] == 0b0 then { + fault.statuscode = Fault_AccessFlag; + return((fault, __UNKNOWN_TTWState())) + }; + walkstate.permissions.xn = [descriptor[54]]; + walkstate.permissions.pxn = [descriptor[53]]; + walkstate.permissions.ap = descriptor[7 .. 6] @ 0b1; + walkstate.contiguous = [descriptor[52]]; + if regime == Regime_EL2 then { + walkstate.nG = 0b0 + } else if accdesc.ss == SS_Secure & walkstate.baseaddress.paspace == PAS_NonSecure then { + walkstate.nG = 0b1 + } else { + walkstate.nG = [descriptor[11]] + }; + assert(constraint((0 <= 'indexlsb & 'indexlsb <= 39))); + walkstate.baseaddress.address = ZeroExtend(descriptor[39 .. indexlsb] @ Zeros(indexlsb), 56); + if walkstate.baseaddress.paspace == PAS_Secure & [descriptor[5]] == 0b1 then { + walkstate.baseaddress.paspace = PAS_NonSecure + }; + let memattr : bits(3) = descriptor[4 .. 2]; + let sh : bits(2) = descriptor[9 .. 8]; + let attr : bits(8) = AArch32_MAIRAttr(UInt(memattr), walkparams.mair); + let s1aarch64 : bool = false; + walkstate.memattrs = S1DecodeMemAttrs(attr, sh, s1aarch64, walkparams); + if __tlb_enabled then { + tlbcontext.xs = walkstate.memattrs.xs; + tlbcontext.level = walkstate.level; + tlbcontext.nG = walkstate.nG; + tlbrecord : TLBRecord = undefined; + tlbrecord.context = tlbcontext; + tlbrecord.walkstate = walkstate; + tlbrecord.blocksize = TranslationSize(walkparams.d128, walkparams.tgx, walkstate.level); + if walkstate.contiguous == 0b1 then { + tlbrecord.contigsize = ContiguousSize(walkparams.d128, walkparams.tgx, walkstate.level) + } else { + tlbrecord.contigsize = 0 + }; + S1TLBCache(tlbrecord) + }; + return((fault, walkstate)) +} + +val AArch32_VAIsOutOfRange : (Regime, S1TTWParams, bits(32)) -> bool + +function AArch32_VAIsOutOfRange (regime, walkparams, va) = { + iasize : int = undefined; + lo_iasize : int = undefined; + up_iasize : int = undefined; + if regime == Regime_EL2 then { + let 'iasize = AArch32_S1IASize(walkparams.t0sz); + return(walkparams.t0sz != 0b000 & not_bool(is_zero_subrange(va, 31, iasize))) + } else if walkparams.t1sz != 0b000 & walkparams.t0sz != 0b000 then { + let 'lo_iasize = AArch32_S1IASize(walkparams.t0sz); + let 'up_iasize = AArch32_S1IASize(walkparams.t1sz); + return(not_bool(is_zero_subrange(va, 31, lo_iasize)) & not_bool(is_ones_subrange(va, 31, up_iasize))) + } else { + return(false) + } +} + +val AArch32_S1TranslateLD : forall ('aligned : Bool). + (FaultRecord, Regime, bits(32), bool('aligned), AccessDescriptor) -> (FaultRecord, AddressDescriptor) + +function AArch32_S1TranslateLD (fault_in, regime, va, aligned, accdesc) = { + fault : FaultRecord = fault_in; + if not_bool(AArch32_S1Enabled(regime, accdesc.ss)) then { + return(AArch32_S1DisabledOutput(fault, regime, va, aligned, accdesc)) + }; + let walkparams : S1TTWParams = AArch32_GetS1TTWParams(regime, va); + if AArch32_VAIsOutOfRange(regime, walkparams, va) then { + fault.level = 1; + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_AddressDescriptor())) + }; + walkstate : TTWState = undefined; + (fault, walkstate) = AArch32_S1WalkLD(fault, regime, walkparams, accdesc, va); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + }; + SetInGuardedPage(false); + if AArch32_S1HasAlignmentFault(accdesc, aligned, walkparams.ntlsmd, walkstate.memattrs) then { + fault.statuscode = Fault_Alignment + } else if AArch32_S1LDHasPermissionsFault(regime, walkparams, walkstate.permissions, walkstate.memattrs.memtype, walkstate.baseaddress.paspace, accdesc) then { + fault.statuscode = Fault_Permission + } else (); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor())) + }; + memattrs : MemoryAttributes = undefined; + if accdesc.acctype == AccessType_IFETCH & (walkstate.memattrs.memtype == MemType_Device | not_bool(AArch32_S1ICacheEnabled(regime))) | (accdesc.acctype != AccessType_IFETCH & walkstate.memattrs.memtype == MemType_Normal) & not_bool(AArch32_S1DCacheEnabled(regime)) then { + memattrs = NormalNCMemAttr(); + memattrs.xs = walkstate.memattrs.xs + } else { + memattrs = walkstate.memattrs + }; + if ((regime == Regime_EL10 & AArch32_EL2Enabled(accdesc.ss)) & (if ELStateUsingAArch32(EL2, accdesc.ss == SS_Secure) then + HCR_read()[VM] + else + HCR_EL2[VM]) == 0b1) & not_bool(__IMPDEF_boolean("Apply effective shareability at stage 1")) then { + memattrs.shareability = walkstate.memattrs.shareability + } else { + memattrs.shareability = EffectiveShareability(memattrs) + }; + let oa : FullAddress = StageOA(ZeroExtend(va, 64), walkparams.d128, walkparams.tgx, walkstate); + let ipa : AddressDescriptor = CreateAddressDescriptor(ZeroExtend(va, 64), oa, memattrs); + return((fault, ipa)) +} + +bitfield DACR32_EL2_Type : bits(64) = + { + D15 : 31..30, + D14 : 29..28, + D13 : 27..26, + D12 : 25..24, + D11 : 23..22, + D10 : 21..20, + D9 : 19..18, + D8 : 17..16, + D7 : 15..14, + D6 : 13..12, + D5 : 11..10, + D4 : 9..8, + D3 : 7..6, + D2 : 5..4, + D1 : 3..2, + D0 : 1..0 + } + +register DACR32_EL2 : DACR32_EL2_Type + +bitfield DACR_Type : bits(32) = + { + D15 : 31..30, + D14 : 29..28, + D13 : 27..26, + D12 : 25..24, + D11 : 23..22, + D10 : 21..20, + D9 : 19..18, + D8 : 17..16, + D7 : 15..14, + D6 : 13..12, + D5 : 11..10, + D4 : 9..8, + D3 : 7..6, + D2 : 5..4, + D1 : 3..2, + D0 : 1..0 + } + +register _DACR_NS : DACR_Type + +val DACR_NS_read : unit -> DACR_Type + +function DACR_NS_read () = { + r : DACR_Type = _DACR_NS; + r.bits[31 .. 0] = Slice(DACR32_EL2.bits, 0, 32); + return(r) +} + +register DACR_S : DACR_Type + +val DACR_read : unit -> DACR_Type + +function DACR_read () = { + r : DACR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = DACR_S + } else { + r = DACR_NS_read() + }; + return(r) +} + +val AArch32_OutputDomain : (Regime, bits(4)) -> bits(2) + +function AArch32_OutputDomain (regime, domain) = { + Dn : bits(2) = undefined; + let 'index = 2 * UInt(domain); + if regime == Regime_EL30 then { + Dn = DACR_S.bits[index + 1 .. index] + } else if HaveAArch32EL(EL3) then { + Dn = DACR_NS_read().bits[index + 1 .. index] + } else { + Dn = DACR_read().bits[index + 1 .. index] + }; + if Dn == 0b10 then { + let (_, __tup_1 : bits(2)) = ConstrainUnpredictableBits(Unpredictable_RESDACR, 2); + Dn = __tup_1 + }; + return(Dn) +} + +val AArch32_S1SDHasPermissionsFault : (Regime, Permissions, MemType, PASpace, AccessDescriptor) -> bool + +function AArch32_S1SDHasPermissionsFault (regime, perms_in, memtype, paspace, accdesc) = { + pan : bits(1) = undefined; + r : bits(1) = undefined; + w : bits(1) = undefined; + x : bits(1) = undefined; + perms : Permissions = perms_in; + pr : bits(1) = undefined; + pw : bits(1) = undefined; + ur : bits(1) = undefined; + uw : bits(1) = undefined; + sctlr : SCTLR_Type = undefined; + if regime == Regime_EL30 then { + sctlr = SCTLR_S + } else if HaveAArch32EL(EL3) then { + sctlr = SCTLR_NS_read() + } else { + sctlr = SCTLR_read__2() + }; + if sctlr[AFE] == 0b0 then { + if perms.ap == 0b100 then { + perms.ap = __IMPDEF_bits(3, "Reserved short descriptor AP encoding") + }; + match perms.ap { + 0b000 => { + (pr, pw, ur, uw) = (0b0, 0b0, 0b0, 0b0) + }, + 0b001 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b0, 0b0) + }, + 0b010 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b1, 0b0) + }, + 0b011 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b1, 0b1) + }, + 0b101 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b0, 0b0) + }, + 0b110 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b1, 0b0) + }, + 0b111 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b1, 0b0) + }, + _ => () + } + } else { + match perms.ap[2 .. 1] { + 0b00 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b0, 0b0) + }, + 0b01 => { + (pr, pw, ur, uw) = (0b1, 0b1, 0b1, 0b1) + }, + 0b10 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b0, 0b0) + }, + 0b11 => { + (pr, pw, ur, uw) = (0b1, 0b0, 0b1, 0b0) + }, + _ => () + } + }; + let ux : bits(1) = ur & not_vec(perms.xn | uw & sctlr[WXN]); + let px : bits(1) = pr & not_vec(((perms.xn | perms.pxn) | pw & sctlr[WXN]) | uw & sctlr[UWXN]); + if HavePANExt() & accdesc.pan then { + let pan : bits(1) = PSTATE.PAN & (ur | uw); + pr = pr & not_vec(pan); + pw = pw & not_vec(pan) + }; + (r, w, x) = if accdesc.el == EL0 then (ur, uw, ux) else (pr, pw, px); + if accdesc.ss == SS_Secure & paspace == PAS_NonSecure then { + x = x & not_vec(if ELUsingAArch32(EL3) then SCR[SIF] else SCR_EL3[SIF]) + }; + let x = x; + if accdesc.acctype == AccessType_IFETCH then { + if memtype == MemType_Device & ConstrainUnpredictable(Unpredictable_INSTRDEVICE) == Constraint_FAULT then { + return(true) + } else { + return(x == 0b0) + } + } else if accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC then { + return(false) + } else if accdesc.write then { + return(w == 0b0) + } else { + return(r == 0b0) + } +} + +val AArch32_DecodeDescriptorTypeSD : forall 'level. + (bits(32), int('level)) -> SDFType + +function AArch32_DecodeDescriptorTypeSD (descriptor, level) = { + if level == 1 & descriptor[1 .. 0] == 0b01 then { + return(SDFType_Table) + } else if level == 1 & ([descriptor[18]] @ [descriptor[1]]) == 0b01 then { + return(SDFType_Section) + } else if level == 1 & ([descriptor[18]] @ [descriptor[1]]) == 0b11 then { + return(SDFType_Supersection) + } else if level == 2 & descriptor[1 .. 0] == 0b01 then { + return(SDFType_LargePage) + } else if level == 2 & (match descriptor[1 .. 0] { + [bitone, _] => true, + _ => false + }) : bool then { + return(SDFType_SmallPage) + } else { + return(SDFType_Invalid) + } +} + +val __IMPDEF_MemoryAttributes : string -> MemoryAttributes + +function __IMPDEF_MemoryAttributes x = { + return(__UNKNOWN_MemoryAttributes()) +} + +val AArch32_DefaultTEXDecode : (bits(3), bits(1), bits(1), bits(1)) -> MemoryAttributes + +function AArch32_DefaultTEXDecode (TEX_in, C_in, B_in, s) = { + memattrs : MemoryAttributes = undefined; + TEX : bits(3) = TEX_in; + C : bits(1) = C_in; + B : bits(1) = B_in; + if (TEX == 0b001 & (C @ B) == 0b01 | TEX == 0b010 & (C @ B) != 0b00) | TEX == 0b011 then { + texcb : bits(5) = undefined; + let (_, __tup_1 : bits(5)) = + ConstrainUnpredictableBits(Unpredictable_RESTEXCB, 5) + in + { + texcb = __tup_1 + }; + TEX = texcb[4 .. 2]; + C = [texcb[1]]; + B = [texcb[0]] + }; + match (TEX @ C) @ B { + 0b00000 => { + memattrs.memtype = MemType_Device; + memattrs.device = DeviceType_nGnRnE; + memattrs.shareability = Shareability_OSH + }, + 0b00001 => { + memattrs.memtype = MemType_Device; + memattrs.device = DeviceType_nGnRE; + memattrs.shareability = Shareability_OSH + }, + 0b01000 => { + memattrs.memtype = MemType_Device; + memattrs.device = DeviceType_nGnRE; + memattrs.shareability = Shareability_OSH + }, + 0b00010 => { + memattrs.memtype = MemType_Normal; + memattrs.inner.attrs = MemAttr_WT; + memattrs.inner.hints = MemHint_RA; + memattrs.outer.attrs = MemAttr_WT; + memattrs.outer.hints = MemHint_RA; + memattrs.shareability = if s == 0b1 then Shareability_OSH else + Shareability_NSH + }, + 0b00011 => { + memattrs.memtype = MemType_Normal; + memattrs.inner.attrs = MemAttr_WB; + memattrs.inner.hints = MemHint_RA; + memattrs.outer.attrs = MemAttr_WB; + memattrs.outer.hints = MemHint_RA; + memattrs.shareability = if s == 0b1 then Shareability_OSH else + Shareability_NSH + }, + 0b00100 => { + memattrs.memtype = MemType_Normal; + memattrs.inner.attrs = MemAttr_NC; + memattrs.outer.attrs = MemAttr_NC; + memattrs.shareability = Shareability_OSH + }, + 0b00110 => { + memattrs = __IMPDEF_MemoryAttributes("") + }, + 0b00111 => { + memattrs.memtype = MemType_Normal; + memattrs.inner.attrs = MemAttr_WB; + memattrs.inner.hints = MemHint_RWA; + memattrs.outer.attrs = MemAttr_WB; + memattrs.outer.hints = MemHint_RWA; + memattrs.shareability = if s == 0b1 then Shareability_OSH else + Shareability_NSH + }, + [bitone, _, _, _, _] => { + memattrs.memtype = MemType_Normal; + memattrs.inner = DecodeSDFAttr(C @ B); + memattrs.outer = DecodeSDFAttr(TEX[1 .. 0]); + if memattrs.inner.attrs == MemAttr_NC & memattrs.outer.attrs == MemAttr_NC then { + memattrs.shareability = Shareability_OSH + } else { + memattrs.shareability = if s == 0b1 then Shareability_OSH else + Shareability_NSH + } + }, + _ => { + Unreachable() + } + }; + memattrs.inner.transient = false; + memattrs.outer.transient = false; + memattrs.tags = MemTag_Untagged; + if memattrs.inner.attrs == MemAttr_WB & memattrs.outer.attrs == MemAttr_WB then { + memattrs.xs = 0b0 + } else { + memattrs.xs = 0b1 + }; + return(memattrs) +} + +val AArch32_RemappedTEXDecode : (Regime, bits(3), bits(1), bits(1), bits(1)) -> MemoryAttributes + +function AArch32_RemappedTEXDecode (regime, TEX, C, B, s) = { + NOSm : bits(1) = undefined; + NSn : bits(1) = undefined; + memattrs : MemoryAttributes = undefined; + prrr : PRRR_Type = undefined; + nmrr : NMRR_Type = undefined; + let 'region = UInt(([TEX[0]] @ C) @ B); + if region == 6 then { + return(__IMPDEF_MemoryAttributes("")) + }; + if regime == Regime_EL30 then { + prrr = PRRR_S; + nmrr = NMRR_S + } else if HaveAArch32EL(EL3) then { + prrr = PRRR_NS_read(); + nmrr = NMRR_NS_read() + } else { + prrr = PRRR_read(); + nmrr = NMRR_read() + }; + let 'base = 2 * region; + attrfield : bits(0 + ('base + 1 - 'base + 1)) = prrr.bits[base + 1 .. base]; + if attrfield == 0b11 then { + let (_, __tup_1 : bits(0 + ('base + 1 - 'base + 1))) = ConstrainUnpredictableBits(Unpredictable_RESPRRR, 2); + attrfield = __tup_1 + }; + IRn : bits(0 + ('base + 1 - 'base + 1)) = undefined; + ORn : bits(0 + ('base + 17 - ('base + 16) + 1)) = undefined; + match attrfield { + 0b00 => { + memattrs.memtype = MemType_Device; + memattrs.device = DeviceType_nGnRnE; + memattrs.shareability = Shareability_OSH + }, + 0b01 => { + memattrs.memtype = MemType_Device; + memattrs.device = DeviceType_nGnRE; + memattrs.shareability = Shareability_OSH + }, + 0b10 => { + let NSn : bits(1) = if s == 0b0 then prrr[NS0] else prrr[NS1]; + let NOSm : bits(1) = [prrr.bits[region + 24]] & NSn; + let IRn : bits(0 + ('base + 1 - 'base + 1)) = nmrr.bits[base + 1 .. base]; + let ORn : bits(0 + ('base + 17 - ('base + 16) + 1)) = nmrr.bits[base + 17 .. base + 16]; + memattrs.memtype = MemType_Normal; + memattrs.inner = DecodeSDFAttr(IRn); + memattrs.outer = DecodeSDFAttr(ORn); + if memattrs.inner.attrs == MemAttr_NC & memattrs.outer.attrs == MemAttr_NC then { + memattrs.shareability = Shareability_OSH + } else { + let sh : bits(2) = NSn @ NOSm; + memattrs.shareability = DecodeShareability(sh) + } + }, + 0b11 => { + Unreachable() + }, + _ => () + }; + memattrs.inner.transient = false; + memattrs.outer.transient = false; + memattrs.tags = MemTag_Untagged; + if memattrs.inner.attrs == MemAttr_WB & memattrs.outer.attrs == MemAttr_WB then { + memattrs.xs = 0b0 + } else { + memattrs.xs = 0b1 + }; + return(memattrs) +} + +val AArch32_TranslationSizeSD : SDFType -> int + +function AArch32_TranslationSizeSD sdftype = { + tsize : {12, 16, 20, 24} = 12; + match sdftype { + SDFType_SmallPage => { + tsize = 12 + }, + SDFType_LargePage => { + tsize = 16 + }, + SDFType_Section => { + tsize = 20 + }, + SDFType_Supersection => { + tsize = 24 + }, + _ => () + }; + let 'tsize = tsize; + return(tsize) +} + +val RemapRegsHaveResetValues : unit -> bool + +val AArch32_S1WalkSD : (FaultRecord, Regime, AccessDescriptor, bits(32)) -> (FaultRecord, TTWState) + +function AArch32_S1WalkSD (fault_in, regime, accdesc, va) = { + finalwalkstate : TTWState = undefined; + s2aligned : bool = undefined; + s2fault : FaultRecord = undefined; + s2walkaddress : AddressDescriptor = undefined; + fault : FaultRecord = fault_in; + tlbcontext : TLBContext = undefined; + if __tlb_enabled then { + tlbcontext = AArch32_GetS1TLBContext(regime, accdesc.ss, va); + let tlbentry : TLBLine = S1TLBLookup(tlbcontext); + if tlbentry.valid_name then { + let finalwalkstate : TTWState = tlbentry.tlbrecord.walkstate; + fault.level = finalwalkstate.level; + return((fault, finalwalkstate)) + }; + () + }; + sctlr : SCTLR_Type = undefined; + ttbcr : TTBCR_Type = undefined; + ttbr0 : TTBR0_Type = undefined; + ttbr1 : TTBR1_Type = undefined; + if regime == Regime_EL30 then { + sctlr = SCTLR_S; + ttbcr = TTBCR_S; + ttbr0 = TTBR0_S; + ttbr1 = TTBR1_S + } else if HaveAArch32EL(EL3) then { + sctlr = SCTLR_NS_read(); + ttbcr = TTBCR_NS_read(); + ttbr0 = TTBR0_NS; + ttbr1 = TTBR1_NS + } else { + sctlr = SCTLR_read__2(); + ttbcr = TTBCR_read(); + ttbr0 = TTBR0_read(); + ttbr1 = TTBR1_read() + }; + assert(ttbcr[EAE] == 0b0); + let ee : bits(1) = sctlr[EE]; + let afe : bits(1) = sctlr[AFE]; + let tre : bits(1) = sctlr[TRE]; + n : range(0, 7) = UInt(ttbcr[N]); + ttb : bits(32) = undefined; + pd : bits(1) = undefined; + irgn : bits(2) = undefined; + rgn : bits(2) = undefined; + s : bits(1) = undefined; + nos : bits(1) = undefined; + varange : VARange = undefined; + if n == 0 | is_zero_subrange(va, 31, 32 - n) then { + ttb = ttbr0[TTB0] @ Zeros(7); + pd = ttbcr[PD0]; + irgn = ttbr0[IRGN]; + rgn = ttbr0[RGN]; + s = ttbr0[S]; + nos = ttbr0[NOS]; + varange = VARange_LOWER + } else { + n = 0; + ttb = ttbr1[TTB1] @ Zeros(7); + pd = ttbcr[PD1]; + irgn = ttbr1[IRGN]; + rgn = ttbr1[RGN]; + s = ttbr1[S]; + nos = ttbr1[NOS]; + varange = VARange_UPPER + }; + let 'n = n; + if pd == 0b1 then { + fault.level = 1; + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_TTWState())) + }; + baseaddress : FullAddress = undefined; + baseaddress.paspace = if accdesc.ss == SS_Secure then PAS_Secure else + PAS_NonSecure; + baseaddress.address = ZeroExtend(ttb[31 .. 14 - n] @ Zeros(14 - n), 56); + let 'startlevel = 1; + walkstate : TTWState = undefined; + walkstate.baseaddress = baseaddress; + walkstate.nG = 0b1; + walkstate.memattrs = WalkMemAttrs(s @ nos, irgn, rgn); + walkstate.level = startlevel; + walkstate.istable = true; + domain : bits(4) = undefined; + descriptor : bits(32) = undefined; + walkaddress : AddressDescriptor = undefined; + walkaddress.vaddress = ZeroExtend(va, 64); + if not_bool(AArch32_S1DCacheEnabled(regime)) then { + walkaddress.memattrs = NormalNCMemAttr(); + walkaddress.memattrs.xs = walkstate.memattrs.xs + } else { + walkaddress.memattrs = walkstate.memattrs + }; + if ((regime == Regime_EL10 & AArch32_EL2Enabled(accdesc.ss)) & (if ELStateUsingAArch32(EL2, accdesc.ss == SS_Secure) then + HCR_read()[VM] + else + HCR_EL2[VM]) == 0b1) & not_bool(__IMPDEF_boolean("Apply effective shareability at stage 1")) then { + walkaddress.memattrs.shareability = walkstate.memattrs.shareability + } else { + walkaddress.memattrs.shareability = EffectiveShareability(walkaddress.memattrs) + }; + nG : bits(1) = undefined; + ns : bits(1) = undefined; + pxn : bits(1) = undefined; + ap : bits(3) = undefined; + tex : bits(3) = undefined; + c : bits(1) = undefined; + b : bits(1) = undefined; + xn : bits(1) = undefined; + repeat { + fault.level = walkstate.level; + index : bits(32) = undefined; + if walkstate.level == 1 then { + index = ZeroExtend(va[31 - n .. 20] @ 0b00, 32) + } else { + index = ZeroExtend(va[19 .. 12] @ 0b00, 32) + }; + walkaddress.paddress.address = walkstate.baseaddress.address | ZeroExtend(index, 56); + walkaddress.paddress.paspace = walkstate.baseaddress.paspace; + let toplevel : bool = walkstate.level == startlevel; + let walkaccess : AccessDescriptor = CreateAccDescS1TTW(toplevel, varange, accdesc); + let translation_info : TranslationInfo = struct { + regime = regime, + vmid = None(), // TODO: if regime == Regime_EL10 then Some(VMID_read()) else None(), + asid = None(), // TODO + va = walkaddress.vaddress, + s1level = Some(walkstate.level), + s2info = None(), + s1params = None(), // TODO: AArch32 doesn't use S1TTWParams? + s2params = None(), + memattrs = walkaddress.memattrs + }; + if regime == Regime_EL10 & AArch32_EL2Enabled(accdesc.ss) then { + s2aligned = true; + (s2fault, s2walkaddress) = AArch32_S2Translate(fault, walkaddress, Some(walkstate.level), s2aligned, walkaccess); + if s2fault.statuscode != Fault_None then { + return((s2fault, __UNKNOWN_TTWState())) + }; + (fault, descriptor) = FetchDescriptor(ee, s2walkaddress, walkaccess, fault, 32, translation_info) + } else { + (fault, descriptor) = FetchDescriptor(ee, walkaddress, walkaccess, fault, 32, translation_info) + }; + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_TTWState())) + }; + walkstate.sdftype = AArch32_DecodeDescriptorTypeSD(descriptor, walkstate.level); + match walkstate.sdftype { + SDFType_Invalid => { + fault.domain = domain; + fault.statuscode = Fault_Translation; + return((fault, __UNKNOWN_TTWState())) + }, + SDFType_Table => { + domain = descriptor[8 .. 5]; + ns = [descriptor[3]]; + pxn = [descriptor[2]]; + walkstate.baseaddress.address = ZeroExtend(descriptor[31 .. 10] @ Zeros(10), 56); + walkstate.level = 2 + }, + SDFType_SmallPage => { + nG = [descriptor[11]]; + s = [descriptor[10]]; + ap = [descriptor[9]] @ descriptor[5 .. 4]; + tex = descriptor[8 .. 6]; + c = [descriptor[3]]; + b = [descriptor[2]]; + xn = [descriptor[0]]; + walkstate.baseaddress.address = ZeroExtend(descriptor[31 .. 12] @ Zeros(12), 56); + walkstate.istable = false + }, + SDFType_LargePage => { + xn = [descriptor[15]]; + tex = descriptor[14 .. 12]; + nG = [descriptor[11]]; + s = [descriptor[10]]; + ap = [descriptor[9]] @ descriptor[5 .. 4]; + c = [descriptor[3]]; + b = [descriptor[2]]; + walkstate.baseaddress.address = ZeroExtend(descriptor[31 .. 16] @ Zeros(16), 56); + walkstate.istable = false + }, + SDFType_Section => { + ns = [descriptor[19]]; + nG = [descriptor[17]]; + s = [descriptor[16]]; + ap = [descriptor[15]] @ descriptor[11 .. 10]; + tex = descriptor[14 .. 12]; + domain = descriptor[8 .. 5]; + xn = [descriptor[4]]; + c = [descriptor[3]]; + b = [descriptor[2]]; + pxn = [descriptor[0]]; + walkstate.baseaddress.address = ZeroExtend(descriptor[31 .. 20] @ Zeros(20), 56); + walkstate.istable = false + }, + SDFType_Supersection => { + ns = [descriptor[19]]; + nG = [descriptor[17]]; + s = [descriptor[16]]; + ap = [descriptor[15]] @ descriptor[11 .. 10]; + tex = descriptor[14 .. 12]; + xn = [descriptor[4]]; + c = [descriptor[3]]; + b = [descriptor[2]]; + pxn = [descriptor[0]]; + domain = 0b0000; + walkstate.baseaddress.address = ZeroExtend((descriptor[8 .. 5] @ (descriptor[23 .. 20] @ descriptor[31 .. 24])) @ Zeros(24), 56); + walkstate.istable = false + } + } + } until walkstate.sdftype != SDFType_Table; + if afe == 0b1 & [ap[0]] == 0b0 then { + fault.domain = domain; + fault.statuscode = Fault_AccessFlag; + return((fault, __UNKNOWN_TTWState())) + }; + if tre == 0b1 then { + walkstate.memattrs = AArch32_RemappedTEXDecode(regime, tex, c, b, s) + } else if RemapRegsHaveResetValues() then { + walkstate.memattrs = AArch32_DefaultTEXDecode(tex, c, b, s) + } else { + walkstate.memattrs = __IMPDEF_MemoryAttributes("") + }; + walkstate.permissions.ap = ap; + walkstate.permissions.xn = xn; + walkstate.permissions.pxn = pxn; + walkstate.domain = domain; + walkstate.nG = nG; + if accdesc.ss == SS_Secure & ns == 0b0 then { + walkstate.baseaddress.paspace = PAS_Secure + } else { + walkstate.baseaddress.paspace = PAS_NonSecure + }; + if __tlb_enabled then { + tlbcontext.xs = walkstate.memattrs.xs; + tlbcontext.nG = walkstate.nG; + tlbrecord : TLBRecord = undefined; + tlbrecord.context = tlbcontext; + tlbrecord.walkstate = walkstate; + tlbrecord.blocksize = AArch32_TranslationSizeSD(walkstate.sdftype); + tlbrecord.contigsize = 0; + S1TLBCache(tlbrecord) + }; + return((fault, walkstate)) +} + +val AArch32_SDStageOA : (FullAddress, bits(32), SDFType) -> FullAddress + +function AArch32_SDStageOA (baseaddress, va, sdftype) = { + tsize : {12, 16, 20, 24} = 12; + match sdftype { + SDFType_SmallPage => { + tsize = 12 + }, + SDFType_LargePage => { + tsize = 16 + }, + SDFType_Section => { + tsize = 20 + }, + SDFType_Supersection => { + tsize = 24 + }, + _ => () + }; + let 'tsize = tsize; + oa : FullAddress = undefined; + oa.address = baseaddress.address[55 .. tsize] @ va[tsize - 1 .. 0]; + oa.paspace = baseaddress.paspace; + return(oa) +} + +val AArch32_S1TranslateSD : forall ('aligned : Bool). + (FaultRecord, Regime, bits(32), bool('aligned), AccessDescriptor) -> (FaultRecord, AddressDescriptor, SDFType) + +function AArch32_S1TranslateSD (fault_in, regime, va, aligned, accdesc) = { + ipa : AddressDescriptor = undefined; + fault : FaultRecord = fault_in; + if not_bool(AArch32_S1Enabled(regime, accdesc.ss)) then { + ipa : AddressDescriptor = undefined; + (fault, ipa) = AArch32_S1DisabledOutput(fault, regime, va, aligned, accdesc); + return((fault, ipa, __UNKNOWN_SDFType())) + }; + walkstate : TTWState = undefined; + (fault, walkstate) = AArch32_S1WalkSD(fault, regime, accdesc, va); + if fault.statuscode != Fault_None then { + return((fault, __UNKNOWN_AddressDescriptor(), __UNKNOWN_SDFType())) + }; + let domain : bits(2) = AArch32_OutputDomain(regime, walkstate.domain); + SetInGuardedPage(false); + ntlsmd : bits(1) = undefined; + if HaveTrapLoadStoreMultipleDeviceExt() then { + match regime { + Regime_EL30 => { + ntlsmd = SCTLR_S[nTLSMD] + }, + Regime_EL10 => { + ntlsmd = if HaveAArch32EL(EL3) then SCTLR_NS_read()[nTLSMD] else + SCTLR_read__2()[nTLSMD] + }, + _ => () + } + } else { + ntlsmd = 0b1 + }; + if AArch32_S1HasAlignmentFault(accdesc, aligned, ntlsmd, walkstate.memattrs) then { + fault.statuscode = Fault_Alignment + } else if not_bool(accdesc.acctype == AccessType_IC | accdesc.acctype == AccessType_DC) & domain == Domain_NoAccess then { + fault.statuscode = Fault_Domain + } else if domain == Domain_Client then { + if AArch32_S1SDHasPermissionsFault(regime, walkstate.permissions, walkstate.memattrs.memtype, walkstate.baseaddress.paspace, accdesc) then { + fault.statuscode = Fault_Permission + }; + () + } else (); + if fault.statuscode != Fault_None then { + fault.domain = walkstate.domain; + return((fault, __UNKNOWN_AddressDescriptor(), walkstate.sdftype)) + }; + memattrs : MemoryAttributes = undefined; + if accdesc.acctype == AccessType_IFETCH & (walkstate.memattrs.memtype == MemType_Device | not_bool(AArch32_S1ICacheEnabled(regime))) | (accdesc.acctype != AccessType_IFETCH & walkstate.memattrs.memtype == MemType_Normal) & not_bool(AArch32_S1DCacheEnabled(regime)) then { + memattrs = NormalNCMemAttr(); + memattrs.xs = walkstate.memattrs.xs + } else { + memattrs = walkstate.memattrs + }; + if ((regime == Regime_EL10 & AArch32_EL2Enabled(accdesc.ss)) & (if ELStateUsingAArch32(EL2, accdesc.ss == SS_Secure) then + HCR_read()[VM] + else + HCR_EL2[VM]) == 0b1) & not_bool(__IMPDEF_boolean("Apply effective shareability at stage 1")) then { + memattrs.shareability = walkstate.memattrs.shareability + } else { + memattrs.shareability = EffectiveShareability(memattrs) + }; + let oa : FullAddress = AArch32_SDStageOA(walkstate.baseaddress, va, walkstate.sdftype); + let ipa : AddressDescriptor = CreateAddressDescriptor(ZeroExtend(va, 64), oa, memattrs); + return((fault, ipa, walkstate.sdftype)) +} + +val AArch64_PARFaultStatus : FaultRecord -> bits(6) + +function AArch64_PARFaultStatus fault = { + fst : bits(6) = undefined; + if fault.statuscode == Fault_Domain then { + assert(fault.level == 1 | fault.level == 2); + fst[1 .. 0] = if fault.level == 1 then 0b01 else 0b10; + fst[5 .. 2] = 0b1111 + } else { + fst = EncodeLDFSC(fault.statuscode, fault.level) + }; + return(fst) +} + +val AArch64_isPARFormatD128 : forall ('is_ATS1Ex : Bool). + (Regime, bool('is_ATS1Ex)) -> bool + +function AArch64_isPARFormatD128 (regime, is_ATS1Ex) = { + isPARFormatD128 : bool = undefined; + if regime == Regime_EL2 | not_bool(Have128BitDescriptorExt()) then { + isPARFormatD128 = false + } else { + isPARFormatD128 = false; + match regime { + Regime_EL3 => { + isPARFormatD128 = TCR_EL3[D128] == 0b1 + }, + Regime_EL20 => { + isPARFormatD128 = TCR2_EL2[D128] == 0b1 + }, + Regime_EL10 => { + if (is_ATS1Ex | not_bool(EL2Enabled())) | (HCR_EL2[VM] @ HCR_EL2[DC]) == 0b00 then { + isPARFormatD128 = TCR2_EL1[D128] == 0b1 + } else { + isPARFormatD128 = VTCR_EL2[D128] == 0b1 + } + }, + _ => () + } + }; + return(isPARFormatD128) +} + +bitfield PAR_Type : bits(64) = + { + ATTR : 63..56, + PA : 39..12, + LPAE : 11..11, + NOS : 10..10, + FSTAGE : 9..9, + NS : 9..9, + S2WLK : 8..8, + SH : 8..7, + FS : (6..6 @ 5..1), + Inner : 6..4, + Outer : 3..2, + FST : 6..1, + SS : 1..1, + F : 0..0 + } + +register PAR_NS : PAR_Type + +register PAR_S : PAR_Type + +val PAR_read : unit -> PAR_Type + +function PAR_read () = { + r : PAR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = PAR_S + } else { + r = PAR_NS + }; + return(r) +} + +bitfield PAR_EL1_Type : bits(128) = + { + D128 : 64..64, + ATTR : 63..56, + DirtyBit : 15..15, + Overlay : 14..14, + TopLevel : 13..13, + AssuredOnly : 12..12, + NSE : 11..11, + S : 9..9, + NS : 9..9, + PTW : 8..8, + SH : 8..7, + FST : 6..1, + F : 0..0 + } + +register _PAR_EL1 : PAR_EL1_Type + +val PAR_EL1_read : unit -> PAR_EL1_Type + +function PAR_EL1_read () = { + r : PAR_EL1_Type = _PAR_EL1; + r.bits[63 .. 0] = Slice(PAR_read().bits, 0, 64); + return(r) +} + +val PAR_write : PAR_Type -> unit + +function PAR_write value_name = { + let r : PAR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + PAR_S = r + } else { + PAR_NS = r + }; + return() +} + +val PAR_EL1_write : PAR_EL1_Type -> unit + +function PAR_EL1_write value_name = { + let r : PAR_EL1_Type = value_name; + PAR_write() = Mk_PAR_Type(SetSlice(64, PAR_read().bits, 0, Slice(r.bits, 0, 64))); + _PAR_EL1 = r; + return() +} + +val __IMPDEF_bit : string -> bits(1) + +function __IMPDEF_bit x = { + return(__UNKNOWN_bit()) +} + +val AArch64_EncodePAR : forall ('is_ATS1Ex : Bool). + (Regime, bool('is_ATS1Ex), AddressDescriptor) -> unit + +function AArch64_EncodePAR (regime, is_ATS1Ex, addrdesc) = { + PAR_EL1_write() = Mk_PAR_EL1_Type(Zeros(128)); + let paspace : PASpace = addrdesc.paddress.paspace; + if AArch64_isPARFormatD128(regime, is_ATS1Ex) then { + PAR_EL1_write() = [PAR_EL1_read() with D128 = 0b1] + } else { + PAR_EL1_write() = [PAR_EL1_read() with D128 = 0b0] + }; + if not_bool(IsFault(addrdesc)) then { + PAR_EL1_write() = [PAR_EL1_read() with F = 0b0]; + if HaveRME() then { + if regime == Regime_EL3 then { + match paspace { + PAS_Secure => { + { + __tmp : PAR_EL1_Type = PAR_EL1_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b00; + PAR_EL1_write() = __tmp + } + }, + PAS_NonSecure => { + { + __tmp : PAR_EL1_Type = PAR_EL1_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b01; + PAR_EL1_write() = __tmp + } + }, + PAS_Root => { + { + __tmp : PAR_EL1_Type = PAR_EL1_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b10; + PAR_EL1_write() = __tmp + } + }, + PAS_Realm => { + { + __tmp : PAR_EL1_Type = PAR_EL1_read(); + (__tmp[NSE] @ __tmp[NS]) = 0b11; + PAR_EL1_write() = __tmp + } + } + } + } else if SecurityStateForRegime(regime) == SS_Secure then { + PAR_EL1_write() = [PAR_EL1_read() with NSE = __UNKNOWN_bit()]; + PAR_EL1_write() = [PAR_EL1_read() with NS = if paspace == PAS_Secure then + 0b0 + else + 0b1] + } else if SecurityStateForRegime(regime) == SS_Realm then { + if regime == Regime_EL10 & is_ATS1Ex then { + PAR_EL1_write() = [PAR_EL1_read() with NSE = __UNKNOWN_bit()]; + PAR_EL1_write() = [PAR_EL1_read() with NS = __UNKNOWN_bit()] + } else { + PAR_EL1_write() = [PAR_EL1_read() with NSE = __UNKNOWN_bit()]; + PAR_EL1_write() = [PAR_EL1_read() with NS = if paspace == PAS_Realm then + 0b0 + else + 0b1] + } + } else { + PAR_EL1_write() = [PAR_EL1_read() with NSE = __UNKNOWN_bit()]; + PAR_EL1_write() = [PAR_EL1_read() with NS = __UNKNOWN_bit()] + } + } else { + PAR_EL1_write() = Mk_PAR_EL1_Type([PAR_EL1_read().bits with 11 .. 11 = 0b1]); + if SecurityStateForRegime(regime) == SS_Secure then { + PAR_EL1_write() = [PAR_EL1_read() with NS = if paspace == PAS_Secure then + 0b0 + else + 0b1] + } else { + PAR_EL1_write() = [PAR_EL1_read() with NS = __UNKNOWN_bit()] + } + }; + PAR_EL1_write() = [PAR_EL1_read() with SH = ReportedPARShareability(PAREncodeShareability(addrdesc.memattrs))]; + if PAR_EL1_read()[D128] == 0b1 then { + PAR_EL1_write() = Mk_PAR_EL1_Type([PAR_EL1_read().bits with 119 .. 76 = addrdesc.paddress.address[55 .. 12]]) + } else { + PAR_EL1_write() = Mk_PAR_EL1_Type([PAR_EL1_read().bits with 55 .. 12 = addrdesc.paddress.address[55 .. 12]]) + }; + PAR_EL1_write() = [PAR_EL1_read() with ATTR = ReportedPARAttrs(EncodePARAttrs(addrdesc.memattrs))]; + PAR_EL1_write() = Mk_PAR_EL1_Type([PAR_EL1_read().bits with 10 .. 10 = __IMPDEF_bit("Non-Faulting PAR")]) + } else { + PAR_EL1_write() = [PAR_EL1_read() with F = 0b1]; + PAR_EL1_write() = [PAR_EL1_read() with DirtyBit = if addrdesc.fault.dirtybit then + 0b1 + else + 0b0]; + PAR_EL1_write() = [PAR_EL1_read() with Overlay = if addrdesc.fault.overlay then + 0b1 + else + 0b0]; + PAR_EL1_write() = [PAR_EL1_read() with TopLevel = if addrdesc.fault.toplevel then + 0b1 + else + 0b0]; + PAR_EL1_write() = [PAR_EL1_read() with AssuredOnly = if addrdesc.fault.assuredonly then + 0b1 + else + 0b0]; + PAR_EL1_write() = [PAR_EL1_read() with FST = AArch64_PARFaultStatus(addrdesc.fault)]; + PAR_EL1_write() = [PAR_EL1_read() with PTW = if addrdesc.fault.s2fs1walk then + 0b1 + else + 0b0]; + PAR_EL1_write() = [PAR_EL1_read() with S = if addrdesc.fault.secondstage then + 0b1 + else + 0b0]; + PAR_EL1_write() = Mk_PAR_EL1_Type([PAR_EL1_read().bits with 11 .. 11 = 0b1]); + PAR_EL1_write() = Mk_PAR_EL1_Type([PAR_EL1_read().bits with 63 .. 48 = __IMPDEF_bits(16, "Faulting PAR")]) + }; + return() +} + +val AArch64_AT : (bits(64), TranslationStage, bits(2), ATAccess) -> unit + +function AArch64_AT (address, stage_in, el_in, ataccess) = { + stage : TranslationStage = stage_in; + el : bits(2) = el_in; + let effective_nse_ns : bits(2) = EffectiveSCR_EL3_NSE() @ EffectiveSCR_EL3_NS(); + if ((HaveRME() & PSTATE.EL == EL3) & effective_nse_ns == 0b10) & el != EL3 then { + throw(Error_Undefined()) + }; + if ((HCR_EL2[E2H] @ HCR_EL2[TGE]) == 0b11 & el == EL1) & stage == TranslationStage_1 then { + el = EL2 + }; + if (HaveEL(EL3) & stage == TranslationStage_12) & not_bool(EL2Enabled()) then { + stage = TranslationStage_1 + }; + let write : bool = ataccess == ATAccess_WritePAN | ataccess == ATAccess_Write; + let ss : SecurityState = SecurityStateAtEL(el); + let pan : bool = ataccess == ATAccess_ReadPAN | ataccess == ATAccess_WritePAN; + let accdesc : AccessDescriptor = CreateAccDescAT(ss, el, write, pan); + let aligned : bool = true; + fault : FaultRecord = NoFault__1(accdesc); + regime : Regime = undefined; + if stage == TranslationStage_12 then { + regime = Regime_EL10 + } else { + regime = TranslationRegime(el) + }; + addrdesc : AddressDescriptor = undefined; + if el == EL0 & ELUsingAArch32(EL1) | el != EL0 & ELUsingAArch32(el) then { + // Determine AArch32 translation info and announce translation start + let tsi = AArch32_GetTranslationStartInfo(regime, ss, accdesc, address[31 .. 0], 1); + start_translation(tsi); + // + if regime == Regime_EL2 | TTBCR_read()[EAE] == 0b1 then { + (fault, addrdesc) = AArch32_S1TranslateLD(fault, regime, address[31 .. 0], aligned, accdesc) + } else { + let (__tup_0 : FaultRecord, __tup_1 : AddressDescriptor, _) = AArch32_S1TranslateSD(fault, regime, address[31 .. 0], aligned, accdesc); + fault = __tup_0; + addrdesc = __tup_1 + } + } else { + // Determine AArch64 translation info and announce translation start + let tsi = AArch64_GetTranslationStartInfo(regime, ss, accdesc, address, 1); + start_translation(tsi); + // + (fault, addrdesc) = AArch64_S1Translate(fault, regime, address, aligned, accdesc) + }; + if stage == TranslationStage_12 & fault.statuscode == Fault_None then { + s1aarch64 : bool = undefined; + if (ELUsingAArch32(EL1) & regime == Regime_EL10) & EL2Enabled() then { + addrdesc.vaddress = ZeroExtend(address, 64); + (fault, addrdesc) = AArch32_S2Translate(fault, addrdesc, None(), aligned, accdesc) + } else if regime == Regime_EL10 & EL2Enabled() then { + let s1aarch64 : bool = true; + (fault, addrdesc) = AArch64_S2Translate(fault, addrdesc, s1aarch64, None(), aligned, accdesc) + } else () + }; + let is_ATS1Ex : bool = stage != TranslationStage_12; + if fault.statuscode != Fault_None then { + addrdesc = CreateFaultyAddressDescriptor(address, fault); + if (IsExternalAbort__1(fault) | PSTATE.EL == EL1 & fault.s2fs1walk) | (HaveRME() & fault.gpcf.gpf != GPCF_None) & (ReportAsGPCException(fault) | ((HCR_EL2[GPF] == 0b1 & PSTATE.EL == EL1) & (el == EL1 | el == EL0)) & is_ATS1Ex) then { + PAR_EL1_write() = Mk_PAR_EL1_Type(__UNKNOWN_bits(128)); + AArch64_Abort(address, addrdesc.fault) + }; + () + }; + let addrdesc = addrdesc; + // Announce result + end_translation(addrdesc); + // + AArch64_EncodePAR(regime, is_ATS1Ex, addrdesc); + return() +} + +bitfield CTILSR_Type : bits(32) = {nTT : 2..2, SLK : 1..1, SLI : 0..0} + +register CTILSR : CTILSR_Type + +bitfield EDLSR_Type : bits(32) = {nTT : 2..2, SLK : 1..1, SLI : 0..0} + +register EDLSR : EDLSR_Type + +bitfield PMLSR_Type : bits(32) = {nTT : 2..2, SLK : 1..1, SLI : 0..0} + +register PMLSR : PMLSR_Type + +type DBGDTRRX_EL0_Type = bits(64) + +register DBGDTRRX_EL0 : DBGDTRRX_EL0_Type + +type DBGDTRTX_EL0_Type = bits(64) + +register DBGDTRTX_EL0 : DBGDTRTX_EL0_Type + +bitfield DBGDTR_EL0_Type : bits(64) = {HighWord : 63..32, LowWord : 31..0} + +register _DBGDTR_EL0 : DBGDTR_EL0_Type + +val DBGDTR_EL0_read__1 : unit -> DBGDTR_EL0_Type + +function DBGDTR_EL0_read__1 () = { + r : DBGDTR_EL0_Type = _DBGDTR_EL0; + if __IMPDEF_boolean("read") then { + r.bits[63 .. 32] = Slice(DBGDTRTX_EL0, 0, 32) + } else { + if __IMPDEF_boolean("read") then { + r.bits[63 .. 32] = Slice(DBGDTRTX_EL0, 0, 32) + } else { + r.bits[63 .. 32] = Slice(DBGDTRRX_EL0, 0, 32) + } + }; + if __IMPDEF_boolean("read") then { + r.bits[31 .. 0] = Slice(DBGDTRRX_EL0, 0, 32) + } else { + if __IMPDEF_boolean("read") then { + r.bits[31 .. 0] = Slice(DBGDTRRX_EL0, 0, 32) + } else { + r.bits[31 .. 0] = Slice(DBGDTRTX_EL0, 0, 32) + } + }; + return(r) +} + +bitfield EDPRSR_Type : bits(32) = + { + EPMADE : 16..16, + EDADE : 14..14, + SDR : 11..11, + SPMAD : 10..10, + EPMAD : 9..9, + SDAD : 8..8, + EDAD : 7..7, + DLK : 6..6, + OSLK : 5..5, + HALTED : 4..4, + SR : 3..3, + R : 2..2, + SPD : 1..1, + PU : 0..0 + } + +register EDPRSR : EDPRSR_Type + +val ExecuteA64 : bits(32) -> unit + +val ExecuteT32__1 : bits(32) -> unit + +bitfield DBGDCCINT_Type : bits(32) = {RX : 30..30, TX : 29..29} + +bitfield MDCCINT_EL1_Type : bits(64) = {RX : 30..30, TX : 29..29} + +register MDCCINT_EL1 : MDCCINT_EL1_Type + +register _DBGDCCINT : DBGDCCINT_Type + +val DBGDCCINT_read : unit -> DBGDCCINT_Type + +function DBGDCCINT_read () = { + r : DBGDCCINT_Type = _DBGDCCINT; + r.bits[31 .. 0] = Slice(MDCCINT_EL1.bits, 0, 32); + return(r) +} + +val LR_write : bits(32) -> unit + +function LR_write value_name = { + R_set(14) = value_name; + return() +} + +val DCPSInstruction : bits(2) -> unit + +function DCPSInstruction target_el = { + from_32 : bool = undefined; + SynchronizeContext(); + handle_el : bits(2) = undefined; + match target_el { + ? if ? == EL1 => { + if PSTATE.EL == EL2 | PSTATE.EL == EL3 & not_bool(UsingAArch32()) then { + handle_el = PSTATE.EL + } else if EL2Enabled() & HCR_EL2[TGE] == 0b1 then { + throw(Error_Undefined()) + } else { + handle_el = EL1 + } + }, + ? if ? == EL2 => { + if not_bool(HaveEL(EL2)) then { + throw(Error_Undefined()) + } else if PSTATE.EL == EL3 & not_bool(UsingAArch32()) then { + handle_el = EL3 + } else if not_bool(IsSecureEL2Enabled()) & CurrentSecurityState() == SS_Secure then { + throw(Error_Undefined()) + } else { + handle_el = EL2 + } + }, + ? if ? == EL3 => { + if EDSCR_read()[SDD] == 0b1 | not_bool(HaveEL(EL3)) then { + throw(Error_Undefined()) + } else { + handle_el = EL3 + } + }, + _ => { + Unreachable() + } + }; + let from_secure : bool = CurrentSecurityState() == SS_Secure; + if ELUsingAArch32(handle_el) then { + if PSTATE.M == M32_Monitor then { + SCR[NS] = 0b0 + }; + assert(UsingAArch32()); + match handle_el { + ? if ? == EL1 => { + AArch32_WriteMode(M32_Svc); + if HavePANExt() & SCTLR_read__2()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + }; + () + }, + ? if ? == EL2 => { + AArch32_WriteMode(M32_Hyp) + }, + ? if ? == EL3 => { + AArch32_WriteMode(M32_Monitor); + if HavePANExt() then { + if not_bool(from_secure) then { + PSTATE.PAN = 0b0 + } else if SCTLR_read__2()[SPAN] == 0b0 then { + PSTATE.PAN = 0b1 + } else () + }; + () + }, + _ => () + }; + if handle_el == EL2 then { + ELR_hyp_write() = __UNKNOWN_bits(32); + HSR_write() = Mk_HSR_Type(__UNKNOWN_bits(32)) + } else { + LR_write() = __UNKNOWN_bits(32) + }; + SPSR_set(32) = __UNKNOWN_bits(32); + PSTATE.E = SCTLR_read__1()[EE]; + DLR_write() = __UNKNOWN_bits(32); + DSPSR_write() = Mk_DSPSR_Type(__UNKNOWN_bits(32)) + } else { + let from_32 : bool = UsingAArch32(); + if from_32 then { + AArch64_MaybeZeroRegisterUppers() + }; + if (from_32 & HaveSME()) & PSTATE.SM == 0b1 then { + ResetSVEState() + } else { + MaybeZeroSVEUppers(target_el) + }; + PSTATE.nRW = 0b0; + PSTATE.SP = 0b1; + PSTATE.EL = handle_el; + if HavePANExt() & (handle_el == EL1 & SCTLR_EL1[SPAN] == 0b0 | ((handle_el == EL2 & HCR_EL2[E2H] == 0b1) & HCR_EL2[TGE] == 0b1) & SCTLR_EL2[SPAN] == 0b0) then { + PSTATE.PAN = 0b1 + }; + ELR_set__1() = __UNKNOWN_bits(64); + SPSR_set(64) = __UNKNOWN_bits(64); + ESR_set__1() = Mk_ESRType(__UNKNOWN_bits(64)); + DLR_EL0 = __UNKNOWN_bits(64); + DSPSR_EL0 = Mk_DSPSR_EL0_Type(__UNKNOWN_bits(64)); + if HaveUAOExt() then { + PSTATE.UAO = 0b0 + }; + if HaveMTEExt() then { + PSTATE.TCO = 0b1 + }; + if HaveGCS() then { + PSTATE.EXLOCK = 0b0 + }; + () + }; + UpdateEDSCRFields(); + sync_errors : bool = HaveIESB() & SCTLR_read__1()[IESB] == 0b1; + if HaveDoubleFaultExt() & not_bool(UsingAArch32()) then { + sync_errors = sync_errors | (EffectiveEA() == 0b1 & SCR_EL3[NMEA] == 0b1) & PSTATE.EL == EL3 + }; + if not_bool(ConstrainUnpredictableBool(Unpredictable_IESBinDebug)) then { + sync_errors = false + }; + if sync_errors then { + SynchronizeErrors() + }; + return() +} + +val DebugRestorePSR : unit -> unit + +function DebugRestorePSR () = { + if UsingAArch32() then { + let spsr : bits(32) = SPSR_read(32); + SetPSTATEFromPSR(spsr); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V @ PSTATE.Q @ PSTATE.GE @ PSTATE.SS @ PSTATE.A @ PSTATE.I @ PSTATE.F) = __UNKNOWN_bits(13); + PSTATE.IT = 0b00000000; + PSTATE.T = 0b1; + DLR_write() = __UNKNOWN_bits(32); + DSPSR_write() = Mk_DSPSR_Type(__UNKNOWN_bits(32)) + } else { + let spsr : bits(64) = SPSR_read(64); + SetPSTATEFromPSR(spsr); + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V @ PSTATE.SS @ PSTATE.D @ PSTATE.A @ PSTATE.I @ PSTATE.F) = __UNKNOWN_bits(9); + DLR_EL0 = __UNKNOWN_bits(64); + DSPSR_EL0 = Mk_DSPSR_EL0_Type(__UNKNOWN_bits(64)) + }; + UpdateEDSCRFields() +} + +val DRPSInstruction : unit -> unit + +function DRPSInstruction () = { + SynchronizeContext(); + sync_errors : bool = HaveIESB() & SCTLR_read__1()[IESB] == 0b1; + if HaveDoubleFaultExt() & not_bool(UsingAArch32()) then { + sync_errors = sync_errors | (EffectiveEA() == 0b1 & SCR_EL3[NMEA] == 0b1) & PSTATE.EL == EL3 + }; + if not_bool(ConstrainUnpredictableBool(Unpredictable_IESBinDebug)) then { + sync_errors = false + }; + if sync_errors then { + SynchronizeErrors() + }; + DebugRestorePSR(); + return() +} + +val DLR_read : unit -> DLR_Type + +function DLR_read () = { + r : DLR_Type = _DLR; + r[31 .. 0] = Slice(DLR_EL0, 0, 32); + return(r) +} + +val DSPSR_read : unit -> DSPSR_Type + +function DSPSR_read () = { + r : DSPSR_Type = _DSPSR; + r.bits[31 .. 0] = Slice(DSPSR_EL0.bits, 0, 32); + return(r) +} + +val DSPSR2_read : unit -> DSPSR2_Type + +function DSPSR2_read () = { + r : DSPSR2_Type = _DSPSR2; + r.bits[31 .. 0] = Slice(DSPSR_EL0.bits, 32, 32); + return(r) +} + +val CheckPendingResetCatch : unit -> unit + +function CheckPendingResetCatch () = { + if HaltingAllowed() & EDESR[RC] == 0b1 then { + let is_async : bool = true; + Halt__1(DebugHalt_ResetCatch, is_async) + }; + () +} + +bitfield CTIDEVCTL_Type : bits(32) = {RCE : 1..1, OSUCE : 0..0} + +register CTIDEVCTL : CTIDEVCTL_Type + +val CheckResetCatch : unit -> unit + +function CheckResetCatch () = { + if HaveDoPD() & CTIDEVCTL[RCE] == 0b1 | not_bool(HaveDoPD()) & EDECR[RCE] == 0b1 then { + EDESR[RC] = 0b1; + if HaltingAllowed() then { + Halt(DebugHalt_ResetCatch) + }; + () + }; + () +} + +val CheckPendingOSUnlockCatch : unit -> unit + +function CheckPendingOSUnlockCatch () = { + if HaltingAllowed() & EDESR[OSUC] == 0b1 then { + let is_async : bool = true; + Halt__1(DebugHalt_OSUnlockCatch, is_async) + }; + () +} + +val CheckOSUnlockCatch : unit -> unit + +function CheckOSUnlockCatch () = { + if HaveDoPD() & CTIDEVCTL[OSUCE] == 0b1 | not_bool(HaveDoPD()) & EDECR[OSUCE] == 0b1 then { + if not_bool(Halted()) then { + EDESR[OSUC] = 0b1 + }; + () + }; + () +} + +val CheckPendingExceptionCatch : forall ('is_async : Bool). + bool('is_async) -> unit + +function CheckPendingExceptionCatch is_async = { + if (Havev8p8Debug() & HaltingAllowed()) & EDESR[EC] == 0b1 then { + Halt__1(DebugHalt_ExceptionCatch, is_async) + }; + () +} + +val CheckSoftwareStep : unit -> unit + +function CheckSoftwareStep () = { + let step_enabled : bool = (not_bool(ELUsingAArch32(DebugTarget())) & AArch64_GenerateDebugExceptions()) & MDSCR_EL1[SS] == 0b1; + if step_enabled & PSTATE.SS == 0b1 then { + __InstructionStep = true + }; + if not_bool(step_enabled) then { + __InstructionStep = false + }; + if step_enabled & PSTATE.SS == 0b0 then { + AArch64_SoftwareStepException() + }; + () +} + +bitfield EDVIDSR_Type : bits(32) = + { + NS : 31..31, + E2 : 30..30, + E3 : 29..29, + HV : 28..28, + VMID : (15..8 @ 7..0), + CONTEXTIDR_EL2 : 31..0 + } + +register EDVIDSR : EDVIDSR_Type + +bitfield PMPCSR_Type : bits(64) = + { + NS : 63..63, + EL : 62..61, + T : 60..60, + NSE : 59..59, + PCSample : (55..32 @ 31..0) + } + +register PMPCSR : PMPCSR_Type + +bitfield PMVIDSR_Type : bits(32) = {VMID : (15..8 @ 7..0)} + +register PMVIDSR : PMVIDSR_Type + +bitfield HTRFCR_Type : bits(32) = + {TS : 6..5, CX : 3..3, E2TRE : 1..1, E0HTRE : 0..0} + +bitfield TRFCR_EL2_Type : bits(64) = + {TS : 6..5, CX : 3..3, E2TRE : 1..1, E0HTRE : 0..0} + +register TRFCR_EL2 : TRFCR_EL2_Type + +register _HTRFCR : HTRFCR_Type + +val HTRFCR_read : unit -> HTRFCR_Type + +function HTRFCR_read () = { + r : HTRFCR_Type = _HTRFCR; + r.bits[31 .. 0] = Slice(TRFCR_EL2.bits, 0, 32); + return(r) +} + +bitfield TRFCR_EL1_Type : bits(64) = {TS : 6..5, E1TRE : 1..1, E0TRE : 0..0} + +register TRFCR_EL1 : TRFCR_EL1_Type + +bitfield TRFCR_Type : bits(32) = {TS : 6..5, E1TRE : 1..1, E0TRE : 0..0} + +register _TRFCR : TRFCR_Type + +val TRFCR_read : unit -> TRFCR_Type + +function TRFCR_read () = { + r : TRFCR_Type = _TRFCR; + r.bits[31 .. 0] = Slice(TRFCR_EL1.bits, 0, 32); + return(r) +} + +val TraceSynchronizationBarrier : unit -> unit + +function TraceSynchronizationBarrier () = { + return() +} + +val AArch32_ReportedInnerAttrs : bits(3) -> bits(3) + +val AArch32_ReportedOuterAttrs : bits(2) -> bits(2) + +val AArch64_CheckNVCondsIfCurrentEL : forall 'crm 'crn 'op0 'op1 'op2. + (int('op0), int('op1), int('crn), int('crm), int('op2)) -> bool + +val DC_CIPAPA : bits(64) -> unit + +val DC_CIGDPAPA : bits(64) -> unit + +val BPIALLIS : unit -> unit + +val BPIALL : unit -> unit + +val BPIMVA : bits(32) -> unit + +val CP15DMB : unit -> unit + +val CP15DSB : unit -> unit + +val CP15ISB : unit -> unit + +val UnallocatedA32_Instruction : bits(32) -> unit + +val UnallocatedT32_32_Instruction : bits(32) -> unit + +val UnallocatedT32_16_Instruction : bits(16) -> unit + +val AArch64_PendingUnmaskedPhysicalInterrupts : bits(3) -> (bool, bool, bool) + +val AArch64_PendingUnmaskedVirtualInterrupts : bits(3) -> (bool, bool, bool) + +val AArch32_PendingUnmaskedPhysicalInterrupts : unit -> (bool, bool, bool) + +val AArch32_PendingUnmaskedVirtualInterrupts : unit -> (bool, bool, bool) + +val TakePendingInterrupts : InterruptReq -> bool + +val __UpdateSystemCounter : unit -> unit + +register __CTIBase : bits(56) = UInt(0x22020000)[56 - 1 .. 0] + +register __CNTControlBase : bits(56) = UInt(0x16200000)[56 - 1 .. 0] + +register __ExtDebugBase : bits(56) = UInt(0x22010000)[56 - 1 .. 0] + +register __GICCPUInterfaceBase : bits(56) = UInt(0x13082000)[56 - 1 .. 0] + +register __GICDistBase : bits(56) = UInt(0x2c010000)[56 - 1 .. 0] + +register __GICITSControlBase : bits(56) = UInt(0x2c120000)[56 - 1 .. 0] + +register __PMUBase : bits(56) = UInt(0x22030000)[56 - 1 .. 0] + +val ExecuteA32 : bits(32) -> unit + +val ExecuteT16 : bits(16) -> unit + +val __SetThisInstrDetails : (__InstrEnc, bits(32), bits(4)) -> unit + +val __FetchInstr : bits(64) -> (__InstrEnc, bits(32)) + +val __DefaultCond : __InstrEnc -> bits(4) + +val __DecodeExecute : (__InstrEnc, bits(32)) -> unit + +val __InstructionExecute : unit -> unit + +val __TopLevel : unit -> unit + +val __CycleEnd : unit -> unit + +register __syncAbortOnReadNormCache : bool = true + +register __syncAbortOnReadNormNonCache : bool = true + +register __syncAbortOnDeviceRead : bool = true + +register __syncAbortOnSoRead : bool = true + +register __syncAbortOnSoWrite : bool = true + +register __syncAbortOnPrefetch : bool = true + +register __syncAbortOnTTWCache : bool = true + +register __syncAbortOnTTWNonCache : bool = true + +register __syncAbortOnWriteNormCache : bool = false + +register __syncAbortOnWriteNormNonCache : bool = false + +register __syncAbortOnDeviceWrite : bool = false + +val SetResetVector : bits(64) -> unit + +val EncodePARange : unit -> bits(4) + +val EncodeVARange : unit -> bits(4) + +val ResetControlRegisters : forall ('cold : Bool). bool('cold) -> unit + +val AArch32_ResetControlRegisters : forall ('cold_reset : Bool). + bool('cold_reset) -> unit + +val TakeReset : forall ('cold : Bool). bool('cold) -> unit + +val AArch64_IMPDEFResets : unit -> unit + +val AArch32_IMPDEFResets : unit -> unit + +val AArch64_SetLSInstructionSyndrome : forall 'Rt ('acq_rel : Bool) ('sign_extend : Bool) ('sixty_four : Bool) 'size. + (int('size), bool('sign_extend), int('Rt), bool('sixty_four), bool('acq_rel)) -> unit + +val AArch32_SetLSInstructionSyndrome : forall 'Rt ('acq_rel : Bool) ('sign_extend : Bool) 'size. + (int('size), bool('sign_extend), int('Rt), bool('acq_rel)) -> unit + +val SetIss2 : bits(5) -> unit + +val SetLoadStoreType : bits(2) -> unit + +val Hint_PreloadDataForWrite : bits(32) -> unit + +val Hint_PreloadData : bits(32) -> unit + +val Hint_PreloadInstr : bits(32) -> unit + +val AArch32_MarkExclusiveVA : forall 'processorid 'size. + (bits(32), int('processorid), int('size)) -> unit + +val AArch32_IsExclusiveVA : forall 'processorid 'size. + (bits(32), int('processorid), int('size)) -> bool + +register __supported_va_size : int = 56 + +register __unpred_tsize_aborts : bool = true + +register __dczid_log2_block_size : int = UInt(0x8) + +register __gmid_log2_block_size : int = UInt(0x4) + +register __num_ctx_breakpoints : int = NUM_BREAKPOINTS + +register __ignore_rvbar_in_aarch32 : bool = false + +register __trickbox_enabled : bool = false + +register __mops_forward_copy : bool = true + +register __CNTbase_frequency : bits(32) = 0x05F5E100 + +register __DBG_ROM_ADDR : bits(56) = UInt(0x22000000)[56 - 1 .. 0] + +register __exclusive_granule_size : bits(4) = 0b0100 + +register __mpam_has_altsp : bool = true + +register CFG_RMR_AA64 : bits(1) = 0b1 + +register ZCR_EL3_LEN_VALUE : int = negate(1) + +register CPTR_EL3_EZ_VALUE : int = negate(1) + +register CPTR_EL3_ESM_VALUE : int = negate(1) + +register SMCR_EL3_LEN_VALUE : int = negate(1) + +register __rme_l0gptsz : bits(4) = Zeros(4) + +register __has_spe_pseudo_cycles : bool = false + +register HEAP_BASE : bits(64) = ZeroExtend(0x00000000, 64) + +register HEAP_LIMIT : bits(64) = ZeroExtend(0x0f000000, 64) + +register STACK_BASE : bits(64) = ZeroExtend(0x10000000, 64) + +register STACK_LIMIT : bits(64) = ZeroExtend(0x0f000000, 64) + +register __mecid_width : bits(4) = 0x0 + +register CFG_MPIDR : bits(32) = 0x80000000 + +val __ConfigureV81 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV81 enabled = { + v8Ap1_IMPLEMENTED = enabled +} + +val __ConfigureV82 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV82 enabled = { + v8Ap2_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV81(enabled) + }; + () +} + +val __ConfigureV83 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV83 enabled = { + v8Ap3_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV82(enabled) + }; + () +} + +val __ConfigureV84 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV84 enabled = { + v8Ap4_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV83(enabled) + }; + () +} + +val __ConfigureV85 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV85 enabled = { + v8Ap5_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV84(enabled) + }; + () +} + +val __ConfigureV86 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV86 enabled = { + v8Ap6_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV85(enabled) + }; + () +} + +val __ConfigureV87 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV87 enabled = { + v8Ap7_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV86(enabled) + }; + () +} + +val __ConfigureV88 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV88 enabled = { + v8Ap8_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV87(enabled) + }; + () +} + +val __ConfigureV89 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV89 enabled = { + v8Ap9_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV88(enabled) + }; + () +} + +val __ConfigureV90 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV90 enabled = { + v9Ap0_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV85(enabled) + }; + () +} + +val __ConfigureV91 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV91 enabled = { + v9Ap1_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV90(enabled); + __ConfigureV86(enabled) + }; + () +} + +val __ConfigureV92 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV92 enabled = { + v9Ap2_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV91(enabled); + __ConfigureV87(enabled) + }; + () +} + +val __ConfigureV93 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV93 enabled = { + v9Ap3_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV92(enabled); + __ConfigureV88(enabled) + }; + () +} + +val __ConfigureV94 : forall ('enabled : Bool). bool('enabled) -> unit + +function __ConfigureV94 enabled = { + v9Ap4_IMPLEMENTED = enabled; + if enabled then { + __ConfigureV93(enabled); + __ConfigureV89(enabled) + }; + () +} + +val decode_max_smeveclen : forall 'value_name. int('value_name) -> int + +function decode_max_smeveclen value_name = { + svl : int = (value_name >> 1); + bitpos : {'n, 'n >= 0. int('n)} = 0; + while svl != 0 do { + svl = (svl >> 1); + bitpos = bitpos + 1 + }; + if value_name == 0 | bitpos > 4 then { + bitpos = 2 + }; + let 'bitpos = bitpos; + let 'max_svl = 128 * pow2(bitpos); + return(max_svl) +} + +val decode_max_sveveclen : forall 'value_name. int('value_name) -> int + +function decode_max_sveveclen value_name = { + max_vl : int = value_name * 64; + if max_vl > 2048 then { + max_vl = 2048 + }; + let 'max_vl = max_vl; + if not_bool(IsPow2(max_vl)) then { + return(FloorPow2(max_vl)) + }; + return(max_vl) +} + +val AArch32_ReservedBreakpointType : forall 'n. + (int('n), bits(4)) -> (Constraint, bits(4)) + +function AArch32_ReservedBreakpointType (n, bt_in) = { + bt : bits(4) = bt_in; + reserved : bool = false; + let context_aware : bool = n >= NumBreakpointsImplemented() - NumContextAwareBreakpointsImplemented(); + if (match bt { + [bitzero, bitone, bitzero, _] => true, + _ => false + }) : bool & HaltOnBreakpointOrWatchpoint() then { + reserved = true + }; + if not_bool((match bt { + [bitzero, _, bitzero, _] => true, + _ => false + }) : bool) & not_bool(context_aware) then { + reserved = true + }; + if (match bt { + [bitone, _, _, _] => true, + _ => false + }) : bool & not_bool(HaveEL(EL2)) then { + reserved = true + }; + if ((match bt { + [bitzero, bitone, bitone, _] => true, + [bitone, bitone, _, _] => true, + _ => false + }) : bool & not_bool(HaveVirtHostExt())) & not_bool(HaveV82Debug()) then { + reserved = true + }; + if reserved then { + c : Constraint = undefined; + (c, bt) = ConstrainUnpredictableBits(Unpredictable_RESBPTYPE, 4); + assert(c == Constraint_DISABLED | c == Constraint_UNKNOWN); + if c == Constraint_DISABLED then { + return((c, __UNKNOWN_bits(4))) + }; + () + }; + return((Constraint_NONE, bt)) +} + +bitfield DBGBCR_Type : bits(32) = + { + BT : 23..20, + LBN : 19..16, + SSC : 15..14, + HMC : 13..13, + BAS : 8..5, + PMC : 2..1, + E : 0..0 + } + +register _DBGBCR : vector(16, DBGBCR_Type) + +val DBGBCR_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> DBGBCR_Type + +function DBGBCR_read n = { + r : DBGBCR_Type = _DBGBCR[n]; + r.bits[31 .. 0] = Slice(DBGBCR_EL1[n].bits, 0, 32); + return(r) +} + +bitfield DBGBVR_Type : bits(32) = {VA : 31..2, ContextID : 31..0} + +register _DBGBVR : vector(16, DBGBVR_Type) + +val DBGBVR_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> DBGBVR_Type + +function DBGBVR_read n = { + r : DBGBVR_Type = _DBGBVR[n]; + r.bits[31 .. 0] = Slice(DBGBVR_EL1[n].bits, 0, 32); + return(r) +} + +bitfield DBGBXVR_Type : bits(32) = {VMID : (15..8 @ 7..0), ContextID2 : 31..0} + +register _DBGBXVR : vector(16, DBGBXVR_Type) + +val DBGBXVR_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> DBGBXVR_Type + +function DBGBXVR_read n = { + r : DBGBXVR_Type = _DBGBXVR[n]; + r.bits[31 .. 0] = Slice(DBGBVR_EL1[n].bits, 32, 32); + return(r) +} + +val AArch32_BreakpointValueMatch : forall ('linked_to : Bool) 'n_in. + (int('n_in), bits(32), bool('linked_to)) -> (bool, bool) + +function AArch32_BreakpointValueMatch (n_in, vaddress, linked_to) = { + n : int = n_in; + c : Constraint = undefined; + if n >= NumBreakpointsImplemented() then { + (c, n) = ConstrainUnpredictableInteger(0, NumBreakpointsImplemented() - 1, Unpredictable_BPNOTIMPL); + assert(c == Constraint_DISABLED | c == Constraint_UNKNOWN); + if c == Constraint_DISABLED then { + return((false, false)) + }; + () + }; + let 'n = n; + assert(constraint((0 <= 'n & 'n < 16))); + if DBGBCR_read(n)[E] == 0b0 then { + return((false, false)) + }; + dbgtype : bits(4) = DBGBCR_read(n)[BT]; + (c, dbgtype) = AArch32_ReservedBreakpointType(n, dbgtype); + if c == Constraint_DISABLED then { + return((false, false)) + }; + let match_addr : bool = (match dbgtype { + [bitzero, _, bitzero, _] => true, + _ => false + }) : bool; + let mismatch : bool = (match dbgtype { + [bitzero, bitone, bitzero, _] => true, + _ => false + }) : bool; + let match_vmid : bool = (match dbgtype { + [bitone, bitzero, _, _] => true, + _ => false + }) : bool; + let match_cid1 : bool = (match dbgtype { + [_, _, bitone, _] => true, + _ => false + }) : bool; + let match_cid2 : bool = (match dbgtype { + [bitone, bitone, _, _] => true, + _ => false + }) : bool; + let linking_enabled : bool = (match dbgtype { + [_, _, _, bitone] => true, + _ => false + }) : bool; + if linked_to & not_bool(linking_enabled) then { + if not_bool(ConstrainUnpredictableBool(Unpredictable_BPLINKINGDISABLED)) then { + return((false, false)) + }; + () + }; + if (not_bool(linked_to) & linking_enabled) & not_bool(match_addr) then { + return((false, false)) + }; + bvr_match : bool = false; + bxvr_match : bool = false; + if match_addr then { + let 'byte = UInt(vaddress[1 .. 0]); + assert(byte == 0 | byte == 2); + let byte_select_match : bool = [DBGBCR_read(n)[BAS][byte]] == 0b1; + let 'top = 31; + bvr_match = vaddress[top .. 2] == DBGBVR_read(n).bits[top .. 2] & byte_select_match + } else if match_cid1 then { + bvr_match = PSTATE.EL != EL2 & CONTEXTIDR_read().bits == DBGBVR_read(n).bits[31 .. 0] + } else (); + if match_vmid then { + vmid : bits(16) = undefined; + bvr_vmid : bits(16) = undefined; + if ELUsingAArch32(EL2) then { + vmid = ZeroExtend(VTTBR[VMID], 16); + bvr_vmid = ZeroExtend(DBGBXVR_read(n).bits[7 .. 0], 16) + } else if not_bool(Have16bitVMID()) | VTCR_EL2[VS] == 0b0 then { + vmid = ZeroExtend(VTTBR_EL2_read()[VMID][7 .. 0], 16); + bvr_vmid = ZeroExtend(DBGBXVR_read(n).bits[7 .. 0], 16) + } else { + vmid = VTTBR_EL2_read()[VMID]; + bvr_vmid = DBGBXVR_read(n).bits[15 .. 0] + }; + bxvr_match = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & vmid == bvr_vmid + } else if match_cid2 then { + bxvr_match = ((PSTATE.EL != EL3 & EL2Enabled()) & not_bool(ELUsingAArch32(EL2))) & DBGBXVR_read(n).bits[31 .. 0] == CONTEXTIDR_EL2.bits[31 .. 0] + } else (); + let bvr_match_valid : bool = match_addr | match_cid1; + let bxvr_match_valid : bool = match_vmid | match_cid2; + let val_match : bool = (not_bool(bxvr_match_valid) | bxvr_match) & (not_bool(bvr_match_valid) | bvr_match); + return((val_match & not_bool(mismatch), not_bool(val_match) & mismatch)) +} + +val AArch32_StateMatch : forall ('isbreakpnt : Bool) ('linked_in : Bool) 'linked_n_in. + (bits(2), bits(1), bits(2), bool('linked_in), int('linked_n_in), bool('isbreakpnt), AccessDescriptor) -> bool + +function AArch32_StateMatch (ssc_in, hmc_in, pxc_in, linked_in, linked_n_in, isbreakpnt, accdesc) = { + first_ctx_cmp : int = undefined; + last_ctx_cmp : int = undefined; + linked_to : bool = undefined; + vaddress : bits(32) = undefined; + hmc : bits(1) = hmc_in; + ssc : bits(2) = ssc_in; + pxc : bits(2) = pxc_in; + linked : bool = linked_in; + linked_n : int = linked_n_in; + c : Constraint = undefined; + let (__tup_0 : Constraint, __tup_1 : bits(2), _, __tup_3 : bits(1), __tup_4 : bits(2)) = + CheckValidStateMatch(ssc, 0b0, hmc, pxc, isbreakpnt) + in + { + c = __tup_0; + ssc = __tup_1; + hmc = __tup_3; + pxc = __tup_4 + }; + if c == Constraint_DISABLED then { + return(false) + }; + let pl2_match : bool = HaveEL(EL2) & (hmc == 0b1 & (ssc @ pxc) != 0b1000 | ssc == 0b11); + let pl1_match : bool = [pxc[0]] == 0b1; + let pl0_match : bool = [pxc[1]] == 0b1; + let ssu_match : bool = ((isbreakpnt & hmc == 0b0) & pxc == 0b00) & ssc != 0b11; + priv_match : bool = undefined; + if ssu_match then { + priv_match = PSTATE.M == M32_User | PSTATE.M == M32_Svc | PSTATE.M == M32_System + } else { + match accdesc.el { + ? if ? == EL3 => { + priv_match = pl1_match + }, + ? if ? == EL2 => { + priv_match = pl2_match + }, + ? if ? == EL1 => { + priv_match = pl1_match + }, + ? if ? == EL0 => { + priv_match = pl0_match + }, + _ => () + } + }; + ss_match : bool = undefined; + match ssc { + 0b00 => { + ss_match = true + }, + 0b01 => { + ss_match = accdesc.ss == SS_NonSecure + }, + 0b10 => { + ss_match = accdesc.ss == SS_Secure + }, + 0b11 => { + ss_match = hmc == 0b1 | accdesc.ss == SS_Secure + }, + _ => () + }; + linked_match : bool = false; + if linked then { + if not_bool(IsContextMatchingBreakpoint(linked_n)) then { + (first_ctx_cmp, last_ctx_cmp) = ContextMatchingBreakpointRange(); + let 'last_ctx_cmp = last_ctx_cmp; + let 'first_ctx_cmp = first_ctx_cmp; + (c, linked_n) = ConstrainUnpredictableInteger(first_ctx_cmp, last_ctx_cmp, Unpredictable_BPNOTCTXCMP); + assert(c == Constraint_DISABLED | c == Constraint_NONE | c == Constraint_UNKNOWN); + match c { + Constraint_DISABLED => { + return(false) + }, + Constraint_NONE => { + linked = false + }, + _ => () + } + }; + let 'linked_n = linked_n; + let vaddress : bits(32) = __UNKNOWN_bits(32); + let linked_to : bool = true; + let (__tup_0 : bool, _) = AArch32_BreakpointValueMatch(linked_n, vaddress, linked_to); + linked_match = __tup_0 + }; + return((priv_match & ss_match) & (not_bool(linked) | linked_match)) +} + +val AArch32_BreakpointMatch : forall 'n 'size, (0 <= 'n & 'n < 16). + (int('n), bits(32), AccessDescriptor, int('size)) -> (bool, bool) + +function AArch32_BreakpointMatch (n, vaddress, accdesc, size) = { + match_i : bool = undefined; + mismatch_i : bool = undefined; + value_match_name : bool = undefined; + value_mismatch_name : bool = undefined; + assert(ELUsingAArch32(S1TranslationRegime__1())); + assert(n < NumBreakpointsImplemented()); + let enabled : bool = DBGBCR_read(n)[E] == 0b1; + let isbreakpnt : bool = true; + let linked : bool = (match DBGBCR_read(n)[BT] { + [bitzero, _, bitzero, bitone] => true, + _ => false + }) : bool; + let linked_to : bool = false; + let 'linked_n = UInt(DBGBCR_read(n)[LBN]); + let state_match : bool = AArch32_StateMatch(DBGBCR_read(n)[SSC], DBGBCR_read(n)[HMC], DBGBCR_read(n)[PMC], linked, linked_n, isbreakpnt, accdesc); + (value_match_name, value_mismatch_name) = AArch32_BreakpointValueMatch(n, vaddress, linked_to); + if size == 4 then { + (match_i, mismatch_i) = AArch32_BreakpointValueMatch(n, vaddress + 2, linked_to); + if not_bool(value_match_name) & match_i then { + value_match_name = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF) + }; + if value_mismatch_name & not_bool(mismatch_i) then { + value_mismatch_name = ConstrainUnpredictableBool(Unpredictable_BPMISMATCHHALF) + }; + () + }; + if [vaddress[1]] == 0b1 & DBGBCR_read(n)[BAS] == 0b1111 then { + if value_match_name then { + value_match_name = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF) + }; + if not_bool(value_mismatch_name) then { + value_mismatch_name = ConstrainUnpredictableBool(Unpredictable_BPMISMATCHHALF) + }; + () + }; + let val_match : bool = (value_match_name & state_match) & enabled; + let mismatch : bool = (value_mismatch_name & state_match) & enabled; + return((val_match, mismatch)) +} + +val AArch32_CheckBreakpoint : forall 'size. + (FaultRecord, bits(32), AccessDescriptor, int('size)) -> FaultRecord + +function AArch32_CheckBreakpoint (fault_in, vaddress, accdesc, size) = { + match_i : bool = undefined; + mismatch_i : bool = undefined; + reason : bits(6) = undefined; + assert(ELUsingAArch32(S1TranslationRegime__1())); + assert(size == 2 | size == 4); + fault : FaultRecord = fault_in; + val_match : bool = false; + mismatch : bool = false; + foreach (i from 0 to (NumBreakpointsImplemented() - 1) by 1 in inc) { + assert(constraint(('loop_i < 16 | not('size in {2, 4})))); + (match_i, mismatch_i) = AArch32_BreakpointMatch(i, vaddress, accdesc, size); + val_match = val_match | match_i; + mismatch = mismatch | mismatch_i + }; + if val_match & HaltOnBreakpointOrWatchpoint() then { + let reason : bits(6) = DebugHalt_Breakpoint; + Halt(reason) + } else if val_match | mismatch then { + fault.statuscode = Fault_Debug; + fault.debugmoe = DebugException_Breakpoint + } else (); + return(fault) +} + +bitfield DBGVCR32_EL2_Type : bits(64) = + { + NSF : 31..31, + NSI : 30..30, + NSD : 28..28, + NSP : 27..27, + NSS : 26..26, + NSU : 25..25, + F : 7..7, + SF : 7..7, + I : 6..6, + SI : 6..6, + D : 4..4, + SD : 4..4, + P : 3..3, + SP : 3..3, + S : 2..2, + SS : 2..2, + U : 1..1, + SU : 1..1 + } + +register DBGVCR32_EL2 : DBGVCR32_EL2_Type + +bitfield DBGVCR_Type : bits(32) = + { + NSF : 31..31, + NSI : 30..30, + NSD : 28..28, + NSP : 27..27, + NSS : 26..26, + NSU : 25..25, + MF : 15..15, + MI : 14..14, + MD : 12..12, + MP : 11..11, + MS : 10..10, + F : 7..7, + SF : 7..7, + I : 6..6, + SI : 6..6, + D : 4..4, + SD : 4..4, + P : 3..3, + SP : 3..3, + S : 2..2, + SS : 2..2, + U : 1..1, + SU : 1..1 + } + +register _DBGVCR : DBGVCR_Type + +val DBGVCR_read : unit -> DBGVCR_Type + +function DBGVCR_read () = { + r : DBGVCR_Type = _DBGVCR; + r.bits[31 .. 0] = Slice(DBGVCR32_EL2.bits, 0, 32); + return(r) +} + +val AArch32_VCRMatch : bits(32) -> bool + +function AArch32_VCRMatch vaddress = { + match_word : bits(32) = undefined; + ss : SecurityState = undefined; + val_match : bool = undefined; + if (UsingAArch32() & ELUsingAArch32(EL1)) & PSTATE.EL != EL2 then { + match_word : bits(32) = Zeros(32); + let ss : SecurityState = CurrentSecurityState(); + if vaddress[31 .. 5] == ExcVectorBase()[31 .. 5] then { + if HaveEL(EL3) & ss == SS_NonSecure then { + match_word[UInt(vaddress[4 .. 2]) + 24] = Bit(0b1) + } else { + match_word[UInt(vaddress[4 .. 2]) + 0] = Bit(0b1) + } + }; + if ((HaveEL(EL3) & ELUsingAArch32(EL3)) & vaddress[31 .. 5] == MVBAR.bits[31 .. 5]) & ss == SS_Secure then { + match_word[UInt(vaddress[4 .. 2]) + 8] = Bit(0b1) + }; + mask : bits(32) = undefined; + if not_bool(HaveEL(EL3)) then { + mask = ((0b00000000 @ 0b00000000) @ 0b00000000) @ 0b11011110 + } else if not_bool(ELUsingAArch32(EL3)) then { + mask = ((0b11011110 @ 0b00000000) @ 0b00000000) @ 0b11011110 + } else { + mask = ((0b11011110 @ 0b00000000) @ 0b11011100) @ 0b11011110 + }; + let match_word : bits(32) = (match_word & DBGVCR_read().bits) & mask; + val_match = not_bool(IsZero(match_word)); + if not_bool(IsZero(match_word[28 .. 27] @ (match_word[12 .. 11] @ match_word[4 .. 3]))) & DebugTarget() == PSTATE.EL then { + val_match = ConstrainUnpredictableBool(Unpredictable_VCMATCHDAPA) + }; + if not_bool(IsZero(vaddress[1 .. 0])) & val_match then { + val_match = ConstrainUnpredictableBool(Unpredictable_VCMATCHHALF) + }; + () + } else { + val_match = false + }; + return(val_match) +} + +val AArch32_CheckVectorCatch : forall 'size. + (FaultRecord, bits(32), int('size)) -> FaultRecord + +function AArch32_CheckVectorCatch (fault_in, vaddress, size) = { + assert(ELUsingAArch32(S1TranslationRegime__1())); + fault : FaultRecord = fault_in; + val_match : bool = AArch32_VCRMatch(vaddress); + if (size == 4 & not_bool(val_match)) & AArch32_VCRMatch(vaddress + 2) then { + val_match = ConstrainUnpredictableBool(Unpredictable_VCMATCHHALF) + }; + if val_match then { + fault.statuscode = Fault_Debug; + fault.debugmoe = DebugException_VectorCatch + }; + return(fault) +} + +bitfield DBGWCR_Type : bits(32) = + { + MASK : 28..24, + WT : 20..20, + LBN : 19..16, + SSC : 15..14, + HMC : 13..13, + BAS : 12..5, + LSC : 4..3, + PAC : 2..1, + E : 0..0 + } + +register _DBGWCR : vector(16, DBGWCR_Type) + +val DBGWCR_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> DBGWCR_Type + +function DBGWCR_read n = { + r : DBGWCR_Type = _DBGWCR[n]; + r.bits[31 .. 0] = Slice(DBGWCR_EL1[n].bits, 0, 32); + return(r) +} + +bitfield DBGWVR_Type : bits(32) = {VA : 31..2} + +register _DBGWVR : vector(16, DBGWVR_Type) + +val DBGWVR_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> DBGWVR_Type + +function DBGWVR_read n = { + r : DBGWVR_Type = _DBGWVR[n]; + r.bits[31 .. 0] = Slice(DBGWVR_EL1[n].bits, 0, 32); + return(r) +} + +val AArch32_WatchpointByteMatch : forall 'n, (0 <= 'n & 'n < 16). + (int('n), bits(32)) -> bool + +function AArch32_WatchpointByteMatch (n, vaddress) = { + LSB : bits(8) = undefined; + MSB : bits(8) = undefined; + let 'top = 31; + bottom : {2, 3} = if [DBGWVR_read(n).bits[2]] == 0b1 then 2 else 3; + byte_select_match : bool = let 'bottom = bottom in + { + [DBGWCR_read(n)[BAS][UInt(vaddress[bottom - 1 .. 0])]] != 0b0 + }; + mask : int = UInt(DBGWCR_read(n)[MASK]); + if mask > 0 & not_bool(IsOnes(DBGWCR_read(n)[BAS])) then { + byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPMASKANDBAS) + } else { + let LSB : bits(8) = DBGWCR_read(n)[BAS] & not_vec(DBGWCR_read(n)[BAS] - 1); + let MSB : bits(8) = DBGWCR_read(n)[BAS] + LSB; + if not_bool(IsZero(MSB & MSB - 1)) then { + byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPBASCONTIGUOUS); + bottom = 3 + }; + () + }; + let 'bottom = bottom; + if mask > 0 & mask <= 2 then { + c : Constraint = undefined; + (c, mask) = ConstrainUnpredictableInteger(3, 31, Unpredictable_RESWPMASK); + assert(c == Constraint_DISABLED | c == Constraint_NONE | c == Constraint_UNKNOWN); + match c { + Constraint_DISABLED => { + return(false) + }, + Constraint_NONE => { + mask = 0 + }, + _ => () + } + }; + let 'mask = mask; + WVR_match : bool = undefined; + if mask > bottom then { + assert(constraint((0 <= 'mask & 'mask <= 'top & 'top < 32))); + WVR_match = vaddress[top .. mask] == DBGWVR_read(n).bits[top .. mask]; + if WVR_match & not_bool(is_zero_subrange(DBGWVR_read(n).bits, mask - 1, bottom)) then { + WVR_match = ConstrainUnpredictableBool(Unpredictable_WPMASKEDBITS) + }; + () + } else { + WVR_match = vaddress[top .. bottom] == DBGWVR_read(n).bits[top .. bottom] + }; + return(WVR_match & byte_select_match) +} + +val AArch32_WatchpointMatch : forall 'n 'size, (0 <= 'n & 'n < 16). + (int('n), bits(32), int('size), AccessDescriptor) -> bool + +function AArch32_WatchpointMatch (n, vaddress, size, accdesc) = { + assert(ELUsingAArch32(S1TranslationRegime__1())); + assert(n < NumWatchpointsImplemented()); + let enabled : bool = DBGWCR_read(n)[E] == 0b1; + let linked : bool = DBGWCR_read(n)[WT] == 0b1; + let isbreakpnt : bool = false; + let 'linked_n = UInt(DBGWCR_EL1[n][LBN]); + let state_match : bool = AArch32_StateMatch(DBGWCR_read(n)[SSC], DBGWCR_read(n)[HMC], DBGWCR_read(n)[PAC], linked, linked_n, isbreakpnt, accdesc); + ls_match : bool = undefined; + match DBGWCR_read(n)[LSC][1 .. 0] { + 0b00 => { + ls_match = false + }, + 0b01 => { + ls_match = accdesc.read + }, + 0b10 => { + ls_match = accdesc.write | accdesc.acctype == AccessType_DC + }, + 0b11 => { + ls_match = true + }, + _ => () + }; + value_match_name : bool = false; + foreach (byte from 0 to (size - 1) by 1 in inc) { + value_match_name = value_match_name | AArch32_WatchpointByteMatch(n, vaddress + byte) + }; + return(((value_match_name & state_match) & ls_match) & enabled) +} + +val AArch32_CheckWatchpoint : forall 'size. + (FaultRecord, bits(32), AccessDescriptor, int('size)) -> FaultRecord + +function AArch32_CheckWatchpoint (fault_in, vaddress, accdesc, size) = { + reason : bits(6) = undefined; + assert(ELUsingAArch32(S1TranslationRegime__1())); + fault : FaultRecord = fault_in; + if accdesc.acctype == AccessType_DC then { + if accdesc.cacheop != CacheOp_Invalidate then { + return(fault) + } else if not_bool(__IMPDEF_boolean("DCIMVAC generates watchpoint")) then { + return(fault) + } else () + } else if not_bool(IsDataAccess(accdesc.acctype)) then { + return(fault) + } else (); + val_match : bool = false; + foreach (i from 0 to (NumWatchpointsImplemented() - 1) by 1 in inc) { + assert(constraint('loop_i < 16)); + if AArch32_WatchpointMatch(i, vaddress, size, accdesc) then { + val_match = true + }; + () + }; + if val_match & HaltOnBreakpointOrWatchpoint() then { + let reason : bits(6) = DebugHalt_Watchpoint; + EDWAR = ZeroExtend(vaddress, 64); + Halt(reason) + } else if val_match then { + fault.statuscode = Fault_Debug; + fault.debugmoe = DebugException_Watchpoint + } else (); + return(fault) +} + +val AArch32_CheckDebug : forall 'size. + (bits(32), AccessDescriptor, int('size)) -> FaultRecord + +function AArch32_CheckDebug (vaddress, accdesc, size) = { + fault : FaultRecord = NoFault__1(accdesc); + let d_side : bool = IsDataAccess(accdesc.acctype) | accdesc.acctype == AccessType_DC; + let i_side : bool = accdesc.acctype == AccessType_IFETCH; + let generate_exception : bool = AArch32_GenerateDebugExceptions() & DBGDSCRext_read()[MDBGen] == 0b1; + let halt : bool = HaltOnBreakpointOrWatchpoint(); + let vector_catch_first_name : bool = ConstrainUnpredictableBool(Unpredictable_BPVECTORCATCHPRI); + if (i_side & vector_catch_first_name) & generate_exception then { + fault = AArch32_CheckVectorCatch(fault, vaddress, size) + }; + if fault.statuscode == Fault_None & (generate_exception | halt) then { + if d_side then { + fault = AArch32_CheckWatchpoint(fault, vaddress, accdesc, size) + } else if i_side then { + fault = AArch32_CheckBreakpoint(fault, vaddress, accdesc, size) + } else () + }; + if ((fault.statuscode == Fault_None & i_side) & not_bool(vector_catch_first_name)) & generate_exception then { + return(AArch32_CheckVectorCatch(fault, vaddress, size)) + }; + return(fault) +} + +val AArch32_FullTranslate : forall ('aligned : Bool). + (bits(32), AccessDescriptor, bool('aligned)) -> AddressDescriptor + +function AArch32_FullTranslate (va, accdesc, aligned) = { + fault : FaultRecord = NoFault__1(accdesc); + let regime : Regime = TranslationRegime(accdesc.el); + ipa : AddressDescriptor = undefined; + if regime == Regime_EL2 | TTBCR_read()[EAE] == 0b1 then { + (fault, ipa) = AArch32_S1TranslateLD(fault, regime, va, aligned, accdesc) + } else { + let (__tup_0 : FaultRecord, __tup_1 : AddressDescriptor, _) = AArch32_S1TranslateSD(fault, regime, va, aligned, accdesc); + fault = __tup_0; + ipa = __tup_1 + }; + if fault.statuscode != Fault_None then { + return(CreateFaultyAddressDescriptor(ZeroExtend(va, 64), fault)) + }; + if regime == Regime_EL10 & EL2Enabled() then { + ipa.vaddress = ZeroExtend(va, 64); + pa : AddressDescriptor = undefined; + (fault, pa) = AArch32_S2Translate(fault, ipa, None(), aligned, accdesc); + if fault.statuscode != Fault_None then { + return(CreateFaultyAddressDescriptor(ZeroExtend(va, 64), fault)) + } else { + return(pa) + } + } else { + return(ipa) + } +} + +val AArch32_TranslateAddress : forall ('aligned : Bool) 'size. + (bits(32), AccessDescriptor, bool('aligned), int('size)) -> AddressDescriptor + +function AArch32_TranslateAddress (va, accdesc, aligned, size) = { + let regime : Regime = TranslationRegime(PSTATE.EL); + if not_bool(RegimeUsingAArch32(regime)) then { + return(AArch64_TranslateAddress(ZeroExtend(va, 64), accdesc, aligned, size)) + }; + // Determine translation context and announce translation start + let regime : Regime = TranslationRegime(accdesc.el); + let tsi = AArch32_GetTranslationStartInfo(regime, accdesc.ss, accdesc, va, size); + start_translation(tsi); + // + result : AddressDescriptor = AArch32_FullTranslate(va, accdesc, aligned); + if not_bool(IsFault(result)) then { + result.fault = AArch32_CheckDebug(va, accdesc, size) + }; + result.vaddress = ZeroExtend(va, 64); + // Announce result + end_translation(result); + // + return(result) +} + +val AArch32_DC : (bits(32), CacheOp, CacheOpScope) -> unit + +function AArch32_DC (regval, cacheop, opscope) = { + cache : CacheRecord = undefined; + cache.acctype = AccessType_DC; + cache.cacheop = cacheop; + cache.opscope = opscope; + cache.cachetype = CacheType_Data; + cache.security = SecurityStateAtEL(PSTATE.EL); + if opscope == CacheOpScope_SetWay then { + cache.shareability = Shareability_NSH; + (cache.setnum, cache.waynum, cache.level) = DecodeSW(ZeroExtend(regval, 64), CacheType_Data); + if ((cacheop == CacheOp_Invalidate & PSTATE.EL == EL1) & EL2Enabled()) & (not_bool(ELUsingAArch32(EL2)) & (HCR_EL2[SWIO] == 0b1 | (HCR_EL2[DC] @ HCR_EL2[VM]) != 0b00) | ELUsingAArch32(EL2) & (HCR_read()[SWIO] == 0b1 | (HCR_read()[DC] @ HCR_read()[VM]) != 0b00)) then { + cache.cacheop = CacheOp_CleanInvalidate + }; + CACHE_OP(cache); + return() + }; + if EL2Enabled() then { + if PSTATE.EL == EL0 | PSTATE.EL == EL1 then { + cache.is_vmid_valid = true; + cache.vmid = VMID_read() + } else { + cache.is_vmid_valid = false + } + } else { + cache.is_vmid_valid = false + }; + if PSTATE.EL == EL0 then { + cache.is_asid_valid = true; + cache.asid = ASID_read() + } else { + cache.is_asid_valid = false + }; + let need_translate : bool = DCInstNeedsTranslation(opscope); + vaddress : bits(32) = regval; + size : int = 0; + if cacheop == CacheOp_Invalidate then { + size = __IMPDEF_integer("Data Cache Invalidate Watchpoint Size"); + assert(size >= 4 * pow2(UInt(CTR_EL0[DminLine])) & size <= 2048); + assert(UInt(size[32 .. 0] & (size - 1)[32 .. 0]) == 0); + vaddress = Align(regval, size) + }; + let 'size = size; + cache.translated = need_translate; + cache.vaddress = ZeroExtend(vaddress, 64); + if need_translate then { + let aligned : bool = true; + let accdesc : AccessDescriptor = CreateAccDescDC(cache); + let memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(vaddress, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch32_Abort(regval, memaddrdesc.fault) + }; + cache.paddress = memaddrdesc.paddress; + if opscope == CacheOpScope_PoC then { + cache.shareability = memaddrdesc.memattrs.shareability + } else { + cache.shareability = Shareability_NSH + } + } else { + cache.shareability = __UNKNOWN_Shareability(); + cache.paddress = __UNKNOWN_FullAddress() + }; + if ((cacheop == CacheOp_Invalidate & PSTATE.EL == EL1) & EL2Enabled()) & (not_bool(ELUsingAArch32(EL2)) & (HCR_EL2[DC] @ HCR_EL2[VM]) != 0b00 | ELUsingAArch32(EL2) & (HCR_read()[DC] @ HCR_read()[VM]) != 0b00) then { + cache.cacheop = CacheOp_CleanInvalidate + }; + CACHE_OP(cache); + return() +} + +val AArch32_IC : CacheOpScope -> unit + +val AArch32_IC__1 : (bits(32), CacheOpScope) -> unit + +function AArch32_IC opscope = { + let regval : bits(32) = __UNKNOWN_bits(32); + AArch32_IC__1(regval, opscope) +} + +function AArch32_IC__1 (regval, opscope) = { + need_translate : bool = undefined; + cache : CacheRecord = undefined; + cache.acctype = AccessType_IC; + cache.cachetype = CacheType_Instruction; + cache.cacheop = CacheOp_Invalidate; + cache.opscope = opscope; + cache.security = SecurityStateAtEL(PSTATE.EL); + if opscope == CacheOpScope_ALLU | opscope == CacheOpScope_ALLUIS then { + if opscope == CacheOpScope_ALLUIS | ((opscope == CacheOpScope_ALLU & PSTATE.EL == EL1) & EL2Enabled()) & HCR_read()[FB] == 0b1 then { + cache.shareability = Shareability_ISH + } else { + cache.shareability = Shareability_NSH + }; + cache.regval = ZeroExtend(regval, 64); + CACHE_OP(cache) + } else { + assert(opscope == CacheOpScope_PoU); + if EL2Enabled() then { + if PSTATE.EL == EL0 | PSTATE.EL == EL1 then { + cache.is_vmid_valid = true; + cache.vmid = VMID_read() + } else { + cache.is_vmid_valid = false + } + } else { + cache.is_vmid_valid = false + }; + if PSTATE.EL == EL0 then { + cache.is_asid_valid = true; + cache.asid = ASID_read() + } else { + cache.is_asid_valid = false + }; + let need_translate : bool = ICInstNeedsTranslation(opscope); + cache.shareability = Shareability_NSH; + cache.vaddress = ZeroExtend(regval, 64); + cache.translated = need_translate; + if not_bool(need_translate) then { + cache.paddress = __UNKNOWN_FullAddress(); + CACHE_OP(cache); + return() + }; + let 'size = 0; + let aligned : bool = true; + let accdesc : AccessDescriptor = CreateAccDescIC(cache); + let memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(regval, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch32_Abort(regval, memaddrdesc.fault) + }; + cache.paddress = memaddrdesc.paddress; + CACHE_OP(cache) + }; + return() +} + +val AArch32_PARFaultStatusLD : FaultRecord -> bits(6) + +function AArch32_PARFaultStatusLD fault = { + syndrome : bits(6) = undefined; + if fault.statuscode == Fault_Domain then { + assert(fault.level == 1 | fault.level == 2); + syndrome[1 .. 0] = if fault.level == 1 then 0b01 else 0b10; + syndrome[5 .. 2] = 0b1111 + } else { + syndrome = EncodeLDFSC(fault.statuscode, fault.level) + }; + return(syndrome) +} + +val AArch32_EncodePARLD : (AddressDescriptor, SecurityState) -> unit + +function AArch32_EncodePARLD (addrdesc, ss) = { + if not_bool(IsFault(addrdesc)) then { + ns : bits(1) = undefined; + if ss == SS_NonSecure then { + ns = __UNKNOWN_bit() + } else if addrdesc.paddress.paspace == PAS_Secure then { + ns = 0b0 + } else { + ns = 0b1 + }; + let ns : bits(1) = if addrdesc.paddress.paspace == PAS_Secure then 0b0 + else + 0b1; + PAR_write() = [PAR_read() with F = 0b0]; + PAR_write() = [PAR_read() with SH = ReportedPARShareability(PAREncodeShareability(addrdesc.memattrs))]; + PAR_write() = [PAR_read() with NS = ns]; + PAR_write() = Mk_PAR_Type([PAR_read().bits with 10 .. 10 = __IMPDEF_bit("Non-Faulting PAR")]); + PAR_write() = [PAR_read() with LPAE = 0b1]; + PAR_write() = [PAR_read() with PA = addrdesc.paddress.address[39 .. 12]]; + PAR_write() = [PAR_read() with ATTR = ReportedPARAttrs(EncodePARAttrs(addrdesc.memattrs))] + } else { + PAR_write() = [PAR_read() with F = 0b1]; + PAR_write() = [PAR_read() with FST = AArch32_PARFaultStatusLD(addrdesc.fault)]; + PAR_write() = [PAR_read() with S2WLK = if addrdesc.fault.s2fs1walk then + 0b1 + else + 0b0]; + PAR_write() = [PAR_read() with FSTAGE = if addrdesc.fault.secondstage then + 0b1 + else + 0b0]; + PAR_write() = [PAR_read() with LPAE = 0b1]; + PAR_write() = Mk_PAR_Type([PAR_read().bits with 63 .. 48 = __IMPDEF_bits(16, "Faulting PAR")]) + }; + return() +} + +val AArch32_PARFaultStatusSD : FaultRecord -> bits(6) + +function AArch32_PARFaultStatusSD fault = { + syndrome : bits(6) = undefined; + syndrome[5] = Bit(if IsExternalAbort__1(fault) then fault.extflag else 0b0); + syndrome[4 .. 0] = EncodeSDFSC(fault.statuscode, fault.level); + return(syndrome) +} + +val AArch32_PARInnerAttrs : MemoryAttributes -> bits(3) + +function AArch32_PARInnerAttrs memattrs = { + result : bits(3) = undefined; + if memattrs.memtype == MemType_Device then { + if memattrs.device == DeviceType_nGnRnE then { + result = 0b001 + } else if memattrs.device == DeviceType_nGnRE then { + result = 0b011 + } else () + } else { + let inner : MemAttrHints = memattrs.inner; + if inner.attrs == MemAttr_NC then { + result = 0b000 + } else if inner.attrs == MemAttr_WB & [inner.hints[0]] == 0b1 then { + result = 0b101 + } else if inner.attrs == MemAttr_WT then { + result = 0b110 + } else if inner.attrs == MemAttr_WB & [inner.hints[0]] == 0b0 then { + result = 0b111 + } else () + }; + return(result) +} + +val AArch32_PAROuterAttrs : MemoryAttributes -> bits(2) + +function AArch32_PAROuterAttrs memattrs = { + result : bits(2) = undefined; + if memattrs.memtype == MemType_Device then { + result = __UNKNOWN_bits(2) + } else { + let outer : MemAttrHints = memattrs.outer; + if outer.attrs == MemAttr_NC then { + result = 0b00 + } else if outer.attrs == MemAttr_WB & [outer.hints[0]] == 0b1 then { + result = 0b01 + } else if outer.attrs == MemAttr_WT & [outer.hints[0]] == 0b0 then { + result = 0b10 + } else if outer.attrs == MemAttr_WB & [outer.hints[0]] == 0b0 then { + result = 0b11 + } else () + }; + return(result) +} + +val AArch32_EncodePARSD : (AddressDescriptor, bits(1), SecurityState) -> unit + +function AArch32_EncodePARSD (addrdesc_in, supersection, ss) = { + addrdesc : AddressDescriptor = addrdesc_in; + if not_bool(IsFault(addrdesc)) then { + if addrdesc.memattrs.memtype == MemType_Device | addrdesc.memattrs.inner.attrs == MemAttr_NC & addrdesc.memattrs.outer.attrs == MemAttr_NC then { + addrdesc.memattrs.shareability = Shareability_OSH + }; + ns : bits(1) = undefined; + if ss == SS_NonSecure then { + ns = __UNKNOWN_bit() + } else if addrdesc.paddress.paspace == PAS_Secure then { + ns = 0b0 + } else { + ns = 0b1 + }; + let ns : bits(1) = if addrdesc.paddress.paspace == PAS_Secure then 0b0 + else + 0b1; + let sh : bits(2) = if addrdesc.memattrs.shareability != Shareability_NSH then + 0b01 + else + 0b00; + PAR_write() = [PAR_read() with F = 0b0]; + PAR_write() = [PAR_read() with SS = supersection]; + PAR_write() = [PAR_read() with Outer = AArch32_ReportedOuterAttrs(AArch32_PAROuterAttrs(addrdesc.memattrs))]; + PAR_write() = [PAR_read() with Inner = AArch32_ReportedInnerAttrs(AArch32_PARInnerAttrs(addrdesc.memattrs))]; + PAR_write() = [PAR_read() with SH = ReportedPARShareability(sh)]; + PAR_write() = Mk_PAR_Type([PAR_read().bits with 8 .. 8 = __IMPDEF_bit("Non-Faulting PAR")]); + PAR_write() = [PAR_read() with NS = ns]; + PAR_write() = [PAR_read() with NOS = if addrdesc.memattrs.shareability == Shareability_OSH then + 0b0 + else + 0b1]; + PAR_write() = [PAR_read() with LPAE = 0b0]; + PAR_write() = [PAR_read() with PA = addrdesc.paddress.address[39 .. 12]] + } else { + PAR_write() = [PAR_read() with F = 0b1]; + PAR_write() = [PAR_read() with FST = AArch32_PARFaultStatusSD(addrdesc.fault)]; + PAR_write() = [PAR_read() with LPAE = 0b0]; + PAR_write() = Mk_PAR_Type([PAR_read().bits with 31 .. 16 = __IMPDEF_bits(16, "Faulting PAR")]) + }; + return() +} + +val AArch32_AT : (bits(32), TranslationStage, bits(2), ATAccess) -> unit + +function AArch32_AT (vaddress, stage_in, el, ataccess) = { + stage : TranslationStage = stage_in; + ss : SecurityState = undefined; + regime : Regime = undefined; + eae : bool = undefined; + if el == EL2 then { + regime = Regime_EL2; + eae = true; + ss = SS_NonSecure + } else if stage == TranslationStage_1 | stage == TranslationStage_12 & not_bool(HaveEL(EL2)) then { + stage = TranslationStage_1; + ss = SecurityStateAtEL(PSTATE.EL); + regime = if ss == SS_Secure & ELUsingAArch32(EL3) then Regime_EL30 else + Regime_EL10; + eae = TTBCR_read()[EAE] == 0b1 + } else { + regime = Regime_EL10; + eae = if HaveAArch32EL(EL3) then TTBCR_NS_read()[EAE] == 0b1 else + TTBCR_read()[EAE] == 0b1; + ss = SS_NonSecure + }; + addrdesc : AddressDescriptor = undefined; + sdftype : SDFType = undefined; + let aligned : bool = true; + supersection : bits(1) = 0b0; + let write : bool = ataccess == ATAccess_WritePAN | ataccess == ATAccess_Write; + let pan : bool = ataccess == ATAccess_WritePAN | ataccess == ATAccess_ReadPAN; + let accdesc : AccessDescriptor = CreateAccDescAT(ss, el, write, pan); + fault : FaultRecord = NoFault__1(accdesc); + // Determine translation info and announce translation start + let tsi = AArch32_GetTranslationStartInfo(regime, ss, accdesc, vaddress, 1); + start_translation(tsi); + // + if eae then { + (fault, addrdesc) = AArch32_S1TranslateLD(fault, regime, vaddress, aligned, accdesc) + } else { + (fault, addrdesc, sdftype) = AArch32_S1TranslateSD(fault, regime, vaddress, aligned, accdesc); + supersection = if sdftype == SDFType_Supersection then 0b1 else 0b0 + }; + if stage == TranslationStage_12 & fault.statuscode == Fault_None then { + (fault, addrdesc) = AArch32_S2Translate(fault, addrdesc, None(), aligned, accdesc) + }; + if fault.statuscode != Fault_None then { + if IsExternalAbort__1(fault) | (PSTATE.EL == EL1 & EL2Enabled()) & fault.s2fs1walk then { + PAR_write() = Mk_PAR_Type(__UNKNOWN_bits(64)); + AArch32_Abort(vaddress, fault) + }; + () + }; + addrdesc.fault = fault; + // Announce result + end_translation(addrdesc); + // + if (eae | stage == TranslationStage_12 & (HCR_read()[VM] == 0b1 | HCR_read()[DC] == 0b1)) | (stage == TranslationStage_1 & el != EL2) & PSTATE.EL == EL2 then { + AArch32_EncodePARLD(addrdesc, ss) + } else { + AArch32_EncodePARSD(addrdesc, supersection, ss) + }; + return() +} + +val AArch32_RestrictPrediction : (bits(32), RestrictType) -> unit + +function AArch32_RestrictPrediction (val_name, restriction) = { + c : ExecutionCntxt = undefined; + let target_el : bits(2) = val_name[25 .. 24]; + if not_bool(HaveEL(target_el)) | UInt(target_el) > UInt(PSTATE.EL) then { + EndOfInstruction() + }; + let ns : bits(1) = [val_name[26]]; + let nse : bits(1) = __UNKNOWN_bit(); + let ss : SecurityState = TargetSecurityState(ns, nse); + c.security = ss; + c.target_el = target_el; + if EL2Enabled() then { + if PSTATE.EL == EL0 | PSTATE.EL == EL1 then { + c.is_vmid_valid = true; + c.all_vmid = false; + c.vmid = VMID_read() + } else if target_el == EL0 | target_el == EL1 then { + c.is_vmid_valid = true; + c.all_vmid = [val_name[27]] == 0b1; + c.vmid = ZeroExtend(val_name[23 .. 16], 16) + } else { + c.is_vmid_valid = false + } + } else { + c.is_vmid_valid = false + }; + if PSTATE.EL == EL0 then { + c.is_asid_valid = true; + c.all_asid = false; + c.asid = ASID_read() + } else if target_el == EL0 then { + c.is_asid_valid = true; + c.all_asid = [val_name[8]] == 0b1; + c.asid = ZeroExtend(val_name[7 .. 0], 16) + } else { + c.is_asid_valid = false + }; + c.restriction = restriction; + RESTRICT_PREDICTIONS(c) +} + +val RRX_C : forall 'N, 'N > 1. (bits('N), bits(1)) -> (bits('N), bits(1)) + +function RRX_C (x, carry_in) = { + let result : bits('N) = [(x >> 1) with ('N - 1) = Bit(carry_in)]; + let carry_out : bits(1) = [x[0]]; + return((result, carry_out)) +} + +val Shift_C : forall 'N 'amount, 'N >= 0. + (bits('N), SRType, int('amount), bits(1)) -> (bits('N), bits(1)) + +function Shift_C (value_name, srtype, amount, carry_in) = { + assert(not_bool(srtype == SRType_RRX & amount != 1)); + result : bits('N) = undefined; + carry_out : bits(1) = undefined; + if amount == 0 then { + (result, carry_out) = (value_name, carry_in) + } else { + match srtype { + SRType_LSL => { + (result, carry_out) = LSL_C(value_name, amount) + }, + SRType_LSR => { + (result, carry_out) = LSR_C(value_name, amount) + }, + SRType_ASR => { + assert(constraint(('N >= 0 & 'amount >= 0))); + (result, carry_out) = ASR_C(value_name, amount) + }, + SRType_ROR => { + assert(constraint('N > 0)); + (result, carry_out) = ROR_C(value_name, amount) + }, + SRType_RRX => { + assert(constraint('N > 1)); + (result, carry_out) = RRX_C(value_name, carry_in) + } + } + }; + return((result, carry_out)) +} + +val A32ExpandImm_C : (bits(12), bits(1)) -> (bits(32), bits(1)) + +function A32ExpandImm_C (imm12, carry_in) = { + carry_out : bits(1) = undefined; + imm32 : bits(32) = undefined; + let unrotated_value : bits(32) = ZeroExtend(imm12[7 .. 0], 32); + (imm32, carry_out) = Shift_C(unrotated_value, SRType_ROR, 2 * UInt(imm12[11 .. 8]), carry_in); + return((imm32, carry_out)) +} + +val A32ExpandImm : bits(12) -> bits(32) + +function A32ExpandImm imm12 = { + imm32 : bits(32) = undefined; + let (__tup_0 : bits(32), _) = A32ExpandImm_C(imm12, PSTATE.C) in + { + imm32 = __tup_0 + }; + return(imm32) +} + +val DecodeImmShift : (bits(2), bits(5)) -> (SRType, int) + +function DecodeImmShift (srtype, imm5) = { + shift_t : SRType = undefined; + shift_n : range(0, 32) = undefined; + match srtype { + 0b00 => { + shift_t = SRType_LSL; + shift_n = UInt(imm5) + }, + 0b01 => { + shift_t = SRType_LSR; + shift_n = if imm5 == 0b00000 then 32 else UInt(imm5) + }, + 0b10 => { + shift_t = SRType_ASR; + shift_n = if imm5 == 0b00000 then 32 else UInt(imm5) + }, + 0b11 => { + if imm5 == 0b00000 then { + shift_t = SRType_RRX; + shift_n = 1 + } else { + shift_t = SRType_ROR; + shift_n = UInt(imm5) + } + } + }; + let 'shift_n = shift_n; + return((shift_t, shift_n)) +} + +val DecodeRegShift : bits(2) -> SRType + +function DecodeRegShift srtype = { + shift_t : SRType = undefined; + match srtype { + 0b00 => { + shift_t = SRType_LSL + }, + 0b01 => { + shift_t = SRType_LSR + }, + 0b10 => { + shift_t = SRType_ASR + }, + 0b11 => { + shift_t = SRType_ROR + } + }; + let shift_t = shift_t; + return(shift_t) +} + +val Shift : forall 'N 'amount, 'N >= 0. + (bits('N), SRType, int('amount), bits(1)) -> bits('N) + +function Shift (value_name, srtype, amount, carry_in) = { + result : bits('N) = undefined; + let (__tup_0 : bits('N), _) = Shift_C(value_name, srtype, amount, carry_in) + in + { + result = __tup_0 + }; + return(result) +} + +val T32ExpandImm_C : (bits(12), bits(1)) -> (bits(32), bits(1)) + +function T32ExpandImm_C (imm12, carry_in) = { + unrotated_value : bits(32) = undefined; + imm32 : bits(32) = undefined; + carry_out : bits(1) = undefined; + if imm12[11 .. 10] == 0b00 then { + match imm12[9 .. 8] { + 0b00 => { + imm32 = ZeroExtend(imm12[7 .. 0], 32) + }, + 0b01 => { + imm32 = ((0b00000000 @ imm12[7 .. 0]) @ 0b00000000) @ imm12[7 .. 0] + }, + 0b10 => { + imm32 = ((imm12[7 .. 0] @ 0b00000000) @ imm12[7 .. 0]) @ 0b00000000 + }, + 0b11 => { + imm32 = ((imm12[7 .. 0] @ imm12[7 .. 0]) @ imm12[7 .. 0]) @ imm12[7 .. 0] + } + }; + carry_out = carry_in + } else { + let unrotated_value : bits(32) = ZeroExtend(0b1 @ imm12[6 .. 0], 32); + (imm32, carry_out) = ROR_C(unrotated_value, UInt(imm12[11 .. 7])) + }; + return((imm32, carry_out)) +} + +val T32ExpandImm : bits(12) -> bits(32) + +function T32ExpandImm imm12 = { + imm32 : bits(32) = undefined; + let (__tup_0 : bits(32), _) = T32ExpandImm_C(imm12, PSTATE.C) in + { + imm32 = __tup_0 + }; + return(imm32) +} + +val AArch32_SystemAccessTrapSyndrome : forall 'ec. + (bits(32), int('ec)) -> ExceptionRecord + +function AArch32_SystemAccessTrapSyndrome (instr, ec) = { + except : ExceptionRecord = undefined; + match ec { + 0 => { + except = ExceptionSyndrome(Exception_Uncategorized) + }, + 3 => { + except = ExceptionSyndrome(Exception_CP15RTTrap) + }, + 4 => { + except = ExceptionSyndrome(Exception_CP15RRTTrap) + }, + 5 => { + except = ExceptionSyndrome(Exception_CP14RTTrap) + }, + 6 => { + except = ExceptionSyndrome(Exception_CP14DTTrap) + }, + 7 => { + except = ExceptionSyndrome(Exception_AdvSIMDFPAccessTrap) + }, + 8 => { + except = ExceptionSyndrome(Exception_FPIDTrap) + }, + 12 => { + except = ExceptionSyndrome(Exception_CP14RRTTrap) + }, + _ => { + Unreachable() + } + }; + iss : bits(20) = Zeros(20); + if except.exceptype == Exception_Uncategorized then { + return(except) + } else if except.exceptype == Exception_FPIDTrap | except.exceptype == Exception_CP14RTTrap | except.exceptype == Exception_CP15RTTrap then { + iss[13 .. 10] = instr[19 .. 16]; + iss[8 .. 5] = instr[15 .. 12]; + iss[9] = Bit(0b0); + if except.exceptype != Exception_FPIDTrap then { + iss[19 .. 17] = instr[7 .. 5]; + iss[16 .. 14] = instr[23 .. 21]; + iss[4 .. 1] = instr[3 .. 0] + } else { + iss[19 .. 17] = 0b000; + iss[16 .. 14] = 0b111; + iss[4 .. 1] = 0b0000 + } + } else if except.exceptype == Exception_CP14RRTTrap | except.exceptype == Exception_AdvSIMDFPAccessTrap | except.exceptype == Exception_CP15RRTTrap then { + iss[19 .. 16] = instr[7 .. 4]; + iss[13 .. 10] = instr[19 .. 16]; + iss[8 .. 5] = instr[15 .. 12]; + iss[4 .. 1] = instr[3 .. 0] + } else if except.exceptype == Exception_CP14DTTrap then { + iss[19 .. 12] = instr[7 .. 0]; + iss[4] = Bit([instr[23]]); + iss[2 .. 1] = [instr[24]] @ [instr[21]]; + if instr[19 .. 16] == 0b1111 then { + iss[8 .. 5] = __UNKNOWN_bits(4); + iss[3] = Bit(0b1) + }; + () + } else (); + iss[0] = Bit([instr[20]]); + except.syndrome[24 .. 20] = ConditionSyndrome(); + except.syndrome[19 .. 0] = iss; + return(except) +} + +val AArch32_TakeHypTrapException : forall 'ec. int('ec) -> unit + +val AArch32_TakeHypTrapException__1 : ExceptionRecord -> unit + +function AArch32_TakeHypTrapException ec = { + let except : ExceptionRecord = AArch32_SystemAccessTrapSyndrome(ThisInstr(), ec); + AArch32_TakeHypTrapException__1(except) +} + +function AArch32_TakeHypTrapException__1 except = { + assert((HaveEL(EL2) & CurrentSecurityState() == SS_NonSecure) & ELUsingAArch32(EL2)); + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x14); + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) +} + +val AArch32_SystemAccessTrap : forall 'ec. (bits(5), int('ec)) -> unit + +function AArch32_SystemAccessTrap (mode, ec) = { + except : ExceptionRecord = undefined; + target_el : bits(2) = undefined; + valid_name : bool = undefined; + (valid_name, target_el) = ELFromM32(mode); + assert(((valid_name & HaveEL(target_el)) & target_el != EL0) & UInt(target_el) >= UInt(PSTATE.EL)); + if target_el == EL2 then { + let except : ExceptionRecord = AArch32_SystemAccessTrapSyndrome(ThisInstr(), ec); + AArch32_TakeHypTrapException__1(except) + } else { + AArch32_TakeUndefInstrException() + } +} + +bitfield HSTR_Type : bits(32) = + { + T15 : 15..15, + T13 : 13..13, + T12 : 12..12, + T11 : 11..11, + T10 : 10..10, + T9 : 9..9, + T8 : 8..8, + T7 : 7..7, + T6 : 6..6, + T5 : 5..5, + T3 : 3..3, + T2 : 2..2, + T1 : 1..1, + T0 : 0..0 + } + +register _HSTR : HSTR_Type + +val HSTR_read : unit -> HSTR_Type + +function HSTR_read () = { + r : HSTR_Type = _HSTR; + r.bits[31 .. 0] = Slice(HSTR_EL2.bits, 0, 32); + return(r) +} + +val AArch32_CheckCP15InstrCoarseTraps : forall 'CRm 'CRn 'nreg. + (int('CRn), int('nreg), int('CRm)) -> unit + +function AArch32_CheckCP15InstrCoarseTraps (CRn, nreg, CRm) = { + major : int = undefined; + if PSTATE.EL == EL0 & (not_bool(ELUsingAArch32(EL1)) | EL2Enabled() & not_bool(ELUsingAArch32(EL2))) then { + AArch64_CheckCP15InstrCoarseTraps(CRn, nreg, CRm) + }; + let trapped_encoding : bool = (CRn == 9 & (CRm == 0 | CRm == 1 | CRm == 2 | CRm == 5 | CRm == 6 | CRm == 7 | CRm == 8) | CRn == 10 & (CRm == 0 | CRm == 1 | CRm == 4 | CRm == 8)) | CRn == 11 & (CRm == 0 | CRm == 1 | CRm == 2 | CRm == 3 | CRm == 4 | CRm == 5 | CRm == 6 | CRm == 7 | CRm == 8 | CRm == 15); + if (PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled() then { + let 'major = if nreg == 1 then CRn else CRm; + assert(constraint((0 <= 'major & 'major < 32))); + if not_bool(major == 4 | major == 14) & [HSTR_read().bits[major]] == 0b1 | (HCR_read()[TIDCP] == 0b1 & nreg == 1) & trapped_encoding then { + if PSTATE.EL == EL0 & __IMPDEF_boolean("UNDEF unallocated CP15 access at EL0") then { + throw(Error_Undefined()) + }; + if ELUsingAArch32(EL2) then { + AArch32_SystemAccessTrap(M32_Hyp, UInt(0x3)) + } else { + AArch64_AArch32SystemAccessTrap(EL2, UInt(0x3)) + } + }; + () + }; + () +} + +val AArch32_CheckFPAdvSIMDTrap : forall ('advsimd : Bool). + bool('advsimd) -> unit + +function AArch32_CheckFPAdvSIMDTrap advsimd = { + except : ExceptionRecord = undefined; + hcptr_cp10 : bits(1) = undefined; + hcptr_tase : bits(1) = undefined; + ss : SecurityState = undefined; + if EL2Enabled() & not_bool(ELUsingAArch32(EL2)) then { + AArch64_CheckFPAdvSIMDTrap() + } else { + if ((HaveEL(EL3) & not_bool(ELUsingAArch32(EL3))) & CPTR_EL3[TFP] == 0b1) & EL3SDDUndefPriority() then { + throw(Error_Undefined()) + }; + let ss : SecurityState = CurrentSecurityState(); + if HaveEL(EL2) & ss != SS_Secure then { + hcptr_tase : bits(1) = HCPTR_read()[TASE]; + hcptr_cp10 : bits(1) = HCPTR_read()[TCP10]; + if HaveEL(EL3) & ELUsingAArch32(EL3) then { + if NSACR[NSASEDIS] == 0b1 then { + hcptr_tase = 0b1 + }; + if NSACR[cp10] == 0b0 then { + hcptr_cp10 = 0b1 + }; + () + }; + if advsimd & hcptr_tase == 0b1 | hcptr_cp10 == 0b1 then { + except : ExceptionRecord = ExceptionSyndrome(Exception_AdvSIMDFPAccessTrap); + except.syndrome[24 .. 20] = ConditionSyndrome(); + if advsimd then { + except.syndrome[5] = Bit(0b1) + } else { + except.syndrome[5] = Bit(0b0); + except.syndrome[3 .. 0] = 0b1010 + }; + if PSTATE.EL == EL2 then { + AArch32_TakeUndefInstrException__1(except) + } else { + AArch32_TakeHypTrapException__1(except) + } + }; + () + }; + if HaveEL(EL3) & not_bool(ELUsingAArch32(EL3)) then { + if CPTR_EL3[TFP] == 0b1 then { + if EL3SDDUndef() then { + throw(Error_Undefined()) + } else { + AArch64_AdvSIMDFPAccessTrap(EL3) + } + }; + () + }; + () + } +} + +val AArch32_CheckAdvSIMDOrFPEnabled : forall ('advsimd : Bool) ('fpexc_check : Bool). + (bool('fpexc_check), bool('advsimd)) -> unit + +function AArch32_CheckAdvSIMDOrFPEnabled (fpexc_check, advsimd) = { + cpacr_asedis : bits(1) = undefined; + cpacr_cp10 : bits(2) = undefined; + fpexc_en : bits(1) = undefined; + if (PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1))) & (not_bool(EL2Enabled()) | not_bool(ELUsingAArch32(EL2)) & HCR_EL2[TGE] == 0b0) then { + AArch64_CheckFPEnabled(); + AArch64_CheckFPAdvSIMDEnabled() + } else if (((PSTATE.EL == EL0 & EL2Enabled()) & not_bool(ELUsingAArch32(EL2))) & HCR_EL2[TGE] == 0b1) & not_bool(ELUsingAArch32(EL1)) then { + if fpexc_check & HCR_EL2[RW] == 0b0 then { + let fpexc_en : bits(1) = __IMPDEF_bits(1, "FPEXC.EN value when TGE==1 and RW==0"); + if fpexc_en == 0b0 then { + throw(Error_Undefined()) + }; + () + }; + AArch64_CheckFPEnabled() + } else { + cpacr_asedis : bits(1) = CPACR_read__1()[ASEDIS]; + cpacr_cp10 : bits(2) = CPACR_read__1()[cp10]; + if (HaveEL(EL3) & ELUsingAArch32(EL3)) & CurrentSecurityState() == SS_NonSecure then { + if NSACR[NSASEDIS] == 0b1 then { + cpacr_asedis = 0b1 + }; + if NSACR[cp10] == 0b0 then { + cpacr_cp10 = 0b00 + }; + () + }; + if PSTATE.EL != EL2 then { + if advsimd & cpacr_asedis == 0b1 then { + throw(Error_Undefined()) + }; + disabled : bool = undefined; + match cpacr_cp10 { + 0b00 => { + disabled = true + }, + 0b01 => { + disabled = PSTATE.EL == EL0 + }, + 0b10 => { + disabled = ConstrainUnpredictableBool(Unpredictable_RESCPACR) + }, + 0b11 => { + disabled = false + } + }; + let disabled = disabled; + if disabled then { + throw(Error_Undefined()) + }; + () + }; + if fpexc_check & FPEXC_read()[EN] == 0b0 then { + throw(Error_Undefined()) + }; + AArch32_CheckFPAdvSIMDTrap(advsimd) + } +} + +val D_read : forall 'n. int('n) -> bits(64) + +function D_read n = { + assert(n >= 0 & n <= 31); + let 'base = MOD(n, 2) * 64; + let vreg : bits(128) = V_read(DIV(n, 2), 128); + return(vreg[base + 63 .. base]) +} + +val CheckAdvSIMDEnabled : unit -> unit + +function CheckAdvSIMDEnabled () = { + let fpexc_check : bool = true; + let advsimd : bool = true; + AArch32_CheckAdvSIMDOrFPEnabled(fpexc_check, advsimd); + foreach (i from 0 to 31 by 1 in inc) { + _Dclone[i] = D_read(i) + }; + return() +} + +val CheckAdvSIMDOrVFPEnabled : forall ('advsimd : Bool) ('include_fpexc_check_name : Bool). + (bool('include_fpexc_check_name), bool('advsimd)) -> unit + +function CheckAdvSIMDOrVFPEnabled (include_fpexc_check_name, advsimd) = { + AArch32_CheckAdvSIMDOrFPEnabled(include_fpexc_check_name, advsimd); + return() +} + +val CheckCryptoEnabled32 : unit -> unit + +function CheckCryptoEnabled32 () = { + CheckAdvSIMDEnabled(); + return() +} + +val CheckVFPEnabled : forall ('include_fpexc_check_name : Bool). + bool('include_fpexc_check_name) -> unit + +function CheckVFPEnabled include_fpexc_check_name = { + let advsimd : bool = false; + AArch32_CheckAdvSIMDOrFPEnabled(include_fpexc_check_name, advsimd); + return() +} + +val FPHalvedSub : forall 'N, 'N in {16, 32, 64}. + (bits('N), bits('N), FPCRType) -> bits('N) + +function FPHalvedSub (op1, op2, fpcr) = { + done : bool = undefined; + inf1 : bool = undefined; + inf2 : bool = undefined; + result : bits('N) = undefined; + result_sign : bits(1) = undefined; + result_value : real = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32 | 'N == 64); + let rounding : FPRounding = FPRoundingMode(fpcr); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + if (inf1 & inf2) & sign1 == sign2 then { + result = FPDefaultNaN__1(fpcr, 'N); + FPProcessException(FPExc_InvalidOp, fpcr) + } else if inf1 & sign1 == 0b0 | inf2 & sign2 == 0b1 then { + result = FPInfinity(0b0, 'N) + } else if inf1 & sign1 == 0b1 | inf2 & sign2 == 0b0 then { + result = FPInfinity(0b1, 'N) + } else if (zero1 & zero2) & sign1 != sign2 then { + result = FPZero(sign1, 'N) + } else { + let result_value : real = (value1_name - value2_name) / 2.0; + if result_value == 0.0 then { + let result_sign : bits(1) = if rounding == FPRounding_NEGINF then + 0b1 + else + 0b0; + result = FPZero(result_sign, 'N) + } else { + result = FPRound(result_value, fpcr, 'N) + } + } + }; + return(result) +} + +val StandardFPSCRValue : unit -> FPCRType + +function StandardFPSCRValue () = { + let value_name : bits(32) = (((0b00000 @ FPSCR_read__1()[AHP]) @ 0b110000) @ FPSCR_read__1()[FZ16]) @ 0b0000000000000000000; + return(Mk_FPCRType(ZeroExtend(value_name, 64))) +} + +val FPRecipStep : forall 'N, 'N in {16, 32}. (bits('N), bits('N)) -> bits('N) + +function FPRecipStep (op1, op2) = { + done : bool = undefined; + inf1 : bool = undefined; + inf2 : bool = undefined; + result : bits('N) = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32); + let fpcr : FPCRType = StandardFPSCRValue(); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + product : bits('N) = undefined; + if inf1 & zero2 | zero1 & inf2 then { + product = FPZero(0b0, 'N) + } else { + product = FPMul(op1, op2, fpcr) + }; + let two : bits('N) = FPTwo(0b0, 'N); + result = FPSub(two, product, fpcr) + }; + return(result) +} + +val FPRSqrtStep : forall 'N, 'N in {16, 32}. (bits('N), bits('N)) -> bits('N) + +function FPRSqrtStep (op1, op2) = { + done : bool = undefined; + inf1 : bool = undefined; + inf2 : bool = undefined; + result : bits('N) = undefined; + sign1 : bits(1) = undefined; + sign2 : bits(1) = undefined; + type1 : FPType = undefined; + type2 : FPType = undefined; + value1_name : real = undefined; + value2_name : real = undefined; + zero1 : bool = undefined; + zero2 : bool = undefined; + assert('N == 16 | 'N == 32); + let fpcr : FPCRType = StandardFPSCRValue(); + (type1, sign1, value1_name) = FPUnpack(op1, fpcr); + (type2, sign2, value2_name) = FPUnpack(op2, fpcr); + (done, result) = FPProcessNaNs(type1, type2, op1, op2, fpcr); + if not_bool(done) then { + let inf1 : bool = type1 == FPType_Infinity; + let inf2 : bool = type2 == FPType_Infinity; + let zero1 : bool = type1 == FPType_Zero; + let zero2 : bool = type2 == FPType_Zero; + product : bits('N) = undefined; + if inf1 & zero2 | zero1 & inf2 then { + product = FPZero(0b0, 'N) + } else { + product = FPMul(op1, op2, fpcr) + }; + let three : bits('N) = FPThree(0b0, 'N); + result = FPHalvedSub(three, product, fpcr) + }; + return(result) +} + +val AArch32_UnalignedAccessFaults : AccessDescriptor -> bool + +function AArch32_UnalignedAccessFaults accdesc = { + return((((AlignmentEnforced() | accdesc.a32lsmd) | accdesc.exclusive) | accdesc.acqsc) | accdesc.relsc) +} + +val AArch32_MemSingle_read : forall ('aligned : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size), AccessDescriptor, bool('aligned)) -> bits('size * 8) + +val AArch32_MemSingle_read__1 : forall ('aligned : Bool) ('ispair : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size), AccessDescriptor, bool('aligned), bool('ispair)) -> bits('size * 8) + +function AArch32_MemSingle_read (address, size, accdesc, aligned) = { + let ispair : bool = false; + return(AArch32_MemSingle_read__1(address, size, accdesc, aligned, ispair)) +} + +function AArch32_MemSingle_read__1 (address, size, accdesc_in, aligned, ispair) = { + assert(size == 1 | size == 2 | size == 4 | size == 8 | size == 16); + value_name : bits('size * 8) = undefined; + let accdesc : AccessDescriptor = accdesc_in; + assert(IsAligned__1(address, size)); + let memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch32_Abort(address, memaddrdesc.fault) + }; + if SPESampleInFlight then { + let is_load : bool = true; + SPESampleLoadStore(is_load, accdesc, memaddrdesc) + }; + memstatus : PhysMemRetStatus = undefined; + (memstatus, value_name) = PhysMemRead(memaddrdesc, size, accdesc, None()); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalReadAbort(memstatus, memaddrdesc, size, accdesc) + }; + return(value_name) +} + +val AArch32_MemSingle_set : forall ('aligned : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size), AccessDescriptor, bool('aligned), bits('size * 8)) -> unit + +val AArch32_MemSingle_set__1 : forall ('aligned : Bool) ('ispair : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size), AccessDescriptor, bool('aligned), bool('ispair), bits('size * 8)) -> unit + +function AArch32_MemSingle_set (address, size, accdesc, aligned, value_name) = { + let ispair : bool = false; + AArch32_MemSingle_set__1(address, size, accdesc, aligned, ispair) = value_name; + return() +} + +function AArch32_MemSingle_set__1 (address, size, accdesc_in, aligned, ispair, value_name) = { + assert(size == 1 | size == 2 | size == 4 | size == 8 | size == 16); + let accdesc : AccessDescriptor = accdesc_in; + assert(IsAligned__1(address, size)); + let memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch32_Abort(address, memaddrdesc.fault) + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), size) + }; + if SPESampleInFlight then { + let is_load : bool = false; + SPESampleLoadStore(is_load, accdesc, memaddrdesc) + }; + let memstatus : PhysMemRetStatus = PhysMemWrite(memaddrdesc, size, accdesc, None(), value_name); // TODO: TranslationInfo + if IsFault__2(memstatus) then { + HandleExternalWriteAbort(memstatus, memaddrdesc, size, accdesc) + }; + return() +} + +val Mem_with_type_read : forall 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size), AccessDescriptor) -> bits('size * 8) + +val Mem_with_type_read__1 : forall ('ispair : Bool) 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size), AccessDescriptor, bool('ispair)) -> bits('size * 8) + +function Mem_with_type_read (address, size, accdesc) = { + let ispair : bool = false; + return(Mem_with_type_read__1(address, size, accdesc, ispair)) +} + +function Mem_with_type_read__1 (address, size, accdesc, ispair) = { + c : Constraint = undefined; + assert(size == 1 | size == 2 | size == 4 | size == 8 | size == 16); + let 'halfsize = DIV(size, 2); + value_name : bits('size * 8) = undefined; + let 'alignment = if ispair then halfsize else size; + aligned : bool = IsAligned__1(address, alignment); + if not_bool(aligned) & AArch32_UnalignedAccessFaults(accdesc) then { + AArch32_Abort(address, AlignmentFault(accdesc)) + }; + if aligned then { + value_name = AArch32_MemSingle_read__1(address, size, accdesc, aligned, ispair) + } else { + assert(size > 1); + value_name[7 .. 0] = AArch32_MemSingle_read(address, 1, accdesc, aligned); + let c : Constraint = ConstrainUnpredictable(Unpredictable_DEVPAGE2); + assert(c == Constraint_FAULT | c == Constraint_NONE); + if c == Constraint_NONE then { + aligned = true + }; + foreach (i from 1 to (size - 1) by 1 in inc) { + value_name[8 * i + 7 .. 8 * i] = AArch32_MemSingle_read(address + i, 1, accdesc, aligned) + } + }; + if BigEndian(accdesc.acctype) then { + value_name = BigEndianReverse(value_name) + }; + let value_name = value_name; + return(value_name) +} + +val Mem_with_type_set : forall 'size, 'size * 8 >= 0. + (bits(32), int('size), AccessDescriptor, bits('size * 8)) -> unit + +val Mem_with_type_set__1 : forall ('ispair : Bool) 'size, 'size * 8 >= 0. + (bits(32), int('size), AccessDescriptor, bool('ispair), bits('size * 8)) -> unit + +function Mem_with_type_set (address, size, accdesc, value_in_name) = { + let ispair : bool = false; + Mem_with_type_set__1(address, size, accdesc, ispair) = value_in_name +} + +function Mem_with_type_set__1 (address, size, accdesc, ispair, value_in_name) = { + c : Constraint = undefined; + let 'halfsize = DIV(size, 2); + value_name : bits('size * 8) = value_in_name; + let 'alignment = if ispair then halfsize else size; + aligned : bool = IsAligned__1(address, alignment); + if not_bool(aligned) & AArch32_UnalignedAccessFaults(accdesc) then { + AArch32_Abort(address, AlignmentFault(accdesc)) + }; + if BigEndian(accdesc.acctype) then { + assert(constraint(('size * 8 == 8 | 'size * 8 == 16 | 'size * 8 == 32 | 'size * 8 == 64 | 'size * 8 == 128))); + value_name = BigEndianReverse(value_name) + }; + if aligned then { + assert(constraint('size in {1, 2, 4, 8, 16})); + AArch32_MemSingle_set__1(address, size, accdesc, aligned, ispair) = value_name + } else { + assert(size > 1); + AArch32_MemSingle_set(address, 1, accdesc, aligned) = value_name[7 .. 0]; + let c : Constraint = ConstrainUnpredictable(Unpredictable_DEVPAGE2); + assert(c == Constraint_FAULT | c == Constraint_NONE); + if c == Constraint_NONE then { + aligned = true + }; + foreach (i from 1 to (size - 1) by 1 in inc) { + AArch32_MemSingle_set(address + i, 1, accdesc, aligned) = value_name[8 * i + 7 .. 8 * i] + } + }; + return() +} + +val MemA_read : forall 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size)) -> bits(8 * 'size) + +function MemA_read (address, size) = { + let acqrel : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescExLDST(MemOp_LOAD, acqrel, tagchecked); + return(Mem_with_type_read(address, size, accdesc)) +} + +val MemA_set : forall 'size, 8 * 'size >= 0. + (bits(32), int('size), bits(8 * 'size)) -> unit + +function MemA_set (address, size, value_name) = { + let acqrel : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescExLDST(MemOp_STORE, acqrel, tagchecked); + Mem_with_type_set(address, size, accdesc) = value_name; + return() +} + +val MemU_read : forall 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size)) -> bits(8 * 'size) + +function MemU_read (address, size) = { + let nontemporal : bool = false; + let privileged : bool = PSTATE.EL != EL0; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescGPR(MemOp_LOAD, nontemporal, privileged, tagchecked); + return(Mem_with_type_read(address, size, accdesc)) +} + +val MemU_set : forall 'size, 8 * 'size >= 0. + (bits(32), int('size), bits(8 * 'size)) -> unit + +function MemU_set (address, size, value_name) = { + let nontemporal : bool = false; + let privileged : bool = PSTATE.EL != EL0; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescGPR(MemOp_STORE, nontemporal, privileged, tagchecked); + Mem_with_type_set(address, size, accdesc) = value_name; + return() +} + +val MemU_unpriv_read : forall 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size)) -> bits(8 * 'size) + +function MemU_unpriv_read (address, size) = { + let nontemporal : bool = false; + let privileged : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescGPR(MemOp_LOAD, nontemporal, privileged, tagchecked); + return(Mem_with_type_read(address, size, accdesc)) +} + +val MemU_unpriv_set : forall 'size, 8 * 'size >= 0. + (bits(32), int('size), bits(8 * 'size)) -> unit + +function MemU_unpriv_set (address, size, value_name) = { + let nontemporal : bool = false; + let privileged : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescGPR(MemOp_STORE, nontemporal, privileged, tagchecked); + Mem_with_type_set(address, size, accdesc) = value_name; + return() +} + +val MemO_read : forall 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size)) -> bits(8 * 'size) + +function MemO_read (address, size) = { + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescAcqRel(MemOp_LOAD, tagchecked); + return(Mem_with_type_read(address, size, accdesc)) +} + +val MemO_set : forall 'size, 8 * 'size >= 0. + (bits(32), int('size), bits(8 * 'size)) -> unit + +function MemO_set (address, size, value_name) = { + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescAcqRel(MemOp_STORE, tagchecked); + Mem_with_type_set(address, size, accdesc) = value_name; + return() +} + +val MemS_read : forall 'size, + 'size in {1, 2, 4, 8, 16}. + (bits(32), int('size)) -> bits(8 * 'size) + +function MemS_read (address, size) = { + let accdesc : AccessDescriptor = CreateAccDescA32LSMD(MemOp_LOAD); + return(Mem_with_type_read(address, size, accdesc)) +} + +val MemS_set : forall 'size, 8 * 'size >= 0. + (bits(32), int('size), bits(8 * 'size)) -> unit + +function MemS_set (address, size, value_name) = { + let accdesc : AccessDescriptor = CreateAccDescA32LSMD(MemOp_STORE); + Mem_with_type_set(address, size, accdesc) = value_name; + return() +} + +val AArch32_SetExclusiveMonitors : forall 'size. (bits(32), int('size)) -> unit + +function AArch32_SetExclusiveMonitors (address, size) = { + __ExclusiveMonitorSet = true; + let acqrel : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescExLDST(MemOp_LOAD, acqrel, tagchecked); + let aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) then { + AArch32_Abort(address, AlignmentFault(accdesc)) + }; + let memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + return() + }; + if memaddrdesc.memattrs.shareability != Shareability_NSH then { + MarkExclusiveGlobal(memaddrdesc.paddress, ProcessorID(), size) + }; + MarkExclusiveLocal(memaddrdesc.paddress, ProcessorID(), size); + AArch32_MarkExclusiveVA(address, ProcessorID(), size) +} + +val AArch32_ExclusiveMonitorsPass : forall 'size. (bits(32), int('size)) -> bool + +function AArch32_ExclusiveMonitorsPass (address, size) = { + let acqrel : bool = false; + let tagchecked : bool = false; + let accdesc : AccessDescriptor = CreateAccDescExLDST(MemOp_STORE, acqrel, tagchecked); + let aligned : bool = IsAligned__1(address, size); + if not_bool(aligned) then { + AArch32_Abort(address, AlignmentFault(accdesc)) + }; + if not_bool(AArch32_IsExclusiveVA(address, ProcessorID(), size)) then { + return(false) + }; + let memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(address, accdesc, aligned, size); + if IsFault(memaddrdesc) then { + AArch32_Abort(address, memaddrdesc.fault) + }; + passed : bool = IsExclusiveLocal(memaddrdesc.paddress, ProcessorID(), size); + ClearExclusiveLocal(ProcessorID()); + if passed & memaddrdesc.memattrs.shareability != Shareability_NSH then { + passed = IsExclusiveGlobal(memaddrdesc.paddress, ProcessorID(), size) + }; + return(passed) +} + +val S_read : forall 'n. int('n) -> bits(32) + +function S_read n = { + assert(n >= 0 & n <= 31); + let 'base = MOD(n, 4) * 32; + let vreg : bits(128) = V_read(DIV(n, 4), 128); + return(vreg[base + 31 .. base]) +} + +val S_set : forall 'n. (int('n), bits(32)) -> unit + +function S_set (n, value_name) = { + assert(n >= 0 & n <= 31); + let 'base = MOD(n, 4) * 32; + vreg : bits(128) = V_read(DIV(n, 4), 128); + vreg[base + 31 .. base] = value_name; + V_set(DIV(n, 4), 128) = vreg; + return() +} + +val D_set : forall 'n. (int('n), bits(64)) -> unit + +function D_set (n, value_name) = { + assert(n >= 0 & n <= 31); + let 'base = MOD(n, 2) * 64; + vreg : bits(128) = V_read(DIV(n, 2), 128); + vreg[base + 63 .. base] = value_name; + V_set(DIV(n, 2), 128) = vreg; + return() +} + +val Q_read : forall 'n. int('n) -> bits(128) + +function Q_read n = { + assert(n >= 0 & n <= 15); + return(V_read(n, 128)) +} + +val Q_set : forall 'n. (int('n), bits(128)) -> unit + +function Q_set (n, value_name) = { + assert(n >= 0 & n <= 15); + V_set(n, 128) = value_name; + return() +} + +val AArch32_ResetGeneralRegisters : unit -> unit + +function AArch32_ResetGeneralRegisters () = { + foreach (i from 0 to 7 by 1 in inc) { + R_set(i) = __UNKNOWN_bits(32) + }; + foreach (i from 8 to 12 by 1 in inc) { + Rmode_set(i, M32_User) = __UNKNOWN_bits(32); + Rmode_set(i, M32_FIQ) = __UNKNOWN_bits(32) + }; + if HaveEL(EL2) then { + Rmode_set(13, M32_Hyp) = __UNKNOWN_bits(32) + }; + foreach (i from 13 to 14 by 1 in inc) { + Rmode_set(i, M32_User) = __UNKNOWN_bits(32); + Rmode_set(i, M32_FIQ) = __UNKNOWN_bits(32); + Rmode_set(i, M32_IRQ) = __UNKNOWN_bits(32); + Rmode_set(i, M32_Svc) = __UNKNOWN_bits(32); + Rmode_set(i, M32_Abort) = __UNKNOWN_bits(32); + Rmode_set(i, M32_Undef) = __UNKNOWN_bits(32); + if HaveEL(EL3) then { + Rmode_set(i, M32_Monitor) = __UNKNOWN_bits(32) + }; + () + }; + return() +} + +val AArch32_ResetSIMDFPRegisters : unit -> unit + +function AArch32_ResetSIMDFPRegisters () = { + foreach (i from 0 to 15 by 1 in inc) { + Q_set(i) = __UNKNOWN_bits(128) + }; + return() +} + +val AArch32_ResetSpecialRegisters : unit -> unit + +function AArch32_ResetSpecialRegisters () = { + SPSR_fiq.bits[31 .. 0] = __UNKNOWN_bits(32); + SPSR_irq.bits[31 .. 0] = __UNKNOWN_bits(32); + SPSR_svc_write() = Mk_SPSR_svc_Type([SPSR_svc_read().bits with 31 .. 0 = __UNKNOWN_bits(32)]); + SPSR_abt.bits[31 .. 0] = __UNKNOWN_bits(32); + SPSR_und.bits[31 .. 0] = __UNKNOWN_bits(32); + if HaveEL(EL2) then { + SPSR_hyp_write() = Mk_SPSR_hyp_Type(__UNKNOWN_bits(32)); + ELR_hyp_write() = __UNKNOWN_bits(32) + }; + if HaveEL(EL3) then { + SPSR_mon = Mk_SPSR_mon_Type(__UNKNOWN_bits(32)) + }; + DLR_write() = __UNKNOWN_bits(32); + DSPSR_write() = Mk_DSPSR_Type(__UNKNOWN_bits(32)); + return() +} + +val AArch32_ExceptionReturn : (bits(32), bits(32)) -> unit + +function AArch32_ExceptionReturn (new_pc_in, spsr) = { + new_pc : bits(32) = new_pc_in; + SynchronizeContext(); + __InstructionStep = false; + SetPSTATEFromPSR(spsr); + ClearExclusiveLocal(ProcessorID()); + SendEventLocal(); + if PSTATE.IL == 0b1 then { + new_pc[1 .. 0] = __UNKNOWN_bits(2) + } else { + if PSTATE.T == 0b1 then { + new_pc[0] = Bit(0b0) + } else { + new_pc[1 .. 0] = 0b00 + } + }; + let branch_conditional : bool = not_bool((match AArch32_CurrentCond() { + [bitone, bitone, bitone, _] => true, + _ => false + }) : bool); + BranchTo(new_pc, BranchType_ERET, branch_conditional); + CheckExceptionCatch(false) +} + +val ALUExceptionReturn : bits(32) -> unit + +function ALUExceptionReturn address = { + if PSTATE.EL == EL2 then { + throw(Error_Undefined()) + } else if PSTATE.M == M32_User | PSTATE.M == M32_System then { + let c : Constraint = ConstrainUnpredictable(Unpredictable_ALUEXCEPTIONRETURN); + assert(c == Constraint_UNDEF | c == Constraint_NOP); + match c { + Constraint_UNDEF => { + throw(Error_Undefined()) + }, + Constraint_NOP => { + EndOfInstruction() + }, + _ => () + } + } else { + AArch32_ExceptionReturn(address, SPSR_read(32)) + } +} + +val SelectInstrSet : InstrSet -> unit + +function SelectInstrSet iset = { + assert(CurrentInstrSet() == InstrSet_A32 | CurrentInstrSet() == InstrSet_T32); + assert(iset == InstrSet_A32 | iset == InstrSet_T32); + PSTATE.T = if iset == InstrSet_A32 then 0b0 else 0b1; + return() +} + +val BXWritePC : (bits(32), BranchType) -> unit + +function BXWritePC (address_in, branch_type) = { + address : bits(32) = address_in; + if [address[0]] == 0b1 then { + SelectInstrSet(InstrSet_T32); + address[0] = Bit(0b0) + } else { + SelectInstrSet(InstrSet_A32); + if [address[1]] == 0b1 & ConstrainUnpredictableBool(Unpredictable_A32FORCEALIGNPC) then { + address[1] = Bit(0b0) + }; + () + }; + let branch_conditional : bool = not_bool((match AArch32_CurrentCond() { + [bitone, bitone, bitone, _] => true, + _ => false + }) : bool); + BranchTo(address, branch_type, branch_conditional) +} + +val BranchWritePC : (bits(32), BranchType) -> unit + +function BranchWritePC (address_in, branch_type) = { + address : bits(32) = address_in; + if CurrentInstrSet() == InstrSet_A32 then { + address[1 .. 0] = 0b00 + } else { + address[0] = Bit(0b0) + }; + let branch_conditional : bool = not_bool((match AArch32_CurrentCond() { + [bitone, bitone, bitone, _] => true, + _ => false + }) : bool); + BranchTo(address, branch_type, branch_conditional) +} + +val ALUWritePC : bits(32) -> unit + +function ALUWritePC address = { + if CurrentInstrSet() == InstrSet_A32 then { + BXWritePC(address, BranchType_INDIR) + } else { + BranchWritePC(address, BranchType_INDIR) + } +} + +val CBWritePC : bits(32) -> unit + +function CBWritePC address_in = { + address : bits(32) = address_in; + assert(CurrentInstrSet() == InstrSet_T32); + address[0] = Bit(0b0); + let branch_conditional : bool = true; + BranchTo(address, BranchType_DIR, branch_conditional) +} + +val LoadWritePC : bits(32) -> unit + +function LoadWritePC address = { + BXWritePC(address, BranchType_INDIR) +} + +val PCStoreValue : unit -> bits(32) + +function PCStoreValue () = { + return(PC_read__1()) +} + +val Din_read : forall 'n. int('n) -> bits(64) + +function Din_read n = { + assert(n >= 0 & n <= 31); + return(_Dclone[n]) +} + +val Qin_read : forall 'n. int('n) -> bits(128) + +function Qin_read n = { + assert(n >= 0 & n <= 15); + return(Din_read(2 * n + 1) @ Din_read(2 * n)) +} + +val AArch32_WriteModeByInstr : bits(5) -> unit + +function AArch32_WriteModeByInstr mode = { + el : bits(2) = undefined; + valid_name : bool = undefined; + (valid_name, el) = ELFromM32(mode); + if UInt(el) > UInt(PSTATE.EL) then { + valid_name = false + }; + if (PSTATE.M == M32_Hyp | mode == M32_Hyp) & PSTATE.M != mode then { + valid_name = false + }; + if (((PSTATE.M == M32_Monitor & HaveEL(EL2)) & el == EL1) & SCR[NS] == 0b1) & HCR_read()[TGE] == 0b1 then { + valid_name = false + }; + let valid_name = valid_name; + if not_bool(valid_name) then { + PSTATE.IL = 0b1 + } else { + AArch32_WriteMode(mode) + } +} + +val BankedRegisterAccessValid : (bits(5), bits(5)) -> unit + +function BankedRegisterAccessValid (SYSm, mode) = { + match SYSm { + [bitzero, bitzero, bitzero, _, _] => { + if mode != M32_FIQ then { + throw(Error_Unpredictable()) + }; + () + }, + 0b00100 => { + if mode != M32_FIQ then { + throw(Error_Unpredictable()) + }; + () + }, + 0b00101 => { + if mode == M32_System then { + throw(Error_Unpredictable()) + }; + () + }, + 0b00110 => { + if mode == M32_Hyp | mode == M32_System then { + throw(Error_Unpredictable()) + }; + () + }, + [bitzero, bitone, bitzero, _, _] => { + if mode == M32_FIQ then { + throw(Error_Unpredictable()) + }; + () + }, + [bitzero, bitone, bitone, bitzero, _] => { + if mode == M32_FIQ then { + throw(Error_Unpredictable()) + }; + () + }, + 0b01110 => { + if mode == M32_FIQ then { + throw(Error_Unpredictable()) + }; + () + }, + [bitone, bitzero, bitzero, bitzero, _] => { + if mode == M32_IRQ then { + throw(Error_Unpredictable()) + }; + () + }, + [bitone, bitzero, bitzero, bitone, _] => { + if mode == M32_Svc then { + throw(Error_Unpredictable()) + }; + () + }, + [bitone, bitzero, bitone, bitzero, _] => { + if mode == M32_Abort then { + throw(Error_Unpredictable()) + }; + () + }, + [bitone, bitzero, bitone, bitone, _] => { + if mode == M32_Undef then { + throw(Error_Unpredictable()) + }; + () + }, + [bitone, bitone, bitone, bitzero, _] => { + if (not_bool(HaveEL(EL3)) | CurrentSecurityState() != SS_Secure) | mode == M32_Monitor then { + throw(Error_Unpredictable()) + }; + () + }, + 0b11110 => { + if not_bool(HaveEL(EL2)) | not_bool(mode == M32_Monitor | mode == M32_Hyp) then { + throw(Error_Unpredictable()) + }; + () + }, + 0b11111 => { + if not_bool(HaveEL(EL2)) | mode != M32_Monitor then { + throw(Error_Unpredictable()) + }; + () + }, + _ => { + throw(Error_Unpredictable()) + } + }; + return() +} + +val ConditionPassed : unit -> bool + +function ConditionPassed () = { + return(ConditionHolds(AArch32_CurrentCond())) +} + +val CPSRWriteByInstr : (bits(32), bits(4)) -> unit + +function CPSRWriteByInstr (value_name, bytemask) = { + let privileged : bool = PSTATE.EL != EL0; + if [bytemask[3]] == 0b1 then { + (PSTATE.N @ PSTATE.Z @ PSTATE.C @ PSTATE.V @ PSTATE.Q) = value_name[31 .. 27] + }; + if [bytemask[2]] == 0b1 then { + if HaveSSBSExt() then { + PSTATE.SSBS = [value_name[23]] + }; + if privileged then { + PSTATE.PAN = [value_name[22]] + }; + if HaveDITExt() then { + PSTATE.DIT = [value_name[21]] + }; + PSTATE.GE = value_name[19 .. 16] + }; + if [bytemask[1]] == 0b1 then { + PSTATE.E = [value_name[9]]; + if privileged then { + PSTATE.A = [value_name[8]] + }; + () + }; + if [bytemask[0]] == 0b1 then { + if privileged then { + (PSTATE.I @ PSTATE.F) = value_name[7 .. 6]; + AArch32_WriteModeByInstr(value_name[4 .. 0]) + }; + () + }; + return() +} + +val InITBlock : unit -> bool + +function InITBlock () = { + if CurrentInstrSet() == InstrSet_T32 then { + return(PSTATE.IT[3 .. 0] != 0b0000) + } else { + return(false) + } +} + +val LastInITBlock : unit -> bool + +function LastInITBlock () = { + return(PSTATE.IT[3 .. 0] == 0b1000) +} + +val SPSRaccessValid : (bits(5), bits(5)) -> unit + +function SPSRaccessValid (SYSm, mode) = { + match SYSm { + 0b01110 => { + if mode == M32_FIQ then { + throw(Error_Unpredictable()) + }; + () + }, + 0b10000 => { + if mode == M32_IRQ then { + throw(Error_Unpredictable()) + }; + () + }, + 0b10010 => { + if mode == M32_Svc then { + throw(Error_Unpredictable()) + }; + () + }, + 0b10100 => { + if mode == M32_Abort then { + throw(Error_Unpredictable()) + }; + () + }, + 0b10110 => { + if mode == M32_Undef then { + throw(Error_Unpredictable()) + }; + () + }, + 0b11100 => { + if (not_bool(HaveEL(EL3)) | mode == M32_Monitor) | CurrentSecurityState() != SS_Secure then { + throw(Error_Unpredictable()) + }; + () + }, + 0b11110 => { + if not_bool(HaveEL(EL2)) | mode != M32_Monitor then { + throw(Error_Unpredictable()) + }; + () + }, + _ => { + throw(Error_Unpredictable()) + } + }; + return() +} + +val SPSRWriteByInstr : (bits(32), bits(4)) -> unit + +function SPSRWriteByInstr (value_name, bytemask) = { + new_spsr : bits(32) = SPSR_read(32); + if [bytemask[3]] == 0b1 then { + new_spsr[31 .. 24] = value_name[31 .. 24] + }; + if [bytemask[2]] == 0b1 then { + new_spsr[23 .. 16] = value_name[23 .. 16] + }; + if [bytemask[1]] == 0b1 then { + new_spsr[15 .. 8] = value_name[15 .. 8] + }; + if [bytemask[0]] == 0b1 then { + new_spsr[7 .. 0] = value_name[7 .. 0] + }; + SPSR_set(32) = new_spsr; + return() +} + +val AArch32_SysRegReadCanWriteAPSR : forall 'cp_num. + (int('cp_num), bits(32)) -> bool + +function AArch32_SysRegReadCanWriteAPSR (cp_num, instr) = { + assert(UsingAArch32()); + assert(cp_num == 14 | cp_num == 15); + assert(cp_num == UInt(instr[11 .. 8])); + let 'opc1 = UInt(instr[23 .. 21]); + let 'opc2 = UInt(instr[7 .. 5]); + let 'CRn = UInt(instr[19 .. 16]); + let 'CRm = UInt(instr[3 .. 0]); + if (((cp_num == 14 & opc1 == 0) & CRn == 0) & CRm == 1) & opc2 == 0 then { + return(true) + }; + return(false) +} + +val UnsignedSat : forall 'N 'i, 0 <= 'N - 1. (int('i), int('N)) -> bits('N) + +function UnsignedSat (i, N) = { + result : bits('N) = undefined; + let (__tup_0 : bits('N), _) = UnsignedSatQ(i, N) in + { + result = __tup_0 + }; + return(result) +} + +val SignedSat : forall 'N 'i, 0 <= 'N - 1. (int('i), int('N)) -> bits('N) + +function SignedSat (i, N) = { + result : bits('N) = undefined; + let (__tup_0 : bits('N), _) = SignedSatQ(i, N) in + { + result = __tup_0 + }; + return(result) +} + +val Sat : forall 'N 'i ('is_unsigned : Bool), + 'N >= 0. + (int('i), int('N), bool('is_unsigned)) -> bits('N) + +function Sat (i, N, is_unsigned) = { + let result : bits('N) = if is_unsigned then { + assert(constraint(0 <= 'N - 1)); + UnsignedSat(i, N) + } else { + assert(constraint(0 <= 'N - 1)); + SignedSat(i, N) + }; + return(result) +} + +val AArch32_ESBOperation : unit -> unit + +function AArch32_ESBOperation () = { + el : bits(2) = undefined; + route_to_aarch64 : bool = PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)); + if (not_bool(route_to_aarch64) & EL2Enabled()) & not_bool(ELUsingAArch32(EL2)) then { + route_to_aarch64 = HCR_EL2[TGE] == 0b1 | HCR_EL2[AMO] == 0b1 + }; + if (not_bool(route_to_aarch64) & HaveEL(EL3)) & not_bool(ELUsingAArch32(EL3)) then { + route_to_aarch64 = EffectiveEA() == 0b1 + }; + if route_to_aarch64 then { + AArch64_ESBOperation(); + return() + }; + let route_to_monitor : bool = (HaveEL(EL3) & ELUsingAArch32(EL3)) & EffectiveEA() == 0b1; + let route_to_hyp : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_read()[TGE] == 0b1 | HCR_read()[AMO] == 0b1); + target : bits(5) = undefined; + if route_to_monitor then { + target = M32_Monitor + } else if route_to_hyp | PSTATE.M == M32_Hyp then { + target = M32_Hyp + } else { + target = M32_Abort + }; + mask_active : bool = undefined; + if CurrentSecurityState() == SS_Secure then { + mask_active = true + } else if target == M32_Monitor then { + mask_active = SCR[AW] == 0b1 & (not_bool(HaveEL(EL2)) | HCR_read()[TGE] == 0b0 & HCR_read()[AMO] == 0b0) + } else { + mask_active = target == M32_Abort | PSTATE.M == M32_Hyp + }; + let mask_set : bool = PSTATE.A == 0b1; + let (_, __tup_1 : bits(2)) = ELFromM32(target) in + { + el = __tup_1 + }; + let intdis : bool = Halted() | ExternalDebugInterruptsDisabled(el); + let masked : bool = intdis | mask_active & mask_set; + if masked & IsSynchronizablePhysicalSErrorPending() then { + syndrome : bits(32) = Zeros(32); + syndrome[31] = Bit(0b1); + syndrome[15 .. 0] = AArch32_PhysicalSErrorSyndrome(); + DISR_write() = Mk_DISR_Type(syndrome); + ClearPendingPhysicalSError() + }; + return() +} + +val AArch32_vESBOperation : unit -> unit + +function AArch32_vESBOperation () = { + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + if not_bool(ELUsingAArch32(EL2)) then { + AArch64_vESBOperation(); + return() + }; + let vSEI_enabled : bool = HCR_read()[TGE] == 0b0 & HCR_read()[AMO] == 0b1; + let vSEI_pending : bool = vSEI_enabled & HCR_read()[VA] == 0b1; + let vintdis : bool = Halted() | ExternalDebugInterruptsDisabled(EL1); + let vmasked : bool = vintdis | PSTATE.A == 0b1; + if vSEI_pending & vmasked then { + syndrome : bits(32) = Zeros(32); + syndrome[31] = Bit(0b1); + syndrome[15 .. 14] = VDFSR_read().bits[15 .. 14]; + syndrome[12] = Bit([VDFSR_read().bits[12]]); + syndrome[9] = Bit(TTBCR_read()[EAE]); + if TTBCR_read()[EAE] == 0b1 then { + syndrome[5 .. 0] = 0b010001 + } else { + (syndrome[10 .. 10] @ syndrome[3 .. 0]) = 0b10110 + }; + VDISR_write() = Mk_VDISR_Type(syndrome); + HCR_write() = [HCR_read() with VA = 0b0] + }; + return() +} + +val AArch32_TakeReset : forall ('cold_reset : Bool). bool('cold_reset) -> unit + +function AArch32_TakeReset cold_reset = { + assert(not_bool(HaveAArch64())); + if HaveEL(EL3) then { + AArch32_WriteMode(M32_Svc); + SCR[NS] = 0b0 + } else if HaveEL(EL2) then { + AArch32_WriteMode(M32_Hyp) + } else { + AArch32_WriteMode(M32_Svc) + }; + AArch32_ResetControlRegisters(cold_reset); + FPEXC_write() = [FPEXC_read() with EN = 0b0]; + (PSTATE.A @ PSTATE.I @ PSTATE.F) = 0b111; + PSTATE.IT = 0b00000000; + if HaveEL(EL2) & not_bool(HaveEL(EL3)) then { + PSTATE.T = HSCTLR_read()[TE]; + PSTATE.E = HSCTLR_read()[EE] + } else { + PSTATE.T = SCTLR_read__2()[TE]; + PSTATE.E = SCTLR_read__2()[EE] + }; + PSTATE.IL = 0b0; + AArch32_ResetGeneralRegisters(); + AArch32_ResetSIMDFPRegisters(); + AArch32_ResetSpecialRegisters(); + ResetExternalDebugRegisters(cold_reset); + rv : bits(32) = undefined; + if HaveEL(EL3) then { + if [MVBAR.bits[0]] == 0b1 then { + rv = MVBAR.bits[31 .. 1] @ 0b0 + } else { + rv = __IMPDEF_bits(32, "reset vector address") + } + } else { + rv = RVBAR[31 .. 1] @ 0b0 + }; + assert([rv[0]] == 0b0 & (PSTATE.T == 0b1 | [rv[1]] == 0b0)); + let branch_conditional : bool = false; + BranchTo(rv, BranchType_RESET, branch_conditional) +} + +val AArch32_CheckAdvSIMDOrFPRegisterTraps : bits(4) -> unit + +function AArch32_CheckAdvSIMDOrFPRegisterTraps reg = { + tid0 : bits(1) = undefined; + tid3 : bits(1) = undefined; + if PSTATE.EL == EL1 & EL2Enabled() then { + let tid0 : bits(1) = if ELUsingAArch32(EL2) then HCR_read()[TID0] else + HCR_EL2[TID0]; + let tid3 : bits(1) = if ELUsingAArch32(EL2) then HCR_read()[TID3] else + HCR_EL2[TID3]; + if tid0 == 0b1 & reg == 0b0000 | tid3 == 0b1 & (reg == 0b0101 | reg == 0b0110 | reg == 0b0111) then { + if ELUsingAArch32(EL2) then { + AArch32_SystemAccessTrap(M32_Hyp, UInt(0x8)) + } else { + AArch64_AArch32SystemAccessTrap(EL2, UInt(0x8)) + } + }; + () + }; + () +} + +val AArch32_TakeSMCException : unit -> unit + +function AArch32_TakeSMCException () = { + assert(HaveEL(EL3) & ELUsingAArch32(EL3)); + AArch32_ITAdvance(); + SSAdvance(); + let preferred_exception_return : bits(32) = NextInstrAddr(32); + let 'vect_offset = UInt(0x08); + let 'lr_offset = 0; + AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset) +} + +val AArch32_TakeHVCException : bits(16) -> unit + +function AArch32_TakeHVCException immediate = { + assert(HaveEL(EL2) & ELUsingAArch32(EL2)); + AArch32_ITAdvance(); + SSAdvance(); + let preferred_exception_return : bits(32) = NextInstrAddr(32); + let 'vect_offset = UInt(0x08); + except : ExceptionRecord = ExceptionSyndrome(Exception_HypervisorCall); + except.syndrome[15 .. 0] = immediate; + if PSTATE.EL == EL2 then { + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterHypMode(except, preferred_exception_return, UInt(0x14)) + } +} + +val AArch32_CallHypervisor : bits(16) -> unit + +function AArch32_CallHypervisor immediate = { + assert(HaveEL(EL2)); + if not_bool(ELUsingAArch32(EL2)) then { + AArch64_CallHypervisor(immediate) + } else { + AArch32_TakeHVCException(immediate) + } +} + +val AArch32_TakeSVCException : bits(16) -> unit + +function AArch32_TakeSVCException immediate = { + except : ExceptionRecord = undefined; + AArch32_ITAdvance(); + SSAdvance(); + let route_to_hyp : bool = (PSTATE.EL == EL0 & EL2Enabled()) & HCR_read()[TGE] == 0b1; + let preferred_exception_return : bits(32) = NextInstrAddr(32); + let 'vect_offset = UInt(0x08); + let 'lr_offset = 0; + if PSTATE.EL == EL2 | route_to_hyp then { + except : ExceptionRecord = ExceptionSyndrome(Exception_SupervisorCall); + except.syndrome[15 .. 0] = immediate; + if PSTATE.EL == EL2 then { + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterHypMode(except, preferred_exception_return, UInt(0x14)) + } + } else { + AArch32_EnterMode(M32_Svc, preferred_exception_return, lr_offset, vect_offset) + } +} + +val AArch32_CallSupervisor : bits(16) -> unit + +function AArch32_CallSupervisor immediate_in = { + immediate : bits(16) = immediate_in; + if AArch32_CurrentCond() != 0b1110 then { + immediate = __UNKNOWN_bits(16) + }; + if AArch32_GeneralExceptionsToAArch64() then { + AArch64_CallSupervisor(immediate) + } else { + AArch32_TakeSVCException(immediate) + } +} + +val AArch32_TakeMonitorTrapException : unit -> unit + +function AArch32_TakeMonitorTrapException () = { + assert(HaveEL(EL3) & ELUsingAArch32(EL3)); + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x04); + let 'lr_offset = if CurrentInstrSet() == InstrSet_A32 then 4 else 2; + AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset) +} + +val AArch32_UndefinedFault : unit -> unit + +function AArch32_UndefinedFault () = { + if AArch32_GeneralExceptionsToAArch64() then { + AArch64_UndefinedFault() + }; + AArch32_TakeUndefInstrException() +} + +val AArch32_CheckIllegalState : unit -> unit + +function AArch32_CheckIllegalState () = { + except : ExceptionRecord = undefined; + route_to_hyp : bool = undefined; + vect_offset : int = undefined; + if AArch32_GeneralExceptionsToAArch64() then { + AArch64_CheckIllegalState() + } else if PSTATE.IL == 0b1 then { + let route_to_hyp : bool = (PSTATE.EL == EL0 & EL2Enabled()) & HCR_read()[TGE] == 0b1; + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x04); + if PSTATE.EL == EL2 | route_to_hyp then { + let except : ExceptionRecord = ExceptionSyndrome(Exception_IllegalState); + if PSTATE.EL == EL2 then { + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterHypMode(except, preferred_exception_return, UInt(0x14)) + } + } else { + AArch32_TakeUndefInstrException() + } + } else () +} + +val AArch32_CheckForSVCTrap : bits(16) -> unit + +function AArch32_CheckForSVCTrap immediate = { + except : ExceptionRecord = undefined; + route_to_el2 : bool = undefined; + vect_offset : int = undefined; + if HaveFGTExt() then { + route_to_el2 : bool = false; + if PSTATE.EL == EL0 then { + route_to_el2 = ((not_bool(ELUsingAArch32(EL1)) & EL2Enabled()) & HFGITR_EL2[SVC_EL0] == 0b1) & (HCR_EL2[E2H] @ HCR_EL2[TGE]) != 0b11 & (not_bool(HaveEL(EL3)) | SCR_EL3[FGTEn] == 0b1) + }; + if route_to_el2 then { + except : ExceptionRecord = ExceptionSyndrome(Exception_SupervisorCall); + except.syndrome[15 .. 0] = immediate; + except.trappedsyscallinst = true; + let preferred_exception_return : bits(64) = ThisInstrAddr(64); + let 'vect_offset = UInt(0x0); + AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset) + }; + () + }; + let route_to_el2 = route_to_el2; + () +} + +val AArch32_CheckForSMCUndefOrTrap : unit -> unit + +function AArch32_CheckForSMCUndefOrTrap () = { + except : ExceptionRecord = undefined; + route_to_hyp : bool = undefined; + if not_bool(HaveEL(EL3)) | PSTATE.EL == EL0 then { + throw(Error_Undefined()) + }; + if EL2Enabled() & not_bool(ELUsingAArch32(EL2)) then { + AArch64_CheckForSMCUndefOrTrap(Zeros(16)) + } else { + let route_to_hyp : bool = (EL2Enabled() & PSTATE.EL == EL1) & HCR_read()[TSC] == 0b1; + if route_to_hyp then { + let except : ExceptionRecord = ExceptionSyndrome(Exception_MonitorCall); + AArch32_TakeHypTrapException__1(except) + }; + () + } +} + +val AArch32_CheckForWFxTrap : (bits(2), WFxType) -> unit + +function AArch32_CheckForWFxTrap (target_el, wfxtype) = { + except : ExceptionRecord = undefined; + assert(HaveEL(target_el)); + if not_bool(ELUsingAArch32(target_el)) then { + AArch64_CheckForWFxTrap(target_el, wfxtype); + return() + }; + let is_wfe : bool = wfxtype == WFxType_WFE; + trap : bool = undefined; + match target_el { + ? if ? == EL1 => { + trap = (if is_wfe then SCTLR_read__2()[nTWE] else + SCTLR_read__2()[nTWI]) == 0b0 + }, + ? if ? == EL2 => { + trap = (if is_wfe then HCR_read()[TWE] else HCR_read()[TWI]) == 0b1 + }, + ? if ? == EL3 => { + trap = (if is_wfe then SCR[TWE] else SCR[TWI]) == 0b1 + }, + _ => () + }; + if trap then { + if ((target_el == EL1 & EL2Enabled()) & not_bool(ELUsingAArch32(EL2))) & HCR_EL2[TGE] == 0b1 then { + AArch64_WFxTrap(wfxtype, target_el) + }; + if target_el == EL3 then { + AArch32_TakeMonitorTrapException() + } else if target_el == EL2 then { + except : ExceptionRecord = ExceptionSyndrome(Exception_WFxTrap); + except.syndrome[24 .. 20] = ConditionSyndrome(); + match wfxtype { + WFxType_WFI => { + except.syndrome[0] = Bit(0b0) + }, + WFxType_WFE => { + except.syndrome[0] = Bit(0b1) + }, + _ => () + }; + AArch32_TakeHypTrapException__1(except) + } else { + AArch32_TakeUndefInstrException() + } + }; + () +} + +val AArch32_CheckITEnabled : bits(4) -> unit + +function AArch32_CheckITEnabled mask = { + accdesc : AccessDescriptor = undefined; + aligned : bool = undefined; + next_instr : bits(16) = undefined; + it_disabled : bits(1) = undefined; + if PSTATE.EL == EL2 then { + it_disabled = HSCTLR_read()[ITD] + } else { + it_disabled = if ELUsingAArch32(EL1) then SCTLR_read__2()[ITD] else + SCTLR_read__1()[ITD] + }; + if it_disabled == 0b1 then { + if mask != 0b1000 then { + throw(Error_Undefined()) + }; + let accdesc : AccessDescriptor = CreateAccDescIFetch(); + let aligned : bool = true; + let next_instr : bits(16) = AArch32_MemSingle_read(NextInstrAddr(32), 2, accdesc, aligned); + if (match next_instr { + [bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _, _, _] => true, + [bitone, bitzero, bitone, bitone, _, _, _, _, _, _, _, _, _, _, _, _] => true, + [bitone, bitzero, bitone, bitzero, bitzero, _, _, _, _, _, _, _, _, _, _, _] => true, + [bitzero, bitone, bitzero, bitzero, bitone, _, _, _, _, _, _, _, _, _, _, _] => true, + [bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, _, bitone, bitone, bitone, bitone, _, _, _] => true, + [bitzero, bitone, bitzero, bitzero, bitzero, bitone, _, _, bitone, _, _, _, _, bitone, bitone, bitone] => true, + _ => false + }) : bool then { + throw(Error_Undefined()) + }; + () + }; + return() +} + +val AArch32_CheckSETENDEnabled : unit -> unit + +function AArch32_CheckSETENDEnabled () = { + setend_disabled : bits(1) = undefined; + if PSTATE.EL == EL2 then { + setend_disabled = HSCTLR_read()[SED] + } else { + setend_disabled = if ELUsingAArch32(EL1) then SCTLR_read__2()[SED] else + SCTLR_read__1()[SED] + }; + if setend_disabled == 0b1 then { + throw(Error_Undefined()) + }; + let setend_disabled = setend_disabled; + return() +} + +val AArch32_TakePhysicalSErrorException : forall ('implicit_esb : Bool). + bool('implicit_esb) -> unit + +function AArch32_TakePhysicalSErrorException implicit_esb = { + route_to_aarch64 : bool = PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)); + if (not_bool(route_to_aarch64) & EL2Enabled()) & not_bool(ELUsingAArch32(EL2)) then { + route_to_aarch64 = HCR_EL2[TGE] == 0b1 | not_bool(IsInHost()) & HCR_EL2[AMO] == 0b1 + }; + if (not_bool(route_to_aarch64) & HaveEL(EL3)) & not_bool(ELUsingAArch32(EL3)) then { + route_to_aarch64 = EffectiveEA() == 0b1 + }; + if route_to_aarch64 then { + AArch64_TakePhysicalSErrorException(implicit_esb) + }; + let route_to_monitor : bool = HaveEL(EL3) & SCR[EA] == 0b1; + let route_to_hyp : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_read()[TGE] == 0b1 | HCR_read()[AMO] == 0b1); + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x10); + let 'lr_offset = 8; + target_el : bits(2) = undefined; + if route_to_monitor then { + target_el = EL3 + } else if PSTATE.EL == EL2 | route_to_hyp then { + target_el = EL2 + } else { + target_el = EL1 + }; + let fault : FaultRecord = GetPendingPhysicalSError(); + let vaddress : bits(32) = __UNKNOWN_bits(32); + let except : ExceptionRecord = AArch32_AbortSyndrome(Exception_DataAbort, fault, vaddress, target_el); + if IsSErrorEdgeTriggered() then { + ClearPendingPhysicalSError() + }; + match target_el { + ? if ? == EL3 => { + AArch32_ReportDataAbort(route_to_monitor, fault, vaddress); + AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset) + }, + ? if ? == EL2 => { + if PSTATE.EL == EL2 then { + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterHypMode(except, preferred_exception_return, UInt(0x14)) + } + }, + ? if ? == EL1 => { + AArch32_ReportDataAbort(route_to_monitor, fault, vaddress); + AArch32_EnterMode(M32_Abort, preferred_exception_return, lr_offset, vect_offset) + }, + _ => { + Unreachable() + } + } +} + +val AArch32_TakeVirtualSErrorException : unit -> unit + +function AArch32_TakeVirtualSErrorException () = { + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + if ELUsingAArch32(EL2) then { + assert(HCR_read()[TGE] == 0b0 & HCR_read()[AMO] == 0b1) + } else { + assert(HCR_EL2[TGE] == 0b0 & HCR_EL2[AMO] == 0b1) + }; + if PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)) then { + AArch64_TakeVirtualSErrorException() + }; + let route_to_monitor : bool = false; + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x10); + let 'lr_offset = 8; + let vaddress : bits(32) = __UNKNOWN_bits(32); + let parity : bool = false; + let fault : Fault = Fault_AsyncExternal; + let 'level = __UNKNOWN_integer(); + fsr : bits(32) = Zeros(32); + if HaveRASExt() then { + if ELUsingAArch32(EL2) then { + fsr[15 .. 14] = VDFSR_read()[AET]; + fsr[12] = Bit(VDFSR_read()[ExT]) + } else { + fsr[15 .. 14] = VSESR_EL2[AET]; + fsr[12] = Bit(VSESR_EL2[ExT]) + } + } else { + fsr[12] = Bit(__IMPDEF_bit("Virtual External abort type")) + }; + if TTBCR_read()[EAE] == 0b1 then { + fsr[9] = Bit(0b1); + fsr[5 .. 0] = EncodeLDFSC(fault, level) + } else { + fsr[9] = Bit(0b0); + (fsr[10 .. 10] @ fsr[3 .. 0]) = EncodeSDFSC(fault, level) + }; + DFSR_write() = Mk_DFSR_Type(fsr); + DFAR_write() = __UNKNOWN_bits(32); + ClearPendingVirtualSError(); + AArch32_EnterMode(M32_Abort, preferred_exception_return, lr_offset, vect_offset) +} + +val AArch32_TakePhysicalIRQException : unit -> unit + +function AArch32_TakePhysicalIRQException () = { + except : ExceptionRecord = undefined; + route_to_aarch64 : bool = PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)); + if (not_bool(route_to_aarch64) & EL2Enabled()) & not_bool(ELUsingAArch32(EL2)) then { + route_to_aarch64 = HCR_EL2[TGE] == 0b1 | HCR_EL2[IMO] == 0b1 & not_bool(IsInHost()) + }; + if (not_bool(route_to_aarch64) & HaveEL(EL3)) & not_bool(ELUsingAArch32(EL3)) then { + route_to_aarch64 = SCR_EL3[IRQ] == 0b1 + }; + if route_to_aarch64 then { + AArch64_TakePhysicalIRQException() + }; + let route_to_monitor : bool = HaveEL(EL3) & SCR[IRQ] == 0b1; + let route_to_hyp : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_read()[TGE] == 0b1 | HCR_read()[IMO] == 0b1); + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x18); + let 'lr_offset = 4; + if route_to_monitor then { + AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset) + } else if PSTATE.EL == EL2 | route_to_hyp then { + let except : ExceptionRecord = ExceptionSyndrome(Exception_IRQ); + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterMode(M32_IRQ, preferred_exception_return, lr_offset, vect_offset) + } +} + +val AArch32_TakeVirtualIRQException : unit -> unit + +function AArch32_TakeVirtualIRQException () = { + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + if ELUsingAArch32(EL2) then { + assert(HCR_read()[TGE] == 0b0 & HCR_read()[IMO] == 0b1) + } else { + assert(HCR_EL2[TGE] == 0b0 & HCR_EL2[IMO] == 0b1) + }; + if PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)) then { + AArch64_TakeVirtualIRQException() + }; + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x18); + let 'lr_offset = 4; + AArch32_EnterMode(M32_IRQ, preferred_exception_return, lr_offset, vect_offset) +} + +val AArch32_TakePhysicalFIQException : unit -> unit + +function AArch32_TakePhysicalFIQException () = { + except : ExceptionRecord = undefined; + route_to_aarch64 : bool = PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)); + if (not_bool(route_to_aarch64) & EL2Enabled()) & not_bool(ELUsingAArch32(EL2)) then { + route_to_aarch64 = HCR_EL2[TGE] == 0b1 | HCR_EL2[FMO] == 0b1 & not_bool(IsInHost()) + }; + if (not_bool(route_to_aarch64) & HaveEL(EL3)) & not_bool(ELUsingAArch32(EL3)) then { + route_to_aarch64 = SCR_EL3[FIQ] == 0b1 + }; + if route_to_aarch64 then { + AArch64_TakePhysicalFIQException() + }; + let route_to_monitor : bool = HaveEL(EL3) & SCR[FIQ] == 0b1; + let route_to_hyp : bool = ((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()) & (HCR_read()[TGE] == 0b1 | HCR_read()[FMO] == 0b1); + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x1C); + let 'lr_offset = 4; + if route_to_monitor then { + AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset) + } else if PSTATE.EL == EL2 | route_to_hyp then { + let except : ExceptionRecord = ExceptionSyndrome(Exception_FIQ); + AArch32_EnterHypMode(except, preferred_exception_return, vect_offset) + } else { + AArch32_EnterMode(M32_FIQ, preferred_exception_return, lr_offset, vect_offset) + } +} + +val AArch32_TakeVirtualFIQException : unit -> unit + +function AArch32_TakeVirtualFIQException () = { + assert((PSTATE.EL == EL0 | PSTATE.EL == EL1) & EL2Enabled()); + if ELUsingAArch32(EL2) then { + assert(HCR_read()[TGE] == 0b0 & HCR_read()[FMO] == 0b1) + } else { + assert(HCR_EL2[TGE] == 0b0 & HCR_EL2[FMO] == 0b1) + }; + if PSTATE.EL == EL0 & not_bool(ELUsingAArch32(EL1)) then { + AArch64_TakeVirtualFIQException() + }; + let preferred_exception_return : bits(32) = ThisInstrAddr(32); + let 'vect_offset = UInt(0x1C); + let 'lr_offset = 4; + AArch32_EnterMode(M32_FIQ, preferred_exception_return, lr_offset, vect_offset) +} + +val AArch32_SoftwareBreakpoint : bits(16) -> unit + +function AArch32_SoftwareBreakpoint immediate = { + if (EL2Enabled() & not_bool(ELUsingAArch32(EL2))) & (HCR_EL2[TGE] == 0b1 | MDCR_EL2[TDE] == 0b1) | not_bool(ELUsingAArch32(EL1)) then { + AArch64_SoftwareBreakpoint(immediate) + }; + let accdesc : AccessDescriptor = CreateAccDescIFetch(); + fault : FaultRecord = NoFault__1(accdesc); + let vaddress : bits(32) = __UNKNOWN_bits(32); + fault.statuscode = Fault_Debug; + fault.debugmoe = DebugException_BKPT; + AArch32_Abort(vaddress, fault) +} + +val AArch32_CheckPCAlignment : unit -> unit + +function AArch32_CheckPCAlignment () = { + let pc : bits(32) = ThisInstrAddr(32); + if CurrentInstrSet() == InstrSet_A32 & [pc[1]] == 0b1 | [pc[0]] == 0b1 then { + if AArch32_GeneralExceptionsToAArch64() then { + AArch64_PCAlignmentFault() + }; + let accdesc : AccessDescriptor = CreateAccDescIFetch(); + fault : FaultRecord = NoFault__1(accdesc); + fault.statuscode = Fault_Alignment; + AArch32_Abort(pc, fault) + }; + () +} + +type PMEVCNTR_Type = bits(32) + +register _PMEVCNTR : vector(31, PMEVCNTR_Type) + +val PMEVCNTR_read : forall 'n, (0 <= 'n & 'n < 31). int('n) -> PMEVCNTR_Type + +function PMEVCNTR_read n = { + r : PMEVCNTR_Type = _PMEVCNTR[n]; + r[31 .. 0] = Slice(PMEVCNTR_EL0[n], 0, 32); + return(r) +} + +val PMEVCNTR_set : forall 'n, (0 <= 'n & 'n < 31). + (int('n), PMEVCNTR_Type) -> unit + +function PMEVCNTR_set (n, value_name) = { + let r : PMEVCNTR_Type = value_name; + PMEVCNTR_EL0[n][31 .. 0] = Slice(r, 0, 32); + _PMEVCNTR[n] = r; + return() +} + +val PMOVSR_write : PMOVSR_Type -> unit + +function PMOVSR_write value_name = { + let r : PMOVSR_Type = value_name; + PMOVSCLR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMOVSR = r; + return() +} + +bitfield PMOVSSET_Type : bits(32) = + { + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMOVSSET : PMOVSSET_Type + +val PMOVSSET_read : unit -> PMOVSSET_Type + +function PMOVSSET_read () = { + r : PMOVSSET_Type = _PMOVSSET; + r.bits[31 .. 0] = Slice(PMOVSSET_EL0.bits, 0, 32); + return(r) +} + +val PMOVSSET_write : PMOVSSET_Type -> unit + +function PMOVSSET_write value_name = { + let r : PMOVSSET_Type = value_name; + PMOVSSET_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMOVSSET = r; + return() +} + +val AArch32_IncrementEventCounter : forall 'idx 'increment_name, + (0 <= 'idx & 'idx < 31). + (int('idx), int('increment_name)) -> unit + +function AArch32_IncrementEventCounter (idx, increment_name) = { + if HaveAArch64() then { + assert(constraint(0 <= 'idx)); + assert(constraint('idx < 31)); + AArch64_IncrementEventCounter(idx, increment_name); + return() + }; + let 'old_value = UInt(PMEVCNTR_read(idx)); + let 'new_value = old_value + PMUCountValue(idx, increment_name); + PMEVCNTR_set(idx) = new_value[31 .. 0]; + let 'ovflw = 32; + if old_value[64 .. ovflw] != new_value[64 .. ovflw] then { + PMOVSSET_write() = Mk_PMOVSSET_Type([PMOVSSET_read().bits with idx .. idx = 0b1]); + PMOVSR_write() = Mk_PMOVSR_Type([PMOVSR_read().bits with idx .. idx = 0b1]); + if [idx[0]] == 0b0 & idx + 1 < GetNumEventCounters() then { + PMUEvent__2(PMU_EVENT_CHAIN, 1, idx + 1) + }; + () + }; + () +} + +val AArch32_ClearEventCounters : unit -> unit + +function AArch32_ClearEventCounters () = { + if HaveAArch64() then { + AArch64_ClearEventCounters(); + return() + }; + let 'counters = AArch32_GetNumEventCountersAccessible(); + if counters != 0 then { + foreach (idx from 0 to (counters - 1) by 1 in inc) { + assert(constraint(0 <= 'loop_idx)); + assert(constraint('loop_idx < 31)); + PMEVCNTR_set(idx) = Zeros(32) + } + }; + () +} + +val AArch32_PMUSwIncrement : bits(32) -> unit + +function AArch32_PMUSwIncrement sw_incr = { + if PMCR_read()[E] == 0b0 & HDCR_read()[HPME] == 0b0 then { + return() + }; + let 'counters = AArch32_GetNumEventCountersAccessible(); + if counters != 0 then { + foreach (idx from 0 to (counters - 1) by 1 in inc) { + assert(constraint((0 <= 'loop_idx & 'loop_idx < 32))); + if [sw_incr[idx]] == 0b1 then { + PMUEvent__2(PMU_EVENT_SW_INCR, 1, idx) + }; + () + } + }; + () +} + +bitfield PMCCNTR_Type : bits(64) = {CCNT : 63..0} + +register _PMCCNTR : PMCCNTR_Type + +val PMCCNTR_read : unit -> PMCCNTR_Type + +function PMCCNTR_read () = { + r : PMCCNTR_Type = _PMCCNTR; + r.bits[63 .. 0] = Slice(PMCCNTR_EL0.bits, 0, 64); + return(r) +} + +val PMCCNTR_write : PMCCNTR_Type -> unit + +function PMCCNTR_write value_name = { + let r : PMCCNTR_Type = value_name; + PMCCNTR_EL0.bits[63 .. 0] = Slice(r.bits, 0, 64); + _PMCCNTR = r; + return() +} + +val AArch32_IncrementCycleCounter : unit -> unit + +function AArch32_IncrementCycleCounter () = { + if CountPMUEvents(CYCLE_COUNTER_ID) & ((PMCR_read()[LC] == 0b1 | PMCR_read()[D] == 0b0) | HasElapsed64Cycles()) then { + let 'old_value = UInt(PMCCNTR_read().bits); + let 'new_value = old_value + 1; + PMCCNTR_write() = Mk_PMCCNTR_Type(new_value[63 .. 0]); + let 'ovflw = if PMCR_read()[LC] == 0b1 then 64 else 32; + if old_value[64 .. ovflw] != new_value[64 .. ovflw] then { + PMOVSSET_write() = [PMOVSSET_read() with C = 0b1]; + PMOVSR_write() = [PMOVSR_read() with C = 0b1] + }; + () + }; + () +} + +val AArch32_PMUCycle : unit -> unit + +function AArch32_PMUCycle () = { + if PMCR_read()[E] == 0b0 & HDCR_read()[HPME] == 0b0 then { + if ShouldBRBEFreeze() then { + BRBEFreeze() + }; + return() + }; + if HaveAArch64() then { + AArch64_PMUCycle(); + return() + }; + if not_bool(HavePMUv3()) then { + return() + }; + PMUEvent(PMU_EVENT_CPU_CYCLES); + let 'counters = GetNumEventCounters(); + if counters != 0 then { + foreach (idx from 0 to (counters - 1) by 1 in inc) { + assert(constraint((0 <= 'loop_idx & 'loop_idx <= 32))); + if CountPMUEvents(idx) then { + assert(constraint((0 <= 'loop_idx & 'loop_idx < 31))); + let 'accumulated = PMUEventAccumulator[idx]; + AArch32_IncrementEventCounter(idx, accumulated) + }; + assert(constraint((0 <= 'loop_idx & 'loop_idx < 31))); + PMUEventAccumulator[idx] = 0 + } + }; + AArch32_IncrementCycleCounter(); + CheckForPMUOverflow() +} + +val AArch32_DTLBI_ALL : (SecurityState, Regime, Shareability, TLBIMemAttr) -> unit + +function AArch32_DTLBI_ALL (security, regime, shareability, attr) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_DALL; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.level = TLBILevel_Any; + r.attr = attr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_DTLBI_ASID : (SecurityState, Regime, bits(16), Shareability, TLBIMemAttr, bits(32)) -> unit + +function AArch32_DTLBI_ASID (security, regime, vmid, shareability, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_DASID; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = TLBILevel_Any; + r.attr = attr; + r.asid = Zeros(8) @ Rt[7 .. 0]; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_DTLBI_VA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(32)) -> unit + +function AArch32_DTLBI_VA (security, regime, vmid, shareability, level, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_DVA; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.asid = Zeros(8) @ Rt[7 .. 0]; + r.address = (Zeros(32) @ Rt[31 .. 12]) @ Zeros(12); + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_ITLBI_ALL : (SecurityState, Regime, Shareability, TLBIMemAttr) -> unit + +function AArch32_ITLBI_ALL (security, regime, shareability, attr) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_IALL; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.level = TLBILevel_Any; + r.attr = attr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_ITLBI_ASID : (SecurityState, Regime, bits(16), Shareability, TLBIMemAttr, bits(32)) -> unit + +function AArch32_ITLBI_ASID (security, regime, vmid, shareability, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_IASID; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = TLBILevel_Any; + r.attr = attr; + r.asid = Zeros(8) @ Rt[7 .. 0]; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_ITLBI_VA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(32)) -> unit + +function AArch32_ITLBI_VA (security, regime, vmid, shareability, level, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_IVA; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.asid = Zeros(8) @ Rt[7 .. 0]; + r.address = (Zeros(32) @ Rt[31 .. 12]) @ Zeros(12); + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_TLBI_ALL : (SecurityState, Regime, Shareability, TLBIMemAttr) -> unit + +function AArch32_TLBI_ALL (security, regime, shareability, attr) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2); + r : TLBIRecord = undefined; + r.op = TLBIOp_ALL; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.level = TLBILevel_Any; + r.attr = attr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_TLBI_VMALL : (SecurityState, Regime, bits(16), Shareability, TLBIMemAttr) -> unit + +function AArch32_TLBI_VMALL (security, regime, vmid, shareability, attr) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VMALL; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.level = TLBILevel_Any; + r.vmid = vmid; + r.attr = attr; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_TLBI_ASID : (SecurityState, Regime, bits(16), Shareability, TLBIMemAttr, bits(32)) -> unit + +function AArch32_TLBI_ASID (security, regime, vmid, shareability, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_ASID; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = TLBILevel_Any; + r.attr = attr; + r.asid = Zeros(8) @ Rt[7 .. 0]; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_TLBI_VA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(32)) -> unit + +function AArch32_TLBI_VA (security, regime, vmid, shareability, level, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VA; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.asid = Zeros(8) @ Rt[7 .. 0]; + r.address = (Zeros(32) @ Rt[31 .. 12]) @ Zeros(12); + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_TLBI_VAA : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(32)) -> unit + +function AArch32_TLBI_VAA (security, regime, vmid, shareability, level, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2 | PSTATE.EL == EL1); + r : TLBIRecord = undefined; + r.op = TLBIOp_VAA; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.address = (Zeros(32) @ Rt[31 .. 12]) @ Zeros(12); + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +val AArch32_TLBI_IPAS2 : (SecurityState, Regime, bits(16), Shareability, TLBILevel, TLBIMemAttr, bits(32)) -> unit + +function AArch32_TLBI_IPAS2 (security, regime, vmid, shareability, level, attr, Rt) = { + assert(PSTATE.EL == EL3 | PSTATE.EL == EL2); + assert(security == SS_NonSecure); + r : TLBIRecord = undefined; + r.op = TLBIOp_IPAS2; + r.from_aarch64 = false; + r.security = security; + r.regime = regime; + r.vmid = vmid; + r.level = level; + r.attr = attr; + r.address = (Zeros(24) @ Rt[27 .. 0]) @ Zeros(12); + r.ipaspace = PAS_NonSecure; + TLBI(r, shareability); + if shareability != Shareability_NSH then { + Broadcast(shareability, r) + }; + return() +} + +bitfield ID_MMFR2_EL1_Type : bits(64) = + { + HWAccFlg : 31..28, + WFIStall : 27..24, + MemBarr : 23..20, + UniTLB : 19..16, + HvdTLB : 15..12, + L1HvdRng : 11..8, + L1HvdBG : 7..4, + L1HvdFG : 3..0 + } + +register ID_MMFR2_EL1 : ID_MMFR2_EL1_Type + +bitfield ID_MMFR4_EL1_Type : bits(64) = + { + EVT : 31..28, + CCIDX : 27..24, + LSM : 23..20, + HPDS : 19..16, + CnP : 15..12, + XNX : 11..8, + AC2 : 7..4, + SpecSEI : 3..0 + } + +register ID_MMFR4_EL1 : ID_MMFR4_EL1_Type + +bitfield ID_AA64MMFR2_EL1_Type : bits(64) = + { + E0PD : 63..60, + EVT : 59..56, + BBM : 55..52, + TTL : 51..48, + FWB : 43..40, + IDS : 39..36, + AT : 35..32, + ST : 31..28, + NV : 27..24, + CCIDX : 23..20, + VARange : 19..16, + IESB : 15..12, + LSM : 11..8, + UAO : 7..4, + CnP : 3..0 + } + +register ID_AA64MMFR2_EL1 : ID_AA64MMFR2_EL1_Type + +bitfield HDFGRTR_EL2_Type : bits(64) = + { + PMBIDR_EL1 : 63..63, + nPMSNEVFR_EL1 : 62..62, + nBRBDATA : 61..61, + nBRBCTL : 60..60, + nBRBIDR : 59..59, + PMCEIDn_EL0 : 58..58, + PMUSERENR_EL0 : 57..57, + TRCVICTLR : 48..48, + TRCSTATR : 47..47, + TRCSSCSRn : 46..46, + TRCSEQSTR : 45..45, + TRCPRGCTLR : 44..44, + TRCOSLSR : 43..43, + TRCIMSPECn : 41..41, + TRCID : 40..40, + TRCCNTVRn : 37..37, + TRCCLAIM : 36..36, + TRCAUXCTLR : 35..35, + TRCAUTHSTATUS : 34..34, + TRC : 33..33, + PMSLATFR_EL1 : 32..32, + PMSIRR_EL1 : 31..31, + PMSIDR_EL1 : 30..30, + PMSICR_EL1 : 29..29, + PMSFCR_EL1 : 28..28, + PMSEVFR_EL1 : 27..27, + PMSCR_EL1 : 26..26, + PMBSR_EL1 : 25..25, + PMBPTR_EL1 : 24..24, + PMBLIMITR_EL1 : 23..23, + PMMIR_EL1 : 22..22, + PMSELR_EL0 : 19..19, + PMOVS : 18..18, + PMINTEN : 17..17, + PMCNTEN : 16..16, + PMCCNTR_EL0 : 15..15, + PMCCFILTR_EL0 : 14..14, + PMEVTYPERn_EL0 : 13..13, + PMEVCNTRn_EL0 : 12..12, + OSDLR_EL1 : 11..11, + OSECCR_EL1 : 10..10, + OSLSR_EL1 : 9..9, + DBGPRCR_EL1 : 7..7, + DBGAUTHSTATUS_EL1 : 6..6, + DBGCLAIM : 5..5, + MDSCR_EL1 : 4..4, + DBGWVRn_EL1 : 3..3, + DBGWCRn_EL1 : 2..2, + DBGBVRn_EL1 : 1..1, + DBGBCRn_EL1 : 0..0 + } + +register HDFGRTR_EL2 : HDFGRTR_EL2_Type + +bitfield ICV_NMIAR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_NMIAR1_EL1 : ICV_NMIAR1_EL1_Type + +bitfield ICH_LR_EL2_Type : bits(64) = + { + State : 63..62, + HW : 61..61, + Group : 60..60, + NMI : 59..59, + Priority : 55..48, + pINTID : 44..32, + vINTID : 31..0 + } + +register ICH_LR_EL2 : vector(16, ICH_LR_EL2_Type) + +bitfield MVFR0_EL1_Type : bits(64) = + { + FPRound : 31..28, + FPShVec : 27..24, + FPSqrt : 23..20, + FPDivide : 19..16, + FPTrap : 15..12, + FPDP : 11..8, + FPSP : 7..4, + SIMDReg : 3..0 + } + +register MVFR0_EL1 : MVFR0_EL1_Type + +bitfield ICC_HPPIR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_HPPIR1_EL1 : ICC_HPPIR1_EL1_Type + +type ICC_AP0R_EL1_Type = bits(64) + +register ICC_AP0R_EL1 : vector(4, ICC_AP0R_EL1_Type) + +bitfield ID_AA64DFR0_EL1_Type : bits(64) = + { + HPMN0 : 63..60, + ExtTrcBuff : 59..56, + BRBE : 55..52, + MTPMU : 51..48, + TraceBuffer : 47..44, + TraceFilt : 43..40, + DoubleLock : 39..36, + PMSVer : 35..32, + CTX_CMPs : 31..28, + SEBEP : 27..24, + WRPs : 23..20, + PMSS : 19..16, + BRPs : 15..12, + PMUVer : 11..8, + TraceVer : 7..4, + DebugVer : 3..0 + } + +register ID_AA64DFR0_EL1 : ID_AA64DFR0_EL1_Type + +bitfield ICV_BPR1_EL1_Type : bits(64) = {BinaryPoint : 2..0} + +register ICV_BPR1_EL1 : ICV_BPR1_EL1_Type + +bitfield ID_ISAR2_EL1_Type : bits(64) = + { + Reversal : 31..28, + PSR_AR : 27..24, + MultU : 23..20, + MultS : 19..16, + Mult : 15..12, + MultiAccessInt : 11..8, + MemHint : 7..4, + LoadStore : 3..0 + } + +register ID_ISAR2_EL1 : ID_ISAR2_EL1_Type + +bitfield PMECR_EL1_Type : bits(64) = {SSE : 4..3, KPME : 2..2, PMEE : 1..0} + +register PMECR_EL1 : PMECR_EL1_Type + +type AIDR_EL1_Type = bits(64) + +register AIDR_EL1 : AIDR_EL1_Type + +bitfield ICV_EOIR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_EOIR1_EL1 : ICV_EOIR1_EL1_Type + +bitfield RMR_EL1_Type : bits(64) = {RR : 1..1, AA64 : 0..0} + +register RMR_EL1 : RMR_EL1_Type + +bitfield OSLAR_EL1_Type : bits(64) = {OSLK : 0..0} + +register OSLAR_EL1 : OSLAR_EL1_Type + +bitfield ICC_HPPIR0_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_HPPIR0_EL1 : ICC_HPPIR0_EL1_Type + +val __set_CNTHPS_CTL_EL2 : CNTHPS_CTL_EL2_Type -> unit + +function __set_CNTHPS_CTL_EL2 value_name = { + let r : CNTHPS_CTL_EL2_Type = value_name; + CNTHPS_CTL_EL2.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTHPS_CTL_EL2.bits[63 .. 3] = Slice(r.bits, 3, 61); + return() +} + +bitfield HAFGRTR_EL2_Type : bits(64) = + { + AMEVTYPER115_EL0 : 49..49, + AMEVCNTR115_EL0 : 48..48, + AMEVTYPER114_EL0 : 47..47, + AMEVCNTR114_EL0 : 46..46, + AMEVTYPER113_EL0 : 45..45, + AMEVCNTR113_EL0 : 44..44, + AMEVTYPER112_EL0 : 43..43, + AMEVCNTR112_EL0 : 42..42, + AMEVTYPER111_EL0 : 41..41, + AMEVCNTR111_EL0 : 40..40, + AMEVTYPER110_EL0 : 39..39, + AMEVCNTR110_EL0 : 38..38, + AMEVTYPER19_EL0 : 37..37, + AMEVCNTR19_EL0 : 36..36, + AMEVTYPER18_EL0 : 35..35, + AMEVCNTR18_EL0 : 34..34, + AMEVTYPER17_EL0 : 33..33, + AMEVCNTR17_EL0 : 32..32, + AMEVTYPER16_EL0 : 31..31, + AMEVCNTR16_EL0 : 30..30, + AMEVTYPER15_EL0 : 29..29, + AMEVCNTR15_EL0 : 28..28, + AMEVTYPER14_EL0 : 27..27, + AMEVCNTR14_EL0 : 26..26, + AMEVTYPER13_EL0 : 25..25, + AMEVCNTR13_EL0 : 24..24, + AMEVTYPER12_EL0 : 23..23, + AMEVCNTR12_EL0 : 22..22, + AMEVTYPER11_EL0 : 21..21, + AMEVCNTR11_EL0 : 20..20, + AMEVTYPER10_EL0 : 19..19, + AMEVCNTR10_EL0 : 18..18, + AMCNTEN1 : 17..17, + AMEVCNTR03_EL0 : 4..4, + AMEVCNTR02_EL0 : 3..3, + AMEVCNTR01_EL0 : 2..2, + AMEVCNTR00_EL0 : 1..1, + AMCNTEN0 : 0..0 + } + +register HAFGRTR_EL2 : HAFGRTR_EL2_Type + +bitfield ICC_BPR0_EL1_Type : bits(64) = {BinaryPoint : 2..0} + +register ICC_BPR0_EL1 : ICC_BPR0_EL1_Type + +bitfield ID_AA64DFR1_EL1_Type : bits(64) = + { + ABL_CMPs : 63..56, + DPFZS : 55..52, + EBEP : 51..48, + ITE : 47..44, + ABLE : 43..40, + PMICNTR : 39..36, + SPMU : 35..32, + CTX_CMPs : 31..24, + WRPs : 23..16, + BRPs : 15..8, + SYSPMUID : 7..0 + } + +register ID_AA64DFR1_EL1 : ID_AA64DFR1_EL1_Type + +bitfield ACCDATA_EL1_Type : bits(64) = {ACCDATA : 31..0} + +register ACCDATA_EL1 : ACCDATA_EL1_Type + +val __set_SCTLR_EL1 : SCTLR_EL1_Type -> unit + +function __set_SCTLR_EL1 value_name = { + let r : SCTLR_EL1_Type = value_name; + SCTLR_EL1.bits[4 .. 0] = Slice(r.bits, 0, 5); + SCTLR_EL1.bits[6] = Bit(Slice(r.bits, 6, 1)); + SCTLR_EL1.bits[63 .. 8] = Slice(r.bits, 8, 56); + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD"))) then { + SCTLR_EL1[ITD] = r[ITD] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN"))) then { + SCTLR_EL1[CP15BEN] = r[CP15BEN] + }; + return() +} + +type REVIDR_EL1_Type = bits(64) + +register REVIDR_EL1 : REVIDR_EL1_Type + +bitfield PMSSCR_EL1_Type : bits(64) = {NC : 32..32, SS : 0..0} + +register PMSSCR_EL1 : PMSSCR_EL1_Type + +val __set_PMSSCR_EL1 : PMSSCR_EL1_Type -> unit + +function __set_PMSSCR_EL1 value_name = { + let r : PMSSCR_EL1_Type = value_name; + PMSSCR_EL1.bits[63 .. 1] = Slice(r.bits, 1, 63); + if not_bool(__IMPDEF_boolean("Capture events are disabled")) then { + PMSSCR_EL1[SS] = r[SS] + }; + return() +} + +bitfield LORID_EL1_Type : bits(64) = {LD : 23..16, LR : 7..0} + +register LORID_EL1 : LORID_EL1_Type + +type TPIDR_EL2_Type = bits(64) + +register TPIDR_EL2 : TPIDR_EL2_Type + +bitfield CNTP_TVAL_EL0_Type : bits(64) = {TimerValue : 31..0} + +register CNTP_TVAL_EL0 : CNTP_TVAL_EL0_Type + +bitfield ID_AA64ISAR1_EL1_Type : bits(64) = + { + LS64 : 63..60, + XS : 59..56, + I8MM : 55..52, + DGH : 51..48, + BF16 : 47..44, + SPECRES : 43..40, + SB : 39..36, + FRINTTS : 35..32, + GPI : 31..28, + GPA : 27..24, + LRCPC : 23..20, + FCMA : 19..16, + JSCVT : 15..12, + API : 11..8, + APA : 7..4, + DPB : 3..0 + } + +register ID_AA64ISAR1_EL1 : ID_AA64ISAR1_EL1_Type + +bitfield ID_AA64MMFR4_EL1_Type : bits(64) = {EIESB : 7..4} + +register ID_AA64MMFR4_EL1 : ID_AA64MMFR4_EL1_Type + +type ACTLR_EL2_Type = bits(64) + +register ACTLR_EL2 : ACTLR_EL2_Type + +bitfield ICH_EISR_EL2_Type : bits(64) = + { + Status15 : 15..15, + Status14 : 14..14, + Status13 : 13..13, + Status12 : 12..12, + Status11 : 11..11, + Status10 : 10..10, + Status9 : 9..9, + Status8 : 8..8, + Status7 : 7..7, + Status6 : 6..6, + Status5 : 5..5, + Status4 : 4..4, + Status3 : 3..3, + Status2 : 2..2, + Status1 : 1..1, + Status0 : 0..0 + } + +register ICH_EISR_EL2 : ICH_EISR_EL2_Type + +bitfield MIDR_EL1_Type : bits(64) = + { + Implementer : 31..24, + Variant : 23..20, + Architecture : 19..16, + PartNum : 15..4, + Revision : 3..0 + } + +register MIDR_EL1 : MIDR_EL1_Type + +bitfield ICC_RPR_EL1_Type : bits(64) = + {NMI : 63..63, NMI_NS : 62..62, Priority : 7..0} + +register ICC_RPR_EL1 : ICC_RPR_EL1_Type + +bitfield ICH_ELRSR_EL2_Type : bits(64) = + { + Status15 : 15..15, + Status14 : 14..14, + Status13 : 13..13, + Status12 : 12..12, + Status11 : 11..11, + Status10 : 10..10, + Status9 : 9..9, + Status8 : 8..8, + Status7 : 7..7, + Status6 : 6..6, + Status5 : 5..5, + Status4 : 4..4, + Status3 : 3..3, + Status2 : 2..2, + Status1 : 1..1, + Status0 : 0..0 + } + +register ICH_ELRSR_EL2 : ICH_ELRSR_EL2_Type + +bitfield ICC_SGI0R_EL1_Type : bits(64) = + { + Aff3 : 55..48, + RS : 47..44, + IRM : 40..40, + Aff2 : 39..32, + INTID : 27..24, + Aff1 : 23..16, + TargetList : 15..0 + } + +register ICC_SGI0R_EL1 : ICC_SGI0R_EL1_Type + +val __set_FPCR : FPCR_Type -> unit + +function __set_FPCR value_name = { + let r : FPCR_Type = value_name; + FPCR.bits[7 .. 0] = Slice(r.bits, 0, 8); + FPCR.bits[14 .. 13] = Slice(r.bits, 13, 2); + FPCR.bits[19] = Bit(Slice(r.bits, 19, 1)); + FPCR.bits[63 .. 22] = Slice(r.bits, 22, 42); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_FPSCR.LEN,STRIDE as RAZ")) then { + FPCR[Stride] = r[Stride] + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_FPSCR.LEN,STRIDE as RAZ")) then { + FPCR[length] = r[length] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Input Denormal floating-point exceptions"))) then { + FPCR[IDE] = r[IDE] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Inexact floating-point exceptions"))) then { + FPCR[IXE] = r[IXE] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Underflow floating-point exceptions"))) then { + FPCR[UFE] = r[UFE] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Overflow floating-point exceptions"))) then { + FPCR[OFE] = r[OFE] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Divide by Zero floating-point exceptions"))) then { + FPCR[DZE] = r[DZE] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Invalid Operation floating-point exceptions"))) then { + FPCR[IOE] = r[IOE] + }; + return() +} + +val __set_CNTHVS_CTL_EL2 : CNTHVS_CTL_EL2_Type -> unit + +function __set_CNTHVS_CTL_EL2 value_name = { + let r : CNTHVS_CTL_EL2_Type = value_name; + CNTHVS_CTL_EL2.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTHVS_CTL_EL2.bits[63 .. 3] = Slice(r.bits, 3, 61); + return() +} + +bitfield SPMACCESSR_EL1_Type : bits(64) = + { + P31 : 63..62, + P30 : 61..60, + P29 : 59..58, + P28 : 57..56, + P27 : 55..54, + P26 : 53..52, + P25 : 51..50, + P24 : 49..48, + P23 : 47..46, + P22 : 45..44, + P21 : 43..42, + P20 : 41..40, + P19 : 39..38, + P18 : 37..36, + P17 : 35..34, + P16 : 33..32, + P15 : 31..30, + P14 : 29..28, + P13 : 27..26, + P12 : 25..24, + P11 : 23..22, + P10 : 21..20, + P9 : 19..18, + P8 : 17..16, + P7 : 15..14, + P6 : 13..12, + P5 : 11..10, + P4 : 9..8, + P3 : 7..6, + P2 : 5..4, + P1 : 3..2, + P0 : 1..0 + } + +register SPMACCESSR_EL1 : SPMACCESSR_EL1_Type + +bitfield SPMSELR_EL0_Type : bits(64) = {SYSPMUSEL : 9..4, BANK : 1..0} + +register SPMSELR_EL0 : SPMSELR_EL0_Type + +val __get_selected_SPMACCESSR_EL1_field : unit -> bits(2) + +function __get_selected_SPMACCESSR_EL1_field () = { + let 'idx = UInt(SPMSELR_EL0[SYSPMUSEL]) * 2; + return(Slice(SPMACCESSR_EL1.bits, idx, 2)) +} + +bitfield ID_AA64PFR1_EL1_Type : bits(64) = + { + PFAR : 63..60, + DF2 : 59..56, + MTEX : 55..52, + THE : 51..48, + GCS : 47..44, + MTE_frac : 43..40, + NMI : 39..36, + CSV2_frac : 35..32, + RNDR_trap : 31..28, + SME : 27..24, + MPAM_frac : 19..16, + RAS_frac : 15..12, + MTE : 11..8, + SSBS : 7..4, + BT : 3..0 + } + +register ID_AA64PFR1_EL1 : ID_AA64PFR1_EL1_Type + +bitfield ID_AA64PFR0_EL1_Type : bits(64) = + { + CSV3 : 63..60, + CSV2 : 59..56, + RME : 55..52, + DIT : 51..48, + AMU : 47..44, + MPAM : 43..40, + SEL2 : 39..36, + SVE : 35..32, + RAS : 31..28, + GIC : 27..24, + AdvSIMD : 23..20, + FP : 19..16, + EL3 : 15..12, + EL2 : 11..8, + EL1 : 7..4, + EL0 : 3..0 + } + +register ID_AA64PFR0_EL1 : ID_AA64PFR0_EL1_Type + +bitfield ICH_AP1R_EL2_Type : bits(64) = + { + NMI : 63..63, + P31 : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register ICH_AP1R_EL2 : vector(4, ICH_AP1R_EL2_Type) + +bitfield ICC_DIR_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_DIR_EL1 : ICC_DIR_EL1_Type + +bitfield PMEVCNTSVR_EL1_Type : bits(64) = {EVCNT : 63..0} + +register PMEVCNTSVR_EL1 : vector(31, PMEVCNTSVR_EL1_Type) + +bitfield ID_AA64ISAR0_EL1_Type : bits(64) = + { + RNDR : 63..60, + TLB : 59..56, + TS : 55..52, + FHM : 51..48, + DP : 47..44, + SM4 : 43..40, + SM3 : 39..36, + SHA3 : 35..32, + RDM : 31..28, + TME : 27..24, + Atomic : 23..20, + CRC32 : 19..16, + SHA2 : 15..12, + SHA1 : 11..8, + AES : 7..4 + } + +register ID_AA64ISAR0_EL1 : ID_AA64ISAR0_EL1_Type + +bitfield PMMIR_EL1_Type : bits(64) = + { + EDGE : 27..24, + THWIDTH : 23..20, + BUS_WIDTH : 19..16, + BUS_SLOTS : 15..8, + SLOTS : 7..0 + } + +register PMMIR_EL1 : PMMIR_EL1_Type + +bitfield ICV_IAR0_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_IAR0_EL1 : ICV_IAR0_EL1_Type + +bitfield ICC_IGRPEN1_EL1_Type : bits(64) = {Enable : 0..0} + +register ICC_IGRPEN1_EL1_S : ICC_IGRPEN1_EL1_Type + +register ICC_IGRPEN1_EL1_NS : ICC_IGRPEN1_EL1_Type + +val ICC_IGRPEN1_EL1_read : unit -> ICC_IGRPEN1_EL1_Type + +function ICC_IGRPEN1_EL1_read () = { + r : ICC_IGRPEN1_EL1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_IGRPEN1_EL1_S + } else { + r = ICC_IGRPEN1_EL1_NS + }; + return(r) +} + +val ICC_IGRPEN1_EL1_write : ICC_IGRPEN1_EL1_Type -> unit + +function ICC_IGRPEN1_EL1_write value_name = { + let r : ICC_IGRPEN1_EL1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_IGRPEN1_EL1_S = r + } else { + ICC_IGRPEN1_EL1_NS = r + }; + return() +} + +bitfield ID_MMFR5_EL1_Type : bits(64) = {nTLBPA : 7..4, ETS : 3..0} + +register ID_MMFR5_EL1 : ID_MMFR5_EL1_Type + +bitfield ICC_NMIAR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_NMIAR1_EL1 : ICC_NMIAR1_EL1_Type + +bitfield DBGCLAIMSET_EL1_Type : bits(64) = {CLAIM : 7..0} + +register DBGCLAIMSET_EL1 : DBGCLAIMSET_EL1_Type + +bitfield ICC_SRE_EL1_Type : bits(64) = {DIB : 2..2, DFB : 1..1, SRE : 0..0} + +register ICC_SRE_EL1_S : ICC_SRE_EL1_Type + +register ICC_SRE_EL1_NS : ICC_SRE_EL1_Type + +val ICC_SRE_EL1_read : unit -> ICC_SRE_EL1_Type + +function ICC_SRE_EL1_read () = { + r : ICC_SRE_EL1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_SRE_EL1_S + } else { + r = ICC_SRE_EL1_NS + }; + return(r) +} + +val ICC_SRE_EL1_write : ICC_SRE_EL1_Type -> unit + +function ICC_SRE_EL1_write value_name = { + let r : ICC_SRE_EL1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_SRE_EL1_S = r + } else { + ICC_SRE_EL1_NS = r + }; + return() +} + +bitfield ICH_AP0R_EL2_Type : bits(64) = + { + P31 : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register ICH_AP0R_EL2 : vector(4, ICH_AP0R_EL2_Type) + +bitfield ICC_IAR0_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_IAR0_EL1 : ICC_IAR0_EL1_Type + +type TPIDR_EL1_Type = bits(64) + +register TPIDR_EL1 : TPIDR_EL1_Type + +bitfield ID_ISAR4_EL1_Type : bits(64) = + { + SWP_frac : 31..28, + PSR_M : 27..24, + SynchPrim_frac : 23..20, + Barrier : 19..16, + SMC : 15..12, + Writeback : 11..8, + WithShifts : 7..4, + Unpriv : 3..0 + } + +register ID_ISAR4_EL1 : ID_ISAR4_EL1_Type + +bitfield ID_ISAR1_EL1_Type : bits(64) = + { + Jazelle : 31..28, + Interwork : 27..24, + Immediate : 23..20, + IfThen : 19..16, + Extend : 15..12, + Except_AR : 11..8, + Except : 7..4, + Endian : 3..0 + } + +register ID_ISAR1_EL1 : ID_ISAR1_EL1_Type + +bitfield PMUACR_EL1_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMUACR_EL1 : PMUACR_EL1_Type + +type ACTLR_EL1_Type = bits(64) + +register ACTLR_EL1 : ACTLR_EL1_Type + +bitfield RMR_EL2_Type : bits(64) = {RR : 1..1, AA64 : 0..0} + +register RMR_EL2 : RMR_EL2_Type + +bitfield PMSELR_EL0_Type : bits(64) = {SEL : 4..0} + +register PMSELR_EL0 : PMSELR_EL0_Type + +bitfield ICC_CTLR_EL1_Type : bits(64) = + { + ExtRange : 19..19, + RSS : 18..18, + A3V : 15..15, + SEIS : 14..14, + IDbits : 13..11, + PRIbits : 10..8, + PMHE : 6..6, + EOImode : 1..1, + CBPR : 0..0 + } + +register ICC_CTLR_EL1_S : ICC_CTLR_EL1_Type + +register ICC_CTLR_EL1_NS : ICC_CTLR_EL1_Type + +val ICC_CTLR_EL1_read : unit -> ICC_CTLR_EL1_Type + +function ICC_CTLR_EL1_read () = { + r : ICC_CTLR_EL1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_CTLR_EL1_S + } else { + r = ICC_CTLR_EL1_NS + }; + return(r) +} + +val ICC_CTLR_EL1_write : ICC_CTLR_EL1_Type -> unit + +function ICC_CTLR_EL1_write value_name = { + let r : ICC_CTLR_EL1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_CTLR_EL1_S = r + } else { + ICC_CTLR_EL1_NS = r + }; + return() +} + +bitfield ID_ISAR6_EL1_Type : bits(64) = + { + CLRBHB : 31..28, + I8MM : 27..24, + BF16 : 23..20, + SPECRES : 19..16, + SB : 15..12, + FHM : 11..8, + DP : 7..4, + JSCVT : 3..0 + } + +register ID_ISAR6_EL1 : ID_ISAR6_EL1_Type + +bitfield ICC_AP1R_EL1_Type : bits(64) = {NMI : 63..63} + +register ICC_AP1R_EL1_S : vector(4, ICC_AP1R_EL1_Type) + +register ICC_AP1R_EL1_NS : vector(4, ICC_AP1R_EL1_Type) + +val ICC_AP1R_EL1_read : forall 'n. int('n) -> ICC_AP1R_EL1_Type + +function ICC_AP1R_EL1_read n = { + r : ICC_AP1R_EL1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + assert(constraint((0 <= 'n & 'n < 4))); + r = ICC_AP1R_EL1_S[n] + } else { + assert(constraint((0 <= 'n & 'n < 4))); + r = ICC_AP1R_EL1_NS[n] + }; + return(r) +} + +val ICC_AP1R_EL1_set : forall 'n. (int('n), ICC_AP1R_EL1_Type) -> unit + +function ICC_AP1R_EL1_set (n, value_name) = { + let r : ICC_AP1R_EL1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + assert(constraint((0 <= 'n & 'n < 4))); + ICC_AP1R_EL1_S[n] = r + } else { + assert(constraint((0 <= 'n & 'n < 4))); + ICC_AP1R_EL1_NS[n] = r + }; + return() +} + +val __set_CNTP_CTL_EL0 : CNTP_CTL_EL0_Type -> unit + +function __set_CNTP_CTL_EL0 value_name = { + let r : CNTP_CTL_EL0_Type = value_name; + CNTP_CTL_EL0.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTP_CTL_EL0.bits[63 .. 3] = Slice(r.bits, 3, 61); + return() +} + +type HFGITR2_EL2_Type = bits(64) + +register HFGITR2_EL2 : HFGITR2_EL2_Type + +bitfield CNTHV_TVAL_EL2_Type : bits(64) = {TimerValue : 31..0} + +register CNTHV_TVAL_EL2 : CNTHV_TVAL_EL2_Type + +bitfield ICH_MISR_EL2_Type : bits(64) = + { + VGrp1D : 7..7, + VGrp1E : 6..6, + VGrp0D : 5..5, + VGrp0E : 4..4, + NP : 3..3, + LRENP : 2..2, + U : 1..1, + EOI : 0..0 + } + +register ICH_MISR_EL2 : ICH_MISR_EL2_Type + +bitfield CSSELR_EL1_Type : bits(64) = {TnD : 4..4, Level : 3..1, InD : 0..0} + +register CSSELR_EL1 : CSSELR_EL1_Type + +bitfield ICV_RPR_EL1_Type : bits(64) = {NMI : 63..63, Priority : 7..0} + +register ICV_RPR_EL1 : ICV_RPR_EL1_Type + +bitfield ICV_PMR_EL1_Type : bits(64) = {Priority : 7..0} + +register ICV_PMR_EL1 : ICV_PMR_EL1_Type + +bitfield ICV_HPPIR0_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_HPPIR0_EL1 : ICV_HPPIR0_EL1_Type + +bitfield ICV_BPR0_EL1_Type : bits(64) = {BinaryPoint : 2..0} + +register ICV_BPR0_EL1 : ICV_BPR0_EL1_Type + +bitfield ISR_EL1_Type : bits(64) = + {IS : 10..10, FS : 9..9, A : 8..8, I : 7..7, F : 6..6} + +register ISR_EL1 : ISR_EL1_Type + +bitfield ID_ISAR3_EL1_Type : bits(64) = + { + T32EE : 31..28, + TrueNOP : 27..24, + T32Copy : 23..20, + TabBranch : 19..16, + SynchPrim : 15..12, + SVC : 11..8, + SIMD : 7..4, + Saturate : 3..0 + } + +register ID_ISAR3_EL1 : ID_ISAR3_EL1_Type + +type AFSR1_EL1_Type = bits(64) + +register AFSR1_EL1 : AFSR1_EL1_Type + +bitfield PMCCNTSVR_EL1_Type : bits(64) = {CCNT : 63..0} + +register PMCCNTSVR_EL1 : PMCCNTSVR_EL1_Type + +bitfield MECIDR_EL2_Type : bits(64) = {MECIDWidthm1 : 3..0} + +register MECIDR_EL2 : MECIDR_EL2_Type + +bitfield PMINTENSET_EL1_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMINTENSET_EL1 : PMINTENSET_EL1_Type + +bitfield SMIDR_EL1_Type : bits(64) = + {Implementer : 31..24, Revision : 23..16, SMPS : 15..15, Affinity : 11..0} + +register SMIDR_EL1 : SMIDR_EL1_Type + +bitfield HFGWTR_EL2_Type : bits(64) = + { + nAMAIR2_EL1 : 63..63, + nMAIR2_EL1 : 62..62, + nS2POR_EL1 : 61..61, + nPOR_EL1 : 60..60, + nPOR_EL0 : 59..59, + nPIR_EL1 : 58..58, + nPIRE0_EL1 : 57..57, + nRCWMASK_EL1 : 56..56, + nTPIDR2_EL0 : 55..55, + nSMPRI_EL1 : 54..54, + nGCS_EL1 : 53..53, + nGCS_EL0 : 52..52, + nACCDATA_EL1 : 50..50, + ERXADDR_EL1 : 49..49, + ERXPFGCDN_EL1 : 48..48, + ERXPFGCTL_EL1 : 47..47, + ERXMISCn_EL1 : 45..45, + ERXSTATUS_EL1 : 44..44, + ERXCTLR_EL1 : 43..43, + ERRSELR_EL1 : 41..41, + ICC_IGRPENn_EL1 : 39..39, + VBAR_EL1 : 38..38, + TTBR1_EL1 : 37..37, + TTBR0_EL1 : 36..36, + TPIDR_EL0 : 35..35, + TPIDRRO_EL0 : 34..34, + TPIDR_EL1 : 33..33, + TCR_EL1 : 32..32, + SCXTNUM_EL0 : 31..31, + SCXTNUM_EL1 : 30..30, + SCTLR_EL1 : 29..29, + PAR_EL1 : 27..27, + MAIR_EL1 : 24..24, + LORSA_EL1 : 23..23, + LORN_EL1 : 22..22, + LOREA_EL1 : 20..20, + LORC_EL1 : 19..19, + FAR_EL1 : 17..17, + ESR_EL1 : 16..16, + CSSELR_EL1 : 13..13, + CPACR_EL1 : 12..12, + CONTEXTIDR_EL1 : 11..11, + APIBKey : 8..8, + APIAKey : 7..7, + APGAKey : 6..6, + APDBKey : 5..5, + APDAKey : 4..4, + AMAIR_EL1 : 3..3, + AFSR1_EL1 : 1..1, + AFSR0_EL1 : 0..0 + } + +register HFGWTR_EL2 : HFGWTR_EL2_Type + +bitfield SMPRI_EL1_Type : bits(64) = {Priority : 3..0} + +register SMPRI_EL1 : SMPRI_EL1_Type + +bitfield PMUSERENR_EL0_Type : bits(64) = + { + TID : 6..6, + IR : 5..5, + UEN : 4..4, + ER : 3..3, + CR : 2..2, + SW : 1..1, + EN : 0..0 + } + +register PMUSERENR_EL0 : PMUSERENR_EL0_Type + +type AMAIR2_EL2_Type = bits(64) + +register AMAIR2_EL2 : AMAIR2_EL2_Type + +type ICV_AP0R_EL1_Type = bits(64) + +register ICV_AP0R_EL1 : vector(4, ICV_AP0R_EL1_Type) + +type AFSR0_EL3_Type = bits(64) + +register AFSR0_EL3 : AFSR0_EL3_Type + +type CNTFRQ_EL0_Type = bits(64) + +register CNTFRQ_EL0 : CNTFRQ_EL0_Type + +bitfield ICV_CTLR_EL1_Type : bits(64) = + { + ExtRange : 19..19, + RSS : 18..18, + A3V : 15..15, + SEIS : 14..14, + IDbits : 13..11, + PRIbits : 10..8, + EOImode : 1..1, + CBPR : 0..0 + } + +register ICV_CTLR_EL1 : ICV_CTLR_EL1_Type + +type AFSR1_EL2_Type = bits(64) + +register AFSR1_EL2 : AFSR1_EL2_Type + +bitfield ICV_IAR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_IAR1_EL1 : ICV_IAR1_EL1_Type + +val __set_FPEXC32_EL2 : FPEXC32_EL2_Type -> unit + +function __set_FPEXC32_EL2 value_name = { + let r : FPEXC32_EL2_Type = value_name; + FPEXC32_EL2.bits[6 .. 5] = Slice(r.bits, 5, 2); + FPEXC32_EL2.bits[30 .. 8] = Slice(r.bits, 8, 23); + FPEXC32_EL2.bits[63 .. 32] = Slice(r.bits, 32, 32); + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Input Denormal floating-point exceptions"))) then { + FPEXC32_EL2[IDF] = r[IDF] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Inexact floating-point exceptions"))) then { + FPEXC32_EL2[IXF] = r[IXF] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Underflow floating-point exceptions"))) then { + FPEXC32_EL2[UFF] = r[UFF] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Overflow floating-point exceptions"))) then { + FPEXC32_EL2[OFF] = r[OFF] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Divide by Zero floating-point exceptions"))) then { + FPEXC32_EL2[DZF] = r[DZF] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Invalid Operation floating-point exceptions"))) then { + FPEXC32_EL2[IOF] = r[IOF] + }; + return() +} + +val __set_MDSCR_EL1 : MDSCR_EL1_Type -> unit + +function __set_MDSCR_EL1 value_name = { + let r : MDSCR_EL1_Type = value_name; + MDSCR_EL1.bits[5 .. 0] = Slice(r.bits, 0, 6); + MDSCR_EL1.bits[13 .. 7] = Slice(r.bits, 7, 7); + MDSCR_EL1.bits[18 .. 15] = Slice(r.bits, 15, 4); + MDSCR_EL1.bits[20] = Bit(Slice(r.bits, 20, 1)); + MDSCR_EL1.bits[25 .. 24] = Slice(r.bits, 24, 2); + MDSCR_EL1.bits[28] = Bit(Slice(r.bits, 28, 1)); + MDSCR_EL1.bits[34 .. 32] = Slice(r.bits, 32, 3); + MDSCR_EL1.bits[63 .. 36] = Slice(r.bits, 36, 28); + if not_bool(OSLSR_EL1[OSLK] == 0b0) then { + MDSCR_EL1[EHBWE] = r[EHBWE] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[TFO] = r[TFO] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[RXfull] = r[RXfull] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[TXfull] = r[TXfull] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[RXO] = r[RXO] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[TXU] = r[TXU] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[INTdis] = r[INTdis] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[TDA] = r[TDA] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[SC2] = r[SC2] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[HDE] = r[HDE] + }; + if OSLSR_EL1[OSLK] == 0b1 then { + MDSCR_EL1[ERR] = r[ERR] + }; + return() +} + +val __set_GPCCR_EL3 : GPCCR_EL3_Type -> unit + +function __set_GPCCR_EL3 value_name = { + let r : GPCCR_EL3_Type = value_name; + GPCCR_EL3.bits[19 .. 0] = Slice(r.bits, 0, 20); + GPCCR_EL3.bits[63 .. 24] = Slice(r.bits, 24, 40); + return() +} + +bitfield ID_PFR0_EL1_Type : bits(64) = + { + RAS : 31..28, + DIT : 27..24, + AMU : 23..20, + CSV2 : 19..16, + State3 : 15..12, + State2 : 11..8, + State1 : 7..4, + State0 : 3..0 + } + +register ID_PFR0_EL1 : ID_PFR0_EL1_Type + +bitfield MVFR1_EL1_Type : bits(64) = + { + SIMDFMAC : 31..28, + FPHP : 27..24, + SIMDHP : 23..20, + SIMDSP : 19..16, + SIMDInt : 15..12, + SIMDLS : 11..8, + FPDNaN : 7..4, + FPFtZ : 3..0 + } + +register MVFR1_EL1 : MVFR1_EL1_Type + +bitfield HDFGWTR2_EL2_Type : bits(64) = + { + nPMZR_EL0 : 21..21, + nPMSDSFR_EL1 : 19..19, + nSPMSCR_EL1 : 16..16, + nSPMACCESSR_EL1 : 15..15, + nSPMCR_EL0 : 14..14, + nSPMOVS : 13..13, + nSPMINTEN : 12..12, + nSPMCNTEN : 11..11, + nSPMSELR_EL0 : 10..10, + nSPMEVTYPERn_EL0 : 9..9, + nSPMEVCNTRn_EL0 : 8..8, + nPMSSCR_EL1 : 7..7, + nMDSELR_EL1 : 5..5, + nPMUACR_EL1 : 4..4, + nPMICFILTR_EL0 : 3..3, + nPMICNTR_EL0 : 2..2, + nPMIAR_EL1 : 1..1, + nPMECR_EL1 : 0..0 + } + +register HDFGWTR2_EL2 : HDFGWTR2_EL2_Type + +bitfield ID_ISAR0_EL1_Type : bits(64) = + { + Divide : 27..24, + Debug : 23..20, + Coproc : 19..16, + CmpBranch : 15..12, + BitField : 11..8, + BitCount : 7..4, + Swap : 3..0 + } + +register ID_ISAR0_EL1 : ID_ISAR0_EL1_Type + +type AFSR0_EL1_Type = bits(64) + +register AFSR0_EL1 : AFSR0_EL1_Type + +val __set_CNTHP_CTL_EL2 : CNTHP_CTL_EL2_Type -> unit + +function __set_CNTHP_CTL_EL2 value_name = { + let r : CNTHP_CTL_EL2_Type = value_name; + CNTHP_CTL_EL2.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTHP_CTL_EL2.bits[63 .. 3] = Slice(r.bits, 3, 61); + return() +} + +bitfield CNTHVS_TVAL_EL2_Type : bits(64) = {TimerValue : 31..0} + +register CNTHVS_TVAL_EL2 : CNTHVS_TVAL_EL2_Type + +bitfield CNTHP_TVAL_EL2_Type : bits(64) = {TimerValue : 31..0} + +register CNTHP_TVAL_EL2 : CNTHP_TVAL_EL2_Type + +bitfield SPMACCESSR_EL2_Type : bits(64) = + { + P31 : 63..62, + P30 : 61..60, + P29 : 59..58, + P28 : 57..56, + P27 : 55..54, + P26 : 53..52, + P25 : 51..50, + P24 : 49..48, + P23 : 47..46, + P22 : 45..44, + P21 : 43..42, + P20 : 41..40, + P19 : 39..38, + P18 : 37..36, + P17 : 35..34, + P16 : 33..32, + P15 : 31..30, + P14 : 29..28, + P13 : 27..26, + P12 : 25..24, + P11 : 23..22, + P10 : 21..20, + P9 : 19..18, + P8 : 17..16, + P7 : 15..14, + P6 : 13..12, + P5 : 11..10, + P4 : 9..8, + P3 : 7..6, + P2 : 5..4, + P1 : 3..2, + P0 : 1..0 + } + +register SPMACCESSR_EL2 : SPMACCESSR_EL2_Type + +val __get_selected_SPMACCESSR_EL2_field : unit -> bits(2) + +function __get_selected_SPMACCESSR_EL2_field () = { + let 'idx = UInt(SPMSELR_EL0[SYSPMUSEL]) * 2; + return(Slice(SPMACCESSR_EL2.bits, idx, 2)) +} + +bitfield PMZR_EL0_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMZR_EL0 : PMZR_EL0_Type + +bitfield PMICNTSVR_EL1_Type : bits(64) = {ICNT : 63..0} + +register PMICNTSVR_EL1 : PMICNTSVR_EL1_Type + +bitfield MDRAR_EL1_Type : bits(64) = {ROMADDR : 55..12, Valid : 1..0} + +register MDRAR_EL1 : MDRAR_EL1_Type + +type OSDTRRX_EL1_Type = bits(64) + +register OSDTRRX_EL1 : OSDTRRX_EL1_Type + +bitfield ICC_IGRPEN1_EL3_Type : bits(64) = + {EnableGrp1S : 1..1, EnableGrp1NS : 0..0} + +register ICC_IGRPEN1_EL3 : ICC_IGRPEN1_EL3_Type + +bitfield ID_MMFR1_EL1_Type : bits(64) = + { + BPred : 31..28, + L1TstCln : 27..24, + L1Uni : 23..20, + L1Hvd : 19..16, + L1UniSW : 15..12, + L1HvdSW : 11..8, + L1UniVA : 7..4, + L1HvdVA : 3..0 + } + +register ID_MMFR1_EL1 : ID_MMFR1_EL1_Type + +bitfield LORSA_EL1_Type : bits(64) = {SA : 55..16, Valid : 0..0} + +register LORSA_EL1 : LORSA_EL1_Type + +bitfield ID_AA64MMFR1_EL1_Type : bits(64) = + { + ECBHB : 63..60, + CMOW : 59..56, + TIDCP1 : 55..52, + nTLBPA : 51..48, + AFP : 47..44, + HCX : 43..40, + ETS : 39..36, + TWED : 35..32, + XNX : 31..28, + SpecSEI : 27..24, + PAN : 23..20, + LO : 19..16, + HPDS : 15..12, + VH : 11..8, + VMIDBits : 7..4, + HAFDBS : 3..0 + } + +register ID_AA64MMFR1_EL1 : ID_AA64MMFR1_EL1_Type + +bitfield PMSWINC_EL0_Type : bits(64) = + { + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register PMSWINC_EL0 : PMSWINC_EL0_Type + +type SCXTNUM_EL2_Type = bits(64) + +register SCXTNUM_EL2 : SCXTNUM_EL2_Type + +val __set_CNTV_CTL_EL0 : CNTV_CTL_EL0_Type -> unit + +function __set_CNTV_CTL_EL0 value_name = { + let r : CNTV_CTL_EL0_Type = value_name; + CNTV_CTL_EL0.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTV_CTL_EL0.bits[63 .. 3] = Slice(r.bits, 3, 61); + return() +} + +bitfield PMIAR_EL1_Type : bits(64) = {ADDRESS : 63..0} + +register PMIAR_EL1 : PMIAR_EL1_Type + +type TPIDR_EL3_Type = bits(64) + +register TPIDR_EL3 : TPIDR_EL3_Type + +bitfield ID_MMFR0_EL1_Type : bits(64) = + { + InnerShr : 31..28, + FCSE : 27..24, + AuxReg : 23..20, + TCM : 19..16, + ShareLvl : 15..12, + OuterShr : 11..8, + PMSA : 7..4, + VMSA : 3..0 + } + +register ID_MMFR0_EL1 : ID_MMFR0_EL1_Type + +type OSDTRTX_EL1_Type = bits(64) + +register OSDTRTX_EL1 : OSDTRTX_EL1_Type + +bitfield ICH_VMCR_EL2_Type : bits(64) = + { + VPMR : 31..24, + VBPR0 : 23..21, + VBPR1 : 20..18, + VEOIM : 9..9, + VCBPR : 4..4, + VFIQEn : 3..3, + VAckCtl : 2..2, + VENG1 : 1..1, + VENG0 : 0..0 + } + +register ICH_VMCR_EL2 : ICH_VMCR_EL2_Type + +bitfield VPIDR_EL2_Type : bits(64) = + { + Implementer : 31..24, + Variant : 23..20, + Architecture : 19..16, + PartNum : 15..4, + Revision : 3..0 + } + +register VPIDR_EL2 : VPIDR_EL2_Type + +type ACTLR_EL3_Type = bits(64) + +register ACTLR_EL3 : ACTLR_EL3_Type + +bitfield ICC_CTLR_EL3_Type : bits(64) = + { + ExtRange : 19..19, + RSS : 18..18, + nDS : 17..17, + A3V : 15..15, + SEIS : 14..14, + IDbits : 13..11, + PRIbits : 10..8, + PMHE : 6..6, + RM : 5..5, + EOImode_EL1NS : 4..4, + EOImode_EL1S : 3..3, + EOImode_EL3 : 2..2, + CBPR_EL1NS : 1..1, + CBPR_EL1S : 0..0 + } + +register ICC_CTLR_EL3 : ICC_CTLR_EL3_Type + +val __set_SCTLR_EL2 : SCTLR_EL2_Type -> unit + +function __set_SCTLR_EL2 value_name = { + let r : SCTLR_EL2_Type = value_name; + SCTLR_EL2.bits[6 .. 0] = Slice(r.bits, 0, 7); + SCTLR_EL2.bits[63 .. 8] = Slice(r.bits, 8, 56); + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD"))) then { + SCTLR_EL2[ITD] = r[ITD] + }; + return() +} + +type AMAIR_EL2_Type = bits(64) + +register AMAIR_EL2 : AMAIR_EL2_Type + +type AMAIR_EL3_Type = bits(64) + +register AMAIR_EL3 : AMAIR_EL3_Type + +bitfield ICC_SRE_EL2_Type : bits(64) = + {Enable : 3..3, DIB : 2..2, DFB : 1..1, SRE : 0..0} + +register ICC_SRE_EL2 : ICC_SRE_EL2_Type + +val __set_CNTPS_CTL_EL1 : CNTPS_CTL_EL1_Type -> unit + +function __set_CNTPS_CTL_EL1 value_name = { + let r : CNTPS_CTL_EL1_Type = value_name; + CNTPS_CTL_EL1.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTPS_CTL_EL1.bits[63 .. 3] = Slice(r.bits, 3, 61); + return() +} + +bitfield LORC_EL1_Type : bits(64) = {DS : 9..2, EN : 0..0} + +register LORC_EL1 : LORC_EL1_Type + +bitfield ID_AA64PFR2_EL1_Type : bits(64) = + {MTEFAR : 11..8, MTESTOREONLY : 7..4, MTEPERM : 3..0} + +register ID_AA64PFR2_EL1 : ID_AA64PFR2_EL1_Type + +type SCXTNUM_EL1_Type = bits(64) + +register SCXTNUM_EL1 : SCXTNUM_EL1_Type + +bitfield CCSIDR2_EL1_Type : bits(64) = {NumSets : 23..0} + +register CCSIDR2_EL1 : CCSIDR2_EL1_Type + +bitfield ICC_ASGI1R_EL1_Type : bits(64) = + { + Aff3 : 55..48, + RS : 47..44, + IRM : 40..40, + Aff2 : 39..32, + INTID : 27..24, + Aff1 : 23..16, + TargetList : 15..0 + } + +register ICC_ASGI1R_EL1 : ICC_ASGI1R_EL1_Type + +bitfield ID_AA64ISAR2_EL1_Type : bits(64) = + { + CSSC : 55..52, + RPRFM : 51..48, + PRFMSLC : 43..40, + SYSINSTR_128 : 39..36, + SYSREG_128 : 35..32, + CLRBHB : 31..28, + PAC_frac : 27..24, + BC : 23..20, + MOPS : 19..16, + APA3 : 15..12, + GPA3 : 11..8, + RPRES : 7..4, + WFxT : 3..0 + } + +register ID_AA64ISAR2_EL1 : ID_AA64ISAR2_EL1_Type + +bitfield HFGRTR2_EL2_Type : bits(64) = + {nRCWSMASK_EL1 : 2..2, nERXGSR_EL1 : 1..1, nPFAR_EL1 : 0..0} + +register HFGRTR2_EL2 : HFGRTR2_EL2_Type + +type TPIDRRO_EL0_Type = bits(64) + +register TPIDRRO_EL0 : TPIDRRO_EL0_Type + +bitfield ID_ISAR5_EL1_Type : bits(64) = + { + VCMA : 31..28, + RDM : 27..24, + CRC32 : 19..16, + SHA2 : 15..12, + SHA1 : 11..8, + AES : 7..4, + SEVL : 3..0 + } + +register ID_ISAR5_EL1 : ID_ISAR5_EL1_Type + +bitfield RMR_EL3_Type : bits(64) = {RR : 1..1, AA64 : 0..0} + +register RMR_EL3 : RMR_EL3_Type + +bitfield ICH_HCR_EL2_Type : bits(64) = + { + EOIcount : 31..27, + DVIM : 15..15, + TDIR : 14..14, + TSEI : 13..13, + TALL1 : 12..12, + TALL0 : 11..11, + TC : 10..10, + vSGIEOICount : 8..8, + VGrp1DIE : 7..7, + VGrp1EIE : 6..6, + VGrp0DIE : 5..5, + VGrp0EIE : 4..4, + NPIE : 3..3, + LRENPIE : 2..2, + UIE : 1..1, + En : 0..0 + } + +register ICH_HCR_EL2 : ICH_HCR_EL2_Type + +bitfield ICC_IGRPEN0_EL1_Type : bits(64) = {Enable : 0..0} + +register ICC_IGRPEN0_EL1 : ICC_IGRPEN0_EL1_Type + +bitfield CNTHPS_TVAL_EL2_Type : bits(64) = {TimerValue : 31..0} + +register CNTHPS_TVAL_EL2 : CNTHPS_TVAL_EL2_Type + +bitfield ICC_BPR1_EL1_Type : bits(64) = {BinaryPoint : 2..0} + +register ICC_BPR1_EL1_S : ICC_BPR1_EL1_Type + +register ICC_BPR1_EL1_NS : ICC_BPR1_EL1_Type + +val ICC_BPR1_EL1_read : unit -> ICC_BPR1_EL1_Type + +function ICC_BPR1_EL1_read () = { + r : ICC_BPR1_EL1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_BPR1_EL1_S + } else { + r = ICC_BPR1_EL1_NS + }; + return(r) +} + +val ICC_BPR1_EL1_write : ICC_BPR1_EL1_Type -> unit + +function ICC_BPR1_EL1_write value_name = { + let r : ICC_BPR1_EL1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_BPR1_EL1_S = r + } else { + ICC_BPR1_EL1_NS = r + }; + return() +} + +type AMAIR_EL1_Type = bits(64) + +register AMAIR_EL1 : AMAIR_EL1_Type + +type SCXTNUM_EL0_Type = bits(64) + +register SCXTNUM_EL0 : SCXTNUM_EL0_Type + +bitfield ICC_EOIR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_EOIR1_EL1 : ICC_EOIR1_EL1_Type + +bitfield ID_AA64MMFR0_EL1_Type : bits(64) = + { + ECV : 63..60, + FGT : 59..56, + ExS : 47..44, + TGran4_2 : 43..40, + TGran64_2 : 39..36, + TGran16_2 : 35..32, + TGran4 : 31..28, + TGran64 : 27..24, + TGran16 : 23..20, + BigEndEL0 : 19..16, + SNSMem : 15..12, + BigEnd : 11..8, + ASIDBits : 7..4, + PARange : 3..0 + } + +register ID_AA64MMFR0_EL1 : ID_AA64MMFR0_EL1_Type + +type TPIDR2_EL0_Type = bits(64) + +register TPIDR2_EL0 : TPIDR2_EL0_Type + +val __set_PMCR_EL0 : PMCR_EL0_Type -> unit + +function __set_PMCR_EL0 value_name = { + let r : PMCR_EL0_Type = value_name; + PMCR_EL0.bits[0] = Bit(Slice(r.bits, 0, 1)); + PMCR_EL0.bits[15 .. 3] = Slice(r.bits, 3, 13); + PMCR_EL0.bits[63 .. 32] = Slice(r.bits, 32, 32); + if not_bool(not_bool(IsFeatureImplemented(FEAT_PMUv3p7))) then { + PMCR_EL0[IMP] = r[IMP] + }; + if not_bool(PMCR_EL0[IMP] != 0b00000000) then { + PMCR_EL0[IDCODE] = r[IDCODE] + }; + PMCR_EL0[C] = r[C]; + PMCR_EL0[P] = r[P]; + return() +} + +bitfield HDFGRTR2_EL2_Type : bits(64) = + { + nPMSDSFR_EL1 : 19..19, + nSPMDEVAFF_EL1 : 18..18, + nSPMID : 17..17, + nSPMSCR_EL1 : 16..16, + nSPMACCESSR_EL1 : 15..15, + nSPMCR_EL0 : 14..14, + nSPMOVS : 13..13, + nSPMINTEN : 12..12, + nSPMCNTEN : 11..11, + nSPMSELR_EL0 : 10..10, + nSPMEVTYPERn_EL0 : 9..9, + nSPMEVCNTRn_EL0 : 8..8, + nPMSSCR_EL1 : 7..7, + nPMSSDATA : 6..6, + nMDSELR_EL1 : 5..5, + nPMUACR_EL1 : 4..4, + nPMICFILTR_EL0 : 3..3, + nPMICNTR_EL0 : 2..2, + nPMIAR_EL1 : 1..1, + nPMECR_EL1 : 0..0 + } + +register HDFGRTR2_EL2 : HDFGRTR2_EL2_Type + +val SDER32_EL3_write : SDER32_EL3_Type -> unit + +function SDER32_EL3_write value_name = { + let r : SDER32_EL3_Type = value_name; + SDER32_EL2.bits[63 .. 0] = Slice(r.bits, 0, 64); + _SDER32_EL3 = r; + return() +} + +bitfield VMPIDR_EL2_Type : bits(64) = + { + Aff3 : 39..32, + U : 30..30, + MT : 24..24, + Aff2 : 23..16, + Aff1 : 15..8, + Aff0 : 7..0 + } + +register VMPIDR_EL2 : VMPIDR_EL2_Type + +bitfield ID_AA64MMFR3_EL1_Type : bits(64) = + { + Spec_FPACC : 63..60, + ADERR : 59..56, + SDERR : 55..52, + ANERR : 47..44, + SNERR : 43..40, + D128_2 : 39..36, + D128 : 35..32, + MEC : 31..28, + AIE : 27..24, + S2POE : 23..20, + S1POE : 19..16, + S2PIE : 15..12, + S1PIE : 11..8, + SCTLRX : 7..4, + TCRX : 3..0 + } + +register ID_AA64MMFR3_EL1 : ID_AA64MMFR3_EL1_Type + +bitfield ICH_VTR_EL2_Type : bits(64) = + { + PRIbits : 31..29, + PREbits : 28..26, + IDbits : 25..23, + SEIS : 22..22, + A3V : 21..21, + nV4 : 20..20, + TDS : 19..19, + DVIM : 18..18, + ListRegs : 4..0 + } + +register ICH_VTR_EL2 : ICH_VTR_EL2_Type + +bitfield ID_PFR1_EL1_Type : bits(64) = + { + GIC : 31..28, + Virt_frac : 27..24, + Sec_frac : 23..20, + GenTimer : 19..16, + Virtualization : 15..12, + MProgMod : 11..8, + Security : 7..4, + ProgMod : 3..0 + } + +register ID_PFR1_EL1 : ID_PFR1_EL1_Type + +val __set_MDSELR_EL1 : MDSELR_EL1_Type -> unit + +function __set_MDSELR_EL1 value_name = { + let r : MDSELR_EL1_Type = value_name; + MDSELR_EL1.bits[3 .. 0] = Slice(r.bits, 0, 4); + MDSELR_EL1.bits[63 .. 6] = Slice(r.bits, 6, 58); + if not_bool(NUM_BREAKPOINTS <= 16 & NUM_WATCHPOINTS <= 16) then { + MDSELR_EL1[BANK] = r[BANK] + }; + return() +} + +val DBGDTR_EL0_write : DBGDTR_EL0_Type -> unit + +function DBGDTR_EL0_write value_name = { + let r : DBGDTR_EL0_Type = value_name; + if __IMPDEF_boolean("read") then { + DBGDTRTX_EL0[31 .. 0] = Slice(r.bits, 32, 32) + } else { + if __IMPDEF_boolean("read") then { + DBGDTRTX_EL0[31 .. 0] = Slice(r.bits, 32, 32) + } else { + DBGDTRRX_EL0[31 .. 0] = Slice(r.bits, 32, 32) + } + }; + if __IMPDEF_boolean("read") then { + DBGDTRRX_EL0[31 .. 0] = Slice(r.bits, 0, 32) + } else { + if __IMPDEF_boolean("read") then { + DBGDTRRX_EL0[31 .. 0] = Slice(r.bits, 0, 32) + } else { + DBGDTRTX_EL0[31 .. 0] = Slice(r.bits, 0, 32) + } + }; + _DBGDTR_EL0 = r; + return() +} + +bitfield ICV_EOIR0_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_EOIR0_EL1 : ICV_EOIR0_EL1_Type + +bitfield ID_DFR1_EL1_Type : bits(64) = {HPMN0 : 7..4, MTPMU : 3..0} + +register ID_DFR1_EL1 : ID_DFR1_EL1_Type + +type SCXTNUM_EL3_Type = bits(64) + +register SCXTNUM_EL3 : SCXTNUM_EL3_Type + +type TPIDR_EL0_Type = bits(64) + +register TPIDR_EL0 : TPIDR_EL0_Type + +type ID_AFR0_EL1_Type = bits(64) + +register ID_AFR0_EL1 : ID_AFR0_EL1_Type + +bitfield RNDRRS_Type : bits(64) = {RNDRRS : 63..0} + +register RNDRRS : RNDRRS_Type + +bitfield LORN_EL1_Type : bits(64) = {Num : 7..0} + +register LORN_EL1 : LORN_EL1_Type + +bitfield ICV_IGRPEN0_EL1_Type : bits(64) = {Enable : 0..0} + +register ICV_IGRPEN0_EL1 : ICV_IGRPEN0_EL1_Type + +bitfield CCSIDR_EL1_Type : bits(64) = {Associativity : 23..3, LineSize : 2..0} + +register CCSIDR_EL1 : CCSIDR_EL1_Type + +bitfield SMPRIMAP_EL2_Type : bits(64) = + { + P15 : 63..60, + P14 : 59..56, + P13 : 55..52, + P12 : 51..48, + P11 : 47..44, + P10 : 43..40, + P9 : 39..36, + P8 : 35..32, + P7 : 31..28, + P6 : 27..24, + P5 : 23..20, + P4 : 19..16, + P3 : 15..12, + P2 : 11..8, + P1 : 7..4, + P0 : 3..0 + } + +register SMPRIMAP_EL2 : SMPRIMAP_EL2_Type + +bitfield RNDR_Type : bits(64) = {RNDR : 63..0} + +register RNDR : RNDR_Type + +bitfield HFGRTR_EL2_Type : bits(64) = + { + nAMAIR2_EL1 : 63..63, + nMAIR2_EL1 : 62..62, + nS2POR_EL1 : 61..61, + nPOR_EL1 : 60..60, + nPOR_EL0 : 59..59, + nPIR_EL1 : 58..58, + nPIRE0_EL1 : 57..57, + nRCWMASK_EL1 : 56..56, + nTPIDR2_EL0 : 55..55, + nSMPRI_EL1 : 54..54, + nGCS_EL1 : 53..53, + nGCS_EL0 : 52..52, + nACCDATA_EL1 : 50..50, + ERXADDR_EL1 : 49..49, + ERXPFGCDN_EL1 : 48..48, + ERXPFGCTL_EL1 : 47..47, + ERXPFGF_EL1 : 46..46, + ERXMISCn_EL1 : 45..45, + ERXSTATUS_EL1 : 44..44, + ERXCTLR_EL1 : 43..43, + ERXFR_EL1 : 42..42, + ERRSELR_EL1 : 41..41, + ERRIDR_EL1 : 40..40, + ICC_IGRPENn_EL1 : 39..39, + VBAR_EL1 : 38..38, + TTBR1_EL1 : 37..37, + TTBR0_EL1 : 36..36, + TPIDR_EL0 : 35..35, + TPIDRRO_EL0 : 34..34, + TPIDR_EL1 : 33..33, + TCR_EL1 : 32..32, + SCXTNUM_EL0 : 31..31, + SCXTNUM_EL1 : 30..30, + SCTLR_EL1 : 29..29, + REVIDR_EL1 : 28..28, + PAR_EL1 : 27..27, + MPIDR_EL1 : 26..26, + MIDR_EL1 : 25..25, + MAIR_EL1 : 24..24, + LORSA_EL1 : 23..23, + LORN_EL1 : 22..22, + LORID_EL1 : 21..21, + LOREA_EL1 : 20..20, + LORC_EL1 : 19..19, + ISR_EL1 : 18..18, + FAR_EL1 : 17..17, + ESR_EL1 : 16..16, + DCZID_EL0 : 15..15, + CTR_EL0 : 14..14, + CSSELR_EL1 : 13..13, + CPACR_EL1 : 12..12, + CONTEXTIDR_EL1 : 11..11, + CLIDR_EL1 : 10..10, + CCSIDR_EL1 : 9..9, + APIBKey : 8..8, + APIAKey : 7..7, + APGAKey : 6..6, + APDBKey : 5..5, + APDAKey : 4..4, + AMAIR_EL1 : 3..3, + AIDR_EL1 : 2..2, + AFSR1_EL1 : 1..1, + AFSR0_EL1 : 0..0 + } + +register HFGRTR_EL2 : HFGRTR_EL2_Type + +bitfield ID_DFR0_EL1_Type : bits(64) = + { + TraceFilt : 31..28, + PerfMon : 27..24, + MProfDbg : 23..20, + MMapTrc : 19..16, + CopTrc : 15..12, + MMapDbg : 11..8, + CopSDbg : 7..4, + CopDbg : 3..0 + } + +register ID_DFR0_EL1 : ID_DFR0_EL1_Type + +bitfield ICV_IGRPEN1_EL1_Type : bits(64) = {Enable : 0..0} + +register ICV_IGRPEN1_EL1 : ICV_IGRPEN1_EL1_Type + +bitfield PMXEVCNTR_EL0_Type : bits(64) = {PMEVCNTR : 63..0} + +register PMXEVCNTR_EL0 : PMXEVCNTR_EL0_Type + +bitfield HFGWTR2_EL2_Type : bits(64) = {nRCWSMASK_EL1 : 2..2, nPFAR_EL1 : 0..0} + +register HFGWTR2_EL2 : HFGWTR2_EL2_Type + +bitfield ICC_SGI1R_EL1_Type : bits(64) = + { + Aff3 : 55..48, + RS : 47..44, + IRM : 40..40, + Aff2 : 39..32, + INTID : 27..24, + Aff1 : 23..16, + TargetList : 15..0 + } + +register ICC_SGI1R_EL1 : ICC_SGI1R_EL1_Type + +type HACR_EL2_Type = bits(64) + +register HACR_EL2 : HACR_EL2_Type + +bitfield MVFR2_EL1_Type : bits(64) = {FPMisc : 7..4, SIMDMisc : 3..0} + +register MVFR2_EL1 : MVFR2_EL1_Type + +bitfield DBGAUTHSTATUS_EL1_Type : bits(64) = + { + RTNID : 27..26, + RTID : 25..24, + RLNID : 15..14, + RLID : 13..12, + SNID : 7..6, + SID : 5..4, + NSNID : 3..2, + NSID : 1..0 + } + +register DBGAUTHSTATUS_EL1 : DBGAUTHSTATUS_EL1_Type + +type AMAIR2_EL3_Type = bits(64) + +register AMAIR2_EL3 : AMAIR2_EL3_Type + +bitfield ICC_SRE_EL3_Type : bits(64) = + {Enable : 3..3, DIB : 2..2, DFB : 1..1, SRE : 0..0} + +register ICC_SRE_EL3 : ICC_SRE_EL3_Type + +type AFSR1_EL3_Type = bits(64) + +register AFSR1_EL3 : AFSR1_EL3_Type + +bitfield ID_MMFR3_EL1_Type : bits(64) = + { + Supersec : 31..28, + CMemSz : 27..24, + CohWalk : 23..20, + PAN : 19..16, + MaintBcst : 15..12, + BPMaint : 11..8, + CMaintSW : 7..4, + CMaintVA : 3..0 + } + +register ID_MMFR3_EL1 : ID_MMFR3_EL1_Type + +bitfield HDFGWTR_EL2_Type : bits(64) = + { + nPMSNEVFR_EL1 : 62..62, + nBRBDATA : 61..61, + nBRBCTL : 60..60, + PMUSERENR_EL0 : 57..57, + TRFCR_EL1 : 49..49, + TRCVICTLR : 48..48, + TRCSSCSRn : 46..46, + TRCSEQSTR : 45..45, + TRCPRGCTLR : 44..44, + TRCOSLAR : 42..42, + TRCIMSPECn : 41..41, + TRCCNTVRn : 37..37, + TRCCLAIM : 36..36, + TRCAUXCTLR : 35..35, + TRC : 33..33, + PMSLATFR_EL1 : 32..32, + PMSIRR_EL1 : 31..31, + PMSICR_EL1 : 29..29, + PMSFCR_EL1 : 28..28, + PMSEVFR_EL1 : 27..27, + PMSCR_EL1 : 26..26, + PMBSR_EL1 : 25..25, + PMBPTR_EL1 : 24..24, + PMBLIMITR_EL1 : 23..23, + PMCR_EL0 : 21..21, + PMSWINC_EL0 : 20..20, + PMSELR_EL0 : 19..19, + PMOVS : 18..18, + PMINTEN : 17..17, + PMCNTEN : 16..16, + PMCCNTR_EL0 : 15..15, + PMCCFILTR_EL0 : 14..14, + PMEVTYPERn_EL0 : 13..13, + PMEVCNTRn_EL0 : 12..12, + OSDLR_EL1 : 11..11, + OSECCR_EL1 : 10..10, + OSLAR_EL1 : 8..8, + DBGPRCR_EL1 : 7..7, + DBGCLAIM : 5..5, + MDSCR_EL1 : 4..4, + DBGWVRn_EL1 : 3..3, + DBGWCRn_EL1 : 2..2, + DBGBVRn_EL1 : 1..1, + DBGBCRn_EL1 : 0..0 + } + +register HDFGWTR_EL2 : HDFGWTR_EL2_Type + +bitfield PMCEID1_EL0_Type : bits(64) = + { + IDhi31 : 63..63, + IDhi30 : 62..62, + IDhi29 : 61..61, + IDhi28 : 60..60, + IDhi27 : 59..59, + IDhi26 : 58..58, + IDhi25 : 57..57, + IDhi24 : 56..56, + IDhi23 : 55..55, + IDhi22 : 54..54, + IDhi21 : 53..53, + IDhi20 : 52..52, + IDhi19 : 51..51, + IDhi18 : 50..50, + IDhi17 : 49..49, + IDhi16 : 48..48, + IDhi15 : 47..47, + IDhi14 : 46..46, + IDhi13 : 45..45, + IDhi12 : 44..44, + IDhi11 : 43..43, + IDhi10 : 42..42, + IDhi9 : 41..41, + IDhi8 : 40..40, + IDhi7 : 39..39, + IDhi6 : 38..38, + IDhi5 : 37..37, + IDhi4 : 36..36, + IDhi3 : 35..35, + IDhi2 : 34..34, + IDhi1 : 33..33, + IDhi0 : 32..32, + ID31 : 31..31, + ID30 : 30..30, + ID29 : 29..29, + ID28 : 28..28, + ID27 : 27..27, + ID26 : 26..26, + ID25 : 25..25, + ID24 : 24..24, + ID23 : 23..23, + ID22 : 22..22, + ID21 : 21..21, + ID20 : 20..20, + ID19 : 19..19, + ID18 : 18..18, + ID17 : 17..17, + ID16 : 16..16, + ID15 : 15..15, + ID14 : 14..14, + ID13 : 13..13, + ID12 : 12..12, + ID11 : 11..11, + ID10 : 10..10, + ID9 : 9..9, + ID8 : 8..8, + ID7 : 7..7, + ID6 : 6..6, + ID5 : 5..5, + ID4 : 4..4, + ID3 : 3..3, + ID2 : 2..2, + ID1 : 1..1, + ID0 : 0..0 + } + +register PMCEID1_EL0 : PMCEID1_EL0_Type + +bitfield CNTPS_TVAL_EL1_Type : bits(64) = {TimerValue : 31..0} + +register CNTPS_TVAL_EL1 : CNTPS_TVAL_EL1_Type + +type ID_AA64AFR1_EL1_Type = bits(64) + +register ID_AA64AFR1_EL1 : ID_AA64AFR1_EL1_Type + +bitfield ICV_AP1R_EL1_Type : bits(64) = {NMI : 63..63} + +register ICV_AP1R_EL1 : vector(4, ICV_AP1R_EL1_Type) + +bitfield LOREA_EL1_Type : bits(64) = {EA : (55..52 @ (51..48 @ 47..16))} + +register LOREA_EL1 : LOREA_EL1_Type + +bitfield CNTV_TVAL_EL0_Type : bits(64) = {TimerValue : 31..0} + +register CNTV_TVAL_EL0 : CNTV_TVAL_EL0_Type + +bitfield ICV_DIR_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_DIR_EL1 : ICV_DIR_EL1_Type + +bitfield ICC_IAR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_IAR1_EL1 : ICC_IAR1_EL1_Type + +bitfield MPIDR_EL1_Type : bits(64) = + { + Aff3 : 39..32, + U : 30..30, + MT : 24..24, + Aff2 : 23..16, + Aff1 : 15..8, + Aff0 : 7..0 + } + +register MPIDR_EL1 : MPIDR_EL1_Type + +bitfield DBGCLAIMCLR_EL1_Type : bits(64) = {CLAIM : 7..0} + +register DBGCLAIMCLR_EL1 : DBGCLAIMCLR_EL1_Type + +bitfield PMCEID0_EL0_Type : bits(64) = + { + IDhi31 : 63..63, + IDhi30 : 62..62, + IDhi29 : 61..61, + IDhi28 : 60..60, + IDhi27 : 59..59, + IDhi26 : 58..58, + IDhi25 : 57..57, + IDhi24 : 56..56, + IDhi23 : 55..55, + IDhi22 : 54..54, + IDhi21 : 53..53, + IDhi20 : 52..52, + IDhi19 : 51..51, + IDhi18 : 50..50, + IDhi17 : 49..49, + IDhi16 : 48..48, + IDhi15 : 47..47, + IDhi14 : 46..46, + IDhi13 : 45..45, + IDhi12 : 44..44, + IDhi11 : 43..43, + IDhi10 : 42..42, + IDhi9 : 41..41, + IDhi8 : 40..40, + IDhi7 : 39..39, + IDhi6 : 38..38, + IDhi5 : 37..37, + IDhi4 : 36..36, + IDhi3 : 35..35, + IDhi2 : 34..34, + IDhi1 : 33..33, + IDhi0 : 32..32, + ID31 : 31..31, + ID30 : 30..30, + ID29 : 29..29, + ID28 : 28..28, + ID27 : 27..27, + ID26 : 26..26, + ID25 : 25..25, + ID24 : 24..24, + ID23 : 23..23, + ID22 : 22..22, + ID21 : 21..21, + ID20 : 20..20, + ID19 : 19..19, + ID18 : 18..18, + ID17 : 17..17, + ID16 : 16..16, + ID15 : 15..15, + ID14 : 14..14, + ID13 : 13..13, + ID12 : 12..12, + ID11 : 11..11, + ID10 : 10..10, + ID9 : 9..9, + ID8 : 8..8, + ID7 : 7..7, + ID6 : 6..6, + ID5 : 5..5, + ID4 : 4..4, + ID3 : 3..3, + ID2 : 2..2, + ID1 : 1..1, + ID0 : 0..0 + } + +register PMCEID0_EL0 : PMCEID0_EL0_Type + +bitfield ICV_HPPIR1_EL1_Type : bits(64) = {INTID : 23..0} + +register ICV_HPPIR1_EL1 : ICV_HPPIR1_EL1_Type + +type ID_AA64AFR0_EL1_Type = bits(64) + +register ID_AA64AFR0_EL1 : ID_AA64AFR0_EL1_Type + +type AFSR0_EL2_Type = bits(64) + +register AFSR0_EL2 : AFSR0_EL2_Type + +type AMAIR2_EL1_Type = bits(64) + +register AMAIR2_EL1 : AMAIR2_EL1_Type + +bitfield ID_PFR2_EL1_Type : bits(64) = + {RAS_frac : 11..8, SSBS : 7..4, CSV3 : 3..0} + +register ID_PFR2_EL1 : ID_PFR2_EL1_Type + +bitfield SPMACCESSR_EL3_Type : bits(64) = + { + P31 : 63..62, + P30 : 61..60, + P29 : 59..58, + P28 : 57..56, + P27 : 55..54, + P26 : 53..52, + P25 : 51..50, + P24 : 49..48, + P23 : 47..46, + P22 : 45..44, + P21 : 43..42, + P20 : 41..40, + P19 : 39..38, + P18 : 37..36, + P17 : 35..34, + P16 : 33..32, + P15 : 31..30, + P14 : 29..28, + P13 : 27..26, + P12 : 25..24, + P11 : 23..22, + P10 : 21..20, + P9 : 19..18, + P8 : 17..16, + P7 : 15..14, + P6 : 13..12, + P5 : 11..10, + P4 : 9..8, + P3 : 7..6, + P2 : 5..4, + P1 : 3..2, + P0 : 1..0 + } + +register SPMACCESSR_EL3 : SPMACCESSR_EL3_Type + +val __get_selected_SPMACCESSR_EL3_field : unit -> bits(2) + +function __get_selected_SPMACCESSR_EL3_field () = { + let 'idx = UInt(SPMSELR_EL0[SYSPMUSEL]) * 2; + return(Slice(SPMACCESSR_EL3.bits, idx, 2)) +} + +val __set_CNTHV_CTL_EL2 : CNTHV_CTL_EL2_Type -> unit + +function __set_CNTHV_CTL_EL2 value_name = { + let r : CNTHV_CTL_EL2_Type = value_name; + CNTHV_CTL_EL2.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTHV_CTL_EL2.bits[63 .. 3] = Slice(r.bits, 3, 61); + return() +} + +bitfield ICC_EOIR0_EL1_Type : bits(64) = {INTID : 23..0} + +register ICC_EOIR0_EL1 : ICC_EOIR0_EL1_Type + +bitfield ID_AA64ZFR0_EL1_Type : bits(64) = + { + F64MM : 59..56, + F32MM : 55..52, + I8MM : 47..44, + SM4 : 43..40, + SHA3 : 35..32, + B16B16 : 27..24, + BF16 : 23..20, + BitPerm : 19..16, + AES : 7..4, + SVEver : 3..0 + } + +register ID_AA64ZFR0_EL1 : ID_AA64ZFR0_EL1_Type + +bitfield ICC_SGI1R_Type : bits(64) = + { + Aff3 : 55..48, + RS : 47..44, + IRM : 40..40, + Aff2 : 39..32, + INTID : 27..24, + Aff1 : 23..16, + TargetList : 15..0 + } + +register _ICC_SGI1R : ICC_SGI1R_Type + +val ICC_SGI1R_read : unit -> ICC_SGI1R_Type + +function ICC_SGI1R_read () = { + r : ICC_SGI1R_Type = _ICC_SGI1R; + r.bits[63 .. 0] = Slice(ICC_SGI1R_EL1.bits, 0, 64); + return(r) +} + +val ICC_SGI1R_write : ICC_SGI1R_Type -> unit + +function ICC_SGI1R_write value_name = { + let r : ICC_SGI1R_Type = value_name; + ICC_SGI1R_EL1.bits[63 .. 0] = Slice(r.bits, 0, 64); + _ICC_SGI1R = r; + return() +} + +type DBGDSAR_Type = bits(64) + +register DBGDSAR : DBGDSAR_Type + +bitfield ICC_SGI0R_Type : bits(64) = + { + Aff3 : 55..48, + RS : 47..44, + IRM : 40..40, + Aff2 : 39..32, + INTID : 27..24, + Aff1 : 23..16, + TargetList : 15..0 + } + +register _ICC_SGI0R : ICC_SGI0R_Type + +val ICC_SGI0R_read : unit -> ICC_SGI0R_Type + +function ICC_SGI0R_read () = { + r : ICC_SGI0R_Type = _ICC_SGI0R; + r.bits[63 .. 0] = Slice(ICC_SGI0R_EL1.bits, 0, 64); + return(r) +} + +val ICC_SGI0R_write : ICC_SGI0R_Type -> unit + +function ICC_SGI0R_write value_name = { + let r : ICC_SGI0R_Type = value_name; + ICC_SGI0R_EL1.bits[63 .. 0] = Slice(r.bits, 0, 64); + _ICC_SGI0R = r; + return() +} + +type CNTVOFF_Type = bits(64) + +register _CNTVOFF : CNTVOFF_Type + +val CNTVOFF_read : unit -> CNTVOFF_Type + +function CNTVOFF_read () = { + r : CNTVOFF_Type = _CNTVOFF; + r[63 .. 0] = Slice(CNTVOFF_EL2, 0, 64); + return(r) +} + +val CNTVOFF_write : CNTVOFF_Type -> unit + +function CNTVOFF_write value_name = { + let r : CNTVOFF_Type = value_name; + CNTVOFF_EL2[63 .. 0] = Slice(r, 0, 64); + _CNTVOFF = r; + return() +} + +bitfield ICC_ASGI1R_Type : bits(64) = + { + Aff3 : 55..48, + RS : 47..44, + IRM : 40..40, + Aff2 : 39..32, + INTID : 27..24, + Aff1 : 23..16, + TargetList : 15..0 + } + +register _ICC_ASGI1R : ICC_ASGI1R_Type + +val ICC_ASGI1R_read : unit -> ICC_ASGI1R_Type + +function ICC_ASGI1R_read () = { + r : ICC_ASGI1R_Type = _ICC_ASGI1R; + r.bits[63 .. 0] = Slice(ICC_ASGI1R_EL1.bits, 0, 64); + return(r) +} + +val ICC_ASGI1R_write : ICC_ASGI1R_Type -> unit + +function ICC_ASGI1R_write value_name = { + let r : ICC_ASGI1R_Type = value_name; + ICC_ASGI1R_EL1.bits[63 .. 0] = Slice(r.bits, 0, 64); + _ICC_ASGI1R = r; + return() +} + +val CNTHP_CVAL_write : CNTHP_CVAL_Type -> unit + +function CNTHP_CVAL_write value_name = { + let r : CNTHP_CVAL_Type = value_name; + CNTHP_CVAL_EL2.bits[63 .. 0] = Slice(r.bits, 0, 64); + _CNTHP_CVAL = r; + return() +} + +bitfield CNTV_CVAL_Type : bits(64) = {CompareValue : 63..0} + +register _CNTV_CVAL : CNTV_CVAL_Type + +val CNTV_CVAL_read : unit -> CNTV_CVAL_Type + +function CNTV_CVAL_read () = { + r : CNTV_CVAL_Type = _CNTV_CVAL; + r.bits[63 .. 0] = Slice(CNTV_CVAL_EL0.bits, 0, 64); + return(r) +} + +val CNTV_CVAL_write : CNTV_CVAL_Type -> unit + +function CNTV_CVAL_write value_name = { + let r : CNTV_CVAL_Type = value_name; + CNTV_CVAL_EL0.bits[63 .. 0] = Slice(r.bits, 0, 64); + _CNTV_CVAL = r; + return() +} + +val TTBR1_write : TTBR1_Type -> unit + +function TTBR1_write value_name = { + let r : TTBR1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + TTBR1_S = r + } else { + TTBR1_NS = r + }; + return() +} + +val TTBR0_write : TTBR0_Type -> unit + +function TTBR0_write value_name = { + let r : TTBR0_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + TTBR0_S = r + } else { + TTBR0_NS = r + }; + return() +} + +bitfield DBGDRAR_Type : bits(64) = {ROMADDR : 47..12, Valid : 1..0} + +register _DBGDRAR : DBGDRAR_Type + +val DBGDRAR_read : unit -> DBGDRAR_Type + +function DBGDRAR_read () = { + r : DBGDRAR_Type = _DBGDRAR; + r.bits[63 .. 0] = Slice(MDRAR_EL1.bits, 0, 64); + return(r) +} + +val DBGDRAR_write : DBGDRAR_Type -> unit + +function DBGDRAR_write value_name = { + let r : DBGDRAR_Type = value_name; + MDRAR_EL1.bits[63 .. 0] = Slice(r.bits, 0, 64); + _DBGDRAR = r; + return() +} + +val CNTP_CVAL_NS_write : CNTP_CVAL_Type -> unit + +function CNTP_CVAL_NS_write value_name = { + let r : CNTP_CVAL_Type = value_name; + CNTP_CVAL_EL0.bits[63 .. 0] = Slice(r.bits, 0, 64); + _CNTP_CVAL_NS = r; + return() +} + +val CNTP_CVAL_write : CNTP_CVAL_Type -> unit + +function CNTP_CVAL_write value_name = { + let r : CNTP_CVAL_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + CNTP_CVAL_S = r + } else { + CNTP_CVAL_NS_write() = r + }; + return() +} + +bitfield ID_AA64SMFR0_EL1_Type : bits(64) = + { + FA64 : 63..63, + SMEver : 59..56, + I16I64 : 55..52, + F64F64 : 48..48, + I16I32 : 47..44, + B16B16 : 43..43, + F16F16 : 42..42, + I8I32 : 39..36, + F16F32 : 35..35, + B16F32 : 34..34, + BI32I32 : 33..33, + F32F32 : 32..32 + } + +register ID_AA64SMFR0_EL1 : ID_AA64SMFR0_EL1_Type + +val __set_MPAM2_EL2 : MPAM2_EL2_Type -> unit + +function __set_MPAM2_EL2 value_name = { + let r : MPAM2_EL2_Type = value_name; + MPAM2_EL2.bits[53 .. 0] = Slice(r.bits, 0, 54); + MPAM2_EL2.bits[62 .. 55] = Slice(r.bits, 55, 8); + if not_bool(HaveEL(EL3)) then { + MPAM2_EL2[MPAMEN] = r[MPAMEN] + }; + return() +} + +val MPAM3_EL3_write : MPAM3_EL3_Type -> unit + +function MPAM3_EL3_write value_name = { + let r : MPAM3_EL3_Type = value_name; + MPAM2_EL2.bits[63] = Bit(Slice(r.bits, 63, 1)); + _MPAM3_EL3 = r; + return() +} + +val __set_MPAM3_EL3 : MPAM3_EL3_Type -> unit + +function __set_MPAM3_EL3 value_name = { + let r : MPAM3_EL3_Type = value_name; + MPAM3_EL3_write() = Mk_MPAM3_EL3_Type(SetSlice(63, MPAM3_EL3_read().bits, 0, Slice(r.bits, 0, 63))); + MPAM3_EL3_write() = [MPAM3_EL3_read() with MPAMEN = r[MPAMEN]]; + return() +} + +val MPAM1_EL1_write : MPAM1_EL1_Type -> unit + +function MPAM1_EL1_write value_name = { + let r : MPAM1_EL1_Type = value_name; + if HaveEL(EL3) then { + MPAM3_EL3_write() = Mk_MPAM3_EL3_Type(SetSlice(1, MPAM3_EL3_read().bits, 63, Slice(r.bits, 63, 1))) + } else { + MPAM2_EL2.bits[63] = Bit(Slice(r.bits, 63, 1)) + }; + _MPAM1_EL1 = r; + return() +} + +val __set_MPAM1_EL1 : MPAM1_EL1_Type -> unit + +function __set_MPAM1_EL1 value_name = { + let r : MPAM1_EL1_Type = value_name; + MPAM1_EL1_write() = Mk_MPAM1_EL1_Type(SetSlice(54, MPAM1_EL1_read().bits, 0, Slice(r.bits, 0, 54))); + MPAM1_EL1_write() = Mk_MPAM1_EL1_Type(SetSlice(5, MPAM1_EL1_read().bits, 55, Slice(r.bits, 55, 5))); + MPAM1_EL1_write() = Mk_MPAM1_EL1_Type(SetSlice(2, MPAM1_EL1_read().bits, 61, Slice(r.bits, 61, 2))); + if not_bool(HaveEL(EL3)) & not_bool(HaveEL(EL2)) then { + MPAM1_EL1_write() = [MPAM1_EL1_read() with MPAMEN = r[MPAMEN]] + }; + return() +} + +bitfield GMID_EL1_Type : bits(64) = {BS : 3..0} + +register GMID_EL1 : GMID_EL1_Type + +bitfield AMEVCNTR1_EL0_Type : bits(64) = {ACNT : 63..0} + +register AMEVCNTR1_EL0 : vector(16, AMEVCNTR1_EL0_Type) + +type AMEVCNTVOFF0_EL2_Type = bits(64) + +register AMEVCNTVOFF0_EL2 : vector(16, AMEVCNTVOFF0_EL2_Type) + +bitfield AMEVCNTR0_Type : bits(64) = {ACNT : 63..0} + +register AMEVCNTR0 : vector(4, AMEVCNTR0_Type) + +bitfield AMEVCNTR1_Type : bits(64) = {ACNT : 63..0} + +register _AMEVCNTR1 : vector(16, AMEVCNTR1_Type) + +val AMEVCNTR1_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> AMEVCNTR1_Type + +function AMEVCNTR1_read n = { + r : AMEVCNTR1_Type = _AMEVCNTR1[n]; + r.bits[63 .. 0] = Slice(AMEVCNTR1_EL0[n].bits, 0, 64); + return(r) +} + +val AMEVCNTR1_set : forall 'n, (0 <= 'n & 'n < 16). + (int('n), AMEVCNTR1_Type) -> unit + +function AMEVCNTR1_set (n, value_name) = { + let r : AMEVCNTR1_Type = value_name; + AMEVCNTR1_EL0[n].bits[63 .. 0] = Slice(r.bits, 0, 64); + _AMEVCNTR1[n] = r; + return() +} + +bitfield AMCR_EL0_Type : bits(64) = {CG1RZ : 17..17, HDBG : 10..10} + +register AMCR_EL0 : AMCR_EL0_Type + +bitfield AMCNTENSET0_EL0_Type : bits(64) = + {P3 : 3..3, P2 : 2..2, P1 : 1..1, P0 : 0..0} + +register AMCNTENSET0_EL0 : AMCNTENSET0_EL0_Type + +bitfield AMCNTENCLR0_EL0_Type : bits(64) = + {P3 : 3..3, P2 : 2..2, P1 : 1..1, P0 : 0..0} + +register AMCNTENCLR0_EL0 : AMCNTENCLR0_EL0_Type + +bitfield AMEVTYPER0_EL0_Type : bits(64) = {evtCount : 15..0} + +register AMEVTYPER0_EL0 : vector(4, AMEVTYPER0_EL0_Type) + +bitfield AMCNTENSET1_EL0_Type : bits(64) = + { + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register AMCNTENSET1_EL0 : AMCNTENSET1_EL0_Type + +bitfield AMCNTENCLR1_EL0_Type : bits(64) = + { + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register AMCNTENCLR1_EL0 : AMCNTENCLR1_EL0_Type + +bitfield AMEVCNTR0_EL0_Type : bits(64) = {ACNT : 63..0} + +register _AMEVCNTR0_EL0 : vector(4, AMEVCNTR0_EL0_Type) + +val AMEVCNTR0_EL0_read : forall 'n, (0 <= 'n & 'n < 4). + int('n) -> AMEVCNTR0_EL0_Type + +function AMEVCNTR0_EL0_read n = { + r : AMEVCNTR0_EL0_Type = _AMEVCNTR0_EL0[n]; + r.bits[63 .. 0] = Slice(AMEVCNTR0[n].bits, 0, 64); + return(r) +} + +val AMEVCNTR0_EL0_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), AMEVCNTR0_EL0_Type) -> unit + +function AMEVCNTR0_EL0_set (n, value_name) = { + let r : AMEVCNTR0_EL0_Type = value_name; + AMEVCNTR0[n].bits[63 .. 0] = Slice(r.bits, 0, 64); + _AMEVCNTR0_EL0[n] = r; + return() +} + +bitfield AMCFGR_EL0_Type : bits(64) = + {NCG : 31..28, HDBG : 24..24, SIZE : 13..8, N : 7..0} + +register AMCFGR_EL0 : AMCFGR_EL0_Type + +type AMEVCNTVOFF1_EL2_Type = bits(64) + +register AMEVCNTVOFF1_EL2 : vector(16, AMEVCNTVOFF1_EL2_Type) + +bitfield AMUSERENR_EL0_Type : bits(64) = {EN : 0..0} + +register AMUSERENR_EL0 : AMUSERENR_EL0_Type + +bitfield AMCG1IDR_EL0_Type : bits(64) = + { + AMEVCNTOFF115_EL2 : 31..31, + AMEVCNTOFF114_EL2 : 30..30, + AMEVCNTOFF113_EL2 : 29..29, + AMEVCNTOFF112_EL2 : 28..28, + AMEVCNTOFF111_EL2 : 27..27, + AMEVCNTOFF110_EL2 : 26..26, + AMEVCNTOFF19_EL2 : 25..25, + AMEVCNTOFF18_EL2 : 24..24, + AMEVCNTOFF17_EL2 : 23..23, + AMEVCNTOFF16_EL2 : 22..22, + AMEVCNTOFF15_EL2 : 21..21, + AMEVCNTOFF14_EL2 : 20..20, + AMEVCNTOFF13_EL2 : 19..19, + AMEVCNTOFF12_EL2 : 18..18, + AMEVCNTOFF11_EL2 : 17..17, + AMEVCNTOFF10_EL2 : 16..16, + AMEVCNTR115_EL0 : 15..15, + AMEVCNTR114_EL0 : 14..14, + AMEVCNTR113_EL0 : 13..13, + AMEVCNTR112_EL0 : 12..12, + AMEVCNTR111_EL0 : 11..11, + AMEVCNTR110_EL0 : 10..10, + AMEVCNTR19_EL0 : 9..9, + AMEVCNTR18_EL0 : 8..8, + AMEVCNTR17_EL0 : 7..7, + AMEVCNTR16_EL0 : 6..6, + AMEVCNTR15_EL0 : 5..5, + AMEVCNTR14_EL0 : 4..4, + AMEVCNTR13_EL0 : 3..3, + AMEVCNTR12_EL0 : 2..2, + AMEVCNTR11_EL0 : 1..1, + AMEVCNTR10_EL0 : 0..0 + } + +register AMCG1IDR_EL0 : AMCG1IDR_EL0_Type + +bitfield AMEVTYPER1_EL0_Type : bits(64) = {evtCount : 15..0} + +register AMEVTYPER1_EL0 : vector(16, AMEVTYPER1_EL0_Type) + +bitfield AMCGCR_EL0_Type : bits(64) = {CG1NC : 15..8, CG0NC : 7..0} + +register AMCGCR_EL0 : AMCGCR_EL0_Type + +val __set_PMSNEVFR_EL1 : PMSNEVFR_EL1_Type -> unit + +function __set_PMSNEVFR_EL1 value_name = { + r : PMSNEVFR_EL1_Type = value_name; + if not_bool(__IMPDEF_boolean("event 63 is not implemented, or filtering on event 63 is not supported")) then { + r[E63] = PMSNEVFR_EL1[E63] + }; + if not_bool(__IMPDEF_boolean("event 62 is not implemented, or filtering on event 62 is not supported")) then { + r[E62] = PMSNEVFR_EL1[E62] + }; + if not_bool(__IMPDEF_boolean("event 61 is not implemented, or filtering on event 61 is not supported")) then { + r[E61] = PMSNEVFR_EL1[E61] + }; + if not_bool(__IMPDEF_boolean("event 60 is not implemented, or filtering on event 60 is not supported")) then { + r[E60] = PMSNEVFR_EL1[E60] + }; + if not_bool(__IMPDEF_boolean("event 59 is not implemented, or filtering on event 59 is not supported")) then { + r[E59] = PMSNEVFR_EL1[E59] + }; + if not_bool(__IMPDEF_boolean("event 58 is not implemented, or filtering on event 58 is not supported")) then { + r[E58] = PMSNEVFR_EL1[E58] + }; + if not_bool(__IMPDEF_boolean("event 57 is not implemented, or filtering on event 57 is not supported")) then { + r[E57] = PMSNEVFR_EL1[E57] + }; + if not_bool(__IMPDEF_boolean("event 56 is not implemented, or filtering on event 56 is not supported")) then { + r[E56] = PMSNEVFR_EL1[E56] + }; + if not_bool(__IMPDEF_boolean("event 55 is not implemented, or filtering on event 55 is not supported")) then { + r[E55] = PMSNEVFR_EL1[E55] + }; + if not_bool(__IMPDEF_boolean("event 54 is not implemented, or filtering on event 54 is not supported")) then { + r[E54] = PMSNEVFR_EL1[E54] + }; + if not_bool(__IMPDEF_boolean("event 53 is not implemented, or filtering on event 53 is not supported")) then { + r[E53] = PMSNEVFR_EL1[E53] + }; + if not_bool(__IMPDEF_boolean("event 52 is not implemented, or filtering on event 52 is not supported")) then { + r[E52] = PMSNEVFR_EL1[E52] + }; + if not_bool(__IMPDEF_boolean("event 51 is not implemented, or filtering on event 51 is not supported")) then { + r[E51] = PMSNEVFR_EL1[E51] + }; + if not_bool(__IMPDEF_boolean("event 50 is not implemented, or filtering on event 50 is not supported")) then { + r[E50] = PMSNEVFR_EL1[E50] + }; + if not_bool(__IMPDEF_boolean("event 49 is not implemented, or filtering on event 49 is not supported")) then { + r[E49] = PMSNEVFR_EL1[E49] + }; + if not_bool(__IMPDEF_boolean("event 48 is not implemented, or filtering on event 48 is not supported")) then { + r[E48] = PMSNEVFR_EL1[E48] + }; + if not_bool(__IMPDEF_boolean("event 31 is not implemented, or filtering on event 31 is not supported")) then { + r[E31] = PMSNEVFR_EL1[E31] + }; + if not_bool(__IMPDEF_boolean("event 30 is not implemented, or filtering on event 30 is not supported")) then { + r[E30] = PMSNEVFR_EL1[E30] + }; + if not_bool(__IMPDEF_boolean("event 29 is not implemented, or filtering on event 29 is not supported")) then { + r[E29] = PMSNEVFR_EL1[E29] + }; + if not_bool(__IMPDEF_boolean("event 28 is not implemented, or filtering on event 28 is not supported")) then { + r[E28] = PMSNEVFR_EL1[E28] + }; + if not_bool(__IMPDEF_boolean("event 27 is not implemented, or filtering on event 27 is not supported")) then { + r[E27] = PMSNEVFR_EL1[E27] + }; + if not_bool(__IMPDEF_boolean("event 26 is not implemented, or filtering on event 26 is not supported")) then { + r[E26] = PMSNEVFR_EL1[E26] + }; + if not_bool(__IMPDEF_boolean("event 25 is not implemented, or filtering on event 25 is not supported")) then { + r[E25] = PMSNEVFR_EL1[E25] + }; + if not_bool(__IMPDEF_boolean("event 24 is not implemented, or filtering on event 24 is not supported")) then { + r[E24] = PMSNEVFR_EL1[E24] + }; + if not_bool(__IMPDEF_boolean("event 15 is not implemented, or filtering on event 15 is not supported")) then { + r[E15] = PMSNEVFR_EL1[E15] + }; + if not_bool(__IMPDEF_boolean("event 14 is not implemented, or filtering on event 14 is not supported")) then { + r[E14] = PMSNEVFR_EL1[E14] + }; + if not_bool(__IMPDEF_boolean("event 13 is not implemented, or filtering on event 13 is not supported")) then { + r[E13] = PMSNEVFR_EL1[E13] + }; + if not_bool(__IMPDEF_boolean("event 12 is not implemented, or filtering on event 12 is not supported")) then { + r[E12] = PMSNEVFR_EL1[E12] + }; + PMSNEVFR_EL1 = r; + return() +} + +type ERXADDR_EL1_Type = bits(64) + +register ERXADDR_EL1 : ERXADDR_EL1_Type + +type ERXMISC0_EL1_Type = bits(64) + +register ERXMISC0_EL1 : ERXMISC0_EL1_Type + +bitfield ERRIDR_EL1_Type : bits(64) = {NUM : 15..0} + +register ERRIDR_EL1 : ERRIDR_EL1_Type + +type ERXPFGCDN_EL1_Type = bits(64) + +register ERXPFGCDN_EL1 : ERXPFGCDN_EL1_Type + +type ERXPFGF_EL1_Type = bits(64) + +register ERXPFGF_EL1 : ERXPFGF_EL1_Type + +bitfield ERRSELR_EL1_Type : bits(64) = {SEL : 15..0} + +register ERRSELR_EL1 : ERRSELR_EL1_Type + +type ERXMISC1_EL1_Type = bits(64) + +register ERXMISC1_EL1 : ERXMISC1_EL1_Type + +type ERXCTLR_EL1_Type = bits(64) + +register ERXCTLR_EL1 : ERXCTLR_EL1_Type + +type ERXSTATUS_EL1_Type = bits(64) + +register ERXSTATUS_EL1 : ERXSTATUS_EL1_Type + +type ERXFR_EL1_Type = bits(64) + +register ERXFR_EL1 : ERXFR_EL1_Type + +bitfield ERXGSR_EL1_Type : bits(64) = + { + S63 : 63..63, + S62 : 62..62, + S61 : 61..61, + S60 : 60..60, + S59 : 59..59, + S58 : 58..58, + S57 : 57..57, + S56 : 56..56, + S55 : 55..55, + S54 : 54..54, + S53 : 53..53, + S52 : 52..52, + S51 : 51..51, + S50 : 50..50, + S49 : 49..49, + S48 : 48..48, + S47 : 47..47, + S46 : 46..46, + S45 : 45..45, + S44 : 44..44, + S43 : 43..43, + S42 : 42..42, + S41 : 41..41, + S40 : 40..40, + S39 : 39..39, + S38 : 38..38, + S37 : 37..37, + S36 : 36..36, + S35 : 35..35, + S34 : 34..34, + S33 : 33..33, + S32 : 32..32, + S31 : 31..31, + S30 : 30..30, + S29 : 29..29, + S28 : 28..28, + S27 : 27..27, + S26 : 26..26, + S25 : 25..25, + S24 : 24..24, + S23 : 23..23, + S22 : 22..22, + S21 : 21..21, + S20 : 20..20, + S19 : 19..19, + S18 : 18..18, + S17 : 17..17, + S16 : 16..16, + S15 : 15..15, + S14 : 14..14, + S13 : 13..13, + S12 : 12..12, + S11 : 11..11, + S10 : 10..10, + S9 : 9..9, + S8 : 8..8, + S7 : 7..7, + S6 : 6..6, + S5 : 5..5, + S4 : 4..4, + S3 : 3..3, + S2 : 2..2, + S1 : 1..1, + S0 : 0..0 + } + +register ERXGSR_EL1 : ERXGSR_EL1_Type + +type ERXMISC3_EL1_Type = bits(64) + +register ERXMISC3_EL1 : ERXMISC3_EL1_Type + +type ERXMISC2_EL1_Type = bits(64) + +register ERXMISC2_EL1 : ERXMISC2_EL1_Type + +type ERXPFGCTL_EL1_Type = bits(64) + +register ERXPFGCTL_EL1 : ERXPFGCTL_EL1_Type + +bitfield BRBINF_EL1_Type : bits(64) = + { + CCU : 46..46, + CC : 45..32, + LASTFAILED : 17..17, + T : 16..16, + TYPE : 13..8, + EL : 7..6, + MPRED : 5..5, + VALID : 1..0 + } + +register BRBINF_EL1 : vector(32, BRBINF_EL1_Type) + +bitfield BRBTGT_EL1_Type : bits(64) = {ADDRESS : 63..0} + +register BRBTGT_EL1 : vector(32, BRBTGT_EL1_Type) + +bitfield BRBSRC_EL1_Type : bits(64) = {ADDRESS : 63..0} + +register BRBSRC_EL1 : vector(32, BRBSRC_EL1_Type) + +val __set_BRBSRCINJ_EL1 : BRBSRCINJ_EL1_Type -> unit + +function __set_BRBSRCINJ_EL1 value_name = { + let r : BRBSRCINJ_EL1_Type = value_name; + if not_bool(BRBINFINJ_EL1[VALID] == 0b00 | BRBINFINJ_EL1[VALID] == 0b01) then { + BRBSRCINJ_EL1[ADDRESS] = r[ADDRESS] + }; + return() +} + +val __set_BRBINFINJ_EL1 : BRBINFINJ_EL1_Type -> unit + +function __set_BRBINFINJ_EL1 value_name = { + let r : BRBINFINJ_EL1_Type = value_name; + BRBINFINJ_EL1.bits[4 .. 0] = Slice(r.bits, 0, 5); + BRBINFINJ_EL1.bits[15 .. 14] = Slice(r.bits, 14, 2); + BRBINFINJ_EL1.bits[31 .. 18] = Slice(r.bits, 18, 14); + BRBINFINJ_EL1.bits[63 .. 47] = Slice(r.bits, 47, 17); + if not_bool(BRBINFINJ_EL1[VALID] == 0b00) then { + BRBINFINJ_EL1[CCU] = r[CCU] + }; + if not_bool(BRBINFINJ_EL1[CCU] == 0b1 | BRBINFINJ_EL1[VALID] == 0b00) then { + BRBINFINJ_EL1[CC] = r[CC] + }; + if not_bool(BRBINFINJ_EL1[VALID] == 0b00) then { + BRBINFINJ_EL1[LASTFAILED] = r[LASTFAILED] + }; + if not_bool(BRBINFINJ_EL1[VALID] == 0b00 | BRBINFINJ_EL1[VALID] == 0b01) then { + BRBINFINJ_EL1[T] = r[T] + }; + if not_bool(BRBINFINJ_EL1[VALID] == 0b00) then { + BRBINFINJ_EL1[TYPE] = r[TYPE] + }; + if not_bool(BRBINFINJ_EL1[VALID] == 0b00 | BRBINFINJ_EL1[VALID] == 0b10) then { + BRBINFINJ_EL1[EL] = r[EL] + }; + if not_bool((BRBINFINJ_EL1[VALID] == 0b00 | BRBINFINJ_EL1[VALID] == 0b01) | [BRBINFINJ_EL1[TYPE][5]] == 0b1) then { + BRBINFINJ_EL1[MPRED] = r[MPRED] + }; + return() +} + +val __set_BRBTGTINJ_EL1 : BRBTGTINJ_EL1_Type -> unit + +function __set_BRBTGTINJ_EL1 value_name = { + let r : BRBTGTINJ_EL1_Type = value_name; + if not_bool(BRBINFINJ_EL1[VALID] == 0b00 | BRBINFINJ_EL1[VALID] == 0b10) then { + BRBTGTINJ_EL1[ADDRESS] = r[ADDRESS] + }; + return() +} + +bitfield GITS_CREADR_Type : bits(64) = {Offset : 19..5, Stalled : 0..0} + +register GITS_CREADR : GITS_CREADR_Type + +bitfield GICR_PENDBASER_Type : bits(64) = + { + PTZ : 62..62, + OuterCache : 58..56, + Physical_Address : 51..16, + Shareability : 11..10, + InnerCache : 9..7 + } + +register GICR_PENDBASER : GICR_PENDBASER_Type + +bitfield GICR_PROPBASER_Type : bits(64) = + { + OuterCache : 58..56, + Physical_Address : 51..12, + Shareability : 11..10, + InnerCache : 9..7, + IDbits : 4..0 + } + +register GICR_PROPBASER : GICR_PROPBASER_Type + +bitfield GICR_VPROPBASER_Type : bits(64) = + { + Valid : 63..63, + Entry_Size : 61..59, + OuterCache : 58..56, + Indirect : 55..55, + Page_Size : 54..53, + Z : 52..52, + Physical_Address : 51..12, + Shareability : 11..10, + InnerCache : 9..7, + IDbits : 4..0, + Size : 6..0 + } + +register GICR_VPROPBASER : GICR_VPROPBASER_Type + +bitfield EDPFR_Type : bits(64) = + { + AMU : 47..44, + SEL2 : 39..36, + SVE : 35..32, + GIC : 27..24, + AdvSIMD : 23..20, + FP : 19..16, + EL3 : 15..12, + EL2 : 11..8, + EL1 : 7..4, + EL0 : 3..0 + } + +register EDPFR : EDPFR_Type + +bitfield GICR_CLRLPIR_Type : bits(64) = {pINTID : 31..0} + +register GICR_CLRLPIR : GICR_CLRLPIR_Type + +bitfield GICR_INVALLR_Type : bits(64) = {V : 63..63, vPEID : 47..32} + +register GICR_INVALLR : GICR_INVALLR_Type + +bitfield EDHSR_Type : bits(64) = + { + GCS : 40..40, + WPT : 23..18, + WPTV : 17..17, + WPF : 16..16, + FnP : 15..15, + VNCR : 13..13, + FnV : 10..10, + CM : 8..8, + WnR : 6..6 + } + +register EDHSR : EDHSR_Type + +bitfield EDPCSR_Type : bits(64) = {NS : 63..63, EL : 62..61} + +register EDPCSR : EDPCSR_Type + +bitfield GICR_VPENDBASER_Type : bits(64) = + { + Valid : 63..63, + IDAI : 62..62, + Doorbell : 62..62, + PendingLast : 61..61, + Dirty : 60..60, + VGrp0En : 59..59, + VGrp1En : 58..58, + OuterCache : 58..56, + Physical_Address : 51..16, + Shareability : 11..10, + InnerCache : 9..7, + vPEID : 15..0 + } + +register GICR_VPENDBASER : GICR_VPENDBASER_Type + +bitfield GITS_TYPER_Type : bits(64) = + { + INV : 46..46, + UMSIirq : 45..45, + UMSI : 44..44, + nID : 43..43, + SVPET : 42..41, + VMAPP : 40..40, + VSGI : 39..39, + MPAM : 38..38, + VMOVP : 37..37, + CIL : 36..36, + CIDbits : 35..32, + HCC : 31..24, + PTA : 19..19, + SEIS : 18..18, + Devbits : 17..13, + ID_bits : 12..8, + ITT_entry_size : 7..4, + CCT : 2..2, + Virtual : 1..1, + Physical : 0..0 + } + +register GITS_TYPER : GITS_TYPER_Type + +bitfield GITS_SGIR_Type : bits(64) = {vPEID : 47..32, vINTID : 3..0} + +register GITS_SGIR : GITS_SGIR_Type + +bitfield EDDFR1_Type : bits(64) = + { + ABL_CMPs : 63..56, + EBEP : 51..48, + ITE : 47..44, + ABLE : 43..40, + PMICNTR : 39..36, + SPMU : 35..32, + CTX_CMPs : 31..24, + WRPs : 23..16, + BRPs : 15..8, + SYSPMUID : 7..0 + } + +register EDDFR1 : EDDFR1_Type + +bitfield GITS_CWRITER_Type : bits(64) = {Offset : 19..5, Retry : 0..0} + +register GITS_CWRITER : GITS_CWRITER_Type + +bitfield EDDFR_Type : bits(64) = + { + ExtTrcBuff : 59..56, + TraceFilt : 43..40, + CTX_CMPs : 31..28, + SEBEP : 27..24, + WRPs : 23..20, + PMSS : 19..16, + BRPs : 15..12, + PMUVer : 11..8, + TraceVer : 7..4 + } + +register EDDFR : EDDFR_Type + +bitfield GICR_INVLPIR_Type : bits(64) = + {V : 63..63, vPEID : 47..32, INTID : 31..0} + +register GICR_INVLPIR : GICR_INVLPIR_Type + +bitfield EDAA32PFR_Type : bits(64) = + {MSA_frac : 19..16, EL3 : 15..12, EL2 : 11..8, PMSA : 7..4, VMSA : 3..0} + +register EDAA32PFR : EDAA32PFR_Type + +bitfield GITS_CBASER_Type : bits(64) = + { + Valid : 63..63, + InnerCache : 61..59, + OuterCache : 55..53, + Physical_Address : 51..12, + Shareability : 11..10, + Size : 7..0 + } + +register GITS_CBASER : GITS_CBASER_Type + +bitfield GICR_SETLPIR_Type : bits(64) = {pINTID : 31..0} + +register GICR_SETLPIR : GICR_SETLPIR_Type + +bitfield PMCFGR_Type : bits(64) = + { + NCG : 31..28, + SS : 22..22, + FZO : 21..21, + UEN : 19..19, + WT : 18..18, + NA : 17..17, + EX : 16..16, + CCD : 15..15, + CC : 14..14, + SIZE : 13..8, + N : 7..0 + } + +register PMCFGR : PMCFGR_Type + +bitfield PMCNTEN_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMCNTEN : PMCNTEN_Type + +val PMCNTEN_read : unit -> PMCNTEN_Type + +function PMCNTEN_read () = { + r : PMCNTEN_Type = _PMCNTEN; + r.bits[63 .. 0] = Slice(PMCNTENSET_EL0.bits, 0, 64); + return(r) +} + +val PMCNTEN_write : PMCNTEN_Type -> unit + +function PMCNTEN_write value_name = { + let r : PMCNTEN_Type = value_name; + PMCNTENSET_EL0.bits[63 .. 0] = Slice(r.bits, 0, 64); + _PMCNTEN = r; + return() +} + +bitfield PMIIDR_Type : bits(64) = + {ProductID : 31..20, Variant : 19..16, Revision : 15..12} + +register PMIIDR : PMIIDR_Type + +bitfield PMINTEN_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMINTEN : PMINTEN_Type + +val PMINTEN_read : unit -> PMINTEN_Type + +function PMINTEN_read () = { + r : PMINTEN_Type = _PMINTEN; + r.bits[63 .. 0] = Slice(PMINTENSET_EL1.bits, 0, 64); + return(r) +} + +val PMINTEN_write : PMINTEN_Type -> unit + +function PMINTEN_write value_name = { + let r : PMINTEN_Type = value_name; + PMINTENSET_EL1.bits[63 .. 0] = Slice(r.bits, 0, 64); + _PMINTEN = r; + return() +} + +bitfield PMOVS_Type : bits(64) = + { + F0 : 32..32, + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMOVS : PMOVS_Type + +val PMOVS_read : unit -> PMOVS_Type + +function PMOVS_read () = { + r : PMOVS_Type = _PMOVS; + r.bits[63 .. 0] = Slice(PMOVSSET_EL0.bits, 0, 64); + return(r) +} + +val PMOVS_write : PMOVS_Type -> unit + +function PMOVS_write value_name = { + let r : PMOVS_Type = value_name; + PMOVSSET_EL0.bits[63 .. 0] = Slice(r.bits, 0, 64); + _PMOVS = r; + return() +} + +bitfield PMPCSCTL_Type : bits(64) = {SS : 4..4, IMP : 1..1, EN : 0..0} + +register PMPCSCTL : PMPCSCTL_Type + +bitfield PMVCIDSR_Type : bits(64) = + {VMID : (47..40 @ 39..32), CONTEXTIDR_EL1 : 31..0} + +register PMVCIDSR : PMVCIDSR_Type + +val TTBCR_NS_write : TTBCR_Type -> unit + +function TTBCR_NS_write value_name = { + let r : TTBCR_Type = value_name; + TCR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _TTBCR_NS = r; + return() +} + +val TTBCR_write : TTBCR_Type -> unit + +function TTBCR_write value_name = { + let r : TTBCR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + TTBCR_S = r + } else { + TTBCR_NS_write() = r + }; + return() +} + +val DBGOSDLR_write : DBGOSDLR_Type -> unit + +function DBGOSDLR_write value_name = { + let r : DBGOSDLR_Type = value_name; + OSDLR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGOSDLR = r; + return() +} + +bitfield ICH_ELRSR_Type : bits(32) = + { + Status15 : 15..15, + Status14 : 14..14, + Status13 : 13..13, + Status12 : 12..12, + Status11 : 11..11, + Status10 : 10..10, + Status9 : 9..9, + Status8 : 8..8, + Status7 : 7..7, + Status6 : 6..6, + Status5 : 5..5, + Status4 : 4..4, + Status3 : 3..3, + Status2 : 2..2, + Status1 : 1..1, + Status0 : 0..0 + } + +register _ICH_ELRSR : ICH_ELRSR_Type + +val ICH_ELRSR_read : unit -> ICH_ELRSR_Type + +function ICH_ELRSR_read () = { + r : ICH_ELRSR_Type = _ICH_ELRSR; + r.bits[31 .. 0] = Slice(ICH_ELRSR_EL2.bits, 0, 32); + return(r) +} + +val ICH_ELRSR_write : ICH_ELRSR_Type -> unit + +function ICH_ELRSR_write value_name = { + let r : ICH_ELRSR_Type = value_name; + ICH_ELRSR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_ELRSR = r; + return() +} + +bitfield ICC_IAR1_Type : bits(32) = {INTID : 23..0} + +register _ICC_IAR1 : ICC_IAR1_Type + +val ICC_IAR1_read : unit -> ICC_IAR1_Type + +function ICC_IAR1_read () = { + r : ICC_IAR1_Type = _ICC_IAR1; + r.bits[31 .. 0] = Slice(ICC_IAR1_EL1.bits, 0, 32); + return(r) +} + +val ICC_IAR1_write : ICC_IAR1_Type -> unit + +function ICC_IAR1_write value_name = { + let r : ICC_IAR1_Type = value_name; + ICC_IAR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_IAR1 = r; + return() +} + +type AIFSR_Type = bits(32) + +register AIFSR_S : AIFSR_Type + +register _AIFSR_NS : AIFSR_Type + +val AIFSR_NS_read : unit -> AIFSR_Type + +function AIFSR_NS_read () = { + r : AIFSR_Type = _AIFSR_NS; + r[31 .. 0] = Slice(AFSR1_EL1, 0, 32); + return(r) +} + +val AIFSR_NS_write : AIFSR_Type -> unit + +function AIFSR_NS_write value_name = { + let r : AIFSR_Type = value_name; + AFSR1_EL1[31 .. 0] = Slice(r, 0, 32); + _AIFSR_NS = r; + return() +} + +val AIFSR_read : unit -> AIFSR_Type + +function AIFSR_read () = { + r : AIFSR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = AIFSR_S + } else { + r = AIFSR_NS_read() + }; + return(r) +} + +val AIFSR_write : AIFSR_Type -> unit + +function AIFSR_write value_name = { + let r : AIFSR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + AIFSR_S = r + } else { + AIFSR_NS_write() = r + }; + return() +} + +bitfield ID_DFR0_Type : bits(32) = + { + TraceFilt : 31..28, + PerfMon : 27..24, + MProfDbg : 23..20, + MMapTrc : 19..16, + CopTrc : 15..12, + MMapDbg : 11..8, + CopSDbg : 7..4, + CopDbg : 3..0 + } + +register _ID_DFR0 : ID_DFR0_Type + +val ID_DFR0_read : unit -> ID_DFR0_Type + +function ID_DFR0_read () = { + r : ID_DFR0_Type = _ID_DFR0; + r.bits[31 .. 0] = Slice(ID_DFR0_EL1.bits, 0, 32); + return(r) +} + +val ID_DFR0_write : ID_DFR0_Type -> unit + +function ID_DFR0_write value_name = { + let r : ID_DFR0_Type = value_name; + ID_DFR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_DFR0 = r; + return() +} + +bitfield CLIDR_Type : bits(32) = + { + ICB : 31..30, + LoUU : 29..27, + LoC : 26..24, + LoUIS : 23..21, + Ctype7 : 20..18, + Ctype6 : 17..15, + Ctype5 : 14..12, + Ctype4 : 11..9, + Ctype3 : 8..6, + Ctype2 : 5..3, + Ctype1 : 2..0 + } + +register _CLIDR : CLIDR_Type + +val CLIDR_read : unit -> CLIDR_Type + +function CLIDR_read () = { + r : CLIDR_Type = _CLIDR; + r.bits[31 .. 0] = Slice(CLIDR_EL1.bits, 0, 32); + return(r) +} + +val CLIDR_write : CLIDR_Type -> unit + +function CLIDR_write value_name = { + let r : CLIDR_Type = value_name; + CLIDR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CLIDR = r; + return() +} + +type HACR_Type = bits(32) + +register _HACR : HACR_Type + +val HACR_read : unit -> HACR_Type + +function HACR_read () = { + r : HACR_Type = _HACR; + r[31 .. 0] = Slice(HACR_EL2, 0, 32); + return(r) +} + +val HACR_write : HACR_Type -> unit + +function HACR_write value_name = { + let r : HACR_Type = value_name; + HACR_EL2[31 .. 0] = Slice(r, 0, 32); + _HACR = r; + return() +} + +type JOSCR_Type = bits(32) + +register JOSCR : JOSCR_Type + +val HCPTR_write : HCPTR_Type -> unit + +function HCPTR_write value_name = { + let r : HCPTR_Type = value_name; + CPTR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HCPTR = r; + return() +} + +val __set_HCPTR : HCPTR_Type -> unit + +function __set_HCPTR value_name = { + let r : HCPTR_Type = value_name; + HCPTR_write() = Mk_HCPTR_Type(SetSlice(10, HCPTR_read().bits, 0, Slice(r.bits, 0, 10))); + HCPTR_write() = Mk_HCPTR_Type(SetSlice(20, HCPTR_read().bits, 12, Slice(r.bits, 12, 20))); + if not_bool(((HaveEL(EL3) & ELUsingAArch32(EL3)) & not_bool(IsCurrentSecurityState(SS_Secure))) & NSACR[cp10] == 0b0) then { + HCPTR_write() = [HCPTR_read() with TCP11 = r[TCP11]] + }; + if not_bool(((HaveEL(EL3) & ELUsingAArch32(EL3)) & not_bool(IsCurrentSecurityState(SS_Secure))) & NSACR[cp10] == 0b0) then { + HCPTR_write() = [HCPTR_read() with TCP10 = r[TCP10]] + }; + return() +} + +bitfield ICV_IGRPEN1_Type : bits(32) = {Enable : 0..0} + +register _ICV_IGRPEN1 : ICV_IGRPEN1_Type + +val ICV_IGRPEN1_read : unit -> ICV_IGRPEN1_Type + +function ICV_IGRPEN1_read () = { + r : ICV_IGRPEN1_Type = _ICV_IGRPEN1; + r.bits[31 .. 0] = Slice(ICV_IGRPEN1_EL1.bits, 0, 32); + return(r) +} + +val ICV_IGRPEN1_write : ICV_IGRPEN1_Type -> unit + +function ICV_IGRPEN1_write value_name = { + let r : ICV_IGRPEN1_Type = value_name; + ICV_IGRPEN1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_IGRPEN1 = r; + return() +} + +bitfield CTR_Type : bits(32) = + { + DIC : 29..29, + IDC : 28..28, + CWG : 27..24, + ERG : 23..20, + DminLine : 19..16, + L1Ip : 15..14, + IminLine : 3..0 + } + +register _CTR : CTR_Type + +val CTR_read : unit -> CTR_Type + +function CTR_read () = { + r : CTR_Type = _CTR; + r.bits[31 .. 0] = Slice(CTR_EL0.bits, 0, 32); + return(r) +} + +val CTR_write : CTR_Type -> unit + +function CTR_write value_name = { + let r : CTR_Type = value_name; + CTR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CTR = r; + return() +} + +bitfield PMUSERENR_Type : bits(32) = + {TID : 6..6, ER : 3..3, CR : 2..2, SW : 1..1, EN : 0..0} + +register _PMUSERENR : PMUSERENR_Type + +val PMUSERENR_read : unit -> PMUSERENR_Type + +function PMUSERENR_read () = { + r : PMUSERENR_Type = _PMUSERENR; + r.bits[31 .. 0] = Slice(PMUSERENR_EL0.bits, 0, 32); + return(r) +} + +val PMUSERENR_write : PMUSERENR_Type -> unit + +function PMUSERENR_write value_name = { + let r : PMUSERENR_Type = value_name; + PMUSERENR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMUSERENR = r; + return() +} + +bitfield CNTHPS_CTL_Type : bits(32) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register _CNTHPS_CTL : CNTHPS_CTL_Type + +val CNTHPS_CTL_read : unit -> CNTHPS_CTL_Type + +function CNTHPS_CTL_read () = { + r : CNTHPS_CTL_Type = _CNTHPS_CTL; + r.bits[31 .. 0] = Slice(CNTHPS_CTL_EL2.bits, 0, 32); + return(r) +} + +val CNTHPS_CTL_write : CNTHPS_CTL_Type -> unit + +function CNTHPS_CTL_write value_name = { + let r : CNTHPS_CTL_Type = value_name; + CNTHPS_CTL_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTHPS_CTL = r; + return() +} + +val DBGBVR_set : forall 'n, (0 <= 'n & 'n < 16). (int('n), DBGBVR_Type) -> unit + +function DBGBVR_set (n, value_name) = { + let r : DBGBVR_Type = value_name; + DBGBVR_EL1[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGBVR[n] = r; + return() +} + +bitfield PMCEID1_Type : bits(32) = + { + ID31 : 31..31, + ID30 : 30..30, + ID29 : 29..29, + ID28 : 28..28, + ID27 : 27..27, + ID26 : 26..26, + ID25 : 25..25, + ID24 : 24..24, + ID23 : 23..23, + ID22 : 22..22, + ID21 : 21..21, + ID20 : 20..20, + ID19 : 19..19, + ID18 : 18..18, + ID17 : 17..17, + ID16 : 16..16, + ID15 : 15..15, + ID14 : 14..14, + ID13 : 13..13, + ID12 : 12..12, + ID11 : 11..11, + ID10 : 10..10, + ID9 : 9..9, + ID8 : 8..8, + ID7 : 7..7, + ID6 : 6..6, + ID5 : 5..5, + ID4 : 4..4, + ID3 : 3..3, + ID2 : 2..2, + ID1 : 1..1, + ID0 : 0..0 + } + +register _PMCEID1 : PMCEID1_Type + +val PMCEID1_read : unit -> PMCEID1_Type + +function PMCEID1_read () = { + r : PMCEID1_Type = _PMCEID1; + r.bits[31 .. 0] = Slice(PMCEID1_EL0.bits, 0, 32); + return(r) +} + +val PMCEID1_write : PMCEID1_Type -> unit + +function PMCEID1_write value_name = { + let r : PMCEID1_Type = value_name; + PMCEID1_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMCEID1 = r; + return() +} + +bitfield DBGAUTHSTATUS_Type : bits(32) = + {SNID : 7..6, SID : 5..4, NSNID : 3..2, NSID : 1..0} + +register _DBGAUTHSTATUS : DBGAUTHSTATUS_Type + +val DBGAUTHSTATUS_read : unit -> DBGAUTHSTATUS_Type + +function DBGAUTHSTATUS_read () = { + r : DBGAUTHSTATUS_Type = _DBGAUTHSTATUS; + r.bits[31 .. 0] = Slice(DBGAUTHSTATUS_EL1.bits, 0, 32); + return(r) +} + +val DBGAUTHSTATUS_write : DBGAUTHSTATUS_Type -> unit + +function DBGAUTHSTATUS_write value_name = { + let r : DBGAUTHSTATUS_Type = value_name; + DBGAUTHSTATUS_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGAUTHSTATUS = r; + return() +} + +bitfield ICC_IAR0_Type : bits(32) = {INTID : 23..0} + +register _ICC_IAR0 : ICC_IAR0_Type + +val ICC_IAR0_read : unit -> ICC_IAR0_Type + +function ICC_IAR0_read () = { + r : ICC_IAR0_Type = _ICC_IAR0; + r.bits[31 .. 0] = Slice(ICC_IAR0_EL1.bits, 0, 32); + return(r) +} + +val ICC_IAR0_write : ICC_IAR0_Type -> unit + +function ICC_IAR0_write value_name = { + let r : ICC_IAR0_Type = value_name; + ICC_IAR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_IAR0 = r; + return() +} + +val PMCNTENSET_write : PMCNTENSET_Type -> unit + +function PMCNTENSET_write value_name = { + let r : PMCNTENSET_Type = value_name; + PMCNTENSET_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMCNTENSET = r; + return() +} + +bitfield ICV_IGRPEN0_Type : bits(32) = {Enable : 0..0} + +register _ICV_IGRPEN0 : ICV_IGRPEN0_Type + +val ICV_IGRPEN0_read : unit -> ICV_IGRPEN0_Type + +function ICV_IGRPEN0_read () = { + r : ICV_IGRPEN0_Type = _ICV_IGRPEN0; + r.bits[31 .. 0] = Slice(ICV_IGRPEN0_EL1.bits, 0, 32); + return(r) +} + +val ICV_IGRPEN0_write : ICV_IGRPEN0_Type -> unit + +function ICV_IGRPEN0_write value_name = { + let r : ICV_IGRPEN0_Type = value_name; + ICV_IGRPEN0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_IGRPEN0 = r; + return() +} + +bitfield ID_MMFR3_Type : bits(32) = + { + Supersec : 31..28, + CMemSz : 27..24, + CohWalk : 23..20, + PAN : 19..16, + MaintBcst : 15..12, + BPMaint : 11..8, + CMaintSW : 7..4, + CMaintVA : 3..0 + } + +register _ID_MMFR3 : ID_MMFR3_Type + +val ID_MMFR3_read : unit -> ID_MMFR3_Type + +function ID_MMFR3_read () = { + r : ID_MMFR3_Type = _ID_MMFR3; + r.bits[31 .. 0] = Slice(ID_MMFR3_EL1.bits, 0, 32); + return(r) +} + +val ID_MMFR3_write : ID_MMFR3_Type -> unit + +function ID_MMFR3_write value_name = { + let r : ID_MMFR3_Type = value_name; + ID_MMFR3_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_MMFR3 = r; + return() +} + +val PRRR_NS_write : PRRR_Type -> unit + +function PRRR_NS_write value_name = { + let r : PRRR_Type = value_name; + MAIR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PRRR_NS = r; + return() +} + +val PRRR_write : PRRR_Type -> unit + +function PRRR_write value_name = { + let r : PRRR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + PRRR_S = r + } else { + PRRR_NS_write() = r + }; + return() +} + +bitfield PMCEID0_Type : bits(32) = + { + ID31 : 31..31, + ID30 : 30..30, + ID29 : 29..29, + ID28 : 28..28, + ID27 : 27..27, + ID26 : 26..26, + ID25 : 25..25, + ID24 : 24..24, + ID23 : 23..23, + ID22 : 22..22, + ID21 : 21..21, + ID20 : 20..20, + ID19 : 19..19, + ID18 : 18..18, + ID17 : 17..17, + ID16 : 16..16, + ID15 : 15..15, + ID14 : 14..14, + ID13 : 13..13, + ID12 : 12..12, + ID11 : 11..11, + ID10 : 10..10, + ID9 : 9..9, + ID8 : 8..8, + ID7 : 7..7, + ID6 : 6..6, + ID5 : 5..5, + ID4 : 4..4, + ID3 : 3..3, + ID2 : 2..2, + ID1 : 1..1, + ID0 : 0..0 + } + +register _PMCEID0 : PMCEID0_Type + +val PMCEID0_read : unit -> PMCEID0_Type + +function PMCEID0_read () = { + r : PMCEID0_Type = _PMCEID0; + r.bits[31 .. 0] = Slice(PMCEID0_EL0.bits, 0, 32); + return(r) +} + +val PMCEID0_write : PMCEID0_Type -> unit + +function PMCEID0_write value_name = { + let r : PMCEID0_Type = value_name; + PMCEID0_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMCEID0 = r; + return() +} + +bitfield ICV_CTLR_Type : bits(32) = + { + ExtRange : 19..19, + RSS : 18..18, + A3V : 15..15, + SEIS : 14..14, + IDbits : 13..11, + PRIbits : 10..8, + EOImode : 1..1, + CBPR : 0..0 + } + +register _ICV_CTLR : ICV_CTLR_Type + +val ICV_CTLR_read : unit -> ICV_CTLR_Type + +function ICV_CTLR_read () = { + r : ICV_CTLR_Type = _ICV_CTLR; + r.bits[31 .. 0] = Slice(ICV_CTLR_EL1.bits, 0, 32); + return(r) +} + +val ICV_CTLR_write : ICV_CTLR_Type -> unit + +function ICV_CTLR_write value_name = { + let r : ICV_CTLR_Type = value_name; + ICV_CTLR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_CTLR = r; + return() +} + +val DBGBXVR_set : forall 'n, (0 <= 'n & 'n < 16). + (int('n), DBGBXVR_Type) -> unit + +function DBGBXVR_set (n, value_name) = { + let r : DBGBXVR_Type = value_name; + DBGBVR_EL1[n].bits[63 .. 32] = Slice(r.bits, 0, 32); + _DBGBXVR[n] = r; + return() +} + +bitfield ID_ISAR6_Type : bits(32) = + { + CLRBHB : 31..28, + I8MM : 27..24, + BF16 : 23..20, + SPECRES : 19..16, + SB : 15..12, + FHM : 11..8, + DP : 7..4, + JSCVT : 3..0 + } + +register _ID_ISAR6 : ID_ISAR6_Type + +val ID_ISAR6_read : unit -> ID_ISAR6_Type + +function ID_ISAR6_read () = { + r : ID_ISAR6_Type = _ID_ISAR6; + r.bits[31 .. 0] = Slice(ID_ISAR6_EL1.bits, 0, 32); + return(r) +} + +val ID_ISAR6_write : ID_ISAR6_Type -> unit + +function ID_ISAR6_write value_name = { + let r : ID_ISAR6_Type = value_name; + ID_ISAR6_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_ISAR6 = r; + return() +} + +type HACTLR_Type = bits(32) + +register _HACTLR : HACTLR_Type + +val HACTLR_read : unit -> HACTLR_Type + +function HACTLR_read () = { + r : HACTLR_Type = _HACTLR; + r[31 .. 0] = Slice(ACTLR_EL2, 0, 32); + return(r) +} + +val HACTLR_write : HACTLR_Type -> unit + +function HACTLR_write value_name = { + let r : HACTLR_Type = value_name; + ACTLR_EL2[31 .. 0] = Slice(r, 0, 32); + _HACTLR = r; + return() +} + +bitfield DBGCLAIMCLR_Type : bits(32) = {CLAIM : 7..0} + +register _DBGCLAIMCLR : DBGCLAIMCLR_Type + +val DBGCLAIMCLR_read : unit -> DBGCLAIMCLR_Type + +function DBGCLAIMCLR_read () = { + r : DBGCLAIMCLR_Type = _DBGCLAIMCLR; + r.bits[31 .. 0] = Slice(DBGCLAIMCLR_EL1.bits, 0, 32); + return(r) +} + +val DBGCLAIMCLR_write : DBGCLAIMCLR_Type -> unit + +function DBGCLAIMCLR_write value_name = { + let r : DBGCLAIMCLR_Type = value_name; + DBGCLAIMCLR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGCLAIMCLR = r; + return() +} + +type TCMTR_Type = bits(32) + +register TCMTR : TCMTR_Type + +val DBGWVR_set : forall 'n, (0 <= 'n & 'n < 16). (int('n), DBGWVR_Type) -> unit + +function DBGWVR_set (n, value_name) = { + let r : DBGWVR_Type = value_name; + DBGWVR_EL1[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGWVR[n] = r; + return() +} + +bitfield ICV_HPPIR1_Type : bits(32) = {INTID : 23..0} + +register _ICV_HPPIR1 : ICV_HPPIR1_Type + +val ICV_HPPIR1_read : unit -> ICV_HPPIR1_Type + +function ICV_HPPIR1_read () = { + r : ICV_HPPIR1_Type = _ICV_HPPIR1; + r.bits[31 .. 0] = Slice(ICV_HPPIR1_EL1.bits, 0, 32); + return(r) +} + +val ICV_HPPIR1_write : ICV_HPPIR1_Type -> unit + +function ICV_HPPIR1_write value_name = { + let r : ICV_HPPIR1_Type = value_name; + ICV_HPPIR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_HPPIR1 = r; + return() +} + +bitfield ID_MMFR5_Type : bits(32) = {nTLBPA : 7..4, ETS : 3..0} + +register _ID_MMFR5 : ID_MMFR5_Type + +val ID_MMFR5_read : unit -> ID_MMFR5_Type + +function ID_MMFR5_read () = { + r : ID_MMFR5_Type = _ID_MMFR5; + r.bits[31 .. 0] = Slice(ID_MMFR5_EL1.bits, 0, 32); + return(r) +} + +val ID_MMFR5_write : ID_MMFR5_Type -> unit + +function ID_MMFR5_write value_name = { + let r : ID_MMFR5_Type = value_name; + ID_MMFR5_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_MMFR5 = r; + return() +} + +type ICV_AP0R_Type = bits(32) + +register _ICV_AP0R : vector(4, ICV_AP0R_Type) + +val ICV_AP0R_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> ICV_AP0R_Type + +function ICV_AP0R_read n = { + r : ICV_AP0R_Type = _ICV_AP0R[n]; + r[31 .. 0] = Slice(ICV_AP0R_EL1[n], 0, 32); + return(r) +} + +val ICV_AP0R_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), ICV_AP0R_Type) -> unit + +function ICV_AP0R_set (n, value_name) = { + let r : ICV_AP0R_Type = value_name; + ICV_AP0R_EL1[n][31 .. 0] = Slice(r, 0, 32); + _ICV_AP0R[n] = r; + return() +} + +bitfield HRMR_Type : bits(32) = {RR : 1..1, AA64 : 0..0} + +register _HRMR : HRMR_Type + +val HRMR_read : unit -> HRMR_Type + +function HRMR_read () = { + r : HRMR_Type = _HRMR; + r.bits[31 .. 0] = Slice(RMR_EL2.bits, 0, 32); + return(r) +} + +val HRMR_write : HRMR_Type -> unit + +function HRMR_write value_name = { + let r : HRMR_Type = value_name; + RMR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HRMR = r; + return() +} + +val HCR2_write : HCR2_Type -> unit + +function HCR2_write value_name = { + let r : HCR2_Type = value_name; + HCR_EL2.bits[63 .. 32] = Slice(r.bits, 0, 32); + _HCR2 = r; + return() +} + +bitfield ID_PFR2_Type : bits(32) = {RAS_frac : 11..8, SSBS : 7..4, CSV3 : 3..0} + +register _ID_PFR2 : ID_PFR2_Type + +val ID_PFR2_read : unit -> ID_PFR2_Type + +function ID_PFR2_read () = { + r : ID_PFR2_Type = _ID_PFR2; + r.bits[31 .. 0] = Slice(ID_PFR2_EL1.bits, 0, 32); + return(r) +} + +val ID_PFR2_write : ID_PFR2_Type -> unit + +function ID_PFR2_write value_name = { + let r : ID_PFR2_Type = value_name; + ID_PFR2_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_PFR2 = r; + return() +} + +val HMAIR0_write : HMAIR0_Type -> unit + +function HMAIR0_write value_name = { + let r : HMAIR0_Type = value_name; + MAIR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HMAIR0 = r; + return() +} + +bitfield ICV_EOIR0_Type : bits(32) = {INTID : 23..0} + +register _ICV_EOIR0 : ICV_EOIR0_Type + +val ICV_EOIR0_read : unit -> ICV_EOIR0_Type + +function ICV_EOIR0_read () = { + r : ICV_EOIR0_Type = _ICV_EOIR0; + r.bits[31 .. 0] = Slice(ICV_EOIR0_EL1.bits, 0, 32); + return(r) +} + +val ICV_EOIR0_write : ICV_EOIR0_Type -> unit + +function ICV_EOIR0_write value_name = { + let r : ICV_EOIR0_Type = value_name; + ICV_EOIR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_EOIR0 = r; + return() +} + +val DACR_NS_write : DACR_Type -> unit + +function DACR_NS_write value_name = { + let r : DACR_Type = value_name; + DACR32_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DACR_NS = r; + return() +} + +val DACR_write : DACR_Type -> unit + +function DACR_write value_name = { + let r : DACR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + DACR_S = r + } else { + DACR_NS_write() = r + }; + return() +} + +bitfield ICH_VTR_Type : bits(32) = + { + PRIbits : 31..29, + PREbits : 28..26, + IDbits : 25..23, + SEIS : 22..22, + A3V : 21..21, + nV4 : 20..20, + TDS : 19..19, + ListRegs : 4..0 + } + +register _ICH_VTR : ICH_VTR_Type + +val ICH_VTR_read : unit -> ICH_VTR_Type + +function ICH_VTR_read () = { + r : ICH_VTR_Type = _ICH_VTR; + r.bits[31 .. 0] = Slice(ICH_VTR_EL2.bits, 0, 32); + return(r) +} + +val ICH_VTR_write : ICH_VTR_Type -> unit + +function ICH_VTR_write value_name = { + let r : ICH_VTR_Type = value_name; + ICH_VTR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_VTR = r; + return() +} + +bitfield CSSELR_Type : bits(32) = {Level : 3..1, InD : 0..0} + +register CSSELR_S : CSSELR_Type + +register _CSSELR_NS : CSSELR_Type + +val CSSELR_NS_read : unit -> CSSELR_Type + +function CSSELR_NS_read () = { + r : CSSELR_Type = _CSSELR_NS; + r.bits[31 .. 0] = Slice(CSSELR_EL1.bits, 0, 32); + return(r) +} + +val CSSELR_NS_write : CSSELR_Type -> unit + +function CSSELR_NS_write value_name = { + let r : CSSELR_Type = value_name; + CSSELR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CSSELR_NS = r; + return() +} + +val CSSELR_read : unit -> CSSELR_Type + +function CSSELR_read () = { + r : CSSELR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = CSSELR_S + } else { + r = CSSELR_NS_read() + }; + return(r) +} + +val CSSELR_write : CSSELR_Type -> unit + +function CSSELR_write value_name = { + let r : CSSELR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + CSSELR_S = r + } else { + CSSELR_NS_write() = r + }; + return() +} + +type JIDR_Type = bits(32) + +register JIDR : JIDR_Type + +val PMCR_write : PMCR_Type -> unit + +function PMCR_write value_name = { + let r : PMCR_Type = value_name; + PMCR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMCR = r; + return() +} + +val __set_PMCR : PMCR_Type -> unit + +function __set_PMCR value_name = { + let r : PMCR_Type = value_name; + PMCR_write() = Mk_PMCR_Type(SetSlice(1, PMCR_read().bits, 0, Slice(r.bits, 0, 1))); + PMCR_write() = Mk_PMCR_Type(SetSlice(13, PMCR_read().bits, 3, Slice(r.bits, 3, 13))); + if not_bool(not_bool(IsFeatureImplemented(FEAT_PMUv3p7))) then { + PMCR_write() = [PMCR_read() with IMP = r[IMP]] + }; + if not_bool(PMCR_read()[IMP] != 0b00000000) then { + PMCR_write() = [PMCR_read() with IDCODE = r[IDCODE]] + }; + PMCR_write() = [PMCR_read() with C = r[C]]; + PMCR_write() = [PMCR_read() with P = r[P]]; + return() +} + +val DBGWCR_set : forall 'n, (0 <= 'n & 'n < 16). (int('n), DBGWCR_Type) -> unit + +function DBGWCR_set (n, value_name) = { + let r : DBGWCR_Type = value_name; + DBGWCR_EL1[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGWCR[n] = r; + return() +} + +bitfield ICH_VMCR_Type : bits(32) = + { + VPMR : 31..24, + VBPR0 : 23..21, + VBPR1 : 20..18, + VEOIM : 9..9, + VCBPR : 4..4, + VFIQEn : 3..3, + VAckCtl : 2..2, + VENG1 : 1..1, + VENG0 : 0..0 + } + +register _ICH_VMCR : ICH_VMCR_Type + +val ICH_VMCR_read : unit -> ICH_VMCR_Type + +function ICH_VMCR_read () = { + r : ICH_VMCR_Type = _ICH_VMCR; + r.bits[31 .. 0] = Slice(ICH_VMCR_EL2.bits, 0, 32); + return(r) +} + +val ICH_VMCR_write : ICH_VMCR_Type -> unit + +function ICH_VMCR_write value_name = { + let r : ICH_VMCR_Type = value_name; + ICH_VMCR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_VMCR = r; + return() +} + +bitfield DBGDEVID1_Type : bits(32) = {PCSROffset : 3..0} + +register DBGDEVID1 : DBGDEVID1_Type + +bitfield ICC_BPR1_Type : bits(32) = {BinaryPoint : 2..0} + +register _ICC_BPR1_S : ICC_BPR1_Type + +val ICC_BPR1_S_read : unit -> ICC_BPR1_Type + +function ICC_BPR1_S_read () = { + r : ICC_BPR1_Type = _ICC_BPR1_S; + r.bits[31 .. 0] = Slice(ICC_BPR1_EL1_S.bits, 0, 32); + return(r) +} + +val ICC_BPR1_S_write : ICC_BPR1_Type -> unit + +function ICC_BPR1_S_write value_name = { + let r : ICC_BPR1_Type = value_name; + ICC_BPR1_EL1_S.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_BPR1_S = r; + return() +} + +register _ICC_BPR1_NS : ICC_BPR1_Type + +val ICC_BPR1_NS_read : unit -> ICC_BPR1_Type + +function ICC_BPR1_NS_read () = { + r : ICC_BPR1_Type = _ICC_BPR1_NS; + r.bits[31 .. 0] = Slice(ICC_BPR1_EL1_NS.bits, 0, 32); + return(r) +} + +val ICC_BPR1_NS_write : ICC_BPR1_Type -> unit + +function ICC_BPR1_NS_write value_name = { + let r : ICC_BPR1_Type = value_name; + ICC_BPR1_EL1_NS.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_BPR1_NS = r; + return() +} + +val ICC_BPR1_read : unit -> ICC_BPR1_Type + +function ICC_BPR1_read () = { + r : ICC_BPR1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_BPR1_S_read() + } else { + r = ICC_BPR1_NS_read() + }; + return(r) +} + +val ICC_BPR1_write : ICC_BPR1_Type -> unit + +function ICC_BPR1_write value_name = { + let r : ICC_BPR1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_BPR1_S_write() = r + } else { + ICC_BPR1_NS_write() = r + }; + return() +} + +bitfield ICV_RPR_Type : bits(32) = {Priority : 7..0} + +register _ICV_RPR : ICV_RPR_Type + +val ICV_RPR_read : unit -> ICV_RPR_Type + +function ICV_RPR_read () = { + r : ICV_RPR_Type = _ICV_RPR; + r.bits[31 .. 0] = Slice(ICV_RPR_EL1.bits, 0, 32); + return(r) +} + +val ICV_RPR_write : ICV_RPR_Type -> unit + +function ICV_RPR_write value_name = { + let r : ICV_RPR_Type = value_name; + ICV_RPR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_RPR = r; + return() +} + +val VBAR_NS_write : VBAR_Type -> unit + +function VBAR_NS_write value_name = { + let r : VBAR_Type = value_name; + VBAR_EL1[31 .. 0] = Slice(r, 0, 32); + _VBAR_NS = r; + return() +} + +val VBAR_write : VBAR_Type -> unit + +function VBAR_write value_name = { + let r : VBAR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + VBAR_S = r + } else { + VBAR_NS_write() = r + }; + return() +} + +bitfield ID_ISAR0_Type : bits(32) = + { + Divide : 27..24, + Debug : 23..20, + Coproc : 19..16, + CmpBranch : 15..12, + BitField : 11..8, + BitCount : 7..4, + Swap : 3..0 + } + +register _ID_ISAR0 : ID_ISAR0_Type + +val ID_ISAR0_read : unit -> ID_ISAR0_Type + +function ID_ISAR0_read () = { + r : ID_ISAR0_Type = _ID_ISAR0; + r.bits[31 .. 0] = Slice(ID_ISAR0_EL1.bits, 0, 32); + return(r) +} + +val ID_ISAR0_write : ID_ISAR0_Type -> unit + +function ID_ISAR0_write value_name = { + let r : ID_ISAR0_Type = value_name; + ID_ISAR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_ISAR0 = r; + return() +} + +val PMINTENCLR_write : PMINTENCLR_Type -> unit + +function PMINTENCLR_write value_name = { + let r : PMINTENCLR_Type = value_name; + PMINTENCLR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMINTENCLR = r; + return() +} + +bitfield ICV_IAR1_Type : bits(32) = {INTID : 23..0} + +register _ICV_IAR1 : ICV_IAR1_Type + +val ICV_IAR1_read : unit -> ICV_IAR1_Type + +function ICV_IAR1_read () = { + r : ICV_IAR1_Type = _ICV_IAR1; + r.bits[31 .. 0] = Slice(ICV_IAR1_EL1.bits, 0, 32); + return(r) +} + +val ICV_IAR1_write : ICV_IAR1_Type -> unit + +function ICV_IAR1_write value_name = { + let r : ICV_IAR1_Type = value_name; + ICV_IAR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_IAR1 = r; + return() +} + +val DBGPRCR_write : DBGPRCR_Type -> unit + +function DBGPRCR_write value_name = { + let r : DBGPRCR_Type = value_name; + DBGPRCR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGPRCR = r; + return() +} + +val SDER_write : SDER_Type -> unit + +function SDER_write value_name = { + let r : SDER_Type = value_name; + if HaveEL(EL3) then { + SDER32_EL3_write() = Mk_SDER32_EL3_Type(SetSlice(32, SDER32_EL3_read().bits, 0, Slice(r.bits, 0, 32))) + } else { + SDER32_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32) + }; + _SDER = r; + return() +} + +bitfield ID_MMFR4_Type : bits(32) = + { + EVT : 31..28, + CCIDX : 27..24, + LSM : 23..20, + HPDS : 19..16, + CnP : 15..12, + XNX : 11..8, + AC2 : 7..4, + SpecSEI : 3..0 + } + +register _ID_MMFR4 : ID_MMFR4_Type + +val ID_MMFR4_read : unit -> ID_MMFR4_Type + +function ID_MMFR4_read () = { + r : ID_MMFR4_Type = _ID_MMFR4; + r.bits[31 .. 0] = Slice(ID_MMFR4_EL1.bits, 0, 32); + return(r) +} + +val ID_MMFR4_write : ID_MMFR4_Type -> unit + +function ID_MMFR4_write value_name = { + let r : ID_MMFR4_Type = value_name; + ID_MMFR4_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_MMFR4 = r; + return() +} + +bitfield ICC_EOIR1_Type : bits(32) = {INTID : 23..0} + +register _ICC_EOIR1 : ICC_EOIR1_Type + +val ICC_EOIR1_read : unit -> ICC_EOIR1_Type + +function ICC_EOIR1_read () = { + r : ICC_EOIR1_Type = _ICC_EOIR1; + r.bits[31 .. 0] = Slice(ICC_EOIR1_EL1.bits, 0, 32); + return(r) +} + +val ICC_EOIR1_write : ICC_EOIR1_Type -> unit + +function ICC_EOIR1_write value_name = { + let r : ICC_EOIR1_Type = value_name; + ICC_EOIR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_EOIR1 = r; + return() +} + +type TPIDRURW_Type = bits(32) + +register TPIDRURW_S : TPIDRURW_Type + +register _TPIDRURW_NS : TPIDRURW_Type + +val TPIDRURW_NS_read : unit -> TPIDRURW_Type + +function TPIDRURW_NS_read () = { + r : TPIDRURW_Type = _TPIDRURW_NS; + r[31 .. 0] = Slice(TPIDR_EL0, 0, 32); + return(r) +} + +val TPIDRURW_NS_write : TPIDRURW_Type -> unit + +function TPIDRURW_NS_write value_name = { + let r : TPIDRURW_Type = value_name; + TPIDR_EL0[31 .. 0] = Slice(r, 0, 32); + _TPIDRURW_NS = r; + return() +} + +val TPIDRURW_read : unit -> TPIDRURW_Type + +function TPIDRURW_read () = { + r : TPIDRURW_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = TPIDRURW_S + } else { + r = TPIDRURW_NS_read() + }; + return(r) +} + +val TPIDRURW_write : TPIDRURW_Type -> unit + +function TPIDRURW_write value_name = { + let r : TPIDRURW_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + TPIDRURW_S = r + } else { + TPIDRURW_NS_write() = r + }; + return() +} + +bitfield ICC_BPR0_Type : bits(32) = {BinaryPoint : 2..0} + +register _ICC_BPR0 : ICC_BPR0_Type + +val ICC_BPR0_read : unit -> ICC_BPR0_Type + +function ICC_BPR0_read () = { + r : ICC_BPR0_Type = _ICC_BPR0; + r.bits[31 .. 0] = Slice(ICC_BPR0_EL1.bits, 0, 32); + return(r) +} + +val ICC_BPR0_write : ICC_BPR0_Type -> unit + +function ICC_BPR0_write value_name = { + let r : ICC_BPR0_Type = value_name; + ICC_BPR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_BPR0 = r; + return() +} + +type ICV_AP1R_Type = bits(32) + +register _ICV_AP1R : vector(4, ICV_AP1R_Type) + +val ICV_AP1R_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> ICV_AP1R_Type + +function ICV_AP1R_read n = { + r : ICV_AP1R_Type = _ICV_AP1R[n]; + r[31 .. 0] = Slice(ICV_AP1R_EL1[n].bits, 0, 32); + return(r) +} + +val ICV_AP1R_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), ICV_AP1R_Type) -> unit + +function ICV_AP1R_set (n, value_name) = { + let r : ICV_AP1R_Type = value_name; + ICV_AP1R_EL1[n].bits[31 .. 0] = Slice(r, 0, 32); + _ICV_AP1R[n] = r; + return() +} + +type ADFSR_Type = bits(32) + +register ADFSR_S : ADFSR_Type + +register _ADFSR_NS : ADFSR_Type + +val ADFSR_NS_read : unit -> ADFSR_Type + +function ADFSR_NS_read () = { + r : ADFSR_Type = _ADFSR_NS; + r[31 .. 0] = Slice(AFSR0_EL1, 0, 32); + return(r) +} + +val ADFSR_NS_write : ADFSR_Type -> unit + +function ADFSR_NS_write value_name = { + let r : ADFSR_Type = value_name; + AFSR0_EL1[31 .. 0] = Slice(r, 0, 32); + _ADFSR_NS = r; + return() +} + +val ADFSR_read : unit -> ADFSR_Type + +function ADFSR_read () = { + r : ADFSR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ADFSR_S + } else { + r = ADFSR_NS_read() + }; + return(r) +} + +val ADFSR_write : ADFSR_Type -> unit + +function ADFSR_write value_name = { + let r : ADFSR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ADFSR_S = r + } else { + ADFSR_NS_write() = r + }; + return() +} + +bitfield CNTHCTL_Type : bits(32) = + { + EVNTIS : 17..17, + EVNTI : 7..4, + EVNTDIR : 3..3, + EVNTEN : 2..2, + PL1PCEN : 1..1, + PL1PCTEN : 0..0 + } + +register _CNTHCTL : CNTHCTL_Type + +val CNTHCTL_read : unit -> CNTHCTL_Type + +function CNTHCTL_read () = { + r : CNTHCTL_Type = _CNTHCTL; + r.bits[31 .. 0] = Slice(CNTHCTL_EL2.bits, 0, 32); + return(r) +} + +val CNTHCTL_write : CNTHCTL_Type -> unit + +function CNTHCTL_write value_name = { + let r : CNTHCTL_Type = value_name; + CNTHCTL_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTHCTL = r; + return() +} + +val DBGVCR_write : DBGVCR_Type -> unit + +function DBGVCR_write value_name = { + let r : DBGVCR_Type = value_name; + DBGVCR32_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGVCR = r; + return() +} + +bitfield ICC_EOIR0_Type : bits(32) = {INTID : 23..0} + +register _ICC_EOIR0 : ICC_EOIR0_Type + +val ICC_EOIR0_read : unit -> ICC_EOIR0_Type + +function ICC_EOIR0_read () = { + r : ICC_EOIR0_Type = _ICC_EOIR0; + r.bits[31 .. 0] = Slice(ICC_EOIR0_EL1.bits, 0, 32); + return(r) +} + +val ICC_EOIR0_write : ICC_EOIR0_Type -> unit + +function ICC_EOIR0_write value_name = { + let r : ICC_EOIR0_Type = value_name; + ICC_EOIR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_EOIR0 = r; + return() +} + +type REVIDR_Type = bits(32) + +register _REVIDR : REVIDR_Type + +val REVIDR_read : unit -> REVIDR_Type + +function REVIDR_read () = { + r : REVIDR_Type = _REVIDR; + r[31 .. 0] = Slice(REVIDR_EL1, 0, 32); + return(r) +} + +bitfield ID_MMFR1_Type : bits(32) = + { + BPred : 31..28, + L1TstCln : 27..24, + L1Uni : 23..20, + L1Hvd : 19..16, + L1UniSW : 15..12, + L1HvdSW : 11..8, + L1UniVA : 7..4, + L1HvdVA : 3..0 + } + +register _ID_MMFR1 : ID_MMFR1_Type + +val ID_MMFR1_read : unit -> ID_MMFR1_Type + +function ID_MMFR1_read () = { + r : ID_MMFR1_Type = _ID_MMFR1; + r.bits[31 .. 0] = Slice(ID_MMFR1_EL1.bits, 0, 32); + return(r) +} + +val ID_MMFR1_write : ID_MMFR1_Type -> unit + +function ID_MMFR1_write value_name = { + let r : ID_MMFR1_Type = value_name; + ID_MMFR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_MMFR1 = r; + return() +} + +bitfield ICV_BPR1_Type : bits(32) = {BinaryPoint : 2..0} + +register _ICV_BPR1 : ICV_BPR1_Type + +val ICV_BPR1_read : unit -> ICV_BPR1_Type + +function ICV_BPR1_read () = { + r : ICV_BPR1_Type = _ICV_BPR1; + r.bits[31 .. 0] = Slice(ICV_BPR1_EL1.bits, 0, 32); + return(r) +} + +val ICV_BPR1_write : ICV_BPR1_Type -> unit + +function ICV_BPR1_write value_name = { + let r : ICV_BPR1_Type = value_name; + ICV_BPR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_BPR1 = r; + return() +} + +bitfield ICC_RPR_Type : bits(32) = {Priority : 7..0} + +register _ICC_RPR : ICC_RPR_Type + +val ICC_RPR_read : unit -> ICC_RPR_Type + +function ICC_RPR_read () = { + r : ICC_RPR_Type = _ICC_RPR; + r.bits[31 .. 0] = Slice(ICC_RPR_EL1.bits, 0, 32); + return(r) +} + +val ICC_RPR_write : ICC_RPR_Type -> unit + +function ICC_RPR_write value_name = { + let r : ICC_RPR_Type = value_name; + ICC_RPR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_RPR = r; + return() +} + +bitfield MVFR2_Type : bits(32) = {FPMisc : 7..4, SIMDMisc : 3..0} + +register _MVFR2 : MVFR2_Type + +val MVFR2_read : unit -> MVFR2_Type + +function MVFR2_read () = { + r : MVFR2_Type = _MVFR2; + r.bits[31 .. 0] = Slice(MVFR2_EL1.bits, 0, 32); + return(r) +} + +val MVFR2_write : MVFR2_Type -> unit + +function MVFR2_write value_name = { + let r : MVFR2_Type = value_name; + MVFR2_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _MVFR2 = r; + return() +} + +bitfield ICC_MSRE_Type : bits(32) = + {Enable : 3..3, DIB : 2..2, DFB : 1..1, SRE : 0..0} + +register ICC_MSRE : ICC_MSRE_Type + +bitfield PMMIR_Type : bits(32) = + { + EDGE : 27..24, + THWIDTH : 23..20, + BUS_WIDTH : 19..16, + BUS_SLOTS : 15..8, + SLOTS : 7..0 + } + +register PMMIR : PMMIR_Type + +bitfield VMPIDR_Type : bits(32) = + { + M : 31..31, + U : 30..30, + MT : 24..24, + Aff2 : 23..16, + Aff1 : 15..8, + Aff0 : 7..0 + } + +register _VMPIDR : VMPIDR_Type + +val VMPIDR_read : unit -> VMPIDR_Type + +function VMPIDR_read () = { + r : VMPIDR_Type = _VMPIDR; + r.bits[31 .. 0] = Slice(VMPIDR_EL2.bits, 0, 32); + return(r) +} + +val VMPIDR_write : VMPIDR_Type -> unit + +function VMPIDR_write value_name = { + let r : VMPIDR_Type = value_name; + VMPIDR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _VMPIDR = r; + return() +} + +bitfield ICC_IGRPEN1_Type : bits(32) = {Enable : 0..0} + +register _ICC_IGRPEN1_S : ICC_IGRPEN1_Type + +val ICC_IGRPEN1_S_read : unit -> ICC_IGRPEN1_Type + +function ICC_IGRPEN1_S_read () = { + r : ICC_IGRPEN1_Type = _ICC_IGRPEN1_S; + r.bits[31 .. 0] = Slice(ICC_IGRPEN1_EL1_S.bits, 0, 32); + return(r) +} + +val ICC_IGRPEN1_S_write : ICC_IGRPEN1_Type -> unit + +function ICC_IGRPEN1_S_write value_name = { + let r : ICC_IGRPEN1_Type = value_name; + ICC_IGRPEN1_EL1_S.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_IGRPEN1_S = r; + return() +} + +register _ICC_IGRPEN1_NS : ICC_IGRPEN1_Type + +val ICC_IGRPEN1_NS_read : unit -> ICC_IGRPEN1_Type + +function ICC_IGRPEN1_NS_read () = { + r : ICC_IGRPEN1_Type = _ICC_IGRPEN1_NS; + r.bits[31 .. 0] = Slice(ICC_IGRPEN1_EL1_NS.bits, 0, 32); + return(r) +} + +val ICC_IGRPEN1_NS_write : ICC_IGRPEN1_Type -> unit + +function ICC_IGRPEN1_NS_write value_name = { + let r : ICC_IGRPEN1_Type = value_name; + ICC_IGRPEN1_EL1_NS.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_IGRPEN1_NS = r; + return() +} + +val ICC_IGRPEN1_read : unit -> ICC_IGRPEN1_Type + +function ICC_IGRPEN1_read () = { + r : ICC_IGRPEN1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_IGRPEN1_S_read() + } else { + r = ICC_IGRPEN1_NS_read() + }; + return(r) +} + +val ICC_IGRPEN1_write : ICC_IGRPEN1_Type -> unit + +function ICC_IGRPEN1_write value_name = { + let r : ICC_IGRPEN1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_IGRPEN1_S_write() = r + } else { + ICC_IGRPEN1_NS_write() = r + }; + return() +} + +val MAIR0_S_write : MAIR0_Type -> unit + +function MAIR0_S_write value_name = { + let r : MAIR0_Type = value_name; + PRRR_S.bits[31 .. 0] = Slice(r.bits, 0, 32); + _MAIR0_S = r; + return() +} + +val MAIR0_NS_write : MAIR0_Type -> unit + +function MAIR0_NS_write value_name = { + let r : MAIR0_Type = value_name; + if ELUsingAArch32(EL3) then { + PRRR_NS_write() = Mk_PRRR_Type(SetSlice(32, PRRR_NS_read().bits, 0, Slice(r.bits, 0, 32))) + } else { + if not_bool(HaveEL(EL3)) | not_bool(ELUsingAArch32(EL3)) then { + MAIR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32) + } else { + PRRR_write() = Mk_PRRR_Type(SetSlice(32, PRRR_read().bits, 0, Slice(r.bits, 0, 32))) + } + }; + _MAIR0_NS = r; + return() +} + +val MAIR0_write : MAIR0_Type -> unit + +function MAIR0_write value_name = { + let r : MAIR0_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + MAIR0_S_write() = r + } else { + MAIR0_NS_write() = r + }; + return() +} + +bitfield FPSID_Type : bits(32) = + { + Implementer : 31..24, + SW : 23..23, + Subarchitecture : 22..16, + PartNum : 15..8, + Variant : 7..4, + Revision : 3..0 + } + +register FPSID : FPSID_Type + +val HVBAR_write : HVBAR_Type -> unit + +function HVBAR_write value_name = { + let r : HVBAR_Type = value_name; + VBAR_EL2[31 .. 0] = Slice(r, 0, 32); + _HVBAR = r; + return() +} + +val HSTR_write : HSTR_Type -> unit + +function HSTR_write value_name = { + let r : HSTR_Type = value_name; + HSTR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HSTR = r; + return() +} + +bitfield ICC_MCTLR_Type : bits(32) = + { + ExtRange : 19..19, + RSS : 18..18, + nDS : 17..17, + A3V : 15..15, + SEIS : 14..14, + IDbits : 13..11, + PRIbits : 10..8, + PMHE : 6..6, + RM : 5..5, + EOImode_EL1NS : 4..4, + EOImode_EL1S : 3..3, + EOImode_EL3 : 2..2, + CBPR_EL1NS : 1..1, + CBPR_EL1S : 0..0 + } + +register ICC_MCTLR : ICC_MCTLR_Type + +bitfield ICC_DIR_Type : bits(32) = {INTID : 23..0} + +register _ICC_DIR : ICC_DIR_Type + +val ICC_DIR_read : unit -> ICC_DIR_Type + +function ICC_DIR_read () = { + r : ICC_DIR_Type = _ICC_DIR; + r.bits[31 .. 0] = Slice(ICC_DIR_EL1.bits, 0, 32); + return(r) +} + +val ICC_DIR_write : ICC_DIR_Type -> unit + +function ICC_DIR_write value_name = { + let r : ICC_DIR_Type = value_name; + ICC_DIR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_DIR = r; + return() +} + +bitfield PMSELR_Type : bits(32) = {SEL : 4..0} + +register _PMSELR : PMSELR_Type + +val PMSELR_read : unit -> PMSELR_Type + +function PMSELR_read () = { + r : PMSELR_Type = _PMSELR; + r.bits[31 .. 0] = Slice(PMSELR_EL0.bits, 0, 32); + return(r) +} + +val PMSELR_write : PMSELR_Type -> unit + +function PMSELR_write value_name = { + let r : PMSELR_Type = value_name; + PMSELR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMSELR = r; + return() +} + +type ID_AFR0_Type = bits(32) + +register _ID_AFR0 : ID_AFR0_Type + +val ID_AFR0_read : unit -> ID_AFR0_Type + +function ID_AFR0_read () = { + r : ID_AFR0_Type = _ID_AFR0; + r[31 .. 0] = Slice(ID_AFR0_EL1, 0, 32); + return(r) +} + +val ID_AFR0_write : ID_AFR0_Type -> unit + +function ID_AFR0_write value_name = { + let r : ID_AFR0_Type = value_name; + ID_AFR0_EL1[31 .. 0] = Slice(r, 0, 32); + _ID_AFR0 = r; + return() +} + +bitfield DBGCLAIMSET_Type : bits(32) = {CLAIM : 7..0} + +register _DBGCLAIMSET : DBGCLAIMSET_Type + +val DBGCLAIMSET_read : unit -> DBGCLAIMSET_Type + +function DBGCLAIMSET_read () = { + r : DBGCLAIMSET_Type = _DBGCLAIMSET; + r.bits[31 .. 0] = Slice(DBGCLAIMSET_EL1.bits, 0, 32); + return(r) +} + +val DBGCLAIMSET_write : DBGCLAIMSET_Type -> unit + +function DBGCLAIMSET_write value_name = { + let r : DBGCLAIMSET_Type = value_name; + DBGCLAIMSET_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGCLAIMSET = r; + return() +} + +val NMRR_NS_write : NMRR_Type -> unit + +function NMRR_NS_write value_name = { + let r : NMRR_Type = value_name; + MAIR_EL1.bits[63 .. 32] = Slice(r.bits, 0, 32); + _NMRR_NS = r; + return() +} + +val NMRR_write : NMRR_Type -> unit + +function NMRR_write value_name = { + let r : NMRR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + NMRR_S = r + } else { + NMRR_NS_write() = r + }; + return() +} + +type TPIDRURO_Type = bits(32) + +register TPIDRURO_S : TPIDRURO_Type + +register _TPIDRURO_NS : TPIDRURO_Type + +val TPIDRURO_NS_read : unit -> TPIDRURO_Type + +function TPIDRURO_NS_read () = { + r : TPIDRURO_Type = _TPIDRURO_NS; + r[31 .. 0] = Slice(TPIDRRO_EL0, 0, 32); + return(r) +} + +val TPIDRURO_NS_write : TPIDRURO_Type -> unit + +function TPIDRURO_NS_write value_name = { + let r : TPIDRURO_Type = value_name; + TPIDRRO_EL0[31 .. 0] = Slice(r, 0, 32); + _TPIDRURO_NS = r; + return() +} + +val TPIDRURO_read : unit -> TPIDRURO_Type + +function TPIDRURO_read () = { + r : TPIDRURO_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = TPIDRURO_S + } else { + r = TPIDRURO_NS_read() + }; + return(r) +} + +val TPIDRURO_write : TPIDRURO_Type -> unit + +function TPIDRURO_write value_name = { + let r : TPIDRURO_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + TPIDRURO_S = r + } else { + TPIDRURO_NS_write() = r + }; + return() +} + +val __get_selected_PMEVCNTR : unit -> PMEVCNTR_Type + +function __get_selected_PMEVCNTR () = { + let 'idx = UInt(PMSELR_read()[SEL]); + assert(idx <= 30); + return(PMEVCNTR_read(idx)) +} + +val __set_selected_PMEVCNTR : PMEVCNTR_Type -> unit + +function __set_selected_PMEVCNTR value_name = { + let 'idx = UInt(PMSELR_read()[SEL]); + assert(idx <= 30); + PMEVCNTR_set(idx) = value_name; + return() +} + +bitfield ICC_IGRPEN0_Type : bits(32) = {Enable : 0..0} + +register _ICC_IGRPEN0 : ICC_IGRPEN0_Type + +val ICC_IGRPEN0_read : unit -> ICC_IGRPEN0_Type + +function ICC_IGRPEN0_read () = { + r : ICC_IGRPEN0_Type = _ICC_IGRPEN0; + r.bits[31 .. 0] = Slice(ICC_IGRPEN0_EL1.bits, 0, 32); + return(r) +} + +val ICC_IGRPEN0_write : ICC_IGRPEN0_Type -> unit + +function ICC_IGRPEN0_write value_name = { + let r : ICC_IGRPEN0_Type = value_name; + ICC_IGRPEN0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_IGRPEN0 = r; + return() +} + +bitfield DBGDTRTXext_Type : bits(32) = {DTRTX : 31..0} + +register _DBGDTRTXext : DBGDTRTXext_Type + +val DBGDTRTXext_read : unit -> DBGDTRTXext_Type + +function DBGDTRTXext_read () = { + r : DBGDTRTXext_Type = _DBGDTRTXext; + r.bits[31 .. 0] = Slice(OSDTRTX_EL1, 0, 32); + return(r) +} + +val DBGDTRTXext_write : DBGDTRTXext_Type -> unit + +function DBGDTRTXext_write value_name = { + let r : DBGDTRTXext_Type = value_name; + OSDTRTX_EL1[31 .. 0] = Slice(r.bits, 0, 32); + _DBGDTRTXext = r; + return() +} + +type ACTLR_Type = bits(32) + +register ACTLR_S : ACTLR_Type + +register _ACTLR_NS : ACTLR_Type + +val ACTLR_NS_read : unit -> ACTLR_Type + +function ACTLR_NS_read () = { + r : ACTLR_Type = _ACTLR_NS; + r[31 .. 0] = Slice(ACTLR_EL1, 0, 32); + return(r) +} + +val ACTLR_NS_write : ACTLR_Type -> unit + +function ACTLR_NS_write value_name = { + let r : ACTLR_Type = value_name; + ACTLR_EL1[31 .. 0] = Slice(r, 0, 32); + _ACTLR_NS = r; + return() +} + +val ACTLR_read : unit -> ACTLR_Type + +function ACTLR_read () = { + r : ACTLR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ACTLR_S + } else { + r = ACTLR_NS_read() + }; + return(r) +} + +val ACTLR_write : ACTLR_Type -> unit + +function ACTLR_write value_name = { + let r : ACTLR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ACTLR_S = r + } else { + ACTLR_NS_write() = r + }; + return() +} + +bitfield MVFR1_Type : bits(32) = + { + SIMDFMAC : 31..28, + FPHP : 27..24, + SIMDHP : 23..20, + SIMDSP : 19..16, + SIMDInt : 15..12, + SIMDLS : 11..8, + FPDNaN : 7..4, + FPFtZ : 3..0 + } + +register _MVFR1 : MVFR1_Type + +val MVFR1_read : unit -> MVFR1_Type + +function MVFR1_read () = { + r : MVFR1_Type = _MVFR1; + r.bits[31 .. 0] = Slice(MVFR1_EL1.bits, 0, 32); + return(r) +} + +val MVFR1_write : MVFR1_Type -> unit + +function MVFR1_write value_name = { + let r : MVFR1_Type = value_name; + MVFR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _MVFR1 = r; + return() +} + +bitfield ICC_CTLR_Type : bits(32) = + { + ExtRange : 19..19, + RSS : 18..18, + A3V : 15..15, + SEIS : 14..14, + IDbits : 13..11, + PRIbits : 10..8, + PMHE : 6..6, + EOImode : 1..1, + CBPR : 0..0 + } + +register _ICC_CTLR_S : ICC_CTLR_Type + +val ICC_CTLR_S_read : unit -> ICC_CTLR_Type + +function ICC_CTLR_S_read () = { + r : ICC_CTLR_Type = _ICC_CTLR_S; + r.bits[31 .. 0] = Slice(ICC_CTLR_EL1_S.bits, 0, 32); + return(r) +} + +val ICC_CTLR_S_write : ICC_CTLR_Type -> unit + +function ICC_CTLR_S_write value_name = { + let r : ICC_CTLR_Type = value_name; + ICC_CTLR_EL1_S.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_CTLR_S = r; + return() +} + +register _ICC_CTLR_NS : ICC_CTLR_Type + +val ICC_CTLR_NS_read : unit -> ICC_CTLR_Type + +function ICC_CTLR_NS_read () = { + r : ICC_CTLR_Type = _ICC_CTLR_NS; + r.bits[31 .. 0] = Slice(ICC_CTLR_EL1_NS.bits, 0, 32); + return(r) +} + +val ICC_CTLR_NS_write : ICC_CTLR_Type -> unit + +function ICC_CTLR_NS_write value_name = { + let r : ICC_CTLR_Type = value_name; + ICC_CTLR_EL1_NS.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_CTLR_NS = r; + return() +} + +val ICC_CTLR_read : unit -> ICC_CTLR_Type + +function ICC_CTLR_read () = { + r : ICC_CTLR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_CTLR_S_read() + } else { + r = ICC_CTLR_NS_read() + }; + return(r) +} + +val ICC_CTLR_write : ICC_CTLR_Type -> unit + +function ICC_CTLR_write value_name = { + let r : ICC_CTLR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_CTLR_S_write() = r + } else { + ICC_CTLR_NS_write() = r + }; + return() +} + +bitfield DBGOSLAR_Type : bits(32) = {OSLA : 31..0} + +register DBGOSLAR : DBGOSLAR_Type + +bitfield DBGDTRRXext_Type : bits(32) = {DTRRX : 31..0} + +register _DBGDTRRXext : DBGDTRRXext_Type + +val DBGDTRRXext_read : unit -> DBGDTRRXext_Type + +function DBGDTRRXext_read () = { + r : DBGDTRRXext_Type = _DBGDTRRXext; + r.bits[31 .. 0] = Slice(OSDTRRX_EL1, 0, 32); + return(r) +} + +val DBGDTRRXext_write : DBGDTRRXext_Type -> unit + +function DBGDTRRXext_write value_name = { + let r : DBGDTRRXext_Type = value_name; + OSDTRRX_EL1[31 .. 0] = Slice(r.bits, 0, 32); + _DBGDTRRXext = r; + return() +} + +type ICC_AP1R_Type = bits(32) + +register _ICC_AP1R_S : vector(4, ICC_AP1R_Type) + +val ICC_AP1R_S_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> ICC_AP1R_Type + +function ICC_AP1R_S_read n = { + r : ICC_AP1R_Type = _ICC_AP1R_S[n]; + r[31 .. 0] = Slice(ICC_AP1R_EL1_S[n].bits, 0, 32); + return(r) +} + +val ICC_AP1R_S_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), ICC_AP1R_Type) -> unit + +function ICC_AP1R_S_set (n, value_name) = { + let r : ICC_AP1R_Type = value_name; + ICC_AP1R_EL1_S[n].bits[31 .. 0] = Slice(r, 0, 32); + _ICC_AP1R_S[n] = r; + return() +} + +register _ICC_AP1R_NS : vector(4, ICC_AP1R_Type) + +val ICC_AP1R_NS_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> ICC_AP1R_Type + +function ICC_AP1R_NS_read n = { + r : ICC_AP1R_Type = _ICC_AP1R_NS[n]; + r[31 .. 0] = Slice(ICC_AP1R_EL1_NS[n].bits, 0, 32); + return(r) +} + +val ICC_AP1R_NS_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), ICC_AP1R_Type) -> unit + +function ICC_AP1R_NS_set (n, value_name) = { + let r : ICC_AP1R_Type = value_name; + ICC_AP1R_EL1_NS[n].bits[31 .. 0] = Slice(r, 0, 32); + _ICC_AP1R_NS[n] = r; + return() +} + +val ICC_AP1R_read : forall 'n. int('n) -> ICC_AP1R_Type + +function ICC_AP1R_read n = { + r : ICC_AP1R_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + assert(constraint((0 <= 'n & 'n < 4))); + r = ICC_AP1R_S_read(n) + } else { + assert(constraint((0 <= 'n & 'n < 4))); + r = ICC_AP1R_NS_read(n) + }; + return(r) +} + +val ICC_AP1R_set : forall 'n. (int('n), ICC_AP1R_Type) -> unit + +function ICC_AP1R_set (n, value_name) = { + let r : ICC_AP1R_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + assert(constraint((0 <= 'n & 'n < 4))); + ICC_AP1R_S_set(n) = r + } else { + assert(constraint((0 <= 'n & 'n < 4))); + ICC_AP1R_NS_set(n) = r + }; + return() +} + +bitfield CNTHVS_CTL_Type : bits(32) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register _CNTHVS_CTL : CNTHVS_CTL_Type + +val CNTHVS_CTL_read : unit -> CNTHVS_CTL_Type + +function CNTHVS_CTL_read () = { + r : CNTHVS_CTL_Type = _CNTHVS_CTL; + r.bits[31 .. 0] = Slice(CNTHVS_CTL_EL2.bits, 0, 32); + return(r) +} + +val CNTHVS_CTL_write : CNTHVS_CTL_Type -> unit + +function CNTHVS_CTL_write value_name = { + let r : CNTHVS_CTL_Type = value_name; + CNTHVS_CTL_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTHVS_CTL = r; + return() +} + +bitfield ICH_AP1R_Type : bits(32) = + { + P31 : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _ICH_AP1R : vector(4, ICH_AP1R_Type) + +val ICH_AP1R_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> ICH_AP1R_Type + +function ICH_AP1R_read n = { + r : ICH_AP1R_Type = _ICH_AP1R[n]; + r.bits[31 .. 0] = Slice(ICH_AP1R_EL2[n].bits, 0, 32); + return(r) +} + +val ICH_AP1R_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), ICH_AP1R_Type) -> unit + +function ICH_AP1R_set (n, value_name) = { + let r : ICH_AP1R_Type = value_name; + ICH_AP1R_EL2[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_AP1R[n] = r; + return() +} + +bitfield ID_MMFR0_Type : bits(32) = + { + InnerShr : 31..28, + FCSE : 27..24, + AuxReg : 23..20, + TCM : 19..16, + ShareLvl : 15..12, + OuterShr : 11..8, + PMSA : 7..4, + VMSA : 3..0 + } + +register _ID_MMFR0 : ID_MMFR0_Type + +val ID_MMFR0_read : unit -> ID_MMFR0_Type + +function ID_MMFR0_read () = { + r : ID_MMFR0_Type = _ID_MMFR0; + r.bits[31 .. 0] = Slice(ID_MMFR0_EL1.bits, 0, 32); + return(r) +} + +val ID_MMFR0_write : ID_MMFR0_Type -> unit + +function ID_MMFR0_write value_name = { + let r : ID_MMFR0_Type = value_name; + ID_MMFR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_MMFR0 = r; + return() +} + +bitfield ICV_BPR0_Type : bits(32) = {BinaryPoint : 2..0} + +register _ICV_BPR0 : ICV_BPR0_Type + +val ICV_BPR0_read : unit -> ICV_BPR0_Type + +function ICV_BPR0_read () = { + r : ICV_BPR0_Type = _ICV_BPR0; + r.bits[31 .. 0] = Slice(ICV_BPR0_EL1.bits, 0, 32); + return(r) +} + +val ICV_BPR0_write : ICV_BPR0_Type -> unit + +function ICV_BPR0_write value_name = { + let r : ICV_BPR0_Type = value_name; + ICV_BPR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_BPR0 = r; + return() +} + +bitfield ICH_EISR_Type : bits(32) = + { + Status15 : 15..15, + Status14 : 14..14, + Status13 : 13..13, + Status12 : 12..12, + Status11 : 11..11, + Status10 : 10..10, + Status9 : 9..9, + Status8 : 8..8, + Status7 : 7..7, + Status6 : 6..6, + Status5 : 5..5, + Status4 : 4..4, + Status3 : 3..3, + Status2 : 2..2, + Status1 : 1..1, + Status0 : 0..0 + } + +register _ICH_EISR : ICH_EISR_Type + +val ICH_EISR_read : unit -> ICH_EISR_Type + +function ICH_EISR_read () = { + r : ICH_EISR_Type = _ICH_EISR; + r.bits[31 .. 0] = Slice(ICH_EISR_EL2.bits, 0, 32); + return(r) +} + +val ICH_EISR_write : ICH_EISR_Type -> unit + +function ICH_EISR_write value_name = { + let r : ICH_EISR_Type = value_name; + ICH_EISR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_EISR = r; + return() +} + +type AMAIR0_Type = bits(32) + +register AMAIR0_S : AMAIR0_Type + +register _AMAIR0_NS : AMAIR0_Type + +val AMAIR0_NS_read : unit -> AMAIR0_Type + +function AMAIR0_NS_read () = { + r : AMAIR0_Type = _AMAIR0_NS; + r[31 .. 0] = Slice(AMAIR_EL1, 0, 32); + return(r) +} + +val AMAIR0_NS_write : AMAIR0_Type -> unit + +function AMAIR0_NS_write value_name = { + let r : AMAIR0_Type = value_name; + AMAIR_EL1[31 .. 0] = Slice(r, 0, 32); + _AMAIR0_NS = r; + return() +} + +val AMAIR0_read : unit -> AMAIR0_Type + +function AMAIR0_read () = { + r : AMAIR0_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = AMAIR0_S + } else { + r = AMAIR0_NS_read() + }; + return(r) +} + +val AMAIR0_write : AMAIR0_Type -> unit + +function AMAIR0_write value_name = { + let r : AMAIR0_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + AMAIR0_S = r + } else { + AMAIR0_NS_write() = r + }; + return() +} + +val HDCR_write : HDCR_Type -> unit + +function HDCR_write value_name = { + let r : HDCR_Type = value_name; + MDCR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HDCR = r; + return() +} + +bitfield MVFR0_Type : bits(32) = + { + FPRound : 31..28, + FPShVec : 27..24, + FPSqrt : 23..20, + FPDivide : 19..16, + FPTrap : 15..12, + FPDP : 11..8, + FPSP : 7..4, + SIMDReg : 3..0 + } + +register _MVFR0 : MVFR0_Type + +val MVFR0_read : unit -> MVFR0_Type + +function MVFR0_read () = { + r : MVFR0_Type = _MVFR0; + r.bits[31 .. 0] = Slice(MVFR0_EL1.bits, 0, 32); + return(r) +} + +val MVFR0_write : MVFR0_Type -> unit + +function MVFR0_write value_name = { + let r : MVFR0_Type = value_name; + MVFR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _MVFR0 = r; + return() +} + +type HAMAIR0_Type = bits(32) + +register _HAMAIR0 : HAMAIR0_Type + +val HAMAIR0_read : unit -> HAMAIR0_Type + +function HAMAIR0_read () = { + r : HAMAIR0_Type = _HAMAIR0; + r[31 .. 0] = Slice(AMAIR_EL2, 0, 32); + return(r) +} + +val HAMAIR0_write : HAMAIR0_Type -> unit + +function HAMAIR0_write value_name = { + let r : HAMAIR0_Type = value_name; + AMAIR_EL2[31 .. 0] = Slice(r, 0, 32); + _HAMAIR0 = r; + return() +} + +bitfield ICC_HSRE_Type : bits(32) = + {Enable : 3..3, DIB : 2..2, DFB : 1..1, SRE : 0..0} + +register _ICC_HSRE : ICC_HSRE_Type + +val ICC_HSRE_read : unit -> ICC_HSRE_Type + +function ICC_HSRE_read () = { + r : ICC_HSRE_Type = _ICC_HSRE; + r.bits[31 .. 0] = Slice(ICC_SRE_EL2.bits, 0, 32); + return(r) +} + +val ICC_HSRE_write : ICC_HSRE_Type -> unit + +function ICC_HSRE_write value_name = { + let r : ICC_HSRE_Type = value_name; + ICC_SRE_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_HSRE = r; + return() +} + +val PMCCFILTR_write : PMCCFILTR_Type -> unit + +function PMCCFILTR_write value_name = { + let r : PMCCFILTR_Type = value_name; + PMCCFILTR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMCCFILTR = r; + return() +} + +bitfield ICH_AP0R_Type : bits(32) = + { + P31 : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _ICH_AP0R : vector(4, ICH_AP0R_Type) + +val ICH_AP0R_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> ICH_AP0R_Type + +function ICH_AP0R_read n = { + r : ICH_AP0R_Type = _ICH_AP0R[n]; + r.bits[31 .. 0] = Slice(ICH_AP0R_EL2[n].bits, 0, 32); + return(r) +} + +val ICH_AP0R_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), ICH_AP0R_Type) -> unit + +function ICH_AP0R_set (n, value_name) = { + let r : ICH_AP0R_Type = value_name; + ICH_AP0R_EL2[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_AP0R[n] = r; + return() +} + +bitfield ID_ISAR5_Type : bits(32) = + { + VCMA : 31..28, + RDM : 27..24, + CRC32 : 19..16, + SHA2 : 15..12, + SHA1 : 11..8, + AES : 7..4, + SEVL : 3..0 + } + +register _ID_ISAR5 : ID_ISAR5_Type + +val ID_ISAR5_read : unit -> ID_ISAR5_Type + +function ID_ISAR5_read () = { + r : ID_ISAR5_Type = _ID_ISAR5; + r.bits[31 .. 0] = Slice(ID_ISAR5_EL1.bits, 0, 32); + return(r) +} + +val ID_ISAR5_write : ID_ISAR5_Type -> unit + +function ID_ISAR5_write value_name = { + let r : ID_ISAR5_Type = value_name; + ID_ISAR5_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_ISAR5 = r; + return() +} + +val HTCR_write : HTCR_Type -> unit + +function HTCR_write value_name = { + let r : HTCR_Type = value_name; + TCR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HTCR = r; + return() +} + +type AIDR_Type = bits(32) + +register _AIDR : AIDR_Type + +val AIDR_read : unit -> AIDR_Type + +function AIDR_read () = { + r : AIDR_Type = _AIDR; + r[31 .. 0] = Slice(AIDR_EL1, 0, 32); + return(r) +} + +bitfield ICC_PMR_Type : bits(32) = {Priority : 7..0} + +register _ICC_PMR : ICC_PMR_Type + +val ICC_PMR_read : unit -> ICC_PMR_Type + +function ICC_PMR_read () = { + r : ICC_PMR_Type = _ICC_PMR; + r.bits[31 .. 0] = Slice(ICC_PMR_EL1.bits, 0, 32); + return(r) +} + +val ICC_PMR_write : ICC_PMR_Type -> unit + +function ICC_PMR_write value_name = { + let r : ICC_PMR_Type = value_name; + ICC_PMR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_PMR = r; + return() +} + +bitfield ICV_EOIR1_Type : bits(32) = {INTID : 23..0} + +register _ICV_EOIR1 : ICV_EOIR1_Type + +val ICV_EOIR1_read : unit -> ICV_EOIR1_Type + +function ICV_EOIR1_read () = { + r : ICV_EOIR1_Type = _ICV_EOIR1; + r.bits[31 .. 0] = Slice(ICV_EOIR1_EL1.bits, 0, 32); + return(r) +} + +val ICV_EOIR1_write : ICV_EOIR1_Type -> unit + +function ICV_EOIR1_write value_name = { + let r : ICV_EOIR1_Type = value_name; + ICV_EOIR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_EOIR1 = r; + return() +} + +bitfield ID_PFR1_Type : bits(32) = + { + GIC : 31..28, + Virt_frac : 27..24, + Sec_frac : 23..20, + GenTimer : 19..16, + Virtualization : 15..12, + MProgMod : 11..8, + Security : 7..4, + ProgMod : 3..0 + } + +register _ID_PFR1 : ID_PFR1_Type + +val ID_PFR1_read : unit -> ID_PFR1_Type + +function ID_PFR1_read () = { + r : ID_PFR1_Type = _ID_PFR1; + r.bits[31 .. 0] = Slice(ID_PFR1_EL1.bits, 0, 32); + return(r) +} + +val ID_PFR1_write : ID_PFR1_Type -> unit + +function ID_PFR1_write value_name = { + let r : ID_PFR1_Type = value_name; + ID_PFR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_PFR1 = r; + return() +} + +bitfield ICH_HCR_Type : bits(32) = + { + EOIcount : 31..27, + TDIR : 14..14, + TSEI : 13..13, + TALL1 : 12..12, + TALL0 : 11..11, + TC : 10..10, + vSGIEOICount : 8..8, + VGrp1DIE : 7..7, + VGrp1EIE : 6..6, + VGrp0DIE : 5..5, + VGrp0EIE : 4..4, + NPIE : 3..3, + LRENPIE : 2..2, + UIE : 1..1, + En : 0..0 + } + +register _ICH_HCR : ICH_HCR_Type + +val ICH_HCR_read : unit -> ICH_HCR_Type + +function ICH_HCR_read () = { + r : ICH_HCR_Type = _ICH_HCR; + r.bits[31 .. 0] = Slice(ICH_HCR_EL2.bits, 0, 32); + return(r) +} + +val ICH_HCR_write : ICH_HCR_Type -> unit + +function ICH_HCR_write value_name = { + let r : ICH_HCR_Type = value_name; + ICH_HCR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_HCR = r; + return() +} + +bitfield RMR_Type : bits(32) = {RR : 1..1, AA64 : 0..0} + +register _RMR : RMR_Type + +val RMR_read : unit -> RMR_Type + +function RMR_read () = { + r : RMR_Type = _RMR; + if HaveEL(EL3) then { + r.bits[31 .. 0] = Slice(RMR_EL3.bits, 0, 32) + } else { + r.bits[31 .. 0] = Slice(RMR_EL1.bits, 0, 32) + }; + return(r) +} + +val RMR_write : RMR_Type -> unit + +function RMR_write value_name = { + let r : RMR_Type = value_name; + if HaveEL(EL3) then { + RMR_EL3.bits[31 .. 0] = Slice(r.bits, 0, 32) + } else { + RMR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32) + }; + _RMR = r; + return() +} + +val HMAIR1_write : HMAIR1_Type -> unit + +function HMAIR1_write value_name = { + let r : HMAIR1_Type = value_name; + MAIR_EL2.bits[63 .. 32] = Slice(r.bits, 0, 32); + _HMAIR1 = r; + return() +} + +bitfield PMCEID3_Type : bits(32) = + { + IDhi31 : 31..31, + IDhi30 : 30..30, + IDhi29 : 29..29, + IDhi28 : 28..28, + IDhi27 : 27..27, + IDhi26 : 26..26, + IDhi25 : 25..25, + IDhi24 : 24..24, + IDhi23 : 23..23, + IDhi22 : 22..22, + IDhi21 : 21..21, + IDhi20 : 20..20, + IDhi19 : 19..19, + IDhi18 : 18..18, + IDhi17 : 17..17, + IDhi16 : 16..16, + IDhi15 : 15..15, + IDhi14 : 14..14, + IDhi13 : 13..13, + IDhi12 : 12..12, + IDhi11 : 11..11, + IDhi10 : 10..10, + IDhi9 : 9..9, + IDhi8 : 8..8, + IDhi7 : 7..7, + IDhi6 : 6..6, + IDhi5 : 5..5, + IDhi4 : 4..4, + IDhi3 : 3..3, + IDhi2 : 2..2, + IDhi1 : 1..1, + IDhi0 : 0..0 + } + +register _PMCEID3 : PMCEID3_Type + +val PMCEID3_read : unit -> PMCEID3_Type + +function PMCEID3_read () = { + r : PMCEID3_Type = _PMCEID3; + r.bits[31 .. 0] = Slice(PMCEID1_EL0.bits, 32, 32); + return(r) +} + +val PMCEID3_write : PMCEID3_Type -> unit + +function PMCEID3_write value_name = { + let r : PMCEID3_Type = value_name; + PMCEID1_EL0.bits[63 .. 32] = Slice(r.bits, 0, 32); + _PMCEID3 = r; + return() +} + +bitfield ICC_HPPIR0_Type : bits(32) = {INTID : 23..0} + +register _ICC_HPPIR0 : ICC_HPPIR0_Type + +val ICC_HPPIR0_read : unit -> ICC_HPPIR0_Type + +function ICC_HPPIR0_read () = { + r : ICC_HPPIR0_Type = _ICC_HPPIR0; + r.bits[31 .. 0] = Slice(ICC_HPPIR0_EL1.bits, 0, 32); + return(r) +} + +val ICC_HPPIR0_write : ICC_HPPIR0_Type -> unit + +function ICC_HPPIR0_write value_name = { + let r : ICC_HPPIR0_Type = value_name; + ICC_HPPIR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_HPPIR0 = r; + return() +} + +val TTBCR2_NS_write : TTBCR2_Type -> unit + +function TTBCR2_NS_write value_name = { + let r : TTBCR2_Type = value_name; + TCR_EL1.bits[63 .. 32] = Slice(r.bits, 0, 32); + _TTBCR2_NS = r; + return() +} + +val TTBCR2_write : TTBCR2_Type -> unit + +function TTBCR2_write value_name = { + let r : TTBCR2_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + TTBCR2_S = r + } else { + TTBCR2_NS_write() = r + }; + return() +} + +bitfield ID_ISAR4_Type : bits(32) = + { + SWP_frac : 31..28, + PSR_M : 27..24, + SynchPrim_frac : 23..20, + Barrier : 19..16, + SMC : 15..12, + Writeback : 11..8, + WithShifts : 7..4, + Unpriv : 3..0 + } + +register _ID_ISAR4 : ID_ISAR4_Type + +val ID_ISAR4_read : unit -> ID_ISAR4_Type + +function ID_ISAR4_read () = { + r : ID_ISAR4_Type = _ID_ISAR4; + r.bits[31 .. 0] = Slice(ID_ISAR4_EL1.bits, 0, 32); + return(r) +} + +val ID_ISAR4_write : ID_ISAR4_Type -> unit + +function ID_ISAR4_write value_name = { + let r : ID_ISAR4_Type = value_name; + ID_ISAR4_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_ISAR4 = r; + return() +} + +bitfield PMCEID2_Type : bits(32) = + { + IDhi31 : 31..31, + IDhi30 : 30..30, + IDhi29 : 29..29, + IDhi28 : 28..28, + IDhi27 : 27..27, + IDhi26 : 26..26, + IDhi25 : 25..25, + IDhi24 : 24..24, + IDhi23 : 23..23, + IDhi22 : 22..22, + IDhi21 : 21..21, + IDhi20 : 20..20, + IDhi19 : 19..19, + IDhi18 : 18..18, + IDhi17 : 17..17, + IDhi16 : 16..16, + IDhi15 : 15..15, + IDhi14 : 14..14, + IDhi13 : 13..13, + IDhi12 : 12..12, + IDhi11 : 11..11, + IDhi10 : 10..10, + IDhi9 : 9..9, + IDhi8 : 8..8, + IDhi7 : 7..7, + IDhi6 : 6..6, + IDhi5 : 5..5, + IDhi4 : 4..4, + IDhi3 : 3..3, + IDhi2 : 2..2, + IDhi1 : 1..1, + IDhi0 : 0..0 + } + +register _PMCEID2 : PMCEID2_Type + +val PMCEID2_read : unit -> PMCEID2_Type + +function PMCEID2_read () = { + r : PMCEID2_Type = _PMCEID2; + r.bits[31 .. 0] = Slice(PMCEID0_EL0.bits, 32, 32); + return(r) +} + +val PMCEID2_write : PMCEID2_Type -> unit + +function PMCEID2_write value_name = { + let r : PMCEID2_Type = value_name; + PMCEID0_EL0.bits[63 .. 32] = Slice(r.bits, 0, 32); + _PMCEID2 = r; + return() +} + +val HSR_read : unit -> HSR_Type + +function HSR_read () = { + r : HSR_Type = _HSR; + r.bits[31 .. 0] = Slice(ESR_EL2.bits, 0, 32); + return(r) +} + +type FCSEIDR_Type = bits(32) + +register FCSEIDR : FCSEIDR_Type + +bitfield ID_DFR1_Type : bits(32) = {HPMN0 : 7..4, MTPMU : 3..0} + +register _ID_DFR1 : ID_DFR1_Type + +val ID_DFR1_read : unit -> ID_DFR1_Type + +function ID_DFR1_read () = { + r : ID_DFR1_Type = _ID_DFR1; + r.bits[31 .. 0] = Slice(ID_DFR1_EL1.bits, 0, 32); + return(r) +} + +val ID_DFR1_write : ID_DFR1_Type -> unit + +function ID_DFR1_write value_name = { + let r : ID_DFR1_Type = value_name; + ID_DFR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_DFR1 = r; + return() +} + +bitfield ICH_LR_Type : bits(32) = {vINTID : 31..0} + +register _ICH_LR : vector(16, ICH_LR_Type) + +val ICH_LR_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> ICH_LR_Type + +function ICH_LR_read n = { + r : ICH_LR_Type = _ICH_LR[n]; + r.bits[31 .. 0] = Slice(ICH_LR_EL2[n].bits, 0, 32); + return(r) +} + +val ICH_LR_set : forall 'n, (0 <= 'n & 'n < 16). (int('n), ICH_LR_Type) -> unit + +function ICH_LR_set (n, value_name) = { + let r : ICH_LR_Type = value_name; + ICH_LR_EL2[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_LR[n] = r; + return() +} + +type HADFSR_Type = bits(32) + +register _HADFSR : HADFSR_Type + +val HADFSR_read : unit -> HADFSR_Type + +function HADFSR_read () = { + r : HADFSR_Type = _HADFSR; + r[31 .. 0] = Slice(AFSR0_EL2, 0, 32); + return(r) +} + +val HADFSR_write : HADFSR_Type -> unit + +function HADFSR_write value_name = { + let r : HADFSR_Type = value_name; + AFSR0_EL2[31 .. 0] = Slice(r, 0, 32); + _HADFSR = r; + return() +} + +type JMCR_Type = bits(32) + +register JMCR : JMCR_Type + +val CNTKCTL_write : CNTKCTL_Type -> unit + +function CNTKCTL_write value_name = { + let r : CNTKCTL_Type = value_name; + CNTKCTL_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTKCTL = r; + return() +} + +bitfield ICV_PMR_Type : bits(32) = {Priority : 7..0} + +register _ICV_PMR : ICV_PMR_Type + +val ICV_PMR_read : unit -> ICV_PMR_Type + +function ICV_PMR_read () = { + r : ICV_PMR_Type = _ICV_PMR; + r.bits[31 .. 0] = Slice(ICV_PMR_EL1.bits, 0, 32); + return(r) +} + +val ICV_PMR_write : ICV_PMR_Type -> unit + +function ICV_PMR_write value_name = { + let r : ICV_PMR_Type = value_name; + ICV_PMR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_PMR = r; + return() +} + +bitfield ICV_HPPIR0_Type : bits(32) = {INTID : 23..0} + +register _ICV_HPPIR0 : ICV_HPPIR0_Type + +val ICV_HPPIR0_read : unit -> ICV_HPPIR0_Type + +function ICV_HPPIR0_read () = { + r : ICV_HPPIR0_Type = _ICV_HPPIR0; + r.bits[31 .. 0] = Slice(ICV_HPPIR0_EL1.bits, 0, 32); + return(r) +} + +val ICV_HPPIR0_write : ICV_HPPIR0_Type -> unit + +function ICV_HPPIR0_write value_name = { + let r : ICV_HPPIR0_Type = value_name; + ICV_HPPIR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_HPPIR0 = r; + return() +} + +val DBGBCR_set : forall 'n, (0 <= 'n & 'n < 16). (int('n), DBGBCR_Type) -> unit + +function DBGBCR_set (n, value_name) = { + let r : DBGBCR_Type = value_name; + DBGBCR_EL1[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGBCR[n] = r; + return() +} + +type DBGWFAR_Type = bits(32) + +register DBGWFAR : DBGWFAR_Type + +val HSCTLR_write : HSCTLR_Type -> unit + +function HSCTLR_write value_name = { + let r : HSCTLR_Type = value_name; + SCTLR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HSCTLR = r; + return() +} + +val __set_HSCTLR : HSCTLR_Type -> unit + +function __set_HSCTLR value_name = { + let r : HSCTLR_Type = value_name; + HSCTLR_write() = Mk_HSCTLR_Type(SetSlice(5, HSCTLR_read().bits, 0, Slice(r.bits, 0, 5))); + HSCTLR_write() = Mk_HSCTLR_Type(SetSlice(1, HSCTLR_read().bits, 6, Slice(r.bits, 6, 1))); + HSCTLR_write() = Mk_HSCTLR_Type(SetSlice(24, HSCTLR_read().bits, 8, Slice(r.bits, 8, 24))); + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD"))) then { + HSCTLR_write() = [HSCTLR_read() with ITD = r[ITD]] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN"))) then { + HSCTLR_write() = [HSCTLR_read() with CP15BEN = r[CP15BEN]] + }; + return() +} + +bitfield ID_ISAR3_Type : bits(32) = + { + T32EE : 31..28, + TrueNOP : 27..24, + T32Copy : 23..20, + TabBranch : 19..16, + SynchPrim : 15..12, + SVC : 11..8, + SIMD : 7..4, + Saturate : 3..0 + } + +register _ID_ISAR3 : ID_ISAR3_Type + +val ID_ISAR3_read : unit -> ID_ISAR3_Type + +function ID_ISAR3_read () = { + r : ID_ISAR3_Type = _ID_ISAR3; + r.bits[31 .. 0] = Slice(ID_ISAR3_EL1.bits, 0, 32); + return(r) +} + +val ID_ISAR3_write : ID_ISAR3_Type -> unit + +function ID_ISAR3_write value_name = { + let r : ID_ISAR3_Type = value_name; + ID_ISAR3_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_ISAR3 = r; + return() +} + +val VTCR_write : VTCR_Type -> unit + +function VTCR_write value_name = { + let r : VTCR_Type = value_name; + VTCR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _VTCR = r; + return() +} + +bitfield ICC_MGRPEN1_Type : bits(32) = {EnableGrp1S : 1..1, EnableGrp1NS : 0..0} + +register ICC_MGRPEN1 : ICC_MGRPEN1_Type + +bitfield TLBTR_Type : bits(32) = {nU : 0..0} + +register TLBTR : TLBTR_Type + +type CNTFRQ_Type = bits(32) + +register _CNTFRQ : CNTFRQ_Type + +val CNTFRQ_read : unit -> CNTFRQ_Type + +function CNTFRQ_read () = { + r : CNTFRQ_Type = _CNTFRQ; + r[31 .. 0] = Slice(CNTFRQ_EL0, 0, 32); + return(r) +} + +val CNTFRQ_write : CNTFRQ_Type -> unit + +function CNTFRQ_write value_name = { + let r : CNTFRQ_Type = value_name; + CNTFRQ_EL0[31 .. 0] = Slice(r, 0, 32); + _CNTFRQ = r; + return() +} + +bitfield PMINTENSET_Type : bits(32) = + { + C : 31..31, + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMINTENSET : PMINTENSET_Type + +val PMINTENSET_read : unit -> PMINTENSET_Type + +function PMINTENSET_read () = { + r : PMINTENSET_Type = _PMINTENSET; + r.bits[31 .. 0] = Slice(PMINTENSET_EL1.bits, 0, 32); + return(r) +} + +val PMINTENSET_write : PMINTENSET_Type -> unit + +function PMINTENSET_write value_name = { + let r : PMINTENSET_Type = value_name; + PMINTENSET_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMINTENSET = r; + return() +} + +bitfield DBGDEVID_Type : bits(32) = + { + CIDMask : 31..28, + AuxRegs : 27..24, + DoubleLock : 23..20, + VirtExtns : 19..16, + VectorCatch : 15..12, + BPAddrMask : 11..8, + WPAddrMask : 7..4, + PCSample : 3..0 + } + +register DBGDEVID : DBGDEVID_Type + +val DFSR_NS_read : unit -> DFSR_Type + +function DFSR_NS_read () = { + r : DFSR_Type = _DFSR_NS; + r.bits[31 .. 0] = Slice(ESR_EL1.bits, 0, 32); + return(r) +} + +val DFSR_read : unit -> DFSR_Type + +function DFSR_read () = { + r : DFSR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = DFSR_S + } else { + r = DFSR_NS_read() + }; + return(r) +} + +bitfield DBGOSECCR_Type : bits(32) = {EDECCR : 31..0} + +register _DBGOSECCR : DBGOSECCR_Type + +val DBGOSECCR_read : unit -> DBGOSECCR_Type + +function DBGOSECCR_read () = { + r : DBGOSECCR_Type = _DBGOSECCR; + r.bits[31 .. 0] = Slice(OSECCR_EL1.bits, 0, 32); + return(r) +} + +val DBGOSECCR_write : DBGOSECCR_Type -> unit + +function DBGOSECCR_write value_name = { + let r : DBGOSECCR_Type = value_name; + OSECCR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGOSECCR = r; + return() +} + +bitfield CCSIDR2_Type : bits(32) = {NumSets : 23..0} + +register _CCSIDR2 : CCSIDR2_Type + +val CCSIDR2_read : unit -> CCSIDR2_Type + +function CCSIDR2_read () = { + r : CCSIDR2_Type = _CCSIDR2; + r.bits[31 .. 0] = Slice(CCSIDR2_EL1.bits, 0, 32); + return(r) +} + +val CCSIDR2_write : CCSIDR2_Type -> unit + +function CCSIDR2_write value_name = { + let r : CCSIDR2_Type = value_name; + CCSIDR2_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CCSIDR2 = r; + return() +} + +bitfield CNTHV_CTL_Type : bits(32) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register _CNTHV_CTL : CNTHV_CTL_Type + +val CNTHV_CTL_read : unit -> CNTHV_CTL_Type + +function CNTHV_CTL_read () = { + r : CNTHV_CTL_Type = _CNTHV_CTL; + r.bits[31 .. 0] = Slice(CNTHV_CTL_EL2.bits, 0, 32); + return(r) +} + +val CNTHV_CTL_write : CNTHV_CTL_Type -> unit + +function CNTHV_CTL_write value_name = { + let r : CNTHV_CTL_Type = value_name; + CNTHV_CTL_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTHV_CTL = r; + return() +} + +bitfield ICH_MISR_Type : bits(32) = + { + VGrp1D : 7..7, + VGrp1E : 6..6, + VGrp0D : 5..5, + VGrp0E : 4..4, + NP : 3..3, + LRENP : 2..2, + U : 1..1, + EOI : 0..0 + } + +register _ICH_MISR : ICH_MISR_Type + +val ICH_MISR_read : unit -> ICH_MISR_Type + +function ICH_MISR_read () = { + r : ICH_MISR_Type = _ICH_MISR; + r.bits[31 .. 0] = Slice(ICH_MISR_EL2.bits, 0, 32); + return(r) +} + +val ICH_MISR_write : ICH_MISR_Type -> unit + +function ICH_MISR_write value_name = { + let r : ICH_MISR_Type = value_name; + ICH_MISR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICH_MISR = r; + return() +} + +type ACTLR2_Type = bits(32) + +register ACTLR2_S : ACTLR2_Type + +register _ACTLR2_NS : ACTLR2_Type + +val ACTLR2_NS_read : unit -> ACTLR2_Type + +function ACTLR2_NS_read () = { + r : ACTLR2_Type = _ACTLR2_NS; + r[31 .. 0] = Slice(ACTLR_EL1, 32, 32); + return(r) +} + +val ACTLR2_NS_write : ACTLR2_Type -> unit + +function ACTLR2_NS_write value_name = { + let r : ACTLR2_Type = value_name; + ACTLR_EL1[63 .. 32] = Slice(r, 0, 32); + _ACTLR2_NS = r; + return() +} + +val ACTLR2_read : unit -> ACTLR2_Type + +function ACTLR2_read () = { + r : ACTLR2_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ACTLR2_S + } else { + r = ACTLR2_NS_read() + }; + return(r) +} + +val ACTLR2_write : ACTLR2_Type -> unit + +function ACTLR2_write value_name = { + let r : ACTLR2_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ACTLR2_S = r + } else { + ACTLR2_NS_write() = r + }; + return() +} + +val CPACR_write : CPACR_Type -> unit + +function CPACR_write value_name = { + let r : CPACR_Type = value_name; + CPACR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CPACR = r; + return() +} + +val __set_CPACR : CPACR_Type -> unit + +function __set_CPACR value_name = { + let r : CPACR_Type = value_name; + CPACR_write() = Mk_CPACR_Type(SetSlice(20, CPACR_read__1().bits, 0, Slice(r.bits, 0, 20))); + CPACR_write() = Mk_CPACR_Type(SetSlice(8, CPACR_read__1().bits, 24, Slice(r.bits, 24, 8))); + if not_bool(((HaveEL(EL3) & ELUsingAArch32(EL3)) & not_bool(IsCurrentSecurityState(SS_Secure))) & NSACR[cp10] == 0b0) then { + CPACR_write() = [CPACR_read__1() with cp11 = r[cp11]] + }; + if not_bool(((HaveEL(EL3) & ELUsingAArch32(EL3)) & not_bool(IsCurrentSecurityState(SS_Secure))) & NSACR[cp10] == 0b0) then { + CPACR_write() = [CPACR_read__1() with cp10 = r[cp10]] + }; + return() +} + +bitfield ICV_IAR0_Type : bits(32) = {INTID : 23..0} + +register _ICV_IAR0 : ICV_IAR0_Type + +val ICV_IAR0_read : unit -> ICV_IAR0_Type + +function ICV_IAR0_read () = { + r : ICV_IAR0_Type = _ICV_IAR0; + r.bits[31 .. 0] = Slice(ICV_IAR0_EL1.bits, 0, 32); + return(r) +} + +val ICV_IAR0_write : ICV_IAR0_Type -> unit + +function ICV_IAR0_write value_name = { + let r : ICV_IAR0_Type = value_name; + ICV_IAR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_IAR0 = r; + return() +} + +bitfield ID_MMFR2_Type : bits(32) = + { + HWAccFlg : 31..28, + WFIStall : 27..24, + MemBarr : 23..20, + UniTLB : 19..16, + HvdTLB : 15..12, + L1HvdRng : 11..8, + L1HvdBG : 7..4, + L1HvdFG : 3..0 + } + +register _ID_MMFR2 : ID_MMFR2_Type + +val ID_MMFR2_read : unit -> ID_MMFR2_Type + +function ID_MMFR2_read () = { + r : ID_MMFR2_Type = _ID_MMFR2; + r.bits[31 .. 0] = Slice(ID_MMFR2_EL1.bits, 0, 32); + return(r) +} + +val ID_MMFR2_write : ID_MMFR2_Type -> unit + +function ID_MMFR2_write value_name = { + let r : ID_MMFR2_Type = value_name; + ID_MMFR2_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_MMFR2 = r; + return() +} + +type HAMAIR1_Type = bits(32) + +register _HAMAIR1 : HAMAIR1_Type + +val HAMAIR1_read : unit -> HAMAIR1_Type + +function HAMAIR1_read () = { + r : HAMAIR1_Type = _HAMAIR1; + r[31 .. 0] = Slice(AMAIR_EL2, 32, 32); + return(r) +} + +val HAMAIR1_write : HAMAIR1_Type -> unit + +function HAMAIR1_write value_name = { + let r : HAMAIR1_Type = value_name; + AMAIR_EL2[63 .. 32] = Slice(r, 0, 32); + _HAMAIR1 = r; + return() +} + +bitfield ISR_Type : bits(32) = {A : 8..8, I : 7..7, F : 6..6} + +register _ISR : ISR_Type + +val ISR_read : unit -> ISR_Type + +function ISR_read () = { + r : ISR_Type = _ISR; + r.bits[31 .. 0] = Slice(ISR_EL1.bits, 0, 32); + return(r) +} + +val ISR_write : ISR_Type -> unit + +function ISR_write value_name = { + let r : ISR_Type = value_name; + ISR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ISR = r; + return() +} + +type HAIFSR_Type = bits(32) + +register _HAIFSR : HAIFSR_Type + +val HAIFSR_read : unit -> HAIFSR_Type + +function HAIFSR_read () = { + r : HAIFSR_Type = _HAIFSR; + r[31 .. 0] = Slice(AFSR1_EL2, 0, 32); + return(r) +} + +val HAIFSR_write : HAIFSR_Type -> unit + +function HAIFSR_write value_name = { + let r : HAIFSR_Type = value_name; + AFSR1_EL2[31 .. 0] = Slice(r, 0, 32); + _HAIFSR = r; + return() +} + +val __set_SCTLR_S : SCTLR_Type -> unit + +function __set_SCTLR_S value_name = { + let r : SCTLR_Type = value_name; + SCTLR_S.bits[4 .. 0] = Slice(r.bits, 0, 5); + SCTLR_S.bits[6] = Bit(Slice(r.bits, 6, 1)); + SCTLR_S.bits[31 .. 8] = Slice(r.bits, 8, 24); + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD"))) then { + SCTLR_S[ITD] = r[ITD] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN"))) then { + SCTLR_S[CP15BEN] = r[CP15BEN] + }; + return() +} + +val SCTLR_NS_write : SCTLR_Type -> unit + +function SCTLR_NS_write value_name = { + let r : SCTLR_Type = value_name; + SCTLR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _SCTLR_NS = r; + return() +} + +val __set_SCTLR_NS : SCTLR_Type -> unit + +function __set_SCTLR_NS value_name = { + let r : SCTLR_Type = value_name; + SCTLR_NS_write() = Mk_SCTLR_Type(SetSlice(5, SCTLR_NS_read().bits, 0, Slice(r.bits, 0, 5))); + SCTLR_NS_write() = Mk_SCTLR_Type(SetSlice(1, SCTLR_NS_read().bits, 6, Slice(r.bits, 6, 1))); + SCTLR_NS_write() = Mk_SCTLR_Type(SetSlice(24, SCTLR_NS_read().bits, 8, Slice(r.bits, 8, 24))); + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD"))) then { + SCTLR_NS_write() = [SCTLR_NS_read() with ITD = r[ITD]] + }; + if not_bool(not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN"))) then { + SCTLR_NS_write() = [SCTLR_NS_read() with CP15BEN = r[CP15BEN]] + }; + return() +} + +val SCTLR_write : SCTLR_Type -> unit + +function SCTLR_write value_name = { + let r : SCTLR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + SCTLR_S = r + } else { + SCTLR_NS_write() = r + }; + return() +} + +val __set_SCTLR : SCTLR_Type -> unit + +function __set_SCTLR value_name = { + let r : SCTLR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + __set_SCTLR_S(r) + } else { + __set_SCTLR_NS(r) + }; + return() +} + +bitfield ID_PFR0_Type : bits(32) = + { + RAS : 31..28, + DIT : 27..24, + AMU : 23..20, + CSV2 : 19..16, + State3 : 15..12, + State2 : 11..8, + State1 : 7..4, + State0 : 3..0 + } + +register _ID_PFR0 : ID_PFR0_Type + +val ID_PFR0_read : unit -> ID_PFR0_Type + +function ID_PFR0_read () = { + r : ID_PFR0_Type = _ID_PFR0; + r.bits[31 .. 0] = Slice(ID_PFR0_EL1.bits, 0, 32); + return(r) +} + +val ID_PFR0_write : ID_PFR0_Type -> unit + +function ID_PFR0_write value_name = { + let r : ID_PFR0_Type = value_name; + ID_PFR0_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_PFR0 = r; + return() +} + +val DBGDCCINT_write : DBGDCCINT_Type -> unit + +function DBGDCCINT_write value_name = { + let r : DBGDCCINT_Type = value_name; + MDCCINT_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGDCCINT = r; + return() +} + +val __set_DBGDSCRext : DBGDSCRext_Type -> unit + +function __set_DBGDSCRext value_name = { + let r : DBGDSCRext_Type = value_name; + DBGDSCRext_write() = Mk_DBGDSCRext_Type(SetSlice(6, DBGDSCRext_read().bits, 0, Slice(r.bits, 0, 6))); + DBGDSCRext_write() = Mk_DBGDSCRext_Type(SetSlice(7, DBGDSCRext_read().bits, 7, Slice(r.bits, 7, 7))); + DBGDSCRext_write() = Mk_DBGDSCRext_Type(SetSlice(1, DBGDSCRext_read().bits, 15, Slice(r.bits, 15, 1))); + DBGDSCRext_write() = Mk_DBGDSCRext_Type(SetSlice(1, DBGDSCRext_read().bits, 20, Slice(r.bits, 20, 1))); + DBGDSCRext_write() = Mk_DBGDSCRext_Type(SetSlice(2, DBGDSCRext_read().bits, 24, Slice(r.bits, 24, 2))); + DBGDSCRext_write() = Mk_DBGDSCRext_Type(SetSlice(1, DBGDSCRext_read().bits, 28, Slice(r.bits, 28, 1))); + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with TFO = r[TFO]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with RXfull = r[RXfull]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with TXfull = r[TXfull]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with RXO = r[RXO]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with TXU = r[TXU]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with INTdis = r[INTdis]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with TDA = r[TDA]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with SC2 = r[SC2]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with HDE = r[HDE]] + }; + if DBGOSLSR_read()[OSLK] == 0b1 then { + DBGDSCRext_write() = [DBGDSCRext_read() with ERR = r[ERR]] + }; + return() +} + +val IFSR_NS_read : unit -> IFSR_Type + +function IFSR_NS_read () = { + r : IFSR_Type = _IFSR_NS; + r.bits[31 .. 0] = Slice(IFSR32_EL2.bits, 0, 32); + return(r) +} + +val IFSR_read : unit -> IFSR_Type + +function IFSR_read () = { + r : IFSR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = IFSR_S + } else { + r = IFSR_NS_read() + }; + return(r) +} + +val ELR_hyp_read : unit -> ELR_hyp_Type + +function ELR_hyp_read () = { + r : ELR_hyp_Type = _ELR_hyp; + r[31 .. 0] = Slice(ELR_EL2, 0, 32); + return(r) +} + +bitfield MIDR_Type : bits(32) = + { + Implementer : 31..24, + Variant : 23..20, + Architecture : 19..16, + PartNum : 15..4, + Revision : 3..0 + } + +register _MIDR : MIDR_Type + +val MIDR_read : unit -> MIDR_Type + +function MIDR_read () = { + r : MIDR_Type = _MIDR; + r.bits[31 .. 0] = Slice(MIDR_EL1.bits, 0, 32); + return(r) +} + +val MIDR_write : MIDR_Type -> unit + +function MIDR_write value_name = { + let r : MIDR_Type = value_name; + MIDR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _MIDR = r; + return() +} + +type ICC_AP0R_Type = bits(32) + +register _ICC_AP0R : vector(4, ICC_AP0R_Type) + +val ICC_AP0R_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> ICC_AP0R_Type + +function ICC_AP0R_read n = { + r : ICC_AP0R_Type = _ICC_AP0R[n]; + r[31 .. 0] = Slice(ICC_AP0R_EL1[n], 0, 32); + return(r) +} + +val ICC_AP0R_set : forall 'n, (0 <= 'n & 'n < 4). + (int('n), ICC_AP0R_Type) -> unit + +function ICC_AP0R_set (n, value_name) = { + let r : ICC_AP0R_Type = value_name; + ICC_AP0R_EL1[n][31 .. 0] = Slice(r, 0, 32); + _ICC_AP0R[n] = r; + return() +} + +bitfield DBGDIDR_Type : bits(32) = + { + WRPs : 31..28, + BRPs : 27..24, + CTX_CMPs : 23..20, + Version : 19..16, + nSUHD_imp : 14..14, + SE_imp : 12..12 + } + +register DBGDIDR : DBGDIDR_Type + +val __set_CNTP_CTL_S : CNTP_CTL_Type -> unit + +function __set_CNTP_CTL_S value_name = { + let r : CNTP_CTL_Type = value_name; + CNTP_CTL_S.bits[1 .. 0] = Slice(r.bits, 0, 2); + CNTP_CTL_S.bits[31 .. 3] = Slice(r.bits, 3, 29); + return() +} + +val __set_CNTP_CTL_NS : CNTP_CTL_Type -> unit + +function __set_CNTP_CTL_NS value_name = { + let r : CNTP_CTL_Type = value_name; + CNTP_CTL_NS_write() = Mk_CNTP_CTL_Type(SetSlice(2, CNTP_CTL_NS_read().bits, 0, Slice(r.bits, 0, 2))); + CNTP_CTL_NS_write() = Mk_CNTP_CTL_Type(SetSlice(29, CNTP_CTL_NS_read().bits, 3, Slice(r.bits, 3, 29))); + return() +} + +val __set_CNTP_CTL : CNTP_CTL_Type -> unit + +function __set_CNTP_CTL value_name = { + let r : CNTP_CTL_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + __set_CNTP_CTL_S(r) + } else { + __set_CNTP_CTL_NS(r) + }; + return() +} + +type TPIDRPRW_Type = bits(32) + +register TPIDRPRW_S : TPIDRPRW_Type + +register _TPIDRPRW_NS : TPIDRPRW_Type + +val TPIDRPRW_NS_read : unit -> TPIDRPRW_Type + +function TPIDRPRW_NS_read () = { + r : TPIDRPRW_Type = _TPIDRPRW_NS; + r[31 .. 0] = Slice(TPIDR_EL1, 0, 32); + return(r) +} + +val TPIDRPRW_NS_write : TPIDRPRW_Type -> unit + +function TPIDRPRW_NS_write value_name = { + let r : TPIDRPRW_Type = value_name; + TPIDR_EL1[31 .. 0] = Slice(r, 0, 32); + _TPIDRPRW_NS = r; + return() +} + +val TPIDRPRW_read : unit -> TPIDRPRW_Type + +function TPIDRPRW_read () = { + r : TPIDRPRW_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = TPIDRPRW_S + } else { + r = TPIDRPRW_NS_read() + }; + return(r) +} + +val TPIDRPRW_write : TPIDRPRW_Type -> unit + +function TPIDRPRW_write value_name = { + let r : TPIDRPRW_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + TPIDRPRW_S = r + } else { + TPIDRPRW_NS_write() = r + }; + return() +} + +val IFAR_S_read : unit -> IFAR_Type + +function IFAR_S_read () = { + r : IFAR_Type = _IFAR_S; + if HaveEL(EL2) then { + r[31 .. 0] = Slice(FAR_EL2, 32, 32) + } else { + r[31 .. 0] = Slice(HIFAR_read(), 0, 32) + }; + return(r) +} + +val IFAR_NS_read : unit -> IFAR_Type + +function IFAR_NS_read () = { + r : IFAR_Type = _IFAR_NS; + r[31 .. 0] = Slice(FAR_EL1, 32, 32); + return(r) +} + +val IFAR_read : unit -> IFAR_Type + +function IFAR_read () = { + r : IFAR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = IFAR_S_read() + } else { + r = IFAR_NS_read() + }; + return(r) +} + +val HTRFCR_write : HTRFCR_Type -> unit + +function HTRFCR_write value_name = { + let r : HTRFCR_Type = value_name; + TRFCR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _HTRFCR = r; + return() +} + +bitfield DBGDTRRXint_Type : bits(32) = {DTRRX : 31..0} + +register _DBGDTRRXint : DBGDTRRXint_Type + +val DBGDTRRXint_read : unit -> DBGDTRRXint_Type + +function DBGDTRRXint_read () = { + r : DBGDTRRXint_Type = _DBGDTRRXint; + r.bits[31 .. 0] = Slice(DBGDTRRX_EL0, 0, 32); + return(r) +} + +bitfield VPIDR_Type : bits(32) = + { + Implementer : 31..24, + Variant : 23..20, + Architecture : 19..16, + PartNum : 15..4, + Revision : 3..0 + } + +register _VPIDR : VPIDR_Type + +val VPIDR_read : unit -> VPIDR_Type + +function VPIDR_read () = { + r : VPIDR_Type = _VPIDR; + r.bits[31 .. 0] = Slice(VPIDR_EL2.bits, 0, 32); + return(r) +} + +val VPIDR_write : VPIDR_Type -> unit + +function VPIDR_write value_name = { + let r : VPIDR_Type = value_name; + VPIDR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _VPIDR = r; + return() +} + +bitfield PMSWINC_Type : bits(32) = + { + P30 : 30..30, + P29 : 29..29, + P28 : 28..28, + P27 : 27..27, + P26 : 26..26, + P25 : 25..25, + P24 : 24..24, + P23 : 23..23, + P22 : 22..22, + P21 : 21..21, + P20 : 20..20, + P19 : 19..19, + P18 : 18..18, + P17 : 17..17, + P16 : 16..16, + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _PMSWINC : PMSWINC_Type + +val PMSWINC_read : unit -> PMSWINC_Type + +function PMSWINC_read () = { + r : PMSWINC_Type = _PMSWINC; + r.bits[31 .. 0] = Slice(PMSWINC_EL0.bits, 0, 32); + return(r) +} + +val PMSWINC_write : PMSWINC_Type -> unit + +function PMSWINC_write value_name = { + let r : PMSWINC_Type = value_name; + PMSWINC_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMSWINC = r; + return() +} + +val PMEVTYPER_set : forall 'n, (0 <= 'n & 'n < 31). + (int('n), PMEVTYPER_Type) -> unit + +function PMEVTYPER_set (n, value_name) = { + let r : PMEVTYPER_Type = value_name; + PMEVTYPER_EL0[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMEVTYPER[n] = r; + return() +} + +val __get_selected_PMEVTYPER : unit -> PMEVTYPER_Type + +function __get_selected_PMEVTYPER () = { + let 'idx = UInt(PMSELR_read()[SEL]); + assert(idx <= 30); + return(PMEVTYPER_read(idx)) +} + +val __set_selected_PMEVTYPER : PMEVTYPER_Type -> unit + +function __set_selected_PMEVTYPER value_name = { + let 'idx = UInt(PMSELR_read()[SEL]); + assert(idx <= 30); + PMEVTYPER_set(idx) = value_name; + return() +} + +bitfield CNTV_CTL_Type : bits(32) = + {ISTATUS : 2..2, IMASK : 1..1, ENABLE : 0..0} + +register _CNTV_CTL : CNTV_CTL_Type + +val CNTV_CTL_read : unit -> CNTV_CTL_Type + +function CNTV_CTL_read () = { + r : CNTV_CTL_Type = _CNTV_CTL; + r.bits[31 .. 0] = Slice(CNTV_CTL_EL0.bits, 0, 32); + return(r) +} + +val CNTV_CTL_write : CNTV_CTL_Type -> unit + +function CNTV_CTL_write value_name = { + let r : CNTV_CTL_Type = value_name; + CNTV_CTL_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CNTV_CTL = r; + return() +} + +val __set_CNTV_CTL : CNTV_CTL_Type -> unit + +function __set_CNTV_CTL value_name = { + let r : CNTV_CTL_Type = value_name; + CNTV_CTL_write() = Mk_CNTV_CTL_Type(SetSlice(2, CNTV_CTL_read().bits, 0, Slice(r.bits, 0, 2))); + CNTV_CTL_write() = Mk_CNTV_CTL_Type(SetSlice(29, CNTV_CTL_read().bits, 3, Slice(r.bits, 3, 29))); + return() +} + +type HTPIDR_Type = bits(32) + +register _HTPIDR : HTPIDR_Type + +val HTPIDR_read : unit -> HTPIDR_Type + +function HTPIDR_read () = { + r : HTPIDR_Type = _HTPIDR; + r[31 .. 0] = Slice(TPIDR_EL2, 0, 32); + return(r) +} + +val HTPIDR_write : HTPIDR_Type -> unit + +function HTPIDR_write value_name = { + let r : HTPIDR_Type = value_name; + TPIDR_EL2[31 .. 0] = Slice(r, 0, 32); + _HTPIDR = r; + return() +} + +val CONTEXTIDR_NS_write : CONTEXTIDR_Type -> unit + +function CONTEXTIDR_NS_write value_name = { + let r : CONTEXTIDR_Type = value_name; + CONTEXTIDR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CONTEXTIDR_NS = r; + return() +} + +val CONTEXTIDR_write : CONTEXTIDR_Type -> unit + +function CONTEXTIDR_write value_name = { + let r : CONTEXTIDR_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + CONTEXTIDR_S = r + } else { + CONTEXTIDR_NS_write() = r + }; + return() +} + +val DFAR_S_read : unit -> DFAR_Type + +function DFAR_S_read () = { + r : DFAR_Type = _DFAR_S; + r[31 .. 0] = Slice(HDFAR_read(), 0, 32); + return(r) +} + +val DFAR_NS_read : unit -> DFAR_Type + +function DFAR_NS_read () = { + r : DFAR_Type = _DFAR_NS; + r[31 .. 0] = Slice(FAR_EL1, 0, 32); + return(r) +} + +val DFAR_read : unit -> DFAR_Type + +function DFAR_read () = { + r : DFAR_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = DFAR_S_read() + } else { + r = DFAR_NS_read() + }; + return(r) +} + +val PMCNTENCLR_write : PMCNTENCLR_Type -> unit + +function PMCNTENCLR_write value_name = { + let r : PMCNTENCLR_Type = value_name; + PMCNTENCLR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _PMCNTENCLR = r; + return() +} + +bitfield ID_ISAR2_Type : bits(32) = + { + Reversal : 31..28, + PSR_AR : 27..24, + MultU : 23..20, + MultS : 19..16, + Mult : 15..12, + MultiAccessInt : 11..8, + MemHint : 7..4, + LoadStore : 3..0 + } + +register _ID_ISAR2 : ID_ISAR2_Type + +val ID_ISAR2_read : unit -> ID_ISAR2_Type + +function ID_ISAR2_read () = { + r : ID_ISAR2_Type = _ID_ISAR2; + r.bits[31 .. 0] = Slice(ID_ISAR2_EL1.bits, 0, 32); + return(r) +} + +val ID_ISAR2_write : ID_ISAR2_Type -> unit + +function ID_ISAR2_write value_name = { + let r : ID_ISAR2_Type = value_name; + ID_ISAR2_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_ISAR2 = r; + return() +} + +val DBGOSLSR_write : DBGOSLSR_Type -> unit + +function DBGOSLSR_write value_name = { + let r : DBGOSLSR_Type = value_name; + OSLSR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _DBGOSLSR = r; + return() +} + +bitfield DBGDTRTXint_Type : bits(32) = {DTRTX : 31..0} + +register _DBGDTRTXint : DBGDTRTXint_Type + +val DBGDTRTXint_write : DBGDTRTXint_Type -> unit + +function DBGDTRTXint_write value_name = { + let r : DBGDTRTXint_Type = value_name; + DBGDTRTX_EL0[31 .. 0] = Slice(r.bits, 0, 32); + _DBGDTRTXint = r; + return() +} + +val TRFCR_write : TRFCR_Type -> unit + +function TRFCR_write value_name = { + let r : TRFCR_Type = value_name; + TRFCR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _TRFCR = r; + return() +} + +val __set_CNTHP_CTL : CNTHP_CTL_Type -> unit + +function __set_CNTHP_CTL value_name = { + let r : CNTHP_CTL_Type = value_name; + CNTHP_CTL_write() = Mk_CNTHP_CTL_Type(SetSlice(2, CNTHP_CTL_read().bits, 0, Slice(r.bits, 0, 2))); + CNTHP_CTL_write() = Mk_CNTHP_CTL_Type(SetSlice(29, CNTHP_CTL_read().bits, 3, Slice(r.bits, 3, 29))); + return() +} + +type AMAIR1_Type = bits(32) + +register AMAIR1_S : AMAIR1_Type + +register _AMAIR1_NS : AMAIR1_Type + +val AMAIR1_NS_read : unit -> AMAIR1_Type + +function AMAIR1_NS_read () = { + r : AMAIR1_Type = _AMAIR1_NS; + r[31 .. 0] = Slice(AMAIR_EL1, 32, 32); + return(r) +} + +val AMAIR1_NS_write : AMAIR1_Type -> unit + +function AMAIR1_NS_write value_name = { + let r : AMAIR1_Type = value_name; + AMAIR_EL1[63 .. 32] = Slice(r, 0, 32); + _AMAIR1_NS = r; + return() +} + +val AMAIR1_read : unit -> AMAIR1_Type + +function AMAIR1_read () = { + r : AMAIR1_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = AMAIR1_S + } else { + r = AMAIR1_NS_read() + }; + return(r) +} + +val AMAIR1_write : AMAIR1_Type -> unit + +function AMAIR1_write value_name = { + let r : AMAIR1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + AMAIR1_S = r + } else { + AMAIR1_NS_write() = r + }; + return() +} + +bitfield CCSIDR_Type : bits(32) = + {NumSets : 27..13, Associativity : 23..3, LineSize : 2..0} + +register _CCSIDR : CCSIDR_Type + +val CCSIDR_read : unit -> CCSIDR_Type + +function CCSIDR_read () = { + r : CCSIDR_Type = _CCSIDR; + r.bits[31 .. 0] = Slice(CCSIDR_EL1.bits, 0, 32); + return(r) +} + +val CCSIDR_write : CCSIDR_Type -> unit + +function CCSIDR_write value_name = { + let r : CCSIDR_Type = value_name; + CCSIDR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _CCSIDR = r; + return() +} + +type DBGDEVID2_Type = bits(32) + +register DBGDEVID2 : DBGDEVID2_Type + +bitfield ICV_DIR_Type : bits(32) = {INTID : 23..0} + +register _ICV_DIR : ICV_DIR_Type + +val ICV_DIR_read : unit -> ICV_DIR_Type + +function ICV_DIR_read () = { + r : ICV_DIR_Type = _ICV_DIR; + r.bits[31 .. 0] = Slice(ICV_DIR_EL1.bits, 0, 32); + return(r) +} + +val ICV_DIR_write : ICV_DIR_Type -> unit + +function ICV_DIR_write value_name = { + let r : ICV_DIR_Type = value_name; + ICV_DIR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICV_DIR = r; + return() +} + +bitfield MPIDR_Type : bits(32) = + { + M : 31..31, + U : 30..30, + MT : 24..24, + Aff2 : 23..16, + Aff1 : 15..8, + Aff0 : 7..0 + } + +register _MPIDR : MPIDR_Type + +val MPIDR_read : unit -> MPIDR_Type + +function MPIDR_read () = { + r : MPIDR_Type = _MPIDR; + r.bits[31 .. 0] = Slice(MPIDR_EL1.bits, 0, 32); + return(r) +} + +val MPIDR_write : MPIDR_Type -> unit + +function MPIDR_write value_name = { + let r : MPIDR_Type = value_name; + MPIDR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _MPIDR = r; + return() +} + +bitfield ICH_LRC_Type : bits(32) = + { + State : 31..30, + HW : 29..29, + Group : 28..28, + Priority : 23..16, + pINTID : 12..0 + } + +register _ICH_LRC : vector(16, ICH_LRC_Type) + +val ICH_LRC_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> ICH_LRC_Type + +function ICH_LRC_read n = { + r : ICH_LRC_Type = _ICH_LRC[n]; + r.bits[31 .. 0] = Slice(ICH_LR_EL2[n].bits, 32, 32); + return(r) +} + +val ICH_LRC_set : forall 'n, (0 <= 'n & 'n < 16). + (int('n), ICH_LRC_Type) -> unit + +function ICH_LRC_set (n, value_name) = { + let r : ICH_LRC_Type = value_name; + ICH_LR_EL2[n].bits[63 .. 32] = Slice(r.bits, 0, 32); + _ICH_LRC[n] = r; + return() +} + +val MAIR1_S_write : MAIR1_Type -> unit + +function MAIR1_S_write value_name = { + let r : MAIR1_Type = value_name; + NMRR_S.bits[31 .. 0] = Slice(r.bits, 0, 32); + _MAIR1_S = r; + return() +} + +val MAIR1_NS_write : MAIR1_Type -> unit + +function MAIR1_NS_write value_name = { + let r : MAIR1_Type = value_name; + if ELUsingAArch32(EL3) then { + NMRR_NS_write() = Mk_NMRR_Type(SetSlice(32, NMRR_NS_read().bits, 0, Slice(r.bits, 0, 32))) + } else { + if not_bool(HaveEL(EL3)) | not_bool(ELUsingAArch32(EL3)) then { + MAIR_EL1.bits[63 .. 32] = Slice(r.bits, 0, 32) + } else { + NMRR_write() = Mk_NMRR_Type(SetSlice(32, NMRR_read().bits, 0, Slice(r.bits, 0, 32))) + } + }; + _MAIR1_NS = r; + return() +} + +val MAIR1_write : MAIR1_Type -> unit + +function MAIR1_write value_name = { + let r : MAIR1_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + MAIR1_S_write() = r + } else { + MAIR1_NS_write() = r + }; + return() +} + +bitfield ICC_HPPIR1_Type : bits(32) = {INTID : 23..0} + +register _ICC_HPPIR1 : ICC_HPPIR1_Type + +val ICC_HPPIR1_read : unit -> ICC_HPPIR1_Type + +function ICC_HPPIR1_read () = { + r : ICC_HPPIR1_Type = _ICC_HPPIR1; + r.bits[31 .. 0] = Slice(ICC_HPPIR1_EL1.bits, 0, 32); + return(r) +} + +val ICC_HPPIR1_write : ICC_HPPIR1_Type -> unit + +function ICC_HPPIR1_write value_name = { + let r : ICC_HPPIR1_Type = value_name; + ICC_HPPIR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_HPPIR1 = r; + return() +} + +bitfield ICC_SRE_Type : bits(32) = {DIB : 2..2, DFB : 1..1, SRE : 0..0} + +register _ICC_SRE_S : ICC_SRE_Type + +val ICC_SRE_S_read : unit -> ICC_SRE_Type + +function ICC_SRE_S_read () = { + r : ICC_SRE_Type = _ICC_SRE_S; + r.bits[31 .. 0] = Slice(ICC_SRE_EL1_S.bits, 0, 32); + return(r) +} + +val ICC_SRE_S_write : ICC_SRE_Type -> unit + +function ICC_SRE_S_write value_name = { + let r : ICC_SRE_Type = value_name; + ICC_SRE_EL1_S.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_SRE_S = r; + return() +} + +register _ICC_SRE_NS : ICC_SRE_Type + +val ICC_SRE_NS_read : unit -> ICC_SRE_Type + +function ICC_SRE_NS_read () = { + r : ICC_SRE_Type = _ICC_SRE_NS; + r.bits[31 .. 0] = Slice(ICC_SRE_EL1_NS.bits, 0, 32); + return(r) +} + +val ICC_SRE_NS_write : ICC_SRE_Type -> unit + +function ICC_SRE_NS_write value_name = { + let r : ICC_SRE_Type = value_name; + ICC_SRE_EL1_NS.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ICC_SRE_NS = r; + return() +} + +val ICC_SRE_read : unit -> ICC_SRE_Type + +function ICC_SRE_read () = { + r : ICC_SRE_Type = undefined; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + r = ICC_SRE_S_read() + } else { + r = ICC_SRE_NS_read() + }; + return(r) +} + +val ICC_SRE_write : ICC_SRE_Type -> unit + +function ICC_SRE_write value_name = { + let r : ICC_SRE_Type = value_name; + if ELUsingAArch32(EL3) & CurrentSecurityState() == SS_Secure then { + ICC_SRE_S_write() = r + } else { + ICC_SRE_NS_write() = r + }; + return() +} + +bitfield ID_ISAR1_Type : bits(32) = + { + Jazelle : 31..28, + Interwork : 27..24, + Immediate : 23..20, + IfThen : 19..16, + Extend : 15..12, + Except_AR : 11..8, + Except : 7..4, + Endian : 3..0 + } + +register _ID_ISAR1 : ID_ISAR1_Type + +val ID_ISAR1_read : unit -> ID_ISAR1_Type + +function ID_ISAR1_read () = { + r : ID_ISAR1_Type = _ID_ISAR1; + r.bits[31 .. 0] = Slice(ID_ISAR1_EL1.bits, 0, 32); + return(r) +} + +val ID_ISAR1_write : ID_ISAR1_Type -> unit + +function ID_ISAR1_write value_name = { + let r : ID_ISAR1_Type = value_name; + ID_ISAR1_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ID_ISAR1 = r; + return() +} + +bitfield AMEVTYPER0_Type : bits(32) = {evtCount : 15..0} + +register _AMEVTYPER0 : vector(4, AMEVTYPER0_Type) + +val AMEVTYPER0_read : forall 'n, (0 <= 'n & 'n < 4). int('n) -> AMEVTYPER0_Type + +function AMEVTYPER0_read n = { + r : AMEVTYPER0_Type = _AMEVTYPER0[n]; + r.bits[31 .. 0] = Slice(AMEVTYPER0_EL0[n].bits, 0, 32); + return(r) +} + +bitfield AMUSERENR_Type : bits(32) = {EN : 0..0} + +register _AMUSERENR : AMUSERENR_Type + +val AMUSERENR_read : unit -> AMUSERENR_Type + +function AMUSERENR_read () = { + r : AMUSERENR_Type = _AMUSERENR; + r.bits[31 .. 0] = Slice(AMUSERENR_EL0.bits, 0, 32); + return(r) +} + +val AMUSERENR_write : AMUSERENR_Type -> unit + +function AMUSERENR_write value_name = { + let r : AMUSERENR_Type = value_name; + AMUSERENR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMUSERENR = r; + return() +} + +bitfield AMEVTYPER1_Type : bits(32) = {evtCount : 15..0} + +register _AMEVTYPER1 : vector(16, AMEVTYPER1_Type) + +val AMEVTYPER1_read : forall 'n, (0 <= 'n & 'n < 16). int('n) -> AMEVTYPER1_Type + +function AMEVTYPER1_read n = { + r : AMEVTYPER1_Type = _AMEVTYPER1[n]; + r.bits[31 .. 0] = Slice(AMEVTYPER1_EL0[n].bits, 0, 32); + return(r) +} + +val AMEVTYPER1_set : forall 'n, (0 <= 'n & 'n < 16). + (int('n), AMEVTYPER1_Type) -> unit + +function AMEVTYPER1_set (n, value_name) = { + let r : AMEVTYPER1_Type = value_name; + AMEVTYPER1_EL0[n].bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMEVTYPER1[n] = r; + return() +} + +bitfield AMCGCR_Type : bits(32) = {CG1NC : 15..8, CG0NC : 7..0} + +register _AMCGCR : AMCGCR_Type + +val AMCGCR_read : unit -> AMCGCR_Type + +function AMCGCR_read () = { + r : AMCGCR_Type = _AMCGCR; + r.bits[31 .. 0] = Slice(AMCGCR_EL0.bits, 0, 32); + return(r) +} + +val AMCGCR_write : AMCGCR_Type -> unit + +function AMCGCR_write value_name = { + let r : AMCGCR_Type = value_name; + AMCGCR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMCGCR = r; + return() +} + +bitfield AMCFGR_Type : bits(32) = + {NCG : 31..28, HDBG : 24..24, SIZE : 13..8, N : 7..0} + +register _AMCFGR : AMCFGR_Type + +val AMCFGR_read : unit -> AMCFGR_Type + +function AMCFGR_read () = { + r : AMCFGR_Type = _AMCFGR; + r.bits[31 .. 0] = Slice(AMCFGR_EL0.bits, 0, 32); + return(r) +} + +val AMCFGR_write : AMCFGR_Type -> unit + +function AMCFGR_write value_name = { + let r : AMCFGR_Type = value_name; + AMCFGR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMCFGR = r; + return() +} + +bitfield AMCNTENCLR1_Type : bits(32) = + { + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _AMCNTENCLR1 : AMCNTENCLR1_Type + +val AMCNTENCLR1_read : unit -> AMCNTENCLR1_Type + +function AMCNTENCLR1_read () = { + r : AMCNTENCLR1_Type = _AMCNTENCLR1; + r.bits[31 .. 0] = Slice(AMCNTENCLR1_EL0.bits, 0, 32); + return(r) +} + +val AMCNTENCLR1_write : AMCNTENCLR1_Type -> unit + +function AMCNTENCLR1_write value_name = { + let r : AMCNTENCLR1_Type = value_name; + AMCNTENCLR1_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMCNTENCLR1 = r; + return() +} + +bitfield AMCNTENSET0_Type : bits(32) = + {P3 : 3..3, P2 : 2..2, P1 : 1..1, P0 : 0..0} + +register _AMCNTENSET0 : AMCNTENSET0_Type + +val AMCNTENSET0_read : unit -> AMCNTENSET0_Type + +function AMCNTENSET0_read () = { + r : AMCNTENSET0_Type = _AMCNTENSET0; + r.bits[31 .. 0] = Slice(AMCNTENSET0_EL0.bits, 0, 32); + return(r) +} + +val AMCNTENSET0_write : AMCNTENSET0_Type -> unit + +function AMCNTENSET0_write value_name = { + let r : AMCNTENSET0_Type = value_name; + AMCNTENSET0_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMCNTENSET0 = r; + return() +} + +bitfield AMCNTENCLR0_Type : bits(32) = + {P3 : 3..3, P2 : 2..2, P1 : 1..1, P0 : 0..0} + +register _AMCNTENCLR0 : AMCNTENCLR0_Type + +val AMCNTENCLR0_read : unit -> AMCNTENCLR0_Type + +function AMCNTENCLR0_read () = { + r : AMCNTENCLR0_Type = _AMCNTENCLR0; + r.bits[31 .. 0] = Slice(AMCNTENCLR0_EL0.bits, 0, 32); + return(r) +} + +val AMCNTENCLR0_write : AMCNTENCLR0_Type -> unit + +function AMCNTENCLR0_write value_name = { + let r : AMCNTENCLR0_Type = value_name; + AMCNTENCLR0_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMCNTENCLR0 = r; + return() +} + +bitfield AMCNTENSET1_Type : bits(32) = + { + P15 : 15..15, + P14 : 14..14, + P13 : 13..13, + P12 : 12..12, + P11 : 11..11, + P10 : 10..10, + P9 : 9..9, + P8 : 8..8, + P7 : 7..7, + P6 : 6..6, + P5 : 5..5, + P4 : 4..4, + P3 : 3..3, + P2 : 2..2, + P1 : 1..1, + P0 : 0..0 + } + +register _AMCNTENSET1 : AMCNTENSET1_Type + +val AMCNTENSET1_read : unit -> AMCNTENSET1_Type + +function AMCNTENSET1_read () = { + r : AMCNTENSET1_Type = _AMCNTENSET1; + r.bits[31 .. 0] = Slice(AMCNTENSET1_EL0.bits, 0, 32); + return(r) +} + +val AMCNTENSET1_write : AMCNTENSET1_Type -> unit + +function AMCNTENSET1_write value_name = { + let r : AMCNTENSET1_Type = value_name; + AMCNTENSET1_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMCNTENSET1 = r; + return() +} + +bitfield AMCR_Type : bits(32) = {CG1RZ : 17..17, HDBG : 10..10} + +register _AMCR : AMCR_Type + +val AMCR_read : unit -> AMCR_Type + +function AMCR_read () = { + r : AMCR_Type = _AMCR; + r.bits[31 .. 0] = Slice(AMCR_EL0.bits, 0, 32); + return(r) +} + +val AMCR_write : AMCR_Type -> unit + +function AMCR_write value_name = { + let r : AMCR_Type = value_name; + AMCR_EL0.bits[31 .. 0] = Slice(r.bits, 0, 32); + _AMCR = r; + return() +} + +bitfield ERRIDR_Type : bits(32) = {NUM : 15..0} + +register _ERRIDR : ERRIDR_Type + +val ERRIDR_read : unit -> ERRIDR_Type + +function ERRIDR_read () = { + r : ERRIDR_Type = _ERRIDR; + r.bits[31 .. 0] = Slice(ERRIDR_EL1.bits, 0, 32); + return(r) +} + +val ERRIDR_write : ERRIDR_Type -> unit + +function ERRIDR_write value_name = { + let r : ERRIDR_Type = value_name; + ERRIDR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ERRIDR = r; + return() +} + +type ERXFR2_Type = bits(32) + +register _ERXFR2 : ERXFR2_Type + +val ERXFR2_read : unit -> ERXFR2_Type + +function ERXFR2_read () = { + r : ERXFR2_Type = _ERXFR2; + r[31 .. 0] = Slice(ERXFR_EL1, 32, 32); + return(r) +} + +type ERXMISC2_Type = bits(32) + +register _ERXMISC2 : ERXMISC2_Type + +val ERXMISC2_read : unit -> ERXMISC2_Type + +function ERXMISC2_read () = { + r : ERXMISC2_Type = _ERXMISC2; + r[31 .. 0] = Slice(ERXMISC1_EL1, 0, 32); + return(r) +} + +val ERXMISC2_write : ERXMISC2_Type -> unit + +function ERXMISC2_write value_name = { + let r : ERXMISC2_Type = value_name; + ERXMISC1_EL1[31 .. 0] = Slice(r, 0, 32); + _ERXMISC2 = r; + return() +} + +type ERXFR_Type = bits(32) + +register _ERXFR : ERXFR_Type + +val ERXFR_read : unit -> ERXFR_Type + +function ERXFR_read () = { + r : ERXFR_Type = _ERXFR; + r[31 .. 0] = Slice(ERXFR_EL1, 0, 32); + return(r) +} + +type ERXADDR_Type = bits(32) + +register _ERXADDR : ERXADDR_Type + +val ERXADDR_read : unit -> ERXADDR_Type + +function ERXADDR_read () = { + r : ERXADDR_Type = _ERXADDR; + r[31 .. 0] = Slice(ERXADDR_EL1, 0, 32); + return(r) +} + +val ERXADDR_write : ERXADDR_Type -> unit + +function ERXADDR_write value_name = { + let r : ERXADDR_Type = value_name; + ERXADDR_EL1[31 .. 0] = Slice(r, 0, 32); + _ERXADDR = r; + return() +} + +type ERXMISC0_Type = bits(32) + +register _ERXMISC0 : ERXMISC0_Type + +val ERXMISC0_read : unit -> ERXMISC0_Type + +function ERXMISC0_read () = { + r : ERXMISC0_Type = _ERXMISC0; + r[31 .. 0] = Slice(ERXMISC0_EL1, 0, 32); + return(r) +} + +val ERXMISC0_write : ERXMISC0_Type -> unit + +function ERXMISC0_write value_name = { + let r : ERXMISC0_Type = value_name; + ERXMISC0_EL1[31 .. 0] = Slice(r, 0, 32); + _ERXMISC0 = r; + return() +} + +type ERXMISC5_Type = bits(32) + +register _ERXMISC5 : ERXMISC5_Type + +val ERXMISC5_read : unit -> ERXMISC5_Type + +function ERXMISC5_read () = { + r : ERXMISC5_Type = _ERXMISC5; + r[31 .. 0] = Slice(ERXMISC2_EL1, 32, 32); + return(r) +} + +val ERXMISC5_write : ERXMISC5_Type -> unit + +function ERXMISC5_write value_name = { + let r : ERXMISC5_Type = value_name; + ERXMISC2_EL1[63 .. 32] = Slice(r, 0, 32); + _ERXMISC5 = r; + return() +} + +bitfield ERRSELR_Type : bits(32) = {SEL : 15..0} + +register _ERRSELR : ERRSELR_Type + +val ERRSELR_read : unit -> ERRSELR_Type + +function ERRSELR_read () = { + r : ERRSELR_Type = _ERRSELR; + r.bits[31 .. 0] = Slice(ERRSELR_EL1.bits, 0, 32); + return(r) +} + +val ERRSELR_write : ERRSELR_Type -> unit + +function ERRSELR_write value_name = { + let r : ERRSELR_Type = value_name; + ERRSELR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _ERRSELR = r; + return() +} + +type ERXCTLR2_Type = bits(32) + +register _ERXCTLR2 : ERXCTLR2_Type + +val ERXCTLR2_read : unit -> ERXCTLR2_Type + +function ERXCTLR2_read () = { + r : ERXCTLR2_Type = _ERXCTLR2; + r[31 .. 0] = Slice(ERXCTLR_EL1, 32, 32); + return(r) +} + +val ERXCTLR2_write : ERXCTLR2_Type -> unit + +function ERXCTLR2_write value_name = { + let r : ERXCTLR2_Type = value_name; + ERXCTLR_EL1[63 .. 32] = Slice(r, 0, 32); + _ERXCTLR2 = r; + return() +} + +val DISR_read : unit -> DISR_Type + +function DISR_read () = { + r : DISR_Type = _DISR; + r.bits[31 .. 0] = Slice(DISR_EL1.bits, 0, 32); + return(r) +} + +val VDFSR_write : VDFSR_Type -> unit + +function VDFSR_write value_name = { + let r : VDFSR_Type = value_name; + VSESR_EL2.bits[31 .. 0] = Slice(r.bits, 0, 32); + _VDFSR = r; + return() +} + +type ERXMISC1_Type = bits(32) + +register _ERXMISC1 : ERXMISC1_Type + +val ERXMISC1_read : unit -> ERXMISC1_Type + +function ERXMISC1_read () = { + r : ERXMISC1_Type = _ERXMISC1; + r[31 .. 0] = Slice(ERXMISC0_EL1, 32, 32); + return(r) +} + +val ERXMISC1_write : ERXMISC1_Type -> unit + +function ERXMISC1_write value_name = { + let r : ERXMISC1_Type = value_name; + ERXMISC0_EL1[63 .. 32] = Slice(r, 0, 32); + _ERXMISC1 = r; + return() +} + +type ERXCTLR_Type = bits(32) + +register _ERXCTLR : ERXCTLR_Type + +val ERXCTLR_read : unit -> ERXCTLR_Type + +function ERXCTLR_read () = { + r : ERXCTLR_Type = _ERXCTLR; + r[31 .. 0] = Slice(ERXCTLR_EL1, 0, 32); + return(r) +} + +val ERXCTLR_write : ERXCTLR_Type -> unit + +function ERXCTLR_write value_name = { + let r : ERXCTLR_Type = value_name; + ERXCTLR_EL1[31 .. 0] = Slice(r, 0, 32); + _ERXCTLR = r; + return() +} + +type ERXMISC6_Type = bits(32) + +register _ERXMISC6 : ERXMISC6_Type + +val ERXMISC6_read : unit -> ERXMISC6_Type + +function ERXMISC6_read () = { + r : ERXMISC6_Type = _ERXMISC6; + r[31 .. 0] = Slice(ERXMISC3_EL1, 0, 32); + return(r) +} + +val ERXMISC6_write : ERXMISC6_Type -> unit + +function ERXMISC6_write value_name = { + let r : ERXMISC6_Type = value_name; + ERXMISC3_EL1[31 .. 0] = Slice(r, 0, 32); + _ERXMISC6 = r; + return() +} + +type ERXMISC4_Type = bits(32) + +register _ERXMISC4 : ERXMISC4_Type + +val ERXMISC4_read : unit -> ERXMISC4_Type + +function ERXMISC4_read () = { + r : ERXMISC4_Type = _ERXMISC4; + r[31 .. 0] = Slice(ERXMISC2_EL1, 0, 32); + return(r) +} + +val ERXMISC4_write : ERXMISC4_Type -> unit + +function ERXMISC4_write value_name = { + let r : ERXMISC4_Type = value_name; + ERXMISC2_EL1[31 .. 0] = Slice(r, 0, 32); + _ERXMISC4 = r; + return() +} + +type ERXADDR2_Type = bits(32) + +register _ERXADDR2 : ERXADDR2_Type + +val ERXADDR2_read : unit -> ERXADDR2_Type + +function ERXADDR2_read () = { + r : ERXADDR2_Type = _ERXADDR2; + r[31 .. 0] = Slice(ERXADDR_EL1, 32, 32); + return(r) +} + +val ERXADDR2_write : ERXADDR2_Type -> unit + +function ERXADDR2_write value_name = { + let r : ERXADDR2_Type = value_name; + ERXADDR_EL1[63 .. 32] = Slice(r, 0, 32); + _ERXADDR2 = r; + return() +} + +type ERXMISC7_Type = bits(32) + +register _ERXMISC7 : ERXMISC7_Type + +val ERXMISC7_read : unit -> ERXMISC7_Type + +function ERXMISC7_read () = { + r : ERXMISC7_Type = _ERXMISC7; + r[31 .. 0] = Slice(ERXMISC3_EL1, 32, 32); + return(r) +} + +val ERXMISC7_write : ERXMISC7_Type -> unit + +function ERXMISC7_write value_name = { + let r : ERXMISC7_Type = value_name; + ERXMISC3_EL1[63 .. 32] = Slice(r, 0, 32); + _ERXMISC7 = r; + return() +} + +type ERXMISC3_Type = bits(32) + +register _ERXMISC3 : ERXMISC3_Type + +val ERXMISC3_read : unit -> ERXMISC3_Type + +function ERXMISC3_read () = { + r : ERXMISC3_Type = _ERXMISC3; + r[31 .. 0] = Slice(ERXMISC1_EL1, 32, 32); + return(r) +} + +val ERXMISC3_write : ERXMISC3_Type -> unit + +function ERXMISC3_write value_name = { + let r : ERXMISC3_Type = value_name; + ERXMISC1_EL1[63 .. 32] = Slice(r, 0, 32); + _ERXMISC3 = r; + return() +} + +val VDISR_read : unit -> VDISR_Type + +function VDISR_read () = { + r : VDISR_Type = _VDISR; + r.bits[31 .. 0] = Slice(VDISR_EL2.bits, 0, 32); + return(r) +} + +type ERXSTATUS_Type = bits(32) + +register _ERXSTATUS : ERXSTATUS_Type + +val ERXSTATUS_read : unit -> ERXSTATUS_Type + +function ERXSTATUS_read () = { + r : ERXSTATUS_Type = _ERXSTATUS; + r[31 .. 0] = Slice(ERXSTATUS_EL1, 0, 32); + return(r) +} + +val ERXSTATUS_write : ERXSTATUS_Type -> unit + +function ERXSTATUS_write value_name = { + let r : ERXSTATUS_Type = value_name; + ERXSTATUS_EL1[31 .. 0] = Slice(r, 0, 32); + _ERXSTATUS = r; + return() +} + +bitfield GICD_CTLR_Type : bits(32) = + { + RWP : 31..31, + nASSGIreq : 8..8, + E1NWF : 7..7, + DS : 6..6, + ARE : 4..4, + ARE_S : 4..4, + EnableGrp1S : 2..2, + EnableGrp1A : 1..1, + EnableGrp1NS : 1..1, + EnableGrp0 : 0..0 + } + +register GICD_CTLR : GICD_CTLR_Type + +bitfield GICC_IAR_Type : bits(32) = {INTID : 23..0} + +register GICC_IAR : GICC_IAR_Type + +bitfield CTILAR_Type : bits(32) = {KEY : 31..0} + +register CTILAR : CTILAR_Type + +bitfield CTIPIDR2_Type : bits(32) = + {REVISION : 7..4, JEDEC : 3..3, DES_1 : 2..0} + +register CTIPIDR2 : CTIPIDR2_Type + +bitfield CTICIDR1_Type : bits(32) = {CLASS : 7..4, PRMBL_1 : 3..0} + +register CTICIDR1 : CTICIDR1_Type + +bitfield GICH_MISR_Type : bits(32) = + { + VGrp1D : 7..7, + VGrp1E : 6..6, + VGrp0D : 5..5, + VGrp0E : 4..4, + NP : 3..3, + LRENP : 2..2, + U : 1..1, + EOI : 0..0 + } + +register GICH_MISR : GICH_MISR_Type + +bitfield CTIDEVTYPE_Type : bits(32) = {SUB : 7..4, MAJOR : 3..0} + +register CTIDEVTYPE : CTIDEVTYPE_Type + +bitfield GITS_CTLR_Type : bits(32) = + { + Quiescent : 31..31, + UMSIirq : 8..8, + ITS_Number : 7..4, + ImDe : 1..1, + Enabled : 0..0 + } + +register GITS_CTLR : GITS_CTLR_Type + +bitfield GICR_IIDR_Type : bits(32) = + {ProductID : 31..24, Variant : 19..16, Revision : 15..12, Implementer : 11..0} + +register GICR_IIDR : GICR_IIDR_Type + +bitfield EDDEVARCH_Type : bits(32) = + { + ARCHITECT : 31..21, + PRESENT : 20..20, + REVISION : 19..16, + ARCHVER : 15..12, + ARCHPART : 11..0 + } + +register EDDEVARCH : EDDEVARCH_Type + +bitfield CTIPIDR1_Type : bits(32) = {DES_0 : 7..4, PART_1 : 3..0} + +register CTIPIDR1 : CTIPIDR1_Type + +bitfield GICV_IAR_Type : bits(32) = {INTID : 24..0} + +register GICV_IAR : GICV_IAR_Type + +bitfield CNTSR_Type : bits(32) = {FCACK : 17..8, DBGH : 1..1} + +register CNTSR : CNTSR_Type + +bitfield EDCIDR3_Type : bits(32) = {PRMBL_3 : 7..0} + +register EDCIDR3 : EDCIDR3_Type + +bitfield GICM_SETSPI_NSR_Type : bits(32) = {INTID : 12..0} + +register GICM_SETSPI_NSR : GICM_SETSPI_NSR_Type + +bitfield GICR_WAKER_Type : bits(32) = + {ChildrenAsleep : 2..2, ProcessorSleep : 1..1} + +register GICR_WAKER : GICR_WAKER_Type + +bitfield GITS_PARTIDR_Type : bits(32) = {PMG : 23..16, PARTID : 15..0} + +register GITS_PARTIDR : GITS_PARTIDR_Type + +bitfield GICV_HPPIR_Type : bits(32) = {INTID : 24..0} + +register GICV_HPPIR : GICV_HPPIR_Type + +bitfield CTIPIDR0_Type : bits(32) = {PART_0 : 7..0} + +register CTIPIDR0 : CTIPIDR0_Type + +bitfield GICM_SETSPI_SR_Type : bits(32) = {INTID : 12..0} + +register GICM_SETSPI_SR : GICM_SETSPI_SR_Type + +bitfield GICV_DIR_Type : bits(32) = {INTID : 24..0} + +register GICV_DIR : GICV_DIR_Type + +type CTIDEVID2_Type = bits(32) + +register CTIDEVID2 : CTIDEVID2_Type + +bitfield EDPIDR3_Type : bits(32) = {REVAND : 7..4, CMOD : 3..0} + +register EDPIDR3 : EDPIDR3_Type + +bitfield GICC_STATUSR_Type : bits(32) = + {ASV : 4..4, WROD : 3..3, RWOD : 2..2, WRD : 1..1, RRD : 0..0} + +register GICC_STATUSR : GICC_STATUSR_Type + +bitfield GICM_IIDR_Type : bits(32) = + {ProductID : 31..24, Variant : 19..16, Revision : 15..12, Implementer : 11..0} + +register GICM_IIDR : GICM_IIDR_Type + +val EDSCR2_write : EDSCR2_Type -> unit + +function EDSCR2_write value_name = { + let r : EDSCR2_Type = value_name; + MDSCR_EL1.bits[63 .. 32] = Slice(r.bits, 0, 32); + _EDSCR2 = r; + return() +} + +bitfield GICR_VSGIR_Type : bits(32) = {vPEID : 15..0} + +register GICR_VSGIR : GICR_VSGIR_Type + +bitfield EDDEVTYPE_Type : bits(32) = {SUB : 7..4, MAJOR : 3..0} + +register EDDEVTYPE : EDDEVTYPE_Type + +bitfield GICM_TYPER_Type : bits(32) = + {Valid : 31..31, CLR : 30..30, SR : 29..29, INTID : 28..16, NumSPIs : 10..0} + +register GICM_TYPER : GICM_TYPER_Type + +bitfield GICD_TYPER2_Type : bits(32) = + {nASSGIcap : 8..8, VIL : 7..7, VID : 4..0} + +register GICD_TYPER2 : GICD_TYPER2_Type + +bitfield GICH_EISR_Type : bits(32) = + { + Status15 : 15..15, + Status14 : 14..14, + Status13 : 13..13, + Status12 : 12..12, + Status11 : 11..11, + Status10 : 10..10, + Status9 : 9..9, + Status8 : 8..8, + Status7 : 7..7, + Status6 : 6..6, + Status5 : 5..5, + Status4 : 4..4, + Status3 : 3..3, + Status2 : 2..2, + Status1 : 1..1, + Status0 : 0..0 + } + +register GICH_EISR : GICH_EISR_Type + +bitfield GICH_ELRSR_Type : bits(32) = + { + Status15 : 15..15, + Status14 : 14..14, + Status13 : 13..13, + Status12 : 12..12, + Status11 : 11..11, + Status10 : 10..10, + Status9 : 9..9, + Status8 : 8..8, + Status7 : 7..7, + Status6 : 6..6, + Status5 : 5..5, + Status4 : 4..4, + Status3 : 3..3, + Status2 : 2..2, + Status1 : 1..1, + Status0 : 0..0 + } + +register GICH_ELRSR : GICH_ELRSR_Type + +bitfield GICM_CLRSPI_NSR_Type : bits(32) = {INTID : 12..0} + +register GICM_CLRSPI_NSR : GICM_CLRSPI_NSR_Type + +bitfield GICV_STATUSR_Type : bits(32) = + {WROD : 3..3, RWOD : 2..2, WRD : 1..1, RRD : 0..0} + +register GICV_STATUSR : GICV_STATUSR_Type + +bitfield EDPIDR1_Type : bits(32) = {DES_0 : 7..4, PART_1 : 3..0} + +register EDPIDR1 : EDPIDR1_Type + +bitfield GICM_CLRSPI_SR_Type : bits(32) = {INTID : 12..0} + +register GICM_CLRSPI_SR : GICM_CLRSPI_SR_Type + +val EDECCR_write : EDECCR_Type -> unit + +function EDECCR_write value_name = { + let r : EDECCR_Type = value_name; + OSECCR_EL1.bits[31 .. 0] = Slice(r.bits, 0, 32); + _EDECCR = r; + return() +} + +bitfield GICV_AEOIR_Type : bits(32) = {INTID : 24..0} + +register GICV_AEOIR : GICV_AEOIR_Type + +bitfield GICC_PMR_Type : bits(32) = {Priority : 7..0} + +register GICC_PMR : GICC_PMR_Type + +bitfield GICV_ABPR_Type : bits(32) = {Binary_Point : 2..0} + +register GICV_ABPR : GICV_ABPR_Type + +bitfield CTIDEVARCH_Type : bits(32) = + {ARCHITECT : 31..21, PRESENT : 20..20, REVISION : 19..16, ARCHID : 15..0} + +register CTIDEVARCH : CTIDEVARCH_Type + +bitfield GICR_MPAMIDR_Type : bits(32) = {PMGmax : 23..16, PARTIDmax : 15..0} + +register GICR_MPAMIDR : GICR_MPAMIDR_Type + +bitfield CTICIDR3_Type : bits(32) = {PRMBL_3 : 7..0} + +register CTICIDR3 : CTICIDR3_Type + +bitfield GICC_RPR_Type : bits(32) = {Priority : 7..0} + +register GICC_RPR : GICC_RPR_Type + +bitfield GICV_AIAR_Type : bits(32) = {INTID : 24..0} + +register GICV_AIAR : GICV_AIAR_Type + +bitfield GICV_RPR_Type : bits(32) = {Priority : 7..0} + +register GICV_RPR : GICV_RPR_Type + +bitfield GICV_AHPPIR_Type : bits(32) = {INTID : 24..0} + +register GICV_AHPPIR : GICV_AHPPIR_Type + +bitfield GICR_CTLR_Type : bits(32) = + { + UWP : 31..31, + DPG1S : 26..26, + DPG1NS : 25..25, + DPG0 : 24..24, + RWP : 3..3, + IR : 2..2, + CES : 1..1, + EnableLPIs : 0..0 + } + +register GICR_CTLR : GICR_CTLR_Type + +bitfield CNTEL0ACR_Type : bits(32) = + {EL0PTEN : 9..9, EL0VTEN : 8..8, EL0VCTEN : 1..1, EL0PCTEN : 0..0} + +register CNTEL0ACR : CNTEL0ACR_Type + +bitfield GICV_BPR_Type : bits(32) = {Binary_Point : 2..0} + +register GICV_BPR : GICV_BPR_Type + +type EDDEVID2_Type = bits(32) + +register EDDEVID2 : EDDEVID2_Type + +bitfield GICV_EOIR_Type : bits(32) = {INTID : 24..0} + +register GICV_EOIR : GICV_EOIR_Type + +bitfield CNTFID0_Type : bits(32) = {Frequency : 31..0} + +register CNTFID0 : CNTFID0_Type + +bitfield GICD_TYPER_Type : bits(32) = + { + ESPI_range : 31..27, + RSS : 26..26, + No1N : 25..25, + A3V : 24..24, + IDbits : 23..19, + DVIS : 18..18, + LPIS : 17..17, + MBIS : 16..16, + num_LPIs : 15..11, + SecurityExtn : 10..10, + NMI : 9..9, + ESPI : 8..8, + CPUNumber : 7..5, + ITLinesNumber : 4..0 + } + +register GICD_TYPER : GICD_TYPER_Type + +bitfield CTICIDR0_Type : bits(32) = {PRMBL_0 : 7..0} + +register CTICIDR0 : CTICIDR0_Type + +bitfield GICC_HPPIR_Type : bits(32) = {INTID : 23..0} + +register GICC_HPPIR : GICC_HPPIR_Type + +bitfield GICD_CLRSPI_NSR_Type : bits(32) = {INTID : 12..0} + +register GICD_CLRSPI_NSR : GICD_CLRSPI_NSR_Type + +bitfield CTIITCTRL_Type : bits(32) = {IME : 0..0} + +register CTIITCTRL : CTIITCTRL_Type + +bitfield GITS_STATUSR_Type : bits(32) = + { + Syndrome : 9..6, + Overflow : 5..5, + UMSI : 4..4, + WROD : 3..3, + RWOD : 2..2, + WRD : 1..1, + RRD : 0..0 + } + +register GITS_STATUSR : GITS_STATUSR_Type + +bitfield GICH_VTR_Type : bits(32) = + { + PRIbits : 31..29, + PREbits : 28..26, + IDbits : 25..23, + SEIS : 22..22, + A3V : 21..21, + ListRegs : 4..0 + } + +register GICH_VTR : GICH_VTR_Type + +bitfield CTIPIDR3_Type : bits(32) = {REVAND : 7..4, CMOD : 3..0} + +register CTIPIDR3 : CTIPIDR3_Type + +bitfield GICC_CTLR_Type : bits(32) = + { + EOImode : 9..9, + EOImodeS : 9..9, + IRQBypDisGrp0 : 6..6, + FIQBypDisGrp0 : 5..5, + CBPR : 4..4, + FIQEn : 3..3, + EnableGrp0 : 0..0 + } + +register GICC_CTLR : GICC_CTLR_Type + +bitfield EDPIDR4_Type : bits(32) = {SIZE : 7..4, DES_2 : 3..0} + +register EDPIDR4 : EDPIDR4_Type + +bitfield CTICONTROL_Type : bits(32) = {GLBEN : 0..0} + +register CTICONTROL : CTICONTROL_Type + +bitfield GICR_INMIR0_Type : bits(32) = + { + nmi31 : 31..31, + nmi30 : 30..30, + nmi29 : 29..29, + nmi28 : 28..28, + nmi27 : 27..27, + nmi26 : 26..26, + nmi25 : 25..25, + nmi24 : 24..24, + nmi23 : 23..23, + nmi22 : 22..22, + nmi21 : 21..21, + nmi20 : 20..20, + nmi19 : 19..19, + nmi18 : 18..18, + nmi17 : 17..17, + nmi16 : 16..16, + nmi15 : 15..15, + nmi14 : 14..14, + nmi13 : 13..13, + nmi12 : 12..12, + nmi11 : 11..11, + nmi10 : 10..10, + nmi9 : 9..9, + nmi8 : 8..8, + nmi7 : 7..7, + nmi6 : 6..6, + nmi5 : 5..5, + nmi4 : 4..4, + nmi3 : 3..3, + nmi2 : 2..2, + nmi1 : 1..1, + nmi0 : 0..0 + } + +register GICR_INMIR0 : GICR_INMIR0_Type + +bitfield GICD_CLRSPI_SR_Type : bits(32) = {INTID : 12..0} + +register GICD_CLRSPI_SR : GICD_CLRSPI_SR_Type + +bitfield GICV_CTLR_Type : bits(32) = + { + EOImode : 9..9, + CBPR : 4..4, + FIQEn : 3..3, + AckCtl : 2..2, + EnableGrp1 : 1..1, + EnableGrp0 : 0..0 + } + +register GICV_CTLR : GICV_CTLR_Type + +bitfield GICR_PARTIDR_Type : bits(32) = {PMG : 23..16, PARTID : 15..0} + +register GICR_PARTIDR : GICR_PARTIDR_Type + +bitfield EDDEVID1_Type : bits(32) = {HSR : 7..4, PCSROffset : 3..0} + +register EDDEVID1 : EDDEVID1_Type + +bitfield EDPRCR_Type : bits(32) = + {COREPURQ : 3..3, CWRR : 1..1, CORENPDRQ : 0..0} + +register EDPRCR : EDPRCR_Type + +bitfield GICR_VSGIPENDR_Type : bits(32) = {Busy : 31..31, Pending : 15..0} + +register GICR_VSGIPENDR : GICR_VSGIPENDR_Type + +bitfield GICD_STATUSR_Type : bits(32) = + {WROD : 3..3, RWOD : 2..2, WRD : 1..1, RRD : 0..0} + +register GICD_STATUSR : GICD_STATUSR_Type + +bitfield GICR_ISENABLER0_Type : bits(32) = + { + Set_enable_bit31 : 31..31, + Set_enable_bit30 : 30..30, + Set_enable_bit29 : 29..29, + Set_enable_bit28 : 28..28, + Set_enable_bit27 : 27..27, + Set_enable_bit26 : 26..26, + Set_enable_bit25 : 25..25, + Set_enable_bit24 : 24..24, + Set_enable_bit23 : 23..23, + Set_enable_bit22 : 22..22, + Set_enable_bit21 : 21..21, + Set_enable_bit20 : 20..20, + Set_enable_bit19 : 19..19, + Set_enable_bit18 : 18..18, + Set_enable_bit17 : 17..17, + Set_enable_bit16 : 16..16, + Set_enable_bit15 : 15..15, + Set_enable_bit14 : 14..14, + Set_enable_bit13 : 13..13, + Set_enable_bit12 : 12..12, + Set_enable_bit11 : 11..11, + Set_enable_bit10 : 10..10, + Set_enable_bit9 : 9..9, + Set_enable_bit8 : 8..8, + Set_enable_bit7 : 7..7, + Set_enable_bit6 : 6..6, + Set_enable_bit5 : 5..5, + Set_enable_bit4 : 4..4, + Set_enable_bit3 : 3..3, + Set_enable_bit2 : 2..2, + Set_enable_bit1 : 1..1, + Set_enable_bit0 : 0..0 + } + +register GICR_ISENABLER0 : GICR_ISENABLER0_Type + +bitfield CTICIDR2_Type : bits(32) = {PRMBL_2 : 7..0} + +register CTICIDR2 : CTICIDR2_Type + +bitfield EDRCR_Type : bits(32) = {CBRRQ : 4..4, CSPA : 3..3, CSE : 2..2} + +register EDRCR : EDRCR_Type + +bitfield GICV_PMR_Type : bits(32) = {Priority : 7..0} + +register GICV_PMR : GICV_PMR_Type + +bitfield EDDEVID_Type : bits(32) = + {AuxRegs : 27..24, DebugPower : 7..4, PCSample : 3..0} + +register EDDEVID : EDDEVID_Type + +bitfield GICC_DIR_Type : bits(32) = {INTID : 23..0} + +register GICC_DIR : GICC_DIR_Type + +bitfield EDCIDR0_Type : bits(32) = {PRMBL_0 : 7..0} + +register EDCIDR0 : EDCIDR0_Type + +bitfield GITS_MPAMIDR_Type : bits(32) = {PMGmax : 23..16, PARTIDmax : 15..0} + +register GITS_MPAMIDR : GITS_MPAMIDR_Type + +bitfield GICD_SGIR_Type : bits(32) = + { + TargetListFilter : 25..24, + CPUTargetList : 23..16, + NSATT : 15..15, + INTID : 3..0 + } + +register GICD_SGIR : GICD_SGIR_Type + +bitfield GICH_VMCR_Type : bits(32) = + { + VPMR : 31..24, + VBPR0 : 23..21, + VBPR1 : 20..18, + VEOIM : 9..9, + VCBPR : 4..4, + VFIQEn : 3..3, + VAckCtl : 2..2, + VENG1 : 1..1, + VENG0 : 0..0 + } + +register GICH_VMCR : GICH_VMCR_Type + +bitfield EDLAR_Type : bits(32) = {KEY : 31..0} + +register EDLAR : EDLAR_Type + +bitfield GICC_AEOIR_Type : bits(32) = {INTID : 23..0} + +register GICC_AEOIR : GICC_AEOIR_Type + +bitfield GICC_AHPPIR_Type : bits(32) = {INTID : 23..0} + +register GICC_AHPPIR : GICC_AHPPIR_Type + +bitfield GICR_SYNCR_Type : bits(32) = {Busy : 0..0} + +register GICR_SYNCR : GICR_SYNCR_Type + +bitfield GICC_ABPR_Type : bits(32) = {Binary_Point : 2..0} + +register GICC_ABPR : GICC_ABPR_Type + +bitfield CTIPIDR4_Type : bits(32) = {SIZE : 7..4, DES_2 : 3..0} + +register CTIPIDR4 : CTIPIDR4_Type + +type CTIDEVID1_Type = bits(32) + +register CTIDEVID1 : CTIDEVID1_Type + +bitfield GITS_MPIDR_Type : bits(32) = + {Aff3 : 31..24, Aff2 : 23..16, Aff1 : 15..8} + +register GITS_MPIDR : GITS_MPIDR_Type + +bitfield EDCIDR2_Type : bits(32) = {PRMBL_2 : 7..0} + +register EDCIDR2 : EDCIDR2_Type + +bitfield GICD_SETSPI_NSR_Type : bits(32) = {INTID : 12..0} + +register GICD_SETSPI_NSR : GICD_SETSPI_NSR_Type + +bitfield CNTID_Type : bits(32) = {CNTSC : 3..0} + +register CNTID : CNTID_Type + +bitfield GITS_IIDR_Type : bits(32) = + {ProductID : 31..24, Variant : 19..16, Revision : 15..12, Implementer : 11..0} + +register GITS_IIDR : GITS_IIDR_Type + +bitfield EDPIDR0_Type : bits(32) = {PART_0 : 7..0} + +register EDPIDR0 : EDPIDR0_Type + +bitfield CTIAUTHSTATUS_Type : bits(32) = {NSNID : 3..2, NSID : 1..0} + +register CTIAUTHSTATUS : CTIAUTHSTATUS_Type + +bitfield GICH_HCR_Type : bits(32) = + { + EOICount : 31..27, + VGrp1DIE : 7..7, + VGrp1EIE : 6..6, + VGrp0DIE : 5..5, + VGrp0EIE : 4..4, + NPIE : 3..3, + LRENPIE : 2..2, + UIE : 1..1, + En : 0..0 + } + +register GICH_HCR : GICH_HCR_Type + +bitfield GICC_BPR_Type : bits(32) = {Binary_Point : 2..0} + +register GICC_BPR : GICC_BPR_Type + +bitfield CTIDEVID_Type : bits(32) = + {INOUT : 25..24, NUMCHAN : 21..16, NUMTRIG : 13..8, EXTMUXNUM : 4..0} + +register CTIDEVID : CTIDEVID_Type + +bitfield GICD_SETSPI_SR_Type : bits(32) = {INTID : 12..0} + +register GICD_SETSPI_SR : GICD_SETSPI_SR_Type + +bitfield GICR_STATUSR_Type : bits(32) = + {WROD : 3..3, RWOD : 2..2, WRD : 1..1, RRD : 0..0} + +register GICR_STATUSR : GICR_STATUSR_Type + +bitfield GICC_EOIR_Type : bits(32) = {INTID : 23..0} + +register GICC_EOIR : GICC_EOIR_Type + +bitfield EDPIDR2_Type : bits(32) = {REVISION : 7..4, JEDEC : 3..3, DES_1 : 2..0} + +register EDPIDR2 : EDPIDR2_Type + +bitfield CNTNSAR_Type : bits(32) = + { + NS7 : 7..7, + NS6 : 6..6, + NS5 : 5..5, + NS4 : 4..4, + NS3 : 3..3, + NS2 : 2..2, + NS1 : 1..1, + NS0 : 0..0 + } + +register CNTNSAR : CNTNSAR_Type + +bitfield EDITCTRL_Type : bits(32) = {IME : 0..0} + +register EDITCTRL : EDITCTRL_Type + +bitfield GICD_IIDR_Type : bits(32) = + {ProductID : 31..24, Variant : 19..16, Revision : 15..12, Implementer : 11..0} + +register GICD_IIDR : GICD_IIDR_Type + +bitfield EDCIDR1_Type : bits(32) = {CLASS : 7..4, PRMBL_1 : 3..0} + +register EDCIDR1 : EDCIDR1_Type + +bitfield GICC_AIAR_Type : bits(32) = {INTID : 23..0} + +register GICC_AIAR : GICC_AIAR_Type + +bitfield AMPIDR2_Type : bits(32) = {REVISION : 7..4, JEDEC : 3..3, DES_1 : 2..0} + +register AMPIDR2 : AMPIDR2_Type + +bitfield AMPIDR4_Type : bits(32) = {SIZE : 7..4, DES_2 : 3..0} + +register AMPIDR4 : AMPIDR4_Type + +bitfield AMIIDR_Type : bits(32) = + {ProductID : 31..20, Variant : 19..16, Revision : 15..12, Implementer : 11..0} + +register AMIIDR : AMIIDR_Type + +bitfield AMPIDR3_Type : bits(32) = {REVAND : 7..4, CMOD : 3..0} + +register AMPIDR3 : AMPIDR3_Type + +bitfield AMCIDR3_Type : bits(32) = {PRMBL_3 : 7..0} + +register AMCIDR3 : AMCIDR3_Type + +bitfield AMDEVARCH_Type : bits(32) = + {ARCHITECT : 31..21, PRESENT : 20..20, REVISION : 19..16, ARCHID : 15..0} + +register AMDEVARCH : AMDEVARCH_Type + +bitfield AMPIDR0_Type : bits(32) = {PART_0 : 7..0} + +register AMPIDR0 : AMPIDR0_Type + +bitfield AMCIDR2_Type : bits(32) = {PRMBL_2 : 7..0} + +register AMCIDR2 : AMCIDR2_Type + +bitfield AMCIDR0_Type : bits(32) = {PRMBL_0 : 7..0} + +register AMCIDR0 : AMCIDR0_Type + +bitfield AMPIDR1_Type : bits(32) = {DES_0 : 7..4, PART_1 : 3..0} + +register AMPIDR1 : AMPIDR1_Type + +bitfield AMCIDR1_Type : bits(32) = {CLASS : 7..4, PRMBL_1 : 3..0} + +register AMCIDR1 : AMCIDR1_Type + +bitfield AMDEVTYPE_Type : bits(32) = {SUB : 7..4, MAJOR : 3..0} + +register AMDEVTYPE : AMDEVTYPE_Type + +type HACTLR2_Type = bits(32) + +register _HACTLR2 : HACTLR2_Type + +val HACTLR2_read : unit -> HACTLR2_Type + +function HACTLR2_read () = { + r : HACTLR2_Type = _HACTLR2; + r[31 .. 0] = Slice(ACTLR_EL2, 32, 32); + return(r) +} + +val HACTLR2_write : HACTLR2_Type -> unit + +function HACTLR2_write value_name = { + let r : HACTLR2_Type = value_name; + ACTLR_EL2[63 .. 32] = Slice(r, 0, 32); + _HACTLR2 = r; + return() +} + +bitfield PMAUTHSTATUS_Type : bits(32) = + { + RTNID : 27..26, + RTID : 25..24, + RLNID : 15..14, + RLID : 13..12, + SNID : 7..6, + SID : 5..4, + NSNID : 3..2, + NSID : 1..0 + } + +register PMAUTHSTATUS : PMAUTHSTATUS_Type + +bitfield PMCGCR0_Type : bits(32) = {CG1NC : 15..8, CG0NC : 7..0} + +register PMCGCR0 : PMCGCR0_Type + +bitfield PMCIDR0_Type : bits(32) = {PRMBL_0 : 7..0} + +register PMCIDR0 : PMCIDR0_Type + +bitfield PMCIDR1_Type : bits(32) = {CLASS : 7..4, PRMBL_1 : 3..0} + +register PMCIDR1 : PMCIDR1_Type + +bitfield PMCIDR2_Type : bits(32) = {PRMBL_2 : 7..0} + +register PMCIDR2 : PMCIDR2_Type + +bitfield PMCIDR3_Type : bits(32) = {PRMBL_3 : 7..0} + +register PMCIDR3 : PMCIDR3_Type + +bitfield PMDEVID_Type : bits(32) = {PMSS : 7..4, PCSample : 3..0} + +register PMDEVID : PMDEVID_Type + +bitfield PMDEVTYPE_Type : bits(32) = {SUB : 7..4, MAJOR : 3..0} + +register PMDEVTYPE : PMDEVTYPE_Type + +bitfield PMITCTRL_Type : bits(32) = {IME : 0..0} + +register PMITCTRL : PMITCTRL_Type + +bitfield PMLAR_Type : bits(32) = {KEY : 31..0} + +register PMLAR : PMLAR_Type + +bitfield PMPIDR0_Type : bits(32) = {PART_0 : 7..0} + +register PMPIDR0 : PMPIDR0_Type + +bitfield PMPIDR1_Type : bits(32) = {DES_0 : 7..4, PART_1 : 3..0} + +register PMPIDR1 : PMPIDR1_Type + +bitfield PMPIDR2_Type : bits(32) = {REVISION : 7..4, JEDEC : 3..3, DES_1 : 2..0} + +register PMPIDR2 : PMPIDR2_Type + +bitfield PMPIDR3_Type : bits(32) = {REVAND : 7..4, CMOD : 3..0} + +register PMPIDR3 : PMPIDR3_Type + +bitfield PMPIDR4_Type : bits(32) = {SIZE : 7..4, DES_2 : 3..0} + +register PMPIDR4 : PMPIDR4_Type + +val TTBR1_EL1_write : TTBR1_EL1_Type -> unit + +function TTBR1_EL1_write value_name = { + let r : TTBR1_EL1_Type = value_name; + TTBR1_write() = Mk_TTBR1_Type(SetSlice(64, TTBR1_read().bits, 0, Slice(r.bits, 0, 64))); + _TTBR1_EL1 = r; + return() +} + +val TTBR0_EL2_write : TTBR0_EL2_Type -> unit + +function TTBR0_EL2_write value_name = { + let r : TTBR0_EL2_Type = value_name; + HTTBR.bits[47 .. 1] = Slice(r.bits, 1, 47); + _TTBR0_EL2 = r; + return() +} + +val VTTBR_EL2_write : VTTBR_EL2_Type -> unit + +function VTTBR_EL2_write value_name = { + let r : VTTBR_EL2_Type = value_name; + VTTBR.bits[63 .. 0] = Slice(r.bits, 0, 64); + _VTTBR_EL2 = r; + return() +} + +val TTBR0_EL1_write : TTBR0_EL1_Type -> unit + +function TTBR0_EL1_write value_name = { + let r : TTBR0_EL1_Type = value_name; + TTBR0_write() = Mk_TTBR0_Type(SetSlice(64, TTBR0_read().bits, 0, Slice(r.bits, 0, 64))); + _TTBR0_EL1 = r; + return() +} + +val __get_ID_AA64MMFR2_EL1 : ID_AA64MMFR2_EL1_Type -> ID_AA64MMFR2_EL1_Type + +function __get_ID_AA64MMFR2_EL1 value_name = { + tmp : ID_AA64MMFR2_EL1_Type = value_name; + let tmp : ID_AA64MMFR2_EL1_Type = Mk_ID_AA64MMFR2_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xf00000000000, 64))); + return(tmp) +} + +val __get_VTCR_EL2 : VTCR_EL2_Type -> VTCR_EL2_Type + +function __get_VTCR_EL2 value_name = { + tmp : VTCR_EL2_Type = value_name; + let tmp : VTCR_EL2_Type = Mk_VTCR_EL2_Type(tmp.bits & not_vec(0xffffec8001900000) | ZeroExtend(0x80000000, 64)); + return(tmp) +} + +val __get_HDFGRTR_EL2 : HDFGRTR_EL2_Type -> HDFGRTR_EL2_Type + +function __get_HDFGRTR_EL2 value_name = { + tmp : HDFGRTR_EL2_Type = value_name; + let tmp : HDFGRTR_EL2_Type = Mk_HDFGRTR_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x1fe04c000300100, 64))); + return(tmp) +} + +val __get_ICV_NMIAR1_EL1 : ICV_NMIAR1_EL1_Type -> ICV_NMIAR1_EL1_Type + +function __get_ICV_NMIAR1_EL1 value_name = { + tmp : ICV_NMIAR1_EL1_Type = value_name; + let tmp : ICV_NMIAR1_EL1_Type = Mk_ICV_NMIAR1_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_SPSR_abt : SPSR_abt_Type -> SPSR_abt_Type + +function __get_SPSR_abt value_name = { + tmp : SPSR_abt_Type = value_name; + let tmp : SPSR_abt_Type = Mk_SPSR_abt_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ICH_LR_EL2 : ICH_LR_EL2_Type -> ICH_LR_EL2_Type + +function __get_ICH_LR_EL2 value_name = { + tmp : ICH_LR_EL2_Type = value_name; + let tmp : ICH_LR_EL2_Type = Mk_ICH_LR_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x700e00000000000, 64))); + return(tmp) +} + +val __get_MDCCINT_EL1 : MDCCINT_EL1_Type -> MDCCINT_EL1_Type + +function __get_MDCCINT_EL1 value_name = { + tmp : MDCCINT_EL1_Type = value_name; + let tmp : MDCCINT_EL1_Type = Mk_MDCCINT_EL1_Type(tmp.bits & not_vec(0xffffffff9fffffff)); + return(tmp) +} + +val __get_ICC_HPPIR1_EL1 : ICC_HPPIR1_EL1_Type -> ICC_HPPIR1_EL1_Type + +function __get_ICC_HPPIR1_EL1 value_name = { + tmp : ICC_HPPIR1_EL1_Type = value_name; + let tmp : ICC_HPPIR1_EL1_Type = Mk_ICC_HPPIR1_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_ICC_AP0R_EL1 : ICC_AP0R_EL1_Type -> ICC_AP0R_EL1_Type + +function __get_ICC_AP0R_EL1 value_name = { + tmp : ICC_AP0R_EL1_Type = value_name; + let tmp : ICC_AP0R_EL1_Type = tmp & not_vec(0xffffffff00000000); + return(tmp) +} + +val __get_TCR2_EL2 : TCR2_EL2_Type -> TCR2_EL2_Type + +function __get_TCR2_EL2 value_name = { + tmp : TCR2_EL2_Type = value_name; + let tmp : TCR2_EL2_Type = Mk_TCR2_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_ESR_EL1 : ESR_EL1_Type -> ESR_EL1_Type + +function __get_ESR_EL1 value_name = { + tmp : ESR_EL1_Type = value_name; + let tmp : ESR_EL1_Type = Mk_ESR_EL1_Type(tmp.bits & not_vec(0xfffff88000000000)); + return(tmp) +} + +val __get_ICV_BPR1_EL1 : ICV_BPR1_EL1_Type -> ICV_BPR1_EL1_Type + +function __get_ICV_BPR1_EL1 value_name = { + tmp : ICV_BPR1_EL1_Type = value_name; + let tmp : ICV_BPR1_EL1_Type = Mk_ICV_BPR1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_TCR_EL3 : TCR_EL3_Type -> TCR_EL3_Type + +function __get_TCR_EL3 value_name = { + tmp : TCR_EL3_Type = value_name; + let tmp : TCR_EL3_Type = Mk_TCR_EL3_Type(tmp.bits & not_vec(0xfffff180000800c0) | ZeroExtend(0x80800000, 64)); + return(tmp) +} + +val __get_PMECR_EL1 : PMECR_EL1_Type -> PMECR_EL1_Type + +function __get_PMECR_EL1 value_name = { + tmp : PMECR_EL1_Type = value_name; + let tmp : PMECR_EL1_Type = Mk_PMECR_EL1_Type(tmp.bits & not_vec(0xffffffffffffffe0)); + return(tmp) +} + +val __get_ICC_PMR_EL1 : ICC_PMR_EL1_Type -> ICC_PMR_EL1_Type + +function __get_ICC_PMR_EL1 value_name = { + tmp : ICC_PMR_EL1_Type = value_name; + let tmp : ICC_PMR_EL1_Type = Mk_ICC_PMR_EL1_Type(tmp.bits & not_vec(0xffffffffffffff00)); + return(tmp) +} + +val __get_RMR_EL1 : RMR_EL1_Type -> RMR_EL1_Type + +function __get_RMR_EL1 value_name = { + tmp : RMR_EL1_Type = value_name; + let tmp : RMR_EL1_Type = Mk_RMR_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_PMICFILTR_EL0 : PMICFILTR_EL0_Type -> PMICFILTR_EL0_Type + +function __get_PMICFILTR_EL0 value_name = { + tmp : PMICFILTR_EL0_Type = value_name; + let tmp : PMICFILTR_EL0_Type = Mk_PMICFILTR_EL0_Type(tmp.bits & not_vec(0xfbffffff020f0000)); + return(tmp) +} + +val __get_ICC_HPPIR0_EL1 : ICC_HPPIR0_EL1_Type -> ICC_HPPIR0_EL1_Type + +function __get_ICC_HPPIR0_EL1 value_name = { + tmp : ICC_HPPIR0_EL1_Type = value_name; + let tmp : ICC_HPPIR0_EL1_Type = Mk_ICC_HPPIR0_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_CNTHPS_CTL_EL2 : CNTHPS_CTL_EL2_Type -> CNTHPS_CTL_EL2_Type + +function __get_CNTHPS_CTL_EL2 value_name = { + tmp : CNTHPS_CTL_EL2_Type = value_name; + let tmp : CNTHPS_CTL_EL2_Type = Mk_CNTHPS_CTL_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_VMECID_A_EL2 : VMECID_A_EL2_Type -> VMECID_A_EL2_Type + +function __get_VMECID_A_EL2 value_name = { + tmp : VMECID_A_EL2_Type = value_name; + let tmp : VMECID_A_EL2_Type = Mk_VMECID_A_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_MECID_RL_A_EL3 : MECID_RL_A_EL3_Type -> MECID_RL_A_EL3_Type + +function __get_MECID_RL_A_EL3 value_name = { + tmp : MECID_RL_A_EL3_Type = value_name; + let tmp : MECID_RL_A_EL3_Type = Mk_MECID_RL_A_EL3_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_HSTR_EL2 : HSTR_EL2_Type -> HSTR_EL2_Type + +function __get_HSTR_EL2 value_name = { + tmp : HSTR_EL2_Type = value_name; + let tmp : HSTR_EL2_Type = Mk_HSTR_EL2_Type(tmp.bits & not_vec(0xffffffffffff4010)); + return(tmp) +} + +val __get_PMOVSCLR_EL0 : PMOVSCLR_EL0_Type -> PMOVSCLR_EL0_Type + +function __get_PMOVSCLR_EL0 value_name = { + tmp : PMOVSCLR_EL0_Type = value_name; + let tmp : PMOVSCLR_EL0_Type = Mk_PMOVSCLR_EL0_Type(tmp.bits & not_vec(0xfffffffe00000000)); + return(tmp) +} + +val __get_HAFGRTR_EL2 : HAFGRTR_EL2_Type -> HAFGRTR_EL2_Type + +function __get_HAFGRTR_EL2 value_name = { + tmp : HAFGRTR_EL2_Type = value_name; + let tmp : HAFGRTR_EL2_Type = Mk_HAFGRTR_EL2_Type(tmp.bits & not_vec(0xfffc00000001ffe0)); + return(tmp) +} + +val __get_ICC_BPR0_EL1 : ICC_BPR0_EL1_Type -> ICC_BPR0_EL1_Type + +function __get_ICC_BPR0_EL1 value_name = { + tmp : ICC_BPR0_EL1_Type = value_name; + let tmp : ICC_BPR0_EL1_Type = Mk_ICC_BPR0_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ACCDATA_EL1 : ACCDATA_EL1_Type -> ACCDATA_EL1_Type + +function __get_ACCDATA_EL1 value_name = { + tmp : ACCDATA_EL1_Type = value_name; + let tmp : ACCDATA_EL1_Type = Mk_ACCDATA_EL1_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_OSDLR_EL1 : OSDLR_EL1_Type -> OSDLR_EL1_Type + +function __get_OSDLR_EL1 value_name = { + tmp : OSDLR_EL1_Type = value_name; + if not_bool(IsFeatureImplemented(FEAT_DoubleLock)) then { + tmp = Mk_OSDLR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x1, 64))) + }; + let tmp : OSDLR_EL1_Type = Mk_OSDLR_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_SCTLR_EL1 : SCTLR_EL1_Type -> SCTLR_EL1_Type + +function __get_SCTLR_EL1 value_name = { + tmp : SCTLR_EL1_Type = value_name; + tmp : SCTLR_EL1_Type = Mk_SCTLR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x400020000, 64))); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN")) then { + tmp = Mk_SCTLR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x0, 64)) | ZeroExtend(0x20, 64)) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD")) then { + tmp = Mk_SCTLR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x80, 64))) + }; + return(tmp) +} + +val __get_PMSSCR_EL1 : PMSSCR_EL1_Type -> PMSSCR_EL1_Type + +function __get_PMSSCR_EL1 value_name = { + tmp : PMSSCR_EL1_Type = value_name; + let tmp : PMSSCR_EL1_Type = Mk_PMSSCR_EL1_Type(tmp.bits & not_vec(0xfffffffefffffffe)); + return(tmp) +} + +val __get_LORID_EL1 : LORID_EL1_Type -> LORID_EL1_Type + +function __get_LORID_EL1 value_name = { + tmp : LORID_EL1_Type = value_name; + let tmp : LORID_EL1_Type = Mk_LORID_EL1_Type(tmp.bits & not_vec(0xffffffffff00ff00)); + return(tmp) +} + +val __get_CONTEXTIDR_EL2 : CONTEXTIDR_EL2_Type -> CONTEXTIDR_EL2_Type + +function __get_CONTEXTIDR_EL2 value_name = { + tmp : CONTEXTIDR_EL2_Type = value_name; + let tmp : CONTEXTIDR_EL2_Type = Mk_CONTEXTIDR_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_FPSR : FPSR_Type -> FPSR_Type + +function __get_FPSR value_name = { + tmp : FPSR_Type = value_name; + let tmp : FPSR_Type = Mk_FPSR_Type(tmp.bits & not_vec(0xffffffff07ffff60)); + return(tmp) +} + +val __get_CNTP_TVAL_EL0 : CNTP_TVAL_EL0_Type -> CNTP_TVAL_EL0_Type + +function __get_CNTP_TVAL_EL0 value_name = { + tmp : CNTP_TVAL_EL0_Type = value_name; + let tmp : CNTP_TVAL_EL0_Type = Mk_CNTP_TVAL_EL0_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ID_AA64MMFR4_EL1 : ID_AA64MMFR4_EL1_Type -> ID_AA64MMFR4_EL1_Type + +function __get_ID_AA64MMFR4_EL1 value_name = { + tmp : ID_AA64MMFR4_EL1_Type = value_name; + let tmp : ID_AA64MMFR4_EL1_Type = Mk_ID_AA64MMFR4_EL1_Type(tmp.bits & not_vec(0xffffffffffffff0f)); + return(tmp) +} + +val __get_ICH_EISR_EL2 : ICH_EISR_EL2_Type -> ICH_EISR_EL2_Type + +function __get_ICH_EISR_EL2 value_name = { + tmp : ICH_EISR_EL2_Type = value_name; + let tmp : ICH_EISR_EL2_Type = Mk_ICH_EISR_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_MIDR_EL1 : MIDR_EL1_Type -> MIDR_EL1_Type + +function __get_MIDR_EL1 value_name = { + tmp : MIDR_EL1_Type = value_name; + let tmp : MIDR_EL1_Type = Mk_MIDR_EL1_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ICC_RPR_EL1 : ICC_RPR_EL1_Type -> ICC_RPR_EL1_Type + +function __get_ICC_RPR_EL1 value_name = { + tmp : ICC_RPR_EL1_Type = value_name; + let tmp : ICC_RPR_EL1_Type = Mk_ICC_RPR_EL1_Type(tmp.bits & not_vec(0x3fffffffffffff00)); + return(tmp) +} + +val __get_ICH_ELRSR_EL2 : ICH_ELRSR_EL2_Type -> ICH_ELRSR_EL2_Type + +function __get_ICH_ELRSR_EL2 value_name = { + tmp : ICH_ELRSR_EL2_Type = value_name; + let tmp : ICH_ELRSR_EL2_Type = Mk_ICH_ELRSR_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_VBAR_EL2 : VBAR_EL2_Type -> VBAR_EL2_Type + +function __get_VBAR_EL2 value_name = { + tmp : VBAR_EL2_Type = value_name; + let tmp : VBAR_EL2_Type = tmp & not_vec(ZeroExtend(0x1f, 64)); + return(tmp) +} + +val __get_HFGITR_EL2 : HFGITR_EL2_Type -> HFGITR_EL2_Type + +function __get_HFGITR_EL2 value_name = { + tmp : HFGITR_EL2_Type = value_name; + let tmp : HFGITR_EL2_Type = Mk_HFGITR_EL2_Type(tmp.bits & not_vec(0xe000000000000000)); + return(tmp) +} + +val __get_CNTHVS_CTL_EL2 : CNTHVS_CTL_EL2_Type -> CNTHVS_CTL_EL2_Type + +function __get_CNTHVS_CTL_EL2 value_name = { + tmp : CNTHVS_CTL_EL2_Type = value_name; + let tmp : CNTHVS_CTL_EL2_Type = Mk_CNTHVS_CTL_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ID_AA64PFR1_EL1 : ID_AA64PFR1_EL1_Type -> ID_AA64PFR1_EL1_Type + +function __get_ID_AA64PFR1_EL1 value_name = { + tmp : ID_AA64PFR1_EL1_Type = value_name; + let tmp : ID_AA64PFR1_EL1_Type = Mk_ID_AA64PFR1_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xf00000, 64))); + return(tmp) +} + +val __get_ICH_AP1R_EL2 : ICH_AP1R_EL2_Type -> ICH_AP1R_EL2_Type + +function __get_ICH_AP1R_EL2 value_name = { + tmp : ICH_AP1R_EL2_Type = value_name; + let tmp : ICH_AP1R_EL2_Type = Mk_ICH_AP1R_EL2_Type(tmp.bits & not_vec(0x7fffffff00000000)); + return(tmp) +} + +val __get_SDER32_EL2 : SDER32_EL2_Type -> SDER32_EL2_Type + +function __get_SDER32_EL2 value_name = { + tmp : SDER32_EL2_Type = value_name; + let tmp : SDER32_EL2_Type = Mk_SDER32_EL2_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_VSTCR_EL2 : VSTCR_EL2_Type -> VSTCR_EL2_Type + +function __get_VSTCR_EL2 value_name = { + tmp : VSTCR_EL2_Type = value_name; + let tmp : VSTCR_EL2_Type = Mk_VSTCR_EL2_Type(tmp.bits & not_vec(0xfffffffd1fff3f00) | ZeroExtend(0x80000000, 64)); + return(tmp) +} + +val __get_ID_AA64ISAR0_EL1 : ID_AA64ISAR0_EL1_Type -> ID_AA64ISAR0_EL1_Type + +function __get_ID_AA64ISAR0_EL1 value_name = { + tmp : ID_AA64ISAR0_EL1_Type = value_name; + tmp : ID_AA64ISAR0_EL1_Type = Mk_ID_AA64ISAR0_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xf, 64))); + if (PSTATE.EL == EL2 | PSTATE.EL == EL1) & SCR_EL3[TME] == 0b0 | (PSTATE.EL == EL1 & EL2Enabled()) & HCR_EL2[TME] == 0b0 then { + tmp = Mk_ID_AA64ISAR0_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xf000000, 64))) + }; + return(tmp) +} + +val __get_PMMIR_EL1 : PMMIR_EL1_Type -> PMMIR_EL1_Type + +function __get_PMMIR_EL1 value_name = { + tmp : PMMIR_EL1_Type = value_name; + let tmp : PMMIR_EL1_Type = Mk_PMMIR_EL1_Type(tmp.bits & not_vec(0xfffffffff0000000)); + return(tmp) +} + +val __get_ICV_IAR0_EL1 : ICV_IAR0_EL1_Type -> ICV_IAR0_EL1_Type + +function __get_ICV_IAR0_EL1 value_name = { + tmp : ICV_IAR0_EL1_Type = value_name; + let tmp : ICV_IAR0_EL1_Type = Mk_ICV_IAR0_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_ICC_IGRPEN1_EL1 : ICC_IGRPEN1_EL1_Type -> ICC_IGRPEN1_EL1_Type + +function __get_ICC_IGRPEN1_EL1 value_name = { + tmp : ICC_IGRPEN1_EL1_Type = value_name; + let tmp : ICC_IGRPEN1_EL1_Type = Mk_ICC_IGRPEN1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_ICC_IGRPEN1_EL1_NS : ICC_IGRPEN1_EL1_Type -> ICC_IGRPEN1_EL1_Type + +function __get_ICC_IGRPEN1_EL1_NS value_name = { + tmp : ICC_IGRPEN1_EL1_Type = value_name; + let tmp : ICC_IGRPEN1_EL1_Type = Mk_ICC_IGRPEN1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_ICC_IGRPEN1_EL1_S : ICC_IGRPEN1_EL1_Type -> ICC_IGRPEN1_EL1_Type + +function __get_ICC_IGRPEN1_EL1_S value_name = { + tmp : ICC_IGRPEN1_EL1_Type = value_name; + let tmp : ICC_IGRPEN1_EL1_Type = Mk_ICC_IGRPEN1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_GPTBR_EL3 : GPTBR_EL3_Type -> GPTBR_EL3_Type + +function __get_GPTBR_EL3 value_name = { + tmp : GPTBR_EL3_Type = value_name; + let tmp : GPTBR_EL3_Type = Mk_GPTBR_EL3_Type(tmp.bits & not_vec(0xffffff0000000000)); + return(tmp) +} + +val __get_MDCCSR_EL0 : MDCCSR_EL0_Type -> MDCCSR_EL0_Type + +function __get_MDCCSR_EL0 value_name = { + tmp : MDCCSR_EL0_Type = value_name; + let tmp : MDCCSR_EL0_Type = Mk_MDCCSR_EL0_Type(tmp.bits & not_vec(0xffffffff9fffffff)); + return(tmp) +} + +val __get_TTBR0_EL3 : TTBR0_EL3_Type -> TTBR0_EL3_Type + +function __get_TTBR0_EL3 value_name = { + tmp : TTBR0_EL3_Type = value_name; + let tmp : TTBR0_EL3_Type = Mk_TTBR0_EL3_Type(tmp.bits & not_vec(0xff00000000000000)); + return(tmp) +} + +val __get_DBGBCR_EL1 : DBGBCR_EL1_Type -> DBGBCR_EL1_Type + +function __get_DBGBCR_EL1 value_name = { + tmp : DBGBCR_EL1_Type = value_name; + let tmp : DBGBCR_EL1_Type = Mk_DBGBCR_EL1_Type(tmp.bits & not_vec(0xffffffff00001e10)); + return(tmp) +} + +val __get_PMCCFILTR_EL0 : PMCCFILTR_EL0_Type -> PMCCFILTR_EL0_Type + +function __get_PMCCFILTR_EL0 value_name = { + tmp : PMCCFILTR_EL0_Type = value_name; + let tmp : PMCCFILTR_EL0_Type = Mk_PMCCFILTR_EL0_Type(tmp.bits & not_vec(0xffffffff020fffff)); + return(tmp) +} + +val __get_ICC_NMIAR1_EL1 : ICC_NMIAR1_EL1_Type -> ICC_NMIAR1_EL1_Type + +function __get_ICC_NMIAR1_EL1 value_name = { + tmp : ICC_NMIAR1_EL1_Type = value_name; + let tmp : ICC_NMIAR1_EL1_Type = Mk_ICC_NMIAR1_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_DBGCLAIMSET_EL1 : DBGCLAIMSET_EL1_Type -> DBGCLAIMSET_EL1_Type + +function __get_DBGCLAIMSET_EL1 value_name = { + tmp : DBGCLAIMSET_EL1_Type = value_name; + let tmp : DBGCLAIMSET_EL1_Type = Mk_DBGCLAIMSET_EL1_Type(tmp.bits & not_vec(0xffffffffffffff00)); + return(tmp) +} + +val __get_ICC_SRE_EL1 : ICC_SRE_EL1_Type -> ICC_SRE_EL1_Type + +function __get_ICC_SRE_EL1 value_name = { + tmp : ICC_SRE_EL1_Type = value_name; + let tmp : ICC_SRE_EL1_Type = Mk_ICC_SRE_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ICC_SRE_EL1_NS : ICC_SRE_EL1_Type -> ICC_SRE_EL1_Type + +function __get_ICC_SRE_EL1_NS value_name = { + tmp : ICC_SRE_EL1_Type = value_name; + let tmp : ICC_SRE_EL1_Type = Mk_ICC_SRE_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ICC_SRE_EL1_S : ICC_SRE_EL1_Type -> ICC_SRE_EL1_Type + +function __get_ICC_SRE_EL1_S value_name = { + tmp : ICC_SRE_EL1_Type = value_name; + let tmp : ICC_SRE_EL1_Type = Mk_ICC_SRE_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ICH_AP0R_EL2 : ICH_AP0R_EL2_Type -> ICH_AP0R_EL2_Type + +function __get_ICH_AP0R_EL2 value_name = { + tmp : ICH_AP0R_EL2_Type = value_name; + let tmp : ICH_AP0R_EL2_Type = Mk_ICH_AP0R_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ICC_IAR0_EL1 : ICC_IAR0_EL1_Type -> ICC_IAR0_EL1_Type + +function __get_ICC_IAR0_EL1 value_name = { + tmp : ICC_IAR0_EL1_Type = value_name; + let tmp : ICC_IAR0_EL1_Type = Mk_ICC_IAR0_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_ESR_EL2 : ESR_EL2_Type -> ESR_EL2_Type + +function __get_ESR_EL2 value_name = { + tmp : ESR_EL2_Type = value_name; + let tmp : ESR_EL2_Type = Mk_ESR_EL2_Type(tmp.bits & not_vec(0xfffff80000000000)); + return(tmp) +} + +val __get_CONTEXTIDR_EL1 : CONTEXTIDR_EL1_Type -> CONTEXTIDR_EL1_Type + +function __get_CONTEXTIDR_EL1 value_name = { + tmp : CONTEXTIDR_EL1_Type = value_name; + let tmp : CONTEXTIDR_EL1_Type = Mk_CONTEXTIDR_EL1_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_PMUACR_EL1 : PMUACR_EL1_Type -> PMUACR_EL1_Type + +function __get_PMUACR_EL1 value_name = { + tmp : PMUACR_EL1_Type = value_name; + let tmp : PMUACR_EL1_Type = Mk_PMUACR_EL1_Type(tmp.bits & not_vec(0xfffffffe00000000)); + return(tmp) +} + +val __get_DSPSR_EL0 : DSPSR_EL0_Type -> DSPSR_EL0_Type + +function __get_DSPSR_EL0 value_name = { + tmp : DSPSR_EL0_Type = value_name; + let tmp : DSPSR_EL0_Type = Mk_DSPSR_EL0_Type(tmp.bits & not_vec(0xfffffff800000000)); + return(tmp) +} + +val __get_RMR_EL2 : RMR_EL2_Type -> RMR_EL2_Type + +function __get_RMR_EL2 value_name = { + tmp : RMR_EL2_Type = value_name; + let tmp : RMR_EL2_Type = Mk_RMR_EL2_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_VNCR_EL2 : VNCR_EL2_Type -> VNCR_EL2_Type + +function __get_VNCR_EL2 value_name = { + tmp : VNCR_EL2_Type = value_name; + let tmp : VNCR_EL2_Type = Mk_VNCR_EL2_Type(tmp.bits & not_vec(ZeroExtend(0xfff, 64))); + return(tmp) +} + +val __get_PMINTENCLR_EL1 : PMINTENCLR_EL1_Type -> PMINTENCLR_EL1_Type + +function __get_PMINTENCLR_EL1 value_name = { + tmp : PMINTENCLR_EL1_Type = value_name; + let tmp : PMINTENCLR_EL1_Type = Mk_PMINTENCLR_EL1_Type(tmp.bits & not_vec(0xfffffffe00000000)); + return(tmp) +} + +val __get_PMSELR_EL0 : PMSELR_EL0_Type -> PMSELR_EL0_Type + +function __get_PMSELR_EL0 value_name = { + tmp : PMSELR_EL0_Type = value_name; + let tmp : PMSELR_EL0_Type = Mk_PMSELR_EL0_Type(tmp.bits & not_vec(0xffffffffffffffe0)); + return(tmp) +} + +val __get_ICC_CTLR_EL1 : ICC_CTLR_EL1_Type -> ICC_CTLR_EL1_Type + +function __get_ICC_CTLR_EL1 value_name = { + tmp : ICC_CTLR_EL1_Type = value_name; + let tmp : ICC_CTLR_EL1_Type = Mk_ICC_CTLR_EL1_Type(tmp.bits & not_vec(0xfffffffffff300bc)); + return(tmp) +} + +val __get_ICC_CTLR_EL1_NS : ICC_CTLR_EL1_Type -> ICC_CTLR_EL1_Type + +function __get_ICC_CTLR_EL1_NS value_name = { + tmp : ICC_CTLR_EL1_Type = value_name; + let tmp : ICC_CTLR_EL1_Type = Mk_ICC_CTLR_EL1_Type(tmp.bits & not_vec(0xfffffffffff300bc)); + return(tmp) +} + +val __get_ICC_CTLR_EL1_S : ICC_CTLR_EL1_Type -> ICC_CTLR_EL1_Type + +function __get_ICC_CTLR_EL1_S value_name = { + tmp : ICC_CTLR_EL1_Type = value_name; + let tmp : ICC_CTLR_EL1_Type = Mk_ICC_CTLR_EL1_Type(tmp.bits & not_vec(0xfffffffffff300bc)); + return(tmp) +} + +val __get_ICC_AP1R_EL1 : ICC_AP1R_EL1_Type -> ICC_AP1R_EL1_Type + +function __get_ICC_AP1R_EL1 value_name = { + tmp : ICC_AP1R_EL1_Type = value_name; + let tmp : ICC_AP1R_EL1_Type = Mk_ICC_AP1R_EL1_Type(tmp.bits & not_vec(0x7fffffff00000000)); + return(tmp) +} + +val __get_ICC_AP1R_EL1_NS : ICC_AP1R_EL1_Type -> ICC_AP1R_EL1_Type + +function __get_ICC_AP1R_EL1_NS value_name = { + tmp : ICC_AP1R_EL1_Type = value_name; + let tmp : ICC_AP1R_EL1_Type = Mk_ICC_AP1R_EL1_Type(tmp.bits & not_vec(0x7fffffff00000000)); + return(tmp) +} + +val __get_ICC_AP1R_EL1_S : ICC_AP1R_EL1_Type -> ICC_AP1R_EL1_Type + +function __get_ICC_AP1R_EL1_S value_name = { + tmp : ICC_AP1R_EL1_Type = value_name; + let tmp : ICC_AP1R_EL1_Type = Mk_ICC_AP1R_EL1_Type(tmp.bits & not_vec(0x7fffffff00000000)); + return(tmp) +} + +val __get_CNTP_CTL_EL0 : CNTP_CTL_EL0_Type -> CNTP_CTL_EL0_Type + +function __get_CNTP_CTL_EL0 value_name = { + tmp : CNTP_CTL_EL0_Type = value_name; + let tmp : CNTP_CTL_EL0_Type = Mk_CNTP_CTL_EL0_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_HFGITR2_EL2 : HFGITR2_EL2_Type -> HFGITR2_EL2_Type + +function __get_HFGITR2_EL2 value_name = { + tmp : HFGITR2_EL2_Type = value_name; + let tmp : HFGITR2_EL2_Type = tmp & not_vec(0xffffffffffffffff); + return(tmp) +} + +val __get_CNTHV_TVAL_EL2 : CNTHV_TVAL_EL2_Type -> CNTHV_TVAL_EL2_Type + +function __get_CNTHV_TVAL_EL2 value_name = { + tmp : CNTHV_TVAL_EL2_Type = value_name; + let tmp : CNTHV_TVAL_EL2_Type = Mk_CNTHV_TVAL_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_SPSR_irq : SPSR_irq_Type -> SPSR_irq_Type + +function __get_SPSR_irq value_name = { + tmp : SPSR_irq_Type = value_name; + let tmp : SPSR_irq_Type = Mk_SPSR_irq_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ICH_MISR_EL2 : ICH_MISR_EL2_Type -> ICH_MISR_EL2_Type + +function __get_ICH_MISR_EL2 value_name = { + tmp : ICH_MISR_EL2_Type = value_name; + let tmp : ICH_MISR_EL2_Type = Mk_ICH_MISR_EL2_Type(tmp.bits & not_vec(0xffffffffffffff00)); + return(tmp) +} + +val __get_CSSELR_EL1 : CSSELR_EL1_Type -> CSSELR_EL1_Type + +function __get_CSSELR_EL1 value_name = { + tmp : CSSELR_EL1_Type = value_name; + let tmp : CSSELR_EL1_Type = Mk_CSSELR_EL1_Type(tmp.bits & not_vec(0xffffffffffffffe0)); + return(tmp) +} + +val __get_ICV_RPR_EL1 : ICV_RPR_EL1_Type -> ICV_RPR_EL1_Type + +function __get_ICV_RPR_EL1 value_name = { + tmp : ICV_RPR_EL1_Type = value_name; + let tmp : ICV_RPR_EL1_Type = Mk_ICV_RPR_EL1_Type(tmp.bits & not_vec(0x7fffffffffffff00)); + return(tmp) +} + +val __get_PFAR_EL2 : PFAR_EL2_Type -> PFAR_EL2_Type + +function __get_PFAR_EL2 value_name = { + tmp : PFAR_EL2_Type = value_name; + let tmp : PFAR_EL2_Type = Mk_PFAR_EL2_Type(tmp.bits & not_vec(0x3f00000000000000)); + return(tmp) +} + +val __get_ICV_PMR_EL1 : ICV_PMR_EL1_Type -> ICV_PMR_EL1_Type + +function __get_ICV_PMR_EL1 value_name = { + tmp : ICV_PMR_EL1_Type = value_name; + let tmp : ICV_PMR_EL1_Type = Mk_ICV_PMR_EL1_Type(tmp.bits & not_vec(0xffffffffffffff00)); + return(tmp) +} + +val __get_MFAR_EL3 : MFAR_EL3_Type -> MFAR_EL3_Type + +function __get_MFAR_EL3 value_name = { + tmp : MFAR_EL3_Type = value_name; + let tmp : MFAR_EL3_Type = Mk_MFAR_EL3_Type(tmp.bits & not_vec(0x3f00000000000000)); + return(tmp) +} + +val __get_SPSR_EL2 : SPSR_EL2_Type -> SPSR_EL2_Type + +function __get_SPSR_EL2 value_name = { + tmp : SPSR_EL2_Type = value_name; + let tmp : SPSR_EL2_Type = Mk_SPSR_EL2_Type(tmp.bits & not_vec(0xfffffff800000000)); + return(tmp) +} + +val __get_TCR_EL1 : TCR_EL1_Type -> TCR_EL1_Type + +function __get_TCR_EL1 value_name = { + tmp : TCR_EL1_Type = value_name; + let tmp : TCR_EL1_Type = Mk_TCR_EL1_Type(tmp.bits & not_vec(0xc000000800000000)); + return(tmp) +} + +val __get_ICV_HPPIR0_EL1 : ICV_HPPIR0_EL1_Type -> ICV_HPPIR0_EL1_Type + +function __get_ICV_HPPIR0_EL1 value_name = { + tmp : ICV_HPPIR0_EL1_Type = value_name; + let tmp : ICV_HPPIR0_EL1_Type = Mk_ICV_HPPIR0_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_SCTLR2_EL1 : SCTLR2_EL1_Type -> SCTLR2_EL1_Type + +function __get_SCTLR2_EL1 value_name = { + tmp : SCTLR2_EL1_Type = value_name; + let tmp : SCTLR2_EL1_Type = Mk_SCTLR2_EL1_Type(tmp.bits & not_vec(0xffffffffffffff83)); + return(tmp) +} + +val __get_ICV_BPR0_EL1 : ICV_BPR0_EL1_Type -> ICV_BPR0_EL1_Type + +function __get_ICV_BPR0_EL1 value_name = { + tmp : ICV_BPR0_EL1_Type = value_name; + let tmp : ICV_BPR0_EL1_Type = Mk_ICV_BPR0_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ISR_EL1 : ISR_EL1_Type -> ISR_EL1_Type + +function __get_ISR_EL1 value_name = { + tmp : ISR_EL1_Type = value_name; + let tmp : ISR_EL1_Type = Mk_ISR_EL1_Type(tmp.bits & not_vec(0xfffffffffffff83f)); + return(tmp) +} + +val __get_MECIDR_EL2 : MECIDR_EL2_Type -> MECIDR_EL2_Type + +function __get_MECIDR_EL2 value_name = { + tmp : MECIDR_EL2_Type = value_name; + let tmp : MECIDR_EL2_Type = Mk_MECIDR_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_PMINTENSET_EL1 : PMINTENSET_EL1_Type -> PMINTENSET_EL1_Type + +function __get_PMINTENSET_EL1 value_name = { + tmp : PMINTENSET_EL1_Type = value_name; + let tmp : PMINTENSET_EL1_Type = Mk_PMINTENSET_EL1_Type(tmp.bits & not_vec(0xfffffffe00000000)); + return(tmp) +} + +val __get_SMIDR_EL1 : SMIDR_EL1_Type -> SMIDR_EL1_Type + +function __get_SMIDR_EL1 value_name = { + tmp : SMIDR_EL1_Type = value_name; + let tmp : SMIDR_EL1_Type = Mk_SMIDR_EL1_Type(tmp.bits & not_vec(0xffffffff00007000)); + return(tmp) +} + +val __get_HFGWTR_EL2 : HFGWTR_EL2_Type -> HFGWTR_EL2_Type + +function __get_HFGWTR_EL2 value_name = { + tmp : HFGWTR_EL2_Type = value_name; + let tmp : HFGWTR_EL2_Type = Mk_HFGWTR_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x845001624c604, 64))); + return(tmp) +} + +val __get_SMPRI_EL1 : SMPRI_EL1_Type -> SMPRI_EL1_Type + +function __get_SMPRI_EL1 value_name = { + tmp : SMPRI_EL1_Type = value_name; + let tmp : SMPRI_EL1_Type = Mk_SMPRI_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_PMUSERENR_EL0 : PMUSERENR_EL0_Type -> PMUSERENR_EL0_Type + +function __get_PMUSERENR_EL0 value_name = { + tmp : PMUSERENR_EL0_Type = value_name; + let tmp : PMUSERENR_EL0_Type = Mk_PMUSERENR_EL0_Type(tmp.bits & not_vec(0xffffffffffffff80)); + return(tmp) +} + +val __get_SCTLR2_EL2 : SCTLR2_EL2_Type -> SCTLR2_EL2_Type + +function __get_SCTLR2_EL2 value_name = { + tmp : SCTLR2_EL2_Type = value_name; + let tmp : SCTLR2_EL2_Type = Mk_SCTLR2_EL2_Type(tmp.bits & not_vec(0xffffffffffffff81)); + return(tmp) +} + +val __get_PMOVSSET_EL0 : PMOVSSET_EL0_Type -> PMOVSSET_EL0_Type + +function __get_PMOVSSET_EL0 value_name = { + tmp : PMOVSSET_EL0_Type = value_name; + let tmp : PMOVSSET_EL0_Type = Mk_PMOVSSET_EL0_Type(tmp.bits & not_vec(0xfffffffe00000000)); + return(tmp) +} + +val __get_ICV_AP0R_EL1 : ICV_AP0R_EL1_Type -> ICV_AP0R_EL1_Type + +function __get_ICV_AP0R_EL1 value_name = { + tmp : ICV_AP0R_EL1_Type = value_name; + let tmp : ICV_AP0R_EL1_Type = tmp & not_vec(0xffffffff00000000); + return(tmp) +} + +val __get_SCTLR_EL3 : SCTLR_EL3_Type -> SCTLR_EL3_Type + +function __get_SCTLR_EL3 value_name = { + tmp : SCTLR_EL3_Type = value_name; + let tmp : SCTLR_EL3_Type = Mk_SCTLR_EL3_Type(tmp.bits & not_vec(0x97d7e4cf0512c780) | ZeroExtend(0x30850030, 64)); + return(tmp) +} + +val __get_VBAR_EL1 : VBAR_EL1_Type -> VBAR_EL1_Type + +function __get_VBAR_EL1 value_name = { + tmp : VBAR_EL1_Type = value_name; + let tmp : VBAR_EL1_Type = tmp & not_vec(ZeroExtend(0x1f, 64)); + return(tmp) +} + +val __get_CNTFRQ_EL0 : CNTFRQ_EL0_Type -> CNTFRQ_EL0_Type + +function __get_CNTFRQ_EL0 value_name = { + tmp : CNTFRQ_EL0_Type = value_name; + let tmp : CNTFRQ_EL0_Type = tmp & not_vec(0xffffffff00000000); + return(tmp) +} + +val __get_ICV_CTLR_EL1 : ICV_CTLR_EL1_Type -> ICV_CTLR_EL1_Type + +function __get_ICV_CTLR_EL1 value_name = { + tmp : ICV_CTLR_EL1_Type = value_name; + let tmp : ICV_CTLR_EL1_Type = Mk_ICV_CTLR_EL1_Type(tmp.bits & not_vec(0xfffffffffff300fc)); + return(tmp) +} + +val __get_MECID_A0_EL2 : MECID_A0_EL2_Type -> MECID_A0_EL2_Type + +function __get_MECID_A0_EL2 value_name = { + tmp : MECID_A0_EL2_Type = value_name; + let tmp : MECID_A0_EL2_Type = Mk_MECID_A0_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_ICV_IAR1_EL1 : ICV_IAR1_EL1_Type -> ICV_IAR1_EL1_Type + +function __get_ICV_IAR1_EL1 value_name = { + tmp : ICV_IAR1_EL1_Type = value_name; + let tmp : ICV_IAR1_EL1_Type = Mk_ICV_IAR1_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_CPACR_EL1 : CPACR_EL1_Type -> CPACR_EL1_Type + +function __get_CPACR_EL1 value_name = { + tmp : CPACR_EL1_Type = value_name; + let tmp : CPACR_EL1_Type = Mk_CPACR_EL1_Type(tmp.bits & not_vec(0xffffffff4cccffff)); + return(tmp) +} + +val __get_DBGDTRRX_EL0 : DBGDTRRX_EL0_Type -> DBGDTRRX_EL0_Type + +function __get_DBGDTRRX_EL0 value_name = { + tmp : DBGDTRRX_EL0_Type = value_name; + let tmp : DBGDTRRX_EL0_Type = tmp & not_vec(0xffffffff00000000); + return(tmp) +} + +val __get_SPSR_EL1 : SPSR_EL1_Type -> SPSR_EL1_Type + +function __get_SPSR_EL1 value_name = { + tmp : SPSR_EL1_Type = value_name; + let tmp : SPSR_EL1_Type = Mk_SPSR_EL1_Type(tmp.bits & not_vec(0xfffffff800000000)); + return(tmp) +} + +val __get_FPEXC32_EL2 : FPEXC32_EL2_Type -> FPEXC32_EL2_Type + +function __get_FPEXC32_EL2 value_name = { + tmp : FPEXC32_EL2_Type = value_name; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Invalid Operation floating-point exceptions")) then { + tmp = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x1, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Divide by Zero floating-point exceptions")) then { + tmp = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x2, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Overflow floating-point exceptions")) then { + tmp = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x4, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Underflow floating-point exceptions")) then { + tmp = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x8, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Inexact floating-point exceptions")) then { + tmp = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x10, 64))) + }; + tmp : FPEXC32_EL2_Type = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(0xffffffff9bfff860) | ZeroExtend(0x700, 64)); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of Input Denormal floating-point exceptions")) then { + tmp = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x80, 64))) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_trapping of floating-point exceptions")) then { + tmp = Mk_FPEXC32_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x4000000, 64))) + }; + return(tmp) +} + +val __get_MDSCR_EL1 : MDSCR_EL1_Type -> MDSCR_EL1_Type + +function __get_MDSCR_EL1 value_name = { + tmp : MDSCR_EL1_Type = value_name; + let tmp : MDSCR_EL1_Type = Mk_MDSCR_EL1_Type(tmp.bits & not_vec(0xfffffff213100f82)); + return(tmp) +} + +val __get_SPSR_fiq : SPSR_fiq_Type -> SPSR_fiq_Type + +function __get_SPSR_fiq value_name = { + tmp : SPSR_fiq_Type = value_name; + let tmp : SPSR_fiq_Type = Mk_SPSR_fiq_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_MECID_P0_EL2 : MECID_P0_EL2_Type -> MECID_P0_EL2_Type + +function __get_MECID_P0_EL2 value_name = { + tmp : MECID_P0_EL2_Type = value_name; + let tmp : MECID_P0_EL2_Type = Mk_MECID_P0_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_GPCCR_EL3 : GPCCR_EL3_Type -> GPCCR_EL3_Type + +function __get_GPCCR_EL3 value_name = { + tmp : GPCCR_EL3_Type = value_name; + let tmp : GPCCR_EL3_Type = Mk_GPCCR_EL3_Type(tmp.bits & not_vec(0xffffffffff0c00f8)); + return(tmp) +} + +val __get_HDFGWTR2_EL2 : HDFGWTR2_EL2_Type -> HDFGWTR2_EL2_Type + +function __get_HDFGWTR2_EL2 value_name = { + tmp : HDFGWTR2_EL2_Type = value_name; + let tmp : HDFGWTR2_EL2_Type = Mk_HDFGWTR2_EL2_Type(tmp.bits & not_vec(0xffffffffffd60040)); + return(tmp) +} + +val __get_TCR2_EL1 : TCR2_EL1_Type -> TCR2_EL1_Type + +function __get_TCR2_EL1 value_name = { + tmp : TCR2_EL1_Type = value_name; + let tmp : TCR2_EL1_Type = Mk_TCR2_EL1_Type(tmp.bits & not_vec(0xffffffffffff33c0)); + return(tmp) +} + +val __get_DCZID_EL0 : DCZID_EL0_Type -> DCZID_EL0_Type + +function __get_DCZID_EL0 value_name = { + tmp : DCZID_EL0_Type = value_name; + let tmp : DCZID_EL0_Type = Mk_DCZID_EL0_Type(tmp.bits & not_vec(0xffffffffffffffe0)); + return(tmp) +} + +val __get_VSTTBR_EL2 : VSTTBR_EL2_Type -> VSTTBR_EL2_Type + +function __get_VSTTBR_EL2 value_name = { + tmp : VSTTBR_EL2_Type = value_name; + let tmp : VSTTBR_EL2_Type = Mk_VSTTBR_EL2_Type(tmp.bits & not_vec(0xff00000000000000)); + return(tmp) +} + +val __get_TRFCR_EL2 : TRFCR_EL2_Type -> TRFCR_EL2_Type + +function __get_TRFCR_EL2 value_name = { + tmp : TRFCR_EL2_Type = value_name; + let tmp : TRFCR_EL2_Type = Mk_TRFCR_EL2_Type(tmp.bits & not_vec(0xffffffffffffff94)); + return(tmp) +} + +val __get_CNTHP_CTL_EL2 : CNTHP_CTL_EL2_Type -> CNTHP_CTL_EL2_Type + +function __get_CNTHP_CTL_EL2 value_name = { + tmp : CNTHP_CTL_EL2_Type = value_name; + let tmp : CNTHP_CTL_EL2_Type = Mk_CNTHP_CTL_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_CNTHVS_TVAL_EL2 : CNTHVS_TVAL_EL2_Type -> CNTHVS_TVAL_EL2_Type + +function __get_CNTHVS_TVAL_EL2 value_name = { + tmp : CNTHVS_TVAL_EL2_Type = value_name; + let tmp : CNTHVS_TVAL_EL2_Type = Mk_CNTHVS_TVAL_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_CNTHP_TVAL_EL2 : CNTHP_TVAL_EL2_Type -> CNTHP_TVAL_EL2_Type + +function __get_CNTHP_TVAL_EL2 value_name = { + tmp : CNTHP_TVAL_EL2_Type = value_name; + let tmp : CNTHP_TVAL_EL2_Type = Mk_CNTHP_TVAL_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_CNTHCTL_EL2 : CNTHCTL_EL2_Type -> CNTHCTL_EL2_Type + +function __get_CNTHCTL_EL2 value_name = { + tmp : CNTHCTL_EL2_Type = value_name; + let tmp : CNTHCTL_EL2_Type = Mk_CNTHCTL_EL2_Type(tmp.bits & not_vec(0xfffffffffff00000)); + return(tmp) +} + +val __get_MDRAR_EL1 : MDRAR_EL1_Type -> MDRAR_EL1_Type + +function __get_MDRAR_EL1 value_name = { + tmp : MDRAR_EL1_Type = value_name; + let tmp : MDRAR_EL1_Type = Mk_MDRAR_EL1_Type(tmp.bits & not_vec(0xff00000000000ffc)); + return(tmp) +} + +val __get_OSDTRRX_EL1 : OSDTRRX_EL1_Type -> OSDTRRX_EL1_Type + +function __get_OSDTRRX_EL1 value_name = { + tmp : OSDTRRX_EL1_Type = value_name; + let tmp : OSDTRRX_EL1_Type = tmp & not_vec(0xffffffff00000000); + return(tmp) +} + +val __get_PFAR_EL1 : PFAR_EL1_Type -> PFAR_EL1_Type + +function __get_PFAR_EL1 value_name = { + tmp : PFAR_EL1_Type = value_name; + let tmp : PFAR_EL1_Type = Mk_PFAR_EL1_Type(tmp.bits & not_vec(0x3f00000000000000)); + return(tmp) +} + +val __get_IFSR32_EL2 : IFSR32_EL2_Type -> IFSR32_EL2_Type + +function __get_IFSR32_EL2 value_name = { + tmp : IFSR32_EL2_Type = value_name; + let tmp : IFSR32_EL2_Type = Mk_IFSR32_EL2_Type(tmp.bits & not_vec(0xfffffffffffee9c0)); + return(tmp) +} + +val __get_ICC_IGRPEN1_EL3 : ICC_IGRPEN1_EL3_Type -> ICC_IGRPEN1_EL3_Type + +function __get_ICC_IGRPEN1_EL3 value_name = { + tmp : ICC_IGRPEN1_EL3_Type = value_name; + let tmp : ICC_IGRPEN1_EL3_Type = Mk_ICC_IGRPEN1_EL3_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_LORSA_EL1 : LORSA_EL1_Type -> LORSA_EL1_Type + +function __get_LORSA_EL1 value_name = { + tmp : LORSA_EL1_Type = value_name; + let tmp : LORSA_EL1_Type = Mk_LORSA_EL1_Type(tmp.bits & not_vec(0xff0000000000fffe)); + return(tmp) +} + +val __get_DBGWCR_EL1 : DBGWCR_EL1_Type -> DBGWCR_EL1_Type + +function __get_DBGWCR_EL1 value_name = { + tmp : DBGWCR_EL1_Type = value_name; + let tmp : DBGWCR_EL1_Type = Mk_DBGWCR_EL1_Type(tmp.bits & not_vec(0xffffffff00e00000)); + return(tmp) +} + +val __get_ESR_EL3 : ESR_EL3_Type -> ESR_EL3_Type + +function __get_ESR_EL3 value_name = { + tmp : ESR_EL3_Type = value_name; + let tmp : ESR_EL3_Type = Mk_ESR_EL3_Type(tmp.bits & not_vec(0xfffff88000000000)); + return(tmp) +} + +val __get_PMEVTYPER_EL0 : PMEVTYPER_EL0_Type -> PMEVTYPER_EL0_Type + +function __get_PMEVTYPER_EL0 value_name = { + tmp : PMEVTYPER_EL0_Type = value_name; + let tmp : PMEVTYPER_EL0_Type = Mk_PMEVTYPER_EL0_Type(tmp.bits & not_vec(ZeroExtend(0xbfff000000f0000, 64))); + return(tmp) +} + +val __get_CNTV_CTL_EL0 : CNTV_CTL_EL0_Type -> CNTV_CTL_EL0_Type + +function __get_CNTV_CTL_EL0 value_name = { + tmp : CNTV_CTL_EL0_Type = value_name; + let tmp : CNTV_CTL_EL0_Type = Mk_CNTV_CTL_EL0_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_TRFCR_EL1 : TRFCR_EL1_Type -> TRFCR_EL1_Type + +function __get_TRFCR_EL1 value_name = { + tmp : TRFCR_EL1_Type = value_name; + let tmp : TRFCR_EL1_Type = Mk_TRFCR_EL1_Type(tmp.bits & not_vec(0xffffffffffffff9c)); + return(tmp) +} + +val __get_OSDTRTX_EL1 : OSDTRTX_EL1_Type -> OSDTRTX_EL1_Type + +function __get_OSDTRTX_EL1 value_name = { + tmp : OSDTRTX_EL1_Type = value_name; + let tmp : OSDTRTX_EL1_Type = tmp & not_vec(0xffffffff00000000); + return(tmp) +} + +val __get_ICH_VMCR_EL2 : ICH_VMCR_EL2_Type -> ICH_VMCR_EL2_Type + +function __get_ICH_VMCR_EL2 value_name = { + tmp : ICH_VMCR_EL2_Type = value_name; + let tmp : ICH_VMCR_EL2_Type = Mk_ICH_VMCR_EL2_Type(tmp.bits & not_vec(0xffffffff0003fde0)); + return(tmp) +} + +val __get_VPIDR_EL2 : VPIDR_EL2_Type -> VPIDR_EL2_Type + +function __get_VPIDR_EL2 value_name = { + tmp : VPIDR_EL2_Type = value_name; + let tmp : VPIDR_EL2_Type = Mk_VPIDR_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ICC_CTLR_EL3 : ICC_CTLR_EL3_Type -> ICC_CTLR_EL3_Type + +function __get_ICC_CTLR_EL3 value_name = { + tmp : ICC_CTLR_EL3_Type = value_name; + let tmp : ICC_CTLR_EL3_Type = Mk_ICC_CTLR_EL3_Type(tmp.bits & not_vec(0xfffffffffff10080)); + return(tmp) +} + +val __get_SCTLR_EL2 : SCTLR_EL2_Type -> SCTLR_EL2_Type + +function __get_SCTLR_EL2 value_name = { + tmp : SCTLR_EL2_Type = value_name; + let tmp : SCTLR_EL2_Type = Mk_SCTLR_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x400020200, 64))); + return(tmp) +} + +val __get_OSLSR_EL1 : OSLSR_EL1_Type -> OSLSR_EL1_Type + +function __get_OSLSR_EL1 value_name = { + tmp : OSLSR_EL1_Type = value_name; + let tmp : OSLSR_EL1_Type = Mk_OSLSR_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_MDCR_EL3 : MDCR_EL3_Type -> MDCR_EL3_Type + +function __get_MDCR_EL3 value_name = { + tmp : MDCR_EL3_Type = value_name; + let tmp : MDCR_EL3_Type = Mk_MDCR_EL3_Type(tmp.bits & not_vec(0xffff80802740012a)); + return(tmp) +} + +val __get_SCTLR2_EL3 : SCTLR2_EL3_Type -> SCTLR2_EL3_Type + +function __get_SCTLR2_EL3 value_name = { + tmp : SCTLR2_EL3_Type = value_name; + let tmp : SCTLR2_EL3_Type = Mk_SCTLR2_EL3_Type(tmp.bits & not_vec(0xffffffffffffffe5)); + return(tmp) +} + +val __get_PMCNTENSET_EL0 : PMCNTENSET_EL0_Type -> PMCNTENSET_EL0_Type + +function __get_PMCNTENSET_EL0 value_name = { + tmp : PMCNTENSET_EL0_Type = value_name; + let tmp : PMCNTENSET_EL0_Type = Mk_PMCNTENSET_EL0_Type(tmp.bits & not_vec(0xfffffffe00000000)); + return(tmp) +} + +val __get_ICC_SRE_EL2 : ICC_SRE_EL2_Type -> ICC_SRE_EL2_Type + +function __get_ICC_SRE_EL2 value_name = { + tmp : ICC_SRE_EL2_Type = value_name; + let tmp : ICC_SRE_EL2_Type = Mk_ICC_SRE_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_CNTPS_CTL_EL1 : CNTPS_CTL_EL1_Type -> CNTPS_CTL_EL1_Type + +function __get_CNTPS_CTL_EL1 value_name = { + tmp : CNTPS_CTL_EL1_Type = value_name; + let tmp : CNTPS_CTL_EL1_Type = Mk_CNTPS_CTL_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_DACR32_EL2 : DACR32_EL2_Type -> DACR32_EL2_Type + +function __get_DACR32_EL2 value_name = { + tmp : DACR32_EL2_Type = value_name; + let tmp : DACR32_EL2_Type = Mk_DACR32_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_LORC_EL1 : LORC_EL1_Type -> LORC_EL1_Type + +function __get_LORC_EL1 value_name = { + tmp : LORC_EL1_Type = value_name; + let tmp : LORC_EL1_Type = Mk_LORC_EL1_Type(tmp.bits & not_vec(0xfffffffffffffc02)); + return(tmp) +} + +val __get_ID_AA64PFR2_EL1 : ID_AA64PFR2_EL1_Type -> ID_AA64PFR2_EL1_Type + +function __get_ID_AA64PFR2_EL1 value_name = { + tmp : ID_AA64PFR2_EL1_Type = value_name; + let tmp : ID_AA64PFR2_EL1_Type = Mk_ID_AA64PFR2_EL1_Type(tmp.bits & not_vec(0xfffffffffffff000)); + return(tmp) +} + +val __get_TCR_EL2 : TCR_EL2_Type -> TCR_EL2_Type + +function __get_TCR_EL2 value_name = { + tmp : TCR_EL2_Type = value_name; + let tmp : TCR_EL2_Type = Mk_TCR_EL2_Type(tmp.bits & not_vec(0xc000000800000040)); + return(tmp) +} + +val __get_CCSIDR2_EL1 : CCSIDR2_EL1_Type -> CCSIDR2_EL1_Type + +function __get_CCSIDR2_EL1 value_name = { + tmp : CCSIDR2_EL1_Type = value_name; + let tmp : CCSIDR2_EL1_Type = Mk_CCSIDR2_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_CTR_EL0 : CTR_EL0_Type -> CTR_EL0_Type + +function __get_CTR_EL0 value_name = { + tmp : CTR_EL0_Type = value_name; + let tmp : CTR_EL0_Type = Mk_CTR_EL0_Type(tmp.bits & not_vec(0xffffffc040003ff0) | ZeroExtend(0x80000000, 64)); + return(tmp) +} + +val __get_SPSR_und : SPSR_und_Type -> SPSR_und_Type + +function __get_SPSR_und value_name = { + tmp : SPSR_und_Type = value_name; + let tmp : SPSR_und_Type = Mk_SPSR_und_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ID_AA64ISAR2_EL1 : ID_AA64ISAR2_EL1_Type -> ID_AA64ISAR2_EL1_Type + +function __get_ID_AA64ISAR2_EL1 value_name = { + tmp : ID_AA64ISAR2_EL1_Type = value_name; + let tmp : ID_AA64ISAR2_EL1_Type = Mk_ID_AA64ISAR2_EL1_Type(tmp.bits & not_vec(0xff00f00000000000)); + return(tmp) +} + +val __get_CPTR_EL3 : CPTR_EL3_Type -> CPTR_EL3_Type + +function __get_CPTR_EL3 value_name = { + tmp : CPTR_EL3_Type = value_name; + let tmp : CPTR_EL3_Type = Mk_CPTR_EL3_Type(tmp.bits & not_vec(0xffffffff3fefeaff)); + return(tmp) +} + +val __get_HFGRTR2_EL2 : HFGRTR2_EL2_Type -> HFGRTR2_EL2_Type + +function __get_HFGRTR2_EL2 value_name = { + tmp : HFGRTR2_EL2_Type = value_name; + let tmp : HFGRTR2_EL2_Type = Mk_HFGRTR2_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_RMR_EL3 : RMR_EL3_Type -> RMR_EL3_Type + +function __get_RMR_EL3 value_name = { + tmp : RMR_EL3_Type = value_name; + let tmp : RMR_EL3_Type = Mk_RMR_EL3_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_ICH_HCR_EL2 : ICH_HCR_EL2_Type -> ICH_HCR_EL2_Type + +function __get_ICH_HCR_EL2 value_name = { + tmp : ICH_HCR_EL2_Type = value_name; + let tmp : ICH_HCR_EL2_Type = Mk_ICH_HCR_EL2_Type(tmp.bits & not_vec(0xffffffff07ff0200)); + return(tmp) +} + +val __get_ICC_IGRPEN0_EL1 : ICC_IGRPEN0_EL1_Type -> ICC_IGRPEN0_EL1_Type + +function __get_ICC_IGRPEN0_EL1 value_name = { + tmp : ICC_IGRPEN0_EL1_Type = value_name; + let tmp : ICC_IGRPEN0_EL1_Type = Mk_ICC_IGRPEN0_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_CNTHPS_TVAL_EL2 : CNTHPS_TVAL_EL2_Type -> CNTHPS_TVAL_EL2_Type + +function __get_CNTHPS_TVAL_EL2 value_name = { + tmp : CNTHPS_TVAL_EL2_Type = value_name; + let tmp : CNTHPS_TVAL_EL2_Type = Mk_CNTHPS_TVAL_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ICC_BPR1_EL1 : ICC_BPR1_EL1_Type -> ICC_BPR1_EL1_Type + +function __get_ICC_BPR1_EL1 value_name = { + tmp : ICC_BPR1_EL1_Type = value_name; + let tmp : ICC_BPR1_EL1_Type = Mk_ICC_BPR1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ICC_BPR1_EL1_NS : ICC_BPR1_EL1_Type -> ICC_BPR1_EL1_Type + +function __get_ICC_BPR1_EL1_NS value_name = { + tmp : ICC_BPR1_EL1_Type = value_name; + let tmp : ICC_BPR1_EL1_Type = Mk_ICC_BPR1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ICC_BPR1_EL1_S : ICC_BPR1_EL1_Type -> ICC_BPR1_EL1_Type + +function __get_ICC_BPR1_EL1_S value_name = { + tmp : ICC_BPR1_EL1_Type = value_name; + let tmp : ICC_BPR1_EL1_Type = Mk_ICC_BPR1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_MECID_A1_EL2 : MECID_A1_EL2_Type -> MECID_A1_EL2_Type + +function __get_MECID_A1_EL2 value_name = { + tmp : MECID_A1_EL2_Type = value_name; + let tmp : MECID_A1_EL2_Type = Mk_MECID_A1_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_ID_AA64MMFR0_EL1 : ID_AA64MMFR0_EL1_Type -> ID_AA64MMFR0_EL1_Type + +function __get_ID_AA64MMFR0_EL1 value_name = { + tmp : ID_AA64MMFR0_EL1_Type = value_name; + let tmp : ID_AA64MMFR0_EL1_Type = Mk_ID_AA64MMFR0_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xff000000000000, 64))); + return(tmp) +} + +val __get_PMCR_EL0 : PMCR_EL0_Type -> PMCR_EL0_Type + +function __get_PMCR_EL0 value_name = { + tmp : PMCR_EL0_Type = value_name; + tmp : PMCR_EL0_Type = Mk_PMCR_EL0_Type(tmp.bits & not_vec(0xfffffffe00000506)); + if not_bool(__IMPDEF_boolean("the implementation includes a PMU event export bus")) then { + tmp = Mk_PMCR_EL0_Type(tmp.bits & not_vec(ZeroExtend(0x10, 64))) + }; + if not_bool(not_bool(IsFeatureImplemented(FEAT_PMUv3p7))) then { + tmp = Mk_PMCR_EL0_Type(tmp.bits & not_vec(ZeroExtend(0xff000000, 64))) + }; + return(tmp) +} + +val __get_HDFGRTR2_EL2 : HDFGRTR2_EL2_Type -> HDFGRTR2_EL2_Type + +function __get_HDFGRTR2_EL2 value_name = { + tmp : HDFGRTR2_EL2_Type = value_name; + let tmp : HDFGRTR2_EL2_Type = Mk_HDFGRTR2_EL2_Type(tmp.bits & not_vec(0xfffffffffff00000)); + return(tmp) +} + +val __get_DBGPRCR_EL1 : DBGPRCR_EL1_Type -> DBGPRCR_EL1_Type + +function __get_DBGPRCR_EL1 value_name = { + tmp : DBGPRCR_EL1_Type = value_name; + let tmp : DBGPRCR_EL1_Type = Mk_DBGPRCR_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_PMCNTENCLR_EL0 : PMCNTENCLR_EL0_Type -> PMCNTENCLR_EL0_Type + +function __get_PMCNTENCLR_EL0 value_name = { + tmp : PMCNTENCLR_EL0_Type = value_name; + let tmp : PMCNTENCLR_EL0_Type = Mk_PMCNTENCLR_EL0_Type(tmp.bits & not_vec(0xfffffffe00000000)); + return(tmp) +} + +val __get_SDER32_EL3 : SDER32_EL3_Type -> SDER32_EL3_Type + +function __get_SDER32_EL3 value_name = { + tmp : SDER32_EL3_Type = value_name; + let tmp : SDER32_EL3_Type = Mk_SDER32_EL3_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_HPFAR_EL2 : HPFAR_EL2_Type -> HPFAR_EL2_Type + +function __get_HPFAR_EL2 value_name = { + tmp : HPFAR_EL2_Type = value_name; + let tmp : HPFAR_EL2_Type = Mk_HPFAR_EL2_Type(tmp.bits & not_vec(0x7fff00000000000f)); + return(tmp) +} + +val __get_VMPIDR_EL2 : VMPIDR_EL2_Type -> VMPIDR_EL2_Type + +function __get_VMPIDR_EL2 value_name = { + tmp : VMPIDR_EL2_Type = value_name; + let tmp : VMPIDR_EL2_Type = Mk_VMPIDR_EL2_Type(tmp.bits & not_vec(0xffffff003e000000) | ZeroExtend(0x80000000, 64)); + return(tmp) +} + +val __get_ID_AA64MMFR3_EL1 : ID_AA64MMFR3_EL1_Type -> ID_AA64MMFR3_EL1_Type + +function __get_ID_AA64MMFR3_EL1 value_name = { + tmp : ID_AA64MMFR3_EL1_Type = value_name; + let tmp : ID_AA64MMFR3_EL1_Type = Mk_ID_AA64MMFR3_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xf000000000000, 64))); + return(tmp) +} + +val __get_ICH_VTR_EL2 : ICH_VTR_EL2_Type -> ICH_VTR_EL2_Type + +function __get_ICH_VTR_EL2 value_name = { + tmp : ICH_VTR_EL2_Type = value_name; + let tmp : ICH_VTR_EL2_Type = Mk_ICH_VTR_EL2_Type(tmp.bits & not_vec(0xffffffff0003ffe0)); + return(tmp) +} + +val __get_MDSELR_EL1 : MDSELR_EL1_Type -> MDSELR_EL1_Type + +function __get_MDSELR_EL1 value_name = { + tmp : MDSELR_EL1_Type = value_name; + let tmp : MDSELR_EL1_Type = Mk_MDSELR_EL1_Type(tmp.bits & not_vec(0xffffffffffffffcf)); + return(tmp) +} + +val __get_VBAR_EL3 : VBAR_EL3_Type -> VBAR_EL3_Type + +function __get_VBAR_EL3 value_name = { + tmp : VBAR_EL3_Type = value_name; + let tmp : VBAR_EL3_Type = tmp & not_vec(ZeroExtend(0x7ff, 64)); + return(tmp) +} + +val __get_MDCR_EL2 : MDCR_EL2_Type -> MDCR_EL2_Type + +function __get_MDCR_EL2 value_name = { + tmp : MDCR_EL2_Type = value_name; + let tmp : MDCR_EL2_Type = Mk_MDCR_EL2_Type(tmp.bits & not_vec(0xfffff4ef03750000)); + return(tmp) +} + +val __get_CNTKCTL_EL1 : CNTKCTL_EL1_Type -> CNTKCTL_EL1_Type + +function __get_CNTKCTL_EL1 value_name = { + tmp : CNTKCTL_EL1_Type = value_name; + let tmp : CNTKCTL_EL1_Type = Mk_CNTKCTL_EL1_Type(tmp.bits & not_vec(0xfffffffffffdfc00)); + return(tmp) +} + +val __get_LORN_EL1 : LORN_EL1_Type -> LORN_EL1_Type + +function __get_LORN_EL1 value_name = { + tmp : LORN_EL1_Type = value_name; + let tmp : LORN_EL1_Type = Mk_LORN_EL1_Type(tmp.bits & not_vec(0xffffffffffffff00)); + return(tmp) +} + +val __get_ICV_IGRPEN0_EL1 : ICV_IGRPEN0_EL1_Type -> ICV_IGRPEN0_EL1_Type + +function __get_ICV_IGRPEN0_EL1 value_name = { + tmp : ICV_IGRPEN0_EL1_Type = value_name; + let tmp : ICV_IGRPEN0_EL1_Type = Mk_ICV_IGRPEN0_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_SPSR_EL3 : SPSR_EL3_Type -> SPSR_EL3_Type + +function __get_SPSR_EL3 value_name = { + tmp : SPSR_EL3_Type = value_name; + let tmp : SPSR_EL3_Type = Mk_SPSR_EL3_Type(tmp.bits & not_vec(0xfffffff800000000)); + return(tmp) +} + +val __get_CCSIDR_EL1 : CCSIDR_EL1_Type -> CCSIDR_EL1_Type + +function __get_CCSIDR_EL1 value_name = { + tmp : CCSIDR_EL1_Type = value_name; + let tmp : CCSIDR_EL1_Type = Mk_CCSIDR_EL1_Type(tmp.bits & not_vec(0xff00000000000000)); + return(tmp) +} + +val __get_VMECID_P_EL2 : VMECID_P_EL2_Type -> VMECID_P_EL2_Type + +function __get_VMECID_P_EL2 value_name = { + tmp : VMECID_P_EL2_Type = value_name; + let tmp : VMECID_P_EL2_Type = Mk_VMECID_P_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_OSECCR_EL1 : OSECCR_EL1_Type -> OSECCR_EL1_Type + +function __get_OSECCR_EL1 value_name = { + tmp : OSECCR_EL1_Type = value_name; + let tmp : OSECCR_EL1_Type = Mk_OSECCR_EL1_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_DBGVCR32_EL2 : DBGVCR32_EL2_Type -> DBGVCR32_EL2_Type + +function __get_DBGVCR32_EL2 value_name = { + tmp : DBGVCR32_EL2_Type = value_name; + let tmp : DBGVCR32_EL2_Type = Mk_DBGVCR32_EL2_Type(tmp.bits & not_vec(0xffffffff21ff2321)); + return(tmp) +} + +val __get_HFGRTR_EL2 : HFGRTR_EL2_Type -> HFGRTR_EL2_Type + +function __get_HFGRTR_EL2 value_name = { + tmp : HFGRTR_EL2_Type = value_name; + let tmp : HFGRTR_EL2_Type = Mk_HFGRTR_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x8000000000000, 64))); + return(tmp) +} + +val __get_CPTR_EL2 : CPTR_EL2_Type -> CPTR_EL2_Type + +function __get_CPTR_EL2 value_name = { + tmp : CPTR_EL2_Type = value_name; + let tmp : CPTR_EL2_Type = Mk_CPTR_EL2_Type(tmp.bits & not_vec(0xffffffff0ccc4000)); + return(tmp) +} + +val __get_CLIDR_EL1 : CLIDR_EL1_Type -> CLIDR_EL1_Type + +function __get_CLIDR_EL1 value_name = { + tmp : CLIDR_EL1_Type = value_name; + let tmp : CLIDR_EL1_Type = Mk_CLIDR_EL1_Type(tmp.bits & not_vec(0xffff800000000000)); + return(tmp) +} + +val __get_HCRX_EL2 : HCRX_EL2_Type -> HCRX_EL2_Type + +function __get_HCRX_EL2 value_name = { + tmp : HCRX_EL2_Type = value_name; + let tmp : HCRX_EL2_Type = Mk_HCRX_EL2_Type(tmp.bits & not_vec(0xffffffffff803000)); + return(tmp) +} + +val __get_ICV_IGRPEN1_EL1 : ICV_IGRPEN1_EL1_Type -> ICV_IGRPEN1_EL1_Type + +function __get_ICV_IGRPEN1_EL1 value_name = { + tmp : ICV_IGRPEN1_EL1_Type = value_name; + let tmp : ICV_IGRPEN1_EL1_Type = Mk_ICV_IGRPEN1_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_HFGWTR2_EL2 : HFGWTR2_EL2_Type -> HFGWTR2_EL2_Type + +function __get_HFGWTR2_EL2 value_name = { + tmp : HFGWTR2_EL2_Type = value_name; + let tmp : HFGWTR2_EL2_Type = Mk_HFGWTR2_EL2_Type(tmp.bits & not_vec(0xfffffffffffffffa)); + return(tmp) +} + +val __get_MECID_P1_EL2 : MECID_P1_EL2_Type -> MECID_P1_EL2_Type + +function __get_MECID_P1_EL2 value_name = { + tmp : MECID_P1_EL2_Type = value_name; + let tmp : MECID_P1_EL2_Type = Mk_MECID_P1_EL2_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_SPMSELR_EL0 : SPMSELR_EL0_Type -> SPMSELR_EL0_Type + +function __get_SPMSELR_EL0 value_name = { + tmp : SPMSELR_EL0_Type = value_name; + let tmp : SPMSELR_EL0_Type = Mk_SPMSELR_EL0_Type(tmp.bits & not_vec(0xfffffffffffffc0c)); + return(tmp) +} + +val __get_DBGAUTHSTATUS_EL1 : DBGAUTHSTATUS_EL1_Type -> DBGAUTHSTATUS_EL1_Type + +function __get_DBGAUTHSTATUS_EL1 value_name = { + tmp : DBGAUTHSTATUS_EL1_Type = value_name; + let tmp : DBGAUTHSTATUS_EL1_Type = Mk_DBGAUTHSTATUS_EL1_Type(tmp.bits & not_vec(0xfffffffff0ff0f00)); + return(tmp) +} + +val __get_SCR_EL3 : SCR_EL3_Type -> SCR_EL3_Type + +function __get_SCR_EL3 value_name = { + tmp : SCR_EL3_Type = value_name; + tmp : SCR_EL3_Type = Mk_SCR_EL3_Type(tmp.bits & not_vec(0xb744000001c00040) | ZeroExtend(0x30, 64)); + if not_bool(HaveAArch32EL(EL1) | HaveAArch32EL(EL2)) then { + tmp = Mk_SCR_EL3_Type(tmp.bits & not_vec(ZeroExtend(0x0, 64)) | ZeroExtend(0x400, 64)) + }; + return(tmp) +} + +val __get_ICC_SRE_EL3 : ICC_SRE_EL3_Type -> ICC_SRE_EL3_Type + +function __get_ICC_SRE_EL3 value_name = { + tmp : ICC_SRE_EL3_Type = value_name; + let tmp : ICC_SRE_EL3_Type = Mk_ICC_SRE_EL3_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_HDFGWTR_EL2 : HDFGWTR_EL2_Type -> HDFGWTR_EL2_Type + +function __get_HDFGWTR_EL2 value_name = { + tmp : HDFGWTR_EL2_Type = value_name; + let tmp : HDFGWTR_EL2_Type = Mk_HDFGWTR_EL2_Type(tmp.bits & not_vec(0x8dfc89c440400240)); + return(tmp) +} + +val __get_CNTPS_TVAL_EL1 : CNTPS_TVAL_EL1_Type -> CNTPS_TVAL_EL1_Type + +function __get_CNTPS_TVAL_EL1 value_name = { + tmp : CNTPS_TVAL_EL1_Type = value_name; + let tmp : CNTPS_TVAL_EL1_Type = Mk_CNTPS_TVAL_EL1_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ID_AA64AFR1_EL1 : ID_AA64AFR1_EL1_Type -> ID_AA64AFR1_EL1_Type + +function __get_ID_AA64AFR1_EL1 value_name = { + tmp : ID_AA64AFR1_EL1_Type = value_name; + let tmp : ID_AA64AFR1_EL1_Type = tmp & not_vec(0xffffffffffffffff); + return(tmp) +} + +val __get_ICV_AP1R_EL1 : ICV_AP1R_EL1_Type -> ICV_AP1R_EL1_Type + +function __get_ICV_AP1R_EL1 value_name = { + tmp : ICV_AP1R_EL1_Type = value_name; + let tmp : ICV_AP1R_EL1_Type = Mk_ICV_AP1R_EL1_Type(tmp.bits & not_vec(0x7fffffff00000000)); + return(tmp) +} + +val __get_LOREA_EL1 : LOREA_EL1_Type -> LOREA_EL1_Type + +function __get_LOREA_EL1 value_name = { + tmp : LOREA_EL1_Type = value_name; + let tmp : LOREA_EL1_Type = Mk_LOREA_EL1_Type(tmp.bits & not_vec(0xff0000000000ffff)); + return(tmp) +} + +val __get_CNTV_TVAL_EL0 : CNTV_TVAL_EL0_Type -> CNTV_TVAL_EL0_Type + +function __get_CNTV_TVAL_EL0 value_name = { + tmp : CNTV_TVAL_EL0_Type = value_name; + let tmp : CNTV_TVAL_EL0_Type = Mk_CNTV_TVAL_EL0_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_ICC_IAR1_EL1 : ICC_IAR1_EL1_Type -> ICC_IAR1_EL1_Type + +function __get_ICC_IAR1_EL1 value_name = { + tmp : ICC_IAR1_EL1_Type = value_name; + let tmp : ICC_IAR1_EL1_Type = Mk_ICC_IAR1_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_MPIDR_EL1 : MPIDR_EL1_Type -> MPIDR_EL1_Type + +function __get_MPIDR_EL1 value_name = { + tmp : MPIDR_EL1_Type = value_name; + let tmp : MPIDR_EL1_Type = Mk_MPIDR_EL1_Type(tmp.bits & not_vec(0xffffff003e000000) | ZeroExtend(0x80000000, 64)); + return(tmp) +} + +val __get_DBGCLAIMCLR_EL1 : DBGCLAIMCLR_EL1_Type -> DBGCLAIMCLR_EL1_Type + +function __get_DBGCLAIMCLR_EL1 value_name = { + tmp : DBGCLAIMCLR_EL1_Type = value_name; + let tmp : DBGCLAIMCLR_EL1_Type = Mk_DBGCLAIMCLR_EL1_Type(tmp.bits & not_vec(0xffffffffffffff00)); + return(tmp) +} + +val __get_DBGWVR_EL1 : DBGWVR_EL1_Type -> DBGWVR_EL1_Type + +function __get_DBGWVR_EL1 value_name = { + tmp : DBGWVR_EL1_Type = value_name; + let tmp : DBGWVR_EL1_Type = Mk_DBGWVR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x3, 64))); + return(tmp) +} + +val __get_ICV_HPPIR1_EL1 : ICV_HPPIR1_EL1_Type -> ICV_HPPIR1_EL1_Type + +function __get_ICV_HPPIR1_EL1 value_name = { + tmp : ICV_HPPIR1_EL1_Type = value_name; + let tmp : ICV_HPPIR1_EL1_Type = Mk_ICV_HPPIR1_EL1_Type(tmp.bits & not_vec(0xffffffffff000000)); + return(tmp) +} + +val __get_ID_AA64AFR0_EL1 : ID_AA64AFR0_EL1_Type -> ID_AA64AFR0_EL1_Type + +function __get_ID_AA64AFR0_EL1 value_name = { + tmp : ID_AA64AFR0_EL1_Type = value_name; + let tmp : ID_AA64AFR0_EL1_Type = tmp & not_vec(0xffffffff00000000); + return(tmp) +} + +val __get_CNTHV_CTL_EL2 : CNTHV_CTL_EL2_Type -> CNTHV_CTL_EL2_Type + +function __get_CNTHV_CTL_EL2 value_name = { + tmp : CNTHV_CTL_EL2_Type = value_name; + let tmp : CNTHV_CTL_EL2_Type = Mk_CNTHV_CTL_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff8)); + return(tmp) +} + +val __get_ID_AA64ZFR0_EL1 : ID_AA64ZFR0_EL1_Type -> ID_AA64ZFR0_EL1_Type + +function __get_ID_AA64ZFR0_EL1 value_name = { + tmp : ID_AA64ZFR0_EL1_Type = value_name; + let tmp : ID_AA64ZFR0_EL1_Type = Mk_ID_AA64ZFR0_EL1_Type(tmp.bits & not_vec(0xf00f00f0f000ff00)); + return(tmp) +} + +val __get_DBGDSAR : DBGDSAR_Type -> DBGDSAR_Type + +function __get_DBGDSAR value_name = { + tmp : DBGDSAR_Type = value_name; + let tmp : DBGDSAR_Type = tmp & not_vec(0xffffffffffffffff); + return(tmp) +} + +val __get_DBGDRAR : DBGDRAR_Type -> DBGDRAR_Type + +function __get_DBGDRAR value_name = { + tmp : DBGDRAR_Type = value_name; + let tmp : DBGDRAR_Type = Mk_DBGDRAR_Type(tmp.bits & not_vec(0xff00000000000ffc)); + return(tmp) +} + +val __get_ZCR_EL3 : ZCR_EL3_Type -> ZCR_EL3_Type + +function __get_ZCR_EL3 value_name = { + tmp : ZCR_EL3_Type = value_name; + let tmp : ZCR_EL3_Type = Mk_ZCR_EL3_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_ZCR_EL1 : ZCR_EL1_Type -> ZCR_EL1_Type + +function __get_ZCR_EL1 value_name = { + tmp : ZCR_EL1_Type = value_name; + let tmp : ZCR_EL1_Type = Mk_ZCR_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_ZCR_EL2 : ZCR_EL2_Type -> ZCR_EL2_Type + +function __get_ZCR_EL2 value_name = { + tmp : ZCR_EL2_Type = value_name; + let tmp : ZCR_EL2_Type = Mk_ZCR_EL2_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_SMCR_EL3 : SMCR_EL3_Type -> SMCR_EL3_Type + +function __get_SMCR_EL3 value_name = { + tmp : SMCR_EL3_Type = value_name; + let tmp : SMCR_EL3_Type = Mk_SMCR_EL3_Type(tmp.bits & not_vec(0xffffffff3ffffff0)); + return(tmp) +} + +val __get_SMCR_EL1 : SMCR_EL1_Type -> SMCR_EL1_Type + +function __get_SMCR_EL1 value_name = { + tmp : SMCR_EL1_Type = value_name; + let tmp : SMCR_EL1_Type = Mk_SMCR_EL1_Type(tmp.bits & not_vec(0xffffffff3ffffff0)); + return(tmp) +} + +val __get_SMCR_EL2 : SMCR_EL2_Type -> SMCR_EL2_Type + +function __get_SMCR_EL2 value_name = { + tmp : SMCR_EL2_Type = value_name; + let tmp : SMCR_EL2_Type = Mk_SMCR_EL2_Type(tmp.bits & not_vec(0xffffffff3ffffff0)); + return(tmp) +} + +val __get_ID_AA64SMFR0_EL1 : ID_AA64SMFR0_EL1_Type -> ID_AA64SMFR0_EL1_Type + +function __get_ID_AA64SMFR0_EL1 value_name = { + tmp : ID_AA64SMFR0_EL1_Type = value_name; + let tmp : ID_AA64SMFR0_EL1_Type = Mk_ID_AA64SMFR0_EL1_Type(tmp.bits & not_vec(0x700e0300ffffffff)); + return(tmp) +} + +val __get_MPAMHCR_EL2 : MPAMHCR_EL2_Type -> MPAMHCR_EL2_Type + +function __get_MPAMHCR_EL2 value_name = { + tmp : MPAMHCR_EL2_Type = value_name; + let tmp : MPAMHCR_EL2_Type = Mk_MPAMHCR_EL2_Type(tmp.bits & not_vec(0xffffffff7ffffefc)); + return(tmp) +} + +val __get_MPAMIDR_EL1 : MPAMIDR_EL1_Type -> MPAMIDR_EL1_Type + +function __get_MPAMIDR_EL1 value_name = { + tmp : MPAMIDR_EL1_Type = value_name; + tmp : MPAMIDR_EL1_Type = Mk_MPAMIDR_EL1_Type(tmp.bits & not_vec(0xc1ffff00ffe10000)); + if not_bool(MPAMIDR_EL1[HAS_HCR] == 0b1) then { + tmp = Mk_MPAMIDR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x1c0000, 64))) + }; + return(tmp) +} + +val __get_MPAM2_EL2 : MPAM2_EL2_Type -> MPAM2_EL2_Type + +function __get_MPAM2_EL2 value_name = { + tmp : MPAM2_EL2_Type = value_name; + let tmp : MPAM2_EL2_Type = Mk_MPAM2_EL2_Type(tmp.bits & not_vec(0x7a38000000000000)); + return(tmp) +} + +val __get_MPAM3_EL3 : MPAM3_EL3_Type -> MPAM3_EL3_Type + +function __get_MPAM3_EL3 value_name = { + tmp : MPAM3_EL3_Type = value_name; + let tmp : MPAM3_EL3_Type = Mk_MPAM3_EL3_Type(tmp.bits & not_vec(ZeroExtend(0xc6f000000000000, 64))); + return(tmp) +} + +val __get_MPAM0_EL1 : MPAM0_EL1_Type -> MPAM0_EL1_Type + +function __get_MPAM0_EL1 value_name = { + tmp : MPAM0_EL1_Type = value_name; + let tmp : MPAM0_EL1_Type = Mk_MPAM0_EL1_Type(tmp.bits & not_vec(0xffff000000000000)); + return(tmp) +} + +val __get_MPAMSM_EL1 : MPAMSM_EL1_Type -> MPAMSM_EL1_Type + +function __get_MPAMSM_EL1 value_name = { + tmp : MPAMSM_EL1_Type = value_name; + let tmp : MPAMSM_EL1_Type = Mk_MPAMSM_EL1_Type(tmp.bits & not_vec(0xffff00ff0000ffff)); + return(tmp) +} + +val __get_MPAM1_EL1 : MPAM1_EL1_Type -> MPAM1_EL1_Type + +function __get_MPAM1_EL1 value_name = { + tmp : MPAM1_EL1_Type = value_name; + let tmp : MPAM1_EL1_Type = Mk_MPAM1_EL1_Type(tmp.bits & not_vec(0x6fbf000000000000)); + return(tmp) +} + +val __get_MPAMVPMV_EL2 : MPAMVPMV_EL2_Type -> MPAMVPMV_EL2_Type + +function __get_MPAMVPMV_EL2 value_name = { + tmp : MPAMVPMV_EL2_Type = value_name; + let tmp : MPAMVPMV_EL2_Type = Mk_MPAMVPMV_EL2_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_GMID_EL1 : GMID_EL1_Type -> GMID_EL1_Type + +function __get_GMID_EL1 value_name = { + tmp : GMID_EL1_Type = value_name; + let tmp : GMID_EL1_Type = Mk_GMID_EL1_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_TFSR_EL3 : TFSR_EL3_Type -> TFSR_EL3_Type + +function __get_TFSR_EL3 value_name = { + tmp : TFSR_EL3_Type = value_name; + let tmp : TFSR_EL3_Type = Mk_TFSR_EL3_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_TFSRE0_EL1 : TFSRE0_EL1_Type -> TFSRE0_EL1_Type + +function __get_TFSRE0_EL1 value_name = { + tmp : TFSRE0_EL1_Type = value_name; + let tmp : TFSRE0_EL1_Type = Mk_TFSRE0_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_TFSR_EL2 : TFSR_EL2_Type -> TFSR_EL2_Type + +function __get_TFSR_EL2 value_name = { + tmp : TFSR_EL2_Type = value_name; + let tmp : TFSR_EL2_Type = Mk_TFSR_EL2_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_TFSR_EL1 : TFSR_EL1_Type -> TFSR_EL1_Type + +function __get_TFSR_EL1 value_name = { + tmp : TFSR_EL1_Type = value_name; + let tmp : TFSR_EL1_Type = Mk_TFSR_EL1_Type(tmp.bits & not_vec(0xfffffffffffffffc)); + return(tmp) +} + +val __get_RGSR_EL1 : RGSR_EL1_Type -> RGSR_EL1_Type + +function __get_RGSR_EL1 value_name = { + tmp : RGSR_EL1_Type = value_name; + let tmp : RGSR_EL1_Type = Mk_RGSR_EL1_Type(tmp.bits & not_vec(0xff000000000000f0)); + return(tmp) +} + +val __get_GCR_EL1 : GCR_EL1_Type -> GCR_EL1_Type + +function __get_GCR_EL1 value_name = { + tmp : GCR_EL1_Type = value_name; + let tmp : GCR_EL1_Type = Mk_GCR_EL1_Type(tmp.bits & not_vec(0xfffffffffffe0000)); + return(tmp) +} + +val __get_AMCR_EL0 : AMCR_EL0_Type -> AMCR_EL0_Type + +function __get_AMCR_EL0 value_name = { + tmp : AMCR_EL0_Type = value_name; + let tmp : AMCR_EL0_Type = Mk_AMCR_EL0_Type(tmp.bits & not_vec(0xfffffffffffdfbff)); + return(tmp) +} + +val __get_AMCNTENSET0_EL0 : AMCNTENSET0_EL0_Type -> AMCNTENSET0_EL0_Type + +function __get_AMCNTENSET0_EL0 value_name = { + tmp : AMCNTENSET0_EL0_Type = value_name; + let tmp : AMCNTENSET0_EL0_Type = Mk_AMCNTENSET0_EL0_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_AMCNTENCLR0_EL0 : AMCNTENCLR0_EL0_Type -> AMCNTENCLR0_EL0_Type + +function __get_AMCNTENCLR0_EL0 value_name = { + tmp : AMCNTENCLR0_EL0_Type = value_name; + let tmp : AMCNTENCLR0_EL0_Type = Mk_AMCNTENCLR0_EL0_Type(tmp.bits & not_vec(0xfffffffffffffff0)); + return(tmp) +} + +val __get_AMEVTYPER0_EL0 : AMEVTYPER0_EL0_Type -> AMEVTYPER0_EL0_Type + +function __get_AMEVTYPER0_EL0 value_name = { + tmp : AMEVTYPER0_EL0_Type = value_name; + let tmp : AMEVTYPER0_EL0_Type = Mk_AMEVTYPER0_EL0_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_AMCNTENSET1_EL0 : AMCNTENSET1_EL0_Type -> AMCNTENSET1_EL0_Type + +function __get_AMCNTENSET1_EL0 value_name = { + tmp : AMCNTENSET1_EL0_Type = value_name; + let tmp : AMCNTENSET1_EL0_Type = Mk_AMCNTENSET1_EL0_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_AMCNTENCLR1_EL0 : AMCNTENCLR1_EL0_Type -> AMCNTENCLR1_EL0_Type + +function __get_AMCNTENCLR1_EL0 value_name = { + tmp : AMCNTENCLR1_EL0_Type = value_name; + let tmp : AMCNTENCLR1_EL0_Type = Mk_AMCNTENCLR1_EL0_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_AMCFGR_EL0 : AMCFGR_EL0_Type -> AMCFGR_EL0_Type + +function __get_AMCFGR_EL0 value_name = { + tmp : AMCFGR_EL0_Type = value_name; + let tmp : AMCFGR_EL0_Type = Mk_AMCFGR_EL0_Type(tmp.bits & not_vec(0xffffffff0effc000)); + return(tmp) +} + +val __get_AMUSERENR_EL0 : AMUSERENR_EL0_Type -> AMUSERENR_EL0_Type + +function __get_AMUSERENR_EL0 value_name = { + tmp : AMUSERENR_EL0_Type = value_name; + let tmp : AMUSERENR_EL0_Type = Mk_AMUSERENR_EL0_Type(tmp.bits & not_vec(0xfffffffffffffffe)); + return(tmp) +} + +val __get_AMCG1IDR_EL0 : AMCG1IDR_EL0_Type -> AMCG1IDR_EL0_Type + +function __get_AMCG1IDR_EL0 value_name = { + tmp : AMCG1IDR_EL0_Type = value_name; + let tmp : AMCG1IDR_EL0_Type = Mk_AMCG1IDR_EL0_Type(tmp.bits & not_vec(0xffffffff00000000)); + return(tmp) +} + +val __get_AMEVTYPER1_EL0 : AMEVTYPER1_EL0_Type -> AMEVTYPER1_EL0_Type + +function __get_AMEVTYPER1_EL0 value_name = { + tmp : AMEVTYPER1_EL0_Type = value_name; + let tmp : AMEVTYPER1_EL0_Type = Mk_AMEVTYPER1_EL0_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_AMCGCR_EL0 : AMCGCR_EL0_Type -> AMCGCR_EL0_Type + +function __get_AMCGCR_EL0 value_name = { + tmp : AMCGCR_EL0_Type = value_name; + let tmp : AMCGCR_EL0_Type = Mk_AMCGCR_EL0_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_PMSFCR_EL1 : PMSFCR_EL1_Type -> PMSFCR_EL1_Type + +function __get_PMSFCR_EL1 value_name = { + tmp : PMSFCR_EL1_Type = value_name; + let tmp : PMSFCR_EL1_Type = Mk_PMSFCR_EL1_Type(tmp.bits & not_vec(0xfffffffffff8ffe0)); + return(tmp) +} + +val __get_PMSIRR_EL1 : PMSIRR_EL1_Type -> PMSIRR_EL1_Type + +function __get_PMSIRR_EL1 value_name = { + tmp : PMSIRR_EL1_Type = value_name; + let tmp : PMSIRR_EL1_Type = Mk_PMSIRR_EL1_Type(tmp.bits & not_vec(0xffffffff000000fe)); + return(tmp) +} + +val __get_PMSICR_EL1 : PMSICR_EL1_Type -> PMSICR_EL1_Type + +function __get_PMSICR_EL1 value_name = { + tmp : PMSICR_EL1_Type = value_name; + let tmp : PMSICR_EL1_Type = Mk_PMSICR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xffffff00000000, 64))); + return(tmp) +} + +val __get_PMSDSFR_EL1 : PMSDSFR_EL1_Type -> PMSDSFR_EL1_Type + +function __get_PMSDSFR_EL1 value_name = { + tmp : PMSDSFR_EL1_Type = value_name; + if not_bool(__IMPDEF_boolean("filtering on Data Source [m] is supported")) then { + tmp = Mk_PMSDSFR_EL1_Type(tmp.bits & not_vec(0xffffffffffffffff)) + }; + return(tmp) +} + +val __get_PMSEVFR_EL1 : PMSEVFR_EL1_Type -> PMSEVFR_EL1_Type + +function __get_PMSEVFR_EL1 value_name = { + tmp : PMSEVFR_EL1_Type = value_name; + tmp : PMSEVFR_EL1_Type = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xffff00000001, 64))); + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 2 is optionally supported")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x4, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 4 is optionally supported")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x10, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p2)) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x40, 64))) + }; + if not_bool((IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 8 is optionally supported")) & __IMPDEF_boolean("event 8 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x100, 64))) + }; + if not_bool((IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 9 is optionally supported")) & __IMPDEF_boolean("event 9 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x200, 64))) + }; + if not_bool((IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 10 is optionally supported")) & __IMPDEF_boolean("event 10 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x400, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p1)) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x800, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_TME)) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x10000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p1) & IsFeatureImplemented(FEAT_SVE)) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x60000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 19 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x80000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 20 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x100000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 21 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x200000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 22 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x400000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 23 is implemented")) then { + tmp = Mk_PMSEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x800000, 64))) + }; + return(tmp) +} + +val __get_PMBLIMITR_EL1 : PMBLIMITR_EL1_Type -> PMBLIMITR_EL1_Type + +function __get_PMBLIMITR_EL1 value_name = { + tmp : PMBLIMITR_EL1_Type = value_name; + let tmp : PMBLIMITR_EL1_Type = Mk_PMBLIMITR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xfd8, 64))); + return(tmp) +} + +val __get_PMBSR_EL1 : PMBSR_EL1_Type -> PMBSR_EL1_Type + +function __get_PMBSR_EL1 value_name = { + tmp : PMBSR_EL1_Type = value_name; + let tmp : PMBSR_EL1_Type = Mk_PMBSR_EL1_Type(tmp.bits & not_vec(0xffffff1f03f00000)); + return(tmp) +} + +val __get_PMSCR_EL2 : PMSCR_EL2_Type -> PMSCR_EL2_Type + +function __get_PMSCR_EL2 value_name = { + tmp : PMSCR_EL2_Type = value_name; + let tmp : PMSCR_EL2_Type = Mk_PMSCR_EL2_Type(tmp.bits & not_vec(0xffffffffffffff04)); + return(tmp) +} + +val __get_PMSCR_EL1 : PMSCR_EL1_Type -> PMSCR_EL1_Type + +function __get_PMSCR_EL1 value_name = { + tmp : PMSCR_EL1_Type = value_name; + let tmp : PMSCR_EL1_Type = Mk_PMSCR_EL1_Type(tmp.bits & not_vec(0xffffffffffffff04)); + return(tmp) +} + +val __get_PMSIDR_EL1 : PMSIDR_EL1_Type -> PMSIDR_EL1_Type + +function __get_PMSIDR_EL1 value_name = { + tmp : PMSIDR_EL1_Type = value_name; + let tmp : PMSIDR_EL1_Type = Mk_PMSIDR_EL1_Type(tmp.bits & not_vec(0xfffffffffc000000)); + return(tmp) +} + +val __get_PMSNEVFR_EL1 : PMSNEVFR_EL1_Type -> PMSNEVFR_EL1_Type + +function __get_PMSNEVFR_EL1 value_name = { + tmp : PMSNEVFR_EL1_Type = value_name; + tmp : PMSNEVFR_EL1_Type = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0xffff00000001, 64))); + if not_bool(__IMPDEF_boolean("the PE supports sampling of speculative instructions")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x2, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 2 is optionally supported")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x4, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 4 is optionally supported")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x10, 64))) + }; + if not_bool((IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 8 is optionally supported")) & __IMPDEF_boolean("event 8 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x100, 64))) + }; + if not_bool((IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 9 is optionally supported")) & __IMPDEF_boolean("event 9 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x200, 64))) + }; + if not_bool((IsFeatureImplemented(FEAT_SPEv1p4) | __IMPDEF_boolean("filtering on event 10 is optionally supported")) & __IMPDEF_boolean("event 10 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x400, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p1)) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x800, 64))) + }; + if __IMPDEF_boolean("event 12 is not implemented, or filtering on event 12 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x1000, 64))) + }; + if __IMPDEF_boolean("event 13 is not implemented, or filtering on event 13 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x2000, 64))) + }; + if __IMPDEF_boolean("event 14 is not implemented, or filtering on event 14 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x4000, 64))) + }; + if __IMPDEF_boolean("event 15 is not implemented, or filtering on event 15 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x8000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_TME)) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x10000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SVE) & IsFeatureImplemented(FEAT_SPEv1p1)) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x60000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 19 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x80000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 20 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x100000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 21 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x200000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 22 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x400000, 64))) + }; + if not_bool(IsFeatureImplemented(FEAT_SPEv1p4) & __IMPDEF_boolean("event 23 is implemented")) then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x800000, 64))) + }; + if __IMPDEF_boolean("event 24 is not implemented, or filtering on event 24 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x1000000, 64))) + }; + if __IMPDEF_boolean("event 25 is not implemented, or filtering on event 25 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x2000000, 64))) + }; + if __IMPDEF_boolean("event 26 is not implemented, or filtering on event 26 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x4000000, 64))) + }; + if __IMPDEF_boolean("event 27 is not implemented, or filtering on event 27 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x8000000, 64))) + }; + if __IMPDEF_boolean("event 28 is not implemented, or filtering on event 28 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x10000000, 64))) + }; + if __IMPDEF_boolean("event 29 is not implemented, or filtering on event 29 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x20000000, 64))) + }; + if __IMPDEF_boolean("event 30 is not implemented, or filtering on event 30 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x40000000, 64))) + }; + if __IMPDEF_boolean("event 31 is not implemented, or filtering on event 31 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x80000000, 64))) + }; + if __IMPDEF_boolean("event 48 is not implemented, or filtering on event 48 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x1000000000000, 64))) + }; + if __IMPDEF_boolean("event 49 is not implemented, or filtering on event 49 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x2000000000000, 64))) + }; + if __IMPDEF_boolean("event 50 is not implemented, or filtering on event 50 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x4000000000000, 64))) + }; + if __IMPDEF_boolean("event 51 is not implemented, or filtering on event 51 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x8000000000000, 64))) + }; + if __IMPDEF_boolean("event 52 is not implemented, or filtering on event 52 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x10000000000000, 64))) + }; + if __IMPDEF_boolean("event 53 is not implemented, or filtering on event 53 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x20000000000000, 64))) + }; + if __IMPDEF_boolean("event 54 is not implemented, or filtering on event 54 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x40000000000000, 64))) + }; + if __IMPDEF_boolean("event 55 is not implemented, or filtering on event 55 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x80000000000000, 64))) + }; + if __IMPDEF_boolean("event 56 is not implemented, or filtering on event 56 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x100000000000000, 64))) + }; + if __IMPDEF_boolean("event 57 is not implemented, or filtering on event 57 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x200000000000000, 64))) + }; + if __IMPDEF_boolean("event 58 is not implemented, or filtering on event 58 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x400000000000000, 64))) + }; + if __IMPDEF_boolean("event 59 is not implemented, or filtering on event 59 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x800000000000000, 64))) + }; + if __IMPDEF_boolean("event 60 is not implemented, or filtering on event 60 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(0x1000000000000000)) + }; + if __IMPDEF_boolean("event 61 is not implemented, or filtering on event 61 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(0x2000000000000000)) + }; + if __IMPDEF_boolean("event 62 is not implemented, or filtering on event 62 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(0x4000000000000000)) + }; + if __IMPDEF_boolean("event 63 is not implemented, or filtering on event 63 is not supported") then { + tmp = Mk_PMSNEVFR_EL1_Type(tmp.bits & not_vec(0x8000000000000000)) + }; + return(tmp) +} + +val __get_PMBIDR_EL1 : PMBIDR_EL1_Type -> PMBIDR_EL1_Type + +function __get_PMBIDR_EL1 value_name = { + tmp : PMBIDR_EL1_Type = value_name; + let tmp : PMBIDR_EL1_Type = Mk_PMBIDR_EL1_Type(tmp.bits & not_vec(0xfffffffffffff0c0)); + return(tmp) +} + +val __get_PMSLATFR_EL1 : PMSLATFR_EL1_Type -> PMSLATFR_EL1_Type + +function __get_PMSLATFR_EL1 value_name = { + tmp : PMSLATFR_EL1_Type = value_name; + let tmp : PMSLATFR_EL1_Type = Mk_PMSLATFR_EL1_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_VDISR_EL2 : VDISR_EL2_Type -> VDISR_EL2_Type + +function __get_VDISR_EL2 value_name = { + tmp : VDISR_EL2_Type = value_name; + let tmp : VDISR_EL2_Type = Mk_VDISR_EL2_Type(tmp.bits & not_vec(0xffffffff7e000000)); + return(tmp) +} + +val __get_ERRIDR_EL1 : ERRIDR_EL1_Type -> ERRIDR_EL1_Type + +function __get_ERRIDR_EL1 value_name = { + tmp : ERRIDR_EL1_Type = value_name; + let tmp : ERRIDR_EL1_Type = Mk_ERRIDR_EL1_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_DISR_EL1 : DISR_EL1_Type -> DISR_EL1_Type + +function __get_DISR_EL1 value_name = { + tmp : DISR_EL1_Type = value_name; + let tmp : DISR_EL1_Type = Mk_DISR_EL1_Type(tmp.bits & not_vec(0xffffffff7e000000)); + return(tmp) +} + +val __get_ERRSELR_EL1 : ERRSELR_EL1_Type -> ERRSELR_EL1_Type + +function __get_ERRSELR_EL1 value_name = { + tmp : ERRSELR_EL1_Type = value_name; + let tmp : ERRSELR_EL1_Type = Mk_ERRSELR_EL1_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_VSESR_EL2 : VSESR_EL2_Type -> VSESR_EL2_Type + +function __get_VSESR_EL2 value_name = { + tmp : VSESR_EL2_Type = value_name; + let tmp : VSESR_EL2_Type = Mk_VSESR_EL2_Type(tmp.bits & not_vec(0xfffffffffe000000)); + return(tmp) +} + +val __get_BRBINF_EL1 : BRBINF_EL1_Type -> BRBINF_EL1_Type + +function __get_BRBINF_EL1 value_name = { + tmp : BRBINF_EL1_Type = value_name; + let tmp : BRBINF_EL1_Type = Mk_BRBINF_EL1_Type(tmp.bits & not_vec(0xffff8000fffcc01c)); + return(tmp) +} + +val __get_BRBCR_EL2 : BRBCR_EL2_Type -> BRBCR_EL2_Type + +function __get_BRBCR_EL2 value_name = { + tmp : BRBCR_EL2_Type = value_name; + let tmp : BRBCR_EL2_Type = Mk_BRBCR_EL2_Type(tmp.bits & not_vec(0xffffffffff3ffc84)); + return(tmp) +} + +val __get_BRBFCR_EL1 : BRBFCR_EL1_Type -> BRBFCR_EL1_Type + +function __get_BRBFCR_EL1 value_name = { + tmp : BRBFCR_EL1_Type = value_name; + let tmp : BRBFCR_EL1_Type = Mk_BRBFCR_EL1_Type(tmp.bits & not_vec(0xffffffffcf80ff3f)); + return(tmp) +} + +val __get_BRBINFINJ_EL1 : BRBINFINJ_EL1_Type -> BRBINFINJ_EL1_Type + +function __get_BRBINFINJ_EL1 value_name = { + tmp : BRBINFINJ_EL1_Type = value_name; + let tmp : BRBINFINJ_EL1_Type = Mk_BRBINFINJ_EL1_Type(tmp.bits & not_vec(0xffff8000fffcc01c)); + return(tmp) +} + +val __get_BRBCR_EL1 : BRBCR_EL1_Type -> BRBCR_EL1_Type + +function __get_BRBCR_EL1 value_name = { + tmp : BRBCR_EL1_Type = value_name; + let tmp : BRBCR_EL1_Type = Mk_BRBCR_EL1_Type(tmp.bits & not_vec(0xffffffffff3ffc84)); + return(tmp) +} + +val __get_BRBIDR0_EL1 : BRBIDR0_EL1_Type -> BRBIDR0_EL1_Type + +function __get_BRBIDR0_EL1 value_name = { + tmp : BRBIDR0_EL1_Type = value_name; + let tmp : BRBIDR0_EL1_Type = Mk_BRBIDR0_EL1_Type(tmp.bits & not_vec(0xffffffffffff0000)); + return(tmp) +} + +val __get_GCSPR_EL3 : GCSPR_EL3_Type -> GCSPR_EL3_Type + +function __get_GCSPR_EL3 value_name = { + tmp : GCSPR_EL3_Type = value_name; + let tmp : GCSPR_EL3_Type = Mk_GCSPR_EL3_Type(tmp.bits & not_vec(ZeroExtend(0x7, 64))); + return(tmp) +} + +val __get_GCSPR_EL1 : GCSPR_EL1_Type -> GCSPR_EL1_Type + +function __get_GCSPR_EL1 value_name = { + tmp : GCSPR_EL1_Type = value_name; + let tmp : GCSPR_EL1_Type = Mk_GCSPR_EL1_Type(tmp.bits & not_vec(ZeroExtend(0x7, 64))); + return(tmp) +} + +val __get_GCSCR_EL3 : GCSCR_EL3_Type -> GCSCR_EL3_Type + +function __get_GCSCR_EL3 value_name = { + tmp : GCSCR_EL3_Type = value_name; + let tmp : GCSCR_EL3_Type = Mk_GCSCR_EL3_Type(tmp.bits & not_vec(0xfffffffffffffc9e)); + return(tmp) +} + +val __get_GCSCR_EL1 : GCSCR_EL1_Type -> GCSCR_EL1_Type + +function __get_GCSCR_EL1 value_name = { + tmp : GCSCR_EL1_Type = value_name; + let tmp : GCSCR_EL1_Type = Mk_GCSCR_EL1_Type(tmp.bits & not_vec(0xfffffffffffffc9e)); + return(tmp) +} + +val __get_GCSPR_EL2 : GCSPR_EL2_Type -> GCSPR_EL2_Type + +function __get_GCSPR_EL2 value_name = { + tmp : GCSPR_EL2_Type = value_name; + let tmp : GCSPR_EL2_Type = Mk_GCSPR_EL2_Type(tmp.bits & not_vec(ZeroExtend(0x7, 64))); + return(tmp) +} + +val __get_GCSCR_EL2 : GCSCR_EL2_Type -> GCSCR_EL2_Type + +function __get_GCSCR_EL2 value_name = { + tmp : GCSCR_EL2_Type = value_name; + let tmp : GCSCR_EL2_Type = Mk_GCSCR_EL2_Type(tmp.bits & not_vec(0xfffffffffffffc9e)); + return(tmp) +} + +val __get_GCSCRE0_EL1 : GCSCRE0_EL1_Type -> GCSCRE0_EL1_Type + +function __get_GCSCRE0_EL1 value_name = { + tmp : GCSCRE0_EL1_Type = value_name; + let tmp : GCSCRE0_EL1_Type = Mk_GCSCRE0_EL1_Type(tmp.bits & not_vec(0xfffffffffffff8de)); + return(tmp) +} + +val __get_GCSPR_EL0 : GCSPR_EL0_Type -> GCSPR_EL0_Type + +function __get_GCSPR_EL0 value_name = { + tmp : GCSPR_EL0_Type = value_name; + let tmp : GCSPR_EL0_Type = Mk_GCSPR_EL0_Type(tmp.bits & not_vec(ZeroExtend(0x7, 64))); + return(tmp) +} + +val __get_DBGOSDLR : DBGOSDLR_Type -> DBGOSDLR_Type + +function __get_DBGOSDLR value_name = { + tmp : DBGOSDLR_Type = value_name; + if not_bool(IsFeatureImplemented(FEAT_DoubleLock)) then { + tmp = Mk_DBGOSDLR_Type(tmp.bits & not_vec(ZeroExtend(0x1, 32))) + }; + let tmp : DBGOSDLR_Type = Mk_DBGOSDLR_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_ICH_ELRSR : ICH_ELRSR_Type -> ICH_ELRSR_Type + +function __get_ICH_ELRSR value_name = { + tmp : ICH_ELRSR_Type = value_name; + let tmp : ICH_ELRSR_Type = Mk_ICH_ELRSR_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_ICC_IAR1 : ICC_IAR1_Type -> ICC_IAR1_Type + +function __get_ICC_IAR1 value_name = { + tmp : ICC_IAR1_Type = value_name; + let tmp : ICC_IAR1_Type = Mk_ICC_IAR1_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_JOSCR : JOSCR_Type -> JOSCR_Type + +function __get_JOSCR value_name = { + tmp : JOSCR_Type = value_name; + let tmp : JOSCR_Type = tmp & not_vec(0xffffffff); + return(tmp) +} + +val __get_HCPTR : HCPTR_Type -> HCPTR_Type + +function __get_HCPTR value_name = { + tmp : HCPTR_Type = value_name; + tmp : HCPTR_Type = Mk_HCPTR_Type(tmp.bits & not_vec(ZeroExtend(0xccc4000, 32))); + if ((HaveEL(EL3) & ELUsingAArch32(EL3)) & not_bool(IsCurrentSecurityState(SS_Secure))) & NSACR[cp10] == 0b0 then { + tmp = Mk_HCPTR_Type(tmp.bits & not_vec(ZeroExtend(0x0, 32)) | ZeroExtend(0xc00, 32)) + }; + return(tmp) +} + +val __get_ICV_IGRPEN1 : ICV_IGRPEN1_Type -> ICV_IGRPEN1_Type + +function __get_ICV_IGRPEN1 value_name = { + tmp : ICV_IGRPEN1_Type = value_name; + let tmp : ICV_IGRPEN1_Type = Mk_ICV_IGRPEN1_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_CTR : CTR_Type -> CTR_Type + +function __get_CTR value_name = { + tmp : CTR_Type = value_name; + let tmp : CTR_Type = Mk_CTR_Type(tmp.bits & not_vec(0x40003ff0) | 0x80000000); + return(tmp) +} + +val __get_PMUSERENR : PMUSERENR_Type -> PMUSERENR_Type + +function __get_PMUSERENR value_name = { + tmp : PMUSERENR_Type = value_name; + let tmp : PMUSERENR_Type = Mk_PMUSERENR_Type(tmp.bits & not_vec(0xffffff80)); + return(tmp) +} + +val __get_DBGAUTHSTATUS : DBGAUTHSTATUS_Type -> DBGAUTHSTATUS_Type + +function __get_DBGAUTHSTATUS value_name = { + tmp : DBGAUTHSTATUS_Type = value_name; + let tmp : DBGAUTHSTATUS_Type = Mk_DBGAUTHSTATUS_Type(tmp.bits & not_vec(0xf0ff0f00)); + return(tmp) +} + +val __get_ICC_IAR0 : ICC_IAR0_Type -> ICC_IAR0_Type + +function __get_ICC_IAR0 value_name = { + tmp : ICC_IAR0_Type = value_name; + let tmp : ICC_IAR0_Type = Mk_ICC_IAR0_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_ICV_IGRPEN0 : ICV_IGRPEN0_Type -> ICV_IGRPEN0_Type + +function __get_ICV_IGRPEN0 value_name = { + tmp : ICV_IGRPEN0_Type = value_name; + let tmp : ICV_IGRPEN0_Type = Mk_ICV_IGRPEN0_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_ICV_CTLR : ICV_CTLR_Type -> ICV_CTLR_Type + +function __get_ICV_CTLR value_name = { + tmp : ICV_CTLR_Type = value_name; + let tmp : ICV_CTLR_Type = Mk_ICV_CTLR_Type(tmp.bits & not_vec(0xfff300fc)); + return(tmp) +} + +val __get_HPFAR : HPFAR_Type -> HPFAR_Type + +function __get_HPFAR value_name = { + tmp : HPFAR_Type = value_name; + let tmp : HPFAR_Type = Mk_HPFAR_Type(tmp.bits & not_vec(ZeroExtend(0xf, 32))); + return(tmp) +} + +val __get_DBGCLAIMCLR : DBGCLAIMCLR_Type -> DBGCLAIMCLR_Type + +function __get_DBGCLAIMCLR value_name = { + tmp : DBGCLAIMCLR_Type = value_name; + let tmp : DBGCLAIMCLR_Type = Mk_DBGCLAIMCLR_Type(tmp.bits & not_vec(0xffffff00)); + return(tmp) +} + +val __get_DBGWVR : DBGWVR_Type -> DBGWVR_Type + +function __get_DBGWVR value_name = { + tmp : DBGWVR_Type = value_name; + let tmp : DBGWVR_Type = Mk_DBGWVR_Type(tmp.bits & not_vec(ZeroExtend(0x3, 32))); + return(tmp) +} + +val __get_ICV_HPPIR1 : ICV_HPPIR1_Type -> ICV_HPPIR1_Type + +function __get_ICV_HPPIR1 value_name = { + tmp : ICV_HPPIR1_Type = value_name; + let tmp : ICV_HPPIR1_Type = Mk_ICV_HPPIR1_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_HRMR : HRMR_Type -> HRMR_Type + +function __get_HRMR value_name = { + tmp : HRMR_Type = value_name; + let tmp : HRMR_Type = Mk_HRMR_Type(tmp.bits & not_vec(0xfffffffc)); + return(tmp) +} + +val __get_ICH_VTR : ICH_VTR_Type -> ICH_VTR_Type + +function __get_ICH_VTR value_name = { + tmp : ICH_VTR_Type = value_name; + let tmp : ICH_VTR_Type = Mk_ICH_VTR_Type(tmp.bits & not_vec(ZeroExtend(0x3ffe0, 32))); + return(tmp) +} + +val __get_CSSELR : CSSELR_Type -> CSSELR_Type + +function __get_CSSELR value_name = { + tmp : CSSELR_Type = value_name; + let tmp : CSSELR_Type = Mk_CSSELR_Type(tmp.bits & not_vec(0xffffffe0)); + return(tmp) +} + +val __get_CSSELR_NS : CSSELR_Type -> CSSELR_Type + +function __get_CSSELR_NS value_name = { + tmp : CSSELR_Type = value_name; + let tmp : CSSELR_Type = Mk_CSSELR_Type(tmp.bits & not_vec(0xffffffe0)); + return(tmp) +} + +val __get_CSSELR_S : CSSELR_Type -> CSSELR_Type + +function __get_CSSELR_S value_name = { + tmp : CSSELR_Type = value_name; + let tmp : CSSELR_Type = Mk_CSSELR_Type(tmp.bits & not_vec(0xffffffe0)); + return(tmp) +} + +val __get_JIDR : JIDR_Type -> JIDR_Type + +function __get_JIDR value_name = { + tmp : JIDR_Type = value_name; + let tmp : JIDR_Type = tmp & not_vec(0xffffffff); + return(tmp) +} + +val __get_PMCR : PMCR_Type -> PMCR_Type + +function __get_PMCR value_name = { + tmp : PMCR_Type = value_name; + tmp : PMCR_Type = Mk_PMCR_Type(tmp.bits & not_vec(ZeroExtend(0x506, 32))); + if not_bool(__IMPDEF_boolean("the implementation includes a PMU event export bus")) then { + tmp = Mk_PMCR_Type(tmp.bits & not_vec(ZeroExtend(0x10, 32))) + }; + if not_bool(not_bool(IsFeatureImplemented(FEAT_PMUv3p7))) then { + tmp = Mk_PMCR_Type(tmp.bits & not_vec(0xff000000)) + }; + return(tmp) +} + +val __get_DBGWCR : DBGWCR_Type -> DBGWCR_Type + +function __get_DBGWCR value_name = { + tmp : DBGWCR_Type = value_name; + let tmp : DBGWCR_Type = Mk_DBGWCR_Type(tmp.bits & not_vec(ZeroExtend(0xe00000, 32))); + return(tmp) +} + +val __get_ICH_VMCR : ICH_VMCR_Type -> ICH_VMCR_Type + +function __get_ICH_VMCR value_name = { + tmp : ICH_VMCR_Type = value_name; + let tmp : ICH_VMCR_Type = Mk_ICH_VMCR_Type(tmp.bits & not_vec(ZeroExtend(0x3fde0, 32))); + return(tmp) +} + +val __get_DBGDEVID1 : DBGDEVID1_Type -> DBGDEVID1_Type + +function __get_DBGDEVID1 value_name = { + tmp : DBGDEVID1_Type = value_name; + let tmp : DBGDEVID1_Type = Mk_DBGDEVID1_Type(tmp.bits & not_vec(0xfffffff0)); + return(tmp) +} + +val __get_ICC_BPR1 : ICC_BPR1_Type -> ICC_BPR1_Type + +function __get_ICC_BPR1 value_name = { + tmp : ICC_BPR1_Type = value_name; + let tmp : ICC_BPR1_Type = Mk_ICC_BPR1_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICC_BPR1_NS : ICC_BPR1_Type -> ICC_BPR1_Type + +function __get_ICC_BPR1_NS value_name = { + tmp : ICC_BPR1_Type = value_name; + let tmp : ICC_BPR1_Type = Mk_ICC_BPR1_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICC_BPR1_S : ICC_BPR1_Type -> ICC_BPR1_Type + +function __get_ICC_BPR1_S value_name = { + tmp : ICC_BPR1_Type = value_name; + let tmp : ICC_BPR1_Type = Mk_ICC_BPR1_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICV_RPR : ICV_RPR_Type -> ICV_RPR_Type + +function __get_ICV_RPR value_name = { + tmp : ICV_RPR_Type = value_name; + let tmp : ICV_RPR_Type = Mk_ICV_RPR_Type(tmp.bits & not_vec(0xffffff00)); + return(tmp) +} + +val __get_VBAR : VBAR_Type -> VBAR_Type + +function __get_VBAR value_name = { + tmp : VBAR_Type = value_name; + let tmp : VBAR_Type = tmp & not_vec(ZeroExtend(0x1f, 32)); + return(tmp) +} + +val __get_VBAR_NS : VBAR_Type -> VBAR_Type + +function __get_VBAR_NS value_name = { + tmp : VBAR_Type = value_name; + let tmp : VBAR_Type = tmp & not_vec(ZeroExtend(0x1f, 32)); + return(tmp) +} + +val __get_VBAR_S : VBAR_Type -> VBAR_Type + +function __get_VBAR_S value_name = { + tmp : VBAR_Type = value_name; + let tmp : VBAR_Type = tmp & not_vec(ZeroExtend(0x1f, 32)); + return(tmp) +} + +val __get_ICV_IAR1 : ICV_IAR1_Type -> ICV_IAR1_Type + +function __get_ICV_IAR1 value_name = { + tmp : ICV_IAR1_Type = value_name; + let tmp : ICV_IAR1_Type = Mk_ICV_IAR1_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_DBGPRCR : DBGPRCR_Type -> DBGPRCR_Type + +function __get_DBGPRCR value_name = { + tmp : DBGPRCR_Type = value_name; + let tmp : DBGPRCR_Type = Mk_DBGPRCR_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_SDER : SDER_Type -> SDER_Type + +function __get_SDER value_name = { + tmp : SDER_Type = value_name; + let tmp : SDER_Type = Mk_SDER_Type(tmp.bits & not_vec(0xfffffffc)); + return(tmp) +} + +val __get_ICC_BPR0 : ICC_BPR0_Type -> ICC_BPR0_Type + +function __get_ICC_BPR0 value_name = { + tmp : ICC_BPR0_Type = value_name; + let tmp : ICC_BPR0_Type = Mk_ICC_BPR0_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_CNTHCTL : CNTHCTL_Type -> CNTHCTL_Type + +function __get_CNTHCTL value_name = { + tmp : CNTHCTL_Type = value_name; + let tmp : CNTHCTL_Type = Mk_CNTHCTL_Type(tmp.bits & not_vec(0xfff00000)); + return(tmp) +} + +val __get_DBGVCR : DBGVCR_Type -> DBGVCR_Type + +function __get_DBGVCR value_name = { + tmp : DBGVCR_Type = value_name; + let tmp : DBGVCR_Type = Mk_DBGVCR_Type(tmp.bits & not_vec(0x21ff2321)); + return(tmp) +} + +val __get_ICV_BPR1 : ICV_BPR1_Type -> ICV_BPR1_Type + +function __get_ICV_BPR1 value_name = { + tmp : ICV_BPR1_Type = value_name; + let tmp : ICV_BPR1_Type = Mk_ICV_BPR1_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICC_RPR : ICC_RPR_Type -> ICC_RPR_Type + +function __get_ICC_RPR value_name = { + tmp : ICC_RPR_Type = value_name; + let tmp : ICC_RPR_Type = Mk_ICC_RPR_Type(tmp.bits & not_vec(0xffffff00)); + return(tmp) +} + +val __get_ICC_MSRE : ICC_MSRE_Type -> ICC_MSRE_Type + +function __get_ICC_MSRE value_name = { + tmp : ICC_MSRE_Type = value_name; + let tmp : ICC_MSRE_Type = Mk_ICC_MSRE_Type(tmp.bits & not_vec(0xfffffff0)); + return(tmp) +} + +val __get_PMMIR : PMMIR_Type -> PMMIR_Type + +function __get_PMMIR value_name = { + tmp : PMMIR_Type = value_name; + let tmp : PMMIR_Type = Mk_PMMIR_Type(tmp.bits & not_vec(0xf0000000)); + return(tmp) +} + +val __get_VMPIDR : VMPIDR_Type -> VMPIDR_Type + +function __get_VMPIDR value_name = { + tmp : VMPIDR_Type = value_name; + let tmp : VMPIDR_Type = Mk_VMPIDR_Type(tmp.bits & not_vec(0x3e000000) | 0x80000000); + return(tmp) +} + +val __get_ICC_IGRPEN1 : ICC_IGRPEN1_Type -> ICC_IGRPEN1_Type + +function __get_ICC_IGRPEN1 value_name = { + tmp : ICC_IGRPEN1_Type = value_name; + let tmp : ICC_IGRPEN1_Type = Mk_ICC_IGRPEN1_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_ICC_IGRPEN1_NS : ICC_IGRPEN1_Type -> ICC_IGRPEN1_Type + +function __get_ICC_IGRPEN1_NS value_name = { + tmp : ICC_IGRPEN1_Type = value_name; + let tmp : ICC_IGRPEN1_Type = Mk_ICC_IGRPEN1_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_ICC_IGRPEN1_S : ICC_IGRPEN1_Type -> ICC_IGRPEN1_Type + +function __get_ICC_IGRPEN1_S value_name = { + tmp : ICC_IGRPEN1_Type = value_name; + let tmp : ICC_IGRPEN1_Type = Mk_ICC_IGRPEN1_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_HVBAR : HVBAR_Type -> HVBAR_Type + +function __get_HVBAR value_name = { + tmp : HVBAR_Type = value_name; + let tmp : HVBAR_Type = tmp & not_vec(ZeroExtend(0x1f, 32)); + return(tmp) +} + +val __get_HSTR : HSTR_Type -> HSTR_Type + +function __get_HSTR value_name = { + tmp : HSTR_Type = value_name; + let tmp : HSTR_Type = Mk_HSTR_Type(tmp.bits & not_vec(0xffff4010)); + return(tmp) +} + +val __get_ICC_MCTLR : ICC_MCTLR_Type -> ICC_MCTLR_Type + +function __get_ICC_MCTLR value_name = { + tmp : ICC_MCTLR_Type = value_name; + let tmp : ICC_MCTLR_Type = Mk_ICC_MCTLR_Type(tmp.bits & not_vec(0xfff10080)); + return(tmp) +} + +val __get_PMSELR : PMSELR_Type -> PMSELR_Type + +function __get_PMSELR value_name = { + tmp : PMSELR_Type = value_name; + let tmp : PMSELR_Type = Mk_PMSELR_Type(tmp.bits & not_vec(0xffffffe0)); + return(tmp) +} + +val __get_DBGCLAIMSET : DBGCLAIMSET_Type -> DBGCLAIMSET_Type + +function __get_DBGCLAIMSET value_name = { + tmp : DBGCLAIMSET_Type = value_name; + let tmp : DBGCLAIMSET_Type = Mk_DBGCLAIMSET_Type(tmp.bits & not_vec(0xffffff00)); + return(tmp) +} + +val __get_ICC_IGRPEN0 : ICC_IGRPEN0_Type -> ICC_IGRPEN0_Type + +function __get_ICC_IGRPEN0 value_name = { + tmp : ICC_IGRPEN0_Type = value_name; + let tmp : ICC_IGRPEN0_Type = Mk_ICC_IGRPEN0_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_ICC_CTLR : ICC_CTLR_Type -> ICC_CTLR_Type + +function __get_ICC_CTLR value_name = { + tmp : ICC_CTLR_Type = value_name; + let tmp : ICC_CTLR_Type = Mk_ICC_CTLR_Type(tmp.bits & not_vec(0xfff300bc)); + return(tmp) +} + +val __get_ICC_CTLR_NS : ICC_CTLR_Type -> ICC_CTLR_Type + +function __get_ICC_CTLR_NS value_name = { + tmp : ICC_CTLR_Type = value_name; + let tmp : ICC_CTLR_Type = Mk_ICC_CTLR_Type(tmp.bits & not_vec(0xfff300bc)); + return(tmp) +} + +val __get_ICC_CTLR_S : ICC_CTLR_Type -> ICC_CTLR_Type + +function __get_ICC_CTLR_S value_name = { + tmp : ICC_CTLR_Type = value_name; + let tmp : ICC_CTLR_Type = Mk_ICC_CTLR_Type(tmp.bits & not_vec(0xfff300bc)); + return(tmp) +} + +val __get_SCR : SCR_Type -> SCR_Type + +function __get_SCR value_name = { + tmp : SCR_Type = value_name; + let tmp : SCR_Type = Mk_SCR_Type(tmp.bits & not_vec(0xffff4c00)); + return(tmp) +} + +val __get_NSACR : NSACR_Type -> NSACR_Type + +function __get_NSACR value_name = { + tmp : NSACR_Type = value_name; + let tmp : NSACR_Type = Mk_NSACR_Type(tmp.bits & not_vec(0xffe873ff)); + return(tmp) +} + +val __get_ICV_BPR0 : ICV_BPR0_Type -> ICV_BPR0_Type + +function __get_ICV_BPR0 value_name = { + tmp : ICV_BPR0_Type = value_name; + let tmp : ICV_BPR0_Type = Mk_ICV_BPR0_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICH_EISR : ICH_EISR_Type -> ICH_EISR_Type + +function __get_ICH_EISR value_name = { + tmp : ICH_EISR_Type = value_name; + let tmp : ICH_EISR_Type = Mk_ICH_EISR_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_HDCR : HDCR_Type -> HDCR_Type + +function __get_HDCR value_name = { + tmp : HDCR_Type = value_name; + let tmp : HDCR_Type = Mk_HDCR_Type(tmp.bits & not_vec(ZeroExtend(0x3750000, 32))); + return(tmp) +} + +val __get_ICC_HSRE : ICC_HSRE_Type -> ICC_HSRE_Type + +function __get_ICC_HSRE value_name = { + tmp : ICC_HSRE_Type = value_name; + let tmp : ICC_HSRE_Type = Mk_ICC_HSRE_Type(tmp.bits & not_vec(0xfffffff0)); + return(tmp) +} + +val __get_PMCCFILTR : PMCCFILTR_Type -> PMCCFILTR_Type + +function __get_PMCCFILTR value_name = { + tmp : PMCCFILTR_Type = value_name; + let tmp : PMCCFILTR_Type = Mk_PMCCFILTR_Type(tmp.bits & not_vec(ZeroExtend(0x20fffff, 32))); + return(tmp) +} + +val __get_HTCR : HTCR_Type -> HTCR_Type + +function __get_HTCR value_name = { + tmp : HTCR_Type = value_name; + let tmp : HTCR_Type = Mk_HTCR_Type(tmp.bits & not_vec(ZeroExtend(0x40, 32))); + return(tmp) +} + +val __get_ICC_PMR : ICC_PMR_Type -> ICC_PMR_Type + +function __get_ICC_PMR value_name = { + tmp : ICC_PMR_Type = value_name; + let tmp : ICC_PMR_Type = Mk_ICC_PMR_Type(tmp.bits & not_vec(0xffffff00)); + return(tmp) +} + +val __get_ICH_HCR : ICH_HCR_Type -> ICH_HCR_Type + +function __get_ICH_HCR value_name = { + tmp : ICH_HCR_Type = value_name; + let tmp : ICH_HCR_Type = Mk_ICH_HCR_Type(tmp.bits & not_vec(ZeroExtend(0x7ff0200, 32))); + return(tmp) +} + +val __get_RMR : RMR_Type -> RMR_Type + +function __get_RMR value_name = { + tmp : RMR_Type = value_name; + let tmp : RMR_Type = Mk_RMR_Type(tmp.bits & not_vec(0xfffffffc)); + return(tmp) +} + +val __get_ICC_HPPIR0 : ICC_HPPIR0_Type -> ICC_HPPIR0_Type + +function __get_ICC_HPPIR0 value_name = { + tmp : ICC_HPPIR0_Type = value_name; + let tmp : ICC_HPPIR0_Type = Mk_ICC_HPPIR0_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_TTBCR2 : TTBCR2_Type -> TTBCR2_Type + +function __get_TTBCR2 value_name = { + tmp : TTBCR2_Type = value_name; + let tmp : TTBCR2_Type = Mk_TTBCR2_Type(tmp.bits & not_vec(0xc0000008)); + return(tmp) +} + +val __get_TTBCR2_NS : TTBCR2_Type -> TTBCR2_Type + +function __get_TTBCR2_NS value_name = { + tmp : TTBCR2_Type = value_name; + let tmp : TTBCR2_Type = Mk_TTBCR2_Type(tmp.bits & not_vec(0xc0000008)); + return(tmp) +} + +val __get_TTBCR2_S : TTBCR2_Type -> TTBCR2_Type + +function __get_TTBCR2_S value_name = { + tmp : TTBCR2_Type = value_name; + let tmp : TTBCR2_Type = Mk_TTBCR2_Type(tmp.bits & not_vec(0xc0000008)); + return(tmp) +} + +val __get_FCSEIDR : FCSEIDR_Type -> FCSEIDR_Type + +function __get_FCSEIDR value_name = { + tmp : FCSEIDR_Type = value_name; + let tmp : FCSEIDR_Type = tmp & not_vec(0xffffffff); + return(tmp) +} + +val __get_JMCR : JMCR_Type -> JMCR_Type + +function __get_JMCR value_name = { + tmp : JMCR_Type = value_name; + let tmp : JMCR_Type = tmp & not_vec(0xffffffff); + return(tmp) +} + +val __get_CNTKCTL : CNTKCTL_Type -> CNTKCTL_Type + +function __get_CNTKCTL value_name = { + tmp : CNTKCTL_Type = value_name; + let tmp : CNTKCTL_Type = Mk_CNTKCTL_Type(tmp.bits & not_vec(0xfffdfc00)); + return(tmp) +} + +val __get_ICV_PMR : ICV_PMR_Type -> ICV_PMR_Type + +function __get_ICV_PMR value_name = { + tmp : ICV_PMR_Type = value_name; + let tmp : ICV_PMR_Type = Mk_ICV_PMR_Type(tmp.bits & not_vec(0xffffff00)); + return(tmp) +} + +val __get_ICV_HPPIR0 : ICV_HPPIR0_Type -> ICV_HPPIR0_Type + +function __get_ICV_HPPIR0 value_name = { + tmp : ICV_HPPIR0_Type = value_name; + let tmp : ICV_HPPIR0_Type = Mk_ICV_HPPIR0_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_DBGBCR : DBGBCR_Type -> DBGBCR_Type + +function __get_DBGBCR value_name = { + tmp : DBGBCR_Type = value_name; + let tmp : DBGBCR_Type = Mk_DBGBCR_Type(tmp.bits & not_vec(ZeroExtend(0x1e10, 32))); + return(tmp) +} + +val __get_DBGWFAR : DBGWFAR_Type -> DBGWFAR_Type + +function __get_DBGWFAR value_name = { + tmp : DBGWFAR_Type = value_name; + let tmp : DBGWFAR_Type = tmp & not_vec(0xffffffff); + return(tmp) +} + +val __get_HSCTLR : HSCTLR_Type -> HSCTLR_Type + +function __get_HSCTLR value_name = { + tmp : HSCTLR_Type = value_name; + tmp : HSCTLR_Type = Mk_HSCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x20200, 32))); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN")) then { + tmp = Mk_HSCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x0, 32)) | ZeroExtend(0x20, 32)) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD")) then { + tmp = Mk_HSCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x80, 32))) + }; + return(tmp) +} + +val __get_VTCR : VTCR_Type -> VTCR_Type + +function __get_VTCR value_name = { + tmp : VTCR_Type = value_name; + let tmp : VTCR_Type = Mk_VTCR_Type(tmp.bits & not_vec(ZeroExtend(0x1900000, 32)) | 0x80000000); + return(tmp) +} + +val __get_ICC_MGRPEN1 : ICC_MGRPEN1_Type -> ICC_MGRPEN1_Type + +function __get_ICC_MGRPEN1 value_name = { + tmp : ICC_MGRPEN1_Type = value_name; + let tmp : ICC_MGRPEN1_Type = Mk_ICC_MGRPEN1_Type(tmp.bits & not_vec(0xfffffffc)); + return(tmp) +} + +val __get_CCSIDR2 : CCSIDR2_Type -> CCSIDR2_Type + +function __get_CCSIDR2 value_name = { + tmp : CCSIDR2_Type = value_name; + let tmp : CCSIDR2_Type = Mk_CCSIDR2_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_ICH_MISR : ICH_MISR_Type -> ICH_MISR_Type + +function __get_ICH_MISR value_name = { + tmp : ICH_MISR_Type = value_name; + let tmp : ICH_MISR_Type = Mk_ICH_MISR_Type(tmp.bits & not_vec(0xffffff00)); + return(tmp) +} + +val __get_CPACR : CPACR_Type -> CPACR_Type + +function __get_CPACR value_name = { + tmp : CPACR_Type = value_name; + tmp : CPACR_Type = Mk_CPACR_Type(tmp.bits & not_vec(0x4c0cffff)); + if ((HaveEL(EL3) & ELUsingAArch32(EL3)) & not_bool(IsCurrentSecurityState(SS_Secure))) & NSACR[cp10] == 0b0 then { + tmp = Mk_CPACR_Type(tmp.bits & not_vec(ZeroExtend(0xf00000, 32))) + }; + return(tmp) +} + +val __get_ICV_IAR0 : ICV_IAR0_Type -> ICV_IAR0_Type + +function __get_ICV_IAR0 value_name = { + tmp : ICV_IAR0_Type = value_name; + let tmp : ICV_IAR0_Type = Mk_ICV_IAR0_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_ISR : ISR_Type -> ISR_Type + +function __get_ISR value_name = { + tmp : ISR_Type = value_name; + let tmp : ISR_Type = Mk_ISR_Type(tmp.bits & not_vec(0xfffff83f)); + return(tmp) +} + +val __get_SCTLR : SCTLR_Type -> SCTLR_Type + +function __get_SCTLR value_name = { + tmp : SCTLR_Type = value_name; + tmp : SCTLR_Type = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x20000, 32))); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN")) then { + tmp = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x0, 32)) | ZeroExtend(0x20, 32)) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD")) then { + tmp = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x80, 32))) + }; + return(tmp) +} + +val __get_SCTLR_NS : SCTLR_Type -> SCTLR_Type + +function __get_SCTLR_NS value_name = { + tmp : SCTLR_Type = value_name; + tmp : SCTLR_Type = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x20000, 32))); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN")) then { + tmp = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x0, 32)) | ZeroExtend(0x20, 32)) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD")) then { + tmp = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x80, 32))) + }; + return(tmp) +} + +val __get_SCTLR_S : SCTLR_Type -> SCTLR_Type + +function __get_SCTLR_S value_name = { + tmp : SCTLR_Type = value_name; + tmp : SCTLR_Type = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x20000, 32))); + if not_bool(__IMPDEF_boolean("IMPLEMENTED_CP15BEN")) then { + tmp = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x0, 32)) | ZeroExtend(0x20, 32)) + }; + if not_bool(__IMPDEF_boolean("IMPLEMENTED_ITD")) then { + tmp = Mk_SCTLR_Type(tmp.bits & not_vec(ZeroExtend(0x80, 32))) + }; + return(tmp) +} + +val __get_DBGDSCRint : DBGDSCRint_Type -> DBGDSCRint_Type + +function __get_DBGDSCRint value_name = { + tmp : DBGDSCRint_Type = value_name; + let tmp : DBGDSCRint_Type = Mk_DBGDSCRint_Type(tmp.bits & not_vec(0x9ff86fc3)); + return(tmp) +} + +val __get_DBGDCCINT : DBGDCCINT_Type -> DBGDCCINT_Type + +function __get_DBGDCCINT value_name = { + tmp : DBGDCCINT_Type = value_name; + let tmp : DBGDCCINT_Type = Mk_DBGDCCINT_Type(tmp.bits & not_vec(0x9fffffff)); + return(tmp) +} + +val __get_DBGDSCRext : DBGDSCRext_Type -> DBGDSCRext_Type + +function __get_DBGDSCRext value_name = { + tmp : DBGDSCRext_Type = value_name; + let tmp : DBGDSCRext_Type = Mk_DBGDSCRext_Type(tmp.bits & not_vec(0x13100f82)); + return(tmp) +} + +val __get_IFSR : IFSR_Type -> IFSR_Type + +function __get_IFSR value_name = { + tmp : IFSR_Type = value_name; + let tmp : IFSR_Type = Mk_IFSR_Type(tmp.bits & not_vec(0xfffee9c0)); + return(tmp) +} + +val __get_IFSR_NS : IFSR_Type -> IFSR_Type + +function __get_IFSR_NS value_name = { + tmp : IFSR_Type = value_name; + let tmp : IFSR_Type = Mk_IFSR_Type(tmp.bits & not_vec(0xfffee9c0)); + return(tmp) +} + +val __get_IFSR_S : IFSR_Type -> IFSR_Type + +function __get_IFSR_S value_name = { + tmp : IFSR_Type = value_name; + let tmp : IFSR_Type = Mk_IFSR_Type(tmp.bits & not_vec(0xfffee9c0)); + return(tmp) +} + +val __get_DBGDIDR : DBGDIDR_Type -> DBGDIDR_Type + +function __get_DBGDIDR value_name = { + tmp : DBGDIDR_Type = value_name; + let tmp : DBGDIDR_Type = Mk_DBGDIDR_Type(tmp.bits & not_vec(ZeroExtend(0x2fff, 32)) | ZeroExtend(0x8000, 32)); + return(tmp) +} + +val __get_CNTP_CTL : CNTP_CTL_Type -> CNTP_CTL_Type + +function __get_CNTP_CTL value_name = { + tmp : CNTP_CTL_Type = value_name; + let tmp : CNTP_CTL_Type = Mk_CNTP_CTL_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_CNTP_CTL_NS : CNTP_CTL_Type -> CNTP_CTL_Type + +function __get_CNTP_CTL_NS value_name = { + tmp : CNTP_CTL_Type = value_name; + let tmp : CNTP_CTL_Type = Mk_CNTP_CTL_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_CNTP_CTL_S : CNTP_CTL_Type -> CNTP_CTL_Type + +function __get_CNTP_CTL_S value_name = { + tmp : CNTP_CTL_Type = value_name; + let tmp : CNTP_CTL_Type = Mk_CNTP_CTL_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_HTRFCR : HTRFCR_Type -> HTRFCR_Type + +function __get_HTRFCR value_name = { + tmp : HTRFCR_Type = value_name; + let tmp : HTRFCR_Type = Mk_HTRFCR_Type(tmp.bits & not_vec(0xffffff94)); + return(tmp) +} + +val __get_PMEVTYPER : PMEVTYPER_Type -> PMEVTYPER_Type + +function __get_PMEVTYPER value_name = { + tmp : PMEVTYPER_Type = value_name; + let tmp : PMEVTYPER_Type = Mk_PMEVTYPER_Type(tmp.bits & not_vec(ZeroExtend(0xf0000, 32))); + return(tmp) +} + +val __get_CNTV_CTL : CNTV_CTL_Type -> CNTV_CTL_Type + +function __get_CNTV_CTL value_name = { + tmp : CNTV_CTL_Type = value_name; + let tmp : CNTV_CTL_Type = Mk_CNTV_CTL_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_DBGOSLSR : DBGOSLSR_Type -> DBGOSLSR_Type + +function __get_DBGOSLSR value_name = { + tmp : DBGOSLSR_Type = value_name; + let tmp : DBGOSLSR_Type = Mk_DBGOSLSR_Type(tmp.bits & not_vec(0xfffffff0)); + return(tmp) +} + +val __get_TRFCR : TRFCR_Type -> TRFCR_Type + +function __get_TRFCR value_name = { + tmp : TRFCR_Type = value_name; + let tmp : TRFCR_Type = Mk_TRFCR_Type(tmp.bits & not_vec(0xffffff9c)); + return(tmp) +} + +val __get_CNTHP_CTL : CNTHP_CTL_Type -> CNTHP_CTL_Type + +function __get_CNTHP_CTL value_name = { + tmp : CNTHP_CTL_Type = value_name; + let tmp : CNTHP_CTL_Type = Mk_CNTHP_CTL_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_DBGDEVID2 : DBGDEVID2_Type -> DBGDEVID2_Type + +function __get_DBGDEVID2 value_name = { + tmp : DBGDEVID2_Type = value_name; + let tmp : DBGDEVID2_Type = tmp & not_vec(0xffffffff); + return(tmp) +} + +val __get_MPIDR : MPIDR_Type -> MPIDR_Type + +function __get_MPIDR value_name = { + tmp : MPIDR_Type = value_name; + let tmp : MPIDR_Type = Mk_MPIDR_Type(tmp.bits & not_vec(0x3e000000) | 0x80000000); + return(tmp) +} + +val __get_ICH_LRC : ICH_LRC_Type -> ICH_LRC_Type + +function __get_ICH_LRC value_name = { + tmp : ICH_LRC_Type = value_name; + let tmp : ICH_LRC_Type = Mk_ICH_LRC_Type(tmp.bits & not_vec(ZeroExtend(0x700e000, 32))); + return(tmp) +} + +val __get_DSPSR2 : DSPSR2_Type -> DSPSR2_Type + +function __get_DSPSR2 value_name = { + tmp : DSPSR2_Type = value_name; + let tmp : DSPSR2_Type = Mk_DSPSR2_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICC_HPPIR1 : ICC_HPPIR1_Type -> ICC_HPPIR1_Type + +function __get_ICC_HPPIR1 value_name = { + tmp : ICC_HPPIR1_Type = value_name; + let tmp : ICC_HPPIR1_Type = Mk_ICC_HPPIR1_Type(tmp.bits & not_vec(0xff000000)); + return(tmp) +} + +val __get_ICC_SRE : ICC_SRE_Type -> ICC_SRE_Type + +function __get_ICC_SRE value_name = { + tmp : ICC_SRE_Type = value_name; + let tmp : ICC_SRE_Type = Mk_ICC_SRE_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICC_SRE_NS : ICC_SRE_Type -> ICC_SRE_Type + +function __get_ICC_SRE_NS value_name = { + tmp : ICC_SRE_Type = value_name; + let tmp : ICC_SRE_Type = Mk_ICC_SRE_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_ICC_SRE_S : ICC_SRE_Type -> ICC_SRE_Type + +function __get_ICC_SRE_S value_name = { + tmp : ICC_SRE_Type = value_name; + let tmp : ICC_SRE_Type = Mk_ICC_SRE_Type(tmp.bits & not_vec(0xfffffff8)); + return(tmp) +} + +val __get_SDCR : SDCR_Type -> SDCR_Type + +function __get_SDCR value_name = { + tmp : SDCR_Type = value_name; + let tmp : SDCR_Type = Mk_SDCR_Type(tmp.bits & not_vec(0xe7413fff)); + return(tmp) +} + +val __get_AMEVTYPER0 : AMEVTYPER0_Type -> AMEVTYPER0_Type + +function __get_AMEVTYPER0 value_name = { + tmp : AMEVTYPER0_Type = value_name; + let tmp : AMEVTYPER0_Type = Mk_AMEVTYPER0_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_AMUSERENR : AMUSERENR_Type -> AMUSERENR_Type + +function __get_AMUSERENR value_name = { + tmp : AMUSERENR_Type = value_name; + let tmp : AMUSERENR_Type = Mk_AMUSERENR_Type(tmp.bits & not_vec(0xfffffffe)); + return(tmp) +} + +val __get_AMEVTYPER1 : AMEVTYPER1_Type -> AMEVTYPER1_Type + +function __get_AMEVTYPER1 value_name = { + tmp : AMEVTYPER1_Type = value_name; + let tmp : AMEVTYPER1_Type = Mk_AMEVTYPER1_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_AMCGCR : AMCGCR_Type -> AMCGCR_Type + +function __get_AMCGCR value_name = { + tmp : AMCGCR_Type = value_name; + let tmp : AMCGCR_Type = Mk_AMCGCR_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_AMCFGR : AMCFGR_Type -> AMCFGR_Type + +function __get_AMCFGR value_name = { + tmp : AMCFGR_Type = value_name; + let tmp : AMCFGR_Type = Mk_AMCFGR_Type(tmp.bits & not_vec(ZeroExtend(0xeffc000, 32))); + return(tmp) +} + +val __get_AMCNTENCLR1 : AMCNTENCLR1_Type -> AMCNTENCLR1_Type + +function __get_AMCNTENCLR1 value_name = { + tmp : AMCNTENCLR1_Type = value_name; + let tmp : AMCNTENCLR1_Type = Mk_AMCNTENCLR1_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_AMCNTENSET0 : AMCNTENSET0_Type -> AMCNTENSET0_Type + +function __get_AMCNTENSET0 value_name = { + tmp : AMCNTENSET0_Type = value_name; + let tmp : AMCNTENSET0_Type = Mk_AMCNTENSET0_Type(tmp.bits & not_vec(0xfffffff0)); + return(tmp) +} + +val __get_AMCNTENCLR0 : AMCNTENCLR0_Type -> AMCNTENCLR0_Type + +function __get_AMCNTENCLR0 value_name = { + tmp : AMCNTENCLR0_Type = value_name; + let tmp : AMCNTENCLR0_Type = Mk_AMCNTENCLR0_Type(tmp.bits & not_vec(0xfffffff0)); + return(tmp) +} + +val __get_AMCNTENSET1 : AMCNTENSET1_Type -> AMCNTENSET1_Type + +function __get_AMCNTENSET1 value_name = { + tmp : AMCNTENSET1_Type = value_name; + let tmp : AMCNTENSET1_Type = Mk_AMCNTENSET1_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_AMCR : AMCR_Type -> AMCR_Type + +function __get_AMCR value_name = { + tmp : AMCR_Type = value_name; + let tmp : AMCR_Type = Mk_AMCR_Type(tmp.bits & not_vec(0xfffdfbff)); + return(tmp) +} + +val __get_ERRIDR : ERRIDR_Type -> ERRIDR_Type + +function __get_ERRIDR value_name = { + tmp : ERRIDR_Type = value_name; + let tmp : ERRIDR_Type = Mk_ERRIDR_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_ERRSELR : ERRSELR_Type -> ERRSELR_Type + +function __get_ERRSELR value_name = { + tmp : ERRSELR_Type = value_name; + let tmp : ERRSELR_Type = Mk_ERRSELR_Type(tmp.bits & not_vec(0xffff0000)); + return(tmp) +} + +val __get_DISR : DISR_Type -> DISR_Type + +function __get_DISR value_name = { + tmp : DISR_Type = value_name; + let tmp : DISR_Type = Mk_DISR_Type(tmp.bits & not_vec(0x7e000000)); + return(tmp) +} + +val __get_VDFSR : VDFSR_Type -> VDFSR_Type + +function __get_VDFSR value_name = { + tmp : VDFSR_Type = value_name; + let tmp : VDFSR_Type = Mk_VDFSR_Type(tmp.bits & not_vec(0xfe000000)); + return(tmp) +} + +val __get_VDISR : VDISR_Type -> VDISR_Type + +function __get_VDISR value_name = { + tmp : VDISR_Type = value_name; + let tmp : VDISR_Type = Mk_VDISR_Type(tmp.bits & not_vec(0x7e000000)); + return(tmp) +} + +val __get_PAR_EL1 : PAR_EL1_Type -> PAR_EL1_Type + +function __get_PAR_EL1 value_name = { + tmp : PAR_EL1_Type = value_name; + let tmp : PAR_EL1_Type = Mk_PAR_EL1_Type(tmp.bits & not_vec(0xff00000000000ffe0000000000000000)); + return(tmp) +} + +val __get_TTBR1_EL1 : TTBR1_EL1_Type -> TTBR1_EL1_Type + +function __get_TTBR1_EL1 value_name = { + tmp : TTBR1_EL1_Type = value_name; + let tmp : TTBR1_EL1_Type = Mk_TTBR1_EL1_Type(tmp.bits & not_vec(0xffffffffff00ffff0000000000000000)); + return(tmp) +} + +val __get_TTBR0_EL2 : TTBR0_EL2_Type -> TTBR0_EL2_Type + +function __get_TTBR0_EL2 value_name = { + tmp : TTBR0_EL2_Type = value_name; + let tmp : TTBR0_EL2_Type = Mk_TTBR0_EL2_Type(tmp.bits & not_vec(0xffffffffff00ffff0000000000000000)); + return(tmp) +} + +val __get_VTTBR_EL2 : VTTBR_EL2_Type -> VTTBR_EL2_Type + +function __get_VTTBR_EL2 value_name = { + tmp : VTTBR_EL2_Type = value_name; + let tmp : VTTBR_EL2_Type = Mk_VTTBR_EL2_Type(tmp.bits & not_vec(0xffffffffff00ffff0000000000000000)); + return(tmp) +} + +val __get_TTBR0_EL1 : TTBR0_EL1_Type -> TTBR0_EL1_Type + +function __get_TTBR0_EL1 value_name = { + tmp : TTBR0_EL1_Type = value_name; + let tmp : TTBR0_EL1_Type = Mk_TTBR0_EL1_Type(tmp.bits & not_vec(0xffffffffff00ffff0000000000000000)); + return(tmp) +} + +val __get_TTBR1_EL2 : TTBR1_EL2_Type -> TTBR1_EL2_Type + +function __get_TTBR1_EL2 value_name = { + tmp : TTBR1_EL2_Type = value_name; + let tmp : TTBR1_EL2_Type = Mk_TTBR1_EL2_Type(tmp.bits & not_vec(0xffffffffff00ffff0000000000000000)); + return(tmp) +} + +val ZeroUnsignedSatQ : forall 'M 'N 'i, 'M >= 0 & 'N >= 0. + (int('i), int('N), int('M)) -> (bits('M), bool) + +function ZeroUnsignedSatQ (i, N, M) = { + result : int = undefined; + saturated : bool = undefined; + if i > pow2(N) - 1 then { + result = pow2(N) - 1; + saturated = true + } else if i < 0 then { + result = 0; + saturated = true + } else { + result = i; + saturated = false + }; + let 'result = result; + fullresult : bits('M) = Zeros(); + if N > 0 then { + assert(constraint((0 <= 'N - 1 & 'N - 1 < 'M))); + fullresult[N - 1 .. 0] = result[N - 1 .. 0] + }; + return((fullresult, saturated)) +} + +val LR_read : unit -> bits(32) + +function LR_read () = { + return(R_read(14)) +} diff --git a/crates/clazel-a64/tests/generated/arm_mrs.rs b/crates/clazel-a64/tests/generated/arm_mrs.rs new file mode 100644 index 000000000..2eb09db37 --- /dev/null +++ b/crates/clazel-a64/tests/generated/arm_mrs.rs @@ -0,0 +1,42 @@ +// @generated by `cargo xtask testdata` from tests/data/arm-mrs/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, commit and license: tests/data/arm-mrs/SOURCE.md. +// +// Arm machine-readable specification: licence and README vendored, Instructions.json pinned. +// 3 files, 6565 bytes. Nothing here is parsed yet; see the converter's +// header for why. Paths are relative to tests/data/arm-mrs/. + +/// One vendored file. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct File { + /// Its path under the suite directory, with `/` separators. + pub path: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every vendored file, sorted by path. +pub const FILES: &[File] = &[ + File { path: "LICENSE.md", size: 1657, sha256: "9e80ed939337b8ea1596bc8660dd080cf282a85ef6ffda9ba2a73c1d1a5115c5" }, + File { path: "README.md", size: 1242, sha256: "514e17170d5f0065386051553bc46d3f246d4616aa9db7e5a63af0d2045b55d1" }, + File { path: "notice.html", size: 3666, sha256: "91e83f6178857ba3e96d69c989bee40c351b775d3a58ff6773c9ec4659ba99d3" }, +]; + +/// A file the suite pins but does not vendor. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Pin { + /// The file's name in `SOURCE.md`. + pub file: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every pinned file. +pub const PINS: &[Pin] = &[ + Pin { file: "Instructions.json", size: 116678333, sha256: "ef75f3ec02df1b9b9c0612f4ea259d6710ac3de686b097d8f9c83d1d97aa800a" }, +]; diff --git a/crates/clazel-a64/tests/generated/sail_arm.rs b/crates/clazel-a64/tests/generated/sail_arm.rs new file mode 100644 index 000000000..c98d38132 --- /dev/null +++ b/crates/clazel-a64/tests/generated/sail_arm.rs @@ -0,0 +1,37 @@ +// @generated by `cargo xtask testdata` from tests/data/sail-arm/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, commit and license: tests/data/sail-arm/SOURCE.md. +// +// Sail Armv9.4-A model, A64 base instructions (jit.md item J.2). +// 14 files, 3942621 bytes. Nothing here is parsed yet; see the converter's +// header for why. Paths are relative to tests/data/sail-arm/. + +/// One vendored file. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct File { + /// Its path under the suite directory, with `/` separators. + pub path: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every vendored file, sorted by path. +pub const FILES: &[File] = &[ + File { path: "LICENSE.md", size: 1780, sha256: "121df4677b246ccb78e33f257c131ee6164067a52c01235bd3d272c82e44dcc4" }, + File { path: "README.md", size: 2987, sha256: "adf87e6a344453c375b1bc8718dbcac6a8fafee97ea94835b4fdb951dd5d92e6" }, + File { path: "src/builtins.sail", size: 7610, sha256: "ab4473cdfcb885e3abe8013cfe9f557e62e6c22d903af16263c5b6af06c6bf8f" }, + File { path: "src/decode_end.sail", size: 6330, sha256: "be7d7b3a71e7b1b50cb53a031b670c70910b9ab1a2a1506a83e12eebde6760a6" }, + File { path: "src/decode_start.sail", size: 5096, sha256: "01ce1d2df4951dcdc4d4ab5fb6eb8c1f9436d3476707d290d42f235e609b644e" }, + File { path: "src/event_clauses.sail", size: 16049, sha256: "bd766e6a61b335e0ad958882e4cdf1e01ffeaf6544eb01140aa0c3e9e5365280" }, + File { path: "src/fetch.sail", size: 14067, sha256: "04a7da0f6e7dcd9ab7a8da81a60389867ceaccba58c6c31264445fec3ef940f9" }, + File { path: "src/instrs64.sail", size: 2130645, sha256: "f46630385fb146b2f74254566a16528ae2c26d41246fca84beeb49a8d35c7fc8" }, + File { path: "src/interface.sail", size: 7784, sha256: "2a00d0a1c66c137bd6636dc6a7df020298d1b1b34663ae24a6699fe153fe8423" }, + File { path: "src/map_clauses.sail", size: 20066, sha256: "b5353b4dbe645d9460da03ca956198218d49a008584b1b15e12c7fd67cdb25ab" }, + File { path: "src/mem.sail", size: 10046, sha256: "227aef2d82846947bef25d8a6ae212e90817a05ab96f677403b276876c66fb16" }, + File { path: "src/prelude.sail", size: 14201, sha256: "933e3d7529bc6a9518b6b2b346174f488a0517a3fd2383da1595ee71353c5ba2" }, + File { path: "src/termination_measures.sail", size: 5514, sha256: "b7531c0c5fdd0fe2f14ddab1b8fb97005d855fa816790f6f51da651c3928e307" }, + File { path: "src/v8_base.sail", size: 1700446, sha256: "7c7a9c92e05cedb7202183160db96dd2b9c1de6cde73a70816159c6ddf2d1b49" }, +]; diff --git a/crates/clazel-a64/tests/vendored_sources.rs b/crates/clazel-a64/tests/vendored_sources.rs new file mode 100644 index 000000000..3eaeb3556 --- /dev/null +++ b/crates/clazel-a64/tests/vendored_sources.rs @@ -0,0 +1,56 @@ +//! The vendored instruction-set sources are the ones the generated inventories +//! list (docs/phases/jit.md item J.2): every listed file exists with the +//! listed size, and the pinned file has a well-formed pin. `cargo xtask +//! testdata` checks the hashes; nothing here reads the content yet. + +use std::path::Path; + +mod sail_arm { + include!("generated/sail_arm.rs"); +} +mod arm_mrs { + include!("generated/arm_mrs.rs"); +} + +fn dir(suite: &str) -> std::path::PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("data") + .join(suite) +} + +fn check(suite: &str, files: &[(&str, u64)]) { + assert!(!files.is_empty(), "{suite}: empty inventory"); + for (path, size) in files { + let len = std::fs::metadata(dir(suite).join(path)) + .map(|m| m.len()) + .ok(); + assert_eq!(len, Some(*size), "{suite}/{path}"); + } +} + +#[test] +fn sail_arm_files_have_their_listed_sizes() { + let files: Vec<_> = sail_arm::FILES.iter().map(|f| (f.path, f.size)).collect(); + check("sail-arm", &files); +} + +#[test] +fn arm_mrs_files_have_their_listed_sizes() { + let files: Vec<_> = arm_mrs::FILES.iter().map(|f| (f.path, f.size)).collect(); + check("arm-mrs", &files); +} + +#[test] +fn instructions_json_is_pinned_and_not_vendored() { + assert_eq!(arm_mrs::PINS.len(), 1); + for p in arm_mrs::PINS { + assert_eq!(p.sha256.len(), 64, "{}", p.file); + assert!(p.size > 0, "{}", p.file); + assert!( + !dir("arm-mrs").join(p.file).exists(), + "{}: 116 MB, pinned only", + p.file + ); + } +} diff --git a/crates/clazel-x64/README.md b/crates/clazel-x64/README.md new file mode 100644 index 000000000..2318144e2 --- /dev/null +++ b/crates/clazel-x64/README.md @@ -0,0 +1,71 @@ +# clazel-x64 + +Part of [Clazel](../../README.md). The x86-64 subset the JIT emits: its +semantics, encoder and decoder ([jit.md](../../docs/phases/jit.md) item J.3). + +Nothing is implemented yet (tier 0, target tier 2). Item J.2 vendored or +pinned the sources the semantics will be written against, in `tests/data/`: + +| Suite | What | Held as | +|---|---|---| +| `acl2-x86isa` | the ACL2 x86isa model (BSD-3-Clause), files of the J.3 subset | 2.6 MB, vendored | +| `sail-x86-from-acl2` | the Sail model translated from it (BSD-3-Clause, BSD-2-Clause) | 0.8 MB, vendored | +| `sail-x86-shina` | a Sail model written from the Intel manuals (MIT) | 0.6 MB, vendored | +| `intel-sdm` | Intel SDM volume 2, version 093 | pinned by URL and SHA-256, not vendored (Intel's terms forbid redistribution) | + +Each has a `SOURCE.md` with the upstream, the commit (or the SHA-256) and the +licence. The tables in `tests/generated/` list every file's size and hash. + +## Are the two x86 models independent? No. + +jit.md item J.2 requires this to be read before the ACL2 and Sail models count +as two sources. The finding: + +- **The Sail model that J.2 names, `rems-project/sail-x86-from-acl2`, is a + mechanical translation of the ACL2 x86isa model.** Its README says so in its + title and first paragraph: it "translates the X86isa formal model of the x86 + ISA, written in ACL2 by Shilpi Goel, Warren A. Hunt, Jr., and Matt Kaufmann, + into Sail". The translator is by Patrick Taylor (a 2020 student project, + supervised by Alasdair Armstrong and Peter Sewell), later extended by Thomas + Bauereiss. The model files are a snapshot of its output, and `model/LICENSE` + carries the ACL2 model's licence as the one it derives from. +- The files confirm it. `model/add_spec.sail` has `gpr_add_spec_1` where + `machine/instructions/add-spec.lisp` has `gpr-add-spec-1`, with the same + steps, in the same order, naming the same helpers (`cf_spec8`, + `add_af_spec8`). `model/conditional.sail` has `jcc_cmovcc_setcc_spec` with + the ACL2 condition table, and the ACL2 `let rflags_var = ...` bindings + survive in it. +- So an error in the ACL2 model's reading of the SDM is in the Sail model as + well, and a differential test between them tests the translator (and + Sail's typing of it), not the semantics. They share their authors' ancestry, + their reading of the manual and their test evidence. **They are one source + for the purpose of J.2.** +- The translated model is also narrower: it has no SSE2 scalar double + instruction (the ACL2 books in `machine/instructions/fp/` were not translated), + so it could not check the `addsd`/`sqrtsd`/`ucomisd` part of the subset even + as a copy. + +A second source that is not a translation: + +- **`shina-lab/sail-x86`** (vendored as `sail-x86-shina`, MIT) is a Sail model + written from the Intel SDM and the AMD manual, and its README and files + mention neither ACL2 nor x86isa. It covers SSE2 scalar double. Its + authorship is one person (Rui Ueyama, with many commits carrying an AI + co-author line); it was created in 2026-03 and has no external review that + we found; its floating-point arithmetic is `extern`, supplied by its + emulator; it states hardware agreement from KVM runs on two hosts (its commit + messages give counts of passing cases). It is independent in lineage, and + its weight as evidence is a person's decision. +- Other sources, not pinned: the K framework's x86-64 semantics (Dasgupta et + al., PLDI 2019, derived from Stoke's specifications, so a separate + lineage from ACL2) and Intel's XED tables (machine-readable encodings, not + semantics). A person may prefer one of them. +- The strongest evidence the plan has is not a model at all: exit criterion 3's + hardware differential tests (running every template on real CPUs on two + OSes) and the decoder differential against `iced-x86`. + +What this means for item J.3 and for the "Risks" paragraph of jit.md: unless a +person accepts `sail-x86-shina` (or another source) as the second, the +"independent transcription from the second source" of J.3 is an independent +transcription of the *same* ACL2 semantics (or of the SDM's pseudocode), and +the crate header must say that, as jit.md's Risks section already requires. diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/LICENSE.md b/crates/clazel-x64/tests/data/acl2-x86isa/LICENSE.md new file mode 100644 index 000000000..8ac217bbb --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/LICENSE.md @@ -0,0 +1,39 @@ +[Note: The license below is based on the template found July 25, 2014 + at: http://opensource.org/licenses/BSD-3-Clause. Except as + otherwise noted, it applies to all files distributed from + http://www.cs.utexas.edu/users/moore/acl2/current/, + as well as to all files distributed from + https://github.com/acl2/acl2 other than those in the + ACL2 Community Books (the books/ subdirectory). +When a file in the ACL2 Community Books refers to this LICENSE, that file's +specified copyright supersedes the copyright shown immediately below.] + +Copyright (c) 2026, Regents of the University of Texas +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +o Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +o Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +o Neither the name of the copyright holder nor the names of + its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/README b/crates/clazel-x64/tests/data/acl2-x86isa/README new file mode 100644 index 000000000..83f141436 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/README @@ -0,0 +1,20 @@ +---------------------------------------------------------------------- + A Formal and Executable Model of the x86 ISA + and the associated x86 Machine-Code Analysis Framework + + Shilpi Goel, Warren A. Hunt, Jr., and Matt Kaufmann + +---------------------------------------------------------------------- + +These files contain a specification of the x86 instruction set +architecture (ISA); we characterize x86 machine instructions and model +the instruction fetch, decode, and execute process using the ACL2 +theorem-proving system. They also contain proofs of correctness of +some x86 machine-code programs. + +Up-to-date documentation is available at: +http://www.cs.utexas.edu/users/moore/acl2/manuals/latest/?topic=ACL2____X86ISA + +Questions/Comments? Contact Shilpi Goel (shigoel@gmail.com). + +---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md b/crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md new file mode 100644 index 000000000..6f37e4bbe --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md @@ -0,0 +1,37 @@ +# The ACL2 x86isa model of the x86-64 instruction set (a subset of its files) + +Upstream: https://github.com/acl2/acl2/tree/33b05575eaf9f54734bf36e6f4bd8ee094ff2ee1/books/projects/x86isa +Commit: 33b05575eaf9f54734bf36e6f4bd8ee094ff2ee1 +License: BSD-3-Clause. The files are ACL2 Community Books, and each carries its own copyright header (Regents of the University of Texas; later years also Yahya Sohail and Intel Corporation), which supersedes the repository's `LICENSE`. `LICENSE.md` is the repository's `LICENSE` at this commit, copied unchanged. + +The commit is the tip of `master` of acl2/acl2 on 2026-11-16 (committed +07:06 UTC). The model is by Shilpi Goel, Warren A. Hunt Jr. and Matt Kaufmann +(University of Texas at Austin, with later contributors). Copied byte for +byte, with the paths relative to `books/projects/x86isa/` kept: + +- `README`, `portcullis/` (the package and the constants the books use); +- `utils/`: the data structures (`structures.lisp` and the others), without + the `.sys` certification caches; +- `machine/`: the fetch, prefix, ModR/M and SIB decoding, the opcode + listing (`inst-listing.lisp`), the register and memory accessors, RFLAGS, + and the dispatch; +- `machine/instructions/`: the instruction books the subset of jit.md item + J.3 reads: `add`, `sub`, `and`, `or`, `xor` (and their `-spec` books), + `arith-and-logic`, shifts and rotates, `multiply`, `logical`, + `conditional` (`jcc`, `cmovcc`, `setcc`), `jump-and-loop` (`jmp`), + `move`, `move-sse` (`movq`), `subroutine` (`ret`), `signextend`, `flags`; +- `machine/instructions/fp/`: the SSE2 floating-point books (`addsd`, + `subsd`, `mulsd`, `divsd`, `sqrtsd`, `ucomisd` and the conversions). + +Not vendored: the proofs (`proofs/`, 12.8 MB), the Linux and virtualization +projects, the `.sys` caches, the x87, SSE integer, MMX, string, segmentation, +paging-only and system-call books, and the images. The instruction books +include ACL2 system books (`centaur/bitops` and others) that are not +vendored; a reader of the model does not need them, and running it would need +the whole ACL2 distribution. + +To update, copy the files from a newer acl2/acl2 commit, change the commit +above, and run `cargo xtask testdata`. `xtask/src/testdata/isa.rs` writes +`tests/generated/acl2_x86isa.rs`, the inventory of paths, sizes and hashes. +Nothing reads the model yet. How this model relates to the Sail one is in +`crates/clazel-x64/README.md`. diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/application-level-memory.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/application-level-memory.lisp new file mode 100644 index 000000000..21e35faf1 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/application-level-memory.lisp @@ -0,0 +1,1349 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "state") + +(local (include-book "centaur/bitops/ihsext-basics" :dir :system)) +(local (include-book "centaur/bitops/width-find-rule" :dir :system)) + +(local (in-theory (disable unsigned-byte-p signed-byte-p))) + +;; =================================================================== + +(defsection app-view + + :parents (machine) + + :short "Application-level view of the x86 model" + + :long "

The x86 model can be used in the application-level view + when the value of the field @('app-view') is T.

+ +

Some supervisor-level features are neither used nor required for +the analysis of application software. In most cases, a user +cares about the correctness of his application program while assuming +that services like paging and I/O operations are provided reliably by +the operating system. The application-level view of our model attempts +to provide the same environment to an application for reasoning as is +provided by an OS for programming. In this mode, our memory model +provides the 2^48-byte linear address space specified for +modern 64-bit Intel machines.

+ +

A 64-bit canonical address can be in either of the two +ranges below:

+ + 0 to 2^47-1 or 2^64-2^47 to 2^64-1 + +

Note that this address space is 2^48 bytes of memory. So I can use +the addresses

+0 to 2^47-1 +

to map the first range, and the addresses

+-2^47 to -1 +

to map the second range.

+ +0 to 2^47-1 | 0 to 2^47-1
+2^64-2^47 to 2^64-1 | -2^47 to -1 + +

The advantage of doing so is that we will avoid bignum creation +during address computations.

+ +

We define some linear memory read and write functions, like @(see +rvm08) and @(see wvm08). These functions are called by the top-level +functions, like @(see rml08) and @(see wml08) when +@('app-view') is true.

+ +

The guards of the linear memory functions are stricter than those +of @('memi') and @('!memi'), because the latter allow reading from and +writing to an address anywhere in the range 0 to 2^52-1, and +@('rvm08') and @('wvm08') allow reads and writes only to the range +0 to 2^48-1 of physical memory: they take as argument a signed 48-bit +integer that represents a canonical address, they convert it to an unsigned +48-bit integer, and they use that to access the @('mem') field. +Basically, we're overloading the @('mem') field +in @('x86') --- when @('app-view') is set, @('mem') +refers to the linear memory; otherwise, it refers to the physical +memory.

" ) + +(defsection linear-memory-in-app-view + + :parents (app-view) + + :short "Definition of linear memory accessor and updater functions, + used when @('app-view') = @('T')" + + :long "

Note that the top-level memory accessor function is @(see + rml08) and updater function is @(see wml08). Their 16, 32, and 64 bit + counterparts are also available. These functions behave differently + depending upon the value of @('app-view').

" + + ) + +;; ---------------------------------------------------------------------- + +(define canonical-address-p (lin-addr) + :prepwork ((in-theory (e/d (signed-byte-p) ()))) + :parents (linear-memory-in-app-view) + :inline t + :no-function t + :enabled t + :short "Recognizer of a canonical address" + :long "

In 64-bit mode, a linear address is considered to be in + canonical form if address bits 63 through to the most-significant implemented + bit by the microarchitecture (represented by the constant + @('*max-linear-address-size*') in these books) are set to either all ones or + all zeros.

" + (mbe :logic (signed-byte-p #.*max-linear-address-size* lin-addr) + :exec (and (integerp lin-addr) + (<= #.*-2^47* lin-addr) + (< lin-addr #.*2^47*))) + + /// + + (defthm canonical-address-p-and-logext-48 + (implies (canonical-address-p a) + (equal (logext 48 a) a))) + + (defthm canonical-address-p-of-logext-48 + (canonical-address-p (logext 48 a)))) + +;; ---------------------------------------------------------------------- + +;; Memory Read Functions: + + +(define rvm08 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (mbe :logic (if (canonical-address-p addr) + (mv nil (memi (n48 addr) x86) x86) + (mv 'rvm08 0 x86)) + :exec (mv nil (memi (n48 addr) x86) x86)) + + /// + + (defthm rvm08-no-error + (implies (canonical-address-p addr) + (equal (mv-nth 0 (rvm08 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p n08p-mv-nth-1-rvm08 + :hyp t + :bound 8 + :concl (mv-nth 1 (rvm08 addr x86)) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm08-unchanged + (equal (mv-nth 2 (rvm08 addr x86)) + x86)) + + (defthm xr-rvm08 + (equal (xr fld index (mv-nth 2 (rvm08 addr x86))) + (xr fld index x86))) + + (defthm rvm08-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm08 addr (xw fld index value x86))) + (mv-nth 0 (rvm08 addr x86))) + (equal (mv-nth 1 (rvm08 addr (xw fld index value x86))) + (mv-nth 1 (rvm08 addr x86))))))) + +(local (in-theory (e/d (bitops::unsigned-byte-p-by-find-rule) ()))) + +(define rvm16 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((1+addr (the (signed-byte #.*max-linear-address-size+1*) + (1+ (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p (1+ addr)) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 1+addr) #.*2^47*)) + + (b* (((the (unsigned-byte 8) byte0) (memi (n48 addr) x86)) + ((the (unsigned-byte 8) byte1) (memi (n48 1+addr) x86))) + (mv nil + (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte1 8)) + byte0)) + x86)) + + (mv 'rvm16 0 x86))) + + (mv 'rvm16 0 x86)) + + /// + + (defthm rvm16-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 1 addr))) + (equal (mv-nth 0 (rvm16 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + + (defthm-unsigned-byte-p n16p-mv-nth-1-rvm16 + :hyp t + :bound 16 + :concl (mv-nth 1 (rvm16 addr x86)) + :gen-linear t + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-type t) + + (defthm x86p-mv-nth-2-rvm16-unchanged + (equal (mv-nth 2 (rvm16 addr x86)) + x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm xr-rvm16 + (equal (xr fld index (mv-nth 2 (rvm16 addr x86))) + (xr fld index x86))) + + (defthm rvm16-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm16 addr (xw fld index value x86))) + (mv-nth 0 (rvm16 addr x86))) + (equal (mv-nth 1 (rvm16 addr (xw fld index value x86))) + (mv-nth 1 (rvm16 addr x86))))))) + +(define rvm32 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((1+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 1 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (2+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (3+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 3 (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p (+ 3 addr)) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 3+addr) + #.*2^47*)) + + (b* (((the (unsigned-byte 8) byte0) (memi (n48 addr) x86)) + ((the (unsigned-byte 8) byte1) (memi (n48 1+addr) x86)) + ((the (unsigned-byte 8) byte2) (memi (n48 2+addr) x86)) + ((the (unsigned-byte 8) byte3) (memi (n48 3+addr) x86)) + ((the (unsigned-byte 16) word1) + (logior byte2 (the (unsigned-byte 16) (ash byte3 8)))) + ((the (unsigned-byte 24) high-24) + (logior byte1 (the (unsigned-byte 24) (ash word1 8)))) + ((the (unsigned-byte 32) dword) + (logior byte0 (the (unsigned-byte 32) (ash high-24 8))))) + (mv nil dword x86)) + + (mv 'rvm32 0 x86))) + + (mv 'rvm32 0 x86)) + + /// + + (defthm rvm32-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 3 addr))) + (equal (mv-nth 0 (rvm32 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm-unsigned-byte-p n32p-mv-nth-1-rvm32 + :hyp t + :bound 32 + :concl (mv-nth 1 (rvm32 addr x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p force (force))))) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm32-unchanged + (equal (mv-nth 2 (rvm32 addr x86)) + x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm xr-rvm32 + (equal (xr fld index (mv-nth 2 (rvm32 addr x86))) + (xr fld index x86))) + + (defthm rvm32-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm32 addr (xw fld index value x86))) + (mv-nth 0 (rvm32 addr x86))) + (equal (mv-nth 1 (rvm32 addr (xw fld index value x86))) + (mv-nth 1 (rvm32 addr x86))))))) + +(define rvm48 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((2+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (5+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 5 (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p 5+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 5+addr) #.*2^47*)) + + (b* (((mv flg0 (the (unsigned-byte 16) word0) x86) + (rvm16 addr x86)) + ((mv flg1 (the (unsigned-byte 32) dword1) x86) + (rvm32 2+addr x86)) + ((the (unsigned-byte 48) value) + (the (unsigned-byte 48) + (logior (the (unsigned-byte 48) (ash dword1 16)) + word0)))) + (mbe :logic (if (or flg0 flg1) + (mv 'rvm48 0 x86) + (mv nil value x86)) + :exec (mv nil value x86))) + + (mv 'rvm48 0 x86))) + + (mv 'rvm48 0 x86)) + + /// + + (local (in-theory (e/d () (rvm16 rvm32)))) + + (defthm rvm48-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 5 addr))) + (equal (mv-nth 0 (rvm48 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm-unsigned-byte-p n48p-mv-nth-1-rvm48 + :hyp t + :bound 48 + :concl (mv-nth 1 (rvm48 addr x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p force (force))))) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm48-unchanged + (equal (mv-nth 2 (rvm48 addr x86)) x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm xr-rvm48 + (equal (xr fld index (mv-nth 2 (rvm48 addr x86))) + (xr fld index x86))) + + (defthm rvm48-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm48 addr (xw fld index value x86))) + (mv-nth 0 (rvm48 addr x86))) + (equal (mv-nth 1 (rvm48 addr (xw fld index value x86))) + (mv-nth 1 (rvm48 addr x86))))))) + +(define rvm64 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d () (rvm32)))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((4+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 4 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (7+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 7 (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p 7+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 7+addr) #.*2^47*)) + + (b* (((mv flg0 (the (unsigned-byte 32) dword0) x86) + (rvm32 addr x86)) + ((mv flg1 (the (unsigned-byte 32) dword1) x86) + (rvm32 4+addr x86)) + ((the (unsigned-byte 64) qword) + (the (unsigned-byte 64) (logior + (the (unsigned-byte 64) + (ash dword1 32)) + dword0)))) + (mbe :logic (if (or flg0 flg1) + (mv 'rvm64 0 x86) + (mv nil qword x86)) + :exec (mv nil qword x86))) + + (mv 'rvm64 0 x86))) + + (mv 'rvm64 0 x86)) + + /// + + (local (in-theory (e/d () (rvm32)))) + + (defthm rvm64-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 7 addr))) + (equal (mv-nth 0 (rvm64 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + + (defthm-unsigned-byte-p n64p-mv-nth-1-rvm64 + :hyp t + :bound 64 + :concl (mv-nth 1 (rvm64 addr x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p force (force))))) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm64-unchanged + (equal (mv-nth 2 (rvm64 addr x86)) + x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm xr-rvm64 + (equal (xr fld index (mv-nth 2 (rvm64 addr x86))) + (xr fld index x86))) + + (defthm rvm64-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm64 addr (xw fld index value x86))) + (mv-nth 0 (rvm64 addr x86))) + (equal (mv-nth 1 (rvm64 addr (xw fld index value x86))) + (mv-nth 1 (rvm64 addr x86))))))) + +(define rvm80 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d () (rvm32)))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((2+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (9+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 9 (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p 9+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 9+addr) #.*2^47*)) + + (b* (((mv flg0 (the (unsigned-byte 16) word0) x86) + (rvm16 addr x86)) + ((mv flg1 (the (unsigned-byte 64) qword1) x86) + (rvm64 2+addr x86)) + ((the (unsigned-byte 80) value) + (the (unsigned-byte 80) + (logior (the (unsigned-byte 80) (ash qword1 16)) + word0)))) + (mbe :logic (if (or flg0 flg1) + (mv 'rvm80 0 x86) + (mv nil value x86)) + :exec (mv nil value x86))) + + (mv 'rvm80 0 x86))) + + (mv 'rvm80 0 x86)) + + /// + + (local (in-theory (e/d () (rvm16 rvm64)))) + + (defthm rvm80-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 9 addr))) + (equal (mv-nth 0 (rvm80 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm-unsigned-byte-p n80p-mv-nth-1-rvm80 + :hyp t + :bound 80 + :concl (mv-nth 1 (rvm80 addr x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p force (force))))) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm80-unchanged + (equal (mv-nth 2 (rvm80 addr x86)) x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm xr-rvm80 + (equal (xr fld index (mv-nth 2 (rvm80 addr x86))) + (xr fld index x86))) + + (defthm rvm80-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm80 addr (xw fld index value x86))) + (mv-nth 0 (rvm80 addr x86))) + (equal (mv-nth 1 (rvm80 addr (xw fld index value x86))) + (mv-nth 1 (rvm80 addr x86))))))) + +(define rvm128 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d () (rvm64)))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((8+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 8 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (15+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 15 (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p 15+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 15+addr) #.*2^47*)) + + (b* (((mv flg0 (the (unsigned-byte 64) qword0) x86) + (rvm64 addr x86)) + ((mv flg1 (the (unsigned-byte 64) qword1) x86) + (rvm64 8+addr x86)) + ((the (unsigned-byte 128) oword) + (the (unsigned-byte 128) (logior + (the (unsigned-byte 128) + (ash qword1 64)) + qword0)))) + (mbe :logic (if (or flg0 flg1) + (mv 'rvm128 0 x86) + (mv nil oword x86)) + :exec (mv nil oword x86))) + + (mv 'rvm128 0 x86))) + + (mv 'rvm128 0 x86)) + + /// + + (local (in-theory (e/d () (rvm64)))) + + (defthm rvm128-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 15 addr))) + (equal (mv-nth 0 (rvm128 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force) rvm64))))) + + (defthm-unsigned-byte-p n128p-mv-nth-1-rvm128 + :hyp t + :bound 128 + :concl (mv-nth 1 (rvm128 addr x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p force (force) rvm64)))) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm128-unchanged + (equal (mv-nth 2 (rvm128 addr x86)) + x86) + :hints (("Goal" :in-theory (e/d () (force (force) rvm64))))) + + (defthm xr-rvm128 + (equal (xr fld index (mv-nth 2 (rvm128 addr x86))) + (xr fld index x86))) + + (defthm rvm128-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm128 addr (xw fld index value x86))) + (mv-nth 0 (rvm128 addr x86))) + (equal (mv-nth 1 (rvm128 addr (xw fld index value x86))) + (mv-nth 1 (rvm128 addr x86))))))) + +(define rvm256 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d () (rvm128)))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((16+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 16 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (31+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 31 (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p 31+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 31+addr) #.*2^47*)) + + (b* (((mv flg0 (the (unsigned-byte 128) oword0) x86) + (rvm128 addr x86)) + ((mv flg1 (the (unsigned-byte 128) oword1) x86) + (rvm128 16+addr x86)) + ((the (unsigned-byte 256) xword) + (the (unsigned-byte 256) (logior + (the (unsigned-byte 256) + (ash oword1 128)) + oword0)))) + (mbe :logic (if (or flg0 flg1) + (mv 'rvm256 0 x86) + (mv nil xword x86)) + :exec (mv nil xword x86))) + + (mv 'rvm256 0 x86))) + + (mv 'rvm256 0 x86)) + + /// + + (local (in-theory (e/d () (rvm128)))) + + (defthm rvm256-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 31 addr))) + (equal (mv-nth 0 (rvm256 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force) rvm128))))) + + (defthm-unsigned-byte-p n256p-mv-nth-1-rvm256 + :hyp t + :bound 256 + :concl (mv-nth 1 (rvm256 addr x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p force (force) rvm128)))) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm256-unchanged + (equal (mv-nth 2 (rvm256 addr x86)) + x86) + :hints (("Goal" :in-theory (e/d () (force (force) rvm128))))) + + (defthm xr-rvm256 + (equal (xr fld index (mv-nth 2 (rvm256 addr x86))) + (xr fld index x86))) + + (defthm rvm256-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm256 addr (xw fld index value x86))) + (mv-nth 0 (rvm256 addr x86))) + (equal (mv-nth 1 (rvm256 addr (xw fld index value x86))) + (mv-nth 1 (rvm256 addr x86))))))) + +(define rvm512 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d () (rvm256)))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((32+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 32 (the (signed-byte #.*max-linear-address-size*) + addr)))) + (63+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 63 (the (signed-byte #.*max-linear-address-size*) + addr))))) + + (if (mbe :logic (canonical-address-p 63+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 63+addr) #.*2^47*)) + + (b* (((mv flg0 (the (unsigned-byte 256) xword0) x86) + (rvm256 addr x86)) + ((mv flg1 (the (unsigned-byte 256) xword1) x86) + (rvm256 32+addr x86)) + ((the (unsigned-byte 512) xxword) + (the (unsigned-byte 512) (logior + (the (unsigned-byte 512) + (ash xword1 256)) + xword0)))) + (mbe :logic (if (or flg0 flg1) + (mv 'rvm512 0 x86) + (mv nil xxword x86)) + :exec (mv nil xxword x86))) + + (mv 'rvm512 0 x86))) + + (mv 'rvm512 0 x86)) + + /// + + (local (in-theory (e/d () (rvm256)))) + + (defthm rvm512-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 63 addr))) + (equal (mv-nth 0 (rvm512 addr x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force) rvm256))))) + + (defthm-unsigned-byte-p n512p-mv-nth-1-rvm512 + :hyp t + :bound 512 + :concl (mv-nth 1 (rvm512 addr x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p force (force) rvm256)))) + :gen-linear t + :gen-type t) + + (defthm x86p-mv-nth-2-rvm512-unchanged + (equal (mv-nth 2 (rvm512 addr x86)) + x86) + :hints (("Goal" :in-theory (e/d () (force (force) rvm256))))) + + (defthm xr-rvm512 + (equal (xr fld index (mv-nth 2 (rvm512 addr x86))) + (xr fld index x86))) + + (defthm rvm512-xw-values + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (rvm512 addr (xw fld index value x86))) + (mv-nth 0 (rvm512 addr x86))) + (equal (mv-nth 1 (rvm512 addr (xw fld index value x86))) + (mv-nth 1 (rvm512 addr x86))))))) + +;; ---------------------------------------------------------------------- + +;; Memory Write Functions: + +(define wvm08 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 8)) + (x86)) + :enabled t + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (mbe :logic (if (canonical-address-p addr) + (let ((x86 (!memi (n48 addr) (n08 val) x86))) + (mv nil x86)) + (mv 'wvm08 x86)) + :exec (let ((x86 (!memi (n48 addr) val x86))) + (mv nil x86))) + /// + + (defthm wvm08-no-error + (implies (canonical-address-p addr) + (equal (mv-nth 0 (wvm08 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm08 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm08 addr val x86)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm xr-wmv08-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm08 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm08) ())))) + + (defthm wvm08-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm08 addr val (xw fld index value x86))) + (mv-nth 0 (wvm08 addr val x86))) + (equal (mv-nth 1 (wvm08 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm08 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm08 wvm08) ()))))) + +(define wvm16 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 16)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((1+addr (the (signed-byte #.*max-linear-address-size+1*) + (1+ (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 1+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 1+addr) + #.*2^47*)) + + (b* (((the (unsigned-byte 8) byte0) + (mbe :logic (n08 val) + :exec (logand #xff val))) + ((the (unsigned-byte 8) byte1) + (mbe :logic (part-select val :low 8 :width 8) + :exec (logand #xff (ash val -8)))) + (x86 (!memi (n48 addr) byte0 x86)) + (x86 (!memi (n48 1+addr) byte1 x86))) + (mv nil x86)) + + (mv 'wvm16 x86))) + + (mv 'wvm16 x86)) + + /// + + (defthm wvm16-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 3 addr))) + (equal (mv-nth 0 (wvm16 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm16 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm16 addr val x86)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm xr-wmv16-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm16 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm16) ())))) + + (defthm wvm16-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm16 addr val (xw fld index value x86))) + (mv-nth 0 (wvm16 addr val x86))) + (equal (mv-nth 1 (wvm16 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm16 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm16 wvm16) ()))))) + +(define wvm32 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 32)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((1+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 1 (the (signed-byte #.*max-linear-address-size*) addr)))) + (2+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) addr)))) + (3+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 3 (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 3+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 3+addr) #.*2^47*)) + + (b* (((the (unsigned-byte 8) byte0) + (mbe :logic (part-select val :low 0 :width 8) + :exec (logand #xff val))) + ((the (unsigned-byte 8) byte1) + (mbe :logic (part-select val :low 8 :width 8) + :exec (logand #xff (ash val -8)))) + ((the (unsigned-byte 8) byte2) + (mbe :logic (part-select val :low 16 :width 8) + :exec (logand #xff (ash val -16)))) + ((the (unsigned-byte 8) byte3) + (mbe :logic (part-select val :low 24 :width 8) + :exec (logand #xff (ash val -24)))) + (x86 (!memi (n48 addr) byte0 x86)) + (x86 (!memi (n48 1+addr) byte1 x86)) + (x86 (!memi (n48 2+addr) byte2 x86)) + (x86 (!memi (n48 3+addr) byte3 x86))) + (mv nil x86)) + + (mv 'wvm32 x86))) + + (mv 'wvm32 x86)) + + /// + + (defthm wvm32-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 3 addr))) + (equal (mv-nth 0 (wvm32 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm32 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm32 addr val x86)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm xr-wmv32-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm32 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm32) ())))) + + (defthm wvm32-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm32 addr val (xw fld index value x86))) + (mv-nth 0 (wvm32 addr val x86))) + (equal (mv-nth 1 (wvm32 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm32 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm32 wvm32) ()))))) + +(define wvm48 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 48)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((2+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) addr)))) + (5+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 5 (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 5+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 5+addr) #.*2^47*)) + + (b* ((word0 (mbe :logic (part-select val :low 0 :width 16) + :exec (logand #xFFFF val))) + (dword1 (mbe :logic (part-select val :low 16 :width 32) + :exec (logand #xFFFFFFFF (ash val -16)))) + ((mv flg0 x86) (wvm16 addr word0 x86)) + ((mv flg1 x86) (wvm32 2+addr dword1 x86))) + (mbe :logic (if (or flg0 flg1) + (mv 'wvm48 x86) + (mv nil x86)) + :exec (mv nil x86))) + + (mv 'wvm48 x86))) + + (mv 'wvm48 x86)) + + /// + + (defthm wvm48-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 5 addr))) + (equal (mv-nth 0 (wvm48 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm48 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm48 addr val x86)))) + :rule-classes (:type-prescription :rewrite)) + + (defthm xr-wmv48-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm48 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm48) ())))) + + (defthm wvm48-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm48 addr val (xw fld index value x86))) + (mv-nth 0 (wvm48 addr val x86))) + (equal (mv-nth 1 (wvm48 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm48 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm48 wvm48) ()))))) + +(define wvm64 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 64)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((4+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 4 (the (signed-byte #.*max-linear-address-size*) addr)))) + (7+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 7 (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 7+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 7+addr) #.*2^47*)) + + (b* ((dword0 (mbe :logic (part-select val :low 0 :width 32) + :exec (logand #xFFFFFFFF val))) + (dword1 (mbe :logic (part-select val :low 32 :width 32) + :exec (logand #xFFFFFFFF (ash val -32)))) + ((mv flg0 x86) (wvm32 addr dword0 x86)) + ((mv flg1 x86) (wvm32 4+addr dword1 x86))) + (mbe :logic (if (or flg0 flg1) + (mv 'wvm64 x86) + (mv nil x86)) + :exec (mv nil x86))) + + (mv 'wvm64 x86))) + + (mv 'wvm64 x86)) + + /// + + (defthm wvm64-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 7 addr))) + (equal (mv-nth 0 (wvm64 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm64 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm64 addr val x86)))) + :rule-classes (:type-prescription :rewrite)) + + (defthm xr-wmv64-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm64 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm64) ())))) + + (defthm wvm64-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm64 addr val (xw fld index value x86))) + (mv-nth 0 (wvm64 addr val x86))) + (equal (mv-nth 1 (wvm64 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm64 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm64 wvm64) ()))))) + +(define wvm80 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 80)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + + (if (mbt (canonical-address-p addr)) + + (let* ((2+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) addr)))) + (9+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 9 (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 9+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 9+addr) #.*2^47*)) + + (b* ((word0 (mbe :logic (part-select val :low 0 :width 16) + :exec (logand #xFFFF val))) + (qword1 (mbe :logic (part-select val :low 16 :width 64) + :exec (logand #xFFFFFFFFFFFFFFFF (ash val -16)))) + ((mv flg0 x86) (wvm16 addr word0 x86)) + ((mv flg1 x86) (wvm64 2+addr qword1 x86))) + (mbe :logic (if (or flg0 flg1) + (mv 'wvm80 x86) + (mv nil x86)) + :exec (mv nil x86))) + + (mv 'wvm80 x86))) + + (mv 'wvm80 x86)) + + /// + + (defthm wvm80-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 9 addr))) + (equal (mv-nth 0 (wvm80 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm80 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm80 addr val x86)))) + :rule-classes (:type-prescription :rewrite)) + + (defthm xr-wmv80-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm80 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm80) ())))) + + (defthm wvm80-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm80 addr val (xw fld index value x86))) + (mv-nth 0 (wvm80 addr val x86))) + (equal (mv-nth 1 (wvm80 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm80 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm80 wvm80) ()))))) + +(define wvm128 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 128)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + :prepwork ((local (in-theory (e/d () (wvm64))))) + (if (mbt (canonical-address-p addr)) + + (let* ((8+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 8 (the (signed-byte #.*max-linear-address-size*) addr)))) + (15+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 15 (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 15+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 15+addr) #.*2^47*)) + + (b* ((qword0 (mbe :logic (part-select val :low 0 :width 64) + :exec (logand #xFFFFFFFFFFFFFFFF val))) + (qword1 (mbe :logic (part-select val :low 64 :width 64) + :exec (logand #xFFFFFFFFFFFFFFFF (ash val -64)))) + ((mv flg0 x86) (wvm64 addr qword0 x86)) + ((mv flg1 x86) (wvm64 8+addr qword1 x86))) + (mbe :logic (if (or flg0 flg1) + (mv 'wvm128 x86) + (mv nil x86)) + :exec (mv nil x86))) + + (mv 'wvm128 x86))) + + (mv 'wvm128 x86)) + + /// + + (defthm wvm128-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 15 addr))) + (equal (mv-nth 0 (wvm128 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm128 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm128 addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:type-prescription :rewrite)) + + (defthm xr-wmv128-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm128 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm128) ())))) + + (defthm wvm128-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm128 addr val (xw fld index value x86))) + (mv-nth 0 (wvm128 addr val x86))) + (equal (mv-nth 1 (wvm128 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm128 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm128 wvm128) ()))))) + +(define wvm256 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 256)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + :prepwork ((local (in-theory (e/d () (wvm128))))) + (if (mbt (canonical-address-p addr)) + + (let* ((16+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 16 (the (signed-byte #.*max-linear-address-size*) addr)))) + (31+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 31 (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 31+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 31+addr) #.*2^47*)) + + (b* ((oword0 (mbe :logic (part-select val :low 0 :width 128) + :exec (logand #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF val))) + (oword1 (mbe :logic (part-select val :low 128 :width 128) + :exec (logand #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF (ash val -128)))) + ((mv flg0 x86) (wvm128 addr oword0 x86)) + ((mv flg1 x86) (wvm128 16+addr oword1 x86))) + (mbe :logic (if (or flg0 flg1) + (mv 'wvm256 x86) + (mv nil x86)) + :exec (mv nil x86))) + + (mv 'wvm256 x86))) + + (mv 'wvm256 x86)) + + /// + + (defthm wvm256-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 31 addr))) + (equal (mv-nth 0 (wvm256 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm256 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm256 addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:type-prescription :rewrite)) + + (defthm xr-wmv256-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm256 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm256) ())))) + + (defthm wvm256-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm256 addr val (xw fld index value x86))) + (mv-nth 0 (wvm256 addr val x86))) + (equal (mv-nth 1 (wvm256 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm256 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm256 wvm256) ()))))) + +(define wvm512 + ((addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 512)) + (x86)) + :enabled t + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :inline t + :no-function t + :parents (linear-memory-in-app-view) + :prepwork ((local (in-theory (e/d () (wvm256))))) + (if (mbt (canonical-address-p addr)) + + (let* ((32+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 32 (the (signed-byte #.*max-linear-address-size*) addr)))) + (63+addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 63 (the (signed-byte #.*max-linear-address-size*) addr))))) + + (if (mbe :logic (canonical-address-p 63+addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) 63+addr) #.*2^47*)) + + (b* ((oword0 (mbe :logic (part-select val :low 0 :width 256) + :exec (logand #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + val))) + (oword1 (mbe :logic (part-select val :low 256 :width 256) + :exec (logand #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + (ash val -256)))) + ((mv flg0 x86) (wvm256 addr oword0 x86)) + ((mv flg1 x86) (wvm256 32+addr oword1 x86))) + (mbe :logic (if (or flg0 flg1) + (mv 'wvm512 x86) + (mv nil x86)) + :exec (mv nil x86))) + + (mv 'wvm512 x86))) + + (mv 'wvm512 x86)) + + /// + + (defthm wvm512-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ 63 addr))) + (equal (mv-nth 0 (wvm512 addr val x86)) + nil)) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + (defthm x86p-mv-nth-1-wvm512 + (implies (x86p x86) + (x86p (mv-nth 1 (wvm512 addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:type-prescription :rewrite)) + + (defthm xr-wmv512-app-view + (implies (not (equal fld :mem)) + (equal (xr fld index (mv-nth 1 (wvm512 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm512) ())))) + + (defthm wvm512-xw-app-view + (implies (not (equal fld :mem)) + (and (equal (mv-nth 0 (wvm512 addr val (xw fld index value x86))) + (mv-nth 0 (wvm512 addr val x86))) + (equal (mv-nth 1 (wvm512 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wvm512 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wvm512 wvm512) ()))))) + +;; ---------------------------------------------------------------------- + +(globally-disable '(rvm08 rvm16 wvm16 rvm32 rvm48 rvm64 rvm80 rvm128 rvm256 rvm512 + wvm08 wvm16 wvm16 wvm32 wvm48 wvm64 wvm80 wvm128 wvm256 wvm512)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/decoding-and-spec-utils.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/decoding-and-spec-utils.lisp new file mode 100644 index 000000000..d6feb5f4e --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/decoding-and-spec-utils.lisp @@ -0,0 +1,2615 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2019, Kestrel Technology, LLC + +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Matt Kaufmann +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +(include-book "std/util/def-bound-theorems" :dir :system) +(include-book "state") +(include-book "application-level-memory") +(include-book "segmentation") +(include-book "top-level-memory") +(include-book "../utils/segmentation-structures") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(in-theory (e/d () (mv-nth))) + +;; ====================================================================== + +(defsection decoding-and-spec-utils + :parents (machine) + :short "Miscellaneous utilities for instruction decoding and for writing + instruction specification functions") + +(local (xdoc::set-default-parents decoding-and-spec-utils)) + +;; ====================================================================== + +(defsection error-objects + + :parents (decoding-and-spec-utils) + + :short "Utilities trafficking in @('erp') objects" + + :long "

We introduce several utilities trafficking in @('erp') +objects, each of which is a stack of individual error objects +typically of the form (ctx . kwd-alist), where @('ctx') is +typically a function name. We do not enforce the shape of an +individual error object, however.

+ +
    +
  • @('!ms-erp'): This macro assumes that @('erp') is already bound +to an error stack, and @('ctx') is bound to the current context, which +is typically the function name (a symbol).
  • + +
  • @('!ms-erp-fresh'): This is same as @('!ms-erp'), but where +@('erp') is not bound and we bind it to @('nil').
  • + +
  • @('!!ms'): @('erp'), @('ctx'), and also @('x86') must already +be bound. We return an updated @('x86') that has a non-nil @('ms') +field conveying useful information.
  • + +
  • @('!!ms-fresh'): @('ctx') and @('x86') must already be bound.
  • + +
  • @('!!fault-fresh'): like @('!!ms-fresh') but it updates +the @('fault') field instead.
  • + +
+ +@(def !ms-erp) + +@(def !ms-erp-fresh) + +@(def !!ms) + +@(def !!ms-fresh) + +@(def !!fault-fresh)" + + (defmacro !ms-erp (&rest args) + `(cons (list ctx ,@args) + erp)) + + (defmacro !ms-erp-fresh (&rest args) + `(let ((erp nil)) + (!ms-erp ,@args))) + + (defmacro !!ms (&rest args) + `(!ms (!ms-erp :rip (rip x86) ,@args) + x86)) + + (defmacro !!ms-fresh (&rest args) + `(!ms (!ms-erp-fresh :rip (rip x86) ,@args) + x86)) + + (defmacro !!fault-fresh (&rest args) + `(!fault (!ms-erp-fresh :rip (rip x86) ,@args) + x86))) + +;; ====================================================================== + +(defsection instruction-pointer-operations + :parents (decoding-and-spec-utils) + :short "Operations to manipulate instruction pointers." + + (define read-*ip ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + x86) + :returns (*ip i48p :hyp (x86p x86)) + + :parents (instruction-pointer-operations) + :short "Read the instruction pointer from the register RIP, EIP, or IP." + :long + "

+ In 64-bit mode, a 64-bit instruction pointer is read from the full RIP. + Since, in the model, this is a 48-bit signed integer, + this function returns a 48-bit signed integer. +

+

+ In 32-bit mode, a 32-bit or 16-bit instruction pointer is read from + EIP (i.e. the low 32 bits of RIP) + or IP (i.e. the low 16 bits of RIP), + based on the CS.D bit, + i.e. the D bit of the current code segment descriptor. + Either way, this function returns an unsigned 32-bit or 16-bit integer, + which is also a signed 48-bit integer. +

+

+ See AMD manual, Oct'13, Vol. 1, Sec. 2.2.4 and Sec. 2.5. + AMD manual, Apr'16, Vol. 2, Sec 4.7.2., + and Intel manual, Mar'17, Vol. 1, Sec. 3.6. +

+

+ In 32-bit mode, the address-size override prefix (if present) + should not affect the instruction pointer size. + It does not seem to make sense + to change the instruction pointer size on a per-instruction basis. +

" + (b* ((*ip (the (signed-byte #.*max-linear-address-size*) (rip x86)))) + (case proc-mode + (#.*64-bit-mode* *ip) + (#.*compatibility-mode* + (b* (((the (unsigned-byte 16) cs-attr) + (seg-hidden-attri #.*cs* x86)) + (cs.d (code-segment-descriptor-attributesBits->d cs-attr))) + (if (= cs.d 1) + (n32 *ip) + (n16 *ip)))) + (otherwise + ;; Unimplemented for other modes! + 0))) + :inline t + :no-function t + /// + + (defthm-signed-byte-p read-*ip-is-i48p + :hyp (x86p x86) + :bound 48 + :concl (read-*ip proc-mode x86) + :gen-type t + :gen-linear t) + + (defrule read-*ip-when-64-bit-modep + (equal (read-*ip #.*64-bit-mode* x86) + (rip x86))) + + (defthm-unsigned-byte-p read-*ip-when-not-64-bit-modep + :hyp (not (equal proc-mode #.*64-bit-mode*)) + :bound 32 + :concl (read-*ip proc-mode x86) + :gen-type t + :gen-linear t)) + + (define add-to-*ip ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (*ip :type (signed-byte #.*max-linear-address-size*)) + (delta :type (signed-byte #.*max-linear-address-size*)) + x86) + :returns (mv flg + (*ip+delta i48p + :hyp (and (i48p *ip) (i48p delta)))) + :prepwork + ((local (in-theory (e/d () (force (force)))))) + :parents (instruction-pointer-operations) + :short "Add a specified amount to an instruction pointer." + :long + "

+ The amount may be positive (increment) or negative (decrement). + This just calculates the new instruction pointer value, + without storing it into the register RIP, EIP, or IP. + The starting value is the result of @(tsee read-*ip) + or a previous invocation of @(tsee add-to-*ip). +

+

+ In 64-bit mode, we check whether the result is a canonical address; + in 32-bit mode, we check whether the result is within the segment limit. + If these checks are not satisfied, + this function returns an error flag (and 0 as incremented address), + which causes the x86 model to stop execution with an error. + It is not clear whether these checks should be performed + when the instruction pointer is incremented + or when an instruction byte is eventually accessed; + the Intel and AMD manuals seem unclear in this respect. + But since the failure of these checks stops execution with an error, + and it is in a way always ``safe'' to stop execution with an error + (in the sense that the model provides no guarantees when this happens), + for now we choose to perform these checks here. +

+

+ Note that a code segment is never expand-down, + so the valid effective addresses are always between 0 and the segment limit + (cf. @(tsee segment-base-and-bounds)). +

" + + (b* ((*ip+delta + (the (signed-byte #.*max-linear-address-size+1*) + (+ *ip delta)))) + + (case proc-mode + + (#.*64-bit-mode* + (if (mbe :logic (canonical-address-p *ip+delta) + :exec (and (<= #.*-2^47* *ip+delta) + (< *ip+delta #.*2^47*))) + (mv nil *ip+delta) + (mv (list :non-canonical-instruction-pointer *ip+delta) 0))) + + (#.*compatibility-mode* + (b* (((the (unsigned-byte 32) cs.limit) + (mbe :logic (loghead 32 (seg-hidden-limiti #.*cs* x86)) + :exec (seg-hidden-limiti #.*cs* x86)))) + (if (and (<= 0 *ip+delta) + (<= *ip+delta cs.limit)) + (mv nil (the (unsigned-byte 32) *ip+delta)) + (mv (list :out-of-segment-instruction-pointer cs.limit *ip+delta) + 0)))) + + (otherwise + (mv (list :unimplemented-proc-mode proc-mode) + 0)))) + + :inline t + :no-function t + /// + + (defthm-signed-byte-p add-to-*ip-is-i48p + :hyp (and (integerp *ip) + (<= -140737488355328 *ip) + (< *ip 140737488355328) + (integerp delta)) + :bound 48 + :concl (mv-nth 1 (add-to-*ip proc-mode *ip delta x86)) + :gen-type t + :gen-linear t) + + (encapsulate () + (local (include-book "kestrel/arithmetic-light/expt2" :dir :system)) + (defthm signed-byte-p-of-mv-nth-1-of-add-to-*ip + (implies (and (<= 48 size) + (integerp size) + (integerp *ip) + (integerp delta)) + (signed-byte-p size + (mv-nth 1 + (add-to-*ip proc-mode *ip delta x86)))))) + + ;; The following theorem is a rewrite rule version of the theorems + ;; generated by the DEFTHM-SIGNED-BYTE-P just above. This rewrite rule is + ;; somewhat inelegant, but without it some proofs fail. The proofs in + ;; question are the ones that enable this rule explicitly, for example the + ;; guard verification proof of TWO-BYTE-OPCODE-DECODE-AND-EXECUTE. The + ;; proofs fail with subgoals about nested ADD-TO-*IPs being 48-bit signed + ;; integers. Perhaps the reason for the failures is that the type + ;; prescription and linear rules generated by the DEFTHM-SIGNED-BYTE-P + ;; above are not triggered on the outer ADD-TO-*IPs of the nests because no + ;; hypotheses about the inner ADD-TO-*IPs are available in the current + ;; proof context. With a rewrite rule, instead, the prover is able to + ;; backchain. We should see if we arrange things so that we can avoid this + ;; rewrite rule. We leave it disabled by default so it's more clear where + ;; it's needed. + (defruled add-to-*ip-is-i48p-rewrite-rule + (implies + (and (integerp *ip) + (<= -140737488355328 *ip) + (< *ip 140737488355328) + (integerp delta)) + (and (integerp (mv-nth 1 (add-to-*ip proc-mode *ip delta x86))) + (rationalp (mv-nth 1 (add-to-*ip proc-mode *ip delta x86))) + (<= -140737488355328 (mv-nth 1 (add-to-*ip proc-mode *ip delta x86))) + (< (mv-nth 1 (add-to-*ip proc-mode *ip delta x86)) 140737488355328) + ;; The following allow us to disable signed-byte-p in places where + ;; add-to-*ip is followed by a check for canonical addresses. + (signed-byte-p 48 (mv-nth 1 (add-to-*ip proc-mode *ip delta x86))) + (signed-byte-p 64 (mv-nth 1 (add-to-*ip proc-mode *ip delta x86)))))) + + (defrule add-to-*ip-rationalp-type + (implies (and (rationalp *ip) + (rationalp delta)) + (rationalp (mv-nth 1 (add-to-*ip proc-mode *ip delta x86)))) + :rule-classes :type-prescription) + + (defrule mv-nth-0-of-add-to-*ip-when-64-bit-modep + (equal (mv-nth 0 (add-to-*ip #.*64-bit-mode* *ip delta x86)) + (if (canonical-address-p (+ *ip delta)) + nil + (list + :non-canonical-instruction-pointer (+ *ip delta))))) + + (defrule mv-nth-1-of-add-to-*ip-when-64-bit-modep + (equal (mv-nth 1 (add-to-*ip #.*64-bit-mode* *ip delta x86)) + (if (canonical-address-p (+ *ip delta)) + (+ *ip delta) + 0))) + + (defthm-unsigned-byte-p mv-nth-1-of-add-to-*ip-when-compatibility-modep + :hyp (and (not (equal proc-mode #.*64-bit-mode*)) + (integerp (+ *ip delta)) + (not (mv-nth 0 + (add-to-*ip + proc-mode *ip delta x86)))) + :bound 32 + :concl (mv-nth 1 (add-to-*ip proc-mode *ip delta x86)) + :gen-linear t + :gen-type t)) + + (define write-*ip ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (*ip :type (signed-byte #.*max-linear-address-size*)) + x86) + :returns (x86-new x86p + :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + :guard (if (equal proc-mode #.*64-bit-mode*) + t + ;; Could strengthen the following, based on cs.d value... + (unsigned-byte-p 32 *ip) + ;; (b* (((the (unsigned-byte 16) cs-attr) + ;; (xr :seg-hidden-attr #.*cs* x86)) + ;; (cs.d + ;; (code-segment-descriptor-attributesBits->d cs-attr))) + ;; (case cs.d + ;; (0 (unsigned-byte-p 16 *ip)) + ;; (otherwise (unsigned-byte-p 32 *ip)))) + ) + + :parents (instruction-pointer-operations) + :short "Write an instruction pointer into the register RIP, EIP, or IP." + :long + "

+ In 64-bit mode, a 64-bit instruction pointer is written into the full RIP. + Since, in the model, this is a 48-bit signed integer, + this function consumes a 48-bit signed integer. +

+

+ In 32-bit mode, the instruction pointer is 32 or 16 bits + based on the CS.D bit, i.e. the D bit of the current code segment descriptor. + In these cases, the argument to this function should be + a 32-bit or 16-bit unsigned integer, which is also a 48-bit signed integer. +

+

+ See AMD manual, Oct'13, Vol. 1, Sec. 2.2.4 and Sec. 2.5. + AMD manual, Apr'16, Vol. 2, Sec 4.7.2., + and Intel manual, Mar'17, Vol. 1, Sec. 3.6. +

+

+ According to Intel manual, Mar'17, Vol. 1, Table 3-1, + it seems that + when writing a 32-bit instruction pointer (EIP) + the high 32 bits of RIP should be set to 0, + and when writing a 16-bit instruction pointer (IP) + the high 48 bits of RIP should be left unmodified; + since in our model the RIP is 48 bits, + the above applies to the high 16 and 32 bits, respectively. + The pseudocode for the JMP instruction in Intel manual, Mar'17, Vol. 2 + shows an assignment @('EIP <- tempEIP AND 0000FFFFh') for the 16-bit case, + which seems to imply that + the high 32 (or 16, in our model) bits are left unmodified + and the high 16 bits of EIP are set to 0, + which would contradict Table 3-1; + the pseudocode for some other instructions + that directly write the instruction pointer (e.g. RET and Jcc) + show similar assignments. + However, it is possible that this assignment has a typo and should be + @('IP <- tempEIP AND 0000FFFFh') instead, + which would be consistent with Table 3-1. + But we also note that the pseudocode for the JMP instruction + shows an assignment @('EIP <- tempEIP') for the 32-bit case, + which seems to imply that + the high 32 (or 16, in our model) bits are left unmodified, + which would contradict Table 3-1. + The AMD manuals do not show pseudocode for these instructions, + and AMD manual, Oct'13, Vol. 1, Fig. 2-10 + (which is somewhat analogous to Intel's Table 3-1) + shows the high bits simply grayed out; + so the AMD manuals do not provide disambiguation help. + It is also possible that Table 3-1 has a typo and should say + that a 16-bit instruction pointer is zero-extended, + but that is not quite consistent with the pseudocode assignments to EIP, + which seem to imply that the high bits are untouched. + Table 3-1 is under a section titled + `Address Calculation in 64-Bit Mode', + which may suggest that the table may not apply to 32-bit mode, + but then it is not clear how it would just apply to 64-bit mode. + For now, we decide to have this function follow Intel's Table 3-1, + but we may revise that if we manage to resolve these ambiguities. + We also note that Intel's Table 3-1 is consistent with the way in which + 32-bit and 16-bit values are written to general-purpose registers + (even though RIP/EIP/IP is not a general-purpose register); + see @(tsee wr32) and @(tsee wr16). +

+

+ This function should be always called + with an instruction pointer of the right type + (48-bit signed, 32-bit unsigned, or 16-bit unsigned) + based on the mode and code segment. + We may add a guard to ensure that in the future, + but for now in the code below + we coerce the instruction pointer to 32 and 16 bits as appropriate, + to verify guards; + these coercions are expected not to change + the argument instruction pointer. +

" + + :prepwork + ((local + (in-theory (e/d () + (bitops::logand-with-bitmask + bitops::logand-with-negated-bitmask)))) + + (local + (defthm logtail-logbitp-lemma + (equal (logand 1 (logtail n x)) + (bool->bit (logbitp n x))) + :hints (("Goal" :in-theory (e/d* (bitops::ihsext-inductions + bitops::ihsext-recursive-redefs) + ())))))) + + :guard-hints (("Goal" :in-theory (e/d (loghead-to-logand) + (unsigned-byte-p)))) + + (case proc-mode + + (#.*64-bit-mode* + (!rip *ip x86)) + + (#.*compatibility-mode* ;; Maybe *protected-mode* too? + (b* ((cs-attr (the (unsigned-byte 16) (seg-hidden-attri #.*cs* x86))) + (cs.d (code-segment-descriptor-attributesBits->d cs-attr))) + (if (= cs.d 1) + (mbe :logic (!rip (n32 *ip) x86) + :exec (!rip (the (unsigned-byte 32) *ip) x86)) + (b* ((rip (the (signed-byte #.*max-linear-address-size*) + (rip x86))) + ((the (signed-byte #.*max-linear-address-size*) rip-new) + (mbe :logic (part-install (n16 *ip) rip :low 0 :width 16) + :exec (logior (logand #ux-1_0000 rip) + (logand #uxFFFF *ip))))) + (!rip rip-new x86))))) + + (otherwise + ;; Unimplemented for other modes! + x86)) + :inline t + :no-function t + /// + + (defrule write-*ip-when-64-bit-modep + (equal (write-*ip #.*64-bit-mode* *ip x86) + (!rip *ip x86))))) + +;; ====================================================================== + +(defsection stack-pointer-operations + :parents (decoding-and-spec-utils) + :short "Operations to manipulate stack pointers." + + (define select-stack-address-size + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + x86) + :returns (size (member-equal size '(2 4 8))) + :parents (stack-pointer-operations) + :short "Address size of the stack, in bytes." + :long + "

+ This is the @('StackAddrSize') attribute + in Intel manual, June 2026, Vol. 2, Sec. 3.1.1.9, + which is also called @('StackAddressSize') or @('StackSize') + in the pseudocode of some instructions that operate on the stack. +

+

+ In 64-bit mode, the stack address size is always 64 bits. + In 32-bit mode, it is 32 or 16 bits, + based on the SS.B bit, + i.e. the B bit of the current stack segment descriptor. + See Intel manual, Jun 2026, Vol. 1, Sec. 6.2.3 and Sec. 6.2.5, + and AMD manual, Jun'23, Vol. 2, Sec. 2.4.5 and Sec. 4.7.3. + The address-size override prefix does not affect + the stack address size (see @(tsee read-*sp)). +

" + (case proc-mode + (#.*64-bit-mode* 8) + (#.*compatibility-mode* + (b* (((the (unsigned-byte 16) ss-attr) (seg-hidden-attri #.*ss* x86)) + (ss.b (data-segment-descriptor-attributesBits->d/b ss-attr))) + (if (= ss.b 1) 4 2))) + (otherwise + ;; Unimplemented for other modes, + ;; but we return the stack address size of + ;; real-address and virtual-8086 modes (i.e. 16 bits), + ;; to keep the return type of this function simple. + 2)) + :inline t + :no-function t + /// + + (defrule select-stack-address-size-when-64-bit-modep + (equal (select-stack-address-size #.*64-bit-mode* x86) 8)) + + (defrule select-stack-address-size-lower-bound + (<= 2 (select-stack-address-size proc-mode x86)) + :rule-classes :linear) + + (defrule select-stack-address-size-upper-bound + (<= (select-stack-address-size proc-mode x86) 8) + :rule-classes :linear) + + (defrule member-equal-of-select-stack-address-size-1-2-4-8 + (member-equal (select-stack-address-size proc-mode x86) + '(1 2 4 8)))) + + (define read-*sp ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + x86) + :returns (*sp i64p :hyp (x86p x86)) + :parents (stack-pointer-operations) + :short "Read the stack pointer from the register RSP, ESP, or SP." + :long + "

+ In 64-bit mode, a 64-bit stack pointer is read from the full RSP. + Since, in the model, this is a 64-bit signed integer, + this function returns a 64-bit signed integer. +

+

+ In 32-bit mode, a 32-bit or 16-bit stack pointer is read from + ESP (i.e. the low 32 bits of RSP) + or SP (i.e. the low 16 bits of RSP), + based on the SS.B bit, + i.e. the B bit of the current stack segment register. + Either way, this function returns an unsigned 32-bit or 16-bit integer, + which is also a signed 64-bit integer. +

+

+ See Intel manual, Mar'23, Vol. 1, Sec. 6.2.3 and Sec. 6.2.5, + and AMD manual, Jun'23, Vol. 2, Sec 2.4.5 and Sec. 4.7.3. + The actual size of the value returned by this function + is @('StackAddrSize'), + introduced in Intel manual, Dec'23, Vol. 2, Sec. 3.1.1.9. +

+

+ In 32-bit mode, the address-size override prefix (if present) + should not affect the stack address size. + It does not seem to make sense + to change the stack address size on a per-instruction basis. +

" + (b* ((*sp (the (signed-byte 64) (rgfi #.*rsp* x86)))) + (case proc-mode + (#.*64-bit-mode* + *sp) + (#.*compatibility-mode* + (b* (((the (unsigned-byte 16) ss-attr) (seg-hidden-attri #.*ss* x86)) + (ss.b (data-segment-descriptor-attributesBits->d/b ss-attr))) + (if (= ss.b 1) + (n32 *sp) + (n16 *sp)))) + (otherwise + ;; Unimplemented for other modes! + 0))) + :inline t + :no-function t + /// + + (defthm-signed-byte-p read-*sp-is-i64p + :hyp (x86p x86) + :bound 64 + :concl (read-*sp proc-mode x86) + :gen-type t + :gen-linear t) + + (defrule read-*sp-when-64-bit-modep + (equal (read-*sp #.*64-bit-mode* x86) (rgfi *rsp* x86))) + + (defthm-unsigned-byte-p read-*sp-when-not-64-bit-modep + :hyp (not (equal proc-mode #.*64-bit-mode*)) + :bound 32 + :concl (read-*sp proc-mode x86) + :gen-type t + :gen-linear t)) + + (define add-to-*sp ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (*sp :type (signed-byte 64)) + (delta :type (signed-byte 64)) + x86) + :returns (mv flg + (*sp+delta i64p)) + :parents (stack-pointer-operations) + :short "Add a specified amount to a stack pointer." + :long + "

+ The amount may be positive (increment) or negative (decrement). + This just calculates the new stack pointer value, + without storing it into the register RSP, ESP, or SP. + The starting value is the result of @(tsee read-*sp) + or a previous invocation of @(tsee add-to-*sp). +

+

+ The increment or decrement is modular: + 64 bits in 64-bit mode, + and either 32 or 16 bits in 32-bit mode (depending on the SS.B bit). + Since our model uses signed 64-bit addresses, we use @(tsee i64) for them, + while we use @(tsee n32) or @(tsee n16) for 32-bit and 16-bit addresses. +

+

+ In 64-bit mode, we check whether the result is a canonical address; + in 32-bit mode, we check whether the result is within the segment limit. + If these checks are not satisfied, + this function returns an error flag (and 0 as new pointer), + which causes the x86 model to stop execution with an error. + It is not clear whether these checks should be performed + when the stack pointer is updated, + or when the stack is eventually accessed through the updated pointer; + the Intel and AMD manuals seem unclear in this respect. + But since the failure of these checks stops execution with an error, + and it is in a way always ``safe'' to stop execution with an error + (in the sense that the model provides no guarantees when this happens), + for now we choose to perform these checks here. +

+

+ Note that a stack segment may be expand-down or expand-up + (see Intel manual, Mar'17, Vol. 3, Sec. 3.4.5.1), + so the checks need to cover these two cases. + See @(tsee segment-base-and-bounds) and @(tsee ea-to-la). +

" + (b* ((*sp+delta (the (signed-byte 65) (+ *sp delta)))) + (case proc-mode + (#.*64-bit-mode* + (let ((*sp+delta (i64 *sp+delta))) + (if (mbe :logic (canonical-address-p *sp+delta) + :exec (and (<= #.*-2^47* *sp+delta) + (< *sp+delta #.*2^47*))) + (mv nil *sp+delta) + (mv (list :non-canonical-stack-address *sp+delta) 0)))) + (#.*compatibility-mode* + (b* (((the (unsigned-byte 32) ss.limit) + (seg-hidden-limiti #.*ss* x86)) + ((the (unsigned-byte 16) ss-attr) + (seg-hidden-attri #.*ss* x86)) + (ss.b (data-segment-descriptor-attributesBits->d/b ss-attr)) + (ss.e (data-segment-descriptor-attributesBits->e ss-attr)) + (ss-lower (if (= ss.e 1) (1+ ss.limit) 0)) + (ss-upper (if (= ss.e 1) + (if (= ss.b 1) + #xffffffff + #xffff) + ss.limit)) + (*sp+delta (if (= ss.b 1) (n32 *sp+delta) (n16 *sp+delta))) + ((unless (and (<= ss-lower *sp+delta) + (<= *sp+delta ss-upper))) + (mv (list :out-of-segment-stack-address + *sp+delta ss-lower ss-upper) + 0))) + (mv nil *sp+delta))) + (otherwise + (mv (list :unimplemented-proc-mode proc-mode) + 0)))) + :inline t + :no-function t + /// + + (defthm-signed-byte-p add-to-*sp-is-i64p + :bound 48 + :concl (mv-nth 1 (add-to-*sp proc-mode *sp delta x86)) + :gen-type t + :gen-linear t) + + (defrule mv-nth-0-of-add-to-*sp-when-64-bit-modep + (equal (mv-nth 0 (add-to-*sp #.*64-bit-mode* *sp delta x86)) + (if (canonical-address-p (i64 (+ *sp delta))) + nil + (list :non-canonical-stack-address (i64 (+ *sp delta)))))) + + (defrule mv-nth-1-of-add-to-*sp-when-64-bit-modep + (equal (mv-nth 1 (add-to-*sp #.*64-bit-mode* *sp delta x86)) + (if (canonical-address-p (i64 (+ *sp delta))) + (i64 (+ *sp delta)) + 0))) + + (defthm-unsigned-byte-p mv-nth-1-of-add-to-*sp-when-compatibility-modep + :hyp (and (not (equal proc-mode #.*64-bit-mode*)) + (integerp (+ *sp delta)) + (not (mv-nth 0 (add-to-*sp proc-mode *sp delta x86)))) + :bound 32 + :concl (mv-nth 1 (add-to-*sp proc-mode *sp delta x86)) + :hints (("Goal" :in-theory (e/d () (force (force))))) + :gen-linear t + :gen-type t)) + + (define write-*sp ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (*sp :type (signed-byte 64)) + x86) + :returns (x86-new x86p :hyp (x86p x86)) + :parents (stack-pointer-operations) + + :guard (if (equal proc-mode #.*64-bit-mode*) + t + ;; Could strengthen the following, based on ss.d. + (unsigned-byte-p 32 *sp) + ;; (b* (((the (unsigned-byte 16) ss-attr) + ;; (xr :seg-hidden-attr #.*ss* x86)) + ;; (ss.d + ;; (data-segment-descriptor-attributesBits->d/b ss-attr))) + ;; (case ss.d + ;; (0 (unsigned-byte-p 16 *sp)) + ;; (otherwise (unsigned-byte-p 32 *sp)))) + ) + + :short "Write a stack pointer into the register RSP, ESP, or SP." + :long + "

+ In 64-bit mode, a 64-bit stack pointer is written into the full RSP. + Since, in the model, this is a 64-bit signed integer, + this function consumes a 64-bit signed integer. +

+

+ In 32-bit mode, the stack pointer is 32 or 16 bits based on the SS.B bit, + i.e. the B bit of the current stack segment descriptor. + In these cases, the argument to this function should be + a 32-bit or 16-bit unsigned integer, which is also a 64-bit signed integer. +

+

+ See Intel manual, Mar'17, Vol. 1, Sec. 6.2.3 and Sec. 6.2.5, + and AMD manual, Apr'16, Vol. 2, Sec 2.4.5 and Sec. 4.7.3. + The actual size of the value consumed by this function + should be @('StackAddrSize'), + introduced in Intel manual, Mar'17, Vol. 2, Sec. 3.1.1.9. +

+

+ The pseudocode of stack instructions like PUSH + in Intel manual, Mar'17, Vol. 2 + show assignments of the form + @('RSP <- ...'), @('ESP <- ...'), and @('SP <- ...') + based on the stack address size. + This may suggests that + when the stack address size is 32 + the assignment to ESP leaves the high 32 bits of RSP unchanged, + and when the stack address size is 16 + the assignment to SP leaves the high 48 bits of RSP unchanged. + However, + as explained in the documentation of @(tsee wr32) and @(tsee wr16), + normally writing to the low 32 bits of a general-purpose register + (which RSP/ESP/SP is) zeros the high 32 bits, + while writing the low 16 bits leaves the high 48 bits unchanged. + Thus, we follow this requirement also when writing RSP/ESP/SP implicitly, + via stack manipulation instructions like PUSH that use + this @(tsee write-*sp) function to update the stack pointer register. +

+

+ This function should be always called + with a stack pointer of the right type + (64-bit signed, 32-bit unsigned, or 16-bit unsigned) + based on the stack address size. + We may add a guard to ensure that in the future, + but for now in the code below + we coerce the stack pointer to 32 and 16 bits as appropriate, + to verify guards; + these coercions are expected not to change the argument stack pointer. +

" + + :prepwork + ((local + (in-theory (e/d () + (bitops::logand-with-bitmask + bitops::logand-with-negated-bitmask)))) + + (local + (defthm logtail-logbitp-lemma + (equal (logand 1 (logtail n x)) + (bool->bit (logbitp n x))) + :hints (("Goal" :in-theory (e/d* (bitops::ihsext-inductions + bitops::ihsext-recursive-redefs) + ())))))) + + :guard-hints (("Goal" :in-theory (e/d (loghead-to-logand) + (unsigned-byte-p)))) + + (case proc-mode + (#.*64-bit-mode* + (!rgfi #.*rsp* *sp x86)) + (#.*compatibility-mode* + (b* (((the (unsigned-byte 16) ss-attr) (seg-hidden-attri #.*ss* x86)) + (ss.b (data-segment-descriptor-attributesBits->d/b ss-attr))) + (if (= ss.b 1) + (mbe :logic (!rgfi #.*rsp* (n32 *sp) x86) + :exec (!rgfi #.*rsp* (the (unsigned-byte 32) *sp) x86)) + (b* (((the (signed-byte 64) rsp) (rgfi #.*rsp* x86)) + ((the (signed-byte 64) rsp-new) + (mbe :logic (part-install (n16 *sp) rsp :low 0 :width 16) + :exec (logior (logand #ux-1_0000 rsp) + (logand #xFFFF *sp))))) + (!rgfi #.*rsp* rsp-new x86))))) + (otherwise + ;; Unimplemented for other modes! + x86)) + :inline t + :no-function t + /// + + (defrule write-*sp-when-64-bit-modep + (equal (write-*sp #.*64-bit-mode* *sp x86) + (!rgfi #.*rsp* *sp x86))))) + +;; ====================================================================== + +(define select-address-size ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (p4? booleanp) + (x86 x86p)) + :prepwork + ((local (in-theory (e/d () (force (force)))))) + :returns (address-size (member-equal address-size '(2 4 8))) + :inline t + :no-function t + :parents (decoding-and-spec-utils) + :short "Address size of an instruction, in bytes." + :long + "

+ This is based on AMD manual, Dec'17, Volume 3, Table 1-3, + and AMD manual, Dec'17, Volume 2, Sections 4.7 and 4.8. +

+

+ In 64-bit mode, the address size is + 64 bits if there is no address override prefix, + 32 bits if there is an address override prefix. + In 32-bit mode, the address size is + 32 bits if either + (i) the default address size is 32 bits + and there is no address override prefix, or + (ii) the default address size is 16 bits + and there is an eddress override prefix; + otherwise, the address size is 16 bits. + In 32-bit mode, + the default address size is determined by the CS.D bit of the code segment: + 32 bits if CS.D is 1, 16 bits if CS.D is 0. +

+

+ The boolean argument of this function + indicates whether there is an override prefix or not. +

" + (case proc-mode + (#.*64-bit-mode* (if p4? 4 8)) + (otherwise ;; #.*compatibility-mode* or #.*protected-mode* + (b* (((the (unsigned-byte 16) cs-attr) (seg-hidden-attri #.*cs* x86)) + (cs.d (code-segment-descriptor-attributesBits->d cs-attr))) + (if (= cs.d 1) (if p4? 2 4) (if p4? 4 2))))) + /// + + (defrule select-address-size-not-2-when-64-bit-modep + (not (equal 2 (select-address-size #.*64-bit-mode* p4? x86)))) + + (defrule select-address-size-leq-8 + (<= (select-address-size proc-mode p4? x86) 8) + :rule-classes :linear) + + (encapsulate () + (local (include-book "kestrel/arithmetic-light/expt2" :dir :system)) + (defthm signed-byte-p-of-select-address-size + (implies (and (<= 5 size) + (integerp size)) + (signed-byte-p size (select-address-size proc-mode p4? x86))) + :hints (("Goal" :in-theory (enable signed-byte-p)))))) + +;; ====================================================================== + +(defsection effective-address-computations + + :parents (decoding-and-spec-utils) + + :short "Computing effective address using ModR/M, SIB bytes, and + displacement bytes present in the instruction" + + (local (xdoc::set-default-parents effective-address-computations)) + + ;; Alignment checks are only carried out in data (or stack) + ;; accesses, and not in code fetches or system segment accesses. + ;; Since these functions are used during code fetching, we call all + ;; r*me* functions with check-alignment? nil. + + (define x86-effective-addr-from-sib + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (rex-byte :type (unsigned-byte 8) "REX byte") + (mod :type (unsigned-byte 2) "mod field of a ModR/M byte") + (sib :type (unsigned-byte 8) "SIB byte") + x86) + + :guard (sib-p sib) + :guard-hints (("Goal" + :use ((:instance bitops::unsigned-byte-p-incr + (a 3) + (b 4) + (x (sib->base sib)))) + :in-theory (e/d () + (unsigned-byte-p + bitops::unsigned-byte-p-incr)))) + + :short "Calculates effective address when SIB is present." + :long "

Source: Intel Vol. 2A, Table 2-3.

+

Also see Intel Vol. 2A, Table 2-2 and Figure 2-6.

+

In 64-bit mode, + we use @('rgfi') to read bases as signed linear addresses, + which encode canonical linear addresses, + which are also effective addresses in 64-bit mode. + In 32-bit mode, + we use @('rr32') to read bases as unsigned effective addresses.

+

In 64-bit mode, + we use @('rgfi') to read indices as signed 64-bit values. + In 32-bit mode, + we limit them to signed 32-bit values.

+

Note that, in 32-bit mode, + we call this function only when the address size is 32 bits. + When the address size is 16 bits, there is no SIB byte: + See Intel Vol. 2 Table 2-1.

+

The displacement is read as a signed values: + see AMD manual, Dec'17, Volume 3, Section 1.5.

" + + :returns (mv flg + (non-truncated-memory-address + integerp :hyp (and (force (x86p x86)) + (integerp temp-rip)) + :rule-classes :type-prescription) + disp + (increment-RIP-by natp :rule-classes :type-prescription) + (x86 x86p :hyp (force (x86p x86)))) + + :prepwork ((local (in-theory (e/d (rime-size riml-size) + (unsigned-byte-p))))) + + (b* (((the (unsigned-byte 3) b) (sib->base sib)) + (check-alignment? nil) + ((mv flg base displacement nrip-bytes x86) + + (case mod + + (0 (if (equal b 5) + (b* (((mv ?flg0 dword x86) + (rime-size-opt + proc-mode 4 temp-RIP #.*cs* :x check-alignment? x86 + :mem-ptr? nil)) ;; sign-extended + ((when flg0) + (mv (cons flg0 'rime-size-opt-error) 0 0 0 x86))) + (mv nil 0 dword 4 x86)) + (mv nil + (if (equal proc-mode #.*64-bit-mode*) + (rgfi (reg-index b rex-byte #.*b*) x86) + (rr32 b x86)) ; rex-byte is 0 in 32-bit mode + 0 + 0 + x86))) + + (1 (b* (((mv ?flg1 byte x86) + (rime-size-opt proc-mode 1 temp-RIP #.*cs* :x check-alignment? x86 + :mem-ptr? nil)) ;; sign-extended + ((when flg1) + (mv (cons flg1 'rime-size-opt-error) 0 0 0 x86))) + (mv nil + (if (equal proc-mode #.*64-bit-mode*) + (rgfi (reg-index b rex-byte #.*b*) x86) + (rr32 b x86)) ; rex-byte is 0 in 32-bit mode + byte + 1 + x86))) + + (2 (b* (((mv ?flg2 dword x86) + (rime-size-opt proc-mode 4 temp-RIP #.*cs* :x check-alignment? x86 + :mem-ptr? nil)) ;; sign-extended + ((when flg2) + (mv (cons flg2 'rime-size-opt-error) 0 0 0 x86))) + (mv nil + (if (equal proc-mode #.*64-bit-mode*) + (rgfi (reg-index b rex-byte #.*b*) x86) + (rr32 b x86)) ; rex-byte is 0 in 32-bit mode + dword + 4 + x86))) + + (otherwise ;; can't happen: (< mod 3) + (mv 'mod-can-not-be-anything-other-than-0-1-or-2 0 0 0 x86)))) + + (ix ;; use REX-BYTE prefix (cf. Intel Vol. 2, Table 2-4) + (reg-index (sib->index sib) rex-byte #.*x*)) + + (index (case ix ; Intel Vol. 2, Figure 2-6 + (4 0) ; no index register; "none" in Intel Table 2-3 + (otherwise (if (equal proc-mode #.*64-bit-mode*) + (rgfi ix x86) + (i32 (rgfi ix x86)))))) ; 32-bit signed index + + (scale (the (unsigned-byte 2) (sib->scale sib))) + (scaled-index (ash index scale)) + + (effective-addr (+ base scaled-index))) + + (mv flg effective-addr displacement nrip-bytes x86)) + + /// + + (defthm x86-effective-addr-from-sib-returns-integerp-displacement + (implies (x86p x86) + (integerp + (mv-nth 2 (x86-effective-addr-from-sib + proc-mode temp-RIP rex-byte mod sib x86)))) + :rule-classes (:rewrite :type-prescription) + :hints (("Goal" :in-theory (e/d (rime-size riml-size) ())))) + + (defthm x86-effective-addr-from-sib-returns-<=-increment-rip-bytes + (<= (mv-nth 3 (x86-effective-addr-from-sib + proc-mode temp-RIP rex-byte mod sib x86)) + 4) + :hints (("Goal" :in-theory (e/d (rime-size riml-size) ()))) + :rule-classes :linear)) + + (encapsulate + () + (local (include-book "arithmetic-5/top" :dir :system)) + + (defthm logext-loghead-identity + (implies (signed-byte-p n x) + (equal (logext n (loghead n x)) x)) + :hints (("Goal" :in-theory (e/d (logext loghead logapp logbitp) ()))))) + + (define x86-effective-addr-16-disp + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*) ) + (mod :type (unsigned-byte 2) "mod field of ModR/M byte") + x86) + :guard (2bits-p mod) + :returns (mv flg + (disp i16p + :hyp (x86p x86) + :hints (("Goal" :in-theory (enable rime-size)))) + (increment-rip-by natp) + (x86 x86p :hyp (x86p x86))) + :short "Calculate the displacement for + 16-bit effective address calculation." + :long + "

+ This is according to Intel manual, Mar'17, Vol. 2, Table 2-1. +

+

+ The displacement is absent (i.e. 0) when Mod is 00b. + An exception to this is when R/M is 110b, + in which case there is a 16-bit displacement that is added to the index. + This case is not handled by this function, + but is instead handled in + its caller function @(tsee x86-effective-addr-16). +

+

+ The displacement is a signed 8-bit value when Mod is 01b. + The displacement is a signed 16-bit value when Mod is 10b. + This function is not called when Mod is 11b. +

+

+ If an error occurs when trying to read the displacement, + 0 is returned as displacement, + but the caller ignores the returned displacement given the error. +

+

+ This function is called only when the address size is 16 bits. +

" + (case mod + (0 (mv nil 0 0 x86)) + (1 (b* (((mv flg byte x86) + (rime-size-opt proc-mode 1 temp-rip #.*cs* :x nil x86 :mem-ptr? nil)) + ((when flg) (mv flg 0 0 x86))) + (mv nil byte 1 x86))) + (2 (b* (((mv flg word x86) + (rime-size-opt proc-mode 2 temp-rip #.*cs* :x nil x86 :mem-ptr? nil)) + ((when flg) (mv flg 0 0 x86))) + (mv nil word 2 x86))) + (otherwise ; shouldn't happen + (mv 'mod-value-wrong 0 0 x86))) + /// + + (more-returns + (disp integerp + :hyp (x86p x86) + :name integerp-of-x86-effective-addr-16-disp.disp + :rule-classes :type-prescription)) + + (defthm mv-nth-2-x86-effective-addr-16-disp-<=-4 + (<= (mv-nth 2 (x86-effective-addr-16-disp proc-mode temp-RIP mod x86)) + 4) + :rule-classes :linear)) + + (define x86-effective-addr-16 + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*) ) + (r/m :type (unsigned-byte 3) "r/m field of ModR/M byte") + (mod :type (unsigned-byte 2) "mod field of ModR/M byte") + x86) + :guard (and (2bits-p mod) + (3bits-p r/m)) + :returns (mv flg + (address n16p) + (increment-rip-by natp) + (x86 x86p :hyp (x86p x86))) + :short "Effective address calculation with 16-bit addressing." + :long + "

+ This is according to Intel manual, Mar'17, Vol. 2, Table 2-1. +

+

+ We assume that the additions in the table are modular, + even though the documentation is not clear in that respect. + So we simply apply @('n16') to the exact integer result. + This is in analogy to the use of @('n32') + for effective address calculation in 64-bit mode + when there is an address size override prefix: + see @(tsee x86-effective-addr-32/64). +

" + (case r/m + (0 (b* ((bx (rr16 #.*rbx* x86)) + (si (rr16 #.*rsi* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ bx si disp)) increment-rip-by x86))) + (1 (b* ((bx (rr16 #.*rbx* x86)) + (di (rr16 #.*rdi* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ bx di disp)) increment-rip-by x86))) + (2 (b* ((bp (rr16 #.*rbp* x86)) + (si (rr16 #.*rsi* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ bp si disp)) increment-rip-by x86))) + (3 (b* ((bp (rr16 #.*rbp* x86)) + (di (rr16 #.*rdi* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ bp di disp)) increment-rip-by x86))) + (4 (b* ((si (rr16 #.*rsi* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ si disp)) increment-rip-by x86))) + (5 (b* ((di (rr16 #.*rdi* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ di disp)) increment-rip-by x86))) + (6 (case mod + (0 (b* (((mv flg disp x86) + (rime-size-opt proc-mode 2 temp-rip #.*cs* :x nil x86 + :mem-ptr? nil)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 disp) 2 x86))) + (otherwise (b* ((bp (rr16 #.*rbp* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp + proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ bp disp)) increment-rip-by x86))))) + (7 (b* ((bx (rr16 #.*rbx* x86)) + ((mv flg disp increment-rip-by x86) + (x86-effective-addr-16-disp proc-mode temp-rip mod x86)) + ((when flg) (mv flg 0 0 x86))) + (mv nil (n16 (+ bx disp)) increment-rip-by x86))) + (otherwise ; shouldn't happen + (mv :r/m-out-of-range 0 0 x86))) + /// + + (defthm-signed-byte-p i64p-mv-nth-1-x86-effective-addr-16 + :hyp t + :bound 64 + :concl (mv-nth 1 (x86-effective-addr-16 proc-mode temp-RIP r/m mod x86)) + :gen-linear t + :gen-type t) + + (defthm natp-mv-nth-2-x86-effective-addr-16 + (natp (mv-nth 2 (x86-effective-addr-16 proc-mode temp-RIP r/m mod x86))) + :rule-classes :type-prescription) + + (defthm mv-nth-2-x86-effective-addr-16-<=-4 + (<= (mv-nth 2 (x86-effective-addr-16 proc-mode temp-RIP r/m mod x86)) + 4) + :rule-classes :linear)) + + (define x86-effective-addr-32/64 + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + p4 + (temp-RIP :type (signed-byte #.*max-linear-address-size*) ) + (rex-byte :type (unsigned-byte 8) "Rex byte") + (r/m :type (unsigned-byte 3) "r/m field of ModR/M byte") + (mod :type (unsigned-byte 2) "mod field of ModR/M byte") + (sib :type (unsigned-byte 8) "Sib byte") + ;; num-imm-bytes is needed for computing the next RIP when + ;; RIP-relative addressing is done. Note that this argument is + ;; only relevant when the operand addressing mode is I, i.e., + ;; when the operand value is encoded in subsequent bytes of the + ;; instruction. For details, see *Z-addressing-method-info* in + ;; x86isa/utils/decoding-utilities.lisp. + (num-imm-bytes :type (unsigned-byte 3) + "Number of immediate bytes (0, 1, 2, or 4) + that follow the sib (or displacement bytes, if any).") + x86) + + :guard (and (2bits-p mod) + (3bits-p r/m) + (sib-p sib)) + :guard-hints (("Goal" :in-theory (e/d (n64-to-i64 rime-size) ()))) + + ;; Returns the flag, the effective address (taking the SIB and + ;; ModR/M bytes into account) and the number of bytes to increment + ;; the temp-RIP by. + :returns (mv + flg + i64p-memory-address + increment-RIP-by + (x86 x86p :hyp (force (x86p x86)))) + + :short "Effective address calculation with 32-bit and 64-bit addressing." + + :long "

Note that we do not add segment bases + (such as the FS and GS bases, if FS and GS overrides are present) + to the effective address computed in this function. + Addition of those segment base addresses is a part of the + segmentation process --- we handle that in the function @(see + ea-to-la) that performs the segment address translation.

+ +

Quoting from Intel Vol 1, Sec 3.3.7:

+ +

In 64-bit mode, the effective address components are + added and the effective address is truncated (See for example + the instruction LEA) before adding the full 64-bit segment + base. The base is never truncated, regardless of addressing + mode in 64-bit mode.

+ +

Quoting Intel Vol. 1 Sec. 3.3.7 (Address Calculations in + 64-Bit Mode):

+ +

All 16-bit and 32-bit address calculations are + zero-extended in IA-32e mode to form 64-bit addresses. Address + calculations are first truncated to the effective address size + of the current mode (64-bit mode or compatibility mode), as + overridden by any address-size prefix. The result is then + zero-extended to the full 64-bit address width. Because of + this, 16-bit and 32-bit applications running in compatibility + mode can access only the low 4 GBytes of the 64-bit mode + effective addresses. Likewise, a 32-bit address generated in + 64-bit mode can access only the low 4 GBytes of the 64-bit + mode effective addresses.

+ +

Also: Intel Vol 1, Section 3.3.7 says that we need + sign-extended displacements in effective address calculations. In + Lisp, sign-extension is implicit.

+ +

In 64-bit mode, instructions such as LEA use this function to + compute the effective address. LEA, at least, does not check + whether the generated address is canonical or not, which is why we + don't make the canonical-address-p check in this function.

+ +

In 64-bit mode, + we use @('rgfi-size') to read bases as signed linear addresses, + which encode canonical linear addresses, + which are also effective addresses in 64-bit mode. + In 32-bit mode, + we use @('rr32') to read bases as unsigned effective addresses.

" + + (b* (((mv flg addr displacement increment-RIP-by x86) + + (case mod + + (0 + (case r/m + (4 + ;; Returns + ;; (mv flg non-truncated-memory-address 0 increment-RIP-by x86) + (x86-effective-addr-from-sib + proc-mode temp-RIP rex-byte mod sib x86)) + (5 + (if (equal proc-mode #.*64-bit-mode*) + ;; RIP-relative addressing in 64-bit mode: + (b* (((mv ?flg0 dword x86) + ;; dword is the sign-extended displacement + ;; present in the instruction. + (rime-size-opt + #.*64-bit-mode* 4 temp-RIP #.*cs* :x nil x86 + :mem-ptr? nil)) + ;; next-rip is the rip of the next instruction. + ;; temp-RIP + 4 bytes of the displacement + ;; mentioned above + bytes of rest of the + ;; instruction (immediate bytes) + ((mv flg next-rip) + (add-to-*ip #.*64-bit-mode* temp-RIP + (+ 4 num-imm-bytes) + x86)) + ((when flg) (mv flg 0 0 0 x86))) + (mv flg0 next-rip dword 4 x86)) + ;; displacement only in 32-bit mode: + (b* (((mv flg dword x86) + ;; dword is the sign-extended displacement + ;; present in the instruction. + (rime-size-opt + proc-mode 4 temp-RIP #.*cs* :x nil x86 :mem-ptr? nil)) + ((when flg) (mv flg 0 0 0 x86))) + (mv nil 0 dword 4 x86)))) + + (otherwise + (mv nil + (if (equal proc-mode #.*64-bit-mode*) + (rgfi (reg-index r/m rex-byte #.*b*) x86) + (rr32 r/m x86)) ; rex-byte is 0 in 32-bit mode + 0 + 0 + x86)))) + + (1 + (case r/m + (4 + ;; Returns + ;; (mv flg non-truncated-memory-address 0 increment-RIP-by x86) + (x86-effective-addr-from-sib + proc-mode temp-RIP rex-byte mod sib x86)) + + (otherwise + (b* (((mv ?flg2 byte2 x86) + (rime-size-opt proc-mode 1 temp-RIP #.*cs* :x nil x86 + :mem-ptr? nil)) ; sign-extended + (reg (if (equal proc-mode #.*64-bit-mode*) + (rgfi (reg-index r/m rex-byte #.*b*) x86) + (rr32 r/m x86)))) ; rex-byte is 0 in 32-bit mode + (mv flg2 reg byte2 1 x86))))) + + (2 + (case r/m + (4 + ;; Returns + ;; (mv flg non-truncated-memory-address 0 increment-RIP-by x86) + (x86-effective-addr-from-sib + proc-mode temp-RIP rex-byte mod sib x86)) + + (otherwise + (b* (((mv ?flg1 dword x86) + (rime-size-opt proc-mode 4 temp-RIP #.*cs* :x nil x86 + :mem-ptr? nil)) ; sign-extended + (reg (if (equal proc-mode #.*64-bit-mode*) + (rgfi (reg-index r/m rex-byte #.*b*) x86) + (rr32 r/m x86)))) ; rex-byte is 0 in 32-bit mode + (mv flg1 reg dword 4 x86))))) + + (otherwise ; shouldn't happen + (mv 'mod-value-wrong 0 0 0 x86)))) + + (dst-base (+ addr displacement)) + + ;; In 64-bit mode, if #x67 (address-override prefix) is + ;; present, the effective address size is 32 bits, else it is + ;; 64 bits. Note that our current virtual memory functions can + ;; cause an error if the address we are reading from/writing to + ;; is >= 2^47-8. + ;; In 32-bit mode, + ;; this function we are in is called when the address size is 32 bits + ;; (X86-EFFECTIVE-ADDR-16 is called when the address size is 16 bits), + ;; so the following code always returns + ;; a 32-bit address in 32-bit mode. + (dst-base (if (equal proc-mode #.*64-bit-mode*) + (if p4 + (n32 dst-base) + (n64-to-i64 (n64 dst-base))) + (n32 dst-base)))) + + (mv flg dst-base increment-RIP-by x86)) + + /// + + (local (in-theory (e/d () (force (force))))) + + + (defthm-signed-byte-p i64p-mv-nth-1-x86-effective-addr-32/64 + :hyp t + :bound 64 + :concl (mv-nth 1 (x86-effective-addr-32/64 + proc-mode p4 temp-RIP rex-byte r/m mod sib + num-imm-bytes x86)) + :gen-linear t + :gen-type t) + + (defthm natp-mv-nth-2-x86-effective-addr-32/64 + (natp (mv-nth 2 (x86-effective-addr-32/64 + proc-mode p4 temp-RIP rex-byte r/m mod sib + num-imm-bytes x86))) + :rule-classes :type-prescription) + + (defthm mv-nth-2-x86-effective-addr-32/64-<=-4 + (<= (mv-nth 2 (x86-effective-addr-32/64 + proc-mode p4 temp-RIP rex-byte r/m mod sib + num-imm-bytes x86)) + 4) + :rule-classes :linear)) + + (define x86-effective-addr + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + p4 + (temp-RIP :type (signed-byte #.*max-linear-address-size*) ) + (rex-byte :type (unsigned-byte 8) "Rex byte") + (r/m :type (unsigned-byte 3) "r/m field of ModR/M byte") + (mod :type (unsigned-byte 2) "mod field of ModR/M byte") + (sib :type (unsigned-byte 8) "Sib byte") + ;; num-imm-bytes is needed for computing the next RIP when + ;; RIP-relative addressing is done. Note that this argument is + ;; only relevant when the operand addressing mode is I, i.e., + ;; when the operand value is encoded in subsequent bytes of the + ;; instruction. For details, see *Z-addressing-method-info* in + ;; x86isa/utils/decoding-utilities.lisp. + (num-imm-bytes :type (unsigned-byte 3) + "Number of immediate bytes (0, 1, 2, or 4) + that follow the sib (or displacement bytes, if any).") + x86) + + + :guard (and (2bits-p mod) + (3bits-p r/m) + (sib-p sib)) + + ;; Returns the flag, the effective address (taking the SIB and + ;; ModR/M bytes into account) and the number of bytes to increment + ;; the temp-RIP by. + :returns (mv + flg + i64p-memory-address + increment-RIP-by + (x86 x86p :hyp (force (x86p x86)))) + + :short "Effective address calculation." + + :long + "

+ This is a wrapper that calls + @(tsee x86-effective-addr-16) or @(tsee x86-effective-addr-32/64) + based on the address size. +

" + + (if (eql 2 (select-address-size proc-mode (if p4 t nil) x86)) + (x86-effective-addr-16 proc-mode temp-rip r/m mod x86) + (x86-effective-addr-32/64 + proc-mode p4 temp-rip rex-byte r/m mod sib num-imm-bytes x86)) + + /// + + (defthm-signed-byte-p i64p-mv-nth-1-x86-effective-addr + :hyp t + :bound 64 + :concl (mv-nth 1 (x86-effective-addr + proc-mode p4 temp-RIP rex-byte r/m mod sib + num-imm-bytes x86)) + :gen-linear t + :gen-type t) + + (defthm natp-mv-nth-2-x86-effective-addr + (natp (mv-nth 2 (x86-effective-addr + proc-mode p4 temp-RIP rex-byte r/m mod sib + num-imm-bytes x86))) + :rule-classes :type-prescription) + + (defthm mv-nth-2-x86-effective-addr-<=-4 + (<= (mv-nth 2 (x86-effective-addr + proc-mode p4 temp-RIP rex-byte r/m mod sib + num-imm-bytes x86)) + 4) + :rule-classes :linear) + + (defthm signed-byte-p-of-mv-nth-2-of-x86-effective-addr + (implies (and (<= 48 size) + (integerp size)) + (signed-byte-p size (mv-nth 2 (x86-effective-addr + proc-mode p4 temp-RIP rex-byte r/m mod sib + num-imm-bytes x86)))) + :hints (("Goal" :in-theory (disable x86-effective-addr)))) + + (defruled x86-effective-addr-when-64-bit-modep + (equal (x86-effective-addr + #.*64-bit-mode* + p4 temp-rip rex-byte r/m mod sib num-imm-bytes x86) + (x86-effective-addr-32/64 + #.*64-bit-mode* + p4 temp-rip rex-byte r/m mod sib num-imm-bytes x86))))) + +;; ====================================================================== + +(local + (defthm-unsigned-byte-p usb-80-of-16-and-64 + :hyp (and (unsigned-byte-p 16 n16) + (unsigned-byte-p 64 n64)) + :bound 80 + :concl (logior n16 (ash n64 16)) + :gen-type t + :gen-linear t)) + +(local + (defthm-unsigned-byte-p usb-48-of-16-and-32 + :hyp (and (unsigned-byte-p 16 n16) + (unsigned-byte-p 32 n32)) + :bound 48 + :concl (logior n16 (ash n32 16)) + :gen-type t + :gen-linear t)) + +(defsection read-operands-and-write-results + + :parents (decoding-and-spec-utils) + + :short "Functions to fetch and read operands from an instruction, + and to write results to appropriate registers/memory locations, + based on ModR/M, SIB, immediate, and/or displacement bytes." + + (local (xdoc::set-default-parents read-operands-and-write-results)) + + (define alignment-checking-enabled-p (x86) + :prepwork ((local (in-theory (e/d* () ())))) + :returns (enabled booleanp :rule-classes :type-prescription) + :short "Checking if alignment is enabled" + :long "

Source: Intel Manuals, Volume 3, Section 6.15, Exception + and Interrupt Reference:

+ +

Interrupt 17 Alignment Check Exception (#AC)

+ +
Exception Class: Fault.
+ +
Description: Indicates that the processor detected an + unaligned memory operand when alignment checking was + enabled. Alignment checks are only carried out in data (or stack) + accesses (not in code fetches or system segment accesses). An example + of an alignment-check violation is a word stored at an odd byte + address, or a doubleword stored at an address that is not an integer + multiple of 4.
+ +
Note that the alignment check exception (#AC) is + generated only for data types that must be aligned on word, + doubleword, and quadword boundaries. A general-protection + exception (#GP) is generated 128-bit data types that are not aligned + on a 16-byte boundary.
+ +
To enable alignment checking, the following conditions + must be true:
+
    +
  • AM flag in CR0 register is set.
  • +
  • AC flag in the EFLAGS register is set.
  • +
  • The CPL is 3 (protected mode or virtual-8086 mode).
  • +
+ +
Alignment-check exceptions (#AC) are generated only when +operating at privilege level 3 (user mode). Memory references that +default to privilege level 0, such as segment descriptor loads, do not +generate alignment-check exceptions, even when caused by a memory +reference made from privilege level 3.
" + + (b* ((cr0 (the (unsigned-byte 32) (n32 (ctri #.*cr0* x86)))) + (AM (cr0Bits->am cr0)) + (AC (flgi :ac x86)) + (CPL (cpl x86))) + (and (equal AM 1) + (equal AC 1) + (equal CPL 3))) + + /// + + (defthm alignment-checking-enabled-p-and-xw + (implies (and (not (equal fld :ctr)) + (not (equal fld :seg-visible)) + (not (equal fld :rflags))) + (equal (alignment-checking-enabled-p (xw fld index val x86)) + (alignment-checking-enabled-p x86)))) + + (defthm alignment-checking-enabled-p-and-xw-ctr + (implies (case-split (or (not (equal (nfix index) *cr0*)) + (and (equal (nfix index) *cr0*) + (equal (cr0Bits->am (loghead 32 val)) + (cr0Bits->am (xr :ctr *cr0* x86)))))) + (equal (alignment-checking-enabled-p (xw :ctr index val x86)) + (alignment-checking-enabled-p x86))) + :hints (("Goal" :in-theory (e/d (cr0bits->am cr0bits-fix) + ())))) + + (defthm alignment-checking-enabled-p-and-xw-rflags + (implies (equal (rflagsBits->ac val) + (rflagsBits->ac (xr :rflags nil x86))) + (equal (alignment-checking-enabled-p (xw :rflags nil val x86)) + (alignment-checking-enabled-p x86))) + :hints (("Goal" :in-theory (e/d (rflagsBits->ac rflagsBits-fix) ())))) + + (defthm alignment-checking-enabled-p-and-xw-seg-visible + (implies (case-split + (or (not (equal index #.*cs*)) + (and (equal index #.*cs*) + (equal (segment-selectorBits->rpl val) + (segment-selectorBits->rpl + (seg-visiblei #.*cs* x86)))))) + (equal (alignment-checking-enabled-p (xw :seg-visible index val x86)) + (alignment-checking-enabled-p x86))) + :hints (("Goal" :in-theory (e/d (segment-selectorbits->rpl segment-selectorbits-fix) + ())))) + + (defthm alignment-checking-enabled-p-and-mv-nth-1-wb + (equal (alignment-checking-enabled-p (mv-nth 1 (wb n addr w val x86))) + (alignment-checking-enabled-p x86)) + :hints (("Goal" :in-theory (e/d* (wb write-to-physical-memory) ())))) + + (defthm alignment-checking-enabled-p-and-mv-nth-2-rb + (equal (alignment-checking-enabled-p (mv-nth 2 (rb n addr r-x x86))) + (alignment-checking-enabled-p x86)) + :hints (("Goal" :in-theory (e/d* (rb) ())))) + + (defthm alignment-checking-enabled-p-and-mv-nth-2-las-to-pas + (equal (alignment-checking-enabled-p + (mv-nth 2 (las-to-pas n lin-addr r-w-x x86))) + (alignment-checking-enabled-p x86)))) + + (define x86-operand-from-modr/m-and-sib-bytes + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (reg-type :type (member #.*gpr-access* + #.*xmm-access* + #.*vex-xmm-access* + #.*ymm-access* + #.*mmx-access*) + "@('reg-type') is @('*gpr-access*') for GPRs, + @('*xmm-access*') for XMMs (non-VEX-encoded), + @('*vex-xmm-access*') for XMMs (VEX-encoded), + @('*ymm-access*') for YMMs, and + @('*mmx-access*) or MMXs. + (@('*zmm-access*'), for ZMMs, is not yet supported.") + (operand-size :type (member 1 2 4 6 8 10 16 32)) + (inst-ac? booleanp + "@('t') if instruction does alignment checking, + @('nil') otherwise.") + (memory-ptr? booleanp + "@('t') if the operand is a memory operand of the + form m16:16, m16:32, or m16:64") + (seg-reg (integer-range-p 0 *segment-register-names-len* seg-reg) + "Register of the segment to read the operand from + (when reading the operand from memory).") + (p4? :type (or t nil) + "Address-Size Override Prefix Present?") + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (rex-byte :type (unsigned-byte 8)) + (r/m :type (unsigned-byte 3)) + (mod :type (unsigned-byte 2)) + (sib :type (unsigned-byte 8)) + (num-imm-bytes :type (unsigned-byte 3)) + x86) + + :guard (if (equal mod #b11) + (case reg-type + (#.*gpr-access* (member operand-size '(1 2 4 8))) + (#.*xmm-access* (member operand-size '(4 8 16))) + (#.*vex-xmm-access* (member operand-size '(4 8 16))) + (#.*ymm-access* (member operand-size '(4 8 16 32))) + (#.*mmx-access* (equal operand-size 8)) + (t t)) + (member operand-size '(1 2 4 6 8 10 16 32))) + + ;; [Shilpi] enabled segment-base-and-bounds for rme-size-opt. + :guard-hints (("Goal" :in-theory (e/d* (segment-base-and-bounds) + (las-to-pas + unsigned-byte-p + signed-byte-p)))) + + :returns + (mv flg + (operand natp :rule-classes :type-prescription) + increment-RIP-by + addr + (x86 x86p :hyp (force (x86p x86)))) + + :short "Read an operand from memory or a register." + + :long + "

+ Based on the ModR/M byte, + the operand is read from either a register or memory. + In the latter case, we calculate the effective address + and then we read the operand from it. + Besides returning the operand, + we also return the calculated effective address. + This is useful for instructions that modify the operand after reading it + (e.g. the source/destination operand of ADD), + which pass the effective address calculated by this function + to @(tsee x86-operand-to-reg/mem) (which writes the result to memory). +

" + + (b* (((mv ?flg0 + (the (signed-byte 64) addr) + (the (integer 0 4) increment-RIP-by) + x86) + (if (equal mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr + proc-mode p4? temp-rip rex-byte r/m mod sib num-imm-bytes x86))) + ((when flg0) + (mv (cons 'x86-effective-addr-error flg0) 0 0 0 x86)) + ((mv ?flg2 operand x86) + (if (equal mod #b11) + (case reg-type + (#.*gpr-access* + (mv nil + (rgfi-size operand-size + (reg-index r/m rex-byte #.*b*) + rex-byte + x86) + x86)) + (#.*mmx-access* + (mv nil + (mmx r/m x86) ; only MM0-MM7 exist + x86)) + (#.*xmm-access* + (mv nil + (xmmi-size operand-size + (reg-index r/m rex-byte #.*b*) + x86) + x86)) + (t + (mv nil + (zmmi-size operand-size + (reg-index r/m rex-byte #.*b*) + x86) + x86))) + (b* ((check-alignment? (and inst-ac? + (alignment-checking-enabled-p x86)))) + ;; The operand is being fetched from the memory, not the + ;; instruction stream. That's why we have :r instead of :x + ;; below. + (rme-size-opt + proc-mode operand-size addr seg-reg :r check-alignment? x86 + :mem-ptr? memory-ptr? + :check-canonicity t)))) + ((when flg2) + (mv (cons 'Rm-Size-Error flg2) 0 0 0 x86))) + + (mv nil operand increment-RIP-by addr x86)) + + /// + + (defthm-unsigned-byte-p bound-of-mv-nth-1-x86-operand-from-modr/m-and-sib-bytes-operand + :hyp (and (equal bound (ash operand-size 3)) + (member operand-size '(1 2 4 8 16 32)) + (or (not (equal reg-type #.*mmx-access*)) + (equal operand-size 8)) + (x86p x86)) + :bound bound + :concl (mv-nth 1 (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type operand-size inst-ac? memory-ptr? + seg-reg p4? temp-RIP rex-byte r/m mod sib num-imm-bytes + x86)) + :gen-linear t + :gen-type t + :hints (("Goal" :in-theory (e/d (rme-size) ())))) + + (defthm-unsigned-byte-p bigger-bound-of-mv-nth-1-x86-operand-from-modr/m-and-sib-bytes-operand + :hyp (and (<= (ash operand-size 3) bound) + (member operand-size '(1 2 4 8 16 32)) + (or (not (equal reg-type #.*mmx-access*)) + (equal operand-size 8)) + (integerp bound) + (x86p x86)) + :bound bound + :concl (mv-nth 1 (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type operand-size inst-ac? memory-ptr? + seg-reg p4? temp-RIP rex-byte r/m mod sib num-imm-bytes + x86)) + :hints (("Goal" :in-theory (e/d () + (x86-operand-from-modr/m-and-sib-bytes + unsigned-byte-p))))) + + (in-theory + (disable + bigger-bound-of-mv-nth-1-x86-operand-from-modr/m-and-sib-bytes-operand)) + + (defthm-unsigned-byte-p bound-of-mv-nth-1-x86-operand-from-modr/m-and-sib-bytes-operand-6-and-10-bytes-read + :hyp (and (equal bound (ash operand-size 3)) + (member operand-size '(6 10)) + (not (equal mod #b11)) + (x86p x86)) + :bound bound + :concl (mv-nth 1 (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type operand-size inst-ac? memory-ptr? + seg-reg p4? temp-RIP rex-byte r/m mod sib num-imm-bytes + x86)) + :gen-linear t + :gen-type t + :hints (("Goal" :in-theory (enable rme-size)))) + + (defthm integerp-x86-operand-from-modr/m-and-sib-bytes-increment-RIP-by-type-prescription + (implies (force (x86p x86)) + (natp (mv-nth + 2 + (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type + operand-size inst-ac? memory-ptr? seg-reg p4 temp-RIP + rex-byte r/m mod sib num-imm-bytes x86)))) + :hints (("Goal" :in-theory (e/d (rml-size) ()))) + :rule-classes :type-prescription) + + (defthm mv-nth-2-x86-operand-from-modr/m-and-sib-bytes-increment-RIP-by-linear<=4 + (implies (x86p x86) + (<= (mv-nth + 2 + (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type operand-size inst-ac? memory-ptr? + seg-reg p4 temp-RIP rex-byte r/m mod sib num-imm-bytes x86)) + 4)) + :hints (("Goal" :in-theory (e/d (rml-size) ()))) + :rule-classes :linear) + + (defthm-signed-byte-p i48p-x86-operand-from-modr/m-and-sib-bytes + ;; For guard proofs obligations originating from calls to add-to-*ip: + :hyp (forced-and (x86p x86)) + :bound 48 + :concl (mv-nth 2 (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type operand-size inst-ac? memory-ptr? + seg-reg p4 temp-rip rex-byte r/m mod sib num-imm-bytes x86)) + :hints (("Goal" :in-theory (e/d (signed-byte-p) ()))) + :gen-linear t + :gen-type t) + + (defthm-signed-byte-p i64p-x86-operand-from-modr/m-and-sib-bytes + :hyp (forced-and (x86p x86)) + :bound 64 + :concl (mv-nth 3 (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type operand-size inst-ac? memory-ptr? + seg-reg p4 temp-rip rex-byte r/m mod sib num-imm-bytes x86)) + :gen-linear t + :gen-type t)) + + (define x86-operand-to-reg/mem + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (operand-size :type (member 1 2 4 6 8 10 16)) + (inst-ac? booleanp + "@('t') if instruction does alignment checking, + @('nil') otherwise") + (memory-ptr? booleanp + "@('t') if the operand is a memory operand + of the form m16:16, m16:32, or m16:64") + (operand :type (integer 0 *)) + (seg-reg (integer-range-p 0 *segment-register-names-len* seg-reg) + "Register of the segment to read the operand from + (when reading the operand from memory).") + (addr :type (signed-byte 64)) + (rex-byte :type (unsigned-byte 8)) + (r/m :type (unsigned-byte 3)) + (mod :type (unsigned-byte 2)) + x86) + + :short "Write an operand to memory or a general-purpose register." + + :long + "

+ Based on the ModR/M byte, + the operand is written to either a register or memory. + The address argument of this function is often + the effective address calculated and returned by + @(tsee x86-operand-from-modr/m-and-sib-bytes). +

" + + :guard (and (unsigned-byte-p (ash operand-size 3) operand) + (if (equal mod #b11) + (member operand-size '(1 2 4 8)) + (member operand-size '(1 2 4 6 8 10 16)))) + + (b* (((when (equal mod #b11)) + (let* ((x86 (!rgfi-size operand-size (reg-index r/m rex-byte #.*b*) + operand rex-byte x86))) + (mv nil x86))) + + (check-alignment? (and inst-ac? (alignment-checking-enabled-p x86))) + ((mv flg x86) + (wme-size + proc-mode operand-size addr seg-reg operand check-alignment? x86 + :mem-ptr? memory-ptr?))) + (mv flg x86)) + + /// + + (defthm x86p-x86-operand-to-reg/mem + (implies (force (x86p x86)) + (x86p + (mv-nth + 1 + (x86-operand-to-reg/mem + proc-mode operand-size inst-ac? + memory-ptr? operand addr seg-reg rex-byte r/m mod x86)))) + :hints (("Goal" :in-theory (e/d () (force (force))))))) + + (define x86-operand-to-mmx/mem + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (inst-ac? booleanp + "@('t') if instruction does alignment checking, + @('nil') otherwise") + (operand :type (unsigned-byte 64)) + (seg-reg (integer-range-p 0 *segment-register-names-len* seg-reg) + "Register of the segment to read the operand from + (when reading the operand from memory).") + (addr :type (signed-byte 64)) + (r/m :type (unsigned-byte 3)) + (mod :type (unsigned-byte 2)) + x86) + + :short "Write an operand to memory or an MMX register." + + :long + "

+ Based on the ModR/M byte, + the operand is written to either a register or memory. + The address argument of this function is often + the effective address calculated and returned by + @(tsee x86-operand-from-modr/m-and-sib-bytes). +

+

+ After writing an MMX register, we update floating-point status: + see @(see mmx-registers-reads-and-writes). +

" + + (b* (((when (equal mod #b11)) + (let* ((x86 (!mmx r/m operand x86)) + (x86 (mmx-instruction-updates x86))) + (mv nil x86))) + + (check-alignment? (and inst-ac? (alignment-checking-enabled-p x86))) + + ((mv flg x86) + (wme-size proc-mode + 8 + addr + seg-reg + operand + check-alignment? + x86 + :mem-ptr? nil))) ; operand is never a memory pointer here + (mv flg x86)) + + /// + + (defthm x86p-x86-operand-to-mmx/mem + (implies (force (x86p x86)) + (x86p (mv-nth 1 (x86-operand-to-mmx/mem proc-mode + inst-ac? + operand + seg-reg + addr + r/m + mod + x86)))) + :hints (("Goal" :in-theory (e/d () (force (force))))))) + + (define x86-operand-to-xmm/mem + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (operand-size :type (member 4 8 16)) + (inst-ac? booleanp + "@('t') if instruction does alignment checking, + @('nil') otherwise") + (operand :type (integer 0 *)) + (seg-reg (integer-range-p 0 *segment-register-names-len* seg-reg) + "Register of the segment to read the operand from + (when reading the operand from memory).") + (addr :type (signed-byte 64)) + (rex-byte :type (unsigned-byte 8)) + (r/m :type (unsigned-byte 3)) + (mod :type (unsigned-byte 2)) + x86) + + :short "Write an operand to memory or an XMM register." + + :long + "

+ Based on the ModR/M byte, + the operand is written to either a register or memory. + The address argument of this function is often + the effective address calculated and returned by + @(tsee x86-operand-from-modr/m-and-sib-bytes). +

+

+ The writing to an XMM register is for a non-VEX-encoded instruction. +

" + + :guard (unsigned-byte-p (ash operand-size 3) operand) + + (b* (((when (equal mod #b11)) + (let* ((x86 (!xmmi-size operand-size (reg-index r/m rex-byte #.*b*) + operand x86))) + (mv nil x86))) + + (check-alignment? (and inst-ac? (alignment-checking-enabled-p x86))) + + ((mv flg x86) + ;; operand is never an m16:16 memory pointer here + (wme-size proc-mode operand-size addr seg-reg operand + check-alignment? x86 :mem-ptr? nil))) + (mv flg x86)) + + /// + + (defthm x86p-x86-operand-to-xmm/mem + (implies (force (x86p x86)) + (x86p + (mv-nth + 1 + (x86-operand-to-xmm/mem + proc-mode operand-size inst-ac? operand + seg-reg addr rex-byte r/m mod x86)))) + :hints (("Goal" :in-theory (e/d () (force (force))))))) + + (define x86-operand-to-zmm/mem + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (reg-type :type (member #.*vex-xmm-access* + #.*ymm-access* + #.*zmm-access*)) + (operand-size :type (member 4 8 16 32)) + (inst-ac? booleanp + "@('t') if instruction does alignment checking, + @('nil') otherwise") + (operand :type (integer 0 *)) + (seg-reg (integer-range-p 0 *segment-register-names-len* seg-reg) + "Register of the segment to read the operand from + (when reading the operand from memory).") + (addr :type (signed-byte 64)) + (rex-byte :type (unsigned-byte 8)) + (r/m :type (unsigned-byte 3)) + (mod :type (unsigned-byte 2)) + x86) + + :guard (and (unsigned-byte-p (ash operand-size 3) operand) + (if (equal mod #b11) + (case reg-type + (#.*vex-xmm-access* (member operand-size '(4 8 16))) + (#.*ymm-access* (member operand-size '(4 8 16 32))) + (t t)) + (member operand-size '(4 8 16 32)))) + + :short "Write an operand to memory or a ZMM register." + + :long + "

+ Based on the ModR/M byte, + the operand is written to either a register or memory. + The address argument of this function is often + the effective address calculated and returned by + @(tsee x86-operand-from-modr/m-and-sib-bytes). +

+

+ This covers writing to ZMM or YMM or XMM registers, + the latter for VEX instructions. + The 512-bit (i.e. 64-byte) writes are not supported yet, + because we first need to add appropriate memory writing functions. +

" + + (b* (((when (equal mod #b11)) + (let* ((x86 (!zmmi-size operand-size (reg-index r/m rex-byte #.*b*) + operand x86 :regtype reg-type))) + (mv nil x86))) + + (check-alignment? (and inst-ac? (alignment-checking-enabled-p x86))) + + ((mv flg x86) + ;; operand is never an m16:16 memory pointer here + (wme-size proc-mode operand-size addr seg-reg operand + check-alignment? x86 :mem-ptr? nil))) + (mv flg x86)) + + /// + + (defthm x86p-x86-operand-to-zmm/mem + (implies (force (x86p x86)) + (x86p + (mv-nth + 1 + (x86-operand-to-zmm/mem + proc-mode reg-type operand-size inst-ac? operand + seg-reg addr rex-byte r/m mod x86)))) + :hints (("Goal" :in-theory (e/d () (force (force)))))))) + +;; ====================================================================== + +(define rip-guard-okp + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (rip :type (signed-byte #.*max-linear-address-size*))) + :short "Size constraints on a memory address of some instruction byte" + + :long "

This function specifies the maximum size of a memory address that + points to some instruction byte in a certain mode of operation. We usually + use this function to specify the guard on @('start-rip') or @('temp-rip') --- + that way, we can put in suitable type declarations in our specification + functions.

+ +

This function doesn't really specify whether a memory address that points + to some instruction byte is valid or not --- that notion is much more + complicated; see @(see canonical-address-p), @(see ea-to-la), and @(see + instruction-pointer-operations) for details.

" + :parents (decoding-and-spec-utils) + :enabled t + (if (equal proc-mode #.*64-bit-mode*) + (signed-byte-p 48 rip) + (unsigned-byte-p 32 rip)) + + /// + + (defthm rip-guard-okp-equiv-for-non-64-bit-modes + (implies (and (rip-guard-okp proc-mode-1 rip) + (not (equal proc-mode-1 0)) + (not (equal proc-mode-2 0))) + (rip-guard-okp proc-mode-2 rip))) + + (defthm rip-guard-okp-for-64-bit-modep + (equal (rip-guard-okp #.*64-bit-mode* rip) + (signed-byte-p #.*max-linear-address-size* rip))) + + (defthm rip-guard-okp-for-compatibility-mode + (equal (rip-guard-okp #.*compatibility-mode* rip) + (unsigned-byte-p 32 rip)))) + +;; ====================================================================== + +(defmacro def-inst + (name &key + (operation 'nil) + (sp/dp 'nil) + (dp-to-sp 'nil) + (high/low 'nil) + (trunc 'nil) + (vex 'nil) + (evex 'nil) + (modr/m 'nil) + (additional-args 'nil) + body parents short long + inline enabled guard-debug guard + guard-hints (verify-guards 't) prepwork thms + returns) + + (if body + `(define ,name + (,@additional-args + ,@(and operation `((operation :type (integer 0 38)))) + ,@(and sp/dp `((sp/dp :type (integer 0 1)))) + ,@(and dp-to-sp `((dp-to-sp :type (integer 0 1)))) + ,@(and high/low `((high/low :type (integer 0 1)))) + ,@(and trunc `((trunc booleanp))) + (proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (rex-byte :type (unsigned-byte 8)) + ,@(if vex + `((vex-prefixes :type (unsigned-byte 24))) + `()) + ,@(if evex + `((evex-prefixes :type (unsigned-byte 32))) + `()) + (opcode :type (unsigned-byte 8)) + (modr/m :type (unsigned-byte 8)) + (sib :type (unsigned-byte 8)) + x86 + ;; If operation = -1, ignore this field. Note that -1 is + ;; the default value of operation. + ;; &optional ((operation :type (integer -1 8)) '-1 ) + ) + + (declare + (ignorable proc-mode start-rip temp-rip prefixes rex-byte + opcode modr/m sib)) + + ,@(and parents `(:parents ,parents)) + ,@(and short `(:short ,short)) + ,@(and long `(:long ,long)) + + ,@(and prepwork `(:prepwork ,prepwork)) + + :guard (and (prefixes-p prefixes) + (ModR/M-p modr/m) + (sib-p sib) + (rip-guard-okp proc-mode temp-rip) + ,@(and guard `(,guard))) + + ,@(and enabled `(:enabled ,enabled)) + ,@(and inline `(:inline ,inline :no-function t)) + ,@(and (not verify-guards) `(:verify-guards ,verify-guards)) + ,@(and guard-debug `(:guard-debug ,guard-debug)) + ,@(and guard-hints `(:guard-hints ,guard-hints)) + + ,@(and returns `(:returns ,returns)) + + (b* ((?ctx ',name) + ,@(and modr/m + '((?r/m (the (unsigned-byte 3) (modr/m->r/m modr/m))) + (?mod (the (unsigned-byte 2) (modr/m->mod modr/m))) + (?reg (the (unsigned-byte 3) (modr/m->reg modr/m)))))) + ,body) + + /// + + (add-to-ruleset instruction-decoding-and-spec-rules + '(,name)) + + ,@(and thms + `(,@thms))) + + nil)) + +;; All the instruction decoding and spec functions will be added to +;; this ruleset automatically if def-inst is used to define these +;; functions. +(def-ruleset instruction-decoding-and-spec-rules nil) + +;; ====================================================================== + +(define x86-step-unimplemented (message x86) + :parents (instructions) + :short "Semantic function corresponding to Intel's instructions unsupported + in the @('x86isa') books" + :long "

Note that the @('ms') field is populated with @('message') here + because this function is called when a model-related error occurs.

" + :returns (x86 x86p :hyp (x86p x86)) + (b* ((ctx 'x86-step-unimplemented)) + (!!ms-fresh :message message))) + +(define x86-illegal-instruction + (message + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + x86) + :parents (instructions) + :short "Semantic function corresponding to opcodes that Intel deems to be + illegal or reserved" + :long "

Note that the @('#UD') (undefined operation) exception should be + thrown here, which is why the @('fault') field is populated with + @('message').

" + :returns (x86 x86p :hyp (x86p x86)) + (b* ((ctx 'x86-illegal-instruction) + ;; We update the RIP to point to the next instruction --- in case we + ;; ever get to the point that we can recover from #UD exceptions, this + ;; may be the right thing to do. + (x86 (!rip temp-rip x86))) + (!!fault-fresh :ud message :instruction-address start-rip))) + +(define x86-general-protection + (message + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + x86) + :parents (instructions) + :short "Semantic function corresponding to a general protection fault" + :long "

Note that the @('#GP') (general protection) exception should be + thrown here, which is why the @('fault') field is populated with + @('message').

" + :returns (x86 x86p :hyp (x86p x86)) + (b* ((ctx 'x86-general-protection) + ;; We update the RIP to point to the next instruction --- in case we + ;; ever get to the point that we can recover from #GP exceptions, this + ;; may be the right thing to do. + (x86 (!rip temp-rip x86))) + (!!fault-fresh :gp message :instruction-address start-rip))) + +(define x86-device-not-available + (message + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + x86) + :parents (instructions) + :short "Semantic function corresponding to a device not available (no math coprocessor) fault" + :long "

Note that the @('#NM') (device not available) exception should be + thrown here, which is why the @('fault') field is populated with + @('message').

" + :returns (x86 x86p :hyp (x86p x86)) + (b* ((ctx 'x86-device-not-available) + ;; We update the RIP to point to the next instruction --- in case we + ;; ever get to the point that we can recover from #NM exceptions, this + ;; may be the right thing to do. + (x86 (!rip temp-rip x86))) + (!!fault-fresh :nm message :instruction-address start-rip))) + +(add-to-ruleset instruction-decoding-and-spec-rules + '(x86-step-unimplemented + x86-illegal-instruction + x86-general-protection + x86-device-not-available)) + +;; ====================================================================== + +(define select-operand-size + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (byte-operand? :type (or t nil)) + (rex-byte :type (unsigned-byte 8)) + (imm? :type (or t nil)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (default64? :type (or t nil)) + (ignore-rex? :type (or t nil)) + (ignore-p3-64? :type (or t nil)) + (x86 x86p)) + + :inline t + :no-function t + :parents (decoding-and-spec-utils) + :guard (prefixes-p prefixes) + + :short "Selecting the operand size for general-purpose instructions" + + :long "

@('select-operand-size') selects the operand size of the + instruction. It is cognizant of the instruction prefixes, the + @('rex') byte, the operand type (e.g., immediate operand or not), + and the default operand size (obtained from the state).

+ +

This function was written by referring to the following: +

    +
  1. Intel Manuals, Vol. 1, Section 3.6, Table 3-3
  2. +
  3. Intel Manuals, Vol. 1, Section 3.6, Table 3-4
  4. +
  5. Intel Manuals, Vol. 2, Section 2.2.1.2
  6. +
+

+ +

+ +

+ + The first image above has been captured from Volume 1: Basic Architecture, + Intel\(R\) 64 and IA-32 Architectures Software Developer's Manual, + Order Number: 253665-062US, March 2017.

+ + The second image above has been captured from Volume 1: Basic Architecture, + Intel\(R\) 64 and IA-32 Architectures Software Developer's Manual, + Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B and 3C, Order Number: + 325462-054US, April 2015.

+ + +
    +
  • Setting REX.W can be used to determine the operand size but does + not solely determine operand width. Like the 66H size prefix, 64-bit + operand size override has no effect on byte-specific operations.
  • + +
  • For non-byte operations: if a 66H prefix is used with prefix + \(REX.W = 1\), 66H is ignored.
  • + +
  • If a 66H override is used with REX and REX.W = 0, the operand size + is 16 bits.
  • +
+
+ +

This function also includes three additional boolean parameters that serve + to accommodate instructions that do not quite follow the general rules + specified by the table above:

+ +
    + +
  • The @('default64?') parameter says whether the default operand size in + 64-bit mode should be 64 bits instead of 32 bits. Examples are @(tsee + x86-near-jmp-op/en-m) and @(tsee x86-push-general-register).
  • + +
  • The @('ignore-rex?') parameter says whether, in 64-bit mode, REX.W should + be ignored for the purpose of determining the operand size. Examples are + @(tsee x86-two-byte-jcc), @(tsee x86-near-jmp-op/en-m), and @(tsee + x86-push-general-register).
  • + +
  • The @('ignore-p3-64?') parameter says whether, in 64-bit mode, P3 should + be ignored for the purpose of determining the operand size. Examples are + @(tsee x86-two-byte-jcc) and @(tsee x86-near-jmp-op/en-m).
  • + +
" + + :enabled t + :returns (size natp :rule-classes :type-prescription) + + (if byte-operand? + 1 + (if (equal proc-mode #.*64-bit-mode*) + (if (and (logbitp #.*w* rex-byte) + (not ignore-rex?)) + (if imm? + ;; Fetch 4 bytes (sign-extended to 64 bits) if operand is + ;; immediate. + 4 + 8) + (if (and (eql #.*operand-size-override* + (the (unsigned-byte 8) (prefixes->opr prefixes))) + (not ignore-p3-64?)) + 2 + (if default64? + 8 + 4))) + ;; 32-bit mode or Compatibility Mode: + (b* (((the (unsigned-byte 16) cs-attr) (seg-hidden-attri #.*cs* x86)) + (cs.d (code-segment-descriptor-attributesBits->d cs-attr)) + (p3? (eql #.*operand-size-override* + (the (unsigned-byte 8) (prefixes->opr prefixes))))) + (if (= cs.d 1) + (if p3? 2 4) + (if p3? 4 2))))) + /// + (defthm select-operand-size-range + (and (<= 1 (select-operand-size proc-mode byte-operand? rex-byte imm? + prefixes default64? ignore-rex? ignore-p3-64? x86)) + (<= (select-operand-size proc-mode byte-operand? rex-byte imm? + prefixes default64? ignore-rex? ignore-p3-64? x86) + 8)) + :rule-classes :linear) + + (defthm select-operand-size-values + (or (equal (select-operand-size proc-mode byte-operand? rex-byte + imm? prefixes default64? ignore-rex? ignore-p3-64? x86) + 1) + (equal (select-operand-size proc-mode byte-operand? rex-byte + imm? prefixes default64? ignore-rex? ignore-p3-64? x86) + 2) + (equal (select-operand-size proc-mode byte-operand? rex-byte + imm? prefixes default64? ignore-rex? ignore-p3-64? x86) + 4) + (equal (select-operand-size proc-mode byte-operand? rex-byte + imm? prefixes default64? ignore-rex? ignore-p3-64? x86) + 8)))) + +;; ====================================================================== + +(define select-segment-register + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (p2 (unsigned-byte-p 8 p2)) + (p4? booleanp) + (mod (unsigned-byte-p 2 mod)) + (r/m (unsigned-byte-p 3 r/m)) + (sib (unsigned-byte-p 8 sib)) + (x86 x86p)) + :returns (seg-reg (integer-range-p 0 *segment-register-names-len* seg-reg)) + :inline t + :no-function t + :parents (decoding-and-spec-utils) + :short "Segment register to use for an instruction operand in memory." + :long + "

+ If there is a segment register override prefix, + the prefix determines the segment register, + according to Intel manual, Mar'17, Volume 2, Section 2.1.1. +

+

+ Otherwise, we use the default segment selection rules + in Intel manual, May'18, Volume 1, Table 3-5. + Since we only call this function for instruction operands, + the CS rule does not apply. + The ES rule applies to string instructions, + but our model does not use this function + to determine the ES segment for string instructions + (which cannot be overridden, + at least for the string instructions we currently support), + so this function does not take the ES rule into account either. + So the result is either SS or DS, + based on whether the base register is one of rSP and rBP or not: + this determination is made based on + Intel manual, May'18, Volume 2, Table 2-1 if the address size is 16 bits, + and Intel manual, May'18, Volume 2, Table 2-2 otherwise. + However, when Mod is not 11b and R/M is 100b, + the notation [--][--] in Table 2-2 indicates the use of a SIB byte: + according to Intel manual, May'18, Volume 2, Table 2-3, + when the Base field of the SIB byte is 100b, + the base register is rSP, + and thus in this case the default segment register is SS. +

+

+ Note that here we may recalculate the address size + even if that has already been calculated as part of + the decoding of the instruction whose operand we are accessing. + Thus, it may be possible to optimize the overall code. +

" + (case p2 + (#x2E #.*cs*) + (#x36 #.*ss*) + (#x3E #.*ds*) + (#x26 #.*es*) + (#x64 #.*fs*) + (#x65 #.*gs*) + (t (b* ((addr-size (select-address-size proc-mode p4? x86))) + (if (= addr-size 2) + (if (and (not (= mod 3)) + (or (= r/m 2) (= r/m 3))) + #.*ss* + #.*ds*) + (if (or (and (or (= mod 1) (= mod 2)) + (= r/m 5)) + (and (not (= mod 3)) + (= r/m 4) + (= (sib->base sib) 4))) + #.*ss* + #.*ds*))))) + /// + + (defret range-of-select-segment-register + (and (<= 0 seg-reg) + (< seg-reg #.*segment-register-names-len*)) + :rule-classes :linear)) + +;; ====================================================================== + +(define check-instruction-length + ((start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (delta-rip :type (unsigned-byte 3))) + :returns (badlength? acl2::maybe-natp + :hints (("Goal" :in-theory (enable acl2::maybe-natp)))) + :inline t + :no-function t + :parents (decoding-and-spec-utils) + :short "Check if the length of an instruction exceeds 15 bytes." + :long + "

+ The maximum length of an instruction is 15 bytes; + a longer instruction causes a #GP(0) exception. + See AMD manual, Dec'17, Volume 2, Table 8-6. + This function is used to check this condition. +

+

+ The @('start-rip') argument is + the instruction pointer at the beginning of the instruction. + The @('temp-rip') argument is generally + the instruction pointer just past the end of the instruction, + in which case the @('delta-rip') argument is 0. + In the other cases, @('delta-rip') is a small non-zero number, + and @('temp-rip + delta-rip') is + the instruction pointer just past the end of the instruction. +

+

+ This function returns @('nil') if the length does not exceed 15 bytes. + Otherwise, this function returns the offending length (a number above 15), + which is useful for error reporting in the model. +

" + (b* ((start-rip (mbe :logic (ifix start-rip) :exec start-rip)) + (temp-rip (mbe :logic (ifix temp-rip) :exec temp-rip)) + (delta-rip (mbe :logic (nfix delta-rip) :exec delta-rip)) + ((the (signed-byte #.*max-linear-address-size+1*) end-rip) + (+ (the (signed-byte #.*max-linear-address-size*) temp-rip) + (the (unsigned-byte 3) delta-rip))) + ((the (signed-byte #.*max-linear-address-size+2*) length) + (- (the (signed-byte #.*max-linear-address-size+1*) end-rip) + (the (signed-byte #.*max-linear-address-size*) start-rip)))) + (and (> length 15) + length))) + +;; ====================================================================== + +(define rex-byte-from-vex-prefixes ((vex-prefixes vex-prefixes-p)) + :guard (vex-prefixes-byte0-p vex-prefixes) + :returns (rex-byte (unsigned-byte-p 8 rex-byte)) + :parents (decoding-and-spec-utils) + :short "Calculate a REX byte from a VEX prefix." + :long + "

+ The VEX prefix (see Intel manual Volume 2 Section 2.3.5 of Dec 2023) + provides an encoding of the REX byte. + Since some of the functions in our model depend on the REX byte + (e.g. @(tsee x86-operand-from-modr/m-and-sib-bytes)), + here we introduce a function to build a REX byte + from its encoding in the VEX prefix. + We do that for both the 2-byte form and the 3-byte form of the VEX prefix; + see @(tsee vex->r), @(tsee vex->x), @(tsee vex->b), and @(tsee vex->w). + See Figure 2-9 in Intel manual Volume 2 of Dec 2023. + Note that the R, X, B bits are encoded negated, + while the W is encoded directly (not negated). +

" + (b* ((vex.w (vex->w vex-prefixes)) + (vex.r (vex->r vex-prefixes)) + (vex.x (vex->x vex-prefixes)) + (vex.b (vex->b vex-prefixes)) + (rex-byte (+ #x40 ; 40h-4Fh + (if (= vex.w 0) 0 #b1000) + (if (= vex.r 1) 0 #b0100) + (if (= vex.x 1) 0 #b0010) + (if (= vex.b 1) 0 #b0001)))) + rex-byte) + /// + + (defthm-unsigned-byte-p unsigned-byte-p-of-rex-byte-from-vex-prefixes + :bound 8 + :concl (rex-byte-from-vex-prefixes vex-prefixes) + :gen-type t + :gen-linear t)) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-creator.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-creator.lisp new file mode 100644 index 000000000..b21a0e773 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-creator.lisp @@ -0,0 +1,503 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2019, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "inst-listing") + +(defsection dispatch-creator + :parents (filtering-instructions) + :short "Utilities to generate opcode dispatch functions from the annotated +opcode maps." + ) + +(local (xdoc::set-default-parents 'dispatch-creator)) + +;; ---------------------------------------------------------------------- + +(local + (defthm true-listp-of-subst-when-not-true-listp-old + (implies (and (true-listp tree) + (not (true-listp old))) + (true-listp (acl2::subst new old tree))))) + + +(define replace-formals-with-arguments-aux ((bindings eqlable-alistp) + (formals true-listp)) + (if (endp bindings) + formals + (b* ((binding (car bindings)) + (formal (car binding)) + ((unless (not (true-listp formal))) + (er hard? 'replace-formals-with-arguments-aux + "~%Formal ~p0 not expected to be a true-list!~%" + formal)) + (argument (cdr binding)) + (new-formals (acl2::subst argument formal formals))) + (replace-formals-with-arguments-aux (cdr bindings) new-formals))) + /// + (defthm true-listp-of-replace-formals-with-arguments-aux + (implies (true-listp formals) + (true-listp (replace-formals-with-arguments-aux + bindings formals))))) + +(define replace-formals-with-arguments ((fn symbolp) + (bindings eqlable-alistp) + (world plist-worldp)) + + (b* ((formals (acl2::formals fn world)) + ((unless (true-listp formals)) nil) + (args (replace-formals-with-arguments-aux bindings formals)) + (call (cons fn args))) + call) + /// + (defthm true-listp-of-replace-formals-with-arguments + (true-listp (replace-formals-with-arguments fn bindings world)))) + +(define create-exceptions-check ((exc exception-desc-p)) + ;; (create-exceptions-check '((:UD (UD-LOCK-USED)))) + ;; (create-exceptions-check '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + ;; (create-exceptions-check '((:ud . ((ud-not-in-prot-or-64-mode) + ;; (ud-not-in-vmx-operation) + ;; (ud-invept-not-supported) + ;; (ud-ModR/M.Mod-indicates-Register))) + ;; (:ex . (chk-exc :type-4 nil)))) + :guard-hints (("Goal" :in-theory (e/d (exception-desc-p) ()))) + (if (atom exc) nil + (b* ((exception (caar exc)) + (exception-list (cdar exc))) + (if (eq exception :ex) + `(let ((chk-ex (or ,@exception-list))) + (or chk-ex + ,(create-exceptions-check (cdr exc)))) + `(if (or ,@exception-list) (quote ,exception) + ,(create-exceptions-check (cdr exc))))))) + +(define make-exception-handling-cases ((exception-info exception-desc-p) + illegal unimplemented + (world plist-worldp)) + :prepwork ((local (in-theory (e/d (exception-desc-p) ())))) + (append (and (or (assoc :ud exception-info) + (assoc :ex exception-info)) + (list (list :ud illegal))) + (and (or (assoc :gp exception-info) + (assoc :ex exception-info)) + (list (list :gp (replace-formals-with-arguments + 'x86-general-protection + '((message . "#GP Encountered!")) + world)))) + (and (or (assoc :nm exception-info) + (assoc :ex exception-info)) + (list (list :nm (replace-formals-with-arguments + 'x86-device-not-available + '((message . "#NM Encountered!")) + world)))) + (list (list t unimplemented)))) + +(define create-call-from-fn-and-exception ((fn fn-desc-p) + (exc exception-desc-p) + (feat symbol-listp) + (wrld plist-worldp)) + :prepwork ((local (in-theory (e/d (exception-desc-p fn-desc-p) ())))) + + (b* ((unimplemented-opcode (replace-formals-with-arguments + 'x86-step-unimplemented + '((message . "Opcode Unimplemented in x86isa!")) + wrld)) + (unimplemented-exc (replace-formals-with-arguments + 'x86-step-unimplemented + '((message . "Unimplemented exception in x86isa!")) + wrld)) + (illegal (replace-formals-with-arguments + 'x86-illegal-instruction + '((message . "#UD Encountered!")) + wrld)) + (fn-call (if (equal fn nil) + unimplemented-opcode + (let ((fn-name (car fn)) + (bindings (cdr fn))) + (if (equal fn-name :no-instruction) + illegal + (replace-formals-with-arguments + fn-name bindings wrld))))) + ;; new-exc explicitly accounts for feature flag information too. + (new-exc (if feat + (b* ((ud (cdr (assoc :ud exc))) + (feat+ud + (cons `(equal (feature-flags-macro ',feat) 0) + ud))) + (put-assoc :ud feat+ud exc)) + exc)) + (exception-check (create-exceptions-check new-exc)) + (exception-cases (make-exception-handling-cases + new-exc illegal unimplemented-exc wrld))) + (cond ((equal fn nil) + (if exception-check + `(let ((fault-var ,exception-check)) + (if fault-var (case fault-var ,@exception-cases) + ,fn-call)) + fn-call)) + (t + (if exception-check + `(let ((fault-var ,exception-check)) + (if fault-var + (case fault-var ,@exception-cases) + ,fn-call)) + fn-call))))) + +(define vex-keyword-case-gen ((prefix-case keywordp)) + + (case prefix-case + (:UNUSED-VVVV `((equal (vex->vvvv vex-prefixes) #b1111))) + ;; TODO: The following line has been commented out because it was causing + ;; SARX/SHLX/SHRX to fail (with #UD) when vvvv was used to encode RAX, + ;; which is a valid encoding for those instructions with that register, + ;; which is generated by compilers. However, we need to make a more detailed + ;; analysis of this, so this is why it is marked as 'TODO'. + ;; ((:NDS :NDD :DDS) `((not (equal (vex->vvvv vex-prefixes) #b1111)))) + ((:128 :LZ :L0) `((equal (vex->l vex-prefixes) 0))) + ((:256 :L1) `((equal (vex->l vex-prefixes) 1))) + ((:no-prefix) `((equal (vex->pp vex-prefixes) 0))) + ((:66) `((equal (vex->pp vex-prefixes) #.*v66*))) + ((:F3) `((equal (vex->pp vex-prefixes) #.*vF3*))) + ((:F2) `((equal (vex->pp vex-prefixes) #.*vF2*))) + ((:W0) `((equal (vex->w vex-prefixes) 0))) + ((:W1) `((equal (vex->w vex-prefixes) 1))) + ;; I don't need :0F, :0F38, and :0F3A below because the + ;; vex-decode-and-execute function deals with this already. + ;; ((:0F) `((vex-prefixes-map-p #x0F vex-prefixes))) + ;; ((:0F38) `((vex-prefixes-map-p #x0F38 vex-prefixes))) + ;; ((:0F3A) `((vex-prefixes-map-p #x0F3A vex-prefixes))) + (otherwise + ;; :LIG, :WIG, :VEX, etc. + `()))) + +(define evex-keyword-case-gen ((prefix-case keywordp)) + + (case prefix-case + (:UNUSED-VVVV `((and (equal (evex->vvvv evex-prefixes) #b1111) + (equal (evex->v-prime evex-prefixes) #b1)))) + ((:NDS :NDD :DDS) `((not + (and (equal (evex->vvvv evex-prefixes) #b1111) + (equal (evex->v-prime evex-prefixes) #b1))))) + ((:128 :LZ :L0) `((equal (evex->vl/rc evex-prefixes) 0))) + ((:256 :L1) `((equal (evex->vl/rc evex-prefixes) 1))) + (:512 `((equal (evex->vl/rc evex-prefixes) 2))) + ((:no-prefix) `((equal (evex->pp evex-prefixes) 0))) + ((:66) `((equal (evex->pp evex-prefixes) #.*v66*))) + ((:F3) `((equal (evex->pp evex-prefixes) #.*vF3*))) + ((:F2) `((equal (evex->pp evex-prefixes) #.*vF2*))) + ((:W0) `((equal (evex->w evex-prefixes) 0))) + ((:W1) `((equal (evex->w evex-prefixes) 1))) + ;; I don't need to account for :0F, :0F38, and :0F3A because the + ;; evex-decode-and-execute function deals with this already. + (otherwise + ;; :LIG, :WIG, :EVEX, etc. + `()))) + +(define avx-keyword-case-gen ((prefix-case keywordp) + (vex? booleanp)) + (if vex? + (vex-keyword-case-gen prefix-case) + (evex-keyword-case-gen prefix-case))) + +(define avx-opcode-case-gen-aux ((case-info acl2::keyword-listp) + (vex? booleanp)) + (if (endp case-info) + nil + `(,@(avx-keyword-case-gen (car case-info) vex?) + ,@(avx-opcode-case-gen-aux (cdr case-info) vex?)))) + +(local + (defthm subsetp-equal-and-keyword-listp + (implies (and (subsetp-equal x y) + (acl2::keyword-listp y) + (true-listp x)) + (acl2::keyword-listp x)) + :hints (("Goal" :in-theory (e/d (subsetp-equal + acl2::keyword-listp) + ()))))) + +(local + (defthm cons-keyword-listp + (implies (and (keywordp e) + (acl2::keyword-listp x)) + (acl2::keyword-listp (cons e x))) + :hints (("Goal" :in-theory (e/d (acl2::keyword-listp) ()))))) + +(define create-dispatch-for-avx-opcode ((map-key keywordp) + (inst inst-p) + call + (caseStmt true-listp) + rest) + :guard (member-equal + map-key + '(:vex-0F :vex-0F-38 :vex-0F-3A + :evex-0F :evex-0F-38 :evex-0F-3A)) + + (b* (((inst inst)) + (opcode inst.opcode) + ((opcode opcode)) + (vex? (and (or + (eql map-key :vex-0F) + (eql map-key :vex-0F-38) + (eql map-key :vex-0F-3A)) + opcode.vex + (eql opcode.evex nil))) + (evex? (and (or + (eql map-key :evex-0F) + (eql map-key :evex-0F-38) + (eql map-key :evex-0F-3A)) + (eql opcode.vex nil) + opcode.evex)) + ((unless (or vex? evex?)) rest) + ;; (- (cw "~% vex: ~p0 vex?: ~p1~%" opcode.vex vex?)) + ;; (- (cw "~% evex: ~p0 evex?: ~p1 ~%" opcode.evex evex?)) + (avx (if vex? opcode.vex opcode.evex)) + (prefix (cond ((member-equal :66 avx) :66) + ((member-equal :F2 avx) :F2) + ((member-equal :F3 avx) :F3) + (t :no-prefix))) + (avx (if (equal prefix :no-prefix) + (cons :no-prefix avx) + avx)) + (avx (if (or (member-equal :NDS avx) + (member-equal :NDD avx) + (member-equal :DDS avx)) + avx + (cons :UNUSED-VVVV avx))) + ;; (- (cw "~% avx: ~p0 ~%" avx)) + (avxCaseStmt + (avx-opcode-case-gen-aux avx vex?)) + ;; (- (cw "~% avxCaseStmt: ~p0 ~%" avxCaseStmt)) + (newCaseStmt + (append avxCaseStmt (list caseStmt))) + ;; (- (cw "~% newCaseStmt: ~p0 ~%" newCaseStmt)) + (newCaseStmt (if (acl2::all-equalp nil newCaseStmt) + nil + (if (< 1 (len (remove-equal 'nil newCaseStmt))) + `(and ,@newCaseStmt) + newCaseStmt)))) + (if newCaseStmt + (cons `(,newCaseStmt ,call) rest) + call))) + +(define create-dispatch-for-one-opcode ((inst-lst inst-list-p) + (map-key keywordp) + (wrld plist-worldp)) + + ;; (create-dispatch-for-one-opcode + ;; (select-insts *one-byte-opcode-map* :opcode #x0) + ;; :one-byte + ;; (w state)) + + ;; (create-dispatch-for-one-opcode + ;; (select-insts *one-byte-opcode-map* :opcode #x80) + ;; :one-byte + ;; (w state)) + + :guard (member-equal + map-key + '(:one-byte + :two-byte + :0F-38-three-byte + :0F-3A-three-byte + :vex-0F :vex-0F-38 :vex-0F-3A + :evex-0F :evex-0F-38 :evex-0F-3A)) + + :guard-hints (("Goal" + :in-theory + (e/d () + (acl2::member-of-cons + endp + keywordp + acl2::keyword-listp + len + remove-equal + member-equal + atom + not + acl2::symbolp-of-car-when-symbol-listp + symbol-listp + (tau-system))))) + + (b* (((when (atom inst-lst)) + (mv t + `((t ,(replace-formals-with-arguments + 'x86-illegal-instruction + '((message . "#UD Encountered!")) + wrld))))) + (inst (car inst-lst)) + ((inst inst)) + (opcode inst.opcode) + ((opcode opcode)) + ((when (and opcode.vex opcode.evex)) + (mv nil + (er hard? 'create-dispatch-for-one-opcode + "Both vex and evex?! Couldn't create dispatch for ~p0.~%" inst))) + (caseStmt + `(,@(and opcode.mode + (if (eql opcode.mode :o64) + `((equal proc-mode #.*64-bit-mode*)) + `((not (equal proc-mode #.*64-bit-mode*))))) + ;; opcode.feat is accounted for in + ;; create-call-from-fn-and-exception. + ;; ,@(and opcode.feat + ;; `((equal (feature-flags-macro ',opcode.feat) 1))) + ,@(and opcode.reg + `((equal (modr/m->reg modr/m) ,opcode.reg))) + ,@(and opcode.mod + (if (equal opcode.mod :mem) + `((not (equal (modr/m->mod modr/m) #b11))) + `((equal (modr/m->mod modr/m) ,opcode.mod)))) + ,@(and opcode.r/m + `((equal (modr/m->r/m modr/m) ,opcode.r/m))) + ,@(and opcode.pfx + `((equal mandatory-prefix + ,(case opcode.pfx + (:66 #x66) + (:F2 #xF2) + (:F3 #xF3) + (otherwise #x0))))) + ,@(and opcode.rex + ;; :w and :not-w are the only two REX-based conditions right + ;; now. + (if (equal opcode.rex :w) + `((logbitp #.*w* rex-byte)) + `((not (logbitp #.*w* rex-byte))))))) + (caseStmt + (cond ((< 1 (len caseStmt)) `(and ,@caseStmt)) + ((consp caseStmt) (car caseStmt)) + (t ''t))) + (call (create-call-from-fn-and-exception + inst.fn inst.excep opcode.feat wrld)) + ((mv & rest) + (create-dispatch-for-one-opcode (cdr inst-lst) map-key wrld)) + ((when (and (member-equal + map-key + '(:vex-0F :vex-0F-38 :vex-0F-3A + :evex-0F :evex-0F-38 :evex-0F-3A)) + (or opcode.vex opcode.evex))) + (mv t + (create-dispatch-for-avx-opcode + map-key inst call caseStmt rest))) + ((when (or (eql map-key :one-byte) + (eql map-key :two-byte) + (eql map-key :0F-38-three-byte) + (eql map-key :0F-3A-three-byte))) + (if caseStmt + (mv t (cons `(,caseStmt ,call) rest)) + ;; This better be the last inst. + (if (endp (cdr inst-lst)) + (mv nil call) + (mv nil + (er hard? 'create-dispatch-for-one-opcode + "~% Expected this to be the last inst, but it's not! ~ + These insts are left: ~% ~p0" + (cdr inst-lst))))))) + ;; Unreachable. + (mv nil nil))) + +(define create-dispatch-for-opcodes ((first-opcode 24bits-p) + (num-opcodes natp) + (map-key keywordp) + (wrld plist-worldp)) + + ;; Include the following for debugging the events that generate the dispatch + ;; functions: + ;; (local (include-book "instructions/top" :ttags :all)) + ;; (local (include-book "dispatch-macros")) + + ;; (create-dispatch-for-opcodes #ux0F_00 256 :two-byte (w state)) + ;; (create-dispatch-for-opcodes #ux00 256 :one-byte (w state)) + ;; (create-dispatch-for-opcodes #ux0F_38_00 256 :0F-38-three-byte (w state)) + ;; (create-dispatch-for-opcodes #ux0F_3A_00 256 :0F-3A-three-byte (w state)) + + :guard (member-equal + map-key + '(:one-byte + :two-byte + :0F-38-three-byte + :0F-3A-three-byte + :vex-0F :vex-0F-38 :vex-0F-3A + :evex-0F :evex-0F-38 :evex-0F-3A)) + + (b* (((when (zp num-opcodes)) + `((t + ,(replace-formals-with-arguments + 'x86-illegal-instruction + '((message . "#UD Encountered!")) + wrld)))) + (rest (if (24bits-p (1+ first-opcode)) + (create-dispatch-for-opcodes + (1+ first-opcode) (1- num-opcodes) map-key wrld) + (er hard? 'create-dispatch-for-opcodes + "Illegal opcode ~s0.~%" (str::hexify (1+ first-opcode))))) + (map (select-opcode-map map-key)) + (same-opcode-insts (select-insts map :opcode first-opcode)) + (relevant-insts + (if (member-equal map-key '(:one-byte + :two-byte + :0F-38-three-byte + :0F-3A-three-byte)) + ;; Because of strict-opcode-p, we know that instructions without + ;; the following CPUID features have empty opcode.vex and + ;; opcode.evex fields, which means that they are non-AVX opcodes. + (remove-insts-with-feat same-opcode-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*)) + ;; Similarly, we know that instructions with these CPUID features are + ;; AVX opcodes. + (keep-insts-with-feat same-opcode-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*)))) + ((when (endp relevant-insts)) rest) + (preCondNeeded? (< 1 (len relevant-insts))) + ((mv moreCondNeeded? dispatch) + (create-dispatch-for-one-opcode relevant-insts map-key wrld)) + (condNeeded? (or preCondNeeded? moreCondNeeded?))) + (cons (cons + ;; Case statements need to consider only the low 8-bits of the + ;; opcode. + (loghead 8 first-opcode) + (if condNeeded? + `((cond ,@dispatch)) + `(,dispatch))) + rest))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-macros.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-macros.lisp new file mode 100644 index 000000000..fd2d26833 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/dispatch-macros.lisp @@ -0,0 +1,346 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2018, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") +(include-book "../utils/structures") +(include-book "cpuid-constants") +(include-book "cpuid") +(include-book "state") + +(local (xdoc::set-default-parents 'opcode-maps)) + +;; Macros and functions used by utilities in dispatch.lisp to create opcode +;; dispatch functions + +;; ---------------------------------------------------------------------- + +;; Exception-related definitions: + +;; ************************************************** +;; Variable bindings related to exceptions +;; -------------------------------------------------- + +;; VARIABLE TERM +;; +;; prefixes 1st return value of get-prefixes; logically: +;; (mv-nth 1 (get-prefixes proc-mode start-rip 0 0 15 x86)) +;; Fetched in x86-fetch-decode-execute for all opcodes + +;; cplx86 (cpl x86) + +;; modr/m byte fetched in x86-fetch-decode-execute (for +;; one-byte opcodes), +;; two-byte-opcode-decode-and-execute (for two-byte +;; opcodes), three-byte-opcode-decode-and-execute (for +;; three-byte opcodes), vex-decode-and-execute (for +;; vex-encoded instructions), and +;; evex-decode-and-execute (for evex-encoded +;; instructions). + +;; cr4 (ctri #.*cr4* x86) +;; cr0 (ctri #.*cr0* x86) + +;; ia32_efer (msri #.*ia32_efer-idx* x86) + +;; cpuid-flag CPUID information listed in Table 3-8, Intel Vol. 2. +;; +;; TODO: +;; +;; From Table 3-8: "Note that CPUID leaves above 2 and +;; below 80000000H are visible only when +;; IA32_MISC_ENABLE[bit 22] has its default value of 0." +;; +;; Is the above relevant for detecting feature support +;; for instructions too (as opposed to just during the +;; execution of the CPUID instruction)? + + +;; ************************************************** + +(defmacro ud-Lock-used () + `(eql #.*lock* (prefixes->lck prefixes))) + +(defmacro ud-Opr-used () + `(eql #.*operand-size-override* (prefixes->opr prefixes))) + +(defmacro ud-Reps-used () + `(or (eql #.*repe* (prefixes->rep prefixes)) + (eql #.*repne* (prefixes->rep prefixes)))) + +(defmacro ud-ModR/M.Mod-indicates-Register () + `(eql (modr/m->mod modr/m) #b11)) + +(defmacro ud-Lock-used-mod-indicates-register () + ;; For now, we check this only for instructions that require a modr/m byte. + ;; There are some instructions that do not take a modr/m byte but that throw + ;; a #UD when lock occurs and the destination is a register operand (e.g., + ;; ADC opcodes 0x14 and 0x15). For those cases, use (ud-Lock-used) instead. + `(and + ;; ModR/M.mod = #b11 means that the modr/m byte points to a register, and + ;; not to a memory operand. See Table 2-2 (32-bit Addressing Forms with + ;; the ModR/M byte) in Intel Vol. 2. + (ud-ModR/M.Mod-indicates-Register) + (eql #.*lock* (prefixes->lck prefixes)))) + +(defmacro ud-Lock-used-Dest-not-Memory-Op () + `(ud-Lock-used-mod-indicates-register)) + +(defmacro ud-source-operand-is-a-register () + `(ud-ModR/M.Mod-indicates-Register)) + +(defmacro ud-second-operand-is-a-register () + `(ud-ModR/M.Mod-indicates-Register)) + +(defmacro ud-cpl-is-not-zero () + `(not (eql (cplx86) 0))) + +(defmacro ud-not-in-prot-or-64-mode () + `(not (or (eql proc-mode #.*64-bit-mode*) + (eql proc-mode #.*protected-mode*)))) + +(defmacro ud-not-in-vmx-operation () + ;; BOZO Rob -- this is not modeled yet in x86 model, so return nil.. + `nil) + +(defmacro ud-invept-not-supported () + ;; BOZO Rob -- we do not support this yet either in x86 model: + ;; (IA32_VMX_PROCBASED_CTLS2[33]=1) but does not support the INVEPT instruction (IA32_VMX_EPT_VPID_CAP[20]=0) + `nil) + +(defmacro ud-invvpid-not-supported () + ;; BOZO Rob -- and similary, x86 doesn't support this yet: + ;; (IA32_VMX_PROCBASED_CTLS2[37]=1) but does not support the INVVPID instruction (IA32_VMX_EPT_VPID_CAP[32]=0) + `nil) + +(defmacro ud-invpcid-not-supported () + `(= (cpuid-flag #ux_07 :reg #.*ebx* :bit 10) 0)) + +(defmacro ud-repne-f2-V86-cpuid-case () + ;; BOZO Rob -- we don't really have V86 mode supported yet in x86, so return nil here: + `nil) + +(defmacro ud-rep-f3-used () + `(eql #.*repe* (prefixes->rep prefixes))) + +(defmacro nm-cr0-ts-is-1 () + `(eql (cr0Bits->ts (cr0)) 1)) + +(defmacro nm-cr0-em-is-1 () + `(eql (cr0Bits->em (cr0)) 1)) + +(defmacro nm-exc-all-types () + ;; for all vex/evex exception types, we have a requirement on cr0.ts bit: + `(nm-cr0-ts-is-1)) + +(defmacro gp-cpl-not-0 () + `(not (eql (cplx86) 0))) + +(defmacro gp-cr4-pce-is-0 () + `(eql (cr4Bits->pce (cr4)) 0)) + +(defmacro gp-cr4-umip-is-1 () + `(eql (cr4Bits->umip (cr4)) 0)) + +(defmacro gp-cr0-pe-is-0 () + `(eql (cr0Bits->pe (cr0)) 0)) + +;; ---------------------------------------------------------------------- + +;; These macros are the access points to the specific registers in the x86 model: + +(defmacro cplx86 () + `(ifix (cpl x86))) + +(defmacro cs.d () + `(b* (((the (unsigned-byte 16) cs-attr) + (seg-hidden-attri #.*cs* x86))) + (code-segment-descriptor-attributesBits->d cs-attr))) + +(defmacro cr0 () + `(the (unsigned-byte 32) + (loghead 32 (ifix (ctri #.*cr0* x86))))) + +(defmacro cr4 () + `(the (unsigned-byte 22) + (loghead 22 (ifix (ctri #.*cr4* x86))))) + +(defmacro ia32_efer () + `(msri #.*ia32_efer-idx* x86)) + +(defmacro feature-flag-macro (x) + `(feature-flag ,x)) + +(defmacro feature-flags-macro (x) + `(feature-flags ,x)) + +;; ---------------------------------------------------------------------- + +(defmacro chk-exc (type-id feature-flags) + `(chk-exc-fn :legacy ,type-id ',feature-flags + ;; captured inputs: + proc-mode prefixes rex-byte opcode modr/m sib x86)) + +(defmacro chk-exc-vex (type-id feature-flags) + `(chk-exc-fn :vex ,type-id ',feature-flags + ;; captured inputs: + proc-mode prefixes rex-byte opcode modr/m sib x86)) + +(defmacro chk-exc-evex (type-id feature-flags) + `(chk-exc-fn :evex ,type-id ',feature-flags + ;; captured inputs: + proc-mode prefixes rex-byte opcode modr/m sib x86)) + +;;;;;; + +(local (include-book "arithmetic-5/top" :dir :system)) + + + +(define chk-exc-fn ((decode-context symbolp) + (type-id symbolp) + (feature-flags symbol-listp) + ;; these parameters are captured from the expected + ;; environment in which chk-exc calls should expand: + (proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (rex-byte :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8)) + (modr/m :type (unsigned-byte 8)) + (sib :type (unsigned-byte 8)) + x86) + + :guard (and (member-eq decode-context '(:legacy :vex :evex)) + (subsetp-equal feature-flags *supported-feature-flags*)) + :guard-hints (("Goal" :in-theory (e/d () (x86$ap xr ifix)))) + (declare (ignore opcode modr/m sib)) ;; don't use these yet, but include them anyways.. + + ;; *** UD checks for conditions that can be detected at decode time *** + + ;; This macro is applicable to non-AVX instructions in only + ;; protected/compatibility and 64-bit modes. + + ;; Note that we don't check for "If an unmasked SIMD floating-point exception + ;; and CR4.OSXMMEXCPT[bit 10] = 0." here (which shows up in Types 2 and 3, + ;; Intel Vol. 2, and in Tables 22-4, 22-5, and 22-6 Intel Vol. 3) --- this is + ;; because this condition can't be checked at decode time and must be + ;; detected in the instruction's semantic function. + + ;; -------------------------------------------------- + + ;; This definition for UD is applicable to the following with the cr4-osfxsr? + ;; value set to T: + + ;; Source: Intel Manuals (May 2018 Edition) + ;; Section 2.4 (AVX and SSE Exception Specification), Chapter 2, Intel Vol. 2 + ;; Section 22.25.3 (Exception Conditions of Legacy SIMD Instructions + ;; Operating on MMX Registers), Chapter 22, Intel Vol. 3 + + ;; Exceptions Type 1 (Section 2.4.1, Intel Vol. 2) + + ;; Exceptions Type 2 (Section 2.4.2, Intel Vol. 2) + + ;; Exceptions Type 3 (Section 2.4.3, Intel Vol. 2) + + ;; Exceptions Type 4 (Section 2.4.4, Intel Vol. 2) + + ;; Exceptions Type 5 (Section 2.4.5, Intel Vol. 2) + + ;; Exceptions Type 7 (Section 2.4.7, Intel Vol. 2) + + ;; Exception Conditions of Legacy SIMD/MMX Instructions with FP Exception and + ;; 16-Byte Alignment (Table 22-4, Intel Vol. 3) + + ;; Exception Conditions for Legacy SIMD/MMX Instructions with XMM and FP + ;; Exception (Table 22-5, Intel Vol. 3) + + ;; Exception Conditions for Legacy SIMD/MMX Instructions with XMM and without + ;; FP Exception (Table 22-6, Intel Vol. 3) + + ;; -------------------------------------------------- + + ;; This definition for UD is applicable to the following with the cr4-osfxsr? + ;; value set to NIL: + + ;; Exception Conditions for SIMD/MMX Instructions with Memory Reference + ;; (Table 22-7, Intel Vol. 3) + + ;; Exception Conditions for Legacy SIMD/MMX Instructions without FP Exception + ;; (Table 22-8, Intel Vol. 3) --- for MASKMOVQ, this requires ModR/M.mod != + ;; #b11, which we check separately. + + ;; Exception Conditions for Legacy SIMD/MMX Instructions without Memory + ;; Reference (Table 22-9, Intel Vol. 3) + + ;; -------------------------------------------------- + + (cond +; (t nil) ;; BOZO Rob -- I want to enable the rest of this definition, but the + ;; guard proof is excruciatingly (although it does go through) and I need to + ;; figure out how to get it to go through quicker.. + ((and (eq decode-context :vex) + (or (ud-Reps-used) + (ud-Opr-used) + (not (eql rex-byte 0)) + (not (or (eql proc-mode #.*64-bit-mode*) + (eql proc-mode #.*compatibility-mode*) + (eql proc-mode #.*protected-mode*))))) + :ud) + ((or (eq type-id :type-vex-gpr) + ;; BOZO Sol -- it seems like maybe this is a synonym? + (eq type-id :type-13)) + ;; from table 2.5.1 from volume 2.. we only need to additionally check + ;; the cpuid requirements: (BOZO Sol -- maybe this is now table 2.6.1?) + (cond ((equal (feature-flags feature-flags) 0) :ud))) + ((equal (cr0Bits->ts (cr0)) 1) + :nm) + ((and (not (member-eq type-id '(:type-22-7 :type-22-8 :type-22-9))) + (equal (cr4Bits->osfxsr (cr4)) 0)) + :ud) + ;; BOZO -- Rob -- still need to add more here :( + ((or (equal (cr0Bits->em (cr0)) 1) + (ud-lock-used) + ;; If a corresponding CPUID feature flag is 0. + ;; Source: Intel Vol. 2 (May 2018 edition) + ;; Figure 3-7 (Feature Information Returned in the ECX register) + ;; Table 3-10 (Feature Information Returned in the ECX register) + ;; Figure 3-8 (Feature Information Returned in the EDX register) + ;; Table 3-11 (More on Feature Information Returned in the EDX register) + (equal (feature-flags feature-flags) 0)) + :ud))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/get-prefixes.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/get-prefixes.lisp new file mode 100644 index 000000000..a046a2358 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/get-prefixes.lisp @@ -0,0 +1,909 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, May - August 2023, Regents of the University of Texas +; Copyright (C) August 2023 - May 2024, Yahya Sohail +; Copyright (C) May 2024 - August 2024, Intel Corporation +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Yahya Sohail + +(in-package "X86ISA") + +;; ---------------------------------------------------------------------- + +(include-book "top-level-memory") +(include-book "prefix-modrm-sib-decoding") +(include-book "decoding-and-spec-utils") + +;; ---------------------------------------------------------------------- + +(defsection x86-decoder + :parents (machine) + :short "Definitions of the x86 fetch, decode, and execute function + and the top-level run function" + ) + +(local (xdoc::set-default-parents x86-decoder)) + +;; ---------------------------------------------------------------------- + +(define get-prefixes + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (rex-byte :type (unsigned-byte 8)) + (cnt :type (integer 0 15)) + x86) + + :guard (prefixes-p prefixes) + :guard-hints + (("Goal" :in-theory + (e/d () + (negative-logand-to-positive-logand-with-integerp-x + signed-byte-p)))) + + :measure (nfix cnt) + :hints (("Goal" :in-theory (e/d () ((tau-system))))) + + :returns + (mv flg + + ;; This is in fact a (unsigned-byte-p *prefixes-width*) + ;; (i.e. a prefixes-p, see (defbitstruct prefixes ...)), + ;; as proved later in this DEFINE form. + (new-prefixes natp :rule-classes :type-prescription + :hyp (forced-and (natp prefixes) + (canonical-address-p start-rip) + (x86p x86)) + :hints + (("Goal" + :in-theory + (e/d () + (force + (force) + unsigned-byte-p + acl2::zp-open not + unsigned-byte-p + signed-byte-p + negative-logand-to-positive-logand-with-integerp-x + acl2::ash-0 + unsigned-byte-p-of-logior + acl2::zip-open + bitops::unsigned-byte-p-incr))))) + + ;; This is in fact an (unsigned-byte-p 8), + ;; as proved later in this DEFINE form. + (new-rex-byte natp :rule-classes :type-prescription + :hyp (forced-and (natp rex-byte) + (natp prefixes) + (x86p x86)) + :hints + (("Goal" + :in-theory + (e/d () + (force + (force) + acl2::zp-open not + unsigned-byte-p + signed-byte-p + negative-logand-to-positive-logand-with-integerp-x + acl2::ash-0 + unsigned-byte-p-of-logior + acl2::zip-open + bitops::unsigned-byte-p-incr))))) + + (new-x86 x86p + :hyp (forced-and (x86p x86) + (canonical-address-p start-rip)) + :hints + (("Goal" + :in-theory + (e/d () + (acl2::zp-open + force (force) + not + unsigned-byte-p + signed-byte-p + acl2::ash-0 + acl2::zip-open + bitops::logtail-of-logior + unsigned-byte-p-of-logtail + acl2::logtail-identity + bitops::logand-with-negated-bitmask + (:linear bitops::logior-<-0-linear-1) + (:linear bitops::logior-<-0-linear-2) + (:linear bitops::logand->=-0-linear-1) + (:linear bitops::logand->=-0-linear-2) + bitops::logtail-natp + natp-of-get-one-byte-prefix-array-code + acl2::ifix-when-not-integerp + ;; bitops::basic-signed-byte-p-of-+ + default-<-1 + negative-logand-to-positive-logand-with-integerp-x)))))) + + :parents (x86-decoder) + + :short "Fetch and store legacy and REX prefixes, if any, of an instruction" + + :long "

The function @('get-prefixes') fetches the legacy and REX prefixes + of an instruction and also returns the first byte following the last such + prefix. The input @('start-rip') points to the first byte of an instruction, + which may potentially be a legacy prefix. The initial value of @('cnt') + should be @('15') so that the result @('(- 15 cnt)') returned at the end of + the recursion is the correct number of legacy and/or REX bytes parsed by this + function.

+ +

Legacy Prefixes

+ +

From Intel Manual, Vol. 2, May 2018, Section 2.1.1 (Instruction + Prefixes):

+ +

Instruction prefixes are divided into four groups, each with a set of + allowable prefix codes. For each instruction, it is only useful to include + up to one prefix code from each of the four groups (Groups 1, 2, 3, + 4). Groups 1 through 4 may be placed in any order relative to each + other.

+ +

Despite the quote from the Intel Manual above, the order of the legacy + prefixes does matter when there is more than one prefix from the same group + --- all but the last prefix from a single prefix group are ignored. + The only exception in this case is for Group 1 prefixes --- see + below for details.

+ +

Examples:

+ +
    +
  • @('0x64_88_00') is @('mov byte ptr fs:[rax], al')
  • +
  • @('0x65_88_00') is @('mov byte ptr gs:[rax], al')
  • +
  • @('0x64_65_88_00') is @('mov byte ptr gs:[rax], al')
  • +
  • @('0x65_64_88_00') is @('mov byte ptr fs:[rax], al')
  • +
+ +
    +
  • @('0xf2_a4') is @('repne movsb byte ptr [rdi], byte ptr [rsi]')
  • +
  • @('0xf3_a4') is @('repe movsb byte ptr [rdi], byte ptr [rsi]')
  • +
  • @('0xf2_f3_a4') is @('repe movsb byte ptr [rdi], byte ptr [rsi]')
  • +
  • @('0xf3_f2_a4') is @('repne movsb byte ptr [rdi], byte ptr [rsi]')
  • +
+ +

We now discuss the Group 1 exception below.

+ +

@('0xf0_f2_a4') is NOT
+ @('repne movsb byte ptr [rdi], byte ptr [rsi]')
+ It is:
+ @('lock repne movsb byte ptr [rdi], byte ptr [rsi]')
+ + Note that lock and rep/repne are Group 1 prefixes. It is important to record + the lock prefix, even if it is overshadowed by a rep/repne prefix, because + the former instruction will not @('#UD'), but the latter instruction will. + This is akin to the lock prefix being in a separate group than the rep/repne + prefixes; in fact, AMD manuals (Section 1.2.1: Summary of Legacy Prefixes, + Vol. 3 May 2018 Edition) treat them as such.

+ +

For details about how mandatory prefixes are picked from legacy prefixes, + see @(see mandatory-prefixes-computation).

+ +

REX Prefixes

+ +

A REX prefix (applicable only to 64-bit mode) is treated as a null prefix + if it is followed by a legacy prefix. Here is an illustrative example (using + Intel's XED, x86 Encoder Decoder --- see + @('https://intelxed.github.io/')):

+ +
    + +
  • @('xed -64 -d 48670100') is @('add dword ptr [eax], eax'); the REX.W + prefix does not have any effect on the operand size, which remains 32 (i.e., + the default operand size in the 64-bit mode).
  • + +
  • @('xed -64 -d 67480100') is @('add qword ptr [eax], rax'); the REX prefix + has the intended effect of promoting the operand size to 64 bits.
  • + +
+ +

Note that the prefixes structure output of this function does not include + the REX byte (which is a separate return value of this function), but its + @(':num-prefixes') field includes a count of the REX prefixes encountered. + This is because adding an 8-bit field to the prefixes structure to store a + REX byte will make it a bignum, thereby impacting execution efficiency.

" + + :prepwork + + ((defthm return-type-of-prefixes->num-linear + (< (prefixes->num prefixes) 16) + :hints (("Goal" :in-theory (e/d (prefixes->num) ()))) + :rule-classes :linear) + + (defthm return-type-of-prefixes->lck-linear + (< (prefixes->lck prefixes) 256) + :hints (("Goal" :in-theory (e/d (prefixes->lck) ()))) + :rule-classes :linear) + + (defthm return-type-of-prefixes->rep-linear + (< (prefixes->rep prefixes) 256) + :hints (("Goal" :in-theory (e/d (prefixes->rep) ()))) + :rule-classes :linear) + + (defthm return-type-of-prefixes->seg-linear + (< (prefixes->seg prefixes) 256) + :hints (("Goal" :in-theory (e/d (prefixes->seg) ()))) + :rule-classes :linear) + + (defthm return-type-of-prefixes->opr-linear + (< (prefixes->opr prefixes) 256) + :hints (("Goal" :in-theory (e/d (prefixes->opr) ()))) + :rule-classes :linear) + + (defthm return-type-of-prefixes->adr-linear + (< (prefixes->adr prefixes) 256) + :hints (("Goal" :in-theory (e/d (prefixes->adr) ()))) + :rule-classes :linear) + + (defthm return-type-of-prefixes->nxt-linear + (< (prefixes->nxt prefixes) 256) + :hints (("Goal" :in-theory (e/d (prefixes->nxt prefixes-fix) + ()))) + :rule-classes :linear) + + (defthm return-type-of-prefixes->num-rewrite + (unsigned-byte-p 4 (prefixes->num prefixes)) + :hints (("Goal" :in-theory (e/d (prefixes->num) ()))) + :rule-classes :rewrite) + + (defthm return-type-of-prefixes->lck-rewrite + (unsigned-byte-p 8 (prefixes->lck prefixes)) + :hints (("Goal" :in-theory (e/d (prefixes->lck) ()))) + :rule-classes :rewrite) + + (defthm return-type-of-prefixes->rep-rewrite + (unsigned-byte-p 8 (prefixes->rep prefixes)) + :hints (("Goal" :in-theory (e/d (prefixes->rep) ()))) + :rule-classes :rewrite) + + (defthm return-type-of-prefixes->seg-rewrite + (unsigned-byte-p 8 (prefixes->seg prefixes)) + :hints (("Goal" :in-theory (e/d (prefixes->seg) ()))) + :rule-classes :rewrite) + + (defthm return-type-of-prefixes->opr-rewrite + (unsigned-byte-p 8 (prefixes->opr prefixes)) + :hints (("Goal" :in-theory (e/d (prefixes->opr) ()))) + :rule-classes :rewrite) + + (defthm return-type-of-prefixes->adr-rewrite + (unsigned-byte-p 8 (prefixes->adr prefixes)) + :hints (("Goal" :in-theory (e/d (prefixes->adr) ()))) + :rule-classes :rewrite) + + (defthm return-type-of-prefixes->nxt-rewrite + (unsigned-byte-p 8 (prefixes->nxt prefixes)) + :hints (("Goal" :in-theory (e/d (prefixes->nxt prefixes-fix) + ()))) + :rule-classes :rewrite) + + (defthm return-type-of-!prefixes->*-linear + (and (unsigned-byte-p 52 (!prefixes->num x prefixes)) + (unsigned-byte-p 52 (!prefixes->lck x prefixes)) + (unsigned-byte-p 52 (!prefixes->rep x prefixes)) + (unsigned-byte-p 52 (!prefixes->seg x prefixes)) + (unsigned-byte-p 52 (!prefixes->opr x prefixes)) + (unsigned-byte-p 52 (!prefixes->adr x prefixes)) + (unsigned-byte-p 52 (!prefixes->nxt x prefixes))) + :hints (("Goal" :in-theory + (e/d* (!prefixes->num + !prefixes->lck + !prefixes->rep + !prefixes->seg + !prefixes->opr + !prefixes->adr + !prefixes->nxt + prefixes-fix + 4bits-fix + 8bits-fix) + (unsigned-byte-p + bitops::logand-with-negated-bitmask)))) + :rule-classes + ((:rewrite) + (:linear :corollary + (and (< (!prefixes->num x prefixes) #.*2^52*) + (< (!prefixes->lck x prefixes) #.*2^52*) + (< (!prefixes->rep x prefixes) #.*2^52*) + (< (!prefixes->seg x prefixes) #.*2^52*) + (< (!prefixes->opr x prefixes) #.*2^52*) + (< (!prefixes->adr x prefixes) #.*2^52*) + (< (!prefixes->nxt x prefixes) #.*2^52*))))) + + (defthm loghead-ash-0 + (implies (and (natp i) + (natp j) + (natp x) + (<= i j)) + (equal (loghead i (ash x j)) + 0)) + :hints (("Goal" + :in-theory (e/d* (acl2::ihsext-inductions + acl2::ihsext-recursive-redefs) + ())))) + + (local + (defthm signed-byte-p-48-lemma + (implies (signed-byte-p 48 start-rip) + (equal (signed-byte-p 48 (1+ start-rip)) + (< (1+ start-rip) *2^47*))))) + + (local (in-theory (e/d () (unsigned-byte-p))))) + + + (if (mbe :logic (zp cnt) + :exec (eql cnt 0)) + ;; Error, too many prefix bytes --- invalid instruction length. + (mv t prefixes rex-byte x86) + + (b* ((ctx 'get-prefixes) + ((mv flg (the (unsigned-byte 8) byte) x86) + (rme08-opt proc-mode start-rip #.*cs* :x x86)) + ((when flg) + (mv (cons ctx flg) byte rex-byte x86)) + + (prefix-byte-group-code + (the (integer 0 4) (get-one-byte-prefix-array-code byte)))) + + (case prefix-byte-group-code + + (0 + (b* ((rex? (and + (eql proc-mode #.*64-bit-mode*) + (equal (the (unsigned-byte 4) (ash byte -4)) 4))) + ((when rex?) + (mv-let + (flg next-rip) + (add-to-*ip proc-mode start-rip 1 x86) + (if flg + (mv flg prefixes rex-byte x86) + (get-prefixes + proc-mode next-rip prefixes + byte ;; REX prefix, overwriting a previously encountered REX, + ;; if any + (the (integer 0 15) (1- cnt)) + x86))))) + ;; Storing the number of prefixes seen and the first byte + ;; following the prefixes in "prefixes": + (let ((prefixes + (the (unsigned-byte #.*prefixes-width*) + (!prefixes->nxt byte prefixes)))) + (mv nil + (the (unsigned-byte #.*prefixes-width*) + (!prefixes->num (- 15 cnt) prefixes)) + rex-byte ;; Preserving rex-byte + x86)))) + + (1 + ;; LOCK (F0), REPE (F3), REPNE (F2) + (b* (((mv flg next-rip) + (add-to-*ip proc-mode start-rip 1 x86)) + ((when flg) + (mv flg prefixes rex-byte x86)) + ((the (unsigned-byte #.*prefixes-width*) prefixes) + (if (equal byte #.*lock*) + (!prefixes->lck byte prefixes) + (!prefixes->rep byte prefixes)))) + ;; Storing the group 1 prefix (possibly overwriting a + ;; previously seen group 1 prefix) and going on... + (get-prefixes + proc-mode next-rip prefixes + 0 ;; Nullify a previously read REX prefix, if any + (the (integer 0 15) (1- cnt)) x86))) + + (2 + ;; ES (26), CS (2E), SS (36), DS (3E), FS (64), GS (65) + (b* (((mv flg next-rip) + (add-to-*ip proc-mode start-rip 1 x86)) + ((when flg) + (mv flg prefixes rex-byte x86))) + + (if (or + ;; In 64-bit mode, all segment override prefixes except FS + ;; and GS overrides are treated as null prefixes. So a + ;; segment override prefix other than the FS and GS overrides + ;; cannot overshadow a FS/GS override. In case two or more + ;; FS/GS overrides are present, all but the last are ignored. + + ;; Source: XED (https://intelxed.github.io/) + ;; Some tests: + ;; xed -64 -d 260f0100 => sgdt ptr [rax] + ;; xed -64 -d 640f0100 => sgdt ptr fs:[rax] + ;; xed -64 -d 64260f0100 => sgdt ptr fs:[rax] + ;; xed -64 -d 6426650f0100 => sgdt ptr gs:[rax] + (and (eql proc-mode #.*64-bit-mode*) + (or (equal byte #.*fs-override*) + (equal byte #.*gs-override*))) + ;; All segment overrides are active in the 32-bit mode, and + ;; all but the last one are ignored. + (not (eql proc-mode #.*64-bit-mode*))) + + ;; Storing the group 2 prefix (possibly overwriting a + ;; previously seen group 2 prefix) and going on... + + (get-prefixes + proc-mode next-rip + (the (unsigned-byte #.*prefixes-width*) + (!prefixes->seg byte prefixes)) + 0 ;; Nullify a previously read REX prefix, if any + (the (integer 0 15) (1- cnt)) + x86) + + ;; We will be here if we are in the 64-bit mode and have seen a + ;; null segment override prefix; we will not store the prefix + ;; but simply decrement cnt. + (get-prefixes proc-mode next-rip prefixes + 0 ;; Nullify a previously read REX prefix, if any + (the (integer 0 15) (1- cnt)) x86)))) + + (3 + ;; Operand-Size Override (66) + (mv-let + (flg next-rip) + (add-to-*ip proc-mode start-rip 1 x86) + (if flg + (mv flg prefixes rex-byte x86) + ;; Storing the group 3 prefix (possibly overwriting a + ;; previously seen group 3 prefix) and going on... + (get-prefixes + proc-mode next-rip + (the (unsigned-byte #.*prefixes-width*) + (!prefixes->opr byte prefixes)) + 0 ;; Nullify a previously read REX prefix, if any + (the (integer 0 15) (1- cnt)) + x86)))) + + (4 + ;; Address-Size Override (67) + (mv-let + (flg next-rip) + (add-to-*ip proc-mode start-rip 1 x86) + (if flg + (mv flg prefixes rex-byte x86) + ;; Storing the group 4 prefix (possibly overwriting a + ;; previously seen group 4 prefix) and going on... + (get-prefixes + proc-mode next-rip + (the (unsigned-byte #.*prefixes-width*) + (!prefixes->adr byte prefixes)) + 0 ;; Nullify a previously read REX prefix, if any + (the (integer 0 15) (1- cnt)) + x86)))) + + (otherwise + (mv t prefixes rex-byte x86))))) + + /// + + (local (in-theory (e/d () (acl2::zp-open not)))) + + (defthm-unsigned-byte-p prefixes-width-p-of-get-prefixes.new-prefixes + ;; [Shilpi] I tried to use defret here instead of defthm-unsigned-byte-p, but I got + ;; into trouble, probably because of the different order of lambda + ;; expansions in defret. + :hyp (and (unsigned-byte-p #.*prefixes-width* prefixes) + (canonical-address-p start-rip) + (x86p x86)) + :bound #.*prefixes-width* + :concl (mv-nth 1 (get-prefixes + proc-mode start-rip prefixes rex-byte cnt x86)) + :hints (("Goal" + :induct (get-prefixes + proc-mode start-rip prefixes rex-byte cnt x86) + :in-theory (e/d () + (signed-byte-p + acl2::ash-0 + acl2::zip-open + bitops::logtail-of-logior + unsigned-byte-p-of-logtail + acl2::logtail-identity + bitops::logand-with-negated-bitmask + (:linear bitops::logior-<-0-linear-1) + (:linear bitops::logior-<-0-linear-2) + (:linear bitops::logand->=-0-linear-1) + (:linear bitops::logand->=-0-linear-2) + bitops::logtail-natp + natp-of-get-one-byte-prefix-array-code + acl2::ifix-when-not-integerp + ;; bitops::basic-signed-byte-p-of-+ + default-<-1 + force (force))))) + :gen-linear t) + + (defthm-unsigned-byte-p byte-p-of-get-prefixes.new-rex-byte + ;; [Shilpi] I tried to use defret here instead of defthm-unsigned-byte-p, but I got + ;; into trouble, probably because of the different order of lambda + ;; expansions in defret. + :hyp (and (unsigned-byte-p 8 rex-byte) + (natp prefixes) + (x86p x86)) + :bound 8 + :concl (mv-nth 2 (get-prefixes + proc-mode start-rip prefixes rex-byte cnt x86)) + :hints (("Goal" + :induct (get-prefixes + proc-mode start-rip prefixes rex-byte cnt x86) + :in-theory (e/d () + (unsigned-byte-p + signed-byte-p + acl2::ash-0 + acl2::zip-open + bitops::logtail-of-logior + unsigned-byte-p-of-logtail + acl2::logtail-identity + bitops::logand-with-negated-bitmask + (:linear bitops::logior-<-0-linear-1) + (:linear bitops::logior-<-0-linear-2) + (:linear bitops::logand->=-0-linear-1) + (:linear bitops::logand->=-0-linear-2) + bitops::logtail-natp + natp-of-get-one-byte-prefix-array-code + acl2::ifix-when-not-integerp + ;; bitops::basic-signed-byte-p-of-+ + default-<-1 + force (force))))) + :gen-linear t) + + (defret get-prefixes-does-not-modify-x86-state-in-app-view + (implies (app-view x86) + (equal new-x86 x86)) + :hints (("Goal" + :in-theory + (union-theories + '(get-prefixes + rme08-does-not-affect-state-in-app-view) + (theory 'minimal-theory))))) + + (local + (in-theory (e/d + (rme08 rml08 rvm08) + (force + (force) + signed-byte-p-48-lemma + signed-byte-p + bitops::logior-equal-0 + acl2::zp-open + not + (:congruence acl2::int-equiv-implies-equal-logand-2) + (:congruence acl2::int-equiv-implies-equal-loghead-2))))) + + + (defthm num-prefixes-get-prefixes-bound + (implies (and (<= cnt 15) + (x86p x86) + (canonical-address-p start-rip) + (unsigned-byte-p #.*prefixes-width* prefixes) + (< (part-select prefixes :low 0 :high 2) 5)) + (<= + (prefixes->num + (mv-nth + 1 + (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86))) + 15)) + :hints (("Goal" + :induct (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + :in-theory (e/d (rme08 rme08-value-when-error) + (signed-byte-p + unsigned-byte-p rme08 rml08 + (force) force + canonical-address-p + not acl2::zp-open + acl2::ash-0 + acl2::zip-open + bitops::logtail-of-logior + unsigned-byte-p-of-logtail + acl2::logtail-identity + bitops::logand-with-negated-bitmask + (:linear bitops::logior-<-0-linear-1) + (:linear bitops::logior-<-0-linear-2) + (:linear bitops::logand->=-0-linear-1) + (:linear bitops::logand->=-0-linear-2) + bitops::logtail-natp + natp-of-get-one-byte-prefix-array-code + acl2::ifix-when-not-integerp + ;; bitops::basic-signed-byte-p-of-+ + default-<-1)))) + :rule-classes :linear) + + (defthm get-prefixes-opener-lemma-zero-cnt + (implies (zp cnt) + (equal (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (mv t prefixes rex-byte x86))) + :hints (("Goal" :in-theory (e/d (get-prefixes) ())))) + + (local + (defthmd get-prefixes-opener-lemma-no-prefix-byte-pre + ;; Note that this lemma is applicable in the system-level view too. + ;; This lemma would be used for those instructions which do not have + ;; any prefix byte. + (b* (((mv flg byte byte-x86) + (rme08 proc-mode start-rip #.*cs* :x x86)) + (prefix-byte-group-code + (get-one-byte-prefix-array-code byte))) + (implies + (and (not flg) + (zp prefix-byte-group-code) + (not (zp cnt))) + (equal + (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (b* ((rex? (and + (eql proc-mode #.*64-bit-mode*) + (equal (ash byte -4) 4))) + ((when rex?) + (mv-let + (flg next-rip) + (add-to-*ip proc-mode start-rip 1 byte-x86) + (if flg + (mv flg prefixes rex-byte byte-x86) + (get-prefixes + proc-mode next-rip prefixes + byte ;; REX prefix, overwriting a previously encountered REX, + ;; if any + (the (integer 0 15) (1- cnt)) + byte-x86))))) + ;; Storing the number of prefixes seen and the first byte + ;; following the prefixes in "prefixes": + (let ((prefixes + (!prefixes->nxt byte prefixes))) + (mv nil + (!prefixes->num (- 15 cnt) prefixes) + rex-byte ;; Preserving rex-byte + byte-x86)))))) + :hints (("Goal" + :induct + (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + :in-theory (e/d () (unsigned-byte-p)))))) + + (defthm get-prefixes-opener-lemma-no-prefix-byte + ;; This lemma is applicable in all the views of the x86isa model. This + ;; lemma would be used for those instructions which do not have any prefix + ;; byte --- either legacy or rex. + (implies + (b* (((mv flg byte &) + (rme08 proc-mode start-rip #.*cs* :x x86)) + (prefix-byte-group-code + (get-one-byte-prefix-array-code byte))) + (and (not flg) + (zp prefix-byte-group-code) + (if (equal proc-mode #.*64-bit-mode*) + (not (equal (ash byte -4) 4)) + t) + (not (zp cnt)))) + (equal + (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (let ((prefixes + (!prefixes->nxt + (mv-nth 1 (rme08 proc-mode start-rip #.*cs* :x x86)) + prefixes))) + (mv nil + (!prefixes->num (- 15 cnt) prefixes) + rex-byte ;; Preserving rex-byte + (mv-nth 2 (rme08 proc-mode start-rip #.*cs* :x x86)))))) + :hints (("Goal" :in-theory (e/d (get-prefixes-opener-lemma-no-prefix-byte-pre) + (rme08 get-prefixes))))) + + (defthm get-prefixes-opener-lemma-no-legacy-prefix-but-rex-prefix + ;; Note that this lemma is applicable only in 64-bit mode. + ;; This lemma is applicable in all the views of the x86isa model. + (implies + (b* (((mv flg byte &) + (rme08 proc-mode start-rip #.*cs* :x x86)) + (prefix-byte-group-code + (get-one-byte-prefix-array-code byte))) + (and (equal proc-mode #.*64-bit-mode*) + (not flg) + (zp prefix-byte-group-code) + (equal (ash byte -4) 4) + (not (zp cnt)))) + (equal + (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (b* (((mv & byte byte-x86) + (rme08 proc-mode start-rip #.*cs* :x x86)) + ((mv flg next-rip) + (add-to-*ip proc-mode start-rip 1 byte-x86))) + (if flg + (mv flg prefixes rex-byte byte-x86) + (get-prefixes + proc-mode next-rip prefixes + byte ;; REX prefix, overwriting a previously encountered REX, + ;; if any + (1- cnt) + byte-x86))))) + :hints (("Goal" :in-theory (e/d (get-prefixes-opener-lemma-no-prefix-byte-pre) + (rme08 get-prefixes))))) + + (defthm get-prefixes-opener-lemma-group-1-prefix + (b* (((mv flg byte byte-x86) + (rme08 proc-mode start-rip #.*cs* :x x86)) + (prefix-byte-group-code (get-one-byte-prefix-array-code byte))) + (implies + (and (or (app-view x86) + (not (marking-view x86))) + (not flg) ;; No error in reading a byte + (equal prefix-byte-group-code 1) + (not (zp cnt)) + (not (mv-nth 0 (add-to-*ip proc-mode start-rip 1 x86)))) + (equal (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (let ((prefixes + (if (equal byte #.*lock*) + (!prefixes->lck byte prefixes) + (!prefixes->rep byte prefixes)))) + (get-prefixes + proc-mode (1+ start-rip) prefixes 0 (1- cnt) byte-x86))))) + :hints (("Goal" + :in-theory + (e/d* (add-to-*ip) + (rb + unsigned-byte-p + negative-logand-to-positive-logand-with-integerp-x))))) + + (defthm get-prefixes-opener-lemma-group-2-prefix + (b* (((mv flg byte byte-x86) + (rme08 proc-mode start-rip #.*cs* :x x86)) + (prefix-byte-group-code + (get-one-byte-prefix-array-code + byte))) + (implies + (and (or (app-view x86) + (and (not (app-view x86)) + (not (marking-view x86)))) + (not flg) ;; No error in reading a byte + (equal prefix-byte-group-code 2) + (not (zp cnt)) + (not (mv-nth 0 (add-to-*ip proc-mode start-rip 1 x86)))) + (equal (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (if (or + (and (eql proc-mode #.*64-bit-mode*) + (or (equal byte #.*fs-override*) + (equal byte #.*gs-override*))) + (not (eql proc-mode #.*64-bit-mode*))) + (get-prefixes proc-mode (1+ start-rip) + (!prefixes->seg byte prefixes) + 0 + (1- cnt) byte-x86) + (get-prefixes + proc-mode (1+ start-rip) prefixes 0 (1- cnt) byte-x86))))) + :hints (("Goal" + :in-theory + (e/d* (add-to-*ip) + (rb + unsigned-byte-p + negative-logand-to-positive-logand-with-integerp-x))))) + + (defthm get-prefixes-opener-lemma-group-3-prefix + (b* (((mv flg byte x862) (rme08 proc-mode start-rip #.*cs* :x x86)) + (prefix-byte-group-code (get-one-byte-prefix-array-code byte))) + (implies (and (not flg) ;; No error in reading a byte + (equal prefix-byte-group-code 3) + (not (zp cnt)) + (not (mv-nth 0 (add-to-*ip proc-mode start-rip 1 x862)))) + (equal (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (get-prefixes proc-mode (1+ start-rip) + (!prefixes->opr byte prefixes) + 0 + (1- cnt) x862)))) + :hints (("Goal" + :in-theory + (e/d* (add-to-*ip) + (rb + unsigned-byte-p + negative-logand-to-positive-logand-with-integerp-x))))) + + (defthm get-prefixes-opener-lemma-group-4-prefix + (b* (((mv flg byte x862) (rme08 proc-mode start-rip #.*cs* :x x86)) + (prefix-byte-group-code (get-one-byte-prefix-array-code byte))) + (implies (and (not flg) ;; No error in reading a byte + (equal prefix-byte-group-code 4) + (not (zp cnt)) + (not (mv-nth 0 (add-to-*ip proc-mode start-rip 1 x862)))) + (equal (get-prefixes proc-mode start-rip prefixes rex-byte cnt x86) + (get-prefixes proc-mode (1+ start-rip) + (!prefixes->adr + byte + prefixes) + 0 + (1- cnt) x862)))) + :hints (("Goal" + :in-theory + (e/d* (add-to-*ip) + (rb + unsigned-byte-p + negative-logand-to-positive-logand-with-integerp-x))))) + + (local + (defret xr-msr-and-seg-hidden-of-get-prefixes-in-app-view + (implies (app-view x86) + (and + (equal (xr :msr idx new-x86) + (xr :msr idx x86)) + (equal (xr :seg-hidden-base idx new-x86) + (xr :seg-hidden-base idx x86)) + (equal (xr :seg-hidden-limit idx new-x86) + (xr :seg-hidden-limit idx x86)) + (equal (xr :seg-hidden-attr idx new-x86) + (xr :seg-hidden-attr idx x86)))) + :hints (("Goal" + :in-theory (e/d () (las-to-pas rb rme08 rml08)))))) + + (local + (defret xr-msr-of-get-prefixes-in-sys-view + (implies (not (app-view x86)) + (and + (equal (xr :msr idx new-x86) + (xr :msr idx x86)) + (equal (xr :seg-hidden-base idx new-x86) + (xr :seg-hidden-base idx x86)) + (equal (xr :seg-hidden-limit idx new-x86) + (xr :seg-hidden-limit idx x86)) + (equal (xr :seg-hidden-attr idx new-x86) + (xr :seg-hidden-attr idx x86)))) + :hints (("Goal" + :induct + :in-theory (e/d () + (unsigned-byte-p get-prefixes-opener-lemma-group-4-prefix + get-prefixes-opener-lemma-group-3-prefix + las-to-pas rb rme08 rml08)))))) + + (local + (defret xr-msr-of-get-prefixes + (and + (equal (xr :msr idx new-x86) + (xr :msr idx x86)) + (equal (xr :seg-hidden-base idx new-x86) + (xr :seg-hidden-base idx x86)) + (equal (xr :seg-hidden-limit idx new-x86) + (xr :seg-hidden-limit idx x86)) + (equal (xr :seg-hidden-attr idx new-x86) + (xr :seg-hidden-attr idx x86))) + :hints (("Goal" + :cases ((app-view x86)) + :do-not-induct t + :in-theory (e/d () (get-prefixes las-to-pas rb rme08 rml08)))))) + + (defret 64-bit-modep-of-get-prefixes + (equal (64-bit-modep new-x86) + (64-bit-modep x86)) + :hints (("Goal" + :do-not-induct t + :in-theory (e/d (64-bit-modep) ())))) + + (defret x86-operation-mode-of-get-prefixes + (equal (x86-operation-mode new-x86) + (x86-operation-mode x86)) + :hints (("Goal" :in-theory (e/d (x86-operation-mode) (get-prefixes)))))) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/guard-helpers.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/guard-helpers.lisp new file mode 100644 index 000000000..aaa754285 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/guard-helpers.lisp @@ -0,0 +1,541 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +;; We will always include this book locally. + +(in-package "X86ISA") + +(include-book "../utils/utilities") +(include-book "../portcullis/utils") +(include-book "../utils/segmentation-structures") +(include-book "tools/rulesets" :dir :system) +(include-book "centaur/bitops/ihs-extensions" :dir :system) +(include-book "centaur/gl/defthm-using-gl" :dir :system) + +(local (include-book "centaur/gl/gl" :dir :system)) + +;; ====================================================================== + +;; Various lemmas for the guard proofs of rm* functions + +;; (defthm-using-gl rml16-guard-proof-helper +;; :hyp (and (n08p a) +;; (n08p b)) +;; :concl (< (logior a (ash b 8)) *2^16*) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8))) +;; :rule-classes :linear) + +;; (defthm-using-gl rb-and-rvm32-helper +;; :hyp (and (n08p a) +;; (n08p b) +;; (n16p c)) +;; :concl (equal (logior a (ash b 8) (ash c 16)) +;; (logior a (ash (logior b (ash c 8)) 8))) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8)) (:nat c 16)) +;; :rule-classes :linear) + +;; (defthm-using-gl rml32-guard-proof-helper +;; :hyp (and (n08p a) +;; (n08p b) +;; (n08p c) +;; (n08p d)) +;; :concl (< +;; (logior a +;; (ash (logior b +;; (ash (logior c (ash d 8)) 8)) +;; 8)) +;; *2^32*) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8) (:nat c 8) (:nat d 8))) +;; :rule-classes :linear) + +;; (defthm-using-gl rml48-guard-proof-helper +;; :hyp (and (n08p a) (n08p b) (n32p c)) +;; :concl (equal (logior a (ash b 8) (ash c 16)) +;; (logior a (ash (logior b (ash c 8)) 8))) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 32) (:nat b 32) (:nat c 32))) +;; :rule-classes :linear) + +;; (defthm-using-gl rb-and-rml48-helper-1 +;; :hyp (and (n08p a) (n08p b) (n08p c) (n08p d) +;; (n08p e) (n08p f)) +;; :concl (equal (logior +;; a +;; (ash (logior +;; b +;; (ash (logior +;; c +;; (ash (logior +;; d (ash (logior e (ash f 8)) 8)) 8)) 8)) 8)) +;; (logior +;; a +;; (ash b 8) +;; (ash (logior +;; c +;; (ash (logior d (ash (logior e (ash f 8)) 8)) +;; 8)) 16))) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8) (:nat c 8) (:nat d 8) +;; (:nat e 8) (:nat f 8)))) + +;; (defthm-using-gl rb-and-rml48-helper-2 +;; :hyp (and (n08p a) (n08p b) (n08p c) (n08p d) +;; (n08p e) (n08p f)) +;; :concl (< +;; (logior +;; a +;; (ash b 8) +;; (ash (logior +;; c +;; (ash (logior d (ash (logior e (ash f 8)) 8)) +;; 8)) 16)) +;; #.*2^48*) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8) (:nat c 8) (:nat d 8) +;; (:nat e 8) (:nat f 8)))) + +;; (defthm-using-gl rb-and-rvm64-helper +;; :hyp (and (n08p a) (n08p b) (n08p c) (n08p d) +;; (n08p e) (n08p f) (n08p g) (n08p h)) +;; :concl (equal +;; (logior a (ash b 8) +;; (ash (logior c (ash d 8)) 16) +;; (ash (logior e (ash f 8) (ash (logior g (ash h 8)) 16)) 32)) +;; (logior a +;; (ash (logior +;; b +;; (ash (logior +;; c +;; (ash (logior +;; d +;; (ash (logior +;; e +;; (ash (logior f (ash (logior g (ash h 8)) 8)) 8)) 8)) 8)) +;; 8)) +;; 8))) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8) (:nat c 8) (:nat d 8) +;; (:nat e 8) (:nat f 8) (:nat g 8) (:nat h 8)))) + +;; (defthm-using-gl rml64-guard-proof-helper +;; :hyp (and (n32p a) (n32p b)) +;; :concl (< (logior a (ash b 32)) *2^64*) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 32) (:nat b 32))) +;; :rule-classes :linear) + +;; (defthm-using-gl rml80-guard-proof-helper +;; :hyp (and (n08p a) (n08p b) (n64p c)) +;; :concl (equal (logior a (ash b 8) (ash c 16)) +;; (logior a (ash (logior b (ash c 8)) 8))) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 64) (:nat b 64) (:nat c 64))) +;; :rule-classes :linear) + +;; (defthm-using-gl rml80-in-sys-view-guard-proof-helper +;; :hyp (and (n08p a) (n08p b) (n08p c) (n08p d) (n08p e) +;; (n08p f) (n08p g) (n08p h) (n08p i) (n08p j)) +;; :concl (< +;; (logior a +;; (ash b 8) +;; (ash (logior +;; c +;; (ash +;; (logior +;; d +;; (ash +;; (logior +;; e +;; (ash +;; (logior +;; f +;; (ash +;; (logior g +;; (ash (logior +;; h (ash +;; (logior i (ash j 8)) +;; 8)) 8)) 8)) 8)) 8)) 8)) 16)) +;; *2^80*) +;; :g-bindings (gl::auto-bindings +;; (:mix (:nat a 8) +;; (:nat b 8) +;; (:nat c 8) +;; (:nat d 8) +;; (:nat e 8) +;; (:nat f 8) +;; (:nat g 8) +;; (:nat h 8) +;; (:nat i 8) +;; (:nat j 8)))) + +;; (in-theory (e/d () +;; (rml16-guard-proof-helper +;; rml48-guard-proof-helper +;; rb-and-rml48-helper-1 +;; rb-and-rml48-helper-2 +;; rb-and-rvm32-helper +;; rml32-guard-proof-helper +;; rb-and-rvm64-helper +;; rml64-guard-proof-helper +;; rml80-in-sys-view-guard-proof-helper +;; ))) + +;; (defthm-using-gl rml32-rb-sys-view-proof-helper +;; :hyp (and (n08p a) +;; (n08p b) +;; (n08p c) +;; (n08p d)) +;; :concl (equal (logior a (ash b 8) (ash (logior c (ash d 8)) 16)) +;; (logior a (ash (logior b (ash (logior c (ash d 8)) 8)) 8))) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8) (:nat c 8) (:nat d 8)))) + +;; ;; (defthm-using-gl rml64-in-sys-view-guard-proof-helper +;; ;; :hyp (and (n08p a) +;; ;; (n08p b) +;; ;; (n08p c) +;; ;; (n08p d) +;; ;; (n08p e) +;; ;; (n08p f) +;; ;; (n08p g) +;; ;; (n08p h)) +;; ;; :concl (< (logior a +;; ;; (ash b 8) +;; ;; (ash (logior c (ash d 8)) 16) +;; ;; (ash (logior +;; ;; e (ash f 8) +;; ;; (ash (logior g (ash h 8)) 16)) 32)) +;; ;; *2^64*) +;; ;; :g-bindings (gl::auto-bindings +;; ;; (:mix (:nat a 8) +;; ;; (:nat b 8) +;; ;; (:nat c 8) +;; ;; (:nat d 8) +;; ;; (:nat e 8) +;; ;; (:nat f 8) +;; ;; (:nat g 8) +;; ;; (:nat h 8)))) + +;; (defthm-using-gl rml64-to-rb-in-sys-view-helper +;; :hyp (and (n08p a) (n08p b) (n08p c) (n08p d) +;; (n08p e) (n08p f) (n08p g) (n08p h)) +;; :concl (equal +;; (logior a +;; (ash (logior b (ash (logior c (ash d 8)) 8)) 8) +;; (ash (logior e (ash (logior f (ash (logior g (ash h 8)) 8)) 8)) 32)) +;; (logior +;; a +;; (ash (logior +;; b +;; (ash (logior +;; c +;; (ash (logior d +;; (ash +;; (logior e +;; (ash +;; (logior f +;; (ash (logior g (ash h 8)) 8)) 8)) 8)) 8)) 8)) 8))) +;; :g-bindings +;; (gl::auto-bindings +;; (:mix (:nat a 8) (:nat b 8) (:nat c 8) (:nat d 8) +;; (:nat e 8) (:nat f 8) (:nat g 8) (:nat h 8)))) + +;; (defthm-using-gl rml64-in-sys-view-guard-proof-helper +;; :hyp (and (n08p a) +;; (n08p b) +;; (n08p c) +;; (n08p d) +;; (n08p e) +;; (n08p f) +;; (n08p g) +;; (n08p h)) +;; :concl (< (logior +;; a +;; (ash (logior +;; b +;; (ash (logior +;; c +;; (ash (logior d +;; (ash +;; (logior e +;; (ash +;; (logior f +;; (ash (logior g (ash h 8)) 8)) 8)) 8)) 8)) 8)) 8)) +;; *2^64*) +;; :g-bindings (gl::auto-bindings +;; (:mix (:nat a 8) +;; (:nat b 8) +;; (:nat c 8) +;; (:nat d 8) +;; (:nat e 8) +;; (:nat f 8) +;; (:nat g 8) +;; (:nat h 8)))) + +;; ====================================================================== + +;; The following theorems are used in instructions/*-instructions.lisp +;; books. + +;; Far Jump: + +(defthm-using-gl far-jmp-conforming-code-segment-guard-helper-1 + :hyp (unsigned-byte-p 16 val16) + :concl (equal (bitops::logsquash 2 val16) + (logand 65532 val16)) + :g-bindings (gl::auto-bindings + (:nat val16 16))) + +(defthm-using-gl far-jmp-conforming-code-segment-guard-helper-2 + :hyp (unsigned-byte-p 16 val16) + :concl (equal (logand -79228162495817593519834398721 (ash val16 96)) + (logand 5192217630372331810936976494821375 (ash val16 96))) + :g-bindings (gl::auto-bindings + (:nat val16 16))) + + +(defthm-using-gl far-jmp-non-conforming-code-segment-guard-helper-3 + :hyp (and (unsigned-byte-p 80 n80) + (unsigned-byte-p 64 n64) + (unsigned-byte-p 16 n16)) + :concl (equal + (logior n64 + (ash (logtail 64 n80) 64) + (logand 5192217630372313364192902785269760 (ash n16 96))) + (logior + n64 + (logand 5192296858534809181786422619668480 + (logior (ash (logtail 64 n80) 64) + (logand 5192217630372331810936976494821375 (ash n16 96)))))) + :g-bindings (gl::auto-bindings + (:mix (:nat n80 80) + (:nat n64 80) + (:nat n16 80)))) + + +(defthm-using-gl far-jmp-call-gate-guard-helper-4 + :hyp (and (unsigned-byte-p 64 n64) + (unsigned-byte-p 48 n48) + (unsigned-byte-p 16 n16)) + :concl (equal + (logior n64 (ash (loghead 32 n48) 64) + (logand 5192217630372313364192902785269760 (ash n16 96))) + (logior + n64 + (logand + 5192296858534809181786422619668480 + (logior + (ash (loghead 32 n48) 64) + (logand 5192217630372331810936976494821375 (ash n16 96)))))) + :g-bindings (gl::auto-bindings + (:mix (:nat n48 64) + (:nat n64 64) + (:nat n16 64)))) + +(defthm-using-gl far-jmp-call-gate-guard-helper-5 + :hyp (call-gate-descriptorbits-p z) + :concl (equal + (logand #xFFFFFFFF00000000 (ash (call-gate-descriptorbits->offset63-32 z) 32)) + (ash (call-gate-descriptorbits->offset63-32 z) 32)) + :g-bindings (gl::auto-bindings (:nat z 128))) + +(defthm-using-gl far-jmp-call-gate-guard-helper-6 + :hyp (unsigned-byte-p 16 x) + :concl (equal (logand #xffff0000 (ash x 16)) + (ash x 16)) + :g-bindings (gl::auto-bindings (:nat x 16))) + +(defthm-using-gl far-jmp-call-gate-guard-helper-7 + :hyp (and (unsigned-byte-p 32 call-gate-descriptorbits->offset63-32) + (unsigned-byte-p 16 call-gate-descriptorbits->offset31-16) + (unsigned-byte-p 16 call-gate-descriptorbits->offset15-0)) + :concl (equal + (logior + (ash + call-gate-descriptorbits->offset31-16 + 16) + (loghead + 32 + call-gate-descriptorbits->offset15-0) + (logand + 18446744069414584320 + (ash + call-gate-descriptorbits->offset63-32 + 32))) + (logior + call-gate-descriptorbits->offset15-0 + (ash + call-gate-descriptorbits->offset31-16 + 16) + (ash + call-gate-descriptorbits->offset63-32 + 32))) + :g-bindings (gl::auto-bindings (:mix (:nat call-gate-descriptorbits->offset15-0 32) + (:nat call-gate-descriptorbits->offset31-16 32) + (:nat call-gate-descriptorbits->offset63-32 32)))) + +(def-ruleset far-jump-guard-helpers + '(far-jmp-conforming-code-segment-guard-helper-1 + far-jmp-conforming-code-segment-guard-helper-2 + far-jmp-non-conforming-code-segment-guard-helper-3 + far-jmp-call-gate-guard-helper-4 + far-jmp-call-gate-guard-helper-5)) + +;; ====================================================================== + +;; LLDT guard helpers: + +(defthm-using-gl x86-lldt-guard-helper-1 + :hyp (unsigned-byte-p 16 y) + :concl (equal (logand -79228162495817593519834398721 (ash y 96)) + (ash y 96)) + :g-bindings `((y (:g-number ,(increasing-list 0 1 17)))) + :rule-classes (:rewrite :linear)) + +(defthm-using-gl x86-lldt-guard-helper-2 + :hyp (and (unsigned-byte-p 128 n128) + (unsigned-byte-p 16 n16)) + :concl (equal + (logior + (loghead 16 (logtail 16 n128)) + (ash (loghead 8 (logtail 32 n128)) 16) + (logand 5192217630372313364192902785269760 (ash n16 96)) + (ash + (logior (loghead 16 n128) + (ash (loghead 4 (logtail 48 n128)) 16)) + 64) + (ash + (logior (loghead 8 (logtail 56 n128)) + (ash (loghead 32 (logtail 64 n128)) 8)) + 24)) + (logior (loghead 16 (logtail 16 n128)) + (ash (loghead 8 (logtail 32 n128)) 16) + (ash + (logior (loghead 8 (logtail 56 n128)) + (ash (loghead 32 (logtail 64 n128)) 8)) + 24) + (logand + 5192296858534809181786422619668480 + (logior + (logand 5192217630372331810936976494821375 (ash n16 96)) + (ash (logior (loghead 16 n128) + (ash (loghead 4 (logtail 48 n128)) + 16)) 64))))) + :g-bindings (gl::auto-bindings + (:mix (:nat n128 128) + (:nat n16 128)))) + +(defthm-using-gl x86-lldt-guard-helper-3 + :hyp (and (unsigned-byte-p 128 n128) + (unsigned-byte-p 16 n16)) + :concl (equal + (logior + (ash n16 96) + (ash + (logior (loghead 16 n128) + (ash (loghead 4 (logtail 48 n128)) + 16)) + 64)) + (logior + (logand + 5192217630372331810936976494821375 (ash n16 96)) + (ash + (logior (loghead 16 n128) + (ash (loghead 4 (logtail 48 n128)) + 16)) + 64))) + :g-bindings (gl::auto-bindings + (:mix (:nat n128 128) + (:nat n16 128)))) + +(def-ruleset lldt-guard-helpers + '(x86-lldt-guard-helper-1 + x86-lldt-guard-helper-2 + x86-lldt-guard-helper-3)) + +;; ====================================================================== + +;; SYSRET: + +(defthm-using-gl x86-sysret-guard-helper-1 + :hyp (unsigned-byte-p 16 seg-visiblei) + :concl (equal (bitops::logsquash 2 seg-visiblei) + (logand 65532 seg-visiblei)) + :g-bindings (gl::auto-bindings + (:nat seg-visiblei 16))) + + +(defthm-using-gl x86-sysret-guard-helper-2 + :hyp (unsigned-byte-p 64 msri) + :concl (and + (equal (logior 3 (+ 16 (logtail 48 msri))) + (logior 3 + (bitops::logsquash + 2 + (+ 16 (logtail 48 msri))))) + (equal (logior 3 (+ 8 (logtail 48 msri))) + (logior 3 + (bitops::logsquash 2 (+ 8 (logtail 48 msri)))))) + :g-bindings (gl::auto-bindings + (:nat msri 64))) + +(def-ruleset sysret-guard-helpers + '(x86-sysret-guard-helper-1 + x86-sysret-guard-helper-2)) + +;; ====================================================================== + +(in-theory (e/d* () + (far-jump-guard-helpers + lldt-guard-helpers + sysret-guard-helpers))) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-listing.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-listing.lisp new file mode 100644 index 000000000..40a36588d --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-listing.lisp @@ -0,0 +1,21961 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2019, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "inst-structs") +(include-book "std/strings/pretty" :dir :system) + +(defsection opcode-maps + :parents (instructions x86-decoder) + :short "ACL2 representation of x86 Opcode Maps (see Intel Manuals, Vol. 2, + Appendix A)") + + +(local (xdoc::set-default-parents 'opcode-maps)) + +;; ---------------------------------------------------------------------- + +;; TODO document the format of this +;; (see also ``create-dispatch-for-opcodes'' in ".../machine/dispatch-creator.lisp") + +(defconst *pre-one-byte-opcode-map* + '((INST "ADD" (OP :OP #x0) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x0)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADD" (OP :OP #x1) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x0)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADD" (OP :OP #x2) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x0)) + '((:UD (UD-LOCK-USED)))) + (INST "ADD" (OP :OP #x3) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x0)) + '((:UD (UD-LOCK-USED)))) + (INST "ADD" (OP :OP #x4) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x0)) + '((:UD (UD-LOCK-USED)))) + (INST "ADD" (OP :OP #x5) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x0)) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH ES" (OP :OP #x6 :MODE :I64) + NIL '(X86-PUSH-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x6 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "PUSH ES is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "POP ES" (OP :OP #x7 :MODE :I64) + NIL + '(X86-POP-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x7 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "POP ES is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "OR" (OP :OP #x8) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x1)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "OR" (OP :OP #x9) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x1)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "OR" (OP :OP #xA) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x1)) + '((:UD (UD-LOCK-USED)))) + (INST "OR" (OP :OP #xB) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x1)) + '((:UD (UD-LOCK-USED)))) + (INST "OR" (OP :OP #xC) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x1)) + '((:UD (UD-LOCK-USED)))) + (INST "OR" (OP :OP #xD) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x1)) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH CS" (OP :OP #xE :MODE :I64) + NIL '(X86-PUSH-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #xE :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "PUSH CS is illegal in the 64-bit mode!")) + '((:UD T))) + (INST :2-BYTE-ESCAPE (OP :OP #xF) + 'NIL + '(TWO-BYTE-OPCODE-DECODE-AND-EXECUTE (ESCAPE-BYTE . OPCODE)) + 'NIL) + (INST "ADC" (OP :OP #x10) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x2)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADC" (OP :OP #x11) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x2)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADC" (OP :OP #x12) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x2)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADC" (OP :OP #x13) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x2)) + '((:UD (UD-LOCK-USED)))) + (INST "ADC" (OP :OP #x14) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x2)) + '((:UD (UD-LOCK-USED)))) + (INST "ADC" (OP :OP #x15) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x2)) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH SS" (OP :OP #x16 :MODE :I64) + NIL '(X86-PUSH-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x16 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "PUSH SS is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "POP SS" (OP :OP #x17 :MODE :I64) + NIL + '(X86-POP-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x17 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "POP SS is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "SBB" (OP :OP #x18) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x6)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SBB" (OP :OP #x19) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x6)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SBB" (OP :OP #x1A) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x6)) + '((:UD (UD-LOCK-USED)))) + (INST "SBB" (OP :OP #x1B) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x6)) + '((:UD (UD-LOCK-USED)))) + (INST "SBB" (OP :OP #x1C) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x6)) + '((:UD (UD-LOCK-USED)))) + (INST "SBB" (OP :OP #x1D) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x6)) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH DS" (OP :OP #x1E :MODE :I64) + NIL '(X86-PUSH-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x1E :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "PUSH DS is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "POP DS" (OP :OP #x1F :MODE :I64) + NIL + '(X86-POP-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x1F :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "POP DS is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "AND" (OP :OP #x20) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x3)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "AND" (OP :OP #x21) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x3)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "AND" (OP :OP #x22) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x3)) + '((:UD (UD-LOCK-USED)))) + (INST "AND" (OP :OP #x23) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x3)) + '((:UD (UD-LOCK-USED)))) + (INST "AND" (OP :OP #x24) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x3)) + '((:UD (UD-LOCK-USED)))) + (INST "AND" (OP :OP #x25) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x3)) + '((:UD (UD-LOCK-USED)))) + (INST :PREFIX-ES (OP :OP #x26) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DAA" (OP :OP #x27 :MODE :I64) + NIL + '(X86-DAA) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #x27 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "DAA is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "SUB" (OP :OP #x28) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x4)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SUB" (OP :OP #x29) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x4)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SUB" (OP :OP #x2A) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x4)) + '((:UD (UD-LOCK-USED)))) + (INST "SUB" (OP :OP #x2B) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x4)) + '((:UD (UD-LOCK-USED)))) + (INST "SUB" (OP :OP #x2C) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x4)) + '((:UD (UD-LOCK-USED)))) + (INST "SUB" (OP :OP #x2D) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x4)) + '((:UD (UD-LOCK-USED)))) + (INST :PREFIX-CS (OP :OP #x2E) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DAS" (OP :OP #x2F :MODE :I64) + NIL + '(X86-DAS) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #x2F :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "DAS is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "XOR" (OP :OP #x30) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x5)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XOR" (OP :OP #x31) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x5)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XOR" (OP :OP #x32) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x5)) + '((:UD (UD-LOCK-USED)))) + (INST "XOR" (OP :OP #x33) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x5)) + '((:UD (UD-LOCK-USED)))) + (INST "XOR" (OP :OP #x34) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x5)) + '((:UD (UD-LOCK-USED)))) + (INST "XOR" (OP :OP #x35) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x5)) + '((:UD (UD-LOCK-USED)))) + (INST :PREFIX-SS (OP :OP #x36) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "AAA" (OP :OP #x37 :MODE :I64) + NIL + '(X86-AAA) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #x37 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "AAA is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "CMP" (OP :OP #x38) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "CMP" (OP :OP #x39) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "CMP" (OP :OP #x3A) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "CMP" (OP :OP #x3B) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "CMP" (OP :OP #x3C) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "CMP" (OP :OP #x3D) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST :PREFIX-DS (OP :OP #x3E) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "AAS" (OP :OP #x3F :MODE :I64) + NIL + '(X86-AAS) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #x3F :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "AAS is illegal in the 64-bit mode!")) + '((:UD T))) + (INST :REX (OP :OP #x40 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x40 :MODE :I64) + (ARG :OP1 '(:EAX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-B (OP :OP #x41 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x41 :MODE :I64) + (ARG :OP1 '(:ECX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-X (OP :OP #x42 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x42 :MODE :I64) + (ARG :OP1 '(:EDX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-XB (OP :OP #x43 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x43 :MODE :I64) + (ARG :OP1 '(:EBX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-R (OP :OP #x44 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x44 :MODE :I64) + (ARG :OP1 '(:ESP)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-RB (OP :OP #x45 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x45 :MODE :I64) + (ARG :OP1 '(:EBP)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-RX (OP :OP #x46 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x46 :MODE :I64) + (ARG :OP1 '(:ESI)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-RXB (OP :OP #x47 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INC" (OP :OP #x47 :MODE :I64) + (ARG :OP1 '(:EDI)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-W (OP :OP #x48 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x48 :MODE :I64) + (ARG :OP1 '(:EAX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-WB (OP :OP #x49 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x49 :MODE :I64) + (ARG :OP1 '(:ECX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-WX (OP :OP #x4A :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x4A :MODE :I64) + (ARG :OP1 '(:EDX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-WXB (OP :OP #x4B :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x4B :MODE :I64) + (ARG :OP1 '(:EBX)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-WR (OP :OP #x4C :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x4C :MODE :I64) + (ARG :OP1 '(:ESP)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-WRB (OP :OP #x4D :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x4D :MODE :I64) + (ARG :OP1 '(:EBP)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-WRX (OP :OP #x4E :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x4E :MODE :I64) + (ARG :OP1 '(:ESI)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST :REX-WRXB (OP :OP #x4F :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "DEC" (OP :OP #x4F :MODE :I64) + (ARG :OP1 '(:EDI)) + '(X86-INC/DEC-4X) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x50 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RAX/R8)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x51 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RCX/R9)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x52 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RDX/R10)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x53 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RBX/R11)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x54 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RSP/R11)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x55 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RBP/R13)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x56 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RSI/R14)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x57 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RDI/R15)) + '(X86-PUSH-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x58 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RAX/R8)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x59 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RCX/R9)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x5A :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RDX/R10)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x5B :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RBX/R11)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x5C :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RSP/R11)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x5D :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RBP/R13)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x5E :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RSI/R14)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x5F :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:RDI/R15)) + '(X86-POP-GENERAL-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "PUSHA/PUSHAD" (OP :OP #x60 :MODE :I64) + NIL '(X86-PUSHA) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #x60 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . + "PUSHA is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "POPA/POPAD" (OP :OP #x61 :MODE :I64) + NIL '(X86-POPA) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #x61 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . + "POPA is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "BOUND" (OP :OP #x62 :MODE :I64) + (ARG :OP1 '(G V) :OP2 '(M A)) + 'NIL + '((:UD (UD-LOCK-USED) + (UD-SECOND-OPERAND-IS-A-REGISTER)))) + (INST :EVEX-BYTE0 (OP :OP #x62 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "MOVSXD" (OP :OP #x63 :MODE :O64) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-MOVSXD) + '((:UD (UD-LOCK-USED)))) + (INST "ARPL" (OP :OP #x63 :MODE :I64) + (ARG :OP1 '(E W) :OP2 '(G W)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST :PREFIX-FS (OP :OP #x64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST :PREFIX-GS (OP :OP #x65) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST :PREFIX-OPSIZE (OP :OP #x66) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST :PREFIX-ADDRSIZE (OP :OP #x67) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "PUSH" + (OP :OP #x68 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(I Z)) + '(X86-PUSH-I) + '((:UD (UD-LOCK-USED)))) + (INST "IMUL" (OP :OP #x69) + (ARG :OP1 '(G V) + :OP2 '(E V) + :OP3 '(I Z)) + '(X86-IMUL-OP/EN-RMI) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #x6A :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(I B)) + '(X86-PUSH-I) + '((:UD (UD-LOCK-USED)))) + (INST "IMUL" (OP :OP #x6B) + (ARG :OP1 '(G V) + :OP2 '(E V) + :OP3 '(I B)) + '(X86-IMUL-OP/EN-RMI) + '((:UD (UD-LOCK-USED)))) + (INST "INS/INSB" (OP :OP #x6C) + (ARG :OP1 '(Y B) :OP2 '(:DX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "INS/INSW/INSD" (OP :OP #x6D) + (ARG :OP1 '(Y Z) :OP2 '(:DX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "OUTS/OUTSB" (OP :OP #x6E) + (ARG :OP1 '(Y B) :OP2 '(:DX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "OUTS/OUTSW/OUTSD" (OP :OP #x6F) + (ARG :OP1 '(Y Z) :OP2 '(:DX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "JO" + (OP :OP #x70 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNO" + (OP :OP #x71 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JB/NAE/C" + (OP :OP #x72 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNB/AE/NC" + (OP :OP #x73 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JZ/E" + (OP :OP #x74 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNZ/NE" + (OP :OP #x75 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JBE/NA" + (OP :OP #x76 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNBE/A" + (OP :OP #x77 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JS" + (OP :OP #x78 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNS" + (OP :OP #x79 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JP/PE" + (OP :OP #x7A :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNP/PO" + (OP :OP #x7B :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JL/NGE" + (OP :OP #x7C :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNL/GE" + (OP :OP #x7D :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JLE/NG" + (OP :OP #x7E :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNLE/G" + (OP :OP #x7F :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-ONE-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "ADD" + (OP :OP #x80 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x0)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "OR" + (OP :OP #x80 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x1)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADC" + (OP :OP #x80 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x2)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SBB" + (OP :OP #x80 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x6)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "AND" + (OP :OP #x80 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x3)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SUB" + (OP :OP #x80 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x4)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XOR" + (OP :OP #x80 + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x5)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "CMP" + (OP :OP #x80 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "ADD" + (OP :OP #x81 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x0)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "OR" + (OP :OP #x81 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x1)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADC" + (OP :OP #x81 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x2)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SBB" + (OP :OP #x81 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x6)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "AND" + (OP :OP #x81 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x3)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SUB" + (OP :OP #x81 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x4)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XOR" + (OP :OP #x81 + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x5)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "CMP" + (OP :OP #x81 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "ADD" + (OP :OP #x82 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x0)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "OR" + (OP :OP #x82 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x1)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADC" + (OP :OP #x82 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x2)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SBB" + (OP :OP #x82 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x6)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "AND" + (OP :OP #x82 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x3)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SUB" + (OP :OP #x82 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x4)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XOR" + (OP :OP #x82 + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x5)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "CMP" + (OP :OP #x82 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1) + :MODE :I64) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x82 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "Opcode 0x82 is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "ADD" + (OP :OP #x83 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x0)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "OR" + (OP :OP #x83 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x1)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "ADC" + (OP :OP #x83 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x2)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SBB" + (OP :OP #x83 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x6)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "AND" + (OP :OP #x83 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x3)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SUB" + (OP :OP #x83 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x4)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XOR" + (OP :OP #x83 + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x5)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "CMP" + (OP :OP #x83 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-1)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x8)) + '((:UD (UD-LOCK-USED)))) + (INST "TEST" (OP :OP #x84) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x7)) + '((:UD (UD-LOCK-USED)))) + (INST "TEST" (OP :OP #x85) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #x7)) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x86) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XCHG" (OP :OP #x87) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "MOV" (OP :OP #x88) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-MOV-OP/EN-MR) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #x89) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-MOV-OP/EN-MR) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #x8A) + (ARG :OP1 '(G B) :OP2 '(E B)) + '(X86-MOV-OP/EN-RM) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #x8B) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-MOV-OP/EN-RM) + '((:UD (UD-LOCK-USED)))) + ;; TODO: For (S w) operands, sensible modr/m.reg values are 0-5 + ;; because there are 6 segment registers. Will these + ;; instructions #UD when modr/m.reg = 6 or 7? E.g., when modr/m + ;; is #x30 or #x38. + (INST "MOV" (OP :OP #x8C) + (ARG :OP1 '(E V) :OP2 '(S W)) + '(X86-MOV-OP/EN-MR) + '((:UD (UD-LOCK-USED)))) + (INST "LEA" (OP :OP #x8D) + (ARG :OP1 '(G V) :OP2 '(M)) + '(X86-LEA) + '((:UD (UD-SOURCE-OPERAND-IS-A-REGISTER) + (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #x8E) + (ARG :OP1 '(S W) :OP2 '(E W)) + '(X86-MOV-OP/EN-RM) + '((:UD (EQUAL (MODR/M->REG MODR/M) #x1) + (UD-LOCK-USED)))) + (INST "POP" + (OP :OP #x8F + :REG #x0 + :SUPERSCRIPTS '(:1A :D64) + :GROUP '(:GROUP-1A)) + (ARG :OP1 '(E V)) + '(X86-POP-EV) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x90) + (ARG :OP1 '(:R8)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x91) + (ARG :OP1 '(:RCX/R9) :OP2 '(:RAX)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x92) + (ARG :OP1 '(:RDX/R10) :OP2 '(:RAX)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x93) + (ARG :OP1 '(:RBX/R11) :OP2 '(:RAX)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x94) + (ARG :OP1 '(:RSP/R12) :OP2 '(:RAX)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x95) + (ARG :OP1 '(:RBP/R13) :OP2 '(:RAX)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x96) + (ARG :OP1 '(:RSI/R14) :OP2 '(:RAX)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "XCHG" (OP :OP #x97) + (ARG :OP1 '(:RDI/R15) :OP2 '(:RAX)) + '(X86-XCHG) + '((:UD (UD-LOCK-USED)))) + (INST "CBW/CWDE/CDQE" (OP :OP #x98) + NIL '(X86-CBW/CWD/CDQE) + '((:UD (UD-LOCK-USED)))) + (INST "CWD/CDQ/CQO" (OP :OP #x99) + NIL '(X86-CWD/CDQ/CQO) + '((:UD (UD-LOCK-USED)))) + (INST "CALL" (OP :OP #x9A :MODE :I64) + (ARG :OP1 '(A P)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "#UD" (OP :OP #x9A :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION + (MESSAGE . + "far CALL is illegal in the 64-bit mode!")) + '((:UD T))) + ;; This tells the processor to handle floating + ;; point exceptions. I'd expect we handle them as they happen + ;; cause we don't do out of order execution or stuff like that + ;; but I am both unfamiliar with the floating point portion of + ;; the x86isa and the floating point portion of this model + ;; I made this a NOP + ;; TODO figure out whether this can actually be a NOP + (INST "FWAIT/WAIT" (OP :OP #x9B) + NIL '(X86-ONE-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "PUSHF/D/Q" + (OP :OP #x9C :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(F V)) + '(X86-PUSHF) + '((:UD (UD-LOCK-USED)))) + (INST "POPF/D/Q" + (OP :OP #x9D :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(F V)) + '(X86-POPF) + '((:UD (UD-LOCK-USED)))) + (INST "SAHF" (OP :OP #x9E) + NIL '(X86-SAHF) + '((:UD (UD-LOCK-USED) + (AND (EQUAL PROC-MODE #x0) + (EQUAL (FEATURE-FLAG-MACRO :LAHF-SAHF) #x0))))) + (INST "LAHF" (OP :OP #x9F) + NIL '(X86-LAHF) + '((:UD (UD-LOCK-USED) + (AND (EQUAL PROC-MODE #x0) + (EQUAL (FEATURE-FLAG-MACRO :LAHF-SAHF) #x0))))) + (INST "MOV" (OP :OP #xA0) + (ARG :OP1 '(:AL) :OP2 '(O B)) + '(X86-MOV-OP/EN-FD) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xA1) + (ARG :OP1 '(:RAX) :OP2 '(O V)) + '(X86-MOV-OP/EN-FD) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xA2) + (ARG :OP1 '(O B) :OP2 '(:AL)) + '(X86-MOV-OP/EN-TD) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xA3) + (ARG :OP1 '(O V) :OP2 '(:RAX)) + '(X86-MOV-OP/EN-TD) + '((:UD (UD-LOCK-USED)))) + (INST "MOVS/B" (OP :OP #xA4) + (ARG :OP1 '(Y B) :OP2 '(X B)) + '(X86-MOVS) + '((:UD (UD-LOCK-USED)))) + (INST "MOVS/W/D/Q" (OP :OP #xA5) + (ARG :OP1 '(Y V) :OP2 '(X V)) + '(X86-MOVS) + '((:UD (UD-LOCK-USED)))) + (INST "CMPS/B" (OP :OP #xA6) + (ARG :OP1 '(X B) :OP2 '(Y B)) + '(X86-CMPS) + '((:UD (UD-LOCK-USED)))) + (INST "CMPS/W/D" (OP :OP #xA7) + (ARG :OP1 '(X V) :OP2 '(Y V)) + '(X86-CMPS) + '((:UD (UD-LOCK-USED)))) + (INST "TEST" (OP :OP #xA8) + (ARG :OP1 '(:AL) :OP2 '(I B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x7)) + '((:UD (UD-LOCK-USED)))) + (INST "TEST" (OP :OP #xA9) + (ARG :OP1 '(:RAX) :OP2 '(I Z)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I (OPERATION . #x7)) + '((:UD (UD-LOCK-USED)))) + (INST "STOS/B" (OP :OP #xAA) + (ARG :OP1 '(Y B) :OP2 '(:AL)) + '(X86-STOS) + '((:UD (UD-LOCK-USED)))) + (INST "STOS/W/D/Q" (OP :OP #xAB) + (ARG :OP1 '(Y V) :OP2 '(:RAX)) + '(X86-STOS) + '((:UD (UD-LOCK-USED)))) + (INST "LODS/B" (OP :OP #xAC) + (ARG :OP1 '(:AL) :OP2 '(X B)) + '(X86-LODS) + '((:UD (UD-LOCK-USED)))) + (INST "LODS/W/D/Q" (OP :OP #xAD) + (ARG :OP1 '(:RAX) :OP2 '(X V)) + '(X86-LODS) + '((:UD (UD-LOCK-USED)))) + (INST "SCAS/B" (OP :OP #xAE) + (ARG :OP1 '(:AL) :OP2 '(Y B)) + '(X86-SCAS) + '((:UD (UD-LOCK-USED)))) + (INST "SCAS/W/D/Q" (OP :OP #xAF) + (ARG :OP1 '(:RAX) :OP2 '(Y V)) + '(X86-SCAS) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB0) + (ARG :OP1 '(:AL/R8L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB1) + (ARG :OP1 '(:CL/R9L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB2) + (ARG :OP1 '(:DL/R10L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB3) + (ARG :OP1 '(:BL/R11L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB4) + (ARG :OP1 '(:AH/R12L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB5) + (ARG :OP1 '(:CH/R13L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB6) + (ARG :OP1 '(:DH/R14L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB7) + (ARG :OP1 '(:BH/R15L) :OP2 '(I B)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB8) + (ARG :OP1 '(:RAX/R8) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xB9) + (ARG :OP1 '(:RCX/R9) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xBA) + (ARG :OP1 '(:RDX/R10) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xBB) + (ARG :OP1 '(:RBX/R11) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xBC) + (ARG :OP1 '(:RSP/R12) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xBD) + (ARG :OP1 '(:RBP/R13) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xBE) + (ARG :OP1 '(:RSI/R14) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xBF) + (ARG :OP1 '(:RDI/R15) :OP2 '(I V)) + '(X86-MOV-OP/EN-OI) + '((:UD (UD-LOCK-USED)))) + (INST "ROL" + (OP :OP #xC0 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROR" + (OP :OP #xC0 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCL" + (OP :OP #xC0 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCR" + (OP :OP #xC0 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHL/SAL" + (OP :OP #xC0 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHR" + (OP :OP #xC0 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SAR" + (OP :OP #xC0 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROL" + (OP :OP #xC1 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROR" + (OP :OP #xC1 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCL" + (OP :OP #xC1 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCR" + (OP :OP #xC1 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHL/SAL" + (OP :OP #xC1 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHR" + (OP :OP #xC1 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SAR" + (OP :OP #xC1 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RET" + (OP :OP #xC2 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(I W)) + '(X86-RET) + '((:UD (UD-LOCK-USED)))) + (INST "RET" + (OP :OP #xC3 :SUPERSCRIPTS '(:F64)) + NIL '(X86-RET) + '((:UD (UD-LOCK-USED)))) + ;; C4 and C5 are first bytes of the vex prefixes, both + ;; in 32-bit and IA-32e modes. However, in the 32-bit + ;; and compatibility modes, the second byte determines + ;; whether the instruction is LES/LDS or a VEX + ;; instruction. We use :o64 here because we're sure + ;; that an "opcode" of C4 and C5 in the 64-bit mode will + ;; not have a modr/m corresponding to it --- basically, + ;; we shouldn't be looking up modr/m info. for these + ;; opcodes in the 64-bit mode. + (INST :VEX3-BYTE0 (OP :OP #xC4 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "LES" (OP :OP #xC4 :MODE :I64) + (ARG :OP1 '(G Z) :OP2 '(M P)) + '(X86-LOAD-FAR-POINTER) + '((:UD (UD-LOCK-USED) + (UD-SOURCE-OPERAND-IS-A-REGISTER)))) + (INST :VEX2-BYTE0 (OP :OP #xC5 :MODE :O64) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "LDS" (OP :OP #xC5 :MODE :I64) + (ARG :OP1 '(G Z) :OP2 '(M P)) + '(X86-LOAD-FAR-POINTER) + '((:UD (UD-LOCK-USED) + (UD-SOURCE-OPERAND-IS-A-REGISTER)))) + (INST "MOV" + (OP :OP #xC6 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-11)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-MOV-OP/EN-MI) + '((:UD (UD-LOCK-USED)))) + (INST "XABORT" + (OP :OP #xC6 + :REG #x7 + :MOD #x3 + :R/M #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-11) + :FEAT '(:RTM)) + (ARG :OP1 '(I B)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "MOV" + (OP :OP #xC7 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-11)) + (ARG :OP1 '(E V) :OP2 '(I Z)) + '(X86-MOV-OP/EN-MI) + '((:UD (UD-LOCK-USED)))) + (INST "XBEGIN" + (OP :OP #xC7 + :REG #x7 + :MOD #x3 + :R/M #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-11) + :FEAT '(:RTM)) + (ARG :OP1 '(J Z)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "ENTER" (OP :OP #xC8) + (ARG :OP1 '(I W) :OP2 '(I B)) + '(X86-ENTER) + '((:UD (UD-LOCK-USED)))) + (INST "LEAVE" + (OP :OP #xC9 :SUPERSCRIPTS '(:D64)) + NIL '(X86-LEAVE) + '((:UD (UD-LOCK-USED)))) + (INST "RET" (OP :OP #xCA) + (ARG :OP1 '(I W)) + 'NIL + 'NIL) + (INST "RET" (OP :OP #xCB) NIL '(X86-RET) 'NIL) + (INST "INT3" (OP :OP #xCC) + NIL '(X86-INT3) + '((:UD (UD-LOCK-USED)))) + (INST "INT" (OP :OP #xCD) + (ARG :OP1 '(I B)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "INTO" (OP :OP #xCE :MODE :I64) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #xCE :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . + "INTO is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "IRET/D/Q" (OP :OP #xCF) + NIL '(X86-IRET) + '((:UD (UD-LOCK-USED)))) + (INST "ROL" + (OP :OP #xD0 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROR" + (OP :OP #xD0 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCL" + (OP :OP #xD0 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCR" + (OP :OP #xD0 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHL/SAL" + (OP :OP #xD0 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHR" + (OP :OP #xD0 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SAR" + (OP :OP #xD0 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROL" + (OP :OP #xD1 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROR" + (OP :OP #xD1 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCL" + (OP :OP #xD1 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCR" + (OP :OP #xD1 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHL/SAL" + (OP :OP #xD1 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHR" + (OP :OP #xD1 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SAR" + (OP :OP #xD1 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(#x1)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROL" + (OP :OP #xD2 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROR" + (OP :OP #xD2 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCL" + (OP :OP #xD2 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCR" + (OP :OP #xD2 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHL/SAL" + (OP :OP #xD2 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHR" + (OP :OP #xD2 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SAR" + (OP :OP #xD2 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E B) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROL" + (OP :OP #xD3 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "ROR" + (OP :OP #xD3 + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCL" + (OP :OP #xD3 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "RCR" + (OP :OP #xD3 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHL/SAL" + (OP :OP #xD3 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SHR" + (OP :OP #xD3 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "SAR" + (OP :OP #xD3 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-2)) + (ARG :OP1 '(E V) :OP2 '(:CL)) + '(X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR) + '((:UD (UD-LOCK-USED)))) + (INST "AAM" (OP :OP #xD4 :MODE :I64) + (ARG :OP1 '(I B)) + '(X86-AAM) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #xD4 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "AAM is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "AAD" (OP :OP #xD5 :MODE :I64) + (ARG :OP1 '(I B)) + '(X86-AAD) + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #xD5 :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "AAD is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "XLAT/XLATB" (OP :OP #xD7) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + + + ;; X87 instruction entries (#xD8 through #xDF) generated from xed datafiles using: + ;; xedscan.py ~/work/xed/datafiles/xed-isa.txt xed-x87.txt + + ;; See comments in xedscan.py for notes on how to extend to more instructions + + (INST "FADD" + (OP :OP #xd8 :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FMUL" + (OP :OP #xd8 :REG 1 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOMP" + (OP :OP #xd8 :REG 3 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUB" + (OP :OP #xd8 :REG 4 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUBR" + (OP :OP #xd8 :REG 5 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIV" + (OP :OP #xd8 :REG 6 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIVR" + (OP :OP #xd8 :REG 7 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FADD" + (OP :OP #xd8 :REG 0 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FMUL" + (OP :OP #xd8 :REG 1 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOM" + (OP :OP #xdc :REG 2 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOM" + (OP :OP #xd8 :REG 2 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FCOM" +;; (OP :OP #xdc :REG 2 :MOD 3 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) + (INST "FCOMP" + (OP :OP #xd8 :REG 3 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FCOMP" +;; (OP :OP #xde :REG 2 :MOD 3 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) + (INST "FSUB" + (OP :OP #xd8 :REG 4 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUBR" + (OP :OP #xd8 :REG 5 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIV" + (OP :OP #xd8 :REG 6 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIVR" + (OP :OP #xd8 :REG 7 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLD" + (OP :OP #xd9 :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FST" + (OP :OP #xd9 :REG 2 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSTP" + (OP :OP #xdd :REG 3 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSTP" + (OP :OP #xdd :REG 3 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FSTP" +;; (OP :OP #xdf :REG 3 :MOD 3 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FSTPNCE" +;; (OP :OP #xd9 :REG 3 :MOD 3 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) + (INST "FLDENV" + (OP :OP #xd9 :REG 4 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLDCW" + (OP :OP #xd9 :REG 5 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FNSTENV" + (OP :OP #xd9 :REG 6 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FNSTCW" + (OP :OP #xd9 :REG 7 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLD" + (OP :OP #xd9 :REG 0 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FXCH" + (OP :OP #xd9 :REG 1 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FXCH" +;; (OP :OP #xdd :REG 1 :MOD 3 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) + (INST "FNOP" + (OP :OP #xd9 :REG 2 :MOD 3 :R/M 0 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCHS" + (OP :OP #xd9 :REG 4 :MOD 3 :R/M 0 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FABS" + (OP :OP #xd9 :REG 4 :MOD 3 :R/M 1 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FTST" + (OP :OP #xd9 :REG 4 :MOD 3 :R/M 4 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FXAM" + (OP :OP #xd9 :REG 4 :MOD 3 :R/M 5 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLD1" + (OP :OP #xd9 :REG 5 :MOD 3 :R/M 0 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLDL2T" + (OP :OP #xd9 :REG 5 :MOD 3 :R/M 1 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLDL2E" + (OP :OP #xd9 :REG 5 :MOD 3 :R/M 2 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLDPI" + (OP :OP #xd9 :REG 5 :MOD 3 :R/M 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLDLG2" + (OP :OP #xd9 :REG 5 :MOD 3 :R/M 4 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLDLN2" + (OP :OP #xd9 :REG 5 :MOD 3 :R/M 5 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLDZ" + (OP :OP #xd9 :REG 5 :MOD 3 :R/M 6 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "F2XM1" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 0 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FYL2X" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 1 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FPTAN" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 2 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FPATAN" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FXTRACT" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 4 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FPREM1" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 5 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDECSTP" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 6 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FINCSTP" + (OP :OP #xd9 :REG 6 :MOD 3 :R/M 7 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FPREM" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 0 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FYL2XP1" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 1 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSQRT" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 2 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSINCOS" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FRNDINT" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 4 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSCALE" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 5 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSIN" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 6 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOS" + (OP :OP #xd9 :REG 7 :MOD 3 :R/M 7 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIADD" + (OP :OP #xda :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIMUL" + (OP :OP #xda :REG 1 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FICOM" + (OP :OP #xda :REG 2 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FICOMP" + (OP :OP #xda :REG 3 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISUB" + (OP :OP #xda :REG 4 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISUBR" + (OP :OP #xda :REG 5 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIDIV" + (OP :OP #xda :REG 6 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIDIVR" + (OP :OP #xda :REG 7 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVB" + (OP :OP #xda :REG 0 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVE" + (OP :OP #xda :REG 1 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVBE" + (OP :OP #xda :REG 2 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVU" + (OP :OP #xda :REG 3 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FUCOMPP" + (OP :OP #xda :REG 5 :MOD 3 :R/M 1 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FILD" + (OP :OP #xdb :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISTTP" + (OP :OP #xdb :REG 1 :MOD :MEM) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIST" + (OP :OP #xdb :REG 2 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISTP" + (OP :OP #xdb :REG 3 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLD" + (OP :OP #xdb :REG 5 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVNB" + (OP :OP #xdb :REG 0 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVNE" + (OP :OP #xdb :REG 1 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVNBE" + (OP :OP #xdb :REG 2 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCMOVNU" + (OP :OP #xdb :REG 3 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FNCLEX" + (OP :OP #xdb :REG 4 :MOD 3 :R/M 2 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FNINIT" + (OP :OP #xdb :REG 4 :MOD 3 :R/M 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FSETPM287_NOP" +;; (OP :OP #xdb :REG 4 :MOD 3 :R/M 4 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FENI8087_NOP" +;; (OP :OP #xdb :REG 4 :MOD 3 :R/M 0 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FDISI8087_NOP" +;; (OP :OP #xdb :REG 4 :MOD 3 :R/M 1 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) + (INST "FUCOMI" + (OP :OP #xdb :REG 5 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOMI" + (OP :OP #xdb :REG 6 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FADD" + (OP :OP #xdc :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FMUL" + (OP :OP #xdc :REG 1 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOMP" + (OP :OP #xdc :REG 3 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUB" + (OP :OP #xdc :REG 4 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUBR" + (OP :OP #xdc :REG 5 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIV" + (OP :OP #xdc :REG 6 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIVR" + (OP :OP #xdc :REG 7 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FADD" + (OP :OP #xdc :REG 0 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FMUL" + (OP :OP #xdc :REG 1 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUBR" + (OP :OP #xdc :REG 4 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUB" + (OP :OP #xdc :REG 5 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIVR" + (OP :OP #xdc :REG 6 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIV" + (OP :OP #xdc :REG 7 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FLD" + (OP :OP #xdd :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISTTP" + (OP :OP #xdd :REG 1 :MOD :MEM) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FST" + (OP :OP #xdd :REG 2 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FRSTOR" + (OP :OP #xdd :REG 4 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FNSAVE" + (OP :OP #xdd :REG 6 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FNSTSW" + (OP :OP #xdd :REG 7 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FFREE" + (OP :OP #xdd :REG 0 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FST" + (OP :OP #xdd :REG 2 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FUCOM" + (OP :OP #xdd :REG 4 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FUCOMP" + (OP :OP #xdd :REG 5 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIADD" + (OP :OP #xde :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIMUL" + (OP :OP #xde :REG 1 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FICOM" + (OP :OP #xde :REG 2 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FICOMP" + (OP :OP #xde :REG 3 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISUB" + (OP :OP #xde :REG 4 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISUBR" + (OP :OP #xde :REG 5 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIDIV" + (OP :OP #xde :REG 6 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIDIVR" + (OP :OP #xde :REG 7 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FADDP" + (OP :OP #xde :REG 0 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FMULP" + (OP :OP #xde :REG 1 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOMPP" + (OP :OP #xde :REG 3 :MOD 3 :R/M 1 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUBRP" + (OP :OP #xde :REG 4 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FSUBP" + (OP :OP #xde :REG 5 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIVRP" + (OP :OP #xde :REG 6 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FDIVP" + (OP :OP #xde :REG 7 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FILD" + (OP :OP #xdf :REG 0 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISTTP" + (OP :OP #xdf :REG 1 :MOD :MEM) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FIST" + (OP :OP #xdf :REG 2 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISTP" + (OP :OP #xdf :REG 3 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FBLD" + (OP :OP #xdf :REG 4 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FILD" + (OP :OP #xdf :REG 5 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FBSTP" + (OP :OP #xdf :REG 6 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FISTP" + (OP :OP #xdf :REG 7 :MOD :MEM :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) +;; Undocumented (from xed-isa.txt): +;; (INST "FFREEP" +;; (OP :OP #xdf :REG 0 :MOD 3 :FEAT '(:FPU)) +;; (ARG) ;; bozo x87 conventions +;; nil +;; '((:UD (UD-LOCK-USED)) +;; (:NM (NM-CR0-TS-IS-1) +;; (NM-CR0-EM-IS-1)))) + (INST "FNSTSW" + (OP :OP #xdf :REG 4 :MOD 3 :R/M 0 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FUCOMIP" + (OP :OP #xdf :REG 5 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "FCOMIP" + (OP :OP #xdf :REG 6 :MOD 3 :FEAT '(:FPU)) + (ARG) ;; bozo x87 conventions + nil + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + +;; end x87 instructions generated by xedscan.py + + (INST "LOOPNE/LOOPNZ" + (OP :OP #xE0 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-LOOP) + '((:UD (UD-LOCK-USED)))) + (INST "LOOPE/LOOPZ" + (OP :OP #xE1 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-LOOP) + '((:UD (UD-LOCK-USED)))) + (INST "LOOP" + (OP :OP #xE2 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-LOOP) + '((:UD (UD-LOCK-USED)))) + (INST "JrCXZ" + (OP :OP #xE3 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-JRCXZ) + '((:UD (UD-LOCK-USED)))) + (INST "IN" (OP :OP #xE4) + (ARG :OP1 '(:AL) :OP2 '(I B)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "IN" (OP :OP #xE5) + (ARG :OP1 '(:EAX) :OP2 '(I B)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "OUT" (OP :OP #xE6) + (ARG :OP1 '(I B) :OP2 '(:AL)) + '(X86-OUT) + '((:UD (UD-LOCK-USED)))) + (INST "OUT" (OP :OP #xE7) + (ARG :OP1 '(I B) :OP2 '(:EAX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "CALL" + (OP :OP #xE8 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-CALL-E8-OP/EN-M) + '((:UD (UD-LOCK-USED)))) + (INST "JMP" + (OP :OP #xE9 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-NEAR-JMP-OP/EN-D) + '((:UD (UD-LOCK-USED)))) + (INST "JMP" (OP :OP #xEA :MODE :I64) + (ARG :OP1 '(A P)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST + "#UD" (OP :OP #xEA :MODE :O64) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "JMP is illegal in the 64-bit mode!")) + '((:UD T))) + (INST "JMP" + (OP :OP #xEB :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J B)) + '(X86-NEAR-JMP-OP/EN-D) + '((:UD (UD-LOCK-USED)))) + (INST "IN" (OP :OP #xEC) + (ARG :OP1 '(:AL) :OP2 '(:DX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "IN" (OP :OP #xED) + (ARG :OP1 '(:EAX) :OP2 '(:DX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "OUT" (OP :OP #xEE) + (ARG :OP1 '(:DX) :OP2 '(:AL)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "OUT" (OP :OP #xEF) + (ARG :OP1 '(:DX) :OP2 '(:EAX)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST :PREFIX-LOCK (OP :OP #xF0) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "INT1" (OP :OP #xF1) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST :PREFIX-REPNE (OP :OP #xF2) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST :PREFIX-REP/REPE (OP :OP #xF3) + 'NIL + '(:NO-INSTRUCTION) + 'NIL) + (INST "HLT" (OP :OP #xF4) + NIL '(X86-HLT) + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "CMC" (OP :OP #xF5) + NIL '(X86-CMC/CLC/STC/CLD/STD) + '((:UD (UD-LOCK-USED)))) + (INST "TEST" + (OP :OP #xF6 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x7)) + '((:UD (UD-LOCK-USED)))) + (INST "NOT" + (OP :OP #xF6 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-NOT/NEG-F6-F7) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "NEG" + (OP :OP #xF6 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-NOT/NEG-F6-F7) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "MUL" + (OP :OP #xF6 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-MUL) + '((:UD (UD-LOCK-USED)))) + (INST "IMUL" + (OP :OP #xF6 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-IMUL-OP/EN-M) + '((:UD (UD-LOCK-USED)))) + (INST "DIV" + (OP :OP #xF6 + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-DIV) + '((:UD (UD-LOCK-USED)))) + (INST "IDIV" + (OP :OP #xF6 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-IDIV) + '((:UD (UD-LOCK-USED)))) + (INST "TEST" + (OP :OP #xF7 + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I (OPERATION . #x7)) + '((:UD (UD-LOCK-USED)))) + (INST "NOT" + (OP :OP #xF7 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-NOT/NEG-F6-F7) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "NEG" + (OP :OP #xF7 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-NOT/NEG-F6-F7) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "MUL" + (OP :OP #xF7 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-MUL) + '((:UD (UD-LOCK-USED)))) + (INST "IMUL" + (OP :OP #xF7 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-IMUL-OP/EN-M) + '((:UD (UD-LOCK-USED)))) + (INST "DIV" + (OP :OP #xF7 + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-DIV) + '((:UD (UD-LOCK-USED)))) + (INST "IDIV" + (OP :OP #xF7 + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-3)) + (ARG :OP1 '(E B)) + '(X86-IDIV) + '((:UD (UD-LOCK-USED)))) + (INST "CLC" (OP :OP #xF8) + NIL '(X86-CMC/CLC/STC/CLD/STD) + '((:UD (UD-LOCK-USED)))) + (INST "STC" (OP :OP #xF9) + NIL '(X86-CMC/CLC/STC/CLD/STD) + '((:UD (UD-LOCK-USED)))) + (INST "CLI" (OP :OP #xFA) + NIL '(X86-CLI) + '((:UD (UD-LOCK-USED)))) + (INST "STI" (OP :OP #xFB) + NIL '(X86-STI) + '((:UD (UD-LOCK-USED)))) + (INST "CLD" (OP :OP #xFC) + NIL '(X86-CMC/CLC/STC/CLD/STD) + 'NIL) + (INST "STD" (OP :OP #xFD) + NIL '(X86-CMC/CLC/STC/CLD/STD) + '((:UD (UD-LOCK-USED)))) + (INST "INC" + (OP :OP #xFE + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-4)) + (ARG :OP1 '(E B)) + '(X86-INC/DEC-FE-FF) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "DEC" + (OP :OP #xFE + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-4)) + (ARG :OP1 '(E B)) + '(X86-INC/DEC-FE-FF) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "INC" + (OP :OP #xFF + :REG #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-5)) + (ARG :OP1 '(E V)) + '(X86-INC/DEC-FE-FF) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "DEC" + (OP :OP #xFF + :REG #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-5)) + (ARG :OP1 '(E V)) + '(X86-INC/DEC-FE-FF) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "near CALL" + (OP :OP #xFF + :REG #x2 + :SUPERSCRIPTS '(:1A :F64) + :GROUP '(:GROUP-5)) + (ARG :OP1 '(E V)) + '(X86-CALL-FF/2-OP/EN-M) + '((:UD (UD-LOCK-USED)))) + (INST "far CALL" + (OP :OP #xFF + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-5)) + (ARG :OP1 '(E P)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "near JMP" + (OP :OP #xFF + :REG #x4 + :SUPERSCRIPTS '(:1A :F64) + :GROUP '(:GROUP-5)) + (ARG :OP1 '(E V)) + '(X86-NEAR-JMP-OP/EN-M) + '((:UD (UD-LOCK-USED)))) + (INST "far JMP" + (OP :OP #xFF + :REG #x5 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-5)) + (ARG :OP1 '(M P)) + '(X86-FAR-JMP-OP/EN-D) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH" + (OP :OP #xFF + :REG #x6 + :SUPERSCRIPTS '(:1A :D64) + :GROUP '(:GROUP-5)) + (ARG :OP1 '(E V)) + '(X86-PUSH-EV) + '((:UD (UD-LOCK-USED)))))) + +(defconst *pre-two-byte-opcode-map* + '((INST "SLDT" + (OP :OP #xF00 + :REG #x0 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(M W)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "SLDT" + (OP :OP #xF00 + :REG #x0 + :MOD #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(R V)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "STR" + (OP :OP #xF00 + :REG #x1 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(M W)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "STR" + (OP :OP #xF00 + :REG #x1 + :MOD #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(R V)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "LLDT" + (OP :OP #xF00 + :REG #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(E W)) + '(X86-LLDT) + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "LTR" + (OP :OP #xF00 + :REG #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(E W)) + '(X86-LTR) + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "VERR" + (OP :OP #xF00 + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(E W)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "VERW" + (OP :OP #xF00 + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-6)) + (ARG :OP1 '(E W)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "SGDT" + (OP :OP #xF01 + :REG #x0 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(M S)) + '(X86-SGDT) + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "VMCALL" + (OP :OP #xF01 + :REG #x0 + :MOD #x3 + :R/M #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL 'NIL + 'NIL) + (INST "VMLAUNCH" + (OP :OP #xF01 + :REG #x0 + :MOD #x3 + :R/M #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL 'NIL + '((:GP (GP-CPL-NOT-0)))) + (INST "VMRESUME" + (OP :OP #xF01 + :REG #x0 + :MOD #x3 + :R/M #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL 'NIL + 'NIL) + (INST "VMXOFF" + (OP :OP #xF01 + :REG #x0 + :MOD #x3 + :R/M #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL 'NIL + ;; BOZO Rob -- following GP only if executed in VMX root operation! + '((:GP (GP-CPL-NOT-0)))) + (INST "SIDT" + (OP :OP #xF01 + :REG #x1 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(M S)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "MONITOR" + (OP :OP #xF01 + :REG #x1 + :MOD #x3 + :R/M #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:MONITOR)) + NIL 'NIL + '((:UD (UD-CPL-IS-NOT-ZERO)))) + (INST "MWAIT" + (OP :OP #xF01 + :REG #x1 + :MOD #x3 + :R/M #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:MONITOR)) + NIL 'NIL + '((:UD (UD-CPL-IS-NOT-ZERO)))) + (INST "CLAC" + (OP :OP #xF01 + :REG #x1 + :MOD #x3 + :R/M #x2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:SMAP)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (UD-CPL-IS-NOT-ZERO)))) + (INST "STAC" + (OP :OP #xF01 + :REG #x1 + :MOD #x3 + :R/M #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:SMAP)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (UD-CPL-IS-NOT-ZERO)))) + (INST "ENCLS" + (OP :OP #xF01 + :REG #x1 + :MOD #x3 + :R/M #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL 'NIL + 'NIL) + (INST "LGDT" + (OP :OP #xF01 + :REG #x2 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(M S)) + '(X86-LGDT) + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "LIDT" + (OP :OP #xF01 + :REG #x3 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(M S)) + '(X86-LIDT) + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "XGETBV" + (OP :OP #xF01 + :REG #x3 + :MOD #x3 + :R/M #x0 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:XSAVE)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->OSXSAVE (CR4)) #x0)))) + (INST "XSETBV" + (OP :OP #xF01 + :REG #x3 + :MOD #x3 + :R/M #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:XSAVE)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->OSXSAVE (CR4)) #x0)))) + (INST "VMFUNC" + (OP :OP #xF01 + :REG #x3 + :MOD #x3 + :R/M #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL 'NIL + 'NIL) + (INST "XEND" + (OP :OP #xF01 + :REG #x3 + :MOD #x3 + :R/M #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:RTM)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (UD-OPR-USED) + (UD-REPS-USED)))) + (INST "XTEST" + (OP :OP #xF01 + :REG #x3 + :MOD #x3 + :R/M #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:HLE :RTM)) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "ENCLU" + (OP :OP #xF01 + :REG #x3 + :MOD #x3 + :R/M #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL 'NIL + '((:NM (NM-CR0-TS-IS-1)))) + (INST "SMSW" + (OP :OP #xF01 + :REG #x4 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(M W)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "SMSW" + (OP :OP #xF01 + :REG #x4 + :MOD #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(R V)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-UMIP-IS-1))))) + (INST "LMSW" + (OP :OP #xF01 + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(E W)) + 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "INVLPG" + (OP :OP #xF01 + :REG #x7 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + (ARG :OP1 '(M B)) + '(X86-INVLPG) + '((:UD (UD-LOCK-USED) + (UD-MODR/M.MOD-INDICATES-REGISTER)) + (:GP (GP-CPL-NOT-0)))) + (INST "SWAPGS" + (OP :OP #xF01 + :REG #x7 + :MOD #x3 + :R/M #x0 + :MODE :O64 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7)) + NIL '(X86-SWAPGS) + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "RDTSCP" + (OP :OP #xF01 + :REG #x7 + :MOD #x3 + :R/M #x1 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-7) + :FEAT '(:RDTSCP)) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "LAR" (OP :OP #xF02) + (ARG :OP1 '(G V) :OP2 '(E W)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "LSL" (OP :OP #xF03) + (ARG :OP1 '(G V) :OP2 '(E W)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "SYSCALL" (OP :OP #xF05 :MODE :O64) + NIL '(X86-SYSCALL-BOTH-VIEWS) + '((:UD (UD-LOCK-USED) + (EQUAL (IA32_EFERBITS->SCE (N12 (IA32_EFER))) + #x0)))) + (INST "CLTS" (OP :OP #xF06) + NIL 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0)))) + (INST "SYSRET" (OP :OP #xF07 :MODE :O64) + NIL '(X86-SYSRET) + '((:UD (UD-LOCK-USED) + (EQUAL (IA32_EFERBITS->SCE (N12 (IA32_EFER))) + #x0)) + (:GP (GP-CPL-NOT-0)))) + (INST "INVD" (OP :OP #xF08) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "WBINVD" (OP :OP #xF09) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "UD2" + (OP :OP #xF0B :SUPERSCRIPTS '(:1B)) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "UD2 encountered!")) + 'NIL) + (INST "prefetchw(/1)" (OP :OP #xF0D) + (ARG :OP1 '(E V)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "MOVUPS" + (OP :OP #xF10 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "MOVUPD" + (OP :OP #xF10 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "MOVSS" + (OP :OP #xF10 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SS)) + '(X86-MOVSS/MOVSD-OP/EN-RM (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "MOVSD" + (OP :OP #xF10 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SD)) + '(X86-MOVSS/MOVSD-OP/EN-RM (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "VMOVSD" + (OP :OP #xF10 + :VEX '(:0F :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSD" + (OP :OP #xF10 + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSS" + (OP :OP #xF10 + :VEX '(:0F :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSS" + (OP :OP #xF10 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVUPD" + (OP :OP #xF10 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-A) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVUPD" + (OP :OP #xF10 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-A) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVUPS" + (OP :OP #xF10 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-A) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVUPS" + (OP :OP #xF10 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-A) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVSD" + (OP :OP #xF10 + :EVEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX512F)) + (ARG :OP1 '(:ModR/M.reg :XMM) + :OP2 '(:VEX.vvvv :XMM) + :OP3 '(:ModR/M.r/m :XMM)) + NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVSD" + (OP :OP #xF10 + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL + NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVSS" + (OP :OP #xF10 + :EVEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVSS" + (OP :OP #xF10 + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVUPD" + (OP :OP #xF10 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPD" + (OP :OP #xF10 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPD" + (OP :OP #xF10 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VMOVUPS" + (OP :OP #xF10 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPS" + (OP :OP #xF10 + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPS" + (OP :OP #xF10 + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "MOVUPS" + (OP :OP #xF11 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(W PS) :OP2 '(V PS)) + '(X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "MOVUPD" + (OP :OP #xF11 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(W PD) :OP2 '(V PD)) + '(X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "MOVSS" + (OP :OP #xF11 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(W SS) + :OP2 '(H X) + :OP3 '(V SS)) + '(X86-MOVSS/MOVSD-OP/EN-MR (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "MOVSD" + (OP :OP #xF11 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(W SD) + :OP2 '(H X) + :OP3 '(V SD)) + '(X86-MOVSS/MOVSD-OP/EN-MR (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "VMOVSD" + (OP :OP #xF11 + :VEX '(:0F :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSD" + (OP :OP #xF11 + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSS" + (OP :OP #xF11 + :VEX '(:0F :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSS" + (OP :OP #xF11 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVUPD" + (OP :OP #xF11 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-B) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVUPD" + (OP :OP #xF11 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-B) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVUPS" + (OP :OP #xF11 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(x86-vmovups/vmovupd/vmovdqu-vex-b) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVUPS" + (OP :OP #xF11 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(x86-vmovups/vmovupd/vmovdqu-vex-b) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVSD" + (OP :OP #xF11 + :EVEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVSD" + (OP :OP #xF11 + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVSS" + (OP :OP #xF11 + :EVEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVSS" + (OP :OP #xF11 + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VMOVUPD" + (OP :OP #xF11 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPD" + (OP :OP #xF11 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPD" + (OP :OP #xF11 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VMOVUPS" + (OP :OP #xF11 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPS" + (OP :OP #xF11 + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VMOVUPS" + (OP :OP #xF11 + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "MOVLPS" + (OP :OP #xF12 :MOD :MEM :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(M Q)) + '(X86-MOVLPS/MOVLPD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "MOVHLPS" + (OP :OP #xF12 :MOD #x3 :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(U Q)) + '(X86-MOVHLPS-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE))))) + (INST "MOVLPD" + (OP :OP #xF12 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(M Q)) + '(X86-MOVLPS/MOVLPD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "MOVSLDUP" + (OP :OP #xF12 :PFX :F3 :FEAT '(:SSE3)) + (ARG :OP1 '(V X) :OP2 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE3))))) + (INST "MOVDDUP" + (OP :OP #xF12 :PFX :F2 :FEAT '(:SSE3)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-MOVDDUP-SSE) + '((:EX (CHK-EXC :TYPE-5 (:SSE3))))) + (INST "VMOVDDUP" + (OP :OP #xF12 + :VEX '(:0F :128 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVDDUP-VEX) + '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVDDUP" + (OP :OP #xF12 + :VEX '(:0F :256 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVDDUP-VEX) + '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVHLPS" + (OP :OP #xF12 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX) + :MOD #x3) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(U Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVLPD" + (OP :OP #xF12 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVLPS" + (OP :OP #xF12 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSLDUP" + (OP :OP #xF12 + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVSLDUP" + (OP :OP #xF12 + :VEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVDDUP" + (OP :OP #xF12 + :EVEX '(:0F :128 :F2 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDDUP" + (OP :OP #xF12 + :EVEX '(:0F :256 :F2 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDDUP" + (OP :OP #xF12 + :EVEX '(:0F :512 :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVHLPS" + (OP :OP #xF12 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVLPD" + (OP :OP #xF12 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVLPS" + (OP :OP #xF12 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512F) + :MOD :MEM) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVSLDUP" + (OP :OP #xF12 + :EVEX '(:0F :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VMOVSLDUP" + (OP :OP #xF12 + :EVEX '(:0F :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VMOVSLDUP" + (OP :OP #xF12 + :EVEX '(:0F :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512F))))) + (INST "MOVLPS" + (OP :OP #xF13 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(M Q) :OP2 '(V Q)) + '(X86-MOVLPS/MOVLPD-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-5 (:SSE))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "MOVLPD" + (OP :OP #xF13 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(M Q) :OP2 '(V Q)) + '(X86-MOVLPS/MOVLPD-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "VMOVLPD" + (OP :OP #xF13 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVLPS" + (OP :OP #xF13 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V Q) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVLPD" + (OP :OP #xF13 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVLPS" + (OP :OP #xF13 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "UNPCKLPS" + (OP :OP #xF14 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-UNPCK?PS-OP/EN-RM (HIGH/LOW . #x0)) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "UNPCKLPD" + (OP :OP #xF14 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-UNPCK?PD-OP/EN-RM (HIGH/LOW . #x0)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VUNPCKLPD" + (OP :OP #xF14 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKLPD" + (OP :OP #xF14 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKLPS" + (OP :OP #xF14 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKLPS" + (OP :OP #xF14 + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKLPD" + (OP :OP #xF14 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKLPD" + (OP :OP #xF14 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKLPD" + (OP :OP #xF14 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VUNPCKLPS" + (OP :OP #xF14 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKLPS" + (OP :OP #xF14 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKLPS" + (OP :OP #xF14 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "UNPCKHPS" + (OP :OP #xF15 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-UNPCK?PS-OP/EN-RM (HIGH/LOW . #x1)) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "UNPCKHPD" + (OP :OP #xF15 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-UNPCK?PD-OP/EN-RM (HIGH/LOW . #x1)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VUNPCKHPD" + (OP :OP #xF15 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKHPD" + (OP :OP #xF15 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKHPS" + (OP :OP #xF15 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKHPS" + (OP :OP #xF15 + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VUNPCKHPD" + (OP :OP #xF15 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKHPD" + (OP :OP #xF15 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKHPD" + (OP :OP #xF15 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VUNPCKHPS" + (OP :OP #xF15 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKHPS" + (OP :OP #xF15 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VUNPCKHPS" + (OP :OP #xF15 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "MOVHPS" + (OP :OP #xF16 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:V1) + :FEAT '(:SSE)) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(M Q)) + '(X86-MOVHPS/MOVHPD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "MOVLHPS" + (OP :OP #xF16 :MOD #x3 :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(U Q)) + '(X86-MOVLHPS-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE))))) + (INST "MOVHPD" + (OP :OP #xF16 + :PFX :66 + :SUPERSCRIPTS '(:V1) + :FEAT '(:SSE2)) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(M Q)) + '(X86-MOVHPS/MOVHPD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))) + (:UD (UD-SOURCE-OPERAND-IS-A-REGISTER)))) + (INST "MOVSHDUP" + (OP :OP #xF16 :PFX :F3 :FEAT '(:SSE3)) + (ARG :OP1 '(V X) :OP2 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE3))))) + (INST "VMOVHPD" + (OP :OP #xF16 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVHPS" + (OP :OP #xF16 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVLHPS" + (OP :OP #xF16 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX) + :MOD #x3) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(U Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVSHDUP" + (OP :OP #xF16 + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVSHDUP" + (OP :OP #xF16 + :VEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVHPD" + (OP :OP #xF16 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVHPS" + (OP :OP #xF16 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512F) + :MOD :MEM) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVLHPS" + (OP :OP #xF16 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVSHDUP" + (OP :OP #xF16 + :EVEX '(:0F :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VMOVSHDUP" + (OP :OP #xF16 + :EVEX '(:0F :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VMOVSHDUP" + (OP :OP #xF16 + :EVEX '(:0F :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512F))))) + (INST "MOVHPS" + (OP :OP #xF17 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:V1) + :FEAT '(:SSE)) + (ARG :OP1 '(M Q) :OP2 '(V Q)) + '(X86-MOVHPS/MOVHPD-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-5 (:SSE))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "MOVHPD" + (OP :OP #xF17 + :PFX :66 + :SUPERSCRIPTS '(:V1) + :FEAT '(:SSE2)) + (ARG :OP1 '(M Q) :OP2 '(V Q)) + '(X86-MOVHPS/MOVHPD-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "VMOVHPD" + (OP :OP #xF17 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVHPS" + (OP :OP #xF17 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V DQ) + :OP2 '(H Q) + :OP3 '(M Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVHPD" + (OP :OP #xF17 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVHPS" + (OP :OP #xF17 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "PREFETCHNTA" + (OP :OP #xF18 + :REG #x0 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "PREFETCHT0" + (OP :OP #xF18 + :REG #x1 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "PREFETCHT1" + (OP :OP #xF18 + :REG #x2 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "PREFETCHT2" + (OP :OP #xF18 + :REG #x3 + :MOD :MEM + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; The remaining encodings of 0F 18 (Group 16), with reg = 4-7 or + ;; mod = 3, are reserved NOPs like 0F 19 below (see the comment + ;; there), except for the prefetch hints that Intel has since + ;; defined in them: PREFETCHRST2 (0F 18 /4 with mod != 3, in the + ;; Intel ISE reference), and PREFETCHIT1 (0F 18 /6) and PREFETCHIT0 + ;; (0F 18 /7), the latter two only in 64-bit mode with RIP-relative + ;; addressing, executing as NOPs otherwise. Being hints without + ;; architectural effects, they are adequately modeled as NOPs too. + (INST "RESERVEDNOP" (OP :OP #xF18 :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "RESERVEDNOP" (OP :OP #xF18 :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "RESERVEDNOP" (OP :OP #xF18 :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "RESERVEDNOP" (OP :OP #xF18 :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "RESERVEDNOP" (OP :OP #xF18 :MOD #x3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; Intel Vol. 2 (Table A-3) shows 0F 19 as a reserved NOP. + ;; Section A.1 says that these opcodes may behave as NOPs on certain + ;; processors. Intel's XED decoder explicitly decodes 0F 19 /r as + ;; a NOP with a register or memory operand, requiring a ModR/M byte + ;; like 0F 1F /0 below. The Intel manual does not state this explicitly + ;; for 0F 19, but it is consistent with the other reserved NOPs + ;; 0F 1A-1E: the instructions since defined in them (MPX, CLDEMOTE, + ;; ENDBR32/ENDBR64, RDSSPD/RDSSPQ) all have a ModR/M byte, and the + ;; manual says that they execute as NOPs on processors that do not + ;; implement them, which is only possible if those processors decode + ;; the ModR/M byte (otherwise F3 0F 1E FA, i.e. ENDBR64, would + ;; execute as a NOP followed by CLI). + (INST "RESERVEDNOP" + (OP :OP #xF19 + :SUPERSCRIPTS '(:1A :1C)) + NIL + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; Intel MPX is not modeled: this model has no MPX state, and thus + ;; no way to enable MPX. Intel Vol. 1 (Appendix E, on Intel MPX) + ;; says: "When Intel MPX is not enabled or not present, all Intel + ;; MPX instructions behave as NOP." The MPX instructions occupy + ;; 0F 1A and 0F 1B, and Intel Vol. 2 says that their reg-reg forms + ;; not assigned to instructions remain NOPs; processors without + ;; MPX, including all the recent Intel ones (MPX has been dropped), + ;; execute all these encodings as reserved NOPs, like 0F 19 above + ;; (see the comment there). Thus, we model all the entries for + ;; 0F 1A and 0F 1B below as NOPs, without :FEAT '(:MPX) because + ;; they are NOPs regardless of whether the processor supports MPX + ;; (cf. ENDBR32/ENDBR64 at 0F 1E below). + ;; + ;; Besides the LOCK prefix, the exception lists in Intel Vol. 2 + ;; give these #UD conditions for the MPX instructions: bound + ;; registers beyond BND3 (explicitly "when Intel MPX is enabled"), + ;; 16-bit addressing (67H prefix with CS.D = 1, or no 67H prefix + ;; with CS.D = 0), and RIP-relative addressing for BNDLDX, BNDSTX, + ;; and BNDMK. All of them apply only when MPX is enabled, by the + ;; sentence quoted above; Intel Vol. 1 also says so specifically + ;; for the first two: Section E.4.1 says that opcodes "encoded to + ;; operate on bound registers beyond BND3 will #UD if Intel MPX is + ;; enabled", and Table E-3, which gives the #UD cases for 16-bit + ;; addressing, applies "when Intel MPX is enabled". Since MPX + ;; cannot be enabled in this model, we omit all those conditions + ;; and keep only the LOCK one, which applies to NOPs as well (see + ;; the NOP page), as in the RESERVEDNOP entries. + (INST "BNDLDX" + (OP :OP #xF1A + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(RB) :OP2 '(M)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; Source: BNDLDX-Load Extended Bounds Using Address + ;; Translation, Intel Vol. 2 (May 2018 edition) + ;; "The reg-reg form of this instruction will remain a NOP." + (INST "RESERVEDNOP" + (OP :OP #xF1A + :MOD #x3 + :PFX :NO-PREFIX) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; The BNDMOV page says "#UD If the LOCK prefix is used but the + ;; destination is not a memory operand", which is the wording used + ;; for the instructions that accept the LOCK prefix; but BNDMOV is + ;; not one of them (see the LOCK prefix page), and the other MPX + ;; pages say "If the LOCK prefix is used". So all four BNDMOV + ;; entries raise #UD whenever the LOCK prefix is used. + (INST "BNDMOV" + (OP :OP #xF1A + :MOD :MEM + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(RB) :OP2 '(M)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDMOV" + (OP :OP #xF1A + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(RB) :OP2 '(MB)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDCL" + (OP :OP #xF1A + :PFX :F3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(RB) :OP2 '(E Y)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDCU" + (OP :OP #xF1A + :PFX :F2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(RB) :OP2 '(E Y)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDSTX" + (OP :OP #xF1B + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(M) :OP2 '(RB)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; "The reg-reg form of this instruction will remain a NOP." + (INST "RESERVEDNOP" + (OP :OP #xF1B + :MOD #x3 + :PFX :NO-PREFIX) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDMOV" + (OP :OP #xF1B + :MOD :MEM + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(M) :OP2 '(RB)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDMOV" + (OP :OP #xF1B + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(MB) :OP2 '(RB)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDMK" + (OP :OP #xF1B + :MOD :MEM + :PFX :F3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(RB) :OP2 '(M Y)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; Source: BNDMK-Make Bounds, Intel Vol. 2 (May 2018 Edition) + ;; "The reg-reg form of this instruction retains legacy behavior + ;; (NOP)." + (INST "RESERVEDNOP" + (OP :OP #xF1B + :MOD #x3 + :PFX :F3) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "BNDCN" + (OP :OP #xF1B + :PFX :F2 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-16)) + (ARG :OP1 '(RB) :OP2 '(E Y)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; Intel Vol. 2 (Table A-3) shows 0F 1C as Group 18, whose only + ;; instruction (Table A-6) is CLDEMOTE (NP 0F 1C /0 m8), a cache + ;; line hint that, according to its specification, does not modify + ;; architectural state and is treated as a NOP by processors that + ;; do not support it. We model it as a NOP, which omits two optional + ;; effects permitted by the specification: setting the A bit (but + ;; not the D bit) in the page tables, and aborting a TSX transaction. + ;; Earlier editions of the manual showed 0F 1C as a reserved NOP, + ;; which is where the mnemonic RESERVEDNOP used here comes from; we + ;; model all the other encodings of 0F 1C as NOPs, like 0F 19 above + ;; (see the comment there). + (INST "RESERVEDNOP" + (OP :OP #xF1C + :SUPERSCRIPTS '(:1A :1C)) + NIL + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; Intel Vol. 2 (Table A-3) shows 0F 1D as a reserved NOP, like + ;; 0F 19 above (see the comment there); no instruction has been + ;; defined in this opcode so far. + (INST "RESERVEDNOP" + (OP :OP #xF1D + :SUPERSCRIPTS '(:1A :1C)) + NIL + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + ;; Intel Vol. 2 (Table A-3) shows 0F 1E as a reserved NOP, i.e. an + ;; opcode reserved for future instructions, executed as a NOP by + ;; processors that do not implement them. Like the NOP 0F 1F /0 + ;; below, it takes a ModR/M byte, as shown by the encodings of the + ;; instructions defined in this opcode so far: ENDBR32 and ENDBR64 + ;; are F3 0F 1E FB and F3 0F 1E FA, where FB and FA are ModR/M bytes + ;; with mod = 3, reg = 7, and r/m = 3 and 2 respectively; RDSSPD and + ;; RDSSPQ are F3 0F 1E /1 with mod = 3. ENDBR32 and ENDBR64 have no + ;; :FEAT because they execute as NOPs on processors without CET + ;; (Intel Vol. 1, CET chapter). + (INST "ENDBR32" + (OP :OP #xF1E + :REG #x7 + :MOD #x3 + :R/M #x3 + :PFX :F3 + :SUPERSCRIPTS '(:1A :1C)) + NIL + '(X86-ENDBR32/ENDBR64) + '((:UD (UD-LOCK-USED)))) + (INST "ENDBR64" + (OP :OP #xF1E + :REG #x7 + :MOD #x3 + :R/M #x2 + :PFX :F3 + :SUPERSCRIPTS '(:1A :1C)) + NIL + '(X86-ENDBR32/ENDBR64) + '((:UD (UD-LOCK-USED)))) + ;; All the other encodings of 0F 1E, with or without prefixes, are + ;; NOPs: the ones not assigned to instructions are reserved NOPs, + ;; and RDSSPD/RDSSPQ are NOPs when CET shadow stacks are not + ;; enabled, as is always the case in this model. + (INST "RESERVEDNOP" + (OP :OP #xF1E + :SUPERSCRIPTS '(:1A :1C)) + NIL + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "NOP" (OP :OP #xF1F) + (ARG :OP1 '(E V)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "MOV" (OP :OP #xF20) + (ARG :OP1 '(R D) :OP2 '(C D)) + '(X86-MOV-CONTROL-REGS-OP/EN-MR) + '((:UD (UD-LOCK-USED) + (LET ((REG (MODR/M->REG MODR/M))) + (IF (AND (EQUAL PROC-MODE #x0) + (LOGBITP #x2 REX-BYTE)) + (NOT (EQUAL REG #x0)) + (OR (EQUAL REG #x1) + (EQUAL REG #x5) + (EQUAL REG #x6) + (EQUAL REG #x7))))) + (:GP (GP-CPL-NOT-0)))) + ;; This is move from debug register + ;; I made it a NOP because we don't have debug registers + (INST "MOV" (OP :OP #xF21) + (ARG :OP1 '(R D) :OP2 '(D D)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED) + (AND (EQUAL (CR4BITS->DE (CR4)) #x1) + (OR (EQUAL (MODR/M->REG MODR/M) #x4) + (EQUAL (MODR/M->REG MODR/M) #x5)))) + (:GP (GP-CPL-NOT-0)))) + (INST "MOV" (OP :OP #xF22) + (ARG :OP1 '(C D) :OP2 '(R D)) + '(X86-MOV-CONTROL-REGS-OP/EN-RM) + '((:UD (UD-LOCK-USED) + (LET ((REG (MODR/M->REG MODR/M))) + (IF (AND (EQUAL PROC-MODE #x0) + (LOGBITP #x2 REX-BYTE)) + (NOT (EQUAL REG #x0)) + (OR (EQUAL REG #x1) + (EQUAL REG #x5) + (EQUAL REG #x6) + (EQUAL REG #x7))))) + (:GP (GP-CPL-NOT-0)))) + ;; This is move to debug register + ;; I made it a NOP because we don't have debug registers + (INST "MOV" (OP :OP #xF23) + (ARG :OP1 '(D D) :OP2 '(R D)) + '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED) + (AND (EQUAL (CR4BITS->DE (CR4)) #x1) + (OR (EQUAL (MODR/M->REG MODR/M) #x4) + (EQUAL (MODR/M->REG MODR/M) #x5)))) + (:GP (GP-CPL-NOT-0)))) + (INST "MOVAPS" + (OP :OP #xF28 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-MOVAPS/MOVAPD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-1 (:SSE))))) + (INST "MOVAPD" + (OP :OP #xF28 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-MOVAPS/MOVAPD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-1 (:SSE2))))) + (INST "VMOVAPD" + (OP :OP #xF28 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-A) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPD" + (OP :OP #xF28 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-A) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPS" + (OP :OP #xF28 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-A) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPS" + (OP :OP #xF28 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-A) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPD" + (OP :OP #xF28 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPD" + (OP :OP #xF28 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPD" + (OP :OP #xF28 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512F))))) + (INST "VMOVAPS" + (OP :OP #xF28 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPS" + (OP :OP #xF28 + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPS" + (OP :OP #xF28 + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512F))))) + (INST "MOVAPS" + (OP :OP #xF29 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(W PS) :OP2 '(V PS)) + '(X86-MOVAPS/MOVAPD-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-1 (:SSE))))) + (INST "MOVAPD" + (OP :OP #xF29 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(W PD) :OP2 '(V PD)) + '(X86-MOVAPS/MOVAPD-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-1 (:SSE2))))) + (INST "VMOVAPD" + (OP :OP #xF29 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-B) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPD" + (OP :OP #xF29 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-B) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPS" + (OP :OP #xF29 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-B) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPS" + (OP :OP #xF29 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-B) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVAPD" + (OP :OP #xF29 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPD" + (OP :OP #xF29 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPD" + (OP :OP #xF29 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512F))))) + (INST "VMOVAPS" + (OP :OP #xF29 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPS" + (OP :OP #xF29 + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512VL :AVX512F))))) + (INST "VMOVAPS" + (OP :OP #xF29 + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1 (:AVX512F))))) + (INST "CVTPI2PS" + (OP :OP #xF2A + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) :OP2 '(Q PI)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-5 (:MMX))))) + (INST "CVTPI2PD" + (OP :OP #xF2A :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) :OP2 '(Q PI)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-6 (:MMX))))) + (INST "CVTSI2SS" + (OP :OP #xF2A :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(E Y)) + '(X86-CVTSI2S?-OP/EN-RM (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "CVTSI2SD" + (OP :OP #xF2A :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(E Y)) + '(X86-CVTSI2S?-OP/EN-RM (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VCVTSI2SD" + (OP :OP #xF2A + :VEX '(:0F :NDS :LIG :F2 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(E Y)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSI2SD" + (OP :OP #xF2A + :VEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(E Y)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSI2SS" + (OP :OP #xF2A + :VEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(E Y)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSI2SS" + (OP :OP #xF2A + :VEX '(:0F :NDS :LIG :F3 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(E Y)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSI2SD" + (OP :OP #xF2A + :EVEX '(:0F :NDS :LIG :F2 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10NF (:AVX512F))))) + (INST "VCVTSI2SD" + (OP :OP #xF2A + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10NF (:AVX512F))))) + (INST "VCVTSI2SS" + (OP :OP #xF2A + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTSI2SS" + (OP :OP #xF2A + :EVEX '(:0F :NDS :LIG :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "MOVNTPS" + (OP :OP #xF2B + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(M PS) :OP2 '(V PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-1 (:SSE))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "MOVNTPD" + (OP :OP #xF2B :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(M PD) :OP2 '(V PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-1 (:SSE2))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "VMOVNTPD" + (OP :OP #xF2B + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(M PD) :OP2 '(V PD)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVNTPD" + (OP :OP #xF2B + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(M PD) :OP2 '(V PD)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVNTPS" + (OP :OP #xF2B + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(M PS) :OP2 '(V PS)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVNTPS" + (OP :OP #xF2B + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(M PS) :OP2 '(V PS)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVNTPD" + (OP :OP #xF2B + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTPD" + (OP :OP #xF2B + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTPD" + (OP :OP #xF2B + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512F))))) + (INST "VMOVNTPS" + (OP :OP #xF2B + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTPS" + (OP :OP #xF2B + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTPS" + (OP :OP #xF2B + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512F))))) + (INST "CVTTPS2PI" + (OP :OP #xF2C + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P PI) :OP2 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-5 (:MMX))))) + (INST "CVTTPD2PI" + (OP :OP #xF2C :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(P PI) :OP2 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-4 (:MMX))))) + (INST "CVTTSS2SI" + (OP :OP #xF2C :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(G Y) :OP2 '(W SS)) + '(X86-CVTS?2SI/CVTTS?2SI-OP/EN-RM (SP/DP . #x0) + (TRUNC . T)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "CVTTSD2SI" + (OP :OP #xF2C :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(G Y) :OP2 '(W SD)) + '(X86-CVTS?2SI/CVTTS?2SI-OP/EN-RM (SP/DP . #x1) + (TRUNC . T)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VCVTTSD2SI" + (OP :OP #xF2C + :VEX '(:0F :LIG :F2 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTTSD2SI" + (OP :OP #xF2C + :VEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTTSS2SI" + (OP :OP #xF2C + :VEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTTSS2SI" + (OP :OP #xF2C + :VEX '(:0F :LIG :F3 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTTSD2SI" + (OP :OP #xF2C + :EVEX '(:0F :LIG :F2 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTTSD2SI" + (OP :OP #xF2C + :EVEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTTSS2SI" + (OP :OP #xF2C + :EVEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTTSS2SI" + (OP :OP #xF2C + :EVEX '(:0F :LIG :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "CVTPS2PI" + (OP :OP #xF2D + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P PI) :OP2 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-5 (:MMX))))) + (INST "CVTPD2PI" + (OP :OP #xF2D :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(Q PI) :OP2 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-4 (:MMX))))) + (INST "CVTSS2SI" + (OP :OP #xF2D :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(G Y) :OP2 '(W SS)) + '(X86-CVTS?2SI/CVTTS?2SI-OP/EN-RM (SP/DP . #x0) + (TRUNC)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "CVTSD2SI" + (OP :OP #xF2D :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(G Y) :OP2 '(W SD)) + '(X86-CVTS?2SI/CVTTS?2SI-OP/EN-RM (SP/DP . #x1) + (TRUNC)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VCVTSD2SI" + (OP :OP #xF2D + :VEX '(:0F :LIG :F2 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSD2SI" + (OP :OP #xF2D + :VEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSS2SI" + (OP :OP #xF2D + :VEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSS2SI" + (OP :OP #xF2D + :VEX '(:0F :LIG :F3 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSD2SI" + (OP :OP #xF2D + :EVEX '(:0F :LIG :F2 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTSD2SI" + (OP :OP #xF2D + :EVEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTSS2SI" + (OP :OP #xF2D + :EVEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTSS2SI" + (OP :OP #xF2D + :EVEX '(:0F :LIG :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "UCOMISS" + (OP :OP #xF2E + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V SS) :OP2 '(W SS)) + '(X86-COMIS?/UCOMIS?-OP/EN-RM (OPERATION . #x9) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "UCOMISD" + (OP :OP #xF2E :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) :OP2 '(W SD)) + '(X86-COMIS?/UCOMIS?-OP/EN-RM (OPERATION . #x9) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VUCOMISD" + (OP :OP #xF2E + :VEX '(:0F :LIG :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) :OP2 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VUCOMISS" + (OP :OP #xF2E + :VEX '(:0F :LIG :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) :OP2 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VUCOMISD" + (OP :OP #xF2E + :EVEX '(:0F :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VUCOMISS" + (OP :OP #xF2E + :EVEX '(:0F :LIG :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "COMISS" + (OP :OP #xF2F + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V SS) :OP2 '(W SS)) + '(X86-COMIS?/UCOMIS?-OP/EN-RM (OPERATION . #x9) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "COMISD" + (OP :OP #xF2F :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) :OP2 '(W SD)) + '(X86-COMIS?/UCOMIS?-OP/EN-RM (OPERATION . #x9) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VCOMISD" + (OP :OP #xF2F + :VEX '(:0F :LIG :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) :OP2 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCOMISS" + (OP :OP #xF2F + :VEX '(:0F :LIG :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) :OP2 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCOMISD" + (OP :OP #xF2F + :EVEX '(:0F :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCOMISS" + (OP :OP #xF2F + :EVEX '(:0F :LIG :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "WRMSR" (OP :OP #xF30) + NIL '(X86-WRMSR) + '((:UD (UD-LOCK-USED)))) + (INST "RDTSC" (OP :OP #xF31) + NIL '(X86-RDTSC) + '((:UD (UD-LOCK-USED)))) + (INST "RDMSR" (OP :OP #xF32) + NIL '(X86-RDMSR) + '((:UD (UD-LOCK-USED)))) + (INST "RDPMC" (OP :OP #xF33) + NIL 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (AND (GP-CPL-NOT-0) + (GP-CR4-PCE-IS-0))))) + (INST "SYSENTER" (OP :OP #xF34) + NIL 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (GP-CR0-PE-IS-0)))) + (INST "SYSEXIT" (OP :OP #xF35) + NIL 'NIL + '((:UD (UD-LOCK-USED)) + (:GP (GP-CPL-NOT-0) (GP-CR0-PE-IS-0)))) + (INST "GETSEC" (OP :OP #xF37) + NIL 'NIL + ;; TODO: Lock Used? Feature flag info? + 'NIL) + (INST :3-BYTE-ESCAPE (OP :OP #xF38) + 'NIL + '(THREE-BYTE-OPCODE-DECODE-AND-EXECUTE (SECOND-ESCAPE-BYTE . OPCODE)) + 'NIL) + (INST :3-BYTE-ESCAPE (OP :OP #xF3A) + 'NIL + '(THREE-BYTE-OPCODE-DECODE-AND-EXECUTE (SECOND-ESCAPE-BYTE . OPCODE)) + 'NIL) + (INST "CMOVO" (OP :OP #xF40) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "CMOVNO" (OP :OP #xF41) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KANDB" + (OP :OP #xF41 + :VEX '(:0F :L1 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-VEX B) + :OP3 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KANDD" + (OP :OP #xF41 + :VEX '(:0F :L1 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-VEX D) + :OP3 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KANDQ" + (OP :OP #xF41 + :VEX '(:0F :L1 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-VEX Q) + :OP3 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KANDW" + (OP :OP #xF41 + :VEX '(:0F :NDS :L1 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-VEX W) + :OP3 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "CMOVB/C/NAE" (OP :OP #xF42) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KANDNB" + (OP :OP #xF42 + :VEX '(:0F :L1 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-VEX B) + :OP3 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KANDND" + (OP :OP #xF42 + :VEX '(:0F :L1 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-VEX D) + :OP3 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KANDNQ" + (OP :OP #xF42 + :VEX '(:0F :L1 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-VEX Q) + :OP3 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KANDNW" + (OP :OP #xF42 + :VEX '(:0F :NDS :L1 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-VEX W) + :OP3 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "CMOVAE/NB/NC" (OP :OP #xF43) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "CMOVE/Z" (OP :OP #xF44) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KNOTB" + (OP :OP #xF44 + :VEX '(:0F :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KNOTD" + (OP :OP #xF44 + :VEX '(:0F :L0 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KNOTQ" + (OP :OP #xF44 + :VEX '(:0F :L0 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) :OP2 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KNOTW" + (OP :OP #xF44 + :VEX '(:0F :L0 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) :OP2 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "CMOVNE/NZ" (OP :OP #xF45) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KORB" + (OP :OP #xF45 + :VEX '(:0F :L1 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-VEX B) + :OP3 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KORD" + (OP :OP #xF45 + :VEX '(:0F :L1 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-VEX D) + :OP3 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KORQ" + (OP :OP #xF45 + :VEX '(:0F :L1 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-VEX Q) + :OP3 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KORW" + (OP :OP #xF45 + :VEX '(:0F :NDS :L1 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-VEX W) + :OP3 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "CMOVBE/NA" (OP :OP #xF46) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KXNORB" + (OP :OP #xF46 + :VEX '(:0F :L1 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-VEX B) + :OP3 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KXNORD" + (OP :OP #xF46 + :VEX '(:0F :L1 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-VEX D) + :OP3 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KXNORQ" + (OP :OP #xF46 + :VEX '(:0F :L1 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-VEX Q) + :OP3 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KXNORW" + (OP :OP #xF46 + :VEX '(:0F :NDS :L1 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-VEX W) + :OP3 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "CMOVA/NBE" (OP :OP #xF47) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KXORB" + (OP :OP #xF47 + :VEX '(:0F :L1 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-VEX B) + :OP3 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KXORD" + (OP :OP #xF47 + :VEX '(:0F :L1 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-VEX D) + :OP3 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KXORQ" + (OP :OP #xF47 + :VEX '(:0F :L1 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-VEX Q) + :OP3 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KXORW" + (OP :OP #xF47 + :VEX '(:0F :NDS :L1 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-VEX W) + :OP3 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "CMOVS" (OP :OP #xF48) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "CMOVNS" (OP :OP #xF49) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "CMOVP/PE" (OP :OP #xF4A) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KADDB" + (OP :OP #xF4A + :VEX '(:0F :L1 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-VEX B) + :OP3 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KADDD" + (OP :OP #xF4A + :VEX '(:0F :L1 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-VEX D) + :OP3 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KADDQ" + (OP :OP #xF4A + :VEX '(:0F :L1 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-VEX Q) + :OP3 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KADDW" + (OP :OP #xF4A + :VEX '(:0F :L1 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-VEX W) + :OP3 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "CMOVNP/PO" (OP :OP #xF4B) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "KUNPCKBW" + (OP :OP #xF4B + :VEX '(:0F :NDS :L1 :66 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-VEX W) + :OP3 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "KUNPCKDQ" + (OP :OP #xF4B + :VEX '(:0F :NDS :L1 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-VEX Q) + :OP3 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KUNPCKWD" + (OP :OP #xF4B + :VEX '(:0F :NDS :L1 :W0) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-VEX D) + :OP3 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "CMOVL/NGE" (OP :OP #xF4C) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "CMOVNL/GE" (OP :OP #xF4D) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "CMOVLE/NG" (OP :OP #xF4E) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "CMOVNLE/G" (OP :OP #xF4F) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-CMOVCC) + '((:UD (UD-LOCK-USED)))) + (INST "MOVMSKPS" + (OP :OP #xF50 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(G Y) :OP2 '(U PS)) + '(X86-MOVMSKPS-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE))))) + (INST "MOVMSKPD" + (OP :OP #xF50 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(G Y) :OP2 '(U PD)) + '(X86-MOVMSKPD-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "VMOVMSKPD" + (OP :OP #xF50 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(U PD)) + '(X86-VMOVMSKPD-VEX) + '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VMOVMSKPD" + (OP :OP #xF50 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(U PD)) + '(X86-VMOVMSKPD-VEX) + '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VMOVMSKPS" + (OP :OP #xF50 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(U PS)) + '(X86-VMOVMSKPS-VEX) + '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VMOVMSKPS" + (OP :OP #xF50 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(G Y) :OP2 '(U PS)) + '(X86-VMOVMSKPS-VEX) + '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "SQRTPS" + (OP :OP #xF51 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + '(X86-SQRTPS-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "SQRTPD" + (OP :OP #xF51 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + '(X86-SQRTPD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "SQRTSS" + (OP :OP #xF51 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + '(X86-SQRTS?-OP/EN-RM (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "SQRTSD" + (OP :OP #xF51 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + '(X86-SQRTS?-OP/EN-RM (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VSQRTPD" + (OP :OP #xF51 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSQRTPD" + (OP :OP #xF51 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSQRTPS" + (OP :OP #xF51 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSQRTPS" + (OP :OP #xF51 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSQRTSD" + (OP :OP #xF51 + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VSQRTSS" + (OP :OP #xF51 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VSQRTPD" + (OP :OP #xF51 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSQRTPD" + (OP :OP #xF51 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSQRTPD" + (OP :OP #xF51 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VSQRTPS" + (OP :OP #xF51 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSQRTPS" + (OP :OP #xF51 + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSQRTPS" + (OP :OP #xF51 + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VSQRTSD" + (OP :OP #xF51 + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VSQRTSS" + (OP :OP #xF51 + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "RSQRTPS" + (OP :OP #xF52 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "RSQRTSS" + (OP :OP #xF52 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "VRSQRTPS" + (OP :OP #xF52 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VRSQRTPS" + (OP :OP #xF52 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VRSQRTSS" + (OP :OP #xF52 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "RCPPS" + (OP :OP #xF53 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "RCPSS" + (OP :OP #xF53 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "VRCPPS" + (OP :OP #xF53 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VRCPPS" + (OP :OP #xF53 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VRCPSS" + (OP :OP #xF53 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "ANDPS" + (OP :OP #xF54 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x3)) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "ANDPD" + (OP :OP #xF54 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x3)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VANDPD" + (OP :OP #xF54 + :VEX '(:0F :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-AND*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDPD" + (OP :OP #xF54 + :VEX '(:0F :NDS :256 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-AND*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDPS" + (OP :OP #xF54 + :VEX '(:0F :NDS :128) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-AND*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDPS" + (OP :OP #xF54 + :VEX '(:0F :NDS :256) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDPD" + (OP :OP #xF54 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDPD" + (OP :OP #xF54 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDPD" + (OP :OP #xF54 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "VANDPS" + (OP :OP #xF54 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDPS" + (OP :OP #xF54 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDPS" + (OP :OP #xF54 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "ANDNPS" + (OP :OP #xF55 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #xD)) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "ANDNPD" + (OP :OP #xF55 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #xD)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VANDNPD" + (OP :OP #xF55 + :VEX '(:0F :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-ANDN*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDNPD" + (OP :OP #xF55 + :VEX '(:0F :NDS :256 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-ANDN*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDNPS" + (OP :OP #xF55 + :VEX '(:0F :NDS :128) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-ANDN*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDNPS" + (OP :OP #xF55 + :VEX '(:0F :NDS :256) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-ANDN*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VANDNPD" + (OP :OP #xF55 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDNPD" + (OP :OP #xF55 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDNPD" + (OP :OP #xF55 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "VANDNPS" + (OP :OP #xF55 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDNPS" + (OP :OP #xF55 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VANDNPS" + (OP :OP #xF55 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "ORPS" + (OP :OP #xF56 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x1)) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "ORPD" + (OP :OP #xF56 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x1)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VORPD" + (OP :OP #xF56 + :VEX '(:0F :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-OR*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VORPD" + (OP :OP #xF56 + :VEX '(:0F :NDS :256 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-OR*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VORPS" + (OP :OP #xF56 + :VEX '(:0F :NDS :128) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-OR*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VORPS" + (OP :OP #xF56 + :VEX '(:0F :NDS :256) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-OR*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VORPD" + (OP :OP #xF56 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VORPD" + (OP :OP #xF56 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VORPD" + (OP :OP #xF56 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "VORPS" + (OP :OP #xF56 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VORPS" + (OP :OP #xF56 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VORPS" + (OP :OP #xF56 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "XORPS" + (OP :OP #xF57 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "XORPD" + (OP :OP #xF57 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VXORPD" + (OP :OP #xF57 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VXORPD" + (OP :OP #xF57 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VXORPS" + (OP :OP #xF57 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VXORPS" + (OP :OP #xF57 + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VXORPD" + (OP :OP #xF57 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VXORPD" + (OP :OP #xF57 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VXORPD" + (OP :OP #xF57 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "VXORPS" + (OP :OP #xF57 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VXORPS" + (OP :OP #xF57 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VXORPS" + (OP :OP #xF57 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "ADDPS" + (OP :OP #xF58 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ADDPS/SUBPS/MULPS/DIVPS/MAXPS/MINPS-OP/EN-RM (OPERATION . #x0)) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "ADDPD" + (OP :OP #xF58 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ADDPD/SUBPD/MULPD/DIVPD/MAXPD/MINPD-OP/EN-RM (OPERATION . #x0)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "ADDSS" + (OP :OP #xF58 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x0) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "ADDSD" + (OP :OP #xF58 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x0) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VADDPD" + (OP :OP #xF58 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VADDPD" + (OP :OP #xF58 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VADDPS" + (OP :OP #xF58 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VADDPS" + (OP :OP #xF58 + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VADDSD" + (OP :OP #xF58 + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VADDSS" + (OP :OP #xF58 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VADDPD" + (OP :OP #xF58 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VADDPD" + (OP :OP #xF58 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VADDPD" + (OP :OP #xF58 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VADDPS" + (OP :OP #xF58 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VADDPS" + (OP :OP #xF58 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VADDPS" + (OP :OP #xF58 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VADDSD" + (OP :OP #xF58 + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VADDSS" + (OP :OP #xF58 + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "MULPS" + (OP :OP #xF59 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ADDPS/SUBPS/MULPS/DIVPS/MAXPS/MINPS-OP/EN-RM (OPERATION . #x1A)) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "MULPD" + (OP :OP #xF59 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ADDPD/SUBPD/MULPD/DIVPD/MAXPD/MINPD-OP/EN-RM (OPERATION . #x1A)) + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "MULSS" + (OP :OP #xF59 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x1A) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "MULSD" + (OP :OP #xF59 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x1A) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VMULPD" + (OP :OP #xF59 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMULPD" + (OP :OP #xF59 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMULPS" + (OP :OP #xF59 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMULPS" + (OP :OP #xF59 + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMULSD" + (OP :OP #xF59 + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VMULSS" + (OP :OP #xF59 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VMULPD" + (OP :OP #xF59 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMULPD" + (OP :OP #xF59 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMULPD" + (OP :OP #xF59 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VMULPS" + (OP :OP #xF59 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMULPS" + (OP :OP #xF59 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMULPS" + (OP :OP #xF59 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VMULSD" + (OP :OP #xF59 + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VMULSS" + (OP :OP #xF59 + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "CVTPS2PD" + (OP :OP #xF5A + :PFX :NO-PREFIX + :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) :OP2 '(W PS)) + '(X86-CVTPS2PD-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "CVTPD2PS" + (OP :OP #xF5A :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PS) :OP2 '(W PD)) + '(X86-CVTPD2PS-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "CVTSS2SD" + (OP :OP #xF5A :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H X) + :OP3 '(W SS)) + '(X86-CVTS?2S?-OP/EN-RM (DP-TO-SP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "CVTSD2SS" + (OP :OP #xF5A :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SS) + :OP2 '(H X) + :OP3 '(W SD)) + '(X86-CVTS?2S?-OP/EN-RM (DP-TO-SP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VCVTPD2PS" + (OP :OP #xF5A + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTPD2PS" + (OP :OP #xF5A + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTPS2PD" + (OP :OP #xF5A + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTPS2PD" + (OP :OP #xF5A + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSD2SS" + (OP :OP #xF5A + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H X) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTSS2SD" + (OP :OP #xF5A + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H X) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCVTPD2PS" + (OP :OP #xF5A + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPD2PS" + (OP :OP #xF5A + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPD2PS" + (OP :OP #xF5A + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTPS2PD" + (OP :OP #xF5A + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512VL :AVX512F))))) + (INST "VCVTPS2PD" + (OP :OP #xF5A + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512VL))))) + (INST "VCVTPS2PD" + (OP :OP #xF5A + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VCVTSD2SS" + (OP :OP #xF5A + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VCVTSS2SD" + (OP :OP #xF5A + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "CVTDQ2PS" + (OP :OP #xF5B + :PFX :NO-PREFIX + :FEAT '(:SSE2)) + (ARG :OP1 '(V PS) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "CVTPS2DQ" + (OP :OP #xF5B :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V DQ) :OP2 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "CVTTPS2DQ" + (OP :OP #xF5B :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(V DQ) :OP2 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "VCVTDQ2PS" + (OP :OP #xF5B + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W DQ)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTDQ2PS" + (OP :OP #xF5B + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) :OP2 '(W DQ)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTPS2DQ" + (OP :OP #xF5B + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTPS2DQ" + (OP :OP #xF5B + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTTPS2DQ" + (OP :OP #xF5B + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTTPS2DQ" + (OP :OP #xF5B + :VEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) :OP2 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTDQ2PS" + (OP :OP #xF5B + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTDQ2PS" + (OP :OP #xF5B + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTDQ2PS" + (OP :OP #xF5B + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTPS2DQ" + (OP :OP #xF5B + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPS2DQ" + (OP :OP #xF5B + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPS2DQ" + (OP :OP #xF5B + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTQQ2PS" + (OP :OP #xF5B + :EVEX '(:0F :128 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTQQ2PS" + (OP :OP #xF5B + :EVEX '(:0F :256 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTQQ2PS" + (OP :OP #xF5B + :EVEX '(:0F :512 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTTPS2DQ" + (OP :OP #xF5B + :EVEX '(:0F :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPS2DQ" + (OP :OP #xF5B + :EVEX '(:0F :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPS2DQ" + (OP :OP #xF5B + :EVEX '(:0F :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "SUBPS" + (OP :OP #xF5C + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ADDPS/SUBPS/MULPS/DIVPS/MAXPS/MINPS-OP/EN-RM (OPERATION . #x4)) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "SUBPD" + (OP :OP #xF5C :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ADDPD/SUBPD/MULPD/DIVPD/MAXPD/MINPD-OP/EN-RM (OPERATION . #x4)) + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "SUBSS" + (OP :OP #xF5C :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x4) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "SUBSD" + (OP :OP #xF5C :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x4) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VSUBPD" + (OP :OP #xF5C + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSUBPD" + (OP :OP #xF5C + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSUBPS" + (OP :OP #xF5C + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSUBPS" + (OP :OP #xF5C + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VSUBSD" + (OP :OP #xF5C + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VSUBSS" + (OP :OP #xF5C + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VSUBPD" + (OP :OP #xF5C + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSUBPD" + (OP :OP #xF5C + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSUBPD" + (OP :OP #xF5C + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VSUBPS" + (OP :OP #xF5C + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSUBPS" + (OP :OP #xF5C + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSUBPS" + (OP :OP #xF5C + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VSUBSD" + (OP :OP #xF5C + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VSUBSS" + (OP :OP #xF5C + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "MINPS" + (OP :OP #xF5D + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ADDPS/SUBPS/MULPS/DIVPS/MAXPS/MINPS-OP/EN-RM (OPERATION . #x24)) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "MINPD" + (OP :OP #xF5D :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ADDPD/SUBPD/MULPD/DIVPD/MAXPD/MINPD-OP/EN-RM (OPERATION . #x24)) + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "MINSS" + (OP :OP #xF5D :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x24) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "MINSD" + (OP :OP #xF5D :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x24) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VMINPD" + (OP :OP #xF5D + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMINPD" + (OP :OP #xF5D + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMINPS" + (OP :OP #xF5D + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMINPS" + (OP :OP #xF5D + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMINSD" + (OP :OP #xF5D + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VMINSS" + (OP :OP #xF5D + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMINPD" + (OP :OP #xF5D + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMINPD" + (OP :OP #xF5D + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMINPD" + (OP :OP #xF5D + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VMINPS" + (OP :OP #xF5D + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMINPS" + (OP :OP #xF5D + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMINPS" + (OP :OP #xF5D + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VMINSD" + (OP :OP #xF5D + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VMINSS" + (OP :OP #xF5D + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "DIVPS" + (OP :OP #xF5E + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ADDPS/SUBPS/MULPS/DIVPS/MAXPS/MINPS-OP/EN-RM (OPERATION . #x1C)) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "DIVPD" + (OP :OP #xF5E :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ADDPD/SUBPD/MULPD/DIVPD/MAXPD/MINPD-OP/EN-RM (OPERATION . #x1C)) + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "DIVSS" + (OP :OP #xF5E :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x1C) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "DIVSD" + (OP :OP #xF5E :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x1C) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VDIVPD" + (OP :OP #xF5E + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VDIVPD" + (OP :OP #xF5E + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VDIVPS" + (OP :OP #xF5E + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VDIVPS" + (OP :OP #xF5E + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VDIVSD" + (OP :OP #xF5E + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VDIVSS" + (OP :OP #xF5E + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VDIVPD" + (OP :OP #xF5E + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VDIVPD" + (OP :OP #xF5E + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VDIVPD" + (OP :OP #xF5E + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VDIVPS" + (OP :OP #xF5E + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VDIVPS" + (OP :OP #xF5E + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VDIVPS" + (OP :OP #xF5E + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VDIVSD" + (OP :OP #xF5E + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VDIVSS" + (OP :OP #xF5E + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "MAXPS" + (OP :OP #xF5F + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + '(X86-ADDPS/SUBPS/MULPS/DIVPS/MAXPS/MINPS-OP/EN-RM (OPERATION . #x22)) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "MAXPD" + (OP :OP #xF5F :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + '(X86-ADDPD/SUBPD/MULPD/DIVPD/MAXPD/MINPD-OP/EN-RM (OPERATION . #x22)) + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "MAXSS" + (OP :OP #xF5F :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x22) + (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "MAXSD" + (OP :OP #xF5F :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + '(X86-ADDS?/SUBS?/MULS?/DIVS?/MAXS?/MINS?-OP/EN-RM (OPERATION . #x22) + (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VMAXPD" + (OP :OP #xF5F + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMAXPD" + (OP :OP #xF5F + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMAXPS" + (OP :OP #xF5F + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMAXPS" + (OP :OP #xF5F + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VMAXSD" + (OP :OP #xF5F + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VMAXSS" + (OP :OP #xF5F + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VMAXPD" + (OP :OP #xF5F + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMAXPD" + (OP :OP #xF5F + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMAXPD" + (OP :OP #xF5F + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VMAXPS" + (OP :OP #xF5F + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMAXPS" + (OP :OP #xF5F + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VMAXPS" + (OP :OP #xF5F + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VMAXSD" + (OP :OP #xF5F + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VMAXSS" + (OP :OP #xF5F + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "PUNPCKLBW" + (OP :OP #xF60 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q D)) + '(X86-PUNPCKL-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PUNPCKLBW" + (OP :OP #xF60 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKL-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKLBW" + (OP :OP #xF60 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKLBW" + (OP :OP #xF60 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKLBW" + (OP :OP #xF60 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKLBW" + (OP :OP #xF60 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKLBW" + (OP :OP #xF60 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PUNPCKLWD" + (OP :OP #xF61 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q D)) + '(X86-PUNPCKL-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PUNPCKLWD" + (OP :OP #xF61 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKL-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKLWD" + (OP :OP #xF61 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKLWD" + (OP :OP #xF61 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKLWD" + (OP :OP #xF61 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKLWD" + (OP :OP #xF61 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKLWD" + (OP :OP #xF61 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PUNPCKLDQ" + (OP :OP #xF62 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q D)) + '(X86-PUNPCKL-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PUNPCKLDQ" + (OP :OP #xF62 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKL-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKLDQ" + (OP :OP #xF62 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKLDQ" + (OP :OP #xF62 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKLDQ" + (OP :OP #xF62 + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKLDQ" + (OP :OP #xF62 + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKLDQ" + (OP :OP #xF62 + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "PACKSSWB" + (OP :OP #xF63 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PACKSSWB-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PACKSSWB" + (OP :OP #xF63 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPACKSSWB" + (OP :OP #xF63 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPACKSSWB" + (OP :OP #xF63 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPACKSSWB" + (OP :OP #xF63 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPACKSSWB" + (OP :OP #xF63 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPACKSSWB" + (OP :OP #xF63 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PCMPGTB" + (OP :OP #xF64 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PCMPGTB/PCMPGTW/PCMPGTD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PCMPGTB" + (OP :OP #xF64 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PCMPGTB/PCMPGTW/PCMPGTD-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPCMPGTB" + (OP :OP #xF64 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPGTB/VPCMPGTW/VPCMPGTD/VPCMPGTQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPGTB" + (OP :OP #xF64 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPGTB/VPCMPGTW/VPCMPGTD/VPCMPGTQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPGTB" + (OP :OP #xF64 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPGTB" + (OP :OP #xF64 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPGTB" + (OP :OP #xF64 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PCMPGTW" + (OP :OP #xF65 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PCMPGTB/PCMPGTW/PCMPGTD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PCMPGTW" + (OP :OP #xF65 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PCMPGTB/PCMPGTW/PCMPGTD-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPCMPGTW" + (OP :OP #xF65 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPGTB/VPCMPGTW/VPCMPGTD/VPCMPGTQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPGTW" + (OP :OP #xF65 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPGTB/VPCMPGTW/VPCMPGTD/VPCMPGTQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPGTW" + (OP :OP #xF65 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPGTW" + (OP :OP #xF65 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPGTW" + (OP :OP #xF65 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PCMPGTD" + (OP :OP #xF66 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PCMPGTB/PCMPGTW/PCMPGTD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PCMPGTD" + (OP :OP #xF66 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PCMPGTB/PCMPGTW/PCMPGTD-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPCMPGTD" + (OP :OP #xF66 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPGTB/VPCMPGTW/VPCMPGTD/VPCMPGTQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPGTD" + (OP :OP #xF66 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPGTB/VPCMPGTW/VPCMPGTD/VPCMPGTQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPGTD" + (OP :OP #xF66 + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPGTD" + (OP :OP #xF66 + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPGTD" + (OP :OP #xF66 + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PACKUSWB" + (OP :OP #xF67 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PACKUSWB-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PACKUSWB" + (OP :OP #xF67 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PACKUSWB-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPACKUSWB" + (OP :OP #xF67 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPACKUSWB" + (OP :OP #xF67 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPACKUSWB" + (OP :OP #xF67 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPACKUSWB" + (OP :OP #xF67 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPACKUSWB" + (OP :OP #xF67 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PUNPCKHBW" + (OP :OP #xF68 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q D)) + '(X86-PUNPCKH-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PUNPCKHBW" + (OP :OP #xF68 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKH-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKHBW" + (OP :OP #xF68 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKHBW" + (OP :OP #xF68 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKHBW" + (OP :OP #xF68 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKHBW" + (OP :OP #xF68 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKHBW" + (OP :OP #xF68 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PUNPCKHWD" + (OP :OP #xF69 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q D)) + '(X86-PUNPCKH-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PUNPCKHWD" + (OP :OP #xF69 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKH-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKHWD" + (OP :OP #xF69 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKHWD" + (OP :OP #xF69 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKHWD" + (OP :OP #xF69 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKHWD" + (OP :OP #xF69 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPUNPCKHWD" + (OP :OP #xF69 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PUNPCKHDQ" + (OP :OP #xF6A + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q D)) + '(X86-PUNPCKH-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PUNPCKHDQ" + (OP :OP #xF6A :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKH-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKHDQ" + (OP :OP #xF6A + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKHDQ" + (OP :OP #xF6A + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKHDQ" + (OP :OP #xF6A + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKHDQ" + (OP :OP #xF6A + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKHDQ" + (OP :OP #xF6A + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "PACKSSDW" + (OP :OP #xF6B + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q D)) + '(X86-PACKSSDW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PACKSSDW" + (OP :OP #xF6B :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPACKSSDW" + (OP :OP #xF6B + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPACKSSDW" + (OP :OP #xF6B + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPACKSSDW" + (OP :OP #xF6B + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512BW))))) + (INST "VPACKSSDW" + (OP :OP #xF6B + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512BW))))) + (INST "VPACKSSDW" + (OP :OP #xF6B + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512BW))))) + (INST "PUNPCKLQDQ" + (OP :OP #xF6C :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKL-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKLQDQ" + (OP :OP #xF6C + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKLQDQ" + (OP :OP #xF6C + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKLQDQ" + (OP :OP #xF6C + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKLQDQ" + (OP :OP #xF6C + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKLQDQ" + (OP :OP #xF6C + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "PUNPCKHQDQ" + (OP :OP #xF6D :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PUNPCKH-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPUNPCKHQDQ" + (OP :OP #xF6D + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPUNPCKHQDQ" + (OP :OP #xF6D + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPUNPCKHQDQ" + (OP :OP #xF6D + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKHQDQ" + (OP :OP #xF6D + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPUNPCKHQDQ" + (OP :OP #xF6D + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "MOVD/Q" + (OP :OP #xF6E + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P D) :OP2 '(E Y)) + '(X86-MOVD/MOVQ-TO-MMX) + '((:EX (CHK-EXC :TYPE-22-8 (:MMX))))) + (INST "MOVD/Q" + (OP :OP #xF6E :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V Y) :OP2 '(E Y)) + '(X86-MOVD/MOVQ-TO-XMM) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "VMOVQ" + (OP :OP #xF6E + :VEX '(:0F :128 :66 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(V Q) :OP2 '(W Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVD" + (OP :OP #xF6E + :VEX '(:0F :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V Q) :OP2 '(W Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVD" + (OP :OP #xF6E + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVQ" + (OP :OP #xF6E + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "MOVQ" + (OP :OP #xF6F + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-MOVQ-FROM-MMX/MEM) + '((:EX (CHK-EXC :TYPE-22-8 (:MMX))))) + (INST "MOVDQA" + (OP :OP #xF6F :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-MOVDQA-TO-XMM) + '((:EX (CHK-EXC :TYPE-1 (:SSE2))))) + (INST "MOVDQU" + (OP :OP #xF6F :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VMOVDQA" + (OP :OP #xF6F + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-A) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVDQA" + (OP :OP #xF6F + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-A) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVDQU" + (OP :OP #xF6F + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-A) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVDQU" + (OP :OP #xF6F + :VEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-A) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVDQA32" + (OP :OP #xF6F + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA32" + (OP :OP #xF6F + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA32" + (OP :OP #xF6F + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQA64" + (OP :OP #xF6F + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA64" + (OP :OP #xF6F + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA64" + (OP :OP #xF6F + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQU16" + (OP :OP #xF6F + :EVEX '(:0F :128 :F2 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU16" + (OP :OP #xF6F + :EVEX '(:0F :256 :F2 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU16" + (OP :OP #xF6F + :EVEX '(:0F :512 :F2 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "VMOVDQU32" + (OP :OP #xF6F + :EVEX '(:0F :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU32" + (OP :OP #xF6F + :EVEX '(:0F :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU32" + (OP :OP #xF6F + :EVEX '(:0F :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQU64" + (OP :OP #xF6F + :EVEX '(:0F :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU64" + (OP :OP #xF6F + :EVEX '(:0F :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU64" + (OP :OP #xF6F + :EVEX '(:0F :512 :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQU8" + (OP :OP #xF6F + :EVEX '(:0F :128 :F2 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU8" + (OP :OP #xF6F + :EVEX '(:0F :256 :F2 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU8" + (OP :OP #xF6F + :EVEX '(:0F :512 :F2 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "PSHUFW" + (OP :OP #xF70 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) + :OP2 '(Q Q) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSHUFD" + (OP :OP #xF70 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + '(X86-PSHUFD) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "PSHUFHW" + (OP :OP #xF70 :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + '(X86-PSHUFHW) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "PSHUFLW" + (OP :OP #xF70 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + '(X86-PSHUFLW) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSHUFD" + (OP :OP #xF70 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSHUFD" + (OP :OP #xF70 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSHUFHW" + (OP :OP #xF70 + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSHUFHW" + (OP :OP #xF70 + :VEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSHUFLW" + (OP :OP #xF70 + :VEX '(:0F :128 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSHUFLW" + (OP :OP #xF70 + :VEX '(:0F :256 :F2 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSHUFD" + (OP :OP #xF70 + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSHUFD" + (OP :OP #xF70 + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSHUFD" + (OP :OP #xF70 + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPSHUFHW" + (OP :OP #xF70 + :EVEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSHUFHW" + (OP :OP #xF70 + :EVEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSHUFHW" + (OP :OP #xF70 + :EVEX '(:0F :512 :F3 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPSHUFLW" + (OP :OP #xF70 + :EVEX '(:0F :128 :F2 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSHUFLW" + (OP :OP #xF70 + :EVEX '(:0F :256 :F2 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSHUFLW" + (OP :OP #xF70 + :EVEX '(:0F :512 :F2 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PSRLW" + (OP :OP #xF71 + :REG #x2 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-12) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSRL-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRLW" + (OP :OP #xF71 + :REG #x2 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-12) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSRL-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "PSRAW" + (OP :OP #xF71 + :REG #x4 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-12) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSRA-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRAW" + (OP :OP #xF71 + :REG #x4 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-12) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSRA-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "PSLLW" + (OP :OP #xF71 + :REG #x6 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-12) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSLL-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSLLW" + (OP :OP #xF71 + :REG #x6 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-12) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSLL-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "VPSRLW" + (OP :OP #xF71 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x2) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VPSRLW" + (OP :OP #xF71 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x2) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPSRAW" + (OP :OP #xF71 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x4) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VPSRAW" + (OP :OP #xF71 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x4) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPSLLW" + (OP :OP #xF71 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x6) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VPSLLW" + (OP :OP #xF71 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x6) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPSRLW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :512 :66 :WIG) + :FEAT '(:AVX512BW) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPSRAW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRAW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX512BW) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPSRAW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :512 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLW" + (OP :OP #xF71 + :EVEX '(:0F :NDD :512 :66 :WIG) + :FEAT '(:AVX512BW) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PSRLD" + (OP :OP #xF72 + :REG #x2 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-13) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSRL-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRLD" + (OP :OP #xF72 + :REG #x2 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-13) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSRL-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "PSRAD" + (OP :OP #xF72 + :REG #x4 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-13) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSRA-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRAD" + (OP :OP #xF72 + :REG #x4 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-13) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSRA-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "PSLLD" + (OP :OP #xF72 + :REG #x6 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-13) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSLL-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSLLD" + (OP :OP #xF72 + :REG #x6 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-13) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSLL-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "VPSLLD" + (OP :OP #xF72 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x2) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VPSLLD" + (OP :OP #xF72 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x2) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPSRAW" + (OP :OP #xF72 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x4) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VPSRAW" + (OP :OP #xF72 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x4) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPSLLW" + (OP :OP #xF72 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x6) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VPSLLW" + (OP :OP #xF72 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x6) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPRORD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x0) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPRORQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F) + :REG #x0) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPRORD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x0) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPRORQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F) + :REG #x0) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPRORD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W0) + :FEAT '(:AVX512F) + :REG #x0) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPRORQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W1) + :FEAT '(:AVX512F) + :REG #x0) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPROLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPROLQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPROLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPROLQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPROLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W0) + :FEAT '(:AVX512F) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPROLQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W1) + :FEAT '(:AVX512F) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPSRLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSRLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSRLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W0) + :FEAT '(:AVX512F) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPSRAD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSRAQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSRAD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSRAQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSRAD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W0) + :FEAT '(:AVX512F) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPSRAQ" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W1) + :FEAT '(:AVX512F) + :REG #x4) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPSLLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSLLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPSLLD" + (OP :OP #xF72 + :EVEX '(:0F :NDD :512 :66 :W0) + :FEAT '(:AVX512F) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "PSRLQ" + (OP :OP #xF73 + :REG #x2 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-14) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSRL-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRLQ" + (OP :OP #xF73 + :REG #x2 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-14) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSRL-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "PSRLDQ" + (OP :OP #xF73 + :REG #x3 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-14) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSLLDQ/PSRLDQ) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "PSLLQ" + (OP :OP #xF73 + :REG #x6 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-14) + :FEAT '(:MMX)) + (ARG :OP1 '(N Q) :OP2 '(I B)) + '(X86-PSLL-IMM-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSLLQ" + (OP :OP #xF73 + :REG #x6 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-14) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSLL-IMM-SSE) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "PSLLDQ" + (OP :OP #xF73 + :REG #x7 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-14) + :FEAT '(:SSE2)) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + '(X86-PSLLDQ/PSRLDQ) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "VPSRLQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x2) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSRLQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x2) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLDQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x3) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSRLDQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x3) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x6) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSLLQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x6) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLDQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX) + :REG #x7) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSLLDQ" + (OP :OP #xF73 + :VEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX2) + :REG #x7) + (ARG :OP1 '(H X) + :OP2 '(U X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :512 :66 :W1) + :FEAT '(:AVX512BW) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPSRLDQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x3) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLDQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x3) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLDQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :512 :66 :WIG) + :FEAT '(:AVX512BW) + :REG #x3) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPSLLQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :512 :66 :W1) + :FEAT '(:AVX512BW) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPSLLDQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x7) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLDQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW) + :REG #x7) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLDQ" + (OP :OP #xF73 + :EVEX '(:0F :NDD :512 :66 :WIG) + :FEAT '(:AVX512BW) + :REG #x7) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PCMPEQB" + (OP :OP #xF74 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PCMPEQB/PCMPEQW/PCMPEQD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PCMPEQB" + (OP :OP #xF74 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PCMPEQB/PCMPEQW/PCMPEQD-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPCMPEQB" + (OP :OP #xF74 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPEQB" + (OP :OP #xF74 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPEQB" + (OP :OP #xF74 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPEQB" + (OP :OP #xF74 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPEQB" + (OP :OP #xF74 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PCMPEQW" + (OP :OP #xF75 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PCMPEQB/PCMPEQW/PCMPEQD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PCMPEQW" + (OP :OP #xF75 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PCMPEQB/PCMPEQW/PCMPEQD-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPCMPEQW" + (OP :OP #xF75 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPEQW" + (OP :OP #xF75 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPEQW" + (OP :OP #xF75 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPEQW" + (OP :OP #xF75 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPEQW" + (OP :OP #xF75 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PCMPEQD" + (OP :OP #xF76 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PCMPEQB/PCMPEQW/PCMPEQD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PCMPEQD" + (OP :OP #xF76 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PCMPEQB/PCMPEQW/PCMPEQD-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPCMPEQD" + (OP :OP #xF76 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPEQD" + (OP :OP #xF76 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPEQD" + (OP :OP #xF76 + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPEQD" + (OP :OP #xF76 + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPEQD" + (OP :OP #xF76 + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "EMMS" (OP :OP #xF77 :PFX :NO-PREFIX) + NIL + '(X86-EMMS) + '((:UD (UD-LOCK-USED) + (EQUAL (CR0BITS->EM (CR0)) #x1)) + (:NM (NM-CR0-TS-IS-1)))) + (INST "VZEROALL" + (OP :OP #xF77 + :VEX '(:0F :256 :WIG) + :FEAT '(:AVX)) + NIL + NIL '((:EX (CHK-EXC :TYPE-8 (:AVX))))) + (INST "VZEROUPPER" + (OP :OP #xF77 + :VEX '(:0F :128 :WIG) + :FEAT '(:AVX)) + NIL + '(x86-vzeroupper) '((:EX (CHK-EXC :TYPE-8 (:AVX))))) + (INST "MREAD" (OP :OP #xF78) + (ARG :OP1 '(E Y) :OP2 '(G Y)) + 'NIL + '((:GP (GP-CPL-NOT-0)))) + (INST "VCVTTPD2UDQ" + (OP :OP #xF78 + :EVEX '(:0F :256 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPD2UDQ" + (OP :OP #xF78 + :EVEX '(:0F :128 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPD2UDQ" + (OP :OP #xF78 + :EVEX '(:0F :512 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTTPD2UQQ" + (OP :OP #xF78 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPD2UQQ" + (OP :OP #xF78 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPD2UQQ" + (OP :OP #xF78 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTTPS2UDQ" + (OP :OP #xF78 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPS2UDQ" + (OP :OP #xF78 + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPS2UDQ" + (OP :OP #xF78 + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTTPS2UQQ" + (OP :OP #xF78 + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPS2UQQ" + (OP :OP #xF78 + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPS2UQQ" + (OP :OP #xF78 + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTTSD2USI" + (OP :OP #xF78 + :EVEX '(:0F :LIG :F2 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTTSD2USI" + (OP :OP #xF78 + :EVEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTTSS2USI" + (OP :OP #xF78 + :EVEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTTSS2USI" + (OP :OP #xF78 + :EVEX '(:0F :LIG :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "MWRITE" (OP :OP #xF79) + (ARG :OP1 '(E Y) :OP2 '(G Y)) + 'NIL + '((:GP (GP-CPL-NOT-0)))) + (INST "VCVTPD2UDQ" + (OP :OP #xF79 + :EVEX '(:0F :128 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPD2UDQ" + (OP :OP #xF79 + :EVEX '(:0F :256 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPD2UDQ" + (OP :OP #xF79 + :EVEX '(:0F :512 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTPD2UQQ" + (OP :OP #xF79 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPD2UQQ" + (OP :OP #xF79 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPD2UQQ" + (OP :OP #xF79 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTPS2UDQ" + (OP :OP #xF79 + :EVEX '(:0F :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPS2UDQ" + (OP :OP #xF79 + :EVEX '(:0F :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPS2UDQ" + (OP :OP #xF79 + :EVEX '(:0F :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTPS2UQQ" + (OP :OP #xF79 + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPS2UQQ" + (OP :OP #xF79 + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPS2UQQ" + (OP :OP #xF79 + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTSD2USI" + (OP :OP #xF79 + :EVEX '(:0F :LIG :F2 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTSD2USI" + (OP :OP #xF79 + :EVEX '(:0F :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTSS2USI" + (OP :OP #xF79 + :EVEX '(:0F :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTSS2USI" + (OP :OP #xF79 + :EVEX '(:0F :LIG :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTTPD2QQ" + (OP :OP #xF7A + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPD2QQ" + (OP :OP #xF7A + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPD2QQ" + (OP :OP #xF7A + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTTPS2QQ" + (OP :OP #xF7A + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPS2QQ" + (OP :OP #xF7A + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTTPS2QQ" + (OP :OP #xF7A + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTUDQ2PD" + (OP :OP #xF7A + :EVEX '(:0F :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTUDQ2PD" + (OP :OP #xF7A + :EVEX '(:0F :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTUDQ2PD" + (OP :OP #xF7A + :EVEX '(:0F :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTUDQ2PS" + (OP :OP #xF7A + :EVEX '(:0F :128 :F2 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTUDQ2PS" + (OP :OP #xF7A + :EVEX '(:0F :256 :F2 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTUDQ2PS" + (OP :OP #xF7A + :EVEX '(:0F :512 :F2 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTUQQ2PD" + (OP :OP #xF7A + :EVEX '(:0F :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTUQQ2PD" + (OP :OP #xF7A + :EVEX '(:0F :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTUQQ2PD" + (OP :OP #xF7A + :EVEX '(:0F :512 :F3 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTUQQ2PS" + (OP :OP #xF7A + :EVEX '(:0F :128 :F2 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTUQQ2PS" + (OP :OP #xF7A + :EVEX '(:0F :256 :F2 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTUQQ2PS" + (OP :OP #xF7A + :EVEX '(:0F :512 :F2 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTPD2QQ" + (OP :OP #xF7B + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPD2QQ" + (OP :OP #xF7B + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPD2QQ" + (OP :OP #xF7B + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTPS2QQ" + (OP :OP #xF7B + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPS2QQ" + (OP :OP #xF7B + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTPS2QQ" + (OP :OP #xF7B + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTUSI2SD" + (OP :OP #xF7B + :EVEX '(:0F :NDS :LIG :F2 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10NF (:AVX512F))))) + (INST "VCVTUSI2SD" + (OP :OP #xF7B + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10NF (:AVX512F))))) + (INST "VCVTUSI2SS" + (OP :OP #xF7B + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "VCVTUSI2SS" + (OP :OP #xF7B + :EVEX '(:0F :NDS :LIG :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3NF (:AVX512F))))) + (INST "HADDPD" + (OP :OP #xF7C :PFX :66 :FEAT '(:SSE3)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE3))))) + (INST "HADDPS" + (OP :OP #xF7C :PFX :F2 :FEAT '(:SSE3)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE3))))) + (INST "VHADDPD" + (OP :OP #xF7C + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VHADDPD" + (OP :OP #xF7C + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VHADDPS" + (OP :OP #xF7C + :VEX '(:0F :NDS :128 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VHADDPS" + (OP :OP #xF7C + :VEX '(:0F :NDS :256 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "HSUBPD" + (OP :OP #xF7D :PFX :66 :FEAT '(:SSE3)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE3))))) + (INST "HSUBPS" + (OP :OP #xF7D :PFX :F2 :FEAT '(:SSE3)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE3))))) + (INST "VHSUBPD" + (OP :OP #xF7D + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VHSUBPD" + (OP :OP #xF7D + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VHSUBPS" + (OP :OP #xF7D + :VEX '(:0F :NDS :128 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VHSUBPS" + (OP :OP #xF7D + :VEX '(:0F :NDS :256 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "MOVD/Q" + (OP :OP #xF7E + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(E Y) :OP2 '(P D)) + '(X86-MOVD/MOVQ-FROM-MMX) + '((:EX (CHK-EXC :TYPE-22-8 (:MMX))))) + (INST "MOVD/Q" + (OP :OP #xF7E :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(E Y) :OP2 '(V Y)) + '(X86-MOVD/MOVQ-FROM-XMM) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "MOVQ" + (OP :OP #xF7E :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(V Q) :OP2 '(W Q)) + '(X86-MOVQ-FROM-XMM/MEM) + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "VMOVD" + (OP :OP #xF7E + :VEX '(:0F :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(E Y) :OP2 '(V Y)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVQ" + (OP :OP #xF7E + :VEX '(:0F :128 :66 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(V Q) :OP2 '(W Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVQ" + (OP :OP #xF7E + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V Q) :OP2 '(W Q)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VMOVD" + (OP :OP #xF7E + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVQ" + (OP :OP #xF7E + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVQ" + (OP :OP #xF7E + :EVEX '(:0F :128 :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "MOVQ" + (OP :OP #xF7F + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(Q Q) :OP2 '(P Q)) + '(X86-MOVQ-TO-MMX/MEM) + '((:EX (CHK-EXC :TYPE-22-8 (:MMX))))) + (INST "MOVDQA" + (OP :OP #xF7F :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(W X) :OP2 '(V X)) + '(X86-MOVDQA-FROM-XMM) + '((:EX (CHK-EXC :TYPE-1 (:SSE2))))) + (INST "MOVDQU" + (OP :OP #xF7F :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(W X) :OP2 '(V X)) + '(X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-MR) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VMOVDQA" + (OP :OP #xF7F + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-B) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVDQA" + (OP :OP #xF7F + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVAPS/VMOVAPD/VMOVDQA-VEX-B) + '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVDQU" + (OP :OP #xF7F + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-B) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVDQU" + (OP :OP #xF7F + :VEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + '(X86-VMOVUPS/VMOVUPD/VMOVDQU-VEX-B) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVDQA32" + (OP :OP #xF7F + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA32" + (OP :OP #xF7F + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA32" + (OP :OP #xF7F + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQA64" + (OP :OP #xF7F + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA64" + (OP :OP #xF7F + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQA64" + (OP :OP #xF7F + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQU16" + (OP :OP #xF7F + :EVEX '(:0F :128 :F2 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU16" + (OP :OP #xF7F + :EVEX '(:0F :256 :F2 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU16" + (OP :OP #xF7F + :EVEX '(:0F :512 :F2 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "VMOVDQU32" + (OP :OP #xF7F + :EVEX '(:0F :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU32" + (OP :OP #xF7F + :EVEX '(:0F :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU32" + (OP :OP #xF7F + :EVEX '(:0F :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQU64" + (OP :OP #xF7F + :EVEX '(:0F :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU64" + (OP :OP #xF7F + :EVEX '(:0F :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512F))))) + (INST "VMOVDQU64" + (OP :OP #xF7F + :EVEX '(:0F :512 :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VMOVDQU8" + (OP :OP #xF7F + :EVEX '(:0F :128 :F2 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU8" + (OP :OP #xF7F + :EVEX '(:0F :256 :F2 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512VL :AVX512BW))))) + (INST "VMOVDQU8" + (OP :OP #xF7F + :EVEX '(:0F :512 :F2 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "JO" + (OP :OP #xF80 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNO" + (OP :OP #xF81 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JB/NAE/C" + (OP :OP #xF82 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNB/AE/NC" + (OP :OP #xF83 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JZ/E" + (OP :OP #xF84 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNZ/NE" + (OP :OP #xF85 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JBE/NA" + (OP :OP #xF86 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNBE/A" + (OP :OP #xF87 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JS" + (OP :OP #xF88 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNS" + (OP :OP #xF89 :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JP/PE" + (OP :OP #xF8A :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNP/PO" + (OP :OP #xF8B :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JL/NGE" + (OP :OP #xF8C :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNL/GE" + (OP :OP #xF8D :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JLE/NG" + (OP :OP #xF8E :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "JNLE/G" + (OP :OP #xF8F :SUPERSCRIPTS '(:F64)) + (ARG :OP1 '(J Z)) + '(X86-TWO-BYTE-JCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETO" (OP :OP #xF90) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "KMOVB" + (OP :OP #xF90 + :VEX '(:0F :L0 :66 :W0) + :FEAT '(:AVX512DQ)) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512DQ))))) + (INST "KMOVD" + (OP :OP #xF90 + :VEX '(:0F :L0 :66 :W1) + :FEAT '(:AVX512BW)) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512BW))))) + (INST "KMOVQ" + (OP :OP #xF90 + :VEX '(:0F :L0 :W1) + :FEAT '(:AVX512BW)) + (ARG :OP1 '(K-REG Q) :OP2 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512BW))))) + (INST "KMOVW" + (OP :OP #xF90 + :VEX '(:0F :L0 :W0) + :FEAT '(:AVX512F)) + (ARG :OP1 '(K-REG W) :OP2 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512F))))) + (INST "SETNO" (OP :OP #xF91) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "KMOVB" + (OP :OP #xF91 + :VEX '(:0F :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD :MEM) + (ARG :OP1 '(K-R/M B) + :OP2 '(K-REG B)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512DQ))))) + (INST "KMOVD" + (OP :OP #xF91 + :VEX '(:0F :L0 :66 :W1) + :FEAT '(:AVX512BW) + :MOD :MEM) + (ARG :OP1 '(K-R/M D) + :OP2 '(K-REG D)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512BW))))) + (INST "KMOVQ" + (OP :OP #xF91 + :VEX '(:0F :L0 :W1) + :FEAT '(:AVX512BW) + :MOD :MEM) + (ARG :OP1 '(K-R/M Q) :OP2 '(K-REG Q)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512BW))))) + (INST "KMOVW" + (OP :OP #xF91 + :VEX '(:0F :L0 :W0) + :FEAT '(:AVX512F) + :MOD :MEM) + (ARG :OP1 '(K-R/M W) :OP2 '(K-REG W)) + NIL + '((:EX (CHK-EXC :TYPE-K21 (:AVX512F))))) + (INST "SETB/NAE/C" (OP :OP #xF92) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "KMOVB" + (OP :OP #xF92 + :VEX '(:0F :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KMOVD" + (OP :OP #xF92 + :VEX '(:0F :L0 :F2 :W0) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KMOVQ" + (OP :OP #xF92 + :VEX '(:0F :L0 :F2 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) :OP2 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KMOVW" + (OP :OP #xF92 + :VEX '(:0F :L0 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) :OP2 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "SETNB/AE/NC" (OP :OP #xF93) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "KMOVB" + (OP :OP #xF93 + :VEX '(:0F :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KMOVD" + (OP :OP #xF93 + :VEX '(:0F :L0 :F2 :W0) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KMOVQ" + (OP :OP #xF93 + :VEX '(:0F :L0 :F2 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) :OP2 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KMOVW" + (OP :OP #xF93 + :VEX '(:0F :L0 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) :OP2 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "SETZ/E" (OP :OP #xF94) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETNZ/NE" (OP :OP #xF95) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETBE/NA" (OP :OP #xF96) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETNBE/A" (OP :OP #xF97) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETS" (OP :OP #xF98) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "KORTESTB" + (OP :OP #xF98 + :VEX '(:0F :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KORTESTD" + (OP :OP #xF98 + :VEX '(:0F :L0 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KORTESTQ" + (OP :OP #xF98 + :VEX '(:0F :L0 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) :OP2 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KORTESTW" + (OP :OP #xF98 + :VEX '(:0F :L0 :W0) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) :OP2 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "SETNS" (OP :OP #xF99) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "KTESTB" + (OP :OP #xF99 + :VEX '(:0F :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KTESTD" + (OP :OP #xF99 + :VEX '(:0F :L0 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KTESTQ" + (OP :OP #xF99 + :VEX '(:0F :L0 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) :OP2 '(K-R/M Q)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KTESTW" + (OP :OP #xF99 + :VEX '(:0F :L0 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG W) :OP2 '(K-R/M W)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "SETP/PE" (OP :OP #xF9A) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETNP/PO" (OP :OP #xF9B) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETL/NGE" (OP :OP #xF9C) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETNL/GE" (OP :OP #xF9D) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETLE/NG" (OP :OP #xF9E) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "SETNLE/G" (OP :OP #xF9F) + (ARG :OP1 '(E B)) + '(X86-SETCC) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH FS" + (OP :OP #xFA0 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:FS)) + '(X86-PUSH-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP FS" + (OP :OP #xFA1 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:FS)) + '(X86-POP-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "CPUID" (OP :OP #xFA2) + NIL '(X86-CPUID) + '((:UD (UD-LOCK-USED)))) + (INST "BT" (OP :OP #xFA3) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-BT-0F-A3) + '((:UD (UD-LOCK-USED)))) + (INST "SHLD" (OP :OP #xFA4) + (ARG :OP1 '(E V) + :OP2 '(G V) + :OP3 '(I B)) + '(X86-SHLD/SHRD) + '((:UD (UD-LOCK-USED)))) + (INST "SHLD" (OP :OP #xFA5) + (ARG :OP1 '(E V) + :OP2 '(G V) + :OP3 '(:CL)) + '(X86-SHLD/SHRD) + '((:UD (UD-LOCK-USED)))) + (INST "PUSH GS" + (OP :OP #xFA8 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:GS)) + '(X86-PUSH-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "POP GS" + (OP :OP #xFA9 :SUPERSCRIPTS '(:D64)) + (ARG :OP1 '(:GS)) + '(X86-POP-SEGMENT-REGISTER) + '((:UD (UD-LOCK-USED)))) + (INST "RSM" (OP :OP #xFAA) + NIL 'NIL + 'NIL) + (INST "BTS" (OP :OP #xFAB) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-BTS-0F-AB) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "SHRD" (OP :OP #xFAC) + (ARG :OP1 '(E V) + :OP2 '(G V) + :OP3 '(I B)) + '(X86-SHLD/SHRD) + '((:UD (UD-LOCK-USED)))) + (INST "SHRD" (OP :OP #xFAD) + (ARG :OP1 '(E V) + :OP2 '(G V) + :OP3 '(:CL)) + '(X86-SHLD/SHRD) + '((:UD (UD-LOCK-USED)))) + (INST "FXSAVE" + (OP :OP #xFAE + :REG #x0 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:FXSR)) + NIL '(X86-FXSAVE/FXSAVE64) + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "RDFSBASE" + (OP :OP #xFAE + :REG #x0 + :MOD #x3 + :PFX :F3 + :MODE :O64 + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:FSGSBASE)) + (ARG :OP1 '(R Y)) + 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->FSGSBASE (CR4)) #x0)))) + (INST "FXRSTOR" + (OP :OP #xFAE + :REG #x1 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:FXSR)) + NIL '(X86-FXRSTOR/FXRSTOR64) + '((:UD (UD-LOCK-USED)) + (:NM (NM-CR0-TS-IS-1) + (NM-CR0-EM-IS-1)))) + (INST "RDGSBASE" + (OP :OP #xFAE + :REG #x1 + :MOD #x3 + :PFX :F3 + :MODE :O64 + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:FSGSBASE)) + (ARG :OP1 '(R Y)) + 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->FSGSBASE (CR4)) #x0)))) + (INST "LDMXCSR" + (OP :OP #xFAE + :REG #x2 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:SSE)) + NIL '(X86-LDMXCSR/STMXCSR-OP/EN-M) + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "WRFSBASE" + (OP :OP #xFAE + :REG #x2 + :MOD #x3 + :PFX :F3 + :MODE :O64 + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:FSGSBASE)) + (ARG :OP1 '(R Y)) + 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->FSGSBASE (CR4)) #x0)))) + (INST "STMXCSR" + (OP :OP #xFAE + :REG #x3 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:SSE)) + NIL '(X86-LDMXCSR/STMXCSR-OP/EN-M) + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "WRGSBASE" + (OP :OP #xFAE + :REG #x3 + :MOD #x3 + :PFX :F3 + :MODE :O64 + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:FSGSBASE)) + (ARG :OP1 '(R Y)) + 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->FSGSBASE (CR4)) #x0)))) + (INST "XSAVE" + (OP :OP #xFAE + :REG #x4 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:XSAVE)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->OSXSAVE (CR4)) #x0)) + (:GP (GP-CPL-NOT-0)) + (:NM (NM-CR0-TS-IS-1)))) + (INST "XRSTOR" + (OP :OP #xFAE + :REG #x5 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:XSAVE)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->OSXSAVE (CR4)) #x0)) + (:GP (GP-CPL-NOT-0)) + (:NM (NM-CR0-TS-IS-1)))) + (INST "LFENCE" + (OP :OP #xFAE + :REG #x5 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:SSE2)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "XSAVEOPT" + (OP :OP #xFAE + :REG #x6 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15)) + NIL 'NIL + '((:UD (UD-LOCK-USED) + (EQUAL (CR4BITS->OSXSAVE (CR4)) #x0) + (OR (EQUAL (FEATURE-FLAG-MACRO :XSAVE) #x0) + (EQUAL (FEATURE-FLAG-MACRO :XSAVEOPT) #x0))) + (:NM (NM-CR0-TS-IS-1)))) + (INST "MFENCE" + (OP :OP #xFAE + :REG #x6 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:SSE2)) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "CLFLUSH" + (OP :OP #xFAE + :REG #x7 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:CLFSH)) + NIL 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "SFENCE" + (OP :OP #xFAE + :REG #x7 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-15) + :FEAT '(:SSE)) + NIL '(X86-TWO-BYTE-NOP) + '((:UD (UD-LOCK-USED)))) + (INST "VLDMXCSR" + (OP :OP #xFAE + :VEX '(:0F :LZ :WIG) + :FEAT '(:AVX) + :REG #x2) + (ARG :OP1 '(M D)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VSTMXCSR" + (OP :OP #xFAE + :VEX '(:0F :LZ :WIG) + :FEAT '(:AVX) + :REG #x3) + (ARG :OP1 '(M D)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "IMUL" (OP :OP #xFAF) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-IMUL-OP/EN-RM) + '((:UD (UD-LOCK-USED)))) + (INST "CMPXCHG" (OP :OP #xFB0) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-CMPXCHG) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "CMPXCHG" (OP :OP #xFB1) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-CMPXCHG) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "LSS" (OP :OP #xFB2) + (ARG :OP1 '(G V) :OP2 '(M P)) + '(X86-LOAD-FAR-POINTER) + '((:UD (UD-LOCK-USED) + (UD-SOURCE-OPERAND-IS-A-REGISTER)))) + (INST "BTR" (OP :OP #xFB3) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-BTR-0F-B3) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "LFS" (OP :OP #xFB4) + (ARG :OP1 '(G V) :OP2 '(M P)) + '(X86-LOAD-FAR-POINTER) + '((:UD (UD-LOCK-USED) + (UD-SOURCE-OPERAND-IS-A-REGISTER)))) + (INST "LGS" (OP :OP #xFB5) + (ARG :OP1 '(G V) :OP2 '(M P)) + '(X86-LOAD-FAR-POINTER) + '((:UD (UD-LOCK-USED) + (UD-SOURCE-OPERAND-IS-A-REGISTER)))) + (INST "MOVZX" (OP :OP #xFB6) + (ARG :OP1 '(G V) :OP2 '(E B)) + '(X86-MOVZX) + '((:UD (UD-LOCK-USED)))) + (INST "MOVZX" (OP :OP #xFB7) + (ARG :OP1 '(G V) :OP2 '(E W)) + '(X86-MOVZX) + '((:UD (UD-LOCK-USED)))) + (INST "JMPE" (OP :OP #xFB8 :PFX :NO-PREFIX) + ;; Reserved for emulator on IPF (Itanium Processor Family). + NIL 'NIL + 'NIL) + (INST "POPCNT" (OP :OP #xFB8 + :PFX :F3 + :FEAT '(:POPCNT)) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(x86-popcnt) + '((:UD (UD-LOCK-USED)))) + (INST "UD1" + (OP :OP #xFB9 + :SUPERSCRIPTS '(:1A :1C) + :GROUP '(:GROUP-10)) + NIL + '(X86-ILLEGAL-INSTRUCTION (MESSAGE . "UD1 encountered!")) + 'NIL) + (INST "BT" + (OP :OP #xFBA + :REG #x4 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-8)) + (ARG :OP1 '(E V) :OP2 '(I B)) + '(X86-BT/BTS/BTR/BTC-0F-BA) + '((:UD (UD-LOCK-USED)))) + (INST "BTS" + (OP :OP #xFBA + :REG #x5 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-8)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-BT/BTS/BTR/BTC-0F-BA) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "BTR" + (OP :OP #xFBA + :REG #x6 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-8)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-BT/BTS/BTR/BTC-0F-BA) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "BTC" + (OP :OP #xFBA + :REG #x7 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-8)) + (ARG :OP1 '(E B) :OP2 '(I B)) + '(X86-BT/BTS/BTR/BTC-0F-BA) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "BTC" (OP :OP #xFBB) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-BTC-0F-BB) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "BSF" (OP :OP #xFBC :PFX :NO-PREFIX) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-BSF) + '((:UD (UD-LOCK-USED)))) + (INST "TZCNT" (OP :OP #xFBC :PFX :F3) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-TZCNT) + 'NIL) + (INST "BSR" (OP :OP #xFBD :PFX :NO-PREFIX) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-BSR) + '((:UD (UD-LOCK-USED)))) + (INST "LZCNT" (OP :OP #xFBD :PFX :F3) + (ARG :OP1 '(G V) :OP2 '(E V)) + '(X86-LZCNT) + '((:UD (UD-LOCK-USED)))) + (INST "MOVSX" (OP :OP #xFBE) + (ARG :OP1 '(G V) :OP2 '(E B)) + '(X86-MOVSX) + '((:UD (UD-LOCK-USED)))) + (INST "MOVSX" (OP :OP #xFBF) + (ARG :OP1 '(G V) :OP2 '(E W)) + '(X86-MOVSX) + '((:UD (UD-LOCK-USED)))) + (INST "XADD" (OP :OP #xFC0) + (ARG :OP1 '(E B) :OP2 '(G B)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #.*OP-XADD*)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "XADD" (OP :OP #xFC1) + (ARG :OP1 '(E V) :OP2 '(G V)) + '(X86-ADD/XADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G (OPERATION . #.*OP-XADD*)) + '((:UD (UD-LOCK-USED-DEST-NOT-MEMORY-OP)))) + (INST "CMPPS" + (OP :OP #xFC2 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS) + :OP4 '(I B)) + '(X86-CMPPS-OP/EN-RMI) + '((:EX (CHK-EXC :TYPE-2 (:SSE))))) + (INST "CMPPD" + (OP :OP #xFC2 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD) + :OP4 '(I B)) + '(X86-CMPPD-OP/EN-RMI) + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "CMPSS" + (OP :OP #xFC2 :PFX :F3 :FEAT '(:SSE)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS) + :OP4 '(I B)) + '(X86-CMPSS/CMPSD-OP/EN-RMI (SP/DP . #x0)) + '((:EX (CHK-EXC :TYPE-3 (:SSE))))) + (INST "CMPSD" + (OP :OP #xFC2 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD) + :OP4 '(I B)) + '(X86-CMPSS/CMPSD-OP/EN-RMI (SP/DP . #x1)) + '((:EX (CHK-EXC :TYPE-3 (:SSE2))))) + (INST "VCMPPD" + (OP :OP #xFC2 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCMPPD" + (OP :OP #xFC2 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCMPPS" + (OP :OP #xFC2 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCMPPS" + (OP :OP #xFC2 + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCMPSD" + (OP :OP #xFC2 + :VEX '(:0F :NDS :LIG :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(H SD) + :OP3 '(W SD) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCMPSS" + (OP :OP #xFC2 + :VEX '(:0F :NDS :LIG :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(H SS) + :OP3 '(W SS) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VCMPPD" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCMPPD" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCMPPD" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCMPPS" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCMPPS" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCMPPS" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCMPSD" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :LIG :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VCMPSS" + (OP :OP #xFC2 + :EVEX '(:0F :NDS :LIG :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "MOVNTI" (OP :OP #xFC3 + :FEAT '(:SSE2)) + (ARG :OP1 '(M Y) :OP2 '(G Y)) + 'NIL + '((:UD (UD-LOCK-USED) + (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "PINSRW" + (OP :OP #xFC4 :MOD #x3 :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) + :OP2 '(R Y) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "PINSRW" + (OP :OP #xFC4 :MOD :MEM :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) + :OP2 '(M W) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "PINSRW" + (OP :OP #xFC4 :MOD #x3 :PFX :66 + :FEAT '(:SSE2)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(R Y) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "PINSRW" + (OP :OP #xFC4 :MOD :MEM :PFX :66 + :FEAT '(:SSE2)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(M W) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "VPINSRW" + (OP :OP #xFC4 + :VEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(R Y) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPINSRW" + (OP :OP #xFC4 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "PEXTRW" + (OP :OP #xFC5 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(G D) + :OP2 '(N Q) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE))))) + (INST "PEXTRW" + (OP :OP #xFC5 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(G D) + :OP2 '(U DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "VPEXTRW" + (OP :OP #xFC5 + :VEX '(:0F :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(G D) + :OP2 '(U DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPEXTRW" + (OP :OP #xFC5 + :EVEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "SHUFPS" + (OP :OP #xFC6 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS) + :OP4 '(I B)) + '(X86-SHUFPS-OP/EN-RMI) + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "SHUFPD" + (OP :OP #xFC6 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD) + :OP4 '(I B)) + '(X86-SHUFPD-OP/EN-RMI) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VSHUFPD" + (OP :OP #xFC6 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VSHUFPD" + (OP :OP #xFC6 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VSHUFPS" + (OP :OP #xFC6 + :VEX '(:0F :NDS :128 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VSHUFPS" + (OP :OP #xFC6 + :VEX '(:0F :NDS :256 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VSHUFPD" + (OP :OP #xFC6 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFPD" + (OP :OP #xFC6 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFPD" + (OP :OP #xFC6 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VSHUFPS" + (OP :OP #xFC6 + :EVEX '(:0F :NDS :128 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFPS" + (OP :OP #xFC6 + :EVEX '(:0F :NDS :256 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFPS" + (OP :OP #xFC6 + :EVEX '(:0F :NDS :512 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "CMPXCHG16B" + (OP :OP #xFC7 + :REG #x1 + :MOD :MEM + :PFX :NO-PREFIX + ;; This opcode is obviously not encodable in non 64-bit modes, but I + ;; won't bother to include that here --- REX bytes shouldn't even be + ;; detected in that mode. + :REX :W + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9) + :FEAT '(:CMPXCHG16B)) + (ARG :OP1 '(M DQ)) + '(X86-CMPXCHG8B/16B) + '((:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "CMPXCHG8B" + (OP :OP #xFC7 + :REG #x1 + :MOD :MEM + :PFX :NO-PREFIX + ;; :NOT-W also includes the case where the rex byte is absent. + :REX :NOT-W + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9) + :FEAT '(:CMPXCHG16B)) + (ARG :OP1 '(M Q)) + '(X86-CMPXCHG8B/16B) + '((:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "VMPTRLD" + (OP :OP #xFC7 + :REG #x6 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9)) + (ARG :OP1 '(M Q)) + 'NIL + '((:GP (GP-CPL-NOT-0)))) + (INST "VMCLEAR" + (OP :OP #xFC7 + :REG #x6 + :MOD :MEM + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9)) + (ARG :OP1 '(M Q)) + 'NIL + '((:GP (GP-CPL-NOT-0)))) + (INST "VMXON" + (OP :OP #xFC7 + :REG #x6 + :MOD :MEM + :PFX :F3 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9)) + (ARG :OP1 '(M Q)) + 'NIL + ;; BOZO Rob -- following GP only if executed outside VMX operation! + '((:GP (GP-CPL-NOT-0)))) + (INST "VMPTRLD" + (OP :OP #xFC7 + :REG #x7 + :MOD :MEM + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9)) + (ARG :OP1 '(M Q)) + 'NIL + '((:GP (GP-CPL-NOT-0)))) + (INST "RDRAND" + (OP :OP #xFC7 + :REG #x6 + :MOD #x3 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9) + :FEAT '(:RDRAND)) + (ARG :OP1 '(R V)) + '(X86-RDRAND) + '((:UD (UD-LOCK-USED) + (UD-REPS-USED)))) + ;; [Shilpi] RDRAND, with #x66 prefix, isn't listed in the Intel manuals (May + ;; 2018 edition). This is because all opcodes in this table other than RDRAND + ;; throw an error if they're used with a SIMD prefix that's not listed as an + ;; allowed mandatory prefix for that opcode. RDRAND can be used with + ;; :no-prefix and :66, but not :F2 or :F3 (see (ud-Reps-used) in :ud listing). + (INST "RDRAND" + (OP :OP #xFC7 + :REG #x6 + :MOD #x3 + :PFX :66 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9) + :FEAT '(:RDRAND)) + (ARG :OP1 '(R W)) + '(X86-RDRAND) + '((:UD (UD-LOCK-USED) + (UD-REPS-USED)))) + (INST "RDSEED" + (OP :OP #xFC7 + :REG #x7 + :PFX :NO-PREFIX + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9) + :FEAT '(:RDSEED)) + (ARG :OP1 '(R V)) + 'NIL + '((:UD (UD-LOCK-USED) + (UD-REPS-USED)))) + (INST "RDPID" + (OP :OP #xFC7 + :REG #x7 + :PFX :F3 + :MODE :O64 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9) + :FEAT '(:RDPID)) + (ARG :OP1 '(R Q)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "RDPID" + (OP :OP #xFC7 + :REG #x7 + :PFX :F3 + :MODE :I64 + :SUPERSCRIPTS '(:1A) + :GROUP '(:GROUP-9) + :FEAT '(:RDPID)) + (ARG :OP1 '(R D)) + 'NIL + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFC8) + (ARG :OP1 '(:RAX/EAX/R8/R8D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFC9) + (ARG :OP1 '(:RCX/ECX/R9/R9D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFCA) + (ARG :OP1 '(:RDX/EDX/R10/R10D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFCB) + (ARG :OP1 '(:RBX/EBX/R11/R11D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFCC) + (ARG :OP1 '(:RSP/ESP/R12/R12D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFCD) + (ARG :OP1 '(:RBP/EBP/R13/R13D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFCE) + (ARG :OP1 '(:RSI/ESI/R14/R14D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "BSWAP" (OP :OP #xFCF) + (ARG :OP1 '(:RDI/EDI/R15/R15D)) + '(X86-BSWAP) + '((:UD (UD-LOCK-USED)))) + (INST "ADDSUBPD" + (OP :OP #xFD0 :PFX :66 :FEAT '(:SSE3)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE3))))) + (INST "ADDSUBPS" + (OP :OP #xFD0 :PFX :F2 :FEAT '(:SSE3)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE3))))) + (INST "VADDSUBPD" + (OP :OP #xFD0 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VADDSUBPD" + (OP :OP #xFD0 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PD) + :OP2 '(H PD) + :OP3 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VADDSUBPS" + (OP :OP #xFD0 + :VEX '(:0F :NDS :128 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VADDSUBPS" + (OP :OP #xFD0 + :VEX '(:0F :NDS :256 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V PS) + :OP2 '(H PS) + :OP3 '(W PS)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PSRLW" + (OP :OP #xFD1 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSRL-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRLW" + (OP :OP #xFD1 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSRL-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSRLW" + (OP :OP #xFD1 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSRLW" + (OP :OP #xFD1 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLW" + (OP :OP #xFD1 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLW" + (OP :OP #xFD1 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLW" + (OP :OP #xFD1 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PSRLD" + (OP :OP #xFD2 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSRL-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRLD" + (OP :OP #xFD2 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSRL-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSRLD" + (OP :OP #xFD2 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSRLD" + (OP :OP #xFD2 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLD" + (OP :OP #xFD2 + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLD" + (OP :OP #xFD2 + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLD" + (OP :OP #xFD2 + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PSRLQ" + (OP :OP #xFD3 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSRL-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRLQ" + (OP :OP #xFD3 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSRL-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSRLQ" + (OP :OP #xFD3 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSRLQ" + (OP :OP #xFD3 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLQ" + (OP :OP #xFD3 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLQ" + (OP :OP #xFD3 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLQ" + (OP :OP #xFD3 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PADDQ" + (OP :OP #xFD4 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDB/PADDW/PADDD/PADDQ-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDQ" + (OP :OP #xFD4 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PADDB/PADDW/PADDD/PADDQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDQ" + (OP :OP #xFD4 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDQ" + (OP :OP #xFD4 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDQ" + (OP :OP #xFD4 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPADDQ" + (OP :OP #xFD4 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPADDQ" + (OP :OP #xFD4 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "PMULLW" + (OP :OP #xFD5 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PMULLW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PMULLW" + (OP :OP #xFD5 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMULLW" + (OP :OP #xFD5 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMULLW" + (OP :OP #xFD5 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMULLW" + (OP :OP #xFD5 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULLW" + (OP :OP #xFD5 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULLW" + (OP :OP #xFD5 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "MOVQ" + (OP :OP #xFD6 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(W Q) :OP2 '(V Q)) + '(X86-MOVQ-TO-XMM/MEM) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "MOVQ2DQ" + (OP :OP #xFD6 :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(V DQ) :OP2 '(N Q)) + 'NIL + '((:UD (EQUAL (CR0BITS->TS (CR0)) #x1) + (EQUAL (CR0BITS->EM (CR0)) #x1) + (EQUAL (CR4BITS->OSFXSR (CR4)) #x0) + (UD-LOCK-USED)))) + (INST "MOVDQ2Q" + (OP :OP #xFD6 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(P Q) :OP2 '(U Q)) + 'NIL + '((:UD (EQUAL (CR0BITS->TS (CR0)) #x1) + (EQUAL (CR0BITS->EM (CR0)) #x1) + (EQUAL (CR4BITS->OSFXSR (CR4)) #x0) + (UD-LOCK-USED)))) + (INST "VMOVQ" + (OP :OP #xFD6 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V Q) :OP2 '(W Q)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMOVQ" + (OP :OP #xFD6 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "PMOVMSKB" + (OP :OP #xFD7 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(G D) :OP2 '(N Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-7 (:SSE))))) + (INST "PMOVMSKB" + (OP :OP #xFD7 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(G D) :OP2 '(U X)) + '(X86-PMOVMSKB-OP/EN-RM) + '((:EX (CHK-EXC :TYPE-7 (:SSE2))))) + (INST "VPMOVMSKB" + (OP :OP #xFD7 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(G D) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX))))) + (INST "VPMOVMSKB" + (OP :OP #xFD7 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(G D) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "PSUBUSB" + (OP :OP #xFD8 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSUBUSB/PSUBUSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBUSB" + (OP :OP #xFD8 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBUSB" + (OP :OP #xFD8 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBUSB" + (OP :OP #xFD8 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBUSB" + (OP :OP #xFD8 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPSUBUSB" + (OP :OP #xFD8 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPSUBUSB" + (OP :OP #xFD8 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512BW))))) + (INST "PSUBUSW" + (OP :OP #xFD9 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSUBUSB/PSUBUSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBUSW" + (OP :OP #xFD9 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBUSW" + (OP :OP #xFD9 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBUSW" + (OP :OP #xFD9 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBUSW" + (OP :OP #xFD9 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPSUBUSW" + (OP :OP #xFD9 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPSUBUSW" + (OP :OP #xFD9 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512BW))))) + (INST "PMINUB" + (OP :OP #xFDA + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PMINUB" + (OP :OP #xFDA :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMINUB" + (OP :OP #xFDA + :VEX '(:0F :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINUB" + (OP :OP #xFDA + :VEX '(:0F :NDS :256 :66) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINUB" + (OP :OP #xFDA + :EVEX '(:0F :NDS :128 :66) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMINUB" + (OP :OP #xFDA + :EVEX '(:0F :NDS :256 :66) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMINUB" + (OP :OP #xFDA + :EVEX '(:0F :NDS :512 :66) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PAND" + (OP :OP #xFDB + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PAND/PANDN/POR/PXOR-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PAND" + (OP :OP #xFDB :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x3)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPAND" + (OP :OP #xFDB + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-AND*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPAND" + (OP :OP #xFDB + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-AND*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPANDD" + (OP :OP #xFDB + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPANDQ" + (OP :OP #xFDB + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPANDD" + (OP :OP #xFDB + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPANDD" + (OP :OP #xFDB + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPANDQ" + (OP :OP #xFDB + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPANDQ" + (OP :OP #xFDB + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "PADDUSB" + (OP :OP #xFDC + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDUSB/PADDUSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDUSB" + (OP :OP #xFDC :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDUSB" + (OP :OP #xFDC + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDUSB" + (OP :OP #xFDC + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDUSB" + (OP :OP #xFDC + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDUSB" + (OP :OP #xFDC + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDUSB" + (OP :OP #xFDC + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PADDUSW" + (OP :OP #xFDD + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDUSB/PADDUSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDUSW" + (OP :OP #xFDD :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDUSW" + (OP :OP #xFDD + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDUSW" + (OP :OP #xFDD + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDUSW" + (OP :OP #xFDD + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDUSW" + (OP :OP #xFDD + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDUSW" + (OP :OP #xFDD + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PMAXUB" + (OP :OP #xFDE + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PMAXUB" + (OP :OP #xFDE :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMAXUB" + (OP :OP #xFDE + :VEX '(:0F :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMAXUB" + (OP :OP #xFDE + :VEX '(:0F :NDS :256 :66) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMAXUB" + (OP :OP #xFDE + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXUB" + (OP :OP #xFDE + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXUB" + (OP :OP #xFDE + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PANDN" + (OP :OP #xFDF + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PAND/PANDN/POR/PXOR-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PANDN" + (OP :OP #xFDF :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #xD)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPANDN" + (OP :OP #xFDF + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-ANDN*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPANDN" + (OP :OP #xFDF + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VANDP?/VANDNP?/VORP?/VXORP?/VPAND/VPANDN/VPOR/VPXOR-VEX + (OPERATION . #.*OP-ANDN*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPANDND" + (OP :OP #xFDF + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPANDND" + (OP :OP #xFDF + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPANDND" + (OP :OP #xFDF + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPANDNQ" + (OP :OP #xFDF + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPANDNQ" + (OP :OP #xFDF + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPANDNQ" + (OP :OP #xFDF + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PAVGB" + (OP :OP #xFE0 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PAVGB" + (OP :OP #xFE0 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPAVGB" + (OP :OP #xFE0 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPAVGB" + (OP :OP #xFE0 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPAVGB" + (OP :OP #xFE0 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPAVGB" + (OP :OP #xFE0 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPAVGB" + (OP :OP #xFE0 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PSRAW" + (OP :OP #xFE1 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSRA-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRAW" + (OP :OP #xFE1 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSRA-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSRAW" + (OP :OP #xFE1 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSRAW" + (OP :OP #xFE1 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRAW" + (OP :OP #xFE1 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRAW" + (OP :OP #xFE1 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRAW" + (OP :OP #xFE1 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PSRAD" + (OP :OP #xFE2 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSRA-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSRAD" + (OP :OP #xFE2 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSRA-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSRAD" + (OP :OP #xFE2 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSRAD" + (OP :OP #xFE2 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRAD" + (OP :OP #xFE2 + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSRAD" + (OP :OP #xFE2 + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSRAD" + (OP :OP #xFE2 + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512F))))) + (INST "VPSRAQ" + (OP :OP #xFE2 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSRAQ" + (OP :OP #xFE2 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSRAQ" + (OP :OP #xFE2 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512F))))) + (INST "PAVGW" + (OP :OP #xFE3 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PAVGW" + (OP :OP #xFE3 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPAVGW" + (OP :OP #xFE3 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPAVGW" + (OP :OP #xFE3 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPAVGW" + (OP :OP #xFE3 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPAVGW" + (OP :OP #xFE3 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPAVGW" + (OP :OP #xFE3 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PMULHUW" + (OP :OP #xFE4 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PMULHUW" + (OP :OP #xFE4 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMULHUW" + (OP :OP #xFE4 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMULHUW" + (OP :OP #xFE4 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMULHUW" + (OP :OP #xFE4 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULHUW" + (OP :OP #xFE4 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULHUW" + (OP :OP #xFE4 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PMULHW" + (OP :OP #xFE5 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PMULHW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PMULHW" + (OP :OP #xFE5 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMULHW" + (OP :OP #xFE5 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMULHW" + (OP :OP #xFE5 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMULHW" + (OP :OP #xFE5 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULHW" + (OP :OP #xFE5 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULHW" + (OP :OP #xFE5 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "CVTTPD2DQ" + (OP :OP #xFE6 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "CVTDQ2PD" + (OP :OP #xFE6 :PFX :F3 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE2))))) + (INST "CVTPD2DQ" + (OP :OP #xFE6 :PFX :F2 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE2))))) + (INST "VCVTDQ2PD" + (OP :OP #xFE6 + :VEX '(:0F :128 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VCVTDQ2PD" + (OP :OP #xFE6 + :VEX '(:0F :256 :F3 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VCVTPD2DQ" + (OP :OP #xFE6 + :VEX '(:0F :128 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTPD2DQ" + (OP :OP #xFE6 + :VEX '(:0F :256 :F2 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTTPD2DQ" + (OP :OP #xFE6 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTTPD2DQ" + (OP :OP #xFE6 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W PD)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VCVTDQ2PD" + (OP :OP #xFE6 + :EVEX '(:0F :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTDQ2PD" + (OP :OP #xFE6 + :EVEX '(:0F :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTDQ2PD" + (OP :OP #xFE6 + :EVEX '(:0F :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTPD2DQ" + (OP :OP #xFE6 + :EVEX '(:0F :128 :F2 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPD2DQ" + (OP :OP #xFE6 + :EVEX '(:0F :256 :F2 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTPD2DQ" + (OP :OP #xFE6 + :EVEX '(:0F :512 :F2 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VCVTQQ2PD" + (OP :OP #xFE6 + :EVEX '(:0F :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTQQ2PD" + (OP :OP #xFE6 + :EVEX '(:0F :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VCVTQQ2PD" + (OP :OP #xFE6 + :EVEX '(:0F :512 :F3 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VCVTTPD2DQ" + (OP :OP #xFE6 + :EVEX '(:0F :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPD2DQ" + (OP :OP #xFE6 + :EVEX '(:0F :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VCVTTPD2DQ" + (OP :OP #xFE6 + :EVEX '(:0F :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "MOVNTQ" + (OP :OP #xFE7 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(M Q) :OP2 '(P Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-8 (:MMX))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "MOVNTDQ" + (OP :OP #xFE7 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(M X) :OP2 '(V X)) + 'NIL + '((:EX (CHK-EXC :TYPE-1 (:SSE2))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "VMOVNTDQ" + (OP :OP #xFE7 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(M X) :OP2 '(V X)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVNTDQ" + (OP :OP #xFE7 + :VEX '(:0F :256 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(M X) :OP2 '(V X)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVNTDQ" + (OP :OP #xFE7 + :EVEX '(:0F :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTDQ" + (OP :OP #xFE7 + :EVEX '(:0F :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTDQ" + (OP :OP #xFE7 + :EVEX '(:0F :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512F))))) + (INST "PSUBSB" + (OP :OP #xFE8 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSUBSB/PSUBSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBSB" + (OP :OP #xFE8 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBSB" + (OP :OP #xFE8 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBSB" + (OP :OP #xFE8 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBSB" + (OP :OP #xFE8 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBSB" + (OP :OP #xFE8 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBSB" + (OP :OP #xFE8 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PSUBSW" + (OP :OP #xFE9 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSUBSB/PSUBSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBSW" + (OP :OP #xFE9 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBSW" + (OP :OP #xFE9 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBSW" + (OP :OP #xFE9 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBSW" + (OP :OP #xFE9 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBSW" + (OP :OP #xFE9 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBSW" + (OP :OP #xFE9 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PMINSW" + (OP :OP #xFEA + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE))))) + (INST "PMINSW" + (OP :OP #xFEA :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMINSW" + (OP :OP #xFEA + :VEX '(:0F :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINSW" + (OP :OP #xFEA + :VEX '(:0F :NDS :256 :66) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINSW" + (OP :OP #xFEA + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMINSW" + (OP :OP #xFEA + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMINSW" + (OP :OP #xFEA + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "POR" + ;; Note: Table 22-7 does not list POR in the + ;; "Applicable Instructions" section, but it does + ;; list PXOR. So this is a guess. + (OP :OP #xFEB + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PAND/PANDN/POR/PXOR-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "POR" + (OP :OP #xFEB :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x1)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPOR" + (OP :OP #xFEB + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #.*OP-OR*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPOR" + (OP :OP #xFEB + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #.*OP-OR*)) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPORD" + (OP :OP #xFEB + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPORD" + (OP :OP #xFEB + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPORD" + (OP :OP #xFEB + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPORQ" + (OP :OP #xFEB + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPORQ" + (OP :OP #xFEB + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPORQ" + (OP :OP #xFEB + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PADDSB" + (OP :OP #xFEC + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDSB/PADDSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDSB" + (OP :OP #xFEC :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDSB" + (OP :OP #xFEC + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDSB" + (OP :OP #xFEC + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDSB" + (OP :OP #xFEC + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDSB" + (OP :OP #xFEC + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDSB" + (OP :OP #xFEC + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PADDSW" + (OP :OP #xFED + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDSB/PADDSW-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDSW" + (OP :OP #xFED :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDSW" + (OP :OP #xFED + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDSW" + (OP :OP #xFED + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDSW" + (OP :OP #xFED + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDSW" + (OP :OP #xFED + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDSW" + (OP :OP #xFED + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PMAXSW" + (OP :OP #xFEE + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PMAXSW" + (OP :OP #xFEE :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMAXSW" + (OP :OP #xFEE + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMAXSW" + (OP :OP #xFEE + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMAXSW" + (OP :OP #xFEE + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXSW" + (OP :OP #xFEE + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXSW" + (OP :OP #xFEE + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PXOR" + (OP :OP #xFEF + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PAND/PANDN/POR/PXOR-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PXOR" + (OP :OP #xFEF :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-ANDP?/ANDNP?/ORP?/XORP?/PAND/PANDN/POR/PXOR-OP/EN-RM + (OPERATION . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPXOR" + (OP :OP #xFEF + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPXOR" + (OP :OP #xFEF + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + (operation . #x5)) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPXORD" + (OP :OP #xFEF + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPXORD" + (OP :OP #xFEF + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPXORD" + (OP :OP #xFEF + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPXORQ" + (OP :OP #xFEF + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPXORQ" + (OP :OP #xFEF + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPXORQ" + (OP :OP #xFEF + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "LDDQU" + (OP :OP #xFF0 :PFX :F2 :FEAT '(:SSE3)) + (ARG :OP1 '(V X) :OP2 '(M X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE3))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "VLDDQU" + (OP :OP #xFF0 + :VEX '(:0F :128 :F2 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) :OP2 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VLDDQU" + (OP :OP #xFF0 + :VEX '(:0F :256 :F2 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) :OP2 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PSLLW" + (OP :OP #xFF1 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSLL-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSLLW" + (OP :OP #xFF1 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSLL-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSLLW" + (OP :OP #xFF1 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSLLW" + (OP :OP #xFF1 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLW" + (OP :OP #xFF1 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLW" + (OP :OP #xFF1 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLW" + (OP :OP #xFF1 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PSLLD" + (OP :OP #xFF2 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSLL-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSLLD" + (OP :OP #xFF2 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSLL-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSLLD" + (OP :OP #xFF2 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSLLD" + (OP :OP #xFF2 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLD" + (OP :OP #xFF2 + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSLLD" + (OP :OP #xFF2 + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSLLD" + (OP :OP #xFF2 + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512F))))) + (INST "PSLLQ" + (OP :OP #xFF3 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSLL-MM/M64-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSLLQ" + (OP :OP #xFF3 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSLL-XMM-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSLLQ" + (OP :OP #xFF3 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSLLQ" + (OP :OP #xFF3 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLQ" + (OP :OP #xFF3 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSLLQ" + (OP :OP #xFF3 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512F))))) + (INST "VPSLLQ" + (OP :OP #xFF3 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512F))))) + (INST "PMULUDQ" + (OP :OP #xFF4 + :PFX :NO-PREFIX + :FEAT '(:SSE2)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PMULUDQ" + (OP :OP #xFF4 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMULUDQ" + (OP :OP #xFF4 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMULUDQ" + (OP :OP #xFF4 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMULUDQ" + (OP :OP #xFF4 + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMULUDQ" + (OP :OP #xFF4 + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMULUDQ" + (OP :OP #xFF4 + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PMADDWD" + (OP :OP #xFF5 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PMADDWD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PMADDWD" + (OP :OP #xFF5 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMADDWD" + (OP :OP #xFF5 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMADDWD" + (OP :OP #xFF5 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMADDWD" + (OP :OP #xFF5 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPMADDWD" + (OP :OP #xFF5 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPMADDWD" + (OP :OP #xFF5 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PSADBW" + (OP :OP #xFF6 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:SSE))))) + (INST "PSADBW" + (OP :OP #xFF6 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSADBW" + (OP :OP #xFF6 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSADBW" + (OP :OP #xFF6 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSADBW" + (OP :OP #xFF6 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSADBW" + (OP :OP #xFF6 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSADBW" + (OP :OP #xFF6 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "MASKMOVQ" + (OP :OP #xFF7 + :PFX :NO-PREFIX + :FEAT '(:SSE)) + (ARG :OP1 '(P Q) :OP2 '(N Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-8 (:MMX))))) + (INST "MASKMOVDQU" + (OP :OP #xFF7 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V DQ) :OP2 '(U DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VMASKMOVDQU" + (OP :OP #xFF7 + :VEX '(:0F :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) :OP2 '(U DQ)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PSUBB" + (OP :OP #xFF8 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSUBB/PSUBW/PSUBD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBB" + (OP :OP #xFF8 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSUBB/PSUBW/PSUBD/PSUBQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBB" + (OP :OP #xFF8 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBB" + (OP :OP #xFF8 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBB" + (OP :OP #xFF8 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBB" + (OP :OP #xFF8 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBB" + (OP :OP #xFF8 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PSUBW" + (OP :OP #xFF9 + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSUBB/PSUBW/PSUBD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBW" + (OP :OP #xFF9 :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSUBB/PSUBW/PSUBD/PSUBQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBW" + (OP :OP #xFF9 + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBW" + (OP :OP #xFF9 + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBW" + (OP :OP #xFF9 + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBW" + (OP :OP #xFF9 + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSUBW" + (OP :OP #xFF9 + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PSUBD" + (OP :OP #xFFA + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PSUBB/PSUBW/PSUBD-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBD" + (OP :OP #xFFA :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSUBB/PSUBW/PSUBD/PSUBQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBD" + (OP :OP #xFFA + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBD" + (OP :OP #xFFA + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBD" + (OP :OP #xFFA + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSUBD" + (OP :OP #xFFA + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSUBD" + (OP :OP #xFFA + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PSUBQ" + (OP :OP #xFFB + :PFX :NO-PREFIX + :FEAT '(:SSE2)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PSUBQ" + (OP :OP #xFFB :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PSUBB/PSUBW/PSUBD/PSUBQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPSUBQ" + (OP :OP #xFFB + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSUBQ" + (OP :OP #xFFB + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpsubb/vpsubw/vpsubd/vpsubq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSUBQ" + (OP :OP #xFFB + :EVEX '(:0F :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSUBQ" + (OP :OP #xFFB + :EVEX '(:0F :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSUBQ" + (OP :OP #xFFB + :EVEX '(:0F :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PADDB" + (OP :OP #xFFC + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDB/PADDW/PADDD/PADDQ-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDB" + (OP :OP #xFFC :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PADDB/PADDW/PADDD/PADDQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDB" + (OP :OP #xFFC + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDB" + (OP :OP #xFFC + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDB" + (OP :OP #xFFC + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDB" + (OP :OP #xFFC + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDB" + (OP :OP #xFFC + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PADDW" + (OP :OP #xFFD + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDB/PADDW/PADDD/PADDQ-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDW" + (OP :OP #xFFD :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PADDB/PADDW/PADDD/PADDQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDW" + (OP :OP #xFFD + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDW" + (OP :OP #xFFD + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDW" + (OP :OP #xFFD + :EVEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDW" + (OP :OP #xFFD + :EVEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPADDW" + (OP :OP #xFFD + :EVEX '(:0F :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PADDD" + (OP :OP #xFFE + :PFX :NO-PREFIX + :FEAT '(:MMX)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + '(X86-PADDB/PADDW/PADDD/PADDQ-MMX) + '((:EX (CHK-EXC :TYPE-22-7 (:MMX))))) + (INST "PADDD" + (OP :OP #xFFE :PFX :66 :FEAT '(:SSE2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-PADDB/PADDW/PADDD/PADDQ-SSE) + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPADDD" + (OP :OP #xFFE + :VEX '(:0F :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPADDD" + (OP :OP #xFFE + :VEX '(:0F :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(x86-vpaddb/vpaddw/vpaddd/vpaddq-vex) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPADDD" + (OP :OP #xFFE + :EVEX '(:0F :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPADDD" + (OP :OP #xFFE + :EVEX '(:0F :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPADDD" + (OP :OP #xFFE + :EVEX '(:0F :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))))) + +(defconst *pre-0F-38-three-byte-opcode-map* + ;; BOZO Rob question -- should these be UD in 64-bit mode? or just ignored.. + '((INST "PSHUFB" + (OP :OP #xF3800 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PSHUFB" + (OP :OP #xF3800 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPSHUFB" + (OP :OP #xF3800 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSHUFB" + (OP :OP #xF3800 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSHUFB" + (OP :OP #xF3800 + :EVEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSHUFB" + (OP :OP #xF3800 + :EVEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPSHUFB" + (OP :OP #xF3800 + :EVEX '(:0F38 :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PHADDW" + (OP :OP #xF3801 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PHADDW" + (OP :OP #xF3801 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPHADDW" + (OP :OP #xF3801 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPHADDW" + (OP :OP #xF3801 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PHADDD" + (OP :OP #xF3802 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PHADDD" + (OP :OP #xF3802 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPHADDD" + (OP :OP #xF3802 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPHADDD" + (OP :OP #xF3802 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PHADDSW" + (OP :OP #xF3803 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PHADDSW" + (OP :OP #xF3803 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPHADDSW" + (OP :OP #xF3803 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPHADDSW" + (OP :OP #xF3803 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PMADDUBSW" + (OP :OP #xF3804 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PMADDUBSW" + (OP :OP #xF3804 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPMADDUBSW" + (OP :OP #xF3804 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMADDUBSW" + (OP :OP #xF3804 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMADDUBSW" + (OP :OP #xF3804 + :EVEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPMADDUBSW" + (OP :OP #xF3804 + :EVEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPMADDUBSW" + (OP :OP #xF3804 + :EVEX '(:0F38 :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PHSUBW" + (OP :OP #xF3805 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PHSUBW" + (OP :OP #xF3805 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPHSUBW" + (OP :OP #xF3805 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPHSUBW" + (OP :OP #xF3805 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PHSUBD" + (OP :OP #xF3806 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PHSUBD" + (OP :OP #xF3806 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPHSUBD" + (OP :OP #xF3806 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPHSUBD" + (OP :OP #xF3806 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PHSUBSW" + (OP :OP #xF3807 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PHSUBSW" + (OP :OP #xF3807 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPHSUBSW" + (OP :OP #xF3807 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPHSUBSW" + (OP :OP #xF3807 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PSIGNB" + (OP :OP #xF3808 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PSIGNB" + (OP :OP #xF3808 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPSIGNB" + (OP :OP #xF3808 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSIGNB" + (OP :OP #xF3808 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PSIGNW" + (OP :OP #xF3809 + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PSIGNW" + (OP :OP #xF3809 + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPSIGNW" + (OP :OP #xF3809 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSIGNW" + (OP :OP #xF3809 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PSIGND" + (OP :OP #xF380A + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PSIGND" + (OP :OP #xF380A + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPSIGND" + (OP :OP #xF380A + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPSIGND" + (OP :OP #xF380A + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PMULHRSW" + (OP :OP #xF380B + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PMULHRSW" + (OP :OP #xF380B + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPMULHRSW" + (OP :OP #xF380B + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMULHRSW" + (OP :OP #xF380B + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMULHRSW" + (OP :OP #xF380B + :EVEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULHRSW" + (OP :OP #xF380B + :EVEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMULHRSW" + (OP :OP #xF380B + :EVEX '(:0F38 :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VPERMILPS" + (OP :OP #xF380C + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPS" + (OP :OP #xF380C + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPS" + (OP :OP #xF380C + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPS" + (OP :OP #xF380C + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPS" + (OP :OP #xF380C + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMILPD" + (OP :OP #xF380D + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPD" + (OP :OP #xF380D + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPD" + (OP :OP #xF380D + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPD" + (OP :OP #xF380D + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPD" + (OP :OP #xF380D + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VTESTPS" + (OP :OP #xF380E + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VTESTPS" + (OP :OP #xF380E + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VTESTPD" + (OP :OP #xF380F + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VTESTPD" + (OP :OP #xF380F + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PBLENDVB" + (OP :OP #xF3810 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMOVUSWB" + (OP :OP #xF3810 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512BW))))) + (INST "VPMOVUSWB" + (OP :OP #xF3810 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512BW))))) + (INST "VPMOVUSWB" + (OP :OP #xF3810 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512BW))))) + (INST "VPSRLVW" + (OP :OP #xF3810 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLVW" + (OP :OP #xF3810 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSRLVW" + (OP :OP #xF3810 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VPMOVUSDB" + (OP :OP #xF3811 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSDB" + (OP :OP #xF3811 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSDB" + (OP :OP #xF3811 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPSRAVW" + (OP :OP #xF3811 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPSRAVW" + (OP :OP #xF3811 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPSRAVW" + (OP :OP #xF3811 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512BW))))) + (INST "VPMOVUSQB" + (OP :OP #xF3812 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSQB" + (OP :OP #xF3812 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSQB" + (OP :OP #xF3812 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPSLLVW" + (OP :OP #xF3812 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLVW" + (OP :OP #xF3812 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPSLLVW" + (OP :OP #xF3812 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VCVTPH2PS" + (OP :OP #xF3813 + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:F16C :AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-11 (:F16C :AVX))))) + (INST "VCVTPH2PS" + (OP :OP #xF3813 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:F16C :AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-11 (:F16C :AVX))))) + (INST "VPMOVUSDW" + (OP :OP #xF3813 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSDW" + (OP :OP #xF3813 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSDW" + (OP :OP #xF3813 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VCVTPH2PS" + (OP :OP #xF3813 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E11 (:AVX512VL :AVX512F))))) + (INST "VCVTPH2PS" + (OP :OP #xF3813 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E11 (:AVX512VL :AVX512F))))) + (INST "VCVTPH2PS" + (OP :OP #xF3813 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E11 (:AVX512F))))) + (INST "BLENDVPS" + (OP :OP #xF3814 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMOVUSQW" + (OP :OP #xF3814 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSQW" + (OP :OP #xF3814 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSQW" + (OP :OP #xF3814 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPRORVD" + (OP :OP #xF3814 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPRORVD" + (OP :OP #xF3814 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPRORVD" + (OP :OP #xF3814 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPRORVQ" + (OP :OP #xF3814 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPRORVQ" + (OP :OP #xF3814 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPRORVQ" + (OP :OP #xF3814 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "BLENDVPD" + (OP :OP #xF3815 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMOVUSQD" + (OP :OP #xF3815 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSQD" + (OP :OP #xF3815 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVUSQD" + (OP :OP #xF3815 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPROLVD" + (OP :OP #xF3815 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPROLVD" + (OP :OP #xF3815 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPROLVD" + (OP :OP #xF3815 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPROLVQ" + (OP :OP #xF3815 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPROLVQ" + (OP :OP #xF3815 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPROLVQ" + (OP :OP #xF3815 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPERMPS" + (OP :OP #xF3816 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V QQ) + :OP2 '(H QQ) + :OP3 '(W QQ)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPERMPD" + (OP :OP #xF3816 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMPD" + (OP :OP #xF3816 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMPS" + (OP :OP #xF3816 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMPS" + (OP :OP #xF3816 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "PTEST" + (OP :OP #xF3817 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPTEST" + (OP :OP #xF3817 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPTEST" + (OP :OP #xF3817 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VBROADCASTSS" + (OP :OP #xF3818 + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) :OP2 '(W D)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VBROADCASTSS" + (OP :OP #xF3818 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) :OP2 '(W D)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VBROADCASTSS" + (OP :OP #xF3818 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX) + :MOD #x3) + (ARG :OP1 '(V X) :OP2 '(W D)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VBROADCASTSS" + (OP :OP #xF3818 + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX) + :MOD #x3) + (ARG :OP1 '(V X) :OP2 '(W D)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VBROADCASTSS" + (OP :OP #xF3818 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VBROADCASTSS" + (OP :OP #xF3818 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VBROADCASTSS" + (OP :OP #xF3818 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VBROADCASTSD" + (OP :OP #xF3819 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V QQ) :OP2 '(W Q)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VBROADCASTSD" + (OP :OP #xF3819 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX) + :MOD #x3) + (ARG :OP1 '(V QQ) :OP2 '(W Q)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VBROADCASTF32X2" + (OP :OP #xF3819 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512DQ))))) + (INST "VBROADCASTF32X2" + (OP :OP #xF3819 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "VBROADCASTSD" + (OP :OP #xF3819 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VBROADCASTSD" + (OP :OP #xF3819 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VBROADCASTF128" + (OP :OP #xF381A + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V QQ) :OP2 '(M DQ)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VBROADCASTF32X4" + (OP :OP #xF381A + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VBROADCASTF32X4" + (OP :OP #xF381A + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VBROADCASTF64X2" + (OP :OP #xF381A + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512DQ))))) + (INST "VBROADCASTF64X2" + (OP :OP #xF381A + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "VBROADCASTF32X8" + (OP :OP #xF381B + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "VBROADCASTF64X4" + (OP :OP #xF381B + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "PABSB" + (OP :OP #xF381C + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PABSB" + (OP :OP #xF381C + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) :OP2 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPABSB" + (OP :OP #xF381C + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPABSB" + (OP :OP #xF381C + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPABSB" + (OP :OP #xF381C + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPABSB" + (OP :OP #xF381C + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPABSB" + (OP :OP #xF381C + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PABSW" + (OP :OP #xF381D + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PABSW" + (OP :OP #xF381D + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) :OP2 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPABSW" + (OP :OP #xF381D + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPABSW" + (OP :OP #xF381D + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPABSW" + (OP :OP #xF381D + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPABSW" + (OP :OP #xF381D + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPABSW" + (OP :OP #xF381D + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PABSD" + (OP :OP #xF381E + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) :OP2 '(Q Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PABSD" + (OP :OP #xF381E + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) :OP2 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPABSD" + (OP :OP #xF381E + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPABSD" + (OP :OP #xF381E + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPABSD" + (OP :OP #xF381E + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPABSD" + (OP :OP #xF381E + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPABSD" + (OP :OP #xF381E + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPABSQ" + (OP :OP #xF381F + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPABSQ" + (OP :OP #xF381F + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPABSQ" + (OP :OP #xF381F + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + ;; BOZO Rob -- do the following have UD? + (INST "PMOVSXBW" + (OP :OP #xF3820 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVSXBW" + (OP :OP #xF3820 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSXBW" + (OP :OP #xF3820 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVSXBW" + (OP :OP #xF3820 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSWB" + (OP :OP #xF3820 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512BW))))) + (INST "VPMOVSWB" + (OP :OP #xF3820 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512BW))))) + (INST "VPMOVSWB" + (OP :OP #xF3820 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512BW))))) + (INST "VPMOVSXBW" + (OP :OP #xF3820 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512BW))))) + (INST "VPMOVSXBW" + (OP :OP #xF3820 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512BW))))) + (INST "VPMOVSXBW" + (OP :OP #xF3820 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512BW))))) + (INST "PMOVSXBD" + (OP :OP #xF3821 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M D)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVSXBD" + (OP :OP #xF3821 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSXBD" + (OP :OP #xF3821 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVSXBD" + (OP :OP #xF3821 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSDB" + (OP :OP #xF3821 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSDB" + (OP :OP #xF3821 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSDB" + (OP :OP #xF3821 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVSXBD" + (OP :OP #xF3821 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXBD" + (OP :OP #xF3821 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXBD" + (OP :OP #xF3821 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVSXBQ" + (OP :OP #xF3822 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M W)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVSXBQ" + (OP :OP #xF3822 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSXBQ" + (OP :OP #xF3822 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVSXBQ" + (OP :OP #xF3822 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSQB" + (OP :OP #xF3822 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSQB" + (OP :OP #xF3822 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSQB" + (OP :OP #xF3822 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVSXBQ" + (OP :OP #xF3822 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXBQ" + (OP :OP #xF3822 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXBQ" + (OP :OP #xF3822 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVSXWD" + (OP :OP #xF3823 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVSXWD" + (OP :OP #xF3823 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSXWD" + (OP :OP #xF3823 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVSXWD" + (OP :OP #xF3823 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSDW" + (OP :OP #xF3823 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSDW" + (OP :OP #xF3823 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSDW" + (OP :OP #xF3823 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVSXWD" + (OP :OP #xF3823 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXWD" + (OP :OP #xF3823 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXWD" + (OP :OP #xF3823 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVSXWQ" + (OP :OP #xF3824 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M D)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "PMOVSXWQ" + (OP :OP #xF3824 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "VPMOVSXWQ" + (OP :OP #xF3824 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVSXWQ" + (OP :OP #xF3824 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSQW" + (OP :OP #xF3824 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSQW" + (OP :OP #xF3824 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSQW" + (OP :OP #xF3824 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVSXWQ" + (OP :OP #xF3824 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXWQ" + (OP :OP #xF3824 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXWQ" + (OP :OP #xF3824 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVSXDQ" + (OP :OP #xF3825 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M D)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "PMOVSXDQ" + (OP :OP #xF3825 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "VPMOVSXDQ" + (OP :OP #xF3825 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVSXDQ" + (OP :OP #xF3825 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVSQD" + (OP :OP #xF3825 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSQD" + (OP :OP #xF3825 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVSQD" + (OP :OP #xF3825 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVSXDQ" + (OP :OP #xF3825 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXDQ" + (OP :OP #xF3825 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVSXDQ" + (OP :OP #xF3825 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "VPTESTMB" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTMB" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTMB" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VPTESTMW" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTMW" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTMW" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VPTESTNMB" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTNMB" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTNMB" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :512 :F3 :W0) + :FEAT '(:AVX512F :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F :AVX512BW))))) + (INST "VPTESTNMW" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTNMW" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPTESTNMW" + (OP :OP #xF3826 + :EVEX '(:0F38 :NDS :512 :F3 :W1) + :FEAT '(:AVX512F :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F :AVX512BW))))) + (INST "VPTESTMD" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTMD" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTMD" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPTESTMQ" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTMQ" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTMQ" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPTESTNMD" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTNMD" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTNMD" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPTESTNMQ" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTNMQ" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTESTNMQ" + (OP :OP #xF3827 + :EVEX '(:0F38 :NDS :512 :F3 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PMULDQ" + (OP :OP #xF3828 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMULDQ" + (OP :OP #xF3828 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMULDQ" + (OP :OP #xF3828 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMOVM2B" + (OP :OP #xF3828 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVM2B" + (OP :OP #xF3828 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVM2B" + (OP :OP #xF3828 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512BW))))) + (INST "VPMOVM2W" + (OP :OP #xF3828 + :EVEX '(:0F38 :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVM2W" + (OP :OP #xF3828 + :EVEX '(:0F38 :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVM2W" + (OP :OP #xF3828 + :EVEX '(:0F38 :512 :F3 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512BW))))) + (INST "VPMULDQ" + (OP :OP #xF3828 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMULDQ" + (OP :OP #xF3828 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMULDQ" + (OP :OP #xF3828 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PCMPEQQ" + (OP :OP #xF3829 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPCMPEQQ" + (OP :OP #xF3829 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPEQQ" + (OP :OP #xF3829 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + '(X86-VPCMPEQB/VPCMPEQW/VPCMPEQD/VPCMPEQQ-VEX) + '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPEQQ" + (OP :OP #xF3829 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPEQQ" + (OP :OP #xF3829 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPEQQ" + (OP :OP #xF3829 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPMOVB2M" + (OP :OP #xF3829 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVB2M" + (OP :OP #xF3829 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVB2M" + (OP :OP #xF3829 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512BW))))) + (INST "VPMOVW2M" + (OP :OP #xF3829 + :EVEX '(:0F38 :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVW2M" + (OP :OP #xF3829 + :EVEX '(:0F38 :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512BW))))) + (INST "VPMOVW2M" + (OP :OP #xF3829 + :EVEX '(:0F38 :512 :F3 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512BW))))) + (INST "MOVNTDQA" + (OP :OP #xF382A + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M X)) + 'NIL + '((:EX (CHK-EXC :TYPE-1 (:SSE4.1))) + (:UD (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "VMOVNTDQA" + (OP :OP #xF382A + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) :OP2 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX))))) + (INST "VMOVNTDQA" + (OP :OP #xF382A + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) :OP2 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-1 (:AVX2))))) + (INST "VMOVNTDQA" + (OP :OP #xF382A + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTDQA" + (OP :OP #xF382A + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512VL :AVX512F))))) + (INST "VMOVNTDQA" + (OP :OP #xF382A + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E1NF (:AVX512F))))) + (INST "VPBROADCASTMB2Q" + (OP :OP #xF382A + :EVEX '(:0F38 :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512CD))))) + (INST "VPBROADCASTMB2Q" + (OP :OP #xF382A + :EVEX '(:0F38 :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512CD))))) + (INST "VPBROADCASTMB2Q" + (OP :OP #xF382A + :EVEX '(:0F38 :512 :F3 :W1) + :FEAT '(:AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512CD))))) + (INST "PACKUSDW" + (OP :OP #xF382B + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPACKUSDW" + (OP :OP #xF382B + :VEX '(:0F38 :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPACKUSDW" + (OP :OP #xF382B + :VEX '(:0F38 :NDS :256 :66) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPACKUSDW" + (OP :OP #xF382B + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512BW))))) + (INST "VPACKUSDW" + (OP :OP #xF382B + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512BW))))) + (INST "VPACKUSDW" + (OP :OP #xF382B + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512BW))))) + (INST "VMASKMOVPS" + (OP :OP #xF382C + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VMASKMOVPS" + (OP :OP #xF382C + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VSCALEFPD" + (OP :OP #xF382C + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSCALEFPD" + (OP :OP #xF382C + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSCALEFPD" + (OP :OP #xF382C + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VSCALEFPS" + (OP :OP #xF382C + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSCALEFPS" + (OP :OP #xF382C + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VSCALEFPS" + (OP :OP #xF382C + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VMASKMOVPD" + (OP :OP #xF382D + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VMASKMOVPD" + (OP :OP #xF382D + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VSCALEFSD" + (OP :OP #xF382D + :EVEX '(:0F38 :NDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VSCALEFSS" + (OP :OP #xF382D + :EVEX '(:0F38 :NDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VMASKMOVPS" + (OP :OP #xF382E + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VMASKMOVPS" + (OP :OP #xF382E + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VMASKMOVPD" + (OP :OP #xF382F + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VMASKMOVPD" + (OP :OP #xF382F + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "PMOVZXBW" + (OP :OP #xF3830 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVZXBW" + (OP :OP #xF3830 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVZXBW" + (OP :OP #xF3830 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVZXBW" + (OP :OP #xF3830 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVWB" + (OP :OP #xF3830 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512BW))))) + (INST "VPMOVWB" + (OP :OP #xF3830 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512BW))))) + (INST "VPMOVWB" + (OP :OP #xF3830 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512BW))))) + (INST "VPMOVZXBW" + (OP :OP #xF3830 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512BW))))) + (INST "VPMOVZXBW" + (OP :OP #xF3830 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512BW))))) + (INST "VPMOVZXBW" + (OP :OP #xF3830 + :EVEX '(:0F38 :128 :66) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512BW))))) + (INST "PMOVZXBD" + (OP :OP #xF3831 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M D)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVZXBD" + (OP :OP #xF3831 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVZXBD" + (OP :OP #xF3831 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVZXBD" + (OP :OP #xF3831 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVDB" + (OP :OP #xF3831 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVDB" + (OP :OP #xF3831 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVDB" + (OP :OP #xF3831 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVZXBD" + (OP :OP #xF3831 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXBD" + (OP :OP #xF3831 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXBD" + (OP :OP #xF3831 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVZXBQ" + (OP :OP #xF3832 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M W)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVZXBQ" + (OP :OP #xF3832 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVZXBQ" + (OP :OP #xF3832 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVZXBQ" + (OP :OP #xF3832 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVQB" + (OP :OP #xF3832 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVQB" + (OP :OP #xF3832 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVQB" + (OP :OP #xF3832 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVZXBQ" + (OP :OP #xF3832 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXBQ" + (OP :OP #xF3832 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXBQ" + (OP :OP #xF3832 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVZXWD" + (OP :OP #xF3833 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVZXWD" + (OP :OP #xF3833 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVZXWD" + (OP :OP #xF3833 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVZXWD" + (OP :OP #xF3833 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVDW" + (OP :OP #xF3833 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVDW" + (OP :OP #xF3833 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVDW" + (OP :OP #xF3833 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVZXWD" + (OP :OP #xF3833 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXWD" + (OP :OP #xF3833 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXWD" + (OP :OP #xF3833 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVZXWQ" + (OP :OP #xF3834 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M D)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVZXWQ" + (OP :OP #xF3834 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVZXWQ" + (OP :OP #xF3834 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVZXWQ" + (OP :OP #xF3834 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVQW" + (OP :OP #xF3834 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVQW" + (OP :OP #xF3834 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVQW" + (OP :OP #xF3834 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVZXWQ" + (OP :OP #xF3834 + :EVEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXWQ" + (OP :OP #xF3834 + :EVEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXWQ" + (OP :OP #xF3834 + :EVEX '(:0F38 :512 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "PMOVZXDQ" + (OP :OP #xF3835 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(M Q)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PMOVZXDQ" + (OP :OP #xF3835 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) :OP2 '(U X)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVZXDQ" + (OP :OP #xF3835 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPMOVZXDQ" + (OP :OP #xF3835 + :VEX '(:0F38 :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(U X)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPMOVQD" + (OP :OP #xF3835 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVQD" + (OP :OP #xF3835 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPMOVQD" + (OP :OP #xF3835 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPMOVZXDQ" + (OP :OP #xF3835 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXDQ" + (OP :OP #xF3835 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512VL :AVX512F))))) + (INST "VPMOVZXDQ" + (OP :OP #xF3835 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E5 (:AVX512F))))) + (INST "VPERMD" + (OP :OP #xF3836 + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V QQ) + :OP2 '(H QQ) + :OP3 '(W QQ)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPERMD" + (OP :OP #xF3836 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMD" + (OP :OP #xF3836 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMQ" + (OP :OP #xF3836 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMQ" + (OP :OP #xF3836 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "PCMPGTQ" + (OP :OP #xF3837 + :PFX :66 + :FEAT '(:SSE4.2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.2))))) + (INST "VPCMPGTQ" + (OP :OP #xF3837 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPCMPGTQ" + (OP :OP #xF3837 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPCMPGTQ" + (OP :OP #xF3837 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPGTQ" + (OP :OP #xF3837 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPGTQ" + (OP :OP #xF3837 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PMINSB" + (OP :OP #xF3838 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMINSB" + (OP :OP #xF3838 + :VEX '(:0F38 :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINSB" + (OP :OP #xF3838 + :VEX '(:0F38 :NDS :256 :66) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMINSB" + (OP :OP #xF3838 + :EVEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMINSB" + (OP :OP #xF3838 + :EVEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMINSB" + (OP :OP #xF3838 + :EVEX '(:0F38 :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VPMOVM2D" + (OP :OP #xF3838 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVM2D" + (OP :OP #xF3838 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVM2D" + (OP :OP #xF3838 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512DQ))))) + (INST "VPMOVM2Q" + (OP :OP #xF3838 + :EVEX '(:0F38 :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVM2Q" + (OP :OP #xF3838 + :EVEX '(:0F38 :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVM2Q" + (OP :OP #xF3838 + :EVEX '(:0F38 :512 :F3 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512DQ))))) + (INST "PMINSD" + (OP :OP #xF3839 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMINSD" + (OP :OP #xF3839 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINSD" + (OP :OP #xF3839 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMINSD" + (OP :OP #xF3839 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINSD" + (OP :OP #xF3839 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINSD" + (OP :OP #xF3839 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPMINSQ" + (OP :OP #xF3839 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINSQ" + (OP :OP #xF3839 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINSQ" + (OP :OP #xF3839 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPMOVD2M" + (OP :OP #xF3839 + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVD2M" + (OP :OP #xF3839 + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVD2M" + (OP :OP #xF3839 + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512DQ))))) + (INST "VPMOVQ2M" + (OP :OP #xF3839 + :EVEX '(:0F38 :128 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVQ2M" + (OP :OP #xF3839 + :EVEX '(:0F38 :256 :F3 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512VL :AVX512DQ))))) + (INST "VPMOVQ2M" + (OP :OP #xF3839 + :EVEX '(:0F38 :512 :F3 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E7NM (:AVX512DQ))))) + (INST "PMINUW" + (OP :OP #xF383A + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE2))))) + (INST "VPMINUW" + (OP :OP #xF383A + :VEX '(:0F38 :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINUW" + (OP :OP #xF383A + :VEX '(:0F38 :NDS :256 :66) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPBROADCASTMW2D" + (OP :OP #xF383A + :EVEX '(:0F38 :128 :F3 :W0) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512CD))))) + (INST "VPBROADCASTMW2D" + (OP :OP #xF383A + :EVEX '(:0F38 :256 :F3 :W0) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512CD))))) + (INST "VPBROADCASTMW2D" + (OP :OP #xF383A + :EVEX '(:0F38 :512 :F3 :W0) + :FEAT '(:AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512CD))))) + (INST "VPMINUW" + (OP :OP #xF383A + :EVEX '(:0F38 :NDS :128 :66) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512CD))))) + (INST "VPMINUW" + (OP :OP #xF383A + :EVEX '(:0F38 :NDS :256 :66) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512CD))))) + (INST "VPMINUW" + (OP :OP #xF383A + :EVEX '(:0F38 :NDS :512 :66) + :FEAT '(:AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512CD))))) + (INST "PMINUD" + (OP :OP #xF383B + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMINUD" + (OP :OP #xF383B + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMINUD" + (OP :OP #xF383B + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMINUD" + (OP :OP #xF383B + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINUD" + (OP :OP #xF383B + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINUD" + (OP :OP #xF383B + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPMINUQ" + (OP :OP #xF383B + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINUQ" + (OP :OP #xF383B + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMINUQ" + (OP :OP #xF383B + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PMAXSB" + (OP :OP #xF383C + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMAXSB" + (OP :OP #xF383C + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMAXSB" + (OP :OP #xF383C + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMAXSB" + (OP :OP #xF383C + :EVEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXSB" + (OP :OP #xF383C + :EVEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXSB" + (OP :OP #xF383C + :EVEX '(:0F38 :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PMAXSD" + (OP :OP #xF383D + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMAXSD" + (OP :OP #xF383D + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMAXSD" + (OP :OP #xF383D + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMAXSD" + (OP :OP #xF383D + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXSD" + (OP :OP #xF383D + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXSD" + (OP :OP #xF383D + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPMAXSQ" + (OP :OP #xF383D + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXSQ" + (OP :OP #xF383D + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXSQ" + (OP :OP #xF383D + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PMAXUW" + (OP :OP #xF383E + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMAXUW" + (OP :OP #xF383E + :VEX '(:0F38 :NDS :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMAXUW" + (OP :OP #xF383E + :VEX '(:0F38 :NDS :256 :66) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMAXUW" + (OP :OP #xF383E + :EVEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXUW" + (OP :OP #xF383E + :EVEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPMAXUW" + (OP :OP #xF383E + :EVEX '(:0F38 :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "PMAXUD" + (OP :OP #xF383F + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMAXUD" + (OP :OP #xF383F + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMAXUD" + (OP :OP #xF383F + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMAXUD" + (OP :OP #xF383F + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXUD" + (OP :OP #xF383F + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXUD" + (OP :OP #xF383F + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPMAXUQ" + (OP :OP #xF383F + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXUQ" + (OP :OP #xF383F + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMAXUQ" + (OP :OP #xF383F + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "PMULLD" + (OP :OP #xF3840 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPMULLD" + (OP :OP #xF3840 + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPMULLD" + (OP :OP #xF3840 + :VEX '(:0F38 :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPMULLD" + (OP :OP #xF3840 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMULLD" + (OP :OP #xF3840 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPMULLD" + (OP :OP #xF3840 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPMULLQ" + (OP :OP #xF3840 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VPMULLQ" + (OP :OP #xF3840 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VPMULLQ" + (OP :OP #xF3840 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "PHMINPOSUW" + (OP :OP #xF3841 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPHMINPOSUW" + (OP :OP #xF3841 + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VGETEXPPD" + (OP :OP #xF3842 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETEXPPD" + (OP :OP #xF3842 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETEXPPD" + (OP :OP #xF3842 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VGETEXPPS" + (OP :OP #xF3842 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETEXPPS" + (OP :OP #xF3842 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETEXPPS" + (OP :OP #xF3842 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VGETEXPSD" + (OP :OP #xF3843 + :EVEX '(:0F38 :NDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VGETEXPSS" + (OP :OP #xF3843 + :EVEX '(:0F38 :NDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VPLZCNTD" + (OP :OP #xF3844 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPLZCNTD" + (OP :OP #xF3844 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPLZCNTD" + (OP :OP #xF3844 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512CD))))) + (INST "VPLZCNTQ" + (OP :OP #xF3844 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPLZCNTQ" + (OP :OP #xF3844 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPLZCNTQ" + (OP :OP #xF3844 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512CD))))) + (INST "VPSRLVD" + (OP :OP #xF3845 + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLVD" + (OP :OP #xF3845 + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLVQ" + (OP :OP #xF3845 + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLVQ" + (OP :OP #xF3845 + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRLVD" + (OP :OP #xF3845 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRLVD" + (OP :OP #xF3845 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRLVD" + (OP :OP #xF3845 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPSRLVQ" + (OP :OP #xF3845 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRLVQ" + (OP :OP #xF3845 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRLVQ" + (OP :OP #xF3845 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPSRAVD" + (OP :OP #xF3846 + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRAVD" + (OP :OP #xF3846 + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSRAVD" + (OP :OP #xF3846 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRAVD" + (OP :OP #xF3846 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRAVD" + (OP :OP #xF3846 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPSRAVQ" + (OP :OP #xF3846 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRAVQ" + (OP :OP #xF3846 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSRAVQ" + (OP :OP #xF3846 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPSLLVD" + (OP :OP #xF3847 + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLVD" + (OP :OP #xF3847 + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLVQ" + (OP :OP #xF3847 + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLVQ" + (OP :OP #xF3847 + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPSLLVD" + (OP :OP #xF3847 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSLLVD" + (OP :OP #xF3847 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSLLVD" + (OP :OP #xF3847 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPSLLVQ" + (OP :OP #xF3847 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSLLVQ" + (OP :OP #xF3847 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPSLLVQ" + (OP :OP #xF3847 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VRCP14PD" + (OP :OP #xF384C + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRCP14PD" + (OP :OP #xF384C + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRCP14PD" + (OP :OP #xF384C + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VRCP14PS" + (OP :OP #xF384C + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRCP14PS" + (OP :OP #xF384C + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRCP14PS" + (OP :OP #xF384C + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VRCP14SD" + (OP :OP #xF384D + :EVEX '(:0F38 :NDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VRCP14SS" + (OP :OP #xF384D + :EVEX '(:0F38 :NDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VRSQRT14PD" + (OP :OP #xF384E + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRSQRT14PD" + (OP :OP #xF384E + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRSQRT14PD" + (OP :OP #xF384E + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VRSQRT14PS" + (OP :OP #xF384E + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRSQRT14PS" + (OP :OP #xF384E + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VRSQRT14PS" + (OP :OP #xF384E + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VRSQRT14SD" + (OP :OP #xF384F + :EVEX '(:0F38 :NDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VRSQRT14SS" + (OP :OP #xF384F + :EVEX '(:0F38 :NDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E10 (:AVX512F))))) + (INST "VP4DPWSSD" + (OP :OP #xF3852 + :EVEX '(:0F38 :DDS :512 :F2 :W0) + :FEAT '(:AVX512_4VNNIW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_4VNNIW))))) + (INST "VP4DPWSSDS" + (OP :OP #xF3853 + :EVEX '(:0F38 :DDS :512 :F2 :W0) + :FEAT '(:AVX512_4VNNIW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_4VNNIW))))) + (INST "VPBROADCASTD" + (OP :OP #xF3858 + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPBROADCASTD" + (OP :OP #xF3858 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPBROADCASTD" + (OP :OP #xF3858 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTD" + (OP :OP #xF3858 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTD" + (OP :OP #xF3858 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPBROADCASTQ" + (OP :OP #xF3859 + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPBROADCASTQ" + (OP :OP #xF3859 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VBROADCASTI32x2" + (OP :OP #xF3859 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512DQ))))) + (INST "VBROADCASTI32x2" + (OP :OP #xF3859 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512DQ))))) + (INST "VBROADCASTI32x2" + (OP :OP #xF3859 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "VPBROADCASTQ" + (OP :OP #xF3859 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTQ" + (OP :OP #xF3859 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTQ" + (OP :OP #xF3859 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VBROADCASTI128" + (OP :OP #xF385A + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V QQ) :OP2 '(M DQ)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VBROADCASTI32X4" + (OP :OP #xF385A + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VBROADCASTI32X4" + (OP :OP #xF385A + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VBROADCASTI64X2" + (OP :OP #xF385A + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512DQ))))) + (INST "VBROADCASTI64X2" + (OP :OP #xF385A + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "VBROADCASTI32X8" + (OP :OP #xF385B + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "VBROADCASTI64X4" + (OP :OP #xF385B + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPBLENDMD" + (OP :OP #xF3864 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPBLENDMD" + (OP :OP #xF3864 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPBLENDMD" + (OP :OP #xF3864 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPBLENDMQ" + (OP :OP #xF3864 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPBLENDMQ" + (OP :OP #xF3864 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPBLENDMQ" + (OP :OP #xF3864 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VBLENDMPD" + (OP :OP #xF3865 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VBLENDMPD" + (OP :OP #xF3865 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VBLENDMPD" + (OP :OP #xF3865 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VBLENDMPS" + (OP :OP #xF3865 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VBLENDMPS" + (OP :OP #xF3865 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VBLENDMPS" + (OP :OP #xF3865 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPBLENDMB" + (OP :OP #xF3866 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPBLENDMB" + (OP :OP #xF3866 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPBLENDMB" + (OP :OP #xF3866 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512BW))))) + (INST "VPBLENDMW" + (OP :OP #xF3866 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPBLENDMW" + (OP :OP #xF3866 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512BW))))) + (INST "VPBLENDMW" + (OP :OP #xF3866 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512BW))))) + (INST "VPERMI2B" + (OP :OP #xF3875 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512_VBMI))))) + (INST "VPERMI2B" + (OP :OP #xF3875 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512_VBMI))))) + (INST "VPERMI2B" + (OP :OP #xF3875 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512_VBMI))))) + (INST "VPERMI2W" + (OP :OP #xF3875 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPERMI2W" + (OP :OP #xF3875 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPERMI2W" + (OP :OP #xF3875 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPERMI2D" + (OP :OP #xF3876 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2D" + (OP :OP #xF3876 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2D" + (OP :OP #xF3876 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMI2Q" + (OP :OP #xF3876 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2Q" + (OP :OP #xF3876 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2Q" + (OP :OP #xF3876 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMI2PD" + (OP :OP #xF3877 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2PD" + (OP :OP #xF3877 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2PD" + (OP :OP #xF3877 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMI2PS" + (OP :OP #xF3877 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2PS" + (OP :OP #xF3877 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMI2PS" + (OP :OP #xF3877 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPBROADCASTB" + (OP :OP #xF3878 + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPBROADCASTB" + (OP :OP #xF3878 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPBROADCASTB" + (OP :OP #xF3878 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTB" + (OP :OP #xF3878 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTB" + (OP :OP #xF3878 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512BW))))) + (INST "VPBROADCASTW" + (OP :OP #xF3879 + :VEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPBROADCASTW" + (OP :OP #xF3879 + :VEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) :OP2 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-7 (:AVX2))))) + (INST "VPBROADCASTW" + (OP :OP #xF3879 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTW" + (OP :OP #xF3879 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTW" + (OP :OP #xF3879 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512BW))))) + (INST "VPBROADCASTB" + (OP :OP #xF387A + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTB" + (OP :OP #xF387A + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTB" + (OP :OP #xF387A + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512BW))))) + (INST "VPBROADCASTW" + (OP :OP #xF387B + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTW" + (OP :OP #xF387B + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512BW))))) + (INST "VPBROADCASTW" + (OP :OP #xF387B + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512BW))))) + (INST "VPBROADCASTD" + (OP :OP #xF387C + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTD" + (OP :OP #xF387C + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTD" + (OP :OP #xF387C + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPBROADCASTQ" + (OP :OP #xF387C + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTQ" + (OP :OP #xF387C + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512VL :AVX512F))))) + (INST "VPBROADCASTQ" + (OP :OP #xF387C + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512F))))) + (INST "VPERMT2B" + (OP :OP #xF387D + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512_VBMI))))) + (INST "VPERMT2B" + (OP :OP #xF387D + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512_VBMI))))) + (INST "VPERMT2B" + (OP :OP #xF387D + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512_VBMI))))) + (INST "VPERMT2W" + (OP :OP #xF387D + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPERMT2W" + (OP :OP #xF387D + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPERMT2W" + (OP :OP #xF387D + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPERMT2D" + (OP :OP #xF387E + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2D" + (OP :OP #xF387E + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2D" + (OP :OP #xF387E + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMT2Q" + (OP :OP #xF387E + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2Q" + (OP :OP #xF387E + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2Q" + (OP :OP #xF387E + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMT2PD" + (OP :OP #xF387F + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2PD" + (OP :OP #xF387F + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2PD" + (OP :OP #xF387F + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMT2PS" + (OP :OP #xF387F + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2PS" + (OP :OP #xF387F + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMT2PS" + (OP :OP #xF387F + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "INVEPT" (OP :OP #xF3880 :PFX :66) + (ARG :OP1 '(G Y) :OP2 '(M DQ)) + 'NIL + '((:UD (UD-NOT-IN-PROT-OR-64-MODE) + (UD-NOT-IN-VMX-OPERATION) + (UD-INVEPT-NOT-SUPPORTED) + (UD-MODR/M.MOD-INDICATES-REGISTER)) + (:GP (GP-CPL-NOT-0)))) + (INST "INVVPID" (OP :OP #xF3881 :PFX :66) + (ARG :OP1 '(G Y) :OP2 '(M DQ)) + 'NIL + '((:UD (UD-NOT-IN-PROT-OR-64-MODE) + (UD-NOT-IN-VMX-OPERATION) + (UD-INVVPID-NOT-SUPPORTED) + (UD-MODR/M.MOD-INDICATES-REGISTER)) + (:GP (GP-CPL-NOT-0)))) + (INST "INVPCID" (OP :OP #xF3882 :PFX :66) + (ARG :OP1 '(G Y) :OP2 '(M DQ)) + 'NIL + '((:UD (UD-LOCK-USED) + (UD-INVPCID-NOT-SUPPORTED) + (UD-MODR/M.MOD-INDICATES-REGISTER)) + (:GP (GP-CPL-NOT-0)))) + (INST "VPMULTISHIFTQB" + (OP :OP #xF3883 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512_VBMI :AVX512VL)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512_VBMI :AVX512VL))))) + (INST "VPMULTISHIFTQB" + (OP :OP #xF3883 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512_VBMI :AVX512VL)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512_VBMI :AVX512VL))))) + (INST "VPMULTISHIFTQB" + (OP :OP #xF3883 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512_VBMI))))) + (INST "VEXPANDPD" + (OP :OP #xF3888 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VEXPANDPD" + (OP :OP #xF3888 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VEXPANDPD" + (OP :OP #xF3888 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VEXPANDPS" + (OP :OP #xF3888 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VEXPANDPS" + (OP :OP #xF3888 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VEXPANDPS" + (OP :OP #xF3888 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VPEXPANDD" + (OP :OP #xF3889 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPEXPANDD" + (OP :OP #xF3889 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPEXPANDD" + (OP :OP #xF3889 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VPEXPANDQ" + (OP :OP #xF3889 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPEXPANDQ" + (OP :OP #xF3889 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPEXPANDQ" + (OP :OP #xF3889 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VCOMPRESSPD" + (OP :OP #xF388A + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VCOMPRESSPD" + (OP :OP #xF388A + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VCOMPRESSPD" + (OP :OP #xF388A + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VCOMPRESSPS" + (OP :OP #xF388A + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VCOMPRESSPS" + (OP :OP #xF388A + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VCOMPRESSPS" + (OP :OP #xF388A + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VPCOMPRESSD" + (OP :OP #xF388B + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPCOMPRESSD" + (OP :OP #xF388B + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPCOMPRESSD" + (OP :OP #xF388B + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VPCOMPRESSQ" + (OP :OP #xF388B + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPCOMPRESSQ" + (OP :OP #xF388B + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512F))))) + (INST "VPCOMPRESSQ" + (OP :OP #xF388B + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512F))))) + (INST "VPMASKMOVD" + (OP :OP #xF388C + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPMASKMOVD" + (OP :OP #xF388C + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPMASKMOVQ" + (OP :OP #xF388C + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPMASKMOVQ" + (OP :OP #xF388C + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPERMB" + (OP :OP #xF388D + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512_VBMI))))) + (INST "VPERMB" + (OP :OP #xF388D + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512_VBMI))))) + (INST "VPERMB" + (OP :OP #xF388D + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512_VBMI)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512_VBMI))))) + (INST "VPERMW" + (OP :OP #xF388D + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPERMW" + (OP :OP #xF388D + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPERMW" + (OP :OP #xF388D + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VPMASKMOVD" + (OP :OP #xF388E + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPMASKMOVD" + (OP :OP #xF388E + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPMASKMOVQ" + (OP :OP #xF388E + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPMASKMOVQ" + (OP :OP #xF388E + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX2) + :MOD :MEM) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(M X)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VPGATHERDD" + (OP :OP #xF3890 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERDD" + (OP :OP #xF3890 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERDQ" + (OP :OP #xF3890 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERDQ" + (OP :OP #xF3890 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERDD" + (OP :OP #xF3890 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERDD" + (OP :OP #xF3890 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERDD" + (OP :OP #xF3890 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VPGATHERDQ" + (OP :OP #xF3890 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERDQ" + (OP :OP #xF3890 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERDQ" + (OP :OP #xF3890 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VPGATHERQD" + (OP :OP #xF3891 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERQD" + (OP :OP #xF3891 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERQQ" + (OP :OP #xF3891 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERQQ" + (OP :OP #xF3891 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VPGATHERQD" + (OP :OP #xF3891 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERQD" + (OP :OP #xF3891 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERQD" + (OP :OP #xF3891 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VPGATHERQQ" + (OP :OP #xF3891 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERQQ" + (OP :OP #xF3891 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPGATHERQQ" + (OP :OP #xF3891 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VGATHERDPD" + (OP :OP #xF3892 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERDPD" + (OP :OP #xF3892 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERDPS" + (OP :OP #xF3892 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERDPS" + (OP :OP #xF3892 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERDPD" + (OP :OP #xF3892 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERDPD" + (OP :OP #xF3892 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERDPD" + (OP :OP #xF3892 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VGATHERDPS" + (OP :OP #xF3892 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERDPS" + (OP :OP #xF3892 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERDPS" + (OP :OP #xF3892 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VGATHERQPD" + (OP :OP #xF3893 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERQPD" + (OP :OP #xF3893 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERQPS" + (OP :OP #xF3893 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERQPS" + (OP :OP #xF3893 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-12 (:AVX2))))) + (INST "VGATHERQPD" + (OP :OP #xF3893 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERQPD" + (OP :OP #xF3893 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERQPD" + (OP :OP #xF3893 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VGATHERQPS" + (OP :OP #xF3893 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERQPS" + (OP :OP #xF3893 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VGATHERQPS" + (OP :OP #xF3893 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VFMADDSUB132PD" + (OP :OP #xF3896 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB132PD" + (OP :OP #xF3896 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB132PS" + (OP :OP #xF3896 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB132PS" + (OP :OP #xF3896 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB132PD" + (OP :OP #xF3896 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB132PD" + (OP :OP #xF3896 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB132PD" + (OP :OP #xF3896 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADDSUB132PS" + (OP :OP #xF3896 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB132PS" + (OP :OP #xF3896 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB132PS" + (OP :OP #xF3896 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUBADD132PD" + (OP :OP #xF3897 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD132PD" + (OP :OP #xF3897 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD132PS" + (OP :OP #xF3897 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD132PS" + (OP :OP #xF3897 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD132PD" + (OP :OP #xF3897 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD132PD" + (OP :OP #xF3897 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD132PD" + (OP :OP #xF3897 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUBADD132PS" + (OP :OP #xF3897 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD132PS" + (OP :OP #xF3897 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD132PS" + (OP :OP #xF3897 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD132PD" + (OP :OP #xF3898 + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD132PD" + (OP :OP #xF3898 + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD132PS" + (OP :OP #xF3898 + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD132PS" + (OP :OP #xF3898 + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD132PD" + (OP :OP #xF3898 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD132PD" + (OP :OP #xF3898 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD132PD" + (OP :OP #xF3898 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD132PS" + (OP :OP #xF3898 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD132PS" + (OP :OP #xF3898 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD132PS" + (OP :OP #xF3898 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD132SD" + (OP :OP #xF3899 + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD132SS" + (OP :OP #xF3899 + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD132SD" + (OP :OP #xF3899 + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMADD132SS" + (OP :OP #xF3899 + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMSUB132PD" + (OP :OP #xF389A + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB132PD" + (OP :OP #xF389A + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB132PS" + (OP :OP #xF389A + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB132PS" + (OP :OP #xF389A + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "V4FMADDPS" + (OP :OP #xF389A + :EVEX '(:0F38 :DDS :512 :F2 :W0) + :FEAT '(:AVX512_4FMAPS)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512_4FMAPS))))) + (INST "VFMSUB132PD" + (OP :OP #xF389A + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB132PD" + (OP :OP #xF389A + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB132PD" + (OP :OP #xF389A + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUB132PS" + (OP :OP #xF389A + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB132PS" + (OP :OP #xF389A + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB132PS" + (OP :OP #xF389A + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUB132SD" + (OP :OP #xF389B + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB132SS" + (OP :OP #xF389B + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "V4FMADDSS" + (OP :OP #xF389B + :EVEX '(:0F38 :DDS :LIG :F2 :W0) + :FEAT '(:AVX512_4FMAPS)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512_4FMAPS))))) + (INST "VFMSUB132SD" + (OP :OP #xF389B + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMSUB132SS" + (OP :OP #xF389B + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMADD132PD" + (OP :OP #xF389C + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD132PD" + (OP :OP #xF389C + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD132PS" + (OP :OP #xF389C + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD132PS" + (OP :OP #xF389C + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD132PD" + (OP :OP #xF389C + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD132PD" + (OP :OP #xF389C + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD132PD" + (OP :OP #xF389C + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMADD132PS" + (OP :OP #xF389C + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD132PS" + (OP :OP #xF389C + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD132PS" + (OP :OP #xF389C + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD132SD" + (OP :OP #xF389D + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD132SS" + (OP :OP #xF389D + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD132SD" + (OP :OP #xF389D + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMADD132SS" + (OP :OP #xF389D + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMSUB132PD" + (OP :OP #xF389E + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB132PD" + (OP :OP #xF389E + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB132PS" + (OP :OP #xF389E + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB132PS" + (OP :OP #xF389E + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB132PD" + (OP :OP #xF389E + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB132PD" + (OP :OP #xF389E + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB132PD" + (OP :OP #xF389E + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMSUB132PS" + (OP :OP #xF389E + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB132PS" + (OP :OP #xF389E + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB132PS" + (OP :OP #xF389E + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMSUB132SD" + (OP :OP #xF389F + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB132SS" + (OP :OP #xF389F + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB132SD" + (OP :OP #xF389F + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMSUB132SS" + (OP :OP #xF389F + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VPSCATTERDD" + (OP :OP #xF38A0 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERDD" + (OP :OP #xF38A0 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERDD" + (OP :OP #xF38A0 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VPSCATTERDQ" + (OP :OP #xF38A0 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERDQ" + (OP :OP #xF38A0 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERDQ" + (OP :OP #xF38A0 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VPSCATTERQD" + (OP :OP #xF38A1 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERQD" + (OP :OP #xF38A1 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERQD" + (OP :OP #xF38A1 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VPSCATTERQQ" + (OP :OP #xF38A1 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERQQ" + (OP :OP #xF38A1 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VPSCATTERQQ" + (OP :OP #xF38A1 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VSCATTERDPD" + (OP :OP #xF38A2 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERDPD" + (OP :OP #xF38A2 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERDPD" + (OP :OP #xF38A2 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VSCATTERDPS" + (OP :OP #xF38A2 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERDPS" + (OP :OP #xF38A2 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERDPS" + (OP :OP #xF38A2 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VSCATTERQPD" + (OP :OP #xF38A3 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERQPD" + (OP :OP #xF38A3 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERQPD" + (OP :OP #xF38A3 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VSCATTERQPS" + (OP :OP #xF38A3 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERQPS" + (OP :OP #xF38A3 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512VL :AVX512F))))) + (INST "VSCATTERQPS" + (OP :OP #xF38A3 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12 (:AVX512F))))) + (INST "VFMADDSUB213PD" + (OP :OP #xF38A6 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB213PD" + (OP :OP #xF38A6 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB213PS" + (OP :OP #xF38A6 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB213PS" + (OP :OP #xF38A6 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB213PD" + (OP :OP #xF38A6 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB213PD" + (OP :OP #xF38A6 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB213PD" + (OP :OP #xF38A6 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADDSUB213PS" + (OP :OP #xF38A6 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB213PS" + (OP :OP #xF38A6 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB213PS" + (OP :OP #xF38A6 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUBADD213PD" + (OP :OP #xF38A7 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD213PD" + (OP :OP #xF38A7 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD213PS" + (OP :OP #xF38A7 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD213PS" + (OP :OP #xF38A7 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD213PD" + (OP :OP #xF38A7 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD213PD" + (OP :OP #xF38A7 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD213PD" + (OP :OP #xF38A7 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUBADD213PS" + (OP :OP #xF38A7 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD213PS" + (OP :OP #xF38A7 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD213PS" + (OP :OP #xF38A7 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD213PD" + (OP :OP #xF38A8 + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD213PD" + (OP :OP #xF38A8 + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD213PS" + (OP :OP #xF38A8 + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD213PS" + (OP :OP #xF38A8 + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD213PD" + (OP :OP #xF38A8 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD213PD" + (OP :OP #xF38A8 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD213PD" + (OP :OP #xF38A8 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD213PS" + (OP :OP #xF38A8 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD213PS" + (OP :OP #xF38A8 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD213PS" + (OP :OP #xF38A8 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD213SD" + (OP :OP #xF38A9 + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD213SS" + (OP :OP #xF38A9 + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD213SD" + (OP :OP #xF38A9 + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMADD213SS" + (OP :OP #xF38A9 + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMSUB213PD" + (OP :OP #xF38AA + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB213PD" + (OP :OP #xF38AA + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB213PS" + (OP :OP #xF38AA + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB213PS" + (OP :OP #xF38AA + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "V4FNMADDPS" + (OP :OP #xF38AA + :EVEX '(:0F38 :DDS :512 :F2 :W0) + :FEAT '(:AVX512_4FMAPS)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512_4FMAPS))))) + (INST "VFMSUB213PD" + (OP :OP #xF38AA + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB213PD" + (OP :OP #xF38AA + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB213PD" + (OP :OP #xF38AA + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUB213PS" + (OP :OP #xF38AA + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB213PS" + (OP :OP #xF38AA + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB213PS" + (OP :OP #xF38AA + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUB213SD" + (OP :OP #xF38AB + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB213SS" + (OP :OP #xF38AB + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "V4FNMADDSS" + (OP :OP #xF38AB + :EVEX '(:0F38 :DDS :LIG :F2 :W0) + :FEAT '(:AVX512_4FMAPS)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512_4FMAPS))))) + (INST "VFMSUB213SD" + (OP :OP #xF38AB + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMSUB213SS" + (OP :OP #xF38AB + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMADD213PD" + (OP :OP #xF38AC + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD213PD" + (OP :OP #xF38AC + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD213PS" + (OP :OP #xF38AC + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD213PS" + (OP :OP #xF38AC + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD213PD" + (OP :OP #xF38AC + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD213PD" + (OP :OP #xF38AC + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD213PD" + (OP :OP #xF38AC + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMADD213PS" + (OP :OP #xF38AC + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD213PS" + (OP :OP #xF38AC + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD213PS" + (OP :OP #xF38AC + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMADD213SD" + (OP :OP #xF38AD + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD213SS" + (OP :OP #xF38AD + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD213SD" + (OP :OP #xF38AD + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMADD213SS" + (OP :OP #xF38AD + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMSUB213PD" + (OP :OP #xF38AE + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB213PD" + (OP :OP #xF38AE + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB213PS" + (OP :OP #xF38AE + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB213PS" + (OP :OP #xF38AE + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB213PD" + (OP :OP #xF38AE + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB213PD" + (OP :OP #xF38AE + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB213PD" + (OP :OP #xF38AE + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMSUB213PS" + (OP :OP #xF38AE + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB213PS" + (OP :OP #xF38AE + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB213PS" + (OP :OP #xF38AE + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMSUB213SD" + (OP :OP #xF38AF + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB213SS" + (OP :OP #xF38AF + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB213SD" + (OP :OP #xF38AF + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMSUB213SS" + (OP :OP #xF38AF + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VPMADD52LUQ" + (OP :OP #xF38B4 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512_IFMA :AVX512VL)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_IFMA :AVX512VL))))) + (INST "VPMADD52LUQ" + (OP :OP #xF38B4 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512_IFMA :AVX512VL)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_IFMA :AVX512VL))))) + (INST "VPMADD52LUQ" + (OP :OP #xF38B4 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512_IFMA)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_IFMA))))) + (INST "VPMADD52HUQ" + (OP :OP #xF38B5 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512_IFMA :AVX512VL)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_IFMA :AVX512VL))))) + (INST "VPMADD52HUQ" + (OP :OP #xF38B5 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512_IFMA :AVX512VL)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_IFMA :AVX512VL))))) + (INST "VPMADD52HUQ" + (OP :OP #xF38B5 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512_IFMA)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512_IFMA))))) + (INST "VFMADDSUB231PD" + (OP :OP #xF38B6 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB231PD" + (OP :OP #xF38B6 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB231PS" + (OP :OP #xF38B6 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB231PS" + (OP :OP #xF38B6 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADDSUB231PD" + (OP :OP #xF38B6 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB231PD" + (OP :OP #xF38B6 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB231PD" + (OP :OP #xF38B6 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADDSUB231PS" + (OP :OP #xF38B6 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB231PS" + (OP :OP #xF38B6 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADDSUB231PS" + (OP :OP #xF38B6 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUBADD231PD" + (OP :OP #xF38B7 + :VEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD231PD" + (OP :OP #xF38B7 + :VEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD231PS" + (OP :OP #xF38B7 + :VEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD231PS" + (OP :OP #xF38B7 + :VEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUBADD231PD" + (OP :OP #xF38B7 + :EVEX '(:0F38 :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD231PD" + (OP :OP #xF38B7 + :EVEX '(:0F38 :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD231PD" + (OP :OP #xF38B7 + :EVEX '(:0F38 :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUBADD231PS" + (OP :OP #xF38B7 + :EVEX '(:0F38 :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD231PS" + (OP :OP #xF38B7 + :EVEX '(:0F38 :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUBADD231PS" + (OP :OP #xF38B7 + :EVEX '(:0F38 :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD231PD" + (OP :OP #xF38B8 + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD231PD" + (OP :OP #xF38B8 + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD231PS" + (OP :OP #xF38B8 + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD231PS" + (OP :OP #xF38B8 + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD231PD" + (OP :OP #xF38B8 + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD231PD" + (OP :OP #xF38B8 + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD231PD" + (OP :OP #xF38B8 + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD231PS" + (OP :OP #xF38B8 + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD231PS" + (OP :OP #xF38B8 + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMADD231PS" + (OP :OP #xF38B8 + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMADD231SD" + (OP :OP #xF38B9 + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD231SS" + (OP :OP #xF38B9 + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMADD231SD" + (OP :OP #xF38B9 + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMADD231SS" + (OP :OP #xF38B9 + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMSUB231PD" + (OP :OP #xF38BA + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB231PD" + (OP :OP #xF38BA + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB231PS" + (OP :OP #xF38BA + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB231PS" + (OP :OP #xF38BA + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB231PD" + (OP :OP #xF38BA + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB231PD" + (OP :OP #xF38BA + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB231PD" + (OP :OP #xF38BA + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUB231PS" + (OP :OP #xF38BA + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB231PS" + (OP :OP #xF38BA + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFMSUB231PS" + (OP :OP #xF38BA + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFMSUB231SD" + (OP :OP #xF38BB + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB231SS" + (OP :OP #xF38BB + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFMSUB231SD" + (OP :OP #xF38BB + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFMSUB231SS" + (OP :OP #xF38BB + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMADD231PD" + (OP :OP #xF38BC + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD231PD" + (OP :OP #xF38BC + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD231PS" + (OP :OP #xF38BC + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD231PS" + (OP :OP #xF38BC + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD231PD" + (OP :OP #xF38BC + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD231PD" + (OP :OP #xF38BC + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD231PD" + (OP :OP #xF38BC + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMADD231PS" + (OP :OP #xF38BC + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD231PS" + (OP :OP #xF38BC + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMADD231PS" + (OP :OP #xF38BC + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMADD231SD" + (OP :OP #xF38BD + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD231SS" + (OP :OP #xF38BD + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMADD231SD" + (OP :OP #xF38BD + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMADD231SS" + (OP :OP #xF38BD + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMSUB231PD" + (OP :OP #xF38BE + :VEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB231PD" + (OP :OP #xF38BE + :VEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB231PS" + (OP :OP #xF38BE + :VEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB231PS" + (OP :OP #xF38BE + :VEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB231PD" + (OP :OP #xF38BE + :EVEX '(:0F38 :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB231PD" + (OP :OP #xF38BE + :EVEX '(:0F38 :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB231PD" + (OP :OP #xF38BE + :EVEX '(:0F38 :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMSUB231PS" + (OP :OP #xF38BE + :EVEX '(:0F38 :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB231PS" + (OP :OP #xF38BE + :EVEX '(:0F38 :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFNMSUB231PS" + (OP :OP #xF38BE + :EVEX '(:0F38 :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFNMSUB231SD" + (OP :OP #xF38BF + :VEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB231SS" + (OP :OP #xF38BF + :VEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:FMA :AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-2 (:FMA :AVX))))) + (INST "VFNMSUB231SD" + (OP :OP #xF38BF + :EVEX '(:0F38 :DDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFNMSUB231SS" + (OP :OP #xF38BF + :EVEX '(:0F38 :DDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VPCONFLICTD" + (OP :OP #xF38C4 + :EVEX '(:0F38 :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPCONFLICTD" + (OP :OP #xF38C4 + :EVEX '(:0F38 :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPCONFLICTD" + (OP :OP #xF38C4 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512CD))))) + (INST "VPCONFLICTQ" + (OP :OP #xF38C4 + :EVEX '(:0F38 :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPCONFLICTQ" + (OP :OP #xF38C4 + :EVEX '(:0F38 :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512CD))))) + (INST "VPCONFLICTQ" + (OP :OP #xF38C4 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512CD)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512CD))))) + (INST "VGATHERPF0DPS" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VGATHERPF0DPD" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VGATHERPF1DPS" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VGATHERPF1DPD" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF0DPS" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x5) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF0DPD" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x5) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF1DPS" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF1DPD" + (OP :OP #xF38C6 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VGATHERPF0QPS" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VGATHERPF0QPD" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x1) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VGATHERPF1QPS" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VGATHERPF1QPD" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x2) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF0QPS" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x5) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF0QPD" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x5) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF1QPS" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512PF) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "VSCATTERPF1QPD" + (OP :OP #xF38C7 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512PF) + :REG #x6) + NIL NIL + '((:EX (CHK-EXC :TYPE-E12NP (:AVX512PF))))) + (INST "SHA1NEXTE" + (OP :OP #xF38C8 :FEAT '(:SHA)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SHA))))) + (INST "VEXP2PD" + (OP :OP #xF38C8 + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512ER))))) + (INST "VEXP2PS" + (OP :OP #xF38C8 + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512ER))))) + (INST "SHA1MSG1" + (OP :OP #xF38C9 :FEAT '(:SHA)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SHA))))) + (INST "SHA1MSG2" + (OP :OP #xF38CA :FEAT '(:SHA)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SHA))))) + (INST "VRCP28PD" + (OP :OP #xF38CA + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512ER))))) + (INST "VRCP28PS" + (OP :OP #xF38CA + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512ER))))) + (INST "SHA256RNDS2" + (OP :OP #xF38CB :FEAT '(:SHA)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SHA))))) + (INST "VRCP28SD" + (OP :OP #xF38CB + :EVEX '(:0F38 :NDS :LIG :66 :W1) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512ER))))) + (INST "VRCP28SS" + (OP :OP #xF38CB + :EVEX '(:0F38 :NDS :LIG :66 :W0) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512ER))))) + (INST "SHA256MSG1" + (OP :OP #xF38CC :FEAT '(:SHA)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SHA))))) + (INST "VRSQRT28PD" + (OP :OP #xF38CC + :EVEX '(:0F38 :512 :66 :W1) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512ER))))) + (INST "VRSQRT28PS" + (OP :OP #xF38CC + :EVEX '(:0F38 :512 :66 :W0) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512ER))))) + (INST "SHA256MSG2" + (OP :OP #xF38CD :FEAT '(:SHA)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SHA))))) + (INST "VRSQRT28SD" + (OP :OP #xF38CD + :EVEX '(:0F38 :NDS :LIG :66 :W1) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512ER))))) + (INST "VRSQRT28SS" + (OP :OP #xF38CD + :EVEX '(:0F38 :NDS :LIG :66 :W0) + :FEAT '(:AVX512ER)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512ER))))) + (INST "AESIMC" + (OP :OP #xF38DB + :PFX :66 + :FEAT '(:AES)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:AES))))) + (INST "VAESIMC" + (OP :OP #xF38DB + :VEX '(:0F38 :128 :66 :WIG) + :FEAT '(:AES :AVX)) + (ARG :OP1 '(V DQ) :OP2 '(W DQ)) + NIL + '((:EX (CHK-EXC :TYPE-4 (:AES :AVX))))) + (INST "AESENC" + (OP :OP #xF38DC + :PFX :66 + :FEAT '(:AES)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:AES))))) + (INST "VAESENC" + (OP :OP #xF38DC + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AES :AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + NIL + '((:EX (CHK-EXC :TYPE-4 (:AES :AVX))))) + (INST "AESENCAST" + (OP :OP #xF38DD + :PFX :66 + :FEAT '(:AES)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:AES))))) + (INST "VAESENCLAST" + (OP :OP #xF38DD + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AES :AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + NIL + '((:EX (CHK-EXC :TYPE-4 (:AES :AVX))))) + (INST "AESDEC" + (OP :OP #xF38DE + :PFX :66 + :FEAT '(:AES)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:AES))))) + (INST "VAESDEC" + (OP :OP #xF38DE + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AES :AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + NIL + '((:EX (CHK-EXC :TYPE-4 (:AES :AVX))))) + (INST "AESDECLAST" + (OP :OP #xF38DF + :PFX :66 + :FEAT '(:AES)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:AES))))) + (INST "VAESDECLAST" + (OP :OP #xF38DF + :VEX '(:0F38 :NDS :128 :66 :WIG) + :FEAT '(:AES :AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ)) + NIL + '((:EX (CHK-EXC :TYPE-4 (:AES :AVX))))) + (INST "MOVBE" (OP :OP #xF38F0 :PFX :NO-PREFIX + :FEAT '(:MOVBE)) + (ARG :OP1 '(G Y) :OP2 '(M Y)) + '(X86-MOVBE-OP/EN-RM) + '((:UD (UD-LOCK-USED) + (UD-REPNE-F2-V86-CPUID-CASE) + (UD-REP-F3-USED) + (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "MOVBE" (OP :OP #xF38F0 :PFX :66 + :FEAT '(:MOVBE)) + (ARG :OP1 '(G W) :OP2 '(M W)) + '(X86-MOVBE-OP/EN-RM) + '((:UD (UD-LOCK-USED) + (UD-REPNE-F2-V86-CPUID-CASE) + (UD-REP-F3-USED) + (UD-MODR/M.MOD-INDICATES-REGISTER)))) + ;; A note about the two mandatory prefixes listed for CRC (0F 38 F0) in the + ;; Intel Opcode Map: The first three-byte opcode map lists CRC under 66 & + ;; F2 separately, even though CRC is already listed under F2 and MOVBE + ;; under 66. Essentially, 66 is just a modifier prefix for CRC in this + ;; case. So we ignore that opcode row in our representation, because + ;; opcode dispatch, modr/m determination, opcode coverage, etc. (which is + ;; what these tables are used for) will still work as expected for CRC, + ;; irrespective of whether 66 is present as a modifier or not. + (INST "CRC32" (OP :OP #xF38F0 :PFX :F2 + :FEAT '(:SSE4.2)) + (ARG :OP1 '(G D) :OP2 '(E B)) + '(X86-CRC32) + '((:UD (UD-LOCK-USED)))) + (INST "MOVBE" (OP :OP #xF38F1 :PFX :NO-PREFIX + :FEAT '(:MOVBE)) + (ARG :OP1 '(M Y) :OP2 '(G Y)) + '(X86-MOVBE-OP/EN-MR) + '((:UD (UD-LOCK-USED) + (UD-REPNE-F2-V86-CPUID-CASE) + (UD-REP-F3-USED) + (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "MOVBE" (OP :OP #xF38F1 :PFX :66 + :FEAT '(:MOVBE)) + (ARG :OP1 '(M W) :OP2 '(G W)) + '(X86-MOVBE-OP/EN-MR) + '((:UD (UD-LOCK-USED) + (UD-REPNE-F2-V86-CPUID-CASE) + (UD-REP-F3-USED) + (UD-MODR/M.MOD-INDICATES-REGISTER)))) + (INST "CRC32" (OP :OP #xF38F1 :PFX :F2 + :FEAT '(:SSE4.2)) + (ARG :OP1 '(G D) :OP2 '(E Y)) + '(X86-CRC32) + '((:UD (UD-LOCK-USED)))) + (INST "ANDN" + (OP :OP #xF38F2 + :VEX '(:0F38 :NDS :LZ :W0) + :FEAT '(:BMI1 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(B Y) + :OP3 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "ANDN" + (OP :OP #xF38F2 + :VEX '(:0F38 :NDS :LZ :W1) + :FEAT '(:BMI1 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(B Y) + :OP3 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + ;; BLSR, BLSMSK, BLSI are VEX-only instructions. + ;; (INST "BLSR" + ;; (OP :OP #xF38F3 + ;; :REG #x1 + ;; :SUPERSCRIPTS '(:V) + ;; :FEAT '(:BMI2 :AVX) + ;; :GROUP '(:GROUP-17)) + ;; (ARG :OP1 '(B Y) :OP2 '(E Y)) + ;; 'NIL + ;; '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + ;; (INST "BLSMSK" + ;; (OP :OP #xF38F3 + ;; :REG #x2 + ;; :FEAT '(:BMI2 :AVX) + ;; :SUPERSCRIPTS '(:V) + ;; :GROUP '(:GROUP-17)) + ;; (ARG :OP1 '(B Y) :OP2 '(E Y)) + ;; 'NIL + ;; '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + ;; (INST "BLSI" + ;; (OP :OP #xF38F3 + ;; :REG #x3 + ;; :SUPERSCRIPTS '(:V) + ;; :FEAT '(:BMI2 :AVX)) + ;; (ARG :OP1 '(B Y) :OP2 '(E Y)) + ;; 'NIL + ;; '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "BLSR" + (OP :OP #xF38F3 + :VEX '(:0F38 :NDD :LZ :W0) + :FEAT '(:BMI1 :AVX) + :REG #x1 + :GROUP '(:GROUP-17)) + (ARG :OP1 '(B Y) :OP2 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "BLSR" + (OP :OP #xF38F3 + :VEX '(:0F38 :NDD :LZ :W1) + :FEAT '(:BMI1 :AVX) + :REG #x1 + :GROUP '(:GROUP-17)) + (ARG :OP1 '(B Y) :OP2 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "BLSMSK" + (OP :OP #xF38F3 + :VEX '(:0F38 :NDD :LZ :W0) + :FEAT '(:BMI1 :AVX) + :REG #x2 + :GROUP '(:GROUP-17)) + (ARG :OP1 '(B Y) :OP2 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "BLSMSK" + (OP :OP #xF38F3 + :VEX '(:0F38 :NDD :LZ :W1) + :FEAT '(:BMI1 :AVX) + :REG #x2 + :GROUP '(:GROUP-17)) + (ARG :OP1 '(B Y) :OP2 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "BLSI" + (OP :OP #xF38F3 + :VEX '(:0F38 :NDD :LZ :W0) + :FEAT '(:BMI1 :AVX) + :REG #x3 + :GROUP '(:GROUP-17)) + (ARG :OP1 '(B Y) :OP2 '(E Y)) + '(x86-blsi) + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "BLSI" + (OP :OP #xF38F3 + :VEX '(:0F38 :NDD :LZ :W1) + :FEAT '(:BMI1 :AVX) + :REG #x3 + :GROUP '(:GROUP-17)) + (ARG :OP1 '(B Y) :OP2 '(E Y)) + '(x86-blsi) + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "BZHI" + (OP :OP #xF38F5 + :VEX '(:0F38 :NDS :LZ :W0) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "BZHI" + (OP :OP #xF38F5 + :VEX '(:0F38 :NDS :LZ :W1) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "PDEP" + (OP :OP #xF38F5 + :VEX '(:0F38 :NDS :LZ :F2 :W0) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(B Y) + :OP3 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "PDEP" + (OP :OP #xF38F5 + :VEX '(:0F38 :NDS :LZ :F2 :W1) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(B Y) + :OP3 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "PEXT" + (OP :OP #xF38F5 + :VEX '(:0F38 :NDS :LZ :F3 :W0) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(B Y) + :OP3 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "PEXT" + (OP :OP #xF38F5 + :VEX '(:0F38 :NDS :LZ :F3 :W1) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(B Y) + :OP3 '(E Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "ADCX" + (OP :OP #xF38F6 + :PFX :66 + :FEAT '(:ADX)) + (ARG :OP1 '(G Y) :OP2 '(E Y)) + '(X86-ADCX/ADOX (ADCX . T)) + '((:UD (UD-LOCK-USED)))) + (INST "ADOX" + (OP :OP #xF38F6 + :PFX :F3 + :FEAT '(:ADX)) + (ARG :OP1 '(G Y) :OP2 '(E Y)) + '(X86-ADCX/ADOX (ADCX . NIL)) + '((:UD (UD-LOCK-USED)))) + (INST "MULX" + (OP :OP #xF38F6 + :VEX '(:0F38 :NDD :LZ :F2 :W0) + :FEAT '(:BMI2)) + (ARG :OP1 '(B Y) + :OP2 '(G Y) + :OP3 '(:RDX) + :OP4 '(E Y)) + '(X86-MULX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2))))) + (INST "MULX" + (OP :OP #xF38F6 + :VEX '(:0F38 :NDD :LZ :F2 :W1) + :FEAT '(:BMI2)) + (ARG :OP1 '(B Y) + :OP2 '(G Y) + :OP3 '(:RDX) + :OP4 '(E Y)) + '(X86-MULX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2))))) + (INST "BEXTR" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :W0) + :FEAT '(:BMI1 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "BEXTR" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :W1) + :FEAT '(:BMI1 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + NIL + '((:EX (CHK-EXC :TYPE-13 (:BMI1 :AVX))))) + (INST "SARX" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :F3 :W0) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + '(X86-SARX/SHLX/SHRX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "SARX" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :F3 :W1) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + '(X86-SARX/SHLX/SHRX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "SHLX" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :66 :W0) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + '(X86-SARX/SHLX/SHRX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "SHLX" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :66 :W1) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + '(X86-SARX/SHLX/SHRX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "SHRX" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :F2 :W0) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + '(X86-SARX/SHLX/SHRX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))) + (INST "SHRX" + (OP :OP #xF38F7 + :VEX '(:0F38 :NDS :LZ :F2 :W1) + :FEAT '(:BMI2 :AVX)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(B Y)) + '(X86-SARX/SHLX/SHRX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2 :AVX))))))) + +(defconst *pre-0f-3a-three-byte-opcode-map* + '((INST "VPERMQ" + (OP :OP #xF3A00 + :VEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V QQ) + :OP2 '(W QQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPERMQ" + (OP :OP #xF3A00 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMQ" + (OP :OP #xF3A00 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMPD" + (OP :OP #xF3A01 + :VEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX2)) + (ARG :OP1 '(V QQ) + :OP2 '(W QQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPERMPD" + (OP :OP #xF3A01 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMPD" + (OP :OP #xF3A01 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPBLENDD" + (OP :OP #xF3A02 + :VEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPBLENDD" + (OP :OP #xF3A02 + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VALIGND" + (OP :OP #xF3A03 + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VALIGNQ" + (OP :OP #xF3A03 + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VALIGND" + (OP :OP #xF3A03 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VALIGNQ" + (OP :OP #xF3A03 + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VALIGND" + (OP :OP #xF3A03 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VALIGNQ" + (OP :OP #xF3A03 + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMILPS" + (OP :OP #xF3A04 + :VEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPS" + (OP :OP #xF3A04 + :VEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPS" + (OP :OP #xF3A04 + :EVEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPS" + (OP :OP #xF3A04 + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPS" + (OP :OP #xF3A04 + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERMILPD" + (OP :OP #xF3A05 + :VEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPD" + (OP :OP #xF3A05 + :VEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPERMILPD" + (OP :OP #xF3A05 + :EVEX '(:0F3A :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPD" + (OP :OP #xF3A05 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VPERMILPD" + (OP :OP #xF3A05 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPERM2F128" + (OP :OP #xF3A06 + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V QQ) + :OP2 '(H QQ) + :OP3 '(W QQ) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "ROUNDPS" + (OP :OP #xF3A08 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE4.1))))) + (INST "VROUNDPS" + (OP :OP #xF3A08 + :VEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VROUNDPS" + (OP :OP #xF3A08 + :VEX '(:0F3A :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VRNDSCALEPS" + (OP :OP #xF3A08 + :EVEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VRNDSCALEPS" + (OP :OP #xF3A08 + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VRNDSCALEPS" + (OP :OP #xF3A08 + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "ROUNDPD" + (OP :OP #xF3A09 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE4.1))))) + (INST "VROUNDPD" + (OP :OP #xF3A09 + :VEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VROUNDPD" + (OP :OP #xF3A09 + :VEX '(:0F3A :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(W X) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VRNDSCALEPD" + (OP :OP #xF3A09 + :EVEX '(:0F3A :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VRNDSCALEPD" + (OP :OP #xF3A09 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VRNDSCALEPD" + (OP :OP #xF3A09 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "ROUNDSS" + (OP :OP #xF3A0A + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V SS) + :OP2 '(W SS) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-3 (:SSE4.1))))) + (INST "VROUNDSS" + (OP :OP #xF3A0A + :VEX '(:0F3A :NDS :LIG :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SS) + :OP2 '(W SS) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VRNDSCALESS" + (OP :OP #xF3A0A + :EVEX '(:0F3A :NDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "ROUNDSD" + (OP :OP #xF3A0B + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V SD) + :OP2 '(W SD) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-3 (:SSE4.1))))) + (INST "VROUNDSD" + (OP :OP #xF3A0B + :VEX '(:0F3A :NDS :LIG :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V SD) + :OP2 '(W SD) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-3 (:AVX))))) + (INST "VRNDSCALESD" + (OP :OP #xF3A0B + :EVEX '(:0F3A :NDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "BLENDPS" + (OP :OP #xF3A0C + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VBLENDPS" + (OP :OP #xF3A0C + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VBLENDPS" + (OP :OP #xF3A0C + :VEX '(:0F3A :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "BLENDPD" + (OP :OP #xF3A0D + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VBLENDPD" + (OP :OP #xF3A0D + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VBLENDPD" + (OP :OP #xF3A0D + :VEX '(:0F3A :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PBLENDW" + (OP :OP #xF3A0E + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VPBLENDW" + (OP :OP #xF3A0E + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPBLENDW" + (OP :OP #xF3A0E + :VEX '(:0F3A :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "PALIGNR" + (OP :OP #xF3A0F + :PFX :NO-PREFIX + :FEAT '(:SSSE3)) + (ARG :OP1 '(P Q) + :OP2 '(Q Q) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "PALIGNR" + (OP :OP #xF3A0F + :PFX :66 + :FEAT '(:SSSE3)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSSE3))))) + (INST "VPALIGNR" + (OP :OP #xF3A0F + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPALIGNR" + (OP :OP #xF3A0F + :VEX '(:0F3A :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VPALIGNR" + (OP :OP #xF3A0F + :EVEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPALIGNR" + (OP :OP #xF3A0F + :EVEX '(:0F3A :NDS :256 :66 :WIG) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VPALIGNR" + (OP :OP #xF3A0F + :EVEX '(:0F3A :NDS :512 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "PEXTRB" + (OP :OP #xF3A14 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(M B) + :OP2 '(V DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PEXTRB" + (OP :OP #xF3A14 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(R D) + :OP2 '(V DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPEXTRB" + (OP :OP #xF3A14 + :VEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(R D) + :OP2 '(V DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPEXTRB" + (OP :OP #xF3A14 + :EVEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "PEXTRW" + (OP :OP #xF3A15 :MOD :MEM :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(M W) + :OP2 '(V DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "PEXTRW" + (OP :OP #xF3A15 :MOD #x3 :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(R D) + :OP2 '(V DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:AVX2))))) + (INST "VPEXTRW" + (OP :OP #xF3A15 + :VEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(G D) + :OP2 '(U DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPEXTRW" + (OP :OP #xF3A15 + :EVEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + (INST "PEXTRD/Q" + (OP :OP #xF3A16 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(E Y) + :OP2 '(V DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "VPEXTRD" + (OP :OP #xF3A16 + :VEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(E Y) + :OP2 '(V DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPEXTRQ" + (OP :OP #xF3A16 + :VEX '(:0F3A :128 :66 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(E Y) + :OP2 '(V DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPEXTRD" + (OP :OP #xF3A16 + :EVEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512DQ))))) + (INST "VPEXTRQ" + (OP :OP #xF3A16 + :EVEX '(:0F3A :128 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512DQ))))) + (INST "EXTRACTPS" + (OP :OP #xF3A17 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(E D) + :OP2 '(V DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "VEXTRACTPS" + (OP :OP #xF3A17 + :VEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(E D) + :OP2 '(V DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VEXTRACTPS" + (OP :OP #xF3A17 + :EVEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "VINSERTF128" + (OP :OP #xF3A18 + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V QQ) + :OP2 '(H QQ) + :OP3 '(W QQ) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VINSERTF32X4" + (OP :OP #xF3A18 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512F))))) + (INST "VINSERTF64X2" + (OP :OP #xF3A18 + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512DQ))))) + (INST "VINSERTF32X4" + (OP :OP #xF3A18 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VINSERTF64X2" + (OP :OP #xF3A18 + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VEXTRACTF128" + (OP :OP #xF3A19 + :VEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(W DQ) + :OP2 '(V QQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX))))) + (INST "VEXTRACTF32X4" + (OP :OP #xF3A19 + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512F))))) + (INST "VEXTRACTF64X2" + (OP :OP #xF3A19 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512DQ))))) + (INST "VEXTRACTF32X4" + (OP :OP #xF3A19 + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VEXTRACTF64X2" + (OP :OP #xF3A19 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VINSERTF32X8" + (OP :OP #xF3A1A + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VINSERTF64X4" + (OP :OP #xF3A1A + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VEXTRACTF32X8" + (OP :OP #xF3A1B + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VEXTRACTF64X4" + (OP :OP #xF3A1B + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VCVTPS2PH" + (OP :OP #xF3A1D + :VEX '(:0F3A :128 :66 :W0) + :FEAT '(:F16C :AVX)) + (ARG :OP1 '(W X) + :OP2 '(V X) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-11 (:F16C :AVX))))) + (INST "VCVTPS2PH" + (OP :OP #xF3A1D + :VEX '(:0F3A :256 :66 :W0) + :FEAT '(:F16C :AVX)) + (ARG :OP1 '(W X) + :OP2 '(V X) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-11 (:F16C :AVX))))) + (INST "VCVTPS2PH" + (OP :OP #xF3A1D + :EVEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E11 (:AVX512VL :AVX512F))))) + (INST "VCVTPS2PH" + (OP :OP #xF3A1D + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E11 (:AVX512VL :AVX512F))))) + (INST "VCVTPS2PH" + (OP :OP #xF3A1D + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E11 (:AVX512F))))) + (INST "VPCMPUD" + (OP :OP #xF3A1E + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPUD" + (OP :OP #xF3A1E + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPUD" + (OP :OP #xF3A1E + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPCMPUQ" + (OP :OP #xF3A1E + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPUQ" + (OP :OP #xF3A1E + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPUQ" + (OP :OP #xF3A1E + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPCMPD" + (OP :OP #xF3A1F + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPD" + (OP :OP #xF3A1F + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPD" + (OP :OP #xF3A1F + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPCMPQ" + (OP :OP #xF3A1F + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPQ" + (OP :OP #xF3A1F + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPCMPQ" + (OP :OP #xF3A1F + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + + (INST "PINSRB" + (OP :OP #xF3A20 + :PFX :66 + :MOD #x3 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(R Y) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + + (INST "PINSRB" + (OP :OP #xF3A20 + :PFX :66 + :MOD :MEM + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(M B) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "VPINSRB" + (OP :OP #xF3A20 + :VEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(R Y) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPINSRB" + (OP :OP #xF3A20 + :EVEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512BW))))) + + (INST "INSERTPS" + (OP :OP #xF3A21 + :PFX :66 + :MOD :MEM + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(M D) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + + (INST "INSERTPS" + (OP :OP #xF3A21 + :PFX :66 + :MOD #x3 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(U DQ) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "VINSERTPS" + (OP :OP #xF3A21 + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX) + :MOD :MEM) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(M D) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VINSERTPS" + (OP :OP #xF3A21 + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX) + :MOD #x3) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(U DQ) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VINSERTPS" + (OP :OP #xF3A21 + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512F))))) + (INST "PINSRD/Q" + (OP :OP #xF3A22 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(E Y) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-5 (:SSE4.1))))) + (INST "VPINSRD" + (OP :OP #xF3A22 + :VEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(E Y) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPINSRQ" + (OP :OP #xF3A22 + :VEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(E Y) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-5 (:AVX))))) + (INST "VPINSRD" + (OP :OP #xF3A22 + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512DQ))))) + (INST "VPINSRQ" + (OP :OP #xF3A22 + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E9NF (:AVX512DQ))))) + (INST "VSHUFF32X4" + (OP :OP #xF3A23 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFF64X2" + (OP :OP #xF3A23 + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFF32X4" + (OP :OP #xF3A23 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VSHUFF64X2" + (OP :OP #xF3A23 + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VPTERNLOGD" + (OP :OP #xF3A25 + :EVEX '(:0F3A :DDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTERNLOGQ" + (OP :OP #xF3A25 + :EVEX '(:0F3A :DDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTERNLOGD" + (OP :OP #xF3A25 + :EVEX '(:0F3A :DDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTERNLOGQ" + (OP :OP #xF3A25 + :EVEX '(:0F3A :DDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512F))))) + (INST "VPTERNLOGD" + (OP :OP #xF3A25 + :EVEX '(:0F3A :DDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VPTERNLOGQ" + (OP :OP #xF3A25 + :EVEX '(:0F3A :DDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512F))))) + (INST "VGETMANTPD" + (OP :OP #xF3A26 + :EVEX '(:0F3A :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETMANTPD" + (OP :OP #xF3A26 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETMANTPD" + (OP :OP #xF3A26 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VGETMANTPS" + (OP :OP #xF3A26 + :EVEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETMANTPS" + (OP :OP #xF3A26 + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VGETMANTPS" + (OP :OP #xF3A26 + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VGETMANTSD" + (OP :OP #xF3A27 + :EVEX '(:0F3A :NDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VGETMANTSS" + (OP :OP #xF3A27 + :EVEX '(:0F3A :NDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "KSHIFTRB" + (OP :OP #xF3A30 + :VEX '(:0F3A :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KSHIFTRW" + (OP :OP #xF3A30 + :VEX '(:0F3A :L0 :66 :W1) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-R/M W) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "KSHIFTRD" + (OP :OP #xF3A31 + :VEX '(:0F3A :L0 :66 :W0) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KSHIFTRQ" + (OP :OP #xF3A31 + :VEX '(:0F3A :L0 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-R/M Q) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KSHIFTLB" + (OP :OP #xF3A32 + :VEX '(:0F3A :L0 :66 :W0) + :FEAT '(:AVX512DQ) + :MOD #x3) + (ARG :OP1 '(K-REG B) + :OP2 '(K-R/M B) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512DQ))))) + (INST "KSHIFTLW" + (OP :OP #xF3A32 + :VEX '(:0F3A :L0 :66 :W1) + :FEAT '(:AVX512F) + :MOD #x3) + (ARG :OP1 '(K-REG W) + :OP2 '(K-R/M W) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512F))))) + (INST "KSHIFTLD" + (OP :OP #xF3A33 + :VEX '(:0F3A :L0 :66 :W0) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG D) + :OP2 '(K-R/M D) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "KSHIFTLQ" + (OP :OP #xF3A33 + :VEX '(:0F3A :L0 :66 :W1) + :FEAT '(:AVX512BW) + :MOD #x3) + (ARG :OP1 '(K-REG Q) + :OP2 '(K-R/M Q) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-K20 (:AVX512BW))))) + (INST "VINSERTI128" + (OP :OP #xF3A38 + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V QQ) + :OP2 '(H QQ) + :OP3 '(W QQ) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VINSERTI32X4" + (OP :OP #xF3A38 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512F))))) + (INST "VINSERTI64X2" + (OP :OP #xF3A38 + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512DQ))))) + (INST "VINSERTI32X4" + (OP :OP #xF3A38 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VINSERTI64X2" + (OP :OP #xF3A38 + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VEXTRACTI128" + (OP :OP #xF3A39 + :VEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(W DQ) + :OP2 '(V QQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VEXTRACTI32X4" + (OP :OP #xF3A39 + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512F))))) + (INST "VEXTRACTI64X2" + (OP :OP #xF3A39 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512VL :AVX512DQ))))) + (INST "VEXTRACTI32X4" + (OP :OP #xF3A39 + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VEXTRACTI64X2" + (OP :OP #xF3A39 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VINSERTI32X8" + (OP :OP #xF3A3A + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VINSERTI64X4" + (OP :OP #xF3A3A + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VEXTRACTI32X8" + (OP :OP #xF3A3B + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512DQ))))) + (INST "VEXTRACTI64X4" + (OP :OP #xF3A3B + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6NF (:AVX512F))))) + (INST "VPCMPUB" + (OP :OP #xF3A3E + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPUB" + (OP :OP #xF3A3E + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPUB" + (OP :OP #xF3A3E + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VPCMPUW" + (OP :OP #xF3A3E + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPUW" + (OP :OP #xF3A3E + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPB" + (OP :OP #xF3A3F + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPB" + (OP :OP #xF3A3F + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPB" + (OP :OP #xF3A3F + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "VPCMPW" + (OP :OP #xF3A3F + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPW" + (OP :OP #xF3A3F + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512VL :AVX512BW))))) + (INST "VPCMPW" + (OP :OP #xF3A3F + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4.NB (:AVX512BW))))) + (INST "DPPS" + (OP :OP #xF3A40 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE4.1))))) + (INST "VDPPS" + (OP :OP #xF3A40 + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "VDPPS" + (OP :OP #xF3A40 + :VEX '(:0F3A :NDS :256 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "DPPD" + (OP :OP #xF3A41 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-2 (:SSE4.1))))) + (INST "VDPPD" + (OP :OP #xF3A41 + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-2 (:AVX))))) + (INST "MPSADBW" + (OP :OP #xF3A42 + :PFX :66 + :FEAT '(:SSE4.1)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.1))))) + (INST "VMPSADBW" + (OP :OP #xF3A42 + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VMPSADBW" + (OP :OP #xF3A42 + :VEX '(:0F3A :NDS :256 :66 :WIG) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VDBPSADBW" + (OP :OP #xF3A42 + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VDBPSADBW" + (OP :OP #xF3A42 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512VL :AVX512BW))))) + (INST "VDBPSADBW" + (OP :OP #xF3A42 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512BW)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF.NB (:AVX512BW))))) + (INST "VSHUFI32X4" + (OP :OP #xF3A43 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFI64X2" + (OP :OP #xF3A43 + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512VL :AVX512F))))) + (INST "VSHUFI32X4" + (OP :OP #xF3A43 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "VSHUFI64X2" + (OP :OP #xF3A43 + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4NF (:AVX512F))))) + (INST "PCLMULQDQ" + (OP :OP #xF3A44 + :PFX :66 + :FEAT '(:PCLMULQDQ)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ) + :OP4 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:PCLMULQDQ))))) + (INST "VPCLMULQDQ" + (OP :OP #xF3A44 + :VEX '(:0F3A :NDS :128 :66 :WIG) + :FEAT '(:PCLMULQDQ :AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(H DQ) + :OP3 '(W DQ) + :OP4 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-4 (:PCLMULQDQ :AVX))))) + (INST "VPERM2I128" + (OP :OP #xF3A46 + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V QQ) + :OP2 '(H QQ) + :OP3 '(W QQ) + :OP4 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-6 (:AVX2))))) + (INST "VBLENDVPS" + (OP :OP #xF3A4A + :VEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(L X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VBLENDVPS" + (OP :OP #xF3A4A + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(L X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VBLENDVPD" + (OP :OP #xF3A4B + :VEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(L X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VBLENDVPD" + (OP :OP #xF3A4B + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(L X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPBLENDVB" + (OP :OP #xF3A4C + :VEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(L X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VPBLENDVB" + (OP :OP #xF3A4C + :VEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX2)) + (ARG :OP1 '(V X) + :OP2 '(H X) + :OP3 '(W X) + :OP4 '(L X)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX2))))) + (INST "VRANGEPD" + (OP :OP #xF3A50 + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VRANGEPD" + (OP :OP #xF3A50 + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VRANGEPD" + (OP :OP #xF3A50 + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VRANGEPS" + (OP :OP #xF3A50 + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VRANGEPS" + (OP :OP #xF3A50 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VRANGEPS" + (OP :OP #xF3A50 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VRANGESD" + (OP :OP #xF3A51 + :EVEX '(:0F3A :NDS :LIG :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512DQ))))) + (INST "VRANGESS" + (OP :OP #xF3A51 + :EVEX '(:0F3A :NDS :LIG :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512DQ))))) + (INST "VFIXUPIMMPD" + (OP :OP #xF3A54 + :EVEX '(:0F3A :NDS :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFIXUPIMMPD" + (OP :OP #xF3A54 + :EVEX '(:0F3A :NDS :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFIXUPIMMPD" + (OP :OP #xF3A54 + :EVEX '(:0F3A :NDS :512 :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFIXUPIMMPS" + (OP :OP #xF3A54 + :EVEX '(:0F3A :NDS :512 :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512F))))) + (INST "VFIXUPIMMPS" + (OP :OP #xF3A54 + :EVEX '(:0F3A :NDS :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFIXUPIMMPS" + (OP :OP #xF3A54 + :EVEX '(:0F3A :NDS :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512F))))) + (INST "VFIXUPIMMSD" + (OP :OP #xF3A55 + :EVEX '(:0F3A :NDS :LIG :66 :W1) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VFIXUPIMMSS" + (OP :OP #xF3A55 + :EVEX '(:0F3A :NDS :LIG :66 :W0) + :FEAT '(:AVX512F)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512F))))) + (INST "VREDUCEPD" + (OP :OP #xF3A56 + :EVEX '(:0F3A :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VREDUCEPD" + (OP :OP #xF3A56 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VREDUCEPD" + (OP :OP #xF3A56 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VREDUCEPS" + (OP :OP #xF3A56 + :EVEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VREDUCEPS" + (OP :OP #xF3A56 + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512VL :AVX512DQ))))) + (INST "VREDUCEPS" + (OP :OP #xF3A56 + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E2 (:AVX512DQ))))) + (INST "VREDUCESS" + (OP :OP #xF3A57 + :EVEX '(:0F3A :NDS :LIG :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512DQ))))) + (INST "VREDUCESD" + (OP :OP #xF3A57 + :EVEX '(:0F3A :NDS :LIG :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E3 (:AVX512DQ))))) + (INST "PCMPESTRM" + (OP :OP #xF3A60 + :PFX :66 + :FEAT '(:SSE4.2)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.2))))) + (INST "VPCMPESTRM" + (OP :OP #xF3A60 + :VEX '(:0F3A :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PCMPESTRI" + (OP :OP #xF3A61 + :PFX :66 + :FEAT '(:SSE4.2)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.2))))) + (INST "VPCMPESTRI" + (OP :OP #xF3A61 + :VEX '(:0F3A :128 :66) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PCMPISTRM" + (OP :OP #xF3A62 + :PFX :66 + :FEAT '(:SSE4.2)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.2))))) + (INST "VPCMPISTRM" + (OP :OP #xF3A62 + :VEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "PCMPISTRI" + (OP :OP #xF3A63 + :PFX :66 + :FEAT '(:SSE4.2)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SSE4.2))))) + (INST "VPCMPISTRI" + (OP :OP #xF3A63 + :VEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + NIL '((:EX (CHK-EXC :TYPE-4 (:AVX))))) + (INST "VFPCLASSPD" + (OP :OP #xF3A66 + :EVEX '(:0F3A :128 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VFPCLASSPD" + (OP :OP #xF3A66 + :EVEX '(:0F3A :256 :66 :W1) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VFPCLASSPD" + (OP :OP #xF3A66 + :EVEX '(:0F3A :512 :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "VFPCLASSPS" + (OP :OP #xF3A66 + :EVEX '(:0F3A :128 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VFPCLASSPS" + (OP :OP #xF3A66 + :EVEX '(:0F3A :256 :66 :W0) + :FEAT '(:AVX512VL :AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512VL :AVX512DQ))))) + (INST "VFPCLASSPS" + (OP :OP #xF3A66 + :EVEX '(:0F3A :512 :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E4 (:AVX512DQ))))) + (INST "VFPCLASSSD" + (OP :OP #xF3A67 + :EVEX '(:0F3A :LIG :66 :W1) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "VFPCLASSSS" + (OP :OP #xF3A67 + :EVEX '(:0F3A :LIG :66 :W0) + :FEAT '(:AVX512DQ)) + NIL NIL + '((:EX (CHK-EXC :TYPE-E6 (:AVX512DQ))))) + (INST "SHA1RNDS4" + (OP :OP #xF3ACC :FEAT '(:SHA)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:SHA))))) + (INST "AESKEYGENASSIST" + (OP :OP #xF3ADF + :PFX :66 + :FEAT '(:AES)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + 'NIL + '((:EX (CHK-EXC :TYPE-4 (:AES))))) + (INST "VAESKEYGENASSIST" + (OP :OP #xF3ADF + :VEX '(:0F3A :128 :66 :WIG) + :FEAT '(:AES :AVX)) + (ARG :OP1 '(V DQ) + :OP2 '(W DQ) + :OP3 '(I B)) + NIL + '((:EX (CHK-EXC :TYPE-4 (:AES :AVX))))) + (INST "RORX" + (OP :OP #xF3AF0 + :VEX '(:0F3A :LZ :F2 :W0) + :FEAT '(:BMI2)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(I B)) + '(X86-RORX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2))))) + (INST "RORX" + (OP :OP #xF3AF0 + :VEX '(:0F3A :LZ :F2 :W1) + :FEAT '(:BMI2)) + (ARG :OP1 '(G Y) + :OP2 '(E Y) + :OP3 '(I B)) + '(X86-RORX) + '((:EX (CHK-EXC :TYPE-13 (:BMI2))))))) + +;; ---------------------------------------------------------------------- + +(define eval-pre-map (x state) + :mode :program + (if (atom x) + (mv nil x state) + (b* (((mv ?erp val state) + (acl2::trans-eval + (car x) + 'eval-pre-map state t)) + ;; (car val) is stobjs-out. + ;; (- (cw "~%~p0~%" (inst-p (cdr val)))) + ((mv erp rest state) + (eval-pre-map (cdr x) state)) + (all (cons (cdr val) rest)) + (erp (or erp (if (inst-list-p all) nil t)))) + (mv erp all state)))) + +(make-event + (mv-let (one-byte-opcode-map + two-byte-opcode-map + 0F-38-three-byte-opcode-map + 0F-3A-three-byte-opcode-map + state) + (b* (((mv ?erp one-byte-map state) + (eval-pre-map *pre-one-byte-opcode-map* state)) + ((mv ?erp two-byte-map state) + (eval-pre-map *pre-two-byte-opcode-map* state)) + ((mv ?erp 0F-38-three-byte-map state) + (eval-pre-map *pre-0F-38-three-byte-opcode-map* state)) + ((mv ?erp 0F-3A-three-byte-map state) + (eval-pre-map *pre-0F-3A-three-byte-opcode-map* state))) + (mv one-byte-map two-byte-map + 0F-38-three-byte-map 0F-3A-three-byte-map + state)) + (mv nil + `(progn + (defconst *one-byte-opcode-map* ',one-byte-opcode-map) + (defconst *two-byte-opcode-map* ',two-byte-opcode-map) + (defconst *0F-38-three-byte-opcode-map* ',0F-38-three-byte-opcode-map) + (defconst *0F-3A-three-byte-opcode-map* ',0F-3A-three-byte-opcode-map)) + state))) + +(defthm inst-list-p-of-maps + (and (inst-list-p *one-byte-opcode-map*) + (inst-list-p *two-byte-opcode-map*) + (inst-list-p *0F-38-three-byte-opcode-map*) + (inst-list-p *0F-3A-three-byte-opcode-map*))) + + +(define select-opcode-map ((map-key keywordp)) + :parents (filtering-instructions) + :guard (member-equal + map-key + '(:one-byte + :two-byte + :0F-38-three-byte + :0F-3A-three-byte + :vex-0F :vex-0F-38 :vex-0F-3A + :evex-0F :evex-0F-38 :evex-0F-3A)) + :returns (inst-lst inst-list-p :hyp :guard) + (case map-key + (:one-byte *one-byte-opcode-map*) + ((:two-byte :vex-0F :evex-0F) *two-byte-opcode-map*) + ((:0F-38-three-byte :vex-0F-38 :evex-0F-38) *0F-38-three-byte-opcode-map*) + ((:0F-3A-three-byte :vex-0F-3A :evex-0F-3A) *0F-3A-three-byte-opcode-map*))) + +(defthm inst-p-implies-mnemonic-p-alt + (implies (and (inst-p x) + (not (stringp (inst->mnemonic x)))) + ;; (keywordp (inst->mnemonic x)) + (symbolp (inst->mnemonic x))) + :hints (("Goal" + :use ((:instance mnemonic-p-of-inst->mnemonic)) + :in-theory (e/d (mnemonic-p inst->mnemonic) + (mnemonic-p-of-inst->mnemonic))))) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-structs.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-structs.lisp new file mode 100644 index 000000000..305bab9ef --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/inst-structs.lisp @@ -0,0 +1,1150 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2018, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Rob Sumners + +(in-package "X86ISA") +(include-book "../utils/basic-structs") +(include-book "std/util/defenum" :dir :system) +(include-book "cpuid-constants") +(include-book "centaur/fty/deftypes" :dir :system) +(include-book "centaur/fty/baselists" :dir :system) +;(include-book "centaur/fty/top" :dir :system) +(include-book "std/lists/duplicity" :dir :system) +(include-book "std/strings/hexify" :dir :system) + +(defsection opcode-maps-structures + :parents (structures opcode-maps) + :short "Structures for representing Intel's x86 Opcode Maps in ACL2" + ) + +(local (xdoc::set-default-parents 'opcode-maps-structures)) + +;; ---------------------------------------------------------------------- + +;; Addressing Information: + +(defconst *Z-addressing-method-info* + + ;; See Intel Vol. 2, Appendix A.2.1 + ;; Also see AMD Vol. 3, Appendix A + + ;; The information in this constant definition comes not only from the + ;; aforementioned Appendices, but also from an examination of the involved + ;; instructions. However, the accuracy of this information has been so far + ;; confirmed only for the instructions covered by the current formal model; + ;; for unimplemented instructions, it is possible that the information may + ;; need to be changed. + + ;; (assoc :modr/m? (cdr (assoc 'A *Z-addressing-method-info*))) + + (list + + '(A (:modr/m? . nil) (:vex? . nil) + (:doc . + "Direct address: the instruction has no ModR/M byte; the address + of the operand is encoded in the instruction. No base register, + index register, or scaling factor can be applied (for example far + JMP (EA)).")) + + '(B (:modr/m? . nil) (:vex? . t) + (:doc . + "The VEX.vvvv field of the VEX prefix selects a general purpose + register.")) + + '(C (:modr/m? . t) (:vex? . nil) + (:doc . + "The reg field of the ModR/M byte selects a control register (for + example MOV (0F20, 0F22)).")) + + '(D (:modr/m? . t) (:vex? . nil) + (:doc . + "The reg field of the ModR/M byte selects a debug register (for + example MOV (0F21,0F23)).")) + + '(E (:modr/m? . t) (:vex? . nil) + (:doc . + "A ModR/M byte follows the opcode and specifies the operand. The + operand is either a general-purpose register or a memory + address. If it is a memory address the address is computed from a + segment register and any of the following values: a base register, + an index register, a scaling factor,a displacement.")) + + '(F (:modr/m? . nil) (:vex? . nil) + (:doc . + "EFLAGS/RFLAGS Register.")) + + '(G (:modr/m? . t) (:vex? . nil) + (:doc . + "The reg field of the ModR/M byte selects a general register (for + example AX (000)).")) + + '(H (:modr/m? . nil) (:vex? . t) + (:doc . + "The VEX.vvvv field of the VEX prefix selects a 128-bit XMM + register or a 256-bit YMM register determined by operand type. For + legacy SSE encodings this operand does not exist, changing the + instruction to destructive form.")) + + '(I (:modr/m? . nil) (:vex? . nil) + (:doc . + "Immediate data: the operand value is encoded in subsequent bytes + of the instruction.")) + + '(J (:modr/m? . nil) (:vex? . nil) + (:doc . + "The instruction contains a relative offset to be added to the + instruction pointer register (for example JMP (0E9), LOOP).")) + + ;; Important: Note that rB, mB are not listed as Z addressing methods in the + ;; Intel manuals (May 2018 edition). I borrowed them from the following: + ;; http://sandpile.org/x86/opc_enc.htm. + + '(rB (:modr/m? . t) (:vex? . nil) + (:doc . + "modr/m.reg is used to access bound registers (added as a part of + the Intel MPX Programming Environment).")) + + '(mB (:modr/m? . t) (:vex? . nil) + (:doc . + "modr/m.r/m is used to access bound registers (added as a part of + the Intel MPX Programming Environment).")) + + ;; Important: Addressing info with "K-" prefix below does not appear in the + ;; Intel Manuals (dated May, 2018). The Intel manuals do not define a Z + ;; addressing method for AVX512 instructions yet, so until they do, I am + ;; going to use my own encoding for specifying opmask registers. + + ;; Source: Section 2.7.3 (Opmask Register Encoding), specifically, Table + ;; 2-33 (Opmask Register Specifier Encoding), Intel Vol. 2 (Jun 2024) + + '(K-reg (:modr/m? . t) (:vex? . nil) + (:doc . + "modr/m.reg is used to access opmask registers k0-k7 (common + usages: source). ")) + + '(K-vex (:modr/m? . nil) (:vex? . t) + (:doc . + "VEX.vvvv is used to access opmask registers k0-k7 (common + usages: 2nd source).")) + + '(K-r/m (:modr/m? . t) (:vex? . nil) + (:doc . + "modr/m.r/m is used to access opmask registers k0-k7 (common + usages: 1st source).")) + + '(K-evex (:modr/m? . nil) (:vex? . nil) (:evex? . t) + (:doc . + "EVEX.aaa is used to access opmask registers k0-k4 (common + usages: Opmask).")) + + '(L (:modr/m? . nil) (:vex? . t) + (:doc . + "The upper 4 bits of the 8-bit immediate selects a 128-bit XMM + register or a 256-bit YMM register determined by operand + type. (the MSB is ignored in 32-bit mode)")) + + '(M (:modr/m? . t) (:vex? . nil) + (:doc . + "The ModR/M byte may refer only to memory (for example BOUND, LES, + LDS, LSS, LFS, LGS, CMPXCHG8B).")) + + '(N (:modr/m? . t) (:vex? . nil) + (:doc . + "The R/M field of the ModR/M byte selects a packed-quadword MMX + technology register.")) + + '(O (:modr/m? . nil) (:vex? . nil) + (:doc . + "The instruction has no ModR/M byte. The offset of the operand is + coded as a word or double word (depending on address size + attribute) in the instruction. No base register index register or + scaling factor can be applied (for example MOV (A0-A3)).")) + + '(P (:modr/m? . t) (:vex? . nil) + (:doc . + "The reg field of the ModR/M byte selects a packed quadword MMX + technology register.")) + + '(Q (:modr/m? . t) (:vex? . nil) + (:doc . + "A ModR/M byte follows the opcode and specifies the operand. The + operand is either an MMX technology register or a memory + address. If it is a memory address the address is computed from a + segment register and any of the following values: a base register, + an index register, a scaling factor, and a displacement.")) + + '(R (:modr/m? . t) (:vex? . nil) + (:doc . + "The R/M field of the ModR/M byte may refer only to a general + register (for example MOV (0F20-0F23)).")) + + '(S (:modr/m? . t) (:vex? . nil) + (:doc . + "The reg field of the ModR/M byte selects a segment register (for + example MOV (8C,8E)).")) + + '(U (:modr/m? . t) (:vex? . t) + (:doc . + "The R/M field of the ModR/M byte selects a 128-bit XMM register + or a 256-bit YMM register determined by operand type.")) + + '(V (:modr/m? . t) (:vex? . t) + (:doc . + "The reg field of the ModR/M byte selects a 128-bit XMM register + or a 256-bit YMM register determined by operand type.")) + + '(W (:modr/m? . t) (:vex? . t) + (:doc . + "A ModR/M byte follows the opcode and specifies the operand. The + operand is either a 128-bit XMM register, a 256-bit YMM + register (determined by operand type), or a memory address. If it + is a memory address the address is computed from a segment + register and any of the following values: a base register, an + index register, a scaling factor,and a displacement.")) + + '(X (:modr/m? . nil) (:vex? . nil) + (:doc . + "Memory addressed by the DS:rSI register pair (for example MOVS, + CMPS, OUTS, or LODS).")) + + '(Y (:modr/m? . nil) (:vex? . nil) + (:doc . + "Memory addressed by the ES:rDI register pair (for example MOVS, + CMPS, INS, STOS, or SCAS).")))) + +(make-event + `(defenum addressing-method-code-p + ,(strip-cars *Z-addressing-method-info*) + :parents (opcode-maps) + :short "Codes for Operand Addressing Method; See Intel Vol. 2, + Appendix A.2.1")) + +(defconst *operand-type-code-info* + + ;; See Intel Vol. 2, A.2.2 Codes for Operand Types + ;; The following abbreviations are used to document operand types: + + (list + + + '(a + (:doc . "Two one-word operands in memory or two double-word operands in + memory,depending on operand-size attribute (used only by the BOUND + instruction).")) + + '(b + (:doc . "Byte, regardless of operand-size attribute.")) + + '(c + (:doc . "Byte or word, depending on operand-size attribute.")) + + '(d + (:doc . "Doubleword, regardless of operand-size attribute.")) + + '(dq + (:doc . "Double-quadword, regardless of operand-size attribute.")) + + '(p + (:doc . "32-bit, 48-bit, or 80-bit pointer, depending on operand-size + attribute.")) + + '(pd + (:doc . "128-bit or 256-bit packed double-precision floating-point data.")) + + '(pi + (:doc . "Quadword MMX technology register (for example: mm0).")) + + '(ps + (:doc . "128-bit or 256-bit packed single-precision floating-point data.")) + + '(q + (:doc . "Quadword, regardless of operand-size attribute.")) + + '(qq + (:doc . "Quad-Quadword (256-bits), regardless of operand-size attribute.")) + + '(s + (:doc . "6-byte or 10-byte pseudo-descriptor.")) + + '(sd + (:doc . "Scalar element of a 128-bit double-precision floating data.")) + + '(ss + (:doc . "Scalar element of a 128-bit single-precision floating data.")) + + '(si + (:doc . "Doubleword integer register (for example: eax).")) + + '(v + (:doc . "Word, doubleword or quadword (in 64-bit mode), depending on + operand-size attribute.")) + + '(w + (:doc . "Word, regardless of operand-size attribute.")) + + '(x + (:doc . "dq or qq based on the operand-size attribute.")) + + '(y + (:doc . "Doubleword or quadword (in 64-bit mode), depending on + operand-size attribute.")) + + '(z + (:doc . "Word for 16-bit operand-size or doubleword for 32 or 64-bit + operand-size.")))) + +(make-event + `(defenum operand-type-code-p + ,(strip-cars *operand-type-code-info*) + :parents (opcode-maps) + :short "Codes for Operand Type; See Intel Vol. 2, Appendix A.2.2")) + +(defconst *opcode-map-superscripts* + + ;; Source: Intel Manuals, Volume 2, Appendix A.2.5. + ;; Table A-1. Superscripts Utilized in Opcode Tables. + + (list + + ;; Bits 5, 4, and 3 of ModR/M byte used as an opcode extension + ;; (refer to Section A.4, Opcode Extensions For One-Byte And + ;; Two-byte Opcodes) + :1a + + ;; Use the 0F0B opcode (UD2 instruction) or the 0FB9H opcode when + ;; deliberately trying to generate an invalid opcode exception + ;; (#UD). + :1b + + ;; Some instructions use the same two-byte opcode. If the + ;; instruction has variations, or the opcode represents different + ;; instructions, the ModR/M byte will be used to differentiate the + ;; instruction. For the value of the ModR/M byte needed to decode + ;; the instruction, see Table A-6. + :1c + + ;; The instruction is invalid or not encodable in 64-bit mode. 40 + ;; through 4F (single-byte INC and DEC) are REX prefix combinations + ;; when in 64-bit mode (use FE/FF Grp 4 and 5 for INC and DEC). + :i64 + + ;; Instruction is only available when in 64-bit mode. + :o64 + + ;; When in 64-bit mode, instruction defaults to 64-bit operand size + ;; and cannot encode 32-bit operand size. + :d64 + + ;; The operand size is forced to a 64-bit operand size when in + ;; 64-bit mode (prefixes that change operand size are ignored for + ;; this instruction in 64-bit mode). + :f64 + + ;; VEX form only exists. There is no legacy SSE form of the + ;; instruction. For Integer GPR instructions it means VEX prefix + ;; required. + :v + + ;; VEX128 & SSE forms only exist (no VEX256), when can't be + ;; inferred from the data size. + :v1 + )) + +(defconst *group-numbers* + '(:group-1 :group-1a + :group-2 :group-3 + :group-4 :group-5 + :group-6 :group-7 + :group-8 :group-9 + :group-10 :group-11 + :group-12 :group-13 + :group-14 :group-15 + :group-16 :group-17)) + +;; ---------------------------------------------------------------------- + +;; Data structures to represent the opcode maps: + +(define op-pfx-p (x) + (or (not x) + (member-equal x '(:NO-PREFIX :66 :F3 :F2 + :v :v66 :vF3 :vF2 + :ev :ev66 :evF3 :evF2))) + + /// + + (define op-pfx-fix ((x op-pfx-p)) + :enabled t + (mbe :logic (if (op-pfx-p x) x 'nil) + :exec x)) + + (fty::deffixtype op-pfx + :pred op-pfx-p + :fix op-pfx-fix + :equiv op-pfx-equiv + :define t)) + +(define op-mode-p (x) + (or (not x) + (member-equal x '(:o64 :i64))) + + /// + + (define op-mode-fix ((x op-mode-p)) + :enabled t + (mbe :logic (if (op-mode-p x) x 'nil) + :exec x)) + + (fty::deffixtype op-mode + :pred op-mode-p + :fix op-mode-fix + :equiv op-mode-equiv + :define t)) + +(define rex-p (x) + (or (not x) + (member-equal x '(:w :not-w))) + /// + (define rex-fix ((x rex-p)) + :enabled t + (mbe :logic (if (rex-p x) x 'nil) + :exec x)) + + (fty::deffixtype rex + :pred rex-p + :fix rex-fix + :equiv rex-equiv + :define t)) + +(define mod-p (x) + (or (not x) + (eq x :mem) ;; mod != #b11 + (2bits-p x)) + /// + (define mod-fix ((x mod-p)) + :enabled t + (mbe :logic (if (mod-p x) x 'nil) + :exec x)) + + (fty::deffixtype mod + :pred mod-p + :fix mod-fix + :equiv mod-equiv + :define t)) + +(define maybe-3bits-p (x) + (or (not x) (3bits-p x)) + /// + (define maybe-3bits-fix ((x maybe-3bits-p)) + :enabled t + (mbe :logic (if (maybe-3bits-p x) x 'nil) + :exec x)) + + (fty::deffixtype maybe-3bits + :pred maybe-3bits-p + :fix maybe-3bits-fix + :equiv maybe-3bits-equiv + :define t)) + +;; I could've defined vex and evex using defprod too, but I don't want the +;; order of the vex/evex prefix cases to matter (so the defprod constructor is +;; out). Nor do I want to use keywords like :vvvv to specify the classes of +;; the prefixes --- this'll reduce the amount of text one has to read/type +;; (thus, the make-* macro is out too). So the following approach of defining +;; a recognizer for the vex/evex prefix cases serves me well. + +(defconst *vvvv-pfx* + '(:NDS :NDD :DDS ;; UNUSED-VVVV + )) + +(defconst *l-pfx* + '(:128 :256 :L0 :L1 :LIG :LZ)) + +(defconst *pp-pfx* + '(:66 :F2 :F3 ;; NP + )) + +(defconst *mm-pfx* + '(:0F :0F38 :0F3A)) + +(defconst *w-pfx* + '(:W0 :W1 :WIG)) + +(defconst *vex-pfx-cases* + ;; See Intel Manual, Vol. 2A, Sec. 3.1.1.2 (Opcode Column in the Instruction + ;; Summary Table (Instructions with VEX Prefix)) + ;; VEX: + ;; [NDS|NDD|DDS].[128|256|LIG|LZ].[66|F2|F3].[0F|0F38|0F3A].[W0|W1|WIG] + (append *vvvv-pfx* *l-pfx* *pp-pfx* *mm-pfx* *w-pfx*)) + +(defconst *evex-pfx-cases* + ;; See Intel Manual, Vol. 2A, Sec. 3.1.1.2 (Opcode Column in the Instruction + ;; Summary Table (Instructions with VEX Prefix)) + ;; EVEX: + ;; [NDS|NDD|DDS].[128|256|512|LIG|LZ].[66|F2|F3].[0F|0F38|0F3A].[W0|W1|WIG] + (append *vvvv-pfx* + (cons :512 *l-pfx*) + *pp-pfx* *mm-pfx* *w-pfx*)) + +(define count-avx-pfx-cases ((lst true-listp) + (alst alistp) + (vex? booleanp)) + :prepwork + ((local + (defthm alistp-put-assoc-equal + (implies (alistp alst) + (alistp (put-assoc-equal k v alst)))))) + + :returns (count-alst alistp :hyp (and (alistp alst) + (true-listp lst))) + (if (endp lst) + alst + (b* ((e (car lst)) + ;; No duplicates in lst. + (rest (cdr lst))) + (cond ((member e *vvvv-pfx*) + (b* ((vvvv (nfix (cdr (assoc-equal :vvvv alst)))) + (alst (put-assoc :vvvv (1+ vvvv) alst))) + (count-avx-pfx-cases rest alst vex?))) + ((member e (if vex? *l-pfx* (cons :512 *l-pfx*))) + (b* ((l (nfix (cdr (assoc-equal :l alst)))) + (alst (put-assoc :l (1+ l) alst))) + (count-avx-pfx-cases rest alst vex?))) + ((member e *pp-pfx*) + (b* ((pp (nfix (cdr (assoc-equal :pp alst)))) + (alst (put-assoc :pp (1+ pp) alst))) + (count-avx-pfx-cases rest alst vex?))) + ((member e *mm-pfx*) + (b* ((mm (nfix (cdr (assoc-equal :mm alst)))) + (alst (put-assoc :mm (1+ mm) alst))) + (count-avx-pfx-cases rest alst vex?))) + ((member e *w-pfx*) + (b* ((w (nfix (cdr (assoc-equal :w alst)))) + (alst (put-assoc :w (1+ w) alst))) + (count-avx-pfx-cases rest alst vex?))))))) + +(define avx-pfx-well-formed-p ((lst true-listp) + (vex? booleanp)) + (b* ((count-alst (count-avx-pfx-cases lst nil vex?)) + (vvvv (if (consp (assoc-equal :vvvv count-alst)) + (cdr (assoc-equal :vvvv count-alst)) + 0)) + ((unless (and (natp vvvv) (<= vvvv 1))) + (cw "Duplicates encountered in VVVV! Lst: ~p0~%" lst)) + (l (if (consp (assoc-equal :l count-alst)) + (cdr (assoc-equal :l count-alst)) + 0)) + ((unless (and (natp L) (<= L 1))) + (cw "Duplicates encountered in L! Lst: ~p0~%" lst)) + (pp (if (consp (assoc-equal :pp count-alst)) + (cdr (assoc-equal :pp count-alst)) + 0)) + ((unless (and (natp pp) (<= pp 1))) + (cw "Duplicates encountered in PP! Lst: ~p0~%" lst)) + (mm (if (consp (assoc-equal :mm count-alst)) + (cdr (assoc-equal :mm count-alst)) + 0)) + ((unless (equal mm 1)) + (cw "MM not equal to 1! Lst: ~p0~%" lst)) + (w (if (consp (assoc-equal :w count-alst)) + (cdr (assoc-equal :w count-alst)) + 0)) + ((unless (and (natp w) (<= w 1))) + (cw "Duplicates encountered in W! Lst: ~p0~%" lst))) + t)) + +(define vex-p (x) + (and (true-listp x) + (subsetp-equal x *vex-pfx-cases*) + (no-duplicatesp-equal x) + (avx-pfx-well-formed-p x t))) + +(define maybe-vex-p (x) + (or (not x) (vex-p x)) + /// + (define maybe-vex-fix ((x maybe-vex-p)) + :enabled t + (mbe :logic (if (maybe-vex-p x) x 'nil) + :exec x)) + + (fty::deffixtype maybe-vex + :pred maybe-vex-p + :fix maybe-vex-fix + :equiv maybe-vex-equiv + :define t)) + +(define evex-p (x) + (and (true-listp x) + (subsetp-equal x *evex-pfx-cases*) + (no-duplicatesp-equal x) + (avx-pfx-well-formed-p x nil))) + +(define maybe-evex-p (x) + (or (not x) (evex-p x)) + /// + (define maybe-evex-fix ((x maybe-evex-p)) + :enabled t + (mbe :logic (if (maybe-evex-p x) x 'nil) + :exec x)) + + (fty::deffixtype maybe-evex + :pred maybe-evex-p + :fix maybe-evex-fix + :equiv maybe-evex-equiv + :define t)) + +(define superscripts-p (x) + (or (not x) + (and (acl2::keyword-listp x) + (subsetp-equal x *opcode-map-superscripts*))) + /// + (define superscripts-fix ((x superscripts-p)) + :enabled t + (mbe :logic (if (superscripts-p x) x 'nil) + :exec x)) + + (fty::deffixtype superscripts + :pred superscripts-p + :fix superscripts-fix + :equiv superscripts-equiv + :define t)) + +(define opcode-extension-group-p (x) + (or (not x) + (and (acl2::keyword-listp x) + (subsetp-equal x *group-numbers*))) + /// + (define opcode-extension-group-fix ((x opcode-extension-group-p)) + :enabled t + (mbe :logic (if (opcode-extension-group-p x) x 'nil) + :exec x)) + + (fty::deffixtype opcode-extension-group + :pred opcode-extension-group-p + :fix opcode-extension-group-fix + :equiv opcode-extension-group-equiv + :define t)) + +(defprod opcode + ((op 24bits-p + "Includes escape bytes of two- and three-byte opcodes as + well" + :default '0) + (mode op-mode-p + :default 'nil) + (reg maybe-3bits-p + "ModR/M.reg descriptor" + :default 'nil) + (mod mod-p + "ModR/M.mod descriptor" + :default 'nil) + (r/m maybe-3bits-p + "ModR/M.r/m descriptor" + :default 'nil) + (pfx op-pfx-p + :default 'nil) + (rex rex-p "REX descriptor" + :default 'nil) + (vex maybe-vex-p + :default 'nil) + (evex maybe-evex-p + :default 'nil) + (feat symbol-listp + :default 'nil) + (superscripts superscripts-p + :default 'nil) + (group opcode-extension-group-p + :default 'nil)) + :layout :tree) + +(defmacro op (&rest args) + `(make-opcode ,@args)) + +(define keyword-list-fix ((x acl2::keyword-listp)) + :enabled t + (mbe :logic (if (acl2::keyword-listp x) x 'nil) + :exec x)) + +(fty::deffixtype keyword-list + :pred acl2::keyword-listp + :fix keyword-list-fix + :equiv keyword-list-equiv + :define t) + +(defprod Op/En-p + ((src1 acl2::keyword-listp) + (src2 acl2::keyword-listp) + (src3 acl2::keyword-listp) + (src4 acl2::keyword-listp))) + +(define operand-type-p (x) + (or (not x) + ;; The opcode maps present in Intel's manuals are incomplete. Notably, + ;; the EVEX-encoded instructions are absent from it. In such cases, we + ;; can describe the operands using the Op/En column present in the + ;; instruction description pages --- this info. can be put in a keyword + ;; list. E.g.: + ;; EVEX.LIG.F2.0F.W1 10 /r VMOVSD xmm1 {k1}{z}, xmm2, xmm3 + ;; Operand 1: ModRM:reg (w) + ;; Operand 2: VEX.vvvv (r) + ;; Operand 3: ModRM:r/m (r) + ;; We can describe these operands as follows (respectively): + ;; '(:ModRM.reg :XMM) + ;; '(:VEX.vvvv :XMM) + ;; '(:ModRM.r/m :XMM) + ;; Suppose YMM registers were also allowed. Then one could say the + ;; following: + ;; '(:ModRM.reg :XMM :YMM) + (acl2::keyword-listp x) + (and (true-listp x) + (if (equal (len x) 1) + (or (acl2-numberp (nth 0 x)) + (addressing-method-code-p (nth 0 x))) + (if (equal (len x) 2) + (and + (addressing-method-code-p (nth 0 x)) + (operand-type-code-p (nth 1 x))) + nil)))) + /// + (define operand-type-fix ((x operand-type-p)) + :enabled t + (mbe :logic (if (operand-type-p x) x 'nil) + :exec x)) + + (fty::deffixtype operand-type + :pred operand-type-p + :fix operand-type-fix + :equiv operand-type-equiv + :define t)) + +(defprod operands + ((op1 operand-type-p :default 'nil) + (op2 operand-type-p :default 'nil) + (op3 operand-type-p :default 'nil) + (op4 operand-type-p :default 'nil)) + :layout :tree) + +(defmacro arg (&rest args) + `(make-operands ,@args)) + +(define maybe-operands-p (x) + (or (not x) (operands-p x)) + /// + (define maybe-operands-fix ((x maybe-operands-p)) + :enabled t + (mbe :logic (if (maybe-operands-p x) x 'nil) + :exec x)) + + (fty::deffixtype maybe-operands + :pred maybe-operands-p + :fix maybe-operands-fix + :equiv maybe-operands-equiv + :define t)) + +(define exception-desc-p (x) + (and (alistp x) + (subsetp-equal (strip-cars x) + '(:ex :ud :gp :nm))) + + /// + + (define exception-desc-fix ((x exception-desc-p)) + :enabled t + (mbe :logic (if (exception-desc-p x) x 'nil) + :exec x)) + + (fty::deffixtype exception-desc + :pred exception-desc-p + :fix exception-desc-fix + :equiv exception-desc-equiv + :define t)) + +(define fn-desc-p (x) + (or (null x) + (and (true-listp x) + (symbolp (car x)) + (eqlable-alistp (cdr x)))) + + /// + + (define fn-desc-fix ((x fn-desc-p)) + :enabled t + (mbe :logic (if (fn-desc-p x) x 'nil) + :exec x)) + + (fty::deffixtype fn-desc + :pred fn-desc-p + :fix fn-desc-fix + :equiv fn-desc-equiv + :define t)) + +(define mnemonic-p (x) + (or (stringp x) + (keywordp x)) + /// + + (define mnemonic-fix ((x mnemonic-p)) + :enabled t + (mbe :logic (if (mnemonic-p x) x ':NONE) + :exec x)) + + (defthm mnemonic-p-of-mnemonic-fix + (mnemonic-p (mnemonic-fix x))) + + (fty::deffixtype mnemonic + :pred mnemonic-p + :fix mnemonic-fix + :equiv mnemonic-equiv + :define t)) + +(define any-present-in ((xs true-listp) + (ys true-listp)) + :short "Is any element of @('xs') present in @('ys')?" + (if (endp xs) + nil + (if (member-equal (car xs) ys) + t + (any-present-in (cdr xs) ys)))) + +(define strict-opcode-p (x) + (and (opcode-p x) + (b* (((opcode x)) + ((when (and + (any-present-in + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*) + x.feat) + (null x.vex) + (null x.evex))) + nil)) + t)) + /// + (define strict-opcode-fix ((x strict-opcode-p)) + :enabled t + (if (strict-opcode-p x) + x + ;; Wiping out :feat --- doesn't really matter what I put here. + (b* ((x (opcode-fix x)) + (x (change-opcode x :feat nil))) + x))) + + (defthm strict-opcode-p-of-strict-opcode-fix + (strict-opcode-p (strict-opcode-fix x))) + + (fty::deffixtype strict-opcode + :pred strict-opcode-p + :fix strict-opcode-fix + :equiv strict-opcode-equiv + :define t)) + +(defprod inst + ((mnemonic mnemonic-p) + (opcode strict-opcode-p + "Opcode descriptor.") + (operands maybe-operands-p + "Description of operands; can be left empty if there are zero + operands." + :default 'nil) + (fn fn-desc-p + "Partial call of the semantic function that implements this + opcode." + :default 'nil) + (excep exception-desc-p + "Conditions for detecting certain decode-time exceptions; can + be left empty if there are no conditions to detect." + :default 'nil)) + :layout :tree) + +(define inst-list-p (xs) + :enabled t + (if (atom xs) + (equal xs nil) + (and (or (inst-p (car xs)) + (cw "~% inst-list-p: problem in: ~p0~% Appears before: ~p1~%" + (car xs) (if (consp (cdr xs)) (cdr xs) nil))) + (inst-list-p (cdr xs))))) + +;; ---------------------------------------------------------------------- + +;; Some useful lemmas: + +(local + (defthm operands-p-when-maybe-operands-p + (implies (and (maybe-operands-p x) x) + (operands-p x)) + :hints (("Goal" :in-theory (e/d (maybe-operands-p) ()))))) + +(defthm operands-p-of-inst->operands + (implies (and (inst-p x) + (inst->operands x)) + (operands-p (inst->operands x))) + :hints (("Goal" :in-theory (e/d (maybe-operands-p inst-p) ())))) + +(defthm operand-type-p-implies-true-listp + (implies (operand-type-p x) + (true-listp x)) + :hints (("Goal" :in-theory (e/d (operand-type-p) ()))) + :rule-classes :forward-chaining) + +(defthm inst-p-implies-operand-type-p-op1 + (implies + (inst-p inst) + (operand-type-p (operands->op1 (inst->operands inst)))) + :hints (("Goal" :in-theory (e/d (inst-p operands-p) ()))) + :rule-classes :forward-chaining) + +(defthm inst-p-implies-operand-type-p-op2 + (implies + (inst-p inst) + (operand-type-p (operands->op2 (inst->operands inst)))) + :hints (("Goal" :in-theory (e/d (inst-p operands-p) ()))) + :rule-classes :forward-chaining) + +(defthm inst-p-implies-operand-type-p-op3 + (implies + (inst-p inst) + (operand-type-p (operands->op3 (inst->operands inst)))) + :hints (("Goal" :in-theory (e/d (inst-p operands-p) ()))) + :rule-classes :forward-chaining) + +(defthm inst-p-implies-operand-type-p-op4 + (implies + (inst-p inst) + (operand-type-p (operands->op4 (inst->operands inst)))) + :hints (("Goal" :in-theory (e/d (inst-p operands-p) ()))) + :rule-classes :forward-chaining) + +(defthm strict-opcode-p-implies-opcode-p + (implies (strict-opcode-p x) + (opcode-p x)) + :hints (("Goal" :in-theory (e/d (strict-opcode-p) ())))) + +(defthm inst-p-implies-opcode-p + (implies (inst-p x) + (opcode-p (inst->opcode x))) + :hints (("Goal" :in-theory (e/d (inst-p) ())))) + +(defthm superscripts-p-implies-true-listp + (implies (superscripts-p x) + (true-listp x)) + :hints (("Goal" :in-theory (e/d (superscripts-p) ()))) + :rule-classes :forward-chaining) + +(defthm vex-p-implies-true-listp + (implies (vex-p x) + (true-listp x)) + :hints (("Goal" :in-theory (e/d (vex-p) ()))) + :rule-classes :forward-chaining) + +(defthm evex-p-implies-true-listp + (implies (evex-p x) + (true-listp x)) + :hints (("Goal" :in-theory (e/d (evex-p) ()))) + :rule-classes :forward-chaining) + +(defthm maybe-vex-p-implies-true-listp + (implies (maybe-vex-p x) + (true-listp x)) + :hints (("Goal" :in-theory (e/d (maybe-vex-p) ()))) + :rule-classes :forward-chaining) + +(defthm maybe-evex-p-implies-true-listp + (implies (maybe-evex-p x) + (true-listp x)) + :hints (("Goal" :in-theory (e/d (maybe-evex-p) ()))) + :rule-classes :forward-chaining) + +(local + (defthm subsetp-equal-and-keyword-listp + (implies (and (subsetp-equal x y) + (acl2::keyword-listp y) + (true-listp x)) + (acl2::keyword-listp x)) + :hints (("Goal" :in-theory (e/d (subsetp-equal + acl2::keyword-listp) + ()))))) + +(defthm maybe-vex-p-implies-keyword-listp + (implies (maybe-vex-p x) + (acl2::keyword-listp x)) + :hints (("Goal" :in-theory (e/d (maybe-vex-p vex-p) ()))) + :rule-classes :forward-chaining) + +(defthm maybe-evex-p-implies-keyword-listp + (implies (maybe-evex-p x) + (acl2::keyword-listp x)) + :hints (("Goal" :in-theory (e/d (maybe-evex-p evex-p) ()))) + :rule-classes :forward-chaining) + +;; ---------------------------------------------------------------------- + +(defsection filtering-instructions + :parents (opcode-maps) + :short "Some Functions to operate on the ACL2 representation of Intel's Opcode + Maps" + ) + +(local (xdoc::set-default-parents 'filtering-instructions)) + +;; Right now, we can't select AVX instructions using the function +;; select-insts. The reason is that VEX/EVEX-encoded instructions (but probably +;; just EVEX-encoded --- I'm being extra cautious here) may be missing +;; operands' information (i.e., their :vex or :evex fields may be empty) +;; because Intel manuals are missing that information. So selecting an +;; instruction based on the presence or absence of the :vex or :evex fields +;; would result in false matches. However, all AVX instructions (I believe) +;; have proper CPUID feature flags. Thus, for now, we can do selection of AVX +;; instructions using the functions remove-insts-with-feat and +;; keep-insts-with-feat below. + +;; I've tried to store all CPUID feature flag information in the :feat field of +;; the opcode, but there are a few cases where that information is in the +;; :excep field of inst instead (just three at this count: SAHF, LAHF, and +;; XSAVEOPT). The reason they're separate is that in these cases, the absence +;; of one feature flag by itself is not enough to cause a #UD --- either we +;; need at least one flag to be present (and the dispatch functions check +;; whether ALL the flags are present in :FEAT) or the #UD also depends on the +;; mode of operation of the processor. Search for FEATURE-FLAG-MACRO in the +;; inst-listings to see those cases. + +(define remove-insts-with-feat ((inst-lst inst-list-p) + (feat acl2::keyword-listp)) + :short "Remove all instructions from @('inst-lst') that have ANY feature + present in @('feat')" + ;; TODO: Replace with select-insts, with :vex and :evex set to t and :get/rem + ;; set to :rem once we have operands' spec. for EVEX instructions. + :returns (new-inst-lst inst-list-p + :hyp (inst-list-p inst-lst)) + (if (endp inst-lst) + nil + (b* ((inst (car inst-lst)) + (rest (remove-insts-with-feat (cdr inst-lst) feat)) + ((inst inst)) + (opcode inst.opcode) + ((opcode opcode)) + ((when (any-present-in feat opcode.feat)) rest)) + (cons inst rest)))) + +(define keep-insts-with-feat ((inst-lst inst-list-p) + (feat acl2::keyword-listp)) + :short "Keep all instructions from @('inst-lst') that have ANY feature + present in @('feat')" + ;; TODO: Replace with select-insts, with :vex and :evex set to t and :get/rem + ;; set to :get once we have operands' spec. for EVEX instructions. + :returns (new-inst-lst inst-list-p + :hyp (inst-list-p inst-lst)) + + (if (endp inst-lst) + nil + (b* ((inst (car inst-lst)) + (rest (keep-insts-with-feat (cdr inst-lst) feat)) + ((inst inst)) + (opcode inst.opcode) + ((opcode opcode)) + ((when (any-present-in feat opcode.feat)) (cons inst rest))) + rest))) + +(define select-insts ((inst-lst inst-list-p) + &key + ((get/rem (member-equal get/rem '(:get :rem)) + "Either get or remove the selected instructions") + ':get) + ((opcode (or (eql opcode nil) (24bits-p opcode)) + "If specified, select all instructions with the + same opcode") + 'nil) + ((mode op-mode-p + "If specified, select all instructions with the + same mode of operation") + 'nil) + ((prefix op-pfx-p + "If specified, select all instructions with the + same prefix") + 'nil) + ((vex? booleanp + "If @('t'), select all instructions with a non-nil + @('opcode.vex') field") + 'nil) + ((fn? booleanp + "If @('t'), select all instructions with a non-nil + @('inst.fn') field") + 'nil)) + + :short "Select instructions satisfying some conditions, and then either + remove the selection or keep only the selection" + + :returns (new-inst-lst inst-list-p + :hyp (inst-list-p inst-lst)) + + (b* (((when (endp inst-lst)) nil) + (rest (select-insts (cdr inst-lst) + ;; Remember to add key/vals here too if you expand + ;; the formals! + :get/rem get/rem + :opcode opcode + :mode mode + :prefix prefix + :vex? vex? + :fn? fn?)) + (inst (car inst-lst)) + ((inst inst)) + ((opcode inst.opcode)) + (match? (and (if (not opcode) + t + (equal opcode inst.opcode.op)) + (if (not mode) + t + (equal mode inst.opcode.mode)) + (if (not prefix) + t + (if (equal prefix :no-prefix) + (or (equal prefix inst.opcode.pfx) + (not inst.opcode.pfx)) + (equal prefix inst.opcode.pfx))) + (if (not vex?) + t + (if inst.opcode.vex t nil)) + (if (not fn?) + t + (if inst.fn t nil))))) + (if (eql get/rem :get) + (append (and match? (list inst)) rest) + (append (if match? nil (list inst)) rest)))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/add-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/add-spec.lisp new file mode 100644 index 000000000..5e5dfd66a --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/add-spec.lisp @@ -0,0 +1,486 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +;; This book contains the specification of the following instructions: +;; add adc + +(include-book "structures" :dir :utils) +(include-book "../rflags-spec") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; SPECIFICATION: ADD +;; ====================================================================== + +(define gpr-add-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-ADD-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (ntoi (mk-name "N" str-nbits "-TO-I" str-nbits)) + (cf-spec-fn (mk-name "CF-SPEC" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (af-spec-fn (mk-name "ADD-AF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits)) + (of-spec-fn (mk-name "OF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + (raw-result (the (unsigned-byte ,(1+ result-nbits)) + (+ (the (unsigned-byte ,result-nbits) dst) + (the (unsigned-byte ,result-nbits) src)))) + (signed-raw-result + (the (signed-byte ,(1+ result-nbits)) + (+ (the (signed-byte ,result-nbits) + (,ntoi dst)) + (the (signed-byte ,result-nbits) + (,ntoi src))))) + + (result (the (unsigned-byte ,result-nbits) + (n-size ,result-nbits raw-result))) + + (cf (the (unsigned-byte 1) (,cf-spec-fn raw-result))) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + (af (the (unsigned-byte 1) (,af-spec-fn dst src))) + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of (the (unsigned-byte 1) (,of-spec-fn signed-raw-result))) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :af af + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->af + af + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags))))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + ;; No undefined flags. + (undefined-flags 0)) + + (mv result output-rflags undefined-flags)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-add-spec-gen-fn 1)) +(make-event (gpr-add-spec-gen-fn 2)) +(make-event (gpr-add-spec-gen-fn 4)) +(make-event (gpr-add-spec-gen-fn 8)) + +(define gpr-xadd-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-XADD-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (ntoi (mk-name "N" str-nbits "-TO-I" str-nbits)) + (cf-spec-fn (mk-name "CF-SPEC" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (af-spec-fn (mk-name "ADD-AF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits)) + (of-spec-fn (mk-name "OF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + (raw-result (the (unsigned-byte ,(1+ result-nbits)) + (+ (the (unsigned-byte ,result-nbits) dst) + (the (unsigned-byte ,result-nbits) src)))) + (signed-raw-result + (the (signed-byte ,(1+ result-nbits)) + (+ (the (signed-byte ,result-nbits) + (,ntoi dst)) + (the (signed-byte ,result-nbits) + (,ntoi src))))) + + (result (the (unsigned-byte ,result-nbits) + (n-size ,result-nbits raw-result))) + + (cf (the (unsigned-byte 1) (,cf-spec-fn raw-result))) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + (af (the (unsigned-byte 1) (,af-spec-fn dst src))) + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of (the (unsigned-byte 1) (,of-spec-fn signed-raw-result))) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :af af + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->af + af + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags))))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + ;; No undefined flags. + (undefined-flags 0)) + + (mv result output-rflags undefined-flags)) + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-xadd-spec-gen-fn 1)) +(make-event (gpr-xadd-spec-gen-fn 2)) +(make-event (gpr-xadd-spec-gen-fn 4)) +(make-event (gpr-xadd-spec-gen-fn 8)) + +;; ====================================================================== +;; SPECIFICATION: ADC +;; ====================================================================== + +(define gpr-adc-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-ADC-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (ntoi (mk-name "N" str-nbits "-TO-I" str-nbits)) + (cf-spec-fn (mk-name "CF-SPEC" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (af-spec-fn (mk-name "ADC-AF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits)) + (of-spec-fn (mk-name "OF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + :inline t + :no-function t + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + (input-cf (the (unsigned-byte 1) + (rflagsBits->cf input-rflags))) + + (raw-result (the (unsigned-byte ,(1+ result-nbits)) + (+ + (the (unsigned-byte ,result-nbits) dst) + (the (unsigned-byte ,result-nbits) src) + (the (unsigned-byte 1) input-cf)))) + (signed-raw-result + (the (signed-byte ,(1+ result-nbits)) + (+ (the (signed-byte ,result-nbits) + (,ntoi dst)) + (the (signed-byte ,result-nbits) + (,ntoi src)) + (the (unsigned-byte 1) + input-cf)))) + + (result (the (unsigned-byte ,result-nbits) + (n-size ,result-nbits raw-result))) + + (cf (the (unsigned-byte 1) (,cf-spec-fn raw-result))) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + (af (the (unsigned-byte 1) (,af-spec-fn dst src input-cf))) + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of (the (unsigned-byte 1) (,of-spec-fn signed-raw-result))) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :af af + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->af + af + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags))))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags 0)) + + (mv result output-rflags undefined-flags)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-adc-spec-gen-fn 1)) +(make-event (gpr-adc-spec-gen-fn 2)) +(make-event (gpr-adc-spec-gen-fn 4)) +(make-event (gpr-adc-spec-gen-fn 8)) + +;; ====================================================================== +;; SPECIFICATION: ADCX/ADOX +;; ====================================================================== + +;; ADCX: Similar to ADC but sets only CF, preserves other flags +;; ADOX: Similar to ADCX but uses/sets OF instead of CF. +(define gpr-adcx/adox-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-ADCX/ADOX-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (cf-spec-fn (mk-name "CF-SPEC" result-nbits))) + + + `(define ,fn-name + ((adcx booleanp) + (dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + :inline t + :no-function t + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + (input-cf (the (unsigned-byte 1) + (if adcx + (rflagsBits->cf input-rflags) + (rflagsBits->of input-rflags)))) + + (raw-result (the (unsigned-byte ,(1+ result-nbits)) + (+ + (the (unsigned-byte ,result-nbits) dst) + (the (unsigned-byte ,result-nbits) src) + (the (unsigned-byte 1) input-cf)))) + + (result (the (unsigned-byte ,result-nbits) + (n-size ,result-nbits raw-result))) + + (cf (the (unsigned-byte 1) (,cf-spec-fn raw-result))) + + (output-rflags (if adcx + (mbe :logic + (change-rflagsBits + input-rflags + :cf cf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf cf input-rflags))) + (mbe :logic + (change-rflagsBits + input-rflags + :of cf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->of cf input-rflags))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags 0)) + + (mv result output-rflags undefined-flags)) + + /// + (local (in-theory (disable unsigned-byte-p))) + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name adcx dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name adcx dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name adcx dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-adcx/adox-spec-gen-fn 4)) +(make-event (gpr-adcx/adox-spec-gen-fn 8)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/and-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/and-spec.lisp new file mode 100644 index 000000000..f3ceb0033 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/and-spec.lisp @@ -0,0 +1,150 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +;; This book contains the specification of the following instructions: +;; and + +(include-book "structures" :dir :utils) +(include-book "../rflags-spec") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; SPECIFICATION: AND +;; ====================================================================== + +(define gpr-and-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-AND-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (?cf-spec-fn (mk-name "CF-SPEC" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + :inline t + :no-function t + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + ((the (unsigned-byte ,result-nbits) result) + (mbe :logic (part-select (logand dst src) + :low 0 :width ,result-nbits) + :exec (logand dst src))) + + (cf 0) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + ;; AF is undefined + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of 0) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags)))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + ;; AF is undefined. + (undefined-flags (!rflagsBits->af 1 0))) + + (mv result output-rflags undefined-flags)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)) + + )) + +(make-event (gpr-and-spec-gen-fn 1)) +(make-event (gpr-and-spec-gen-fn 2)) +(make-event (gpr-and-spec-gen-fn 4)) +(make-event (gpr-and-spec-gen-fn 8)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic-spec.lisp new file mode 100644 index 000000000..2c32dd6a7 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic-spec.lisp @@ -0,0 +1,137 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "add-spec") +(include-book "sub-spec") +(include-book "or-spec") +(include-book "and-spec") +(include-book "xor-spec") + +;; ====================================================================== + +(defun gpr-arith/logic-spec-gen-fn (operand-size) + + (declare (type (member 1 2 4 8) operand-size) + (xargs :verify-guards nil)) + + (b* ((fn-name (mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + (gpr-add-spec-fn (mk-name "GPR-ADD-SPEC-" operand-size)) + (gpr-adc-spec-fn (mk-name "GPR-ADC-SPEC-" operand-size)) + (?gpr-sub-spec-fn (mk-name "GPR-SUB-SPEC-" operand-size)) + (?gpr-sbb-spec-fn (mk-name "GPR-SBB-SPEC-" operand-size)) + (?gpr-cmp-spec-fn (mk-name "GPR-CMP-SPEC-" operand-size)) + (?gpr-or-spec-fn (mk-name "GPR-OR-SPEC-" operand-size)) + (?gpr-and-spec-fn (mk-name "GPR-AND-SPEC-" operand-size)) + (?gpr-xor-spec-fn (mk-name "GPR-XOR-SPEC-" operand-size)) + (?gpr-test-spec-fn (mk-name "GPR-TEST-SPEC-" operand-size)) + (?gpr-xadd-spec-fn (mk-name "GPR-XADD-SPEC-" operand-size))) + + `(define ,fn-name + ((operation :type (member #.*OP-ADD* #.*OP-XADD* #.*OP-ADC* #.*OP-SUB* + #.*OP-SBB* #.*OP-CMP* #.*OP-OR* + #.*OP-AND* #.*OP-XOR* #.*OP-TEST*)) + (dst :type (unsigned-byte ,(ash operand-size 3))) + (src :type (unsigned-byte ,(ash operand-size 3))) + (input-rflags :type (unsigned-byte 32))) + + :parents (gpr-arith/logic-spec) + :enabled t + (case operation + (#.*OP-ADD* ;; 0 + (,gpr-add-spec-fn dst src input-rflags)) + (#.*OP-OR* ;; 1 + (,gpr-or-spec-fn dst src input-rflags)) + (#.*OP-ADC* ;; 2 + (,gpr-adc-spec-fn dst src input-rflags)) + (#.*OP-AND* ;; 3 + (,gpr-and-spec-fn dst src input-rflags)) + (#.*OP-SUB* ;; 4 + (,gpr-sub-spec-fn dst src input-rflags)) + (#.*OP-XOR* ;; 5 + (,gpr-xor-spec-fn dst src input-rflags)) + (#.*OP-SBB* ;; 6 + (,gpr-sbb-spec-fn dst src input-rflags)) + (#.*OP-TEST* ;; 7 + ;; We will re-use the AND specification here. + (,gpr-and-spec-fn dst src input-rflags)) + (#.*OP-CMP* ;; 8 + ;; We will re-use the SUB specification here. + (,gpr-sub-spec-fn dst src input-rflags)) + (#.*OP-XADD* ;; 0 + (,gpr-xadd-spec-fn dst src input-rflags)) + (otherwise + ;; The guard will prevent us from reaching here. + (mv 0 0 0)))))) + +(make-event (gpr-arith/logic-spec-gen-fn 1)) +(make-event (gpr-arith/logic-spec-gen-fn 2)) +(make-event (gpr-arith/logic-spec-gen-fn 4)) +(make-event (gpr-arith/logic-spec-gen-fn 8)) + +(defsection gpr-arith/logic-spec + + :parents (instruction-semantic-functions) + :short "Semantics of general-purpose arithmetic and logical instructions" + :long "

These instructions are:

+
    +
  • @('ADD')
  • +
  • @('ADC')
  • +
  • @('SUB')
  • +
  • @('SBB')
  • +
  • @('CMP')
  • +
  • @('OR')
  • +
  • @('AND')
  • +
  • @('XOR')
  • +
  • @('TEST')
  • +
  • @('XADD')
  • +
+ +@(def gpr-arith/logic-spec)" + + (defmacro gpr-arith/logic-spec + (operand-size operation dst src input-rflags) + `(case ,operand-size + (1 (gpr-arith/logic-spec-1 ,operation ,dst ,src ,input-rflags)) + (2 (gpr-arith/logic-spec-2 ,operation ,dst ,src ,input-rflags)) + (4 (gpr-arith/logic-spec-4 ,operation ,dst ,src ,input-rflags)) + (otherwise + (gpr-arith/logic-spec-8 ,operation ,dst ,src ,input-rflags))))) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic.lisp new file mode 100644 index 000000000..9feb521c9 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/arith-and-logic.lisp @@ -0,0 +1,1018 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "arith-and-logic-spec") +(include-book "../decoding-and-spec-utils") + +;(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +;(local (include-book "centaur/bitops/signed-byte-p" :dir :system)) + +;; ====================================================================== + +;; Some helper theorems to speed up checkpoints involving (un)signed-byte-p: + +(local + (defthm signed-byte-p-49-thm-1 + (implies (and (signed-byte-p 48 (+ a b)) + (signed-byte-p 48 c) + (integerp a) + (integerp b)) + (signed-byte-p 49 (+ (- c) a b))))) + +(local + (defthm signed-byte-p-48-thm-1 + (implies (and (signed-byte-p 48 x) + (< (+ x y) *2^47*) + (natp y)) + (signed-byte-p 48 (+ x y))))) + +(local + (defthm signed-byte-p-49-thm-2 + (implies (and (signed-byte-p 48 (+ a b)) + (signed-byte-p 48 c) + (< (+ z a b) *2^47*) + (integerp a) + (integerp b) + (natp z)) + (signed-byte-p 49 (+ z (- c) a b))) + :hints (("Goal" :in-theory (e/d* (signed-byte-p) ()))))) + +(local + (defthm signed-byte-p-48-thm-2 + (implies (and (signed-byte-p 48 x) + (< (+ z x y) *2^47*) + (natp y) + (natp z)) + (signed-byte-p 48 (+ z x y))))) + +(local + (defthm signed-byte-p-49-thm-3 + (implies (and (signed-byte-p 48 x) + (natp y) + (<= y 4)) + (signed-byte-p 49 (+ x y))) + :hints (("Goal" :in-theory (e/d* (signed-byte-p unsigned-byte-p) + ()))))) + +(local + (defthm signed-byte-p-48-thm-3 + (implies (and (not (signed-byte-p 48 (+ x y))) + (signed-byte-p 48 x) + (natp y)) + (<= *2^47* (+ x y))))) + +(local + (defthm signed-byte-p-49-thm-4 + (implies (and (signed-byte-p 48 y) + (signed-byte-p 48 z) + (< (+ x y) *2^47*) + (natp x)) + (signed-byte-p 49 (+ x y (- z)))) + :hints (("Goal" :in-theory (e/d* (signed-byte-p unsigned-byte-p) + ()))))) + +(local + (defrule signed-byte-p-49-thm-5 + (implies (and (signed-byte-p 48 x) + (signed-byte-p 48 y)) + (signed-byte-p 49 (+ (- x) y))))) + + + +(local + (defthm member-equal-and-integers + (implies (and (<= operation 8) + (<= 0 operation) + (integerp operation)) + (member-equal operation '(0 2 4 6 8 1 3 5 7))))) + +(defrulel signed-byte-p-64-when-signed-byte-p48 + (implies (signed-byte-p 48 x) + (signed-byte-p 64 x))) + +(defrulel signed-byte-p-49-when-signed-byte-p48 + (implies (signed-byte-p 48 x) + (signed-byte-p 49 x))) + +(local (in-theory (e/d* () + (member-equal + signed-byte-p + unsigned-byte-p + rml-size)))) + +;; ====================================================================== +;; INSTRUCTIONS: (one-byte opcode map) +;; add, adc, sub, sbb, or, and, sub, xor, cmp, test +;; ====================================================================== + +(def-inst x86-add/xadd/adc/sub/sbb/or/and/xor/cmp/test-E-G + + :parents (one-byte-opcodes) + + :short "Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP, TEST: Addressing Mode = \(E, G\)" + + :long "

Op/En = MR: \[OP R/M, REG\] or \[OP E, G\]

+ +

where @('E') is the destination operand and @('G') is the source + operand. Note that @('E') stands for a general-purpose register or + memory operand specified by the @('ModRM.r/m') field, and @('G') + stands for a general-purpose register specified by the + @('ModRM.reg') field.

+ + \[OP R/M, REG\] Flags Affected
+ 00, 01: ADD c p a z s o
+ 08, 09: OR p z s \(o and c cleared, a undefined\)
+ 10, 11: ADC c p a z s o
+ 18, 19: SBB c p a z s o
+ 20, 21: AND p z s \(o and c cleared, a undefined\)
+ 28, 29: SUB c p a z s o
+ 30, 31: XOR p z s \(o and c cleared, a undefined\)
+ 38, 39: CMP c p a z s o
+ 84, 85: TEST p z s \(o and c cleared, a undefined\)
+ 0F C0, 0F C1: XADD c p a z s o
" + + :operation t + + :guard (and (natp operation) + (or (<= operation 8) + (equal operation #.*OP-XADD*))) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d* () + (unsigned-byte-p + signed-byte-p))))) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (byte-operand? (eql 0 (the (unsigned-byte 1) + (logand 1 opcode)))) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + (G (rgfi-size operand-size + (the (unsigned-byte 4) + (reg-index reg rex-byte #.*r*)) + rex-byte x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + E + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) E-addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode #.*gpr-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Everything above this point is just further decoding the + ;; instruction and fetching operands. + + ;; Instruction Specification: + + ;; Computing the flags and the result: + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((mv result + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (gpr-arith/logic-spec operand-size operation E G input-rflags)) + + ;; Write destination into source for XADD + (x86 (if (equal operation *OP-XADD*) + (!rgfi-size operand-size (reg-index reg rex-byte #.*r*) E rex-byte x86) + x86)) + ;; Updating the x86 state with the result and eflags. + ((mv flg1 x86) + (if (or (eql operation #.*OP-CMP*) + (eql operation #.*OP-TEST*)) + ;; CMP and TEST modify just the flags. + (mv nil x86) + (x86-operand-to-reg/mem proc-mode operand-size + inst-ac? + nil ;; Not a memory pointer operand + result + seg-reg + (the (signed-byte 64) E-addr) + rex-byte + r/m + mod + x86))) + ((when flg1) + (!!ms-fresh :x86-operand-to-reg/mem flg1)) + + (x86 (write-user-rflags output-rflags undefined-flags x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + + + +(def-inst x86-adcx/adox + + :parents (three-byte-opcodes) + + :short "Operand Fetch and Execute for ADCX/ADOX" + + :long "

Op/En = RM: \[OP REG, R/M\] or \[OP G, E\]

+ +

where @('G') is the destination operand and @('E') is the source + operand. Note that @('G') stands for a general-purpose register + specified by the @('ModRM.reg') field, and @('E') stands for a + general-purpose register or memory operand specified by the + @('ModRM.r/m') field.

+ +

These instructions are essentially variations of ADC with different flag + behavior. ADCX sums the two operands and the CF flag (just like ADC), then + sets the CF flag according to unsigned overflow (just like ADC), but doesn't + modify any other flags. ADOX is the same as ADCX but uses/sets OF in place of + CF.

" + + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d* () + (unsigned-byte-p + signed-byte-p))))) + + :modr/m t + + :additional-args ((adcx booleanp)) + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + (operand-size (if (logbitp *w* rex-byte) 8 4)) + + (G (rgfi-size operand-size + (the (unsigned-byte 4) + (reg-index reg rex-byte #.*r*)) + rex-byte x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + E + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) E-addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode #.*gpr-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + + ;; Computing the flags and the result: + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((mv result + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (case operand-size + (8 (gpr-adcx/adox-spec-8 adcx G E input-rflags)) + (t (gpr-adcx/adox-spec-4 adcx G E input-rflags)))) + + ;; Updating the x86 state with the result and eflags. + (x86 + (!rgfi-size operand-size (reg-index reg rex-byte #.*r*) result + rex-byte x86)) + + (x86 (write-user-rflags output-rflags undefined-flags x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + + +(def-inst x86-add/adc/sub/sbb/or/and/xor/cmp-G-E + + :parents (one-byte-opcodes) + + :short "Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP: Addressing Mode = \(G, E\)" + + :long "

Op/En = RM: \[OP REG, R/M\] or \[OP G, E\]

+ +

where @('G') is the destination operand and @('E') is the source + operand. Note that @('G') stands for a general-purpose register + specified by the @('ModRM.reg') field, and @('E') stands for a + general-purpose register or memory operand specified by the + @('ModRM.r/m') field.

+ + \[OP REG, R/M\] Flags Affected
+ 02, 03: ADD c p a z s o
+ 0A, 0B: OR p z s \(o and c cleared, a undefined\)
+ 12, 13: ADC c p a z s o
+ 1A, 1B: SBB c p a z s o
+ 22, 23: AND p z s \(o and c cleared, a undefined\)
+ 2A, 2B: SUB c p a z s o
+ 32, 33: XOR p z s \(o and c cleared, a undefined\)
+ 3A, 3B: CMP c p a z s o
" + + :operation t + + :guard (and (not (equal operation #.*OP-TEST*)) + (natp operation) + (<= operation 8)) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d* () + (unsigned-byte-p + signed-byte-p))))) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (byte-operand? (eql 0 (the (unsigned-byte 1) + (logand 1 opcode)))) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + (G (rgfi-size operand-size + (the (unsigned-byte 4) + (reg-index reg rex-byte #.*r*)) + rex-byte x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + E + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) E-addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode #.*gpr-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Everything above this point is just further decoding the + ;; instruction and fetching operands. + + ;; Instruction Specification: + + ;; Computing the flags and the result: + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((mv result + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (gpr-arith/logic-spec operand-size operation G E input-rflags)) + + ;; Updating the x86 state with the result and eflags. + (x86 + (if (eql operation #.*OP-CMP*) + ;; CMP modifies the flags only. + x86 + (!rgfi-size operand-size (reg-index reg rex-byte #.*r*) result + rex-byte x86))) + + (x86 (write-user-rflags output-rflags undefined-flags x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +(def-inst x86-add/adc/sub/sbb/or/and/xor/cmp-test-E-I + + :parents (one-byte-opcodes) + + :short "Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP, TEST: Addressing Mode = \(E, I\)" + + :long "

Op/En = MI: \[OP R/M, IMM\] or \[OP E, I\]

+ +

where @('E') is the destination operand and @('I') is the source + operand. Note that @('E') stands for a general-purpose register or + memory operand specified by the @('ModRM.r/m') field, and @('I') + stands for immediate data. All opcodes except those of TEST fall + under Group 1, and have opcode extensions (ModR/M.reg field), as + per Table A-6 of the Intel Manuals, Vol. 2. The opcodes for TEST + fall under Unary Group 3, and also have opcode extensions.

+ + \[OP R/M, IMM\] Flags Affected
+ 80-83 (000): ADD c p a z s o
+ 80-83 (001): OR p z s \(o and c cleared, a undefined\)
+ 80-83 (010): ADC c p a z s o
+ 80-83 (011): SBB c p a z s o
+ 80-83 (100): AND p z s \(o and c cleared, a undefined\)
+ 80-83 (101): SUB c p a z s o
+ 80-83 (110): XOR p z s \(o and c cleared, a undefined\)
+ 80-83 (111): CMP c p a z s o
+ F6-F7 (000): TEST p z s \(o and c cleared, a undefined\)
" + + :operation t + + :guard (and (natp operation) + (<= operation 8) + ;; The opcode 82H is an alternative encoding that generates #UD + ;; in 64-bit mode; see AMD manual, Dec'17, Volume 3, Appendix + ;; B.3. Also see the opcode-maps. + (if (eql opcode #x82) + (not (equal proc-mode #.*64-bit-mode*)) + t)) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d* () + (force + (force) + gpr-arith/logic-spec-8 + gpr-arith/logic-spec-4 + gpr-arith/logic-spec-2 + gpr-arith/logic-spec-1 + rml-size + select-operand-size + unsigned-byte-p + signed-byte-p))))) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (E-byte-operand? (or (eql opcode #x80) + (eql opcode #x82) + (eql opcode #xF6))) + ((the (integer 1 8) E-size) + (select-operand-size + proc-mode E-byte-operand? rex-byte nil prefixes nil nil nil x86)) + + (imm-byte-operand? (or (eql opcode #x80) + (eql opcode #x82) + (eql opcode #x83) + (eql opcode #xF6))) + ((the (integer 1 4) imm-size) + (select-operand-size + proc-mode imm-byte-operand? rex-byte t prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + E + increment-RIP-by + (the (signed-byte 64) E-addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode #.*gpr-access* + E-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + imm-size ;; bytes of immediate data + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ((mv ?flg1 (the (unsigned-byte 32) imm) x86) + (rme-size-opt proc-mode imm-size temp-rip #.*cs* :x nil x86)) + ((when flg1) + (!!ms-fresh :rme-size-error flg1)) + + ;; Sign-extend imm: + (imm + (mbe :logic (loghead (ash E-size 3) (logext (ash imm-size 3) imm)) + :exec (logand (case E-size + (1 #.*2^8-1*) + (2 #.*2^16-1*) + (4 #.*2^32-1*) + (8 #.*2^64-1*) + ;; Won't reach here. + (t 0)) + (case imm-size + (1 (the (signed-byte 8) + (n08-to-i08 + (the (unsigned-byte 8) imm)))) + (2 (the (signed-byte 16) + (n16-to-i16 + (the (unsigned-byte 16) imm)))) + (4 (the (signed-byte 32) + (n32-to-i32 + (the (unsigned-byte 32) imm)))) + ;; Won't reach here. + (t 0))))) + + ((mv flg (the (signed-byte #.*max-linear-address-size+1*) temp-rip)) + (add-to-*ip proc-mode temp-rip imm-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Everything above this point is just further decoding the + ;; instruction and fetching operands. + + ;; Instruction Specification: + + ;; Computing the flags and the result: + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((mv result + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (gpr-arith/logic-spec E-size operation E imm input-rflags)) + + ;; Updating the x86 state with the result and eflags. + ((mv flg1 x86) + (if (or (eql operation #.*OP-CMP*) + (eql operation #.*OP-TEST*)) + ;; CMP and TEST modify just the flags. + (mv nil x86) + (x86-operand-to-reg/mem proc-mode E-size + inst-ac? + nil ;; Not a memory pointer operand + result + seg-reg + (the (signed-byte 64) E-addr) + rex-byte + r/m + mod + x86))) + ;; Note: If flg1 is non-nil, we bail out without changing the + ;; x86 state. + ((when flg1) + (!!ms-fresh :x86-operand-to-reg/mem flg1)) + + (x86 (write-user-rflags output-rflags undefined-flags x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +(def-inst x86-add/adc/sub/sbb/or/and/xor/cmp-test-rAX-I + + :parents (one-byte-opcodes) + + :short "Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP, TEST: Addressing Mode = \(rAX, I\)" + + :long "

Op/En = I: \[OP rAX, IMM\] or \[OP rAX, I\]

+ +

where @('rAX') is the destination operand and @('I') is the + source operand. Note that @('rAX') stands for AL/AX/EAX/RAX, + depending on the operand size, and @('I') stands for immediate + data.

+ + \[OP rAX, IMM\] Flags Affected
+ 04, 05: ADD c p a z s o
+ 0C, 0D: OR p z s \(o and c cleared, a undefined\)
+ 14, 15: ADC c p a z s o
+ 1C, 1D: SBB c p a z s o
+ 24, 25: AND p z s \(o and c cleared, a undefined\)
+ 2C, 2D: SUB c p a z s o
+ 34, 35: XOR p z s \(o and c cleared, a undefined\)
+ 3C, 3D: CMP c p a z s o
+ A8, A9: TEST p z s \(o and c cleared, a undefined\)
" + + :operation t + + :guard (and (natp operation) + (<= operation 8)) + + :prepwork ((local (in-theory (e/d* () (commutativity-of-+))))) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d* () + (force (force) + gpr-arith/logic-spec-8 + gpr-arith/logic-spec-4 + gpr-arith/logic-spec-2 + gpr-arith/logic-spec-1 + unsigned-byte-p))))) + :body + + (b* ((byte-operand? (equal 0 (logand 1 opcode))) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte t prefixes nil nil nil x86)) + ;; rex does not promote byte opcodes to 64-bit + (rAX-size (if (and (not byte-operand?) + (logbitp #.*w* rex-byte)) + 8 + operand-size)) + + (rAX (rgfi-size rAX-size *rax* rex-byte x86)) + ((mv ?flg imm x86) + (rme-size-opt proc-mode operand-size temp-rip #.*cs* :x nil x86)) + ((when flg) + (!!ms-fresh :rme-size-error flg)) + + ;; Sign-extend imm when required. + (imm + (if (and (not byte-operand?) + (equal rAX-size 8)) + (the (unsigned-byte 64) + (n64 + (the (signed-byte 32) + (n32-to-i32 + (the (unsigned-byte 32) imm))))) + (the (unsigned-byte 32) imm))) + + ((mv flg (the (signed-byte #.*max-linear-address-size+1*) temp-rip)) + (add-to-*ip proc-mode temp-rip operand-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Everything above this point is just further decoding the + ;; instruction and fetching operands. + + ;; Instruction Specification: + + ;; Computing the flags and the result: + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((mv result + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (gpr-arith/logic-spec rAX-size operation rAX imm input-rflags)) + + ;; Updating the x86 state with the result and eflags. + (x86 + (if (or (eql operation #.*OP-CMP*) + (eql operation #.*OP-TEST*)) + ;; CMP and TEST modify just the flags. + x86 + (!rgfi-size rAX-size *rax* result rex-byte x86))) + + (x86 (write-user-rflags output-rflags undefined-flags x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;; ====================================================================== +;; INSTRUCTION: INC/DEC +;; ====================================================================== + +(local + (defthm logsquash-and-logand-32 + (implies (unsigned-byte-p 32 x) + (equal (bitops::logsquash 1 x) + (logand 4294967294 x))) + :hints (("Goal" :in-theory (e/d (bitops::logsquash) + (bitops::logand-with-negated-bitmask)))))) + +(def-inst x86-inc/dec-FE-FF + + ;; FE/0,1: INC/DEC r/m8 + ;; FF/0,1: INC/DEC r/m16, r/m32, r/m64 + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + (select-byte-operand (equal 0 (logand 1 opcode))) + + ((the (integer 1 8) r/mem-size) + (select-operand-size + proc-mode select-byte-operand rex-byte nil prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + r/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode #.*gpr-access* + r/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Computing the flags and the result: + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((the (unsigned-byte 1) old-cf) + (rflagsBits->cf input-rflags)) + ((mv result output-rflags undefined-flags) + (gpr-arith/logic-spec r/mem-size + (if (eql reg 0) + ;; INC + #.*OP-ADD* + ;; DEC + #.*OP-SUB*) + r/mem 1 input-rflags)) + + ;; Updating the x86 state: + ;; CF is unchanged. + (output-rflags (the (unsigned-byte 32) + (!rflagsBits->cf old-cf output-rflags))) + (x86 (write-user-rflags output-rflags undefined-flags x86)) + + ((mv flg1 x86) + (x86-operand-to-reg/mem proc-mode r/mem-size + inst-ac? + nil ;; Not a memory pointer operand + result + seg-reg + (the (signed-byte 64) addr) + rex-byte + r/m + mod + x86)) + ((when flg1) + (!!ms-fresh :x86-operand-to-reg/mem flg1)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-inc/dec-4x + + ;; 40 + rw: INC r16 + ;; 40 + rd: INC r32 + ;; 48 + rw: DEC r16 + ;; 48 + rd: DEC r32 + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (;; This is not encodable in 64-bit mode, because in that mode a 4x byte + ;; is treated as a REX prefix, not as an opcode. Thus, if we reach this + ;; point in the code, we know that we are in 32-bit mode. + + ((the (integer 2 4) operand-size) + (select-operand-size + proc-mode nil 0 nil prefixes nil nil nil x86)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (reg (the (unsigned-byte 3) (logand 7 opcode))) + (operand (rgfi-size operand-size reg 0 x86)) + + ;; Computing the flags and the result: + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((the (unsigned-byte 1) old-cf) + (rflagsBits->cf input-rflags)) + ((mv result output-rflags undefined-flags) + (gpr-arith/logic-spec operand-size + (if (logbitp 3 opcode) ; 48-4F + ;; DEC + #.*OP-SUB* + ;; INC + #.*OP-ADD*) + operand 1 input-rflags)) + + ;; Updating the x86 state: + ;; CF is unchanged (see Intel manual, Mar'17, Vol. 2, INC & DEC) + (output-rflags (the (unsigned-byte 32) + (!rflagsBits->cf old-cf output-rflags))) + (x86 (write-user-rflags output-rflags undefined-flags x86)) + (x86 (!rgfi-size operand-size reg result 0 x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: NOT/NEG +;; ====================================================================== + +(def-inst x86-not/neg-F6-F7 + + ;; F6/2: NOT r/m8 + ;; F7/2: NOT r/m16, r/m32, r/m64 + + ;; F6/3: NEG r/m8 + ;; F7/3: NEG r/m16, r/m32, r/m64 + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + (select-byte-operand (equal 0 (logand 1 opcode))) + ((the (integer 0 8) r/mem-size) + (select-operand-size + proc-mode select-byte-operand rex-byte nil prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + r/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode #.*gpr-access* + r/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Computing the flags and the result: + + ((the (unsigned-byte 32) input-rflags) (rflags x86)) + ((mv result + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (case reg + (3 + ;; (NEG x) = (SUB 0 x) + (gpr-arith/logic-spec r/mem-size #.*OP-SUB* 0 r/mem input-rflags)) + (otherwise + ;; NOT (and some other instructions not specified yet) + (mv (trunc r/mem-size (lognot r/mem)) 0 0)))) + + ;; Updating the x86 state: + (x86 + (if (eql reg 3) + (let* ( ;; CF is special for NEG. + (cf (the (unsigned-byte 1) (if (equal 0 r/mem) 0 1))) + (output-rflags + (the (unsigned-byte 32) + (!rflagsBits->cf cf output-rflags))) + (x86 (write-user-rflags output-rflags undefined-flags x86))) + x86) + x86)) + ((mv flg1 x86) + (x86-operand-to-reg/mem proc-mode r/mem-size + inst-ac? + nil ;; Not a memory pointer operand + result + seg-reg + (the (signed-byte 64) addr) + rex-byte + r/m + mod + x86)) + ((when flg1) + (!!ms-fresh :x86-operand-to-reg/mem flg1)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/conditional.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/conditional.lisp new file mode 100644 index 000000000..9d57a374d --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/conditional.lisp @@ -0,0 +1,563 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../decoding-and-spec-utils") +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; INSTRUCTION: Jcc/JrCXZ/CMOVcc/SETcc +;; ====================================================================== + +; From Intel Vol. 1, 6-11: + +;; In 64-bit mode, the operand size for all near branches (CALL, RET, JCC, +;; JCXZ, JMP, and LOOP) is forced to 64 bits. These instructions update the +;; 64-bit RIP without the need for a REX operand-size prefix. + +;; The following aspects of near branches are controlled by the effective +;; operand size: +;; Truncation of the size of the instruction pointer +;; Size of a stack pop or push, due to a CALL or RET +;; Size of a stack-pointer increment or decrement, due to a CALL or RET +;; Indirect-branch operand size + +;; In 64-bit mode, all of the above actions are forced to 64 bits regardless of +;; operand size prefixes (operand size prefixes are silently ignored). However, +;; the displacement field for relative branches is still limited to 32 bits and +;; the address size for near branches is not forced in 64-bit mode. + +;; Address sizes affect the size of RCX used for JCXZ and LOOP; they also +;; impact the address calculation for memory indirect branches. Such addresses +;; are 64 bits by default; but they can be overridden to 32 bits by an address +;; size prefix. + +(define jcc/cmovcc/setcc-spec + ((opcode :type (unsigned-byte 8)) + x86) + + ;; Jcc + + ;; Op Instruction Condition + ;; 70 JO rel8 Jump if OF = 1 + ;; 71 JNO rel8 Jump if OF = 0 + ;; 72 JB/NAE/C rel8 Jump if CF = 1 + ;; 73 JNB/AE/NC rel8 Jump if CF = 0 + ;; 74 JZ/E rel8 Jump if ZF = 1 + ;; 75 JNZ/NE rel8 Jump if ZF = 0 + ;; 76 JBE/NA rel8 Jump if CF = 1 or ZF = 1 + ;; 77 JNBE/A rel8 Jump if CF = 0 and ZF = 0 + ;; 78 JS rel8 Jump if SF = 1 + ;; 79 JNS rel8 Jump if SF = 0 + ;; 7A JP/PE rel8 Jump if PF = 1 + ;; 7B JNP/PO rel8 Jump if PF = 0 + ;; 7C JL/NGE rel8 Jump if SF != OF + ;; 7D JNL/GE rel8 Jump if SF = OF + ;; 7E JLE/NG rel8 Jump if ZF = 1 or SF != OF + ;; 7F JNLE/G rel8 Jump if ZF = 0 and SF = OF + + ;; Op Instruction Condition + ;; 0F 80 JO rel32 Jump if OF = 1 + ;; 0F 81 JNO rel32 Jump if OF = 0 + ;; 0F 82 JB/NAE/C rel32 Jump if CF = 1 + ;; 0F 83 JNB/AE/NC rel32 Jump if CF = 0 + ;; 0F 84 JZ/E rel32 Jump if ZF = 1 + ;; 0F 85 JNZ/JNE rel32 Jump if ZF = 0 + ;; 0F 86 JBE/NA rel32 Jump if CF = 1 or ZF = 1 + ;; 0F 87 JNBE/A rel32 Jump if CF = 0 and ZF = 0 + ;; 0F 88 JS rel32 Jump if SF = 1 + ;; 0F 89 JNS rel32 Jump if SF = 0 + ;; 0F 8A JP/PE rel32 Jump if PF = 1 + ;; 0F 8B JNP/PO rel32 Jump if PF = 0 + ;; 0F 8C JL/NGE rel32 Jump if SF != OF + ;; 0F 8D JNL/GE rel32 Jump if SF = OF + ;; 0F 8E JLE/NG rel32 Jump if ZF = 1 or SF != OF + ;; 0F 8F JNLE/G rel32 Jump if ZF = 0 and SF = OF + + ;; CMOVcc + + ;; 0F 40 CMOVO r16/32/64, r/m16/32/64 Move if OF = 1 + ;; 0F 41 CMOVNO r16/32/64, r/m16/32/64 Move if OF = 0 + ;; 0F 42 CMOVB/CMOVC/CMOVNAE r16/32/64, r/m16/32/64 Move if CF = 1 + ;; 0F 43 CMOVAE/CMOVNB/CMOVNC r16/32/64, r/m16/32/64 Move if CF = 0 + ;; 0F 44 CMOVE/CMOVZ r16/32/64, r/m16/32/64 Move if ZF = 1 + ;; 0F 45 CMOVNE/CMOVNZ r16/32/64, r/m16/32/64 Move if ZF = 0 + ;; 0F 46 CMOVBE/CMOVNA r16/32/64, r/m16/32/64 Move if CF = 1 or ZF = 1 + ;; 0F 47 CMOVA/CMOVNBE r16/32/64, r/m16/32/64 Move if CF = 0 and ZF = 0 + ;; 0F 48 CMOVS r16/32/64, r/m16/32/64 Move if SF = 1 + ;; 0F 49 CMOVNS r16/32/64, r/m16/32/64 Move if SF = 0 + ;; 0F 4A CMOVP/CMOVPE r16/32/64, r/m16/32/64 Move if PF = 1 + ;; 0F 4B CMOVNP/CMOVPO r16/32/64, r/m16/32/64 Move if PF = 0 + ;; 0F 4C CMOVL/CMOVNGE r16/32/64, r/m16/32/64 Move if SF != OF + ;; 0F 4D CMOVGE/CMOVNL r16/32/64, r/m16/32/64 Move if SF = OF + ;; 0F 4E CMOVLE/CMOVNG r16/32/64, r/m16/32/64 Move if ZF = 1 or SF != OF + ;; 0F 4F CMOVG/CMOVNLE r16/32/64, r/m16/32/64 Move if ZF = 0 and SF = OF + + (let ((low-nibble (the (unsigned-byte 4) (logand opcode #xf)))) + (case low-nibble + (#x0 (equal 1 (the (unsigned-byte 1) (flgi :of x86)))) + (#x1 (equal 0 (the (unsigned-byte 1) (flgi :of x86)))) + (#x2 (equal 1 (the (unsigned-byte 1) (flgi :cf x86)))) + (#x3 (equal 0 (the (unsigned-byte 1) (flgi :cf x86)))) + (#x4 (equal 1 (the (unsigned-byte 1) (flgi :zf x86)))) + (#x5 (equal 0 (the (unsigned-byte 1) (flgi :zf x86)))) + (#x6 (or (equal 1 (the (unsigned-byte 1) (flgi :cf x86))) + (equal 1 (the (unsigned-byte 1) (flgi :zf x86))))) + (#x7 (and (equal 0 (the (unsigned-byte 1) (flgi :cf x86))) + (equal 0 (the (unsigned-byte 1) (flgi :zf x86))))) + (#x8 (equal 1 (the (unsigned-byte 1) (flgi :sf x86)))) + (#x9 (equal 0 (the (unsigned-byte 1) (flgi :sf x86)))) + (#xA (equal 1 (the (unsigned-byte 1) (flgi :pf x86)))) + (#xB (equal 0 (the (unsigned-byte 1) (flgi :pf x86)))) + (#xC (not (equal (the (unsigned-byte 1) (flgi :sf x86)) + (the (unsigned-byte 1) (flgi :of x86))))) + (#xD (equal (the (unsigned-byte 1) (flgi :sf x86)) + (the (unsigned-byte 1) (flgi :of x86)))) + (#xE (or (equal 1 (the (unsigned-byte 1) (flgi :zf x86))) + (not (equal (the (unsigned-byte 1) (flgi :sf x86)) + (the (unsigned-byte 1) (flgi :of x86)))))) + (#xF (and (equal 0 (the (unsigned-byte 1) (flgi :zf x86))) + (equal (the (unsigned-byte 1) (flgi :sf x86)) + (the (unsigned-byte 1) (flgi :of x86))))) + (otherwise ;; will not be reached + nil)))) + +(def-inst x86-one-byte-jcc + + ;; Jump (short) if condition is met + + ;; Intel manual, Mar'17, Vol. 2A, Jcc reference says: + ;; "In 64-bit mode, operand size is fixed at 64 bits. + ;; JMP Short is RIP + 8-bit offset sign extended to 64 bits." + + ;; Op/En: D + ;; Jcc + + ;; Op Instruction Condition + ;; 70 JO rel8 Jump if OF = 1 + ;; 71 JNO rel8 Jump if OF = 0 + ;; 72 JB/NAE/C rel8 Jump if CF = 1 + ;; 73 JNB/AE/NC rel8 Jump if CF = 0 + ;; 74 JZ/E rel8 Jump if ZF = 1 + ;; 75 JNZ/NE rel8 Jump if ZF = 0 + ;; 76 JBE/NA rel8 Jump if CF = 1 or ZF = 1 + ;; 77 JNBE/A rel8 Jump if CF = 0 and ZF = 0 + ;; 78 JS rel8 Jump if SF = 1 + ;; 79 JNS rel8 Jump if SF = 0 + ;; 7A JP/PE rel8 Jump if PF = 1 + ;; 7B JNP/PO rel8 Jump if PF = 0 + ;; 7C JL/NGE rel8 Jump if SF != OF + ;; 7D JNL/GE rel8 Jump if SF = OF + ;; 7E JLE/NG rel8 Jump if ZF = 1 or SF != OF + ;; 7F JNLE/G rel8 Jump if ZF = 0 and SF = OF + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 riml32 rime-size) ()))) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (enable rime-size)))) + + :body + + (b* (;; temp-rip right now points to the rel8 byte. Add 1 to + ;; temp-rip to account for rel8 when computing the length + ;; of this instruction. + (badlength? (check-instruction-length start-rip temp-rip 1)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (branch-cond (jcc/cmovcc/setcc-spec opcode x86))) + + (if branch-cond + + ;; branch condition is true: + (b* (;; read rel8 (a value between -128 and +127): + ((mv flg rel8 x86) (rime-size proc-mode 1 temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :rime-size-error flg)) + ;; add rel8 to the address of the next instruction, + ;; which is one past temp-rip to take the rel8 byte into account: + ((mv flg next-rip) (add-to-*ip proc-mode temp-rip (1+ rel8) x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + ;; set instruction pointer to new value: + (x86 (write-*ip proc-mode next-rip x86))) + x86) + + ;; branch condition is false: + (b* (;; go to the next instruction, + ;; which starts just after the rel8 byte: + ((mv flg next-rip) (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + (x86 (write-*ip proc-mode next-rip x86))) + x86)))) + +(def-inst x86-two-byte-jcc + + ;; Jump (near) if condition is met + + ;; Intel manual, Mar'17, Vol. 2A, Jcc reference says: + ;; "In 64-bit mode, operand size is fixed at 64 bits. + ;; JMP Short is RIP + 32-bit offset sign extended to 64 bits." + + ;; Two-byte Jcc: The operand-size is forced to a 64-bit operand size + ;; when in 64-bit mode (prefixes that change operand size are ignored + ;; for this instruction in 64-bit mode). See Intel Manual, Vol. 2C, + ;; Table A-1, row with 'f64'. + + ;; Op/En: D + ;; Op Instruction Condition + ;; 0F 80 JO rel32 Jump if OF = 1 + ;; 0F 81 JNO rel32 Jump if OF = 0 + ;; 0F 82 JB/NAE/C rel32 Jump if CF = 1 + ;; 0F 83 JNB/AE/NC rel32 Jump if CF = 0 + ;; 0F 84 JZ/E rel32 Jump if ZF = 1 + ;; 0F 85 JNZ/JNE rel32 Jump if ZF = 0 + ;; 0F 86 JBE/NA rel32 Jump if CF = 1 or ZF = 1 + ;; 0F 87 JNBE/A rel32 Jump if CF = 0 and ZF = 0 + ;; 0F 88 JS rel32 Jump if SF = 1 + ;; 0F 89 JNS rel32 Jump if SF = 0 + ;; 0F 8A JP/PE rel32 Jump if PF = 1 + ;; 0F 8B JNP/PO rel32 Jump if PF = 0 + ;; 0F 8C JL/NGE rel32 Jump if SF != OF + ;; 0F 8D JNL/GE rel32 Jump if SF = OF + ;; 0F 8E JLE/NG rel32 Jump if ZF = 1 or SF != OF + ;; 0F 8F JNLE/G rel32 Jump if ZF = 0 and SF = OF + + :parents (two-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 riml32 rime-size) ()))) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (enable rime-size)))) + + :body + + ;; Note: Here opcode is the second byte of the two byte opcode. + + (b* (((the (integer 0 4) offset-size) + (select-operand-size proc-mode nil rex-byte nil prefixes nil t t x86)) + + ;; temp-rip right now points to the rel16/rel32 byte. Add 2 or 4 to + ;; temp-rip to account for rel16/rel32 when computing the length + ;; of this instruction. + (badlength? (check-instruction-length start-rip temp-rip offset-size)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (branch-cond (jcc/cmovcc/setcc-spec opcode x86))) + + (if branch-cond + + ;; branch condition is true: + (b* (;; read rel16/rel32 (as a signed value): + ((mv flg offset x86) + (rime-size proc-mode offset-size temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :rime-size-error flg)) + ;; add rel16/rel32 to the address of the next instruction, + ;; which is 2 or 4 past temp-rip to take the rel16/32 into + ;; account: + ((mv flg next-rip) + (add-to-*ip proc-mode temp-rip (+ offset-size offset) x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + ;; set instruction pointer to new value: + (x86 (write-*ip proc-mode next-rip x86))) + x86) + + ;; branch condition is false: + (b* (;; fo to the next instruction, + ;; which starts just after the rel16/rel32: + ((mv flg next-rip) (add-to-*ip proc-mode temp-rip offset-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + (x86 (write-*ip proc-mode next-rip x86))) + x86)))) + +(def-inst x86-jrcxz + + ;; Jump (short) if condition is met + + ;; E3 cb: JCXZ rel8 Jump short if CX is 0 + ;; E3 cb: JECXZ rel8 Jump short if ECX is 0 + ;; E3 cb: JRCXZ rel8 Jump short if RCX is 0 + + ;; The register checked is determined by the address-size attribute. + + ;; Jump short: RIP = RIP + 8-bit offset sign-extended to 64-bits + + ;; Op/En: D + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 + riml32 + rime-size + select-address-size) + ()))) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (enable rime-size)))) + + :body + + (b* (;; temp-rip right now points to the rel8 byte. Add 1 to + ;; temp-rip to account for rel8 when computing the length + ;; of this instruction. + (badlength? (check-instruction-length start-rip temp-rip 1)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + (register-size (select-address-size proc-mode p4? x86)) + + (branch-cond + (equal (rgfi-size register-size *rcx* rex-byte x86) 0))) + + (if branch-cond + + ;; branch condition is true: + (b* (;; read rel8 (a value between -128 and +127): + ((mv flg rel8 x86) (rime-size proc-mode 1 temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :rime-size-error flg)) + ;; add rel8 to the address of the next instruction, + ;; which is one past temp-rip to take the rel8 byte into account: + ((mv flg next-rip) (add-to-*ip proc-mode temp-rip (1+ rel8) x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + ;; set instruction pointer to new value: + (x86 (write-*ip proc-mode next-rip x86))) + x86) + + ;; branch condition is false: + (b* (;; go to the next instruction, + ;; which starts just after the rel8 byte: + ((mv flg next-rip) (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + (x86 (write-*ip proc-mode next-rip x86))) + x86)))) + +(def-inst x86-cmovcc + + ;; Op/En: RM + ;; [OP REG, R/M] + + ;; CMOVcc + + ;; 0F 40 CMOVO r16/32/64, r/m16/32/64 Move if OF = 1 + ;; 0F 41 CMOVNO r16/32/64, r/m16/32/64 Move if OF = 0 + ;; 0F 42 CMOVB/CMOVC/CMOVNAE r16/32/64, r/m16/32/64 Move if CF = 1 + ;; 0F 43 CMOVAE/CMOVNB/CMOVNC r16/32/64, r/m16/32/64 Move if CF = 0 + ;; 0F 44 CMOVE/CMOVZ r16/32/64, r/m16/32/64 Move if ZF = 1 + ;; 0F 45 CMOVNE/CMOVNZ r16/32/64, r/m16/32/64 Move if ZF = 0 + ;; 0F 46 CMOVBE/CMOVNA r16/32/64, r/m16/32/64 Move if CF = 1 or ZF = 1 + ;; 0F 47 CMOVA/CMOVNBE r16/32/64, r/m16/32/64 Move if CF = 0 and ZF = 0 + ;; 0F 48 CMOVS r16/32/64, r/m16/32/64 Move if SF = 1 + ;; 0F 49 CMOVNS r16/32/64, r/m16/32/64 Move if SF = 0 + ;; 0F 4A CMOVP/CMOVPE r16/32/64, r/m16/32/64 Move if PF = 1 + ;; 0F 4B CMOVNP/CMOVPO r16/32/64, r/m16/32/64 Move if PF = 0 + ;; 0F 4C CMOVL/CMOVNGE r16/32/64, r/m16/32/64 Move if SF != OF + ;; 0F 4D CMOVGE/CMOVNL r16/32/64, r/m16/32/64 Move if SF = OF + ;; 0F 4E CMOVLE/CMOVNG r16/32/64, r/m16/32/64 Move if ZF = 1 or SF != OF + ;; 0F 4F CMOVG/CMOVNLE r16/32/64, r/m16/32/64 Move if ZF = 0 and SF = OF + + :parents (two-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 riml32) ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + ;; Note, opcode here denotes the second byte of the two-byte opcode. + + (b* ((p2 (prefixes->seg prefixes)) + + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* operand-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (branch-cond (jcc/cmovcc/setcc-spec opcode x86)) + + ;; Update the x86 state: + (x86 + (if branch-cond + (!rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + reg/mem + rex-byte + x86) + ;; The pseudocode in the Intel manual says that + ;; the high 32 bits are zeroed + ;; when in 64-bit mode the operand size is 32, + ;; even when the condition is false. + (if (and (equal operand-size 4) ; 32 bits + (equal proc-mode #.*64-bit-mode*)) + (!rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + (loghead 32 (rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + rex-byte x86)) + rex-byte + x86) + x86))) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-setcc + + ;; Op/En: M + + ;; SETcc + + ;; 0F 90 SETO r/m8 Set if OF = 1 + ;; 0F 91 SETNO r/m8 Set if OF = 0 + ;; 0F 92 SETB/SETC/SETNAE r/m8 Set if CF = 1 + ;; 0F 93 SETAE/SETNB/SETNC r/m8 Set if CF = 0 + ;; 0F 94 SETE/SETZ r/m8 Set if ZF = 1 + ;; 0F 95 SETNE/SETNZ r/m8 Set if ZF = 0 + ;; 0F 96 SETBE/SETNA r/m8 Set if CF = 1 or ZF = 1 + ;; 0F 97 SETA/SETNBE r/m8 Set if CF = 0 and ZF = 0 + ;; 0F 98 SETS r/m8 Set if SF = 1 + ;; 0F 99 SETNS r/m8 Set if SF = 0 + ;; 0F 9A SETP/SETPE r/m8 Set if PF = 1 + ;; 0F 9B SETNP/SETPO r/m8 Set if PF = 0 + ;; 0F 9C SETL/SETNGE r/m8 Set if SF != OF + ;; 0F 9D SETGE/SETNL r/m8 Set if SF = OF + ;; 0F 9E SETLE/SETNG r/m8 Set if ZF = 1 or SF != OF + ;; 0F 9F SETG/SETNLE r/m8 Set if ZF = 0 and SF = OF + + :parents (two-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 riml32) ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + ;; Note, opcode here denotes the second byte of the two-byte opcode. + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (equal mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (branch-cond (jcc/cmovcc/setcc-spec opcode x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ;; Update the x86 state: + (inst-ac? t) + (val (if branch-cond 1 0)) + ((mv flg2 x86) + (x86-operand-to-reg/mem proc-mode 1 + inst-ac? + nil ;; Not a memory pointer operand + val + seg-reg + (the (signed-byte 64) addr) + rex-byte + r/m + mod + x86)) + ;; Note: If flg1 is non-nil, we bail out without changing the x86 state. + ((when flg2) + (!!ms-fresh :x86-operand-to-reg/mem flg2)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/flags.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/flags.lisp new file mode 100644 index 000000000..cd2c1d61a --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/flags.lisp @@ -0,0 +1,188 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2024, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../decoding-and-spec-utils") + +;; ====================================================================== +;; INSTRUCTION: CMC/CLC/STC/CLD/STD +;; ====================================================================== + +(def-inst x86-cmc/clc/stc/cld/std + + ;; Op/En: NP + ;; F5: CMC (CF complemented, all other flags are unaffected) + ;; F8: CLC (CF cleared, all other flags are unaffected) + ;; F9: STC (CF set, all other flags are unaffected) + ;; FC: CLD (DF cleared, all other flags are unaffected) + ;; FD: STD (DF set, all other flags are unaffected) + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 riml32) ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* ((x86 (case opcode + (#xF5 ;; CMC + (let* ((cf (the (unsigned-byte 1) + (flgi :cf x86))) + (not-cf (if (equal cf 1) 0 1))) + (!flgi :cf not-cf x86))) + (#xF8 ;; CLC + (!flgi :cf 0 x86)) + (#xF9 ;; STC + (!flgi :cf 1 x86)) + (#xFC ;; CLD + (!flgi :df 0 x86)) + (otherwise ;; #xFD STD + (!flgi :df 1 x86)))) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: SAHF +;; ====================================================================== + +(def-inst x86-sahf + + ;; Opcode: #x9E + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 riml32) ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (((the (unsigned-byte 16) ax) (rr16 #.*rax* x86)) + ((the (unsigned-byte 8) ah) (ash ax -8)) + ((the (unsigned-byte 32) rflags) (rflags x86)) + ;; Bits 1, 3, and 5 of eflags are unaffected, with the values remaining + ;; 1, 0, and 0, respectively. + (cf (rflagsBits->cf ah)) + (pf (rflagsBits->pf ah)) + (af (rflagsBits->af ah)) + (zf (rflagsBits->zf ah)) + (sf (rflagsBits->sf ah)) + ((the (unsigned-byte 32) new-rflags) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->af + af + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + rflags)))))) + ;; Update the x86 state: + (x86 (!rflags new-rflags x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: LAHF +;; ====================================================================== + +(def-inst x86-lahf + + ;; Opcode: #x9F + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables + riml08 riml32) + ((tau-system))))) + + :returns (x86 x86p :hyp (x86p x86)) + + :prepwork + ((local + (defthm unsigned-byte-p-8-of-rflagsBits-for-lahf + (< (rflagsbits cf 1 pf 0 af 0 zf sf 0 0 0 0 0 0 0 0 0 0 0 0 0 0) + 256) + :hints (("Goal" :in-theory (e/d* (rflagsbits + bitops::ihsext-inductions + bitops::ihsext-recursive-redefs) + ())))))) + + :body + + (b* (((the (unsigned-byte 32) rflags) (rflags x86)) + (cf (rflagsBits->cf rflags)) + (pf (rflagsBits->pf rflags)) + (af (rflagsBits->af rflags)) + (zf (rflagsBits->zf rflags)) + (sf (rflagsBits->sf rflags)) + + ((the (unsigned-byte 8) new-ah) + (!rflagsBits->cf + cf + (!rflagsBits->res1 + 1 + (!rflagsBits->pf + pf + (!rflagsBits->res2 + 0 + (!rflagsBits->af + af + (!rflagsBits->res3 + 0 + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + 0))))))))) + + ((the (unsigned-byte 16) ax) (rr16 #.*rax* x86)) + ((the (unsigned-byte 16) new-ax) + (logior (logand #xFF ax) (ash new-ah 8))) + ;; Update the x86 state: + (x86 (wr16 #.*rax* new-ax x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/add-mul-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/add-mul-spec.lisp new file mode 100644 index 000000000..4644e6858 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/add-mul-spec.lisp @@ -0,0 +1,195 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau + +;; All events beginning with the prefix RTL:: in this book are +;; imported from the RTL/REL11 library under the directory +;; "books/rtl/rel11/lib", authored by David M. Russinoff +;; (david@russinoff.com). + +(in-package "X86ISA") +(include-book "utilities" :dir :utils) +(include-book "fp-structures" :dir :utils) +(include-book "rtl/rel11/portcullis" :dir :system) +(include-book "tools/with-supporters" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) +(local (in-theory (e/d (bitops::ash-1-removal) ()))) + +;; ====================================================================== + +(defsection floating-point-add-mul + :parents (floating-point-arithmetic-specifications) + :short "Specification of floating-point ADD, SUB, MUL, and DIV + operations" ) + +(local (xdoc::set-default-parents floating-point-add-mul)) + +;; ====================================================================== + +;; ADD, SUB, MUL, DIV: + +(define convert-arith-operation-to-rtl-op + ((operation natp)) + :inline t + :no-function t + (case operation + (#.*OP-ADD* 'RTL::ADD) + (#.*OP-SUB* 'RTL::SUB) + (#.*OP-MUL* 'RTL::MUL) + (#.*OP-DIV* 'RTL::DIV) + (otherwise + (er hard? 'convert-operation-to-rtl-op "Illegal operation ~x0." operation)))) + +(ACL2::with-supporters + (local (include-book "rtl/rel11/lib/excps" :dir :system)) + :names (rtl::formal-+ rtl::cat rtl::cat-size) + + (in-theory (e/d () (rtl::sse-binary-spec))) + + (defun sse-add/sub/mul/div (operation operand1 operand2 mxcsr exp-width frac-width) + (declare (xargs :guard (and (natp operation) + (natp operand1) (natp operand2) (n32p mxcsr) + (posp exp-width) (posp frac-width)) + :guard-hints (("Goal" + :in-theory (e/d () (unsigned-byte-p not))))) + (type (integer 0 38) operation)) + (b* (((mv result mxcsr) + (ec-call + (rtl::sse-binary-spec + (convert-arith-operation-to-rtl-op operation) + operand1 operand2 mxcsr + (list nil (1+ frac-width) exp-width)))) + ;; Hopefully, the following fixes will go away once we know + ;; rtl::sse-binary-spec returns a well-formed result and + ;; mxcsr. + (result (loghead (+ 1 exp-width frac-width) (ifix result))) + (mxcsr (loghead 32 (ifix mxcsr))) + ;; Pre-computation Exceptions + ;; Check invalid operation + ((when (and (equal (mxcsrBits->ie mxcsr) 1) + (equal (mxcsrBits->im mxcsr) 0))) + (mv 'invalid-operand-exception-is-not-masked result mxcsr)) + ;; Check divide-by-zero + ((when (and (equal (mxcsrBits->ze mxcsr) 1) + (equal (mxcsrBits->zm mxcsr) 0))) + (mv 'divide-by-zero-exception-is-not-masked result mxcsr)) + ;; Check denormal operand + ((when (and (equal (mxcsrBits->de mxcsr) 1) + (equal (mxcsrBits->dm mxcsr) 0))) + (mv 'denormal-operand-exception-is-not-masked result mxcsr)) + ;; Post-computation Exceptions + ;; Check overflow + ((when (and (equal (mxcsrBits->oe mxcsr) 1) + (equal (mxcsrBits->om mxcsr) 0))) + (mv 'overflow-exception-is-not-masked result mxcsr)) + ;; Check underflow + ((when (and (equal (mxcsrBits->ue mxcsr) 1) + (equal (mxcsrBits->um mxcsr) 0))) + (mv 'underflow-exception-is-not-masked result mxcsr)) + ;; Check precision + ((when (and (equal (mxcsrBits->pe mxcsr) 1) + (equal (mxcsrBits->pm mxcsr) 0))) + (mv 'precision-exception-is-not-masked result mxcsr))) + (mv nil result mxcsr)))) + +(defthm unsigned-byte-p-of-result-of-sse-add/sub/mul/div + (implies (and (equal fp-width (+ 1 exp-width frac-width)) + (posp exp-width) + (posp frac-width)) + (unsigned-byte-p + fp-width + (mv-nth 1 (sse-add/sub/mul/div operation op1 op2 mxcsr exp-width frac-width))))) + +(defthm unsigned-byte-p-of-mxcsr-of-sse-add/sub/mul/div + (unsigned-byte-p + 32 + (mv-nth 2 (sse-add/sub/mul/div operation op1 op2 mxcsr exp-width frac-width))) + :rule-classes :type-prescription) + +(in-theory (disable sse-add/sub/mul/div)) + +;; Single-Precision Operations: + +(define sp-sse-add/sub/mul/div + ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 32)) + (op2 :type (unsigned-byte 32)) + (mxcsr :type (unsigned-byte 32))) + (sse-add/sub/mul/div operation op1 op2 mxcsr #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH*) + + /// + (defthm-unsigned-byte-p n32p-result-sp-sse-add/sub/mul/div + :bound 32 + :concl (mv-nth 1 (sp-sse-add/sub/mul/div operation op1 op2 mxcsr)) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-flags-sp-sse-add/sub/mul/div + :bound 32 + :concl (mv-nth 2 (sp-sse-add/sub/mul/div operation op1 op2 mxcsr)) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; Double-Precision Operations: + +(define dp-sse-add/sub/mul/div + ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 64)) + (op2 :type (unsigned-byte 64)) + (mxcsr :type (unsigned-byte 32))) + (sse-add/sub/mul/div operation op1 op2 mxcsr #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH*) + + /// + (defthm-unsigned-byte-p n64p-result-dp-sse-add/sub/mul/div + :bound 64 + :concl (mv-nth 1 (dp-sse-add/sub/mul/div operation op1 op2 mxcsr)) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-flags-dp-sse-add/sub/mul/div + :bound 32 + :concl (mv-nth 2 (dp-sse-add/sub/mul/div operation op1 op2 mxcsr)) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arith-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arith-spec.lisp new file mode 100644 index 000000000..a34b57674 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arith-spec.lisp @@ -0,0 +1,318 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau + +(in-package "X86ISA") +(include-book "base") +(include-book "add-mul-spec") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) +(local (in-theory (e/d (bitops::ash-1-removal) ()))) + +;; ====================================================================== + +(defsection floating-point-arithmetic-specifications + :parents (floating-point-specifications) + :short "Specification of binary floating-point arithmetic operations + like MAX, MIN, ADD, SUB, MUL, and DIV" ) + +(local (xdoc::set-default-parents floating-point-arithmetic-specifications)) + +;; ====================================================================== + +;; Specifications of FP MAX and MIN: + +(define sse-max/min-special (kind1 + (sign1 :type (unsigned-byte 1)) + (exp1 natp) + (implicit1 :type (unsigned-byte 1)) + (frac1 natp) + kind2 + (sign2 :type (unsigned-byte 1)) + (exp2 natp) + (implicit2 :type (unsigned-byte 1)) + (frac2 natp) + (operation :type (integer 0 38))) + :long "

This function checks whether the operands are SNaN or + QNaN. If at least one of them is NaN or both of them are zeros, then + it returns the second operand. It also handles infinities.

+ +

Return values: (mv flag sign exp implicit frac + invalid).

" + (cond + ((or (eq kind1 'snan) (eq kind1 'qnan) (eq kind1 'indef) + (eq kind2 'snan) (eq kind2 'qnan) (eq kind2 'indef)) + (mv t sign2 exp2 implicit2 frac2 t)) + ((and (eq kind1 'zero) (eq kind2 'zero)) + (mv t sign2 exp2 implicit2 frac2 nil)) + ((eq kind1 'inf) + (if (or (and (int= operation #.*OP-MAX*) (int= sign1 0)) + (and (int= operation #.*OP-MIN*) (int= sign1 1))) + (mv t sign1 exp1 implicit1 frac1 nil) + (mv t sign2 exp2 implicit2 frac2 nil))) + ((eq kind2 'inf) + (if (or (and (int= operation #.*OP-MAX*) (int= sign2 0)) + (and (int= operation #.*OP-MIN*) (int= sign2 1))) + (mv t sign2 exp2 implicit2 frac2 nil) + (mv t sign1 exp1 implicit1 frac1 nil))) + (t (mv nil 0 0 0 0 nil))) + /// + + (defthm integerp-sse-max/min-special-1 + (implies (and (integerp sign1) (integerp sign2)) + (integerp (mv-nth 1 (sse-max/min-special + kind1 sign1 exp1 implicit1 frac1 + kind2 sign2 exp2 implicit2 frac2 + operation)))) + :rule-classes :type-prescription) + + (defthm integerp-sse-max/min-special-2 + (implies (and (integerp exp1) (integerp exp2)) + (integerp (mv-nth 2 (sse-max/min-special + kind1 sign1 exp1 implicit1 frac1 + kind2 sign2 exp2 implicit2 frac2 + operation)))) + :rule-classes :type-prescription) + + (defthm integerp-sse-max/min-special-3 + (implies (and (integerp implicit1) (integerp implicit2)) + (integerp (mv-nth 3 (sse-max/min-special + kind1 sign1 exp1 implicit1 frac1 + kind2 sign2 exp2 implicit2 frac2 + operation)))) + :rule-classes :type-prescription) + + (defthm integerp-sse-max/min-special-4 + (implies (and (integerp frac1) (integerp frac2)) + (integerp (mv-nth 4 (sse-max/min-special + kind1 sign1 exp1 implicit1 frac1 + kind2 sign2 exp2 implicit2 frac2 + operation)))) + :rule-classes :type-prescription)) + +(define sse-max/min-sign (rat rat1 sign1 sign2) + :guard (and (rationalp rat) + (rationalp rat1) + (integerp sign1) + (integerp sign2)) + :inline t + :no-function t + (if (eql rat rat1) sign1 sign2) + /// + + (defthm integerp-sse-max/min-sign + (implies (forced-and (integerp sign1) + (integerp sign2)) + (integerp (sse-max/min-sign rat rat1 sign1 sign2))) + :rule-classes :type-prescription)) + +(define sse-max/min ((operation :type (integer 0 38)) + (op1 natp) + (op2 natp) + (mxcsr :type (unsigned-byte 32)) + (exp-width posp) + (frac-width posp)) + + (b* ((mxcsr (mbe :logic (loghead 32 mxcsr) + :exec mxcsr)) + ((mv kind1 sign1 exp1 implicit1 frac1) + (fp-decode op1 exp-width frac-width)) + ((mv kind2 sign2 exp2 implicit2 frac2) + (fp-decode op2 exp-width frac-width)) + (daz (logbitp #.*mxcsr-daz* mxcsr)) + ((mv kind1 exp1 frac1) + (sse-daz kind1 exp1 frac1 daz)) + ((mv kind2 exp2 frac2) + (sse-daz kind2 exp2 frac2 daz)) + ((mv special-ok sign exp & frac invalid) + (sse-max/min-special kind1 sign1 exp1 implicit1 frac1 + kind2 sign2 exp2 implicit2 frac2 + operation)) + + ;; Check invalid operation + (mxcsr (if invalid (!mxcsrBits->ie 1 mxcsr) mxcsr)) + (im (logbitp #.*mxcsr-im* mxcsr)) + ((when (and invalid (not im))) + (mv 'invalid-operand-exception-is-not-masked 0 mxcsr)) + + ;; Check denormal operand + (de (denormal-exception kind1 kind2)) + (mxcsr (if de (!mxcsrBits->de 1 mxcsr) mxcsr)) + (dm (logbitp #.*mxcsr-dm* mxcsr)) + ((when (and de (not dm))) + (mv 'denormal-operand-exception-is-not-masked 0 mxcsr))) + + (if special-ok + (mv nil + (fp-encode-integer sign exp frac exp-width frac-width) + mxcsr) + (b* ((bias (nfix (ec-call (RTL::bias (list nil (1+ frac-width) exp-width))))) + (rat1 (fp-to-rat sign1 exp1 frac1 bias exp-width frac-width)) + (rat2 (fp-to-rat sign2 exp2 frac2 bias exp-width frac-width)) + (rat (case operation + (#.*OP-MAX* (if (> rat1 rat2) rat1 rat2)) + (#.*OP-MIN* (if (< rat1 rat2) rat1 rat2)) + ;; Should never be reached. + (otherwise 0))) + + (sign (sse-max/min-sign rat rat1 sign1 sign2)) + + (fp-result + (rat-to-fp rat sign + nil nil nil 0 ;; rc will not be used here. + ;; I just put a dummy value 0. + exp-width frac-width))) + + (mv nil fp-result mxcsr)))) + /// + + (defthm integerp-result-sse-max/min + (integerp + (mv-nth 1 (sse-max/min operation op1 op2 mxcsr exp-width frac-width))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p n32p-mxcsr-sse-max/min + :bound 32 + :concl (mv-nth 2 (sse-max/min operation op1 op2 mxcsr exp-width frac-width)) + :hints (("Goal" :in-theory (e/d* (unsigned-byte-p-when-mxcsrbits-p) (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; Single-Precision Operations: + +(define sp-sse-max/min ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 32)) + (op2 :type (unsigned-byte 32)) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-max/min operation op1 op2 mxcsr + #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH*)) + (result (n32 result)) + (mxcsr (mbe :logic (n32 mxcsr) + :exec mxcsr))) + (mv flg result mxcsr)) + /// + + (defthm-unsigned-byte-p n32p-result-sp-sse-max/min + :bound 32 + :concl (mv-nth 1 (sp-sse-max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-sp-sse-max/min + :bound 32 + :concl (mv-nth 2 (sp-sse-max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t)) + +;; Double-Precision Operations: + +(define dp-sse-max/min ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 64)) + (op2 :type (unsigned-byte 64)) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-max/min operation op1 op2 mxcsr + #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH*)) + (result (n64 result)) + (mxcsr (mbe :logic (n32 mxcsr) + :exec mxcsr))) + (mv flg result mxcsr)) + /// + + (defthm-unsigned-byte-p n64p-result-dp-sse-max/min + :bound 64 + :concl (mv-nth 1 (dp-sse-max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-dp-sse-max/min + :bound 32 + :concl (mv-nth 2 (dp-sse-max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t)) + +;; ====================================================================== + +;; Top-level Single and Double Precision Arithmetic Operations: + +(define sp-sse-add/sub/mul/div/max/min ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 32)) + (op2 :type (unsigned-byte 32)) + (mxcsr :type (unsigned-byte 32))) + (if (or (int= operation #.*OP-MAX*) (int= operation #.*OP-MIN*)) + (sp-sse-max/min operation op1 op2 mxcsr) + (sp-sse-add/sub/mul/div operation op1 op2 mxcsr)) + + /// + + (defthm-unsigned-byte-p n32p-result-sp-sse-add/sub/mul/div/max/min + :bound 32 + :concl (mv-nth 1 (sp-sse-add/sub/mul/div/max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-sp-sse-add/sub/mul/div/max/min + :bound 32 + :concl (mv-nth 2 (sp-sse-add/sub/mul/div/max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t)) + +(define dp-sse-add/sub/mul/div/max/min ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 64)) + (op2 :type (unsigned-byte 64)) + (mxcsr :type (unsigned-byte 32))) + (if (or (int= operation #.*OP-MAX*) (int= operation #.*OP-MIN*)) + (dp-sse-max/min operation op1 op2 mxcsr) + (dp-sse-add/sub/mul/div operation op1 op2 mxcsr)) + + /// + + (defthm-unsigned-byte-p n64p-result-dp-sse-add/sub/mul/div/max/min + :bound 64 + :concl (mv-nth 1 (dp-sse-add/sub/mul/div/max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-dp-sse-add/sub/mul/div/max/min + :bound 32 + :concl (mv-nth 2 (dp-sse-add/sub/mul/div/max/min operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arithmetic.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arithmetic.lisp new file mode 100644 index 000000000..0a5678cb5 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/arithmetic.lisp @@ -0,0 +1,721 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../../decoding-and-spec-utils") +(include-book "arith-spec") +(include-book "sqrt-spec") +(include-book "centaur/bitops/merge" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +; ============================================================================= +; INSTRUCTION: SSE/SSE2 Arithmetic Instructions +; ============================================================================= + +(def-inst x86-adds?/subs?/muls?/divs?/maxs?/mins?-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Add/Sub/Mul/Div/Max/Min scalar single/double precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ F3 0F 58: ADDSS xmm1, xmm2/m32
+ F3 0F 59: MULSS xmm1, xmm2/m32
+ F3 0F 5C: SUBSS xmm1, xmm2/m32
+ F3 0F 5D: MINSS xmm1, xmm2/m32
+ F3 0F 5E: DIVSS xmm1, xmm2/m32
+ F3 0F 5F: MAXSS xmm1, xmm2/m32
+ + F2 0F 58: ADDSD xmm1, xmm2/m64
+ F2 0F 59: MULSD xmm1, xmm2/m64
+ F2 0F 5C: SUBSD xmm1, xmm2/m64
+ F2 0F 5D: MINSD xmm1, xmm2/m64
+ F2 0F 5E: DIVSD xmm1, xmm2/m64
+ F2 0F 5F: MAXSD xmm1, xmm2/m64
" + + :operation t + + :sp/dp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) operand-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + (xmm (xmmi-size operand-size xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 3 + t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg1 result (the (unsigned-byte 32) mxcsr)) + (if (equal sp/dp #.*OP-DP*) + (dp-sse-add/sub/mul/div/max/min operation xmm xmm/mem (mxcsr x86)) + (sp-sse-add/sub/mul/div/max/min operation xmm xmm/mem (mxcsr x86)))) + + ((when flg1) + (if (equal sp/dp #.*OP-DP*) + (!!fault-fresh :fp-exception :dp-sse-add/sub/mul/div/max/min flg1) + (!!fault-fresh :fp-exception :sp-sse-add/sub/mul/div/max/min flg1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size operand-size xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-addps/subps/mulps/divps/maxps/minps-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Add/Sub/Mul/Div/Max/Min packed single-precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 0F 58: ADDPS xmm1, xmm2/m128
+ 0F 5C: SUBPS xmm1, xmm2/m128
+ 0F 59: MULPS xmm1, xmm2/m128
+ 0F 5E: DIVPS xmm1, xmm2/m128
+ 0F 5F: MAXPS xmm1, xmm2/m128
+ 0F 5D: MINPS xmm1, xmm2/m128
" + + :operation t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 2 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size+1*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (xmm0 (mbe :logic (part-select xmm :low 0 :high 31) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF xmm)))) + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 31) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF xmm/mem)))) + + (xmm1 (mbe :logic (part-select xmm :low 32 :high 63) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF (ash xmm -32))))) + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 32 :high 63) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF (ash xmm/mem -32))))) + + (xmm2 (mbe :logic (part-select xmm :low 64 :high 95) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF (ash xmm -64))))) + (xmm/mem2 (mbe :logic (part-select xmm/mem :low 64 :high 95) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF (ash xmm/mem -64))))) + + (xmm3 (mbe :logic (part-select xmm :low 96 :high 127) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF (ash xmm -96))))) + (xmm/mem3 (mbe :logic (part-select xmm/mem :low 96 :high 127) + :exec (the (unsigned-byte 32) (logand #uxFFFF_FFFF (ash xmm/mem -96))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + ((mv flg1 + (the (unsigned-byte 32) result0) + (the (unsigned-byte 32) mxcsr0)) + (sp-sse-add/sub/mul/div/max/min operation xmm0 xmm/mem0 mxcsr)) + + ((when flg1) + (!!ms-fresh :sp-sse-add/sub/mul/div/max/min flg1)) + + ((mv flg2 + (the (unsigned-byte 32) result1) + (the (unsigned-byte 32) mxcsr1)) + (sp-sse-add/sub/mul/div/max/min operation xmm1 xmm/mem1 mxcsr)) + + ((when flg2) + (!!ms-fresh :sp-sse-add/sub/mul/div/max/min flg2)) + + ((mv flg3 + (the (unsigned-byte 32) result2) + (the (unsigned-byte 32) mxcsr2)) + (sp-sse-add/sub/mul/div/max/min operation xmm2 xmm/mem2 mxcsr)) + + ((when flg3) + (!!ms-fresh :sp-sse-add/sub/mul/div/max/min flg3)) + + ((mv flg4 + (the (unsigned-byte 32) result3) + (the (unsigned-byte 32) mxcsr3)) + (sp-sse-add/sub/mul/div/max/min operation xmm3 xmm/mem3 mxcsr)) + + ((when flg4) + (!!ms-fresh :sp-sse-add/sub/mul/div/max/min flg4)) + + (result (merge-4-u32s result3 result2 result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1 mxcsr2 mxcsr3))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-addpd/subpd/mulpd/divpd/maxpd/minpd-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Add/Sub/Mul/Div/Max/Min packed double-precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 66 0F 58: ADDPD xmm1, xmm2/m128
+ 66 0F 59: MULPD xmm1, xmm2/m128
+ 66 0F 5C: SUBPD xmm1, xmm2/m128
+ 66 0F 5D: MINPD xmm1, xmm2/m128
+ 66 0F 5E: DIVPD xmm1, xmm2/m128
+ 66 0F 5F: MAXPD xmm1, xmm2/m128
" + + :operation t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 2 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (xmm0 (mbe :logic (part-select xmm :low 0 :high 63) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF xmm)))) + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 63) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF xmm/mem)))) + + (xmm1 (mbe :logic (part-select xmm :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF (ash xmm -64))))) + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF (ash xmm/mem -64))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + ((mv flg1 + (the (unsigned-byte 64) result0) + (the (unsigned-byte 32) mxcsr0)) + (dp-sse-add/sub/mul/div/max/min operation xmm0 xmm/mem0 mxcsr)) + + ((when flg1) + (!!ms-fresh :dp-sse-add/sub/mul/div/max/min flg1)) + + ((mv flg2 + (the (unsigned-byte 64) result1) + (the (unsigned-byte 32) mxcsr1)) + (dp-sse-add/sub/mul/div/max/min operation xmm1 xmm/mem1 mxcsr)) + + ((when flg2) + (!!ms-fresh :dp-sse-add/sub/mul/div/max/min flg2)) + + (result (merge-2-u64s result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== + +(def-inst x86-sqrts?-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Square root of scalar single/double precision floating-point value" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ F3 0F 51: SQRTSS xmm1, xmm2/m32
+ F2 0F 51: SQRTSD xmm1, xmm2/m64
" + + :sp/dp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) operand-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 3 + t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg1 result (the (unsigned-byte 32) mxcsr)) + (if (equal sp/dp #.*OP-DP*) + (dp-sse-sqrt xmm/mem (mxcsr x86)) + (sp-sse-sqrt xmm/mem (mxcsr x86)))) + + ((when flg1) + (if (equal sp/dp #.*OP-DP*) + (!!ms-fresh :dp-sse-sqrt flg1) + (!!ms-fresh :sp-sse-sqrt flg1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size operand-size xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-sqrtps-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Square roots of packed single-precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 0F 51: SQRTPS xmm1, xmm2/m128
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 2 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 31) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF xmm/mem)))) + + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 32 :high 63) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm/mem -32))))) + + (xmm/mem2 (mbe :logic (part-select xmm/mem :low 64 :high 95) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm/mem -64))))) + + (xmm/mem3 (mbe :logic (part-select xmm/mem :low 96 :high 127) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm/mem -96))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + ((mv flg1 + (the (unsigned-byte 32) result0) + (the (unsigned-byte 32) mxcsr0)) + (sp-sse-sqrt xmm/mem0 mxcsr)) + + ((when flg1) + (!!ms-fresh :sp-sse-sqrt flg1)) + + ((mv flg2 + (the (unsigned-byte 32) result1) + (the (unsigned-byte 32) mxcsr1)) + (sp-sse-sqrt xmm/mem1 mxcsr)) + + ((when flg2) + (!!ms-fresh :sp-sse-sqrt flg2)) + + ((mv flg3 + (the (unsigned-byte 32) result2) + (the (unsigned-byte 32) mxcsr2)) + (sp-sse-sqrt xmm/mem2 mxcsr)) + + ((when flg3) + (!!ms-fresh :sp-sse-sqrt flg3)) + + ((mv flg4 + (the (unsigned-byte 32) result3) + (the (unsigned-byte 32) mxcsr3)) + (sp-sse-sqrt xmm/mem3 mxcsr)) + + ((when flg4) + (!!ms-fresh :sp-sse-sqrt flg4)) + + (result (merge-4-u32s result3 result2 result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1 mxcsr2 mxcsr3))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-sqrtpd-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Square roots packed double-precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 66 0F 51: SQRTPD xmm1, xmm2/m128
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 2 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 63) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF xmm/mem)))) + + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF (ash xmm/mem -64))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + ((mv flg1 + (the (unsigned-byte 64) result0) + (the (unsigned-byte 32) mxcsr0)) + (dp-sse-sqrt xmm/mem0 mxcsr)) + + ((when flg1) + (!!ms-fresh :dp-sse-sqrt flg1)) + + ((mv flg2 + (the (unsigned-byte 64) result1) + (the (unsigned-byte 32) mxcsr1)) + (dp-sse-sqrt xmm/mem1 mxcsr)) + + ((when flg2) + (!!ms-fresh :dp-sse-sqrt flg2)) + + (result (merge-2-u64s result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/base.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/base.lisp new file mode 100644 index 000000000..7b4d69638 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/base.lisp @@ -0,0 +1,407 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau +; Contributing Author(s): +; Alessandro Coglio + +;; All events beginning with the prefix RTL:: in this book are +;; imported from the RTL/REL11 library under the directory +;; "books/rtl/rel11/lib", authored by David M. Russinoff +;; (david@russinoff.com). + +(in-package "X86ISA") +(include-book "utilities" :dir :utils) +(include-book "fp-structures" :dir :utils) +(include-book "rtl/rel11/portcullis" :dir :system) +(include-book "tools/with-supporters" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) +(local (in-theory (e/d (bitops::ash-1-removal) ()))) + +;; ====================================================================== + +(defsection floating-point-specifications + :parents (instruction-semantic-functions) + :short "Misc. utilities for the specification of floating-point operations" + ) + +(defsection basic-floating-point-utilities + :parents (floating-point-specifications) + ) + +(local (xdoc::set-default-parents basic-floating-point-utilities)) + +;; ====================================================================== + +(defmacro fp-max-exp (exp-width) `(1- (ash 1 ,exp-width))) +(defmacro fp-inf-exp (exp-width) `(fp-max-exp ,exp-width)) +(defmacro fp-max-finite-exp (exp-width) `(- (ash 1 ,exp-width) 2)) +(defmacro fp-inf-frac () 0) +(defmacro fp-max-frac (frac-width) `(1- (ash 1 ,frac-width))) + +(defmacro rc-cases (&key rn rd ru rz other) + `(case RC + (,*RC-RN* ,rn) + (,*RC-RD* ,rd) + (,*RC-RU* ,ru) + (,*RC-RZ* ,rz) + (otherwise ,other))) + +(define fp-round-overflow-generic ((RC integerp) + (sign integerp) + (exp-width posp) + (frac-width posp)) + :short "Returns rounded sign, exponent, and fraction in case of overflow." + (RC-cases + :rn (mv sign (fp-inf-exp exp-width) (fp-inf-frac)) + :rd (if (eql 0 sign) + (mv sign (fp-max-finite-exp exp-width) (fp-max-frac frac-width)) + (mv sign (fp-inf-exp exp-width) (fp-inf-frac))) + :ru (if (eql 0 sign) + (mv sign (fp-inf-exp exp-width) (fp-inf-frac)) + (mv sign (fp-max-finite-exp exp-width) (fp-max-frac frac-width))) + :rz (mv sign (fp-max-finite-exp exp-width) (fp-max-frac frac-width)) + ;; Should never get here. + :other (mv 0 0 0)) + /// + + (defthm integerp-fp-round-overflow-generic-0 + (implies (integerp sign) + (integerp (mv-nth 0 (fp-round-overflow-generic rc sign exp-width frac-width)))) + :rule-classes :type-prescription) + + (defthm integerp-fp-round-overflow-generic-1 + (integerp (mv-nth 1 (fp-round-overflow-generic rc sign exp-width frac-width))) + :rule-classes :type-prescription) + + (defthm integerp-fp-round-overflow-generic-2 + (integerp (mv-nth 2 (fp-round-overflow-generic rc sign exp-width frac-width))) + :rule-classes :type-prescription)) + +;; ====================================================================== + +;; FP-ENCODE-INTEGER: + +(define fp-encode-integer ((sign integerp) + (exp integerp) + (frac integerp) + (exp-width posp) + (frac-width posp)) + (logior frac (logior (ash exp frac-width) + (ash sign (+ exp-width frac-width)))) + + /// + + (defthm integerp-fp-encode-integer + (integerp (fp-encode-integer sign exp frac exp-width frac-width)) + :hints (("Goal" :in-theory '(fp-encode-integer (:type-prescription binary-logior)))) + :rule-classes :type-prescription)) + + +;; FP-DECODE: + +(define fp-decode ((x integerp) + (exp-width posp) + (frac-width posp)) + :long + "

This function returns: +

    +
  • One of the symbols INDEF, QNAN, SNAN, INF, ZERO, DENORMAL, or NORMAL
  • +
  • sign bit
  • +
  • exponent bits
  • +
  • implicit bit value
  • +
  • fraction bits
  • +

" + + (b* ((sign-bit-index (+ frac-width exp-width)) + (frac (part-select x :low 0 :width frac-width)) + (exp (part-select x :low frac-width :width exp-width)) + (sign (part-select x :low sign-bit-index :width 1))) + (cond ((eql exp 0) + ;; Denormal or zero + (b* ((sym (if (not (eql frac 0)) 'denormal 'zero))) + (mv sym sign exp 0 frac))) + ((eql exp (1- (ash 1 exp-width))) + ;; Infinity or NAN + (if (eql frac 0) + ;; infinity + (mv 'inf sign exp 1 frac) + ;; nan + (let ((sym (if (logbitp (1- frac-width) frac) + ;; qnan + (if (and (eql sign 1) + (eql frac (ash 1 (1- frac-width)))) + 'indef + 'qnan) + 'snan))) + (mv sym sign exp 1 frac)))) + (t (mv 'normal sign exp 1 frac)))) + + /// + + (defthm-unsigned-byte-p n01p-fp-decode-sign-bit + :bound 1 + :concl (mv-nth 1 (fp-decode x exp-width frac-width)) + :gen-type t + :gen-linear t) + + (defthm natp-exp-fp-decode + (implies (posp exp-width) + (natp (mv-nth 2 (fp-decode x exp-width frac-width)))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p exp-width-wide-exp-from-fp-decode-lemma + :hyp (posp exp-width) + :bound exp-width + :concl (mv-nth 2 (fp-decode x exp-width frac-width)) + :gen-linear t) + + (defthm-unsigned-byte-p n01p-implicit-bit-fp-decode + :bound 1 + :concl (mv-nth 3 (fp-decode x exp-width frac-width)) + :gen-type t + :gen-linear t) + + (defthm natp-frac-from-fp-decode + (implies (posp frac-width) + (natp (mv-nth 4 (fp-decode x exp-width frac-width)))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p frac-width-wide-frac-from-fp-decode-lemma + :hyp (posp frac-width) + :bound frac-width + :concl (mv-nth 4 (fp-decode x exp-width frac-width)) + :gen-type t + :gen-linear t)) + +;; ====================================================================== + +;; SSE-DAZ: + +(define sse-daz (kind exp frac daz) + (if (and daz (eq kind 'denormal)) + (mv 'zero 0 0) + (mv kind exp frac)) + /// + (defthm natp-sse-daz-1 + (implies (natp exp) + (natp (mv-nth 1 (sse-daz kind exp frac daz)))) + :rule-classes :type-prescription) + + (defthm natp-sse-daz-2 + (implies (natp frac) + (natp (mv-nth 2 (sse-daz kind exp frac daz)))) + :rule-classes :type-prescription)) + +;; ====================================================================== + +;; DENORMAL EXCEPTION: + +(define denormal-exception (kind1 kind2) + (and (not (member kind1 '(snan qnan indef))) + (not (member kind2 '(snan qnan indef))) + (or (eq kind1 'denormal) (eq kind2 'denormal)))) + +;; ====================================================================== + +;; FP-TO-RAT: + +(define fp-to-rat ((sign integerp) + (exp integerp) + (frac integerp) + (bias natp) + (exp-width posp) + (frac-width posp)) + :short "Convert the bit-vector or integer representation used by + hardware to rational for the cases of zero, denormal, and normal." + (cond + ((and (eql exp 0) (eql frac 0)) + 0) + ;; Denormal case + ((and (eql exp 0) (not (eql frac 0))) + (let ((man (* frac + (expt 2 (- frac-width))))) + (* (if (eql sign 0) 1 -1) + man + (expt 2 (- 1 bias))))) + ;; Normal case + ((and (< 0 exp) + (<= exp (fp-max-finite-exp exp-width))) + (let ((man (* (logior (ash 1 frac-width) frac) + (expt 2 (- frac-width))))) + (* (if (eql sign 0) 1 -1) + man + (expt 2 (- exp bias))))) + ;; Should never get here. + (t 0)) + /// + (defthm rationalp-fp-to-rat + (implies (integerp frac) + (rationalp (fp-to-rat sign exp frac bias exp-width frac-width))) + :rule-classes :type-prescription)) + +;; RAT-TO-FP: + +(ACL2::with-supporters + (local (include-book "rtl/rel11/lib/reps" :dir :system)) + :names (rtl::formal-+ rtl::cat-size rtl::cat) + + (defun rat-to-fp (rat sign overflow underflow flush rc + exp-width frac-width) + ;; Convert the rational to bit-vector or integer representation + ;; used by hardware. + ;; Return (mv sign exp frac) + (declare (xargs :guard (and (rationalp rat) + (integerp sign) + (booleanp overflow) + (booleanp underflow) + (booleanp flush) + (integerp rc) + (posp exp-width) + (posp frac-width)))) + (cond + ((eql rat 0) + (fp-encode-integer sign 0 0 exp-width frac-width)) + (overflow + (b* (((mv sign exp frac) + (fp-round-overflow-generic rc sign exp-width frac-width))) + (fp-encode-integer sign exp frac exp-width frac-width))) + (flush + (fp-encode-integer sign 0 0 exp-width frac-width)) + (underflow + (if (ec-call (rtl::drepp rat (list nil (1+ frac-width) exp-width))) + ;; Denormal representable + (ec-call (rtl::dencode rat (list nil (1+ frac-width) exp-width))) + ;; Not denormal representable, should never happen. + (fp-encode-integer sign 0 0 exp-width frac-width))) + ;; Denormal number + ((ec-call (rtl::drepp rat (list nil (1+ frac-width) exp-width))) + (ec-call (rtl::dencode rat (list nil (1+ frac-width) exp-width)))) + ;; Normal number + ((ec-call (rtl::nrepp rat (list nil (1+ frac-width) exp-width))) + (ec-call (rtl::nencode rat (list nil (1+ frac-width) exp-width)))) + ;; Should never get here. + (t 0)))) + +(defthm integerp-rat-to-fp + (integerp (rat-to-fp rat sign overflow underflow flush rc exp-width frac-width)) + :rule-classes :type-prescription) + +(in-theory (disable rat-to-fp)) + +;; ====================================================================== + +(define make-special-bp (kind + (nan-frac-bits integerp) + (sign integerp) + (exp-width posp) + (frac-width posp)) + ;; Returns (mv sign exp implicit frac) + (case kind + (indef (mv 1 (1- (ash 1 exp-width)) 1 (ash 1 (1- frac-width)))) + (qnan (mv sign (1- (ash 1 exp-width)) 1 + (+ (ash 1 (1- frac-width)) + nan-frac-bits))) + (snan (mv sign (1- (ash 1 exp-width)) 1 + nan-frac-bits)) + (inf (mv sign (1- (ash 1 exp-width)) 1 0)) + (zero (mv sign 0 0 0)) + ;; These two aren't particularly useful -- they're just arbitrary examples + ;; of denormal and normal, resp. + (denormal (mv 0 0 0 1)) + (otherwise (mv 0 1 1 0))) + /// + + (defthm integerp-make-special-bp-0 + (implies (integerp sign) + (integerp (mv-nth 0 (make-special-bp kind nan-frac-bits sign exp-width frac-width)))) + :rule-classes :type-prescription) + + (defthm integerp-make-special-bp-1 + (integerp (mv-nth 1 (make-special-bp kind nan-frac-bits sign exp-width frac-width))) + :rule-classes :type-prescription) + + (defthm integerp-make-special-bp-2 + (integerp (mv-nth 2 (make-special-bp kind nan-frac-bits sign exp-width frac-width))) + :rule-classes :type-prescription) + + (defthm integerp-make-special-bp-3 + (implies (integerp nan-frac-bits) + (integerp (mv-nth 3 (make-special-bp kind nan-frac-bits sign exp-width frac-width)))) + :rule-classes :type-prescription)) + +(defmacro flag-make-special-bp (kind nan-frac-bits sign invalid) + `(mv-let (sign exp explicit frac) + (make-special-bp ,kind ,nan-frac-bits ,sign exp-width frac-width) + (mv t sign exp explicit frac ,invalid))) + +;; ====================================================================== + +(define convert-rc-to-mode ((rc natp)) + :enabled t + :inline t + :no-function t + (case rc + (#.*RC-RN* 'RTL::RNE) + (#.*RC-RD* 'RTL::RDN) + (#.*RC-RU* 'RTL::RUP) + (#.*RC-RZ* 'RTL::RTZ) + (otherwise nil))) + +(ACL2::with-supporters + (local (include-book "rtl/rel11/lib/round" :dir :system)) + + (defun rat-round (x rc bias exp-width frac-width) + (declare (xargs :guard (and (rationalp x) + (natp rc) + (natp bias) + (posp exp-width) + (posp frac-width)))) + + (if (> (RTL::expo x) (- bias)) + (ec-call (rtl::rnd x (convert-rc-to-mode rc) (1+ frac-width))) + (ec-call (rtl::drnd x (convert-rc-to-mode rc) (list nil (1+ frac-width) exp-width)))))) + +(defthm rationalp-rat-round + (implies (rationalp x) + (rationalp (rat-round x rc bias exp-width frac-width))) + :rule-classes :type-prescription) + +(in-theory (disable rat-round)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cmp-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cmp-spec.lisp new file mode 100644 index 000000000..6a6fbe070 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cmp-spec.lisp @@ -0,0 +1,294 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau + +(in-package "X86ISA") +(include-book "base") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) +(local (in-theory (e/d (bitops::ash-1-removal) ()))) + +;; ====================================================================== + +(defsection floating-point-comparison-specifications + :parents (floating-point-specifications) + :short "Specification of floating-point comparison operations" + ) + +(local (xdoc::set-default-parents floating-point-comparison-specifications)) + +;; ====================================================================== + +;; Specifications of FP Comparisons: + +(define sse-cmp-special (kind1 + (sign1 :type (unsigned-byte 1)) + kind2 + (sign2 :type (unsigned-byte 1)) + (exp-width posp) + (frac-width posp) + (operation :type (integer 0 38))) + :long "

This function checks whether operands are NaN and then + returns the corresponding results. It also handles the + infinities.

+

Return values: (mv flag integer-result invalid)

" + (let ((invalid (or (eq kind1 'snan) + (eq kind2 'snan) + (and (or (eq kind1 'qnan) (eq kind1 'indef) + (eq kind2 'qnan) (eq kind2 'indef)) + (or (int= operation #.*OP-CMPLT*) + (int= operation #.*OP-CMPLE*) + (int= operation #.*OP-CMPNLT*) + (int= operation #.*OP-CMPNLE*) + (int= operation #.*OP-COMI*)))))) + (cond + ((or (eq kind1 'snan) (eq kind1 'qnan) (eq kind1 'indef) + (eq kind2 'snan) (eq kind2 'qnan) (eq kind2 'indef)) + (cond ((or (int= operation #.*OP-CMPUNORD*) + (int= operation #.*OP-CMPNEQ*) + (int= operation #.*OP-CMPNLT*) + (int= operation #.*OP-CMPNLE*)) + ;; Return the mask of all 1s. + (mv t + (1- (ash 1 (+ 1 exp-width frac-width))) + invalid)) + ((or (int= operation #.*OP-COMI*) + (int= operation #.*OP-UCOMI*)) + ;; Return a particular integer result for this case (here we + ;; return 7). We then use this result to recognize the unordered + ;; relationship and set the corresponding flags in the EFLAGS + ;; register. + (mv t 7 invalid)) + ;; Return the mask of all 0s. + (t (mv t 0 invalid)))) + ((or (eq kind1 'inf) (eq kind2 'inf)) + ;; Convert -inf to -1, + ;; +inf to 1, + ;; finite to 0. + ;; The purpose of this conversion is used for comparison between two + ;; operands in which at least one of them is infinity. + (b* ((rat1 (if (eq kind1 'inf) + (if (int= sign1 0) 1 -1) + 0)) + (rat2 (if (eq kind2 'inf) + (if (int= sign2 0) 1 -1) + 0)) + (cmp-result + (case operation + (#.*OP-CMPEQ* (= rat1 rat2)) + (#.*OP-CMPLT* (< rat1 rat2)) + (#.*OP-CMPLE* (<= rat1 rat2)) + (#.*OP-CMPUNORD* nil) ;; Neither source operand is a NaN. + (#.*OP-CMPNEQ* (not (= rat1 rat2))) + (#.*OP-CMPNLT* (not (< rat1 rat2))) + (#.*OP-CMPNLE* (not (<= rat1 rat2))) + (#.*OP-CMPORD* t) ;; Neither source operand is a NaN. + (otherwise nil))) + + (result + (if (or (int= operation #.*OP-COMI*) + (int= operation #.*OP-UCOMI*)) + ;; Compare rat1 with rat2. + ;; Return 0 standing for rat1 > rat2, + ;; 1 standing for rat1 < rat2, + ;; 4 standing for ra1 = rat2. + ;; Of course, we can choose any other values to return. + ;; The only requirement is that they must be distinct and + ;; different from the value returned for the case of + ;; unordered relationship, which is 7. + (cond ((> rat1 rat2) 0) + ((< rat1 rat2) 1) + (t 4)) + (if cmp-result + ;; Return the mask of all 1s. + (1- (ash 1 (+ 1 exp-width frac-width))) + ;; Return the mask of all 0s. + 0)))) + (mv t result invalid))) + (t (mv nil 0 invalid)))) + + /// + + (defthm integerp-sse-cmp-special-1 + (integerp + (mv-nth + 1 + (sse-cmp-special kind1 sign1 kind2 sign2 exp-width frac-width operation))) + :rule-classes :type-prescription)) + +(define sse-cmp ((operation :type (integer 0 38)) + (op1 natp) + (op2 natp) + (mxcsr :type (unsigned-byte 32)) + (exp-width posp) + (frac-width posp)) + :prepwork ((local (in-theory (e/d* () + (bitops::logand-with-negated-bitmask +; Matt K. mod April 2016 for addition of type-set bit for the set {1}. + (:t BOOL->BIT)))))) + (b* ((mxcsr (mbe :logic (loghead 32 mxcsr) + :exec mxcsr)) + ((mv kind1 sign1 exp1 ?implicit1 frac1) + (fp-decode op1 exp-width frac-width)) + ((mv kind2 sign2 exp2 ?implicit2 frac2) + (fp-decode op2 exp-width frac-width)) + (daz (equal (mxcsrBits->daz mxcsr) 1)) + ((mv kind1 exp1 frac1) + (sse-daz kind1 exp1 frac1 daz)) + ((mv kind2 exp2 frac2) + (sse-daz kind2 exp2 frac2 daz)) + ((mv special-ok result invalid) + (sse-cmp-special kind1 sign1 kind2 sign2 + exp-width frac-width operation)) + + ;; Check invalid operation + (mxcsr (if invalid (!mxcsrBits->ie 1 mxcsr) mxcsr)) + (im (equal (mxcsrBits->im mxcsr) 1)) + ((when (and invalid (not im))) + (mv 'invalid-operand-exception-is-not-masked 0 mxcsr)) + + ;; Check denormal operand + (de (denormal-exception kind1 kind2)) + (mxcsr (if de (!mxcsrBits->de 1 mxcsr) mxcsr)) + (dm (equal (mxcsrBits->dm mxcsr) 1)) + ((when (and de (not dm))) + (mv 'denormal-operand-exception-is-not-masked 0 mxcsr))) + + (if special-ok + (mv nil result mxcsr) + (b* ((bias (nfix (ec-call (RTL::bias (list nil (1+ frac-width) exp-width))))) + (rat1 (fp-to-rat sign1 exp1 frac1 bias exp-width frac-width)) + (rat2 (fp-to-rat sign2 exp2 frac2 bias exp-width frac-width)) + (cmp-result + (case operation + (#.*OP-CMPEQ* (= rat1 rat2)) + (#.*OP-CMPLT* (< rat1 rat2)) + (#.*OP-CMPLE* (<= rat1 rat2)) + (#.*OP-CMPUNORD* nil) ;; Neither source operand is a NaN. + (#.*OP-CMPNEQ* (not (= rat1 rat2))) + (#.*OP-CMPNLT* (not (< rat1 rat2))) + (#.*OP-CMPNLE* (not (<= rat1 rat2))) + (#.*OP-CMPORD* t) ;; Neither source operand is a NaN. + (otherwise nil))) + + (result + (if (or (int= operation #.*OP-COMI*) + (int= operation #.*OP-UCOMI*)) + ;; Compare rat1 with rat2. + ;; Return 0 standing for rat1 > rat2, + ;; 1 standing for rat1 < rat2, + ;; 4 standing for ra1 = rat2. + ;; Of course, we can choose any other values to return. + ;; The only requirement is that they must be distinct and + ;; different from the value returned by the function + ;; sse-cmp-special for the case of unordered relationship, + ;; which is 7. + (cond ((> rat1 rat2) 0) + ((< rat1 rat2) 1) + (t 4)) + (if cmp-result + ;; Return all 1s. + (1- (ash 1 (+ 1 exp-width frac-width))) + ;; Return all 0s. + 0)))) + + (mv nil result mxcsr)))) + /// + + (defthm integerp-result-sse-cmp + (integerp (mv-nth 1 (sse-cmp operation op1 op2 mxcsr exp-width frac-width))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p n32p-mxcsr-sse-cmp + :bound 32 + :concl (mv-nth 2 (sse-cmp operation op1 op2 mxcsr exp-width frac-width)) + :hints (("Goal" :in-theory (e/d* (unsigned-byte-p-when-mxcsrbits-p) (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; ====================================================================== + +;; Single-Precision: + +(define sp-sse-cmp ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 32)) + (op2 :type (unsigned-byte 32)) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-cmp operation op1 op2 mxcsr #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH*)) + (result (n32 result))) + (mv flg result mxcsr)) + /// + (defthm-unsigned-byte-p n32p-result-sp-sse-cmp + :bound 32 + :concl (mv-nth 1 (sp-sse-cmp operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-sp-sse-cmp + :bound 32 + :concl (mv-nth 2 (sp-sse-cmp operation op1 op2 mxcsr)) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; Double-Precision: + +(define dp-sse-cmp ((operation :type (integer 0 38)) + (op1 :type (unsigned-byte 64)) + (op2 :type (unsigned-byte 64)) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-cmp operation op1 op2 mxcsr #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH*)) + (result (n64 result))) + (mv flg result mxcsr)) + /// + (defthm-unsigned-byte-p n64p-result-dp-sse-cmp + :bound 64 + :concl (mv-nth 1 (dp-sse-cmp operation op1 op2 mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-dp-sse-cmp + :bound 32 + :concl (mv-nth 2 (dp-sse-cmp operation op1 op2 mxcsr)) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/convert.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/convert.lisp new file mode 100644 index 000000000..939d7bc4e --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/convert.lisp @@ -0,0 +1,537 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../../decoding-and-spec-utils") +(include-book "cvt-spec") +(include-book "centaur/bitops/merge" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +; ============================================================================= +; INSTRUCTION: SSE/SSE2 Conversion Instructions +; ============================================================================= + +(def-inst x86-cvts?2si/cvtts?2si-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Convert scalar single/double precision FP value to integer" + + :long + "

Op/En = RM: \[OP REG, XMM/M\]

+ F3 0F 2C: CVTTSS2SI r32, xmm2/m32
+ F3 REX.W 0F 2C: CVTTSS2SI r64, xmm2/m32
+ F3 0F 2D: CVTSS2SI r32, xmm2/m32
+ F3 REX.W 0F 2D: CVTSS2SI r64, xmm2/m32
+ + F2 0F 2C: CVTTSD2SI r32, xmm2/m64
+ F2 REX.W 0F 2C: CVTTSD2SI r64, xmm2/m64
+ F2 0F 2D: CVTSD2SI r32, xmm2/m64
+ F2 REX.W 0F 2D: CVTSD2SI r64, xmm2/m64
" + + :sp/dp t + + :trunc t + + :guard-hints (("Goal" :in-theory (enable reg-index + sp-sse-cvt-fp-to-int + dp-sse-cvt-fp-to-int))) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) reg-size) + (if (logbitp #.*w* rex-byte) 8 4)) + + ((the (integer 4 8) xmm/mem-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + + ((the (unsigned-byte 4) rgf-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 3 + t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + xmm/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg1 result (the (unsigned-byte 32) mxcsr)) + (if (equal sp/dp #.*OP-DP*) + (dp-sse-cvt-fp-to-int reg-size xmm/mem (mxcsr x86) trunc) + (sp-sse-cvt-fp-to-int reg-size xmm/mem (mxcsr x86) trunc))) + + ((when flg1) + (if (equal sp/dp #.*OP-DP*) + (!!ms-fresh :dp-sse-cvt-fp-to-int flg1) + (!!ms-fresh :sp-sse-cvt-fp-to-int flg1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!rgfi-size reg-size rgf-index result rex-byte x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-cvtsi2s?-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Convert integer to scalar single/double precision FP value" + + :long + "

Op/En = RM: \[OP XMM, R/M\]

+ F3 0F 2A: CVTSI2SS xmm, r/m32
+ F3 REX.W 0F 2A: CVTSI2SS xmm, r/m64
+ + F2 0F 2A: CVTSI2SD xmm, r/m32
+ F2 REX.W 0F 2A: CVTSI2SD xmm, r/m64
" + + :sp/dp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) reg/mem-size) + (if (logbitp #.*w* rex-byte) 8 4)) + + ((the (integer 4 8) xmm-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 3 + t) + ((mv flg0 + reg/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + reg/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (reg/mem (if (int= reg/mem-size 4) + (n32-to-i32 reg/mem) + (n64-to-i64 reg/mem))) + + ((mv flg1 result (the (unsigned-byte 32) mxcsr)) + (if (equal sp/dp #.*OP-DP*) + (dp-sse-cvt-int-to-fp reg/mem (mxcsr x86)) + (sp-sse-cvt-int-to-fp reg/mem (mxcsr x86)))) + + ((when flg1) + (if (equal sp/dp #.*OP-DP*) + (!!ms-fresh :dp-sse-cvt-int-to-fp flg1) + (!!ms-fresh :sp-sse-cvt-int-to-fp flg1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size xmm-size xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-cvts?2s?-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Convert scalar single/double precision FP value to scalar + double/single FP value" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ F3 0F 5A: CVTSS2SD xmm1, xmm2/m32
+ F2 0F 5A: CVTSD2SS xmm1, xmm2/m64
" + + :dp-to-sp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) xmm-size) + (if (equal dp-to-sp #.*DP-TO-SP*) 4 8)) + + ((the (integer 4 8) xmm/mem-size) + (if (equal dp-to-sp #.*DP-TO-SP*) 8 4)) + + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 3 + t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + xmm/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg1 result (the (unsigned-byte 32) mxcsr)) + (if (equal dp-to-sp #.*DP-TO-SP*) + (sse-cvt-dp-to-sp xmm/mem (mxcsr x86)) + (sse-cvt-sp-to-dp xmm/mem (mxcsr x86)))) + + ((when flg1) + (if (equal dp-to-sp #.*DP-TO-SP*) + (!!ms-fresh :sse-cvt-dp-to-sp flg1) + (!!ms-fresh :sse-cvt-sp-to-dp flg1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size xmm-size xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-cvtps2pd-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Convert packed single-precision FP values to packed double-precision + FP values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 0F 5A: CVTPS2PD xmm1, xmm2/m64
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Note that VEX.256 version follows Exception Type 3 + ;; without #AC. We haven't implemented VEX.256 yet. + t) + ((mv flg0 + (the (unsigned-byte 64) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 8 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 31) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF xmm/mem)))) + + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 32 :high 63) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm/mem -32))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + ((mv flg1 + (the (unsigned-byte 64) result0) + (the (unsigned-byte 32) mxcsr0)) + (sse-cvt-sp-to-dp xmm/mem0 mxcsr)) + + ((when flg1) + (!!ms-fresh :sse-cvt-sp-to-dp flg1)) + + ((mv flg2 + (the (unsigned-byte 64) result1) + (the (unsigned-byte 32) mxcsr1)) + (sse-cvt-sp-to-dp xmm/mem1 mxcsr)) + + ((when flg2) + (!!ms-fresh :sse-cvt-sp-to-dp flg2)) + + (result (merge-2-u64s result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-cvtpd2ps-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Convert packed double-precision FP values to packed single-precision + FP values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 66 0F 5A: CVTPD2PS xmm1, xmm2/m128
" + + :guard-hints (("Goal" :in-theory (enable merge-2-u32s))) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 2 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 63) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF xmm/mem)))) + + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF (ash xmm/mem -64))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + ((mv flg1 + (the (unsigned-byte 32) result0) + (the (unsigned-byte 32) mxcsr0)) + (sse-cvt-dp-to-sp xmm/mem0 mxcsr)) + + ((when flg1) + (!!ms-fresh :sse-cvt-dp-to-sp flg1)) + + ((mv flg2 + (the (unsigned-byte 32) result1) + (the (unsigned-byte 32) mxcsr1)) + (sse-cvt-dp-to-sp xmm/mem1 mxcsr)) + + ((when flg2) + (!!ms-fresh :sse-cvt-dp-to-sp flg2)) + + (result (merge-2-u32s result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + ;; Bits[127:64] of the destination XMM register are zeroed. + ;; Hence, we write 8-byte result into 16-byte destination XMM register. + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cvt-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cvt-spec.lisp new file mode 100644 index 000000000..4c04f0090 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/cvt-spec.lisp @@ -0,0 +1,569 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau + +;; Specifications of FP Converts + +(in-package "X86ISA") +(include-book "base") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) +(local (in-theory (e/d (bitops::ash-1-removal) ()))) + +;; ====================================================================== + +(defsection floating-point-converts + :parents (floating-point-specifications) + :short "Specification of floating-point conversion operations" ) + +(local (xdoc::set-default-parents floating-point-converts)) + +;; ====================================================================== + +;; FP to Integer: + +(define rat-round-to-int-rn ((rat rationalp)) + :returns (r integerp :rule-classes :type-prescription) + (round rat 1)) + +(define rat-round-to-int-rd ((rat rationalp)) + :returns (r integerp :rule-classes :type-prescription) + (let ((rn (round rat 1))) + (if (> rn rat) (1- rn) rn))) + +(define rat-round-to-int-ru ((rat rationalp)) + :returns (r integerp :rule-classes :type-prescription) + (let ((rn (round rat 1))) + (if (< rn rat) (1+ rn) rn))) + +(define rat-round-to-int-rz ((rat rationalp)) + :returns (r integerp :rule-classes :type-prescription) + (truncate rat 1)) + +(define rat-round-to-int ((rat rationalp) + (rc natp)) + :inline t + :no-function t + :returns (r integerp :rule-classes :type-prescription) + (rc-cases + :rn (rat-round-to-int-rn rat) + :rd (rat-round-to-int-rd rat) + :ru (rat-round-to-int-ru rat) + :rz (rat-round-to-int-rz rat) + ;; Should never get here. + :other 0)) + +(define sse-cvt-fp-to-int-special (kind (nbytes natp)) + :short "Check whether the operand is NaN or infinity. If so, return + the integer indefinite." + ;; Return (mv flag integer-result invalid). + :returns (mv flg + (r integerp :hyp :guard :rule-classes :type-prescription) + invalid) + (let ((invalid (or (eq kind 'snan) (eq kind 'qnan) + (eq kind 'indef) (eq kind 'inf)))) + (if invalid + (mv t (ash 1 (1- (ash nbytes 3))) invalid) + (mv nil 0 invalid)))) + +(define sse-cvt-fp-to-int ((nbytes natp) + (op natp) + (mxcsr :type (unsigned-byte 32)) + (trunc booleanp) + (exp-width posp) + (frac-width posp)) + :prepwork ((local (in-theory (e/d* () (bitops::logand-with-negated-bitmask))))) + + (b* ((mxcsr (mbe :logic (loghead 32 mxcsr) + :exec mxcsr)) + ((mv kind sign exp ?implicit frac) + (fp-decode op exp-width frac-width)) + (daz (logbitp #.*mxcsr-daz* mxcsr)) + ((mv kind exp frac) + (sse-daz kind exp frac daz)) + ((mv special-ok result invalid) + (sse-cvt-fp-to-int-special kind nbytes)) + + ;; Check invalid operation + (mxcsr (if invalid (!mxcsrBits->ie 1 mxcsr) mxcsr)) + (im (equal (mxcsrBits->im mxcsr) 1)) + ((when (and invalid (not im))) + (mv 'invalid-operand-exception-is-not-masked 0 mxcsr))) + + (if special-ok + (mv nil result mxcsr) + (b* ((bias (nfix (ec-call (RTL::bias (list nil (1+ frac-width) exp-width))))) + (rat (fp-to-rat sign exp frac bias exp-width frac-width)) + (rc (mbe :logic + (part-select mxcsr :low #.*mxcsr-rc* :high (1+ #.*mxcsr-rc*)) + ;; (get-bits #.*mxcsr-rc* (1+ #.*mxcsr-rc*) mxcsr) + :exec (logand #b11 (ash mxcsr (- #.*mxcsr-rc*))))) + (rc (if trunc #b11 rc)) + (rat-to-int (rat-round-to-int rat rc)) + (nbits (ash nbytes 3)) + (min-signed-int (- (expt 2 (1- nbits)))) + (max-signed-int (1- (expt 2 (1- nbits)))) + (out-of-range (or (< rat-to-int min-signed-int) + (> rat-to-int max-signed-int))) + ;; If the converted integer is out-of-range, set IE flag. + (mxcsr (if out-of-range (!mxcsrBits->ie 1 mxcsr) mxcsr)) + ((when (and out-of-range (not im))) + (mv 'invalid-operand-exception-is-not-masked 0 mxcsr)) + ;; If out-of-range and IM is masked, return integer indefinite. + ((when out-of-range) + (mv nil (ash 1 (1- nbits)) mxcsr)) + + ;; Check precision + (pe (not (= rat-to-int rat))) + (mxcsr (if pe (!mxcsrBits->pe 1 mxcsr) mxcsr)) + (pm (equal (mxcsrBits->pm mxcsr) 1)) + ((when (and pe (not pm))) + (mv 'precision-exception-is-not-masked 0 mxcsr))) + + (mv nil rat-to-int mxcsr)))) + /// + + (defthm integerp-result-sse-cvt-fp-to-int + (implies (natp nbytes) + (integerp (mv-nth 1 (sse-cvt-fp-to-int + nbytes op mxcsr trunc exp-width frac-width)))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p n32p-mxcsr-sse-cvt-fp-to-int + :bound 32 + :concl (mv-nth 2 (sse-cvt-fp-to-int + nbytes op mxcsr trunc exp-width frac-width)) + :hints (("Goal" :in-theory (e/d* (unsigned-byte-p-when-mxcsrbits-p) (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; ====================================================================== + +;; Integerp to FP: + +(define sse-cvt-int-to-fp ((op integerp) + (mxcsr :type (unsigned-byte 32)) + (exp-width posp) + (frac-width posp)) + :prepwork + ((local (in-theory (e/d* () (unsigned-byte-p))))) + (b* ((mxcsr (mbe :logic (loghead 32 mxcsr) + :exec mxcsr)) + (rc (mbe :logic + (part-select mxcsr :low #.*mxcsr-rc* :high (1+ #.*mxcsr-rc*)) + :exec (logand #b11 (ash mxcsr (- #.*mxcsr-rc*))))) + (bias (nfix (ec-call (RTL::bias (list nil (1+ frac-width) exp-width))))) + (int-to-rat (rat-round op rc bias exp-width frac-width)) + (sign (cond ((> int-to-rat 0) 0) + ((< int-to-rat 0) 1) + (t (if (int= rc #.*rc-rd*) 1 0)))) + + ;; Check precision + (pe (not (= op int-to-rat))) + (mxcsr (if pe (!mxcsrBits->pe 1 mxcsr) mxcsr)) + (pm (equal (mxcsrBits->pm mxcsr) 1)) + ((when (and pe (not pm))) + (mv 'precision-exception-is-not-masked 0 mxcsr)) + + (fp-result + (rat-to-fp int-to-rat sign + nil nil nil rc + exp-width frac-width))) + + (mv nil fp-result mxcsr)) + /// + + (defthm integerp-result-sse-cvt-int-to-fp + (integerp (mv-nth 1 (sse-cvt-int-to-fp op mxcsr exp-width frac-width))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p n32p-mxcsr-sse-cvt-int-to-fp + :bound 32 + :concl (mv-nth 2 (sse-cvt-int-to-fp op mxcsr exp-width frac-width)) + :hints (("Goal" :in-theory (e/d* (unsigned-byte-p-when-mxcsrbits-p) (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; ====================================================================== + +;; Convert FP1 to FP2: + +(define denormalp ((rat rationalp) + (rounded-expo integerp) + (bias natp)) + (let ((expo (RTL::expo rat)) + (minus-bias (- bias))) + (or (<= rounded-expo minus-bias) + (and (= rounded-expo 0) + (<= expo minus-bias)))) + /// + + (defthm booleanp-denormalp + (booleanp (denormalp rat rounded-expo bias)))) + +(define sse-cvt-fp1-to-fp2-special (kind + (sign :type (unsigned-byte 1)) + (implicit :type (unsigned-byte 1)) + (frac natp) + (frac-width1 posp) + (exp-width2 posp) + (frac-width2 posp)) + :short "Check whether the operand is SNaN or QNaN and then return + corresponding result. Also handle the infinities." + ;; Return (mv flag sign exp implicit frac invalid). + (let ((invalid (eq kind 'snan))) + (cond + ((eq kind 'snan) + (let ((exp-width exp-width2) + (frac-width frac-width2) + (nan-frac-bits (ash + (part-select frac :low 0 :high (nfix (- frac-width1 2))) + (- frac-width2 frac-width1)))) + (flag-make-special-bp 'qnan nan-frac-bits + sign invalid))) + ((or (eq kind 'qnan) (eq kind 'indef)) + (let ((exp-width exp-width2) + (frac (ash frac (- frac-width2 frac-width1)))) + (mv t sign (fp-max-exp exp-width) implicit frac invalid))) + ((eq kind 'inf) + (let ((exp-width exp-width2) + (frac-width frac-width2)) + (flag-make-special-bp 'inf 0 sign invalid))) + (t (mv nil 0 0 0 0 invalid)))) + + /// + + (defthm integerp-sse-cvt-fp1-to-fp2-special-1 + (implies (integerp sign) + (integerp + (mv-nth + 1 + (sse-cvt-fp1-to-fp2-special + kind sign implicit frac frac-width1 exp-width2 frac-width2)))) + :rule-classes :type-prescription) + + (defthm integerp-sse-cvt-fp1-to-fp2-special-2 + (integerp (mv-nth + 2 + (sse-cvt-fp1-to-fp2-special + kind sign implicit frac frac-width1 exp-width2 frac-width2))) + :rule-classes :type-prescription) + + (defthm integerp-sse-cvt-fp1-to-fp2-special-3 + (implies (integerp implicit) + (integerp (mv-nth + 3 (sse-cvt-fp1-to-fp2-special + kind sign implicit frac frac-width1 exp-width2 frac-width2)))) + :rule-classes :type-prescription) + + (defthm integerp-sse-cvt-fp1-to-fp2-special-4 + (integerp (mv-nth + 4 + (sse-cvt-fp1-to-fp2-special + kind sign implicit frac frac-width1 exp-width2 frac-width2))) + :rule-classes :type-prescription)) + +(ACL2::with-supporters + (local (include-book "rtl/rel11/lib/excps" :dir :system)) + (defun sse-cvt-fp1-to-fp2 (op mxcsr + exp-width1 frac-width1 + exp-width2 frac-width2) + (declare (xargs :guard (and (natp op) (n32p mxcsr) + (posp exp-width1) (posp frac-width1) + (posp exp-width2) (posp frac-width2)) + :guard-hints (("Goal" :in-theory (e/d* () + (rtl::sse-post-comp + bitops::logand-with-negated-bitmask + bitops::loghead-of-loghead-1 + unsigned-byte-p + bitops::logtail-of-loghead + bitops::logbitp-of-loghead-in-bounds + bitops::loghead-of-logior)))))) + (b* ((mxcsr (mbe :logic (loghead 32 mxcsr) + :exec mxcsr)) + ((mv kind sign exp ?implicit frac) + (fp-decode op exp-width1 frac-width1)) + (daz (logbitp #.*mxcsr-daz* mxcsr)) + ((mv kind ?exp frac) + (sse-daz kind exp frac daz)) + ((mv special-ok sign-special exp-special & frac-special invalid) + (sse-cvt-fp1-to-fp2-special kind sign implicit frac frac-width1 + exp-width2 frac-width2)) + ;; Check invalid operation + (mxcsr (if invalid (!mxcsrBits->ie 1 mxcsr) mxcsr)) + (im (equal (mxcsrBits->im mxcsr) 1)) + ((when (and invalid (not im))) + (mv 'invalid-operand-exception-is-not-masked 0 mxcsr)) + ;; Check denormal operand + (de (eq kind 'denormal)) + (mxcsr (if de (!mxcsrBits->de 1 mxcsr) mxcsr)) + (dm (equal (mxcsrBits->dm mxcsr) 1)) + ((when (and de (not dm))) + (mv 'denormal-operand-exception-is-not-masked 0 mxcsr))) + + (if special-ok + (mv nil + (fp-encode-integer sign-special exp-special frac-special + exp-width2 frac-width2) + mxcsr) + (b* ((bias1 (nfix (ec-call (RTL::bias (list nil (1+ frac-width1) exp-width1))))) + (bias2 (nfix (ec-call (RTL::bias (list nil (1+ frac-width2) exp-width2))))) + (rat (fp-to-rat sign exp frac bias1 exp-width1 frac-width1)) + ((mv result flags) + (ec-call (rtl::sse-post-comp rat mxcsr (list nil (1+ frac-width2) exp-width2)))) + (result (loghead (+ 1 frac-width2 exp-width2) (ifix result))) + (mxcsr (loghead 32 (logior (ifix flags) mxcsr))) + + ;; Post-computation Exceptions + ;; Check overflow + (overflowp (equal (mxcsrBits->oe mxcsr) 1)) + ((when (and overflowp + (equal (mxcsrBits->om mxcsr) 0))) + (mv 'overflow-exception-is-not-masked result mxcsr)) + ;; Check underflow + ((when (and (equal (mxcsrBits->ue mxcsr) 1) + (equal (mxcsrBits->um mxcsr) 0))) + (mv 'underflow-exception-is-not-masked result mxcsr)) + ;; Check precision + ((when (and (equal (mxcsrBits->pe mxcsr) 1) + (equal (mxcsrBits->pm mxcsr) 0))) + (mv 'precision-exception-is-not-masked result mxcsr)) + + (rc + (mbe :logic (part-select mxcsr :low #.*mxcsr-rc* :high (1+ #.*mxcsr-rc*)) + :exec (logand #b11 (ash mxcsr (- #.*mxcsr-rc*))))) + (rounded-rat (rat-round rat rc bias2 exp-width2 frac-width2)) + + (rounded-expo (RTL::expo rounded-rat)) + (denormalp (denormalp rat rounded-expo bias2)) + + (flush (and denormalp + (equal (mxcsrBits->um mxcsr) 1) + (equal (mxcsrBits->ftz mxcsr) 1))) + (fp-result + (rat-to-fp rounded-rat sign overflowp + denormalp flush rc exp-width2 frac-width2))) + + (mv nil fp-result mxcsr)))))) + + +(defthm integerp-result-sse-cvt-fp1-to-fp2 + (integerp (mv-nth + 1 + (sse-cvt-fp1-to-fp2 op mxcsr exp-width1 frac-width1 exp-width2 frac-width2))) + :hints (("Goal" :in-theory (e/d* () + (rtl::sse-post-comp + bitops::loghead-of-loghead-1 + unsigned-byte-p + bitops::logtail-of-loghead + bitops::logbitp-of-loghead-in-bounds + bitops::loghead-of-logior)))) + :rule-classes :type-prescription) + +(defthm-unsigned-byte-p n32p-mxcsr-sse-cvt-fp1-to-fp2 + :bound 32 + :concl (mv-nth + 2 + (sse-cvt-fp1-to-fp2 op mxcsr exp-width1 frac-width1 exp-width2 frac-width2)) + :hints (("Goal" :in-theory (e/d* (unsigned-byte-p-when-mxcsrbits-p) + (rtl::sse-post-comp + bitops::loghead-of-loghead-1 + unsigned-byte-p + bitops::logtail-of-loghead + bitops::logbitp-of-loghead-in-bounds + bitops::loghead-of-logior)))) + :gen-type t + :gen-linear t) + +(in-theory (e/d () (sse-cvt-fp1-to-fp2))) + +;; ====================================================================== + +;; Single-Precision Operations: + +(define sp-sse-cvt-fp-to-int ((nbytes :type (integer 0 *)) + (op :type (unsigned-byte 32)) + (mxcsr :type (unsigned-byte 32)) + (trunc booleanp)) + (b* (((mv flg result mxcsr) + (sse-cvt-fp-to-int nbytes op mxcsr trunc + #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH*)) + + (result (trunc nbytes result))) + (mv flg result mxcsr)) + + /// + + (defthm bytesp-sp-sse-cvt-fp-to-int-1 + (implies (and (natp nbytes) + (member nbytes '(1 2 4 8 16))) + (unsigned-byte-p + (ash nbytes 3) + (mv-nth 1 (sp-sse-cvt-fp-to-int nbytes op mxcsr trunc))))) + + (defthm-unsigned-byte-p n32p-mxcsr-sp-sse-cvt-fp-to-int + :bound 32 + :concl (mv-nth 2 (sp-sse-cvt-fp-to-int nbytes op mxcsr trunc)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +(define sp-sse-cvt-int-to-fp ((op integerp) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-cvt-int-to-fp op mxcsr + #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH*)) + + (result (n32 result))) + (mv flg result mxcsr)) + /// + + (defthm-unsigned-byte-p n32p-result-sp-sse-cvt-int-to-fp + :bound 32 + :concl (mv-nth 1 (sp-sse-cvt-int-to-fp op mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-sp-sse-cvt-int-to-fp + :bound 32 + :concl (mv-nth 2 (sp-sse-cvt-int-to-fp op mxcsr)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +(define sse-cvt-sp-to-dp ((op :type (unsigned-byte 32)) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-cvt-fp1-to-fp2 op mxcsr + #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH* + #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH*)) + + (result (n64 result))) + (mv flg result mxcsr)) + /// + + (defthm-unsigned-byte-p n64p-result-sse-cvt-sp-to-dp + :bound 64 + :concl (mv-nth 1 (sse-cvt-sp-to-dp op mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-sse-cvt-sp-to-dp + :bound 32 + :concl (mv-nth 2 (sse-cvt-sp-to-dp op mxcsr)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; Double-Precision Operations: + +(define dp-sse-cvt-fp-to-int ((nbytes :type (integer 0 *)) + (op :type (unsigned-byte 64)) + (mxcsr :type (unsigned-byte 32)) + (trunc booleanp)) + (b* (((mv flg result mxcsr) + (sse-cvt-fp-to-int nbytes op mxcsr trunc + #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH*)) + + (result (trunc nbytes result))) + (mv flg result mxcsr)) + + /// + + (defthm bytesp-dp-sse-cvt-fp-to-int-1 + (implies (and (natp nbytes) + (member nbytes '(1 2 4 8 16))) + (unsigned-byte-p + (ash nbytes 3) + (mv-nth 1 (dp-sse-cvt-fp-to-int nbytes op mxcsr trunc))))) + + (defthm-unsigned-byte-p n32p-mxcsr-dp-sse-cvt-fp-to-int + :bound 32 + :concl (mv-nth 2 (dp-sse-cvt-fp-to-int nbytes op mxcsr trunc)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +(define dp-sse-cvt-int-to-fp ((op integerp) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-cvt-int-to-fp op mxcsr + #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH*)) + + (result (n64 result))) + (mv flg result mxcsr)) + /// + + (defthm-unsigned-byte-p n64p-result-dp-sse-cvt-int-to-fp + :bound 64 + :concl (mv-nth 1 (dp-sse-cvt-int-to-fp op mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-dp-sse-cvt-int-to-fp + :bound 32 + :concl (mv-nth 2 (dp-sse-cvt-int-to-fp op mxcsr)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +(define sse-cvt-dp-to-sp ((op :type (unsigned-byte 64)) + (mxcsr :type (unsigned-byte 32))) + (b* (((mv flg result mxcsr) + (sse-cvt-fp1-to-fp2 op mxcsr + #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH* + #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH*)) + + (result (n32 result))) + (mv flg result mxcsr)) + /// + + (defthm-unsigned-byte-p n32p-result-sse-cvt-dp-to-sp + :bound 32 + :concl (mv-nth 1 (sse-cvt-dp-to-sp op mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-sse-cvt-dp-to-sp + :bound 32 + :concl (mv-nth 2 (sse-cvt-dp-to-sp op mxcsr)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/mxcsr.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/mxcsr.lisp new file mode 100644 index 000000000..a1201571c --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/mxcsr.lisp @@ -0,0 +1,141 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../../decoding-and-spec-utils") +(include-book "base") +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +; ============================================================================= +; INSTRUCTION: MXCSR State Management Instructions +; ============================================================================= + +(def-inst x86-ldmxcsr/stmxcsr-Op/En-M + + :parents (two-byte-opcodes fp-opcodes) + + :short "Load/Store MXCSR register" + + :long + "

Op/En = M: \[OP M\]

+ 0F AE /2: LDMXCSR m32
+ 0F AE /3: STMXCSR m32
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg0 + (the (unsigned-byte 32) mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + 4 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (x86 + (case reg + (2 ;; LDMXCSR + (!mxcsr mem x86)) + (3 ;; STMXCSR + (b* ((mxcsr (the (unsigned-byte 32) (mxcsr x86))) + ((mv flg1 x86) + (x86-operand-to-reg/mem proc-mode + 4 + inst-ac? + nil ;; Not a memory pointer operand + mxcsr + seg-reg + addr + rex-byte + r/m + mod + x86)) + ;; Note: If flg1 is non-nil, we bail out without changing the + ;; x86 state. + ((when flg1) + (!!ms-fresh :x86-operand-to-reg/mem flg1))) + x86)) + (otherwise ;; Should never be reached, unimplemented. + x86))) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/sqrt-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/sqrt-spec.lisp new file mode 100644 index 000000000..698edae55 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/sqrt-spec.lisp @@ -0,0 +1,158 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau + +;; All events beginning with the prefix RTL:: in this book are +;; imported from the RTL/REL11 library under the directory +;; "books/rtl/rel11/lib", authored by David M. Russinoff +;; (david@russinoff.com). + +(in-package "X86ISA") +(include-book "utilities" :dir :utils) +(include-book "fp-structures" :dir :utils) +(include-book "rtl/rel11/portcullis" :dir :system) +(include-book "tools/with-supporters" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) +(local (in-theory (e/d (bitops::ash-1-removal) ()))) + +;; ====================================================================== + +(defsection floating-point-sqrt-specifications + :parents (floating-point-arithmetic-specifications) + :short "Specification of SQRT operation" + ) + +(local (xdoc::set-default-parents floating-point-sqrt-specifications)) + +;; ====================================================================== + +;; SQRT: + +(ACL2::with-supporters + (local (include-book "rtl/rel11/lib/excps" :dir :system)) + :names (rtl::formal-+ rtl::cat rtl::cat-size) + + (in-theory (e/d () (rtl::sse-sqrt-spec))) + + (defun sse-sqrt (operand mxcsr exp-width frac-width) + (declare (xargs :guard (and (natp operand) + (n32p mxcsr) + (posp exp-width) + (posp frac-width)))) + (b* (((mv result mxcsr) + (ec-call + (rtl::sse-sqrt-spec + operand mxcsr (list nil (1+ frac-width) exp-width)))) + ;; Hopefully, the following fixes will go away once we know + ;; rtl::sse-binary-spec returns a well-formed result and + ;; mxcsr. + (result (loghead (+ 1 exp-width frac-width) (ifix result))) + (mxcsr (loghead 32 (ifix mxcsr))) + ;; Pre-computation Exceptions + ;; Check invalid operation + ((when (and (equal (mxcsrBits->ie mxcsr) 1) + (equal (mxcsrBits->im mxcsr) 0))) + (mv 'invalid-operand-exception-is-not-masked result mxcsr)) + ;; Check denormal operand + ((when (and (equal (mxcsrBits->de mxcsr) 1) + (equal (mxcsrBits->dm mxcsr) 0))) + (mv 'denormal-operand-exception-is-not-masked result mxcsr)) + ;; Post-computation Exceptions + ;; Check precision + ((when (and (equal (mxcsrBits->pe mxcsr) 1) + (equal (mxcsrBits->pm mxcsr) 0))) + (mv 'precision-exception-is-not-masked result mxcsr))) + (mv nil result mxcsr)))) + +(defthm unsigned-byte-p-of-result-of-sse-sqrt + (implies (and (equal fp-width (+ 1 exp-width frac-width)) + (posp exp-width) + (posp frac-width)) + (unsigned-byte-p fp-width + (mv-nth 1 (sse-sqrt op mxcsr exp-width frac-width))))) + +(defthm unsigned-byte-p-of-mxcsr-of-sse-sqrt + (unsigned-byte-p 32 (mv-nth 2 (sse-sqrt op mxcsr exp-width frac-width)))) + +(in-theory (disable sse-sqrt)) + +;; ====================================================================== + +;; Single-Precision Operation: + +(define sp-sse-sqrt ((x :type (unsigned-byte 32)) + (mxcsr :type (unsigned-byte 32))) + (sse-sqrt x mxcsr #.*IEEE-SP-EXP-WIDTH* #.*IEEE-SP-FRAC-WIDTH*) + + /// + + (defthm-unsigned-byte-p n32p-result-sp-sse-sqrt + :bound 32 + :concl (mv-nth 1 (sp-sse-sqrt x mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-sp-sse-sqrt + :bound 32 + :concl (mv-nth 2 (sp-sse-sqrt x mxcsr)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; Double-Precision Operation: + +(define dp-sse-sqrt ((x :type (unsigned-byte 64)) + (mxcsr :type (unsigned-byte 32))) + (sse-sqrt x mxcsr #.*IEEE-DP-EXP-WIDTH* #.*IEEE-DP-FRAC-WIDTH*) + + /// + (defthm-unsigned-byte-p n64p-result-dp-sse-sqrt + :bound 64 + :concl (mv-nth 1 (dp-sse-sqrt x mxcsr)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mxcsr-dp-sse-sqrt + :bound 32 + :concl (mv-nth 2 (dp-sse-sqrt x mxcsr)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/top.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/top.lisp new file mode 100644 index 000000000..982fa6c46 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/top.lisp @@ -0,0 +1,90 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau + +(in-package "X86ISA") + +;; ====================================================================== + +;; All the floating-point instructions implemented so far are 128-bit +;; Legacy SSE (or in some cases, SSE2) versions. Just to be very +;; clear, the following versions of the floating-point instructions +;; are unimplemented: MMX, AVX, AVX2, and AVX512. + +(include-book "arithmetic") +(include-book "logical") +(include-book "shuffle-and-unpack") +(include-book "mxcsr") +(include-book "simd-integer") +(include-book "convert") +(include-book "non-arith") + +;; Exception Types and Alignment Checking: A Quick Reference +;; (TO-DO: make this into a doc topic or a function later...) + +;; Type 1 (Legacy SSE): #GP if not 16 byte aligned + +;; Type 2 (Legacy SSE): #GP if not 16 byte aligned + +;; Type 3: #AC if alignment checking is enabled and an +;; unaligned memory reference of 8 Bytes or less is +;; made while the current privilege level is 3. + +;; Type 4 (Legacy SSE): #GP if not 16 byte aligned (PCMPESTRI, PCMPESTRM, +;; PCMPISTRI, and PCMPISTRM instructions do not +;; cause #GP if the memory operand is not aligned to +;; 16-Byte boundary) + +;; Type 5: #AC if alignment checking is enabled and an unaligned +;; memory reference is made while the current +;; privilege level is 3. + +;; Type 6: #AC for 4 or 8 byte memory references if alignment +;; checking is enabled and an unaligned memory +;; reference is made while the current privilege level +;; is 3. + +;; Type 7: No FP exceptions, no memory argument + +;; Type 8: No memory argument + +;; Type 11: No AC + +;; Type 12: No AC + + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/jump-and-loop.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/jump-and-loop.lisp new file mode 100644 index 000000000..e6ddd01ef --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/jump-and-loop.lisp @@ -0,0 +1,1013 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../decoding-and-spec-utils") + +(local (include-book "../guard-helpers")) +(local (include-book "centaur/bitops/signed-byte-p" :dir :system)) +(local (in-theory (e/d () (unsigned-byte-p)))) + + +;; ====================================================================== +;; INSTRUCTION: (one-byte opcode map) +;; jmp +;; ====================================================================== + +; From Intel Vol. 1, Section 6.3.7: + +;; In 64-bit mode, the operand size for all near branches (CALL, RET, JCC, +;; JCXZ, JMP, and LOOP) is forced to 64 bits. These instructions update the +;; 64-bit RIP without the need for a REX operand-size prefix. + +;; The following aspects of near branches are controlled by the effective +;; operand size: +;; Truncation of the size of the instruction pointer +;; Size of a stack pop or push, due to a CALL or RET +;; Size of a stack-pointer increment or decrement, due to a CALL or RET +;; Indirect-branch operand size + +;; In 64-bit mode, all of the above actions are forced to 64 bits regardless of +;; operand size prefixes (operand size prefixes are silently ignored). However, +;; the displacement field for relative branches is still limited to 32 bits and +;; the address size for near branches is not forced in 64-bit mode. + +;; Address sizes affect the size of RCX used for JCXZ and LOOP; they also +;; impact the address calculation for memory indirect branches. Such addresses +;; are 64 bits by default; but they can be overridden to 32 bits by an address +;; size prefix. + +(def-inst x86-near-jmp-Op/En-D + + ;; Op/En: D + ;; E9: JMP rel32: Jump Near, relative, RIP = RIP + 32-bit + ;; displacement sign-extended to 64-bits + ;; EB: JMP rel8: Jump Short, RIP = RIP + 8-bit displacement + ;; sign-extended to 64-bits + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (rime-size-of-1-to-rime08 + rime-size-of-2-to-rime16 + rime-size-of-4-to-rime32) + ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* ((byte-operand? (eql opcode #xEB)) ; T if jump short + ((the (integer 0 4) offset-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil t t x86)) + + ((mv ?flg (the (signed-byte 32) offset) x86) + (rime-size proc-mode offset-size temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :rime-size-error flg)) + + ((mv flg next-rip) + (add-to-*ip proc-mode temp-rip (the (integer 0 4) offset-size) x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip next-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg temp-rip) (add-to-*ip proc-mode next-rip offset x86)) + ((when flg) (!!ms-fresh :virtual-memory-error temp-rip)) + + ;; when the size is 16 bits, zero the high bits of EIP + ;; (see pseudocode of JMP in Intel manual, Mar'17, Vol. 2: + (temp-rip (if (eql offset-size 2) + (logand #xffff temp-rip) + temp-rip)) + + ;; Update the x86 state: + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(local (include-book "centaur/bitops/width-find-rule" :dir :system)) +(local (in-theory (e/d (bitops::unsigned-byte-p-by-find-rule) ()))) +(local (in-theory (e/d (bigger-bound-of-mv-nth-1-x86-operand-from-modr/m-and-sib-bytes-operand) ()))) + +(def-inst x86-near-jmp-Op/En-M + + ;; Absolute indirect jump: RIP = r/m16/32/64 + ;; FF/4: JMP r/m16 + ;; FF/4: JMP r/m32 + ;; FF/4: JMP r/m64 + ;; Op/En: M + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 riml32) ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (;; Note that the reg field serves as an opcode extension for + ;; this instruction. The reg field will always be 4 when this + ;; function is called. + + (p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 2 8) operand-size) + (select-operand-size proc-mode nil rex-byte nil prefixes t t t x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg + jmp-addr + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* operand-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes-error flg)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Note that instruction pointers are modeled as signed in 64-bit mode, + ;; but unsigned in 32-bit mode. + (jmp-addr (if (equal proc-mode #.*64-bit-mode*) + (i64 jmp-addr) + jmp-addr)) + ;; Ensure that the return address is canonical (for 64-bit mode) and + ;; within code segment limits (for 32-bit mode). See pseudocode in Intel + ;; manual. + ((unless (if (equal proc-mode #.*64-bit-mode*) + (canonical-address-p jmp-addr) + (b* ((cs.limit (the (unsigned-byte 32) + (seg-hidden-limiti #.*cs* x86)))) + (and (<= 0 jmp-addr) (<= jmp-addr cs.limit))))) + (!!fault-fresh :gp 0 :bad-return-address jmp-addr)) ;; #GP(0) + + ;; Update the x86 state: + (x86 (write-*ip proc-mode jmp-addr x86))) + x86)) + +(local + (defthm unsigned-byte-p-128-xr-str + (implies (x86p x86) + (unsigned-byte-p 128 (xr :str i x86))))) + +(local + (defthmd signed-byte-p-64-when-unsigned-byte-p-48 + (implies (unsigned-byte-p 48 x) + (signed-byte-p 64 x)))) + +(local + (defthmd signed-byte-p-64-when-unsigned-byte-p-32 + (implies (unsigned-byte-p 32 x) + (signed-byte-p 64 x)))) + +(local + (defthmd signed-byte-p-48-when-unsigned-byte-p-32 + (implies (unsigned-byte-p 32 x) + (signed-byte-p 48 x)))) + +(local + (defthm unsigned-byte-p-1-bool->bit + (unsigned-byte-p 1 (bool->bit x)))) + +(local + (defthm unsigned-byte-p-3-mv-nth-2-x86-operand-from-modr/m-and-sib-bytes + (implies + (x86p x86) + (unsigned-byte-p + 3 + (mv-nth 2 + (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type + operand-size inst-ac? memory-ptr? + seg-reg p4? temp-rip rex-byte + r/m mod sib num-imm-bytes x86)))))) + +(local + (defthm jmp-addr-limit-lemma + (implies (and (unsigned-byte-p 16 x) + (unsigned-byte-p 4 y)) + (signed-byte-p 48 + (1- (ash (logior x (ash y 16)) 12)))) + :hints (("Goal" :in-theory (e/d* (bitops::ihsext-inductions + bitops::ihsext-recursive-redefs) + ()))))) +(local + (defthm ret-forcing-round-helper-1 + (implies (x86p x86) + (unsigned-byte-p + 96 + (xr + :str #.*gdtr* + (mv-nth 4 + (x86-operand-from-modr/m-and-sib-bytes + proc-mode reg-type + operand-size inst-ac? memory-ptr? + seg-reg p4? temp-rip rex-byte + r/m mod sib num-imm-bytes x86))))))) + +(local + (defthm ret-forcing-round-helper-2 + (implies (x86p x86) + (unsigned-byte-p + 96 + (xr + :str #.*gdtr* + (mv-nth 2 (rml-size n addr r-x x86))))))) + +(local + (defthm ret-forcing-round-helper-3 + (implies (x86p x86) + (unsigned-byte-p + 16 + (make-code-segment-attr-field + (mv-nth 1 (rml-size 8 addr r-x x86))))))) + +(local + (defthm unsigned-byte-p-96-of-xr-str + (unsigned-byte-p 96 (xr :str i x86)))) + +(local + (defthm x86-far-jmp-op/en-d-helper-1 + (unsigned-byte-p + 32 + (logior + (call-gate-descriptorbits->offset15-0 x) + (ash (call-gate-descriptorbits->offset31-16 y) 16))) + :hints (("Goal" :in-theory (e/d (call-gate-descriptorbits->offset15-0 + call-gate-descriptorbits->offset31-16) + ()))))) + +(local + (defthm x86-far-jmp-op/en-d-helper-2 + (unsigned-byte-p + 64 + (logior (call-gate-descriptorbits->offset15-0 x) + (ash (call-gate-descriptorbits->offset31-16 y) 16) + (ash (call-gate-descriptorbits->offset63-32 z) 32))) + :hints (("Goal" :in-theory (e/d (call-gate-descriptorbits->offset15-0 + call-gate-descriptorbits->offset31-16) + ()))))) + +(local + (defthm x86-far-jmp-op/en-d-helper-3 + (unsigned-byte-p 32 (gdtr/idtrbits->limit x)) + :hints (("Goal" :in-theory (e/d (gdtr/idtrbits->limit + gdtr/idtrbits-fix) + ()))))) + +(local + (defthm x86-far-jmp-op/en-d-helper-4 + (equal + (logior (call-gate-descriptorbits->offset15-0 x) + (logand #xFFFF0000 (ash (call-gate-descriptorbits->offset31-16 y) 16))) + (logior (call-gate-descriptorbits->offset15-0 x) + (ash (call-gate-descriptorbits->offset31-16 y) 16))) + :hints (("Goal" :in-theory (e/d (far-jmp-call-gate-guard-helper-6) + ()))))) + +(defthmd unsigned-byte-p-32-call-gate-descriptorbits->offset63-32 + (unsigned-byte-p 32 (call-gate-descriptorbits->offset63-32 x)) + :hints (("goal" :in-theory (e/d (call-gate-descriptorbits->offset63-32) ())))) + +(defthmd unsigned-byte-p-16-call-gate-descriptorbits->offset31-16 + (unsigned-byte-p 16 (call-gate-descriptorbits->offset31-16 x)) + :hints (("goal" :in-theory (e/d (call-gate-descriptorbits->offset31-16) ())))) + +(defthmd unsigned-byte-p-16-call-gate-descriptorbits->offset15-0 + (unsigned-byte-p 16 (call-gate-descriptorbits->offset15-0 x)) + :hints (("goal" :in-theory (e/d (call-gate-descriptorbits->offset15-0) ())))) + +(defthm x86-far-jmp-op/en-d-helper-5 + (equal + (logior + (ash + (call-gate-descriptorbits->offset31-16 + x) + 16) + (loghead + 32 + (call-gate-descriptorbits->offset15-0 + y)) + (logand + 18446744069414584320 + (ash + (call-gate-descriptorbits->offset63-32 + z) + 32))) + (logior + (call-gate-descriptorbits->offset15-0 + y) + (ash + (call-gate-descriptorbits->offset31-16 + x) + 16) + (ash + (call-gate-descriptorbits->offset63-32 + z) + 32))) + :hints (("goal" :in-theory (e/d (far-jmp-call-gate-guard-helper-7 + unsigned-byte-p-32-call-gate-descriptorbits->offset63-32 + unsigned-byte-p-16-call-gate-descriptorbits->offset31-16 + unsigned-byte-p-16-call-gate-descriptorbits->offset15-0) + ((:rewrite bitops::commutativity-2-of-logior) + (:rewrite acl2::loghead-identity) + (:rewrite unsigned-byte-p-16-call-gate-descriptorbits->offset15-0) + (:rewrite bitops::unsigned-byte-p-by-find-rule)))))) + +(def-inst x86-far-jmp-Op/En-D + + :parents (one-byte-opcodes) + + :short "Absolute Indirect Jump: Far" + + :long "

Op/En: D

+

FF/5: JMP m16:16 or m16:32 or m16:64

+ +

Source: Intel Manuals \(Vol. 2A\) Instruction Set Reference: the +text below has been edited to contain information only about the +64-bit mode.

+ +

The JMP instruction cannot be used to perform +inter-privilege-level far jumps. The processor always uses the +segment selector part of the far address to access the corresponding +descriptor in the GDT or LDT. The descriptor type and access rights +determine the type of jump to be performed.

+ +

Far Jump to a Conforming or Non-Conforming Code Segment: If +the selected descriptor is for a code segment, a far jump to a code +segment at the same privilege level is performed. If the selected code +segment is at a different privilege level and the code segment is +non-conforming, a general-protection exception is generated. The +target operand specifies an absolute far address indirectly with a +memory location \(m16:16 or m16:32 or m16:64\). The operand-size +attribute and the REX.w bit determine the size of the offset \(16 or +32 or 64 bits\) in the far address. The new code segment selector and +its descriptor are loaded into CS register, and the offset from the +instruction is loaded into the RIP register.

+ +

Far Jump through a Call Gate: When executing a far jump +through a call gate, the segment selector specified by the target +operand identifies the call gate. The offset part of the target +operand is ignored. The processor then jumps to the code segment +specified in the call gate descriptor and begins executing the +instruction at the offset specified in the call gate. No stack switch +occurs. The target operand specifies the far address of the call gate +indirectly with a memory location \(m16:16 or m16:32 or m16:64\).

" + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" + :in-theory + (union-theories + '(!ms !ms$a !fault !fault$a + !seg-hidden-attri !seg-hidden-attri$a + !seg-hidden-limiti !seg-hidden-limiti$a + ssr-hidden-limiti ssr-hidden-limiti$a + seg-hidden-basei seg-hidden-basei$a + !seg-visiblei !seg-visiblei$a + !seg-hidden-basei !seg-hidden-basei$a + x86-far-jmp-op/en-d + (:rewrite x86p-of-write-*ip) + (:rewrite x86p-of-x86-operand-from-modr/m-and-sib-bytes.x86) + x86p-of-mv-nth-2-of-rml-size + x86p-of-write-*ip + (:rewrite x86p-xw)) + (theory 'minimal-theory))))) + + :prepwork + ((local (in-theory (e/d* (far-jump-guard-helpers + bigger-bound-of-mv-nth-1-x86-operand-from-modr/m-and-sib-bytes-operand) + (unsigned-byte-p + member-equal + acl2::logtail-identity + not + signed-byte-p + (tau-system)))))) + + :guard-hints (("Goal" :in-theory (enable + signed-byte-p-64-when-unsigned-byte-p-48 + signed-byte-p-64-when-unsigned-byte-p-32))) + :modr/m t + + :body + + (b* ( ;; Note that this exception was not mentioned in the Intel + ;; Manuals, but I think that the reason for this omission was + ;; that the JMP instruction reference sheet mentioned direct + ;; addressing opcodes too (which are unavailable in the 64-bit + ;; mode). If the source operand is not a memory location, then + ;; #GP(0) is raised. + ((when (equal mod #b11)) + (!!ms-fresh :source-operand-not-memory-location mod)) + + (p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 2 8) offset-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg + mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* + ;; offset-size is the number of bytes of the + ;; offset. We need two more bytes for the selector. + (the (integer 2 10) (+ 2 offset-size)) inst-ac? + t ;; A memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes-error flg)) + + (badlength? + (check-instruction-length start-rip temp-rip increment-RIP-by)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (selector (the (unsigned-byte 16) (n16 mem))) + (offset (mbe :logic (part-select mem :low 16 :width + (ash offset-size 3)) + :exec (ash mem -16))) + + ;; Getting the selector's components: + ((the (unsigned-byte 13) sel-index) + (segment-selectorBits->index selector)) + ((the (unsigned-byte 1) sel-ti) + (segment-selectorBits->ti selector)) + ((the (unsigned-byte 2) sel-rpl) + (segment-selectorBits->rpl selector)) + + ;; Is the selector a null selector? A null selector points to + ;; the first entry in the GDT (sel-index=0, ti=0). + ;; The exception #GP(0) is raised when the segment selector in + ;; the destination operand is NULL. + ((when (and (equal sel-ti 0) + (equal sel-index 0))) + (!!fault-fresh :gp 0 :gp-nullselector 0)) ;; #GP(0) + + ((mv dt-base-addr dt-limit) + (if (equal sel-ti 0) + ;; Selector references the GDT. + (b* ((gdtr (the (unsigned-byte 80) (stri #.*gdtr* x86))) + (gdtr-base (if (eql proc-mode #.*64-bit-mode*) + (gdtr/idtrBits->base-addr gdtr) + (n32 (gdtr/idtrBits->base-addr gdtr)))) + (gdtr-limit (gdtr/idtrBits->limit gdtr))) + (mv gdtr-base gdtr-limit)) + ;; Selector references the LDT whose base address is in + ;; LDTR. + (b* ((ldtr-base + (the (unsigned-byte 64) (ssr-hidden-basei #.*ldtr* x86))) + (ldtr-base (if (eql proc-mode #.*64-bit-mode*) + ldtr-base + (n32 ldtr-base))) + (ldtr-limit + (the (unsigned-byte 32) (ssr-hidden-limiti #.*ldtr* x86)))) + (mv ldtr-base ldtr-limit)))) + + ;; We start by reading 8 bytes from the descriptor table, because code + ;; segments are always 8 bytes long. + + ;; Is the limit of the selector within the descriptor table limit? + ;; To obtain the largest address of the descriptor that we are + ;; reading from the GDT or LDT, we multiply the selector index by 8 + ;; and we add 7 to it, because a code descriptor is 8 bytes long (see + ;; AMD manual, Dec'17, Volume 2, Figures 4-14 and 4-20). + (largest-address (+ (ash sel-index 3) 7)) + ((when (< dt-limit largest-address)) + (!!fault-fresh + :gp sel-index ;; #GP(selector) + :gp-selector-limit-check-failed (list selector dt-base-addr dt-limit))) + + ;; Now that we know the segment selector is valid, we check if + ;; the segment descriptor address is valid. + (descriptor-addr + ;; The index is scaled by 8. + (+ dt-base-addr (the (unsigned-byte 16) (ash sel-index 3)))) + ((when (not (canonical-address-p descriptor-addr))) + (!!ms-fresh :descriptor-addr-virtual-memory-error descriptor-addr)) + + ;; Now we read the descriptor (or the first 8 bytes of it if we are in + ;; 64-bit mode and it is not a code descriptor): + ((mv flg (the (unsigned-byte 64) descriptor) x86) + ;; [TO-DO@Shilpi]: I believe I should use :x below and not + ;; :r. Double check. + (rml-size 8 descriptor-addr :x x86)) + ((when flg) + (!!ms-fresh :rml-size-error flg)) + + ;; Now we look at the descriptor just read to see what kind it is, + ;; and to process it according to the cases in the pseudocode in + ;; Intel manual, May'18, Volume 2, JMP specification. + + ;; Read the S bit, which is 0 for system segments and 1 for user segments + ;; (AMD manual, Dec'17, Volume 2, Table 4-2). + ;; We use CODE-SEGMENT-DESCRIPTOR-LAYOUTBITS->* even though we don't know + ;; whether this is a code segment yet; it could be a system segment, or + ;; the first half of it in 64-bit mode. But we need to read the S bit + ;; somehow, and CODE-SEGMENT-DESCRIPTOR-LAYOUTBITS->* does that. + ;; TODO: maybe introduce and use a generic function to read the S bit + ;; from a segment descriptor that is not necessarily a code segment? + (s (code-segment-descriptorBits->s descriptor)) + + ;; If S = 1, the descriptor is for a user segment. The only kind of user + ;; segment valid for JMP is a code segment. So we process this descriptor + ;; as a code descriptor segment. + ((when (= s 1)) + + ;; Process conforming or non-conforming code segment: + + ;; The treatment of Conforming and Non-Conforming code segments here + ;; only differs in the privilege check (see pseudocode in Intel manual, + ;; May'18, Volume 2, JMP specification). So we use almost the same ACL2 + ;; code (below) for them. + + (b* ( ;; Ensure that the most significant bit of the Type field is 1 + ;; (i.e. code segment), not 0 (i.e. data segment). See AMD manual, + ;; Dec'17, Volume 2, Table 4-3; the bit is referred to as 'Bit 11' + ;; there, because it is bit 11 of the high quadword of the + ;; descriptor (see Figure 4-14). + (msb-of-type + (code-segment-descriptorBits->msb-of-type descriptor)) + ((unless (= msb-of-type 1)) + (!!fault-fresh + :gp sel-index ;; #GP(selector) + :jmp-far-data-segment sel-index)) + + ;; Ensure that D = 0 in 64-bit mode: + (d (code-segment-descriptorBits->d descriptor)) + ;; This condition is equivalent to Intel pseudocode's condition + ;; (see 64-BIT-MODEP): + ((when (and (eql proc-mode #.*64-bit-mode*) (= d 1))) + (!!fault-fresh + :gp sel-index ;; #GP(selector) + :cs.d=1-in-64-bit-mode sel-index)) + + ;; Privilege check (differs for conforming and nonconforming + ;; code segments): + (cpl (cpl x86)) + (dpl (code-segment-descriptorBits->dpl descriptor)) + (c (code-segment-descriptorBits->c descriptor)) + (allowed (if (= c 1) ; conforming + ;; Access is allowed to a conforming code segment + ;; when DPL <= CPL (numerically). RPL is ignored + ;; for this privilege check. + (<= dpl cpl) + ;; Access is allowed to a conforming code segment + ;; when RPL <= CPL (numerically) and CPL = DPL. + (and (<= sel-rpl cpl) + (equal cpl dpl)))) + ;; If access is not allowed, #GP(segment-selector) is raised. + ((when (not allowed)) + (!!fault-fresh + :gp sel-index ;; #GP(selector) + :privilege-check-fail (acons :dpl dpl + (acons :cpl cpl + (acons :rpl sel-rpl nil))))) + + ;; Ensure that the segment is present: + (p (code-segment-descriptorBits->p descriptor)) + ((unless (= p 1)) + (!!fault-fresh + :np sel-index ;; #NP(selector) + :code-segment-not-present sel-index)) + + ;; Trimming the offset based on the operand-size, + ;; and changing the sign in 64-bit mode: + (jmp-addr + (case offset-size + (2 (n16 offset)) + (4 (n32 offset)) + (t (i64 offset)))) + + ;; #GP(0) is thrown if the target offset in destination is + ;; non-canonical (in 64-bit mode) or outside the segment limit (in + ;; 32-bit mode): + (jmp-addr-ok + (if (eql proc-mode #.*64-bit-mode*) + (canonical-address-p jmp-addr) + (b* ((limit15-0 (code-segment-descriptorBits->limit15-0 + descriptor)) + (limit19-16 (code-segment-descriptorBits->limit19-16 + descriptor)) + (limit (part-install limit15-0 + (ash limit19-16 16) + :low 0 :width 16)) + (g (code-segment-descriptorBits->g descriptor)) + ;; If G = 1, the limit is the number of 4-Kbyte blocks + ;; (AMD manual, Dec'17, Volume 2, Section 4.7.1): + (max-offset + (if (= g 1) + (1- (ash limit 12)) + limit))) + (< jmp-addr max-offset)))) + ((unless jmp-addr-ok) + (!!fault-fresh + :gp 0 ;; #GP(0) + :noncanonical-or-outside-segment-limit jmp-addr)) + + ;; Calculate the new contents of the CS register: + (new-cs-visible + (!segment-selectorBits->rpl cpl selector)) + ;; Update x86 state: + (x86 (!seg-visiblei #.*cs* new-cs-visible x86)) + (x86 (!seg-hidden-basei #.*cs* dt-base-addr x86)) + (x86 (!seg-hidden-limiti #.*cs* dt-limit x86)) + (x86 (!seg-hidden-attri #.*cs* + ;; Get attributes from the descriptor in GDT. + (make-code-segment-attr-field descriptor) + x86)) + (x86 (write-*ip proc-mode jmp-addr x86))) + x86)) + + ;; Here S = 0, so the descriptor just read is a system segment, + ;; or the first half of it in 64-bit mode. + + ;; In 32-bit mode, we only support JMP far in the application-level + ;; view, not in the system-level view of 32-bit mode. Only code + ;; segments, handled above, are used in the application-level view; call + ;; gates, handled below, are used in the system-level view. Thus, at + ;; this point we stop if we are in 32-bit mode. Support for system + ;; segments in 32-bit mode will be added eventually. + + ((when (not (equal proc-mode #.*64-bit-mode*))) + (!!ms-fresh :far-jmp-system-unimplemented-in-32-bit-mode)) + + ;; Here we know we are in 64-bit mode. Thus, we have just read the first + ;; 8 bytes of a system descriptor (which is always 16 bytes in 64-bit + ;; mode). So now we read a 16-byte descriptor from the table, checking + ;; the limit (TODO: maybe optimize this by just reading the next 8 bytes + ;; and joining them with the already read 8 bytes above): + (largest-address (+ (ash sel-index 3) 15)) + ((when (< dt-limit largest-address)) + (!!fault-fresh + :gp sel-index ;; #GP(selector) + :gp-selector-limit-check-failed (list selector dt-base-addr dt-limit))) + ((mv flg (the (unsigned-byte 128) descriptor) x86) + ;; [TO-DO@Shilpi]: I believe I should use :x below and not + ;; :r. Double check. + (rml-size 16 descriptor-addr :x x86)) + ((when flg) + (!!ms-fresh :rml-size-error flg)) + + ;; Check if the descriptor is a call gate descriptor: + ((mv call-gate-desc? reason2) + ;; Note that the following predicate reports the + ;; descriptor to be invalid if the P flag of the + ;; descriptor is 0. + (ia32e-valid-call-gate-segment-descriptor-p descriptor)) + + ;; If it is a call gate descriptor, process it accordingly: + ((when call-gate-desc?) + + (b* ((cpl (cpl x86)) + (dpl (call-gate-descriptorBits->dpl descriptor)) + + ;; Access is allowed when: + ;; 1. CPL <= Call gate's DPL + ;; 2. RPL <= Call gate's DPL + ;; 3. If the destination Code segment is conforming, + ;; then: DPL of code segment <= CPL + ;; If the destination Code segment is non-conforming, + ;; then: DPL of code segment = CPL. + ;; If access is not allowed, #GP(segment-selector) is + ;; raised. + ;; Below, we check 1 and 2. We will check for 3 after we + ;; read in the code segment descriptor. + ((when (not (and (<= cpl dpl) + (<= sel-rpl dpl)))) + (!!fault-fresh + :gp sel-index ;; #GP(selector) + :privilege-check-fail (acons :dpl dpl + (acons :cpl cpl + (acons :rpl sel-rpl nil))))) + + (cs-selector + (call-gate-descriptorBits->selector descriptor)) + ((the (unsigned-byte 13) cs-sel-index) + (segment-selectorBits->index cs-selector)) + ((the (unsigned-byte 1) cs-sel-ti) + (segment-selectorBits->ti cs-selector)) + ((the (unsigned-byte 2) cs-sel-rpl) + (segment-selectorBits->rpl cs-selector)) + + ;; If the call gate's code segment selector is NULL, + ;; #GP(0) is raised. + ((when (and (equal cs-sel-ti 0) + (equal cs-sel-index 0))) + (!!fault-fresh :gp 0 ;; #GP(0) + :call-gate-code-segment-nullselector 0)) + + ;; Is the call gate code segment selector index outside + ;; the descriptor table limit? If so, #GP(code segment + ;; selector) is raised. + ((mv cs-dt-base-addr cs-dt-limit) + (if (equal sel-ti 0) + ;; Code Segment Selector references the GDT. + (b* ((gdtr (the (unsigned-byte 80) (stri #.*gdtr* x86))) + (gdtr-base (gdtr/idtrBits->base-addr gdtr)) + (gdtr-base (if (eql proc-mode *64-bit-mode*) + gdtr-base + (n32 gdtr-base))) + (gdtr-limit (gdtr/idtrBits->limit gdtr))) + (mv gdtr-base gdtr-limit)) + ;; Code Segment Selector references the LDT whose base + ;; address is in LDTR. + (b* ((ldtr-base (the (unsigned-byte 64) + (ssr-hidden-basei #.*ldtr* x86))) + (ldtr-base (if (eql proc-mode #.*64-bit-mode*) + ldtr-base + (n32 ldtr-base))) + (ldtr-limit (the (unsigned-byte 32) + (ssr-hidden-limiti #.*ldtr* x86)))) + (mv ldtr-base ldtr-limit)))) + ;; To obtain the largest address of the descriptor that we are + ;; reading from the GDT or LDT, we multiply the selector index by 8 + ;; and we add 7 to it, becausea code descriptor is 8 bytes long (see + ;; AMD manual, Dec'17, Volume 2, Figures 4-14 and 4-20). + (largest-address (+ (ash cs-sel-index 3) 7)) + ((when (< cs-dt-limit largest-address)) + (!!fault-fresh :gp cs-sel-index + :gp-selector-limit-check-failed (list + cs-selector + cs-dt-base-addr + cs-dt-limit))) + + ;; Reading the code segment: we check if the code segment + ;; descriptor is valid. + (cs-descriptor-addr + ;; The index is scaled by 8. + (+ cs-dt-base-addr (the (unsigned-byte 16) (ash cs-sel-index 3)))) + ((when (not (canonical-address-p cs-descriptor-addr))) + (!!ms-fresh :cs-descriptor-addr-virtual-memory-error cs-descriptor-addr)) + ((mv flg (the (unsigned-byte 64) cs-descriptor) x86) + ;; [TO-DO@Shilpi]: I believe I should use :x below and not :r. + (rml-size 8 cs-descriptor-addr :x x86)) + ((when flg) + (!!ms-fresh :rml-size-error flg)) + ((mv valid? reason) + ;; Note that the following predicate reports the + ;; descriptor to be invalid if the P flag of the + ;; descriptor is 0. + (ia32e-valid-code-segment-descriptor-p cs-descriptor)) + ((when (not valid?)) + (!!fault-fresh + :gp cs-sel-index ;; #GP(selector) + :call-gate-code-segment-descriptor-invalid (cons reason cs-descriptor))) + + ;; Checking the privileges of the code segment: + (cs-dpl (code-segment-descriptorBits->dpl cs-descriptor)) + (c-bit (code-segment-descriptorBits->c cs-descriptor)) + ((when (or (and ;; Conforming code segment + (equal c-bit 1) + (not (<= cs-dpl cpl))) + (and ;; Conforming code segment + (equal c-bit 0) + (not (eql cs-dpl cpl))))) + (!!fault-fresh :gp cs-sel-index ;; #GP(selector) + :privilege-check-fail (acons :c-bit c-bit + (acons :cpl cpl + (acons :cs-dpl cs-dpl nil))))) + + (call-gate-offset15-0 + (call-gate-descriptorBits->offset15-0 descriptor)) + (call-gate-offset31-16 + (call-gate-descriptorBits->offset31-16 descriptor)) + (call-gate-offset63-32 ;; this is 0 in 32-bit mode + (call-gate-descriptorBits->offset63-32 descriptor)) + (call-gate-offset31-0 + (mbe :logic (part-install call-gate-offset15-0 + (ash call-gate-offset31-16 16) + :low 0 :width 16) + :exec + (the (unsigned-byte 32) + (logior (the (unsigned-byte 16) call-gate-offset15-0) + (the (unsigned-byte 32) + (ash call-gate-offset31-16 16)))))) + (call-gate-offset + (mbe :logic + (part-install call-gate-offset31-0 + (ash call-gate-offset63-32 32) + :low 0 :width 32) + :exec + (the (unsigned-byte 64) + (logior (the (unsigned-byte 32) call-gate-offset31-0) + (the (unsigned-byte 64) + (ash call-gate-offset63-32 32)))))) + + ;; Trimming the call gate offset based on the operand-size: + (jmp-addr + (case offset-size + (2 (n16 call-gate-offset)) + (4 (n32 call-gate-offset)) + (t call-gate-offset))) + + ;; #GP(0) is thrown if the target offset in destination is + ;; non-canonical. + ((when (not (canonical-address-p jmp-addr))) + (!!ms-fresh :target-offset-virtual-memory-error jmp-addr)) + + (new-cs-visible + (!segment-selectorBits->rpl cpl cs-selector)) + ;; Update x86 state: + (x86 (!seg-visiblei #.*cs* new-cs-visible x86)) + (x86 (!seg-hidden-basei #.*cs* cs-dt-base-addr x86)) + (x86 (!seg-hidden-limiti #.*cs* cs-dt-limit x86)) + (x86 (!seg-hidden-attri #.*cs* + ;; Get attributes from the descriptor in GDT. + (make-code-segment-attr-field cs-descriptor) + x86)) + (x86 (write-*ip proc-mode jmp-addr x86))) + x86))) + + ;; If it is not a code segment or call gate descriptor, since we are in + ;; 64-bit mode for now, #GP(selector) is raised. + (!!fault-fresh + :gp sel-index ;; #GP(selector) + :either-both-code-segment-or-call-gate-are-absent-or-some-other-descriptor-is-present + (cons reason2 descriptor)))) + +;; ====================================================================== +;; INSTRUCTION: LOOP +;; ====================================================================== + +; From Intel Vol. 1, Section 6.3.7: + +;; In 64-bit mode, the operand size for all near branches (CALL, RET, JCC, +;; JCXZ, JMP, and LOOP) is forced to 64 bits. These instructions update the +;; 64-bit RIP without the need for a REX operand-size prefix. + +;; The following aspects of near branches are controlled by the effective +;; operand size: +;; Truncation of the size of the instruction pointer +;; Size of a stack pop or push, due to a CALL or RET +;; Size of a stack-pointer increment or decrement, due to a CALL or RET +;; Indirect-branch operand size + +;; In 64-bit mode, all of the above actions are forced to 64 bits regardless of +;; operand size prefixes (operand size prefixes are silently ignored). However, +;; the displacement field for relative branches is still limited to 32 bits and +;; the address size for near branches is not forced in 64-bit mode. + +;; Address sizes affect the size of RCX used for JCXZ and LOOP; they also +;; impact the address calculation for memory indirect branches. Such addresses +;; are 64 bits by default; but they can be overridden to 32 bits by an address +;; size prefix. + +(def-inst x86-loop + + ;; E0: LOOPNE/LOOPNZ rel8 + ;; E1: LOOPE/LOOPZ rel8 + ;; E2: LOOP rel8 + + ;; Intel Vol2A, LOOP/LOOPcc specification says: + ;; "Performs the loop operation using the RCX, ECX or CX as a counter + ;; (depending on whether address size is 64 bits, 32 bits, or 16 + ;; bits)." + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (riml08 + riml32 + rime-size + select-address-size) + (unsigned-byte-p)))) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" + :in-theory + (e/d* (rime-size) + (unsigned-byte-p + member-equal + acl2::logtail-identity + not + rml-size + select-operand-size))))) + + :prepwork + ((local (in-theory (e/d* (far-jump-guard-helpers) + (unsigned-byte-p + member-equal + acl2::logtail-identity + not))))) + + :body + + (b* (;; temp-rip right now points to the rel8 byte. Add 1 to + ;; temp-rip to account for rel8 when computing the length + ;; of this instruction. + (badlength? (check-instruction-length start-rip temp-rip 1)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 2 8) counter-size) (select-address-size proc-mode p4? x86)) + (counter (rgfi-size counter-size *rcx* rex-byte x86)) + (counter (trunc counter-size (1- counter))) + + ((the (unsigned-byte 1) zf) (flgi :zf x86)) + + (branch-cond + (if (equal opcode #xE2) ;; LOOP + (not (equal counter 0)) + (if (equal opcode #xE1) ;; LOOPE/LOOPZ + (and (equal zf 1) + (not (equal counter 0))) + ;; #xE0: LOOPNE/LOOPNZ + (and (equal zf 0) + (not (equal counter 0))))))) + + (if branch-cond + + ;; branch condition is true: + (b* ( ;; read rel8 (a value between -128 and +127): + ((mv flg rel8 x86) (rime-size proc-mode 1 temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :rime-size-error flg)) + ;; add rel8 to the address of the next instruction, + ;; which is one past temp-rip to take the rel8 byte into account: + ((mv flg next-rip) (add-to-*ip proc-mode temp-rip (1+ rel8) x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + ;; update counter: + (x86 (!rgfi-size counter-size *rcx* counter rex-byte x86)) + ;; set instruction pointer to new value: + (x86 (write-*ip proc-mode next-rip x86))) + x86) + + ;; branch condition is false: + (b* ( ;; go to the next instruction, + ;; which starts just after the rel8 byte: + ((mv flg next-rip) (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + ;; update counter: + (x86 (!rgfi-size counter-size *rcx* counter rex-byte x86)) + ;; set instruction pointer to new value: + (x86 (write-*ip proc-mode next-rip x86))) + x86)))) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/logical.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/logical.lisp new file mode 100644 index 000000000..94946accc --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/logical.lisp @@ -0,0 +1,395 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Authors: +; Cuong Chau +; Alessandro Coglio (www.alessandrocoglio.info) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(in-package "X86ISA") + +(include-book "../decoding-and-spec-utils") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MMX variants + +(def-inst x86-pand/pandn/por/pxor-mmx + + :parents (two-byte-opcodes) + + :short "Logical instructions (MMX variants)." + + :long + " + NP 0F DB /r PAND mm, mm/m64 + NP 0F DF /r PANDN mm, mm/m64 + NP 0F EB /r POR mm, mm/m64 + NP 0F EF /r PXOR mm, mm/m64 + " + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ;; The operand size is always 64 bits, i.e. 8 bytes. + (operand-size 8) + + ;; The first source operand (Operand 1 in the Intel manual) + ;; is the MMX register specified in Reg. + ;; This is also the destination operand, + ;; and thus we obtain the index for later use. + ;; Since there are only 8 MMX registers, the REX byte is not used. + ((the (unsigned-byte 4) src1/dst-index) reg) + ((the (unsigned-byte 64) src1) (mmx src1/dst-index x86)) + + ;; The second source operand (Operand 2 in the Intel manual) + ;; is the MMX register, or memory operand, specified in Mod and R/M. + (inst-ac? t) ; Intel Manual Volume 2 Table 2-21 (Dec 2023) + ((mv flg + (the (unsigned-byte 64) src2) + (the (integer 0 4) increment-rip-by) + ?addr + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*mmx-access* + operand-size + inst-ac? + nil ; not a memory operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; no immediate operand + x86)) + ((when flg) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg)) + + ;; Increment the instruction pointer in the temp-rip variable. + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ;; Ensure the instruction is not too long. + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Calculate the result. + (result (case opcode + (#xdb (logand src1 src2)) + (#xdf (logand (lognot src1) src2)) + (#xeb (logior src1 src2)) + (#xef (logxor src1 src2)) + (t 0))) ; unreachable + + ;; Store the result into the destination register. + (x86 (!mmx src1/dst-index result x86)) + (x86 (mmx-instruction-updates x86)) + + ;; Update the instruction pointer. + (x86 (write-*ip proc-mode temp-rip x86))) + + x86) + + :guard-hints (("Goal" :in-theory (disable unsigned-byte-p)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; SSE variants + +(def-inst x86-andp?/andnp?/orp?/xorp?/pand/pandn/por/pxor-Op/En-RM + + :parents (two-byte-opcodes) + + :short "Logical instructions (SSE variants)." + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 0F 54: ANDPS xmm1, xmm2/m128
+ 0F 55: ANDNPS xmm1, xmm2/m128
+ 0F 56: ORPS xmm1, xmm2/m128
+ 0F 57: XORPS xmm1, xmm2/m128
+ + 66 0F 54: ANDPD xmm1, xmm2/m128
+ 66 0F 55: ANDNPD xmm1, xmm2/m128
+ 66 0F 56: ORPD xmm1, xmm2/m128
+ 66 0F 57: XORPD xmm1, xmm2/m128
+ + 66 0F DB: PAND xmm1, xmm2/m128
+ 66 0F DF: PANDN xmm1, xmm2/m128
+ 66 0F EB: POR xmm1, xmm2/m128
+ 66 0F EF: PXOR xmm1, xmm2/m128
" + + :operation t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 4 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (result (case operation + (#.*OP-AND* (logand xmm xmm/mem)) + (#.*OP-ANDN* (logand (lognot xmm) xmm/mem)) + (#.*OP-OR* (logior xmm xmm/mem)) + (#.*OP-XOR* (logxor xmm xmm/mem)) + ;; Should not reach here. + (otherwise 0))) + + ;; Update the x86 state: + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; AVX variants + +(def-inst x86-vandp?/vandnp?/vorp?/vxorp?/vpand/vpandn/vpor/vpxor-vex + + :parents (two-byte-opcodes) + + :short "VEX-encoded logical instructions." + + :long + " + VANDPD xmm1, xmm2, xmm3/m128 + VANDPD ymm1, ymm2, ymm3/m256 + + VANDPS xmm1, xmm2, xmm3/m128 + VANDPS ymm1, ymm2, ymm3/m256 + + VANDNPD xmm1, xmm2, xmm3/m128 + VANDNPD ymm1, ymm2, ymm3/m256 + + VANDNPS xmm1, xmm2, xmm3/m128 + VANDNPS ymm1, ymm2, ymm3/m256 + + VORPD xmm1, xmm2, xmm3/m128 + VORPD ymm1, ymm2, ymm3/m256 + + VORPS xmm1, xmm2, xmm3/m128 + VORPS ymm1, ymm2, ymm3/m256 + + VXORPD xmm1, xmm2, xmm3/m128 + VXORPD ymm1, ymm2, ymm3/m256 + + VXORPS xmm1, xmm2, xmm3/m128 + VXORPS ymm1, ymm2, ymm3/m256 + + VPAND xmm1, xmm2, xmm3/m128 + VPAND ymm1, ymm2, ymm3/m256 + + VPANDN xmm1, xmm2, xmm3/m128 + VPANDN ymm1, ymm2, ymm3/m256 + + VPOR xmm1, xmm2, xmm3/m128 + VPOR ymm1, ymm2, ymm3/m256 + + VPXOR xmm1, xmm2, xmm3/m128 + VPXOR ymm1, ymm2, ymm3/m256 + " + + :modr/m t + + :operation t + + :vex t + + :guard (vex-prefixes-byte0-p vex-prefixes) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (rex-byte (rex-byte-from-vex-prefixes vex-prefixes)) + + ;; The operand size is determined by VEX.L, + ;; based on the VEX.128 and VEX.256 notation + ;; (see Intel Manual Volume 2 Section 3.1.1.2 (Dec 2023)). + ((the (integer 16 32) operand-size) + (if (equal (vex->l vex-prefixes) 1) + 32 + 16)) + + ;; The first source operand (Operand 2 in the Intel Manual) + ;; is the XMM or YMM register specified in VEX.vvvv. + ((the (unsigned-byte 4) src1-index) + (vex-vvvv-reg-index (vex->vvvv vex-prefixes))) + ((the (unsigned-byte 256) src1) (zmmi-size operand-size src1-index x86)) + + ;; The second source operand (Operand 3 in the Intel Manual) + ;; is the XMM or YMM register, or memory operand, + ;; specified in the ModR/M byte. + ;; There is no alignment checking + ;; (see Intel Manual Volume 2 Table 2-21 (Dec 2023)). + (inst-ac? nil) ; Exceptions Type 4 + ((mv flg + src2 + (the (integer 0 4) increment-rip-by) + (the (signed-byte 64) addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + (if (= operand-size 16) + #.*VEX-XMM-ACCESS* + #.*YMM-ACCESS*) + operand-size + inst-ac? + nil ; not a memory operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; no immediate operand + x86)) + ((when flg) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg)) + + ;; The destination operand (Operand 1 in the Intel Manual) + ;; is the XMM or YMM register specified in the reg bits of ModR/M. + ((the (unsigned-byte 4) dst-index) (reg-index reg rex-byte #.*r*)) + + ;; Increment the instruction pointer in the temp-rip variable. + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ;; Ensure the instruction is not too long. + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Apply the logical operation to the source operands, + ;; and only keep the appropriate number of bits. + (result (case operation + (#.*OP-AND* (logand src1 src2)) + (#.*OP-ANDN* (logand (lognot src1) src2)) + (#.*OP-OR* (logior src1 src2)) + (#.*OP-XOR* (logxor src1 src2)) + (otherwise 0))) ; unreachable + (result (if (= operand-size 16) + (n128 result) + (n256 result))) + + ;; Store the result into the destination register. + (x86 (!zmmi-size operand-size + dst-index + result + x86 + :regtype (if (= operand-size 16) + #.*vex-xmm-access* + #.*ymm-access*))) + + ;; Update the instruction pointer. + (x86 (write-*ip proc-mode temp-rip x86))) + + x86) + + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + + :prepwork + ((defrulel verify-guards-lemma + (implies (unsigned-byte-p 4 x) + (unsigned-byte-p 5 x))))) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move-sse.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move-sse.lisp new file mode 100644 index 000000000..0077b1292 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move-sse.lisp @@ -0,0 +1,1494 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, May - August 2023, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; Copyright (C) August 2023 - May 2024, Yahya Sohail +; Copyright (C) May 2024 - August 2024, Intel Corporation +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Authors: +; Shilpi Goel +; Cuong Chau +; Alessandro Coglio +; Yahya Sohail + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(in-package "X86ISA") + +(include-book "../decoding-and-spec-utils") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVQ + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movq-to-xmm/mem + + ;; 66 0F D6 /r: MOVQ xmm2/m64, xmm1 + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + ((the (unsigned-byte 64) xmm) + (xmmi-size 8 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (int= mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? t) + ((mv flg1 x86) + (x86-operand-to-xmm/mem proc-mode + ;; If writing to xmm register, use size 16 to + ;; clear upper bits + ;; If writing to memory, use size 8 + (if (int= mod #b11) + 16 8) + inst-ac? + xmm + seg-reg + addr + rex-byte + r/m + mod + x86)) + ;; Note: If flg1 is non-nil, we bail out without changing the x86 state. + ((when flg1) + (!!ms-fresh :x86-operand-to-xmm/mem flg1)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movq-from-xmm/mem + + ;; F3 0F 7E /r: MOVQ xmm1, xmm2/m64 + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 8 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (x86 (!xmmi-size 16 xmm-index xmm/mem x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVD/MOVQ + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movd/movq-to-xmm + + ;; 66 0F 6E /r: MOVD xmm, r/m32 + ;; 66 REX.W 0F 6E /r: MOVQ xmm, r/m64 + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (the (unsigned-byte 8) (prefixes->seg prefixes))) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + ((the (integer 4 8) operand-size) + (if (logbitp #.*w* rex-byte) + 8 + 4)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 reg/mem (the (unsigned-byte 3) increment-RIP-by) ?addr x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* operand-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + ;; The operand size is 16 bytes (128 bits) because, + ;; according to the MOVD/MOVQ specification in Intel Volume 2, + ;; the value stored in the XMM register is zero-extended to 128 bits. + (x86 (!xmmi-size 16 + (reg-index reg rex-byte #.*r*) + reg/mem + x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movd/movq-from-xmm + + ;; 66 0F 7E /r: MOVD r/m32, xmm + ;; 66 REX.W 0F 7E /r: MOVQ r/m64, xmm + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (the (unsigned-byte 8) (prefixes->seg prefixes))) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + ((the (integer 4 8) operand-size) + (if (logbitp #.*w* rex-byte) + 8 + 4)) + + (register (xmmi-size operand-size + (reg-index reg rex-byte #.*r*) + x86)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (equal mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? t) + ((mv flg2 x86) + (x86-operand-to-reg/mem proc-mode + operand-size + inst-ac? + nil ;; Not a memory pointer operand + register + seg-reg + addr + rex-byte + r/m + mod + x86)) + ;; Note: If flg1 is non-nil, we bail out without changing the x86 state. + ((when flg2) + (!!ms-fresh :x86-operand-to-reg/mem flg2)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVDQA + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movdqa-to-xmm + + :parents (two-byte-opcodes) + + :short "Move aligned packed integer values." + + :long + " + 66 0F 6F /r MOVDQA xmm1, xmm2/m128 + " + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (the (unsigned-byte 8) (prefixes->seg prefixes))) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (operand-size 16) + + (inst-ac? t) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (unsigned-byte 3) increment-rip-by) + ?addr + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + operand-size + inst-ac? + nil ; not memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; no immediate operand + x86)) + ((when flg0) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (x86 (!xmmi-size operand-size xmm-index xmm/mem x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movdqa-from-xmm + + :parents (two-byte-opcodes) + + :short "Move aligned packed integer values." + + :long + " + 66 0F 7F /r MOVDQA xmm2/m128, xmm1 + " + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (operand-size 16) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-rip-by) + x86) + (if (int= mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; no immediate operand + x86))) + ((when flg0) (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? ;; Exceptions Type 1 + t) + ((mv flg1 x86) + (x86-operand-to-xmm/mem proc-mode + operand-size + inst-ac? + xmm + seg-reg + addr + rex-byte + r/m + mod + x86)) + ((when flg1) + (!!ms-fresh :x86-operand-to-xmm/mem flg1)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVSS, MOVSD + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movss/movsd-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move scalar single/double precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ F3 0F 10: MOVSS xmm1, xmm2/m32
+ F2 0F 10: MOVSD xmm1, xmm2/m64
" + + :sp/dp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) operand-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; From Intel manual, Vol. 2A: For non-VEX encoded syntax and when the + ;; source and destination operands are XMM registers, the high + ;; doublewords/quadword of the destination operand remains + ;; unchanged. When the source operand is a memory location and + ;; destination operand is an XMM register, the high doublewords/quadword + ;; of the destination operand is cleared to all 0s. + (operand-size (if (= mod #b11) operand-size 16)) + + ;; Update the x86 state: + (x86 (!xmmi-size operand-size xmm-index xmm/mem x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movss/movsd-Op/En-MR + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move scalar single/double precision floating-point values" + + :long + "

Op/En = MR: \[OP XMM/M, XMM\]

+ F3 0F 11: MOVSS xmm2/m32, xmm1
+ F2 0F 11: MOVSD xmm2/m64, xmm1
" + + :sp/dp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) operand-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + (xmm (xmmi-size operand-size xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (int= mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg1 x86) + (x86-operand-to-xmm/mem proc-mode + operand-size + inst-ac? + xmm + seg-reg + addr + rex-byte + r/m + mod + x86)) + ((when flg1) + (!!ms-fresh :x86-operand-to-xmm/mem flg1)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVAPS, MOVAPD + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movaps/movapd-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move aligned packed single/double precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 0F 28: MOVAPS xmm1, xmm2/m128
+ 66 0F 28: MOVAPD xmm1, xmm2/m128
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 1 + t) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (x86 (!xmmi-size 16 xmm-index xmm/mem x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movaps/movapd-Op/En-MR + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move aligned packed single/double precision floating-point values" + + :long + "

Op/En = MR: \[OP XMM/M, XMM\]

+ 0F 29: MOVAPS xmm2/m128, xmm1
+ 66 0F 29: MOVAPD xmm2/m128, xmm1
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (int= mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? ;; Exceptions Type 1 + t) + ((mv flg1 x86) + (x86-operand-to-xmm/mem proc-mode + 16 + inst-ac? + xmm + seg-reg + addr + rex-byte + r/m + mod + x86)) + ((when flg1) + (!!ms-fresh :x86-operand-to-xmm/mem flg1)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVUPS, MOVUPD, MOVDQU + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movups/movupd/movdqu-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 0F 10: MOVUPS xmm1, xmm2/m128
+ 66 0F 10: MOVUPD xmm1, xmm2/m128
+ F3 0F 6F: MOVDQU xmm1, xmm2/m128
+ +

Note: The MOVDQU, MOVUPS, and MOVUPD instructions perform 128-bit + unaligned loads or stores. They do not generate general-protection + exceptions (#GP) when operands are not aligned on a 16-byte + boundary. If alignment checking is enabled, alignment-check + exceptions (#AC) may or may not be generated depending on processor + implementation when data addresses are not aligned on an 8-byte + boundary.

" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? + ;; Exceptions Type 4 but treatment of #AC varies. For now, we + ;; check the alignment. + t) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (x86 (!xmmi-size 16 xmm-index xmm/mem x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movups/movupd/movdqu-Op/En-MR + + :parents (two-byte-opcodes fp-opcodes) + + :long + "

Op/En = MR: \[OP XMM/M, XMM\]

+ 0F 11: MOVUPS xmm2/m128, xmm1
+ 66 0F 11: MOVUPD xmm2/m128, xmm1
+ F3 0F 7F: MOVDQU xmm2/m128, xmm1
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (int= mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? ;; Exceptions Type 4, but treatment of #AC + ;; varies. For now, we do alignment checking. + t) + ((mv flg1 x86) + (x86-operand-to-xmm/mem proc-mode + 16 + inst-ac? + xmm + seg-reg + addr + rex-byte + r/m + mod + x86)) + ;; Note: If flg1 is non-nil, we bail out without changing the x86 state. + ((when flg1) + (!!ms-fresh :x86-operand-to-xmm/mem flg1)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVLPS, MOVLPD + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movlps/movlpd-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move low packed single/double precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, M\]

+ 0F 12: MOVLPS xmm, m64
+ 66 0F 12: MOVLPD xmm, m64
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg0 + (the (unsigned-byte 64) mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 8 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (x86 (!xmmi-size 8 xmm-index mem x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movlps/movlpd-Op/En-MR + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move low packed single/double precision floating-point values" + + :long + "

Op/En = MR: \[OP M, XMM\]

+ 0F 13: MOVLPS m64, xmm
+ 66 0F 13: MOVLPD m64, xmm
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + ((the (unsigned-byte 64) xmm) + (xmmi-size 8 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg1 x86) + (x86-operand-to-xmm/mem proc-mode + 8 + inst-ac? + xmm + seg-reg + addr + rex-byte + r/m + mod + x86)) + ((when flg1) + (!!ms-fresh :x86-operand-to-xmm/mem flg1)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVHPS, MOVHPD + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movhps/movhpd-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move high packed single/double precision floating-point values" + + :long + "

Op/En = RM: \[OP XMM, M\]

+ 0F 16: MOVHPS xmm, m64
+ 66 0F 16: MOVHPD xmm, m64
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg0 + (the (unsigned-byte 64) mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?v-addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 8 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + ((the (unsigned-byte 64) low-qword) + (xmmi-size 8 xmm-index x86)) + (result (merge-2-u64s mem low-qword)) + (x86 (!xmmi-size 16 xmm-index result x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movhps/movhpd-Op/En-MR + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move high packed single/double precision floating-point values" + + :long + "

Op/En = MR: \[OP M, XMM\]

+ 0F 17: MOVHPS m64, xmm
+ 66 0F 17: MOVHPD m64, xmm
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (high-qword (mbe :logic (part-select xmm :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF + (ash xmm -64))))) + + (p2 (prefixes->seg prefixes)) + + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg1 x86) + (x86-operand-to-xmm/mem proc-mode + 8 + inst-ac? + high-qword + seg-reg + addr + rex-byte + r/m + mod + x86)) + ((when flg1) + (!!ms-fresh :x86-operand-to-xmm/mem flg1)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVHLPS + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movhlps-sse + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move packed single precision floating-point values high to low." + + :long + " + NP 0F 12 /r MOVHLPS xmm1, xmm2 + " + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((operand-size 16) ; 128 bits + + ;; Operand 1 (destination) is in Reg. + ((the (unsigned-byte 4) xmm1-index) (reg-index reg rex-byte #.*r*)) + + ;; Operand 2 (source) is in R/M. + ((the (unsigned-byte 4) xmm2-index) (reg-index r/m rex-byte #.*b*)) + ((the (unsigned-byte 128) xmm2) (xmmi-size operand-size xmm2-index x86)) + + ;; High quadword of xmm2. + ((the (unsigned-byte 64) high-qword) + (mbe :logic (part-select xmm2 :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF + (ash xmm2 -64))))) + + ;; Update xmm1 (just its low 64 bits). + (x86 (!xmmi-size 8 xmm1-index high-qword x86)) + + ;; Update instruction pointer. + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVLHPS + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movlhps-sse + + :parents (two-byte-opcodes fp-opcodes) + + :short "Move packed single precision floating-point values low to high." + + :long + " + NP 0F 16 /r MOVLHPS xmm1, xmm2 + " + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((operand-size 16) ; 128 bits + + ;; Operand 1 (destination) is in Reg. + ((the (unsigned-byte 4) xmm1-index) (reg-index reg rex-byte #.*r*)) + ((the (unsigned-byte 128) xmm1) (xmmi-size operand-size xmm1-index x86)) + + ;; Operand 2 (source) is in R/M. + ((the (unsigned-byte 4) xmm2-index) (reg-index r/m rex-byte #.*b*)) + ((the (unsigned-byte 128) xmm2) (xmmi-size operand-size xmm2-index x86)) + + ;; Low quadword of xmm2. + ((the (unsigned-byte 64) low-qword) + (mbe :logic (part-select xmm2 :low 0 :high 63) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF + xmm2)))) + + ;; New value for xmm1. + ((the (unsigned-byte 128) new-xmm1) + (part-install low-qword xmm1 :low 64 :high 127)) + + ;; Update xmm1. + (x86 (!xmmi-size operand-size xmm1-index new-xmm1 x86)) + + ;; Update instruction pointer. + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVDDUP + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movddup-sse + + :parents (two-byte-opcodes) + + :short "MOVDDUP: replicate double precision floating-point values." + + :long + "

+ This is the SSE variant. +

+

+ Although the operand size is 128 bits, + the use of @('m64') in @('xmm2/m64') in the Intel manual + suggests that only 64 bits are read from the source operand. + If the access is to memory, + reading 128 and ignoring the 64 high ones can make a difference + if the additional memory accesses cause some kind of exception. +

" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ;; index of xmm1: + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + ;; read xmm2/m64: + (inst-ac? ;; Exceptions Type 5 + t) + ((mv flg0 + (the (unsigned-byte 64) val) + (the (integer 0 4) increment-RIP-by) + & ; address of the operand + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 8 ; only 64 bits + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; value for xmm1: + (dup-val (logior (ash val 64) val)) + + ;; write to xmm1: + (x86 (!xmmi-size 16 xmm-index dup-val x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; MOVMSKPS, MOVMSKPD + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movmskps-sse + + :parents (two-byte-opcodes) + + :short "MOVMSKPS: extract packed single precision floating-point sign mask." + + :long + (xdoc::topstring + (xdoc::codeblock + "NP 0F 50 /r MOVMSKPS reg, xmm") + (xdoc::p + "This is the SSE variant.")) + + :modr/m t + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (;; Index of source register. + ((the (unsigned-byte 4) xmm-index) (reg-index reg rex-byte #.*r*)) + + ;; Index of destination register. + ((the (unsigned-byte 4) reg-index) (reg-index r/m rex-byte #.*b*)) + + ;; Collect sign bits. + ((the (unsigned-byte 128) src) (xmmi-size 16 xmm-index x86)) + (sign0 (logbit 31 src)) + (sign1 (logbit 63 src)) + (sign2 (logbit 95 src)) + (sign3 (logbit 127 src)) + + ;; Form value to put into destination. + ((the (unsigned-byte 4) dst) + (acl2::logappn 1 sign0 + 1 sign1 + 1 sign2 + 1 sign3)) + + ;; Write the value into the destination. + ;; We use 64 bits as the operand size, for the following reasons. + ;; In 64-bit mode, that is the default size, + ;; as stated in the manual page for MOVMSKPS; + ;; and there is no way to override it, + ;; because the operand-size-override prefix 66h + ;; is used as mandatory prefix for MOVMSKPD. + ;; In fact, overriding would have no effect, + ;; because writing a 32-bit operand into a GPR in 64-bit mode + ;; zeroes the high 32 bits + ;; (Intel manual, Mar 2026, Vol 1, Sec 3.4.1.1), + ;; which in this case is the same as zero-extending + ;; the 4 bits with the signs to 64 bits. + ;; In 32-bit mode, the upper 32 bits are undefined, + ;; but, as reasoned in the documentation for our WR32 function, + ;; it is adequate to zero those upper 32 bits + ;; when writing the lower 32 bits; + ;; the upper 32 bits can be made undefined + ;; upon switching from 32-bit mode to 64-bit mode. + (x86 (wr64 reg-index dst x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movmskpd-sse + + :parents (two-byte-opcodes) + + :short "MOVMSKPD: extract packed double precision floating-point sign mask." + + :long + (xdoc::topstring + (xdoc::codeblock + "66 0F 50 /r MOVMSKPD reg, xmm") + (xdoc::p + "This is the SSE variant.")) + + :modr/m t + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (;; Index of source register. + ((the (unsigned-byte 4) xmm-index) (reg-index reg rex-byte #.*r*)) + + ;; Index of destination register. + ((the (unsigned-byte 4) reg-index) (reg-index r/m rex-byte #.*b*)) + + ;; Collect sign bits. + ((the (unsigned-byte 128) src) (xmmi-size 16 xmm-index x86)) + (sign0 (logbit 63 src)) + (sign1 (logbit 127 src)) + + ;; Form value to put into destination. + ((the (unsigned-byte 2) dst) + (acl2::logappn 1 sign0 + 1 sign1)) + + ;; Write the value into the destination. + ;; We use 64 bits as the operand size, for the following reasons. + ;; In 64-bit mode, that is the default size, + ;; as stated in the manual page for MOVMSKPS; + ;; and there is no way to override it, + ;; because the operand-size-override prefix 66h + ;; is used as mandatory prefix for MOVMSKPD. + ;; In fact, overriding would have no effect, + ;; because writing a 32-bit operand into a GPR in 64-bit mode + ;; zeroes the high 32 bits + ;; (Intel manual, Mar 2026, Vol 1, Sec 3.4.1.1), + ;; which in this case is the same as zero-extending + ;; the 4 bits with the signs to 64 bits. + ;; In 32-bit mode, the upper 32 bits are undefined, + ;; but, as reasoned in the documentation for our WR32 function, + ;; it is adequate to zero those upper 32 bits + ;; when writing the lower 32 bits; + ;; the upper 32 bits can be made undefined + ;; upon switching from 32-bit mode to 64-bit mode. + (x86 (wr64 reg-index dst x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move.lisp new file mode 100644 index 000000000..ff1dfd980 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/move.lisp @@ -0,0 +1,1181 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, May - August 2023, Regents of the University of Texas +; Copyright (C) 2025, Kestrel Technology, LLC +; Copyright (C) August 2023 - May 2024, Yahya Sohail +; Copyright (C) May 2024 - August 2024, Intel Corporation +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Authors: +; Shilpi Goel +; Alessandro Coglio +; Yahya Sohail + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../decoding-and-spec-utils") + +;(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +(local (in-theory (e/d (bigger-bound-of-mv-nth-1-x86-operand-from-modr/m-and-sib-bytes-operand) + (signed-byte-p + acl2::member-of-cons + rme-size$inline + rml-size$inline + unsigned-byte-p)))) + +;; ====================================================================== +;; INSTRUCTION: MOV +;; ====================================================================== + +(def-inst x86-mov-Op/En-MR + + ;; Op/En: MR + ;; [OP R/M, REG] + ;; 88: MOV r/m8, r8 + ;; 89: MOV r/m16, r16 + ;; 89: MOV r/m32, r32 + ;; 89: MOV r/m64, r64 + ;; 8C: MOV r/m16, Sreg + ;; 8C: MOV r16/r32/m16, Sreg + ;; 8C: MOV r64/m16, Sreg + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (the (unsigned-byte 8) (prefixes->seg prefixes))) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + (byte-operand? (equal opcode #x88)) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + ((when (and (>= reg *segment-register-names-len*) + (equal opcode #x8C))) + (!!ms-fresh :invalid-segment-register)) + (register (if (equal opcode #x8C) + (seg-visiblei reg x86) + (rgfi-size operand-size (reg-index reg rex-byte #.*r*) + rex-byte x86))) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (equal mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + ;; Note: This refers to the segment register corresponding to the potential + ;; memory write, not the segment register being read if this is 0x8C + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (inst-ac? t) + ((mv flg2 x86) + (x86-operand-to-reg/mem proc-mode operand-size + inst-ac? + nil ;; Not a memory pointer operand + register + seg-reg + addr + rex-byte + r/m + mod + x86)) + ;; Note: If flg1 is non-nil, we bail out without changing the x86 state. + ((when flg2) + (!!ms-fresh :x86-operand-to-reg/mem flg2)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-mov-Op/En-RM + + ;; Op/En: RM + ;; [OP REG, R/M] + ;; 8A: MOV r8, r/m8 + ;; 8B: MOV r16, r/m16 + ;; 8B: MOV r32, r/m32 + ;; 8B: MOV r64, r/m64 + ;; 8E: MOV Sreg, r/m16 + ;; 8E: MOV Sreg, r/m64 + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + (byte-operand? (equal opcode #x8A)) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + ;; Refers to segment register for memory access, not the one being + ;; written to in the case of 0x8E + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 reg/mem (the (unsigned-byte 3) increment-RIP-by) ?addr x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* operand-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Update the x86 state: + (x86 (if (equal opcode #x8E) + (b* (((when (>= reg #.*segment-register-names-len*)) + (!!ms-fresh :invalid-dest-sreg)) + (selector (loghead 16 reg/mem)) + ((mv flg descriptor x86) + (get-segment-descriptor reg selector x86)) + ((when flg) + (b* (((when (equal flg t)) + (!!ms-fresh :get-segment-descriptor))) + (!!fault-fresh (car flg) (cadr flg) (caddr flg)))) + (x86 (load-segment-reg reg selector descriptor x86))) + x86) + (!rgfi-size operand-size (reg-index reg rex-byte #.*r*) + reg/mem rex-byte x86))) + ((when (or (fault x86) + (ms x86))) x86) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-mov-Op/En-FD + + ;; Op/En: FD + ;; [OP rAX, Moffs] + ;; A0: MOV AL, moffs8 + ;; A1: MOV AX/EAX/RAX, moffs16/moffs32/moffs64 + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (;; This instruction does not require a ModR/M byte. + (p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + ;; The Intel manual says the following: + + ;; Under the MOV instruction description: + + ;; The moffs8, moffs16, moffs32 and moffs64 operands specify a + ;; simple offset relative to the segment base, where 8, 16, 32 + ;; and 64 refer to the size of the data. The address-size + ;; attribute of the instruction determines the size of the + ;; offset, either 16, 32 or 64 bits. + + ;; Under the "Instruction Column in the Opcode Summary Table" + ;; (Intel manual, Jan'19, Vol. 2, Sec. 3.1.1.3): + + ;; moffs8, moffs16, moffs32, moffs64 A simple memory variable + ;; (memory offset) of type byte, word, or doubleword used by + ;; some variants of the MOV instruction. The actual address is + ;; given by a simple offset relative to the segment base. No + ;; ModR/M byte is used in the instruction. The number shown + ;; with moffs indicates its size, which is determined by the + ;; address-size attribute of the instruction. + + ;; Under "Codes for Addressing Method" + ;; (Intel manual, Jan'19, Vol. 2, App. A.2.1): + + ;; O The instruction has no ModR/M byte. The offset of the + ;; operand is coded as a word or double word (depending on + ;; address size attribute) in the instruction. No base + ;; register, index register, or scaling factor can be applied + ;; (for example, MOV (A0-A3)). + + (byte-operand? (eql opcode #xA0)) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + ((the (integer 1 8) offset-size) + (select-address-size proc-mode p4? x86)) + + ;; Get the offset: + ((mv flg offset x86) + (rime-size-opt proc-mode offset-size temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :rime-size-error flg)) + + ;; Check if the above memory read caused any problems: + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip offset-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (seg-reg (select-segment-register proc-mode p2 p4? 0 0 sib x86)) + + ;; Get data from offset in segment: + (inst-ac? (alignment-checking-enabled-p x86)) + ((mv flg data x86) + (rme-size-opt proc-mode operand-size offset seg-reg :r inst-ac? x86 + :check-canonicity t)) + ((when flg) (!!ms-fresh :rme-size-error flg)) + + ;; Write the data to rAX: + (x86 (!rgfi-size operand-size *rax* data rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-mov-Op/En-TD + + ;; Op/En: TD + ;; [OP Moffs, rAX] + ;; A2: MOV moffs8, AL + ;; A3: MOV moffs16/moffs32/moffs64, AX/EAX/RAX + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (;; This instruction does not require a ModR/M byte. + (p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + ;; The Intel manual says the following: + + ;; Under the MOV instruction description: + + ;; The moffs8, moffs16, moffs32 and moffs64 operands specify a + ;; simple offset relative to the segment base, where 8, 16, 32 + ;; and 64 refer to the size of the data. The address-size + ;; attribute of the instruction determines the size of the + ;; offset, either 16, 32 or 64 bits. + + ;; Under the "Instruction Column in the Opcode Summary Table" + ;; (Intel manual, Jan'19, Vol. 2, Sec. 3.1.1.3): + + ;; moffs8, moffs16, moffs32, moffs64 A simple memory variable + ;; (memory offset) of type byte, word, or doubleword used by + ;; some variants of the MOV instruction. The actual address is + ;; given by a simple offset relative to the segment base. No + ;; ModR/M byte is used in the instruction. The number shown + ;; with moffs indicates its size, which is determined by the + ;; address-size attribute of the instruction. + + ;; Under "Codes for Addressing Method" + ;; (Intel manual, Jan'19, Vol. 2, App. A.2.1): + + ;; O The instruction has no ModR/M byte. The offset of the + ;; operand is coded as a word or double word (depending on + ;; address size attribute) in the instruction. No base + ;; register, index register, or scaling factor can be applied + ;; (for example, MOV (A0-A3)). + + (byte-operand? (eql opcode #xA2)) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + ((the (integer 1 8) offset-size) + (select-address-size proc-mode p4? x86)) + + ;; Get the offset: + ((mv flg offset x86) + (rime-size-opt proc-mode offset-size temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :rime-size-error flg)) + + ;; Check if the above memory read caused any problems: + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip offset-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (seg-reg (select-segment-register proc-mode p2 p4? 0 0 sib x86)) + + ;; Get data from rAX: + (data (rgfi-size operand-size *rax* rex-byte x86)) + + ;; Write the data to offset in segment: + (inst-ac? t) + ((mv flg x86) + (x86-operand-to-reg/mem proc-mode + operand-size + inst-ac? + nil ;; Not a memory pointer operand + data + seg-reg + offset + rex-byte + 0 + 0 + x86)) + ((when flg) (!!ms-fresh :x86-operand-to-reg/mem flg)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-mov-Op/En-OI + + ;; Op/En: OI + ;; [OP REG, IMM] + ;; B0 + rb: MOV r8, imm8 + ;; B8 + rw: MOV r16, imm16 + ;; B8 + rd: MOV r32, imm32 + ;; B8 + rd: MOV r64, imm64 + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* ((byte-operand? (and (<= #xB0 opcode) ;; B0+rb + (<= opcode #xB7))) + ((the (integer 1 8) operand-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + ;; We don't do any alignment check below when fetching the + ;; immediate operand; reading the immediate operand is done + ;; during code fetching, where alignment checks aren't supposed + ;; to be done (see Intel Manuals, Volume 3, Section 6.15, + ;; Exception and Interrupt Reference, Interrupt 17 Alignment + ;; Check Exception (#AC) for details). + ((mv flg0 imm x86) + (rme-size-opt proc-mode operand-size temp-rip #.*cs* :x nil x86 :mem-ptr? nil)) + ((when flg0) + (!!ms-fresh :imm-rme-size-error flg0)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip operand-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (reg (the (unsigned-byte 3) (logand 7 opcode))) + ;; Update the x86 state: + ;; See Intel Table 3.1, p.3-3, Vol. 2-A + (x86 (!rgfi-size operand-size (reg-index reg rex-byte #.*b*) + imm rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-mov-Op/En-MI + + ;; Op/En: MI + ;; [OP R/M, IMM] + ;; C6/0: MOV r/m8, imm8 + ;; C7/0: MOV r/m16, imm16 + ;; C7/0: MOV r/m32, imm32 + ;; C7/0: MOV r/m64, imm32 + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + (byte-operand? (eql opcode #xC6)) + ((the (integer 1 8) imm-size) + (select-operand-size + proc-mode byte-operand? rex-byte t prefixes nil nil nil x86)) + + ((the (integer 1 8) reg/mem-size) + (if (and (equal opcode #xC7) + (logbitp #.*w* rex-byte)) + 8 + imm-size)) + + ((mv flg0 + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (if (equal mod #b11) + (mv nil 0 0 x86) + (x86-effective-addr proc-mode p4? + temp-rip + rex-byte + r/m + mod + sib + imm-size ;; bytes of immediate data + x86))) + ((when flg0) + (!!ms-fresh :x86-effective-addr-error flg0)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + ((mv flg2 imm x86) + (rme-size-opt proc-mode imm-size temp-rip #.*cs* :x nil x86 + :check-canonicity nil)) + ((when flg2) + (!!ms-fresh :imm-rme-size-error flg2)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip imm-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (imm (if (equal reg/mem-size 8) + ;; Sign-extended + (n64 (n32-to-i32 imm)) + imm)) + + ;; Update the x86 state: + (inst-ac? t) + ((mv flg3 x86) + (x86-operand-to-reg/mem proc-mode reg/mem-size + inst-ac? + nil ;; Not a memory pointer operand + imm + seg-reg + addr + rex-byte + r/m + mod + x86)) + ;; Note: If flg2 is non-nil, we bail out without changing the x86 state. + ((when flg3) + (!!ms-fresh :x86-operand-to-reg/mem flg3)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: LEA +;; ====================================================================== + +(def-inst x86-lea + + ;; Op/En: RM + ;; opcode = #x8D/r + ;; LEA r16, m + ;; LEA r32, m + ;; LEA r64, m + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ;; this is the operand size + ;; in Intel manual, Mar'17, Vol 2, Tables 3-53 and 3-54: + ((the (integer 2 8) register-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + ((mv ?flg0 + (the (signed-byte 64) M) + (the (unsigned-byte 3) increment-RIP-by) + x86) + (x86-effective-addr proc-mode p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) (!!ms-fresh :x86-effective-addr-error flg0)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (M (trunc register-size M)) + ;; Update the x86 state: + (x86 (!rgfi-size + register-size (reg-index reg rex-byte #.*r*) M rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: MOVSX/MOVSXD +;; ====================================================================== + +; AT&T mnemonic: MOVSLQ + +(def-inst x86-movsxd + + ;; Op/En: RM + ;; [OP REG, R/M] + ;; #x63: MOVSXD r16, r/m16 (Move word to word) + ;; MOVSXD r32, r/m32 (Move doubleword to doubleword) + ;; MOVSXD r64, r/m32 (Move doubleword to quadword with sign-extension) + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 1 8) reg/mem-size) + (select-operand-size + proc-mode nil rex-byte t prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + reg/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (register-size (if (logbitp #.*w* rex-byte) + 8 + reg/mem-size)) + (reg/mem (if (equal register-size 8) + (n64 (n32-to-i32 reg/mem)) ;; sign-extended + reg/mem)) + + ;; Update the x86 state: + (x86 (!rgfi-size register-size (reg-index reg rex-byte #.*r*) reg/mem + rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-movsx + + ;; Op/En: RM + ;; [OP REG, R/M] + + ;; #x0F BE: MOVSX r16/32/64, r/m8 + ;; (Move byte to word/doubleword/quadword with sign-extension) + + ;; #x0F BF: MOVSX r16/32/64, r/m16 + ;; (Move word to word/doubleword/quadword with sign-extension) + + ;; Note that Intel manual, May'18, Volume 2 excludes the operand-size variant + ;; MOVSX r16 r/m16, in the sense that it does not list it explicitly. + ;; AMD manual, Dec'17, Volume 3 also omits this operand-size variant. + ;; However, experiments with real processors show that at least some + ;; processors support that operand-size variant. This suggests that it may be + ;; just an omission from the manuals, and therefore our model supports it. + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (reg/mem-size (if (equal opcode #xBE) 1 2)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + reg/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (register-size (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + (reg/mem (case reg/mem-size + (1 + (mbe :logic (part-select (n08-to-i08 reg/mem) + :low 0 :width (ash register-size 3)) + :exec (logand (1- (ash 1 (the (integer 8 64) + (ash register-size 3)))) + (n08-to-i08 reg/mem)))) + (2 (case register-size + (2 reg/mem) + (otherwise + (mbe :logic (part-select (n16-to-i16 reg/mem) + :low 0 :width (ash register-size 3)) + :exec (logand (1- (ash 1 (the (integer 8 64) + (ash register-size 3)))) + (n16-to-i16 reg/mem)))))))) + + ;; Update the x86 state: + (x86 (!rgfi-size register-size (reg-index reg rex-byte #.*r*) reg/mem + rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: MOVZX +;; ====================================================================== + +(def-inst x86-movzx + + ;; Op/En: RM + ;; [OP REG, R/M] + + ;; #x0F B6: MOVZX r16/32/64, r/m8 + ;; (Move byte to word/doubleword/quadword with zero-extension) + + ;; #x0F B7: MOVZX r16/32/64, r/m16 + ;; (Move word to word/doubleword/quadword with zero-extension) + + ;; Note that Intel manual, May'18, Volume 2 excludes the operand-size variant + ;; MOVZX r16 r/m16, in the sense that it does not list it explicitly. + ;; AMD manual, Dec'17, Volume 3 also omits this operand-size variant. + ;; However, experiments with real processors show that at least some + ;; processors support that operand-size variant. This suggests that it may be + ;; just an omission from the manuals, and therefore our model supports it. + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (reg/mem-size (if (equal opcode #xB6) 1 2)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode #.*gpr-access* + reg/mem-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((the (integer 1 8) register-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + ;; Update the x86 state: + (x86 (!rgfi-size register-size (reg-index reg rex-byte #.*r*) reg/mem + rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: MOV to/from Control Registers +;; ====================================================================== + +(def-inst x86-mov-control-regs-Op/En-MR + + ;; Move control register to GPR + + ;; Op/En: MR + ;; [OP R/M, REG] + ;; 0F 20/r: MOV r32, CR0-CR7 + ;; 0F 20/r: MOV r64, CR0-CR7 + ;; REX.R + 0F 20/0: MOV r64, CR8 + + ;; From Intel Manuals, Vol 2A, "MOV Move to/from Control + ;; Register": + + ;; At the opcode level, the reg field within the ModR/M byte + ;; specifies which of the control registers is loaded or read. The 2 + ;; bits in the mod field are ignored. The r/m field specifies the + ;; general-purpose register loaded or read. Attempts to reference + ;; CR1, CR5, CR6, CR7, and CR9-CR15 result in undefined opcode (#UD) + ;; exceptions. + + ;; In 64-bit mode, the instruction's default operation size + ;; is 64 bits. The REX.R prefix must be used to access + ;; CR8. Use of REX.B permits access to additional registers + ;; (R8-R15). Use of the REX.W prefix or 66H prefix is + ;; ignored. Use of the REX.R prefix to specify a register + ;; other than CR8 causes an invalid-opcode exception. See the + ;; summary chart at the beginning of this section for encoding + ;; data and limits. + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (;; The r/m field specifies the GPR (destination). + ;; MOD field is ignored. + ;; The reg field specifies the control register (source). + + ;; *operand-size-override* and REX.W are ignored. + + ;; Get value from the control register + (ctr-index + ;; Note that there is a #UD Exception if an attempt is made to access + ;; CR1, CR5, CR6, or CR7 or if the REX.R prefix is used to specify a + ;; register other than CR8. This is checked during dispatch --- see + ;; opcode-maps for details. + (if (and (logbitp #.*r* rex-byte) + (equal reg 0)) + #.*cr8* + reg)) + + (operand-size (if (equal proc-mode #.*64-bit-mode*) 8 4)) + + (ctr-val (the (unsigned-byte 64) (ctri ctr-index x86))) + (ctr-val (if (eql operand-size 4) (n32 ctr-val) ctr-val)) + + ;; Update the x86 state: + (x86 + (!rgfi-size operand-size + (reg-index r/m rex-byte #.*b*) + ctr-val + rex-byte + x86)) + ;; The OF, SF, ZF, AF, PF, and CF flags are undefined. + (x86 (!flgi-undefined :cf x86)) + (x86 (!flgi-undefined :pf x86)) + (x86 (!flgi-undefined :af x86)) + (x86 (!flgi-undefined :zf x86)) + (x86 (!flgi-undefined :sf x86)) + (x86 (!flgi-undefined :of x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-mov-control-regs-Op/En-RM + + ;; Move GPR to control register + + ;; Op/En: RM + ;; [OP R/M, REG] + ;; 0F 22/r: MOV CR0-CR7, r32 + ;; 0F 22/r: MOV CR0-CR7, r64 + ;; REX.R + 0F 22/0: MOV CR8, r64 + + ;; From Intel Manuals, Vol 2A, "MOV Move to/from Control + ;; Register": + + ;; At the opcode level, the reg field within the ModR/M byte + ;; specifies which of the control registers is loaded or read. The 2 + ;; bits in the mod field are ignored. The r/m field specifies the + ;; general-purpose register loaded or read. Attempts to reference + ;; CR1, CR5, CR6, CR7, and CR9-CR15 result in undefined opcode (#UD) + ;; exceptions. + + ;; In 64-bit mode, the instruction's default operation size + ;; is 64 bits. The REX.R prefix must be used to access + ;; CR8. Use of REX.B permits access to additional registers + ;; (R8-R15). Use of the REX.W prefix or 66H prefix is + ;; ignored. Use of the REX.R prefix to specify a register + ;; other than CR8 causes an invalid-opcode exception. See the + ;; summary chart at the beginning of this section for encoding + ;; data and limits. + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (;; The r/m field specifies the GPR (source). + ;; MOD field is ignored. + ;; The reg field specifies the control register (destination). + + ;; *operand-size-override* and REX.W are ignored. + + + (operand-size (if (equal proc-mode #.*64-bit-mode*) 8 4)) + + ;; Get value from GPR + (reg-val (rgfi-size operand-size (reg-index r/m rex-byte #.*b*) rex-byte x86)) + + ;; Update the x86 state: + (ctr-index + ;; Note that there is a #UD Exception if an attempt is made to access + ;; CR1, CR5, CR6, or CR7 or if the REX.R prefix is used to specify a + ;; register other than CR8. This is checked during dispatch --- see + ;; opcode-maps for details. + (if (and (logbitp #.*r* rex-byte) + (equal reg 0)) + #.*cr8* + reg)) + + ;; Clear the tlb on loads to cr3 + (x86 (if (or (equal ctr-index #.*cr3*) + (equal ctr-index #.*cr0*) + ;; Loading cr4 doesn't always require invalidation + ;; (see Vol 3, Chapter 4.10.4.1 of the Intel SDM), + ;; but this is valid too, since we're always + ;; allowed to invalidate + (equal ctr-index #.*cr4*)) + (b* ((tlb (tlb x86)) + (- (fast-alist-free tlb)) + (x86 (!tlb :tlb x86))) + x86) + x86)) + + ;; TODO: What should be done when the register is too large for + ;; the control register? ATM, !ctri-write takes the lowest n bits + (x86 + (!ctri-write ctr-index + reg-val + x86)) + ;; The OF, SF, ZF, AF, PF, and CF flags are undefined. + (x86 (!flgi-undefined :cf x86)) + (x86 (!flgi-undefined :pf x86)) + (x86 (!flgi-undefined :af x86)) + (x86 (!flgi-undefined :zf x86)) + (x86 (!flgi-undefined :sf x86)) + (x86 (!flgi-undefined :of x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: MOVBE +;; ====================================================================== + +(define movbe-reverse-bytes ((val (unsigned-byte-p (* 8 size) val)) (size natp)) + :returns (rev-val (unsigned-byte-p (* 8 size) rev-val) + :hyp :guard + :hints + (("Goal" + :use (:instance + returns-lemma + (l (loghead 8 val)) + (h (movbe-reverse-bytes (logtail 8 val) + (+ -1 size))) + (m 256) + (n (* 8 (1- size))))))) + :parents (instruction-semantic-functions) + :short "Reverse the bytes in an operand of a given byte size." + (cond ((zp size) 0) + (t (logapp (* 8 (1- size)) + (movbe-reverse-bytes (logtail 8 val) (1- size)) + (loghead 8 val)))) + + :prepwork + ((defruledl returns-lemma + (implies (and (natp l) + (natp h) + (posp m) + (natp n) + (< l (expt (expt 2 m) n)) + (< h (expt 2 m))) + (< (+ l (* (expt (expt 2 m) n) h)) + (expt (expt 2 m) (1+ n)))) + :cases ((<= (* (expt (expt 2 m) n) h) + (- (expt (expt 2 m) (1+ n)) (expt (expt 2 m) n)))) + :prep-books ((include-book "arithmetic-5/top" :dir :system))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movbe-op/en-rm + + :parents (two-byte-opcodes) + + :short "MOVBE: Move data after swapping bytes." + + :long + "

This is the variant that moves from memory to register.

" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (the (unsigned-byte 8) (prefixes->seg prefixes))) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 2 8) operand-size) + (select-operand-size proc-mode + nil ; byte-operand? + rex-byte + nil ; imm? + prefixes + nil ; default64? + nil ; ignore-rex? + nil ; ignore-p3-64? + x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ((mv flg operand (the (unsigned-byte 3) increment-rip-by) ?addr x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + operand-size + t ; inst-ac? + nil ; memory-ptr? + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; num-imm-bytes + x86)) + ((when flg) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ; #GP(0) + + (result (movbe-reverse-bytes operand operand-size)) + + (x86 (!rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + result + rex-byte + x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def-inst x86-movbe-op/en-mr + + :parents (two-byte-opcodes) + + :short "MOVBE: Move data after swapping bytes." + + :long + "

This is the variant that moves from register to memory.

" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* ((p2 (the (unsigned-byte 8) (prefixes->seg prefixes))) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 2 8) operand-size) + (select-operand-size proc-mode + nil ; byte-operand? + rex-byte + nil ; imm? + prefixes + nil ; default64? + nil ; ignore-rex? + nil ; ignore-p3-64? + x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (operand (rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + rex-byte + x86)) + + (result (movbe-reverse-bytes operand operand-size)) + + ((mv flg + (the (signed-byte 64) addr) + (the (unsigned-byte 3) increment-rip-by) + x86) + (x86-effective-addr proc-mode + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; num-imm-bytes + x86)) + ((when flg) (!!ms-fresh :x86-effective-addr-error flg)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ; #GP(0) + + ((mv flg x86) + (x86-operand-to-reg/mem proc-mode + operand-size + t ; inst-ac? + nil ; memory-ptr? + result + seg-reg + addr + rex-byte + r/m + mod + x86)) + ((when flg) (!!ms-fresh :x86-operand-to-reg/mem flg)) + + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply-spec.lisp new file mode 100644 index 000000000..761a54d26 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply-spec.lisp @@ -0,0 +1,329 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +;; This book contains the specification of the following instructions: +;; mul imul + +(in-package "X86ISA") + +(include-book "../rflags-spec") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +(set-non-linearp t) + +;; ====================================================================== +;; Unsigned multiply: MUL +;; ====================================================================== + +(define mul-spec-gen ((size :type (member 8 16 32 64))) + :verify-guards nil + + (let* ((mask (1- (expt 2 size))) + (neg-size (- size)) + (size*2 (* 2 size)) + (fn-name (mk-name "MUL-SPEC-" size)) + (str-nbits (if (eql size 8) "08" size))) + + `(define ,fn-name + ((dst :type (unsigned-byte ,size)) + (src :type (unsigned-byte ,size))) + + :parents (mul-spec) + + (b* ((dst (mbe :logic (n-size ,size dst) + :exec dst)) + (src (mbe :logic (n-size ,size src) + :exec src)) + + (product + (the (unsigned-byte ,size*2) (* dst src))) + + (product-high + (mbe :logic (part-select product :low ,size :width ,size) + :exec (the (unsigned-byte ,size) + (ash (the (unsigned-byte ,size*2) product) ,neg-size)))) + (product-low + (mbe :logic (part-select product :low 0 :width ,size) + :exec (the (unsigned-byte ,size) (logand ,mask product))))) + + (mv product-high product-low product)) + + /// + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,size + :concl (mv-nth 0 (,fn-name dst src)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound ,size + :concl (mv-nth 1 (,fn-name dst src)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound ,size*2 + :concl (mv-nth 2 (,fn-name dst src)) + :hints (("Goal" :in-theory (e/d (unsigned-byte-p) ()))) + :gen-type t + :gen-linear t)) + )) + +(make-event (mul-spec-gen 8)) +(make-event (mul-spec-gen 16)) +(make-event (mul-spec-gen 32)) +(make-event (mul-spec-gen 64)) + +(define mul-spec + ((size :type (member 1 2 4 8)) + dst src) + :guard (case size + (1 (and (n08p src) (n08p dst))) + (2 (and (n16p src) (n16p dst))) + (4 (and (n32p src) (n32p dst))) + (8 (and (n64p src) (n64p dst))) + (otherwise nil)) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + :short "Specification for the @('MUL') (unsigned multiply) instruction" + + (case size + (1 (mul-spec-8 dst src)) + (2 (mul-spec-16 dst src)) + (4 (mul-spec-32 dst src)) + (8 (mul-spec-64 dst src)) + (otherwise (mv 0 0 0))) + + /// + + (defthm-unsigned-byte-p mv-nth-0-mul-spec + :hyp (member size '(1 2 4 8)) + :bound (ash size 3) + :concl (mv-nth 0 (mul-spec size dst src)) + :gen-linear t + :gen-type t) + + (defthm-unsigned-byte-p mv-nth-1-mul-spec + :hyp (member size '(1 2 4 8)) + :bound (ash size 3) + :concl (mv-nth 1 (mul-spec size dst src)) + :gen-linear t + :gen-type t) + + (defthm-unsigned-byte-p mv-nth-2-mul-spec + :hyp (member size '(1 2 4 8)) + :bound (* 2 (ash size 3)) + :concl (mv-nth 2 (mul-spec size dst src)) + :gen-linear t + :gen-type t) + + ) + +;; ====================================================================== +;; Signed multiply: IMUL +;; ====================================================================== + +(local + (encapsulate + () + + (local (include-book "arithmetic-5/top" :dir :system)) + + (defthm size-of-signed-multiplication-product + (implies (and (unsigned-byte-p size src) + (unsigned-byte-p size dst) + (natp size) + (< 0 size) + (equal size*2 (* 2 size))) + (signed-byte-p size*2 (* (logext size dst) (logext size src)))) + :hints (("Goal" :in-theory (e/d (logext loghead logapp logbitp) + ())))))) + + +(define imul-spec-gen ((size :type (member 8 16 32 64))) + :verify-guards nil + + (let* ((mask (1- (expt 2 size))) + (neg-size (- size)) + (size*2 (* 2 size)) + (fn-name (mk-name "IMUL-SPEC-" size)) + (str-nbits (if (eql size 8) "08" size))) + + `(define ,fn-name + ((dst :type (unsigned-byte ,size)) + (src :type (unsigned-byte ,size))) + + :parents (imul-spec) + :guard-hints (("Goal" :in-theory + (e/d (n08-to-i08 n16-to-i16 + n32-to-i32 n64-to-i64) + (unsigned-byte-p signed-byte-p)))) + + (b* ((dst-int (the (signed-byte ,size) (ntoi ,size dst))) + (src-int (the (signed-byte ,size) (ntoi ,size src))) + + (product-int (the (signed-byte ,size*2) + (* (the (signed-byte ,size) dst-int) + (the (signed-byte ,size) src-int)))) + (product (the (unsigned-byte ,size*2) (n-size ,size*2 product-int))) + + (product-high + (mbe :logic (part-select product :low ,size :width ,size) + :exec (the (unsigned-byte ,size) + (ash (the (unsigned-byte ,size*2) product) ,neg-size)))) + (product-low + (mbe :logic (part-select product :low 0 :width ,size) + :exec (the (unsigned-byte ,size) (logand ,mask product)))) + + (product-low-int (the (signed-byte ,size) + (ntoi ,size product-low))) + + (cf-and-of + ;; If product-low-int == product-int, then CF and OF + ;; should be cleared. Otherwise, they should be set. + (the (unsigned-byte 1) + (bool->bit + (not (equal + (the (signed-byte ,size) product-low-int) + (the (signed-byte ,size*2) product-int))))))) + + (mv product-high product-low product cf-and-of)) + + /// + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,size + :concl (mv-nth 0 (,fn-name dst src)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound ,size + :concl (mv-nth 1 (,fn-name dst src)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound ,size*2 + :concl (mv-nth 2 (,fn-name dst src)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-3-" fn-name) + :bound 1 + :concl (mv-nth 3 (,fn-name dst src)) + :gen-type t + :gen-linear t)) + )) + + +(make-event (imul-spec-gen 8)) +(make-event (imul-spec-gen 16)) +(make-event (imul-spec-gen 32)) +(make-event (imul-spec-gen 64)) + + +(define imul-spec + ((size :type (member 1 2 4 8)) + dst src) + :guard (case size + (1 (and (n08p src) (n08p dst))) + (2 (and (n16p src) (n16p dst))) + (4 (and (n32p src) (n32p dst))) + (8 (and (n64p src) (n64p dst))) + (otherwise nil)) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + :short "Specification for the @('IMUL') (unsigned imultiply) instruction" + + (case size + (1 (imul-spec-8 dst src)) + (2 (imul-spec-16 dst src)) + (4 (imul-spec-32 dst src)) + (8 (imul-spec-64 dst src)) + (otherwise (mv 0 0 0 0))) + + /// + + (defthm-unsigned-byte-p mv-nth-0-imul-spec + :hyp (member size '(1 2 4 8)) + :bound (ash size 3) + :concl (mv-nth 0 (imul-spec size dst src)) + :gen-linear t + :gen-type t) + + (defthm-unsigned-byte-p mv-nth-1-imul-spec + :hyp (member size '(1 2 4 8)) + :bound (ash size 3) + :concl (mv-nth 1 (imul-spec size dst src)) + :gen-linear t + :gen-type t) + + (defthm-unsigned-byte-p mv-nth-2-imul-spec + :hyp (member size '(1 2 4 8)) + :bound (* 2 (ash size 3)) + :concl (mv-nth 2 (imul-spec size dst src)) + :gen-linear t + :gen-type t) + + (defthm-unsigned-byte-p mv-nth-3-imul-spec + :hyp (member size '(1 2 4 8)) + :bound 1 + :concl (mv-nth 3 (imul-spec size dst src)) + :gen-linear t + :gen-type t) + + ) + +;; ====================================================================== + +(set-non-linearp nil) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply.lisp new file mode 100644 index 000000000..3c8417edd --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/multiply.lisp @@ -0,0 +1,545 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "multiply-spec") +(include-book "../decoding-and-spec-utils") +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; INSTRUCTION: MUL +;; ====================================================================== + +(def-inst x86-mul + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + ;; Note that the reg field serves as an opcode extension for this + ;; instruction. The reg field will always be 4 when this function + ;; is called. + + :guard (equal (modr/m->reg modr/m) 4) + + :long + "

Op/En: M

+ +

F6/4:
+ MUL r/m8: AX := AL \* r/m8

+ + F7/4:
+ MUL r/m16: DX:AX := AX \* r/m16
+ MUL r/m32: EDX:EAX := EAX \* r/m32
+ MUL r/m64: RDX:RAX := RAX \* r/m64

" + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + (select-byte-operand (equal opcode #xF6)) + ((the (integer 1 8) reg/mem-size) + (select-operand-size + proc-mode select-byte-operand rex-byte nil prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* reg/mem-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (rAX (rgfi-size reg/mem-size *rax* rex-byte x86)) + + ;; Computing the result: + ((mv product-high product-low product) + (mul-spec reg/mem-size rAX reg/mem)) + + ;; Updating the x86 state: + + (x86 + (case reg/mem-size + (1 ;; AX := AL * r/m8 + (let* ((x86 (!rgfi-size 2 *rax* product rex-byte x86))) + x86)) + (otherwise + (let* ((x86 ;; Write to rAX + (!rgfi-size reg/mem-size *rax* product-low + rex-byte x86)) + (x86 ;; Write to rDX + (!rgfi-size reg/mem-size *rdx* product-high + rex-byte x86))) + x86)))) + + (x86 + (if (equal product-high 0) + (let* ((x86 (!flgi :cf 0 x86)) + (x86 (!flgi-undefined :pf x86)) + (x86 (!flgi-undefined :af x86)) + (x86 (!flgi-undefined :zf x86)) + (x86 (!flgi-undefined :sf x86)) + (x86 (!flgi :of 0 x86))) + x86) + (let* ((x86 (!flgi :cf 1 x86)) + (x86 (!flgi-undefined :pf x86)) + (x86 (!flgi-undefined :af x86)) + (x86 (!flgi-undefined :zf x86)) + (x86 (!flgi-undefined :sf x86)) + (x86 (!flgi :of 1 x86))) + x86))) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: IMUL +;; ====================================================================== + +(def-inst x86-imul-Op/En-M + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + ;; Note that the reg field serves as an opcode extension for this + ;; instruction. The reg field will always be 5 when this function is + ;; called. + + :guard (equal (modr/m->reg modr/m) 5) + + :long + "

Op/En: M

+ +

F6/5:
+ IMUL r/m8: AX := AL \* r/m8

+ + F7/5:
+ IMUL r/m16: DX:AX := AX \* r/m16
+ IMUL r/m32: EDX:EAX := EAX \* r/m32
+ IMUL r/m64: RDX:RAX := RAX \* r/m64

" + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + (select-byte-operand (equal opcode #xF6)) + ((the (integer 1 8) reg/mem-size) + (select-operand-size + proc-mode select-byte-operand rex-byte nil prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* reg/mem-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (rAX (rgfi-size reg/mem-size *rax* rex-byte x86)) + + ;; Computing the result: + ((mv product-high product-low product (the (unsigned-byte 1) cf-and-of)) + (imul-spec reg/mem-size rAX reg/mem)) + + ;; Updating the x86 state: + + (x86 + (case reg/mem-size + (1 ;; AX := AL * r/m8 + (let* ((x86 (!rgfi-size 2 *rax* product rex-byte x86))) + x86)) + (otherwise + (let* ((x86 ;; Write to rAX + (!rgfi-size reg/mem-size *rax* product-low + rex-byte x86)) + (x86 ;; Write to rDX + (!rgfi-size reg/mem-size *rdx* product-high + rex-byte x86))) + x86)))) + + (x86 + (let* ((x86 (!flgi :cf cf-and-of x86)) + (x86 (!flgi-undefined :pf x86)) + (x86 (!flgi-undefined :af x86)) + (x86 (!flgi-undefined :zf x86)) + (x86 (!flgi-undefined :sf x86)) + (x86 (!flgi :of cf-and-of x86))) + x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-imul-Op/En-RM + + :parents (two-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + + :long + "

Op/En: RM

+ +

0F AF:
+ IMUL r16, r/m16: r16 := r16 \* r/m16
+ IMUL r32, r/m32: r32 := r32 \* r/m32
+ IMUL r64, r/m64: r64 := r64 \* r/m64

" + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* + (prefixes->adr prefixes))) + + ((the (integer 1 8) reg/mem-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* reg/mem-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + (register (rgfi-size reg/mem-size + (reg-index reg rex-byte #.*r*) + rex-byte + x86)) + + ;; Computing the result: + ((mv ?product-high product-low ?product (the (unsigned-byte 1) cf-and-of)) + (imul-spec reg/mem-size reg/mem register)) + + ;; Updating the x86 state: + (x86 + (!rgfi-size reg/mem-size + (reg-index reg rex-byte #.*r*) + product-low + rex-byte + x86)) + + (x86 + (let* ((x86 (!flgi :cf cf-and-of x86)) + (x86 (!flgi-undefined :pf x86)) + (x86 (!flgi-undefined :af x86)) + (x86 (!flgi-undefined :zf x86)) + (x86 (!flgi-undefined :sf x86)) + (x86 (!flgi :of cf-and-of x86))) + x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +(def-inst x86-imul-Op/En-RMI + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (force (force)))))) + + :long + "

Op/En: RMI

+ +

6B ib:
+ IMUL r16, r/m16, imm8
+ IMUL r32, r/m32, imm8
+ IMUL r64, r/m64, imm8

+ + 69 iw:
+ IMUL r16, r/m16, imm16
+ IMUL r32, r/m32, imm32
+ IMUL r64, r/m64, imm32

" + + :guard-hints (("Goal" :in-theory (enable rme-size-of-1-to-rme08 + rme-size-of-2-to-rme16 + rme-size-of-4-to-rme32))) + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 1 8) reg/mem-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + ((the (integer 1 4) imm-size) + (if (equal opcode #x6B) + 1 + ;; opcode = #x69 + (if (equal reg/mem-size 2) + 2 + 4))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 + reg/mem + (the (unsigned-byte 3) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* reg/mem-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + imm-size ;; imm-size bytes of immediate data + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + ((mv flg1 (the (unsigned-byte 32) imm) x86) + (rme-size-opt proc-mode imm-size temp-rip #.*cs* :x nil x86)) + ((when flg1) + (!!ms-fresh :rme-size-error flg1)) + + ;; Sign-extend the immediate to the operand size. + ;; Recall that imm is an unsigned integer of byte size imm-size. + ;; This is a no-op if imm-size = reg/mem-size. + ;; But if imm-size < reg/mem-size, + ;; the logext makes the integer negative if the high bit is set, + ;; and the loghead truncates the bits higher than the operand size. + ;; (It is never the case that imm-size > reg/mem-size.) + ;; IMUL-SPEC, called below, needs two unsigned operands of the same size, + ;; so here we ensure the immediate is of the same size, + ;; but taking the sign extension into account, + ;; as required in the Intel manual's description of IMUL. + ;; Then IMUL-SPEC internally takes care of + ;; interpreting the operands with the appropriate signs + ;; (based on their high bits), + ;; but here we need to ensure that + ;; we pass the appropriate values to IMUL-SPEC. + (imm (loghead (* 8 reg/mem-size) (logext (* 8 imm-size) imm))) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip imm-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error temp-rip)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Computing the result: + ((mv ?product-high product-low ?product (the (unsigned-byte 1) cf-and-of)) + (imul-spec reg/mem-size reg/mem imm)) + + ;; Updating the x86 state: + (x86 + (!rgfi-size reg/mem-size + (reg-index reg rex-byte #.*r*) + product-low + rex-byte + x86)) + + (x86 + (let* ((x86 (!flgi :cf cf-and-of x86)) + (x86 (!flgi-undefined :pf x86)) + (x86 (!flgi-undefined :af x86)) + (x86 (!flgi-undefined :zf x86)) + (x86 (!flgi-undefined :sf x86)) + (x86 (!flgi :of cf-and-of x86))) + x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: MULX +;; ====================================================================== + +(def-inst x86-mulx + + :returns (x86 x86p :hyp (x86p x86)) + + :parents (three-byte-opcodes) + + :short "MULX: Unsigned multiply without affecting flags." + + :modr/m t + + :vex t + + :guard (vex-prefixes-byte0-p vex-prefixes) + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ;; VEX.W selects a 64-bit operand only in 64-bit mode. + ;; In other modes the operand is always 32 bits, + ;; and the VEX register-extension bits are ignored: + ;; VEX.R and VEX.B via the zero REX byte here, + ;; and the high bit of VEX.vvvv via the masking further below + ;; (see Intel manual Volume 2 Section 2.3.5.6). + (64-bit-mode? (equal proc-mode #.*64-bit-mode*)) + (operand-size (if (and 64-bit-mode? + (equal (vex->w vex-prefixes) 1)) + 8 + 4)) + (rex-byte (if 64-bit-mode? + (rex-byte-from-vex-prefixes vex-prefixes) + 0)) + + ;; Read the explicit source specified by ModR/M.r/m. + ((mv flg src2 increment-rip-by & x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + operand-size + t ; inst-ac? + nil ; memory-ptr? + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; num-imm-bytes + x86)) + ((when flg) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) (!!fault-fresh :gp 0 :instruction-length badlength?)) + + ;; Read the implicit source EDX/RDX + ;; before writing the destinations, which may include it. + (src1 (rgfi-size operand-size *rdx* rex-byte x86)) + + ;; The product is the same as for MUL, just without the flag updates. + ((mv product-high product-low &) (mul-spec operand-size src1 src2)) + + ;; VEX.vvvv supplies the destination of the low half, + ;; and ModR/M.reg the destination of the high half. + ;; The high half is written last, so that it prevails + ;; when the two destinations are the same register, + ;; as the Intel manual prescribes. + ;; A 32-bit write also clears its upper half. + ;; No flags are read or written. + (low-reg (vex-vvvv-reg-index (vex->vvvv vex-prefixes))) + (low-reg (if 64-bit-mode? low-reg (loghead 3 low-reg))) + (x86 (!rgfi-size operand-size low-reg product-low rex-byte x86)) + (x86 (!rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + product-high + rex-byte + x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/or-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/or-spec.lisp new file mode 100644 index 000000000..1623beeef --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/or-spec.lisp @@ -0,0 +1,148 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +;; This book contains the specification of the following instructions: +;; or + +(include-book "structures" :dir :utils) +(include-book "../rflags-spec") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + + +;; ====================================================================== +;; SPECIFICATION: OR +;; ====================================================================== + +(define gpr-or-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-OR-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + :inline t + :no-function t + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + ((the (unsigned-byte ,result-nbits) result) + (mbe :logic (part-select (logior dst src) + :low 0 :width ,result-nbits) + :exec (logior dst src))) + + (cf 0) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + ;; AF is undefined. + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of 0) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags)))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + ;; AF is undefined. + (undefined-flags (!rflagsBits->af 1 0))) + + (mv result output-rflags undefined-flags)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-or-spec-gen-fn 1)) +(make-event (gpr-or-spec-gen-fn 2)) +(make-event (gpr-or-spec-gen-fn 4)) +(make-event (gpr-or-spec-gen-fn 8)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/rotate-and-shift.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/rotate-and-shift.lisp new file mode 100644 index 000000000..b742ce730 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/rotate-and-shift.lisp @@ -0,0 +1,625 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "shifts-spec") +(include-book "rotates-spec") +(include-book "../decoding-and-spec-utils") +;(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; INSTRUCTION: SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR +;; ====================================================================== + +(local + (defrule add-to-*ip-integerp-type + (implies (and (integerp *ip) + (integerp delta)) + (integerp (mv-nth 1 (add-to-*ip proc-mode *ip delta x86)))) + :in-theory (e/d (add-to-*ip) ()) + :rule-classes (:rewrite :type-prescription))) + +(local (in-theory (disable acl2::member-of-cons signed-byte-p))) + +(def-inst x86-sal/sar/shl/shr/rcl/rcr/rol/ror + + :guard (not (equal (modr/m->reg modr/m) 6)) + + :guard-hints (("Goal" + :in-theory (e/d () + (unsigned-byte-p + not force (force))))) + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory + (e/d () + (trunc + select-operand-size + mv-nth-0-of-add-to-*ip-when-64-bit-modep + mv-nth-1-of-add-to-*ip-when-64-bit-modep + signed-byte-p + unsigned-byte-p + not force (force)))))) + + :long + "

+ Op/En: MI
+ C0/0: ROL r/m8, imm8
+ C0/1: ROR r/m8, imm8
+ C0/2: RCL r/m8, imm8
+ C0/3: RCR r/m8, imm8
+ C0/4: SAL/SHL r/m8, imm8
+ C0/5: SHR r/m8, imm8
+ C0/7: SAR r/m8, imm8
+ C1/0: ROL r/m16/32/64, imm8
+ C1/1: ROR r/m16/32/64, imm8
+ C1/2: RCL r/m16/32/64, imm8
+ C1/3: RCR r/m16/32/64, imm8
+ C1/4: SAL/SHL r/m16/32/64, imm8
+ C1/5: SHR r/m16/32/64, imm8
+ C1/7: SAR r/m16/32/64. imm8
+

+ +

+ Op/En: M1
+ D0/0: ROL r/m8, 1
+ D0/1: ROR r/m8, 1
+ D0/2: RCL r/m8, 1
+ D0/3: RCR r/m8, 1
+ D0/4: SAL/SHL r/m8, 1
+ D0/5: SHR r/m8, 1
+ D0/7: SAR r/m8, 1
+ D1/0: ROL r/m16/32/64, 1
+ D1/1: ROR r/m16/32/64, 1
+ D1/2: RCL r/m16/32/64, 1
+ D1/3: RCR r/m16/32/64, 1
+ D1/4: SAL/SHL r/m16/32/64, 1
+ D1/5: SHR r/m16/32/64, 1
+ D1/7: SAR r/m16/32/64, 1
+

+ +

+ Op/En: MC
+ D2/0: ROL r/m8, CL
+ D2/1: ROR r/m8, CL
+ D2/2: RCL r/m8, CL
+ D2/3: RCR r/m8, CL
+ D2/4: SAL/SHL r/m8, CL
+ D2/5: SHR r/m8, CL
+ D2/7: SAR r/m8, CL
+ D3/0: ROL r/m16/32/64, CL
+ D3/1: ROR r/m16/32/64, CL
+ D3/2: RCL r/m16/32/64, CL
+ D3/3: RCR r/m16/32/64, CL
+ D3/4: SAL/SHL r/m16/32/64, CL
+ D3/5: SHR r/m16/32/64, CL
+ D3/7: SAR r/m16/32/64, CL
+

" + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + (byte-operand? (or (equal opcode #xC0) + (equal opcode #xD0) + (equal opcode #xD2))) + ((the (integer 0 8) ?reg/mem-size) + (select-operand-size + proc-mode byte-operand? rex-byte nil prefixes nil nil nil x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? t) + ((mv flg0 ?reg/mem (the (unsigned-byte 3) increment-RIP-by) addr x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* reg/mem-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + ;; Bytes of immediate data (only relevant when RIP-relative + ;; addressing is done to get ?reg/mem operand) + (if (or (equal opcode #xC0) + (equal opcode #xC1)) + 1 + 0) + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ((mv flg1 shift/rotate-by x86) + (case opcode + ((#xD0 #xD1) + (mv nil 1 x86)) + ((#xD2 #xD3) + (mv nil (rr08 *rcx* rex-byte x86) x86)) + ((#xC0 #xC1) + (rme-size-opt proc-mode 1 temp-rip #.*cs* :x nil x86)) + (otherwise ;; will not be reached + (mv nil 0 x86)))) + ((when flg1) + (!!ms-fresh :rme-size-error flg1)) + + ;; REX does not promote to 64-bits for byte-operand opcodes + (countMask (if (and (not byte-operand?) + (logbitp #.*w* rex-byte)) + #x3F + #x1F)) + (shift/rotate-by (logand countMask shift/rotate-by)) + + ((mv flg (the (signed-byte #.*max-linear-address-size+1*) temp-rip)) + (if (or (equal opcode #xC0) + (equal opcode #xC1)) + (add-to-*ip proc-mode temp-rip 1 x86) + (mv nil temp-rip))) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Computing the flags and the result: + (input-rflags (the (unsigned-byte 32) (rflags x86))) + + ((mv result + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (case reg + (0 + ;; ROL + (rol-spec reg/mem-size reg/mem shift/rotate-by input-rflags)) + (1 + ;; ROR + (ror-spec reg/mem-size reg/mem shift/rotate-by input-rflags)) + (2 + ;; RCL + (rcl-spec reg/mem-size reg/mem shift/rotate-by input-rflags)) + (3 + ;; RCR + (rcr-spec reg/mem-size reg/mem shift/rotate-by input-rflags)) + (4 + ;; SAL/SHL + (sal/shl-spec reg/mem-size reg/mem shift/rotate-by input-rflags)) + (5 + ;; SHR + (shr-spec reg/mem-size reg/mem shift/rotate-by input-rflags)) + (7 + ;; SAR + (sar-spec reg/mem-size reg/mem shift/rotate-by input-rflags)) + ;; The guard for this function will ensure that we don't + ;; reach here. + (otherwise + (mv 0 0 0)))) + + ;; Update the x86 state: + + (x86 (write-user-rflags output-rflags undefined-flags x86)) + + ((mv flg2 x86) + (x86-operand-to-reg/mem proc-mode reg/mem-size + inst-ac? + nil ;; Not a memory pointer operand + ;; TO-DO@Shilpi: Remove this trunc. + (trunc reg/mem-size result) + seg-reg + addr + rex-byte + r/m + mod + x86)) + ;; Note: If flg2 is non-nil, we bail out without changing the x86 state. + ((when flg2) + (!!ms-fresh :x86-operand-to-reg/mem flg2)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: SHLD/SHRD +;; ====================================================================== + +(def-inst x86-shld/shrd + + :returns (x86 x86p :hyp (x86p x86)) + + :parents (two-byte-opcodes) + + :short "Double-precision shift left or right." + + :long + "

+ Op/En: MRI
+ 0F A4: SHLD r/m16, r16, imm8
+ 0F A4: SHLD r/m32, r32, imm8
+ 0F A4: SHLD r/m64, r64, imm8
+

+ +

+ Op/En: MRC
+ 0F A5: SHLD r/m16, r16, CL
+ 0F A5: SHLD r/m32, r32, CL
+ 0F A5: SHLD r/m64, r64, CL
+

+ +

+ Op/En: MRI
+ 0F AC: SHRD r/m16, r16, imm8
+ 0F AC: SHRD r/m32, r32, imm8
+ 0F AC: SHRD r/m64, r64, imm8
+

+ +

+ Op/En: MRC
+ 0F AD: SHRD r/m16, r16, CL
+ 0F AD: SHRD r/m32, r32, CL
+ 0F AD: SHRD r/m64, r64, CL
+

" + + :modr/m t + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + + ((the (integer 2 8) operand-size) + (select-operand-size proc-mode + nil ; not a byte operand + rex-byte + nil ; not an immediate operand + prefixes + nil ; no 64-bit default in 64-bit mode + nil ; don't ignore REX in 64-bit mode + nil ; don't ignore P3 in 64-bit mode + x86)) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ;; read destination operand: + + (inst-ac? t) + (num-imm-bytes (if (member opcode '(#xa4 #xac)) 1 0)) + ((mv flg dst-value increment-rip-by dst-addr x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + operand-size + inst-ac? + nil ; not memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod sib + num-imm-bytes + x86)) + ((when flg) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ;; read source operand: + + (src-value (rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + rex-byte + x86)) + + ;; read count operand: + + ((mv flg count x86) + (case opcode + ((#xA4 #xAC) (rme-size-opt proc-mode 1 temp-rip #.*cs* :x nil x86)) + ((#xA5 #xAD) (mv nil (rr08 *rcx* rex-byte x86) x86)) + (otherwise (mv nil 0 x86)))) ; unreachable + ((when flg) (!!ms-fresh :rme-size-error flg)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (case opcode + ((#xA4 #xAC) (add-to-*ip proc-mode temp-rip 1 x86)) + ((#xA5 #xAD) (mv nil temp-rip)) + (otherwise (mv nil 0)))) ; unreachable + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ;; check instruction length now that we have read all of it: + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; mask count according to pseudocode (the text only mentions masking + ;; when CL is used, but the pseudocode masks also if imm8 is used): + + (count-mask (if (logbitp #.*w* rex-byte) + #x3f + #x1f)) + (count (logand count-mask count)) + + ;; compute result and flags: + + (input-rflags (the (unsigned-byte 32) (rflags x86))) + + ((mv result + result-undefined? + (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + (case opcode + ((#xA4 #xA5) (shld-spec + operand-size dst-value src-value count input-rflags)) + ((#xAC #xAD) (shrd-spec + operand-size dst-value src-value count input-rflags)) + (otherwise (mv 0 nil 0 0)))) ; unreachable + + ((mv result x86) + (if result-undefined? + (undef-read x86) + (mv result x86))) + + ;; update the state: + + (x86 (write-user-rflags output-rflags undefined-flags x86)) + + ((mv flg x86) + (x86-operand-to-reg/mem proc-mode + operand-size + inst-ac? + nil ;; not memory pointer operand + (trunc operand-size result) ; TODO: remove trunc + seg-reg + dst-addr + rex-byte + r/m + mod + x86)) + ((when flg) (!!ms-fresh :x86-operand-to-reg/mem flg)) + + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;; ====================================================================== +;; INSTRUCTION: SARX/SHLX/SHRX +;; ====================================================================== + +(def-inst x86-sarx/shlx/shrx + + :returns (x86 x86p :hyp (x86p x86)) + + :parents (three-byte-opcodes) + + :short "SARX/SHLX/SHRX: Shift without affecting flags." + + :vex t + + :modr/m t + + :guard (vex-prefixes-byte0-p vex-prefixes) + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (rex-byte (rex-byte-from-vex-prefixes vex-prefixes)) + + ;; The operand size is always 32 in 32-bit mode. + ;; In 64-bit mode, it is 32 or 64 based on whether VEX.W is 0 or 1. + ((the (integer 4 8) operand-size) + (if (and (equal proc-mode #.*64-bit-mode*) + (equal (vex->w vex-prefixes) 1)) + 8 + 4)) + + ;; Since the Intel manual does not say anything specific about registers, + ;; the registers for the operands must be the general-purpose ones. + ;; This is confirmed by looking at some disassembled code. + + ;; The first source operand, i.e. Operand 2 in the Intel manual, + ;; is specified in the Mod and R/M bits of the ModR/M byte. + ;; This operand is the value to be shifted. + ;; We ignore the returned address of the operand, + ;; because the operand is only used as source in these instructions. + (inst-ac? t) + ((mv flg val-to-shift increment-rip-by & x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + *gpr-access* + operand-size + inst-ac? + nil ; not memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ; num-imm-bytes + x86)) + ((when flg) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; The second source operand, i.e. Operand 3 in the Intel manual, + ;; is specified in the vvvv bits of the VEX prefix, + ;; in negated (one's complement) form; + ;; see Figure 2-9 of the Intel manual Volume 2 of Dec 2023. + ;; This operand is the count by which + ;; the other source operand must be shifted. + ;; Based on the operand size, + ;; the count is masked to keep the low 5 or 6 bits, + ;; as specified in the pseudocode of the Intel manual + ;; for these instructions. + (cnt-reg (vex-vvvv-reg-index (vex->vvvv vex-prefixes))) + (cnt-to-shift (rgfi-size operand-size + cnt-reg + rex-byte + x86)) + (cnt-mask (if (= operand-size 4) #x1f #x3f)) + (cnt-to-shift (logand cnt-to-shift cnt-mask)) + + ;; We calculate the result of the shift, + ;; based on the pp bits in the VEX prefixes, + ;; which provide an opcode extension + ;; to select one of the three instructions. + ;; See Figure 2-9 of Intel manual Volume 2 of Dec 2023. + (result (case (vex->pp vex-prefixes) + (#b01 (shlx-spec operand-size val-to-shift cnt-to-shift)) ; 66 + (#b10 (sarx-spec operand-size val-to-shift cnt-to-shift)) ; F2 + (#b11 (shrx-spec operand-size val-to-shift cnt-to-shift)) ; F3 + (otherwise 0))) ; cannot happen + + ;; The destination operand, i.e. Operand 1 in the Intel manual, + ;; is specified in the Reg/Opcode bits of the ModR/M byte, + ;; where in this case those bits specify a register + ;; (not an opcode extension). + ;; So we store the result into that register. + (x86 (!rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + result + rex-byte + x86)) + + ;; Update the program counter. + (x86 (write-*ip proc-mode temp-rip x86))) + + x86) + + :guard-hints (("Goal" :in-theory (enable shlx-spec sarx-spec shrx-spec)))) + +;; ====================================================================== +;; INSTRUCTION: RORX +;; ====================================================================== + +(def-inst x86-rorx + + :returns (x86 x86p :hyp (x86p x86)) + + :parents (three-byte-opcodes) + + :short "RORX: Rotate right without affecting flags." + + :modr/m t + + :vex t + + :guard (vex-prefixes-byte0-p vex-prefixes) + + :body + + (b* ((p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ;; VEX.W selects a 64-bit operand only in 64-bit mode. + ;; In other modes the operand is always 32 bits, + ;; and the VEX register-extension bits (in particular VEX.B) are ignored. + (64-bit-mode? (equal proc-mode #.*64-bit-mode*)) + (operand-size (if (and 64-bit-mode? + (equal (vex->w vex-prefixes) 1)) + 8 + 4)) + (rex-byte (if 64-bit-mode? + (rex-byte-from-vex-prefixes vex-prefixes) + 0)) + + ;; Read the source specified by ModR/M.r/m. + ;; Include the immediate byte in RIP-relative address calculation. + ((mv flg src increment-rip-by & x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*gpr-access* + operand-size + t ; inst-ac? + nil ; memory-ptr? + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 1 ; num-imm-bytes + x86)) + ((when flg) (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg)) + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ;; Read the imm8. + ((mv flg cnt x86) (rme08 proc-mode temp-rip #.*cs* :x x86)) + ((when flg) (!!ms-fresh :imm-rme08-error flg)) + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) (!!fault-fresh :gp 0 :instruction-length badlength?)) + + (result (rorx-spec operand-size src cnt)) + ;; ModR/M.reg supplies the destination. + ;; A 32-bit write also clears its upper half, + ;; even when the masked rotation count is zero. + ;; No flags are read or written. + (x86 (!rgfi-size operand-size + (reg-index reg rex-byte #.*r*) + result + rex-byte + x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/shifts-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/shifts-spec.lisp new file mode 100644 index 000000000..96b197586 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/shifts-spec.lisp @@ -0,0 +1,1724 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) + +;; This book contains the specification of the following instructions: +;; sal sar shl shr +;; sarx shlx shrx +;; shld shrd + +(in-package "X86ISA") + +(include-book "structures" :dir :utils) +(include-book "../rflags-spec") +(include-book "centaur/bitops/fast-rotate" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (in-theory (e/d () + (bitops::logand-with-negated-bitmask + force (force))))) + +;; Note: SRC (for SAL/SAR/SHL/SHR) or CNT (for SARX/SHLX/SHRX and SHLD/SHRD) +;; operand is either an (unsigned-byte 6) or (unsigned-byte 5) +;; since it is masked before the actual rotate or shift operations. + +;; ---------------------------------------------------------------------- + +;; Shifts: + +(local (include-book "arithmetic/top-with-meta" :dir :system)) + +(local + (defthm logbitp-and-logtail-thm + (implies (and (bind-free + (list (list (cons 'n ''8)) + (list (cons 'n ''16)) + (list (cons 'n ''32)) + (list (cons 'n ''64))) + (n)) + (natp dst) + (< dst (expt 2 n)) + (natp n) + (natp m) + (< m n)) + (equal (bool->bit (logbitp m dst)) + (logand 1 (logtail m dst)))) + :hints (("Goal" :in-theory (e/d* (bool->bit + acl2::logtail** + acl2::ihsext-inductions + acl2::unsigned-byte-p**) + (unsigned-byte-p)))))) + +(local (in-theory (e/d (loghead-to-logand + acl2::bitp) + (bitops::logand-with-bitmask)))) + +(defthm logand-2^32-1-rflagsbits + (b* ((rflagsbits (rflagsbits cf res1 pf res2 + af res3 zf sf tf intf df of iopl + nt res4 rf vm ac vif vip id res5))) + (equal (logand #xFFFFFFFF rflagsbits) + rflagsbits)) + :hints (("Goal" + :use ((:instance rflagsbits-p-of-rflagsbits)) + :in-theory (e/d (rflagsbits-p) (rflagsbits-p-of-rflagsbits + unsigned-byte-p))))) + +;;;;;;;;;; SAL/SHL: + +(define sal/shl-spec-gen ((size :type (member 8 16 32 64))) + :verify-guards nil + + (b* ((size-1 (1- size)) + (neg-size-1 (- size-1)) + (fn-name (mk-name "SAL/SHL-SPEC-" size)) + (str-nbits (if (eql size 8) "08" size))) + + `(define ,fn-name + ((dst :type (unsigned-byte ,size)) + (src :type (unsigned-byte 6) + "Note that @('src') is masked appropriately + by the caller of this function.") + (input-rflags :type (unsigned-byte 32))) + + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + (unsigned-byte-p + (tau-system))))) + :parents (sal/shl-spec) + + (b* ((dst (mbe :logic (n-size ,size dst) + :exec dst)) + (src (mbe :logic (n-size 6 src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + (raw-result (ash dst src)) + (result (the (unsigned-byte ,size) (n-size ,size raw-result))) + + ((mv (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + + (case src + (0 + ;; No flags affected. + (mv input-rflags 0)) + + (1 + ;; All flags, but AF, are changed accordingly. AF is + ;; undefined. + (b* ((cf + ;; CF contains the last bit shifted out of the operand. + (mbe + :logic (part-select + dst + :low ,size-1 + :width 1) + :exec + (the (unsigned-byte 1) + (logand 1 + (the (unsigned-byte ,size) + (ash (the (unsigned-byte ,size) dst) + ,neg-size-1)))))) + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + (of + ;; OF is set when the top two bits of the original + ;; operand are the same. + (b-xor cf + (mbe :logic (logbit ,size-1 result) + :exec (the (unsigned-byte 1) + (logand 1 + (the (unsigned-byte 1) + (ash (the (unsigned-byte ,size) + result) + ,neg-size-1))))))) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags)))))))) + + (undefined-flags (!rflagsBits->af 1 0))) + + (mv output-rflags undefined-flags))) + + (otherwise + (if (<= ,size src) + ;; CF is undefined for SHL and SHR where the src + ;; is >= the width of the destination operand. OF and + ;; AF are also undefined. Other flags are affected as + ;; usual. + (b* ( ;; CF is undefined. + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + ;; OF is undefined. + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags)))))) + + (undefined-flags (mbe :logic + (change-rflagsBits + 0 + :cf 1 + :af 1 + :of 1) + :exec + (!rflagsBits->cf + 1 + (!rflagsBits->af + 1 + (!rflagsBits->of + 1 0)))))) + (mv output-rflags undefined-flags)) + + ;; OF and AF are undefined. Other flags are affected as + ;; usual. + (b* ((cf + ;; CF contains the last bit shifted out + ;; of the operand. + (part-select dst :low (- ,size src) :width 1)) + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + ;; OF is undefined. + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags))))))) + + (undefined-flags (mbe :logic + (change-rflagsBits + 0 + :af 1 + :of 1) + :exec + (!rflagsBits->af + 1 + (!rflagsBits->of + 1 + 0))))) + (mv output-rflags undefined-flags)))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags (mbe :logic (n32 undefined-flags) + :exec undefined-flags))) + + (mv result output-rflags undefined-flags)) + + /// + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,size + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (sal/shl-spec-gen 8)) +(make-event (sal/shl-spec-gen 16)) +(make-event (sal/shl-spec-gen 32)) +(make-event (sal/shl-spec-gen 64)) + +(define sal/shl-spec + ((size :type (member 1 2 4 8)) + dst src + (input-rflags :type (unsigned-byte 32))) + :guard (and (n06p src) + (case size + (1 (n08p dst)) + (2 (n16p dst)) + (4 (n32p dst)) + (8 (n64p dst)) + (otherwise nil))) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SAL/SHL') instruction" + + :long "

Source: Intel Manual, Volume 2B, Instruction Set Reference +\(N-Z\).

+ +

The shift arithmetic left \(SAL\) and shift logical left \(SHL\) +instructions perform the same operation; they shift the bits in the +destination operand to the left \(toward more significant bit +locations\). For each shift count, the most significant bit of the +destination operand is shifted into the CF flag, and the least +significant bit is cleared. The OF flag is affected only on 1-bit +shifts. For left shifts, the OF flag is set to 0 if the +most-significant bit of the result is the same as the CF flag (that +is, the top two bits of the original operand were the same); +otherwise, it is set to 1.

" + + (case size + (1 (sal/shl-spec-8 dst src input-rflags)) + (2 (sal/shl-spec-16 dst src input-rflags)) + (4 (sal/shl-spec-32 dst src input-rflags)) + (8 (sal/shl-spec-64 dst src input-rflags)) + (otherwise (mv 0 0 0))) + + /// + + (defthm natp-mv-nth-0-sal/shl-spec + (natp (mv-nth 0 (sal/shl-spec size dst src input-rflags))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p n32p-mv-nth-1-sal/shl-spec + :bound 32 + :concl (mv-nth 1 (sal/shl-spec size dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mv-nth-2-sal/shl-spec + :bound 32 + :concl (mv-nth 2 (sal/shl-spec size dst src input-rflags)) + :gen-type t + :gen-linear t)) + +;;;;;;;;;; SHR: + +(define shr-spec-gen ((size :type (member 8 16 32 64))) + :verify-guards nil + + (b* ((size-1 (1- size)) + (size+1 (1+ size)) + (neg-size-1 (- size-1)) + (fn-name (mk-name "SHR-SPEC-" size)) + (?str-nbits (if (eql size 8) "08" size))) + + `(define ,fn-name + ((dst :type (unsigned-byte ,size)) + (src :type (unsigned-byte 6) + "Note that @('src') is masked appropriately + by the caller of this function.") + (input-rflags :type (unsigned-byte 32))) + + :parents (shr-spec) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + (unsigned-byte-p + (tau-system))))) + + (b* ((dst (mbe :logic (n-size ,size dst) + :exec dst)) + (src (mbe :logic (n-size 6 src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + (neg-src (the (signed-byte ,size+1) (- src))) + (raw-result (the (unsigned-byte ,size) + (ash + (the (unsigned-byte ,size) dst) + (the (signed-byte ,size+1) neg-src)))) + (result (the (unsigned-byte ,size) (n-size ,size raw-result))) + + ((mv (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + + (case src + (0 + ;; No flags affected. + (mv input-rflags 0)) + + (1 + (b* + ((cf (mbe :logic (part-select dst :low 0 :width 1) + :exec (the (unsigned-byte 1) + (logand 1 (the (unsigned-byte ,size) + dst))))) + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + (of (mbe :logic (part-select dst :low ,size-1 :width 1) + :exec (the (unsigned-byte 1) + (ash (the (unsigned-byte ,size) dst) + ,neg-size-1)))) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags)))))))) + (undefined-flags (the (unsigned-byte 32) + (!rflagsBits->af 1 0)))) + (mv output-rflags undefined-flags))) + + (otherwise + (if (<= ,size src) + (b* ( + ;; CF is undefined. + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + ;; OF is undefined. + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags)))))) + + (undefined-flags (mbe :logic + (change-rflagsBits + 0 + :cf 1 + :af 1 + :of 1) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + 1 + (!rflagsBits->af + 1 + (!rflagsBits->of + 1 + 0))))))) + + (mv output-rflags undefined-flags)) + + (b* ((cf (mbe :logic (part-select dst :low (1- src) :width 1) + :exec (let* ((shft + (the (signed-byte ,size) + (- 1 + (the (unsigned-byte ,size) src))))) + (the (unsigned-byte 1) + (logand + 1 + (the (unsigned-byte ,size) + (ash + (the (unsigned-byte ,size) dst) + (the (signed-byte ,size) shft)))))))) + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + ;; OF is undefined. + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags))))))) + + (undefined-flags (mbe :logic + (change-rflagsBits + 0 + :af 1 + :of 1) + :exec + (!rflagsBits->af + 1 + (!rflagsBits->of + 1 0))))) + (mv output-rflags undefined-flags)))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags (mbe :logic (n32 undefined-flags) + :exec undefined-flags))) + + (mv result output-rflags undefined-flags)) + + /// + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,size + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(local + (defthm logand-1-and-logtail-thm + (implies (and (unsigned-byte-p (1+ n) dst) + (natp n)) + (equal (logand 1 (logtail n dst)) + (logtail n dst))) + :hints (("Goal" :in-theory (e/d* (bool->bit + acl2::logtail** + acl2::ihsext-inductions + acl2::unsigned-byte-p**) + (unsigned-byte-p)))))) + +(make-event (shr-spec-gen 8)) +(make-event (shr-spec-gen 16)) +(make-event (shr-spec-gen 32)) +(make-event (shr-spec-gen 64)) + +(define shr-spec + ((size :type (member 1 2 4 8)) + dst src + (input-rflags :type (unsigned-byte 32))) + :guard (and (unsigned-byte-p 6 src) + (case size + (1 (n08p dst)) + (2 (n16p dst)) + (4 (n32p dst)) + (8 (n64p dst)) + (otherwise nil))) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SHR') instruction" + + :long "

Source: Intel Manual, Volume 2B, Instruction Set Reference \(N-Z\).

+ +

The shift arithmetic right \(SAR\) and shift logical right \(SHR\) +instructions shift the bits of the destination operand to the right +\(toward less significant bit locations\). For each shift count, the +least significant bit of the destination operand is shifted into the +CF flag, and the most significant bit is either set or cleared +depending on the instruction type. The SHR instruction clears the most +significant bit (see Figure 7-8 in the Intel 64 and IA-32 +Architectures Software Developer s Manual, Volume 1)... The OF flag is +affected only on 1-bit shifts. For the SAR instruction, the OF flag is +cleared for all 1-bit shifts. For the SHR instruction, the OF flag is +set to the most-significant bit of the original operand.

" + + (case size + (1 (shr-spec-8 dst src input-rflags)) + (2 (shr-spec-16 dst src input-rflags)) + (4 (shr-spec-32 dst src input-rflags)) + (8 (shr-spec-64 dst src input-rflags)) + (otherwise (mv 0 0 0))) + + /// + + (defthm natp-mv-nth-0-shr-spec + (natp (mv-nth 0 (shr-spec size dst src input-rflags))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p n32p-mv-nth-1-shr-spec + :bound 32 + :concl (mv-nth 1 (shr-spec size dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mv-nth-2-shr-spec + :bound 32 + :concl (mv-nth 2 (shr-spec size dst src input-rflags)) + :gen-type t + :gen-linear t)) + +;;;;;;;;;; SAR: + +(define sar-spec-gen ((size :type (member 8 16 32 64))) + :verify-guards nil + + (b* ((size+1 (1+ size)) + (size-1 (1- size)) + (neg-size-1 (- size-1)) +; (size-mask (1- (expt 2 size))) + (fn-name (mk-name "SAR-SPEC-" size)) + (?str-nbits (if (eql size 8) "08" size))) + + `(define ,fn-name + ((dst :type (unsigned-byte ,size)) + (src :type (unsigned-byte 6) + "Note that @('src') is masked appropriately + by the caller of this function.") + (input-rflags :type (unsigned-byte 32))) + + :parents (sar-spec) + :guard-hints + (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + (unsigned-byte-p + bitops::logbit-to-logbitp + (tau-system)))) + (and stable-under-simplificationp + '(:in-theory (enable bitops::logbit-to-logbitp)))) + :prepwork + ((local + (defthm sar-spec-helper + (implies (unsigned-byte-p ,size dst) + (equal (logand ,(1- (expt 2 size)) (logtail src dst)) + (logtail src dst))) + :hints (("Goal" + :do-not-induct t + :use ((:instance unsigned-byte-p-of-logtail + (size1 ,size) + (size src) + (i dst))) + :in-theory (e/d* () + (unsigned-byte-p + unsigned-byte-p-of-logtail)))))) + + (local + (defthm sar-spec-helper-2 + (implies (unsigned-byte-p (1+ n) x) + (equal (logbit n x) + (logtail n x))) + :hints (("Goal" :in-theory + (e/d (bitops::logbitp** bitops::logbitp-induct + bitops::logtail** bitops::logtail-induct + bitops::unsigned-byte-p**) + (unsigned-byte-p))))))) + + (b* ((dst (mbe :logic (n-size ,size dst) + :exec dst)) + (src (mbe :logic (n-size 6 src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + (neg-src (the (signed-byte ,size+1) (- src))) + (raw-result-not-sign-extended + (the (unsigned-byte ,size) + (ash + (the (unsigned-byte ,size) dst) + (the (signed-byte ,size+1) neg-src)))) + (raw-result + (if (eql (mbe :logic (logbit ,size-1 dst) + :exec (the (unsigned-byte 1) + (ash (the (unsigned-byte ,size) + dst) + ,neg-size-1))) + 1) + (loghead ,size + (ash + (mbe :logic (logext ,size dst) + :exec (bitops::fast-logext ,size dst)) + neg-src)) +; (the (unsigned-byte ,size) +; (logior ,size-mask raw-result-not-sign-extended)) + raw-result-not-sign-extended)) + (result (mbe :logic (n-size ,size raw-result) + :exec raw-result)) + + ((mv (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + + (case src + (0 + ;; No flags affected. + (mv input-rflags 0)) + + (1 + (b* ((cf (mbe :logic (part-select dst :low 0 :width 1) + :exec (the (unsigned-byte 1) + (logand 1 (the (unsigned-byte ,size) + dst))))) + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + (of 0) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags)))))))) + + (undefined-flags + (the (unsigned-byte 32) + (!rflagsBits->af 1 0)))) + (mv output-rflags undefined-flags))) + + (otherwise + (b* ((cf (if (<= ,size src) + (mbe :logic (part-select dst :low ,size-1 :width 1) + :exec (let* ((shft (the (signed-byte ,size) ,neg-size-1))) + (the (unsigned-byte 1) + (ash + (the (unsigned-byte ,size) dst) + (the (signed-byte ,size) shft))))) + (mbe :logic (part-select dst :low (1- src) :width 1) + :exec (let* ((shft + (the (signed-byte ,size) + (- 1 + (the (unsigned-byte ,size) src))))) + (the (unsigned-byte 1) + (logand + 1 + (the (unsigned-byte ,size) + (ash + (the (unsigned-byte ,size) dst) + (the (signed-byte ,size) shft))))))))) + (pf (general-pf-spec ,size result)) + ;; AF is undefined. + (zf (zf-spec result)) + (sf (general-sf-spec ,size result)) + ;; OF is undefined. + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags))))))) + + (undefined-flags (mbe :logic + (change-rflagsBits + 0 + :af 1 + :of 1) + :exec + (the (unsigned-byte 32) + (!rflagsBits->af + 1 + (!rflagsBits->of + 1 + 0)))))) + (mv output-rflags undefined-flags))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags (mbe :logic (n32 undefined-flags) + :exec undefined-flags))) + + (mv result output-rflags undefined-flags)) + + /// + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,size + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (sar-spec-gen 8)) +(make-event (sar-spec-gen 16)) +(make-event (sar-spec-gen 32)) +(make-event (sar-spec-gen 64)) + +(define sar-spec + ((size :type (member 1 2 4 8)) + dst src + (input-rflags :type (unsigned-byte 32))) + :guard (and (n06p src) + (case size + (1 (n08p dst)) + (2 (n16p dst)) + (4 (n32p dst)) + (8 (n64p dst)) + (otherwise nil))) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SAR') instruction" + + :long "

Source: Intel Manual, Volume 2B, Instruction Set Reference \(N-Z\).

+ +

The shift arithmetic right \(SAR\) and shift logical right \(SHR\) +instructions shift the bits of the destination operand to the right +\(toward less significant bit locations\). For each shift count, the +least significant bit of the destination operand is shifted into the +CF flag, and the most significant bit is either set or cleared +depending on the instruction type. The SAR instruction sets or clears +the most significant bit to correspond to the sign \(most significant +bit\) of the original value in the destination operand. In effect, the +SAR instruction fills the empty bit position s shifted value with the +sign of the unshifted value. ... The OF flag is affected only on 1-bit +shifts. For the SAR instruction, the OF flag is cleared for all 1-bit +shifts. For the SHR instruction, the OF flag is set to the +most-significant bit of the original operand.

" + + (case size + (1 (sar-spec-8 dst src input-rflags)) + (2 (sar-spec-16 dst src input-rflags)) + (4 (sar-spec-32 dst src input-rflags)) + (8 (sar-spec-64 dst src input-rflags)) + (otherwise (mv 0 0 0))) + + /// + + (defthm natp-mv-nth-0-sar-spec + (natp (mv-nth 0 (sar-spec size dst src input-rflags))) + :rule-classes :type-prescription) + + (defthm-unsigned-byte-p n32p-mv-nth-1-sar-spec + :bound 32 + :concl (mv-nth 1 (sar-spec size dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mv-nth-2-sar-spec + :bound 32 + :concl (mv-nth 2 (sar-spec size dst src input-rflags)) + :gen-type t + :gen-linear t)) + +;;;;;;;;;; SHLD: + +(define shld-spec-gen ((size :type (member 16 32 64))) + :verify-guards nil + + (b* ((size-1 (1- size)) + (neg-size-1 (- size-1)) + (size*2 (* 2 size)) + (fn-name (mk-name "SHLD-SPEC-" size))) + + `(define ,fn-name + ((dst :type (unsigned-byte ,size)) + (src :type (unsigned-byte ,size)) + (cnt :type (unsigned-byte 6) + "Note that @('cnt') is masked appropriately + by the caller of this function.") + (input-rflags :type (unsigned-byte 32))) + :returns (mv output-dst ; result (irrelevant if undefined-dst? is t) + undefined-dst? ; true iff result of operation is undefined + output-rflags ; output flags, ignoring the undefined ones + undefined-flags) ; flags to set to undefined values + + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + (unsigned-byte-p + (tau-system))))) + + :parents (shld-spec) + + (b* ((dst (mbe :logic (n-size ,size dst) + :exec dst)) + (src (mbe :logic (n-size ,size src) + :exec src)) + (cnt (mbe :logic (n-size 6 cnt) + :exec cnt)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + ;; we juxtapose dst and src, + ;; by shifting dst to the left by size bits + ;; and OR'ing that with src, + ;; obtaining a 2*size bit value: + (dst-src (the (unsigned-byte ,size*2) + (logior (the (unsigned-byte ,size*2) + (ash (the (unsigned-byte ,size) dst) + ,size)) + (the (unsigned-byte ,size) src)))) + ;; we shift the juxtaposed dst and src to the left by cnt bits, + ;; so that the high bits of src go into the low bits of dst: + (output-dst (the (unsigned-byte ,size) + ;; Our result is in the 2*size-1:size bits + (n-size ,size + (logtail ,size + (ash (the (unsigned-byte ,size*2) + dst-src) + (the (unsigned-byte ,size) + cnt)))))) + + ((mv (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + + (case cnt + + (0 + ;; no flags affected + (mv input-rflags 0)) + + (1 + ;; all flags but AF changed accordingly, AF undefined: + (b* ((cf ; last bit shifted out of dst, i.e. highest bit + (mbe :logic (part-select dst :low ,size-1 :width 1) + :exec (the (unsigned-byte 1) + (logand (the (unsigned-byte ,size) + (ash + (the (unsigned-byte ,size) + dst) + ,neg-size-1)) + 1)))) + (of ; set iff a sign change occurred + (if (= (logbit ,size-1 dst) + (logbit ,size-1 output-dst)) + 0 + 1)) + (pf (general-pf-spec ,size output-dst)) + (zf (zf-spec output-dst)) + (sf (general-sf-spec ,size output-dst)) + (output-rflags (mbe + :logic + (change-rflagsBits + input-rflags + :cf cf + :of of + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->of + of + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags)))))))) + (undefined-flags (the (unsigned-byte 32) + (!rflagsBits->af 1 0)))) + (mv output-rflags undefined-flags))) + + (otherwise + + (if (<= cnt ,size) + ;; all flags but OF and AF changed accordingly, + ;; OF and AF undefined: + (b* ((cf ; last bit shifted out of dst + (mbe :logic (part-select dst + :low (- ,size cnt) + :width 1) + :exec (logand + 1 + (the (unsigned-byte ,size) + (ash (the (unsigned-byte ,size) dst) + (the (signed-byte 7) + (- cnt ,size))))))) + (pf (general-pf-spec ,size output-dst)) + (zf (zf-spec output-dst)) + (sf (general-sf-spec ,size output-dst)) + (output-rflags (mbe + :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags))))))) + (undefined-flags (mbe + :logic + (change-rflagsBits + 0 + :af 1 + :of 1) + :exec + (!rflagsBits->af + 1 + (!rflagsBits->of + 1 0))))) + (mv output-rflags undefined-flags)) + + ;; all flags undefined if cnt > size: + (b* ((output-rflags input-rflags) + (undefined-flags (the (unsigned-byte 32) + (!rflagsBits->cf + 1 + (!rflagsBits->of + 1 + (!rflagsBits->pf + 1 + (!rflagsBits->zf + 1 + (!rflagsBits->sf + 1 + (!rflagsBits->af + 1 + input-rflags))))))))) + (mv output-rflags undefined-flags)))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags (mbe :logic (n32 undefined-flags) + :exec undefined-flags))) + + (mv output-dst + (> cnt ,size) ; result undefined if count exceeds operand size + output-rflags + undefined-flags)) + + /// + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p ,(mk-name "N" size "-MV-NTH-0-" fn-name) + :bound ,size + :concl (mv-nth 0 (,fn-name dst src cnt input-rflags)) + :hints (("Goal" :in-theory (enable bool->bit))) + :gen-type t + :gen-linear t) + + (defthm ,(mk-name "BOOLEANP-MV-NTH-1-" fn-name) + (booleanp (mv-nth 1 (,fn-name dst src cnt input-rflags)))) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src cnt input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-3-" fn-name) + :bound 32 + :concl (mv-nth 3 (,fn-name dst src cnt input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (shld-spec-gen 16)) +(make-event (shld-spec-gen 32)) +(make-event (shld-spec-gen 64)) + +(define shld-spec + ((size :type (member 2 4 8)) + dst + src + cnt + (input-rflags :type (unsigned-byte 32))) + :guard (and (unsigned-byte-p 6 cnt) + (case size + (2 (and (n16p dst) (n16p src))) + (4 (and (n32p dst) (n32p src))) + (8 (and (n64p dst) (n64p src))) + (otherwise nil))) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SHLD') instruction." + + (case size + (2 (shld-spec-16 dst src cnt input-rflags)) + (4 (shld-spec-32 dst src cnt input-rflags)) + (8 (shld-spec-64 dst src cnt input-rflags)) + (otherwise (mv 0 nil 0 0))) + + /// + + (defthm natp-mv-nth-0-shld-spec + (natp (mv-nth 0 (shld-spec size dst src cnt input-rflags))) + :rule-classes :type-prescription) + + (defthm booleanp-of-mv-nth-1-shld-spec + (booleanp (mv-nth 1 (shld-spec size dst src cnt input-rflags)))) + + (defthm-unsigned-byte-p n32p-mv-nth-2-shld-spec + :bound 32 + :concl (mv-nth 2 (shld-spec size dst src cnt input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mv-nth-3-shld-spec + :bound 32 + :concl (mv-nth 3 (shld-spec size dst src cnt input-rflags)) + :gen-type t + :gen-linear t)) + +;;;;;;;;;; SHRD: + +(define shrd-spec-gen ((size :type (member 16 32 64))) + :verify-guards nil + + (b* ((size+1 (1+ size)) + (size-1 (1- size)) + (size*2 (* 2 size)) + (fn-name (mk-name "SHRD-SPEC-" size))) + + `(define ,fn-name + ((dst :type (unsigned-byte ,size)) + (src :type (unsigned-byte ,size)) + (cnt :type (unsigned-byte 6) + "Note that @('cnt') is masked appropriately + by the caller of this function..") + (input-rflags :type (unsigned-byte 32))) + :returns (mv output-dst ; result (irrelevant if undefined-dst? is t) + undefined-dst? ; true iff result of operation is undefined + output-rflags ; output flags, ignoring the undefined ones + undefined-flags) ; flags to set to undefined values + + :parents (shrd-spec) + + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + (unsigned-byte-p + (tau-system))))) + + (b* ((dst (mbe :logic (n-size ,size dst) + :exec dst)) + (src (mbe :logic (n-size ,size src) + :exec src)) + (cnt (mbe :logic (n-size 6 cnt) + :exec cnt)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + ;; we juxtapose src and dst, + ;; by shifting src to the left by size bits + ;; and OR'ing that with dst, + ;; obtaining a 2*size bit value: + (src-dst (the (unsigned-byte ,size*2) + (logior (the (unsigned-byte ,size*2) + (ash (the (unsigned-byte ,size) src) + ,size)) + (the (unsigned-byte ,size) dst)))) + ;; we shift the juxtaposed src and dst to the rigth by cnt bits, + ;; so that the low bits of src go into the high bits of dst: + (neg-cnt (the (signed-byte ,size+1) (- cnt))) + (output-dst (the (unsigned-byte ,size) + (n-size ,size (ash (the (unsigned-byte ,size*2) + src-dst) + (the (signed-byte ,size+1) + neg-cnt))))) + + ((mv (the (unsigned-byte 32) output-rflags) + (the (unsigned-byte 32) undefined-flags)) + + (case cnt + + (0 + ;; no flags affected + (mv input-rflags 0)) + + (1 + ;; all flags but AF changed accordingly, AF undefined: + (b* ((cf ; last bit shifted out of dst, i.e. lowest bit + (mbe :logic (part-select dst :low 0 :width 1) + :exec (the (unsigned-byte 1) + (logand (the (unsigned-byte ,size) dst) + 1)))) + (of ; set iff a sign change occurred + (if (= (logbit ,size-1 dst) + (logbit ,size-1 output-dst)) + 0 + 1)) + (pf (general-pf-spec ,size output-dst)) + (zf (zf-spec output-dst)) + (sf (general-sf-spec ,size output-dst)) + (output-rflags (mbe + :logic + (change-rflagsBits + input-rflags + :cf cf + :of of + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->of + of + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags)))))))) + (undefined-flags (the (unsigned-byte 32) + (!rflagsBits->af 1 0)))) + (mv output-rflags undefined-flags))) + + (otherwise + + (if (<= cnt ,size) + ;; all flags but OF and AF changed accordingly, + ;; OF and AF undefined: + (b* ((cf ; last bit shifted out of dst + (mbe :logic (part-select dst :low (1- cnt) :width 1) + :exec (logand + 1 + (the (unsigned-byte ,size) + (ash (the (unsigned-byte ,size) dst) + (the (signed-byte ,size+1) + (1+ neg-cnt))))))) + (pf (general-pf-spec ,size output-dst)) + (zf (zf-spec output-dst)) + (sf (general-sf-spec ,size output-dst)) + (output-rflags (mbe + :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + input-rflags))))))) + (undefined-flags (mbe + :logic + (change-rflagsBits + 0 + :af 1 + :of 1) + :exec + (!rflagsBits->af + 1 + (!rflagsBits->of + 1 0))))) + (mv output-rflags undefined-flags)) + + ;; all flags undefined if cnt > size: + (b* ((output-rflags input-rflags) + (undefined-flags (the (unsigned-byte 32) + (!rflagsBits->cf + 1 + (!rflagsBits->of + 1 + (!rflagsBits->pf + 1 + (!rflagsBits->zf + 1 + (!rflagsBits->sf + 1 + (!rflagsBits->af + 1 + input-rflags))))))))) + (mv output-rflags undefined-flags)))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags (mbe :logic (n32 undefined-flags) + :exec undefined-flags))) + + (mv output-dst + (> cnt ,size) ; result undefined if count exceeds operand size + output-rflags + undefined-flags)) + + /// + + (local (in-theory (e/d () (unsigned-byte-p)))) + + (defthm-unsigned-byte-p ,(mk-name "N" size "-MV-NTH-0-" fn-name) + :bound ,size + :concl (mv-nth 0 (,fn-name dst src cnt input-rflags)) + :gen-type t + :gen-linear t) + + (defthm ,(mk-name "BOOLEANP-MV-NTH-1-" fn-name) + (booleanp (mv-nth 1 (,fn-name dst src cnt input-rflags)))) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src cnt input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-3-" fn-name) + :bound 32 + :concl (mv-nth 3 (,fn-name dst src cnt input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (shrd-spec-gen 16)) +(make-event (shrd-spec-gen 32)) +(make-event (shrd-spec-gen 64)) + +(define shrd-spec + ((size :type (member 2 4 8)) + dst + src + cnt + (input-rflags :type (unsigned-byte 32))) + :guard (and (unsigned-byte-p 6 cnt) + (case size + (2 (and (n16p dst) (n16p src))) + (4 (and (n32p dst) (n32p src))) + (8 (and (n64p dst) (n64p src))) + (otherwise nil))) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SHRD') instruction." + + (case size + (2 (shrd-spec-16 dst src cnt input-rflags)) + (4 (shrd-spec-32 dst src cnt input-rflags)) + (8 (shrd-spec-64 dst src cnt input-rflags)) + (otherwise (mv 0 nil 0 0))) + + /// + + (defthm natp-mv-nth-0-shrd-spec + (natp (mv-nth 0 (shrd-spec size dst src cnt input-rflags))) + :rule-classes :type-prescription) + + (defthm booleanp-of-mv-nth-1-shrd-spec + (booleanp (mv-nth 1 (shrd-spec size dst src cnt input-rflags)))) + + (defthm-unsigned-byte-p n32p-mv-nth-2-shrd-spec + :bound 32 + :concl (mv-nth 2 (shrd-spec size dst src cnt input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p n32p-mv-nth-3-shrd-spec + :bound 32 + :concl (mv-nth 3 (shrd-spec size dst src cnt input-rflags)) + :gen-type t + :gen-linear t)) + +;;;;;;;;;; SHLX: + +(define shlx-spec-gen ((size :type (member 32 64))) + :verify-guards nil + + (b* ((fn-name (mk-name "SHLX-SPEC-" size))) + + `(define ,fn-name + ;; There is no dst parameter because the result does not depend on it: + ;; the result is just stored in the destination operand. + ((src :type (unsigned-byte ,size)) + (cnt :type (unsigned-byte 6))) + + :parents (shlx-spec) + + (b* ((src (mbe :logic (n-size ,size src) + :exec src)) + (cnt (mbe :logic (n-size 6 cnt) + :exec cnt)) + + (raw-result (ash src cnt)) + (result (the (unsigned-byte ,size) (n-size ,size raw-result)))) + + result) + + :guard-hints (("Goal" :in-theory (disable unsigned-byte-p))) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" size "-" fn-name) + :bound ,size + :concl (,fn-name src cnt) + :gen-type t + :gen-linear t)))) + +; Only operand sizes 32 and 64 are suported. +(make-event (shlx-spec-gen 32)) +(make-event (shlx-spec-gen 64)) + +(define shlx-spec ((size :type (member 4 8)) + src + (cnt (unsigned-byte-p 6 cnt))) + :guard (case size + (4 (n32p src)) + (8 (n64p src)) + (otherwise nil)) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SHLX') instruction." + + :long + "

Since this instruction does not affect the flags, + this function does not take or return flags.

" + + (case size + (4 (shlx-spec-32 src cnt)) + (8 (shlx-spec-64 src cnt)) + (otherwise 0)) + + /// + + (defthm natp-shlx-spec + (natp (shlx-spec size src cnt)) + :rule-classes :type-prescription)) + +;;;;;;;;;; SHRX: + +(define shrx-spec-gen ((size :type (member 32 64))) + :verify-guards nil + + (b* ((size+1 (1+ size)) + (fn-name (mk-name "SHRX-SPEC-" size))) + + `(define ,fn-name + ;; There is no dst parameter because the result does not depend on it: + ;; the result is just stored in the destination operand. + ((src :type (unsigned-byte ,size)) + (cnt :type (unsigned-byte 6))) + + :parents (shrx-spec) + + (b* ((src (mbe :logic (n-size ,size src) + :exec src)) + (cnt (mbe :logic (n-size 6 cnt) + :exec cnt)) + (neg-cnt (the (signed-byte ,size+1) (- cnt))) + + (raw-result (the (unsigned-byte ,size) + (ash (the (unsigned-byte ,size) src) + (the (signed-byte ,size+1) neg-cnt)))) + (result (the (unsigned-byte ,size) (n-size ,size raw-result)))) + + result) + + :guard-hints (("Goal" :in-theory (disable unsigned-byte-p))) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" size "-" fn-name) + :bound ,size + :concl (,fn-name src cnt) + :gen-type t + :gen-linear t)))) + +; Only operand sizes 32 and 64 are suported. +(make-event (shrx-spec-gen 32)) +(make-event (shrx-spec-gen 64)) + +(define shrx-spec ((size :type (member 4 8)) + src + (cnt (unsigned-byte-p 6 cnt))) + :guard (case size + (4 (n32p src)) + (8 (n64p src)) + (otherwise nil)) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SHRX') instruction." + + :long + "

Since this instruction does not affect the flags, + this function does not take or return flags.

" + + (case size + (4 (shrx-spec-32 src cnt)) + (8 (shrx-spec-64 src cnt)) + (otherwise 0)) + + /// + + (defthm natp-shrx-spec + (natp (shrx-spec size src cnt)) + :rule-classes :type-prescription)) + +;;;;;;;;;; SARX: + +(define sarx-spec-gen ((size :type (member 32 64))) + :verify-guards nil + + (b* ((size+1 (1+ size)) + (size-1 (1- size)) + (neg-size-1 (- size-1)) + (fn-name (mk-name "SARX-SPEC-" size))) + + `(define ,fn-name + ;; There is no dst parameter because the result does not depend on it: + ;; the result is just stored in the destination operand. + ((src :type (unsigned-byte ,size)) + (cnt :type (unsigned-byte 6))) + + :parents (sarx-spec) + + (b* ((src (mbe :logic (n-size ,size src) + :exec src)) + (cnt (mbe :logic (n-size 6 cnt) + :exec cnt)) + (neg-cnt (the (signed-byte ,size+1) (- cnt))) + + (raw-result + (if (eql (mbe :logic (logbit ,size-1 src) + :exec (logand 1 + (the (unsigned-byte 1) + (ash (the (unsigned-byte ,size) + src) + ,neg-size-1)))) + 1) + ;; If the operand is negative, shift its logext, + ;; obtaining a non-positive value, which is then loghead'd. + (loghead ,size + (ash (mbe :logic (logext ,size src) + :exec (bitops::fast-logext ,size src)) + neg-cnt)) + ;; If the operand is non-negative, shift it directly, + ;; obtaining a non-negative value. + (the (unsigned-byte ,size) + (ash (the (unsigned-byte ,size) src) + (the (signed-byte ,size+1) neg-cnt))))) + (result (mbe :logic (n-size ,size raw-result) + :exec raw-result))) + + result) + + :guard-hints (("Goal" :in-theory (disable unsigned-byte-p))) + + :prepwork + ((local + (defthm verify-guards-lemma + (implies (unsigned-byte-p ,size src) + (equal (logand ,(1- (expt 2 size)) (logtail cnt src)) + (logtail cnt src))) + :hints (("Goal" + :do-not-induct t + :use ((:instance unsigned-byte-p-of-logtail + (size1 ,size) + (size cnt) + (i src))) + :in-theory (e/d* () + (unsigned-byte-p + unsigned-byte-p-of-logtail))))))) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" size "-" fn-name) + :bound ,size + :concl (,fn-name src cnt) + :gen-type t + :gen-linear t)))) + +; Only operand sizes 32 and 64 are suported. +(make-event (sarx-spec-gen 32)) +(make-event (sarx-spec-gen 64)) + +(define sarx-spec ((size :type (member 4 8)) + src + (cnt (unsigned-byte-p 6 cnt))) + :guard (case size + (4 (n32p src)) + (8 (n64p src)) + (otherwise nil)) + + :inline t + :no-function t + + :parents (instruction-semantic-functions) + + :short "Specification for the @('SARX') instruction." + + :long + "

Since this instruction does not affect the flags, + this function does not take or return flags.

" + + (case size + (4 (sarx-spec-32 src cnt)) + (8 (sarx-spec-64 src cnt)) + (otherwise 0)) + + /// + + (defthm natp-sarx-spec + (natp (sarx-spec size src cnt)) + :rule-classes :type-prescription)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/signextend.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/signextend.lisp new file mode 100644 index 000000000..745027bcd --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/signextend.lisp @@ -0,0 +1,137 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../decoding-and-spec-utils") +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; INSTRUCTION: CBW/CWDE/CDQE/CLTQ +;; ====================================================================== + +(def-inst x86-cbw/cwd/cdqe + + ;; Op/En: NP + + ;; #x98: CBW: AX := Sign-extended AL + ;; #x98: CWDE: EAX := Sign-extended AX + ;; #x98: CDQE: RAX := Sign-extended EAX + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :guard-hints (("Goal" :in-theory (e/d (n08-to-i08 + n16-to-i16 + n32-to-i32 + n64-to-i64) + ()))) + + :body + + (b* (((the (integer 1 8) register-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + ((the (integer 1 4) src-size) (ash register-size -1)) + + ((the (unsigned-byte 32) src) + (mbe :logic + (rgfi-size src-size *rax* rex-byte x86) + :exec + (case src-size + (1 (rr08 *rax* rex-byte x86)) + (2 (rr16 *rax* x86)) + (4 (rr32 *rax* x86)) + (otherwise 0)))) + + (dst (if (logbitp (the (integer 0 32) + (1- (the (integer 0 32) (ash src-size 3)))) + src) + (trunc register-size (case src-size + (1 (n08-to-i08 src)) + (2 (n16-to-i16 src)) + (t (n32-to-i32 src)))) + src)) + + ;; Update the x86 state: + (x86 (!rgfi-size register-size *rax* dst rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;; ====================================================================== +;; INSTRUCTION: CWD/CDQ/CQO +;; ====================================================================== + +(def-inst x86-cwd/cdq/cqo + + ;; Op/En: NP + + ;; #x99: CWD: DX:AX := Sign-extended AX + ;; #x99: CDQ: EDX:EAX := Sign-extended EAX + ;; #x99: CQO: RDX:RAX := Sign-extended RAX + + :parents (one-byte-opcodes) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (((the (integer 1 8) src-size) + (select-operand-size + proc-mode nil rex-byte nil prefixes nil nil nil x86)) + + (src (rgfi-size src-size *rax* rex-byte x86)) + + (rDX (if (logbitp (1- (ash src-size 3)) src) + (trunc src-size -1) + 0)) + + ;; Update the x86 state: + (x86 (!rgfi-size src-size *rdx* rDX rex-byte x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/sub-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/sub-spec.lisp new file mode 100644 index 000000000..3bb374a8d --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/sub-spec.lisp @@ -0,0 +1,290 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +;; This book contains the specification of the following instructions: +;; sub sbb + +(include-book "structures" :dir :utils) +(include-book "../rflags-spec") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; SPECIFICATION: SUB +;; ====================================================================== + +;; The SUB instruction performs integer subtraction. It evaluates the +;; result for both signed and unsigned integer operands and sets the +;; OF and CF flags to indicate an overflow in the signed or unsigned +;; result, respectively. The SF flag indicates the sign of the signed +;; result. + +;; (def-gl-thm sub-signed-and-unsigned-check +;; :hyp (and (n32p x) +;; (n32p y)) +;; :concl (equal (n32 (- (n32-to-i32 x) (n32-to-i32 y))) +;; (n32 (- x y))) +;; :g-bindings `((x (:g-number ,(gl-int 0 2 33))) +;; (y (:g-number ,(gl-int 1 2 33))))) + +(define gpr-sub-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-SUB-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (ntoi (mk-name "N" str-nbits "-TO-I" str-nbits)) + (?cf-spec-fn (mk-name "CF-SPEC" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (af-spec-fn (mk-name "SUB-AF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits)) + (of-spec-fn (mk-name "OF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + :inline t + :no-function t + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + (signed-raw-result + (the (signed-byte ,(1+ result-nbits)) + (- (the (signed-byte ,result-nbits) + (,ntoi dst)) + (the (signed-byte ,result-nbits) + (,ntoi src))))) + + (result (the (unsigned-byte ,result-nbits) + (n-size ,result-nbits signed-raw-result))) + + (cf (the (unsigned-byte 1) (acl2::bool->bit (< dst src)))) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + (af (the (unsigned-byte 1) (,af-spec-fn dst src))) + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of (the (unsigned-byte 1) (,of-spec-fn signed-raw-result))) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :af af + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->af + af + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags))))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags 0)) + + (mv result output-rflags undefined-flags)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-sub-spec-gen-fn 1)) +(make-event (gpr-sub-spec-gen-fn 2)) +(make-event (gpr-sub-spec-gen-fn 4)) +(make-event (gpr-sub-spec-gen-fn 8)) + +;; ====================================================================== +;; SPECIFICATION: SBB +;; ====================================================================== + +(define gpr-sbb-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-SBB-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (ntoi (mk-name "N" str-nbits "-TO-I" str-nbits)) + (?cf-spec-fn (mk-name "CF-SPEC" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (af-spec-fn (mk-name "SBB-AF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits)) + (of-spec-fn (mk-name "OF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + :inline t + :no-function t + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + (input-cf (the (unsigned-byte 1) + (rflagsBits->cf input-rflags))) + + (signed-raw-result + (the (signed-byte ,(+ 2 result-nbits)) + (- (the (signed-byte ,result-nbits) + (,ntoi dst)) + (the (signed-byte ,(1+ result-nbits)) + (+ (the (signed-byte ,result-nbits) + (,ntoi src)) + input-cf))))) + + (result (the (unsigned-byte ,result-nbits) + (n-size ,result-nbits signed-raw-result))) + + (cf (the (unsigned-byte 1) + (acl2::bool->bit + (< dst + (the (unsigned-byte ,(1+ result-nbits)) + (+ input-cf src)))))) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + (af (the (unsigned-byte 1) (,af-spec-fn dst src input-cf))) + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of (the (unsigned-byte 1) (,of-spec-fn signed-raw-result))) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :af af + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->af + af + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of + input-rflags))))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + (undefined-flags 0)) + + (mv result output-rflags undefined-flags)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-sbb-spec-gen-fn 1)) +(make-event (gpr-sbb-spec-gen-fn 2)) +(make-event (gpr-sbb-spec-gen-fn 4)) +(make-event (gpr-sbb-spec-gen-fn 8)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/subroutine.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/subroutine.lisp new file mode 100644 index 000000000..e93f51009 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/subroutine.lisp @@ -0,0 +1,917 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, May - August 2023, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; Copyright (C) August 2023 - May 2024, Yahya Sohail +; Copyright (C) May 2024 - August 2024, Intel Corporation +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio +; Yahya Sohail + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../decoding-and-spec-utils") +;(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + + +;; ====================================================================== +;; INSTRUCTION: CALL +;; ====================================================================== + +;; From Intel manual, Mar'17, Volume 1, Section 6.3.7: + +;; In 64-bit mode, the operand size for all near branches (CALL, RET, +;; JCC, JCXZ, JMP, and LOOP) is forced to 64 bits. These instructions +;; update the 64-bit RIP without the need for a REX operand-size +;; prefix. + +;; The following aspects of near branches are controlled by the +;; effective operand size: +;; Truncation of the size of the instruction pointer +;; Size of a stack pop or push, due to a CALL or RET +;; Size of a stack-pointer increment or decrement, due to a CALL or RET +;; Indirect-branch operand size + +;; In 64-bit mode, all of the above actions are forced to 64 bits +;; regardless of operand size prefixes (operand size prefixes are +;; silently ignored). However, the displacement field for relative +;; branches is still limited to 32 bits and the address size for near +;; branches is not forced in 64-bit mode. + +;; Address sizes affect the size of RCX used for JCXZ and LOOP; they +;; also impact the address calculation for memory indirect +;; branches. Such addresses are 64 bits by default; but they can be +;; overridden to 32 bits by an address size prefix. + +(def-inst x86-call-E8-Op/En-M + + ;; Call near, displacement relative to the next instruction + ;; Op/En: M + ;; E8 cw (CALL rel16) + ;; E8 cd (CALL rel32) + ;; Note E8 cw (CALL rel16) is N.S. in 64-bit mode. + + ;; The address-size override prefix will not have any effect here + ;; since we have no memory operands. + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (;riml08 + ;riml32 + rime-size-of-2-to-rime16 + rime-size-of-4-to-rime32 + select-address-size) + ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (((the (integer 0 4) offset-size) + (select-operand-size proc-mode nil rex-byte nil prefixes nil t t x86)) + + ;; AC is not done during code fetches. Fetching rel16 or rel32 from the + ;; instruction stream still qualifies as a code fetch. + ((mv flg0 (the (signed-byte 32) rel16/32) x86) + (rime-size-opt proc-mode offset-size temp-rip #.*cs* :x nil x86)) + ((when flg0) (!!ms-fresh :rime-size-opt-error flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size+1*) next-rip)) + (add-to-*ip proc-mode temp-rip offset-size x86)) + ((when flg) (!!ms-fresh :rip-increment-error next-rip)) + + (badlength? (check-instruction-length start-rip next-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) call-rip)) + (add-to-*ip proc-mode next-rip rel16/32 x86)) + ((when flg) (!!ms-fresh :call-rip-invalid call-rip)) + + (rsp (read-*sp proc-mode x86)) + ((the (integer 2 8) addr-size) (select-address-size proc-mode nil x86)) + ((mv flg new-rsp) (add-to-*sp proc-mode rsp (- addr-size) x86)) + ((when flg) (!!fault-fresh :ss 0 :call flg)) ;; #SS(0) + + ((mv flg x86) + ;; Note that instruction pointers are modeled as signed in 64-bit mode, + ;; but unsigned in 32-bit mode. + (if (equal proc-mode #.*64-bit-mode*) + (wime-size-opt + #.*64-bit-mode* addr-size + (the (signed-byte #.*max-linear-address-size*) new-rsp) + #.*ss* + next-rip + (alignment-checking-enabled-p x86) + x86) + (wme-size-opt + proc-mode addr-size + (the (signed-byte #.*max-linear-address-size*) new-rsp) + #.*ss* + ;; the following coercions (N16 and N32) should not be + ;; necessary, but they make the guard proofs easier for now: + (if (= addr-size 2) + (n16 next-rip) + (n32 next-rip)) + (alignment-checking-enabled-p x86) + x86))) + ((when flg) (!!ms-fresh :stack-writing-error flg)) + + ;; Update the rip to point to the called procedure. + (x86 (write-*ip proc-mode call-rip x86)) + ;; Decrement the stack pointer. + (x86 (write-*sp proc-mode new-rsp x86))) + x86)) + +(def-inst x86-call-FF/2-Op/En-M + + ;; Call near, absolute indirect, address given in r/m16/32/64. + ;; Op/En: M + ;; FF/2 r/m16 + ;; FF/2 r/m32 + ;; FF/2 r/m64 + ;; Note that FF/2 r/m16 and r/m32 are N.E. in 64-bit mode. + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (;riml08 + ;riml32 + select-address-size) + ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 2 8) operand-size) + (select-operand-size proc-mode nil rex-byte nil prefixes t t t x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + ;; Note that the reg field serves as an opcode extension for + ;; this instruction. The reg field will always be 2 when this + ;; function is called. + (inst-ac? t) + ((mv flg0 + call-rip + (the (unsigned-byte 3) increment-rip-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes + proc-mode #.*gpr-access* operand-size inst-ac? + nil ;; Not a memory pointer operand + seg-reg p4? temp-rip rex-byte r/m mod sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) next-rip)) + (add-to-*ip proc-mode temp-rip increment-rip-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error next-rip)) + + (badlength? (check-instruction-length start-rip next-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Note that instruction pointers are modeled as signed in 64-bit mode, + ;; but unsigned in 32-bit mode. + (call-rip (if (equal proc-mode #.*64-bit-mode*) + (i64 call-rip) + call-rip)) + ;; Ensure that the return address is canonical (for 64-bit mode) and + ;; within code segment limits (for 32-bit mode). See pseudocode in Intel + ;; manual. + ((unless (if (equal proc-mode #.*64-bit-mode*) + (canonical-address-p call-rip) + (and (<= 0 call-rip) + (<= call-rip + (the (unsigned-byte 32) + (seg-hidden-limiti #.*cs* x86)))))) + (!!fault-fresh :gp 0 :bad-return-address call-rip)) ;; #GP(0) + + (rsp (read-*sp proc-mode x86)) + + ;; The size of the RIP/EIP/IP is determined by + ;; the processor mode and the CS.D bit (see READ-*IP). + ;; It is not (necessarily) the result of SELECT-ADDRESS-SIZE, + ;; which may be subject to address size overrides. + (rip-size (case proc-mode + (#.*64-bit-mode* 8) + (#.*compatibility-mode* + (b* (((the (unsigned-byte 16) cs-attr) + (seg-hidden-attri #.*cs* x86)) + (cs.d (code-segment-descriptor-attributesbits->d + cs-attr))) + (if (= cs.d 1) 4 2))) + (t 0))) ; other modes not implemented yet + + ((mv flg new-rsp) (add-to-*sp proc-mode rsp (- rip-size) x86)) + ((when flg) (!!fault-fresh :ss 0 :call flg)) ;; #SS(0) + + ;; Update the x86 state: + ;; Push the return address on the stack. + (check-alignment? (alignment-checking-enabled-p x86)) + ((mv flg x86) + ;; Note that instruction pointers are modeled as signed in 64-bit mode, + ;; but unsigned in 32-bit mode. + (case rip-size + ;; Note that we need check-canonicity t only for rip-size = 8, + ;; because we get this size only in 64-bit mode. + (8 (wime-size-opt proc-mode + rip-size + new-rsp + #.*ss* + next-rip + check-alignment? + x86 + :check-canonicity t)) + ;; It should be an invariant that, if rip-size = 4, + ;; next-rip is 32 bits, but since at the moment + ;; we don't have that invariant, we coerce next-rip. + (4 (wme-size-opt proc-mode + rip-size + new-rsp + #.*ss* + (n32 next-rip) + check-alignment? + x86)) + (2 (wme-size-opt proc-mode + rip-size + new-rsp + #.*ss* + (n16 next-rip) + check-alignment? + x86)) + (t (mv :not-implemented x86)))) + ((when flg) (!!ms-fresh :stack-writing-error flg)) + ;; Update the rip to point to the called procedure. + (x86 (write-*ip proc-mode call-rip x86)) + ;; Decrement the stack pointer. + (x86 (write-*sp proc-mode new-rsp x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: RET +;; ====================================================================== + +;; From Intel manual, Mar'17, Volume 1, Section 6.3.7: + +;; In 64-bit mode, the operand size for all near branches (CALL, RET, +;; JCC, JCXZ, JMP, and LOOP) is forced to 64 bits. These instructions +;; update the 64-bit RIP without the need for a REX operand-size +;; prefix. + +;; The following aspects of near branches are controlled by the +;; effective operand size: +;; Truncation of the size of the instruction pointer +;; Size of a stack pop or push, due to a CALL or RET +;; Size of a stack-pointer increment or decrement, due to a CALL or RET +;; Indirect-branch operand size + +;; In 64-bit mode, all of the above actions are forced to 64 bits +;; regardless of operand size prefixes (operand size prefixes are +;; silently ignored). However, the displacement field for relative +;; branches is still limited to 32 bits and the address size for near +;; branches is not forced in 64-bit mode. + +;; Address sizes affect the size of RCX used for JCXZ and LOOP; they +;; also impact the address calculation for memory indirect +;; branches. Such addresses are 64 bits by default; but they can be +;; overridden to 32 bits by an address size prefix. + +;; End of quoted text from the Intel manual. + +;; In 32-bit mode, the operand size should be the size of the code address, +;; i.e. 32 bits if CS.D = 1 and 16 bits if CS.D = 0: in other words, the +;; operand size override prefix P3 should have no effect here. Thus, we pass 0 +;; as the PREFIXES argument to SELECT-OPERAND-SIZE; note that this function +;; only accesses the P3 prefix out of all the prefixes, so passing 0 as the +;; prefixes has no adverse effect. + +;; Note that also in 64-bit mode (see above) the operand size (64 bits) is +;; equal to the size of the code address (64 bits, even though in our model we +;; only model the low 48 bits due to the invariant of instruction pointers +;; being canonical). + +(def-inst x86-ret + + ;; Op/En: #xC2 iw: I: Near return to calling procedure and pop imm16 bytes from + ;; stack + ;; #xC3: NP: Near return to calling procedure + ;; #xCB: ZO: Far return to calling procedure + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (rime-size rme-size) ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* ((rsp (read-*sp proc-mode x86)) + + ((the (integer 2 8) operand-size) + (select-operand-size proc-mode nil rex-byte nil 0 t t t x86)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) new-rsp) x86) + (if (not (equal opcode #xC2)) + (b* (((mv flg1 new-rsp) + (add-to-*sp proc-mode rsp operand-size x86)) + ((when flg1) (mv flg1 0 x86))) + (mv nil new-rsp x86)) + ;; We don't do any alignment check below when fetching the + ;; immediate operand; reading the immediate operand is done + ;; during code fetching, where alignment checks aren't supposed + ;; to be done (see Intel Manuals, Volume 3, Section 6.15, + ;; Exception and Interrupt Reference, Interrupt 17 Alignment + ;; Check Exception (#AC) for details). + (b* (((mv flg1 (the (unsigned-byte 16) imm16) x86) + (rme16-opt proc-mode temp-rip #.*cs* :x nil x86)) + ((when flg1) (mv flg1 0 x86)) + ((mv flg1 new-rsp) + (add-to-*sp proc-mode rsp (+ operand-size imm16) x86)) + ((when flg1) (mv flg1 0 x86))) + (mv nil new-rsp x86)))) + ((when flg) + (!!ms-fresh :imm-rml16-error flg)) + + ;; For #xC3: We don't need to check for valid length for + ;; one-byte instructions. The length will be more than 15 only + ;; if get-prefixes fetches 15 prefixes, and that error will be + ;; caught in x86-fetch-decode-execute, that is, before control + ;; reaches this function. + ;; For #xC2: We add 2 to temp-rip to account for imm16. + (badlength? (and (eql opcode #xC2) + (check-instruction-length start-rip temp-rip 2))) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Note that instruction pointers are modeled as signed in 64-bit mode, + ;; but unsigned in 32-bit mode. + (check-alignment? (alignment-checking-enabled-p x86)) + ((mv flg (the (signed-byte 64) tos) x86) + (if (= operand-size 8) + (rime-size-opt + ;; Note that we need check-canonicity t only for operand-size = 8, + ;; because we get this size only in 64-bit mode. + proc-mode operand-size rsp #.*ss* :r check-alignment? x86 + :mem-ptr? nil + :check-canonicity t) + (rme-size-opt + proc-mode operand-size rsp #.*ss* :r check-alignment? x86 + :mem-ptr? nil))) + ((when flg) + (cond + ((and (consp flg) (eql (car flg) :non-canonical-address)) + (!!fault-fresh :ss 0 :riml64-error flg)) ;; #SS(0) + ((and (consp flg) (eql (car flg) :unaligned-linear-address)) + (!!fault-fresh :ac 0 :memory-access-unaligned rsp)) ;; #AC(0) + (t ;; Unclassified error! + (!!fault-fresh flg)))) + + ;; Ensure that the return address is canonical (for 64-bit mode) and + ;; within code segment limits (for 32-bit mode near return). See pseudocode in Intel + ;; manual. + ((unless (if (equal proc-mode #.*64-bit-mode*) + (canonical-address-p tos) + (b* (((the (unsigned-byte 32) cs.limit) + (seg-hidden-limiti #.*cs* x86))) + (or (equal opcode #xCB) + (and (<= 0 tos) (<= tos cs.limit)))))) + (!!fault-fresh :gp 0 :bad-return-address tos)) ;; #GP(0) + + ;; Update the x86 state: + + ;; Handle the far return case + ((mv new-rsp x86) + (if (equal opcode #xCB) + (b* (((mv flg cs-selector x86) + (rme-size-opt + proc-mode operand-size new-rsp #.*ss* :r check-alignment? x86 + :mem-ptr? nil)) + ((when flg) + (b* ((x86 (cond + ((and (consp flg) (eql (car flg) :non-canonical-address)) + (!!fault-fresh :ss 0 :riml64-error flg)) ;; #SS(0) + ((and (consp flg) (eql (car flg) :unaligned-linear-address)) + (!!fault-fresh :ac 0 :memory-access-unaligned rsp)) ;; #AC(0) + (t ;; Unclassified error! + (!!fault-fresh flg))))) + (mv 0 x86))) + (cs-selector (loghead 16 cs-selector)) + ((mv flg cs-descriptor x86) + (get-segment-descriptor #.*cs* cs-selector x86)) + ((when flg) + (b* (((when (equal flg t)) + (b* ((x86 (!!ms-fresh :get-segment-descriptor))) + (mv 0 x86))) + (x86 (!!fault-fresh (car flg) (cadr flg) (caddr flg)))) + (mv 0 x86))) + (x86 (load-segment-reg #.*cs* cs-selector cs-descriptor x86)) + ((mv flg new-rsp) + (add-to-*sp proc-mode new-rsp operand-size x86)) + ((when flg) + (b* ((x86 (!!fault-fresh :ss 0 :pop flg))) + (mv 0 x86)))) + (mv new-rsp x86)) + (mv new-rsp x86))) + ((when (or (fault x86) + (ms x86))) x86) + + ;; Increment the stack pointer. + (x86 (write-*sp proc-mode new-rsp x86)) + + ;; Update the rip to point to the return address. + ;; The pseudocode for RET in Intel manual, Mar'17, Volume 2 + ;; says that a 16-bit return instruction pointer + ;; should be zero-extended and stored into EIP. + ;; Thus, we do not use WRITE-*IP here, + ;; which has a different treatment for 16-bit instruction pointers. + ;; This seems inconsistent, and it is an ambiguous aspect + ;; of the Intel and AMD manuals. + (x86 (!rip (the (signed-byte #.*max-linear-address-size*) tos) x86))) + + x86)) + +;; ====================================================================== +;; INSTRUCTION: LEAVE +;; ====================================================================== + +(def-inst x86-leave + + ;; The LEAVE instruction releases the stack frame set up by an + ;; earlier ENTER instruction. + + ;; Op/En: NP + ;; C9 + ;; rSP := rBP + ;; rBP := Pop() (i.e. get bytes from the stack, also considering the + ;; operand-size override prefix, and put them in rBP, and then + ;; increment the stack pointer appropriately) + + ;; According to the pseudocode in Intel manual, Jun 2026, Volume 2A, LEAVE + ;; specification, the size of rSP and rBP in the assignment rSP := rBP is + ;; determined by StackAddressSize, while the size of rBP in the assignment + ;; rBP := Pop() is determined by OperandSize. That is, the stack address + ;; size determines the width at which rBP is used as an address: it is the + ;; new value of rSP, and also the address from which the pop reads. The + ;; operand size determines the width of the data transfer into rBP: the + ;; number of bytes popped, and the slice of rBP that receives them. The two + ;; sizes may differ: e.g. LEAVE with a 66H prefix in 64-bit mode pops 16 + ;; bits of data from the address in the full 64-bit rBP. This reading of + ;; the pseudocode is confirmed by the Description section of the ENTER + ;; specification, which says that the OperandSize attribute determines "the + ;; data being transferred from SP/ESP/RSP register into the BP/EBP/RBP + ;; register" (in ENTER, the transfer opposite to LEAVE's), and which makes + ;; software responsible for ensuring that, after a 66H ENTER (whose rBP + ;; write updates only BP, leaving the high bits of rBP stale), the value of + ;; rBP "remains a valid address in the stack" so that a 66H LEAVE works: + ;; this implies that LEAVE uses the full stack-address-size-wide rBP as the + ;; address of the pop. Thus, below we read rBP at the stack address size, + ;; and we use the operand size for the pop's data. + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (;;riml08 + ;;riml32 + rme-size-of-2-to-rme16 + rme-size-of-4-to-rme32 + rme-size-of-8-to-rme64 + rme16 + rme32 + rme64) + ()))) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (((the (integer 2 8) operand-size) + (select-operand-size proc-mode nil rex-byte nil prefixes t t nil x86)) + + ;; We read rBP at the stack address size (not the operand size), + ;; because this value is used as an address, + ;; namely the new value of rSP, from which the pop below reads; + ;; see the comments at the beginning of this function. + ((the (integer 2 8) stack-address-size) + (select-stack-address-size proc-mode x86)) + (rbp/ebp/bp (rgfi-size stack-address-size *rbp* 0 x86)) + + ;; RBP/EBP/BP is the new value of RSP/ESP/SP now, + ;; but we cannot write it into the state yet, + ;; because according to + ;; Intel manual, Jun 2026, Vol. 3, Section 7.5, + ;; a fault must leave the processor state in the same state as + ;; at the start of the instruction that caused the fault, + ;; the following code may result in #SS, + ;; and Table 7-1 in Chapter 7 classifies #SS as a fault. + ;; We use RBP/EBP/BP, below, to pop the new value of RBP/EBP/BP: + ;; as we do that, + ;; we implicitly check it to be canonical (in 64-bit mode) or + ;; within the stack segment limits (in 32-bit mode), + ;; so there's no need to make these checks explicitly here. + + (inst-ac? (alignment-checking-enabled-p x86)) + ((mv flg val x86) (rme-size-opt + proc-mode + operand-size + (the (signed-byte 64) (i64 rbp/ebp/bp)) + #.*ss* + :r + inst-ac? + x86 + :mem-ptr? nil + :check-canonicity t)) + ((when flg) (!!fault-fresh :ss 0 :pop-error flg)) ;; #SS(0) + + ((mv flg (the (signed-byte 64) new-rsp)) + (add-to-*sp proc-mode (i64 rbp/ebp/bp) operand-size x86)) + ((when flg) (!!ms-fresh :invalid-rsp new-rsp)) + + ;; We don't need to check for valid length for one-byte + ;; instructions. The length will be more than 15 only if + ;; get-prefixes fetches 15 prefixes, and that error will be + ;; caught in x86-fetch-decode-execute, that is, before control + ;; reaches this function. + + ;; Update the x86 state: + ;; We chose to write the value val into the register using !rgfi-size + ;; rather than !rgfi since val is a n64p value and !rgfi expects an i64p + ;; value. + + (x86 (!rgfi-size operand-size *rbp* val rex-byte x86)) + (x86 (write-*sp proc-mode new-rsp x86)) + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== +;; INSTRUCTION: ENTER +;; ====================================================================== + +(define x86-enter-copy-nested-frame-pointers + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (count :type (integer 0 31)) + (operand-size :type (integer 2 8)) + (frame-ptr :type (signed-byte 64)) + (rsp :type (signed-byte 64)) + (check-alignment? booleanp) + x86) + :guard (member operand-size '(2 4 8)) + :returns (mv flg + (new-rsp i64p :hyp (i64p rsp)) + (x86 x86p :hyp (x86p x86))) + :parents (x86-enter) + :short "Copy the nested frame pointers onto the stack, + as part of the ENTER instruction with nesting level greater than 0." + :long + "

+ This is the loop in the pseudocode of the ENTER instruction + (Intel manual, Jun 2026, Volume 2A): + when the nesting level is greater than 0, + after pushing the (old) frame pointer rBP, + @('NestingLevel - 1') further frame pointers are copied onto the stack, + by repeatedly decrementing @('frame-ptr') (initially rBP) + and reading the frame pointer at that stack address. + The @('count') argument is @('NestingLevel - 1'), + i.e. the number of frame pointers still to be copied. + The @('rsp') argument is the running stack pointer, + which is decremented and written to on each iteration. +

+

+ Per the ENTER specification, the operand size is + the size of each frame pointer copied by the loop, + i.e. the size of the data read and written by each iteration, + and thus also the amount by which + @('frame-ptr') and @('rsp') are decremented. +

" + (if (mbe :logic (zp count) :exec (eql count 0)) + (mv nil (the (signed-byte 64) rsp) x86) + (b* ( ;; frame-ptr := frame-ptr - operand-size + ((mv flg (the (signed-byte 64) frame-ptr)) + (add-to-*sp proc-mode frame-ptr (- operand-size) x86)) + ((when flg) (mv flg 0 x86)) + ;; read the frame pointer at [frame-ptr] + ((mv flg val x86) (rme-size-opt proc-mode + operand-size + frame-ptr + #.*ss* + :r + check-alignment? + x86 + :mem-ptr? nil)) + ((when flg) (mv flg 0 x86)) + ;; push it, i.e. rsp := rsp - operand-size and [rsp] := val + ((mv flg (the (signed-byte 64) rsp)) + (add-to-*sp proc-mode rsp (- operand-size) x86)) + ((when flg) (mv flg 0 x86)) + ((mv flg x86) (wme-size-opt proc-mode + operand-size + rsp + #.*ss* + val + check-alignment? + x86 + :mem-ptr? nil)) + ((when flg) (mv flg 0 x86))) + (x86-enter-copy-nested-frame-pointers proc-mode + (- count 1) + operand-size + frame-ptr + rsp + check-alignment? + x86))) + :measure (nfix count) + :guard-hints (("Goal" + :in-theory (e/d (rme-size-of-2-to-rme16 + rme-size-of-4-to-rme32 + rme-size-of-8-to-rme64) + ()) + :cases ((eql operand-size 2) + (eql operand-size 4) + (eql operand-size 8)))) + + /// + + ;; The returned stack pointer is a 64-bit signed integer. We generate the + ;; type-prescription and linear rules (in addition to the rewrite rule that + ;; :RETURNS provides), so that the guards of the caller (X86-ENTER), which + ;; passes the returned stack pointer to operations such as ADD-TO-*SP, can be + ;; verified. + (defthm-signed-byte-p + signed-byte-p-64-of-mv-nth-1-x86-enter-copy-nested-frame-pointers + :hyp (i64p rsp) + :bound 64 + :concl (mv-nth 1 (x86-enter-copy-nested-frame-pointers proc-mode + count + operand-size + frame-ptr + rsp + check-alignment? + x86)) + :gen-type t + :gen-linear t + :hints (("Goal" + :induct t + :in-theory (enable x86-enter-copy-nested-frame-pointers))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; for speed: +(local (in-theory (disable acl2::member-of-cons member-equal + rgfi-size$inline))) + +(def-inst x86-enter + + ;; The ENTER instruction creates a stack frame for a procedure, + ;; which is later released by the LEAVE instruction (see X86-LEAVE). + + ;; Op/En: II + ;; C8 iw ib ENTER imm16, imm8 + ;; imm16 (the first operand) is the number of bytes reserved on the stack + ;; for the local variables of the procedure; imm8 (the second operand) is + ;; the lexical nesting level, whose low 5 bits are used (i.e. it is taken + ;; modulo 32). + + ;; See the pseudocode in the Intel manual, Jun 2026, Volume 2A, ENTER + ;; specification, as well as the helper function + ;; X86-ENTER-COPY-NESTED-FRAME-POINTERS above. + + ;; rBP is used at two different widths in this instruction (cf. the + ;; comments in X86-LEAVE about the roles of the operand size and of the + ;; stack address size). As data, rBP is operand-size wide: the Description + ;; section of the ENTER specification says that the OperandSize attribute + ;; determines the size of each frame pointer copied onto the stack, and + ;; "the data being transferred from SP/ESP/RSP register into the BP/EBP/RBP + ;; register"; accordingly, Push(rBP) below pushes the operand-size-wide + ;; rBP, and rBP := FrameTemp writes the low operand-size-wide part of + ;; FrameTemp into rBP. As an address, rBP is stack-address-size wide: the + ;; loop in the pseudocode decrements RBP, EBP, or BP according to + ;; StackSize (notably, the full RBP when StackSize = 64 and OperandSize = + ;; 16); accordingly, the base address from which the nested frame pointers + ;; are copied below is the stack-address-size-wide rBP. + + :parents (one-byte-opcodes) + + :guard-hints (("Goal" :in-theory (e/d (rme-size-of-2-to-rme16 + rme-size-of-4-to-rme32 + rme-size-of-8-to-rme64 + ;rme64 + ) + (;signed-byte-p + )))) + + :returns (x86 x86p :hyp (x86p x86)) + + :body + + (b* (((the (integer 2 8) operand-size) + (select-operand-size proc-mode nil rex-byte nil prefixes t t nil x86)) + + ;; Read the two immediate operands: + ;; the allocation size (imm16) and the nesting level (imm8). + ;; These are fetched from the instruction stream, so, like other code + ;; fetches, no alignment checking is done here. + + ((mv flg (the (unsigned-byte 16) alloc-size) x86) + (rme16-opt proc-mode temp-rip #.*cs* :x nil x86)) + ((when flg) (!!ms-fresh :alloc-size-read-error flg)) + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip 2 x86)) + ((when flg) + (!!fault-fresh :gp 0 :temp-rip-not-canonical temp-rip)) ;; #GP(0) + + ((mv flg (the (unsigned-byte 8) nesting-byte) x86) + (rme08-opt proc-mode temp-rip #.*cs* :x x86)) + ((when flg) (!!ms-fresh :nesting-level-read-error flg)) + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) + (!!fault-fresh :gp 0 :temp-rip-not-canonical temp-rip)) ;; #GP(0) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; NestingLevel := imm8 MOD 32. + ((the (integer 0 31) nesting-level) (loghead 5 nesting-byte)) + + (check-alignment? (alignment-checking-enabled-p x86)) + + ;; Push rBP. The value pushed is the operand-size-wide rBP; + ;; see the comments at the beginning of this function. + ((the (unsigned-byte 64) rbp) (rgfi-size operand-size *rbp* 0 x86)) + (rsp (read-*sp proc-mode x86)) + ((mv flg (the (signed-byte 64) rsp)) + (add-to-*sp proc-mode rsp (- operand-size) x86)) + ((when flg) (!!fault-fresh :ss 0 :push-rbp flg)) ;; #SS(0) + ((mv flg x86) (wme-size-opt proc-mode + operand-size + rsp + #.*ss* + rbp + check-alignment? + x86 + :mem-ptr? nil)) + ;; The COND below is analogous to the one after the nesting block + ;; further down (see the comment there about the possible errors), + ;; with two differences: + ;; the #SS case omits the error tags :NON-CANONICAL-STACK-ADDRESS + ;; and :OUT-OF-SEGMENT-STACK-ADDRESS, + ;; which can only arise from ADD-TO-*SP, + ;; whose failure for this push of rBP + ;; is already mapped to #SS just above; + ;; the #SS case also omits the error symbols RML16 etc., + ;; which can only arise from reads, while this is a write. + ((when flg) + (cond + ((or (and (consp flg) (eql (car flg) :segment-limit-fail)) + (member-eq flg '(wml16 wml32 wml64))) + (!!fault-fresh :ss 0 :stack-writing-error flg)) ;; #SS(0) + ((and (consp flg) (eql (car flg) :unaligned-linear-address)) + (!!fault-fresh :ac 0 :memory-access-unaligned flg)) ;; #AC(0) + (t ;; Unclassified error! + (!!ms-fresh :stack-writing-error flg)))) + + ;; FrameTemp := rSP, i.e. the stack pointer just after pushing rBP. + ((the (signed-byte 64) frame-temp) rsp) + + ;; If NestingLevel > 0, copy the NestingLevel - 1 nested frame pointers + ;; onto the stack (see X86-ENTER-COPY-NESTED-FRAME-POINTERS) and then + ;; push FrameTemp. If NestingLevel = 0, none of this is done: the + ;; pseudocode in the Intel manual jumps to the CONTINUE label below. + ((mv flg (the (signed-byte 64) rsp) x86) + (if (eql nesting-level 0) + (mv nil rsp x86) + (b* (;; The base address from which the nested frame pointers are + ;; copied is the stack-address-size-wide rBP; + ;; see the comments at the beginning of this function. + ((the (integer 2 8) stack-address-size) + (select-stack-address-size proc-mode x86)) + ((the (signed-byte 64) frame-ptr) + (i64 (rgfi-size stack-address-size *rbp* 0 x86))) + ((mv flg (the (signed-byte 64) rsp) x86) + (x86-enter-copy-nested-frame-pointers proc-mode + (1- nesting-level) + operand-size + frame-ptr + rsp + check-alignment? + x86)) + ((when flg) (mv flg rsp x86)) + ;; Push FrameTemp. + ((mv flg (the (signed-byte 64) rsp)) + (add-to-*sp proc-mode rsp (- operand-size) x86)) + ((when flg) (mv flg rsp x86)) + ((mv flg x86) (wme-size-opt proc-mode + operand-size + rsp + #.*ss* + (loghead (ash operand-size 3) + frame-temp) + check-alignment? + x86 + :mem-ptr? nil)) + ((when flg) (mv flg rsp x86))) + (mv nil rsp x86)))) + ;; In the COND below: + ;; the error tags :NON-CANONICAL-STACK-ADDRESS + ;; and :OUT-OF-SEGMENT-STACK-ADDRESS come from ADD-TO-*SP; + ;; the error tag :SEGMENT-LIMIT-FAIL comes from EA-TO-LA + ;; (via RME-SIZE and WME-SIZE), in 32-bit mode, + ;; for an access that starts within the stack segment limits + ;; but ends past them; + ;; the error symbols RML16 etc. and WML16 etc. + ;; come from the functions with those names + ;; (via RME-SIZE and WME-SIZE), in 64-bit mode, + ;; for an access that starts at a canonical address + ;; but ends past the canonical address space. + ;; The last two kinds of errors are possible because ADD-TO-*SP + ;; only checks the start address of an access. + ;; All the aforementioned errors are stack faults (#SS); + ;; an :UNALIGNED-LINEAR-ADDRESS error from RME-SIZE or WME-SIZE + ;; is instead an alignment check fault (#AC). + ((when flg) + (cond + ((or (and (consp flg) + (or (eql (car flg) :non-canonical-stack-address) + (eql (car flg) :out-of-segment-stack-address) + (eql (car flg) :segment-limit-fail))) + (member-eq flg '(rml16 rml32 rml64 wml16 wml32 wml64))) + (!!fault-fresh :ss 0 :enter-stack-error flg)) ;; #SS(0) + ((and (consp flg) (eql (car flg) :unaligned-linear-address)) + (!!fault-fresh :ac 0 :memory-access-unaligned flg)) ;; #AC(0) + (t ;; Unclassified error! + (!!ms-fresh :enter-error flg)))) + + ;; Update the x86 state: + + ;; Calculate rSP - AllocSize. + ;; We calculate the new rSP, but we write it a few lines below. + ;; We calculate this before writing to rBP because + ;; this calculation can cause a #SS fault, + ;; and according to Intel manual, Jun 2026, Vol. 3, Section 7.5, + ;; a fault must leave the processor state + ;; in the same state as at the start of + ;; the instruction that caused the fault; + ;; Table 7-1 in Chapter 7 classifies #SS as a fault. + ((mv flg (the (signed-byte 64) rsp)) + (add-to-*sp proc-mode rsp (- alloc-size) x86)) + ((when flg) (!!fault-fresh :ss 0 :alloc-error flg)) ;; #SS(0) + + ;; rBP := FrameTemp. + ;; We use !rgfi-size (rather than !rgfi) since it expects an unsigned + ;; value, so we take the low bits of FrameTemp accordingly. + (x86 (!rgfi-size operand-size *rbp* + (loghead (ash operand-size 3) + frame-temp) + rex-byte x86)) + ;; rSP := rSP - AllocSize. + ;; The calculation was done above, for the reason explained above. + (x86 (write-*sp proc-mode rsp x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/top.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/top.lisp new file mode 100644 index 000000000..f49f887b9 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/top.lisp @@ -0,0 +1,167 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "arith-and-logic") +(include-book "bit") +(include-book "conditional") +(include-book "divide") +(include-book "endbranch") +(include-book "exchange") +(include-book "flags") +(include-book "halt") +(include-book "jump-and-loop") +(include-book "logical") +(include-book "move") +(include-book "move-mmx") +(include-book "move-sse") +(include-book "move-vex") +(include-book "multiply") +(include-book "padd") +(include-book "pmadd") +(include-book "pmul") +(include-book "psub") +(include-book "pshift") +(include-book "push-and-pop") +(include-book "rand") +(include-book "rotate-and-shift") +(include-book "segmentation") +(include-book "signextend") +(include-book "string") +(include-book "syscall" :ttags (:syscall-exec)) +(include-book "pack") +(include-book "subroutine") +(include-book "fp/top") +(include-book "interrupts") +(include-book "cpuid") +(include-book "msrs") +(include-book "x87") +(include-book "time") +(include-book "pio") +(include-book "cache") +(include-book "punpck") +(include-book "pcmp") +(include-book "pshuf") +(include-book "emms") +(include-book "bcd") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== + +(defsection instructions + :parents (machine) + :short "Umbrella topic for specification of Intel's x86 instructions" + ) + +(defsection one-byte-opcodes + :parents (instructions) + :short "Instruction semantic functions for Intel's instructions with a + one-byte opcode" ) + +(defsection two-byte-opcodes + :parents (instructions) + :short "Instruction semantic functions for Intel's instructions with two-byte + opcodes" ) + +(defsection three-byte-opcodes + :parents (instructions) + :short "Instruction semantic functions for Intel's instructions with three-byte + opcodes" ) + +(defsection fp-opcodes + :parents (instructions) + :short "Instruction semantic functions for Intel's floating-point instructions" + ) + +(defsection privileged-opcodes + :parents (instructions) + :short "Instruction semantic functions for Intel's privileged instructions" + ) + +(defsection instruction-semantic-functions + :parents (instructions) + :short "Instruction Semantic Functions" + :long "

The instruction semantic functions have dual roles:

+ +
    +
  1. They fetch the instruction's operands, as dictated by the decoded + components of the instruction \(like the prefixes, SIB byte, etc.\) + provided as input; these decoded components are provided by our x86 + decoder function @(see x86-fetch-decode-execute).
  2. + +
  3. They contain or act as the functional specification of the + instructions. For example, the functional specification function of + the ADD instruction returns two values: the appropriately truncated + sum of the operands and the modified flags. We do not deal with the + x86 state in these specifications.
  4. +
+ +

Each semantic function takes, among other arguments, the value +@('start-rip') of the instruction pointer at the beginning of the +instruction, and the value @('temp-rip') of the instruction pointer +after the decoding of the prefixes, REX byte, opcode, ModR/M byte, and +SIB byte (some of these bytes may not be present). The semantic +function may further increment the instruction pointer beyond +@('temp-rip') to read the ending bytes of the instruction, e.g. to +read a displacement or an immediate. The semantic function eventually +writes the final value of the instruction pointer into RIP.

") + +;; ---------------------------------------------------------------------- + +(in-theory (e/d () (rip-guard-okp))) + +;; ====================================================================== + +;; To see the rules in the instruction-decoding-and-spec-rules +;; ruleset: + +(define show-inst-decoding-and-spec-fn + ((state)) + :mode :program + (let ((world (w state))) + (ruleset-theory 'instruction-decoding-and-spec-rules))) + +(defmacro show-inst-decoding-and-spec-ruleset () + `(show-inst-decoding-and-spec-fn state)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/xor-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/xor-spec.lisp new file mode 100644 index 000000000..b3bfe69fe --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/xor-spec.lisp @@ -0,0 +1,147 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +;; This book contains the specification of the following instructions: +;; xor + +(include-book "structures" :dir :utils) +(include-book "../rflags-spec") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== +;; SPECIFICATION: XOR +;; ====================================================================== + +(define gpr-xor-spec-gen-fn ((operand-size :type (member 1 2 4 8))) + :verify-guards nil + + (b* ((fn-name (mk-name "GPR-XOR-SPEC-" operand-size)) + (result-nbits (ash operand-size 3)) + (str-nbits (if (eql result-nbits 8) "08" result-nbits)) + (pf-spec-fn (mk-name "PF-SPEC" result-nbits)) + (sf-spec-fn (mk-name "SF-SPEC" result-nbits))) + + + `(define ,fn-name + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (input-rflags :type (unsigned-byte 32))) + :parents (,(mk-name "GPR-ARITH/LOGIC-SPEC-" operand-size)) + :guard-hints (("Goal" :in-theory (e/d* (rflag-RoWs-enables) + ((tau-system))))) + :inline t + :no-function t + + (b* ((dst (mbe :logic (n-size ,result-nbits dst) + :exec dst)) + (src (mbe :logic (n-size ,result-nbits src) + :exec src)) + (input-rflags (mbe :logic (n32 input-rflags) + :exec input-rflags)) + + ((the (unsigned-byte ,result-nbits) result) + (mbe :logic (part-select (logxor dst src) + :low 0 :width ,result-nbits) + :exec (logxor dst src))) + + (cf 0) + (pf (the (unsigned-byte 1) (,pf-spec-fn result))) + ;; AF is undefined. + (zf (the (unsigned-byte 1) (zf-spec result))) + (sf (the (unsigned-byte 1) (,sf-spec-fn result))) + (of 0) + + (output-rflags (mbe :logic + (change-rflagsBits + input-rflags + :cf cf + :pf pf + :zf zf + :sf sf + :of of) + :exec + (the (unsigned-byte 32) + (!rflagsBits->cf + cf + (!rflagsBits->pf + pf + (!rflagsBits->zf + zf + (!rflagsBits->sf + sf + (!rflagsBits->of + of input-rflags)))))))) + + (output-rflags (mbe :logic (n32 output-rflags) + :exec output-rflags)) + + ;; AF is undefined. + (undefined-flags (!rflagsBits->af 1 0))) + + (mv result output-rflags undefined-flags)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N" str-nbits "-MV-NTH-0-" fn-name) + :bound ,result-nbits + :concl (mv-nth 0 (,fn-name dst src input-rflags)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-1-" fn-name) + :bound 32 + :concl (mv-nth 1 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t) + + (defthm-unsigned-byte-p ,(mk-name "MV-NTH-2-" fn-name) + :bound 32 + :concl (mv-nth 2 (,fn-name dst src input-rflags)) + :gen-type t + :gen-linear t)))) + +(make-event (gpr-xor-spec-gen-fn 1)) +(make-event (gpr-xor-spec-gen-fn 2)) +(make-event (gpr-xor-spec-gen-fn 4)) +(make-event (gpr-xor-spec-gen-fn 8)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/linear-memory.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/linear-memory.lisp new file mode 100644 index 000000000..b93d7725e --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/linear-memory.lisp @@ -0,0 +1,6904 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2024, Kestrel Technology, LLC + +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Robert Krug +; Contributing Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) +; Eric Smith (eric.smith@kestrel.edu) + +(in-package "X86ISA") +(include-book "paging") +(include-book "centaur/bitops/merge" :dir :system) + +;; ====================================================================== + +;(local (include-book "guard-helpers")) +; (local (include-book "centaur/bitops/ihs-extensions" :dir :system)) ;; Redundant +(local (include-book "centaur/bitops/signed-byte-p" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) +(local (include-book "std/basic/inductions" :dir :system)) +(local (include-book "kestrel/bv/unsigned-byte-p" :dir :system)) + +(set-case-split-limitations '(0 100)) ; for speed + +;; ====================================================================== + +(defsection linear-memory + :parents (machine) + :short "Linear Memory Accessor and Updater Functions" + :long "

First, a quick note about virtual, linear, and physical + addresses:

+ +
    +
  • Linear (or Virtual) Address: In the flat memory model (see + Intel Vol. 1, Section 3.3.1), memory appears to a program as a single, + continuous address space, called a linear (or virtual) address + space. An address for any byte in linear address space is called a + linear address. When paging is disabled, then a linear address is the + same as a physical address.
  • + +
  • Physical Address: The memory that the processor addresses + on its bus is called physical memory. Physical memory is organized as + a sequence of 8-bit bytes. Each byte is assigned a unique address, + called a physical address. When employing the processor's memory + management facilities, programs do not directly address physical + memory.
  • + +
" ) + +(local (xdoc::set-default-parents linear-memory)) + +;; ====================================================================== + +;; Some utilities to generate numerous (but efficient) RoW and WoW +;; kinda theorems: + +(defun remove-elements-from-list (elems lst) + (if (or (endp lst) (endp elems)) + lst + (if (member (car lst) elems) + (remove-elements-from-list (remove (car lst) elems) (cdr lst)) + (cons (car lst) (remove-elements-from-list elems (cdr lst)))))) + +(defun search-and-replace-once (search-term replace-term lst) + (if (endp lst) + nil + (if (equal search-term (car lst)) + (cons replace-term (cdr lst)) + (cons (car lst) (search-and-replace-once search-term replace-term (cdr lst)))))) + +(defun generate-read-fn-over-xw-thms-1 + (xw-fld read-fn read-fn-formals output-index hyps-term double-rewrite-in-concl?) + ;; (generate-read-fn-over-xw-thms-1 :RGF 'gather-all-paging-structure-qword-addresses '(x86) -1 t t) + (b* ((body + (if (equal output-index -1) + `(equal + (,read-fn + ,@(search-and-replace-once 'x86 `(XW ,xw-fld index val x86) read-fn-formals)) + (,read-fn + ,@(if double-rewrite-in-concl? + (search-and-replace-once 'x86 '(double-rewrite x86) read-fn-formals) + read-fn-formals))) + `(equal + (mv-nth ,output-index + (,read-fn + ,@(search-and-replace-once + 'x86 `(XW ,xw-fld index val x86) read-fn-formals))) + (mv-nth ,output-index + (,read-fn ,@(if double-rewrite-in-concl? + (search-and-replace-once + 'x86 '(double-rewrite x86) read-fn-formals) + read-fn-formals))))))) + `(defthm ,(mk-name (if (equal output-index -1) + read-fn + (mk-name "MV-NTH-" output-index "-" read-fn)) + "-XW-" xw-fld) + ,(if (atom hyps-term) + body + `(implies ,hyps-term ,body))))) + +(defun generate-read-fn-over-xw-thms-aux + (xw-flds read-fn read-fn-formals output-index hyps-term double-rewrite-in-concl?) + (if (endp xw-flds) + nil + (cons + (generate-read-fn-over-xw-thms-1 + (car xw-flds) read-fn read-fn-formals output-index hyps-term double-rewrite-in-concl?) + (generate-read-fn-over-xw-thms-aux + (cdr xw-flds) read-fn read-fn-formals output-index hyps-term double-rewrite-in-concl?)))) + +(define generate-read-fn-over-xw-thms + (xw-flds read-fn read-fn-formals + &key + (output-index '-1) + (hyps 't) + (double-rewrite? 'nil) + (prepwork 'nil)) + :verify-guards nil + ;; (generate-read-fn-over-xw-thms + ;; *x86-field-names-as-keywords* + ;; 'rvm08 + ;; (acl2::formals 'rvm08$inline (w state)) + ;; :prepwork '((local (in-theory (e/d* () (xw)))))) + `(encapsulate () + ,@(or prepwork nil) + ,@(generate-read-fn-over-xw-thms-aux + xw-flds read-fn read-fn-formals output-index hyps double-rewrite?))) + +(defun generate-write-fn-over-xw-thms-1 + (xw-fld write-fn write-fn-formals output-index hyps-term) + ;; (generate-write-fn-over-xw-thms-1 :RGF 'rvm08 '(addr x86) 2 t) + (b* ((body + (if (equal output-index -1) + `(equal + (,write-fn + ,@(search-and-replace-once 'x86 `(XW ,xw-fld index val x86) write-fn-formals)) + (XW ,xw-fld index val ,(cons write-fn write-fn-formals))) + `(equal + (mv-nth + ,output-index + (,write-fn + ,@(search-and-replace-once 'x86 `(XW ,xw-fld index val x86) write-fn-formals))) + (XW ,xw-fld index val (mv-nth ,output-index ,(cons write-fn write-fn-formals))))))) + `(defthm ,(mk-name (if (equal output-index -1) + write-fn + (mk-name "MV-NTH-" output-index "-" write-fn)) + "-XW-" xw-fld) + ,(if (atom hyps-term) + body + `(implies ,hyps-term ,body))))) + +(defun generate-write-fn-over-xw-thms-aux + (xw-flds write-fn write-fn-formals output-index hyps-term) + (if (endp xw-flds) + nil + (cons (generate-write-fn-over-xw-thms-1 + (car xw-flds) write-fn write-fn-formals output-index hyps-term) + (generate-write-fn-over-xw-thms-aux + (cdr xw-flds) write-fn write-fn-formals output-index hyps-term)))) + +(define generate-write-fn-over-xw-thms + (xw-flds write-fn write-fn-formals + &key + (output-index '-1) + (hyps 't) + (prepwork 'nil)) + :verify-guards nil + ;; (generate-write-fn-over-xw-thms + ;; *x86-field-names-as-keywords* + ;; 'wvm08 + ;; (acl2::formals 'wvm08$inline (w state)) + ;; :prepwork '((local (in-theory (e/d* () (xw)))))) + `(encapsulate () + ,@(or prepwork nil) + ,@(generate-write-fn-over-xw-thms-aux xw-flds write-fn write-fn-formals output-index hyps))) + +(defun generate-xr-over-write-thms-1 + (xr-fld write-fn write-fn-formals output-index hyps-term double-rewrite-in-concl?) + ;; (generate-xr-over-write-thms-1 :RGF 'rb '(addr r-x x86) 2 t nil) + (b* ((body + (if (equal output-index -1) + `(equal (XR ,xr-fld index ,(cons write-fn write-fn-formals)) + (XR ,xr-fld index ,(if double-rewrite-in-concl? + `(double-rewrite x86) + `x86))) + `(equal (XR ,xr-fld index (mv-nth ,output-index ,(cons write-fn write-fn-formals))) + (XR ,xr-fld index ,(if double-rewrite-in-concl? + `(double-rewrite x86) + `x86)))))) + `(defthm ,(mk-name "XR-" xr-fld "-" + (if (equal output-index -1) + write-fn (mk-name "MV-NTH-" output-index "-" write-fn))) + ,(if (atom hyps-term) + body + `(implies ,hyps-term ,body))))) + +(defun generate-xr-over-write-thms-aux + (xr-flds write-fn write-fn-formals output-index hyps-term double-rewrite?) + (if (endp xr-flds) + nil + (cons + (generate-xr-over-write-thms-1 + (car xr-flds) write-fn write-fn-formals output-index hyps-term double-rewrite?) + (generate-xr-over-write-thms-aux + (cdr xr-flds) write-fn write-fn-formals output-index hyps-term double-rewrite?)))) + +(define generate-xr-over-write-thms + (xr-flds write-fn write-fn-formals + &key + (output-index '-1) + (hyps 't) + (double-rewrite? 'nil) + (prepwork 'nil)) + :verify-guards nil + ;; (generate-xr-over-write-thms + ;; *x86-field-names-as-keywords* + ;; 'wvm08 + ;; (acl2::formals 'wvm08$inline (w state)) + ;; :prepwork '((local (in-theory (e/d* () (xw)))))) + `(encapsulate () + ,@(or prepwork nil) + ,@(generate-xr-over-write-thms-aux + xr-flds write-fn write-fn-formals output-index hyps double-rewrite?))) + +;; ====================================================================== + +;; Some misc. arithmetic lemmas and macros: + +(defthm signed-byte-p-limits-thm + ;; i is positive, k is positive, k < i + (implies (and (signed-byte-p n (+ i addr)) + (signed-byte-p n addr) + (integerp k) + (<= 0 k) + (< k i)) + (signed-byte-p n (+ k addr)))) + +(defthmd push-ash-inside-logior + (equal (ash (logior x y) n) + (logior (ash x n) (ash y n))) + :hints (("Goal" :in-theory (e/d* (ihsext-recursive-redefs + ihsext-inductions) + ())))) + +(local (in-theory (e/d () (unsigned-byte-p)))) + +;; ====================================================================== + +;; Events related to RB and WB: + +(defsection reasoning-about-memory-reads-and-writes + :parents (linear-memory) + :short "Definitions of @(see rb) and @(see wb)" + + :long "

The functions @('rb') (read bytes) and @('wb') (write + bytes) are used in reasoning about memory reads and writes. Functions + like @('rml08'), @('rml16'), @('rml32'), and @('rml64') are reduced to + @('rb'), and @('wml08'), @('wml16'), @('wml32'), and @('wml64') to + @('wb') during reasoning.

" + + (local (xdoc::set-default-parents reasoning-about-memory-reads-and-writes)) + + (define canonical-address-listp (lst) + :short "Recognizer of a list of canonical addresses" + :enabled t + (if (equal lst nil) + t + (and (consp lst) + (canonical-address-p (car lst)) + (canonical-address-listp (cdr lst)))) + /// + (defthm cdr-canonical-address-listp + (implies (canonical-address-listp x) + (canonical-address-listp (cdr x))))) + + (define create-canonical-address-list (count addr) + :guard (natp count) + + :long "

Given a canonical address @('addr'), + @('create-canonical-address-list') creates a list of canonical + addresses where the first address is @('addr') and the last address + is the last canonical address in the range @('addr') to @('addr + + count').

" + :enabled t + + (if (or (zp count) + (not (canonical-address-p addr))) + nil + (cons addr (create-canonical-address-list (1- count) + (1+ addr)))) + /// + + (defthm true-listp-create-canonical-address-list + (true-listp (create-canonical-address-list cnt lin-addr)) + :rule-classes (:rewrite :type-prescription)) + + (defthm canonical-address-listp-create-canonical-address-list + (canonical-address-listp + (create-canonical-address-list count addr)) + :rule-classes (:rewrite :type-prescription)) + + (defthm create-canonical-address-list-1 + (implies (canonical-address-p x) + (equal (create-canonical-address-list 1 x) + (list x))) + :hints (("Goal" :expand (create-canonical-address-list 1 x)))) + + (defthm len-of-create-canonical-address-list + (implies (and (canonical-address-p (+ -1 addr count)) + (canonical-address-p addr) + (natp count)) + (equal (len (create-canonical-address-list count addr)) + count))) + + (defthm car-create-canonical-address-list + (implies (and (canonical-address-p addr) + (posp count)) + (equal (car (create-canonical-address-list count addr)) + addr))) + + (defthm cdr-create-canonical-address-list + (implies (and (canonical-address-p addr) + (posp count)) + (equal (cdr (create-canonical-address-list count addr)) + (create-canonical-address-list (1- count) (1+ addr))))) + + (defthm consp-of-create-canonical-address-list + (implies (and (canonical-address-p addr) + (natp count) + (< 0 count)) + (consp (create-canonical-address-list count addr))) + :hints (("Goal" :in-theory (e/d (canonical-address-p + signed-byte-p) + ())))) + + (defthmd create-canonical-address-list-split + (implies (and (canonical-address-p addr) + (canonical-address-p (+ k addr)) + (natp j) + (natp k)) + (equal (create-canonical-address-list (+ k j) addr) + (append (create-canonical-address-list k addr) + (create-canonical-address-list j (+ k addr))))) + :hints (("Goal" :in-theory (e/d* (canonical-address-p signed-byte-p) + ()))))) + + (local + (defthm ash-n-3-minus-8-lemma + (implies (posp n) + (equal (+ -8 (ash n 3)) + (ash (+ -1 n) 3))) + :hints (("goal" :in-theory (e/d* (bitops::ihsext-inductions + bitops::ihsext-recursive-redefs + ash floor) + ()))))) + + (local + (defthm unsigned-byte-p-of-ash-x-8-lemma + (implies + (and (unsigned-byte-p (ash (+ -1 n) 3) x) + (< 0 n) + (integerp n)) + (unsigned-byte-p (ash n 3) (ash x 8))) + :hints (("goal" :in-theory (e/d () (unsigned-byte-p-of-ash)) + :use ((:instance unsigned-byte-p-of-ash + (n (ash n 3)) + (x x) + (m 8))))))) + + (local + (defthm byte-width-unsigned-byte-p-ash-incr + (implies (and (unsigned-byte-p 8 b) + (posp n)) + (unsigned-byte-p (ash n 3) b)) + :hints (("Goal" + :use ((:instance bitops::unsigned-byte-p-incr + (a 8) (x b) (b (ash n 3)))) + :in-theory (e/d (ash floor) + (bitops::unsigned-byte-p-incr)))))) + + (local + (defthm unsigned-byte-p-of-logior-ash-x-8-lemma + (implies + (and (unsigned-byte-p (ash (+ -1 n) 3) x) + (unsigned-byte-p 8 b) + (< 0 n) + (integerp n)) + (unsigned-byte-p (ash n 3) (logior b (ash x 8)))) + :hints (("goal" :in-theory (e/d () + (unsigned-byte-p-of-logior + ash-n-3-minus-8-lemma + byte-width-unsigned-byte-p-ash-incr)) + :use ((:instance byte-width-unsigned-byte-p-ash-incr) + (:instance unsigned-byte-p-of-logior + (n (ash n 3)) + (i b) + (j (ash x 8)))))))) + + (define rb-1 ((n natp "Number of bytes to be read") + (addr integerp "First linear address") + (r-x :type (member :r :x) "Type of memory access") + (x86)) + :verify-guards :after-returns + :returns + (mv flg + (val natp :rule-classes :type-prescription) + (new-x86 x86p :hyp (x86p x86))) + + :guard (canonical-address-p (+ -1 n addr)) + :enabled t + + (if (zp n) + (mv nil 0 x86) + ;; rb-1 is used only in the app-level view so it makes sense to + ;; use rvm08 here. + (b* (((unless (canonical-address-p addr)) + (mv 'rb-1 0 x86)) + ((mv flg0 byte0 x86) + (rvm08 addr x86)) + ((when flg0) + (mv flg0 0 x86)) + ((mv rest-flg rest-bytes x86) + (rb-1 (1- n) (1+ addr) r-x x86))) + (mv rest-flg (logior byte0 (ash rest-bytes 8)) x86))) + + /// + + (defret integerp-of-mv-nth-1-rb-1 + (integerp val) + :rule-classes :type-prescription) + + (defret rb-1-returns-x86 + (implies t ;; (app-view x86) + (equal new-x86 x86))) + + (local + (defthm rb-1-returns-no-error-helper + (implies t ;; (xr :app-view nil x86) + (not (mv-nth 0 (rb-1 1 #.*2^47-1* r-x x86)))) + :hints (("Goal" :expand (rb-1 1 #.*2^47-1* r-x x86))))) + + (defthm rb-1-returns-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ -1 n addr)) + ;; (app-view x86) + ) + (equal (mv-nth 0 (rb-1 n addr r-x x86)) nil)) + :hints (("Goal" :in-theory (e/d (rvm08) ())))) + + (defthm-unsigned-byte-p size-of-rb-1 + :hyp (and (equal m (ash n 3)) (natp n)) + :bound m + :concl (mv-nth 1 (rb-1 n addr r-x x86)) + :hints (("Goal" :in-theory (e/d* (rvm08) (unsigned-byte-p signed-byte-p)))) + :gen-linear t) + + (encapsulate () + (local (include-book "kestrel/arithmetic-light/floor" :dir :system)) + (defthm unsigned-byte-p-of-mv-nth-1-of-rb-1 + (implies (and (<= (* 8 n) size) + (natp size)) + (unsigned-byte-p size (mv-nth 1 (rb-1 n addr r-x x86)))) + :hints (("Goal" :use (:instance size-of-rb-1 (m (ash n 3))) + :in-theory (e/d (ash) (size-of-rb-1)))))) + ) + + (define las-to-pas + ((n natp "Number of bytes to be read") + (lin-addr integerp "First linear address") + (r-w-x :type (member :r :w :x) "Type of memory access: read, write, or execute") + x86) + :enabled t + :guard (not (app-view x86)) ;; Not x86 "flat" mode or ``app(lication) mode'' + :verify-guards nil + ;; It'd be sweet if las-to-pas returned the following instead of a + ;; list of physical addresses: , where this region of + ;; physical memory corresponds to the linear memory region under + ;; consideration . However, it's not quite so simple + ;; because a contiguous linear memory region, like the one denoted + ;; by , can map to multiple non-contiguous physical + ;; memory regions. + :returns (mv flg + (p-addrs true-listp :rule-classes (:rewrite :type-prescription)) + (x86 x86p :hyp (x86p x86) :hints (("Goal" :in-theory (e/d () (x86p)))))) + + (if (zp n) + (mv nil nil x86) + (b* (((unless (canonical-address-p lin-addr)) + (mv t nil x86)) + ((mv flg p-addr x86) + (ia32e-la-to-pa lin-addr r-w-x x86)) + ((when flg) (mv flg nil x86)) + ((mv flg p-addrs x86) + (las-to-pas (1- n) (1+ lin-addr) r-w-x x86))) + (mv flg (if flg nil (cons p-addr p-addrs)) x86))) + + /// + + (defthm consp-mv-nth-1-las-to-pas + (implies (and (not (mv-nth 0 (las-to-pas n lin-addr r-w-x x86))) + (not (zp n))) + (consp (mv-nth 1 (las-to-pas n lin-addr r-w-x x86)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm car-mv-nth-1-las-to-pas + (implies (and (not (mv-nth 0 (las-to-pas n lin-addr r-w-x x86))) + (not (zp n))) + (equal (car (mv-nth 1 (las-to-pas n lin-addr r-w-x x86))) + (mv-nth 1 (ia32e-la-to-pa lin-addr r-w-x x86)))) + :hints (("Goal" :in-theory (e/d* (las-to-pas) ())))) + + (defthm physical-address-listp-mv-nth-1-las-to-pas + (physical-address-listp (mv-nth 1 (las-to-pas n lin-addr r-w-x x86)))) + + (defthm las-to-pas-n=0 + (and (equal (mv-nth 0 (las-to-pas 0 lin-addr r-w-x x86)) nil) + (equal (mv-nth 1 (las-to-pas 0 lin-addr r-w-x x86)) nil) + (equal (mv-nth 2 (las-to-pas 0 lin-addr r-w-x x86)) x86))) + + (defthm xr-las-to-pas + (implies + (and (not (equal fld :tlb)) + (not (equal fld :mem)) + (not (equal fld :fault))) + (equal (xr fld index (mv-nth 2 (las-to-pas n lin-addr r-w-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + ;; The double-rewrites below are crucial to the applicability of the rules + ;; below (in sys-view mode). + (defthm xr-rflags-las-to-pas + (implies (not (mv-nth 0 (las-to-pas n lin-addr r-w-x (double-rewrite x86)))) + (equal (xr :rflags nil (mv-nth 2 (las-to-pas n lin-addr r-w-x x86))) + (xr :rflags nil (double-rewrite x86)))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm xr-fault-las-to-pas + (implies (not (mv-nth 0 (las-to-pas n lin-addr r-w-x (double-rewrite x86)))) + (equal (xr :fault nil (mv-nth 2 (las-to-pas n lin-addr r-w-x x86))) + (xr :fault nil (double-rewrite x86)))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm las-to-pas-xw-values + (implies (and (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :fault)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :seg-visible)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + ;; or we could say this: + ;; (not (member-equal fld '(:mem :rflags :fault :ctr :msr :app-view :marking-view :seg-visible :tlb :implicit-supervisor-access))) + ) + (and (equal (mv-nth 0 (las-to-pas n lin-addr r-w-x (xw fld index val x86))) + (mv-nth 0 (las-to-pas n lin-addr r-w-x x86))) + (equal (mv-nth 1 (las-to-pas n lin-addr r-w-x (xw fld index val x86))) + (mv-nth 1 (las-to-pas n lin-addr r-w-x x86)))))) + + (defrule 64-bit-modep-of-las-to-pas + (equal (64-bit-modep (mv-nth 2 (las-to-pas n lin-addr r-w-x x86))) + (64-bit-modep x86)) + :hints (("Goal" :in-theory (e/d* (64-bit-modep) (force (force)))))) + + (defrule x86-operation-mode-of-las-to-pas + (equal (x86-operation-mode (mv-nth 2 (las-to-pas n lin-addr r-w-x x86))) + (x86-operation-mode x86)) + :hints (("Goal" :in-theory (e/d* (x86-operation-mode) + (las-to-pas))))) + + (defthm las-to-pas-xw-state + (implies (and (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :fault)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :seg-visible)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + ;; or we could say this: + ;; (not (member-equal fld '(:mem :rflags :fault :ctr :msr :app-view :marking-view :seg-visible :tlb :implicit-supervisor-access))) + ) + (equal (mv-nth 2 (las-to-pas n lin-addr r-w-x (xw fld index val x86))) + (xw fld index val(mv-nth 2 (las-to-pas n lin-addr r-w-x x86)))))) + + (local + (defun-nx las-to-pas-xw-rflags-not-ac-hint (lin-addr n r-w-x value x86) + (declare (xargs :measure (nfix n))) + (if (zp n) + x86 + (if (not (canonical-address-p lin-addr)) + x86 + (if (mv-nth 0 (ia32e-la-to-pa lin-addr r-w-x x86)) + x86 + (las-to-pas-xw-rflags-not-ac-hint + (+ 1 lin-addr) (+ -1 n) r-w-x value + (mv-nth 2 (ia32e-la-to-pa lin-addr r-w-x x86)))))))) + + (defthm las-to-pas-xw-rflags-not-ac + (implies (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags (double-rewrite x86)))) + (and + (equal (mv-nth 0 (las-to-pas n lin-addr r-w-x (xw :rflags nil value x86))) + (mv-nth 0 (las-to-pas n lin-addr r-w-x (double-rewrite x86)))) + (equal (mv-nth 1 (las-to-pas n lin-addr r-w-x (xw :rflags nil value x86))) + (mv-nth 1 (las-to-pas n lin-addr r-w-x (double-rewrite x86)))))) + :hints (("Goal" + :induct (las-to-pas-xw-rflags-not-ac-hint lin-addr n r-w-x value x86) + :in-theory (e/d () (force (force)))))) + + (defthm las-to-pas-xw-rflags-state-not-ac + (implies (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86))) + (equal (mv-nth 2 (las-to-pas n lin-addr r-w-x (xw :rflags nil value x86))) + (xw :rflags nil value (mv-nth 2 (las-to-pas n lin-addr r-w-x x86))))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm len-of-mv-nth-1-las-to-pas + (implies (not (mv-nth 0 (las-to-pas n lin-addr r-w-x x86))) + (equal (len (mv-nth 1 (las-to-pas n lin-addr r-w-x x86))) + (nfix n)))) + (verify-guards las-to-pas)) + + (define read-from-physical-memory ((p-addrs physical-address-listp) + x86) + :parents (reasoning-about-memory-reads-and-writes physical-memory) + :enabled t + :verify-guards :after-returns + :returns (value integerp :rule-classes :type-prescription) + :guard (not (app-view x86)) + (if (endp p-addrs) + 0 + (b* ((addr0 (car p-addrs)) + (byte0 (memi addr0 x86)) + (rest-bytes (read-from-physical-memory (cdr p-addrs) x86))) + (logior byte0 (ash rest-bytes 8)))) + + /// + + (defthm-unsigned-byte-p size-of-read-from-physical-memory + :hyp (equal n (ash (len p-addrs) 3)) + :bound n + :concl (read-from-physical-memory p-addrs x86) + :hints (("Goal" :in-theory (e/d* () (signed-byte-p)))) + :gen-type t + :gen-linear t) + + (encapsulate () + (local (include-book "kestrel/arithmetic-light/floor" :dir :system)) + (defthm unsigned-byte-p-of-read-from-physical-memory + (implies (and (<= (* 8 (len p-addrs)) size) + (integerp size)) + (unsigned-byte-p size (read-from-physical-memory p-addrs x86))) + :hints (("Goal" :use (:instance size-of-read-from-physical-memory (n (* 8 (len p-addrs)))) + :in-theory (e/d (ash) (size-of-read-from-physical-memory)))))) + + (defthm read-from-physical-memory-xw-rflags + (equal (read-from-physical-memory p-addrs (xw :rflags nil val x86)) + (read-from-physical-memory p-addrs x86))) + + (defthm read-from-physical-memory-xw-not-mem + (implies (not (equal fld :mem)) + (equal (read-from-physical-memory p-addrs (xw fld index val x86)) + (read-from-physical-memory p-addrs x86))))) + + (define rb ((n natp "Number of bytes to be read") + (addr integerp "First linear address") + (r-x :type (member :r :x) "Type of memory access") + (x86)) + :enabled t + :verify-guards :after-returns + :returns (mv flg + (val integerp :rule-classes :type-prescription) + (new-x86 x86p :hyp (x86p x86) :hints (("Goal" :in-theory (e/d () (x86p)))))) + + :guard (canonical-address-p (+ -1 n addr)) + + (if (app-view x86) + (rb-1 n addr r-x x86) + (b* (((mv flg p-addrs x86) + (las-to-pas n addr r-x x86)) + ((when flg) (mv flg 0 x86)) + (val (read-from-physical-memory p-addrs x86))) + (mv nil val x86))) + + /// + + (defret natp-of-mv-nth-1-rb + (natp val) + :hints (("Goal" :in-theory (e/d* () (force (force))))) + :rule-classes :type-prescription) + + (defret rb-no-reads-when-zp-n + (implies (zp n) + (equal val 0)) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthmd rb-is-rb-1-for-app-view + (implies (app-view x86) + (equal (rb n addr r-x x86) + (rb-1 n addr r-x x86)))) + + (defthm rb-returns-no-error-app-view + (implies (and (app-view x86) + (canonical-address-p addr) + (canonical-address-p (+ -1 n addr))) + (equal (mv-nth 0 (rb n addr r-x x86)) nil))) + + (defthm rb-returns-x86-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rb n addr r-x x86)) x86))) + + (defthm-unsigned-byte-p size-of-rb + :hyp (and (equal m (ash n 3)) + (natp n)) + :bound m + :concl (mv-nth 1 (rb n addr r-x x86)) + :hints (("Goal" + :do-not-induct t + :in-theory (e/d* () (unsigned-byte-p)))) + :gen-linear t) + + (defthm-unsigned-byte-p size-of-rb-in-app-view + ;; No need to know whether the addresses are canonical or not... + :hyp (and (app-view x86) (natp n)) + :bound (ash n 3) + :concl (mv-nth 1 (rb n addr r-x x86)) + :gen-linear t) + + (defthm rb-values-and-xw-rflags-in-sys-view + (implies (and (equal (rflagsBits->ac (double-rewrite value)) + (rflagsBits->ac (rflags x86))) + (not (app-view x86)) + (x86p x86)) + (and (equal (mv-nth 0 (rb n addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rb n addr r-x (double-rewrite x86)))) + (equal (mv-nth 1 (rb n addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rb n addr r-x (double-rewrite x86)))))) + :hints (("Goal" + :do-not-induct t + :in-theory (e/d* (rb) ())))) + + (defrule 64-bit-modep-of-rb + (equal (64-bit-modep (mv-nth 2 (rb n addr r-x x86))) + (64-bit-modep x86)) + :enable 64-bit-modep + :disable (force (force))) + + (defrule x86-operation-mode-of-rb + (equal (x86-operation-mode (mv-nth 2 (rb n addr r-x x86))) + (x86-operation-mode x86)) + :enable x86-operation-mode + :disable rb)) + + ;; Definition of WB and other related events: + + (define wb-1 ((n natp "Number of bytes to be written") + (addr integerp "First linear address") + ;; I could do away with the following argument (w), + ;; but I choose to keep it around because the current + ;; version of Codewalker expects reader and writer + ;; functions to have similar signatures. + (w :type (member :w) "Type of memory access: write") + (value natp) + (x86)) + :guard (canonical-address-p (+ -1 n addr)) + :enabled t + :ignore-ok t + + (if (zp n) + (mv nil x86) + ;; wb-1 is used only in the app-view, so it makes sense to + ;; use wvm08 here. + (b* (((unless (canonical-address-p addr)) + (mv t x86)) + ((mv flg0 x86) + (wvm08 addr (loghead 8 value) x86)) + ((when flg0) + (mv flg0 x86)) + ((mv rest-flg x86) + (wb-1 (1- n) (1+ addr) w (logtail 8 value) x86))) + (mv rest-flg x86))) + + /// + + (defthm wb-1-returns-x86p + (implies (x86p x86) + (x86p (mv-nth 1 (wb-1 n addr w value x86)))) + :hints (("Goal" :in-theory (e/d () (x86p))))) + + (local + (defthm wb-1-returns-no-error-helper + (implies t ;; (xr :app-view nil x86) + (not (mv-nth 0 (wb-1 1 #.*2^47-1* w value x86)))) + :hints (("Goal" :expand (wb-1 1 #.*2^47-1* w value x86))))) + + (defthm wb-1-returns-no-error + (implies (and (canonical-address-p addr) + (canonical-address-p (+ -1 n addr)) + ;; (app-view x86) + ) + (equal (mv-nth 0 (wb-1 n addr w value x86)) + nil)) + :hints (("Goal" :in-theory (e/d (wvm08) ()))))) + + (define write-to-physical-memory ((p-addrs physical-address-listp) + (value natp) + x86) + :parents (reasoning-about-memory-reads-and-writes physical-memory) + :enabled t + :guard (not (app-view x86)) + (if (endp p-addrs) + x86 + (b* ((addr0 (car p-addrs)) + (byte0 (loghead 8 value)) + (x86 (!memi addr0 byte0 x86))) + (write-to-physical-memory (cdr p-addrs) (logtail 8 value) x86))) + + /// + + (defthm x86p-write-to-physical-memory + (implies (and (x86p x86) + ;; The following hypothesis can be weakened to + ;; integer-listp. + (physical-address-listp p-addrs)) + (x86p (write-to-physical-memory p-addrs value x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm xr-not-mem-write-to-physical-memory + (implies (not (equal fld :mem)) + (equal (xr fld index (write-to-physical-memory p-addrs bytes x86)) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm write-to-physical-memory-xw-in-sys-view + ;; Keep the state updated by write-to-physical-memory inside all other nests of writes. + (implies (not (equal fld :mem)) + (equal (write-to-physical-memory p-addrs bytes (xw fld index value x86)) + (xw fld index value (write-to-physical-memory p-addrs bytes x86)))) + :hints (("Goal" :in-theory (e/d* (write-to-physical-memory) ())))) + + (defrule 64-bit-modep-of-write-to-physical-memory + (equal (64-bit-modep (write-to-physical-memory p-addrs value x86)) + (64-bit-modep x86)) + :enable 64-bit-modep + :disable (force (force))) + + (defrule x86-operation-mode-of-write-to-physical-memory + (equal (x86-operation-mode (write-to-physical-memory p-addrs value x86)) + (x86-operation-mode x86)) + :enable x86-operation-mode + :disable write-to-physical-memory)) + + (define wb ((n natp "Number of bytes to be written") + (addr integerp "First linear address") + ;; I could do away with the following argument (w), + ;; but I choose to keep it around because the current + ;; version of Codewalker expects reader and writer + ;; functions to have similar signatures. + (w :type (member :w) "Type of memory access") + (value natp) + (x86)) + + :ignore-ok t + :guard (canonical-address-p (+ -1 n addr)) + :enabled t + + (if (app-view x86) + (wb-1 n addr w value x86) + (b* (((mv flg p-addrs x86) + (las-to-pas n addr :w x86)) + ((when flg) (mv flg x86)) + (x86 (write-to-physical-memory p-addrs value x86))) + (mv nil x86))) + + /// + + (defthm wb-no-writes-when-zp-n + (equal (mv-nth 1 (wb 0 addr val w x86)) x86) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthmd wb-is-wb-1-for-app-view + (implies (app-view x86) + (equal (wb n addr w value x86) + (wb-1 n addr w value x86)))) + + (defthm x86p-of-wb + (implies (x86p x86) + (x86p (mv-nth 1 (wb n addr w value x86)))) + :hints (("Goal" :in-theory (e/d () (x86p))))) + + (defthm wb-returns-no-error-app-view + (implies (and (canonical-address-p addr) + (canonical-address-p (+ -1 n addr)) + (app-view x86)) + (equal (mv-nth 0 (wb n addr w value x86)) nil)))) + + (defthm wb-by-wb-1-for-app-view-induction-rule + t + :rule-classes ((:induction :pattern (wb n addr w value x86) + :condition (app-view x86) + :scheme (wb-1 n addr w value x86)))) + + (local (in-theory (e/d () (force (force))))) + + ;; Relating rb and xr/xw in the application-level view: + + (defthm xr-rb-state-in-app-view + (implies (app-view x86) + (equal (xr fld index (mv-nth 2 (rb n addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ())))) + + (defthm rb-xw-values-in-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rb n addr r-x (xw fld index value x86))) + (mv-nth 0 (rb n addr r-x x86))) + (equal (mv-nth 1 (rb n addr r-x (xw fld index value x86))) + (mv-nth 1 (rb n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ()) + :induct (rb-1 n addr r-x x86)))) + + (defthm rb-xw-state-in-app-view + (implies (and (app-view x86) + (not (equal fld :app-view))) + (equal (mv-nth 2 (rb n addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rb n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ())))) + + ;; Relating rb and xr/xw in the system-level view: + + (defthm xr-rb-1-state-in-sys-view + (implies (and (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault))) + (equal (xr fld index (mv-nth 2 (rb-1 n addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ()) + :induct (rb-1 n addr r-x x86)))) + + (defthm xr-rb + (implies (and (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb))) + (equal (xr fld index (mv-nth 2 (rb n addr r-x x86))) + (xr fld index x86)))) + + (defthm rb-1-xw-values-in-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :ctr)) + (not (equal fld :seg-visible)) + (not (equal fld :msr)) + (not (equal fld :fault)) + (not (equal fld :app-view)) + (not (equal fld :marking-view))) + (and (equal (mv-nth 0 (rb-1 n addr r-x (xw fld index value x86))) + (mv-nth 0 (rb-1 n addr r-x x86))) + (equal (mv-nth 1 (rb-1 n addr r-x (xw fld index value x86))) + (mv-nth 1 (rb-1 n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ()) + :induct (rb-1 n addr r-x x86)))) + + (defthm rb-xw-values + (implies (and (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :ctr)) + (not (equal fld :seg-visible)) + (not (equal fld :msr)) + (not (equal fld :fault)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access))) + (and (equal (mv-nth 0 (rb n addr r-x (xw fld index value x86))) + (mv-nth 0 (rb n addr r-x x86))) + (equal (mv-nth 1 (rb n addr r-x (xw fld index value x86))) + (mv-nth 1 (rb n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb) ())))) + + + (defthm rb-1-xw-rflags-not-ac-values-in-sys-view + (implies (and (not (app-view x86)) + (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rb-1 n addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rb-1 n addr r-x x86))) + (equal (mv-nth 1 (rb-1 n addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rb-1 n addr r-x x86))))) + :hints (("Goal" :induct (rb-1 n addr r-x x86) + :in-theory (e/d* (rb rb-1) ())))) + + (defthm rb-xw-rflags-not-ac-values-in-sys-view + (implies (and (not (app-view x86)) + (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rb n addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rb n addr r-x x86))) + (equal (mv-nth 1 (rb n addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rb n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb) ())))) + + (defthm rb-1-xw-state-in-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :ctr)) + (not (equal fld :seg-visible)) + (not (equal fld :msr)) + (not (equal fld :fault)) + (not (equal fld :app-view)) + (not (equal fld :marking-view))) + (equal (mv-nth 2 (rb-1 n addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rb-1 n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ()) + :induct (rb-1 n addr r-x x86)))) + + (defthm rb-xw-state + (implies (and (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :ctr)) + (not (equal fld :seg-visible)) + (not (equal fld :msr)) + (not (equal fld :fault)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access))) + (equal (mv-nth 2 (rb n addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rb n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ()) + :induct (rb-1 n addr r-x x86)))) + + (defthm rb-1-xw-rflags-not-ac-state-in-sys-view + (implies (and (not (app-view x86)) + (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86)))) + (equal (mv-nth 2 (rb-1 n addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value (mv-nth 2 (rb-1 n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb rb-1) ()) + :induct (rb-1 n addr r-x x86)))) + + (defthm rb-xw-rflags-not-ac-state-in-sys-view + (implies (and (not (app-view x86)) + (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86)))) + (equal (mv-nth 2 (rb n addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value (mv-nth 2 (rb n addr r-x x86))))) + :hints (("Goal" :in-theory (e/d* (rb) (force (force)))))) + + ;; Relating wb and xr/xw in the application-level view: + + (defthm xr-wb-1-in-app-view + (implies (and (app-view x86) + (not (equal fld :mem))) + (equal (xr fld index (mv-nth 1 (wb-1 n addr w value x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wb-1) ())))) + + (defthm xr-wb-in-app-view + (implies (and (app-view x86) + (not (equal fld :mem))) + (equal (xr fld index (mv-nth 1 (wb n addr w value x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wb) ())))) + + (defthm wb-1-xw-in-app-view + ;; Keep the state updated by wb-1 inside all other nests of writes. + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (wb-1 n addr w val (xw fld index value x86))) + (mv-nth 0 (wb-1 n addr w val x86))) + (equal (mv-nth 1 (wb-1 n addr w val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wb-1 n addr w val x86)))))) + :hints (("Goal" :in-theory (e/d* (wb-1) ())))) + + (defthm wb-xw-in-app-view + ;; Keep the state updated by wb inside all other nests of writes. + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (wb n addr w val (xw fld index value x86))) + (mv-nth 0 (wb n addr w val x86))) + (equal (mv-nth 1 (wb n addr w val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wb n addr w val x86)))))) + :hints (("Goal" :in-theory (e/d* (wb) ())))) + + ;; Relating wb and xr/xw in the system-level view: + + (defthm xr-wb + (implies (and (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb))) + (equal (xr fld index (mv-nth 1 (wb n addr w value x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wb) ())))) + + (defthm xr-fault-wb-in-system-level-marking-view + (implies + (not (mv-nth 0 (las-to-pas n addr :w (double-rewrite x86)))) + (equal (xr :fault nil (mv-nth 1 (wb n addr w val x86))) + (xr :fault nil x86))) + :hints + (("Goal" :do-not-induct t + :in-theory (e/d* (wb) + ((:meta acl2::mv-nth-cons-meta) + force (force)))))) + + (defrule 64-bit-modep-of-mv-nth-1-of-wb ; contributed by Eric Smith + (equal (64-bit-modep (mv-nth 1 (wb n addr w value x86))) + (64-bit-modep x86)) + :hints (("Goal" :in-theory (e/d* (64-bit-modep) + (force (force)))))) + + (defrule x86-operation-mode-of-mv-nth-1-of-wb + (equal (x86-operation-mode (mv-nth 1 (wb n addr w value x86))) + (x86-operation-mode x86)) + :hints (("Goal" :in-theory (e/d* (x86-operation-mode) + (wb))))) + + (defthm wb-xw-values + (implies (and (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :ctr)) + (not (equal fld :seg-visible)) + (not (equal fld :msr)) + (not (equal fld :fault)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access))) + (equal (mv-nth 0 (wb n addr w value (xw fld index val x86))) + (mv-nth 0 (wb n addr w value x86)))) + :hints (("Goal" :in-theory (e/d* (wb) ())))) + + (defthm wb-xw-state + (implies (and (not (equal fld :mem)) + (not (equal fld :rflags)) + (not (equal fld :ctr)) + (not (equal fld :seg-visible)) + (not (equal fld :msr)) + (not (equal fld :fault)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access))) + (equal (mv-nth 1 (wb n addr w value (xw fld index val x86))) + (xw fld index val (mv-nth 1 (wb n addr w value x86))))) + :hints (("Goal" :in-theory (e/d* (wb) ())))) + + ;; Note that wb is kept inside all other nests of writes. + + (defthm wb-xw-rflags-not-ac-in-sys-view + ;; Keep the state updated by wb inside all other nests of writes. + (implies (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86))) + (and (equal (mv-nth 0 (wb n addr w val (xw :rflags nil value x86))) + (mv-nth 0 (wb n addr w val (double-rewrite x86)))) + (equal (mv-nth 1 (wb n addr w val (xw :rflags nil value x86))) + (xw :rflags nil value (mv-nth 1 (wb n addr w val x86)))))) + :hints (("Goal" :in-theory (e/d* (wb) (write-to-physical-memory))))) + + (defthm xr-fault-wb-in-sys-view + (implies (and (not (mv-nth 0 (las-to-pas n addr :w x86))) + (not (marking-view x86))) + (equal (xr :fault nil (mv-nth 1 (wb n addr w val x86))) + (xr :fault nil x86))) + :hints + (("Goal" :in-theory (e/d* (wb) + (write-to-physical-memory force (force)))))) + + (local + (encapsulate + () + + (local (include-book "arithmetic-3/top" :dir :system)) + + (defthm ash-and-plus + (implies (posp n) + (equal (+ 8 (ash (+ -1 n) 3)) + (ash n 3))) + :hints (("Goal" :in-theory (e/d* (ash) ())))) + + (defthm ash-and-minus + (implies (posp n) + (equal (+ -8 (ash n 3)) + (ash (+ -1 n) 3))) + :hints (("Goal" :in-theory (e/d* (ash) ())))) + + (defthm ash-n-3-bound + (implies (and (not (zp n)) + (natp n)) + (<= 8 (ash n 3))) + :hints (("Goal" :in-theory (e/d* (ash) ()))) + :rule-classes :linear) + + (defthm ash-separate-out + (implies (natp n) + (equal (ash (+ 1 n) 3) + (+ 8 (ash n 3)))) + :hints (("Goal" :in-theory (e/d* (ash) ())))))) + + (defthm split-rb-in-app-view + (implies (and (canonical-address-p (+ -1 i j lin-addr)) + (canonical-address-p lin-addr) + (app-view x86) + (natp i) + (natp j)) + (equal (mv-nth 1 (rb (+ i j) lin-addr r-x x86)) + (b* ((low (mv-nth 1 (rb i lin-addr r-x x86))) + (high (mv-nth 1 (rb j (+ i lin-addr) r-x x86)))) + (logior low (ash high (ash i 3)))))) + :hints (("Goal" :in-theory (e/d* (push-ash-inside-logior) + (unsigned-byte-p + force (force)))))) + + (defun-nx split-wb-induction-scheme (i j lin-addr val x86) + (cond ((or (not (natp i)) + (not (natp j)) + (zp (+ i j)) + (zp i) + (not (canonical-address-p lin-addr)) + (not (canonical-address-p (+ -1 i j lin-addr)))) + (mv i j lin-addr val x86)) + (t + (split-wb-induction-scheme (1- i) j (1+ lin-addr) (logtail 8 val) + (mv-nth 1 (wvm08 lin-addr (loghead 8 val) x86)))))) + + (local + (defthm wb-1-1 + (implies (canonical-address-p lin-addr) + (equal (mv-nth 1 (wb-1 1 lin-addr w val x86)) + (mv-nth 1 (wvm08 lin-addr (loghead 8 val) x86)))) + :hints (("Goal" + :expand ((wb-1 1 lin-addr w val x86)) + :in-theory (e/d (wb-1) ()))))) + + (defthm split-wb-in-app-view + (implies (and (canonical-address-p lin-addr) + (canonical-address-p (+ -1 i j lin-addr)) + (unsigned-byte-p (ash (+ i j) 3) val) + (app-view x86) + (posp i) + (natp j)) + (equal (mv-nth 1 (wb-1 (+ i j) lin-addr w val x86)) + (mv-nth 1 (wb-1 j (+ i lin-addr) w + (loghead (ash j 3) (logtail (ash i 3) val)) + (mv-nth 1 (wb-1 i lin-addr w (loghead (ash i 3) val) x86)))))) + :hints (("Goal" + :induct (split-wb-induction-scheme i j lin-addr val x86) + :in-theory (e/d* (push-ash-inside-logior) + (unsigned-byte-p)))))) + +;; ====================================================================== + +;; Defining the 8, 16, 32, 48, and 64, 80, and 128 bit memory +;; read/write functions: + +;; I haven't used physical memory functions like rm-low-* and wm-low-* +;; in the system-level view below because the *-low-* functions take +;; one physical address as input and assume that the values to be read +;; or written are from contiguous physical memory locations. In the +;; functions below, there's no guarantee that the translation of +;; contiguous linear addresses will produce contiguous physical +;; addresses (though, IRL, that's likely the case). That's why there +;; are long and ugly sequences of memi and !memi below instead of nice +;; and pretty wrappers. + +(local + (defthm signed-byte-p-48-to-<-rule + (implies (and (signed-byte-p 48 lin-addr) + (syntaxp (quotep n)) + (natp n)) + (equal (signed-byte-p 48 (+ n lin-addr)) + (< (+ n lin-addr) #.*2^47*))))) + +(local + (defthmd rb-1-in-terms-of-its-components + ;; Ugh, dumb rule. + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ -1 n lin-addr)) + (x86p x86)) + (equal (rb-1 n lin-addr r-x x86) + (list nil + (mv-nth 1 (rb-1 n lin-addr r-x x86)) + x86))) + :hints (("Goal" + :expand ((rb-1 1 #.*2^47-1* r-x x86)) + :in-theory (e/d (rb-1) (force (force))))))) + +(defthmd rb-1-opener-theorem + (implies (canonical-address-p addr) + (equal (rb-1 1 addr r-x x86) + (mv nil (ifix (mv-nth 1 (rvm08 addr x86))) x86))) + :hints (("Goal" :expand ((rb-1 1 addr r-x x86)) + :in-theory (e/d* (rvm08) (force (force)))))) + +(defthmd wb-1-opener-theorem + (implies (canonical-address-p addr) + (equal (wb-1 1 addr w val x86) + (wvm08 addr (loghead 8 val) x86))) + :hints (("Goal" :expand ((wb-1 1 addr w val x86)) + :in-theory (e/d* (wvm08) ())))) + +(local (in-theory (e/d (rb-1-opener-theorem wb-1-opener-theorem) + (signed-byte-p)))) + +(local + (defthm member-equal-r-w-x-lemma + (implies (member-equal r-x '(:r :x)) + (member-equal r-x '(:r :w :x))))) + +(local (in-theory (e/d* () (member-equal)))) + +(local + (defthmd las-to-pas-opener-when-canonical + (implies (and (posp n) + (canonical-address-p lin-addr)) + (equal (las-to-pas n lin-addr r-w-x x86) + (b* (((mv flg p-addr x86) + (ia32e-la-to-pa lin-addr r-w-x x86)) + ((when flg) (mv flg nil x86)) + ((mv flg p-addrs x86) + (las-to-pas (1- n) + (1+ lin-addr) + r-w-x x86))) + (mv flg (if flg nil (cons p-addr p-addrs)) + x86)))))) + +(define rml08 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints (("goal" + :in-theory (e/d* (ifix rvm08) ()))) + + (mbe + :logic + (rb 1 lin-addr r-x x86) + :exec + (if (app-view x86) + (rvm08 lin-addr x86) + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) + (mv flag 0 x86)) + (byte (the (unsigned-byte 8) (memi p-addr x86)))) + (mv nil byte x86)))) + + /// + + (defthm-unsigned-byte-p n08p-mv-nth-1-rml08 + :hyp t + :bound 8 + :concl (mv-nth 1 (rml08 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml08 + (implies (and (<= 8 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml08 lin-addr r-x x86))))) + + (defthm x86p-rml08 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml08 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () (x86p))))) + + (local + (defthm rml08-value-when-error-helper + (implies (and (xr :app-view nil x86) + (mv-nth 0 (rb-1 1 addr r-x x86))) + (equal (mv-nth 1 (rb-1 1 addr r-x x86)) + 0)) + :hints (("Goal" :expand ((rb-1 1 addr r-x x86)))))) + + (defthm rml08-value-when-error + (implies (mv-nth 0 (rml08 addr r-x x86)) + (equal (mv-nth 1 (rml08 addr r-x x86)) 0)) + :hints (("Goal" + :cases ((app-view x86)) + :in-theory (e/d () (force (force)))))) + + (defthm rml08-does-not-affect-state-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml08 start-rip r-x x86)) x86)) + :hints (("Goal" :in-theory (e/d (rvm08) (force (force)))))) + + (defthm app-view-rml08-no-error + (implies (and (app-view x86) + (canonical-address-p addr) + (x86p x86)) + (and (equal (mv-nth 0 (rml08 addr r-x x86)) nil) + (equal (mv-nth 1 (rml08 addr :x x86)) + (memi (loghead 48 addr) x86)) + (equal (mv-nth 2 (rml08 addr r-x x86)) x86))) + :hints (("Goal" :in-theory (e/d (rvm08) (force (force)))))) + + (defthm xr-rml08-state-in-app-view + (implies (app-view x86) + (equal (xr fld index (mv-nth 2 (rml08 addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm xr-rml08-state-in-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb))) + (equal (xr fld index (mv-nth 2 (rml08 addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm rml08-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml08 addr r-x (xw fld index value x86))) + (mv-nth 0 (rml08 addr r-x x86))) + (equal (mv-nth 1 (rml08 addr r-x (xw fld index value x86))) + (mv-nth 1 (rml08 addr r-x x86))) + ;; No need for the conclusion about the state because + ;; "rml08-does-not-affect-state-in-app-view". + )) + :hints (("Goal" :in-theory (e/d* () (rb))))) + + (defthm rml08-xw-system-mode + (implies (and (not (app-view x86)) + (not (equal fld :tlb)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :implicit-supervisor-access))) + (and (equal (mv-nth 0 (rml08 addr r-x (xw fld index value x86))) + (mv-nth 0 (rml08 addr r-x x86))) + (equal (mv-nth 1 (rml08 addr r-x (xw fld index value x86))) + (mv-nth 1 (rml08 addr r-x x86))) + (equal (mv-nth 2 (rml08 addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml08 addr r-x x86))))))) + + (defthm rml08-xw-system-mode-rflags-not-ac + (implies (and (not (app-view x86)) + (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml08 addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml08 addr r-x x86))) + (equal (mv-nth 1 (rml08 addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml08 addr r-x x86))) + (equal (mv-nth 2 (rml08 addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value (mv-nth 2 (rml08 addr r-x x86))))))) + + (defrule 64-bit-modep-of-rml08 + (equal (64-bit-modep (mv-nth 2 (rml08 li-addr r-x x86))) + (64-bit-modep x86)) + :enable 64-bit-modep + :disable (force (force))) + + (defrule x86-operation-mode-of-rml08 + (equal (x86-operation-mode (mv-nth 2 (rml08 li-addr r-x x86))) + (x86-operation-mode x86)) + :enable x86-operation-mode + :disable rml08)) + +(define riml08 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + + (mv-let (flag val x86) + (rml08 lin-addr r-x x86) + (mv flag (n08-to-i08 val) x86)) + /// + + (defthm-signed-byte-p i08p-mv-nth-1-riml08 + :hyp t + :bound 8 + :concl (mv-nth 1 (riml08 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm x86p-riml08 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (riml08 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:rewrite :type-prescription))) + +(define wml08 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 8)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 8 val)) + :split-types t + :guard-hints (("Goal" :in-theory (e/d* (wvm08) ()))) + + (mbe + :logic (wb 1 lin-addr :w val x86) + :exec + (if (app-view x86) + (wvm08 lin-addr val x86) + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) + (mv flag x86)) + (byte (mbe :logic (n08 val) :exec val)) + (x86 (!memi p-addr byte x86))) + (mv nil x86)))) + + /// + + (defthm x86p-wml08 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml08 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p force (force))))) + :rule-classes (:rewrite :type-prescription)) + + (defthm app-view-wml08-no-error + (implies (and (app-view x86) + (canonical-address-p addr)) + (equal (mv-nth 0 (wml08 addr val x86)) nil)) + :hints (("Goal" :in-theory (e/d (wml08 wvm08) ())))) + + (defthm xr-wml08-app-view + (implies (and (app-view x86) + (not (equal fld :mem))) + (equal (xr fld index (mv-nth 1 (wml08 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wvm08) ())))) + + (defthm xr-wml08-sys-view + (implies (and (not (app-view x86)) + (not (equal fld :tlb)) + (not (equal fld :mem)) + (not (equal fld :fault))) + (equal (xr fld index (mv-nth 1 (wml08 addr val x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm wml08-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (wml08 addr val (xw fld index value x86))) + (mv-nth 0 (wml08 addr val x86))) + (equal (mv-nth 1 (wml08 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wml08 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* (wml08 wvm08) ())))) + + (defthm wml08-xw-system-mode + (implies (and (not (app-view x86)) + (not (equal fld :tlb)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :rflags)) + (not (equal fld :msr)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :implicit-supervisor-access))) + (and (equal (mv-nth 0 (wml08 addr val (xw fld index value x86))) + (mv-nth 0 (wml08 addr val x86))) + (equal (mv-nth 1 (wml08 addr val (xw fld index value x86))) + (xw fld index value (mv-nth 1 (wml08 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm wml08-xw-system-mode-rflags-not-ac + (implies (and (not (app-view x86)) + (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86)))) + (and (equal (mv-nth 0 (wml08 addr val (xw :rflags nil value x86))) + (mv-nth 0 (wml08 addr val x86))) + (equal (mv-nth 1 (wml08 addr val (xw :rflags nil value x86))) + (xw :rflags nil value (mv-nth 1 (wml08 addr val x86)))))) + :hints (("Goal" :in-theory (e/d* () (force (force))))))) + +(define wiml08 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (signed-byte 8)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (signed-byte-p 8 val)) + :split-types t + + (wml08 lin-addr (the (unsigned-byte 8) (n08 val)) x86) + /// + (defthm x86p-wiml08 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wiml08 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:rewrite :type-prescription))) + +(local (include-book "centaur/bitops/width-find-rule" :dir :system)) +(local (in-theory (e/d (bitops::unsigned-byte-p-by-find-rule) ()))) + +(define rml16 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints (("Goal" :in-theory (e/d (rb-and-rvm16 rml08) + ()))) + + :prepwork + + ((defthmd rb-and-rvm16 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (1+ lin-addr)) + (x86p x86)) + (equal (rvm16 lin-addr x86) + (rb 2 lin-addr r-x x86))) + :hints (("Goal" + :in-theory (e/d (rml08 rvm08 rvm16) + (force (force))))))) + + (let* ((1+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (1+ (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 1+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 1+lin-addr) + #.*2^47*)) + + (mbe :logic + (rb 2 lin-addr r-x x86) + :exec + (if (app-view x86) + + (rvm16 lin-addr x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (1+lin-addr + (the (signed-byte #.*max-linear-address-size+1*) + (1+ (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) ?p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (the (unsigned-byte 8) (memi p-addr0 x86))) + (byte1 (the (unsigned-byte 8) (memi p-addr1 x86))) + + (word (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte1 8)) + byte0)))) + + (mv nil word x86)))) + + (mv 'rml16 0 x86))) + + /// + + (defthm-unsigned-byte-p n16p-mv-nth-1-rml16 + :hyp t + :bound 16 + :concl (mv-nth 1 (rml16 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml16 + (implies (and (<= 16 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml16 lin-addr r-x x86))))) + + (defthm x86p-rml16 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml16 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (disable x86p unsigned-byte-p signed-byte-p (force)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml16-value-when-error + (implies (mv-nth 0 (rml16 lin-addr r-x x86)) + (equal (mv-nth 1 (rml16 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml16) + (force (force)))))) + + (defthm rml16-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml16 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml16 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml16-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml16 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml16 member-equal) + (force (force)))))) + + (defrule rml16-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml16 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml16 lin-addr r-x x86))) + (equal (mv-nth 1 (rml16 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml16 lin-addr r-x x86))))) + :enable (rml16) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml16-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml16 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml16 lin-addr r-x x86))) + (equal (mv-nth 1 (rml16 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml16 lin-addr r-x x86))) + (equal (mv-nth 2 (rml16 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml16 lin-addr r-x x86)))))) + :enable (rml16 member-equal) + :disable (rb unsigned-byte-p signed-byte-p force (force))) + + (defrule rml16-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml16 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml16 lin-addr r-x x86))) + (equal (mv-nth 1 (rml16 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml16 lin-addr r-x x86))) + (equal (mv-nth 2 (rml16 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml16 lin-addr r-x x86)))))) + :enable (rml16) + :disable (rb unsigned-byte-p signed-byte-p member-equal))) + +(define riml16 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :split-types t + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + + (mv-let (flag val x86) + (rml16 lin-addr r-x x86) + (mv flag (n16-to-i16 val) x86)) + /// + + (defthm-signed-byte-p i16p-mv-nth-1-riml16 + :hyp t + :bound 16 + :concl (mv-nth 1 (riml16 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm signed-byte-p-of-mv-nth-1-of-riml16 + (implies (and (<= 16 size) + (integerp size)) + (signed-byte-p size (mv-nth 1 (riml16 lin-addr r-x x86)))) + :hints (("Goal" :use (i16p-mv-nth-1-riml16) + :in-theory (disable i16p-mv-nth-1-riml16 riml16)))) + + (defthm x86p-riml16 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (riml16 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:rewrite :type-prescription))) + +(define wml16 + ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 16)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 16 val)) + :split-types t + :guard-hints (("Goal" :in-theory (e/d (wb-and-wvm16) ()))) + + :prepwork + + ((defthmd wb-and-wvm16 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (1+ lin-addr))) + (equal (wvm16 lin-addr val x86) + (wb 2 lin-addr :w val x86))) + :hints (("Goal" + :in-theory (e/d (wml08 wvm08 wvm16) + (force (force) unsigned-byte-p)))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((1+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (1+ (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + (if (mbe :logic (canonical-address-p 1+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 1+lin-addr) + #.*2^47*)) + + (mbe + :logic + (wb 2 lin-addr :w val x86) + :exec + (if (app-view x86) + + (wvm16 lin-addr val x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe + :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) (logand #xff val)))) + (byte1 (mbe + :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86))) + (mv nil x86)))) + + (mv 'wml16 x86))) + + (mv 'wml16 x86)) + + /// + + (defthm x86p-wml16 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml16 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p unsigned-byte-p signed-byte-p force (force))))) + :rule-classes (:rewrite :type-prescription))) + +(define wiml16 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (signed-byte 16)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (signed-byte-p 16 val)) + :split-types t + + (wml16 lin-addr (the (unsigned-byte 16) (n16 val)) x86) + /// + (defthm x86p-wiml16 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wiml16 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:rewrite :type-prescription))) + +(define rml32 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints (("Goal" :in-theory (e/d (rb-and-rvm32 rml08) + (rb-1 + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + + ((defthmd rb-and-rvm32 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 3 lin-addr))) + (equal + (rvm32 lin-addr x86) + (rb 4 lin-addr r-x x86))) + :hints (("Goal" + :in-theory (e/d (rml08 rvm08 rvm32) (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((3+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 3 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + (if (mbe :logic (canonical-address-p 3+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 3+lin-addr) + #.*2^47*)) + + (mbe :logic + (rb 4 lin-addr r-x x86) + :exec + (if (app-view x86) + + (rvm32 lin-addr x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (1+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 1 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (2+lin-addr (the (signed-byte #.*max-linear-address-size+2*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (3+lin-addr (the (signed-byte #.*max-linear-address-size+3*) + (+ 3 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (the (unsigned-byte 8) (memi p-addr0 x86))) + (byte1 (the (unsigned-byte 8) (memi p-addr1 x86))) + (byte2 (the (unsigned-byte 8) (memi p-addr2 x86))) + (byte3 (the (unsigned-byte 8) (memi p-addr3 x86))) + ((the (unsigned-byte 16) word1) + (logior byte2 (the (unsigned-byte 16) (ash byte3 8)))) + ((the (unsigned-byte 24) high-24) + (logior byte1 (the (unsigned-byte 24) (ash word1 8)))) + ((the (unsigned-byte 32) dword) + (logior byte0 (the (unsigned-byte 32) (ash high-24 8))))) + + (mv nil dword x86)))) + + (mv 'rml32 0 x86))) + + (mv 'rml32 0 x86)) + + /// + + (defthm-unsigned-byte-p n32p-mv-nth-1-rml32 + :hyp t + :bound 32 + :concl (mv-nth 1 (rml32 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml32 + (implies (and (<= 32 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml32 lin-addr r-x x86))))) + + (defthm x86p-rml32 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml32 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (disable x86p unsigned-byte-p signed-byte-p (force)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml32-value-when-error + (implies (mv-nth 0 (rml32 lin-addr r-x x86)) + (equal (mv-nth 1 (rml32 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml32) + (force (force)))))) + + (defthm rml32-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml32 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml32 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml32-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml32 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml32 member-equal) + (force (force)))))) + + (defrule rml32-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml32 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml32 lin-addr r-x x86))) + (equal (mv-nth 1 (rml32 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml32 lin-addr r-x x86))))) + :enable (rml32) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml32-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml32 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml32 lin-addr r-x x86))) + (equal (mv-nth 1 (rml32 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml32 lin-addr r-x x86))) + (equal (mv-nth 2 (rml32 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml32 lin-addr r-x x86)))))) + :enable (rml32 member-equal) + :disable (rb unsigned-byte-p signed-byte-p force (force))) + + (defrule rml32-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml32 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml32 lin-addr r-x x86))) + (equal (mv-nth 1 (rml32 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml32 lin-addr r-x x86))) + (equal (mv-nth 2 (rml32 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml32 lin-addr r-x x86)))))) + :enable (rml32) + :disable (rb unsigned-byte-p signed-byte-p member-equal))) + +(define riml32 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + + (mv-let (flag val x86) + (rml32 lin-addr r-x x86) + (mv flag (n32-to-i32 val) x86)) + /// + + (defthm-signed-byte-p i32p-mv-nth-1-riml32 + :hyp t + :bound 32 + :concl (mv-nth 1 (riml32 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm signed-byte-p-of-mv-nth-1-of-riml32 + (implies (and (<= 32 size) + (integerp size)) + (signed-byte-p size (mv-nth 1 (riml32 lin-addr r-x x86)))) + :hints (("Goal" :use (i32p-mv-nth-1-riml32) + :in-theory (disable i32p-mv-nth-1-riml32 riml32)))) + + (defthm x86p-riml32 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (riml32 lin-addr r-x x86)))) + :rule-classes (:rewrite :type-prescription))) + +(define wml32 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 32)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 32 val)) + :split-types t + :guard-hints (("Goal" :in-theory (e/d (wb-and-wvm32) + ((:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + + ((defthmd wb-and-wvm32 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 3 lin-addr))) + (equal (wvm32 lin-addr val x86) + (wb 4 lin-addr :w val x86))) + :hints (("Goal" :in-theory (e/d (wml08 wvm08 wvm32) + (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((3+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 3 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 3+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 3+lin-addr) + #.*2^47*)) + + (mbe + :logic + (wb 4 lin-addr :w val x86) + :exec + (if (app-view x86) + (wvm32 lin-addr val x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (2+lin-addr (the (signed-byte #.*max-linear-address-size+2*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (3+lin-addr (the (signed-byte #.*max-linear-address-size+3*) + (+ 3 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe + :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) (logand #xff val)))) + (byte1 (mbe + :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + (byte2 (mbe + :logic (part-select val :low 16 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -16))))) + (byte3 (mbe + :logic (part-select val :low 24 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -24))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86)) + (x86 (!memi p-addr2 byte2 x86)) + (x86 (!memi p-addr3 byte3 x86))) + (mv nil x86)))) + + (mv 'wml32 x86))) + + (mv 'wml32 x86)) + + /// + + (defthm x86p-wml32 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml32 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p force (force))))) + :rule-classes (:rewrite :type-prescription))) + +(define wiml32 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (signed-byte 32)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (signed-byte-p 32 val)) + :split-types t + + (wml32 lin-addr (the (unsigned-byte 32) (n32 val)) x86) + /// + (defthm x86p-wiml32 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wiml32 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:rewrite :type-prescription))) + +(local + (defthm dumb-member-lemma + (implies (and (not (equal r-x :r)) + (not (equal r-x :x))) + (not (member-equal r-x '(:r :x)))))) +(local (in-theory (e/d () ((:rewrite acl2::member-eql-exec-is-member-equal) + (:rewrite acl2::member-of-cons) + (:rewrite acl2::member-when-atom))))) + + +(define rml48 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints (("Goal" + :in-theory (e/d (rb-and-rvm48 + las-to-pas-opener-when-canonical + push-ash-inside-logior) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + ((local + (defthmd rb-and-rvm48-helper + (implies + (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 5 lin-addr))) + (equal (rvm48 lin-addr x86) + (list nil + (logior + (mv-nth 1 (rb 2 lin-addr r-x x86)) + (ash (mv-nth 1 (rb 4 (+ 2 lin-addr) r-x x86)) 16)) + x86))) + :hints (("Goal" :use ((:instance rb-and-rvm16) + (:instance rb-and-rvm32 (lin-addr (+ 2 lin-addr)))) + :in-theory (e/d (rvm48) + (force (force))))))) + + + (defthmd rb-and-rvm48 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 5 lin-addr))) + (equal (rvm48 lin-addr x86) + (rb 6 lin-addr r-x x86))) + :hints (("Goal" + :in-theory (e/d (rb-and-rvm48-helper + push-ash-inside-logior) + (signed-byte-p + force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((5+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 5 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 5+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 5+lin-addr) + #.*2^47*)) + + (mbe :logic + (rb 6 lin-addr r-x x86) + :exec + (if (app-view x86) + + (rvm48 lin-addr x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (memi p-addr0 x86)) + (byte1 (memi p-addr1 x86)) + (byte2 (memi p-addr2 x86)) + (byte3 (memi p-addr3 x86)) + (byte4 (memi p-addr4 x86)) + (byte5 (memi p-addr5 x86)) + + (word0 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte1 8)) + byte0))) + (word1 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte3 8)) + byte2))) + (word2 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte5 8)) + byte4))) + (dword1 (the (unsigned-byte 32) + (logior (the (unsigned-byte 32) (ash word2 16)) + word1))) + (value (the (unsigned-byte 48) + (logior (the (unsigned-byte 48) (ash dword1 16)) + word0)))) + + (mv nil value x86)))) + + (mv 'rml48 0 x86))) + + (mv 'rml48 0 x86)) + + /// + + (defthm-unsigned-byte-p n48p-mv-nth-1-rml48 + :hyp t + :bound 48 + :concl (mv-nth 1 (rml48 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :otf-flg t + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml48 + (implies (and (<= 48 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml48 lin-addr r-x x86))))) + + (defthm x86p-rml48 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml48 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () ((force) unsigned-byte-p signed-byte-p)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml48-value-when-error + (implies (mv-nth 0 (rml48 lin-addr r-x x86)) + (equal (mv-nth 1 (rml48 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml48) + (force (force)))))) + + (defthm rml48-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml48 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml48 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml48-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml48 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml48 member-equal) + (force (force)))))) + + (defrule rml48-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml48 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml48 lin-addr r-x x86))) + (equal (mv-nth 1 (rml48 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml48 lin-addr r-x x86))))) + :enable (rml48) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml48-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml48 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml48 lin-addr r-x x86))) + (equal (mv-nth 1 (rml48 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml48 lin-addr r-x x86))) + (equal (mv-nth 2 (rml48 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml48 lin-addr r-x x86)))))) + :enable (rml48 member-equal) + :disable (rb unsigned-byte-p signed-byte-p force (force))) + + (defrule rml48-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml48 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml48 lin-addr r-x x86))) + (equal (mv-nth 1 (rml48 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml48 lin-addr r-x x86))) + (equal (mv-nth 2 (rml48 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml48 lin-addr r-x x86)))))) + :enable (rml48) + :disable (rb unsigned-byte-p signed-byte-p member-equal))) + +(define wml48 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 48)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 48 val)) + :split-types t + :guard-hints (("Goal" + :in-theory (e/d (wb-and-wvm48 + las-to-pas-opener-when-canonical) + ((:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + + ((defthmd wb-and-wvm48 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 5 lin-addr))) + (equal (wvm48 lin-addr val x86) + (wb 6 lin-addr :w val x86))) + :hints (("Goal" :in-theory (e/d (wml08 wvm08 wvm16 wvm32 wvm48) + (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((5+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 5 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 5+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 5+lin-addr) + #.*2^47*)) + + (mbe + :logic + (wb 6 lin-addr :w val x86) + :exec + (if (app-view x86) + + (wvm48 lin-addr val x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (2+lin-addr (the (signed-byte #.*max-linear-address-size+2*) + (+ 2 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (3+lin-addr (the (signed-byte #.*max-linear-address-size+3*) + (+ 3 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (4+lin-addr (the (signed-byte #.*max-linear-address-size+4*) + (+ 4 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (5+lin-addr (the (signed-byte #.*max-linear-address-size+5*) + (+ 5 (the (signed-byte #.*max-linear-address-size*) + lin-addr)))) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe + :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) (logand #xff val)))) + (byte1 (mbe + :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + (byte2 (mbe + :logic (part-select val :low 16 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -16))))) + (byte3 (mbe + :logic (part-select val :low 24 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -24))))) + (byte4 (mbe + :logic (part-select val :low 32 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -32))))) + (byte5 (mbe + :logic (part-select val :low 40 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -40))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86)) + (x86 (!memi p-addr2 byte2 x86)) + (x86 (!memi p-addr3 byte3 x86)) + (x86 (!memi p-addr4 byte4 x86)) + (x86 (!memi p-addr5 byte5 x86))) + (mv nil x86)))) + + (mv 'wml48 x86))) + + (mv 'wml48 x86)) + + /// + + (defthm x86p-wml48 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml48 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p force (force))))) + :rule-classes (:rewrite :type-prescription))) + +(define rml64 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints + (("Goal" + :in-theory (e/d (rb-and-rvm64 + las-to-pas-opener-when-canonical + push-ash-inside-logior) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + ( + (local + (defthmd rb-and-rvm64-helper-1 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 7 lin-addr))) + (equal (rvm64 lin-addr x86) + (list nil + (logior (mv-nth 1 (rb-1 4 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 4 (+ 4 lin-addr) r-x x86)) + 32)) + x86))) + :hints (("Goal" :use ((:instance rb-and-rvm32) + (:instance rb-and-rvm32 (lin-addr (+ 4 lin-addr)))) + :in-theory (e/d (rvm64) + (force (force))))))) + + + (local + (defthmd rb-and-rvm64-helper-2 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 7 lin-addr))) + (equal + (logior (mv-nth 1 (rb-1 4 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 4 (+ 4 lin-addr) r-x x86)) + 32)) + (mv-nth 1 (rb-1 8 lin-addr r-x x86)))) + :hints (("Goal" + :use ((:instance split-rb-in-app-view + (i 4) + (j 4))) + :in-theory (e/d () (force (force))))))) + + (defthmd rb-and-rvm64 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 7 lin-addr))) + (equal (rvm64 lin-addr x86) + (rb 8 lin-addr r-x x86))) + :hints (("Goal" + :use ((:instance rb-1-in-terms-of-its-components + (n 8))) + :in-theory (e/d (rb-and-rvm64-helper-1 + rb-and-rvm64-helper-2) + (signed-byte-p + force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((7+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 7 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 7+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 7+lin-addr) + #.*2^47*)) + + (mbe :logic + (rb 8 lin-addr r-x x86) + + :exec + (if (app-view x86) + + (rvm64 lin-addr x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (memi p-addr0 x86)) + (byte1 (memi p-addr1 x86)) + (byte2 (memi p-addr2 x86)) + (byte3 (memi p-addr3 x86)) + (byte4 (memi p-addr4 x86)) + (byte5 (memi p-addr5 x86)) + (byte6 (memi p-addr6 x86)) + (byte7 (memi p-addr7 x86)) + + (word0 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte1 8)) + byte0))) + (word1 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte3 8)) + byte2))) + (dword0 (the (unsigned-byte 32) + (logior (the (unsigned-byte 32) (ash word1 16)) + word0))) + (word2 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte5 8)) + byte4))) + (word3 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte7 8)) + byte6))) + (dword1 (the (unsigned-byte 32) + (logior (the (unsigned-byte 32) (ash word3 16)) + word2))) + (qword (the (unsigned-byte 64) + (logior (the (unsigned-byte 64) (ash dword1 32)) + dword0)))) + + (mv nil qword x86)))) + + (mv 'rml64 0 x86))) + + (mv 'rml64 0 x86)) + + /// + + (defthm-unsigned-byte-p n64p-mv-nth-1-rml64 + :hyp t + :bound 64 + :concl (mv-nth 1 (rml64 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :otf-flg t + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml64 + (implies (and (<= 64 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml64 lin-addr r-x x86))))) + + (defthm x86p-rml64 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml64 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () ((force) unsigned-byte-p signed-byte-p)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml64-value-when-error + (implies (mv-nth 0 (rml64 lin-addr r-x x86)) + (equal (mv-nth 1 (rml64 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml64) + (force (force)))))) + + (defthm rml64-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml64 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml64 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml64-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml64 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml64 member-equal) + (force (force)))))) + + (defrule rml64-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml64 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml64 lin-addr r-x x86))) + (equal (mv-nth 1 (rml64 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml64 lin-addr r-x x86))))) + :enable (rml64) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml64-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml64 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml64 lin-addr r-x x86))) + (equal (mv-nth 1 (rml64 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml64 lin-addr r-x x86))) + (equal (mv-nth 2 (rml64 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml64 lin-addr r-x x86)))))) + :enable (rml64 member-equal) + :disable (rb unsigned-byte-p signed-byte-p force (force))) + + (defrule rml64-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml64 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml64 lin-addr r-x x86))) + (equal (mv-nth 1 (rml64 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml64 lin-addr r-x x86))) + (equal (mv-nth 2 (rml64 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml64 lin-addr r-x x86)))))) + :enable (rml64) + :disable (rb unsigned-byte-p signed-byte-p member-equal))) + +(define riml64 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + + (mv-let (flag val x86) + (rml64 lin-addr r-x x86) + (mv flag (n64-to-i64 val) x86)) + /// + + (defthm-signed-byte-p i64p-mv-nth-1-riml64 + :hyp t + :bound 64 + :concl (mv-nth 1 (riml64 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (signed-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm x86p-riml64 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (riml64 lin-addr r-x x86)))) + :rule-classes (:rewrite :type-prescription))) + +(define wml64 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 64)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 64 val)) + :split-types t + + :guard-hints + (("Goal" + :in-theory (e/d (wb-and-wvm64 las-to-pas-opener-when-canonical) + ((:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + + ((defthmd wb-and-wvm64 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 7 lin-addr))) + (equal (wvm64 lin-addr val x86) + (wb 8 lin-addr :w val x86))) + :hints (("Goal" :in-theory (e/d (wml08 wvm08 wvm32 wvm64) + (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((7+lin-addr (the (signed-byte #.*max-linear-address-size+2*) + (+ 7 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 7+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 7+lin-addr) + #.*2^47*)) + + (mbe + :logic + (wb 8 lin-addr :w val x86) + :exec + (if (app-view x86) + + (wvm64 lin-addr val x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff val)))) + (byte1 (mbe :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + (byte2 (mbe :logic (part-select val :low 16 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -16))))) + (byte3 (mbe :logic (part-select val :low 24 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -24))))) + (byte4 (mbe :logic (part-select val :low 32 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -32))))) + (byte5 (mbe :logic (part-select val :low 40 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -40))))) + (byte6 (mbe :logic (part-select val :low 48 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -48))))) + (byte7 (mbe :logic (part-select val :low 56 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -56))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86)) + (x86 (!memi p-addr2 byte2 x86)) + (x86 (!memi p-addr3 byte3 x86)) + (x86 (!memi p-addr4 byte4 x86)) + (x86 (!memi p-addr5 byte5 x86)) + (x86 (!memi p-addr6 byte6 x86)) + (x86 (!memi p-addr7 byte7 x86))) + + (mv nil x86)))) + + (mv 'wml64 x86))) + + (mv 'wml64 x86)) + + /// + + (defthm x86p-wml64 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml64 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p force (force) unsigned-byte-p signed-byte-p)))) + :rule-classes (:rewrite :type-prescription))) + +(define wiml64 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (signed-byte 64)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (signed-byte-p 64 val)) + :split-types t + + (wml64 lin-addr (the (unsigned-byte 64) (n64 val)) x86) + /// + (defthm x86p-wiml64 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wiml64 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:rewrite :type-prescription))) + +(define rml80 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints + (("Goal" + :in-theory (e/d (rb-and-rvm80 + las-to-pas-opener-when-canonical + push-ash-inside-logior) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + ((defthmd rb-and-rvm80 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 9 lin-addr))) + (equal (rvm80 lin-addr x86) + (rb 10 lin-addr r-x x86))) + :hints (("Goal" + :in-theory (e/d (rvm80 rb-and-rvm16 rb-and-rvm64 push-ash-inside-logior) + (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((9+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 9 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + (if (mbe :logic (canonical-address-p 9+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 9+lin-addr) + #.*2^47*)) + + (mbe :logic + (rb 10 lin-addr r-x x86) + + :exec + (if (app-view x86) + + (rvm80 lin-addr x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (memi p-addr0 x86)) + (byte1 (memi p-addr1 x86)) + (byte2 (memi p-addr2 x86)) + (byte3 (memi p-addr3 x86)) + (byte4 (memi p-addr4 x86)) + (byte5 (memi p-addr5 x86)) + (byte6 (memi p-addr6 x86)) + (byte7 (memi p-addr7 x86)) + (byte8 (memi p-addr8 x86)) + (byte9 (memi p-addr9 x86)) + + (word0 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte1 8)) + byte0))) + (word1 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte3 8)) + byte2))) + (word2 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte5 8)) + byte4))) + (dword0 (the (unsigned-byte 32) + (logior (the (unsigned-byte 32) (ash word2 16)) + word1))) + (word3 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte7 8)) + byte6))) + (word4 (the (unsigned-byte 16) + (logior (the (unsigned-byte 16) (ash byte9 8)) + byte8))) + (dword1 (the (unsigned-byte 32) + (logior (the (unsigned-byte 32) (ash word4 16)) + word3))) + (qword (the (unsigned-byte 64) + (logior (the (unsigned-byte 64) (ash dword1 32)) + dword0))) + (value + (the (unsigned-byte 80) + (logior (the (unsigned-byte 80) (ash qword 16)) + word0)))) + + (mv nil value x86)))) + + (mv 'rml80 0 x86))) + + (mv 'rml80 0 x86)) + + /// + + (defthm-unsigned-byte-p n80p-mv-nth-1-rml80 + :hyp t + :bound 80 + :concl (mv-nth 1 (rml80 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d (rb) (signed-byte-p)))) + :otf-flg t + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml80 + (implies (and (<= 80 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml80 lin-addr r-x x86))))) + + (defthm x86p-rml80 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml80 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () (rb unsigned-byte-p signed-byte-p (force))))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml80-value-when-error + (implies (mv-nth 0 (rml80 lin-addr r-x x86)) + (equal (mv-nth 1 (rml80 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml80) + (force (force)))))) + + (defthm rml80-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml80 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml80 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml80-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml80 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml80 member-equal) + (force (force)))))) + + (defrule rml80-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml80 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml80 lin-addr r-x x86))) + (equal (mv-nth 1 (rml80 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml80 lin-addr r-x x86))))) + :enable (rml80) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml80-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml80 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml80 lin-addr r-x x86))) + (equal (mv-nth 1 (rml80 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml80 lin-addr r-x x86))) + (equal (mv-nth 2 (rml80 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml80 lin-addr r-x x86)))))) + :enable (rml80 member-equal) + :disable (rb unsigned-byte-p signed-byte-p force (force))) + + (defrule rml80-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml80 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml80 lin-addr r-x x86))) + (equal (mv-nth 1 (rml80 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml80 lin-addr r-x x86))) + (equal (mv-nth 2 (rml80 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml80 lin-addr r-x x86)))))) + :enable (rml80) + :disable (rb unsigned-byte-p signed-byte-p member-equal))) + +(define wml80 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 80)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 80 val)) + :split-types t + :guard-hints + (("Goal" + :in-theory (e/d (wb-and-wvm80 las-to-pas-opener-when-canonical) + ((:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + + ((defthmd wb-and-wvm80 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 9 lin-addr))) + (equal (wvm80 lin-addr val x86) + (wb 10 lin-addr :w val x86))) + :hints (("Goal" :in-theory (e/d (wml08 wvm08 wvm16 wvm32 wvm64 wvm80) + (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((9+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 9 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 9+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 9+lin-addr) + #.*2^47*)) + + (mbe + :logic + (wb 10 lin-addr :w val x86) + + :exec + (if (app-view x86) + + (wvm80 lin-addr val x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff val)))) + (byte1 (mbe :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + (byte2 (mbe :logic (part-select val :low 16 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -16))))) + (byte3 (mbe :logic (part-select val :low 24 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -24))))) + (byte4 (mbe :logic (part-select val :low 32 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -32))))) + (byte5 (mbe :logic (part-select val :low 40 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -40))))) + (byte6 (mbe :logic (part-select val :low 48 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -48))))) + (byte7 (mbe :logic (part-select val :low 56 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -56))))) + (byte8 (mbe :logic (part-select val :low 64 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -64))))) + (byte9 (mbe :logic (part-select val :low 72 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -72))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86)) + (x86 (!memi p-addr2 byte2 x86)) + (x86 (!memi p-addr3 byte3 x86)) + (x86 (!memi p-addr4 byte4 x86)) + (x86 (!memi p-addr5 byte5 x86)) + (x86 (!memi p-addr6 byte6 x86)) + (x86 (!memi p-addr7 byte7 x86)) + (x86 (!memi p-addr8 byte8 x86)) + (x86 (!memi p-addr9 byte9 x86))) + + (mv nil x86)))) + + (mv 'wml80 x86))) + + (mv 'wml80 x86)) + + /// + + (defthm x86p-wml80 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml80 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (x86p rb force (force) unsigned-byte-p signed-byte-p)))) + :rule-classes (:rewrite :type-prescription))) + +; Thanks to Dmitry Nadezhin for proving the equivalence of rm/wml128 +; to rb/wb. + +(define rml128 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints (("Goal" + :in-theory (e/d (las-to-pas-opener-when-canonical + rb-and-rvm128 + bitops::merge-16-u8s + logapp-is-logapp-inline) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + ((local + (defthmd rb-and-rvm128-helper-1 + (implies + (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 15 lin-addr))) + (equal (rvm128 lin-addr x86) + (list + nil + (logior (mv-nth 1 (rb-1 8 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 8 (+ 8 lin-addr) r-x x86)) + 64)) + x86))) + :hints (("Goal" :in-theory (e/d (rvm128 rb-and-rvm64) + (force (force))))))) + + (local + (defthmd rb-and-rvm128-helper-2 + (implies + (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 15 lin-addr))) + (equal + (logior (mv-nth 1 (rb-1 8 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 8 (+ 8 lin-addr) r-x x86)) 64)) + (mv-nth 1 (rb-1 16 lin-addr r-x x86)))) + :hints (("Goal" + :in-theory (e/d () (force (force))) + :use + ((:instance split-rb-in-app-view + (i 8) (j 8))))))) + + (defthmd rb-and-rvm128 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 15 lin-addr))) + (equal (rvm128 lin-addr x86) + (rb 16 lin-addr r-x x86))) + :hints (("Goal" + :use ((:instance rb-1-in-terms-of-its-components + (n 16))) + :in-theory (e/d (rb-and-rvm128-helper-1 + rb-and-rvm128-helper-2) + (force (force)))))) + + (defthm-unsigned-byte-p unsigned-byte-p-128-of-merge-16-u8s-linear + :hyp (and (unsigned-byte-p 8 h7) + (unsigned-byte-p 8 h6) + (unsigned-byte-p 8 h5) + (unsigned-byte-p 8 h4) + (unsigned-byte-p 8 h3) + (unsigned-byte-p 8 h2) + (unsigned-byte-p 8 h1) + (unsigned-byte-p 8 h0) + (unsigned-byte-p 8 l7) + (unsigned-byte-p 8 l6) + (unsigned-byte-p 8 l5) + (unsigned-byte-p 8 l4) + (unsigned-byte-p 8 l3) + (unsigned-byte-p 8 l2) + (unsigned-byte-p 8 l1) + (unsigned-byte-p 8 l0)) + :bound 128 + :concl (bitops::merge-16-u8s h7 h6 h5 h4 h3 h2 h1 h0 l7 l6 l5 l4 l3 l2 l1 l0) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-linear t)) + + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((15+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 15 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 15+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 15+lin-addr) + #.*2^47*)) + + (mbe :logic + (rb 16 lin-addr r-x x86) + :exec + (if (app-view x86) + + (rvm128 lin-addr x86) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+10*) 10+lin-addr) + (+ 10 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr10) x86) + (la-to-pa 10+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+11*) 11+lin-addr) + (+ 11 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr11) x86) + (la-to-pa 11+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+12*) 12+lin-addr) + (+ 12 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr12) x86) + (la-to-pa 12+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+13*) 13+lin-addr) + (+ 13 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr13) x86) + (la-to-pa 13+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+14*) 14+lin-addr) + (+ 14 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr14) x86) + (la-to-pa 14+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 15+lin-addr) + (+ 15 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr15) x86) + (la-to-pa 15+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (memi p-addr0 x86)) + (byte1 (memi p-addr1 x86)) + (byte2 (memi p-addr2 x86)) + (byte3 (memi p-addr3 x86)) + (byte4 (memi p-addr4 x86)) + (byte5 (memi p-addr5 x86)) + (byte6 (memi p-addr6 x86)) + (byte7 (memi p-addr7 x86)) + (byte8 (memi p-addr8 x86)) + (byte9 (memi p-addr9 x86)) + (byte10 (memi p-addr10 x86)) + (byte11 (memi p-addr11 x86)) + (byte12 (memi p-addr12 x86)) + (byte13 (memi p-addr13 x86)) + (byte14 (memi p-addr14 x86)) + (byte15 (memi p-addr15 x86)) + + (oword + (the (unsigned-byte 128) + (bitops::merge-16-u8s + byte15 byte14 byte13 byte12 + byte11 byte10 byte9 byte8 + byte7 byte6 byte5 byte4 + byte3 byte2 byte1 byte0)))) + + (mv nil oword x86)))) + + (mv 'rml128 0 x86))) + + (mv 'rml128 0 x86)) + + /// + + (defthm-unsigned-byte-p n128p-mv-nth-1-rml128 + :hyp t + :bound 128 + :concl (mv-nth 1 (rml128 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (force (force) signed-byte-p)))) + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml128 + (implies (and (<= 128 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml128 lin-addr r-x x86))))) + + (defthm x86p-rml128 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml128 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () ((force) unsigned-byte-p signed-byte-p)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml128-value-when-error + (implies (mv-nth 0 (rml128 lin-addr r-x x86)) + (equal (mv-nth 1 (rml128 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml128) + (force (force)))))) + + (defthm rml128-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml128 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml128 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml128-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml128 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml128) + (force (force)))))) + + (defrule rml128-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml128 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml128 lin-addr r-x x86))) + (equal (mv-nth 1 (rml128 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml128 lin-addr r-x x86))))) + :enable (rml128) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml128-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml128 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml128 lin-addr r-x x86))) + (equal (mv-nth 1 (rml128 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml128 lin-addr r-x x86))) + (equal (mv-nth 2 (rml128 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml128 lin-addr r-x x86)))))) + :enable (rml128) + :disable (rb unsigned-byte-p signed-byte-p force (force) + ;; for speed: + signed-byte-p-48-to-<-rule)) + + (defrule rml128-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml128 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml128 lin-addr r-x x86))) + (equal (mv-nth 1 (rml128 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml128 lin-addr r-x x86))) + (equal (mv-nth 2 (rml128 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml128 lin-addr r-x x86)))))) + :enable (rml128) + :disable (rb unsigned-byte-p signed-byte-p member-equal + ;; for speed: + signed-byte-p-48-to-<-rule))) + +;; TODO: Prove wml128 equivalent to rb in the system-level view (again). +(define wml128 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 128)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 128 val)) + :split-types t + :guard-hints + (("Goal" :in-theory (e/d (wb-and-wvm128) + (wvm128 + not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + ((defthmd wb-and-wvm128 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 15 lin-addr))) + (equal (wvm128 lin-addr val x86) + (wb 16 lin-addr :w val x86))) + :hints (("Goal" :in-theory (e/d (wml08 wvm08 wvm32 wvm64 wvm128) + (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((15+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 15 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 15+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 15+lin-addr) + #.*2^47*)) + + (if (app-view x86) + + (mbe :logic (wb 16 lin-addr :w val x86) + :exec (wvm128 lin-addr val x86)) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+10*) 10+lin-addr) + (+ 10 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr10) x86) + (la-to-pa 10+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+11*) 11+lin-addr) + (+ 11 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr11) x86) + (la-to-pa 11+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+12*) 12+lin-addr) + (+ 12 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr12) x86) + (la-to-pa 12+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+13*) 13+lin-addr) + (+ 13 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr13) x86) + (la-to-pa 13+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+14*) 14+lin-addr) + (+ 14 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr14) x86) + (la-to-pa 14+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 15+lin-addr) + (+ 15 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr15) x86) + (la-to-pa 15+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff val)))) + (byte1 (mbe :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + (byte2 (mbe :logic (part-select val :low 16 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -16))))) + (byte3 (mbe :logic (part-select val :low 24 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -24))))) + (byte4 (mbe :logic (part-select val :low 32 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -32))))) + (byte5 (mbe :logic (part-select val :low 40 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -40))))) + (byte6 (mbe :logic (part-select val :low 48 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -48))))) + (byte7 (mbe :logic (part-select val :low 56 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -56))))) + (byte8 (mbe :logic (part-select val :low 64 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -64))))) + (byte9 (mbe :logic (part-select val :low 72 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -72))))) + (byte10 (mbe :logic (part-select val :low 80 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -80))))) + (byte11 (mbe :logic (part-select val :low 88 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -88))))) + (byte12 (mbe :logic (part-select val :low 96 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -96))))) + (byte13 (mbe :logic (part-select val :low 104 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -104))))) + (byte14 (mbe :logic (part-select val :low 112 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -112))))) + (byte15 (mbe :logic (part-select val :low 120 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -120))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86)) + (x86 (!memi p-addr2 byte2 x86)) + (x86 (!memi p-addr3 byte3 x86)) + (x86 (!memi p-addr4 byte4 x86)) + (x86 (!memi p-addr5 byte5 x86)) + (x86 (!memi p-addr6 byte6 x86)) + (x86 (!memi p-addr7 byte7 x86)) + (x86 (!memi p-addr8 byte8 x86)) + (x86 (!memi p-addr9 byte9 x86)) + (x86 (!memi p-addr10 byte10 x86)) + (x86 (!memi p-addr11 byte11 x86)) + (x86 (!memi p-addr12 byte12 x86)) + (x86 (!memi p-addr13 byte13 x86)) + (x86 (!memi p-addr14 byte14 x86)) + (x86 (!memi p-addr15 byte15 x86))) + + (mv nil x86))) + + + (mv 'wml128 x86))) + + (mv 'wml128 x86)) + + /// + + (defthm x86p-wml128 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml128 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (rb x86p force (force) unsigned-byte-p signed-byte-p)))) + :rule-classes (:rewrite :type-prescription))) + +;; TODO: Prove rml256 equivalent to rb in the system-level view. (again) +(define rml256 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints (("Goal" + :in-theory (e/d (rb-and-rvm256) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + ((local + (defthmd rb-and-rvm256-helper-1 + (implies + (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 31 lin-addr))) + (equal (rvm256 lin-addr x86) + (list + nil + (logior (mv-nth 1 (rb-1 16 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 16 (+ 16 lin-addr) r-x x86)) + 128)) + x86))) + :hints (("Goal" :in-theory (e/d (rvm256 rb-and-rvm128) + (force (force))))))) + + (local + (defthmd rb-and-rvm256-helper-2 + (implies + (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 31 lin-addr))) + (equal + (logior (mv-nth 1 (rb-1 16 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 16 (+ 16 lin-addr) r-x x86)) 128)) + (mv-nth 1 (rb-1 32 lin-addr r-x x86)))) + :hints (("Goal" + :in-theory (e/d () (force (force))) + :use + ((:instance split-rb-in-app-view + (i 16) (j 16))))))) + + (defthmd rb-and-rvm256 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 31 lin-addr))) + (equal (rvm256 lin-addr x86) + (rb 32 lin-addr r-x x86))) + :hints (("Goal" + :use ((:instance rb-1-in-terms-of-its-components + (n 32))) + :in-theory (e/d (rb-and-rvm256-helper-1 + rb-and-rvm256-helper-2) + (force (force)))))) + + (defthm-unsigned-byte-p unsigned-byte-p-256-of-merge-32-u8s-linear + :hyp (and (unsigned-byte-p 8 h15) + (unsigned-byte-p 8 h14) + (unsigned-byte-p 8 h13) + (unsigned-byte-p 8 h12) + (unsigned-byte-p 8 h11) + (unsigned-byte-p 8 h10) + (unsigned-byte-p 8 h9) + (unsigned-byte-p 8 h8) + (unsigned-byte-p 8 h7) + (unsigned-byte-p 8 h6) + (unsigned-byte-p 8 h5) + (unsigned-byte-p 8 h4) + (unsigned-byte-p 8 h3) + (unsigned-byte-p 8 h2) + (unsigned-byte-p 8 h1) + (unsigned-byte-p 8 h0) + (unsigned-byte-p 8 l15) + (unsigned-byte-p 8 l14) + (unsigned-byte-p 8 l13) + (unsigned-byte-p 8 l12) + (unsigned-byte-p 8 l11) + (unsigned-byte-p 8 l10) + (unsigned-byte-p 8 l9) + (unsigned-byte-p 8 l8) + (unsigned-byte-p 8 l7) + (unsigned-byte-p 8 l6) + (unsigned-byte-p 8 l5) + (unsigned-byte-p 8 l4) + (unsigned-byte-p 8 l3) + (unsigned-byte-p 8 l2) + (unsigned-byte-p 8 l1) + (unsigned-byte-p 8 l0)) + :bound 256 + :concl (bitops::merge-32-u8s h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0 + l15 l14 l13 l12 l11 l10 l9 l8 l7 l6 l5 l4 l3 l2 l1 l0) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :gen-linear t)) + + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((31+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 31 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 31+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 31+lin-addr) + #.*2^47*)) + + (if (app-view x86) + (mbe :logic (rb 32 lin-addr r-x x86) + :exec (rvm256 lin-addr x86)) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+10*) 10+lin-addr) + (+ 10 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr10) x86) + (la-to-pa 10+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+11*) 11+lin-addr) + (+ 11 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr11) x86) + (la-to-pa 11+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+12*) 12+lin-addr) + (+ 12 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr12) x86) + (la-to-pa 12+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+13*) 13+lin-addr) + (+ 13 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr13) x86) + (la-to-pa 13+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+14*) 14+lin-addr) + (+ 14 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr14) x86) + (la-to-pa 14+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 15+lin-addr) + (+ 15 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr15) x86) + (la-to-pa 15+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 16+lin-addr) + (+ 16 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr16) x86) + (la-to-pa 16+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+17*) 17+lin-addr) + (+ 17 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr17) x86) + (la-to-pa 17+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+18*) 18+lin-addr) + (+ 18 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr18) x86) + (la-to-pa 18+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+19*) 19+lin-addr) + (+ 19 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr19) x86) + (la-to-pa 19+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+20*) 20+lin-addr) + (+ 20 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr20) x86) + (la-to-pa 20+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+21*) 21+lin-addr) + (+ 21 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr21) x86) + (la-to-pa 21+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+22*) 22+lin-addr) + (+ 22 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr22) x86) + (la-to-pa 22+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+23*) 23+lin-addr) + (+ 23 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr23) x86) + (la-to-pa 23+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+24*) 24+lin-addr) + (+ 24 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr24) x86) + (la-to-pa 24+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+25*) 25+lin-addr) + (+ 25 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr25) x86) + (la-to-pa 25+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+26*) 26+lin-addr) + (+ 26 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr26) x86) + (la-to-pa 26+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+27*) 27+lin-addr) + (+ 27 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr27) x86) + (la-to-pa 27+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+28*) 28+lin-addr) + (+ 28 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr28) x86) + (la-to-pa 28+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+29*) 29+lin-addr) + (+ 29 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr29) x86) + (la-to-pa 29+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+30*) 30+lin-addr) + (+ 30 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr30) x86) + (la-to-pa 30+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+31*) 31+lin-addr) + (+ 31 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr31) x86) + (la-to-pa 31+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (memi p-addr0 x86)) + (byte1 (memi p-addr1 x86)) + (byte2 (memi p-addr2 x86)) + (byte3 (memi p-addr3 x86)) + (byte4 (memi p-addr4 x86)) + (byte5 (memi p-addr5 x86)) + (byte6 (memi p-addr6 x86)) + (byte7 (memi p-addr7 x86)) + (byte8 (memi p-addr8 x86)) + (byte9 (memi p-addr9 x86)) + (byte10 (memi p-addr10 x86)) + (byte11 (memi p-addr11 x86)) + (byte12 (memi p-addr12 x86)) + (byte13 (memi p-addr13 x86)) + (byte14 (memi p-addr14 x86)) + (byte15 (memi p-addr15 x86)) + + (byte16 (memi p-addr16 x86)) + (byte17 (memi p-addr17 x86)) + (byte18 (memi p-addr18 x86)) + (byte19 (memi p-addr19 x86)) + (byte20 (memi p-addr20 x86)) + (byte21 (memi p-addr21 x86)) + (byte22 (memi p-addr22 x86)) + (byte23 (memi p-addr23 x86)) + (byte24 (memi p-addr24 x86)) + (byte25 (memi p-addr25 x86)) + (byte26 (memi p-addr26 x86)) + (byte27 (memi p-addr27 x86)) + (byte28 (memi p-addr28 x86)) + (byte29 (memi p-addr29 x86)) + (byte30 (memi p-addr30 x86)) + (byte31 (memi p-addr31 x86)) + + (xword + (the (unsigned-byte 256) + (bitops::merge-32-u8s + byte31 byte30 byte29 byte28 + byte27 byte26 byte25 byte24 + byte23 byte22 byte21 byte20 + byte19 byte18 byte17 byte16 + byte15 byte14 byte13 byte12 + byte11 byte10 byte9 byte8 + byte7 byte6 byte5 byte4 + byte3 byte2 byte1 byte0)))) + + (mv nil xword x86))) + + (mv 'rml256 0 x86))) + + (mv 'rml256 0 x86)) + + /// + + (defthm-unsigned-byte-p n256p-mv-nth-1-rml256 + :hyp t + :bound 256 + :concl (mv-nth 1 (rml256 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (force (force) signed-byte-p + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule + x86isa::la-to-pa$inline)))) + :gen-linear t + :gen-type t) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml256 + (implies (and (<= 256 size) + (integerp size)) + (unsigned-byte-p size (mv-nth 1 (rml256 lin-addr r-x x86))))) + + (defthm x86p-rml256 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml256 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () ((force) unsigned-byte-p signed-byte-p + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml256-value-when-error + (implies (mv-nth 0 (rml256 lin-addr r-x x86)) + (equal (mv-nth 1 (rml256 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml256) + (force + (force) + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule + x86isa::la-to-pa$inline))))) + + (defthm rml256-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml256 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml256 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml256-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml256 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml256) + (force + (force) + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule))))) + + (defrule rml256-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml256 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml256 lin-addr r-x x86))) + (equal (mv-nth 1 (rml256 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml256 lin-addr r-x x86))))) + :enable (rml256) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml256-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml256 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml256 lin-addr r-x x86))) + (equal (mv-nth 1 (rml256 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml256 lin-addr r-x x86))) + (equal (mv-nth 2 (rml256 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml256 lin-addr r-x x86)))))) + :enable (rml256) + :disable (rb unsigned-byte-p signed-byte-p force (force) + ;; for speed: + signed-byte-p-48-to-<-rule)) + + (defrule rml256-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml256 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml256 lin-addr r-x x86))) + (equal (mv-nth 1 (rml256 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml256 lin-addr r-x x86))) + (equal (mv-nth 2 (rml256 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml256 lin-addr r-x x86)))))) + :enable (rml256) + :disable (rb unsigned-byte-p signed-byte-p member-equal + ;; for speed: + signed-byte-p-48-to-<-rule))) + +;; TODO: Prove wml256 equivalent to rb in the system-level view (again). +(define wml256 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 256)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 256 val)) + :split-types t + :guard-hints + (("Goal" :in-theory (e/d (wb-and-wvm256) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0))))) + + :prepwork + ((defthmd wb-and-wvm256 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 31 lin-addr))) + (equal (wvm256 lin-addr val x86) + (wb 32 lin-addr :w val x86))) + :hints (("Goal" :in-theory (e/d (wml08 wvm08 wvm32 wvm64 wvm128 wvm256) + (force (force))))))) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((31+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 31 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 31+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 31+lin-addr) + #.*2^47*)) + + (if (app-view x86) + + (mbe :logic (wb 32 lin-addr :w val x86) + :exec (wvm256 lin-addr val x86)) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+10*) 10+lin-addr) + (+ 10 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr10) x86) + (la-to-pa 10+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+11*) 11+lin-addr) + (+ 11 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr11) x86) + (la-to-pa 11+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+12*) 12+lin-addr) + (+ 12 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr12) x86) + (la-to-pa 12+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+13*) 13+lin-addr) + (+ 13 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr13) x86) + (la-to-pa 13+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+14*) 14+lin-addr) + (+ 14 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr14) x86) + (la-to-pa 14+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 15+lin-addr) + (+ 15 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr15) x86) + (la-to-pa 15+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+16*) 16+lin-addr) + (+ 16 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr16) x86) + (la-to-pa 16+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+17*) 17+lin-addr) + (+ 17 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr17) x86) + (la-to-pa 17+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+18*) 18+lin-addr) + (+ 18 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr18) x86) + (la-to-pa 18+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+19*) 19+lin-addr) + (+ 19 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr19) x86) + (la-to-pa 19+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+20*) 20+lin-addr) + (+ 20 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr20) x86) + (la-to-pa 20+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+21*) 21+lin-addr) + (+ 21 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr21) x86) + (la-to-pa 21+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+22*) 22+lin-addr) + (+ 22 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr22) x86) + (la-to-pa 22+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+23*) 23+lin-addr) + (+ 23 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr23) x86) + (la-to-pa 23+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+24*) 24+lin-addr) + (+ 24 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr24) x86) + (la-to-pa 24+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+25*) 25+lin-addr) + (+ 25 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr25) x86) + (la-to-pa 25+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+26*) 26+lin-addr) + (+ 26 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr26) x86) + (la-to-pa 26+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+27*) 27+lin-addr) + (+ 27 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr27) x86) + (la-to-pa 27+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+28*) 28+lin-addr) + (+ 28 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr28) x86) + (la-to-pa 28+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+29*) 29+lin-addr) + (+ 29 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr29) x86) + (la-to-pa 29+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+30*) 30+lin-addr) + (+ 30 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr30) x86) + (la-to-pa 30+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+31*) 31+lin-addr) + (+ 31 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr31) x86) + (la-to-pa 31+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff val)))) + (byte1 (mbe :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + (byte2 (mbe :logic (part-select val :low 16 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -16))))) + (byte3 (mbe :logic (part-select val :low 24 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -24))))) + (byte4 (mbe :logic (part-select val :low 32 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -32))))) + (byte5 (mbe :logic (part-select val :low 40 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -40))))) + (byte6 (mbe :logic (part-select val :low 48 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -48))))) + (byte7 (mbe :logic (part-select val :low 56 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -56))))) + (byte8 (mbe :logic (part-select val :low 64 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -64))))) + (byte9 (mbe :logic (part-select val :low 72 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -72))))) + (byte10 (mbe :logic (part-select val :low 80 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -80))))) + (byte11 (mbe :logic (part-select val :low 88 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -88))))) + (byte12 (mbe :logic (part-select val :low 96 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -96))))) + (byte13 (mbe :logic (part-select val :low 104 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -104))))) + (byte14 (mbe :logic (part-select val :low 112 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -112))))) + (byte15 (mbe :logic (part-select val :low 120 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -120))))) + (byte16 (mbe :logic (part-select val :low 128 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -128))))) + (byte17 (mbe :logic (part-select val :low 136 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -136))))) + (byte18 (mbe :logic (part-select val :low 144 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -144))))) + (byte19 (mbe :logic (part-select val :low 152 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -152))))) + (byte20 (mbe :logic (part-select val :low 160 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -160))))) + (byte21 (mbe :logic (part-select val :low 168 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -168))))) + (byte22 (mbe :logic (part-select val :low 176 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -176))))) + (byte23 (mbe :logic (part-select val :low 184 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -184))))) + (byte24 (mbe :logic (part-select val :low 192 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -192))))) + (byte25 (mbe :logic (part-select val :low 200 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -200))))) + (byte26 (mbe :logic (part-select val :low 208 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -208))))) + (byte27 (mbe :logic (part-select val :low 216 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -216))))) + (byte28 (mbe :logic (part-select val :low 224 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -224))))) + (byte29 (mbe :logic (part-select val :low 232 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -232))))) + (byte30 (mbe :logic (part-select val :low 240 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -240))))) + (byte31 (mbe :logic (part-select val :low 248 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -248))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86)) + (x86 (!memi p-addr2 byte2 x86)) + (x86 (!memi p-addr3 byte3 x86)) + (x86 (!memi p-addr4 byte4 x86)) + (x86 (!memi p-addr5 byte5 x86)) + (x86 (!memi p-addr6 byte6 x86)) + (x86 (!memi p-addr7 byte7 x86)) + (x86 (!memi p-addr8 byte8 x86)) + (x86 (!memi p-addr9 byte9 x86)) + (x86 (!memi p-addr10 byte10 x86)) + (x86 (!memi p-addr11 byte11 x86)) + (x86 (!memi p-addr12 byte12 x86)) + (x86 (!memi p-addr13 byte13 x86)) + (x86 (!memi p-addr14 byte14 x86)) + (x86 (!memi p-addr15 byte15 x86)) + (x86 (!memi p-addr16 byte16 x86)) + (x86 (!memi p-addr17 byte17 x86)) + (x86 (!memi p-addr18 byte18 x86)) + (x86 (!memi p-addr19 byte19 x86)) + (x86 (!memi p-addr20 byte20 x86)) + (x86 (!memi p-addr21 byte21 x86)) + (x86 (!memi p-addr22 byte22 x86)) + (x86 (!memi p-addr23 byte23 x86)) + (x86 (!memi p-addr24 byte24 x86)) + (x86 (!memi p-addr25 byte25 x86)) + (x86 (!memi p-addr26 byte26 x86)) + (x86 (!memi p-addr27 byte27 x86)) + (x86 (!memi p-addr28 byte28 x86)) + (x86 (!memi p-addr29 byte29 x86)) + (x86 (!memi p-addr30 byte30 x86)) + (x86 (!memi p-addr31 byte31 x86))) + + (mv nil x86))) + + + (mv 'wml256 x86))) + + (mv 'wml256 x86)) + + /// + + (defthm x86p-wml256 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml256 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (rb x86p force (force) unsigned-byte-p signed-byte-p + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule)))) + :rule-classes (:rewrite :type-prescription))) + +;; TODO: Prove rml512 equivalent to rb in the system-level view. (again) +(define rml512 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (member-eq r-x '(:r :x))) + :split-types t + :guard-hints (("Goal" + :in-theory (e/d (rb-and-rvm512) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0) + la-to-pa + rb)))) + + :prepwork + ((local + (defthmd rb-and-rvm512-helper-1 + (implies + (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 63 lin-addr))) + (equal (rvm512 lin-addr x86) + (list + nil + (logior (mv-nth 1 (rb-1 32 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 32 (+ 32 lin-addr) r-x x86)) + 256)) + x86))) + :hints (("Goal" :in-theory (e/d (rvm512 rb-and-rvm256) + (force (force))))))) + + (local + (defthmd rb-and-rvm512-helper-2 + (implies + (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 63 lin-addr))) + (equal + (logior (mv-nth 1 (rb-1 32 lin-addr r-x x86)) + (ash (mv-nth 1 (rb-1 32 (+ 32 lin-addr) r-x x86)) 256)) + (mv-nth 1 (rb-1 64 lin-addr r-x x86)))) + :hints (("Goal" + :in-theory (e/d () (force (force))) + :use + ((:instance split-rb-in-app-view + (i 32) (j 32))))))) + + (defthmd rb-and-rvm512 + (implies (and (app-view x86) + (x86p x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 63 lin-addr))) + (equal (rvm512 lin-addr x86) + (rb 64 lin-addr r-x x86))) + :hints (("Goal" + :use ((:instance rb-1-in-terms-of-its-components + (n 64))) + :in-theory (e/d (rb-and-rvm512-helper-1 + rb-and-rvm512-helper-2) + (force (force)))))) + + (defthm-unsigned-byte-p unsigned-byte-p-512-of-merge-64-u8s-linear + :hyp (and (unsigned-byte-p 8 h31) + (unsigned-byte-p 8 h30) + (unsigned-byte-p 8 h29) + (unsigned-byte-p 8 h28) + (unsigned-byte-p 8 h27) + (unsigned-byte-p 8 h26) + (unsigned-byte-p 8 h25) + (unsigned-byte-p 8 h24) + (unsigned-byte-p 8 h23) + (unsigned-byte-p 8 h22) + (unsigned-byte-p 8 h21) + (unsigned-byte-p 8 h20) + (unsigned-byte-p 8 h19) + (unsigned-byte-p 8 h18) + (unsigned-byte-p 8 h17) + (unsigned-byte-p 8 h16) + (unsigned-byte-p 8 h15) + (unsigned-byte-p 8 h14) + (unsigned-byte-p 8 h13) + (unsigned-byte-p 8 h12) + (unsigned-byte-p 8 h11) + (unsigned-byte-p 8 h10) + (unsigned-byte-p 8 h9) + (unsigned-byte-p 8 h8) + (unsigned-byte-p 8 h7) + (unsigned-byte-p 8 h6) + (unsigned-byte-p 8 h5) + (unsigned-byte-p 8 h4) + (unsigned-byte-p 8 h3) + (unsigned-byte-p 8 h2) + (unsigned-byte-p 8 h1) + (unsigned-byte-p 8 h0) + (unsigned-byte-p 8 l31) + (unsigned-byte-p 8 l30) + (unsigned-byte-p 8 l29) + (unsigned-byte-p 8 l28) + (unsigned-byte-p 8 l27) + (unsigned-byte-p 8 l26) + (unsigned-byte-p 8 l25) + (unsigned-byte-p 8 l24) + (unsigned-byte-p 8 l23) + (unsigned-byte-p 8 l22) + (unsigned-byte-p 8 l21) + (unsigned-byte-p 8 l20) + (unsigned-byte-p 8 l19) + (unsigned-byte-p 8 l18) + (unsigned-byte-p 8 l17) + (unsigned-byte-p 8 l16) + (unsigned-byte-p 8 l15) + (unsigned-byte-p 8 l14) + (unsigned-byte-p 8 l13) + (unsigned-byte-p 8 l12) + (unsigned-byte-p 8 l11) + (unsigned-byte-p 8 l10) + (unsigned-byte-p 8 l9) + (unsigned-byte-p 8 l8) + (unsigned-byte-p 8 l7) + (unsigned-byte-p 8 l6) + (unsigned-byte-p 8 l5) + (unsigned-byte-p 8 l4) + (unsigned-byte-p 8 l3) + (unsigned-byte-p 8 l2) + (unsigned-byte-p 8 l1) + (unsigned-byte-p 8 l0)) + :bound 512 + :concl (bitops::merge-64-u8s h31 h30 h29 h28 h27 h26 h25 h24 h23 h22 h21 h20 h19 h18 h17 h16 + h15 h14 h13 h12 h11 h10 h9 h8 h7 h6 h5 h4 h3 h2 h1 h0 + l31 l30 l29 l28 l27 l26 l25 l24 l23 l22 l21 l20 l19 l18 l17 l16 + l15 l14 l13 l12 l11 l10 l9 l8 l7 l6 l5 l4 l3 l2 l1 l0) + :hints (("Goal" :in-theory (e/d* () (unsigned-byte-p)))) + :hints-l (("Goal" :in-theory (disable BITOPS::UNSIGNED-BYTE-P-512-OF-MERGE-64-U8S))) + :gen-rewrite nil + :gen-linear t) + + (local (in-theory (disable ia32e-la-to-pa-fixes-perm)))) + + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((63+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 63 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 63+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 63+lin-addr) + #.*2^47*)) + + (if (app-view x86) + (mbe :logic (rb 64 lin-addr r-x x86) + :exec (rvm512 lin-addr x86)) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+10*) 10+lin-addr) + (+ 10 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr10) x86) + (la-to-pa 10+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+11*) 11+lin-addr) + (+ 11 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr11) x86) + (la-to-pa 11+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+12*) 12+lin-addr) + (+ 12 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr12) x86) + (la-to-pa 12+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+13*) 13+lin-addr) + (+ 13 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr13) x86) + (la-to-pa 13+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+14*) 14+lin-addr) + (+ 14 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr14) x86) + (la-to-pa 14+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 15+lin-addr) + (+ 15 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr15) x86) + (la-to-pa 15+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 16+lin-addr) + (+ 16 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr16) x86) + (la-to-pa 16+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+17*) 17+lin-addr) + (+ 17 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr17) x86) + (la-to-pa 17+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+18*) 18+lin-addr) + (+ 18 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr18) x86) + (la-to-pa 18+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+19*) 19+lin-addr) + (+ 19 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr19) x86) + (la-to-pa 19+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+20*) 20+lin-addr) + (+ 20 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr20) x86) + (la-to-pa 20+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+21*) 21+lin-addr) + (+ 21 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr21) x86) + (la-to-pa 21+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+22*) 22+lin-addr) + (+ 22 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr22) x86) + (la-to-pa 22+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+23*) 23+lin-addr) + (+ 23 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr23) x86) + (la-to-pa 23+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+24*) 24+lin-addr) + (+ 24 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr24) x86) + (la-to-pa 24+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+25*) 25+lin-addr) + (+ 25 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr25) x86) + (la-to-pa 25+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+26*) 26+lin-addr) + (+ 26 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr26) x86) + (la-to-pa 26+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+27*) 27+lin-addr) + (+ 27 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr27) x86) + (la-to-pa 27+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+28*) 28+lin-addr) + (+ 28 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr28) x86) + (la-to-pa 28+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+29*) 29+lin-addr) + (+ 29 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr29) x86) + (la-to-pa 29+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+30*) 30+lin-addr) + (+ 30 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr30) x86) + (la-to-pa 30+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+31*) 31+lin-addr) + (+ 31 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr31) x86) + (la-to-pa 31+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+32*) 32+lin-addr) + (+ 32 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr32) x86) + (la-to-pa 32+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+33*) 33+lin-addr) + (+ 33 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr33) x86) + (la-to-pa 33+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+34*) 34+lin-addr) + (+ 34 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr34) x86) + (la-to-pa 34+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+35*) 35+lin-addr) + (+ 35 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr35) x86) + (la-to-pa 35+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+36*) 36+lin-addr) + (+ 36 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr36) x86) + (la-to-pa 36+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+37*) 37+lin-addr) + (+ 37 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr37) x86) + (la-to-pa 37+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+38*) 38+lin-addr) + (+ 38 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr38) x86) + (la-to-pa 38+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+39*) 39+lin-addr) + (+ 39 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr39) x86) + (la-to-pa 39+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+40*) 40+lin-addr) + (+ 40 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr40) x86) + (la-to-pa 40+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+41*) 41+lin-addr) + (+ 41 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr41) x86) + (la-to-pa 41+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+42*) 42+lin-addr) + (+ 42 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr42) x86) + (la-to-pa 42+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+43*) 43+lin-addr) + (+ 43 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr43) x86) + (la-to-pa 43+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+44*) 44+lin-addr) + (+ 44 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr44) x86) + (la-to-pa 44+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+45*) 45+lin-addr) + (+ 45 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr45) x86) + (la-to-pa 45+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+46*) 46+lin-addr) + (+ 46 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr46) x86) + (la-to-pa 46+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+47*) 47+lin-addr) + (+ 47 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr47) x86) + (la-to-pa 47+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+48*) 48+lin-addr) + (+ 48 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr48) x86) + (la-to-pa 48+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+49*) 49+lin-addr) + (+ 49 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr49) x86) + (la-to-pa 49+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+50*) 50+lin-addr) + (+ 50 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr50) x86) + (la-to-pa 50+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+51*) 51+lin-addr) + (+ 51 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr51) x86) + (la-to-pa 51+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+52*) 52+lin-addr) + (+ 52 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr52) x86) + (la-to-pa 52+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+53*) 53+lin-addr) + (+ 53 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr53) x86) + (la-to-pa 53+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+54*) 54+lin-addr) + (+ 54 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr54) x86) + (la-to-pa 54+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+55*) 55+lin-addr) + (+ 55 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr55) x86) + (la-to-pa 55+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+56*) 56+lin-addr) + (+ 56 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr56) x86) + (la-to-pa 56+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+57*) 57+lin-addr) + (+ 57 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr57) x86) + (la-to-pa 57+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+58*) 58+lin-addr) + (+ 58 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr58) x86) + (la-to-pa 58+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+59*) 59+lin-addr) + (+ 59 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr59) x86) + (la-to-pa 59+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+60*) 60+lin-addr) + (+ 60 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr60) x86) + (la-to-pa 60+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+61*) 61+lin-addr) + (+ 61 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr61) x86) + (la-to-pa 61+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+62*) 62+lin-addr) + (+ 62 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr62) x86) + (la-to-pa 62+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + ((the (signed-byte #.*max-linear-address-size+63*) 63+lin-addr) + (+ 63 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr63) x86) + (la-to-pa 63+lin-addr r-x x86)) + ((when flag) (mv flag 0 x86)) + + (byte0 (memi p-addr0 x86)) + (byte1 (memi p-addr1 x86)) + (byte2 (memi p-addr2 x86)) + (byte3 (memi p-addr3 x86)) + (byte4 (memi p-addr4 x86)) + (byte5 (memi p-addr5 x86)) + (byte6 (memi p-addr6 x86)) + (byte7 (memi p-addr7 x86)) + (byte8 (memi p-addr8 x86)) + (byte9 (memi p-addr9 x86)) + (byte10 (memi p-addr10 x86)) + (byte11 (memi p-addr11 x86)) + (byte12 (memi p-addr12 x86)) + (byte13 (memi p-addr13 x86)) + (byte14 (memi p-addr14 x86)) + (byte15 (memi p-addr15 x86)) + + (byte16 (memi p-addr16 x86)) + (byte17 (memi p-addr17 x86)) + (byte18 (memi p-addr18 x86)) + (byte19 (memi p-addr19 x86)) + (byte20 (memi p-addr20 x86)) + (byte21 (memi p-addr21 x86)) + (byte22 (memi p-addr22 x86)) + (byte23 (memi p-addr23 x86)) + (byte24 (memi p-addr24 x86)) + (byte25 (memi p-addr25 x86)) + (byte26 (memi p-addr26 x86)) + (byte27 (memi p-addr27 x86)) + (byte28 (memi p-addr28 x86)) + (byte29 (memi p-addr29 x86)) + (byte30 (memi p-addr30 x86)) + (byte31 (memi p-addr31 x86)) + + (byte32 (memi p-addr32 x86)) + (byte33 (memi p-addr33 x86)) + (byte34 (memi p-addr34 x86)) + (byte35 (memi p-addr35 x86)) + (byte36 (memi p-addr36 x86)) + (byte37 (memi p-addr37 x86)) + (byte38 (memi p-addr38 x86)) + (byte39 (memi p-addr39 x86)) + (byte40 (memi p-addr40 x86)) + (byte41 (memi p-addr41 x86)) + (byte42 (memi p-addr42 x86)) + (byte43 (memi p-addr43 x86)) + (byte44 (memi p-addr44 x86)) + (byte45 (memi p-addr45 x86)) + (byte46 (memi p-addr46 x86)) + (byte47 (memi p-addr47 x86)) + + (byte48 (memi p-addr48 x86)) + (byte49 (memi p-addr49 x86)) + (byte50 (memi p-addr50 x86)) + (byte51 (memi p-addr51 x86)) + (byte52 (memi p-addr52 x86)) + (byte53 (memi p-addr53 x86)) + (byte54 (memi p-addr54 x86)) + (byte55 (memi p-addr55 x86)) + (byte56 (memi p-addr56 x86)) + (byte57 (memi p-addr57 x86)) + (byte58 (memi p-addr58 x86)) + (byte59 (memi p-addr59 x86)) + (byte60 (memi p-addr60 x86)) + (byte61 (memi p-addr61 x86)) + (byte62 (memi p-addr62 x86)) + (byte63 (memi p-addr63 x86)) + + (xxword + (the (unsigned-byte 512) + (bitops::merge-64-u8s + byte63 byte62 byte61 byte60 + byte59 byte58 byte57 byte56 + byte55 byte54 byte53 byte52 + byte51 byte50 byte49 byte48 + byte47 byte46 byte45 byte44 + byte43 byte42 byte41 byte40 + byte39 byte38 byte37 byte36 + byte35 byte34 byte33 byte32 + byte31 byte30 byte29 byte28 + byte27 byte26 byte25 byte24 + byte23 byte22 byte21 byte20 + byte19 byte18 byte17 byte16 + byte15 byte14 byte13 byte12 + byte11 byte10 byte9 byte8 + byte7 byte6 byte5 byte4 + byte3 byte2 byte1 byte0)))) + + (mv nil xxword x86))) + + (mv 'rml512 0 x86))) + + (mv 'rml512 0 x86)) + + /// + + (defthm-unsigned-byte-p n512p-mv-nth-1-rml512 + :hyp t + :bound 512 + :concl (mv-nth 1 (rml512 lin-addr r-x x86)) + :hints (("Goal" :in-theory (e/d () (force (force) signed-byte-p + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule + x86isa::la-to-pa$inline)))) + :gen-linear t + :gen-type t) + + (defthm x86p-rml512 + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml512 lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d () ((force) unsigned-byte-p signed-byte-p + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule + la-to-pa + rb)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm rml512-value-when-error + (implies (mv-nth 0 (rml512 lin-addr r-x x86)) + (equal (mv-nth 1 (rml512 lin-addr r-x x86)) + 0)) + :hints (("Goal" :in-theory (e/d (rml512) + (force + (force) + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule + x86isa::la-to-pa$inline + rb))))) + + ;; (defthm rml512-x86-unmodified-in-not-marking-view + ;; (implies (and (not (marking-view x86)) + ;; (not (mv-nth 0 (rml512 lin-addr r-x x86)))) + ;; (equal (mv-nth 2 (rml512 lin-addr r-x x86)) + ;; x86)) + ;; :hints (("Goal" :in-theory (e/d (rml512 + ;; unsigned-byte-p + ;; signed-byte-p) + ;; (force (force)))))) + + (defthm rml512-x86-unmodified-in-app-view + (implies (app-view x86) + (equal (mv-nth 2 (rml512 lin-addr r-x x86)) + x86)) + :hints (("Goal" :in-theory (e/d (rml512 + unsigned-byte-p + signed-byte-p) + (force (force)))))) + + (defthm xr-rml512-state-sys-view + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; (member-equal fld *x86-field-names-as-keywords*) + ) + (equal (xr fld index (mv-nth 2 (rml512 lin-addr r-x x86))) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d (rml512) + (force + (force) + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule + la-to-pa + rb))))) + + (defrule rml512-xw-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (and (equal (mv-nth 0 (rml512 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml512 lin-addr r-x x86))) + (equal (mv-nth 1 (rml512 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml512 lin-addr r-x x86))))) + :enable (rml512) + :disable (rb unsigned-byte-p signed-byte-p (force) force)) + + (defrule rml512-xw-sys-view + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :marking-view)) + (not (equal fld :tlb)) + (not (equal fld :implicit-supervisor-access)) + (member-equal fld *x86-field-names-as-keywords*)) + (and (equal (mv-nth 0 (rml512 lin-addr r-x (xw fld index value x86))) + (mv-nth 0 (rml512 lin-addr r-x x86))) + (equal (mv-nth 1 (rml512 lin-addr r-x (xw fld index value x86))) + (mv-nth 1 (rml512 lin-addr r-x x86))) + (equal (mv-nth 2 (rml512 lin-addr r-x (xw fld index value x86))) + (xw fld index value (mv-nth 2 (rml512 lin-addr r-x x86)))))) + :enable (rml512) + :disable (rb unsigned-byte-p signed-byte-p force (force) + ;; for speed: + x86isa::signed-byte-p-48-to-<-rule)) + + (defrule rml512-xw-sys-view-rflags-not-ac + (implies + (and (not (app-view x86)) + (equal (rflagsbits->ac value) + (rflagsbits->ac (rflags x86)))) + (and (equal (mv-nth 0 (rml512 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 0 (rml512 lin-addr r-x x86))) + (equal (mv-nth 1 (rml512 lin-addr r-x (xw :rflags nil value x86))) + (mv-nth 1 (rml512 lin-addr r-x x86))) + (equal (mv-nth 2 (rml512 lin-addr r-x (xw :rflags nil value x86))) + (xw :rflags nil value + (mv-nth 2 (rml512 lin-addr r-x x86)))))) + :enable (rml512) + :disable (rb unsigned-byte-p signed-byte-p member-equal + ;; for speed: + signed-byte-p-48-to-<-rule))) + +;; TODO: Prove wml512 equivalent to rb in the system-level view (again). +(define wml512 ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (unsigned-byte 512)) + (x86)) + + :parents (linear-memory) + :guard (and (canonical-address-p lin-addr) + (unsigned-byte-p 512 val)) + :split-types t + :guard-hints + (("Goal" :in-theory (e/d (wb-and-wvm512) + (not + (:rewrite acl2::ash-0) + (:rewrite acl2::zip-open) + (:linear bitops::logior-<-0-linear-2) + (:rewrite xr-and-ia32e-la-to-pa-in-non-marking-view) + (:rewrite bitops::logior-equal-0) + la-to-pa + wb)))) + + :prepwork + ((defthmd wb-and-wvm512 + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ 63 lin-addr))) + (equal (wvm512 lin-addr val x86) + (wb 64 lin-addr :w val x86))) + :hints (("Goal" :in-theory (e/d (wml08 wvm08 wvm32 wvm64 wvm128 wvm256 wvm512) + (force (force)))))) + + ;; The guard proof needs a larger stack limit. + (set-rewrite-stack-limit 2000)) + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((63+lin-addr (the (signed-byte #.*max-linear-address-size+1*) + (+ 63 (the (signed-byte #.*max-linear-address-size*) + lin-addr))))) + + + (if (mbe :logic (canonical-address-p 63+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+1*) + 63+lin-addr) + #.*2^47*)) + + (if (app-view x86) + + (mbe :logic (wb 64 lin-addr :w val x86) + :exec (wvm512 lin-addr val x86)) + + (b* (((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr0) x86) + (la-to-pa lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+1*) 1+lin-addr) + (+ 1 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr1) x86) + (la-to-pa 1+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+2*) 2+lin-addr) + (+ 2 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr2) x86) + (la-to-pa 2+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+3*) 3+lin-addr) + (+ 3 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr3) x86) + (la-to-pa 3+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+4*) 4+lin-addr) + (+ 4 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr4) x86) + (la-to-pa 4+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+5*) 5+lin-addr) + (+ 5 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr5) x86) + (la-to-pa 5+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+6*) 6+lin-addr) + (+ 6 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr6) x86) + (la-to-pa 6+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+7*) 7+lin-addr) + (+ 7 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr7) x86) + (la-to-pa 7+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+8*) 8+lin-addr) + (+ 8 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr8) x86) + (la-to-pa 8+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+9*) 9+lin-addr) + (+ 9 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr9) x86) + (la-to-pa 9+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+10*) 10+lin-addr) + (+ 10 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr10) x86) + (la-to-pa 10+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+11*) 11+lin-addr) + (+ 11 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr11) x86) + (la-to-pa 11+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+12*) 12+lin-addr) + (+ 12 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr12) x86) + (la-to-pa 12+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+13*) 13+lin-addr) + (+ 13 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr13) x86) + (la-to-pa 13+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+14*) 14+lin-addr) + (+ 14 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr14) x86) + (la-to-pa 14+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+15*) 15+lin-addr) + (+ 15 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr15) x86) + (la-to-pa 15+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+16*) 16+lin-addr) + (+ 16 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr16) x86) + (la-to-pa 16+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+17*) 17+lin-addr) + (+ 17 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr17) x86) + (la-to-pa 17+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+18*) 18+lin-addr) + (+ 18 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr18) x86) + (la-to-pa 18+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+19*) 19+lin-addr) + (+ 19 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr19) x86) + (la-to-pa 19+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+20*) 20+lin-addr) + (+ 20 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr20) x86) + (la-to-pa 20+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+21*) 21+lin-addr) + (+ 21 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr21) x86) + (la-to-pa 21+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+22*) 22+lin-addr) + (+ 22 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr22) x86) + (la-to-pa 22+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+23*) 23+lin-addr) + (+ 23 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr23) x86) + (la-to-pa 23+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+24*) 24+lin-addr) + (+ 24 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr24) x86) + (la-to-pa 24+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+25*) 25+lin-addr) + (+ 25 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr25) x86) + (la-to-pa 25+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+26*) 26+lin-addr) + (+ 26 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr26) x86) + (la-to-pa 26+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+27*) 27+lin-addr) + (+ 27 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr27) x86) + (la-to-pa 27+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+28*) 28+lin-addr) + (+ 28 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr28) x86) + (la-to-pa 28+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+29*) 29+lin-addr) + (+ 29 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr29) x86) + (la-to-pa 29+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+30*) 30+lin-addr) + (+ 30 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr30) x86) + (la-to-pa 30+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+31*) 31+lin-addr) + (+ 31 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr31) x86) + (la-to-pa 31+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+32*) 32+lin-addr) + (+ 32 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr32) x86) + (la-to-pa 32+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+33*) 33+lin-addr) + (+ 33 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr33) x86) + (la-to-pa 33+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+34*) 34+lin-addr) + (+ 34 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr34) x86) + (la-to-pa 34+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+35*) 35+lin-addr) + (+ 35 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr35) x86) + (la-to-pa 35+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+36*) 36+lin-addr) + (+ 36 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr36) x86) + (la-to-pa 36+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+37*) 37+lin-addr) + (+ 37 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr37) x86) + (la-to-pa 37+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+38*) 38+lin-addr) + (+ 38 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr38) x86) + (la-to-pa 38+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+39*) 39+lin-addr) + (+ 39 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr39) x86) + (la-to-pa 39+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+40*) 40+lin-addr) + (+ 40 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr40) x86) + (la-to-pa 40+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+41*) 41+lin-addr) + (+ 41 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr41) x86) + (la-to-pa 41+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+42*) 42+lin-addr) + (+ 42 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr42) x86) + (la-to-pa 42+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+43*) 43+lin-addr) + (+ 43 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr43) x86) + (la-to-pa 43+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+44*) 44+lin-addr) + (+ 44 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr44) x86) + (la-to-pa 44+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+45*) 45+lin-addr) + (+ 45 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr45) x86) + (la-to-pa 45+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+46*) 46+lin-addr) + (+ 46 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr46) x86) + (la-to-pa 46+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+47*) 47+lin-addr) + (+ 47 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr47) x86) + (la-to-pa 47+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+48*) 48+lin-addr) + (+ 48 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr48) x86) + (la-to-pa 48+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+49*) 49+lin-addr) + (+ 49 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr49) x86) + (la-to-pa 49+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+50*) 50+lin-addr) + (+ 50 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr50) x86) + (la-to-pa 50+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+51*) 51+lin-addr) + (+ 51 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr51) x86) + (la-to-pa 51+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+52*) 52+lin-addr) + (+ 52 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr52) x86) + (la-to-pa 52+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+53*) 53+lin-addr) + (+ 53 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr53) x86) + (la-to-pa 53+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+54*) 54+lin-addr) + (+ 54 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr54) x86) + (la-to-pa 54+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+55*) 55+lin-addr) + (+ 55 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr55) x86) + (la-to-pa 55+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+56*) 56+lin-addr) + (+ 56 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr56) x86) + (la-to-pa 56+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+57*) 57+lin-addr) + (+ 57 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr57) x86) + (la-to-pa 57+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+58*) 58+lin-addr) + (+ 58 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr58) x86) + (la-to-pa 58+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+59*) 59+lin-addr) + (+ 59 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr59) x86) + (la-to-pa 59+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+60*) 60+lin-addr) + (+ 60 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr60) x86) + (la-to-pa 60+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+61*) 61+lin-addr) + (+ 61 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr61) x86) + (la-to-pa 61+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+62*) 62+lin-addr) + (+ 62 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr62) x86) + (la-to-pa 62+lin-addr :w x86)) + ((when flag) (mv flag x86)) + ((the (signed-byte #.*max-linear-address-size+63*) 63+lin-addr) + (+ 63 lin-addr)) + ((mv flag (the (unsigned-byte #.*physical-address-size*) p-addr63) x86) + (la-to-pa 63+lin-addr :w x86)) + ((when flag) (mv flag x86)) + + (byte0 (mbe :logic (part-select val :low 0 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff val)))) + (byte1 (mbe :logic (part-select val :low 8 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -8))))) + (byte2 (mbe :logic (part-select val :low 16 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -16))))) + (byte3 (mbe :logic (part-select val :low 24 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -24))))) + (byte4 (mbe :logic (part-select val :low 32 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -32))))) + (byte5 (mbe :logic (part-select val :low 40 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -40))))) + (byte6 (mbe :logic (part-select val :low 48 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -48))))) + (byte7 (mbe :logic (part-select val :low 56 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -56))))) + (byte8 (mbe :logic (part-select val :low 64 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -64))))) + (byte9 (mbe :logic (part-select val :low 72 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -72))))) + (byte10 (mbe :logic (part-select val :low 80 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -80))))) + (byte11 (mbe :logic (part-select val :low 88 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -88))))) + (byte12 (mbe :logic (part-select val :low 96 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -96))))) + (byte13 (mbe :logic (part-select val :low 104 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -104))))) + (byte14 (mbe :logic (part-select val :low 112 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -112))))) + (byte15 (mbe :logic (part-select val :low 120 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -120))))) + (byte16 (mbe :logic (part-select val :low 128 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -128))))) + (byte17 (mbe :logic (part-select val :low 136 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -136))))) + (byte18 (mbe :logic (part-select val :low 144 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -144))))) + (byte19 (mbe :logic (part-select val :low 152 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -152))))) + (byte20 (mbe :logic (part-select val :low 160 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -160))))) + (byte21 (mbe :logic (part-select val :low 168 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -168))))) + (byte22 (mbe :logic (part-select val :low 176 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -176))))) + (byte23 (mbe :logic (part-select val :low 184 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -184))))) + (byte24 (mbe :logic (part-select val :low 192 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -192))))) + (byte25 (mbe :logic (part-select val :low 200 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -200))))) + (byte26 (mbe :logic (part-select val :low 208 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -208))))) + (byte27 (mbe :logic (part-select val :low 216 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -216))))) + (byte28 (mbe :logic (part-select val :low 224 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -224))))) + (byte29 (mbe :logic (part-select val :low 232 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -232))))) + (byte30 (mbe :logic (part-select val :low 240 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -240))))) + (byte31 (mbe :logic (part-select val :low 248 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -248))))) + (byte32 (mbe :logic (part-select val :low 256 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -256))))) + (byte33 (mbe :logic (part-select val :low 264 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -264))))) + (byte34 (mbe :logic (part-select val :low 272 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -272))))) + (byte35 (mbe :logic (part-select val :low 280 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -280))))) + (byte36 (mbe :logic (part-select val :low 288 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -288))))) + (byte37 (mbe :logic (part-select val :low 296 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -296))))) + (byte38 (mbe :logic (part-select val :low 304 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -304))))) + (byte39 (mbe :logic (part-select val :low 312 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -312))))) + (byte40 (mbe :logic (part-select val :low 320 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -320))))) + (byte41 (mbe :logic (part-select val :low 328 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -328))))) + (byte42 (mbe :logic (part-select val :low 336 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -336))))) + (byte43 (mbe :logic (part-select val :low 344 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -344))))) + (byte44 (mbe :logic (part-select val :low 352 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -352))))) + (byte45 (mbe :logic (part-select val :low 360 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -360))))) + (byte46 (mbe :logic (part-select val :low 368 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -368))))) + (byte47 (mbe :logic (part-select val :low 376 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -376))))) + (byte48 (mbe :logic (part-select val :low 384 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -384))))) + (byte49 (mbe :logic (part-select val :low 392 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -392))))) + (byte50 (mbe :logic (part-select val :low 400 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -400))))) + (byte51 (mbe :logic (part-select val :low 408 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -408))))) + (byte52 (mbe :logic (part-select val :low 416 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -416))))) + (byte53 (mbe :logic (part-select val :low 424 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -424))))) + (byte54 (mbe :logic (part-select val :low 432 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -432))))) + (byte55 (mbe :logic (part-select val :low 440 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -440))))) + (byte56 (mbe :logic (part-select val :low 448 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -448))))) + (byte57 (mbe :logic (part-select val :low 456 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -456))))) + (byte58 (mbe :logic (part-select val :low 464 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -464))))) + (byte59 (mbe :logic (part-select val :low 472 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -472))))) + (byte60 (mbe :logic (part-select val :low 480 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -480))))) + (byte61 (mbe :logic (part-select val :low 488 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -488))))) + (byte62 (mbe :logic (part-select val :low 496 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -496))))) + (byte63 (mbe :logic (part-select val :low 504 :width 8) + :exec (the (unsigned-byte 8) + (logand #xff (ash val -504))))) + + (x86 (!memi p-addr0 byte0 x86)) + (x86 (!memi p-addr1 byte1 x86)) + (x86 (!memi p-addr2 byte2 x86)) + (x86 (!memi p-addr3 byte3 x86)) + (x86 (!memi p-addr4 byte4 x86)) + (x86 (!memi p-addr5 byte5 x86)) + (x86 (!memi p-addr6 byte6 x86)) + (x86 (!memi p-addr7 byte7 x86)) + (x86 (!memi p-addr8 byte8 x86)) + (x86 (!memi p-addr9 byte9 x86)) + (x86 (!memi p-addr10 byte10 x86)) + (x86 (!memi p-addr11 byte11 x86)) + (x86 (!memi p-addr12 byte12 x86)) + (x86 (!memi p-addr13 byte13 x86)) + (x86 (!memi p-addr14 byte14 x86)) + (x86 (!memi p-addr15 byte15 x86)) + (x86 (!memi p-addr16 byte16 x86)) + (x86 (!memi p-addr17 byte17 x86)) + (x86 (!memi p-addr18 byte18 x86)) + (x86 (!memi p-addr19 byte19 x86)) + (x86 (!memi p-addr20 byte20 x86)) + (x86 (!memi p-addr21 byte21 x86)) + (x86 (!memi p-addr22 byte22 x86)) + (x86 (!memi p-addr23 byte23 x86)) + (x86 (!memi p-addr24 byte24 x86)) + (x86 (!memi p-addr25 byte25 x86)) + (x86 (!memi p-addr26 byte26 x86)) + (x86 (!memi p-addr27 byte27 x86)) + (x86 (!memi p-addr28 byte28 x86)) + (x86 (!memi p-addr29 byte29 x86)) + (x86 (!memi p-addr30 byte30 x86)) + (x86 (!memi p-addr31 byte31 x86)) + (x86 (!memi p-addr32 byte32 x86)) + (x86 (!memi p-addr33 byte33 x86)) + (x86 (!memi p-addr34 byte34 x86)) + (x86 (!memi p-addr35 byte35 x86)) + (x86 (!memi p-addr36 byte36 x86)) + (x86 (!memi p-addr37 byte37 x86)) + (x86 (!memi p-addr38 byte38 x86)) + (x86 (!memi p-addr39 byte39 x86)) + (x86 (!memi p-addr40 byte40 x86)) + (x86 (!memi p-addr41 byte41 x86)) + (x86 (!memi p-addr42 byte42 x86)) + (x86 (!memi p-addr43 byte43 x86)) + (x86 (!memi p-addr44 byte44 x86)) + (x86 (!memi p-addr45 byte45 x86)) + (x86 (!memi p-addr46 byte46 x86)) + (x86 (!memi p-addr47 byte47 x86)) + (x86 (!memi p-addr48 byte48 x86)) + (x86 (!memi p-addr49 byte49 x86)) + (x86 (!memi p-addr50 byte50 x86)) + (x86 (!memi p-addr51 byte51 x86)) + (x86 (!memi p-addr52 byte52 x86)) + (x86 (!memi p-addr53 byte53 x86)) + (x86 (!memi p-addr54 byte54 x86)) + (x86 (!memi p-addr55 byte55 x86)) + (x86 (!memi p-addr56 byte56 x86)) + (x86 (!memi p-addr57 byte57 x86)) + (x86 (!memi p-addr58 byte58 x86)) + (x86 (!memi p-addr59 byte59 x86)) + (x86 (!memi p-addr60 byte60 x86)) + (x86 (!memi p-addr61 byte61 x86)) + (x86 (!memi p-addr62 byte62 x86)) + (x86 (!memi p-addr63 byte63 x86))) + + (mv nil x86))) + + + (mv 'wml512 x86))) + + (mv 'wml512 x86)) + + /// + + (defthm x86p-wml512 + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml512 lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (rb x86p force (force) unsigned-byte-p signed-byte-p la-to-pa)))) + :rule-classes (:rewrite :type-prescription))) + +;; ====================================================================== + +(defsection Parametric-Memory-Reads-and-Writes + + :parents (linear-memory) + + :short "Functions to read/write 8/16/32/64/128/256 bits into the memory." + + (local (in-theory (e/d (member-equal) ()))) + + (define rml-size ((nbytes :type (member 1 2 4 6 8 10 16 32)) + (addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + :guard (natp nbytes) + :guard-hints (("Goal" :in-theory (e/d* (signed-byte-p) ()))) + :inline t + :no-function t + :enabled t + (case nbytes + (1 (rml08 addr r-x x86)) + (2 (rml16 addr r-x x86)) + (4 (rml32 addr r-x x86)) + (6 + ;; Use case: To fetch operands of the form m16:32 (see far jmp + ;; instruction). + (rml48 addr r-x x86)) + (8 (rml64 addr r-x x86)) + (10 + ;; Use case: The instructions LGDT and LIDT need to read 10 + ;; bytes at once. + (rml80 addr r-x x86)) + (16 (rml128 addr r-x x86)) + (32 (rml256 addr r-x x86)) + (otherwise + (if (mbe :logic (canonical-address-p (+ -1 nbytes addr)) + :exec (< (+ -1 nbytes addr) #.*2^47*)) + (rb nbytes addr r-x x86) + (mv 'rml-size 0 x86)))) + + /// + + (defthm x86p-of-mv-nth-2-of-rml-size + (implies (force (x86p x86)) + (x86p (mv-nth 2 (rml-size bytes lin-addr r-x x86))))) + + ;; TODO Prove the following after proving the equivalence of rml128 + ;; and rb in system-level view. + ;; (defthmd rml-size-to-rb + ;; (implies (and (canonical-address-p (+ -1 nbytes lin-addr)) + ;; (canonical-address-p lin-addr)) + ;; (b* (((mv flg1 val x86-1) + ;; (rml-size nbytes lin-addr r-x x86)) + ;; ((mv flg2 bytes x86-2) + ;; (rb nbytes lin-addr r-x x86))) + ;; (and (equal flg1 flg2) + ;; (equal val (if flg1 0 bytes)) + ;; (equal x86-1 x86-2)))) + ;; :hints (("Goal" :in-theory (e/d* (signed-byte-p rml08 rml128 rml32 rml48 rml64 rml80 rml16) + ;; ())))) + + (defthm natp-of-mv-nth-1-of-rml-size-type + (natp (mv-nth 1 (rml-size nbytes addr r-x x86))) + :rule-classes :type-prescription) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rml-size + (implies (and (<= (* 8 nbytes) size) + (natp size)) + (unsigned-byte-p size (mv-nth 1 (rml-size nbytes addr r-x x86)))) + :hints (("Goal" :cases ((natp nbytes)))))) + + (define riml-size ((nbytes :type (member 1 2 4 8)) + (addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + :inline t + :no-function t + :enabled t + (case nbytes + (1 (riml08 addr r-x x86)) + (2 (riml16 addr r-x x86)) + (4 (riml32 addr r-x x86)) + (8 (riml64 addr r-x x86)) + (otherwise + (mv 'riml-size nbytes x86)))) + + (define wml-size ((nbytes :type (member 1 2 4 6 8 10 16 32)) + (addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (integer 0 *)) + (x86)) + :guard (case nbytes + (1 (n08p val)) + (2 (n16p val)) + (4 (n32p val)) + (6 (n48p val)) + (8 (n64p val)) + (10 (n80p val)) + (16 (n128p val)) + (32 (n256p val))) + :inline t + :no-function t + :enabled t + (case nbytes + (1 (wml08 addr val x86)) + (2 (wml16 addr val x86)) + (4 (wml32 addr val x86)) + (6 + ;; Use case: To store operands of the form m16:32. + (wml48 addr val x86)) + (8 (wml64 addr val x86)) + (10 + ;; Use case: Instructions like SGDT and SIDT write 10 bytes to + ;; the memory. + (wml80 addr val x86)) + (16 (wml128 addr val x86)) + (32 (wml256 addr val x86)) + (otherwise + (if (mbe :logic (canonical-address-p (+ -1 nbytes addr)) + :exec (< (+ nbytes addr) #.*2^47-1*)) + (wb nbytes addr :w val x86) + (mv 'wml-size x86)))) + + /// + + (defthm x86p-wml-size + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml-size nbytes lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (rb force (force) unsigned-byte-p signed-byte-p))))) + + ;; TODO Prove the following after proving the equivalence of wml128 + ;; and wb in system-level view. + ;; (defthmd wml-size-to-wb + ;; (implies (and (canonical-address-p (+ -1 nbytes lin-addr)) + ;; (canonical-address-p lin-addr)) + ;; (b* (((mv flg1 x86-1) + ;; (wml-size nbytes lin-addr val x86)) + ;; ((mv flg2 x86-2) + ;; (wb nbytes lin-addr :w val x86))) + ;; (and (equal flg1 flg2) + ;; (equal x86-1 x86-2)))) + ;; :hints (("Goal" :in-theory (e/d* (signed-byte-p + ;; las-to-pas + ;; wml08 wml128 wml32 wml48 wml64 wml80 wml16) + ;; ())))) + ) + + (define wiml-size ((nbytes :type (member 1 2 4 8)) + (addr :type (signed-byte #.*max-linear-address-size*)) + (val :type integer) + (x86)) + :guard (case nbytes + (1 (i08p val)) + (2 (i16p val)) + (4 (i32p val)) + (8 (i64p val))) + :inline t + :no-function t + :enabled t + (case nbytes + (1 (wiml08 addr val x86)) + (2 (wiml16 addr val x86)) + (4 (wiml32 addr val x86)) + (8 (wiml64 addr val x86)) + (otherwise + (mv 'wiml-size x86))))) + +#|| + +;; The following definitions of rml/wml-size are nicer in one sense that +;; their definition is in terms of rb/wb, unlike in the functions +;; above, where the equivalence of rm/wml-size to rb/wb is established +;; via a theorem. However, these nicer definitions cause some proofs +;; to fail in decoding-and-spec-utils.lisp, which I'd rather not +;; fix right now. + +(define rml-size + ((nbytes :type (member 1 2 4 6 8 10 16)) + (lin-addr :type (signed-byte #.*max-linear-address-size*)) + (r-x :type (member :r :x)) + (x86)) + :guard (natp nbytes) + :guard-hints (("Goal" + :in-theory + (e/d* (signed-byte-p rml08 rml128 rml32 rml48 rml64 rml80 rml16) + (create-canonical-address-list-1)))) + :inline t + :no-function t + + (if (mbt (canonical-address-p lin-addr)) + + (let* ((last-lin-addr (the (signed-byte 49) + (+ -1 nbytes lin-addr)))) + (if (mbe :logic (canonical-address-p last-lin-addr) + :exec (< (the (signed-byte 49) last-lin-addr) + #.*2^47*)) + + (mbe + :logic + (b* (((mv flg bytes x86) + (rb (create-canonical-address-list nbytes lin-addr) + r-x x86)) + (result (combine-bytes bytes))) + (mv flg result x86)) + + :exec + + (case nbytes + (1 (rml08 lin-addr r-x x86)) + (2 (rml16 lin-addr r-x x86)) + (4 (rml32 lin-addr r-x x86)) + (6 + ;; Use case: To fetch operands of the form m16:32 (see far jmp ; ; + ;; instruction). ; ; + (rml48 lin-addr r-x x86)) + (8 (rml64 lin-addr r-x x86)) + (10 + ;; Use case: The instructions LGDT and LIDT need to read 10 ; ; + ;; bytes at once. ; ; + (rml80 lin-addr r-x x86)) + (16 (rml128 lin-addr r-x x86)) + (otherwise + (b* (((mv flg bytes x86) + (rb (create-canonical-address-list nbytes lin-addr) + r-x x86)) + ((when flg) + (mv flg 0 x86))) + (mv nil (combine-bytes bytes) x86))))) + + (mv 'rml-size 0 x86))) + (mv 'rml-size 0 x86)) + + /// + + (defthm x86p-of-mv-nth-2-of-rml-size + (implies (and (signed-byte-p *max-linear-address-size* lin-addr) + (x86p x86)) + (x86p (mv-nth 2 (rml-size bytes lin-addr r-x x86)))))) + +(define wml-size + ((nbytes :type (member 1 2 4 6 8 10 16)) + (lin-addr :type (signed-byte #.*max-linear-address-size*)) + (val :type (integer 0 *)) + (x86)) + :guard (and (natp nbytes) + (case nbytes + (1 (n08p val)) + (2 (n16p val)) + (4 (n32p val)) + (6 (n48p val)) + (8 (n64p val)) + (10 (n80p val)) + (16 (n128p val)))) + :guard-hints (("Goal" :in-theory (e/d* (signed-byte-p + las-to-pas + byte-ify + wml08 wml128 wml32 wml48 wml64 wml80 wml16) + ()))) + :inline t + :no-function t + (if (mbt (canonical-address-p lin-addr)) + (let* ((last-lin-addr (the (signed-byte 49) + (+ -1 nbytes lin-addr)))) + (if + (mbe :logic (canonical-address-p last-lin-addr) + :exec (< (the (signed-byte 49) last-lin-addr) + #.*2^47*)) + (mbe + :logic + (wb (create-addr-bytes-alist + (create-canonical-address-list nbytes lin-addr) + (byte-ify nbytes val)) + x86) + :exec + (case nbytes + (1 (wml08 lin-addr val x86)) + (2 (wml16 lin-addr val x86)) + (4 (wml32 lin-addr val x86)) + (6 + ;; Use case: To store operands of the form m16:32. ; + (wml48 lin-addr val x86)) + (8 (wml64 lin-addr val x86)) + (10 + ;; Use case: Instructions like SGDT and SIDT write 10 bytes to ; + ;; the memory. ; + (wml80 lin-addr val x86)) + (16 (wml128 lin-addr val x86)) + (otherwise + (wb (create-addr-bytes-alist + (create-canonical-address-list nbytes lin-addr) + (byte-ify nbytes val)) + x86)))) + + (mv 'wml-size x86))) + (mv 'wml-size x86)) + + /// + + (defthm x86p-wml-size + (implies (force (x86p x86)) + (x86p (mv-nth 1 (wml-size nbytes lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d () (rb force (force) unsigned-byte-p signed-byte-p)))))) + +||# + +;; ====================================================================== + +;; Writing canonical address to memory: + +;; A short note on why I couldn't make do with wiml64 to write a +;; canonical address to the memory: + +;; Here's a small, compelling example. The following is some +;; information provided by profile when running fib(24); here, wiml64 +;; was used to store a canonical address in the memory in the +;; specification of the CALL (#xE8) instruction. + +;; (defun X86ISA::X86-CALL-E8-OP/EN-M calls 7.50E+4 +;; ... +;; Heap bytes allocated 4.80E+6; 33.3% +;; Heap bytes allocated per call 64 + +;; So, for fib(24), 4,801,792 bytes are allocated on the heap! And +;; this is with paging turned off. + +;; The reason why wiml64 uses such a lot of memory is because it +;; creates bignums all the time. But when I have to store a canonical +;; address in the memory, I *know* that I'm storing a quantity lesser +;; than 64-bits. Thus, I use write-canonical-address-to-memory to +;; avoid the creation of bignums. Like the other rm* and wm* +;; functions, I have an MBE inside write-canonical-address-to-memory, +;; where the :logic part is defined in terms of WB. + +;; Note that write-canonical-address-to-memory is optimized in the +;; application-level view only --- in the system-level mode, it's +;; merely a call of wml64. + +(define write-canonical-address-to-memory-user-exec + ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (canonical-address :type (signed-byte #.*max-linear-address-size*)) + (x86)) + + :inline t + :no-function t + :parents (linear-memory) + + :guard (and (canonical-address-p lin-addr) + (canonical-address-p (+ 7 lin-addr)) + (app-view x86)) + :guard-hints (("Goal" :in-theory (e/d (n16-to-i16 member-equal) + ()))) + + (if (mbt (and (app-view x86) + (canonical-address-p (+ 7 lin-addr)))) + + (b* (((the (unsigned-byte 32) canonical-address-low-nat) + (n32 canonical-address)) + ((the (signed-byte 32) canonical-address-high-int) + (mbe + :logic + (n16-to-i16 (part-select canonical-address :low 32 :high 47)) + :exec + (the (signed-byte 16) + (ash canonical-address -32)))) + ((mv flg0 x86) + (wml32 lin-addr canonical-address-low-nat x86)) + ((the (signed-byte #.*max-linear-address-size+1*) next-addr) + (+ 4 lin-addr)) + ((when (mbe :logic (not (canonical-address-p next-addr)) + :exec (<= #.*2^47* + (the (signed-byte + #.*max-linear-address-size+1*) + next-addr)))) + (mv 'wml64-canonical-address-user-view x86)) + ((mv flg1 x86) + (wiml32 next-addr canonical-address-high-int x86)) + ((when (or flg0 flg1)) + (mv 'wml64-canonical-address-user-view x86))) + (mv nil x86)) + + (mv 'unreachable x86))) + +(local + (defthmd wb-1-in-app-view + (implies (and (x86p x86) + (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p (+ -1 n lin-addr))) + (equal (wb-1 n lin-addr w val x86) + (mv nil (mv-nth 1 (wb-1 n lin-addr w val x86))))) + :hints (("Goal" :in-theory (e/d* (wvm08) ()))))) + +(local + (defthm write-canonical-address-to-memory-user-exec-and-wb + (implies (and (app-view x86) + (canonical-address-p lin-addr) + (canonical-address-p canonical-address) + (canonical-address-p (+ 7 lin-addr)) + (x86p x86)) + (equal (write-canonical-address-to-memory-user-exec + lin-addr canonical-address x86) + (wb 8 lin-addr :w (loghead 64 canonical-address) x86))) + :hints (("Goal" + :use ((:instance split-wb-in-app-view + (i 4) + (j 4) + (w :w) + (lin-addr lin-addr) + (val (loghead 64 canonical-address))) + (:instance wb-1-in-app-view + (n 8) + (lin-addr lin-addr) + (w :w) + (val (loghead 64 canonical-address)))) + :in-theory (e/d* + (write-canonical-address-to-memory-user-exec + wiml32 + wml32 + wb-and-wvm64 + wb-1) + ()))))) + +(define write-canonical-address-to-memory + ((lin-addr :type (signed-byte #.*max-linear-address-size*)) + (canonical-address :type (signed-byte #.*max-linear-address-size*)) + (x86)) + + :parents (linear-memory) + :guard-hints (("Goal" :in-theory (e/d (n16-to-i16) + ()))) + + (let* ((7+lin-addr (the (signed-byte #.*max-linear-address-size+2*) + (+ 7 lin-addr)))) + + + (if (mbe :logic (canonical-address-p 7+lin-addr) + :exec (< (the (signed-byte #.*max-linear-address-size+2*) + 7+lin-addr) + #.*2^47*)) + + + (if (app-view x86) + + (mbe :logic + (wb 8 lin-addr :w (loghead 64 canonical-address) x86) + :exec + (write-canonical-address-to-memory-user-exec + lin-addr canonical-address x86)) + + (b* ((canonical-address-unsigned-val + (mbe :logic (loghead 64 canonical-address) + :exec (logand #.*2^64-1* canonical-address)))) + ;; Note that calling wml64 here will be a tad expensive --- + ;; for one, there's an extra function call. Also, the + ;; app-view field will have to be checked + ;; again inside wml64. However, this is better for + ;; reasoning than laying down the code again. As it is, + ;; performance in the system-level view is quite less than + ;; that in application-level view. + (wml64 lin-addr canonical-address-unsigned-val x86))) + + (mv 'write-canonical-address-to-memory-error x86))) + + /// + + (defthm x86p-write-canonical-address-to-memory + (implies (force (x86p x86)) + (x86p (mv-nth + 1 + (write-canonical-address-to-memory + lin-addr canonical-address x86)))) + :rule-classes (:rewrite :type-prescription))) + +;; ====================================================================== + +(defsection program-location + :parents (linear-memory) + + (define byte-listp (x) + :parents (linear-memory) + :short "Recognizer of a list of bytes" + :enabled t + (if (equal x nil) + t + (and (consp x) + (n08p (car x)) + (byte-listp (cdr x)))) + /// + + (defthm byte-listp-implies-true-listp + (implies (byte-listp x) + (true-listp x)) + :rule-classes :forward-chaining) + + (defthm-unsigned-byte-p n08p-element-of-byte-listp + :hyp (and (byte-listp acc) + (natp m) + (< m (len acc))) + :bound 8 + :concl (nth m acc) + :gen-linear t + :gen-type t) + + (defthm repeat-byte-listp + (implies (unsigned-byte-p 8 m) + (byte-listp (acl2::repeat n m))) + :hints (("Goal" :in-theory (e/d (acl2::repeat) ()))) + :rule-classes (:type-prescription :rewrite)) + + (defthm len-of-nthcdr-byte-listp + (implies (and (< m (len acc)) + (natp m)) + (equal (len (nthcdr m acc)) + (- (len acc) m)))) + + (defthm byte-listp-revappend + (implies (forced-and (byte-listp lst1) + (byte-listp lst2)) + (byte-listp (revappend lst1 lst2))) + :rule-classes :type-prescription) + + (defthm true-listp-make-list-ac + (implies (true-listp ac) + (true-listp (make-list-ac n val ac))) + :rule-classes :type-prescription) + + (defthm reverse-byte-listp + (implies (byte-listp x) + (byte-listp (reverse x))) + :rule-classes (:type-prescription :rewrite)) + + (defthm byte-listp-append + (implies (forced-and (byte-listp lst1) + (byte-listp lst2)) + (byte-listp (append lst1 lst2))) + :rule-classes (:rewrite :type-prescription)) + + (defthm make-list-ac-byte-listp + (implies (and (byte-listp x) + (n08p m)) + (byte-listp (make-list-ac n m x))) + :rule-classes (:type-prescription :rewrite))) + + (define combine-bytes (bytes) + :short "Combine a list of bytes, LSB-first, into a single unsigned number" + :guard (byte-listp bytes) + :enabled t + (if (endp bytes) + 0 + ;; (logior (car bytes) (ash (combine-bytes (cdr bytes)) 8)) + (logapp 8 (if (mbt (unsigned-byte-p 8 (car bytes))) + (car bytes) + 0) + (combine-bytes (cdr bytes)))) + + /// + (defthm natp-combine-bytes + (implies (force (byte-listp bytes)) + (natp (combine-bytes bytes))) + :rule-classes :type-prescription) + + (local + (defthm ash-n-3-+-8-lemma + (implies (natp n) + (equal (ash (+ 1 n) 3) (+ 8 (ash n 3)))) + :hints (("goal" :in-theory (e/d* (bitops::ihsext-inductions + bitops::ihsext-recursive-redefs + ash floor) + ()))))) + + (defthm unsigned-byte-p-of-combine-bytes + (implies (and (equal n (ash (len bytes) 3)) + (byte-listp bytes)) + (unsigned-byte-p n (combine-bytes bytes))) + :hints (("Goal" :in-theory (e/d (unsigned-byte-p logapp) ()))) + :rule-classes ((:rewrite) + (:linear + :corollary + (implies (and (equal n (ash (len bytes) 3)) + (byte-listp bytes)) + (<= 0 (combine-bytes bytes)))))) + + (defthm size-of-combine-bytes + (implies (and (equal l (len bytes)) + (byte-listp bytes)) + (< (combine-bytes bytes) (expt 2 (ash l 3)))) + :hints (("Goal" + :use ((:instance unsigned-byte-p-of-combine-bytes + (n (ash (len bytes) 3)))) + :in-theory (e/d* () (unsigned-byte-p-of-combine-bytes)))) + :rule-classes :linear)) + + (local (include-book "std/lists/nthcdr" :dir :system)) + (local (include-book "std/lists/take" :dir :system)) + + (defthm byte-listp-of-nthcdr + (implies (byte-listp xs) + (byte-listp (nthcdr n xs)))) + + (defthm byte-listp-of-take + (implies (and (byte-listp xs) + (<= n (len xs))) + (byte-listp (take n xs)))) + + (define combine-n-bytes ((low natp "Index of the first byte") + (num natp "Number of bytes to combine, + starting at @('pos')") + (bytes byte-listp "LSB first")) + :guard (<= (+ low num) (len bytes)) + :enabled t + (if (mbt (and (<= (+ low num) (len bytes)) + (byte-listp bytes) + (natp low) + (natp num))) + (combine-bytes (take num (nthcdr low bytes))) + 0) + + /// + + (local + (defthm repeat-nil-not-byte-listp + (implies (not (zp n)) + (not (byte-listp (acl2::repeat n nil)))) + :hints (("Goal" :in-theory (e/d (acl2::repeat) ()))))) + + (defthm combine-bytes-and-take-degenerate-case-1 + (implies (zp n) (equal (combine-bytes (take n bytes)) 0))) + + (defthm combine-bytes-and-take-degenerate-case-2 + (equal (combine-bytes (take n nil)) 0) + :hints (("goal" :in-theory (e/d (acl2::repeat) ())))) + + (defthm natp-of-combine-bytes-of-take + (implies (byte-listp bytes) + (<= 0 (combine-bytes (take num bytes)))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm natp-combine-n-bytes + (implies (force (byte-listp bytes)) + (natp (combine-n-bytes low num bytes))) + :hints (("Goal" :in-theory (e/d* () (force (force))))) + :rule-classes + ((:type-prescription) + (:linear + :corollary + (implies (byte-listp bytes) + (<= 0 (combine-n-bytes low num bytes)))))) + + (defthm unsigned-byte-p-of-combine-n-bytes + (implies (and (equal n (ash num 3)) (natp num)) + (unsigned-byte-p n (combine-n-bytes low num bytes))) + :hints (("Goal" + :do-not-induct t + :use ((:instance unsigned-byte-p-of-combine-bytes + (n (ash num 3)) + (bytes (take num (nthcdr low bytes))))) + :in-theory (e/d* () (unsigned-byte-p-of-combine-bytes))))) + + (defthm size-of-combine-n-bytes + (< (combine-n-bytes low num bytes) (expt 2 (ash num 3))) + :hints (("Goal" + :do-not-induct t + :use ((:instance unsigned-byte-p-of-combine-n-bytes + (n (ash num 3)))) + :in-theory (e/d () (unsigned-byte-p-of-combine-n-bytes)))) + :rule-classes :linear)) + + (define program-at (prog-addr bytes x86) + + :parents (linear-memory) + :non-executable t + + :short "Predicate that makes a statement about a program's location + in the memory" + :long "

We use @('program-at') to state that a program, given by + as a list of @('bytes'), is located at contiguous addresses from + @('prog-addr') to @('(len bytes) + prog-addr - 1') in the memory of + the x86 state. Note that this function is non-executable; we use it + only for reasoning about machine-code.

" + :guard (and (canonical-address-p prog-addr) + (canonical-address-p (+ -1 (len bytes) prog-addr)) + (byte-listp bytes)) + + (b* (((mv flg bytes-read ?x86) + (rb (len bytes) prog-addr :x x86))) + (and + (equal flg nil) + + ;; (combine-n-bytes 2 3 '(#xAA #xBB #xCC #xDD #xEE)) + ;; == + ;; (part-select (combine-bytes '(#xAA #xBB #xCC #xDD #xEE)) + ;; :low (ash 2 3) :width (ash 3 3)) + + ;; I prefer combine-n-bytes here instead of combine-bytes + ;; because combine-n-bytes lets me think of subseqs of a list + ;; in the same way I think about slices of a number a la + ;; part-select. + (equal bytes-read (combine-n-bytes 0 (len bytes) bytes)))) + + /// + + (defthm program-at-xw-in-app-view + (implies (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view))) + (equal (program-at addr bytes (xw fld index value x86)) + (program-at addr bytes x86))) + :hints (("Goal" :in-theory (e/d* () (rb))))))) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/modes.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/modes.lisp new file mode 100644 index 000000000..14b65d92a --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/modes.lisp @@ -0,0 +1,200 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Alessandro Coglio +; Contributing Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "segmentation-structures" :dir :utils) +(include-book "paging-structures" :dir :utils) +(include-book "register-readers-and-writers") +(include-book "std/bitsets/bignum-extract" :dir :system) ;; For 64-bit-modep + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ====================================================================== + +(defxdoc x86-modes + :parents (machine) + :short "Modes of operation of the processor." + :long + "

+ For now we do not model in detail all the processor modes and transitions + (see Figure 2-3 in Intel Volume 3A). + We implicitly assume that the processor + is always in one of the following modes: +

+
    +
  • Protected mode.
  • +
  • Compatibility mode (sub-mode of IA-32e mode).
  • +
  • 64-bit mode (sub-mode of IA-32e mode).
  • +
+

+ No real-address mode, virtual-8086 mode, or system management mode for now. +

") + +(local (xdoc::set-default-parents x86-modes)) + +;; ---------------------------------------------------------------------- + +(define 64-bit-modep (x86) + :parents (x86-modes) + :short "Check whether we are in 64-bit mode." + :long + "

+ Given the modeling assumption stated in @(see x86-modes), + this predicate discriminates between + 64-bit mode and the other two modes (collectively, 32-bit mode). + Based on Intel manual, Mar'17, Vol. 3A, Sec. 2.2 (near Fig. 2-3), + the discrimination is based on the IA32_EFER.LME and CS.L bits: + if they are both 1, we are in 64-bit mode, + otherwise we are in 32-bit mode + (protected mode if IA32_EFER.LME is 0, + compatibility mode if IA32_EFER.LME is 1 and CS.L is 0; + note that when IA32_EFER.LME is 0, CS.L should be 0, + according to Intel manual, Mar'17, Vol. 3A, Sec. 3.4.5). +

+

+ This predicate does not include state invariants such as + the constraints imposed by the 64-bit mode consistency checks + described in Intel manual, Mar'17, Vol. 3A, Sec. 9.8.5. +

+

+ This predicate is useful as a hypothesis of theorems + about either 64-bit or 32-bit mode. +

+

+ Since @('(xr :msr ... x86)') returns a 64-bit value + but the IA32_EFER register consists of 12 bits. + So we use @(tsee n12) to make @('ia32_eferBits') functions applicable. +

" + + :no-function t + :guard-hints (("Goal" :in-theory (e/d (bitsets::bignum-extract) (x86p)))) + (mbe + :logic + (b* ((ia32_efer (n12 (msri #.*ia32_efer-idx* x86))) + (ia32_efer.lma (ia32_eferBits->lma ia32_efer)) + (cs-attr (seg-hidden-attri #.*cs* x86)) + (cs.l (code-segment-descriptor-attributesBits->l cs-attr))) + (and (equal ia32_efer.lma 1) + (equal cs.l 1))) + :exec + ;; [Shilpi] During execution, include the following book for efficiency (to + ;; decrease the bytes allocated on the heap because of all the bignum + ;; operations). This is likely most efficient on CCL. + ;; (include-book "std/bitsets/bignum-extract-opt" :dir :system) + ;; Note that this book requires a trust tag. + (b* (((the (unsigned-byte 32) ia32_efer-low-32) + (bitsets::bignum-extract + (msri #.*ia32_efer-idx* x86) + 0)) + ((the (unsigned-byte 12) ia32_efer) + (mbe :logic (n12 ia32_efer-low-32) + :exec (logand #xFFF (the (unsigned-byte 32) ia32_efer-low-32)))) + (ia32_efer.lma (ia32_eferBits->lma ia32_efer)) + ((the (unsigned-byte 16) cs-attr) + (seg-hidden-attri #.*cs* x86)) + (cs.l (code-segment-descriptor-attributesBits->l cs-attr))) + (and (equal ia32_efer.lma 1) + (equal cs.l 1)))) + /// + + (local (in-theory (e/d () (force (force))))) + + (defrule 64-bit-modep-of-xw ; contributed by Eric Smith + (implies (and (not (equal fld :msr)) + (not (equal fld :seg-hidden-attr))) + (equal (64-bit-modep (xw fld index value x86)) + (64-bit-modep x86)))) + + ;; (defrule 64-bit-modep-of-!flgi ; contributed by Eric Smith + ;; (equal (64-bit-modep (!flgi flag val x86)) + ;; (64-bit-modep x86))) + + ;; (defrule 64-bit-modep-of-!flgi-undefined + ;; (equal (64-bit-modep (!flgi-undefined flg x86)) + ;; (64-bit-modep x86)) + ;; :enable !flgi-undefined) + + (defrule 64-bit-modep-of-write-user-rflags + (equal (64-bit-modep (write-user-rflags vector mask x86)) + (64-bit-modep x86)))) + +;; ---------------------------------------------------------------------- + +(define x86-operation-mode (x86) + :short "Returns the current mode of operation of the x86 machine" + :long + "

We only support 64-bit, Compatibility, and 32-bit Protected Modes + for now.

+ +

See @(see x86-modes).

" + :parents (x86-modes) + :returns (mode natp :rule-classes (:type-prescription :rewrite)) + (cond ((64-bit-modep x86) #.*64-bit-mode*) + ;; TODO: Other modes of operation + (t #.*compatibility-mode*)) + + /// + + (defret range-of-x86-operation-mode + (and (<= 0 mode) + (< mode #.*num-proc-modes*)) + :rule-classes :linear) + + (defrule x86-operation-mode-of-xw + (implies (and (not (equal fld :msr)) + (not (equal fld :seg-hidden-attr))) + (equal (x86-operation-mode (xw fld index value x86)) + (x86-operation-mode x86)))) + + ;; (defrule x86-operation-mode-of-!flgi + ;; (equal (x86-operation-mode (!flgi flag val x86)) + ;; (x86-operation-mode x86))) + + ;; (defrule x86-operation-mode-of-!flgi-undefined + ;; (equal (x86-operation-mode (!flgi-undefined flg x86)) + ;; (x86-operation-mode x86)) + ;; :enable !flgi-undefined) + + (defrule x86-operation-mode-of-write-user-rflags + (equal (x86-operation-mode (write-user-rflags vector mask x86)) + (x86-operation-mode x86)))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/physical-memory.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/physical-memory.lisp new file mode 100644 index 000000000..0431d4fd3 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/physical-memory.lisp @@ -0,0 +1,671 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Robert Krug +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "modes") +(include-book "../proofs/utilities/disjoint") + +;; ====================================================================== + +(defsection physical-memory + + :parents (machine) + + :short "Physical memory read and write functions" + + :long "

Note that the top-level memory accessor function is @(see + rme08) and updater function is @(see wme08). Their 16, 32, 64, and + 128 bit counterparts are also available. These functions behave + differently depending upon the value of + @('app-view').

+ +

The functions defined here, like @(see rm-low-32) and @(see +wm-low-32), are low-level read and write functions that access +physical memory directly in the system-level view. We do not +recommend using these functions at the top-level.

") + +(local (xdoc::set-default-parents physical-memory)) + +;; ====================================================================== + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "centaur/bitops/width-find-rule" :dir :system)) +(local (include-book "centaur/bitops/equal-by-logbitp" :dir :system)) + +;; ====================================================================== + +(define physical-address-p (phy-addr) + :parents (physical-memory) + :inline t + :no-function t + :enabled t + (mbe :logic (unsigned-byte-p #.*physical-address-size* phy-addr) + :exec (and (integerp phy-addr) + (<= 0 phy-addr) + (< phy-addr #.*mem-size-in-bytes*)))) + +(define physical-address-listp (lst) + :parents (physical-memory) + :short "Recognizer of a list of physical addresses" + :enabled t + (if (equal lst nil) + t + (and (consp lst) + (physical-address-p (car lst)) + (physical-address-listp (cdr lst))))) + +(define create-physical-address-list (count addr) + + :guard (and (natp count) + (physical-address-p addr) + (physical-address-p (+ addr count))) + :parents (physical-memory) + + :long "

Given a physical address @('addr'), + @('create-physical-address-list') creates a list of physical + addresses where the first address is @('addr') and the last address + is the last physical address in the range @('addr') to @('addr + + count').

" + :enabled t + + (if (or (zp count) + (not (physical-address-p addr))) + nil + (cons addr (create-physical-address-list (1- count) + (1+ addr)))) + /// + + (defthm physical-address-listp-create-physical-address-list + (physical-address-listp + (create-physical-address-list count addr)) + :rule-classes (:rewrite :type-prescription))) + +(define addr-range (count addr) + :guard (natp count) + + :enabled t + + (if (zp count) + nil + ;; The ifix below is intentional --- it allows addr-range to be + ;; used with both integer (canonical addresses, modeled as + ;; signed-byte-p) as well as natp (physical addresses, modeled as + ;; unsigned-byte-p) addresses. + (cons (ifix addr) + (addr-range (1- count) (1+ (ifix addr))))) + + /// + + (defthm neg-addr-range=nil + (implies (negp i) (equal (addr-range i n) nil))) + + (defthm true-listp-addr-range + (true-listp (addr-range count addr)) + :rule-classes :type-prescription) + + (defthm addr-range-1 + (equal (addr-range 1 x) + (list (ifix x))) + :hints (("Goal" :expand (addr-range 1 x)))) + + (defthm len-of-addr-range + (implies (natp n) + (equal (len (addr-range n val)) n)) + :hints (("Goal" :in-theory (e/d (addr-range) ())))) + + (defthm physical-address-listp-addr-range + (implies (and (physical-address-p lin-addr) + (physical-address-p (+ -1 n lin-addr))) + (physical-address-listp (addr-range n lin-addr))) + :hints (("Goal" :in-theory (e/d (addr-range) ())))) + + (defthm member-p-addr-range + (implies (and (<= prog-addr addr) + (< addr (+ n prog-addr)) + (integerp n) + (integerp addr) + (integerp prog-addr)) + (equal (member-p addr (addr-range n prog-addr)) + t))) + + (defthm member-p-addr-range-from-member-p-addr-range + (implies (and (member-p x (addr-range j y)) + (integerp l) + (< j l)) + (equal (member-p x (addr-range l y)) + t))) + + (defthm not-member-p-addr-range + (implies (and (or (< addr prog-addr) + (<= (+ n prog-addr) addr)) + (integerp prog-addr)) + (equal (member-p addr (addr-range n prog-addr)) + nil))) + + (defthm not-member-p-addr-range-from-not-member-p-addr-range + (implies (and (not (member-p x (addr-range j y))) + (integerp j) + (<= l j)) + (equal (member-p x (addr-range l y)) + nil))) + + (defthm subset-p-two-addr-ranges + (implies (and (integerp x) + (integerp y) + (<= y x) + (<= (+ i x) (+ j y)) + (integerp j)) + (subset-p (addr-range i x) + (addr-range j y))) + :hints (("Goal" :in-theory (e/d (subset-p) nil)))) + + (defthm not-disjoint-p-two-addr-ranges-thm + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j) + (<= x y) + (< y (+ i x)) + (<= (+ i x) (+ j y))) + (equal (disjoint-p (addr-range i x) + (addr-range j y)) + nil)) + :hints (("Goal" :in-theory (e/d (disjoint-p member-p) ())))) + + (defthm disjoint-p-two-addr-ranges-thm-0 + (implies (and (integerp x) + (integerp y) + (integerp j) + (< 0 j) + (<= (+ i x) y)) + (disjoint-p (addr-range i x) + (addr-range j y))) + :hints (("Goal" :in-theory (e/d (disjoint-p member-p) ())))) + + (defthm disjoint-p-two-addr-ranges-thm-1 + (implies (and (integerp x) + (integerp y) + (integerp j) + (< 0 j) + (<= (+ j y) x)) + (disjoint-p (addr-range i x) + (addr-range j y))) + :hints (("Goal" :in-theory (e/d (disjoint-p member-p) ())))) + + ;; (defthm disjoint-p-two-addr-ranges-thm-2 + ;; (implies (and (disjoint-p (addr-range i x) + ;; (addr-range j y)) + ;; (integerp i) + ;; (integerp j) + ;; (<= k i) + ;; (<= l j)) + ;; (disjoint-p (addr-range k x) + ;; (addr-range l y))) + ;; :hints (("Goal" :in-theory (e/d (disjoint-p member-p) ())))) + + (defthm disjoint-p-two-addr-ranges-thm-2 + (implies (and (disjoint-p (addr-range i x) (addr-range j y)) + (subset-p (addr-range ia a) (addr-range i x)) + (subset-p (addr-range jb b) (addr-range j y))) + (disjoint-p (addr-range ia a) (addr-range jb b))) + :hints (("Goal" :in-theory (e/d (disjoint-p member-p) ())))) + + (defthm disjoint-p-two-addr-ranges-thm-3 + (implies (and (disjoint-p (addr-range j y) (addr-range i x)) + (subset-p (addr-range ia a) (addr-range i x)) + (subset-p (addr-range jb b) (addr-range j y))) + (disjoint-p (addr-range ia a) (addr-range jb b))) + :hints (("Goal" :use ((:instance disjoint-p-commutative + (a (addr-range j y)) + (b (addr-range i x))))))) + + (defthm consp-addr-range + (implies (posp n) + (consp (addr-range n val))) + :rule-classes (:type-prescription :rewrite)) + + (defthm car-addr-range + (implies (posp n) + (equal (car (addr-range n val)) + (ifix val)))) + + (defthm cdr-addr-range + (implies (and (posp n) + (integerp val)) + (equal (cdr (addr-range n val)) + (addr-range (1- n) (1+ val))))) + + (defthm no-duplicates-p-and-addr-range + (no-duplicates-p (addr-range n x)) + :hints (("Goal" :in-theory (e/d* (member-p) ())))) + + (defthm instance-of-pos-1-accumulator-thm + (implies (and (member-p e x) + (natp acc)) + (equal (pos-1 e x (+ 1 acc)) + (+ 1 (pos-1 e x acc))))) + + ;; (defthm nth-pos-of-addr-range-first + ;; (implies (and (integerp index) + ;; (posp n)) + ;; (equal (pos index (addr-range n index)) 0)) + ;; :hints (("Goal" :in-theory (e/d* (pos) ())))) + + (defthm nth-pos-of-addr-range + (implies (and (<= index i) (< i (+ n index)) + (integerp index) (integerp i) (posp n)) + (equal (pos i (addr-range n index)) + (- i index))) + :hints (("Goal" :in-theory (e/d* (pos) ())))) + + (defthmd addr-range-ifix + (equal (addr-range n (ifix x)) (addr-range n x))) + + (defthm integerp-addr-range-member + (implies (member-p x (addr-range n m)) + (integerp x))) + + (defthm addr-range-not-member-out-of-range + (implies (and (natp n) + (integerp addr) + (< el addr) + (>= el (+ addr n))) + (not (member-p el (addr-range n addr)))))) + +;; ====================================================================== + +;; Memory read functions: + +;; These functions are very similar to their linear memory +;; counterparts, rvm* --- they just differ in guards and the number of +;; return values. + +;; Memory write functions: + +;; These functions are very similar to their linear memory +;; counterparts wvm* --- they differ in guards and the number of +;; return values. + +;; ---------------------------------------------------------------------- + +(local (in-theory (e/d () (unsigned-byte-p)))) +(local (in-theory (e/d (bitops::unsigned-byte-p-by-find-rule) ()))) + +(define rm-low-32 + ((addr :type (unsigned-byte #.*physical-address-size*)) + (x86)) + :guard (and (not (app-view x86)) + (integerp addr) + (<= 0 addr) + (< (+ 3 addr) *mem-size-in-bytes*)) + :inline t + :no-function t + :parents (physical-memory) + + (if (mbt (not (app-view x86))) + + (let ((addr (mbe :logic (ifix addr) + :exec addr))) + + (b* (((the (unsigned-byte 8) byte0) (mbe :logic (loghead 8 (memi addr x86)) + :exec (memi addr x86))) + ((the (unsigned-byte 8) byte1) (mbe :logic (loghead 8 (memi (1+ addr) x86)) + :exec (memi (1+ addr) x86))) + ((the (unsigned-byte 16) word0) + (logior (the (unsigned-byte 16) (ash byte1 8)) byte0)) + ((the (unsigned-byte 8) byte2) (mbe :logic (loghead 8 (memi (+ 2 addr) x86)) + :exec (memi (+ 2 addr) x86))) + ((the (unsigned-byte 8) byte3) (mbe :logic (loghead 8 (memi (+ 3 addr) x86)) + :exec (memi (+ 3 addr) x86))) + ((the (unsigned-byte 16) word1) + (the (unsigned-byte 16) (logior (the (unsigned-byte 16) (ash byte3 8)) byte2))) + ((the (unsigned-byte 32) dword) (logior (the (unsigned-byte 32) (ash word1 16)) word0))) + dword)) + 0) + + + /// + + (defthm rm-low-32-in-app-view + (implies (app-view x86) + (equal (rm-low-32 p-addr x86) 0))) + + (defthm-unsigned-byte-p n32p-rm-low-32 + :bound 32 + :concl (rm-low-32 addr x86) + :hints (("Goal" :in-theory (e/d () (force (force))))) + :gen-linear t + :gen-type t) + + (defthm rm-low-32-xw + (implies (and (not (equal fld :mem)) + (not (equal fld :app-view))) + (equal (rm-low-32 addr (xw fld index val x86)) + (rm-low-32 addr x86))) + :hints (("Goal" :in-theory (e/d* (rm-low-32) (force (force))))))) + +(define wm-low-32 + ((addr :type (unsigned-byte #.*physical-address-size*)) + (val :type (unsigned-byte 32)) + (x86)) + :inline t + :no-function t + :guard (and (not (app-view x86)) + (< (+ 3 addr) *mem-size-in-bytes*)) + :guard-hints (("Goal" :in-theory (e/d (logtail) ()))) + :parents (physical-memory) + + (if (mbt (not (app-view x86))) + + (let ((addr (mbe :logic (ifix addr) + :exec addr))) + + (b* (((the (unsigned-byte 8) byte0) + (mbe :logic (part-select val :low 0 :width 8) + :exec (logand #xff val))) + ((the (unsigned-byte 8) byte1) + (mbe :logic (part-select val :low 8 :width 8) + :exec (logand #xff (ash val -8)))) + ((the (unsigned-byte 8) byte2) + (mbe :logic (part-select val :low 16 :width 8) + :exec (logand #xff (ash val -16)))) + ((the (unsigned-byte 8) byte3) + (mbe :logic (part-select val :low 24 :width 8) + :exec (logand #xff (ash val -24)))) + (x86 (!memi addr byte0 x86)) + (x86 (!memi (+ 1 addr) byte1 x86)) + (x86 (!memi (+ 2 addr) byte2 x86)) + (x86 (!memi (+ 3 addr) byte3 x86))) + x86)) + + x86) + + /// + + (defthm x86p-wm-low-32 + (implies (x86p x86) + (x86p (wm-low-32 addr val x86))) + :rule-classes (:rewrite :type-prescription)) + + (defthm xr-wm-low-32 + (implies (not (equal fld :mem)) + (equal (xr fld index (wm-low-32 addr val x86)) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wm-low-32) (force (force)))))) + + (defthm wm-low-32-xw + (implies (and (not (equal fld :mem)) + (not (equal fld :app-view))) + (equal (wm-low-32 addr val (xw fld index value x86)) + (xw fld index value (wm-low-32 addr val x86)))) + :hints (("Goal" :in-theory (e/d* (wm-low-32) (force (force))))))) + + +; MattK mod for ACL2(p): Hint LOGBITP-REASONING modifies state: +; (set-waterfall-parallelism nil) + +(defthmd put-logior-4-bytes-together + (implies (unsigned-byte-p 32 val) + (equal (logior (loghead 8 val) + (ash (loghead 8 (logtail 8 val)) 8) + (ash (logior (loghead 8 (logtail 16 val)) + (ash (logtail 24 val) 8)) + 16)) + val)) + :hints ((bitops::logbitp-reasoning))) + +;; rm-low-32/wm-low-32/xw RoW: + +(defthm |(rm-low-32 addr2 (wm-low-32 addr1 val x86)) --- same addr| + (implies (and (equal addr1 addr2) + (force (n32p val)) + (not (app-view x86))) + (equal (rm-low-32 addr2 (wm-low-32 addr1 val x86)) + val)) + :hints (("Goal" :in-theory (e/d (rm-low-32 wm-low-32 nfix ifix put-logior-4-bytes-together) + (unsigned-byte-p force (force)))))) + +(defthm |(rm-low-32 addr2 (wm-low-32 addr1 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 4 addr1) + (addr-range 4 addr2)) + (equal (rm-low-32 addr2 (wm-low-32 addr1 val x86)) + (rm-low-32 addr2 x86))) + :hints (("Goal" :in-theory (e/d (rm-low-32 wm-low-32 nfix ifix) + (unsigned-byte-p force (force)))))) + +(defthm |(rm-low-32 addr2 (xw :mem addr1 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 1 addr1) + (addr-range 4 addr2)) + (equal (rm-low-32 addr2 (xw :mem addr1 val x86)) + (rm-low-32 addr2 x86))) + :hints (("Goal" :in-theory (e/d (rm-low-32) (force (force)))))) + +(defthm |(xr :mem addr1 (wm-low-32 addr2 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 4 addr2) + (addr-range 1 addr1)) + (equal (xr :mem addr1 (wm-low-32 addr2 val x86)) + (xr :mem addr1 x86))) + :hints (("Goal" :in-theory (e/d (nfix wm-low-32) (force (force)))))) + +;; wm-low-32 WoW: + +(defthm |(wm-low-32 addr2 val2 (wm-low-32 addr1 val1 x86)) --- same addr| + (implies (equal addr1 addr2) + (equal (wm-low-32 addr2 val2 (wm-low-32 addr1 val1 x86)) + (wm-low-32 addr2 val2 x86))) + :hints (("Goal" :in-theory (e/d (wm-low-32 nfix ifix) (force (force)))))) + +(defthm |(wm-low-32 addr2 val2 (wm-low-32 addr1 val1 x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 4 addr1) + (addr-range 4 addr2)) + (equal (wm-low-32 addr2 val2 (wm-low-32 addr1 val1 x86)) + (wm-low-32 addr1 val1 (wm-low-32 addr2 val2 x86)))) + :hints (("Goal" :in-theory (e/d* (wm-low-32) ()))) + :rule-classes ((:rewrite :loop-stopper ((addr2 addr1))))) + +(defthm |(xw :mem addr1 (wm-low-32 addr2 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 4 addr2) + (addr-range 1 addr1)) + (equal (wm-low-32 addr2 val2 (xw :mem addr1 val1 x86)) + (xw :mem addr1 val1 (wm-low-32 addr2 val2 x86)))) + :hints (("Goal" :in-theory (e/d (nfix ifix wm-low-32) (force (force)))))) + +;; ====================================================================== + +(define rm-low-64 + ((addr :type (unsigned-byte #.*physical-address-size*)) + (x86)) + :guard (and (not (app-view x86)) + (integerp addr) + (<= 0 addr) + (< (+ 7 addr) *mem-size-in-bytes*)) + :guard-hints (("Goal" :in-theory (e/d (unsigned-byte-p) + (rm-low-32 force (force))))) + :parents (physical-memory) + + (if (mbt (not (app-view x86))) + + (b* ((addr (mbe :logic (ifix addr) :exec addr)) + ((the (unsigned-byte 32) dword0) + (rm-low-32 addr x86)) + ((the (unsigned-byte 32) dword1) + (rm-low-32 (+ 4 addr) x86)) + ((the (unsigned-byte 64) qword) + (logior + (the (unsigned-byte 64) + (ash dword1 32)) + dword0))) + qword) + + 0) + + /// + + (defthm rm-low-64-in-app-view + (implies (app-view x86) + (equal (rm-low-64 p-addr x86) 0))) + + (defthm-unsigned-byte-p n64p-rm-low-64 + :bound 64 + :concl (rm-low-64 addr x86) + :hints (("Goal" :in-theory (e/d () + (rm-low-32 + force (force))))) + :gen-linear t + :gen-type t) + + (defthm rm-low-64-xw + (implies (and (not (equal fld :mem)) + (not (equal fld :app-view))) + (equal (rm-low-64 addr (xw fld index val x86)) + (rm-low-64 addr x86))) + :hints (("Goal" :in-theory (e/d* (rm-low-64) (force (force))))))) + +(define wm-low-64 + ((addr :type (unsigned-byte #.*physical-address-size*)) + (val :type (unsigned-byte 64)) + (x86)) + :guard (and (not (app-view x86)) + (< (+ 7 addr) *mem-size-in-bytes*)) + :guard-hints (("Goal" :in-theory (e/d (logtail unsigned-byte-p) + (x86p)))) + :parents (physical-memory) + + (if (mbt (not (app-view x86))) + + (b* ((addr (mbe :logic (ifix addr) :exec addr)) + (dword0 (mbe :logic (part-select val :low 0 :width 32) + :exec (logand #xFFFFFFFF val))) + (dword1 (mbe :logic (part-select val :low 32 :width 32) + :exec (logand #xFFFFFFFF (ash val -32)))) + (x86 (wm-low-32 addr dword0 x86)) + (x86 (wm-low-32 (+ 4 addr) dword1 x86))) + x86) + x86) + /// + (defthm x86p-wm-low-64 + (implies (x86p x86) + (x86p (wm-low-64 addr val x86))) + :hints (("Goal" :in-theory (e/d () (x86p)))) + :rule-classes (:rewrite :type-prescription)) + + (defthm xr-wm-low-64 + (implies (not (equal fld :mem)) + (equal (xr fld index (wm-low-64 addr val x86)) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* (wm-low-64) (force (force)))))) + + (defthm wm-low-64-xw + (implies (and (not (equal fld :mem)) + (not (equal fld :app-view))) + (equal (wm-low-64 addr val (xw fld index value x86)) + (xw fld index value (wm-low-64 addr val x86)))) + :hints (("Goal" :in-theory (e/d* (wm-low-64) (force (force))))))) + +;; rm-low-64/wm-low-64 RoW: + +(defthmd put-logior-2-dwords-together + (implies (unsigned-byte-p 64 val) + (equal (logior (loghead 32 val) + (ash (logtail 32 val) 32)) + val)) + :hints ((bitops::logbitp-reasoning))) + +(defthm |(rm-low-64 addr2 (wm-low-64 addr1 val x86)) --- same addr| + (implies (and (equal addr1 addr2) + (force (n64p val)) + (not (app-view x86))) + (equal (rm-low-64 addr2 (wm-low-64 addr1 val x86)) + val)) + :hints (("Goal" :in-theory (e/d (rm-low-64 wm-low-64 put-logior-2-dwords-together) + ())))) + +(defthm |(rm-low-64 addr2 (wm-low-64 addr1 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 8 addr1) + (addr-range 8 addr2)) + (equal (rm-low-64 addr2 (wm-low-64 addr1 val x86)) + (rm-low-64 addr2 x86))) + :hints (("Goal" + :expand ((:free (n x) (addr-range n x))) ;; ugh + :in-theory (e/d (rm-low-64 wm-low-64 ifix) + (disjoint-p))))) + +(defthm |(rm-low-64 addr2 (xw :mem addr1 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 1 addr1) + (addr-range 8 addr2)) + (equal (rm-low-64 addr2 (xw :mem addr1 val x86)) + (rm-low-64 addr2 x86))) + :hints (("Goal" :in-theory (e/d (rm-low-64 rm-low-32) (force (force)))))) + +(defthm |(xr :mem addr1 (wm-low-64 addr2 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 8 addr2) + (addr-range 1 addr1)) + (equal (xr :mem addr1 (wm-low-64 addr2 val x86)) + (xr :mem addr1 x86))) + :hints (("Goal" :in-theory (e/d (ifix wm-low-32 wm-low-64) (force (force)))))) + +;; wm-low-64 WoW: + +(defthm |(wm-low-64 addr2 val2 (wm-low-64 addr1 val1 x86)) --- same addr| + (implies (equal addr1 addr2) + (equal (wm-low-64 addr2 val2 (wm-low-64 addr1 val1 x86)) + (wm-low-64 addr2 val2 x86))) + :hints (("Goal" :in-theory (e/d (wm-low-64) (rm-low-32 wm-low-32))))) + +(defthm |(wm-low-64 addr2 val2 (wm-low-64 addr1 val1 x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 8 addr1) + (addr-range 8 addr2)) + (equal (wm-low-64 addr2 val2 (wm-low-64 addr1 val1 x86)) + (wm-low-64 addr1 val1 (wm-low-64 addr2 val2 x86)))) + :hints (("Goal" :in-theory (e/d (wm-low-64 wm-low-32) ()))) + :rule-classes ((:rewrite :loop-stopper ((addr2 addr1))))) + +(defthm |(xw :mem addr1 (wm-low-64 addr2 val x86)) --- disjoint addr| + (implies (disjoint-p (addr-range 8 addr2) + (addr-range 1 addr1)) + (equal (wm-low-64 addr2 val2 (xw :mem addr1 val1 x86)) + (xw :mem addr1 val1 (wm-low-64 addr2 val2 x86)))) + :hints (("Goal" :in-theory (e/d (ifix wm-low-64 wm-low-32) (force (force)))))) + +;; ====================================================================== + +(globally-disable '(rm-low-32 rm-low-64 wm-low-32 wm-low-64)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/prefix-modrm-sib-decoding.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/prefix-modrm-sib-decoding.lisp new file mode 100644 index 000000000..fd4578fbb --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/prefix-modrm-sib-decoding.lisp @@ -0,0 +1,2524 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +(include-book "../utils/structures") +(include-book "top-level-memory") +(include-book "dispatch-macros") +(include-book "inst-structs") +(local (include-book "inst-listing")) +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ---------------------------------------------------------------------- + +(defsection prefix-modrm-sib-decoding + :parents (decoding-and-spec-utils) + :short "Decoding utilities for the prefixes, ModR/M, and SIB bytes" + + :long "

Legacy Prefix Decoding

+ +

Array @('*one-byte-prefixes-group-code-info-ar*') is used for the efficient + lookup of prefix group code information from the one-byte opcode map; see + @(see legacy-prefixes-decoding) and @(see opcode-maps).

+ +

Picking Mandatory Prefixes

+ +

See @(see mandatory-prefixes-computation) and @(see + instructions-with-mandatory-prefixes) for details.

+ +

ModR/M and VEX Decoding

+ +

Arrays are created for the efficient lookup of modr/m-related information + from the opcode maps. See @(see ModR/M-decoding).

+ +

SIB Detecting and Decoding

+ +

See @(see SIB-decoding) for details.

") + +(local (xdoc::set-default-parents prefix-modrm-sib-decoding)) + +;; ---------------------------------------------------------------------- + +(defsection legacy-prefixes-decoding + + :short "Functions to detect and decode legacy prefixes" + + (local (xdoc::set-default-parents legacy-prefixes-decoding)) + + (define inst-prefix-byte-group-code ((inst inst-p)) + + :short "Takes in a single instruction and figures out if it is a prefix + byte; if so, the prefix group number is returned." + + :long "

The return value @('0') corresponds to \"not a prefix\" and + @('1'), @('2'), @('3') and @('4') correspond to the prefix group of + byte.

+ +

Note that legacy prefixes are a part of the one-byte opcode map.

" + + (b* (((inst inst))) + (cond + ((keywordp inst.mnemonic) + (case inst.mnemonic + (:prefix-Lock 1) ;; #xF0 + (:prefix-REPNE 1) ;; #xF2 + (:prefix-REP/REPE 1) ;; #xF3 + + (:prefix-ES 2) ;; #x26 + (:prefix-CS 2) ;; #x2E + (:prefix-SS 2) ;; #x36 + (:prefix-DS 2) ;; #x3E + (:prefix-FS 2) ;; #x64 + (:prefix-GS 2) ;; #x65 + + (:prefix-OpSize 3) ;; #x66 + + (:prefix-AddrSize 4) ;; #x67 + + (t 0))) + + (t 0)))) + + (local + (defthm inst-p-of-car-of-inst-list-p + (implies (and (equal (len xs) 1) + (inst-list-p xs)) + (inst-p (car xs))))) + + (define inst-list-prefix-byte-group-code ((first-opcode 24bits-p) + (num-opcodes natp) + (inst-lst inst-list-p)) + :short "Takes in a list of instructions and returns prefix byte group code + for each of the constituent instructions" + + :long "

Source: Intel Manuals, Vol. 2, Section 2.1.1.

+ +

The value @('0') corresponds to \"not a prefix\" and @('1'), + @('2'), @('3') and @('4') correspond to the prefix group of + byte.

" + + (b* (((when (zp num-opcodes)) nil) + (rest (if (24bits-p (1+ first-opcode)) + (inst-list-prefix-byte-group-code + (1+ first-opcode) (1- num-opcodes) inst-lst) + (er hard? 'inst-list-prefix-byte-group-code + "Illegal opcode ~s0.~%" (str::hexify (1+ first-opcode))))) + (same-opcode-insts (select-insts inst-lst :opcode first-opcode)) + ((when (equal (len same-opcode-insts) 1)) + (cons (inst-prefix-byte-group-code (car same-opcode-insts)) rest))) + (cons 0 rest))) + + (make-event + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 + 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 2 2 3 4 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (computed-table + (inst-list-prefix-byte-group-code + #x0 256 *one-byte-opcode-map*)) + ((unless (equal precomputed-table computed-table)) + (er hard 'one-byte-prefixes-group-code-info + "Error: Incorrect legacy prefix info computed!"))) + `(defconst *one-byte-prefixes-group-code-info-ar* + (list-to-array 'one-byte-prefixes-group-code-info + (quote ,computed-table))))) + + (define get-one-byte-prefix-array-code + ((byte :type (unsigned-byte 8))) + :returns (code natp :rule-classes (:rewrite :type-prescription)) + (aref1 'one-byte-prefixes-group-code-info + *one-byte-prefixes-group-code-info-ar* + (mbe :logic (loghead 8 byte) + :exec byte)) + /// + (defthm upper-bound-get-one-byte-prefix-array-code + (<= (get-one-byte-prefix-array-code x) 4)))) + +;; ---------------------------------------------------------------------- + +(defsection instructions-with-mandatory-prefixes + + :short "Based off @(see opcode-maps), pre-computing the opcodes that have a + valid instruction corresponding to the following prefixes: + @(':NO-PREFIX :66 :F3 :F2')." + + (local (xdoc::set-default-parents instructions-with-mandatory-prefixes)) + + (define opcode-present? ((first-opcode 24bits-p) + (num-opcodes natp) + (inst-lst inst-list-p)) + :short "Returns a 256-element list, where a @('1') at a position @('i') + denotes that at least one instruction with opcode @('i') exists in + @('inst-lst'); @('0') denotes no such instruction is present." + + :returns (lst true-listp) + (b* (((when (zp num-opcodes)) nil) + (rest (if (24bits-p (1+ first-opcode)) + (opcode-present? + (1+ first-opcode) (1- num-opcodes) inst-lst) + (er hard? 'opcode-present? + "Illegal opcode ~s0.~%" (str::hexify (1+ first-opcode))))) + (same-opcode-insts (select-insts inst-lst :opcode first-opcode)) + ((when (endp same-opcode-insts)) + (cons 0 rest))) + (cons 1 rest))) + + (make-event + (b* ((64-insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + + (NP-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :NO-PREFIX)) + (NP-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + NP-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (NP-computed-table (opcode-present? #ux0F_00 256 NP-pfx-insts)) + + (66-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :66)) + (66-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + 66-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (66-computed-table (opcode-present? #ux0F_00 256 66-pfx-insts)) + + (F2-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F2)) + (F2-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F2-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F2-computed-table (opcode-present? #ux0F_00 256 F2-pfx-insts)) + + (F3-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F3)) + (F3-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F3-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F3-computed-table (opcode-present? #ux0F_00 256 F3-pfx-insts))) + `(progn + + (defconst *64-bit-mode-two-byte-no-prefix-ok-ar* + (list-to-array '64-bit-mode-two-byte-no-prefix-ok + (ints-to-booleans + (quote ,NP-computed-table)))) + + (defconst *64-bit-mode-two-byte-66-ok-ar* + (list-to-array '64-bit-mode-two-byte-66-ok + (ints-to-booleans + (quote ,66-computed-table)))) + + (defconst *64-bit-mode-two-byte-F2-ok-ar* + (list-to-array '64-bit-mode-two-byte-F2-ok + (ints-to-booleans + (quote ,F2-computed-table)))) + + (defconst *64-bit-mode-two-byte-F3-ok-ar* + (list-to-array '64-bit-mode-two-byte-F3-ok + (ints-to-booleans + (quote ,F3-computed-table))))))) + + (make-event + (b* ((32-insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + + (NP-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :NO-PREFIX)) + (NP-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + NP-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (NP-computed-table (opcode-present? #ux0F_00 256 NP-pfx-insts)) + + (66-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :66)) + (66-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + 66-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (66-computed-table (opcode-present? #ux0F_00 256 66-pfx-insts)) + + (F2-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F2)) + (F2-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F2-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F2-computed-table (opcode-present? #ux0F_00 256 F2-pfx-insts)) + + (F3-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F3)) + (F3-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F3-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F3-computed-table (opcode-present? #ux0F_00 256 F3-pfx-insts))) + `(progn + + (defconst *32-bit-mode-two-byte-no-prefix-ok-ar* + (list-to-array '32-bit-mode-two-byte-no-prefix-ok + (ints-to-booleans + (quote ,NP-computed-table)))) + + (defconst *32-bit-mode-two-byte-66-ok-ar* + (list-to-array '32-bit-mode-two-byte-66-ok + (ints-to-booleans + (quote ,66-computed-table)))) + + (defconst *32-bit-mode-two-byte-F2-ok-ar* + (list-to-array '32-bit-mode-two-byte-F2-ok + (ints-to-booleans + (quote ,F2-computed-table)))) + + (defconst *32-bit-mode-two-byte-F3-ok-ar* + (list-to-array '32-bit-mode-two-byte-F3-ok + (ints-to-booleans + (quote ,F3-computed-table))))))) + + (make-event + (b* ((64-insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + + (NP-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :NO-PREFIX)) + (NP-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + NP-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (NP-computed-table (opcode-present? #ux0F_38_00 256 NP-pfx-insts)) + + (66-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :66)) + (66-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + 66-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (66-computed-table (opcode-present? #ux0F_38_00 256 66-pfx-insts)) + + (F2-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F2)) + (F2-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F2-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F2-computed-table (opcode-present? #ux0F_38_00 256 F2-pfx-insts)) + + (F3-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F3)) + (F3-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F3-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F3-computed-table (opcode-present? #ux0F_38_00 256 F3-pfx-insts))) + `(progn + + (defconst *64-bit-mode-0f-38-three-byte-no-prefix-ok-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-no-prefix-ok + (ints-to-booleans + (quote ,NP-computed-table)))) + + (defconst *64-bit-mode-0f-38-three-byte-66-ok-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-66-ok + (ints-to-booleans + (quote ,66-computed-table)))) + + (defconst *64-bit-mode-0f-38-three-byte-F2-ok-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-F2-ok + (ints-to-booleans + (quote ,F2-computed-table)))) + + (defconst *64-bit-mode-0f-38-three-byte-F3-ok-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-F3-ok + (ints-to-booleans + (quote ,F3-computed-table))))))) + + (make-event + (b* ((32-insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + + (NP-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :no-prefix)) + (NP-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + NP-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (NP-computed-table (opcode-present? #ux0F_38_00 256 NP-pfx-insts)) + + (66-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :66)) + (66-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + 66-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (66-computed-table (opcode-present? #ux0F_38_00 256 66-pfx-insts)) + + (F2-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F2)) + (F2-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F2-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F2-computed-table (opcode-present? #ux0F_38_00 256 F2-pfx-insts)) + + (F3-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F3)) + (F3-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F3-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F3-computed-table (opcode-present? #ux0F_38_00 256 F3-pfx-insts))) + `(progn + + (defconst *32-bit-mode-0f-38-three-byte-no-prefix-ok-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-no-prefix-ok + (ints-to-booleans + (quote ,NP-computed-table)))) + + (defconst *32-bit-mode-0f-38-three-byte-66-ok-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-66-ok + (ints-to-booleans + (quote ,66-computed-table)))) + + (defconst *32-bit-mode-0f-38-three-byte-F2-ok-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-F2-ok + (ints-to-booleans + (quote ,F2-computed-table)))) + (defconst *32-bit-mode-0f-38-three-byte-F3-ok-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-F3-ok + (ints-to-booleans + (quote ,F3-computed-table))))))) + + (make-event + (b* ((64-insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + + (NP-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :no-prefix)) + (NP-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + NP-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (NP-computed-table (opcode-present? #ux0F_3A_00 256 NP-pfx-insts)) + + (66-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :66)) + (66-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + 66-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (66-computed-table (opcode-present? #ux0F_3A_00 256 66-pfx-insts)) + + (F2-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F2)) + (F2-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F2-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F2-computed-table (opcode-present? #ux0F_3A_00 256 F2-pfx-insts)) + + (F3-pfx-insts (select-insts 64-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F3)) + (F3-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F3-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F3-computed-table (opcode-present? #ux0F_3A_00 256 F3-pfx-insts))) + `(progn + + (defconst *64-bit-mode-0f-3A-three-byte-no-prefix-ok-ar* + (list-to-array '64-bit-mode-0f-3A-three-byte-no-prefix-ok + (ints-to-booleans + (quote ,NP-computed-table)))) + + (defconst *64-bit-mode-0f-3A-three-byte-66-ok-ar* + (list-to-array '64-bit-mode-0f-3A-three-byte-66-ok + (ints-to-booleans + (quote ,66-computed-table)))) + + (defconst *64-bit-mode-0f-3A-three-byte-F2-ok-ar* + (list-to-array '64-bit-mode-0f-3A-three-byte-F2-ok + (ints-to-booleans + (quote ,F2-computed-table)))) + (defconst *64-bit-mode-0f-3A-three-byte-F3-ok-ar* + (list-to-array '64-bit-mode-0f-3A-three-byte-F3-ok + (ints-to-booleans + (quote ,F3-computed-table))))))) + + (make-event + (b* ((32-insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + + (NP-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :no-prefix)) + (NP-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + NP-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (NP-computed-table (opcode-present? #ux0F_3A_00 256 NP-pfx-insts)) + + (66-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :66)) + (66-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + 66-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (66-computed-table (opcode-present? #ux0F_3A_00 256 66-pfx-insts)) + + (F2-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F2)) + (F2-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F2-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F2-computed-table (opcode-present? #ux0F_3A_00 256 F2-pfx-insts)) + + (F3-pfx-insts (select-insts 32-insts + ;; All instructions with the appropriate + ;; prefix. + :get/rem :get :prefix :F3)) + (F3-pfx-insts (remove-insts-with-feat + ;; All non-AVX instructions. + F3-pfx-insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (F3-computed-table (opcode-present? #ux0F_3A_00 256 F3-pfx-insts))) + `(progn + + (defconst *32-bit-mode-0f-3A-three-byte-no-prefix-ok-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-no-prefix-ok + (ints-to-booleans + (quote ,NP-computed-table)))) + + (defconst *32-bit-mode-0f-3A-three-byte-66-ok-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-66-ok + (ints-to-booleans + (quote ,66-computed-table)))) + + (defconst *32-bit-mode-0f-3A-three-byte-F2-ok-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-F2-ok + (ints-to-booleans + (quote ,F2-computed-table)))) + (defconst *32-bit-mode-0f-3A-three-byte-F3-ok-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-F3-ok + (ints-to-booleans + (quote ,F3-computed-table)))))))) + +(defsection mandatory-prefixes-computation + + :short "Picking a mandatory prefix" + + :long "

When should we interpret a SIMD prefix (@('66'), @('F2'), + @('F3')) as the mandatory prefix for a given opcode in the two- and three-byte + opcode maps?

+ +

Here are some decoding rules for SIMD mandatory prefixes; note that these + do NOT apply for VEX/EVEX-encoded instructions because the mandatory prefixes + are explicitly stated there. All the examples listed below are from Intel's + XED (x86 Encoder Decoder: @('https://intelxed.github.io/')).

+ +
    + +
  1. For opcodes that can take mandatory prefixes, @('66') is ignored when + @('F2')/@('F3') are present. Also, a mandatory prefix does not have to + immediately precede the opcode byte --- see (4) below.

    + +

    Examples:

    + + + + (1) xed -64 -d 660f6f00 ;; movdqa xmm0, xmmword ptr [rax] + (2) xed -64 -d f30f6f00 ;; movdqu xmm0, xmmword ptr [rax] + (3) xed -64 -d 66f30f6f00 ;; movdqu xmm0, xmmword ptr [rax] (same as (2)) + (4) xed -64 -d f3660f6f00 ;; movdqu xmm0, xmmword ptr [rax] (same as (2)) + + + +
  2. + +
  3. For opcodes that can take mandatory prefixes, the presence of an + unsupported SIMD prefix translates to a reserved instruction; such a prefix + does NOT act as a modifier prefix.

    + +

    Examples: Opcode @('0f 6b') has a no-prefix form and @('66') + mandatory prefix form. When used with @('f3'), it leads to an error; see (3) + below.

    + + + + (1) xed -64 -d 0f6b00 ;; packssdw mmx0, qword ptr [rax] + (2) xed -64 -d 660f6b00 ;; packssdw xmm0, xmmword ptr [rax] + (3) xed -64 -d f3660f6b00 ;; GENERAL_ERROR Could not decode... + + + +
  4. + +
" + + (local (include-book "std/strings/decimal" :dir :system)) + + (local + (define gen-compute-mandatory-prefix-fn + ((map (member-equal map '(#ux0F #ux0F_38 #ux0F_3A))) + (mode (member-equal mode '(32 64)))) + + (b* ((mode-name (str::cat (str::nat-to-dec-string mode) "-BIT")) + (pre-name (str::cat mode-name "-COMPUTE-MANDATORY-PREFIX-FOR-")) + (map-name (case map + (#ux0F "TWO-BYTE") + (#ux0F_38 "0F-38-THREE-BYTE") + (#ux0F_3A "0F-3A-THREE-BYTE"))) + (name (intern$ (str::cat pre-name map-name "-OPCODE") "X86ISA")) + + (F3-ok-crux + (str::cat mode-name "-MODE-" map-name "-F3-OK")) + (F3-ok (intern$ F3-ok-crux "X86ISA")) + (F3-ok-const (intern$ (str::cat "*" F3-ok-crux "-AR*") "X86ISA")) + + (F2-ok-crux + (str::cat mode-name "-MODE-" map-name "-F2-OK")) + (F2-ok (intern$ F2-ok-crux "X86ISA")) + (F2-ok-const (intern$ (str::cat "*" F2-ok-crux "-AR*") "X86ISA")) + + (66-ok-crux + (str::cat mode-name "-MODE-" map-name "-66-OK")) + (66-ok (intern$ 66-ok-crux "X86ISA")) + (66-ok-const (intern$ (str::cat "*" 66-ok-crux "-AR*") "X86ISA"))) + + `(define ,name + ((opcode :type (unsigned-byte 8) + "Relevant opcode byte") + (prefixes :type (unsigned-byte #.*prefixes-width*))) + :guard (prefixes-p prefixes) + :guard-hints + (("Goal" :in-theory (disable aref1 assoc-equal (tau-system)))) + :inline t + + :returns (mandatory-prefix + (unsigned-byte-p 8 mandatory-prefix) + :hints + (("goal" + :use ((:instance 8bits-p-of-prefixes->opr (x prefixes)) + (:instance 8bits-p-of-prefixes->rep (x prefixes))) + :in-theory (e/d (8bits-p) + (8bits-p-of-prefixes->opr + 8bits-p-of-prefixes->rep))))) + + (let ((rep-pfx (the (unsigned-byte 8) (prefixes->rep prefixes)))) + + ;; We first check for F2/F3 prefixes, because they have precedence over + ;; 66. + (if (not (eql rep-pfx 0)) + + (if (or (and (equal rep-pfx #.*mandatory-f3h*) + (aref1 ',F3-ok ,F3-ok-const opcode)) + (and + (equal rep-pfx #.*mandatory-f2h*) + (aref1 ',F2-ok ,F2-ok-const opcode))) + + ;; If the opcode is allowed to have F2/F3, then rep-pfx is the + ;; mandatory-prefix. + + rep-pfx + + ;; If F2/F3 is used with an opcode that does not support + ;; these prefixes as mandatory prefixes, then either F2/F3 + ;; are used as modifier prefixes or the instruction throws a + ;; #UD (which ought to be handled in the dispatch or in the + ;; instruction's semantic function). However, even if 66 is + ;; present, we return 0 as the mandatory prefix because F2/F3 + ;; override 66. + + 0) + + ;; If F2/F3 are not present, then we check for 66 prefix. + (let ((opr-pfx (the (unsigned-byte 8) (prefixes->opr prefixes)))) + + (if (not (eql opr-pfx 0)) + + (if (aref1 ',66-ok ,66-ok-const opcode) + + opr-pfx + + ;; If 66 is used with an opcode that does not support it + ;; as a mandatory prefix, then again, either it is used + ;; as a modifier prefix or the instruction throws a #UD + ;; (handled either in dispatch or in the instruction's + ;; semantic function). + 0) + + ;; No mandatory prefixes present. + 0)))))))) + + (make-event + `(progn + ,(gen-compute-mandatory-prefix-fn #ux0F 64) + ,(gen-compute-mandatory-prefix-fn #ux0F 32) + ,(gen-compute-mandatory-prefix-fn #ux0F_38 64) + ,(gen-compute-mandatory-prefix-fn #ux0F_38 32) + ,(gen-compute-mandatory-prefix-fn #ux0F_3A 64) + ,(gen-compute-mandatory-prefix-fn #ux0F_3A 32))) + + (define compute-mandatory-prefix-for-two-byte-opcode + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (opcode :type (unsigned-byte 8)) + (prefixes :type (unsigned-byte #.*prefixes-width*))) + :inline t + :no-function t + :returns (mandatory-prefix + (unsigned-byte-p 8 mandatory-prefix) + :hints (("Goal" :in-theory (e/d () + (unsigned-byte-p))))) + + (case proc-mode + (#.*64-bit-mode* + (64-bit-compute-mandatory-prefix-for-two-byte-opcode + opcode prefixes)) + (otherwise + (32-bit-compute-mandatory-prefix-for-two-byte-opcode + opcode prefixes)))) + + (define compute-mandatory-prefix-for-0F-38-three-byte-opcode + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (opcode :type (unsigned-byte 8)) + (prefixes :type (unsigned-byte #.*prefixes-width*))) + :inline t + :no-function t + :returns (mandatory-prefix + (unsigned-byte-p 8 mandatory-prefix) + :hints (("Goal" :in-theory (e/d () + (unsigned-byte-p))))) + + (case proc-mode + (#.*64-bit-mode* + (64-bit-compute-mandatory-prefix-for-0F-38-three-byte-opcode + opcode prefixes)) + (otherwise + (32-bit-compute-mandatory-prefix-for-0F-38-three-byte-opcode + opcode prefixes)))) + + (define compute-mandatory-prefix-for-0F-3A-three-byte-opcode + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (opcode :type (unsigned-byte 8)) + (prefixes :type (unsigned-byte #.*prefixes-width*))) + + :inline t + :no-function t + :returns (mandatory-prefix + (unsigned-byte-p 8 mandatory-prefix) + :hints (("Goal" :in-theory (e/d () + (unsigned-byte-p))))) + + (case proc-mode + (#.*64-bit-mode* + (64-bit-compute-mandatory-prefix-for-0F-3A-three-byte-opcode + opcode prefixes)) + (otherwise + (32-bit-compute-mandatory-prefix-for-0F-3A-three-byte-opcode + opcode prefixes)))) + + (define compute-mandatory-prefix-for-three-byte-opcode + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (second-escape-byte :type (unsigned-byte 8) + "Second byte of the three-byte opcode; either + @('0x38') or @('0x3A')") + (opcode :type (unsigned-byte 8) + "Third byte of the three-byte opcode") + (prefixes :type (unsigned-byte #.*prefixes-width*))) + + :inline t + :no-function t + :guard (or (equal second-escape-byte #x38) + (equal second-escape-byte #x3A)) + + :returns (mandatory-prefix + (unsigned-byte-p 8 mandatory-prefix) + :hints (("Goal" :in-theory (e/d () (unsigned-byte-p))))) + + :short "Three-byte opcodes: picks the appropriate SIMD prefix as the + mandatory prefix, if applicable" + + (case second-escape-byte + (#x38 + (compute-mandatory-prefix-for-0F-38-three-byte-opcode + proc-mode opcode prefixes)) + (#x3A + (compute-mandatory-prefix-for-0F-3A-three-byte-opcode + proc-mode opcode prefixes)) + (otherwise 0)))) + +;; ---------------------------------------------------------------------- + +(defsection ModR/M-detection + + :short "Utilities to detect which opcodes need a ModR/M byte" + + (local (xdoc::set-default-parents ModR/M-detection)) + + (define operand-needs-modr/m-p ((operand operand-type-p)) + :short "True if operand needs a modr/m byte" + (b* (((when (null operand)) nil) + (Zop (car operand))) + (cdr (assoc-equal :modr/m? + (cdr (assoc-equal Zop *Z-addressing-method-info*)))))) + + (define inst-needs-modr/m-p ((inst inst-p)) + :short "Given an @(tsee inst-p), determine whether it requires a ModR/M + byte or not." + (b* (((inst inst)) + (opcode inst.opcode) + ((opcode opcode)) + ((when (or (member-equal :1a opcode.superscripts) + (member-equal :1c opcode.superscripts))) + ;; If :1a or :1c are present, then we don't even need to look at the + ;; operand info. --- this instruction definitely needs a ModR/M + ;; byte. See *opcode-map-superscripts* for details. + t) + (operands inst.operands) + ((unless operands) + ;; When no operand info. is present, then no ModR/M byte is needed. + nil) + ((operands operands))) + ;; Return t if any operand needs a ModR/M byte, and nil if none of them + ;; do. + (or (operand-needs-modr/m-p operands.op1) + (operand-needs-modr/m-p operands.op2) + (operand-needs-modr/m-p operands.op3) + (operand-needs-modr/m-p operands.op4)))) + + (define any-inst-needs-modr/m-p ((inst-lst inst-list-p)) + :short "Does any instruction in @('inst-lst') require a ModR/M byte?" + (if (endp inst-lst) + nil + (or (inst-needs-modr/m-p (car inst-lst)) + (any-inst-needs-modr/m-p (cdr inst-lst))))) + + (define compute-modr/m-for-opcodes ((first-opcode 24bits-p) + (num-opcodes natp) + (inst-lst inst-list-p)) + :returns (computed-table true-listp) + + ;; Given a list of instructions with the same opcode, if any of them + ;; require a ModR/M byte, then all of them must --- i.e., these + ;; instructions must be a set of "group" instructions belonging to the + ;; opcode extensions map. Otherwise, differentiating between them wouldn't + ;; be possible. + + (b* (((when (zp num-opcodes)) nil) + (rest (if (24bits-p (1+ first-opcode)) + (compute-modr/m-for-opcodes + (1+ first-opcode) (1- num-opcodes) inst-lst) + (er hard? 'compute-modr/m-for-opcodes + "Illegal opcode ~s0.~%" (str::hexify (1+ first-opcode))))) + (same-opcode-insts (select-insts inst-lst :opcode first-opcode)) + ((when (endp same-opcode-insts)) + (cons 0 rest))) + (cons (if (any-inst-needs-modr/m-p same-opcode-insts) 1 0) + rest)))) + +(defsection ModR/M-decoding + + :short "Functions to detect and decode ModR/M bytes" + + (local (xdoc::set-default-parents ModR/M-decoding)) + + (local + (define first-mismatch? ((x true-listp) + (y true-listp) + (cnt natp)) + ;; For debugging any precomputed-table and computed-table mismatches. + (if (endp x) + (list :x x :y y :cnt cnt) + (if (equal (car x) (car y)) + (first-mismatch? (cdr x) (cdr y) (1+ cnt)) + (list :x (car x) :y (car y) :cnt cnt))))) + + (make-event + ;; For 64-bit mode: + (b* ((precomputed-table + '( + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 + 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 + )) + (computed-table (compute-modr/m-for-opcodes + #x0 256 + (select-insts *one-byte-opcode-map* + :get/rem :rem + :mode :i64))) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-one-byte-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-one-byte-has-modr/m-ar* + (list-to-array '64-bit-mode-one-byte-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit/Compatibility Modes: + (b* ((precomputed-table + '( + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 + 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 + )) + (computed-table (compute-modr/m-for-opcodes + #x0 256 + (select-insts *one-byte-opcode-map* + :get/rem :rem + :mode :o64))) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-one-byte-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-one-byte-has-modr/m-ar* + (list-to-array '32-bit-mode-one-byte-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + ;; ModR/M Arrays for Two-byte Opcode Map: + (make-event + ;; For 64-bit mode: (:NO-PREFIX) + (b* ((precomputed-table + '( + 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 + 1 1 1 1 1 1 1 0 1 1 0 0 0 0 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 + 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 + 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 + )) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :no-prefix)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-two-byte-no-prefix-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-two-byte-no-prefix-has-modr/m-ar* + (list-to-array '64-bit-mode-two-byte-no-prefix-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + ;; The older precomputed tables below (commented out) were a bit misleading + ;; because they also had results for prefixes not equal to the relevant one. + + (make-event + ;; For 64-bit mode: (:66) + (b* ((precomputed-table + ;; '( + ;; 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + ;; 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 + ;; 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 + ;; ) + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0)) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :66)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-two-byte-66-has-modr/m-ar + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-two-byte-66-has-modr/m-ar* + (list-to-array '64-bit-mode-two-byte-66-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:F2) + (b* ((precomputed-table + ;; '( + ;; 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + ;; 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 + ;; 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 + ;; 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; ) + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F2)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-two-byte-F2-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-two-byte-F2-has-modr/m-ar* + (list-to-array '64-bit-mode-two-byte-F2-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:F3) + (b* ((precomputed-table + ;; '( + ;; 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ;; 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + ;; 0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 0 + ;; 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; ) + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 1 0 0 0 1 1 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 + 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F3)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-two-byte-F3-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-two-byte-F3-has-modr/m-ar* + (list-to-array '64-bit-mode-two-byte-F3-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:NO-PREFIX) + (b* ((precomputed-table + ;; '( + ;; 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 + ;; 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1 + ;; 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 + ;; 1 1 1 1 1 1 1 0 1 1 0 0 0 0 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 + ;; 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + ;; 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 + ;; ) + '( + 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 + 1 1 1 1 1 1 1 0 1 1 0 0 0 0 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 + 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 + 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0)) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :no-prefix)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-two-byte-no-prefix-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-two-byte-no-prefix-has-modr/m-ar* + (list-to-array '32-bit-mode-two-byte-no-prefix-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:66) + (b* ((precomputed-table + ;; '( + ;; 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + ;; 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 + ;; 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + ;; 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 + ;; ) + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0)) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :66)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-two-byte-66-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-two-byte-66-has-modr/m-ar* + (list-to-array '32-bit-mode-two-byte-66-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:F2) + (b* ((precomputed-table + ;; '( + ;; 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + ;; 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 + ;; 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 + ;; 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; ) + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F2)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-two-byte-F2-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-two-byte-F2-has-modr/m-ar* + (list-to-array '32-bit-mode-two-byte-F2-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:F3) + (b* ((precomputed-table + ;; '( + ;; 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + ;; 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + ;; 0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 0 + ;; 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + ;; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ;; ) + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 1 0 0 0 1 1 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 + 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) + (insts (select-insts *two-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F3)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-two-byte-F3-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-two-byte-F3-has-modr/m-ar* + (list-to-array '32-bit-mode-two-byte-F3-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + ;; ModR/M Arrays for the first Three-byte Opcode Map: + (make-event + ;; For 64-bit mode: (:NO-PREFIX) + (b* ((precomputed-table + '( + 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :no-prefix)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-38-three-byte-no-prefix-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-38-three-byte-no-prefix-has-modr/m-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-no-prefix-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:66) + (b* ((precomputed-table + '( + 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 + 1 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 + 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0)) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :66)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-38-three-byte-66-has-modr/m-ar + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-38-three-byte-66-has-modr/m-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-66-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:F2) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F2)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-38-three-byte-F2-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-38-three-byte-F2-has-modr/m-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-F2-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:F3) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0)) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F3)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-38-three-byte-F3-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-38-three-byte-F3-has-modr/m-ar* + (list-to-array '64-bit-mode-0f-38-three-byte-F3-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:NO-PREFIX) + (b* ((precomputed-table + '( + 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :no-prefix)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-38-three-byte-no-prefix-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-38-three-byte-no-prefix-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-no-prefix-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:66) + (b* ((precomputed-table + '( + 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 + 1 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 + 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 + 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 + 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :66)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-38-three-byte-66-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-38-three-byte-66-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-66-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:F2) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F2)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-38-three-byte-F2-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-38-three-byte-F2-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-F2-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:F3) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-38-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F3)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_38_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-38-three-byte-F3-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-38-three-byte-F3-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-38-three-byte-F3-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + ;; ModR/M Arrays for the second Three-byte Opcode Map: + (make-event + ;; For 64-bit mode: (:NO-PREFIX) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :no-prefix)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-3A-three-byte-no-prefix-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-3A-three-byte-no-prefix-has-modr/m-ar* + (list-to-array '64-bit-mode-0f-3A-three-byte-no-prefix-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:66) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :66)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-3A-three-byte-66-has-modr/m-ar + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-3A-three-byte-66-has-modr/m-ar* + (list-to-array '64-bit-mode-0f-3A-three-byte-66-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:F2) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F2)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-3A-three-byte-F2-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-3A-three-byte-F2-has-modr/m-ar* + (list-to-array + '64-bit-mode-0f-3A-three-byte-F2-has-modr/m + (ints-to-booleans (quote ,computed-table)))))) + + (make-event + ;; For 64-bit mode: (:F3) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 64-bit mode. + :get/rem :rem + :mode :i64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F3)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '64-bit-mode-0f-3A-three-byte-F3-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *64-bit-mode-0f-3A-three-byte-F3-has-modr/m-ar* + (list-to-array '64-bit-mode-0f-3A-three-byte-F3-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:NO-PREFIX) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :no-prefix)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-3A-three-byte-no-prefix-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-3A-three-byte-no-prefix-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-no-prefix-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:66) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 + 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 + 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :66)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-3A-three-byte-66-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-3A-three-byte-66-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-66-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:F2) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F2)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-3A-three-byte-F2-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-3A-three-byte-F2-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-F2-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (make-event + ;; For 32-bit mode: (:F3) + (b* ((precomputed-table + '( + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (insts (select-insts *0F-3A-three-byte-opcode-map* + ;; All instructions valid in 32-bit mode. + :get/rem :rem + :mode :o64)) + (insts (select-insts insts + ;; All instructions with the appropriate prefix. + :get/rem :get :prefix :F3)) + (insts (remove-insts-with-feat + ;; All non-AVX instructions. + insts + (append (list :avx :avx2 :bmi1 :bmi2) + *avx512-feature-flags*))) + (computed-table (compute-modr/m-for-opcodes #ux0F_3A_00 256 insts)) + ((unless (equal precomputed-table computed-table)) + (er hard '32-bit-mode-0f-3A-three-byte-F3-has-modr/m + "Error: Incorrect ModR/M info computed!"))) + `(defconst *32-bit-mode-0f-3A-three-byte-F3-has-modr/m-ar* + (list-to-array '32-bit-mode-0f-3A-three-byte-F3-has-modr/m + (ints-to-booleans + (quote ,computed-table)))))) + + (with-output + :off :all + :gag-mode nil + + (progn + + (define 64-bit-mode-one-byte-opcode-ModR/M-p + ((opcode :type (unsigned-byte 8))) + :inline t + :no-function t + :short "Returns a boolean saying whether, in 64-bit mode, + the given opcode in the one-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + (aref1 '64-bit-mode-one-byte-has-modr/m + *64-bit-mode-one-byte-has-modr/m-ar* opcode)) + + (define 32-bit-mode-one-byte-opcode-ModR/M-p + ((opcode :type (unsigned-byte 8))) + :inline t + :no-function t + :short "Returns a boolean saying whether, in 32-bit mode, + the given opcode in the one-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + (aref1 '32-bit-mode-one-byte-has-modr/m + *32-bit-mode-one-byte-has-modr/m-ar* opcode)) + + (define one-byte-opcode-ModR/M-p + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (opcode :type (unsigned-byte 8))) + :short "Returns @('t') if a one-byte opcode requires a ModR/M byte; + @('nil') otherwise" + :inline t + :no-function t + :returns (bool booleanp :hyp (n08p opcode)) + (if (equal proc-mode #.*64-bit-mode*) + (64-bit-mode-one-byte-opcode-ModR/M-p opcode) + ;; TODO: Other modes eventually. + (32-bit-mode-one-byte-opcode-ModR/M-p opcode))) + + (define 64-bit-mode-two-byte-opcode-ModR/M-p + ((mandatory-prefix :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8) + "Second byte of the two-byte opcode")) + :short "Returns a boolean saying whether, in 64-bit mode, + the given opcode in the two-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + + (case mandatory-prefix + + (#.*mandatory-66h* + (aref1 '64-bit-mode-two-byte-66-has-modr/m + *64-bit-mode-two-byte-66-has-modr/m-ar* opcode)) + + (#.*mandatory-F3h* + (aref1 '64-bit-mode-two-byte-F3-has-modr/m + *64-bit-mode-two-byte-F3-has-modr/m-ar* opcode)) + + (#.*mandatory-F2h* + (aref1 '64-bit-mode-two-byte-F2-has-modr/m + *64-bit-mode-two-byte-F2-has-modr/m-ar* opcode)) + + (t + ;; Applies to simple cells as well as NP compound cells. + (aref1 '64-bit-mode-two-byte-no-prefix-has-modr/m + *64-bit-mode-two-byte-no-prefix-has-modr/m-ar* opcode)))) + + (define 32-bit-mode-two-byte-opcode-ModR/M-p + ((mandatory-prefix :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8) + "Second byte of the two-byte opcode")) + :short "Returns a boolean saying whether, in 32-bit mode, + the given opcode in the two-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + + (case mandatory-prefix + + (#.*mandatory-66h* + (aref1 '32-bit-mode-two-byte-66-has-modr/m + *32-bit-mode-two-byte-66-has-modr/m-ar* opcode)) + + (#.*mandatory-F3h* + (aref1 '32-bit-mode-two-byte-F3-has-modr/m + *32-bit-mode-two-byte-F3-has-modr/m-ar* opcode)) + + (#.*mandatory-F2h* + (aref1 '32-bit-mode-two-byte-F2-has-modr/m + *32-bit-mode-two-byte-F2-has-modr/m-ar* opcode)) + + (t + ;; Applies to simple cells as well as NP compound cells. + (aref1 '32-bit-mode-two-byte-no-prefix-has-modr/m + *32-bit-mode-two-byte-no-prefix-has-modr/m-ar* opcode)))) + + (define two-byte-opcode-ModR/M-p + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (mandatory-prefix :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8) + "Second byte of the two-byte opcode")) + :short "Returns @('t') if a two-byte opcode requires a ModR/M byte; + @('nil') otherwise. Doesn't account for AVX/AVX2/AVX512 instructions." + :inline t + :no-function t + :returns (bool booleanp :hyp (n08p opcode)) + + (cond ((equal proc-mode #.*64-bit-mode*) + (64-bit-mode-two-byte-opcode-ModR/M-p + mandatory-prefix opcode)) + (t + ;; TODO: Other modes here eventually. + (32-bit-mode-two-byte-opcode-ModR/M-p + mandatory-prefix opcode)))) + + + (define 64-bit-mode-0F-38-three-byte-opcode-ModR/M-p + ((mandatory-prefix :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8) + "Third byte of the 38 three-byte opcode")) + :short "Returns a boolean saying whether, in 64-bit mode, the given + opcode in the first three-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + + (case mandatory-prefix + + (#.*mandatory-66h* + (aref1 '64-bit-mode-0F-38-three-byte-66-has-modr/m + *64-bit-mode-0F-38-three-byte-66-has-modr/m-ar* opcode)) + + (#.*mandatory-F3h* + (aref1 '64-bit-mode-0F-38-three-byte-F3-has-modr/m + *64-bit-mode-0F-38-three-byte-F3-has-modr/m-ar* opcode)) + + (#.*mandatory-F2h* + (aref1 '64-bit-mode-0F-38-three-byte-F2-has-modr/m + *64-bit-mode-0F-38-three-byte-F2-has-modr/m-ar* opcode)) + + (t + ;; Applies to simple cells as well as NP compound cells. + (aref1 '64-bit-mode-0F-38-three-byte-no-prefix-has-modr/m + *64-bit-mode-0F-38-three-byte-no-prefix-has-modr/m-ar* + opcode)))) + + (define 32-bit-mode-0F-38-three-byte-opcode-ModR/M-p + ((mandatory-prefix :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8) + "Third byte of the 38 three-byte opcode")) + :short "Returns a boolean saying whether, in 32-bit mode, the given + opcode in the first three-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + + (case mandatory-prefix + + (#.*mandatory-66h* + (aref1 '32-bit-mode-0F-38-three-byte-66-has-modr/m + *32-bit-mode-0F-38-three-byte-66-has-modr/m-ar* opcode)) + + (#.*mandatory-F3h* + (aref1 '32-bit-mode-0F-38-three-byte-F3-has-modr/m + *32-bit-mode-0F-38-three-byte-F3-has-modr/m-ar* opcode)) + + (#.*mandatory-F2h* + (aref1 '32-bit-mode-0F-38-three-byte-F2-has-modr/m + *32-bit-mode-0F-38-three-byte-F2-has-modr/m-ar* opcode)) + + (t + ;; Applies to simple cells as well as NP compound cells. + (aref1 '32-bit-mode-0F-38-three-byte-no-prefix-has-modr/m + *32-bit-mode-0F-38-three-byte-no-prefix-has-modr/m-ar* + opcode)))) + + (define 64-bit-mode-0F-3A-three-byte-opcode-ModR/M-p + ((mandatory-prefix :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8) + "Third byte of the 3A three-byte opcode")) + :short "Returns a boolean saying whether, in 64-bit mode, the given + opcode in the second three-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + + (case mandatory-prefix + + (#.*mandatory-66h* + (aref1 '64-bit-mode-0F-3A-three-byte-66-has-modr/m + *64-bit-mode-0F-3A-three-byte-66-has-modr/m-ar* opcode)) + + (#.*mandatory-F3h* + (aref1 '64-bit-mode-0F-3A-three-byte-F3-has-modr/m + *64-bit-mode-0F-3A-three-byte-F3-has-modr/m-ar* opcode)) + + (#.*mandatory-F2h* + (aref1 '64-bit-mode-0F-3A-three-byte-F2-has-modr/m + *64-bit-mode-0F-3A-three-byte-F2-has-modr/m-ar* opcode)) + + (t + ;; Applies to simple cells as well as NP compound cells. + (aref1 '64-bit-mode-0F-3A-three-byte-no-prefix-has-modr/m + *64-bit-mode-0F-3A-three-byte-no-prefix-has-modr/m-ar* + opcode)))) + + (define 32-bit-mode-0F-3A-three-byte-opcode-ModR/M-p + ((mandatory-prefix :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8) + "Third byte of the 3A three-byte opcode")) + :short "Returns a boolean saying whether, in 32-bit mode, the given + opcode in the second three-byte opcode map expects a ModR/M byte." + :returns (bool booleanp :hyp (n08p opcode)) + + (case mandatory-prefix + + (#.*mandatory-66h* + (aref1 '32-bit-mode-0F-3A-three-byte-66-has-modr/m + *32-bit-mode-0F-3A-three-byte-66-has-modr/m-ar* opcode)) + + (#.*mandatory-F3h* + (aref1 '32-bit-mode-0F-3A-three-byte-F3-has-modr/m + *32-bit-mode-0F-3A-three-byte-F3-has-modr/m-ar* opcode)) + + (#.*mandatory-F2h* + (aref1 '32-bit-mode-0F-3A-three-byte-F2-has-modr/m + *32-bit-mode-0F-3A-three-byte-F2-has-modr/m-ar* opcode)) + + (t + ;; Applies to simple cells as well as NP compound cells. + (aref1 '32-bit-mode-0F-3A-three-byte-no-prefix-has-modr/m + *32-bit-mode-0F-3A-three-byte-no-prefix-has-modr/m-ar* + opcode)))) + + (define three-byte-opcode-ModR/M-p + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (mandatory-prefix :type (unsigned-byte 8)) + (escape-byte :type (unsigned-byte 8) + "Second byte of the three-byte opcode --- either + @('#x38') or @('#x3A')") + (opcode :type (unsigned-byte 8) + "Third byte of the three-byte opcode")) + :short "Returns @('t') if a three-byte opcode requires a ModR/M byte; + @('nil') otherwise. Doesn't account for AVX/AVX2/AVX512 instructions." + :inline t + :no-function t + :guard (or (equal escape-byte #x38) + (equal escape-byte #x3A)) + :returns (bool booleanp :hyp (n08p opcode)) + + (cond ((equal escape-byte #x38) + (if (equal proc-mode #.*64-bit-mode*) + (64-bit-mode-0F-38-three-byte-opcode-ModR/M-p + mandatory-prefix opcode) + ;; TODO: Other modes here eventually. + (32-bit-mode-0F-38-three-byte-opcode-ModR/M-p + mandatory-prefix opcode))) + (t + (if (equal proc-mode #.*64-bit-mode*) + (64-bit-mode-0F-3A-three-byte-opcode-ModR/M-p + mandatory-prefix opcode) + ;; TODO: Other modes here eventually. + (32-bit-mode-0F-3A-three-byte-opcode-ModR/M-p + mandatory-prefix opcode))))))) + + (define show-no-modr/m-insts ((inst-lst inst-list-p)) + :returns (no-modr/m-insts inst-list-p + :hyp (inst-list-p inst-lst)) + :short "Show all the instructions in @('inst-lst') which don't require a + ModR/M byte" + + (b* (((when (endp inst-lst)) nil) + (inst (car inst-lst)) + (rest (show-no-modr/m-insts (cdr inst-lst)))) + (if (inst-needs-modr/m-p inst) + rest + (cons inst rest)))) + + (assert-event + (b* ((insts (append *one-byte-opcode-map* + *two-byte-opcode-map* + *0F-38-three-byte-opcode-map* + *0F-3A-three-byte-opcode-map*)) + (insts (select-insts insts :vex? t)) + (no-modr/m-opcodes (show-no-modr/m-insts insts)) + ((unless (equal (len no-modr/m-opcodes) 2)) nil) + (inst1 (nth 0 no-modr/m-opcodes)) + (inst2 (nth 1 no-modr/m-opcodes)) + ((inst inst1)) ((opcode inst1.opcode)) + ((inst inst2)) ((opcode inst2.opcode))) + (and (equal inst1.opcode.op #ux0F_77) + (equal inst2.opcode.op #ux0F_77)))) + + (define vex-opcode-ModR/M-p + ((vex-prefixes :type (unsigned-byte 24)) + (opcode :type (unsigned-byte 8))) + :short "Returns @('t') if a VEX-encoded opcode requires a ModR/M byte; + @('nil') otherwise." + :inline t + :no-function t + :returns (bool booleanp) + :guard (vex-prefixes-byte0-p vex-prefixes) + (if (not (equal opcode #x77)) + t + ;; VZEROALL/VZEROUPPER are the only two VEX-encoded instructions that do + ;; not require a ModR/M byte. These have the opcode #ux0F_77. See the + ;; assert-event above. + (not (vex-prefixes-map-p #x0F vex-prefixes))))) + +;; ---------------------------------------------------------------------- + +(defsection SIB-decoding + :parents (decoding-and-spec-utils) + :short "Functions to detect and decode SIB bytes" + + (local (xdoc::set-default-parents SIB-decoding)) + + (define x86-decode-SIB-p + ((ModR/M :type (unsigned-byte 8)) + (16-bit-addressp booleanp)) + :returns (bool booleanp :hyp (n08p ModR/M)) + :short "Returns a boolean saying whether a SIB byte is expected to follow a + ModR/M byte or not." + :long + "

+ This is based on Intel manual, Jan'19, Volume 2, Tables 2-1 and 2-2, + as well as AMD manual, Dec'17, Volume 3, Tables A-33 and A-35. + When the address size is 32 or 64 bits, + Intel Table 2-2 and AMD Table A-35 apply: + a SIB byte is expected exactly when + ModR/M.mod is not #b11 and ModR/M.r/m is #b100. + When the address size is 16 bits, no SIB byte is expected. +

+

+ Intel Table 2-3 applies to 32-bit addresses, + but Section 2.2.1.3 says that it also applies to 64-bit addresses. + AMD Table A-35 mentions both 32-bit and 64-bit addressing. +

+

+ Intel manual, Jan'19, Volume 2, Table 2-7 is not very clear, + giving the impression that a SIB byte may be required + when Mod = 00 and R/M = 101 (last column of first row). + But AMD manual, Dec'17, Volume 3, Table 1-16 + (which corresponds to Intel Table 2-7) clearly says that + no SIB byte is present in the first row. + Intel's last column of first row means that, + in order to use @('Disp32') instead of @('RIP+Disp32'), + 64-bit mode must use the encoding with SIB in the second row. +

+

+ The second argument of this function says whether + the address size is 16 bits or not (i.e. 32 or 64 bits). + In 64-bit mode, this argument is always @('nil'). + In 32-bit mode, this argument may be @('t') or @('nil'). +

" + (and (not 16-bit-addressp) + (b* ((r/m (modr/m->r/m ModR/M)) + (mod (modr/m->mod ModR/M))) + (and (int= r/m 4) + (not (int= mod 3))))))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/register-readers-and-writers.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/register-readers-and-writers.lisp new file mode 100644 index 000000000..3b8825b71 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/register-readers-and-writers.lisp @@ -0,0 +1,1831 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2024, Kestrel Technology LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author: +; Alessandro Coglio (www.alessandrocoglio.info) + +(in-package "X86ISA") +(include-book "state") +(include-book "rflags-spec") +(include-book "fp-structures" :dir :utils) +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +; Instruction to cert.pl for dependency tracking. +; (depends-on "register-readers-and-writers-raw.lsp") + +;; ---------------------------------------------------------------------- + +(defsection register-readers-and-writers + :parents (machine) + :short "Top-level utilities for reading and writing into various + registers" + ) + +(local (in-theory (e/d () (unsigned-byte-p)))) + +;; ---------------------------------------------------------------------- + +; This is also used for indices of XMM/YMM/ZMM registers. +; So we should generalize the XDOC names and the documentation. +(defsection GPR-indices + + :parents (register-readers-and-writers) + + :short "Functions that enable the use of extended GPRs using the + @('rex') byte" + + (local (xdoc::set-default-parents GPR-indices)) + + (define reg-indexp + ((reg) + (rex-byte :type (unsigned-byte 8))) + :short "Valid GPR index recognizer" + :long "

General-purpose register indices are 3 bits except in +64-bit mode, where they can have 4 bits depending on the @('rex') +prefix.

" + :enabled t + (if (eql rex-byte 0) + (n03p reg) + (n04p reg)) + + /// + + (defthm reg-indexp-for-3-bits + (implies (and (syntaxp (quotep reg)) + (n03p reg)) + (reg-indexp reg rex))) + + (defthm reg-indexp-logand-7 + (reg-indexp (loghead 3 modr/m) rex-byte) + :hints (("Goal" :in-theory (enable reg-indexp))))) + + (define reg-index + ((reg :type (unsigned-byte 3) "Register index") + (rex-byte :type (unsigned-byte 8) "REX prefix") + (index :type (unsigned-byte 2) "One of the W, R, X, or B bits of the REX prefix")) + :inline t + :no-function t + :short "Using the REX prefix to access general-purpose registers" + :long "

In 64-bit mode, in addition to generating 64-bit operand sizes, + the REX prefix is used to reference registers R8 to R15. Instructions that + include REX prefixes can access these registers if the relevant W, R, X, or + B bit in the REX prefix is set. E.g., let R be the relevant bit in the REX + prefix and let R be set --- so @('index') = @(`*r*`) for this function. If + @('reg') = 0 (which, in the non-REX world, would refer to rAX), + @('reg-index') would give us the register index corresponding to the + register r8. If R is not set, @('reg-index') will give us the index + corresponding to rAX.

+ +

In 32-bit mode, the REX prefix is absent. This function can be used in + 32-bit mode, by passing 0 as REX.

" + + (if (logbitp index rex-byte) + (logior 8 (mbe :logic (n03 reg) :exec reg)) + (mbe :logic (n03 reg) :exec reg)) + + /// + + (local (in-theory (e/d (reg-indexp) ()))) + + (defthm reg-indexp-reg-index + (reg-indexp (reg-index reg rex-byte name) rex-byte)) + + (defthm-unsigned-byte-p n04p-reg-index + :hyp t + :bound 4 + :concl (reg-index reg rex-byte name) + :gen-linear t + :gen-type t) + + (defthm reg-indexp-forward + (implies (reg-indexp reg rex-byte) + (unsigned-byte-p 4 reg)) + :rule-classes :forward-chaining))) + +;; ---------------------------------------------------------------------- + +(define vex-vvvv-reg-index ((vvvv :type (unsigned-byte 4))) + :returns (index natp) + :parents (register-readers-and-writers) + :short "Register index specified by the VEX.vvvv bits." + :long + (xdoc::topstring + (xdoc::p + "The VEX.vvvv bits specify a register index + in inverted (i.e. ones' complement) form: + see Intel Manual Volume 2 Section 2.3.6 (Dec 2023). + We introduce this function to perform the ones' complement, + for greater abstraction.")) + (loghead 4 (lognot vvvv)) + /// + + (defthm-unsigned-byte-p n04p-of-vex-vvvv-reg-index + :hyp t + :bound 4 + :concl (vex-vvvv-reg-index vvvv) + :gen-linear t + :gen-type t)) + +;; ---------------------------------------------------------------------- + +;; [Jared] these rules broke something below +(local (in-theory (disable bitops::logext-of-logand + bitops::logext-of-logior))) + +(defsection GPRs-Reads-and-Writes + + :parents (register-readers-and-writers) + + :short "Functions to read/write 8/16/32/64 bits into the registers" + + :long "

@(see rr08), @(see rr16), @(see rr32), and @(see rr64) +will read the contents of the GPRs as natural numbers. Remember that +@('rgfi') will return an @(see i64p) value.

+ +

Here is an example:

+
+ +\(!rgfi 0 -1 x86\) ;; Write -1 to register 0 + + +

\(rr64 0 x86\) returns @('18446744073709551615') and +(rgfi 0 x86) returns @('-1'). Note that +@('18446744073709551615') is a bignum in CCL. This is precisely the +reason why we declared registers as @('i64p') instead of @('n64p'); +@('-1') would be stored as a bignum if the registers were +@('n64p').

+ +

Similarly, @(see wr08), @(see wr16), @(see wr32), and @(see wr64) +are used to write natural numbers into the GPRs.

" + + (local (xdoc::set-default-parents GPRs-Reads-and-Writes)) + + (define rr08 + ((reg :type (unsigned-byte 4)) + (rex :type (unsigned-byte 8)) + (x86)) + :inline t + :no-function t + :guard (reg-indexp reg rex) + :short "Read from byte general-purpose registers" + :long "

Source: Intel Manual Volume 1 Section 3.4.1.1 (Jun 2024) + (General-Purpose Registers in 64-bit Mode)

+ +
In 64-bit mode, there are limitations on accessing byte + registers. An instruction cannot reference legacy high-bytes (for example: AH, + BH, CH, DH) and one of the new byte registers at the same time (for example: + the low byte of the RAX register). However, instructions may reference legacy + low-bytes (for example: AL, BL, CL or DL) and new byte registers at the same + time (for example: the low byte of the R8 register, or R8L). The architecture + enforces this limitation by changing high-byte references (AH, BH, CH, DH) to + low byte references (BPL, SPL, DIL, SIL: the low 8 bits for RBP, RSP, RDI and + RSI) for instructions using a REX prefix.
+ +

In other words, without the REX prefix, indices 0-7 refer to byte registers + AL, CL, DL, BL, AH, CH, DH, and BH, whereas with the REX prefix, indices 0-15 + refer to AL, CL, DL, BL, SPL, BPL, SIL, DIL, R8L, R9L, R10L, R11L, R12L, R13L, + R14L, R15L. This applies to 64-bit mode.

+ +

In 32-bit mode, this function is called with 0 as REX.

" + + (b* ((reg (mbe :logic (nfix reg) :exec reg))) + (cond ((or (not (eql rex 0)) + (< reg 4)) + (let ((qword (the (signed-byte 64) (rgfi reg x86)))) + (n08 qword))) + (t ;; no rex and reg is at least 4 -- then read from AH, etc. + (let ((qword + (the (signed-byte 64) + (rgfi (the (unsigned-byte 4) (- reg 4)) x86)))) + (mbe :logic (part-select qword :low 8 :width 8) + :exec (n08 (ash qword -8))))))) + + /// + + (defthm-unsigned-byte-p n08p-rr08 + :hyp t + :bound 8 + :concl (rr08 reg rex x86) + :gen-linear t + :gen-type t)) + + (define wr08 + ((reg :type (unsigned-byte 4)) + (rex :type (unsigned-byte 8)) + (byte :type (unsigned-byte 8)) + (x86)) + :inline t + :no-function t + :guard (reg-indexp reg rex) + :guard-hints (("Goal" :in-theory (e/d ( + loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + :short "Writing to byte general-purpose registers" + :long "

Note Intel Manual Volume 1 Section 3.4.1.1 (Jun 2024), + which says the following about 64-bit mode:

+ +

8-bit and 16-bit operands generate an 8-bit or 16-bit result. The + upper 56 or 48 bits (respectively) of the destination general-purpose + register are not modified by the operation.

+ +

This is also confirmed by AMD manual, Jun'15, Vol. 3, App. B.1, under + ‘No Extension of 8-Bit and 16-Bit Results’.

+ +

In 32-bit mode, the upper 32 bits are undefined, as specified by the + following quote from the same page as above:

+ +

Because the upper 32 bits of 64-bit general-purpose registers are + undefined in 32-bit modes, the upper 32 bits of any general-purpose register + are not preserved when switching from 64-bit mode to a 32-bit mode (to + protected mode or compatibility mode). Software must not depend on these + bits to maintain a value after a 64-bit to 32-bit mode switch.

+ +

This function is used both in 64-bit mode and in 32-bit mode. Since in + 32-bit mode the high 32 bits of general-purpose registers are not + accessible, it is fine for this function to leave those bits unchanged, as + opposed to, for example, setting them to undefined values as done by the + semantic functions of certain instructions for certain flags. This way, in + this function, we can treat 32-bit and 64-bit the same, without a case + split. Note that the switching from 32-bit mode to 64-bit mode (when + modeled) will set the high 32 bits of general-purpose registers to undefined + values.

" + + (b* ((reg (mbe :logic (nfix reg) :exec reg))) + (cond ((or (not (eql rex 0)) + (< reg 4)) + (let ((qword (the (signed-byte 64) (rgfi reg x86)))) + (!rgfi reg + (n64-to-i64 + (mbe :logic + (part-install + byte + (part-select qword :low 0 :width 64) + :low 0 :width 8) + :exec + (the (unsigned-byte 64) + (logior (the (unsigned-byte 64) + (logand #xffffffffffffff00 qword)) + byte)))) + x86))) + (t ;; no rex and reg is at least 4 -- then write to AH, etc. + (let* ((index (the (unsigned-byte 4) + (- (the (unsigned-byte 4) reg) 4))) + (qword (the (signed-byte 64) (rgfi index x86)))) + (!rgfi index + (n64-to-i64 + (mbe :logic + (part-install + byte + (part-select qword :low 0 :width 64) + :low 8 :width 8) + :exec + (the (unsigned-byte 64) + (logior (the (unsigned-byte 64) + (logand #xffffffffffff00ff qword)) + (the (unsigned-byte 16) (ash byte 8)))))) + x86))))) + + /// + + (defthm x86p-wr08 + (implies (x86p x86) + (x86p (wr08 reg rex byte x86))))) + + (encapsulate + () + + (local + (include-book "arithmetic-5/top" :dir :system)) + + (defthm loghead-logtail-logext-for-rr08/wr08 + (implies (integerp x) + (equal (loghead 8 (logtail 8 (logext 64 x))) + (loghead 8 (logtail 8 x)))) + :hints (("Goal" :in-theory + (e/d (logtail evenp oddp logbitp logext loghead logapp) + ()))))) + + (defthm rr08-wr08-same + (equal (rr08 reg rex (wr08 reg rex byte x86)) + (loghead 8 byte)) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 + rr08 wr08) + (unsigned-byte-p + (force) force))))) + + (defthm rr08-wr08-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rr08 reg1 rex1 (wr08 reg2 rex2 byte x86)) + (rr08 reg1 rex1 x86))) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 rr08 wr08) + (force (force)))))) + + (define rr16 + ((reg :type (unsigned-byte 4)) + (x86)) + :inline t + :no-function t + :short "Read from word general-purpose registers" + + (n16 (the (signed-byte 64) (rgfi reg x86))) + + /// + + (defthm-unsigned-byte-p n16p-rr16 + :hyp t + :bound 16 + :concl (rr16 reg x86) + :gen-linear t + :gen-type t)) + + (define wr16 + ((reg :type (unsigned-byte 4)) + (val :type (unsigned-byte 16)) + (x86)) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d ( + loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + :short "Write to word general-purpose registers" + :long "

Note Intel Vol. 1 Sec. 3.4.1.1 + p. 3-17, which says the following about 64-bit mode:

+ +

8-bit and 16-bit operands generate an 8-bit or 16-bit result. The + upper 56 or 48 bits (respectively) of the destination general-purpose + register are not modified by the operation.

+ +

This is also confirmed by AMD manual, Jun'15, Vol. 3, App. B.1, under + ‘No Extension of 8-Bit and 16-Bit Results’.

+ +

In 32-bit mode, the upper 32 bits are undefined, as specified by the + following quote from the same page as above:

+ +

Because the upper 32 bits of 64-bit general-purpose registers are + undefined in 32-bit modes, the upper 32 bits of any general-purpose register + are not preserved when switching from 64-bit mode to a 32-bit mode (to + protected mode or compatibility mode). Software must not depend on these + bits to maintain a value after a 64-bit to 32-bit mode switch.

+ +

This function is used both in 64-bit mode and in 32-bit mode. Since in + 32-bit mode the high 32 bits of general-purpose registers are not + accessible, it is fine for this function to leave those bits unchanged, as + opposed to, for example, setting them to undefined values as done by the + semantic functions of certain instructions for certain flags. This way, in + this function, we can treat 32-bit and 64-bit the same, without a case + split. Note that the switching from 32-bit mode to 64-bit mode (when + modeled) will set the high 32 bits of general-purpose registers to undefined + values.

" + + (let ((qword (the (signed-byte 64) (rgfi reg x86)))) + (!rgfi reg + (n64-to-i64 + (mbe :logic + (part-install + val + (part-select qword :low 0 :width 64) + :low 0 :width 16) + :exec + (the (unsigned-byte 64) + (logior (the (unsigned-byte 64) + (logand qword #xffffffffffff0000)) + val)))) + x86)) + + /// + + (defthm x86p-wr16 + (implies (x86p x86) + (x86p (wr16 reg val x86))))) + + (defthm rr16-wr16-same + (equal (rr16 reg (wr16 reg val x86)) + (loghead 16 val)) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 + rr16 wr16) + (unsigned-byte-p force (force)))))) + + (defthm rr16-wr16-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rr16 reg1 (wr16 reg2 val x86)) + (rr16 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 rr16 wr16) + (force (force)))))) + + (define rr32 + ((reg :type (unsigned-byte 4)) + (x86)) + :inline t + :no-function t + :short "Read from doubleword general-purpose registers" + + (n32 (the (signed-byte 64) (rgfi reg x86))) + + /// + + (defthm-unsigned-byte-p n32p-rr32 + :hyp t + :bound 32 + :concl (rr32 reg x86) + :gen-linear t + :gen-type t)) + + (define wr32 + ((reg :type (unsigned-byte 4)) + (val :type (unsigned-byte 32)) + (x86)) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d ( + loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + + :short "Write to doubleword general-purpose registers" + :long "

Note Intel Vol. 1 Sec. 3.4.1.1 + p. 3-17, which says the following about 64-bit mode:

+ +

32-bit operands generate a 32-bit result, zero-extended to a 64-bit + result in the destination general-purpose register.

+ +

This is also confirmed by AMD manual, Jun'15, Vol. 3, App. B.1, under `No + Extension of 8-Bit and 16-Bit Results'.

+ +

In 32-bit mode, the upper 32 bits are undefined, as specified by the + following quote from the same page as above:

+ +

Because the upper 32 bits of 64-bit general-purpose registers are + undefined in 32-bit modes, the upper 32 bits of any general-purpose register + are not preserved when switching from 64-bit mode to a 32-bit mode (to + protected mode or compatibility mode). Software must not depend on these + bits to maintain a value after a 64-bit to 32-bit mode switch.

+ +

This function is used both in 64-bit mode and in 32-bit mode. Since in + 32-bit mode the high 32 bits of general-purpose registers are not + accessible, it is fine for this function to set those bits to 0, as opposed + to, for example, setting them to undefined values as done by the semantic + functions of certain instructions for certain flags. This way, in this + function, we can treat 32-bit and 64-bit the same, without a case + split. Note that the switching from 32-bit mode to 64-bit mode (when + modeled) will set the high 32 bits of general-purpose registers to undefined + values.

" + + (!rgfi reg (mbe :logic (n32 val) :exec val) x86) + + /// + + (defthm x86p-wr32 + (implies (x86p x86) + (x86p (wr32 reg val x86))))) + + (defthm rr32-wr32-same + (equal (rr32 reg (wr32 reg val x86)) + (loghead 32 val)) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 + rr32 wr32) + (unsigned-byte-p))))) + + (defthm rr32-wr32-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rr32 reg1 (wr32 reg2 val x86)) + (rr32 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 rr32 wr32) + ())))) + + (define rr64 + ((reg :type (unsigned-byte 4)) + (x86)) + :inline t + :no-function t + :short "Read from quadword general-purpose registers" + :long "

This function is used only in 64-bit mode.

" + + (n64 (the (signed-byte 64) (rgfi reg x86))) + + /// + + (defthm-unsigned-byte-p n64p-rr64 + :hyp t + :bound 64 + :concl (rr64 reg x86) + :gen-linear t + :gen-type t)) + + (define wr64 + ((reg :type (unsigned-byte 4)) + (val :type (unsigned-byte 64)) + (x86)) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d ( + loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + (b* ((x86 (!rgfi reg (n64-to-i64 val) x86))) + x86) + :short "Write to quadword general-purpose registers" + :long "

This function is used only in 64-bit mode.

" + + /// + (defthm x86p-wr64 + (implies (x86p x86) + (x86p (wr64 reg val x86))))) + + (defthm rr64-wr64-same + (equal (rr64 reg (wr64 reg val x86)) + (loghead 64 val)) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 + rr64 wr64) + (unsigned-byte-p))))) + + (defthm rr64-wr64-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rr64 reg1 (wr64 reg2 val x86)) + (rr64 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (n64-to-i64 rr64 wr64) + ())))) + + (define rgfi-size + ((nbytes :type (unsigned-byte 4)) + (index :type (unsigned-byte 4)) + (rex :type (unsigned-byte 8)) + x86) + :enabled t + :guard (and (reg-indexp index rex) + (member nbytes '(1 2 4 8))) + :inline t + :no-function t + :returns (val natp :rule-classes :type-prescription) + :short "Read form byte, word, doubleword, or quadword + general-purpose register" + (case nbytes + (1 (rr08 index rex x86)) + (2 (rr16 index x86)) + (4 (rr32 index x86)) + (8 (rr64 index x86)) + (otherwise + ;; This function shouldn't really be used in the case when nbytes + ;; != 1, 2, 4, or 8. Anyway, the guard says nbytes shouldn't be + ;; anything else. + 0))) + + (encapsulate () + (local (include-book "kestrel/arithmetic-light/expt" :dir :system)) + (defthm rgfi-size-linear + (< (rgfi-size nbytes index rex x86) (expt 2 (* 8 nbytes))) + :rule-classes :linear + :hints (("Goal" :in-theory (enable rgfi-size))))) + + (define !rgfi-size + ((nbytes :type (unsigned-byte 4)) + (index :type (unsigned-byte 4)) + (val :type integer) + (rex :type (unsigned-byte 8)) + x86) + :enabled t + :guard (and (reg-indexp index rex) + (member nbytes '(1 2 4 8)) + (unsigned-byte-p (ash nbytes 3) val)) + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (x86p))))) + :inline t + :no-function t + :short "Write to byte, word, doubleword, or quadword + general-purpose register" + (case nbytes + (1 (wr08 index rex val x86)) + (2 (wr16 index val x86)) + (4 (wr32 index val x86)) + (8 (wr64 index val x86)) + (otherwise + ;; The guard says nbytes shouldn't be anything other than 1, 2, + ;; 4, or 8. + x86)))) + +;; ---------------------------------------------------------------------- + +(defsection MMX-Registers-Reads-and-Writes + + :parents (register-readers-and-writers) + + :short "Functions to read/write into the MMX registers" + + :long "

From Section 12.2, Intel Manual, Volume 3 \(System + Programming\):

+ +

The MMX state consists of eight 64-bit registers \(MM0 +through MM7\). These registers are aliased to the low 64-bits \(bits 0 +through 63\) of floating-point registers R0 through R7 \(see Figure +12-1\). Note that the MMX registers are mapped to the physical +locations of the floating-point registers \(R0 through R7\), not to +the relative locations of the registers in the floating-point register +stack \(ST0 through ST7\). As a result, the MMX register mapping is +fixed and is not affected by value in the Top Of Stack \(TOS\) field +in the floating-point status word \(bits 11 through 13\).

+ +

From Section 12.2, Intel Manual, Volume 3 \(System Programming\)

: + +

When a value is written into an MMX register using an MMX +instruction, the value also appears in the corresponding +floating-point register in bits 0 through 63. Likewise, when a +floating-point value written into a floating-point register by a x87 +FPU, the low 64 bits of that value also appears in a the corresponding +MMX register.

+ +

The execution of MMX instructions have several side effects on +the x87 FPU state contained in the floating-point registers, the x87 +FPU tag word, and the x87 FPU status word. These side effects are as +follows:

+ +

* When an MMX instruction writes a value into an MMX register, +at the same time, bits 64 through 79 of the corresponding +floating-point register are set to all 1s.

+ +

* When an MMX instruction \(other than the EMMS instruction\) is +executed, each of the tag fields in the x87 FPU tag word is set to 00B +\(valid\). \(See also Section 12.2.1, Effect of MMX, x87 FPU, FXSAVE, +and FXRSTOR Instructions on the x87 FPU Tag Word.\)

+ +

* When the EMMS instruction is executed, each tag field in the +x87 FPU tag word is set to 11B \(empty)\.

+ +

* Each time an MMX instruction is executed, the TOS value is +set to 000B. Execution of MMX instructions does not affect the other +bits in the x87 FPU status word \(bits 0 through 10 and bits 14 and +15\) or the contents of the other x87 FPU registers that comprise the +x87 FPU state \(the x87 FPU control word, instruction pointer, data +pointer, or opcode registers\).

" + + (local (xdoc::set-default-parents MMX-Registers-Reads-and-Writes)) + + (define mmx + ((i :type (integer 0 7)) + (x86)) + :inline t + :no-function t + (let ((reg80 (the (unsigned-byte 80) (fp-datai i x86)))) + (mbe :logic (part-select reg80 :low 0 :width 64) + :exec (logand #.*2^64-1* reg80))) + + /// + + (defthm-unsigned-byte-p n64p-mmx + :hyp t + :bound 64 + :concl (mmx i x86) + :gen-type t + :gen-linear t)) + + (define !mmx + ((i :type (integer 0 7)) + (v :type (unsigned-byte 64)) + (x86)) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d () + (unsigned-byte-p)))) + + (let ((val80 (mbe :logic (part-install #xFFFF v :low 64 :high 79) + :exec (the (unsigned-byte 80) + (logior #uxFFFF_00000000_00000000 v))))) + (!fp-datai i val80 x86)) + + /// + + (defthm x86p-!mmx + (implies (x86p x86) + (x86p (!mmx i v x86))) + :hints (("Goal" :in-theory (e/d () (force (force))))))) + + (define mmx-instruction-updates (x86) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d (unsigned-byte-p-when-fp-statusbits-p) + ()))) + :short "We set the FPU tags and the TOS field + to 00B \(valid\) and 000B respectively." + :long + (xdoc::topstring + (xdoc::p + "This function accounts for the effects of + all MMX instructions except EMMS. + The settting of the FPU tags is described in + Intel manual Volume 1 (Feb 2026) Section 9.5.1. + The setting of the TOS field of the status register is described in + Intel manual Volume 3 (Feb 2026) Section 15.2.")) + (b* ((x86 (!fp-tag 0 x86)) + (fp-status (fp-status x86)) + (x86 (!fp-status (!fp-statusBits->top 0 fp-status) x86))) + x86) + + /// + + (defthm x86p-mmx-instruction-updates + (implies (x86p x86) + (x86p (mmx-instruction-updates x86)))))) + +;; ---------------------------------------------------------------------- + +(defsection ZMMs-Reads-and-Writes + + :parents (register-readers-and-writers) + + :short "Functions to read/write 32/64/128/256/512 bits into the + XMM/YMM/ZMM registers" + + :long "

Source: Intel Vol. 1, Section 15.5: ACCESSING XMM, YMM AND ZMM + REGISTERS

+ +
The lower 128 bits of a YMM register is aliased to the + corresponding XMM register. Legacy SSE instructions (i.e., SIMD + instructions operating on XMM state but not using the VEX prefix, + also referred to non-VEX encoded SIMD instructions) will not access + the upper bits (MAXVL-1:128) of the YMM registers. AVX and FMA + instructions with a VEX prefix and vector length of 128-bits zeroes + the upper 128 bits of the YMM register.
+ +
Upper bits of YMM registers (255:128) can be read and + written to by many instructions with a VEX.256 prefix. XSAVE and + XRSTOR may be used to save and restore the upper bits of the YMM + registers.
+ +
The lower 256 bits of a ZMM register are aliased to the + corresponding YMM register. Legacy SSE instructions (i.e., SIMD + instructions operating on XMM state but not using the VEX prefix, + also referred to non-VEX encoded SIMD instructions) will not access + the upper bits (MAXVL-1:128) of the ZMM registers, where MAXVL is + maximum vector length (currently 512 bits). AVX and FMA instructions + with a VEX prefix and vector length of 128-bits zero the upper 384 + bits of the ZMM register, while the VEX prefix and vector length of + 256-bits zeroes the upper 256 bits of the ZMM register. Upper bits + of ZMM registers (511:256) can be read and written to by instructions + with an EVEX.512 prefix.
+ +

@(see rz32), @(see rz64), @(see rz128), @(see rz256), and @(see + rz512) will read the contents of the ZMMs as natural numbers.

+ +

Similarly, @(see wz32), @(see wz64), @(see wz128), @(see wz256), + and @(see wz512) are used to write natural numbers into the + ZMMs.

" + + (local (xdoc::set-default-parents ZMMs-Reads-and-Writes)) + + (define rz32 + ((reg :type (unsigned-byte 5)) + (x86)) + :inline t + :no-function t + + (n32 (the (unsigned-byte 512) (zmmi reg x86))) + + /// + + (defthm-unsigned-byte-p n32p-rz32 + :hyp t + :bound 32 + :concl (rz32 reg x86) + :gen-linear t + :gen-type t)) + + (define rz64 + ((reg :type (unsigned-byte 5)) + (x86)) + :inline t + :no-function t + + (n64 (the (unsigned-byte 512) (zmmi reg x86))) + + /// + + (defthm-unsigned-byte-p n64p-rz64 + :hyp t + :bound 64 + :concl (rz64 reg x86) + :gen-linear t + :gen-type t)) + + (define rz128 + ((reg :type (unsigned-byte 5)) + (x86)) + :inline t + :no-function t + + (n128 (the (unsigned-byte 512) (zmmi reg x86))) + + /// + + (defthm-unsigned-byte-p n128p-rz128 + :hyp t + :bound 128 + :concl (rz128 reg x86) + :gen-linear t + :gen-type t)) + + (define rz256 + ((reg :type (unsigned-byte 5)) + (x86)) + :inline t + :no-function t + + (n256 (the (unsigned-byte 512) (zmmi reg x86))) + + /// + + (defthm-unsigned-byte-p n256p-rz256 + :hyp t + :bound 256 + :concl (rz256 reg x86) + :gen-linear t + :gen-type t)) + + (define rz512 + ((reg :type (unsigned-byte 5)) + (x86)) + :inline t + :no-function t + + (n512 (the (unsigned-byte 512) (zmmi reg x86))) + + /// + + (local (in-theory (e/d () (force (force))))) + + (defthm-unsigned-byte-p n512p-rz512 + :hyp t + :bound 512 + :concl (rz512 reg x86) + :gen-linear t + :gen-type t)) + + (define vector-access-type-p (x) + :returns (ok? booleanp :rule-classes :type-prescription) + :enabled t + (or (equal x #.*xmm-access*) + (equal x #.*vex-xmm-access*) + (equal x #.*ymm-access*) + (equal x #.*zmm-access*))) + + (define wz32 + ((reg :type (unsigned-byte 5)) + (val :type (unsigned-byte 32)) + (x86) + &key + ((regtype vector-access-type-p) '*zmm-access*)) + :short "Write @('val') to low 32 bits of a ZMM register" + :long "

Upper bits: For XMM registers, upper @(`(- 512 + 128)`) bits are preserved if @('regtype') is @('*xmm-access*'); + for @('*vex-xmm-access*'), these bits are zeroed out. For + @('*ymm-access*'), upper @(`(- 512 256)`) bits are zeroed + out. For @('*zmm-access*'), no upper bits are zeroed out.

" + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d (loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + + (b* ((data (the (unsigned-byte 512) (zmmi reg x86))) + (regtype (the (unsigned-byte 3) regtype)) + (data (case regtype + (#.*vex-xmm-access* + (loghead 128 data)) + (#.*ymm-access* + (loghead 256 data)) + (otherwise + ;; Preserve upper bits. + data))) + (val (n32 (the (unsigned-byte 32) val)))) + (!zmmi reg (part-install val data :low 0 :width 32) x86)) + + /// + + (local (in-theory (e/d () (force (force))))) + + (defthm x86p-wz32 + (implies (x86p x86) + (x86p (wz32 reg val x86 :regtype access))))) + + (defthm rz32-wz32-same + (equal (rz32 reg (wz32 reg val x86 :regtype access)) + (loghead 32 val)) + :hints (("Goal" + :in-theory (e/d (rz32 wz32) + (unsigned-byte-p + force (force)))))) + + (defthm rz32-wz32-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rz32 reg1 (wz32 reg2 val x86 :regtype access)) + (rz32 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (rz32 wz32) + (force (force)))))) + + (define wz64 + ((reg :type (unsigned-byte 5)) + (val :type (unsigned-byte 64)) + (x86) + &key + ((regtype vector-access-type-p) '*zmm-access*)) + :short "Write @('val') to low 64 bits of a ZMM register" + :long "

Upper bits: For XMM registers, upper @(`(- 512 + 128)`) bits are preserved if @('regtype') is @('*xmm-access*'); + for @('*vex-xmm-access*'), these bits are zeroed out. For + @('*ymm-access*'), upper @(`(- 512 256)`) bits are zeroed + out. For @('*zmm-access*'), no upper bits are zeroed out.

" + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d (loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + (b* ((data (the (unsigned-byte 512) (zmmi reg x86))) + (regtype (the (unsigned-byte 3) regtype)) + (data (case regtype + (#.*vex-xmm-access* + (loghead 128 data)) + (#.*ymm-access* + (loghead 256 data)) + (otherwise + ;; Preserve upper bits. + data))) + (val (the (unsigned-byte 64) (n64 val)))) + (!zmmi reg (part-install val data :low 0 :width 64) x86)) + + /// + + (local (in-theory (e/d () (force (force))))) + + (defthm x86p-wz64 + (implies (x86p x86) + (x86p (wz64 reg val x86 :regtype access))))) + + (defthm rz64-wz64-same + (equal (rz64 reg (wz64 reg val x86 :regtype access)) + (loghead 64 val)) + :hints (("Goal" + :in-theory (e/d (rz64 wz64) + (unsigned-byte-p + force (force)))))) + + (defthm rz64-wz64-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rz64 reg1 (wz64 reg2 val x86 :regtype access)) + (rz64 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (rz64 wz64) + (force (force)))))) + + (define wz128 + ((reg :type (unsigned-byte 5)) + (val :type (unsigned-byte 128)) + (x86) + &key + ((regtype vector-access-type-p) '*zmm-access*)) + :short "Write @('val') to low 128 bits of a ZMM register" + :long "

Upper bits: For XMM registers, upper @(`(- 512 + 128)`) bits are preserved if @('regtype') is @('*xmm-access*'); + for @('*vex-xmm-access*'), these bits are zeroed out. For + @('*ymm-access*'), upper @(`(- 512 256)`) bits are zeroed + out. For @('*zmm-access*'), no upper bits are zeroed out.

" + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d (loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + + (b* ((data (the (unsigned-byte 512) (zmmi reg x86))) + (regtype (the (unsigned-byte 3) regtype)) + (data (case regtype + (#.*vex-xmm-access* + (loghead 128 data)) + (#.*ymm-access* + (loghead 256 data)) + (otherwise + ;; Preserve upper bits. + data))) + (val (the (unsigned-byte 128) (n128 val)))) + (!zmmi reg (part-install val data :low 0 :width 128) x86)) + + /// + + (local (in-theory (e/d () (force (force))))) + + (defthm x86p-wz128 + (implies (x86p x86) + (x86p (wz128 reg val x86 :regtype access))))) + + (defthm rz128-wz128-same + (equal (rz128 reg (wz128 reg val x86 :regtype access)) + (loghead 128 val)) + :hints (("Goal" + :in-theory (e/d (rz128 wz128) + (unsigned-byte-p + force (force)))))) + + (defthm rz128-wz128-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rz128 reg1 (wz128 reg2 val x86 :regtype access)) + (rz128 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (rz128 wz128) + (force (force)))))) + + (define wz256 + ((reg :type (unsigned-byte 5)) + (val :type (unsigned-byte 256)) + (x86) + &key + ((regtype vector-access-type-p) '*zmm-access*)) + + :short "Write @('val') to low 256 bits of a ZMM register." + :long "

Upper bits: For @('*ymm-access*'), upper @(`(- + 512 256)`) bits are zeroed out. For @('*zmm-access*'), no upper + bits are zeroed out.

" + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d (loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + + (b* ((data (the (unsigned-byte 512) (zmmi reg x86))) + (regtype (the (unsigned-byte 3) regtype)) + (data (case regtype + (#.*ymm-access* + (loghead 256 data)) + (otherwise + ;; Preserve upper bits. + data))) + (val (the (unsigned-byte 256) (n256 val)))) + (!zmmi reg (part-install val data :low 0 :width 256) x86)) + + /// + + (local (in-theory (e/d () (force (force))))) + + (defthm x86p-wz256 + (implies (x86p x86) + (x86p (wz256 reg val x86 :regtype access))))) + + (defthm rz256-wz256-same + (equal (rz256 reg (wz256 reg val x86 :regtype access)) + (loghead 256 val)) + :hints (("Goal" + :in-theory (e/d (rz256 wz256) + (unsigned-byte-p + force (force)))))) + + (defthm rz256-wz256-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rz256 reg1 (wz256 reg2 val x86 :regtype access)) + (rz256 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (rz256 wz256) + (force (force)))))) + + (define wz512 + ((reg :type (unsigned-byte 5)) + (val :type (unsigned-byte 512)) + (x86)) + :short "Write @('val') to 512 bits of a ZMM register." + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d (loghead-to-logand + bitops::logsquash) + (bitops::logand-with-negated-bitmask + bitops::logand-with-bitmask + unsigned-byte-p)))) + + (let ((val (the (unsigned-byte 512) (n512 val)))) + (!zmmi reg val x86)) + + /// + + (local (in-theory (e/d () (force (force))))) + + (defthm x86p-wz512 + (implies (x86p x86) + (x86p (wz512 reg val x86))))) + + (defthm rz512-wz512-same + (equal (rz512 reg (wz512 reg val x86)) + (loghead 512 val)) + :hints (("Goal" + :in-theory (e/d (rz512 wz512) + (unsigned-byte-p + force (force)))))) + + (defthm rz512-wz512-different + (implies (not (equal (nfix reg1) (nfix reg2))) + (equal (rz512 reg1 (wz512 reg2 val x86)) + (rz512 reg1 x86))) + :hints (("Goal" + :in-theory (e/d (rz512 wz512) + (force (force)))))) + + (define zmmi-size + ((nbytes :type (unsigned-byte 7)) + (index :type (unsigned-byte 5)) + x86) + :enabled t + :guard (member nbytes '(4 8 16 32 64)) + :inline t + :no-function t + :returns (val natp :rule-classes :type-prescription) + (case nbytes + (4 (rz32 index x86)) + (8 (rz64 index x86)) + (16 (rz128 index x86)) + (32 (rz256 index x86)) + (64 (rz512 index x86)) + (otherwise + 0))) + + (define !zmmi-size + ((nbytes :type (unsigned-byte 7)) + (index :type (unsigned-byte 5)) + (val :type integer) + x86 + &key + ((regtype vector-access-type-p) '*zmm-access*)) + :short "Write @('val') to low @('nbytes') of a ZMM register" + :long "

Upper bits: For XMM registers, upper @(`(- 512 + 128)`) bits are preserved if @('regtype') is @('*xmm-access*'); + for @('*vex-xmm-access*'), these bits are zeroed out. For + @('*ymm-access*'), upper @(`(- 512 256)`) bits are zeroed + out. For @('*zmm-access*'), no upper bits are zeroed out.

" + :enabled t + :guard (and (member nbytes '(4 8 16 32 64)) + (unsigned-byte-p (ash nbytes 3) val)) + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (x86p))))) + :inline t + :no-function t + (case nbytes + (4 (wz32 index val x86 :regtype regtype)) + (8 (wz64 index val x86 :regtype regtype)) + (16 (wz128 index val x86 :regtype regtype)) + (32 (wz256 index val x86 :regtype regtype)) + (64 (wz512 index val x86)) + (otherwise + x86)))) + +(defsection CTR-Reads-and-Writes + :parents (register-readers-and-writers) + :short "Functions to read/write into the control registers" + + (local (xdoc::set-default-parents CTR-Reads-and-Writes)) + + (define !ctri-write ((ctr-index natp) + (val n64p) + x86) + + :returns (x86 x86p :hyp (x86p x86)) + :guard (< ctr-index #.*control-register-names-len*) + + (b* ((val-write (case ctr-index + (*CR0* (loghead 32 val)) + ;; All but the low 21 bits of CR4 are reserved + (*CR4* (logapp 21 val (ctri *CR4* x86))) + (otherwise val))) + (x86 (!ctri ctr-index val-write x86))) + x86))) + +(defsection MSR-Reads-and-Writes + :parents (register-readers-and-writers) + :short "Functions to read/write into the MSRs" + + (local (xdoc::set-default-parents CTR-Reads-and-Writes)) + + (defun valid-msr-addr-p (msr-addr) + (declare (xargs :guard t)) + (member msr-addr '(#.*IA32_SYSENTER_CS* + #.*IA32_SYSENTER_ESP* + #.*IA32_SYSENTER_EIP* + #.*IA32_EFER* + #.*IA32_FS_BASE* + #.*IA32_GS_BASE* + #.*IA32_KERNEL_GS_BASE* + #.*IA32_STAR* + #.*IA32_LSTAR* + #.*IA32_FMASK* + #.*IA32_MISC_ENABLE*))) + + (defun msr-addr-to-index (msr-addr) + (declare (xargs :guard (valid-msr-addr-p msr-addr))) + (case msr-addr + (#.*IA32_SYSENTER_CS* #.*IA32_SYSENTER_CS-IDX*) + (#.*IA32_SYSENTER_ESP* #.*IA32_SYSENTER_ESP-IDX*) + (#.*IA32_SYSENTER_EIP* #.*IA32_SYSENTER_EIP-IDX*) + (#.*IA32_EFER* #.*IA32_EFER-IDX*) + (#.*IA32_FS_BASE* #.*IA32_FS_BASE-IDX*) + (#.*IA32_GS_BASE* #.*IA32_GS_BASE-IDX*) + (#.*IA32_KERNEL_GS_BASE* #.*IA32_KERNEL_GS_BASE-IDX*) + (#.*IA32_STAR* #.*IA32_STAR-IDX*) + (#.*IA32_LSTAR* #.*IA32_LSTAR-IDX*) + (#.*IA32_FMASK* #.*IA32_FMASK-IDX*) + (#.*IA32_MISC_ENABLE* #.*IA32_MISC_ENABLE-IDX*) + ;; Should not be possible due to the guard + (t -1))) + + (define msra ((msr-addr valid-msr-addr-p) + x86) + + :returns (msr-val n64p) + + (b* ((msr-index (msr-addr-to-index msr-addr))) + (msri msr-index x86))) + + (define !msra ((msr-addr valid-msr-addr-p) + (val :type (unsigned-byte 64)) + x86) + + :returns (x86 x86p :hyp (x86p x86)) + + (b* ((msr-index (msr-addr-to-index msr-addr))) + (!msri msr-index val x86)))) + + +(defsection XMMs-Reads-and-Writes + + :parents (ZMMs-Reads-and-Writes register-readers-and-writers) + + :short "Functions to read/write 32/64/128 bits into the XMM + registers (to be used by non-VEX encoded 128-bit SIMD instructions)" + + :long "

These functions are meant to be used by instructions that + do not use a VEX or EVEX prefix --- these functions preserve the + upper bits of ZMM registers. For instructions that use these + prefixes and zero out these bits instead, see @(see + ZMMs-Reads-and-Writes).

+ +

Note that the index for accessing the XMM registers is 4-bits + wide (as opposed to the 5-bit index for ZMM registers --- see @(see + ZMMs-Reads-and-Writes)) because only 16 XMM registers were supported + initially in the 64-bit mode (and 8 in the 32-bit mode).

+ +

Source: Intel Vol. 2, Section 2.3.10 --- AVX Instructions + and Upper 128-bits of YMM registers:

+ +
If an instruction with a destination XMM register is + encoded with a VEX prefix, the processor zeroes the upper + bits (above bit 128) of the equivalent YMM register. Legacy SSE + instructions without VEX preserve the upper bits.
+ +

Functions @(see rx32), @(see rx64), and @(see rx128) will read the + contents of the XMMs (i.e., low 128 bits of ZMMs) as natural + numbers.

+ +

Similarly, functions @(see wx32), @(see wx64), and @(see wx128) + are used to write natural numbers into the XMMs (and preserve the + upper bits of ZMMs).

" + + (local (xdoc::set-default-parents XMMs-Reads-and-Writes)) + + (define rx32 + ((reg :type (unsigned-byte 4)) + (x86)) + :inline t + :no-function t + :enabled t + (rz32 reg x86)) + + (define rx64 + ((reg :type (unsigned-byte 4)) + (x86)) + :inline t + :no-function t + :enabled t + (rz64 reg x86)) + + (define rx128 + ((reg :type (unsigned-byte 4)) + (x86)) + :inline t + :no-function t + :enabled t + (rz128 reg x86)) + + (define wx32 + ((reg :type (unsigned-byte 4)) + (val :type (unsigned-byte 32)) + (x86)) + :short "Write @('val') to low 32 bits of a ZMM register; upper + bits are preserved." + :inline t + :no-function t + :enabled t + (wz32 reg val x86 :regtype #.*xmm-access*)) + + (define wx64 + ((reg :type (unsigned-byte 4)) + (val :type (unsigned-byte 64)) + (x86)) + :short "Write @('val') to low 64 bits of a ZMM register; upper + bits are preserved." + :inline t + :no-function t + :enabled t + (wz64 reg val x86 :regtype #.*xmm-access*)) + + (define wx128 + ((reg :type (unsigned-byte 4)) + (val :type (unsigned-byte 128)) + (x86)) + :short "Write @('val') to low 128 bits of a ZMM register; upper + bits are preserved." + :inline t + :no-function t + :enabled t + (wz128 reg val x86 :regtype #.*xmm-access*)) + + (define xmmi-size + ((nbytes :type (unsigned-byte 5)) + (index :type (unsigned-byte 4)) + x86) + :enabled t + :guard (member nbytes '(4 8 16)) + :inline t + :no-function t + :returns (val natp :rule-classes :type-prescription) + (case nbytes + (4 (rx32 index x86)) + (8 (rx64 index x86)) + (16 (rx128 index x86)) + (otherwise + ;; This function shouldn't really be used in the case when nbytes + ;; != 4, 8, or 16. Anyway, the guard says nbytes shouldn't be + ;; anything else. + 0))) + + (define !xmmi-size + ((nbytes :type (unsigned-byte 5)) + (index :type (unsigned-byte 4)) + (val :type integer) + x86) + :short "Write @('val') to low @('nbytes') of an XMM register; + upper bits of the ZMM register are preserved." + :enabled t + :guard (and (member nbytes '(4 8 16)) + (unsigned-byte-p (ash nbytes 3) val)) + :returns (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (x86p))))) + :inline t + :no-function t + (case nbytes + (4 (wx32 index val x86)) + (8 (wx64 index val x86)) + (16 (wx128 index val x86)) + (otherwise + ;; This function shouldn't really be used in the case when nbytes + ;; != 4, 8, or 16. Anyway, the guard says nbytes shouldn't be + ;; anything else. + x86)))) + +;; ---------------------------------------------------------------------- + +(defsection characterizing-undefined-behavior + + :parents (machine) + + :short "An @('undef') field in the @('x86') state feeds unknown + values to processor components that are undefined" + + :long "

The @('undef') field is used to feed unknown values to +processor components that are undefined, as per the Intel +specifications. For example, the @('SF'), @('ZF'), @('AF'), and +@('PF') rflags are undefined after a @('MUL') instruction is +executed.

+ +

The principle behind the @('undef') field is quite like that of the +@('oracle') sub-field of the @('env') field \(see @(see +environment-field)\). We describe our use of the @('undef') field by +comparing it to the @('oracle') sub-field.

+ +

For reasoning about programs that involve commonly occurring +\"undefined events\" \(like flag computations\), using the @('oracle') +sub-field can be quite tedious, since it has to be carefully +initialized; i.e., a list of appropriate \(symbolic or concrete\) +values has to be associated with the instruction pointer where any +such undefined event occurs. Imagine doing that for @('SF'), @('ZF'), +@('AF'), and @('PF') every time a @('MUL') instruction is executed. +The reason why we need this initialization is because the only way to +access the @('oracle') is through the functions @(see pop-x86-oracle) +and @(see env-read); @('pop-x86-oracle') expects the @('oracle') to +contain information in a specific format, and @('env-read') will give +us nothing unless we put something in to begin with.

+ +

On the other hand, the @('undef') field doesn't require any such +initialization. The @('undef') field contains a natural number that +is increased every time an undefined value is pulled for use \(using +the constrained function @('create-undef')\) from a pool of undefined +values; thus, every access of the @('undef') field causes it to +contain a new value which is used to seed a unique undefined +value. See @(see undef-read) for details.

+ +

There is a reason why we enforced that tediousness in the case of +the @('oracle') sub-field: it provides a way of tracking any +computation that relies on the @('env') field. Such computations don't +happen often, and when they do, it'd probably be better if we knew +exactly what we are expecting from the environment. Initializing the +@('oracle') is a way of expressing these expectations. However, in the +case of undefined values, we aren't really expecting anything from the +environment. All we want is a sort of infinite pool of arbitary +values, seeded from @('undef') in our case, that we don't know +anything about. As such, we wouldn't be able to prove that a value +obtained from @('undef') is equal \(or not\) to any other value, +either obtained from @('undef') or not. This is exactly what we need +when reasoning about undefined values --- an undefined value is +different from another undefined value, and also all the known +values.

" + + ) + +(encapsulate + ( ((create-undef *) => *) ) + + (local + (defun create-undef (x) + (nfix x))) + + (defthm integerp-create-undef + (integerp (create-undef x)) + :rule-classes (:rewrite :type-prescription)) + + (defthm natp-create-undef + (natp (create-undef x)) + :rule-classes (:rewrite :type-prescription))) + +(define unsafe-!undef (v x86) + + :long "

Note that @('unsafe-!undef') is enabled, not untouchable, + and non-executable. It can be used in proof attempts but not during + execution.

+ +

@('unsafe-!undef') should be used judiciously because updating the + @('undef') field with a value it held previously might contaminate + our 'pool of undefined values', i.e., @(see undef-read) might then + produce a call of @('create-undef') that collides with a previous + call of @('create-undef'), which would make the result of an + equality test between them equal instead of indeterminate.

+ +

An example of an acceptable use of @('unsafe-!undef') is to + specify the @('undef') field in a final x86 state during a proof + attempt.

" + + :non-executable t + :enabled t + :returns (x86 x86p :hyp (x86p x86)) + :parents (undef-read) + (!undef v x86)) + +(define undef-read-logic (x86) + :enabled t + :returns (mv (unknown natp :rule-classes :type-prescription) + (x86 x86p :hyp (x86p x86))) + :parents (undef-read) + + (b* ((undef-seed (nfix (undef x86))) + (new-unknown (create-undef undef-seed)) + (x86 (!undef (1+ undef-seed) x86))) + (mv new-unknown x86))) + +(define undef-read (x86) + ;; TO-DO@Shilpi: I'll need to add more args to this function if I + ;; need the corresponding raw Lisp function to have more info. + :inline nil + :enabled t + :returns (mv (unknown natp :rule-classes :type-prescription) + (x86 x86p :hyp (x86p x86))) + :parents (characterizing-undefined-behavior) + + :short "Get a unique unknown to be used when reasoning about + undefined values in the processor" + :long "

See @(see characterizing-undefined-behavior) for more + details.

+ +

The accessor and updater functions of the @('undef') field are + untouchable so that the only way to create a new seed for unknowns + is via this function.

" + + (undef-read-logic x86)) + +;; We make the following two functions untouchable so that they cannot +;; be used on their own outside function undef-read-logic. + +(push-untouchable + (!undef$inline) + t) + +;; ---------------------------------------------------------------------- + +(defsection rflags-Reads-and-Writes + :parents (rflag-specifications register-readers-and-writers) + :short "Reading from and writing to the @('rflags') register in the @('x86') state" + + :long "

We define convenient macros @('flgi') and @('!flgi') to read a + flag's value and to write a flag's value into the @('rflags') field in the + @('x86') state, respectively. Additionally, @('!flgi-undefined') can be + used to write an undefined value into a particular flag.

" + + (local (xdoc::set-default-parents rflags-Reads-and-Writes)) + + ;; Tips for doing flg RoW proofs: + ;; (thm (equal (RFLAGSBITS->CF (!rflagsbits->df df rflags)) + ;; (RFLAGSBITS->CF rflags)) + ;; ;; Need to enable the following rule for the flag being updated so that + ;; ;; the same kind of rule for the other one (RFLAGSBITS->CF-OF-RFLAGSBITS + ;; ;; here) can fire. + ;; :hints (("Goal" :in-theory (e/d (!RFLAGSBITS->DF-IS-RFLAGSBITS) + ;; ())))) + + ;; The following works out of the box. + ;; (thm (equal (RFLAGSBITS->CF (!rflagsbits->cf cf rflags)) + ;; (bfix cf))) + + (defmacro flgi (flg x86) + (declare (xargs :guard (keywordp flg))) + `(b* ((rflags (the (unsigned-byte 32) (rflags ,x86)))) + ,(case flg + (:cf '(rflagsBits->cf rflags)) + (:pf '(rflagsBits->pf rflags)) + (:af '(rflagsBits->af rflags)) + (:zf '(rflagsBits->zf rflags)) + (:sf '(rflagsBits->sf rflags)) + (:tf '(rflagsBits->tf rflags)) + (:if '(rflagsBits->intf rflags)) + (:df '(rflagsBits->df rflags)) + (:of '(rflagsBits->of rflags)) + (:iopl '(rflagsBits->iopl rflags)) + (:nt '(rflagsBits->nt rflags)) + (:rf '(rflagsBits->rf rflags)) + (:vm '(rflagsBits->vm rflags)) + (:ac '(rflagsBits->ac rflags)) + (:vif '(rflagsBits->vif rflags)) + (:vip '(rflagsBits->vip rflags)) + (:id '(rflagsBits->id rflags)) + (otherwise + (er hard 'flgi "~%FLGI: illegal flg keyword: ~x0.~%" flg))))) + + (defmacro !flgi (flg val x86) + (declare (xargs :guard (keywordp flg))) + `(b* ((rflags (the (unsigned-byte 32) (rflags ,x86))) + (new-rflags + (the (unsigned-byte 32) + ,(case flg + (:cf `(!rflagsBits->cf ,val rflags)) + (:pf `(!rflagsBits->pf ,val rflags)) + (:af `(!rflagsBits->af ,val rflags)) + (:zf `(!rflagsBits->zf ,val rflags)) + (:sf `(!rflagsBits->sf ,val rflags)) + (:tf `(!rflagsBits->tf ,val rflags)) + (:if `(!rflagsBits->intf ,val rflags)) + (:df `(!rflagsBits->df ,val rflags)) + (:of `(!rflagsBits->of ,val rflags)) + (:iopl `(!rflagsBits->iopl ,val rflags)) + (:nt `(!rflagsBits->nt ,val rflags)) + (:rf `(!rflagsBits->rf ,val rflags)) + (:vm `(!rflagsBits->vm ,val rflags)) + (:ac `(!rflagsBits->ac ,val rflags)) + (:vif `(!rflagsBits->vif ,val rflags)) + (:vip `(!rflagsBits->vip ,val rflags)) + (:id `(!rflagsBits->id ,val rflags)) + (otherwise + (er hard '!flgi "~%!FLGI: illegal flg keyword: ~x0.~%" flg)))))) + (!rflags new-rflags ,x86))) + + (define undef-flg-logic (x86) + :enabled t + :prepwork ((local (in-theory (e/d* () (undef-read))))) + :returns (mv (unknown natp :rule-classes :type-prescription) + (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (x86p)))))) + (undef-read x86)) + + (define undef-flg (x86) + ;; I have smashed this function under the hood. This is a tad more + ;; efficient than smashing just undef-read when flags are assigned + ;; undefined values because it helps us avoid calling n01 while + ;; execution. This saves one call to the builtin LOGAND that might + ;; create bignums, potentially. + :inline nil + :enabled t + :prepwork ((local (in-theory (e/d* () (undef-flg-logic))))) + :returns (mv (unknown-bit bitp :rule-classes :type-prescription) + (x86 x86p :hyp (x86p x86) + :hints (("Goal" :in-theory (e/d () (x86p)))))) + (b* (((mv val x86) + (undef-flg-logic x86))) + (mv (n01 val) x86))) + + (defmacro !flgi-undefined (flg x86) + (declare (xargs :guard (keywordp flg))) + `(b* ((rflags (the (unsigned-byte 32) (rflags ,x86))) + ((mv val x86) (undef-flg ,x86)) + (new-rflags + (the (unsigned-byte 32) + ,(case flg + (:cf '(!rflagsBits->cf val rflags)) + (:pf '(!rflagsBits->pf val rflags)) + (:af '(!rflagsBits->af val rflags)) + (:zf '(!rflagsBits->zf val rflags)) + (:sf '(!rflagsBits->sf val rflags)) + (:tf '(!rflagsBits->tf val rflags)) + (:if '(!rflagsBits->intf val rflags)) + (:df '(!rflagsBits->df val rflags)) + (:of '(!rflagsBits->of val rflags)) + (:iopl '(!rflagsBits->iopl val rflags)) + (:nt '(!rflagsBits->nt val rflags)) + (:rf '(!rflagsBits->rf val rflags)) + (:vm '(!rflagsBits->vm val rflags)) + (:ac '(!rflagsBits->ac val rflags)) + (:vif '(!rflagsBits->vif val rflags)) + (:vip '(!rflagsBits->vip val rflags)) + (:id '(!rflagsBits->id val rflags)) + (otherwise + (er hard '!flgi "~%!FLGI-UNDEFINED: illegal flg keyword: ~x0.~%" flg)))))) + (!rflags new-rflags ,x86))) + + (define write-user-rflags + ((user-flags-vector :type (unsigned-byte 32)) + (undefined-mask :type (unsigned-byte 32)) + x86) + + :inline t + :no-function t + + :short "Writing user rflags \(CF, PF, AF, ZF, SF, and OF\), + including undefined ones, to the x86 state" + + :long "

We set the undefined flags, which are indicated by + @('mask'), to the value returned by @(see undef-read).

" + + :guard-hints (("Goal" :in-theory (e/d (rflagsBits->cf + rflagsBits->pf + rflagsBits->af + rflagsBits->zf + rflagsBits->sf + rflagsBits->of + rflagsbits-fix) + (unsigned-byte-p + not + (tau-system))))) + :prepwork ((local (in-theory (e/d () + (bitops::logand-with-negated-bitmask + fty::unsigned-byte-p-1-when-bitp))))) + + :returns (x86 x86p :hyp (x86p x86)) + + (b* ((user-flags-vector + (mbe :logic (n32 user-flags-vector) :exec user-flags-vector)) + (undefined-mask + (mbe :logic (n32 undefined-mask) :exec undefined-mask)) + ((the (unsigned-byte 32) input-rflags) + (mbe :logic (n32 (rflags x86)) :exec (rflags x86)))) + + (mbe + :logic + (b* ((x86 (if (equal (rflagsBits->cf undefined-mask) 1) + (!flgi-undefined :cf x86) + (!flgi :cf (rflagsBits->cf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->pf undefined-mask) 1) + (!flgi-undefined :pf x86) + (!flgi :pf (rflagsBits->pf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->af undefined-mask) 1) + (!flgi-undefined :af x86) + (!flgi :af (rflagsBits->af user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->zf undefined-mask) 1) + (!flgi-undefined :zf x86) + (!flgi :zf (rflagsBits->zf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->sf undefined-mask) 1) + (!flgi-undefined :sf x86) + (!flgi :sf (rflagsBits->sf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->of undefined-mask) 1) + (!flgi-undefined :of x86) + (!flgi :of (rflagsBits->of user-flags-vector) x86)))) + x86) + :exec + (if (eql undefined-mask 0) + (b* ((x86 (!flgi :cf (rflagsBits->cf user-flags-vector) x86)) + (x86 (!flgi :pf (rflagsBits->pf user-flags-vector) x86)) + (x86 (!flgi :af (rflagsBits->af user-flags-vector) x86)) + (x86 (!flgi :zf (rflagsBits->zf user-flags-vector) x86)) + (x86 (!flgi :sf (rflagsBits->sf user-flags-vector) x86)) + (x86 (!flgi :of (rflagsBits->of user-flags-vector) x86))) + x86) + (b* ((x86 (if (equal (rflagsBits->cf undefined-mask) 1) + (!flgi-undefined :cf x86) + (!flgi :cf (rflagsBits->cf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->pf undefined-mask) 1) + (!flgi-undefined :pf x86) + (!flgi :pf (rflagsBits->pf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->af undefined-mask) 1) + (!flgi-undefined :af x86) + (!flgi :af (rflagsBits->af user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->zf undefined-mask) 1) + (!flgi-undefined :zf x86) + (!flgi :zf (rflagsBits->zf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->sf undefined-mask) 1) + (!flgi-undefined :sf x86) + (!flgi :sf (rflagsBits->sf user-flags-vector) x86))) + (x86 (if (equal (rflagsBits->of undefined-mask) 1) + (!flgi-undefined :of x86) + (!flgi :of (rflagsBits->of user-flags-vector) x86)))) + x86)))) + + /// + + (local (in-theory (e/d (undef-read) ()))) + + (defthm xr-write-user-rflags + (implies (and (not (equal fld :rflags)) + (not (equal fld :undef))) + (equal (xr fld index (write-user-rflags flags mask x86)) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm xr-write-user-rflags-no-mask + ;; Do we need this? + (implies (not (equal fld :rflags)) + (equal (xr fld index (write-user-rflags flags 0 x86)) + (xr fld index x86))) + :hints (("Goal" :in-theory (e/d* () (force (force)))))) + + (defthm rflags-and-write-user-rflags-no-mask + (equal (write-user-rflags user-flags-vector 0 x86) + (b* ((x86 (!flgi :cf (rflagsBits->cf user-flags-vector) x86)) + (x86 (!flgi :pf (rflagsBits->pf user-flags-vector) x86)) + (x86 (!flgi :af (rflagsBits->af user-flags-vector) x86)) + (x86 (!flgi :zf (rflagsBits->zf user-flags-vector) x86)) + (x86 (!flgi :sf (rflagsBits->sf user-flags-vector) x86)) + (x86 (!flgi :of (rflagsBits->of user-flags-vector) x86))) + x86)) + :hints (("Goal" :in-theory (e/d* (rflagsBits->cf + rflagsBits->pf + rflagsBits->af + rflagsBits->zf + rflagsBits->sf + rflagsBits->of + rflagsbits-fix) + (force (force)))))))) + + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/rflags-spec.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/rflags-spec.lisp new file mode 100644 index 000000000..f00a3b70d --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/rflags-spec.lisp @@ -0,0 +1,866 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "std/util/def-bound-theorems" :dir :system) +(include-book "../utils/utilities") +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ---------------------------------------------------------------------- + +(defsection rflag-specifications + :parents (machine) + :short "Specifications of @('rflags')" + ) + +;; ---------------------------------------------------------------------- + +(define general-cf-spec-fn (result-nbits raw-result) + :long "

General @('CF') Specification (Source: Intel Manuals, + Vol. 1, Section 3.4.3.1):

+ +

Carry flag Set if an arithmetic operation generates a +carry or a borrow out of the most-significant bit of the result; +cleared otherwise. This flag indicates an overflow condition for +unsigned-integer arithmetic. It is also used in multiple-precision +arithmetic.

" + :parents (rflag-specifications) + :inline t + :no-function t + :guard (and (natp result-nbits) + (natp raw-result)) + (acl2::bool->bit (not (unsigned-byte-p result-nbits raw-result))) + + /// + + (defthm-unsigned-byte-p n01p-general-cf-spec-fn + :bound 1 + :concl (general-cf-spec-fn result-nbits raw-result) + :gen-linear t + :gen-type t)) + +(define cf-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "CF-SPEC" result-nbits) + ((raw-result :type (unsigned-byte ,(1+ result-nbits)))) + :inline t + :no-function t + :parents (rflag-specifications) + (acl2::bool->bit (mbe :logic (not (unsigned-byte-p ,result-nbits raw-result)) + :exec (not (< raw-result ,(expt 2 result-nbits))))) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-CF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "CF-SPEC" result-nbits) raw-result) + :gen-linear t + :gen-type t))) + +(make-event (cf-spec-gen-fn 8)) +(make-event (cf-spec-gen-fn 16)) +(make-event (cf-spec-gen-fn 32)) +(make-event (cf-spec-gen-fn 64)) + +(defmacro general-cf-spec (result-nbits raw-result) + (cond ((eql result-nbits 8) + `(cf-spec8 ,raw-result)) + ((eql result-nbits 16) + `(cf-spec16 ,raw-result)) + ((eql result-nbits 32) + `(cf-spec32 ,raw-result)) + ((eql result-nbits 64) + `(cf-spec64 ,raw-result)) + (t + `(general-cf-spec-fn ,result-nbits ,raw-result)))) + +(add-macro-alias general-cf-spec general-cf-spec-fn) + +;; ---------------------------------------------------------------------- + +(define general-of-spec-fn (result-nbits signed-raw-result) + :guard (and (natp result-nbits) + (integerp signed-raw-result)) + :long "

General @('OF') Specification (Source: Intel Manuals, + Vol. 1, Section 3.4.3.1):

+ +

Overflow flag Set if the integer result is too large a +positive number or too small a negative number (excluding the +sign-bit) to fit in the destination operand; cleared otherwise. This +flag indicates an overflow condition for signed-integer (two s +complement) arithmetic.

" + :parents (rflag-specifications) + + (acl2::bool->bit (not (signed-byte-p result-nbits signed-raw-result))) + + /// + + (defthm-unsigned-byte-p n01p-general-of-spec-fn + :bound 1 + :concl (general-of-spec-fn result-nbits signed-raw-result))) + +(define of-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "OF-SPEC" result-nbits) + ((signed-raw-result :type (signed-byte ,(1+ result-nbits)))) + :inline t + :no-function t + :parents (rflag-specifications) + (acl2::bool->bit (mbe :logic (not (signed-byte-p ,result-nbits signed-raw-result)) + :exec (or + (not (<= ,(- (expt 2 (1- result-nbits))) signed-raw-result)) + (not (< signed-raw-result ,(expt 2 (1- result-nbits))))))) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-OF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "OF-SPEC" result-nbits) signed-raw-result) + :gen-type t + :gen-linear t))) + +(make-event (of-spec-gen-fn 8)) +(make-event (of-spec-gen-fn 16)) +(make-event (of-spec-gen-fn 32)) +(make-event (of-spec-gen-fn 64)) + +(defmacro general-of-spec (result-nbits signed-raw-result) + (cond ((eql result-nbits 8) + `(of-spec8 ,signed-raw-result)) + ((eql result-nbits 16) + `(of-spec16 ,signed-raw-result)) + ((eql result-nbits 32) + `(of-spec32 ,signed-raw-result)) + ((eql result-nbits 64) + `(of-spec64 ,signed-raw-result)) + (t + `(general-of-spec-fn ,result-nbits ,signed-raw-result)))) + +(add-macro-alias general-of-spec general-of-spec-fn) + +;; ---------------------------------------------------------------------- + +(define zf-spec + ;; CCL generates great code for this function, even without type + ;; declarations. + ((result :type (integer 0 *))) + :inline t + :no-function t + :long "

General @('ZF') Specification (Source: Intel Manuals, + Vol. 1, Section 3.4.3.1):

+ +

Zero flag Set if the result is zero; cleared +otherwise.

" + :parents (rflag-specifications) + + (if (equal result 0) 1 0) + /// + + (defthm-unsigned-byte-p n01p-zf-spec + :bound 1 + :concl (zf-spec result) + :gen-type t + :gen-linear t) + + (defthm zf-spec-thm + (implies (not (equal x 0)) + (equal (zf-spec x) 0)))) + +;; ---------------------------------------------------------------------- + +;; [Shilpi]: I could have put the theorems preceding the define of +;; pf-spec inside its :prepwork, but I believe that these theorems can +;; be useful later on too. Putting them outside the define makes them +;; more visible. + +(local + (encapsulate + () + (local (include-book "arithmetic-5/top" :dir :system)) + + (defthm logbitp-and-loghead + (implies (integerp x) + (equal (acl2::bool->bit (logbitp 0 x)) + (loghead 1 x))) + :hints (("Goal" :in-theory + (e/d (acl2::bool->bit + evenp oddp + logbitp + loghead) + ())))) + + (defthm logbitp-and-logtail + (implies (unsigned-byte-p (1+ n) x) + (equal (acl2::bool->bit (logbitp n x)) + (logtail n x))) + :hints (("Goal" :in-theory + (e/d (acl2::bool->bit + evenp oddp + logbitp + logtail + nfix) + ())))))) + +(defthm logcount-and-loghead + (implies (and (integerp x) + (natp n)) + (<= (logcount (loghead n x)) n)) + :hints (("Goal" :in-theory + (e/d* (acl2::ihsext-inductions acl2::ihsext-recursive-redefs) + (logcount loghead))))) + + +(defthm logcount-bound + (<= (logcount x) (integer-length x)) + :hints (("Goal" :in-theory + (e/d* (acl2::ihsext-inductions + acl2::ihsext-recursive-redefs) + (logcount)))) + :rule-classes :linear) + +(encapsulate + () + (local (include-book "centaur/bitops/signed-byte-p" :dir :system)) + + (defthm unsigned-byte-p-and-integer-length + (implies (and (unsigned-byte-p n x) + (natp n)) + (<= (integer-length x) n)) + :hints (("Goal" :in-theory (e/d* (acl2::ihsext-inductions + acl2::ihsext-recursive-redefs) + ()))) + :rule-classes :linear)) + + +(define bitcount8 + ((x :type (unsigned-byte 8))) + :measure (integer-length x) + :inline t + :no-function t + :verify-guards nil + :enabled t + (if (zp x) + 0 + (+ (the (unsigned-byte 1) + (mbe :logic + ;; (logcar x) + (loghead 1 x) + :exec (logand 1 x))) + (the (integer 0 8) + (bitcount8 + (the (unsigned-byte 8) + (mbe :logic + ;; (logcdr x) + (logtail 1 x) + :exec (ash x -1))))))) + /// + + + (defthm bitcount8-and-logcount + (implies (unsigned-byte-p 8 x) + (equal (bitcount8 x) + (logcount x))) + :hints (("Goal" :in-theory + (e/d* (acl2::ihsext-inductions + acl2::ihsext-recursive-redefs) + (logcount))))) + + (local + (defthm logtail-1-bound-linear + (implies (and (unsigned-byte-p 8 x) + (unsigned-byte-p 7 (logtail 1 x))) + (<= (integer-length (logtail 1 x)) 7)) + :hints (("Goal" :use ((:instance unsigned-byte-p-and-integer-length + (x (logtail 1 x)) + (n 7))) + :in-theory (e/d () + (unsigned-byte-p-and-integer-length)))) + :rule-classes :linear)) + + (verify-guards bitcount8$inline)) + +(define pf-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "PF-SPEC" result-nbits) + ((result :type (unsigned-byte ,result-nbits))) + :parents (rflag-specifications) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + + (mbe :logic (acl2::bool->bit (not + (logbitp + 0 + (logcount + ;; Only the least significant byte + ;; (i.e. the low 8 bits) is considered + ;; for calculating the parity flag + ;; (Intel manual, Vol. 1, Section 3.4.3.1). + ,(if (equal result-nbits 8) + `result + `(loghead 8 result)))))) + :exec (if (eql (logand 1 + (the (integer 0 8) + (bitcount8 + (the (unsigned-byte 8) + ,(if (equal result-nbits 8) + `result + `(logand 255 result)))))) + 0) + 1 0)) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-PF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "PF-SPEC" result-nbits) result) + :gen-type t + :gen-linear t))) + +(make-event (pf-spec-gen-fn 8)) +(make-event (pf-spec-gen-fn 16)) +(make-event (pf-spec-gen-fn 32)) +(make-event (pf-spec-gen-fn 64)) + +(define general-pf-spec-fn + ((result-nbits :type (member 8 16 32 64)) + (result :type (integer 0 *))) + :long "

General @('PF') Specification (Source: Intel Manuals, + Vol. 1, Section 3.4.3.1):

+ +

Parity flag Set if the least-significant byte of the +result contains an even number of 1 bits; cleared otherwise.

" + :parents (rflag-specifications) + :inline t + :no-function t + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p)))) + :guard (unsigned-byte-p result-nbits result) + (mbe :logic (acl2::bool->bit (not (logbitp 0 (logcount (loghead 8 result))))) + :exec (if (eql (logand 1 + (the (integer 0 8) + (bitcount8 + (the (unsigned-byte 8) + (logand 255 + (if (eql result-nbits 64) + result + (the (unsigned-byte 32) + result))))))) + 0) + 1 0)) + + /// + + (defthm-unsigned-byte-p n01p-general-pf-spec-fn + :bound 1 + :concl (general-pf-spec-fn result-nbits result) + :gen-type t + :gen-linear t)) + +(defmacro general-pf-spec (result-nbits result) + (cond ((eql result-nbits 8) + `(pf-spec8 ,result)) + ((eql result-nbits 16) + `(pf-spec16 ,result)) + ((eql result-nbits 32) + `(pf-spec32 ,result)) + ((eql result-nbits 64) + `(pf-spec64 ,result)) + (t + `(general-pf-spec-fn ,result-nbits ,result)))) + +(add-macro-alias general-pf-spec general-pf-spec-fn) + +;; ---------------------------------------------------------------------- + +(define sf-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "SF-SPEC" result-nbits) + ((result :type (unsigned-byte ,result-nbits))) + :inline t + :no-function t + + :parents (rflag-specifications) + + (mbe + :logic + (part-select result :low ,(1- result-nbits) :width 1) + :exec + (the (unsigned-byte 1) (ash result ,(- (1- result-nbits))))) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-SF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "SF-SPEC" result-nbits) result) + :gen-type t + :gen-linear t) + )) + +(make-event (sf-spec-gen-fn 8)) +(make-event (sf-spec-gen-fn 16)) +(make-event (sf-spec-gen-fn 32)) +(make-event (sf-spec-gen-fn 64)) + +(define general-sf-spec-fn + ((result-nbits :type (member 8 16 32 64)) + (result :type (integer 0 *))) + :inline t + :no-function t + :guard (unsigned-byte-p result-nbits result) + :long "

General @('SF') Specification (Source: Intel Manuals, + Vol. 1, Section 3.4.3.1):

+ +

Sign flag Set equal to the most-significant bit of the +result, which is the sign bit of a signed integer. (0 indicates a +positive value and 1 indicates a negative value.)

" + :parents (rflag-specifications) + + (mbe + :logic + (part-select result :low (1- result-nbits) :width 1) + :exec + (the (unsigned-byte 1) + (ash + (if (eql result-nbits 64) + result + (the (unsigned-byte 50) result)) + (the (integer -63 0) + (- (the (integer 0 63) + (1- (the (integer 0 64) result-nbits)))))))) + /// + + (defthm-unsigned-byte-p n01p-general-sf-spec-fn + :bound 1 + :concl (general-sf-spec-fn result-nbits result) + :gen-type t + :gen-linear t)) + +(defmacro general-sf-spec (result-nbits result) + (cond ((eql result-nbits 8) + `(sf-spec8 ,result)) + ((eql result-nbits 16) + `(sf-spec16 ,result)) + ((eql result-nbits 32) + `(sf-spec32 ,result)) + ((eql result-nbits 64) + `(sf-spec64 ,result)) + (t + `(general-sf-spec-fn ,result-nbits ,result)))) + +(add-macro-alias general-sf-spec general-sf-spec-fn) + +;; ---------------------------------------------------------------------- + +;; Instruction-specific AF specification: + +(define add-af-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "ADD-AF-SPEC" result-nbits) + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits))) + :inline t + :no-function t + :parents (rflag-specifications) + + (b* (((the (unsigned-byte 4) dst-3-0) + (mbe :logic (part-select dst :low 0 :width 4) + :exec (logand #xF dst))) + ((the (unsigned-byte 4) src-3-0) + (mbe :logic (part-select src :low 0 :width 4) + :exec (logand #xF src))) + + (add + (the (unsigned-byte 5) + (+ (the (unsigned-byte 4) dst-3-0) + (the (unsigned-byte 4) src-3-0)))) + + (af (the (unsigned-byte 1) (bool->bit (< #xF add))))) + + af) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-ADD-AF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "ADD-AF-SPEC" result-nbits) dst src) + :gen-linear t + :gen-type t))) + +(make-event (add-af-spec-gen-fn 8)) +(make-event (add-af-spec-gen-fn 16)) +(make-event (add-af-spec-gen-fn 32)) +(make-event (add-af-spec-gen-fn 64)) + +(defmacro add-af-spec (result-nbits dst src) + (cond ((eql result-nbits 8) + `(add-af-spec8 ,dst ,src)) + ((eql result-nbits 16) + `(add-af-spec16 ,dst ,src)) + ((eql result-nbits 32) + `(add-af-spec32 ,dst ,src)) + (t + `(add-af-spec-fn + ,result-nbits ,dst ,src)))) + +(define sub-af-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "SUB-AF-SPEC" result-nbits) + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits))) + :inline t + :no-function t + :parents (rflag-specifications) + + (b* (((the (unsigned-byte 4) dst-3-0) + (mbe :logic (part-select dst :low 0 :width 4) + :exec (logand #xF dst))) + ((the (unsigned-byte 4) src-3-0) + (mbe :logic (part-select src :low 0 :width 4) + :exec (logand #xF src))) + + (sub + (the (signed-byte 5) + (- (the (unsigned-byte 4) dst-3-0) + (the (unsigned-byte 4) src-3-0)))) + + (af (the (unsigned-byte 1) (bool->bit (< sub 0))))) + + af) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-SUB-AF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "SUB-AF-SPEC" result-nbits) + dst src) + :gen-linear t + :gen-type t))) + +(make-event (sub-af-spec-gen-fn 8)) +(make-event (sub-af-spec-gen-fn 16)) +(make-event (sub-af-spec-gen-fn 32)) +(make-event (sub-af-spec-gen-fn 64)) + +(defmacro sub-af-spec + (result-nbits dst src) + (cond ((eql result-nbits 8) + `(sub-af-spec8 ,dst ,src)) + ((eql result-nbits 16) + `(sub-af-spec16 ,dst ,src)) + ((eql result-nbits 32) + `(sub-af-spec32 ,dst ,src)) + (t + `(sub-af-spec-fn + ,result-nbits ,dst ,src)))) + +(define adc-af-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "ADC-AF-SPEC" result-nbits) + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (cf :type (unsigned-byte 1))) + :inline t + :no-function t + :parents (rflag-specifications) + + (b* (((the (unsigned-byte 4) dst-3-0) + (mbe :logic (part-select dst :low 0 :width 4) + :exec (logand #xF dst))) + ((the (unsigned-byte 4) src-3-0) + (mbe :logic (part-select src :low 0 :width 4) + :exec (logand #xF src))) + + (adc + (the (unsigned-byte 6) + (+ (the (unsigned-byte 4) dst-3-0) + (the (unsigned-byte 4) src-3-0) + (the (unsigned-byte 1) cf)))) + + (af (the (unsigned-byte 1) (bool->bit (< #xF adc))))) + + af) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-ADC-AF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "ADC-AF-SPEC" result-nbits) + dst src cf) + :gen-linear t + :gen-type t))) + +(make-event (adc-af-spec-gen-fn 8)) +(make-event (adc-af-spec-gen-fn 16)) +(make-event (adc-af-spec-gen-fn 32)) +(make-event (adc-af-spec-gen-fn 64)) + +(defmacro adc-af-spec + (result-nbits dst src cf) + (cond ((eql result-nbits 8) + `(adc-af-spec8 ,dst ,src ,cf)) + ((eql result-nbits 16) + `(adc-af-spec16 ,dst ,src ,cf)) + ((eql result-nbits 32) + `(adc-af-spec32 ,dst ,src ,cf)) + (t + `(adc-af-spec-fn + ,result-nbits ,dst ,src ,cf)))) + +(define sbb-af-spec-gen-fn (result-nbits) + :verify-guards nil + + `(define ,(mk-name "SBB-AF-SPEC" result-nbits) + ((dst :type (unsigned-byte ,result-nbits)) + (src :type (unsigned-byte ,result-nbits)) + (cf :type (unsigned-byte 1))) + :inline t + :no-function t + :parents (rflag-specifications) + + (b* (((the (unsigned-byte 4) dst-3-0) + (mbe :logic (part-select dst :low 0 :width 4) + :exec (logand #xF dst))) + ((the (unsigned-byte 4) src-3-0) + (mbe :logic (part-select src :low 0 :width 4) + :exec (logand #xF src))) + + ((the (unsigned-byte 6) sbb) + (logand #x3F (- (the (unsigned-byte 4) dst-3-0) + (+ (the (unsigned-byte 4) src-3-0) + (the (unsigned-byte 4) cf))))) + + (af (the (unsigned-byte 1) (bool->bit (> sbb #xF))))) + + af) + + /// + + (defthm-unsigned-byte-p ,(mk-name "N01P-SBB-AF-SPEC" result-nbits) + :bound 1 + :concl (,(mk-name "SBB-AF-SPEC" result-nbits) + dst src cf) + :gen-linear t + :gen-type t))) + +(make-event (sbb-af-spec-gen-fn 8)) +(make-event (sbb-af-spec-gen-fn 16)) +(make-event (sbb-af-spec-gen-fn 32)) +(make-event (sbb-af-spec-gen-fn 64)) + +(defmacro sbb-af-spec + (result-nbits dst src cf) + (cond ((eql result-nbits 8) + `(sbb-af-spec8 ,dst ,src ,cf)) + ((eql result-nbits 16) + `(sbb-af-spec16 ,dst ,src ,cf)) + ((eql result-nbits 32) + `(sbb-af-spec32 ,dst ,src ,cf)) + (t + `(sbb-af-spec-fn + ,result-nbits ,dst ,src ,cf)))) + +;; ---------------------------------------------------------------------- + +;; Some arithmetic theorems that will be used in all books higher up +;; (especially for proving away MBEs): + +(encapsulate + () + + (local (include-book "arithmetic-5/top" :dir :system)) + + (defun power-of-2p-measure (x) + (cond ((or (not (natp x)) + (<= x 1)) + 0) + (t (floor x 1)))) + + (defn is-power-of-2p (x) + (declare (xargs :measure (power-of-2p-measure x))) + (if (natp x) + (if (<= x 1) + t + (is-power-of-2p (* 1/2 x))) + nil)) + + (local + (set-default-hints + '((acl2::nonlinearp-default-hint++ acl2::id acl2::stable-under-simplificationp + acl2::hist nil)))) + + (defthm ash-bounds-with-powers-of-two + ;; A general ash bounds theorem + (implies (and (integerp i) + (<= 0 i) + (equal 2-to-x (* 2-to-x-y (expt 2 y))) + (< i 2-to-x) + (syntaxp (quotep 2-to-x)) + (is-power-of-2p 2-to-x) + (< (expt 2 y) 2-to-x) + (syntaxp (quotep y)) + (syntaxp (quotep 2-to-x-y)) + (integerp y) + (<= 0 y)) + (< (ash i (- y)) 2-to-x-y)) + :rule-classes :rewrite) + + ) ;; End of encapsulate + +(local + (defun my-induct (x y) + (if (and (natp x) + (natp y)) + (if (zp x) + y + (if (zp y) + x + (my-induct (logcdr x) (logcdr y)))) + nil))) + +(defthm integer-length-of-logior-of-natp + (implies (and (natp x) + (natp y) + (<= (integer-length x) (integer-length y))) + (equal (integer-length (logior x y)) + (integer-length y))) + :hints (("Goal" :induct (my-induct x y) + :in-theory (e/d (acl2::integer-length**) + (integer-length))))) + +(defthm integer-length-and-loghead-when-natp-identity-theorem + (implies (natp x) + (equal (loghead (integer-length x) x) + x)) + :hints (("Goal" :in-theory (e/d* (acl2::loghead** acl2::integer-length** + acl2::ihsext-inductions) + ((force)))))) + +(defthm mod-expt-and-integer-length-identity-theorem + (implies (natp x) + (equal (mod x (expt 2 (integer-length x))) + x)) + :hints (("Goal" :in-theory (e/d* (acl2::ihsext-arithmetic) + (bitops::ash-1-removal))))) + +(encapsulate + () + + (local (include-book "arithmetic-5/top" :dir :system)) + + ;; The following are useful for MBE kind of proofs. Be careful when + ;; using them though; sometimes, they might cause loops when enabled + ;; alongside logand-with-negated-bitmask and + ;; logand-with-bitmask. + + (defthmd negative-logand-to-positive-logand-with-natp-x + (implies (and (syntaxp (and (quotep n) + (let* ((n-abs (acl2::unquote n))) + (< n-abs 0)))) + (equal m (integer-length x)) + (integerp n) + (natp x)) + (equal (logand n x) + (logand (logand (1- (ash 1 m)) n) x)))) + + (defun find-best-fitting-m (n) + (if (signed-byte-p 8 (acl2::unquote n)) + (list (list (cons 'm ''8)) + (list (cons 'm ''16)) + (list (cons 'm ''32)) + (list (cons 'm ''64)) + (list (cons 'm ''128))) + (if (signed-byte-p 16 (acl2::unquote n)) + (list (list (cons 'm ''16)) + (list (cons 'm ''32)) + (list (cons 'm ''64)) + (list (cons 'm ''128))) + (if (signed-byte-p 32 (acl2::unquote n)) + (list (list (cons 'm ''32)) + (list (cons 'm ''64)) + (list (cons 'm ''128))) + (list (list (cons 'm ''64)) + (list (cons 'm ''128))))))) + + (defthm negative-logand-to-positive-logand-with-integerp-x + (implies (and (syntaxp (and (quotep n) + (let* ((n-abs (acl2::unquote n))) + (< n-abs 0)))) + (bind-free (find-best-fitting-m n) (m)) + (unsigned-byte-p m x) + (integerp n)) + (equal (logand n x) + (logand (logand (1- (ash 1 m)) n) x)))) + + (defthmd loghead-to-logand + ;; This rule causes loop when used alongside + ;; bitops::logand-with-bitmask and bitops::logand-with-negated-bitmask. + (implies (and (natp n) + (syntaxp (quotep n)) + (integerp x)) + (equal (loghead n x) + (logand (1- (expt 2 n)) x))) + :hints (("Goal" :in-theory (e/d (loghead) ())))) + + (defthm logand-redundant + (implies (and (unsigned-byte-p n x) + (equal width (1- (ash 1 n))) + (syntaxp (quotep width))) + (equal (logand width x) + x))) + + (defthm weed-out-irrelevant-logand-when-first-operand-constant + (implies (and + ;; syntaxp will restrict the application of this + ;; theorem... + (syntaxp (quotep x)) + (unsigned-byte-p n y) + (equal (logand (1- (expt 2 n)) x) (1- (expt 2 n)))) + (equal (logand x y) y)) + :hints (("Goal" + :use ((:instance acl2::mod-logand (x x) (y y) (n n))) + :in-theory (disable acl2::mod-logand))))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/state.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/state.lisp new file mode 100644 index 000000000..66f0e1520 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/state.lisp @@ -0,0 +1,993 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, May - August 2023, Regents of the University of Texas +; Copyright (C) August 2023 - May 2024, Yahya Sohail +; Copyright (C) May 2024 - August 2024, Intel Corporation +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Matt Kaufmann +; Warren A. Hunt, Jr. +; Robert Krug +; Updated by Shilpi Goel in June, 2021 to use +; the bigmem and defrstobj books. +; Contributing Author(s): +; Yahya Sohail + +(in-package "X86ISA") + +(include-book "utilities" :dir :utils) +(include-book "structures" :dir :utils) +(include-book "centaur/defrstobj2/defrstobj" :dir :system) + +(include-book "centaur/bigmems/bigmem/bigmem" :dir :system) + +(include-book "centaur/bitops/ihsext-basics" :dir :system) +(include-book "std/strings/pretty" :dir :system) + +(include-book "tlb") +(include-book "tty") + +; cert_param: (non-lispworks) + +;; Matt Kaufmann discovered that LispWorks complained about making an +;; array whose length is more than twice the legal limit. Here's the +;; exact error (from an email Matt sent to Shilpi): + +;; HARD ACL2 ERROR in ACL2::MAKE-ARRAY$: The dimensions of an array must +;; obey restrictions of the underlying Common Lisp: each must be a non- +;; negative integer less than the value of array-dimension-limit (here, +;; 536870911) and their product must be less than the value of array- +;; total-size-limit (here, 536870911). The call +;; '(ACL2::MAKE-ARRAY$ 1342177280 +;; :ELEMENT-TYPE '(UNSIGNED-BYTE 8) +;; :INITIAL-ELEMENT '0), +;; which has dimensions 1342177280, is thus illegal. + +;; Since other Lisps do not complain about the large array length, we +;; choose not to support LispWorks at this point. + +;; ---------------------------------------------------------------------- + +(defsection machine + :parents (x86isa) + :short "Core elements of the x86 ISA, like the @('x86') state, + decoder function, etc., and proofs about the x86 ISA + specification.") + +(local (xdoc::set-default-parents x86isa-state)) + +;; ---------------------------------------------------------------------- +;; x86 state +;; ---------------------------------------------------------------------- + +(defsection physical-memory-model + :parents (x86isa-state) + :short "How to change physical memory models" + :long "

We use the @(tsee bigmems::bigmems) library to model the + memory. The default model is @(tsee bigmem::bigmem). This model is + \"attachable,\" which allows one to replace it in execution with a + logically equivalent stobj. Here's why you'd want to replace it:

+ +

@(tsee bigmem::bigmem) provides constant access time for the entire address +space. However, accessing a byte requires walking a 3 level hierarchy.

+ +

@(tsee bigmem-asymmetric::bigmem-asymmetric) provides faster access to the +lower 6GB of physical memory, because those values are stored in an array, but +slower access to the rest of the address space, since it stores the rest of the +values in an ordered alist.

+ +

If you're only going to be using the lower 6GB of memory (or mostly using +the lower 6 GB) of memory, using the @(tsee +bigmem-asymmetric::bigmem-asymmetric) makes sense, otherwise use @(tsee +bigmem::bigmem)

+ +

By default, the model uses @(tsee bigmem::bigmem). To switch to @(tsee +bigmem-asymmetric::bigmem-asymmetric), submit the following events to ACL2 +before including the x86 books:

+ + +(include-book \"centaur/bigmems/bigmem-asymmetric/bigmem-asymmetric\" :dir :system) +(attach-stobj bigmem::mem bigmem-asymmetric::mem) +") + +(defsection environment-field + + :parents (x86isa-state) + + :short "An environment field that includes a simple model of the + file system and an oracle" + + :long "

The environment allows reasoning about non-deterministic + events and computations in the ISA, like the @('RDRAND') instruction + and in the user-level mode, the @('SYSCALL') instruction.

" + + (define rip-ret-alistp (lst) + :short "Recognizer for the @('oracle') sub-field of the environment + field @('env')" + :long "

A valid @('rip-ret-alistp') associates canonical linear + addresses, i.e., 48-bit integers in our specification, to a list + of arbitrary values. For example, '((1 . ((-1 . 12) 5000)) (2 + . (0))) means that if the oracle in the environment field is + consulted at address 1, '(-1 . 12) will be + popped out. If the oracle is consulted again at the address + 1, then 5000 will be popped out.

" + :parents (environment-field) + (if (atom lst) + (equal lst nil) + (and (consp (car lst)) + (i48p (caar lst)) + (true-listp (cdar lst)) + (rip-ret-alistp (cdr lst)))) + /// + + (defthm rip-ret-alistp-fwd-chaining-alistp + (implies (rip-ret-alistp x) + (alistp x)) + :rule-classes :forward-chaining)) + + (define env-alistp (env) + :short "Recognizer of the environment field @('env')" + :long "

As of now, @('env-alistp') consists of three sub-fields, + all of which are basically alists --- file descriptors, file + contents, and an oracle field.

" + :parents (environment-field) + (or (equal env nil) + (and (alistp env) + (equal (len env) 3) + (consp (assoc :FILE-DESCRIPTORS env)) + (alistp (cdr (assoc :FILE-DESCRIPTORS env))) + (consp (assoc :FILE-CONTENTS env)) + (alistp (cdr (assoc :FILE-CONTENTS env))) + (consp (assoc :ORACLE env)) + (rip-ret-alistp (cdr (assoc :ORACLE env))))) + + /// + + (defun env-alist-fix (x) + (declare (xargs :guard (env-alistp x))) + (mbe :logic (if (env-alistp x) x nil) + :exec x)) + + (defthm env-alistp-fwd-chaining-alistp + (implies (env-alistp x) + (alistp x)) + :rule-classes :forward-chaining) + + (defrulel nth-and-assoc-equal-check + (implies (and (alistp x) + (not (equal (car (nth 0 x)) :oracle)) + (equal (car (nth 1 x)) :oracle)) + (equal (nth 1 x) + (assoc-equal :oracle x)))) + + (defthm env-alistp-implies-rip-ret-alistp + (implies (env-alistp x) + (rip-ret-alistp (cdr (assoc-equal :oracle x)))) + :rule-classes (:rewrite :forward-chaining)) + + (defthm env-alistp-implies-alistp-file-descriptors + (implies (env-alistp x) + (alistp (cdr (assoc-equal :file-descriptors x)))) + :rule-classes (:rewrite :forward-chaining)) + + (defthm env-alistp-implies-alistp-file-contents + (implies (env-alistp x) + (alistp (cdr (assoc-equal :file-contents x)))) + :rule-classes (:rewrite :forward-chaining)))) + +(defn os-info-fix (x) + (if (keywordp x) x :linux)) + +(defconst *x86isa-state* + `( + ;; -------------------------------------------------- + (:doc "
Fields that govern the model's operation
+ +

These fields are an artifact of our x86 ISA model.

+ +
    ") + + (:doc "
  • @('MS'): Model state, used to indicate I/O or errors + that our model does not handle yet. Basically, we use the model + state to assert partial correctness. If the model state is nil + till the end of execution, we expect the results to be correct. + Otherwise, all bets are off.
    ") + (ms :type t :initially nil) + (:doc "
  • ") + + (:doc "
  • @('FAULT'): We need some way to pass exceptions and + such around. So we stuff them into the @('fault') slot, to be + processed by the step function.
    ") + (fault :type t :initially nil) + (:doc "
  • ") + + (:doc "
  • @('ENV'): Environment for the programs running on our + x86 model.
    ") + (env :type (satisfies env-alistp) + :fix (ec-call (env-alist-fix x)) + :initially nil) + (:doc "
  • ") + + (:doc "
  • @('UNDEF'): Field that seeds unknown values that + characterize commonly occurring undefined behavior.
    ") + (undef :type t :initially 0) + (:doc "
  • ") + + (:doc "
  • @('APP-VIEW'): This field acts as a switch. When its + value is @('t'), support for system features like paging is + absent. When its value is @('nil'), the model is in @('sys-view') + and support for system features is present.
    ") + (app-view :type (satisfies booleanp) + :fix (acl2::bool-fix x) + :initially t) + (:doc "
  • ") + + (:doc "
  • @('MARKING-VIEW'): This field also acts as a + switch. When its value is @('t'), then accessed and dirty bits in + the paging structures are set during those data structure + traversals, as expected. Otherwise, these bits are not set. This + switch is meaningful only in when the model is in @('sys-view').
    ") + (marking-view :type (satisfies booleanp) + :fix (acl2::bool-fix x) + :initially t) + (:doc "
  • ") + + (:doc "
  • @('ENABLE-PERIPHERALS'): This field also acts as a + switch. When its value is @('t'), then the model's peripherals + (timer and TTY) are enabled. Otherwise, the model acts like + there are no peripherals. This only applies when the model + is in @('sys-view').
    ") + (enable-peripherals :type (satisfies booleanp) + :fix (acl2::bool-fix x) + :initially t) + (:doc "
  • ") + + (:doc "
  • @('HANDLE-INTERRUPTS'): This field also acts as a + switch. When its value is @('t'), then exceptions and interrupts + are handled using handlers in the IDT. Otherwise, exceptions and + interrupts cause the ms or fault fields to be set after instruction + execution, which terminates execution when using x86-run. This + only applies when the model is in @('sys-view'). Note: The timer + peripheral triggers interrupts, and they won't be handled unless + this is @('t'), so if you are using it, you probably want to enable + this.
    ") + (handle-exceptions :type (satisfies booleanp) + :fix (acl2::bool-fix x) + :initially t) + (:doc "
  • ") + + (:doc "
  • @('OS-INFO'): This field is meaningful only in + @('app-view') mode to model system call behavior.
    ") + (os-info :type (satisfies keywordp) + :fix (ec-call (os-info-fix x)) + :initially :linux) + (:doc "
  • ") + + (:doc "
") + + ;; -------------------------------------------------- + + (:doc "
Components of the x86 state specified by this model
+ +
    ") + + (:doc + "
  • @('RGF'): The general-purpose registers are just an array of + signed 64-bit integers. Note that we choose to define the GPRs + as signed integers for the sake of efficiency. For instance, + @('-1') in unsigned format would occupy 64 bits, a bignum. But + in the signed format, it would be a fixum. See Intel Volume 1, + Section 3.4.1 (General-Purpose Registers) for information about + these registers.
    ") + (rgf :type (array (signed-byte 64) + (,*64-bit-general-purpose-registers-len*)) + :initially 0 + :fix (acl2::logext 64 (ifix x)) + :resizable nil + :accessor rgfi + :updater !rgfi) + (:doc "
  • ") + + (:doc "
  • @('RIP'): We choose the RIP to be a 48-bit signed + integer. RIP can contain only canonical addresses, which range + from 0 to 2^47-1 and 2^64-2^47 to 2^64-1, inclusive, for the + 64-bit mode. So, in our model, 0 to 2^47-1 represents the lower + range of canonical addresses and -2^47 to -1 represents the upper + range of canonical addresses. See Intel manual, Jan'19, Volume 1, + Section 3.5 for details about the instruction pointer.
    ") + (rip :type (signed-byte 48) + :initially 0 + :fix (acl2::logext 48 (ifix x))) + (:doc "
  • ") + + (:doc "
  • @('RFLAGS'): We define the @('rflags') register as a + 32-bit field, even though in the 64-bit mode, rflags is a 64-bit + register --- this is justified because Intel says that the top 32 + bits of rflags are reserved. See Intel manual, Jan'19A, Volume 1, + Section 3.4.3 for details about @('rflags').
    ") + (rflags :type (unsigned-byte 32) + ;; Bit 1 is always 1. + :initially 2 + :fix (acl2::loghead 32 (ifix x))) + (:doc "
  • ") + + (:doc "
  • @('User Segment Registers'): +

    Visible portion: + @({ 16-bit selector INDEX(13)::TI(1)::RPL(2) })

    +

    Hidden/Cache portion (see Intel manual, Mar'17, Vol. 3A, Figure 3-7): + @({ 16-bit Attributes + 32-bit Limit + 64-bit Base Address})

    +

    See Intel manual, Jan'19, Volume 1, Section 3.4.2 and Intel + manual, Jan'19, Volume 3, Sections 3.4.2 and 3.4.3 for + details.


    ") + (seg-visible :type (array (unsigned-byte 16) + (#.*segment-register-names-len*)) + :initially 0 + :fix (acl2::loghead 16 (ifix x)) + :resizable nil + :accessor seg-visiblei + :updater !seg-visiblei) + (seg-hidden-base :type (array (unsigned-byte 64) + (#.*segment-register-names-len*)) + :fix (acl2::loghead 64 (ifix x)) + :initially 0 + :resizable nil + :accessor seg-hidden-basei + :updater !seg-hidden-basei) + (seg-hidden-limit :type (array (unsigned-byte 32) + (#.*segment-register-names-len*)) + :fix (acl2::loghead 32 (ifix x)) + :initially 0 + :resizable nil + :accessor seg-hidden-limiti + :updater !seg-hidden-limiti) + (seg-hidden-attr :type (array (unsigned-byte 16) + (#.*segment-register-names-len*)) + :fix (acl2::loghead 16 (ifix x)) + :initially 0 + :resizable nil + :accessor seg-hidden-attri + :updater !seg-hidden-attri) + (:doc "
  • ") + + (:doc "
  • @('System Table Registers (GDTR and IDTR)'): These + registers point to bounded tables of (up to 8192) segment + descriptors. In 64-bit mode, the system table registers are + extended from 48 to 80 bits. See Intel manual, Jan'19, Volume 3, + Figure 2-6.
    ") + (str :type (array (unsigned-byte 80) + (#.*gdtr-idtr-names-len*)) + :fix (acl2::loghead 80 (ifix x)) + :initially 0 + :resizable nil + :accessor stri + :updater !stri) + (:doc "
  • ") + + (:doc "
  • @('System Segment Registers (Task Register and LDTR)'): +

    Visible portion: + @({ 16-bit selector INDEX(13)::TI(1)::RPL(2) })

    +

    Hidden/Cache portion: + @({ 16-bit Attributes + 32-bit Limit + 64-bit Base Address })

    +

    See Intel manual, Jan'19, Volume 3, Figure 2-6 for details.


    ") + (ssr-visible :type (array (unsigned-byte 16) + (#.*ldtr-tr-names-len*)) + :initially 0 + :fix (acl2::loghead 16 (ifix x)) + :resizable nil + :accessor ssr-visiblei + :updater !ssr-visiblei) + (ssr-hidden-base :type (array (unsigned-byte 64) + (#.*ldtr-tr-names-len*)) + :initially 0 + :fix (acl2::loghead 64 (ifix x)) + :resizable nil + :accessor ssr-hidden-basei + :updater !ssr-hidden-basei) + (ssr-hidden-limit :type (array (unsigned-byte 32) + (#.*ldtr-tr-names-len*)) + :initially 0 + :fix (acl2::loghead 32 (ifix x)) + :resizable nil + :accessor ssr-hidden-limiti + :updater !ssr-hidden-limiti) + (ssr-hidden-attr :type (array (unsigned-byte 16) + (#.*ldtr-tr-names-len*)) + :fix (acl2::loghead 16 (ifix x)) + :initially 0 + :resizable nil + :accessor ssr-hidden-attri + :updater !ssr-hidden-attri) + (:doc "
  • ") + + (:doc "
  • @('CTR'): Control registers --- See Intel manual, + Jan'19, Volume 3, Section 2.5.
    ") + ;; [Shilpi]: + ;; Note that CR0 is still a 32-bit register in 64-bit mode. All + ;; other control registers are 64-bit wide. Also, CR4 has all + ;; but the low 21 bits reserved. It'd be nice to define these + ;; registers separately so that bignum creation can be avoided + ;; during slicing operations involving these registers. + (ctr :type (array (unsigned-byte 64) + (#.*control-register-names-len*)) + :fix (acl2::loghead 64 (ifix x)) + :initially 0 + :resizable nil + :accessor ctri + :updater !ctri) + (:doc "
  • ") + + (:doc "
  • @('DBG'): Debug registers --- See Intel manual, Jan'19, + Volume 3, Section 17.2.
    ") + (dbg :type (array (unsigned-byte 64) + (#.*debug-register-names-len*)) + :initially 0 + :fix (acl2::loghead 64 (ifix x)) + :resizable nil + :accessor dbgi + :updater !dbgi) + (:doc "
  • ") + + + (:doc "
  • @('FPU 80-bit data registers'): The MMX + registers (@('MM0') through @('MM7')) are aliased to the low + 64-bits of the FPU data registers. See Intel manual, Jan'19, + Volume 1, Section 8.1.2.") + (fp-data :type (array (unsigned-byte 80) + (#.*fp-data-register-names-len*)) + :fix (acl2::loghead 80 (ifix x)) + :initially 0 + :resizable nil + :accessor fp-datai + :updater !fp-datai) + (:doc "
  • ") + + (:doc "
  • @('FPU 16-bit control register'): See Intel manual, + Jan'19, Volume 1, Section 8.1.5.") + (fp-ctrl :type (unsigned-byte 16) + :fix (acl2::loghead 16 (ifix x)) + :initially 0) + (:doc "
  • ") + + (:doc "
  • @('FPU 16-bit status register'): See Intel manual, + Jan'19, Volume 1, Section 8.1.3.") + (fp-status :type (unsigned-byte 16) + :fix (acl2::loghead 16 (ifix x)) + :initially 0) + (:doc "
  • ") + + (:doc "
  • @('FPU 16-bit tag register'): See Intel manual, + Jan'19, Volume 1, Section 8.1.7.") + (fp-tag :type (unsigned-byte 16) + :fix (acl2::loghead 16 (ifix x)) + :initially 0) + (:doc "
  • ") + + (:doc "
  • @('FPU 48-bit last instruction pointer'): See Intel + manual, Jan'19, Volume 1, Figure 8-1.") + (fp-last-inst :type (unsigned-byte 48) + :fix (acl2::loghead 48 (ifix x)) + :initially 0) + (:doc "
  • ") + + (:doc "
  • @('FPU 48-bit last data (operand) pointer'): See Intel + manual, Jan'19, Volume 1, Figure 8-1.") + (fp-last-data :type (unsigned-byte 48) + :fix (acl2::loghead 48 (ifix x)) + :initially 0) + (:doc "
  • ") + + (:doc "
  • @('FPU 11-bit opcode:') See Intel manual, Jan'19, + Volume 1, Figure 8-1.
    ") + (fp-opcode :type (unsigned-byte 11) + :fix (acl2::loghead 11 (ifix x)) + :initially 0) + (:doc "
  • ") + + (:doc "
  • @('MXCSR') register") + (mxcsr :type (unsigned-byte 32) + ;; Bits 7 through 12 are the individual masks for the + ;; SIMD floating point exceptions. These are set upon + ;; a power-up or reset. + :fix (acl2::loghead 32 (ifix x)) + :initially 8064) + (:doc "
  • ") + + + (:doc "
  • @('OPMASK'): 8 opmask registers are used for + conditional execution and merging of data elements in the + destination operands of AVX-512 EVEX-encoded instructions. They + are also used as operands in opmask instructions like KMOV, etc.") + (opmsk :type (array (unsigned-byte 64) + (#.*opmsk-register-names-len*)) + :fix (acl2::loghead 64 (ifix x)) + :initially 0 + :resizable nil + :accessor opmski + :updater !opmski) + (:doc "
  • ") + + (:doc "
  • @('ZMM'): ZMM 512-bit data registers --- the lower + 256-bits of the ZMM registers are aliased to the respective + 256-bit YMM registers and the lower 128-bit are aliased to the + respective 128-bit XMM registers. Note that registers YMM16/XMM16 + to YMM31/XMM31 are available only via the EVEX prefix (AVX-512).") + (zmm :type (array (unsigned-byte 512) + (#.*zmm-register-names-len*)) + :fix (acl2::loghead 512 (ifix x)) + :initially 0 + :resizable nil + :accessor zmmi + :updater !zmmi) + (:doc "
  • ") + + (:doc "
  • @('MSR'): Model-specific registers
    ") + (msr :type (array (unsigned-byte 64) + (#.*model-specific-register-names-len*)) + :fix (acl2::loghead 64 (ifix x)) + :initially 0 + :resizable nil + :accessor msri + :updater !msri) + (:doc "
  • ") + + (:doc "
  • @('MEM'): Field modeling @('2^52') bytes of physical + memory in @('sys-view') and @('2^48') bytes of linear memory in + @('app-view').
    ") + (mem :type (array (unsigned-byte 8) (,*mem-size-in-bytes*)) ;; 2^52 + :initially 0 + :fix (acl2::loghead 8 (ifix x)) + :child-stobj bigmem::mem + :child-accessor bigmem::read-mem + :child-updater bigmem::write-mem + :accessor memi + :updater !memi) + (:doc "
  • ") + + (:doc "
  • @('Inhibit Interrupts One Instruction'): The Intel manual states + that some instructions, like the STI instruction, inhibit interrupts + for one instruction after execution, despite the interrupt flag being + set immediately. This flag is used to implement that. It is t when + interrupts should not be allows and is cleared after executing an + instruction if it was set at the beginning of the instruction. + Consult the documentation for STI in Volume 2B 4.3 in the Intel + manual.
    ") + (inhibit-interrupts-one-instruction :type (satisfies booleanp) + :initially nil + :fix (acl2::bool-fix x)) + (:doc "
  • ") + + (:doc "
  • @('Time Stamp Counter'): This keeps track of how many instructions have been executed for the RDTSC instruction.
    ") + (time-stamp-counter :type (satisfies natp) + :initially 0 + :fix (nfix x)) + (:doc "
  • ") + + (:doc "
  • @('Last Clock Event'): Our clock device sends a clock event every 100,000 instructions. When interrupts + are disabled, however, we can't send a clock event. Instead of sending one on every 100,000 instructions, + we send an interrupt if interrupts are enabled and the last clock event was 100,000 or more instructions ago. + This keeps track of how many instructions have been executed since the last clock event.
    ") + (last-clock-event :type (satisfies natp) + :initially 0 + :fix (nfix x)) + (:doc "
  • ") + + (:doc "
  • @('Implicit Supervisor Access'): This field is a boolean + flag that, when t, tells the address translation system that all + translations should be treated as implicit supervisor accesses, + regardless of current privilege level.
    ") + (implicit-supervisor-access :type (satisfies booleanp) + :initially nil + :fix (acl2::bool-fix x)) + (:doc "
  • ") + + (:doc "
  • @('TLB'): This field models a (number of) TLB(s). See @(tsee tlb) + for a detailed discussion about our address translation caching scheme and + its consistency with the x86 ISA. It is a fast alist that is @(tsee tlbp). + Invalid translations are not cached.
    ") + (tlb :type (satisfies tlbp) + :initially :tlb + :fix (tlb-fix x)) + (:doc "
  • ") + + (:doc "
  • @('TTY-in'): This field models the input buffer of the TTY device.
    ") + (tty-in :type (satisfies tty-bufferp) + :initially nil + :fix (tty-buffer-fix x)) + (:doc "
  • ") + + (:doc "
  • @('TTY-out'): This field models the output buffer of the TTY device.
    ") + (tty-out :type (satisfies tty-bufferp) + :initially nil + :fix (tty-buffer-fix x)) + (:doc "
  • ") + + (:doc "
"))) + +(make-event + `(defconst *x86-field-names-as-keywords* + ',(loop$ for i in (strip-cars *x86isa-state*) + when (not (equal i :doc)) + collect + (intern$ (symbol-name i) "KEYWORD")))) + +(defun xdoc-x86-state (xs) ;; xs: *x86isa-state* + (if (atom xs) + "" + (let* ((fld (car xs)) + (rest (xdoc-x86-state (cdr xs)))) + (if (equal (car fld) :doc) + (str::cat (cadr fld) rest) + (str::cat "@({ " (str::pretty fld + :config (str::make-printconfig + :home-package (pkg-witness "X86ISA") + :print-lowercase t)) + " })" rest))))) + +(with-output + :on summary + :summary-off #!acl2(:other-than errors time) + (make-event + `(rstobj2::defrstobj x86 + ,@(loop$ for fld in *x86isa-state* append + (if (equal (car fld) :doc) + nil + (list fld))) + :inline t + :non-memoizable t + :enable '(bigmem::read-mem-over-write-mem + bigmem::read-mem-from-nil + bigmem::loghead-identity-alt) + :accessor xr + :updater xw + :accessor-template ( x) + :updater-template (! x)))) + +(defthm x86p-xw + (implies (x86p x86) + (x86p (xw fld index val x86)))) + +(globally-disable '(x86p)) + +(defthm-signed-byte-p i64p-xr-rgf + :hyp t + :bound 64 + :concl (xr :rgf i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n32p-xr-rflags + :hyp t + :bound 32 + :concl (xr :rflags i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n16p-xr-seg-visible + :hyp t + :bound 16 + :concl (xr :seg-visible i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(encapsulate () + (local (include-book "kestrel/arithmetic-light/expt2" :dir :system)) + + (defthm unsigned-byte-p-of-xr-seg-visible + (implies (and (<= 16 size) + (integerp size)) + (unsigned-byte-p size (xr :seg-visible i x86))) + :hints (("Goal" :use n16p-xr-seg-visible + :in-theory (disable n16p-xr-seg-visible + elem-p-of-xr-seg-visible))))) + +(defthm-unsigned-byte-p n64p-xr-seg-hidden-base + :hyp t + :bound 64 + :concl (xr :seg-hidden-base i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n32p-xr-seg-hidden-limit + :hyp t + :bound 32 + :concl (xr :seg-hidden-limit i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n16p-xr-seg-hidden-attr + :hyp t + :bound 16 + :concl (xr :seg-hidden-attr i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n64p-xr-ssr-hidden-base + :hyp t + :bound 64 + :concl (xr :ssr-hidden-base i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n32p-xr-ssr-hidden-limit + :hyp t + :bound 32 + :concl (xr :ssr-hidden-limit i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n64p-xr-ctr + :hyp t + :bound 64 + :concl (xr :ctr i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n80p-xr-fp-data + :hyp t + :bound 80 + :concl (xr :fp-data i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n32p-xr-mxcsr + :hyp t + :bound 32 + :concl (xr :mxcsr i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n512p-xr-zmm + :hyp t + :bound 512 + :concl (xr :zmm i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n08p-xr-mem + :hyp t + :bound 8 + :concl (xr :mem i x86) + :gen-rewrite nil ; already done by defrstobj + :gen-linear t + :gen-type t) + +(defthm-unsigned-byte-p n64p-xr-msr + :hyp t + :bound 64 + :concl (xr :msr i x86) + :gen-linear t + :gen-type t) + +(defthm-signed-byte-p i48p-xr-rip + :hyp t + :bound 48 + :concl (xr :rip i x86) + :gen-linear t + :gen-type t) + +;; ---------------------------------------------------------------------- + +(make-event + `(defxdoc x86isa-state + :pkg "X86ISA" + :parents (machine) + :short "The state of the @('x86isa') model" + :long ,(str::cat + "

Definition of the @('x86isa') state

+ +

The definition of the state uses nested and abstract stobjs by way of + community books @(tsee rstobj2::defrstobj), @(tsee bigmem::bigmem), or @(tsee + bigmem-asymmetric::bigmem-asymmetric). It may be interesting to read about + the old definition to see how the current definition supports all of its + functionality but in a more maintainable way; see @(see + x86isa-state-history).

+ +

The @('bigmem') and @('bigmem-asymmetric') books define a memory model + similar to the old @('x86isa') memory model in that it provides a record + representation for reasoning and an allocate-on-demand, array-like performance + for execution. The x86 concrete stobj has the @('bigmem') stobj for its memory + field; @('defrstobj') exports the @('bigmem') memory accessor and updater + functions alongside those of other x86 fields and gives us a state definition + that's logically a multi-typed record. @('defrstobj') also allows the + definition of a universal accessor and updater, so we still retain that + feature in the @('x86isa') books.

+ +

Note that the @('bigmem') books define a 64-bit address space, + though the @('x86isa') state restricts that to a 52-bit address space + because the max. physical address allowed by the x86 architecture is + 52 (as of this writing in mid-2021). If the max. allowed physical + address is increased anywhere up to 64 bits, then we can simply + change the size of the @('mem') field in the @('x86isa') stobj.

+ +

x86 ISA state components modeled by @('x86isa')

" + + (xdoc-x86-state *x86isa-state*)))) + +(defxdoc x86isa-state-history + :parents (x86isa-state) + :short "A short history of the definition of the x86 state" + + :long "

Old definition of the @('x86isa') state

+ +

Before @(tsee bigmems::bigmems) and @(tsee rstobj2::defrstobj) were used to + define the x86 state, the x86 state's definition was rather tedious. (For + future reference, the following git revision has that old definition: + @('dea40263247bd930077205526934bc596686bfb0')).

+ +

This current file @('state.lisp') replaces the following old + files, all of which are deleted now.

+
    +
  • @('concrete-state.lisp')
  • +
  • @('concrete-memory.lisp')
  • +
  • @('abstract-state.lisp')
  • +
  • @('state-field-thms.lisp')
  • +
+ +

The old x86isa memory model was based on the FMCAD'2012 paper \"A + Formal Model of a Large Memory that Supports Efficient Execution\". + The following comment from the old file @('concrete-state.lisp') + describes it briefly:

+ + + .... + ;; For our ACL2 model, we define a paging-like mechanism to + ;; model the complete x86 52-bit address space. The memory is + ;; laid out in a flat array, to be viewed as back-to-back + ;; \"pseudo-pages\" each of size 2^27 bytes (128MB). The address + ;; of a byte is split into two pieces: a 25-bit pseudo-page + ;; address and a 27-bit offset within a page. The mem-table + ;; data structure is of size *mem-table-size* = 2^25 -- thus, + ;; indices are 25 bits -- and it maps these indices to 25-bit + ;; pseudo-page addresses. However, the mem-table values are + ;; actually 26-bit values: the least significant bit is + ;; initially 1, but is 0 when the entry is valid, in which case + ;; the most significant 25 bits represent a pseudo-page address. + ;; The offset of a byte address is a 27-bit wide address, which + ;; when added to (ash pseudo-page-address 27), gives the \"real\" + ;; address of a byte stored in mem-array. Mem-array-next-addr + ;; keeps track of the 25-bit index of the pseudo-page to be + ;; allocated next. + + ;; Here is an example of how this works. Suppose we have the + ;; following, where again, the least significant bit of 0 + ;; indicates a valid entry, and where {i, 1'bx} denotes + ;; concatenation of the bit-vector i with the single bit x. + + ;; mem-table[#x0654321] = {0, 1'b0} + ;; mem-table[#x16789ab] = {1, 1'b0} + ;; mem-table[#x0111111] = {2, 1'b0} + + ;; All additional values in mem-table are the initial value of + ;; 1, which means \"page is not present\". + + ;; Then mem-array starts as follows. + + ;; 2^27 bytes corresponding to byte addresses with top 25 bits = #x0654321 + ;; 2^27 bytes corresponding to byte addresses with top 25 bits = #x16789ab + ;; 2^27 bytes corresponding to byte addresses with top 25 bits = #x0111111 + + (mem-table :type (array (unsigned-byte #.*mem-table-size-bits+1*) + ;; *mem-table-size-bits* of pseudo-page + ;; address, followed by 1 extra bit + ;; (LSB) to indicate the + ;; absence/presence of pseudo-pages + (#.*mem-table-size*)) + :initially 1 + :resizable nil) + + (mem-array :type (array (unsigned-byte 8) + (#.*initial-mem-array-length*)) + :initially 0 + :resizable t) + + (mem-array-next-addr :type (integer 0 #.*mem-table-size*) + :initially 0) + + ... + + +

The proof of correctness of this memory model was pretty + involved (see the old file @('concrete-memory.lisp')). Then there + was the overhead of introducing an abstract stobj to logically view + this memory as a record (see old file @('abstract-stobj.lisp')).

+ +

All of this was finished before nested stobjs were supported in + ACL2, so there was not much incentive to simplify the memory model or + the state definition.

+ +
Non-interference Properties
+ +

We used a neat trick for all the accessors and updaters of + the @('x86isa') state's field that is worth mentioning here. Say + @('RGFI*') is the name of the corresponding exported accessor from + defabsstobj; during execution, @('RGFI*') calls are really + @('RGF$CI') calls, the concrete accessor from the corresponding + concrete stobj.

+ + Signature: (RGFI* index x86) + +

We also defined a universal accessor function @('XR'), meant to be + used only for reasoning:

+ + Signature: (XR fld-name index x86) + +

@('XR') case-split on @('fld-name') and called the appropriate + accessor function (e.g., if fld-name was @(':RGF'), @('XR') called + @('RGFI*'), and so on). We defined a similar universal updater + function @('XW'). We then proved read-over-write/write-over-write, + etc. lemmas about just @('XR') and @('XW'), thereby getting these + properties for all fields of the x86 state. This way, we avoid a + blow-up in the number of such lemmas as the number of fields in the + state increase.

+ +

We then defined another function, @('RGFI') (inlined), with the + same signature as @('RGFI*'), whose body was an @('MBE') like + so:

+ + + (RGFI index x86) := + (mbe :logic (XR :RGF index x86) + :exec (RGFI* index x86)) + + +

We then used @('RGFI') as the canonical accessor function for the + @('RGF') field --- we never used @('RGFI*') or @('XR') in our + definitions from this point on, though @('XR') was often used in + definitions where we didn't care about the execution speed (e.g., + non-executable functions used only for reasoning). We kept @('RGFI') + enabled and @('XR') disabled.

+ +

The consequence of this was that whenever an @('RGFI') call was + encountered during reasoning, it quickly opened up to @('XR') (about + which we have all those nice theorems). During execution, @('RGFI') + was simply the efficient concrete accessor @('RGF$CI').

") + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/three-byte-opcodes-dispatch.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/three-byte-opcodes-dispatch.lisp new file mode 100644 index 000000000..2b4d1db21 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/three-byte-opcodes-dispatch.lisp @@ -0,0 +1,276 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2018, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +;; (include-book "instructions/top" :ttags (:syscall-exec)) +;; Other instruction books may be needed here eventually: +(include-book "instructions/arith-and-logic") +(include-book "instructions/bit") +(include-book "instructions/move") +(include-book "decoding-and-spec-utils") +(include-book "prefix-modrm-sib-decoding") +(include-book "dispatch-macros") +(include-book "cpuid") +(include-book "std/strings/hexify" :dir :system) + +(local (include-book "dispatch-creator")) +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "centaur/bitops/signed-byte-p" :dir :system)) + +(local (in-theory (e/d () + (app-view-rml08-no-error + (:meta acl2::mv-nth-cons-meta) + rme08-value-when-error + member-equal)))) + +(local (xdoc::set-default-parents x86-decoder)) + +;; ---------------------------------------------------------------------- + + +(make-event + (b* ((dispatch + (create-dispatch-for-opcodes + #ux0F_38_00 256 :0F-38-three-byte (w state)))) + + `(define first-three-byte-opcode-execute + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (mandatory-prefix :type (unsigned-byte 8)) + (rex-byte :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8)) + (modr/m :type (unsigned-byte 8)) + (sib :type (unsigned-byte 8)) + x86) + + ;; #x0F #x38 are the first two opcode bytes. + + :parents (x86-decoder) + ;; The following arg will avoid binding __function__ to + ;; first-three-byte-opcode-execute. The automatic __function__ binding + ;; that comes with define causes stack overflows during the guard proof + ;; of this function. + :no-function t + :ignore-ok t + :short "First three-byte opcode dispatch function." + :long "

@('first-three-byte-opcode-execute') is the doorway to the + first three-byte opcode map, i.e., to all three-byte opcodes whose first + two opcode bytes are @('0F 38').

" + :guard-hints (("Goal" + :do-not '(preprocess) + :in-theory + (e/d + () + (unsigned-byte-p signed-byte-p)))) + :guard (rip-guard-okp proc-mode temp-rip) + (case opcode ,@dispatch) + + /// + + (defthm x86p-first-three-byte-opcode-execute + (implies (x86p x86) + (x86p + (first-three-byte-opcode-execute + proc-mode start-rip temp-rip prefixes + mandatory-prefix rex-byte opcode modr/m sib x86))))))) + +(make-event + (b* ((dispatch + (create-dispatch-for-opcodes + #ux0F_3A_00 256 :0F-3A-three-byte (w state)))) + + `(define second-three-byte-opcode-execute + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (mandatory-prefix :type (unsigned-byte 8)) + (rex-byte :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8)) + (modr/m :type (unsigned-byte 8)) + (sib :type (unsigned-byte 8)) + x86) + + ;; #x0F #x3A are the first two opcode bytes. + + :parents (x86-decoder) + ;; The following arg will avoid binding __function__ to + ;; second-three-byte-opcode-execute. The automatic __function__ binding that + ;; comes with define causes stack overflows during the guard proof of this + ;; function. + :no-function t + :ignore-ok t + :short "Second three-byte opcode dispatch function." + :long "

@('second-three-byte-opcode-execute') is the doorway to the second + three-byte opcode map, i.e., to all three-byte opcodes whose second two + opcode bytes are @('0F 3A').

" + :guard (rip-guard-okp proc-mode temp-rip) + :guard-hints (("Goal" + :do-not '(preprocess) + :in-theory (e/d () (unsigned-byte-p signed-byte-p)))) + + (case opcode ,@dispatch) + + /// + + (defthm x86p-second-three-byte-opcode-execute + (implies (x86p x86) + (x86p (second-three-byte-opcode-execute + proc-mode start-rip temp-rip prefixes + mandatory-prefix rex-byte opcode modr/m sib x86))))))) + + +(local (defthm unsigned-byte-p-when-lte-loghead + (implies (and (natp x) + (natp n) + (<= x (loghead n y))) + (unsigned-byte-p n x)) + :hints(("Goal" :in-theory (enable unsigned-byte-p) + :use ((:instance acl2::unsigned-byte-p-loghead + (size n) (size1 n) (i y))))))) + + +(define three-byte-opcode-decode-and-execute + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (rex-byte :type (unsigned-byte 8)) + (second-escape-byte :type (unsigned-byte 8)) + x86) + + :ignore-ok t + :guard (or (equal second-escape-byte #x38) + (equal second-escape-byte #x3A)) + :guard-hints (("Goal" :do-not '(preprocess) + :in-theory (e/d* + (add-to-*ip add-to-*ip-is-i48p-rewrite-rule) + (unsigned-byte-p + (:type-prescription bitops::logand-natp-type-2) + (:type-prescription bitops::ash-natp-type) + acl2::loghead-identity + not + tau-system + (tau-system))))) + :parents (x86-decoder) + :short "Decoder and dispatch function for three-byte opcodes, where @('0x0F + 0x38') are the first two opcode bytes" + :long "

Source: Intel Manual, Volume 2, Appendix A-2

" + + (b* ((ctx 'three-byte-opcode-decode-and-execute) + + ((mv flg0 (the (unsigned-byte 8) opcode) x86) + (rme08 proc-mode temp-rip #.*cs* :x x86)) + ((when flg0) + (!!ms-fresh :opcode-byte-access-error flg0)) + + ;; Possible values of opcode: all values denote opcodes of the first or + ;; second three-byte map, depending on the value of second-escape-byte. + ;; The function first-three-byte-opcode-execute or + ;; second-three-byte-opcode-execute case-splits on this opcode byte and + ;; calls the appropriate instruction semantic function. + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :increment-error flg)) + + ;; ((mv msg (the (unsigned-byte 8) mandatory-prefix)) + ;; (compute-mandatory-prefix-for-three-byte-opcode + ;; proc-mode second-escape-byte opcode prefixes)) + ;; ((when msg) + ;; (x86-illegal-instruction msg start-rip temp-rip x86)) + + ((the (unsigned-byte 8) mandatory-prefix) + (compute-mandatory-prefix-for-three-byte-opcode + proc-mode second-escape-byte opcode prefixes)) + (modr/m? + (three-byte-opcode-ModR/M-p + proc-mode mandatory-prefix second-escape-byte opcode)) + ((mv flg1 (the (unsigned-byte 8) modr/m) x86) + (if modr/m? + (rme08 proc-mode temp-rip #.*cs* :x x86) + (mv nil 0 x86))) + ((when flg1) (!!ms-fresh :modr/m-byte-read-error flg1)) + + ((mv flg temp-rip) (if modr/m? + (add-to-*ip proc-mode temp-rip 1 x86) + (mv nil temp-rip))) + ((when flg) (!!ms-fresh :increment-error flg)) + + (sib? (and modr/m? + (b* ((p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + (16-bit-addressp (eql 2 (select-address-size proc-mode p4? x86)))) + (x86-decode-SIB-p modr/m 16-bit-addressp)))) + ((mv flg2 (the (unsigned-byte 8) sib) x86) + (if sib? + (rme08 proc-mode temp-rip #.*cs* :x x86) + (mv nil 0 x86))) + ((when flg2) + (!!ms-fresh :sib-byte-read-error flg2)) + + ((mv flg temp-rip) (if sib? + (add-to-*ip proc-mode temp-rip 1 x86) + (mv nil temp-rip))) + ((when flg) (!!ms-fresh :increment-error flg))) + + (case second-escape-byte + (#x38 + (first-three-byte-opcode-execute + proc-mode start-rip temp-rip prefixes mandatory-prefix + rex-byte opcode modr/m sib x86)) + (#x3A + (second-three-byte-opcode-execute + proc-mode start-rip temp-rip prefixes mandatory-prefix + rex-byte opcode modr/m sib x86)) + (otherwise + ;; Unreachable. + (!!ms-fresh :illegal-value-of-second-escape-byte second-escape-byte)))) + + /// + + (defrule x86p-three-byte-opcode-decode-and-execute + (implies (x86p x86) + (x86p (three-byte-opcode-decode-and-execute + proc-mode start-rip temp-rip prefixes rex-byte escape-byte x86))) + :enable add-to-*ip-is-i48p-rewrite-rule + :disable signed-byte-p)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/top-level-memory.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/top-level-memory.lisp new file mode 100644 index 000000000..a90d33b69 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/top-level-memory.lisp @@ -0,0 +1,1982 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2024, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) +; Contributing Author(s): +; Dmitry Nadezhin +; Shilpi Goel + +(in-package "X86ISA") + +;; ---------------------------------------------------------------------- + +(include-book "segmentation") + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +;; ---------------------------------------------------------------------- + +(defsection top-level-memory + :parents (machine) + :short "Top-level Memory Accessor and Updater Functions" + ) + +(local (xdoc::set-default-parents top-level-memory)) + +;; ---------------------------------------------------------------------- + +(define address-aligned-p + ((addr :type (signed-byte #.*max-linear-address-size*)) + (operand-size :type (member 1 2 4 6 8 10 16 32 64)) + (memory-ptr? booleanp)) + :inline t + :no-function t + :returns (yes/no booleanp :rule-classes :type-prescription) + :short "Check the alignment of a linear address." + :long + "

+ Besides the address to check for alignment, + this function takes as argument the operand size + (from which the alignment to check is determined) + and a flag indicating whether the address to check for alignment + contains a memory operand of the form m16:16, m16:32, or m16:64 + (see Intel manual, Mar'17, Volume 2, Section 3.1.1.3). +

+

+ Words, doublewords, quadwords, and double quadwords + must be aligned at boundaries of 2, 4, 8, or 16 bytes. + Memory pointers of the form m16:xx must be aligned so that + their xx portion is aligned as a word, doubleword, or quadword; + this automatically guarantees that their m16 portion is aligned as a word. + See Intel manual, Mar'17, Volume 1, Section 4.1.1. + See AMD manual, Dec'17, Volume 2, Table 8-7 + (note that the table does not mention explicitly + memory pointers of the form m16:64). +

+

+ If the operand size is 6, the operand must be an m16:32 pointer. + If the operand size is 10, the operand must an m16:64 pointer. + If the operand size is 4, it may be either an m16:16 pointer or not; + in this case, the @('memory-ptr?') argument is used to + determine whether the address should be aligned + at a word or doubleword boundary. + If the operand size is 1, 2, 8, or 16, + it cannot be a memory pointer of the form m16:xx. +

" + (b* ((addr (the (signed-byte #.*max-linear-address-size*) addr)) + (operand-size (the (integer 0 65) operand-size))) + (case operand-size + ;; Every byte access is always aligned. + (1 t) + (6 (equal (logand addr #b11) 0)) ; m16:32 + (10 (equal (logand addr #b111) 0)) ; m16:64 + (otherwise + (if (and memory-ptr? + (eql operand-size 4)) + (equal (logand addr #b1) 0) ; m16:16 + (equal (logand addr (the (integer 0 65) (- operand-size 1))) + 0))))) + + /// + + (defthm memory-byte-accesses-are-always-aligned + (equal (address-aligned-p addr 1 mem-ptr?) t)) + + (defthm address-aligned-p-mem-ptr-input-irrelevant-for-all-but-bytes=4 + (implies (and (syntaxp (not (equal mem-ptr? ''nil))) + (not (equal nbytes 4))) + (equal (address-aligned-p addr nbytes mem-ptr?) + (address-aligned-p addr nbytes nil))))) + +;; ---------------------------------------------------------------------- + +;; Memory Read Functions: + +(define gen-read-function (&key + (size natp) + (signed? booleanp) + (check-alignment?-var booleanp) + (mem-ptr?-var booleanp)) + :mode :program + + (b* ((size-str (symbol-name (if (< size 10) + (acl2::packn (list 0 size)) + (acl2::packn (list size))))) + (fn (str::cat (if signed? "RIME" "RME") size-str)) + (fn-name (intern$ fn "X86ISA")) + (fn-call `(,fn-name proc-mode eff-addr seg-reg r-x + ,@(and check-alignment?-var + '(check-alignment?)) + x86 + ,@(and mem-ptr?-var + `(:mem-ptr? mem-ptr?)))) + (lin-mem-fn (str::cat (if signed? "RIML" "RML") size-str)) + (lin-mem-fn-name (intern$ lin-mem-fn "X86ISA")) + (short-doc-string + (str::cat + "Read " + (if signed? "a signed " "an unsigned ") + (str::nat-to-dec-string size) + "-bit value from memory via an effective address.")) + (long-doc-string + (str::cat + "

The effective address @('eff-addr') is translated to a canonical + linear address using @(see ea-to-la). If this translation is + successful and no other errors (like alignment errors) occur, then + @(see " lin-mem-fn ") is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored (see Atmel manual, Dec'17, Volume 2, Section 4.8.1).

"))) + + `(define ,fn-name ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (eff-addr :type (signed-byte 64)) + (seg-reg :type (integer 0 #.*segment-register-names-len-1*)) + (r-x :type (member :r :x)) + ,@(and check-alignment?-var `((check-alignment? booleanp))) + x86 + ,@(and mem-ptr?-var `(&key ((mem-ptr? booleanp) 'nil)))) + :inline t + :no-function t + :returns (mv flg + (value + (,(if signed? 'signed-byte-p 'unsigned-byte-p) ,size value) + :hyp (x86p x86)) + (x86-new x86p :hyp (x86p x86))) + :parents (top-level-memory) + + :short ,short-doc-string + :long ,long-doc-string + + (b* (((when (and + (/= proc-mode #.*64-bit-mode*) + (= seg-reg #.*cs*) + (eq r-x :r) + (b* ((attr (loghead 16 (seg-hidden-attri seg-reg x86))) + (r (code-segment-descriptor-attributesBits->r attr))) + (= r 0)))) + (mv (list :execute-only-code-segment eff-addr) 0 x86)) + ((mv flg lin-addr) + (ea-to-la proc-mode eff-addr seg-reg ,(/ size 8) x86)) + ((when flg) (mv flg 0 x86)) + ,@(and + check-alignment?-var + `(((unless (or (not check-alignment?) + (address-aligned-p + lin-addr + ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))) + (mv (list :unaligned-linear-address lin-addr) 0 x86))))) + (,lin-mem-fn-name lin-addr r-x x86)) + /// + + (,(if signed? 'defthm-signed-byte-p 'defthm-unsigned-byte-p) + ,(mk-name (if signed? "I" "N") size-str "P-OF-MV-NTH-1-" fn) + :hyp t + :bound ,size + :concl (mv-nth 1 ,fn-call) + :gen-linear t + :gen-type t) + + (defrule ,(mk-name fn "-VALUE-WHEN-ERROR") + (implies (mv-nth 0 ,fn-call) + (equal (mv-nth 1 ,fn-call) 0)) + :enable (,@(and signed? + `(,lin-mem-fn-name + ;; ,(mk-name "RML" size-str) + )) + )) + + (defrule ,(mk-name fn "-DOES-NOT-AFFECT-STATE-IN-APP-VIEW") + (implies (app-view x86) + (equal (mv-nth 2 ,fn-call) x86)) + :enable (,@(and signed? + `(,lin-mem-fn-name + ;; ,(mk-name "RML" size-str) + )) + )) + + (defrule ,(mk-name "XR-" fn "-STATE-APP-VIEW") + (implies (app-view x86) + (equal (xr fld index (mv-nth 2 ,fn-call)) + (xr fld index x86))) + :enable (,@(and signed? + `(,lin-mem-fn-name + ;; ,(mk-name "RML" size-str) + )))) + + (defrule ,(mk-name "XR-" fn "-STATE-SYS-VIEW") + (implies (and ;; (not (app-view x86)) + (not (equal fld :mem)) + (not (equal fld :fault)) + (not (equal fld :tlb)) + ;; ,@(if (< size 10) + ;; nil + ;; `((member-equal fld *x86-field-names-as-keywords*))) + ) + (equal (xr fld index (mv-nth 2 ,fn-call)) + (xr fld index x86))) + :enable (,@(and signed? + `(,lin-mem-fn-name + ;; ,(mk-name "RML" size-str) + ))) + ,@(if (< size 10) + nil + `(:disable (rb unsigned-byte-p signed-byte-p member-equal)))) + + (defrule ,(mk-name fn "-XW-APP-VIEW") + (implies + (and (app-view x86) + (not (equal fld :mem)) + (not (equal fld :app-view)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :seg-visible)) + (not (equal fld :msr))) + (and + (equal (mv-nth 0 + ,(search-and-replace-once + 'x86 + '(xw fld index value x86) + fn-call)) + (mv-nth 0 ,fn-call)) + (equal (mv-nth 1 ,(search-and-replace-once + 'x86 + '(xw fld index value x86) + fn-call)) + (mv-nth 1 ,fn-call)) + ;; No need for the conclusion about the state; see + ;; ,(mk-name fn "-DOES-NOT-AFFECT-STATE-IN-APP-VIEW") + )) + :enable (,@(and signed? + `(,lin-mem-fn-name + ;; ,(mk-name "RML" size-str) + ))) + :disable (rb)) + + (defrule ,(mk-name fn "-XW-SYS-VIEW") + (implies + (and (not (app-view x86)) + (not (equal fld :fault)) + (not (equal fld :seg-visible)) + (not (equal fld :seg-hidden-base)) + (not (equal fld :seg-hidden-limit)) + (not (equal fld :seg-hidden-attr)) + (not (equal fld :mem)) + (not (equal fld :ctr)) + (not (equal fld :msr)) + (not (equal fld :rflags)) + (not (equal fld :app-view)) + (not (equal fld :tlb)) + (not (equal fld :marking-view)) + (not (equal fld :implicit-supervisor-access)) + ,@(if (< size 10) + nil + `((member-equal fld *x86-field-names-as-keywords*)))) + (and + (equal + (mv-nth 0 ,(search-and-replace-once + 'x86 + '(xw fld index value x86) + fn-call)) + (mv-nth 0 ,fn-call)) + (equal + (mv-nth 1 ,(search-and-replace-once + 'x86 + '(xw fld index value x86) + fn-call)) + (mv-nth 1 ,fn-call)) + (equal + (mv-nth 2 ,(search-and-replace-once + 'x86 + '(xw fld index value x86) + fn-call)) + (xw fld index value (mv-nth 2 ,fn-call))))) + :enable (,@(and signed? + `(,lin-mem-fn-name + ;; ,(mk-name "RML" size-str) + ))) + ,@(if (< size 10) + nil + `(:disable (rb unsigned-byte-p signed-byte-p member-equal)))) + + (defrule ,(mk-name fn "-XW-SYS-VIEW-RFLAGS-NOT-AC") + (implies + (and (not (app-view x86)) + (equal (rflagsBits->ac value) + (rflagsBits->ac (rflags x86)))) + (and + (equal + (mv-nth 0 ,(search-and-replace-once + 'x86 + '(xw :rflags nil value x86) + fn-call)) + (mv-nth 0 ,fn-call)) + (equal + (mv-nth 1 ,(search-and-replace-once + 'x86 + '(xw :rflags nil value x86) + fn-call)) + (mv-nth 1 ,fn-call)) + (equal + (mv-nth 2 ,(search-and-replace-once + 'x86 + '(xw :rflags nil value x86) + fn-call)) + (xw :rflags nil value (mv-nth 2 ,fn-call))))) + :enable (,@(and signed? + `(,lin-mem-fn-name + ;; ,(mk-name "RML" size-str) + ))) + :disable (rb unsigned-byte-p signed-byte-p)) + + (defrule ,(mk-name fn "-WHEN-64-BIT-MODEP-AND-NOT-FS/GS") + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (canonical-address-p eff-addr) + ,@(and check-alignment?-var + `((or (not check-alignment?) + (address-aligned-p + eff-addr ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))))) + (equal ,(search-and-replace-once 'proc-mode + '#.*64-bit-mode* + fn-call) + (,lin-mem-fn-name eff-addr r-x x86)))) + + ,@(and + check-alignment?-var + `((defrule ,(mk-name fn "-UNALIGNED-WHEN-64-BIT-MODEP-AND-NOT-FS/GS") + (implies + (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not + (or (not check-alignment?) + (address-aligned-p + eff-addr + ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))) + (canonical-address-p eff-addr)) + (equal ,(search-and-replace-once 'proc-mode + '#.*64-bit-mode* + fn-call) + (list (list :unaligned-linear-address eff-addr) + 0 + x86)))))) + + (defrule ,(mk-name fn "-WHEN-64-BIT-MODEP-AND-FS/GS") + (implies + (or (equal seg-reg #.*fs*) + (equal seg-reg #.*gs*)) + (equal + ,(search-and-replace-once 'proc-mode '#.*64-bit-mode* fn-call) + (b* (((mv flg lin-addr) + (b* (((mv base & &) + (segment-base-and-bounds 0 seg-reg x86)) + (lin-addr (i64 (+ base (n64 eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0)))) + ((when flg) + (mv flg 0 x86)) + ,@(and + check-alignment?-var + `(((unless (or (not check-alignment?) + (address-aligned-p + lin-addr + ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))) + (mv (list :unaligned-linear-address lin-addr) 0 x86))))) + (,lin-mem-fn-name lin-addr r-x x86)))) + :hints (("Goal" :in-theory (e/d (ea-to-la) ()))))))) + +(make-event + `(progn + (local (in-theory (e/d () + (unsigned-byte-p + signed-byte-p + force (force))))) + ;; rme08 + ,(gen-read-function :size 8 + :signed? nil + :check-alignment?-var nil + :mem-ptr?-var nil) + ;; rime08 + ,(gen-read-function :size 8 + :signed? t + :check-alignment?-var nil + :mem-ptr?-var nil) + ;; rme16 + ,(gen-read-function :size 16 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; rime16 + ,(gen-read-function :size 16 + :signed? t + :check-alignment?-var t + :mem-ptr?-var nil) + ;; rme32 + ,(gen-read-function :size 32 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var t) + ;; rime32 + ,(gen-read-function :size 32 + :signed? t + :check-alignment?-var t + :mem-ptr?-var t) + ;; rme48 + ,(gen-read-function :size 48 ;; typically a m16:32 pointer + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; rme64 + ,(gen-read-function :size 64 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; rime64 + ,(gen-read-function :size 64 + :signed? t + :check-alignment?-var t + :mem-ptr?-var nil) + ;; rme80 + ,(gen-read-function :size 80 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; rme128 + ;; Note: A #GP exception should be thrown here instead of an #AC fault when + ;; the address is not aligned. See Intel Manuals, Volume 3, Section 6.15, + ;; Exception and Interrupt Reference, Interrupt 17 Alignment Check + ;; Exception (#AC). + ,(gen-read-function :size 128 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; rme256 + ;; Note: A #GP exception should be thrown here instead of an #AC fault when + ;; the address is not aligned. See Intel Manuals, Volume 2, Tables 2-18 and + ;; 2-44. + ,(gen-read-function :size 256 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil))) + +(define rme-size + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (nbytes :type (member 1 2 4 6 8 10 16 32)) + (eff-addr :type (signed-byte 64)) + (seg-reg :type (integer 0 #.*segment-register-names-len-1*)) + (r-x :type (member :r :x)) + (check-alignment? booleanp) + x86 + &key + ;; Default value for mem-ptr? is nil --- note that this input is + ;; relevant only for nbytes = 4. + ((mem-ptr? booleanp) 'nil)) + :returns (mv flg + (value natp :rule-classes (:rewrite :type-prescription)) + (x86-new x86p :hyp (x86p x86))) + :parents (top-level-memory) + :short "Read an unsigned value with the specified number of bytes + from memory via an effective address." + :long + "

The effective address is translated to a canonical linear address using + @(see ea-to-la). If this translation is successful and no other errors (like + alignment errors) occur, then @(see rml-size) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored; see Intel manual, Dec'17, Volume 2, Section 4.8.1

" + (b* (((when (and (/= proc-mode #.*64-bit-mode*) + (= seg-reg #.*cs*) + (eq r-x :r) + (b* ((attr (loghead 16 (seg-hidden-attri seg-reg x86))) + (r (code-segment-descriptor-attributesBits->r attr))) + (= r 0)))) + (mv (list :execute-only-code-segment eff-addr) 0 x86)) + ((mv flg lin-addr) (ea-to-la proc-mode eff-addr seg-reg nbytes x86)) + ((when flg) (mv flg 0 x86)) + ((unless (or (not check-alignment?) + (address-aligned-p lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) 0 x86))) + (rml-size nbytes lin-addr r-x x86)) + :inline t + :no-function t + + /// + + (defrule rme-size-when-64-bit-modep-and-not-fs/gs + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (canonical-address-p eff-addr) + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (equal (rme-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rml-size nbytes eff-addr r-x x86)))) + + (defrule rme-size-when-64-bit-modep-fs/gs + (implies (or (equal seg-reg #.*fs*) + (equal seg-reg #.*gs*)) + (equal (rme-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (b* (((mv flg lin-addr) + (b* (((mv base & &) + (segment-base-and-bounds 0 seg-reg x86)) + (lin-addr (i64 (+ base (n64 eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0)))) + ((when flg) + (mv flg 0 x86)) + ((unless (or (not check-alignment?) + (address-aligned-p + lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) 0 x86))) + (rml-size nbytes lin-addr r-x x86)))) + :in-theory (e/d (ea-to-la) ())) + + (defthm rme-size-unaligned-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of rme-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (canonical-address-p eff-addr)) + (equal (rme-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :unaligned-linear-address eff-addr) + 0 x86))) + :hints (("Goal" :in-theory (e/d (rme-size) ())))) + + (defthm rme-size-non-canonical-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of rme-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not (canonical-address-p eff-addr))) + (equal (rme-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :non-canonical-address eff-addr) 0 x86))) + :hints (("Goal" :in-theory (e/d (rme-size) ())))) + + (defruled rme-size-of-1-to-rme08 + (equal + (rme-size proc-mode 1 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme08 proc-mode eff-addr seg-reg r-x x86)) + :enable (rme-size rme08)) + + (defruled rme-size-of-2-to-rme16 + (equal + (rme-size proc-mode 2 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme16 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rme-size rme16)) + + (defruled rme-size-of-4-to-rme32 + (equal + (rme-size proc-mode 4 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme32 proc-mode eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?)) + :enable (rme-size rme32)) + + (defruled rme-size-of-6-to-rme48 + (equal + (rme-size proc-mode 6 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme48 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rme-size rme48)) + + (defruled rme-size-of-8-to-rme64 + (equal + (rme-size proc-mode 8 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme64 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rme-size rme64)) + + (defruled rme-size-of-10-to-rme64 + (equal + (rme-size proc-mode 10 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme80 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rme-size rme80)) + + (defruled rme-size-of-16-to-rme128 + (equal + (rme-size proc-mode 16 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme128 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rme-size rme128)) + + (defruled rme-size-of-32-to-rme256 + (equal + (rme-size proc-mode 32 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rme256 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rme-size rme256)) + + (defthm unsigned-byte-p-of-mv-nth-1-of-rme-size + (implies (and (<= (* 8 nbytes) size) + (natp size)) + (unsigned-byte-p size (mv-nth 1 (rme-size proc-mode nbytes eff-addr seg-reg r-x check-alignment? x86)))) + :hints (("Goal" :in-theory (disable rml-size))))) + +(define rime-size + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (nbytes :type (member 1 2 4 8)) + (eff-addr :type (signed-byte 64)) + (seg-reg :type (integer 0 #.*segment-register-names-len-1*)) + (r-x :type (member :r :x)) + (check-alignment? booleanp) + x86 + &key + ;; Default value for mem-ptr? is nil --- note that this input is + ;; relevant only for nbytes = 4. + ((mem-ptr? booleanp) 'nil)) + :returns (mv flg + (value integerp :hyp (integerp nbytes)) + (x86-new x86p :hyp (x86p x86))) + :parents (top-level-memory) + :short "Read a signed value with the specified number of bytes + from memory via an effective address." + :long + "

The effective address is translated to a canonical linear address using + @(see ea-to-la). If this translation is successful and no other errors (like + alignment errors) occur, then @(see riml-size) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored; see Atmel manual, Dec'17, Volume 2, Section 4.8.1

" + (b* (((when (and (/= proc-mode #.*64-bit-mode*) + (= seg-reg #.*cs*) + (eq r-x :r) + (b* ((attr (loghead 16 (seg-hidden-attri seg-reg x86))) + (r (code-segment-descriptor-attributesBits->r attr))) + (= r 0)))) + (mv (list :execute-only-code-segment eff-addr) 0 x86)) + ((mv flg lin-addr) (ea-to-la proc-mode eff-addr seg-reg nbytes x86)) + ((when flg) (mv flg 0 x86)) + ((unless (or (not check-alignment?) + (address-aligned-p lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) 0 x86))) + (riml-size nbytes lin-addr r-x x86)) + :inline t + :no-function t + /// + + (defrule rime-size-when-64-bit-modep-and-not-fs/gs + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (canonical-address-p eff-addr) + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (equal (rime-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (riml-size nbytes eff-addr r-x x86)))) + + (defrule rime-size-when-64-bit-modep-fs/gs + (implies (or (equal seg-reg #.*fs*) + (equal seg-reg #.*gs*)) + (equal (rime-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (b* (((mv flg lin-addr) + (b* (((mv base & &) + (segment-base-and-bounds 0 seg-reg x86)) + (lin-addr (i64 (+ base (n64 eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0)))) + ((when flg) + (mv flg 0 x86)) + ((unless (or (not check-alignment?) + (address-aligned-p + lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) 0 x86))) + (riml-size nbytes lin-addr r-x x86)))) + :in-theory (e/d (ea-to-la) ())) + + (defthm rime-size-unaligned-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of rime-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (canonical-address-p eff-addr)) + (equal (rime-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :unaligned-linear-address eff-addr) + 0 x86))) + :hints (("Goal" :in-theory (e/d (rime-size) ())))) + + (defthm rime-size-non-canonical-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of rime-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not (canonical-address-p eff-addr))) + (equal (rime-size #.*64-bit-mode* + nbytes eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :non-canonical-address eff-addr) 0 x86))) + :hints (("Goal" :in-theory (e/d (rime-size) ())))) + + (defruled rime-size-of-1-to-rime08 + (equal (rime-size proc-mode 1 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rime08 proc-mode eff-addr seg-reg r-x x86)) + :enable (rime-size rime08)) + + (defruled rime-size-of-2-to-rime16 + (equal (rime-size proc-mode 2 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rime16 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rime-size rime16)) + + (defruled rime-size-of-4-to-rime32 + (equal + (rime-size proc-mode 4 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rime32 proc-mode eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?)) + :enable (rime-size rime32)) + + (defruled rime-size-of-8-to-rime64 + (equal + (rime-size proc-mode 8 eff-addr seg-reg r-x check-alignment? x86 + :mem-ptr? mem-ptr?) + (rime64 proc-mode eff-addr seg-reg r-x check-alignment? x86)) + :enable (rime-size rime64)) + + (defthm signed-byte-p-of-mv-nth-1-of-rime-size + (implies (and (<= (* 8 nbytes) size) + (member-equal nbytes '(1 2 4 8)) + (integerp size)) + (signed-byte-p size (mv-nth 1 (rime-size proc-mode nbytes eff-addr seg-reg r-x check-alignment? x86)))))) + +;; ---------------------------------------------------------------------- + +;; Memory Write Functions: + +(define gen-write-function (&key + (size natp) + (signed? booleanp) + (check-alignment?-var booleanp) + (mem-ptr?-var booleanp)) + :mode :program + + (b* ((size-str (symbol-name (if (< size 10) + (acl2::packn (list 0 size)) + (acl2::packn (list size))))) + (fn (str::cat (if signed? "WIME" "WME") size-str)) + (fn-name (intern$ fn "X86ISA")) + (fn-call `(,fn-name proc-mode eff-addr seg-reg val + ,@(and check-alignment?-var + '(check-alignment?)) + x86 + ,@(and mem-ptr?-var + `(:mem-ptr? mem-ptr?)))) + (lin-mem-fn (str::cat (if signed? "WIML" "WML") size-str)) + (lin-mem-fn-name (intern$ lin-mem-fn "X86ISA")) + (short-doc-string + (str::cat + "Write " + (if signed? "a signed " "an unsigned ") + (str::nat-to-dec-string size) + "-bit value to memory via an effective address.")) + (long-doc-string + (str::cat + "

The effective address @('eff-addr') is translated to a canonical + linear address. If this translation is successful and no other error + occurs (like alignment errors), then @(see " lin-mem-fn ") is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments (DS, ES, FS, GS, and SS) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments (this is + not explicitly mentioned in Intel manual, May'18, Volume 3, Section + 3.4.5.1, but it seems reasonable). In 64-bit mode, the W bit is + ignored (see Atmel manual, Dec'17, Volume 2, Section 4.8.1); by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

"))) + + `(define ,fn-name ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (eff-addr :type (signed-byte 64)) + (seg-reg :type (integer 0 #.*segment-register-names-len-1*)) + (val :type (,(if signed? 'signed-byte 'unsigned-byte) ,size)) + ,@(and check-alignment?-var `((check-alignment? booleanp))) + x86 + ,@(and mem-ptr?-var `(&key ((mem-ptr? booleanp) 'nil)))) + :inline t + :no-function t + :returns (mv flg + (x86-new x86p :hyp (x86p x86))) + :parents (top-level-memory) + + :short ,short-doc-string + :long ,long-doc-string + + (b* (((when (and (/= proc-mode #.*64-bit-mode*) + (or (= seg-reg #.*cs*) + (b* ((attr (loghead + 16 (seg-hidden-attri seg-reg x86))) + (w (data-segment-descriptor-attributesBits->w + attr))) + (= w 0))))) + (mv (list :non-writable-segment eff-addr seg-reg) x86)) + ((mv flg lin-addr) + (ea-to-la proc-mode eff-addr seg-reg ,(/ size 8) x86)) + ((when flg) (mv flg x86)) + ,@(and + check-alignment?-var + `(((unless (or (not check-alignment?) + (address-aligned-p + lin-addr + ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))) + (mv (list :unaligned-linear-address lin-addr) x86))))) + (,lin-mem-fn-name lin-addr val x86)) + /// + + (defrule ,(mk-name fn "-WHEN-64-BIT-MODEP-AND-NOT-FS/GS") + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (canonical-address-p eff-addr) + ,@(and check-alignment?-var + `((or (not check-alignment?) + (address-aligned-p + eff-addr ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))))) + (equal ,(search-and-replace-once 'proc-mode + '#.*64-bit-mode* + fn-call) + (,lin-mem-fn-name eff-addr val x86)))) + + ,@(and + check-alignment?-var + `((defrule ,(mk-name fn "-UNALIGNED-WHEN-64-BIT-MODEP-AND-NOT-FS/GS") + (implies + (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not + (or (not check-alignment?) + (address-aligned-p + eff-addr + ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))) + (canonical-address-p eff-addr)) + (equal ,(search-and-replace-once 'proc-mode + '#.*64-bit-mode* + fn-call) + (list (list :unaligned-linear-address eff-addr) x86)))))) + + (defrule ,(mk-name fn "-WHEN-64-BIT-MODEP-AND-FS/GS") + (implies + (or (equal seg-reg #.*fs*) + (equal seg-reg #.*gs*)) + (equal + ,(search-and-replace-once 'proc-mode '#.*64-bit-mode* fn-call) + (b* (((mv flg lin-addr) + (b* (((mv base & &) + (segment-base-and-bounds 0 seg-reg x86)) + (lin-addr (i64 (+ base (n64 eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0)))) + ((when flg) + (mv flg x86)) + ,@(and + check-alignment?-var + `(((unless (or (not check-alignment?) + (address-aligned-p + lin-addr + ,(/ size 8) + ,(if mem-ptr?-var 'mem-ptr? 'nil)))) + (mv (list :unaligned-linear-address lin-addr) x86))))) + (,lin-mem-fn-name lin-addr val x86)))) + :hints (("Goal" :in-theory (e/d (ea-to-la) ()))))))) + +(make-event + `(progn + (local (in-theory (e/d () + (unsigned-byte-p + signed-byte-p + force (force))))) + ;; wme08 + ,(gen-write-function :size 8 + :signed? nil + :check-alignment?-var nil + :mem-ptr?-var nil) + ;; wime08 + ,(gen-write-function :size 8 + :signed? t + :check-alignment?-var nil + :mem-ptr?-var nil) + ;; wme16 + ,(gen-write-function :size 16 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; wime16 + ,(gen-write-function :size 16 + :signed? t + :check-alignment?-var t + :mem-ptr?-var nil) + ;; wme32 + ,(gen-write-function :size 32 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var t) + ;; wime32 + ,(gen-write-function :size 32 + :signed? t + :check-alignment?-var t + :mem-ptr?-var t) + ;; wme48 + ,(gen-write-function :size 48 ;; typically a m16:32 pointer + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; wme64 + ,(gen-write-function :size 64 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; wime64 + ,(gen-write-function :size 64 + :signed? t + :check-alignment?-var t + :mem-ptr?-var nil) + ;; wme80 + ,(gen-write-function :size 80 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; wme128 + ;; Note: A #GP exception should be thrown here instead of an #AC fault when + ;; the address is not aligned. See Intel Manuals, Volume 3, Section 6.15, + ;; Exception and Interrupt Reference, Interrupt 17 Alignment Check + ;; Exception (#AC). + ,(gen-write-function :size 128 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil) + ;; wme256 + ;; Note: A #GP exception should be thrown here instead of an #AC fault when + ;; the address is not aligned. See Intel Manuals, Volume 2, Tables 2-18 and + ;; 2-44. + ,(gen-write-function :size 256 + :signed? nil + :check-alignment?-var t + :mem-ptr?-var nil))) + +(define wme-size + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (nbytes :type (member 1 2 4 6 8 10 16 32)) + (eff-addr :type (signed-byte 64)) + (seg-reg :type (integer 0 #.*segment-register-names-len-1*)) + (val :type (integer 0 *)) + (check-alignment? booleanp) + x86 + &key + ;; Default value for mem-ptr? is nil --- note that this input is + ;; relevant only for nbytes = 4. + ((mem-ptr? booleanp) 'nil)) + :guard (case nbytes + (1 (n08p val)) + (2 (n16p val)) + (4 (n32p val)) + (6 (n48p val)) + (8 (n64p val)) + (10 (n80p val)) + (16 (n128p val)) + (32 (n256p val))) + :returns (mv flg + (x86-new x86p :hyp (x86p x86))) + :parents (top-level-memory) + :short "Write an unsigned value with the specified number of bytes + to memory via an effective address." + :long + "

The effective address is translated to a canonical linear address. If + this translation is successful and no other errors occur (like alignment + errors), then @(see wml-size) is called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments (DS, ES, FS, GS, and SS) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments (this is + not explicitly mentioned in Intel manual, May'18, Volume 3, Section + 3.4.5.1, but it seems reasonable. In 64-bit mode, the W bit is + ignored (see Atmel manual, Dec'17, Volume 2, Section 4.8.1); by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

" + (b* (((when (and (/= proc-mode #.*64-bit-mode*) + (or (= seg-reg #.*cs*) + (b* ((attr (loghead + 16 (seg-hidden-attri seg-reg x86))) + (w (data-segment-descriptor-attributesBits->w + attr))) + (= w 0))))) + (mv (list :non-writable-segment eff-addr seg-reg) x86)) + ((mv flg lin-addr) (ea-to-la proc-mode eff-addr seg-reg nbytes x86)) + ((when flg) (mv flg x86)) + ((unless (or (not check-alignment?) + (address-aligned-p lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) x86))) + (wml-size nbytes lin-addr val x86)) + :inline t + :no-function t + /// + + (defrule wme-size-when-64-bit-modep-and-not-fs/gs + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (canonical-address-p eff-addr) + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (equal + (wme-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (wml-size nbytes eff-addr val x86)))) + + (defrule wme-size-when-64-bit-modep-fs/gs + (implies (or (equal seg-reg #.*fs*) + (equal seg-reg #.*gs*)) + (equal (wme-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (b* (((mv flg lin-addr) + (b* (((mv base & &) + (segment-base-and-bounds 0 seg-reg x86)) + (lin-addr (i64 (+ base (n64 eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0)))) + ((when flg) + (mv flg x86)) + ((unless (or (not check-alignment?) + (address-aligned-p + lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) x86))) + (wml-size nbytes lin-addr val x86)))) + :in-theory (e/d (ea-to-la) ())) + + (defthm wme-size-64-bit-unaligned-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of wme-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (canonical-address-p eff-addr)) + (equal (wme-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :unaligned-linear-address eff-addr) x86))) + :hints (("Goal" :in-theory (e/d (wme-size) ())))) + + (defthm wme-size-non-canonical-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of rme-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not (canonical-address-p eff-addr))) + (equal (wme-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :non-canonical-address eff-addr) x86))) + :hints (("Goal" :in-theory (e/d (wme-size) ()))))) + +(define wime-size + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (nbytes :type (member 1 2 4 8)) + (eff-addr :type (signed-byte 64)) + (seg-reg :type (integer 0 #.*segment-register-names-len-1*)) + (val :type integer) + (check-alignment? booleanp) + x86 + &key + ;; Default value for mem-ptr? is nil --- note that this input is + ;; relevant only for nbytes = 4. + ((mem-ptr? booleanp) 'nil)) + :inline t + :no-function t + :guard (case nbytes + (1 (i08p val)) + (2 (i16p val)) + (4 (i32p val)) + (8 (i64p val))) + :returns (mv flg + (x86-new x86p :hyp (x86p x86))) + :parents (top-level-memory) + :short "Write a signed value with the specified number of bytes + to memory via an effective address." + :long + "

The effective address is translated to a canonical linear address. If + this translation is successful and no other errors occur (like alignment + errors), then @(see wiml-size) is called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments (DS, ES, FS, GS, and SS) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments (this is + not explicitly mentioned in Intel manual, May'18, Volume 3, Section + 3.4.5.1, but it seems reasonable. In 64-bit mode, the W bit is + ignored (see Atmel manual, Dec'17, Volume 2, Section 4.8.1); by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

" + (b* (((when (and (/= proc-mode #.*64-bit-mode*) + (or (= seg-reg #.*cs*) + (b* ((attr (loghead + 16 (seg-hidden-attri seg-reg x86))) + (w (data-segment-descriptor-attributesBits->w + attr))) + (= w 0))))) + (mv (list :non-writable-segment eff-addr seg-reg) x86)) + ((mv flg lin-addr) (ea-to-la proc-mode eff-addr seg-reg nbytes x86)) + ((when flg) (mv flg x86)) + ((unless (or (not check-alignment?) + (address-aligned-p lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) x86))) + (wiml-size nbytes lin-addr val x86)) + + /// + + (defrule wime-size-when-64-bit-modep-and-not-fs/gs + (implies + (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (canonical-address-p eff-addr) + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (equal (wime-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (wiml-size nbytes eff-addr val x86)))) + + (defrule wime-size-when-64-bit-modep-fs/gs + (implies (or (equal seg-reg #.*fs*) + (equal seg-reg #.*gs*)) + (equal (wime-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (b* (((mv flg lin-addr) + (b* (((mv base & &) + (segment-base-and-bounds 0 seg-reg x86)) + (lin-addr (i64 (+ base (n64 eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0)))) + ((when flg) + (mv flg x86)) + ((unless (or (not check-alignment?) + (address-aligned-p + lin-addr nbytes mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) x86))) + (wiml-size nbytes lin-addr val x86)))) + :in-theory (e/d (ea-to-la) ())) + + (defthm wime-size-unaligned-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of wime-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not + (or (not check-alignment?) + (address-aligned-p eff-addr nbytes mem-ptr?))) + (canonical-address-p eff-addr)) + (equal (wime-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :unaligned-linear-address eff-addr) x86)))) + + (defthm wime-size-non-canonical-when-64-bit-modep-and-not-fs/gs + ;; [Shilpi] Added for guard proof obligations generated from the expansion + ;; of rme-size-opt. + (implies (and (not (equal seg-reg #.*fs*)) + (not (equal seg-reg #.*gs*)) + (not (canonical-address-p eff-addr))) + (equal (wime-size #.*64-bit-mode* + nbytes eff-addr seg-reg val check-alignment? x86 + :mem-ptr? mem-ptr?) + (list (list :non-canonical-address eff-addr) x86))) + :hints (("Goal" :in-theory (e/d (wime-size) ()))))) + +;; ---------------------------------------------------------------------- + +;; Macro definitions for efficient 64-bit mode execution: + +;; The idea here is that in 64-bit mode, when we already know that eff-addr is +;; a canonical address (e.g., because it is produced by a function that always +;; returns a canonical address) and if the seg-reg is *cs* (which is the common +;; case), then we needn't check for canonicity of eff-addr. + +(defmacro rme08-opt (proc-mode eff-addr seg-reg r-x x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rme08 ,proc-mode ,eff-addr ,seg-reg ,r-x ,x86) + :exec + (if (eql proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86))) + (rml08 lin-addr ,r-x ,x86)) + (rme08 ,proc-mode ,eff-addr ,seg-reg ,r-x ,x86)))) + +(defmacro rime08-opt (proc-mode eff-addr seg-reg r-x x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rime08 ,proc-mode ,eff-addr ,seg-reg ,r-x ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86))) + (riml08 lin-addr ,r-x ,x86)) + (rime08 ,proc-mode ,eff-addr ,seg-reg ,r-x ,x86)))) + +(defmacro wme08-opt (proc-mode eff-addr seg-reg val x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wme08 ,proc-mode ,eff-addr ,seg-reg ,val ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86))) + (wml08 lin-addr ,val ,x86)) + (wme08 ,proc-mode ,eff-addr ,seg-reg ,val ,x86)))) + +(defmacro wime08-opt (proc-mode eff-addr seg-reg val x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wime08 ,proc-mode ,eff-addr ,seg-reg ,val ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86))) + (wiml08 lin-addr ,val ,x86)) + (wime08 ,proc-mode ,eff-addr ,seg-reg ,val ,x86)))) + +(defmacro rme16-opt (proc-mode eff-addr seg-reg r-x check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rme16 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 2 nil))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (rml16 lin-addr ,r-x ,x86)) + (rme16 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86)))) + +(defmacro rime16-opt (proc-mode eff-addr seg-reg r-x check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rime16 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 2 nil))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (riml16 lin-addr ,r-x ,x86)) + (rime16 ,proc-mode ,eff-addr ,seg-reg ,r-x ,x86)))) + +(defmacro wme16-opt (proc-mode eff-addr seg-reg val check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wme16 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 2 nil))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (wml16 lin-addr ,val ,x86)) + (wme16 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86)))) + +(defmacro wime16-opt (proc-mode eff-addr seg-reg val check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wime16 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 2 nil))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (wiml16 lin-addr ,val ,x86)) + (wime16 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86)))) + +(defmacro rme32-opt (proc-mode eff-addr seg-reg r-x check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rme32 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 4 ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (rml32 lin-addr ,r-x ,x86)) + (rme32 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +(defmacro rime32-opt (proc-mode eff-addr seg-reg r-x check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rime32 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 4 ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (riml32 lin-addr ,r-x ,x86)) + (rime32 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +(defmacro wme32-opt (proc-mode eff-addr seg-reg val check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wme32 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 4 ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) x86))) + (wml32 lin-addr ,val ,x86)) + (wme32 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +(defmacro wime32-opt (proc-mode eff-addr seg-reg val check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wime32 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 4 nil))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (wiml32 lin-addr ,val ,x86)) + (wime32 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86)))) + +(defmacro rme48-opt (proc-mode eff-addr seg-reg r-x check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rme48 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 6 t))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (rml48 lin-addr ,r-x ,x86)) + (rme48 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86)))) + +(defmacro wme48-opt (proc-mode eff-addr seg-reg val check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wme48 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 6 t))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (wml48 lin-addr ,val ,x86)) + (wme48 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86)))) + +(defmacro rme64-opt (proc-mode eff-addr seg-reg r-x check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rme64 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 8 nil))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (rml64 lin-addr ,r-x ,x86)) + (rme64 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86)))) + +(defmacro rime64-opt (proc-mode eff-addr seg-reg r-x check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (rime64 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 8 nil))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (riml64 lin-addr ,r-x ,x86)) + (rime64 ,proc-mode ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86)))) + +(defmacro wme64-opt (proc-mode eff-addr seg-reg val check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wme64 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr 8 ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) x86))) + (wml64 lin-addr ,val ,x86)) + (wme64 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +(defmacro wime64-opt (proc-mode eff-addr seg-reg val check-alignment? x86 + &key (check-canonicity 'nil)) + (declare (xargs :guard (natp seg-reg))) + `(mbe + :logic + (wime64 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + ,(if (or (eql seg-reg #.*fs*) + (eql seg-reg #.*gs*)) + `(b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + (if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr ,8 nil))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (wiml64 lin-addr ,val ,x86)) + (wime64 ,proc-mode ,eff-addr ,seg-reg ,val ,check-alignment? ,x86)))) + +;; Note that unlike the macros above, the generic rme/wme*-size macros work for +;; all kinds of seg-reg values. + +(defmacro rme-size-opt + (proc-mode nbytes eff-addr seg-reg r-x check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + `(mbe + :logic + (rme-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + (if (or (eql ,seg-reg #.*fs*) + (eql ,seg-reg #.*gs*)) + (b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + ,(if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr ,nbytes ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (rml-size ,nbytes lin-addr ,r-x ,x86)) + (rme-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +(defmacro rime-size-opt + (proc-mode nbytes eff-addr seg-reg r-x check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + `(mbe + :logic + (rime-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + (if (or (eql ,seg-reg #.*fs*) + (eql ,seg-reg #.*gs*)) + (b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + ,(if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg 0 ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr ,nbytes ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) 0 ,x86))) + (riml-size ,nbytes lin-addr ,r-x ,x86)) + (rime-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,r-x ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +(defmacro wme-size-opt + (proc-mode nbytes eff-addr seg-reg val check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + `(mbe + :logic + (wme-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + (if (or (eql ,seg-reg #.*fs*) + (eql ,seg-reg #.*gs*)) + (b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + ,(if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr ,nbytes ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (wml-size ,nbytes lin-addr ,val ,x86)) + (wme-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +(defmacro wime-size-opt + (proc-mode nbytes eff-addr seg-reg val check-alignment? x86 + &key + (mem-ptr? 'nil) + (check-canonicity 'nil)) + `(mbe + :logic + (wime-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?) + :exec + (if (equal ,proc-mode #.*64-bit-mode*) + (b* (((mv flg (the (signed-byte #.*max-linear-address-size*) lin-addr)) + (if (or (eql ,seg-reg #.*fs*) + (eql ,seg-reg #.*gs*)) + (b* (((mv (the (unsigned-byte 64) base) & &) + (segment-base-and-bounds 0 ,seg-reg ,x86)) + ((the (signed-byte 64) lin-addr) + (i64 (+ base (n64 ,eff-addr))))) + (if (canonical-address-p lin-addr) + (mv nil lin-addr) + (mv (list :non-canonical-address lin-addr) 0))) + ,(if check-canonicity + `(b* (((unless (canonical-address-p ,eff-addr)) + (mv (list :non-canonical-address ,eff-addr) 0))) + (mv nil ,eff-addr)) + `(mv nil ,eff-addr)))) + ((when flg) + (mv flg ,x86)) + ((unless (or (not ,check-alignment?) + (address-aligned-p lin-addr ,nbytes ,mem-ptr?))) + (mv (list :unaligned-linear-address lin-addr) ,x86))) + (wiml-size ,nbytes lin-addr ,val ,x86)) + (wime-size + ,proc-mode ,nbytes ,eff-addr ,seg-reg ,val ,check-alignment? ,x86 + :mem-ptr? ,mem-ptr?)))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/two-byte-opcodes-dispatch.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/two-byte-opcodes-dispatch.lisp new file mode 100644 index 000000000..30f54239c --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/two-byte-opcodes-dispatch.lisp @@ -0,0 +1,245 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2018, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "instructions/top" :ttags (:syscall-exec)) +(include-book "three-byte-opcodes-dispatch" :ttags (:syscall-exec)) + +(local (include-book "dispatch-creator")) +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "centaur/bitops/signed-byte-p" :dir :system)) + +(local (in-theory (e/d () + (app-view-rml08-no-error + (:meta acl2::mv-nth-cons-meta) + rme08-value-when-error + member-equal)))) + +(local (xdoc::set-default-parents x86-decoder)) + +;; ---------------------------------------------------------------------- + +(make-event + (b* ((dispatch + (create-dispatch-for-opcodes + #ux0F_00 256 :two-byte (w state)))) + + `(define two-byte-opcode-execute + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (mandatory-prefix :type (unsigned-byte 8)) + (rex-byte :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8)) + (modr/m :type (unsigned-byte 8)) + (sib :type (unsigned-byte 8)) + x86) + + :parents (x86-decoder) + ;; The following arg will avoid binding __function__ to + ;; two-byte-opcode-execute. The automatic __function__ binding that comes + ;; with define causes stack overflows during the guard proof of this + ;; function. + :no-function t + + :short "Two-byte opcode dispatch function." + :long "

@('two-byte-opcode-execute') is the doorway to the two-byte + opcode map, and will lead to the three-byte opcode map if @('opcode') is + either @('#x38') or @('#x3A').

" + :guard (and (prefixes-p prefixes) + (modr/m-p modr/m) + (sib-p sib) + (rip-guard-okp proc-mode temp-rip)) + :guard-hints (("Goal" + :do-not '(preprocess) + :in-theory (e/d (member-equal) + (logbit + bitops::logbit-to-logbitp + unsigned-byte-p + (:t unsigned-byte-p) + signed-byte-p)))) + + (case opcode ,@dispatch) + + /// + + (defthm x86p-two-byte-opcode-execute + (implies (x86p x86) + (x86p (two-byte-opcode-execute + proc-mode start-rip temp-rip prefixes mandatory-prefix + rex-byte opcode modr/m sib x86))))))) + +(local + (defthm unsigned-byte-p-from-<=-loghead + (implies (and (<= x (loghead n y)) + (natp n) + (natp x)) + (unsigned-byte-p n x)))) + +(define two-byte-opcode-decode-and-execute + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (rex-byte :type (unsigned-byte 8)) + (escape-byte :type (unsigned-byte 8)) + x86) + + :ignore-ok t + :guard (and (prefixes-p prefixes) + (equal escape-byte #x0F) + (rip-guard-okp proc-mode temp-rip)) + :guard-hints (("Goal" :do-not '(preprocess) + :in-theory (e/d* + (rip-guard-okp + add-to-*ip + modr/m-p + add-to-*ip-is-i48p-rewrite-rule) + (unsigned-byte-p + (:type-prescription bitops::logand-natp-type-2) + (:type-prescription bitops::ash-natp-type) + acl2::loghead-identity + not + tau-system + (tau-system))))) + :parents (x86-decoder) + :short "Decoder and dispatch function for two-byte opcodes" + :long "

Source: Intel Manual, Volume 2, Appendix A-2

" + + (b* ((ctx 'two-byte-opcode-decode-and-execute) + + ((mv flg0 (the (unsigned-byte 8) opcode) x86) + (rme08 proc-mode temp-rip #.*cs* :x x86)) + ((when flg0) + (!!ms-fresh :opcode-byte-access-error flg0)) + + ;; Possible values of opcode: + + ;; 1. #x38 and #x3A: These are escapes to the two three-byte opcode + ;; maps. Function three-byte-opcode-decode-and-execute is called + ;; here, which also fetches the ModR/M and SIB bytes for these + ;; opcodes. + + ;; 2. All other values denote opcodes of the two-byte map. The function + ;; two-byte-opcode-execute case-splits on this opcode byte and calls + ;; the appropriate instruction semantic function. + + ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :increment-error flg)) + + ;; Initial spec, buggy: + ;; ((mv msg (the (unsigned-byte 8) mandatory-prefix)) + ;; (compute-mandatory-prefix-for-two-byte-opcode + ;; proc-mode opcode prefixes)) + ;; ((when msg) + ;; (x86-illegal-instruction msg start-rip temp-rip x86)) + + ;; (modr/m? + ;; (two-byte-opcode-ModR/M-p + ;; proc-mode mandatory-prefix opcode)) + ;; ((mv flg1 (the (unsigned-byte 8) modr/m) x86) + ;; (if modr/m? + ;; (rme08 proc-mode temp-rip #.*cs* :x x86) + ;; (mv nil 0 x86))) + ;; ((when flg1) (!!ms-fresh :modr/m-byte-read-error flg1)) + + ;; Fixed, but complicated spec.: + ;; ((mv modr/m-mand-err + ;; (the (unsigned-byte 8) mandatory-prefix) + ;; modr/m? + ;; (the (unsigned-byte 8) modr/m) + ;; x86) + ;; (two-byte-opcode-modr/m-and-mandatory-prefix + ;; proc-mode opcode prefixes temp-rip x86)) + ;; ((when modr/m-mand-err) + ;; (if (and (consp modr/m-mand-err) + ;; (equal (car modr/m-mand-err) :illegal-use-of-mandatory-prefix)) + ;; ;; #UD thrown. + ;; (x86-illegal-instruction modr/m-mand-err start-rip temp-rip x86) + ;; ;; Model-related error + ;; (!!ms-fresh :modr/m-error modr/m-mand-err))) + + ;; Simplified spec.: + ((the (unsigned-byte 8) mandatory-prefix) + (compute-mandatory-prefix-for-two-byte-opcode proc-mode opcode prefixes)) + (modr/m? (two-byte-opcode-ModR/M-p proc-mode mandatory-prefix opcode)) + ((mv flg1 (the (unsigned-byte 8) modr/m) x86) + (if modr/m? + (rme08 proc-mode temp-rip #.*cs* :x x86) + (mv nil 0 x86))) + ((when flg1) (!!ms-fresh :modr/m-byte-read-error flg1)) + + ((mv flg temp-rip) (if modr/m? + (add-to-*ip proc-mode temp-rip 1 x86) + (mv nil temp-rip))) + ((when flg) (!!ms-fresh :increment-error flg)) + + (sib? (and modr/m? + (b* ((p4? (eql #.*addr-size-override* + (the (unsigned-byte 8) (prefixes->adr prefixes)))) + (16-bit-addressp (eql 2 (select-address-size proc-mode p4? x86)))) + (x86-decode-SIB-p modr/m 16-bit-addressp)))) + ((mv flg2 (the (unsigned-byte 8) sib) x86) + (if sib? + (rme08 proc-mode temp-rip #.*cs* :x x86) + (mv nil 0 x86))) + ((when flg2) + (!!ms-fresh :sib-byte-read-error flg2)) + + ((mv flg temp-rip) (if sib? + (add-to-*ip proc-mode temp-rip 1 x86) + (mv nil temp-rip))) + ((when flg) (!!ms-fresh :increment-error flg))) + + (two-byte-opcode-execute + proc-mode start-rip temp-rip prefixes mandatory-prefix + rex-byte opcode modr/m sib x86)) + + /// + + (defrule x86p-two-byte-opcode-decode-and-execute + (implies (x86p x86) + (x86p (two-byte-opcode-decode-and-execute + proc-mode start-rip temp-rip prefixes + rex-byte escape-byte x86))) + :enable add-to-*ip-is-i48p-rewrite-rule + :disable (signed-byte-p))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/x86.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/x86.lisp new file mode 100644 index 000000000..3787268a3 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/x86.lisp @@ -0,0 +1,893 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, May - August 2023, Regents of the University of Texas +; Copyright (C) August 2023 - May 2024, Yahya Sohail +; Copyright (C) May 2024 - August 2024, Intel Corporation +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Yahya Sohail + +(in-package "X86ISA") + +;; ---------------------------------------------------------------------- + +(include-book "instructions/top" :ttags (:syscall-exec)) +(include-book "two-byte-opcodes-dispatch" :ttags (:syscall-exec)) +(include-book "three-byte-opcodes-dispatch" :ttags (:syscall-exec)) +(include-book "vex-opcodes-dispatch") +(include-book "evex-opcodes-dispatch") +(include-book "cpuid") +(include-book "dispatch-macros") +(include-book "get-prefixes") +(include-book "interrupt-servicing") +(include-book "std/strings/hexify" :dir :system) + +(local (include-book "dispatch-creator")) +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "centaur/bitops/signed-byte-p" :dir :system)) + +(local (in-theory (e/d () + (app-view-rml08-no-error + (:meta acl2::mv-nth-cons-meta) + rme08-value-when-error + member-equal)))) + +;; ---------------------------------------------------------------------- + +(local (xdoc::set-default-parents x86-decoder)) + +;; ---------------------------------------------------------------------- + +;; One-byte Opcode Map: + +(make-event + + (b* ((dispatch + (create-dispatch-for-opcodes #ux00 256 :one-byte (w state)))) + + `(define one-byte-opcode-execute + ((proc-mode :type (integer 0 #.*num-proc-modes-1*)) + (start-rip :type (signed-byte #.*max-linear-address-size*)) + (temp-rip :type (signed-byte #.*max-linear-address-size*)) + (prefixes :type (unsigned-byte #.*prefixes-width*)) + (rex-byte :type (unsigned-byte 8)) + (opcode :type (unsigned-byte 8)) + (modr/m :type (unsigned-byte 8)) + (sib :type (unsigned-byte 8)) + x86) + + :parents (x86-decoder) + ;; The following arg will avoid binding __function__ to + ;; one-byte-opcode-execute. The automatic __function__ binding + ;; that comes with define causes stack overflows during the guard + ;; proof of this function. + :no-function t + :short "Top-level dispatch function." + :long "

@('one-byte-opcode-execute') is the doorway to all the opcode + maps (for non-AVX/AVX512 instructions).

" + + :guard (and (prefixes-p prefixes) + (modr/m-p modr/m) + (sib-p sib) + (rip-guard-okp proc-mode temp-rip)) + :guard-hints (("Goal" + :do-not '(preprocess) + :in-theory (e/d () (unsigned-byte-p signed-byte-p)))) + + (case opcode ,@dispatch) + + /// + + (defthm x86p-one-byte-opcode-execute + (implies (x86p x86) + (x86p (one-byte-opcode-execute + proc-mode start-rip temp-rip + prefixes rex-byte opcode modr/m sib x86))))))) + +;; ---------------------------------------------------------------------- + +;; Can be smashed by tty-raw.lsp +(define write-tty ((c :type (unsigned-byte 8)) + x86) + :parents (tty) + :short "Write a byte to the TTY." + :long "

This function writes a byte to the @('tty-out') field of the x86 + state by consing the byte to the front of it. Including @('tty-raw.lsp') in + raw lisp smashes this function to write to a TCP port instead.

" + :returns (x86 x86p :hyp (x86p x86)) + (!tty-out (cons c (tty-out x86)) x86)) + +(define read-tty (x86) + :parents (tty) + :short "Read a byte from the TTY." + :long "

This function reads a byte from the @('tty-in') field of the x86 + stobj by extracting and returning its @('car') and writing the @('cdr') to + the @('tty-in') field. If the @('tty-in') field is empty (i.e. it is + @('nil')), this function returns @('nil') and the @('x86') stobj is + unmodified. Including @('tty-raw.lsp') in raw lisp smashes this function to + read from a TCP port instead.

" + :returns (mv byt + (x86 x86p :hyp (x86p x86))) + :guard-hints (("Goal" :in-theory (disable ELEM-P-OF-XR-TTY-IN) + :use (:instance ELEM-P-OF-XR-TTY-IN (i nil) (x86$a x86)))) + (b* ((buf (tty-in x86)) + ((when (null buf)) (mv nil x86)) + (byt (car buf)) + (x86 (!tty-in (cdr buf) x86))) + (mv byt x86)) + /// + (defthm unsigned-byte-p-8-non-nil-read-tty + (implies (and (x86p x86) + (mv-nth 0 (read-tty x86))) + (unsigned-byte-p 8 (mv-nth 0 (read-tty x86)))) + :hints (("Goal" :in-theory (disable ELEM-P-OF-XR-TTY-IN) + :use (:instance ELEM-P-OF-XR-TTY-IN (i nil) (x86$a x86)))))) + +(define x86-exec-peripherals (x86) + :parents (peripherals) + :short "Execute the peripherals" + :guard-hints (("Goal" :use ((:instance ELEM-P-OF-XR-LAST-CLOCK-EVENT (i nil) (x86$a x86)) + (:instance ELEM-P-OF-XR-TIME-STAMP-COUNTER (i nil) (x86$a x86))) + :in-theory (disable ELEM-P-OF-XR-LAST-CLOCK-EVENT ELEM-P-OF-XR-TIME-STAMP-COUNTER))) + :returns (x86 x86p :hyp (x86p x86)) + (b* (((when (app-view x86)) x86) + ;; Increment the time stamp counter + (time-stamp-counter (n64 (1+ (time-stamp-counter x86)))) + (x86 (!time-stamp-counter time-stamp-counter x86)) + + ;; This is part of the clock device. + (x86 (if (app-view x86) + x86 + (wm-low-64 #x100 time-stamp-counter x86))) + + (last-clock-event (last-clock-event x86)) + (x86 (if (and (> last-clock-event 100000) + (equal (rflagsBits->intf (rflags x86)) 1) + (not (inhibit-interrupts-one-instruction x86)) + (not (equal (memi #x108 x86) 0)) + (not (fault x86))) + (b* ((x86 (!last-clock-event 0 x86)) + (x86 (!fault (cons '(:interrupt 32) (fault x86)) x86))) + x86) + (!last-clock-event (1+ last-clock-event) x86))) + + ;; Time to check for any TTY output + ;; The TTY protocol is simple. If 0x3F9 is nonzero + ;; 0x3F8 has an output character. (physical addresses of course) + (x86 (b* ((tty-byte-valid (not (equal (memi #x3F9 x86) 0))) + ((when (not tty-byte-valid)) x86) + (tty-output-byte (memi #x3F8 x86)) + (x86 (!memi #x3F9 0 x86)) + (x86 (write-tty tty-output-byte x86))) + x86)) + ;; We check if the tty input buffer is empty + ;; If so, we write the new byte and set valid flag + (x86 (b* ((tty-write-byte-valid (not (equal (memi #x3FB x86) 0))) + ((when tty-write-byte-valid) x86) + ((mv tty-input x86) (read-tty x86)) + ((when (equal tty-input nil)) x86) + (x86 (!memi #x3FA tty-input x86)) + (x86 (!memi #x3FB 1 x86))) + x86))) + x86)) + +(define x86-fetch-decode-execute (x86) + + :parents (x86-decoder) + :short "Top-level step function" + + :long "

@('x86-fetch-decode-execute') is the step function of our x86 + interpreter. It fetches one instruction by looking up the memory address + indicated by the instruction pointer @('rip'), decodes that instruction, and + dispatches control to the appropriate instruction semantic function.

" + + :prepwork + ((local + (defthm guard-helper-1 + (implies (and (<= 0 (+ x y)) + (<= (+ x y) a) + (unsigned-byte-p 32 a) + (integerp x) (integerp y)) + (signed-byte-p 48 (+ x y))))) + + (local + (defthm guard-helper-2 + (implies (and (<= 0 (+ x y)) + (<= (+ x y) a) + (unsigned-byte-p 32 a) + (integerp x) (integerp y)) + (signed-byte-p 64 (+ x y))))) + + (local + (defthm guard-helper-3 + (implies (unsigned-byte-p 8 b0) + (and + (unsigned-byte-p 32 (logior 98 (ash b0 8))) + (unsigned-byte-p 24 (logior 196 (ash b0 8))) + (unsigned-byte-p 24 (logior 197 (ash b0 8))))))) + + (local + (defthm guard-helper-4 + (implies (and (unsigned-byte-p 4 num) + (signed-byte-p 48 rip)) + (and (signed-byte-p 64 (+ 1 rip num)) + (signed-byte-p 64 (+ 2 rip num)))))) + + (local + (defthm guard-helper-5 + (implies (unsigned-byte-p 4 num) + (signed-byte-p 48 (+ 1 num))))) + + (local + (defthm dumb-integerp-of-mv-nth-1-rme08-rule + (implies (force (x86p x86)) + (integerp (mv-nth 1 (rme08 proc-mode eff-addr seg-reg r-x x86)))) + :rule-classes (:rewrite :type-prescription))) + + (local + (defthm unsigned-byte-p-from-<= + (implies (and (<= x y) + (unsigned-byte-p n y) + (natp x)) + (unsigned-byte-p n x)))) + + (local (in-theory (e/d* () + (signed-byte-p + unsigned-byte-p + not (tau-system))))) + + ;; For RoW proofs involving these bitstructs' accessors and updaters: + (local (in-theory (e/d (!vex-prefixes->byte0-is-vex-prefixes + !vex-prefixes->byte1-is-vex-prefixes + !vex-prefixes->byte2-is-vex-prefixes + !evex-prefixes->byte0-is-evex-prefixes + !evex-prefixes->byte1-is-evex-prefixes + !evex-prefixes->byte2-is-evex-prefixes + !evex-prefixes->byte3-is-evex-prefixes) + ())))) + + :guard-hints + (("Goal" :in-theory (e/d (modr/m-p + prefixes-p + vex-prefixes-byte0-p + add-to-*ip + add-to-*ip-is-i48p-rewrite-rule) + ()))) + + (b* (;; We don't want our interpreter to take a step if the machine is in a + ;; bad state. Such checks are made in x86-run but I am duplicating them + ;; here in case this function is being used at the top-level. + ((when (or (ms x86) (fault x86))) x86) + (app-view? (app-view x86)) + + (inhibit-interrupts-one-instruction? (inhibit-interrupts-one-instruction x86)) + (x86 (b* ((ctx 'x86-fetch-decode-execute) + + (proc-mode (x86-operation-mode x86)) + (64-bit-modep (equal proc-mode #.*64-bit-mode*)) + + (start-rip (the (signed-byte #.*max-linear-address-size*) + (read-*ip proc-mode x86))) + + ((mv flg + (the (unsigned-byte #.*prefixes-width*) prefixes) + (the (unsigned-byte 8) rex-byte) + x86) + (get-prefixes proc-mode start-rip 0 0 15 x86)) + ;; Among other errors (including if there are 15 prefix (legacy and REX) + ;; bytes, which leaves no room for an opcode byte in a legal + ;; instruction), if get-prefixes detects a non-canonical address while + ;; attempting to fetch prefixes, flg will be non-nil. + ((when flg) + (!!ms-fresh :error-in-reading-prefixes flg)) + + ((the (unsigned-byte 8) opcode/vex/evex-byte) + (prefixes->nxt prefixes)) + + ((the (unsigned-byte 4) prefix-length) + (prefixes->num prefixes)) + + ((mv flg temp-rip) (add-to-*ip proc-mode start-rip (1+ prefix-length) x86)) + ((when flg) (!!ms-fresh :increment-error flg)) + + (vex-byte0? (or (equal opcode/vex/evex-byte #.*vex2-byte0*) + (equal opcode/vex/evex-byte #.*vex3-byte0*))) + ;; If opcode/vex/evex-byte is either 0xC4 (*vex3-byte0*) or 0xC5 + ;; (*vex2-byte0*), then we always have a VEX-encoded instruction in the + ;; 64-bit mode. But in the 32-bit mode, these bytes may not signal the + ;; start of the VEX prefixes. 0xC4 and 0xC5 map to LES and LDS + ;; instructions (respectively) in the 32-bit mode if bits[7:6] of the + ;; next byte, which we call les/lds-distinguishing-byte below, are *not* + ;; 11b. Otherwise, they signal the start of VEX prefixes in the 32-bit + ;; mode too. + + ;; Though the second byte acts as the distinguishing byte only in the + ;; 32-bit mode, we always read the first two bytes of a VEX prefix in + ;; this function for simplicity. + ((mv flg les/lds-distinguishing-byte x86) + (if vex-byte0? + (rme08-opt proc-mode temp-rip #.*cs* :x x86) + (mv nil 0 x86))) + ((when flg) + (!!ms-fresh :les/lds-distinguishing-byte-read-error flg)) + ;; If the instruction is indeed LDS or LES in the 32-bit mode, temp-rip + ;; is incremented after the ModR/M is detected (see add-to-*ip following + ;; modr/m? below). + ((when (and vex-byte0? + (or 64-bit-modep + (and (not 64-bit-modep) + (equal (part-select + les/lds-distinguishing-byte + :low 6 :high 7) + #b11))))) + ;; Handle VEX-encoded instructions separately. + (b* (((mv flg temp-rip) + (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) + (!!ms-fresh :vex-byte1-increment-error flg)) + (vex-prefixes + (!vex-prefixes->byte0 opcode/vex/evex-byte 0)) + (vex-prefixes + (!vex-prefixes->byte1 les/lds-distinguishing-byte vex-prefixes))) + (vex-decode-and-execute + proc-mode + start-rip temp-rip prefixes rex-byte vex-prefixes x86))) + + (opcode/evex-byte opcode/vex/evex-byte) + + (evex-byte0? (equal opcode/evex-byte #.*evex-byte0*)) + ;; Byte 0x62 is byte0 of the 4-byte EVEX prefix. In 64-bit mode, this + ;; byte indicates the beginning of the EVEX prefix --- note that in the + ;; pre-AVX512 era, this would lead to a #UD, but we don't model that + ;; here. + + ;; Similar to the VEX prefix situation, things are more complicated in + ;; the 32-bit mode, where 0x62 aliases to the 32-bit only BOUND + ;; instruction. The Intel Manuals (May, 2018) don't seem to say + ;; anything explicitly about how one differentiates between the EVEX + ;; prefix and the BOUND instruction in 32-bit mode. However, a legal + ;; BOUND instruction must always have a memory operand as its second + ;; operand, which means that ModR/M.mod != 0b11 (see Intel Vol. 2, Table + ;; 2-2). So, if bits [7:6] of the byte following 0x62 are NOT 0b11, + ;; then 0x62 refers to a legal BOUND instruction. Otherwise, it signals + ;; the beginning of the EVEX prefix. + + ;; Again, similar to the VEX prefix situation: though the second byte + ;; acts as the distinguishing byte only in the 32-bit mode, we always + ;; read the first two bytes of an EVEX prefix in this function for + ;; simplicity. + ((mv flg bound-distinguishing-byte x86) + (if evex-byte0? + (rme08-opt proc-mode temp-rip #.*cs* :x x86) + (mv nil 0 x86))) + ((when flg) + (!!ms-fresh :bound-distinguishing-byte-read-error flg)) + ;; If the instruction is indeed BOUND in the 32-bit mode, temp-rip is + ;; incremented after the ModR/M is detected (see add-to-*ip following + ;; modr/m? below). + ((when (and evex-byte0? + (or 64-bit-modep + (and (not 64-bit-modep) + (equal (part-select + bound-distinguishing-byte + :low 6 :high 7) + #b11))))) + ;; Handle EVEX-encoded instructions separately. + (b* (((mv flg temp-rip) + (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) + (!!ms-fresh :evex-byte1-increment-error flg)) + (evex-prefixes + (!evex-prefixes->byte0 opcode/evex-byte 0)) + (evex-prefixes + (!evex-prefixes->byte1 bound-distinguishing-byte evex-prefixes))) + (evex-decode-and-execute + proc-mode + start-rip temp-rip prefixes rex-byte evex-prefixes x86))) + + + (opcode-byte opcode/evex-byte) + + ;; Possible values of opcode-byte: + + ;; The opcode-byte should not contain any of the (legacy) prefixes, REX + ;; bytes, VEX prefixes, and EVEX prefixes -- by this point, all these + ;; prefix bytes should have been processed. So, here are the kinds of + ;; values opcode-byte can have: + + ;; 1. An opcode of the one-byte opcode map: this function prefetches the + ;; ModR/M and SIB bytes for these opcodes. The function + ;; one-byte-opcode-execute case-splits on this opcode byte and calls + ;; the appropriate instruction semantic function. + + ;; 2. #x0F -- two-byte or three-byte opcode indicator: modr/m? is set to + ;; NIL (see *64-bit-mode-one-byte-has-modr/m-ar* and + ;; *32-bit-mode-one-byte-has-modr/m-ar*). No ModR/M and SIB bytes + ;; are prefetched by this function for the two-byte or three-byte + ;; opcode maps. In one-byte-opcode-execute, we call + ;; two-byte-opcode-decode-and-execute, where we fetch the ModR/M and + ;; SIB bytes for the two-byte opcodes or dispatch control to + ;; three-byte-opcode-decode-and-execute when appropriate (i.e., when + ;; the byte following #x0F is either #x38 or #x3A). Note that in + ;; this function, temp-rip will not be incremented beyond this point + ;; for these opcodes --- i.e., it points at the byte *following* + ;; #x0F. + + ;; The modr/m and sib byte prefetching in this function is biased + ;; towards the one-byte opcode map. The functions + ;; two-byte-opcode-decode-and-execute and + ;; three-byte-opcode-decode-and-execute do their own prefetching. We + ;; made this choice to take advantage of the fact that the most + ;; frequently encountered instructions are from the one-byte opcode map. + ;; Another reason is that the instruction encoding syntax is clearer to + ;; understand this way; this is a nice way of seeing how one opcode map + ;; "escapes" into another. + + (modr/m? (one-byte-opcode-ModR/M-p proc-mode opcode-byte)) + ((mv flg (the (unsigned-byte 8) modr/m) x86) + (if modr/m? + (if (or vex-byte0? evex-byte0?) + ;; The above will be true only if the instruction is LES or LDS + ;; or BOUND in the 32-bit mode. + (mv nil les/lds-distinguishing-byte x86) + (rme08-opt proc-mode temp-rip #.*cs* :x x86)) + (mv nil 0 x86))) + ((when flg) + (!!ms-fresh :modr/m-byte-read-error flg)) + + ((mv flg temp-rip) + (if modr/m? + (add-to-*ip proc-mode temp-rip 1 x86) + (mv nil temp-rip))) + ((when flg) (!!ms-fresh :increment-error flg)) + + (sib? (and modr/m? + (b* ((p4? (eql #.*addr-size-override* + (the (unsigned-byte 8) (prefixes->adr prefixes)))) + (16-bit-addressp (eql 2 (select-address-size + proc-mode p4? x86)))) + (x86-decode-SIB-p modr/m 16-bit-addressp)))) + + ((mv flg (the (unsigned-byte 8) sib) x86) + (if sib? + (rme08-opt proc-mode temp-rip #.*cs* :x x86) + (mv nil 0 x86))) + ((when flg) + (!!ms-fresh :sib-byte-read-error flg)) + + ((mv flg temp-rip) + (if sib? + (add-to-*ip proc-mode temp-rip 1 x86) + (mv nil temp-rip))) + ((when flg) (!!ms-fresh :increment-error flg)) + + (x86 (one-byte-opcode-execute + proc-mode start-rip temp-rip prefixes rex-byte opcode-byte + modr/m sib x86))) + x86)) + + ((when app-view?) x86) + + (x86 (if (enable-peripherals x86) + (x86-exec-peripherals x86) + x86)) + (x86 (if (and (fault x86) + (handle-exceptions x86)) + (handle-faults x86) + x86)) + + (x86 (if inhibit-interrupts-one-instruction? + (!inhibit-interrupts-one-instruction nil x86) + x86))) + x86) + + + /// + + (defrule x86p-x86-fetch-decode-execute + (implies (x86p x86) + (x86p (x86-fetch-decode-execute x86))) + ;; for speed: + :disable (xw-xw-inter-field-arrange-writes + mv-nth-0-of-add-to-*ip-when-64-bit-modep + mv-nth-1-of-add-to-*ip-when-64-bit-modep + bitops::part-select-width-low$inline + bitops::part-select-low-high$inline + mv-nth + i48p-xr-rip + right-shift-to-logtail + acl2::logtail-identity + get-prefixes-opener-lemma-no-legacy-prefix-but-rex-prefix + get-prefixes-opener-lemma-group-2-prefix + get-prefixes-opener-lemma-group-1-prefix + get-prefixes-opener-lemma-group-4-prefix + get-prefixes-opener-lemma-group-3-prefix + get-prefixes-opener-lemma-zero-cnt + get-prefixes-opener-lemma-no-prefix-byte + get-prefixes-opener-lemma-no-legacy-prefix-but-rex-prefix + get-prefixes-does-not-modify-x86-state-in-app-view + num-prefixes-get-prefixes-bound) + :enable add-to-*ip-is-i48p-rewrite-rule) + + (defthmd ms-fault-and-x86-fetch-decode-and-execute + (implies (and (x86p x86) + (or (ms x86) (fault x86))) + (equal (x86-fetch-decode-execute x86) x86))) + + (defthm x86-fetch-decode-execute-opener + ;; Note that this opener lemma applies to all supported modes of operation + ;; (see x86-operation-mode). + + ;; TODO: Extend to VEX and EVEX prefixes. + (implies + (and + (app-view x86) + (not (ms x86)) + (not (fault x86)) + (equal proc-mode (x86-operation-mode x86)) + (equal start-rip (read-*ip proc-mode x86)) + (not (mv-nth 0 (get-prefixes proc-mode start-rip 0 0 15 x86))) + (equal prefixes (mv-nth 1 (get-prefixes proc-mode start-rip 0 0 15 x86))) + (equal rex-byte (mv-nth 2 (get-prefixes proc-mode start-rip 0 0 15 x86))) + (equal opcode/vex/evex-byte (prefixes->nxt prefixes)) + (equal prefix-length (prefixes->num prefixes)) + (equal temp-rip0 + (mv-nth 1 (add-to-*ip proc-mode start-rip (1+ prefix-length) x86))) + + ;; *** No VEX prefixes *** + (not (equal opcode/vex/evex-byte #.*vex3-byte0*)) + (not (equal opcode/vex/evex-byte #.*vex2-byte0*)) + ;; *** No EVEX prefixes *** + (not (equal opcode/vex/evex-byte #.*evex-byte0*)) + + (equal modr/m? + (one-byte-opcode-ModR/M-p proc-mode opcode/vex/evex-byte)) + (equal modr/m (if modr/m? + (mv-nth 1 (rme08 proc-mode temp-rip0 #.*cs* :x x86)) + 0)) + (equal temp-rip1 (if modr/m? + (mv-nth 1 (add-to-*ip proc-mode temp-rip0 1 x86)) + temp-rip0)) + (equal p4? (equal #.*addr-size-override* (prefixes->adr prefixes))) + (equal 16-bit-addressp (equal 2 (select-address-size proc-mode p4? x86))) + (equal sib? (and modr/m? (x86-decode-sib-p modr/m 16-bit-addressp))) + (equal sib (if sib? (mv-nth 1 (rme08 proc-mode temp-rip1 #.*cs* :x x86)) 0)) + + (equal temp-rip2 (if sib? + (mv-nth 1 (add-to-*ip proc-mode temp-rip1 1 x86)) + temp-rip1)) + + (or (app-view x86) (not (marking-view x86))) + (not (mv-nth 0 (add-to-*ip proc-mode start-rip (1+ prefix-length) x86))) + (if modr/m? + (and (not (mv-nth 0 (add-to-*ip proc-mode temp-rip0 1 x86))) + (not (mv-nth 0 (rme08 proc-mode temp-rip0 #.*cs* :x x86)))) + t) + (if sib? + (and (not (mv-nth 0 (add-to-*ip proc-mode temp-rip1 1 x86))) + (not (mv-nth 0 (rme08 proc-mode temp-rip1 #.*cs* :x x86)))) + t) + (x86p x86) + ;; Print the rip and the first opcode byte of the instruction + ;; under consideration after all the non-trivial hyps (above) of + ;; this rule have been relieved: + (syntaxp + (and (not (cw "~% [ x86instr @ rip: ~p0 ~%" start-rip)) + (not (cw " op0: ~s0 ] ~%" + (str::hexify (unquote opcode/vex/evex-byte))))))) + (equal + (x86-fetch-decode-execute x86) + (one-byte-opcode-execute + proc-mode start-rip temp-rip2 prefixes rex-byte + opcode/vex/evex-byte modr/m sib x86))) + :hints (("Goal" + :cases ((app-view x86)) + :in-theory (e/d () + (one-byte-opcode-execute + signed-byte-p + not + member-equal)))))) + +(in-theory (e/d (vex-decode-and-execute + evex-decode-and-execute + one-byte-opcode-execute + two-byte-opcode-execute + first-three-byte-opcode-execute + second-three-byte-opcode-execute) + ())) + +;; ---------------------------------------------------------------------- + +;; Running the interpreter: + +;; Schedule: (in the M1 style) + +(defun binary-clk+ (i j) + (+ (nfix i) (nfix j))) + +(defthm clk+-associative + (implies (binary-clk+ (binary-clk+ i j) k) + (binary-clk+ i (binary-clk+ j k)))) + +(defmacro clk+ (&rest args) + (if (endp args) + 0 + (if (endp (cdr args)) + (car args) + `(binary-clk+ ,(car args) + (clk+ ,@(cdr args)))))) + +(define x86-run + ;; I fixed n to a fixnum for efficiency. Also, executing more than + ;; 2^59 instructions in one go seems kind of daunting. + ((n :type (unsigned-byte 59)) + x86) + + :parents (x86-decoder) + :short "Top-level specification function for the x86 ISA model" + :long "

@('x86-run') returns the x86 state obtained by executing + @('n') instructions or until it halts, whatever comes first. It + simply called the step function @(see x86-fetch-decode-execute) + recursively.

" + + :returns (x86 x86p :hyp (x86p x86)) + + (cond ((fault x86) + x86) + ((ms x86) + x86) + ((mbe :logic (zp n) + :exec (equal 0 n)) + x86) + (t (let* ((x86 (x86-fetch-decode-execute x86)) + (n (the (unsigned-byte 59) (1- n)))) + (x86-run n x86)))) + + + /// + + (defthmd x86-run-and-x86-fetch-decode-and-execute-commutative + ;; x86-fetch-decode-execute and x86-run can commute. + (implies (and (natp k) + (x86p x86) + (not (ms x86)) + (not (fault x86))) + (equal (x86-run k (x86-fetch-decode-execute x86)) + (x86-fetch-decode-execute (x86-run k x86)))) + :hints (("Goal" :in-theory (e/d + (ms-fault-and-x86-fetch-decode-and-execute) ())))) + + + ;; Some opener theorems for x86-run: + + (defthm x86-run-halted + (implies (or (ms x86) (fault x86)) + (equal (x86-run n x86) x86))) + + (defthm x86-run-opener-not-ms-not-fault-zp-n + (implies (and (syntaxp (quotep n)) + (zp n)) + (equal (x86-run n x86) x86))) + + (defthm x86-run-opener-not-ms-not-zp-n + (implies (and (not (ms x86)) + (not (fault x86)) + (syntaxp (quotep n)) + (not (zp n))) + (equal (x86-run n x86) + (x86-run (1- n) (x86-fetch-decode-execute x86))))) + + ;; To enable compositional reasoning, we prove the following two + ;; theorems: + + (defthm x86-run-plus + (implies (and (natp n1) + (natp n2) + (syntaxp (quotep n1))) + (equal (x86-run (clk+ n1 n2) x86) + (x86-run n2 (x86-run n1 x86))))) + + (encapsulate + () + + (local (include-book "arithmetic/top" :dir :system)) + + (defthmd x86-run-plus-1 + (implies (and (natp n1) + (natp n2) + (syntaxp (quotep n1))) + (equal (x86-run (clk+ n1 n2) x86) + (x86-run n1 (x86-run n2 x86))))))) + +(in-theory (disable binary-clk+)) + +;; ---------------------------------------------------------------------- + +;; Some variants of x86-run: + +(define x86-run-steps1 + ((n :type (unsigned-byte 59)) + (n0 :type (unsigned-byte 59)) + x86) + + :enabled t + :guard (and (natp n) + (natp n0) + (<= n n0)) + + (b* ((diff (the (unsigned-byte 59) (- n0 n))) + ;; (- (if (equal (mod diff 100000000) 0) + ;; (save-x86 "x86-state" x86) + ;; nil)) + ) + (cond ((ms x86) + (mv diff x86)) + ((fault x86) + (mv diff x86)) + ((zp n) + (let* ((ctx 'x86-run) + (x86 (!!ms-fresh :timeout t))) + (mv diff x86))) + (t (b* ((x86 (x86-fetch-decode-execute x86)) + (n-1 (the (unsigned-byte 59) (1- n)))) + (x86-run-steps1 n-1 n0 x86)))))) + +(defun next-n-bytes-null-p (addr len x86) + (declare (xargs :stobjs (x86) + :mode :program)) + (b* (((when (equal len 0)) (mv t x86)) + ((mv flg val x86) (rvm08 addr x86)) + ((when flg) (mv t x86)) + ((when (not (equal val 0))) (mv nil x86))) + (next-n-bytes-null-p (1+ addr) (1- len) x86))) + +(define x86-run-steps + ((n :type (unsigned-byte 59)) + x86) + + :parents (x86-decoder) + :short "An alternative to @(see x86-run)" + :long "

@('x86-run-steps') returns two values --- number of steps + taken by the machine before it comes to a halt and the x86 state. + Note that the number of steps will always be less than or equal to + @('n').

" + + (x86-run-steps1 n n x86) + + /// + + (defthm x86-run-steps1-is-x86-run-ms + (implies (ms x86) + (equal (mv-nth 1 (x86-run-steps1 n n0 x86)) + (x86-run n x86)))) + + (defthm x86-run-steps1-is-x86-run-zp-n + (implies (and (not (ms x86)) + (not (fault x86)) + (zp n)) + (equal (mv-nth 1 (x86-run-steps1 n n0 x86)) + (!ms (list (list* 'x86-run + :rip (rip x86) + '(:timeout t))) + (x86-run n x86)))) + :hints (("Goal" :expand (x86-run n x86)))) + + (defthm x86-run-steps1-open + (implies (and (not (ms x86)) + (not (fault x86)) + (not (zp n))) + (equal (mv-nth 1 (x86-run-steps1 n n0 x86)) + (mv-nth 1 (x86-run-steps1 (1- n) n0 + (x86-fetch-decode-execute x86))))))) + +(in-theory (disable x86-run-steps1)) + +(define x86-fetch-decode-execute-halt + ((halt-address :type (signed-byte #.*max-linear-address-size*)) + x86) + :enabled t + :parents (x86-decoder) + :inline t + :no-function t + + :short "Alternative version of @(tsee x86-fetch-decode-execute) that sets the + @('MS') field if @('rip') is equal to @('halt-address')" + + :returns (x86 x86p :hyp (x86p x86)) + + :prepwork + ((local (in-theory (e/d* () (signed-byte-p unsigned-byte-p not))))) + + (if (equal (the (signed-byte #.*max-linear-address-size*) + (rip x86)) + halt-address) + (b* ((ctx 'x86-fetch-decode-execute-halt)) + (!!ms-fresh)) + (x86-fetch-decode-execute x86))) + +(define x86-run-halt + ((halt-address :type (signed-byte #.*max-linear-address-size*)) + (n :type (unsigned-byte 59)) + x86) + + :parents (x86-decoder) + :short "Alternative version of @(tsee x86-run) that uses @(tsee + x86-fetch-decode-execute-halt) instead of @(tsee x86-fetch-decode-execute)" + + :returns (x86 x86p :hyp (x86p x86)) + + (cond ((fault x86) x86) + ((ms x86) x86) + ((mbe :logic (zp n) :exec (equal 0 n)) x86) + (t (let* ((x86 (x86-fetch-decode-execute-halt halt-address x86)) + (n (the (unsigned-byte 59) (1- n)))) + (x86-run-halt halt-address n x86))))) + +(define x86-run-halt-count + ((halt-address :type (signed-byte #.*max-linear-address-size*)) + (n :type (unsigned-byte 59)) + x86 + (n0 :type (unsigned-byte 59))) + + :guard (<= n n0) ;; n == n0, to begin with. + + :short "A combination in functionality of @(tsee x86-run-steps) and @(tsee + x86-run-halt)" + + :long "

Run @('n') instructions or till @('halt-address') is reached, + whichever comes first. This function also returns the number of times @(tsee + x86-fetch-decode-execute-halt) is executed. Note that + @('x86-fetch-decode-execute-halt') is executed one more time than @(tsee + x86-fetch-decode-execute) --- i.e., when @('rip == halt-address').

" + + :returns (mv (steps natp :hyp (and (natp n0) (natp n)) + :rule-classes :type-prescription) + (x86 x86p :hyp (x86p x86))) + + (if (mbt (<= n n0)) + + (cond ((or (fault x86) + (ms x86) + (mbe :logic (zp n) :exec (equal 0 n))) + (mv (the (unsigned-byte 59) (- n0 n)) x86)) + (t + (let* ((x86 (x86-fetch-decode-execute-halt halt-address x86)) + (n (the (unsigned-byte 59) (1- n)))) + (x86-run-halt-count halt-address n x86 n0)))) + + (mv 0 x86))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/package.lsp b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/package.lsp new file mode 100644 index 000000000..48c8caecf --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/package.lsp @@ -0,0 +1,107 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +;; ====================================================================== + +(in-package "ACL2") + +(include-book "centaur/defrstobj2/portcullis" :dir :system) + +(include-book "centaur/bigmems/bigmem/portcullis" :dir :system) +(include-book "centaur/bigmems/bigmem-asymmetric/portcullis" :dir :system) +(include-book "centaur/bigmems/portcullis" :dir :system) + +(include-book "centaur/bitops/portcullis" :dir :system) +(include-book "centaur/fty/portcullis" :dir :system) +(include-book "centaur/gl/portcullis" :dir :system) +(include-book "std/portcullis" :dir :system) + +(defpkg "X86ISA" + (union-eq + '( + binary-logand + binary-logior + binary-logxor + + ;; Commenting out letters g and s to avoid name clashes, for + ;; e.g., acl2::g and x86isa::g would refer to the same function + ;; in x86isa/portcullis/records-0.lisp, which would have name + ;; clashes with the function acl2::g in misc/records.lisp. + + a b c d e f + ;; g + h i j k l m n o p q r + ;; s + t u v w x y z + lst + + definline + def-gl-thm + gl::defthm-using-gl + b* + include-raw + + ;; XDOC + defsection + defxdoc + top + + ;; TOOLS + fty::defprod + fty::defbitstruct + def-ruleset + def-ruleset! + add-to-ruleset + ruleset-theory + enable* + disable* + e/d* + std::defthm-natp + std::defthm-unsigned-byte-p + std::defthm-signed-byte-p + + x86isa ; so that top-level :doc topic is also in "ACL2" package + + acl2::defxdoc+ + ) + (union-eq *acl2-exports* + acl2::*bitops-exports* + std::*std-exports* + *common-lisp-symbols-from-main-lisp-package*))) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/portcullis.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/portcullis.lisp new file mode 100644 index 000000000..2d071821a --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/portcullis.lisp @@ -0,0 +1,42 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +; Added 1/11/2016 by Matt K. to avoid: "Error: Heap (dynamic space) overflow". +; cert_param: (non-cmucl) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-constants.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-constants.lisp new file mode 100644 index 000000000..3c3016b85 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-constants.lisp @@ -0,0 +1,661 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2024, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) + +(in-package "X86ISA") + +(include-book "std/util/defconsts" :dir :system) + +(local (include-book "sharp-dot-defuns")) + +;; ---------------------------------------------------------------------- + +;; Some expt constants: + +(defconst *2^0* (expt 2 0)) +(defconst *2^1* (expt 2 1)) +(defconst *2^2* (expt 2 2)) +(defconst *2^3* (expt 2 3)) +(defconst *2^4* (expt 2 4)) +(defconst *2^5* (expt 2 5)) +(defconst *2^6* (expt 2 6)) +(defconst *2^7* (expt 2 7)) +(defconst *2^8* (expt 2 8)) +(defconst *2^8-1* (- *2^8* 1)) +(defconst *2^12* (expt 2 12)) +(defconst *2^12-1* (- *2^12* 1)) +(defconst *2^15* (expt 2 15)) +(defconst *2^16* (expt 2 16)) +(defconst *2^16-1* (- *2^16* 1)) +(defconst *2^18* (expt 2 18)) +(defconst *2^21* (expt 2 21)) +(defconst *2^21-1* (- *2^21* 1)) +(defconst *2^22* (expt 2 22)) +(defconst *2^22-1* (- *2^22* 1)) +(defconst *2^24* (expt 2 24)) +(defconst *2^25* (expt 2 25)) +(defconst *2^26* (expt 2 26)) +(defconst *2^27* (expt 2 27)) +(defconst *2^27-1* (- *2^27* 1)) +(defconst *2^28* (expt 2 28)) +(defconst *2^30* (expt 2 30)) +(defconst *2^31* (expt 2 31)) +(defconst *2^32* (expt 2 32)) +(defconst *2^35* (expt 2 35)) +(defconst *2^43* (expt 2 43)) +(defconst *2^44* (expt 2 44)) +(defconst *2^45* (expt 2 45)) +(defconst *2^47* (expt 2 47)) +(defconst *-2^47* (- (expt 2 47))) +(defconst *2^47-1* (- *2^47* 1)) +(defconst *2^47-8* (- *2^47* 8)) +(defconst *2^47-16* (- *2^47* 16)) +(defconst *2^48* (expt 2 48)) +(defconst *2^48-1* (- *2^48* 1)) +(defconst *2^48-8* (- *2^48* 8)) +(defconst *2^48-16* (- *2^48* 16)) +(defconst *2^52* (expt 2 52)) +(defconst *2^63* (expt 2 63)) +(defconst *2^64* (expt 2 64)) +(defconst *2^64-1* (- *2^64* 1)) +(defconst *2^127* (expt 2 127)) +(defconst *2^128* (expt 2 128)) +(defconst *2^256* (expt 2 256)) +(defconst *2^512* (expt 2 512)) +(defconst *2^32-1* (- *2^32* 1)) +(defconst *2^32-2* (- *2^32* 2)) +(defconst *2^32-3* (- *2^32* 3)) +(defconst *2^32-4* (- *2^32* 4)) +(defconst *2^32-5* (- *2^32* 5)) +(defconst *2^32-6* (- *2^32* 6)) +(defconst *2^32-7* (- *2^32* 7)) +(defconst *2^32-8* (- *2^32* 8)) +(defconst *2^32-9* (- *2^32* 9)) +(defconst *2^32-10* (- *2^32* 10)) +(defconst *2^32-11* (- *2^32* 11)) +(defconst *2^32-12* (- *2^32* 12)) +(defconst *2^32-13* (- *2^32* 13)) +(defconst *2^32-14* (- *2^32* 14)) +(defconst *2^32-15* (- *2^32* 15)) +(defconst *2^32-16* (- *2^32* 16)) + +;; ---------------------------------------------------------------------- + +;; Prefixes (Intel manual, Dec'23, Vol. 2A, Section 2): + +(defconst *prefixes-width* + ;; Width of the prefixes layout structure; see :doc + ;; legacy-prefixes-layout-structure. + 52) + +;; Group 1: +(defconst *lock* #xF0) +(defconst *rep* #xF3) +(defconst *repe* #xF3) +(defconst *repne* #xF2) + +;; Group 2: +(defconst *es-override* #x26) +(defconst *cs-override* #x2E) +(defconst *ss-override* #x36) +(defconst *ds-override* #x3E) +(defconst *fs-override* #x64) +(defconst *gs-override* #x65) + +;; Group 3: +(defconst *operand-size-override* #x66) + +;; Group 4: +(defconst *addr-size-override* #x67) + +;; Mandatory Prefixes (for certain instructions): +(defconst *mandatory-66h* #x66) +(defconst *mandatory-f2h* #xF2) +(defconst *mandatory-f3h* #xF3) + +;; VEX Prefix: + +(defconst *vex-width* + ;; Width of the vex prefixes layout structure; see :doc + ;; vex-prefixes-layout-structures. + 24) + +(defconst *vex2-byte0* #xC5) ;; First byte of the 2-byte VEX prefix +(defconst *vex3-byte0* #xC4) ;; First byte of the 3-byte VEX prefix + +;; EVEX Prefix: + +(defconst *evex-width* + ;; Width of the evex prefixes layout structure; see :doc + ;; evex-prefixes-layout-structures. + 32) + +(defconst *evex-byte0* #x62) ;; First byte of the 4-byte EVEX prefix + +;; The following constants apply to both VEX and EVEX prefixes: + +;; Two-bit values of the PP field: +(defconst *v66* #b01) +(defconst *vF3* #b10) +(defconst *vF2* #b11) +;; 4-bit values of the M-MMMM field (MMM for EVEX): +(defconst *v0F* #b00001) +(defconst *v0F38* #b00010) +(defconst *v0F3A* #b00011) + +;; ---------------------------------------------------------------------- + +;; Identifiers of some arithmetic and logical instructions: +;; (note: different from the opcode; specific to the formal model) + +;; Even IDs: Arithmetic Instructions + +(defconst *OP-ADD* 0) +(defconst *OP-ADC* 2) +(defconst *OP-SUB* 4) +(defconst *OP-SBB* 6) +(defconst *OP-CMP* 8) +(defconst *OP-SAL/SHL* 10) +(defconst *OP-SHR* 12) +(defconst *OP-SAR* 14) +(defconst *OP-RCL* 16) +(defconst *OP-RCR* 18) +(defconst *OP-ROL* 20) +(defconst *OP-ROR* 22) +(defconst *OP-NEG* 24) +(defconst *OP-MUL* 26) +(defconst *OP-DIV* 28) +(defconst *OP-IMUL* 30) +(defconst *OP-IDIV* 32) +(defconst *OP-MAX* 34) +(defconst *OP-MIN* 36) +(defconst *OP-XADD* 38) + +;; Odd IDs: Logical Instructions + +(defconst *OP-OR* 1) +(defconst *OP-AND* 3) +(defconst *OP-XOR* 5) +(defconst *OP-TEST* 7) +(defconst *OP-BT* 9) +(defconst *OP-CMPXCHG* 11) +(defconst *OP-ANDN* 13) + +;; FP IDs: + +(defconst *OP-SP* 0) +(defconst *OP-DP* 1) + +;; Single/Double FP conversions: + +(defconst *SP-TO-DP* 0) +(defconst *DP-TO-SP* 1) + +;; SIMD packs: + +(defconst *LOW-PACK* 0) +(defconst *HIGH-PACK* 1) + +;; IDs: Comparison Instructions + +(defconst *OP-CMPEQ* 0) +(defconst *OP-CMPLT* 1) +(defconst *OP-CMPLE* 2) +(defconst *OP-CMPUNORD* 3) +(defconst *OP-CMPNEQ* 4) +(defconst *OP-CMPNLT* 5) +(defconst *OP-CMPNLE* 6) +(defconst *OP-CMPORD* 7) +(defconst *OP-COMI* 8) +(defconst *OP-UCOMI* 9) + +;; ---------------------------------------------------------------------- + +;; REX bits (Intel manual, Dec'23, Vol. 2A, Section 2.2.1.2): + +(defconst *b* 0) +(defconst *x* 1) +(defconst *r* 2) +(defconst *w* 3) + +;; Rflags (Intel manual, Dec'23, Vol. 1, Figure 3-8): + +(defconst *cf* 0) ;; Carry Flag +(defconst *pf* 2) ;; Parity Flag +(defconst *af* 4) ;; Auxiliary Carry Flag +(defconst *zf* 6) ;; Zero Flag +(defconst *sf* 7) ;; Sign Flag +(defconst *tf* 8) ;; Trap Flag +(defconst *if* 9) ;; Interrupt Enable Flag +(defconst *df* 10) ;; Direction Flag +(defconst *of* 11) ;; Overflow Flag +(defconst *iopl* 12) ;; I/O Privilege Level (also includes bit 13) +(defconst *nt* 14) ;; Nested Task +(defconst *rf* 16) ;; Resume Flag +(defconst *vm* 17) ;; Virtual-8086 Mode +(defconst *ac* 18) ;; Alignment Check / Access Control +(defconst *vif* 19) ;; Virtual Interrupt Flag +(defconst *vip* 20) ;; Virtual Interrupt Pending +(defconst *id* 21) ;; ID flag + +(defconst *flg-names* + (list *cf* *pf* *af* *zf* *sf* *tf* *if* *df* + *of* *iopl* *nt* *rf* *vm* *ac* *vif* *vip* *id*)) + +(make-event + `(defconst *max-flg-index* + ,(max-list *flg-names*))) + +;; FP Status Register (Intel Manual, Dec'23, Vol. 1, Figure 8-4): + +(defconst *fp-ie* 0) ;; Invalid Operation Flag +(defconst *fp-de* 1) ;; Denormalized Operand Flag +(defconst *fp-ze* 2) ;; Zero Divide Flag +(defconst *fp-oe* 3) ;; Overflow Flag +(defconst *fp-ue* 4) ;; Underflow Flag +(defconst *fp-pe* 5) ;; Precision Flag +(defconst *fp-sf* 6) ;; Stack Fault +(defconst *fp-es* 7) ;; Error Summary Status +(defconst *fp-c0* 8) ;; Condition Code +(defconst *fp-c1* 9) ;; Condition Code +(defconst *fp-c2* 10) ;; Condition Code +(defconst *fp-top* 11) ;; Top of Stack Pointer +(defconst *fp-c3* 14) ;; Condition Code +(defconst *fp-b* 15) ;; FPU Busy + +(defconst *fp-status-names* + (list *fp-ie* *fp-de* *fp-ze* *fp-oe* *fp-ue* *fp-pe* *fp-sf* + *fp-es* *fp-c0* *fp-c1* *fp-c2* *fp-top* *fp-c3* *fp-b*)) + +;; MXCSR (Intel Manual, Dec'23, Vol. 1, Figure 10-3): + +;; Bits 16 through 31 of the MXCSR register are reserved and are +;; cleared on a power-up or reset of the processor; attempting to +;; write a non-zero value to these bits, using either the FXRSTOR +;; or LDMXCSR instructions, will result in a general-protection +;; exception (#GP) being generated. + +(defconst *mxcsr-ie* 0) ;; Invalid Operation Flag +(defconst *mxcsr-de* 1) ;; Denormal Flag +(defconst *mxcsr-ze* 2) ;; Divide-by-Zero Flag +(defconst *mxcsr-oe* 3) ;; Overflow Flag +(defconst *mxcsr-ue* 4) ;; Underflow Flag +(defconst *mxcsr-pe* 5) ;; Precision Flag +(defconst *mxcsr-daz* 6) ;; Denormals Are Zeros +(defconst *mxcsr-im* 7) ;; Invalid Operation Mask +(defconst *mxcsr-dm* 8) ;; Denormal Mask +(defconst *mxcsr-zm* 9) ;; Divide-by-Zero Mask +(defconst *mxcsr-om* 10) ;; Overflow Mask +(defconst *mxcsr-um* 11) ;; Underflow Mask +(defconst *mxcsr-pm* 12) ;; Precision Mask +(defconst *mxcsr-rc* 13) ;; Rounding Control +(defconst *mxcsr-ftz* 15) ;; Flush to Zero +(defconst *mxcsr-reserved* 16) ;; Reserved + + +(defconst *mxcsr-names* + (list *mxcsr-ie* *mxcsr-de* *mxcsr-ze* *mxcsr-oe* *mxcsr-ue* + *mxcsr-pe* *mxcsr-daz* *mxcsr-im* *mxcsr-dm* *mxcsr-zm* + *mxcsr-om* *mxcsr-um* *mxcsr-pm* *mxcsr-rc* *mxcsr-ftz* + *mxcsr-reserved*)) + + +;; Access GPR, XMM, YMM, ZMM, or MMX (specific to the formal model): + +(defconst *gpr-access* 0) +(defconst *xmm-access* 1) ;; Non-VEX Encoded SIMD Instructions +(defconst *vex-xmm-access* 2) +(defconst *ymm-access* 3) +(defconst *zmm-access* 4) +(defconst *mmx-access* 5) + +;; Rounding Control bit definitions (Intel manual, Dec'23, Vol. 1, Table 4-8): + +(defconst *rc-rn* 0) +(defconst *rc-rd* 1) +(defconst *rc-ru* 2) +(defconst *rc-rz* 3) + +;; Constants for (unordered) compare scalar floating-point +;; instructions (COMISS, UCOMISS, etc.) (specific to the formal model): + +(defconst *unordered* 0) +(defconst *greater_than* 1) +(defconst *less_than* 2) +(defconst *equal* 3) + +;; Single-precision floating-point +;; format (Intel manual, Dec'23, Vol. 1, Table 4-3): + +(defconst *ieee-sp-exp-width* 8) +(defconst *ieee-sp-frac-width* 23) + +;; Double-precision floating-point format +;; format (Intel manual, Dec'23, Vol. 1, Table 4-3): + +(defconst *ieee-dp-exp-width* 11) +(defconst *ieee-dp-frac-width* 52) + +;; Extended Feature Enable Register (Intel manual, Dec'23, Vol. 3A, Table 2-1) + +(defconst *ia32_efer-sce* 0) ;; Syscall Enable (R/W) --- enables + ;; SYSCALL/SYSRET +(defconst *ia32_efer-lme* 8) ;; Long Mode Enabled (R/W) +(defconst *ia32_efer-lma* 10) ;; Long Mode Active (R) +(defconst *ia32_efer-nxe* 11) ;; Execute Disable Bit Enable (R/W) + ;; (Enables page access restriction by + ;; preventing instruction fetches from + ;; PAE pages with the XD bit set) + +(defconst *ia32_efer-names* + (list *ia32_efer-sce* *ia32_efer-lme* *ia32_efer-lma* *ia32_efer-nxe*)) + +;; ---------------------------------------------------------------------- + +; Constants related to the memory model in the x86 state: + +; Virtual Memory: + +(defconst *max-linear-address-size* 48) +(defconst *max-linear-address-size+1* (1+ *max-linear-address-size*)) +(defconst *max-linear-address-size+2* (+ 2 *max-linear-address-size*)) +(defconst *max-linear-address-size+3* (+ 3 *max-linear-address-size*)) +(defconst *max-linear-address-size+4* (+ 4 *max-linear-address-size*)) +(defconst *max-linear-address-size+5* (+ 5 *max-linear-address-size*)) +(defconst *max-linear-address-size+6* (+ 6 *max-linear-address-size*)) +(defconst *max-linear-address-size+7* (+ 7 *max-linear-address-size*)) +(defconst *max-linear-address-size+8* (+ 8 *max-linear-address-size*)) +(defconst *max-linear-address-size+9* (+ 9 *max-linear-address-size*)) +(defconst *max-linear-address-size+10* (+ 10 *max-linear-address-size*)) +(defconst *max-linear-address-size+11* (+ 11 *max-linear-address-size*)) +(defconst *max-linear-address-size+12* (+ 12 *max-linear-address-size*)) +(defconst *max-linear-address-size+13* (+ 13 *max-linear-address-size*)) +(defconst *max-linear-address-size+14* (+ 14 *max-linear-address-size*)) +(defconst *max-linear-address-size+15* (+ 15 *max-linear-address-size*)) +(defconst *max-linear-address-size+16* (+ 16 *max-linear-address-size*)) +(defconst *max-linear-address-size+17* (+ 17 *max-linear-address-size*)) +(defconst *max-linear-address-size+18* (+ 18 *max-linear-address-size*)) +(defconst *max-linear-address-size+19* (+ 19 *max-linear-address-size*)) +(defconst *max-linear-address-size+20* (+ 20 *max-linear-address-size*)) +(defconst *max-linear-address-size+21* (+ 21 *max-linear-address-size*)) +(defconst *max-linear-address-size+22* (+ 22 *max-linear-address-size*)) +(defconst *max-linear-address-size+23* (+ 23 *max-linear-address-size*)) +(defconst *max-linear-address-size+24* (+ 24 *max-linear-address-size*)) +(defconst *max-linear-address-size+25* (+ 25 *max-linear-address-size*)) +(defconst *max-linear-address-size+26* (+ 26 *max-linear-address-size*)) +(defconst *max-linear-address-size+27* (+ 27 *max-linear-address-size*)) +(defconst *max-linear-address-size+28* (+ 28 *max-linear-address-size*)) +(defconst *max-linear-address-size+29* (+ 29 *max-linear-address-size*)) +(defconst *max-linear-address-size+30* (+ 30 *max-linear-address-size*)) +(defconst *max-linear-address-size+31* (+ 31 *max-linear-address-size*)) +(defconst *max-linear-address-size+32* (+ 32 *max-linear-address-size*)) +(defconst *max-linear-address-size+33* (+ 33 *max-linear-address-size*)) +(defconst *max-linear-address-size+34* (+ 34 *max-linear-address-size*)) +(defconst *max-linear-address-size+35* (+ 35 *max-linear-address-size*)) +(defconst *max-linear-address-size+36* (+ 36 *max-linear-address-size*)) +(defconst *max-linear-address-size+37* (+ 37 *max-linear-address-size*)) +(defconst *max-linear-address-size+38* (+ 38 *max-linear-address-size*)) +(defconst *max-linear-address-size+39* (+ 39 *max-linear-address-size*)) +(defconst *max-linear-address-size+40* (+ 40 *max-linear-address-size*)) +(defconst *max-linear-address-size+41* (+ 41 *max-linear-address-size*)) +(defconst *max-linear-address-size+42* (+ 42 *max-linear-address-size*)) +(defconst *max-linear-address-size+43* (+ 43 *max-linear-address-size*)) +(defconst *max-linear-address-size+44* (+ 44 *max-linear-address-size*)) +(defconst *max-linear-address-size+45* (+ 45 *max-linear-address-size*)) +(defconst *max-linear-address-size+46* (+ 46 *max-linear-address-size*)) +(defconst *max-linear-address-size+47* (+ 47 *max-linear-address-size*)) +(defconst *max-linear-address-size+48* (+ 48 *max-linear-address-size*)) +(defconst *max-linear-address-size+49* (+ 49 *max-linear-address-size*)) +(defconst *max-linear-address-size+50* (+ 50 *max-linear-address-size*)) +(defconst *max-linear-address-size+51* (+ 51 *max-linear-address-size*)) +(defconst *max-linear-address-size+52* (+ 52 *max-linear-address-size*)) +(defconst *max-linear-address-size+53* (+ 53 *max-linear-address-size*)) +(defconst *max-linear-address-size+54* (+ 54 *max-linear-address-size*)) +(defconst *max-linear-address-size+55* (+ 55 *max-linear-address-size*)) +(defconst *max-linear-address-size+56* (+ 56 *max-linear-address-size*)) +(defconst *max-linear-address-size+57* (+ 57 *max-linear-address-size*)) +(defconst *max-linear-address-size+58* (+ 58 *max-linear-address-size*)) +(defconst *max-linear-address-size+59* (+ 59 *max-linear-address-size*)) +(defconst *max-linear-address-size+60* (+ 60 *max-linear-address-size*)) +(defconst *max-linear-address-size+61* (+ 61 *max-linear-address-size*)) +(defconst *max-linear-address-size+62* (+ 62 *max-linear-address-size*)) +(defconst *max-linear-address-size+63* (+ 63 *max-linear-address-size*)) +(defconst *max-linear-address-size-1* (1- *max-linear-address-size*)) +(defconst *2^max-linear-address-size-1* (expt 2 *max-linear-address-size-1*)) +(defconst *-2^max-linear-address-size-1* (- *2^max-linear-address-size-1*)) +(defconst *max-linear-address-space* (expt 2 *max-linear-address-size*)) +(defconst *max-linear-page-size* (- *max-linear-address-size* 12)) + +; Physical Memory: + +(defconst *physical-address-size* 52) ; Intel Manual Dec'23 Vol 1 Section 3.2.1 +(defconst *physical-address-size+1* (+ 1 *physical-address-size*)) +(defconst *physical-address-size+2* (+ 2 *physical-address-size*)) +(defconst *physical-address-size+4* (+ 4 *physical-address-size*)) +(defconst *physical-address-size+7* (+ 7 *physical-address-size*)) +(defconst *mem-size-in-bytes* (expt 2 *physical-address-size*)) +(defconst *mem-size-in-words* (floor *mem-size-in-bytes* 2)) +(defconst *mem-size-in-dwords* (floor *mem-size-in-bytes* 4)) +(defconst *mem-size-in-qwords* (floor *mem-size-in-bytes* 8)) + +(defconst *mem-size-in-bytes-1* (+ -1 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-2* (+ -2 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-3* (+ -3 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-4* (+ -4 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-5* (+ -5 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-6* (+ -6 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-7* (+ -7 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-8* (+ -8 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-9* (+ -9 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-10* (+ -10 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-11* (+ -11 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-12* (+ -12 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-13* (+ -13 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-14* (+ -14 *mem-size-in-bytes*)) +(defconst *mem-size-in-bytes-15* (+ -15 *mem-size-in-bytes*)) + +;; ---------------------------------------------------------------------- + +;; Constants related to Flags (specific to the formal model): + +(defconst *unchanged* 2) +(defconst *undefined* 3) + +;; ---------------------------------------------------------------------- + +;; Instruction Sets: + +;; Floating-Point (specific to the formal model): +(defconst *fpu* 0) +(defconst *mmx* 1) +(defconst *sse* 2) +(defconst *sse2* 3) +(defconst *sse3* 4) +(defconst *avx* 5) +(defconst *avx2* 6) +(defconst *avx512* 7) + +;; ---------------------------------------------------------------------- + +;; Constants related to modes of operation of an x86 processor +;; (specific to the formal model): + +;; IA-32e Mode, introduced by Intel 64(R) Architecture, has the following two +;; sub-modes: +(defconst *64-bit-mode* 0) +(defconst *compatibility-mode* 1) + +;; IA-32 architecture supports the following modes: +(defconst *protected-mode* 2) ;; Virtual-8086 mode is built into it +(defconst *real-address-mode* 3) +(defconst *smm-mode* 4) ;; System Management Mode + +;; Total Number of Processor Modes: +(defconst *num-proc-modes* 5) +(defconst *num-proc-modes-1* (1- *num-proc-modes*)) + +;; ---------------------------------------------------------------------- + +;; Exceptions and Interrupts +;; Reference: Intel Manual Dec'23 Volume 1 Table 6-1 + +; Mnemonic Vector Description & +; Source + +(defconst *#DE* 0) ; Divide Error + ; DIV and IDIV instructions. + +(defconst *#DB* 1) ; Debug + ; Any code or data reference. + +(defconst *#NMI* 2) ; Reserved: NMI Interrupt + ; Non-maskable external interrupt. + +(defconst *#BP* 3) ; Breakpoint + ; INT3 instruction. + +(defconst *#OF* 4) ; Overflow + ; INTO instruction. + +(defconst *#BR* 5) ; BOUND Range Exceeded + ; BOUND instruction. + +(defconst *#UD* 6) ; Invalid Opcode (UnDefined Opcode) + ; UD instruction or reserved opcode. + +(defconst *#NM* 7) ; Device Not Available (No Math Coprocessor) + ; Floating-point or WAIT/FWAIT instruction. + +(defconst *#DF* 8) ; Double Fault + ; Any instruction that can generate an exception, an + ; NMI, or an INTR. + +(defconst *#resMF* 9) ; CoProcessor Segment Overrun (reserved) + ; Floating-point instruction. + ; NOTE: IA-32 processors after the Intel386 + ; processor do not generate this exception. + +(defconst *#TS* 10) ; Invalid TSS + ; Task switch or TSS access. + +(defconst *#NP* 11) ; Segment Not Present + ; Loading segment registers or accessing system segments. + +(defconst *#SS* 12) ; Stack Segment Fault + ; Stack operations and SS register loads. + +(defconst *#GP* 13) ; General Protection + ; Any memory reference and other protection checks. + +(defconst *#PF* 14) ; Page Fault + ; Any memory reference + +(defconst *#res15* 15) ; Reserved + +(defconst *#MF* 16) ; Floating-Point Error (Math Fault) + ; Floating-point or WAIT/FWAIT instruction. + +(defconst *#AC* 17) ; Alignment Check + ; Any data reference in memory. + ; This exception was introduced in the Intel486 processor. + +(defconst *#MC* 18) ; Machine Check + ; Error codes (if any) and source are model dependent. + ; This exception was introduced in the Pentium + ; processor and enhanced in the P6 family + ; processors. + +(defconst *#XM* 19) ; SIMD Floating-Point Exception + ; SIMD Floating-Point Instruction + ; This exception was introduced in the Pentium III + ; processor. + +(defconst *#VE* 20) ; Virtualization Exception + ; EPT violations + ; This exception can occur only on processors that + ; support the 1-setting of the “EPT-violation #VE” + ; VM-execution control. + +(defconst *#CP* 21) ; Control Protection Exception + ; The RET, IRET, RSTORSSP, and SETSSBSY instructions + ; can generate this exception. When CET indirect + ; branch tracking is enabled, this exception can be + ; generated due to a missing ENDBRANCH instruction + ; at the target of an indirect call or jump. + +;; 22-31 Reserved +;; +;; 32-255 Maskable Interrupts +;; External interrupt from INTR pin or INT n instruction. + +;; ---------------------------------------------------------------------- + +;; Indices and length of fields in the x86 state (see +;; machine/concrete-state.lisp): + +(make-event (define-general-purpose-registers)) +(make-event (define-32-bit-general-purpose-registers)) + +(make-event (define-segment-registers)) +(defconst *segment-register-names-len-1* (1- *segment-register-names-len*)) + +(make-event (define-gdtr/idtr-registers)) + +(make-event (define-ldtr/tr-registers)) + +(make-event (define-control-registers)) + +(make-event (define-debug-registers)) + +(make-event (define-fp-registers)) + +(make-event (define-mmx-registers)) + +(make-event (define-xmm-registers)) + +(make-event (define-ymm-registers)) + +(make-event (define-zmm-registers)) + +(make-event (define-opmsk-registers)) + +(make-event (define-model-specific-registers)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-defuns.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-defuns.lisp new file mode 100644 index 000000000..39d189e0e --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/sharp-dot-defuns.lisp @@ -0,0 +1,323 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2020, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "utils") +(include-book "std/util/bstar" :dir :system) + +;; ---------------------------------------------------------------------- + +;; Indices and length of fields in the x86 state (see +;; machine/concrete-state.lisp): + +(defun define-general-purpose-registers () + + ;; These indices are from Tables 2-1, 2-2, and 2-3 (addressing modes), as well + ;; as Tables B-2, B-3, B-4, and B-5 of Intel Manual Volume 2 (Dec 2023): + `(defconsts (*RAX* *RCX* *RDX* *RBX* *RSP* *RBP* *RSI* *RDI* + *R8* *R9* *R10* *R11* *R12* *R13* *R14* *R15* + *64-bit-general-purpose-registers-len*) + ,(b* ((lst (increasing-list 0 1 16)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +(defun define-32-bit-general-purpose-registers () + + ;; These are the same as *RAX* etc. above: + `(defconsts (*EAX* *ECX* *EDX* *EBX* *ESP* *EBP* *ESI* *EDI* + *R8d* *R9d* *R10d* *R11d* *R12d* *R13d* *R14d* *R15d*) + ,(b* ((lst (increasing-list 0 1 15)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +(defun define-segment-registers () + + ;; These are from Table B-8 of the Intel Manual Volume 2 (Dec 2023); + ;; these indices are used in the Reg field of the ModR/M byte of the + ;; instructions 'MOV ..., ', to represent ('MOV ..., CS' + ;; is disallowed, but the only index not used for the other segment registers + ;; is 1): + `(defconsts (*ES* *CS* *SS* *DS* *FS* *GS* + *segment-register-names-len*) + ,(b* ((lst (increasing-list 0 1 6)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +(defun define-gdtr/idtr-registers () + + ;; Specific to the formal model: + `(defconsts (*GDTR* *IDTR* *gdtr-idtr-names-len*) + ,(b* ((lst (increasing-list 0 1 2)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +(defun define-ldtr/tr-registers () + + ;; Specific to the formal model: + `(defconsts (*LDTR* *TR* *ldtr-tr-names-len*) + ,(b* ((lst (increasing-list 0 1 2)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +;; Source: Intel Manual Volume 3 Section 2.5 (Dec 2023) +(defun define-control-registers () + + ;; These indices are used in the Reg field of the ModR/M byte of the + ;; instructions MOV from/to control registers (also see Intel Manual + ;; Volume 2 Table B-9 and Section 2.2.2 (Dec 2023)): + `(defconsts (*CR0* ;; cr0 controls operating mode and states of + ;; processor + *CR1* ;; cr1 is reserved + *CR2* ;; cr2 holds the page fault linear address (the + ;; one that caused the page fault) + *CR3* ;; cr3 is associated with paging + *CR4* ;; cr4 enables or indicates support for processor + ;; extensions + *CR5* ;; cr5 is reserved + *CR6* ;; cr6 is reserved + *CR7* ;; cr7 is reserved + *CR8* ;; cr8 provides read/write access to the TPR. + ;; (Task Priority Register) available only in 64 + ;; bit mode (see Intel Manual Volume 2 Section 2.2.2 + ;; (Dec 2023)) + ;; cr9 thru cr15 are not implemented in our model yet. + *CR9* *CR10* *CR11* *CR12* *CR13* *CR14* *CR15* + *XCR0* ; TODO: separate this from the *CR...*s + *control-register-names-len*) + ,(b* ((lst (increasing-list 0 1 17)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +(defun define-debug-registers () + + ;; These indices are used in the Reg field of the ModR/M byte of the + ;; instructions MOV from/to debug registers (also see Intel Manual + ;; Volume 2 Table B-9 and Section 2.2.2 (Dec 2023)): + `(defconsts (*DR0* ;; dr0 holds breakpoint 0 virtual address, 64/32 bit + *DR1* ;; dr1 holds breakpoint 1 virtual address, 64/32 bit + *DR2* ;; dr2 holds breakpoint 2 virtual address, 64/32 bit + *DR3* ;; dr3 holds breakpoint 3 virtual address, 64/32 bit + *DR4* ;; dr4 is reserved + *DR5* ;; dr5 is reserved + *DR6* ;; dr6 + *DR7* ;; dr7 + *debug-register-names-len*) + ,(b* ((lst (increasing-list 0 1 8)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +;; Source: Intel Manual Volume 1 Section 8.1.2 (Dec 2023) +(defun define-fp-registers () + ;; 80-bit registers + + ;; Note: The Intel manual refers to these registers as R0, R1, ... , R7 + ;; (see Intel Manual Volume 1 Figure 8-1 (Dec 2023), + ;; but in our model, we will refer to them as FP0, FP1, ..., FP7. + + `(defconsts (*FP0* *FP1* *FP2* *FP3* *FP4* *FP5* *FP6* *FP7* + *fp-data-register-names-len*) + + ,(b* ((lst (increasing-list 0 1 8)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +;; Source: Intel Manual Volume 1 Section 9.2.2 (Dec 2023) +(defun define-mmx-registers () + ;; 64-bit registers + + ;; The MM registers (MM0 through MM7) are aliased to the low 64-bits of + ;; the FPU data registers (see Intel Manual Volume 1 Section 8.1 (Dec 2023)). + + `(defconsts (*MM0* *MM1* *MM2* *MM3* *MM4* *MM5* *MM6* *MM7* + *mmx-register-names-len*) + + ,(b* ((lst (increasing-list 0 1 8)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +;; Source: Intel Manual Volume 1 Sections 10.2.1 and 10.2.2 (Dec 2023) +(defun define-xmm-registers () + ;; 128-bit registers + + `(defconsts (*XMM0* *XMM1* *XMM2* *XMM3* *XMM4* *XMM5* *XMM6* *XMM7* + *XMM8* *XMM9* *XMM10* *XMM11* + *XMM12* *XMM13* *XMM14* *XMM15* + *xmm-register-names-len*) + + ,(b* ((lst (increasing-list 0 1 16)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +;; Source: Intel Manual Volume 1 Figure 14-1 (Dec 2023) +(defun define-ymm-registers () + ;; 256-bit registers + + `(defconsts (*YMM0* *YMM1* *YMM2* *YMM3* *YMM4* *YMM5* *YMM6* *YMM7* + *YMM8* *YMM9* *YMM10* *YMM11* + *YMM12* *YMM13* *YMM14* *YMM15* + *ymm-register-names-len*) + + ,(b* ((lst (increasing-list 0 1 16)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +;; Source: Intel Manual Volume 1 Figure 15-1 (Dec 2023) +(defun define-zmm-registers () + ;; 512-bit registers + + `(progn + ;; mv can't be given more than 32 arguments, so I've had to + ;; separately define *zmm-register-names-len*. + (defconst *zmm-register-names-len* 32) + (defconsts (*ZMM0* *ZMM1* *ZMM2* *ZMM3* *ZMM4* *ZMM5* *ZMM6* *ZMM7* + *ZMM8* *ZMM9* *ZMM10* *ZMM11* + *ZMM12* *ZMM13* *ZMM14* *ZMM15* + *ZMM16* *ZMM17* *ZMM18* *ZMM19* *ZMM20* + *ZMM21* *ZMM22* *ZMM23* *ZMM24* *ZMM25* + *ZMM26* *ZMM27* *ZMM28* *ZMM29* *ZMM30* + *ZMM31*) + + ,(b* ((lst (increasing-list 0 1 31)) + (len (len lst))) + (cons 'mv (append lst (list len))))))) + +;; Source: Intel Manual Volume 1 Section 15.1.3 (Dec 2023) +(defun define-opmsk-registers () + ;; 64-bit registers + + `(defconsts (*K0* *K1* *K2* *K3* *K4* *K5* *K6* *K7* + *opmsk-register-names-len*) + + ,(b* ((lst (increasing-list 0 1 8)) + (len (len lst))) + (cons 'mv (append lst (list len)))))) + +(defun define-model-specific-registers () + + ;; Source: Intel Manual Volume 4 Section 2.1 (Architectural MSRs) (Dec 2023) + + ;; At this point, we only model the MSRs that we need. Remember, + ;; these are Intel-specific registers, and may or may not be + ;; available on AMD machines. + + ;; The constants ending with IDX are used to index into the STOBJ + ;; field for model-specific registers. + + ;; Note that *ia32_efer-idx* and *ia32_efer* (as well as the other pairs) are + ;; different. The latter is the "address" of the register on the real + ;; machine and the former is the index of the register in the x86 stobj. So + ;; the *...-IDX* values are specific to the formal model. + + `(defconsts (*IA32_SYSENTER_CS* + *IA32_SYSENTER_CS-IDX* + + *IA32_SYSENTER_ESP* + *IA32_SYSENTER_ESP-IDX* + + *IA32_SYSENTER_EIP* + *IA32_SYSENTER_EIP-IDX* + + ;; extended features enables --- If + ;; CPUID.80000001.EDX.[bit 20] or + ;; CPUID.80000001.EDX.[bit 29] + *IA32_EFER* + *IA32_EFER-IDX* + + ;; Map of BASE Address of FS (R/W) --- If + ;; CPUID.80000001.EDX.[bit 29] = 1 + *IA32_FS_BASE* + *IA32_FS_BASE-IDX* + + ;; Map of BASE Address of GB (R/W) --- If + ;; CPUID.80000001.EDX.[bit 29] = 1 + *IA32_GS_BASE* + *IA32_GS_BASE-IDX* + + ;; Swap Target of BASE Address of GS (R/W) --- If + ;; CPUID.80000001.EDX.[bit 29] = 1 + *IA32_KERNEL_GS_BASE* + *IA32_KERNEL_GS_BASE-IDX* + + ;; System Call Target Address (R/W) --- If + ;; CPUID.80000001.EDX.[bit 29] = 1 + *IA32_STAR* + *IA32_STAR-IDX* + + ;; IA-32e Mode System Call Target Address (R/W) --- If + ;; CPUID.80000001.EDX.[bit 29] = 1 + *IA32_LSTAR* + *IA32_LSTAR-IDX* + + ;; System Call Flag Mask (R/W) --- If + ;; CPUID.80000001.EDX.[bit 29] = 1 + *IA32_FMASK* + *IA32_FMASK-IDX* + + *IA32_MISC_ENABLE* + *IA32_MISC_ENABLE-IDX* + + *model-specific-register-names-len*) + + ,(b* ((lst (list #ux174 + 8 + #ux175 + 9 + #ux176 + 10 + #uxC000_0080 ;; ia32_efer and idx + 0 + #uxC000_0100 ;; ia32_fs_base and idx + 1 + #uxC000_0101 ;; ia32_gs_base and idx + 2 + #uxC000_0102 ;; ia32_kernel_gs_base and idx + 3 + #uxC000_0081 ;; ia32_star and idx + 4 + #uxC000_0082 ;; ia32_lstar and idx + 5 + #uxC000_0084 ;; ia32_fmask and idx + 6 + #ux01_a0 ;; ia32_misc_enable and idx + 7 + )) + (len (/ (len lst) 2))) + (cons 'mv (append lst (list len)))))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/utils.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/utils.lisp new file mode 100644 index 000000000..edc442ade --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/portcullis/utils.lisp @@ -0,0 +1,76 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2020, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(local (include-book "arithmetic/top-with-meta" :dir :system)) + +;; ---------------------------------------------------------------------- + +; Some misc. functions used throughout the formal model: + +; On powers of 2, this function is a base 2 logarithm: +; it maps 2^n to n+count -- count is the accumulator. +(defun log-2 (x count) + (declare (xargs :measure (nfix x) + :guard (natp count))) + (if (natp x) + (if (<= x 1) + count + (log-2 (* 1/2 x) (1+ count))) + count)) + +; This function returns the list +; (start (+ by start) (+ (* 2 by) start) ... (+ (* (1- count) by) start)). +(defun increasing-list (start by count) + (declare (xargs :guard (and (natp start) + (natp by) + (natp count)))) + (if (zp count) + nil + (cons start + (increasing-list (+ by start) by (1- count))))) + +; Maximum of a list of numbers (NIL if the list is empty). +(defun max-list (l) + (if (or (endp l) + (equal (len l) 1)) + (car l) + (max (car l) (max-list (cdr l))))) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/utils/basic-structs.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/utils/basic-structs.lisp new file mode 100644 index 000000000..06b4b03b0 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/utils/basic-structs.lisp @@ -0,0 +1,74 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2018, Shilpi Goel +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "centaur/fty/bitstruct" :dir :system) + +;; We do these once, here, to avoid each defbitstruct below doing them locally: +(local (include-book "centaur/bitops/ihsext-basics" :dir :system)) +(local (include-book "centaur/bitops/equal-by-logbitp" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) + +(local (xdoc::set-default-parents structures)) + +;; Bitstruct field widths: + +(defbitstruct 2bits 2) +(defbitstruct 3bits 3) +(defbitstruct 4bits 4) +(defbitstruct 5bits 5) +(defbitstruct 6bits 6) +(defbitstruct 7bits 7) +(defbitstruct 8bits 8) +(defbitstruct 10bits 10) +(defbitstruct 11bits 11) +(defbitstruct 12bits 12) +(defbitstruct 13bits 13) +(defbitstruct 16bits 16) +(defbitstruct 17bits 17) +(defbitstruct 19bits 19) +(defbitstruct 22bits 22) +(defbitstruct 24bits 24) +(defbitstruct 31bits 31) +(defbitstruct 32bits 32) +(defbitstruct 36bits 36) +(defbitstruct 40bits 40) +(defbitstruct 45bits 45) +(defbitstruct 54bits 54) +(defbitstruct 64bits 64) diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/utils/fp-structures.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/utils/fp-structures.lisp new file mode 100644 index 000000000..dc1f27caa --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/utils/fp-structures.lisp @@ -0,0 +1,124 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel + +(in-package "X86ISA") + +(include-book "basic-structs") + +;; We do these once, here, to avoid each defbitstruct below doing them locally: +(local (include-book "centaur/bitops/ihsext-basics" :dir :system)) +(local (include-book "centaur/bitops/equal-by-logbitp" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) + +;; ---------------------------------------------------------------------- + +(defsection fp-bitstructs + :parents (structures) + :short "Bitstructs related to floating-point operations.") + +(local (xdoc::set-default-parents fp-bitstructs)) + +;; ---------------------------------------------------------------------- + +(defbitstruct fp-statusBits + :short "The x87 FPU Status Register." + :long "

Source: Intel Manual, Mar 2026, Vol. 1, Section 8.1.3.

" + ((ie bitp) ;; Invalid Operation Flag + (de bitp) ;; Denormalized Operand Flag + (ze bitp) ;; Zero Divide Flag + (oe bitp) ;; Overflow Flag + (ue bitp) ;; Underflow Flag + (pe bitp) ;; Precision Flag + (sf bitp) ;; Stack Fault + (es bitp) ;; Error Summary Status + (c0 bitp) ;; Condition Code + (c1 bitp) ;; Condition Code + (c2 bitp) ;; Condition Code + (top 3bits) ;; Top of stack pointer + (c3 bitp) ;; Condition Code + (b bitp) ;; FPU Busy + ) + :msb-first nil + :inline t) + +(local + (defthm fp-status-layout-ok + (iff (fp-statusBits-p x) + (unsigned-byte-p 16 x)) + :rule-classes nil)) + +(in-theory (disable unsigned-byte-p-when-fp-statusbits-p)) + +(defbitstruct mxcsrBits + :short "The MXCSR Control and Status Register." + :long "

Source: Intel Manual, Mar 2026, Vol. 1, Section 10.2.3.

" + ;; From the manual: + ;; Bits 16 through 31 of the MXCSR register are reserved and are + ;; cleared on a power-up or reset of the processor; attempting to + ;; write a non-zero value to these bits, using either the FXRSTOR + ;; or LDMXCSR instructions, will result in a general-protection + ;; exception (#GP) being generated. + ((ie bitp) ;; Invalid Operation Flag + (de bitp) ;; Denormal Flag + (ze bitp) ;; Divide-by-Zero Flag + (oe bitp) ;; Overflow Flag + (ue bitp) ;; Underflow Flag + (pe bitp) ;; Precision Flag + (daz bitp) ;; Denormals are Zeros + (im bitp) ;; Invalid Operation Mask + (dm bitp) ;; Denormal Mask + (zm bitp) ;; Divide-by-Zero Mask + (om bitp) ;; Overflow Mask + (um bitp) ;; Underflow Mask + (pm bitp) ;; Precision Mask + (rc 2bits) ;; Rounding Control + (ftz bitp) ;; Flush to Zero + (reserved 16bits) ;; Reserved bits + ) + :msb-first nil + :inline t) + +(local + (defthm mxcsr-layout-ok + (iff (mxcsrBits-p x) + (unsigned-byte-p 32 x)) + :rule-classes nil)) + +(in-theory (disable unsigned-byte-p-when-mxcsrbits-p)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/utils/paging-structures.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/utils/paging-structures.lisp new file mode 100644 index 000000000..27bf0e59a --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/utils/paging-structures.lisp @@ -0,0 +1,288 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author: +; Alessandro Coglio + +(in-package "X86ISA") + +(include-book "basic-structs") + +(include-book "xdoc/constructors" :dir :system) + +;; We do these once, here, to avoid each defbitstruct below doing them locally: +(local (include-book "centaur/bitops/ihsext-basics" :dir :system)) +(local (include-book "centaur/bitops/equal-by-logbitp" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) + +;; ---------------------------------------------------------------------- + +(defsection paging-bitstructs + :parents (structures) + :short "Bitstructs related to the paging data structures." + :long + (xdoc::topstring + (xdoc::p + "Source: + Intel Manual, Mar 2026, Vol. 3A, + Tables 5-15 through 5-20, + Figure 5-11.") + (xdoc::p + "For now we only model structures for 4-level paging. + As mentioned in + Intel Manual, Mar 2026, Vol. 3A, Section 5.1.1, footnote 1, + this paging mode was previously called `IA-32e paging': + this is why the names of the bitstructs below start with @('ia32e'). + We may want to update these names at some point, + perhaps when we add structures for the other paging three modes."))) + +(local (xdoc::set-default-parents paging-bitstructs)) + +;; ---------------------------------------------------------------------- + +(defbitstruct ia32e-page-tablesBits ; Tables 5-15 through 5-20 + + ;; This constant defines the common bit fields for page table + ;; structure entries. + + ;; The field reference-addr refers to the 40 bits in a paging + ;; structure entry that contain the address of the inferior paging + ;; structure. If this paging entry maps a page (PS=1) instead of + ;; referencing an inferior structure (PS=0), do not use the + ;; reference-addr field to access the address of the page. Use + ;; dedicated operations (e.g., those defined from the bitstruct + ;; ia32e-pdpte-1GB-page-layout) in that case, because unlike + ;; reference-addr, the address of the mapped page is contained in + ;; different-sized fields for each paging structure. + + ;; Note that the d, ps, res1, and res2 fields + ;; are not common to all the paging structures, + ;; as indicated in the comments next to them. + ;; It could be appropriate to: + ;; - rename d to d/res + ;; - rename ps to ps/pat + ;; - split res1 into g/res for bit 8 and res1 for bits 10:9 + ;; - split res2 into res2 for bits 58:52 and pkey/res for bits 62:59 + ;; We may do that at some point, + ;; but the current names, + ;; although not fully descriptive, + ;; may be adequate for the current uses of this structure. + + ((p bitp) ;; Page present + (r/w bitp) ;; Read/Write + (u/s bitp) ;; User/supervisor + (pwt bitp) ;; Page-level Write-Through + (pcd bitp) ;; Page-level Cache-Disable + (a bitp) ;; Accessed + (d bitp) ;; Dirty (or ignored) + (ps bitp) ;; Page size (or PAT) + (res1 3bits) ;; Ignored (bits 10:8), + ;; or global translation in bit 8 + (r bitp) ;; Ignored for ordinary paging; + ;; restart for HLAT paging + (reference-addr 40bits) ;; Address of inferior paging table + (res2 11bits) ;; Ignored (bits 62:52), + ;; or protection key in bits 62:59 + (xd bitp)) ;; Execute Disable + :msb-first nil + :inline t) + +(local + (defthm ia32e-page-tables-layout-ok + (iff (ia32e-page-tablesBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct ia32e-pml4eBits ; Table 5-15 + ((p bitp) ;; Present + (r/w bitp) ;; Read/write + (u/s bitp) ;; User/supervisor + (pwt bitp) ;; Page-level Write-Through + (pcd bitp) ;; Page-level Cache-Disable + (a bitp) ;; Accessed (whether entry has been used for LA translation) + (res1 bitp) ;; Ignored + (ps bitp) ;; Page size (must be 0) + (res2 3bits) ;; Ignored (bits 10:8) + (r bitp) ;; Ignored for ordinary paging; restart for HLAT paging + (pdpt 40bits) ;; Address of page-directory pointer table (bits 51:12, any M) + (res3 11bits) ;; Ignored (bits 62:52) + (xd bitp)) ;; If IA32_EFER.NXE = 1, execute disable; + ;; otherwise reserved (must be 0) + :msb-first nil + :inline t) + +(local + (defthm ia32e-pml4e-layout-ok + (iff (ia32e-pml4eBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct ia32e-pdpte-1GB-pageBits ; Table 5-16 + ((p bitp) ;; Present + (r/w bitp) ;; Read/write + (u/s bitp) ;; User/supervisor + (pwt bitp) ;; Page-level Write-Through + (pcd bitp) ;; Page-level Cache-Disable + (a bitp) ;; Accessed (whether entry has been used for LA translation) + (d bitp) ;; Dirty (whether referenced page was written) + (ps bitp) ;; Page size (Must be 1 for 1GB pages) + (g bitp) ;; Global translation + (res1 2bits) ;; Ignored (bits 10:9) + (r bitp) ;; Ignored for ordinary paging; restart for HLAT paging + (pat bitp) ;; PAT + (res2 17bits) ;; Reserved (bits 29:13) + (page 22bits) ;; Address of 1GB page (bits 51:30, any M) + (res3 7bits) ;; Ignored (bits 58:52) + (pkey 4bits) ;; Protection key + (xd bitp)) ;; If IA32_EFER.NXE = 1, execute disable; + ;; otherwise reserved (must be 0) + :msb-first nil + :inline t) + +(local + (defthm ia32e-pdpte-1GB-page-layout-ok + (iff (ia32e-pdpte-1GB-pageBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct ia32e-pdpte-pg-dirBits ; Table 5-17 + ((p bitp) ;; Present + (r/w bitp) ;; Read/write + (u/s bitp) ;; User/supervisor + (pwt bitp) ;; Page-level Write-Through + (pcd bitp) ;; Page-level Cache-Disable + (a bitp) ;; Accessed (whether this entry has been used for LA translation) + (res1 bitp) ;; Ignored + (ps bitp) ;; Page size (must be 0) + (res2 3bits) ;; Ignored (bits 10:8) + (r bitp) ;; Ignored for ordinary paging; restart for HLAT paging + (pd 40bits) ;; Address of 4K-aligned page directory (bits 51:12, any M) + (res3 11bits) ;; Ignored (bits 62:52) + (xd bitp)) ;; If IA32_EFER.NXE = 1, execute disable; + ;; otherwise reserved (must be 0) + :msb-first nil + :inline t) + +(local + (defthm ia32e-pdpte-pg-dir-layout-ok + (iff (ia32e-pdpte-pg-dirBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct ia32e-pde-2MB-pageBits ; Table 5-18 + ((p bitp) ;; Present + (r/w bitp) ;; Read/write + (u/s bitp) ;; User/supervisor + (pwt bitp) ;; Page-level Write-Through + (pcd bitp) ;; Page-level Cache-Disable + (a bitp) ;; Accessed + (d bitp) ;; Dirty (whether referenced page was written) + (ps bitp) ;; Page size (Must be 1 for 2MB pages) + (g bitp) ;; Global translation + (res1 2bits) ;; Ignored (bits 10:9) + (r bitp) ;; Ignored for ordinary paging; restart for HLAT paging + (pat bitp) ;; PAT + (res2 8bits) ;; Reserved (bits 20:13) + (page 31bits) ;; Address of the 2MB page (bits 51-21, any M) + (res3 7bits) ;; Ignored (bits 58:52) + (pkey 4bits) ;; Protection key + (xd bitp) ;; If IA32_EFER.NXE = 1, execute disable; + ;; otherwise reserved (must be 0) + ) + :msb-first nil + :inline t) + +(local + (defthm ia32e-pde-2MB-page-layout-ok + (iff (ia32e-pde-2MB-pageBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct ia32e-pde-pg-tableBits ; Table 5-19 + ((p bitp) ;; Present + (r/w bitp) ;; Read/write + (u/s bitp) ;; User/supervisor + (pwt bitp) ;; Page-level Write-Through + (pcd bitp) ;; Page-level Cache-Disable + (a bitp) ;; Accessed + (res1 bitp) ;; Ignored + (ps bitp) ;; Page size (must be 0) + (res2 3bits) ;; Ignored (bits 10:8) + (r bitp) ;; Ignored for ordinary paging; restart for HLAT paging + (pt 40bits) ;; Address of the 4K-aligned page table (bits 51:12, any M) + (res3 11bits) ;; Ignored (bits 62:52) + (xd bitp) ;; If IA32_EFER.NXE = 1, execute disable; + ;; otherwise reserved (must be 0) + ) + :msb-first nil + :inline t) + +(local + (defthm ia32e-pde-pg-table-layout-ok + (iff (ia32e-pde-pg-tableBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct ia32e-pte-4K-pageBits ; Table 5-20 + ((p bitp) ;; Present + (r/w bitp) ;; Read/write + (u/s bitp) ;; User/supervisor + (pwt bitp) ;; Page-level Write-Through + (pcd bitp) ;; Page-level Cache-Disable + (a bitp) ;; Accessed + (d bitp) ;; Dirty (whether referenced page was written) + (pat bitp) ;; PAT + (g bitp) ;; Global translation + (res1 2bits) ;; Ignored (bits 10:9) + (r bitp) ;; Ignored for ordinary paging; restart for HLAT paging + (page 40bits) ;; Address of the 4K page (bits 51:12, any M) + (res3 7bits) ;; Ignored (bits 58:52) + (pkey 4bits) ;; Protection key + (xd bitp) ;; If IA32_EFER.NXE = 1, execute disable; + ;; otherwise reserved (must be 0) + ) + :msb-first nil + :inline t) + +(local + (defthm ia32e-pte-4k-page-layout-ok + (iff (ia32e-pte-4k-pageBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/utils/records-0.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/utils/records-0.lisp new file mode 100644 index 000000000..eb7b2eef0 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/utils/records-0.lisp @@ -0,0 +1,425 @@ +;; Author: +;; Shilpi Goel + +;; Note: The license below is based on the template at: +;; http://opensource.org/licenses/BSD-3-Clause + +;; Copyright (C) 2013, 2015 Regents of the University of Texas +;; All rights reserved. + +;; Redistribution and use in source and binary forms, with or without +;; modification, are permitted provided that the following conditions are +;; met: + +;; o Redistributions of source code must retain the above copyright +;; notice, this list of conditions and the following disclaimer. + +;; o Redistributions in binary form must reproduce the above copyright +;; notice, this list of conditions and the following disclaimer in the +;; documentation and/or other materials provided with the distribution. + +;; o Neither the name of the University of Texas, Austin nor the names of +;; its contributors may be used to endorse or promote products derived +;; from this software without specific prior written permission. + +;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +;; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +;; ---------------------------------------------------------------------- + +;; This book is a slightly modified version of the records book by Rob +;; Sumners and Matt Kaufmann (books/misc/records.lisp). + +;; Differences between this book and books/misc/records.lisp: +;; - This book uses 0 instead of NIL for absent fields and for the empty record. +;; - This book uses (ILL-FORMED-KEY) instead of NIL as the "bad key". + +(in-package "X86ISA") + +(include-book "misc/total-order" :dir :system) + +;; ---------------------------------------------------------------------- + +; The "bad key". +(defun ill-formed-key () + (declare (xargs :guard t)) + "unlikely-we-should-ever-encounter-this-particular-string-as-a-key!?!?!?!") + +; Recognize NIL-terminated alists with ordered keys and no 0 values. +(defun well-formed-alistp-aux (x) + (declare (xargs :guard t)) + (or (null x) + (and (consp x) + (consp (car x)) + (not (eql (cdar x) 0)) + (or (atom (cdr x)) + (and (consp (cadr x)) + (ACL2::<< (caar x) (caadr x)))) + (well-formed-alistp-aux (cdr x))))) + +; Recognize 0 and non-empty WELL-FORMED-ALISTP-AUX values (see above). +; Here 0 is the empty record. +(defun well-formed-alistp (x) + (declare (xargs :guard t)) + (and (not (equal x nil)) + (or (eql x 0) + (well-formed-alistp-aux x)))) + +; Recognize NIL-terminated alists with ordered keys +; without the bad key and without 0 values. +(defun good-alistp-aux (x) + (declare (xargs :guard t)) + (or (null x) + (and (consp x) + (consp (car x)) + (not (equal (caar x) (ill-formed-key))) + (not (eql (cdar x) 0)) + (or (atom (cdr x)) + (and (consp (cadr x)) + (ACL2::<< (caar x) (caadr x)))) + (good-alistp-aux (cdr x))))) + +; Recognize 0 and non-empty GOOD-ALISTP-AUX values (see above). +; Here 0 is the empty record. +(defun good-alistp (x) + (declare (xargs :guard t)) + (and (not (equal x nil)) + (or (eql x 0) + (good-alistp-aux x)))) + +(defthmd good-alistp-aux-implies-well-formed-alistp-aux + (implies (good-alistp-aux alst) + (well-formed-alistp-aux alst))) + +(defthmd good-alistp-implies-well-formed-alistp + (implies (good-alistp alst) + (well-formed-alistp alst))) + +(local (in-theory (e/d (good-alistp-aux-implies-well-formed-alistp-aux + good-alistp-implies-well-formed-alistp) + ()))) + +; Recognize values outside WELL-FORMED-ALISTP, +; and WELL-FORMED-ALISTP values with just a pair consisting of +; the bad key and recursively an ILL-FORMED-ALISTP value. +(defun ill-formed-alistp (x) + (declare (xargs :guard t)) + (or (not (well-formed-alistp x)) + (and (consp x) + (consp (car x)) + (equal (caar x) (ill-formed-key)) + (null (cdr x)) + (ill-formed-alistp (cdar x))))) + +(local + (defthm good-alistp-aux-implies-not-ill-formed-alistp + (implies (and (good-alistp-aux x) + x) + (not (ill-formed-alistp x))))) + +(local + (defthm good-alistp-implies-not-ill-formed-alistp + (implies (good-alistp x) + (not (ill-formed-alistp x))))) + +; Read key I from record R. +; Return 0 if key not present. +(defun gi (i r) + (declare (xargs :guard t + :measure (acl2-count r))) + (if (or (eql r 0) + (atom r) + (atom (car r))) + 0 + (if (ACL2::<< i (caar r)) + 0 + (if (equal (caar r) i) + (cdar r) + (if (cdr r) + (gi i (cdr r)) + 0))))) + +; Auxiliary function to write value V for key I in record R. +; Used by SI (below) when V is not 0. +(defun si-aux (i v r) + (declare (xargs :guard t)) + (if (or (atom r) (atom (car r))) + (cons (cons i v) nil) + (if (equal (caar r) i) + (cons (cons i v) (cdr r)) + (if (ACL2::<< i (caar r)) + (cons (cons i v) r) + (cons (car r) (si-aux i v (cdr r))))))) + +; Remove key I from record R. +; Used by SI (below) when V is 0. +(defun si-kill (i r) + (declare (xargs :guard t)) + (if (or (atom r) (atom (car r))) + nil + (if (equal (caar r) i) + (cdr r) + (cons (car r) (si-kill i (cdr r)))))) + +; Write value V for key I in record R. +; Treat 0 as the empty record. +(defun si (i v r) + (declare (xargs :guard t)) + (if (eql r 0) + (if (eql v 0) + r + (cons (cons i v) nil)) + (if (eql v 0) + (or (si-kill i r) 0) + (si-aux i v r)))) + +(local + (defthm si-kill-preserves-well-formed-alistp-aux + (implies (well-formed-alistp-aux alst) + (well-formed-alistp-aux (si-kill i alst))))) + +(local + (defthm si-aux-preserves-well-formed-alistp-aux + (implies (and (well-formed-alistp-aux alst) + (not (equal v 0)) + (not (equal i (ill-formed-key)))) + (well-formed-alistp-aux (si-aux i v alst))))) + +(defthm si-preserves-well-formed-alistp + (implies (well-formed-alistp alst) + (well-formed-alistp (si i v alst)))) + + +(local + (defthm gi-same-si-aux + (implies (well-formed-alistp-aux alst) + (equal (gi i (si i v alst)) + v)))) + +(local + (defthm gi-same-si-aux-aux + (implies (well-formed-alistp-aux alst) + (equal (gi i (si-aux i v alst)) + v)))) + +(defthm gi-same-si + (implies (well-formed-alistp alst) + (equal (gi i (si i v alst)) + v))) + +(defthm gi-diff-si + (implies (and (well-formed-alistp r) + (not (equal i j))) + (equal (gi i (si j v r)) + (gi i r)))) + +(defthm si-same-gi + (implies (well-formed-alistp r) + (equal (si a (gi a r) r) + r))) + +(local + (defthm si-aux-same-si-aux + (implies (and (well-formed-alistp-aux r) + (not (equal x 0)) + (not (equal y 0))) + (equal (si-aux a y (si-aux a x r)) + (si-aux a y r))))) + +(local + (defthm si-same-si-helper-1 + (implies (and (well-formed-alistp r) + (not (equal r 0))) + (equal (si-kill a (si-kill a r)) + (si-kill a r))))) + +(local + (defthm si-same-si-helper-2 + (implies (and (well-formed-alistp r) + (not (equal r 0))) + (equal (si-kill a (si-aux a x r)) + (si-kill a r))))) + +(local + (defthm si-same-si-helper-3 + (implies (and (well-formed-alistp r) + (not (equal r 0))) + (equal (si-aux a y (si-kill a r)) + (si-aux a y r))))) + +(defthm si-same-si + (implies (well-formed-alistp r) + (equal (si a y (si a x r)) + (si a y r))) + :otf-flg t) + +(defthm si-diff-si + (implies (and (not (equal i j)) + (well-formed-alistp r)) + (equal (si j y (si i x r)) + (si i x (si j y r)))) + :rule-classes ((:rewrite :loop-stopper ((j i si)))) + :otf-flg t) + +;; ---------------------------------------------------------------------- + +;; Conversion functions: + +; Map ACL2 objects to well-formed records. +(defun acl2->map (x) + (declare (xargs :guard t)) + (if (ill-formed-alistp x) + (list (cons (ill-formed-key) x)) + x)) + +; Inverse of ACL2->MAP. +(defun map->acl2 (x) + (declare (xargs :guard t)) + (if (well-formed-alistp x) + (if (ill-formed-alistp x) + (cdar x) + x) + x)) + +(local + (defthm acl2->map-map->acl2-of-well-formed-alistp + (implies (well-formed-alistp x) + (equal (acl2->map (map->acl2 x)) + x)))) + +(local + (defthm acl2->map-returns-well-formed-alistp + (well-formed-alistp (acl2->map x)))) + +(local + (defthm acl2->map-preserves-equality + (iff (equal (acl2->map x) (acl2->map y)) + (equal x y)))) + +(local + (defthm map->acl2-acl2->map-inverse + (equal (map->acl2 (acl2->map x)) x))) + +(local + (defthm map->acl2-of-record-non-zero + (implies (and (not (equal r 0)) + (well-formed-alistp r)) + (not (equal (map->acl2 r) 0))))) + +;; ---------------------------------------------------------------------- + +;; Definition of gz and sz: + +; The generic record g(et) which works on any ACL2 object. +(defun gz (i x) + (declare (xargs :guard t)) + (gi i (acl2->map x))) + +; The generic record s(et) which works on any ACL2 object. +(defun sz (i v x) + (declare (xargs :guard t)) + (map->acl2 (si i v (acl2->map x)))) + +(local + (defthmd good-alistp-aux-alst-sz-preserves-good-alistp + (implies (and (good-alistp-aux alst) + alst + (not (equal i (ill-formed-key)))) + (good-alistp (sz i v alst))))) + +(local + (defthmd sz-preserves-good-alistp-0 + (implies (not (equal i (ill-formed-key))) + (good-alistp (sz i v 0))))) + +(defthm sz-preserves-good-alistp + (implies (and (good-alistp alst) + (not (equal i (ill-formed-key)))) + (good-alistp (sz i v alst))) + :hints (("Goal" :use ((:instance + good-alistp-aux-alst-sz-preserves-good-alistp) + (:instance + sz-preserves-good-alistp-0))))) + +(in-theory (disable si gi acl2->map map->acl2)) + +;; ---------------------------------------------------------------------- + +;; Final exported properties of g and s: + +(defthm gz-same-sz + (equal (gz i (sz i v r)) v)) + +(defthm gz-diff-sz + (implies (not (equal a b)) + (equal (gz a (sz b v r)) + (gz a r)))) + +;;;; NOTE: The following can be used instead of the above rules to force ACL2 +;;;; to do a case-split. We disable this rule by default since it can lead to +;;;; an expensive case explosion, but in many cases, this rule may be more +;;;; effective than two rules above and should be enabled. + +(defthm gz-of-sz-redux + (equal (gz a (sz b v r)) + (if (equal a b) + v + (gz a r)))) + +(in-theory (disable gz-of-sz-redux)) + +(defthm sz-same-gz + (equal (sz a (gz a r) r) + r)) + +(defthm sz-same-sz + (equal (sz a y (sz a x r)) + (sz a y r))) + +(defthm sz-diff-sz + (implies (not (equal a b)) + (equal (sz b y (sz a x r)) + (sz a x (sz b y r)))) + :rule-classes ((:rewrite :loop-stopper ((b a sz))))) + +;; The following theorems are less relevant but have been useful in +;; dealing with a default record of 0. + +(defthm gz-of-0-is-0 + (equal (gz a 0) 0) + :hints (("Goal" :in-theory (e/d (gi) ())))) + +(defthm non-0-if-gz-non-0 + (implies (not (equal (gz a r) 0)) (not (equal r 0))) + :hints (("Goal" :in-theory (e/d (gi) ()))) + :rule-classes :forward-chaining) + +(defthm sz-non-0-cannot-be-0 + (implies (not (equal v 0)) + (not (equal (sz a v r) 0))) + :hints (("Goal" :in-theory (e/d (map->acl2 si acl2->map) ())))) + +;; Some functions to disable: + +(in-theory (disable well-formed-alistp-aux + well-formed-alistp + good-alistp-aux + good-alistp + si-aux + si-kill)) + +;; We disable sz and gz, assuming the rules proven in this book are sufficient to +;; manipulate record terms which are encountered. + +(in-theory (disable sz gz)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/utils/segmentation-structures.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/utils/segmentation-structures.lisp new file mode 100644 index 000000000..4188b4459 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/utils/segmentation-structures.lisp @@ -0,0 +1,400 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Contributing Author: +; Alessandro Coglio + +(in-package "X86ISA") + +(include-book "basic-structs") + +(include-book "xdoc/constructors" :dir :system) + +;; We do these once, here, to avoid each defbitstruct below doing them locally: +(local (include-book "centaur/bitops/ihsext-basics" :dir :system)) +(local (include-book "centaur/bitops/equal-by-logbitp" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) + +;; ---------------------------------------------------------------------- + +(defsection segmentation-bitstructs + :parents (structures) + :short "Bitstructs related to segmentation, protection, etc.") + +(local (xdoc::set-default-parents segmentation-bitstructs)) + +;; ---------------------------------------------------------------------- + +(defbitstruct hidden-segment-registerBits + :short "Hidden part of segment registers." + :long + (xdoc::topstring + (xdoc::p + "As shown in Intel manual, Mar 2026, Vol. 3A, Figure 3-7, + segment registers have a hidden part, + consisting of three fields. + These fields are \"cached\" from the segment descriptor (Figure 3-8):") + (xdoc::ul + (xdoc::li + "The base address is 32 bits in the segment descriptor, + so the 64 bits in @('base-addr') in this bitstruct can hold it.") + (xdoc::li + "The segment limit is 20 bits in the segment descriptor, + and based on the G (granularity) flag it covers up to 4 GiB, + so the 32 bits in @('limit') in this bitstruct can hold it. + IMPORTANT: this means that the cached limit field must be + populated only after G flag is taken into account.") + (xdoc::li + "There are 12 remaining bits in the segment descriptor, + so the 16 bits in @('attr') in this bitstruct can hold them."))) + ((base-addr 64bits) ;; Base Address + (limit 32bits) ;; Segment Limit + (attr 16bits)) ;; Attributes + :inline t + :msb-first nil) + +(local + (defthm hidden-segment-register-layout-ok + (iff (hidden-segment-registerBits-p x) + (unsigned-byte-p 112 x)) + :rule-classes nil)) + +(defbitstruct segment-selectorBits + :short "Segment selectors." + :long + (xdoc::topstring + (xdoc::p + "These are the visible part of segment registers: + see Intel manual, Mar 2026, Vol. 3A, Figure 3-7. + The layout of a segment selector is in Figure 3-6.")) + ((rpl 2bits) ;; Requested Privilege Level (RPL) + (ti bitp) ;; Table Indicator (0 = GDT, 1 = LDT) + (index 13bits)) ;; Index of descriptor in GDT or LDT + :inline t + :msb-first nil) + +(local + (defthm segment-selector-layout-ok + (iff (segment-selectorBits-p x) + (unsigned-byte-p 16 x)) + :rule-classes nil)) + +(defbitstruct gdtr/idtrBits + :short "Global and Interrupt Descriptor Table Registers (GDTR and IDTR)." + :long + (xdoc::topstring + (xdoc::p + "Intel manual, Mar 2026, Vol. 3A, Figure 2-6; + AMD manual, Mar 2026, Vol. 2, Figures 4-7 and 4-8.") + (xdoc::p + "We use 64 bits to accommodate the longer size.")) + ((base-addr 64bits) ;; Segment Base Address + (limit 16bits)) ;; Segment Limit + :msb-first nil + :inline t) + +(local + (defthm gdtr/idtr-layout-ok + (iff (gdtr/idtrBits-p x) + (unsigned-byte-p 80 x)) + :rule-classes nil)) + +(defbitstruct code-segment-descriptorBits + :short "Code segment descriptors." + :long + (xdoc::topstring + (xdoc::p + "Intel manual, Mar 2026, Vol. 3A, Figure 3-8; + AMD manual, Mar 2026, Vol. 2, Figures 4-14 and 4-20.")) + ((limit15-0 16bits) ;; Ignored in 64-bit mode + (base15-0 16bits) ;; Ignored in 64-bit mode + (base23-16 8bits) ;; Ignored in 64-bit mode + (a bitp) ;; Accessed; ignored in 64-bit mode + (r bitp) ;; Readable; ignored in 64-bit mode + (c bitp) ;; Conforming + (msb-of-type bitp) ;; Must be 1 + (s bitp) ;; System descriptor (0 = system; 1 = code or data); + ;; must be 1 in 64-bit mode + (dpl 2bits) ;; Descriptor privilege level + (p bitp) ;; Segment present + (limit19-16 4bits) ;; Ignored in 64-bit mode + (avl bitp) ;; Available for use by system software; + ;; ignored in 64-bit mode + (l bitp) ;; 64-bit segment + (d bitp) ;; Default operation size + (g bitp) ;; Granularity; ignored in 64-bit mode + (base31-24 8bits)) ;; Ignored in 64-bit mode + :msb-first nil + :inline t) + +(local + (defthm code-segment-descriptor-layout-ok + (iff (code-segment-descriptorBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct code-segment-descriptor-attributesBits + :short "Subset of @(tsee code-segment-descriptorBits)." + ((a bitp) + (r bitp) + (c bitp) + (msb-of-type bitp) + (s bitp) + (dpl 2bits) + (p bitp) + (avl bitp) + (l bitp) + (d bitp) + (g bitp) + (unknownBits 4bits)) + :msb-first nil + :inline t) + +(local + (defthm code-segment-descriptor-attributes-layout-ok + (iff (code-segment-descriptor-attributesBits-p x) + (unsigned-byte-p 16 x)) + :rule-classes nil)) + +(defbitstruct data-segment-descriptorBits + :short "Data segment descriptors." + :long + (xdoc::topstring + (xdoc::p + "Intel manual, Mar 2026, Vol. 3A, Figure 3-8; + AMD manual, Mar 2026, Vol. 2, Figures 4-15 and 4-21.")) + ((limit15-0 16bits) ;; Ignored in 64-bit mode + (base15-0 16bits) ;; Ignored in 64-bit mode + (base23-16 8bits) ;; Ignored in 64-bit mode + (a bitp) ;; Accessed; ignored in 64-bit mode + (w bitp) ;; Read/write; ignored in 64-bit mode + (e bitp) ;; Execute; ignored in 64-bit mode + (msb-of-type bitp) ;; Must be 0 + (s bitp) ;; System descriptor (0 = system; 1 = code or data); + ;; must be 1 in 64-bit mode + (dpl 2bits) ;; Descriptor privilege level; ignored in 64-bit mode + (p bitp) ;; Segment present + (limit19-16 4bits) ;; Ignored in 64-bit mode + (avl bitp) ;; Available for use by system software; + ;; ignored in 64-bit mode + (l bitp) ;; 64-bit segment + (d/b bitp) ;; Default operation size + (g bitp) ;; Granularity; ignored in 64-bit mode + (base31-24 8bits)) ;; Ignored in 64-bit mode + :msb-first nil + :inline t) + +(local + (defthm data-segment-descriptor-layout-ok + (iff (data-segment-descriptorBits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct data-segment-descriptor-attributesBits + :short "Subset of @(tsee data-segment-descriptorBits)." + ((a bitp) + (w bitp) + (e bitp) + (msb-of-type bitp) + (s bitp) + (dpl 2bits) + (p bitp) + (avl bitp) + (l bitp) + (d/b bitp) + (g bitp) + (unknownBits 4bits)) + :msb-first nil + :inline t) + +(local + (defthm data-segment-descriptor-attributes-layout-ok + (iff (data-segment-descriptor-attributesBits-p x) + (unsigned-byte-p 16 x)) + :rule-classes nil)) + +(defbitstruct system-segment-descriptorBits + :short "System segment descriptors, in 64-bit mode." + :long + (xdoc::topstring + (xdoc::p + "Intel manual, Mar 2026, Vol. 3A, Figure 3-11; + AMD manual, Mar 2026, Vol. 2, Figure 4-22.") + (xdoc::p + "This is for 64-bit mode; + in 32-bit mode, the layout is different.")) + ((limit15-0 16bits) + (base15-0 16bits) + (base23-16 8bits) + (type 4bits) + (s bitp) ;; System descriptor (0 = system; 1 = code or data) + (dpl 2bits) ;; Descriptor privilege level + (p bitp) ;; Segment present + (limit19-16 4bits) + (avl bitp) ;; Available for use by system software + (res1 2bits) ;; L and D/B bits are ignored + (g bitp) ;; Granularity + (base31-24 8bits) + (base63-32 32bits) + (res2 8bits) + (all-zeroes? 5bits) ;; Must all be 0 + (res3 19bits)) + :msb-first nil + :inline t) + +(local + (defthm system-segment-descriptor-layout-ok + (iff (system-segment-descriptorBits-p x) + (unsigned-byte-p 128 x)) + :rule-classes nil)) + +(defbitstruct system-segment-descriptor-attributesBits + :short "Subset of @(tsee system-segment-descriptorBits)." + ((type 4bits) + (s bitp) + (dpl 2bits) + (p bitp) + (avl bitp) + (g bitp) + (unknownBits 6bits)) + :msb-first nil + :inline t) + +(local + (defthm system-segment-descriptor-attributes-layout-ok + (iff (system-segment-descriptor-attributesBits-p x) + (unsigned-byte-p 16 x)) + :rule-classes nil)) + +(defbitstruct call-gate-descriptorBits + :short "Call-gate descriptors, in 64-bit mode." + :long + (xdoc::topstring + (xdoc::p + "Intel manual, Mar 2026, Vol. 3A, Figure 3-11; + AMD manual, Mar 2026, Vol. 2, Figure 4-23.") + (xdoc::p + "This is for 64-bit mode; + in 32-bit mode, the layout is different.")) + ((offset15-0 16bits) + (selector 16bits) + (res1 8bits) + (type 4bits) + (s bitp) ;; System descriptor (0 = system; 1 = code or data) + (dpl 2bits) ;; Descriptor privilege level + (p bitp) ;; Segment present + (offset31-16 16bits) + (offset63-32 32bits) + (res2 8bits) + (all-zeroes? 5bits) ;; Must all be 0 + (res3 19bits)) + :msb-first nil + :inline t) + +(local + (defthm call-gate-descriptor-layout-ok + (iff (call-gate-descriptorBits-p x) + (unsigned-byte-p 128 x)) + :rule-classes nil)) + +(defbitstruct call-gate-descriptor-attributesBits + :short "Subset of @(tsee call-gate-descriptorBits)." + ((type 4bits) + (s bitp) + (dpl 2bits) + (p bitp) + (unknownBits 8bits)) + :msb-first nil + :inline t) + +(local + (defthm call-gate-descriptor-attributes-layout-ok + (iff (call-gate-descriptor-attributesBits-p x) + (unsigned-byte-p 16 x)) + :rule-classes nil)) + +(defbitstruct interrupt/trap-gate-descriptorBits + :short "Interrupt-gate and trap-gate descriptors, in 64-bit mode." + :long + (xdoc::topstring + (xdoc::p + "Intel manual, Mar 2026, Vol. 3A, Figure 3-11; + AMD manual, Mar 2026, Vol. 2, Figure 4-24.") + (xdoc::p + "This is for 64-bit mode; + in 32-bit mode, the layout is different.")) + ((offset15-0 16bits) + (selector 16bits) + (ist 3bits) ;; Interrupt stack table + (res1 5bits) + (type 4bits) + (s bitp) ;; System descriptor (0 = system; 1 = code or data) + (dpl 2bits) ;; Descriptor privilege level + (p bitp) ;; Segment present + (offset31-16 16bits) + (offset63-32 32bits) + (res2 8bits) + (all-zeroes? 5bits) ;; Must all be 0 + (res3 19bits)) + :msb-first nil + :inline t) + +(local + (defthm interrupt/trap-gate-descriptor-layout-ok + (iff (interrupt/trap-gate-descriptorBits-p x) + (unsigned-byte-p 128 x)) + :rule-classes nil)) + +(defbitstruct interrupt/trap-gate-descriptor-attributesBits + :short "Subset of @(tsee interrupt/trap-gate-descriptorBits)." + ((ist 3bits) + (type 4bits) + (s bitp) + (dpl 2bits) + (p bitp) + (unknownBits 5bits)) + :msb-first nil + :inline t) + +(local + (defthm interrupt/trap-gate-descriptor-attributes-layout-ok + (iff (interrupt/trap-gate-descriptor-attributesBits-p x) + (unsigned-byte-p 16 x)) + :rule-classes nil)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/utils/structures.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/utils/structures.lisp new file mode 100644 index 000000000..16742f9e6 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/utils/structures.lisp @@ -0,0 +1,823 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Warren A. Hunt, Jr. +; Matt Kaufmann +; Robert Krug +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +(include-book "basic-structs") + +(local (include-book "centaur/bitops/ihsext-basics" :dir :system)) + +;; We do these once, here, to avoid each defbitstruct below doing them locally: +(local (include-book "centaur/bitops/equal-by-logbitp" :dir :system)) +(local (include-book "arithmetic/top-with-meta" :dir :system)) + +(std::make-define-config + :no-function t + :inline t) + +;; ---------------------------------------------------------------------- + +(defsection structures + :parents (utils) + :short "x86-specific bit structures." + + :long "

We define some bit structures using @(see fty::defbitstruct) to + describe the fields of registers and x86 data structures.

" ) + +(local (xdoc::set-default-parents structures)) + +;; ---------------------------------------------------------------------- + +;; We add "Bits" as a suffix for all bitstructs other than the decoding-related +;; ones and the basic ones in basic-structs.lisp. The reason is that +;; otherwise, the names of these other bitstructs may clash with x86 state +;; accessor functions (e.g., rflags, mxcsr, etc.). + +;; Decoding-related Structures: + +(defsection legacy-prefixes-layout-structure + + :short "Structure to collect legacy prefix bytes from an x86 instruction." + + :long + "

These prefixes are described in + Intel manual, Mar 2026, Vol. 2, Sections 2.1 and 2.2.

+

The field @('num') of @('prefixes') not only includes the number of + legacy prefixes present in an instruction, but also the number of REX bytes, + even though REX bytes are not stored in this structure. See @(tsee + get-prefixes) for details.

" + + (defbitstruct prefixes + ((num 4bits "Number of Prefix Bytes") + (lck 8bits "Lock Prefix") + (rep 8bits "Repeat Prefix") + (seg 8bits "Segment Override Prefix") + (opr 8bits "Operand-Size Override Prefix") + (adr 8bits "Address-Size Override Prefix") + (nxt 8bits "First non-prefix instruction byte")) + :inline t) + + (local + (defthm prefixes-layout-ok + (iff (prefixes-p x) + (unsigned-byte-p *prefixes-width* x)) + :rule-classes nil))) + +(defsection vex-prefixes-layout-structures + + :short "Functions to decode and structures to collect + VEX prefix bytes in an x86 instruction." + :long + "

The VEX prefix is described in + Intel manual, Mar 2026, Vol. 2, Section 2.3.

" + + (defbitstruct vex-prefixes + :short "VEX prefixes." + :long "

Intel manual, Mar 2026, Vol. 2, Figure 2-9.

" + ((byte0 8bits "Can either be #xC4 or #xC5") + (byte1 8bits "Byte 1") + (byte2 8bits "Byte 2, relevant only for 3-byte VEX prefixes")) + :inline t) + + (local + (defthm vex-prefixes-layout-ok + (iff (vex-prefixes-p x) + (unsigned-byte-p *vex-width* x)) + :rule-classes nil)) + + (define vex-prefixes-byte0-p ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :returns (ok booleanp) + :short "Returns @('t') if byte0 of the @('vex-prefixes') structure is + either @('*vex2-byte0*') (i.e. C5H) or @('*vex3-byte0*') (i.e. C4H); + returns @('nil') otherwise." + (let ((byte0 (vex-prefixes->byte0 vex-prefixes))) + (or (equal byte0 #.*vex2-byte0*) (equal byte0 #.*vex3-byte0*)))) + + ;; From Intel manual, Mar 2026, Vol. 2, Section 2.3.5.6: + ;; "In 32-bit mode the VEX first + ;; byte C4 and C5 alias onto the LES and LDS instructions. To + ;; maintain compatibility with existing programs the VEX 2nd byte, + ;; bits [7:6] must be 11b." + + ;; So, in 32-bit mode, vex2-byte1 must have R and MSB of + ;; vvvv set to 1, and vex3-byte1 must have R and X set to 1 + ;; if VEX is to be used instead of LES/LDS. + + ;; From Intel manual, Mar 2026, Vol. 2, Section 2.3.5.6: + ;; "If an instruction does not use VEX.vvvv then it should be set to + ;; 1111b otherwise instruction will #UD. In 64-bit mode all 4 bits + ;; may be used. See Table 2-8 for the encoding of the XMM or YMM + ;; registers. In 32-bit and 16-bit modes bit 6 must be 1 (if bit 6 + ;; is not 1, the 2-byte VEX version will generate LDS instruction + ;; and the 3-byte VEX version will ignore this bit)." + + ;; The above is the reason why only 8 XMM/YMM registers are available in + ;; 32-bit and 16-bit modes. + + ;; Source for VEX layout constants: + ;; Intel Vol. 2 (Mar 2026), Figure 2-9 (VEX bit fields) + + ;; Note that the 2-byte VEX implies a leading 0F opcode byte, and + ;; the 3-byte VEX implies leading 0F, 0F 38, or 0F 3A bytes. + + (defbitstruct vex2-byte1 + :short "Byte 1 of 2-byte VEX prefix." + :long "

Intel manual, Mar 2026, Vol. 2, Figure 2-9.

" + ((pp 2bits + "Opcode extension providing equivalent functionality of a SIMD + prefix:
+ @('#b00: None')
+ @('#b01: #x66')
+ @('#b10: #xF3')
+ @('#b11: #xF2')") + (l bitp + "Vector Length:
+ @('0: scalar or 128-bit vector')
+ @('1: 256-bit vector')") + (vvvv 4bits + "A register specifier (in 1's complement form) + or @('1111') if unused.") + (r bitp + "@('REX.R') in 1's complement (inverted) form:
+ @('1: Same as REX.R=0 (must be 1 in 32-bit mode);')
+ @('0: Same as REX.R=1 (64-bit mode only)').
+ In protected and compatibility modes, the bit must be set to @('1'), + otherwise the instruction is LES or LDS.")) + :msb-first nil + :inline t) + + (defbitstruct vex3-byte1 + :short "Byte 1 of 3-byte VEX prefix." + :long "

Intel manual, Mar 2026, Vol. 2, Figure 2-9.

" + ((m-mmmm 5bits + "@('00000'): Reserved for future use (will #UD)
+ @('00001'): implied 0F leading opcode byte
+ @('00010'): implied 0F 38 leading opcode bytes
+ @('00011'): implied 0F 3A leading opcode bytes
+ @('00100-11111'): Reserved for future use (will #UD)") + (b bitp + "REX.B in 1's complement (inverted) form
+ @('1 - Same as REX.B=0') (Ignored in 32-bit mode)
+ @('0 - Same as REX.B=1') (64-bit mode only)") + (x bitp + "REX.X in 1's complement (inverted) form
+ @('1 - Same as REX.X=0') (must be 1 in 32-bit mode)
+ @('0 - Same as REX.X=1') (64-bit mode only)
+ In 32-bit modes, this bit must be set to @('1'), + otherwise the instruction is LES or LDS.") + (r bitp + "REX.R in 1's complement (inverted) form
+ @('1 - Same as REX.R=0') (must be 1 in 32-bit mode)
+ @('0 - Same as REX.R=1') (64-bit mode only)
+ In protected and compatibility modes the bit must be set to @('1'), + otherwise the instruction is LES or LDS.")) + :xvar vex3byte1 + :msb-first nil + :inline t) + + (defbitstruct vex3-byte2 + :short "Byte 2 of 3-byte VEX prefix." + :long "

Intel manual, Mar 2026, Vol. 2, Figure 2-9.

" + ((pp 2bits + "Opcode extension providing equivalent functionality of + a SIMD prefix:
+ @('#b00: None')
+ @('#b01: #x66')
+ @('#b10: #xF3')
+ @('#b11: #xF2')") + (l bitp + "Vector Length:
+ @('0: scalar or 128-bit vector')
+ @('1: 256-bit vector')") + (vvvv 4bits + "A register specifier (in 1's complement form) + or @('1111') if unused.") + (w bitp + "Opcode specific (use like REX.W, or used for opcode extension, + or ignored, depending on the opcode byte)." )) + :msb-first nil + :inline t) + + (define vex-prefixes-map-p ((bytes :type (unsigned-byte 16)) + (vex-prefixes :type (unsigned-byte #.*vex-width*))) + :guard (and (vex-prefixes-byte0-p vex-prefixes) + (or (equal bytes #ux0F) + (equal bytes #ux0F38) + (equal bytes #ux0F3A))) + :returns (ok booleanp) + :short "Returns @('t') if the @('vex-prefixes'), + irrespective of whether they are two- or three-byte form, + indicate the map that begins with the escape bytes @('bytes')." + :long + "

Intel manual, Mar 2026, Vol. 2, Section 2.3.6.1 + says that 2-byte VEX implies 0F opcode byte

" + (b* ((byte0 (vex-prefixes->byte0 vex-prefixes)) + (byte1 (vex-prefixes->byte1 vex-prefixes))) + (case bytes + (#ux0F + (or (equal byte0 #.*vex2-byte0*) + (and (equal byte0 #.*vex3-byte0*) + (equal (vex3-byte1->m-mmmm byte1) #.*v0F*)))) + (otherwise ; 0F38 and 0F3A + (and (equal byte0 #.*vex3-byte0*) + (if (equal bytes #ux0F38) + (equal (vex3-byte1->m-mmmm byte1) #.*v0F38*) + (equal (vex3-byte1->m-mmmm byte1) #.*v0F3A*))))))) + + ;; Some convenient accessor functions for those fields of the VEX prefixes + ;; that are common to both the two- and three-byte forms: + + (define vex->vvvv ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :guard (vex-prefixes-byte0-p vex-prefixes) + :returns (vvvv (unsigned-byte-p 4 vvvv) + :hyp (vex-prefixes-byte0-p vex-prefixes) + :hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + :short "Get the @('vvvv') field of @('vex-prefixes'); + cognizant of the two- or three-byte VEX prefixes form." + ;; We avoid inlining these to avoid slow compilation in the + ;; vex-opcodes-dispatch book: + :inline nil + (case (vex-prefixes->byte0 vex-prefixes) + (#.*vex2-byte0* + (vex2-byte1->vvvv (vex-prefixes->byte1 vex-prefixes))) + (#.*vex3-byte0* + (vex3-byte2->vvvv (vex-prefixes->byte2 vex-prefixes))) + (otherwise (prog2$ (acl2::impossible) 0))) + :guard-hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + + (define vex->l ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :guard (vex-prefixes-byte0-p vex-prefixes) + :returns (l (unsigned-byte-p 1 l) + :hyp (vex-prefixes-byte0-p vex-prefixes) + :hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + :short "Get the @('L') field of @('vex-prefixes'); + cognizant of the two- or three-byte VEX prefixes form." + :inline nil + (case (vex-prefixes->byte0 vex-prefixes) + (#.*vex2-byte0* + (vex2-byte1->l (vex-prefixes->byte1 vex-prefixes))) + (#.*vex3-byte0* + (vex3-byte2->l (vex-prefixes->byte2 vex-prefixes))) + (otherwise (prog2$ (acl2::impossible) 0))) + :guard-hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + + (define vex->pp ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :guard (vex-prefixes-byte0-p vex-prefixes) + :returns (pp (unsigned-byte-p 2 pp) + :hyp (vex-prefixes-byte0-p vex-prefixes) + :hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + :short "Get the @('pp') field of @('vex-prefixes'); + cognizant of the two- or three-byte VEX prefixes form." + :inline nil + (case (vex-prefixes->byte0 vex-prefixes) + (#.*vex2-byte0* + (vex2-byte1->pp (vex-prefixes->byte1 vex-prefixes))) + (#.*vex3-byte0* + (vex3-byte2->pp (vex-prefixes->byte2 vex-prefixes))) + (otherwise (prog2$ (acl2::impossible) 0))) + :guard-hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + + (define vex->r ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :guard (vex-prefixes-byte0-p vex-prefixes) + :returns (r (unsigned-byte-p 1 r) + :hyp (vex-prefixes-byte0-p vex-prefixes) + :hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + :short "Get the @('R') field of @('vex-prefixes'); + cognizant of the two- or three-byte VEX prefixes form." + :inline nil + (case (vex-prefixes->byte0 vex-prefixes) + (#.*vex2-byte0* + (vex2-byte1->r (vex-prefixes->byte1 vex-prefixes))) + (#.*vex3-byte0* + (vex3-byte1->r (vex-prefixes->byte1 vex-prefixes))) + (otherwise (prog2$ (acl2::impossible) 0))) + :guard-hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + + (define vex->w ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :guard (vex-prefixes-byte0-p vex-prefixes) + :returns (w (unsigned-byte-p 1 w) + :hyp (vex-prefixes-byte0-p vex-prefixes) + :hints (("Goal" :in-theory (enable vex-prefixes-byte0-p)))) + :short "Get the @('W') field of @('vex-prefixes'); + cognizant of the two- or three-byte VEX prefixes form." + :inline nil + (case (vex-prefixes->byte0 vex-prefixes) + (#.*vex3-byte0* + (vex3-byte2->w (vex-prefixes->byte2 vex-prefixes))) + ;; Source: Intel Vol. 2A, Section 3.1.1.2 --- Opcode Column in the + ;; Instruction Summary Table (Instructions with VEX Prefix): + ;; "The presence of W0 in the opcode column does not preclude the opcode + ;; to be encoded using the C5H form of the VEX prefix, if the semantics + ;; of the opcode does not require other VEX subfields not present in the + ;; two-byte form of the VEX prefix." + (otherwise 0)) + + /// + + (defret if-not-vex3-byte0-then-vex-w=0 + (implies (not (equal (vex-prefixes->byte0 vex-prefixes) #.*vex3-byte0*)) + (equal (vex->w vex-prefixes) 0)))) + + ;; Some convenient accessor functions for those fields of the VEX prefixes + ;; that only apply to the three-byte forms, but that can be extended to + ;; the two-byte forms: + + (define vex->x ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :returns (x (unsigned-byte-p 1 x)) + :short "Get the @('X') field of @('vex-prefixes') for the three-byte form, + or return 1 for the two-byte form." + :long "

Although the two-byte form has no @('X') bit, + as far as the VEX encoding of the REX byte is concerned, + the two-byte form can be regarded as encoding the value 0 + for the @('X') bit of the REX byte. + Since the REX.X encoding in VEX is negated, + this function returns 1 for the two-byte form.

+

See Intel manual Volume 2 Figure 2-9 of Mar 2026.

" + (case (vex-prefixes->byte0 vex-prefixes) + (#.*vex3-byte0* (vex3-byte1->x (vex-prefixes->byte1 vex-prefixes))) + (otherwise 1))) + + (define vex->b ((vex-prefixes :type (unsigned-byte #.*vex-width*))) + :returns (b (unsigned-byte-p 1 b)) + :short "Get the @('B') field of @('vex-prefixes') for the three-byte form, + or return 1 for the two-byte form." + :long "

Although the two-byte form has no @('B') bit, + as far as the VEX encoding of the REX byte is concerned, + the two-byte form can be regarded as encoding the value 0 + for the @('B') bit of the REX byte. + Since the REX.B encoding in VEX is negated, + this function returns 1 for the two-byte form.

+

See Intel manual Volume 2 Figure 2-9 of Mar 2026.

" + (case (vex-prefixes->byte0 vex-prefixes) + (#.*vex3-byte0* (vex3-byte1->b (vex-prefixes->byte1 vex-prefixes))) + (otherwise 1)))) + +(defsection evex-prefixes-layout-structures + + :short "Functions to decode and structures to collect + EVEX prefix bytes in an x86 instruction." + :long + "

The EVEX prefix is described in + Intel manual, Mar 2026, Vol. 2, Section 2.7.

" + + ;; Sources: - Intel Vol. 2, Section 2.7 + ;; - Sandpile, under "byte encodings" section: + ;; http://www.sandpile.org/x86/opc_enc.htm + + (defbitstruct evex-prefixes + :short "EVEX prefixes." + :long "

Intel manual, Mar 2026, Vol. 2, Figure 2-11.

" + ((byte0 8bits) ;; Should be #ux62 + (byte1 8bits) + (byte2 8bits) + (byte3 8bits)) + :inline t + :msb-first nil) + + (local + (defthm evex-prefixes-layout-ok + (iff (evex-prefixes-p x) + (unsigned-byte-p *evex-width* x)) + :rule-classes nil)) + + (defbitstruct evex-byte1 + :short "Byte 1 of EVEX prefix." + :long "

Intel manual, Mar 2026, Vol. 2, + Figure 2-11 and Table 2-32.

" + ((mmm 3bits + "Access to up to 8 decoding maps (currently only 1, 2, 3, 5, 6). + Compressed legacy escape: + low two bits identical to lowest two bits of VEX.m-mmmm.") + (res bitp "Reserved; must be zero." :default '0) + (r-prime bitp + "High-16 register specifier modifier; + combine with EVEX.R and ModR/M.reg.") + ;; R, X, B are the next-8 register specifier modifiers; + ;; combine with ModR/M.reg, ModR/M.r/m (base, index/vidx). + (b bitp) + (x bitp "Must be set to @('1') in 32-bit mode, + otherwise instruction is BOUND.") + (r bitp "Must be set to @('1') in 32-bit mode, + otherwise instruction is BOUND.")) + :inline t + :msb-first nil + :xvar byte1) + + (defbitstruct evex-byte2 + :short "Byte 2 of EVEX prefix." + :long "

Intel manual, Mar 2026, Vol. 2, + Figure 2-11 and Table 2-32.

" + ((pp 2bits "Compressed legacy escape: identical to low two bits of VEX.pp.") + (res bitp "Reserved; Must be one." :default '1) + (vvvv 4bits "VVVV register specifier --- same as VEX.vvvv.") + (w bitp "Operand size promotion / opcode extension.")) + :inline t + :msb-first nil) + + (defbitstruct evex-byte3 + :short "Byte 3 of EVEX prefix." + :long "

Intel manual, Mar 2026, Vol. 2, + Figure 2-11 and Table 2-32.

" + ((aaa 3bits "Embedded opmask register specifier.") + (v-prime bitp + "High-16 VVVV/VIDX register specifier; + combine with EVEX.vvvv or when VSIB present.") + (b bitp "Broadcast/RC/SAE Context.") + (vl/rc 2bits "Vector length/RC (denoted as L'L in the Intel manuals).") + (z bitp "Zeroing/Merging.")) + :inline t + :msb-first nil) + + ;; Some wrapper functions to the macros above to make the EVEX dispatch + ;; functions' guard proofs simpler: + + (define evex->aaa ((evex-prefixes evex-prefixes-p)) + :returns (aaa (unsigned-byte-p 3 aaa) :hyp :guard) + :short "Get the @('aaa') field of @('evex-prefixes')." + ;; We avoid inlining these to avoid slow compilation in the + ;; evex-opcodes-dispatch book: + :inline nil + (evex-byte3->aaa (evex-prefixes->byte3 evex-prefixes))) + + (define evex->z ((evex-prefixes evex-prefixes-p)) + :returns (z (unsigned-byte-p 1 z) :hyp :guard) + :short "Get the @('z') field of @('evex-prefixes')." + :inline nil + (evex-byte3->z (evex-prefixes->byte3 evex-prefixes))) + + (define evex->vvvv ((evex-prefixes evex-prefixes-p)) + :returns (vvvv (unsigned-byte-p 4 vvvv) :hyp :guard) + :short "Get the @('vvvv') field of @('evex-prefixes')." + :inline nil + (evex-byte2->vvvv (evex-prefixes->byte2 evex-prefixes))) + + (define evex->v-prime ((evex-prefixes evex-prefixes-p)) + :returns (v-prime (unsigned-byte-p 1 v-prime) :hyp :guard) + :short "Get the @('v-prime') field of @('evex-prefixes')." + :inline nil + (evex-byte3->v-prime (evex-prefixes->byte3 evex-prefixes))) + + (define evex->vl/rc ((evex-prefixes evex-prefixes-p)) + :returns (vl/rc (unsigned-byte-p 2 vl/rc) :hyp :guard) + :short "Get the @('vl/rc') field of @('evex-prefixes')." + :inline nil + (evex-byte3->vl/rc (evex-prefixes->byte3 evex-prefixes))) + + (define evex->pp ((evex-prefixes evex-prefixes-p)) + :returns (pp (unsigned-byte-p 2 pp) :hyp :guard) + :short "Get the @('pp') field of @('evex-prefixes')." + :inline nil + (evex-byte2->pp (evex-prefixes->byte2 evex-prefixes))) + + (define evex->w ((evex-prefixes evex-prefixes-p)) + :returns (w (unsigned-byte-p 1 w) :hyp :guard) + :short "Get the @('W') field of @('evex-prefixes')." + :inline nil + (evex-byte2->w (evex-prefixes->byte2 evex-prefixes)))) + +(defsection ModR/M-structures + :parents (ModR/M-decoding structures) + :short "Bitstruct definitions to store a ModR/M byte and its fields." + :long "

Intel manual, Mar 2026, Vol. 2, Figure 2-1.

" + + (local (xdoc::set-default-parents ModR/M-structures)) + + (defbitstruct modr/m + :short "ModR/M byte." + ((r/m 3bits) + (reg 3bits) + (mod 2bits)) + :inline t + :msb-first nil) + + (defthm return-type-of-ModR/M->r/m-linear + (< (ModR/M->r/m modr/m) 8) + :hints (("Goal" :in-theory (e/d (ModR/M->r/m) ()))) + :rule-classes :linear) + + (defthm return-type-of-ModR/M->reg-linear + (< (ModR/M->reg modr/m) 8) + :hints (("Goal" :in-theory (e/d (ModR/M->reg) ()))) + :rule-classes :linear) + + (defthm return-type-of-ModR/M->mod-linear + (< (ModR/M->mod modr/m) 4) + :hints (("Goal" :in-theory (e/d (ModR/M->mod modr/m-fix) ()))) + :rule-classes :linear)) + +(defsection SIB-structures + + :parents (SIB-decoding structures) + :short "Bitstruct definitions to store a SIB byte and its fields." + :long "

Intel manual, Mar 2026, Vol. 2, Figure 2-1.

" + + (local (xdoc::set-default-parents SIB-structures)) + + (defbitstruct sib + :short "SIB byte." + ((base 3bits) + (index 3bits) + (scale 2bits)) + :inline t + :msb-first nil) + + (defthm return-type-of-sib->base-linear + (< (sib->base sib) 8) + :hints (("Goal" :in-theory (e/d (sib->base) ()))) + :rule-classes :linear) + + (defthm return-type-of-sib->index-linear + (< (sib->index sib) 8) + :hints (("Goal" :in-theory (e/d (sib->index) ()))) + :rule-classes :linear) + + (defthm return-type-of-sib->scale-linear + (< (sib->scale sib) 4) + :hints (("Goal" :in-theory (e/d (sib->scale sib-fix) ()))) + :rule-classes :linear)) + +;; ---------------------------------------------------------------------- + +;; Rflags: + +(defbitstruct rflagsBits + :short "Flags register." + :long "

Intel Manual, Mar 2026, Vol. 1, Section 3.4.3.

" + ((cf bitp) ; carry flag + (res1 bitp :default '1) ; 1 (reserved) + (pf bitp) ; parity flag + (res2 bitp :default '0) ; 0 (reserved) + (af bitp) ; auxiliary carry flag + (res3 bitp :default '0) ; 0 (reserved) + (zf bitp) ; zero flag + (sf bitp) ; sign flag + (tf bitp) ; trap flag + (intf bitp) ; interrupt enable flag + (df bitp) ; direction flag + (of bitp) ; overflow flag + (iopl 2bits) ; I/O privilege level + (nt bitp) ; nested task + (res4 bitp :default '0) ; 0 (reserved) + (rf bitp) ; resume flag + (vm bitp) ; virtual-8086 mode + (ac bitp) ; alignment check / access control + (vif bitp) ; virtual interrupt flag + (vip bitp) ; virtual interrupt pending + (id bitp) ; id flag + (res5 10bits) ; 0 (reserved) + ) + :msb-first nil + :inline t) + +(local + (defthm rflagsBits-layout-ok + (iff (rflagsBits-p x) + (unsigned-byte-p 32 x)) + :rule-classes nil)) + +;; Enable the following for RoW proofs involving rflags +;; (bitstruct accessor and updater functions): + +(def-ruleset rflag-RoWs-enables + '(!rflagsBits->cf-is-rflagsBits + !rflagsBits->res1-is-rflagsBits + !rflagsBits->pf-is-rflagsBits + !rflagsBits->res2-is-rflagsBits + !rflagsBits->af-is-rflagsBits + !rflagsBits->res3-is-rflagsBits + !rflagsBits->zf-is-rflagsBits + !rflagsBits->sf-is-rflagsBits + !rflagsBits->tf-is-rflagsBits + !rflagsBits->intf-is-rflagsBits + !rflagsBits->df-is-rflagsBits + !rflagsBits->of-is-rflagsBits + !rflagsBits->iopl-is-rflagsBits + !rflagsBits->nt-is-rflagsBits + !rflagsBits->res4-is-rflagsBits + !rflagsBits->rf-is-rflagsBits + !rflagsBits->vm-is-rflagsBits + !rflagsBits->ac-is-rflagsBits + !rflagsBits->vif-is-rflagsBits + !rflagsBits->vip-is-rflagsBits + !rflagsBits->id-is-rflagsBits + !rflagsBits->res5-is-rflagsBits)) + +;; ---------------------------------------------------------------------- + +;; Control Registers: + +(defbitstruct cr0Bits + :short "CR0 register." + :long "

Intel Manual, Mar 2026, Vol. 3A, Section 2.5.

" + ((pe bitp "Protection Enable") + (mp bitp "Monitor coProcessor") + (em bitp "Emulation Bit") + (ts bitp "Task Switched") + (et bitp "Extension Type") + (ne bitp "Numeric Error") + (res1 10bits "0 (Reserved)") + (wp bitp "Write Protect") + (res2 bitp "0 (Reserved)") + (am bitp "Alignment Mask") + (res3 10bits "0 (Reserved)") + (nw bitp "Not Write-through") + (cd bitp "Cache Disable") + (pg bitp "Paging Bit")) + :msb-first nil + :inline t) + +(local + (defthm cr0-layout-ok + (iff (cr0Bits-p x) + (unsigned-byte-p 32 x)) + :rule-classes nil)) + +(defbitstruct cr3Bits + :short "CR3 register." + :long "

Intel Manual, Mar 2026, Vol. 3A, Section 2.5.

" + ((res1 3bits) ;; 0 + (pwt bitp) ;; Page-Level Writes Tranparent + (pcd bitp) ;; Page-Level Cache Disable + (res2 7bits) ;; 0 + (pdb 40bits) ;; Page Directory Base + (res3 12bits) ;; Reserved (must be zero) + ;; The reason why res3 are 12 reserved bits is that + ;; CR3[63:MAXPHYADDR] must be 0 (see Intel Manual Vol. 3A Section 2.5), + ;; and in our model we have 52-bit physical addresses. + ) + :msb-first nil + :inline t) + +(local + (defthm cr3-layout-ok + (iff (cr3Bits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +(defbitstruct cr4Bits + :short "CR4 register." + :long "

Intel Manual, Mar 2026, Vol. 3A, Section 2.5.

" + ((vme bitp) ;; Virtual-8086 Mode Extensions + (pvi bitp) ;; Protected-Mode Virtual Interrupts + (tsd bitp) ;; Time-Stamp Disable + (de bitp) ;; Debugging Extensions + (pse bitp) ;; Page Size Extensions + (pae bitp) ;; Physical Address Extension + (mce bitp) ;; Machine-Check Enable + (pge bitp) ;; Page Global Enable + (pce bitp) ;; Performance Monitoring Counter Enable + (osfxsr bitp) ;; OS Support for FXSAVE and FXRSTOR + (osxmmexcpt bitp) ;; OS Support for unmasked SIMD FP Exceptions + (umip bitp) ;; User-mode instruction prevention + (la57 bitp) ;; enables 5-level paging + (vmxe bitp) ;; VMX Enable Bit + (smxe bitp) ;; SMX Enable Bit + (res1 bitp) ;; 0 (Reserved) + (fsgsbase bitp) ;; FSGSBase-Enable Bit (enables the instructions + ;; RDFSBASE, RDGSBASE, WRFSBASE, and WRGSBASE) + (pcide bitp) ;; Process-Context Identifiers Enable Bit + (osxsave bitp) ;; XSAVE and Processor Extended States + (kl bitp) ;; Key Locker Enable Bit + (smep bitp) ;; Supervisor Mode Execution Prevention + (smap bitp) ;; Supervisor Mode Access Prevention + (pke bitp) ;; Enable protection keys for user-mode pages + (cet bitp) ;; Control Flow Enforcement Technology + (pks bitp) ;; Protection keys for supervisor-mode pages + (uintr bitp) ;; User interrupts enable bit + (res2 2bits) ;; 0 (Reserved) + (lam-sup bitp) ;; Supervisor LAM enable + (res3 3bits) ;; 0 (Reserved) + (fred bitp) ;; FRED enable + ;; The remaining bits are reserved. + ) + :msb-first nil + :inline t) + +(local + (defthm cr4-layout-ok + (iff (cr4Bits-p x) + (unsigned-byte-p 33 x)) + :rule-classes nil)) + +; Intel manual, Mar 2026, Vol. 3A, Section 13.8.6 +(defbitstruct cr8Bits + :short "CR8 register." + :long "

Intel Manual, Mar 2026, Vol. 3A, Section 2.5.

" + ( + ;; Task Priority Level (width = 4). This sets + ;; the threshold value corresponding to the + ;; highest- priority interrupt to be + ;; blocked. A value of 0 means all interrupts + ;; are enabled. This field is available in 64- + ;; bit mode. A value of 15 means all + ;; interrupts will be disabled. + (cr8-trpl 4bits) ;; Task Priority Level + ;; The remaining bits are reserved. + ) + :msb-first nil + :inline t) + +(local + (defthm cr8-layout-ok + (iff (cr8Bits-p x) + (unsigned-byte-p 4 x)) + :rule-classes nil)) + +(defbitstruct xcr0Bits + :short "XCR0 register." + :long "

Intel manual, Mar 2026, Vol. 3A, Figure 2-8.

" + ;; Software can access XCR0 only if CR4.OSXSAVE[bit 18] = 1. (This bit + ;; is also readable as CPUID.01H:ECX.OSXSAVE[bit 27].) + ((fpu/mmx-state bitp) ;; This bit must be 1. An attempt + ;; to write 0 to this bit causes a + ;; #GP exception. + (sse-state bitp) + (avx-state bitp) + (bndreg-state bitp) + (bndcsr-state bitp) + (opmask-state bitp) + (zmm_hi256-state bitp) + (hi16_zmm-state bitp) + (res1 bitp) ;; 0 (Reserved) + (pkru-state bitp) + (res2 7bits) ;; 0 (Reserved) + (tileconfig-state bitp) + (tiledata-state bitp) + (res3 45bits)) + :msb-first nil + :inline t) + +(local + (defthm xcr0-layout-ok + (iff (xcr0Bits-p x) + (unsigned-byte-p 64 x)) + :rule-classes nil)) + +;; ---------------------------------------------------------------------- + +;; Model-specific Registers: + +(defbitstruct ia32_eferBits + :short "IA32_EFER register." + :long "

Intel Manual, Mar 2026, Vol. 3A, Section 2.2.1.

" + ((sce bitp) ;; Syscall Enable (R/W) (enables SYSCALL/SYSRET) + (res1 7bits) ;; Reserved? + (lme bitp) ;; Long Mode Enabled (R/W) + (res2 bitp) ;; Reserved? + (lma bitp) ;; Long Mode Active (R) + (nxe bitp) ;; Execute Disable Bit Enable (R/W) + ;; (Enables page access restriction by + ;; preventing instruction fetches from + ;; PAE pages with the XD bit set) + ;; The remaining bits are reserved. + ) + :msb-first nil + :inline t) + +(local + (defthm ia32_efer-layout-ok + (iff (ia32_eferBits-p x) + (unsigned-byte-p 12 x)) + :rule-classes nil)) + +;; ---------------------------------------------------------------------- diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/utils/utilities.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/utils/utilities.lisp new file mode 100644 index 000000000..d198781d2 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/utils/utilities.lisp @@ -0,0 +1,485 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2026, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Shilpi Goel +; Warren A. Hunt, Jr. +; Matt Kaufmann +; Contributing Author(s): +; Alessandro Coglio + +(in-package "X86ISA") + +(include-book "xdoc/top" :dir :system) +(include-book "std/util/define" :dir :system) +(include-book "std/util/defrule" :dir :system) +(include-book "std/util/def-bound-theorems" :dir :system) +(include-book "std/lists/list-fix" :dir :system) +(include-book "centaur/bitops/part-install" :dir :system) +(include-book "centaur/bitops/fast-logext" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) +(local (include-book "centaur/bitops/logbitp-bounds" :dir :system)) +(local (include-book "std/alists/alistp" :dir :system)) + +;; ---------------------------------------------------------------------- + +(defsection utils + :parents (x86isa) + :short "Utilities for rest of the @('X86ISA') books.") + +(defsection utilities + :parents (utils)) + +;; ---------------------------------------------------------------------- + +(defsection mk-name + + :parents (utilities) + :short "Macro that can be used to create event names by + concatenating strings, symbols, numbers, and characters." + :long "@(def mk-name)" + + (defmacro mk-name (&rest x) + ;; Note that the package is X86ISA here. + `(acl2::packn-pos (list ,@x) 'x86isa::mk-name))) + +;; ---------------------------------------------------------------------- + +;; Convenient forcing idiom: + +(defun formal-force-list (x) + (declare (xargs :guard (true-listp x))) + (cond ((endp x) nil) + (t (cons `(force ,(car x)) + (formal-force-list (cdr x)))))) + +(defmacro forced-and (&rest x) + `(and ,@(formal-force-list x))) + +;; ---------------------------------------------------------------------- + +(defsection constants-conversions-and-bounds + :parents (utilities) + :short "Definitions of commonly used constants and some functions to + convert between @('natp') and @('integerp'), etc." + + :long "

Definitions of constants (of the form @('*2^W*'), where @('W') is the +plain decimal natural number) and functions/macros grouped in @('ruleset')s of +the following form are defined (where in the function/macro names @('W') is +zero-padded to at least two digits, so @('8') is represented as @('08')):

+ +
    + +
  • @('nWp') belongs to @('nwp-defs') ruleset. +@({ + (define nWp (x) + (unsigned-byte-p W x)) +})
  • + +
  • @('nW') belongs to @('nw-defs') ruleset. +@({ + (define nW ((x integerp)) + (mbe :logic (loghead W x) + :exec (logand 2^W-1 x))) +})
  • + +
  • @('iWp') belongs to @('iwp-defs') ruleset. +@({ + (define iWp (x) + (signed-byte-p W x)) +})
  • + +
  • @('iW') belongs to @('iw-defs') ruleset. +@({ + (define iW ((x integerp)) + (mbe :logic (logext W x) + :exec (fast-logext W x))) +})
  • + +
  • @('nW-to-iW') belongs to @('nw-to-iw-defs') ruleset. +@({ + (define nW-to-iW ((x nWp :type (unsigned-byte W))) + (mbe :logic (logext W x) + :exec (if (< x 2^(W-1)) x (- x 2^W)))) +})
  • + +
  • @('iW-to-nW') belongs to @('iw-to-nw-defs') ruleset. +@({ + (define iW-to-nW ((x iWp :type (signed-byte W))) + (mbe :logic (loghead W x) + :exec (if (>= x 0) x (+ x 2^W)))) +})
  • + +
+ +

The function @('np-def-n') is used to automatically create these +constants and functions.

") + +;; Lemmas to help in the MBE proof obligations +;; of the generated NTOI and ITON functions below: + +(local + (encapsulate () + + (local (include-book "arithmetic-5/top" :dir :system)) + + (defruled logext-when-unsigned-byte-p-and-sign-changes + (implies (and (unsigned-byte-p size x) + (<= (expt 2 (1- size)) x)) + (equal (logext size x) (- x (expt 2 size)))) + :enable (logext logapp loghead)) + + (defruled loghead-when-signed-byte-p-and-sign-changes + (implies (and (signed-byte-p size x) + (< x 0)) + (equal (loghead size x) (+ (expt 2 size) x))) + :enable loghead + :prep-lemmas + ((defrule lemma + (implies (posp size) + (< (expt 2 (1- size)) + (expt 2 size))) + :rule-classes :linear))))) + +(def-ruleset nwp-defs nil) +(def-ruleset nw-defs nil) +(def-ruleset iwp-defs nil) +(def-ruleset iw-defs nil) +(def-ruleset nw-to-iw-defs nil) +(def-ruleset iw-to-nw-defs nil) + +(define np-def-n (n) + :mode :program + :guard (posp n) + :parents (constants-conversions-and-bounds) + (let* ((str-n (symbol-name (if (< n 10) + (acl2::packn (list 0 n)) + (acl2::packn (list n))))) + (digits (symbol-name (acl2::packn (list n)))) + (2^XY (mk-name "*2^" digits "*")) + (nXYp (mk-name "N" str-n "P")) + (nXY (mk-name "N" str-n)) + (iXYp (mk-name "I" str-n "P")) + (iXY (mk-name "I" str-n)) + (ntoi (mk-name "N" str-n "-TO-I" str-n)) + (iton (mk-name "I" str-n "-TO-N" str-n))) + (list + + `(defconst ,2^XY + (expt 2 ,n)) + + ;; All the following functions are kept enabled. + + `(define ,nXYp (x) + ;; XY-bit natural number recognizer + :inline t + :no-function t + :enabled t + :parents (constants-conversions-and-bounds) + (unsigned-byte-p ,n x)) + + `(define ,nXY ((x integerp)) + ;; Truncate input to an XY-bit natural number + ;; This function can be used to convert, say a 32-bit integer + ;; to a 32-bit natural number. + :inline t + :no-function t + :enabled t + :parents (constants-conversions-and-bounds) + (mbe :logic (loghead ,n x) + :exec (logand ,(1- (expt 2 n)) x))) + + `(define ,iXYp (x) + ;; XY-bit integer recognizer + :inline t + :no-function t + :enabled t + :parents (constants-conversions-and-bounds) + (signed-byte-p ,n x)) + + `(define ,iXY ((x integerp)) + ;; Truncate input to an XY-bit signed integer number + ;; This function can be used to convert, say a 32-bit natural number + ;; to a 32-bit integer. + :inline t + :no-function t + :enabled t + :parents (constants-conversions-and-bounds) + (mbe :logic (logext ,n x) + :exec (bitops::fast-logext ,n x))) + + `(define ,ntoi ((x ,nXYp :type (unsigned-byte ,n))) + ;; Convert natural number to integer + :inline t + :no-function t + :enabled t + :parents (constants-conversions-and-bounds) + :guard-hints (("Goal" + :in-theory + (enable logext-when-unsigned-byte-p-and-sign-changes))) + (mbe :logic (logext ,n x) + :exec (if (< x ,(expt 2 (1- n))) + x + (- x ,(expt 2 n))))) + + `(define ,iton ((x ,iXYp :type (signed-byte ,n))) + ;; Convert integer to natural number + :inline t + :no-function t + :enabled t + :parents (constants-conversions-and-bounds) + :guard-hints (("Goal" + :in-theory + (enable loghead-when-signed-byte-p-and-sign-changes))) + (mbe :logic (loghead ,n x) + :exec (if (>= x 0) + x + (+ x ,(expt 2 n))))) + + `(add-to-ruleset nwp-defs '(,nXYp)) + `(add-to-ruleset nw-defs '(,nXY)) + `(add-to-ruleset iwp-defs '(,iXYp)) + `(add-to-ruleset iw-defs '(,iXY)) + `(add-to-ruleset nw-to-iw-defs '(,ntoi)) + `(add-to-ruleset iw-to-nw-defs '(,iton)) + ))) + +(define np-defs (lst) + :mode :program + :guard (acl2::pos-listp lst) + :parents (constants-conversions-and-bounds) + (if (atom lst) nil + (append (np-def-n (car lst)) + (np-defs (cdr lst))))) + +(defmacro defuns-np (&rest lst) + (cons 'progn (np-defs lst))) + +(defuns-np 1 2 3 4 5 6 8 9 11 12 16 17 18 20 21 22 24 25 26 27 28 + 30 32 33 35 43 44 45 47 48 49 51 52 55 59 60 64 65 80 112 120 128 256 512) + +(defmacro n-size (n x) + ;; We prefer using n-size in functions that generate functions. E.g., + ;; see gpr-add-spec-gen-fn in machine/instructions/add-spec.lisp. + (let* ((fn-name (mk-name "N" + (symbol-name (if (< n 10) + (acl2::packn (list 0 n)) + (acl2::packn (list n))))))) + `(,fn-name ,x))) + +(defmacro ntoi (n x) + ;; We prefer using ntoi in functions that generate functions. E.g., + ;; see idiv-spec-gen in machine/instructions/divide-spec.lisp. + (let* ((val (symbol-name (if (< n 10) + (acl2::packn (list 0 n)) + (acl2::packn (list n))))) + (fn-name (mk-name "N" val "-TO-I" val))) + `(,fn-name ,x))) + +(define trunc + ;; We prefer using trunc in function definitions. + ((n :type (integer 0 *)) ; n is in bytes + (x :type integer)) + :inline t + :no-function t + :enabled t + (case n + (1 (n08 x)) + (2 (n16 x)) + (4 (n32 x)) + (8 (n64 x)) + (16 (n128 x)) + (t (part-select x :low 0 :width (* 8 n))))) + +;; ---------------------------------------------------------------------- + +;; Handy utility for turning a positional list into an array + +(defun list-to-alist (x i acc) + (declare (xargs :guard (and (true-listp x) + (natp i) + (alistp acc)))) + (cond ((endp x) (reverse acc)) + (t (list-to-alist (cdr x) + (1+ i) + (acons i (car x) acc))))) + +(defthm alistp-of-list-to-alist + (implies (alistp acc) + (alistp (list-to-alist x i acc)))) + +(defthm bounded-integer-alistp-monotone + (implies (and (bounded-integer-alistp x i) + (natp i) + (natp j) + (<= i j)) + (bounded-integer-alistp x j))) + +(defthm bounded-integer-alistp-revappend + (implies (true-listp x) + (equal (bounded-integer-alistp (revappend x y) i) + (and (bounded-integer-alistp x i) + (bounded-integer-alistp y i)))) + :hints (("Goal" :induct (revappend x y)))) + +(defthm bounded-integer-alistp-list-to-alist + (implies (and (natp i) + (bounded-integer-alistp acc i) + (equal k (+ i (len x)))) + (bounded-integer-alistp (list-to-alist x i acc) + k))) + +(defun list-to-array (name x) + (declare (xargs :guard (and (symbolp name) + (true-listp x) + x + (< (length x) + (acl2::array-maximum-length-bound))))) + (let ((alist (list-to-alist x 0 nil)) + (len (length x))) + (compress1 name + `((:header :dimensions (,len) + :maximum-length ,(1+ len) + :default x + :name ,name) + ,@alist)))) + +;; ---------------------------------------------------------------------- + +;; Maps a list of integers to a corresponding list of Booleans, +;; treating 0 as false. Example: (ints-to-booleans '(0 1 0 0 1)) ==> +;; (nil t nil nil t). + +(defun ints-to-booleans-acc (x acc) + (declare (xargs :guard (and (integer-listp x) + (true-listp acc)))) + (cond ((endp x) (reverse acc)) + (t (ints-to-booleans-acc (cdr x) + (cons (not (zerop (car x))) + acc))))) + +(defun ints-to-booleans (x) + (declare (xargs :guard (integer-listp x))) + (ints-to-booleans-acc x nil)) + +;; ---------------------------------------------------------------------- + +(defsection globally-disabled-events + :parents (utilities) + + :short "A ruleset containing all the events supposed to be mostly + globally disabled in our books" + + :long "

The macro @('globally-disable') adds its argument --- + either a ruleset or an event --- to the ruleset called + @('globally-disabled-events'), and then disables + @('globally-disabled-events').

+ +

Use the following form to see the events in this ruleset:

+ + +\(show-globally-disabled-events-ruleset\) + + +

The idea behind having a @('globally-disabled-events') ruleset is +to provide some indication to the user of these books which events are +supposed to be mostly disabled throughout the books. This ruleset does +NOT reflect the enabled status of these events at any point, i.e., we +do not guarantee that an event @('FOO') in this ruleset will be +disabled everywhere in these books.

+ +

If you need to enable some events in @('globally-disabled-events') +during book/proof development, it is recommended to do so locally.

+ +

Use the following form to see the current status (enabled or +disabled) of the events in the @('globally-disabled-events') +ruleset:

+ + +\(show-globally-disabled-events-status\) + + +

@('show-globally-disabled-events-status') simply calls @(see +disabledp) recursively on the events in +@('globally-disabled-events').

" + + (def-ruleset globally-disabled-events nil) + + (define globally-disable-fn + ((events "Can be a symbol (another ruleset) + or a @('true-listp') (set of events)")) + (b* ((events (if (true-listp events) + `(quote ,events) + events))) + `(progn + ;; add-to-ruleset will catch any invalid events, e.g., + ;; those that don't exist. + (add-to-ruleset globally-disabled-events ,events) + (in-theory (disable* globally-disabled-events))))) + + (defmacro globally-disable (events) + `(make-event (globally-disable-fn ,events))) + + (define show-globally-disabled-events-fn + ((state)) + :mode :program + (let ((world (w state))) + (ruleset-theory 'globally-disabled-events))) + + (defmacro show-globally-disabled-events-ruleset () + `(show-globally-disabled-events-fn state)) + + (defun disabledp-lst (lst count state) + (declare (xargs :stobjs (state) + :mode :program)) + (if (endp lst) + (mv (cw "~%~%Number of events in GLOBALLY-DISABLED-EVENTS: ~x0~%~%" + count) + :invisible + state) + + (b* ((- (cw "~%-- ~x0 ~%~t1 ~x2~%" + (car lst) + 1 + (or (disabledp (car lst)) + :ENABLED)))) + (disabledp-lst (cdr lst) (1+ count) state)))) + + (defmacro show-globally-disabled-events-status () + `(disabledp-lst (show-globally-disabled-events-ruleset) 0 state)) + + (globally-disable '(logior logand logxor floor mod ash))) diff --git a/crates/clazel-x64/tests/data/intel-sdm/LICENSE.md b/crates/clazel-x64/tests/data/intel-sdm/LICENSE.md new file mode 100644 index 000000000..9d8c34732 --- /dev/null +++ b/crates/clazel-x64/tests/data/intel-sdm/LICENSE.md @@ -0,0 +1,10 @@ +# Licence of the Intel SDM + +None granted for redistribution. The Intel 64 and IA-32 Architectures +Software Developer's Manual is Copyright Intel Corporation. Intel's Terms of +Use (https://www.intel.com/content/www/us/en/legal/terms-of-use.html, read on +2026-11-16) say its documents may be used for personal, non-commercial +information and may not be copied or posted. The PDF is therefore not +vendored here: `SOURCE.md` pins it by URL, size and SHA-256. + +This file is a statement of that decision, not a copy of a licence. diff --git a/crates/clazel-x64/tests/data/intel-sdm/SOURCE.md b/crates/clazel-x64/tests/data/intel-sdm/SOURCE.md new file mode 100644 index 000000000..2701a58bc --- /dev/null +++ b/crates/clazel-x64/tests/data/intel-sdm/SOURCE.md @@ -0,0 +1,28 @@ +# Intel 64 and IA-32 Architectures Software Developer's Manual, volume 2 (A-Z), pinned and not vendored + +Upstream: https://cdrdv2-public.intel.com/929352/325383-093-sdm-vol-2abcd.pdf +SHA-256: d137a7887787bbb06c1a8b8bafd51958d8d2e16b4dff987a03226c845cca1516 325383-093-sdm-vol-2abcd.pdf +Size: 11294447 325383-093-sdm-vol-2abcd.pdf +License: Intel copyright, no licence to redistribute. See `LICENSE.md`. + +Version 093 of "Combined Volumes 2A, 2B, 2C and 2D: Instruction Set Reference, +A-Z" (order number 325383), the latest on Intel's page +https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html +on 2026-11-16 (the link there, https://cdrdv2.intel.com/v1/dl/getContent/671110, +redirects to the URL above). The encoding tables of jit.md item J.3 are +Appendix A (the opcode maps) and the "Instruction Operand Encoding" tables of +each instruction page; the operations are the pseudocode of each page. + +The PDF is not in this repository, because Intel's terms of use +(https://www.intel.com/content/www/us/en/legal/terms-of-use.html) say its +documents may not be copied or posted, and the PDF carries no open licence. So +the pin is the URL, the size and the SHA-256 above: a reader fetches the file +and compares. If Intel moves or replaces the file, the hash no longer matches +and the pin must be changed by a person, after reading the new edition's +change list. + +`xtask/src/testdata/isa.rs` writes `tests/generated/intel_sdm.rs`, the table +of this pin. Intel's XED encoder/decoder tables (Apache-2.0, +https://github.com/intelxed/xed) are a machine-readable form of the same +encoding data and are not pinned here; whether to pin them is a decision for a +person. diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENCE b/crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENCE new file mode 100644 index 000000000..5300da8d0 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENCE @@ -0,0 +1,37 @@ +All files and directories are subject to the BSD two-clause licence +below, except the translated x86 model files in the `model/` +directory, which are subject to the terms of a BSD three-clause licence +and additionally the licence of the original ACL2 x86 model, from which +the Sail model is generated (see `model/LICENSE`). + +Copyright (c) 2020 Patrick Taylor +Copyright (c) 2022 Capabilities Limited + +This software was developed in part by SRI International, the University +of Cambridge Computer Laboratory (Department of Computer Science and +Technology), and Capabilities Limited under Defense Advanced Research +Projects Agency (DARPA) Contract No. HR001122C0110 ("ETC"). + +Portions of this software were developed by Thomas Bauereiss under +contract to Capabilities Limited. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENSE.md b/crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENSE.md new file mode 100644 index 000000000..538667177 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/LICENSE.md @@ -0,0 +1,81 @@ +The files in this directory and its subdirectories are distributed under the +terms of the following two BSD three-clause licences, where the latter is the +licence of the original ACL2 x86 model from which this Sail model is derived. + +Copyright (c) 2020 Patrick Taylor +Copyright (c) 2022 Capabilities Limited + +This software was developed in part by SRI International, the University +of Cambridge Computer Laboratory (Department of Computer Science and +Technology), and Capabilities Limited under Defense Advanced Research +Projects Agency (DARPA) Contract No. HR001122C0110 ("ETC"). + +Portions of this software were developed by Thomas Bauereiss under +contract to Capabilities Limited. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +[Note: The license below is based on the template found July 25, 2014 + at: http://opensource.org/licenses/BSD-3-Clause. Except as + otherwise noted, it applies to all files distributed from + http://www.cs.utexas.edu/users/moore/acl2/current/, + as well as to all files distributed from + https://github.com/acl2/acl2 other than those in the + ACL2 Community Books (the books/ subdirectory). +When a file in the ACL2 Community Books refers to this LICENSE, that file's +specified copyright supersedes the copyright shown immediately below.] + +Copyright (c) 2022, Regents of the University of Texas +Copyright (C) 2022, Shilpi Goel +Copyright (C) 2022, Kestrel Technology, LLC +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +o Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +o Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +o Neither the name of the copyright holder nor the names of + its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/README.md b/crates/clazel-x64/tests/data/sail-x86-from-acl2/README.md new file mode 100644 index 000000000..737830c30 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/README.md @@ -0,0 +1,68 @@ +# ACL2-to-Sail translator and the resulting Sail x86 ISA model + +[ToC] + +## Introduction + +This project translates the [X86isa](https://www.cs.utexas.edu/~moore/acl2/v8-5/combined-manual/index.html?topic=ACL2____X86ISA) formal model of the x86 ISA, written in ACL2 by Shilpi Goel, Warren A. Hunt, Jr., and Matt Kaufmann, into [Sail](https://www.cl.cam.ac.uk/~pes20/sail/popl2019.html), a language designed for modelling ISA semantics. + +The translator was originally developed by Patrick Taylor as a student project in 2020, with supervision by Alasdair Armstrong and Peter Sewell. Since then, Thomas Bauereiss has updated and extended it, in particular extending the scope of the translation, making the data type annotations more precise, and making the generated Sail code more idiomatic. + +This README provides a quick start guide for getting the translator working, before detailing the implementation. + +Files and folders: + +* `model/` contains a snapshot of the Sail model generated by the translator. +* `translator/` contains the translator code as well as validation scripts in `translator/validation/`. The `Readme.md` file in the latter directory describes how to use the translated model. +* `doc/` contains documentation of the original prototype of the translator, in particular Patrick's dissertation in `doc/diss/latex/diss.pdf`. Much of this still applies to the current version of the translator, but some aspects have changed; for example, the type inference now generates fixed-width bitvector type annotations where possible, rather than using unbounded integers. + +## Quick Start Guide - Running the Translator + +These first steps give us a current version of the ACL2 x86 model. The certification steps are necessary because the translator must be able to call a running instance of ACL2 with the X86ISA project loaded in order to perform macro expansion. + +1. Download and install ACL2 and certify the community books as detailed here: . SBCL is the recommended underlying Common Lisp - CCL seems to cause problems. +2. Certify the `x86ISA` book as explained here: . I ran `cert.pl top` from `/tools/execution/` where `/books/projects/x86isa/`. `cert.pl` should be in `/books/build/`. +3. Go to the `translator` directory, and copy the configuration file template `config.toml.in` to `config.toml`. Set the configuration varialbe `acl2_process` to the path to the ACL2 executable (probably called `saved_acl2`). +4. Run `python3 callACL2.py` to start a running instance of ACL2 with which the translator can interact. You can change its port number by setting `acl2_port` in `config.toml`. Wait until it prints `Ready` before proceeding. Leave this running and execute the next steps in a separate terminal. + +These steps run the translator. + +1. Set other options in `translator/config.toml`. Most should be fine as default except: + 1. `x86_project_folder` location of the x86 ISA project folder (probably `/books/projects/x86isa/`). + 2. `outputFolder` - the Sail output files will be saved here. Make sure that this directory exists before running the translation. + 3. `unresolvedTypesFile` - location of a log file for the type resolution algorithm. +2. Run `python3 ./transform.py` to perform the translation. +3. The translation could take a few minutes - once it has completed the program will exit. + +## Code Structure and File Guide + +The following diagram shows the general structure of the translator. Each file is also briefly described below. + +![Diagrams](doc/Diagrams.svg) + +**General** + +* `transform.py` is the top level file. It defines the environment which is threaded throughout the translator and dispatches control of translation to individual 'translation functions' (see General Comments below). +* `lex_parse.py` contains functions for lexing and parsing Lisp code and for pretty printing Lisp ASTs. + +**Translation Functions** + +* `specialTokens.py` contains translation functions for 'special tokens' (i.e. built-in Lisp forms or forms which are convenient to translate manually). +* `handwritten_tokens.py` contains the names and types of the handwritten functions contained in `handwritten.sail`. +* `manualInterventions.py` contains the code for Lisp forms which do not conform to the assumptions made in the translation functions and where a special case is required. + +**Configuration Files** + +* `config.toml.in` is a configuration file template that should be copied to `config.toml` to enable it. It contains file paths, most notably for locating the ACL2 model and setting output folder. There are some global options in here as well. +* `config_patterns.py` defines the slice of the model to translate by either specifying Lisp forms to exclude from files otherwise translated, or by specifying Lisp forms to translate from files otherwise excluded. +* `config_function_maps.py` contains mappings of Lisp tokens to Python translation functions (drawn from the translation function files above). These tables are used each time a token is encountered during translation. + +**Misc.** + +* `SailASTelems.py` and `SailTypes.py` contain Python representations of Sail syntactic elements and Sail types, as well as pretty printing methods. Some computation is performed here: the class `SailApp` contains some type resolution code; and other AST classes contain special case code (see `doc/SpecialCases.md` for details). +* `callACL2.py` and `socketFuncs.py` contain code for starting an ACL2 instance which can be queried for macro expansions etc. +* `utils.py` contains miscellaneous utilities, most notably a function for transforming Lisp names (which are very permissive) into Sail names. + +## Licence + +The files in this repository are distributed under the BSD 2-clause licence in `LICENCE`, except for the model snapshot in `model`, which is derived from the original ACL2 model, distributed under the BSD 3-clause licence. A copy of the latter can be found in `model/LICENCE`. diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md b/crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md new file mode 100644 index 000000000..5f499cfa5 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md @@ -0,0 +1,39 @@ +# The Sail x86 model translated mechanically from the ACL2 x86isa model (a subset of its files) + +Upstream: https://github.com/rems-project/sail-x86-from-acl2/tree/0c6c023dccc7c20d8d9dbfc481f01d9bb49d62bf +Commit: 0c6c023dccc7c20d8d9dbfc481f01d9bb49d62bf +License: BSD-3-Clause for the model snapshot (`model/LICENSE`: Patrick Taylor and Capabilities Limited, and the University of Texas for the ACL2 model it derives from; `LICENSE.md` is a copy of it); BSD-2-Clause for the translator and the rest of the repository (`LICENCE`). + +The commit is the tip of `master` of rems-project/sail-x86-from-acl2 on +2026-11-16 ("Update README.md", 2024-11-29; its last model change is "Update +model snapshot"). Its README says the model is "automatically translated" +from the ACL2 x86isa model by a translator written by Patrick Taylor and +extended by Thomas Bauereiss (supervised by Alasdair Armstrong and Peter +Sewell). **This model is therefore not an independent source from +`acl2-x86isa`**: the functions keep the ACL2 names (`gpr_add_spec_1`, +`jcc_cmovcc_setcc_spec`) and the structure of the ACL2 books line by line. +The analysis is in `crates/clazel-x64/README.md`. + +Copied byte for byte, from the repository root, `README.md` and `LICENCE`; from +`model/`, the files of the integer subset of jit.md item J.3: the prelude and +register files, the ModR/M, SIB and prefix decoding, RFLAGS, linear and +physical memory, `step.sail` and the two- and three-byte opcode dispatch, and +the books for `add`, `sub`, `and`, `or`, `xor`, shifts and rotates, +`multiply`, `conditional`, `jump_and_loop`, `mov`, `move`, `subroutine` and +`signextend`. + +Not vendored: the translator (`translator/`), the documentation, the +generated test patches, `evex_opcodes_dispatch.sail` and +`vex_opcodes_dispatch.sail` (1.3 MB, AVX), and the books outside the subset. +**The translated model appears to have no SSE2 scalar double instructions**: +none of the vendored files mentions `addsd`, `sqrtsd` or `ucomisd`, and the +files not vendored are named for integer, string, segment and system +instructions and for the AVX dispatch (the floating-point books of the ACL2 +model, `machine/instructions/fp/`, were not translated; only the shuffle and +unpack and `mov` SSE books were). It can serve as a second source for the +integer subset at most. + +To update, copy the files from a newer commit, change the commit above, and +run `cargo xtask testdata`. `xtask/src/testdata/isa.rs` writes +`tests/generated/sail_x86_from_acl2.rs`, the inventory of paths, sizes and +hashes. Nothing reads the model yet. diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/LICENSE b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/LICENSE new file mode 100644 index 000000000..538667177 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/LICENSE @@ -0,0 +1,81 @@ +The files in this directory and its subdirectories are distributed under the +terms of the following two BSD three-clause licences, where the latter is the +licence of the original ACL2 x86 model from which this Sail model is derived. + +Copyright (c) 2020 Patrick Taylor +Copyright (c) 2022 Capabilities Limited + +This software was developed in part by SRI International, the University +of Cambridge Computer Laboratory (Department of Computer Science and +Technology), and Capabilities Limited under Defense Advanced Research +Projects Agency (DARPA) Contract No. HR001122C0110 ("ETC"). + +Portions of this software were developed by Thomas Bauereiss under +contract to Capabilities Limited. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +[Note: The license below is based on the template found July 25, 2014 + at: http://opensource.org/licenses/BSD-3-Clause. Except as + otherwise noted, it applies to all files distributed from + http://www.cs.utexas.edu/users/moore/acl2/current/, + as well as to all files distributed from + https://github.com/acl2/acl2 other than those in the + ACL2 Community Books (the books/ subdirectory). +When a file in the ACL2 Community Books refers to this LICENSE, that file's +specified copyright supersedes the copyright shown immediately below.] + +Copyright (c) 2022, Regents of the University of Texas +Copyright (C) 2022, Shilpi Goel +Copyright (C) 2022, Kestrel Technology, LLC +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +o Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +o Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +o Neither the name of the copyright holder nor the names of + its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/Makefile b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/Makefile new file mode 100644 index 000000000..4e2834491 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/Makefile @@ -0,0 +1,58 @@ +# Attempt to work with either sail from opam or built from repo in SAIL_DIR +ifneq ($(SAIL_DIR),) +# Use sail repo in SAIL_DIR +SAIL:=$(SAIL_DIR)/sail +export SAIL_DIR +else +# Use sail from opam package +SAIL_DIR:=$(shell opam config var sail:share) +SAIL:=sail +endif + +ISLA_SAIL=isla-sail + +PRELUDE_SAILS=prelude.sail register_types.sail registers.sail register_accessors.sail opcode_ext.sail memory_accessors.sail init.sail config.sail logging.sail +MODEL_SAILS=step.sail +MAIN_SAIL=main.sail +ALL_SAILS=$(PRELUDE_SAILS) $(MODEL_SAILS) $(MAIN_SAIL) + +TRANSLATOR_OUTPUT=../output + +CC?=gcc + +GMP_FLAGS = $(shell pkg-config --cflags gmp) +# N.B. GMP does not have pkg-config metadata on Ubuntu 18.04 so default to -lgmp +GMP_LIBS := $(shell pkg-config --libs gmp || echo -lgmp) + +ZLIB_FLAGS = $(shell pkg-config --cflags zlib) +ZLIB_LIBS = $(shell pkg-config --libs zlib) + +all: x86_emulator + +.PHONY: all interactive update_snapshot + +x86_emulator.c: $(ALL_SAILS) + $(SAIL) -c -memo_z3 $(SAIL_FLAGS) $(ALL_SAILS) > x86_emulator.c.temp + mv x86_emulator.c.temp x86_emulator.c + +x86_emulator: x86_emulator.c + $(CC) -O2 -DHAVE_SETCONFIG x86_emulator.c $(SAIL_DIR)/lib/*.c $(GMP_FLAGS) $(GMP_LIBS) $(ZLIB_FLAGS) $(ZLIB_LIBS) -I $(SAIL_DIR)/lib/ -o x86_emulator + +x86.ir: $(ALL_SAILS) + $(ISLA_SAIL) $(foreach file,$(wildcard ../test-generation-patches/*.sail),-splice $(file)) -verbose 1 -o x86 $(ALL_SAILS) + +interactive: + $(SAIL) -i -memo_z3 $(SAIL_FLAGS) $(ALL_SAILS) + +update_snapshot: + mkdir -p $(TRANSLATOR_OUTPUT)/format + cd $(TRANSLATOR_OUTPUT); $(SAIL) -output_sail -output_sail_dir format $(ALL_SAILS) + cp $(TRANSLATOR_OUTPUT)/format/*.sail . + cp ../translator/handwrittenSupport/*.sail . + # Add ifdefs to structures.sail to support multiple inclusions + echo "\$$ifndef __X86_STRUCTURES" > structures.sail.header + echo "\$$define __X86_STRUCTURES" >> structures.sail.header + cat structures.sail.header structures.sail > structures.sail.tmp + echo "\$$endif" >> structures.sail.tmp + mv structures.sail.tmp structures.sail + rm structures.sail.header diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/add_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/add_spec.sail new file mode 100644 index 000000000..515ae192e --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/add_spec.sail @@ -0,0 +1,141 @@ +$include "./rflags_spec.sail" + +val gpr_add_spec_1 : (bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_add_spec_1 (dst, src, input_rflags) = { + let raw_result : bits(9) = bits_of_int(unsigned(dst) + unsigned(src), 9); + let signed_raw_result : sbits(9) = bits_of_int(signed(dst) + signed(src), 9); + let result : bits(8) = truncate(raw_result, 8); + let cf : bits(1) = cf_spec8(raw_result); + let pf : bits(1) = pf_spec8(result); + let af : bits(1) = add_af_spec8(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : bits(1) = of_spec8(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_add_spec_2 : (bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_add_spec_2 (dst, src, input_rflags) = { + let raw_result : bits(17) = bits_of_int(unsigned(dst) + unsigned(src), 17); + let signed_raw_result : sbits(17) = bits_of_int(signed(dst) + signed(src), 17); + let result : bits(16) = truncate(raw_result, 16); + let cf : bits(1) = cf_spec16(raw_result); + let pf : bits(1) = pf_spec16(result); + let af : bits(1) = add_af_spec16(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : bits(1) = of_spec16(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_add_spec_4 : (bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_add_spec_4 (dst, src, input_rflags) = { + let raw_result : bits(33) = bits_of_int(unsigned(dst) + unsigned(src), 33); + let signed_raw_result : sbits(33) = bits_of_int(signed(dst) + signed(src), 33); + let result : bits(32) = truncate(raw_result, 32); + let cf : bits(1) = cf_spec32(raw_result); + let pf : bits(1) = pf_spec32(result); + let af : bits(1) = add_af_spec32(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : bits(1) = of_spec32(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_add_spec_8 : (bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_add_spec_8 (dst, src, input_rflags) = { + let raw_result : bits(65) = bits_of_int(unsigned(dst) + unsigned(src), 65); + let signed_raw_result : sbits(65) = bits_of_int(signed(dst) + signed(src), 65); + let result : bits(64) = truncate(raw_result, 64); + let cf : bits(1) = cf_spec64(raw_result); + let pf : bits(1) = pf_spec64(result); + let af : bits(1) = add_af_spec64(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : bits(1) = of_spec64(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_adc_spec_1 : (bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_adc_spec_1 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let raw_result : bits(9) = bits_of_int(unsigned(dst) + (unsigned(src) + unsigned(input_cf)), 9); + let signed_raw_result : sbits(9) = bits_of_int(signed(dst) + (signed(src) + unsigned(input_cf)), 9); + let result : bits(8) = truncate(raw_result, 8); + let cf : bits(1) = cf_spec8(raw_result); + let pf : bits(1) = pf_spec8(result); + let af : bits(1) = adc_af_spec8(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : bits(1) = of_spec8(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_adc_spec_2 : (bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_adc_spec_2 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let raw_result : bits(17) = bits_of_int(unsigned(dst) + (unsigned(src) + unsigned(input_cf)), 17); + let signed_raw_result : sbits(17) = bits_of_int(signed(dst) + (signed(src) + unsigned(input_cf)), 17); + let result : bits(16) = truncate(raw_result, 16); + let cf : bits(1) = cf_spec16(raw_result); + let pf : bits(1) = pf_spec16(result); + let af : bits(1) = adc_af_spec16(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : bits(1) = of_spec16(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_adc_spec_4 : (bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_adc_spec_4 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let raw_result : bits(33) = bits_of_int(unsigned(dst) + (unsigned(src) + unsigned(input_cf)), 33); + let signed_raw_result : sbits(33) = bits_of_int(signed(dst) + (signed(src) + unsigned(input_cf)), 33); + let result : bits(32) = truncate(raw_result, 32); + let cf : bits(1) = cf_spec32(raw_result); + let pf : bits(1) = pf_spec32(result); + let af : bits(1) = adc_af_spec32(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : bits(1) = of_spec32(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_adc_spec_8 : (bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_adc_spec_8 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let raw_result : bits(65) = bits_of_int(unsigned(dst) + (unsigned(src) + unsigned(input_cf)), 65); + let signed_raw_result : sbits(65) = bits_of_int(signed(dst) + (signed(src) + unsigned(input_cf)), 65); + let result : bits(64) = truncate(raw_result, 64); + let cf : bits(1) = cf_spec64(raw_result); + let pf : bits(1) = pf_spec64(result); + let af : bits(1) = adc_af_spec64(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : bits(1) = of_spec64(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/and_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/and_spec.sail new file mode 100644 index 000000000..9232d6ba2 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/and_spec.sail @@ -0,0 +1,56 @@ + +val gpr_and_spec_1 : (bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_and_spec_1 (dst, src, input_rflags) = { + let result : bits(8) = logand(dst, src)[7 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_and_spec_2 : (bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_and_spec_2 (dst, src, input_rflags) = { + let result : bits(16) = logand(dst, src)[15 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_and_spec_4 : (bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_and_spec_4 (dst, src, input_rflags) = { + let result : bits(32) = logand(dst, src)[31 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_and_spec_8 : (bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_and_spec_8 (dst, src, input_rflags) = { + let result : bits(64) = logand(dst, src)[63 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/application_level_memory.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/application_level_memory.sail new file mode 100644 index 000000000..30744e484 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/application_level_memory.sail @@ -0,0 +1,30 @@ + +/*! Recognizer of a canonical address +

In 64-bit mode, a linear address is considered to be in + canonical form if address bits 63 through to the most-significant implemented + bit by the microarchitecture ( represented by the constant + @ ( ' *max-linear-address-size* ' ) in these books ) are set to either all ones or + all zeros.

*/ +function canonical_address_p lin_addr = { + signed_byte_p(48, lin_addr) +} + +val rvm08 : sbits(48) -> bits(8) + +function rvm08 addr = { + if canonical_address_p(signed(addr)) then { + memi(sail_zero_extend(addr, 64)) + } else { + x86_model_error("rvm08") + } +} + +val wvm08 : (sbits(48), bits(8)) -> unit + +function wvm08 (addr, sailval) = { + if canonical_address_p(signed(addr)) then { + bang_memi(sail_zero_extend(addr, 64), sailval) + } else { + x86_model_error("wvm08") + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic.sail new file mode 100644 index 000000000..7517e70c4 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic.sail @@ -0,0 +1,282 @@ +$include "./arith_and_logic_spec.sail" +$include "./decoding_and_spec_utils.sail" + +/*! Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP, TEST: Addressing Mode = ( E, G ) +

Op/En = MR: [OP R/M, REG] or [OP E, G]

+ +

where @ ( ' E ' ) is the destination operand and @ ( ' G ' ) is the source + operand. Note that @ ( ' E ' ) stands for a general-purpose register or + memory operand specified by the @ ( ' ModRM.r/m ' ) field, and @ ( ' G ' ) + stands for a general-purpose register specified by the + @ ( ' ModRM.reg ' ) field.

+ + [OP R/M, REG] Flags Affected
+ 00, 01: ADD c p a z s o
+ 08, 09: OR p z s ( o and c cleared, a undefined )
+ 10, 11: ADC c p a z s o
+ 18, 19: SBB c p a z s o
+ 20, 21: AND p z s ( o and c cleared, a undefined )
+ 28, 29: SUB c p a z s o
+ 30, 31: XOR p z s ( o and c cleared, a undefined )
+ 38, 39: CMP c p a z s o
+ 84, 85: TEST p z s ( o and c cleared, a undefined )
*/ +val x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g : (range(0, 8), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g (operation, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP/TEST-E-G"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = 0b0 == truncate(logand(0x01, opcode), 1); + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let g : bits(64) = rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b10), rex_byte); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (e, increment_rip_by, e_addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let input_rflags : rflagsbits = rflags; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = gpr_arith_logic_spec(operand_size, operation, truncate(e, 64), g, input_rflags); + if operation == 8 | operation == 7 then () else { + x86_operand_to_reg_mem(proc_mode, operand_size, inst_ac?, false, sail_zero_extend(result, 128), seg_reg, e_addr, prefixes, rex_byte, r_m, mod_var, sib) + }; + write_user_rflags(output_rflags, undefined_flags); + write_iptr(proc_mode, temp_rip) +} + +/*! Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP: Addressing Mode = ( G, E ) +

Op/En = RM: [OP REG, R/M] or [OP G, E]

+ +

where @ ( ' G ' ) is the destination operand and @ ( ' E ' ) is the source + operand. Note that @ ( ' G ' ) stands for a general-purpose register + specified by the @ ( ' ModRM.reg ' ) field, and @ ( ' E ' ) stands for a + general-purpose register or memory operand specified by the + @ ( ' ModRM.r/m ' ) field.

+ + [OP REG, R/M] Flags Affected
+ 02, 03: ADD c p a z s o
+ 0A, 0B: OR p z s ( o and c cleared, a undefined )
+ 12, 13: ADC c p a z s o
+ 1A, 1B: SBB c p a z s o
+ 22, 23: AND p z s ( o and c cleared, a undefined )
+ 2A, 2B: SUB c p a z s o
+ 32, 33: XOR p z s ( o and c cleared, a undefined )
+ 3A, 3B: CMP c p a z s o
*/ +val x86_add_adc_sub_sbb_or_and_xor_cmp_g_e : (range(0, 8), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_add_adc_sub_sbb_or_and_xor_cmp_g_e (operation, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-G-E"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = 0b0 == truncate(logand(0x01, opcode), 1); + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let g : bits(64) = rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b10), rex_byte); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (e, increment_rip_by, e_addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let input_rflags : rflagsbits = rflags; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = gpr_arith_logic_spec(operand_size, operation, g, truncate(e, 64), input_rflags); + if operation == 8 then () else { + write_rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b10), result, rex_byte) + }; + write_user_rflags(output_rflags, undefined_flags); + write_iptr(proc_mode, temp_rip) +} + +/*! Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP, TEST: Addressing Mode = ( E, I ) +

Op/En = MI: [OP R/M, IMM] or [OP E, I]

+ +

where @ ( ' E ' ) is the destination operand and @ ( ' I ' ) is the source + operand. Note that @ ( ' E ' ) stands for a general-purpose register or + memory operand specified by the @ ( ' ModRM.r/m ' ) field, and @ ( ' I ' ) + stands for immediate data. All opcodes except those of TEST fall + under Group 1, and have opcode extensions ( ModR/M.reg field ) , as + per Table A-6 of the Intel Manuals, Vol. 2. The opcodes for TEST + fall under Unary Group 3, and also have opcode extensions.

+ + [OP R/M, IMM] Flags Affected
+ 80-83 ( 000 ) : ADD c p a z s o
+ 80-83 ( 001 ) : OR p z s ( o and c cleared, a undefined )
+ 80-83 ( 010 ) : ADC c p a z s o
+ 80-83 ( 011 ) : SBB c p a z s o
+ 80-83 ( 100 ) : AND p z s ( o and c cleared, a undefined )
+ 80-83 ( 101 ) : SUB c p a z s o
+ 80-83 ( 110 ) : XOR p z s ( o and c cleared, a undefined )
+ 80-83 ( 111 ) : CMP c p a z s o
+ F6-F7 ( 000 ) : TEST p z s ( o and c cleared, a undefined )
*/ +val x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i : (range(0, 8), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i (operation, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-E-I"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let e_byte_operand? : bool = opcode == 0x80 | opcode == 0x82 | opcode == 0xf6; + let e_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, e_byte_operand?, rex_byte, false, prefixes, false, false, false); + let imm_byte_operand? : bool = opcode == 0x80 | opcode == 0x82 | opcode == 0x83 | opcode == 0xf6; + let imm_size : {|1, 2, 4|} = check_range(1, 4, select_operand_size(proc_mode, imm_byte_operand?, rex_byte, true, prefixes, false, false, false)); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (e, increment_rip_by, e_addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, e_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, bits_of_int(imm_size, 3)); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let imm : bits(32) = truncate(rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), imm_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), 32); + let imm : int = loghead(ash(e_size, 3), binary_logext(ash(imm_size, 3), unsigned(imm))); + let temp_rip : sbits(49) = sail_sign_extend(add_to_iptr(proc_mode, temp_rip, bits_of_int(imm_size, 48)), 49); + let badlength? : option(int) = check_instruction_length(start_rip, truncate(temp_rip, 48), 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let input_rflags : rflagsbits = rflags; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = gpr_arith_logic_spec(e_size, operation, truncate(e, 64), bits_of_int(imm, 64), input_rflags); + if operation == 8 | operation == 7 then () else { + x86_operand_to_reg_mem(proc_mode, e_size, inst_ac?, false, sail_zero_extend(result, 128), seg_reg, e_addr, prefixes, rex_byte, r_m, mod_var, sib) + }; + write_user_rflags(output_rflags, undefined_flags); + write_iptr(proc_mode, truncate(temp_rip, 48)) +} + +/*! Operand Fetch and Execute for ADD, ADC, SUB, SBB, OR, AND, + XOR, CMP, TEST: Addressing Mode = ( rAX, I ) +

Op/En = I: [OP rAX, IMM] or [OP rAX, I]

+ +

where @ ( ' rAX ' ) is the destination operand and @ ( ' I ' ) is the + source operand. Note that @ ( ' rAX ' ) stands for AL/AX/EAX/RAX, + depending on the operand size, and @ ( ' I ' ) stands for immediate + data.

+ + [OP rAX, IMM] Flags Affected
+ 04, 05: ADD c p a z s o
+ 0C, 0D: OR p z s ( o and c cleared, a undefined )
+ 14, 15: ADC c p a z s o
+ 1C, 1D: SBB c p a z s o
+ 24, 25: AND p z s ( o and c cleared, a undefined )
+ 2C, 2D: SUB c p a z s o
+ 34, 35: XOR p z s ( o and c cleared, a undefined )
+ 3C, 3D: CMP c p a z s o
+ A8, A9: TEST p z s ( o and c cleared, a undefined )
*/ +val x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i : (range(0, 8), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i (operation, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-ADD/ADC/SUB/SBB/OR/AND/XOR/CMP-TEST-RAX-I"; + let byte_operand? : bool = 0x00 == logand(0x01, opcode); + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, true, prefixes, false, false, false); + let rax_size : {|1, 2, 4, 8|} = { + if logbitp(3, rex_byte) then 8 else { + operand_size + } + }; + let rax_var : bits(64) = rgfi_size(bits_of_int(rax_size, 4), 0x0, rex_byte); + let imm : bits(128) = rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), operand_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let (final_operand_size, imm) : ({|1, 2, 4, 8|}, bits(64)) = { + if not_bool(byte_operand?) & rax_size == 8 then { + (8, sail_sign_extend(truncate(imm, 32), 64)) + } else { + (operand_size, sail_zero_extend(truncate(imm, 32), 64)) + } + }; + let temp_rip : sbits(49) = sail_sign_extend(add_to_iptr(proc_mode, temp_rip, bits_of_int(operand_size, 48)), 49); + let badlength? : option(int) = check_instruction_length(start_rip, truncate(temp_rip, 48), 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let input_rflags : rflagsbits = rflags; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = gpr_arith_logic_spec(rax_size, operation, rax_var, imm, input_rflags); + if operation == 8 | operation == 7 then () else { + write_rgfi_size(bits_of_int(final_operand_size, 4), 0x0, result, rex_byte) + }; + write_user_rflags(output_rflags, undefined_flags); + write_iptr(proc_mode, truncate(temp_rip, 48)) +} + +val x86_inc_dec_fe_ff : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_inc_dec_fe_ff (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-INC/DEC-FE-FF"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let select_byte_operand : bool = 0x00 == logand(0x01, opcode); + let r_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, select_byte_operand, rex_byte, false, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (r_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, r_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let input_rflags : rflagsbits = rflags; + let old_cf : bits(1) = input_rflags[cf]; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = gpr_arith_logic_spec(r_mem_size, if reg == 0b000 then 0 else 4, truncate(r_mem, 64), 0x0000000000000001, input_rflags); + let output_rflags : rflagsbits = [output_rflags with cf = old_cf]; + write_user_rflags(output_rflags, undefined_flags); + x86_operand_to_reg_mem(proc_mode, r_mem_size, inst_ac?, false, sail_zero_extend(result, 128), seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} + +val x86_inc_dec_4x : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_inc_dec_4x (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-INC/DEC-4X"; + let operand_size : {|2, 4|} = check_range(2, 4, select_operand_size(proc_mode, false, 0x00, false, prefixes, false, false, false)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let reg : bits(3) = truncate(logand(0x07, opcode), 3); + let operand : bits(64) = rgfi_size(bits_of_int(operand_size, 4), sail_zero_extend(reg, 4), 0x00); + let input_rflags : rflagsbits = rflags; + let old_cf : bits(1) = input_rflags[cf]; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = gpr_arith_logic_spec(operand_size, if logbitp(3, opcode) then 4 else 0, operand, 0x0000000000000001, input_rflags); + let output_rflags : rflagsbits = [output_rflags with cf = old_cf]; + write_user_rflags(output_rflags, undefined_flags); + write_rgfi_size(bits_of_int(operand_size, 4), sail_zero_extend(reg, 4), result, 0x00); + write_iptr(proc_mode, temp_rip) +} + +val x86_not_neg_f6_f7 : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_not_neg_f6_f7 (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-NOT/NEG-F6-F7"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let select_byte_operand : bool = 0x00 == logand(0x01, opcode); + let r_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, select_byte_operand, rex_byte, false, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (r_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, r_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let input_rflags : rflagsbits = rflags; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = { + match reg { + 3 => gpr_arith_logic_spec(r_mem_size, 4, 0x0000000000000000, truncate(r_mem, 64), input_rflags), + _ => (sail_mask(64, trunc(r_mem_size, lognot(r_mem))), Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + } + }; + if reg == 0b011 then { + let cf : bits(1) = { + if 0x00000000000000000000000000000000 == r_mem then 0b0 else 0b1 + }; + let output_rflags : rflagsbits = [output_rflags with cf]; + write_user_rflags(output_rflags, undefined_flags) + }; + x86_operand_to_reg_mem(proc_mode, r_mem_size, inst_ac?, false, sail_zero_extend(result, 128), seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic_spec.sail new file mode 100644 index 000000000..04e999225 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/arith_and_logic_spec.sail @@ -0,0 +1,108 @@ +$include "./add_spec.sail" +$include "./sub_spec.sail" +$include "./or_spec.sail" +$include "./and_spec.sail" +$include "./xor_spec.sail" + +val gpr_arith_logic_spec_1 : ({|0, 1, 2, 3, 4, 5, 6, 7, 8|}, bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_arith_logic_spec_1 (operation, dst, src, input_rflags) = { + (match operation { + 0 => gpr_add_spec_1(dst, src, input_rflags), + 1 => gpr_or_spec_1(dst, src, input_rflags), + 2 => gpr_adc_spec_1(dst, src, input_rflags), + 3 => gpr_and_spec_1(dst, src, input_rflags), + 4 => gpr_sub_spec_1(dst, src, input_rflags), + 5 => gpr_xor_spec_1(dst, src, input_rflags), + 6 => gpr_sbb_spec_1(dst, src, input_rflags), + 7 => gpr_and_spec_1(dst, src, input_rflags), + 8 => gpr_sub_spec_1(dst, src, input_rflags), + _ => (0x00, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(8), rflagsbits, rflagsbits) +} + +val gpr_arith_logic_spec_2 : ({|0, 1, 2, 3, 4, 5, 6, 7, 8|}, bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_arith_logic_spec_2 (operation, dst, src, input_rflags) = { + (match operation { + 0 => gpr_add_spec_2(dst, src, input_rflags), + 1 => gpr_or_spec_2(dst, src, input_rflags), + 2 => gpr_adc_spec_2(dst, src, input_rflags), + 3 => gpr_and_spec_2(dst, src, input_rflags), + 4 => gpr_sub_spec_2(dst, src, input_rflags), + 5 => gpr_xor_spec_2(dst, src, input_rflags), + 6 => gpr_sbb_spec_2(dst, src, input_rflags), + 7 => gpr_and_spec_2(dst, src, input_rflags), + 8 => gpr_sub_spec_2(dst, src, input_rflags), + _ => (0x0000, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(16), rflagsbits, rflagsbits) +} + +val gpr_arith_logic_spec_4 : ({|0, 1, 2, 3, 4, 5, 6, 7, 8|}, bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_arith_logic_spec_4 (operation, dst, src, input_rflags) = { + (match operation { + 0 => gpr_add_spec_4(dst, src, input_rflags), + 1 => gpr_or_spec_4(dst, src, input_rflags), + 2 => gpr_adc_spec_4(dst, src, input_rflags), + 3 => gpr_and_spec_4(dst, src, input_rflags), + 4 => gpr_sub_spec_4(dst, src, input_rflags), + 5 => gpr_xor_spec_4(dst, src, input_rflags), + 6 => gpr_sbb_spec_4(dst, src, input_rflags), + 7 => gpr_and_spec_4(dst, src, input_rflags), + 8 => gpr_sub_spec_4(dst, src, input_rflags), + _ => (0x00000000, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(32), rflagsbits, rflagsbits) +} + +val gpr_arith_logic_spec_8 : ({|0, 1, 2, 3, 4, 5, 6, 7, 8|}, bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_arith_logic_spec_8 (operation, dst, src, input_rflags) = { + (match operation { + 0 => gpr_add_spec_8(dst, src, input_rflags), + 1 => gpr_or_spec_8(dst, src, input_rflags), + 2 => gpr_adc_spec_8(dst, src, input_rflags), + 3 => gpr_and_spec_8(dst, src, input_rflags), + 4 => gpr_sub_spec_8(dst, src, input_rflags), + 5 => gpr_xor_spec_8(dst, src, input_rflags), + 6 => gpr_sbb_spec_8(dst, src, input_rflags), + 7 => gpr_and_spec_8(dst, src, input_rflags), + 8 => gpr_sub_spec_8(dst, src, input_rflags), + _ => (0x0000000000000000, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(64), rflagsbits, rflagsbits) +} + +/*! Semantics of general-purpose arithmetic and logical instructions +

These instructions are:

+
    +
  • @ ( ' ADD ' )
  • +
  • @ ( ' ADC ' )
  • +
  • @ ( ' SUB ' )
  • +
  • @ ( ' SBB ' )
  • +
  • @ ( ' CMP ' )
  • +
  • @ ( ' OR ' )
  • +
  • @ ( ' AND ' )
  • +
  • @ ( ' XOR ' )
  • +
  • @ ( ' TEST ' )
  • +
+ + @ ( def gpr-arith/logic-spec ) */ +val gpr_arith_logic_spec : ({|1, 2, 4, 8|}, {|0, 1, 2, 3, 4, 5, 6, 7, 8|}, bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_arith_logic_spec (operand_size, operation, dst, src, input_rflags) = { + (match operand_size { + 1 => { + let (elem0, elem1, elem2) : (bits(8), rflagsbits, rflagsbits) = gpr_arith_logic_spec_1(operation, truncate(dst, 8), truncate(src, 8), input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 2 => { + let (elem0, elem1, elem2) : (bits(16), rflagsbits, rflagsbits) = gpr_arith_logic_spec_2(operation, truncate(dst, 16), truncate(src, 16), input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 4 => { + let (elem0, elem1, elem2) : (bits(32), rflagsbits, rflagsbits) = gpr_arith_logic_spec_4(operation, truncate(dst, 32), truncate(src, 32), input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + _ => gpr_arith_logic_spec_8(operation, dst, src, input_rflags) + }) : (bits(64), rflagsbits, rflagsbits) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/auxiliary.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/auxiliary.sail new file mode 100644 index 000000000..8b0f846a6 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/auxiliary.sail @@ -0,0 +1,36 @@ + +val n64_bit_compute_mandatory_prefix_for_two_byte_opcode : (bits(8), prefixes) -> bits(8) + +function n64_bit_compute_mandatory_prefix_for_two_byte_opcode (opcode, prefixes) = { + let rep_pfx : bits(8) = prefixes[rep]; + if not_bool(rep_pfx == 0x00) then { + if rep_pfx == 0xf3 & [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true, true, false, false, false, true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, true, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)] | rep_pfx == 0xf2 & [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, true, true, true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)] then { + rep_pfx + } else 0x00 + } else { + let opr_pfx : bits(8) = prefixes[opr]; + if not_bool(opr_pfx == 0x00) then { + if [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)] then { + opr_pfx + } else 0x00 + } else 0x00 + } +} + +val n32_bit_compute_mandatory_prefix_for_two_byte_opcode : (bits(8), prefixes) -> bits(8) + +function n32_bit_compute_mandatory_prefix_for_two_byte_opcode (opcode, prefixes) = { + let rep_pfx : bits(8) = prefixes[rep]; + if not_bool(rep_pfx == 0x00) then { + if rep_pfx == 0xf3 & [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, true, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)] | rep_pfx == 0xf2 & [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, true, true, true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)] then { + rep_pfx + } else 0x00 + } else { + let opr_pfx : bits(8) = prefixes[opr]; + if not_bool(opr_pfx == 0x00) then { + if [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)] then { + opr_pfx + } else 0x00 + } else 0x00 + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/conditional.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/conditional.sail new file mode 100644 index 000000000..004fea7d3 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/conditional.sail @@ -0,0 +1,148 @@ + +val jcc_cmovcc_setcc_spec : bits(8) -> bool + +function jcc_cmovcc_setcc_spec opcode = { + let low_nibble : bits(4) = truncate(logand(opcode, 0x0f), 4); + (match low_nibble { + 0 => 0b1 == (let rflags_var : rflagsbits = rflags in rflags_var[of]), + 1 => 0b0 == (let rflags_var : rflagsbits = rflags in rflags_var[of]), + 2 => 0b1 == (let rflags_var : rflagsbits = rflags in rflags_var[cf]), + 3 => 0b0 == (let rflags_var : rflagsbits = rflags in rflags_var[cf]), + 4 => 0b1 == (let rflags_var : rflagsbits = rflags in rflags_var[zf]), + 5 => 0b0 == (let rflags_var : rflagsbits = rflags in rflags_var[zf]), + 6 => 0b1 == (let rflags_var : rflagsbits = rflags in rflags_var[cf]) | 0b1 == (let rflags_var : rflagsbits = + rflags + in + rflags_var[zf]), + 7 => 0b0 == (let rflags_var : rflagsbits = rflags in rflags_var[cf]) & 0b0 == (let rflags_var : rflagsbits = + rflags + in + rflags_var[zf]), + 8 => 0b1 == (let rflags_var : rflagsbits = rflags in rflags_var[sf]), + 9 => 0b0 == (let rflags_var : rflagsbits = rflags in rflags_var[sf]), + 10 => 0b1 == (let rflags_var : rflagsbits = rflags in rflags_var[pf]), + 11 => 0b0 == (let rflags_var : rflagsbits = rflags in rflags_var[pf]), + 12 => not_bool((let rflags_var : rflagsbits = rflags in rflags_var[sf]) == (let rflags_var : rflagsbits = rflags + in + rflags_var[of])), + 13 => (let rflags_var : rflagsbits = rflags in rflags_var[sf]) == (let rflags_var : rflagsbits = rflags in + rflags_var[of]), + 14 => 0b1 == (let rflags_var : rflagsbits = rflags in rflags_var[zf]) | not_bool((let rflags_var : rflagsbits = + rflags + in + rflags_var[sf]) == (let rflags_var : rflagsbits = rflags in rflags_var[of])), + 15 => 0b0 == (let rflags_var : rflagsbits = rflags in rflags_var[zf]) & (let rflags_var : rflagsbits = rflags in + rflags_var[sf]) == (let rflags_var : rflagsbits = rflags in rflags_var[of]), + _ => false + }) : bool +} + +val x86_one_byte_jcc : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_one_byte_jcc (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-ONE-BYTE-JCC"; + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b001); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let branch_cond : bool = jcc_cmovcc_setcc_spec(opcode); + if branch_cond then { + let rel8 : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(1 + signed(rel8), 48)); + write_iptr(proc_mode, next_rip) + } else { + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + write_iptr(proc_mode, next_rip) + } +} + +val x86_two_byte_jcc : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_two_byte_jcc (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-TWO-BYTE-JCC"; + let offset_size : {|1, 2, 4|} = check_range(0, 4, select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, true, true)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, bits_of_int(offset_size, 3)); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let branch_cond : bool = jcc_cmovcc_setcc_spec(opcode); + if branch_cond then { + let offset : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), offset_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(offset_size + signed(offset), 48)); + write_iptr(proc_mode, next_rip) + } else { + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(offset_size, 48)); + write_iptr(proc_mode, next_rip) + } +} + +val x86_jrcxz : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_jrcxz (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-JRCXZ"; + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b001); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let p4? : bool = 0x67 == prefixes[adr]; + let register_size : address_size = select_address_size(proc_mode, Some(prefixes)); + let branch_cond : bool = rgfi_size(bits_of_int(register_size, 4), 0x1, rex_byte) == 0x0000000000000000; + if branch_cond then { + let rel8 : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(1 + signed(rel8), 48)); + write_iptr(proc_mode, next_rip) + } else { + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + write_iptr(proc_mode, next_rip) + } +} + +val x86_cmovcc : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_cmovcc (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-CMOVCC"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false); + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let branch_cond : bool = jcc_cmovcc_setcc_spec(opcode); + if branch_cond then { + write_rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b10), truncate(reg_mem, 64), rex_byte) + } else if operand_size == 4 & (in_64bit_mode(proc_mode) | in_compatibility_mode(proc_mode)) then { + wr32(reg_index(reg, rex_byte, 0b10), rr32(reg_index(reg, rex_byte, 0b10))) + } else (); + write_iptr(proc_mode, temp_rip) +} + +val x86_setcc : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_setcc (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-SETCC"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000) + } + }; + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let branch_cond : bool = jcc_cmovcc_setcc_spec(opcode); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let sailval : {|0, 1|} = { + if branch_cond then 1 else 0 + }; + x86_operand_to_reg_mem(proc_mode, 1, inst_ac?, false, bits_of_int(sailval, 128), seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/config.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/config.sail new file mode 100644 index 000000000..bb0c24a46 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/config.sail @@ -0,0 +1,33 @@ +$ifndef __X86_CONFIG +$define __X86_CONFIG + +function clause __SetConfig("rip", value) = write_rip(get_slice_int(48, value, 0)) +function clause __SetConfig("rax", value) = write_rgfi(0, get_slice_int(64, value, 0)) +function clause __SetConfig("rbx", value) = write_rgfi(3, get_slice_int(64, value, 0)) +function clause __SetConfig("rcx", value) = write_rgfi(1, get_slice_int(64, value, 0)) +function clause __SetConfig("rdx", value) = write_rgfi(2, get_slice_int(64, value, 0)) +function clause __SetConfig("rsi", value) = write_rgfi(6, get_slice_int(64, value, 0)) +function clause __SetConfig("rdi", value) = write_rgfi(7, get_slice_int(64, value, 0)) +function clause __SetConfig("rsp", value) = write_rgfi(4, get_slice_int(64, value, 0)) +function clause __SetConfig("rbp", value) = write_rgfi(5, get_slice_int(64, value, 0)) +function clause __SetConfig("r8", value) = write_rgfi(8, get_slice_int(64, value, 0)) +function clause __SetConfig("r9", value) = write_rgfi(9, get_slice_int(64, value, 0)) +function clause __SetConfig("r10", value) = write_rgfi(10, get_slice_int(64, value, 0)) +function clause __SetConfig("r11", value) = write_rgfi(11, get_slice_int(64, value, 0)) +function clause __SetConfig("r12", value) = write_rgfi(12, get_slice_int(64, value, 0)) +function clause __SetConfig("r13", value) = write_rgfi(13, get_slice_int(64, value, 0)) +function clause __SetConfig("r14", value) = write_rgfi(14, get_slice_int(64, value, 0)) +function clause __SetConfig("r15", value) = write_rgfi(15, get_slice_int(64, value, 0)) +function clause __SetConfig("rflags", value) = { + rflags = Mk_rflagsbits(get_slice_int(32, value, 0)); + if log_register_writes then log_rflags_write() +} +function clause __SetConfig("cr4", value) = { ctrs[4] = get_slice_int(64, value, 0) } +function clause __SetConfig("app_view", value) = { app_view = (value != 0) } +function clause __SetConfig("log_register_writes", value) = { log_register_writes = (value != 0) } + +// TODO: This should print information about __SetConfig to stderr. +val __ListConfig : unit -> unit +function __ListConfig () = () + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/decoding_and_spec_utils.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/decoding_and_spec_utils.sail new file mode 100644 index 000000000..4111d417f --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/decoding_and_spec_utils.sail @@ -0,0 +1,963 @@ +$include "./other_non_det.sail" + +/*! Operations to manipulate instruction pointers. +Read the instruction pointer from the register RIP, EIP, or IP. +

+ In 64-bit mode, a 64-bit instruction pointer is read from the full RIP. + Since, in the model, this is a 48-bit signed integer, + this function returns a 48-bit signed integer. +

+

+ In 32-bit mode, a 32-bit or 16-bit instruction pointer is read from + EIP ( i.e. the low 32 bits of RIP ) + or IP ( i.e. the low 16 bits of RIP ) , + based on the CS.D bit, + i.e. the D bit of the current code segment descriptor. + Either way, this function returns an unsigned 32-bit or 16-bit integer, + which is also a signed 48-bit integer. +

+

+ See AMD manual, Oct ' 13, Vol. 1, Sec. 2.2.4 and Sec. 2.5. + AMD manual, Apr ' 16, Vol. 2, Sec 4.7.2., + and Intel manual, Mar ' 17, Vol. 1, Sec. 3.6. +

+

+ In 32-bit mode, the address-size override prefix ( if present ) + should not affect the instruction pointer size. + It does not seem to make sense + to change the instruction pointer size on a per-instruction basis. +

*/ +val read_iptr : proc_mode -> sbits(48) + +function read_iptr proc_mode = { + let iptr : sbits(48) = read_rip(); + if in_64bit_mode(proc_mode) then { + iptr + } else if in_compatibility_mode(proc_mode) then { + let cs_attr : bits(16) = seg_hidden_attrs[1]; + let cs_d : bits(1) = Mk_code_segment_descriptor_attributesbits(cs_attr)[d]; + if cs_d == 0b1 then { + sail_zero_extend(truncate(iptr, 32), 48) + } else { + sail_zero_extend(sail_zero_extend(truncate(iptr, 16), 32), 48) + } + } else 0x000000000000 +} + +/*! Add a specified amount to an instruction pointer. +

+ The amount may be positive ( increment ) or negative ( decrement ) . + This just calculates the new instruction pointer value, + without storing it into the register RIP, EIP, or IP. + The starting value is the result of @ ( tsee read-*ip ) + or a previous invocation of @ ( tsee add-to-*ip ) . +

+

+ In 64-bit mode, we check whether the result is a canonical address; + in 32-bit mode, we check whether the result is within the segment limit. + If these checks are not satisfied, + this function returns an error flag ( and 0 as incremented address ) , + which causes the x86 model to stop execution with an error. + It is not clear whether these checks should be performed + when the instruction pointer is incremented + or when an instruction byte is eventually accessed; + the Intel and AMD manuals seem unclear in this respect. + But since the failure of these checks stops execution with an error, + and it is in a way always ` ` safe ' ' to stop execution with an error + ( in the sense that the model provides no guarantees when this happens ) , + for now we choose to perform these checks here. +

+

+ Note that a code segment is never expand-down, + so the valid effective addresses are always between 0 and the segment limit + ( cf. @ ( tsee segment-base-and-bounds ) ) . +

*/ +val add_to_iptr : (proc_mode, sbits(48), sbits(48)) -> sbits(48) + +function add_to_iptr (proc_mode, iptr, delta) = { + let iptr_plus_delta : sbits(49) = bits_of_int(signed(iptr) + signed(delta), 49); + if in_64bit_mode(proc_mode) then { + if canonical_address_p(signed(iptr_plus_delta)) then { + truncate(iptr_plus_delta, 48) + } else { + x86_model_error(":NON-CANONICAL-INSTRUCTION-POINTER") + } + } else if in_compatibility_mode(proc_mode) then { + let cs_limit : bits(32) = loghead(32, seg_hidden_limits[1]); + if 0 <= signed(iptr_plus_delta) & signed(iptr_plus_delta) <= unsigned(cs_limit) then { + truncate(sail_zero_extend(truncate(iptr_plus_delta, 32), 49), 48) + } else { + x86_model_error(":OUT-OF-SEGMENT-INSTRUCTION-POINTER") + } + } else { + x86_model_error(":UNIMPLEMENTED-PROC-MODE") + } +} + +/*! Write an instruction pointer into the register RIP, EIP, or IP. +

+ In 64-bit mode, a 64-bit instruction pointer is written into the full RIP. + Since, in the model, this is a 48-bit signed integer, + this function consumes a 48-bit signed integer. +

+

+ In 32-bit mode, the instruction pointer is 32 or 16 bits + based on the CS.D bit, i.e. the D bit of the current code segment descriptor. + In these cases, the argument to this function should be + a 32-bit or 16-bit unsigned integer, which is also a 48-bit signed integer. +

+

+ See AMD manual, Oct ' 13, Vol. 1, Sec. 2.2.4 and Sec. 2.5. + AMD manual, Apr ' 16, Vol. 2, Sec 4.7.2., + and Intel manual, Mar ' 17, Vol. 1, Sec. 3.6. +

+

+ According to Intel manual, Mar ' 17, Vol. 1, Table 3-1, + it seems that + when writing a 32-bit instruction pointer ( EIP ) + the high 32 bits of RIP should be set to 0, + and when writing a 16-bit instruction pointer ( IP ) + the high 48 bits of RIP should be left unmodified; + since in our model the RIP is 48 bits, + the above applies to the high 16 and 32 bits, respectively. + The pseudocode for the JMP instruction in Intel manual, Mar ' 17, Vol. 2 + shows an assignment @ ( ' EIP <- tempEIP AND 0000FFFFh ' ) for the 16-bit case, + which seems to imply that + the high 32 ( or 16, in our model ) bits are left unmodified + and the high 16 bits of EIP are set to 0, + which would contradict Table 3-1; + the pseudocode for some other instructions + that directly write the instruction pointer ( e.g. RET and Jcc ) + show similar assignments. + However, it is possible that this assignment has a typo and should be + @ ( ' IP <- tempEIP AND 0000FFFFh ' ) instead, + which would be consistent with Table 3-1. + But we also note that the pseudocode for the JMP instruction + shows an assignment @ ( ' EIP <- tempEIP ' ) for the 32-bit case, + which seems to imply that + the high 32 ( or 16, in our model ) bits are left unmodified, + which would contradict Table 3-1. + The AMD manuals do not show pseudocode for these instructions, + and AMD manual, Oct ' 13, Vol. 1, Fig. 2-10 + ( which is somewhat analogous to Intel ' s Table 3-1 ) + shows the high bits simply grayed out; + so the AMD manuals do not provide disambiguation help. + It is also possible that Table 3-1 has a typo and should say + that a 16-bit instruction pointer is zero-extended, + but that is not quite consistent with the pseudocode assignments to EIP, + which seem to imply that the high bits are untouched. + Table 3-1 is under a section titled + ` Address Calculation in 64-Bit Mode ' , + which may suggest that the table may not apply to 32-bit mode, + but then it is not clear how it would just apply to 64-bit mode. + For now, we decide to have this function follow Intel ' s Table 3-1, + but we may revise that if we manage to resolve these ambiguities. + We also note that Intel ' s Table 3-1 is consistent with the way in which + 32-bit and 16-bit values are written to general-purpose registers + ( even though RIP/EIP/IP is not a general-purpose register ) ; + see @ ( tsee wr32 ) and @ ( tsee wr16 ) . +

+

+ This function should be always called + with an instruction pointer of the right type + ( 48-bit signed, 32-bit unsigned, or 16-bit unsigned ) + based on the mode and code segment. + We may add a guard to ensure that in the future, + but for now in the code below + we coerce the instruction pointer to 32 and 16 bits as appropriate, + to verify guards; + these coercions are expected not to change + the argument instruction pointer. +

*/ +val write_iptr : (proc_mode, sbits(48)) -> unit + +function write_iptr (proc_mode, iptr) = { + if in_64bit_mode(proc_mode) then { + write_rip(iptr) + } else if in_compatibility_mode(proc_mode) then { + let cs_attr : bits(16) = seg_hidden_attrs[1]; + let cs_d : bits(1) = Mk_code_segment_descriptor_attributesbits(cs_attr)[d]; + if cs_d == 0b1 then { + write_rip(sail_zero_extend(truncate(iptr, 32), 48)) + } else { + let rip_var : sbits(48) = read_rip(); + let rip_new : sbits(48) = changeSlice(rip_var, 0, 16, truncate(iptr, 16)); + write_rip(rip_new) + } + } else () +} + +/*! Operations to manipulate stack pointers. +Read the stack pointer from the register RSP, ESP, or SP. +

+ In 64-bit mode, a 64-bit stack pointer is read from the full RSP. + Since, in the model, this is a 64-bit signed integer, + this function returns a 64-bit signed integer. +

+

+ In 32-bit mode, a 32-bit or 16-bit stack pointer is read from + ESP ( i.e. the low 32 bits of RSP ) + or SP ( i.e. the low 16 bits of RSP ) , + based on the SS.B bit, + i.e. the B bit of the current stack segment register. + Either way, this function returns an unsigned 32-bit or 16-bit integer, + which is also a signed 64-bit integer. +

+

+ See Intel manual, Mar ' 17, Vol. 1, Sec. 6.2.3 and Sec. 6.2.5, + and AMD manual, Apr ' 16, Vol. 2, Sec 2.4.5 and Sec. 4.7.3. + The actual size of the value returned by this function + is @ ( ' StackAddrSize ' ) , + introduced in Intel manual, Mar ' 17, Vol. 2, Sec. 3.1.1.9. +

+

+ In 32-bit mode, the address-size override prefix ( if present ) + should not affect the stack address size. + It does not seem to make sense + to change the stack address size on a per-instruction basis. +

*/ +val read_sptr : proc_mode -> sbits(64) + +function read_sptr proc_mode = { + let sptr : sbits(64) = rgfi(4); + if in_64bit_mode(proc_mode) then { + sptr + } else if in_compatibility_mode(proc_mode) then { + let ss_attr : bits(16) = seg_hidden_attrs[2]; + let ss_b : bits(1) = Mk_data_segment_descriptor_attributesbits(ss_attr)[d_b]; + if ss_b == 0b1 then { + sail_zero_extend(truncate(sptr, 32), 64) + } else { + sail_zero_extend(sail_zero_extend(truncate(sptr, 16), 32), 64) + } + } else 0x0000000000000000 +} + +/*! Add a specified amount to a stack pointer. +

+ The amount may be positive ( increment ) or negative ( decrement ) . + This just calculates the new stack pointer value, + without storing it into the register RSP, ESP, or SP. + The starting value is the result of @ ( tsee read-*sp ) + or a previous invocation of @ ( tsee add-to-*sp ) . +

+

+ The increment or decrement is modular: + 64 bits in 64-bit mode, + and either 32 or 16 bits in 32-bit mode ( depending on the SS.B bit ) . + Since our model uses signed 64-bit addresses, we use @ ( tsee i64 ) for them, + while we use @ ( tsee n32 ) or @ ( tsee n16 ) for 32-bit and 16-bit addresses. +

+

+ In 64-bit mode, we check whether the result is a canonical address; + in 32-bit mode, we check whether the result is within the segment limit. + If these checks are not satisfied, + this function returns an error flag ( and 0 as new pointer ) , + which causes the x86 model to stop execution with an error. + It is not clear whether these checks should be performed + when the stack pointer is updated, + or when the stack is eventually accessed through the updated pointer; + the Intel and AMD manuals seem unclear in this respect. + But since the failure of these checks stops execution with an error, + and it is in a way always ` ` safe ' ' to stop execution with an error + ( in the sense that the model provides no guarantees when this happens ) , + for now we choose to perform these checks here. +

+

+ Note that a stack segment may be expand-down or expand-up + ( see Intel manual, Mar ' 17, Vol. 3, Sec. 3.4.5.1 ) , + so the checks need to cover these two cases. + See @ ( tsee segment-base-and-bounds ) and @ ( tsee ea-to-la ) . +

*/ +val add_to_sptr : (proc_mode, sbits(64), sbits(64)) -> sbits(64) + +function add_to_sptr (proc_mode, sptr, delta) = { + let sptr_plus_delta : sbits(65) = bits_of_int(signed(sptr) + signed(delta), 65); + if in_64bit_mode(proc_mode) then { + let sptr_plus_delta : sbits(64) = truncate(sptr_plus_delta, 64); + if canonical_address_p(signed(sptr_plus_delta)) then { + sptr_plus_delta + } else { + x86_model_error(":NON-CANONICAL-STACK-ADDRESS") + } + } else if in_compatibility_mode(proc_mode) then { + let ss_limit : bits(32) = seg_hidden_limits[2]; + let ss_attr : bits(16) = seg_hidden_attrs[2]; + let ss_b : bits(1) = Mk_data_segment_descriptor_attributesbits(ss_attr)[d_b]; + let ss_e : bits(1) = Mk_data_segment_descriptor_attributesbits(ss_attr)[e]; + let ss_lower : int = { + if ss_e == 0b1 then { + 1 + unsigned(ss_limit) + } else 0 + }; + let ss_upper : bits(32) = { + if ss_e == 0b1 then { + if ss_b == 0b1 then 0xffffffff else 0x0000ffff + } else { + ss_limit + } + }; + let sptr_plus_delta : bits(32) = { + if ss_b == 0b1 then { + truncate(sptr_plus_delta, 32) + } else { + sail_zero_extend(truncate(sptr_plus_delta, 16), 32) + } + }; + if not_bool(ss_lower <= unsigned(sptr_plus_delta) & unsigned(sptr_plus_delta) <= unsigned(ss_upper)) then x86_model_error(":OUT-OF-SEGMENT-STACK-ADDRESS"); + sail_zero_extend(sptr_plus_delta, 64) + } else { + x86_model_error(":UNIMPLEMENTED-PROC-MODE") + } +} + +/*! Write a stack pointer into the register RSP, ESP, or SP. +

+ In 64-bit mode, a 64-bit stack pointer is written into the full RSP. + Since, in the model, this is a 64-bit signed integer, + this function consumes a 64-bit signed integer. +

+

+ In 32-bit mode, the stack pointer is 32 or 16 bits based on the SS.B bit, + i.e. the B bit of the current stack segment descriptor. + In these cases, the argument to this function should be + a 32-bit or 16-bit unsigned integer, which is also a 64-bit signed integer. +

+

+ See Intel manual, Mar ' 17, Vol. 1, Sec. 6.2.3 and Sec. 6.2.5, + and AMD manual, Apr ' 16, Vol. 2, Sec 2.4.5 and Sec. 4.7.3. + The actual size of the value consumed by this function + should be @ ( ' StackAddrSize ' ) , + introduced in Intel manual, Mar ' 17, Vol. 2, Sec. 3.1.1.9. +

+

+ The pseudocode of stack instructions like PUSH + in Intel manual, Mar ' 17, Vol. 2 + show assignments of the form + @ ( ' RSP <- ... ' ) , @ ( ' ESP <- ... ' ) , and @ ( ' SP <- ... ' ) + based on the stack address size. + This may suggests that + when the stack address size is 32 + the assignment to ESP leaves the high 32 bits of RSP unchanged, + and when the stack address size is 16 + the assignment to SP leaves the high 48 bits of RSP unchanged. + However, + as explained in the documentation of @ ( tsee wr32 ) and @ ( tsee wr16 ) , + normally writing to the low 32 bits of a general-purpose register + ( which RSP/ESP/SP is ) zeros the high 32 bits, + while writing the low 16 bits leaves the high 48 bits unchanged. + Thus, we follow this requirement also when writing RSP/ESP/SP implicitly, + via stack manipulation instructions like PUSH that use + this @ ( tsee write-*sp ) function to update the stack pointer register. +

+

+ This function should be always called + with a stack pointer of the right type + ( 64-bit signed, 32-bit unsigned, or 16-bit unsigned ) + based on the stack address size. + We may add a guard to ensure that in the future, + but for now in the code below + we coerce the stack pointer to 32 and 16 bits as appropriate, + to verify guards; + these coercions are expected not to change the argument stack pointer. +

*/ +val write_sptr : (proc_mode, sbits(64)) -> unit + +function write_sptr (proc_mode, sptr) = { + if in_64bit_mode(proc_mode) then { + write_rgfi(4, sptr) + } else if in_compatibility_mode(proc_mode) then { + let ss_attr : bits(16) = seg_hidden_attrs[2]; + let ss_b : bits(1) = Mk_data_segment_descriptor_attributesbits(ss_attr)[d_b]; + if ss_b == 0b1 then { + write_rgfi(4, sail_zero_extend(truncate(sptr, 32), 64)) + } else { + let rsp_var : sbits(64) = rgfi(4); + let rsp_new : sbits(64) = changeSlice(rsp_var, 0, 16, truncate(sptr, 16)); + write_rgfi(4, rsp_new) + } + } else () +} + +/*! Computing effective address using ModR/M, SIB bytes, and + displacement bytes present in the instruction +Calculates effective address when SIB is present. +

Source: Intel Vol. 2A, Table 2-3.

+

Also see Intel Vol. 2A, Table 2-2 and Figure 2-6.

+

In 64-bit mode, + we use @ ( ' rgfi ' ) to read bases as signed linear addresses, + which encode canonical linear addresses, + which are also effective addresses in 64-bit mode. + In 32-bit mode, + we use @ ( ' rr32 ' ) to read bases as unsigned effective addresses.

+

In 64-bit mode, + we use @ ( ' rgfi ' ) to read indices as signed 64-bit values. + In 32-bit mode, + we limit them to signed 32-bit values.

+

Note that, in 32-bit mode, + we call this function only when the address size is 32 bits. + When the address size is 16 bits, there is no SIB byte: + See Intel Vol. 2 Table 2-1.

+

The displacement is read as a signed values: + see AMD manual, Dec ' 17, Volume 3, Section 1.5.

*/ +val x86_effective_addr_from_sib : (proc_mode, sbits(48), bits(8), bits(2), sib) -> (int, sbits(64), {|0, 1, 4|}) + +function x86_effective_addr_from_sib (proc_mode, temp_rip, rex_byte, mod_var, sib) = { + let b : bits(3) = sib[base]; + let check_alignment? : bool = false; + let (base, displacement, nrip_bytes) : (sbits(64), sbits(64), {|0, 1, 4|}) = { + match mod_var { + 0 => { + if b == 0b101 then { + let dword : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 4, sail_sign_extend(temp_rip, 64), None(), 1, ":X", check_alignment?, false); + (0x0000000000000000, dword, 4) + } else { + (if in_64bit_mode(proc_mode) then { + rgfi(unsigned(reg_index(b, rex_byte, 0b00))) + } else { + sail_zero_extend(rr32(sail_zero_extend(b, 4)), 64) + }, 0x0000000000000000, 0) + } + }, + 1 => { + let byte : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", check_alignment?, false); + (if in_64bit_mode(proc_mode) then { + rgfi(unsigned(reg_index(b, rex_byte, 0b00))) + } else { + sail_zero_extend(rr32(sail_zero_extend(b, 4)), 64) + }, byte, 1) + }, + 2 => { + let dword : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 4, sail_sign_extend(temp_rip, 64), None(), 1, ":X", check_alignment?, false); + (if in_64bit_mode(proc_mode) then { + rgfi(unsigned(reg_index(b, rex_byte, 0b00))) + } else { + sail_zero_extend(rr32(sail_zero_extend(b, 4)), 64) + }, dword, 4) + }, + _ => x86_model_error("mod-can-not-be-anything-other-than-0-1-or-2") + } + }; + let ix : bits(4) = reg_index(sib[index], rex_byte, 0b01); + let index : sbits(64) = { + match ix { + 4 => 0x0000000000000000, + _ => { + if in_64bit_mode(proc_mode) then { + rgfi(unsigned(ix)) + } else { + sail_sign_extend(truncate(rgfi(unsigned(ix)), 32), 64) + } + } + } + }; + let scale : bits(2) = sib[scale]; + let scaled_index : int = ash(signed(index), unsigned(scale)); + let effective_addr : int = signed(base) + scaled_index; + (effective_addr, displacement, nrip_bytes) +} + +/*! Calculate the displacement for + 16-bit effective address calculation. +

+ This is according to Intel manual, Mar ' 17, Vol. 2, Table 2-1. +

+

+ The displacement is absent ( i.e. 0 ) when Mod is 00b. + An exception to this is when R/M is 110b, + in which case there is a 16-bit displacement that is added to the index. + This case is not handled by this function, + but is instead handled in + its caller function @ ( tsee x86-effective-addr-16 ) . +

+

+ The displacement is a signed 8-bit value when Mod is 01b. + The displacement is a signed 16-bit value when Mod is 10b. + This function is not called when Mod is 11b. +

+

+ If an error occurs when trying to read the displacement, + 0 is returned as displacement, + but the caller ignores the returned displacement given the error. +

+

+ This function is called only when the address size is 16 bits. +

*/ +val x86_effective_addr_16_disp : (proc_mode, sbits(48), bits(2)) -> (sbits(64), {|0, 1, 2|}) + +function x86_effective_addr_16_disp (proc_mode, temp_rip, mod_var) = { + (match mod_var { + 0 => (0x0000000000000000, 0), + 1 => { + let byte : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + (byte, 1) + }, + 2 => { + let word : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 2, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + (word, 2) + }, + _ => x86_model_error("mod-value-wrong") + }) : (sbits(64), {|0, 1, 2|}) +} + +/*! Effective address calculation with 16-bit addressing. +

+ This is according to Intel manual, Mar ' 17, Vol. 2, Table 2-1. +

+

+ We assume that the additions in the table are modular, + even though the documentation is not clear in that respect. + So we simply apply @ ( ' n16 ' ) to the exact integer result. + This is in analogy to the use of @ ( ' n32 ' ) + for effective address calculation in 64-bit mode + when there is an address size override prefix: + see @ ( tsee x86-effective-addr-32/64 ) . +

*/ +val x86_effective_addr_16 : (proc_mode, sbits(48), bits(3), bits(2)) -> (bits(16), {|0, 1, 2|}) + +function x86_effective_addr_16 (proc_mode, temp_rip, r_m, mod_var) = { + (match r_m { + 0 => { + let bx : bits(16) = rr16(0x3); + let si : bits(16) = rr16(0x6); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(bx) + (unsigned(si) + signed(disp)), 16), increment_rip_by) + }, + 1 => { + let bx : bits(16) = rr16(0x3); + let di : bits(16) = rr16(0x7); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(bx) + (unsigned(di) + signed(disp)), 16), increment_rip_by) + }, + 2 => { + let bp : bits(16) = rr16(0x5); + let si : bits(16) = rr16(0x6); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(bp) + (unsigned(si) + signed(disp)), 16), increment_rip_by) + }, + 3 => { + let bp : bits(16) = rr16(0x5); + let di : bits(16) = rr16(0x7); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(bp) + (unsigned(di) + signed(disp)), 16), increment_rip_by) + }, + 4 => { + let si : bits(16) = rr16(0x6); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(si) + signed(disp), 16), increment_rip_by) + }, + 5 => { + let di : bits(16) = rr16(0x7); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(di) + signed(disp), 16), increment_rip_by) + }, + 6 => { + (match mod_var { + 0 => { + let disp : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 2, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + (truncate(disp, 16), 2) + }, + _ => { + let bp : bits(16) = rr16(0x5); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(bp) + signed(disp), 16), increment_rip_by) + } + }) : (bits(16), {|0, 1, 2|}) + }, + 7 => { + let bx : bits(16) = rr16(0x3); + let (disp, increment_rip_by) : (sbits(64), {|0, 1, 2|}) = x86_effective_addr_16_disp(proc_mode, temp_rip, mod_var); + (bits_of_int(unsigned(bx) + signed(disp), 16), increment_rip_by) + }, + _ => x86_model_error(":R/M-OUT-OF-RANGE") + }) : (bits(16), {|0, 1, 2|}) +} + +/*! Effective address calculation with 32-bit and 64-bit addressing. +

Note that we do not add segment bases + ( such as the FS and GS bases, if FS and GS overrides are present ) + to the effective address computed in this function. + Addition of those segment base addresses is a part of the + segmentation process --- we handle that in the function @ ( see + ea-to-la ) that performs the segment address translation.

+ +

Quoting from Intel Vol 1, Sec 3.3.7:

+ +

In 64-bit mode, the effective address components are + added and the effective address is truncated ( See for example + the instruction LEA ) before adding the full 64-bit segment + base. The base is never truncated, regardless of addressing + mode in 64-bit mode.

+ +

Quoting Intel Vol. 1 Sec. 3.3.7 ( Address Calculations in + 64-Bit Mode ) :

+ +

All 16-bit and 32-bit address calculations are + zero-extended in IA-32e mode to form 64-bit addresses. Address + calculations are first truncated to the effective address size + of the current mode ( 64-bit mode or compatibility mode ) , as + overridden by any address-size prefix. The result is then + zero-extended to the full 64-bit address width. Because of + this, 16-bit and 32-bit applications running in compatibility + mode can access only the low 4 GBytes of the 64-bit mode + effective addresses. Likewise, a 32-bit address generated in + 64-bit mode can access only the low 4 GBytes of the 64-bit + mode effective addresses.

+ +

Also: Intel Vol 1, Section 3.3.7 says that we need + sign-extended displacements in effective address calculations. In + Lisp, sign-extension is implicit.

+ +

In 64-bit mode, instructions such as LEA use this function to + compute the effective address. LEA, at least, does not check + whether the generated address is canonical or not, which is why we + don ' t make the canonical-address-p check in this function.

+ +

In 64-bit mode, + we use @ ( ' rgfi-size ' ) to read bases as signed linear addresses, + which encode canonical linear addresses, + which are also effective addresses in 64-bit mode. + In 32-bit mode, + we use @ ( ' rr32 ' ) to read bases as unsigned effective addresses.

*/ +val x86_effective_addr_32_64 : (proc_mode, bool, sbits(48), bits(8), bits(3), bits(2), sib, bits(3)) -> (sbits(64), {|0, 1, 4|}) + +function x86_effective_addr_32_64 (proc_mode, p4, temp_rip, rex_byte, r_m, mod_var, sib, num_imm_bytes) = { + let (addr, displacement, increment_rip_by) : (int, sbits(64), {|0, 1, 4|}) = { + match mod_var { + 0 => { + (match r_m { + 4 => x86_effective_addr_from_sib(proc_mode, temp_rip, rex_byte, mod_var, sib), + 5 => { + if in_64bit_mode(proc_mode) then { + let dword : sbits(64) = rime_size(Mode_64bit, select_address_size(proc_mode, None()), 4, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let next_rip : sbits(48) = add_to_iptr(Mode_64bit, temp_rip, bits_of_int(4 + unsigned(num_imm_bytes), 48)); + (signed(next_rip), dword, 4) + } else { + let dword : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 4, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + (signed(0x000000000000), dword, 4) + } + }, + _ => (if in_64bit_mode(proc_mode) then { + signed(rgfi(unsigned(reg_index(r_m, rex_byte, 0b00)))) + } else { + signed(sail_zero_extend(rr32(sail_zero_extend(r_m, 4)), 64)) + }, 0x0000000000000000, 0) + }) : (int, sbits(64), {|0, 1, 4|}) + }, + 1 => { + (match r_m { + 4 => x86_effective_addr_from_sib(proc_mode, temp_rip, rex_byte, mod_var, sib), + _ => { + let byte2 : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let reg : sbits(64) = { + if in_64bit_mode(proc_mode) then { + rgfi(unsigned(reg_index(r_m, rex_byte, 0b00))) + } else { + sail_zero_extend(rr32(sail_zero_extend(r_m, 4)), 64) + } + }; + (signed(reg), byte2, 1) + } + }) : (int, sbits(64), {|0, 1, 4|}) + }, + 2 => { + (match r_m { + 4 => x86_effective_addr_from_sib(proc_mode, temp_rip, rex_byte, mod_var, sib), + _ => { + let dword : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, None()), 4, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let reg : sbits(64) = { + if in_64bit_mode(proc_mode) then { + rgfi(unsigned(reg_index(r_m, rex_byte, 0b00))) + } else { + sail_zero_extend(rr32(sail_zero_extend(r_m, 4)), 64) + } + }; + (signed(reg), dword, 4) + } + }) : (int, sbits(64), {|0, 1, 4|}) + }, + _ => x86_model_error("mod-value-wrong") + } + }; + let dst_base : int = addr + signed(displacement); + let dst_base : sbits(64) = { + if in_64bit_mode(proc_mode) then { + if p4 then { + sail_zero_extend(bits_of_int(dst_base, 32), 64) + } else { + bits_of_int(dst_base, 64) + } + } else { + sail_zero_extend(bits_of_int(dst_base, 32), 64) + } + }; + (dst_base, increment_rip_by) +} + +/*! Effective address calculation. +

+ This is a wrapper that calls + @ ( tsee x86-effective-addr-16 ) or @ ( tsee x86-effective-addr-32/64 ) + based on the address size. +

*/ +val x86_effective_addr : (proc_mode, prefixes, sbits(48), bits(8), bits(3), bits(2), sib, bits(3)) -> (sbits(64), {|0, 1, 2, 4|}) + +function x86_effective_addr (proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, num_imm_bytes) = { + let p4 = 0x67 == prefixes[adr]; + if 2 == select_address_size(proc_mode, Some(prefixes)) then { + let (elem1, elem2) : (bits(16), {|0, 1, 2|}) = x86_effective_addr_16(proc_mode, temp_rip, r_m, mod_var); + (sail_zero_extend(elem1, 64), elem2) + } else { + x86_effective_addr_32_64(proc_mode, p4, temp_rip, rex_byte, r_m, mod_var, sib, num_imm_bytes) + } +} + +/*! Functions to fetch and read operands from an instruction, + and to write results to appropriate registers/memory locations, + based on ModR/M, SIB, immediate, and/or displacement bytes. +Checking if alignment is enabled +

Source: Intel Manuals, Volume 3, Section 6.15, Exception + and Interrupt Reference:

+ +

Interrupt 17 Alignment Check Exception ( #AC )

+ +
Exception Class: Fault.
+ +
Description: Indicates that the processor detected an + unaligned memory operand when alignment checking was + enabled. Alignment checks are only carried out in data ( or stack ) + accesses ( not in code fetches or system segment accesses ) . An example + of an alignment-check violation is a word stored at an odd byte + address, or a doubleword stored at an address that is not an integer + multiple of 4.
+ +
Note that the alignment check exception ( #AC ) is + generated only for data types that must be aligned on word, + doubleword, and quadword boundaries. A general-protection + exception ( #GP ) is generated 128-bit data types that are not aligned + on a 16-byte boundary.
+ +
To enable alignment checking, the following conditions + must be true:
+
    +
  • AM flag in CR0 register is set.
  • +
  • AC flag in the EFLAGS register is set.
  • +
  • The CPL is 3 ( protected mode or virtual-8086 mode ) .
  • +
+ +
Alignment-check exceptions ( #AC ) are generated only when + operating at privilege level 3 ( user mode ) . Memory references that + default to privilege level 0, such as segment descriptor loads, do not + generate alignment-check exceptions, even when caused by a memory + reference made from privilege level 3.
*/ +val alignment_checking_enabled_p : unit -> bool + +function alignment_checking_enabled_p () = { + let cr0 : bits(32) = truncate(ctrs[0], 32); + let am : bits(1) = Mk_cr0bits(cr0)[am]; + let ac : bits(2) = { + let rflags_var : rflagsbits = rflags; + sail_zero_extend(rflags_var[ac], 2) + }; + let cpl : bits(2) = Mk_segment_selectorbits(seg_visibles[1])[rpl]; + am == 0b1 & ac == 0b01 & cpl == 0b11 +} + +/*! Read an operand from memory or a register. +

+ Based on the ModR/M byte, + the operand is read from either a register or memory. + In the latter case, we calculate the effective address + and the we read the operand from it. + Besides returning the operand, + we also return the calculated effective address. + This is useful for instructions that modify the operand after reading it + ( e.g. the source/destination operand of ADD ) , + which pass the effective address calculated by this function + to @ ( tsee x86-operand-to-reg/mem ) ( which writes the result to memory ) . +

*/ +val x86_operand_from_modr_m_and_sib_bytes : (proc_mode, bits(1), {|1, 2, 4, 6, 8, 10, 16|}, bool, bool, range(0, 5), prefixes, sbits(48), bits(8), bits(3), bits(2), sib, bits(3)) -> (bits(128), {|0, 1, 2, 4|}, sbits(64)) + +function x86_operand_from_modr_m_and_sib_bytes (proc_mode, reg_type, operand_size, inst_ac?, memory_ptr?, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, num_imm_bytes) = { + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, num_imm_bytes) + } + }; + let operand : bits(128) = { + if mod_var == 0b11 then { + if reg_type == 0b0 then { + sail_zero_extend(rgfi_size(bits_of_int(operand_size, 4), reg_index(r_m, rex_byte, 0b00), rex_byte), 128) + } else { + xmmi_size(bits_of_int(operand_size, 5), reg_index(r_m, rex_byte, 0b00)) + } + } else { + let check_alignment? : bool = inst_ac? & alignment_checking_enabled_p(); + let addr_size = select_address_size(proc_mode, Some(prefixes)); + let base_reg = select_base_register(proc_mode, rex_byte, r_m, mod_var, sib); + rme_size(proc_mode, addr_size, operand_size, addr, base_reg, seg_reg, ":R", check_alignment?, memory_ptr?) + } + }; + (operand, increment_rip_by, addr) +} + +/*! Write an operand to memory or a general-purpose register. +

+ Based on the ModR/M byte, + the operand is written to either a register or memory. + The address argument of this function is often + the effective address calculated and returned by + @ ( tsee x86-operand-from-modr/m-and-sib-bytes ) . +

*/ +val x86_operand_to_reg_mem : (proc_mode, {|1, 2, 4, 6, 8, 10, 16|}, bool, bool, bits(128), seg_reg_idx, sbits(64), prefixes, bits(8), bits(3), bits(2), sib) -> unit + +function x86_operand_to_reg_mem (proc_mode, operand_size, inst_ac?, memory_ptr?, operand, seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib) = { + if mod_var == 0b11 then { + write_rgfi_size(bits_of_int(operand_size, 4), reg_index(r_m, rex_byte, 0b00), truncate(operand, 64), rex_byte) + } else { + let check_alignment? : bool = inst_ac? & alignment_checking_enabled_p(); + let addr_size = select_address_size(proc_mode, Some(prefixes)); + let base_reg : option(base_reg_idx) = select_base_register(proc_mode, rex_byte, r_m, mod_var, sib); + wme_size(proc_mode, addr_size, operand_size, addr, base_reg, seg_reg, operand, check_alignment?, memory_ptr?) + } +} + +/*! Write an operand to memory or an XMM register. +

+ Based on the ModR/M byte, + the operand is written to either a register or memory. + The address argument of this function is often + the effective address calculated and returned by + @ ( tsee x86-operand-from-modr/m-and-sib-bytes ) . +

*/ +val x86_operand_to_xmm_mem : (proc_mode, {|4, 8, 16|}, bool, bits(128), seg_reg_idx, sbits(64), prefixes, bits(8), bits(3), bits(2), sib) -> unit + +function x86_operand_to_xmm_mem (proc_mode, operand_size, inst_ac?, operand, seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib) = { + if mod_var == 0b11 then { + write_xmmi_size(bits_of_int(operand_size, 5), reg_index(r_m, rex_byte, 0b00), unsigned(operand)) + } else { + let check_alignment? : bool = inst_ac? & alignment_checking_enabled_p(); + let addr_size = select_address_size(proc_mode, Some(prefixes)); + let base_reg : option(base_reg_idx) = select_base_register(proc_mode, rex_byte, r_m, mod_var, sib); + wme_size(proc_mode, addr_size, operand_size, addr, base_reg, seg_reg, operand, check_alignment?, false) + } +} + +/*! Selecting the operand size for general-purpose instructions +

@ ( ' select-operand-size ' ) selects the operand size of the + instruction. It is cognizant of the instruction prefixes, the + @ ( ' rex ' ) byte, the operand type ( e.g., immediate operand or not ) , + and the default operand size ( obtained from the state ) .

+ +

This function was written by referring to the following: +

    +
  1. Intel Manuals, Vol. 1, Section 3.6, Table 3-3
  2. +
  3. Intel Manuals, Vol. 1, Section 3.6, Table 3-4
  4. +
  5. Intel Manuals, Vol. 2, Section 2.2.1.2
  6. +
+

+ +

+ +

+ + The first image above has been captured from Volume 1: Basic Architecture, + Intel\ ( R\ ) 64 and IA-32 Architectures Software Developer ' s Manual, + Order Number: 253665-062US, March 2017.

+ + The second image above has been captured from Volume 1: Basic Architecture, + Intel\ ( R\ ) 64 and IA-32 Architectures Software Developer ' s Manual, + Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B and 3C, Order Number: + 325462-054US, April 2015.

+ + +
    +
  • Setting REX.W can be used to determine the operand size but does + not solely determine operand width. Like the 66H size prefix, 64-bit + operand size override has no effect on byte-specific operations.
  • + +
  • For non-byte operations: if a 66H prefix is used with prefix + \ ( REX.W = 1\ ) , 66H is ignored.
  • + +
  • If a 66H override is used with REX and REX.W = 0, the operand size + is 16 bits.
  • +
+
+ +

This function also includes three additional boolean parameters that serve + to accommodate instructions that do not quite follow the general rules + specified by the table above:

+ +
    + +
  • The @ ( ' default64? ' ) parameter says whether the default operand size in + 64-bit mode should be 64 bits instead of 32 bits. Examples are @ ( tsee + x86-near-jmp-op/en-m ) and @ ( tsee x86-push-general-register ) .
  • + +
  • The @ ( ' ignore-rex? ' ) parameter says whether, in 64-bit mode, REX.W should + be ignored for the purpose of determining the operand size. Examples are + @ ( tsee x86-two-byte-jcc ) , @ ( tsee x86-near-jmp-op/en-m ) , and @ ( tsee + x86-push-general-register ) .
  • + +
  • The @ ( ' ignore-p3-64? ' ) parameter says whether, in 64-bit mode, P3 should + be ignored for the purpose of determining the operand size. Examples are + @ ( tsee x86-two-byte-jcc ) and @ ( tsee x86-near-jmp-op/en-m ) .
  • + +
*/ +val select_operand_size : (proc_mode, bool, bits(8), bool, prefixes, bool, bool, bool) -> {|1, 2, 4, 8|} + +function select_operand_size (proc_mode, byte_operand?, rex_byte, imm?, prefixes, default64?, ignore_rex?, ignore_p3_64?) = { + if byte_operand? then 1 else if in_64bit_mode(proc_mode) then { + if logbitp(3, rex_byte) & not_bool(ignore_rex?) then { + if imm? then 4 else 8 + } else if 0x66 == prefixes[opr] & not_bool(ignore_p3_64?) then 2 else if default64? then 8 else 4 + } else { + let cs_attr : bits(16) = seg_hidden_attrs[1]; + let cs_d : bits(1) = Mk_code_segment_descriptor_attributesbits(cs_attr)[d]; + let p3? : bool = 0x66 == prefixes[opr]; + if cs_d == 0b1 then { + if p3? then 2 else 4 + } else if p3? then 4 else 2 + } +} + +/*! Check if the length of an instruction exceeds 15 bytes. +

+ The maximum length of an instruction is 15 bytes; + a longer instruction causes a #GP ( 0 ) exception. + See AMD manual, Dec ' 17, Volume 2, Table 8-6. + This function is used to check this condition. +

+

+ The @ ( ' start-rip ' ) argument is + the instruction pointer at the beginning of the instruction. + The @ ( ' temp-rip ' ) argument is generally + the instruction pointer just past the end of the instruction, + in which case the @ ( ' delta-rip ' ) argument is 0. + In the other cases, @ ( ' delta-rip ' ) is a small non-zero number, + and @ ( ' temp-rip + delta-rip ' ) is + the instruction pointer just past the end of the instruction. +

+

+ This function returns @ ( ' nil ' ) if the length does not exceed 15 bytes. + Otherwise, this function returns the offending length ( a number above 15 ) , + which is useful for error reporting in the model. +

*/ +val check_instruction_length : (sbits(48), sbits(48), bits(3)) -> option(int) + +function check_instruction_length (start_rip, temp_rip, delta_rip) = { + let start_rip : int = signed(start_rip); + let temp_rip : int = signed(temp_rip); + let delta_rip : nat = unsigned(delta_rip); + let end_rip : sbits(49) = bits_of_int(signed(bits_of_int(temp_rip, 48)) + unsigned(bits_of_int(delta_rip, 3)), 49); + let length : sbits(50) = bits_of_int(signed(end_rip) - signed(bits_of_int(start_rip, 48)), 50); + if 15 < signed(length) then { + Some(signed(length)) + } else { + None() + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/dispatch_macros.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/dispatch_macros.sail new file mode 100644 index 000000000..1aef22f41 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/dispatch_macros.sail @@ -0,0 +1,17 @@ + +val chk_exc_fn : (string, string, list(string), proc_mode, prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function chk_exc_fn (decode_context, type_id, feature_flags, proc_mode, prefixes, rex_byte, opcode, modr_m, sib) = { + if decode_context == ":VEX" & ((0xf3 == prefixes[rep] | 0xf2 == prefixes[rep]) | 0x66 == prefixes[opr] | not_bool(rex_byte == 0x00) | not_bool(in_64bit_mode(proc_mode) | in_compatibility_mode(proc_mode) | in_protected_mode(proc_mode))) then { + x86_fault("(:ud)") + } else if type_id == ":TYPE-VEX-GPR" then { + if feature_flags_fn(feature_flags) == 0 then x86_fault("(:ud)"); + () + } else if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 then { + x86_fault("(:nm)") + } else if not_bool(in_list(type_id, [|":TYPE-22-7", ":TYPE-22-8", ":TYPE-22-9"|])) & Mk_cr4bits(loghead(22, ctrs[4]))[osfxsr] == 0b0 then { + x86_fault("(:ud)") + } else if Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 | 0xf0 == prefixes[lck] | feature_flags_fn(feature_flags) == 0 then { + x86_fault("(:ud)") + } else () +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/environment.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/environment.sail new file mode 100644 index 000000000..c2ca6e592 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/environment.sail @@ -0,0 +1 @@ +$include "./top_level_memory.sail" diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/init.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/init.sail new file mode 100644 index 000000000..e90d6a300 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/init.sail @@ -0,0 +1,8 @@ +$ifndef __X86_INIT +$define __X86_INIT + +// An extension hook for model initialization; called by main() +val initialize_model : unit -> unit +function initialize_model() = () + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/jump_and_loop.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/jump_and_loop.sail new file mode 100644 index 000000000..92a95167c --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/jump_and_loop.sail @@ -0,0 +1,304 @@ + +val x86_near_jmp_op_en_d : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_near_jmp_op_en_d (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-NEAR-JMP-OP/EN-D"; + let byte_operand? : bool = opcode == 0xeb; + let offset_size : {|1, 2, 4|} = check_range(0, 4, select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, true, true)); + let offset : sbits(32) = truncate(rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), offset_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), 32); + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(offset_size, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, next_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, next_rip, sail_sign_extend(offset, 48)); + let temp_rip : sbits(48) = { + if offset_size == 2 then { + logand(0x00000000ffff, temp_rip) + } else { + temp_rip + } + }; + write_iptr(proc_mode, temp_rip) +} + +val x86_near_jmp_op_en_m : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_near_jmp_op_en_m (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-NEAR-JMP-OP/EN-M"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let operand_size : {|2, 4, 8|} = check_range(2, 8, select_operand_size(proc_mode, false, rex_byte, false, prefixes, true, true, true)); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (jmp_addr, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let jmp_addr : sbits(64) = truncate(jmp_addr, 64); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let jmp_addr : sbits(64) = { + if in_64bit_mode(proc_mode) then { + jmp_addr + } else { + jmp_addr + } + }; + if not_bool(if in_64bit_mode(proc_mode) then { + canonical_address_p(signed(jmp_addr)) + } else { + let cs_limit : bits(32) = seg_hidden_limits[1]; + 0 <= signed(jmp_addr) & signed(jmp_addr) <= unsigned(cs_limit) + }) then x86_fault("(!!FAULT-FRESH :GP 0 :BAD-RETURN-ADDRESS JMP-ADDR)"); + write_iptr(proc_mode, truncate(jmp_addr, 48)) +} + +/*! Absolute Indirect Jump: Far +

Op/En: D

+

FF/5: JMP m16:16 or m16:32 or m16:64

+ +

Source: Intel Manuals ( Vol. 2A ) Instruction Set Reference: the + text below has been edited to contain information only about the + 64-bit mode.

+ +

The JMP instruction cannot be used to perform + inter-privilege-level far jumps. The processor always uses the + segment selector part of the far address to access the corresponding + descriptor in the GDT or LDT. The descriptor type and access rights + determine the type of jump to be performed.

+ +

Far Jump to a Conforming or Non-Conforming Code Segment: If + the selected descriptor is for a code segment, a far jump to a code + segment at the same privilege level is performed. If the selected code + segment is at a different privilege level and the code segment is + non-conforming, a general-protection exception is generated. The + target operand specifies an absolute far address indirectly with a + memory location ( m16:16 or m16:32 or m16:64 ) . The operand-size + attribute and the REX.w bit determine the size of the offset ( 16 or + 32 or 64 bits ) in the far address. The new code segment selector and + its descriptor are loaded into CS register, and the offset from the + instruction is loaded into the RIP register.

+ +

Far Jump through a Call Gate: When executing a far jump + through a call gate, the segment selector specified by the target + operand identifies the call gate. The offset part of the target + operand is ignored. The processor then jumps to the code segment + specified in the call gate descriptor and begins executing the + instruction at the offset specified in the call gate. No stack switch + occurs. The target operand specifies the far address of the call gate + indirectly with a memory location ( m16:16 or m16:32 or m16:64 ) .

*/ +val x86_far_jmp_op_en_d : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_far_jmp_op_en_d (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-FAR-JMP-OP/EN-D"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + if mod_var == 0b11 then x86_model_error(":SOURCE-OPERAND-NOT-MEMORY-LOCATION"); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let offset_size : {|2, 4, 8|} = check_range(2, 8, select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false)); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, 2 + offset_size, inst_ac?, true, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, increment_rip_by); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let selector : bits(16) = truncate(mem, 16); + let offset : bits(64) = sail_mask(64, bitslice(mem, 16, ash(offset_size, 3))); + let sel_index : bits(13) = Mk_segment_selectorbits(selector)[index]; + let sel_ti : bits(1) = Mk_segment_selectorbits(selector)[ti]; + let sel_rpl : bits(2) = Mk_segment_selectorbits(selector)[rpl]; + if sel_ti == 0b0 & sel_index == 0b0000000000000 then x86_fault("(!!FAULT-FRESH :GP 0 :GP-NULLSELECTOR 0)"); + let (dt_base_addr, dt_limit) : (bits(64), bits(32)) = { + if sel_ti == 0b0 then { + let gdtr : bits(80) = strs[0]; + let gdtr_base : bits(64) = { + if in_64bit_mode(proc_mode) then { + Mk_gdtr_idtrbits(gdtr)[base_addr] + } else { + sail_zero_extend(truncate(Mk_gdtr_idtrbits(gdtr)[base_addr], 32), 64) + } + }; + let gdtr_limit : bits(16) = Mk_gdtr_idtrbits(gdtr)[limit]; + (gdtr_base, sail_zero_extend(gdtr_limit, 32)) + } else { + let ldtr_base : bits(64) = ssr_hidden_bases[0]; + let ldtr_base : bits(64) = { + if in_64bit_mode(proc_mode) then { + ldtr_base + } else { + sail_zero_extend(truncate(ldtr_base, 32), 64) + } + }; + let ldtr_limit : bits(32) = ssr_hidden_limits[0]; + (ldtr_base, ldtr_limit) + } + }; + let largest_address : int = ash(unsigned(sel_index), 3) + 7; + if unsigned(dt_limit) < largest_address then x86_fault("(!!FAULT-FRESH :GP SEL-INDEX :GP-SELECTOR-LIMIT-CHECK-FAILED (LIST SELECTOR DT-BASE-ADDR DT-LIMIT))"); + let descriptor_addr : int = unsigned(dt_base_addr) + unsigned(bits_of_int(ash(unsigned(sel_index), 3), 16)); + if not_bool(canonical_address_p(descriptor_addr)) then x86_model_error(":DESCRIPTOR-ADDR-VIRTUAL-MEMORY-ERROR"); + let descriptor : bits(64) = truncate(rml_size(8, bits_of_int(descriptor_addr, 48), ":X"), 64); + let s : bits(1) = Mk_code_segment_descriptorbits(descriptor)[s]; + if s == 0b1 then { + let msb_of_type : bits(1) = Mk_code_segment_descriptorbits(descriptor)[msb_of_type]; + if not_bool(msb_of_type == 0b1) then x86_fault("(!!FAULT-FRESH :GP SEL-INDEX :JMP-FAR-DATA-SEGMENT SEL-INDEX)"); + let d : bits(1) = Mk_code_segment_descriptorbits(descriptor)[d]; + if in_64bit_mode(proc_mode) & d == 0b1 then x86_fault("(!!FAULT-FRESH :GP SEL-INDEX :CS.D=1-IN-64-BIT-MODE SEL-INDEX)"); + let cpl : bits(2) = Mk_segment_selectorbits(seg_visibles[1])[rpl]; + let dpl : bits(2) = Mk_code_segment_descriptorbits(descriptor)[dpl]; + let c : bits(1) = Mk_code_segment_descriptorbits(descriptor)[c]; + let allowed : bool = { + if c == 0b1 then { + unsigned(dpl) <= unsigned(cpl) + } else { + unsigned(sel_rpl) <= unsigned(cpl) & cpl == dpl + } + }; + if not_bool(allowed) then x86_fault("(!!FAULT-FRESH :GP SEL-INDEX :PRIVILEGE-CHECK-FAIL (ACONS :DPL DPL (ACONS :CPL CPL (ACONS :RPL SEL-RPL NIL))))"); + let p : bits(1) = Mk_code_segment_descriptorbits(descriptor)[p]; + if not_bool(p == 0b1) then x86_fault("(!!FAULT-FRESH :NP SEL-INDEX :CODE-SEGMENT-NOT-PRESENT SEL-INDEX)"); + let jmp_addr : sbits(64) = { + match offset_size { + 2 => sail_zero_extend(truncate(offset, 16), 64), + 4 => sail_zero_extend(truncate(offset, 32), 64), + _ => offset + } + }; + let jmp_addr_ok : bool = { + if in_64bit_mode(proc_mode) then { + canonical_address_p(signed(jmp_addr)) + } else { + let limit15_0 : bits(16) = Mk_code_segment_descriptorbits(descriptor)[limit15_0]; + let limit19_16 : bits(4) = Mk_code_segment_descriptorbits(descriptor)[limit19_16]; + let limit : int = changeSlice(ash(unsigned(limit19_16), 16), 0, 16, unsigned(limit15_0)); + let g : bits(1) = Mk_code_segment_descriptorbits(descriptor)[g]; + let max_offset : int : int = { + if g == 0b1 then { + ash(limit, 12) - 1 + } else { + limit + } + }; + signed(jmp_addr) < max_offset : int + } + }; + if not_bool(jmp_addr_ok) then x86_fault("(!!FAULT-FRESH :GP 0 :NONCANONICAL-OR-OUTSIDE-SEGMENT-LIMIT JMP-ADDR)"); + let new_cs_visible : segment_selectorbits = [Mk_segment_selectorbits(selector) with rpl = cpl]; + seg_visibles[1] = new_cs_visible.bits; + seg_hidden_bases[1] = dt_base_addr; + seg_hidden_limits[1] = dt_limit; + seg_hidden_attrs[1] = make_code_segment_attr_field(descriptor).bits; + write_iptr(proc_mode, truncate(jmp_addr, 48)) + } else { + if not_bool(in_64bit_mode(proc_mode)) then x86_model_error(":FAR-JMP-SYSTEM-UNIMPLEMENTED-IN-32-BIT-MODE"); + let largest_address : int = ash(unsigned(sel_index), 3) + 15; + if unsigned(dt_limit) < largest_address then x86_fault("(!!FAULT-FRESH :GP SEL-INDEX :GP-SELECTOR-LIMIT-CHECK-FAILED (LIST SELECTOR DT-BASE-ADDR DT-LIMIT))"); + let descriptor : bits(128) = rml_size(16, bits_of_int(descriptor_addr, 48), ":X"); + let (call_gate_desc?, reason2) : (bool, (string, bits(128))) = ia32e_valid_call_gate_segment_descriptor_p(descriptor); + if call_gate_desc? then { + let cpl : bits(2) = Mk_segment_selectorbits(seg_visibles[1])[rpl]; + let dpl : bits(2) = Mk_call_gate_descriptorbits(descriptor)[dpl]; + if not_bool(unsigned(cpl) <= unsigned(dpl) & unsigned(sel_rpl) <= unsigned(dpl)) then x86_fault("(!!FAULT-FRESH :GP SEL-INDEX :PRIVILEGE-CHECK-FAIL (ACONS :DPL DPL (ACONS :CPL CPL (ACONS :RPL SEL-RPL NIL))))"); + let cs_selector : bits(16) = Mk_call_gate_descriptorbits(descriptor)[selector]; + let cs_sel_index : bits(13) = Mk_segment_selectorbits(cs_selector)[index]; + let cs_sel_ti : bits(1) = Mk_segment_selectorbits(cs_selector)[ti]; + let cs_sel_rpl : bits(2) = Mk_segment_selectorbits(cs_selector)[rpl]; + if cs_sel_ti == 0b0 & cs_sel_index == 0b0000000000000 then x86_fault("(!!FAULT-FRESH :GP 0 :CALL-GATE-CODE-SEGMENT-NULLSELECTOR 0)"); + let (cs_dt_base_addr, cs_dt_limit) : (bits(64), bits(32)) = { + if sel_ti == 0b0 then { + let gdtr : bits(80) = strs[0]; + let gdtr_base : bits(64) = Mk_gdtr_idtrbits(gdtr)[base_addr]; + let gdtr_base : bits(64) = { + if in_64bit_mode(proc_mode) then { + gdtr_base + } else { + sail_zero_extend(truncate(gdtr_base, 32), 64) + } + }; + let gdtr_limit : bits(16) = Mk_gdtr_idtrbits(gdtr)[limit]; + (gdtr_base, sail_zero_extend(gdtr_limit, 32)) + } else { + let ldtr_base : bits(64) = ssr_hidden_bases[0]; + let ldtr_base : bits(64) = { + if in_64bit_mode(proc_mode) then { + ldtr_base + } else { + sail_zero_extend(truncate(ldtr_base, 32), 64) + } + }; + let ldtr_limit : bits(32) = ssr_hidden_limits[0]; + (ldtr_base, ldtr_limit) + } + }; + let largest_address : int = ash(unsigned(cs_sel_index), 3) + 7; + if unsigned(cs_dt_limit) < largest_address then x86_fault("(!!FAULT-FRESH :GP CS-SEL-INDEX :GP-SELECTOR-LIMIT-CHECK-FAILED (LIST CS-SELECTOR CS-DT-BASE-ADDR CS-DT-LIMIT))"); + let cs_descriptor_addr : int = unsigned(cs_dt_base_addr) + unsigned(bits_of_int(ash(unsigned(cs_sel_index), 3), 16)); + if not_bool(canonical_address_p(cs_descriptor_addr)) then x86_model_error(":CS-DESCRIPTOR-ADDR-VIRTUAL-MEMORY-ERROR"); + let cs_descriptor : bits(64) = truncate(rml_size(8, bits_of_int(cs_descriptor_addr, 48), ":X"), 64); + let (valid?, reason) : (bool, (string, bits(64))) = ia32e_valid_code_segment_descriptor_p(cs_descriptor); + if not_bool(valid?) then x86_fault("(!!FAULT-FRESH :GP CS-SEL-INDEX :CALL-GATE-CODE-SEGMENT-DESCRIPTOR-INVALID (CONS REASON CS-DESCRIPTOR))"); + let cs_dpl : bits(2) = Mk_code_segment_descriptorbits(cs_descriptor)[dpl]; + let c_bit : bits(1) = Mk_code_segment_descriptorbits(cs_descriptor)[c]; + if c_bit == 0b1 & not_bool(unsigned(cs_dpl) <= unsigned(cpl)) | c_bit == 0b0 & not_bool(cs_dpl == cpl) then x86_fault("(!!FAULT-FRESH :GP CS-SEL-INDEX :PRIVILEGE-CHECK-FAIL (ACONS :C-BIT C-BIT (ACONS :CPL CPL (ACONS :CS-DPL CS-DPL NIL))))"); + let call_gate_offset15_0 : bits(16) = Mk_call_gate_descriptorbits(descriptor)[offset15_0]; + let call_gate_offset31_16 : bits(16) = Mk_call_gate_descriptorbits(descriptor)[offset31_16]; + let call_gate_offset63_32 : bits(32) = Mk_call_gate_descriptorbits(descriptor)[offset63_32]; + let call_gate_offset31_0 : int = changeSlice(ash(unsigned(call_gate_offset31_16), 16), 0, 16, unsigned(call_gate_offset15_0)); + let call_gate_offset : int = changeSlice(ash(unsigned(call_gate_offset63_32), 32), 0, 32, call_gate_offset31_0); + let jmp_addr : sbits(64) = { + match offset_size { + 2 => sail_zero_extend(bits_of_int(call_gate_offset, 16), 64), + 4 => sail_zero_extend(bits_of_int(call_gate_offset, 32), 64), + _ => bits_of_int(call_gate_offset, 64) + } + }; + if not_bool(canonical_address_p(signed(jmp_addr))) then x86_model_error(":TARGET-OFFSET-VIRTUAL-MEMORY-ERROR"); + let new_cs_visible : segment_selectorbits = [Mk_segment_selectorbits(cs_selector) with rpl = cpl]; + seg_visibles[1] = new_cs_visible.bits; + seg_hidden_bases[1] = cs_dt_base_addr; + seg_hidden_limits[1] = cs_dt_limit; + seg_hidden_attrs[1] = make_code_segment_attr_field(cs_descriptor).bits; + write_iptr(proc_mode, truncate(jmp_addr, 48)) + } else { + x86_fault("(!!FAULT-FRESH :GP SEL-INDEX :EITHER-BOTH-CODE-SEGMENT-OR-CALL-GATE-ARE-ABSENT-OR-SOME-OTHER-DESCRIPTOR-IS-PRESENT (CONS REASON2 DESCRIPTOR))") + } + } +} + +val x86_loop : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_loop (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-LOOP"; + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b001); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let p4? : bool = 0x67 == prefixes[adr]; + let counter_size : address_size = select_address_size(proc_mode, Some(prefixes)); + let counter : bits(64) = rgfi_size(bits_of_int(counter_size, 4), 0x1, rex_byte); + let counter : bits(64) = sail_mask(64, trunc(counter_size, bits_of_int(unsigned(counter) - 1, 64))); + let zf : bits(1) = { + let rflags_var : rflagsbits = rflags; + rflags_var[zf] + }; + let branch_cond : bool = { + if opcode == 0xe2 then { + not_bool(counter == 0x0000000000000000) + } else if opcode == 0xe1 then { + zf == 0b1 & not_bool(counter == 0x0000000000000000) + } else { + zf == 0b0 & not_bool(counter == 0x0000000000000000) + } + }; + if branch_cond then { + let rel8 : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(1 + signed(rel8), 48)); + write_rgfi_size(bits_of_int(counter_size, 4), 0x1, counter, rex_byte); + write_iptr(proc_mode, next_rip) + } else { + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + write_rgfi_size(bits_of_int(counter_size, 4), 0x1, counter, rex_byte); + write_iptr(proc_mode, next_rip) + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/linear_memory.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/linear_memory.sail new file mode 100644 index 000000000..38a1042ab --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/linear_memory.sail @@ -0,0 +1,428 @@ +$include "./paging.sail" + +/*! Definitions of @ ( see rb ) and @ ( see wb ) +

The functions @ ( ' rb ' ) ( read bytes ) and @ ( ' wb ' ) ( write + bytes ) are used in reasoning about memory reads and writes. Functions + like @ ( ' rml08 ' ) , @ ( ' rml16 ' ) , @ ( ' rml32 ' ) , and @ ( ' rml64 ' ) are reduced to + @ ( ' rb ' ) , and @ ( ' wml08 ' ) , @ ( ' wml16 ' ) , @ ( ' wml32 ' ) , and @ ( ' wml64 ' ) to + @ ( ' wb ' ) during reasoning.

*/ +val rml08 : (sbits(48), string) -> bits(8) + +function rml08 (lin_addr, r_x) = { + rb(1, lin_addr, r_x) +} + +val riml08 : (sbits(48), string) -> sbits(8) + +function riml08 (lin_addr, r_x) = { + let sailval : bits(8) = rml08(lin_addr, r_x); + sailval +} + +val wml08 : (sbits(48), bits(8)) -> unit + +function wml08 (lin_addr, sailval) = { + wb(1, lin_addr, ":W", sailval) +} + +val wiml08 : (sbits(48), sbits(8)) -> unit + +function wiml08 (lin_addr, sailval) = { + wml08(lin_addr, sailval) +} + +val rml16 : (sbits(48), string) -> bits(16) + +function rml16 (lin_addr, r_x) = { + let one__plus_lin_addr : sbits(49) = bits_of_int(1 + signed(lin_addr), 49); + if canonical_address_p(signed(one__plus_lin_addr)) then { + rb(2, lin_addr, r_x) + } else { + x86_model_error("rml16") + } +} + +val riml16 : (sbits(48), string) -> sbits(16) + +function riml16 (lin_addr, r_x) = { + let sailval : bits(16) = rml16(lin_addr, r_x); + sailval +} + +val wml16 : (sbits(48), bits(16)) -> unit + +function wml16 (lin_addr, sailval) = { + assert(canonical_address_p(signed(lin_addr))); + let one__plus_lin_addr : sbits(49) = bits_of_int(1 + signed(lin_addr), 49); + if canonical_address_p(signed(one__plus_lin_addr)) then { + wb(2, lin_addr, ":W", sailval) + } else { + x86_model_error("wml16") + } +} + +val wiml16 : (sbits(48), sbits(16)) -> unit + +function wiml16 (lin_addr, sailval) = { + wml16(lin_addr, sailval) +} + +val rml32 : (sbits(48), string) -> bits(32) + +function rml32 (lin_addr, r_x) = { + assert(canonical_address_p(signed(lin_addr))); + let three__plus_lin_addr : sbits(49) = bits_of_int(3 + signed(lin_addr), 49); + if canonical_address_p(signed(three__plus_lin_addr)) then { + rb(4, lin_addr, r_x) + } else { + x86_model_error("rml32") + } +} + +val riml32 : (sbits(48), string) -> sbits(32) + +function riml32 (lin_addr, r_x) = { + let sailval : bits(32) = rml32(lin_addr, r_x); + sailval +} + +val wml32 : (sbits(48), bits(32)) -> unit + +function wml32 (lin_addr, sailval) = { + assert(canonical_address_p(signed(lin_addr))); + let three__plus_lin_addr : sbits(49) = bits_of_int(3 + signed(lin_addr), 49); + if canonical_address_p(signed(three__plus_lin_addr)) then { + wb(4, lin_addr, ":W", sailval) + } else { + x86_model_error("wml32") + } +} + +val wiml32 : (sbits(48), sbits(32)) -> unit + +function wiml32 (lin_addr, sailval) = { + wml32(lin_addr, sailval) +} + +val rml48 : (sbits(48), string) -> bits(48) + +function rml48 (lin_addr, r_x) = { + assert(canonical_address_p(signed(lin_addr))); + let five__plus_lin_addr : sbits(49) = bits_of_int(5 + signed(lin_addr), 49); + if canonical_address_p(signed(five__plus_lin_addr)) then { + rb(6, lin_addr, r_x) + } else { + x86_model_error("rml48") + } +} + +val wml48 : (sbits(48), bits(48)) -> unit + +function wml48 (lin_addr, sailval) = { + assert(canonical_address_p(signed(lin_addr))); + let five__plus_lin_addr : sbits(49) = bits_of_int(5 + signed(lin_addr), 49); + if canonical_address_p(signed(five__plus_lin_addr)) then { + wb(6, lin_addr, ":W", sailval) + } else { + x86_model_error("wml48") + } +} + +val rml64 : (sbits(48), string) -> bits(64) + +function rml64 (lin_addr, r_x) = { + assert(canonical_address_p(signed(lin_addr))); + let seven__plus_lin_addr : sbits(49) = bits_of_int(7 + signed(lin_addr), 49); + if canonical_address_p(signed(seven__plus_lin_addr)) then { + rb(8, lin_addr, r_x) + } else { + x86_model_error("rml64") + } +} + +val riml64 : (sbits(48), string) -> sbits(64) + +function riml64 (lin_addr, r_x) = { + let sailval : bits(64) = rml64(lin_addr, r_x); + sailval +} + +val wml64 : (sbits(48), bits(64)) -> unit + +function wml64 (lin_addr, sailval) = { + assert(canonical_address_p(signed(lin_addr))); + let seven__plus_lin_addr : sbits(50) = bits_of_int(7 + signed(lin_addr), 50); + if canonical_address_p(signed(seven__plus_lin_addr)) then { + wb(8, lin_addr, ":W", sailval) + } else { + x86_model_error("wml64") + } +} + +val wiml64 : (sbits(48), sbits(64)) -> unit + +function wiml64 (lin_addr, sailval) = { + wml64(lin_addr, sailval) +} + +val rml80 : (sbits(48), string) -> bits(80) + +function rml80 (lin_addr, r_x) = { + assert(canonical_address_p(signed(lin_addr))); + let nine__plus_lin_addr : sbits(49) = bits_of_int(9 + signed(lin_addr), 49); + if canonical_address_p(signed(nine__plus_lin_addr)) then { + rb(10, lin_addr, r_x) + } else { + x86_model_error("rml80") + } +} + +val wml80 : (sbits(48), bits(80)) -> unit + +function wml80 (lin_addr, sailval) = { + assert(canonical_address_p(signed(lin_addr))); + let nine__plus_lin_addr : sbits(49) = bits_of_int(9 + signed(lin_addr), 49); + if canonical_address_p(signed(nine__plus_lin_addr)) then { + wb(10, lin_addr, ":W", sailval) + } else { + x86_model_error("wml80") + } +} + +val rml128 : (sbits(48), string) -> bits(128) + +function rml128 (lin_addr, r_x) = { + assert(canonical_address_p(signed(lin_addr))); + let one_5_plus_lin_addr : sbits(49) = bits_of_int(15 + signed(lin_addr), 49); + if canonical_address_p(signed(one_5_plus_lin_addr)) then { + if app_view then { + rb(16, lin_addr, r_x) + } else { + let p_addr0 : bits(52) = la_to_pa(lin_addr, r_x); + let one__plus_lin_addr : sbits(49) = bits_of_int(1 + signed(lin_addr), 49); + let p_addr1 : bits(52) = la_to_pa(truncate(one__plus_lin_addr, 48), r_x); + let _2_plus_lin_addr : sbits(50) = bits_of_int(2 + signed(lin_addr), 50); + let p_addr2 : bits(52) = la_to_pa(truncate(_2_plus_lin_addr, 48), r_x); + let three__plus_lin_addr : sbits(51) = bits_of_int(3 + signed(lin_addr), 51); + let p_addr3 : bits(52) = la_to_pa(truncate(three__plus_lin_addr, 48), r_x); + let _4_plus_lin_addr : sbits(52) = bits_of_int(4 + signed(lin_addr), 52); + let p_addr4 : bits(52) = la_to_pa(truncate(_4_plus_lin_addr, 48), r_x); + let five__plus_lin_addr : sbits(53) = bits_of_int(5 + signed(lin_addr), 53); + let p_addr5 : bits(52) = la_to_pa(truncate(five__plus_lin_addr, 48), r_x); + let _6_plus_lin_addr : sbits(54) = bits_of_int(6 + signed(lin_addr), 54); + let p_addr6 : bits(52) = la_to_pa(truncate(_6_plus_lin_addr, 48), r_x); + let seven__plus_lin_addr : sbits(55) = bits_of_int(7 + signed(lin_addr), 55); + let p_addr7 : bits(52) = la_to_pa(truncate(seven__plus_lin_addr, 48), r_x); + let _8_plus_lin_addr : sbits(56) = bits_of_int(8 + signed(lin_addr), 56); + let p_addr8 : bits(52) = la_to_pa(truncate(_8_plus_lin_addr, 48), r_x); + let nine__plus_lin_addr : sbits(57) = bits_of_int(9 + signed(lin_addr), 57); + let p_addr9 : bits(52) = la_to_pa(truncate(nine__plus_lin_addr, 48), r_x); + let one_0_plus_lin_addr : sbits(58) = bits_of_int(10 + signed(lin_addr), 58); + let p_addr10 : bits(52) = la_to_pa(truncate(one_0_plus_lin_addr, 48), r_x); + let one_1_plus_lin_addr : sbits(59) = bits_of_int(11 + signed(lin_addr), 59); + let p_addr11 : bits(52) = la_to_pa(truncate(one_1_plus_lin_addr, 48), r_x); + let one_2_plus_lin_addr : sbits(60) = bits_of_int(12 + signed(lin_addr), 60); + let p_addr12 : bits(52) = la_to_pa(truncate(one_2_plus_lin_addr, 48), r_x); + let one_3_plus_lin_addr : sbits(61) = bits_of_int(13 + signed(lin_addr), 61); + let p_addr13 : bits(52) = la_to_pa(truncate(one_3_plus_lin_addr, 48), r_x); + let one_4_plus_lin_addr : sbits(62) = bits_of_int(14 + signed(lin_addr), 62); + let p_addr14 : bits(52) = la_to_pa(truncate(one_4_plus_lin_addr, 48), r_x); + let one_5_plus_lin_addr : sbits(63) = bits_of_int(15 + signed(lin_addr), 63); + let p_addr15 : bits(52) = la_to_pa(truncate(one_5_plus_lin_addr, 48), r_x); + let byte0 : bits(8) = memi(sail_zero_extend(p_addr0, 64)); + let byte1 : bits(8) = memi(sail_zero_extend(p_addr1, 64)); + let byte2 : bits(8) = memi(sail_zero_extend(p_addr2, 64)); + let byte3 : bits(8) = memi(sail_zero_extend(p_addr3, 64)); + let byte4 : bits(8) = memi(sail_zero_extend(p_addr4, 64)); + let byte5 : bits(8) = memi(sail_zero_extend(p_addr5, 64)); + let byte6 : bits(8) = memi(sail_zero_extend(p_addr6, 64)); + let byte7 : bits(8) = memi(sail_zero_extend(p_addr7, 64)); + let byte8 : bits(8) = memi(sail_zero_extend(p_addr8, 64)); + let byte9 : bits(8) = memi(sail_zero_extend(p_addr9, 64)); + let byte10 : bits(8) = memi(sail_zero_extend(p_addr10, 64)); + let byte11 : bits(8) = memi(sail_zero_extend(p_addr11, 64)); + let byte12 : bits(8) = memi(sail_zero_extend(p_addr12, 64)); + let byte13 : bits(8) = memi(sail_zero_extend(p_addr13, 64)); + let byte14 : bits(8) = memi(sail_zero_extend(p_addr14, 64)); + let byte15 : bits(8) = memi(sail_zero_extend(p_addr15, 64)); + let oword : bits(128) = byte15 @ (byte14 @ (byte13 @ (byte12 @ (byte11 @ (byte10 @ (byte9 @ (byte8 @ (byte7 @ (byte6 @ (byte5 @ (byte4 @ (byte3 @ (byte2 @ (byte1 @ byte0)))))))))))))); + oword + } + } else { + x86_model_error("rml128") + } +} + +val wml128 : (sbits(48), bits(128)) -> unit + +function wml128 (lin_addr, sailval) = { + assert(canonical_address_p(signed(lin_addr))); + let one_5_plus_lin_addr : sbits(49) = bits_of_int(15 + signed(lin_addr), 49); + if canonical_address_p(signed(one_5_plus_lin_addr)) then { + if app_view then { + wb(16, lin_addr, ":W", sailval) + } else { + let p_addr0 : bits(52) = la_to_pa(lin_addr, ":W"); + let one__plus_lin_addr : sbits(49) = bits_of_int(1 + signed(lin_addr), 49); + let p_addr1 : bits(52) = la_to_pa(truncate(one__plus_lin_addr, 48), ":W"); + let _2_plus_lin_addr : sbits(50) = bits_of_int(2 + signed(lin_addr), 50); + let p_addr2 : bits(52) = la_to_pa(truncate(_2_plus_lin_addr, 48), ":W"); + let three__plus_lin_addr : sbits(51) = bits_of_int(3 + signed(lin_addr), 51); + let p_addr3 : bits(52) = la_to_pa(truncate(three__plus_lin_addr, 48), ":W"); + let _4_plus_lin_addr : sbits(52) = bits_of_int(4 + signed(lin_addr), 52); + let p_addr4 : bits(52) = la_to_pa(truncate(_4_plus_lin_addr, 48), ":W"); + let five__plus_lin_addr : sbits(53) = bits_of_int(5 + signed(lin_addr), 53); + let p_addr5 : bits(52) = la_to_pa(truncate(five__plus_lin_addr, 48), ":W"); + let _6_plus_lin_addr : sbits(54) = bits_of_int(6 + signed(lin_addr), 54); + let p_addr6 : bits(52) = la_to_pa(truncate(_6_plus_lin_addr, 48), ":W"); + let seven__plus_lin_addr : sbits(55) = bits_of_int(7 + signed(lin_addr), 55); + let p_addr7 : bits(52) = la_to_pa(truncate(seven__plus_lin_addr, 48), ":W"); + let _8_plus_lin_addr : sbits(56) = bits_of_int(8 + signed(lin_addr), 56); + let p_addr8 : bits(52) = la_to_pa(truncate(_8_plus_lin_addr, 48), ":W"); + let nine__plus_lin_addr : sbits(57) = bits_of_int(9 + signed(lin_addr), 57); + let p_addr9 : bits(52) = la_to_pa(truncate(nine__plus_lin_addr, 48), ":W"); + let one_0_plus_lin_addr : sbits(58) = bits_of_int(10 + signed(lin_addr), 58); + let p_addr10 : bits(52) = la_to_pa(truncate(one_0_plus_lin_addr, 48), ":W"); + let one_1_plus_lin_addr : sbits(59) = bits_of_int(11 + signed(lin_addr), 59); + let p_addr11 : bits(52) = la_to_pa(truncate(one_1_plus_lin_addr, 48), ":W"); + let one_2_plus_lin_addr : sbits(60) = bits_of_int(12 + signed(lin_addr), 60); + let p_addr12 : bits(52) = la_to_pa(truncate(one_2_plus_lin_addr, 48), ":W"); + let one_3_plus_lin_addr : sbits(61) = bits_of_int(13 + signed(lin_addr), 61); + let p_addr13 : bits(52) = la_to_pa(truncate(one_3_plus_lin_addr, 48), ":W"); + let one_4_plus_lin_addr : sbits(62) = bits_of_int(14 + signed(lin_addr), 62); + let p_addr14 : bits(52) = la_to_pa(truncate(one_4_plus_lin_addr, 48), ":W"); + let one_5_plus_lin_addr : sbits(63) = bits_of_int(15 + signed(lin_addr), 63); + let p_addr15 : bits(52) = la_to_pa(truncate(one_5_plus_lin_addr, 48), ":W"); + let byte0 : bits(8) = sailval[7 .. 0]; + let byte1 : bits(8) = sailval[15 .. 8]; + let byte2 : bits(8) = sailval[23 .. 16]; + let byte3 : bits(8) = sailval[31 .. 24]; + let byte4 : bits(8) = sailval[39 .. 32]; + let byte5 : bits(8) = sailval[47 .. 40]; + let byte6 : bits(8) = sailval[55 .. 48]; + let byte7 : bits(8) = sailval[63 .. 56]; + let byte8 : bits(8) = sailval[71 .. 64]; + let byte9 : bits(8) = sailval[79 .. 72]; + let byte10 : bits(8) = sailval[87 .. 80]; + let byte11 : bits(8) = sailval[95 .. 88]; + let byte12 : bits(8) = sailval[103 .. 96]; + let byte13 : bits(8) = sailval[111 .. 104]; + let byte14 : bits(8) = sailval[119 .. 112]; + let byte15 : bits(8) = sailval[127 .. 120]; + bang_memi(sail_zero_extend(p_addr0, 64), byte0); + bang_memi(sail_zero_extend(p_addr1, 64), byte1); + bang_memi(sail_zero_extend(p_addr2, 64), byte2); + bang_memi(sail_zero_extend(p_addr3, 64), byte3); + bang_memi(sail_zero_extend(p_addr4, 64), byte4); + bang_memi(sail_zero_extend(p_addr5, 64), byte5); + bang_memi(sail_zero_extend(p_addr6, 64), byte6); + bang_memi(sail_zero_extend(p_addr7, 64), byte7); + bang_memi(sail_zero_extend(p_addr8, 64), byte8); + bang_memi(sail_zero_extend(p_addr9, 64), byte9); + bang_memi(sail_zero_extend(p_addr10, 64), byte10); + bang_memi(sail_zero_extend(p_addr11, 64), byte11); + bang_memi(sail_zero_extend(p_addr12, 64), byte12); + bang_memi(sail_zero_extend(p_addr13, 64), byte13); + bang_memi(sail_zero_extend(p_addr14, 64), byte14); + bang_memi(sail_zero_extend(p_addr15, 64), byte15) + } + } else { + x86_model_error("wml128") + } +} + +/*! Functions to read/write 8/16/32/64/128 bits into the memory: */ +val rml_size : ({|1, 2, 4, 6, 8, 10, 16|}, sbits(48), string) -> bits(128) + +function rml_size (nbytes, addr, r_x) = { + (match nbytes { + 1 => sail_zero_extend(rml08(addr, r_x), 128), + 2 => sail_zero_extend(rml16(addr, r_x), 128), + 4 => sail_zero_extend(rml32(addr, r_x), 128), + 6 => sail_zero_extend(rml48(addr, r_x), 128), + 8 => sail_zero_extend(rml64(addr, r_x), 128), + 10 => sail_zero_extend(rml80(addr, r_x), 128), + 16 => rml128(addr, r_x), + _ => { + if canonical_address_p(-1 + (nbytes + signed(addr))) then { + sail_mask(128, rb(nbytes, addr, r_x)) + } else { + x86_model_error("rml-size") + } + } + }) : bits(128) +} + +val riml_size : ({|1, 2, 4, 8|}, sbits(48), string) -> sbits(64) + +function riml_size (nbytes, addr, r_x) = { + (match nbytes { + 1 => sail_sign_extend(riml08(addr, r_x), 64), + 2 => sail_sign_extend(riml16(addr, r_x), 64), + 4 => sail_sign_extend(riml32(addr, r_x), 64), + 8 => riml64(addr, r_x), + _ => x86_model_error("riml-size") + }) : sbits(64) +} + +val wml_size : ({|1, 2, 4, 6, 8, 10, 16|}, sbits(48), nat) -> unit + +function wml_size (nbytes, addr, sailval) = { + (match nbytes { + 1 => wml08(addr, bits_of_int(sailval, 8)), + 2 => wml16(addr, bits_of_int(sailval, 16)), + 4 => wml32(addr, bits_of_int(sailval, 32)), + 6 => wml48(addr, bits_of_int(sailval, 48)), + 8 => wml64(addr, bits_of_int(sailval, 64)), + 10 => wml80(addr, bits_of_int(sailval, 80)), + 16 => wml128(addr, bits_of_int(sailval, 128)), + _ => { + if canonical_address_p(-1 + (nbytes + signed(addr))) then { + wb(nbytes, addr, ":W", bits_of_int(sailval, 8 * nbytes)) + } else { + x86_model_error("wml-size") + } + } + }) : unit +} + +val wiml_size : ({|1, 2, 4, 8|}, sbits(48), int) -> unit + +function wiml_size (nbytes, addr, sailval) = { + (match nbytes { + 1 => wiml08(addr, bits_of_int(sailval, 8)), + 2 => wiml16(addr, bits_of_int(sailval, 16)), + 4 => wiml32(addr, bits_of_int(sailval, 32)), + 8 => wiml64(addr, bits_of_int(sailval, 64)), + _ => x86_model_error("wiml-size") + }) : unit +} + +val write_canonical_address_to_memory_user_exec : (sbits(48), sbits(48)) -> option(string) + +function write_canonical_address_to_memory_user_exec (lin_addr, canonical_address) = { + assert(app_view & canonical_address_p(7 + signed(lin_addr))); + let canonical_address_low_nat : bits(32) = truncate(canonical_address, 32); + let canonical_address_high_int : sbits(32) = sail_sign_extend(sail_zero_extend(canonical_address[47 .. 32], 16), 32); + wml32(lin_addr, canonical_address_low_nat); + let next_addr : sbits(49) = bits_of_int(4 + signed(lin_addr), 49); + if not_bool(canonical_address_p(signed(next_addr))) then x86_model_error("wml64-canonical-address-user-view"); + wiml32(truncate(next_addr, 48), canonical_address_high_int); + None() : option(string) +} + +val write_canonical_address_to_memory : (sbits(48), sbits(48)) -> unit + +function write_canonical_address_to_memory (lin_addr, canonical_address) = { + let seven__plus_lin_addr : sbits(50) = bits_of_int(7 + signed(lin_addr), 50); + if canonical_address_p(signed(seven__plus_lin_addr)) then { + if app_view then { + wb(8, lin_addr, ":W", loghead(64, canonical_address)) + } else { + let canonical_address_unsigned_val : bits(64) = loghead(64, canonical_address); + wml64(lin_addr, canonical_address_unsigned_val) + } + } else { + x86_model_error("write-canonical-address-to-memory-error") + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/logging.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/logging.sail new file mode 100644 index 000000000..d1f6068c4 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/logging.sail @@ -0,0 +1,65 @@ +$ifndef __X86_LOGGING +$define __X86_LOGGING + +val printState : unit -> unit +function printState () = { + print_bits("rax = ", rgfi(0)); + print_bits("rbx = ", rgfi(3)); + print_bits("rcx = ", rgfi(1)); + print_bits("rdx = ", rgfi(2)); + print_bits("rsi = ", rgfi(6)); + print_bits("rdi = ", rgfi(7)); + print_bits("rbp = ", rgfi(5)); + print_bits("rsp = ", rgfi(4)); + print_bits("r8 = ", rgfi(8)); + print_bits("r9 = ", rgfi(9)); + print_bits("r10 = ", rgfi(10)); + print_bits("r11 = ", rgfi(11)); + print_bits("r12 = ", rgfi(12)); + print_bits("r13 = ", rgfi(13)); + print_bits("r14 = ", rgfi(14)); + print_bits("r15 = ", rgfi(15)); + + print_bits("rflags = ", rflags.bits); + + print_bits("rip = ", read_rip()); +} + +function log_gpr_write(idx) = { + match idx { + 0 => print_bits("rax = ", rgfi(0)), + 1 => print_bits("rcx = ", rgfi(1)), + 2 => print_bits("rdx = ", rgfi(2)), + 3 => print_bits("rbx = ", rgfi(3)), + 4 => print_bits("rsp = ", rgfi(4)), + 5 => print_bits("rbp = ", rgfi(5)), + 6 => print_bits("rsi = ", rgfi(6)), + 7 => print_bits("rdi = ", rgfi(7)), + 8 => print_bits("r8 = ", rgfi(8)), + 9 => print_bits("r9 = ", rgfi(9)), + 10 => print_bits("r10 = ", rgfi(10)), + 11 => print_bits("r11 = ", rgfi(11)), + 12 => print_bits("r12 = ", rgfi(12)), + 13 => print_bits("r13 = ", rgfi(13)), + 14 => print_bits("r14 = ", rgfi(14)), + 15 => print_bits("r15 = ", rgfi(15)) + } +} + +function log_rflags_write() = { + print_bits("rflags = ", rflags.bits); +} + +function log_rip_write() = { + print_bits("rip = ", read_rip()); +} + +function log_memory_read(addr, len, value) = { + print_endline(bits_str(read_rip()) + ": R " + bits_str(addr) + " " + dec_str(len) + " " + bits_str(value)) +} + +function log_memory_write(addr, len, value) = { + print_endline(bits_str(read_rip()) + ": W " + bits_str(addr) + " " + dec_str(len) + " " + bits_str(value)) +} + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/main.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/main.sail new file mode 100644 index 000000000..7bc360518 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/main.sail @@ -0,0 +1,60 @@ +register haltAddrReg : sbits(48) + +function clause __SetConfig("ha", value) = { haltAddrReg = get_slice_int(48, value, 0) } + +// Set 64 bit mode +val initialise_64_bit_mode : unit -> unit +function initialise_64_bit_mode () = { + let msr0 = read_msr(0); + let efer = Mk_ia32_eferbits(msr0[11 .. 0]); + let new_efer = [efer with lma = 0b1]; + write_msr(0, [msr0 with 11 .. 0 = new_efer.bits]); + seg_hidden_attrs[1] = [Mk_code_segment_descriptor_attributesbits(seg_hidden_attrs[1]) with l = 0b1].bits; +} + +function clause __SetConfig("set64bit", value) = { + // Ignore the value + initialise_64_bit_mode() +} +function clause __SetConfig(c, _) = throw(Emsg("Unrecognised config " + c)) +end __SetConfig + +val x86_step_print_halt : (sbits(48), bool, bool, int) -> bool +function x86_step_print_halt(haltAddr, printEachStep, printCount, count) = { + if read_rip() == haltAddr then { + return true + } else { + x86_fetch_decode_execute(); + if printEachStep then printState(); + if printCount then print_int("Steps = ", count + 1); + return false + } +} + +// Simulates the same ACL2 function +val x86_run_halt : (sbits(48), int, bool, bool, int) -> int +function x86_run_halt (haltAddr, maxSteps, printEachStep, printCount, count) = { + if maxSteps == 0 then { + return count + } else { + try { + let halt? : bool = x86_step_print_halt(haltAddr, printEachStep, printCount, count + 1); + if halt? then { + return count + } else { + return x86_run_halt(haltAddr, maxSteps - 1, printEachStep, printCount, count + 1) + } + } + catch { + Emsg(msg) => { print_endline(msg); return count } + } + } +} + +// A main function for C compilation +val main : unit -> unit +function main () = { + initialize_model(); + steps = x86_run_halt(haltAddrReg, 10000, not_bool(log_register_writes), false, 0); + print_int("Steps = ", steps); +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/memory_accessors.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/memory_accessors.sail new file mode 100644 index 000000000..1bf34a64a --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/memory_accessors.sail @@ -0,0 +1,113 @@ +$ifndef __X86_MEMORY_ACCESSORS +$define __X86_MEMORY_ACCESSORS + +$include "structures.sail" +$include "segmentation_structures.sail" +$include "linear_memory.sail" +$include "segmentation.sail" +// For prefixes bitfield definition: +$include "opcode_ext.sail" + +type address_size = {|2, 4, 8|} +type moffset_size = {|2, 4, 8|} +type base_reg_idx = range(0, 15) +type seg_reg_idx = range(0, 5) + +val address_aligned_p : (sbits(48), {|1, 2, 4, 6, 8, 10, 16, 32, 64|}, bool) -> bool + +val check_linear_memory_access : (proc_mode, address_size, {|1, 2, 4, 6, 8, 10, 16|}, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool, bool) -> unit + +function check_linear_memory_access (proc_mode, addr_size, nbytes, lin_addr, base_reg, seg_reg, access_kind, check_alignment?, mem_ptr?) = { + if not_bool(not_bool(check_alignment?) | address_aligned_p(truncate(lin_addr, 48), nbytes, mem_ptr?)) then { + x86_fault(":UNALIGNED-LINEAR-ADDRESS") + } else { + return () + } +} + +// TODO: Move the following functions? + +val select_base_register : (proc_mode, bits(8), bits(3), bits(2), sib) -> option(base_reg_idx) + +function select_base_register(proc_mode, rex_byte, r_m, mod_var, sib) = { + // TODO + None() +} + +val select_address_size : (proc_mode, option(prefixes)) -> address_size + +function select_address_size (proc_mode, prefixes) = { + let p4? : bool = match prefixes { + Some(prefixes) => 0x67 == prefixes[adr], + None() => false + }; + if in_64bit_mode(proc_mode) then { + if p4? then 4 else 8 + } else { + let cs_attr : bits(16) = seg_hidden_attrs[1]; + let cs_d : bits(1) = Mk_code_segment_descriptor_attributesbits(cs_attr)[d]; + if cs_d == 0b1 then { + if p4? then 2 else 4 + } else if p4? then 4 else 2 + } +} + +val select_moffset_size : (proc_mode, option(prefixes)) -> moffset_size + +function select_moffset_size (proc_mode, prefixes) = { + select_address_size (proc_mode, prefixes) +} + +val select_segment_register : (proc_mode, prefixes, bits(2), bits(3), sib) -> seg_reg_idx + +function select_segment_register (proc_mode, prefixes, mod_var, r_m, sib) = { + match prefixes[seg] { + 46 => 1, + 54 => 2, + 62 => 3, + 38 => 0, + 100 => 4, + 101 => 5, + _ => { + let addr_size : {|2, 4, 8|} = select_address_size(proc_mode, Some(prefixes)); + if addr_size == 2 then { + if not_bool(mod_var == 0b11) & (r_m == 0b010 | r_m == 0b011) then 2 else 3 + } else if (mod_var == 0b01 | mod_var == 0b10) & r_m == 0b101 | not_bool(mod_var == 0b11) & r_m == 0b100 & sib[base] == 0b100 then 2 else 3 + } + } +} + +val load_bytes_from_ea : forall 'nbytes, 'nbytes in {1, 2, 4, 6, 8, 10, 16}. + (proc_mode, address_size, int('nbytes), sbits(64), option(base_reg_idx), seg_reg_idx, string, bool, bool) -> bits(8 * 'nbytes) + +function load_bytes_from_ea (proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?) = { + let cs_attrs = Mk_code_segment_descriptor_attributesbits(seg_hidden_attrs[1]); + if not_bool(in_64bit_mode(proc_mode)) & seg_reg == 1 & r_x == ":R" & cs_attrs[r] == 0b0 then { + x86_fault(":EXECUTE-ONLY-CODE-SEGMENT") + } else { + let lin_addr : sbits(64) = ea_to_la(proc_mode, eff_addr, seg_reg, nbytes); + check_linear_memory_access(proc_mode, addr_size, nbytes, lin_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?); + // Use rb directly instead of rml_size; it returns a + // bitvector of the right width and performs the same + // checks for canonical addresses that rml_size does. + rb(nbytes, lin_addr, r_x) + } +} + +val store_bytes_to_ea : forall 'nbytes, 'nbytes in {1, 2, 4, 6, 8, 10, 16}. + (proc_mode, address_size, int('nbytes), sbits(64), option(base_reg_idx), seg_reg_idx, bits(8 * 'nbytes), bool, bool) -> unit + +function store_bytes_to_ea (proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, data, check_alignment?, mem_ptr?) = { + let seg_attrs = Mk_data_segment_descriptor_attributesbits(seg_hidden_attrs[seg_reg]); + if not_bool(in_64bit_mode(proc_mode)) & (seg_reg == 1 | seg_attrs[w] == 0b0) then { + x86_fault(":NON-WRITABLE-SEGMENT") + } else { + let lin_addr : sbits(64) = ea_to_la(proc_mode, eff_addr, seg_reg, nbytes); + check_linear_memory_access(proc_mode, addr_size, nbytes, lin_addr, base_reg, seg_reg, ":W", check_alignment?, mem_ptr?); + wb(nbytes, lin_addr, ":W", data) + } +} + +function observe_mem_write (addr, len) = () + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/modes.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/modes.sail new file mode 100644 index 000000000..0b603666a --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/modes.sail @@ -0,0 +1,37 @@ +$include "./register_readers_and_writers.sail" + +/*! Check whether we are in 64-bit mode. +

+ Given the modeling assumption stated in @ ( see x86-modes ) , + this predicate discriminates between + 64-bit mode and the other two modes ( collectively, 32-bit mode ) . + Based on Intel manual, Mar ' 17, Vol. 3A, Sec. 2.2 ( near Fig. 2-3 ) , + the discrimination is based on the IA32_EFER.LME and CS.L bits: + if they are both 1, we are in 64-bit mode, + otherwise we are in 32-bit mode + ( protected mode if IA32_EFER.LME is 0, + compatibility mode if IA32_EFER.LME is 1 and CS.L is 0; + note that when IA32_EFER.LME is 0, CS.L should be 0, + according to Intel manual, Mar ' 17, Vol. 3A, Sec. 3.4.5 ) . +

+

+ This predicate does not include state invariants such as + the constraints imposed by the 64-bit mode consistency checks + described in Intel manual, Mar ' 17, Vol. 3A, Sec. 9.8.5. +

+

+ This predicate is useful as a hypothesis of theorems + about either 64-bit or 32-bit mode. +

+

+ Since @ ( ' ( xr :msr ... x86 ) ' ) returns a 64-bit value + but the IA32_EFER register consists of 12 bits. + So we use @ ( tsee n12 ) to make @ ( ' ia32_eferBits ' ) functions applicable. +

*/ +function n64_bit_modep () = { + let ia32_efer : bits(12) = truncate(read_msr(0), 12); + let ia32_efer_lma : bits(1) = Mk_ia32_eferbits(ia32_efer)[lma]; + let cs_attr : bits(16) = seg_hidden_attrs[1]; + let cs_l : bits(1) = Mk_code_segment_descriptor_attributesbits(cs_attr)[l]; + ia32_efer_lma == 0b1 & cs_l == 0b1 +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/mov.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/mov.sail new file mode 100644 index 000000000..1b0cf2409 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/mov.sail @@ -0,0 +1,292 @@ + +/*! Move scalar single/double precision floating-point values +

Op/En = RM: [OP XMM, XMM/M]

+ F3 0F 10: MOVSS xmm1, xmm2/m32
+ F2 0F 10: MOVSD xmm1, xmm2/m64
*/ +val x86_movss_movsd_op_en_rm : (range(0, 1), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movss_movsd_op_en_rm (sp_dp, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVSS/MOVSD-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let operand_size : {|4, 8|} = { + if sp_dp == 1 then 8 else 4 + }; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (xmm_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let operand_size : {|4, 8, 16|} = { + if mod_var == 0b11 then { + operand_size + } else 16 + }; + write_xmmi_size(bits_of_int(operand_size, 5), xmm_index, unsigned(xmm_mem)); + write_iptr(proc_mode, temp_rip) +} + +/*! Move scalar single/double precision floating-point values +

Op/En = MR: [OP XMM/M, XMM]

+ F3 0F 11: MOVSS xmm2/m32, xmm1
+ F2 0F 11: MOVSD xmm2/m64, xmm1
*/ +val x86_movss_movsd_op_en_mr : (range(0, 1), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movss_movsd_op_en_mr (sp_dp, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVSS/MOVSD-OP/EN-MR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let operand_size : {|4, 8|} = { + if sp_dp == 1 then 8 else 4 + }; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(bits_of_int(operand_size, 5), xmm_index); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000) + } + }; + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let inst_ac? : bool = true; + x86_operand_to_xmm_mem(proc_mode, operand_size, inst_ac?, xmm, seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} + +/*! Move aligned packed single/double precision floating-point values +

Op/En = RM: [OP XMM, XMM/M]

+ 0F 28: MOVAPS xmm1, xmm2/m128
+ 66 0F 28: MOVAPD xmm1, xmm2/m128
*/ +val x86_movaps_movapd_op_en_rm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movaps_movapd_op_en_rm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVAPS/MOVAPD-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (xmm_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 16, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + write_xmmi_size(0b10000, xmm_index, unsigned(xmm_mem)); + write_iptr(proc_mode, temp_rip) +} + +/*! Move aligned packed single/double precision floating-point values +

Op/En = MR: [OP XMM/M, XMM]

+ 0F 29: MOVAPS xmm2/m128, xmm1
+ 66 0F 29: MOVAPD xmm2/m128, xmm1
*/ +val x86_movaps_movapd_op_en_mr : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movaps_movapd_op_en_mr (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVAPS/MOVAPD-OP/EN-MR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(0b10000, xmm_index); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000) + } + }; + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let inst_ac? : bool = true; + x86_operand_to_xmm_mem(proc_mode, 16, inst_ac?, xmm, seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} + +/*!

Op/En = RM: [OP XMM, XMM/M]

+ 0F 10: MOVUPS xmm1, xmm2/m128
+ 66 0F 10: MOVUPD xmm1, xmm2/m128
+ F3 0F 6F: MOVDQU xmm1, xmm2/m128
+ +

Note: The MOVDQU, MOVUPS, and MOVUPD instructions perform 128-bit + unaligned loads or stores. They do not generate general-protection + exceptions ( #GP ) when operands are not aligned on a 16-byte + boundary. If alignment checking is enabled, alignment-check + exceptions ( #AC ) may or may not be generated depending on processor + implementation when data addresses are not aligned on an 8-byte + boundary.

*/ +val x86_movups_movupd_movdqu_op_en_rm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movups_movupd_movdqu_op_en_rm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (xmm_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 16, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + write_xmmi_size(0b10000, xmm_index, unsigned(xmm_mem)); + write_iptr(proc_mode, temp_rip) +} + +/*!

Op/En = MR: [OP XMM/M, XMM]

+ 0F 11: MOVUPS xmm2/m128, xmm1
+ 66 0F 11: MOVUPD xmm2/m128, xmm1
+ F3 0F 7F: MOVDQU xmm2/m128, xmm1
*/ +val x86_movups_movupd_movdqu_op_en_mr : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movups_movupd_movdqu_op_en_mr (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVUPS/MOVUPD/MOVDQU-OP/EN-MR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(0b10000, xmm_index); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000) + } + }; + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let inst_ac? : bool = true; + x86_operand_to_xmm_mem(proc_mode, 16, inst_ac?, xmm, seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} + +/*! Move low packed single/double precision floating-point values +

Op/En = RM: [OP XMM, M]

+ 0F 12: MOVLPS xmm, m64
+ 66 0F 12: MOVLPD xmm, m64
*/ +val x86_movlps_movlpd_op_en_rm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movlps_movlpd_op_en_rm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVLPS/MOVLPD-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 8, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let mem : bits(64) = truncate(mem, 64); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + write_xmmi_size(0b01000, xmm_index, unsigned(mem)); + write_iptr(proc_mode, temp_rip) +} + +/*! Move low packed single/double precision floating-point values +

Op/En = MR: [OP M, XMM]

+ 0F 13: MOVLPS m64, xmm
+ 66 0F 13: MOVLPD m64, xmm
*/ +val x86_movlps_movlpd_op_en_mr : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movlps_movlpd_op_en_mr (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVLPS/MOVLPD-OP/EN-MR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(64) = truncate(xmmi_size(0b01000, xmm_index), 64); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let inst_ac? : bool = true; + x86_operand_to_xmm_mem(proc_mode, 8, inst_ac?, sail_zero_extend(xmm, 128), seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} + +/*! Move high packed single/double precision floating-point values +

Op/En = RM: [OP XMM, M]

+ 0F 16: MOVHPS xmm, m64
+ 66 0F 16: MOVHPD xmm, m64
*/ +val x86_movhps_movhpd_op_en_rm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movhps_movhpd_op_en_rm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVHPS/MOVHPD-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (mem, increment_rip_by, v_addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 8, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let mem : bits(64) = truncate(mem, 64); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let low_qword : bits(64) = truncate(xmmi_size(0b01000, xmm_index), 64); + let result : bits(128) = mem @ low_qword; + write_xmmi_size(0b10000, xmm_index, unsigned(result)); + write_iptr(proc_mode, temp_rip) +} + +/*! Move high packed single/double precision floating-point values +

Op/En = MR: [OP M, XMM]

+ 0F 17: MOVHPS m64, xmm
+ 66 0F 17: MOVHPD m64, xmm
*/ +val x86_movhps_movhpd_op_en_mr : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movhps_movhpd_op_en_mr (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVHPS/MOVHPD-OP/EN-MR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(0b10000, xmm_index); + let high_qword : bits(64) = xmm[127 .. 64]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let inst_ac? : bool = true; + x86_operand_to_xmm_mem(proc_mode, 8, inst_ac?, sail_zero_extend(high_qword, 128), seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/move.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/move.sail new file mode 100644 index 000000000..86407245b --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/move.sail @@ -0,0 +1,357 @@ + +val x86_mov_op_en_mr : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mov_op_en_mr (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOV-OP/EN-MR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = opcode == 0x88; + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let register_var : bits(64) = rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b10), rex_byte); + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000) + } + }; + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let inst_ac? : bool = true; + x86_operand_to_reg_mem(proc_mode, operand_size, inst_ac?, false, sail_zero_extend(register_var, 128), seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} + +val x86_mov_op_en_rm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mov_op_en_rm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOV-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = opcode == 0x8a; + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + write_rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b10), truncate(reg_mem, 64), rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_mov_op_en_fd : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mov_op_en_fd (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOV-OP/EN-FD"; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = opcode == 0xa0; + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let offset_size : moffset_size = select_moffset_size(proc_mode, Some(prefixes)); + let offset : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), offset_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(offset_size, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, 0b00, 0b000, sib); + let inst_ac? : bool = alignment_checking_enabled_p(); + let data : bits(128) = rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), operand_size, offset, None(), seg_reg, ":R", inst_ac?, false); + write_rgfi_size(bits_of_int(operand_size, 4), 0x0, truncate(data, 64), rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_mov_op_en_td : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mov_op_en_td (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOV-OP/EN-TD"; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = opcode == 0xa2; + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let offset_size : moffset_size = select_moffset_size(proc_mode, Some(prefixes)); + let offset : sbits(64) = rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), offset_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(offset_size, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, 0b00, 0b000, sib); + let data : bits(64) = rgfi_size(bits_of_int(operand_size, 4), 0x0, rex_byte); + let inst_ac? : bool = true; + x86_operand_to_reg_mem(proc_mode, operand_size, inst_ac?, false, sail_zero_extend(data, 128), seg_reg, offset, prefixes, rex_byte, 0b000, 0b00, sib); + write_iptr(proc_mode, temp_rip) +} + +val x86_mov_op_en_oi : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mov_op_en_oi (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOV-OP/EN-OI"; + let byte_operand? : bool = 176 <= unsigned(opcode) & unsigned(opcode) <= 183; + let operand_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let imm : bits(128) = rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), operand_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(operand_size, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let reg : bits(3) = truncate(logand(0x07, opcode), 3); + write_rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b00), truncate(imm, 64), rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_mov_op_en_mi : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mov_op_en_mi (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOV-OP/EN-MI"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = opcode == 0xc6; + let imm_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, true, prefixes, false, false, false); + let reg_mem_size : {|1, 2, 4, 8|} = { + if opcode == 0xc7 & logbitp(3, rex_byte) then 8 else { + imm_size + } + }; + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, bits_of_int(imm_size, 3)) + } + }; + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let imm : bits(128) = rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), imm_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(imm_size, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let imm : bits(128) = { + if reg_mem_size == 8 then { + sail_zero_extend(sail_sign_extend(truncate(imm, 32), 64), 128) + } else { + imm + } + }; + let inst_ac? : bool = true; + x86_operand_to_reg_mem(proc_mode, reg_mem_size, inst_ac?, false, imm, seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} + +val x86_lea : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_lea (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-LEA"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p4? : bool = 0x67 == prefixes[adr]; + let register_size : {|2, 4, 8|} = check_range(2, 8, select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false)); + let (m, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let m : bits(64) = sail_mask(64, trunc_signed(register_size, m)); + write_rgfi_size(bits_of_int(register_size, 4), reg_index(reg, rex_byte, 0b10), m, rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_movsx : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movsx (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVSX"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let reg_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, true, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let register_size : {|1, 2, 4, 8|} = { + if logbitp(3, rex_byte) then 8 else { + reg_mem_size + } + }; + let reg_mem : bits(128) = { + if register_size == 8 then { + sail_zero_extend(sail_sign_extend(truncate(reg_mem, 32), 64), 128) + } else { + reg_mem + } + }; + write_rgfi_size(bits_of_int(register_size, 4), reg_index(reg, rex_byte, 0b10), truncate(reg_mem, 64), rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_movsxd : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movsxd (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVSXD"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let reg_mem_size : {|1, 2|} = { + if opcode == 0xbe then 1 else 2 + }; + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let register_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false); + let reg_mem : bits(128) = { + match reg_mem_size { + 1 => sail_zero_extend(sail_mask(64, signed_bitslice(truncate(reg_mem, 8), 0, ash(register_size, 3))), 128), + 2 => { + (match register_size { + 2 => reg_mem, + _ => sail_zero_extend(sail_mask(64, signed_bitslice(truncate(reg_mem, 16), 0, ash(register_size, 3))), 128) + }) : bits(128) + } + } + }; + write_rgfi_size(bits_of_int(register_size, 4), reg_index(reg, rex_byte, 0b10), truncate(reg_mem, 64), rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_movzx : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movzx (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVZX"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let reg_mem_size : {|1, 2|} = { + if opcode == 0xb6 then 1 else 2 + }; + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let register_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false); + write_rgfi_size(bits_of_int(register_size, 4), reg_index(reg, rex_byte, 0b10), truncate(reg_mem, 64), rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_mov_control_regs_op_en_mr : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mov_control_regs_op_en_mr (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOV-CONTROL-REGS-OP/EN-MR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let ctr_index : bits(4) = { + if logbitp(2, rex_byte) & reg == 0b000 then 0x8 else { + sail_zero_extend(reg, 4) + } + }; + let operand_size : {|4, 8|} = { + if in_64bit_mode(proc_mode) then 8 else 4 + }; + let ctr_val : bits(64) = ctrs[unsigned(ctr_index)]; + let ctr_val : bits(64) = { + if operand_size == 4 then { + sail_zero_extend(truncate(ctr_val, 32), 64) + } else { + ctr_val + } + }; + write_rgfi_size(bits_of_int(operand_size, 4), reg_index(r_m, rex_byte, 0b00), ctr_val, rex_byte); + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with cf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with pf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with af = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with zf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with sf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with of = sailval] in rflags = new_rflags; + write_iptr(proc_mode, temp_rip) +} + +val x86_movd_movq_to_xmm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movd_movq_to_xmm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVD/MOVQ-TO-XMM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let operand_size : {|4, 8|} = { + if logbitp(3, rex_byte) then 8 else 4 + }; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + write_xmmi_size(bits_of_int(operand_size, 5), reg_index(reg, rex_byte, 0b10), unsigned(reg_mem)); + write_iptr(proc_mode, temp_rip) +} + +val x86_movd_movq_from_xmm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_movd_movq_from_xmm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MOVD/MOVQ-FROM-XMM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let operand_size : {|4, 8|} = { + if logbitp(3, rex_byte) then 8 else 4 + }; + let register_var : bits(128) = xmmi_size(bits_of_int(operand_size, 5), reg_index(reg, rex_byte, 0b10)); + let (addr, increment_rip_by) : (sbits(64), {|0, 1, 2, 4|}) = { + if mod_var == 0b11 then { + (0x0000000000000000, 0) + } else { + x86_effective_addr(proc_mode, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000) + } + }; + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let inst_ac? : bool = true; + x86_operand_to_reg_mem(proc_mode, operand_size, inst_ac?, false, register_var, seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply.sail new file mode 100644 index 000000000..449103a88 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply.sail @@ -0,0 +1,235 @@ +$include "./multiply_spec.sail" + +/*!

Op/En: M

+ +

F6/4:
+ MUL r/m8: AX := AL * r/m8

+ + F7/4:
+ MUL r/m16: DX:AX := AX * r/m16
+ MUL r/m32: EDX:EAX := EAX * r/m32
+ MUL r/m64: RDX:RAX := RAX * r/m64

*/ +val x86_mul : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_mul (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-MUL"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let select_byte_operand : bool = opcode == 0xf6; + let reg_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, select_byte_operand, rex_byte, false, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let rax_var : bits(64) = rgfi_size(bits_of_int(reg_mem_size, 4), 0x0, rex_byte); + let (product_high, product_low, product) : (bits(64), bits(64), bits(128)) = mul_spec(reg_mem_size, rax_var, truncate(reg_mem, 64)); + (match reg_mem_size { + 1 => write_rgfi_size(0x2, 0x0, truncate(product, 64), rex_byte), + _ => { + write_rgfi_size(bits_of_int(reg_mem_size, 4), 0x0, product_low, rex_byte); + write_rgfi_size(bits_of_int(reg_mem_size, 4), 0x2, product_high, rex_byte) + } + }) : unit; + if product_high == 0x0000000000000000 then { + { + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with cf = 0b0] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with pf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with af = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with zf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with sf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with of = 0b0]; + rflags = new_rflags + } + } else { + { + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with cf = 0b1] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with pf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with af = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with zf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with sf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with of = 0b1]; + rflags = new_rflags + } + }; + write_iptr(proc_mode, temp_rip) +} + +/*!

Op/En: M

+ +

F6/5:
+ IMUL r/m8: AX := AL * r/m8

+ + F7/5:
+ IMUL r/m16: DX:AX := AX * r/m16
+ IMUL r/m32: EDX:EAX := EAX * r/m32
+ IMUL r/m64: RDX:RAX := RAX * r/m64

*/ +val x86_imul_op_en_m : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_imul_op_en_m (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-IMUL-OP/EN-M"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let select_byte_operand : bool = opcode == 0xf6; + let reg_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, select_byte_operand, rex_byte, false, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let rax_var : bits(64) = rgfi_size(bits_of_int(reg_mem_size, 4), 0x0, rex_byte); + let (product_high, product_low, product, cf_and_of) : (bits(64), bits(64), bits(128), bits(1)) = imul_spec(reg_mem_size, rax_var, truncate(reg_mem, 64)); + (match reg_mem_size { + 1 => write_rgfi_size(0x2, 0x0, truncate(product, 64), rex_byte), + _ => { + write_rgfi_size(bits_of_int(reg_mem_size, 4), 0x0, product_low, rex_byte); + write_rgfi_size(bits_of_int(reg_mem_size, 4), 0x2, product_high, rex_byte) + } + }) : unit; + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with cf = cf_and_of] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with pf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with af = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with zf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with sf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with of = cf_and_of] in rflags = new_rflags; + write_iptr(proc_mode, temp_rip) +} + +/*!

Op/En: RM

+ +

0F AF:
+ IMUL r16, r/m16: r16 := r16 * r/m16
+ IMUL r32, r/m32: r32 := r32 * r/m32
+ IMUL r64, r/m64: r64 := r64 * r/m64

*/ +val x86_imul_op_en_rm : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_imul_op_en_rm (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-IMUL-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let reg_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let register_var : bits(64) = rgfi_size(bits_of_int(reg_mem_size, 4), reg_index(reg, rex_byte, 0b10), rex_byte); + let (product_high, product_low, product, cf_and_of) : (bits(64), bits(64), bits(128), bits(1)) = imul_spec(reg_mem_size, truncate(reg_mem, 64), register_var); + write_rgfi_size(bits_of_int(reg_mem_size, 4), reg_index(reg, rex_byte, 0b10), product_low, rex_byte); + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with cf = cf_and_of] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with pf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with af = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with zf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with sf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with of = cf_and_of] in rflags = new_rflags; + write_iptr(proc_mode, temp_rip) +} + +/*!

Op/En: RMI

+ +

6B ib:
+ IMUL r16, r/m16, imm8
+ IMUL r32, r/m32, imm8
+ IMUL r64, r/m64, imm8

+ + 69 iw:
+ IMUL r16, r/m16, imm16
+ IMUL r32, r/m32, imm32
+ IMUL r64, r/m64, imm32

*/ +val x86_imul_op_en_rmi : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_imul_op_en_rmi (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-IMUL-OP/EN-RMI"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let reg_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false); + let imm_size : {|1, 2, 4|} = { + if opcode == 0x6b then 1 else if reg_mem_size == 2 then 2 else 4 + }; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, bits_of_int(imm_size, 3)); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let imm : bits(32) = truncate(rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), imm_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), 32); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(imm_size, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let (product_high, product_low, product, cf_and_of) : (bits(64), bits(64), bits(128), bits(1)) = imul_spec(reg_mem_size, truncate(reg_mem, 64), sail_sign_extend(imm, 64)); + write_rgfi_size(bits_of_int(reg_mem_size, 4), reg_index(reg, rex_byte, 0b10), product_low, rex_byte); + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with cf = cf_and_of] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with pf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with af = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with zf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let sailval : bits(1) = undef_flg() in + let new_rflags : rflagsbits = [rflags_var with sf = sailval] in rflags = new_rflags; + let rflags_var : rflagsbits = rflags in + let new_rflags : rflagsbits = [rflags_var with of = cf_and_of] in rflags = new_rflags; + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply_spec.sail new file mode 100644 index 000000000..31da6dd92 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/multiply_spec.sail @@ -0,0 +1,136 @@ + +val mul_spec_8 : (bits(8), bits(8)) -> (bits(8), bits(8), bits(16)) + +function mul_spec_8 (dst, src) = { + let product : bits(16) = bits_of_int(unsigned(dst) * unsigned(src), 16); + let product_high : bits(8) = product[15 .. 8]; + let product_low : bits(8) = product[7 .. 0]; + (product_high, product_low, product) +} + +val mul_spec_16 : (bits(16), bits(16)) -> (bits(16), bits(16), bits(32)) + +function mul_spec_16 (dst, src) = { + let product : bits(32) = bits_of_int(unsigned(dst) * unsigned(src), 32); + let product_high : bits(16) = product[31 .. 16]; + let product_low : bits(16) = product[15 .. 0]; + (product_high, product_low, product) +} + +val mul_spec_32 : (bits(32), bits(32)) -> (bits(32), bits(32), bits(64)) + +function mul_spec_32 (dst, src) = { + let product : bits(64) = bits_of_int(unsigned(dst) * unsigned(src), 64); + let product_high : bits(32) = product[63 .. 32]; + let product_low : bits(32) = product[31 .. 0]; + (product_high, product_low, product) +} + +val mul_spec_64 : (bits(64), bits(64)) -> (bits(64), bits(64), bits(128)) + +function mul_spec_64 (dst, src) = { + let product : bits(128) = bits_of_int(unsigned(dst) * unsigned(src), 128); + let product_high : bits(64) = product[127 .. 64]; + let product_low : bits(64) = product[63 .. 0]; + (product_high, product_low, product) +} + +/*! Specification for the @ ( ' MUL ' ) ( unsigned multiply ) instruction */ +val mul_spec : ({|1, 2, 4, 8|}, bits(64), bits(64)) -> (bits(64), bits(64), bits(128)) + +function mul_spec (size, dst, src) = { + (match size { + 1 => { + let (elem0, elem1, elem2) : (bits(8), bits(8), bits(16)) = mul_spec_8(truncate(dst, 8), truncate(src, 8)); + (sail_zero_extend(elem0, 64), sail_zero_extend(elem1, 64), sail_zero_extend(elem2, 128)) + }, + 2 => { + let (elem0, elem1, elem2) : (bits(16), bits(16), bits(32)) = mul_spec_16(truncate(dst, 16), truncate(src, 16)); + (sail_zero_extend(elem0, 64), sail_zero_extend(elem1, 64), sail_zero_extend(elem2, 128)) + }, + 4 => { + let (elem0, elem1, elem2) : (bits(32), bits(32), bits(64)) = mul_spec_32(truncate(dst, 32), truncate(src, 32)); + (sail_zero_extend(elem0, 64), sail_zero_extend(elem1, 64), sail_zero_extend(elem2, 128)) + }, + 8 => mul_spec_64(dst, src), + _ => (0x0000000000000000, 0x0000000000000000, 0x00000000000000000000000000000000) + }) : (bits(64), bits(64), bits(128)) +} + +val imul_spec_8 : (bits(8), bits(8)) -> (bits(8), bits(8), bits(16), bits(1)) + +function imul_spec_8 (dst, src) = { + let dst_int : sbits(8) = dst; + let src_int : sbits(8) = src; + let product_int : sbits(16) = bits_of_int(signed(dst_int) * signed(src_int), 16); + let product : bits(16) = product_int; + let product_high : bits(8) = product[15 .. 8]; + let product_low : bits(8) = product[7 .. 0]; + let product_low_int : sbits(8) = product_low; + let cf_and_of : bits(1) = bool_to_bits(not_bool(sail_sign_extend(product_low_int, 16) == product_int)); + (product_high, product_low, product, cf_and_of) +} + +val imul_spec_16 : (bits(16), bits(16)) -> (bits(16), bits(16), bits(32), bits(1)) + +function imul_spec_16 (dst, src) = { + let dst_int : sbits(16) = dst; + let src_int : sbits(16) = src; + let product_int : sbits(32) = bits_of_int(signed(dst_int) * signed(src_int), 32); + let product : bits(32) = product_int; + let product_high : bits(16) = product[31 .. 16]; + let product_low : bits(16) = product[15 .. 0]; + let product_low_int : sbits(16) = product_low; + let cf_and_of : bits(1) = bool_to_bits(not_bool(sail_sign_extend(product_low_int, 32) == product_int)); + (product_high, product_low, product, cf_and_of) +} + +val imul_spec_32 : (bits(32), bits(32)) -> (bits(32), bits(32), bits(64), bits(1)) + +function imul_spec_32 (dst, src) = { + let dst_int : sbits(32) = dst; + let src_int : sbits(32) = src; + let product_int : sbits(64) = bits_of_int(signed(dst_int) * signed(src_int), 64); + let product : bits(64) = product_int; + let product_high : bits(32) = product[63 .. 32]; + let product_low : bits(32) = product[31 .. 0]; + let product_low_int : sbits(32) = product_low; + let cf_and_of : bits(1) = bool_to_bits(not_bool(sail_sign_extend(product_low_int, 64) == product_int)); + (product_high, product_low, product, cf_and_of) +} + +val imul_spec_64 : (bits(64), bits(64)) -> (bits(64), bits(64), bits(128), bits(1)) + +function imul_spec_64 (dst, src) = { + let dst_int : sbits(64) = dst; + let src_int : sbits(64) = src; + let product_int : sbits(128) = bits_of_int(signed(dst_int) * signed(src_int), 128); + let product : bits(128) = product_int; + let product_high : bits(64) = product[127 .. 64]; + let product_low : bits(64) = product[63 .. 0]; + let product_low_int : sbits(64) = product_low; + let cf_and_of : bits(1) = bool_to_bits(not_bool(sail_sign_extend(product_low_int, 128) == product_int)); + (product_high, product_low, product, cf_and_of) +} + +/*! Specification for the @ ( ' IMUL ' ) ( unsigned imultiply ) instruction */ +val imul_spec : ({|1, 2, 4, 8|}, bits(64), bits(64)) -> (bits(64), bits(64), bits(128), bits(1)) + +function imul_spec (size, dst, src) = { + (match size { + 1 => { + let (elem0, elem1, elem2, elem3) : (bits(8), bits(8), bits(16), bits(1)) = imul_spec_8(truncate(dst, 8), truncate(src, 8)); + (sail_zero_extend(elem0, 64), sail_zero_extend(elem1, 64), sail_zero_extend(elem2, 128), elem3) + }, + 2 => { + let (elem0, elem1, elem2, elem3) : (bits(16), bits(16), bits(32), bits(1)) = imul_spec_16(truncate(dst, 16), truncate(src, 16)); + (sail_zero_extend(elem0, 64), sail_zero_extend(elem1, 64), sail_zero_extend(elem2, 128), elem3) + }, + 4 => { + let (elem0, elem1, elem2, elem3) : (bits(32), bits(32), bits(64), bits(1)) = imul_spec_32(truncate(dst, 32), truncate(src, 32)); + (sail_zero_extend(elem0, 64), sail_zero_extend(elem1, 64), sail_zero_extend(elem2, 128), elem3) + }, + 8 => imul_spec_64(dst, src), + _ => (0x0000000000000000, 0x0000000000000000, 0x00000000000000000000000000000000, 0b0) + }) : (bits(64), bits(64), bits(128), bits(1)) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/opcode_ext.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/opcode_ext.sail new file mode 100644 index 000000000..7efca24a7 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/opcode_ext.sail @@ -0,0 +1,81 @@ +$ifndef __X86_OPCODE_EXT +$define __X86_OPCODE_EXT + +$include "structures.sail" + +enum proc_mode = { + Mode_64bit, + Mode_Compatibility, + Mode_Protected, + Mode_Real, + Mode_SMM +} + +function in_64bit_mode(proc_mode) : proc_mode -> bool = match proc_mode { + Mode_64bit => true, + _ => false +} +function in_compatibility_mode(proc_mode) : proc_mode -> bool = match proc_mode { + Mode_Compatibility => true, + _ => false +} +function in_protected_mode(proc_mode) : proc_mode -> bool = match proc_mode { + Mode_Protected => true, + _ => false +} +function in_real_mode(proc_mode) : proc_mode -> bool = match proc_mode { + Mode_Real => true, + _ => false +} +function in_system_management_mode(proc_mode) : proc_mode -> bool = match proc_mode { + Mode_SMM => true, + _ => false +} + +/*! Returns the current mode of operation of the x86 machine +

We only support 64-bit, Compatibility, and 32-bit Protected Modes + for now.

+

See @ ( see x86-modes ) .

*/ +val x86_operation_mode : unit -> proc_mode + +function x86_operation_mode () = { + if n64_bit_modep() then Mode_64bit else Mode_Compatibility +} + +bitfield prefixes : bits(52) = + {nxt : 51..44, adr : 43..36, opr : 35..28, seg : 27..20, rep : 19..12, lck : 11..4, num : 3..0} + +val is_ext_prefix_byte : (proc_mode, prefixes, bits(8), range(0, 15), bits(8)) -> bool +function is_ext_prefix_byte(proc_mode, prefixes, rex_byte, cnt, byte) = false + +val process_ext_prefix_byte : (proc_mode, prefixes, bits(8), range(0, 15), bits(8)) -> (prefixes, bits(8), bool) +function process_ext_prefix_byte(proc_mode, prefixes, rex_byte, cnt, byte) = (prefixes, rex_byte, false) + +val ext_one_byte_opcode_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> bool +function ext_one_byte_opcode_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = false + +val ext_two_byte_opcode_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), bits(8), modr_m, sib) -> bool +function ext_two_byte_opcode_execute(proc_mode, start_rip, temp_rip, prefixes, mandatory_prefix, rex_byte, opcode, modr_m, sib) = false + +val ext_vex_0f_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), vex_prefixes, bits(8), modr_m, sib) -> bool +function ext_vex_0f_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, vex_prefixes, opcode, modr_m, sib) = false + +val ext_vex_0f38_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), vex_prefixes, bits(8), modr_m, sib) -> bool +function ext_vex_0f38_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, vex_prefixes, opcode, modr_m, sib) = false + +val ext_vex_0f3a_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), vex_prefixes, bits(8), modr_m, sib) -> bool +function ext_vex_0f3a_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, vex_prefixes, opcode, modr_m, sib) = false + +val ext_evex_0f_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), evex_prefixes, bits(8), modr_m, sib) -> bool +function ext_evex_0f_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, evex_prefixes, opcode, modr_m, sib) = false + +val ext_evex_0f38_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), evex_prefixes, bits(8), modr_m, sib) -> bool +function ext_evex_0f38_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, evex_prefixes, opcode, modr_m, sib) = false + +val ext_evex_0f3a_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), evex_prefixes, bits(8), modr_m, sib) -> bool +function ext_evex_0f3a_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, evex_prefixes, opcode, modr_m, sib) = false + +val unimplemented_x86_syscall_app_view : (proc_mode, sbits(48), sbits(48), bits(52), bits(8), bits(8), bits(8), bits(8)) -> unit +function unimplemented_x86_syscall_app_view (_, _, _, _, _, _, _, _) = throw(Syscall()) + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/or_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/or_spec.sail new file mode 100644 index 000000000..36797fdda --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/or_spec.sail @@ -0,0 +1,56 @@ + +val gpr_or_spec_1 : (bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_or_spec_1 (dst, src, input_rflags) = { + let result : bits(8) = logior(dst, src)[7 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_or_spec_2 : (bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_or_spec_2 (dst, src, input_rflags) = { + let result : bits(16) = logior(dst, src)[15 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_or_spec_4 : (bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_or_spec_4 (dst, src, input_rflags) = { + let result : bits(32) = logior(dst, src)[31 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_or_spec_8 : (bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_or_spec_8 (dst, src, input_rflags) = { + let result : bits(64) = logior(dst, src)[63 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/physical_memory.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/physical_memory.sail new file mode 100644 index 000000000..455573ad6 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/physical_memory.sail @@ -0,0 +1,57 @@ +$include "./modes.sail" + +val physical_address_p : int -> bool + +function physical_address_p phy_addr = { + unsigned_byte_p(52, phy_addr) +} + +val rm_low_32 : int -> bits(32) + +function rm_low_32 addr = { + assert(not_bool(app_view)); + let byte0 : bits(8) = loghead(8, memi(bits_of_int(addr, 64))); + let byte1 : bits(8) = loghead(8, memi(bits_of_int(1 + addr, 64))); + let word0 : bits(16) = logior(bits_of_int(ash(unsigned(byte1), 8), 16), sail_zero_extend(byte0, 16)); + let byte2 : bits(8) = loghead(8, memi(bits_of_int(2 + addr, 64))); + let byte3 : bits(8) = loghead(8, memi(bits_of_int(3 + addr, 64))); + let word1 : bits(16) = logior(bits_of_int(ash(unsigned(byte3), 8), 16), sail_zero_extend(byte2, 16)); + let dword : bits(32) = logior(bits_of_int(ash(unsigned(word1), 16), 32), sail_zero_extend(word0, 32)); + dword +} + +val wm_low_32 : (bits(52), bits(32)) -> unit + +function wm_low_32 (addr, sailval) = { + assert(not_bool(app_view)); + let addr : int = unsigned(addr); + let byte0 : bits(8) = sailval[7 .. 0]; + let byte1 : bits(8) = sailval[15 .. 8]; + let byte2 : bits(8) = sailval[23 .. 16]; + let byte3 : bits(8) = sailval[31 .. 24]; + bang_memi(bits_of_int(addr, 64), byte0); + bang_memi(bits_of_int(1 + addr, 64), byte1); + bang_memi(bits_of_int(2 + addr, 64), byte2); + bang_memi(bits_of_int(3 + addr, 64), byte3) +} + +val rm_low_64 : int -> bits(64) + +function rm_low_64 addr = { + assert(not_bool(app_view)); + let dword0 : bits(32) = rm_low_32(addr); + let dword1 : bits(32) = rm_low_32(4 + addr); + let qword : bits(64) = logior(bits_of_int(ash(unsigned(dword1), 32), 64), sail_zero_extend(dword0, 64)); + qword +} + +val wm_low_64 : (bits(52), bits(64)) -> unit + +function wm_low_64 (addr, sailval) = { + assert(not_bool(app_view)); + let addr : int = unsigned(addr); + let dword0 : bits(32) = sailval[31 .. 0]; + let dword1 : bits(32) = sailval[63 .. 32]; + wm_low_32(bits_of_int(addr, 52), dword0); + wm_low_32(bits_of_int(4 + addr, 52), dword1) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prefix_modrm_sib_decoding.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prefix_modrm_sib_decoding.sail new file mode 100644 index 000000000..bb72d77be --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prefix_modrm_sib_decoding.sail @@ -0,0 +1,185 @@ +$include "./auxiliary.sail" +$include "./dispatch_macros.sail" + +/*! Functions to detect and decode legacy prefixes */ +val get_one_byte_prefix_array_code : bits(8) -> {|0, 1, 2, 3, 4|} + +function get_one_byte_prefix_array_code byte = { + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] : vector(256, dec, {|0, 1, 2, 3, 4|})[unsigned(loghead(8, byte))] +} + +/*! Picking a mandatory prefix +

When should we interpret a SIMD prefix ( @ ( ' 66 ' ) , @ ( ' F2 ' ) , + @ ( ' F3 ' ) ) as the mandatory prefix for a given opcode in the two- and three-byte + opcode maps?

+ +

Here are some decoding rules for SIMD mandatory prefixes; note that these + do NOT apply for VEX/EVEX-encoded instructions because the mandatory prefixes + are explicitly stated there. All the examples listed below are from Intel ' s + XED ( x86 Encoder Decoder: @ ( ' https://intelxed.github.io/ ' ) ) .

+ +
    + +
  1. For opcodes that can take mandatory prefixes, @ ( ' 66 ' ) is ignored when + @ ( ' F2 ' ) /@ ( ' F3 ' ) are present. Also, a mandatory prefix does not have to + immediately precede the opcode byte --- see ( 4 ) below.

    + +

    Examples:

    + + + + ( 1 ) xed -64 -d 660f6f00 ;; movdqa xmm0, xmmword ptr [rax] + ( 2 ) xed -64 -d f30f6f00 ;; movdqu xmm0, xmmword ptr [rax] + ( 3 ) xed -64 -d 66f30f6f00 ;; movdqu xmm0, xmmword ptr [rax] ( same as ( 2 ) ) + ( 4 ) xed -64 -d f3660f6f00 ;; movdqu xmm0, xmmword ptr [rax] ( same as ( 2 ) ) + + + +
  2. + +
  3. For opcodes that can take mandatory prefixes, the presence of an + unsupported SIMD prefix translates to a reserved instruction; such a prefix + does NOT act as a modifier prefix.

    + +

    Examples: Opcode @ ( ' 0f 6b ' ) has a no-prefix form and @ ( ' 66 ' ) + mandatory prefix form. When used with @ ( ' f3 ' ) , it leads to an error; see ( 3 ) + below.

    + + + + ( 1 ) xed -64 -d 0f6b00 ;; packssdw mmx0, qword ptr [rax] + ( 2 ) xed -64 -d 660f6b00 ;; packssdw xmm0, xmmword ptr [rax] + ( 3 ) xed -64 -d f3660f6b00 ;; GENERAL_ERROR Could not decode... + + + +
  4. + +
*/ +val compute_mandatory_prefix_for_two_byte_opcode : (proc_mode, bits(8), prefixes) -> bits(8) + +function compute_mandatory_prefix_for_two_byte_opcode (proc_mode, opcode, prefixes) = { + if in_64bit_mode(proc_mode) then { + n64_bit_compute_mandatory_prefix_for_two_byte_opcode(opcode, prefixes) + } else { + n32_bit_compute_mandatory_prefix_for_two_byte_opcode(opcode, prefixes) + } +} + +/*! Functions to detect and decode ModR/M bytes +Returns a boolean saying whether, in 64-bit mode, + the given opcode in the one-byte opcode map expects a ModR/M byte. */ +val n64_bit_mode_one_byte_opcode_modr_m_p : bits(8) -> bool + +function n64_bit_mode_one_byte_opcode_modr_m_p opcode = { + [true, true, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true] : vector(256, dec, bool)[unsigned(opcode)] +} + +/*! Returns a boolean saying whether, in 32-bit mode, + the given opcode in the one-byte opcode map expects a ModR/M byte. */ +val n32_bit_mode_one_byte_opcode_modr_m_p : bits(8) -> bool + +function n32_bit_mode_one_byte_opcode_modr_m_p opcode = { + [true, true, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, false, false, false, true, true, true, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, true, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true, true, true, true] : vector(256, dec, bool)[unsigned(opcode)] +} + +/*! Returns @ ( ' t ' ) if a one-byte opcode requires a ModR/M byte; + @ ( ' nil ' ) otherwise */ +val one_byte_opcode_modr_m_p : (proc_mode, bits(8)) -> bool + +function one_byte_opcode_modr_m_p (proc_mode, opcode) = { + if in_64bit_mode(proc_mode) then { + n64_bit_mode_one_byte_opcode_modr_m_p(opcode) + } else { + n32_bit_mode_one_byte_opcode_modr_m_p(opcode) + } +} + +/*! Returns a boolean saying whether, in 64-bit mode, + the given opcode in the two-byte opcode map expects a ModR/M byte. */ +val n64_bit_mode_two_byte_opcode_modr_m_p : (bits(8), bits(8)) -> bool + +function n64_bit_mode_two_byte_opcode_modr_m_p (mandatory_prefix, opcode) = { + (match mandatory_prefix { + 102 => [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)], + 243 => [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true, true, false, false, false, true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, true, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)], + 242 => [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, true, true, true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)], + _ => [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, true, true, true, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, true, true, true, true, true, true, true, true, true, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, true, true, false, false, false, true, true, false, true, true, true, true, true, true, true, true, true, false, false, true, false, false, false, false, false, false, false, false, false, true, true, true, true] : vector(256, dec, bool)[unsigned(opcode)] + }) : bool +} + +/*! Returns a boolean saying whether, in 32-bit mode, + the given opcode in the two-byte opcode map expects a ModR/M byte. */ +val n32_bit_mode_two_byte_opcode_modr_m_p : (bits(8), bits(8)) -> bool + +function n32_bit_mode_two_byte_opcode_modr_m_p (mandatory_prefix, opcode) = { + (match mandatory_prefix { + 102 => [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)], + 243 => [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false, false, false, true, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, true, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)], + 242 => [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, true, true, true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] : vector(256, dec, bool)[unsigned(opcode)], + _ => [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, true, true, true, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, true, true, true, true, true, true, true, true, true, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, true, true, false, false, false, true, true, false, true, true, true, true, true, true, true, true, true, false, false, true, false, false, false, false, false, false, false, false, false, true, true, true, true] : vector(256, dec, bool)[unsigned(opcode)] + }) : bool +} + +/*! Returns @ ( ' t ' ) if a two-byte opcode requires a ModR/M byte; + @ ( ' nil ' ) otherwise. Doesn ' t account for AVX/AVX2/AVX512 instructions. */ +val two_byte_opcode_modr_m_p : (proc_mode, bits(8), bits(8)) -> bool + +function two_byte_opcode_modr_m_p (proc_mode, mandatory_prefix, opcode) = { + if in_64bit_mode(proc_mode) then { + n64_bit_mode_two_byte_opcode_modr_m_p(mandatory_prefix, opcode) + } else { + n32_bit_mode_two_byte_opcode_modr_m_p(mandatory_prefix, opcode) + } +} + +/*! Returns @ ( ' t ' ) if a VEX-encoded opcode requires a ModR/M byte; + @ ( ' nil ' ) otherwise. */ +val vex_opcode_modr_m_p : (vex_prefixes, bits(8)) -> bool + +function vex_opcode_modr_m_p (vex_prefixes, opcode) = { + if not_bool(opcode == 0x77) then true else { + not_bool(vex_prefixes_map_p(0x000f, vex_prefixes)) + } +} + +/*! Functions to detect and decode SIB bytes +Returns a boolean saying whether a SIB byte is expected to follow a + ModR/M byte or not. +

+ This is based on Intel manual, Jan ' 19, Volume 2, Tables 2-1 and 2-2, + as well as AMD manual, Dec ' 17, Volume 3, Tables A-33 and A-35. + When the address size is 32 or 64 bits, + Intel Table 2-2 and AMD Table A-35 apply: + a SIB byte is expected exactly when + ModR/M.mod is not #b11 and ModR/M.r/m is #b100. + When the address size is 16 bits, no SIB byte is expected. +

+

+ Intel Table 2-3 applies to 32-bit addresses, + but Section 2.2.1.3 says that it also applies to 64-bit addresses. + AMD Table A-35 mentions both 32-bit and 64-bit addressing. +

+

+ Intel manual, Jan ' 19, Volume 2, Table 2-7 is not very clear, + giving the impression that a SIB byte may be required + when Mod = 00 and R/M = 101 ( last column of first row ) . + But AMD manual, Dec ' 17, Volume 3, Table 1-16 + ( which corresponds to Intel Table 2-7 ) clearly says that + no SIB byte is present in the first row. + Intel ' s last column of first row means that, + in order to use @ ( ' Disp32 ' ) instead of @ ( ' RIP+Disp32 ' ) , + 64-bit mode must use the encoding with SIB in the second row. +

+

+ The second argument of this function says whether + the address size is 16 bits or not ( i.e. 32 or 64 bits ) . + In 64-bit mode, this argument is always @ ( ' nil ' ) . + In 32-bit mode, this argument may be @ ( ' t ' ) or @ ( ' nil ' ) . +

*/ +val x86_decode_sib_p : (modr_m, bool) -> bool + +function x86_decode_sib_p (modr_m, n16_bit_addressp) = { + not_bool(n16_bit_addressp) & (let r_m : bits(3) = modr_m[r_m] in + let mod_var : bits(2) = modr_m[mod] in r_m == 0b100 & not_bool(mod_var == 0b11)) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prelude.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prelude.sail new file mode 100644 index 000000000..db136d67a --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/prelude.sail @@ -0,0 +1,711 @@ +/*-----------------------------------------------------------------*/ +// This file contains the handwritten functions for the ACL2 +// translation. +/*-----------------------------------------------------------------*/ + +$ifndef __X86_PRELUDE +$define __X86_PRELUDE + +$ifndef _DEFAULT_DEC + default Order dec +$endif + +$include +$include +$include + +overload operator + = {concat_str, and_bool} + +// Type synonym for signed bitvectors, which are distinguished from unsigned +// bitvectors by ACL2 (but not by Sail) + +type sbits ('n : Int), 'n > 0 = bits('n) + +/*-----------------------------------------------------------------*/ +// Misc +/*-----------------------------------------------------------------*/ + +/* +The `feature-flags` function in cpuid.lisp takes an argument +`features`. The guard specifies `features` must be a subset of the +supported features, and so this is proved statically. The function +checks that all features in its argument are enabled by passing each +one to `feature-flag` (not plural). In turn, `feature-flag` uses +`cpuid-flag` macro which uses `cpuid-flag-fn`... which is always 1 +because all features are enabled by default. Thus, translate +`feature-flag` simply as `1`. + +Append `_fn` to the names to stop shadowing a formal parameter at +a use-site in `chk_exc_fn` in `dispatch_macros.lisp`. + +TODO: avoidance of shadowing should be done elsewhere. +*/ + +val feature_flag_fn : string -> int +function feature_flag_fn (feature) = 1 + + +val feature_flags_fn : list(string) -> int +function feature_flags_fn (features) = + match features { + [||] => 1, + x :: xs => if feature_flag_fn(x) == 0 + then 0 + else feature_flags_fn(xs) + } + +/*-----------------------------------------------------------------*/ +// Exceptions +/*-----------------------------------------------------------------*/ + +union exception = { + Emsg : string, + Syscall : unit /* TODO: Pass data? */ +} + +val x86_model_error : forall ('a : Type). string -> 'a +function x86_model_error(msg) = throw(Emsg("Model error: " + msg)) + +val x86_fault : forall ('a : Type). string -> 'a +function x86_fault(msg) = throw(Emsg("Fault: " + msg)) + + +/*-----------------------------------------------------------------*/ +// Undefined behaviour +// +// In the ACL2 model, undefined values for things like flags just +// return zero. Here we use Sail's builtin `undefined`, which +// actually does the same. +/*-----------------------------------------------------------------*/ + +val undef_read_logic : unit -> nat +function undef_read_logic () = undefined + +/*-----------------------------------------------------------------*/ +// Utility functions +/*-----------------------------------------------------------------*/ + +val eq_bits_nat : forall 'n, 'n > 0. (bits('n), nat) -> bool +function eq_bits_nat (x, y) = (unsigned(x) == y) + +overload operator == = {eq_bits_nat} + +/* +pow2 taken from sail-riscv/model/prelude.sail +*/ + +val pow2 = pure "pow2" : forall 'n. int('n) -> int(2 ^ 'n) + +/* +TODO: is there a utility function for this +TODO: make bool_to_bit and bit_to_bool a mapping? +*/ +val bool_to_bits : bool -> bits(1) +function bool_to_bits (b) = match b { + true => 0b1, + false => 0b0 +} + +val bits_to_bool : bits(1) -> bool +function bits_to_bool (b) = match b { + 0b1 => true, + 0b0 => false +} + +val sail_mask_signed : forall 'len 'v, 'len >= 0 & 'v >= 0. (int('len), bits('v)) -> bits('len) + +function sail_mask_signed(len, v) = if len <= length(v) then truncate(v, len) else sail_sign_extend(v, len) + +// TODO: The original trunc function in x86isa/utils/utilities.lisp +// seems to intrepret n as the number of bytes in some cases, and +// the number of bits in others... although it seems to be used with +// numbers of bytes as far as I can see, so use that... +val trunc : forall 'n 'm, 'n in {1, 2, 4, 8, 16} & 'm > 0. (int('n), bits('m)) -> bits(8 * 'n) +function trunc (n, x) = sail_mask(8 * n, x) + +val trunc_signed : forall 'n 'm, 'n in {1, 2, 4, 8, 16} & 'm > 0. (int('n), bits('m)) -> bits(8 * 'n) +function trunc_signed (n, x) = sail_mask_signed(8 * n, x) + +// Bit slicing functions for translating part_select. This may be called with +// indices that go beyond the length of the bitvector, so handle the case where +// we have to zero-extend or sign-extend, depending on whether the original +// bitvector is treated as signed or not. +val bitslice : forall 'n 'low 'width. (bits('n), int('low), int('width)) -> bits('width) +function bitslice (x, low, width) = { + assert('n >= 0 & low >= 0 & width > 0); + if (low + width <= 'n) then { + x[low + width - 1 .. low] + } else if (low < 'n - 1) then { + sail_zeros(low + width - 'n) @ x['n - 1 .. low] + } else { + sail_zeros(width) + } +} + +// Signed bitslicing function that sign-extends rather than zero-extends in +// case the slice goes out of bounds +val signed_bitslice : forall 'n 'low 'width. (bits('n), int('low), int('width)) -> bits('width) +function signed_bitslice (x, low, width) = { + assert('n >= 0 & low >= 0 & width > 0); + if (low + width <= 'n) then { + x[low + width - 1 .. low] + } else if (low < 'n - 1) then { + // Sign-extend by replicating the MSB + replicate_bits([x['n - 1]], low + width - 'n) @ x['n - 1 .. low] + } else { + sail_zeros(width) + } +} + +val nat_of_int : (int) -> nat +function nat_of_int i = { + assert (i >= 0); + i +} + +val nfix : int -> nat +function nfix i = if i >= 0 then i else 0 + +val check_range : forall 'n 'm 'i, 'n <= 'm. (int('n), int('m), int('i)) -> {'j, 'n <= 'j & 'j <= 'm & 'i == 'j. int('j)} +function check_range(n, m, i) = { + assert(n <= i & i <= m); + i +} + +val bits_of_int : forall 'n, 'n >= 0. (int, int('n)) -> bits('n) +function bits_of_int (x, n) = get_slice_int(n, x, 0) + +val fits_in_bitvector : (int, int) -> bool +function fits_in_bitvector (n, x) = (0 <= x & x < pow2(n)) + +val fits_in_signed_bitvector : (int, int) -> bool +function fits_in_signed_bitvector (n, x) = (negate(pow2(n - 1)) <= x & x < pow2(n - 1)) + +val isEven : int -> bool +function isEven x = + if get_slice_int(1, x, 0) == 0b0 then true else false + +// b-xor: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____B-XOR +val b_xor : (int, int) -> int +function b_xor (i, j) = { + assert(0 <= i & i <= 1 & 0 <= j & j <= 1); + if i == 0 + then if j == 0 then 0 else 1 + else if j == 0 then 1 else 0 +} + +val in_list : (string, list(string)) -> bool +function in_list (x, xs) = match xs { + y :: ys => if x == y then true else in_list(x, ys), + [||] => false +} + +/*-----------------------------------------------------------------*/ +// Unsigned and signed byte_p - recognisers +/*-----------------------------------------------------------------*/ + +/* +http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____UNSIGNED-BYTE-P +*/ +val unsigned_byte_p_int : (int, int) -> bool +function unsigned_byte_p_int (bits, x) = { + assert(bits >= 0); + 0 <= x & x < pow2(bits) +} + +val unsigned_byte_p_bits : forall 'n, 'n >= 0. (int, bits('n)) -> bool +function unsigned_byte_p_bits (bits, x) = unsigned_byte_p_int(bits, unsigned(x)) + +overload unsigned_byte_p = {unsigned_byte_p_int, unsigned_byte_p_bits} + +/* +http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____SIGNED-BYTE-P +*/ +val signed_byte_p_int : (int, int) -> bool +function signed_byte_p_int (bits, x) = { + assert(bits >= 0); + negate(pow2(bits - 1)) <= x & x < pow2(bits - 1) +} + +val signed_byte_p_bits : forall 'n, 'n > 0. (int, bits('n)) -> bool +function signed_byte_p_bits (bits, x) = signed_byte_p_int(bits, signed(x)) + +overload signed_byte_p = {signed_byte_p_int, signed_byte_p_bits} + +/*-----------------------------------------------------------------*/ +// Logic functions +/*-----------------------------------------------------------------*/ + +/* +`loghead size i` returns size low-order bits of i. +In C-like languages: `i & ((1 << size) - 1)` +If size = 0, then return = 0 + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____LOGHEAD +*/ + +val loghead_int : (int, int) -> int +function loghead_int (size, i) = + if size == 0 + then 0 + else + unsigned( + get_slice_int(size, i, 0) + ) + +val loghead_bits : forall 'n 'm, 'n >= 0 & 'm >= 0. (int('n), bits('m)) -> bits('n) +function loghead_bits (size, x) = sail_mask(size, x) + +overload loghead = {loghead_bits, loghead_int} + +/*-----------------------------------------------------------------*/ +/* +`logtail pos i` returns high-order part of i starting at bit pos + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____LOGTAIL +*/ +val logtail_int : (int, int) -> int +function logtail_int (pos, x) = + shr_int(x, pos) + +val logtail_bits : forall 'pos 'n, 'pos >= 0 & 'pos < 'n. (int('pos), bits('n)) -> bits('n - 'pos) +function logtail_bits (pos, x) = x[('n - 1) .. pos] + +overload logtail = {logtail_bits, logtail_int} + +/*-----------------------------------------------------------------*/ +/* +"For a nonnegative integer i and an integer j, (logbitp i j) is a +Boolean, which is t if and only if the value of the ith bit is 1 in +the two's complement representation of j. + +(Logbitp i j) has a guard that i is a nonnegative integer and j is +an integer." + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGBITP +*/ +val logbitp_int : (int, int) -> bool +function logbitp_int (i, j) = { + assert(i >= 0); + bits_to_bool( + get_slice_int(1, j, i) + ) +} + +val logbitp_bits : forall 'n 'pos, 'n >= 0. (int('pos), bits('n)) -> bool +function logbitp_bits (pos, x) = if (0 <= pos & pos < 'n) then (x[pos] == bitone) else false + +overload logbitp = {logbitp_bits, logbitp_int} + +/* +Also `logbit` which "is just like the Common Lisp function +`(logbitppos i)`, except that we return 0b1 or 0b0 (instead of t or +nil)." + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____LOGBIT +*/ +val logbit_int : (int, int) -> bits(1) +function logbit_int (pos, j) = { + assert(pos >= 0); + get_slice_int(1, j, pos) +} + +val logbit_bits : forall 'n 'pos, 'n >= 0. (int('pos), bits('n)) -> bits(1) +function logbit_bits (pos, x) = if (0 <= pos & pos < 'n) then [x[pos]] else [bitzero] + +overload logbit = {logbit_bits, logbit_int} + +/*-----------------------------------------------------------------*/ +/* +The function lognot is used in the definition of logcount. It is +simply a bitwise not. + +See (logcount): http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGCOUNT +See (lognot): http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGNOT + +TODO: why do we take the lognot? This does a bitwise not and seems +to change the number of on bits? Maybe 'on' bits means 0 when +negative. +*/ + +val lognot_int : (int) -> int +function lognot_int x = negate(x) - 1 + +overload lognot = {not_vec, lognot_int} + +val logcount_int : (int) -> int +function logcount_int(x) = + if x == 0 then 0 else + if x < 0 then logcount_int(lognot(x)) else + if isEven (x) + then logcount_int (shr_int (x, 1)) + else logcount_int (shr_int (x, 1)) + 1 + +val logcount_bits : forall 'n, 'n >= 0. (bits('n)) -> int +function logcount_bits (x) = logcount_int(unsigned(x)) + +overload logcount = {logcount_bits, logcount_int} + +/*-----------------------------------------------------------------*/ +/* +floor + +This implementation passes the tests mentioned in the spec above. +An old implementation, used conversion to and from real numbers. + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____FLOOR +*/ +val floor2 : (int, int) -> int +function floor2 (i, j) = { + tdiv = tdiv_int(i,j); + tmod = tmod_int(i,j); + if ((j > 0) & (tmod >= 0)) | ((j < 0) & (tmod <= 0)) + then tdiv + else tdiv - 1 +} + +/*-----------------------------------------------------------------*/ +/* +logand + +Wikipedia: "Shifting right by n bits on a two's complement signed +binary number has the effect of dividing it by 2n, but it always +rounds down (towards negative infinity)." + +This is what we want when replacing the `floor` function + +NOTE: at first tried using tdiv_int instead of floor2, but this does +not have the same behaviour as floor in the ACL2 spec. + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGAND +*/ + +val logand_int : (int, int) -> int +function logand_int (i, j) = + if i == 0 then 0 else + if j == 0 then 0 else + if i == -1 then j else + if j == -1 then i else + let x = 2 * (logand_int (floor2 (i, 2), (floor2 (j, 2)))) in + x + ( if isEven (i) then 0 else + if isEven (j) then 0 else + 1) + +overload logand = {and_vec, logand_int} + +/*-----------------------------------------------------------------*/ +/* +logior + +Here only the binary version is implemented. It's basically a +copy/paste job from the docs by this stage. + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGIOR +*/ +val logior_int : (int, int) -> int +function logior_int (i, j) = + lognot(logand(lognot(i), lognot(j))) + +overload logior = {or_vec, logior_int} + +/*-----------------------------------------------------------------*/ +/* +logxor + +Here only the binary version is implemented. + +See: + logxor: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGXOR + logeqv: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGEQV + logorc1:http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____LOGORC1 +*/ +val logxor : forall 'n, 'n >= 0. (bits('n), bits('n)) -> bits('n) +function logxor (x, y) = xor_vec(x, y) + +/*-----------------------------------------------------------------*/ +/* +logext + +See: +http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____LOGEXT +http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____LOGAPP +*/ +/* TODO */ +val binary_logapp : (int, int, int) -> int +function binary_logapp (size, i, j) = + (loghead (size, i)) + (j * pow2(size)) + +val binary_logext : (int, int) -> int +function binary_logext (size, i) = { + assert(0 < size); + binary_logapp (size - 1, + i, + if logbitp (size - 1, i) + then negate(1) + else 0) +} + + +/*-----------------------------------------------------------------*/ +/* +ash + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____ASH + +TODO: check this implementation matches the spec +*/ +val ash_bits : forall 'n, 'n >= 0. (bits('n), int) -> bits('n) +function ash_bits (i, c) = + if c == 0 then i else + if c > 0 then sail_shiftleft(i, c) + else sail_arith_shiftright(i, negate(c)) + +val ash_left_int : forall 'x 'n, 'n >= 0. (int('x), int('n)) -> int('x * (2 ^ 'n)) +function ash_left_int (x, n) = x * pow2(n) + +val ash_int : (int, int) -> int +function ash_int (i, c) = + if c == 0 then i else + if c > 0 then _shl_int(i, c) + else _shr_int(i, negate(c)) + +overload ash = {ash_bits, ash_left_int, ash_int} + +/*-----------------------------------------------------------------*/ +/* +abs + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____ABS +*/ +val abs : (int) -> int +function abs x = if x < 0 then negate(x) else x + +/*-----------------------------------------------------------------*/ +/* +mod + +This implementation passes the examples in the spec below. + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=COMMON-LISP____MOD + +TODO: is there an inbuilt for this? +*/ +val mod : (int, int) -> int +function mod (x, y) = + x - (floor2(x,y) * y) + +/*-----------------------------------------------------------------*/ +/* +rotate-left. + +rotates-spec.lisp uses `fast-rotate-left` in +`centaur/bitops/fast-rotate`. Apparently this is logically +equivalent to `rotate-left`, so we implement our own here. + +Based loosely on: + * http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____ROTATE-LEFT + * http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____ROTATE-RIGHT +*/ +val rotate_left_bits : forall 'n. (bits('n), int, int) -> bits('n) +function rotate_left_bits (x, width, places) = { + let high = sail_shiftleft(x, places); + let low = sail_shiftright(x, width-places); + high | low +} + +val rotate_left_int : (int, int, int) -> int +function rotate_left_int (x, width, places) = { + assert(0 <= places); + placesMod = mod(places, width); + low_num = width - placesMod; + xl = get_slice_int(low_num, x, 0); + xh = get_slice_int(placesMod, x, low_num); + unsigned(xl @ xh) +} +overload rotate_left = {rotate_left_bits, rotate_left_int} + +val rotate_right_bits : forall 'n. (bits('n), int, int) -> bits('n) +function rotate_right_bits (x, width, places) = { + let low = sail_shiftright(x, places); + let high = sail_shiftleft(x, width-places); + high | low +} + +val rotate_right_int : (int, int, int) -> int +function rotate_right_int (x, width, places) = { + assert(0 <= places); + placesMod = mod(places, width); + xl = get_slice_int(placesMod, x, 0); + xh = get_slice_int(width - placesMod, x, placesMod); + unsigned(xl @ xh) +} +overload rotate_right = {rotate_right_bits, rotate_right_int} + +/*-----------------------------------------------------------------*/ +/* +MERGE-2-U64S etc. + +"Concatenate 2 64-bit numbers together to form an 128-bit result." + +See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/?topic=ACL2____MERGE-2-U64S +OR: `:pe MERGE-2-U64S` etc. + +TODO: Autogenerate? +*/ +val merge_2_u64s : (bits(64), bits(64)) -> bits(128) +function merge_2_u64s (a1, a0) = a1 @ a0 + +val merge_2_u32s : (bits(32), bits(32)) -> bits(64) +function merge_2_u32s (a1, a0) = a1 @ a0 + +val merge_4_u32s : (bits(32), bits(32), bits(32), bits(32)) -> bits(128) +function merge_4_u32s (a3, a2, a1, a0) = a3 @ a2 @ a1 @ a0 + +/*-----------------------------------------------------------------*/ +// Some bitvector operations +/*-----------------------------------------------------------------*/ + +infix 7 << +overload operator << = {sail_shiftleft} + +infix 7 >> +overload operator >> = {sail_shiftright} + +// Used in part-install. See: http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index.html?topic=ACL2____PART-INSTALL +// TODO: this is almost identical to genericBitstructUpdater below - maybe merge them + +val changeSlice_int : (int, int, int, int) -> int +function changeSlice_int (x, low, width, v) = + set_slice_int(width, x, low, get_slice_int(width, v, 0)) + +val changeSlice_bits : forall 'n 'low 'width, 'low >= 0 & 'width > 0 & 'low + 'width <= 'n. + (bits('n), int('low), int('width), bits('width)) -> bits('n) +function changeSlice_bits (x, low, width, v) = [x with (low + width - 1) .. low = v] + +overload changeSlice = {changeSlice_bits, changeSlice_int} + +val genericBitstructAccessor : forall 'width 'n 'low, 'width > 0 & 'low >= 0 & 'low + 'width <= 'n. + (int('width), bits('n), int('low)) -> bits('width) +function genericBitstructAccessor (width, inputBits, low) = + inputBits[(low + width - 1) .. low] + +val genericBitstructUpdater : forall 'width 'n 'low, 'width > 0 & 'low >= 0 & 'low + 'width <= 'n. + (int('width), bits('width), int('low), bits('n)) -> bits('n) +function genericBitstructUpdater (width, spliceBits, low, inputBits) = + [inputBits with (low + width - 1) .. low = spliceBits] + +/* +Reading from and writing to memory +*/ + +val log_memory_read : forall 'addr_width 'n, 'addr_width > 0 & 'n > 0. (bits('addr_width), int('n), bits(8 * 'n)) -> unit + +// TODO: Rename these +val memi : forall 'addr_width, 'addr_width > 0. (bits('addr_width)) -> bits(8) +function memi (addr) = { + result = __read_mem( Read_plain, // Read type + 64, // Address size + sail_mask(64, addr), // Address to read + 1 // Number of bytes to read + ); + log_memory_read(addr, 1, result); + result +} + +val log_memory_write : forall 'addr_width 'n, 'addr_width > 0 & 'n > 0. (bits('addr_width), int('n), bits(8 * 'n)) -> unit + +val bang_memi : forall 'addr_width, 'addr_width > 0. (bits('addr_width), bits(8)) -> unit +function bang_memi (addr, valToWrite) = { + dummy = + __write_mem_ea( Write_plain, // Write type + 64, // Address size + sail_mask(64, addr), // Address to write to (0 here) + 1); // Number of bytes to write + dummy2 = + __write_mem(Write_plain, // Write type + 64, // Address size + sail_mask(64, addr), // Address to write to (0 here) + 1, // Number of bytes to write + valToWrite // Value to write + ); + log_memory_write(addr, 1, valToWrite); +} + +/*-----------------------------------------------------------------*/ +// Config +/*-----------------------------------------------------------------*/ + +val __SetConfig : (string, int) -> unit +scattered function __SetConfig + +// app-view is part of the x86 model state. See thesis section 5.1 +// and conrete-memory.lisp + +register app_view : bool +register marking_view : bool + +/* Register logging helpers */ +register log_register_writes : bool + +val log_gpr_write : range(0, 15) -> unit +val log_rflags_write : unit -> unit +val log_rip_write : unit -> unit + +// Model state. +register ms_reg : bool + +val ms : unit -> bool +function ms () = ms_reg + +// Fault. +register fault_reg : bool + +val fault : unit -> bool +function fault () = fault_reg + +/* Handwritten implementations of `rb` and `wb` in a more idiomatic style, + * using for-loops instead of working with lists of addresses and bytes, like + * the ACL2 implementations. + */ + +/* Address translation function and another helper function used by `rb`/`wb` */ +val ia32e_la_to_pa : (sbits(48), string) -> bits(52) +val canonical_address_p : int -> bool +val n64_bit_modep : unit -> bool +val observe_mem_write : (sbits(48), int) -> unit + +val rb : forall 'addr_width 'n, 'addr_width > 0 & 'n > 0. (int('n), bits('addr_width), string) -> bits(8 * 'n) + +function rb (n, addr, access_kind) = { + result : bits(8 * 'n) = sail_zeros(8 * n); + foreach (offset from 0 to (n - 1)) { + if not_bool(canonical_address_p(signed(addr) + offset)) then x86_model_error("rb: non-canonical address"); + let lin_addr : bits(48) = add_bits_int(sail_mask_signed(48, addr), offset); + let phys_addr : bits(52) = + if app_view then sail_mask_signed(52, lin_addr) else ia32e_la_to_pa(lin_addr, access_kind) + in + result[((8 * offset) + 7) .. (8 * offset)] = memi(phys_addr) + }; + return result +} + +val wb : forall 'addr_width 'n, 'addr_width > 0 & 'n > 0. (int('n), bits('addr_width), string, bits(8 * 'n)) -> unit + +function wb (n, addr, access_kind, value) = { + foreach (offset from 0 to (n - 1)) { + if not_bool(canonical_address_p(signed(addr) + offset)) then { + if offset != 0 then observe_mem_write(sail_mask_signed(48, addr), offset - 1); + x86_model_error("wb: non-canonical address") + }; + let lin_addr : bits(48) = add_bits_int(sail_mask_signed(48, addr), offset); + let phys_addr : bits(52) = + if app_view then sail_mask_signed(52, lin_addr) else ia32e_la_to_pa(lin_addr, access_kind) + in + bang_memi(phys_addr, value[((8 * offset) + 7) .. (8 * offset)]) + }; + + let dummy = observe_mem_write(sail_mask_signed(48, addr), n); + return () +} + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_accessors.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_accessors.sail new file mode 100644 index 000000000..5e167e46e --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_accessors.sail @@ -0,0 +1,35 @@ +$ifndef __X86_REGISTER_ACCESSORS +$define __X86_REGISTER_ACCESSORS + +val rgfi : (int) -> sbits(64) +function rgfi (regNum) = { + assert(0 <= regNum & regNum < 16); + regval_from_reg(read_gpr(regNum)) +} + +val write_rgfi : (int, sbits(64)) -> unit +function write_rgfi (regNum, regval_to_write) = { + assert(0 <= regNum & regNum < 16); + write_gpr(regNum, regval_into_reg(regval_to_write)) +} + +val read_rip : unit -> sbits(48) +function read_rip() = truncate(regval_from_reg(rip), 48) + +val write_rip : sbits(48) -> unit +function write_rip(value) = { + rip = regval_into_reg(sail_sign_extend(value, 64)); + if log_register_writes then log_rip_write() +} + +type msr_index = range(0, 6) + +val read_msr : msr_index -> bits(64) +function read_msr(idx) = msrs[idx] + +val write_msr : (msr_index, bits(64)) -> unit +function write_msr(idx, value) = { + msrs[idx] = value +} + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_readers_and_writers.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_readers_and_writers.sail new file mode 100644 index 000000000..a420350b8 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_readers_and_writers.sail @@ -0,0 +1,614 @@ + +/*! Functions that enable the use of extended GPRs using the + @ ( ' rex ' ) byte +Using the REX prefix to access general-purpose registers +

In 64-bit mode, in addition to generating 64-bit operand sizes, + the REX prefix is used to reference registers R8 to R15. Instructions that + include REX prefixes can access these registers if the relevant W, R, X, or + B bit in the REX prefix is set. E.g., let R be the relevant bit in the REX + prefix and let R be set --- so @ ( ' index ' ) = @ ( ` *r* ` ) for this function. If + @ ( ' reg ' ) = 0 ( which, in the non-REX world, would refer to rAX ) , + @ ( ' reg-index ' ) would give us the register index corresponding to the + register r8. If R is not set, @ ( ' reg-index ' ) will give us the index + corresponding to rAX.

+ +

In 32-bit mode, the REX prefix is absent. This function can be used in + 32-bit mode, by passing 0 as REX.

*/ +val reg_index : (bits(3), bits(8), bits(2)) -> bits(4) + +function reg_index (reg, rex_byte, index) = { + if logbitp(unsigned(index), rex_byte) then { + logior(0x8, sail_zero_extend(reg, 4)) + } else { + sail_zero_extend(reg, 4) + } +} + +/*! Functions to read/write 8/16/32/64 bits into the registers +

@ ( see rr08 ) , @ ( see rr16 ) , @ ( see rr32 ) , and @ ( see rr64 ) + will read the contents of the GPRs as natural numbers. Remember that + @ ( ' rgfi ' ) will return an @ ( see i64p ) value.

+ +

Here is an example:

+
+ + \ ( !rgfi 0 -1 x86\ ) ;; Write -1 to register 0 + + +

\ ( rr64 0 x86\ ) returns @ ( ' 18446744073709551615 ' ) and + ( rgfi 0 x86 ) returns @ ( ' -1 ' ) . Note that + @ ( ' 18446744073709551615 ' ) is a bignum in CCL. This is precisely the + reason why we declared registers as @ ( ' i64p ' ) instead of @ ( ' n64p ' ) ; + @ ( ' -1 ' ) would be stored as a bignum if the registers were + @ ( ' n64p ' ) .

+ +

Similarly, @ ( see wr08 ) , @ ( see wr16 ) , @ ( see wr32 ) , and @ ( see wr64 ) + are used to write natural numbers into the GPRs.

+Read from byte general-purpose registers +

Source: Intel Manuals, Vol. 1, Section + 3.4.1.1 ( General-Purpose Registers in 64-bit Mode )

+ +
In 64-bit mode, there are limitations on accessing byte + registers. An instruction cannot reference legacy high-bytes ( for example: AH, + BH, CH, DH ) and one of the new byte registers at the same time ( for example: + the low byte of the RAX register ) . However, instructions may reference legacy + low-bytes ( for example: AL, BL, CL or DL ) and new byte registers at the same + time ( for example: the low byte of the R8 register, or R8L ) . The architecture + enforces this limitation by changing high-byte references ( AH, BH, CH, DH ) to + low byte references ( BPL, SPL, DIL, SIL: the low 8 bits for RBP, RSP, RDI and + RSI ) for instructions using a REX prefix.
+ +

In other words, without the REX prefix, indices 0-7 refer to byte registers + AL, CL, DL, BL, AH, CH, DH, and BH, whereas with the REX prefix, indices 0-15 + refer to AL, CL, DL, BL, SPL, BPL, SIL, DIL, R8L, R9L, R10L, R11L, R12L, R13L, + R14L, R15L. This applies to 64-bit mode.

+ +

In 32-bit mode, this function is called with 0 as REX.

*/ +val rr08 : (bits(4), bits(8)) -> bits(8) + +function rr08 (reg, rex) = { + let reg : nat = unsigned(reg); + if not_bool(rex == 0x00) | reg < 4 then { + let qword : sbits(64) = rgfi(reg); + truncate(qword, 8) + } else { + let qword : sbits(64) = rgfi(unsigned(bits_of_int(reg - 4, 4))); + qword[15 .. 8] + } +} + +/*! Writing to byte general-purpose registers +

Note Intel Vol. 1 Sec. 3.4.1.1 + p. 3-17, which says the following about 64-bit mode:

+ +

8-bit and 16-bit operands generate an 8-bit or 16-bit result. + The upper 56 or 48 bits ( respectively ) of the destination general-purpose + register are not modified by the operation.

+ +

This is also confirmed by AMD manual, Jun ' 15, Vol. 3, App. B.1, under + ‘No Extension of 8-Bit and 16-Bit Results’.

+ +

In 32-bit mode, the upper 32 bits are undefined, as specified by + the following quote from the same page as above:

+ +

Because the upper 32 bits of 64-bit general-purpose registers are + undefined in 32-bit modes, the upper 32 bits of any general-purpose + register are not preserved when switching from 64-bit mode to a 32-bit + mode ( to protected mode or compatibility mode ) . Software must not depend on + these bits to maintain a value after a 64-bit to 32-bit mode + switch.

+ +

In 32-bit mode, this function is called with 0 as REX. Since in 32-bit + mode the high 32 bits of general-purpose registers are not accessible, it + is fine for this function to leave those bits unchanged, as opposed to, for + example, setting them to undefined values as done by the semantic functions + of certain instructions for certain flags. The switching from 32-bit mode + to 64-bit mode ( when modeled ) will set the high 32 bits of general-purpose + registers to undefined values.

*/ +val wr08 : (bits(4), bits(8), bits(8)) -> unit + +function wr08 (reg, rex, byte) = { + let reg : nat = unsigned(reg); + if not_bool(rex == 0x00) | reg < 4 then { + let qword : sbits(64) = rgfi(reg); + write_rgfi(reg, changeSlice(qword[63 .. 0], 0, 8, byte)) + } else { + let index : bits(4) = bits_of_int(unsigned(bits_of_int(reg, 4)) - 4, 4); + let qword : sbits(64) = rgfi(unsigned(index)); + write_rgfi(unsigned(index), changeSlice(qword[63 .. 0], 8, 8, byte)) + } +} + +/*! Read from word general-purpose registers */ +val rr16 : bits(4) -> bits(16) + +function rr16 reg = { + truncate(rgfi(unsigned(reg)), 16) +} + +/*! Write to word general-purpose registers +

Note Intel Vol. 1 Sec. 3.4.1.1 + p. 3-17, which says the following about 64-bit mode:

+ +

8-bit and 16-bit operands generate an 8-bit or 16-bit result. + The upper 56 or 48 bits ( respectively ) of the destination general-purpose + register are not modified by the operation.

+ +

This is also confirmed by AMD manual, Jun ' 15, Vol. 3, App. B.1, under + ‘No Extension of 8-Bit and 16-Bit Results’.

+ +

In 32-bit mode, the upper 32 bits are undefined, as specified by + the following quote from the same page as above:

+ +

Because the upper 32 bits of 64-bit general-purpose registers are + undefined in 32-bit modes, the upper 32 bits of any general-purpose + register are not preserved when switching from 64-bit mode to a 32-bit + mode ( to protected mode or compatibility mode ) . Software must not depend on + these bits to maintain a value after a 64-bit to 32-bit mode + switch.

+ +

This function is used both in 64-bit mode and in 32-bit mode. Since in + 32-bit mode the high 32 bits of general-purpose registers are not + accessible, it is fine for this function to leave those bits unchanged, as + opposed to, for example, setting them to undefined values as done by the + semantic functions of certain instructions for certain flags. The switching + from 32-bit mode to 64-bit mode ( when modeled ) will set the high 32 bits of + general-purpose registers to undefined values.

*/ +val wr16 : (bits(4), bits(16)) -> unit + +function wr16 (reg, sailval) = { + let qword : sbits(64) = rgfi(unsigned(reg)); + write_rgfi(unsigned(reg), changeSlice(qword[63 .. 0], 0, 16, sailval)) +} + +/*! Read from doubleword general-purpose registers */ +val rr32 : bits(4) -> bits(32) + +function rr32 reg = { + truncate(rgfi(unsigned(reg)), 32) +} + +/*! Write to doubleword general-purpose registers +

Note Intel Vol. 1 Sec. 3.4.1.1 + p. 3-17, which says the following about 64-bit mode:

+ +

32-bit operands generate a 32-bit result, zero-extended to a + 64-bit result in the destination general-purpose + register.

+ +

This is also confirmed by AMD manual, Jun ' 15, Vol. 3, App. B.1, under + ` No Extension of 8-Bit and 16-Bit Results ' .

+ +

In 32-bit mode, the upper 32 bits are undefined, as specified by the + following quote from the same page as above:

+ +

Because the upper 32 bits of 64-bit general-purpose registers are + undefined in 32-bit modes, the upper 32 bits of any general-purpose + register are not preserved when switching from 64-bit mode to a 32-bit + mode ( to protected mode or compatibility mode ) . Software must not depend on + these bits to maintain a value after a 64-bit to 32-bit mode + switch.

+ +

This function is used both in 64-bit mode and in 32-bit mode. Since in + 32-bit mode the high 32 bits of general-purpose registers are not + accessible, it is fine for this function to set those bits to 0, as opposed + to, for example, setting them to undefined values as done by the semantic + functions of certain instructions for certain flags. The switching from + 32-bit mode to 64-bit mode ( when modeled ) will set the high 32 bits of + general-purpose registers to undefined values.

*/ +val wr32 : (bits(4), bits(32)) -> unit + +function wr32 (reg, sailval) = { + write_rgfi(unsigned(reg), sail_zero_extend(sailval, 64)) +} + +/*! Read from quadword general-purpose registers +

This function is used only in 64-bit mode.

*/ +val rr64 : bits(4) -> bits(64) + +function rr64 reg = { + rgfi(unsigned(reg)) +} + +/*! Write to quadword general-purpose registers +

This function is used only in 64-bit mode.

*/ +val wr64 : (bits(4), bits(64)) -> unit + +function wr64 (reg, sailval) = { + write_rgfi(unsigned(reg), sailval) +} + +/*! Read form byte, word, doubleword, or quadword + general-purpose register */ +val rgfi_size : (bits(4), bits(4), bits(8)) -> bits(64) + +function rgfi_size (nbytes, index, rex) = { + (match nbytes { + 1 => sail_zero_extend(rr08(index, rex), 64), + 2 => sail_zero_extend(rr16(index), 64), + 4 => sail_zero_extend(rr32(index), 64), + 8 => rr64(index), + _ => 0x0000000000000000 + }) : bits(64) +} + +/*! Write to byte, word, doubleword, or quadword + general-purpose register */ +val write_rgfi_size : (bits(4), bits(4), bits(64), bits(8)) -> unit + +function write_rgfi_size (nbytes, index, sailval, rex) = { + (match nbytes { + 1 => wr08(index, rex, truncate(sailval, 8)), + 2 => wr16(index, truncate(sailval, 16)), + 4 => wr32(index, truncate(sailval, 32)), + 8 => wr64(index, sailval), + _ => () + }) : unit +} + +/*! Functions to read/write into the MMX registers +

From Section 12.2, Intel Manual, Volume 3 \ ( System + Programming\ ) :

+ +

The MMX state consists of eight 64-bit registers \ ( MM0 + through MM7\ ) . These registers are aliased to the low 64-bits \ ( bits 0 + through 63\ ) of floating-point registers R0 through R7 \ ( see Figure + 12-1\ ) . Note that the MMX registers are mapped to the physical + locations of the floating-point registers \ ( R0 through R7\ ) , not to + the relative locations of the registers in the floating-point register + stack \ ( ST0 through ST7\ ) . As a result, the MMX register mapping is + fixed and is not affected by value in the Top Of Stack \ ( TOS\ ) field + in the floating-point status word \ ( bits 11 through 13\ ) .

+ +

From Section 12.2, Intel Manual, Volume 3 \ ( System Programming\ )

: + +

When a value is written into an MMX register using an MMX + instruction, the value also appears in the corresponding + floating-point register in bits 0 through 63. Likewise, when a + floating-point value written into a floating-point register by a x87 + FPU, the low 64 bits of that value also appears in a the corresponding + MMX register.

+ +

The execution of MMX instructions have several side effects on + the x87 FPU state contained in the floating-point registers, the x87 + FPU tag word, and the x87 FPU status word. These side effects are as + follows:

+ +

* When an MMX instruction writes a value into an MMX register, + at the same time, bits 64 through 79 of the corresponding + floating-point register are set to all 1s.

+ +

* When an MMX instruction \ ( other than the EMMS instruction\ ) is + executed, each of the tag fields in the x87 FPU tag word is set to 00B + \ ( valid\ ) . \ ( See also Section 12.2.1, Effect of MMX, x87 FPU, FXSAVE, + and FXRSTOR Instructions on the x87 FPU Tag Word.\ )

+ +

* When the EMMS instruction is executed, each tag field in the + x87 FPU tag word is set to 11B \ ( empty ) \.

+ +

* Each time an MMX instruction is executed, the TOS value is + set to 000B. Execution of MMX instructions does not affect the other + bits in the x87 FPU status word \ ( bits 0 through 10 and bits 14 and + 15\ ) or the contents of the other x87 FPU registers that comprise the + x87 FPU state \ ( the x87 FPU control word, instruction pointer, data + pointer, or opcode registers\ ) .

+Functions to read/write 32/64/128/256/512 bits into the + XMM/YMM/ZMM registers +

Source: Intel Vol. 1, Section 15.5: ACCESSING XMM, YMM AND ZMM + REGISTERS

+ +
The lower 128 bits of a YMM register is aliased to the + corresponding XMM register. Legacy SSE instructions ( i.e., SIMD + instructions operating on XMM state but not using the VEX prefix, + also referred to non-VEX encoded SIMD instructions ) will not access + the upper bits ( MAXVL-1:128 ) of the YMM registers. AVX and FMA + instructions with a VEX prefix and vector length of 128-bits zeroes + the upper 128 bits of the YMM register.
+ +
Upper bits of YMM registers ( 255:128 ) can be read and + written to by many instructions with a VEX.256 prefix. XSAVE and + XRSTOR may be used to save and restore the upper bits of the YMM + registers.
+ +
The lower 256 bits of a ZMM register are aliased to the + corresponding YMM register. Legacy SSE instructions ( i.e., SIMD + instructions operating on XMM state but not using the VEX prefix, + also referred to non-VEX encoded SIMD instructions ) will not access + the upper bits ( MAXVL-1:128 ) of the ZMM registers, where MAXVL is + maximum vector length ( currently 512 bits ) . AVX and FMA instructions + with a VEX prefix and vector length of 128-bits zero the upper 384 + bits of the ZMM register, while the VEX prefix and vector length of + 256-bits zeroes the upper 256 bits of the ZMM register. Upper bits + of ZMM registers ( 511:256 ) can be read and written to by instructions + with an EVEX.512 prefix.
+ +

@ ( see rz32 ) , @ ( see rz64 ) , @ ( see rz128 ) , @ ( see rz256 ) , and @ ( see + rz512 ) will read the contents of the ZMMs as natural numbers.

+ +

Similarly, @ ( see wz32 ) , @ ( see wz64 ) , @ ( see wz128 ) , @ ( see wz256 ) , + and @ ( see wz512 ) are used to write natural numbers into the + ZMMs.

*/ +val rz32 : bits(5) -> bits(32) + +function rz32 reg = { + truncate(zmms[unsigned(reg)], 32) +} + +val rz64 : bits(5) -> bits(64) + +function rz64 reg = { + truncate(zmms[unsigned(reg)], 64) +} + +val rz128 : bits(5) -> bits(128) + +function rz128 reg = { + truncate(zmms[unsigned(reg)], 128) +} + +/*! Write @ ( ' val ' ) to low 32 bits of a ZMM register +

Upper bits: For XMM registers, upper @ ( ` ( - 512 + 128 ) ` ) bits are preserved if @ ( ' regtype ' ) is @ ( ' *xmm-access* ' ) ; + for @ ( ' *vex-xmm-access* ' ) , these bits are zeroed out. For + @ ( ' *ymm-access* ' ) , upper @ ( ` ( - 512 256 ) ` ) bits are zeroed + out. For @ ( ' *zmm-access* ' ) , no upper bits are zeroed out.

*/ +struct struct_wz32 = {regtype : int} + +val wz32 : (bits(5), bits(32), struct_wz32) -> unit + +function wz32 (reg, sailval, keywords) = { + let data : bits(512) = zmms[unsigned(reg)]; + let regtype : bits(3) = bits_of_int(keywords.regtype, 3); + let data : bits(512) = { + match regtype { + 2 => sail_zero_extend(loghead(128, data), 512), + 3 => sail_zero_extend(loghead(256, data), 512), + _ => data + } + }; + zmms[unsigned(reg)] = changeSlice(data, 0, 32, sailval) +} + +/*! Write @ ( ' val ' ) to low 64 bits of a ZMM register +

Upper bits: For XMM registers, upper @ ( ` ( - 512 + 128 ) ` ) bits are preserved if @ ( ' regtype ' ) is @ ( ' *xmm-access* ' ) ; + for @ ( ' *vex-xmm-access* ' ) , these bits are zeroed out. For + @ ( ' *ymm-access* ' ) , upper @ ( ` ( - 512 256 ) ` ) bits are zeroed + out. For @ ( ' *zmm-access* ' ) , no upper bits are zeroed out.

*/ +struct struct_wz64 = {regtype : int} + +val wz64 : (bits(5), bits(64), struct_wz64) -> unit + +function wz64 (reg, sailval, keywords) = { + let data : bits(512) = zmms[unsigned(reg)]; + let regtype : bits(3) = bits_of_int(keywords.regtype, 3); + let data : bits(512) = { + match regtype { + 2 => sail_zero_extend(loghead(128, data), 512), + 3 => sail_zero_extend(loghead(256, data), 512), + _ => data + } + }; + zmms[unsigned(reg)] = changeSlice(data, 0, 64, sailval) +} + +/*! Write @ ( ' val ' ) to low 128 bits of a ZMM register +

Upper bits: For XMM registers, upper @ ( ` ( - 512 + 128 ) ` ) bits are preserved if @ ( ' regtype ' ) is @ ( ' *xmm-access* ' ) ; + for @ ( ' *vex-xmm-access* ' ) , these bits are zeroed out. For + @ ( ' *ymm-access* ' ) , upper @ ( ` ( - 512 256 ) ` ) bits are zeroed + out. For @ ( ' *zmm-access* ' ) , no upper bits are zeroed out.

*/ +struct struct_wz128 = {regtype : int} + +val wz128 : (bits(5), bits(128), struct_wz128) -> unit + +function wz128 (reg, sailval, keywords) = { + let data : bits(512) = zmms[unsigned(reg)]; + let regtype : bits(3) = bits_of_int(keywords.regtype, 3); + let data : bits(512) = { + match regtype { + 2 => sail_zero_extend(loghead(128, data), 512), + 3 => sail_zero_extend(loghead(256, data), 512), + _ => data + } + }; + zmms[unsigned(reg)] = changeSlice(data, 0, 128, sailval) +} + +/*! Functions to read/write 32/64/128 bits into the XMM + registers ( to be used by non-VEX encoded 128-bit SIMD instructions ) +

These functions are meant to be used by instructions that + do not use a VEX or EVEX prefix --- these functions preserve the + upper bits of ZMM registers. For instructions that use these + prefixes and zero out these bits instead, see @ ( see + ZMMs-Reads-and-Writes ) .

+ +

Note that the index for accessing the XMM registers is 4-bits + wide ( as opposed to the 5-bit index for ZMM registers --- see @ ( see + ZMMs-Reads-and-Writes ) ) because only 16 XMM registers were supported + initially in the 64-bit mode ( and 8 in the 32-bit mode ) .

+ +

Source: Intel Vol. 2, Section 2.3.10 --- AVX Instructions + and Upper 128-bits of YMM registers:

+ +
If an instruction with a destination XMM register is + encoded with a VEX prefix, the processor zeroes the upper + bits ( above bit 128 ) of the equivalent YMM register. Legacy SSE + instructions without VEX preserve the upper bits.
+ +

Functions @ ( see rx32 ) , @ ( see rx64 ) , and @ ( see rx128 ) will read the + contents of the XMMs ( i.e., low 128 bits of ZMMs ) as natural + numbers.

+ +

Similarly, functions @ ( see wx32 ) , @ ( see wx64 ) , and @ ( see wx128 ) + are used to write natural numbers into the XMMs ( and preserve the + upper bits of ZMMs ) .

*/ +val rx32 : bits(4) -> bits(32) + +function rx32 reg = { + rz32(sail_zero_extend(reg, 5)) +} + +val rx64 : bits(4) -> bits(64) + +function rx64 reg = { + rz64(sail_zero_extend(reg, 5)) +} + +val rx128 : bits(4) -> bits(128) + +function rx128 reg = { + rz128(sail_zero_extend(reg, 5)) +} + +/*! Write @ ( ' val ' ) to low 32 bits of a ZMM register; upper + bits are preserved. */ +val wx32 : (bits(4), bits(32)) -> unit + +function wx32 (reg, sailval) = { + wz32(sail_zero_extend(reg, 5), sailval, struct { regtype = 1 }) +} + +/*! Write @ ( ' val ' ) to low 64 bits of a ZMM register; upper + bits are preserved. */ +val wx64 : (bits(4), bits(64)) -> unit + +function wx64 (reg, sailval) = { + wz64(sail_zero_extend(reg, 5), sailval, struct { regtype = 1 }) +} + +/*! Write @ ( ' val ' ) to low 128 bits of a ZMM register; upper + bits are preserved. */ +val wx128 : (bits(4), bits(128)) -> unit + +function wx128 (reg, sailval) = { + wz128(sail_zero_extend(reg, 5), sailval, struct { regtype = 1 }) +} + +val xmmi_size : (bits(5), bits(4)) -> bits(128) + +function xmmi_size (nbytes, index) = { + (match nbytes { + 4 => sail_zero_extend(rx32(index), 128), + 8 => sail_zero_extend(rx64(index), 128), + 16 => rx128(index), + _ => 0x00000000000000000000000000000000 + }) : bits(128) +} + +/*! Write @ ( ' val ' ) to low @ ( ' nbytes ' ) of an XMM register; + upper bits of the ZMM register are preserved. */ +val write_xmmi_size : (bits(5), bits(4), int) -> unit + +function write_xmmi_size (nbytes, index, sailval) = { + (match nbytes { + 4 => wx32(index, bits_of_int(sailval, 32)), + 8 => wx64(index, bits_of_int(sailval, 64)), + 16 => wx128(index, bits_of_int(sailval, 128)), + _ => () + }) : unit +} + +/*! Get a unique unknown to be used when reasoning about + undefined values in the processor +

See @ ( see characterizing-undefined-behavior ) for more + details.

+ +

The accessor and updater functions of the @ ( ' undef ' ) field are + untouchable so that the only way to create a new seed for unknowns + is via this function.

*/ +val undef_read : unit -> nat + +function undef_read () = { + undef_read_logic() +} + +/*! Reading from and writing to the @ ( ' rflags ' ) register in the @ ( ' x86 ' ) state +

We define convenient macros @ ( ' flgi ' ) and @ ( ' !flgi ' ) to read a + flag ' s value and to write a flag ' s value into the @ ( ' rflags ' ) field in the + @ ( ' x86 ' ) state, respectively. Additionally, @ ( ' !flgi-undefined ' ) can be + used to write an undefined value into a particular flag.

*/ +val undef_flg_logic : unit -> nat + +function undef_flg_logic () = { + undef_read() +} + +val undef_flg : unit -> bits(1) + +function undef_flg () = { + let sailval : nat = undef_flg_logic(); + bits_of_int(sailval, 1) +} + +/*! Writing user rflags \ ( CF, PF, AF, ZF, SF, and OF\ ) , + including undefined ones, to the x86 state +

We set the undefined flags, which are indicated by + @ ( ' mask ' ) , to the value returned by @ ( see undef-read ) .

*/ +val write_user_rflags : (rflagsbits, rflagsbits) -> unit + +function write_user_rflags (user_flags_vector, undefined_mask) = { + let input_rflags : rflagsbits = rflags; + if undefined_mask[cf] == 0b1 then { + let rflags_var : rflagsbits = rflags; + let sailval : bits(1) = undef_flg(); + let new_rflags : rflagsbits = [rflags_var with cf = sailval]; + rflags = new_rflags + } else { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with cf = user_flags_vector[cf]]; + rflags = new_rflags + }; + if undefined_mask[pf] == 0b1 then { + let rflags_var : rflagsbits = rflags; + let sailval : bits(1) = undef_flg(); + let new_rflags : rflagsbits = [rflags_var with pf = sailval]; + rflags = new_rflags + } else { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with pf = user_flags_vector[pf]]; + rflags = new_rflags + }; + if undefined_mask[af] == 0b1 then { + let rflags_var : rflagsbits = rflags; + let sailval : bits(1) = undef_flg(); + let new_rflags : rflagsbits = [rflags_var with af = sailval]; + rflags = new_rflags + } else { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with af = user_flags_vector[af]]; + rflags = new_rflags + }; + if undefined_mask[zf] == 0b1 then { + let rflags_var : rflagsbits = rflags; + let sailval : bits(1) = undef_flg(); + let new_rflags : rflagsbits = [rflags_var with zf = sailval]; + rflags = new_rflags + } else { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with zf = user_flags_vector[zf]]; + rflags = new_rflags + }; + if undefined_mask[sf] == 0b1 then { + let rflags_var : rflagsbits = rflags; + let sailval : bits(1) = undef_flg(); + let new_rflags : rflagsbits = [rflags_var with sf = sailval]; + rflags = new_rflags + } else { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with sf = user_flags_vector[sf]]; + rflags = new_rflags + }; + if undefined_mask[of] == 0b1 then { + let rflags_var : rflagsbits = rflags; + let sailval : bits(1) = undef_flg(); + let new_rflags : rflagsbits = [rflags_var with of = sailval]; + rflags = new_rflags + } else { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with of = user_flags_vector[of]]; + rflags = new_rflags + }; + if log_register_writes then log_rflags_write(); + () +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_types.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_types.sail new file mode 100644 index 000000000..5e9636070 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/register_types.sail @@ -0,0 +1,12 @@ +$ifndef __X86_REGISTER_TYPES +$define __X86_REGISTER_TYPES + +type regtype = sbits(64) + +val regval_from_reg : regtype -> sbits(64) +function regval_from_reg(r) = r + +val regval_into_reg : sbits(64) -> regtype +function regval_into_reg(v) = v + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/registers.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/registers.sail new file mode 100644 index 000000000..06f973d89 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/registers.sail @@ -0,0 +1,154 @@ +$ifndef __X86_REGISTERS +$define __X86_REGISTERS + +$include "structures.sail" + +// Although one would expect rflags to be 64 bits, the ACL2 models +// it as 32 bits +register rflags : rflagsbits + +register rip : regtype + +// In ACL2 rgfi() is often called with a `defconst` argument. E.g. +// ` (rgfi *rax*) ` +// Unfortunately the translator currently translates these as number literals. +// So (ignoring the dummy x86 variable) the above will become: +// ` rgfi(0)` +// To find the number *rax* maps to, one can simply type `*rax*` into and ACL2 +// terminal with the x86 ISA project loaded. +// +// Each of the gprs is defined separately below, as opposed to a vector of +// bitvectors as other registers are. This is so they play nicely with +// concurrency tools. It also means rgfi() and write_rgfi() must work out +// which reg to access themselves, instead of indexing an array. +// +// See here for some hints on rgfi: +// http://www.cs.utexas.edu/users/moore/acl2/manuals/current/manual/index-seo.php/X86ISA____GPRS-READS-AND-WRITES?path=3532/29063/10660/6710/25183 + +register rax : regtype +register rbx : regtype +register rcx : regtype +register rdx : regtype +register rsi : regtype +register rdi : regtype +register rsp : regtype +register rbp : regtype +register r8 : regtype +register r9 : regtype +register r10 : regtype +register r11 : regtype +register r12 : regtype +register r13 : regtype +register r14 : regtype +register r15 : regtype + +val read_gpr : range(0, 15) -> regtype +function read_gpr(idx) = { + match idx { + 0 => rax, + 1 => rcx, + 2 => rdx, + 3 => rbx, + 4 => rsp, + 5 => rbp, + 6 => rsi, + 7 => rdi, + 8 => r8, + 9 => r9, + 10 => r10, + 11 => r11, + 12 => r12, + 13 => r13, + 14 => r14, + 15 => r15 + } +} + +val write_gpr : (range(0, 15), regtype) -> unit +function write_gpr(idx, value) = { + match idx { + 0 => rax = value, + 1 => rcx = value, + 2 => rdx = value, + 3 => rbx = value, + 4 => rsp = value, + 5 => rbp = value, + 6 => rsi = value, + 7 => rdi = value, + 8 => r8 = value, + 9 => r9 = value, + 10 => r10 = value, + 11 => r11 = value, + 12 => r12 = value, + 13 => r13 = value, + 14 => r14 = value, + 15 => r15 = value + }; + if log_register_writes then log_gpr_write(idx); +} + +/* +Model Specific Registers + +Footnote b in section 5.1 of Goel thesis says only 6 MSR registers +(I think they mean 7) are thus far defined in the model. For now, +we enumerate some of them explicitely here. Fortuantely, the indexes +range from 0..6, and we can lump them into a vector of registers + +TODO: make this enumeration automatic +*/ +register msrs : vector(7, dec, bits(64)) // 64 bits as per table 5.1 in thesis + +/* +seg-visible registers etc.. From `concrete-state.lisp` we find +there are 6 x 16bit registers + +TODO: make this automatic (including the number 6, which is a global +constant but subject to change) + +TODO: in `xr` in ACL2 we have things like seg_hidden_attri* (i.e. +with a trailing asterisk). Why is this? +*/ +register seg_visibles : vector(6, dec, bits(16)) + +register seg_hidden_attrs : vector(6, dec, bits(16)) + +register seg_hidden_bases : vector(6, dec, bits(64)) + +register seg_hidden_limits : vector(6, dec, bits(32)) + +/* +zmm registers. From `concrete-state.lisp` we find there are +32 x 512bit registers + +TODO: make this automatic (including the number 32, which is a global +constant but subject to change) +*/ +register zmms : vector (32, dec, bits(512)) + +/* +Control registers. From `concrete-state.lisp` we find there are +17 x 64bit registers + +TODO: make this automatic (including the number 17, which is a global +constant but subject to change) +*/ +register ctrs : vector (17, dec, bits(64)) + +/* +We can use `:pe ...` from `stri` and find we need the following. +*/ +register strs : vector(2, dec, bits(80)) + +/* +ssr +*/ +register ssr_visibles : vector(2, dec, bits(16)) + +register ssr_hidden_bases : vector(2, dec, bits(64)) + +register ssr_hidden_limits : vector(2, dec, bits(32)) + +register ssr_hidden_attrs : vector(2, dec, bits(16)) + +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rflags_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rflags_spec.sail new file mode 100644 index 000000000..94bac4872 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rflags_spec.sail @@ -0,0 +1,327 @@ +$include "./application_level_memory.sail" + +/*!

General @ ( ' CF ' ) Specification ( Source: Intel Manuals, + Vol. 1, Section 3.4.3.1 ) :

+ +

Carry flag Set if an arithmetic operation generates a + carry or a borrow out of the most-significant bit of the result; + cleared otherwise. This flag indicates an overflow condition for + unsigned-integer arithmetic. It is also used in multiple-precision + arithmetic.

*/ +val general_cf_spec_fn : (nat, nat) -> bits(1) + +function general_cf_spec_fn (result_nbits, raw_result) = { + bool_to_bits(not_bool(unsigned_byte_p(result_nbits, raw_result))) +} + +val cf_spec8 : bits(9) -> bits(1) + +function cf_spec8 raw_result = { + bool_to_bits(not_bool(unsigned_byte_p(8, unsigned(raw_result)))) +} + +val cf_spec16 : bits(17) -> bits(1) + +function cf_spec16 raw_result = { + bool_to_bits(not_bool(unsigned_byte_p(16, unsigned(raw_result)))) +} + +val cf_spec32 : bits(33) -> bits(1) + +function cf_spec32 raw_result = { + bool_to_bits(not_bool(unsigned_byte_p(32, unsigned(raw_result)))) +} + +val cf_spec64 : bits(65) -> bits(1) + +function cf_spec64 raw_result = { + bool_to_bits(not_bool(unsigned_byte_p(64, unsigned(raw_result)))) +} + +/*!

General @ ( ' OF ' ) Specification ( Source: Intel Manuals, + Vol. 1, Section 3.4.3.1 ) :

+ +

Overflow flag Set if the integer result is too large a + positive number or too small a negative number ( excluding the + sign-bit ) to fit in the destination operand; cleared otherwise. This + flag indicates an overflow condition for signed-integer ( two s + complement ) arithmetic.

*/ +val general_of_spec_fn : (nat, int) -> bits(1) + +function general_of_spec_fn (result_nbits, signed_raw_result) = { + bool_to_bits(not_bool(signed_byte_p(result_nbits, signed_raw_result))) +} + +val of_spec8 : sbits(9) -> bits(1) + +function of_spec8 signed_raw_result = { + bool_to_bits(not_bool(signed_byte_p(8, signed(signed_raw_result)))) +} + +val of_spec16 : sbits(17) -> bits(1) + +function of_spec16 signed_raw_result = { + bool_to_bits(not_bool(signed_byte_p(16, signed(signed_raw_result)))) +} + +val of_spec32 : sbits(33) -> bits(1) + +function of_spec32 signed_raw_result = { + bool_to_bits(not_bool(signed_byte_p(32, signed(signed_raw_result)))) +} + +val of_spec64 : sbits(65) -> bits(1) + +function of_spec64 signed_raw_result = { + bool_to_bits(not_bool(signed_byte_p(64, signed(signed_raw_result)))) +} + +/*!

General @ ( ' ZF ' ) Specification ( Source: Intel Manuals, + Vol. 1, Section 3.4.3.1 ) :

+ +

Zero flag Set if the result is zero; cleared + otherwise.

*/ +val zf_spec : nat -> bits(1) + +function zf_spec result = { + if result == 0 then 0b1 else 0b0 +} + +val bitcount8 : bits(8) -> nat + +function bitcount8 x = { + if x == 0 then 0 else { + nat_of_int(unsigned(loghead(1, x)) + check_range(0, 8, bitcount8(bits_of_int(logtail(1, unsigned(x)), 8)))) + } +} + +val pf_spec8 : bits(8) -> bits(1) + +function pf_spec8 result = { + bool_to_bits(not_bool(logbitp(0, logcount(unsigned(result))))) +} + +val pf_spec16 : bits(16) -> bits(1) + +function pf_spec16 result = { + bool_to_bits(not_bool(logbitp(0, logcount(unsigned(loghead(8, result)))))) +} + +val pf_spec32 : bits(32) -> bits(1) + +function pf_spec32 result = { + bool_to_bits(not_bool(logbitp(0, logcount(unsigned(loghead(8, result)))))) +} + +val pf_spec64 : bits(64) -> bits(1) + +function pf_spec64 result = { + bool_to_bits(not_bool(logbitp(0, logcount(unsigned(loghead(8, result)))))) +} + +/*!

General @ ( ' PF ' ) Specification ( Source: Intel Manuals, + Vol. 1, Section 3.4.3.1 ) :

+ +

Parity flag Set if the least-significant byte of the + result contains an even number of 1 bits; cleared otherwise.

*/ +val general_pf_spec_fn : ({|8, 16, 32, 64|}, nat) -> bits(1) + +function general_pf_spec_fn (result_nbits, result) = { + bool_to_bits(not_bool(logbitp(0, logcount(loghead(8, result))))) +} + +val sf_spec8 : bits(8) -> bits(1) + +function sf_spec8 result = { + result[7 .. 7] +} + +val sf_spec16 : bits(16) -> bits(1) + +function sf_spec16 result = { + result[15 .. 15] +} + +val sf_spec32 : bits(32) -> bits(1) + +function sf_spec32 result = { + result[31 .. 31] +} + +val sf_spec64 : bits(64) -> bits(1) + +function sf_spec64 result = { + result[63 .. 63] +} + +/*!

General @ ( ' SF ' ) Specification ( Source: Intel Manuals, + Vol. 1, Section 3.4.3.1 ) :

+ +

Sign flag Set equal to the most-significant bit of the + result, which is the sign bit of a signed integer. ( 0 indicates a + positive value and 1 indicates a negative value. )

*/ +val general_sf_spec_fn : ({|8, 16, 32, 64|}, nat) -> bits(1) + +function general_sf_spec_fn (result_nbits, result) = { + get_slice_int(1, result, result_nbits - 1) +} + +val add_af_spec8 : (bits(8), bits(8)) -> bits(1) + +function add_af_spec8 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let add : bits(5) = bits_of_int(unsigned(dst_3_0) + unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(15 < unsigned(add)); + af +} + +val add_af_spec16 : (bits(16), bits(16)) -> bits(1) + +function add_af_spec16 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let add : bits(5) = bits_of_int(unsigned(dst_3_0) + unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(15 < unsigned(add)); + af +} + +val add_af_spec32 : (bits(32), bits(32)) -> bits(1) + +function add_af_spec32 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let add : bits(5) = bits_of_int(unsigned(dst_3_0) + unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(15 < unsigned(add)); + af +} + +val add_af_spec64 : (bits(64), bits(64)) -> bits(1) + +function add_af_spec64 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let add : bits(5) = bits_of_int(unsigned(dst_3_0) + unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(15 < unsigned(add)); + af +} + +val sub_af_spec8 : (bits(8), bits(8)) -> bits(1) + +function sub_af_spec8 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sub : sbits(5) = bits_of_int(unsigned(dst_3_0) - unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(signed(sub) < 0); + af +} + +val sub_af_spec16 : (bits(16), bits(16)) -> bits(1) + +function sub_af_spec16 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sub : sbits(5) = bits_of_int(unsigned(dst_3_0) - unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(signed(sub) < 0); + af +} + +val sub_af_spec32 : (bits(32), bits(32)) -> bits(1) + +function sub_af_spec32 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sub : sbits(5) = bits_of_int(unsigned(dst_3_0) - unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(signed(sub) < 0); + af +} + +val sub_af_spec64 : (bits(64), bits(64)) -> bits(1) + +function sub_af_spec64 (dst, src) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sub : sbits(5) = bits_of_int(unsigned(dst_3_0) - unsigned(src_3_0), 5); + let af : bits(1) = bool_to_bits(signed(sub) < 0); + af +} + +val adc_af_spec8 : (bits(8), bits(8), bits(1)) -> bits(1) + +function adc_af_spec8 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let adc : bits(6) = bits_of_int(unsigned(dst_3_0) + (unsigned(src_3_0) + unsigned(cf)), 6); + let af : bits(1) = bool_to_bits(15 < unsigned(adc)); + af +} + +val adc_af_spec16 : (bits(16), bits(16), bits(1)) -> bits(1) + +function adc_af_spec16 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let adc : bits(6) = bits_of_int(unsigned(dst_3_0) + (unsigned(src_3_0) + unsigned(cf)), 6); + let af : bits(1) = bool_to_bits(15 < unsigned(adc)); + af +} + +val adc_af_spec32 : (bits(32), bits(32), bits(1)) -> bits(1) + +function adc_af_spec32 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let adc : bits(6) = bits_of_int(unsigned(dst_3_0) + (unsigned(src_3_0) + unsigned(cf)), 6); + let af : bits(1) = bool_to_bits(15 < unsigned(adc)); + af +} + +val adc_af_spec64 : (bits(64), bits(64), bits(1)) -> bits(1) + +function adc_af_spec64 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let adc : bits(6) = bits_of_int(unsigned(dst_3_0) + (unsigned(src_3_0) + unsigned(cf)), 6); + let af : bits(1) = bool_to_bits(15 < unsigned(adc)); + af +} + +val sbb_af_spec8 : (bits(8), bits(8), bits(1)) -> bits(1) + +function sbb_af_spec8 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sbb : int = unsigned(dst_3_0) - (unsigned(src_3_0) + unsigned(sail_zero_extend(cf, 4))); + let af : bits(1) = bool_to_bits(sbb < 0); + af +} + +val sbb_af_spec16 : (bits(16), bits(16), bits(1)) -> bits(1) + +function sbb_af_spec16 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sbb : int = unsigned(dst_3_0) - (unsigned(src_3_0) + unsigned(sail_zero_extend(cf, 4))); + let af : bits(1) = bool_to_bits(sbb < 0); + af +} + +val sbb_af_spec32 : (bits(32), bits(32), bits(1)) -> bits(1) + +function sbb_af_spec32 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sbb : int = unsigned(dst_3_0) - (unsigned(src_3_0) + unsigned(sail_zero_extend(cf, 4))); + let af : bits(1) = bool_to_bits(sbb < 0); + af +} + +val sbb_af_spec64 : (bits(64), bits(64), bits(1)) -> bits(1) + +function sbb_af_spec64 (dst, src, cf) = { + let dst_3_0 : bits(4) = dst[3 .. 0]; + let src_3_0 : bits(4) = src[3 .. 0]; + let sbb : int = unsigned(dst_3_0) - (unsigned(src_3_0) + unsigned(sail_zero_extend(cf, 4))); + let af : bits(1) = bool_to_bits(sbb < 0); + af +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rotate_and_shift.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rotate_and_shift.sail new file mode 100644 index 000000000..f0330d7b7 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/rotate_and_shift.sail @@ -0,0 +1,202 @@ +$include "./shifts_spec.sail" +$include "./rotates_spec.sail" + +/*!

+ Op/En: MI
+ C0/0: ROL r/m8, imm8
+ C0/1: ROR r/m8, imm8
+ C0/2: RCL r/m8, imm8
+ C0/3: RCR r/m8, imm8
+ C0/4: SAL/SHL r/m8, imm8
+ C0/5: SHR r/m8, imm8
+ C0/7: SAR r/m8, imm8
+ C1/0: ROL r/m16/32/64, imm8
+ C1/1: ROR r/m16/32/64, imm8
+ C1/2: RCL r/m16/32/64, imm8
+ C1/3: RCR r/m16/32/64, imm8
+ C1/4: SAL/SHL r/m16/32/64, imm8
+ C1/5: SHR r/m16/32/64, imm8
+ C1/7: SAR r/m16/32/64. imm8
+

+ +

+ Op/En: M1
+ D0/0: ROL r/m8, 1
+ D0/1: ROR r/m8, 1
+ D0/2: RCL r/m8, 1
+ D0/3: RCR r/m8, 1
+ D0/4: SAL/SHL r/m8, 1
+ D0/5: SHR r/m8, 1
+ D0/7: SAR r/m8, 1
+ D1/0: ROL r/m16/32/64, 1
+ D1/1: ROR r/m16/32/64, 1
+ D1/2: RCL r/m16/32/64, 1
+ D1/3: RCR r/m16/32/64, 1
+ D1/4: SAL/SHL r/m16/32/64, 1
+ D1/5: SHR r/m16/32/64, 1
+ D1/7: SAR r/m16/32/64, 1
+

+ +

+ Op/En: MC
+ D2/0: ROL r/m8, CL
+ D2/1: ROR r/m8, CL
+ D2/2: RCL r/m8, CL
+ D2/3: RCR r/m8, CL
+ D2/4: SAL/SHL r/m8, CL
+ D2/5: SHR r/m8, CL
+ D2/7: SAR r/m8, CL
+ D3/0: ROL r/m16/32/64, CL
+ D3/1: ROR r/m16/32/64, CL
+ D3/2: RCL r/m16/32/64, CL
+ D3/3: RCR r/m16/32/64, CL
+ D3/4: SAL/SHL r/m16/32/64, CL
+ D3/5: SHR r/m16/32/64, CL
+ D3/7: SAR r/m16/32/64, CL
+

*/ +val x86_sal_sar_shl_shr_rcl_rcr_rol_ror : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_sal_sar_shl_shr_rcl_rcr_rol_ror (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-SAL/SAR/SHL/SHR/RCL/RCR/ROL/ROR"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let byte_operand? : bool = opcode == 0xc0 | opcode == 0xd0 | opcode == 0xd2; + let reg_mem_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, byte_operand?, rex_byte, false, prefixes, false, false, false); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (reg_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, reg_mem_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, if opcode == 0xc0 | opcode == 0xc1 then 0b001 else 0b000); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let shift_rotate_by : bits(128) = { + match opcode { + 208 => 0x00000000000000000000000000000001, + 209 => 0x00000000000000000000000000000001, + 210 => sail_zero_extend(rr08(0x1, rex_byte), 128), + 211 => sail_zero_extend(rr08(0x1, rex_byte), 128), + 192 => rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), + 193 => rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), + _ => 0x00000000000000000000000000000000 + } + }; + let countmask : {|31, 63|} = { + if logbitp(3, rex_byte) & not_bool(byte_operand?) then 63 else 31 + }; + let shift_rotate_by : bits(128) = logand(bits_of_int(countmask, 128), shift_rotate_by); + let temp_rip : sbits(49) = { + if opcode == 0xc0 | opcode == 0xc1 then { + sail_sign_extend(add_to_iptr(proc_mode, temp_rip, 0x000000000001), 49) + } else { + sail_sign_extend(temp_rip, 49) + } + }; + let badlength? : option(int) = check_instruction_length(start_rip, truncate(temp_rip, 48), 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let input_rflags : rflagsbits = rflags; + let (result, output_rflags, undefined_flags) : (bits(64), rflagsbits, rflagsbits) = { + match reg { + 0 => rol_spec(reg_mem_size, truncate(reg_mem, 64), truncate(shift_rotate_by, 6), input_rflags), + 1 => ror_spec(reg_mem_size, truncate(reg_mem, 64), truncate(shift_rotate_by, 6), input_rflags), + 2 => rcl_spec(reg_mem_size, truncate(reg_mem, 64), truncate(shift_rotate_by, 6), input_rflags), + 3 => rcr_spec(reg_mem_size, truncate(reg_mem, 64), truncate(shift_rotate_by, 6), input_rflags), + 4 => sal_shl_spec(reg_mem_size, truncate(reg_mem, 64), truncate(shift_rotate_by, 6), input_rflags), + 5 => shr_spec(reg_mem_size, truncate(reg_mem, 64), truncate(shift_rotate_by, 6), input_rflags), + 7 => sar_spec(reg_mem_size, truncate(reg_mem, 64), truncate(shift_rotate_by, 6), input_rflags), + _ => (0x0000000000000000, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + } + }; + write_user_rflags(output_rflags, undefined_flags); + x86_operand_to_reg_mem(proc_mode, reg_mem_size, inst_ac?, false, sail_zero_extend(sail_mask(64, trunc(reg_mem_size, result)), 128), seg_reg, addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, truncate(temp_rip, 48)) +} + +/*! Double-precision shift left or right. +

+ Op/En: MRI
+ 0F A4: SHLD r/m16, r16, imm8
+ 0F A4: SHLD r/m32, r32, imm8
+ 0F A4: SHLD r/m64, r64, imm8
+

+ +

+ Op/En: MRC
+ 0F A5: SHLD r/m16, r16, CL
+ 0F A5: SHLD r/m32, r32, CL
+ 0F A5: SHLD r/m64, r64, CL
+

+ +

+ Op/En: MRI
+ 0F AC: SHRD r/m16, r16, imm8
+ 0F AC: SHRD r/m32, r32, imm8
+ 0F AC: SHRD r/m64, r64, imm8
+

+ +

+ Op/En: MRC
+ 0F AD: SHRD r/m16, r16, CL
+ 0F AD: SHRD r/m32, r32, CL
+ 0F AD: SHRD r/m64, r64, CL
+

*/ +val x86_shld_shrd : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_shld_shrd (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-SHLD/SHRD"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let operand_size : {|2, 4, 8|} = check_range(2, 8, select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false)); + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (dst_value, increment_rip_by, dst_addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b001); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let src_value : bits(64) = rgfi_size(bits_of_int(operand_size, 4), reg_index(reg, rex_byte, 0b10), rex_byte); + let count : bits(128) = { + match opcode { + 164 => rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), + 172 => rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), + 165 => sail_zero_extend(rr08(0x1, rex_byte), 128), + 173 => sail_zero_extend(rr08(0x1, rex_byte), 128), + _ => 0x00000000000000000000000000000000 + } + }; + let temp_rip : sbits(48) = { + match opcode { + 164 => add_to_iptr(proc_mode, temp_rip, 0x000000000001), + 172 => add_to_iptr(proc_mode, temp_rip, 0x000000000001), + 165 => temp_rip, + 173 => temp_rip, + _ => 0x000000000000 + } + }; + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let count_mask : {|31, 63|} = { + if logbitp(3, rex_byte) then 63 else 31 + }; + let count : bits(128) = logand(bits_of_int(count_mask, 128), count); + let input_rflags : rflagsbits = rflags; + let (result, result_undefined?, output_rflags, undefined_flags) : (bits(64), bool, rflagsbits, rflagsbits) = { + match opcode { + 164 => shld_spec(operand_size, truncate(dst_value, 64), src_value, truncate(count, 6), input_rflags), + 165 => shld_spec(operand_size, truncate(dst_value, 64), src_value, truncate(count, 6), input_rflags), + 172 => shrd_spec(operand_size, truncate(dst_value, 64), src_value, truncate(count, 6), input_rflags), + 173 => shrd_spec(operand_size, truncate(dst_value, 64), src_value, truncate(count, 6), input_rflags), + _ => (0x0000000000000000, false, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + } + }; + let result : int = { + if result_undefined? then { + undef_read() + } else { + unsigned(result) + } + }; + write_user_rflags(output_rflags, undefined_flags); + x86_operand_to_reg_mem(proc_mode, operand_size, inst_ac?, false, sail_zero_extend(sail_mask(64, trunc(operand_size, bits_of_int(result, 64))), 128), seg_reg, dst_addr, prefixes, rex_byte, r_m, mod_var, sib); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shifts_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shifts_spec.sail new file mode 100644 index 000000000..9f9771bd0 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shifts_spec.sail @@ -0,0 +1,914 @@ + +val sal_shl_spec_8 : (bits(8), bits(6), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function sal_shl_spec_8 (dst, src, input_rflags) = { + let raw_result : int = ash(unsigned(dst), unsigned(src)); + let result : bits(8) = bits_of_int(raw_result, 8); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[7 .. 7]; + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : int = b_xor(unsigned(cf), unsigned(logbit(7, result))); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 8 <= unsigned(src) then { + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, 8 - unsigned(src), 1); + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val sal_shl_spec_16 : (bits(16), bits(6), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function sal_shl_spec_16 (dst, src, input_rflags) = { + let raw_result : int = ash(unsigned(dst), unsigned(src)); + let result : bits(16) = bits_of_int(raw_result, 16); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[15 .. 15]; + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : int = b_xor(unsigned(cf), unsigned(logbit(15, result))); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 16 <= unsigned(src) then { + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, 16 - unsigned(src), 1); + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val sal_shl_spec_32 : (bits(32), bits(6), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function sal_shl_spec_32 (dst, src, input_rflags) = { + let raw_result : int = ash(unsigned(dst), unsigned(src)); + let result : bits(32) = bits_of_int(raw_result, 32); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[31 .. 31]; + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : int = b_xor(unsigned(cf), unsigned(logbit(31, result))); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 32 <= unsigned(src) then { + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, 32 - unsigned(src), 1); + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val sal_shl_spec_64 : (bits(64), bits(6), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function sal_shl_spec_64 (dst, src, input_rflags) = { + let raw_result : int = ash(unsigned(dst), unsigned(src)); + let result : bits(64) = bits_of_int(raw_result, 64); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[63 .. 63]; + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : int = b_xor(unsigned(cf), unsigned(logbit(63, result))); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 64 <= unsigned(src) then { + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, 64 - unsigned(src), 1); + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +/*! Specification for the @ ( ' SAL/SHL ' ) instruction +

Source: Intel Manual, Volume 2B, Instruction Set Reference + \ ( N-Z\ ) .

+ +

The shift arithmetic left \ ( SAL\ ) and shift logical left \ ( SHL\ ) + instructions perform the same operation; they shift the bits in the + destination operand to the left \ ( toward more significant bit + locations\ ) . For each shift count, the most significant bit of the + destination operand is shifted into the CF flag, and the least + significant bit is cleared. The OF flag is affected only on 1-bit + shifts. For left shifts, the OF flag is set to 0 if the + most-significant bit of the result is the same as the CF flag ( that + is, the top two bits of the original operand were the same ) ; + otherwise, it is set to 1.

*/ +val sal_shl_spec : ({|1, 2, 4, 8|}, bits(64), bits(6), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function sal_shl_spec (size, dst, src, input_rflags) = { + (match size { + 1 => { + let (elem0, elem1, elem2) : (bits(8), rflagsbits, rflagsbits) = sal_shl_spec_8(truncate(dst, 8), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 2 => { + let (elem0, elem1, elem2) : (bits(16), rflagsbits, rflagsbits) = sal_shl_spec_16(truncate(dst, 16), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 4 => { + let (elem0, elem1, elem2) : (bits(32), rflagsbits, rflagsbits) = sal_shl_spec_32(truncate(dst, 32), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 8 => sal_shl_spec_64(dst, src, input_rflags), + _ => (0x0000000000000000, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(64), rflagsbits, rflagsbits) +} + +val shr_spec_8 : (bits(8), bits(6), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function shr_spec_8 (dst, src, input_rflags) = { + let neg_src : sbits(9) = bits_of_int(negate(unsigned(src)), 9); + let raw_result : bits(8) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 8); + let result : bits(8) = raw_result; + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : bits(1) = dst[7 .. 7]; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 8 <= unsigned(src) then { + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val shr_spec_16 : (bits(16), bits(6), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function shr_spec_16 (dst, src, input_rflags) = { + let neg_src : sbits(17) = bits_of_int(negate(unsigned(src)), 17); + let raw_result : bits(16) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 16); + let result : bits(16) = raw_result; + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : bits(1) = dst[15 .. 15]; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 16 <= unsigned(src) then { + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val shr_spec_32 : (bits(32), bits(6), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function shr_spec_32 (dst, src, input_rflags) = { + let neg_src : sbits(33) = bits_of_int(negate(unsigned(src)), 33); + let raw_result : bits(32) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 32); + let result : bits(32) = raw_result; + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : bits(1) = dst[31 .. 31]; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 32 <= unsigned(src) then { + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val shr_spec_64 : (bits(64), bits(6), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function shr_spec_64 (dst, src, input_rflags) = { + let neg_src : sbits(65) = bits_of_int(negate(unsigned(src)), 65); + let raw_result : bits(64) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 64); + let result : bits(64) = raw_result; + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : bits(1) = dst[63 .. 63]; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 64 <= unsigned(src) then { + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +/*! Specification for the @ ( ' SHR ' ) instruction +

Source: Intel Manual, Volume 2B, Instruction Set Reference \ ( N-Z\ ) .

+ +

The shift arithmetic right \ ( SAR\ ) and shift logical right \ ( SHR\ ) + instructions shift the bits of the destination operand to the right + \ ( toward less significant bit locations\ ) . For each shift count, the + least significant bit of the destination operand is shifted into the + CF flag, and the most significant bit is either set or cleared + depending on the instruction type. The SHR instruction clears the most + significant bit ( see Figure 7-8 in the Intel 64 and IA-32 + Architectures Software Developer s Manual, Volume 1 ) ... The OF flag is + affected only on 1-bit shifts. For the SAR instruction, the OF flag is + cleared for all 1-bit shifts. For the SHR instruction, the OF flag is + set to the most-significant bit of the original operand.

*/ +val shr_spec : ({|1, 2, 4, 8|}, bits(64), bits(6), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function shr_spec (size, dst, src, input_rflags) = { + (match size { + 1 => { + let (elem0, elem1, elem2) : (bits(8), rflagsbits, rflagsbits) = shr_spec_8(truncate(dst, 8), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 2 => { + let (elem0, elem1, elem2) : (bits(16), rflagsbits, rflagsbits) = shr_spec_16(truncate(dst, 16), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 4 => { + let (elem0, elem1, elem2) : (bits(32), rflagsbits, rflagsbits) = shr_spec_32(truncate(dst, 32), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 8 => shr_spec_64(dst, src, input_rflags), + _ => (0x0000000000000000, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(64), rflagsbits, rflagsbits) +} + +val sar_spec_8 : (bits(8), bits(6), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function sar_spec_8 (dst, src, input_rflags) = { + let neg_src : sbits(9) = bits_of_int(negate(unsigned(src)), 9); + let raw_result_not_sign_extended : bits(8) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 8); + let raw_result : int = { + if logbit(7, dst) == 0b1 then { + loghead(8, ash(binary_logext(8, unsigned(dst)), signed(neg_src))) + } else { + unsigned(raw_result_not_sign_extended) + } + }; + let result : bits(8) = bits_of_int(raw_result, 8); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 8 <= unsigned(src) then { + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val sar_spec_16 : (bits(16), bits(6), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function sar_spec_16 (dst, src, input_rflags) = { + let neg_src : sbits(17) = bits_of_int(negate(unsigned(src)), 17); + let raw_result_not_sign_extended : bits(16) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 16); + let raw_result : int = { + if logbit(15, dst) == 0b1 then { + loghead(16, ash(binary_logext(16, unsigned(dst)), signed(neg_src))) + } else { + unsigned(raw_result_not_sign_extended) + } + }; + let result : bits(16) = bits_of_int(raw_result, 16); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 16 <= unsigned(src) then { + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val sar_spec_32 : (bits(32), bits(6), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function sar_spec_32 (dst, src, input_rflags) = { + let neg_src : sbits(33) = bits_of_int(negate(unsigned(src)), 33); + let raw_result_not_sign_extended : bits(32) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 32); + let raw_result : int = { + if logbit(31, dst) == 0b1 then { + loghead(32, ash(binary_logext(32, unsigned(dst)), signed(neg_src))) + } else { + unsigned(raw_result_not_sign_extended) + } + }; + let result : bits(32) = bits_of_int(raw_result, 32); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 32 <= unsigned(src) then { + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +val sar_spec_64 : (bits(64), bits(6), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function sar_spec_64 (dst, src, input_rflags) = { + let neg_src : sbits(65) = bits_of_int(negate(unsigned(src)), 65); + let raw_result_not_sign_extended : bits(64) = bits_of_int(ash(unsigned(dst), signed(neg_src)), 64); + let raw_result : int = { + if logbit(63, dst) == 0b1 then { + loghead(64, ash(binary_logext(64, unsigned(dst)), signed(neg_src))) + } else { + unsigned(raw_result_not_sign_extended) + } + }; + let result : bits(64) = bits_of_int(raw_result, 64); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match src { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if 64 <= unsigned(src) then { + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let output_rflags : rflagsbits = [input_rflags with pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with cf = 0b1, af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let cf : bits(1) = bitslice(dst, unsigned(src) - 1, 1); + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (result, output_rflags, undefined_flags) +} + +/*! Specification for the @ ( ' SAR ' ) instruction +

Source: Intel Manual, Volume 2B, Instruction Set Reference \ ( N-Z\ ) .

+ +

The shift arithmetic right \ ( SAR\ ) and shift logical right \ ( SHR\ ) + instructions shift the bits of the destination operand to the right + \ ( toward less significant bit locations\ ) . For each shift count, the + least significant bit of the destination operand is shifted into the + CF flag, and the most significant bit is either set or cleared + depending on the instruction type. The SAR instruction sets or clears + the most significant bit to correspond to the sign \ ( most significant + bit\ ) of the original value in the destination operand. In effect, the + SAR instruction fills the empty bit position s shifted value with the + sign of the unshifted value. ... The OF flag is affected only on 1-bit + shifts. For the SAR instruction, the OF flag is cleared for all 1-bit + shifts. For the SHR instruction, the OF flag is set to the + most-significant bit of the original operand.

*/ +val sar_spec : ({|1, 2, 4, 8|}, bits(64), bits(6), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function sar_spec (size, dst, src, input_rflags) = { + (match size { + 1 => { + let (elem0, elem1, elem2) : (bits(8), rflagsbits, rflagsbits) = sar_spec_8(truncate(dst, 8), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 2 => { + let (elem0, elem1, elem2) : (bits(16), rflagsbits, rflagsbits) = sar_spec_16(truncate(dst, 16), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 4 => { + let (elem0, elem1, elem2) : (bits(32), rflagsbits, rflagsbits) = sar_spec_32(truncate(dst, 32), src, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2) + }, + 8 => sar_spec_64(dst, src, input_rflags), + _ => (0x0000000000000000, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(64), rflagsbits, rflagsbits) +} + +val shld_spec_16 : (bits(16), bits(16), bits(6), rflagsbits) -> (bits(16), bool, rflagsbits, rflagsbits) + +function shld_spec_16 (dst, src, cnt, input_rflags) = { + let dst_src : bits(32) = logior(bits_of_int(ash(unsigned(dst), 16), 32), sail_zero_extend(src, 32)); + let output_dst : bits(16) = bits_of_int(ash(unsigned(dst_src), unsigned(sail_zero_extend(cnt, 16)) - 16), 16); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match cnt { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[15 .. 15]; + let of : {|0, 1|} = { + if logbit(15, dst) == logbit(15, output_dst) then 0 else 1 + }; + let pf : bits(1) = pf_spec16(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec16(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, of = bits_of_int(of, 1), pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if unsigned(cnt) <= 16 then { + let cf : bits(1) = bitslice(dst, 16 - unsigned(cnt), 1); + let pf : bits(1) = pf_spec16(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec16(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let output_rflags : rflagsbits = input_rflags; + let undefined_flags : rflagsbits = [input_rflags with af = 0b1, sf = 0b1, zf = 0b1, pf = 0b1, of = 0b1, cf = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (output_dst, unsigned(cnt) > 16, output_rflags, undefined_flags) +} + +val shld_spec_32 : (bits(32), bits(32), bits(6), rflagsbits) -> (bits(32), bool, rflagsbits, rflagsbits) + +function shld_spec_32 (dst, src, cnt, input_rflags) = { + let dst_src : bits(64) = logior(bits_of_int(ash(unsigned(dst), 32), 64), sail_zero_extend(src, 64)); + let output_dst : bits(32) = bits_of_int(ash(unsigned(dst_src), unsigned(sail_zero_extend(cnt, 32)) - 32), 32); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match cnt { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[31 .. 31]; + let of : {|0, 1|} = { + if logbit(31, dst) == logbit(31, output_dst) then 0 else 1 + }; + let pf : bits(1) = pf_spec32(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec32(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, of = bits_of_int(of, 1), pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if unsigned(cnt) <= 32 then { + let cf : bits(1) = bitslice(dst, 32 - unsigned(cnt), 1); + let pf : bits(1) = pf_spec32(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec32(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let output_rflags : rflagsbits = input_rflags; + let undefined_flags : rflagsbits = [input_rflags with af = 0b1, sf = 0b1, zf = 0b1, pf = 0b1, of = 0b1, cf = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (output_dst, unsigned(cnt) > 32, output_rflags, undefined_flags) +} + +val shld_spec_64 : (bits(64), bits(64), bits(6), rflagsbits) -> (bits(64), bool, rflagsbits, rflagsbits) + +function shld_spec_64 (dst, src, cnt, input_rflags) = { + let dst_src : bits(128) = logior(bits_of_int(ash(unsigned(dst), 64), 128), sail_zero_extend(src, 128)); + let output_dst : bits(64) = bits_of_int(ash(unsigned(dst_src), unsigned(sail_zero_extend(cnt, 64)) - 64), 64); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match cnt { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[63 .. 63]; + let of : {|0, 1|} = { + if logbit(63, dst) == logbit(63, output_dst) then 0 else 1 + }; + let pf : bits(1) = pf_spec64(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec64(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, of = bits_of_int(of, 1), pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if unsigned(cnt) <= 64 then { + let cf : bits(1) = bitslice(dst, 64 - unsigned(cnt), 1); + let pf : bits(1) = pf_spec64(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec64(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let output_rflags : rflagsbits = input_rflags; + let undefined_flags : rflagsbits = [input_rflags with af = 0b1, sf = 0b1, zf = 0b1, pf = 0b1, of = 0b1, cf = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (output_dst, unsigned(cnt) > 64, output_rflags, undefined_flags) +} + +/*! Specification for the @ ( ' SHLD ' ) instruction. */ +val shld_spec : ({|2, 4, 8|}, bits(64), bits(64), bits(6), rflagsbits) -> (bits(64), bool, rflagsbits, rflagsbits) + +function shld_spec (size, dst, src, cnt, input_rflags) = { + (match size { + 2 => { + let (elem0, elem1, elem2, elem3) : (bits(16), bool, rflagsbits, rflagsbits) = shld_spec_16(truncate(dst, 16), truncate(src, 16), cnt, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2, elem3) + }, + 4 => { + let (elem0, elem1, elem2, elem3) : (bits(32), bool, rflagsbits, rflagsbits) = shld_spec_32(truncate(dst, 32), truncate(src, 32), cnt, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2, elem3) + }, + 8 => shld_spec_64(dst, src, cnt, input_rflags), + _ => (0x0000000000000000, false, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(64), bool, rflagsbits, rflagsbits) +} + +val shrd_spec_16 : (bits(16), bits(16), bits(6), rflagsbits) -> (bits(16), bool, rflagsbits, rflagsbits) + +function shrd_spec_16 (dst, src, cnt, input_rflags) = { + let src_dst : bits(32) = logior(bits_of_int(ash(unsigned(src), 16), 32), sail_zero_extend(dst, 32)); + let neg_cnt : sbits(17) = bits_of_int(negate(unsigned(cnt)), 17); + let output_dst : bits(16) = bits_of_int(ash(unsigned(src_dst), signed(neg_cnt)), 16); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match cnt { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let of : {|0, 1|} = { + if logbit(15, dst) == logbit(15, output_dst) then 0 else 1 + }; + let pf : bits(1) = pf_spec16(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec16(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, of = bits_of_int(of, 1), pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if unsigned(cnt) <= 16 then { + let cf : bits(1) = bitslice(dst, unsigned(cnt) - 1, 1); + let pf : bits(1) = pf_spec16(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec16(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let output_rflags : rflagsbits = input_rflags; + let undefined_flags : rflagsbits = [input_rflags with af = 0b1, sf = 0b1, zf = 0b1, pf = 0b1, of = 0b1, cf = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (output_dst, unsigned(cnt) > 16, output_rflags, undefined_flags) +} + +val shrd_spec_32 : (bits(32), bits(32), bits(6), rflagsbits) -> (bits(32), bool, rflagsbits, rflagsbits) + +function shrd_spec_32 (dst, src, cnt, input_rflags) = { + let src_dst : bits(64) = logior(bits_of_int(ash(unsigned(src), 32), 64), sail_zero_extend(dst, 64)); + let neg_cnt : sbits(33) = bits_of_int(negate(unsigned(cnt)), 33); + let output_dst : bits(32) = bits_of_int(ash(unsigned(src_dst), signed(neg_cnt)), 32); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match cnt { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let of : {|0, 1|} = { + if logbit(31, dst) == logbit(31, output_dst) then 0 else 1 + }; + let pf : bits(1) = pf_spec32(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec32(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, of = bits_of_int(of, 1), pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if unsigned(cnt) <= 32 then { + let cf : bits(1) = bitslice(dst, unsigned(cnt) - 1, 1); + let pf : bits(1) = pf_spec32(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec32(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let output_rflags : rflagsbits = input_rflags; + let undefined_flags : rflagsbits = [input_rflags with af = 0b1, sf = 0b1, zf = 0b1, pf = 0b1, of = 0b1, cf = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (output_dst, unsigned(cnt) > 32, output_rflags, undefined_flags) +} + +val shrd_spec_64 : (bits(64), bits(64), bits(6), rflagsbits) -> (bits(64), bool, rflagsbits, rflagsbits) + +function shrd_spec_64 (dst, src, cnt, input_rflags) = { + let src_dst : bits(128) = logior(bits_of_int(ash(unsigned(src), 64), 128), sail_zero_extend(dst, 128)); + let neg_cnt : sbits(65) = bits_of_int(negate(unsigned(cnt)), 65); + let output_dst : bits(64) = bits_of_int(ash(unsigned(src_dst), signed(neg_cnt)), 64); + let (output_rflags, undefined_flags) : (rflagsbits, rflagsbits) = { + match cnt { + 0 => (input_rflags, Mk_rflagsbits(0x00000000)), + 1 => { + let cf : bits(1) = dst[0 .. 0]; + let of : {|0, 1|} = { + if logbit(63, dst) == logbit(63, output_dst) then 0 else 1 + }; + let pf : bits(1) = pf_spec64(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec64(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, of = bits_of_int(of, 1), pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (output_rflags, undefined_flags) + }, + _ => { + if unsigned(cnt) <= 64 then { + let cf : bits(1) = bitslice(dst, unsigned(cnt) - 1, 1); + let pf : bits(1) = pf_spec64(output_dst); + let zf : bits(1) = zf_spec(unsigned(output_dst)); + let sf : bits(1) = sf_spec64(output_dst); + let output_rflags : rflagsbits = [input_rflags with cf, pf, zf, sf]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1, of = 0b1]; + (output_rflags, undefined_flags) + } else { + let output_rflags : rflagsbits = input_rflags; + let undefined_flags : rflagsbits = [input_rflags with af = 0b1, sf = 0b1, zf = 0b1, pf = 0b1, of = 0b1, cf = 0b1]; + (output_rflags, undefined_flags) + } + } + } + }; + (output_dst, unsigned(cnt) > 64, output_rflags, undefined_flags) +} + +/*! Specification for the @ ( ' SHRD ' ) instruction. */ +val shrd_spec : ({|2, 4, 8|}, bits(64), bits(64), bits(6), rflagsbits) -> (bits(64), bool, rflagsbits, rflagsbits) + +function shrd_spec (size, dst, src, cnt, input_rflags) = { + (match size { + 2 => { + let (elem0, elem1, elem2, elem3) : (bits(16), bool, rflagsbits, rflagsbits) = shrd_spec_16(truncate(dst, 16), truncate(src, 16), cnt, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2, elem3) + }, + 4 => { + let (elem0, elem1, elem2, elem3) : (bits(32), bool, rflagsbits, rflagsbits) = shrd_spec_32(truncate(dst, 32), truncate(src, 32), cnt, input_rflags); + (sail_zero_extend(elem0, 64), elem1, elem2, elem3) + }, + 8 => shrd_spec_64(dst, src, cnt, input_rflags), + _ => (0x0000000000000000, false, Mk_rflagsbits(0x00000000), Mk_rflagsbits(0x00000000)) + }) : (bits(64), bool, rflagsbits, rflagsbits) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shuffle_and_unpack.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shuffle_and_unpack.sail new file mode 100644 index 000000000..3735faf3b --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/shuffle_and_unpack.sail @@ -0,0 +1,182 @@ + +val extract_32_bits : (bits(128), bits(2)) -> bits(32) + +function extract_32_bits (x, n) = { + (match n { + 0 => x[31 .. 0], + 1 => x[63 .. 32], + 2 => x[95 .. 64], + _ => x[127 .. 96] + }) : bits(32) +} + +val extract_64_bits : (bits(128), range(0, 1)) -> bits(64) + +function extract_64_bits (x, n) = { + (match n { + 0 => x[63 .. 0], + _ => x[127 .. 64] + }) : bits(64) +} + +/*! Shuffle packed single-precision floating-point values +

Op/En = RMI: [OP XMM, XMM/M, IMM]

+ 0F C6: SHUFPS xmm1, xmm2/m128, imm8
*/ +val x86_shufps_op_en_rmi : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_shufps_op_en_rmi (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-SHUFPS-OP/EN-RMI"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(0b10000, xmm_index); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (xmm_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 16, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b001); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let imm : bits(8) = truncate(rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), 8); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let imm0 : bits(2) = imm[1 .. 0]; + let imm1 : bits(2) = imm[3 .. 2]; + let imm2 : bits(2) = imm[5 .. 4]; + let imm3 : bits(2) = imm[7 .. 6]; + let dword0 : bits(32) = extract_32_bits(xmm, imm0); + let dword1 : bits(32) = extract_32_bits(xmm, imm1); + let dword2 : bits(32) = extract_32_bits(xmm_mem, imm2); + let dword3 : bits(32) = extract_32_bits(xmm_mem, imm3); + let result : bits(128) = dword3 @ (dword2 @ (dword1 @ dword0)); + write_xmmi_size(0b10000, xmm_index, unsigned(result)); + write_iptr(proc_mode, temp_rip) +} + +/*! Shuffle packed double-precision floating-point values +

Op/En = RMI: [OP XMM, XMM/M, IMM]

+ 66 0F C6: SHUFPD xmm1, xmm2/m128, imm8
*/ +val x86_shufpd_op_en_rmi : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_shufpd_op_en_rmi (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-SHUFPD-OP/EN-RMI"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(0b10000, xmm_index); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (xmm_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 16, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b001); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let imm : bits(8) = truncate(rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), 1, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), 8); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let imm0 : bits(1) = logbit(0, imm); + let imm1 : bits(1) = logbit(1, imm); + let qword0 : bits(64) = extract_64_bits(xmm, unsigned(imm0)); + let qword1 : bits(64) = extract_64_bits(xmm_mem, unsigned(imm1)); + let result : bits(128) = qword1 @ qword0; + write_xmmi_size(0b10000, xmm_index, unsigned(result)); + write_iptr(proc_mode, temp_rip) +} + +/*! Unpack and interleave low/high packed single-precision floating-point + values +

Op/En = RM: [OP XMM, XMM/M]

+ 0F 14: UNPCKLPS xmm1, xmm2/m128
+ 0F 15: UNPCKHPS xmm1, xmm2/m128
*/ +val x86_unpck?ps_op_en_rm : (range(0, 1), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_unpck?ps_op_en_rm (high_low, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-UNPCK?PS-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(0b10000, xmm_index); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (xmm_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 16, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let dword0 : bits(32) = { + if high_low == 1 then { + xmm[95 .. 64] + } else { + xmm[31 .. 0] + } + }; + let dword1 : bits(32) = { + if high_low == 1 then { + xmm_mem[95 .. 64] + } else { + xmm_mem[31 .. 0] + } + }; + let dword2 : bits(32) = { + if high_low == 1 then { + xmm[127 .. 96] + } else { + xmm[63 .. 32] + } + }; + let dword3 : bits(32) = { + if high_low == 1 then { + xmm_mem[127 .. 96] + } else { + xmm_mem[63 .. 32] + } + }; + let result : bits(128) = dword3 @ (dword2 @ (dword1 @ dword0)); + write_xmmi_size(0b10000, xmm_index, unsigned(result)); + write_iptr(proc_mode, temp_rip) +} + +/*! Unpack and interleave low/high packed double-precision floating-point + values +

Op/En = RM: [OP XMM, XMM/M]

+ 66 0F 14: UNPCKLPD xmm1, xmm2/m128
+ 66 0F 15: UNPCKHPD xmm1, xmm2/m128
*/ +val x86_unpck?pd_op_en_rm : (range(0, 1), proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_unpck?pd_op_en_rm (high_low, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-UNPCK?PD-OP/EN-RM"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let xmm_index : bits(4) = reg_index(reg, rex_byte, 0b10); + let xmm : bits(128) = xmmi_size(0b10000, xmm_index); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (xmm_mem, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b1, 16, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, bits_of_int(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, temp_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let qword0 : bits(64) = { + if high_low == 1 then { + xmm[127 .. 64] + } else { + xmm[63 .. 0] + } + }; + let qword1 : bits(64) = { + if high_low == 1 then { + xmm_mem[127 .. 64] + } else { + xmm_mem[63 .. 0] + } + }; + let result : bits(128) = qword1 @ qword0; + write_xmmi_size(0b10000, xmm_index, unsigned(result)); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/signextend.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/signextend.sail new file mode 100644 index 000000000..702c8465a --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/signextend.sail @@ -0,0 +1,37 @@ + +val x86_cbw_cwd_cdqe : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_cbw_cwd_cdqe (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-CBW/CWD/CDQE"; + let register_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false); + let src_size : range(1, 4) = check_range(1, 4, ash(register_size, -1)); + let src : bits(32) = truncate(rgfi_size(bits_of_int(src_size, 4), 0x0, rex_byte), 32); + let dst : bits(64) = { + if logbitp(check_range(0, 32, check_range(0, 32, ash(src_size, 3)) - 1), src) then { + sail_mask(64, trunc_signed(register_size, (match src_size { + 1 => sail_sign_extend(truncate(src, 8), 32), + 2 => sail_sign_extend(truncate(src, 16), 32), + _ => src + }) : sbits(32))) + } else { + sail_zero_extend(src, 64) + } + }; + write_rgfi_size(bits_of_int(register_size, 4), 0x0, dst, rex_byte); + write_iptr(proc_mode, temp_rip) +} + +val x86_cwd_cdq_cqo : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_cwd_cdq_cqo (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-CWD/CDQ/CQO"; + let src_size : {|1, 2, 4, 8|} = select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, false, false); + let src : bits(64) = rgfi_size(bits_of_int(src_size, 4), 0x0, rex_byte); + let rdx_var : bits(64) = { + if logbitp(ash(src_size, 3) - 1, src) then { + sail_mask(64, trunc(src_size, 0xffffffffffffffff)) + } else 0x0000000000000000 + }; + write_rgfi_size(bits_of_int(src_size, 4), 0x2, rdx_var, rex_byte); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/step.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/step.sail new file mode 100644 index 000000000..1bb27ab83 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/step.sail @@ -0,0 +1,2493 @@ +$include "./top.sail" +$include "./two_byte_opcodes_dispatch.sail" +$include "./vex_opcodes_dispatch.sail" +$include "./evex_opcodes_dispatch.sail" + +/*! Fetch and store legacy and REX prefixes, if any, of an instruction +

The function @ ( ' get-prefixes ' ) fetches the legacy and REX prefixes + of an instruction and also returns the first byte following the last such + prefix. The input @ ( ' start-rip ' ) points to the first byte of an instruction, + which may potentially be a legacy prefix. The initial value of @ ( ' cnt ' ) + should be @ ( ' 15 ' ) so that the result @ ( ' ( - 15 cnt ) ' ) returned at the end of + the recursion is the correct number of legacy and/or REX bytes parsed by this + function.

+ +

Legacy Prefixes

+ +

From Intel Manual, Vol. 2, May 2018, Section 2.1.1 ( Instruction + Prefixes ) :

+ +

Instruction prefixes are divided into four groups, each with a set of + allowable prefix codes. For each instruction, it is only useful to include + up to one prefix code from each of the four groups ( Groups 1, 2, 3, + 4 ) . Groups 1 through 4 may be placed in any order relative to each + other.

+ +

Despite the quote from the Intel Manual above, the order of the legacy + prefixes does matter when there is more than one prefix from the same group + --- all but the last prefix from a single prefix group are ignored. + The only exception in this case is for Group 1 prefixes --- see + below for details.

+ +
    +
  • @ ( ' 0x64_88_00 ' ) is @ ( ' mov byte ptr fs:[rax], al ' )
  • +
  • @ ( ' 0x65_88_00 ' ) is @ ( ' mov byte ptr gs:[rax], al ' )
  • +
  • @ ( ' 0x64_65_88_00 ' ) is @ ( ' mov byte ptr gs:[rax], al ' )
  • +
  • @ ( ' 0x65_64_88_00 ' ) is @ ( ' mov byte ptr fs:[rax], al ' )
  • +
+ +
    +
  • @ ( ' 0xf2_a4 ' ) is @ ( ' repne movsb byte ptr [rdi], byte ptr [rsi] ' )
  • +
  • @ ( ' 0xf3_a4 ' ) is @ ( ' repe movsb byte ptr [rdi], byte ptr [rsi] ' )
  • +
  • @ ( ' 0xf2_f3_a4 ' ) is @ ( ' repe movsb byte ptr [rdi], byte ptr [rsi] ' )
  • +
  • @ ( ' 0xf3_f2_a4 ' ) is @ ( ' repne movsb byte ptr [rdi], byte ptr [rsi] ' )
  • +
+ +

We now discuss the Group 1 exception below.

+ +

@ ( ' 0xf0_f2_a4 ' ) is NOT
+ @ ( ' repne movsb byte ptr [rdi], byte ptr [rsi] ' )
+ It is:
+ @ ( ' lock repne movsb byte ptr [rdi], byte ptr [rsi] ' )
+ + Note that lock and rep/repne are Group 1 prefixes. It is important to record + the lock prefix, even if it is overshadowed by a rep/repne prefix, because + the former instruction will not @ ( ' #UD ' ) , but the latter instruction will. + This is akin to the lock prefix being in a separate group than the rep/repne + prefixes; in fact, AMD manuals ( Section 1.2.1: Summary of Legacy Prefixes, + Vol. 3 May 2018 Edition ) treat them as such.

+ +

For details about how mandatory prefixes are picked from legacy prefixes, + see @ ( see mandatory-prefixes-computation ) .

+ +

REX Prefixes

+ +

A REX prefix ( applicable only to 64-bit mode ) is treated as a null prefix + if it is followed by a legacy prefix. Here is an illustrative example ( using + Intel ' s XED, x86 Encoder Decoder --- see + @ ( ' https://intelxed.github.io/ ' ) ) :

+ +
    + +
  • @ ( ' xed -64 -d 48670100 ' ) is @ ( ' add dword ptr [eax], eax ' ) ; the REX.W + prefix does not have any effect on the operand size, which remains 32 ( i.e., + the default operand size in the 64-bit mode ) .
  • + +
  • @ ( ' xed -64 -d 67480100 ' ) is @ ( ' add qword ptr [eax], rax ' ) ; the REX prefix + has the intended effect of promoting the operand size to 64 bits.
  • + +
+ +

Note that the prefixes structure output of this function does not include + the REX byte ( which is a separate return value of this function ) , but its + @ ( ' :num-prefixes ' ) field includes a count of the REX prefixes encountered. + This is because adding an 8-bit field to the prefixes structure to store a + REX byte will make it a bignum, thereby impacting execution efficiency.

*/ +val get_prefixes : (proc_mode, sbits(48), prefixes, bits(8), range(0, 15)) -> (prefixes, bits(8)) + +function get_prefixes (proc_mode, start_rip, prefixes, rex_byte, cnt) = { + if cnt == 0 then { + (prefixes, rex_byte) + } else { + let byte : bits(8) = rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(start_rip, 64), None(), 1, ":X"); + if is_ext_prefix_byte(proc_mode, prefixes, rex_byte, cnt, byte) then { + let (prefixes, rex_byte, continue?) = process_ext_prefix_byte(proc_mode, prefixes, rex_byte, cnt, byte); + if not_bool(continue?) then { + (prefixes, rex_byte) + } else { + let next_rip : sbits(48) = add_to_iptr(proc_mode, start_rip, 0x000000000001); + get_prefixes(proc_mode, next_rip, prefixes, rex_byte, check_range(0, 15, cnt - 1)) + } + } else { + let prefix_byte_group_code : {|0, 1, 2, 3, 4|} = get_one_byte_prefix_array_code(byte); + match prefix_byte_group_code { + 0 => { + let rex? : bool = in_64bit_mode(proc_mode) & bits_of_int(ash(unsigned(byte), -4), 4) == 0x4; + if rex? then { + let next_rip : sbits(48) = add_to_iptr(proc_mode, start_rip, 0x000000000001); + get_prefixes(proc_mode, next_rip, prefixes, byte, check_range(0, 15, cnt - 1)) + } else { + let prefixes : prefixes = [prefixes with nxt = byte]; + ([prefixes with num = bits_of_int(15 - cnt, 4)], rex_byte) + } + }, + 1 => { + let next_rip : sbits(48) = add_to_iptr(proc_mode, start_rip, 0x000000000001); + let prefixes : prefixes = { + if byte == 0xf0 then { + [prefixes with lck = byte] + } else { + [prefixes with rep = byte] + } + }; + get_prefixes(proc_mode, next_rip, prefixes, 0x00, check_range(0, 15, cnt - 1)) + }, + 2 => { + let next_rip : sbits(48) = add_to_iptr(proc_mode, start_rip, 0x000000000001); + if in_64bit_mode(proc_mode) & (byte == 0x64 | byte == 0x65) | not_bool(in_64bit_mode(proc_mode)) then { + get_prefixes(proc_mode, next_rip, [prefixes with seg = byte], 0x00, check_range(0, 15, cnt - 1)) + } else { + get_prefixes(proc_mode, next_rip, prefixes, 0x00, check_range(0, 15, cnt - 1)) + } + }, + 3 => { + let next_rip : sbits(48) = add_to_iptr(proc_mode, start_rip, 0x000000000001); + get_prefixes(proc_mode, next_rip, [prefixes with opr = byte], 0x00, check_range(0, 15, cnt - 1)) + }, + 4 => { + let next_rip : sbits(48) = add_to_iptr(proc_mode, start_rip, 0x000000000001); + get_prefixes(proc_mode, next_rip, [prefixes with adr = byte], 0x00, check_range(0, 15, cnt - 1)) + }, + _ => (prefixes, rex_byte) + } + } + } +} + +/*! Top-level dispatch function. +

@ ( ' one-byte-opcode-execute ' ) is the doorway to all the opcode + maps ( for non-AVX/AVX512 instructions ) .

*/ +val one_byte_opcode_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function one_byte_opcode_execute (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + if ext_one_byte_opcode_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) then { + return() + } else { + (match opcode { + 0 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 1 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 2 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 3 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 4 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 5 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 6 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_segment_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"PUSH ES is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 7 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"POP ES is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 8 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 9 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 10 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 11 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 12 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 13 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 14 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_segment_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"PUSH CS is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 15 => two_byte_opcode_decode_and_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode), + 16 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 17 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 18 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 19 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 20 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 21 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 22 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_segment_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"PUSH SS is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 23 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"POP SS is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 24 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 25 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 26 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 27 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 28 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 29 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 30 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_segment_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"PUSH DS is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 31 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"POP DS is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 32 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 33 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 34 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 35 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 36 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 37 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 38 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 39 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"DAA is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 40 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 41 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 42 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 43 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 44 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 45 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 46 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 47 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"DAS is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 48 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 49 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 50 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 51 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 52 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 53 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 54 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 55 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"AAA is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 56 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 57 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 58 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 59 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_g_e(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 60 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 61 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 62 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 63 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"AAS is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 64 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 65 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 66 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 67 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 68 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 69 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 70 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 71 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 72 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 73 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 74 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 75 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 76 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 77 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 78 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 79 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_4x(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 80 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 81 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 82 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 83 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 84 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 85 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 86 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 87 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 88 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 89 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 90 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 91 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 92 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 93 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 94 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 95 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_general_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 96 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pusha(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"PUSHA is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 97 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_popa(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"POPA is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 98 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 99 => { + if in_64bit_mode(proc_mode) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_movsx(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 100 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 101 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 102 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 103 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 104 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_i(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 105 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_imul_op_en_rmi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 106 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_i(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 107 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_imul_op_en_rmi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 108 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 109 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 110 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 111 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 112 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 113 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 114 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 115 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 116 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 117 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 118 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 119 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 120 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 121 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 122 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 123 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 124 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 125 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 126 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 127 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_one_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 128 => { + if modr_m[reg] == 0b000 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b110 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 129 => { + if modr_m[reg] == 0b000 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b110 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 130 => { + if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b000 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b001 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b010 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b011 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b100 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b101 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b110 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if not_bool(in_64bit_mode(proc_mode)) & modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"Opcode 0x82 is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 131 => { + if modr_m[reg] == 0b000 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(2, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(6, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(3, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(4, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b110 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(5, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(8, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 132 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(7, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 133 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_g(7, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 134 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 135 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 136 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 137 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 138 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 139 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 140 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 141 => { + if modr_m[mod] == 0b11 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_lea(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 142 => { + if modr_m[reg] == 0b001 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 143 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pop_ev(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 144 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + if logbitp(0, rex_byte) then { + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_one_byte_nop(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } + }, + 145 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 146 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 147 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 148 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 149 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 150 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 151 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_xchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 152 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cbw_cwd_cdqe(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 153 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cwd_cdq_cqo(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 154 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"far CALL is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 155 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 156 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_pushf(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 157 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_popf(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 158 => { + if 0xf0 == prefixes[lck] | in_64bit_mode(proc_mode) & feature_flag_fn(":LAHF-SAHF") == 0 then { + x86_fault("(:UD)") + }; + x86_sahf(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 159 => { + if 0xf0 == prefixes[lck] | in_64bit_mode(proc_mode) & feature_flag_fn(":LAHF-SAHF") == 0 then { + x86_fault("(:UD)") + }; + x86_lahf(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 160 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_fd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 161 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_fd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 162 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_td(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 163 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_td(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 164 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_movs(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 165 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_movs(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 166 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmps(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 167 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmps(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 168 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(7, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 169 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_rax_i(7, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 170 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_stos(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 171 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_stos(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 172 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 173 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 174 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 175 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 176 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 177 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 178 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 179 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 180 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 181 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 182 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 183 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 184 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 185 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 186 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 187 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 188 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 189 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 190 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 191 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_oi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 192 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 193 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 194 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_ret(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 195 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_ret(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 196 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 197 => { + if in_64bit_mode(proc_mode) then { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } else if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 198 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_mi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b000 then { + if feature_flags_fn([|":RTM"|]) == 0 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 199 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mov_op_en_mi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b000 then { + if feature_flags_fn([|":RTM"|]) == 0 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 200 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 201 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_leave(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 202 => x86_model_error("Opcode Unimplemented in x86isa!"), + 203 => x86_model_error("Opcode Unimplemented in x86isa!"), + 204 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 205 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 206 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"INTO is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 207 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 208 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 209 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 210 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 211 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_sal_sar_shl_shr_rcl_rcr_rol_ror(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 212 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"AAM is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 213 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"AAD is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 215 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 216 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 217 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 218 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 219 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 220 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 221 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 222 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 223 => { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 224 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_loop(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 225 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_loop(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 226 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_loop(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 227 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_jrcxz(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 228 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 229 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 230 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 231 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 232 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_call_e8_op_en_m(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 233 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_near_jmp_op_en_d(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 234 => { + if not_bool(in_64bit_mode(proc_mode)) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) then { + if true then { + x86_fault("(:UD)") + }; + x86_fault("(X86-ILLEGAL-INSTRUCTION \"JMP is illegal in the 64-bit mode!\" START-RIP TEMP-RIP X86)") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 235 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_near_jmp_op_en_d(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 236 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 237 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 238 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 239 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 240 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 241 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 242 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 243 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)"), + 244 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_hlt(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 245 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmc_clc_stc_cld_std(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 246 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(7, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_not_neg_f6_f7(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_not_neg_f6_f7(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mul(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_imul_op_en_m(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b110 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_div(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_idiv(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 247 => { + if modr_m[reg] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_add_adc_sub_sbb_or_and_xor_cmp_test_e_i(7, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_not_neg_f6_f7(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_not_neg_f6_f7(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_mul(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_imul_op_en_m(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b110 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_div(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b111 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_idiv(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 248 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmc_clc_stc_cld_std(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 249 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmc_clc_stc_cld_std(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 250 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 251 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 252 => x86_cmc_clc_stc_cld_std(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib), + 253 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmc_clc_stc_cld_std(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 254 => { + if modr_m[reg] == 0b000 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_fe_ff(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_fe_ff(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 255 => { + if modr_m[reg] == 0b000 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_fe_ff(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b001 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_inc_dec_fe_ff(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_call_ff_2_op_en_m(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_near_jmp_op_en_m(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_far_jmp_op_en_d(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b110 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_ev(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + _ => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + }) : unit + } +} + +/*! Top-level step function +

@ ( ' x86-fetch-decode-execute ' ) is the step function of our x86 + interpreter. It fetches one instruction by looking up the memory address + indicated by the instruction pointer @ ( ' rip ' ) , decodes that instruction, and + dispatches control to the appropriate instruction semantic function.

*/ +val x86_fetch_decode_execute : unit -> unit + +function x86_fetch_decode_execute () = { + let ctx : string = "x86-fetch-decode-execute"; + if ms() | fault() then () else { + let proc_mode : proc_mode = x86_operation_mode(); + let n64_bit_modep_var : bool = in_64bit_mode(proc_mode); + let start_rip : sbits(48) = read_iptr(proc_mode); + let (prefixes, rex_byte) : (prefixes, bits(8)) = get_prefixes(proc_mode, start_rip, Mk_prefixes(0x0000000000000), 0x00, 15); + let prefixes : prefixes = Mk_prefixes(prefixes.bits); + let opcode_vex_evex_byte : bits(8) = prefixes[nxt]; + let prefix_length : bits(4) = prefixes[num]; + let temp_rip : sbits(48) = add_to_iptr(proc_mode, start_rip, bits_of_int(1 + unsigned(prefix_length), 48)); + let vex_byte0? : bool = opcode_vex_evex_byte == 0xc5 | opcode_vex_evex_byte == 0xc4; + let les_lds_distinguishing_byte : bits(8) : bits(8) = { + if vex_byte0? then { + rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X") + } else 0x00 + }; + if vex_byte0? & (n64_bit_modep_var | not_bool(n64_bit_modep_var) & les_lds_distinguishing_byte : bits(8)[7 .. 6] == 0b11) then { + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + let vex_prefixes : vex_prefixes = [Mk_vex_prefixes(0x000000) with byte0 = opcode_vex_evex_byte]; + let vex_prefixes : vex_prefixes = [vex_prefixes with byte1 = les_lds_distinguishing_byte : bits(8)]; + vex_decode_and_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, vex_prefixes) + } else { + let opcode_evex_byte : bits(8) = opcode_vex_evex_byte; + let evex_byte0? : bool = opcode_evex_byte == 0x62; + let bound_distinguishing_byte : bits(8) = { + if evex_byte0? then { + rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X") + } else 0x00 + }; + if evex_byte0? & (n64_bit_modep_var | not_bool(n64_bit_modep_var) & bound_distinguishing_byte[7 .. 6] == 0b11) then { + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + let evex_prefixes : evex_prefixes = [Mk_evex_prefixes(0x00000000) with byte0 = opcode_evex_byte]; + let evex_prefixes : evex_prefixes = [evex_prefixes with byte1 = bound_distinguishing_byte]; + evex_decode_and_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, evex_prefixes) + } else { + let opcode_byte : bits(8) = opcode_evex_byte; + let modr_m? : bool = one_byte_opcode_modr_m_p(proc_mode, opcode_byte); + let modr_m : modr_m = { + if modr_m? then { + if vex_byte0? | evex_byte0? then { + Mk_modr_m(les_lds_distinguishing_byte : bits(8)) + } else { + Mk_modr_m(rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X")) + } + } else { + Mk_modr_m(0x00) + } + }; + let temp_rip : sbits(48) = { + if modr_m? then { + add_to_iptr(proc_mode, temp_rip, 0x000000000001) + } else { + temp_rip + } + }; + let sib? : bool = modr_m? & (let p4? : bool = 0x67 == prefixes[adr] in + let n16_bit_addressp : bool = 2 == select_address_size(proc_mode, Some(prefixes)) in + x86_decode_sib_p(modr_m, n16_bit_addressp)); + let sib : sib = { + if sib? then { + Mk_sib(rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X")) + } else { + Mk_sib(0x00) + } + }; + let temp_rip : sbits(48) = { + if sib? then { + add_to_iptr(proc_mode, temp_rip, 0x000000000001) + } else { + temp_rip + } + }; + one_byte_opcode_execute(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode_byte, modr_m, sib) + } + } + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/structures.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/structures.sail new file mode 100644 index 000000000..8371c0e9b --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/structures.sail @@ -0,0 +1,248 @@ +$ifndef __X86_STRUCTURES +$define __X86_STRUCTURES + +/*! Functions to collect legacy prefix bytes from an x86 instruction +

The field @ ( ' num ' ) of @ ( ' prefixes ' ) not only includes the number of + legacy prefixes present in an instruction, but also the number of REX bytes, + even though REX bytes are not stored in this structure. See @ ( tsee + get-prefixes ) for details.

+Functions to decode and collect VEX prefix bytes from an x86 + instruction */ +bitfield vex_prefixes : bits(24) = {byte2 : 23..16, byte1 : 15..8, byte0 : 7..0} + +/*! Returns @ ( ' t ' ) if byte0 of the @ ( ' vex-prefixes ' ) structure is + either @ ( ' *vex2-byte0* ' ) or @ ( ' *vex3-byte0* ' ) ; returns @ ( ' nil ' ) otherwise */ +val vex_prefixes_byte0_p : vex_prefixes -> bool + +function vex_prefixes_byte0_p vex_prefixes = { + let byte0 : bits(8) = vex_prefixes[byte0]; + byte0 == 0xc5 | byte0 == 0xc4 +} + +bitfield vex2_byte1 : bits(8) = {r : 7..7, vvvv : 6..3, l : 2..2, pp : 1..0} + +bitfield vex3_byte1 : bits(8) = {r : 7..7, x : 6..6, b : 5..5, m_mmmm : 4..0} + +bitfield vex3_byte2 : bits(8) = {w : 7..7, vvvv : 6..3, l : 2..2, pp : 1..0} + +/*! Returns @ ( ' t ' ) if the @ ( ' vex-prefixes ' ) , irrespective of whether + they are two- or three-byte form, indicate the map that begins with the + escape bytes @ ( ' bytes ' ) */ +val vex_prefixes_map_p : (bits(16), vex_prefixes) -> bool + +function vex_prefixes_map_p (bytes, vex_prefixes) = { + let byte0 : bits(8) = vex_prefixes[byte0]; + let byte1 : bits(8) = vex_prefixes[byte1]; + (match bytes { + 15 => byte0 == 0xc5 | byte0 == 0xc4 & Mk_vex3_byte1(byte1)[m_mmmm] == 0b00001, + _ => byte0 == 0xc4 & (if bytes == 0x0f38 then { + Mk_vex3_byte1(byte1)[m_mmmm] == 0b00010 + } else { + Mk_vex3_byte1(byte1)[m_mmmm] == 0b00011 + }) + }) : bool +} + +/*! Get the @ ( ' VVVV ' ) field of @ ( ' vex-prefixes ' ) ; cognizant of the two- + or three-byte VEX prefixes form */ +val vex_get_vvvv : vex_prefixes -> sbits(5) + +function vex_get_vvvv vex_prefixes = { + (match vex_prefixes[byte0] { + 197 => sail_zero_extend(Mk_vex2_byte1(vex_prefixes[byte1])[vvvv], 5), + 196 => sail_zero_extend(Mk_vex3_byte2(vex_prefixes[byte2])[vvvv], 5), + _ => 0b11111 + }) : sbits(5) +} + +/*! Get the @ ( ' L ' ) field of @ ( ' vex-prefixes ' ) ; cognizant of the two- or + three-byte VEX prefixes form */ +val vex_get_l : vex_prefixes -> sbits(2) + +function vex_get_l vex_prefixes = { + (match vex_prefixes[byte0] { + 197 => sail_zero_extend(Mk_vex2_byte1(vex_prefixes[byte1])[l], 2), + 196 => sail_zero_extend(Mk_vex3_byte2(vex_prefixes[byte2])[l], 2), + _ => 0b11 + }) : sbits(2) +} + +/*! Get the @ ( ' PP ' ) field of @ ( ' vex-prefixes ' ) ; cognizant of the two- or + three-byte VEX prefixes form */ +val vex_get_pp : vex_prefixes -> sbits(3) + +function vex_get_pp vex_prefixes = { + (match vex_prefixes[byte0] { + 197 => sail_zero_extend(Mk_vex2_byte1(vex_prefixes[byte1])[pp], 3), + 196 => sail_zero_extend(Mk_vex3_byte2(vex_prefixes[byte2])[pp], 3), + _ => 0b111 + }) : sbits(3) +} + +/*! Get the @ ( ' W ' ) field of @ ( ' vex-prefixes ' ) ; cognizant of the two- or + three-byte VEX prefixes form */ +val vex_get_w : vex_prefixes -> bits(1) + +function vex_get_w vex_prefixes = { + (match vex_prefixes[byte0] { + 196 => Mk_vex3_byte2(vex_prefixes[byte2])[w], + _ => 0b0 + }) : bits(1) +} + +/*! Functions to decode and collect EVEX prefix bytes from an x86 + instruction */ +bitfield evex_prefixes : bits(32) = {byte3 : 31..24, byte2 : 23..16, byte1 : 15..8, byte0 : 7..0} + +bitfield evex_byte1 : bits(8) = {r : 7..7, x : 6..6, b : 5..5, r_prime : 4..4, res : 3..2, mm : 1..0} + +bitfield evex_byte2 : bits(8) = {w : 7..7, vvvv : 6..3, res : 2..2, pp : 1..0} + +bitfield evex_byte3 : bits(8) = {z : 7..7, vl_rc : 6..5, b : 4..4, v_prime : 3..3, aaa : 2..0} + +/*! Get the @ ( ' aaa ' ) field ( embedded opmask ) of @ ( ' evex-prefixes ' ) */ +val evex_get_aaa : evex_prefixes -> bits(3) + +function evex_get_aaa evex_prefixes = { + Mk_evex_byte3(evex_prefixes[byte3])[aaa] +} + +/*! Get the @ ( ' z ' ) field ( embedded opmask ) of @ ( ' evex-prefixes ' ) */ +val evex_get_z : evex_prefixes -> bits(1) + +function evex_get_z evex_prefixes = { + Mk_evex_byte3(evex_prefixes[byte3])[z] +} + +/*! Get the @ ( ' VVVV ' ) field of @ ( ' evex-prefixes ' ) */ +val evex_get_vvvv : evex_prefixes -> bits(4) + +function evex_get_vvvv evex_prefixes = { + Mk_evex_byte2(evex_prefixes[byte2])[vvvv] +} + +/*! Get the @ ( ' v-prime ' ) field of @ ( ' evex-prefixes ' ) */ +val evex_get_v_prime : evex_prefixes -> bits(1) + +function evex_get_v_prime evex_prefixes = { + Mk_evex_byte3(evex_prefixes[byte3])[v_prime] +} + +/*! Get the @ ( ' vl/rc ' ) field of @ ( ' evex-prefixes ' ) */ +val evex_get_vl_rc : evex_prefixes -> bits(2) + +function evex_get_vl_rc evex_prefixes = { + Mk_evex_byte3(evex_prefixes[byte3])[vl_rc] +} + +/*! Get the @ ( ' PP ' ) field of @ ( ' evex-prefixes ' ) */ +val evex_get_pp : evex_prefixes -> bits(2) + +function evex_get_pp evex_prefixes = { + Mk_evex_byte2(evex_prefixes[byte2])[pp] +} + +/*! Get the @ ( ' W ' ) field of @ ( ' evex-prefixes ' ) */ +val evex_get_w : evex_prefixes -> bits(1) + +function evex_get_w evex_prefixes = { + Mk_evex_byte2(evex_prefixes[byte2])[w] +} + +/*! Bitstruct definitions to store a ModR/M byte and its fields */ +bitfield modr_m : bits(8) = {mod : 7..6, reg : 5..3, r_m : 2..0} + +/*! Bitstruct definitions to store a SIB byte and its fields */ +bitfield sib : bits(8) = {scale : 7..6, index : 5..3, base : 2..0} + +bitfield rflagsbits : bits(32) = + { + res5 : 31..22, + id : 21..21, + vip : 20..20, + vif : 19..19, + ac : 18..18, + vm : 17..17, + rf : 16..16, + res4 : 15..15, + nt : 14..14, + iopl : 13..12, + of : 11..11, + df : 10..10, + intf : 9..9, + tf : 8..8, + sf : 7..7, + zf : 6..6, + res3 : 5..5, + af : 4..4, + res2 : 3..3, + pf : 2..2, + res1 : 1..1, + cf : 0..0 + } + +bitfield cr0bits : bits(32) = + { + pg : 31..31, + cd : 30..30, + nw : 29..29, + res3 : 28..19, + am : 18..18, + res2 : 17..17, + wp : 16..16, + res1 : 15..6, + ne : 5..5, + et : 4..4, + ts : 3..3, + em : 2..2, + mp : 1..1, + pe : 0..0 + } + +bitfield cr3bits : bits(64) = {res3 : 63..52, pdb : 51..12, res2 : 11..5, pcd : 4..4, pwt : 3..3, res1 : 2..0} + +bitfield cr4bits : bits(22) = + { + smap : 21..21, + smep : 20..20, + res2 : 19..19, + osxsave : 18..18, + pcide : 17..17, + fsgsbase : 16..16, + res1 : 15..15, + smxe : 14..14, + vmxe : 13..13, + la57 : 12..12, + umip : 11..11, + osxmmexcpt : 10..10, + osfxsr : 9..9, + pce : 8..8, + pge : 7..7, + mce : 6..6, + pae : 5..5, + pse : 4..4, + de : 3..3, + tsd : 2..2, + pvi : 1..1, + vme : 0..0 + } + +bitfield cr8bits : bits(4) = {cr8_trpl : 3..0} + +bitfield xcr0bits : bits(64) = + { + res2 : 63..10, + pkru_state : 9..9, + res1 : 8..8, + hi16_zmm_state : 7..7, + zmm_hi256_state : 6..6, + opmask_state : 5..5, + bndcsr_state : 4..4, + bndreg_state : 3..3, + avx_state : 2..2, + sse_state : 1..1, + fpu_mmx_state : 0..0 + } + +bitfield ia32_eferbits : bits(12) = {nxe : 11..11, lma : 10..10, res2 : 9..9, lme : 8..8, res1 : 7..1, sce : 0..0} +$endif diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/sub_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/sub_spec.sail new file mode 100644 index 000000000..6bb62355b --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/sub_spec.sail @@ -0,0 +1,132 @@ + +val gpr_sub_spec_1 : (bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_sub_spec_1 (dst, src, input_rflags) = { + let signed_raw_result : sbits(9) = bits_of_int(signed(dst) - signed(src), 9); + let result : bits(8) = truncate(signed_raw_result, 8); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(src)); + let pf : bits(1) = pf_spec8(result); + let af : bits(1) = sub_af_spec8(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : bits(1) = of_spec8(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_sub_spec_2 : (bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_sub_spec_2 (dst, src, input_rflags) = { + let signed_raw_result : sbits(17) = bits_of_int(signed(dst) - signed(src), 17); + let result : bits(16) = truncate(signed_raw_result, 16); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(src)); + let pf : bits(1) = pf_spec16(result); + let af : bits(1) = sub_af_spec16(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : bits(1) = of_spec16(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_sub_spec_4 : (bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_sub_spec_4 (dst, src, input_rflags) = { + let signed_raw_result : sbits(33) = bits_of_int(signed(dst) - signed(src), 33); + let result : bits(32) = truncate(signed_raw_result, 32); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(src)); + let pf : bits(1) = pf_spec32(result); + let af : bits(1) = sub_af_spec32(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : bits(1) = of_spec32(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_sub_spec_8 : (bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_sub_spec_8 (dst, src, input_rflags) = { + let signed_raw_result : sbits(65) = bits_of_int(signed(dst) - signed(src), 65); + let result : bits(64) = truncate(signed_raw_result, 64); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(src)); + let pf : bits(1) = pf_spec64(result); + let af : bits(1) = sub_af_spec64(dst, src); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : bits(1) = of_spec64(signed_raw_result); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_sbb_spec_1 : (bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_sbb_spec_1 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let signed_raw_result : sbits(10) = bits_of_int(signed(dst) - signed(bits_of_int(signed(src) + unsigned(input_cf), 9)), 10); + let result : bits(8) = truncate(signed_raw_result, 8); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(bits_of_int(unsigned(input_cf) + unsigned(src), 9))); + let pf : bits(1) = pf_spec8(result); + let af : bits(1) = sbb_af_spec8(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : bits(1) = of_spec8(truncate(signed_raw_result, 9)); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_sbb_spec_2 : (bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_sbb_spec_2 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let signed_raw_result : sbits(18) = bits_of_int(signed(dst) - signed(bits_of_int(signed(src) + unsigned(input_cf), 17)), 18); + let result : bits(16) = truncate(signed_raw_result, 16); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(bits_of_int(unsigned(input_cf) + unsigned(src), 17))); + let pf : bits(1) = pf_spec16(result); + let af : bits(1) = sbb_af_spec16(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : bits(1) = of_spec16(truncate(signed_raw_result, 17)); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_sbb_spec_4 : (bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_sbb_spec_4 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let signed_raw_result : sbits(34) = bits_of_int(signed(dst) - signed(bits_of_int(signed(src) + unsigned(input_cf), 33)), 34); + let result : bits(32) = truncate(signed_raw_result, 32); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(bits_of_int(unsigned(input_cf) + unsigned(src), 33))); + let pf : bits(1) = pf_spec32(result); + let af : bits(1) = sbb_af_spec32(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : bits(1) = of_spec32(truncate(signed_raw_result, 33)); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} + +val gpr_sbb_spec_8 : (bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_sbb_spec_8 (dst, src, input_rflags) = { + let input_cf : bits(1) = input_rflags[cf]; + let signed_raw_result : sbits(66) = bits_of_int(signed(dst) - signed(bits_of_int(signed(src) + unsigned(input_cf), 65)), 66); + let result : bits(64) = truncate(signed_raw_result, 64); + let cf : bits(1) = bool_to_bits(unsigned(dst) < unsigned(bits_of_int(unsigned(input_cf) + unsigned(src), 65))); + let pf : bits(1) = pf_spec64(result); + let af : bits(1) = sbb_af_spec64(dst, src, input_cf); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : bits(1) = of_spec64(truncate(signed_raw_result, 65)); + let output_rflags : rflagsbits = [input_rflags with cf, pf, af, zf, sf, of]; + let undefined_flags : rflagsbits = Mk_rflagsbits(0x00000000); + (result, output_rflags, undefined_flags) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/subroutine.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/subroutine.sail new file mode 100644 index 000000000..362838bc3 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/subroutine.sail @@ -0,0 +1,123 @@ + +val x86_call_e8_op_en_m : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_call_e8_op_en_m (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-CALL-E8-OP/EN-M"; + let offset_size : {|1, 2, 4|} = check_range(0, 4, select_operand_size(proc_mode, false, rex_byte, false, prefixes, false, true, true)); + let rel16_32 : sbits(32) = truncate(rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), offset_size, sail_sign_extend(temp_rip, 64), None(), 1, ":X", false, false), 32); + let next_rip : sbits(49) = sail_sign_extend(add_to_iptr(proc_mode, temp_rip, bits_of_int(offset_size, 48)), 49); + let badlength? : option(int) = check_instruction_length(start_rip, truncate(next_rip, 48), 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let call_rip : sbits(48) = add_to_iptr(proc_mode, truncate(next_rip, 48), sail_sign_extend(rel16_32, 48)); + let rsp_var : sbits(64) = read_sptr(proc_mode); + let addr_size : address_size = select_address_size(proc_mode, None()); + let new_rsp : sbits(64) = add_to_sptr(proc_mode, rsp_var, bits_of_int(negate(addr_size), 64)); + if in_64bit_mode(proc_mode) then { + wime_size(Mode_64bit, select_address_size(proc_mode, Some(prefixes)), addr_size, sail_sign_extend(truncate(new_rsp, 48), 64), None(), 2, sail_sign_extend(next_rip, 128), alignment_checking_enabled_p(), false) + } else { + wme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), addr_size, sail_sign_extend(truncate(new_rsp, 48), 64), None(), 2, if addr_size == 2 then { + sail_zero_extend(sail_zero_extend(truncate(next_rip, 16), 32), 128) + } else { + sail_zero_extend(truncate(next_rip, 32), 128) + }, alignment_checking_enabled_p(), false) + }; + write_iptr(proc_mode, call_rip); + write_sptr(proc_mode, new_rsp) +} + +val x86_call_ff_2_op_en_m : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_call_ff_2_op_en_m (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-CALL-FF/2-OP/EN-M"; + let r_m : bits(3) = modr_m[r_m]; + let mod_var : bits(2) = modr_m[mod]; + let reg : bits(3) = modr_m[reg]; + let operand_size : {|2, 4, 8|} = check_range(2, 8, select_operand_size(proc_mode, false, rex_byte, false, prefixes, true, true, true)); + let p2 : bits(8) = prefixes[seg]; + let p4? : bool = 0x67 == prefixes[adr]; + let seg_reg : seg_reg_idx = select_segment_register(proc_mode, prefixes, mod_var, r_m, sib); + let inst_ac? : bool = true; + let (call_rip, increment_rip_by, addr) : (bits(128), {|0, 1, 2, 4|}, sbits(64)) = x86_operand_from_modr_m_and_sib_bytes(proc_mode, 0b0, operand_size, inst_ac?, false, seg_reg, prefixes, temp_rip, rex_byte, r_m, mod_var, sib, 0b000); + let call_rip : sbits(64) = truncate(call_rip, 64); + let increment_rip_by : bits(3) = bits_of_int(increment_rip_by, 3); + let next_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, sail_zero_extend(increment_rip_by, 48)); + let badlength? : option(int) = check_instruction_length(start_rip, next_rip, 0b000); + if is_some(badlength?) then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let call_rip : sbits(64) = { + if in_64bit_mode(proc_mode) then { + call_rip + } else { + call_rip + } + }; + if not_bool(if in_64bit_mode(proc_mode) then { + canonical_address_p(signed(call_rip)) + } else { + 0 <= signed(call_rip) & signed(call_rip) <= unsigned(seg_hidden_limits[1]) + }) then x86_fault("(!!FAULT-FRESH :GP 0 :BAD-RETURN-ADDRESS CALL-RIP)"); + let rsp_var : sbits(64) = read_sptr(proc_mode); + let addr_size : address_size = select_address_size(proc_mode, None()); + let new_rsp : sbits(64) = add_to_sptr(proc_mode, rsp_var, bits_of_int(negate(addr_size), 64)); + let check_alignment? : bool = alignment_checking_enabled_p(); + if in_64bit_mode(proc_mode) then { + wime_size(Mode_64bit, select_address_size(proc_mode, Some(prefixes)), addr_size, sail_sign_extend(truncate(new_rsp, 48), 64), None(), 2, sail_sign_extend(next_rip, 128), alignment_checking_enabled_p(), false) + } else { + wme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), addr_size, sail_sign_extend(truncate(new_rsp, 48), 64), None(), 2, if addr_size == 2 then { + sail_zero_extend(sail_zero_extend(truncate(next_rip, 16), 32), 128) + } else { + sail_zero_extend(truncate(next_rip, 32), 128) + }, alignment_checking_enabled_p(), false) + }; + write_iptr(proc_mode, truncate(call_rip, 48)); + write_sptr(proc_mode, new_rsp) +} + +val x86_ret : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_ret (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-RET"; + let rsp_var : sbits(64) = read_sptr(proc_mode); + let operand_size : {|2, 4, 8|} = check_range(2, 8, select_operand_size(proc_mode, false, rex_byte, false, Mk_prefixes(0x0000000000000), true, true, true)); + let new_rsp : sbits(48) = { + if opcode == 0xc3 then { + let new_rsp : sbits(64) = add_to_sptr(proc_mode, rsp_var, bits_of_int(operand_size, 64)); + truncate(new_rsp, 48) + } else { + let imm16 : bits(16) = rme16(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X", false); + let new_rsp : sbits(64) = add_to_sptr(proc_mode, rsp_var, bits_of_int(operand_size + unsigned(imm16), 64)); + truncate(new_rsp, 48) + } + }; + let badlength? : bool = opcode == 0xc2 & is_some(check_instruction_length(start_rip, temp_rip, 0b010)); + if badlength? then x86_fault("(!!FAULT-FRESH :GP 0 :INSTRUCTION-LENGTH BADLENGTH?)"); + let check_alignment? : bool = alignment_checking_enabled_p(); + let tos : sbits(64) = { + if operand_size == 8 then { + rime_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), operand_size, rsp_var, None(), 2, ":R", check_alignment?, false) + } else { + truncate(rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), operand_size, rsp_var, None(), 2, ":R", check_alignment?, false), 64) + } + }; + if not_bool(if in_64bit_mode(proc_mode) then { + canonical_address_p(signed(tos)) + } else { + let cs_limit : bits(32) = seg_hidden_limits[1]; + 0 <= signed(tos) & signed(tos) <= unsigned(cs_limit) + }) then x86_fault("(!!FAULT-FRESH :GP 0 :BAD-RETURN-ADDRESS TOS)"); + write_sptr(proc_mode, sail_sign_extend(new_rsp, 64)); + write_rip(truncate(tos, 48)) +} + +val x86_leave : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_leave (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-LEAVE"; + let operand_size : {|2, 4, 8|} = check_range(2, 8, select_operand_size(proc_mode, false, rex_byte, false, prefixes, true, true, false)); + let rbp_ebp_bp : bits(64) = rgfi_size(bits_of_int(operand_size, 4), 0x5, 0x00); + let inst_ac? : bool = alignment_checking_enabled_p(); + let sailval : bits(128) = rme_size(proc_mode, select_address_size(proc_mode, Some(prefixes)), operand_size, rbp_ebp_bp, None(), 2, ":R", inst_ac?, false); + let new_rsp : sbits(64) = add_to_sptr(proc_mode, rbp_ebp_bp, bits_of_int(operand_size, 64)); + write_rgfi_size(bits_of_int(operand_size, 4), 0x5, truncate(sailval, 64), rex_byte); + write_sptr(proc_mode, new_rsp); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/three_byte_opcodes_dispatch.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/three_byte_opcodes_dispatch.sail new file mode 100644 index 000000000..50688ce8c --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/three_byte_opcodes_dispatch.sail @@ -0,0 +1 @@ +$include "./prefix_modrm_sib_decoding.sail" diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top.sail new file mode 100644 index 000000000..eaf48c0e3 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top.sail @@ -0,0 +1,99 @@ +$include "./arith_and_logic.sail" +$include "./bit.sail" +$include "./conditional.sail" +$include "./divide.sail" +$include "./exchange.sail" +$include "./jump_and_loop.sail" +$include "./move.sail" +$include "./multiply.sail" +$include "./push_and_pop.sail" +$include "./rotate_and_shift.sail" +$include "./segmentationinst.sail" +$include "./signextend.sail" +$include "./string.sail" +$include "./syscall.sail" +$include "./subroutine.sail" +$include "./topfp.sail" + +val x86_hlt : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_hlt (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-HLT"; + write_iptr(proc_mode, temp_rip); + x86_model_error(":LEGAL-HALT") +} + +val x86_cmc_clc_stc_cld_std : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_cmc_clc_stc_cld_std (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-CMC/CLC/STC/CLD/STD"; + (match opcode { + 245 => { + let cf : bits(1) = { + let rflags_var : rflagsbits = rflags; + rflags_var[cf] + }; + let not_cf : {|0, 1|} = { + if cf == 0b1 then 0 else 1 + }; + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with cf = bits_of_int(not_cf, 1)]; + rflags = new_rflags + }, + 248 => { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with cf = 0b0]; + rflags = new_rflags + }, + 249 => { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with cf = 0b1]; + rflags = new_rflags + }, + 252 => { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with df = 0b0]; + rflags = new_rflags + }, + _ => { + let rflags_var : rflagsbits = rflags; + let new_rflags : rflagsbits = [rflags_var with df = 0b1]; + rflags = new_rflags + } + }) : unit; + write_iptr(proc_mode, temp_rip) +} + +val x86_sahf : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_sahf (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-SAHF"; + let ax : bits(16) = rr16(0x0); + let ah : bits(8) = bits_of_int(ash(unsigned(ax), -8), 8); + let rflags_var : rflagsbits = rflags; + let cf : bits(1) = Mk_rflagsbits(sail_zero_extend(ah, 32))[cf]; + let pf : bits(1) = Mk_rflagsbits(sail_zero_extend(ah, 32))[pf]; + let af : bits(1) = Mk_rflagsbits(sail_zero_extend(ah, 32))[af]; + let zf : bits(1) = Mk_rflagsbits(sail_zero_extend(ah, 32))[zf]; + let sf : bits(1) = Mk_rflagsbits(sail_zero_extend(ah, 32))[sf]; + let new_rflags : rflagsbits = [rflags_var with sf, zf, af, pf, cf]; + rflags = new_rflags; + write_iptr(proc_mode, temp_rip) +} + +val x86_lahf : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), modr_m, sib) -> unit + +function x86_lahf (proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) = { + let ctx : string = "X86-LAHF"; + let rflags_var : rflagsbits = rflags; + let cf : bits(1) = rflags_var[cf]; + let pf : bits(1) = rflags_var[pf]; + let af : bits(1) = rflags_var[af]; + let zf : bits(1) = rflags_var[zf]; + let sf : bits(1) = rflags_var[sf]; + let new_ah : rflagsbits = [Mk_rflagsbits(0x00000000) with sf, zf, res3 = 0b0, af, res2 = 0b0, pf, res1 = 0b1, cf]; + let ax : bits(16) = rr16(0x0); + let new_ax : bits(16) = bits_of_int(logior(unsigned(logand(0x00ff, ax)), ash(unsigned(new_ah.bits), 8)), 16); + wr16(0x0, new_ax); + write_iptr(proc_mode, temp_rip) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top_level_memory.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top_level_memory.sail new file mode 100644 index 000000000..881cf5030 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/top_level_memory.sail @@ -0,0 +1,491 @@ + +/*! Check the alignment of a linear address. +

+ Besides the address to check for alignment, + this function takes as argument the operand size + ( from which the alignment to check is determined ) + and a flag indicating whether the address to check for alignment + contains a memory operand of the form m16:16, m16:32, or m16:64 + ( see Intel manual, Mar ' 17, Volume 2, Section 3.1.1.3 ) . +

+

+ Words, doublewords, quadwords, and double quadwords + must be aligned at boundaries of 2, 4, 8, or 16 bytes. + Memory pointers of the form m16:xx must be aligned so that + their xx portion is aligned as a word, doubleword, or quadword; + this automatically guarantees that their m16 portion is aligned as a word. + See Intel manual, Mar ' 17, Volume 1, Section 4.1.1. + See AMD manual, Dec ' 17, Volume 2, Table 8-7 + ( note that the table does not mention explicitly + memory pointers of the form m16:64 ) . +

+

+ If the operand size is 6, the operand must be an m16:32 pointer. + If the operand size is 10, the operand must an m16:64 pointer. + If the operand size is 4, it may be either an m16:16 pointer or not; + in this case, the @ ( ' memory-ptr? ' ) argument is used to + determine whether the address should be aligned + at a word or doubleword boundary. + If the operand size is 1, 2, 8, or 16, + it cannot be a memory pointer of the form m16:xx. +

*/ +function address_aligned_p (addr, operand_size, memory_ptr?) = { + (match operand_size { + 1 => true, + 6 => logand(addr, 0x000000000003) == 0x000000000000, + 10 => logand(addr, 0x000000000007) == 0x000000000000, + _ => { + if memory_ptr? & operand_size == 4 then { + logand(addr, 0x000000000001) == 0x000000000000 + } else { + logand(addr, bits_of_int(check_range(0, 65, operand_size - 1), 48)) == 0x000000000000 + } + } + }) : bool +} + +/*! Read an unsigned 8-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RML08 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +val rme08 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, string) -> bits(8) + +function rme08 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, r_x) = { + load_bytes_from_ea(proc_mode, addr_size, 1, eff_addr, base_reg, seg_reg, r_x, false, false) +} + +/*! Read a signed 8-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RIML08 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +overload rime08 = {rme08} + +/*! Read an unsigned 16-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RML16 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +val rme16 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool) -> bits(16) + +function rme16 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, r_x, check_alignment?) = { + load_bytes_from_ea(proc_mode, addr_size, 2, eff_addr, base_reg, seg_reg, r_x, check_alignment?, false) +} + +/*! Read a signed 16-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RIML16 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +overload rime16 = {rme16} + +/*! Read an unsigned 32-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RML32 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +val rme32 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool, bool) -> bits(32) + +function rme32 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?) = { + load_bytes_from_ea(proc_mode, addr_size, 4, eff_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?) +} + +/*! Read a signed 32-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RIML32 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +overload rime32 = {rme32} + +/*! Read an unsigned 48-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RML48 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +val rme48 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool) -> bits(48) + +function rme48 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, r_x, check_alignment?) = { + load_bytes_from_ea(proc_mode, addr_size, 6, eff_addr, base_reg, seg_reg, r_x, check_alignment?, false) +} + +/*! Read an unsigned 64-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RML64 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +val rme64 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool) -> bits(64) + +function rme64 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, r_x, check_alignment?) = { + load_bytes_from_ea(proc_mode, addr_size, 8, eff_addr, base_reg, seg_reg, r_x, check_alignment?, false) +} + +/*! Read a signed 64-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RIML64 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +overload rime64 = {rme64} + +/*! Read an unsigned 80-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RML80 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +val rme80 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool) -> bits(80) + +function rme80 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, r_x, check_alignment?) = { + load_bytes_from_ea(proc_mode, addr_size, 10, eff_addr, base_reg, seg_reg, r_x, check_alignment?, false) +} + +/*! Read an unsigned 128-bit value from memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address using @ ( see ea-to-la ) . If this translation is + successful and no other errors ( like alignment errors ) occur, then + @ ( see RML128 ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) .

*/ +val rme128 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool) -> bits(128) + +function rme128 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, r_x, check_alignment?) = { + load_bytes_from_ea(proc_mode, addr_size, 16, eff_addr, base_reg, seg_reg, r_x, check_alignment?, false) +} + +/*! Read an unsigned value with the specified number of bytes + from memory via an effective address. +

The effective address is translated to a canonical linear address using + @ ( see ea-to-la ) . If this translation is successful and no other errors ( like + alignment errors ) occur, then @ ( see rml-size ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored; see Intel manual, Dec ' 17, Volume 2, Section 4.8.1

*/ +val rme_size : (proc_mode, address_size, {|1, 2, 4, 6, 8, 10, 16|}, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool, bool) -> bits(128) + +function rme_size (proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?) = { + sail_zero_extend(load_bytes_from_ea(proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?), 128) +} + +/*! Read a signed value with the specified number of bytes + from memory via an effective address. +

The effective address is translated to a canonical linear address using + @ ( see ea-to-la ) . If this translation is successful and no other errors ( like + alignment errors ) occur, then @ ( see riml-size ) is called.

+

Prior to the effective address translation, we check whether read + access is allowed. The only case in which it is not allowed is when a + read access is attempted on an execute-only code segment, in 32-bit + mode. In 64-bit mode, the R bit of the code segment descriptor is + ignored; see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1

*/ +val rime_size : (proc_mode, address_size, {|1, 2, 4, 6, 8|}, sbits(64), option(base_reg_idx), seg_reg_idx, string, bool, bool) -> sbits(64) + +function rime_size (proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?) = { + sail_sign_extend(load_bytes_from_ea(proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, r_x, check_alignment?, mem_ptr?), 64) +} + +/*! Write an unsigned 8-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WML08 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme08 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, bits(8)) -> unit + +function wme08 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, data) = { + store_bytes_to_ea(proc_mode, addr_size, 1, eff_addr, base_reg, seg_reg, data, false, false) +} + +/*! Write a signed 8-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WIML08 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +overload wime08 = {wme08} + +/*! Write an unsigned 16-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WML16 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme16 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, bits(16), bool) -> unit + +function wme16 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, data, check_alignment?) = { + store_bytes_to_ea(proc_mode, addr_size, 2, eff_addr, base_reg, seg_reg, data, check_alignment?, false) +} + +/*! Write a signed 16-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WIML16 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +overload wime16 = {wme16} + +/*! Write an unsigned 32-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WML32 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme32 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, bits(32), bool, bool) -> unit + +function wme32 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, data, check_alignment?, mem_ptr?) = { + store_bytes_to_ea(proc_mode, addr_size, 4, eff_addr, base_reg, seg_reg, data, check_alignment?, mem_ptr?) +} + +/*! Write a signed 32-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WIML32 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +overload wime32 = {wme32} + +/*! Write an unsigned 48-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WML48 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme48 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, bits(48), bool) -> unit + +function wme48 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, data, check_alignment?) = { + store_bytes_to_ea(proc_mode, addr_size, 6, eff_addr, base_reg, seg_reg, data, check_alignment?, false) +} + +/*! Write an unsigned 64-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WML64 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme64 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, bits(64), bool) -> unit + +function wme64 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, data, check_alignment?) = { + store_bytes_to_ea(proc_mode, addr_size, 8, eff_addr, base_reg, seg_reg, data, check_alignment?, false) +} + +/*! Write a signed 64-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WIML64 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +overload wime64 = {wme64} + +/*! Write an unsigned 80-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WML80 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme80 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, bits(80), bool) -> unit + +function wme80 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, data, check_alignment?) = { + store_bytes_to_ea(proc_mode, addr_size, 10, eff_addr, base_reg, seg_reg, data, check_alignment?, false) +} + +/*! Write an unsigned 128-bit value to memory via an effective address. +

The effective address @ ( ' eff-addr ' ) is translated to a canonical + linear address. If this translation is successful and no other error + occurs ( like alignment errors ) , then @ ( see WML128 ) is + called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme128 : (proc_mode, address_size, sbits(64), option(base_reg_idx), seg_reg_idx, bits(128), bool) -> unit + +function wme128 (proc_mode, addr_size, eff_addr, base_reg, seg_reg, data, check_alignment?) = { + store_bytes_to_ea(proc_mode, addr_size, 16, eff_addr, base_reg, seg_reg, data, check_alignment?, false) +} + +/*! Write an unsigned value with the specified number of bytes + to memory via an effective address. +

The effective address is translated to a canonical linear address. If + this translation is successful and no other errors occur ( like alignment + errors ) , then @ ( see wml-size ) is called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +val wme_size : forall 'nbytes, 'nbytes in {1, 2, 4, 6, 8, 10, 16}. + (proc_mode, address_size, int('nbytes), sbits(64), option(base_reg_idx), seg_reg_idx, bits(128), bool, bool) -> unit + +function wme_size (proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, data, check_alignment?, mem_ptr?) = { + store_bytes_to_ea(proc_mode, addr_size, nbytes, eff_addr, base_reg, seg_reg, truncate(data, 8 * nbytes), check_alignment?, mem_ptr?) +} + +/*! Write a signed value with the specified number of bytes + to memory via an effective address. +

The effective address is translated to a canonical linear address. If + this translation is successful and no other errors occur ( like alignment + errors ) , then @ ( see wiml-size ) is called.

+

Prior to the effective address translation, we check whether write + access is allowed. In 32-bit mode, write access is allowed in data + segments ( DS, ES, FS, GS, and SS ) if the W bit in the segment + descriptor is 1; write access is disallowed in code segments ( this is + not explicitly mentioned in Intel manual, May ' 18, Volume 3, Section + 3.4.5.1, but it seems reasonable ) . In 64-bit mode, the W bit is + ignored ( see Atmel manual, Dec ' 17, Volume 2, Section 4.8.1 ) ; by + analogy, we allow write access to the code segment as well. + These checks may be slightly optimized using the invariant that + SS.W must be 1 when SS is loaded.

*/ +overload wime_size = {wme_size} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/two_byte_opcodes_dispatch.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/two_byte_opcodes_dispatch.sail new file mode 100644 index 000000000..507245df7 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/two_byte_opcodes_dispatch.sail @@ -0,0 +1,2805 @@ +$include "./three_byte_opcodes_dispatch.sail" + +/*! Two-byte opcode dispatch function. +

@ ( ' two-byte-opcode-execute ' ) is the doorway to the two-byte + opcode map, and will lead to the three-byte opcode map if @ ( ' opcode ' ) is + either @ ( ' #x38 ' ) or @ ( ' #x3A ' ) .

*/ +val two_byte_opcode_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8), bits(8), modr_m, sib) -> unit + +function two_byte_opcode_execute (proc_mode, start_rip, temp_rip, prefixes, mandatory_prefix, rex_byte, opcode, modr_m, sib) = { + if ext_two_byte_opcode_execute(proc_mode, start_rip, temp_rip, prefixes, mandatory_prefix, rex_byte, opcode, modr_m, sib) then { + return() + } else { + (match opcode { + 0 => { + if modr_m[reg] == 0b000 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b000 & modr_m[mod] == 0b11 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & modr_m[mod] == 0b11 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b010 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_lldt(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b101 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 1 => { + if modr_m[reg] == 0b000 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b000 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b001 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b000 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b010 then { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b000 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b011 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b000 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b100 then { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b000 then { + if feature_flags_fn([|":MONITOR"|]) == 0 | not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b001 then { + if feature_flags_fn([|":MONITOR"|]) == 0 | not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b010 then { + if feature_flags_fn([|":SMAP"|]) == 0 | 0xf0 == prefixes[lck] | not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b011 then { + if feature_flags_fn([|":SMAP"|]) == 0 | 0xf0 == prefixes[lck] | not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b111 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b010 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_lgdt(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_lidt(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b011 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b000 then { + if feature_flags_fn([|":XSAVE"|]) == 0 | 0xf0 == prefixes[lck] | Mk_cr4bits(loghead(22, ctrs[4]))[osxsave] == 0b0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b011 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b001 then { + if feature_flags_fn([|":XSAVE"|]) == 0 | 0xf0 == prefixes[lck] | Mk_cr4bits(loghead(22, ctrs[4]))[osxsave] == 0b0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b011 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b100 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b011 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b101 then { + if feature_flags_fn([|":RTM"|]) == 0 | 0xf0 == prefixes[lck] | 0x66 == prefixes[opr] | 0xf3 == prefixes[rep] | 0xf2 == prefixes[rep] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b011 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b110 then { + if feature_flags_fn([|":HLE", ":RTM"|]) == 0 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b011 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b111 then { + if Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 then { + x86_fault("(:NM)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 & modr_m[mod] == 0b11 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[umip] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b111 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if in_64bit_mode(proc_mode) & modr_m[reg] == 0b111 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b000 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b111 & modr_m[mod] == 0b11 & modr_m[r_m] == 0b001 then { + if feature_flags_fn([|":RDTSCP"|]) == 0 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 2 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 3 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 5 => { + if in_64bit_mode(proc_mode) then { + if 0xf0 == prefixes[lck] | Mk_ia32_eferbits(truncate(read_msr(0), 12))[sce] == 0b0 then { + x86_fault("(:UD)") + }; + x86_syscall_both_views(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 6 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 7 => { + if in_64bit_mode(proc_mode) then { + if 0xf0 == prefixes[lck] | Mk_ia32_eferbits(truncate(read_msr(0), 12))[sce] == 0b0 then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_sysret(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 8 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 9 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 11 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"UD2 encountered!\" START-RIP TEMP-RIP X86)"), + 13 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 16 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movups_movupd_movdqu_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movups_movupd_movdqu_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movss_movsd_op_en_rm(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movss_movsd_op_en_rm(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 17 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movups_movupd_movdqu_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movups_movupd_movdqu_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movss_movsd_op_en_mr(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movss_movsd_op_en_mr(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 18 => { + if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_movlps_movlpd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_movlps_movlpd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movlps_movlpd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movlps_movlpd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 19 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_movlps_movlpd_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_movlps_movlpd_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 20 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_unpck?ps_op_en_rm(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_unpck?pd_op_en_rm(0, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 21 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_unpck?ps_op_en_rm(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_unpck?pd_op_en_rm(1, proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 22 => { + if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_movhps_movhpd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_movhps_movhpd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 23 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_movhps_movhpd_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_movhps_movhpd_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 24 => { + if modr_m[reg] == 0b000 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b001 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b010 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b011 & not_bool(modr_m[mod] == 0b11) then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b101 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b111 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[mod] == 0b11 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 25 => x86_model_error("Opcode Unimplemented in x86isa!"), + 26 => { + if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x00 then { + if feature_flags_fn([|":MPX"|]) == 0 | 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[reg], rex_byte, 0b10)) | (if in_64bit_mode(proc_mode) then { + modr_m[mod] == 0b00 & (modr_m[r_m] == 0b101 | modr_m[r_m] == 0b100 & sib[base] == 0b101 & sib[index] == 0b100) + } else if prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + if feature_flags_fn([|":MPX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x66 then { + if feature_flags_fn([|":MPX"|]) == 0 | modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[r_m], rex_byte, 0b00)) | (if not_bool(in_64bit_mode(proc_mode)) & prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + if feature_flags_fn([|":MPX"|]) == 0 | modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[r_m], rex_byte, 0b00)) | (if not_bool(in_64bit_mode(proc_mode)) & prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + if feature_flags_fn([|":MPX"|]) == 0 | 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[reg], rex_byte, 0b10)) | not_bool(in_64bit_mode(proc_mode)) & (if prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + if feature_flags_fn([|":MPX"|]) == 0 | 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[reg], rex_byte, 0b10)) | not_bool(in_64bit_mode(proc_mode)) & (if prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 27 => { + if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x00 then { + if feature_flags_fn([|":MPX"|]) == 0 | 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[reg], rex_byte, 0b10)) | (if in_64bit_mode(proc_mode) then { + modr_m[mod] == 0b00 & (modr_m[r_m] == 0b101 | modr_m[r_m] == 0b100 & sib[base] == 0b101 & sib[index] == 0b100) + } else if prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + if feature_flags_fn([|":MPX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x66 then { + if feature_flags_fn([|":MPX"|]) == 0 | modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[r_m], rex_byte, 0b00)) | (if not_bool(in_64bit_mode(proc_mode)) & prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + if feature_flags_fn([|":MPX"|]) == 0 | modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[r_m], rex_byte, 0b00)) | (if not_bool(in_64bit_mode(proc_mode)) & prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0xf3 then { + if feature_flags_fn([|":MPX"|]) == 0 | 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[reg], rex_byte, 0b10)) | (if in_64bit_mode(proc_mode) then { + modr_m[mod] == 0b00 & (modr_m[r_m] == 0b101 | modr_m[r_m] == 0b100 & sib[base] == 0b101 & sib[index] == 0b100) + } else if prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0xf3 then { + if feature_flags_fn([|":MPX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + if feature_flags_fn([|":MPX"|]) == 0 | 0xf0 == prefixes[lck] | 4 <= unsigned(reg_index(modr_m[reg], rex_byte, 0b10)) | not_bool(in_64bit_mode(proc_mode)) & (if prefixes[adr] == 0x67 then { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b1 + } else { + (let cs_attr : bits(16) = seg_hidden_attrs[1] in + Mk_code_segment_descriptor_attributesbits(cs_attr)[d]) == 0b0 + }) then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 28 => x86_model_error("Opcode Unimplemented in x86isa!"), + 29 => x86_model_error("Opcode Unimplemented in x86isa!"), + 30 => x86_model_error("Opcode Unimplemented in x86isa!"), + 31 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_nop(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 32 => { + if 0xf0 == prefixes[lck] | (let reg : bits(3) = modr_m[reg] in + if in_64bit_mode(proc_mode) & logbitp(2, rex_byte) then { + not_bool(reg == 0b000) + } else { + reg == 0b001 | reg == 0b101 | reg == 0b110 | reg == 0b111 + }) then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_mov_control_regs_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 33 => { + if 0xf0 == prefixes[lck] | Mk_cr4bits(loghead(22, ctrs[4]))[de] == 0b1 & (modr_m[reg] == 0b100 | modr_m[reg] == 0b101) then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 34 => { + if 0xf0 == prefixes[lck] | (let reg : bits(3) = modr_m[reg] in + if in_64bit_mode(proc_mode) & logbitp(2, rex_byte) then { + not_bool(reg == 0b000) + } else { + reg == 0b001 | reg == 0b101 | reg == 0b110 | reg == 0b111 + }) then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 35 => { + if 0xf0 == prefixes[lck] | Mk_cr4bits(loghead(22, ctrs[4]))[de] == 0b1 & (modr_m[reg] == 0b100 | modr_m[reg] == 0b101) then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 40 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movaps_movapd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movaps_movapd_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 41 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movaps_movapd_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movaps_movapd_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 43 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 48 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 49 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 50 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 51 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) & Mk_cr4bits(loghead(22, ctrs[4]))[pce] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 52 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if Mk_cr0bits(loghead(32, ctrs[0]))[pe] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 53 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + } else { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) | Mk_cr0bits(loghead(32, ctrs[0]))[pe] == 0b0 then { + x86_fault("(:GP)") + }; + () + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 55 => x86_model_error("Opcode Unimplemented in x86isa!"), + 64 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 65 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 66 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 67 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 68 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 69 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 70 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 71 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 72 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 73 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 74 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 75 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 76 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 77 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 78 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 79 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmovcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 80 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 82 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 83 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 91 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 96 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 97 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 98 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 99 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 100 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 101 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 102 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 103 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 104 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 105 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 106 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 107 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 108 => { + if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 109 => { + if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 110 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-8", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movd_movq_to_xmm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 111 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-8", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movups_movupd_movdqu_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 112 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 113 => { + if modr_m[reg] == 0b010 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b010 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 114 => { + if modr_m[reg] == 0b010 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b010 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b100 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 115 => { + if modr_m[reg] == 0b010 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b010 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b011 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 & modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b111 & modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-7", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 117 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 118 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 119 => { + if mandatory_prefix == 0x00 then { + if 0xf0 == prefixes[lck] | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 120 => { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 121 => { + if not_bool(unsigned(Mk_segment_selectorbits(seg_visibles[1])[rpl]) == 0) then { + x86_fault("(:GP)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 124 => { + if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 125 => { + if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 126 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-8", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movd_movq_from_xmm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 127 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-8", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_movups_movupd_movdqu_op_en_mr(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 128 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 129 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 130 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 131 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 132 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 133 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 134 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 135 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 136 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 137 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 138 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 139 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 140 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 141 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 142 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 143 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_two_byte_jcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 144 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 145 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 146 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 147 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 148 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 149 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 150 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 151 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 152 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 153 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 154 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 155 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 156 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 157 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 158 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 159 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_setcc(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 160 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_segment_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 161 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 162 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 163 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_bt_0f_a3(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 164 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_shld_shrd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 165 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_shld_shrd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 168 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_push_segment_register(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 169 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 170 => x86_model_error("Opcode Unimplemented in x86isa!"), + 171 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 172 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_shld_shrd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 173 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_shld_shrd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 175 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_imul_op_en_rm(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 176 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmpxchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 177 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_cmpxchg(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 178 => { + if 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 179 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 180 => { + if 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 181 => { + if 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 182 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_movzx(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 183 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_movzx(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 184 => { + if mandatory_prefix == 0x00 then { + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + if feature_flags_fn([|":POPCNT"|]) == 0 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 185 => x86_fault("(X86-ILLEGAL-INSTRUCTION \"UD1 encountered!\" START-RIP TEMP-RIP X86)"), + 186 => { + if modr_m[reg] == 0b100 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_bt_0f_ba(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if modr_m[reg] == 0b101 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b110 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[reg] == 0b111 then { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 187 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 189 => { + if mandatory_prefix == 0x00 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 190 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_movsxd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 191 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_movsxd(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + }, + 192 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 193 => { + if modr_m[mod] == 0b11 & 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 195 => { + if feature_flags_fn([|":SSE2"|]) == 0 | 0xf0 == prefixes[lck] | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 196 => { + if modr_m[mod] == 0b11 & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if modr_m[mod] == 0b11 & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else if not_bool(modr_m[mod] == 0b11) & mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 197 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 198 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_shufps_op_en_rmi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_shufpd_op_en_rmi(proc_mode, start_rip, temp_rip, prefixes, rex_byte, opcode, modr_m, sib) + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 200 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 201 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 202 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 203 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 204 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 205 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 206 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 207 => { + if 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + }, + 208 => { + if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 209 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 210 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 211 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 212 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 213 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 214 => { + if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + if feature_flags_fn([|":SSE2"|]) == 0 | Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 | Mk_cr4bits(loghead(22, ctrs[4]))[osfxsr] == 0b0 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + if feature_flags_fn([|":SSE2"|]) == 0 | Mk_cr0bits(loghead(32, ctrs[0]))[ts] == 0b1 | Mk_cr0bits(loghead(32, ctrs[0]))[em] == 0b1 | Mk_cr4bits(loghead(22, ctrs[4]))[osfxsr] == 0b0 | 0xf0 == prefixes[lck] then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 216 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 217 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 218 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 220 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 221 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 222 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 224 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 225 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 226 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 227 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 228 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 229 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 230 => { + if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf3 then { + chk_exc_fn(":LEGACY", ":TYPE-5", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-2", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 231 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-8", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-1", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 232 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 233 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 234 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 236 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 237 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 238 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 240 => { + if mandatory_prefix == 0xf2 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE3"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE3"|]) == 0 | modr_m[mod] == 0b11 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 241 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 242 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 243 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 244 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 245 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 246 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":SSE"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 247 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-8", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 248 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 249 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 250 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 251 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 252 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 253 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 254 => { + if mandatory_prefix == 0x00 then { + chk_exc_fn(":LEGACY", ":TYPE-22-7", [|":MMX"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":MMX"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else if mandatory_prefix == 0x66 then { + chk_exc_fn(":LEGACY", ":TYPE-4", [|":SSE2"|], proc_mode, prefixes, rex_byte, opcode, modr_m, sib); + if feature_flags_fn([|":SSE2"|]) == 0 then { + x86_fault("(:UD)") + }; + x86_model_error("Opcode Unimplemented in x86isa!") + } else { + x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + } + }, + 42 => throw(Emsg("Translation error: two-byte opcode 42 not translated")), + 44 => throw(Emsg("Translation error: two-byte opcode 44 not translated")), + 45 => throw(Emsg("Translation error: two-byte opcode 45 not translated")), + 46 => throw(Emsg("Translation error: two-byte opcode 46 not translated")), + 47 => throw(Emsg("Translation error: two-byte opcode 47 not translated")), + 56 => throw(Emsg("Translation error: two-byte opcode 56 not translated")), + 58 => throw(Emsg("Translation error: two-byte opcode 58 not translated")), + 81 => throw(Emsg("Translation error: two-byte opcode 81 not translated")), + 84 => throw(Emsg("Translation error: two-byte opcode 84 not translated")), + 85 => throw(Emsg("Translation error: two-byte opcode 85 not translated")), + 86 => throw(Emsg("Translation error: two-byte opcode 86 not translated")), + 87 => throw(Emsg("Translation error: two-byte opcode 87 not translated")), + 88 => throw(Emsg("Translation error: two-byte opcode 88 not translated")), + 89 => throw(Emsg("Translation error: two-byte opcode 89 not translated")), + 90 => throw(Emsg("Translation error: two-byte opcode 90 not translated")), + 92 => throw(Emsg("Translation error: two-byte opcode 92 not translated")), + 93 => throw(Emsg("Translation error: two-byte opcode 93 not translated")), + 94 => throw(Emsg("Translation error: two-byte opcode 94 not translated")), + 95 => throw(Emsg("Translation error: two-byte opcode 95 not translated")), + 116 => throw(Emsg("Translation error: two-byte opcode 116 not translated")), + 174 => throw(Emsg("Translation error: two-byte opcode 174 not translated")), + 188 => throw(Emsg("Translation error: two-byte opcode 188 not translated")), + 194 => throw(Emsg("Translation error: two-byte opcode 194 not translated")), + 199 => throw(Emsg("Translation error: two-byte opcode 199 not translated")), + 215 => throw(Emsg("Translation error: two-byte opcode 215 not translated")), + 219 => throw(Emsg("Translation error: two-byte opcode 219 not translated")), + 223 => throw(Emsg("Translation error: two-byte opcode 223 not translated")), + 235 => throw(Emsg("Translation error: two-byte opcode 235 not translated")), + 239 => throw(Emsg("Translation error: two-byte opcode 239 not translated")), + _ => x86_fault("(X86-ILLEGAL-INSTRUCTION \"#UD Encountered!\" START-RIP TEMP-RIP X86)") + }) : unit + } +} + +/*! Decoder and dispatch function for two-byte opcodes +

Source: Intel Manual, Volume 2, Appendix A-2

*/ +val two_byte_opcode_decode_and_execute : (proc_mode, sbits(48), sbits(48), prefixes, bits(8), bits(8)) -> unit + +function two_byte_opcode_decode_and_execute (proc_mode, start_rip, temp_rip, prefixes, rex_byte, escape_byte) = { + let ctx : string = "two-byte-opcode-decode-and-execute"; + let opcode : bits(8) = rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X"); + let temp_rip : sbits(48) = add_to_iptr(proc_mode, temp_rip, 0x000000000001); + let mandatory_prefix : bits(8) = compute_mandatory_prefix_for_two_byte_opcode(proc_mode, opcode, prefixes); + let modr_m? : bool = two_byte_opcode_modr_m_p(proc_mode, mandatory_prefix, opcode); + let modr_m : modr_m = { + if modr_m? then { + Mk_modr_m(rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X")) + } else { + Mk_modr_m(0x00) + } + }; + let temp_rip : sbits(48) = { + if modr_m? then { + add_to_iptr(proc_mode, temp_rip, 0x000000000001) + } else { + temp_rip + } + }; + let sib? : bool = modr_m? & (let p4? : bool = 0x67 == prefixes[adr] in + let n16_bit_addressp : bool = 2 == select_address_size(proc_mode, Some(prefixes)) in + x86_decode_sib_p(modr_m, n16_bit_addressp)); + let sib : sib = { + if sib? then { + Mk_sib(rme08(proc_mode, select_address_size(proc_mode, Some(prefixes)), sail_sign_extend(temp_rip, 64), None(), 1, ":X")) + } else { + Mk_sib(0x00) + } + }; + let temp_rip : sbits(48) = { + if sib? then { + add_to_iptr(proc_mode, temp_rip, 0x000000000001) + } else { + temp_rip + } + }; + two_byte_opcode_execute(proc_mode, start_rip, temp_rip, prefixes, mandatory_prefix, rex_byte, opcode, modr_m, sib) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/xor_spec.sail b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/xor_spec.sail new file mode 100644 index 000000000..a7001797a --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/model/xor_spec.sail @@ -0,0 +1,56 @@ + +val gpr_xor_spec_1 : (bits(8), bits(8), rflagsbits) -> (bits(8), rflagsbits, rflagsbits) + +function gpr_xor_spec_1 (dst, src, input_rflags) = { + let result : bits(8) = logxor(dst, src)[7 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec8(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec8(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_xor_spec_2 : (bits(16), bits(16), rflagsbits) -> (bits(16), rflagsbits, rflagsbits) + +function gpr_xor_spec_2 (dst, src, input_rflags) = { + let result : bits(16) = logxor(dst, src)[15 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec16(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec16(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_xor_spec_4 : (bits(32), bits(32), rflagsbits) -> (bits(32), rflagsbits, rflagsbits) + +function gpr_xor_spec_4 (dst, src, input_rflags) = { + let result : bits(32) = logxor(dst, src)[31 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec32(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec32(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} + +val gpr_xor_spec_8 : (bits(64), bits(64), rflagsbits) -> (bits(64), rflagsbits, rflagsbits) + +function gpr_xor_spec_8 (dst, src, input_rflags) = { + let result : bits(64) = logxor(dst, src)[63 .. 0]; + let cf : {|0|} = 0; + let pf : bits(1) = pf_spec64(result); + let zf : bits(1) = zf_spec(unsigned(result)); + let sf : bits(1) = sf_spec64(result); + let of : {|0|} = 0; + let output_rflags : rflagsbits = [input_rflags with cf = bits_of_int(cf, 1), pf, zf, sf, of = bits_of_int(of, 1)]; + let undefined_flags : rflagsbits = [Mk_rflagsbits(0x00000000) with af = 0b1]; + (result, output_rflags, undefined_flags) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md b/crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md new file mode 100644 index 000000000..f24dac031 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Rui Ueyama + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/README.md b/crates/clazel-x64/tests/data/sail-x86-shina/README.md new file mode 100644 index 000000000..497fe9d25 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/README.md @@ -0,0 +1,116 @@ +# sail-x86 + +This repo contains a comprehensive formal specification of the x86-64 +instruction set written in the +[Sail](https://github.com/rems-project/sail) ISA specification +language, based on the +[Intel Software Developer's Manual](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html) +(SDM) and actual hardware behavior. Our goal is to provide an +authoritative, machine-readable formalization of x86-64 for researchers +and practitioners who need to formally verify software or hardware +targeting the architecture. + +## Status + +The specification covers the general-purpose, SSE, SSE2, SSE3, SSSE3, +SSE4.1, SSE4.2, AES-NI, AVX/AVX2, AVX-512/EVEX, and x87 FPU +instruction sets, plus the system level: segmentation, paging +(32-bit/PAE/4-level/5-level with EPT), exceptions and interrupts, +real, [virtual-8086](docs/virtual-8086.md) and compatibility modes, SMM, +and VMX virtualization (Linux/KVM +runs as a nested hypervisor on the model's VMX). SGX, AMX, CET, MPX, +and TSX are out of scope, as is any concurrency or memory-ordering +model; see docs/x86-64-completeness-checklist.md for the per-unit +inventory. + +The Sail model can be compiled to C++ using the Sail compiler and serves +as the CPU core in two emulators: a user-mode emulator that runs real +Linux x86-64 binaries (coreutils, Python, Clang), and a system-level +emulator that boots Linux to an interactive shell and SeaBIOS+FreeDOS +to a DOS prompt. The +emulators provide the scaffolding not covered by the ISA specification +itself — memory, peripherals, syscall emulation. + +## Building + +Prerequisites: + +- [Sail](https://github.com/rems-project/sail) 0.20+ +- GMP (`sudo apt install libgmp-dev`) +- CMake 3.20+ +- GCC or Clang with C++23 support + +``` +mkdir build && cd build +cmake .. +make -j$(nproc) +``` + +## User-mode emulator + +``` +./build/usermode-emu/sail-x86-user [args...] +``` + +Both statically and dynamically linked x86-64 ELF binaries are +supported. The emulator interprets each instruction through the Sail +model and emulates Linux syscalls. + +``` +$ ./build/usermode-emu/sail-x86-user /bin/ls / +bin boot dev etc home lib ... +$ ./build/usermode-emu/sail-x86-user /usr/bin/python3 -c "print('hello')" +hello +``` + +Pass `-d` for a debug trace of each instruction. + +## System emulator (Linux boot) + +The system emulator loads a bzImage through the kernel's own 16-bit +real-mode setup path and +boots Linux with an initramfs to an interactive serial console. + +To download the Linux kernel source, build it with a minimal +configuration, build a BusyBox initramfs, and print the boot command: + +``` +cd build +make linux +``` + +This requires `curl`, `busybox-static`, and `fakeroot` in addition to +the standard kernel build tools. The kernel source is downloaded +automatically. + +To run the emulator manually: + +``` +./build/system-emu/sail-x86-system -i initramfs.cpio bzImage +``` + +## Testing + +``` +cd build && ctest -j$(nproc) --output-on-failure +``` + +## Project structure + +- `model/` — Sail specification (~40 files) + - Instruction decoder (prefix, ModR/M, opcode maps) + - Per-instruction semantics (ALU, SSE, AVX, x87, system) + - Types, registers, memory, flags, floating-point externals +- `usermode-emu/` — user-mode Linux emulator in C++ + - ELF loader, Linux syscall emulation, execution loop +- `system-emu/` — system-level emulator in C++ + - Physical memory, device emulation (UART, PIT, PIC) + - Paging, interrupt/exception delivery + - Scripts to build a minimal Linux kernel and initramfs +- `emu-shared/` — code shared between both emulators +- `kvm/` — KVM-based differential tests against real hardware +- `test/` — test programs + +## Acknowledgement + +This work was supported by JST, CREST Grant Number JPMJCR22M3, Japan. diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md b/crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md new file mode 100644 index 000000000..cff2ddb2c --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md @@ -0,0 +1,40 @@ +# A Sail model of x86-64 written from the Intel manuals (a subset of its files) + +Upstream: https://github.com/shina-lab/sail-x86/tree/1829cb6ecc5f924b0fd920582953a2402357a12a +Commit: 1829cb6ecc5f924b0fd920582953a2402357a12a +License: MIT (`LICENSE.md` is the repository's `LICENSE`, copied unchanged; Copyright (c) 2026 Rui Ueyama). + +The commit is the tip of `main` of shina-lab/sail-x86 on 2026-11-16 +("XSAVEC, XGETBV, FPREM and FCMOV: undefined where one manual leaves open what +the other defines", 2026-10-23). Its README says it is "based on the Intel +Software Developer's Manual (SDM) and actual hardware behavior", and the +commit messages cite SDM and AMD APM page numbers and compare the model with +KVM runs on an AMD Zen 4 and an Intel Xeon host. + +**Why it is here:** the other Sail model (`sail-x86-from-acl2`) is a +mechanical translation of the ACL2 model, so it cannot be the second, +independent source jit.md item J.2 asks for. This one has no relation to ACL2 +that its README or the files read here state, and it covers SSE2 scalar +double. It is not a peer-reviewed or long-established source: the repository +was created in 2026-03, has about 1,380 commits by one author, many with an AI +co-author line, and its floating-point arithmetic is `extern` (soft-float +supplied by the emulator, `model/extern.sail`). Whether it may count as the +second source is a decision for a person (`crates/clazel-x64/README.md`). + +Copied byte for byte: `README.md`, `docs/x86-64-completeness-checklist.md`, +and from `model/` the files of item J.3's subset and what they need: +`x86.sail_project` (the build order), `prelude`, `core_types`, `extern`, `regs`, +`rflags`, `exceptions`, `paging`, `mem`, `operands`, `branchless`, `insn_simd`, +`insn_prefixes`, `insn_modrm`, `insn_alu`, `insn_sse_fp`, `insn_baseline`, +`insn_groups`, `insn_dispatch` and `fetch_execute`. + +Not vendored: VEX, EVEX, AMX, x87, MMX, SSE integer, XSAVE, VMX, SMM, +virtual-8086, interrupts and crypto (`model/` is 1.5 MB in all), and the +emulators, tests, proofs and reports. Without them the model does not build as +it stands (`x86.sail_project` lists the rest); it is a text to read, as the +other suites are. + +To update, copy the files from a newer commit, change the commit above, and +run `cargo xtask testdata`. `xtask/src/testdata/isa.rs` writes +`tests/generated/sail_x86_shina.rs`, the inventory of paths, sizes and +hashes. Nothing reads the model yet. diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md b/crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md new file mode 100644 index 000000000..7b2971670 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md @@ -0,0 +1,1152 @@ +# x86-64 ISA Completeness Checklist + +Derived from Intel SDM (835 instruction pages, 1208 unique mnemonics). +Each item is testable: verify the Sail spec implements it, or explicitly +documents it as out-of-scope. Refer to the SDM for exact semantics. + +--- + +## Part 1: Instruction Coverage by ISA Extension + +For each instruction: verify (a) it decodes correctly for all valid +opcode/operand-size/addressing-mode combinations listed in SDM, (b) it +computes the correct result, (c) it sets flags per SDM, (d) 64-bit mode +validity matches SDM (some are invalid in 64-bit mode). + +### 1.1 General-Purpose Integer (base x86-64) + +#### 1.1.1 Data Transfer +- [x] MOV (reg/mem/imm, all operand sizes 8/16/32/64) — verified correct +- [x] MOV to/from control registers (MOV CRn) [mov-1 in SDM] — verified correct +- [x] MOV to/from debug registers (MOV DRn) [mov-2 in SDM] — verified: 0F 21 (read) and 0F 23 (write), CPL=0 required, DR4/DR5 alias DR6/DR7 +- [x] MOVSX, MOVSXD (sign-extend 8→16/32/64, 16→32/64, 32→64) — verified correct +- [x] MOVZX (zero-extend 8→16/32/64, 16→32/64) — verified correct +- [x] MOVBE (byte-swap load/store, MOVBE extension) — verified correct +- [x] XCHG (reg-reg, reg-mem; implicit LOCK on memory) — verified correct +- [x] XADD (exchange and add) — verified correct +- [x] CMPXCHG (compare and exchange, 8/16/32/64) — verified correct +- [x] CMPXCHG8B, CMPXCHG16B (8-byte/16-byte compare-and-exchange) — verified correct +- [x] BSWAP (byte-swap 32/64) — verified correct +- [x] XLAT, XLATB (table lookup translation) — verified + KVM tests +- [x] CMOVcc (all 16 conditions, 16/32/64-bit) — verified correct + +#### 1.1.2 Stack Operations +- [x] PUSH (reg, mem, imm8, imm16/32; 16/64-bit operand sizes in 64-bit mode) — verified correct +- [x] POP (reg, mem; 16/64-bit in 64-bit mode) — verified correct +- [x] PUSHF, PUSHFQ (push flags) — verified correct +- [x] POPF, POPFQ (pop flags) — verified, IOPL bug fixed +- [x] PUSHA, PUSHAD (invalid in 64-bit mode — must #UD) — verified correct +- [x] POPA, POPAD (invalid in 64-bit mode — must #UD) — verified correct +- [x] ENTER (create stack frame, nesting levels 0-31) — verified + KVM tests (levels 0,1) +- [x] LEAVE (destroy stack frame) — verified + KVM tests + +#### 1.1.3 Arithmetic +- [x] ADD (all operand size/type combinations, flag effects) — verified correct +- [x] ADC (add with carry) — verified correct +- [x] SUB (subtract) — verified correct +- [x] SBB (subtract with borrow) — verified correct +- [x] INC (no CF modification) — verified correct +- [x] DEC (no CF modification) — verified correct +- [x] NEG (two's complement negate) — verified correct +- [x] CMP (subtract without storing) — verified correct +- [x] MUL (unsigned multiply, 8/16/32/64-bit; widening to double-size) — verified correct +- [x] IMUL (signed multiply — 1-operand widening, 2-operand, 3-operand forms) — verified correct +- [x] DIV (unsigned divide, 8/16/32/64-bit; #DE on overflow/zero) — verified correct +- [x] IDIV (signed divide; #DE on overflow/zero) — verified correct + +#### 1.1.4 Sign/Zero Extension of Accumulators +- [x] CBW (AL→AX), CWDE (AX→EAX), CDQE (EAX→RAX) — verified correct +- [x] CWD (AX→DX:AX), CDQ (EAX→EDX:EAX), CQO (RAX→RDX:RAX) — verified correct + +#### 1.1.5 Logical +- [x] AND, OR, XOR (all operand combinations; OF=CF=0) — verified correct +- [x] NOT (bitwise complement, no flag effects) — verified correct +- [x] TEST (AND without storing) — verified correct + +#### 1.1.6 Shift and Rotate +- [x] SHL/SAL (shift left, same opcode) — verified correct +- [x] SHR (logical shift right) — verified correct +- [x] SAR (arithmetic shift right) — verified correct, OF=0 for count=1 +- [x] ROL (rotate left) — verified correct, SF/ZF/AF/PF unaffected +- [x] ROR (rotate right) — verified correct +- [x] RCL (rotate through carry left) — verified correct, MOD 9/17 for 8/16-bit +- [x] RCR (rotate through carry right) — verified correct, OF set before rotation +- [x] SHLD (double-precision shift left) — verified correct +- [x] SHRD (double-precision shift right) — verified correct +- [x] Shift/rotate count masking (count & 0x1F for 32-bit, count & 0x3F for 64-bit) — verified +- [x] OF flag: defined only for 1-bit shifts, undefined for multi-bit — verified + +#### 1.1.7 Bit and Byte Operations +- [x] BT (bit test → CF) — verified correct +- [x] BTS (bit test and set) — verified correct +- [x] BTR (bit test and reset) — verified correct +- [x] BTC (bit test and complement) — verified correct +- [x] BSF (bit scan forward) — verified correct +- [x] BSR (bit scan reverse) — verified correct +- [x] SETcc (all 16 conditions, byte result) — verified correct +- [x] POPCNT (population count, POPCNT extension) — verified correct +- [x] LZCNT (leading zero count, LZCNT extension — different from BSR) — verified correct +- [x] TZCNT (trailing zero count, BMI1 extension — different from BSF) — verified correct + +#### 1.1.8 Control Flow +- [x] JMP (near relative 8/32, near indirect reg/mem, far direct, far indirect) — verified correct +- [x] Jcc (all 16 conditions, rel8 and rel32) — verified correct +- [x] CALL (near relative, near indirect, far direct, far indirect) — verified, f64 operand-size fix applied +- [x] RET (near, near+imm16, far, far+imm16) — verified, f64 operand-size fix; RETF verified correct +- [x] LOOP, LOOPcc (LOOPE/LOOPZ, LOOPNE/LOOPNZ; uses RCX/ECX/CX per addr size) — verified + KVM tests +- [x] INT n, INT3 (software interrupts) — verified correct; fixed: no error code push for software ints, gate DPL check added. INT1/ICEBP not implemented (raises #UD) +- [x] INTO (invalid in 64-bit mode — must #UD) — verified correct +- [x] IRET, IRETD, IRETQ (interrupt return) — verified, AC/ID flag fix applied +- [x] BOUND (invalid in 64-bit mode — must #UD) — verified correct + +#### 1.1.9 String Operations +- [x] MOVS, MOVSB, MOVSW, MOVSD, MOVSQ — verified correct +- [x] CMPS, CMPSB, CMPSW, CMPSD, CMPSQ — verified correct +- [x] SCAS, SCASB, SCASW, SCASD (SCASQ in 64-bit mode) — verified correct +- [x] LODS, LODSB, LODSW, LODSD, LODSQ — verified correct +- [x] STOS, STOSB, STOSW, STOSD, STOSQ — verified correct +- [N/A] INS, INSB, INSW, INSD — port string I/O, requires I/O port infrastructure not modeled +- [N/A] OUTS, OUTSB, OUTSW, OUTSD — port string I/O, requires I/O port infrastructure not modeled +- [x] REP/REPE/REPZ/REPNE/REPNZ prefix interaction with all string ops — verified correct +- [x] Direction flag (DF) effect on SI/DI increment/decrement — verified correct + +#### 1.1.10 I/O +- [x] IN (imm8 port, DX port; AL/AX/EAX) — verified correct (E4/E5/EC/ED), all operand sizes +- [x] OUT (imm8 port, DX port; AL/AX/EAX) — verified correct (E6/E7/EE/EF), all operand sizes +- [N/A] INS/OUTS (port string I/O, see 1.1.9) — requires I/O port infrastructure not modeled + +#### 1.1.11 Flag Manipulation +- [x] STC, CLC, CMC (set/clear/complement carry) — verified correct +- [x] STD, CLD (set/clear direction) — verified correct +- [x] STI, CLI (set/clear interrupt; IOPL interaction) — verified correct +- [x] LAHF (load AH from flags SF:ZF:0:AF:0:PF:1:CF) — **BUG FIXED**: bit order was reversed +- [x] SAHF (store AH into flags) + +#### 1.1.12 Segment and Address Operations +- [x] LEA (all addressing modes, 16/32/64-bit) — verified, 67h address-size fix applied +- [N/A] LDS, LES (invalid in 64-bit mode — opcodes C4/C5 are VEX prefix) +- [N/A] LFS, LGS, LSS (0F B2/B4/B5 — valid in 64-bit but rarely used; segment descriptor loading not fully modeled) +- [x] NOP (1-byte 0x90 and multi-byte 0F 1F /0) — verified correct + +#### 1.1.13 Decimal Arithmetic (all invalid in 64-bit mode — must #UD) +- [x] AAA, AAS, AAM, AAD — verified #UD in 64-bit mode +- [x] DAA, DAS — verified #UD in 64-bit mode + +#### 1.1.14 Miscellaneous +- [x] CPUID (leaf/subleaf dispatching, feature reporting) — verified correct +- [x] UD (UD0, UD1, UD2 — always #UD) — verified correct +- [x] HLT (halt, ring-0 only) — verified correct +- [x] PAUSE (spin-loop hint) — verified correct +- [x] SERIALIZE (execution serialization) — verified (NOP in sequential model) +- [x] LOCK prefix (valid only with specific memory-destination instructions) — verified correct +- [x] RDTSC (read timestamp counter) — verified correct +- [x] RDTSCP (read timestamp counter and processor ID) — implemented + +### 1.2 x87 Floating-Point + +#### 1.2.1 Data Transfer +- [x] FLD (load float: 32/64/80-bit, ST(i)) — verified: D9/0 mem (f32), DD/0 mem (f64), DB/5 mem (f80), D9/0 reg +- [x] FST, FSTP (store float: 32/64-bit, ST(i); FSTP also 80-bit) — verified: D9/2,3 (f32), DD/2,3 (f64), DB/7 (f80 FSTP) +- [x] FILD (load integer: 16/32/64-bit → ST(0)) — verified: DF/0 (i16), DB/0 (i32), DF/5 (i64) +- [x] FIST, FISTP (store integer from ST(0)) — verified: DF/2,3 (i16), DB/2,3 (i32), DF/7 (i64 FISTP) +- [x] FISTTP (store integer with truncation, SSE3) — verified: DF/1 (i16), DB/1 (i32), DD/1 (i64) +- [x] FBLD (load BCD) — verified: DF/4 mem +- [x] FBSTP (store BCD and pop) — verified: DF/6 mem +- [x] FXCH (exchange ST(0) with ST(i)) — verified: D9/1 reg +- [x] FCMOVcc (conditional float move, 8 conditions) — verified: DA/0-3 (B,E,BE,U), DB/0-3 (NB,NE,NBE,NU) + +#### 1.2.2 Arithmetic +- [x] FADD, FADDP, FIADD — verified: D8/0 (f32), DC/0 (f64), DA/0 (i32), DE/0 (i16), DE/0 reg (FADDP) +- [x] FSUB, FSUBP, FISUB — verified: D8/4, DC/5 reg, DA/4, DE/5 reg (FSUBP) +- [x] FSUBR, FSUBRP, FISUBR (reversed subtract) — verified: D8/5, DC/4 reg, DA/5, DE/4 reg (FSUBRP) +- [x] FMUL, FMULP, FIMUL — verified: D8/1, DC/1, DA/1, DE/1 reg (FMULP) +- [x] FDIV, FDIVP, FIDIV — verified: D8/6, DC/7 reg, DA/6, DE/7 reg (FDIVP) +- [x] FDIVR, FDIVRP, FIDIVR (reversed divide) — verified: D8/7, DC/6 reg, DA/7, DE/6 reg (FDIVRP) +- [x] FABS (absolute value) — verified: D9 E1 +- [x] FCHS (change sign) — verified: D9 E0 +- [x] FSQRT (square root) — verified: D9 FA +- [x] FPREM (partial remainder, 8087-compatible) — verified: D9 F8 +- [x] FPREM1 (IEEE partial remainder) — verified: D9 F5 +- [x] FRNDINT (round to integer) — verified: D9 FC +- [x] FSCALE (scale by power of 2) — verified: D9 FD +- [x] FXTRACT (extract exponent and significand) — verified: D9 F4; fixed FCOM/FCOMP memory: was comparing with ST(i) instead of memory operand + +#### 1.2.3 Transcendental +- [x] FSIN, FCOS, FSINCOS — verified: D9 FE (FSIN), D9 FF (FCOS), D9 FB (FSINCOS pushes cos) +- [x] FPTAN, FPATAN — verified: D9 F2 (FPTAN: tan + push 1.0), D9 F3 (FPATAN: atan2 + pop) +- [x] F2XM1 (2^x - 1) — verified: D9 F0 +- [x] FYL2X, FYL2XP1 (y * log2(x), y * log2(x+1)) — verified: D9 F1, D9 F9 + +#### 1.2.4 Comparison +- [x] FCOM, FCOMP, FCOMPP — verified: D8/2,3 (f32), DC/2,3 (f64), DE D9 (FCOMPP); fixed memory FCOM bug +- [x] FICOM, FICOMP — verified: DA/2,3 (i32 mem), DE/2,3 (i16 mem) +- [x] FCOMI, FCOMIP, FUCOMI, FUCOMIP (set EFLAGS) — verified: DB/5 (FUCOMI), DB/6 (FCOMI), DF/5 (FUCOMIP), DF/6 (FCOMIP) +- [x] FUCOM, FUCOMP, FUCOMPP (unordered compare) — verified: DD/4 (FUCOM), DD/5 (FUCOMP), DA E9 (FUCOMPP) +- [x] FTST (compare ST(0) with 0.0) — verified: D9 E4 +- [x] FXAM (examine ST(0): class/sign) — verified: D9 E5, sets C3/C2/C0 for class, C1 for sign + +#### 1.2.5 Constants +- [x] FLD1, FLDZ, FLDPI, FLDL2E, FLDL2T, FLDLG2, FLDLN2 — verified: D9 E8-EE + +#### 1.2.6 Control +- [x] FINIT, FNINIT (initialize FPU) — verified: DB E3 +- [x] FCLEX, FNCLEX (clear exceptions) — verified: DB E2 +- [x] FLDCW, FSTCW/FNSTCW (load/store control word) — verified: D9/5 (FLDCW), D9/7 (FNSTCW) +- [x] FSTSW/FNSTSW (store status word — AX or memory) — verified: DF E0 (FNSTSW AX), DD/7 (FNSTSW m16) +- [x] FLDENV, FSTENV/FNSTENV (load/store environment) — verified: D9/4 (FLDENV), D9/6 (FNSTENV) +- [x] FSAVE/FNSAVE, FRSTOR (save/restore full state) — verified: DD/6 (FNSAVE), DD/4 (FRSTOR) +- [x] FFREE (free ST(i) register) — verified: DD/0 reg +- [x] FDECSTP, FINCSTP (decrement/increment stack pointer) — verified: D9 F6, D9 F7 +- [x] FNOP (x87 no-op) — verified: D9 D0 (reg=2, sti=0) +- [x] FWAIT/WAIT (wait for pending FPU exceptions) — verified: opcode 9B + +#### 1.2.7 x87 State Save/Restore (SSE era) +- [x] FXSAVE, FXRSTOR (save/restore x87+SSE state) — verified: 0F AE /0 (FXSAVE), /1 (FXRSTOR), REX.W variants + +### 1.3 MMX (legacy, 64-bit packed integer in mm0-mm7) + +- [x] EMMS (empty MMX state — required for x87↔MMX transition) — verified: 0F 77 + KVM tests +- [x] All MMX integer instructions (MOVD/Q, PADD*, PSUB*, PMUL*, PAND/POR/PXOR, PCMP*, PACK*, PUNPCK*, PSHUFW, PINSRW, PEXTRW, PMOVMSKB, PAVG*, PMIN/MAX*, PSAD*, shifts) — ~50 instructions with KVM differential tests +- [x] MASKMOVQ, MOVNTQ — MMX non-temporal ops + KVM tests +- [N/A] MOVDQ2Q, MOVQ2DQ — MMX↔XMM transfer (rarely used, can add if needed) +- [N/A] CVTPD2PI, CVTPI2PD, CVTPI2PS, CVTPS2PI, CVTTPD2PI, CVTTPS2PI — MMX↔float conversions (legacy, rarely used) + +### 1.4 SSE (128-bit, single-precision float) + +#### 1.4.1 SSE Arithmetic +- [x] ADDPS, ADDSS — verified + KVM tests +- [x] SUBPS, SUBSS — verified + KVM tests +- [x] MULPS, MULSS — verified + KVM tests +- [x] DIVPS, DIVSS — verified + KVM tests +- [x] SQRTPS, SQRTSS — verified + KVM tests +- [x] RCPPS, RCPSS (reciprocal approximation) — verified + KVM tests +- [x] RSQRTPS, RSQRTSS (reciprocal sqrt approximation) — verified + KVM tests +- [x] MAXPS, MAXSS (NaN handling per SDM) — verified, NaN bug fixed +- [x] MINPS, MINSS (NaN handling per SDM) — verified, NaN bug fixed + +#### 1.4.2 SSE Comparison +- [x] CMPPS (all 8 predicates), CMPSS — verified, pred 6 NaN bug fixed +- [x] COMISS (ordered compare → EFLAGS) — verified + KVM tests +- [x] UCOMISS (unordered compare → EFLAGS) — verified + KVM tests + +#### 1.4.3 SSE Logical +- [x] ANDPS, ANDNPS, ORPS, XORPS — verified + KVM tests + +#### 1.4.4 SSE Shuffle/Unpack +- [x] SHUFPS (4-element shuffle) — verified + KVM tests +- [x] UNPCKHPS, UNPCKLPS (interleave high/low) — verified + KVM tests +- [x] MOVHLPS, MOVLHPS (move high-to-low, low-to-high) — verified + KVM tests + +#### 1.4.5 SSE Data Transfer +- [x] MOVAPS, MOVUPS (aligned/unaligned 128-bit) — verified + KVM tests +- [x] MOVSS (scalar single) — verified + KVM tests +- [x] MOVHPS, MOVLPS (move high/low 64-bit) — verified + KVM tests +- [x] MOVMSKPS (extract sign bits → GPR) — verified + KVM tests +- [x] MOVNTPS (non-temporal store) — verified + KVM tests + +#### 1.4.6 SSE Conversion +- [x] CVTPS2PD, CVTPD2PS — verified + KVM tests +- [x] CVTSS2SD, CVTSD2SS — verified + KVM tests +- [x] CVTSI2SS, CVTSS2SI — verified + KVM tests +- [x] CVTTSS2SI (truncating) — verified + KVM tests +- [x] CVTDQ2PS, CVTPS2DQ, CVTTPS2DQ — verified, overflow bug fixed + +#### 1.4.7 SSE State/Control +- [x] LDMXCSR, STMXCSR (MXCSR load/store) — verified + KVM tests +- [x] Rounding mode control (bits 14:13) — verified + KVM tests (FP Edge) +- [x] Flush-to-zero (bit 15) — verified + KVM tests (DAZ/FTZ) +- [x] Denormals-are-zeros (bit 6) — verified + KVM tests (DAZ/FTZ) +- [x] Exception mask bits and flag bits — verified + +### 1.5 SSE2 (128-bit, double-precision float + 128-bit integer) + +#### 1.5.1 SSE2 Float64 Arithmetic +- [x] ADDPD, ADDSD — verified + KVM tests +- [x] SUBPD, SUBSD — verified + KVM tests +- [x] MULPD, MULSD — verified + KVM tests +- [x] DIVPD, DIVSD — verified + KVM tests +- [x] SQRTPD, SQRTSD — verified + KVM tests +- [x] MAXPD, MAXSD — verified + KVM tests +- [x] MINPD, MINSD — verified + KVM tests + +#### 1.5.2 SSE2 Float64 Comparison +- [x] CMPPD, CMPSD (all 8 predicates) — verified + KVM tests +- [x] COMISD, UCOMISD — verified + KVM tests + +#### 1.5.3 SSE2 Float64 Logical +- [x] ANDPD, ANDNPD, ORPD, XORPD — verified + KVM tests + +#### 1.5.4 SSE2 Float64 Shuffle/Unpack +- [x] SHUFPD — verified + KVM tests +- [x] UNPCKHPD, UNPCKLPD — verified + KVM tests + +#### 1.5.5 SSE2 Float64 Data Transfer +- [x] MOVAPD, MOVUPD — verified + KVM tests +- [x] MOVSD (scalar double) — verified + KVM tests +- [x] MOVHPD, MOVLPD — verified + KVM tests +- [x] MOVMSKPD — verified + KVM tests +- [x] MOVNTPD — verified + KVM tests + +#### 1.5.6 SSE2 Float64 Conversion +- [x] CVTSI2SD, CVTSD2SI, CVTTSD2SI — verified + KVM tests +- [x] CVTPD2DQ, CVTTPD2DQ, CVTDQ2PD — verified + KVM tests + +#### 1.5.7 SSE2 128-bit Integer +- [x] PADDB..PADDQ (byte/word/dword/qword add, 128-bit) — verified + KVM tests +- [x] PSUBB..PSUBQ (128-bit sub) — verified + KVM tests +- [x] PADDSB, PADDSW, PADDUSB, PADDUSW (128-bit saturating add) — verified + KVM tests +- [x] PSUBSB, PSUBSW, PSUBUSB, PSUBUSW (128-bit saturating sub) — verified + KVM tests +- [x] PMULLW, PMULHW, PMULHUW, PMULUDQ (128-bit multiply variants) — verified + KVM tests +- [x] PMADDWD (128-bit multiply-add) — verified + KVM tests +- [x] PAND, PANDN, POR, PXOR (128-bit) — verified + KVM tests +- [x] PCMPEQB/W/D, PCMPGTB/W/D (128-bit) — verified + KVM tests +- [x] PSLLW/D/Q, PSRLW/D/Q, PSRAW/D (128-bit shifts, imm and xmm count) — verified + KVM tests +- [x] PSLLDQ, PSRLDQ (byte shift 128-bit) — verified + KVM tests +- [x] PACKSSWB, PACKSSDW, PACKUSWB (128-bit pack) — verified + KVM tests +- [x] PUNPCKHBW/WD/DQ/QDQ, PUNPCKLBW/WD/DQ/QDQ (128-bit unpack) — verified + KVM tests +- [x] PSHUFD, PSHUFHW, PSHUFLW (128-bit shuffle) — verified + KVM tests +- [x] MOVDQA, MOVDQU (aligned/unaligned 128-bit integer) — verified + KVM tests +- [x] MOVD, MOVQ (GPR↔XMM transfer) — verified + KVM tests +- [x] MOVNTDQ (non-temporal 128-bit store) — verified + KVM tests +- [x] MASKMOVDQU (byte-masked store) — verified +- [x] PEXTRW, PINSRW (128-bit extract/insert word) — verified + KVM tests +- [x] PMOVMSKB (128-bit byte-mask to GPR) — verified + KVM tests +- [x] PAVGB, PAVGW (128-bit) — verified + KVM tests +- [x] PMAXSW, PMAXUB, PMINSW, PMINUB (128-bit) — verified + KVM tests +- [x] PSADBW (128-bit) — verified + KVM tests +- [x] MOVDDUP (SSE3-era but doubles low qword) — verified + KVM tests +- [x] MOVSHDUP, MOVSLDUP (SSE3) — verified + KVM tests +- [x] LDDQU (SSE3, unaligned load for video) — verified + KVM tests +- [x] PTEST (SSE4.1) — verified + KVM tests + +### 1.6 SSE3 / SSSE3 + +#### 1.6.1 SSE3 +- [x] ADDSUBPS, ADDSUBPD (alternating add/subtract) — verified + KVM tests +- [x] HADDPS, HADDPD (horizontal add) — verified + KVM tests +- [x] HSUBPS, HSUBPD (horizontal subtract) — verified + KVM tests +- [x] MOVDDUP, MOVSHDUP, MOVSLDUP — verified + KVM tests +- [x] LDDQU — verified + KVM tests +- [x] FISTTP (x87 store-integer-with-truncation) — verified in x87 section: DF/1 (i16), DB/1 (i32), DD/1 (i64) +- [N/A] MONITOR, MWAIT (monitor/wait, ring-0) — power management hints, no behavioral effect in sequential model + +#### 1.6.2 SSSE3 (Supplemental SSE3) +- [x] PSHUFB (shuffle bytes) — verified + KVM tests +- [x] PHADDW, PHADDD, PHADDSW (horizontal add) — verified + KVM tests +- [x] PHSUBW, PHSUBD, PHSUBSW (horizontal sub) — verified + KVM tests +- [x] PMADDUBSW (multiply-add unsigned/signed bytes) — verified + KVM tests +- [x] PMULHRSW (multiply high with round and scale) — verified + KVM tests +- [x] PALIGNR (byte-align concatenation) — verified + KVM tests +- [x] PABSB, PABSW, PABSD (absolute value) — verified + KVM tests +- [x] PSIGNB, PSIGNW, PSIGND (conditional negate) — verified + KVM tests + +### 1.7 SSE4.1 / SSE4.2 + +#### 1.7.1 SSE4.1 +- [x] PMULLD (packed multiply low dword → dword) — verified + KVM tests +- [x] PMULDQ (packed multiply signed dword → qword) — verified + KVM tests +- [x] PBLENDW, BLENDPS, BLENDPD (blend with immediate) — verified + KVM tests +- [x] PBLENDVB, BLENDVPS, BLENDVPD (variable blend) — verified + KVM tests +- [x] DPPD, DPPS (dot product) — verified + KVM tests +- [x] ROUNDPS, ROUNDPD, ROUNDSS, ROUNDSD (round with mode) — verified + KVM tests +- [x] INSERTPS, EXTRACTPS (single-precision insert/extract) — verified + KVM tests +- [x] PINSRB, PINSRD, PINSRQ (insert byte/dword/qword) — verified + KVM tests +- [x] PEXTRB, PEXTRD, PEXTRQ (extract byte/dword/qword) — verified + KVM tests +- [x] PMOVSX (packed sign-extend: B→W, B→D, B→Q, W→D, W→Q, D→Q) — verified + KVM tests +- [x] PMOVZX (packed zero-extend: same variants) — verified + KVM tests +- [x] PMINSB, PMINSD, PMINUW, PMINUD (new min variants) — verified + KVM tests +- [x] PMAXSB, PMAXSD, PMAXUW, PMAXUD (new max variants) — verified + KVM tests +- [x] PACKUSDW (pack dword→word unsigned saturation) — verified + KVM tests +- [x] PCMPEQQ (packed compare equal qword) — verified + KVM tests +- [x] PHMINPOSUW (horizontal minimum of unsigned words) — verified + KVM tests +- [x] MPSADBW (multiple sum of absolute differences) — verified + KVM tests +- [x] MOVNTDQA (non-temporal aligned load) — verified + KVM tests +- [x] PTEST (128-bit bitwise test → ZF/CF) — verified + KVM tests + +#### 1.7.2 SSE4.2 +- [x] PCMPESTRI, PCMPESTRM (explicit-length string compare) — verified, delegated to hardware intrinsics +- [x] PCMPISTRI, PCMPISTRM (implicit-length string compare) — verified, delegated to hardware intrinsics +- [x] PCMPGTQ (packed compare greater-than qword) — verified correct +- [x] CRC32 (CRC-32C accumulate) — verified correct + KVM tests +- [x] POPCNT (population count) — verified correct + +### 1.8 AVX (VEX-encoded, 256-bit float, non-destructive 3-operand) + +Note: All SSE integer/float instructions have VEX-encoded equivalents +(VADDPS, VMULPD, VPAND, etc.). The tester should verify: + +- [x] VEX 128-bit forms zero the upper 128 bits of YMM — verified (write_xmm zeroes ZMM[511:128]) +- [x] VEX 256-bit forms of all SSE float ops (PS/PD/SS/SD) — verified + KVM tests +- [x] VEX 3-operand encoding (dest ≠ src1 for all applicable ops) — verified + KVM tests +- [x] VBROADCAST (VBROADCASTSS, VBROADCASTSD, VBROADCASTF128) — verified + KVM tests +- [x] VINSERTF128, VEXTRACTF128 (insert/extract 128-bit lane) — verified + KVM tests +- [x] VPERM2F128 (permute 256-bit float lanes) — verified + KVM tests +- [x] VMASKMOV (conditional float load/store with mask) — verified + KVM tests +- [x] VTESTPS, VTESTPD (bitwise test → ZF/CF) — verified + KVM tests +- [x] VZEROALL, VZEROUPPER (clear upper YMM state) — verified correct +- [x] VEX.vvvv must be 1111b for instructions that don't use it — verified + +### 1.9 AVX2 (VEX-encoded, 256-bit integer) + +- [x] All SSE2/SSSE3/SSE4.1 integer ops promoted to 256-bit (VPADDB..Q, VPSUBB..Q, etc.) — verified + KVM tests +- [x] VPBLENDD (blend dwords with immediate) — verified + KVM tests +- [x] VPBROADCASTB/W/D/Q (broadcast scalar to all elements) — verified + KVM tests +- [x] VPBROADCAST from GPR — verified: EVEX-only (7A/7B/7C), implemented in insn_evex_arith.sail and insn_evex_perm.sail +- [x] VPERMD, VPERMQ (cross-lane dword/qword permute) — verified + KVM tests +- [x] VPERMPD, VPERMPS (cross-lane float permute) — verified + KVM tests +- [x] VPERM2I128 (permute 128-bit integer lanes) — verified + KVM tests +- [x] VINSERTI128, VEXTRACTI128 (insert/extract 128-bit integer lane) — verified + KVM tests +- [x] VPMASKMOV (conditional integer load/store) — verified + KVM tests +- [x] VPSLLVD/Q, VPSRLVD/Q, VPSRAVD (per-element variable shift) — verified + KVM tests +- [x] VPGATHERDD/DQ/QD/QQ (gather integer with VSIB addressing) — verified + KVM tests +- [x] VGATHERDPS/DPD/QPS/QPD (gather float with VSIB addressing) — verified + KVM tests + +### 1.10 FMA (Fused Multiply-Add, VEX-encoded) + +All 132/213/231 forms, scalar and packed, float32 and float64: +- [x] VFMADD{132,213,231}{PS,PD,SS,SD} (fused multiply-add) — verified + KVM tests +- [x] VFMSUB{132,213,231}{PS,PD,SS,SD} (fused multiply-subtract) — verified + KVM tests +- [x] VFNMADD{132,213,231}{PS,PD,SS,SD} (fused negate-multiply-add) — verified + KVM tests +- [x] VFNMSUB{132,213,231}{PS,PD,SS,SD} (fused negate-multiply-subtract) — verified + KVM tests +- [x] VFMADDSUB{132,213,231}{PS,PD} (alternating add/sub) — verified + KVM tests +- [x] VFMSUBADD{132,213,231}{PS,PD} (alternating sub/add) — verified + KVM tests + +### 1.11 BMI1 / BMI2 (Bit Manipulation) + +#### 1.11.1 BMI1 +- [x] ANDN (bitwise AND-NOT, sets flags) — verified correct +- [x] BEXTR (bit field extract) — verified correct +- [x] BLSI (isolate lowest set bit) — verified correct +- [x] BLSMSK (mask up to lowest set bit) — verified correct +- [x] BLSR (reset lowest set bit) — verified correct +- [x] TZCNT (trailing zero count) — verified correct + +#### 1.11.2 BMI2 +- [x] BZHI (zero high bits from specified position) — verified correct +- [x] MULX (unsigned multiply without flags) — verified correct +- [x] PDEP (parallel bit deposit) — verified correct +- [x] PEXT (parallel bit extract) — verified correct +- [x] RORX (rotate right without flags) — verified correct +- [x] SARX, SHLX, SHRX (shift without flags) — verified correct + +### 1.12 ADX (Multi-Precision Arithmetic) +- [x] ADCX (unsigned add with CF in, CF out) — verified correct +- [x] ADOX (unsigned add with OF in, OF out) — verified correct + +### 1.13 AES-NI (AES New Instructions) +- [x] AESENC (one AES encryption round) — verified, delegated to hardware intrinsics +- [x] AESENCLAST (last AES encryption round) — verified, delegated to hardware intrinsics +- [x] AESDEC (one AES decryption round) — verified, delegated to hardware intrinsics +- [x] AESDECLAST (last AES decryption round) — verified, delegated to hardware intrinsics +- [x] AESIMC (inverse mix columns) — verified, delegated to hardware intrinsics +- [x] AESKEYGENASSIST (AES key generation assist) — verified, delegated to hardware intrinsics +- [x] PCLMULQDQ (carry-less multiplication) — verified, delegated to hardware intrinsics + +### 1.14 SHA (SHA Extensions) +- [x] SHA1RNDS4 (SHA-1 4 rounds) — implemented, delegated to hardware intrinsics + KVM tests +- [x] SHA1NEXTE (SHA-1 next E) — implemented, delegated to hardware intrinsics + KVM tests +- [x] SHA1MSG1, SHA1MSG2 (SHA-1 message schedule) — implemented, delegated to hardware intrinsics + KVM tests +- [x] SHA256RNDS2 (SHA-256 2 rounds) — implemented, implicit XMM0 operand + KVM tests +- [x] SHA256MSG1, SHA256MSG2 (SHA-256 message schedule) — implemented, delegated to hardware intrinsics + KVM tests + +### 1.15 AVX-512 Foundation (EVEX-encoded, 512-bit, opmask) + +#### 1.15.1 EVEX Encoding Mechanics +- [x] EVEX prefix decoding (4-byte prefix: P0/P1/P2/P3) — verified and fixed: mmm is 3 bits (was 2), added P[3]=0 and P[10]=1 reserved bit checks +- [x] EVEX.R, EVEX.X, EVEX.B, EVEX.R' (register extension to 32 SIMD regs) — verified: all inverted, correct bit positions +- [x] EVEX.aaa (opmask register k1-k7; k0 = no masking) — verified: stored directly from P2[2:0] +- [x] EVEX.z (zeroing vs merging masking) — verified: P2[7], stored directly +- [x] EVEX.b (broadcast, rounding override, SAE) — verified: P2[4], stored directly +- [x] EVEX.L'L (vector length: 128/256/512) — verified: P2[6:5], stored directly +- [x] Embedded rounding control {rn-sae, rd-sae, ru-sae, rz-sae} — implemented via evex_begin_rc/evex_end_rc: overrides MXCSR RC when EVEX.b=1 for reg-reg, forces 512-bit vector length; applied to all EVEX FP arithmetic, all FMA, VSCALEF, VGETEXP, and all EVEX conversion instructions (VCVTPS2DQ/UDQ/QQ, VCVTPD2DQ/UDQ/QQ, VCVTDQ2PS, VCVTQQ2PS/PD, VCVTUDQ2PS/PD, VCVTUQQ2PS/PD, VCVTPS2PD, VCVTPD2PS, VCVTSI2SS/SD, VCVTSS2SI/SD, VCVTUSI2SS/SD, VCVTSS2USI, VCVTSD2USI) + 22 KVM tests +- [x] Suppress-all-exceptions (SAE) — implied by embedded rounding control (EVEX.b=1 for reg-reg); sequential model does not generate FP exceptions, so SAE has no behavioral effect +- [x] Memory broadcast (1-to-4, 1-to-8, 1-to-16) — verified: comprehensive coverage via evex_bcast_src_f32/f64_{zmm,ymm,xmm} helpers. Applied to ALL dword/qword EVEX instructions: packed FP arithmetic, FMA 132/213/231, conversions (same-width/narrowing/widening), permutes, compares, shuffles, integer arithmetic, logical, VNNI, ternary logic, variable shifts/rotates, VPOPCNT/VPLZCNT/VPCONFLICT, VPMADD52, VGF2P8AFFINE, and more. Byte/word BW-extension instructions correctly excluded (no broadcast per SDM). 22 KVM broadcast tests. + +#### 1.15.2 Opmask (k0-k7) Instructions +- [x] KMOVW/B/D/Q (move mask) — verified: W forms implemented (0F 90/91/92/93) + KVM tests +- [x] KANDW/B/D/Q, KANDNW/B/D/Q (mask AND, AND-NOT) — verified: W forms implemented (0F 41/42) + KVM tests +- [x] KORW/B/D/Q, KXORW/B/D/Q, KXNORW/B/D/Q (mask OR, XOR, XNOR) — verified: W forms implemented (0F 45/47/46) + KVM tests +- [x] KNOTW/B/D/Q (mask NOT) — verified: W form implemented (0F 44) + KVM tests +- [x] KORTESTW/B/D/Q, KTESTW/B/D/Q (mask test → EFLAGS) — verified: W forms implemented (0F 98/99) + KVM tests +- [x] KSHIFTLW/B/D/Q, KSHIFTRW/B/D/Q (mask shift) — verified: W forms implemented (0F3A 32/30) + KVM tests +- [x] KUNPCKBW, KUNPCKWD, KUNPCKDQ (mask unpack) — verified: BW/WD forms implemented (0F 4B) +- [x] KADDW/B/D/Q (mask add) — verified: W form implemented (0F 4A) + +#### 1.15.3 AVX-512F Arithmetic (512-bit) +- [x] VADDPS/PD, VSUBPS/PD (512-bit add/sub) — verified: implemented in insn_evex_fp.sail +- [x] VMULPS/PD, VDIVPS/PD (512-bit mul/div) — verified: implemented in insn_evex_fp.sail +- [x] VSQRTPS/PD (512-bit sqrt) — verified: implemented in insn_evex_fp.sail +- [x] VFMADD/VFMSUB/VFNMADD/VFNMSUB (512-bit FMA, all forms) — verified: all 132/213/231, PS/PD/SS/SD in insn_evex_fma.sail +- [x] VFMADDSUB/VFMSUBADD (512-bit alternating) — verified: implemented in insn_evex_fma.sail +- [x] VMAXPS/PD, VMINPS/PD (512-bit with opmask) — verified: implemented in insn_evex_fp.sail +- [x] Scalar variants: VADDSS/SD, VMULSS/SD, VSUBSS/SD, VDIVSS/SD, VSQRTSS/SD, VMINSS/SD, VMAXSS/SD (EVEX-encoded scalars) — implemented with {er} support + 13 KVM tests +- [x] EVEX VMOVSS/SD (scalar move, load/store/reg-reg merge) — verified: opcode 10 (load) + opcode 11 (store), both memory and 3-operand register forms + 8 KVM tests +- [x] All with merging/zeroing masking — verified: evex_merge helper applies k-mask throughout + +#### 1.15.4 AVX-512F Comparison +- [x] VCMPPS/PD (compare → opmask register, all 32 predicates) — verified: full 5-bit predicate in insn_evex_fp.sail +- [x] VPCMPD/UD/Q/UQ (integer compare → opmask, 8 predicates) — fixed: 0x1F was calling unsigned instead of signed; added missing VPCMPQ (W=1) and VPCMPUQ (W=1); opcode 0x1E added for VPCMPUD/UQ. KVM-tested signed vs unsigned results. +- [x] VPCMPB/UB/W/UW (AVX-512BW, compare bytes/words → opmask) — fixed: added missing VPCMPW (W=1) and VPCMPUW (W=1) variants. KVM-tested signed vs unsigned word results. +- [x] VPTESTMB/W/D/Q (bitwise test → opmask) — verified: implemented in insn_evex_arith.sail +- [x] VPTESTNMB/W/D/Q (bitwise test-not → opmask) — verified: implemented in insn_evex_arith.sail + +#### 1.15.5 AVX-512F Conversion +- [x] VCVTPS2PD, VCVTPD2PS (float widen/narrow, 512-bit) — verified: implemented in insn_evex_fp.sail +- [x] VCVTPS2DQ, VCVTDQ2PS, VCVTTPD2DQ, etc. — verified: implemented in insn_evex_fp.sail +- [x] VCVTPS2UDQ, VCVTPD2UDQ (convert to unsigned) — verified: implemented in insn_evex_fp.sail +- [x] VCVTUDQ2PS, VCVTUDQ2PD (unsigned int → float) — verified: implemented in insn_evex_fp.sail +- [x] VCVTPS2QQ, VCVTPD2QQ (float → signed qword) — verified: helpers + dispatch in insn_evex_fp.sail +- [x] VCVTPS2UQQ, VCVTPD2UQQ (float → unsigned qword) — verified: helpers + dispatch in insn_evex_fp.sail +- [x] VCVTQQ2PS (signed qword → float32, narrowing) — implemented: EVEX.NP.0F.W1 5B + KVM tests +- [x] VCVTQQ2PD (signed qword → float64) — verified: helpers + dispatch in insn_evex_fp.sail +- [x] VCVTUQQ2PS, VCVTUQQ2PD (unsigned qword → float) — verified: helpers + dispatch in insn_evex_fp.sail +- [x] VCVTSD2USI, VCVTSS2USI (scalar float → unsigned GPR) — verified: EVEX 0F 79 F2/F3 prefix +- [x] VCVTUSI2SD, VCVTUSI2SS (unsigned GPR → scalar float) — verified: EVEX 0F 7B F2/F3 prefix +- [x] VCVTTPS2QQ, VCVTTPD2QQ (truncating float → signed qword) — verified: helpers + dispatch +- [x] VCVTTPS2UDQ, VCVTTPD2UDQ (truncating float → unsigned dword) — verified: helpers + dispatch +- [x] VCVTTPS2UQQ, VCVTTPD2UQQ (truncating float → unsigned qword) — verified: helpers + dispatch + +#### 1.15.6 AVX-512F Data Movement +- [x] VMOVDQA32/64, VMOVDQU32/64 (aligned/unaligned with mask) — verified: implemented in insn_evex_fp.sail and insn_evex_int.sail; VMOVDQU8/16 not yet implemented +- [x] VPBROADCASTD/Q (broadcast with EVEX) — verified: from XMM/mem and GPR in insn_evex_perm.sail +- [x] VPBROADCASTB/W (AVX-512BW) — verified: from XMM/mem and GPR in insn_evex_perm.sail +- [x] VBROADCASTSS/SD/F32X4/F64X2/F32X8/F64X4 (broadcast scalar/lane) — verified: all forms in insn_evex_perm.sail (0F38 18/19/1A/1B) +- [x] VMOVSH, VMOVW (AVX-512FP16) — FP16 move instructions implemented in insn_evex_fp16.sail +- [x] VCOMPRESSPD/PS (compress packed float) — verified: insn_evex_perm.sail + 5 KVM tests; memory store form implemented (writes only compressed elements) +- [x] VEXPANDPD/PS (expand packed float) — verified: insn_evex_perm.sail + 2 KVM tests +- [x] VPCOMPRESSD/Q (compress packed int) — verified: insn_evex_perm.sail + 1 KVM test; memory store form implemented +- [x] VPEXPANDD/Q (expand packed int) — verified: insn_evex_perm.sail + +#### 1.15.7 AVX-512F Permute/Shuffle +- [x] VPERMD/W, VPERMQ, VPERMPD, VPERMPS (512-bit permute) — verified: implemented in insn_evex_perm.sail +- [x] VPERMI2B/W/D/Q/PS/PD (2-source permute, index in dest) — verified and fixed: D/Q/PS/PD in insn_evex_perm.sail; B/W opcode 0F38 75 was missing from dispatch, now implemented + 1 KVM test +- [x] VPERMT2B/W/D/Q/PS/PD (2-source permute, index in src) — verified: D/Q/PS/PD in insn_evex_perm.sail, B/W in insn_evex_arith.sail +- [x] VPERMILPS, VPERMILPD (in-lane permute) — verified: implemented in insn_evex_perm.sail +- [x] VSHUFF32X4, VSHUFF64X2, VSHUFI32X4, VSHUFI64X2 (cross-lane shuffle) — verified: implemented in insn_evex_imm.sail +- [x] VINSERTF32X4/64X2/32X8/64X4 (insert 128/256-bit) — verified: all forms in insn_evex_imm.sail (0F3A 18/1A) +- [x] VINSERTI32X4/64X2/32X8/64X4 (integer insert) — verified: all forms in insn_evex_imm.sail +- [x] VEXTRACTF32X4/64X2/32X8/64X4 (extract 128/256-bit) — verified: all forms in insn_evex_imm.sail (0F3A 19/1B) +- [x] VEXTRACTI32X4/64X2/32X8/64X4 (integer extract) — verified: all forms in insn_evex_imm.sail +- [x] VALIGND, VALIGNQ (dword/qword-granularity concatenate+shift) — verified: implemented in insn_evex_imm.sail +- [x] VPSHUFBITQMB (AVX-512BITALG, shuffle bit test → mask) — verified: insn_evex_perm.sail, 0F38 8F + +#### 1.15.8 AVX-512F Logic and Blend +- [x] VPTERNLOGD, VPTERNLOGQ (ternary logic with imm8 truth table) — verified: implemented in insn_evex_imm.sail + 10 KVM tests (a, b, c, ones, zeros, AND, OR, XOR, 3-way XOR, 3-way AND) +- [x] VPBLENDMD/Q (blend with opmask) — verified and fixed: D/Q in insn_evex_perm.sail; B/W in insn_evex_arith.sail; merge masking bug fixed (k[i]=0 gave old_dst instead of SRC1) + 5 KVM tests +- [x] VBLENDMPS, VBLENDMPD (blend float with opmask) — verified and fixed: insn_evex_perm.sail; same merge masking bug fixed + +#### 1.15.9 AVX-512F Shift/Rotate +- [x] VPSLLVW/D/Q, VPSRLVW/D/Q, VPSRAVW/D/Q (variable shift, 512-bit) — verified: all variants in insn_evex_arith.sail +- [x] VPSRAQ (arithmetic right shift qwords by imm/xmm, AVX-512 new) — verified: insn_evex_int.sail + 4 KVM tests +- [x] VPROLVD/Q (variable rotate left) — verified: implemented in insn_evex_arith.sail +- [x] VPROLD/Q (immediate rotate left) — implemented in insn_evex_int.sail, EVEX.66.0F 72 /1 + KVM tests +- [x] VPRORVD/Q (variable rotate right) — verified: implemented in insn_evex_arith.sail +- [x] VPRORD/Q (immediate rotate right) — implemented in insn_evex_int.sail, EVEX.66.0F 72 /0 + KVM tests + +#### 1.15.10 AVX-512F Gather/Scatter +- [x] VPGATHERDD/DQ/QD/QQ (EVEX gather with opmask) — verified: implemented in insn_evex_perm.sail; fixed disp_n for W=1 qword variants (was 4, now 8) +- [x] VGATHERDPS/DPD/QPS/QPD (EVEX gather float) — verified: implemented in insn_evex_perm.sail; fixed disp_n for W=1 variants +- [x] VPSCATTERDD/DQ/QD/QQ (scatter integer) — verified: implemented in insn_evex_fma.sail; fixed disp_n for W=1 qword variants +- [x] VSCATTERDPS/DPD/QPS/QPD (scatter float) — verified: implemented in insn_evex_fma.sail; fixed disp_n for W=1 variants +- [N/A] VGATHERPF0/PF1 (prefetch gather, AVX-512PF) — AVX-512PF (Xeon Phi only) not targeted +- [N/A] VSCATTERPF0/PF1 (prefetch scatter, AVX-512PF) — AVX-512PF (Xeon Phi only) not targeted + +#### 1.15.11 AVX-512F Math/Special +- [x] VGETEXPPD/PS/SD/SS (extract float exponent) — verified: implemented in insn_evex_fma.sail + 2 KVM tests +- [x] VGETMANTPD/PS/SD/SS (extract float mantissa) — verified and **BUG FIXED**: imm8 field mapping was swapped (used [1:0] as sign control instead of [3:2]); added normalization interval support + 2 KVM tests +- [x] VRCP14PD/PS/SD/SS (approximate reciprocal) — verified: implemented in insn_evex_fma.sail +- [x] VRSQRT14PD/PS/SD/SS (approximate reciprocal sqrt) — verified: implemented in insn_evex_fma.sail +- [N/A] VRCP28PD/PS/SD/SS (high-precision reciprocal, AVX-512ER) — AVX-512ER (Xeon Phi only) not targeted +- [N/A] VRSQRT28PD/PS/SD/SS (high-precision recip sqrt, AVX-512ER) — AVX-512ER (Xeon Phi only) not targeted +- [N/A] VEXP2PD/PS (base-2 exponential, AVX-512ER) — AVX-512ER (Xeon Phi only) not targeted +- [x] VSCALEFPD/PS/SD/SS (scale by power of 2) — verified: implemented in insn_evex_fma.sail +- [x] VRNDSCALEPD/PS/SD/SS (round to fixed number of fraction bits) — verified: rounding mode fix applied + 4 KVM tests +- [x] VREDUCEPD/PS/SD/SS (reduce float range) — verified + 2 KVM tests +- [x] VRANGEPD/PS/SD/SS (range restriction) — verified and **BUG FIXED**: sign control (imm8[3:2]) was ignored, abs_min/abs_max returned absolute values instead of originals; rewritten to match SDM pseudocode + 8 KVM tests +- [x] VFIXUPIMMPD/PS/SD/SS (fix up special float values) — verified: full token classification + response table in C emulator + 2 KVM tests +- [x] VFPCLASSPD/PS/SD/SS (classify float → opmask) — verified: implemented in insn_evex_imm.sail + 8 KVM tests (all 8 token types tested) + +#### 1.15.12 AVX-512 Integer Extensions +- [x] VPMOVDB/DW/QB/QD/QW/WB (truncate) — verified: all variants in insn_evex_arith.sail and insn_evex_imm.sail +- [x] VPMOVSDB/SDW/SQB/SQD/SQW/SWB (signed saturation truncate) — verified: implemented in insn_evex_arith.sail +- [x] VPMOVUSDB/USDW/USQB/USQD/USQW/USWB (unsigned saturation truncate) — verified: implemented in insn_evex_arith.sail +- [x] VPMOVB2M/W2M/D2M/Q2M (MSB to mask) — verified: all 4 variants in insn_evex_arith.sail +- [x] VPMOVM2B/W/D/Q (mask to vector) — verified: all 4 variants in insn_evex_arith.sail +- [x] VPMADD52HUQ, VPMADD52LUQ (52-bit integer FMA, AVX-512IFMA) — verified: insn_evex_fma.sail, 0F38 B4/B5 + 4 KVM tests +- [x] VPMULTISHIFTQB (multi-shift qword, AVX-512VBMI) — verified: insn_evex_arith.sail, 0F38 83 + 2 KVM tests +- [x] VPOPCNTB/W/D/Q (per-element popcount, AVX-512BITALG/VPOPCNTDQ) — verified: insn_evex_arith.sail, 0F38 54/55 + 2 KVM tests +- [x] VPLZCNTD/Q (per-element leading zero count, AVX-512CD) — verified: insn_evex_arith.sail, 0F38 44 + 2 KVM tests +- [x] VPCONFLICTD/Q (conflict detection, AVX-512CD) — verified: insn_evex_arith.sail, 0F38 C4 + 3 KVM tests +- [x] VPDPBUSD, VPDPBUSDS, VPDPWSSD, VPDPWSSDS (VNNI dot product) — verified: all 4 variants in insn_evex_arith.sail + 5 KVM tests +- [x] VP2INTERSECTD/Q (AVX-512VP2INTERSECT) — insn_evex_arith.sail, 0F38 68; checked against a C reference in avx512-test (no hardware oracle: only Tiger Lake and Zen 5 have it) +- [N/A] VP4DPWSSD, VP4DPWSSDS (4-iteration dot product, AVX-512_4VNNIW) — Xeon Phi only, not targeted +- [N/A] V4FMADDPS, V4FMADDSS, V4FNMADDPS, V4FNMADDSS (AVX-512_4FMAPS) — Xeon Phi only, not targeted +- [x] VPSHLDW/D/Q, VPSHLDVW/D/Q (concatenate and shift left, AVX-512VBMI2) — verified and fixed: immediate in insn_evex_imm.sail + 4 KVM tests; variable in insn_evex_arith.sail + 2 KVM tests (operand order bug fixed) +- [x] VPSHRDW/D/Q, VPSHRDVW/D/Q (concatenate and shift right, AVX-512VBMI2) — verified and fixed: immediate in insn_evex_imm.sail + 4 KVM tests; variable in insn_evex_arith.sail + 2 KVM tests (operand order bug fixed) +- [x] VPCOMPRESSB/W (byte/word compress, AVX-512VBMI2) — **REWRITTEN**: was simplified pass-through (just copy), now implements proper compress semantics with writemask + 8 KVM tests (reg+mem forms) +- [x] VPEXPANDB/W (byte/word expand, AVX-512VBMI2) — **REWRITTEN**: was simplified pass-through, now implements proper expand semantics with writemask +- [x] VDBPSADBW (double-block packed SAD, AVX-512BW) — verified and fixed: insn_evex_imm.sail, 0F3A 42 + 2 KVM tests (algorithm rewritten to match SDM: dword selection + sliding window SAD) + +### 1.16 AVX-512 FP16 (EVEX-encoded, float16) + +- [x] VADDPH/SH, VSUBPH/SH, VMULPH/SH, VDIVPH/SH, VMINPH/SH, VMAXPH/SH, VSQRTPH — packed/scalar FP16 arithmetic (MAP5, NP W=0) +- [x] VCVTPH2PD, VCVTDQ2PH, VCVTQQ2PH — FP16 conversions (MAP5) +- [x] VFMADD132/213/231PH, VFMSUB132/213/231PH, VFNMADD132/213/231PH, VFNMSUB132/213/231PH — all 12 FP16 FMA forms (MAP6, 66 W=0) +- [x] VCMPPH/SH, VCOMISH, VUCOMISH — FP16 compare (MAP3 0xC2 + MAP5 0x2E/0x2F) +- [x] VRCPPH/SH, VRSQRTPH/SH — FP16 reciprocal/rsqrt (MAP6 0x4C-0x4F) +- [x] VSCALEFPH/SH, VGETEXPPH/SH, VGETMANTPH/SH — FP16 special ops (MAP6 0x2C/0x2D/0x42/0x43, MAP3 0x26/0x27) +- [x] VREDUCEPH/SH, VRNDSCALEPH/SH, VFPCLASSPH/SH — FP16 reduce/round/classify (MAP3 0x56/0x57/0x08/0x0A/0x66/0x67) +- [x] VFMADDSUBPH, VFMSUBADDPH — FP16 interleaved FMA (MAP6 0x96/0x97/0xA6/0xA7/0xB6/0xB7) +- [x] VFCMADDCPH/SH, VFCMULCPH/SH, VFMADDCPH/SH, VFMULCPH/SH — FP16 complex arithmetic (MAP6 0x56/0x57/0xD6/0xD7) +- [x] VMOVSH, VMOVW — FP16 move (MAP5 0x10/0x11/0x6E/0x7E) +- [x] All FP16 conversions (VCVTPH2W/UW/DQ/UDQ/QQ/UQQ, VCVTW2PH/UW2PH, VCVTSH2SS/SD, VCVTSI2SH, VCVTSH2SI, etc.) — MAP5 0x78-0x7D, 0x2A/0x2C/0x2D/0x5A/0x5B/0x1D, MAP6 0x13 +- [x] Scalar FP16 FMA (VFMADD/VFMSUB/VFNMADD/VFNMSUB 132/213/231SH) — MAP6 0x99-0xBF odd opcodes + +### 1.17 AVX-512 BFloat16 +- [x] VCVTNE2PS2BF16, VCVTNEPS2BF16, VDPBF16PS + +### 1.18 AMX (Advanced Matrix Extensions) +- [N/A] All AMX instructions (LDTILECFG, STTILECFG, TILELOADD/T1, TILESTORED, TILEZERO, TILERELEASE, TDPBSSD/BSUD/BUSD/BUUD, TDPBF16PS) — AMX not targeted; requires tile register file and specialized dot-product microarchitecture + +### 1.18.1 F16C (Float16 Conversion) +- [x] VCVTPS2PH (float32 → float16, VEX 128/256 + EVEX 128/256/512) — verified: implemented in insn_vex.sail + insn_evex_imm.sail, subnormal fix applied + 4 KVM tests; imm8 rounding control not yet honored (always rounds nearest) +- [x] VCVTPH2PS (float16 → float32, VEX 128/256 + EVEX 128/256/512) — verified: implemented in insn_vex.sail + insn_evex_arith.sail + KVM tests + +### 1.19 Galois Field (GFNI) +- [x] GF2P8MULB (GF(2^8) byte multiply) — legacy SSE + VEX 128/256 + EVEX 128/256/512, all + KVM tests +- [x] GF2P8AFFINEINVQB (GF(2^8) affine inverse) — legacy SSE + VEX 128/256 + EVEX 128/256/512, all + KVM tests +- [x] GF2P8AFFINEQB (GF(2^8) affine transform) — legacy SSE + VEX 128/256 + EVEX 128/256/512, all + KVM tests + +### 1.20 Key Locker +- [N/A] All Key Locker instructions (LOADIWKEY, ENCODEKEY128/256, AESENC/DEC128/256KL, AESENC/DECWIDE128/256KL) — Key Locker not targeted; requires internal wrapping key hardware + +### 1.21 CET (Control-Flow Enforcement Technology) + +#### 1.21.1 Indirect Branch Tracking +- [x] ENDBR32, ENDBR64 (end branch markers) — handled as NOP via 0F 1E multi-byte NOP range (correct when CET not enabled) + +#### 1.21.2 Shadow Stack +- [N/A] All CET shadow stack instructions (INCSSPD/Q, RDSSPD/Q, SAVEPREVSSP, RSTORSSP, WRSSD/Q, WRUSSD/Q, SETSSBSY, CLRSSBSY) — CET shadow stack not targeted; requires separate shadow stack page table support + +### 1.22 MPX (Memory Protection Extensions) — deprecated +- [N/A] All MPX instructions (BNDMK, BNDCL/CU/CN, BNDMOV, BNDLDX/STX) — MPX deprecated by Intel, removed from hardware; not targeted + +### 1.23 TSX (Transactional Synchronization Extensions) +- [N/A] All TSX instructions (XBEGIN, XEND, XABORT, XTEST, XACQUIRE/XRELEASE HLE prefixes) — TSX effectively deprecated (disabled via microcode on most CPUs due to security issues); not targeted + +### 1.24 XSAVE State Management +- [x] XSAVE (0F AE /4), XRSTOR (0F AE /5) — verified: delegates to external C++ +- [N/A] XSAVEC, XSAVEOPT, XSAVES, XRSTORS — extended XSAVE variants; XSAVE/XRSTOR already implemented and sufficient for Linux boot +- [x] XGETBV (get extended control register XCR0) — verified: 0F 01 D0, returns 0xE7 for XCR0 +- [N/A] XSETBV (set extended control register XCR0) — XCR0 is hardcoded to 0xE7 (x87+SSE+AVX+AVX-512); dynamic feature enable not needed + +### 1.25 System Instructions + +#### 1.25.1 Descriptor Table +- [x] LGDT, LIDT (load GDT/IDT register) — verified: memory-only, CPL=0 required +- [x] SGDT, SIDT (store GDT/IDT register) — verified: memory-only, no privilege check +- [x] LLDT, SLDT (load/store LDT register) — verified: 0F 00 /0 (SLDT), /2 (LLDT) +- [x] LTR, STR (load/store task register) — verified: 0F 00 /1 (STR), /3 (LTR) with GDT descriptor parsing +- [x] ARPL (adjust RPL, invalid in 64-bit mode) — verified: opcode 63h is MOVSXD in 64-bit mode; ARPL only exists in 32-bit mode +- [N/A] LAR (load access rights) — segment descriptor queries; full descriptor model not implemented +- [N/A] LSL (load segment limit) — segment descriptor queries; full descriptor model not implemented +- [N/A] VERR, VERW (verify segment for read/write) — segment descriptor queries; full descriptor model not implemented + +#### 1.25.2 Control Registers +- [x] MOV CRn (CR0, CR2, CR3, CR4, CR8) — previously verified +- [x] MOV DRn (DR0-DR3, DR6, DR7) — verified: 0F 21/23, CPL=0, DR4/5 alias DR6/7 +- [x] LMSW, SMSW (load/store machine status word — CR0 low 16) — verified: LMSW CPL=0, SMSW any CPL; implemented SMSW reg/mem forms +- [x] CLTS (clear TS flag in CR0) — verified: 0F 06, CPL=0 required + +#### 1.25.3 MSR +- [x] RDMSR, WRMSR (read/write model-specific registers) — verified: special handling for EFER, FS/GS/KERNEL_GS_BASE + +#### 1.25.4 Cache/Memory Management +- [x] INVLPG (invalidate TLB entry) — verified: 0F 01 /7 memory-only, CPL=0 +- [N/A] INVPCID (invalidate process-context identifier) — TLB is not modeled (no caching) +- [x] WBINVD (write-back and invalidate cache) — verified: NOP with CPL=0 check; WBNOINVD not implemented (hint variant) +- [x] CLFLUSH, CLFLUSHOPT, CLWB (cache-line flush/writeback) — NOP in sequential model (0F AE /7 mem) +- [N/A] CLDEMOTE (cache-line demote) — cache hint, NOP in sequential model +- [x] PREFETCHH (prefetch to cache hierarchy) — NOP (0F 18 range, multi-byte NOP) +- [x] PREFETCHW (prefetch for write, 3DNow!/AMD) — NOP +- [N/A] PREFETCHWT1 (prefetch with write intent to L2) — cache hint, NOP in sequential model +- [x] LFENCE, SFENCE, MFENCE (memory fences) — verified: NOP in sequential model (0F AE /5,/6,/7 mod=11) +- [x] MOVNTI (non-temporal store, 32/64-bit) — verified: 0F C3 +- [x] MOVNTDQ, MOVNTPD, MOVNTPS (non-temporal SIMD stores) — verified in SSE dispatch +- [x] MOVNTQ (MMX non-temporal store) — implemented + KVM tests +- [x] MOVNTDQA (non-temporal aligned load) — verified in SSE dispatch +- [x] MOVDIR64B (64-byte direct store) — implemented (insn_baseline.sail, exec_movdir64b): ES:reg destination at the address size, 64-byte aligned linear address, source read before any destination check; KVM tests +- [x] MOVDIRI (direct store) — implemented: NP 0F 38 F9, an ordinary 32/64-bit store in the sequential model; KVM tests +- [x] SERIALIZE (execution serialization) — verified: 0F 01 E8, NOP in sequential model + +#### 1.25.5 Task/Interrupt +- [x] SWAPGS (swap GS base) — verified correct +- [x] SYSCALL, SYSRET (fast system call/return) — verified, RFLAGS mask fix applied +- [x] SYSENTER, SYSEXIT (fast system call/return, legacy) — implemented (insn_baseline.sail 0F 34/0F 35); IA-32e semantics asserted by system_test_basic +- [x] HLT (halt) — verified correct +- [x] RSM (resume from system management mode) — implemented (smm.sail); exercised by the SeaBIOS CALL32_SMM trampoline during the FreeDOS boot + +#### 1.25.6 Privilege +- [x] STI, CLI (interrupt flag) — verified: FA (CLI), FB (STI) +- [x] STAC, CLAC (alignment check in SMAP) — verified: 0F 01 CA (CLAC), 0F 01 CB (STAC) +- [x] RDPKRU, WRPKRU (protection key rights) — verified: 0F 01 EE/EF, returns 0 (no PKU) +- [N/A] RDPMC (read performance counter) — performance counters not modeled +- [N/A] RDPID (read processor ID) — delegates to TSC_AUX which is already implemented via RDTSCP + +#### 1.25.7 VMX (Virtual Machine Extensions) +- [x] All VMX instructions (VMXON/OFF, VMLAUNCH/RESUME, VMCALL, VMCLEAR/PTRLD/PTRST, VMREAD/WRITE, VMFUNC, INVEPT/INVVPID) — implemented (insn_vmx.sail, vmx.sail, vmx_vmcs.sail); hosts Linux/KVM as a nested hypervisor with EPT + +#### 1.25.8 SMX (Safer Mode Extensions) +- [N/A] SENTER, SEXIT (measured launch) — SMX not targeted + +#### 1.25.9 SGX (Software Guard Extensions) +- [N/A] All SGX instructions (ENCLS, ENCLU, ENCLV) — SGX deprecated on consumer CPUs; enclave infrastructure not targeted + +#### 1.25.10 UINTR (User Interrupts) +- [N/A] SENDUIPI, UIRET, TESTUI, STUI, CLUI, WAKEUP — UINTR not targeted + +#### 1.25.11 ENQCMD +- [x] ENQCMD, ENQCMDS (enqueue command) — implemented with IA32_PASID (insn_baseline.sail, exec_enqcmd); no modeled device has an enqueue register, so the store is dropped with ZF = 1 (retry) + +#### 1.25.12 PCONFIG +- [N/A] PCONFIG (platform configuration) — TME/MKTME key management not targeted + +#### 1.25.13 WAITPKG (Timed Pause) +- [N/A] TPAUSE, UMONITOR, UMWAIT — user-mode wait extensions not targeted; PAUSE already implemented as NOP + +#### 1.25.14 HRESET +- [N/A] HRESET (history reset) — branch prediction history not modeled + +#### 1.25.15 TSX Suspend Tracking +- [N/A] XRESLDTRK, XSUSLDTRK (resume/suspend load tracking) — TSX load tracking not targeted + +#### 1.25.16 RDRAND/RDSEED +- [x] RDRAND, RDSEED (hardware random number) — implemented, delegates to host intrinsics + +#### 1.25.17 PTWRITE +- [N/A] PTWRITE (write to Processor Trace packet) — Processor Trace not modeled + +#### 1.25.18 INVD +- [N/A] INVD (invalidate cache without writeback) — cache not modeled; WBINVD already handled as NOP + +#### 1.25.19 SMCTRL +- [N/A] SMCTRL (system management control) — SMM not modeled + +#### 1.25.20 ENTERACCS, EXITAC +- [N/A] ENTERACCS, EXITAC (authenticated code module) — TXT/ACM not targeted + +--- + +## Part 2: Encoding and Decoding + +### 2.1 Legacy Prefix Handling +- [x] Operand-size override (66h) — verified + KVM tests +- [x] Address-size override (67h) — decode_rm/decode_rm_evex truncate EA to 32 bits +- [x] Segment overrides (26h/2Eh/36h/3Eh/64h/65h) — verified (FS/GS functional) +- [x] LOCK prefix (F0h) — must #UD on invalid instructions — verified +- [x] REP/REPE/REPNE (F3h/F2h) — correct interaction with string ops — verified +- [x] REP as mandatory prefix (SSE opcode disambiguation) — verified +- [x] Multiple prefix handling (last one wins for same group) — verified + +### 2.2 REX Prefix (40h-4Fh) +- [x] REX.W (64-bit operand size) — verified + KVM tests +- [x] REX.R (ModR/M reg extension) — verified + KVM tests +- [x] REX.X (SIB index extension) — verified + KVM tests +- [x] REX.B (ModR/M r/m, SIB base, opcode reg extension) — verified + KVM tests +- [x] REX access to registers R8-R15, SPL/BPL/SIL/DIL — verified + KVM tests +- [x] REX on instructions that already use 64-bit default (PUSH/POP) — verified + +### 2.3 VEX Prefix (C4h 3-byte, C5h 2-byte) +- [x] 2-byte VEX (C5h): R, vvvv, L, pp — verified + KVM tests +- [x] 3-byte VEX (C4h): R, X, B, mmmmm, W, vvvv, L, pp — verified + KVM tests +- [x] VEX.vvvv field for 3rd operand or must-be-1111b check — verified +- [x] VEX.L (128 vs 256) — verified + KVM tests +- [x] #UD when VEX used with LOCK/66h/F2h/F3h/REX — verified + +### 2.4 EVEX Prefix (62h, 4 bytes) +- [x] Full EVEX field decoding (R, X, B, R', mmm, W, vvvv, pp, z, L'L, b, V', aaa) — verified and fixed: mmm 3-bit, reserved bit checks added +- [x] EVEX to 32 SIMD registers (ZMM0-ZMM31) — verified: evex_reg_idx (R':R:reg), evex_rm_reg_idx (X:B:rm), evex_vvvvv (V':vvvv) all decode to 0-31 range +- [x] EVEX.b interpretation per instruction (broadcast vs rounding vs SAE) — verified: broadcast via broadcast_f32/f64/byte helpers; embedded rounding via evex_begin_rc/evex_end_rc for core FP arithmetic + conversions +- [x] EVEX compressed displacement (disp8*N) — verified in decode_sib_evex() +- [x] #UD for reserved EVEX field values — verified: P[3]!=0 → #UD, P[10]!=1 → #UD, mmm=0/4-7 → #UD + +### 2.5 ModR/M and SIB +- [x] All 256 ModR/M byte values decoded correctly — verified + KVM tests +- [x] SIB byte decoding (scale, index, base) — verified + KVM tests +- [x] [RIP+disp32] addressing (ModR/M=00, R/M=101 in 64-bit mode) — verified + KVM tests +- [x] SIB with no index (index=100) — verified +- [x] SIB with no base (base=101, mod=00) — verified +- [N/A] 16-bit addressing modes (with 67h in 32-bit mode) — 32-bit/16-bit compat mode not fully modeled; 64-bit mode uses 67h for 32-bit addressing only + +### 2.6 Immediate and Displacement Sizes +- [x] imm8, imm16, imm32 selection per opcode — verified + KVM tests +- [x] Sign-extension of imm8 to 16/32/64-bit — verified + KVM tests +- [x] No imm64 except MOV r64,imm64 (opcode B8+rd) — verified +- [x] disp8, disp16, disp32 per addressing mode — verified + KVM tests +- [x] EVEX compressed disp8 (disp8 * element_size * vector_length/8) — verified + +### 2.7 Default Operand/Address Sizes in 64-bit Mode +- [x] Default operand size = 32 for most instructions — verified + KVM tests +- [x] Default operand size = 64 for PUSH, POP, CALL, RET, JMP near — verified, d64/f64 fixes applied +- [x] No 32-bit address/operand for stack operations in 64-bit mode — verified +- [x] 16-bit operand override (66h) still valid in 64-bit mode — verified + KVM tests +- [x] 32-bit address override (67h) in 64-bit mode — EA truncation implemented +- [x] Instructions with forced 64-bit operand (MOV CRn, SWAPGS, etc.) — verified + +--- + +## Part 3: Architectural State and Registers + +### 3.1 General-Purpose Registers +- [x] RAX-RSP, RBP, RSI, RDI (64-bit), EAX-EDI (32-bit), AX-DI (16-bit), AL-DIL (8-bit) — verified + KVM tests +- [x] R8-R15 (64/32/16/8-bit forms: R8D, R8W, R8B) — verified + KVM tests +- [x] SPL, BPL, SIL, DIL (accessible only with REX prefix) — verified + KVM tests +- [x] AH, BH, CH, DH (NOT accessible when REX prefix present) — verified +- [x] 32-bit writes zero-extend to 64-bit — verified + KVM tests +- [x] 8-bit and 16-bit writes do NOT zero-extend — verified + KVM tests + +### 3.2 RFLAGS +- [x] CF (bit 0), PF (bit 2), AF (bit 4), ZF (bit 6), SF (bit 7), OF (bit 11) — verified + KVM tests +- [x] DF (bit 10), IF (bit 9), TF (bit 8) — verified +- [x] IOPL (bits 13:12) — verified, POPF bug fixed +- [x] NT (bit 14), RF (bit 16), VM (bit 17) — verified +- [x] AC (bit 18), VIF (bit 19), VIP (bit 20), ID (bit 21) — verified, IRET bug fixed +- [x] PF set based on low 8 bits of result (even parity) — verified + KVM tests +- [x] AF set on carry out of bit 3 — verified + KVM tests +- [x] Correct "undefined" flag behavior (per SDM per instruction) — verified + +### 3.3 Instruction Pointer +- [x] RIP (64-bit), EIP (32-bit in compat mode) — verified: `register RIP : qword` in regs.sail:7 +- [x] RIP-relative addressing in 64-bit mode — verified: decode_rm() handles mod=00/rm=101 as RIP+disp32; rip_rel_pending fixup mechanism + +### 3.4 Segment Registers +- [x] CS, DS, ES, SS, FS, GS — verified: SegReg vector(6, word) in regs.sail:181, indices defined in core_types.sail +- [x] In 64-bit mode: DS/ES/SS bases forced to 0 — verified: apply_segment() only adds base for FS/GS +- [x] FS.base, GS.base (from MSRs, WRFSBASE/WRGSBASE) — implemented +- [N/A] CS selects code segment attributes (L/D bits for 64/compat mode) — mode tracked via cur_mode register; CS descriptor L/D bits not explicitly modeled (always 64-bit mode) + +### 3.5 x87 FPU Registers +- [x] ST(0)-ST(7) (80-bit extended precision) — verified: x87_ST vector, TOP-relative addressing +- [x] FPU control word (precision, rounding, exception masks) — verified: x87_cw, default 0x037F +- [x] FPU status word (TOP, condition codes C0-C3, exception flags) — verified: x87_sw, TOP at bits 13:11 +- [x] FPU tag word (valid/zero/special/empty per register) — verified: x87_tw, 2-bit tags +- [N/A] Last instruction/operand pointers — x87 FIP/FDP not modeled (no x87 exception delivery) + +### 3.6 MMX Registers +- [x] MM0-MM7 (alias to low 64 bits of ST(0)-ST(7)) — fully modeled via x87 physical registers with proper tag/TOP management + +### 3.7 SSE/AVX Registers +- [x] XMM0-XMM15 (128-bit, base SSE) — verified: ZMM vector(32, zmmword), read_xmm/write_xmm access low 128 bits +- [x] YMM0-YMM15 (256-bit, AVX) — verified: read_ymm/write_ymm access low 256 bits +- [x] XMM16-XMM31, YMM16-YMM31, ZMM0-ZMM31 (512-bit, AVX-512) — verified: simd_idx = range(0,31), all 32 registers +- [x] MXCSR (SSE control/status register) — verified: delegated to C++ externals (__ldmxcsr/__stmxcsr), rounding/FTZ/DAZ handled by host FPU + +### 3.8 Opmask Registers +- [x] k0-k7 (64-bit each in AVX-512) — verified: KREG vector(8, qword) in regs.sail:169 +- [x] k0 = always-all-ones (cannot be used as writemask) — verified: documented in regs.sail:163 comment + +### 3.9 AMX Tile Registers +- [N/A] TMM0-TMM7, TILECFG — AMX not targeted (see 1.18) + +### 3.10 Control Registers +- [x] CR0 (PE, MP, EM, TS, ET, NE, WP, AM, NW, CD, PG) — verified: all bit positions defined in regs.sail:292-303 +- [x] CR2 (page-fault linear address) — verified: register CR2 : qword, set by page fault handler +- [x] CR3 (page-directory base, PCID) — verified: register CR3 : qword, used in pt_walk for paging +- [x] CR4 (VME, PVI, TSD, DE, PSE, PAE, MCE, PGE, PCE, OSFXSR, OSXMMEXCPT, + LA57, FSGSBASE, PCIDE, OSXSAVE) — verified: bit positions defined in regs.sail:305-320; SMEP/SMAP/PKE/CET/PKS not yet modeled +- [N/A] CR8 (TPR, 64-bit mode only) — APIC task priority register not modeled +- [x] XCR0 (XSAVE feature enable) — verified: XGETBV returns 0xE7 for XCR0 + +### 3.11 Debug Registers +- [x] DR0-DR3 (breakpoint addresses) — verified: registers declared in regs.sail:285-288 +- [x] DR6 (debug status) — verified: register DR6 : qword in regs.sail:289 +- [x] DR7 (debug control) — verified: register DR7 : qword in regs.sail:290 + +### 3.12 Descriptor Table Registers +- [x] GDTR (base + limit) — verified: GDTR_base : qword, GDTR_limit : word in regs.sail:332-333 +- [x] IDTR (base + limit) — verified: IDTR_base : qword, IDTR_limit : word in regs.sail:334-335 +- [x] LDTR (selector + hidden base/limit/attributes) — verified: LDTR : word in regs.sail:336 (selector only, no hidden cache) +- [x] TR (selector + hidden base/limit/attributes) — verified: TR : word, TR_base : qword, TR_limit : dword in regs.sail:337-341 + +### 3.13 MSRs (Commonly Used) +- [x] IA32_EFER (SCE, LME, LMA, NXE) — verified: native Sail register, bit positions in regs.sail:322-326 +- [x] IA32_STAR, IA32_LSTAR, IA32_FMASK (SYSCALL/SYSRET) — verified: read via __rdmsr(0xC0000081/82/84) +- [N/A] IA32_CSTAR (compat mode SYSCALL) — compat mode not targeted +- [x] IA32_FS_BASE, IA32_GS_BASE, IA32_KERNEL_GS_BASE — verified: native Sail registers in regs.sail:191-193 +- [N/A] IA32_SYSENTER_CS/ESP/EIP — SYSENTER/SYSEXIT not targeted (see 1.25.5) +- [x] IA32_TSC, IA32_TSC_AUX — verified: TSC via __rdtsc(), TSC_AUX via __rdmsr(0xC0000103) +- [N/A] IA32_PAT (page attribute table) — memory types not modeled in sequential model +- [N/A] IA32_APIC_BASE — APIC MMIO not modeled (system emulator uses legacy PIC) +- [N/A] IA32_MISC_ENABLE — miscellaneous feature enable bits not modeled +- [N/A] IA32_XSS — supervisor XSAVE state components not modeled + +--- + +## Part 4: Memory and Addressing + +### 4.1 Addressing Modes (64-bit) +- [x] Register direct — verified in insn_modrm.sail:258-260 (modbits=11) +- [x] [reg] (all 16 GPRs as base) — verified, REX.B extends to 16 GPRs +- [x] [reg + disp8/disp32] — verified (mod=01 disp8, mod=10 disp32) +- [x] [RIP + disp32] (RIP-relative) — verified, with 67h truncation to 32-bit +- [x] [base + index*scale] (scale = 1/2/4/8) — verified in decode_sib() +- [x] [base + index*scale + disp8/disp32] — verified +- [x] [disp32] (absolute, only via SIB; zero-extended to 64-bit) — verified (SIB base=5, mod=00) +- [x] [index*scale + disp32] (no base, via SIB) — verified +- [x] RSP/R12 as base forces SIB byte — verified (r/m=100 routes to SIB decode) +- [x] RBP/R13 with mod=00 means [disp32] (no base) — verified in decode_sib() and decode_rm() + +### 4.2 Segmentation +- [N/A] Segment descriptor loading and caching — flat model assumed; FS/GS base set via MSRs +- [x] Flat model (DS/ES/SS base = 0 in 64-bit long mode) — verified in apply_segment(): only FS/GS add base +- [x] FS/GS non-zero base in 64-bit mode — verified, FS_BASE/GS_BASE added in apply_segment() +- [N/A] Segment limit checking (in compat/legacy mode) — compat/legacy mode not targeted +- [N/A] Code segment (conforming vs non-conforming) — full segment descriptor model not implemented; 64-bit flat mode assumed +- [N/A] Stack segment (SS.DPL = CPL) — SS descriptor not explicitly modeled; CPL tracked via cur_cpl register + +### 4.3 Paging +- [x] 4-level paging (PML4 → PDPT → PD → PT) — verified: pt_walk with level 3→0 recursion +- [N/A] 5-level paging (PML5, when CR4.LA57 = 1) — 5-level paging not targeted; 4-level paging sufficient for Linux boot +- [x] 4KB pages — verified: level 0 leaf, offset[11:0] +- [x] 2MB large pages (PS bit in PDE) — verified: level 1 leaf with PS=1, offset[20:0] +- [x] 1GB huge pages (PS bit in PDPTE) — verified: level 2 leaf with PS=1, offset[29:0] +- [x] Page table entry format (P, R/W, U/S, PWT, PCD, A, D, PS, G, NX) — verified: P, R/W, U/S, A, D, PS, NX checked +- [x] CR3 (page-directory base register) — verified: used in translate_addr, masked to PPN +- [N/A] PCID (process-context identifiers, CR4.PCIDE) — TLB not modeled; no caching +- [x] NX (no-execute) bit support (IA32_EFER.NXE) — verified: XD bit[63] checked when EFER.NXE=1 +- [N/A] SMEP (CR4.SMEP — supervisor can't execute user pages) — access control checks not fully modeled; Linux boots with noapic/nolapic +- [N/A] SMAP (CR4.SMAP — supervisor can't access user pages unless AC=1) — STAC/CLAC implemented but SMAP check not enforced in page walk +- [N/A] PKU (protection keys for user pages) — RDPKRU/WRPKRU return 0; PKU enforcement not modeled +- [N/A] PKS (protection keys for supervisor pages) — not modeled +- [N/A] PAT (page attribute table — memory type per page) — memory types not modeled in sequential model + +### 4.4 Memory Types and Ordering +- [N/A] All memory types (UC, WC, WT, WB, WP) and MTRR/PAT interaction — sequential model has no memory hierarchy; all accesses are immediately visible +- [N/A] Memory ordering guarantees (strong ordering, store-buffer forwarding, LOCK barriers, fence semantics) — sequential model is inherently sequentially consistent; no reordering possible + +### 4.5 Alignment +- [N/A] #AC for misaligned access at CPL=3 when CR0.AM=1 and RFLAGS.AC=1 — alignment check exception not modeled +- [N/A] #GP for misaligned LOCK'd instructions — split-lock detection not modeled +- [x] SSE: #GP for misaligned MOVAPS/MOVAPD/MOVDQA (128-bit aligned) — verified: alignment check in insn_sse_fp.sail and insn_vex_fp.sail +- [N/A] AVX-512: VMOVDQA32/64 require alignment, VMOVDQU do not — alignment checks for EVEX memory ops delegated to C++ externals +- [N/A] FXSAVE/FXRSTOR require 16-byte alignment — delegated to C++ __fxsave/__fxrstor externals +- [N/A] XSAVE requires 64-byte alignment — delegated to C++ __xsave/__xrstor externals + +--- + +## Part 5: Exceptions and Interrupts + +### 5.1 Exception Vectors +- [x] #DE (0) — divide error (DIV/IDIV) — verified: raised by DIV/IDIV, tested in system emulator +- [N/A] #DB (1) — debug exception; hardware breakpoint/single-step not modeled +- [x] NMI (2) — non-maskable interrupt — delivered through IDT like other interrupts +- [x] #BP (3) — breakpoint (INT3) — verified: INT3 delivers as software trap, tested +- [x] #OF (4) — overflow (INTO) — verified: INTO raises #UD in 64-bit mode (correct) +- [x] #BR (5) — bound range exceeded (BOUND) — verified: BOUND raises #UD in 64-bit mode (correct) +- [x] #UD (6) — invalid opcode — verified: raised throughout for invalid encodings +- [x] #NM (7) — device not available: CR0.EM/TS/MP for x87, MMX, SSE, AVX, AVX-512, the XSAVE family, FXSAVE/FXRSTOR, LDMXCSR/STMXCSR, EMMS and WAIT (exceptions.sail check_cr0_*); KVM template kvm-tests-cr0.cpp +- [x] #DF (8) — double fault — verified: escalation logic in deliver_exception(), tested +- [N/A] #TS (10) — invalid TSS; TSS validation not fully modeled +- [x] #NP (11) — segment not present — verified: raised in deliver_exception_inner for not-present gate +- [N/A] #SS (12) — stack-segment fault; stack segment limits not enforced in 64-bit mode (canonical check covers this) +- [x] #GP (13) — general protection — verified: raised for privilege violations, bad MSR, etc. with error code +- [x] #PF (14) — page fault (error code: P, W/R, U/S, RSVD, I/D) — verified in paging.sail, tested +- [N/A] #MF (16) — x87 FPU floating-point error; x87 exceptions always masked, no #MF delivery +- [N/A] #AC (17) — alignment check; not modeled (see 4.5) +- [x] #MC (18) — machine check — used as triple fault signal +- [N/A] #XM (19) — SIMD floating-point exception; SSE exceptions always masked, no #XM delivery +- [N/A] #VE (20) — virtualization exception; VMX/EPT not modeled +- [N/A] #CP (21) — control protection exception; CET not modeled +- [N/A] #HV (28) — hypervisor injection; SEV-ES not modeled +- [N/A] #VC (29) — VMM communication; SEV-ES not modeled +- [N/A] #SX (30) — security exception; not modeled + +### 5.2 Interrupt Delivery +- [x] IDT lookup (vector × 16 in 64-bit mode) — verified in read_idt_gate(), tested +- [x] Interrupt gate vs trap gate (IF clearing) — verified: type 0xE clears IF, 0xF preserves; tested +- [x] IST (Interrupt Stack Table) mechanism — verified in deliver_exception_inner(), read_tss_ist() +- [x] Error code pushing (which exceptions push error codes) — verified; fixed: software ints skip error code (SDM §6.13) +- [x] RSP alignment to 16 on interrupt stack frame — verified: `new_rsp & 0xFFF...F0`; tested +- [x] CPL change: stack switch via TSS — verified: reads RSP0 from TSS on privilege change +- [x] Same-privilege interrupt: no stack switch — verified: uses current RSP when old_cpl==0 and IST==0 + +### 5.3 Exception Conditions Per Instruction +- [x] Each instruction must raise exactly the exceptions listed in SDM — verified for #UD, #GP, #PF, #DE, #NM; #XM/#AC/#SS not modeled (see above) +- [x] #UD for invalid opcode in current mode (e.g., ARPL in 64-bit) — verified: ARPL, INTO, BOUND, PUSHA/POPA all #UD +- [x] #GP for privilege violations — verified: LGDT/LIDT/LMSW/INVLPG/RDMSR/WRMSR check CPL=0 +- [N/A] #SS for stack-segment violations — stack segment limits not enforced in 64-bit mode +- [x] #PF for page faults with correct error code — verified: P, W/R, U/S, RSVD, I/D bits in error code +- [x] #NM when CR0.EM=1 or CR0.TS=1 for x87/SSE/AVX — after every #UD the encoding decides (but for x87 and the FXSAVE/FXRSTOR opcode), before memory faults; EM=1 is #UD for MMX/legacy SSE +- [N/A] #XM or #UD based on CR4.OSXMMEXCPT for SSE exceptions — SSE exceptions always masked + +--- + +## Part 6: Processor Modes and Transitions + +### 6.1 Long Mode (64-bit) +- [x] Enabling: CR0.PG=1, CR4.PAE=1, IA32_EFER.LME=1 — system emulator boots through this sequence; cur_mode tracks 64-bit/32-bit/16-bit +- [x] 64-bit sub-mode (CS.L=1, CS.D=0) — primary operating mode, fully modeled +- [x] Compatibility sub-mode (CS.L=0; 32-bit code in long mode) — implemented; runs IA32 userspace (hello32) under the booted kernel and the KVM harness's compat-mode differential tests +- [x] Default operand/address sizes per mode — verified: d64/f64 rules for PUSH/POP/CALL/RET, 66h/67h overrides + +### 6.2 Protected Mode (Legacy 32-bit) +- [N/A] Full GDT/LDT/IDT operation — GDT/IDT base/limit loaded via LGDT/LIDT; full descriptor parsing only for TSS (LTR) and IDT gates +- [x] Privilege levels (CPL, RPL, DPL) — CPL tracked via cur_cpl register; used for privilege checks (LGDT, RDMSR, etc.) and stack switching on interrupts +- [x] Gate descriptors (interrupt gates, trap gates) — IDT gate parsing in deliver_exception_inner(); call gates and task gates not modeled + +### 6.3 Real Mode +- [x] Real mode (segment:offset, IVT, no privilege checking) — implemented; SeaBIOS executes from the reset vector and FreeDOS runs to an interactive prompt + +### 6.4 Mode Transitions +- [x] Real → Protected (set CR0.PE) — implemented; SeaBIOS boots through this transition (and unreal mode relies on the cached descriptors across it) +- [x] Protected → Long (set CR4.PAE, IA32_EFER.LME, then CR0.PG) — system emulator boots through this sequence +- [N/A] Long → Protected (clear CR0.PG, then clear IA32_EFER.LME) — not targeted +- [N/A] Far JMP/CALL to change CS.L (64-bit ↔ compat) — compat mode not targeted + +### 6.5 System Management Mode (SMM) +- [x] RSM instruction and SMRAM save state — implemented (smm.sail per SDM ch. 34, incl. SMBASE relocation and auto-HALT restart); exercised by the SeaBIOS CALL32_SMM FreeDOS boot + +--- + +## Part 7: Floating-Point Semantics (Cross-Cutting) + +### 7.1 IEEE 754 Compliance +- [x] Rounding modes: round-nearest-even, round-down, round-up, round-toward-zero — verified + KVM FP Edge tests (622+ tests) +- [x] Denormal (subnormal) number handling — verified + KVM FP Edge tests (DAZ/FTZ category) +- [x] NaN propagation rules (Intel: src1 priority for SSE MIN/MAX) — verified: f32_nan_prop/f64_nan_prop in C emulator, KVM tests +- [x] Signaling NaN vs quiet NaN behavior — verified + KVM FP Edge tests (NaN category) +- [x] Infinity arithmetic (+∞, -∞) — verified + KVM FP Edge tests (Inf category) +- [x] Signed zero (+0, -0) semantics — verified + KVM FP Edge tests (signed zeros category) +- [x] Flush-to-zero (MXCSR.FTZ) — verified + KVM FP Edge tests +- [x] Denormals-are-zeros (MXCSR.DAZ) — verified + KVM FP Edge tests + +### 7.2 FP Exception Reporting +- [N/A] FP exception flag reporting (IE, DE, ZE, OE, UE, PE) — all FP exceptions are always masked; exception flags set by host FPU via C++ externals but not explicitly checked by Sail model +- [N/A] Masked vs unmasked exception behavior — unmasked FP exceptions (#MF/#XM delivery) not modeled; all exceptions masked + +### 7.3 x87 vs SSE FP Differences +- [x] x87 uses 80-bit internal precision — verified: x87_ST stores 80-bit extended precision values +- [x] SSE uses operand precision (32 or 64-bit) — verified: SSE ops use f32/f64 via C++ externals +- [N/A] x87 exception via #MF, SSE via #XM (or #UD) — exception delivery not implemented; all FP exceptions always masked +- [x] x87 condition codes (C0-C3) vs SSE EFLAGS setting — verified: FCOM sets C0/C2/C3 in SW, COMISS sets EFLAGS + +--- + +## Part 8: Concurrency and Atomicity (Cross-Cutting) + +### 8.1 LOCK Prefix +- [x] Valid only with: ADD, ADC, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B/16B, + DEC, INC, NEG, NOT, OR, SBB, SUB, XOR, XADD, XCHG — verified: is_lockable_1byte/2byte +- [x] #UD on LOCK with any other instruction — verified: checked at dispatch entry +- [x] LOCK'd operations are atomic and act as full memory barriers — sequential model (implicit) +- [x] XCHG implicitly LOCK'd when memory operand — verified + +### 8.2 Alignment and Atomicity +- [N/A] Atomicity guarantees (naturally-aligned loads/stores, CMPXCHG16B alignment, split-lock detection) — sequential model has no concurrency; all operations are inherently atomic + +--- + +## Part 9: Instruction-Specific Behavioral Details + +These are tricky behaviors a formal spec MUST get right. + +### 9.1 Shift/Rotate Count Masking +- [x] 32-bit ops: count masked to 5 bits (& 0x1F) — verified in shift.sail +- [x] 64-bit ops: count masked to 6 bits (& 0x3F) — verified in shift.sail +- [x] OF defined only for count=1 shifts — verified +- [x] Count=0 shifts: no flags modified — verified + +### 9.2 REP String Operations +- [x] RCX=0 → no operation, no flags changed — verified in string.sail +- [x] REPE/REPNE with CMPS/SCAS: early termination on ZF mismatch — verified +- [N/A] Interruptibility between iterations — sequential model processes string ops atomically; interrupt interleaving not modeled +- [x] Address size determines whether CX/ECX/RCX is used — verified + +### 9.3 PUSH/POP RSP +- [x] PUSH RSP pushes the value of RSP before the push — verified + KVM tests +- [x] POP RSP: value popped is the new RSP (not incremented after) — verified + +### 9.4 MOV to SS +- [N/A] Inhibits interrupts for one instruction after MOV to SS — interrupt inhibition not modeled (sequential model delivers interrupts at instruction boundary only) + +### 9.5 Division +- [x] DIV: #DE if quotient overflows or divisor=0 — verified + KVM tests +- [x] IDIV: #DE if quotient overflows or divisor=0 — verified + KVM tests +- [x] 8-bit DIV: AX / src → AL quotient, AH remainder — verified +- [x] 16-bit DIV: DX:AX / src → AX quotient, DX remainder — verified +- [x] etc. for 32/64-bit — verified + +### 9.6 IMUL Forms +- [x] 1-operand: signed widening multiply (same as MUL but signed) — verified + KVM tests +- [x] 2-operand: dst = dst × src (truncated, OF/CF set if sign-extended result ≠ full result) — verified +- [x] 3-operand: dst = src × imm (truncated, same OF/CF rule) — verified + +### 9.7 BSF/BSR vs TZCNT/LZCNT +- [x] BSF/BSR: ZF=1 if source is 0, destination UNDEFINED — verified + KVM tests +- [x] TZCNT/LZCNT: CF=1 if source is 0, result = operand bit size — verified + KVM tests +- [x] On CPUs without BMI, TZCNT executes as BSF (F3 prefix ignored) — N/A (we always have BMI) +- [x] LZCNT without ABM: executes as BSR — N/A (we always have ABM) + +### 9.8 CPUID +- [x] Leaf 0: max basic leaf, vendor string — delegated to __cpuid external +- [x] Leaf 1: family/model/stepping, feature flags (ECX, EDX) — delegated to __cpuid external +- [x] Leaf 7: extended feature flags (structured) — delegated to __cpuid external +- [x] Leaf 0x80000000-0x80000008: extended leaves — delegated to __cpuid external +- [x] Must report feature bits consistent with implemented instructions — host passthrough via __cpuid +- [x] Invalid/unsupported leaves: return 0 or last valid leaf's data — handled by host CPUID + +### 9.9 NOP Width +- [x] 1-byte NOP (0x90 = XCHG EAX,EAX) — verified: special-cased in dispatch, does not zero-extend +- [x] Multi-byte NOP (0F 1F /0, various lengths up to 9 bytes) — verified: consumes ModR/M + SIB + disp +- [x] In 64-bit mode, 0x90 is NOP (not XCHG EAX,EAX which would zero-extend) — verified correct + +### 9.10 VEX/EVEX Upper-Bits Clearing +- [x] VEX-128: zero bits 255:128 of YMM — verified: write_xmm zeroes upper +- [x] VEX-256: zero bits 511:256 of ZMM (if AVX-512 supported) — verified: write_ymm zeroes 511:256 +- [x] EVEX-128: zero bits 511:128 — verified: write_xmm() initializes 512-bit reg to zeros, writes low 128 +- [x] EVEX-256: zero bits 511:256 — verified: write_ymm() initializes 512-bit reg to zeros, writes low 256 +- [x] Legacy SSE: upper bits of YMM/ZMM are PRESERVED (no zeroing) — verified: write_xmm_legacy preserves +- [x] SSE↔AVX transition penalty implications (VZEROUPPER) — verified: VZEROUPPER/VZEROALL implemented + +--- + +## Part 10: Summary Statistics + +- **Total unique mnemonics in SDM:** 1,208 +- **SDM instruction pages:** 835 (some cover multiple related mnemonics) +- **ISA extension groups:** ~30+ (from base x86-64 through AMX) + +### Rough instruction count by category: +| Category | Approx. count | +|---|---| +| General-purpose integer | ~120 | +| x87 floating-point | ~90 | +| MMX | ~50 (implemented) | +| SSE (1/2/3/SSSE3/4.1/4.2) | ~200 | +| AVX/AVX2 (VEX re-encoding of above) | (same ops, VEX form) | +| FMA | ~96 forms (4 ops × 3 orderings × 2 types × 2 sizes + packed variants) | +| AVX-512 (F/BW/DQ/CD/VL/VBMI/IFMA/VNNI/BITALG/VP2INTERSECT/etc.) | ~350+ | +| AVX-512 FP16 | ~80 (all implemented) | +| BMI1/BMI2/ADX | ~16 | +| AES-NI/SHA/GFNI/PCLMULQDQ | ~18 | +| Key Locker | ~10 | +| CET (shadow stack + IBT) | ~12 | +| AMX | ~8 | +| System (VMX/SGX/SMX/descriptors/CR/DR/MSR) | ~60 | +| TSX/XSAVE/misc | ~20 | + +--- + +## How to Use This Checklist + +For each `[ ]` item: +1. Search the Sail codebase for the instruction mnemonic or opcode +2. Verify it decodes the correct opcode bytes per SDM +3. Verify it handles all valid operand-size and addressing-mode variants +4. Verify flag effects match SDM exactly +5. Verify exception conditions match SDM (#UD in wrong mode, #GP for privilege, etc.) +6. Mark as one of: + - `[x]` Implemented and correct + - `[~]` Partially implemented (note what's missing) + - `[ ]` Not implemented + - `[N/A]` Explicitly out of scope (document why) diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail new file mode 100644 index 000000000..fa280a44e --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail @@ -0,0 +1,415 @@ +// x86-64 — Branchless bit-manipulation helpers +// +// Pure utility functions used across multiple instruction files. +// All are branch-free to support formal verification tools (Isla/SMT). + +// Branchless POPCNT +val popcount : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n) +function popcount(v) = { + let x : qword = zero_extend(v); + let x = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555); + let x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); + let x = (x & 0x0f0f0f0f0f0f0f0f) + ((x >> 4) & 0x0f0f0f0f0f0f0f0f); + let x = (x & 0x00ff00ff00ff00ff) + ((x >> 8) & 0x00ff00ff00ff00ff); + let x = (x & 0x0000ffff0000ffff) + ((x >> 16) & 0x0000ffff0000ffff); + let x = (x & 0x00000000ffffffff) + ((x >> 32) & 0x00000000ffffffff); + let x = unsigned(x); + assert(x <= 'n); + x +} + +// or_reduce: 1 if any bit is set, 0 otherwise (branchless tree reduction). +val or_reduce : forall 'n, 0 < 'n & 'n <= 512. bits('n) -> bits(1) +function or_reduce(v) = { + let x : zmmword = zero_extend(v); + let x = x | (x >> 1); + let x = x | (x >> 2); + let x = x | (x >> 4); + let x = x | (x >> 8); + let x = x | (x >> 16); + let x = x | (x >> 32); + let x = x | (x >> 64); + let x = x | (x >> 128); + let x = x | (x >> 256); + x[0] +} + +// is_nonzero: 0 if all bits are zero, 1 otherwise. +val is_nonzero : forall 'n, 0 < 'n & 'n <= 512. bits('n) -> bit +function is_nonzero(v) = or_reduce(v)[0] + +// is_zero: 1 if all bits are zero, 0 otherwise. +val is_zero : forall 'n, 0 < 'n & 'n <= 512. bits('n) -> bit +function is_zero(v) = ~(is_nonzero(v)) + +// is_eq: 1 if a == b, 0 otherwise. +val is_eq : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit +function is_eq(a, b) = is_zero(a ^ b) + +// is_gt: 1 if a > b (signed), 0 otherwise. +val is_gt : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit +function is_gt(a, b) = { + let diff : bits('n + 1) = sign_extend(b) - sign_extend(a); + diff['n] +} + +// is_gt_u: 1 if a > b (unsigned), 0 otherwise. +val is_gt_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit +function is_gt_u(a, b) = { + let diff : bits('n + 1) = zero_extend(b) - zero_extend(a); + diff['n] +} + +// is_ne: 1 if a != b, 0 otherwise. +val is_ne : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit +function is_ne(a, b) = is_nonzero(a ^ b) + +// is_lt_u: 1 if a < b (unsigned), 0 otherwise. +val is_lt_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit +function is_lt_u(a, b) = is_gt_u(b, a) + +// is_ge_u: 1 if a >= b (unsigned), 0 otherwise. +val is_ge_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit +function is_ge_u(a, b) = ~(is_gt_u(b, a)) + +// is_le_u: 1 if a <= b (unsigned), 0 otherwise. +val is_le_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit +function is_le_u(a, b) = ~(is_gt_u(a, b)) + +// Rotate left/right by a bounded integer amount. +val rotl : forall 'm 'n, 'm >= 'n >= 0. (bits('m), int('n)) -> bits('m) +function rotl(v, shift) = (v << shift) | (v >> ('m - shift)) + +val rotr : forall 'm 'n, 'm >= 'n >= 0. (bits('m), int('n)) -> bits('m) +function rotr(v, shift) = (v >> shift) | (v << ('m - shift)) + +// Branchless blend: select a or b per element based on a single bit. +// sel=0 -> a, sel=1 -> b. +val blend : forall 'n, 0 < 'n. (bits('n), bits('n), bit) -> bits('n) +function blend(a, b, sel) = { + let m : bits('n) = sign_extend(sel); + (a & ~(m)) | (b & m) +} + +// ========================================================================= +// Comparison helpers (return full-width masks) +// ========================================================================= + +// All-ones if a == b, all-zeros otherwise. +val cmp_eq : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function cmp_eq(a, b) = sign_extend(is_eq(a, b)) + +// All-ones if a > b (signed), all-zeros otherwise. +val cmp_gt : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function cmp_gt(a, b) = sign_extend(is_gt(a, b)) + +// ========================================================================= +// Min/max +// ========================================================================= + +// PSIGN: negate if b < 0, zero if b == 0, keep if b > 0. +val psign : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function psign(a, b) = { + let neg_mask : bits('n) = sign_extend(b['n - 1]); + ((a ^ neg_mask) - neg_mask) & sign_extend(is_nonzero(b)) +} + +val max_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function max_s(a, b) = blend(a, b, is_gt(b, a)) + +val min_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function min_s(a, b) = blend(a, b, is_gt(a, b)) + +val max_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function max_u(a, b) = blend(a, b, is_gt_u(b, a)) + +val min_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function min_u(a, b) = blend(a, b, is_gt_u(a, b)) + +// ========================================================================= +// Bit-scan / count helpers +// ========================================================================= + +// Branchless CLZ via smear (fill all bits below MSB) then popcount. +val clz : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n) +function clz(v) = { + let x1 : bits('n) = v | (v >> 1); + let x2 : bits('n) = x1 | (x1 >> 2); + let x3 : bits('n) = x2 | (x2 >> 4); + let x4 : bits('n) = x3 | (x3 >> 8); + let x5 : bits('n) = x4 | (x4 >> 16); + let x6 : bits('n) = x5 | (x5 >> 32); + 'n - popcount(x6) +} + +// Branchless CTZ via popcount: ctz(v) = popcount(~v & (v - 1)) +val ctz : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n) +function ctz(v) = popcount(~(v) & (v - 1)) + +// BSR (bit scan reverse): index of highest set bit = width - 1 - clz(v). +// Precondition: v != 0 (BSR is undefined for zero). +val bsr : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n - 1) +function bsr(v) = { + let x = clz(v); + assert(x < 'n); + 'n - 1 - x +} + +// ========================================================================= +// Byte manipulation +// ========================================================================= + +// BSWAP — Reverse byte order of a bitvector. +val bswap : forall 'n, 'n in {16, 32, 64}. bits('n) -> bits('n) +function bswap(v) = { + match 'n { + 16 => v[7..0] @ v[15..8], + 32 => v[7..0] @ v[15..8] @ v[23..16] @ v[31..24], + 64 => v[7..0] @ v[15..8] @ v[23..16] @ v[31..24] @ v[39..32] @ v[47..40] @ v[55..48] @ v[63..56] + } +} + +// ========================================================================= +// Absolute value, saturation arithmetic, and rounding average +// ========================================================================= + +// Branchless absolute value: mask = sign-extend of MSB; (x ^ mask) - mask +val abs : forall 'n, 'n > 0. bits('n) -> bits('n) +function abs(x) = { + let m : bits('n) = sign_extend(x['n - 1]); + (x ^ m) - m +} + +// Signed saturating add. +val sat_add_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function sat_add_s(a, b) = { + let wide : bits('n + 1) = sign_extend(a) + sign_extend(b); + let result : bits('n) = wide[('n - 1) .. 0]; + let overflow : bit = wide['n] ^ result['n - 1]; + let msb_only : bits('n) = zero_extend(0b1) << ('n - 1); + let clamp : bits('n) = msb_only ^ sign_extend(~(wide['n])); + blend(result, clamp, overflow) +} + +// Unsigned saturating add. +val sat_add_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function sat_add_u(a, b) = { + let wide : bits('n + 1) = zero_extend(a) + zero_extend(b); + wide[('n - 1) .. 0] | sign_extend(wide['n]) +} + +val sat_sub_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function sat_sub_s(a, b) = { + let wide : bits('n + 1) = sign_extend(a) - sign_extend(b); + let result : bits('n) = wide[('n - 1) .. 0]; + let overflow : bit = wide['n] ^ result['n - 1]; + let msb_only : bits('n) = zero_extend(0b1) << ('n - 1); + let clamp : bits('n) = msb_only ^ sign_extend(~(wide['n])); + blend(result, clamp, overflow) +} + +val sat_sub_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function sat_sub_u(a, b) = { + let wide : bits('n + 1) = zero_extend(a) - zero_extend(b); + wide[('n - 1) .. 0] & sign_extend(~(wide['n])) +} + +// Rounding average: (a + b + 1) >> 1 +val avg : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) +function avg(a, b) = { + let sum : bits('n + 1) = zero_extend(a) + zero_extend(b) + 1; + sum['n .. 1] +} + +// Signed saturation: clamp signed x to [-(2^(dst-1)), 2^(dst-1)-1], truncate. +val sat_s : forall 'n 'dst, 0 < 'dst & 'dst < 'n & 'n <= 64. + (implicit('dst), bits('n)) -> bits('dst) +function sat_s(dst, x) = { + let hi : bits('n) = zero_extend(ones(dst - 1)); + let lo : bits('n) = ~(hi); + min_s(max_s(x, lo), hi)[('dst - 1)..0] +} + +// Signed-to-unsigned saturation: clamp signed x to [0, 2^dst-1], truncate. +val sat_su : forall 'n 'dst, 0 < 'dst & 'dst < 'n & 'n <= 64. + (implicit('dst), bits('n)) -> bits('dst) +function sat_su(dst, x) = { + let hi : bits('n) = zero_extend(ones(dst)); + let lo : bits('n) = zeros(); + min_s(max_s(x, lo), hi)[('dst - 1)..0] +} + +// Unsigned saturation: clamp unsigned x to [0, 2^dst-1], truncate. +val sat_u : forall 'n 'dst, 0 < 'dst & 'dst < 'n & 'n <= 64. + (implicit('dst), bits('n)) -> bits('dst) +function sat_u(dst, x) = { + let hi : bits('n) = zero_extend(ones(dst)); + min_u(x, hi)[('dst - 1)..0] +} + +// PSHUFB: per-byte shuffle within a 128-bit lane. +// Each result byte is selected from src by the low 4 bits of the corresponding +// ctrl byte. If ctrl byte's high bit is set, the result byte is zero. +val pshufb : (bits(128), bits(128)) -> bits(128) +function pshufb(src, ctrl) = { + var r : bits(128) = zeros(); + foreach (i from 0 to 15) { + let lo = i * 8; + let mask : byte = velem(8, ctrl, i); + let selected : byte = velem(8, src, mask[3..0]); + r[(lo + 7)..lo] = selected & sign_extend(~(mask[7])) + }; + r +} + +// PMADDUBSW per-pair: unsigned*signed byte multiply, add adjacent, saturate to word. +val pmaddubsw_pair : (byte, byte, byte, byte) -> word +function pmaddubsw_pair(a_even, b_even, a_odd, b_odd) = { + let p1 : int = unsigned(a_even) * signed(b_even); + let p2 : int = unsigned(a_odd) * signed(b_odd); + let sum : int = p1 + p2; + let wide : bits(17) = get_slice_int(17, sum, 0); + let sign : bits(1) = wide[16]; + let of_mask : word = sign_extend(sign ^ wide[15]); + let sat : word = sign_extend(sign) ^ 0x7FFF; + (sat & of_mask) | (wide[15..0] & ~(of_mask)) +} + +// Absolute difference of unsigned bytes. +val abs_diff : forall 'n, 'n > 0. (bits('n), bits('n)) -> int +function abs_diff(a, b) = { + let d1 = (0b0 @ a) - (0b0 @ b); + let d2 = (0b0 @ b) - (0b0 @ a); + let m1 : bits('n) = sign_extend(~(d1['n])); + let m2 : bits('n) = sign_extend(~(d2['n])); + unsigned((d1['n-1..0] & m1) | (d2['n-1..0] & m2)) +} + +// PSADBW: sum of absolute differences of 8 unsigned byte pairs, zero-extended to 64 bits. +val psadbw : (bits(64), bits(64)) -> bits(64) +function psadbw(a, b) = + zero_extend(get_slice_int(16, + abs_diff(a[63..56], b[63..56]) + abs_diff(a[55..48], b[55..48]) + + abs_diff(a[47..40], b[47..40]) + abs_diff(a[39..32], b[39..32]) + + abs_diff(a[31..24], b[31..24]) + abs_diff(a[23..16], b[23..16]) + + abs_diff(a[15..8], b[15..8]) + abs_diff(a[7..0], b[7..0]), 0)) + +// FP16 <-> FP32 conversion. +val fp16_to_fp32 : bits(16) -> bits(32) +function fp16_to_fp32(h) = { + let sign : bits(1) = h[15..15]; + let exp5 : bits(5) = h[14..10]; + let frac10 : bits(10) = h[9..0]; + let inf_nan : bit = is_eq(exp5, 0b11111); + let zero_exp : bit = is_eq(exp5, 0b00000); + let frac_nz : bit = is_nonzero(frac10); + let normal_body : bits(31) = (zero_extend(exp5) + 0x70) @ frac10 @ 0b0000000000000; + let lz = clz(frac10); + let denorm_body : bits(31) = + to_bits(8, 112 - lz) @ (frac10 << (lz + 1)) @ 0b0000000000000; + let infnan_body : bits(31) = 0xFF @ frac10 @ 0b0000000000000; + let body : bits(31) = blend(normal_body, denorm_body, zero_exp & frac_nz); + let body : bits(31) = blend(body, zeros(), zero_exp & ~(frac_nz)); + let body : bits(31) = blend(body, infnan_body, inf_nan); + sign @ body +} + +val fp32_to_fp16 : (bits(32), bits(2)) -> bits(16) +function fp32_to_fp16(f, rc) = { + let sign : bits(1) = f[31..31]; + let exp8 : bits(8) = f[30..23]; + let frac23 : bits(23) = f[22..0]; + let is_inf_nan : bit = is_eq(exp8, 0xFF); + let is_overflow : bit = is_gt_u(exp8, 0x8E) & ~(is_inf_nan); + // Tiny results are converted to denormals with the selected rounding + // (SDM VCVTPS2PH: "Underflow results (i.e., tiny results) are converted + // to denormals. MXCSR.FTZ is ignored."; Vol.1 §4.8.4). Values below + // 2^-25, half the smallest half-precision denormal, including zero and + // single-precision denormals, are handled through the sticky bit alone. + let input_zero : bit = is_zero(exp8) & ~(is_nonzero(frac23)); + let is_tiny : bit = is_lt_u(exp8, 0x66) & ~(input_zero); + let is_denorm_out : bit = is_lt_u(exp8, 0x71) & is_ge_u(exp8, 0x66); + let norm_top15 : bits(15) = (exp8 - 0x70)[4..0] @ frac23[22..13]; + let norm_round : bit = frac23[12]; + let norm_sticky : bit = is_nonzero(frac23[11..0]); + let shift_amt = unsigned(0x71 - exp8); + let shifted : bits(37) = ((0b1 @ frac23) @ 0b0000000000000) >> shift_amt; + let denorm_top15 : bits(15) = 0b00000 @ shifted[35..26]; + let denorm_round : bit = shifted[25]; + let denorm_sticky : bit = is_nonzero(shifted[24..0]); + let below : bit = is_tiny | input_zero; + let top15 : bits(15) = blend(blend(norm_top15, denorm_top15, is_denorm_out), zeros(), below); + let round_bit : bit = ((norm_round & ~(is_denorm_out)) | (denorm_round & is_denorm_out)) & ~(below); + let sticky_bit : bit = ((norm_sticky & ~(is_denorm_out)) | (denorm_sticky & is_denorm_out) | is_tiny) & ~(input_zero); + let rs : bit = round_bit | sticky_bit; + let rne_up : bit = round_bit & (sticky_bit | top15[0]); + let down_up : bit = sign[0] & rs; + let up_up : bit = ~(sign[0]) & rs; + let lo : bit = (rne_up & ~(rc[0])) | (down_up & rc[0]); + let hi : bit = (up_up & ~(rc[0])); + let round_up : bit = (lo & ~(rc[1])) | (hi & rc[1]); + let result15 : bits(15) = top15 + zero_extend(round_up); + // An overflow rounds to infinity, or to the largest finite value when the + // rounding direction excludes infinity: toward zero, or toward the side + // opposite the result's sign (Vol.1 §4.8.4, Table 4-9). + let saturate : bit = is_eq(rc, 0b11) | (is_eq(rc, 0b01) & ~(sign[0])) | (is_eq(rc, 0b10) & sign[0]); + let overflow15 : bits(15) = blend(0b11111 @ zeros(10), 0b11110 @ ones(10), saturate); + let body : bits(15) = blend(result15, overflow15, is_overflow); + let body : bits(15) = blend(body, 0b11111 @ frac23[22..13], is_inf_nan); + sign @ body +} + +// Multiply high with rounding and scale: ((a*b) >> (n-2) + 1) >> 1 +val mulhrs : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) +function mulhrs(a, b) = { + let prod : bits('n * 2) = to_bits_truncate(signed(a) * signed(b)); + let shifted = prod >>> ('n - 2); + let rounded : bits('n * 2) = to_bits_truncate(signed(shifted) + 1); + (rounded >>> 1)[('n - 1)..0] +} + +// ========================================================================= +// GFNI primitives (GF(2^8) with irreducible polynomial x^8+x^4+x^3+x+1) +// ========================================================================= + +val gf2p8_mul : (byte, byte) -> byte +function gf2p8_mul(a, b) = { + var result : bits(9) = zeros(); + var aa : bits(9) = zero_extend(a); + foreach (i from 0 to 7) { + result = result ^ (sign_extend(b[i..i]) & aa); + aa = aa << 1; + aa = aa ^ (sign_extend(aa[8]) & 0b100011011) // 0x11B + }; + result[7..0] +} + +val gf2p8_affine : (byte, qword, byte) -> byte +function gf2p8_affine(src, matrix, imm8) = { + var r : byte = zeros(); + foreach (i from 0 to 7) { + let row_lo : range(0, 56) = (7 - i) * 8; + let row : byte = matrix[(row_lo + 7)..row_lo]; + let product : byte = src & row; + let x4 : bits(4) = product[7..4] ^ product[3..0]; + let x2 : bits(2) = x4[3..2] ^ x4[1..0]; + let bit : bit = (x2[1] ^ x2[0])[0]; + r[i] = bit ^ imm8[i]; + }; + r +} + +val gf2p8_inv : byte -> byte +function gf2p8_inv(x) = { + let x2 = gf2p8_mul(x, x); + let x3 = gf2p8_mul(x2, x); + let x6 = gf2p8_mul(x3, x3); + let x12 = gf2p8_mul(x6, x6); + let x15 = gf2p8_mul(x12, x3); + let x30 = gf2p8_mul(x15, x15); + let x60 = gf2p8_mul(x30, x30); + let x63 = gf2p8_mul(x60, x3); + let x126 = gf2p8_mul(x63, x63); + let x252 = gf2p8_mul(x126, x126); + gf2p8_mul(x252, x2) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail new file mode 100644 index 000000000..99ef5078b --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail @@ -0,0 +1,130 @@ +// x86-64 — Core Types + +// Operand size in bits. Used throughout the model to select register +// and memory access widths. Replaces a dedicated enum so that subset +// types like {16, 32, 64} work naturally with Sail's type system. +type operand_size = {8, 16, 32, 64} + +// Address sizes for memory operands. +type address_size = {16, 32, 64} + +// Processor operating modes. +enum ProcessorMode = { + RealMode, + ProtectedMode, + Virtual8086Mode, + CompatibilityMode, + LongMode, +} + +// Current privilege level. +type cpl_t = range(0, 3) + +// Common byte/word/dword/qword types. +type byte = bits(8) +type word = bits(16) +type dword = bits(32) +type qword = bits(64) +type fp80 = bits(80) +type xmmword = bits(128) +type ymmword = bits(256) +type zmmword = bits(512) + +// Access type for page table permission checks. +// PT_Implicit models the "implicit supervisor" accesses the CPU makes +// when reading descriptor tables (GDT/LDT/IDT/TSS) — per SDM Vol.3A §4.6 +// these bypass the U/S page-protection check regardless of the current +// CPL, so a CPL=3 `MOV GS, sel` can load a descriptor out of a kernel- +// mapped GDT without faulting. +// Implicit writes (descriptor accessed bits) also bypass U/S, but obey CR0.WP. +enum PTAccess = { PT_Read, PT_Write, PT_Execute, PT_Implicit, PT_ImplicitWrite } + +// Index into the 16 general-purpose registers (0..15). +type gpr_idx = range(0, 15) + +// GPR reference: register index + REX context (needed for 8-bit AH/SPL distinction). +struct GPRRef = { + gpr_idx : gpr_idx, + has_rex : bool, +} + +// Index into the segment register file (0..5: ES, CS, SS, DS, FS, GS). +type segreg_idx = range(0, 5) +let ES : segreg_idx = 0 +let CS : segreg_idx = 1 +let SS : segreg_idx = 2 +let DS : segreg_idx = 3 +let FS : segreg_idx = 4 +let GS : segreg_idx = 5 + +// Memory reference: segment + linear/effective address. +// Every x86 memory access is relative to a segment. +struct MemRef = { + seg : segreg_idx, + addr : qword, +} + +// Segment descriptor cache (hidden part of segment registers). +// Per SDM Vol.3A §3.4.3, each segment register has a visible part +// (16-bit selector) and a hidden part loaded from the GDT/LDT descriptor. +struct SegDescCache = { + seg_base : qword, // linear base address + seg_limit : dword, // segment limit (byte-granular after scaling) + seg_type : bits(4), // type field (code/data, R/W, accessed, etc.) + seg_s : bit, // descriptor type: 0=system, 1=code/data + seg_dpl : range(0, 3), // descriptor privilege level + seg_present : bit, // segment present + seg_db : bit, // D/B bit (default operation size) + seg_l : bit, // L bit (64-bit code segment) + seg_g : bit, // granularity (0=byte, 1=4KB) +} + +// Default segment descriptor cache for real mode: +// base=0, limit=0xFFFF, present, data R/W, DPL=0 +val default_seg_desc_cache : unit -> SegDescCache +function default_seg_desc_cache() = struct { + seg_base = 0x0000000000000000, + seg_limit = 0x0000FFFF, + seg_type = 0x3, // data, R/W, accessed + seg_s = 0b1, // code/data + seg_dpl = 0, + seg_present = 0b1, + seg_db = 0b0, // 16-bit default + seg_l = 0b0, + seg_g = 0b0, // byte granularity +} + +// Exception class for double-fault escalation (SDM Vol.3 Table 7-4). +enum ExceptionClass = { EC_Benign, EC_Contributory, EC_PageFault } + +// How an event reaches the IDT. Only an exception carries an error code +// (SDM Vol.3A Table 7-1, §7.13: the error code belongs to "an exception +// condition") and sets RF in the pushed RFLAGS image; only a software +// interrupt (INT n, INT3, INTO) is subject to the gate DPL check +// (§7.12.1.1). An external interrupt is neither, whatever its vector: +// IRQ0 at vector 8 (the 8259 default the BIOS leaves in place) is an +// interrupt, not #DF, and pushes no error code. +enum EventKind = { EV_Exception, EV_SoftwareInt, EV_ExternalInt } + +// Exception/interrupt vector numbers. +type exception_vector = range(0, 255) + +// Standard x86 exceptions. +let EXN_DE : exception_vector = 0 // Divide Error +let EXN_DB : exception_vector = 1 // Debug +let EXN_NMI : exception_vector = 2 // Non-Maskable Interrupt +let EXN_BP : exception_vector = 3 // Breakpoint +let EXN_OF : exception_vector = 4 // Overflow +let EXN_BR : exception_vector = 5 // BOUND Range Exceeded +let EXN_UD : exception_vector = 6 // Invalid Opcode +let EXN_NM : exception_vector = 7 // Device Not Available +let EXN_DF : exception_vector = 8 // Double Fault +let EXN_TS : exception_vector = 10 // Invalid TSS +let EXN_NP : exception_vector = 11 // Segment Not Present +let EXN_SS : exception_vector = 12 // Stack-Segment Fault +let EXN_GP : exception_vector = 13 // General Protection +let EXN_PF : exception_vector = 14 // Page Fault +let EXN_MF : exception_vector = 16 // x87 FPU Error +let EXN_AC : exception_vector = 17 // Alignment Check +let EXN_MC : exception_vector = 18 // Machine Check +let EXN_XM : exception_vector = 19 // SIMD Floating-Point diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail new file mode 100644 index 000000000..f4f28e7df --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail @@ -0,0 +1,140 @@ +// x86-64 — Exception Handling + +// Sail exception type for faults raised during decode/execute. +// Caught by step() and stored in fault registers. +union exception = { + Fault : (exception_vector, dword), + VMExit : (dword, qword), // (exit_reason, exit_qualification) + // An x87 stack fault with the invalid-operation exception unmasked. It + // ends the x87 instruction without delivering an exception; the #MF + // waits for the next waiting x87 instruction (dispatch_x87). + X87Unmasked : unit, +} + +// System state — tracks whether the CPU is running, halted, or handling a syscall. +enum SystemState = { SysRunning, SysHalted, SysSyscall } +register system_state : SystemState + +// Fault registers — set by step() when an exception is caught. +// The C++ harness reads these to determine the fault disposition. +register fault_pending : bool +register fault_vector : exception_vector +register fault_error_code : dword + +// Raise #GP(0) — the most common fault. +val raise_GP0 : forall ('a : Type). unit -> 'a +function raise_GP0() = { + throw Fault(EXN_GP, 0x00000000); + exit() // never reached; satisfies type checker +} + +// Raise #GP with a selector error code. +val raise_GP : forall ('a : Type). dword -> 'a +function raise_GP(sel) = { + throw Fault(EXN_GP, sel); + exit() // never reached; satisfies type checker +} + +// Raise #UD — invalid opcode. +val raise_UD : forall ('a : Type). unit -> 'a +function raise_UD() = { + throw Fault(EXN_UD, 0x00000000); + exit() // never reached; satisfies type checker +} + +// Raise #SS(0) — stack segment fault. +val raise_SS0 : forall ('a : Type). unit -> 'a +function raise_SS0() = { + throw Fault(EXN_SS, 0x00000000); + exit() // never reached; satisfies type checker +} + +// Raise #DE — divide error. +val raise_DE : forall ('a : Type). unit -> 'a +function raise_DE() = { + throw Fault(EXN_DE, 0x00000000); + exit() // never reached; satisfies type checker +} + +// Raise #BR — BOUND range exceeded. +val raise_BR : forall ('a : Type). unit -> 'a +function raise_BR() = { + throw Fault(EXN_BR, 0x00000000); + exit() // never reached; satisfies type checker +} + +// Raise #NM — device not available. +val raise_NM : forall ('a : Type). unit -> 'a +function raise_NM() = { + throw Fault(EXN_NM, 0x00000000); + exit() // never reached; satisfies type checker +} + +// CR0.EM and CR0.TS (SDM Vol.3A §2.5; APM Vol.2 §3.1.1). An OS sets TS +// on a task switch and saves the x87, MMX and SIMD state of the old task +// only when the new one first uses it, on the #NM; EM says there is no +// x87 FPU. +// +// #UD and #NM are both faults from decoding the instruction, in one class +// whose internal order the manuals leave open: "Faults from Decoding the +// Next Instruction ... Invalid Opcode (#UD), Coprocessor Not Available +// (#NM)", and "the priority of events within a class is +// implementation-dependent" (SDM Vol.3A §7.9, Table 7-2, class 9); +// "interrupt prioritization within a group is implementation dependent" +// (APM Vol.2 §8.5, Table 8-9, group 6). The model's choice is to raise +// every #UD the encoding or the enabled state decides first: an undefined +// opcode, prefix, ModR/M.reg extension or r/m form, a VSIB operand without +// a SIB byte, register operands an instruction forbids, a CPUID feature +// the processor lacks, AVX or AVX-512 state disabled in XCR0, an undefined +// x87 form. So the checks come after the decoder's (the tables of +// insn_dispatch.sail, vex_check_form, evex_check_form, x87_undefined). +// Both come before the instruction touches its operands: Table 7-2 "does +// not specify the prioritization of faults that arise during instruction +// execution" (#GP, #SS, #PF, #AC), which follow the decoding, and the +// APM puts those in group 7, below group 6. +// +// PAUSE, PREFETCHh, SFENCE, LFENCE, MFENCE, MOVNTI, CLFLUSH, CRC32 and +// POPCNT (SDM Vol.3A §2.5) and the VEX-encoded general-purpose +// instructions (BMI1, BMI2: Vol.2A §2.6.1, Type 13) are not affected. + +// MMX and legacy-encoded SSE instructions, LDMXCSR, STMXCSR and EMMS: #UD +// if EM = 1, whatever TS; else #NM if TS = 1. SDM Vol.3A §2.5: "If the EM +// flag is set, the setting of the TS flag has no effect on the execution +// of x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instructions" (Table 15-1 for +// MMX, Table 16-1 for SSE; the exception classes of Vol.2A §2.5; the EMMS +// page). APM Vol.2 §3.1.1: EM "forces an invalid-opcode exception (#UD) +// when an attempt is made to execute any of the 64-bit or 128-bit media +// instructions", TS an #NM, whose order is open (§8.5, Table 8-9, group +// 6); the model takes the SDM's. +val check_cr0_sse : unit -> unit +function check_cr0_sse() = { + if CR0[2] == 0b1 then raise_UD(); // EM + if CR0[3] == 0b1 then raise_NM() // TS +} + +// The VEX- and EVEX-encoded SIMD instructions, the opmask instructions, +// and XSAVE, XRSTOR, XSAVEOPT, XSAVEC, XSAVES and XRSTORS: #NM if TS = 1. +// EM does not affect them in the SDM: its VEX classes name it only as +// "Legacy SSE instruction: If CR0.EM[bit 2] = 1" (Vol.2A §2.5, Type 5, +// Table 2-22) or not at all (Types 6, 8 and 12), the EVEX Types E1-E12 +// (§2.8) and the opmask Types K20 and K21 (§2.9) not at all, and neither +// manual's XSAVE pages name it. The APM's #UD for "any SSE instruction +// (uses ZMM/YMM/XMM registers) ... when CR0.EM = 1" (Vol.2 §8.2.7), and +// for AVX-512 under "CR0.EM = 1" (Vol.4 §3.2.1), is a fault of one manual +// only, which the model does not raise. +val check_cr0_ts : unit -> unit +function check_cr0_ts() = if CR0[3] == 0b1 then raise_NM() + +// x87 instructions (Vol.3A Table 2-2), FXSAVE and FXRSTOR: #NM if EM = 1 +// or TS = 1. FXSAVE and FXRSTOR: "#NM If CR0.TS[bit 3] = 1. If +// CR0.EM[bit 2] = 1." (SDM Vol.2A FXSAVE, FXRSTOR); "setting EM to 1 +// forces an invalid-opcode exception (#UD) when an attempt is made to +// execute any of the 64-bit or 128-bit media instructions except the +// FXSAVE and FXRSTOR instructions. Attempting to execute these +// instructions when EM is set results in an #NM exception instead" (APM +// Vol.2 §3.1.1). That is the rule of the two instructions, NP 0F AE /0 +// and /1 with a memory operand; their opcode under a 66, F2 or F3 prefix, +// or VEX- or EVEX-encoded, is no instruction and takes the #UD of the +// decoder. WAIT/FWAIT has a rule of its own (opcode 9B). +val check_cr0_x87 : unit -> unit +function check_cr0_x87() = if CR0[2] == 0b1 | CR0[3] == 0b1 then raise_NM() diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail new file mode 100644 index 000000000..dbc9290a7 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail @@ -0,0 +1,489 @@ +// x86-64 — External Function Declarations +// +// All functions provided by the execution environment (C/C++ harness). + +// ========================================================================= +// Memory primitives +// ========================================================================= + +// Raw physical memory read/write. Size parameter 'n is in bits. +val __read_mem : forall 'n, 'n > 0. (qword, int('n)) -> bits('n) +val __write_mem : forall 'n, 'n > 0. (qword, int('n), bits('n)) -> unit + +// Slow-path for page-crossing accesses (each byte translated separately). +val __mem_read_crossing : forall 'n, 'n > 0. (qword, int('n), PTAccess) -> bits('n) +val __mem_write_crossing : forall 'n, 'n > 0. (qword, int('n), bits('n)) -> unit + +// Software TLB (purely an optimization; removing does not affect correctness). +val __tlb_lookup : (qword, bool) -> option(qword) +val __tlb_insert : (qword, qword, bool) -> unit +val __tlb_flush : unit -> unit + +// ========================================================================= +// System +// ========================================================================= + +val __rdtsc : unit -> qword +val __rdrand64 : unit -> (qword, bit) +val __rdseed64 : unit -> (qword, bit) + +// MSR read/write — implemented in C++ as a key-value store +val __rdmsr : dword -> qword +val __wrmsr : (dword, qword) -> unit + +// SDM Vol.3A 13.8.6.1: CR8 aliases the enabled local APIC's TPR[7:4]. +val __read_cr8 : unit -> bits(4) +val __write_cr8 : bits(4) -> unit + +val __syscall : (qword, qword) -> unit + +val __software_interrupt : byte -> unit + +// Check for and acknowledge a pending external interrupt. +// Returns the vector number, or -1 if no interrupt pending. +val __check_pending_irq : unit -> int + +// Check if an SMI is pending (set by emulator on port 0xB2 write). +val __check_pending_smi : unit -> bool + +val __wait : unit -> unit + +// ========================================================================= +// I/O ports +// ========================================================================= + +val __port_in8 : word -> byte +val __port_in16 : word -> word +val __port_in32 : word -> dword + +val __port_out8 : (word, byte) -> unit +val __port_out16 : (word, word) -> unit +val __port_out32 : (word, dword) -> unit + +// ========================================================================= +// MXCSR +// ========================================================================= + +val __ldmxcsr : dword -> unit +val __stmxcsr : unit -> dword + +// ========================================================================= +// FP enums +// ========================================================================= + +enum FPCompareResult = { FP_GT, FP_LT, FP_EQ, FP_UNORDERED } + +enum FPClass = { + FP_Unsupported, + FP_NaN, + FP_Normal, + FP_Infinity, + FP_Zero, + FP_Empty, + FP_Denormal +} + +// ========================================================================= +// Single precision (f32) +// ========================================================================= + +val __f32_add : (dword, dword) -> dword +val __f32_sub : (dword, dword) -> dword +val __f32_mul : (dword, dword) -> dword +val __f32_div : (dword, dword) -> dword +val __f32_sqrt : dword -> dword +val __f32_min : (dword, dword) -> dword +val __f32_max : (dword, dword) -> dword +val __f32_rsqrt : dword -> dword +val __f32_rcp : dword -> dword + +// ========================================================================= +// Double precision (forced64) +// ========================================================================= + +val __f64_add : (qword, qword) -> qword +val __f64_sub : (qword, qword) -> qword +val __f64_mul : (qword, qword) -> qword +val __f64_div : (qword, qword) -> qword +val __f64_sqrt : qword -> qword +val __f64_min : (qword, qword) -> qword +val __f64_max : (qword, qword) -> qword + +// ========================================================================= +// FP comparison +// ========================================================================= + +val __f32_compare : (dword, dword) -> FPCompareResult +val __f64_compare : (qword, qword) -> FPCompareResult +val __f16_compare : (word, word) -> FPCompareResult + +// ========================================================================= +// FP conversions: int <-> float +// ========================================================================= + +val __int32_to_f64 : dword -> qword +val __int64_to_f64 : qword -> qword +val __int32_to_f32 : dword -> dword +val __int64_to_f32 : qword -> dword +val __f64_to_int32 : qword -> dword +val __f64_to_int64 : qword -> qword +val __f32_to_int32 : dword -> dword +val __f32_to_int64 : dword -> qword +val __f64_to_int32_trunc : qword -> dword +val __f64_to_int64_trunc : qword -> qword +val __f32_to_int32_trunc : dword -> dword +val __f32_to_int64_trunc : dword -> qword + +// ========================================================================= +// FP conversions: unsigned int <-> float +// ========================================================================= + +val __uint32_to_f32 : dword -> dword +val __uint64_to_f32 : qword -> dword +val __uint32_to_f64 : dword -> qword +val __uint64_to_f64 : qword -> qword +val __f32_to_uint32 : dword -> dword +val __f32_to_uint64 : dword -> qword +val __f64_to_uint32 : qword -> dword +val __f64_to_uint64 : qword -> qword +val __f32_to_uint32_trunc : dword -> dword +val __f32_to_uint64_trunc : dword -> qword +val __f64_to_uint32_trunc : qword -> dword +val __f64_to_uint64_trunc : qword -> qword + +// ========================================================================= +// FP conversions: float <-> float +// ========================================================================= + +val __f64_to_f32 : qword -> dword +val __f32_to_f64 : dword -> qword + +// ========================================================================= +// FP rounding (SSE4.1 ROUNDPS/ROUNDPD/ROUNDSS/ROUNDSD) +// ========================================================================= + +val __f32_round : (dword, byte) -> dword +val __f64_round : (qword, byte) -> qword + +// ========================================================================= +// FMA: fused multiply-add +// ========================================================================= + +val __f32_fmadd : (dword, dword, dword) -> dword +val __f32_fmsub : (dword, dword, dword) -> dword +val __f32_fnmadd : (dword, dword, dword) -> dword +val __f32_fnmsub : (dword, dword, dword) -> dword +val __f64_fmadd : (qword, qword, qword) -> qword +val __f64_fmsub : (qword, qword, qword) -> qword +val __f64_fnmadd : (qword, qword, qword) -> qword +val __f64_fnmsub : (qword, qword, qword) -> qword + +// ========================================================================= +// AVX-512 FP special +// ========================================================================= + +// VSCALEF: result = src1 * 2^(floor(src2)) +val __f32_scalef : (dword, dword) -> dword +val __f64_scalef : (qword, qword) -> qword + +// VGETEXP: extract unbiased exponent as FP value +val __f32_getexp : dword -> dword +val __f64_getexp : qword -> qword + +// VRCP14: approximate reciprocal (14-bit precision) +val __f32_rcp14 : dword -> dword +val __f64_rcp14 : qword -> qword + +// VRSQRT14: approximate reciprocal square root (14-bit precision) +val __f32_rsqrt14 : dword -> dword +val __f64_rsqrt14 : qword -> qword + +// VRNDSCALE: round to specified number of fraction bits +val __f32_rndscale : (dword, byte) -> dword +val __f64_rndscale : (qword, byte) -> qword + +// VGETMANT: extract mantissa as FP value +val __f32_getmant : (dword, byte) -> dword +val __f64_getmant : (qword, byte) -> qword + +// VREDUCE: reduce FP value +val __f32_reduce : (dword, byte) -> dword +val __f64_reduce : (qword, byte) -> qword + +// VFIXUPIMM: fix up special FP values +val __f32_fixupimm : (dword, dword, dword, byte) -> dword +val __f64_fixupimm : (qword, qword, qword, byte) -> qword + +// VDPBF16PS: BF16 dot product element (dst += bf16_hi*bf16_hi + bf16_lo*bf16_lo) +val __vdpbf16ps_elem : (dword, dword, dword) -> dword + +// ========================================================================= +// Half precision (f16) — AVX-512 FP16 +// ========================================================================= + +val __f16_add : (word, word) -> word +val __f16_sub : (word, word) -> word +val __f16_mul : (word, word) -> word +val __f16_div : (word, word) -> word +val __f16_sqrt : word -> word +val __f16_min : (word, word) -> word +val __f16_max : (word, word) -> word + +// FP16 FMA +val __f16_fmadd : (word, word, word) -> word +val __f16_fmsub : (word, word, word) -> word +val __f16_fnmadd : (word, word, word) -> word +val __f16_fnmsub : (word, word, word) -> word + +// FP16 conversions +val __f16_to_f32 : word -> dword +val __f32_to_f16 : dword -> word +val __f16_to_f64 : word -> qword +val __f64_to_f16 : qword -> word +val __f16_to_int32 : word -> dword +val __f16_to_int64 : word -> qword +val __f16_to_int32_trunc : word -> dword +val __f16_to_int64_trunc : word -> qword +val __int32_to_f16 : dword -> word +val __int64_to_f16 : qword -> word +val __f16_to_uint32 : word -> dword +val __f16_to_uint64 : word -> qword +val __f16_to_uint32_trunc : word -> dword +val __f16_to_uint64_trunc : word -> qword +val __uint32_to_f16 : dword -> word +val __uint64_to_f16 : qword -> word +val __f16_to_int16 : word -> word +val __f16_to_int16_trunc : word -> word +val __int16_to_f16 : word -> word +val __f16_to_uint16 : word -> word +val __f16_to_uint16_trunc : word -> word +val __uint16_to_f16 : word -> word + +// FP16 special operations +val __f16_scalef : (word, word) -> word +val __f16_getexp : word -> word +val __f16_rcp : word -> word +val __f16_rsqrt : word -> word +val __f16_rndscale : (word, byte) -> word +val __f16_getmant : (word, byte) -> word +val __f16_reduce : (word, byte) -> word + +// ========================================================================= +// KNL: VRCP28/VRSQRT28/VEXP2 +// ========================================================================= + +val __f32_rcp28 : dword -> dword +val __f64_rcp28 : qword -> qword +val __f32_rsqrt28 : dword -> dword +val __f64_rsqrt28 : qword -> qword +val __f32_exp2 : dword -> dword +val __f64_exp2 : qword -> qword + +// ========================================================================= +// x87 extended precision (f80) +// ========================================================================= + +// Arithmetic +val __f80_add : (fp80, fp80) -> fp80 +val __f80_sub : (fp80, fp80) -> fp80 +val __f80_mul : (fp80, fp80) -> fp80 +val __f80_div : (fp80, fp80) -> fp80 +val __f80_sqrt : fp80 -> fp80 +val __f80_abs : fp80 -> fp80 +val __f80_chs : fp80 -> fp80 +val __f80_compare : (fp80, fp80) -> FPCompareResult + +// Conversions to/from 80-bit extended precision +val __f80_from_f32 : dword -> fp80 +val __f80_from_f64 : qword -> fp80 +val __f80_to_f32 : fp80 -> dword +val __f80_to_f64 : fp80 -> qword +val __f80_from_int16 : word -> fp80 +val __f80_from_int32 : dword -> fp80 +val __f80_from_int64 : qword -> fp80 +val __f80_to_int16 : fp80 -> word +val __f80_to_int32 : fp80 -> dword +val __f80_to_int64 : fp80 -> qword +val __f80_to_int16_trunc : fp80 -> word +val __f80_to_int32_trunc : fp80 -> dword +val __f80_to_int64_trunc : fp80 -> qword + +// Constants +val __f80_zero : unit -> fp80 +val __f80_one : unit -> fp80 +val __f80_log2_10 : unit -> fp80 +val __f80_log2_e : unit -> fp80 +val __f80_pi : unit -> fp80 +val __f80_log10_2 : unit -> fp80 +val __f80_ln_2 : unit -> fp80 + +// Classification +val __f80_classify : fp80 -> FPClass + +// Decomposition (used by FXTRACT) +val __f80_extract_exponent : fp80 -> fp80 +val __f80_extract_significand : fp80 -> fp80 + +// Transcendental operations +val __f80_yl2x : (fp80, fp80) -> fp80 +val __f80_yl2xp1 : (fp80, fp80) -> fp80 +val __f80_sin : fp80 -> fp80 +val __f80_cos : fp80 -> fp80 +val __f80_tan : fp80 -> fp80 +val __f80_atan2 : (fp80, fp80) -> fp80 +val __f80_2xm1 : fp80 -> fp80 +val __f80_scale : (fp80, fp80) -> fp80 +// FPREM and FPREM1 of (ST(0), ST(1)): the remainder, or the partial +// remainder of their Operation for exponents 64 or more apart, in bits +// 79..0, and Q0, Q1, Q2 of the quotient and C2 (the reduction is +// incomplete) in bits 80..83, all 0 for a NaN result. +val __f80_prem : (fp80, fp80) -> bits(84) +val __f80_prem1 : (fp80, fp80) -> bits(84) +val __f80_round : fp80 -> fp80 + +// BCD conversions (for FBLD/FBSTP) +val __f80_from_bcd : fp80 -> fp80 +val __f80_to_bcd : fp80 -> fp80 + +// ========================================================================= +// Polymorphic FP wrappers (dispatch by bitvector width) +// ========================================================================= + +// Unary +// {8,16,32,64,80} — has f80 extern +val fp_sqrt : forall 'n, 'n in {8, 16, 32, 64, 80}. bits('n) -> bits('n) +function fp_sqrt(x) = match 'n { + 8 => unreachable(), 16 => __f16_sqrt(x), 32 => __f32_sqrt(x), 64 => __f64_sqrt(x), 80 => __f80_sqrt(x) +} + +// {8,16,32,64} — no f80 extern +val fp_getexp : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_getexp(x) = match 'n { + 8 => unreachable(), 16 => __f16_getexp(x), 32 => __f32_getexp(x), 64 => __f64_getexp(x) +} + +val fp_rcp : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_rcp(x) = match 'n { + 8 => unreachable(), 64 => unreachable(), 16 => __f16_rcp(x), 32 => __f32_rcp(x) +} + +val fp_rsqrt : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_rsqrt(x) = match 'n { + 8 => unreachable(), 64 => unreachable(), 16 => __f16_rsqrt(x), 32 => __f32_rsqrt(x) +} + +val fp_rcp14 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_rcp14(x) = match 'n { + 8 => unreachable(), 16 => unreachable(), 32 => __f32_rcp14(x), 64 => __f64_rcp14(x) +} + +val fp_rsqrt14 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_rsqrt14(x) = match 'n { + 8 => unreachable(), 16 => unreachable(), 32 => __f32_rsqrt14(x), 64 => __f64_rsqrt14(x) +} + +val fp_rcp28 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_rcp28(x) = match 'n { + 8 => unreachable(), 16 => unreachable(), 32 => __f32_rcp28(x), 64 => __f64_rcp28(x) +} + +val fp_rsqrt28 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_rsqrt28(x) = match 'n { + 8 => unreachable(), 16 => unreachable(), 32 => __f32_rsqrt28(x), 64 => __f64_rsqrt28(x) +} + +val fp_exp2 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) +function fp_exp2(x) = match 'n { + 8 => unreachable(), 16 => unreachable(), 32 => __f32_exp2(x), 64 => __f64_exp2(x) +} + +// Binary — {8,16,32,64,80} where f80 extern exists +val fp_add : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) +function fp_add(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_add(a, b), 32 => __f32_add(a, b), 64 => __f64_add(a, b), 80 => __f80_add(a, b) +} + +val fp_sub : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) +function fp_sub(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_sub(a, b), 32 => __f32_sub(a, b), 64 => __f64_sub(a, b), 80 => __f80_sub(a, b) +} + +val fp_mul : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) +function fp_mul(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_mul(a, b), 32 => __f32_mul(a, b), 64 => __f64_mul(a, b), 80 => __f80_mul(a, b) +} + +val fp_div : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) +function fp_div(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_div(a, b), 32 => __f32_div(a, b), 64 => __f64_div(a, b), 80 => __f80_div(a, b) +} + +// Binary — {8,16,32,64} only +val fp_min : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) +function fp_min(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_min(a, b), 32 => __f32_min(a, b), 64 => __f64_min(a, b) +} + +val fp_max : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) +function fp_max(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_max(a, b), 32 => __f32_max(a, b), 64 => __f64_max(a, b) +} + +val fp_scalef : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) +function fp_scalef(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_scalef(a, b), 32 => __f32_scalef(a, b), 64 => __f64_scalef(a, b) +} + +// Binary with byte imm +val fp_round : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) +function fp_round(x, imm) = match 'n { + 8 => unreachable(), 16 => unreachable(), 32 => __f32_round(x, imm), 64 => __f64_round(x, imm) +} + +val fp_rndscale : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) +function fp_rndscale(x, imm) = match 'n { + 8 => unreachable(), 16 => __f16_rndscale(x, imm), 32 => __f32_rndscale(x, imm), 64 => __f64_rndscale(x, imm) +} + +val fp_getmant : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) +function fp_getmant(x, imm) = match 'n { + 8 => unreachable(), 16 => __f16_getmant(x, imm), 32 => __f32_getmant(x, imm), 64 => __f64_getmant(x, imm) +} + +val fp_reduce : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) +function fp_reduce(x, imm) = match 'n { + 8 => unreachable(), 16 => __f16_reduce(x, imm), 32 => __f32_reduce(x, imm), 64 => __f64_reduce(x, imm) +} + +// Ternary FMA +val fp_fmadd : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) +function fp_fmadd(a, b, c) = match 'n { + 8 => unreachable(), 16 => __f16_fmadd(a, b, c), 32 => __f32_fmadd(a, b, c), 64 => __f64_fmadd(a, b, c) +} + +val fp_fmsub : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) +function fp_fmsub(a, b, c) = match 'n { + 8 => unreachable(), 16 => __f16_fmsub(a, b, c), 32 => __f32_fmsub(a, b, c), 64 => __f64_fmsub(a, b, c) +} + +val fp_fnmadd : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) +function fp_fnmadd(a, b, c) = match 'n { + 8 => unreachable(), 16 => __f16_fnmadd(a, b, c), 32 => __f32_fnmadd(a, b, c), 64 => __f64_fnmadd(a, b, c) +} + +val fp_fnmsub : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) +function fp_fnmsub(a, b, c) = match 'n { + 8 => unreachable(), 16 => __f16_fnmsub(a, b, c), 32 => __f32_fnmsub(a, b, c), 64 => __f64_fnmsub(a, b, c) +} + +// Ternary with byte imm +val fp_fixupimm : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n), byte) -> bits('n) +function fp_fixupimm(a, b, c, imm) = match 'n { + 8 => unreachable(), 16 => unreachable(), 32 => __f32_fixupimm(a, b, c, imm), 64 => __f64_fixupimm(a, b, c, imm) +} + +// Comparison — {8,16,32,64,80} (has f80 extern) +val fp_compare : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> FPCompareResult +function fp_compare(a, b) = match 'n { + 8 => unreachable(), 16 => __f16_compare(a, b), 32 => __f32_compare(a, b), 64 => __f64_compare(a, b), 80 => __f80_compare(a, b) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail new file mode 100644 index 000000000..655c91cc0 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail @@ -0,0 +1,261 @@ +// x86-64 — Fetch-Decode-Execute Loop +// +// Top-level entry point for the instruction cycle. +// Fetches and decodes one instruction from RIP, executes it, +// and advances RIP past the instruction bytes. + +// Raise #DB reporting the given DR6 status bits: the processor clears B0-B3 +// and sets what it reports, never clearing the rest (SDM Vol.3B §20.2.3). +// The B0-B3 in `open` are undefined. With an IDT the exception is +// delivered with RIP as the return address: already advanced past the +// instruction for a trap (single step), still at the instruction for a +// fault (instruction breakpoint). Without an IDT it is reported like any +// fault, with that RIP. +val raise_debug_exception : (qword, bits(4)) -> unit +function raise_debug_exception(status, open) = { + DR6 = (DR6 & 0xFFFFFFFFFFFFFFF0) | status | zero_extend((undefined : bits(4)) & open); + if system_mode then { + try { + deliver_exception(EXN_DB, 0x00000000, EV_Exception) + } catch { + Fault(vec2, err2) => { + fault_pending = true; + fault_vector = vec2; + fault_error_code = err2 + }, + VMExit(reason, qual) => complete_vm_exit(reason, qual), + } + } else { + fault_pending = true; + fault_vector = EXN_DB; + fault_error_code = 0x00000000 + } +} + +// Instruction breakpoints matching a linear address (SDM Vol.3B §20.2.5): +// R/Wn = 00 (execute) with LENn = 00 (any other length is undefined for +// instruction breakpoints), and DRn equal to the address of the +// instruction's first byte, prefixes included. `enabled` selects the +// breakpoints that Ln or Gn enables, the hits, or the others. +val insn_breakpoint_matches : (qword, bool) -> bits(4) +function insn_breakpoint_matches(lin, enabled) = { + var hits : bits(4) = 0x0; + foreach (n from 0 to 3) { + let on : bool = DR7[2 * n] == bitone | DR7[2 * n + 1] == bitone; + let rw_len : bits(4) = DR7[(19 + 4 * n) .. (16 + 4 * n)]; + let dr : qword = match n { 0 => DR0, 1 => DR1, 2 => DR2, _ => DR3 }; + if on == enabled & rw_len == 0x0 & dr == lin then hits[n] = bitone + }; + hits +} + +// Decode and execute one instruction. +// Sets fault_pending/fault_vector/fault_error_code on exception. +val step : unit -> unit +function step() = { + fault_pending = false; + event_delivered = false; + rep_trap_rf = false; + // Data breakpoints hit by a MOV SS/POP SS are delivered after the + // following instruction (SDM Vol.3B §20.3.1.2), so they survive one step. + if ss_shadow != 1 then { + pending_dbp = 0x0; + open_dbp = 0x0 + }; + + // Check for pending SMI before anything else. + // SDM §34.2: "The SMI takes precedence over [...] debug exceptions + // and external interrupts." SMIs are non-maskable (not blocked by IF). + if system_mode & ~(in_smm) & __check_pending_smi() then { + deliver_smi(); + return () + }; + + // Check for pending external interrupts before fetching. + // Only deliver if IF=1 (interrupts enabled) and in system mode, and not + // in the instruction following STI or MOV SS/POP SS (SDM Vol.3A + // §7.8.1 and §7.8.3). + if system_mode & IF_flag == 0b1 & ss_shadow == 0 & sti_shadow == 0 then { + let irq_vec = __check_pending_irq(); + if 0 <= irq_vec & irq_vec <= 255 then { + let vec : exception_vector = irq_vec; + // VMX: external interrupt exit (pin_based_controls bit 0) + if in_vmx_non_root & vmcs.pin_based_controls[0] == 0b1 then { + vmcs.exit_instr_length = 0x00000000; + // NMI exit (pin_based_controls bit 3) — vector 2 + if vec == 2 & vmcs.pin_based_controls[3] == 0b1 then { + complete_vm_exit(VMEXIT_EXCEPTION_NMI, 0x0000000000000202); + return () + }; + complete_vm_exit(VMEXIT_EXTERNAL_INT, zero_extend(to_bits(32, vec))); + return () + }; + try { + deliver_exception(vec, 0x00000000, EV_ExternalInt); + return () + } catch { + Fault(vec2, err2) => { + fault_pending = true; + fault_vector = vec2; + fault_error_code = err2; + return () + }, + VMExit(reason, qual) => { + complete_vm_exit(reason, qual); + return () + }, + } + } + }; + + // Instruction breakpoint (SDM Vol.3B §20.3.1.1): the highest-priority + // debug exception, a fault before the instruction. The check is skipped + // when RF is set (IRET restoring a handler's frame) and for the + // instruction after MOV SS/POP SS: "Any instruction breakpoint on the + // next instruction is suppressed (as if EFLAGS.RF were 1)" (SDM Vol.3A + // §7.8.3, p.7-8); the processor "does not allow external interrupts or + // debug exceptions to occur until the instruction immediately following + // the MOV SS or POP SS instruction completes execution" (APM Vol.2 + // §8.1.4, p.245). RF is then cleared, so it protects exactly one + // instruction. + if RF == 0b0 & ss_shadow != 1 then { + let lin = RIP + get_seg_base(CS); + let hits = insn_breakpoint_matches(lin, true); + if hits != 0x0 then { + raise_debug_exception(zero_extend(hits), insn_breakpoint_matches(lin, false)); + return () + } + }; + RF = 0b0; + + // Set decode position to current RIP + decode_pos = RIP; + insn_start = RIP; + rip_rel_pending = false; + next_rip = None(); + + // Save RSP and flags so we can restore them if the instruction faults. + // x86 guarantees that a faulting instruction leaves architectural state + // as if it never executed. RSP and flags are the registers most likely + // to be modified before a memory op that can fault (e.g. PUSH modifies + // RSP before the store; ALU-to-memory ops update flags before writeback). + // Other registers (x87, segments) are handled by reordering the + // individual instructions so that side effects follow memory ops. + let saved_rsp = GPR[RSP]; + let saved_rflags = read_rflags(); + + // TF is sampled before the instruction: the instruction that sets TF + // (POPF, IRET) is not trapped, the one that clears it still is. + let tf_at_start : bool = TF == 0b1; + + let faulted : bool = + try { + // VME faults before the instruction when a virtual interrupt is + // both enabled and pending (SDM Vol.3B §23.3.2), even at IOPL 3. + if cur_mode == Virtual8086Mode & CR4[0] == bitone & + VIF == bitone & VIP == bitone then raise_GP0(); + // Decode and execute one instruction + decode_execute(); + false + } catch { + Fault(vec, err) => { + GPR[RSP] = saved_rsp; + write_rflags(saved_rflags); + VIF = saved_rflags[19]; + VIP = saved_rflags[20]; + if system_mode then { + // In system mode, deliver faults through the IDT. + try { + deliver_exception(vec, err, EV_Exception); + // RIP already set to handler by deliver_exception; skip normal advance + return () + } catch { + // deliver_exception itself faulted — double/triple fault + Fault(vec2, err2) => { + fault_pending = true; + fault_vector = vec2; + fault_error_code = err2; + return () + }, + VMExit(_, _) => return (), + } + } else { + // RF as the pushed RFLAGS image would carry it (see + // deliver_exception): 1 for a fault-class exception, but the + // current value, cleared at the start of the instruction, for a + // software interrupt whatever its vector (SDM Vol.3B §20.3.1.1). + // INT n, INT3, INTO and INT1 set sw_return_rip before raising. + match sw_return_rip { + Some(_) => sw_return_rip = None(), + None() => if is_fault_class(vec) then RF = 0b1, + }; + fault_pending = true; + fault_vector = vec; + fault_error_code = err; + true + } + }, + // VMX: VM exit from VMX non-root operation. + // Save guest state, load host state, record exit info. + VMExit(reason, qual) => { + complete_vm_exit(reason, qual); + return () + }, + }; + + // Advance RIP unless we faulted or halted. + // Control-flow instructions set next_rip to the branch target; + // otherwise we fall through to the next instruction. + if ~(faulted) & system_state == SysRunning then + RIP = match next_rip { Some(t) => t, None() => decode_pos }; + + // Debug traps after the instruction, reported together in DR6: + // BS — single step (SDM Vol.3B §20.3.1.4): TF was set at the start, + // unless the instruction delivered an event through the IDT + // (INT n, INT3, INTO and INT1 clear TF as part of delivery); + // Bn — data breakpoints hit by the instruction's accesses (§20.3.1.2), + // which INT n does not discard. + // With BS the other B0-B3 are undefined: "When the BS flag is set, any of + // the other debug status bits also may be set" (§20.2.3 p.20-4); "Other + // status bits within the DR6 register can be set by the processor along + // with the BS bit" (APM Vol.2 §13.1.1.3 p.395). A fault loses them (the + // early return above), and after MOV SS/POP SS the single-step trap is + // suppressed and the data breakpoints wait for the following instruction + // (§7.8.3, §20.3.1.2). + if ~(faulted) & system_state == SysRunning & ss_shadow != 2 then { + let bs : qword = if tf_at_start & ~(event_delivered) then 0x0000000000004000 else zeros(); + let status : qword = bs | zero_extend(pending_dbp); + let open : bits(4) = (if bs != zeros() then 0xF else open_dbp) & ~(pending_dbp); + if status != zeros() then { + // RF in the image of a trap after a non-final iteration of a repeated + // string instruction is undefined. The SDM pushes 1: "For any + // trap-class exception generated by any iteration of a repeated + // string instruction but the last iteration, the value pushed for RF + // is 1" (§20.3.1.1 p.20-9). The APM sets it "when a string + // instruction is interrupted", "However, when a #DB exception occurs, + // the processor clears RFLAGS.RF to 0 in the rFLAGS image" (Vol.2 + // §8.2.2 p.250). + if rep_trap_rf then RF = undefined; + raise_debug_exception(status, open) + } + }; + + // The SS-load shadow lasts through the following instruction. + ss_shadow = match ss_shadow { 2 => 1, _ => 0 }; + sti_shadow = match sti_shadow { 2 => 1, _ => 0 } +} + +// Run instructions until a fault, halt, or step count reached. +val run : int -> unit +function run(max_steps) = { + var remaining : int = max_steps; + + while remaining > 0 & ~(fault_pending) & system_state == SysRunning do { + step(); + remaining = remaining - 1 + } +} + +// Dummy main function required by the Sail C++ backend. +val main : unit -> unit +function main() = () diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail new file mode 100644 index 000000000..f17e17fd9 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail @@ -0,0 +1,100 @@ +// x86-64 — ALU Helpers +// +// These helpers perform ALU operations on resolved values, handling +// flag updates and result write-back. They support both register and +// memory operands via the RM union. + +// Perform an ALU operation on two operand-sized values. +// Returns (result, should_write_back). CMP doesn't write back. +val alu_compute : forall 'os, 'os in {8, 16, 32, 64}. (ALUOp, bits('os), bits('os), int('os)) -> (bits('os), bool) +function alu_compute(op, a, b, os) = { + match op { + ALU_ADD => { + let result = a + b; + update_flags_add(result, a, b); + (result, true) + }, + ALU_OR => { + let result = a | b; + update_flags_logic(result); + (result, true) + }, + ALU_ADC => { + let result = a + b + zero_extend(CF); + update_flags_adc(result, a, b, CF); + (result, true) + }, + ALU_SBB => { + let result = a - b - zero_extend(CF); + update_flags_sbb(result, a, b, CF); + (result, true) + }, + ALU_AND => { + let result = a & b; + update_flags_logic(result); + (result, true) + }, + ALU_SUB => { + let result = a - b; + update_flags_sub(result, a, b); + (result, true) + }, + ALU_XOR => { + let result = a ^ b; + update_flags_logic(result); + (result, true) + }, + ALU_CMP => { + let result = a - b; + update_flags_sub(result, a, b); + (result, false) // CMP: don't write back + }, + } +} + +// Execute ALU: dst_rm OP= src_reg +val exec_alu_rm_reg : (ALUOp, RM, GPRRef, {8, 16, 32, 64}) -> unit +function exec_alu_rm_reg(op, dest, reg, os) = { + let a = if op == ALU_CMP then v(os, dest) else read_rmw(os, dest); + let b = v(os, reg); + let (result, wb) = alu_compute(op, a, b, os); + if wb then v(os, dest) = result +} + +// Execute ALU: dst_reg OP= src_rm +val exec_alu_reg_rm : (ALUOp, GPRRef, RM, {8, 16, 32, 64}) -> unit +function exec_alu_reg_rm(op, reg, src, os) = { + let a = v(os, reg); + let b = v(os, src); + let (result, wb) = alu_compute(op, a, b, os); + if wb then v(reg) = result +} + +// Execute ALU: AL/AX/EAX/RAX OP= imm (accumulator short forms) +val exec_alu_acc_imm : forall 'os, 'os in {8, 16, 32, 64}. (ALUOp, bits('os), int('os), Prefixes) -> unit +function exec_alu_acc_imm(op, imm, os, _) = { + let a = v(os, RAX); + let (result, wb) = alu_compute(op, a, imm, os); + if wb then v(RAX) = result +} + +// Execute ALU: dest OP= imm (Group 1: opcodes 80, 81, 83) +val exec_alu_rm_imm : forall 'os, 'os in {8, 16, 32, 64}. (ALUOp, RM, bits('os), int('os)) -> unit +function exec_alu_rm_imm(op, dest, imm, os) = { + let a = if op == ALU_CMP then v(os, dest) else read_rmw(os, dest); + let (result, wb) = alu_compute(op, a, imm, os); + if wb then v(os, dest) = result +} + +// Map Group 1 reg field (0-7) to ALUOp. +val group1_op : range(0, 7) -> ALUOp +function group1_op(reg) = match reg { + 0 => ALU_ADD, + 1 => ALU_OR, + 2 => ALU_ADC, + 3 => ALU_SBB, + 4 => ALU_AND, + 5 => ALU_SUB, + 6 => ALU_XOR, + 7 => ALU_CMP, +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail new file mode 100644 index 000000000..2af4f8eb2 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail @@ -0,0 +1,2551 @@ +// x86-64 — 2-Byte Opcode Map: Baseline Operations +// +// CMOVcc, Jcc, SETcc, BT/BTS/BTR/BTC, SHLD/SHRD, IMUL, MOVZX/MOVSX, +// BSF/BSR, POPCNT, CMPXCHG, XADD, BSWAP, CPUID, RDTSC, and more. + +// DR7.GD (SDM Vol.3B §20.2.4, §20.3.1.3): any MOV DR while GD is set raises +// #DB before the access, a fault with DR6.BD set and RF = 1 in the pushed +// image; the processor clears GD on the way to the handler so that the +// handler itself can use the debug registers. +val general_detect_check : unit -> unit +function general_detect_check() = { + if DR7[13] == bitone then { + DR7[13] = bitzero; + DR6 = (DR6 & 0xFFFFFFFFFFFFFFF0) | 0x0000000000002000; + RF = 0b1; + throw Fault(EXN_DB, 0x00000000) + } +} + +// A linear address is canonical when bits 63:N repeat bit N-1, with N = 48 +// under 4-level paging and 57 under 5-level paging (SDM Vol.1 §3.3.7.1, +// Vol.3A §4.5). SYSRET and SYSEXIT raise #GP(0) for a non-canonical target. +val is_canonical_linear : qword -> bool +function is_canonical_linear(addr) = + if CR4[12] == 0b1 then addr[63..56] == zeros() | addr[63..56] == ones() + else addr[63..47] == zeros() | addr[63..47] == ones() + +// LOCK is valid only on the lockable instructions and only where the +// destination is in memory (SDM Vol.2B LOCK): with a register operand, +// or on CMP (which does not write), it raises #UD. +val check_lock_rm : (Prefixes, RM, bool) -> unit +function check_lock_rm(pfx, dest, is_cmp) = { + if pfx.has_lock then { + match dest { + RM_reg(_) => raise_UD(), + RM_mem(_) => if is_cmp then raise_UD(), + } + } +} + +// XADD — Exchange and Add +val exec_xadd : (GPRRef, GPRRef, operand_size) -> unit +function exec_xadd(dst, src, os) = { + let a = v(os, dst); + let b = v(os, src); + update_flags_add(a + b, a, b); + v(src) = a; + v(dst) = a + b +} + +// Descriptor type validation for LAR in IA-32e mode (SDM Table 1-49). +// System segment types (S=0): valid = 2 (LDT), 9 (avail TSS), B (busy TSS), C (call gate). +// Code/data segments (S=1): all valid. +val lar_type_valid_64 : dword -> bool +function lar_type_valid_64(desc_hi) = { + let s_bit : bit = desc_hi[12]; + if s_bit == 0b1 then { + true + } else { + let typ : bits(4) = desc_hi[11..8]; + typ == 0x2 | typ == 0x9 | typ == 0xB | typ == 0xC + } +} + +// Descriptor type validation for LSL in IA-32e mode (SDM Table 1-53). +// System segment types (S=0): valid = 2 (LDT), 9 (avail TSS), B (busy TSS). +// Code/data segments (S=1): all valid. +val lsl_type_valid_64 : dword -> bool +function lsl_type_valid_64(desc_hi) = { + let s_bit : bit = desc_hi[12]; + if s_bit == 0b1 then { + true + } else { + let typ : bits(4) = desc_hi[11..8]; + typ == 0x2 | typ == 0x9 | typ == 0xB + } +} + +// Privilege check for non-conforming segments: CPL ≤ DPL and RPL ≤ DPL. +// Conforming code segments (S=1, type[3]=1, type[2]=1) bypass this check. +val desc_privilege_ok : (dword, word) -> bool +function desc_privilege_ok(desc_hi, selector) = { + let s_bit : bit = desc_hi[12]; + let is_conforming : bool = s_bit == 0b1 & desc_hi[11] == 0b1 & desc_hi[10] == 0b1; + if is_conforming then { + true + } else { + let dpl : range(0, 3) = unsigned(desc_hi[14..13]); + let rpl : range(0, 3) = unsigned(selector[1..0]); + cur_cpl <= dpl & rpl <= dpl + } +} + +// CPUID — returns (EAX, EBX, ECX, EDX) for a given leaf/subleaf. +// Feature-dependent leaves are built from has_* registers and XCR0. +val cpuid : (dword, dword) -> (dword, dword, dword, dword) +function cpuid(leaf, subleaf) = { + let leaf_val : range(0, 4294967295) = unsigned(leaf); + let sub_val : range(0, 4294967295) = unsigned(subleaf); + + match leaf_val { + // Leaf 0: Vendor string + max basic leaf (1EH with AMX, whose leaves + // 1DH and 1EH are valid only when MAX_LEAF reaches them). + // We report "GenuineIntel" because system libraries (e.g. glibc) + // select code paths based on the vendor string. Presenting as a + // genuine Intel CPU ensures the same feature negotiation that would + // happen on real hardware. + 0 => (if has_amx_tile then 0x0000001E else 0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69), + + // Leaf 1: Family/Model/Stepping, feature bits + 1 => { + let eax : dword = 0x000506E3; // Family 6, Model 5E, Stepping 3 + let ebx : dword = 0x00010800; // CLFLUSH=8, max logical=1 + + // ECX: built dynamically from has_* flags and CR4/XCR0 + var ecx : dword = 0x00000000; + if has_sse3 then ecx = ecx | 0x00000001; // bit 0 (SSE3) + if has_pclmulqdq then ecx = ecx | 0x00000002; // bit 1 + if has_vmx then ecx = ecx | 0x00000020; // bit 5 (VMX) + if has_ssse3 then ecx = ecx | 0x00000200; // bit 9 (SSSE3) + if has_fma then ecx = ecx | 0x00001000; // bit 12 + if has_cx16 then ecx = ecx | 0x00002000; // bit 13 (CX16) + if has_sse4_1 then ecx = ecx | 0x00080000; // bit 19 (SSE4.1) + if has_sse4_2 then ecx = ecx | 0x00100000; // bit 20 (SSE4.2) + if has_movbe then ecx = ecx | 0x00400000; // bit 22 + if has_popcnt then ecx = ecx | 0x00800000; // bit 23 + if has_aesni then ecx = ecx | 0x02000000; // bit 25 + if has_xsave then ecx = ecx | 0x04000000; // bit 26 (XSAVE) + if CR4[18] == 0b1 then ecx = ecx | 0x08000000; // bit 27 (OSXSAVE) + if XCR0[2] == 0b1 then ecx = ecx | 0x10000000; // bit 28 (AVX) + if has_f16c then ecx = ecx | 0x20000000; // bit 29 + if has_rdrand then ecx = ecx | 0x40000000; // bit 30 + + // EDX: baseline features (FPU, VME, DE, PSE, TSC, MSR, PAE, MCE, CX8, + // APIC, SEP, MTRR, PGE, MCA, CMOV, PAT, PSE36, CLFLUSH, + // MMX, FXSR, SSE, SSE2) + let edx : dword = 0x078BFBFF; + (eax, ebx, ecx, edx) + }, + + // Leaf 2: Cache/TLB descriptors + 2 => (0x76036301, 0x00F0B5FF, 0x00000000, 0x00C30000), + + // Leaf 4: Deterministic cache parameters — no more caches + 4 => (0x00000000, 0x00000000, 0x00000000, 0x00000000), + + // Leaf 7: Structured extended feature flags + 7 => { + if sub_val == 0 then { + var ebx : dword = 0x00000000; + ebx = ebx | 0x00000200; // ERMS (bit 9) + if has_bmi1 then ebx = ebx | 0x00000008; // bit 3 + if XCR0[2] == 0b1 then ebx = ebx | 0x00000020; // AVX2 (bit 5) + if has_bmi2 then ebx = ebx | 0x00000100; // bit 8 + // AVX-512 (SDM Vol.1 Tables 21-19 to 21-22): each extension its + // own bit, from its own feature register (regs.sail). + if has_avx512f then ebx = ebx | 0x00010000; // bit 16 (AVX512F) + if has_avx512dq then ebx = ebx | 0x00020000; // bit 17 (AVX512DQ) + if has_avx512_ifma then ebx = ebx | 0x00200000; // bit 21 (AVX512_IFMA) + if has_avx512pf then ebx = ebx | 0x04000000; // bit 26 (AVX512PF) + if has_avx512er then ebx = ebx | 0x08000000; // bit 27 (AVX512ER) + if has_avx512cd then ebx = ebx | 0x10000000; // bit 28 (AVX512CD) + if has_avx512bw then ebx = ebx | 0x40000000; // bit 30 (AVX512BW) + if has_avx512vl then ebx = ebx | 0x80000000; // bit 31 (AVX512VL) + if has_rdseed then ebx = ebx | 0x00040000; // bit 18 + if has_adx then ebx = ebx | 0x00080000; // bit 19 + if has_smap then ebx = ebx | 0x00100000; // bit 20 (SMAP) + if has_ptwrite then ebx = ebx | 0x02000000; // bit 25 (Intel PT: leaf 14H) + if has_sha then ebx = ebx | 0x20000000; // bit 29 + // The x87 pointer rules (regs.sail): FDP_EXCPTN_ONLY (bit 6) and + // FCS_FDS_DEPRECATION (bit 13), reserved in the APM. + if has_fdp_excptn_only then ebx = ebx | 0x00000040; + if has_fcs_fds_deprecation then ebx = ebx | 0x00002000; + var ecx : dword = 0x00000000; + if has_avx512_vbmi then ecx = ecx | 0x00000002; // bit 1 (AVX512_VBMI) + if has_avx512_vbmi2 then ecx = ecx | 0x00000040; // bit 6 (AVX512_VBMI2) + if has_avx512_vnni then ecx = ecx | 0x00000800; // bit 11 (AVX512_VNNI) + if has_avx512_bitalg then ecx = ecx | 0x00001000; // bit 12 (AVX512_BITALG) + if has_avx512_vpopcntdq then ecx = ecx | 0x00004000; // bit 14 (AVX512_VPOPCNTDQ) + if has_waitpkg then ecx = ecx | 0x00000020; // bit 5 (WAITPKG) + if has_gfni then ecx = ecx | 0x00000100; // bit 8 (GFNI) + if has_vaes then ecx = ecx | 0x00000200; // bit 9 (VAES) + if has_vpclmulqdq then ecx = ecx | 0x00000400; // bit 10 (VPCLMULQDQ) + if has_la57 then ecx = ecx | 0x00010000; // bit 16 (LA57) + if has_rdpid then ecx = ecx | 0x00400000; // bit 22 (RDPID) + if has_cldemote then ecx = ecx | 0x02000000; // bit 25 (CLDEMOTE) + if has_movdiri then ecx = ecx | 0x08000000; // bit 27 + if has_movdir64b then ecx = ecx | 0x10000000; // bit 28 + if has_enqcmd then ecx = ecx | 0x20000000; // bit 29 (ENQCMD) + var edx : dword = 0x00000000; + if has_avx512_vp2intersect then edx = edx | 0x00000100; // bit 8 (AVX512_VP2INTERSECT) + if has_avx512_fp16 then edx = edx | 0x00800000; // bit 23 (AVX512_FP16) + if has_amx_bf16 then edx = edx | 0x00400000; // bit 22 (AMX-BF16) + if has_amx_tile then edx = edx | 0x01000000; // bit 24 (AMX-TILE) + if has_amx_int8 then edx = edx | 0x02000000; // bit 25 (AMX-INT8) + // EAX: maximum sub-leaf; sub-leaf 1 exists once something is in it + let max_sub : dword = if has_avx_vnni | has_avx512_bf16 then 0x00000001 else 0x00000000; + (max_sub, ebx, ecx, edx) + } else if sub_val == 1 then { + var eax : dword = 0x00000000; + if has_avx_vnni then eax = eax | 0x00000010; // bit 4 (AVX-VNNI) + if has_avx512_bf16 then eax = eax | 0x00000020; // bit 5 (AVX512_BF16) + (eax, 0x00000000, 0x00000000, 0x00000000) + } else { + (0x00000000, 0x00000000, 0x00000000, 0x00000000) + } + }, + + // Leaf 0xD: XSAVE state component info (SDM Table 21-36, Vol.1 §13.2) + 13 => match (has_xsave, sub_val) { + // EAX/EDX = XCR0_SUPPORTED + // EBX = standard size for currently enabled components (dynamic) + // ECX = max standard size for all supported components + (true, 0) => (XCR0_SUPPORTED[31..0], + xsave_area_size_standard(XCR0), + xsave_area_size_standard(XCR0_SUPPORTED), + XCR0_SUPPORTED[63..32]), + // EAX: XSAVEOPT(0), XSAVEC(1), XGETBV w/ ECX=1(2), XSAVES/XRSTORS(3), + // XFD(4) + // EBX = compacted size for XCR0 | IA32_XSS (dynamic), "If EAX[1] + // and EAX[3] are both enumerated as 0, EBX enumerates zero" + // ECX = supported IA32_XSS bits [31:0] (none) + // EDX = supported IA32_XSS bits [63:32] (none) + (true, 1) => { + var eax : dword = 0x00000000; + if has_xsaveopt then eax = eax | 0x00000001; + if has_xsavec then eax = eax | 0x00000002; + if has_xgetbv1 then eax = eax | 0x00000004; + if has_xsaves then eax = eax | 0x00000008; + if has_xfd then eax = eax | 0x00000010; + let ebx : dword = if has_xsavec | has_xsaves then xsave_area_size_compacted(XCR0) else 0x00000000; + (eax, ebx, 0x00000000, 0x00000000) + }, + // A user state component i of XCR0_SUPPORTED: EAX its size, EBX its + // standard-format offset, ECX[1] its 64-byte alignment in the + // compacted format and ECX[2] whether IA32_XFD can disable it (the + // model implements XFD for TILEDATA only). + (true, i) => if 2 <= i & i <= 18 then { + if XCR0_SUPPORTED[i] == bitone then { + let ecx : dword = (if xsave_comp_align[i] then 0x00000002 else 0x00000000) + | (if xfd_supported()[i] == bitone then 0x00000004 else 0x00000000); + (xsave_comp_size[i], xsave_comp_offset[i], ecx, 0x00000000) + } else (0x00000000, 0x00000000, 0x00000000, 0x00000000) + } else (0x00000000, 0x00000000, 0x00000000, 0x00000000), + _ => (0x00000000, 0x00000000, 0x00000000, 0x00000000) + }, + + // Leaf 0x1D: AMX tile information (SDM Table 21-65, 21-66). Sub-leaf 0 + // gives the highest palette, 1; sub-leaf 1 describes palette 1: 8192 + // bytes of tiles, 1024 per tile, 64 per row, 8 tile names, 16 rows. + 29 => match (has_amx_tile, sub_val) { + (true, 0) => (0x00000001, 0x00000000, 0x00000000, 0x00000000), + (true, 1) => (0x04002000, 0x00080040, 0x00000010, 0x00000000), + _ => (0x00000000, 0x00000000, 0x00000000, 0x00000000) + }, + + // Leaf 0x1E: TMUL information (SDM Table 21-67): tmul_maxk = 16 rows, + // tmul_maxn = 64 column bytes. + 30 => if has_amx_tile & sub_val == 0 then (0x00000000, 0x00004010, 0x00000000, 0x00000000) + else (0x00000000, 0x00000000, 0x00000000, 0x00000000), + + // Leaf 0x14: Intel PT (SDM Table 21-49), valid with CPUID.07H:EBX[25]. + // Sub-leaf 0: EAX the highest sub-leaf, EBX[4] PTWRITE; no trace + // output scheme (ECX = 0). + 20 => if has_ptwrite & sub_val == 0 then (0x00000000, 0x00000010, 0x00000000, 0x00000000) + else (0x00000000, 0x00000000, 0x00000000, 0x00000000), + + // Leaf 0x15: Time Stamp Counter / Core Crystal Clock + // EAX = denominator, EBX = numerator, ECX = crystal frequency (Hz) + // TSC freq = crystal_freq * numerator / denominator = 25MHz * 40 / 1 = 1GHz + 21 => (0x00000001, 0x00000028, 0x017D7840, 0x00000000), + + // Leaf 0x16: Processor Frequency Information (MHz) + // EAX = base freq, EBX = max freq, ECX = bus freq + 22 => (0x000003E8, 0x000003E8, 0x00000064, 0x00000000), + + // Leaf 0x80000000: Max extended leaf + 2147483648 => (0x80000008, 0x00000000, 0x00000000, 0x00000000), + + // Leaf 0x80000001: Extended feature bits + 2147483649 => { + // ECX: LAHF(0), conditionally LZCNT(5), SSE4A(6), MisAlignSse(7) + // and PREFETCHW(8) + var ecx : dword = 0x00000001; // LAHF + if has_lzcnt then ecx = ecx | 0x00000020; // bit 5 + if has_sse4a then ecx = ecx | 0x00000040; // bit 6 (AMD APM Vol.3 Appendix E) + if has_misalignsse then ecx = ecx | 0x00000080; // bit 7 (APM Vol.3 Appendix E) + if has_prefetchw then ecx = ecx | 0x00000100; // bit 8 + // EDX: SYSCALL(11), NX(20), LM(29) + let edx : dword = 0x20100800; + (0x00000000, 0x00000000, ecx, edx) + }, + + // Leaves 0x80000002-0x80000004: Processor brand string "Sail x86-64 Emulator" + 2147483650 => (0x6C696153, 0x36387820, 0x2034362D, 0x6C756D45), + 2147483651 => (0x726F7461, 0x00000000, 0x00000000, 0x00000000), + 2147483652 => (0x00000000, 0x00000000, 0x00000000, 0x00000000), + + // Leaf 0x80000007: Advanced power management — invariant TSC (bit 8) + 2147483655 => (0x00000000, 0x00000000, 0x00000000, 0x00000100), + + // Leaf 0x80000008: Address sizes + // EAX[7:0] = physical address bits (39), EAX[15:8] = virtual address bits + // Virtual: 57 with LA57, 48 without + // EBX[2] = RstrFpErrPtrs (has_rstr_fp_err_ptrs in regs.sail; reserved + // in the SDM) + 2147483656 => { + let virt_bits : dword = if has_la57 then 0x00003900 else 0x00003000; + let ebx : dword = if has_rstr_fp_err_ptrs then 0x00000004 else 0x00000000; + (virt_bits | 0x00000027, ebx, 0x00000000, 0x00000000) + }, + + // Unknown leaf: return zeros + _ => (0x00000000, 0x00000000, 0x00000000, 0x00000000), + } +} + +// SHLD — Double Precision Shift Left +// +// Shifts dst left by count, filling vacated bits from src (high bits). +// Equivalent to: result = upper_half(dst:src << count) +// If count=0, no operation. If count > operand_size, undefined. +// CF = last bit shifted out. SF, ZF, PF set from result. +// OF defined for count=1 (sign change). AF undefined. +val exec_shld : forall 'os, 'os in {16, 32, 64}. (implicit('os), bits('os), bits('os), byte) -> bits('os) +function exec_shld(os, d, s, count_raw) = { + let count : range(0, 63) = match os { + 64 => unsigned(count_raw) % 64, + _ => unsigned(count_raw) % 32, + }; + + let count_bv : bits(6) = to_bits(6, count); + let old_CF = CF; + let old_OF = OF; + let old_SF = SF; + let old_ZF = ZF; + let old_PF = PF; + let old_AF = AF; + + // Clamp count to [0, os] for valid computation; garbage for count > os is blended away + let clamped_bv : bits(7) = min_u(to_bits(7, count), to_bits(7, os)); + let clamped : range(0, 127) = unsigned(clamped_bv); + let cf_count = clamped + unsigned(is_zero(count_bv)); + assert(cf_count >= 1 & cf_count <= os); + let wide = d @ s; + let shifted = wide << clamped; + let r = shifted[(os * 2 - 1)..os]; + CF = wide[os * 2 - cf_count]; + update_SF_ZF_PF(r); + OF = r[os - 1] ^ d[os - 1]; + AF = undefined; + // OF defined only for count==1; undefined otherwise + OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); + + // count==0: restore old flags + let count_nz : bit = is_nonzero(count_bv); + CF = blend(old_CF, CF, count_nz); + OF = blend(old_OF, OF, count_nz); + SF = blend(old_SF, SF, count_nz); + ZF = blend(old_ZF, ZF, count_nz); + PF = blend(old_PF, PF, count_nz); + AF = blend(old_AF, AF, count_nz); + let result : bits('os) = blend(d, r, count_nz); + + // count > os: SDM says result and flags undefined + let count_gt_os : bit = is_gt_u(to_bits(7, count), to_bits(7, os)); + CF = blend(CF, undefined, count_gt_os); + OF = blend(OF, undefined, count_gt_os); + SF = blend(SF, undefined, count_gt_os); + ZF = blend(ZF, undefined, count_gt_os); + PF = blend(PF, undefined, count_gt_os); + AF = blend(AF, undefined, count_gt_os); + blend(result, undefined, count_gt_os) +} + +// SHRD — Double Precision Shift Right +// +// Shifts dst right by count, filling vacated bits from src (low bits). +// Equivalent to: result = lower_half(src:dst >> count) +// If count=0, no operation. If count > operand_size, undefined. +// CF = last bit shifted out. SF, ZF, PF set from result. +// OF defined for count=1 (sign change). AF undefined. +val exec_shrd : forall 'os, 'os in {16, 32, 64}. (implicit('os), bits('os), bits('os), byte) -> bits('os) +function exec_shrd(os, d, s, count_raw) = { + let count : range(0, 63) = match os { + 64 => unsigned(count_raw) % 64, + _ => unsigned(count_raw) % 32, + }; + + let count_bv : bits(6) = to_bits(6, count); + let old_CF = CF; + let old_OF = OF; + let old_SF = SF; + let old_ZF = ZF; + let old_PF = PF; + let old_AF = AF; + + // Clamp count to [0, os] for valid computation + let clamped_bv : bits(7) = min_u(to_bits(7, count), to_bits(7, os)); + let clamped : range(0, 127) = unsigned(clamped_bv); + let cf_count = clamped + unsigned(is_zero(count_bv)); + assert(cf_count >= 1 & cf_count <= 64); + let wide = s @ d; + let shifted = wide >> clamped; + let r = shifted[(os - 1)..0]; + let d_ext : bits(64) = zero_extend(d); + CF = d_ext[cf_count - 1]; + update_SF_ZF_PF(r); + OF = r[os - 1] ^ d[os - 1]; + AF = undefined; + // OF defined only for count==1; undefined otherwise + OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); + + // count==0: restore old flags + let count_nz : bit = is_nonzero(count_bv); + CF = blend(old_CF, CF, count_nz); + OF = blend(old_OF, OF, count_nz); + SF = blend(old_SF, SF, count_nz); + ZF = blend(old_ZF, ZF, count_nz); + PF = blend(old_PF, PF, count_nz); + AF = blend(old_AF, AF, count_nz); + let result : bits('os) = blend(d, r, count_nz); + + // count > os: SDM says result and flags undefined + let count_gt_os : bit = is_gt_u(to_bits(7, count), to_bits(7, os)); + CF = blend(CF, undefined, count_gt_os); + OF = blend(OF, undefined, count_gt_os); + SF = blend(SF, undefined, count_gt_os); + ZF = blend(ZF, undefined, count_gt_os); + PF = blend(PF, undefined, count_gt_os); + AF = blend(AF, undefined, count_gt_os); + blend(result, undefined, count_gt_os) +} + +// Adjust BT/BTS/BTR/BTC operands for memory bit string addressing. +// For register rm: bit index is masked to operand size (e.g., mod 64 for 64). +// For memory rm: the full signed bit offset indexes into an arbitrarily long +// bit string, so the effective address is displaced by (offset / op_bits) words. +// Returns (possibly-adjusted RM, bit number within the accessed word). +val bt_adjust : forall 'os, 'os in {16, 32, 64}. (implicit('os), RM, bits('os)) -> (RM, range(0, 'os - 1)) +function bt_adjust(os, rm, bit_idx) = { + match rm { + RM_reg(_) => { + let bit_num : range(0, 'os - 1) = unsigned(bit_idx) % os; + (rm, bit_num) + }, + RM_mem(m) => { + // Apply RIP-relative fixup first, before adding the bit string + // displacement. Otherwise fixup_addr would discard our adjustment. + let base_addr : qword = fixup_addr(m.addr); + rip_rel_pending = false; + + // For memory operands, the full signed bit offset indexes into a bit + // string starting at the effective address. Compute the word displacement + // (Euclidean: bit_num is always in [0, op_bits)). + let off = signed(bit_idx); + let r = rem_round_zero(off, os); + let q = quot_round_zero(off, os); + // Branchless Euclidean adjustment: sign = 0 when r >= 0, -1 when r < 0 + let r_bv : bits(7) = get_slice_int(7, r, 0); + let sign : int = negate(unsigned(r_bv[6])); + let byte_disp : int = (q + sign) * (os / 8); + let bit_num_int : int = r - sign * os; + let new_addr : qword = base_addr + get_slice_int(64, byte_disp, 0); + let bit_num : range(0, 63) = unsigned(get_slice_int(6, bit_num_int, 0)); + assert(bit_num < os); + (RM_mem(struct { seg = m.seg, addr = new_addr }), bit_num) + }, + } +} + +// TPAUSE r32, , (66 0F AE /6, mod = 11) and UMWAIT r32, , +// (F2 0F AE /6, mod = 11) — SDM Vol.2B; CPUID.07H.00H:ECX.WAITPKG[5]. +// The processor rests in the C0.1 or C0.2 state that bit 0 of the register +// selects until the TSC reaches EDX:EAX or, first, the limit the OS set in +// IA32_UMWAIT_CONTROL[31:2] (TSC quanta; 0 for no limit), and sets CF when +// the OS limit ended the wait; UMWAIT also wakes on a store to the UMONITOR +// range and does not rest at all when no monitor is armed. The model does +// not idle: a wait ends at once. "Other implementation-dependent events +// may also cause the processor to exit" (SDM Vol.2B UMWAIT p.4-739; TPAUSE +// lists NMI, SMI and the like, p.4-725) before the OS limit, so when the +// instruction would rest and the OS limit is the earlier deadline, CF is +// undefined; otherwise it is 0. AF, PF, SF, ZF and OF are cleared. +val exec_tpause_umwait : (GPRRef, bool) -> unit +function exec_tpause_umwait(r, is_umwait) = { + if ~(has_waitpkg) then raise_UD(); + let ctl : dword = v(32, r); + if ctl[31..1] != zeros() then raise_GP0(); + if CR4[2] == 0b1 & cur_cpl != 0 then raise_GP0(); + let limit : qword = zero_extend(__rdmsr(0x000000E1)[31..2] @ 0b00); + let tsc : qword = __rdtsc(); + let instr_deadline : qword = v(32, RDX) @ v(32, RAX); + let rests : bool = ~(is_umwait) | umonitor_armed; + let using_os_deadline : bool = limit != zeros() & (tsc + limit) <_u instr_deadline; + CF = if rests & using_os_deadline then undefined else 0b0; + OF = 0b0; + SF = 0b0; + ZF = 0b0; + AF = 0b0; + PF = 0b0; + if is_umwait then umonitor_armed = false +} + +// UMONITOR r16/r32/r64 (F3 0F AE /6, mod = 11): arm the monitor on the +// linear address of the effective address in the register, whose width is +// the address size; DS unless overridden. The SDM gives the instruction +// "the permission checking and faults associated with a byte load" +// (#GP(0) or #SS(0) for a non-canonical address, #PF), so the model reads +// a byte there; the monitored range itself is not tracked. +val exec_umonitor : (GPRRef, Prefixes) -> unit +function exec_umonitor(r, pfx) = { + if ~(has_waitpkg) then raise_UD(); + let ea : qword = match get_address_size(pfx) { + 16 => zero_extend(v(16, r)), + 32 => zero_extend(v(32, r)), + 64 => v(64, r), + }; + let _ : byte = read_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }); + umonitor_armed = true +} + +// The destination of MOVDIR64B, ENQCMD and ENQCMDS (66/F2/F3 0F 38 F8), +// translated for their 64-byte store. The register operand, at the +// address size, is an offset into ES, which no prefix overrides (SDM +// Vol.2B MOVDIR64B, Vol.2A ENQCMD). Segmentation checks the 64 bytes as +// any access (#GP(0) for a non-canonical address in 64-bit mode, beyond +// the ES limit outside it), the destination must be 64-byte aligned +// (#GP(0)), and the translation is a write's (#PF with W = 1), after a +// data breakpoint on writes has seen the access. MOVDIR64B is #GP(0) "If +// address in destination (register) operand is not aligned to a 64-byte +// boundary" (SDM Vol.2B 4-52; APM Vol.3 MOVDIR64B: "The destination +// operand was not 64-byte aligned"), the offset; ENQCMD and ENQCMDS "If +// destination linear address is not aligned" (SDM Vol.2A 3-290, 3-293), +// the ES base added: `linear_aligned` selects the second. The destination +// is not the ModR/M operand: a RIP-relative source's fixup in seg_linear +// must not move it. +val es_dest64_paddr : (Prefixes, GPRRef, bool) -> qword +function es_dest64_paddr(pfx, reg, linear_aligned) = { + rip_rel_pending = false; + let asz = get_address_size(pfx); + let offset : qword = zero_extend(v(asz, reg)); + let dst : MemRef = struct { seg = ES, addr = offset }; + let lin : qword = seg_linear(dst, 64); + let aligned : bits(6) = if linear_aligned then lin[5..0] else offset[5..0]; + if aligned != 0b000000 then raise_GP0(); + note_data_access(lin, 64, true); + translate_addr(lin, PT_Write) +} + +// MOVDIR64B r16/r32/r64, m512 (66 0F 38 F8 /r), mod != 11 — SDM Vol.2B; +// CPUID.07H.00H:ECX.MOVDIR64B[28]. It reads 64 bytes from the source, an +// ordinary load that need not be aligned, and writes them to the +// destination with one 64-byte direct store: "MOVDIR64B first reads +// 64-bytes from the source memory address. It then performs a 64-byte +// direct-store operation to the destination address" (SDM Vol.2B 4-51), +// so a fault on the source comes before one of the store (a non-canonical +// or unmapped destination). The exception lists give no order between a +// source fault and a misaligned destination, nor between that and the +// destination's translation; the model checks the alignment with the +// store, after the source is read and before the translation. +val exec_movdir64b : Prefixes -> unit +function exec_movdir64b(pfx) = { + if ~(has_movdir64b) then raise_UD(); + let (reg, src) = fetch_modrm(pfx); + let data : zmmword = rm_mem(src); + phys_write(es_dest64_paddr(pfx, reg, false), data) +} + +// ENQCMD r, m512 (F2 0F 38 F8 /r) and ENQCMDS r, m512 (F3 0F 38 F8 /r), +// mod != 11 — SDM Vol.2A; CPUID.07H.00H:ECX.ENQCMD[29]. Each reads 64 +// bytes of command data from the source (an ordinary load, no alignment) +// and sends a command built from them with an enqueue store to the +// destination, whose offset in ES (no override) is the register operand +// at the address size and whose linear address must be 64-byte aligned. +// ENQCMD requires a valid IA32_PASID and bits 31:0 of the source to be +// zero, in whose place the command gets the PASID and a privilege bit of +// 0 (user); ENQCMDS, CPL 0 only, requires bits 30:20 to be zero and sends +// the source as it is. The enqueue store returns a status in ZF: 0 when a +// device's enqueue register accepted the command, 1 (retry) otherwise, +// and "if the destination address was not an enqueue register (including +// the case of a memory address) ... the store is dropped and is written +// neither to MMIO nor to memory". The model has no device with an +// enqueue register, so a store that address translation lets through is +// dropped with ZF = 1; the other arithmetic flags are cleared. +// +// The order of the checks: ENQCMD reads the source only once IA32_PASID +// is valid ("IF IA32_PASID[31] = 0 THEN #GP; ELSE COMMAND := (SRC & ...", +// SDM Vol.2A 3-290, Operation), and in VMX non-root operation both +// instructions translate the PASID "only after checking for conditions +// that may result in general-protection exception (the check of +// IA32_PASID.Valid for ENQCMD; the privilege-level check for ENQCMDS), +// after loading the instruction's source operand from memory, and thus +// after any faults ... that the loading may cause", and "before the +// actual enqueue store and thus before any faults ... that it may cause" +// (SDM Vol.3C §28.3): the source's faults come before the store's. The +// rest the exception lists leave open, and the model chooses: ENQCMDS's +// CPL check before the source is read, the whole source read before its +// bits are checked, and the destination's alignment (with the store, as +// for MOVDIR64B) after the bits and before the translation, which is a +// write's (#PF with W = 1) and hits a data breakpoint on writes although +// the store is dropped. (The mod = 11 forms are URDMSR and UWRMSR with +// USER_MSR, CPUID.07H.01H:EDX[15], which the model does not implement: +// #UD.) +val exec_enqcmd : (Prefixes, bool) -> unit +function exec_enqcmd(pfx, supervisor) = { + if ~(has_enqcmd) then raise_UD(); + let (reg, src) = fetch_modrm(pfx); + let m : MemRef = match src { RM_mem(m) => m, RM_reg(_) => raise_UD() }; + if supervisor then { + if cur_cpl != 0 then raise_GP0() + } else { + if IA32_PASID[31] == bitzero then raise_GP0() + }; + let data : zmmword = read_mem(m); + if supervisor then { + if data[30..20] != zeros() then raise_GP0() + } else { + if data[31..0] != zeros() then raise_GP0() + }; + // COMMAND := (SRC & ~FFFFFFFFH) | (IA32_PASID & FFFFFH) for ENQCMD, + // DEST := SRC for ENQCMDS: the data a device's enqueue register would get. + let _command : zmmword = + if supervisor then data + else data[511..32] @ 0b000000000000 @ IA32_PASID[19..0]; + let _ = es_dest64_paddr(pfx, reg, true); + CF = 0b0; + PF = 0b0; + AF = 0b0; + ZF = 0b1; + SF = 0b0; + OF = 0b0 +} + +// CLFLUSH, CLFLUSHOPT and CLWB m8 change no architectural state, but each +// "is subject to all permission checking and faults associated with a byte +// load" and "like a load, ... sets the A bit but not the D bit" (SDM +// Vol.2A CLFLUSH, CLFLUSHOPT, CLWB): the segment and canonical checks of a +// byte at m, and the translation of a read. +val cache_line_access : MemRef -> unit +function cache_line_access(m) = { + let _ = translate_addr(seg_linear(m, 1), PT_Read); + () +} + +// ========================================================================= +// Fast system calls: SYSCALL, SYSRET, SYSENTER and SYSEXIT +// +// The manuals define them in different modes. The SDM defines SYSCALL and +// SYSRET in 64-bit mode only ("not recognized" elsewhere, #UD) and SYSENTER +// and SYSEXIT in every protected mode; the APM defines SYSCALL and SYSRET +// in every mode and SYSENTER and SYSEXIT outside long mode only (#UD in +// it). The model executes each instruction wherever a manual defines it, +// as that manual gives it, and where both define it but give different +// values, the value is undefined: either manual's, `if (undefined : bool) +// then else `, of which the emulator, whose +// undefined values are false and zeros, takes the SDM's. +// ========================================================================= + +// The flat segments the fast system calls load into the CS and SS +// descriptor caches in place of the descriptors their selectors name: base +// 0, a 4-GByte limit, execute/read or read/write data, accessed, S = 1, +// P = 1, G = 1, and CS.L and CS.D for 64-bit or 32-bit code. +val fast_call_code : (range(0, 3), bool) -> SegDescCache +function fast_call_code(dpl, long) = struct { + seg_base = 0x0000000000000000, + seg_limit = 0xFFFFFFFF, + seg_type = 0xB, + seg_s = 0b1, + seg_dpl = dpl, + seg_present = 0b1, + seg_db = if long then 0b0 else 0b1, + seg_l = if long then 0b1 else 0b0, + seg_g = 0b1, +} + +val fast_call_stack : range(0, 3) -> SegDescCache +function fast_call_stack(dpl) = struct { + seg_base = 0x0000000000000000, + seg_limit = 0xFFFFFFFF, + seg_type = 0x3, + seg_s = 0b1, + seg_dpl = dpl, + seg_present = 0b1, + seg_db = 0b1, + seg_l = 0b0, + seg_g = 0b1, +} + +// SYSCALL in system mode, after the IA32_EFER.SCE check both manuals make +// first. In IA-32e mode, the APM's SYSCALL_LONG_MODE (Vol.3 SYSCALL +// p.486): RCX := the next RIP, R11 := RFLAGS, RFLAGS &= ~SFMASK, CS and SS +// from STAR[47:32] with fixed 64-bit code and stack at CPL 0, and RIP := +// LSTAR from 64-bit mode and CSTAR from compatibility mode ("temp_RIP.q = +// MSR_CSTAR", "Always switch to 64-bit mode in long mode"). The SDM's +// SYSCALL is the 64-bit-mode part of it (Vol.2B SYSCALL 4-698: "IF +// IA32_EFER.LMA = 0 OR CS.L = 0 ... THEN #UD"). Outside IA-32e mode, the +// APM's SYSCALL_LEGACY_MODE (p.487), in real, virtual-8086 and protected +// mode alike ("There are no permission checks based on the CPL, real +// mode, or virtual-8086 mode", p.484): "RCX.d = next_RIP; temp_RIP.d = +// MSR_STAR.EIP; CS.sel = MSR_STAR.SYSCALL_CS AND 0xFFFC; CS.attr = 32-bit +// code,dpl0 ... SS.sel = MSR_STAR.SYSCALL_CS + 8; SS.attr = 32-bit +// stack,dpl0 ... RFLAGS.VM,IF,RF=0; CPL = 0", with no R11 or SFMASK. +// RF is clear here already (the fetch clears it), as both leave it. +val exec_syscall : unit -> unit +function exec_syscall() = { + let star : qword = __rdmsr(0xC0000081); + let flags = read_rflags(); + write_segreg(CS, star[47..32] & 0xFFFC); + write_segreg(SS, star[47..32] + 0x0008); + SegCache[SS] = fast_call_stack(0); + cur_cpl = 0; + if EFER[10] == 0b1 then { + v(RCX) = decode_pos; + // RF in the saved RFLAGS, where the manuals differ: "R11 := RFLAGS" + // (SDM, 4-699), "R11.q = RFLAGS // with rf cleared" (APM, p.486). (The + // model's fetch clears RF before the instruction executes, so it is 0 + // in `flags`.) + v(R11) = if (undefined : bool) then flags & ~(0x0000000000010000) else flags; + let fmask : qword = __rdmsr(0xC0000084); + write_rflags(flags & ~(fmask)); + if fmask[19] == bitone then VIF = bitzero; + if fmask[20] == bitone then VIP = bitzero; + let target : qword = __rdmsr(if cur_mode == LongMode then 0xC0000082 else 0xC0000083); + SegCache[CS] = fast_call_code(0, true); + cur_mode = LongMode; + next_rip = Some(target) + } else { + v(32, RCX) = decode_pos[31..0]; + IF_flag = bitzero; + SegCache[CS] = fast_call_code(0, false); + if cur_mode == Virtual8086Mode then cur_mode = ProtectedMode; + next_rip = Some(zero_extend(star[31..0])) + } +} + +// SYSRET. The SDM (Vol.2B SYSRET 4-709) has #UD unless in 64-bit mode +// with IA32_EFER.SCE = 1, then "IF (CPL ≠ 0) THEN #GP(0)". The APM (Vol.3 +// SYSRET pp.493-495) has #UD for SCE = 0, then "IF ((!PROTECTED_MODE) || +// (CPL != 0)) EXCEPTION [#GP(0)]", and executes SYSRET_64BIT_MODE in +// 64-bit mode and SYSRET_NON_64BIT_MODE in legacy protected and +// compatibility mode. Where the SDM's #UD meets the APM's #GP(0), in real +// and virtual-8086 mode and at CPL > 0 outside 64-bit mode, the vectors +// differ; the model raises the APM's, as the manual that defines SYSRET +// there. +val exec_sysret : Prefixes -> unit +function exec_sysret(pfx) = { + if EFER[0] != 0b1 then raise_UD(); + if cur_mode == RealMode | cur_mode == Virtual8086Mode | cur_cpl != 0 then raise_GP0(); + let star : qword = __rdmsr(0xC0000081); + let sysret_cs : word = star[63..48]; + if cur_mode == LongMode then { + // With a 64-bit operand size RIP := RCX, else RIP := ECX. The SDM + // checks RCX first, "IF (RCX is not canonical) THEN #GP(0)"; the APM + // does not ("temp_RIP.q = RCX", p.494), and its processor returns to + // CPL 3 and faults on the fetch there: "Attempting to execute code + // ... at a non-canonical RIP" is #GP(0) (Vol.2 §8.2.14, Table 8-6, + // p.256). The model follows the APM, the fetch raising the #GP. + let new_rip : qword = if pfx.rex_w then v(RCX) else zero_extend(v(32, RCX)); + // "RFLAGS := (R11 & 3C7FD7H) | 2" (SDM), "RFLAGS.q = R11 // RF=0,VM=0" + // (APM): R11 but for RF, VM and the reserved bits, VIF and VIP included. + let r11 : qword = v(R11); + write_rflags((r11 & 0x00000000003C7FD7) | 0x0000000000000002); + VIF = r11[19]; + VIP = r11[20]; + // "CS.Selector := CS.Selector OR 3; (* RPL forced to 3 *)" (SDM), + // "CS.sel = (MSR_STAR.SYSRET_CS + 16) OR 3" or "MSR_STAR.SYSRET_CS OR + // 3" (APM), with fixed 64-bit or 32-bit code at DPL 3. + write_segreg(CS, (if pfx.rex_w then sysret_cs + 0x0010 else sysret_cs) | 0x0003); + SegCache[CS] = fast_call_code(3, pfx.rex_w); + // SS, where the manuals differ. The SDM forces the RPL to 3 and loads + // fixed values: "SS.Selector := (IA32_STAR[63:48]+8) OR 3; ... SS.Base + // := 0; SS.Limit := FFFFFH; SS.Type := 3; SS.S := 1; SS.DPL := 3; SS.P + // := 1; SS.B := 1; SS.G := 1". The APM loads the selector alone, + // "SS.sel = MSR_STAR.SYSRET_CS + 8 // SS selector is changed, // SS + // base, limit, attributes unchanged" (p.494), "and its RPL is not + // forced to 3" (p.492). + let apm_ss : bool = undefined; + write_segreg(SS, if apm_ss then sysret_cs + 0x0008 else (sysret_cs + 0x0008) | 0x0003); + if ~(apm_ss) then SegCache[SS] = fast_call_stack(3); + cur_cpl = 3; + set_mode(if pfx.rex_w then LongMode else CompatibilityMode); + next_rip = Some(new_rip) + } else { + // SYSRET_NON_64BIT_MODE (APM p.494): "CS.sel = MSR_STAR.SYSRET_CS OR 3 + // ... CS.attr = 32-bit code,dpl3; temp_RIP.d = RCX; SS.sel = + // MSR_STAR.SYSRET_CS + 8 // SS selector is changed. // SS base, limit, + // attributes unchanged. RFLAGS.IF = 1; CPL = 3". + write_segreg(CS, sysret_cs | 0x0003); + SegCache[CS] = fast_call_code(3, false); + write_segreg(SS, sysret_cs + 0x0008); + IF_flag = bitone; + cur_cpl = 3; + next_rip = Some(zero_extend(v(32, RCX))) + } +} + +// SYSENTER. SDM Vol.2B SYSENTER (4-702): "IF CR0.PE = 0 OR (... +// IA32_SYSENTER_CS[15:2] = 0) THEN #GP(0)", then "RFLAGS.VM := 0; +// RFLAGS.IF := 0", RSP := IA32_SYSENTER_ESP and RIP := IA32_SYSENTER_EIP +// (bits 31:0 outside IA-32e mode), CS := IA32_SYSENTER_CS[15:0] AND FFFCH +// and SS := CS + 8 with fixed code and stack at CPL 0, and 64-bit mode in +// IA-32e mode ("When executed in IA-32e mode, the SYSENTER instruction +// transitions the logical processor to 64-bit mode; otherwise, the logical +// processor remains in protected mode", 4-701). The APM gives the same +// outside long mode (Vol.3 SYSENTER pp.488-489: "If SYSENTER is used in +// real mode, a #GP is raised", #GP if "MSR_SYSENTER_CS was a null +// selector", VM and IF cleared) and makes SYSENTER #UD in long mode ("An +// invalid-opcode exception occurs if this instruction is used in long +// mode"), where the model executes the SDM's. +val exec_sysenter : unit -> unit +function exec_sysenter() = { + let sysenter_cs : qword = __rdmsr(0x00000174); + if CR0[0] == 0b0 | sysenter_cs[15..2] == zeros() then raise_GP0(); + let ia32e : bool = EFER[10] == 0b1; + // The selectors outside long mode, where the manuals differ: the SDM + // forces the RPL to 0, "CS.Selector := IA32_SYSENTER_CS[15:0] AND FFFCH" + // and "SS.Selector := CS.Selector + 8"; the APM takes "MSR_SYSENTER_CS: + // Contains the CS selector of the called procedure. The SS selector is + // set to MSR_SYSENTER_CS + 8" (p.488). + let cs_sel : word = if ~(ia32e) & (undefined : bool) then sysenter_cs[15..0] + else sysenter_cs[15..0] & 0xFFFC; + write_segreg(CS, cs_sel); + SegCache[CS] = fast_call_code(0, ia32e); + write_segreg(SS, cs_sel + 0x0008); + SegCache[SS] = fast_call_stack(0); + cur_cpl = 0; + // Leaving virtual-8086 mode clears VM. + cur_mode = if ia32e then LongMode else ProtectedMode; + IF_flag = 0b0; + let sysenter_esp : qword = __rdmsr(0x00000175); + let sysenter_eip : qword = __rdmsr(0x00000176); + v(RSP) = if ia32e then sysenter_esp else zero_extend(sysenter_esp[31..0]); + next_rip = Some(if ia32e then sysenter_eip else zero_extend(sysenter_eip[31..0])) +} + +// SYSEXIT. SDM Vol.2B SYSEXIT (4-706): "IF IA32_SYSENTER_CS[15:2] = 0 OR +// CR0.PE = 0 OR CPL ≠ 0 THEN #GP(0)", which in virtual-8086 mode, at CPL +// 3, is "#GP(0) The SYSEXIT instruction is not recognized in virtual-8086 +// mode" (4-707); with a 64-bit operand size also "If RCX or RDX contains a +// non-canonical address" (64-Bit Mode Exceptions). Then RSP := RCX and +// RIP := RDX (ECX and EDX without REX.W), CS := IA32_SYSENTER_CS + 32 (64- +// bit operand size) or + 16, RPL forced to 3, and SS := CS + 8, with fixed +// code and stack at CPL 3; 64-bit mode with REX.W, else compatibility mode +// in IA-32e mode and protected mode outside it. The APM's exception table +// (Vol.3 SYSEXIT p.491) has the same #GP cases outside long mode ("This +// instruction is only recognized in protected mode" for real and +// virtual-8086 mode, "CPL was not 0", "MSR_SYSENTER_CS was a null +// selector") and #UD in long mode, where the model executes the SDM's. +// +// The SDM's 64-bit-mode list has "#GP(0) If IA32_SYSENTER_CS = 0" where +// its Operation section has bits 15:2: for IA32_SYSENTER_CS from 1 to 3 in +// 64-bit mode the SDM gives both a #GP(0) and the return. The model +// follows the Operation section, the instruction's definition. +val exec_sysexit : Prefixes -> unit +function exec_sysexit(pfx) = { + let sysenter_cs : qword = __rdmsr(0x00000174); + if sysenter_cs[15..2] == zeros() | CR0[0] == 0b0 | cur_cpl != 0 then raise_GP0(); + if pfx.rex_w & ~(is_canonical_linear(v(64, RCX)) & is_canonical_linear(v(64, RDX))) then raise_GP0(); + // The selectors outside long mode, where the manuals differ: the SDM + // forces the RPL to 3, "CS.Selector := CS.Selector OR 3" and + // "SS.Selector := CS.Selector + 8"; the APM gives them as "MSR + // SYSENTER_CS+16" and "MSR SYSENTER_CS+24" (p.490). + let base : word = sysenter_cs[15..0] + (if pfx.rex_w then 0x0020 else 0x0010); + let cs_sel : word = if EFER[10] == 0b0 & (undefined : bool) then base else base | 0x0003; + write_segreg(CS, cs_sel); + SegCache[CS] = fast_call_code(3, pfx.rex_w); + write_segreg(SS, cs_sel + 0x0008); + SegCache[SS] = fast_call_stack(3); + cur_cpl = 3; + if pfx.rex_w then { + cur_mode = LongMode; + v(RSP) = v(64, RCX); + next_rip = Some(v(64, RDX)) + } else { + set_mode(if EFER[10] == 0b1 then CompatibilityMode else ProtectedMode); + v(32, RSP) = v(32, RCX); + next_rip = Some(zero_extend(v(32, RDX))) + } +} + +val dispatch_2byte_gpr : (range(0, 255), Prefixes) -> unit +function dispatch_2byte_gpr(op, pfx) = { + // Descriptor-query/task-register instructions are not recognized in + // virtual-8086 mode (SDM Vol.2 SLDT/STR/LLDT/LTR/VERR/VERW/LAR/LSL). + if cur_mode == Virtual8086Mode & (op == 0 | op == 2 | op == 3) then raise_UD(); + match op { + // 0F 00: Group 6 (SLDT, STR, LLDT, LTR, VERR, VERW) + 0 => { + let modrm = fetch(1); + let reg_field : range(0, 7) = unsigned(modrm[5..3]); + match reg_field { + // 0F 00 /0: SLDT r/m16 — Store LDTR + 0 => { + let dest = modrm_rm(modrm, pfx); + match dest { + RM_reg(r) => v(r) = LDTR, + RM_mem(m) => v(m) = LDTR, + } + }, + + // 0F 00 /1: STR r/m16 — Store Task Register + 1 => { + let dest = modrm_rm(modrm, pfx); + match dest { + RM_reg(r) => v(r) = TR, + RM_mem(m) => v(m) = TR, + } + }, + + // 0F 00 /2: LLDT r/m16 — Load LDT Register (requires CPL=0) + 2 => { + if cur_mode == RealMode then raise_UD(); + if cur_cpl != 0 then raise_GP0(); + let src = modrm_rm(modrm, pfx); + let sel : word = v(src); + if sel[15..2] == zeros() then { + LDTR = sel; + LDTR_valid = false + } else { + let err = selector_error_code(sel); + let off : qword = zero_extend(sel & 0xFFF8); + let size : int = if EFER[10] == 0b1 then 16 else 8; + if sel[2] == 0b1 | unsigned(off) + size - 1 > unsigned(GDTR_limit) then raise_GP(err); + let lo : dword = read_mem_implicit(GDTR_base + off); + let hi : dword = read_mem_implicit(GDTR_base + off + 4); + let desc = parse_seg_descriptor(lo, hi); + if desc.seg_s == 0b1 | desc.seg_type != 0x2 then raise_GP(err); + if desc.seg_present == 0b0 then throw Fault(EXN_NP, err); + var base = desc.seg_base; + if EFER[10] == 0b1 then { + let upper : dword = read_mem_implicit(GDTR_base + off + 8); + base = upper @ base[31..0] + }; + LDTR = sel; + LDTR_base = base; + LDTR_limit = desc.seg_limit; + LDTR_valid = true + } + }, + + // 0F 00 /3: LTR r/m16 — Load Task Register (SDM Vol.2A LTR) + 3 => { + // Not recognized in real-address mode; CPL must be 0. + if cur_mode == RealMode then raise_UD(); + if cur_cpl != 0 then raise_GP0(); + let src = modrm_rm(modrm, pfx); + let sel : word = v(src); + // Operation: a null selector is #GP(0); an LDT selector or an + // index beyond the GDT limit is #GP(selector), before the + // descriptor is read. In 64-bit mode the TSS descriptor is + // 16 bytes. + if (sel & 0xFFFC) == zeros() then raise_GP0(); + let err : dword = selector_error_code(sel); + if sel[2] == 0b1 then raise_GP(err); + let desc_off : qword = zero_extend(sel & 0xFFF8); + let desc_size : int = if cur_mode == LongMode then 16 else 8; + if unsigned(desc_off) + desc_size - 1 > unsigned(GDTR_limit) then raise_GP(err); + // Implicit supervisor reads of the descriptor. + let desc_addr : qword = GDTR_base + desc_off; + let desc_lo : dword = read_mem_implicit(desc_addr); + let desc_hi : dword = read_mem_implicit(desc_addr + 4); + // An available TSS is a system descriptor (S = 0) of type 1001B + // (32/64-bit) or, in protected mode only, 0001B (16-bit); a + // busy TSS or any other descriptor is #GP(selector), and a + // descriptor that is not present is #NP(selector). + let typ : bits(4) = desc_hi[11..8]; + let available_tss : bool = + desc_hi[12] == 0b0 & (typ == 0x9 | (typ == 0x1 & cur_mode == ProtectedMode)); + if ~(available_tss) then raise_GP(err); + if desc_hi[15] == 0b0 then throw Fault(EXN_NP, err); + // Base = desc[63:56] @ desc[39:32] @ desc[31:16], extended by the + // upper 8 bytes in 64-bit mode, whose type field must be zero. + var base : qword = zero_extend(desc_hi[31..24] @ desc_hi[7..0] @ desc_lo[31..16]); + if cur_mode == LongMode then { + let ext_lo : dword = read_mem_implicit(desc_addr + 8); + let ext_hi : dword = read_mem_implicit(desc_addr + 12); + if ext_hi[12..8] != 0b00000 then raise_GP(err); + base = ext_lo @ base[31..0] + }; + // Limit = desc[51:48] @ desc[15:0] (with granularity) + let raw_limit : bits(20) = desc_hi[19..16] @ desc_lo[15..0]; + let limit : dword = if desc_hi[23] == 0b1 then zero_extend(raw_limit) @ 0xFFF + else zero_extend(raw_limit); + // TSSsegmentDescriptor(busy) := 1: type bit 1 of the descriptor in + // memory, then the task register itself. + write_mem_linear(desc_addr + 4, desc_hi | 0x00000200); + TR = sel; + TR_base = base; + TR_limit = limit; + TR_type = typ | 0x2 + }, + + // 0F 00 /4: VERR r/m16 — Verify segment readable, set ZF + 4 => { + let src = modrm_rm(modrm, pfx); + let selector : word = v(src); + if (selector & 0xFFFC) == zeros() then { + ZF = 0b0 + } else { + let desc_addr = descriptor_address(selector); + if ~(descriptor_in_bounds(selector)) then { + ZF = 0b0 + } else { + let desc_hi : dword = read_mem_implicit(desc_addr + 4); + let present : bit = desc_hi[15]; + let s_bit : bit = desc_hi[12]; + // Readable: data segments always readable; code readable if R bit set + let is_code : bit = desc_hi[11]; + let readable : bit = desc_hi[9] | ~(is_code); + if present == 0b0 | s_bit == 0b0 | readable == 0b0 + | ~(desc_privilege_ok(desc_hi, selector)) then { + ZF = 0b0 + } else { + ZF = 0b1 + } + } + } + }, + + // 0F 00 /5: VERW r/m16 — Verify segment writable, set ZF + 5 => { + let src = modrm_rm(modrm, pfx); + let selector : word = v(src); + if (selector & 0xFFFC) == zeros() then { + ZF = 0b0 + } else { + let desc_addr = descriptor_address(selector); + if ~(descriptor_in_bounds(selector)) then { + ZF = 0b0 + } else { + let desc_hi : dword = read_mem_implicit(desc_addr + 4); + let present : bit = desc_hi[15]; + let s_bit : bit = desc_hi[12]; + let is_code : bit = desc_hi[11]; + // Writable: only data segments with W bit set + let writable : bit = desc_hi[9] & ~(is_code); + if present == 0b0 | s_bit == 0b0 | writable == 0b0 + | ~(desc_privilege_ok(desc_hi, selector)) then { + ZF = 0b0 + } else { + ZF = 0b1 + } + } + } + }, + _ => raise_UD(), + } + }, + + // 0F 01: Group 7 (privileged/system instructions) + 1 => { + let modrm = fetch(1); + let modrm_val : range(0, 255) = unsigned(modrm); + let reg_field : range(0, 7) = unsigned(modrm[5..3]); + let mod_field : range(0, 3) = unsigned(modrm[7..6]); + + match modrm_val { + // 0F 01 D1: XSETBV — Write XCR (ECX selects register, EDX:EAX = value) + // SDM: #GP(0) if CPL > 0; #GP(0) if ECX != 0 (only XCR0 exists); + // #GP(0) if attempting to set unsupported bits or violating constraints. + // Unconditional VM exit in non-root (SDM §26.1.2), after the #UD of + // the XSAVE feature set ("invalid-opcode exceptions" "have priority + // over VM exits", Vol.3C §28.1.1 p.28-1). + 209 => { + check_xsave_enabled(true); + vmx_exit_xsetbv(); + if cur_cpl != 0 then raise_GP0(); + let ecx_val : dword = v(RCX); + if ecx_val != 0x00000000 then raise_GP0(); + let new_xcr0 : qword = v(32, RDX) @ v(32, RAX); + // Any bit set that is not in XCR0_SUPPORTED → #GP + if (new_xcr0 & ~(XCR0_SUPPORTED)) != zeros() then raise_GP0(); + // Bit 0 (x87) must always be 1 + if new_xcr0[0] == 0b0 then raise_GP0(); + // Can't set AVX (bit 2) without SSE (bit 1) + if new_xcr0[2..1] == 0b10 then raise_GP0(); + // Bits 7:5 (AVX-512) must be all-or-nothing, and require bits 2:1 + let avx512_bits : bits(3) = new_xcr0[7..5]; + if avx512_bits != 0b000 & avx512_bits != 0b111 then raise_GP0(); + if avx512_bits == 0b111 & (new_xcr0[2] == 0b0 | new_xcr0[1] == 0b0) then raise_GP0(); + // Bits 18:17 (AMX) must be both-or-neither + if new_xcr0[17] != new_xcr0[18] then raise_GP0(); + XCR0 = new_xcr0 + }, + + // 0F 01 D0: XGETBV — Read XCR0. ECX = 1 (CPUID.(0DH,1):EAX[2]) + // returns "the logical-AND of XCR0 and the current value of the + // XINUSE state-component bitmap" (SDM XGETBV; APM Vol.4 XGETBV + // p.1763). The SDM's "always sets EAX[1] to 1 if XCR0[1] = 1 and + // MXCSR does not have its RESET value of 1F80H" (Vol.1 §13.6 + // p.13-18) the APM does not have, so EAX[1] is undefined then + // (XINUSE[1] or 1), and the emulator takes the SDM's 1. Any other + // ECX is #GP(0), which "includes ECX = 1 if + // CPUID.0DH.01H:EAX.XGETBV1[2] = 0". + 208 => { + check_xsave_enabled(true); + let ecx_val : dword = v(RCX); + if ecx_val == 0x00000000 | (ecx_val == 0x00000001 & has_xgetbv1) then { + var xcr : qword = XCR0; + if ecx_val == 0x00000001 then { + xcr = XCR0 & xinuse(); + if XCR0[1] == bitone & __stmxcsr() != 0x00001F80 then + xcr[1] = if (undefined : bool) then xcr[1] else bitone + }; + v(RAX) = xcr[31..0]; + v(RDX) = xcr[63..32] + } else { + raise_GP0() + } + }, + + // 0F 01 CA: CLAC — Clear AC flag (SMAP). With F2 the encoding is + // ERETS and with F3 ERETU (SDM Vol.2A: FRED event returns), which + // the model does not implement: #UD, as on a processor without FRED. + // CLAC and STAC are #UD "If the CPL > 0", "If + // CPUID.07H.00H:EBX.SMAP[20] = 0", and in virtual-8086 mode, "not + // recognized" there (SDM Vol.2A CLAC 3-139, Vol.2B STAC 4-670); the + // APM has the same three (Vol.3 CLAC p.381, STAC p.477: "Instruction + // not supported by CPUID", "Instruction is not supported in virtual + // mode", "CPL was not 0"). + 202 => { + if pfx.has_rep | pfx.has_repne then raise_UD(); + if ~(has_smap) | cur_mode == Virtual8086Mode | cur_cpl != 0 then raise_UD(); + AC_flag = 0b0 + }, + + // 0F 01 CB: STAC — Set AC flag (SMAP) + 203 => { + if ~(has_smap) | cur_mode == Virtual8086Mode | cur_cpl != 0 then raise_UD(); + AC_flag = 0b1 + }, + + // 0F 01 E8: SERIALIZE — NOP in sequential interpreter + 232 => (), + + // 0F 01 EE: RDPKRU — Read Protection Key Rights (ECX must be 0) + // Returns PKRU in EAX, 0 in EDX. We don't implement PKU, so + // return 0 (all access allowed). F3 0F 01 EE is CLUI (SDM + // Vol.2A: "#UD if CPUID.07H.00H:EDX.UINTR[5] = 0"), not implemented. + 238 => { + if pfx.has_rep then raise_UD(); + v(RAX) = 0x00000000; + v(RDX) = 0x00000000 + }, + + // 0F 01 EF: WRPKRU — Write Protection Key Rights (NOP, no PKU). + // F3 0F 01 EF is STUI (UINTR), not implemented: #UD. + 239 => { + if pfx.has_rep then raise_UD() + }, + + // 0F 01 F9: RDTSCP — Read TSC and IA32_TSC_AUX + // SDM: #GP(0) if CR4.TSD (bit 2) = 1 and CPL > 0 + 249 => { + if CR4[2] == 0b1 & cur_cpl != 0 then raise_GP0(); + vmx_exit_if_rdtscp(); + let tsc = __rdtsc(); + v(RAX) = tsc[31..0]; + v(RDX) = tsc[63..32]; + v(RCX) = __rdmsr(0xC0000103)[31..0] + }, + + // 0F 01 C1: VMCALL (SDM Vol.3C §31.2.6) + 193 => exec_vmcall(), + + // 0F 01 C2: VMLAUNCH (SDM Vol.3C §31.2.7) + 194 => exec_vmlaunch(), + + // 0F 01 C3: VMRESUME (SDM Vol.3C §31.2.7) + 195 => exec_vmresume(), + + // 0F 01 C4: VMXOFF (SDM Vol.3C §31.2.2) + 196 => { + vmx_exit_vmx_insn(VMEXIT_VMXOFF); + exec_vmxoff() + }, + + // 0F 01 F8: SWAPGS, in 64-bit mode at CPL 0: "IF CS.L ≠ 1 (* Not + // in 64-Bit Mode *) ... THEN #UD; FI; IF CPL ≠ 0 THEN #GP(0)" (SDM + // Vol.2B SWAPGS 4-696); "Executing SWAPGS in any other mode + // generates an undefined opcode exception" (APM Vol.3 SWAPGS p.482). + 248 => { + if cur_mode != LongMode then raise_UD(); + if cur_cpl != 0 then raise_GP0(); + let tmp = SegCache[GS].seg_base; + SegCache[GS].seg_base = KERNEL_GS_BASE; + KERNEL_GS_BASE = tmp + }, + + _ => { + // Group 7: dispatch by reg_field, then check memory vs register + let dest = modrm_rm(modrm, pfx); + match reg_field { + // 0F 01 /0: SGDT m — Store GDTR (memory only) + // Non-64-bit: 6 bytes (2 limit + 4 base). + // 64-bit: 10 bytes (2 limit + 8 base). SDM Vol.2A LGDT/LIDT. + 0 => match dest { + RM_mem(m) => { + if cur_mode == LongMode then + write_mem(80, m, GDTR_base @ GDTR_limit) + else + write_mem(48, m, GDTR_base[31..0] @ GDTR_limit) + }, + RM_reg(_) => raise_UD(), + }, + + // 0F 01 /1: SIDT m — Store IDTR (memory only) + 1 => match dest { + RM_mem(m) => { + if cur_mode == LongMode then + write_mem(80, m, IDTR_base @ IDTR_limit) + else + write_mem(48, m, IDTR_base[31..0] @ IDTR_limit) + }, + RM_reg(_) => raise_UD(), + }, + + // 0F 01 /2: LGDT m — Load GDTR (memory only, requires CPL=0) + // SDM Vol.2A §LGDT Operation: + // 16: Limit := SRC[0:15]; Base := SRC[16:47] AND 00FFFFFFH; + // 32: Limit := SRC[0:15]; Base := SRC[16:47]; + // 64: Limit := SRC[0:15]; Base := SRC[16:79]; + // 16 and 32 both read 6 bytes (2 limit + 4 base); 16 + // masks the base to 24 bits. 64 reads 10 bytes (2 + 8). + // In 64-bit mode, the operand size is forced to 64-bit + // regardless of REX.W (SDM: "In 64-bit mode, the instruction's + // operand size is fixed at 8+2 bytes"). + 2 => { + if cur_cpl != 0 then raise_GP0(); + match dest { + RM_mem(m) => { + if cur_mode == LongMode then { + let d : bits(80) = read_mem(m); + GDTR_base = d[79..16]; + GDTR_limit = d[15..0] + } else { + let d : bits(48) = read_mem(m); + GDTR_base = if opsize(pfx) == 16 + then zero_extend(d[39..16]) + else zero_extend(d[47..16]); + GDTR_limit = d[15..0] + } + }, + RM_reg(_) => raise_UD(), + } + }, + + // 0F 01 /3: LIDT m — Load IDTR (memory only, requires CPL=0) + // Same operand-size semantics as LGDT. + 3 => { + if cur_cpl != 0 then raise_GP0(); + match dest { + RM_mem(m) => { + if cur_mode == LongMode then { + let d : bits(80) = read_mem(m); + IDTR_base = d[79..16]; + IDTR_limit = d[15..0] + } else { + let d : bits(48) = read_mem(m); + IDTR_base = if opsize(pfx) == 16 + then zero_extend(d[39..16]) + else zero_extend(d[47..16]); + IDTR_limit = d[15..0] + } + }, + RM_reg(_) => raise_UD(), + } + }, + + // 0F 01 /4: SMSW r/m16 — Store Machine Status Word + // No privilege check required (accessible from any CPL). + // SDM: stores low 16 bits of CR0 to r/m16. With 32-bit + // register operand, stores low 32 bits; with 64-bit, all 64. + // Outside 64-bit mode "when the destination operand is a + // 32-bit register, the low-order 16 bits of register CR0 are + // copied into the low-order 16 bits of the register and the + // high-order 16 bits are undefined" (SDM Vol.2B SMSW p.4-658), + // where the APM stores "the low 32 bits of CR0" (Vol.3 SMSW + // p.476). + 4 => match dest { + RM_reg(r) => { + let os = opsize(pfx); + if os == 32 & cur_mode != LongMode then + v(r) = (undefined : word) @ CR0[15..0] + else + v(r) = CR0[(os - 1) .. 0] + }, + RM_mem(m) => v(m) = CR0[15..0], + }, + + // 0F 01 /6: LMSW r/m16 — Load Machine Status Word (requires CPL=0) + 6 => { + if cur_cpl != 0 then raise_GP0(); + let msw : word = v(dest); + // LMSW sets low 4 bits of CR0; only PE (bit 0) is sticky + // (cannot clear PE once set). MP/EM/TS are freely assignable. + var new_cr0 = CR0; + new_cr0[3..1] = msw[3..1]; + new_cr0[0] = msw[0] | CR0[0]; + CR0 = new_cr0; + // SDM Vol.2A LMSW: setting PE enters protected mode. Retain + // segment caches until reloaded (Vol.3A 12.9.1, step 9). + if cur_mode == RealMode & new_cr0[0] == 0b1 then + cur_mode = ProtectedMode + }, + + // 0F 01 /7: INVLPG m — Invalidate TLB Entry (memory only, requires CPL=0) + 7 => { + if cur_cpl != 0 then raise_GP0(); + match dest { + RM_mem(m) => { + vmx_exit_if_invlpg(seg_linear(m, 1)); + __tlb_flush() + }, + RM_reg(_) => raise_UD(), + } + }, + _ => raise_UD(), + } + }, + } + }, + + // 0F 02: LAR r, r/m16 — Load Access Rights Byte + // Reads descriptor from GDT, validates type and privilege, loads access rights. + 2 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + let selector : word = v(src); + if (selector & 0xFFFC) == zeros() then { + ZF = 0b0 + } else { + let desc_addr = descriptor_address(selector); + if ~(descriptor_in_bounds(selector)) then { + ZF = 0b0 + } else { + let desc_hi : dword = read_mem_implicit(desc_addr + 4); + if ~(lar_type_valid_64(desc_hi)) | ~(desc_privilege_ok(desc_hi, selector)) then { + ZF = 0b0 + } else { + let ar : qword = zero_extend(zero_extend(desc_hi[23..0]) & 0x00FFFF00 : dword); + v(reg) = ar[(os - 1) .. 0]; + ZF = 0b1 + } + } + } + }, + + // 0F 03: LSL r, r/m16 — Load Segment Limit + // Reads descriptor from GDT, validates type and privilege, loads segment limit. + 3 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + let selector : word = v(src); + if (selector & 0xFFFC) == zeros() then { + ZF = 0b0 + } else { + let desc_addr = descriptor_address(selector); + if ~(descriptor_in_bounds(selector)) then { + ZF = 0b0 + } else { + let desc_lo : dword = read_mem_implicit(desc_addr); + let desc_hi : dword = read_mem_implicit(desc_addr + 4); + if ~(lsl_type_valid_64(desc_hi)) | ~(desc_privilege_ok(desc_hi, selector)) then { + ZF = 0b0 + } else { + let limit_lo : word = desc_lo[15..0]; + let limit_hi : bits(4) = desc_hi[19..16]; + let granularity : bit = desc_hi[23]; + let limit : dword = zero_extend(limit_hi @ limit_lo); + let fl_ext : qword = zero_extend(if granularity == 0b1 + then (limit << 12) | 0x00000FFF + else limit); + v(reg) = fl_ext[(os - 1) .. 0]; + ZF = 0b1 + } + } + } + }, + + // 0F 05: SYSCALL. #UD if IA32_EFER.SCE = 0, in either manual and + // whatever the mode (SDM Vol.2B SYSCALL 4-699; APM Vol.3 SYSCALL + // p.486); then exec_syscall. + 5 => { + if EFER[0] != 0b1 then raise_UD(); + if system_mode then exec_syscall() + else __syscall(RIP, read_rflags()) + }, + + // 0F 06: CLTS — Clear TS flag in CR0 (requires CPL=0) + 6 => { + if cur_cpl != 0 then raise_GP0(); + CR0[3] = 0b0 // TS = bit 3 + }, + + // 0F 07: SYSRET (exec_sysret) + 7 => exec_sysret(pfx), + + // 0F 09: WBINVD — Write Back and Invalidate Cache (NOP, requires CPL=0) + // 0F 08: INVD — Invalidate Internal Caches (requires CPL=0) + // SDM: Flush(InternalCaches); SignalFlush(ExternalCaches); Continue + // Destructive: dirty cache lines discarded (not written back). + 8 => { + if cur_cpl != 0 then raise_GP0(); + vmx_exit_invd() + }, + + // 0F 09: WBINVD — Write Back and Invalidate Cache (requires CPL=0) + 9 => { + if cur_cpl != 0 then raise_GP0(); + vmx_exit_if_wbinvd() + }, + + // 0F 0B: UD2 + 11 => raise_UD(), + + // 0F 1F: Multi-byte NOP r/m (prefetch hint) + 31 => { + let modrm = fetch(1); + let _ = modrm_rm(modrm, pfx) // consume ModR/M + SIB + disp + }, + + // 0F 20: MOV reg, CRn — Read control register (requires CPL=0) + // REX.R extends reg field to access CR8 + 32 => { + if cur_cpl != 0 then raise_GP0(); + let modrm = fetch(1); + let rex_r_eff : bit = if pfx.has_rex then pfx.rex_r else 0b0; + let cr_idx : range(0, 15) = unsigned(rex_r_eff @ modrm[5..3]); + let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); + let cr_val : qword = match vmx_cr_read_shadow(cr_idx) { + Some(shadow_val) => shadow_val, + None() => match cr_idx { + 0 => CR0, + 2 => CR2, + 3 => CR3, + 4 => CR4, + 8 => zero_extend(__read_cr8()), + _ => raise_UD(), + }, + }; + v(rm_idx) = cr_val; + finish_system_register_move() + }, + + // 0F 22: MOV CRn, reg — Write control register (requires CPL=0) + // REX.R extends reg field to access CR8 + 34 => { + if cur_cpl != 0 then raise_GP0(); + let modrm = fetch(1); + let rex_r_eff : bit = if pfx.has_rex then pfx.rex_r else 0b0; + let cr_idx : range(0, 15) = unsigned(rex_r_eff @ modrm[5..3]); + let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); + let cr_val : qword = v(rm_idx); + vmx_exit_if_cr_write(cr_idx, cr_val); + match cr_idx { + 0 => { + // SDM Vol.2B MOV to CR: setting a reserved bit in CR0[63:32] is + // #GP(0), setting one in CR0[31:0] is ignored. Reserved: all but + // PE MP EM TS ET NE (5:0), WP (16), AM (18), NW CD PG (31:29). + if cr_val[63..32] != zeros() then raise_GP0(); + let cr_val : qword = cr_val & 0x00000000E005003F; + // #GP(0) on invalid combinations: PG = 1 with PE = 0, or CD = 0 + // with NW = 1; and in 64-bit mode on clearing PG. + if cr_val[31] == 0b1 & cr_val[0] == 0b0 then raise_GP0(); + if cr_val[29] == 0b1 & cr_val[30] == 0b0 then raise_GP0(); + if cur_mode == LongMode & cr_val[31] == 0b0 then raise_GP0(); + CR0 = cr_val; + // EFER.LMA = EFER.LME & CR0.PG (SDM Vol.3 §4.1.1) + let lme = EFER[8]; + let pg = cr_val[31]; + EFER[10] = lme & pg; // Update LMA + if lme == 0b1 & pg == 0b1 then { + // IA-32e mode: 64-bit if CS.L=1, compatibility if CS.L=0 + if SegCache[CS].seg_l == 0b1 then + cur_mode = LongMode + else + cur_mode = CompatibilityMode + } else if cr_val[0] == 0b1 then { + cur_mode = ProtectedMode + } else { + cur_mode = RealMode + } + }, + 2 => CR2 = cr_val, + 3 => { CR3 = cr_val; __tlb_flush() }, + 4 => { + // SDM Vol.2B MOV to CR: #GP(0) on setting a reserved bit in CR4. + // Vol.3A §2.5 defines bits 14:0, 25:16, 27, 28 and 32; the rest + // (15, 26, 31:29, 63:33) are reserved. + if (cr_val & 0xFFFFFFFEE4008000) != zeros() then raise_GP0(); + // #GP(0) on leaving IA-32e mode by clearing CR4.PAE + if EFER[10] == 0b1 & cr_val[5] == 0b0 then raise_GP0(); + // SDM: #GP(0) if changing CR4.LA57 (bit 12) while paging is enabled + if CR0[31] == 0b1 & cr_val[12] != CR4[12] then raise_GP0(); + CR4 = cr_val + }, + 8 => { + // SDM Vol.2B MOV to CR: #GP(0) on setting a reserved bit in CR8; + // only the TPR field, bits 3:0, is defined (Vol.3A §2.5). + if cr_val[63..4] != zeros() then raise_GP0(); + CR8 = cr_val[3..0]; + __write_cr8(CR8) + }, + _ => raise_UD(), + }; + finish_system_register_move() + }, + + // 0F 21: MOV reg, DRn — Read debug register (requires CPL=0) + // SDM MOV DR: CR4.DE=1 and DR4/DR5 → #UD; otherwise DR4/5 alias DR6/7; + // CPL > 0 → #GP(0); DR7.GD → #DB before the access (§20.3.1.3). + // Outside 64-bit mode the read returns the low 32 bits (§20.2.6). + 33 => { + let modrm = fetch(1); + let dr_idx : range(0, 7) = unsigned(modrm[5..3]); + if (dr_idx == 4 | dr_idx == 5) & CR4[3] == 0b1 then raise_UD(); + if cur_cpl != 0 then raise_GP0(); + general_detect_check(); + vmx_exit_if_dr_access(); + let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); + let dr_val : qword = match dr_idx { + 0 => DR0, + 1 => DR1, + 2 => DR2, + 3 => DR3, + 4 => DR6, // alias when CR4.DE=0 + 5 => DR7, // alias when CR4.DE=0 + 6 => DR6, + 7 => DR7, + }; + if cur_mode == LongMode then v(rm_idx) = dr_val + else v(32, rm_idx) = dr_val[31..0]; + finish_system_register_move() + }, + + // 0F 23: MOV DRn, reg — Write debug register (requires CPL=0) + // Same checks as the read. In 64-bit mode a 1 in bits 63:32 of the + // value for DR6 or DR7 is #GP(0) (§20.2.6); outside it the upper 32 + // bits are filled with zeros. DR6 keeps only its status bits (B0-B3, + // BD, BS, BT) over fixed reserved bits; DR7 keeps its enable and + // condition fields, bit 10 reads as 1 and the other reserved bits as 0. + 35 => { + let modrm = fetch(1); + let dr_idx : range(0, 7) = unsigned(modrm[5..3]); + if (dr_idx == 4 | dr_idx == 5) & CR4[3] == 0b1 then raise_UD(); + if cur_cpl != 0 then raise_GP0(); + general_detect_check(); + vmx_exit_if_dr_access(); + let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); + let dr_val : qword = if cur_mode == LongMode then v(rm_idx) else zero_extend(v(32, rm_idx)); + let status_reg : bool = dr_idx >= 4; + if status_reg & dr_val[63..32] != zeros() then raise_GP0(); + match dr_idx { + 0 => DR0 = dr_val, + 1 => DR1 = dr_val, + 2 => DR2 = dr_val, + 3 => DR3 = dr_val, + 4 => DR6 = (dr_val & 0x000000000000E00F) | 0x00000000FFFF0FF0, // alias when CR4.DE=0 + 5 => DR7 = (dr_val & 0x00000000FFFF2BFF) | 0x0000000000000400, // alias when CR4.DE=0 + 6 => DR6 = (dr_val & 0x000000000000E00F) | 0x00000000FFFF0FF0, + 7 => DR7 = (dr_val & 0x00000000FFFF2BFF) | 0x0000000000000400, + }; + finish_system_register_move() + }, + + // 0F 30: WRMSR — Write MSR (requires CPL=0) + 48 => { + if cur_cpl != 0 then raise_GP0(); + vmx_exit_if_wrmsr(); + let ecx : dword = v(RCX); + let msr_val : qword = v(32, RDX) @ v(32, RAX); + + // Handle EFER specially since it has a Sail register + if ecx == 0xC0000080 then { + EFER = msr_val + } else if ecx == 0x0000003A then { + // IA32_FEATURE_CONTROL: #GP(0) if lock bit (bit 0) is already set + if ia32_feature_control[0] == 0b1 then raise_GP0(); + ia32_feature_control = msr_val + } else if ecx == 0xC0000100 then { + SegCache[FS].seg_base = msr_val + } else if ecx == 0xC0000101 then { + SegCache[GS].seg_base = msr_val + } else if ecx == 0xC0000102 then { + KERNEL_GS_BASE = msr_val + } else if ecx == 0x00000DA0 then { + // IA32_XSS (0xDA0): supervisor state components for XSAVES/XRSTORS. + // It exists with XSAVES (SDM Vol.1 §13.2 p.13-4), and "A bit can + // be set in the IA32_XSS MSR if and only if the corresponding bit + // is set in" CPUID.0DH.01H:EDX:ECX, which has none. + if ~(has_xsaves) then raise_GP0(); + if msr_val != zeros() then raise_GP0() + } else if ecx == 0x000000E1 then { + // IA32_UMWAIT_CONTROL (0xE1, SDM Vol.2B TPAUSE/UMWAIT): the OS + // limit on a wait in bits 31:2 and the C0.2 disable in bit 0; bit + // 1 and bits 63:32 are reserved. Exists with WAITPKG. + if ~(has_waitpkg) then raise_GP0(); + if msr_val[63..32] != zeros() | msr_val[1] == bitone then raise_GP0(); + __wrmsr(ecx, msr_val) + } else if ecx == 0x000001C4 | ecx == 0x000001C5 then { + // IA32_XFD (1C4H) and IA32_XFD_ERR (1C5H), SDM Vol.1 §13.14 + // p.13-27: exist with XFD (CPUID.0DH.01H:EAX[4]); "Bit i of either + // MSR can be set to 1 only if CPUID.0DH.i:ECX[2] is enumerated as + // 1", and WRMSR of another bit is #GP. + if ~(has_xfd) then raise_GP0(); + if (msr_val & ~(xfd_supported())) != zeros() then raise_GP0(); + if ecx == 0x000001C4 then IA32_XFD = msr_val else IA32_XFD_ERR = msr_val + } else if ecx == 0x00000D93 then { + // IA32_PASID (D93H): exists with ENQCMD; bits 19:0 (PASID) and + // 31 (valid) are writable, and a value that sets a reserved bit, + // 30:20 or 63:32, is #GP(0) (SDM WRMSR). + if ~(has_enqcmd) then raise_GP0(); + if (msr_val & ~(0x00000000800FFFFF : qword)) != zeros() then raise_GP0(); + IA32_PASID = msr_val + } else if ecx >=_u 0x00000480 & ecx <=_u 0x00000491 then { + // VMX capability MSRs are read-only — #GP(0) on write + raise_GP0() + } else { + __wrmsr(ecx, msr_val) + } + }, + + // 0F 0D: PREFETCHW m8 (/1; SDM Vol.2B) and the reserved NOPs of the + // opcode's other forms. Every 0F 0D encoding is decoded with a ModR/M + // byte and behaves as NOP (SDM Vol.3B §25.15, "Reserved NOP"): the + // hint moves no architectural state and takes no memory fault. The + // APM defines the opcode as PREFETCH/PREFETCHW, where "only the memory + // form of ModRM is valid. The register form of ModRM causes an + // invalid-opcode exception" (Vol.3 PREFETCH, p.293-294), a #UD of one + // manual only, which the model does not raise. + 13 => { + let modrm = fetch(1); + let _ = modrm_rm(modrm, pfx) + }, + + // 0F 18-1E: PREFETCHh, CLDEMOTE (0F 1C /0) and the reserved NOPs. + // These all consume ModR/M and do nothing. + op if 24 <= op & op <= 30 => { + let modrm = fetch(1); + let _ = modrm_rm(modrm, pfx) + }, + + // 0F 31: RDTSC + // SDM: #GP(0) if CR4.TSD (bit 2) = 1 and CPL > 0 + 49 => { + if CR4[2] == 0b1 & cur_cpl != 0 then raise_GP0(); + vmx_exit_if_rdtsc(); + let tsc = __rdtsc(); + v(RAX) = tsc[31..0]; + v(RDX) = tsc[63..32] + }, + + // 0F 33: RDPMC — Read Performance-Monitoring Counter + // SDM pseudocode: + // IF (((CR4.PCE = 1) or (CPL = 0)) and (ECX indicates a supported counter)) + // THEN EAX := counter[31:0]; EDX := ZeroExtend(counter[MSCB:32]); + // ELSE #GP(0); + // FI; + // No performance counters are modeled, so ECX always indicates an + // unsupported counter → unconditional #GP(0). + 51 => raise_GP0(), + + // 0F 34: SYSENTER (exec_sysenter) + 52 => exec_sysenter(), + + // 0F 35: SYSEXIT (exec_sysexit) + 53 => exec_sysexit(pfx), + + // 0F 32: RDMSR — Read MSR (requires CPL=0) + 50 => { + if cur_cpl != 0 then raise_GP0(); + vmx_exit_if_rdmsr(); + let ecx : dword = v(RCX); + // Handle registers with Sail state specially + let msr : qword = match ecx { + 0xC0000080 => EFER, + 0x0000003A => ia32_feature_control, + // IA32_XSS exists with XSAVES and is always 0 (no supervisor state + // components supported) + 0x00000DA0 => { if ~(has_xsaves) then raise_GP0(); zeros() }, + // IA32_UMWAIT_CONTROL exists with WAITPKG; the value written, 0 at reset + 0x000000E1 => { if ~(has_waitpkg) then raise_GP0(); __rdmsr(ecx) }, + // IA32_XFD and IA32_XFD_ERR exist with XFD + 0x000001C4 => { if ~(has_xfd) then raise_GP0(); IA32_XFD }, + 0x000001C5 => { if ~(has_xfd) then raise_GP0(); IA32_XFD_ERR }, + // IA32_PASID exists with ENQCMD + 0x00000D93 => { if ~(has_enqcmd) then raise_GP0(); IA32_PASID }, + 0xC0000100 => SegCache[FS].seg_base, + 0xC0000101 => SegCache[GS].seg_base, + 0xC0000102 => KERNEL_GS_BASE, + // VMX Capability MSRs (SDM Appendix A) — read-only + 0x00000480 => 0x0098040000000001, // VMX_BASIC: rev=1, size=1024, WB, TRUE controls + 0x00000481 => 0x0000003F00000016, // VMX_PINBASED_CTLS + 0x00000482 => 0xFFF9FFFE0401E172, // VMX_PROCBASED_CTLS + 0x00000483 => 0x003FFFFF00036DFF, // VMX_EXIT_CTLS + 0x00000484 => 0x0000F3FF000011FF, // VMX_ENTRY_CTLS + 0x00000485 => 0x0000000000000020, // VMX_MISC + 0x00000486 => 0x0000000080000021, // VMX_CR0_FIXED0: PE+NE+PG must be 1 + 0x00000487 => 0x00000000FFFFFFFF, // VMX_CR0_FIXED1: all allowed + 0x00000488 => 0x0000000000002000, // VMX_CR4_FIXED0: VMXE must be 1 + 0x00000489 => 0x00000000FFFFFFFF, // VMX_CR4_FIXED1: all bits allowed + 0x0000048A => 0x000000000000002E, // VMX_VMCS_ENUM + 0x0000048B => 0x001010EA00000000, // VMX_PROCBASED_CTLS2: EPT, unrestricted guest, RDTSCP, WBINVD, INVPCID, XSAVES + 0x0000048C => 0x0000000006134141, // VMX_EPT_VPID_CAP: exec-only, 4-level walk, UC, WB, 2MB, 1GB, INVEPT + 0x0000048D => 0x0000003F00000000, // VMX_TRUE_PINBASED_CTLS + 0x0000048E => 0xFFF9FFFE04006172, // VMX_TRUE_PROCBASED_CTLS + 0x0000048F => 0x003FFFFF00036DFB, // VMX_TRUE_EXIT_CTLS + 0x00000490 => 0x0000F3FF000011FB, // VMX_TRUE_ENTRY_CTLS + 0x00000491 => 0x0000000000000000, // VMX_VMFUNC: no VM functions + 0x00000492 => 0x0000000000000000, // VMX_PROCBASED_CTLS3: no tertiary controls + _ => __rdmsr(ecx), + }; + v(RAX) = msr[31..0]; + v(RDX) = msr[63..32] + }, + + // 0F 40-4F: CMOVcc r, r/m + op if 64 <= op & op <= 79 => { + let cc : cc_idx = op - 64; + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + v(reg) = blend(v(os, reg), v(os, src), eval_cc(cc)) + }, + + // 0F 77: EMMS — set x87 tag word to all empty. NP 0F 77 (SDM Vol.2A + // EMMS): 66, F2 or F3 leaves it undefined; then #UD if CR0.EM = 1 and + // #NM if CR0.TS = 1, as for MMX. + 119 => { + if get_mandatory_prefix(pfx) != MP_NONE then raise_UD(); + check_cr0_sse(); + x87_tw = 0xFFFF; + x87_mmx_last = true + }, + + // 0F 80-8F: Jcc rel16/rel32 (forced64) + op if 128 <= op & op <= 143 => { + let cc : cc_idx = op - 128; + let rs = opsize_rel(pfx); + let offset : qword = sign_extend(fetch(rs / 8)); + if eval_cc(cc) == 0b1 then { + let os = opsize_forced64(pfx); + next_rip = Some(zero_extend((decode_pos + offset)[(os - 1) .. 0])); + } + }, + + // 0F 90-9F: SETcc r/m8 + op if 144 <= op & op <= 159 => { + let cc : cc_idx = op - 144; + let modrm = fetch(1); + let dest = modrm_rm(modrm, pfx); + v(dest) = zero_extend(8, eval_cc(cc)) + }, + + // 0F AE: Group 15 — FXSAVE/FXRSTOR/LDMXCSR/STMXCSR/XSAVE/XRSTOR/ + // LFENCE/MFENCE/SFENCE/RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE + 174 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + // The forms the SDM Vol.2 opcode tables define, by mandatory prefix + // (FXSAVE, FXRSTOR, LDMXCSR, STMXCSR, XSAVE, XRSTOR, XSAVEOPT and + // CLFLUSH are NP, as are LFENCE, MFENCE and SFENCE); any other is #UD. + // PTWRITE (F3 /4) is #UD with 66h or without CPUID.(14H,0):EBX[4] + // (SDM Vol.2B PTWRITE). Not implemented: F3 /5 reg INCSSP (CET + // shadow stacks, #UD while CR4.CET = 0). + let is_reg : bool = match dest { RM_reg(_) => true, RM_mem(_) => false }; + let ptwrite : bool = reg_field == 4 & has_ptwrite & ~(pfx.has_opsize); + let defined : bool = match (get_mandatory_prefix(pfx), is_reg) { + // FXSAVE ... CLFLUSH m8 + (MP_NONE, false) => true, + // LFENCE, MFENCE, SFENCE + (MP_NONE, true) => reg_field >= 5, + // CLWB m8, CLFLUSHOPT m8 + (MP_66, false) => reg_field >= 6, + // TPAUSE r32 + (MP_66, true) => reg_field == 6, + // RDFSBASE, RDGSBASE, WRFSBASE, WRGSBASE; UMONITOR; PTWRITE r32/r64 + (MP_F3, true) => reg_field <= 3 | reg_field == 6 | ptwrite, + // PTWRITE m32/m64 + (MP_F3, false) => ptwrite, + // UMWAIT r32 + (MP_F2, true) => reg_field == 6, + _ => false, + }; + if ~(defined) then raise_UD(); + if ptwrite & pfx.has_rep then { + // PTWRITE r/m32, r/m64 (REX.W): the operand goes to a PTW packet + // when Intel PT traces it (SDM Vol.2B PTWRITE). The model has no + // processor trace, so only the read, and its faults, remain. + let _ = if pfx.rex_w then zero_extend(64, v(64, dest)) else zero_extend(64, v(32, dest)); + return () + }; + // F3 prefix with mod=11 and reg_field 0-3: FSGSBASE instructions + // SDM: #UD if CR4.FSGSBASE (bit 16) = 0 + if pfx.has_rep & reg_field <= 3 then { + if CR4[16] != 0b1 then raise_UD(); + match dest { + RM_reg(r) => match (reg_field, pfx.rex_w) { + // F3 0F AE /0 mod=11: RDFSBASE r32/r64 + (0, true) => v(r) = SegCache[FS].seg_base, + (0, false) => v(r) = SegCache[FS].seg_base[31..0], + // F3 0F AE /1 mod=11: RDGSBASE r32/r64 + (1, true) => v(r) = SegCache[GS].seg_base, + (1, false) => v(r) = SegCache[GS].seg_base[31..0], + // F3 0F AE /2 mod=11: WRFSBASE r32/r64 + (2, true) => SegCache[FS].seg_base = v(64, r), + (2, false) => SegCache[FS].seg_base = zero_extend(v(32, r)), + // F3 0F AE /3 mod=11: WRGSBASE r32/r64 + (3, true) => SegCache[GS].seg_base = v(64, r), + (3, false) => SegCache[GS].seg_base = zero_extend(v(32, r)), + _ => raise_UD(), + }, + RM_mem(_) => raise_UD(), + } + } else match reg_field { + // FXSAVE m512byte (SDM Vol.2A FXSAVE): #NM if CR0.EM or CR0.TS is + // set (check_cr0_x87), then #GP(0) unless the operand is aligned on + // a 16-byte boundary. + 0 => match dest { + RM_mem(m) => { + check_cr0_x87(); + check_alignment(m, 16); + exec_fxsave(seg_linear(m, 512), pfx.rex_w) + }, + _ => raise_UD(), + }, + + // FXRSTOR m512byte (SDM Vol.2A FXRSTOR): #NM as FXSAVE, then + // #GP(0) unless the operand is 16-byte aligned, and for an image + // whose MXCSR sets a reserved bit (exec_fxrstor). + 1 => match dest { + RM_mem(m) => { + check_cr0_x87(); + check_alignment(m, 16); + exec_fxrstor(seg_linear(m, 512), pfx.rex_w) + }, + _ => raise_UD(), + }, + + // LDMXCSR m32 and STMXCSR m32 (SDM Vol.2A LDMXCSR and Vol.2B + // STMXCSR: exception class 5) + 2 => { check_cr0_sse(); load_mxcsr(rm_mem(dest)) }, + 3 => { check_cr0_sse(); rm_mem(dest) = __stmxcsr() }, + + // XSAVE m (#NM if CR0.TS = 1, whatever CR0.EM, as for the whole + // XSAVE family: SDM Vol.2D XSAVE) + 4 => match dest { + RM_mem(m) => { + check_xsave_enabled(true); + check_cr0_ts(); + let mask : qword = v(32, RDX) @ v(32, RAX); + exec_xsave(seg_linear(m, 576), mask, pfx.rex_w) + }, + RM_reg(_) => raise_UD(), + }, + + 5 => match dest { + RM_mem(m) => { + // /5 mem: XRSTOR m + check_xsave_enabled(true); + check_cr0_ts(); + let mask : qword = v(32, RDX) @ v(32, RAX); + exec_xrstor(seg_linear(m, 576), mask, pfx.rex_w) + }, + RM_reg(_) => { + // /5 mod=11: LFENCE + () + }, + }, + + // /6: XSAVEOPT (NP, mem) / CLWB (66, mem) / MFENCE (NP, reg), and + // with mod=11 the WAITPKG instructions TPAUSE (66), UMONITOR (F3) + // and UMWAIT (F2) (SDM Vol.2B; CPUID.07H.00H:ECX.WAITPKG[5]). + 6 => match dest { + RM_mem(m) => { + if pfx.has_opsize then { + cache_line_access(m) // CLWB + } else { + // XSAVEOPT: architecturally equivalent to XSAVE + check_xsave_enabled(has_xsaveopt); + check_cr0_ts(); + let mask : qword = v(32, RDX) @ v(32, RAX); + exec_xsaveopt(seg_linear(m, 576), mask, pfx.rex_w) + } + }, + RM_reg(r) => match get_mandatory_prefix(pfx) { + // MFENCE + MP_NONE => (), + // TPAUSE r32, , + MP_66 => exec_tpause_umwait(r, false), + // UMWAIT r32, , + MP_F2 => exec_tpause_umwait(r, true), + // UMONITOR r16/r32/r64 + MP_F3 => exec_umonitor(r, pfx), + }, + }, + + // /7: CLFLUSH (NP, mem) / CLFLUSHOPT (66, mem) / SFENCE (reg) + 7 => match dest { + RM_mem(m) => cache_line_access(m), + RM_reg(_) => (), + }, + } + }, + + // 0F A2: CPUID — unconditional VM exit in non-root (SDM §26.1.2) + 162 => { + vmx_exit_cpuid(); + let leaf : dword = v(RAX); + let subleaf : dword = v(RCX); + let (eax, ebx, ecx, edx) = cpuid(leaf, subleaf); + v(RAX) = eax; + v(RBX) = ebx; + v(RCX) = ecx; + v(RDX) = edx + }, + + // 0F A0: PUSH FS (d64) + // SDM: pushes FS selector. d64 = default 64 in long mode. + // Non-64-bit mode: operand size from CS.D and 66h prefix. + 160 => push_segreg(opsize_default64(pfx), FS), + + // 0F A1: POP FS (d64) + 161 => { + let os = opsize_default64(pfx); + load_data_segment_register(FS, match os { + 16 => pop(16), + 32 => pop(32)[15..0], + 64 => pop(64)[15..0], + }) + }, + + // 0F A3: BT r/m, r + 163 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + let bit_idx = v(os, reg); + let (adj_rm, bit_num) = bt_adjust(src, bit_idx); + CF = v(os, adj_rm)[bit_num]; + OF = undefined; + SF = undefined; + AF = undefined; + PF = undefined + }, + + // 0F A4: SHLD r/m, r, imm8 + 164 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + let count = fetch(1); + // SDM SHLD/SHRD: every operand access uses the decoded width. + // An inferred qword write would overwrite adjacent memory on r/m16/32. + v(os, dest) = exec_shld(os, read_rmw(os, dest), v(os, reg), count) + }, + + // 0F A5: SHLD r/m, r, CL + 165 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + let count : byte = v(RCX); + v(os, dest) = exec_shld(os, read_rmw(os, dest), v(os, reg), count) + }, + + // 0F A8: PUSH GS (d64) + 168 => push_segreg(opsize_default64(pfx), GS), + + // 0F A9: POP GS (d64) + 169 => { + let os = opsize_default64(pfx); + load_data_segment_register(GS, match os { + 16 => pop(16), + 32 => pop(32)[15..0], + 64 => pop(64)[15..0], + }) + }, + + // 0F AA: RSM — Resume from System Management Mode + // SDM Vol.2B §RSM: #UD if not in SMM. Restores processor state from + // SMRAM and returns to the mode active before the SMI. + 170 => exec_rsm(), + + // 0F AB: BTS r/m, r + 171 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + let bit_idx = v(os, reg); + let (adj_rm, bit_num) = bt_adjust(dest, bit_idx); + var x = read_rmw(os, adj_rm); + CF = x[bit_num]; + x[bit_num] = 0b1; + v(adj_rm) = x; + OF = undefined; + SF = undefined; + AF = undefined; + PF = undefined + }, + + // 0F AC: SHRD r/m, r, imm8 + 172 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + let count = fetch(1); + v(os, dest) = exec_shrd(os, read_rmw(os, dest), v(os, reg), count) + }, + + // 0F AD: SHRD r/m, r, CL + 173 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + let count : byte = v(RCX); + v(os, dest) = exec_shrd(os, read_rmw(os, dest), v(os, reg), count) + }, + + // 0F AF: IMUL r, r/m (2-operand) + // SDM: SF, ZF, AF, PF are undefined after IMUL. + 175 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + let a = v(os, reg); + let b = v(os, src); + let product : int = signed(sign_extend(a) : qword) * signed(sign_extend(b) : qword); + let result : qword = to_bits_truncate(product); + let w = to_bits_truncate(os * 2, product); + CF = is_nonzero(w[os * 2 - 1 .. os] ^ sign_extend(w[os - 1])); + OF = CF; + SF = undefined; + ZF = undefined; + AF = undefined; + PF = undefined; + v(reg) = to_bits_truncate(os, product) + }, + + // 0F B3: BTR r/m, r + 179 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + let bit_idx = v(os, reg); + let (adj_rm, bit_num) = bt_adjust(dest, bit_idx); + var x = read_rmw(os, adj_rm); + CF = x[bit_num]; + x[bit_num] = 0b0; + v(os, adj_rm) = x; + OF = undefined; + SF = undefined; + AF = undefined; + PF = undefined + }, + + // 0F B2: LSS r, m16:16/32/64 — Load far pointer into SS + // 0F B4: LFS r, m16:16/32/64 — Load far pointer into FS + // 0F B5: LGS r, m16:16/32/64 — Load far pointer into GS + // Memory format: [offset (16/32/64-bit)][selector (16-bit)] + // Register operand only (memory source); #UD for register source. + // With REX.W the SDM has "REX.W + 0F B2 /r LSS r64,m16:64" (Vol.2A + // LDS/LES/LFS/LGS/LSS p.3-540), the only definition of the form: the + // APM lists only mem16:16 and mem16:32, "A 64-bit operand is not + // supported" (Vol.3 LDS-LSS p.216), without saying what REX.W then + // does. The model loads the SDM's m16:64. + op if op == 178 | op == 180 | op == 181 => { + let os : {16, 32, 64} = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + match src { + RM_mem(m) => { + let (far_offset, selector) = read_far_pointer(os, m); + let seg : segreg_idx = match op { + 178 => SS, + 180 => FS, + 181 => GS, + }; + load_data_segment_register(seg, selector); + // The destination width follows the operand size, not the qword + // used by read_far_pointer to represent the offset. + v(reg) = far_offset[os - 1 .. 0] + }, + RM_reg(_) => raise_UD(), + } + }, + + // 0F B0: CMPXCHG r/m8, r8 + 176 => { + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + let dest_val = read_rmw(8, dest); + let acc : byte = v(RAX); + let src : byte = v(reg); + let cmp_result = acc - dest_val; + update_flags_sub(cmp_result, acc, dest_val); + // SDM Vol.2A CMPXCHG, Operation: equal loads DEST from SRC and leaves + // the accumulator alone; only the unequal case writes the accumulator. + v(dest) = blend(dest_val, src, ZF); + if ZF == 0b0 then v(RAX) = dest_val + }, + + // 0F B1: CMPXCHG r/m, r + 177 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + let dest_val = read_rmw(os, dest); + let acc = v(os, RAX); + let src = v(os, reg); + let cmp_result = acc - dest_val; + update_flags_sub(cmp_result, acc, dest_val); + // As for the byte form: the accumulator is written only when unequal. + v(os, dest) = blend(dest_val, src, ZF); + if ZF == 0b0 then v(RAX) = dest_val + }, + + // 0F B6: MOVZX r, r/m8 + 182 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + v(reg) = zero_extend(os, v(8, src)) + }, + + // 0F B7: MOVZX r, r/m16 + 183 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + v(reg) = zero_extend(os, v(16, src)) + }, + + // 0F BA: Group 8 — BT/BTS/BTR/BTC r/m, imm8 + 186 => { + let os = opsize(pfx); + let (reg_field, dest) = fetch_modrm_raw(pfx); + // LOCK valid only for BTS (/5), BTR (/6), BTC (/7) with memory + if pfx.has_lock & reg_field == 4 then raise_UD(); + check_lock_rm(pfx, dest, false); + // /0-/3 are reserved: #UD before the operand is accessed. + if reg_field < 4 then raise_UD(); + let imm = fetch(1); + var x = if reg_field == 4 then v(os, dest) else read_rmw(os, dest); + let bit_num : range(0, 63) = unsigned(imm) % os; + assert(bit_num < os); + CF = x[bit_num]; + match reg_field { + // BT — just test, no modification + 4 => (), + // BTS — set bit + 5 => { + x[bit_num] = 0b1; + v(dest) = x + }, + // BTR — reset bit + 6 => { + x[bit_num] = 0b0; + v(dest) = x + }, + // BTC — complement bit + 7 => { + x[bit_num] = ~(x[bit_num]); + v(dest) = x + }, + _ => raise_UD(), + }; + OF = undefined; + SF = undefined; + AF = undefined; + PF = undefined + }, + + // 0F BB: BTC r/m, r + 187 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + let bit_idx = v(os, reg); + let (adj_rm, bit_num) = bt_adjust(dest, bit_idx); + var x = read_rmw(os, adj_rm); + CF = x[bit_num]; + x[bit_num] = ~(x[bit_num]); + v(os, adj_rm) = x; + OF = undefined; + SF = undefined; + AF = undefined; + PF = undefined + }, + + // 0F BC: BSF r, r/m (or TZCNT with F3 prefix) + 188 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + if pfx.has_rep & has_bmi1 then { + // TZCNT r16/r32/r64, r/m16/r/m32/r/m64. "On processors that do + // not support TZCNT, the instruction byte encoding is executed as + // BSF" (SDM Vol.2B TZCNT p.4-727; APM Vol.3 TZCNT p.362: "treated + // as the BSF instruction"). + let src_val = v(os, src); + let count = ctz(src_val); + let result : qword = to_bits_truncate(count); + v(reg) = result[(os - 1) .. 0]; + CF = is_zero(src_val); + ZF = src_val[0]; + OF = undefined; + SF = undefined; + AF = undefined; + PF = undefined + } else { + // BSF r16/r32/r64, r/m16/r/m32/r/m64 + // ZF is set for a zero source and cleared otherwise. The other + // flags are undefined: the SDM sets PF from the source's parity and + // clears CF, OF, SF and AF, but "On some older processors, the CF, + // OF, SF, AF, and PF flags are unmodified" (Vol.2A BSF p.3-107, + // footnote 2), and the APM marks all five U (Vol.3 BSF p.123). + // For a zero source "the destination operand is unmodified", but + // "on some older processors, use of a 32-bit operand size may clear + // the upper 32 bits of a 64-bit destination while leaving the lower + // 32 bits unmodified" (SDM, footnote 1); the APM "does not change + // the contents of the destination register". So the register + // stays, except bits 63:32 after a 32-bit BSF, which are undefined. + // Linux's ffs(), fls() and fls64() (arch/x86/include/asm/bitops.h) + // preload -1 and rely only on the low 32 bits surviving. + let src_val = v(os, src); + let zf : bit = is_zero(src_val); + let idx = ctz(src_val); + let result : qword = to_bits_truncate(idx); + CF = undefined; + OF = undefined; + SF = undefined; + AF = undefined; + ZF = zf; + PF = undefined; + let old : qword = GPR[reg.gpr_idx]; + let kept : qword = if os == 32 then (undefined : dword) @ old[31..0] else old; + v(reg) = result[(os - 1) .. 0]; + GPR[reg.gpr_idx] = blend(GPR[reg.gpr_idx], kept, zf) + } + }, + + // 0F BD: BSR r, r/m (or LZCNT with F3 prefix) + 189 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + if pfx.has_rep & has_lzcnt then { + // LZCNT r16/r32/r64, r/m16/r/m32/r/m64. "On processors that do + // not support LZCNT, the instruction byte encoding is executed as + // BSR" (SDM Vol.2A LZCNT p.3-578; APM Vol.3 LZCNT p.234: + // "interpreted as the BSR instruction"). + let src_val = v(os, src); + let count = clz(src_val); + let result : qword = to_bits_truncate(count); + v(reg) = result[(os - 1) .. 0]; + CF = is_zero(src_val); + ZF = src_val[os - 1]; + OF = undefined; + SF = undefined; + AF = undefined; + PF = undefined + } else { + // BSR r16/r32/r64, r/m16/r/m32/r/m64 + // The flag and destination rules of BSF above, in the same words + // (SDM Vol.2A BSR p.3-109 and its footnotes; APM Vol.3 BSR p.124). + let src_val = v(os, src); + let zf : bit = is_zero(src_val); + // Sentinel bit 0 ensures bsr gets nonzero input; result ignored when zf=1 + let idx : range(0, 63) = bsr(zero_extend(src_val) | 0x0000000000000001); + let result : qword = to_bits_truncate(idx); + CF = undefined; + OF = undefined; + SF = undefined; + AF = undefined; + ZF = zf; + PF = undefined; + let old : qword = GPR[reg.gpr_idx]; + let kept : qword = if os == 32 then (undefined : dword) @ old[31..0] else old; + v(reg) = result[(os - 1) .. 0]; + GPR[reg.gpr_idx] = blend(GPR[reg.gpr_idx], kept, zf) + } + }, + + // 0F BE: MOVSX r, r/m8 + 190 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + let sx : qword = sign_extend(v(8, src)); + v(reg) = sx[(os - 1) .. 0] + }, + + // 0F BF: MOVSX r, r/m16 + 191 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + let sx : qword = sign_extend(v(16, src)); + v(reg) = sx[(os - 1) .. 0] + }, + + // 0F C0: XADD r/m8, r8 + 192 => { + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + match dest { + RM_reg(dst) => exec_xadd(dst, reg, 8), + RM_mem(m) => { + // Memory operand: read, exchange, add, write back + let mem_val : byte = read_rmw_mem(m); + let reg_val : byte = v(reg); + let sum : byte = mem_val + reg_val; + // A write fault must leave SRC unchanged for restart (SDM + // Vol.3A 7.5; Vol.2D XADD). Commit memory before register state. + v(m) = sum; + v(reg) = mem_val; + update_flags_add(sum, mem_val, reg_val) + }, + } + }, + + // 0F C1: XADD r/m, r + 193 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + match dest { + RM_reg(dst) => exec_xadd(dst, reg, os), + RM_mem(_) => { + let mem_val = read_rmw(os, dest); + let reg_val = v(os, reg); + let sum = mem_val + reg_val; + v(os, dest) = sum; + v(reg) = mem_val; + update_flags_add(sum, mem_val, reg_val) + }, + } + }, + + // 0F B8: POPCNT r, r/m (F3 prefix) + 184 => { + let mp = get_mandatory_prefix(pfx); + if mp != MP_F3 then raise_UD(); + if ~(has_popcnt) then raise_UD(); + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + let src_val = v(os, src); + let count : range(0, 64) = popcount(zero_extend(src_val) : qword); + OF = 0b0; + SF = 0b0; + AF = 0b0; + CF = 0b0; + PF = 0b0; + ZF = is_zero(src_val); + let result : qword = to_bits_truncate(count); + v(reg) = result[(os - 1) .. 0] + }, + + // 0F C3: MOVNTI m32/64, r — NP 0F C3 (SDM Vol.2B MOVNTI): 66, F2 or F3 + // leaves it undefined. + 195 => { + if get_mandatory_prefix(pfx) != MP_NONE then raise_UD(); + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + rm_mem(dest) = v(os, reg) + }, + + // 0F C7: Group 9 + 199 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + // The forms the SDM Vol.2 opcode tables define, by mandatory prefix; + // any other is #UD. NFx (RDRAND, RDSEED) excludes F2 and F3 (SDM + // Vol.2A §3.1.1.1); F3 /6 reg is SENDUIPI (UINTR, not implemented). + // Of Group 9 only CMPXCHG8B/16B takes LOCK (SDM Vol.2B LOCK). + let mp = get_mandatory_prefix(pfx); + let is_reg : bool = match dest { RM_reg(_) => true, RM_mem(_) => false }; + let defined : bool = match (reg_field, is_reg) { + // CMPXCHG8B m64, CMPXCHG16B m128 + (1, false) => true, + // XRSTORS, XSAVEC, XSAVES (NP) + (r, false) if 3 <= r & r <= 5 => mp == MP_NONE, + // VMPTRLD (NP), VMCLEAR (66), VMXON (F3) + (6, false) => mp != MP_F2, + // RDRAND (NFx) + (6, true) => mp == MP_NONE | mp == MP_66, + // VMPTRST (NP) + (7, false) => mp == MP_NONE, + // RDSEED (NFx), RDPID (F3) + (7, true) => mp != MP_F2, + _ => false, + }; + if ~(defined) | (pfx.has_lock & reg_field != 1) then raise_UD(); + match reg_field { + // CMPXCHG8B/CMPXCHG16B m64/m128. SDM Vol.2A CMPXCHG8B/CMPXCHG16B, + // Operation: the destination is written either way, with + // RCX:RBX when equal and with its own value when not; #GP(0) if + // the CMPXCHG16B operand is not aligned on a 16-byte boundary. + 1 => match dest { + RM_mem(m) => { + if pfx.rex_w then { + if ~(has_cx16) then raise_UD(); + check_alignment(m, 16); + let mem_val : bits(128) = read_rmw_mem(m); + let mem_lo : qword = mem_val[63..0]; + let mem_hi : qword = mem_val[127..64]; + let eq : bit = is_eq(v(64, RAX), mem_lo) & is_eq(v(64, RDX), mem_hi); + write_mem(128, m, blend(mem_val, v(64, RCX) @ v(64, RBX), eq)); + ZF = eq; + v(RAX) = blend(mem_lo, v(64, RAX), eq); + v(RDX) = blend(mem_hi, v(64, RDX), eq) + } else { + let mem_val : qword = read_rmw_mem(m); + let mem_lo : dword = mem_val[31..0]; + let mem_hi : dword = mem_val[63..32]; + let eq : bit = is_eq(v(32, RAX), mem_lo) & is_eq(v(32, RDX), mem_hi); + v(m) = blend(mem_val, v(32, RCX) @ v(32, RBX), eq); + ZF = eq; + v(RAX) = blend(mem_lo, v(32, RAX), eq); + v(RDX) = blend(mem_hi, v(32, RDX), eq) + } + }, + RM_reg(_) => raise_UD(), + }, + // /3 mem: XRSTORS — restore extended state (supervisor, requires + // CPL=0). The #NM of CR0.TS, a fault from decoding the instruction, + // comes ahead of the #GP of CPL (SDM Vol.3A §7.9), here and in + // XSAVES. + 3 => match dest { + RM_mem(m) => { + check_xsave_enabled(has_xsaves); + check_cr0_ts(); + if cur_cpl != 0 then raise_GP0(); + let mask : qword = v(32, RDX) @ v(32, RAX); + exec_xrstors(seg_linear(m, 576), mask, pfx.rex_w) + }, + _ => raise_UD(), + }, + // /4 mem: XSAVEC — save extended state with compaction + 4 => match dest { + RM_mem(m) => { + check_xsave_enabled(has_xsavec); + check_cr0_ts(); + let mask : qword = v(32, RDX) @ v(32, RAX); + exec_xsavec(seg_linear(m, 576), mask, pfx.rex_w) + }, + _ => raise_UD(), + }, + // /5 mem: XSAVES — save extended state (supervisor, requires CPL=0) + 5 => match dest { + RM_mem(m) => { + check_xsave_enabled(has_xsaves); + check_cr0_ts(); + if cur_cpl != 0 then raise_GP0(); + let mask : qword = v(32, RDX) @ v(32, RAX); + exec_xsaves(seg_linear(m, 576), mask, pfx.rex_w) + }, + _ => raise_UD(), + }, + // /6: RDRAND (mod=11) or VMX (mod!=11) + 6 => match dest { + RM_reg(r) => { + // /6 mod=11: NFx RDRAND r16/r32/r64 + if ~(has_rdrand) then raise_UD(); + let os = opsize(pfx); + let (rnd, cf_val) = __rdrand64(); + v(r) = rnd[(os - 1) .. 0] & sign_extend(cf_val); + CF = cf_val; + OF = 0b0; + SF = 0b0; + ZF = 0b0; + AF = 0b0; + PF = 0b0 + }, + RM_mem(m) => { + // /6 mem: VMX instructions discriminated by prefix + // NP 0F C7 /6 mem → VMPTRLD + // 66 0F C7 /6 mem → VMCLEAR + // F3 0F C7 /6 mem → VMXON + if pfx.has_rep then + vmx_exit_vmx_insn(VMEXIT_VMXON) + else if pfx.has_opsize then + vmx_exit_vmx_insn(VMEXIT_VMCLEAR) + else + vmx_exit_vmx_insn(VMEXIT_VMPTRLD); + let addr = seg_linear(m, 8); + if pfx.has_rep then + exec_vmxon(addr) + else if pfx.has_opsize then + exec_vmclear(addr) + else + exec_vmptrld(addr) + }, + }, + // /7: RDSEED or RDPID (mod=11) or VMPTRST (mod!=11) + 7 => match dest { + RM_reg(r) => { + if pfx.has_rep then { + // F3 0F C7 /7: RDPID r32/r64 (SDM Vol.2B RDPID): DEST := + // IA32_TSC_AUX. "The value of CS.D and operand-size prefixes + // (66H and REX.W) do not affect the behavior", so the + // destination is r64 in 64-bit mode and r32 otherwise. + if ~(has_rdpid) then raise_UD(); + let aux : dword = __rdmsr(0xC0000103)[31..0]; + if cur_mode == LongMode then v(r) = zero_extend(64, aux) else v(r) = aux + } else { + // /7 mod=11: NFx RDSEED r16/r32/r64 + if ~(has_rdseed) then raise_UD(); + let os = opsize(pfx); + let (rnd, cf_val) = __rdseed64(); + v(r) = rnd[(os - 1) .. 0] & sign_extend(cf_val); + CF = cf_val; + OF = 0b0; + SF = 0b0; + ZF = 0b0; + AF = 0b0; + PF = 0b0 + } + }, + RM_mem(m) => { + // /7 mem: VMPTRST — store current VMCS pointer + vmx_exit_vmx_insn(VMEXIT_VMPTRST); + exec_vmptrst(seg_linear(m, 8)) + }, + }, + _ => raise_UD(), + } + }, + + // 0F C8-CF: BSWAP r32/r64 (register in opcode) + op if 200 <= op & op <= 207 => { + let reg_field : range(0, 7) = op - 200; + let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); + let os = opsize(pfx); + if os == 16 then { + // SDM: the result is undefined for a 16-bit operand. + v(reg) = undefined : word + } else { + v(os, reg) = bswap(v(os, reg)) + } + }, + + // 66/F2 0F 78 and 0F 79 with SSE4A: EXTRQ and INSERTQ (exec_sse4a) + op if (op == 120 | op == 121) & has_sse4a + & (get_mandatory_prefix(pfx) == MP_66 | get_mandatory_prefix(pfx) == MP_F2) => + exec_sse4a(op, pfx), + + // 0F 78: VMREAD r/m64, r64 (SDM Vol.3C §31.2.4) + // In 64-bit mode, operand size is always 64 bits. + 120 => { + vmx_exit_vmx_insn(VMEXIT_VMREAD); + let (reg, dest) = fetch_modrm(pfx); + exec_vmread(pfx, dest, reg.gpr_idx) + }, + + // 0F 79: VMWRITE r64, r/m64 (SDM Vol.3C §31.2.5) + 121 => { + vmx_exit_vmx_insn(VMEXIT_VMWRITE); + let (reg, src) = fetch_modrm(pfx); + exec_vmwrite(pfx, src, reg.gpr_idx) + }, + + _ => raise_UD(), + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail new file mode 100644 index 000000000..ff1cf2490 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail @@ -0,0 +1,2358 @@ +// x86-64 — Opcode Dispatch +// +// Central dispatch for 1-byte, 2-byte (0F xx), and 3-byte (0F 38/3A xx) +// opcode maps. Routes to category-specific handlers. + +// XCHG — Exchange Register/Memory with Register +val exec_xchg_reg_reg : (gpr_idx, gpr_idx, operand_size) -> unit +function exec_xchg_reg_reg(a, b, os) = { + let temp = v(os, a); + v(a) = v(os, b); + v(b) = temp +} + +// IN — Input from Port +val exec_in : (word, operand_size) -> unit +function exec_in(port, os) = { + check_io_permission(port, if os == 64 then 4 else os / 8); + note_io_access(port, if os == 64 then 4 else os / 8); + match os { + 8 => v(RAX) = __port_in8(port), + 16 => v(RAX) = __port_in16(port), + 32 => v(RAX) = __port_in32(port), + 64 => v(RAX) = __port_in32(port) + } +} + +// OUT — Output to Port +val exec_out : (word, operand_size) -> unit +function exec_out(port, os) = { + check_io_permission(port, if os == 64 then 4 else os / 8); + note_io_access(port, if os == 64 then 4 else os / 8); + match os { + 8 => __port_out8(port, v(RAX)), + 16 => __port_out16(port, v(RAX)), + 32 => __port_out32(port, v(RAX)), + 64 => __port_out32(port, v(RAX)) + } +} + +// JMP near relative: RIP := decode_pos + sign-extended offset + +// POP — Pop a Value from the Stack +val exec_pop_reg : (gpr_idx, {16, 32, 64}) -> unit +function exec_pop_reg(dst, os) = { + match os { + 16 => v(dst) = pop(16), + 32 => v(dst) = if cur_mode == LongMode then pop(64)[31..0] else pop(32), + 64 => v(dst) = pop(64), + } +} + +// LOOP/LOOPcc — Loop According to ECX Counter +enum LoopVariant = { LOOP_always, LOOP_e, LOOP_ne } + +// os is the operand size of the near branch (opsize_forced64), which +// truncates the target: "IF OperandSize = 16 THEN tempEIP := tempEIP AND +// 0000FFFFH" (SDM Vol.2A LOOP/LOOPcc). +val exec_loop : (byte, LoopVariant, address_size, {16, 32, 64}) -> unit +function exec_loop(rel8, variant, asz, os) = { + v(RCX) = v(asz, RCX) - 1; + let count_nonzero : bool = v(asz, RCX) != zeros(); + let take_branch : bool = match variant { + LOOP_always => count_nonzero, + LOOP_e => if count_nonzero then ZF == 0b1 else false, + LOOP_ne => if count_nonzero then ZF == 0b0 else false, + }; + if take_branch then { + next_rip = Some(zero_extend((decode_pos + sign_extend(rel8))[(os - 1) .. 0])); + } +} + +// Map rows 00-3F to ALU operation. Each operation occupies 8 opcodes. +val opcode_to_alu : range(0, 63) -> ALUOp +function opcode_to_alu(op) = { + let row : range(0, 7) = unsigned(to_bits_truncate(3, op / 8)); + match row { + 0 => ALU_ADD, + 1 => ALU_OR, + 2 => ALU_ADC, + 3 => ALU_SBB, + 4 => ALU_AND, + 5 => ALU_SUB, + 6 => ALU_XOR, + 7 => ALU_CMP, + } +} + +// ALU dispatch for opcodes 00-3F (columns 0-5). +val dispatch_alu_opcode : (range(0, 63), Prefixes) -> unit +function dispatch_alu_opcode(op, pfx) = { + let alu_op = opcode_to_alu(op); + let col : range(0, 7) = op % 8; + // LOCK is only valid on columns 0-1 (r/m destination), not CMP, and only with memory + if pfx.has_lock & col >= 2 then raise_UD(); + match col { + // OP r/m8, r8 + 0 => { + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, alu_op == ALU_CMP); + exec_alu_rm_reg(alu_op, dest, reg, 8) + }, + // OP r/m, r (word/dword/qword) + 1 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, alu_op == ALU_CMP); + exec_alu_rm_reg(alu_op, dest, reg, os) + }, + // OP r8, r/m8 + 2 => { + let (reg, src) = fetch_modrm(pfx); + exec_alu_reg_rm(alu_op, reg, src, 8) + }, + // OP r, r/m (word/dword/qword) + 3 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + exec_alu_reg_rm(alu_op, reg, src, os) + }, + // OP AL, imm8 + 4 => { + let imm : byte = fetch(1); + exec_alu_acc_imm(alu_op, imm, 8, pfx) + }, + // OP rAX, imm (Iz: 16 or 32 bit, sign-extended) + 5 => { + let os = opsize(pfx); + let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); + exec_alu_acc_imm(alu_op, imm[(os - 1) .. 0], os, pfx) + }, + _ => raise_UD(), // unreachable + } +} + +// ========================================================================= +// String Operations (MOVS, STOS, LODS, SCAS, CMPS, INS, OUTS, REP) +// ========================================================================= + +// INS — Input from port DX to ES:[RDI] +val exec_ins : (operand_size, address_size) -> unit +function exec_ins(os_in, asz) = { + // SDM: INS only supports 8/16/32-bit I/O; REX.W is ignored. + let os : {8, 16, 32} = if os_in == 64 then 32 else os_in; + let port : word = v(RDX); + check_io_permission(port, os / 8); + let off : qword = zero_extend(v(asz, RDI)); + // INS destination is always ES:DI (not overridable). + let dst : MemRef = struct { seg = ES, addr = off }; + note_io_access(port, os / 8); + match os { + 8 => v(dst) = __port_in8(port), + 16 => v(dst) = __port_in16(port), + 32 => v(dst) = __port_in32(port), + }; + let step = (1 - 2 * unsigned(DF)) * (os / 8); + v(RDI) = (off + step)[asz - 1 .. 0] +} + +// OUTS — Output from DS:[RSI] to port DX +// SDM Vol.2B §OUTS: Source is DS:(E)SI, DS segment may be overridden. +val exec_outs : (operand_size, address_size, Prefixes) -> unit +function exec_outs(os_in, asz, pfx) = { + // SDM: OUTS only supports 8/16/32-bit I/O; REX.W is ignored. + let os : {8, 16, 32} = if os_in == 64 then 32 else os_in; + let port : word = v(RDX); + check_io_permission(port, os / 8); + let off : qword = zero_extend(v(asz, RSI)); + let src_seg : segreg_idx = match pfx.seg_override { + Some(s) => s, + None() => DS, + }; + let src : MemRef = struct { seg = src_seg, addr = off }; + note_io_access(port, os / 8); + match os { + 8 => __port_out8(port, v(src)), + 16 => __port_out16(port, v(src)), + 32 => __port_out32(port, v(src)), + }; + let step = (1 - 2 * unsigned(DF)) * (os / 8); + v(RSI) = (off + step)[asz - 1 .. 0] +} + +val exec_movs : (operand_size, address_size, Prefixes) -> unit +function exec_movs(os, asz, pfx) = { + let src_off : qword = zero_extend(v(asz, RSI)); + let dst_off : qword = zero_extend(v(asz, RDI)); + // MOVS source is DS:SI (overridable), destination is always ES:DI. + let src_seg : segreg_idx = match pfx.seg_override { + Some(s) => s, + None() => DS, + }; + let src : MemRef = struct { seg = src_seg, addr = src_off }; + let dst : MemRef = struct { seg = ES, addr = dst_off }; + v(dst) = v(os, src); + let step = (1 - 2 * unsigned(DF)) * (os / 8); + v(RSI) = (src_off + step)[asz - 1 .. 0]; + v(RDI) = (dst_off + step)[asz - 1 .. 0]; +} + +val exec_stos : (operand_size, address_size) -> unit +function exec_stos(os, asz) = { + let off : qword = zero_extend(v(asz, RDI)); + // STOS destination is always ES:DI (not overridable). + let dst : MemRef = struct { seg = ES, addr = off }; + v(dst) = v(os, RAX); + let step = (1 - 2 * unsigned(DF)) * (os / 8); + v(RDI) = (off + step)[asz - 1 .. 0] +} + +val exec_lods : (operand_size, address_size, Prefixes) -> unit +function exec_lods(os, asz, pfx) = { + let off : qword = zero_extend(v(asz, RSI)); + // LODS source is DS:SI (overridable). + let src_seg : segreg_idx = match pfx.seg_override { + Some(s) => s, + None() => DS, + }; + let src : MemRef = struct { seg = src_seg, addr = off }; + v(RAX) = v(os, src); + let step = (1 - 2 * unsigned(DF)) * (os / 8); + v(RSI) = (off + step)[asz - 1 .. 0] +} + +val exec_scas : (operand_size, address_size) -> unit +function exec_scas(os, asz) = { + let off : qword = zero_extend(v(asz, RDI)); + // SCAS destination is always ES:DI (not overridable). + let dst : MemRef = struct { seg = ES, addr = off }; + let a = v(os, RAX); + let b = v(os, dst); + update_flags_sub(a - b, a, b); + let step = (1 - 2 * unsigned(DF)) * (os / 8); + v(RDI) = (off + step)[asz - 1 .. 0] +} + +val exec_cmps : (operand_size, address_size, Prefixes) -> unit +function exec_cmps(os, asz, pfx) = { + let src_off : qword = zero_extend(v(asz, RSI)); + let dst_off : qword = zero_extend(v(asz, RDI)); + // CMPS source is DS:SI (overridable), destination is ES:DI. + let src_seg : segreg_idx = match pfx.seg_override { + Some(s) => s, + None() => DS, + }; + let src : MemRef = struct { seg = src_seg, addr = src_off }; + let dst : MemRef = struct { seg = ES, addr = dst_off }; + let a = v(os, src); + let b = v(os, dst); + update_flags_sub(a - b, a, b); + let step = (1 - 2 * unsigned(DF)) * (os / 8); + v(RSI) = (src_off + step)[asz - 1 .. 0]; + v(RDI) = (dst_off + step)[asz - 1 .. 0] +} + +enum RepPrefix = { REP_none, REP_rep, REP_repe, REP_repne } + +// SDM Vol.2A 2.1.1: F2 and F3 repeat string and I/O instructions. +// The ZF termination conditions apply only to CMPS/SCAS (Vol.1 7.3.9.2). +// What F2 does to MOVS, STOS, LODS, INS and OUTS neither manual says: "The +// REPE/REPZ and REPNE/REPNZ prefixes are used only with the CMPS and SCAS +// instructions" (SDM Vol.1 §7.3.9.2, p.7-19), and REPNE "can only be used +// with the CMPSx and SCASx instructions" (APM Vol.1 §3.5.1.4, p.79). The +// model repeats them by the count alone, as for F3, on both vendors. +enum StringOp = { STR_movs, STR_stos, STR_lods, STR_cmps, STR_scas, STR_ins, STR_outs } + +val exec_rep : (RepPrefix, StringOp, operand_size, address_size, Prefixes) -> unit +function exec_rep(prefix, op, os, asz, pfx) = { + while v(asz, RCX) != zeros() do { + match op { + STR_movs => exec_movs(os, asz, pfx), + STR_stos => exec_stos(os, asz), + STR_lods => exec_lods(os, asz, pfx), + STR_cmps => exec_cmps(os, asz, pfx), + STR_scas => exec_scas(os, asz), + STR_ins => exec_ins(os, asz), + STR_outs => exec_outs(os, asz, pfx), + }; + v(RCX) = v(asz, RCX) - 1; + if prefix == REP_repe & ZF == 0b0 then return (); + if prefix == REP_repne & ZF == 0b1 then return (); + // A data breakpoint hit by this iteration, or single-step, is reported + // after the iteration: the instruction resumes for the remaining count + // (RIP back at its first byte; SDM Vol.3B §20.3.1.1, §20.3.1.2). A + // data breakpoint may wait for later iterations: with fast-string + // operation "the processor recognizes interrupts and data breakpoints + // only on boundaries between these groups", whose size is + // implementation-specific (SDM Vol.1 §7.3.9.3 p.7-19), and "All + // breakpoint conditions, except certain string operations preceded by + // a repeat prefix, are exact" (APM Vol.2 §13.1.1.4 p.397). So whether + // the group goes on is undefined. + let group_continues : bool = undefined; + if (pending_dbp != 0x0 & ~(group_continues) | TF == 0b1) & v(asz, RCX) != zeros() then { + next_rip = Some(insn_start); + rep_trap_rf = true; + return () + } + } +} + +// ========================================================================= +// 2-Byte Opcode Map (0F xx) Dispatch +// ========================================================================= + +// Check if a 2-byte opcode (0F xx) is lockable. +// Lockable: BTS (0F AB), BTR (0F B3), BTC (0F BB), +// CMPXCHG (0F B0, 0F B1), XADD (0F C0, 0F C1), CMPXCHG8B/16B (0F C7) +val is_lockable_2byte : range(0, 255) -> bool +function is_lockable_2byte(op) = match op { + 171 => true, // 0F AB: BTS + 176 => true, // 0F B0: CMPXCHG + 177 => true, // 0F B1: CMPXCHG + 179 => true, // 0F B3: BTR + 186 => true, // 0F BA: Group 8 (BTS/BTR/BTC imm, not BT) + 187 => true, // 0F BB: BTC + 192 => true, // 0F C0: XADD + 193 => true, // 0F C1: XADD + 199 => true, // 0F C7: CMPXCHG8B/16B + _ => false, +} + +// What one mandatory prefix lets a legacy-encoded SIMD opcode take in +// ModR/M.rm: nothing (the opcode is undefined with that prefix), only a +// register, only memory, or either. +enum RMForms = { RMF_None, RMF_Reg, RMF_Mem, RMF_Any } + +// rm_forms(mp, NP, 66, F3, F2): the entry of an opcode's row for prefix mp. +val rm_forms : (MandatoryPrefix, RMForms, RMForms, RMForms, RMForms) -> RMForms +function rm_forms(mp, np, p66, f3, f2) = match mp { + MP_NONE => np, + MP_66 => p66, + MP_F3 => f3, + MP_F2 => f2, +} + +// The forms of an instruction of a CPUID feature: none on a processor +// without the feature, whose encodings are undefined there. +val with_feature : (bool, RMForms) -> RMForms +function with_feature(present, forms) = if present then forms else RMF_None + +// The SIMD opcodes of the 0F map (those dispatch_2byte_sse_fp, +// dispatch_2byte_sse_int and dispatch_mmx implement) by mandatory prefix, +// F2/F3 taking precedence over 66 (get_mandatory_prefix), as the opcode +// tables of the SDM Vol.2 instruction pages give them. A prefix that an +// opcode's table does not list leaves it undefined (#UD): the MMX forms +// are "NP", which allows no 66, F2 or F3 (SDM Vol.2 §3.1.1.1). An r/m +// operand the table writes m64, m128 or mem is memory only, and one it +// writes mm, xmm or reg alone a register only. reg is ModR/M.reg, the +// opcode extension of the 0F 71-73 groups. Every form is SSE, SSE2 or +// MMX, which an x86-64 processor has, but for the SSE3 ones. +val simd_0f_forms : (range(0, 255), MandatoryPrefix, range(0, 7)) -> RMForms +function simd_0f_forms(op, mp, reg) = match op { + // MOVUPS, MOVUPD, MOVSS, MOVSD (load and store) + op if op == 16 | op == 17 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // MOVLPS xmm, m64 or MOVHLPS xmm, xmm; MOVLPD xmm, m64; MOVSLDUP; MOVDDUP + 18 => rm_forms(mp, RMF_Any, RMF_Mem, with_feature(has_sse3, RMF_Any), + with_feature(has_sse3, RMF_Any)), + // MOVLPS m64, xmm; MOVLPD m64, xmm + 19 => rm_forms(mp, RMF_Mem, RMF_Mem, RMF_None, RMF_None), + // UNPCKLPS, UNPCKLPD; UNPCKHPS, UNPCKHPD + op if op == 20 | op == 21 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // MOVHPS xmm, m64 or MOVLHPS xmm, xmm; MOVHPD xmm, m64; MOVSHDUP + 22 => rm_forms(mp, RMF_Any, RMF_Mem, with_feature(has_sse3, RMF_Any), RMF_None), + // MOVHPS m64, xmm; MOVHPD m64, xmm + 23 => rm_forms(mp, RMF_Mem, RMF_Mem, RMF_None, RMF_None), + // MOVAPS, MOVAPD (load and store) + op if op == 40 | op == 41 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // CVTPI2PS, CVTPI2PD, CVTSI2SS, CVTSI2SD + 42 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // MOVNTPS m128, xmm; MOVNTPD m128, xmm; and the SSE4A MOVNTSS mem32, xmm + // and MOVNTSD mem64, xmm (AMD APM Vol.4), which the SDM leaves undefined + 43 => rm_forms(mp, RMF_Mem, RMF_Mem, with_feature(has_sse4a, RMF_Mem), + with_feature(has_sse4a, RMF_Mem)), + // CVT(T)PS2PI, CVT(T)PD2PI, CVT(T)SS2SI, CVT(T)SD2SI + op if op == 44 | op == 45 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // UCOMISS, UCOMISD; COMISS, COMISD + op if op == 46 | op == 47 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // MOVMSKPS reg, xmm; MOVMSKPD reg, xmm + 80 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), + // SQRTPS, SQRTPD, SQRTSS, SQRTSD + 81 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // RSQRTPS, RSQRTSS; RCPPS, RCPSS + op if op == 82 | op == 83 => rm_forms(mp, RMF_Any, RMF_None, RMF_Any, RMF_None), + // ANDPS/PD, ANDNPS/PD, ORPS/PD, XORPS/PD + op if 84 <= op & op <= 87 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // ADD, MUL, CVTPS2PD/CVTPD2PS/CVTSS2SD/CVTSD2SS (PS, PD, SS, SD) + op if 88 <= op & op <= 90 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // CVTDQ2PS, CVTPS2DQ, CVTTPS2DQ + 91 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), + // SUB, MIN, DIV, MAX (PS, PD, SS, SD) + op if 92 <= op & op <= 95 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // PUNPCKL*, PACKSSWB, PCMPGT*, PACKUSWB, PUNPCKH*, PACKSSDW (mm, xmm) + op if 96 <= op & op <= 107 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // PUNPCKLQDQ, PUNPCKHQDQ + op if op == 108 | op == 109 => rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_None), + // MOVD/MOVQ mm, r/m; MOVD/MOVQ xmm, r/m + 110 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // MOVQ mm, mm/m64; MOVDQA; MOVDQU (load) + 111 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), + // PSHUFW, PSHUFD, PSHUFHW, PSHUFLW + 112 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // Groups 12 and 13: PSRLW/D /2, PSRAW/D /4, PSLLW/D /6 (mm, xmm) + op if op == 113 | op == 114 => + if reg == 2 | reg == 4 | reg == 6 + then rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None) + else RMF_None, + // Group 14: PSRLQ /2, PSLLQ /6 (mm, xmm); PSRLDQ /3, PSLLDQ /7 (xmm) + 115 => + if reg == 2 | reg == 6 + then rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None) + else if reg == 3 | reg == 7 + then rm_forms(mp, RMF_None, RMF_Reg, RMF_None, RMF_None) + else RMF_None, + // PCMPEQB, PCMPEQW, PCMPEQD (mm, xmm) + op if 116 <= op & op <= 118 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // HADDPD, HADDPS; HSUBPD, HSUBPS + op if op == 124 | op == 125 => + with_feature(has_sse3, rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_Any)), + // MOVD/MOVQ r/m, mm; MOVD/MOVQ r/m, xmm; MOVQ xmm, xmm/m64 + 126 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), + // MOVQ mm/m64, mm; MOVDQA; MOVDQU (store) + 127 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), + // CMPPS, CMPPD, CMPSS, CMPSD + 194 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), + // PINSRW mm, r32/m16; PINSRW xmm, r32/m16 + 196 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // PEXTRW reg, mm; PEXTRW reg, xmm + 197 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), + // SHUFPS, SHUFPD + 198 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // ADDSUBPD, ADDSUBPS + 208 => with_feature(has_sse3, rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_Any)), + // PSRLW, PSRLD, PSRLQ, PADDQ, PMULLW (mm, xmm) + op if 209 <= op & op <= 213 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // MOVQ xmm/m64, xmm; MOVQ2DQ xmm, mm; MOVDQ2Q mm, xmm + 214 => rm_forms(mp, RMF_None, RMF_Any, RMF_Reg, RMF_Reg), + // PMOVMSKB reg, mm; PMOVMSKB reg, xmm + 215 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), + // PSUBUS*, PMINUB, PAND, PADDUS*, PMAXUB, PANDN, PAVGB, PSRAW, PSRAD, + // PAVGW, PMULHUW, PMULHW (mm, xmm) + op if 216 <= op & op <= 229 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // CVTTPD2DQ, CVTDQ2PD, CVTPD2DQ + 230 => rm_forms(mp, RMF_None, RMF_Any, RMF_Any, RMF_Any), + // MOVNTQ m64, mm; MOVNTDQ m128, xmm + 231 => rm_forms(mp, RMF_Mem, RMF_Mem, RMF_None, RMF_None), + // PSUBS*, PMINSW, POR, PADDS*, PMAXSW, PXOR (mm, xmm) + op if 232 <= op & op <= 239 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // LDDQU xmm, mem + 240 => with_feature(has_sse3, rm_forms(mp, RMF_None, RMF_None, RMF_None, RMF_Mem)), + // PSLLW, PSLLD, PSLLQ, PMULUDQ, PMADDWD, PSADBW (mm, xmm) + op if 241 <= op & op <= 246 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + // MASKMOVQ mm, mm; MASKMOVDQU xmm, xmm + 247 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), + // PSUBB/W/D/Q, PADDB/W/D (mm, xmm) + op if 248 <= op & op <= 254 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), + _ => RMF_None, +} + +// The SIMD opcodes of the 0F 38 map, as simd_0f_forms gives those of the +// 0F map: the SSSE3 forms with no prefix (MMX registers) or 66 (XMM +// registers), the 66 forms of SSE4.1, SSE4.2, GFNI and AES-NI, and the NP +// forms of SHA. The general-purpose instructions of the map (MOVBE, +// CRC32, ADCX, ADOX, INVEPT, INVPCID, MOVDIRI, MOVDIR64B, ENQCMD and +// ENQCMDS) are decoded ahead of these. +val simd_0f38_forms : (range(0, 255), MandatoryPrefix) -> RMForms +function simd_0f38_forms(op, mp) = { + let p66 : RMForms = rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_None); + match op { + // PSHUFB, PHADDW/D, PHADDSW, PMADDUBSW, PHSUBW/D, PHSUBSW, PSIGNB/W/D, + // PMULHRSW; PABSB/W/D (mm, xmm) + op if op <= 11 | (28 <= op & op <= 30) => + with_feature(has_ssse3, rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None)), + // PBLENDVB, BLENDVPS, BLENDVPD, PTEST; PMOVSX*; PMULDQ, PCMPEQQ, + // PACKUSDW; PMOVZX*; PMINSB ... PMULLD, PHMINPOSUW + op if op == 16 | op == 20 | op == 21 | op == 23 | (32 <= op & op <= 37) + | op == 40 | op == 41 | op == 43 | (48 <= op & op <= 53) + | (56 <= op & op <= 65) => with_feature(has_sse4_1, p66), + // MOVNTDQA xmm, m128 + 42 => with_feature(has_sse4_1, rm_forms(mp, RMF_None, RMF_Mem, RMF_None, RMF_None)), + // PCMPGTQ + 55 => with_feature(has_sse4_2, p66), + // SHA1NEXTE, SHA1MSG1, SHA1MSG2, SHA256RNDS2, SHA256MSG1, SHA256MSG2 + op if 200 <= op & op <= 205 => + with_feature(has_sha, rm_forms(mp, RMF_Any, RMF_None, RMF_None, RMF_None)), + // GF2P8MULB + 207 => with_feature(has_gfni, p66), + // AESIMC, AESENC, AESENCLAST, AESDEC, AESDECLAST + op if 219 <= op & op <= 223 => with_feature(has_aesni, p66), + _ => RMF_None, + } +} + +// The opcodes of the 0F 3A map, all SIMD: the 66 forms of SSE4.1, SSE4.2, +// PCLMULQDQ, GFNI and AES-NI, PALIGNR (SSSE3) with no prefix or 66, and +// the NP SHA1RNDS4. +val simd_0f3a_forms : (range(0, 255), MandatoryPrefix) -> RMForms +function simd_0f3a_forms(op, mp) = { + let p66 : RMForms = rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_None); + match op { + // ROUNDPS/PD/SS/SD, BLENDPS/PD, PBLENDW + op if 8 <= op & op <= 14 => with_feature(has_sse4_1, p66), + // PALIGNR (mm, xmm) + 15 => with_feature(has_ssse3, rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None)), + // PEXTRB, PEXTRW, PEXTRD/Q, EXTRACTPS; PINSRB, INSERTPS, PINSRD/Q; + // DPPS, DPPD, MPSADBW + op if (20 <= op & op <= 23) | (32 <= op & op <= 34) | (64 <= op & op <= 66) => + with_feature(has_sse4_1, p66), + // PCLMULQDQ + 68 => with_feature(has_pclmulqdq, p66), + // PCMPESTRM, PCMPESTRI, PCMPISTRM, PCMPISTRI + op if 96 <= op & op <= 99 => with_feature(has_sse4_2, p66), + // SHA1RNDS4 + 204 => with_feature(has_sha, rm_forms(mp, RMF_Any, RMF_None, RMF_None, RMF_None)), + // GF2P8AFFINEQB, GF2P8AFFINEINVQB + op if op == 206 | op == 207 => with_feature(has_gfni, p66), + // AESKEYGENASSIST + 223 => with_feature(has_aesni, p66), + _ => RMF_None, + } +} + +// The checks of a legacy-encoded SIMD instruction (MMX or SSE) of opcode +// op in map 1 (0F), 2 (0F 38) or 3 (0F 3A), made once its opcode is +// fetched and before its handler fetches and reads its operands: #UD for a +// mandatory prefix that leaves the opcode undefined, an r/m form it does +// not take, or a CPUID feature the processor lacks, all of which are +// decided on the opcode and the ModR/M byte; then the #UD of CR0.EM and +// the #NM of CR0.TS (check_cr0_sse). These are faults from decoding the +// instruction (SDM Vol.3A §7.9, Table 7-2), so they come ahead of the #GP, +// #PF or #AC of an operand access, which arise only as the instruction +// executes. Of the #UD and #NM, the manuals give no order; the model +// raises the #UD of the encoding first (exceptions.sail). +val check_legacy_simd : (range(1, 3), range(0, 255), Prefixes) -> unit +function check_legacy_simd(map, op, pfx) = { + let modrm = peek_modrm(); + let is_reg : bool = modrm[7..6] == 0b11; + let mp = get_mandatory_prefix(pfx); + let forms : RMForms = match map { + 1 => simd_0f_forms(op, mp, unsigned(modrm[5..3])), + 2 => simd_0f38_forms(op, mp), + 3 => simd_0f3a_forms(op, mp), + }; + match forms { + RMF_None => raise_UD(), + RMF_Reg => if ~(is_reg) then raise_UD(), + RMF_Mem => if is_reg then raise_UD(), + RMF_Any => (), + }; + check_cr0_sse() +} + +val dispatch_opcode_2byte : (byte, Prefixes) -> unit +function dispatch_opcode_2byte(opcode, pfx) = { + let op : range(0, 255) = unsigned(opcode); + // LOCK prefix is only valid on specific 2-byte opcodes; #UD otherwise. + if pfx.has_lock & ~(is_lockable_2byte(op)) then raise_UD(); + match op { + // 0F 38: 3-byte escape (SSSE3/SSE4/AES-NI) + 56 => { + let opcode3 = fetch(1); + let op3 : range(0, 255) = unsigned(opcode3); + if op3 == 246 then { + // ADCX (66) / ADOX (F3) + // The 66/F3 prefix is a mandatory prefix, NOT an operand size override. + // Operand size is determined by REX.W only: W=1 → 64-bit, else 32-bit. + if ~(has_adx) then raise_UD(); + let mp = get_mandatory_prefix(pfx); + let os : {32, 64} = if pfx.rex_w then 64 else 32; + let (reg, src) = fetch_modrm(pfx); + let src_val = v(os, src); + if mp == MP_66 then { + let a = v(os, reg); + let result = a + src_val + zero_extend(CF); + let w = (0b0 @ a) + (0b0 @ src_val) + zero_extend(CF); + CF = w[os]; + v(reg) = result + } else if mp == MP_F3 then { + let a = v(os, reg); + let result = a + src_val + zero_extend(OF); + let w = (0b0 @ a) + (0b0 @ src_val) + zero_extend(OF); + OF = w[os]; + v(reg) = result + } else { + raise_UD() + } + } else if op3 == 128 & get_mandatory_prefix(pfx) == MP_66 then { + // 66 0F 38 80: INVEPT r64, m128 — Invalidate EPT TLB + if cur_cpl != 0 then raise_GP0(); + if ~(in_vmx_root) & ~(in_vmx_non_root) then raise_UD(); + if in_vmx_non_root then { + vmcs.exit_instr_length = (decode_pos - insn_start)[31..0]; + throw VMExit(VMEXIT_INVEPT, 0x0000000000000000) + }; + let (reg, src) = fetch_modrm(pfx); + let _ : xmmword = rm_mem(src); // consume operand + __tlb_flush(); + vmx_succeed() + } else if op3 == 130 & get_mandatory_prefix(pfx) == MP_66 then { + // 66 0F 38 82: INVPCID r64, m128 — Invalidate TLB by PCID. The + // register form is undefined, a decode-time #UD ahead of the + // privilege check (SDM Vol.3A §7.9). + let (reg, src) = fetch_modrm(pfx); + let m : MemRef = match src { RM_mem(m) => m, RM_reg(_) => raise_UD() }; + if cur_cpl != 0 then raise_GP0(); + let desc : xmmword = read_mem(m); + let inv_type : qword = v(reg); + if unsigned(inv_type) > 3 then raise_GP0(); + let reserved : bits(52) = desc[63..12]; + let pcid : bits(12) = desc[11..0]; + // The bits of the linear address that are all equal when it is + // canonical: 63:47, or 63:56 with 5-level paging (CR4.LA57), as in + // seg_linear. + let top17 : bits(17) = + if CR4[12] == 0b1 then sign_extend(desc[127..120]) else desc[127..111]; + // SDM INVPCID, 64-bit mode #GP(0): bits 63:12 of the descriptor + // are not all zero (any type); CR4.PCIDE = 0, type 0 or 1, and a + // nonzero PCID; type 0 and a non-canonical linear address. + let is_type_01 : bit = ~(inv_type[1]); + let is_type_0 : bit = ~(inv_type[1] | inv_type[0]); + let bad_reserved : bit = ~(((0b0 @ reserved) - 1)[52]); + let bad_pcid : bit = ~(((0b0 @ pcid) - 1)[12]) & ~(CR4[17]); // CR4.PCIDE + let diff : bits(17) = top17 ^ sign_extend(top17[16]); + let non_canonical : bit = ~(((0b0 @ diff) - 1)[17]); + let fault : bit = bad_reserved | (is_type_01 & bad_pcid) | (is_type_0 & non_canonical); + if fault == 0b1 then raise_GP0(); + __tlb_flush() + } else if (op3 == 240 | op3 == 241) then { + // MOVBE (0F 38 F0/F1) or CRC32 (F2 0F 38 F0/F1) + let mp = get_mandatory_prefix(pfx); + if mp == MP_F2 then { + if ~(has_crc32) then raise_UD(); + let (reg, src) = fetch_modrm(pfx); + let os = if op3 == 240 then 8 else opsize(pfx); + let src_val = v(os, src); + let result : bits(32) = crc32c(v(32, reg), src_val); + if pfx.rex_w then { + v(reg) = zero_extend(64, result) + } else { + v(reg) = result + } + } else { + // MOVBE (0F 38 F0/F1) — load/store with byte swap. The opcode + // is defined with no prefix, 66 (16-bit operands) and F2 (CRC32) + // only (SDM Vol.2B MOVBE, CRC32): F3 is #UD. + if mp == MP_F3 then raise_UD(); + if ~(has_movbe) then raise_UD(); + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + if op3 == 240 then { + v(os, reg) = bswap(rm_mem(os, dest)) + } else { + rm_mem(dest) = bswap(v(os, reg)) + } + } + } else if op3 == 249 & get_mandatory_prefix(pfx) == MP_NONE then { + // MOVDIRI m32/m64, r32/r64 (NP 0F 38 F9) + if ~(has_movdiri) then raise_UD(); + let (reg, dest) = fetch_modrm(pfx); + let os = if pfx.rex_w then 64 else 32; + rm_mem(dest) = v(os, reg) + } else if op3 == 248 & get_mandatory_prefix(pfx) == MP_66 then { + // MOVDIR64B r, m512 (66 0F 38 F8) + exec_movdir64b(pfx) + } else if op3 == 248 & (get_mandatory_prefix(pfx) == MP_F2 + | get_mandatory_prefix(pfx) == MP_F3) then { + // ENQCMD r, m512 (F2 0F 38 F8) and ENQCMDS r, m512 (F3 0F 38 F8) + exec_enqcmd(pfx, get_mandatory_prefix(pfx) == MP_F3) + } else { + // The SIMD opcodes (simd_0f38_forms) + check_legacy_simd(2, op3, pfx); + match op3 { + // BLENDVPS or BLENDVPD + op3 if op3 == 20 | op3 == 21 => dispatch_3byte_38_sse_fp(opcode3, pfx), + // SHA extensions (NP 0F 38 C8-CD) + op3 if 200 <= op3 & op3 <= 205 => { + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let src_xmm : xmmword = decode_xmm_src(src); + match op3 { + // SHA1NEXTE xmm1, xmm2/m128 + 200 => ZMM[xreg][127..0] = sha1nexte(read_simd(xreg), src_xmm), + // SHA1MSG1 xmm1, xmm2/m128 + 201 => ZMM[xreg][127..0] = sha1msg1(read_simd(xreg), src_xmm), + // SHA1MSG2 xmm1, xmm2/m128 + 202 => ZMM[xreg][127..0] = sha1msg2(read_simd(xreg), src_xmm), + // SHA256RNDS2 xmm1, xmm2/m128, + 203 => ZMM[xreg][127..0] = sha256rnds2(read_simd(xreg), src_xmm, read_simd(0)), + // SHA256MSG1 xmm1, xmm2/m128 + 204 => ZMM[xreg][127..0] = sha256msg1(read_simd(xreg), src_xmm), + // SHA256MSG2 xmm1, xmm2/m128 + 205 => ZMM[xreg][127..0] = sha256msg2(read_simd(xreg), src_xmm), + _ => raise_UD(), + } + }, + _ => dispatch_3byte_38_sse_int(opcode3, pfx), + } + } + }, + // 0F 3A: 3-byte escape (SSE4/AES-NI with imm8), all SIMD (simd_0f3a_forms) + 58 => { + let opcode3 = fetch(1); + let op3 : range(0, 255) = unsigned(opcode3); + check_legacy_simd(3, op3, pfx); + match op3 { + // SSE4.1 FP: ROUNDPS/PD/SS/SD, BLENDPS/PD, PEXTRW, EXTRACTPS, INSERTPS, DPPS, DPPD + op3 if (8 <= op3 & op3 <= 13) | op3 == 21 | op3 == 23 | op3 == 33 | op3 == 64 | op3 == 65 => + dispatch_3byte_3a_sse_fp(opcode3, pfx), + 204 => { + // SHA1RNDS4 xmm1, xmm2/m128, imm8 (NP 0F 3A CC /r ib) + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let imm : byte = fetch(1); + let src_xmm : xmmword = decode_xmm_src(src); + ZMM[xreg][127..0] = sha1rnds4(read_simd(xreg), src_xmm, imm) + }, + _ => dispatch_3byte_3a_sse_int(opcode3, pfx), + } + }, + + // SSE floating-point (data movement, arithmetic, conversion, comparison) + op if (16 <= op & op <= 23) | (40 <= op & op <= 47) | (80 <= op & op <= 95) + | op == 124 | op == 125 | op == 194 | op == 198 + | op == 208 | op == 214 | op == 230 => { + check_legacy_simd(1, op, pfx); + dispatch_2byte_sse_fp(op, pfx) + }, + + // SSE integer (packed integer arithmetic, logical, shift, pack/unpack) + // and, without a mandatory prefix, MMX (dispatch_mmx) + op if (96 <= op & op <= 118) | op == 126 | op == 127 | op == 196 | op == 197 + | (209 <= op & op <= 213) | (215 <= op & op <= 229) + | (231 <= op & op <= 255) => { + check_legacy_simd(1, op, pfx); + dispatch_2byte_sse_int(op, pfx) + }, + + // GPR and system operations (everything else) + _ => dispatch_2byte_gpr(op, pfx), + } +} + +// ========================================================================= +// 1-Byte Opcode Map Dispatch +// ========================================================================= + +// Check if a 1-byte opcode is lockable (LOCK prefix valid with memory dest). +// Lockable: ALU cols 0-1 (00-3F), 80-83 (ALU imm), 86-87 (XCHG), +// F6/F7 (NOT /2, NEG /3), FE/FF (INC /0, DEC /1) +val is_lockable_1byte : range(0, 255) -> bool +function is_lockable_1byte(op) = { + match op { + op if op <= 63 & (op % 8 == 0 | op % 8 == 1) => true, // ALU r/m, r + op if 128 <= op & op <= 131 => true, // 80-83: ALU r/m, imm + op if 134 <= op & op <= 135 => true, // 86-87: XCHG + op if 246 <= op & op <= 247 => true, // F6-F7: TEST/NOT/NEG/MUL/DIV + op if 254 <= op & op <= 255 => true, // FE-FF: INC/DEC + _ => false, + } +} + +// IRET uses the privilege before the return to decide which flags can +// change (SDM Vol.2A, RETURN-TO-SAME/OUTER-PRIVILEGE-LEVEL, pp.3-493, +// 3-495). In particular a ring-3 IRET cannot clear or raise IOPL. +val restore_iret_flags : ({16, 32, 64}, qword, cpl_t, bool) -> unit +function restore_iret_flags(os, image, old_cpl, protected_return) = { + var flags : qword = image; + if protected_return then { + if old_cpl > unsigned(IOPL) then flags[9] = IF_flag; + if old_cpl != 0 then flags[13..12] = IOPL + }; + if os == 16 then + write_rflags((read_rflags() & 0xFFFFFFFFFFFF0000) | zero_extend(flags[15..0])) + else { + write_rflags(flags); + RF = flags[16]; + if protected_return & old_cpl == 0 then { + VIF = flags[19]; + VIP = flags[20] + } + } +} + +// Legacy protected-mode RETF. SDM Vol.2B RET, Protected Mode and +// RETURN-TO-SAME/OUTER-PRIVILEGE-LEVEL, pp.4-571--4-575. In particular, +// a not-present return CS must fault before its descriptor is installed. +val exec_legacy_retf : ({16, 32}, option(word)) -> unit +function exec_legacy_retf(os, maybe_imm) = { + let sas = stack_addr_size(); + let old_sp : qword = zero_extend(v(sas, RSP)); + let adjustment : word = match maybe_imm { Some(i) => i, None() => 0x0000 }; + check_seg_limit(SS, old_sp, 2 * (os / 8)); + let (ip, cs) = pop_far_pointer(os); + if cs[15..2] == zeros() then raise_GP0(); + let code = read_descriptor(cs); + let rpl : cpl_t = unsigned(cs[1..0]); + let err = selector_error_code(cs); + if code.seg_s == 0b0 | code.seg_type[3] == 0b0 | rpl < cur_cpl then + throw Fault(EXN_GP, err); + if (code.seg_type[2] == 0b1 & code.seg_dpl > rpl) | + (code.seg_type[2] == 0b0 & code.seg_dpl != rpl) then + throw Fault(EXN_GP, err); + if code.seg_present == 0b0 then throw Fault(EXN_NP, err); + var accessed_code = code; + + if rpl > cur_cpl then { + check_seg_limit(SS, old_sp, 4 * (os / 8) + unsigned(adjustment)); + v(sas, RSP) = v(sas, RSP) + zero_extend(adjustment); + let (sp, ss) = pop_far_pointer(os); + if ss[15..2] == zeros() then raise_GP0(); + let stack = read_descriptor(ss); + let ss_err = selector_error_code(ss); + if unsigned(ss[1..0]) != rpl | stack.seg_dpl != rpl | + stack.seg_s == 0b0 | stack.seg_type[3] == 0b1 | + stack.seg_type[1] == 0b0 then throw Fault(EXN_GP, ss_err); + if stack.seg_present == 0b0 then throw Fault(EXN_SS, ss_err); + if unsigned(ip) > unsigned(code.seg_limit) then raise_GP0(); + // All faulting checks precede architectural segment/CPL changes. + accessed_code = access_segment_descriptor(cs, code); + let accessed_stack = access_segment_descriptor(ss, stack); + write_segreg(SS, ss); + SegCache[SS] = accessed_stack; + v(RSP) = sp; + cur_cpl = rpl; + foreach (seg from 0 to 5) { + if seg != CS & seg != SS then { + let desc = SegCache[seg]; + if read_segreg(seg)[15..2] == zeros() | + (desc.seg_dpl < rpl & + (desc.seg_type[3] == 0b0 | desc.seg_type[2] == 0b0)) then + write_segreg(seg, 0x0000) + } + }; + let new_sas = stack_addr_size(); + v(new_sas, RSP) = v(new_sas, RSP) + zero_extend(adjustment) + } else { + if unsigned(ip) > unsigned(code.seg_limit) then raise_GP0(); + accessed_code = access_segment_descriptor(cs, code); + v(sas, RSP) = v(sas, RSP) + zero_extend(adjustment) + }; + write_segreg(CS, cs); + SegCache[CS] = accessed_code; + next_rip = Some(ip) +} + +// RETF — Far return (opcodes CA, CB). +// In 64-bit mode, default operand size is 32; REX.W makes it 64. +// Same-privilege: pop RIP, CS. +// Outer-privilege (RPL > CPL): also pop RSP, SS, then set CPL = RPL. +// SDM Vol.2 RET — IA-32e Mode Operation. +val exec_retf : (Prefixes, option(word)) -> unit +function exec_retf(pfx, maybe_imm) = { + if cur_mode == ProtectedMode & EFER[10] == 0b0 then { + exec_legacy_retf(if opsize(pfx) == 32 then 32 else 16, maybe_imm); + return () + }; + // Operand size: in 64-bit mode, default is 32, REX.W → 64, 66h → 16. + // In non-64-bit mode, determined by CS.D and 66h prefix. + let os : {16, 32, 64} = if cur_mode == LongMode then { + if pfx.rex_w then 64 + else if pfx.has_opsize then 16 + else 32 + } else { + opsize(pfx) + }; + + // Pop return RIP and CS as a single operation. + let (new_rip, new_cs) = pop_far_pointer(os); + + // In protected/long mode, null CS selector is invalid. + // In real mode, CS=0x0000 is a valid segment (linear address 0). + let protected_return = cur_mode != RealMode & cur_mode != Virtual8086Mode; + if cur_mode == Virtual8086Mode & unsigned(new_rip) > 65535 then raise_GP0(); + if protected_return & new_cs == 0x0000 then { + throw Fault(EXN_GP, 0x00000000) + }; + + let return_rpl : cpl_t = unsigned(new_cs[1..0]); + + // RPL must not be less than current CPL (not applicable in real mode) + if protected_return & return_rpl < cur_cpl then { + throw Fault(EXN_GP, selector_error_code(new_cs)) + }; + + // In real mode, far return simply pops IP and CS — no privilege checks, + // no SS/RSP pop (SDM Vol.2B RET, "Real-address mode or virtual-8086 mode"). + // In protected/long mode, check RPL for inter-privilege return. + if protected_return & return_rpl > cur_cpl then { + // Outer-privilege return (SDM Vol.2B RET — IA-32e Mode): + // First release callee's parameters (RSP += imm16), then pop outer RSP/SS. + match maybe_imm { + Some(imm) => v(RSP) = v(64, RSP) + zero_extend(imm), + None() => (), + }; + let (new_rsp, new_ss) = pop_far_pointer(os); + v(RSP) = new_rsp; + load_segment_register(SS, new_ss); + } else { + // Same-privilege (or real mode): adjust RSP for imm16 if present + match maybe_imm { + Some(imm) => v(RSP) = v(64, RSP) + zero_extend(imm), + None() => (), + } + }; + + // Load new CS (selector + descriptor cache) and set CPL + load_segment_register(CS, new_cs); + // Update cur_mode: in IA-32e mode, CS.L determines 64-bit vs compatibility + if EFER[10] == 0b1 then { + set_mode(if SegCache[CS].seg_l == 0b1 then LongMode else CompatibilityMode) + }; + // In real mode, CPL is always 0 (no privilege levels). + if protected_return then cur_cpl = return_rpl; + + // Set RIP to return address + next_rip = Some(new_rip) +} + +val decode_execute : unit -> unit +function decode_execute() = { + let (pfx, opcode) = scan_prefixes(); + let op : range(0, 255) = unsigned(opcode); + + // LOCK prefix is only valid on specific opcodes; #UD otherwise. + // (Per-instruction checks for register vs memory are done later.) + if pfx.has_lock & ~(is_lockable_1byte(op)) & op != 15 then raise_UD(); + if op <= 63 & op % 8 <= 5 then { + // ALU instructions 00-3F (regular pattern, columns 0-5 only) + dispatch_alu_opcode(op, pfx) + } else { + match op { + // 06: PUSH ES — Push ES selector onto stack (SDM Vol.2B PUSH) + // Invalid in 64-bit mode. The operand size determines the push + // width (push_segreg). + 6 => { + if cur_mode == LongMode then raise_UD(); + push_segreg(opsize(pfx), ES) + }, + + // 07: POP ES — Pop stack into ES (SDM Vol.2B POP) + // Invalid in 64-bit mode. Pops operand-size value, loads low 16 bits + // into ES and updates descriptor cache (load_segment_register). + 7 => { + if cur_mode == LongMode then raise_UD(); + let os = opsize(pfx); + let x : word = match os { + 32 => pop(32)[15..0], + _ => pop(16), + }; + load_data_segment_register(ES, x) + }, + + // 0E: PUSH CS — Push CS selector onto stack (SDM Vol.2B PUSH) + // Invalid in 64-bit mode. + 14 => { + if cur_mode == LongMode then raise_UD(); + push_segreg(opsize(pfx), CS) + }, + + // 0F: Two-byte escape + 15 => { + let opcode2 = fetch(1); + dispatch_opcode_2byte(opcode2, pfx) + }, + + // 16: PUSH SS — Push SS selector onto stack (SDM Vol.2B PUSH) + // Invalid in 64-bit mode. + 22 => { + if cur_mode == LongMode then raise_UD(); + push_segreg(opsize(pfx), SS) + }, + + // 17: POP SS — Pop stack into SS (SDM Vol.2B POP) + // Invalid in 64-bit mode. Loading SS inhibits interrupts and the + // single-step trap until after the next instruction (SDM Vol.3A §7.8.3). + 23 => { + if cur_mode == LongMode then raise_UD(); + let os = opsize(pfx); + let x : word = match os { + 32 => pop(32)[15..0], + _ => pop(16), + }; + load_data_segment_register(SS, x); + ss_shadow = 2 + }, + + // 1E: PUSH DS — Push DS selector onto stack (SDM Vol.2B PUSH) + // Invalid in 64-bit mode. + 30 => { + if cur_mode == LongMode then raise_UD(); + push_segreg(opsize(pfx), DS) + }, + + // 1F: POP DS — Pop stack into DS (SDM Vol.2B POP) + // Invalid in 64-bit mode. + 31 => { + if cur_mode == LongMode then raise_UD(); + let os = opsize(pfx); + let x : word = match os { + 32 => pop(32)[15..0], + _ => pop(16), + }; + load_data_segment_register(DS, x) + }, + + // 27: DAA — Decimal Adjust AL After Addition (SDM Vol.2A) + // #UD in 64-bit mode. Adjusts packed BCD result in AL after ADD. + 39 => { + if cur_mode == LongMode then raise_UD(); + let old_al : byte = v(RAX); + let old_cf = CF; + let lo : bits(4) = old_al[3..0]; + let cond1 : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; + let al1 : byte = old_al + (0x06 & sign_extend(cond1)); + AF = cond1[0]; + let cond2 : bits(1) = ~(((0b0 @ old_al) - 0b0_1001_1010)[8]) | old_cf; + let al_final : byte = al1 + (0x60 & sign_extend(cond2)); + CF = cond2[0]; + v(RAX) = al_final; + update_SF_ZF_PF(al_final); + OF = undefined + }, + + // 2F: DAS — Decimal Adjust AL After Subtraction (SDM Vol.2A) + // #UD in 64-bit mode. Adjusts packed BCD result in AL after SUB. + 47 => { + if cur_mode == LongMode then raise_UD(); + let old_al : byte = v(RAX); + let old_cf = CF; + let lo : bits(4) = old_al[3..0]; + let cond1 : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; + let al1 : byte = old_al - (0x06 & sign_extend(cond1)); + let borrow1 : bits(5) = (0b0 @ lo) - (0b0 @ 0b0110); + AF = cond1[0]; + let cond2 : bits(1) = ~(((0b0 @ old_al) - 0b0_1001_1010)[8]) | old_cf; + let al_final : byte = al1 - (0x60 & sign_extend(cond2)); + CF = (cond2 | (cond1 & (old_cf | borrow1[4])))[0]; + v(RAX) = al_final; + update_SF_ZF_PF(al_final); + OF = undefined + }, + + // 37: AAA — ASCII Adjust After Addition (SDM Vol.2A) + // #UD in 64-bit mode. Adjusts unpacked BCD result in AL/AH. + 55 => { + if cur_mode == LongMode then raise_UD(); + let lo : bits(4) = v(8, RAX)[3..0]; + let cond : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; + let new_ax : word = v(RAX) + (0x0106 & sign_extend(cond)); + v(RAX) = new_ax; + AF = cond[0]; + CF = cond[0]; + v(RAX) = new_ax[7..0] & 0x0F; + OF = undefined; + SF = undefined; + ZF = undefined; + PF = undefined; + }, + + // 3F: AAS — ASCII Adjust AL After Subtraction (SDM Vol.2A) + // #UD in 64-bit mode. Adjusts unpacked BCD result in AL/AH. + 63 => { + if cur_mode == LongMode then raise_UD(); + let lo : bits(4) = v(8, RAX)[3..0]; + let cond : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; + let new_ax : word = v(RAX) - (0x0106 & sign_extend(cond)); + v(RAX) = new_ax; + AF = cond[0]; + CF = cond[0]; + v(RAX) = new_ax[7..0] & 0x0F; + OF = undefined; + SF = undefined; + ZF = undefined; + PF = undefined; + }, + + // 40-47: INC r32/r16 (compat/protected mode only; REX prefix in 64-bit) + op if 64 <= op & op <= 71 => { + let reg : range(0, 7) = op - 64; + let os = opsize(pfx); + v(reg) = exec_inc(v(os, reg)) + }, + + // 48-4F: DEC r32/r16 (compat/protected mode only; REX prefix in 64-bit) + op if 72 <= op & op <= 79 => { + let reg : range(0, 7) = op - 72; + let os = opsize(pfx); + v(reg) = exec_dec(v(os, reg)) + }, + + // 50-57: PUSH reg (default64) + op if 80 <= op & op <= 87 => { + let reg_field : range(0, 7) = op - 80; + let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); + let os = opsize_default64(pfx); + match os { + 16 => push(16, v(reg)), + 32 => if cur_mode == LongMode + then push(64, zero_extend(v(32, reg))) + else push(32, v(reg)), + 64 => push(64, v(reg)), + } + }, + + // 58-5F: POP reg (default64) + op if 88 <= op & op <= 95 => { + let reg_field : range(0, 7) = op - 88; + let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); + let os = opsize_default64(pfx); + exec_pop_reg(reg, os) + }, + + // 60: PUSHA/PUSHAD — Push All General-Purpose Registers + // #UD in 64-bit mode. Pushes AX..DI (16) or EAX..EDI (32). + // Push order: AX, CX, DX, BX, original SP, BP, SI, DI. + 96 => { + if cur_mode == LongMode then raise_UD(); + let os = opsize(pfx); + match os { + 32 => push(256, v(32, RAX) @ v(32, RCX) @ v(32, RDX) @ v(32, RBX) @ + v(32, RSP) @ v(32, RBP) @ v(32, RSI) @ v(32, RDI)), + _ => push(128, v(16, RAX) @ v(16, RCX) @ v(16, RDX) @ v(16, RBX) @ + v(16, RSP) @ v(16, RBP) @ v(16, RSI) @ v(16, RDI)), + } + }, + + // 61: POPA/POPAD — Pop All General-Purpose Registers + // #UD in 64-bit mode. Pops DI..AX (16) or EDI..EAX (32). + // Pop order: EDI, ESI, EBP, skip ESP slot, EBX, EDX, ECX, EAX. + 97 => { + if cur_mode == LongMode then raise_UD(); + let os = opsize(pfx); + match os { + 32 => { + // Pop all 8 dwords; the ESP slot is discarded. + v(RDI) = pop(32); + v(RSI) = pop(32); + v(RBP) = pop(32); + let _ = pop(32); // skip ESP + v(RBX) = pop(32); + v(RDX) = pop(32); + v(RCX) = pop(32); + v(RAX) = pop(32) + }, + _ => { + // Pop all 8 words; the SP slot is discarded. + v(RDI) = pop(16); + v(RSI) = pop(16); + v(RBP) = pop(16); + let _ = pop(16); // skip SP + v(RBX) = pop(16); + v(RDX) = pop(16); + v(RCX) = pop(16); + v(RAX) = pop(16) + }, + } + }, + + // 62: EVEX prefix, or BOUND (in 16/32-bit mode). + // SDM Vol.2 §2.7.11.2, opcode-independent: in non-64-bit modes the + // byte after 62h decodes as EVEX iff its top two bits (EVEX.R̄X̄) + // are 11b; any other value makes it BOUND's ModR/M, which is then + // necessarily a memory form (mod=11b would have meant EVEX) — + // the same peek-and-disambiguate structure as C4/C5 VEX-vs-LES/LDS. + // In 64-bit mode, 0x62 is always the EVEX prefix. + 98 => { + if cur_mode == LongMode then { + if vex_after_legacy_prefix(pfx) then raise_UD(); + dispatch_evex(pfx) + } else { + let byte2 = fetch(1); + if byte2[7..6] == 0b11 then { + if vex_after_legacy_prefix(pfx) then raise_UD(); + dispatch_evex_with_p0(byte2, pfx) + } else { + // BOUND r16/r32, m16&16/m32&32: #BR if index out of bounds. + let modrm = byte2; + let src = modrm_rm(modrm, pfx); + match src { + RM_reg(_) => raise_UD(), // unreachable: mod=11 is EVEX + RM_mem(m) => { + let os = opsize(pfx); + assert(os <= 32); + let reg = modrm_reg(modrm, pfx); + let index = signed(v(os, reg)); + // BOUND reads two consecutive os-bit values (lower, upper bounds) + let d = v(os * 2, m); + if index < signed(d[os - 1 .. 0]) | signed(d[os * 2 - 1 .. os]) < index then + raise_BR(); + }, + } + } + } + }, + + // 63: MOVSXD r64, r/m32 in 64-bit mode; ARPL r/m16, r16 in protected + // and compatibility mode (SDM Vol.2A ARPL: "not encodable in 64-bit + // mode", #UD in real-address mode) + 99 => { + if cur_mode == LongMode then { + let (reg, src) = fetch_modrm(pfx); + if pfx.rex_w then { + v(reg) = sign_extend(64, v(32, src)) + } else { + let os = opsize(pfx); + v(reg) = v(os, src) + } + } else if cur_mode == RealMode | cur_mode == Virtual8086Mode then { + raise_UD() + } else { + // IF DEST[RPL] < SRC[RPL] THEN ZF := 1; DEST[RPL] := SRC[RPL] + // ELSE ZF := 0. Only ZF is affected. + let (reg, dest) = fetch_modrm(pfx); + let d : word = v(16, dest); + let s : word = v(16, reg); + if unsigned(d[1..0]) < unsigned(s[1..0]) then { + ZF = 0b1; + v(dest) = d[15..2] @ s[1..0] + } else { + ZF = 0b0 + } + } + }, + + // 68: PUSH imm16/32 (d64, Iz) + 104 => { + let os = opsize_default64(pfx); + let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); + exec_push_imm(imm[(os - 1) .. 0]) + }, + + // 69: IMUL r, r/m, imm (3-operand, Iz) + 105 => { + let 'os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + // Fetch imm BEFORE reading src so decode_pos is final for RIP-relative fixup + let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); + let src_val = v(os, src); + let product : int = signed(src_val[os - 1 .. 0]) * signed(imm[os - 1 .. 0]); + let result : qword = to_bits_truncate(product); + let w : bits('os * 2) = to_bits_truncate(product); + CF = is_nonzero(w['os * 2 - 1 .. 'os] ^ sign_extend(w['os - 1])); + OF = CF; + // SDM: SF, ZF, AF, PF are undefined after IMUL. + SF = undefined; + ZF = undefined; + AF = undefined; + PF = undefined; + v(reg) = result[(os - 1) .. 0] + }, + + // 6A: PUSH imm8 (d64, sign-extended) + 106 => { + let os = opsize_default64(pfx); + let imm : qword = sign_extend(fetch(1)); + exec_push_imm(imm[(os - 1) .. 0]) + }, + + // 6B: IMUL r, r/m, imm8 (3-operand, Ib sign-extended) + 107 => { + let 'os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + // Fetch imm BEFORE reading src so decode_pos is final for RIP-relative fixup + let imm : qword = sign_extend(fetch(1)); + let src_val = v(os, src); + let product : int = signed(src_val[os - 1 .. 0]) * signed(imm[os - 1 .. 0]); + let result : qword = to_bits_truncate(product); + let w : bits('os * 2) = to_bits_truncate(product); + CF = is_nonzero(w['os * 2 - 1 .. 'os] ^ sign_extend(w['os - 1])); + OF = CF; + // SDM: SF, ZF, AF, PF are undefined after IMUL. + SF = undefined; + ZF = undefined; + AF = undefined; + PF = undefined; + v(reg) = result[(os - 1) .. 0] + }, + + // 6C: INSB — Input byte from port DX to ES:[RDI] + 108 => { + vmx_exit_if_io(v(RDX), 8, true); + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_ins, 8, asz, pfx) + else exec_ins(8, asz) + }, + // 6D: INSW/INSD — Input word/dword from port DX to ES:[RDI] + 109 => { + let os = opsize(pfx); + vmx_exit_if_io(v(RDX), os, true); + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_ins, os, asz, pfx) + else exec_ins(os, asz) + }, + // 6E: OUTSB — Output byte from DS:[RSI] to port DX + 110 => { + vmx_exit_if_io(v(RDX), 8, false); + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_outs, 8, asz, pfx) + else exec_outs(8, asz, pfx) + }, + // 6F: OUTSW/OUTSD — Output word/dword from DS:[RSI] to port DX + 111 => { + let os = opsize(pfx); + vmx_exit_if_io(v(RDX), os, false); + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_outs, os, asz, pfx) + else exec_outs(os, asz, pfx) + }, + + // 70-7F: Jcc rel8 (forced64) + op if 112 <= op & op <= 127 => { + let cc : cc_idx = op - 112; + let offset : qword = sign_extend(fetch(1)); + if eval_cc(cc) == 0b1 then { + let os = opsize_forced64(pfx); + next_rip = Some(zero_extend((decode_pos + offset)[(os - 1) .. 0])); + } + }, + + // 80/82: Group 1 — ALU r/m8, imm8. SDM Vol.3B 25.15 + // defines 82h as the 80h alias outside 64-bit mode only. + // (A guard rather than an or-pattern: the official Sail parser + // does not accept `128 | 130 =>`.) + op if op == 128 | op == 130 => { + if op == 130 & cur_mode == LongMode then raise_UD(); + let (reg_field, dest) = fetch_modrm_raw(pfx); + let imm : byte = fetch(1); + let alu_op = group1_op(reg_field); + check_lock_rm(pfx, dest, alu_op == ALU_CMP); + exec_alu_rm_imm(alu_op, dest, imm, 8) + }, + + // 81: Group 1 — ALU r/m, imm (Iz) + 129 => { + let os = opsize(pfx); + let (reg_field, dest) = fetch_modrm_raw(pfx); + let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); + let alu_op = group1_op(reg_field); + check_lock_rm(pfx, dest, alu_op == ALU_CMP); + exec_alu_rm_imm(alu_op, dest, imm[(os - 1) .. 0], os) + }, + + // 83: Group 1 — ALU r/m, imm8 (sign-extended) + 131 => { + let os = opsize(pfx); + let (reg_field, dest) = fetch_modrm_raw(pfx); + let imm : qword = sign_extend(fetch(1)); + let alu_op = group1_op(reg_field); + check_lock_rm(pfx, dest, alu_op == ALU_CMP); + exec_alu_rm_imm(alu_op, dest, imm[(os - 1) .. 0], os) + }, + + // 84: TEST r/m8, r8 + 132 => { + let (reg, src) = fetch_modrm(pfx); + update_flags_logic(v(8, src) & v(8, reg)) + }, + + // 85: TEST r/m, r + 133 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + update_flags_logic(v(os, src) & v(os, reg)) + }, + + // 86: XCHG r/m8, r8 + 134 => { + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + let tmp : byte = read_rmw(dest); + v(dest) = v(8, reg); + v(reg) = tmp + }, + + // 87: XCHG r/m, r + 135 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + check_lock_rm(pfx, dest, false); + let tmp = read_rmw(os, dest); + v(dest) = v(os, reg); + v(reg) = tmp + }, + + // 88: MOV r/m8, r8 + 136 => { + let (reg, dest) = fetch_modrm(pfx); + v(dest) = v(8, reg) + }, + + // 89: MOV r/m, r + 137 => { + let os = opsize(pfx); + let (reg, dest) = fetch_modrm(pfx); + v(dest) = v(os, reg) + }, + + // 8A: MOV r8, r/m8 + 138 => { + let (reg, src) = fetch_modrm(pfx); + v(reg) = v(8, src) + }, + + // 8B: MOV r, r/m + 139 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + v(reg) = v(os, src) + }, + + // 8C: MOV r/m16, sreg + 140 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + if reg_field > 5 then raise_UD(); + assert(reg_field <= 5); + let seg : segreg_idx = reg_field; + match dest { + RM_reg(r) => { + let os = opsize(pfx); + v(r) = zero_extend(os, read_segreg(seg)) + }, + RM_mem(m) => v(m) = read_segreg(seg), + } + }, + + // 8D: LEA r, m + 141 => { + let os = opsize(pfx); + let (reg, src) = fetch_modrm(pfx); + match src { + RM_mem(m) => v(reg) = m.addr[(os - 1) .. 0], + RM_reg(_) => raise_UD(), + } + }, + + // 8E: MOV sreg, r/m16 + 142 => { + let (reg_field, src) = fetch_modrm_raw(pfx); + if reg_field > 5 then raise_UD(); + assert(reg_field <= 5); + let seg : segreg_idx = reg_field; + if seg == CS then raise_UD(); + load_data_segment_register(seg, v(src)); + // Loading SS starts the one-instruction shadow that holds interrupts + // and the single-step trap (SDM Vol.3A §7.8.3); LSS does not. + if seg == SS then ss_shadow = 2 + }, + + // 8F /0: POP r/m (default64) + // SDM: "If the RSP register is used as a base register for addressing + // a destination operand in memory, the POP instruction computes the + // effective address of the operand after it increments the RSP register." + 143 => { + let modrm = fetch(1); + let reg_field : range(0, 7) = unsigned(modrm[5..3]); + if reg_field != 0 then raise_UD(); + let os = opsize_default64(pfx); + let mod_field : range(0, 3) = unsigned(modrm[7..6]); + if mod_field == 3 then { + // Register destination — no address computation issue + let idx = unsigned(pfx.rex_b @ modrm[2..0]); + exec_pop_reg(idx, os) + } else { + // Memory destination: pop first, THEN compute effective address + // (SDM requires RSP-relative addresses use the post-pop RSP). + // We pop first so that modrm_rm sees the updated RSP. + let a : qword = zero_extend(pop(os)); + let dest = modrm_rm(modrm, pfx); + match dest { + RM_mem(m) => v(m) = a[(os - 1) .. 0], + _ => raise_UD(), + } + } + }, + + // 90: NOP / PAUSE (F3 90) / XCHG R8D,EAX (REX.B). REX.B selects R8 + // for 90 on both XCHG pages (SDM Vol.2D XCHG, 90+rd; APM Vol.3 XCHG: + // "Opcode 90h can still be used to exchange rAX and r8 if the + // appropriate REX prefix is used"), and PAUSE is F3 90 alone (SDM + // Vol.2B PAUSE). F3 on the XCHG is a repeat prefix on a non-string + // instruction, which the model ignores (scan_prefixes). + 144 => { + if pfx.rex_b == 0b1 then { + let os = opsize(pfx); + exec_xchg_reg_reg(RAX, R8, os) + } else { + if pfx.has_rep then vmx_exit_if_pause() + } + }, + + // 91-97: XCHG rAX, r + op if 145 <= op & op <= 151 => { + let reg_field : range(0, 7) = op - 144; + let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); + let os = opsize(pfx); + exec_xchg_reg_reg(RAX, reg, os) + }, + + // 98: CBW/CWDE/CDQE + 152 => { + let os = opsize(pfx); + v(RAX) = sign_extend(os, v(os / 2, RAX)) + }, + + // 99: CWD/CDQ/CQO + 153 => { + let os = opsize(pfx); + v(RDX) = sign_extend(os, v(os, RAX)[os - 1]) + }, + + // 9A: CALL ptr16:16/ptr16:32 — Far call, immediate + // Invalid in 64-bit mode. Encoding: offset (16/32 bits) then selector (16 bits). + 154 => { + if cur_mode == LongMode then raise_UD(); + let os = opsize(pfx); + assert(os <= 32); + let offset : qword = zero_extend(fetch(if os == 16 then 2 else 4)); + let selector : word = fetch(2); + match cur_mode { + RealMode => { + // Push old CS:IP/EIP + push(zero_extend(os, read_segreg(CS)) @ decode_pos[os - 1 .. 0]); + load_segment_register(CS, selector); + let target : qword = zero_extend(offset[os - 1 .. 0]); + next_rip = Some(target) + }, + _ => exec_far_call(selector, offset, os), + } + }, + + // 9B: FWAIT/WAIT: #NM if CR0.MP and CR0.TS are both set, whatever + // CR0.EM (SDM Vol.3A §2.5, Table 2-2) + 155 => { + if CR0[1] == 0b1 & CR0[3] == 0b1 then raise_NM(); + __wait(); + x87_undefine_cc(0x4700) + }, + + // 9C: PUSHF (default64) + // SDM: push(RFLAGS AND 00FCFFFFH) — RF (bit 16) and VM (bit 17) cleared. + 156 => { + let os = opsize_default64(pfx); + var flags = read_rflags() & 0x0000000000FCFFFF; + if cur_mode == Virtual8086Mode & IOPL != 0b11 then { + if CR4[0] == bitzero | os != 16 then raise_GP0(); + flags[9] = VIF; + flags[13..12] = 0b11 + }; + exec_push_imm(flags[(os - 1) .. 0]) + }, + + // 9D: POPF (default64) + // At CPL 0: all flags except RF, VIP, VIF, VM modifiable. + // RF is always cleared (cleared at start of every instruction). + // For 16-bit: only lower 16 bits affect flags (IOPL modifiable at CPL 0, + // but AC/ID are above bit 15 and are NOT modified). + 157 => { + let os = opsize_default64(pfx); + let virtualize = cur_mode == Virtual8086Mode & IOPL != 0b11; + if virtualize & (CR4[0] == bitzero | os != 16) then raise_GP0(); + var v : qword = zero_extend(pop(os)); + if virtualize then { + if v[8] == bitone | (VIP == bitone & v[9] == bitone) then raise_GP0(); + VIF = v[9] + }; + let cpl2 = to_bits(2, cur_cpl); + v[13..12] = blend(IOPL, v[13..12], is_eq(cpl2, 0b00)); + v[9] = blend(IF_flag, v[9], is_le_u(cpl2, v[13..12])); + match os { + 16 => { v[18] = AC_flag; v[21] = ID; write_rflags(v) }, + 32 => write_rflags(v), + 64 => { write_rflags(v); RF = 0b0 }, + } + }, + + // 9E: SAHF + 158 => { + let ah = GPR[RAX][15..8]; + CF = ah[0]; + PF = ah[2]; + AF = ah[4]; + ZF = ah[6]; + SF = ah[7] + }, + + // 9F: LAHF — AH := RFLAGS[7:0] = SF:ZF:0:AF:0:PF:1:CF + 159 => GPR[RAX][15..8] = SF @ ZF @ 0b0 @ AF @ 0b0 @ PF @ 0b1 @ CF, + + // A0: MOV AL, moffs8 + 160 => { + let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); + let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; + v(RAX) = read_mem(8, addr); + }, + + // A1: MOV rAX, moffs + 161 => { + let os = opsize(pfx); + let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); + let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; + v(RAX) = read_mem(os, addr) + }, + + // A2: MOV moffs8, AL + 162 => { + let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); + let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; + write_mem(addr, v(8, RAX)) + }, + + // A3: MOV moffs, rAX + 163 => { + let os = opsize(pfx); + let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); + let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; + write_mem(addr, v(os, RAX)) + }, + + // A4: MOVSB + 164 => { + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_movs, 8, asz, pfx) + else exec_movs(8, asz, pfx) + }, + + // A5: MOVSW/MOVSD/MOVSQ + 165 => { + let os = opsize(pfx); + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_movs, os, asz, pfx) + else exec_movs(os, asz, pfx) + }, + + // A6: CMPSB + 166 => { + let asz = get_address_size(pfx); + if pfx.has_rep then exec_rep(REP_repe, STR_cmps, 8, asz, pfx) + else if pfx.has_repne then exec_rep(REP_repne, STR_cmps, 8, asz, pfx) + else exec_cmps(8, asz, pfx) + }, + + // A7: CMPSW/CMPSD/CMPSQ + 167 => { + let os = opsize(pfx); + let asz = get_address_size(pfx); + if pfx.has_rep then exec_rep(REP_repe, STR_cmps, os, asz, pfx) + else if pfx.has_repne then exec_rep(REP_repne, STR_cmps, os, asz, pfx) + else exec_cmps(os, asz, pfx) + }, + + // A8: TEST AL, imm8 + 168 => { + let imm : qword = zero_extend(fetch(1)); + let a : qword = zero_extend(v(8, RAX)); + let result = a & imm; + update_flags_logic(result[7..0]) + }, + + // A9: TEST rAX, imm (Iz) + 169 => { + let os = opsize(pfx); + let imm = sign_extend(os, fetch(if os == 16 then 2 else 4)); + let a = v(os, RAX); + let result = a & imm; + update_flags_logic(result) + }, + + // AA: STOSB + 170 => { + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_stos, 8, asz, pfx) + else exec_stos(8, asz) + }, + + // AB: STOSW/STOSD/STOSQ + 171 => { + let os = opsize(pfx); + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_stos, os, asz, pfx) + else exec_stos(os, asz) + }, + + // AC: LODSB + 172 => { + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_lods, 8, asz, pfx) + else exec_lods(8, asz, pfx) + }, + + // AD: LODSW/LODSD/LODSQ + 173 => { + let os = opsize(pfx); + let asz = get_address_size(pfx); + if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_lods, os, asz, pfx) + else exec_lods(os, asz, pfx) + }, + + // AE: SCASB + 174 => { + let asz = get_address_size(pfx); + if pfx.has_rep then exec_rep(REP_repe, STR_scas, 8, asz, pfx) + else if pfx.has_repne then exec_rep(REP_repne, STR_scas, 8, asz, pfx) + else exec_scas(8, asz) + }, + + // AF: SCASW/SCASD/SCASQ + 175 => { + let os = opsize(pfx); + let asz = get_address_size(pfx); + if pfx.has_rep then exec_rep(REP_repe, STR_scas, os, asz, pfx) + else if pfx.has_repne then exec_rep(REP_repne, STR_scas, os, asz, pfx) + else exec_scas(os, asz) + }, + + // B0-B7: MOV r8, imm8 + op if 176 <= op & op <= 183 => { + // Without REX, registers 4-7 map to AH/CH/DH/BH (high byte). + let gpr_idx = unsigned(pfx.rex_b @ to_bits(3, op - 176)); + let reg : GPRRef = struct { gpr_idx = gpr_idx, has_rex = pfx.has_rex }; + v(reg) = fetch(1) + }, + + // B8-BF: MOV r, imm (Iv) + op if 184 <= op & op <= 191 => { + let reg = unsigned(pfx.rex_b @ to_bits(3, op - 184)); + let os = opsize(pfx); + v(reg) = fetch(os / 8) + }, + + // C0: Group 2 — shift r/m8 by imm8 + 192 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + let count = fetch(1); + exec_shift_rm(reg_field, dest, count, 8) + }, + + // C1: Group 2 — shift r/m by imm8 + 193 => { + let os = opsize(pfx); + let (reg_field, dest) = fetch_modrm_raw(pfx); + let count = fetch(1); + exec_shift_rm(reg_field, dest, count, os) + }, + + // C2: RET near imm16, at the operand size of a near branch + // (opsize_forced64). + 194 => { + let imm = fetch(2); + let os = opsize_forced64(pfx); + next_rip = Some(zero_extend(pop(os))); + v(64, RSP) = v(RSP) + zero_extend(imm) + }, + + // C3: RET near, at the operand size of a near branch + // (opsize_forced64). + 195 => next_rip = Some(zero_extend(pop(opsize_forced64(pfx)))), + + // C4: LES r, m16:16/32 (non-64-bit) or 3-byte VEX prefix + // SDM Vol.2A §2.3.5: In non-64-bit mode, if the second byte has + // bit 7 set (mod=11 in ModRM terms), it is a VEX prefix, not LES. + // This works because LES requires a memory operand (mod≠11), + // so mod=11 is an otherwise-invalid encoding reused for VEX. + 196 => { + if cur_mode == LongMode then { + if vex_after_legacy_prefix(pfx) then raise_UD(); + dispatch_vex(0xC4, pfx) + } else { + // Peek at second byte to distinguish VEX from LES. + // SDM Vol.2A §2.3.5: VEX requires mod=11 (bits 7:6 both set). + // mod≠11 (memory operand) is a valid LES encoding. + let byte2 = fetch(1); + if byte2[7..6] == 0b11 then { + // mod=11: VEX prefix in non-64-bit mode + if vex_after_legacy_prefix(pfx) then raise_UD(); + dispatch_vex_with_byte2(0xC4, byte2, pfx) + } else { + // mod≠11: LES r, m16:16/32 + let os = opsize(pfx); + let reg = modrm_reg(byte2, pfx); + let src = modrm_rm(byte2, pfx); + match src { + RM_mem(m) => { + let (far_offset, selector) = read_far_pointer(os, m); + load_data_segment_register(ES, selector); + // SDM LDS/LES/LFS/LGS/LSS: commit only the operand-sized + // offset after validating the selector (r16 preserves high bits). + v(reg) = far_offset[os - 1 .. 0] + }, + RM_reg(_) => raise_UD(), // unreachable: mod=11 handled above + } + } + } + }, + + // C5: LDS r, m16:16/32 (non-64-bit) or 2-byte VEX prefix + // Same VEX/LDS distinction as C4/LES above. + 197 => { + if cur_mode == LongMode then { + if vex_after_legacy_prefix(pfx) then raise_UD(); + dispatch_vex(0xC5, pfx) + } else { + let byte2 = fetch(1); + if byte2[7..6] == 0b11 then { + if vex_after_legacy_prefix(pfx) then raise_UD(); + dispatch_vex_with_byte2(0xC5, byte2, pfx) + } else { + let os = opsize(pfx); + let reg = modrm_reg(byte2, pfx); + let src = modrm_rm(byte2, pfx); + match src { + RM_mem(m) => { + let (far_offset, selector) = read_far_pointer(os, m); + load_data_segment_register(DS, selector); + v(reg) = far_offset[os - 1 .. 0] + }, + RM_reg(_) => raise_UD(), + } + } + } + }, + + // C6 /0: MOV r/m8, imm8 + 198 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + if reg_field != 0 then raise_UD(); + v(dest) = fetch(1) + }, + + // C7 /0: MOV r/m, imm (Iz) + 199 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + if reg_field != 0 then raise_UD(); + let os = opsize(pfx); + v(dest) = sign_extend(os, fetch(if os == 16 then 2 else 4)) + }, + + // C8: ENTER imm16, imm8 (SDM Vol.2A ENTER, Operation). The frame + // pointers of the outer levels are read through SS at rBP minus + // multiples of the operand size, rBP being as wide as the stack + // address size ("RBP := RBP - 2; Push([RBP])" for a 16-bit operand + // in 64-bit mode). RBP itself is written once, at the end, so that + // a fault leaves it unchanged (step() restores RSP). + 200 => { + let size = fetch(2); + let level = fetch(1); + let os = opsize_default64(pfx); + let 'sas = stack_addr_size(); + let nesting : range(0, 31) = unsigned(level) % 32; + push(v(os, RBP)); + let frame_temp = v(os, RSP); + if nesting > 1 then { + var fp : bits('sas) = v(sas, RBP); + foreach (i from 1 to (nesting - 1)) { + fp = fp - os / 8; + let m : MemRef = struct { seg = SS, addr = zero_extend(fp) }; + push(read_mem(os, m)) + } + }; + if nesting >= 1 then push(frame_temp); + // "The ENTER instruction causes a page fault whenever a write + // using the final value of the stack pointer (within the current + // stack segment) would do so" (SDM Vol.2A ENTER p.3-295), which + // gives neither the size of that write nor its place among the + // pushes. The APM's Operation gives both: after the pushes, + // "WRITE_MEM.v [SS:RSP.s] = temp_unused // ENTER finishes with a + // memory write check on the final stack pointer, but no write + // actually occurs" (Vol.3 ENTER p.183); the model follows it on + // both vendors. Neither manual says whether the pushes stay in + // memory when the check faults; in the model they do. + let final_sp : bits('sas) = v(sas, RSP) - zero_extend(size); + let m : MemRef = struct { seg = SS, addr = zero_extend(final_sp) }; + check_crossing_pages(seg_linear(m, os / 8), os / 8, PT_Write); + v(RBP) = frame_temp; + v(RSP) = final_sp + }, + + // C9: LEAVE — RSP := RBP, then POP RBP + // StackAddrSize determines which portion of RBP is used for the + // stack pointer assignment: 64-bit in long mode, 32/16 otherwise. + // OperandSize (16/32/64) controls the width of the POP. + 201 => { + let os = opsize_default64(pfx); + let sas = stack_addr_size(); + v(RSP) = v(sas, RBP); + v(RBP) = pop(os) + }, + + // CA: RETF imm16 — Far return with stack adjustment + // CB: RETF — Far return + // In 64-bit mode, default operand size for far RET is 32; REX.W makes it 64. + // Same-privilege: pop RIP, CS only. + // Outer-privilege (RPL of new CS > CPL): also pop RSP, SS. (SDM Vol.2 RET) + 202 => exec_retf(pfx, Some(fetch(2))), + 203 => exec_retf(pfx, None()), + + // CC: INT 3 — trap (saved RIP points past the INT3 byte) + // SDM: software interrupt, no error code pushed, gate DPL check applies. + // Without an IDT (user mode) the fault is reported with RIP already + // past the instruction, as the pushed return address would be. + 204 => { + if system_mode then { + sw_return_rip = Some(decode_pos); + deliver_exception(3, 0x00000000, EV_SoftwareInt); + next_rip = Some(RIP) // deliver_exception set RIP to handler + } else { + RIP = decode_pos; + sw_return_rip = Some(decode_pos); + __software_interrupt(0x03) + } + }, + + // CD: INT imm8 + // SDM: software interrupt, no error code pushed, gate DPL check applies. + 205 => { + let imm = fetch(1); + if redirect_vm86_interrupt(unsigned(imm), decode_pos) then return (); + if system_mode then { + sw_return_rip = Some(decode_pos); + deliver_exception(unsigned(imm), 0x00000000, EV_SoftwareInt); + next_rip = Some(RIP) // deliver_exception set RIP to handler + } else { + RIP = decode_pos; + sw_return_rip = Some(decode_pos); + __software_interrupt(imm) + } + }, + + // CE: INTO — Interrupt on Overflow (SDM Vol.2A INT n/INTO/INT3/INT1) + // #UD in 64-bit mode. If OF=1, generates #OF (vector 4). + 206 => { + if cur_mode == LongMode then raise_UD(); + if OF == 0b1 then { + if system_mode then { + sw_return_rip = Some(decode_pos); + deliver_exception(EXN_OF, 0x00000000, EV_SoftwareInt); + next_rip = Some(RIP) + } else { + RIP = decode_pos; + sw_return_rip = Some(decode_pos); + __software_interrupt(0x04) + } + } + }, + + // CF: IRET/IRETD/IRETQ — Interrupt Return + // Real mode: pop IP, CS, FLAGS (3 words, no SP/SS). + // Protected mode same-privilege: pop EIP, CS, EFLAGS (no ESP/SS). + // Protected mode outer-privilege: also pop ESP, SS. + // 64-bit mode: always pop RIP, CS, RFLAGS, RSP, SS (SDM Vol.2 IRET). + 207 => { + let os = opsize(pfx); + let iret_cpl = cur_cpl; + let protected_return = cur_mode != RealMode; + if cur_mode == Virtual8086Mode then { + assert(os == 16 | os == 32); + iret_in_vm86(os); + return () + }; + if NT == 0b1 & cur_mode != RealMode then raise_GP0(); + if os == 16 | os == 32 then { + // IRET/IRETD (16/32-bit operand size) + let new_ip = pop(os); + let new_cs = pop(os); + let new_flags = pop(os); + if os == 32 & cur_cpl == 0 & cur_mode != RealMode & zero_extend(64, new_flags)[17] == bitone then { + iret_to_vm86(zero_extend(new_ip), new_cs[15..0], zero_extend(new_flags)); + return () + }; + let return_rpl : cpl_t = unsigned(new_cs[1..0]); + + // Prepare an outer stack descriptor before changing CS: its + // accessed-bit write may #PF and must leave the old segments intact. + let outer_return = cur_mode != RealMode & return_rpl > cur_cpl; + var outer_sp : qword = 0x0000000000000000; + var outer_ss : word = 0x0000; + if outer_return then { + outer_sp = zero_extend(pop(os)); + let ss_image = pop(os); + outer_ss = ss_image[15..0]; + let _ = access_segment_descriptor(outer_ss, read_descriptor(outer_ss)) + }; + next_rip = Some(zero_extend(new_ip)); + load_segment_register(CS, new_cs[15..0]); + if outer_return then { + v(RSP) = outer_sp; + load_segment_register(SS, outer_ss) + }; + + // In real mode, CPL is always 0 (no privilege levels). + // In protected mode, set CPL from the return CS selector RPL. + if cur_mode != RealMode then cur_cpl = return_rpl; + // 16-bit IRET only modifies lower 16 flags bits; 32-bit replaces all, + // RF included (SDM IRET: "EFLAGS(RF, AC, ID) := tempEFLAGS"), which + // is how a debug handler resumes past an instruction breakpoint. + restore_iret_flags(os, zero_extend(new_flags), iret_cpl, protected_return) + } else { + let new_rip = pop(os); + let new_cs = pop(os); + let new_rflags = pop(os); + let new_rsp = pop(os); + let new_ss = pop(os); + next_rip = Some(new_rip); + + // Load CS selector and descriptor cache from GDT. + // Implicit supervisor access (SDM Vol.3A §4.6). + let sel_offset : qword = zero_extend(new_cs[15..3] @ 0b000); + let desc_lo : dword = read_mem_implicit(GDTR_base + sel_offset); + let desc_hi : dword = read_mem_implicit(GDTR_base + sel_offset + 4); + let code_desc = access_segment_descriptor(new_cs[15..0], parse_seg_descriptor(desc_lo, desc_hi)); + let ss_sel_offset : qword = zero_extend(new_ss[15..3] @ 0b000); + let ss_desc_lo : dword = read_mem_implicit(GDTR_base + ss_sel_offset); + let ss_desc_hi : dword = read_mem_implicit(GDTR_base + ss_sel_offset + 4); + let stack_desc = access_segment_descriptor(new_ss[15..0], parse_seg_descriptor(ss_desc_lo, ss_desc_hi)); + write_segreg(CS, new_cs[15..0]); + SegCache[CS] = code_desc; + set_mode(if SegCache[CS].seg_l == 0b1 then LongMode else CompatibilityMode); + + cur_cpl = unsigned(new_cs[1..0]); + restore_iret_flags(os, new_rflags, iret_cpl, protected_return); + v(RSP) = new_rsp; + // Load SS selector *and* descriptor cache from the GDT (SDM Vol.2 + // IRET: on return to outer privilege the hidden part of SS — + // including D/B for stack address size — must be reloaded, not + // just the visible selector). Without this, IRETQ from a 64-bit + // kernel to a 32-bit compat-mode process leaves SegCache[SS].seg_db + // at whatever stale value it held, so user-mode POP/PUSH read from + // (ESP & 0xFFFF) instead of ESP. + write_segreg(SS, new_ss[15..0]); + SegCache[SS] = stack_desc; + } + }, + + // D0: Group 2 — shift r/m8 by 1 + 208 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + exec_shift_rm(reg_field, dest, 0x01, 8) + }, + + // D1: Group 2 — shift r/m by 1 + 209 => { + let os = opsize(pfx); + let (reg_field, dest) = fetch_modrm_raw(pfx); + exec_shift_rm(reg_field, dest, 0x01, os) + }, + + // D2: Group 2 — shift r/m8 by CL + 210 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + let count : byte = v(RCX); + exec_shift_rm(reg_field, dest, count, 8) + }, + + // D3: Group 2 — shift r/m by CL + 211 => { + let os = opsize(pfx); + let (reg_field, dest) = fetch_modrm_raw(pfx); + let count : byte = v(RCX); + exec_shift_rm(reg_field, dest, count, os) + }, + + // D4: AAM — ASCII Adjust AX After Multiply (SDM Vol.2A) + // #UD in 64-bit mode. D4 ib: AH := AL / imm8; AL := AL MOD imm8. + // #DE if imm8 == 0. + 212 => { + if cur_mode == LongMode then raise_UD(); + let imm = fetch(1); + if imm == 0x00 then raise_DE(); + let temp_al : byte = v(RAX); + let divisor = unsigned(imm); + assert(divisor > 0); + v(RAX) = to_bits(8, unsigned(temp_al) / divisor) @ to_bits(8, unsigned(temp_al) % divisor); + update_SF_ZF_PF(v(8, RAX)); + OF = undefined; + AF = undefined; + CF = undefined + }, + + // D5: AAD — ASCII Adjust AX Before Division (SDM Vol.2A) + // #UD in 64-bit mode. D5 ib: AL := (AL + AH * imm8) AND FFH; AH := 0. + 213 => { + if cur_mode == LongMode then raise_UD(); + let imm = fetch(1); + let temp_al = v(8, RAX); + let temp_ah = v(16, RAX)[15..8]; + let result : byte = to_bits(8, (unsigned(temp_al) + unsigned(temp_ah) * unsigned(imm)) % 256); + v(RAX) = 0x00 @ result; + update_SF_ZF_PF(result); + OF = undefined; + AF = undefined; + CF = undefined + }, + + // D6: SALC — Set AL to Carry Flag (undocumented, invalid in 64-bit mode) + // AL := 0 - CF (0xFF if CF=1, 0x00 if CF=0). No flags affected. + 214 => { + if cur_mode == LongMode then raise_UD(); + v(RAX) = sign_extend(8, CF); + }, + + // D7: XLAT/XLATB + 215 => { + // SDM Vol.2D, XLAT: DS:(E)BX + unsigned AL, with segment + // override support. Truncate the effective offset to address size + // before adding the segment base (Vol.1, address calculations). + let asz = get_address_size(pfx); + let al : qword = zero_extend(v(8, RAX)); + let sum : qword = zero_extend(v(asz, RBX)) + al; + let seg : segreg_idx = match pfx.seg_override { + Some(s) => s, + None() => DS, + }; + let src : MemRef = struct { seg = seg, addr = zero_extend(sum[asz - 1 .. 0]) }; + v(RAX) = read_mem(8, src) + }, + + // D8-DF: x87 FPU + op if 216 <= op & op <= 223 => dispatch_x87(opcode, pfx), + + // E0: LOOPNE/LOOPNZ rel8 + 224 => { + let rel = fetch(1); + let asz = get_address_size(pfx); + exec_loop(rel, LOOP_ne, asz, opsize_forced64(pfx)) + }, + + // E1: LOOPE/LOOPZ rel8 + 225 => { + let rel = fetch(1); + let asz = get_address_size(pfx); + exec_loop(rel, LOOP_e, asz, opsize_forced64(pfx)) + }, + + // E2: LOOP rel8 + 226 => { + let rel = fetch(1); + let asz = get_address_size(pfx); + exec_loop(rel, LOOP_always, asz, opsize_forced64(pfx)) + }, + + // E3: JCXZ/JECXZ/JRCXZ rel8 + // Address size selects CX (16), ECX (32), or RCX (64). + 227 => { + let rel : qword = sign_extend(fetch(1)); + let count_reg = v(get_address_size(pfx), RCX); + if count_reg == zeros() then { + let os = opsize_forced64(pfx); + next_rip = Some(zero_extend((decode_pos + rel)[(os - 1) .. 0])) + } + }, + + // E4: IN AL, imm8 + 228 => { + let port : word = zero_extend(fetch(1)); + vmx_exit_if_io(port, 8, true); + exec_in(port, 8) + }, + + // E5: IN eAX, imm8 + 229 => { + let port : word = zero_extend(fetch(1)); + let os = opsize(pfx); + vmx_exit_if_io(port, os, true); + exec_in(port, os) + }, + + // E6: OUT imm8, AL + 230 => { + let port : word = zero_extend(fetch(1)); + vmx_exit_if_io(port, 8, false); + exec_out(port, 8) + }, + + // E7: OUT imm8, eAX + 231 => { + let port : word = zero_extend(fetch(1)); + let os = opsize(pfx); + vmx_exit_if_io(port, os, false); + exec_out(port, os) + }, + + // E8: CALL rel16/rel32 (forced64) + 232 => { + let rs = opsize_rel(pfx); + let offset : qword = sign_extend(fetch(rs / 8)); + let os = opsize_forced64(pfx); + let return_addr = decode_pos; + match os { + 16 => push(16, return_addr[15..0]), + 32 => if cur_mode == LongMode + then push(64, zero_extend(return_addr[31..0])) + else push(32, return_addr[31..0]), + 64 => push(64, return_addr), + }; + next_rip = Some(zero_extend((return_addr + offset)[(os - 1) .. 0])) + }, + + // E9: JMP rel16/rel32 (forced64) + 233 => { + let os = opsize_forced64(pfx); + let rs = opsize_rel(pfx); + let offset : qword = sign_extend(fetch(rs / 8)); + next_rip = Some(zero_extend((decode_pos + offset)[(os - 1) .. 0])) + }, + + // EA: JMP ptr16:16/ptr16:32 — Far jump, immediate + // Invalid in 64-bit mode. Encoding: offset (16/32 bits) then selector (16 bits). + 234 => { + if cur_mode == LongMode then raise_UD(); + let os = opsize(pfx); + let offset : qword = zero_extend(fetch(if os == 16 then 2 else 4)); + let selector : word = fetch(2); + match cur_mode { + RealMode => { + load_segment_register(CS, selector); + let target : qword = match os { + 16 => zero_extend(offset[15..0]), + _ => zero_extend(offset[31..0]), + }; + next_rip = Some(target) + }, + _ => exec_far_jmp(selector, offset, os), + } + }, + + // EB: JMP rel8 (forced64) + 235 => { + let os = opsize_forced64(pfx); + let rel : qword = sign_extend(fetch(1)); + next_rip = Some(zero_extend((decode_pos + rel)[(os - 1) .. 0])) + }, + + // EC: IN AL, DX + 236 => { + let port : word = v(RDX); + vmx_exit_if_io(port, 8, true); + exec_in(port, 8) + }, + + // ED: IN eAX, DX + 237 => { + let port : word = v(RDX); + let os = opsize(pfx); + vmx_exit_if_io(port, os, true); + exec_in(port, os) + }, + + // EE: OUT DX, AL + 238 => { + let port : word = v(RDX); + vmx_exit_if_io(port, 8, false); + exec_out(port, 8) + }, + + // EF: OUT DX, eAX + 239 => { + let port : word = v(RDX); + let os = opsize(pfx); + vmx_exit_if_io(port, os, false); + exec_out(port, os) + }, + + // F1: INT1 / ICEBP — #DB (vector 1) as a trap: the saved RIP points + // past the instruction, DR6 is not modified, no error code, and unlike + // INT n the gate's DPL is not checked (SDM Vol.2A INT n/INTO/INT3/INT1). + 241 => { + if system_mode then { + sw_return_rip = Some(decode_pos); + deliver_exception(EXN_DB, 0x00000000, EV_Exception); + next_rip = Some(RIP) + } else { + RIP = decode_pos; + sw_return_rip = Some(decode_pos); + __software_interrupt(0x01) + } + }, + + // F4: HLT — SDM: #GP(0) if CPL > 0 + 244 => { + if cur_cpl != 0 then raise_GP0(); + vmx_exit_if_hlt(); + // HLT completes before the halt state is entered: execution resumes + // at the following instruction (and SMM saves the post-HLT RIP, + // SDM Vol.3 §34.10). step() skips its RIP commit once + // system_state != SysRunning, so commit the new RIP here. + RIP = decode_pos; + system_state = SysHalted + }, + + // F5: CMC + 245 => CF = ~(CF), + + // F6: Group 3 — unary byte operations + 246 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + // LOCK valid only for NOT (/2) and NEG (/3) with memory destination + if pfx.has_lock & (reg_field != 2 & reg_field != 3) then raise_UD(); + check_lock_rm(pfx, dest, false); + dispatch_group3_byte(reg_field, dest) + }, + + // F7: Group 3 — unary word/dword/qword operations + 247 => { + let os = opsize(pfx); + let (reg_field, dest) = fetch_modrm_raw(pfx); + // LOCK valid only for NOT (/2) and NEG (/3) with memory destination + if pfx.has_lock & (reg_field != 2 & reg_field != 3) then raise_UD(); + check_lock_rm(pfx, dest, false); + dispatch_group3(reg_field, dest, os) + }, + + // F8: CLC + 248 => CF = 0b0, + + // F9: STC + 249 => CF = 0b1, + + // FA: CLI + 250 => exec_interrupt_flag(false), + + // FB: STI + // SDM Vol.2B STI: inhibit only when IF was clear (a second STI with + // IF already set does not extend the inhibition); exec_interrupt_flag + // sets the shadow and handles VIF under VME/PVI. + 251 => exec_interrupt_flag(true), + + // FC: CLD + 252 => DF = 0b0, + + // FD: STD + 253 => DF = 0b1, + + // FE: Group 4 — INC/DEC r/m8 + 254 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + // LOCK valid only for INC (/0) and DEC (/1) with memory + if pfx.has_lock & reg_field >= 2 then raise_UD(); + check_lock_rm(pfx, dest, false); + match reg_field { + 0 => v(dest) = exec_inc(read_rmw(8, dest)), + 1 => v(dest) = exec_dec(read_rmw(8, dest)), + _ => raise_UD(), + } + }, + + // FF: Group 5 — INC/DEC/CALL/JMP/PUSH r/m + 255 => { + let (reg_field, dest) = fetch_modrm_raw(pfx); + // LOCK valid only for INC (/0) and DEC (/1) with memory + if pfx.has_lock & reg_field >= 2 then raise_UD(); + check_lock_rm(pfx, dest, false); + dispatch_group5(reg_field, dest, pfx) + }, + + // Unhandled opcode + _ => raise_UD(), + } + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail new file mode 100644 index 000000000..a8e969924 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail @@ -0,0 +1,501 @@ +// x86-64 — Group Instruction Helpers (INC/DEC, shifts, MUL/DIV, etc.) +// +// Computes dest := dest + 1. Updates OF, SF, ZF, AF, PF. CF unchanged. + +val exec_inc : forall 'os, 'os in {8, 16, 32, 64}. (bits('os)) -> bits('os) +function exec_inc(a) = { + update_flags_add_no_cf(a + 1, a, zero_extend(0b1)); + a + 1 +} + +// DEC — Decrement by 1 +// +// Computes dest := dest - 1. Updates OF, SF, ZF, AF, PF. CF unchanged. +val exec_dec : forall 'os, 'os in {8, 16, 32, 64}. (bits('os)) -> bits('os) +function exec_dec(a) = { + update_flags_sub_no_cf(a - 1, a, zero_extend(0b1)); + a - 1 +} + +// MUL — Unsigned Multiply +// SDM: SF, ZF, AF, PF are undefined after MUL. +val exec_mul : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit +function exec_mul(os, src) = { + let product : int = unsigned(v(os, RAX)) * unsigned(src); + let result : bits('os * 2) = to_bits_truncate(product); + if os == 8 then { + v(RAX) = result; + } else { + v(RAX) = result[(os - 1)..0]; + v(RDX) = result[(os * 2 - 1)..os]; + }; + CF = is_nonzero(result[(os * 2 - 1)..os]); + OF = CF; + SF = undefined; + ZF = undefined; + AF = undefined; + PF = undefined +} + +// DIV — Unsigned Divide +// SDM: CF, OF, SF, ZF, AF, PF are undefined after DIV. +val exec_div : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit +function exec_div(os, src) = { + let divisor = unsigned(src); + if divisor == 0 then raise_DE(); + assert(divisor > 0); + let dividend = if os == 8 + then unsigned(v(16, RAX)) + else unsigned(v(os, RDX) @ v(os, RAX)); + let quotient = dividend / divisor; + let remainder = dividend - quotient * divisor; + if quotient >= pow2(os) then raise_DE(); + let q_bits = to_bits_truncate(os, quotient); + let r_bits = to_bits_truncate(os, remainder); + if os == 8 then { + v(RAX) = r_bits @ q_bits + } else { + v(RAX) = q_bits; + v(RDX) = r_bits + }; + CF = undefined; + OF = undefined; + SF = undefined; + ZF = undefined; + AF = undefined; + PF = undefined +} + +// IDIV — Signed Divide +// SDM: CF, OF, SF, ZF, AF, PF are undefined after IDIV. +val exec_idiv : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit +function exec_idiv(os, src) = { + let divisor = signed(src); + if divisor == 0 then raise_DE(); + assert(divisor != 0); + let dividend = if os == 8 + then signed(v(16, RAX)) + else signed(v(os, RDX) @ v(os, RAX)); + let quotient = quot_round_zero(dividend, divisor); + let remainder = rem_round_zero(dividend, divisor); + if quotient < -pow2(os - 1) | (pow2(os - 1) - 1) < quotient then raise_DE(); + let q_bits = to_bits_truncate(os, quotient); + let r_bits = to_bits_truncate(os, remainder); + if os == 8 then { + v(RAX) = r_bits @ q_bits + } else { + v(RAX) = q_bits; + v(RDX) = r_bits + }; + CF = undefined; + OF = undefined; + SF = undefined; + ZF = undefined; + AF = undefined; + PF = undefined +} + +// IMUL — Signed Multiply (one-operand form) +// SDM: SF, ZF, AF, PF are undefined after IMUL. +val exec_imul_1 : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit +function exec_imul_1(os, src) = { + let product : int = signed(v(os, RAX)) * signed(src); + let result : bits('os * 2) = to_bits_truncate(product); + if os == 8 then { + v(RAX) = result; + } else { + v(RAX) = result[(os - 1)..0]; + v(RDX) = result[(os * 2 - 1)..os]; + }; + CF = is_nonzero(result[(os * 2 - 1)..os] ^ sign_extend(result[os - 1])); + OF = CF; + SF = undefined; + ZF = undefined; + AF = undefined; + PF = undefined +} + +// PUSH imm +val exec_push_imm : forall 'os, 'os in {16, 32, 64}. (implicit('os), bits('os)) -> unit +function exec_push_imm(os, imm) = { + match os { + 16 => push(16, imm), + 32 => if cur_mode == LongMode then push(64, sign_extend(imm)) else push(32, imm), + 64 => push(64, imm), + } +} + +// ========================================================================= +// Group 3 (F6): Unary byte operations +// ========================================================================= + +val dispatch_group3_byte : (range(0, 7), RM) -> unit +function dispatch_group3_byte(reg_field, dest) = { + if reg_field == 0 | reg_field == 1 then { + // TEST r/m8, imm8 + // Fetch imm BEFORE reading dest so decode_pos is final for RIP-relative fixup + let imm : byte = fetch(1); + update_flags_logic(v(8, dest) & imm) + } else { + // NOT and NEG write their operand back; MUL and DIV only read it. + let x = if reg_field <= 3 then read_rmw(8, dest) else v(8, dest); + match reg_field { + // NOT r/m8 + 2 => v(dest) = x ^ 0xFF, + // NEG r/m8 + 3 => { + update_flags_sub(zeros() - x, zeros(), x); + v(dest) = zeros() - x + }, + 4 => exec_mul(x), + 5 => exec_imul_1(x), + 6 => exec_div(x), + 7 => exec_idiv(x), + } + } +} + +// ========================================================================= +// Group 3 (F7): Unary word/dword/qword operations +// ========================================================================= + +val dispatch_group3 : (range(0, 7), RM, {16, 32, 64}) -> unit +function dispatch_group3(reg_field, dest, os) = { + if reg_field == 0 | reg_field == 1 then { + // TEST r/m, imm (Iz) + // Fetch imm BEFORE reading dest so decode_pos is final for RIP-relative fixup + let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); + update_flags_logic(v(os, dest) & imm[(os - 1) .. 0]) + } else { + // NOT and NEG write their operand back; MUL and DIV only read it. + let x = if reg_field <= 3 then read_rmw(os, dest) else v(os, dest); + match reg_field { + // NOT r/m + 2 => v(dest) = ~(x), + // NEG r/m + 3 => { + update_flags_sub(zeros() - x, zeros(), x); + v(os, dest) = zeros() - x + }, + 4 => exec_mul(x), + 5 => exec_imul_1(x), + 6 => exec_div(x), + 7 => exec_idiv(x), + } + } +} + +// ========================================================================= +// Group 5 (FF): INC/DEC/CALL/JMP/PUSH +// ========================================================================= + +// The width of the offset in the far pointer of FF /3 and FF /5 at +// operand size os. With REX.W the manuals give the encoding different +// meanings, so the model follows the vendor register (regs.sail): "REX.W +// FF /3 CALL m16:64" and "REX.W FF /5 JMP m16:64" (SDM Vol.2A CALL, JMP), +// where "If the operand-size is 32 or 64 bits, the operand is a 32-bit +// offset followed by a 16-bit selector" (APM Vol.3 CALL (Far) p.139; JMP +// (Far) p.210, "a 16-bit selector followed by a 32-bit offset"). The +// operand size still sets the width of the pushes. +val far_pointer_offset_size : {16, 32, 64} -> {16, 32, 64} +function far_pointer_offset_size(os) = if os == 64 & vendor == Vendor_AMD then 32 else os + +val dispatch_group5 : (range(0, 7), RM, Prefixes) -> unit +function dispatch_group5(reg_field, dest, pfx) = { + match reg_field { + // INC r/m + 0 => { + let os = opsize(pfx); + v(dest) = exec_inc(read_rmw(os, dest)) + }, + + // DEC r/m + 1 => { + let os = opsize(pfx); + v(dest) = exec_dec(read_rmw(os, dest)) + }, + + // CALL near indirect, at the operand size of a near branch + // (opsize_forced64). + 2 => { + let os = opsize_forced64(pfx); + let target : qword = zero_extend(v(os, dest)); + let return_addr : qword = decode_pos; + push(return_addr[os - 1 .. 0]); + next_rip = Some(target) + }, + + // CALL far indirect m16:16/m16:32/m16:64 + // Memory operand contains offset (16/32/64 bits) then selector (16 bits). + // Register form is #UD. + 3 => { + match dest { + RM_reg(_) => raise_UD(), + RM_mem(m) => { + let os = opsize(pfx); + let (far_offset, far_selector) = read_far_pointer(far_pointer_offset_size(os), m); + exec_far_call(far_selector, far_offset, os) + }, + } + }, + + // JMP near indirect, at the operand size of a near branch + // (opsize_forced64). + 4 => next_rip = Some(zero_extend(v(opsize_forced64(pfx), dest))), + + // JMP far indirect m16:16/m16:32/m16:64 + // Memory operand contains offset (16/32/64 bits) then selector (16 bits). + // Register form is #UD. + 5 => { + match dest { + RM_reg(_) => raise_UD(), + RM_mem(m) => { + let os = opsize(pfx); + let (far_offset, far_selector) = read_far_pointer(far_pointer_offset_size(os), m); + exec_far_jmp(far_selector, far_offset, os) + }, + } + }, + + // PUSH r/m (d64) + 6 => { + let os = opsize_default64(pfx); + exec_push_imm(v(os, dest)) + }, + + // 7: reserved + 7 => raise_UD(), + } +} + +// SHL/SAL — Shift Left +// +// Shifts dest left by count bits. CF = last bit shifted out. +// If count=0, flags unchanged. If count=1, OF = MSB(result) XOR CF. +// SF, ZF, PF set from result. AF undefined for count != 0. +val exec_shl : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) +function exec_shl(a, count_raw) = { + let count : range(0, 63) = match 'os { + 64 => unsigned(count_raw) % 64, + _ => unsigned(count_raw) % 32, + }; + let count_bv : bits(6) = to_bits(6, count); + let old_CF = CF; let old_OF = OF; let old_SF = SF; + let old_ZF = ZF; let old_PF = PF; let old_AF = AF; + let result : bits('os) = a << count; + let cf_count : range(0, 64) = count + unsigned(is_zero(count_bv)); + let cf_idx : range(0, 63) = ('os + 64 - cf_count) % 64; + let a_ext : bits(64) = zero_extend(a); + + CF = a_ext[cf_idx]; + update_SF_ZF_PF(result); + OF = result['os - 1] ^ CF; + AF = undefined; + // OF defined only for count==1; undefined otherwise + OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); + // CF undefined when count >= operand size (possible for 8/16-bit) + CF = blend(CF, undefined, is_ge_u(to_bits(7, count), to_bits(7, 'os))); + + // When count==0: restore all flags and return original value + let count_nz : bit = is_nonzero(count_bv); + CF = blend(old_CF, CF, count_nz); + OF = blend(old_OF, OF, count_nz); + SF = blend(old_SF, SF, count_nz); + ZF = blend(old_ZF, ZF, count_nz); + PF = blend(old_PF, PF, count_nz); + AF = blend(old_AF, AF, count_nz); + blend(a, result, count_nz) +} + +// SHR — Shift Right (Logical) +// +// Shifts dest right by count bits, filling with zeros. +// CF = last bit shifted out. If count=1, OF = MSB(original). +// SF, ZF, PF set from result. AF undefined for count != 0. +val exec_shr : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) +function exec_shr(a, count_raw) = { + let mod_val : range(32, 64) = if 'os == 64 then 64 else 32; + let count : range(0, 63) = unsigned(count_raw) % mod_val; + let count_bv : bits(6) = to_bits(6, count); + let old_CF = CF; let old_OF = OF; let old_SF = SF; + let old_ZF = ZF; let old_PF = PF; let old_AF = AF; + let result : bits('os) = a >> count; + let cf_count : range(0, 64) = count + unsigned(is_zero(count_bv)); + assert(cf_count >= 1); + let a_ext : bits(64) = zero_extend(a); + + CF = a_ext[cf_count - 1]; + update_SF_ZF_PF(result); + OF = a['os - 1]; + AF = undefined; + // OF defined only for count==1; undefined otherwise + OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); + // CF undefined when count >= operand size (possible for 8/16-bit) + CF = blend(CF, undefined, is_ge_u(to_bits(7, count), to_bits(7, 'os))); + + let count_nz : bit = is_nonzero(count_bv); + CF = blend(old_CF, CF, count_nz); + OF = blend(old_OF, OF, count_nz); + SF = blend(old_SF, SF, count_nz); + ZF = blend(old_ZF, ZF, count_nz); + PF = blend(old_PF, PF, count_nz); + AF = blend(old_AF, AF, count_nz); + blend(a, result, count_nz) +} + +// SAR — Shift Right (Arithmetic) +// +// Shifts dest right by count bits, preserving sign bit. +// CF = last bit shifted out. OF cleared for count=1. +// SF, ZF, PF set from result. AF undefined for count != 0. +val exec_sar : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) +function exec_sar(a, count_raw) = { + let mod_val : range(32, 64) = if 'os == 64 then 64 else 32; + let count : range(0, 63) = unsigned(count_raw) % mod_val; + let count_bv : bits(6) = to_bits(6, count); + let old_CF = CF; let old_OF = OF; let old_SF = SF; + let old_ZF = ZF; let old_PF = PF; let old_AF = AF; + let cf_count : range(0, 64) = count + unsigned(is_zero(count_bv)); + assert(cf_count >= 1); + let cf_idx_bv : bits(7) = min_u(to_bits(7, cf_count - 1), to_bits(7, 'os - 1)); + let cf_idx = unsigned(cf_idx_bv); + assert(cf_idx < 'os); + + CF = a[cf_idx]; + let result : bits('os) = a >>> count; + update_SF_ZF_PF(result); + OF = 0b0; + AF = undefined; + // OF defined only for count==1; undefined otherwise + OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); + + let count_nz : bit = is_nonzero(count_bv); + CF = blend(old_CF, CF, count_nz); + OF = blend(old_OF, OF, count_nz); + SF = blend(old_SF, SF, count_nz); + ZF = blend(old_ZF, ZF, count_nz); + PF = blend(old_PF, PF, count_nz); + AF = blend(old_AF, AF, count_nz); + blend(a, result, count_nz) +} + +// ROL — Rotate Left +// ROR — Rotate Right +// +// ROL: Rotates bits left. CF = LSB(result) after rotate. +// ROR: Rotates bits right. CF = MSB(result) after rotate. +// OF defined only for count=1. SF, ZF, AF, PF unaffected. +// Count is masked to 5 bits (6 bits for 64-bit operands). +val exec_rol : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) +function exec_rol(a, count_raw) = { + let count : range(0, 63) = match 'os { + 64 => unsigned(count_raw) % 64, + _ => unsigned(count_raw) % 32, + }; + let old_CF = CF; let old_OF = OF; + let result : bits('os) = rotl(a, count % 'os); + + CF = result[0]; + OF = result['os - 1] ^ CF; + // OF defined only for count==1; undefined otherwise + OF = blend(undefined, OF, is_eq(to_bits(6, count), 0b000001)); + + let count_nz : bit = is_nonzero(to_bits(6, count)); + CF = blend(old_CF, CF, count_nz); + OF = blend(old_OF, OF, count_nz); + blend(a, result, count_nz) +} + +val exec_ror : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) +function exec_ror(a, count_raw) = { + let count : range(0, 63) = match 'os { + 64 => unsigned(count_raw) % 64, + _ => unsigned(count_raw) % 32, + }; + let old_CF = CF; let old_OF = OF; + let result : bits('os) = rotr(a, count % 'os); + + CF = result['os - 1]; + OF = result['os - 1] ^ result['os - 2]; + // OF defined only for count==1; undefined otherwise + OF = blend(undefined, OF, is_eq(to_bits(6, count), 0b000001)); + + let count_nz : bit = is_nonzero(to_bits(6, count)); + CF = blend(old_CF, CF, count_nz); + OF = blend(old_OF, OF, count_nz); + blend(a, result, count_nz) +} + +// RCL — Rotate Through Carry Left +// RCR — Rotate Through Carry Right +// +// RCL: Rotates (n+1)-bit value (CF:dest) left by count. +// RCR: Rotates (n+1)-bit value (CF:dest) right by count. +// OF defined only for count=1. Count masked to 5 bits (6 for 64-bit). +val exec_rcl : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) +function exec_rcl(a, count_raw) = { + let masked : range(0, 63) = match 'os { + 64 => unsigned(count_raw) % 64, + _ => unsigned(count_raw) % 32, + }; + let c = masked % ('os + 1); + let old_CF = CF; let old_OF = OF; + let wide = a @ CF; + let rotated = rotl(wide, c); + + CF = rotated[0]; + OF = rotated['os] ^ rotated[0]; + // OF defined only for masked==1; undefined otherwise + OF = blend(undefined, OF, is_eq(to_bits(6, masked), 0b000001)); + + let c_nz : bit = is_nonzero(to_bits(6, c)); + CF = blend(old_CF, CF, c_nz); + OF = blend(old_OF, OF, c_nz); + blend(a, rotated['os..1], c_nz) +} + +val exec_rcr : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) +function exec_rcr(a, count_raw) = { + let masked : range(0, 63) = match 'os { + 64 => unsigned(count_raw) % 64, + _ => unsigned(count_raw) % 32, + }; + let c = masked % ('os + 1); + let old_CF = CF; let old_OF = OF; + + // OF is set from original value before rotation for RCR + OF = a['os - 1] ^ CF; + // OF defined only for masked==1; undefined otherwise + OF = blend(undefined, OF, is_eq(to_bits(6, masked), 0b000001)); + let wide = a @ CF; + let rotated = rotr(wide, c); + CF = rotated[0]; + + let c_nz : bit = is_nonzero(to_bits(6, c)); + CF = blend(old_CF, CF, c_nz); + OF = blend(old_OF, OF, c_nz); + blend(a, rotated['os..1], c_nz) +} + +// ========================================================================= +// Generic shift/rotate handler for Group 2 +// +// For register operands, delegates to existing exec_ functions. +// For memory operands, reads/shifts/writes back inline. +// ========================================================================= +val exec_shift_rm : forall 'os, 'os in {8, 16, 32, 64}. (range(0, 7), RM, byte, int('os)) -> unit +function exec_shift_rm(shift_op, dest, count_raw, os) = { + // exec_* functions handle count==0 via blend (return original, flags preserved). + let src_val = read_rmw(os, dest); + let new_val : bits('os) = match shift_op { + 0 => exec_rol(src_val, count_raw), + 1 => exec_ror(src_val, count_raw), + 2 => exec_rcl(src_val, count_raw), + 3 => exec_rcr(src_val, count_raw), + 4 => exec_shl(src_val, count_raw), + 5 => exec_shr(src_val, count_raw), + 6 => exec_shl(src_val, count_raw), // SAL = SHL + 7 => exec_sar(src_val, count_raw), + }; + v(os, dest) = new_val +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail new file mode 100644 index 000000000..794de75ef --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail @@ -0,0 +1,496 @@ +// x86-64 — ModR/M and SIB Decoding +// +// Decodes the ModR/M byte, optional SIB byte, and displacement to +// produce either a register operand or an effective memory address. +// +// In 64-bit mode: +// - mod=00, r/m=101 => [RIP + disp32] +// - r/m=100 (with mod!=11) => SIB byte follows +// - SIB base=101 with mod=00 => disp32 only (no base register) + +// Decode SIB byte and compute effective address. +// Returns the memory address. +val decode_sib : (byte, range(0, 2), Prefixes) -> qword +function decode_sib(sib, modbits, pfx) = { + let scale : range(0, 3) = unsigned(sib[7..6]); + + // Base and index registers (extended by REX.B / REX.X) + let base_idx : gpr_idx = unsigned(pfx.rex_b @ sib[2..0]); + let index_idx : gpr_idx = unsigned(pfx.rex_x @ sib[5..3]); + + // Compute base component + let base_val : qword = + if sib[2..0] == 0b101 & modbits == 0 then { + // mod=00, base=101: no base register, disp32 follows + sign_extend(fetch(4)) + } else if sib[2..0] == 0b101 & modbits == 1 then { + // mod=01, base=101: [RBP/R13] + disp8 + v(64, base_idx) + sign_extend(fetch(1)) + } else if sib[2..0] == 0b101 & modbits == 2 then { + // mod=10, base=101: [RBP/R13] + disp32 + v(64, base_idx) + sign_extend(fetch(4)) + } else { + // Normal base register with displacement handled by caller + if modbits == 0 then + v(64, base_idx) + else if modbits == 1 then { + v(64, base_idx) + sign_extend(fetch(1)) + } else { + v(64, base_idx) + sign_extend(fetch(4)) + } + }; + + // Compute index component: index=100 (RSP without REX.X) means no index + let index_val : qword = + if sib[5..3] == 0b100 & pfx.rex_x == 0b0 then { + 0x0000000000000000 + } else { + let idx_reg = v(64, index_idx); + match scale { + 0 => idx_reg, + 1 => idx_reg << 1, + 2 => idx_reg << 2, + 3 => idx_reg << 3, + } + }; + + base_val + index_val +} + +// Apply segment base to a memory address (SDM Vol.3A §3.4). +// Linear address = segment base + effective address. +// If there's an explicit segment override prefix, use that segment; +// otherwise use the default segment (DS for most, SS for BP/SP-based). +// Resolve the effective segment for a memory operand, considering +// any explicit segment override prefix and the default segment. +val resolve_seg : (Prefixes, segreg_idx) -> segreg_idx +function resolve_seg(pfx, default_seg) = match pfx.seg_override { + Some(s) => s, + None() => default_seg, +} + +// The default segment of a 32- or 64-bit memory operand with the base +// register field base (ModR/M.rm, or SIB.base after rm = 100b): SS for an +// rSP or rBP base, DS otherwise ("When the ESP or EBP register is used as +// the base, the SS segment is the default segment. In all other cases, +// the DS segment is the default segment", SDM Vol.1 §3.7.5 p.3-23; in +// 64-bit mode "instructions using RSP/RBP as base registers", §3.3.7.1 +// p.3-10). R12 and R13, whose encodings are rSP's and rBP's with REX.B +// (VEX.B̄, EVEX.B̄ clear), are other registers: DS, so a non-canonical +// [r13+0] is #GP(0), not #SS(0). SIB.base = 101b with mod = 00b names no +// base. +val base_default_seg : (bits(3), range(0, 3), Prefixes) -> segreg_idx +function base_default_seg(base, modbits, pfx) = + if pfx.rex_b == 0b0 & (base == 0b100 | base == 0b101 & modbits != 0) then SS else DS + +// Byte i of the destination of MASKMOVQ, MASKMOVDQU and VMASKMOVDQU: "the +// effective address in the DI/EDI/RDI register (the default segment +// register is DS, but this may be overridden with a segment-override +// prefix) ... (The size of the store address depends on the address-size +// attribute.)" (SDM Vol.2B MASKMOVDQU, MASKMOVQ). +val maskmov_dest : (Prefixes, range(0, 15)) -> MemRef +function maskmov_dest(pfx, i) = { + let ea : qword = v(64, RDI) + to_bits(64, i); + let addr : qword = match get_address_size(pfx) { + 16 => zero_extend(ea[15..0]), + 32 => zero_extend(ea[31..0]), + 64 => ea, + }; + struct { seg = resolve_seg(pfx, DS), addr = addr } +} + +// Compute EVEX compressed displacement scale factor for "Full" tuple type. +// Without broadcast: N = vector size in bytes. With broadcast: N = element size. +val evex_full_disp_n : Prefixes -> range(4, 64) +function evex_full_disp_n(pfx) = + if pfx.evex_b then + (if pfx.vex_w then 8 else 4) + else match pfx.evex_ll { + 0 => 16, + 1 => 32, + 2 => 64, + 3 => raise_UD(), + } + +// The scale for the "Half" tuple type (SDM Vol.2 §2.7.5, Table 2-34): the +// memory operand is half a vector, VL/16 bytes, or with EVEX.b one 32-bit +// element. Half is the type of the widening conversions from 32-bit +// elements (VCVTDQ2PD, VCVTUDQ2PD, VCVTPS2PD, VCVT[T]PS2[U]QQ), all W0. +val evex_half_disp_n : Prefixes -> range(4, 32) +function evex_half_disp_n(pfx) = + if pfx.evex_b then 4 + else match pfx.evex_ll { + 0 => 8, + 1 => 16, + 2 => 32, + 3 => raise_UD(), + } + +// The same for opcodes whose F3/F2 forms are scalar (SS/SD: Tuple1 Scalar, +// N = element size) and whose NP/66 forms are Full (PS/PD): 0F 10/11/51/ +// 58-5F/C2. +val evex_fp_disp_n : (MandatoryPrefix, Prefixes) -> range(4, 64) +function evex_fp_disp_n(mp, pfx) = match mp { + MP_F3 => 4, + MP_F2 => 8, + _ => evex_full_disp_n(pfx), +} + +// Decode SIB with EVEX compressed disp8. +val decode_sib_evex : (byte, range(0, 2), Prefixes, range(1, 64)) -> qword +function decode_sib_evex(sib, modbits, pfx, disp_n) = { + let scale : range(0, 3) = unsigned(sib[7..6]); + + let base_idx : gpr_idx = unsigned(pfx.rex_b @ sib[2..0]); + let index_idx : gpr_idx = unsigned(pfx.rex_x @ sib[5..3]); + + let base_val : qword = + if sib[2..0] == 0b101 & modbits == 0 then { + sign_extend(fetch(4)) + } else if sib[2..0] == 0b101 & modbits == 1 then { + let d8 : byte = fetch(1); + let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); + v(64, base_idx) + scaled_disp + } else if sib[2..0] == 0b101 & modbits == 2 then { + v(64, base_idx) + sign_extend(fetch(4)) + } else { + if modbits == 0 then + v(64, base_idx) + else if modbits == 1 then { + let d8 : byte = fetch(1); + let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); + v(64, base_idx) + scaled_disp + } else { + v(64, base_idx) + sign_extend(fetch(4)) + } + }; + + let index_val : qword = + if sib[5..3] == 0b100 & pfx.rex_x == 0b0 then { + 0x0000000000000000 + } else { + let idx_reg = v(64, index_idx); + match scale { + 0 => idx_reg, + 1 => idx_reg << 1, + 2 => idx_reg << 2, + 3 => idx_reg << 3, + } + }; + + base_val + index_val +} + +// The segment and address size of a VSIB memory operand, as for any other +// memory operand (modrm_rm): the segment of the base register +// (base_default_seg) unless a prefix overrides it, and 32-bit addresses +// with 67h in 64-bit mode. "VSIB memory addressing requires 32-bit or +// 64-bit effective address. In 32-bit mode, VSIB addressing is not +// supported when address size attribute is overridden to 16 bits", which +// is #UD (Vol.2A §2.3.12). Returns the segment and whether the addresses +// are 64 bits. +val vsib_seg_asize : (byte, range(0, 3), Prefixes) -> (segreg_idx, bool) +function vsib_seg_asize(sib, modbits, pfx) = { + let asz = get_address_size(pfx); + if asz == 16 then raise_UD(); + (resolve_seg(pfx, base_default_seg(sib[2..0], modbits, pfx)), asz == 64) +} + +// Decode VSIB for gather/scatter instructions. +// Returns base address (GPR + displacement), vector index register, scale, +// segment and address size. +// The SIB byte's index field references a vector register (extended by EVEX.V'/X). +val decode_vsib_evex : (byte, Prefixes, range(1, 64)) -> VSIB +function decode_vsib_evex(modrm, pfx, disp_n) = { + let modbits : range(0, 3) = unsigned(modrm[7..6]); + // VSIB always has rm=100 (SIB present), mod != 11 (evex_check_form). + let sib : byte = fetch(1); + let scale : range(0, 3) = unsigned(sib[7..6]); + let (seg, addr64) = vsib_seg_asize(sib, modbits, pfx); + + // Base register uses EVEX.B extension (same as normal SIB) + let base_idx : gpr_idx = unsigned(pfx.rex_b @ sib[2..0]); + + // Index is a vector register: VIDX = {EVEX.V', EVEX.X, sib.index} (SDM + // Vol.2A Table 1-33). V' is folded into bit 4 of evex_vvvvv; R' extends + // modrm.reg, not the index. + let v_prime : bits(1) = if pfx.evex_vvvvv >= 16 then 0b1 else 0b0; + let vidx : simd_idx = unsigned(v_prime @ pfx.rex_x @ sib[5..3]); + + let base_val : qword = + if sib[2..0] == 0b101 & modbits == 0 then { + sign_extend(fetch(4)) + } else if modbits == 0 then { + v(64, base_idx) + } else if modbits == 1 then { + let d8 : byte = fetch(1); + let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); + v(64, base_idx) + scaled_disp + } else { + v(64, base_idx) + sign_extend(fetch(4)) + }; + + struct { vsib_base = base_val, vsib_vidx = vidx, vsib_scale = scale, + vsib_seg = seg, vsib_addr64 = addr64 } +} + +// Decode ModR/M with EVEX compressed disp8. disp_n is the scale factor. +val modrm_rm_evex : (byte, Prefixes, range(1, 64)) -> RM +function modrm_rm_evex(modrm, pfx, disp_n) = { + let modbits : range(0, 3) = unsigned(modrm[7..6]); + let rm_raw : bits(3) = modrm[2..0]; + + if modbits == 3 then { + RM_reg(struct { gpr_idx = unsigned(pfx.rex_b @ rm_raw), has_rex = pfx.has_rex }) + } else if modbits == 0 & rm_raw == 0b101 then { + let disp : qword = sign_extend(fetch(4)); + if cur_mode == LongMode then { + // RIP-relative: [RIP + disp32] (no compression for disp32) + rip_rel_pending = true; + rip_rel_disp = disp; + let ea : qword = decode_pos + disp; + let ad_keep : qword = sign_extend(~(pfx.has_adsize)); + let ea : qword = ea & (ad_keep | 0x00000000FFFFFFFF); + RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) + } else { + // Compat/protected mode: [disp32] absolute + let ea : qword = disp & 0x00000000FFFFFFFF; + RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) + } + } else { + let asz = get_address_size(pfx); + var default_seg : segreg_idx = base_default_seg(rm_raw, modbits, pfx); + let addr : qword = + if rm_raw == 0b100 then { + let sib : byte = fetch(1); + default_seg = base_default_seg(sib[2..0], modbits, pfx); + decode_sib_evex(sib, modbits, pfx, disp_n) + } else if modbits == 0 then { + v(64, unsigned(pfx.rex_b @ rm_raw)) + } else { + if modbits == 1 then { + // disp8 * N + let d8 : byte = fetch(1); + let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); + v(64, unsigned(pfx.rex_b @ rm_raw)) + scaled_disp + } else { + // disp32 (no compression) + v(64, unsigned(pfx.rex_b @ rm_raw)) + sign_extend(fetch(4)) + } + }; + let addr : qword = match asz { + 16 => addr & 0x000000000000FFFF, + 32 => addr & 0x00000000FFFFFFFF, + 64 => addr, + }; + RM_mem(struct { seg = resolve_seg(pfx, default_seg), addr = addr }) + } +} + +// Decode ModR/M with 16-bit addressing (SDM Vol.2 Table 2-1). +// No SIB byte, no REX extension. Register pairs for effective address: +// rm=0: [BX+SI], 1: [BX+DI], 2: [BP+SI], 3: [BP+DI], +// 4: [SI], 5: [DI], 6: [disp16] (mod=00) or [BP], 7: [BX] +// Default segment: BP-based → SS, others → DS. +val modrm_rm_16 : (byte, Prefixes) -> RM +function modrm_rm_16(modrm, pfx) = { + let modbits : range(0, 3) = unsigned(modrm[7..6]); + let rm_raw : range(0, 7) = unsigned(modrm[2..0]); + + if modbits == 3 then { + RM_reg(struct { gpr_idx = unsigned(modrm[2..0]), has_rex = false }) + } else { + // Compute base address from register pair + let base : word = match rm_raw { + 0 => v(16, RBX) + v(16, RSI), + 1 => v(16, RBX) + v(16, RDI), + 2 => v(16, RBP) + v(16, RSI), + 3 => v(16, RBP) + v(16, RDI), + 4 => v(16, RSI), + 5 => v(16, RDI), + 6 => if modbits == 0 then 0x0000 else v(16, RBP), + 7 => v(16, RBX), + }; + // Add displacement + let ea : word = if modbits == 0 & rm_raw == 6 then { + // mod=00, rm=110: [disp16] absolute + fetch(2) + } else if modbits == 0 then { + base + } else if modbits == 1 then { + // + sign-extended disp8 + base + sign_extend(fetch(1)) + } else { + // modbits == 2: + disp16 + base + fetch(2) + }; + // Default segment: BP-based → SS, others → DS + let default_seg : segreg_idx = + if rm_raw == 2 | rm_raw == 3 then SS // [BP+SI], [BP+DI] + else if rm_raw == 6 & modbits != 0 then SS // [BP]+disp + else DS; + RM_mem(struct { seg = resolve_seg(pfx, default_seg), addr = zero_extend(ea) }) + } +} + +// Decode ModR/M byte and return the r/m operand (register or memory address). +// The reg field is decoded separately by the caller via modrm_reg(). +// The modrm byte has already been fetched by the caller. +val modrm_rm : (byte, Prefixes) -> RM +function modrm_rm(modrm, pfx) = { + // 16-bit addressing uses a completely different table (SDM Table 2-1) + if get_address_size(pfx) == 16 then { + return modrm_rm_16(modrm, pfx) + }; + + let modbits : range(0, 3) = unsigned(modrm[7..6]); + let rm_raw : bits(3) = modrm[2..0]; + + if modbits == 3 then { + // Register direct — no segment override + RM_reg(struct { gpr_idx = unsigned(pfx.rex_b @ rm_raw), has_rex = pfx.has_rex }) + } else if modbits == 0 & rm_raw == 0b101 then { + let disp : qword = sign_extend(fetch(4)); + if cur_mode == LongMode then { + // RIP-relative: [RIP + disp32] + // With 67h prefix, uses EIP + disp32 (truncated to 32 bits). + // If the instruction has trailing bytes (imm8/imm32), + // fixup_addr() will adjust by the delta at use time. + rip_rel_pending = true; + rip_rel_disp = disp; + let ea : qword = decode_pos + disp; + let ad_keep : qword = sign_extend(~(pfx.has_adsize)); + let ea : qword = ea & (ad_keep | 0x00000000FFFFFFFF); + RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) + } else { + // Compat/protected mode: [disp32] absolute (no RIP-relative) + let ea : qword = disp & 0x00000000FFFFFFFF; + RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) + } + } else { + // Memory operand — compute address then apply segment + let asz = get_address_size(pfx); + // Default segment: BP/SP-based → SS, otherwise → DS (base_default_seg) + var default_seg : segreg_idx = base_default_seg(rm_raw, modbits, pfx); + let addr : qword = + if rm_raw == 0b100 then { + // SIB byte follows + let sib : byte = fetch(1); + default_seg = base_default_seg(sib[2..0], modbits, pfx); + decode_sib(sib, modbits, pfx) + } else if modbits == 0 then { + // [reg] no displacement + v(64, unsigned(pfx.rex_b @ rm_raw)) + } else { + if modbits == 1 then { + // [reg] + disp8 + v(64, unsigned(pfx.rex_b @ rm_raw)) + sign_extend(fetch(1)) + } else { + // modbits == 2: [reg] + disp32 + v(64, unsigned(pfx.rex_b @ rm_raw)) + sign_extend(fetch(4)) + } + }; + // Truncate address based on address size + let addr : qword = match asz { + 16 => addr & 0x000000000000FFFF, + 32 => addr & 0x00000000FFFFFFFF, + 64 => addr, + }; + RM_mem(struct { seg = resolve_seg(pfx, default_seg), addr = addr }) + } +} + +// Decode ModR/M r/m as a SIMD register-or-memory operand. +val modrm_xrm : (byte, Prefixes) -> XRM +function modrm_xrm(modrm, pfx) = match modrm_rm(modrm, pfx) { + RM_reg(_) => XRM_reg(unsigned(pfx.rex_b @ modrm[2..0])), + RM_mem(m) => XRM_mem(m), +} + +// Fetch and decode ModR/M byte, returning GPRRef reg and RM operand. +val fetch_modrm : Prefixes -> (GPRRef, RM) +function fetch_modrm(pfx) = { + let modrm : byte = fetch(1); + (modrm_reg(modrm, pfx), modrm_rm(modrm, pfx)) +} + +// Fetch and decode ModR/M byte, returning raw reg field and RM operand. +// Use for group opcodes and segment register instructions. +val fetch_modrm_raw : Prefixes -> (range(0, 7), RM) +function fetch_modrm_raw(pfx) = { + let modrm : byte = fetch(1); + let reg_field : range(0, 7) = unsigned(modrm[5..3]); + (reg_field, modrm_rm(modrm, pfx)) +} + +// The 16-byte alignment of the m128 source of a legacy SSE load/execute +// instruction: #GP(0) if misaligned, unless MXCSR.MM (bit 17) is 1. "AMD +// processors that support Misaligned SSE Mode may be programmed to disable +// this exception behavior for legacy load/execute SSE instructions"; "If +// MXCSR.MM is set, the #GP is inhibited and the exception behavior depends +// on the alignment checking mechanism" (APM Vol.1 §4.3.2 p.120-121), whose +// #AC the model implements for no instruction. MM can be 1 only on a +// machine whose MXCSR_MASK has bit 17, one with MisAlignSse +// (has_misalignsse). The instructions that "do not support misaligned +// accesses" use decode_xmm_src_aligned. +val check_sse_src_alignment : MemRef -> unit +function check_sse_src_alignment(m) = + if __stmxcsr()[17] == bitzero then check_alignment(m, 16) + +// Helper: decode XMM src operand value (read from register or memory). +// Enforces 16-byte alignment for memory operands (legacy SSE default). +val decode_xmm_src : XRM -> xmmword +function decode_xmm_src(src) = match src { + XRM_reg(xi) => read_simd(xi), + XRM_mem(m) => { check_sse_src_alignment(m); read_mem(m) }, +} + +// The loads of MOVAPS, MOVAPD, MOVDQA and MOVNTDQA, #GP(0) for a +// misaligned operand whatever MXCSR.MM: "The FXSAVE, FXRSTOR, (V)MOVAPD, +// (V)MOVAPS, and (V)MOVDQA, (V)MOVNTDQ, (V)MOVNTPD and (V)MOVNTPS +// instructions do not support misaligned accesses" (APM Vol.1 §4.3.2 +// p.121), and the pages of these and of MOVNTDQA give the #GP with no MM +// condition (APM Vol.4 pp.283, 286, 296, 321). For MOVNTDQA, APM Vol.1 +// p.152 says instead that the read "causes a #GP or invokes the alignment +// checking mechanism depending on the setting of the MXCSR[MM] bit"; the +// model follows its instruction page. +val decode_xmm_src_aligned : XRM -> xmmword +function decode_xmm_src_aligned(src) = match src { + XRM_reg(xi) => read_simd(xi), + XRM_mem(m) => { check_alignment(m, 16); read_mem(m) }, +} + +// Unaligned variant: no alignment check (for MOVDQU, PCMPxSTRx, etc.). +val decode_xmm_src_u : XRM -> xmmword +function decode_xmm_src_u(src) = match src { + XRM_reg(xi) => read_simd(xi), + XRM_mem(m) => read_mem(m), +} + +// SSE FP source: scalar reads 32/64 bits, packed reads 128 bits. +// F3 (SS) → 32-bit memory read; F2 (SD) → 64-bit; NP/66 (PS/PD) → 128-bit. +// Packed path enforces 16-byte alignment; scalar paths do not. +val decode_sse_fp_src : (XRM, MandatoryPrefix) -> xmmword +function decode_sse_fp_src(src, mp) = match src { + XRM_reg(xi) => read_simd(xi), + XRM_mem(m) => match mp { + MP_F3 => zero_extend(read_mem(32, m)), + MP_F2 => zero_extend(read_mem(64, m)), + _ => { check_sse_src_alignment(m); read_mem(m) }, + }, +} + +// Scalar FP source: reads low 'eb bits from XMM register or 'eb bits from memory. +val decode_scalar_src : forall 'eb, 'eb in {8, 16, 32, 64}. (implicit('eb), XRM) -> bits('eb) +function decode_scalar_src(eb, src) = match src { + XRM_reg(xi) => ZMM[xi][('eb - 1) .. 0], + XRM_mem(m) => read_mem(m), +} + +// Partial XMM source: reads low 'n bits from XMM register or 'n bits from memory. +// No alignment check (used for PMOVSX/PMOVZX which read m16/m32/m64). +val decode_xmm_partial_src : forall 'n, 'n in {16, 32, 64}. (implicit('n), XRM) -> bits('n) +function decode_xmm_partial_src(n, src) = match src { + XRM_reg(xi) => ZMM[xi][('n - 1) .. 0], + XRM_mem(m) => read_mem(m), +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail new file mode 100644 index 000000000..82c65ff15 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail @@ -0,0 +1,112 @@ +// x86-64 — Prefix Scanning +// +// Scans legacy prefixes and REX prefix from the instruction stream. +// In 64-bit mode, bytes 40-4F are REX prefixes (not INC/DEC). +// REX must be the last prefix before the opcode byte. + +val scan_prefixes : unit -> (Prefixes, byte) +function scan_prefixes() = { + var pfx : Prefixes = default_prefixes(); + var opcode : byte = 0x00; + var done : bool = false; + + // Loop scanning prefix bytes. The 15-byte instruction length limit is + // enforced by fetch(1), which raises #GP(0) if exceeded. + while ~(done) do { + let b : byte = fetch(1); + let bv : range(0, 255) = unsigned(b); + + // Clear REX state on any legacy prefix (REX must be last) + match bv { + // F0 = LOCK + 240 => pfx = {pfx with has_lock = true, has_rex = false, + rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // F2 = REPNE / mandatory prefix. F2 and F3 repeat the string and I/O + // instructions (exec_rep) and form the opcodes the opcode tables + // list with them (get_mandatory_prefix). Any other instruction + // ignores them, on both vendors. The APM defines that: "Repeat + // Prefixes—These prefixes affect only certain string instructions" + // (Vol.3 §1.2.1, p.6), and "The following prefixes are ignored by x87 + // instructions: REP—The F3h and F2h prefixes" (Vol.1 §6.6.2, p.327). + // The SDM leaves it open: "Use of repeat prefixes and/or undefined + // opcodes with other Intel 64 or IA-32 instructions is reserved; such + // use may cause unpredictable behavior" (Vol.2A §2.1.1, p.2-2), but + // for NOP, "NP 90", where other prefixes "will either cause an + // invalid-opcode exception (#UD) or result in the encoding for a + // different instruction" (Vol.2A §3.1.1.1, p.3-2): F2 90 is no + // instruction, and the model runs the NOP, as the APM has it. + // Where the APM's opcode maps form the opcode with F2 or F3 and list + // no instruction, "cells shaded gray represent reserved opcodes" + // (Vol.3 §A.1, p.524), #UD: the model raises it in the SSE, 0F 38 + // and 0F 3A maps and Groups 9 and 15, but not for 0F BA, 0F BB, MOVSX + // and CMPXCHG8B with either, nor BSF and BSR with F2 (Table A-4, + // p.532, Table A-7, p.536), which it runs as without the prefix. + 242 => pfx = {pfx with has_repne = true, has_rep = false, has_rex = false, + rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // F3 = REP / mandatory prefix + 243 => pfx = {pfx with has_rep = true, has_repne = false, has_rex = false, + rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 26 = ES override. In 64-bit mode, "the CS, DS, ES, and SS + // segment-override prefixes have no effect" and "are treated as null + // prefixes" (AMD64 APM Vol.3 §1.2.4): they leave the segment, and an + // FS or GS override before them, as they are. So does the SDM: + // "Other segment override prefixes (CS, DS, ES, and SS) are ignored" + // (Vol.1 §3.3.7.1 p.3-10), and a non-canonical ds:[rbp] is #SS(0), + // as without the prefix. + 38 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(ES), + has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 2E = CS override + 46 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(CS), + has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 36 = SS override + 54 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(SS), + has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 3E = DS override + 62 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(DS), + has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 64 = FS override + 100 => pfx = {pfx with seg_override = Some(FS), has_rex = false, + rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 65 = GS override + 101 => pfx = {pfx with seg_override = Some(GS), has_rex = false, + rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 66 = operand size override + 102 => pfx = {pfx with has_opsize = true, has_rex = false, + rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 67 = address size override + 103 => pfx = {pfx with has_adsize = 0b1, has_rex = false, + rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, + // 40-4F = REX prefix (64-bit mode only; INC/DEC in 32-bit mode) + bv if 64 <= bv & bv <= 79 & cur_mode == LongMode => + pfx = {pfx with + has_rex = true, + rex_w = b[3] == 0b1, + rex_r = b[2], + rex_x = b[1], + rex_b = b[0], + }, + _ => { + // Not a prefix — this is the opcode byte + opcode = b; + done = true; + }, + } + }; + (pfx, opcode) +} + +// Determine the mandatory prefix for 2-byte/3-byte opcode interpretation. +// F2/F3 take priority over 66. Last F2/F3 wins (handled in scan_prefixes). +val get_mandatory_prefix : Prefixes -> MandatoryPrefix +function get_mandatory_prefix(pfx) = + if pfx.has_repne then MP_F2 + else if pfx.has_rep then MP_F3 + else if pfx.has_opsize then MP_66 + else MP_NONE + +// VEX and EVEX are #UD after a LOCK, 66h, F2h or F3h prefix, or after a REX +// prefix (one followed by the escape byte; scan_prefixes forgets a REX +// that another prefix follows) (SDM Vol.2 §2.3.2, §2.7.11.1). +val vex_after_legacy_prefix : Prefixes -> bool +function vex_after_legacy_prefix(pfx) = + pfx.has_lock | pfx.has_opsize | pfx.has_repne | pfx.has_rep | pfx.has_rex diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail new file mode 100644 index 000000000..2021f7e4a --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail @@ -0,0 +1,698 @@ +// x86-64 — Shared SIMD Helpers +// +// Generic packed element-wise operations and vector-width helper functions +// shared across legacy SSE, VEX, and EVEX instruction files. + +// ========================================================================= +// Broadcast: replicate an element to fill a vector. +// ========================================================================= + +val broadcast : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (implicit('vl), bits('eb)) -> bits('vl) +function broadcast(vl, v) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + r[(lo + 'eb - 1)..lo] = v + }; + r +} + +// ========================================================================= +// Generic packed element-wise operations +// ========================================================================= + +// Generic packed unary operation (element-wise, one source). +enum PackedUnaryOp = { + PU_Abs, PU_Popcnt, PU_Lzcnt, PU_FSqrt, PU_FRsqrt, PU_FRcp, + PU_CvtDQ2PS, PU_CvtPS2DQ, PU_CvtTPS2DQ, + PU_CvtPS2UDQ, PU_CvtTPS2UDQ, + PU_CvtUDQ2PS, + PU_CvtPD2QQ, PU_CvtTPD2QQ, + PU_CvtPD2UQQ, PU_CvtTPD2UQQ, + PU_CvtQQ2PD, PU_CvtUQQ2PD, + PU_CvtPH2W, PU_CvtPH2UW, PU_CvtTPH2W, PU_CvtTPH2UW, + PU_CvtW2PH, PU_CvtUW2PH, + PU_FPGetexp, PU_FPRcp14, PU_FPRsqrt14, PU_FPRcp28, PU_FPRsqrt28, PU_FPExp2 +} + +val packed_unary_elem : forall 'eb, 'eb in {8, 16, 32, 64}. + (PackedUnaryOp, bits('eb)) -> bits('eb) +function packed_unary_elem(op, a) = match op { + PU_Abs => abs(a), + PU_Popcnt => to_bits(popcount(a)), + PU_Lzcnt => to_bits(clz(a)), + PU_FSqrt => fp_sqrt(a), + PU_FRsqrt => fp_rsqrt(a), + PU_FRcp => fp_rcp(a), + PU_CvtDQ2PS => { assert('eb == 32); __int32_to_f32(a) }, + PU_CvtPS2DQ => { assert('eb == 32); __f32_to_int32(a) }, + PU_CvtTPS2DQ => { assert('eb == 32); __f32_to_int32_trunc(a) }, + PU_CvtPS2UDQ => { assert('eb == 32); __f32_to_uint32(a) }, + PU_CvtTPS2UDQ => { assert('eb == 32); __f32_to_uint32_trunc(a) }, + PU_CvtUDQ2PS => { assert('eb == 32); __uint32_to_f32(a) }, + PU_CvtPD2QQ => { assert('eb == 64); __f64_to_int64(a) }, + PU_CvtTPD2QQ => { assert('eb == 64); __f64_to_int64_trunc(a) }, + PU_CvtPD2UQQ => { assert('eb == 64); __f64_to_uint64(a) }, + PU_CvtTPD2UQQ => { assert('eb == 64); __f64_to_uint64_trunc(a) }, + PU_CvtQQ2PD => { assert('eb == 64); __int64_to_f64(a) }, + PU_CvtUQQ2PD => { assert('eb == 64); __uint64_to_f64(a) }, + PU_CvtPH2W => { assert('eb == 16); __f16_to_int16(a) }, + PU_CvtPH2UW => { assert('eb == 16); __f16_to_uint16(a) }, + PU_CvtTPH2W => { assert('eb == 16); __f16_to_int16_trunc(a) }, + PU_CvtTPH2UW => { assert('eb == 16); __f16_to_uint16_trunc(a) }, + PU_CvtW2PH => { assert('eb == 16); __int16_to_f16(a) }, + PU_CvtUW2PH => { assert('eb == 16); __uint16_to_f16(a) }, + PU_FPGetexp => fp_getexp(a), + PU_FPRcp14 => fp_rcp14(a), + PU_FPRsqrt14 => fp_rsqrt14(a), + PU_FPRcp28 => fp_rcp28(a), + PU_FPRsqrt28 => fp_rsqrt28(a), + PU_FPExp2 => fp_exp2(a), +} + +val packed_unop : forall 'vl 'eb, 'vl in {64, 128, 256, 512} & 'eb in {8, 16, 32, 64}. + (PackedUnaryOp, int('eb), bits('vl)) -> bits('vl) +function packed_unop(op, eb, a) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + r[(lo + 'eb - 1)..lo] = packed_unary_elem(op, velem('eb, a, i)) + }; + r +} + +// Generic packed binary operation (element-wise, two sources). +enum PackedBinOp = { + PB_Add, PB_Sub, + PB_SatAddS, PB_SatSubS, PB_SatAddU, PB_SatSubU, + PB_MinU, PB_MaxU, PB_MinS, PB_MaxS, + PB_Avg, + PB_Srl, PB_Sra, PB_Sll, + PB_MulLow, PB_MulHighS, PB_MulHighU, PB_MulHRS, + PB_Ror, PB_Rol, + PB_CmpEq, PB_CmpGt, + PB_PSign, + PB_FAdd, PB_FSub, PB_FMul, PB_FDiv, PB_FMin, PB_FMax, + PB_FPScalef, + PB_Psadbw, PB_Pmaddubsw, PB_Pmaddwd, PB_Pmuludq, PB_Pmuldq, PB_Pshufb, + PB_HorizAddW, PB_HorizAddD, PB_HorizSatAddW, + PB_HorizSubW, PB_HorizSubD, PB_HorizSatSubW, + PB_HorizFAddS, PB_HorizFAddD, PB_HorizFSubS, PB_HorizFSubD, + PB_FAddSubS, PB_FAddSubD, + PB_And, PB_Or, PB_Xor, PB_Andn, +} + +// PMADDWD per-pair: signed * signed + signed * signed +val pmaddwd_pair : (word, word, word, word) -> dword +function pmaddwd_pair(a, b, c, d) = + to_bits_truncate(signed(a) * signed(b) + signed(c) * signed(d)) + +// Forward declaration — defined after packed_elem_op. +val packed_horiz : forall 'ew, 'ew in {16, 32, 64}. + (PackedBinOp, int('ew), bits(128)) -> bits(64) + +// Per-element dispatch: applies the operation to one pair of elements. +// Most ops work at eb in {8,16,32,64}; lane ops (PB_Pshufb etc.) work at eb=128. +val packed_elem_op : forall 'eb, 'eb in {8, 16, 32, 64, 128}. + (PackedBinOp, bits('eb), bits('eb)) -> bits('eb) +function packed_elem_op(op, a, b) = match op { + PB_Add => a + b, + PB_Sub => a - b, + PB_SatAddS => { assert('eb <= 64); sat_add_s(a, b) }, + PB_SatSubS => { assert('eb <= 64); sat_sub_s(a, b) }, + PB_SatAddU => { assert('eb <= 64); sat_add_u(a, b) }, + PB_SatSubU => { assert('eb <= 64); sat_sub_u(a, b) }, + PB_MinU => { assert('eb <= 64); min_u(a, b) }, + PB_MaxU => { assert('eb <= 64); max_u(a, b) }, + PB_MinS => { assert('eb <= 64); min_s(a, b) }, + PB_MaxS => { assert('eb <= 64); max_s(a, b) }, + PB_Avg => { assert('eb <= 64); avg(a, b) }, + // Per-element shift counts (VPSRLV*, VPSRAV*, VPSLLV*; SDM Vol.2C): a + // count of at least the element width leaves 0, or for the arithmetic + // shift every bit equal to the sign bit. Shifting by the raw lane value + // would build an intermediate as wide as the count. + PB_Srl => if unsigned(b) >= 'eb then zeros() else a >> unsigned(b), + PB_Sra => if unsigned(b) >= 'eb then (if a['eb - 1] == bitone then ones() else zeros()) + else a >>> unsigned(b), + PB_Sll => if unsigned(b) >= 'eb then zeros() else a << unsigned(b), + PB_MulLow => to_bits_truncate(signed(a) * signed(b)), + PB_MulHighS => get_slice_int('eb, signed(a) * signed(b), 'eb), + PB_MulHighU => get_slice_int('eb, unsigned(a) * unsigned(b), 'eb), + PB_MulHRS => { assert('eb <= 64); mulhrs(a, b) }, + PB_Ror => { assert('eb <= 64); rotr(a, unsigned(b) % 'eb) }, + PB_Rol => { assert('eb <= 64); rotl(a, unsigned(b) % 'eb) }, + PB_CmpEq => { assert('eb <= 64); cmp_eq(a, b) }, + PB_CmpGt => { assert('eb <= 64); cmp_gt(a, b) }, + PB_PSign => { assert('eb <= 64); psign(a, b) }, + PB_FAdd => { assert('eb <= 64); fp_add(a, b) }, + PB_FSub => { assert('eb <= 64); fp_sub(a, b) }, + PB_FMul => { assert('eb <= 64); fp_mul(a, b) }, + PB_FDiv => { assert('eb <= 64); fp_div(a, b) }, + PB_FMin => { assert('eb <= 64); fp_min(a, b) }, + PB_FMax => { assert('eb <= 64); fp_max(a, b) }, + PB_FPScalef => { assert('eb <= 64); fp_scalef(a, b) }, + PB_And => a & b, + PB_Or => a | b, + PB_Xor => a ^ b, + PB_Andn => ~(a) & b, + + // Ops with internal sub-element structure + PB_Pmaddubsw => { assert('eb == 16); pmaddubsw_pair(a[7..0], b[7..0], a[15..8], b[15..8]) }, + PB_Pmaddwd => { assert('eb == 32); pmaddwd_pair(a[15..0], b[15..0], a[31..16], b[31..16]) }, + PB_Pmuludq => { assert('eb == 64); to_bits(64, unsigned(a[31..0]) * unsigned(b[31..0])) }, + PB_Pmuldq => { assert('eb == 64); to_bits_truncate(signed(a[31..0]) * signed(b[31..0])) }, + PB_Psadbw => { assert('eb == 64); psadbw(a, b) }, + PB_Pshufb => { assert('eb == 128); pshufb(a, b) }, + PB_HorizAddW => { assert('eb == 128); packed_horiz(PB_Add, 16, b) @ packed_horiz(PB_Add, 16, a) }, + PB_HorizAddD => { assert('eb == 128); packed_horiz(PB_Add, 32, b) @ packed_horiz(PB_Add, 32, a) }, + PB_HorizSatAddW => { assert('eb == 128); packed_horiz(PB_SatAddS, 16, b) @ packed_horiz(PB_SatAddS, 16, a) }, + PB_HorizSubW => { assert('eb == 128); packed_horiz(PB_Sub, 16, b) @ packed_horiz(PB_Sub, 16, a) }, + PB_HorizSubD => { assert('eb == 128); packed_horiz(PB_Sub, 32, b) @ packed_horiz(PB_Sub, 32, a) }, + PB_HorizSatSubW => { assert('eb == 128); packed_horiz(PB_SatSubS, 16, b) @ packed_horiz(PB_SatSubS, 16, a) }, + PB_HorizFAddS => { assert('eb == 128); packed_horiz(PB_FAdd, 32, b) @ packed_horiz(PB_FAdd, 32, a) }, + PB_HorizFAddD => { assert('eb == 128); packed_horiz(PB_FAdd, 64, b) @ packed_horiz(PB_FAdd, 64, a) }, + PB_HorizFSubS => { assert('eb == 128); packed_horiz(PB_FSub, 32, b) @ packed_horiz(PB_FSub, 32, a) }, + PB_HorizFSubD => { assert('eb == 128); packed_horiz(PB_FSub, 64, b) @ packed_horiz(PB_FSub, 64, a) }, + // ADDSUBPS: even dwords use SUB, odd dwords use ADD + PB_FAddSubS => { assert('eb == 128); fp_add(a[127..96], b[127..96]) @ fp_sub(a[95..64], b[95..64]) @ + fp_add(a[63..32], b[63..32]) @ fp_sub(a[31..0], b[31..0]) }, + // ADDSUBPD: low qword uses SUB, high qword uses ADD + PB_FAddSubD => { assert('eb == 128); fp_add(a[127..64], b[127..64]) @ fp_sub(a[63..0], b[63..0]) }, +} + +// Reduce adjacent ew-bit element pairs within a 128-bit vector, producing 64 bits. +function packed_horiz(op, ew, src) = { + var r : bits(64) = zeros(); + foreach (i from 0 to (64 / ew - 1)) { + let s = i * 2 * ew; + let d = i * ew; + r[(d + ew - 1)..d] = packed_elem_op(op, src[(s + ew - 1)..s], src[(s + 2 * ew - 1)..(s + ew)]); + }; + r +} + +// Apply a packed binary operation element-wise across a vector. +val packed_binop : forall 'vl 'eb, 'vl in {64, 128, 256, 512} & 'eb in {8, 16, 32, 64, 128}. + (PackedBinOp, int('eb), bits('vl), bits('vl)) -> bits('vl) +function packed_binop(op, eb, a, b) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + r[(lo + 'eb - 1)..lo] = packed_elem_op(op, velem('eb, a, i), velem('eb, b, i)) + }; + r +} + +// Per-lane unary-with-immediate operations (PSHUFD, PSHUFHW, PSHUFLW). +enum PackedLaneImmOp = { PLI_Pshufd, PLI_Pshufhw, PLI_Pshuflw } + +val packed_lane_imm_elem : (PackedLaneImmOp, bits(128), byte) -> bits(128) +function packed_lane_imm_elem(op, src, imm) = match op { + PLI_Pshufd => { + var r : bits(128) = zeros(); + foreach (i from 0 to 3) { + let sel : range(0, 3) = unsigned(imm[(i * 2 + 1)..(i * 2)]); + let lo = i * 32; + r[(lo + 31)..lo] = velem(32, src, sel) + }; + r + }, + PLI_Pshufhw => { + var r : bits(128) = zeros(); + r[63..0] = src[63..0]; + foreach (i from 0 to 3) { + let sel : range(0, 3) = unsigned(imm[(i * 2 + 1)..(i * 2)]); + let lo = i * 16 + 64; + r[(lo + 15)..lo] = velem(16, src, sel + 4) + }; + r + }, + PLI_Pshuflw => { + var r : bits(128) = zeros(); + r[127..64] = src[127..64]; + foreach (i from 0 to 3) { + let sel : range(0, 3) = unsigned(imm[(i * 2 + 1)..(i * 2)]); + let lo = i * 16; + r[(lo + 15)..lo] = velem(16, src, sel) + }; + r + }, +} + +val packed_lane_imm_op : forall 'vl, 'vl in {128, 256, 512}. + (PackedLaneImmOp, bits('vl), byte) -> bits('vl) +function packed_lane_imm_op(op, src, imm) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 128 - 1)) { + let lo = i * 128; + r[(lo + 127)..lo] = packed_lane_imm_elem(op, velem(128, src, i), imm) + }; + r +} + +// Uniform packed shift: apply a scalar shift count to all elements. +enum PackedShiftOp = { PS_Srl, PS_Sra, PS_Sll } + +val packed_uniform_shift : forall 'vl 'eb, 'vl in {64, 128, 256, 512} & 'eb in {16, 32, 64, 128}. + (PackedShiftOp, int('eb), bits('vl), nat) -> bits('vl) +function packed_uniform_shift(op, eb, src, count) = { + // A count greater than the element width leaves all 0s (PSRL*, PSLL*) or + // the sign bit in every position (PSRA*): SDM PSRLW/PSRLD/PSRLQ, + // PSLLW/PSLLD/PSLLQ, PSRAW/PSRAD/PSRAQ, Description. Shifting by the + // width itself gives the same result, so clamp the count there; the + // 64-bit register count can otherwise exceed what the bitvector shift + // accepts. + let c : nat = if count > eb then eb else count; + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + let e = velem('eb, src, i); + r[(lo + 'eb - 1)..lo] = match op { + PS_Srl => e >> c, + PS_Sra => e >>> c, + PS_Sll => e << c, + } + }; + r +} + +// Interleave elements from two sources (PUNPCKLBW/WD/DQ/QDQ, PUNPCKHBW/WD/DQ/QDQ). +// Within each 128-bit lane, takes elements from the low (half=0) or high (half=64) +// half of a and b, and interleaves them: r[2i]=a[half+i], r[2i+1]=b[half+i]. +val packed_unpack : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (int('eb), {0, 64}, bits('vl), bits('vl)) -> bits('vl) +function packed_unpack(eb, half, a, b) = { + var r : bits('vl) = zeros(); + let elems_per_half = 64 / eb; + foreach (j from 0 to ('vl / 128 - 1)) { + let lbase = j * 128; + foreach (i from 0 to (elems_per_half - 1)) { + let src_lo = lbase + half + i * eb; + let dst_lo = lbase + i * 2 * eb; + r[(dst_lo + eb - 1)..dst_lo] = a[(src_lo + eb - 1)..src_lo]; + r[(dst_lo + 2 * eb - 1)..(dst_lo + eb)] = b[(src_lo + eb - 1)..src_lo]; + } + }; + r +} + +// Generic packed narrowing unary operation (each element shrinks). +// BF16 conversion: FP32 → BFloat16 (RNE, denormals flush to zero) +val convert_fp32_to_bf16 : dword -> word +function convert_fp32_to_bf16(x) = { + let exp : byte = x[30..23]; + let mant : bits(23) = x[22..0]; + let exp_zero : bit = is_zero(exp); + let exp_all : bit = is_zero(~(exp)); + let mant_nz : bit = is_nonzero(mant); + let r_zero : word = x[31] @ zeros(15); + let r_nan : word = x[31..16] | 0x0040; + let r_inf : word = x[31..16]; + let r_normal : word = (x + 0x00007FFF + zero_extend(x[16]))[31..16]; + let r1 : word = blend(r_normal, r_zero, exp_zero); + let r2 : word = blend(r1, r_inf, exp_all & ~(mant_nz)); + blend(r2, r_nan, exp_all & mant_nz) +} + +enum PackedNarrowOp = { PN_Trunc, PN_SatU, PN_SatS, PN_SatSU, PN_FP32toBF16 } + +val packed_narrow_elem : forall 'src 'dst, 'src in {16, 32, 64} & 'dst in {8, 16, 32} & 'src > 'dst. + (PackedNarrowOp, int('dst), bits('src)) -> bits('dst) +function packed_narrow_elem(op, dst, a) = match op { + PN_Trunc => a[('dst - 1)..0], + PN_SatU => sat_u(a), + PN_SatS => sat_s(a), + PN_SatSU => sat_su(a), + PN_FP32toBF16 => { assert('src == 32 & 'dst == 16); convert_fp32_to_bf16(a) }, +} + +val packed_narrow_unop : forall 'vl 'src 'dst, + 'vl in {128, 256, 512} & 'src in {16, 32, 64} & 'dst in {8, 16, 32} & 'src > 'dst. + (PackedNarrowOp, int('src), int('dst), bits('vl)) -> bits(div('vl * 'dst, 'src)) +function packed_narrow_unop(op, src_eb, dst_eb, a) = { + var r : bits(div('vl * 'dst, 'src)) = zeros(); + foreach (i from 0 to ('vl / 'src - 1)) { + let slo = i * 'src; + let dlo = i * 'dst; + r[(dlo + 'dst - 1)..dlo] = packed_narrow_elem(op, dst_eb, a[(slo + 'src - 1)..slo]) + }; + r +} + +// Two-source narrowing pack: within each 128-bit lane, narrow elements from a +// into the lower half and from b into the upper half, applying saturation. +// Covers PACKSSWB (PN_SatS, 16→8), PACKSSDW (PN_SatS, 32→16), +// PACKUSWB (PN_SatSU, 16→8), PACKUSDW (PN_SatSU, 32→16). +val packed_pack : forall 'vl 'src 'dst, + 'vl in {128, 256, 512} & 'src in {16, 32} & 'dst in {8, 16} & 'src == 'dst * 2. + (PackedNarrowOp, int('src), int('dst), bits('vl), bits('vl)) -> bits('vl) +function packed_pack(op, src, dst, a, b) = { + var r : bits('vl) = zeros(); + let elems = 128 / src; + foreach (j from 0 to ('vl / 128 - 1)) { + let lbase = j * 128; + foreach (i from 0 to (elems - 1)) { + let slo = lbase + i * src; + let a_lo = lbase + i * dst; + let b_lo = lbase + 64 + i * dst; + r[(a_lo + dst - 1)..a_lo] = packed_narrow_elem(op, dst, a[(slo + src - 1)..slo]); + r[(b_lo + dst - 1)..b_lo] = packed_narrow_elem(op, dst, b[(slo + src - 1)..slo]); + } + }; + r +} + +// Generic packed widening unary operation (each element expands). +enum PackedWidenOp = { PW_SignExtend, PW_ZeroExtend } + +val packed_widen_unop : forall 'vl 'n 'src 'dst, + 'vl in {128, 256, 512} & 'src in {8, 16, 32} & 'dst in {16, 32, 64} & 'dst > 'src & + 'n > 0 & 'n * 'dst == 'vl * 'src. + (implicit('vl), PackedWidenOp, int('src), int('dst), bits('n)) -> bits('vl) +function packed_widen_unop(vl, op, src_eb, dst_eb, a) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'dst - 1)) { + let slo = i * 'src; + let dlo = i * 'dst; + let elem = a[(slo + 'src - 1)..slo]; + r[(dlo + 'dst - 1)..dlo] = match op { + PW_SignExtend => sign_extend(dst_eb, elem), + PW_ZeroExtend => zero_extend(dst_eb, elem), + } + }; + r +} + +// Generic packed ternary operation (element-wise, three sources). +enum PackedTernaryOp = { + PT_FMAdd, PT_FMSub, PT_FNMAdd, PT_FNMSub, + PT_FunnelShl, PT_FunnelShr, + PT_DPBusd, PT_DPBusds, PT_DPWssd, PT_DPWssds, +} + +val packed_ternary_elem : forall 'eb, 'eb in {8, 16, 32, 64}. + (PackedTernaryOp, bits('eb), bits('eb), bits('eb)) -> bits('eb) +function packed_ternary_elem(op, a, b, c) = match op { + PT_FMAdd => fp_fmadd(a, b, c), + PT_FMSub => fp_fmsub(a, b, c), + PT_FNMAdd => fp_fnmadd(a, b, c), + PT_FNMSub => fp_fnmsub(a, b, c), + PT_FunnelShl => velem('eb, (a @ b) << (unsigned(c) % 'eb), 1), + PT_FunnelShr => velem('eb, (b @ a) >> (unsigned(c) % 'eb), 0), + + PT_DPBusd => { + assert('eb == 32); + to_bits_truncate(32, signed(a) + + unsigned(b[7..0]) * signed(c[7..0]) + + unsigned(b[15..8]) * signed(c[15..8]) + + unsigned(b[23..16]) * signed(c[23..16]) + + unsigned(b[31..24]) * signed(c[31..24])) + }, + PT_DPBusds => { + assert('eb == 32); + sat_s(to_bits_truncate(33, signed(a) + + unsigned(b[7..0]) * signed(c[7..0]) + + unsigned(b[15..8]) * signed(c[15..8]) + + unsigned(b[23..16]) * signed(c[23..16]) + + unsigned(b[31..24]) * signed(c[31..24]))) + }, + PT_DPWssd => { + assert('eb == 32); + to_bits_truncate(32, signed(a) + + signed(b[15..0]) * signed(c[15..0]) + + signed(b[31..16]) * signed(c[31..16])) + }, + PT_DPWssds => { + assert('eb == 32); + sat_s(to_bits_truncate(33, signed(a) + + signed(b[15..0]) * signed(c[15..0]) + + signed(b[31..16]) * signed(c[31..16]))) + }, +} + +val packed_ternop : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (PackedTernaryOp, int('eb), bits('vl), bits('vl), bits('vl)) -> bits('vl) +function packed_ternop(op, eb, a, b, c) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + r[(lo + 'eb - 1)..lo] = packed_ternary_elem(op, velem('eb, a, i), velem('eb, b, i), velem('eb, c, i)) + }; + r +} + +// ========================================================================= +// FP16 <-> FP32 packed conversion +// ========================================================================= + +val avx_vcvtph2ps : forall 'n, 'n in {64, 128, 256}. bits('n) -> bits('n * 2) +function avx_vcvtph2ps(src) = { + var r : bits('n * 2) = zeros(); + foreach (i from 0 to ('n / 16 - 1)) { + let lo = i * 32; + r[(lo + 31)..lo] = fp16_to_fp32(velem(16, src, i)); + }; + r +} + +val avx_vcvtps2ph : forall 'n, 'n in {128, 256, 512}. (bits('n), bits(2)) -> bits(div('n, 2)) +function avx_vcvtps2ph(src, rc) = { + var r : bits(div('n, 2)) = zeros(); + foreach (i from 0 to ('n / 32 - 1)) { + let lo = i * 16; + r[(lo + 15)..lo] = fp32_to_fp16(velem(32, src, i), rc); + }; + r +} + +// ========================================================================= +// GFNI vector operations +// ========================================================================= + +val avx_gf2p8mulb : forall 'vl, 'vl in {128, 256, 512}. + (bits('vl), bits('vl)) -> bits('vl) +function avx_gf2p8mulb(src1, src2) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 8 - 1)) { + let lo = i * 8; + r[(lo + 7)..lo] = gf2p8_mul(velem(8, src1, i), velem(8, src2, i)); + }; + r +} + +// Per-byte affine transform; each byte uses the 8x8 matrix from its 64-bit lane. +val avx_gf2p8affineqb : forall 'vl, 'vl in {128, 256, 512}. + (bits('vl), bits('vl), byte) -> bits('vl) +function avx_gf2p8affineqb(src1, src2, imm8) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 8 - 1)) { + let lo = i * 8; + r[(lo + 7)..lo] = gf2p8_affine(velem(8, src1, i), velem(64, src2, i / 8), imm8); + }; + r +} + +// Same but first applies GF(2^8) inverse on each src1 byte. +val avx_gf2p8affineinvqb : forall 'vl, 'vl in {128, 256, 512}. + (bits('vl), bits('vl), byte) -> bits('vl) +function avx_gf2p8affineinvqb(src1, src2, imm8) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 8 - 1)) { + let lo = i * 8; + r[(lo + 7)..lo] = gf2p8_affine(gf2p8_inv(velem(8, src1, i)), velem(64, src2, i / 8), imm8); + }; + r +} + +// ========================================================================= +// VP2INTERSECTD/Q: intersection of two element sets as position masks +// ========================================================================= + +// Bit i of the first mask is set when src1 element i occurs anywhere in +// src2; bit j of the second when src2 element j occurs anywhere in src1. +val vp2intersect : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {32, 64}. + (int('eb), bits('vl), bits('vl)) -> (qword, qword) +function vp2intersect(eb, src1, src2) = { + var m1 : qword = zeros(); + var m2 : qword = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + foreach (j from 0 to ('vl / 'eb - 1)) { + if velem('eb, src1, i) == velem('eb, src2, j) then { + m1[i] = bitone; + m2[j] = bitone + } + } + }; + (m1, m2) +} + +// ========================================================================= +// AES rounds on every 128-bit lane (VEX.256 and EVEX forms, VAES) +// ========================================================================= + +enum AesRound = { AES_Enc, AES_EncLast, AES_Dec, AES_DecLast } + +// The four rounds occupy opcodes 0F38 DC-DF in every encoding. +val aes_round_of_opcode : range(0, 255) -> AesRound +function aes_round_of_opcode(op) = match op { + 220 => AES_Enc, + 221 => AES_EncLast, + 222 => AES_Dec, + _ => AES_DecLast, +} + +val aes_round : (AesRound, xmmword, xmmword) -> xmmword +function aes_round(op, state, key) = match op { + AES_Enc => aesenc(state, key), + AES_EncLast => aesenclast(state, key), + AES_Dec => aesdec(state, key), + AES_DecLast => aesdeclast(state, key), +} + +// One round per 128-bit lane, each lane with its own state and round key. +val avx_aes_round : forall 'vl, 'vl in {128, 256, 512}. + (AesRound, bits('vl), bits('vl)) -> bits('vl) +function avx_aes_round(op, state, key) = { + var r : bits('vl) = zeros(); + foreach (lane from 0 to ('vl / 128 - 1)) { + let lo = lane * 128; + r[(lo + 127)..lo] = aes_round(op, velem(128, state, lane), velem(128, key, lane)); + }; + r +} + +// ========================================================================= +// Cross-lane permute (1-source and 2-source) +// ========================================================================= + +// 1-source permute: for each element i, result[i] = src[idx[i] % n_elems]. +val packed_permute : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (int('eb), bits('vl), bits('vl)) -> bits('vl) +function packed_permute(eb, src, idx) = { + var r : bits('vl) = zeros(); + let n = 'vl / 'eb; + foreach (i from 0 to (n - 1)) { + let j = unsigned(velem('eb, idx, i)) % n; + let lo = i * 'eb; + r[(lo + 'eb - 1)..lo] = velem('eb, src, j) + }; + r +} + +// 2-source permute: for each element i, result[i] = concat(t1,t2)[idx[i] % (2*n_elems)]. +val packed_permute2 : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (int('eb), bits('vl), bits('vl), bits('vl)) -> bits('vl) +function packed_permute2(eb, t1, t2, idx) = { + var r : bits('vl) = zeros(); + let n = 'vl / 'eb; + foreach (i from 0 to (n - 1)) { + let j = unsigned(velem('eb, idx, i)) % (2 * n); + let k = j % n; + let sel : bit = bool_to_bit(j >= n); + let lo = i * 'eb; + r[(lo + 'eb - 1)..lo] = blend(velem('eb, t1, k), velem('eb, t2, k), sel) + }; + r +} + +// ========================================================================= +// Expand/compress: mask-driven scatter/gather within a vector +// ========================================================================= + +// Count set bits in mask below position 'upto'. +val popcount_mask : forall 'n, 0 < 'n & 'n <= 64. (bits('n), int) -> int +function popcount_mask(v, upto) = { + assert(upto >= 0); + let w : qword = zero_extend(v); + popcount(w & ((0x0000000000000001 << upto) - 1)) +} + +// Packed funnel shift with immediate count (VPSHLD/VPSHRD imm forms). +val packed_funnel_shl_imm : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {16, 32, 64}. + (int('eb), bits('vl), bits('vl), nat) -> bits('vl) +function packed_funnel_shl_imm(eb, src1, src2, cnt) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + let a = velem('eb, src1, i); + let b = velem('eb, src2, i); + r[(lo + 'eb - 1)..lo] = velem('eb, (a @ b) << (cnt % 'eb), 1) + }; + r +} + +val packed_funnel_shr_imm : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {16, 32, 64}. + (int('eb), bits('vl), bits('vl), nat) -> bits('vl) +function packed_funnel_shr_imm(eb, src1, src2, cnt) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + let a = velem('eb, src1, i); + let b = velem('eb, src2, i); + r[(lo + 'eb - 1)..lo] = velem('eb, (b @ a) >> (cnt % 'eb), 0) + }; + r +} + +// Expand: for each dest element i, if mask[i] is set, copy from the next +// contiguous source element (indexed by popcount of lower mask bits). +val packed_expand : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (int('eb), bits('vl), qword) -> bits('vl) +function packed_expand(eb, src, mask) = { + var result : bits('vl) = zeros(); + let n = 'vl / 'eb; + foreach (i from 0 to (n - 1)) { + let j = popcount_mask(mask, i); + assert(j >= 0); + let lo = i * 'eb; + let src_elem : bits('eb) = get_slice_int('eb, unsigned(src), j * 'eb); + let lane_mask : bits('eb) = sign_extend(mask[i..i]); + result[(lo + 'eb - 1)..lo] = src_elem & lane_mask; + }; + result +} + +// Compress: for each source element i, if mask[i] is set, pack it into the +// next contiguous dest position (indexed by popcount of lower mask bits). +val packed_compress : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (int('eb), bits('vl), qword) -> bits('vl) +function packed_compress(eb, src, mask) = { + var result : bits('vl) = zeros(); + let n = 'vl / 'eb; + foreach (i from 0 to (n - 1)) { + let j = popcount_mask(mask, i); + assert(j >= 0); + let src_elem : bits('eb) = get_slice_int('eb, unsigned(src), i * 'eb); + let lane_mask : bits('eb) = sign_extend(mask[i..i]); + result = result | (zero_extend(src_elem & lane_mask) << (j * 'eb)); + }; + result +} + +// Compress to memory: compress, then write only the populated bytes. +val packed_compress_mem : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. + (int('eb), qword, bits('vl), qword) -> unit +function packed_compress_mem(eb, addr, src, mask) = { + let result = packed_compress(eb, src, mask); + let nbits = popcount_mask(mask, 'vl / 'eb) * 'eb; + assert(nbits >= 0 & nbits <= 'vl); + if nbits > 0 then + write_mem_linear(addr, truncate(result, nbits)); +} + +// ========================================================================= +// FP compare → EFLAGS helper (UCOMISS/SD/SH, COMISS/SD/SH, FUCOMI, etc.) +// Sets ZF/PF/CF from comparison result, clears OF/SF/AF. +// ========================================================================= + +val set_eflags_fp_compare : forall 'n, 'n in {16, 32, 64, 80}. (bits('n), bits('n)) -> unit +function set_eflags_fp_compare(a, b) = { + match fp_compare(a, b) { + FP_UNORDERED => { ZF = 0b1; PF = 0b1; CF = 0b1 }, + FP_GT => { ZF = 0b0; PF = 0b0; CF = 0b0 }, + FP_LT => { ZF = 0b0; PF = 0b0; CF = 0b1 }, + FP_EQ => { ZF = 0b1; PF = 0b0; CF = 0b0 }, + }; + OF = 0b0; SF = 0b0; AF = 0b0 +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail new file mode 100644 index 000000000..9b46b9c04 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail @@ -0,0 +1,893 @@ +// x86-64 — SSE Floating-Point Operations +// +// SSE/SSE2/SSE3 data movement, arithmetic, conversion, and comparison. + +// ========================================================================= +// SSE FP dispatch helpers — all-prefix binop/unop (PS/PD/SS/SD) +// ========================================================================= + +// SSE FP binary: MP_NONE=PS(32), MP_66=PD(64), MP_F3=SS, MP_F2=SD +val sse_exec_fp_binop : (PackedBinOp, simd_idx, xmmword, MandatoryPrefix) -> unit +function sse_exec_fp_binop(op, xreg, src_xmm, mp) = match mp { + MP_NONE => ZMM[xreg][127..0] = packed_binop(op, 32, read_simd(xreg), src_xmm), + MP_66 => ZMM[xreg][127..0] = packed_binop(op, 64, read_simd(xreg), src_xmm), + MP_F3 => ZMM[xreg][31..0] = packed_elem_op(op, ZMM[xreg][31..0], src_xmm[31..0]), + MP_F2 => ZMM[xreg][63..0] = packed_elem_op(op, ZMM[xreg][63..0], src_xmm[63..0]), +} + +// SSE FP unary: MP_NONE=PS(32), MP_66=PD(64), MP_F3=SS, MP_F2=SD +val sse_exec_fp_unop : (PackedUnaryOp, simd_idx, xmmword, MandatoryPrefix) -> unit +function sse_exec_fp_unop(op, xreg, src_xmm, mp) = match mp { + MP_NONE => ZMM[xreg][127..0] = packed_unop(op, 32, src_xmm), + MP_66 => ZMM[xreg][127..0] = packed_unop(op, 64, src_xmm), + MP_F3 => ZMM[xreg][31..0] = packed_unary_elem(op, src_xmm[31..0]), + MP_F2 => ZMM[xreg][63..0] = packed_unary_elem(op, src_xmm[63..0]), +} + +// ========================================================================= +// SSE floating-point dispatch +// ========================================================================= + +// FP comparison predicate helpers (used by CMPPS/CMPPD/CMPSS/CMPSD and +// EVEX VCMPPS/PD/SS/SD). SDM defines 32 predicates (imm8[4:0]). +// Predicates 16-31 repeat 0-15 with signaling/quiet flipped (same results). +// +// eval_fp_predicate: shared predicate logic on a comparison result. +// Returns 1 bit. Used by both SSE (sign-extended to mask) and EVEX (bit to kmask). +val eval_fp_predicate : (FPCompareResult, bits(4)) -> bit +function eval_fp_predicate(r, pred) = { + let unord : bit = match r { FP_UNORDERED => 0b1, _ => 0b0 }; + let eq : bit = match r { FP_EQ => 0b1, _ => 0b0 }; + let lt : bit = match r { FP_LT => 0b1, _ => 0b0 }; + let gt : bit = match r { FP_GT => 0b1, _ => 0b0 }; + let le : bit = lt | eq; + match pred { + 0x0 => eq, // EQ_OQ + 0x1 => lt, // LT_OS + 0x2 => le, // LE_OS + 0x3 => unord, // UNORD_Q + 0x4 => ~(eq), // NEQ_UQ (true for NaN) + 0x5 => ~(lt), // NLT_US (true for NaN) + 0x6 => ~(le), // NLE_US (true for NaN) + 0x7 => ~(unord), // ORD_Q + 0x8 => eq | unord, // EQ_UQ (true for NaN) + 0x9 => lt | unord, // NGE_US (true for NaN) + 0xA => le | unord, // NGT_US + 0xB => 0b0, // FALSE_OQ + 0xC => ~(eq) & ~(unord), // NEQ_OQ (false for NaN) + 0xD => ~(lt) & ~(unord), // GE_OS (false for NaN) + 0xE => gt, // GT_OS (false for NaN) + 0xF => 0b1, // TRUE_UQ + } +} + +// SSE CMPPS/CMPPD: returns full-width mask (all-ones or all-zeros per element) +val cmp_pred : forall 'n, 'n in {32, 64}. (bits('n), bits('n), bits(5)) -> bits('n) +function cmp_pred(a, b, pred) = + match('n) { + 32 => sign_extend(eval_fp_predicate(fp_compare(a, b), pred[3..0])), + 64 => sign_extend(eval_fp_predicate(fp_compare(a, b), pred[3..0])), + } + +// EVEX VCMPPS/VCMPPD: returns 1 bit per element (for kmask) +// pred[3:0] selects comparison; pred[4] only affects signaling (not modeled). +val cmp_pred5 : forall 'n, 'n in {32, 64}. (bits('n), bits('n), range(0, 31)) -> bit +function cmp_pred5(a, b, pred) = + match 'n { + 32 => eval_fp_predicate(fp_compare(a, b), to_bits(4, pred % 16)), + 64 => eval_fp_predicate(fp_compare(a, b), to_bits(4, pred % 16)), + } + +// Packed FP compare with predicate: element-wise CMPPS/CMPPD +val packed_cmp_pred : forall 'vl 'eb, 'vl in {128, 256} & 'eb in {32, 64}. + (int('eb), bits('vl), bits('vl), bits(5)) -> bits('vl) +function packed_cmp_pred(eb, a, b, pred) = { + var r : bits('vl) = zeros(); + foreach (i from 0 to ('vl / 'eb - 1)) { + let lo = i * 'eb; + r[(lo + 'eb - 1)..lo] = cmp_pred(velem('eb, a, i), velem('eb, b, i), pred) + }; + r +} + +val dispatch_2byte_sse_fp : (range(0, 255), Prefixes) -> unit +function dispatch_2byte_sse_fp(op, pfx) = { + match op { + // 0F 10: MOVUPS/MOVUPD/MOVSD/MOVSS xmm, xmm/m + 16 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + match mp { + // MOVUPS/MOVUPD xmm1, xmm2/m128 + MP_NONE => ZMM[xreg][127..0] = decode_xmm_src_u(src), + MP_66 => ZMM[xreg][127..0] = decode_xmm_src_u(src), + MP_F3 => { + // MOVSS xmm1, xmm2/m32 + match src { + XRM_reg(xi) => ZMM[xreg][31..0] = ZMM[xi][31..0], + XRM_mem(m) => ZMM[xreg][127..0] = zero_extend(v(32, m)), + } + }, + MP_F2 => { + // MOVSD xmm1, xmm2/m64 + match src { + XRM_reg(xi) => ZMM[xreg][63..0] = ZMM[xi][63..0], + XRM_mem(m) => ZMM[xreg][127..0] = zero_extend(v(64, m)), + } + }, + } + }, + // 0F 11: MOVUPS/MOVUPD/MOVSD/MOVSS xmm/m, xmm + 17 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let dest = modrm_xrm(modrm, pfx); + match mp { + // MOVUPS/MOVUPD xmm2/m128, xmm1 + MP_NONE => match dest { + XRM_reg(xi) => ZMM[xi][127..0] = read_simd(xreg), + XRM_mem(m) => write_mem(m, read_simd(128, xreg)), + }, + MP_66 => match dest { + XRM_reg(xi) => ZMM[xi][127..0] = read_simd(xreg), + XRM_mem(m) => write_mem(m, read_simd(128, xreg)), + }, + MP_F3 => { + // MOVSS m32, xmm1 + match dest { + XRM_reg(xi) => ZMM[xi][31..0] = ZMM[xreg][31..0], + XRM_mem(m) => v(m) = ZMM[xreg][31..0], + } + }, + MP_F2 => { + // MOVSD m64, xmm1 + match dest { + XRM_reg(xi) => ZMM[xi][63..0] = ZMM[xreg][63..0], + XRM_mem(m) => v(m) = ZMM[xreg][63..0], + } + }, + } + }, + // 0F 12: MOVLPS/MOVLPD/MOVSLDUP/MOVDDUP + 18 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + match mp { + MP_NONE => { + // MOVLPS xmm, m64 or MOVHLPS xmm, xmm + match src { + XRM_reg(xi) => { + let src : xmmword = read_simd(xi); + ZMM[xreg][127..0] = read_simd(128, xreg)[127..64] @ src[127..64] + }, + XRM_mem(m) => ZMM[xreg][63..0] = v(m), + } + }, + // MOVLPD xmm, m64 + MP_66 => match src { + XRM_reg(_) => raise_UD(), + XRM_mem(m) => ZMM[xreg][63..0] = v(m), + }, + MP_F3 => { + // MOVSLDUP xmm1, xmm2/m128 (SSE3) + let d : xmmword = decode_xmm_src(src); + ZMM[xreg][127..0] = d[95..64] @ d[95..64] @ d[31..0] @ d[31..0] + }, + MP_F2 => { + // MOVDDUP xmm1, xmm2/m64 (SSE3) + let lo : qword = decode_scalar_src(src); + ZMM[xreg][127..0] = lo @ lo + }, + } + }, + // 0F 13: MOVLPS/MOVLPD m64, xmm + 19 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let dest = modrm_rm(modrm, pfx); + rm_mem(64, dest) = read_simd(128, xreg)[63..0] + }, + // 0F 14: UNPCKLPS/UNPCKLPD + 20 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let src_xmm : xmmword = decode_xmm_src(src); + match mp { + MP_NONE => ZMM[xreg][127..0] = packed_unpack(32, 0, read_simd(xreg), src_xmm), + MP_66 => ZMM[xreg][127..0] = packed_unpack(64, 0, read_simd(xreg), src_xmm), + _ => raise_UD(), + } + }, + // 0F 15: UNPCKHPS/UNPCKHPD + 21 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let src_xmm : xmmword = decode_xmm_src(src); + match mp { + MP_NONE => ZMM[xreg][127..0] = packed_unpack(32, 64, read_simd(xreg), src_xmm), + MP_66 => ZMM[xreg][127..0] = packed_unpack(64, 64, read_simd(xreg), src_xmm), + _ => raise_UD(), + } + }, + // 0F 16: MOVHPS/MOVHPD/MOVSHDUP + 22 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + match mp { + MP_NONE => { + match src { + XRM_reg(xi) => { + let src : xmmword = read_simd(xi); + ZMM[xreg][127..0] = src[63..0] @ read_simd(128, xreg)[63..0] + }, + XRM_mem(m) => ZMM[xreg][127..64] = v(m), + } + }, + // MOVHPD xmm, m64 + MP_66 => match src { + XRM_reg(_) => raise_UD(), + XRM_mem(m) => ZMM[xreg][127..64] = v(m), + }, + MP_F3 => { + // MOVSHDUP xmm1, xmm2/m128 (SSE3) + let d : xmmword = decode_xmm_src(src); + ZMM[xreg][127..0] = d[127..96] @ d[127..96] @ d[63..32] @ d[63..32]; + }, + _ => raise_UD(), + } + }, + // 0F 17: MOVHPS/MOVHPD m64, xmm + 23 => { + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let dest = modrm_rm(modrm, pfx); + rm_mem(64, dest) = read_simd(128, xreg)[127..64] + }, + // 0F 28: MOVAPS/MOVAPD xmm, xmm/m128 + 40 => { + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + ZMM[xreg][127..0] = decode_xmm_src_aligned(modrm_xrm(modrm, pfx)) + }, + // 0F 29: MOVAPS/MOVAPD xmm/m128, xmm + 41 => { + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let dest = modrm_xrm(modrm, pfx); + match dest { + XRM_reg(xi) => ZMM[xi][127..0] = read_simd(xreg), + XRM_mem(m) => { check_alignment(m, 16); write_mem(m, read_simd(128, xreg)) }, + } + }, + // 0F 2A: CVTSI2SS/CVTSI2SD + 42 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_rm(modrm, pfx); + // The integer source is r/m32, or r/m64 with REX.W (SDM Vol.2A + // CVTSI2SS, CVTSI2SD); there is no 16-bit form. A 66h beside the F2h + // or F3h is "Other use of the 66H prefix", which "is reserved; such + // use may cause unpredictable behavior" (SDM Vol.2A §2.1.1, p.2-2); + // the model ignores it, as F2h and F3h take precedence over 66h for + // every legacy SIMD opcode (get_mandatory_prefix). + let rex_w = pfx.rex_w; + match mp { + // CVTSI2SS xmm, r/m32/64 (F3 prefix) + MP_F3 => ZMM[xreg][31..0] = + if rex_w then __int64_to_f32(v(64, src)) else __int32_to_f32(v(32, src)), + // CVTSI2SD xmm, r/m32/64 (F2 prefix) + MP_F2 => ZMM[xreg][63..0] = + if rex_w then __int64_to_f64(v(64, src)) else __int32_to_f64(v(32, src)), + // CVTPI2PS xmm, mm/m64 (NP) — SDM: DEST[31:0] := cvt(SRC[31:0]); DEST[63:32] := cvt(SRC[63:32]) + // High quadword unchanged. + MP_NONE => { + let mm_src : qword = match src { + RM_reg(_) => { mmx_touch(); x87_ST[unsigned(modrm[2..0])][63..0] }, + RM_mem(m) => v(m), + }; + ZMM[xreg][31..0] = __int32_to_f32(mm_src[31..0]); + ZMM[xreg][63..32] = __int32_to_f32(mm_src[63..32]) + }, + // CVTPI2PD xmm, mm/m64 (66 prefix) — SDM: full XMM write + MP_66 => { + let mm_src : qword = match src { + RM_reg(_) => { mmx_touch(); x87_ST[unsigned(modrm[2..0])][63..0] }, + RM_mem(m) => v(m), + }; + let lo : qword = __int32_to_f64(mm_src[31..0]); + let hi : qword = __int32_to_f64(mm_src[63..32]); + ZMM[xreg][127..0] = hi @ lo + }, + } + }, + // 0F 2C: CVTTSS2SI/CVTTSD2SI + 44 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let src = modrm_xrm(modrm, pfx); + match mp { + // CVTTSS2SI r, xmm/m32 (F3) + MP_F3 => { + let reg = modrm_reg(modrm, pfx); + let os = opsize(pfx); + let src_val : dword = decode_scalar_src(src); + match os { + 64 => v(reg) = __f32_to_int64_trunc(src_val), + _ => v(reg) = __f32_to_int32_trunc(src_val), + } + }, + // CVTTSD2SI r, xmm/m64 (F2) + MP_F2 => { + let reg = modrm_reg(modrm, pfx); + let os = opsize(pfx); + let src_val : qword = decode_scalar_src(src); + match os { + 64 => v(reg) = __f64_to_int64_trunc(src_val), + _ => v(reg) = __f64_to_int32_trunc(src_val), + } + }, + // CVTTPS2PI mm, xmm/m64 (NP) + MP_NONE => { + let src_val : qword = decode_scalar_src(src); + mmx_touch(); + let mm_dst : range(0, 7) = unsigned(modrm[5..3]); + x87_ST[mm_dst] = ones(16) @ (__f32_to_int32_trunc(src_val[63..32]) @ __f32_to_int32_trunc(src_val[31..0])) + }, + // CVTTPD2PI mm, xmm/m128 (66) + MP_66 => { + let src_xmm : xmmword = decode_xmm_src(src); + mmx_touch(); + let mm_dst : range(0, 7) = unsigned(modrm[5..3]); + x87_ST[mm_dst] = ones(16) @ (__f64_to_int32_trunc(src_xmm[127..64]) @ __f64_to_int32_trunc(src_xmm[63..0])) + }, + } + }, + // 0F 2D: CVTSS2SI/CVTSD2SI + 45 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let src = modrm_xrm(modrm, pfx); + match mp { + // CVTSS2SI r, xmm/m32 (F3) + MP_F3 => { + let reg = modrm_reg(modrm, pfx); + let os = opsize(pfx); + let src_val : dword = decode_scalar_src(src); + match os { + 64 => v(reg) = __f32_to_int64(src_val), + _ => v(reg) = __f32_to_int32(src_val), + } + }, + // CVTSD2SI r, xmm/m64 (F2) + MP_F2 => { + let reg = modrm_reg(modrm, pfx); + let os = opsize(pfx); + let src_val : qword = decode_scalar_src(src); + match os { + 64 => v(reg) = __f64_to_int64(src_val), + _ => v(reg) = __f64_to_int32(src_val), + } + }, + // CVTPS2PI mm, xmm/m64 (NP) + MP_NONE => { + let src_val : qword = decode_scalar_src(src); + mmx_touch(); + let mm_dst : range(0, 7) = unsigned(modrm[5..3]); + x87_ST[mm_dst] = ones(16) @ (__f32_to_int32(src_val[63..32]) @ __f32_to_int32(src_val[31..0])) + }, + // CVTPD2PI mm, xmm/m128 (66) + MP_66 => { + let src_xmm : xmmword = decode_xmm_src(src); + mmx_touch(); + let mm_dst : range(0, 7) = unsigned(modrm[5..3]); + x87_ST[mm_dst] = ones(16) @ (__f64_to_int32(src_xmm[127..64]) @ __f64_to_int32(src_xmm[63..0])) + }, + } + }, + // 0F 2E: UCOMISS/UCOMISD + 46 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + if mp == MP_NONE + then set_eflags_fp_compare(read_simd(128, xreg)[31..0] : dword, decode_scalar_src(src)) + else set_eflags_fp_compare(read_simd(128, xreg)[63..0] : qword, decode_scalar_src(src)) + }, + // 0F 2F: COMISS/COMISD + 47 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + if mp == MP_NONE + then set_eflags_fp_compare(read_simd(128, xreg)[31..0] : dword, decode_scalar_src(src)) + else set_eflags_fp_compare(read_simd(128, xreg)[63..0] : qword, decode_scalar_src(src)) + }, + // 0F 50: MOVMSKPS/MOVMSKPD + 80 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let reg = modrm_reg(modrm, pfx); + let xi = xrm_reg(modrm_xrm(modrm, pfx)); + let src_xmm : xmmword = read_simd(xi); + match mp { + MP_NONE => { + let mask : bits(4) = src_xmm[127] @ src_xmm[95] @ src_xmm[63] @ src_xmm[31]; + v(reg) = zero_extend(32, mask) + }, + MP_66 => { + let mask : bits(2) = src_xmm[127] @ src_xmm[63]; + v(reg) = zero_extend(32, mask) + }, + _ => raise_UD(), + } + }, + // 0F 51-5F: SSE/SSE2 scalar/packed arithmetic + // These follow a pattern based on mandatory prefix: + // NONE=PS, 66=PD, F3=SS, F2=SD + op if 81 <= op & op <= 95 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let arith_op : range(0, 15) = op - 80; + // CVTPS2PD (0F 5A, NP) reads xmm/m64, not xmm/m128 + let src_xmm : xmmword = if arith_op == 10 & mp == MP_NONE then + zero_extend(decode_xmm_partial_src(64, src)) + else + decode_sse_fp_src(src, mp); + match arith_op { + // 0F 51: SQRT + 1 => sse_exec_fp_unop(PU_FSqrt, xreg, src_xmm, mp), + // 0F 54: ANDPS/ANDPD + 4 => ZMM[xreg][127..0] = read_simd(xreg) & src_xmm, + // 0F 55: ANDNPS/ANDNPD + 5 => ZMM[xreg][127..0] = ~(read_simd(xreg)) & src_xmm, + // 0F 56: ORPS/ORPD + 6 => ZMM[xreg][127..0] = read_simd(xreg) | src_xmm, + // 0F 57: XORPS/XORPD + 7 => ZMM[xreg][127..0] = read_simd(xreg) ^ src_xmm, + // 0F 58: ADD + 8 => sse_exec_fp_binop(PB_FAdd, xreg, src_xmm, mp), + // 0F 59: MUL + 9 => sse_exec_fp_binop(PB_FMul, xreg, src_xmm, mp), + // 0F 5A: CVTPS2PD/CVTPD2PS/CVTSS2SD/CVTSD2SS + 10 => { + match mp { + // CVTPS2PD: reads xmm/m64 (already decoded above) + MP_NONE => { + let r : xmmword = __f32_to_f64(src_xmm[63..32]) @ __f32_to_f64(src_xmm[31..0]); + ZMM[xreg][127..0] = r + }, + // CVTPD2PS: reads xmm/m128 + MP_66 => { + let r : xmmword = zeros(64) @ __f64_to_f32(src_xmm[127..64]) @ __f64_to_f32(src_xmm[63..0]); + ZMM[xreg][127..0] = r + }, + // CVTSS2SD: reads xmm/m32 + MP_F3 => ZMM[xreg][63..0] = __f32_to_f64(src_xmm[31..0]), + // CVTSD2SS: reads xmm/m64 + MP_F2 => ZMM[xreg][31..0] = __f64_to_f32(src_xmm[63..0]), + } + }, + // 0F 5B: CVTDQ2PS/CVTPS2DQ/CVTTPS2DQ — all packed (F3 is NOT scalar) + 11 => { + let s : xmmword = if mp == MP_F3 then decode_xmm_src(src) else src_xmm; + match mp { + MP_NONE => ZMM[xreg][127..0] = packed_unop(PU_CvtDQ2PS, 32, s), + MP_66 => ZMM[xreg][127..0] = packed_unop(PU_CvtPS2DQ, 32, s), + MP_F3 => ZMM[xreg][127..0] = packed_unop(PU_CvtTPS2DQ, 32, s), + _ => raise_UD(), + } + }, + // 0F 5C: SUB + 12 => sse_exec_fp_binop(PB_FSub, xreg, src_xmm, mp), + // 0F 5D: MIN + 13 => sse_exec_fp_binop(PB_FMin, xreg, src_xmm, mp), + // 0F 5E: DIV + 14 => sse_exec_fp_binop(PB_FDiv, xreg, src_xmm, mp), + // 0F 5F: MAX + 15 => sse_exec_fp_binop(PB_FMax, xreg, src_xmm, mp), + // 0F 52: RSQRTPS/RSQRTSS + 2 => match mp { + MP_NONE => ZMM[xreg][127..0] = packed_unop(PU_FRsqrt, 32, src_xmm), + MP_F3 => ZMM[xreg][31..0] = fp_rsqrt(src_xmm[31..0]), + _ => raise_UD(), + }, + // 0F 53: RCPPS/RCPSS + 3 => match mp { + MP_NONE => ZMM[xreg][127..0] = packed_unop(PU_FRcp, 32, src_xmm), + MP_F3 => ZMM[xreg][31..0] = fp_rcp(src_xmm[31..0]), + _ => raise_UD(), + }, + _ => raise_UD(), + } + }, + // 0F C6: SHUFPS/SHUFPD xmm, xmm/m128, imm8 + 198 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let imm = fetch(1); + // SDM Vol.2A §2.2.1.6: RIP-relative addresses use the next + // instruction's RIP, including this trailing immediate byte. + let src_xmm : xmmword = decode_xmm_src(src); + match mp { + MP_NONE => { + let d : xmmword = read_simd(xreg); + let d0 : dword = velem(32, d, imm[1..0]); + let d1 : dword = velem(32, d, imm[3..2]); + let d2 : dword = velem(32, src_xmm, imm[5..4]); + let d3 : dword = velem(32, src_xmm, imm[7..6]); + ZMM[xreg][127..0] = d3 @ d2 @ d1 @ d0 + }, + MP_66 => { + let d : xmmword = read_simd(xreg); + let low : qword = blend(d[63..0], d[127..64], imm[0]); + let high : qword = blend(src_xmm[63..0], src_xmm[127..64], imm[1]); + ZMM[xreg][127..0] = high @ low + }, + _ => raise_UD(), + } + }, + // 0F D6: MOVQ xmm/m64, xmm (66 prefix) + 214 => { + let mp = get_mandatory_prefix(pfx); + match mp { + // 66 0F D6: MOVQ xmm1/m64, xmm2 — store low 64 bits + MP_66 => { + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let dest = modrm_xrm(modrm, pfx); + let data : xmmword = read_simd(xreg); + match dest { + XRM_reg(xi) => ZMM[xi][127..0] = zero_extend(data[63..0]), + XRM_mem(m) => v(m) = data[63..0], + } + }, + // F2 0F D6: MOVDQ2Q mm, xmm — SDM: DEST := SRC[63:0] + MP_F2 => { + let modrm = fetch(1); + let xi = xrm_reg(modrm_xrm(modrm, pfx)); + let mm_dst : range(0, 7) = unsigned(modrm[5..3]); + mmx_touch(); + x87_ST[mm_dst] = ones(16) @ (read_simd(128, xi)[63..0]) + }, + // F3 0F D6: MOVQ2DQ xmm, mm — SDM: DEST[63:0] := SRC; DEST[127:64] := 0, + // with the transition to MMX operation (TOP := 0, all tags valid) + MP_F3 => { + let modrm = fetch(1); + let _ = modrm_rm(modrm, pfx); + let dst_xmm = modrm_xreg(modrm, pfx); + let mm_src : range(0, 7) = unsigned(modrm[2..0]); + mmx_touch(); + ZMM[dst_xmm][127..0] = zero_extend(x87_ST[mm_src][63..0]) + }, + _ => raise_UD(), + } + }, + // 0F E6: CVTDQ2PD/CVTPD2DQ/CVTTPD2DQ + 230 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + match mp { + // CVTDQ2PD: reads only 64 bits (two dwords), no alignment required + MP_F3 => { + let lo64 : qword = decode_xmm_partial_src(64, src); + let r : xmmword = __int32_to_f64(lo64[63..32]) @ __int32_to_f64(lo64[31..0]); + ZMM[xreg][127..0] = r + }, + // CVTPD2DQ: reads 128 bits, 16-byte alignment required + MP_F2 => { + let src_xmm : xmmword = decode_xmm_src(src); + let r : xmmword = zeros(64) @ __f64_to_int32(src_xmm[127..64]) @ __f64_to_int32(src_xmm[63..0]); + ZMM[xreg][127..0] = r + }, + // CVTTPD2DQ: reads 128 bits, 16-byte alignment required + MP_66 => { + let src_xmm : xmmword = decode_xmm_src(src); + let lo : dword = __f64_to_int32_trunc(src_xmm[63..0]); + let hi : dword = __f64_to_int32_trunc(src_xmm[127..64]); + let r : xmmword = zeros(64) @ hi @ lo; + ZMM[xreg][127..0] = r + }, + _ => raise_UD(), + } + }, + // 0F 2B: MOVNTPS/MOVNTPD m128, xmm (requires 16-byte alignment); on AMD + // also MOVNTSS m32, xmm (F3) and MOVNTSD m64, xmm (F2), the low element + // with no alignment requirement (AMD APM Vol.4 MOVNTSS, MOVNTSD) + 43 => { + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let dest = modrm_rm(modrm, pfx); + match get_mandatory_prefix(pfx) { + MP_F3 => rm_mem(dest) = read_simd(128, xreg)[31..0], + MP_F2 => rm_mem(dest) = read_simd(128, xreg)[63..0], + _ => { + check_alignment(dest, 16); + rm_mem(dest) = read_simd(128, xreg) + }, + } + }, + // 0F 7C: HADDPS/HADDPD (SSE3) + 124 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let src_xmm : xmmword = decode_xmm_src(src); + match mp { + MP_F2 => ZMM[xreg][127..0] = packed_binop(PB_HorizFAddS, 128, read_simd(xreg), src_xmm), + MP_66 => ZMM[xreg][127..0] = packed_binop(PB_HorizFAddD, 128, read_simd(xreg), src_xmm), + _ => raise_UD(), + } + }, + // 0F 7D: HSUBPS/HSUBPD (SSE3) + 125 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let src_xmm : xmmword = decode_xmm_src(src); + match mp { + MP_F2 => ZMM[xreg][127..0] = packed_binop(PB_HorizFSubS, 128, read_simd(xreg), src_xmm), + MP_66 => ZMM[xreg][127..0] = packed_binop(PB_HorizFSubD, 128, read_simd(xreg), src_xmm), + _ => raise_UD(), + } + }, + // 0F C2: CMPPS/CMPPD/CMPSS/CMPSD xmm, xmm/m, imm8 + 194 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let imm = fetch(1); + let src_xmm : xmmword = decode_sse_fp_src(src, mp); + let a : xmmword = read_simd(xreg); + let pred : bits(5) = zero_extend(imm[2..0]); + match mp { + MP_NONE => ZMM[xreg][127..0] = packed_cmp_pred(32, a, src_xmm, pred), + MP_66 => ZMM[xreg][127..0] = packed_cmp_pred(64, a, src_xmm, pred), + MP_F3 => ZMM[xreg][127..0] = a[127..32] @ cmp_pred(a[31..0], src_xmm[31..0], pred), + MP_F2 => ZMM[xreg][127..0] = a[127..64] @ cmp_pred(a[63..0], src_xmm[63..0], pred), + } + }, + // 0F D0: ADDSUBPS/ADDSUBPD (SSE3) + 208 => { + let mp = get_mandatory_prefix(pfx); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let src_xmm : xmmword = decode_xmm_src(src); + match mp { + MP_F2 => ZMM[xreg][127..0] = packed_binop(PB_FAddSubS, 128, read_simd(xreg), src_xmm), + MP_66 => ZMM[xreg][127..0] = packed_binop(PB_FAddSubD, 128, read_simd(xreg), src_xmm), + _ => raise_UD(), + } + }, + _ => raise_UD(), + } +} + +// INSERTPS — Insert Scalar Single-Precision FP Value (SSE4.1) +val exec_insertps : (simd_idx, xmmword, byte) -> unit +function exec_insertps(dst, src, imm8) = { + let a : xmmword = read_simd(dst); + let b : xmmword = src; + // Select source float using imm8[7:6] + let src_sel : range(0, 3) = unsigned(imm8[7..6]); + let src_float : dword = b[(src_sel * 32 + 31) .. (src_sel * 32)]; + // Insert at destination position using imm8[5:4] + let sel = imm8[5..4]; + let m0 : dword = sign_extend(~(sel[1] | sel[0])); + let x1 : bits(2) = sel ^ 0b01; + let m1 : dword = sign_extend(~(x1[1] | x1[0])); + let x2 : bits(2) = sel ^ 0b10; + let m2 : dword = sign_extend(~(x2[1] | x2[0])); + let x3 : bits(2) = sel ^ 0b11; + let m3 : dword = sign_extend(~(x3[1] | x3[0])); + let t0 : dword = (src_float & m0) | (a[31..0] & ~(m0)); + let t1 : dword = (src_float & m1) | (a[63..32] & ~(m1)); + let t2 : dword = (src_float & m2) | (a[95..64] & ~(m2)); + let t3 : dword = (src_float & m3) | (a[127..96] & ~(m3)); + // Zero lanes indicated by imm8[3:0] (branchless) + ZMM[dst][127..0] = (t3 & sign_extend(~(imm8[3]))) @ + (t2 & sign_extend(~(imm8[2]))) @ + (t1 & sign_extend(~(imm8[1]))) @ + (t0 & sign_extend(~(imm8[0]))) +} + +// ========================================================================= +// 3-Byte Opcode Map: SSE Floating-Point Operations +// ========================================================================= + +// 0F 38 xx — SSE FP operations (BLENDVPS, BLENDVPD) +val dispatch_3byte_38_sse_fp : (byte, Prefixes) -> unit +function dispatch_3byte_38_sse_fp(opcode, pfx) = { + let op : range(0, 255) = unsigned(opcode); + let mp = get_mandatory_prefix(pfx); + if mp != MP_66 then raise_UD(); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + let src_xmm : xmmword = decode_xmm_src(src); + match op { + // BLENDVPS xmm1, xmm2/m128, + 20 => { + let a : xmmword = read_simd(xreg); + let m : xmmword = read_simd(0); + var r : xmmword = zeros(); + foreach (i from 0 to 3) { + let lo = i * 32; + r[(lo + 31)..lo] = blend(velem(32, a, i), velem(32, src_xmm, i), m[lo + 31]) + }; + ZMM[xreg][127..0] = r + }, + // BLENDVPD xmm1, xmm2/m128, + 21 => { + let a : xmmword = read_simd(xreg); + let m : xmmword = read_simd(0); + var r : xmmword = zeros(); + foreach (i from 0 to 1) { + let lo = i * 64; + r[(lo + 63)..lo] = blend(velem(64, a, i), velem(64, src_xmm, i), m[lo + 63]) + }; + ZMM[xreg][127..0] = r + }, + _ => raise_UD(), + } +} + +// 0F 3A xx — SSE FP operations (ROUND*, BLEND*, DP*, EXTRACTPS, INSERTPS) +val dispatch_3byte_3a_sse_fp : (byte, Prefixes) -> unit +function dispatch_3byte_3a_sse_fp(opcode, pfx) = { + let op : range(0, 255) = unsigned(opcode); + let mp = get_mandatory_prefix(pfx); + if mp != MP_66 then raise_UD(); + let modrm = fetch(1); + let xreg = modrm_xreg(modrm, pfx); + let src = modrm_xrm(modrm, pfx); + // Every 0F 3A instruction ends with an imm8. Fetch it before any operand + // is accessed: a RIP-relative operand is relative to the end of the + // instruction (see fixup_addr). + let imm = fetch(1); + match op { + // SSE4.1 — ROUNDPS xmm1, xmm2/m128, imm8 + 8 => { + let src_xmm = decode_xmm_src(src); + var r : xmmword = zeros(); + foreach (i from 0 to 3) { + let lo = i * 32; + r[(lo + 31)..lo] = fp_round(velem(32, src_xmm, i), imm) + }; + ZMM[xreg][127..0] = r + }, + // ROUNDPD xmm1, xmm2/m128, imm8 + 9 => { + let src_xmm = decode_xmm_src(src); + var r : xmmword = zeros(); + foreach (i from 0 to 1) { + let lo = i * 64; + r[(lo + 63)..lo] = fp_round(velem(64, src_xmm, i), imm) + }; + ZMM[xreg][127..0] = r + }, + // ROUNDSS: reads 32 bits from memory, no alignment required + 10 => { + let src32 : dword = decode_scalar_src(src); + let a : xmmword = read_simd(xreg); + let lo : dword = fp_round(src32, imm); + ZMM[xreg][127..0] = a[127..32] @ lo + }, + // ROUNDSD: reads 64 bits from memory, no alignment required + 11 => { + let src64 : qword = decode_scalar_src(src); + let a : xmmword = read_simd(xreg); + let lo : qword = fp_round(src64, imm); + ZMM[xreg][127..0] = a[127..64] @ lo + }, + + // SSE4.1 — BLENDPS xmm1, xmm2/m128, imm8 + 12 => { + let src_xmm = decode_xmm_src(src); + let a : xmmword = read_simd(xreg); + var r : xmmword = zeros(); + foreach (i from 0 to 3) { + let lo = i * 32; + r[(lo + 31)..lo] = blend(velem(32, a, i), velem(32, src_xmm, i), imm[i]) + }; + ZMM[xreg][127..0] = r + }, + // BLENDPD xmm1, xmm2/m128, imm8 + 13 => { + let src_xmm = decode_xmm_src(src); + let a : xmmword = read_simd(xreg); + var r : xmmword = zeros(); + foreach (i from 0 to 1) { + let lo = i * 64; + r[(lo + 63)..lo] = blend(velem(64, a, i), velem(64, src_xmm, i), imm[i]) + }; + ZMM[xreg][127..0] = r + }, + + // PEXTRW r/m16, xmm, imm8 (SSE4.1, 66 0F 3A 15) + // SDM: ModRM:reg = source XMM, ModRM:r/m = dest (reg: zero-extend to 32, mem: 16 bits) + 21 => { + let sel : range(0, 7) = unsigned(imm[2..0]); + let w : word = velem(16, ZMM[xreg], sel); + match src { + XRM_reg(_) => v(modrm_rm_reg(modrm, pfx)) = zero_extend(32, w), + XRM_mem(m) => v(m) = w, + } + }, + + // EXTRACTPS r/m32, xmm, imm8 + 23 => { + let data = velem(32, ZMM[xreg], imm[1..0]); + match src { + XRM_reg(_) => v(modrm_rm_reg(modrm, pfx)) = data, + XRM_mem(m) => v(m) = data, + } + }, + + // INSERTPS xmm, xmm/m32, imm8 + // Memory form: reads 32 bits, imm8[7:6] forced to 0 (count_s ignored). + 33 => { + match src { + XRM_reg(xi) => exec_insertps(xreg, read_simd(xi), imm), + XRM_mem(m) => { + let src_val : xmmword = zero_extend(v(32, m)); + exec_insertps(xreg, src_val, imm & 0x3F) + }, + } + }, + + // SSE4.1 — dot product + 64 => { + let src_xmm = decode_xmm_src(src); + let a : xmmword = read_simd(xreg); + let temp0 : dword = fp_mul(a[31..0], src_xmm[31..0]) & sign_extend(imm[4]); + let temp1 : dword = fp_mul(a[63..32], src_xmm[63..32]) & sign_extend(imm[5]); + let temp2 : dword = fp_mul(a[95..64], src_xmm[95..64]) & sign_extend(imm[6]); + let temp3 : dword = fp_mul(a[127..96], src_xmm[127..96]) & sign_extend(imm[7]); + let sum01 : dword = fp_add(temp0, temp1); + let sum23 : dword = fp_add(temp2, temp3); + let sum : dword = fp_add(sum01, sum23); + ZMM[xreg][127..0] = + (sum & sign_extend(imm[3])) @ + (sum & sign_extend(imm[2])) @ + (sum & sign_extend(imm[1])) @ + (sum & sign_extend(imm[0])) + }, + 65 => { + let src_xmm = decode_xmm_src(src); + let a : xmmword = read_simd(xreg); + let temp0 : qword = fp_mul(a[63..0], src_xmm[63..0]) & sign_extend(imm[4]); + let temp1 : qword = fp_mul(a[127..64], src_xmm[127..64]) & sign_extend(imm[5]); + let sum : qword = fp_add(temp0, temp1); + ZMM[xreg][127..0] = + (sum & sign_extend(imm[1])) @ + (sum & sign_extend(imm[0])) + }, + + _ => raise_UD(), + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail new file mode 100644 index 000000000..f83a79f2f --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail @@ -0,0 +1,755 @@ +// x86-64 — Memory Interface +// +// Two-layer memory model following the sail-riscv pattern: +// read_mem/write_mem (virtual) → translate_addr → phys_read/phys_write +// +// When paging is disabled (CR0.PG=0, user-mode emulation), translate_addr +// returns the address unchanged, so all existing instruction code works +// without modification. +// +// Physical memory primitives (__read_mem, __write_mem, phys_read, phys_write) +// and the address translation function (translate_addr) are defined in +// paging.sail, which is compiled before this file. + +// Forward declarations so that the read_mem/write_mem overloads are +// available to all functions in this file (including stack operations). +// Size parameter 'n is in bits. +val read_mem_linear : forall 'n, 'n > 0. (implicit('n), qword, PTAccess) -> bits('n) +val read_mem_data : forall 'n, 'n > 0. (implicit('n), qword) -> bits('n) +val read_mem_implicit : forall 'n, 'n > 0. (implicit('n), qword) -> bits('n) +val write_mem_linear : forall 'n, 'n > 0. (implicit('n), qword, bits('n)) -> unit +val read_mem_ref : forall 'n, 'n > 0. (implicit('n), MemRef) -> bits('n) +val write_mem_ref : forall 'n, 'n > 0. (implicit('n), MemRef, bits('n)) -> unit + +overload read_mem = {read_mem_data, read_mem_ref} +overload write_mem = {write_mem_linear, write_mem_ref} + +// Records that an access matches breakpoint n: a hit in pending_dbp when +// Ln or Gn enables it, otherwise a match in open_dbp. LENn = 10b is eight +// bytes in long mode: "Breakpoint conditions for 8-byte memory read/writes +// are supported in all modes" (SDM Vol.3B §20.2.6 p.20-7), "8 byte ... +// (Long mode only; otherwise undefined.)" (APM Vol.2 §13.1.1.4 p.397). +// Outside long mode such a breakpoint matches only within the eight bytes, +// and whether it hits is undefined. +val note_breakpoint_match : (range(0, 3), bool) -> unit +function note_breakpoint_match(n, len8) = { + let long_mode : bool = cur_mode == LongMode | cur_mode == CompatibilityMode; + if DR7[2 * n] == bitone | DR7[2 * n + 1] == bitone then { + if ~(len8) | long_mode | (undefined : bool) then pending_dbp[n] = bitone + } else open_dbp[n] = bitone +} + +// Data breakpoints (SDM Vol.3B §20.2.5, §20.3.1.2): an access matches DRn +// when R/Wn is 01 (writes) or 11 (reads and writes) and any byte of the +// access lies in the LENn-byte range at DRn, whose low address bits LENn +// masks (1, 2, 8 and 4 bytes for 00, 01, 10 and 11). Instruction fetches +// and the processor's own descriptor-table reads do not count. Hits +// accumulate in pending_dbp for the trap that step() raises after the +// instruction. +val note_data_access : (qword, int, bool) -> unit +function note_data_access(lin, nbytes, is_write) = { + foreach (n from 0 to 3) { + let rw : bits(2) = DR7[(17 + 4 * n) .. (16 + 4 * n)]; + let len_field : bits(2) = DR7[(19 + 4 * n) .. (18 + 4 * n)]; + let len : range(1, 8) = match len_field { + 0b00 => 1, 0b01 => 2, 0b10 => 8, _ => 4 + }; + let dr : qword = match n { 0 => DR0, 1 => DR1, 2 => DR2, _ => DR3 }; + let base : int = unsigned(dr & ~(to_bits(64, len - 1))); + let applies : bool = (rw == 0b01 & is_write) | rw == 0b11; + if applies & unsigned(lin) < base + len & base < unsigned(lin) + nbytes then + note_breakpoint_match(n, len_field == 0b10) + } +} + +// I/O breakpoints (SDM Vol.3B §20.2.4, §20.2.5): with CR4.DE set, R/Wn = 10 +// makes DRn an I/O breakpoint; the port address is zero-extended and +// compared with the LENn-byte range at DRn like a data breakpoint. Hits +// join pending_dbp. Without CR4.DE the encoding is undefined and ignored. +val note_io_access : (word, int) -> unit +function note_io_access(port, nbytes) = { + if CR4[3] == bitone then { + foreach (n from 0 to 3) { + let rw : bits(2) = DR7[(17 + 4 * n) .. (16 + 4 * n)]; + let len_field : bits(2) = DR7[(19 + 4 * n) .. (18 + 4 * n)]; + let len : range(1, 8) = match len_field { + 0b00 => 1, 0b01 => 2, 0b10 => 8, _ => 4 + }; + let dr : qword = match n { 0 => DR0, 1 => DR1, 2 => DR2, _ => DR3 }; + let base : int = unsigned(dr & ~(to_bits(64, len - 1))); + let p : int = unsigned(port); + if rw == 0b10 & p < base + len & base < p + nbytes then + note_breakpoint_match(n, len_field == 0b10) + } + } +} + +// Validate every page before a crossing access enters the external byte-copy +// helper. Keep faulting translations in Sail: an external callback into +// translate_addr cannot propagate a Sail exception through every backend's +// foreign-call ABI. In particular, an instruction fetch must not consume +// bytes from a failed translation. SDM Vol.3A §§7.5–7.6 and Interrupt 14: +// #PF preserves the faulting instruction for restart; CR2 identifies its +// failing linear address. Checking all pages also avoids partial MOV stores. +val check_crossing_pages : (qword, int, PTAccess) -> unit +function check_crossing_pages(addr, nbytes, access) = { + let _ = translate_addr(addr, access); + // Walk the following page starts while they lie inside the access. + // (Bitvector arithmetic: the official type checker cannot bound an + // integer offset converted with to_bits here.) + var page : qword = (addr & 0xFFFFFFFFFFFFF000) + 0x0000000000001000; + while unsigned(page - addr) < nbytes do { + let _ = translate_addr(page, access); + page = page + 0x0000000000001000 + } +} + +// Read 'n bits from memory at the given virtual address. +// Goes through address translation when paging is enabled. +// If the access crosses a 4KB page boundary, each byte is translated +// separately to handle non-contiguous physical pages. +function read_mem_linear(n, addr, access) = { + if access == PT_Read then note_data_access(addr, n / 8, false); + let page_offset = unsigned(addr & 0x0000000000000FFF); + if page_offset + n / 8 <= 4096 then { + let paddr = translate_addr(addr, access); + phys_read(n, paddr) + } else { + check_crossing_pages(addr, n / 8, access); + __mem_read_crossing(addr, n, access) + } +} + +// Data-read wrapper: read_mem_linear with PT_Read access. +function read_mem_data(n, addr) = read_mem_linear(addr, PT_Read) + +// Implicit-read wrapper for descriptor-table accesses (GDT/LDT/IDT/TSS). +// SDM Vol.3A §4.6: these reads the CPU itself performs always execute +// at supervisor regardless of the current CPL and bypass the U/S page +// check, so user-mode instructions (e.g. `MOV GS, sel` at CPL=3) can +// load a descriptor out of a kernel-mapped GDT without a #PF. +function read_mem_implicit(n, addr) = read_mem_linear(addr, PT_Implicit) + +// Write 'n bits to memory at the given virtual address. +// Same page-crossing logic as mem_read. +function write_mem_linear(n, addr, data) = { + note_data_access(addr, n / 8, true); + let page_offset = unsigned(addr & 0x0000000000000FFF); + if page_offset + n / 8 <= 4096 then { + let paddr = translate_addr(addr, PT_Write); + phys_write(n, paddr, data) + } else { + check_crossing_pages(addr, n / 8, PT_Write); + __mem_write_crossing(addr, n, data) + } +} + +// Stack operations. +// In long mode, uses RSP directly (SS base is 0). +// In non-long mode, linear address = SS base + ESP/SP (SDM Vol.3A §3.4). +// Stack pointer width depends on SS.B: if SS.B=1 then ESP (32-bit), +// if SS.B=0 then SP (16-bit). In long mode, always RSP (64-bit). + +// Stack address size: 64 in long mode, 32 if SS.B=1, 16 if SS.B=0. +val stack_addr_size : unit -> {16, 32, 64} +function stack_addr_size() = + if cur_mode == LongMode then 64 + else if SegCache[SS].seg_db == 0b1 then 32 + else 16 + +// Stack push helper: decrement SP by the value's byte width, write +// the value at the new SP, then commit the SP update — all as a +// single logical operation. Because SP is written only after the +// store succeeds, a fault during write_mem leaves SP unchanged. +// +// In non-64-bit modes with SS.B=0, SP is 16-bit and wraps at 0xFFFF. +// Without wrapping, SP=2 minus 4 would produce linear address SS.base-2, +// which is below the segment — wrong. It should wrap to SS.base+0xFFFE. +val push : forall 'n, 8 <= 'n & 'n <= 512. (implicit('n), bits('n)) -> unit +val check_seg_limit : (segreg_idx, qword, int) -> unit +function push(n, v) = { + let sas = stack_addr_size(); + let new_sp = v(sas, RSP) - n / 8; + if cur_mode == Virtual8086Mode then check_seg_limit(SS, zero_extend(new_sp), n / 8); + write_mem(get_seg_base(SS) + zero_extend(new_sp), v); + v(RSP) = new_sp +} + +// Stack pop helper: read 'n bits from SP, then advance SP — again +// as a single logical operation. +val pop : forall 'n, 8 <= 'n & 'n <= 512. (implicit('n)) -> bits('n) +function pop(n) = { + let sas = stack_addr_size(); + let sp = v(sas, RSP); + if cur_mode == Virtual8086Mode then check_seg_limit(SS, zero_extend(sp), n / 8); + let x : bits('n) = read_mem(get_seg_base(SS) + zero_extend(sp)); + v(RSP) = sp + n / 8; + x +} + +// PUSH of a segment register: "if the operand size is 64-bits, a +// zero-extended value is pushed on the stack; if the operand size is +// 32-bits, either a zero-extended value is pushed on the stack or the +// segment selector is written on the stack using a 16-bit move", which +// leaves "the upper portion of the stack location unmodified" (SDM Vol.2B +// PUSH p.4-522). The APM says only that the operand size "determines the +// number of bytes pushed" (Vol.3 PUSH). So with a 32-bit operand size the +// upper two bytes of the slot are undefined. +val push_segreg : ({16, 32, 64}, segreg_idx) -> unit +function push_segreg(os, idx) = { + let sel = read_segreg(idx); + match os { + 16 => push(16, sel), + 32 => push(32, (undefined : word) @ sel), + 64 => push(64, zero_extend(sel)), + } +} + +// ========================================================================= +// Segment register loading +// ========================================================================= + +// The TI bit selects the cached LDT or GDT (SDM Vol.3A sections 3.4.2, +// 3.5.1; LLDT caches the LDT descriptor, not its constituent descriptors). +val descriptor_address : word -> qword +function descriptor_address(sel) = + (if sel[2] == 0b1 then LDTR_base else GDTR_base) + zero_extend(sel & 0xFFF8) + +val descriptor_in_bounds : word -> bool +function descriptor_in_bounds(sel) = { + let limit : dword = if sel[2] == 0b1 then LDTR_limit else zero_extend(GDTR_limit); + (sel[2] == 0b0 | LDTR_valid) & unsigned(sel & 0xFFF8) + 7 <= unsigned(limit) +} + +// Load a segment register with a selector, updating both the visible +// selector and the hidden descriptor cache (SDM Vol.3A §3.4.5). +// In real mode: base = selector << 4; limit and attributes are NOT changed. +// This preserves "unreal mode" / "big real mode" behavior where a segment +// retains its large limit from a prior protected-mode descriptor load. +// (SDM Vol.3A §3.4.5: "Every segment register has a 'visible' part and +// a 'hidden' part... in real-address mode, only the base is updated.") +// In protected/compat mode: read 8-byte descriptor from GDT/LDT. +// In long mode: just store the selector (FS/GS base set via MSR). +// Virtual-8086 segment loads ignore descriptor tables, including selectors +// whose low bits look like an RPL or TI. All six caches describe writable +// 64-KByte segments at selector * 16 with DPL 3 (SDM Vol.3B §23.2). +val load_vm86_segment : (segreg_idx, word) -> unit +function load_vm86_segment(idx, selector) = { + write_segreg(idx, selector); + SegCache[idx] = {default_seg_desc_cache() with + seg_base = zero_extend(selector) << 4, seg_dpl = 3} +} + +// SDM Vol.3A 3.4.5.1: every load of a code/data selector sets A in +// its descriptor. This is an implicit supervisor write, subject to WP; +// do it before committing the visible selector or hidden cache. +val access_segment_descriptor : (word, SegDescCache) -> SegDescCache +function access_segment_descriptor(selector, desc) = { + if selector[15..2] != zeros() & desc.seg_s == 0b1 & desc.seg_type[0] == 0b0 then { + let addr = descriptor_address(selector) + 5; + let access_byte : byte = read_mem_implicit(addr); + let paddr = translate_addr(addr, PT_ImplicitWrite); + phys_write(paddr, access_byte | 0x01); + {desc with seg_type = desc.seg_type | 0x1} + } else desc +} + +val load_segment_register : (segreg_idx, word) -> unit +function load_segment_register(idx, selector) = { + // Do memory reads (GDT lookup) before writing the segment register, + // so that a fault during the GDT read leaves the segment unchanged. + match cur_mode { + Virtual8086Mode => load_vm86_segment(idx, selector), + RealMode => { + write_segreg(idx, selector); + SegCache[idx].seg_base = zero_extend(selector) << 4 + }, + _ => { + // SDM §3.4.4: In all modes (including 64-bit), segment loads read the + // GDT/LDT and populate the hidden descriptor cache. For DS/ES/SS in + // 64-bit mode, the cached values are ignored during address calculation + // (handled by get_seg_base). For FS/GS, the 32-bit base is loaded + // (upper bits cleared); WRMSR can then set the full 64-bit base. + if selector[2] == 0b1 & ~(LDTR_valid) then + throw Fault(EXN_GP, zero_extend(selector & 0xFFFC)); + let desc_addr = descriptor_address(selector); + // Implicit supervisor access: the CPU's own GDT/LDT reads bypass + // U/S so a CPL=3 `MOV GS, sel` can load a descriptor out of a + // kernel-mapped GDT. + let desc_lo : dword = read_mem_implicit(desc_addr); + let desc_hi : dword = read_mem_implicit(desc_addr + 4); + let desc = access_segment_descriptor(selector, parse_seg_descriptor(desc_lo, desc_hi)); + write_segreg(idx, selector); + SegCache[idx] = desc + }, + } +} + +// Error code of a fault attributed to a segment selector (SDM Vol.3A §7.13, +// Figure 7-7): the selector's index and TI bit; bits 1:0 are the IDT and +// EXT flags, both clear for a selector referenced by an instruction. +val selector_error_code : word -> dword +function selector_error_code(selector) = zero_extend(selector & 0xFFFC) + +// ========================================================================= +// Segment limit checking (SDM Vol.3A §6.3) +// ========================================================================= + +// Check that an access at the given offset with the given size is within +// the segment limit. Raises #GP(0) for non-SS segments, #SS(0) for SS. +// Only checks in non-long mode; 64-bit mode disables limit checking for +// CS/DS/ES/SS (SDM Vol.3A §6.3.1). +// For expand-up segments: offset + size - 1 <= effective_limit. +// For expand-down data segments: limit < offset, and the last byte must +// not exceed FFFFH (B=0) or FFFFFFFFH (B=1), per SDM Vol.3A section 6.3. +function check_seg_limit(seg, offset, access_size) = { + if cur_mode != LongMode then { + let desc = SegCache[seg]; + let limit : dword = desc.seg_limit; + let expand_down = desc.seg_s == 0b1 & desc.seg_type[3..2] == 0b01; + let last = unsigned(offset) + access_size - 1; + // Written with a plain boolean variable and an integer bound: the + // official type checker cannot unify the refinement types of the + // two branches otherwise, and 0xFFFFFFFF/0xFFFF differ in width. + var invalid : bool = false; + if expand_down then { + let upper : int = if desc.seg_db == 0b1 then 4294967295 else 65535; + invalid = unsigned(offset) <= unsigned(limit) | last > upper + } else { + invalid = last > unsigned(limit) + }; + if invalid then { + if seg == SS then throw Fault(EXN_SS, 0x00000000) + else throw Fault(EXN_GP, 0x00000000) + } + } +} + +// ========================================================================= +// Segment-aware memory access (SDM Vol.3A §3.4) +// +// Translates a logical address (segment, offset) to a linear address: +// 1. Check offset against segment limit (§6.3) +// 2. Linear address = segment base + offset +// Then passes the linear address through paging (translate_addr). +// ========================================================================= + +// Translate a logical (segment, offset) pair to a linear address, +// performing segment limit checking with the given access size. +// Also applies the RIP-relative fixup if pending. +// +// Linear address width (SDM Vol.1 §3.3.3): +// Long mode: 64-bit canonical linear addresses. +// Compatibility: 32-bit linear address space — (seg_base + offset) +// is computed mod 2^32. This matters for FS/GS +// accesses with negative 32-bit displacements: +// glibc's 32-bit TLS code reads %gs:-44 expecting +// the 32-bit wrap (GS.base + 0xFFFFFFD4 = +// GS.base-44 mod 2^32). Without the truncation the +// 64-bit sum overflows past 4GB into unmapped +// territory and every TLS load #PFs. +// Real/protected: 32-bit linear — same truncation. +val seg_linear : (MemRef, int) -> qword +function seg_linear(m, access_size) = { + // Apply RIP-relative fixup if pending (only in LongMode, where + // mod=00 rm=101 means [RIP+disp32]) + let offset = if rip_rel_pending then decode_pos + rip_rel_disp else m.addr; + check_seg_limit(m.seg, offset, access_size); + let linear : qword = offset + get_seg_base(m.seg); + if cur_mode == LongMode then { + // A data access through a non-canonical linear address is #GP(0), + // or #SS(0) when the SS segment is used (SDM Vol.1 §3.3.7.1; the + // "64-Bit Mode Exceptions" of every memory instruction). Canonical: + // bits 63:47 all equal, or 63:56 with 5-level paging (CR4.LA57). + let high : bits(17) = if CR4[12] == 0b1 then sign_extend(linear[63..56]) else linear[63..47]; + if high != zeros() & high != ones() then { + if m.seg == SS then raise_SS0() else raise_GP0() + }; + linear + } else { + zero_extend(linear[31..0]) + } +} + +// Segmented memory read/write via MemRef (n is in bits; seg_linear takes bytes). +function read_mem_ref(n, m) = read_mem_linear(seg_linear(m, n / 8), PT_Read) +function write_mem_ref(n, m, v) = write_mem_linear(seg_linear(m, n / 8), v) + +// Read a far pointer (selector:offset) from memory. +// Memory layout: [offset (os bits)][selector (16 bits)]. +// Returns (zero-extended offset, selector). +val read_far_pointer : forall 'os, 'os in {16, 32, 64}. (int('os), MemRef) -> (qword, word) +function read_far_pointer(os, m) = { + let d : bits('os + 16) = read_mem(m); + (zero_extend(d['os - 1 .. 0]), d['os + 15 .. 'os]) +} + +// Pop a far pointer (selector:offset) from the stack. +// Each element occupies a full operand-size slot, so the frame is 2*os bits. +// This differs from read_far_pointer (compact os+16 layout for memory +// operands) because CALL FAR pushes each element as a separate os-wide +// push, and RETF pops them the same way. +val pop_far_pointer : forall 'os, 'os in {16, 32, 64}. int('os) -> (qword, word) +function pop_far_pointer(os) = { + let offset = pop(os); + let selector = pop(os); + (zero_extend(offset), selector[15..0]) +} + +// ========================================================================= +// Protected-mode far transfer helpers (SDM Vol.2A JMP/CALL — Protected Mode) +// ========================================================================= + +// Read a segment descriptor from the GDT or cached LDT. +// Returns the parsed descriptor cache entry. +// Raises #GP(selector) if the selector index is beyond the table limit. +val read_descriptor : word -> SegDescCache +function read_descriptor(selector) = { + // Descriptor must fit within the table limit (offset + 7 <= limit) + if ~(descriptor_in_bounds(selector)) then { + throw Fault(EXN_GP, selector_error_code(selector)) + }; + // Implicit supervisor access (SDM Vol.3A §4.6): descriptor-table reads + // bypass U/S regardless of CPL. + let desc_addr = descriptor_address(selector); + let desc_lo : dword = read_mem_implicit(desc_addr); + let desc_hi : dword = read_mem_implicit(desc_addr + 4); + parse_seg_descriptor(desc_lo, desc_hi) +} + +// Load SS, DS, ES, FS or GS on behalf of MOV Sreg, POP Sreg and the LxS +// instructions, with the checks of the SDM's Operation sections (Vol.2B +// MOV, "Loading a segment register while in protected mode results in +// special checks and actions"; Vol.2B POP; Vol.2A LDS/LES/LFS/LGS/LSS): +// SS: null selector -> #GP(0); index beyond the table limit, RPL != CPL, +// not a writable data segment, or DPL != CPL -> #GP(selector); +// not present -> #SS(selector). In 64-bit mode a null SS loads at +// CPL < 3. The SDM also faults when its RPL is not CPL ("#GP(0) If +// an attempt is made to load SS register with NULL segment selector +// when CPL < 3 and CPL ≠ RPL", MOV, 64-Bit Mode Exceptions), a fault +// of one manual only, which the model does not raise: the APM has no +// RPL condition, "A #GP occurs if software attempts to ... load the +// SS register with a null selector in non 64-bit mode or at CPL 3" +// (Vol.2 §4.5.1, p.79; Vol.3 MOV p.242 and LSS p.217, "in +// non-64-bit mode or while CPL = 3"). +// DS/ES/FS/GS with a non-null selector: index beyond the table limit, +// neither a data nor a readable code segment, or a data or +// nonconforming code segment with RPL > DPL or CPL > DPL +// -> #GP(selector); not present -> #NP(selector). +// DS/ES/FS/GS with a null selector: loaded without checks. +// Real mode loads the base from the selector. CS is never loaded here: +// far transfers have their own checks. +val load_data_segment_register : (segreg_idx, word) -> unit +function load_data_segment_register(idx, selector) = { + if cur_mode == RealMode | cur_mode == Virtual8086Mode then load_segment_register(idx, selector) + else { + let rpl : range(0, 3) = unsigned(selector[1..0]); + let null_selector : bool = selector[15..2] == zeros(); + if idx == SS then { + if null_selector then { + if cur_mode == LongMode & cur_cpl < 3 then + load_segment_register(idx, selector) + else + raise_GP0() + } else { + let desc = read_descriptor(selector); + let writable_data : bool = desc.seg_s == 0b1 & desc.seg_type[3] == 0b0 + & desc.seg_type[1] == 0b1; + if rpl != cur_cpl | ~(writable_data) | desc.seg_dpl != cur_cpl then { + throw Fault(EXN_GP, selector_error_code(selector)) + }; + if desc.seg_present == 0b0 then { + throw Fault(EXN_SS, selector_error_code(selector)) + }; + load_segment_register(idx, selector) + } + } else if null_selector then { + load_segment_register(idx, selector) + } else { + let desc = read_descriptor(selector); + let data : bool = desc.seg_type[3] == 0b0; + let readable_code : bool = desc.seg_type[3] == 0b1 & desc.seg_type[1] == 0b1; + let conforming_code : bool = desc.seg_type[3] == 0b1 & desc.seg_type[2] == 0b1; + if desc.seg_s == 0b0 | ~(data | readable_code) then { + throw Fault(EXN_GP, selector_error_code(selector)) + }; + if ~(conforming_code) & (rpl > desc.seg_dpl | cur_cpl > desc.seg_dpl) then { + throw Fault(EXN_GP, selector_error_code(selector)) + }; + if desc.seg_present == 0b0 then { + throw Fault(EXN_NP, selector_error_code(selector)) + }; + load_segment_register(idx, selector) + } + } +} + +// Validate and load CS for a far JMP in protected mode (same-privilege, +// code segment only — no call gates or task switches). +// SDM Vol.2A JMP — Protected Mode, non-64-bit: +// 1. Selector must not be null (#GP(0)) +// 2. Selector index must be within GDT/LDT limits (#GP(selector)) +// 3. Descriptor must be a code segment (S=1, type bit 3 set) (#GP(selector)) +// 4. Non-conforming: DPL = CPL and RPL <= CPL (#GP(selector)) +// Conforming: DPL <= CPL (#GP(selector)) +// 5. Segment must be present (#NP(selector)) +// 6. Load CS, set RPL = CPL +val validate_far_jmp_cs : word -> SegDescCache +function validate_far_jmp_cs(selector) = { + // Null selector check + if selector[15..2] == zeros() then { + throw Fault(EXN_GP, 0x00000000) + }; + + let desc = read_descriptor(selector); + + // Must be a code/data segment (S=1), not a system descriptor + if desc.seg_s == 0b0 then { + throw Fault(EXN_GP, selector_error_code(selector)) + }; + // Must be a code segment (type bit 3 set) + if desc.seg_type[3] == 0b0 then { + throw Fault(EXN_GP, selector_error_code(selector)) + }; + + let rpl : range(0, 3) = unsigned(selector[1..0]); + let conforming : bool = desc.seg_type[2] == 0b1; + + if conforming then { + // Conforming: DPL must be <= CPL + if desc.seg_dpl > cur_cpl then { + throw Fault(EXN_GP, selector_error_code(selector)) + } + } else { + // Non-conforming: DPL must equal CPL, RPL must be <= CPL + if desc.seg_dpl != cur_cpl then { + throw Fault(EXN_GP, selector_error_code(selector)) + }; + if rpl > cur_cpl then { + throw Fault(EXN_GP, selector_error_code(selector)) + } + }; + + // Segment must be present + if desc.seg_present == 0b0 then { + throw Fault(EXN_NP, selector_error_code(selector)) + }; + + desc +} + +// Complete a far transfer in protected mode: load CS from a validated +// descriptor, update execution mode, and set RIP. +// Shared by exec_far_jmp and exec_far_call. +val finish_far_transfer : (SegDescCache, word, qword, {16, 32, 64}) -> unit +function finish_far_transfer(desc, selector, offset, os) = { + let desc = access_segment_descriptor(selector, desc); + let adj_sel : word = (selector & 0xFFFC) | zero_extend(to_bits(2, cur_cpl)); + write_segreg(CS, adj_sel); + SegCache[CS] = desc; + if EFER[10] == 0b1 then { + set_mode(if desc.seg_l == 0b1 then LongMode else CompatibilityMode) + }; + next_rip = Some(match os { + 16 => zero_extend(offset[15..0]), + 32 => zero_extend(offset[31..0]), + _ => offset, + }) +} + +// Execute far JMP: load CS:RIP from selector:offset. +val exec_far_jmp : (word, qword, {16, 32, 64}) -> unit +function exec_far_jmp(selector, offset, os) = match cur_mode { + m if m == RealMode | m == Virtual8086Mode => { + if cur_mode == Virtual8086Mode & os == 32 & unsigned(offset[31..0]) > 65535 then raise_GP0(); + load_segment_register(CS, selector); + next_rip = Some(match os { + 16 => zero_extend(offset[15..0]), + _ => zero_extend(offset[31..0]), + }) + }, + _ => { + if selector[15..2] == zeros() then raise_GP0(); + let desc = read_descriptor(selector); + if EFER[10] == 0b0 & desc.seg_s == 0b0 & + (desc.seg_type == 0x4 | desc.seg_type == 0xC) then { + // SDM Vol.2A JMP, CALL-GATE: unlike CALL, JMP cannot enter a + // more-privileged nonconforming segment and never changes stacks. + let err = selector_error_code(selector); + if desc.seg_dpl < cur_cpl | unsigned(selector[1..0]) > desc.seg_dpl then raise_GP(err); + if desc.seg_present == 0b0 then throw Fault(EXN_NP, err); + let gate : qword = read_mem_implicit(descriptor_address(selector)); + let target_sel : word = gate[31..16]; + if target_sel[15..2] == zeros() then raise_GP0(); + let target = read_descriptor(target_sel); + let target_err = selector_error_code(target_sel); + if target.seg_s == 0b0 | target.seg_type[3] == 0b0 | + (target.seg_type[2] == 0b1 & target.seg_dpl > cur_cpl) | + (target.seg_type[2] == 0b0 & target.seg_dpl != cur_cpl) then raise_GP(target_err); + if target.seg_present == 0b0 then throw Fault(EXN_NP, target_err); + let width : {16, 32} = if desc.seg_type == 0x4 then 16 else 32; + let dest : qword = if width == 16 then zero_extend(gate[15..0]) + else zero_extend(gate[63..48] @ gate[15..0]); + if unsigned(dest) > unsigned(target.seg_limit) then raise_GP0(); + finish_far_transfer(target, target_sel, dest, width) + } else finish_far_transfer(validate_far_jmp_cs(selector), selector, offset, os) + }, +} + +// Execute far CALL: push CS:RIP, then load CS:RIP from selector:offset. +// In protected mode, the descriptor is validated before pushing so that +// a fault does not modify the stack. +// Stack selection for a legacy inter-privilege transfer. SDM Vol.2A CALL, +// MORE-PRIVILEGE; Vol.3A section 10.6, Figure 10-10 (16-bit TSS). +val read_privilege_stack : cpl_t -> (qword, word) +function read_privilege_stack(level) = { + let is32 : bool = TR_type[3] == 0b1; + let off : qword = to_bits(64, if is32 then level * 8 + 4 else level * 4 + 2); + let last : int = if is32 then 5 else 3; + if unsigned(off) + last > unsigned(TR_limit) then + throw Fault(EXN_TS, selector_error_code(TR)); + if is32 then { + let sp : dword = read_mem_implicit(TR_base + off); + let ss : word = read_mem_implicit(TR_base + off + 4); + (zero_extend(sp), ss) + } else { + let sp : word = read_mem_implicit(TR_base + off); + let ss : word = read_mem_implicit(TR_base + off + 2); + (zero_extend(sp), ss) + } +} + +val validate_privilege_stack : (word, cpl_t) -> SegDescCache +function validate_privilege_stack(sel, level) = { + let err = selector_error_code(sel); + if sel[15..2] == zeros() then throw Fault(EXN_TS, err); + let desc : SegDescCache = try { read_descriptor(sel) } catch { + Fault(v, e) => { + if v == EXN_GP then throw Fault(EXN_TS, err) else throw Fault(v, e); + exit() + }, + e => throw e, + }; + if unsigned(sel[1..0]) != level | desc.seg_dpl != level | + desc.seg_s == 0b0 | desc.seg_type[3] == 0b1 | desc.seg_type[1] == 0b0 then + throw Fault(EXN_TS, err); + if desc.seg_present == 0b0 then throw Fault(EXN_SS, err); + desc +} + +// Write a checked legacy transfer frame without changing segment registers. +// The complete destination range is validated before the first write. +val write_legacy_frame : (SegDescCache, qword, vector(35, dword), range(1, 35), {16, 32}, cpl_t, dword) -> qword +function write_legacy_frame(desc, sp, frame, count, width, level, err) = { + let sas : {16, 32} = if desc.seg_db == 0b1 then 32 else 16; + let top = unsigned(sp[sas - 1 .. 0]); + let size = count * (width / 8); + let bottom = top - size; + let expand_down : bool = desc.seg_type[2] == 0b1; + if bottom < 0 | (expand_down & bottom <= unsigned(desc.seg_limit)) | + (~(expand_down) & top - 1 > unsigned(desc.seg_limit)) then throw Fault(EXN_SS, err); + let addr = desc.seg_base + to_bits(64, bottom); + let old_cpl = cur_cpl; + cur_cpl = level; + try { + foreach (i from 0 to size - 1) { + let _ = translate_addr(addr + to_bits(64, i), PT_Write); + () + }; + foreach (i from 0 to count - 1) { + write_mem_linear(width, addr + to_bits(64, i * (width / 8)), frame[i][width - 1 .. 0]) + } + } catch { e => { cur_cpl = old_cpl; throw e } }; + cur_cpl = old_cpl; + to_bits(64, bottom) +} + +// Legacy 16/32-bit call gates (SDM Vol.2A CALL, CALL-GATE, +// MORE-PRIVILEGE and SAME-PRIVILEGE). The operand's offset is ignored. +val exec_legacy_call_gate : (word, SegDescCache) -> unit +function exec_legacy_call_gate(selector, gate_desc) = { + let err = selector_error_code(selector); + if gate_desc.seg_dpl < cur_cpl | unsigned(selector[1..0]) > gate_desc.seg_dpl then raise_GP(err); + if gate_desc.seg_present == 0b0 then throw Fault(EXN_NP, err); + let gate : qword = read_mem_implicit(descriptor_address(selector)); + let target_sel : word = gate[31..16]; + if target_sel[15..2] == zeros() then raise_GP0(); + let target = read_descriptor(target_sel); + if target.seg_s == 0b0 | target.seg_type[3] == 0b0 | target.seg_dpl > cur_cpl then + raise_GP(selector_error_code(target_sel)); + if target.seg_present == 0b0 then throw Fault(EXN_NP, selector_error_code(target_sel)); + let width : {16, 32} = if gate_desc.seg_type == 0x4 then 16 else 32; + let offset : qword = if width == 16 then zero_extend(gate[15..0]) else zero_extend(gate[63..48] @ gate[15..0]); + if unsigned(offset) > unsigned(target.seg_limit) then raise_GP0(); + let inward : bool = target.seg_type[2] == 0b0 & target.seg_dpl < cur_cpl; + let level : cpl_t = if inward then target.seg_dpl else cur_cpl; + let old_sp : qword = zero_extend(v(stack_addr_size(), RSP)); + var stack_desc = SegCache[SS]; + var stack_sel = read_segreg(SS); + var stack_sp = old_sp; + let params : range(0, 31) = if inward then unsigned(gate[36..32]) else 0; + var frame : vector(35, dword) = [ + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 + ]; + frame[0] = decode_pos[31..0]; + frame[1] = zero_extend(read_segreg(CS)); + if inward then { + let (new_sp, new_ss) = read_privilege_stack(level); + stack_desc = validate_privilege_stack(new_ss, level); + stack_sel = new_ss; + stack_sp = new_sp; + foreach (i from 0 to params - 1) { + let src : MemRef = struct { seg = SS, addr = old_sp + to_bits(64, i * (width / 8)) }; + frame[i + 2] = zero_extend(read_mem(width, src)) + }; + frame[params + 2] = old_sp[31..0]; + frame[params + 3] = zero_extend(read_segreg(SS)) + }; + let count : range(1, 35) = if inward then params + 4 else 2; + let new_sp = write_legacy_frame(stack_desc, stack_sp, frame, count, width, level, + if inward then selector_error_code(stack_sel) else 0x00000000); + let accessed_target = access_segment_descriptor(target_sel, target); + if inward then { + let accessed_stack = access_segment_descriptor(stack_sel, stack_desc); + write_segreg(SS, stack_sel); + SegCache[SS] = accessed_stack; + v(32, RSP) = new_sp[31..0] + } else { + let sas = stack_addr_size(); + v(RSP) = new_sp[sas - 1 .. 0] + }; + cur_cpl = level; + finish_far_transfer(accessed_target, target_sel, offset, width) +} + +val exec_far_call : (word, qword, {16, 32, 64}) -> unit +function exec_far_call(selector, offset, os) = match cur_mode { + m if m == RealMode | m == Virtual8086Mode => { + if cur_mode == Virtual8086Mode & os == 32 & unsigned(offset[31..0]) > 65535 then raise_GP0(); + match os { + 16 => push(32, read_segreg(CS) @ decode_pos[15..0]), + _ => push(64, zero_extend(32, read_segreg(CS)) @ decode_pos[31..0]), + }; + exec_far_jmp(selector, offset, os) + }, + _ => { + if cur_mode == ProtectedMode & selector[15..2] != zeros() then { + let gate = read_descriptor(selector); + if gate.seg_s == 0b0 & (gate.seg_type == 0x4 | gate.seg_type == 0xC) then { + exec_legacy_call_gate(selector, gate); + return () + } + }; + let desc = validate_far_jmp_cs(selector); + match os { + 16 => push(32, read_segreg(CS) @ decode_pos[15..0]), + 32 => push(64, zero_extend(32, read_segreg(CS)) @ decode_pos[31..0]), + 64 => push(128, zero_extend(64, read_segreg(CS)) @ decode_pos), + }; + finish_far_transfer(desc, selector, offset, os) + }, +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail new file mode 100644 index 000000000..27e816d91 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail @@ -0,0 +1,418 @@ +// x86-64 — Operand types, decode helpers, and operand accessors + +// ========================================================================= +// Prefix state accumulated during prefix scanning +// ========================================================================= + +struct Prefixes = { + has_lock : bool, + has_repne : bool, // F2 + has_rep : bool, // F3 + seg_override : option(segreg_idx), + has_opsize : bool, // 66 + has_adsize : bit, // 67 + rex_w : bool, + rex_r : bit, + rex_x : bit, + rex_b : bit, + has_rex : bool, // any REX present (changes byte reg encoding) + // VEX prefix fields + vex_present : bool, // VEX prefix was decoded + vex_l : bool, // vector length: false=128, true=256 + vex_vvvv : simd_idx, // extra register operand (already complemented) + vex_w : bool, // VEX.W (like REX.W for some instructions) + // EVEX prefix fields + evex_present : bool, // EVEX prefix was decoded + evex_ll : range(0, 3),// vector length: 0=128, 1=256, 2=512 + evex_vvvvv : simd_idx,// 5-bit source register (vvvv + V') + evex_aaa : kreg_idx, // opmask register index (k0-k7) + evex_z : bit, // zeroing (1) vs merging (0) + evex_b : bool, // broadcast / rounding control + evex_rr : bit, // R' (extends reg to 5 bits) +} + +val default_prefixes : unit -> Prefixes +function default_prefixes() = struct { + has_lock = false, + has_repne = false, + has_rep = false, + seg_override = None(), + has_opsize = false, + has_adsize = 0b0, + rex_w = false, + rex_r = 0b0, + rex_x = 0b0, + rex_b = 0b0, + has_rex = false, + vex_present = false, + vex_l = false, + vex_vvvv = 0, + vex_w = false, + evex_present = false, + evex_ll = 0, + evex_vvvvv = 0, + evex_aaa = 0, + evex_z = 0b0, + evex_b = false, + evex_rr = 0b0, +} + +// ========================================================================= +// Resolved ModR/M operand — either a register or memory address +// ========================================================================= + +// A resolved ModR/M operand: either a register index or a logical memory +// address (segment + effective address/offset). Per SDM Vol.3A §3.4, the +// processor translates a logical address to a linear address by: +// 1. checking the offset against the segment limit (§6.3) +// 2. adding the segment base to the offset +// Both steps happen at memory-access time, not during decode. +union RM = { + RM_reg : GPRRef, + RM_mem : MemRef, +} + +// SIMD register-or-memory operand (XMM/YMM/ZMM). +// Unlike RM (which carries a GPRRef), XRM carries a simd_idx directly. +union XRM = { + XRM_reg : simd_idx, + XRM_mem : MemRef, +} + +// Extract simd_idx from XRM, raising #UD if it's a memory operand. +// Use for register-only SIMD instructions. +val xrm_reg : XRM -> simd_idx +function xrm_reg(xm) = match xm { + XRM_reg(xi) => xi, + XRM_mem(_) => { raise_UD(); 0 }, +} + +// RIP-relative fixup for effective addresses. When rip_rel_pending is true, +// the offset was computed with an intermediate decode_pos (before trailing +// imm bytes were fetched). seg_linear() handles this automatically, so +// instruction code rarely needs to call this directly. +val fixup_addr : qword -> qword +function fixup_addr(addr) = + if rip_rel_pending then decode_pos + rip_rel_disp + else addr + +// ========================================================================= +// ALU operation codes (for the regular 00-3F pattern + Group 1) +// ========================================================================= + +enum ALUOp = { + ALU_ADD, + ALU_OR, + ALU_ADC, + ALU_SBB, + ALU_AND, + ALU_SUB, + ALU_XOR, + ALU_CMP, +} + +// ========================================================================= +// Shift/rotate operation codes (for Group 2) +// ========================================================================= + +// ========================================================================= +// Mandatory prefix classification (for 2-byte+ opcodes) +// ========================================================================= + +enum MandatoryPrefix = { + MP_NONE, + MP_66, + MP_F2, + MP_F3, +} + +// ========================================================================= +// Decode state — mutable position tracking during fetch +// (decode_pos is defined in regs.sail so instruction implementations +// can access it for control-flow instructions) +// ========================================================================= + +// Fetch n bytes from the instruction stream. Returns bits(8*n). +// Uses PT_Execute access type for paging permission checks (NX bit). +// x86 instructions are at most 15 bytes; raises #GP(0) if exceeded. +val fetch : forall 'n, 'n > 0. int('n) -> bits(8 * 'n) +function fetch(n) = { + if unsigned(decode_pos) - unsigned(insn_start) + n > 15 then { + throw(Fault(EXN_GP, 0x00000000)) + }; + if cur_mode == Virtual8086Mode then check_seg_limit(CS, decode_pos, n); + let linear : qword = decode_pos + get_seg_base(CS); + // "Attempting to execute code ... at a non-canonical RIP" is #GP(0) + // (APM Vol.2 §8.2.14, Table 8-6), where an AMD SYSRET can leave RIP. + // The control transfers check their targets themselves. + if cur_mode == LongMode then { + let high : bits(17) = if CR4[12] == 0b1 then sign_extend(linear[63..56]) else linear[63..47]; + if high != zeros() & high != ones() then throw(Fault(EXN_GP, 0x00000000)) + }; + // SDM Vol.3A sections 3.4 and 5.1.1: outside 64-bit mode the + // segment-base addition produces a 32-bit linear address. Instruction + // fetch needs the same truncation as segmented data accesses. + let addr = if cur_mode == LongMode then linear else zero_extend(linear[31..0]); + let result : bits(8 * 'n) = read_mem_linear(addr, PT_Execute); + decode_pos = decode_pos + n; + result +} + +// The next instruction byte, left in the stream: the ModR/M byte of an +// opcode whose validity depends on it, checked before the instruction +// decodes its operands (check_legacy_simd). +val peek_modrm : unit -> byte +function peek_modrm() = { + let modrm : byte = fetch(1); + decode_pos = decode_pos - 1; + modrm +} + +// The byte after the ModR/M byte, left in the stream like it: the SIB byte +// of a VSIB operand, whose registers decide whether a gather is valid +// (vex_check_form, evex_check_form). +val peek_sib : unit -> byte +function peek_sib() = { + let _ : byte = fetch(1); + let sib : byte = fetch(1); + decode_pos = decode_pos - 2; + sib +} + +// ========================================================================= +// Operand size determination +// ========================================================================= + +// Standard operand size (SDM Vol.1 §3.6). +// LongMode: default OS32, REX.W → OS64, 66h → OS16. +// Non-LongMode, CS.D=1: default OS32, 66h → OS16. +// Non-LongMode, CS.D=0: default OS16, 66h → OS32. +val opsize : Prefixes -> {16, 32, 64} +function opsize(pfx) = + if pfx.rex_w then { + 64 + } else if cur_mode == LongMode then { + if pfx.has_opsize then 16 else 32 + } else if get_cs_db() == 0b1 then { + if pfx.has_opsize then 16 else 32 + } else { + if pfx.has_opsize then 32 else 16 + } + +// Operand size for instructions that default to 64-bit (PUSH, POP). +// LongMode: default OS64, 66h → OS16 (OS32 not encodable), REX.W → OS64 +// with or without 66h ("setting REX.W takes precedence over the operand- +// size prefix (66H) when both are used", SDM Vol.1 §3.6.1 p.3-19; "if a +// 66H prefix is used with prefix (REX.W = 1), 66H is ignored", Vol.2A +// §2.2.1.2 p.2-8). +// Non-LongMode, CS.D=1: default OS32, 66h → OS16. +// Non-LongMode, CS.D=0: default OS16, 66h → OS32. +val opsize_default64 : Prefixes -> {16, 32, 64} +function opsize_default64(pfx) = + if pfx.rex_w then { + 64 + } else if cur_mode == LongMode then { + if pfx.has_opsize then 16 else 64 + } else if get_cs_db() == 0b1 then { + if pfx.has_opsize then 16 else 32 + } else { + if pfx.has_opsize then 32 else 16 + } + +// Operand size of the near branches: CALL, RET, Jcc, JrCXZ, JMP, LOOP and +// LOOPcc. It sets the truncation of the new instruction pointer, the size +// of CALL's push and RET's pop, and the indirect-branch operand size. +// Outside 64-bit mode it is the operand size (CS.D and 66h). In 64-bit +// mode the manuals give 66h different meanings, so the model follows the +// vendor register (regs.sail): "all of the above actions are forced to 64 +// bits regardless of operand size prefixes (operand size prefixes are +// silently ignored)" (SDM Vol.1 §6.4.7 p.6-12; "f64", Vol.2D Table A-1), +// where on AMD "The operand size for near branches can be overridden to +// 16 bits in 64-bit mode" (APM Vol.2 §2.5.6 p.32; Vol.1 §3.7.9.1 Table +// 3-9 p.90; Vol.3 Table B-1, note 6), and REX.W, which takes precedence +// over 66h (Vol.3 §1.2.2 p.8), keeps it at 64. +val opsize_forced64 : Prefixes -> {16, 32, 64} +function opsize_forced64(pfx) = + if cur_mode == LongMode then { + if pfx.has_opsize & ~(pfx.rex_w) & vendor == Vendor_AMD then 16 else 64 + } else if get_cs_db() == 0b1 then { + if pfx.has_opsize then 16 else 32 + } else { + if pfx.has_opsize then 32 else 16 + } + +// Displacement size of CALL rel, JMP rel and Jcc rel (E8, E9, 0F 80-8F): +// the operand size outside 64-bit mode, and in 64-bit mode 32 bits ("the +// displacement field for relative branches is still limited to 32 bits", +// SDM Vol.1 §6.4.7 p.6-12), but 16 bits where 66h makes the operand size +// 16 on AMD (opsize_forced64): "CALL rel16off E8 iw", "JMP rel16off E9 +// cw", "JO rel16off 0F 80 cw" (APM Vol.3 CALL (Near), JMP (Near), Jcc). +val opsize_rel : Prefixes -> {16, 32} +function opsize_rel(pfx) = if opsize_forced64(pfx) == 16 then 16 else 32 + +// ========================================================================= +// Register index helpers (extending 3-bit fields with REX bits) +// ========================================================================= + +// Decode the ModR/M reg field (bits 5:3) with REX.R. +val modrm_reg : (byte, Prefixes) -> GPRRef +function modrm_reg(modrm, pfx) = + struct { gpr_idx = unsigned(pfx.rex_r @ modrm[5..3]), has_rex = pfx.has_rex } + +// Decode the ModR/M r/m field (bits 2:0) with REX.B. +val modrm_rm_reg : (byte, Prefixes) -> gpr_idx +function modrm_rm_reg(modrm, pfx) = + unsigned(pfx.rex_b @ modrm[2..0]) + +// ========================================================================= +// Generic operand read/write through RM union +// ========================================================================= + +val read_rm_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM) -> bits('os) +function read_rm_val(os, rm) = + match rm { + RM_reg(r) => read_gpr_ref(r), + RM_mem(m) => read_mem(m), + } + +val write_rm_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM, bits('os)) -> unit +function write_rm_val(os, rm, v) = + match rm { + RM_reg(r) => write_gpr_ref(r) = v, + RM_mem(m) => write_mem(m,v), + } + +// The memory destination of a read-modify-write instruction (ADD, ADC, +// SUB, SBB, AND, OR, XOR, INC, DEC, NOT, NEG, the shifts and rotates, +// SHLD/SHRD, BTS/BTR/BTC, XCHG, XADD, CMPXCHG, CMPXCHG8B/16B) is read with +// write intent: the read already needs write access to every page of the +// operand. The W/R bit of a page fault is 1 "if the access causing the +// page-fault exception was a write" (SDM Vol.3A §5.7 p.5-39; APM Vol.2 +// §8.4.2 p.264), and neither manual says whether the read of a +// read-modify-write is one. The model reports it as a write, as the SDM +// does for EPT: "An EPT violation that occurs during as a result of +// execution of a read-modify-write operation sets bit 1 (data write)" +// (Vol.3C §30.2.1 p.30-8). CMPXCHG writes in any case: "the destination +// operand receives a write cycle without regard to the result of the +// comparison" (SDM Vol.2A CMPXCHG p.3-194), "CMPXCHG always does a +// read-modify-write on the memory operand" (APM Vol.3 CMPXCHG p.167). Of +// a shift or rotate by 0 the manuals give only the flags ("If the count is +// 0, the flags are not affected", SDM Vol.2B SAL/SAR/SHL/SHR p.4-606; "If +// the shift count is 0, no flags are modified", APM Vol.3 SAL p.325), not +// whether it accesses its memory operand; in the model it is an RMW like +// any other count. +val read_rmw_mem : forall 'n, 'n > 0. (implicit('n), MemRef) -> bits('n) +function read_rmw_mem(n, m) = read_mem_linear(seg_linear(m, n / 8), PT_Write) + +val read_rmw : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM) -> bits('os) +function read_rmw(os, rm) = + match rm { + RM_reg(r) => read_gpr_ref(r), + RM_mem(m) => read_rmw_mem(m), + } + +// Memory-only RM read/write: raise #UD if register operand. +// Size parameter 'n is in bits. +val read_mem_rm : forall 'n, 'n > 0. (implicit('n), RM) -> bits('n) +function read_mem_rm(n, rm) = + match rm { + RM_reg(_) => raise_UD(), + RM_mem(m) => read_mem(m), + } + +val write_mem_rm : forall 'n, 'n > 0. (implicit('n), RM, bits('n)) -> unit +function write_mem_rm(n, rm, v) = + match rm { + RM_reg(_) => raise_UD(), + RM_mem(m) => write_mem(m,v), + } + +// Register-only RM read/write: raise #UD if memory operand. +val read_reg_rm : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM) -> bits('os) +function read_reg_rm(os, rm) = + match rm { + RM_reg(r) => read_gpr_ref(r), + RM_mem(_) => raise_UD(), + } + +val write_reg_rm : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM, bits('os)) -> unit +function write_reg_rm(os, rm, v) = + match rm { + RM_reg(r) => write_gpr_ref(r) = v, + RM_mem(_) => raise_UD(), + } + +overload rm = {read_rm_val, write_rm_val} +overload rm_mem = {read_mem_rm, write_mem_rm} +overload rm_reg = {read_reg_rm, write_reg_rm} + +// Alignment check: raises #GP(0) if linear address is not aligned. +// No-op for register operands. +val check_memref_alignment : forall 'a, 'a in {16, 32, 64}. (MemRef, int('a)) -> unit +function check_memref_alignment(m, align) = + if unsigned(seg_linear(m, 0)) % align != 0 then raise_GP0() + +val check_rm_alignment : forall 'a, 'a in {16, 32, 64}. (RM, int('a)) -> unit +function check_rm_alignment(rm, align) = match rm { + RM_mem(m) => check_memref_alignment(m, align), + RM_reg(_) => (), +} + +overload check_alignment = {check_memref_alignment, check_rm_alignment} + +// ========================================================================= +// Universal operand accessor v() +// ========================================================================= +// +// Mirrors SDM pseudocode style: v(dest) = v(src) + v(dest) +// Works uniformly on gpr_idx, GPRRef, RM, and MemRef operands. +val read_memref_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), MemRef) -> bits('os) +function read_memref_val(os, m) = read_mem(m) + +val write_memref_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), MemRef, bits('os)) -> unit +function write_memref_val(os, m, x) = write_mem(m, x) + +overload v = {read_memref_val, write_memref_val, read_rm_val, write_rm_val} + +// ========================================================================= +// Address size determination (for string ops, LOOP, XLAT, etc.) +// ========================================================================= + +// Address size (SDM Vol.1 §3.6). +// LongMode: default 64, 67h → 32. +// Non-LongMode, CS.D=1: default 32, 67h → 16. +// Non-LongMode, CS.D=0: default 16, 67h → 32. +val get_address_size : Prefixes -> address_size +function get_address_size(pfx) = + if cur_mode == LongMode then { + if pfx.has_adsize == 0b1 then 32 else 64 + } else if get_cs_db() == 0b1 then { + if pfx.has_adsize == 0b1 then 16 else 32 + } else { + if pfx.has_adsize == 0b1 then 32 else 16 + } + +// ========================================================================= +// SIMD element extraction +// ========================================================================= + +// Extract the i-th element of width 'eb from a bitvector. +// velem(32, src, 2) returns src[95..64] — the third dword. +// Index can be nat or bitvector. +val velem_nat : forall 'vl 'eb, 'vl > 0 & 'eb > 0 & 'vl >= 'eb. + (int('eb), bits('vl), nat) -> bits('eb) +function velem_nat(eb, v, i) = (v >> (i * eb))[('eb - 1) .. 0] + +val velem_bits : forall 'vl 'eb 'ib, 'vl > 0 & 'eb > 0 & 'vl >= 'eb & 'ib > 0. + (int('eb), bits('vl), bits('ib)) -> bits('eb) +function velem_bits(eb, v, i) = (v >> (unsigned(i) * eb))[('eb - 1) .. 0] + +overload velem = {velem_nat, velem_bits} + +// ========================================================================= +// SIMD register index helpers (extending 3-bit fields with REX bits) +// ========================================================================= + +val modrm_xreg : (byte, Prefixes) -> simd_idx +function modrm_xreg(modrm, pfx) = + unsigned(pfx.rex_r @ modrm[5..3]) diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail new file mode 100644 index 000000000..8d1752608 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail @@ -0,0 +1,481 @@ +// x86-64 — 4-Level and 5-Level Paging (Long Mode) +// +// Implements the IA-32e paging mechanism: +// 4-level (default): Virtual address → PML4 → PDPT → PD → PT → Physical address +// 5-level (CR4.LA57): Virtual address → PML5 → PML4 → PDPT → PD → PT → Physical address +// +// Page table walks use phys_read to avoid recursion through mem_read. +// Follows the sail-riscv pattern: translate_addr() returns physical address +// or throws Fault(EXN_PF, error_code) on failure. + +// Apply A20 gate masking: when A20 is disabled, bit 20 of the physical +// address is forced to zero, wrapping the address space at 1MB. +val a20_mask : qword -> qword +function a20_mask(addr) = + if ~(a20_enabled) & system_mode then addr & 0xFFFFFFFFFFEFFFFF + else addr + +// ========================================================================= +// EPT (Extended Page Tables) Translation — SDM Vol.3C §29.3 +// +// When in VMX non-root with EPT enabled (secondary proc controls bit 1), +// guest-physical addresses go through a second translation layer: +// Guest Physical Address (GPA) → EPT walk → Host Physical Address (HPA) +// +// The EPT page table format mirrors the standard 4-level paging: +// EPT PML4 → EPT PDPT → EPT PD → EPT PT +// Entries use R/W/X permission bits (bits 2:0) instead of P/R-W/U-S. +// The EPT root pointer is in vmcs.ept_pointer[51:12]. +// ========================================================================= + +// Check if EPT is active (fast path: just read the cached register). +// ept_active is declared in regs.sail, set by vm_entry/complete_vm_exit. +val ept_enabled : unit -> bool +function ept_enabled() = ept_active + +// Build EPT violation exit qualification +val ept_violation_qual : (PTAccess, bool) -> qword +function ept_violation_qual(access, present) = { + var qual : qword = zeros(); + // Descriptor reads and writes retain their access direction at EPT. + if access == PT_Read | access == PT_Implicit then qual[0] = 0b1; + if (access == PT_Write | access == PT_ImplicitWrite) then qual[1] = 0b1; + if access == PT_Execute then qual[2] = 0b1; + if present then { + qual[3] = 0b1; + qual[4] = 0b1; + qual[5] = 0b1 + }; + qual +} + +// Walk the EPT page table hierarchy. Uses __read_mem directly (not phys_read) +// to avoid recursion since phys_read calls ept_translate. +// On violation, throws VMExit(VMEXIT_EPT_VIOLATION, qualification). +val ept_walk : (qword, PTAccess, qword, range(0, 3)) -> qword +function ept_walk(gpa, access, table_base, level) = { + let index : qword = match level { + 3 => zero_extend((gpa[47..39]) : bits(9)), // PML4 + 2 => zero_extend((gpa[38..30]) : bits(9)), // PDPT + 1 => zero_extend((gpa[29..21]) : bits(9)), // PD + 0 => zero_extend((gpa[20..12]) : bits(9)), // PT + }; + let epte_addr : qword = table_base + (index << 3); + let epte : qword = __read_mem(epte_addr, 64); + + // Check R/W/X permissions (bits 2:0). If all zero, entry not present. + let r = epte[0]; + let w = epte[1]; + let x = epte[2]; + if (r | w | x) == 0b0 then { + // EPT violation: not present + let qual : qword = ept_violation_qual(access, false); + vmcs.guest_physical_address = gpa; + vmcs.exit_instr_length = 0x00000000; + throw VMExit(VMEXIT_EPT_VIOLATION, qual) + }; + + // Check for large page (PS bit = bit 7) + let is_leaf : bool = if level == 0 then true + else if (level == 1 | level == 2) & epte[7] == 0b1 then true + else false; + + if is_leaf then { + // Permission check. Implicit (descriptor-table) accesses are reads + // at the EPT level — R must be set on the leaf EPTE. + let denied : bool = match access { + PT_Read => r == 0b0, + PT_Write => w == 0b0, + PT_Execute => x == 0b0, + PT_Implicit => r == 0b0, + PT_ImplicitWrite => w == 0b0, + }; + if denied then { + let qual : qword = ept_violation_qual(access, true); + vmcs.guest_physical_address = gpa; + vmcs.exit_instr_length = 0x00000000; + throw VMExit(VMEXIT_EPT_VIOLATION, qual) + }; + + // Compute host physical address + let ppn : qword = epte & 0x000FFFFFFFFFF000; + match level { + 0 => ppn | (gpa & 0x0000000000000FFF), // 4KB + 1 => (ppn & 0x000FFFFFFFE00000) | (gpa & 0x00000000001FFFFF), // 2MB + _ => (ppn & 0x000FFFFFC0000000) | (gpa & 0x000000003FFFFFFF), // 1GB + } + } else if level > 0 then { + let next_base : qword = epte & 0x000FFFFFFFFFF000; + ept_walk(gpa, access, next_base, level - 1) + } else { + // Unreachable: level==0 is always a leaf + vmcs.guest_physical_address = gpa; + throw VMExit(VMEXIT_EPT_VIOLATION, ept_violation_qual(access, false)) + } +} +termination_measure ept_walk(_, _, _, level) = level + +// EPT-translate a guest physical address to host physical address. +// Only active when EPT is enabled; otherwise returns gpa unchanged. +val ept_translate : (qword, PTAccess) -> qword +function ept_translate(gpa, access) = { + if ept_enabled() then { + let ept_root : qword = vmcs.ept_pointer & 0x000FFFFFFFFFF000; + ept_walk(gpa, access, ept_root, 3) + } else { + gpa + } +} + +// Physical memory access (bypass virtual address translation). +// Used by page table walks and by mem_read/mem_write when paging is off. +// When EPT is active, translates guest-physical to host-physical first. +// Size parameter 'n is in bits. +val phys_read : forall 'n, 'n > 0. (implicit('n), qword) -> bits('n) +function phys_read(n, addr) = { + let pa = a20_mask(addr); + if ept_active then __read_mem(ept_translate(pa, PT_Read), n) + else __read_mem(pa, n) +} + +val phys_write : forall 'n, 'n > 0. (implicit('n), qword, bits('n)) -> unit +function phys_write(n, addr, data) = { + let pa = a20_mask(addr); + if ept_active then __write_mem(ept_translate(pa, PT_Write), n, data) + else __write_mem(pa, n, data) +} + +// Build a #PF error code from access type and fault cause. +val mk_pf_error : (PTAccess, bool, bool) -> dword +function mk_pf_error(access, present, reserved) = { + var ec : dword = 0x00000000; + // Bit 0: P — page was present (permission violation vs not-present) + if present then ec[0] = 0b1; + // Bit 1: W/R — write access caused the fault + if (access == PT_Write | access == PT_ImplicitWrite) then ec[1] = 0b1; + // Bit 2: U/S — user-mode access caused the fault. + // Implicit (descriptor-table) accesses are supervisor regardless of CPL. + if cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite) then ec[2] = 0b1; + // Bit 3: RSVD — reserved bit set in PTE + if reserved then ec[3] = 0b1; + // Bit 4: I/D — instruction fetch caused the fault. Hardware sets it + // only when the paging mode can express execute permission: CR4.SMEP=1, + // or NXE-capable paging (PAE/4-level/5-level, i.e. CR4.PAE=1) with + // IA32_EFER.NXE=1 (SDM Vol.3A §4.7). + if access == PT_Execute & + (CR4[20] == 0b1 | (CR4[5] == 0b1 & EFER[11] == 0b1)) + then ec[4] = 0b1; + ec +} + +// Check permissions on a leaf PTE. Returns true if access is allowed. +val check_pte_permissions : (qword, PTAccess) -> bool +function check_pte_permissions(pte, access) = { + let rw = pte[1]; // Read/Write bit + let us = pte[2]; // User/Supervisor bit + let xd = pte[63]; // Execute-Disable bit (if EFER.NXE=1) + + // Implicit accesses (GDT/LDT/IDT/TSS reads by the CPU itself) always + // execute at supervisor privilege regardless of CPL, and don't cause + // an NX fault (they're not instruction fetches). Writes of this class + // (e.g. A/D-bit updates, TSS busy-bit set) still respect WP. + if access == PT_Implicit then true + else if access == PT_ImplicitWrite then rw == 0b1 | CR0[16] == 0b0 + // User-mode access to supervisor page: always denied + else if cur_cpl == 3 & us == 0b0 then false + // Write to read-only page: + // - In user mode: always denied + // - In kernel mode: denied if CR0.WP=1, allowed if WP=0 + else if (access == PT_Write | access == PT_ImplicitWrite) & rw == 0b0 then { + if cur_cpl == 3 then false + else CR0[16] == 0b0 // WP=0 → allowed, WP=1 → denied + } + // Execute from XD page: denied if EFER.NXE=1 + else if access == PT_Execute & xd == 0b1 & EFER[11] == 0b1 then + false + else + true +} + +// Update Accessed and Dirty bits in the PTE if needed. +val update_accessed_dirty : (qword, qword, PTAccess) -> unit +function update_accessed_dirty(pte_addr, pte, access) = { + var new_pte = pte; + var changed : bool = false; + // Set Accessed bit if not already set + if pte[5] == 0b0 then { + new_pte[5] = 0b1; + changed = true + }; + // Set Dirty bit for writes if not already set + if (access == PT_Write | access == PT_ImplicitWrite) & pte[6] == 0b0 then { + new_pte[6] = 0b1; + changed = true + }; + if changed then phys_write(pte_addr, new_pte) +} + +// Page table walk. +// Walks PML5 → PML4 → PDPT → PD → PT to translate a 64-bit linear address. +// On success, returns the physical address. +// On failure, throws Fault(EXN_PF, error_code). +// +// The `level` parameter counts down: +// 4=PML5 (5-level only), 3=PML4, 2=PDPT, 1=PD, 0=PT. +val pt_walk : (qword, PTAccess, qword, range(0, 4)) -> qword +function pt_walk(linear, access, table_base, level) = { + // 1. Compute index: 9 bits per level + // PML5: bits[56:48], PML4: bits[47:39], PDPT: bits[38:30], + // PD: bits[29:21], PT: bits[20:12] + let index : qword = match level { + 4 => zero_extend((linear[56..48]) : bits(9)), // PML5 index + 3 => zero_extend((linear[47..39]) : bits(9)), // PML4 index + 2 => zero_extend((linear[38..30]) : bits(9)), // PDPT index + 1 => zero_extend((linear[29..21]) : bits(9)), // PD index + 0 => zero_extend((linear[20..12]) : bits(9)), // PT index + }; + let pte_addr : qword = table_base + (index << 3); + + // 2. Read PTE from physical memory (bypasses translation) + let pte : qword = phys_read(pte_addr); + + // 3. Check Present bit + if pte[0] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, false, false)) + }; + + // 4. Check reserved bits + // PML5E and PML4E: PS (bit 7) must be 0 (reserved) + // PDPTE/PDE: PS=1 allowed for huge pages + if (level == 4 | level == 3) & pte[7] == 0b1 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, true)) + }; + + // 5. Check if this is a leaf entry + let is_leaf : bool = if level == 0 then true + else if 1 <= level & level <= 2 & pte[7] == 0b1 then true // PS=1 + else false; + + if is_leaf then { + // 6. Permission check + if ~(check_pte_permissions(pte, access)) then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, false)) + }; + + // 7. Update A/D bits + update_accessed_dirty(pte_addr, pte, access); + + // 8. Compute physical address + let ppn : qword = pte & 0x000FFFFFFFFFF000; // bits[51:12] + match level { + // 4KB page: PPN[51:12] | offset[11:0] + 0 => ppn | (linear & 0x0000000000000FFF), + // 2MB page: PPN[51:21] | offset[20:0] + 1 => (ppn & 0x000FFFFFFFE00000) | (linear & 0x00000000001FFFFF), + // 1GB page: PPN[51:30] | offset[29:0] + _ => (ppn & 0x000FFFFFC0000000) | (linear & 0x000000003FFFFFFF), + } + } else if level > 0 then { + // 9. Non-leaf: recurse to next level + let next_base : qword = pte & 0x000FFFFFFFFFF000; + // Update Accessed bit on non-leaf entries too + if pte[5] == 0b0 then phys_write(pte_addr, pte | 0x0000000000000020); + pt_walk(linear, access, next_base, level - 1) + } else { + // level 0 non-leaf = impossible (always leaf) + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, true)) + } +} +termination_measure pt_walk(_, _, _, level) = level + +// ========================================================================= +// 32-bit non-PAE paging (SDM Vol.3A §4.3) +// +// 2-level walk: CR3 → Page Directory (1024 × 4-byte PDEs) → Page Table +// Linear address split: [31:22]=PDE index, [21:12]=PTE index, [11:0]=offset +// CR4.PSE=1 enables 4MB pages when PDE.PS=1. +// ========================================================================= + +val pt_walk_32 : (qword, PTAccess) -> qword +function pt_walk_32(linear, access) = { + let pd_base : qword = CR3 & 0x00000000FFFFF000; + + // 1. PDE lookup: index = linear[31:22] + let pde_index : qword = zero_extend((linear[31..22]) : bits(10)); + let pde_addr : qword = pd_base + (pde_index << 2); + let pde : dword = phys_read(pde_addr); + + // Check present + if pde[0] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, false, false)) + }; + + // Check permissions (R/W, U/S). Implicit (descriptor-table) accesses + // run at supervisor and bypass the U/S check regardless of CPL. + if (access == PT_Write | access == PT_ImplicitWrite) & pde[1] == 0b0 then { + if (cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite)) | CR0[16] == 0b1 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, false)) + } + }; + if cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite) & pde[2] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, false)) + }; + + // 4MB page (CR4.PSE=1 and PDE.PS=1) + if CR4[4] == 0b1 & pde[7] == 0b1 then { + // Update A/D bits + var new_pde = pde; + var changed : bool = false; + if pde[5] == 0b0 then { new_pde[5] = 0b1; changed = true }; + if (access == PT_Write | access == PT_ImplicitWrite) & pde[6] == 0b0 then { + new_pde[6] = 0b1; changed = true + }; + if changed then phys_write(pde_addr, new_pde); + // Physical address: PDE[31:22] @ linear[21:0] + let ppn : dword = pde & 0xFFC00000; + zero_extend(ppn | zero_extend(linear[21..0])) + } else { + // 2. PTE lookup: index = linear[21:12] + let pt_base : qword = zero_extend(pde & 0xFFFFF000); + let pte_index : qword = zero_extend((linear[21..12]) : bits(10)); + let pte_addr : qword = pt_base + (pte_index << 2); + let pte : dword = phys_read(pte_addr); + + // Check present + if pte[0] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, false, false)) + }; + + // Check permissions. Implicit (descriptor-table) accesses bypass U/S. + if (access == PT_Write | access == PT_ImplicitWrite) & pte[1] == 0b0 then { + if (cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite)) | CR0[16] == 0b1 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, false)) + } + }; + if cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite) & pte[2] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, false)) + }; + + // Update A/D bits on PDE and PTE + if pde[5] == 0b0 then phys_write(pde_addr, pde | 0x00000020); + var new_pte = pte; + var pte_changed : bool = false; + if pte[5] == 0b0 then { new_pte[5] = 0b1; pte_changed = true }; + if (access == PT_Write | access == PT_ImplicitWrite) & pte[6] == 0b0 then { + new_pte[6] = 0b1; pte_changed = true + }; + if pte_changed then phys_write(pte_addr, new_pte); + + // Physical address: PTE[31:12] @ linear[11:0] + zero_extend((pte & 0xFFFFF000) | zero_extend(linear[11..0])) + } +} + +// ========================================================================= +// PAE paging (SDM Vol.3A §4.4) +// +// 3-level walk: CR3 → PDPT (4 × 64-bit entries) → PD → PT +// Linear address split: [31:30]=PDPTE, [29:21]=PDE, [20:12]=PTE, [11:0]=offset +// PDE/PTE are 64-bit. Supports 2MB pages when PDE.PS=1. +// ========================================================================= + +val pt_walk_pae : (qword, PTAccess) -> qword +function pt_walk_pae(linear, access) = { + // 1. PDPTE lookup: index = linear[31:30] (2 bits, 4 entries) + let pdpt_base : qword = CR3 & 0x00000000FFFFFFE0; + let pdpte_index : qword = zero_extend((linear[31..30]) : bits(2)); + let pdpte_addr : qword = pdpt_base + (pdpte_index << 3); + let pdpte : qword = phys_read(pdpte_addr); + + if pdpte[0] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, false, false)) + }; + + // 2. PDE lookup: index = linear[29:21] + let pd_base : qword = pdpte & 0x000FFFFFFFFFF000; + let pde_index : qword = zero_extend((linear[29..21]) : bits(9)); + let pde_addr : qword = pd_base + (pde_index << 3); + let pde : qword = phys_read(pde_addr); + + if pde[0] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, false, false)) + }; + + // Permission checks + if ~(check_pte_permissions(pde, access)) then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, false)) + }; + + // 2MB page (PDE.PS=1) + if pde[7] == 0b1 then { + update_accessed_dirty(pde_addr, pde, access); + let ppn : qword = pde & 0x000FFFFFFFE00000; + ppn | zero_extend(linear[20..0]) + } else { + // 3. PTE lookup: index = linear[20:12] + let pt_base : qword = pde & 0x000FFFFFFFFFF000; + let pte_index : qword = zero_extend((linear[20..12]) : bits(9)); + let pte_addr : qword = pt_base + (pte_index << 3); + let pte : qword = phys_read(pte_addr); + + if pte[0] == 0b0 then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, false, false)) + }; + + if ~(check_pte_permissions(pte, access)) then { + CR2 = linear; + throw Fault(EXN_PF, mk_pf_error(access, true, false)) + }; + + // Update A/D on PDE and PTE + if pde[5] == 0b0 then phys_write(pde_addr, pde | 0x0000000000000020); + update_accessed_dirty(pte_addr, pte, access); + + let ppn : qword = pte & 0x000FFFFFFFFFF000; + ppn | zero_extend(linear[11..0]) + } +} + +// Top-level address translation. +// Dispatches to the appropriate paging mode based on CR0.PG, EFER.LMA, +// and CR4.PAE (SDM Vol.3A §4.1.1). +val translate_addr : (qword, PTAccess) -> qword +function translate_addr(linear, access) = { + if CR0[31] == 0b0 then { + linear // Paging disabled: linear = physical + } else if EFER[10] == 0b1 then { + // IA-32e mode (long mode): 4-level or 5-level paging + let is_write = (access == PT_Write | access == PT_ImplicitWrite); + match (if access == PT_ImplicitWrite then None() else __tlb_lookup(linear, is_write)) { + Some(paddr) => paddr, + None() => { + let table_base : qword = CR3 & 0x000FFFFFFFFFF000; + let start_level : range(0, 4) = + if CR4[12] == 0b1 then 4 else 3; + let paddr = pt_walk(linear, access, table_base, start_level); + if access != PT_ImplicitWrite then __tlb_insert(linear, paddr, is_write); + paddr + }, + } + } else if CR4[5] == 0b1 then { + // PAE paging (CR4.PAE=1, EFER.LMA=0) + pt_walk_pae(linear, access) + } else { + // 32-bit non-PAE paging + pt_walk_32(linear, access) + } +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail new file mode 100644 index 000000000..538999453 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail @@ -0,0 +1,126 @@ +// x86-64 — Prelude + +default Order dec + +$include +$include +$include +$include +$include +$include +$include +$include +$include + +val unreachable : forall ('a : Type). unit -> 'a +function unreachable() = { + print_endline("unreachable"); + exit() +} + +overload ~ = {not_bool, not_vec} +overload operator & = {and_vec} +overload operator | = {or_vec} +overload operator ^ = {xor_vec} + +val sub_vec = pure {c: "sub_bits", cpp: "sub_bits", _: "sub_vec"} : forall 'n. (bits('n), bits('n)) -> bits('n) +val sub_vec_int = pure {c: "sub_bits_int", cpp: "sub_bits_int", _: "sub_vec_int"} : forall 'n. (bits('n), int) -> bits('n) +overload operator - = {sub_vec, sub_vec_int} +overload operator * = {mult_atom, mult_int} + +val quot_positive_round_zero = pure {interpreter: "quot_round_zero", lem: "hardware_quot", c: "tdiv_int", cpp: "tdiv_int"} + : forall 'n 'm, 'n >= 0 & 'm > 0. (int('n), int('m)) -> int(div('n, 'm)) + +val rem_positive_round_zero = pure {interpreter: "rem_round_zero", lem: "hardware_mod", c: "tmod_int", cpp: "tmod_int"} + : forall 'n 'm, 'n >= 0 & 'm > 0. (int('n), int('m)) -> int(mod('n, 'm)) + +val quot_round_zero = pure {interpreter: "quot_round_zero", lem: "hardware_quot", c: "tdiv_int", cpp: "tdiv_int"} + : forall 'm, 'm != 0. (int, int('m)) -> int + +val rem_round_zero = pure {interpreter: "rem_round_zero", lem: "hardware_mod", c: "tmod_int", cpp: "tmod_int"} + : forall 'm, 'm != 0. (int, int('m)) -> int + +overload operator / = {quot_positive_round_zero} +overload operator % = {rem_positive_round_zero} + +val sign_extend : forall 'n 'm, 'm >= 'n. (implicit('m), bits('n)) -> bits('m) +val zero_extend : forall 'n 'm, 'm >= 'n. (implicit('m), bits('n)) -> bits('m) +function sign_extend(m, v) = sail_sign_extend(v, m) +function zero_extend(m, v) = sail_zero_extend(v, m) + +val zeros : forall 'n, 'n >= 0. implicit('n) -> bits('n) +function zeros(n) = sail_zeros(n) + +val ones : forall 'n, 'n >= 0. implicit('n) -> bits('n) +function ones(n) = sail_ones(n) + +val trunc : forall 'm 'n, 'm >= 0 & 'm <= 'n. (implicit('m), bits('n)) -> bits('m) +function trunc(m, v) = truncate(v, m) + +infix 4 <_s +infix 4 >_s +infix 4 <=_s +infix 4 >=_s +infix 4 <_u +infix 4 >_u +infix 4 <=_u +infix 4 >=_u + +val operator <_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool +val operator >_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool +val operator <=_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool +val operator >=_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool +val operator <_u : forall 'n. (bits('n), bits('n)) -> bool +val operator >_u : forall 'n. (bits('n), bits('n)) -> bool +val operator <=_u : forall 'n. (bits('n), bits('n)) -> bool +val operator >=_u : forall 'n. (bits('n), bits('n)) -> bool + +function operator <_s (x, y) = signed(x) < signed(y) +function operator >_s (x, y) = signed(x) > signed(y) +function operator <=_s (x, y) = signed(x) <= signed(y) +function operator >=_s (x, y) = signed(x) >= signed(y) +function operator <_u (x, y) = unsigned(x) < unsigned(y) +function operator >_u (x, y) = unsigned(x) > unsigned(y) +function operator <=_u (x, y) = unsigned(x) <= unsigned(y) +function operator >=_u (x, y) = unsigned(x) >= unsigned(y) + +infix 7 >> +infix 7 >>> +infix 7 << + +val "shift_bits_right" : forall 'n 'm. (bits('n), bits('m)) -> bits('n) +val "shift_bits_right_arith" : forall 'n 'm. (bits('n), bits('m)) -> bits('n) +val "shift_bits_left" : forall 'n 'm. (bits('n), bits('m)) -> bits('n) +val "shiftl" : forall 'm 'n, 'n >= 0. (bits('m), int('n)) -> bits('m) +val "shiftr" : forall 'm 'n, 'n >= 0. (bits('m), int('n)) -> bits('m) + +overload operator >> = {shift_bits_right, shiftr} +overload operator << = {shift_bits_left, shiftl} + +// Arithmetic right shift without allocating a vector of width n + shift. +// Complement negative values before a logical shift, then complement back. +// This also sign-fills when the count is greater than or equal to the width. +val operator >>> : forall 'n 'm, 'n >= 1 & 'm >= 0. (bits('n), int('m)) -> bits('n) +function operator >>>(value, shift) = { + let sign : bits('n) = sign_extend(value[('n - 1)..('n - 1)]); + // The SMT backend sizes shift counts to the shifted vector. Widen by a + // fixed amount so a full 64-bit x86 count is not truncated for small lanes. + let shifted : bits('n + 64) = zero_extend('n + 64, value ^ sign) >> shift; + shifted[('n - 1)..0] ^ sign +} + +mapping bool_bit : bool <-> bit = { + true <-> 0b1, + false <-> 0b0, +} + +function bool_to_bit(x : bool) -> bit = bool_bit(x) + +val to_bits : forall 'l 'x, 'l >= 0 & 0 <= 'x < 2 ^ 'l. (implicit('l), int('x)) -> bits('l) +function to_bits(l, n) = get_slice_int(l, n, 0) + +val to_bits_truncate : forall 'l, 'l >= 0. (implicit('l), int) -> bits('l) +function to_bits_truncate(l, n) = get_slice_int(l, n, 0) + +val print_log = pure {c: "print_endline", cpp: "print_endline", _: "print_endline"} : string -> unit +val trace_log = pure {c: "trace_stderr", cpp: "trace_stderr", _: "print_endline"} : string -> unit diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail new file mode 100644 index 000000000..c2704c867 --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail @@ -0,0 +1,1184 @@ +// x86-64 — Register Definitions + +// ========================================================================= +// Instruction pointer +// ========================================================================= + +register RIP : qword + +// Branch target set by control-flow instructions (JMP, CALL, RET, Jcc). +// When Some, step() uses this instead of decode_pos to update RIP. +register next_rip : option(qword) = None() + +// ========================================================================= +// Processor mode and privilege +// ========================================================================= + +register cur_mode : ProcessorMode +register cur_cpl : cpl_t + +// ========================================================================= +// General-purpose registers +// +// x86-64 has 16 64-bit GPRs. Sub-register access (e.g. AL, AX, EAX) +// is handled by the read/write functions below. +// ========================================================================= + +register GPR : vector(16, qword) + +// Polymorphic GPR read by operand size. +val read_gpr : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), gpr_idx) -> bits('os) +function read_gpr(os, idx) = match os { + 8 => GPR[idx][7..0], + 16 => GPR[idx][15..0], + 32 => GPR[idx][31..0], + 64 => GPR[idx] +} + +// Polymorphic GPR write by operand size. A 32-bit result is zero-extended +// to 64 bits in 64-bit mode (SDM Vol.1 §3.4.1.1). Outside it "the upper +// 32 bits of 64-bit general-purpose registers are undefined" (SDM Vol.1 +// §3.4.1.1, p.3-13; APM Vol.1 §3.4.5, p.74: "undefined and not accessible +// to software"), and a 32-bit write leaves them so. An 8- or 16-bit +// write keeps the rest of the register. +val write_gpr : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), gpr_idx, bits('os)) -> unit +function write_gpr(os, idx, v) = match os { + 8 => GPR[idx] = GPR[idx][63..8] @ v, + 16 => GPR[idx] = GPR[idx][63..16] @ v, + 32 => GPR[idx] = if cur_mode == LongMode then zero_extend(v) else (undefined : dword) @ v, + 64 => GPR[idx] = v +} + +// Polymorphic GPR read via GPRRef. +// In byte mode without REX, indices 4-7 mean AH/CH/DH/BH (high byte of +// GPR 0-3). With any REX prefix, they mean SPL/BPL/SIL/DIL. +val read_gpr_ref : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), GPRRef) -> bits('os) +function read_gpr_ref(os, r) = { + let idx = r.gpr_idx; + if os == 8 then { + if ~(r.has_rex) & 4 <= idx & idx <= 7 then + GPR[idx - 4][15..8] + else + GPR[idx][7..0] + } else { + read_gpr(idx) + } +} + +// Polymorphic GPR write via GPRRef. +val write_gpr_ref : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), GPRRef, bits('os)) -> unit +function write_gpr_ref(os, r, v) = { + let idx = r.gpr_idx; + if os == 8 then { + if ~(r.has_rex) & 4 <= idx & idx <= 7 then + GPR[idx - 4][15..8] = v + else + GPR[idx][7..0] = v + } else { + write_gpr(idx, v) + } +} + +overload v = {read_gpr, write_gpr, read_gpr_ref, write_gpr_ref} + +// A change of processor mode: "the upper 32 bits of any general-purpose +// register are not preserved when switching from 64-bit mode to a 32-bit +// mode (to protected mode or compatibility mode)" (SDM Vol.1 §3.4.1.1, +// p.3-13); "The processor does not preserve the upper 32 bits of the +// 64-bit GPRs across changes from 64-bit mode to compatibility or legacy +// modes" (APM Vol.1 §3.4.5, p.74). Those of RAX-RDI become undefined. +// R8-R15, which a 32-bit mode cannot reach, "are preserved across +// transitions from 64-bit mode into compatibility mode then back into +// 64-bit mode" (SDM, ibid.). +val set_mode : ProcessorMode -> unit +function set_mode(m) = { + if cur_mode == LongMode & m != LongMode then { + foreach (i from 0 to 7) { + GPR[i] = (undefined : dword) @ GPR[i][31..0] + } + }; + cur_mode = m +} + +// Named GPR indices for readability. +let RAX : gpr_idx = 0 +let RCX : gpr_idx = 1 +let RDX : gpr_idx = 2 +let RBX : gpr_idx = 3 +let RSP : gpr_idx = 4 +let RBP : gpr_idx = 5 +let RSI : gpr_idx = 6 +let RDI : gpr_idx = 7 +let R8 : gpr_idx = 8 +let R9 : gpr_idx = 9 +let R10 : gpr_idx = 10 +let R11 : gpr_idx = 11 +let R12 : gpr_idx = 12 +let R13 : gpr_idx = 13 +let R14 : gpr_idx = 14 +let R15 : gpr_idx = 15 + +// The vendor whose manual the model follows where the SDM and the APM give +// one encoding different meanings that no undefined value can express: +// 66h on the near branches in 64-bit mode, which changes the instruction's +// length, its stack width and the truncation of RIP (opsize_forced64 and +// opsize_rel, operands.sail), and far CALL and JMP with REX.W, which read +// an m16:64 or an m16:32 pointer (far_pointer_offset_size, +// insn_groups.sail). It does not change the CPUID vendor string. The KVM +// differential harness sets it from the host; the emulators keep the Intel +// default. +enum Vendor = { Vendor_Intel, Vendor_AMD } +register vendor : Vendor = Vendor_Intel + +// ========================================================================= +// x87 FPU Register State +// +// The x87 FPU has an 8-register stack of 80-bit extended precision values. +// Registers are accessed relative to the TOP pointer in the status word. +// The full state includes the control word, status word, and tag word. +// ========================================================================= + +register x87_ST : vector(8, fp80) +register x87_cw : word // control word (default 0x037F) +register x87_sw : word // status word (default 0x0000) +register x87_tw : word // tag word (default 0xFFFF = all empty) +// The last non-control x87 instruction's address, CS selector and opcode, +// and its memory operand's offset and segment selector (SDM Vol.1 §8.1.8, +// §8.1.9). x87_record_last says when each is recorded. +register x87_fip : qword +register x87_fcs : word +register x87_fop : bits(11) +register x87_fdp : qword +register x87_fds : word +// Whether MMX instructions ran after the last x87 instruction: FXSAVE and +// XSAVE then save "the MMX technology registers", and "the high 16 bits +// of the field are reserved" (SDM Vol.2A FXSAVE, Field Definitions +// p.3-414). mmx_touch and EMMS set it, and dispatch_x87 clears it. +register x87_mmx_last : bool = false + +val x87_top : unit -> range(0, 7) +function x87_top() = unsigned(x87_sw[13..11]) + +val x87_set_top : int -> unit +function x87_set_top(t) = { + x87_sw[13..11] = to_bits_truncate(3, t) +} + +val x87_physical : int -> range(0, 7) +function x87_physical(i) = unsigned(to_bits_truncate(3, x87_top() + i)) + +// Tag word helpers: each register has a 2-bit tag at bits [2*phys+1 .. 2*phys]. +// Tag value 3 = empty, anything else = valid. +val x87_mark_valid : range(0, 7) -> unit +function x87_mark_valid(phys) = { + let shift_amt = 2 * phys; + let mask : word = ~(0x0003 << shift_amt); + x87_tw = x87_tw & mask +} + +val x87_mark_empty : range(0, 7) -> unit +function x87_mark_empty(phys) = { + let shift_amt = 2 * phys; + let bits : word = 0x0003 << shift_amt; + x87_tw = x87_tw | bits +} + +// Read ST(i) — the i-th register from the top of the x87 stack. +val x87_read_st : int -> fp80 +function x87_read_st(i) = x87_ST[x87_physical(i)] + +// Write a value to ST(i). The register then holds a number, so it is no +// longer tagged empty (SDM Vol.1 §8.1.7: the tag indicates whether a +// register contains a valid number, zero, a special value, or is empty). +val x87_write_st : (int, fp80) -> unit +function x87_write_st(i, v) = { + let phys = x87_physical(i); + x87_ST[phys] = v; + x87_mark_valid(phys) +} + +// Tag of a non-empty register from its contents (SDM Vol.1 §8.1.7, Figure +// 8-7): 00 valid, 01 zero, 10 special (NaN, unsupported, infinity, denormal). +val x87_class_tag : fp80 -> bits(2) +function x87_class_tag(v) = { + let exp : bits(15) = v[78..64]; + let mant : qword = v[63..0]; + if exp == zeros() then (if mant == zeros() then 0b01 else 0b10) + else if exp == ones() then 0b10 + else if mant[63] == bitzero then 0b10 + else 0b00 +} + +// The tag word as FSTENV and FSAVE store it: registers tagged empty stay +// empty, the others are classified from their contents. +val x87_tag_word : unit -> word +function x87_tag_word() = { + var tw : word = x87_tw; + foreach (i from 0 to 7) { + let tag : bits(2) = (tw >> (2 * i))[1..0]; + if tag != 0b11 then { + let cleared : word = tw & ~(0x0003 << (2 * i)); + tw = cleared | (zero_extend(x87_class_tag(x87_ST[i])) << (2 * i)) + } + }; + tw +} + +// Push a value onto the x87 stack (decrement TOP, write to new ST(0)). +val x87_push : fp80 -> unit +function x87_push(v) = { + let new_top = x87_physical(-1); + x87_set_top(new_top); + x87_ST[new_top] = v; + x87_mark_valid(new_top) +} + +// Pop the top of the x87 stack (read ST(0), increment TOP). +val x87_pop : unit -> fp80 +function x87_pop() = { + let cur_top = x87_top(); + let result = x87_ST[cur_top]; + x87_mark_empty(cur_top); + x87_set_top(x87_physical(1)); + result +} + +// Mark ST(i) as empty (used by FFREE). +val x87_free : int -> unit +function x87_free(i) = x87_mark_empty(x87_physical(i)) + +// Whether ST(i) is tagged empty. +val x87_is_empty : int -> bool +function x87_is_empty(i) = (x87_tw >> (2 * x87_physical(i)))[1..0] == 0b11 + +// The real indefinite, a QNaN with the sign set and the significand +// 1100...0 (SDM Vol.1 §4.8.3.7, Table 4-3): the masked response of an +// x87 invalid operation. The packed BCD indefinite has the same bits. +let x87_indefinite : fp80 = 0xFFFFC000000000000000 + +// Decrement TOP (used by FDECSTP). +val x87_dec_top : unit -> unit +function x87_dec_top() = x87_set_top(x87_physical(-1)) + +// Increment TOP (used by FINCSTP). +val x87_inc_top : unit -> unit +function x87_inc_top() = x87_set_top(x87_physical(1)) + +// Initialize x87 state (used by FINIT/FNINIT). +val x87_init : unit -> unit +function x87_init() = { + x87_cw = 0x037F; + x87_sw = 0x0000; + x87_tw = 0xFFFF; + x87_fip = zeros(); + x87_fcs = zeros(); + x87_fop = zeros(); + x87_fdp = zeros(); + x87_fds = zeros(); + foreach (i from 0 to 7) { + x87_ST[i] = zeros() + } +} + +// FSW.ES (bit 7, error summary) and FSW.B (bit 15) are set exactly when an +// exception flag is set whose mask bit is clear. Loading either word +// recomputes them, as does unmasking a set flag (FLDCW). +val x87_update_es : unit -> unit +function x87_update_es() = { + let pending : bit = if (x87_sw[5..0] & ~(x87_cw[5..0])) != 0b000000 then bitone else bitzero; + x87_sw[7] = pending; + x87_sw[15] = pending +} + +// FCW bits 15:13 and 7:6 are reserved (SDM Vol.1 Figure 8-6 p.8-7; APM +// Vol.1 Figure 6-4 p.293, §6.2.3: "All bits, except reserved bits, can be +// read and written"), and neither manual says what they read after a +// load, so a load leaves them undefined. FNINIT and FNSAVE set the whole +// word to 037FH (SDM §8.1.5; x87_init). +val x87_set_cw : word -> unit +function x87_set_cw(cw) = { + x87_cw = (cw & 0x1F3F) | ((undefined : word) & 0xE0C0); + x87_update_es() +} + +val x87_set_sw : word -> unit +function x87_set_sw(sw) = { + x87_sw = sw; + x87_update_es() +} + +// The CPUID bits that select how the x87 pointers are kept and saved, each +// enumerated by one manual and reserved (0) in the other, and so three +// independent parameters: CPUID.(EAX=07H,ECX=0):EBX[6] FDP_EXCPTN_ONLY, "If +// 1, the x87 FPU Data Pointer is updated only on x87 exceptions", and +// EBX[13] FCS_FDS_DEPRECATION, "If 1, deprecates FPU CS and FPU DS values" +// (SDM Vol.1 Table 21-19 p.21-27, §8.1.8 p.8-9), and CPUID Fn8000_0008_EBX[2] +// RstrFpErrPtrs, "FP Error Pointers Restored by XRSTOR" (APM Vol.3 +// Appendix E p.659, Vol.2 §11.5.10 p.361). CPUID reports them as they are +// set, and x87_record_last, xsave_x87 and xrstor_x87 follow them; where a +// bit is 0, the value the other manual's rule then gives is open as well. +// The defaults are those of the processor the CPUID identifies +// ("GenuineIntel"); the KVM harness sets each from its host. +register has_fdp_excptn_only : bool = true +register has_fcs_fds_deprecation : bool = true +register has_rstr_fp_err_ptrs : bool = false + +// The FCS or FDS that FNSTENV, FNSAVE, FXSAVE and XSAVE write: "If +// CPUID.07H.00H:EBX[13] = 1, the processor deprecates FCS and FDS; it +// saves each as 0000H" (SDM Vol.1 §8.1.8). The loads take both from the +// image either way. +val x87_saved_selector : word -> word +function x87_saved_selector(sel) = if has_fcs_fds_deprecation then 0x0000 else sel + +// ========================================================================= +// MMX register access +// +// MMX registers MM0-MM7 alias the low 64 bits of the x87 physical registers +// ST(0)-ST(7), accessed by physical index (not relative to TOP). +// Writing an MMX register sets bits [79:64] to all ones and marks the tag +// as valid. All MMX instructions also set TOS (TOP) to 0 and mark all +// tag bits as valid (tag word = 0x0000). +// ========================================================================= + +// Called on any MMX instruction: set TOS=0, all tags=valid. +val mmx_touch : unit -> unit +function mmx_touch() = { + x87_sw[13..11] = 0b000; // TOP = 0 + x87_tw = 0x0000; // all valid + x87_mmx_last = true +} + +// Save the 28-byte x87 environment in the 32-bit protected-mode format +// (SDM Vol.1 Figure 8-9 p.8-11; APM Vol.2 Figure 11-4 p.352) as +// bits(224): FCW, FSW and FTW in the low halves of three doublewords, +// then FIP[31:0], FCS with FOP in bits 26:16 and 00000b above it, +// FDP[31:0], and FDS. The high halves of the FCW, FSW, FTW and FDS +// doublewords are reserved ("Reserved, IGN" in the APM) with no value +// given, so they are written undefined. +val x87_save_env : unit -> bits(224) +function x87_save_env() = { + var buf : bits(224) = zeros(); + buf[15..0] = x87_cw; + buf[31..16] = (undefined : word); + buf[47..32] = x87_sw; + buf[63..48] = (undefined : word); + buf[79..64] = x87_tag_word(); + buf[95..80] = (undefined : word); + buf[127..96] = x87_fip[31..0]; + buf[143..128] = x87_saved_selector(x87_fcs); + buf[154..144] = x87_fop; + buf[191..160] = x87_fdp[31..0]; + buf[207..192] = x87_saved_selector(x87_fds); + buf[223..208] = (undefined : word); + buf +} + +// Load the 28-byte x87 environment from bits(224), the inverse of +// x87_save_env. FCW is loaded first, so that FSW.ES reflects its masks. +val x87_load_env : bits(224) -> unit +function x87_load_env(buf) = { + x87_set_cw(buf[15..0]); + x87_set_sw(buf[47..32]); + x87_tw = buf[79..64]; + x87_fip = zero_extend(buf[127..96]); + x87_fcs = buf[143..128]; + x87_fop = buf[154..144]; + x87_fdp = zero_extend(buf[191..160]); + x87_fds = buf[207..192] +} + +// The 14-byte environment of a 16-bit operand size in protected mode +// (SDM Vol.1 §8.1.10, Figure 8-11 p.8-12; APM Vol.2 Figure 11-6 p.354): +// FCW, FSW, FTW, FIP[15:0], FCS, FDP[15:0] and FDS, without FOP. Loading +// it clears bits 63:32 of the two offsets ("loads the lower 32 bits from +// memory and clears the upper 32 bits", §8.1.8), of whose lower 32 the +// image holds 16. Neither manual gives bits 31:16 of the offsets, nor +// FOP, which the image does not have, a value: both are undefined. +val x87_save_env16 : unit -> bits(112) +function x87_save_env16() = + x87_saved_selector(x87_fds) @ x87_fdp[15..0] @ x87_saved_selector(x87_fcs) @ x87_fip[15..0] + @ x87_tag_word() @ x87_sw @ x87_cw + +val x87_load_env16 : bits(112) -> unit +function x87_load_env16(buf) = { + x87_set_cw(buf[15..0]); + x87_set_sw(buf[31..16]); + x87_tw = buf[47..32]; + x87_fip = zero_extend((undefined : word) @ buf[63..48]); + x87_fcs = buf[79..64]; + x87_fop = undefined; + x87_fdp = zero_extend((undefined : word) @ buf[95..80]); + x87_fds = buf[111..96] +} + +// The eight registers that follow the environment in an FSAVE image, in +// stack order: DEST[ST(i)] := ST(i) (SDM Vol.2A FSAVE/FNSAVE, Operation). +val x87_save_regs : unit -> bits(640) +function x87_save_regs() = { + var buf : bits(640) = zeros(); + foreach (i from 0 to 7) { + buf[(i * 80 + 79) .. (i * 80)] = x87_read_st(i) + }; + buf +} + +// ST(i) := SRC[ST(i)] (SDM Vol.2A FRSTOR, Operation), relative to the TOP +// of the environment loaded first. +val x87_load_regs : bits(640) -> unit +function x87_load_regs(buf) = { + foreach (i from 0 to 7) { + x87_ST[x87_physical(i)] = buf[(i * 80 + 79) .. (i * 80)] + } +} + +// ========================================================================= +// SIMD registers (XMM/YMM/ZMM) +// +// We model the full 512-bit ZMM registers. XMM and YMM access the +// low 128 and 256 bits respectively. +// x86-64 has 16 registers (0-15), AVX-512 extends to 32. +// ========================================================================= + +type simd_idx = range(0, 31) + +register ZMM : vector(32, zmmword) + +// Polymorphic SIMD read by vector length. +val read_simd : forall 'vl, 'vl in {128, 256, 512}. (implicit('vl), simd_idx) -> bits('vl) +function read_simd(vl, idx) = match vl { + 128 => ZMM[idx][127..0], + 256 => ZMM[idx][255..0], + 512 => ZMM[idx] +} + +// Polymorphic SIMD write by vector length (zeros upper bits). +val write_simd : forall 'vl, 'vl in {128, 256, 512}. (implicit('vl), simd_idx, bits('vl)) -> unit +function write_simd(vl, idx, v) = match vl { + 128 => { ZMM[idx][511..128] = zeros(); ZMM[idx][127..0] = v }, + 256 => { ZMM[idx][511..256] = zeros(); ZMM[idx][255..0] = v }, + 512 => ZMM[idx] = v +} + +// ========================================================================= +// AVX-512 Opmask registers (k0-k7) +// +// k0 is special: when used as a writemask, it means "no masking" (all 1s). +// k1-k7 are general-purpose mask registers. +// ========================================================================= + +type kreg_idx = range(0, 7) + +register KREG : vector(8, qword) + +val read_kreg : kreg_idx -> qword +function read_kreg(idx) = KREG[idx] + +val write_kreg : (kreg_idx, qword) -> unit +function write_kreg(idx, v) = KREG[idx] = v + +// ========================================================================= +// Segment registers +// ========================================================================= + +register SegReg : vector(6, word) + +// Segment descriptor caches (hidden part of each segment register). +// Per SDM Vol.3A §3.4.3, loaded from GDT/LDT on segment register write. +register SegCache : vector(6, SegDescCache) + +val read_segreg : segreg_idx -> word +function read_segreg(idx) = SegReg[idx] + +val write_segreg : (segreg_idx, word) -> unit +function write_segreg(idx, v) = SegReg[idx] = v + +// Kernel GS base (shadow register swapped with SegCache[GS].seg_base by SWAPGS). +register KERNEL_GS_BASE : qword + +// ========================================================================= +// Descriptor table registers +// ========================================================================= + +register GDTR_base : qword +register GDTR_limit : word +register IDTR_base : qword +register IDTR_limit : word +register LDTR : word // LDT selector +register LDTR_base : qword +register LDTR_limit : dword +register LDTR_valid : bool = false +register TR : word // Task register selector + +// TSS base and limit (loaded from GDT when LTR executes) +register TR_base : qword +register TR_limit : dword +// Hidden TSS descriptor type, retained by LTR (SDM Vol.3A section 10.2.4). +register TR_type : bits(4) = 0xB + +// ========================================================================= +// Segment descriptor cache helpers +// ========================================================================= + +// Get the linear base address of a segment. +// In LongMode, ES/CS/SS/DS are treated as base 0 (SDM Vol.3A §3.4.4); +// FS and GS bases are stored in SegCache (set via MSR or descriptor load). +// In other modes, all segment bases come from the descriptor cache. +val get_seg_base : segreg_idx -> qword +function get_seg_base(seg) = + if cur_mode == LongMode & seg != FS & seg != GS + then 0x0000000000000000 + else SegCache[seg].seg_base + +// Get the CS.D bit (default operation size). +// Returns 0b1 when CS.D=1 (32-bit default), 0b0 when CS.D=0 (16-bit). +val get_cs_db : unit -> bit +function get_cs_db() = SegCache[CS].seg_db + +// Parse an 8-byte segment descriptor into a SegDescCache (SDM Vol.3A §3.4.5). +// lo = descriptor bytes [3:0], hi = descriptor bytes [7:4]. +val parse_seg_descriptor : (dword, dword) -> SegDescCache +function parse_seg_descriptor(lo, hi) = { + // Base address: hi[31:24] @ hi[7:0] @ lo[31:16] + let base : dword = hi[31..24] @ hi[7..0] @ lo[31..16]; + // Limit: hi[19:16] @ lo[15:0] (20-bit raw limit) + let raw_limit : bits(20) = hi[19..16] @ lo[15..0]; + // Granularity: if G=1, scale limit by 4KB (shift left 12, fill low bits) + let g : bit = hi[23]; + let limit : dword = if g == 0b1 then zero_extend(raw_limit) @ 0xFFF + else zero_extend(raw_limit); + struct { + seg_base = zero_extend(base), + seg_limit = limit, + seg_type = hi[11..8], + seg_s = hi[12], + seg_dpl = unsigned(hi[14..13]), + seg_present = hi[15], + seg_db = hi[22], + seg_l = hi[21], + seg_g = g, + } +} + +// load_segment_register is defined in mem.sail (needs mem_read32). + +// ========================================================================= +// Decode position +// +// Tracks the current position in the instruction stream during decoding. +// Placed here (rather than in decode/) so instruction implementations +// can access it for control-flow instructions (CALL, JMP, RET, Jcc). +// ========================================================================= + +register decode_pos : qword + +// Start of current instruction (set to RIP at beginning of step()). +// Used to enforce the 15-byte maximum instruction length. +register insn_start : qword + +// Instruction buffer for Isla symbolic execution. +// Holds up to 15 instruction bytes (120 bits) in little-endian order: +// bits [7..0] = byte at offset 0, bits [15..8] = byte at offset 1, etc. +// The splice file overrides fetch() to read from this register +// instead of memory, because Isla's symbolic memory model does not +// connect writes to subsequent reads at the same address. +register insn_buf : bits(120) = zeros() + +// Output register for ISLA equivalence proofs. +register Final_result : bits(128) = zeros() + +// Symbolic data-memory window for ISLA equivalence proofs: 256 bytes at +// 0x7000. The splice file routes phys_read/phys_write here so that a +// load at a concrete address is a shared symbolic input. Unused by the +// emulator. +register mem_window : bits(2048) + +// RIP-relative fixup state: when modrm_rm sees mod=00 rm=101 (RIP+disp32), +// it saves decode_pos after consuming the displacement bytes. If the +// instruction has trailing bytes (imm8, imm32), decode_pos will advance +// further. The fixup delta (decode_pos - rip_rel_saved_pos) is added to +// the preliminary RM_mem address at use time. +register rip_rel_pending : bool +register rip_rel_disp : qword + +// VSIB (Vector SIB) addressing info for gather/scatter +struct VSIB = { + vsib_base : qword, // base address (GPR + displacement) + vsib_vidx : simd_idx, // vector register containing indices + vsib_scale : range(0, 3), // scale factor (0=1, 1=2, 2=4, 3=8) + vsib_seg : segreg_idx, // segment of the accesses + vsib_addr64 : bool, // 64-bit addresses (else 32-bit) +} + +// ========================================================================= +// Control registers (system-level) +// ========================================================================= + +register CR0 : qword // PE, PG, WP, etc. +register CR2 : qword // Page Fault Linear Address +register CR3 : qword // Page table base +register CR4 : qword // PAE, PSE, OSFXSR, OSXSAVE, etc. +register CR8 : bits(4) // Task Priority Register (TPR), bits 3:0 +register EFER : qword // Extended Feature Enable Register + +// Debug registers +// Default values are specified by SDM +register DR0 : qword = 0x0000000000000000 // Linear breakpoint address 0 +register DR1 : qword = 0x0000000000000000 // Linear breakpoint address 1 +register DR2 : qword = 0x0000000000000000 // Linear breakpoint address 2 +register DR3 : qword = 0x0000000000000000 // Linear breakpoint address 3 +register DR6 : qword = 0x00000000FFFF0FF0 // Debug status +register DR7 : qword = 0x0000000000000400 // Debug control + +// Single-step bookkeeping, maintained by step() and deliver_exception +// (SDM Vol.3B §20.3.1.4, Vol.3A §7.8.3): +// event_delivered — an exception or interrupt went through the IDT during +// the current instruction (INT n, INT3, INTO, INT1, a +// fault); such an instruction gets no single-step trap. +// ss_shadow — 2 right after MOV SS/POP SS, 1 through the following +// instruction, 0 otherwise: suppresses the trap after the +// SS load and holds external interrupts until after the +// next instruction. +register event_delivered : bool = false +register ss_shadow : range(0, 2) = 0 +// STI delays maskable interrupts through the following instruction, but +// unlike MOV SS it does not suppress debug traps. +register sti_shadow : range(0, 2) = 0 + +// Data-breakpoint bookkeeping (SDM Vol.3B §20.3.1.2), maintained by the +// memory interface, exec_rep and step(): +// pending_dbp — Bn of the data breakpoints hit by the current +// instruction's accesses; reported as a trap after it, +// kept across a MOV SS/POP SS and delivered after the +// following instruction, lost on a fault. +// open_dbp — Bn of the breakpoints the accesses match although +// neither Ln nor Gn enables them: "They may or may not be +// set if the breakpoint is not enabled" (§20.2.3 p.20-4), +// where the APM clears them (Vol.2 §13.1.1.3 p.394), so +// they are undefined in the DR6 of the trap. +// rep_trap_rf — a repeated string instruction stopped after an +// iteration that is not its last (data breakpoint or single +// step): RF in the trap's RFLAGS image is undefined (see +// step()). +register pending_dbp : bits(4) = 0x0 +register open_dbp : bits(4) = 0x0 +register rep_trap_rf : bool = false + +// CR0 bit positions +let CR0_PE : int = 0 // Protection Enable +let CR0_MP : int = 1 // Monitor Coprocessor +let CR0_EM : int = 2 // Emulation +let CR0_TS : int = 3 // Task Switched +let CR0_ET : int = 4 // Extension Type +let CR0_NE : int = 5 // Numeric Error +let CR0_WP : int = 16 // Write Protect +let CR0_AM : int = 18 // Alignment Mask +let CR0_NW : int = 29 // Not Write-through +let CR0_CD : int = 30 // Cache Disable +let CR0_PG : int = 31 // Paging + +// CR4 bit positions +let CR4_VME : int = 0 // Virtual-8086 Mode Extensions +let CR4_PVI : int = 1 // Protected-Mode Virtual Interrupts +let CR4_TSD : int = 2 // Time Stamp Disable +let CR4_DE : int = 3 // Debugging Extensions +let CR4_PSE : int = 4 // Page Size Extensions +let CR4_PAE : int = 5 // Physical Address Extension +let CR4_MCE : int = 6 // Machine-Check Enable +let CR4_PGE : int = 7 // Page Global Enable +let CR4_PCE : int = 8 // Performance-Monitoring Counter Enable +let CR4_OSFXSR : int = 9 // OS Support for FXSAVE/FXRSTOR +let CR4_OSXMMEXCPT : int = 10 // OS Support for Unmasked SIMD FP Exceptions +let CR4_LA57 : int = 12 // 5-Level Paging +let CR4_FSGSBASE : int = 16 // FSGSBASE Enable +let CR4_PCIDE : int = 17 // PCID Enable +let CR4_VMXE : int = 13 // VMX Enable +let CR4_OSXSAVE : int = 18 // XSAVE and Processor Extended States Enable + +// EFER bit positions +let EFER_SCE : int = 0 // SYSCALL Enable +let EFER_LME : int = 8 // Long Mode Enable +let EFER_LMA : int = 10 // Long Mode Active +let EFER_NXE : int = 11 // No-Execute Enable + +// ========================================================================= +// Extended Control Register 0 (XCR0) and CPUID feature flags +// +// XCR0 controls OS-level enabling of XSAVE-managed state components. +// XCR0_SUPPORTED defines the hardware (silicon) mask; XCR0 <= XCR0_SUPPORTED. +// CPUID feature flags model silicon-fixed features (BMI, POPCNT, etc.). +// All are set at init time; Isla treats them as constants. +// ========================================================================= + +register XCR0 : qword // Extended Control Register 0 (OS-enabled state) +register XCR0_SUPPORTED : qword // Which XCR0 bits this "CPU" supports (silicon mask) + +// XCR0 bit position constants (SDM Table 13-1) +let XCR0_X87 : int = 0 +let XCR0_SSE : int = 1 +let XCR0_AVX : int = 2 +let XCR0_OPMASK : int = 5 +let XCR0_ZMM_HI256 : int = 6 +let XCR0_HI16_ZMM : int = 7 +let XCR0_TILECFG : int = 17 +let XCR0_TILEDATA : int = 18 + +// CPUID feature flag registers (concrete booleans, set at init) +register has_sse3 : bool // CPUID.01H:ECX[0] +register has_ssse3 : bool // CPUID.01H:ECX[9] +register has_sse4_1 : bool // CPUID.01H:ECX[19] +register has_sse4_2 : bool // CPUID.01H:ECX[20] +register has_cx16 : bool // CPUID.01H:ECX[13] — CMPXCHG16B +register has_popcnt : bool +register has_lzcnt : bool +register has_bmi1 : bool +register has_bmi2 : bool +register has_fma : bool +register has_aesni : bool +register has_pclmulqdq : bool +register has_vpclmulqdq : bool // CPUID.07H:ECX[10] — VEX.256 and EVEX VPCLMULQDQ +register has_vaes : bool // CPUID.07H:ECX[9] — VEX.256 and EVEX VAESENC/VAESENCLAST/VAESDEC/VAESDECLAST +register has_gfni : bool // CPUID.07H:ECX[8] — GF2P8AFFINEQB/GF2P8AFFINEINVQB/GF2P8MULB in every encoding +register has_avx_vnni : bool // CPUID.(07H,1):EAX[4] — VEX VPDPBUSD/VPDPBUSDS/VPDPWSSD/VPDPWSSDS +register has_f16c : bool +register has_movbe : bool +register has_adx : bool +register has_sha : bool +register has_rdrand : bool +register has_rdseed : bool +register has_rdpid : bool // CPUID.07H:ECX[22] — RDPID (F3 0F C7 /7) +register has_crc32 : bool +register has_movdiri : bool +register has_movdir64b : bool +register has_enqcmd : bool // CPUID.07H:ECX[29] — ENQCMD, ENQCMDS and IA32_PASID +register has_xsave : bool // XSAVE/XRSTOR, XSETBV/XGETBV, XCR0 (CPUID.01H:ECX[26]) +// The AVX-512 extensions, each its own CPUID bit (SDM Vol.1 Tables 21-19 +// to 21-22, pp. 21-27 to 21-30), which the model reports in leaf 7 and +// whose instructions are #UD without it ("If any corresponding CPUID +// feature flag is '0'", Vol.2A Table 2-46 and the other EVEX exception +// classes; "If relevant CPUID feature flag is '0'", Tables 2-65 and 2-66 +// of the opmask instructions). evex_extension in insn_evex_forms.sail +// gives each EVEX form its extension; AVX512VL adds the 128- and 256-bit +// forms of the instructions that have a 512-bit form. +register has_avx512f : bool // CPUID.07H:EBX[16] +register has_avx512dq : bool // CPUID.07H:EBX[17] +register has_avx512_ifma : bool // CPUID.07H:EBX[21] +register has_avx512pf : bool // CPUID.07H:EBX[26] — VGATHERPF*, VSCATTERPF* (Xeon Phi) +register has_avx512er : bool // CPUID.07H:EBX[27] — VEXP2*, VRCP28*, VRSQRT28* (Xeon Phi) +register has_avx512cd : bool // CPUID.07H:EBX[28] +register has_avx512bw : bool // CPUID.07H:EBX[30] +register has_avx512vl : bool // CPUID.07H:EBX[31] +register has_avx512_vbmi : bool // CPUID.07H:ECX[1] +register has_avx512_vbmi2 : bool // CPUID.07H:ECX[6] +register has_avx512_vnni : bool // CPUID.07H:ECX[11] — EVEX VPDPBUSD/VPDPBUSDS/VPDPWSSD/VPDPWSSDS +register has_avx512_bitalg : bool // CPUID.07H:ECX[12] +register has_avx512_vpopcntdq : bool // CPUID.07H:ECX[14] +register has_avx512_vp2intersect : bool // CPUID.07H:EDX[8] +// The XSAVE extensions of CPUID.(0DH,1):EAX (SDM Vol.1 §13.2 p.13-3, +// Table 21-35): "If EAX[0] = 0, execution of XSAVEOPT causes an +// invalid-opcode exception (#UD)"; EAX[1], "the compacted format", XSAVEC +// and "the compacted form of XRSTOR"; EAX[2], XGETBV with ECX = 1; EAX[3], +// XSAVES, XRSTORS and IA32_XSS ("an attempt to access the IA32_XSS MSR +// using RDMSR or WRMSR causes a general-protection exception (#GP)" +// without it); EAX[4], extended feature disable (§13.14: IA32_XFD and +// IA32_XFD_ERR). +register has_xsaveopt : bool +register has_xsavec : bool +register has_xgetbv1 : bool +register has_xsaves : bool +register has_xfd : bool +register has_avx512_fp16 : bool // CPUID.07H:EDX[23] — AVX512-FP16 (EVEX maps 5 and 6, and 0F3A forms) +register has_avx512_bf16 : bool // CPUID.(07H,1):EAX[5] +register has_la57 : bool // CPUID.07H:ECX[16] — 5-Level Paging +register has_vmx : bool // CPUID.01H:ECX[5] — VMX support +register has_amx_tile : bool // CPUID.07H:EDX[24] — AMX tile architecture (LDTILECFG, TILELOADD, ...) +register has_amx_int8 : bool // CPUID.07H:EDX[25] — TDPBSSD/TDPBSUD/TDPBUSD/TDPBUUD +register has_amx_bf16 : bool // CPUID.07H:EDX[22] — TDPBF16PS +register has_prefetchw : bool // CPUID.80000001H:ECX[8] — PREFETCHW (0F 0D /1; a NOP either way) +register has_cldemote : bool // CPUID.07H:ECX[25] — CLDEMOTE (0F 1C /0; a NOP either way) +register has_waitpkg : bool // CPUID.07H:ECX[5] — TPAUSE, UMONITOR, UMWAIT and IA32_UMWAIT_CONTROL +// SMAP (CPUID.07H:EBX[20]): CLAC and STAC are #UD without it (SDM Vol.2A +// CLAC, Vol.2B STAC; APM Vol.3 CLAC, STAC). The model has the +// instructions but not CR4.SMAP's access checks, so no profile sets it; +// the KVM harness gives it the guest's value. +register has_smap : bool +// PTWRITE (F3 0F AE /4) is #UD unless CPUID.(14H,0):EBX[4] = 1 (SDM Vol.2B +// PTWRITE), a leaf of Intel PT, which CPUID.07H:EBX[25] reports (SDM +// §36.3.1). The model has no processor trace (no IA32_RTIT_* MSRs), so +// no profile sets it; the KVM harness gives it the host's value, as the +// guest executes PTWRITE natively. +register has_ptwrite : bool +// AMD SSE4A (EXTRQ, INSERTQ, MOVNTSS, MOVNTSD) is #UD unless CPUID +// Fn8000_0001_ECX[SSE4A] (bit 6) = 1 (AMD APM Vol.4 EXTRQ, INSERTQ, +// MOVNTSD, MOVNTSS). The profiles describe the "GenuineIntel" processor +// the CPUID presents, so none sets it; the KVM harness gives it the +// host's value. +register has_sse4a : bool +// AMD Misaligned SSE mode, CPUID Fn8000_0001_ECX[MisAlignSse] (bit 7; +// APM Vol.3 Appendix E p.649): MXCSR.MM (bit 17) then exists and masks the +// #GP of a misaligned legacy SSE memory operand (check_sse_src_alignment +// in insn_modrm.sail; APM Vol.1 §4.2.2 p.118, §4.3.2 p.120). "The +// corresponding MXCSR_MASK bit (17) is 1", so a machine with it reports +// that bit in MXCSR_MASK as well. No enable_features_* profile sets it; +// the KVM harness sets it, and MXCSR_MASK, from the host. +register has_misalignsse : bool + +// MXCSR_MASK, the value FXSAVE and XSAVE store at bytes 31:28 of the +// legacy region: "All bits set to 0 in the MXCSR_MASK value indicate +// reserved bits in the MXCSR register", which LDMXCSR, FXRSTOR and XRSTOR +// may not set (#GP(0)), and "If the value of the MXCSR_MASK field is +// 00000000H, then the MXCSR_MASK value is the default value of 0000FFBFH" +// (SDM Vol.1 §11.6.6 p.11-21; APM Vol.2 §11.5.10 p.364). The value is the +// implementation's, which software reads from an FXSAVE image; the KVM +// harness sets the host's. The default is bits 15:0, DAZ included. +register MXCSR_MASK : dword = 0x0000FFFF + +// The XSAVE layout of the user state components the model implements: +// 2 (AVX), 5-7 (AVX-512) and 17-18 (AMX). For each, CPUID.(0DH,i) "EAX +// enumerates the size (in bytes) required for state component i", "EBX +// enumerates the offset (in bytes, from the base of the XSAVE area) of the +// section used for state component i" in the standard format, and "If +// ECX[1] returns 1, state component i is located on the next 64-byte +// boundary following the preceding state component" in the compacted one +// (SDM Vol.1 §13.2 p.13-4, §13.4.3; APM Vol.2 §11.5.3, Table 11-6). +// Neither manual fixes the offsets or the alignment, so they are the +// implementation's; the KVM harness sets the host's. Indexed by +// component; a component the processor does not support has size 0. +register xsave_comp_size : vector(19, dword) +register xsave_comp_offset : vector(19, dword) +register xsave_comp_align : vector(19, bool) + +val set_xsave_component : (range(0, 18), int, int, bool) -> unit +function set_xsave_component(i, size, offset, align) = { + xsave_comp_size[i] = get_slice_int(32, size, 0); + xsave_comp_offset[i] = get_slice_int(32, offset, 0); + xsave_comp_align[i] = align +} + +// The user-level monitor of UMONITOR/UMWAIT (SDM Vol.2B): armed by +// UMONITOR, consumed by UMWAIT. Stores to the monitored range are not +// tracked; UMWAIT is taken to run to its deadline, which the SDM allows. +register umonitor_armed : bool = false + +// IA32_PASID (D93H; SDM Vol.2A ENQCMD, and Vol.4 Table 2-2): bits 19:0 +// hold the process address space identifier that ENQCMD puts in bits 19:0 +// of its command, bit 31 whether it is valid (ENQCMD is #GP(0) while it is +// 0); bits 30:20 and 63:32 are reserved. The MSR exists with ENQCMD. The +// model starts it at 0, no valid PASID, as a thread that was given none +// has it (a KVM guest, which cannot write it, runs with that value). +// XSAVES and XRSTORS manage it as supervisor state component 10, PASID +// state (CPUID.0DH.01H:ECX[10]), which the model does not implement: +// IA32_XSS supports no component. +register IA32_PASID : qword = zeros() + +// ========================================================================= +// Intel AMX tile state (SDM Vol.1 Chapter 19) +// +// Palette 1, the only non-INIT palette, has eight tiles of at most 16 rows +// by 64 bytes (CPUID.1DH.01H). TILECFG holds the palette, the restart row +// of an interrupted tile load or store, and each tile's shape; a tile whose +// rows and colsb are both zero is not valid. TMM holds the rows, tile t +// row r at index 16 * t + r. TILES_CONFIGURED of the SDM is +// tilecfg_palette != 0. XSAVE manages TILECFG as component 17 and the +// 8 KB of tile data as component 18. +// ========================================================================= + +register tilecfg_palette : byte = 0x00 +register tilecfg_start_row : byte = 0x00 +register tilecfg_colsb : vector(8, word) +register tilecfg_rows : vector(8, byte) +register TMM : vector(128, zmmword) + +// Extended feature disable (SDM Vol.1 §13.14; CPUID.0DH.01H:EAX[4]): +// IA32_XFD (1C4H) disables the state components whose bits it and XCR0 +// both have, and IA32_XFD_ERR (1C5H) names the components an instruction +// faulted on (#NM). Only bit 18 (TILEDATA) can be set (xfd_supported in +// insn_xsave.sail); both reset to zero. +register IA32_XFD : qword = zeros() +register IA32_XFD_ERR : qword = zeros() + +// zero_all_tile_data of the SDM. +val amx_zero_all_tiles : unit -> unit +function amx_zero_all_tiles() = { + foreach (i from 0 to 127) { + TMM[i] = zeros() + } +} + +// TILECFG in its INIT state: palette 0, TILES_CONFIGURED = 0. +val amx_init_tilecfg : unit -> unit +function amx_init_tilecfg() = { + tilecfg_palette = 0x00; + tilecfg_start_row = 0x00; + foreach (n from 0 to 7) { + tilecfg_colsb[n] = 0x0000; + tilecfg_rows[n] = 0x00 + } +} + +// ========================================================================= +// XCR0 / feature check helpers +// ========================================================================= + +// AVX enabled: CR4.OSXSAVE(bit 18)=1 and XCR0.SSE(bit 1)=1, AVX(bit 2)=1 +val avx_enabled : unit -> bool +function avx_enabled() = + CR4[18] == 0b1 & XCR0[2] == 0b1 & XCR0[1] == 0b1 + +// The state requirement of the AVX-512 instructions, the EVEX-encoded and +// the opmask ones: "software can execute Intel AVX-512 instructions only +// if CR4.OSXSAVE = 1 and XCR0[7:5] = 111b. Otherwise, any execution of an +// Intel AVX-512 instruction causes an invalid-opcode exception (#UD)" +// (SDM Vol.1 §13.3, p. 13-5; Vol.2A Table 2-39: "111xx111b", and +// "111xxx11b" for the opmask instructions, a difference XSETBV leaves no +// room for: it allows XCR0[7:5] = 111b only with XCR0[2:1] = 11b, §13.3). +// Their CPUID features are checked per instruction (evex_check_form, +// vex_check_form). +val avx512_enabled : unit -> bool +function avx512_enabled() = + avx_enabled() & XCR0[5] == 0b1 & XCR0[6] == 0b1 & XCR0[7] == 0b1 + +// ========================================================================= +// Convenience functions: configure features by processor level +// ========================================================================= + +// x86-64-v1: Baseline 64-bit (SSE2 only, no extensions) +val enable_features_v1 : unit -> unit +function enable_features_v1() = { + // CR0: clear EM, set MP + CR0 = (CR0 & 0xFFFFFFFFFFFFFFFB) | 0x0000000000000002; + // CR4: OSFXSR + OSXMMEXCPT + CR4 = CR4 | 0x0000000000000600; + XCR0_SUPPORTED = 0x0000000000000003; // x87 + SSE + XCR0 = 0x0000000000000003; + // All CPUID features off + has_sse3 = false; + has_ssse3 = false; + has_sse4_1 = false; + has_sse4_2 = false; + has_cx16 = false; + has_popcnt = false; + has_lzcnt = false; + has_bmi1 = false; + has_bmi2 = false; + has_fma = false; + has_aesni = false; + has_pclmulqdq = false; + has_vpclmulqdq = false; + has_vaes = false; + has_gfni = false; + has_avx_vnni = false; + has_f16c = false; + has_movbe = false; + has_adx = false; + has_sha = false; + has_rdrand = false; + has_rdseed = false; + has_rdpid = false; + has_crc32 = false; + has_movdiri = false; + has_movdir64b = false; + has_enqcmd = false; + has_xsave = false; + has_avx512f = false; + has_avx512dq = false; + has_avx512_ifma = false; + has_avx512pf = false; + has_avx512er = false; + has_avx512cd = false; + has_avx512bw = false; + has_avx512vl = false; + has_avx512_vbmi = false; + has_avx512_vbmi2 = false; + has_avx512_vnni = false; + has_avx512_bitalg = false; + has_avx512_vpopcntdq = false; + has_avx512_vp2intersect = false; + has_xsaveopt = false; + has_xsavec = false; + has_xgetbv1 = false; + has_xsaves = false; + has_xfd = false; + has_avx512_fp16 = false; + has_avx512_bf16 = false; + has_vmx = false; + has_la57 = false; + has_amx_tile = false; + has_amx_int8 = false; + has_amx_bf16 = false; + has_prefetchw = false; + has_cldemote = false; + has_ptwrite = false; + has_sse4a = false; + has_misalignsse = false; + has_waitpkg = false; + MXCSR_MASK = 0x0000FFFF; + // No extended state component: x87 and SSE are in the legacy region. + foreach (i from 0 to 18) { + set_xsave_component(i, 0, 0, false) + } +} + +// x86-64-v2: Nehalem+ (SSE4.2, POPCNT, CMPXCHG16B) +val enable_features_v2 : unit -> unit +function enable_features_v2() = { + enable_features_v1(); + has_sse3 = true; + has_ssse3 = true; + has_sse4_1 = true; + has_sse4_2 = true; + has_cx16 = true; + has_xsave = true; + has_xsaveopt = true; + has_xsavec = true; + has_xgetbv1 = true; + has_xsaves = true; + has_popcnt = true; + has_crc32 = true; + has_pclmulqdq = true; + has_vmx = true +} + +// x86-64-v3: Haswell+ (AVX2, FMA, BMI1/2, MOVBE, F16C) +val enable_features_v3 : unit -> unit +function enable_features_v3() = { + enable_features_v2(); + CR4 = CR4 | 0x0000000000040000; // OSXSAVE + XCR0_SUPPORTED = 0x0000000000000007; // x87 + SSE + AVX + XCR0 = 0x0000000000000007; + // The extended region starts right after the 64-byte header. + set_xsave_component(2, 256, 576, false); + has_bmi1 = true; + has_bmi2 = true; + has_fma = true; + has_lzcnt = true; + has_f16c = true; + has_movbe = true; + has_rdrand = true; + has_aesni = true; + has_adx = true; + has_prefetchw = true // Broadwell and later +} + +// x86-64-v4 and everything above it that the model implements: AVX-512 +// (F/CD/BW/DQ/VL, IFMA, VBMI, VBMI2, VNNI, BITALG, VPOPCNTDQ, +// VP2INTERSECT, FP16, BF16), SHA, RDSEED, GFNI, VAES, VPCLMULQDQ, AVX-VNNI +val enable_features_v4 : unit -> unit +function enable_features_v4() = { + enable_features_v3(); + XCR0_SUPPORTED = 0x00000000000000E7; // + opmask + ZMM_Hi256 + Hi16_ZMM + XCR0 = 0x00000000000000E7; + // The places of the MPX components 3 and 4 (960 and 1024, 64 bytes + // each) stay unused. + set_xsave_component(5, 64, 1088, false); + set_xsave_component(6, 512, 1152, false); + set_xsave_component(7, 1024, 1664, false); + has_avx512f = true; + has_avx512dq = true; + has_avx512_ifma = true; + has_avx512cd = true; + has_avx512bw = true; + has_avx512vl = true; + has_avx512_vbmi = true; + has_avx512_vbmi2 = true; + has_avx512_vnni = true; + has_avx512_bitalg = true; + has_avx512_vpopcntdq = true; + has_avx512_vp2intersect = true; + has_avx512_fp16 = true; + has_avx512_bf16 = true; + has_rdseed = true; + has_rdpid = true; + has_sha = true; + has_vpclmulqdq = true; + has_vaes = true; + has_gfni = true; + has_avx_vnni = true +} + +// Everything the model implements: x86-64-v4 plus Intel AMX (AMX-TILE, +// AMX-INT8, AMX-BF16), whose tile state XCR0 bits 17 and 18 enable, and +// AVX512ER and AVX512PF, the extensions of the Xeon Phi processors only +// (SDM Vol.1 Table 21-19). +val enable_features_all : unit -> unit +function enable_features_all() = { + enable_features_v4(); + XCR0_SUPPORTED = XCR0_SUPPORTED | 0x0000000000060000; // + TILECFG + TILEDATA + XCR0 = XCR0 | 0x0000000000060000; + has_avx512er = true; + has_avx512pf = true; + // After the PKRU component (9, 2688, 8 bytes), each 64-byte aligned in + // the compacted format. + set_xsave_component(17, 64, 2752, true); + set_xsave_component(18, 8192, 2816, true); + has_xfd = true; + has_amx_tile = true; + has_amx_int8 = true; + has_amx_bf16 = true; + has_cldemote = true; + has_waitpkg = true; + has_enqcmd = true +} + +// ========================================================================= +// System mode flag +// +// When true, faults are delivered via IDT (system-level emulation). +// When false, faults return to the C++ harness (user-mode emulation). +// ========================================================================= + +register system_mode : bool + +// Exception delivery nesting depth (0 = normal, 1 = delivering, 2 = double fault) +// Used to detect double fault and triple fault conditions. +register exception_depth : range(0, 3) + +// Class of the exception currently being delivered (for escalation decisions). +register delivering_exc_class : ExceptionClass + +// ========================================================================= +// System Management Mode (SMM) — SDM Vol.3C Chapter 34 +// +// in_smm: true when the processor is in SMM. RSM is only valid in SMM. +// smbase: base physical address of SMRAM. Default 0x30000 after reset. +// Updated from SMRAM state save area (offset 7EF8h) on each RSM. +// ========================================================================= + +register in_smm : bool = false +register smbase : dword = 0x00030000 + +// ========================================================================= +// VMX (VT-x) State — SDM Vol.3C Chapter 24 +// +// in_vmx_root: true when in VMX root operation (hypervisor) +// in_vmx_non_root: true when in VMX non-root operation (guest) +// vmcs_ptr: physical address of the current VMCS (None if no current VMCS) +// vmxon_region_pa: physical address of the VMXON region +// vmcs: cached VMCS data (serialized to memory by VMCLEAR) +// ========================================================================= + +register in_vmx_root : bool = false +register in_vmx_non_root : bool = false +register vmcs_ptr : option(qword) = None() +register vmxon_region_pa : qword = zeros() +register vmcs : VMCS_data = default_vmcs() + +// IA32_FEATURE_CONTROL MSR (0x3A) +// Bit 0: Lock — once set, WRMSR to this MSR causes #GP(0) +// Bit 1: Enable VMX in SMX operation +// Bit 2: Enable VMX outside SMX operation +// Default: locked + VMX-outside-SMX enabled (bits 0 and 2) +register ia32_feature_control : qword = 0x0000000000000005 + +// Cached EPT-active flag. Set by vm_entry(), cleared by complete_vm_exit(). +// Avoids re-reading VMCS control bits on every phys_read/phys_write. +register ept_active : bool = false + +// ========================================================================= +// A20 gate +// +// When disabled, physical address bit 20 is forced to zero, causing +// the 1MB address space to wrap around (real-mode compatibility). +// On reset, A20 is disabled. Enabled via port 0x92 or keyboard controller. +// ========================================================================= + +register a20_enabled : bool = false diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail new file mode 100644 index 000000000..530361b0d --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail @@ -0,0 +1,222 @@ +// x86-64 — RFLAGS Register and Flag Computation + +// RFLAGS register. We model individual flags as separate registers +// for clarity, since different instructions update different subsets. + +register CF : bit // Carry Flag +register PF : bit // Parity Flag +register AF : bit // Auxiliary Carry Flag +register ZF : bit // Zero Flag +register SF : bit // Sign Flag +register OF : bit // Overflow Flag +register DF : bit // Direction Flag +register IF_flag : bit // Interrupt Enable Flag (IF is a Sail keyword) +register TF : bit // Trap Flag +register IOPL : bits(2) // I/O Privilege Level +register NT : bit // Nested Task +register RF : bit // Resume Flag +register VIF : bit = 0b0 // Virtual Interrupt Flag +register VIP : bit = 0b0 // Virtual Interrupt Pending +register ID : bit // ID Flag (CPUID available if toggleable) +register AC_flag : bit // Alignment Check flag + +// Pack individual flags into a 64-bit RFLAGS value. +// Bits: 0=CF, 1=1(reserved), 2=PF, 4=AF, 6=ZF, 7=SF, 8=TF, 9=IF, 10=DF, +// 11=OF, 13:12=IOPL, 14=NT, 16=RF, 17=VM, 18=AC, 19=VIF, 20=VIP, 21=ID +val read_rflags : unit -> qword +function read_rflags() = { + var r : qword = zeros(); + r[0] = CF; + r[1] = 0b1; // reserved, always 1 + r[2] = PF; + r[4] = AF; + r[6] = ZF; + r[7] = SF; + r[8] = TF; + r[9] = IF_flag; + r[10] = DF; + r[11] = OF; + r[13..12] = IOPL; + r[14] = NT; + r[16] = RF; + r[17] = if cur_mode == Virtual8086Mode then bitone else bitzero; + r[18] = AC_flag; + r[19] = VIF; + r[20] = VIP; + r[21] = ID; + r +} + +// Write all individual flags from a packed RFLAGS value. +// This sets CF, PF, AF, ZF, SF, TF, IF, DF, OF, IOPL, NT, AC, ID. +// RF, VM, VIF and VIP are NOT set (they have special handling). +val write_rflags : qword -> unit +function write_rflags(v) = { + CF = v[0]; + PF = v[2]; + AF = v[4]; + ZF = v[6]; + SF = v[7]; + TF = v[8]; + IF_flag = v[9]; + DF = v[10]; + OF = v[11]; + IOPL = v[13..12]; + NT = v[14]; + AC_flag = v[18]; + ID = v[21]; +} + +// MOV to/from CRn and DRn: "The OF, SF, ZF, AF, PF, and CF flags are +// undefined" (SDM Vol.2B MOV—Move to/from Control Registers, 4-33; +// MOV—Move to/from Debug Registers, 4-35), where the APM has "rFLAGS +// Affected: None" (Vol.3 MOV CRn p.427, MOV DRn p.428), one of the values +// the SDM allows. Call only after the access succeeds, so faults retain +// the original flags. +val finish_system_register_move : unit -> unit +function finish_system_register_move() = { + CF = undefined; + PF = undefined; + AF = undefined; + ZF = undefined; + SF = undefined; + OF = undefined +} + +// Compute the parity of the low 8 bits of a value. +// PF is set if the number of set bits in the low byte is even. +val compute_PF : byte -> bit +function compute_PF(val8) = { + let r4 : bits(4) = val8[7..4] ^ val8[3..0]; + let r2 : bits(2) = r4[3..2] ^ r4[1..0]; + let r1 : bits(1) = r2[1] ^ r2[0]; + // PF=1 means even parity, so invert + (~(r1))[0] +} + +// Update SF, ZF, PF based on a result value. +// These three flags are set identically by most arithmetic/logic instructions. +val update_SF_ZF_PF : forall 'n, 'n >= 8. bits('n) -> unit +function update_SF_ZF_PF(result) = { + SF = result['n - 1]; + let zf_wide : bits('n + 1) = (0b0 @ result) - 1; + ZF = zf_wide['n]; + PF = compute_PF(result[7..0]) +} + +// Compute OF, AF, SF, ZF, PF for addition without modifying CF. +// Used by INC which must preserve CF. +val update_flags_add_no_cf : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit +function update_flags_add_no_cf(result, a, b) = { + OF = (~(a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; + let af_wide : bits(5) = (0b0 @ a[3..0]) + (0b0 @ b[3..0]); + AF = af_wide[4]; + update_SF_ZF_PF(result) +} + +// Compute OF, AF, SF, ZF, PF for subtraction without modifying CF. +// Used by DEC which must preserve CF. +val update_flags_sub_no_cf : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit +function update_flags_sub_no_cf(result, a, b) = { + OF = ((a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; + let af_wide : bits(5) = (0b0 @ a[3..0]) - (0b0 @ b[3..0]); + AF = af_wide[4]; + update_SF_ZF_PF(result) +} + +// Compute CF and OF for addition: dest = a + b. +val update_flags_add : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit +function update_flags_add(result, a, b) = { + // CF: carry bit from wide addition + let cf_wide : bits('n + 1) = (0b0 @ a) + (0b0 @ b); + CF = cf_wide['n]; + // OF: signed overflow — same sign inputs, different sign result + OF = (~(a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; + // AF: carry out of bit 3 + let af_wide : bits(5) = (0b0 @ a[3..0]) + (0b0 @ b[3..0]); + AF = af_wide[4]; + update_SF_ZF_PF(result) +} + +// Compute CF and OF for subtraction: dest = a - b. +val update_flags_sub : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit +function update_flags_sub(result, a, b) = { + // CF: borrow bit from wide subtraction + let cf_wide : bits('n + 1) = (0b0 @ a) - (0b0 @ b); + CF = cf_wide['n]; + // OF: signed overflow — different sign inputs, result sign differs from a + OF = ((a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; + // AF: borrow out of bit 3 + let af_wide : bits(5) = (0b0 @ a[3..0]) - (0b0 @ b[3..0]); + AF = af_wide[4]; + update_SF_ZF_PF(result) +} + +// Compute CF and OF for addition with carry: dest = a + b + carry_in. +val update_flags_adc : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n), bit) -> unit +function update_flags_adc(result, a, b, carry_in) = { + // CF: carry bit from wide addition with carry_in + let cf_wide : bits('n + 1) = (0b0 @ a) + (0b0 @ b) + zero_extend(carry_in); + CF = cf_wide['n]; + // OF: signed overflow from wide signed addition + let of_wide : bits('n + 1) = sign_extend(a) + sign_extend(b) + zero_extend(carry_in); + OF = (of_wide['n .. 'n] ^ of_wide['n - 1 .. 'n - 1])[0]; + // AF: nibble carry with carry_in + let af_wide : bits(5) = (0b0 @ a[3..0]) + (0b0 @ b[3..0]) + zero_extend(carry_in); + AF = af_wide[4]; + update_SF_ZF_PF(result) +} + +// Compute CF and OF for subtraction with borrow: dest = a - b - borrow_in. +val update_flags_sbb : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n), bit) -> unit +function update_flags_sbb(result, a, b, borrow_in) = { + // CF: borrow bit from wide subtraction with borrow_in + let cf_wide : bits('n + 1) = (0b0 @ a) - (0b0 @ b) - zero_extend(borrow_in); + CF = cf_wide['n]; + // OF: signed overflow from wide signed subtraction + let of_wide : bits('n + 1) = sign_extend(a) - sign_extend(b) - zero_extend(borrow_in); + OF = (of_wide['n .. 'n] ^ of_wide['n - 1 .. 'n - 1])[0]; + // AF: nibble borrow with borrow_in + let af_wide : bits(5) = (0b0 @ a[3..0]) - (0b0 @ b[3..0]) - zero_extend(borrow_in); + AF = af_wide[4]; + update_SF_ZF_PF(result) +} + +// Evaluate an x86 condition code (4-bit, from Jcc/CMOVcc/SETcc opcodes). +// The condition codes correspond to the low 4 bits of the opcode: +// 0=O 1=NO 2=B 3=AE 4=E 5=NE 6=BE 7=A +// 8=S 9=NS A=P B=NP C=L D=GE E=LE F=G +type cc_idx = range(0, 15) + +val eval_cc : cc_idx -> bit +function eval_cc(cc) = { + let sf_ne_of : bits(1) = SF ^ OF; + let results : bits(16) = + (~(ZF) & ~(sf_ne_of)) @ // F: G/NLE + (ZF | sf_ne_of) @ // E: LE/NG + (~(sf_ne_of)) @ // D: GE/NL + sf_ne_of @ // C: L/NGE + (~(PF)) @ // B: NP/PO + PF @ // A: P/PE + (~(SF)) @ // 9: NS + SF @ // 8: S + (~(CF) & ~(ZF)) @ // 7: A/NBE + (CF | ZF) @ // 6: BE/NA + (~(ZF)) @ // 5: NE/NZ + ZF @ // 4: E/Z + (~(CF)) @ // 3: AE/NB/NC + CF @ // 2: B/C/NAE + (~(OF)) @ // 1: NO + OF; // 0: O + results[cc] +} + +// Update flags for logical operations (AND, OR, XOR). +// CF and OF are cleared; AF is undefined per SDM. +val update_flags_logic : forall 'n, 'n >= 8. bits('n) -> unit +function update_flags_logic(result) = { + CF = 0b0; + OF = 0b0; + AF = undefined; + update_SF_ZF_PF(result) +} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project b/crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project new file mode 100644 index 000000000..1a82f420a --- /dev/null +++ b/crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project @@ -0,0 +1,66 @@ +prelude { + files + prelude.sail, +} + +core { + requires prelude + + files + core_types.sail, + extern.sail, + vmx_types.sail, + regs.sail, + rflags.sail, + exceptions.sail, + paging.sail, + mem.sail, + interrupts.sail, + vm86.sail, + vmx_vmcs.sail, +} + +decode { + requires prelude, core + + files + operands.sail, + branchless.sail, + crypto.sail, + insn_simd.sail, + insn_prefixes.sail, + insn_modrm.sail, + smm.sail, + vmx.sail, + insn_vmx.sail, + insn_alu.sail, + insn_x87.sail, + insn_sse_fp.sail, + insn_sse_int.sail, + insn_mmx.sail, + insn_xsave.sail, + insn_baseline.sail, + insn_groups.sail, + insn_fma.sail, + insn_sse4_helpers.sail, + insn_vex.sail, + insn_vex_imm.sail, + insn_vex_fp.sail, + insn_vex_int.sail, + insn_vex_fma.sail, + insn_vex_arith.sail, + insn_amx.sail, + insn_vex_dispatch.sail, + insn_evex.sail, + insn_evex_fp.sail, + insn_evex_int.sail, + insn_evex_fma.sail, + insn_evex_perm.sail, + insn_evex_arith.sail, + insn_evex_fp16.sail, + insn_evex_imm.sail, + insn_evex_forms.sail, + insn_evex_dispatch.sail, + insn_dispatch.sail, + fetch_execute.sail, +} diff --git a/crates/clazel-x64/tests/generated/acl2_x86isa.rs b/crates/clazel-x64/tests/generated/acl2_x86isa.rs new file mode 100644 index 000000000..add76bc18 --- /dev/null +++ b/crates/clazel-x64/tests/generated/acl2_x86isa.rs @@ -0,0 +1,86 @@ +// @generated by `cargo xtask testdata` from tests/data/acl2-x86isa/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, commit and license: tests/data/acl2-x86isa/SOURCE.md. +// +// ACL2 x86isa model files for the subset of jit.md item J.3. +// 63 files, 2498309 bytes. Nothing here is parsed yet; see the converter's +// header for why. Paths are relative to tests/data/acl2-x86isa/. + +/// One vendored file. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct File { + /// Its path under the suite directory, with `/` separators. + pub path: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every vendored file, sorted by path. +pub const FILES: &[File] = &[ + File { path: "LICENSE.md", size: 2084, sha256: "358ca43cd493116dda153fe67419f197fd0e99ece9345f8fdff60d8584849a9d" }, + File { path: "README", size: 885, sha256: "aa46c3ff7f21b161d694157c06a03e2784f0c3389485b5d7f322eb8b04fbdc08" }, + File { path: "machine/application-level-memory.lisp", size: 51838, sha256: "51bbf413b44a70942ccec94f9e1d247bb23503b81c18cb939275e6374a88f2b0" }, + File { path: "machine/decoding-and-spec-utils.lisp", size: 106265, sha256: "00f4a139072bd13de4e00d827bb225830108d838d8f196dc2a499159fb1fa383" }, + File { path: "machine/dispatch-creator.lisp", size: 21526, sha256: "17f3a704ba6041ebab9b1e1d4254c68ef76635dc116851a4e98a00c49db6d37e" }, + File { path: "machine/dispatch-macros.lisp", size: 13155, sha256: "027979da1fd7d9c26c68cc54e7cb358237a3f0bb04e3a8b5b0fbed7973b6e81d" }, + File { path: "machine/get-prefixes.lisp", size: 38098, sha256: "17617d8444efef6e37b292553518a3adadc009cb486d869fef9814a2445d6877" }, + File { path: "machine/guard-helpers.lisp", size: 19563, sha256: "3095906b0862fa40e749a84c64b6e1f1c57198c0d2afed165afda442c1b6d5ea" }, + File { path: "machine/inst-listing.lisp", size: 729751, sha256: "ccd90ab0a20598ac2580e4cf03f207e6782a43539ae317b0d139018978d69489" }, + File { path: "machine/inst-structs.lisp", size: 38432, sha256: "ca4bc17048ed0f93341aa667f9b984a68cde0b531eeee2a731564e6b34335aac" }, + File { path: "machine/instructions/add-spec.lisp", size: 20163, sha256: "4f639d319104d719445f4b63fb8349049b03a6c22527b0375db4367017e490a5" }, + File { path: "machine/instructions/and-spec.lisp", size: 5947, sha256: "fcb575d589e15efc7502f4ba2ae5e23acf63549ad831ffe7ad519f98703bd465" }, + File { path: "machine/instructions/arith-and-logic-spec.lisp", size: 5516, sha256: "a071236e1611f9ebf664a30b566a18635bd6cfc1e433a6e1600977cad64fde64" }, + File { path: "machine/instructions/arith-and-logic.lisp", size: 38875, sha256: "809dead722587e3360243a70d16c2bdddd8f04691da64bc0b7031d6037d6de64" }, + File { path: "machine/instructions/conditional.lisp", size: 25168, sha256: "f0fcc6408d94369d234ad0eecd1af05703975497c11304f9cad9a6d484a81c15" }, + File { path: "machine/instructions/flags.lisp", size: 6224, sha256: "ef3954e8e310434161956bb50f11c761ef9cc77d0d9b559920977b8301840048" }, + File { path: "machine/instructions/fp/add-mul-spec.lisp", size: 7750, sha256: "83322d45ee3b53caa6ca87d1385b73a6b844ea3d839430a322fb25017438b24a" }, + File { path: "machine/instructions/fp/arith-spec.lisp", size: 12549, sha256: "a6a39f4fc322900e31fc871aa818a14f6ea9e07a12e08b9d910d3603ca37373d" }, + File { path: "machine/instructions/fp/arithmetic.lisp", size: 25835, sha256: "99daa7e127b5c5e4cb438dac7f33d122c3a826d082811ddb7bafee29d6b3955f" }, + File { path: "machine/instructions/fp/base.lisp", size: 14803, sha256: "d8c9a763f6ddbdf0f4f74334ccbecb61b0a4425b78958fc44eaef55d51141e05" }, + File { path: "machine/instructions/fp/cmp-spec.lisp", size: 12052, sha256: "0d54f6ec2fec0c03c9571f53cedc62b93926e461193a7f44b18b2e62a31893da" }, + File { path: "machine/instructions/fp/convert.lisp", size: 18745, sha256: "869f6ed9a170bd0b4690dcc2766888aabd18e1908901fd03b2a00a637e714cef" }, + File { path: "machine/instructions/fp/cvt-spec.lisp", size: 22086, sha256: "64e02b07965a80fcd786df9a95087fba93c4d7e617755f2e0eb263d067f720bb" }, + File { path: "machine/instructions/fp/mxcsr.lisp", size: 5562, sha256: "7aee2ad7b72525572bfcebd3ec892af0650a312b784c490ad394a4e2e6b26597" }, + File { path: "machine/instructions/fp/sqrt-spec.lisp", size: 5998, sha256: "3c82aa74064b48cc4d235e11fbaa3b6a391cf4491041f0ff8f93be8383db5282" }, + File { path: "machine/instructions/fp/top.lisp", size: 3663, sha256: "1d35633b80b9d1bdb88bac6f747c388dfab0ed1c5adc5e307a2f965b209734d6" }, + File { path: "machine/instructions/jump-and-loop.lisp", size: 43822, sha256: "3f1bcff3bc0f26dd0af399397753c1b574ffdd50ef037fe8656f8aa013a6b7c0" }, + File { path: "machine/instructions/logical.lisp", size: 14329, sha256: "2416720a249e52a0a24950b0c7d8e96efeca577a1a58bf3d14fb1d48d346c42d" }, + File { path: "machine/instructions/move-sse.lisp", size: 49001, sha256: "40c080806fc345cd37d5df6b19edc3ab48ba55f825aabc08c083e6cb7fbaf885" }, + File { path: "machine/instructions/move.lisp", size: 43098, sha256: "74fede806e1fac56165482ccf9cbd31c791ee542e9a6ec0809285f1c092d4a76" }, + File { path: "machine/instructions/multiply-spec.lisp", size: 10396, sha256: "4c0640df3736ffd0f07d76d097b0cc61ee3dc127bab200d301eefd80a11b5b52" }, + File { path: "machine/instructions/multiply.lisp", size: 19277, sha256: "50fcc0670802417562162036ec217e4229e68860f2d34143fe3da29c34c4526a" }, + File { path: "machine/instructions/or-spec.lisp", size: 5746, sha256: "65acf2678d207c9b81e43c6016bdf7f439593814a55b92d649fcc8676d38233c" }, + File { path: "machine/instructions/rotate-and-shift.lisp", size: 23051, sha256: "514ff2887fce7aedf9a143819f8919d58bc61a72e77dfe427555bf9c3bb61545" }, + File { path: "machine/instructions/shifts-spec.lisp", size: 70054, sha256: "4eb4413a621e61c560b6ee3a5a7be414cac2dbaf7938172ccee5a9bed4c587db" }, + File { path: "machine/instructions/signextend.lisp", size: 4783, sha256: "49be47d36fc26ad9625ec082c72d5b43286ad3b4edf7f7429c043a6372944714" }, + File { path: "machine/instructions/sub-spec.lisp", size: 11567, sha256: "a145446a3e2f82fdc295f6e247fd318d98d6d1d965f75e5b7a20d53191fa4b1d" }, + File { path: "machine/instructions/subroutine.lisp", size: 42098, sha256: "875e470add5d25d87193f25f6a724efb38cac4950134f14c337a7b54cb20502f" }, + File { path: "machine/instructions/top.lisp", size: 5993, sha256: "44d6ea575aed8a0749213656ae37ff7fb52b246e52fa3b497451e7e2294adfb5" }, + File { path: "machine/instructions/xor-spec.lisp", size: 5776, sha256: "d8a90003f777a8bb971972a490eca625ba6121c7565b032f7c72cbf34f6aee73" }, + File { path: "machine/linear-memory.lisp", size: 324243, sha256: "0d45ab4110f9b55edd31f66e885f9a8c6c751336bc2771ade080ee32ed0d1e07" }, + File { path: "machine/modes.lisp", size: 7652, sha256: "f105ffdea6e18e37d99acfc9b4b4e5aaf3fb460dc4d2905890297078d7bbdd30" }, + File { path: "machine/physical-memory.lisp", size: 25360, sha256: "ce94b0ebffc17b73cc34598138e8e8959d73b1a2745b2c8585dd401de75da60c" }, + File { path: "machine/prefix-modrm-sib-decoding.lisp", size: 109322, sha256: "a063b7d2d5fe20df7b0419f066fb2d26f75cef9851dc23fcafea926393129adb" }, + File { path: "machine/register-readers-and-writers.lisp", size: 70591, sha256: "af682c8d8bd947b47d67730cc906c36e68e8484f7080f91ae2c25fc8e864dd38" }, + File { path: "machine/rflags-spec.lisp", size: 27997, sha256: "7b46bfb8b3eeb30b28938323359e7c456e7e2d1a672405458431e41afc50b507" }, + File { path: "machine/state.lisp", size: 38582, sha256: "fedde92511c2f38aaabcd95c12b671c88301e8776413f15f44aa76599bad29fa" }, + File { path: "machine/three-byte-opcodes-dispatch.lisp", size: 11337, sha256: "f72a45bd5b12437f5d8116de93ca87978150e736359e893a4cc76f94bf9611e7" }, + File { path: "machine/top-level-memory.lisp", size: 95243, sha256: "6f74e55e7cc6833fd34dad4b52e3e5f444f9067d205ddef52a9307e209d55e59" }, + File { path: "machine/two-byte-opcodes-dispatch.lisp", size: 10096, sha256: "c0f6f332823392a4e03e95e74482e9cead3bc6b2a73acb7278261f0eb9eb4822" }, + File { path: "machine/x86.lisp", size: 37437, sha256: "e73251b5ea07fdb524d3530006ed268be9ebe1756d9e85abb29d34d08c006f85" }, + File { path: "portcullis/package.lsp", size: 3482, sha256: "274d6fe165dc33e6d59d4cd53aec1751497e7de2eabd048ce8d0702c7bb4a5b9" }, + File { path: "portcullis/portcullis.lisp", size: 1880, sha256: "4eec69e015ec858fce1f611349eda9fd84eb25d55b83fe325776122abc60ee3c" }, + File { path: "portcullis/sharp-dot-constants.lisp", size: 25781, sha256: "276a19e1464e6fe21a3c8844bf63be80445de2b35ff2411809f07208d39d16db" }, + File { path: "portcullis/sharp-dot-defuns.lisp", size: 12566, sha256: "a37473f1b09ce248a1f69457daaee98697f8daee4cb186d295cc9dfe361b791e" }, + File { path: "portcullis/utils.lisp", size: 2887, sha256: "ebeebdc4aba0b47501c7e23ca54998bad142fb644961c26ae0c9ff74bfeae9a5" }, + File { path: "utils/basic-structs.lisp", size: 2732, sha256: "e62e2b1b3a3a524a1feadc81df723d0c302aa8b1a416c35b172a38595722a265" }, + File { path: "utils/fp-structures.lisp", size: 4686, sha256: "8eace3885f9ffcb01a825d9731eb848c5adb257a1fdf4609d9e5e01062616f07" }, + File { path: "utils/paging-structures.lisp", size: 11121, sha256: "b179a9bac6bdd9c485d01cda8cc38ea9eb91ae33fd0dce7132e1e98c57f47260" }, + File { path: "utils/records-0.lisp", size: 12865, sha256: "538f27ac8463b3058dcc7f0b3257c05384a5166f82d481be47910335df2e93fd" }, + File { path: "utils/segmentation-structures.lisp", size: 12902, sha256: "811a8ae74230fbeb5ec59b48246ebfe5d5cfcbf87463c3eb5b958cb43ef44862" }, + File { path: "utils/structures.lisp", size: 31620, sha256: "74fa6a8766f1f3a0fe65a91b67598854fa5dc04cb26f7862273a58a765960044" }, + File { path: "utils/utilities.lisp", size: 16403, sha256: "e1d5412ed5467d2b9cb2b3d77429f97bcb3fc6e01df1c6b89e9a41775d392b9b" }, +]; diff --git a/crates/clazel-x64/tests/generated/intel_sdm.rs b/crates/clazel-x64/tests/generated/intel_sdm.rs new file mode 100644 index 000000000..4dbb16fda --- /dev/null +++ b/crates/clazel-x64/tests/generated/intel_sdm.rs @@ -0,0 +1,22 @@ +// @generated by `cargo xtask testdata` from tests/data/intel-sdm/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, pins and license: tests/data/intel-sdm/SOURCE.md. +// +// Intel SDM volume 2, pinned by URL and SHA-256 (Intel's terms do not allow redistribution). + +/// A file the suite pins but does not vendor. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Pin { + /// The file's name in `SOURCE.md`. + pub file: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every pinned file. +pub const PINS: &[Pin] = &[ + Pin { file: "325383-093-sdm-vol-2abcd.pdf", size: 11294447, sha256: "d137a7887787bbb06c1a8b8bafd51958d8d2e16b4dff987a03226c845cca1516" }, +]; diff --git a/crates/clazel-x64/tests/generated/sail_x86_from_acl2.rs b/crates/clazel-x64/tests/generated/sail_x86_from_acl2.rs new file mode 100644 index 000000000..c141d5994 --- /dev/null +++ b/crates/clazel-x64/tests/generated/sail_x86_from_acl2.rs @@ -0,0 +1,73 @@ +// @generated by `cargo xtask testdata` from tests/data/sail-x86-from-acl2/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, commit and license: tests/data/sail-x86-from-acl2/SOURCE.md. +// +// Sail x86 model translated from the ACL2 one (jit.md item J.2); not independent of it. +// 50 files, 709571 bytes. Nothing here is parsed yet; see the converter's +// header for why. Paths are relative to tests/data/sail-x86-from-acl2/. + +/// One vendored file. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct File { + /// Its path under the suite directory, with `/` separators. + pub path: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every vendored file, sorted by path. +pub const FILES: &[File] = &[ + File { path: "LICENCE", size: 2011, sha256: "0d3b38d888099279e9f15482122d37ca994ec368837ad276028bf8a122d09b38" }, + File { path: "LICENSE.md", size: 4273, sha256: "b683c3f63ee3cb0740a59bd111611f34eb32b8629f4cefbcdeafa31639c43d00" }, + File { path: "README.md", size: 6249, sha256: "5e44846278a06d9ace245fbefd232ee6c1d499ababaabd5769eff9ae8b77d03d" }, + File { path: "model/LICENSE", size: 4273, sha256: "b683c3f63ee3cb0740a59bd111611f34eb32b8629f4cefbcdeafa31639c43d00" }, + File { path: "model/Makefile", size: 2025, sha256: "c237d56257789eb3d6818bc1196c73bb6c67d0c6b59711eb4eddbf91187d3d32" }, + File { path: "model/add_spec.sail", size: 7134, sha256: "906c53af7ddf16b8e18f83fde654d3e074e38f1022aa2f229c2e927b18fddf87" }, + File { path: "model/and_spec.sail", size: 2521, sha256: "f9a3c0f0c688be7851f7752ba7676ba5fbc9e7f1f64fdd4913af463f09b5ba6a" }, + File { path: "model/application_level_memory.sail", size: 864, sha256: "505188dad643f3b52474f4baf14be1bd894143fcc3c39005f3de5989f5a8f89e" }, + File { path: "model/arith_and_logic.sail", size: 18140, sha256: "0f710c88a2e3127a115ca1099a1c083975c05b4415ad899a196d9e2184ac7998" }, + File { path: "model/arith_and_logic_spec.sail", size: 4838, sha256: "b8faad856a8156119e46c3680d522a5de81cdd7d8a83af7de593dd66e80e8d8b" }, + File { path: "model/auxiliary.sail", size: 11801, sha256: "787712ec5130d758cb854c6749fde6414473121130b0f8324c9b73be97f67d2b" }, + File { path: "model/conditional.sail", size: 8581, sha256: "26ecaa0eea7a248d9d1c17210c07458a8709f0bb2f81ac0c4ed354b1eae5c4cd" }, + File { path: "model/config.sail", size: 2082, sha256: "bba58e1d5af2cc9401f93e80d4f4fee9602cdb191eb5196b2964c7068ff579f0" }, + File { path: "model/decoding_and_spec_utils.sail", size: 43068, sha256: "f4e70be76f7bb309554722f07bbe71157c08ecef1f37eb0e5cc3993e72296ea7" }, + File { path: "model/dispatch_macros.sail", size: 1067, sha256: "541fcf3e5e3df5dd9c83352d646815f03759369ba0500057ffb50e914506ff4d" }, + File { path: "model/environment.sail", size: 35, sha256: "33b613a3059d023a3b543b7a9ed5f28c2f80b6fefb2710844b9bdf438b5c7f25" }, + File { path: "model/init.sail", size: 180, sha256: "e330b0a9b0099ba699996e3a596890df0fd9caee61e2b814569aaf1388b04b4c" }, + File { path: "model/jump_and_loop.sail", size: 18720, sha256: "06c3c76defaf10697bf345d7a7bbb584d3100f53014b606c2e4694768c9a2ce4" }, + File { path: "model/linear_memory.sail", size: 18531, sha256: "de0f6a226a8d9619359334f3a063071b9baf763f402a82105aed12b1145b4c84" }, + File { path: "model/logging.sail", size: 1938, sha256: "de785bad9420d481654e5cd773892bc02c526b197ceec0747a759de39310b4ea" }, + File { path: "model/main.sail", size: 1795, sha256: "0e125c0e38c51eb076f4d482dc81384121af464972c3b3c7c6c148780571a6e0" }, + File { path: "model/memory_accessors.sail", size: 4529, sha256: "b1373bc368724fb175ba2fb2482c01a5d4ce668e84eae6eed8114002d1d42fb9" }, + File { path: "model/modes.sail", size: 1546, sha256: "0f791685159e7ba823e008f0d557fccc7dcfa5f316dde564fb2617c04a694e06" }, + File { path: "model/mov.sail", size: 16615, sha256: "3ef6e82be78fcb79de1d00df72ff0c2132a4a393ca724b448be49458ae83818d" }, + File { path: "model/move.sail", size: 21127, sha256: "08d9815bf2c7ce204ee4e9f2ac208cae2477048b122cb29780440d44ac24af68" }, + File { path: "model/multiply.sail", size: 13789, sha256: "90516031b4582c583f6036fce09115fb9854e4289f7f32a1965e556e1391feb5" }, + File { path: "model/multiply_spec.sail", size: 6199, sha256: "47211e118e578dc123e7bfac547e9be5fbb41ccf469d314874b89537877391ba" }, + File { path: "model/opcode_ext.sail", size: 3856, sha256: "d33e16eb589ff6e521f9d1a2f12edc5492133cfa79c2dbd7464499420a67ff5c" }, + File { path: "model/or_spec.sail", size: 2513, sha256: "33510144b55a95d75ce981bd90a4dab446787ce014f20ae01b1234a972157294" }, + File { path: "model/physical_memory.sail", size: 2024, sha256: "a2ee81b2527358d2d2bb7dfe1e4b82e639c1c5d80f1a8a2dbc920a879564872e" }, + File { path: "model/prefix_modrm_sib_decoding.sail", size: 25071, sha256: "b6a5fd1c2abd8c1c398809777467d29fa73941ddd8f4154e0769d21793f449a4" }, + File { path: "model/prelude.sail", size: 22998, sha256: "c8459e03dac0bd80620bfd8b91498b153e95cbb2924113f8617a3c3fcbf90bfd" }, + File { path: "model/register_accessors.sail", size: 872, sha256: "9a8d33be19bcd2572929685bd2861c03055914cce148661551fb5e425d39b304" }, + File { path: "model/register_readers_and_writers.sail", size: 24980, sha256: "8de4459b533c20147f2953f2f7a90a3fabcc9debb5f494940f3f573030b0ee5a" }, + File { path: "model/register_types.sail", size: 244, sha256: "530206628dea46dbb35e559008f88ce9946ae4f97da0152154480d50ed6ea9d8" }, + File { path: "model/registers.sail", size: 4160, sha256: "789f81d776682f76b3b70e1a179537713c95327edef9f7eefca58f4a36992902" }, + File { path: "model/rflags_spec.sail", size: 10005, sha256: "2195224ef798d10d0ff7ba6a1ab56c448cbceaa8a503bce570cf5da06b9db7c8" }, + File { path: "model/rotate_and_shift.sail", size: 9525, sha256: "2fba5ec9ce5e519c0cea7d2b7373fe20e45846c4f141eb4d005d309ef26ca4f1" }, + File { path: "model/shifts_spec.sail", size: 46510, sha256: "b9aef38181aadfb1481bef64ac1c6869e43cc107a1b372757cb33ae2c7523705" }, + File { path: "model/shuffle_and_unpack.sail", size: 8699, sha256: "cd48bd0a6e4ca4fe11fcf0334fbba373933dbe1c24ddc46963e87e2b699a5828" }, + File { path: "model/signextend.sail", size: 1844, sha256: "7a988571a3fff6133c3757d997865754d5c46312cda023c42b2e1b720668f696" }, + File { path: "model/step.sail", size: 118010, sha256: "4f3d45bd77edb94b3ec307aa077383d2e4337185d396bda4a894823dc2c86462" }, + File { path: "model/structures.sail", size: 7237, sha256: "fced32f0ec990acaf36e1e48190b94fe480a34db1c980c8744fe1fe114a1eb8f" }, + File { path: "model/sub_spec.sail", size: 6949, sha256: "ad76d5f6b08a99c648bc824dad5da86daefa3a1585be6209bf15d19b98980444" }, + File { path: "model/subroutine.sail", size: 7793, sha256: "0f415d06d8a09dba50dab30dba68d7b2eb6ecd44f8f5022fb90cc8ffd9619b2b" }, + File { path: "model/three_byte_opcodes_dispatch.sail", size: 44, sha256: "1f7a32638be7197875d0828b94460314434cac53b931649c0716594c817222aa" }, + File { path: "model/top.sail", size: 3828, sha256: "920e6a5ac62a52c91f1632319e1b2acf434ea42d666a9c4d4731396d6fdc1a91" }, + File { path: "model/top_level_memory.sail", size: 28897, sha256: "05e0b4b971ccbbce073d0cb28fe05d2fbdf98b4b594158f49aecedfdb011f243" }, + File { path: "model/two_byte_opcodes_dispatch.sail", size: 147060, sha256: "612a6e99b0be5f734c6393a7566abd4497ad3f4bea570cc9ed5ac4f1550f4171" }, + File { path: "model/xor_spec.sail", size: 2521, sha256: "abaf22867709d9f828c9fa1b348316dad793a821cb29695a5d36e2b857f1007f" }, +]; diff --git a/crates/clazel-x64/tests/generated/sail_x86_shina.rs b/crates/clazel-x64/tests/generated/sail_x86_shina.rs new file mode 100644 index 000000000..7b01b4bf4 --- /dev/null +++ b/crates/clazel-x64/tests/generated/sail_x86_shina.rs @@ -0,0 +1,46 @@ +// @generated by `cargo xtask testdata` from tests/data/sail-x86-shina/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, commit and license: tests/data/sail-x86-shina/SOURCE.md. +// +// Sail x86 model written from the Intel manuals (jit.md item J.2), the candidate second source. +// 23 files, 577218 bytes. Nothing here is parsed yet; see the converter's +// header for why. Paths are relative to tests/data/sail-x86-shina/. + +/// One vendored file. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct File { + /// Its path under the suite directory, with `/` separators. + pub path: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every vendored file, sorted by path. +pub const FILES: &[File] = &[ + File { path: "LICENSE.md", size: 1067, sha256: "e65ecb752d534b9cb7b16b601a944dae24bca8dcda44a18c300d0cd6d9144d58" }, + File { path: "README.md", size: 3742, sha256: "5da3d30fcbd5ac032ea0f1f7af71760e74fcd32513922b7cbf0ce8c3df596474" }, + File { path: "docs/x86-64-completeness-checklist.md", size: 77631, sha256: "652a87d6840977385904caf03cb23af52acad18c35abd8f16f6753122686aedf" }, + File { path: "model/branchless.sail", size: 16415, sha256: "8a1ac92bd9790ea6604f13674ff60337ab5f36f2964b9fe2b5310a897ed10f2e" }, + File { path: "model/core_types.sail", size: 5017, sha256: "fb3d14b45577a51f016a14c320c67830327d88bf0e7c3e729ccbbfb44c71f289" }, + File { path: "model/exceptions.sail", size: 6410, sha256: "f927ca47a0b02f65caa2f0eb3657e23245728b3f027b8d2aafab2d1a58dac565" }, + File { path: "model/extern.sail", size: 18555, sha256: "d37f9127074f48c63a1777670b13cdc4dcbbc39f5cd6f145a2252c5b28e814d1" }, + File { path: "model/fetch_execute.sail", size: 10680, sha256: "40dd44e213864e37d80a7ab0695496d5cef34057518ec9ef69ce05fec7151a88" }, + File { path: "model/insn_alu.sail", size: 2957, sha256: "5fdc1dff9e642c311a34a0b8150d39122d6edbd24b3ce1b4fcfc3e55a875ec2d" }, + File { path: "model/insn_baseline.sail", size: 107247, sha256: "cc02f5b1712cea47182436b8f8dee34aa59b68e0ddffd1eab4bda2e6d47b80e8" }, + File { path: "model/insn_dispatch.sail", size: 90511, sha256: "cd5ef19df0c6684733d09450a110ede3671a4ea0d2ef446f0ed98befc7a8aa2b" }, + File { path: "model/insn_groups.sail", size: 17156, sha256: "986bd93d642c9f788fab960e7fd54f391cdf25a78b19dea95012d56d56b2a768" }, + File { path: "model/insn_modrm.sail", size: 19571, sha256: "6a056df43aaf88b1deaa4323d0bc328ca851816b9cd298a93fa64d884f5fcf7d" }, + File { path: "model/insn_prefixes.sail", size: 5826, sha256: "f81da5829b55ef596ca38f4b451e5a3e67471a2a2223dd57f9970e3c3c4d4203" }, + File { path: "model/insn_simd.sail", size: 27867, sha256: "52f8dd8664f41a8f8192d18b2ba8c8547b944aa8e4c59d4fa4aa379cfcf89599" }, + File { path: "model/insn_sse_fp.sail", size: 33900, sha256: "72e09025d51b424e3ea8806a99bc6556f7391fe22828802276d4552123e68649" }, + File { path: "model/mem.sail", size: 34839, sha256: "18c521e8677447bed0c6d0d96ced9dad9f06f34b1e278adaba4bb361deeec3f8" }, + File { path: "model/operands.sail", size: 16630, sha256: "8308eed94cc7b1e864092bf0a3bafb1acfe1a55593bafdfcb052798f6d45ef2b" }, + File { path: "model/paging.sail", size: 18548, sha256: "13f5caa064cb383928ff3cc872c643dce2ee6c888da8274b53185eb2a6222bea" }, + File { path: "model/prelude.sail", size: 5068, sha256: "3c5ef7a17b04fbf3ac361eb4f71b7e29a86d7782cd4a02063cd02a8851504c33" }, + File { path: "model/regs.sail", size: 48159, sha256: "18902f88eefe8bdc2c81274a66832f2a0fecd37084c6dfbe4072102bf79f8abe" }, + File { path: "model/rflags.sail", size: 8242, sha256: "3c098ce4cac15e3bb0e5b0d0b8ae6f2c7b8918f7073af0ab9ebcf5b89bc6686f" }, + File { path: "model/x86.sail_project", size: 1180, sha256: "a677b09cc51906ddabe6c92da52f91ea36dd20e51f6f6b88101b5867934ab9fd" }, +]; diff --git a/crates/clazel-x64/tests/vendored_sources.rs b/crates/clazel-x64/tests/vendored_sources.rs new file mode 100644 index 000000000..cd5bf9de0 --- /dev/null +++ b/crates/clazel-x64/tests/vendored_sources.rs @@ -0,0 +1,77 @@ +//! The vendored instruction-set sources are the ones the generated inventories +//! list (docs/phases/jit.md item J.2): every listed file exists with the +//! listed size, and the pinned file has a well-formed pin. `cargo xtask +//! testdata` checks the hashes; nothing here reads the content yet. + +use std::path::Path; + +mod acl2_x86isa { + include!("generated/acl2_x86isa.rs"); +} +mod sail_x86_from_acl2 { + include!("generated/sail_x86_from_acl2.rs"); +} +mod sail_x86_shina { + include!("generated/sail_x86_shina.rs"); +} +mod intel_sdm { + include!("generated/intel_sdm.rs"); +} + +fn check(suite: &str, files: &[(&str, u64)]) { + let dir = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("data") + .join(suite); + assert!(!files.is_empty(), "{suite}: empty inventory"); + for (path, size) in files { + let len = std::fs::metadata(dir.join(path)).map(|m| m.len()).ok(); + assert_eq!(len, Some(*size), "{suite}/{path}"); + } +} + +#[test] +fn acl2_x86isa_files_have_their_listed_sizes() { + let files: Vec<_> = acl2_x86isa::FILES + .iter() + .map(|f| (f.path, f.size)) + .collect(); + check("acl2-x86isa", &files); +} + +#[test] +fn sail_x86_from_acl2_files_have_their_listed_sizes() { + let files: Vec<_> = sail_x86_from_acl2::FILES + .iter() + .map(|f| (f.path, f.size)) + .collect(); + check("sail-x86-from-acl2", &files); +} + +#[test] +fn sail_x86_shina_files_have_their_listed_sizes() { + let files: Vec<_> = sail_x86_shina::FILES + .iter() + .map(|f| (f.path, f.size)) + .collect(); + check("sail-x86-shina", &files); +} + +#[test] +fn the_sdm_is_pinned_and_not_vendored() { + assert_eq!(intel_sdm::PINS.len(), 1); + for p in intel_sdm::PINS { + assert_eq!(p.sha256.len(), 64, "{}", p.file); + assert!(p.size > 0, "{}", p.file); + let here = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("data") + .join("intel-sdm") + .join(p.file); + assert!( + !here.exists(), + "{}: Intel's PDF must not be vendored", + p.file + ); + } +} From 94a50a7750f80b421d25b13b6128340d04a9703e Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Mon, 16 Nov 2026 14:46:42 +0000 Subject: [PATCH 4/8] Add iced-x86 and yaxpeax-arm as test dependencies; record the J.2 pins and benchmark proposal Co-Authored-By: Claude Sonnet 5.5 --- Cargo.lock | 80 +++++++++++++++++++ crates/clazel-a64/Cargo.toml | 4 + .../tests/reference_disassembler.rs | 34 ++++++++ crates/clazel-x64/Cargo.toml | 3 + .../tests/reference_disassembler.rs | 38 +++++++++ docs/DEPENDENCIES.md | 9 +++ docs/phases/jit.md | 59 ++++++++++++++ 7 files changed, 227 insertions(+) create mode 100644 crates/clazel-a64/tests/reference_disassembler.rs create mode 100644 crates/clazel-x64/tests/reference_disassembler.rs diff --git a/Cargo.lock b/Cargo.lock index 20d498734..08903694e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,6 +76,18 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +[[package]] +name = "bitvec" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -191,6 +203,10 @@ dependencies = [ [[package]] name = "clazel-a64" version = "0.0.0" +dependencies = [ + "yaxpeax-arch", + "yaxpeax-arm", +] [[package]] name = "clazel-base64" @@ -616,6 +632,9 @@ dependencies = [ [[package]] name = "clazel-x64" version = "0.0.0" +dependencies = [ + "iced-x86", +] [[package]] name = "codespan-reporting" @@ -874,6 +893,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures-core" version = "0.3.34" @@ -1053,6 +1078,15 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" +[[package]] +name = "iced-x86" +version = "1.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c23ad4d19dca41180e835ef6fbd2c1ee655777eca086ad80dd517e0513322879" +dependencies = [ + "lazy_static", +] + [[package]] name = "idna" version = "1.1.0" @@ -1126,6 +1160,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.190" @@ -1707,6 +1747,12 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.10.3" @@ -2040,6 +2086,12 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tendril" version = "0.5.1" @@ -2437,6 +2489,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "xml5ever" version = "0.39.0" @@ -2458,6 +2519,25 @@ dependencies = [ "sha2", ] +[[package]] +name = "yaxpeax-arch" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb869f86d5a365bf741d9df773f7a5347757b1c466b7383b74989324785ef36b" +dependencies = [ + "num-traits", +] + +[[package]] +name = "yaxpeax-arm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79f8d9808ad0b7e434882c66e50704138e7c0bdf3408a9f3159c50603dc3168c" +dependencies = [ + "bitvec", + "yaxpeax-arch", +] + [[package]] name = "zerocopy" version = "0.8.63" diff --git a/crates/clazel-a64/Cargo.toml b/crates/clazel-a64/Cargo.toml index cffb002c5..daf48a048 100644 --- a/crates/clazel-a64/Cargo.toml +++ b/crates/clazel-a64/Cargo.toml @@ -19,3 +19,7 @@ target-tier = 2 [lints] workspace = true + +[dev-dependencies] +yaxpeax-arm = { version = "=0.5.0", default-features = false, features = ["fmt"] } +yaxpeax-arch = { version = "=0.3.3", default-features = false } diff --git a/crates/clazel-a64/tests/reference_disassembler.rs b/crates/clazel-a64/tests/reference_disassembler.rs new file mode 100644 index 000000000..cdbf5a352 --- /dev/null +++ b/crates/clazel-a64/tests/reference_disassembler.rs @@ -0,0 +1,34 @@ +//! The reference disassembler builds and decodes (docs/phases/jit.md item J.2). +//! +//! `yaxpeax-arm` is a test dependency only (class `test` in +//! docs/DEPENDENCIES.md). Item J.4's decoder differential will compare it with +//! `clazel-a64` on every encoding of the subset; this test only shows that it +//! is wired in and answers for one instruction of each kind the subset has. + +use yaxpeax_arch::{Decoder, U8Reader}; +use yaxpeax_arm::armv8::a64::{InstDecoder, Opcode}; + +fn opcode_of(word: u32) -> Option { + let bytes = word.to_le_bytes(); + let mut reader = U8Reader::new(&bytes); + InstDecoder::default() + .decode(&mut reader) + .ok() + .map(|inst| inst.opcode) +} + +#[test] +fn add_x0_x1_x2() { + assert_eq!(opcode_of(0x8b02_0020), Some(Opcode::ADD)); +} + +#[test] +fn b_and_ret() { + assert_eq!(opcode_of(0x1400_0004), Some(Opcode::B)); + assert_eq!(opcode_of(0xd65f_03c0), Some(Opcode::RET)); +} + +#[test] +fn svc_is_outside_the_subset_but_decodes() { + assert_eq!(opcode_of(0xd400_0001), Some(Opcode::SVC)); +} diff --git a/crates/clazel-x64/Cargo.toml b/crates/clazel-x64/Cargo.toml index 524bfa9ab..9f1e74121 100644 --- a/crates/clazel-x64/Cargo.toml +++ b/crates/clazel-x64/Cargo.toml @@ -19,3 +19,6 @@ target-tier = 2 [lints] workspace = true + +[dev-dependencies] +iced-x86 = { version = "=1.22.0", default-features = false, features = ["std", "decoder", "encoder", "instr_info", "intel"] } diff --git a/crates/clazel-x64/tests/reference_disassembler.rs b/crates/clazel-x64/tests/reference_disassembler.rs new file mode 100644 index 000000000..89d08cf5a --- /dev/null +++ b/crates/clazel-x64/tests/reference_disassembler.rs @@ -0,0 +1,38 @@ +//! The reference disassembler builds and decodes (docs/phases/jit.md item J.2). +//! +//! `iced-x86` is a test dependency only (class `test` in +//! docs/DEPENDENCIES.md). Item J.3's decoder differential will compare it with +//! `clazel-x64` on every encoding of the subset; this test only shows that it +//! is wired in and answers for one instruction of each kind the subset has. + +use iced_x86::{Code, Decoder, DecoderOptions, Mnemonic}; + +fn decode(bytes: &[u8]) -> (Mnemonic, usize) { + let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE); + let inst = decoder.decode(); + (inst.mnemonic(), inst.len()) +} + +#[test] +fn add_rax_rbx() { + // REX.W 01 /r: add r/m64, r64. + assert_eq!(decode(&[0x48, 0x01, 0xd8]), (Mnemonic::Add, 3)); +} + +#[test] +fn jmp_rel32_and_ret() { + assert_eq!(decode(&[0xe9, 0x10, 0x00, 0x00, 0x00]), (Mnemonic::Jmp, 5)); + assert_eq!(decode(&[0xc3]), (Mnemonic::Ret, 1)); +} + +#[test] +fn addsd_xmm0_xmm1() { + // F2 0F 58 /r: addsd xmm1, xmm2/m64. + assert_eq!(decode(&[0xf2, 0x0f, 0x58, 0xc1]), (Mnemonic::Addsd, 4)); +} + +#[test] +fn syscall_is_outside_the_subset_but_decodes() { + let mut decoder = Decoder::new(64, &[0x0f, 0x05], DecoderOptions::NONE); + assert_eq!(decoder.decode().code(), Code::Syscall); +} diff --git a/docs/DEPENDENCIES.md b/docs/DEPENDENCIES.md index 0193109e9..9f6e17fdb 100644 --- a/docs/DEPENDENCIES.md +++ b/docs/DEPENDENCIES.md @@ -245,6 +245,15 @@ Changing a row is a reviewable act. Adding one means saying why below. | unicode-properties | 0.1.5 | test | Unicode General_Category (the only feature `rustybuzz` enables), required by `rustybuzz`. No dependencies. | | unicode-script | 0.5.9 | test | The Unicode Script property, required by `rustybuzz`. No dependencies. | | ab_glyph_rasterizer | 0.1.10 | test | Alex Butler's coverage rasterizer (used by `ab_glyph`, `glyph_brush` and `wgpu_glyph`), a descendant of `font-rs`: the reference engine in `clazel-glyph-mask`'s differential test (`tests/conformance_masks.rs`, phase-5.md item 5.17), the same signed-area accumulation in `f32` written by another author. Used without default features but with `std`, which is its only default; `cargo tree` shows no dependencies (`libm` is optional and off). It has `unsafe` only to call its line function through a pointer chosen by CPU feature detection (all variants are the same scalar code). Pinned to 0.1.10, its latest release. | +| iced-x86 | 1.22.0 | test | A fast x86/x64 decoder, encoder and disassembler (icedland/iced, MIT): the reference in `clazel-x64`'s decoder and encoder differential tests (jit.md items J.2 and J.3, exit criterion 3). Used without default features, with `std`, `decoder`, `encoder`, `instr_info` and `intel` (its `no_std` build needs `lazy_static`'s spin feature, one more package); its only dependency is `lazy_static`. | +| lazy_static | 1.5.0 | test | Lazily initialised statics (MIT OR Apache-2.0), required by `iced-x86`'s `std` feature. No dependencies. | +| yaxpeax-arm | 0.5.0 | test | An ARM decoder (yaxpeax project, 0BSD): the reference in `clazel-a64`'s decoder differential test (jit.md items J.2 and J.4, exit criterion 3). Used without default features (no `serde`) and with `fmt`; it needs `bitvec` and `yaxpeax-arch`. | +| yaxpeax-arch | 0.3.3 | test | The architecture traits of the yaxpeax project (0BSD), required by `yaxpeax-arm`. Used without default features; its only dependency is `num-traits`, which the table lists under `shipped` (the stricter class, as it is locked under libcrux's `cfg(hax)`). | +| bitvec | 1.1.1 | test | Bit-level views of memory (MIT), required by `yaxpeax-arm`. It needs the four packages in the rows below. | +| funty | 2.0.0 | test | Fundamental-type traits (MIT), required by `bitvec`. No dependencies. | +| radium | 0.7.0 | test | Atomic and non-atomic cell abstraction (MIT), required by `bitvec`. No dependencies. | +| tap | 1.0.1 | test | Method-chaining helpers (MIT), required by `bitvec` and `wyz`. No dependencies. | +| wyz | 0.5.1 | test | A utility collection (MIT), required by `bitvec`. Its only dependency is `tap`. | | naga | 30.0.1 | tooling | The wgpu project's shader translator: `xtask/src/shaders.rs` compiles `clazel-gpu`'s GLSL to the committed SPIR-V with it and `cargo xtask check` confirms the two agree (phase-5.md item 5.17b: "compiled from GLSL by tooling that never ships"). No SPIR-V compiler is installed on the development machine, and this keeps the check in Rust. Features `glsl-in`, `spv-out`, and `wgsl-in`, which is unused but without which 30.0.1 does not build. | | naga-types | 30.0.1 | tooling | Required by `naga` (GLSL to SPIR-V for `clazel-gpu`'s shaders, in `xtask` only). | | arrayvec | 0.7.8 | tooling | Required by `naga` (GLSL to SPIR-V for `clazel-gpu`'s shaders, in `xtask` only). | diff --git a/docs/phases/jit.md b/docs/phases/jit.md index 314918f7d..9de104c70 100644 --- a/docs/phases/jit.md +++ b/docs/phases/jit.md @@ -369,6 +369,65 @@ code. `yaxpeax-arm`), each a `test` row in DEPENDENCIES.md. - Pin the benchmark set, and record the JIT-off numbers. +**Status (2026-11-16): sources pinned, benchmark numbers not recorded.** +- **Pinned:** each is a suite under `crates/clazel-x64/tests/data/` or + `crates/clazel-a64/tests/data/`, with a `SOURCE.md`, a licence and an + `xtask` converter (`xtask/src/testdata/isa.rs`). The crate READMEs record + what the pins show: + - ACL2 `x86isa` (acl2/acl2 at 33b05575, BSD-3-Clause, 2.6 MB); + - the Sail x86 model translated from it (rems-project/sail-x86-from-acl2 + at 0c6c023d, 0.8 MB); + - a Sail x86 model written from the Intel manuals (shina-lab/sail-x86 at + 1829cb6e, MIT, 0.6 MB); + - Intel's SDM volume 2, version 093, **pinned by URL and SHA-256 only**: + Intel's terms forbid redistribution; + - the Sail Armv9.4-A model (rems-project/sail-arm at 5416ef6b, + BSD-3-Clause-Clear, 3.9 MB); + - Arm's machine-readable specification (BSD-3-Clause, so it may be + redistributed), release 2026-09: the licence and README are vendored, and + `Instructions.json` (116 MB, over the size budget) is pinned by + SHA-256. +- **Not independent, as the pins show:** the Sail x86 model that this item + names is a mechanical translation of the ACL2 model, and the Sail Arm model + is a translation of Arm's own ASL, the same text as the machine-readable + specification. So J.3's and J.4's "second source" is not independent unless + a person accepts `shina-lab/sail-x86` for x86-64, and for A64 no second + formal source was found. See the two READMEs. +- **Reference disassemblers:** `iced-x86` 1.22.0 (with `lazy_static`) and + `yaxpeax-arm` 0.5.0 (with `yaxpeax-arch`, `bitvec` and four small + packages), each a `test` row in DEPENDENCIES.md, dev-dependencies of the new + crates only. +- **Proposed benchmark set** (a proposal, for a person to accept): the + compute-bound programs of Octane 2.0, from `chromium/octane` (archived; + BSD-3-Clause for the harness, each benchmark file with its own licence + header) at commit 570ad1ccfe86e3eecba0636c8f932ac08edec517. They need no + DOM, and `run.js` is a shell harness. SHA-256 of each file at that commit: + + | File | SHA-256 | + |---|---| + | `base.js` | `216612c2e7096a02b3e52b57e9cf9351bbaf180d60938d5c60b85fd756232733` | + | `run.js` | `b4b10b05e3ccefd6f49d57763ec67ef746c3e7c093ed0fdd602c7f126af5c12f` | + | `richards.js` | `1246a64a24b931158bf01c24640343259fa74b0226e73bad630bd1f686aa0fa7` | + | `deltablue.js` | `6c4784e82f3e8f5c18306d289653d08b17b38838f1bac16b38611d7318fa5a36` | + | `crypto.js` | `b01b6b3fe534327fdef05131162927bc5508f100a3208e185d0c5a4efb200a39` | + | `raytrace.js` | `64b8ff90969966dd69659100e28754976dfc3e9a4f8ee55b9232f974c66ed08c` | + | `earley-boyer.js` | `8dd28a505f7e705642f86816232b012fd3c770ec8afc9f719ce89ce772dab347` | + | `splay.js` | `f9a6a60d8f205908f5542ad1180abc1902dcdab3dcb4278017c5ce179ee123f7` | + | `navier-stokes.js` | `27926de809451c60b0c49a4185c08f97081310d0db166a30c1d202fb656556a2` | + | `box2d.js` | `83b10c280f004e7b156a9e04d09ce4109892ea92788f7c6c963f7fadf29c7bd4` | + | `regexp.js` | `a292d6047900c5296ea9e2628453832cc3bfe397e49fddade8aff7b5876c8263` | + | `LICENSE` | `cf853177951c6de1b17c029b66edf71f8b194cca1722339a7b5def4e8165aaaa` | + + Left out: `code-load`, `pdfjs`, `typescript`, `mandreel`, `gbemu`, `zlib` + (large, or they need `eval`, typed arrays or the DOM). Octane is retired + and measures peak throughput, so it is a smoke measure for a baseline JIT, + not a claim about page loads; WebKit's JetStream (`WebKit/JetStream`) is + the live alternative and was not pinned (it is large and mixes in + WebAssembly). +- **Not done:** the JIT-off numbers. No engine exists, so there is nothing + to measure. They are recorded when the interpreter runs these files, in + the benchmark suite's README, with the machine and the engine commit. + ### J.3 `clazel-x64` (L) - The subset: 64- and 32-bit integer ALU ops, shifts, `imul`, `cmp`/`test` From 9bf184fec24a5079e322c06e29a15069f170456b Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Mon, 16 Nov 2026 15:44:39 +0000 Subject: [PATCH 5/8] Record the second-transcription decision, drop the shina Sail model, pin the Arm ARM (J.2) The second transcriptions come from the vendors' manuals (Intel SDM, Arm ARM) written by a different session; the Sail x86 translation is only a check on our reading of ACL2. shina-lab/sail-x86 is removed (single author, unreviewed, floating point external). The Arm Architecture Reference Manual issue M.d is pinned by URL, size and SHA-256, not vendored. Co-Authored-By: Claude Sonnet 5.5 --- crates/clazel-a64/README.md | 23 +- .../clazel-a64/tests/data/arm-arm/LICENSE.md | 17 + .../clazel-a64/tests/data/arm-arm/SOURCE.md | 34 + .../clazel-a64/tests/data/sail-arm/SOURCE.md | 5 +- crates/clazel-a64/tests/generated/arm_arm.rs | 22 + crates/clazel-a64/tests/vendored_sources.rs | 22 + crates/clazel-x64/README.md | 62 +- .../clazel-x64/tests/data/intel-sdm/SOURCE.md | 5 +- .../tests/data/sail-x86-from-acl2/SOURCE.md | 4 +- .../tests/data/sail-x86-shina/LICENSE.md | 21 - .../tests/data/sail-x86-shina/README.md | 116 - .../tests/data/sail-x86-shina/SOURCE.md | 40 - .../docs/x86-64-completeness-checklist.md | 1152 -------- .../data/sail-x86-shina/model/branchless.sail | 415 --- .../data/sail-x86-shina/model/core_types.sail | 130 - .../data/sail-x86-shina/model/exceptions.sail | 140 - .../data/sail-x86-shina/model/extern.sail | 489 ---- .../sail-x86-shina/model/fetch_execute.sail | 261 -- .../data/sail-x86-shina/model/insn_alu.sail | 100 - .../sail-x86-shina/model/insn_baseline.sail | 2551 ----------------- .../sail-x86-shina/model/insn_dispatch.sail | 2358 --------------- .../sail-x86-shina/model/insn_groups.sail | 501 ---- .../data/sail-x86-shina/model/insn_modrm.sail | 496 ---- .../sail-x86-shina/model/insn_prefixes.sail | 112 - .../data/sail-x86-shina/model/insn_simd.sail | 698 ----- .../sail-x86-shina/model/insn_sse_fp.sail | 893 ------ .../tests/data/sail-x86-shina/model/mem.sail | 755 ----- .../data/sail-x86-shina/model/operands.sail | 418 --- .../data/sail-x86-shina/model/paging.sail | 481 ---- .../data/sail-x86-shina/model/prelude.sail | 126 - .../tests/data/sail-x86-shina/model/regs.sail | 1184 -------- .../data/sail-x86-shina/model/rflags.sail | 222 -- .../sail-x86-shina/model/x86.sail_project | 66 - .../tests/generated/sail_x86_shina.rs | 46 - crates/clazel-x64/tests/vendored_sources.rs | 12 - docs/phases/jit.md | 51 +- xtask/src/testdata.rs | 3 +- xtask/src/testdata/isa.rs | 30 +- 38 files changed, 205 insertions(+), 13856 deletions(-) create mode 100644 crates/clazel-a64/tests/data/arm-arm/LICENSE.md create mode 100644 crates/clazel-a64/tests/data/arm-arm/SOURCE.md create mode 100644 crates/clazel-a64/tests/generated/arm_arm.rs delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/README.md delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail delete mode 100644 crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project delete mode 100644 crates/clazel-x64/tests/generated/sail_x86_shina.rs diff --git a/crates/clazel-a64/README.md b/crates/clazel-a64/README.md index 635617dac..29fc90417 100644 --- a/crates/clazel-a64/README.md +++ b/crates/clazel-a64/README.md @@ -11,24 +11,31 @@ pinned the sources the semantics will be written against, in `tests/data/`: |---|---|---| | `sail-arm` | the Sail Armv9.4-A model: A64 base instructions and shared pseudocode (BSD-3-Clause-Clear) | 3.9 MB, vendored | | `arm-mrs` | Arm's machine-readable specification, 2026-09 release (BSD-3-Clause) | licence and README vendored; `Instructions.json` (116,678,333 bytes) pinned by SHA-256 | +| `arm-arm` | Arm Architecture Reference Manual for A-profile (DDI 0487), issue M.d | pinned by URL, size (129,014,701 bytes) and SHA-256, not vendored (Arm's terms forbid copying) | Each has a `SOURCE.md` with the upstream, the commit (or the SHA-256) and the licence. The tables in `tests/generated/` list every file's size and hash. -## Are the two A64 sources independent? No. +## Where the transcriptions come from + +Decided by the user on 2026-11-16 (jit.md, the note under J.4): + +- The **primary spec** is transcribed from the Sail Arm model and Arm's ASL. +- The **independent transcription** is made from the Arm Architecture + Reference Manual's prose, by a **different session** that does not read the + primary transcription. +- The **hardware differential tests** on the macOS runner (exit criterion 3) + are the further check against both. + +## The two formal A64 sources are one source The Sail Arm model's README says its Sail files "are derived from the 2023-03 version of Arm's ASL specification using the automatic ASL-to-Sail translation tool". Arm's machine-readable specification (`Instructions.json`) carries the same ASL as the operation of each instruction. So the two are one source in two syntaxes (the Sail model is from the 2023-03 ASL, the JSON from -2026-09), and they share Arm's own errors, if any. jit.md items J.2 and J.4 -say each semantics is transcribed from independent sources; for A64 no -second, independent formal source was found. The Arm Architecture Reference -Manual's prose and the hardware differential tests on the macOS runner (exit -criterion 3) are independent evidence; a person should decide whether the -second A64 transcription is made from the prose, and what the crate header -says. +2026-09), and they share Arm's own errors, if any. That is why the second +transcription comes from the manual's prose. The `arm-mrs` JSON is also the only machine-readable encoding table (`Instructions.json` has every encoding with its fixed and variable bits), so diff --git a/crates/clazel-a64/tests/data/arm-arm/LICENSE.md b/crates/clazel-a64/tests/data/arm-arm/LICENSE.md new file mode 100644 index 000000000..08ec186f3 --- /dev/null +++ b/crates/clazel-a64/tests/data/arm-arm/LICENSE.md @@ -0,0 +1,17 @@ +# Licence of the Arm Architecture Reference Manual + +None granted for redistribution. The Arm Architecture Reference Manual for +A-profile architecture (DDI 0487) is Arm Limited's copyright and is published +under Arm's documentation terms, not under an open licence. Arm's website +terms (https://www.arm.com/company/policies/terms-and-conditions, read on +2026-11-16) forbid reproducing or copying its content without express written +permission, and allow a personal reference copy only. We found no grant to +redistribute the manual. Arm's own machine-readable specification, a different +product, is BSD-3-Clause (`../arm-mrs/`). The PDF is therefore not vendored: +`SOURCE.md` pins it by URL, size and SHA-256. + +The proprietary notice inside the PDF was not read (the 129 MB file was read +only for its hash); a person should read it before anyone proposes vendoring +any part of the document. + +This file is a statement of that decision, not a copy of a licence. diff --git a/crates/clazel-a64/tests/data/arm-arm/SOURCE.md b/crates/clazel-a64/tests/data/arm-arm/SOURCE.md new file mode 100644 index 000000000..97cfd6e39 --- /dev/null +++ b/crates/clazel-a64/tests/data/arm-arm/SOURCE.md @@ -0,0 +1,34 @@ +# Arm Architecture Reference Manual for A-profile architecture (DDI 0487), issue M.d, pinned and not vendored + +Upstream: https://documentation-service.arm.com/static/6abbec2a6db85c5e6614a4a1 +SHA-256: 80d589a4645feba6bdb9d77edfaf04d4394d5d5444a4c41f97cf4fdd20eee3d5 DDI0487M_d_a-profile_architecture_reference_manual.pdf +Size: 129014701 DDI0487M_d_a-profile_architecture_reference_manual.pdf +License: Arm copyright, proprietary notice, no licence to redistribute. See `LICENSE.md`. + +The file is what Arm's own documentation service serves for DDI 0487 "latest" +on 2026-11-16: its API +(`https://documentation-service.arm.com/documentation/ddi0487/latest`) names +version label **M.d** (document quality "EAC", Arm's early-access label for a +release not yet final) and lists this PDF as the resource +`DDI0487M_d_a-profile_architecture_reference_manual.pdf`. The human-facing +page is https://developer.arm.com/documentation/ddi0487/latest, which +redirects to support.arm.com and is a script-driven page that a plain client +cannot read; the `static/` URL above is the one the API gave, fetched without +its `token` query parameter, and it returned the PDF (`%PDF-1.7`, 129,014,701 +bytes, 129 MB). + +This is the source of the independent A64 transcription of jit.md item J.4: +the instruction pages (Part C, "The A64 Instruction Set") give each +instruction's encoding and its pseudocode, and Part B gives the application +level model. Pinned Arm ARM issues change: when Arm publishes M.e or a final +M.d, the hash no longer matches and a person must repin after reading the +change list. + +The PDF is not in this repository: it is far over the size budget (129 MB), +and Arm's documents carry a proprietary notice with no right to redistribute +(`LICENSE.md`). Nothing was checked against a mirror. The `static/` URL is +Arm's own host, but it is an opaque document id, and Arm may withdraw it when +it replaces the issue; if so, repin from the page above. + +`xtask/src/testdata/isa.rs` writes `tests/generated/arm_arm.rs`, the table of +this pin. diff --git a/crates/clazel-a64/tests/data/sail-arm/SOURCE.md b/crates/clazel-a64/tests/data/sail-arm/SOURCE.md index 777929814..5b92cbd1a 100644 --- a/crates/clazel-a64/tests/data/sail-arm/SOURCE.md +++ b/crates/clazel-a64/tests/data/sail-arm/SOURCE.md @@ -26,7 +26,10 @@ and C snapshots, and the other versions (`arm-v8.5-a`, `arm-v9.3-a`). automatic ASL-to-Sail translation tool" and that the ASL came as a snapshot provided by Arm. So it is not independent of Arm's machine-readable specification (`arm-mrs`, Arm's 2026-09 release of the same ASL): see -`crates/clazel-a64/README.md`. +`crates/clazel-a64/README.md`. By the user's decision of 2026-11-16 (jit.md, +the note under J.4) the primary spec is transcribed from this model and +Arm's ASL, and the independent transcription from the Arm Architecture +Reference Manual's prose (`arm-arm`). To update, copy the files from a newer commit, change the commit above, and run `cargo xtask testdata`. `xtask/src/testdata/isa.rs` writes diff --git a/crates/clazel-a64/tests/generated/arm_arm.rs b/crates/clazel-a64/tests/generated/arm_arm.rs new file mode 100644 index 000000000..a737f2bac --- /dev/null +++ b/crates/clazel-a64/tests/generated/arm_arm.rs @@ -0,0 +1,22 @@ +// @generated by `cargo xtask testdata` from tests/data/arm-arm/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, pins and license: tests/data/arm-arm/SOURCE.md. +// +// Arm Architecture Reference Manual for A-profile (DDI 0487), pinned by URL and SHA-256 (Arm's terms do not allow redistribution). + +/// A file the suite pins but does not vendor. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Pin { + /// The file's name in `SOURCE.md`. + pub file: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every pinned file. +pub const PINS: &[Pin] = &[ + Pin { file: "DDI0487M_d_a-profile_architecture_reference_manual.pdf", size: 129014701, sha256: "80d589a4645feba6bdb9d77edfaf04d4394d5d5444a4c41f97cf4fdd20eee3d5" }, +]; diff --git a/crates/clazel-a64/tests/vendored_sources.rs b/crates/clazel-a64/tests/vendored_sources.rs index 3eaeb3556..1531a2ea9 100644 --- a/crates/clazel-a64/tests/vendored_sources.rs +++ b/crates/clazel-a64/tests/vendored_sources.rs @@ -11,6 +11,28 @@ mod sail_arm { mod arm_mrs { include!("generated/arm_mrs.rs"); } +mod arm_arm { + include!("generated/arm_arm.rs"); +} + +#[test] +fn the_arm_arm_is_pinned_and_not_vendored() { + assert_eq!(arm_arm::PINS.len(), 1); + for p in arm_arm::PINS { + assert_eq!(p.sha256.len(), 64, "{}", p.file); + assert!(p.size > 0, "{}", p.file); + assert!( + !Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("data") + .join("arm-arm") + .join(p.file) + .exists(), + "{}: Arm's PDF must not be vendored", + p.file + ); + } +} fn dir(suite: &str) -> std::path::PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")) diff --git a/crates/clazel-x64/README.md b/crates/clazel-x64/README.md index 2318144e2..808d9fe78 100644 --- a/crates/clazel-x64/README.md +++ b/crates/clazel-x64/README.md @@ -10,16 +10,29 @@ pinned the sources the semantics will be written against, in `tests/data/`: |---|---|---| | `acl2-x86isa` | the ACL2 x86isa model (BSD-3-Clause), files of the J.3 subset | 2.6 MB, vendored | | `sail-x86-from-acl2` | the Sail model translated from it (BSD-3-Clause, BSD-2-Clause) | 0.8 MB, vendored | -| `sail-x86-shina` | a Sail model written from the Intel manuals (MIT) | 0.6 MB, vendored | -| `intel-sdm` | Intel SDM volume 2, version 093 | pinned by URL and SHA-256, not vendored (Intel's terms forbid redistribution) | +| `intel-sdm` | Intel SDM volume 2, version 093 | pinned by URL, size and SHA-256, not vendored (Intel's terms forbid redistribution) | Each has a `SOURCE.md` with the upstream, the commit (or the SHA-256) and the licence. The tables in `tests/generated/` list every file's size and hash. -## Are the two x86 models independent? No. +## Where the transcriptions come from -jit.md item J.2 requires this to be read before the ACL2 and Sail models count -as two sources. The finding: +Decided by the user on 2026-11-16 (jit.md, the note under J.3): + +- The **primary spec** is transcribed from the ACL2 x86isa model. +- The **independent transcription** is made from the Intel SDM's prose and + pseudocode, by a **different session** that does not read the primary + transcription. +- The **hardware differential tests** (exit criterion 3) are the further + check against both. +- The Sail x86 translation is kept **only as a check on our reading of + ACL2**. It is **not independent of ACL2**, and the crate header must not + call it a second source. + +## The two x86 models are not independent + +jit.md item J.2 required this to be read before the ACL2 and Sail models +count as two sources. The finding: - **The Sail model that J.2 names, `rems-project/sail-x86-from-acl2`, is a mechanical translation of the ACL2 x86isa model.** Its README says so in its @@ -38,34 +51,13 @@ as two sources. The finding: - So an error in the ACL2 model's reading of the SDM is in the Sail model as well, and a differential test between them tests the translator (and Sail's typing of it), not the semantics. They share their authors' ancestry, - their reading of the manual and their test evidence. **They are one source - for the purpose of J.2.** + their reading of the manual and their test evidence. **They are one source.** - The translated model is also narrower: it has no SSE2 scalar double - instruction (the ACL2 books in `machine/instructions/fp/` were not translated), - so it could not check the `addsd`/`sqrtsd`/`ucomisd` part of the subset even - as a copy. - -A second source that is not a translation: - -- **`shina-lab/sail-x86`** (vendored as `sail-x86-shina`, MIT) is a Sail model - written from the Intel SDM and the AMD manual, and its README and files - mention neither ACL2 nor x86isa. It covers SSE2 scalar double. Its - authorship is one person (Rui Ueyama, with many commits carrying an AI - co-author line); it was created in 2026-03 and has no external review that - we found; its floating-point arithmetic is `extern`, supplied by its - emulator; it states hardware agreement from KVM runs on two hosts (its commit - messages give counts of passing cases). It is independent in lineage, and - its weight as evidence is a person's decision. -- Other sources, not pinned: the K framework's x86-64 semantics (Dasgupta et - al., PLDI 2019, derived from Stoke's specifications, so a separate - lineage from ACL2) and Intel's XED tables (machine-readable encodings, not - semantics). A person may prefer one of them. -- The strongest evidence the plan has is not a model at all: exit criterion 3's - hardware differential tests (running every template on real CPUs on two - OSes) and the decoder differential against `iced-x86`. - -What this means for item J.3 and for the "Risks" paragraph of jit.md: unless a -person accepts `sail-x86-shina` (or another source) as the second, the -"independent transcription from the second source" of J.3 is an independent -transcription of the *same* ACL2 semantics (or of the SDM's pseudocode), and -the crate header must say that, as jit.md's Risks section already requires. + instruction (the ACL2 books in `machine/instructions/fp/` were not + translated), so it cannot even check the `addsd`/`sqrtsd`/`ucomisd` part of + the subset as a copy. + +Another Sail x86 model, `shina-lab/sail-x86`, was considered as the second +source and rejected: a single author, no review we could find, and its +floating-point arithmetic left external. Other formal models (the K +framework's x86-64 semantics, Intel's XED encoding tables) are not pinned. diff --git a/crates/clazel-x64/tests/data/intel-sdm/SOURCE.md b/crates/clazel-x64/tests/data/intel-sdm/SOURCE.md index 2701a58bc..dbad1f0d4 100644 --- a/crates/clazel-x64/tests/data/intel-sdm/SOURCE.md +++ b/crates/clazel-x64/tests/data/intel-sdm/SOURCE.md @@ -11,7 +11,10 @@ https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.h on 2026-11-16 (the link there, https://cdrdv2.intel.com/v1/dl/getContent/671110, redirects to the URL above). The encoding tables of jit.md item J.3 are Appendix A (the opcode maps) and the "Instruction Operand Encoding" tables of -each instruction page; the operations are the pseudocode of each page. +each instruction page; the operations are the pseudocode of each page. By the +user's decision of 2026-11-16 (jit.md, the note under J.3) this is the source +of the independent transcription, written by a different session from the +primary one. The PDF is not in this repository, because Intel's terms of use (https://www.intel.com/content/www/us/en/legal/terms-of-use.html) say its diff --git a/crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md b/crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md index 5f499cfa5..29ecd2b80 100644 --- a/crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md +++ b/crates/clazel-x64/tests/data/sail-x86-from-acl2/SOURCE.md @@ -12,7 +12,9 @@ extended by Thomas Bauereiss (supervised by Alasdair Armstrong and Peter Sewell). **This model is therefore not an independent source from `acl2-x86isa`**: the functions keep the ACL2 names (`gpr_add_spec_1`, `jcc_cmovcc_setcc_spec`) and the structure of the ACL2 books line by line. -The analysis is in `crates/clazel-x64/README.md`. +The analysis is in `crates/clazel-x64/README.md`. By the user's decision of +2026-11-16 (jit.md, the note under J.3) it is kept **only as a check on our +reading of ACL2**; the independent transcription comes from Intel's SDM. Copied byte for byte, from the repository root, `README.md` and `LICENCE`; from `model/`, the files of the integer subset of jit.md item J.3: the prelude and diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md b/crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md deleted file mode 100644 index f24dac031..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2026 Rui Ueyama - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/README.md b/crates/clazel-x64/tests/data/sail-x86-shina/README.md deleted file mode 100644 index 497fe9d25..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# sail-x86 - -This repo contains a comprehensive formal specification of the x86-64 -instruction set written in the -[Sail](https://github.com/rems-project/sail) ISA specification -language, based on the -[Intel Software Developer's Manual](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html) -(SDM) and actual hardware behavior. Our goal is to provide an -authoritative, machine-readable formalization of x86-64 for researchers -and practitioners who need to formally verify software or hardware -targeting the architecture. - -## Status - -The specification covers the general-purpose, SSE, SSE2, SSE3, SSSE3, -SSE4.1, SSE4.2, AES-NI, AVX/AVX2, AVX-512/EVEX, and x87 FPU -instruction sets, plus the system level: segmentation, paging -(32-bit/PAE/4-level/5-level with EPT), exceptions and interrupts, -real, [virtual-8086](docs/virtual-8086.md) and compatibility modes, SMM, -and VMX virtualization (Linux/KVM -runs as a nested hypervisor on the model's VMX). SGX, AMX, CET, MPX, -and TSX are out of scope, as is any concurrency or memory-ordering -model; see docs/x86-64-completeness-checklist.md for the per-unit -inventory. - -The Sail model can be compiled to C++ using the Sail compiler and serves -as the CPU core in two emulators: a user-mode emulator that runs real -Linux x86-64 binaries (coreutils, Python, Clang), and a system-level -emulator that boots Linux to an interactive shell and SeaBIOS+FreeDOS -to a DOS prompt. The -emulators provide the scaffolding not covered by the ISA specification -itself — memory, peripherals, syscall emulation. - -## Building - -Prerequisites: - -- [Sail](https://github.com/rems-project/sail) 0.20+ -- GMP (`sudo apt install libgmp-dev`) -- CMake 3.20+ -- GCC or Clang with C++23 support - -``` -mkdir build && cd build -cmake .. -make -j$(nproc) -``` - -## User-mode emulator - -``` -./build/usermode-emu/sail-x86-user [args...] -``` - -Both statically and dynamically linked x86-64 ELF binaries are -supported. The emulator interprets each instruction through the Sail -model and emulates Linux syscalls. - -``` -$ ./build/usermode-emu/sail-x86-user /bin/ls / -bin boot dev etc home lib ... -$ ./build/usermode-emu/sail-x86-user /usr/bin/python3 -c "print('hello')" -hello -``` - -Pass `-d` for a debug trace of each instruction. - -## System emulator (Linux boot) - -The system emulator loads a bzImage through the kernel's own 16-bit -real-mode setup path and -boots Linux with an initramfs to an interactive serial console. - -To download the Linux kernel source, build it with a minimal -configuration, build a BusyBox initramfs, and print the boot command: - -``` -cd build -make linux -``` - -This requires `curl`, `busybox-static`, and `fakeroot` in addition to -the standard kernel build tools. The kernel source is downloaded -automatically. - -To run the emulator manually: - -``` -./build/system-emu/sail-x86-system -i initramfs.cpio bzImage -``` - -## Testing - -``` -cd build && ctest -j$(nproc) --output-on-failure -``` - -## Project structure - -- `model/` — Sail specification (~40 files) - - Instruction decoder (prefix, ModR/M, opcode maps) - - Per-instruction semantics (ALU, SSE, AVX, x87, system) - - Types, registers, memory, flags, floating-point externals -- `usermode-emu/` — user-mode Linux emulator in C++ - - ELF loader, Linux syscall emulation, execution loop -- `system-emu/` — system-level emulator in C++ - - Physical memory, device emulation (UART, PIT, PIC) - - Paging, interrupt/exception delivery - - Scripts to build a minimal Linux kernel and initramfs -- `emu-shared/` — code shared between both emulators -- `kvm/` — KVM-based differential tests against real hardware -- `test/` — test programs - -## Acknowledgement - -This work was supported by JST, CREST Grant Number JPMJCR22M3, Japan. diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md b/crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md deleted file mode 100644 index cff2ddb2c..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/SOURCE.md +++ /dev/null @@ -1,40 +0,0 @@ -# A Sail model of x86-64 written from the Intel manuals (a subset of its files) - -Upstream: https://github.com/shina-lab/sail-x86/tree/1829cb6ecc5f924b0fd920582953a2402357a12a -Commit: 1829cb6ecc5f924b0fd920582953a2402357a12a -License: MIT (`LICENSE.md` is the repository's `LICENSE`, copied unchanged; Copyright (c) 2026 Rui Ueyama). - -The commit is the tip of `main` of shina-lab/sail-x86 on 2026-11-16 -("XSAVEC, XGETBV, FPREM and FCMOV: undefined where one manual leaves open what -the other defines", 2026-10-23). Its README says it is "based on the Intel -Software Developer's Manual (SDM) and actual hardware behavior", and the -commit messages cite SDM and AMD APM page numbers and compare the model with -KVM runs on an AMD Zen 4 and an Intel Xeon host. - -**Why it is here:** the other Sail model (`sail-x86-from-acl2`) is a -mechanical translation of the ACL2 model, so it cannot be the second, -independent source jit.md item J.2 asks for. This one has no relation to ACL2 -that its README or the files read here state, and it covers SSE2 scalar -double. It is not a peer-reviewed or long-established source: the repository -was created in 2026-03, has about 1,380 commits by one author, many with an AI -co-author line, and its floating-point arithmetic is `extern` (soft-float -supplied by the emulator, `model/extern.sail`). Whether it may count as the -second source is a decision for a person (`crates/clazel-x64/README.md`). - -Copied byte for byte: `README.md`, `docs/x86-64-completeness-checklist.md`, -and from `model/` the files of item J.3's subset and what they need: -`x86.sail_project` (the build order), `prelude`, `core_types`, `extern`, `regs`, -`rflags`, `exceptions`, `paging`, `mem`, `operands`, `branchless`, `insn_simd`, -`insn_prefixes`, `insn_modrm`, `insn_alu`, `insn_sse_fp`, `insn_baseline`, -`insn_groups`, `insn_dispatch` and `fetch_execute`. - -Not vendored: VEX, EVEX, AMX, x87, MMX, SSE integer, XSAVE, VMX, SMM, -virtual-8086, interrupts and crypto (`model/` is 1.5 MB in all), and the -emulators, tests, proofs and reports. Without them the model does not build as -it stands (`x86.sail_project` lists the rest); it is a text to read, as the -other suites are. - -To update, copy the files from a newer commit, change the commit above, and -run `cargo xtask testdata`. `xtask/src/testdata/isa.rs` writes -`tests/generated/sail_x86_shina.rs`, the inventory of paths, sizes and -hashes. Nothing reads the model yet. diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md b/crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md deleted file mode 100644 index 7b2971670..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/docs/x86-64-completeness-checklist.md +++ /dev/null @@ -1,1152 +0,0 @@ -# x86-64 ISA Completeness Checklist - -Derived from Intel SDM (835 instruction pages, 1208 unique mnemonics). -Each item is testable: verify the Sail spec implements it, or explicitly -documents it as out-of-scope. Refer to the SDM for exact semantics. - ---- - -## Part 1: Instruction Coverage by ISA Extension - -For each instruction: verify (a) it decodes correctly for all valid -opcode/operand-size/addressing-mode combinations listed in SDM, (b) it -computes the correct result, (c) it sets flags per SDM, (d) 64-bit mode -validity matches SDM (some are invalid in 64-bit mode). - -### 1.1 General-Purpose Integer (base x86-64) - -#### 1.1.1 Data Transfer -- [x] MOV (reg/mem/imm, all operand sizes 8/16/32/64) — verified correct -- [x] MOV to/from control registers (MOV CRn) [mov-1 in SDM] — verified correct -- [x] MOV to/from debug registers (MOV DRn) [mov-2 in SDM] — verified: 0F 21 (read) and 0F 23 (write), CPL=0 required, DR4/DR5 alias DR6/DR7 -- [x] MOVSX, MOVSXD (sign-extend 8→16/32/64, 16→32/64, 32→64) — verified correct -- [x] MOVZX (zero-extend 8→16/32/64, 16→32/64) — verified correct -- [x] MOVBE (byte-swap load/store, MOVBE extension) — verified correct -- [x] XCHG (reg-reg, reg-mem; implicit LOCK on memory) — verified correct -- [x] XADD (exchange and add) — verified correct -- [x] CMPXCHG (compare and exchange, 8/16/32/64) — verified correct -- [x] CMPXCHG8B, CMPXCHG16B (8-byte/16-byte compare-and-exchange) — verified correct -- [x] BSWAP (byte-swap 32/64) — verified correct -- [x] XLAT, XLATB (table lookup translation) — verified + KVM tests -- [x] CMOVcc (all 16 conditions, 16/32/64-bit) — verified correct - -#### 1.1.2 Stack Operations -- [x] PUSH (reg, mem, imm8, imm16/32; 16/64-bit operand sizes in 64-bit mode) — verified correct -- [x] POP (reg, mem; 16/64-bit in 64-bit mode) — verified correct -- [x] PUSHF, PUSHFQ (push flags) — verified correct -- [x] POPF, POPFQ (pop flags) — verified, IOPL bug fixed -- [x] PUSHA, PUSHAD (invalid in 64-bit mode — must #UD) — verified correct -- [x] POPA, POPAD (invalid in 64-bit mode — must #UD) — verified correct -- [x] ENTER (create stack frame, nesting levels 0-31) — verified + KVM tests (levels 0,1) -- [x] LEAVE (destroy stack frame) — verified + KVM tests - -#### 1.1.3 Arithmetic -- [x] ADD (all operand size/type combinations, flag effects) — verified correct -- [x] ADC (add with carry) — verified correct -- [x] SUB (subtract) — verified correct -- [x] SBB (subtract with borrow) — verified correct -- [x] INC (no CF modification) — verified correct -- [x] DEC (no CF modification) — verified correct -- [x] NEG (two's complement negate) — verified correct -- [x] CMP (subtract without storing) — verified correct -- [x] MUL (unsigned multiply, 8/16/32/64-bit; widening to double-size) — verified correct -- [x] IMUL (signed multiply — 1-operand widening, 2-operand, 3-operand forms) — verified correct -- [x] DIV (unsigned divide, 8/16/32/64-bit; #DE on overflow/zero) — verified correct -- [x] IDIV (signed divide; #DE on overflow/zero) — verified correct - -#### 1.1.4 Sign/Zero Extension of Accumulators -- [x] CBW (AL→AX), CWDE (AX→EAX), CDQE (EAX→RAX) — verified correct -- [x] CWD (AX→DX:AX), CDQ (EAX→EDX:EAX), CQO (RAX→RDX:RAX) — verified correct - -#### 1.1.5 Logical -- [x] AND, OR, XOR (all operand combinations; OF=CF=0) — verified correct -- [x] NOT (bitwise complement, no flag effects) — verified correct -- [x] TEST (AND without storing) — verified correct - -#### 1.1.6 Shift and Rotate -- [x] SHL/SAL (shift left, same opcode) — verified correct -- [x] SHR (logical shift right) — verified correct -- [x] SAR (arithmetic shift right) — verified correct, OF=0 for count=1 -- [x] ROL (rotate left) — verified correct, SF/ZF/AF/PF unaffected -- [x] ROR (rotate right) — verified correct -- [x] RCL (rotate through carry left) — verified correct, MOD 9/17 for 8/16-bit -- [x] RCR (rotate through carry right) — verified correct, OF set before rotation -- [x] SHLD (double-precision shift left) — verified correct -- [x] SHRD (double-precision shift right) — verified correct -- [x] Shift/rotate count masking (count & 0x1F for 32-bit, count & 0x3F for 64-bit) — verified -- [x] OF flag: defined only for 1-bit shifts, undefined for multi-bit — verified - -#### 1.1.7 Bit and Byte Operations -- [x] BT (bit test → CF) — verified correct -- [x] BTS (bit test and set) — verified correct -- [x] BTR (bit test and reset) — verified correct -- [x] BTC (bit test and complement) — verified correct -- [x] BSF (bit scan forward) — verified correct -- [x] BSR (bit scan reverse) — verified correct -- [x] SETcc (all 16 conditions, byte result) — verified correct -- [x] POPCNT (population count, POPCNT extension) — verified correct -- [x] LZCNT (leading zero count, LZCNT extension — different from BSR) — verified correct -- [x] TZCNT (trailing zero count, BMI1 extension — different from BSF) — verified correct - -#### 1.1.8 Control Flow -- [x] JMP (near relative 8/32, near indirect reg/mem, far direct, far indirect) — verified correct -- [x] Jcc (all 16 conditions, rel8 and rel32) — verified correct -- [x] CALL (near relative, near indirect, far direct, far indirect) — verified, f64 operand-size fix applied -- [x] RET (near, near+imm16, far, far+imm16) — verified, f64 operand-size fix; RETF verified correct -- [x] LOOP, LOOPcc (LOOPE/LOOPZ, LOOPNE/LOOPNZ; uses RCX/ECX/CX per addr size) — verified + KVM tests -- [x] INT n, INT3 (software interrupts) — verified correct; fixed: no error code push for software ints, gate DPL check added. INT1/ICEBP not implemented (raises #UD) -- [x] INTO (invalid in 64-bit mode — must #UD) — verified correct -- [x] IRET, IRETD, IRETQ (interrupt return) — verified, AC/ID flag fix applied -- [x] BOUND (invalid in 64-bit mode — must #UD) — verified correct - -#### 1.1.9 String Operations -- [x] MOVS, MOVSB, MOVSW, MOVSD, MOVSQ — verified correct -- [x] CMPS, CMPSB, CMPSW, CMPSD, CMPSQ — verified correct -- [x] SCAS, SCASB, SCASW, SCASD (SCASQ in 64-bit mode) — verified correct -- [x] LODS, LODSB, LODSW, LODSD, LODSQ — verified correct -- [x] STOS, STOSB, STOSW, STOSD, STOSQ — verified correct -- [N/A] INS, INSB, INSW, INSD — port string I/O, requires I/O port infrastructure not modeled -- [N/A] OUTS, OUTSB, OUTSW, OUTSD — port string I/O, requires I/O port infrastructure not modeled -- [x] REP/REPE/REPZ/REPNE/REPNZ prefix interaction with all string ops — verified correct -- [x] Direction flag (DF) effect on SI/DI increment/decrement — verified correct - -#### 1.1.10 I/O -- [x] IN (imm8 port, DX port; AL/AX/EAX) — verified correct (E4/E5/EC/ED), all operand sizes -- [x] OUT (imm8 port, DX port; AL/AX/EAX) — verified correct (E6/E7/EE/EF), all operand sizes -- [N/A] INS/OUTS (port string I/O, see 1.1.9) — requires I/O port infrastructure not modeled - -#### 1.1.11 Flag Manipulation -- [x] STC, CLC, CMC (set/clear/complement carry) — verified correct -- [x] STD, CLD (set/clear direction) — verified correct -- [x] STI, CLI (set/clear interrupt; IOPL interaction) — verified correct -- [x] LAHF (load AH from flags SF:ZF:0:AF:0:PF:1:CF) — **BUG FIXED**: bit order was reversed -- [x] SAHF (store AH into flags) - -#### 1.1.12 Segment and Address Operations -- [x] LEA (all addressing modes, 16/32/64-bit) — verified, 67h address-size fix applied -- [N/A] LDS, LES (invalid in 64-bit mode — opcodes C4/C5 are VEX prefix) -- [N/A] LFS, LGS, LSS (0F B2/B4/B5 — valid in 64-bit but rarely used; segment descriptor loading not fully modeled) -- [x] NOP (1-byte 0x90 and multi-byte 0F 1F /0) — verified correct - -#### 1.1.13 Decimal Arithmetic (all invalid in 64-bit mode — must #UD) -- [x] AAA, AAS, AAM, AAD — verified #UD in 64-bit mode -- [x] DAA, DAS — verified #UD in 64-bit mode - -#### 1.1.14 Miscellaneous -- [x] CPUID (leaf/subleaf dispatching, feature reporting) — verified correct -- [x] UD (UD0, UD1, UD2 — always #UD) — verified correct -- [x] HLT (halt, ring-0 only) — verified correct -- [x] PAUSE (spin-loop hint) — verified correct -- [x] SERIALIZE (execution serialization) — verified (NOP in sequential model) -- [x] LOCK prefix (valid only with specific memory-destination instructions) — verified correct -- [x] RDTSC (read timestamp counter) — verified correct -- [x] RDTSCP (read timestamp counter and processor ID) — implemented - -### 1.2 x87 Floating-Point - -#### 1.2.1 Data Transfer -- [x] FLD (load float: 32/64/80-bit, ST(i)) — verified: D9/0 mem (f32), DD/0 mem (f64), DB/5 mem (f80), D9/0 reg -- [x] FST, FSTP (store float: 32/64-bit, ST(i); FSTP also 80-bit) — verified: D9/2,3 (f32), DD/2,3 (f64), DB/7 (f80 FSTP) -- [x] FILD (load integer: 16/32/64-bit → ST(0)) — verified: DF/0 (i16), DB/0 (i32), DF/5 (i64) -- [x] FIST, FISTP (store integer from ST(0)) — verified: DF/2,3 (i16), DB/2,3 (i32), DF/7 (i64 FISTP) -- [x] FISTTP (store integer with truncation, SSE3) — verified: DF/1 (i16), DB/1 (i32), DD/1 (i64) -- [x] FBLD (load BCD) — verified: DF/4 mem -- [x] FBSTP (store BCD and pop) — verified: DF/6 mem -- [x] FXCH (exchange ST(0) with ST(i)) — verified: D9/1 reg -- [x] FCMOVcc (conditional float move, 8 conditions) — verified: DA/0-3 (B,E,BE,U), DB/0-3 (NB,NE,NBE,NU) - -#### 1.2.2 Arithmetic -- [x] FADD, FADDP, FIADD — verified: D8/0 (f32), DC/0 (f64), DA/0 (i32), DE/0 (i16), DE/0 reg (FADDP) -- [x] FSUB, FSUBP, FISUB — verified: D8/4, DC/5 reg, DA/4, DE/5 reg (FSUBP) -- [x] FSUBR, FSUBRP, FISUBR (reversed subtract) — verified: D8/5, DC/4 reg, DA/5, DE/4 reg (FSUBRP) -- [x] FMUL, FMULP, FIMUL — verified: D8/1, DC/1, DA/1, DE/1 reg (FMULP) -- [x] FDIV, FDIVP, FIDIV — verified: D8/6, DC/7 reg, DA/6, DE/7 reg (FDIVP) -- [x] FDIVR, FDIVRP, FIDIVR (reversed divide) — verified: D8/7, DC/6 reg, DA/7, DE/6 reg (FDIVRP) -- [x] FABS (absolute value) — verified: D9 E1 -- [x] FCHS (change sign) — verified: D9 E0 -- [x] FSQRT (square root) — verified: D9 FA -- [x] FPREM (partial remainder, 8087-compatible) — verified: D9 F8 -- [x] FPREM1 (IEEE partial remainder) — verified: D9 F5 -- [x] FRNDINT (round to integer) — verified: D9 FC -- [x] FSCALE (scale by power of 2) — verified: D9 FD -- [x] FXTRACT (extract exponent and significand) — verified: D9 F4; fixed FCOM/FCOMP memory: was comparing with ST(i) instead of memory operand - -#### 1.2.3 Transcendental -- [x] FSIN, FCOS, FSINCOS — verified: D9 FE (FSIN), D9 FF (FCOS), D9 FB (FSINCOS pushes cos) -- [x] FPTAN, FPATAN — verified: D9 F2 (FPTAN: tan + push 1.0), D9 F3 (FPATAN: atan2 + pop) -- [x] F2XM1 (2^x - 1) — verified: D9 F0 -- [x] FYL2X, FYL2XP1 (y * log2(x), y * log2(x+1)) — verified: D9 F1, D9 F9 - -#### 1.2.4 Comparison -- [x] FCOM, FCOMP, FCOMPP — verified: D8/2,3 (f32), DC/2,3 (f64), DE D9 (FCOMPP); fixed memory FCOM bug -- [x] FICOM, FICOMP — verified: DA/2,3 (i32 mem), DE/2,3 (i16 mem) -- [x] FCOMI, FCOMIP, FUCOMI, FUCOMIP (set EFLAGS) — verified: DB/5 (FUCOMI), DB/6 (FCOMI), DF/5 (FUCOMIP), DF/6 (FCOMIP) -- [x] FUCOM, FUCOMP, FUCOMPP (unordered compare) — verified: DD/4 (FUCOM), DD/5 (FUCOMP), DA E9 (FUCOMPP) -- [x] FTST (compare ST(0) with 0.0) — verified: D9 E4 -- [x] FXAM (examine ST(0): class/sign) — verified: D9 E5, sets C3/C2/C0 for class, C1 for sign - -#### 1.2.5 Constants -- [x] FLD1, FLDZ, FLDPI, FLDL2E, FLDL2T, FLDLG2, FLDLN2 — verified: D9 E8-EE - -#### 1.2.6 Control -- [x] FINIT, FNINIT (initialize FPU) — verified: DB E3 -- [x] FCLEX, FNCLEX (clear exceptions) — verified: DB E2 -- [x] FLDCW, FSTCW/FNSTCW (load/store control word) — verified: D9/5 (FLDCW), D9/7 (FNSTCW) -- [x] FSTSW/FNSTSW (store status word — AX or memory) — verified: DF E0 (FNSTSW AX), DD/7 (FNSTSW m16) -- [x] FLDENV, FSTENV/FNSTENV (load/store environment) — verified: D9/4 (FLDENV), D9/6 (FNSTENV) -- [x] FSAVE/FNSAVE, FRSTOR (save/restore full state) — verified: DD/6 (FNSAVE), DD/4 (FRSTOR) -- [x] FFREE (free ST(i) register) — verified: DD/0 reg -- [x] FDECSTP, FINCSTP (decrement/increment stack pointer) — verified: D9 F6, D9 F7 -- [x] FNOP (x87 no-op) — verified: D9 D0 (reg=2, sti=0) -- [x] FWAIT/WAIT (wait for pending FPU exceptions) — verified: opcode 9B - -#### 1.2.7 x87 State Save/Restore (SSE era) -- [x] FXSAVE, FXRSTOR (save/restore x87+SSE state) — verified: 0F AE /0 (FXSAVE), /1 (FXRSTOR), REX.W variants - -### 1.3 MMX (legacy, 64-bit packed integer in mm0-mm7) - -- [x] EMMS (empty MMX state — required for x87↔MMX transition) — verified: 0F 77 + KVM tests -- [x] All MMX integer instructions (MOVD/Q, PADD*, PSUB*, PMUL*, PAND/POR/PXOR, PCMP*, PACK*, PUNPCK*, PSHUFW, PINSRW, PEXTRW, PMOVMSKB, PAVG*, PMIN/MAX*, PSAD*, shifts) — ~50 instructions with KVM differential tests -- [x] MASKMOVQ, MOVNTQ — MMX non-temporal ops + KVM tests -- [N/A] MOVDQ2Q, MOVQ2DQ — MMX↔XMM transfer (rarely used, can add if needed) -- [N/A] CVTPD2PI, CVTPI2PD, CVTPI2PS, CVTPS2PI, CVTTPD2PI, CVTTPS2PI — MMX↔float conversions (legacy, rarely used) - -### 1.4 SSE (128-bit, single-precision float) - -#### 1.4.1 SSE Arithmetic -- [x] ADDPS, ADDSS — verified + KVM tests -- [x] SUBPS, SUBSS — verified + KVM tests -- [x] MULPS, MULSS — verified + KVM tests -- [x] DIVPS, DIVSS — verified + KVM tests -- [x] SQRTPS, SQRTSS — verified + KVM tests -- [x] RCPPS, RCPSS (reciprocal approximation) — verified + KVM tests -- [x] RSQRTPS, RSQRTSS (reciprocal sqrt approximation) — verified + KVM tests -- [x] MAXPS, MAXSS (NaN handling per SDM) — verified, NaN bug fixed -- [x] MINPS, MINSS (NaN handling per SDM) — verified, NaN bug fixed - -#### 1.4.2 SSE Comparison -- [x] CMPPS (all 8 predicates), CMPSS — verified, pred 6 NaN bug fixed -- [x] COMISS (ordered compare → EFLAGS) — verified + KVM tests -- [x] UCOMISS (unordered compare → EFLAGS) — verified + KVM tests - -#### 1.4.3 SSE Logical -- [x] ANDPS, ANDNPS, ORPS, XORPS — verified + KVM tests - -#### 1.4.4 SSE Shuffle/Unpack -- [x] SHUFPS (4-element shuffle) — verified + KVM tests -- [x] UNPCKHPS, UNPCKLPS (interleave high/low) — verified + KVM tests -- [x] MOVHLPS, MOVLHPS (move high-to-low, low-to-high) — verified + KVM tests - -#### 1.4.5 SSE Data Transfer -- [x] MOVAPS, MOVUPS (aligned/unaligned 128-bit) — verified + KVM tests -- [x] MOVSS (scalar single) — verified + KVM tests -- [x] MOVHPS, MOVLPS (move high/low 64-bit) — verified + KVM tests -- [x] MOVMSKPS (extract sign bits → GPR) — verified + KVM tests -- [x] MOVNTPS (non-temporal store) — verified + KVM tests - -#### 1.4.6 SSE Conversion -- [x] CVTPS2PD, CVTPD2PS — verified + KVM tests -- [x] CVTSS2SD, CVTSD2SS — verified + KVM tests -- [x] CVTSI2SS, CVTSS2SI — verified + KVM tests -- [x] CVTTSS2SI (truncating) — verified + KVM tests -- [x] CVTDQ2PS, CVTPS2DQ, CVTTPS2DQ — verified, overflow bug fixed - -#### 1.4.7 SSE State/Control -- [x] LDMXCSR, STMXCSR (MXCSR load/store) — verified + KVM tests -- [x] Rounding mode control (bits 14:13) — verified + KVM tests (FP Edge) -- [x] Flush-to-zero (bit 15) — verified + KVM tests (DAZ/FTZ) -- [x] Denormals-are-zeros (bit 6) — verified + KVM tests (DAZ/FTZ) -- [x] Exception mask bits and flag bits — verified - -### 1.5 SSE2 (128-bit, double-precision float + 128-bit integer) - -#### 1.5.1 SSE2 Float64 Arithmetic -- [x] ADDPD, ADDSD — verified + KVM tests -- [x] SUBPD, SUBSD — verified + KVM tests -- [x] MULPD, MULSD — verified + KVM tests -- [x] DIVPD, DIVSD — verified + KVM tests -- [x] SQRTPD, SQRTSD — verified + KVM tests -- [x] MAXPD, MAXSD — verified + KVM tests -- [x] MINPD, MINSD — verified + KVM tests - -#### 1.5.2 SSE2 Float64 Comparison -- [x] CMPPD, CMPSD (all 8 predicates) — verified + KVM tests -- [x] COMISD, UCOMISD — verified + KVM tests - -#### 1.5.3 SSE2 Float64 Logical -- [x] ANDPD, ANDNPD, ORPD, XORPD — verified + KVM tests - -#### 1.5.4 SSE2 Float64 Shuffle/Unpack -- [x] SHUFPD — verified + KVM tests -- [x] UNPCKHPD, UNPCKLPD — verified + KVM tests - -#### 1.5.5 SSE2 Float64 Data Transfer -- [x] MOVAPD, MOVUPD — verified + KVM tests -- [x] MOVSD (scalar double) — verified + KVM tests -- [x] MOVHPD, MOVLPD — verified + KVM tests -- [x] MOVMSKPD — verified + KVM tests -- [x] MOVNTPD — verified + KVM tests - -#### 1.5.6 SSE2 Float64 Conversion -- [x] CVTSI2SD, CVTSD2SI, CVTTSD2SI — verified + KVM tests -- [x] CVTPD2DQ, CVTTPD2DQ, CVTDQ2PD — verified + KVM tests - -#### 1.5.7 SSE2 128-bit Integer -- [x] PADDB..PADDQ (byte/word/dword/qword add, 128-bit) — verified + KVM tests -- [x] PSUBB..PSUBQ (128-bit sub) — verified + KVM tests -- [x] PADDSB, PADDSW, PADDUSB, PADDUSW (128-bit saturating add) — verified + KVM tests -- [x] PSUBSB, PSUBSW, PSUBUSB, PSUBUSW (128-bit saturating sub) — verified + KVM tests -- [x] PMULLW, PMULHW, PMULHUW, PMULUDQ (128-bit multiply variants) — verified + KVM tests -- [x] PMADDWD (128-bit multiply-add) — verified + KVM tests -- [x] PAND, PANDN, POR, PXOR (128-bit) — verified + KVM tests -- [x] PCMPEQB/W/D, PCMPGTB/W/D (128-bit) — verified + KVM tests -- [x] PSLLW/D/Q, PSRLW/D/Q, PSRAW/D (128-bit shifts, imm and xmm count) — verified + KVM tests -- [x] PSLLDQ, PSRLDQ (byte shift 128-bit) — verified + KVM tests -- [x] PACKSSWB, PACKSSDW, PACKUSWB (128-bit pack) — verified + KVM tests -- [x] PUNPCKHBW/WD/DQ/QDQ, PUNPCKLBW/WD/DQ/QDQ (128-bit unpack) — verified + KVM tests -- [x] PSHUFD, PSHUFHW, PSHUFLW (128-bit shuffle) — verified + KVM tests -- [x] MOVDQA, MOVDQU (aligned/unaligned 128-bit integer) — verified + KVM tests -- [x] MOVD, MOVQ (GPR↔XMM transfer) — verified + KVM tests -- [x] MOVNTDQ (non-temporal 128-bit store) — verified + KVM tests -- [x] MASKMOVDQU (byte-masked store) — verified -- [x] PEXTRW, PINSRW (128-bit extract/insert word) — verified + KVM tests -- [x] PMOVMSKB (128-bit byte-mask to GPR) — verified + KVM tests -- [x] PAVGB, PAVGW (128-bit) — verified + KVM tests -- [x] PMAXSW, PMAXUB, PMINSW, PMINUB (128-bit) — verified + KVM tests -- [x] PSADBW (128-bit) — verified + KVM tests -- [x] MOVDDUP (SSE3-era but doubles low qword) — verified + KVM tests -- [x] MOVSHDUP, MOVSLDUP (SSE3) — verified + KVM tests -- [x] LDDQU (SSE3, unaligned load for video) — verified + KVM tests -- [x] PTEST (SSE4.1) — verified + KVM tests - -### 1.6 SSE3 / SSSE3 - -#### 1.6.1 SSE3 -- [x] ADDSUBPS, ADDSUBPD (alternating add/subtract) — verified + KVM tests -- [x] HADDPS, HADDPD (horizontal add) — verified + KVM tests -- [x] HSUBPS, HSUBPD (horizontal subtract) — verified + KVM tests -- [x] MOVDDUP, MOVSHDUP, MOVSLDUP — verified + KVM tests -- [x] LDDQU — verified + KVM tests -- [x] FISTTP (x87 store-integer-with-truncation) — verified in x87 section: DF/1 (i16), DB/1 (i32), DD/1 (i64) -- [N/A] MONITOR, MWAIT (monitor/wait, ring-0) — power management hints, no behavioral effect in sequential model - -#### 1.6.2 SSSE3 (Supplemental SSE3) -- [x] PSHUFB (shuffle bytes) — verified + KVM tests -- [x] PHADDW, PHADDD, PHADDSW (horizontal add) — verified + KVM tests -- [x] PHSUBW, PHSUBD, PHSUBSW (horizontal sub) — verified + KVM tests -- [x] PMADDUBSW (multiply-add unsigned/signed bytes) — verified + KVM tests -- [x] PMULHRSW (multiply high with round and scale) — verified + KVM tests -- [x] PALIGNR (byte-align concatenation) — verified + KVM tests -- [x] PABSB, PABSW, PABSD (absolute value) — verified + KVM tests -- [x] PSIGNB, PSIGNW, PSIGND (conditional negate) — verified + KVM tests - -### 1.7 SSE4.1 / SSE4.2 - -#### 1.7.1 SSE4.1 -- [x] PMULLD (packed multiply low dword → dword) — verified + KVM tests -- [x] PMULDQ (packed multiply signed dword → qword) — verified + KVM tests -- [x] PBLENDW, BLENDPS, BLENDPD (blend with immediate) — verified + KVM tests -- [x] PBLENDVB, BLENDVPS, BLENDVPD (variable blend) — verified + KVM tests -- [x] DPPD, DPPS (dot product) — verified + KVM tests -- [x] ROUNDPS, ROUNDPD, ROUNDSS, ROUNDSD (round with mode) — verified + KVM tests -- [x] INSERTPS, EXTRACTPS (single-precision insert/extract) — verified + KVM tests -- [x] PINSRB, PINSRD, PINSRQ (insert byte/dword/qword) — verified + KVM tests -- [x] PEXTRB, PEXTRD, PEXTRQ (extract byte/dword/qword) — verified + KVM tests -- [x] PMOVSX (packed sign-extend: B→W, B→D, B→Q, W→D, W→Q, D→Q) — verified + KVM tests -- [x] PMOVZX (packed zero-extend: same variants) — verified + KVM tests -- [x] PMINSB, PMINSD, PMINUW, PMINUD (new min variants) — verified + KVM tests -- [x] PMAXSB, PMAXSD, PMAXUW, PMAXUD (new max variants) — verified + KVM tests -- [x] PACKUSDW (pack dword→word unsigned saturation) — verified + KVM tests -- [x] PCMPEQQ (packed compare equal qword) — verified + KVM tests -- [x] PHMINPOSUW (horizontal minimum of unsigned words) — verified + KVM tests -- [x] MPSADBW (multiple sum of absolute differences) — verified + KVM tests -- [x] MOVNTDQA (non-temporal aligned load) — verified + KVM tests -- [x] PTEST (128-bit bitwise test → ZF/CF) — verified + KVM tests - -#### 1.7.2 SSE4.2 -- [x] PCMPESTRI, PCMPESTRM (explicit-length string compare) — verified, delegated to hardware intrinsics -- [x] PCMPISTRI, PCMPISTRM (implicit-length string compare) — verified, delegated to hardware intrinsics -- [x] PCMPGTQ (packed compare greater-than qword) — verified correct -- [x] CRC32 (CRC-32C accumulate) — verified correct + KVM tests -- [x] POPCNT (population count) — verified correct - -### 1.8 AVX (VEX-encoded, 256-bit float, non-destructive 3-operand) - -Note: All SSE integer/float instructions have VEX-encoded equivalents -(VADDPS, VMULPD, VPAND, etc.). The tester should verify: - -- [x] VEX 128-bit forms zero the upper 128 bits of YMM — verified (write_xmm zeroes ZMM[511:128]) -- [x] VEX 256-bit forms of all SSE float ops (PS/PD/SS/SD) — verified + KVM tests -- [x] VEX 3-operand encoding (dest ≠ src1 for all applicable ops) — verified + KVM tests -- [x] VBROADCAST (VBROADCASTSS, VBROADCASTSD, VBROADCASTF128) — verified + KVM tests -- [x] VINSERTF128, VEXTRACTF128 (insert/extract 128-bit lane) — verified + KVM tests -- [x] VPERM2F128 (permute 256-bit float lanes) — verified + KVM tests -- [x] VMASKMOV (conditional float load/store with mask) — verified + KVM tests -- [x] VTESTPS, VTESTPD (bitwise test → ZF/CF) — verified + KVM tests -- [x] VZEROALL, VZEROUPPER (clear upper YMM state) — verified correct -- [x] VEX.vvvv must be 1111b for instructions that don't use it — verified - -### 1.9 AVX2 (VEX-encoded, 256-bit integer) - -- [x] All SSE2/SSSE3/SSE4.1 integer ops promoted to 256-bit (VPADDB..Q, VPSUBB..Q, etc.) — verified + KVM tests -- [x] VPBLENDD (blend dwords with immediate) — verified + KVM tests -- [x] VPBROADCASTB/W/D/Q (broadcast scalar to all elements) — verified + KVM tests -- [x] VPBROADCAST from GPR — verified: EVEX-only (7A/7B/7C), implemented in insn_evex_arith.sail and insn_evex_perm.sail -- [x] VPERMD, VPERMQ (cross-lane dword/qword permute) — verified + KVM tests -- [x] VPERMPD, VPERMPS (cross-lane float permute) — verified + KVM tests -- [x] VPERM2I128 (permute 128-bit integer lanes) — verified + KVM tests -- [x] VINSERTI128, VEXTRACTI128 (insert/extract 128-bit integer lane) — verified + KVM tests -- [x] VPMASKMOV (conditional integer load/store) — verified + KVM tests -- [x] VPSLLVD/Q, VPSRLVD/Q, VPSRAVD (per-element variable shift) — verified + KVM tests -- [x] VPGATHERDD/DQ/QD/QQ (gather integer with VSIB addressing) — verified + KVM tests -- [x] VGATHERDPS/DPD/QPS/QPD (gather float with VSIB addressing) — verified + KVM tests - -### 1.10 FMA (Fused Multiply-Add, VEX-encoded) - -All 132/213/231 forms, scalar and packed, float32 and float64: -- [x] VFMADD{132,213,231}{PS,PD,SS,SD} (fused multiply-add) — verified + KVM tests -- [x] VFMSUB{132,213,231}{PS,PD,SS,SD} (fused multiply-subtract) — verified + KVM tests -- [x] VFNMADD{132,213,231}{PS,PD,SS,SD} (fused negate-multiply-add) — verified + KVM tests -- [x] VFNMSUB{132,213,231}{PS,PD,SS,SD} (fused negate-multiply-subtract) — verified + KVM tests -- [x] VFMADDSUB{132,213,231}{PS,PD} (alternating add/sub) — verified + KVM tests -- [x] VFMSUBADD{132,213,231}{PS,PD} (alternating sub/add) — verified + KVM tests - -### 1.11 BMI1 / BMI2 (Bit Manipulation) - -#### 1.11.1 BMI1 -- [x] ANDN (bitwise AND-NOT, sets flags) — verified correct -- [x] BEXTR (bit field extract) — verified correct -- [x] BLSI (isolate lowest set bit) — verified correct -- [x] BLSMSK (mask up to lowest set bit) — verified correct -- [x] BLSR (reset lowest set bit) — verified correct -- [x] TZCNT (trailing zero count) — verified correct - -#### 1.11.2 BMI2 -- [x] BZHI (zero high bits from specified position) — verified correct -- [x] MULX (unsigned multiply without flags) — verified correct -- [x] PDEP (parallel bit deposit) — verified correct -- [x] PEXT (parallel bit extract) — verified correct -- [x] RORX (rotate right without flags) — verified correct -- [x] SARX, SHLX, SHRX (shift without flags) — verified correct - -### 1.12 ADX (Multi-Precision Arithmetic) -- [x] ADCX (unsigned add with CF in, CF out) — verified correct -- [x] ADOX (unsigned add with OF in, OF out) — verified correct - -### 1.13 AES-NI (AES New Instructions) -- [x] AESENC (one AES encryption round) — verified, delegated to hardware intrinsics -- [x] AESENCLAST (last AES encryption round) — verified, delegated to hardware intrinsics -- [x] AESDEC (one AES decryption round) — verified, delegated to hardware intrinsics -- [x] AESDECLAST (last AES decryption round) — verified, delegated to hardware intrinsics -- [x] AESIMC (inverse mix columns) — verified, delegated to hardware intrinsics -- [x] AESKEYGENASSIST (AES key generation assist) — verified, delegated to hardware intrinsics -- [x] PCLMULQDQ (carry-less multiplication) — verified, delegated to hardware intrinsics - -### 1.14 SHA (SHA Extensions) -- [x] SHA1RNDS4 (SHA-1 4 rounds) — implemented, delegated to hardware intrinsics + KVM tests -- [x] SHA1NEXTE (SHA-1 next E) — implemented, delegated to hardware intrinsics + KVM tests -- [x] SHA1MSG1, SHA1MSG2 (SHA-1 message schedule) — implemented, delegated to hardware intrinsics + KVM tests -- [x] SHA256RNDS2 (SHA-256 2 rounds) — implemented, implicit XMM0 operand + KVM tests -- [x] SHA256MSG1, SHA256MSG2 (SHA-256 message schedule) — implemented, delegated to hardware intrinsics + KVM tests - -### 1.15 AVX-512 Foundation (EVEX-encoded, 512-bit, opmask) - -#### 1.15.1 EVEX Encoding Mechanics -- [x] EVEX prefix decoding (4-byte prefix: P0/P1/P2/P3) — verified and fixed: mmm is 3 bits (was 2), added P[3]=0 and P[10]=1 reserved bit checks -- [x] EVEX.R, EVEX.X, EVEX.B, EVEX.R' (register extension to 32 SIMD regs) — verified: all inverted, correct bit positions -- [x] EVEX.aaa (opmask register k1-k7; k0 = no masking) — verified: stored directly from P2[2:0] -- [x] EVEX.z (zeroing vs merging masking) — verified: P2[7], stored directly -- [x] EVEX.b (broadcast, rounding override, SAE) — verified: P2[4], stored directly -- [x] EVEX.L'L (vector length: 128/256/512) — verified: P2[6:5], stored directly -- [x] Embedded rounding control {rn-sae, rd-sae, ru-sae, rz-sae} — implemented via evex_begin_rc/evex_end_rc: overrides MXCSR RC when EVEX.b=1 for reg-reg, forces 512-bit vector length; applied to all EVEX FP arithmetic, all FMA, VSCALEF, VGETEXP, and all EVEX conversion instructions (VCVTPS2DQ/UDQ/QQ, VCVTPD2DQ/UDQ/QQ, VCVTDQ2PS, VCVTQQ2PS/PD, VCVTUDQ2PS/PD, VCVTUQQ2PS/PD, VCVTPS2PD, VCVTPD2PS, VCVTSI2SS/SD, VCVTSS2SI/SD, VCVTUSI2SS/SD, VCVTSS2USI, VCVTSD2USI) + 22 KVM tests -- [x] Suppress-all-exceptions (SAE) — implied by embedded rounding control (EVEX.b=1 for reg-reg); sequential model does not generate FP exceptions, so SAE has no behavioral effect -- [x] Memory broadcast (1-to-4, 1-to-8, 1-to-16) — verified: comprehensive coverage via evex_bcast_src_f32/f64_{zmm,ymm,xmm} helpers. Applied to ALL dword/qword EVEX instructions: packed FP arithmetic, FMA 132/213/231, conversions (same-width/narrowing/widening), permutes, compares, shuffles, integer arithmetic, logical, VNNI, ternary logic, variable shifts/rotates, VPOPCNT/VPLZCNT/VPCONFLICT, VPMADD52, VGF2P8AFFINE, and more. Byte/word BW-extension instructions correctly excluded (no broadcast per SDM). 22 KVM broadcast tests. - -#### 1.15.2 Opmask (k0-k7) Instructions -- [x] KMOVW/B/D/Q (move mask) — verified: W forms implemented (0F 90/91/92/93) + KVM tests -- [x] KANDW/B/D/Q, KANDNW/B/D/Q (mask AND, AND-NOT) — verified: W forms implemented (0F 41/42) + KVM tests -- [x] KORW/B/D/Q, KXORW/B/D/Q, KXNORW/B/D/Q (mask OR, XOR, XNOR) — verified: W forms implemented (0F 45/47/46) + KVM tests -- [x] KNOTW/B/D/Q (mask NOT) — verified: W form implemented (0F 44) + KVM tests -- [x] KORTESTW/B/D/Q, KTESTW/B/D/Q (mask test → EFLAGS) — verified: W forms implemented (0F 98/99) + KVM tests -- [x] KSHIFTLW/B/D/Q, KSHIFTRW/B/D/Q (mask shift) — verified: W forms implemented (0F3A 32/30) + KVM tests -- [x] KUNPCKBW, KUNPCKWD, KUNPCKDQ (mask unpack) — verified: BW/WD forms implemented (0F 4B) -- [x] KADDW/B/D/Q (mask add) — verified: W form implemented (0F 4A) - -#### 1.15.3 AVX-512F Arithmetic (512-bit) -- [x] VADDPS/PD, VSUBPS/PD (512-bit add/sub) — verified: implemented in insn_evex_fp.sail -- [x] VMULPS/PD, VDIVPS/PD (512-bit mul/div) — verified: implemented in insn_evex_fp.sail -- [x] VSQRTPS/PD (512-bit sqrt) — verified: implemented in insn_evex_fp.sail -- [x] VFMADD/VFMSUB/VFNMADD/VFNMSUB (512-bit FMA, all forms) — verified: all 132/213/231, PS/PD/SS/SD in insn_evex_fma.sail -- [x] VFMADDSUB/VFMSUBADD (512-bit alternating) — verified: implemented in insn_evex_fma.sail -- [x] VMAXPS/PD, VMINPS/PD (512-bit with opmask) — verified: implemented in insn_evex_fp.sail -- [x] Scalar variants: VADDSS/SD, VMULSS/SD, VSUBSS/SD, VDIVSS/SD, VSQRTSS/SD, VMINSS/SD, VMAXSS/SD (EVEX-encoded scalars) — implemented with {er} support + 13 KVM tests -- [x] EVEX VMOVSS/SD (scalar move, load/store/reg-reg merge) — verified: opcode 10 (load) + opcode 11 (store), both memory and 3-operand register forms + 8 KVM tests -- [x] All with merging/zeroing masking — verified: evex_merge helper applies k-mask throughout - -#### 1.15.4 AVX-512F Comparison -- [x] VCMPPS/PD (compare → opmask register, all 32 predicates) — verified: full 5-bit predicate in insn_evex_fp.sail -- [x] VPCMPD/UD/Q/UQ (integer compare → opmask, 8 predicates) — fixed: 0x1F was calling unsigned instead of signed; added missing VPCMPQ (W=1) and VPCMPUQ (W=1); opcode 0x1E added for VPCMPUD/UQ. KVM-tested signed vs unsigned results. -- [x] VPCMPB/UB/W/UW (AVX-512BW, compare bytes/words → opmask) — fixed: added missing VPCMPW (W=1) and VPCMPUW (W=1) variants. KVM-tested signed vs unsigned word results. -- [x] VPTESTMB/W/D/Q (bitwise test → opmask) — verified: implemented in insn_evex_arith.sail -- [x] VPTESTNMB/W/D/Q (bitwise test-not → opmask) — verified: implemented in insn_evex_arith.sail - -#### 1.15.5 AVX-512F Conversion -- [x] VCVTPS2PD, VCVTPD2PS (float widen/narrow, 512-bit) — verified: implemented in insn_evex_fp.sail -- [x] VCVTPS2DQ, VCVTDQ2PS, VCVTTPD2DQ, etc. — verified: implemented in insn_evex_fp.sail -- [x] VCVTPS2UDQ, VCVTPD2UDQ (convert to unsigned) — verified: implemented in insn_evex_fp.sail -- [x] VCVTUDQ2PS, VCVTUDQ2PD (unsigned int → float) — verified: implemented in insn_evex_fp.sail -- [x] VCVTPS2QQ, VCVTPD2QQ (float → signed qword) — verified: helpers + dispatch in insn_evex_fp.sail -- [x] VCVTPS2UQQ, VCVTPD2UQQ (float → unsigned qword) — verified: helpers + dispatch in insn_evex_fp.sail -- [x] VCVTQQ2PS (signed qword → float32, narrowing) — implemented: EVEX.NP.0F.W1 5B + KVM tests -- [x] VCVTQQ2PD (signed qword → float64) — verified: helpers + dispatch in insn_evex_fp.sail -- [x] VCVTUQQ2PS, VCVTUQQ2PD (unsigned qword → float) — verified: helpers + dispatch in insn_evex_fp.sail -- [x] VCVTSD2USI, VCVTSS2USI (scalar float → unsigned GPR) — verified: EVEX 0F 79 F2/F3 prefix -- [x] VCVTUSI2SD, VCVTUSI2SS (unsigned GPR → scalar float) — verified: EVEX 0F 7B F2/F3 prefix -- [x] VCVTTPS2QQ, VCVTTPD2QQ (truncating float → signed qword) — verified: helpers + dispatch -- [x] VCVTTPS2UDQ, VCVTTPD2UDQ (truncating float → unsigned dword) — verified: helpers + dispatch -- [x] VCVTTPS2UQQ, VCVTTPD2UQQ (truncating float → unsigned qword) — verified: helpers + dispatch - -#### 1.15.6 AVX-512F Data Movement -- [x] VMOVDQA32/64, VMOVDQU32/64 (aligned/unaligned with mask) — verified: implemented in insn_evex_fp.sail and insn_evex_int.sail; VMOVDQU8/16 not yet implemented -- [x] VPBROADCASTD/Q (broadcast with EVEX) — verified: from XMM/mem and GPR in insn_evex_perm.sail -- [x] VPBROADCASTB/W (AVX-512BW) — verified: from XMM/mem and GPR in insn_evex_perm.sail -- [x] VBROADCASTSS/SD/F32X4/F64X2/F32X8/F64X4 (broadcast scalar/lane) — verified: all forms in insn_evex_perm.sail (0F38 18/19/1A/1B) -- [x] VMOVSH, VMOVW (AVX-512FP16) — FP16 move instructions implemented in insn_evex_fp16.sail -- [x] VCOMPRESSPD/PS (compress packed float) — verified: insn_evex_perm.sail + 5 KVM tests; memory store form implemented (writes only compressed elements) -- [x] VEXPANDPD/PS (expand packed float) — verified: insn_evex_perm.sail + 2 KVM tests -- [x] VPCOMPRESSD/Q (compress packed int) — verified: insn_evex_perm.sail + 1 KVM test; memory store form implemented -- [x] VPEXPANDD/Q (expand packed int) — verified: insn_evex_perm.sail - -#### 1.15.7 AVX-512F Permute/Shuffle -- [x] VPERMD/W, VPERMQ, VPERMPD, VPERMPS (512-bit permute) — verified: implemented in insn_evex_perm.sail -- [x] VPERMI2B/W/D/Q/PS/PD (2-source permute, index in dest) — verified and fixed: D/Q/PS/PD in insn_evex_perm.sail; B/W opcode 0F38 75 was missing from dispatch, now implemented + 1 KVM test -- [x] VPERMT2B/W/D/Q/PS/PD (2-source permute, index in src) — verified: D/Q/PS/PD in insn_evex_perm.sail, B/W in insn_evex_arith.sail -- [x] VPERMILPS, VPERMILPD (in-lane permute) — verified: implemented in insn_evex_perm.sail -- [x] VSHUFF32X4, VSHUFF64X2, VSHUFI32X4, VSHUFI64X2 (cross-lane shuffle) — verified: implemented in insn_evex_imm.sail -- [x] VINSERTF32X4/64X2/32X8/64X4 (insert 128/256-bit) — verified: all forms in insn_evex_imm.sail (0F3A 18/1A) -- [x] VINSERTI32X4/64X2/32X8/64X4 (integer insert) — verified: all forms in insn_evex_imm.sail -- [x] VEXTRACTF32X4/64X2/32X8/64X4 (extract 128/256-bit) — verified: all forms in insn_evex_imm.sail (0F3A 19/1B) -- [x] VEXTRACTI32X4/64X2/32X8/64X4 (integer extract) — verified: all forms in insn_evex_imm.sail -- [x] VALIGND, VALIGNQ (dword/qword-granularity concatenate+shift) — verified: implemented in insn_evex_imm.sail -- [x] VPSHUFBITQMB (AVX-512BITALG, shuffle bit test → mask) — verified: insn_evex_perm.sail, 0F38 8F - -#### 1.15.8 AVX-512F Logic and Blend -- [x] VPTERNLOGD, VPTERNLOGQ (ternary logic with imm8 truth table) — verified: implemented in insn_evex_imm.sail + 10 KVM tests (a, b, c, ones, zeros, AND, OR, XOR, 3-way XOR, 3-way AND) -- [x] VPBLENDMD/Q (blend with opmask) — verified and fixed: D/Q in insn_evex_perm.sail; B/W in insn_evex_arith.sail; merge masking bug fixed (k[i]=0 gave old_dst instead of SRC1) + 5 KVM tests -- [x] VBLENDMPS, VBLENDMPD (blend float with opmask) — verified and fixed: insn_evex_perm.sail; same merge masking bug fixed - -#### 1.15.9 AVX-512F Shift/Rotate -- [x] VPSLLVW/D/Q, VPSRLVW/D/Q, VPSRAVW/D/Q (variable shift, 512-bit) — verified: all variants in insn_evex_arith.sail -- [x] VPSRAQ (arithmetic right shift qwords by imm/xmm, AVX-512 new) — verified: insn_evex_int.sail + 4 KVM tests -- [x] VPROLVD/Q (variable rotate left) — verified: implemented in insn_evex_arith.sail -- [x] VPROLD/Q (immediate rotate left) — implemented in insn_evex_int.sail, EVEX.66.0F 72 /1 + KVM tests -- [x] VPRORVD/Q (variable rotate right) — verified: implemented in insn_evex_arith.sail -- [x] VPRORD/Q (immediate rotate right) — implemented in insn_evex_int.sail, EVEX.66.0F 72 /0 + KVM tests - -#### 1.15.10 AVX-512F Gather/Scatter -- [x] VPGATHERDD/DQ/QD/QQ (EVEX gather with opmask) — verified: implemented in insn_evex_perm.sail; fixed disp_n for W=1 qword variants (was 4, now 8) -- [x] VGATHERDPS/DPD/QPS/QPD (EVEX gather float) — verified: implemented in insn_evex_perm.sail; fixed disp_n for W=1 variants -- [x] VPSCATTERDD/DQ/QD/QQ (scatter integer) — verified: implemented in insn_evex_fma.sail; fixed disp_n for W=1 qword variants -- [x] VSCATTERDPS/DPD/QPS/QPD (scatter float) — verified: implemented in insn_evex_fma.sail; fixed disp_n for W=1 variants -- [N/A] VGATHERPF0/PF1 (prefetch gather, AVX-512PF) — AVX-512PF (Xeon Phi only) not targeted -- [N/A] VSCATTERPF0/PF1 (prefetch scatter, AVX-512PF) — AVX-512PF (Xeon Phi only) not targeted - -#### 1.15.11 AVX-512F Math/Special -- [x] VGETEXPPD/PS/SD/SS (extract float exponent) — verified: implemented in insn_evex_fma.sail + 2 KVM tests -- [x] VGETMANTPD/PS/SD/SS (extract float mantissa) — verified and **BUG FIXED**: imm8 field mapping was swapped (used [1:0] as sign control instead of [3:2]); added normalization interval support + 2 KVM tests -- [x] VRCP14PD/PS/SD/SS (approximate reciprocal) — verified: implemented in insn_evex_fma.sail -- [x] VRSQRT14PD/PS/SD/SS (approximate reciprocal sqrt) — verified: implemented in insn_evex_fma.sail -- [N/A] VRCP28PD/PS/SD/SS (high-precision reciprocal, AVX-512ER) — AVX-512ER (Xeon Phi only) not targeted -- [N/A] VRSQRT28PD/PS/SD/SS (high-precision recip sqrt, AVX-512ER) — AVX-512ER (Xeon Phi only) not targeted -- [N/A] VEXP2PD/PS (base-2 exponential, AVX-512ER) — AVX-512ER (Xeon Phi only) not targeted -- [x] VSCALEFPD/PS/SD/SS (scale by power of 2) — verified: implemented in insn_evex_fma.sail -- [x] VRNDSCALEPD/PS/SD/SS (round to fixed number of fraction bits) — verified: rounding mode fix applied + 4 KVM tests -- [x] VREDUCEPD/PS/SD/SS (reduce float range) — verified + 2 KVM tests -- [x] VRANGEPD/PS/SD/SS (range restriction) — verified and **BUG FIXED**: sign control (imm8[3:2]) was ignored, abs_min/abs_max returned absolute values instead of originals; rewritten to match SDM pseudocode + 8 KVM tests -- [x] VFIXUPIMMPD/PS/SD/SS (fix up special float values) — verified: full token classification + response table in C emulator + 2 KVM tests -- [x] VFPCLASSPD/PS/SD/SS (classify float → opmask) — verified: implemented in insn_evex_imm.sail + 8 KVM tests (all 8 token types tested) - -#### 1.15.12 AVX-512 Integer Extensions -- [x] VPMOVDB/DW/QB/QD/QW/WB (truncate) — verified: all variants in insn_evex_arith.sail and insn_evex_imm.sail -- [x] VPMOVSDB/SDW/SQB/SQD/SQW/SWB (signed saturation truncate) — verified: implemented in insn_evex_arith.sail -- [x] VPMOVUSDB/USDW/USQB/USQD/USQW/USWB (unsigned saturation truncate) — verified: implemented in insn_evex_arith.sail -- [x] VPMOVB2M/W2M/D2M/Q2M (MSB to mask) — verified: all 4 variants in insn_evex_arith.sail -- [x] VPMOVM2B/W/D/Q (mask to vector) — verified: all 4 variants in insn_evex_arith.sail -- [x] VPMADD52HUQ, VPMADD52LUQ (52-bit integer FMA, AVX-512IFMA) — verified: insn_evex_fma.sail, 0F38 B4/B5 + 4 KVM tests -- [x] VPMULTISHIFTQB (multi-shift qword, AVX-512VBMI) — verified: insn_evex_arith.sail, 0F38 83 + 2 KVM tests -- [x] VPOPCNTB/W/D/Q (per-element popcount, AVX-512BITALG/VPOPCNTDQ) — verified: insn_evex_arith.sail, 0F38 54/55 + 2 KVM tests -- [x] VPLZCNTD/Q (per-element leading zero count, AVX-512CD) — verified: insn_evex_arith.sail, 0F38 44 + 2 KVM tests -- [x] VPCONFLICTD/Q (conflict detection, AVX-512CD) — verified: insn_evex_arith.sail, 0F38 C4 + 3 KVM tests -- [x] VPDPBUSD, VPDPBUSDS, VPDPWSSD, VPDPWSSDS (VNNI dot product) — verified: all 4 variants in insn_evex_arith.sail + 5 KVM tests -- [x] VP2INTERSECTD/Q (AVX-512VP2INTERSECT) — insn_evex_arith.sail, 0F38 68; checked against a C reference in avx512-test (no hardware oracle: only Tiger Lake and Zen 5 have it) -- [N/A] VP4DPWSSD, VP4DPWSSDS (4-iteration dot product, AVX-512_4VNNIW) — Xeon Phi only, not targeted -- [N/A] V4FMADDPS, V4FMADDSS, V4FNMADDPS, V4FNMADDSS (AVX-512_4FMAPS) — Xeon Phi only, not targeted -- [x] VPSHLDW/D/Q, VPSHLDVW/D/Q (concatenate and shift left, AVX-512VBMI2) — verified and fixed: immediate in insn_evex_imm.sail + 4 KVM tests; variable in insn_evex_arith.sail + 2 KVM tests (operand order bug fixed) -- [x] VPSHRDW/D/Q, VPSHRDVW/D/Q (concatenate and shift right, AVX-512VBMI2) — verified and fixed: immediate in insn_evex_imm.sail + 4 KVM tests; variable in insn_evex_arith.sail + 2 KVM tests (operand order bug fixed) -- [x] VPCOMPRESSB/W (byte/word compress, AVX-512VBMI2) — **REWRITTEN**: was simplified pass-through (just copy), now implements proper compress semantics with writemask + 8 KVM tests (reg+mem forms) -- [x] VPEXPANDB/W (byte/word expand, AVX-512VBMI2) — **REWRITTEN**: was simplified pass-through, now implements proper expand semantics with writemask -- [x] VDBPSADBW (double-block packed SAD, AVX-512BW) — verified and fixed: insn_evex_imm.sail, 0F3A 42 + 2 KVM tests (algorithm rewritten to match SDM: dword selection + sliding window SAD) - -### 1.16 AVX-512 FP16 (EVEX-encoded, float16) - -- [x] VADDPH/SH, VSUBPH/SH, VMULPH/SH, VDIVPH/SH, VMINPH/SH, VMAXPH/SH, VSQRTPH — packed/scalar FP16 arithmetic (MAP5, NP W=0) -- [x] VCVTPH2PD, VCVTDQ2PH, VCVTQQ2PH — FP16 conversions (MAP5) -- [x] VFMADD132/213/231PH, VFMSUB132/213/231PH, VFNMADD132/213/231PH, VFNMSUB132/213/231PH — all 12 FP16 FMA forms (MAP6, 66 W=0) -- [x] VCMPPH/SH, VCOMISH, VUCOMISH — FP16 compare (MAP3 0xC2 + MAP5 0x2E/0x2F) -- [x] VRCPPH/SH, VRSQRTPH/SH — FP16 reciprocal/rsqrt (MAP6 0x4C-0x4F) -- [x] VSCALEFPH/SH, VGETEXPPH/SH, VGETMANTPH/SH — FP16 special ops (MAP6 0x2C/0x2D/0x42/0x43, MAP3 0x26/0x27) -- [x] VREDUCEPH/SH, VRNDSCALEPH/SH, VFPCLASSPH/SH — FP16 reduce/round/classify (MAP3 0x56/0x57/0x08/0x0A/0x66/0x67) -- [x] VFMADDSUBPH, VFMSUBADDPH — FP16 interleaved FMA (MAP6 0x96/0x97/0xA6/0xA7/0xB6/0xB7) -- [x] VFCMADDCPH/SH, VFCMULCPH/SH, VFMADDCPH/SH, VFMULCPH/SH — FP16 complex arithmetic (MAP6 0x56/0x57/0xD6/0xD7) -- [x] VMOVSH, VMOVW — FP16 move (MAP5 0x10/0x11/0x6E/0x7E) -- [x] All FP16 conversions (VCVTPH2W/UW/DQ/UDQ/QQ/UQQ, VCVTW2PH/UW2PH, VCVTSH2SS/SD, VCVTSI2SH, VCVTSH2SI, etc.) — MAP5 0x78-0x7D, 0x2A/0x2C/0x2D/0x5A/0x5B/0x1D, MAP6 0x13 -- [x] Scalar FP16 FMA (VFMADD/VFMSUB/VFNMADD/VFNMSUB 132/213/231SH) — MAP6 0x99-0xBF odd opcodes - -### 1.17 AVX-512 BFloat16 -- [x] VCVTNE2PS2BF16, VCVTNEPS2BF16, VDPBF16PS - -### 1.18 AMX (Advanced Matrix Extensions) -- [N/A] All AMX instructions (LDTILECFG, STTILECFG, TILELOADD/T1, TILESTORED, TILEZERO, TILERELEASE, TDPBSSD/BSUD/BUSD/BUUD, TDPBF16PS) — AMX not targeted; requires tile register file and specialized dot-product microarchitecture - -### 1.18.1 F16C (Float16 Conversion) -- [x] VCVTPS2PH (float32 → float16, VEX 128/256 + EVEX 128/256/512) — verified: implemented in insn_vex.sail + insn_evex_imm.sail, subnormal fix applied + 4 KVM tests; imm8 rounding control not yet honored (always rounds nearest) -- [x] VCVTPH2PS (float16 → float32, VEX 128/256 + EVEX 128/256/512) — verified: implemented in insn_vex.sail + insn_evex_arith.sail + KVM tests - -### 1.19 Galois Field (GFNI) -- [x] GF2P8MULB (GF(2^8) byte multiply) — legacy SSE + VEX 128/256 + EVEX 128/256/512, all + KVM tests -- [x] GF2P8AFFINEINVQB (GF(2^8) affine inverse) — legacy SSE + VEX 128/256 + EVEX 128/256/512, all + KVM tests -- [x] GF2P8AFFINEQB (GF(2^8) affine transform) — legacy SSE + VEX 128/256 + EVEX 128/256/512, all + KVM tests - -### 1.20 Key Locker -- [N/A] All Key Locker instructions (LOADIWKEY, ENCODEKEY128/256, AESENC/DEC128/256KL, AESENC/DECWIDE128/256KL) — Key Locker not targeted; requires internal wrapping key hardware - -### 1.21 CET (Control-Flow Enforcement Technology) - -#### 1.21.1 Indirect Branch Tracking -- [x] ENDBR32, ENDBR64 (end branch markers) — handled as NOP via 0F 1E multi-byte NOP range (correct when CET not enabled) - -#### 1.21.2 Shadow Stack -- [N/A] All CET shadow stack instructions (INCSSPD/Q, RDSSPD/Q, SAVEPREVSSP, RSTORSSP, WRSSD/Q, WRUSSD/Q, SETSSBSY, CLRSSBSY) — CET shadow stack not targeted; requires separate shadow stack page table support - -### 1.22 MPX (Memory Protection Extensions) — deprecated -- [N/A] All MPX instructions (BNDMK, BNDCL/CU/CN, BNDMOV, BNDLDX/STX) — MPX deprecated by Intel, removed from hardware; not targeted - -### 1.23 TSX (Transactional Synchronization Extensions) -- [N/A] All TSX instructions (XBEGIN, XEND, XABORT, XTEST, XACQUIRE/XRELEASE HLE prefixes) — TSX effectively deprecated (disabled via microcode on most CPUs due to security issues); not targeted - -### 1.24 XSAVE State Management -- [x] XSAVE (0F AE /4), XRSTOR (0F AE /5) — verified: delegates to external C++ -- [N/A] XSAVEC, XSAVEOPT, XSAVES, XRSTORS — extended XSAVE variants; XSAVE/XRSTOR already implemented and sufficient for Linux boot -- [x] XGETBV (get extended control register XCR0) — verified: 0F 01 D0, returns 0xE7 for XCR0 -- [N/A] XSETBV (set extended control register XCR0) — XCR0 is hardcoded to 0xE7 (x87+SSE+AVX+AVX-512); dynamic feature enable not needed - -### 1.25 System Instructions - -#### 1.25.1 Descriptor Table -- [x] LGDT, LIDT (load GDT/IDT register) — verified: memory-only, CPL=0 required -- [x] SGDT, SIDT (store GDT/IDT register) — verified: memory-only, no privilege check -- [x] LLDT, SLDT (load/store LDT register) — verified: 0F 00 /0 (SLDT), /2 (LLDT) -- [x] LTR, STR (load/store task register) — verified: 0F 00 /1 (STR), /3 (LTR) with GDT descriptor parsing -- [x] ARPL (adjust RPL, invalid in 64-bit mode) — verified: opcode 63h is MOVSXD in 64-bit mode; ARPL only exists in 32-bit mode -- [N/A] LAR (load access rights) — segment descriptor queries; full descriptor model not implemented -- [N/A] LSL (load segment limit) — segment descriptor queries; full descriptor model not implemented -- [N/A] VERR, VERW (verify segment for read/write) — segment descriptor queries; full descriptor model not implemented - -#### 1.25.2 Control Registers -- [x] MOV CRn (CR0, CR2, CR3, CR4, CR8) — previously verified -- [x] MOV DRn (DR0-DR3, DR6, DR7) — verified: 0F 21/23, CPL=0, DR4/5 alias DR6/7 -- [x] LMSW, SMSW (load/store machine status word — CR0 low 16) — verified: LMSW CPL=0, SMSW any CPL; implemented SMSW reg/mem forms -- [x] CLTS (clear TS flag in CR0) — verified: 0F 06, CPL=0 required - -#### 1.25.3 MSR -- [x] RDMSR, WRMSR (read/write model-specific registers) — verified: special handling for EFER, FS/GS/KERNEL_GS_BASE - -#### 1.25.4 Cache/Memory Management -- [x] INVLPG (invalidate TLB entry) — verified: 0F 01 /7 memory-only, CPL=0 -- [N/A] INVPCID (invalidate process-context identifier) — TLB is not modeled (no caching) -- [x] WBINVD (write-back and invalidate cache) — verified: NOP with CPL=0 check; WBNOINVD not implemented (hint variant) -- [x] CLFLUSH, CLFLUSHOPT, CLWB (cache-line flush/writeback) — NOP in sequential model (0F AE /7 mem) -- [N/A] CLDEMOTE (cache-line demote) — cache hint, NOP in sequential model -- [x] PREFETCHH (prefetch to cache hierarchy) — NOP (0F 18 range, multi-byte NOP) -- [x] PREFETCHW (prefetch for write, 3DNow!/AMD) — NOP -- [N/A] PREFETCHWT1 (prefetch with write intent to L2) — cache hint, NOP in sequential model -- [x] LFENCE, SFENCE, MFENCE (memory fences) — verified: NOP in sequential model (0F AE /5,/6,/7 mod=11) -- [x] MOVNTI (non-temporal store, 32/64-bit) — verified: 0F C3 -- [x] MOVNTDQ, MOVNTPD, MOVNTPS (non-temporal SIMD stores) — verified in SSE dispatch -- [x] MOVNTQ (MMX non-temporal store) — implemented + KVM tests -- [x] MOVNTDQA (non-temporal aligned load) — verified in SSE dispatch -- [x] MOVDIR64B (64-byte direct store) — implemented (insn_baseline.sail, exec_movdir64b): ES:reg destination at the address size, 64-byte aligned linear address, source read before any destination check; KVM tests -- [x] MOVDIRI (direct store) — implemented: NP 0F 38 F9, an ordinary 32/64-bit store in the sequential model; KVM tests -- [x] SERIALIZE (execution serialization) — verified: 0F 01 E8, NOP in sequential model - -#### 1.25.5 Task/Interrupt -- [x] SWAPGS (swap GS base) — verified correct -- [x] SYSCALL, SYSRET (fast system call/return) — verified, RFLAGS mask fix applied -- [x] SYSENTER, SYSEXIT (fast system call/return, legacy) — implemented (insn_baseline.sail 0F 34/0F 35); IA-32e semantics asserted by system_test_basic -- [x] HLT (halt) — verified correct -- [x] RSM (resume from system management mode) — implemented (smm.sail); exercised by the SeaBIOS CALL32_SMM trampoline during the FreeDOS boot - -#### 1.25.6 Privilege -- [x] STI, CLI (interrupt flag) — verified: FA (CLI), FB (STI) -- [x] STAC, CLAC (alignment check in SMAP) — verified: 0F 01 CA (CLAC), 0F 01 CB (STAC) -- [x] RDPKRU, WRPKRU (protection key rights) — verified: 0F 01 EE/EF, returns 0 (no PKU) -- [N/A] RDPMC (read performance counter) — performance counters not modeled -- [N/A] RDPID (read processor ID) — delegates to TSC_AUX which is already implemented via RDTSCP - -#### 1.25.7 VMX (Virtual Machine Extensions) -- [x] All VMX instructions (VMXON/OFF, VMLAUNCH/RESUME, VMCALL, VMCLEAR/PTRLD/PTRST, VMREAD/WRITE, VMFUNC, INVEPT/INVVPID) — implemented (insn_vmx.sail, vmx.sail, vmx_vmcs.sail); hosts Linux/KVM as a nested hypervisor with EPT - -#### 1.25.8 SMX (Safer Mode Extensions) -- [N/A] SENTER, SEXIT (measured launch) — SMX not targeted - -#### 1.25.9 SGX (Software Guard Extensions) -- [N/A] All SGX instructions (ENCLS, ENCLU, ENCLV) — SGX deprecated on consumer CPUs; enclave infrastructure not targeted - -#### 1.25.10 UINTR (User Interrupts) -- [N/A] SENDUIPI, UIRET, TESTUI, STUI, CLUI, WAKEUP — UINTR not targeted - -#### 1.25.11 ENQCMD -- [x] ENQCMD, ENQCMDS (enqueue command) — implemented with IA32_PASID (insn_baseline.sail, exec_enqcmd); no modeled device has an enqueue register, so the store is dropped with ZF = 1 (retry) - -#### 1.25.12 PCONFIG -- [N/A] PCONFIG (platform configuration) — TME/MKTME key management not targeted - -#### 1.25.13 WAITPKG (Timed Pause) -- [N/A] TPAUSE, UMONITOR, UMWAIT — user-mode wait extensions not targeted; PAUSE already implemented as NOP - -#### 1.25.14 HRESET -- [N/A] HRESET (history reset) — branch prediction history not modeled - -#### 1.25.15 TSX Suspend Tracking -- [N/A] XRESLDTRK, XSUSLDTRK (resume/suspend load tracking) — TSX load tracking not targeted - -#### 1.25.16 RDRAND/RDSEED -- [x] RDRAND, RDSEED (hardware random number) — implemented, delegates to host intrinsics - -#### 1.25.17 PTWRITE -- [N/A] PTWRITE (write to Processor Trace packet) — Processor Trace not modeled - -#### 1.25.18 INVD -- [N/A] INVD (invalidate cache without writeback) — cache not modeled; WBINVD already handled as NOP - -#### 1.25.19 SMCTRL -- [N/A] SMCTRL (system management control) — SMM not modeled - -#### 1.25.20 ENTERACCS, EXITAC -- [N/A] ENTERACCS, EXITAC (authenticated code module) — TXT/ACM not targeted - ---- - -## Part 2: Encoding and Decoding - -### 2.1 Legacy Prefix Handling -- [x] Operand-size override (66h) — verified + KVM tests -- [x] Address-size override (67h) — decode_rm/decode_rm_evex truncate EA to 32 bits -- [x] Segment overrides (26h/2Eh/36h/3Eh/64h/65h) — verified (FS/GS functional) -- [x] LOCK prefix (F0h) — must #UD on invalid instructions — verified -- [x] REP/REPE/REPNE (F3h/F2h) — correct interaction with string ops — verified -- [x] REP as mandatory prefix (SSE opcode disambiguation) — verified -- [x] Multiple prefix handling (last one wins for same group) — verified - -### 2.2 REX Prefix (40h-4Fh) -- [x] REX.W (64-bit operand size) — verified + KVM tests -- [x] REX.R (ModR/M reg extension) — verified + KVM tests -- [x] REX.X (SIB index extension) — verified + KVM tests -- [x] REX.B (ModR/M r/m, SIB base, opcode reg extension) — verified + KVM tests -- [x] REX access to registers R8-R15, SPL/BPL/SIL/DIL — verified + KVM tests -- [x] REX on instructions that already use 64-bit default (PUSH/POP) — verified - -### 2.3 VEX Prefix (C4h 3-byte, C5h 2-byte) -- [x] 2-byte VEX (C5h): R, vvvv, L, pp — verified + KVM tests -- [x] 3-byte VEX (C4h): R, X, B, mmmmm, W, vvvv, L, pp — verified + KVM tests -- [x] VEX.vvvv field for 3rd operand or must-be-1111b check — verified -- [x] VEX.L (128 vs 256) — verified + KVM tests -- [x] #UD when VEX used with LOCK/66h/F2h/F3h/REX — verified - -### 2.4 EVEX Prefix (62h, 4 bytes) -- [x] Full EVEX field decoding (R, X, B, R', mmm, W, vvvv, pp, z, L'L, b, V', aaa) — verified and fixed: mmm 3-bit, reserved bit checks added -- [x] EVEX to 32 SIMD registers (ZMM0-ZMM31) — verified: evex_reg_idx (R':R:reg), evex_rm_reg_idx (X:B:rm), evex_vvvvv (V':vvvv) all decode to 0-31 range -- [x] EVEX.b interpretation per instruction (broadcast vs rounding vs SAE) — verified: broadcast via broadcast_f32/f64/byte helpers; embedded rounding via evex_begin_rc/evex_end_rc for core FP arithmetic + conversions -- [x] EVEX compressed displacement (disp8*N) — verified in decode_sib_evex() -- [x] #UD for reserved EVEX field values — verified: P[3]!=0 → #UD, P[10]!=1 → #UD, mmm=0/4-7 → #UD - -### 2.5 ModR/M and SIB -- [x] All 256 ModR/M byte values decoded correctly — verified + KVM tests -- [x] SIB byte decoding (scale, index, base) — verified + KVM tests -- [x] [RIP+disp32] addressing (ModR/M=00, R/M=101 in 64-bit mode) — verified + KVM tests -- [x] SIB with no index (index=100) — verified -- [x] SIB with no base (base=101, mod=00) — verified -- [N/A] 16-bit addressing modes (with 67h in 32-bit mode) — 32-bit/16-bit compat mode not fully modeled; 64-bit mode uses 67h for 32-bit addressing only - -### 2.6 Immediate and Displacement Sizes -- [x] imm8, imm16, imm32 selection per opcode — verified + KVM tests -- [x] Sign-extension of imm8 to 16/32/64-bit — verified + KVM tests -- [x] No imm64 except MOV r64,imm64 (opcode B8+rd) — verified -- [x] disp8, disp16, disp32 per addressing mode — verified + KVM tests -- [x] EVEX compressed disp8 (disp8 * element_size * vector_length/8) — verified - -### 2.7 Default Operand/Address Sizes in 64-bit Mode -- [x] Default operand size = 32 for most instructions — verified + KVM tests -- [x] Default operand size = 64 for PUSH, POP, CALL, RET, JMP near — verified, d64/f64 fixes applied -- [x] No 32-bit address/operand for stack operations in 64-bit mode — verified -- [x] 16-bit operand override (66h) still valid in 64-bit mode — verified + KVM tests -- [x] 32-bit address override (67h) in 64-bit mode — EA truncation implemented -- [x] Instructions with forced 64-bit operand (MOV CRn, SWAPGS, etc.) — verified - ---- - -## Part 3: Architectural State and Registers - -### 3.1 General-Purpose Registers -- [x] RAX-RSP, RBP, RSI, RDI (64-bit), EAX-EDI (32-bit), AX-DI (16-bit), AL-DIL (8-bit) — verified + KVM tests -- [x] R8-R15 (64/32/16/8-bit forms: R8D, R8W, R8B) — verified + KVM tests -- [x] SPL, BPL, SIL, DIL (accessible only with REX prefix) — verified + KVM tests -- [x] AH, BH, CH, DH (NOT accessible when REX prefix present) — verified -- [x] 32-bit writes zero-extend to 64-bit — verified + KVM tests -- [x] 8-bit and 16-bit writes do NOT zero-extend — verified + KVM tests - -### 3.2 RFLAGS -- [x] CF (bit 0), PF (bit 2), AF (bit 4), ZF (bit 6), SF (bit 7), OF (bit 11) — verified + KVM tests -- [x] DF (bit 10), IF (bit 9), TF (bit 8) — verified -- [x] IOPL (bits 13:12) — verified, POPF bug fixed -- [x] NT (bit 14), RF (bit 16), VM (bit 17) — verified -- [x] AC (bit 18), VIF (bit 19), VIP (bit 20), ID (bit 21) — verified, IRET bug fixed -- [x] PF set based on low 8 bits of result (even parity) — verified + KVM tests -- [x] AF set on carry out of bit 3 — verified + KVM tests -- [x] Correct "undefined" flag behavior (per SDM per instruction) — verified - -### 3.3 Instruction Pointer -- [x] RIP (64-bit), EIP (32-bit in compat mode) — verified: `register RIP : qword` in regs.sail:7 -- [x] RIP-relative addressing in 64-bit mode — verified: decode_rm() handles mod=00/rm=101 as RIP+disp32; rip_rel_pending fixup mechanism - -### 3.4 Segment Registers -- [x] CS, DS, ES, SS, FS, GS — verified: SegReg vector(6, word) in regs.sail:181, indices defined in core_types.sail -- [x] In 64-bit mode: DS/ES/SS bases forced to 0 — verified: apply_segment() only adds base for FS/GS -- [x] FS.base, GS.base (from MSRs, WRFSBASE/WRGSBASE) — implemented -- [N/A] CS selects code segment attributes (L/D bits for 64/compat mode) — mode tracked via cur_mode register; CS descriptor L/D bits not explicitly modeled (always 64-bit mode) - -### 3.5 x87 FPU Registers -- [x] ST(0)-ST(7) (80-bit extended precision) — verified: x87_ST vector, TOP-relative addressing -- [x] FPU control word (precision, rounding, exception masks) — verified: x87_cw, default 0x037F -- [x] FPU status word (TOP, condition codes C0-C3, exception flags) — verified: x87_sw, TOP at bits 13:11 -- [x] FPU tag word (valid/zero/special/empty per register) — verified: x87_tw, 2-bit tags -- [N/A] Last instruction/operand pointers — x87 FIP/FDP not modeled (no x87 exception delivery) - -### 3.6 MMX Registers -- [x] MM0-MM7 (alias to low 64 bits of ST(0)-ST(7)) — fully modeled via x87 physical registers with proper tag/TOP management - -### 3.7 SSE/AVX Registers -- [x] XMM0-XMM15 (128-bit, base SSE) — verified: ZMM vector(32, zmmword), read_xmm/write_xmm access low 128 bits -- [x] YMM0-YMM15 (256-bit, AVX) — verified: read_ymm/write_ymm access low 256 bits -- [x] XMM16-XMM31, YMM16-YMM31, ZMM0-ZMM31 (512-bit, AVX-512) — verified: simd_idx = range(0,31), all 32 registers -- [x] MXCSR (SSE control/status register) — verified: delegated to C++ externals (__ldmxcsr/__stmxcsr), rounding/FTZ/DAZ handled by host FPU - -### 3.8 Opmask Registers -- [x] k0-k7 (64-bit each in AVX-512) — verified: KREG vector(8, qword) in regs.sail:169 -- [x] k0 = always-all-ones (cannot be used as writemask) — verified: documented in regs.sail:163 comment - -### 3.9 AMX Tile Registers -- [N/A] TMM0-TMM7, TILECFG — AMX not targeted (see 1.18) - -### 3.10 Control Registers -- [x] CR0 (PE, MP, EM, TS, ET, NE, WP, AM, NW, CD, PG) — verified: all bit positions defined in regs.sail:292-303 -- [x] CR2 (page-fault linear address) — verified: register CR2 : qword, set by page fault handler -- [x] CR3 (page-directory base, PCID) — verified: register CR3 : qword, used in pt_walk for paging -- [x] CR4 (VME, PVI, TSD, DE, PSE, PAE, MCE, PGE, PCE, OSFXSR, OSXMMEXCPT, - LA57, FSGSBASE, PCIDE, OSXSAVE) — verified: bit positions defined in regs.sail:305-320; SMEP/SMAP/PKE/CET/PKS not yet modeled -- [N/A] CR8 (TPR, 64-bit mode only) — APIC task priority register not modeled -- [x] XCR0 (XSAVE feature enable) — verified: XGETBV returns 0xE7 for XCR0 - -### 3.11 Debug Registers -- [x] DR0-DR3 (breakpoint addresses) — verified: registers declared in regs.sail:285-288 -- [x] DR6 (debug status) — verified: register DR6 : qword in regs.sail:289 -- [x] DR7 (debug control) — verified: register DR7 : qword in regs.sail:290 - -### 3.12 Descriptor Table Registers -- [x] GDTR (base + limit) — verified: GDTR_base : qword, GDTR_limit : word in regs.sail:332-333 -- [x] IDTR (base + limit) — verified: IDTR_base : qword, IDTR_limit : word in regs.sail:334-335 -- [x] LDTR (selector + hidden base/limit/attributes) — verified: LDTR : word in regs.sail:336 (selector only, no hidden cache) -- [x] TR (selector + hidden base/limit/attributes) — verified: TR : word, TR_base : qword, TR_limit : dword in regs.sail:337-341 - -### 3.13 MSRs (Commonly Used) -- [x] IA32_EFER (SCE, LME, LMA, NXE) — verified: native Sail register, bit positions in regs.sail:322-326 -- [x] IA32_STAR, IA32_LSTAR, IA32_FMASK (SYSCALL/SYSRET) — verified: read via __rdmsr(0xC0000081/82/84) -- [N/A] IA32_CSTAR (compat mode SYSCALL) — compat mode not targeted -- [x] IA32_FS_BASE, IA32_GS_BASE, IA32_KERNEL_GS_BASE — verified: native Sail registers in regs.sail:191-193 -- [N/A] IA32_SYSENTER_CS/ESP/EIP — SYSENTER/SYSEXIT not targeted (see 1.25.5) -- [x] IA32_TSC, IA32_TSC_AUX — verified: TSC via __rdtsc(), TSC_AUX via __rdmsr(0xC0000103) -- [N/A] IA32_PAT (page attribute table) — memory types not modeled in sequential model -- [N/A] IA32_APIC_BASE — APIC MMIO not modeled (system emulator uses legacy PIC) -- [N/A] IA32_MISC_ENABLE — miscellaneous feature enable bits not modeled -- [N/A] IA32_XSS — supervisor XSAVE state components not modeled - ---- - -## Part 4: Memory and Addressing - -### 4.1 Addressing Modes (64-bit) -- [x] Register direct — verified in insn_modrm.sail:258-260 (modbits=11) -- [x] [reg] (all 16 GPRs as base) — verified, REX.B extends to 16 GPRs -- [x] [reg + disp8/disp32] — verified (mod=01 disp8, mod=10 disp32) -- [x] [RIP + disp32] (RIP-relative) — verified, with 67h truncation to 32-bit -- [x] [base + index*scale] (scale = 1/2/4/8) — verified in decode_sib() -- [x] [base + index*scale + disp8/disp32] — verified -- [x] [disp32] (absolute, only via SIB; zero-extended to 64-bit) — verified (SIB base=5, mod=00) -- [x] [index*scale + disp32] (no base, via SIB) — verified -- [x] RSP/R12 as base forces SIB byte — verified (r/m=100 routes to SIB decode) -- [x] RBP/R13 with mod=00 means [disp32] (no base) — verified in decode_sib() and decode_rm() - -### 4.2 Segmentation -- [N/A] Segment descriptor loading and caching — flat model assumed; FS/GS base set via MSRs -- [x] Flat model (DS/ES/SS base = 0 in 64-bit long mode) — verified in apply_segment(): only FS/GS add base -- [x] FS/GS non-zero base in 64-bit mode — verified, FS_BASE/GS_BASE added in apply_segment() -- [N/A] Segment limit checking (in compat/legacy mode) — compat/legacy mode not targeted -- [N/A] Code segment (conforming vs non-conforming) — full segment descriptor model not implemented; 64-bit flat mode assumed -- [N/A] Stack segment (SS.DPL = CPL) — SS descriptor not explicitly modeled; CPL tracked via cur_cpl register - -### 4.3 Paging -- [x] 4-level paging (PML4 → PDPT → PD → PT) — verified: pt_walk with level 3→0 recursion -- [N/A] 5-level paging (PML5, when CR4.LA57 = 1) — 5-level paging not targeted; 4-level paging sufficient for Linux boot -- [x] 4KB pages — verified: level 0 leaf, offset[11:0] -- [x] 2MB large pages (PS bit in PDE) — verified: level 1 leaf with PS=1, offset[20:0] -- [x] 1GB huge pages (PS bit in PDPTE) — verified: level 2 leaf with PS=1, offset[29:0] -- [x] Page table entry format (P, R/W, U/S, PWT, PCD, A, D, PS, G, NX) — verified: P, R/W, U/S, A, D, PS, NX checked -- [x] CR3 (page-directory base register) — verified: used in translate_addr, masked to PPN -- [N/A] PCID (process-context identifiers, CR4.PCIDE) — TLB not modeled; no caching -- [x] NX (no-execute) bit support (IA32_EFER.NXE) — verified: XD bit[63] checked when EFER.NXE=1 -- [N/A] SMEP (CR4.SMEP — supervisor can't execute user pages) — access control checks not fully modeled; Linux boots with noapic/nolapic -- [N/A] SMAP (CR4.SMAP — supervisor can't access user pages unless AC=1) — STAC/CLAC implemented but SMAP check not enforced in page walk -- [N/A] PKU (protection keys for user pages) — RDPKRU/WRPKRU return 0; PKU enforcement not modeled -- [N/A] PKS (protection keys for supervisor pages) — not modeled -- [N/A] PAT (page attribute table — memory type per page) — memory types not modeled in sequential model - -### 4.4 Memory Types and Ordering -- [N/A] All memory types (UC, WC, WT, WB, WP) and MTRR/PAT interaction — sequential model has no memory hierarchy; all accesses are immediately visible -- [N/A] Memory ordering guarantees (strong ordering, store-buffer forwarding, LOCK barriers, fence semantics) — sequential model is inherently sequentially consistent; no reordering possible - -### 4.5 Alignment -- [N/A] #AC for misaligned access at CPL=3 when CR0.AM=1 and RFLAGS.AC=1 — alignment check exception not modeled -- [N/A] #GP for misaligned LOCK'd instructions — split-lock detection not modeled -- [x] SSE: #GP for misaligned MOVAPS/MOVAPD/MOVDQA (128-bit aligned) — verified: alignment check in insn_sse_fp.sail and insn_vex_fp.sail -- [N/A] AVX-512: VMOVDQA32/64 require alignment, VMOVDQU do not — alignment checks for EVEX memory ops delegated to C++ externals -- [N/A] FXSAVE/FXRSTOR require 16-byte alignment — delegated to C++ __fxsave/__fxrstor externals -- [N/A] XSAVE requires 64-byte alignment — delegated to C++ __xsave/__xrstor externals - ---- - -## Part 5: Exceptions and Interrupts - -### 5.1 Exception Vectors -- [x] #DE (0) — divide error (DIV/IDIV) — verified: raised by DIV/IDIV, tested in system emulator -- [N/A] #DB (1) — debug exception; hardware breakpoint/single-step not modeled -- [x] NMI (2) — non-maskable interrupt — delivered through IDT like other interrupts -- [x] #BP (3) — breakpoint (INT3) — verified: INT3 delivers as software trap, tested -- [x] #OF (4) — overflow (INTO) — verified: INTO raises #UD in 64-bit mode (correct) -- [x] #BR (5) — bound range exceeded (BOUND) — verified: BOUND raises #UD in 64-bit mode (correct) -- [x] #UD (6) — invalid opcode — verified: raised throughout for invalid encodings -- [x] #NM (7) — device not available: CR0.EM/TS/MP for x87, MMX, SSE, AVX, AVX-512, the XSAVE family, FXSAVE/FXRSTOR, LDMXCSR/STMXCSR, EMMS and WAIT (exceptions.sail check_cr0_*); KVM template kvm-tests-cr0.cpp -- [x] #DF (8) — double fault — verified: escalation logic in deliver_exception(), tested -- [N/A] #TS (10) — invalid TSS; TSS validation not fully modeled -- [x] #NP (11) — segment not present — verified: raised in deliver_exception_inner for not-present gate -- [N/A] #SS (12) — stack-segment fault; stack segment limits not enforced in 64-bit mode (canonical check covers this) -- [x] #GP (13) — general protection — verified: raised for privilege violations, bad MSR, etc. with error code -- [x] #PF (14) — page fault (error code: P, W/R, U/S, RSVD, I/D) — verified in paging.sail, tested -- [N/A] #MF (16) — x87 FPU floating-point error; x87 exceptions always masked, no #MF delivery -- [N/A] #AC (17) — alignment check; not modeled (see 4.5) -- [x] #MC (18) — machine check — used as triple fault signal -- [N/A] #XM (19) — SIMD floating-point exception; SSE exceptions always masked, no #XM delivery -- [N/A] #VE (20) — virtualization exception; VMX/EPT not modeled -- [N/A] #CP (21) — control protection exception; CET not modeled -- [N/A] #HV (28) — hypervisor injection; SEV-ES not modeled -- [N/A] #VC (29) — VMM communication; SEV-ES not modeled -- [N/A] #SX (30) — security exception; not modeled - -### 5.2 Interrupt Delivery -- [x] IDT lookup (vector × 16 in 64-bit mode) — verified in read_idt_gate(), tested -- [x] Interrupt gate vs trap gate (IF clearing) — verified: type 0xE clears IF, 0xF preserves; tested -- [x] IST (Interrupt Stack Table) mechanism — verified in deliver_exception_inner(), read_tss_ist() -- [x] Error code pushing (which exceptions push error codes) — verified; fixed: software ints skip error code (SDM §6.13) -- [x] RSP alignment to 16 on interrupt stack frame — verified: `new_rsp & 0xFFF...F0`; tested -- [x] CPL change: stack switch via TSS — verified: reads RSP0 from TSS on privilege change -- [x] Same-privilege interrupt: no stack switch — verified: uses current RSP when old_cpl==0 and IST==0 - -### 5.3 Exception Conditions Per Instruction -- [x] Each instruction must raise exactly the exceptions listed in SDM — verified for #UD, #GP, #PF, #DE, #NM; #XM/#AC/#SS not modeled (see above) -- [x] #UD for invalid opcode in current mode (e.g., ARPL in 64-bit) — verified: ARPL, INTO, BOUND, PUSHA/POPA all #UD -- [x] #GP for privilege violations — verified: LGDT/LIDT/LMSW/INVLPG/RDMSR/WRMSR check CPL=0 -- [N/A] #SS for stack-segment violations — stack segment limits not enforced in 64-bit mode -- [x] #PF for page faults with correct error code — verified: P, W/R, U/S, RSVD, I/D bits in error code -- [x] #NM when CR0.EM=1 or CR0.TS=1 for x87/SSE/AVX — after every #UD the encoding decides (but for x87 and the FXSAVE/FXRSTOR opcode), before memory faults; EM=1 is #UD for MMX/legacy SSE -- [N/A] #XM or #UD based on CR4.OSXMMEXCPT for SSE exceptions — SSE exceptions always masked - ---- - -## Part 6: Processor Modes and Transitions - -### 6.1 Long Mode (64-bit) -- [x] Enabling: CR0.PG=1, CR4.PAE=1, IA32_EFER.LME=1 — system emulator boots through this sequence; cur_mode tracks 64-bit/32-bit/16-bit -- [x] 64-bit sub-mode (CS.L=1, CS.D=0) — primary operating mode, fully modeled -- [x] Compatibility sub-mode (CS.L=0; 32-bit code in long mode) — implemented; runs IA32 userspace (hello32) under the booted kernel and the KVM harness's compat-mode differential tests -- [x] Default operand/address sizes per mode — verified: d64/f64 rules for PUSH/POP/CALL/RET, 66h/67h overrides - -### 6.2 Protected Mode (Legacy 32-bit) -- [N/A] Full GDT/LDT/IDT operation — GDT/IDT base/limit loaded via LGDT/LIDT; full descriptor parsing only for TSS (LTR) and IDT gates -- [x] Privilege levels (CPL, RPL, DPL) — CPL tracked via cur_cpl register; used for privilege checks (LGDT, RDMSR, etc.) and stack switching on interrupts -- [x] Gate descriptors (interrupt gates, trap gates) — IDT gate parsing in deliver_exception_inner(); call gates and task gates not modeled - -### 6.3 Real Mode -- [x] Real mode (segment:offset, IVT, no privilege checking) — implemented; SeaBIOS executes from the reset vector and FreeDOS runs to an interactive prompt - -### 6.4 Mode Transitions -- [x] Real → Protected (set CR0.PE) — implemented; SeaBIOS boots through this transition (and unreal mode relies on the cached descriptors across it) -- [x] Protected → Long (set CR4.PAE, IA32_EFER.LME, then CR0.PG) — system emulator boots through this sequence -- [N/A] Long → Protected (clear CR0.PG, then clear IA32_EFER.LME) — not targeted -- [N/A] Far JMP/CALL to change CS.L (64-bit ↔ compat) — compat mode not targeted - -### 6.5 System Management Mode (SMM) -- [x] RSM instruction and SMRAM save state — implemented (smm.sail per SDM ch. 34, incl. SMBASE relocation and auto-HALT restart); exercised by the SeaBIOS CALL32_SMM FreeDOS boot - ---- - -## Part 7: Floating-Point Semantics (Cross-Cutting) - -### 7.1 IEEE 754 Compliance -- [x] Rounding modes: round-nearest-even, round-down, round-up, round-toward-zero — verified + KVM FP Edge tests (622+ tests) -- [x] Denormal (subnormal) number handling — verified + KVM FP Edge tests (DAZ/FTZ category) -- [x] NaN propagation rules (Intel: src1 priority for SSE MIN/MAX) — verified: f32_nan_prop/f64_nan_prop in C emulator, KVM tests -- [x] Signaling NaN vs quiet NaN behavior — verified + KVM FP Edge tests (NaN category) -- [x] Infinity arithmetic (+∞, -∞) — verified + KVM FP Edge tests (Inf category) -- [x] Signed zero (+0, -0) semantics — verified + KVM FP Edge tests (signed zeros category) -- [x] Flush-to-zero (MXCSR.FTZ) — verified + KVM FP Edge tests -- [x] Denormals-are-zeros (MXCSR.DAZ) — verified + KVM FP Edge tests - -### 7.2 FP Exception Reporting -- [N/A] FP exception flag reporting (IE, DE, ZE, OE, UE, PE) — all FP exceptions are always masked; exception flags set by host FPU via C++ externals but not explicitly checked by Sail model -- [N/A] Masked vs unmasked exception behavior — unmasked FP exceptions (#MF/#XM delivery) not modeled; all exceptions masked - -### 7.3 x87 vs SSE FP Differences -- [x] x87 uses 80-bit internal precision — verified: x87_ST stores 80-bit extended precision values -- [x] SSE uses operand precision (32 or 64-bit) — verified: SSE ops use f32/f64 via C++ externals -- [N/A] x87 exception via #MF, SSE via #XM (or #UD) — exception delivery not implemented; all FP exceptions always masked -- [x] x87 condition codes (C0-C3) vs SSE EFLAGS setting — verified: FCOM sets C0/C2/C3 in SW, COMISS sets EFLAGS - ---- - -## Part 8: Concurrency and Atomicity (Cross-Cutting) - -### 8.1 LOCK Prefix -- [x] Valid only with: ADD, ADC, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B/16B, - DEC, INC, NEG, NOT, OR, SBB, SUB, XOR, XADD, XCHG — verified: is_lockable_1byte/2byte -- [x] #UD on LOCK with any other instruction — verified: checked at dispatch entry -- [x] LOCK'd operations are atomic and act as full memory barriers — sequential model (implicit) -- [x] XCHG implicitly LOCK'd when memory operand — verified - -### 8.2 Alignment and Atomicity -- [N/A] Atomicity guarantees (naturally-aligned loads/stores, CMPXCHG16B alignment, split-lock detection) — sequential model has no concurrency; all operations are inherently atomic - ---- - -## Part 9: Instruction-Specific Behavioral Details - -These are tricky behaviors a formal spec MUST get right. - -### 9.1 Shift/Rotate Count Masking -- [x] 32-bit ops: count masked to 5 bits (& 0x1F) — verified in shift.sail -- [x] 64-bit ops: count masked to 6 bits (& 0x3F) — verified in shift.sail -- [x] OF defined only for count=1 shifts — verified -- [x] Count=0 shifts: no flags modified — verified - -### 9.2 REP String Operations -- [x] RCX=0 → no operation, no flags changed — verified in string.sail -- [x] REPE/REPNE with CMPS/SCAS: early termination on ZF mismatch — verified -- [N/A] Interruptibility between iterations — sequential model processes string ops atomically; interrupt interleaving not modeled -- [x] Address size determines whether CX/ECX/RCX is used — verified - -### 9.3 PUSH/POP RSP -- [x] PUSH RSP pushes the value of RSP before the push — verified + KVM tests -- [x] POP RSP: value popped is the new RSP (not incremented after) — verified - -### 9.4 MOV to SS -- [N/A] Inhibits interrupts for one instruction after MOV to SS — interrupt inhibition not modeled (sequential model delivers interrupts at instruction boundary only) - -### 9.5 Division -- [x] DIV: #DE if quotient overflows or divisor=0 — verified + KVM tests -- [x] IDIV: #DE if quotient overflows or divisor=0 — verified + KVM tests -- [x] 8-bit DIV: AX / src → AL quotient, AH remainder — verified -- [x] 16-bit DIV: DX:AX / src → AX quotient, DX remainder — verified -- [x] etc. for 32/64-bit — verified - -### 9.6 IMUL Forms -- [x] 1-operand: signed widening multiply (same as MUL but signed) — verified + KVM tests -- [x] 2-operand: dst = dst × src (truncated, OF/CF set if sign-extended result ≠ full result) — verified -- [x] 3-operand: dst = src × imm (truncated, same OF/CF rule) — verified - -### 9.7 BSF/BSR vs TZCNT/LZCNT -- [x] BSF/BSR: ZF=1 if source is 0, destination UNDEFINED — verified + KVM tests -- [x] TZCNT/LZCNT: CF=1 if source is 0, result = operand bit size — verified + KVM tests -- [x] On CPUs without BMI, TZCNT executes as BSF (F3 prefix ignored) — N/A (we always have BMI) -- [x] LZCNT without ABM: executes as BSR — N/A (we always have ABM) - -### 9.8 CPUID -- [x] Leaf 0: max basic leaf, vendor string — delegated to __cpuid external -- [x] Leaf 1: family/model/stepping, feature flags (ECX, EDX) — delegated to __cpuid external -- [x] Leaf 7: extended feature flags (structured) — delegated to __cpuid external -- [x] Leaf 0x80000000-0x80000008: extended leaves — delegated to __cpuid external -- [x] Must report feature bits consistent with implemented instructions — host passthrough via __cpuid -- [x] Invalid/unsupported leaves: return 0 or last valid leaf's data — handled by host CPUID - -### 9.9 NOP Width -- [x] 1-byte NOP (0x90 = XCHG EAX,EAX) — verified: special-cased in dispatch, does not zero-extend -- [x] Multi-byte NOP (0F 1F /0, various lengths up to 9 bytes) — verified: consumes ModR/M + SIB + disp -- [x] In 64-bit mode, 0x90 is NOP (not XCHG EAX,EAX which would zero-extend) — verified correct - -### 9.10 VEX/EVEX Upper-Bits Clearing -- [x] VEX-128: zero bits 255:128 of YMM — verified: write_xmm zeroes upper -- [x] VEX-256: zero bits 511:256 of ZMM (if AVX-512 supported) — verified: write_ymm zeroes 511:256 -- [x] EVEX-128: zero bits 511:128 — verified: write_xmm() initializes 512-bit reg to zeros, writes low 128 -- [x] EVEX-256: zero bits 511:256 — verified: write_ymm() initializes 512-bit reg to zeros, writes low 256 -- [x] Legacy SSE: upper bits of YMM/ZMM are PRESERVED (no zeroing) — verified: write_xmm_legacy preserves -- [x] SSE↔AVX transition penalty implications (VZEROUPPER) — verified: VZEROUPPER/VZEROALL implemented - ---- - -## Part 10: Summary Statistics - -- **Total unique mnemonics in SDM:** 1,208 -- **SDM instruction pages:** 835 (some cover multiple related mnemonics) -- **ISA extension groups:** ~30+ (from base x86-64 through AMX) - -### Rough instruction count by category: -| Category | Approx. count | -|---|---| -| General-purpose integer | ~120 | -| x87 floating-point | ~90 | -| MMX | ~50 (implemented) | -| SSE (1/2/3/SSSE3/4.1/4.2) | ~200 | -| AVX/AVX2 (VEX re-encoding of above) | (same ops, VEX form) | -| FMA | ~96 forms (4 ops × 3 orderings × 2 types × 2 sizes + packed variants) | -| AVX-512 (F/BW/DQ/CD/VL/VBMI/IFMA/VNNI/BITALG/VP2INTERSECT/etc.) | ~350+ | -| AVX-512 FP16 | ~80 (all implemented) | -| BMI1/BMI2/ADX | ~16 | -| AES-NI/SHA/GFNI/PCLMULQDQ | ~18 | -| Key Locker | ~10 | -| CET (shadow stack + IBT) | ~12 | -| AMX | ~8 | -| System (VMX/SGX/SMX/descriptors/CR/DR/MSR) | ~60 | -| TSX/XSAVE/misc | ~20 | - ---- - -## How to Use This Checklist - -For each `[ ]` item: -1. Search the Sail codebase for the instruction mnemonic or opcode -2. Verify it decodes the correct opcode bytes per SDM -3. Verify it handles all valid operand-size and addressing-mode variants -4. Verify flag effects match SDM exactly -5. Verify exception conditions match SDM (#UD in wrong mode, #GP for privilege, etc.) -6. Mark as one of: - - `[x]` Implemented and correct - - `[~]` Partially implemented (note what's missing) - - `[ ]` Not implemented - - `[N/A]` Explicitly out of scope (document why) diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail deleted file mode 100644 index fa280a44e..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/branchless.sail +++ /dev/null @@ -1,415 +0,0 @@ -// x86-64 — Branchless bit-manipulation helpers -// -// Pure utility functions used across multiple instruction files. -// All are branch-free to support formal verification tools (Isla/SMT). - -// Branchless POPCNT -val popcount : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n) -function popcount(v) = { - let x : qword = zero_extend(v); - let x = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555); - let x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); - let x = (x & 0x0f0f0f0f0f0f0f0f) + ((x >> 4) & 0x0f0f0f0f0f0f0f0f); - let x = (x & 0x00ff00ff00ff00ff) + ((x >> 8) & 0x00ff00ff00ff00ff); - let x = (x & 0x0000ffff0000ffff) + ((x >> 16) & 0x0000ffff0000ffff); - let x = (x & 0x00000000ffffffff) + ((x >> 32) & 0x00000000ffffffff); - let x = unsigned(x); - assert(x <= 'n); - x -} - -// or_reduce: 1 if any bit is set, 0 otherwise (branchless tree reduction). -val or_reduce : forall 'n, 0 < 'n & 'n <= 512. bits('n) -> bits(1) -function or_reduce(v) = { - let x : zmmword = zero_extend(v); - let x = x | (x >> 1); - let x = x | (x >> 2); - let x = x | (x >> 4); - let x = x | (x >> 8); - let x = x | (x >> 16); - let x = x | (x >> 32); - let x = x | (x >> 64); - let x = x | (x >> 128); - let x = x | (x >> 256); - x[0] -} - -// is_nonzero: 0 if all bits are zero, 1 otherwise. -val is_nonzero : forall 'n, 0 < 'n & 'n <= 512. bits('n) -> bit -function is_nonzero(v) = or_reduce(v)[0] - -// is_zero: 1 if all bits are zero, 0 otherwise. -val is_zero : forall 'n, 0 < 'n & 'n <= 512. bits('n) -> bit -function is_zero(v) = ~(is_nonzero(v)) - -// is_eq: 1 if a == b, 0 otherwise. -val is_eq : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit -function is_eq(a, b) = is_zero(a ^ b) - -// is_gt: 1 if a > b (signed), 0 otherwise. -val is_gt : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit -function is_gt(a, b) = { - let diff : bits('n + 1) = sign_extend(b) - sign_extend(a); - diff['n] -} - -// is_gt_u: 1 if a > b (unsigned), 0 otherwise. -val is_gt_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit -function is_gt_u(a, b) = { - let diff : bits('n + 1) = zero_extend(b) - zero_extend(a); - diff['n] -} - -// is_ne: 1 if a != b, 0 otherwise. -val is_ne : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit -function is_ne(a, b) = is_nonzero(a ^ b) - -// is_lt_u: 1 if a < b (unsigned), 0 otherwise. -val is_lt_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit -function is_lt_u(a, b) = is_gt_u(b, a) - -// is_ge_u: 1 if a >= b (unsigned), 0 otherwise. -val is_ge_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit -function is_ge_u(a, b) = ~(is_gt_u(b, a)) - -// is_le_u: 1 if a <= b (unsigned), 0 otherwise. -val is_le_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bit -function is_le_u(a, b) = ~(is_gt_u(a, b)) - -// Rotate left/right by a bounded integer amount. -val rotl : forall 'm 'n, 'm >= 'n >= 0. (bits('m), int('n)) -> bits('m) -function rotl(v, shift) = (v << shift) | (v >> ('m - shift)) - -val rotr : forall 'm 'n, 'm >= 'n >= 0. (bits('m), int('n)) -> bits('m) -function rotr(v, shift) = (v >> shift) | (v << ('m - shift)) - -// Branchless blend: select a or b per element based on a single bit. -// sel=0 -> a, sel=1 -> b. -val blend : forall 'n, 0 < 'n. (bits('n), bits('n), bit) -> bits('n) -function blend(a, b, sel) = { - let m : bits('n) = sign_extend(sel); - (a & ~(m)) | (b & m) -} - -// ========================================================================= -// Comparison helpers (return full-width masks) -// ========================================================================= - -// All-ones if a == b, all-zeros otherwise. -val cmp_eq : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function cmp_eq(a, b) = sign_extend(is_eq(a, b)) - -// All-ones if a > b (signed), all-zeros otherwise. -val cmp_gt : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function cmp_gt(a, b) = sign_extend(is_gt(a, b)) - -// ========================================================================= -// Min/max -// ========================================================================= - -// PSIGN: negate if b < 0, zero if b == 0, keep if b > 0. -val psign : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function psign(a, b) = { - let neg_mask : bits('n) = sign_extend(b['n - 1]); - ((a ^ neg_mask) - neg_mask) & sign_extend(is_nonzero(b)) -} - -val max_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function max_s(a, b) = blend(a, b, is_gt(b, a)) - -val min_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function min_s(a, b) = blend(a, b, is_gt(a, b)) - -val max_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function max_u(a, b) = blend(a, b, is_gt_u(b, a)) - -val min_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function min_u(a, b) = blend(a, b, is_gt_u(a, b)) - -// ========================================================================= -// Bit-scan / count helpers -// ========================================================================= - -// Branchless CLZ via smear (fill all bits below MSB) then popcount. -val clz : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n) -function clz(v) = { - let x1 : bits('n) = v | (v >> 1); - let x2 : bits('n) = x1 | (x1 >> 2); - let x3 : bits('n) = x2 | (x2 >> 4); - let x4 : bits('n) = x3 | (x3 >> 8); - let x5 : bits('n) = x4 | (x4 >> 16); - let x6 : bits('n) = x5 | (x5 >> 32); - 'n - popcount(x6) -} - -// Branchless CTZ via popcount: ctz(v) = popcount(~v & (v - 1)) -val ctz : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n) -function ctz(v) = popcount(~(v) & (v - 1)) - -// BSR (bit scan reverse): index of highest set bit = width - 1 - clz(v). -// Precondition: v != 0 (BSR is undefined for zero). -val bsr : forall 'n, 0 < 'n & 'n <= 64. bits('n) -> range(0, 'n - 1) -function bsr(v) = { - let x = clz(v); - assert(x < 'n); - 'n - 1 - x -} - -// ========================================================================= -// Byte manipulation -// ========================================================================= - -// BSWAP — Reverse byte order of a bitvector. -val bswap : forall 'n, 'n in {16, 32, 64}. bits('n) -> bits('n) -function bswap(v) = { - match 'n { - 16 => v[7..0] @ v[15..8], - 32 => v[7..0] @ v[15..8] @ v[23..16] @ v[31..24], - 64 => v[7..0] @ v[15..8] @ v[23..16] @ v[31..24] @ v[39..32] @ v[47..40] @ v[55..48] @ v[63..56] - } -} - -// ========================================================================= -// Absolute value, saturation arithmetic, and rounding average -// ========================================================================= - -// Branchless absolute value: mask = sign-extend of MSB; (x ^ mask) - mask -val abs : forall 'n, 'n > 0. bits('n) -> bits('n) -function abs(x) = { - let m : bits('n) = sign_extend(x['n - 1]); - (x ^ m) - m -} - -// Signed saturating add. -val sat_add_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function sat_add_s(a, b) = { - let wide : bits('n + 1) = sign_extend(a) + sign_extend(b); - let result : bits('n) = wide[('n - 1) .. 0]; - let overflow : bit = wide['n] ^ result['n - 1]; - let msb_only : bits('n) = zero_extend(0b1) << ('n - 1); - let clamp : bits('n) = msb_only ^ sign_extend(~(wide['n])); - blend(result, clamp, overflow) -} - -// Unsigned saturating add. -val sat_add_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function sat_add_u(a, b) = { - let wide : bits('n + 1) = zero_extend(a) + zero_extend(b); - wide[('n - 1) .. 0] | sign_extend(wide['n]) -} - -val sat_sub_s : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function sat_sub_s(a, b) = { - let wide : bits('n + 1) = sign_extend(a) - sign_extend(b); - let result : bits('n) = wide[('n - 1) .. 0]; - let overflow : bit = wide['n] ^ result['n - 1]; - let msb_only : bits('n) = zero_extend(0b1) << ('n - 1); - let clamp : bits('n) = msb_only ^ sign_extend(~(wide['n])); - blend(result, clamp, overflow) -} - -val sat_sub_u : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function sat_sub_u(a, b) = { - let wide : bits('n + 1) = zero_extend(a) - zero_extend(b); - wide[('n - 1) .. 0] & sign_extend(~(wide['n])) -} - -// Rounding average: (a + b + 1) >> 1 -val avg : forall 'n, 0 < 'n & 'n <= 64. (bits('n), bits('n)) -> bits('n) -function avg(a, b) = { - let sum : bits('n + 1) = zero_extend(a) + zero_extend(b) + 1; - sum['n .. 1] -} - -// Signed saturation: clamp signed x to [-(2^(dst-1)), 2^(dst-1)-1], truncate. -val sat_s : forall 'n 'dst, 0 < 'dst & 'dst < 'n & 'n <= 64. - (implicit('dst), bits('n)) -> bits('dst) -function sat_s(dst, x) = { - let hi : bits('n) = zero_extend(ones(dst - 1)); - let lo : bits('n) = ~(hi); - min_s(max_s(x, lo), hi)[('dst - 1)..0] -} - -// Signed-to-unsigned saturation: clamp signed x to [0, 2^dst-1], truncate. -val sat_su : forall 'n 'dst, 0 < 'dst & 'dst < 'n & 'n <= 64. - (implicit('dst), bits('n)) -> bits('dst) -function sat_su(dst, x) = { - let hi : bits('n) = zero_extend(ones(dst)); - let lo : bits('n) = zeros(); - min_s(max_s(x, lo), hi)[('dst - 1)..0] -} - -// Unsigned saturation: clamp unsigned x to [0, 2^dst-1], truncate. -val sat_u : forall 'n 'dst, 0 < 'dst & 'dst < 'n & 'n <= 64. - (implicit('dst), bits('n)) -> bits('dst) -function sat_u(dst, x) = { - let hi : bits('n) = zero_extend(ones(dst)); - min_u(x, hi)[('dst - 1)..0] -} - -// PSHUFB: per-byte shuffle within a 128-bit lane. -// Each result byte is selected from src by the low 4 bits of the corresponding -// ctrl byte. If ctrl byte's high bit is set, the result byte is zero. -val pshufb : (bits(128), bits(128)) -> bits(128) -function pshufb(src, ctrl) = { - var r : bits(128) = zeros(); - foreach (i from 0 to 15) { - let lo = i * 8; - let mask : byte = velem(8, ctrl, i); - let selected : byte = velem(8, src, mask[3..0]); - r[(lo + 7)..lo] = selected & sign_extend(~(mask[7])) - }; - r -} - -// PMADDUBSW per-pair: unsigned*signed byte multiply, add adjacent, saturate to word. -val pmaddubsw_pair : (byte, byte, byte, byte) -> word -function pmaddubsw_pair(a_even, b_even, a_odd, b_odd) = { - let p1 : int = unsigned(a_even) * signed(b_even); - let p2 : int = unsigned(a_odd) * signed(b_odd); - let sum : int = p1 + p2; - let wide : bits(17) = get_slice_int(17, sum, 0); - let sign : bits(1) = wide[16]; - let of_mask : word = sign_extend(sign ^ wide[15]); - let sat : word = sign_extend(sign) ^ 0x7FFF; - (sat & of_mask) | (wide[15..0] & ~(of_mask)) -} - -// Absolute difference of unsigned bytes. -val abs_diff : forall 'n, 'n > 0. (bits('n), bits('n)) -> int -function abs_diff(a, b) = { - let d1 = (0b0 @ a) - (0b0 @ b); - let d2 = (0b0 @ b) - (0b0 @ a); - let m1 : bits('n) = sign_extend(~(d1['n])); - let m2 : bits('n) = sign_extend(~(d2['n])); - unsigned((d1['n-1..0] & m1) | (d2['n-1..0] & m2)) -} - -// PSADBW: sum of absolute differences of 8 unsigned byte pairs, zero-extended to 64 bits. -val psadbw : (bits(64), bits(64)) -> bits(64) -function psadbw(a, b) = - zero_extend(get_slice_int(16, - abs_diff(a[63..56], b[63..56]) + abs_diff(a[55..48], b[55..48]) + - abs_diff(a[47..40], b[47..40]) + abs_diff(a[39..32], b[39..32]) + - abs_diff(a[31..24], b[31..24]) + abs_diff(a[23..16], b[23..16]) + - abs_diff(a[15..8], b[15..8]) + abs_diff(a[7..0], b[7..0]), 0)) - -// FP16 <-> FP32 conversion. -val fp16_to_fp32 : bits(16) -> bits(32) -function fp16_to_fp32(h) = { - let sign : bits(1) = h[15..15]; - let exp5 : bits(5) = h[14..10]; - let frac10 : bits(10) = h[9..0]; - let inf_nan : bit = is_eq(exp5, 0b11111); - let zero_exp : bit = is_eq(exp5, 0b00000); - let frac_nz : bit = is_nonzero(frac10); - let normal_body : bits(31) = (zero_extend(exp5) + 0x70) @ frac10 @ 0b0000000000000; - let lz = clz(frac10); - let denorm_body : bits(31) = - to_bits(8, 112 - lz) @ (frac10 << (lz + 1)) @ 0b0000000000000; - let infnan_body : bits(31) = 0xFF @ frac10 @ 0b0000000000000; - let body : bits(31) = blend(normal_body, denorm_body, zero_exp & frac_nz); - let body : bits(31) = blend(body, zeros(), zero_exp & ~(frac_nz)); - let body : bits(31) = blend(body, infnan_body, inf_nan); - sign @ body -} - -val fp32_to_fp16 : (bits(32), bits(2)) -> bits(16) -function fp32_to_fp16(f, rc) = { - let sign : bits(1) = f[31..31]; - let exp8 : bits(8) = f[30..23]; - let frac23 : bits(23) = f[22..0]; - let is_inf_nan : bit = is_eq(exp8, 0xFF); - let is_overflow : bit = is_gt_u(exp8, 0x8E) & ~(is_inf_nan); - // Tiny results are converted to denormals with the selected rounding - // (SDM VCVTPS2PH: "Underflow results (i.e., tiny results) are converted - // to denormals. MXCSR.FTZ is ignored."; Vol.1 §4.8.4). Values below - // 2^-25, half the smallest half-precision denormal, including zero and - // single-precision denormals, are handled through the sticky bit alone. - let input_zero : bit = is_zero(exp8) & ~(is_nonzero(frac23)); - let is_tiny : bit = is_lt_u(exp8, 0x66) & ~(input_zero); - let is_denorm_out : bit = is_lt_u(exp8, 0x71) & is_ge_u(exp8, 0x66); - let norm_top15 : bits(15) = (exp8 - 0x70)[4..0] @ frac23[22..13]; - let norm_round : bit = frac23[12]; - let norm_sticky : bit = is_nonzero(frac23[11..0]); - let shift_amt = unsigned(0x71 - exp8); - let shifted : bits(37) = ((0b1 @ frac23) @ 0b0000000000000) >> shift_amt; - let denorm_top15 : bits(15) = 0b00000 @ shifted[35..26]; - let denorm_round : bit = shifted[25]; - let denorm_sticky : bit = is_nonzero(shifted[24..0]); - let below : bit = is_tiny | input_zero; - let top15 : bits(15) = blend(blend(norm_top15, denorm_top15, is_denorm_out), zeros(), below); - let round_bit : bit = ((norm_round & ~(is_denorm_out)) | (denorm_round & is_denorm_out)) & ~(below); - let sticky_bit : bit = ((norm_sticky & ~(is_denorm_out)) | (denorm_sticky & is_denorm_out) | is_tiny) & ~(input_zero); - let rs : bit = round_bit | sticky_bit; - let rne_up : bit = round_bit & (sticky_bit | top15[0]); - let down_up : bit = sign[0] & rs; - let up_up : bit = ~(sign[0]) & rs; - let lo : bit = (rne_up & ~(rc[0])) | (down_up & rc[0]); - let hi : bit = (up_up & ~(rc[0])); - let round_up : bit = (lo & ~(rc[1])) | (hi & rc[1]); - let result15 : bits(15) = top15 + zero_extend(round_up); - // An overflow rounds to infinity, or to the largest finite value when the - // rounding direction excludes infinity: toward zero, or toward the side - // opposite the result's sign (Vol.1 §4.8.4, Table 4-9). - let saturate : bit = is_eq(rc, 0b11) | (is_eq(rc, 0b01) & ~(sign[0])) | (is_eq(rc, 0b10) & sign[0]); - let overflow15 : bits(15) = blend(0b11111 @ zeros(10), 0b11110 @ ones(10), saturate); - let body : bits(15) = blend(result15, overflow15, is_overflow); - let body : bits(15) = blend(body, 0b11111 @ frac23[22..13], is_inf_nan); - sign @ body -} - -// Multiply high with rounding and scale: ((a*b) >> (n-2) + 1) >> 1 -val mulhrs : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) -function mulhrs(a, b) = { - let prod : bits('n * 2) = to_bits_truncate(signed(a) * signed(b)); - let shifted = prod >>> ('n - 2); - let rounded : bits('n * 2) = to_bits_truncate(signed(shifted) + 1); - (rounded >>> 1)[('n - 1)..0] -} - -// ========================================================================= -// GFNI primitives (GF(2^8) with irreducible polynomial x^8+x^4+x^3+x+1) -// ========================================================================= - -val gf2p8_mul : (byte, byte) -> byte -function gf2p8_mul(a, b) = { - var result : bits(9) = zeros(); - var aa : bits(9) = zero_extend(a); - foreach (i from 0 to 7) { - result = result ^ (sign_extend(b[i..i]) & aa); - aa = aa << 1; - aa = aa ^ (sign_extend(aa[8]) & 0b100011011) // 0x11B - }; - result[7..0] -} - -val gf2p8_affine : (byte, qword, byte) -> byte -function gf2p8_affine(src, matrix, imm8) = { - var r : byte = zeros(); - foreach (i from 0 to 7) { - let row_lo : range(0, 56) = (7 - i) * 8; - let row : byte = matrix[(row_lo + 7)..row_lo]; - let product : byte = src & row; - let x4 : bits(4) = product[7..4] ^ product[3..0]; - let x2 : bits(2) = x4[3..2] ^ x4[1..0]; - let bit : bit = (x2[1] ^ x2[0])[0]; - r[i] = bit ^ imm8[i]; - }; - r -} - -val gf2p8_inv : byte -> byte -function gf2p8_inv(x) = { - let x2 = gf2p8_mul(x, x); - let x3 = gf2p8_mul(x2, x); - let x6 = gf2p8_mul(x3, x3); - let x12 = gf2p8_mul(x6, x6); - let x15 = gf2p8_mul(x12, x3); - let x30 = gf2p8_mul(x15, x15); - let x60 = gf2p8_mul(x30, x30); - let x63 = gf2p8_mul(x60, x3); - let x126 = gf2p8_mul(x63, x63); - let x252 = gf2p8_mul(x126, x126); - gf2p8_mul(x252, x2) -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail deleted file mode 100644 index 99ef5078b..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/core_types.sail +++ /dev/null @@ -1,130 +0,0 @@ -// x86-64 — Core Types - -// Operand size in bits. Used throughout the model to select register -// and memory access widths. Replaces a dedicated enum so that subset -// types like {16, 32, 64} work naturally with Sail's type system. -type operand_size = {8, 16, 32, 64} - -// Address sizes for memory operands. -type address_size = {16, 32, 64} - -// Processor operating modes. -enum ProcessorMode = { - RealMode, - ProtectedMode, - Virtual8086Mode, - CompatibilityMode, - LongMode, -} - -// Current privilege level. -type cpl_t = range(0, 3) - -// Common byte/word/dword/qword types. -type byte = bits(8) -type word = bits(16) -type dword = bits(32) -type qword = bits(64) -type fp80 = bits(80) -type xmmword = bits(128) -type ymmword = bits(256) -type zmmword = bits(512) - -// Access type for page table permission checks. -// PT_Implicit models the "implicit supervisor" accesses the CPU makes -// when reading descriptor tables (GDT/LDT/IDT/TSS) — per SDM Vol.3A §4.6 -// these bypass the U/S page-protection check regardless of the current -// CPL, so a CPL=3 `MOV GS, sel` can load a descriptor out of a kernel- -// mapped GDT without faulting. -// Implicit writes (descriptor accessed bits) also bypass U/S, but obey CR0.WP. -enum PTAccess = { PT_Read, PT_Write, PT_Execute, PT_Implicit, PT_ImplicitWrite } - -// Index into the 16 general-purpose registers (0..15). -type gpr_idx = range(0, 15) - -// GPR reference: register index + REX context (needed for 8-bit AH/SPL distinction). -struct GPRRef = { - gpr_idx : gpr_idx, - has_rex : bool, -} - -// Index into the segment register file (0..5: ES, CS, SS, DS, FS, GS). -type segreg_idx = range(0, 5) -let ES : segreg_idx = 0 -let CS : segreg_idx = 1 -let SS : segreg_idx = 2 -let DS : segreg_idx = 3 -let FS : segreg_idx = 4 -let GS : segreg_idx = 5 - -// Memory reference: segment + linear/effective address. -// Every x86 memory access is relative to a segment. -struct MemRef = { - seg : segreg_idx, - addr : qword, -} - -// Segment descriptor cache (hidden part of segment registers). -// Per SDM Vol.3A §3.4.3, each segment register has a visible part -// (16-bit selector) and a hidden part loaded from the GDT/LDT descriptor. -struct SegDescCache = { - seg_base : qword, // linear base address - seg_limit : dword, // segment limit (byte-granular after scaling) - seg_type : bits(4), // type field (code/data, R/W, accessed, etc.) - seg_s : bit, // descriptor type: 0=system, 1=code/data - seg_dpl : range(0, 3), // descriptor privilege level - seg_present : bit, // segment present - seg_db : bit, // D/B bit (default operation size) - seg_l : bit, // L bit (64-bit code segment) - seg_g : bit, // granularity (0=byte, 1=4KB) -} - -// Default segment descriptor cache for real mode: -// base=0, limit=0xFFFF, present, data R/W, DPL=0 -val default_seg_desc_cache : unit -> SegDescCache -function default_seg_desc_cache() = struct { - seg_base = 0x0000000000000000, - seg_limit = 0x0000FFFF, - seg_type = 0x3, // data, R/W, accessed - seg_s = 0b1, // code/data - seg_dpl = 0, - seg_present = 0b1, - seg_db = 0b0, // 16-bit default - seg_l = 0b0, - seg_g = 0b0, // byte granularity -} - -// Exception class for double-fault escalation (SDM Vol.3 Table 7-4). -enum ExceptionClass = { EC_Benign, EC_Contributory, EC_PageFault } - -// How an event reaches the IDT. Only an exception carries an error code -// (SDM Vol.3A Table 7-1, §7.13: the error code belongs to "an exception -// condition") and sets RF in the pushed RFLAGS image; only a software -// interrupt (INT n, INT3, INTO) is subject to the gate DPL check -// (§7.12.1.1). An external interrupt is neither, whatever its vector: -// IRQ0 at vector 8 (the 8259 default the BIOS leaves in place) is an -// interrupt, not #DF, and pushes no error code. -enum EventKind = { EV_Exception, EV_SoftwareInt, EV_ExternalInt } - -// Exception/interrupt vector numbers. -type exception_vector = range(0, 255) - -// Standard x86 exceptions. -let EXN_DE : exception_vector = 0 // Divide Error -let EXN_DB : exception_vector = 1 // Debug -let EXN_NMI : exception_vector = 2 // Non-Maskable Interrupt -let EXN_BP : exception_vector = 3 // Breakpoint -let EXN_OF : exception_vector = 4 // Overflow -let EXN_BR : exception_vector = 5 // BOUND Range Exceeded -let EXN_UD : exception_vector = 6 // Invalid Opcode -let EXN_NM : exception_vector = 7 // Device Not Available -let EXN_DF : exception_vector = 8 // Double Fault -let EXN_TS : exception_vector = 10 // Invalid TSS -let EXN_NP : exception_vector = 11 // Segment Not Present -let EXN_SS : exception_vector = 12 // Stack-Segment Fault -let EXN_GP : exception_vector = 13 // General Protection -let EXN_PF : exception_vector = 14 // Page Fault -let EXN_MF : exception_vector = 16 // x87 FPU Error -let EXN_AC : exception_vector = 17 // Alignment Check -let EXN_MC : exception_vector = 18 // Machine Check -let EXN_XM : exception_vector = 19 // SIMD Floating-Point diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail deleted file mode 100644 index f4f28e7df..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/exceptions.sail +++ /dev/null @@ -1,140 +0,0 @@ -// x86-64 — Exception Handling - -// Sail exception type for faults raised during decode/execute. -// Caught by step() and stored in fault registers. -union exception = { - Fault : (exception_vector, dword), - VMExit : (dword, qword), // (exit_reason, exit_qualification) - // An x87 stack fault with the invalid-operation exception unmasked. It - // ends the x87 instruction without delivering an exception; the #MF - // waits for the next waiting x87 instruction (dispatch_x87). - X87Unmasked : unit, -} - -// System state — tracks whether the CPU is running, halted, or handling a syscall. -enum SystemState = { SysRunning, SysHalted, SysSyscall } -register system_state : SystemState - -// Fault registers — set by step() when an exception is caught. -// The C++ harness reads these to determine the fault disposition. -register fault_pending : bool -register fault_vector : exception_vector -register fault_error_code : dword - -// Raise #GP(0) — the most common fault. -val raise_GP0 : forall ('a : Type). unit -> 'a -function raise_GP0() = { - throw Fault(EXN_GP, 0x00000000); - exit() // never reached; satisfies type checker -} - -// Raise #GP with a selector error code. -val raise_GP : forall ('a : Type). dword -> 'a -function raise_GP(sel) = { - throw Fault(EXN_GP, sel); - exit() // never reached; satisfies type checker -} - -// Raise #UD — invalid opcode. -val raise_UD : forall ('a : Type). unit -> 'a -function raise_UD() = { - throw Fault(EXN_UD, 0x00000000); - exit() // never reached; satisfies type checker -} - -// Raise #SS(0) — stack segment fault. -val raise_SS0 : forall ('a : Type). unit -> 'a -function raise_SS0() = { - throw Fault(EXN_SS, 0x00000000); - exit() // never reached; satisfies type checker -} - -// Raise #DE — divide error. -val raise_DE : forall ('a : Type). unit -> 'a -function raise_DE() = { - throw Fault(EXN_DE, 0x00000000); - exit() // never reached; satisfies type checker -} - -// Raise #BR — BOUND range exceeded. -val raise_BR : forall ('a : Type). unit -> 'a -function raise_BR() = { - throw Fault(EXN_BR, 0x00000000); - exit() // never reached; satisfies type checker -} - -// Raise #NM — device not available. -val raise_NM : forall ('a : Type). unit -> 'a -function raise_NM() = { - throw Fault(EXN_NM, 0x00000000); - exit() // never reached; satisfies type checker -} - -// CR0.EM and CR0.TS (SDM Vol.3A §2.5; APM Vol.2 §3.1.1). An OS sets TS -// on a task switch and saves the x87, MMX and SIMD state of the old task -// only when the new one first uses it, on the #NM; EM says there is no -// x87 FPU. -// -// #UD and #NM are both faults from decoding the instruction, in one class -// whose internal order the manuals leave open: "Faults from Decoding the -// Next Instruction ... Invalid Opcode (#UD), Coprocessor Not Available -// (#NM)", and "the priority of events within a class is -// implementation-dependent" (SDM Vol.3A §7.9, Table 7-2, class 9); -// "interrupt prioritization within a group is implementation dependent" -// (APM Vol.2 §8.5, Table 8-9, group 6). The model's choice is to raise -// every #UD the encoding or the enabled state decides first: an undefined -// opcode, prefix, ModR/M.reg extension or r/m form, a VSIB operand without -// a SIB byte, register operands an instruction forbids, a CPUID feature -// the processor lacks, AVX or AVX-512 state disabled in XCR0, an undefined -// x87 form. So the checks come after the decoder's (the tables of -// insn_dispatch.sail, vex_check_form, evex_check_form, x87_undefined). -// Both come before the instruction touches its operands: Table 7-2 "does -// not specify the prioritization of faults that arise during instruction -// execution" (#GP, #SS, #PF, #AC), which follow the decoding, and the -// APM puts those in group 7, below group 6. -// -// PAUSE, PREFETCHh, SFENCE, LFENCE, MFENCE, MOVNTI, CLFLUSH, CRC32 and -// POPCNT (SDM Vol.3A §2.5) and the VEX-encoded general-purpose -// instructions (BMI1, BMI2: Vol.2A §2.6.1, Type 13) are not affected. - -// MMX and legacy-encoded SSE instructions, LDMXCSR, STMXCSR and EMMS: #UD -// if EM = 1, whatever TS; else #NM if TS = 1. SDM Vol.3A §2.5: "If the EM -// flag is set, the setting of the TS flag has no effect on the execution -// of x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instructions" (Table 15-1 for -// MMX, Table 16-1 for SSE; the exception classes of Vol.2A §2.5; the EMMS -// page). APM Vol.2 §3.1.1: EM "forces an invalid-opcode exception (#UD) -// when an attempt is made to execute any of the 64-bit or 128-bit media -// instructions", TS an #NM, whose order is open (§8.5, Table 8-9, group -// 6); the model takes the SDM's. -val check_cr0_sse : unit -> unit -function check_cr0_sse() = { - if CR0[2] == 0b1 then raise_UD(); // EM - if CR0[3] == 0b1 then raise_NM() // TS -} - -// The VEX- and EVEX-encoded SIMD instructions, the opmask instructions, -// and XSAVE, XRSTOR, XSAVEOPT, XSAVEC, XSAVES and XRSTORS: #NM if TS = 1. -// EM does not affect them in the SDM: its VEX classes name it only as -// "Legacy SSE instruction: If CR0.EM[bit 2] = 1" (Vol.2A §2.5, Type 5, -// Table 2-22) or not at all (Types 6, 8 and 12), the EVEX Types E1-E12 -// (§2.8) and the opmask Types K20 and K21 (§2.9) not at all, and neither -// manual's XSAVE pages name it. The APM's #UD for "any SSE instruction -// (uses ZMM/YMM/XMM registers) ... when CR0.EM = 1" (Vol.2 §8.2.7), and -// for AVX-512 under "CR0.EM = 1" (Vol.4 §3.2.1), is a fault of one manual -// only, which the model does not raise. -val check_cr0_ts : unit -> unit -function check_cr0_ts() = if CR0[3] == 0b1 then raise_NM() - -// x87 instructions (Vol.3A Table 2-2), FXSAVE and FXRSTOR: #NM if EM = 1 -// or TS = 1. FXSAVE and FXRSTOR: "#NM If CR0.TS[bit 3] = 1. If -// CR0.EM[bit 2] = 1." (SDM Vol.2A FXSAVE, FXRSTOR); "setting EM to 1 -// forces an invalid-opcode exception (#UD) when an attempt is made to -// execute any of the 64-bit or 128-bit media instructions except the -// FXSAVE and FXRSTOR instructions. Attempting to execute these -// instructions when EM is set results in an #NM exception instead" (APM -// Vol.2 §3.1.1). That is the rule of the two instructions, NP 0F AE /0 -// and /1 with a memory operand; their opcode under a 66, F2 or F3 prefix, -// or VEX- or EVEX-encoded, is no instruction and takes the #UD of the -// decoder. WAIT/FWAIT has a rule of its own (opcode 9B). -val check_cr0_x87 : unit -> unit -function check_cr0_x87() = if CR0[2] == 0b1 | CR0[3] == 0b1 then raise_NM() diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail deleted file mode 100644 index dbc9290a7..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/extern.sail +++ /dev/null @@ -1,489 +0,0 @@ -// x86-64 — External Function Declarations -// -// All functions provided by the execution environment (C/C++ harness). - -// ========================================================================= -// Memory primitives -// ========================================================================= - -// Raw physical memory read/write. Size parameter 'n is in bits. -val __read_mem : forall 'n, 'n > 0. (qword, int('n)) -> bits('n) -val __write_mem : forall 'n, 'n > 0. (qword, int('n), bits('n)) -> unit - -// Slow-path for page-crossing accesses (each byte translated separately). -val __mem_read_crossing : forall 'n, 'n > 0. (qword, int('n), PTAccess) -> bits('n) -val __mem_write_crossing : forall 'n, 'n > 0. (qword, int('n), bits('n)) -> unit - -// Software TLB (purely an optimization; removing does not affect correctness). -val __tlb_lookup : (qword, bool) -> option(qword) -val __tlb_insert : (qword, qword, bool) -> unit -val __tlb_flush : unit -> unit - -// ========================================================================= -// System -// ========================================================================= - -val __rdtsc : unit -> qword -val __rdrand64 : unit -> (qword, bit) -val __rdseed64 : unit -> (qword, bit) - -// MSR read/write — implemented in C++ as a key-value store -val __rdmsr : dword -> qword -val __wrmsr : (dword, qword) -> unit - -// SDM Vol.3A 13.8.6.1: CR8 aliases the enabled local APIC's TPR[7:4]. -val __read_cr8 : unit -> bits(4) -val __write_cr8 : bits(4) -> unit - -val __syscall : (qword, qword) -> unit - -val __software_interrupt : byte -> unit - -// Check for and acknowledge a pending external interrupt. -// Returns the vector number, or -1 if no interrupt pending. -val __check_pending_irq : unit -> int - -// Check if an SMI is pending (set by emulator on port 0xB2 write). -val __check_pending_smi : unit -> bool - -val __wait : unit -> unit - -// ========================================================================= -// I/O ports -// ========================================================================= - -val __port_in8 : word -> byte -val __port_in16 : word -> word -val __port_in32 : word -> dword - -val __port_out8 : (word, byte) -> unit -val __port_out16 : (word, word) -> unit -val __port_out32 : (word, dword) -> unit - -// ========================================================================= -// MXCSR -// ========================================================================= - -val __ldmxcsr : dword -> unit -val __stmxcsr : unit -> dword - -// ========================================================================= -// FP enums -// ========================================================================= - -enum FPCompareResult = { FP_GT, FP_LT, FP_EQ, FP_UNORDERED } - -enum FPClass = { - FP_Unsupported, - FP_NaN, - FP_Normal, - FP_Infinity, - FP_Zero, - FP_Empty, - FP_Denormal -} - -// ========================================================================= -// Single precision (f32) -// ========================================================================= - -val __f32_add : (dword, dword) -> dword -val __f32_sub : (dword, dword) -> dword -val __f32_mul : (dword, dword) -> dword -val __f32_div : (dword, dword) -> dword -val __f32_sqrt : dword -> dword -val __f32_min : (dword, dword) -> dword -val __f32_max : (dword, dword) -> dword -val __f32_rsqrt : dword -> dword -val __f32_rcp : dword -> dword - -// ========================================================================= -// Double precision (forced64) -// ========================================================================= - -val __f64_add : (qword, qword) -> qword -val __f64_sub : (qword, qword) -> qword -val __f64_mul : (qword, qword) -> qword -val __f64_div : (qword, qword) -> qword -val __f64_sqrt : qword -> qword -val __f64_min : (qword, qword) -> qword -val __f64_max : (qword, qword) -> qword - -// ========================================================================= -// FP comparison -// ========================================================================= - -val __f32_compare : (dword, dword) -> FPCompareResult -val __f64_compare : (qword, qword) -> FPCompareResult -val __f16_compare : (word, word) -> FPCompareResult - -// ========================================================================= -// FP conversions: int <-> float -// ========================================================================= - -val __int32_to_f64 : dword -> qword -val __int64_to_f64 : qword -> qword -val __int32_to_f32 : dword -> dword -val __int64_to_f32 : qword -> dword -val __f64_to_int32 : qword -> dword -val __f64_to_int64 : qword -> qword -val __f32_to_int32 : dword -> dword -val __f32_to_int64 : dword -> qword -val __f64_to_int32_trunc : qword -> dword -val __f64_to_int64_trunc : qword -> qword -val __f32_to_int32_trunc : dword -> dword -val __f32_to_int64_trunc : dword -> qword - -// ========================================================================= -// FP conversions: unsigned int <-> float -// ========================================================================= - -val __uint32_to_f32 : dword -> dword -val __uint64_to_f32 : qword -> dword -val __uint32_to_f64 : dword -> qword -val __uint64_to_f64 : qword -> qword -val __f32_to_uint32 : dword -> dword -val __f32_to_uint64 : dword -> qword -val __f64_to_uint32 : qword -> dword -val __f64_to_uint64 : qword -> qword -val __f32_to_uint32_trunc : dword -> dword -val __f32_to_uint64_trunc : dword -> qword -val __f64_to_uint32_trunc : qword -> dword -val __f64_to_uint64_trunc : qword -> qword - -// ========================================================================= -// FP conversions: float <-> float -// ========================================================================= - -val __f64_to_f32 : qword -> dword -val __f32_to_f64 : dword -> qword - -// ========================================================================= -// FP rounding (SSE4.1 ROUNDPS/ROUNDPD/ROUNDSS/ROUNDSD) -// ========================================================================= - -val __f32_round : (dword, byte) -> dword -val __f64_round : (qword, byte) -> qword - -// ========================================================================= -// FMA: fused multiply-add -// ========================================================================= - -val __f32_fmadd : (dword, dword, dword) -> dword -val __f32_fmsub : (dword, dword, dword) -> dword -val __f32_fnmadd : (dword, dword, dword) -> dword -val __f32_fnmsub : (dword, dword, dword) -> dword -val __f64_fmadd : (qword, qword, qword) -> qword -val __f64_fmsub : (qword, qword, qword) -> qword -val __f64_fnmadd : (qword, qword, qword) -> qword -val __f64_fnmsub : (qword, qword, qword) -> qword - -// ========================================================================= -// AVX-512 FP special -// ========================================================================= - -// VSCALEF: result = src1 * 2^(floor(src2)) -val __f32_scalef : (dword, dword) -> dword -val __f64_scalef : (qword, qword) -> qword - -// VGETEXP: extract unbiased exponent as FP value -val __f32_getexp : dword -> dword -val __f64_getexp : qword -> qword - -// VRCP14: approximate reciprocal (14-bit precision) -val __f32_rcp14 : dword -> dword -val __f64_rcp14 : qword -> qword - -// VRSQRT14: approximate reciprocal square root (14-bit precision) -val __f32_rsqrt14 : dword -> dword -val __f64_rsqrt14 : qword -> qword - -// VRNDSCALE: round to specified number of fraction bits -val __f32_rndscale : (dword, byte) -> dword -val __f64_rndscale : (qword, byte) -> qword - -// VGETMANT: extract mantissa as FP value -val __f32_getmant : (dword, byte) -> dword -val __f64_getmant : (qword, byte) -> qword - -// VREDUCE: reduce FP value -val __f32_reduce : (dword, byte) -> dword -val __f64_reduce : (qword, byte) -> qword - -// VFIXUPIMM: fix up special FP values -val __f32_fixupimm : (dword, dword, dword, byte) -> dword -val __f64_fixupimm : (qword, qword, qword, byte) -> qword - -// VDPBF16PS: BF16 dot product element (dst += bf16_hi*bf16_hi + bf16_lo*bf16_lo) -val __vdpbf16ps_elem : (dword, dword, dword) -> dword - -// ========================================================================= -// Half precision (f16) — AVX-512 FP16 -// ========================================================================= - -val __f16_add : (word, word) -> word -val __f16_sub : (word, word) -> word -val __f16_mul : (word, word) -> word -val __f16_div : (word, word) -> word -val __f16_sqrt : word -> word -val __f16_min : (word, word) -> word -val __f16_max : (word, word) -> word - -// FP16 FMA -val __f16_fmadd : (word, word, word) -> word -val __f16_fmsub : (word, word, word) -> word -val __f16_fnmadd : (word, word, word) -> word -val __f16_fnmsub : (word, word, word) -> word - -// FP16 conversions -val __f16_to_f32 : word -> dword -val __f32_to_f16 : dword -> word -val __f16_to_f64 : word -> qword -val __f64_to_f16 : qword -> word -val __f16_to_int32 : word -> dword -val __f16_to_int64 : word -> qword -val __f16_to_int32_trunc : word -> dword -val __f16_to_int64_trunc : word -> qword -val __int32_to_f16 : dword -> word -val __int64_to_f16 : qword -> word -val __f16_to_uint32 : word -> dword -val __f16_to_uint64 : word -> qword -val __f16_to_uint32_trunc : word -> dword -val __f16_to_uint64_trunc : word -> qword -val __uint32_to_f16 : dword -> word -val __uint64_to_f16 : qword -> word -val __f16_to_int16 : word -> word -val __f16_to_int16_trunc : word -> word -val __int16_to_f16 : word -> word -val __f16_to_uint16 : word -> word -val __f16_to_uint16_trunc : word -> word -val __uint16_to_f16 : word -> word - -// FP16 special operations -val __f16_scalef : (word, word) -> word -val __f16_getexp : word -> word -val __f16_rcp : word -> word -val __f16_rsqrt : word -> word -val __f16_rndscale : (word, byte) -> word -val __f16_getmant : (word, byte) -> word -val __f16_reduce : (word, byte) -> word - -// ========================================================================= -// KNL: VRCP28/VRSQRT28/VEXP2 -// ========================================================================= - -val __f32_rcp28 : dword -> dword -val __f64_rcp28 : qword -> qword -val __f32_rsqrt28 : dword -> dword -val __f64_rsqrt28 : qword -> qword -val __f32_exp2 : dword -> dword -val __f64_exp2 : qword -> qword - -// ========================================================================= -// x87 extended precision (f80) -// ========================================================================= - -// Arithmetic -val __f80_add : (fp80, fp80) -> fp80 -val __f80_sub : (fp80, fp80) -> fp80 -val __f80_mul : (fp80, fp80) -> fp80 -val __f80_div : (fp80, fp80) -> fp80 -val __f80_sqrt : fp80 -> fp80 -val __f80_abs : fp80 -> fp80 -val __f80_chs : fp80 -> fp80 -val __f80_compare : (fp80, fp80) -> FPCompareResult - -// Conversions to/from 80-bit extended precision -val __f80_from_f32 : dword -> fp80 -val __f80_from_f64 : qword -> fp80 -val __f80_to_f32 : fp80 -> dword -val __f80_to_f64 : fp80 -> qword -val __f80_from_int16 : word -> fp80 -val __f80_from_int32 : dword -> fp80 -val __f80_from_int64 : qword -> fp80 -val __f80_to_int16 : fp80 -> word -val __f80_to_int32 : fp80 -> dword -val __f80_to_int64 : fp80 -> qword -val __f80_to_int16_trunc : fp80 -> word -val __f80_to_int32_trunc : fp80 -> dword -val __f80_to_int64_trunc : fp80 -> qword - -// Constants -val __f80_zero : unit -> fp80 -val __f80_one : unit -> fp80 -val __f80_log2_10 : unit -> fp80 -val __f80_log2_e : unit -> fp80 -val __f80_pi : unit -> fp80 -val __f80_log10_2 : unit -> fp80 -val __f80_ln_2 : unit -> fp80 - -// Classification -val __f80_classify : fp80 -> FPClass - -// Decomposition (used by FXTRACT) -val __f80_extract_exponent : fp80 -> fp80 -val __f80_extract_significand : fp80 -> fp80 - -// Transcendental operations -val __f80_yl2x : (fp80, fp80) -> fp80 -val __f80_yl2xp1 : (fp80, fp80) -> fp80 -val __f80_sin : fp80 -> fp80 -val __f80_cos : fp80 -> fp80 -val __f80_tan : fp80 -> fp80 -val __f80_atan2 : (fp80, fp80) -> fp80 -val __f80_2xm1 : fp80 -> fp80 -val __f80_scale : (fp80, fp80) -> fp80 -// FPREM and FPREM1 of (ST(0), ST(1)): the remainder, or the partial -// remainder of their Operation for exponents 64 or more apart, in bits -// 79..0, and Q0, Q1, Q2 of the quotient and C2 (the reduction is -// incomplete) in bits 80..83, all 0 for a NaN result. -val __f80_prem : (fp80, fp80) -> bits(84) -val __f80_prem1 : (fp80, fp80) -> bits(84) -val __f80_round : fp80 -> fp80 - -// BCD conversions (for FBLD/FBSTP) -val __f80_from_bcd : fp80 -> fp80 -val __f80_to_bcd : fp80 -> fp80 - -// ========================================================================= -// Polymorphic FP wrappers (dispatch by bitvector width) -// ========================================================================= - -// Unary -// {8,16,32,64,80} — has f80 extern -val fp_sqrt : forall 'n, 'n in {8, 16, 32, 64, 80}. bits('n) -> bits('n) -function fp_sqrt(x) = match 'n { - 8 => unreachable(), 16 => __f16_sqrt(x), 32 => __f32_sqrt(x), 64 => __f64_sqrt(x), 80 => __f80_sqrt(x) -} - -// {8,16,32,64} — no f80 extern -val fp_getexp : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_getexp(x) = match 'n { - 8 => unreachable(), 16 => __f16_getexp(x), 32 => __f32_getexp(x), 64 => __f64_getexp(x) -} - -val fp_rcp : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_rcp(x) = match 'n { - 8 => unreachable(), 64 => unreachable(), 16 => __f16_rcp(x), 32 => __f32_rcp(x) -} - -val fp_rsqrt : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_rsqrt(x) = match 'n { - 8 => unreachable(), 64 => unreachable(), 16 => __f16_rsqrt(x), 32 => __f32_rsqrt(x) -} - -val fp_rcp14 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_rcp14(x) = match 'n { - 8 => unreachable(), 16 => unreachable(), 32 => __f32_rcp14(x), 64 => __f64_rcp14(x) -} - -val fp_rsqrt14 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_rsqrt14(x) = match 'n { - 8 => unreachable(), 16 => unreachable(), 32 => __f32_rsqrt14(x), 64 => __f64_rsqrt14(x) -} - -val fp_rcp28 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_rcp28(x) = match 'n { - 8 => unreachable(), 16 => unreachable(), 32 => __f32_rcp28(x), 64 => __f64_rcp28(x) -} - -val fp_rsqrt28 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_rsqrt28(x) = match 'n { - 8 => unreachable(), 16 => unreachable(), 32 => __f32_rsqrt28(x), 64 => __f64_rsqrt28(x) -} - -val fp_exp2 : forall 'n, 'n in {8, 16, 32, 64}. bits('n) -> bits('n) -function fp_exp2(x) = match 'n { - 8 => unreachable(), 16 => unreachable(), 32 => __f32_exp2(x), 64 => __f64_exp2(x) -} - -// Binary — {8,16,32,64,80} where f80 extern exists -val fp_add : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) -function fp_add(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_add(a, b), 32 => __f32_add(a, b), 64 => __f64_add(a, b), 80 => __f80_add(a, b) -} - -val fp_sub : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) -function fp_sub(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_sub(a, b), 32 => __f32_sub(a, b), 64 => __f64_sub(a, b), 80 => __f80_sub(a, b) -} - -val fp_mul : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) -function fp_mul(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_mul(a, b), 32 => __f32_mul(a, b), 64 => __f64_mul(a, b), 80 => __f80_mul(a, b) -} - -val fp_div : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> bits('n) -function fp_div(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_div(a, b), 32 => __f32_div(a, b), 64 => __f64_div(a, b), 80 => __f80_div(a, b) -} - -// Binary — {8,16,32,64} only -val fp_min : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) -function fp_min(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_min(a, b), 32 => __f32_min(a, b), 64 => __f64_min(a, b) -} - -val fp_max : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) -function fp_max(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_max(a, b), 32 => __f32_max(a, b), 64 => __f64_max(a, b) -} - -val fp_scalef : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n)) -> bits('n) -function fp_scalef(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_scalef(a, b), 32 => __f32_scalef(a, b), 64 => __f64_scalef(a, b) -} - -// Binary with byte imm -val fp_round : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) -function fp_round(x, imm) = match 'n { - 8 => unreachable(), 16 => unreachable(), 32 => __f32_round(x, imm), 64 => __f64_round(x, imm) -} - -val fp_rndscale : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) -function fp_rndscale(x, imm) = match 'n { - 8 => unreachable(), 16 => __f16_rndscale(x, imm), 32 => __f32_rndscale(x, imm), 64 => __f64_rndscale(x, imm) -} - -val fp_getmant : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) -function fp_getmant(x, imm) = match 'n { - 8 => unreachable(), 16 => __f16_getmant(x, imm), 32 => __f32_getmant(x, imm), 64 => __f64_getmant(x, imm) -} - -val fp_reduce : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), byte) -> bits('n) -function fp_reduce(x, imm) = match 'n { - 8 => unreachable(), 16 => __f16_reduce(x, imm), 32 => __f32_reduce(x, imm), 64 => __f64_reduce(x, imm) -} - -// Ternary FMA -val fp_fmadd : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) -function fp_fmadd(a, b, c) = match 'n { - 8 => unreachable(), 16 => __f16_fmadd(a, b, c), 32 => __f32_fmadd(a, b, c), 64 => __f64_fmadd(a, b, c) -} - -val fp_fmsub : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) -function fp_fmsub(a, b, c) = match 'n { - 8 => unreachable(), 16 => __f16_fmsub(a, b, c), 32 => __f32_fmsub(a, b, c), 64 => __f64_fmsub(a, b, c) -} - -val fp_fnmadd : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) -function fp_fnmadd(a, b, c) = match 'n { - 8 => unreachable(), 16 => __f16_fnmadd(a, b, c), 32 => __f32_fnmadd(a, b, c), 64 => __f64_fnmadd(a, b, c) -} - -val fp_fnmsub : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n)) -> bits('n) -function fp_fnmsub(a, b, c) = match 'n { - 8 => unreachable(), 16 => __f16_fnmsub(a, b, c), 32 => __f32_fnmsub(a, b, c), 64 => __f64_fnmsub(a, b, c) -} - -// Ternary with byte imm -val fp_fixupimm : forall 'n, 'n in {8, 16, 32, 64}. (bits('n), bits('n), bits('n), byte) -> bits('n) -function fp_fixupimm(a, b, c, imm) = match 'n { - 8 => unreachable(), 16 => unreachable(), 32 => __f32_fixupimm(a, b, c, imm), 64 => __f64_fixupimm(a, b, c, imm) -} - -// Comparison — {8,16,32,64,80} (has f80 extern) -val fp_compare : forall 'n, 'n in {8, 16, 32, 64, 80}. (bits('n), bits('n)) -> FPCompareResult -function fp_compare(a, b) = match 'n { - 8 => unreachable(), 16 => __f16_compare(a, b), 32 => __f32_compare(a, b), 64 => __f64_compare(a, b), 80 => __f80_compare(a, b) -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail deleted file mode 100644 index 655c91cc0..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/fetch_execute.sail +++ /dev/null @@ -1,261 +0,0 @@ -// x86-64 — Fetch-Decode-Execute Loop -// -// Top-level entry point for the instruction cycle. -// Fetches and decodes one instruction from RIP, executes it, -// and advances RIP past the instruction bytes. - -// Raise #DB reporting the given DR6 status bits: the processor clears B0-B3 -// and sets what it reports, never clearing the rest (SDM Vol.3B §20.2.3). -// The B0-B3 in `open` are undefined. With an IDT the exception is -// delivered with RIP as the return address: already advanced past the -// instruction for a trap (single step), still at the instruction for a -// fault (instruction breakpoint). Without an IDT it is reported like any -// fault, with that RIP. -val raise_debug_exception : (qword, bits(4)) -> unit -function raise_debug_exception(status, open) = { - DR6 = (DR6 & 0xFFFFFFFFFFFFFFF0) | status | zero_extend((undefined : bits(4)) & open); - if system_mode then { - try { - deliver_exception(EXN_DB, 0x00000000, EV_Exception) - } catch { - Fault(vec2, err2) => { - fault_pending = true; - fault_vector = vec2; - fault_error_code = err2 - }, - VMExit(reason, qual) => complete_vm_exit(reason, qual), - } - } else { - fault_pending = true; - fault_vector = EXN_DB; - fault_error_code = 0x00000000 - } -} - -// Instruction breakpoints matching a linear address (SDM Vol.3B §20.2.5): -// R/Wn = 00 (execute) with LENn = 00 (any other length is undefined for -// instruction breakpoints), and DRn equal to the address of the -// instruction's first byte, prefixes included. `enabled` selects the -// breakpoints that Ln or Gn enables, the hits, or the others. -val insn_breakpoint_matches : (qword, bool) -> bits(4) -function insn_breakpoint_matches(lin, enabled) = { - var hits : bits(4) = 0x0; - foreach (n from 0 to 3) { - let on : bool = DR7[2 * n] == bitone | DR7[2 * n + 1] == bitone; - let rw_len : bits(4) = DR7[(19 + 4 * n) .. (16 + 4 * n)]; - let dr : qword = match n { 0 => DR0, 1 => DR1, 2 => DR2, _ => DR3 }; - if on == enabled & rw_len == 0x0 & dr == lin then hits[n] = bitone - }; - hits -} - -// Decode and execute one instruction. -// Sets fault_pending/fault_vector/fault_error_code on exception. -val step : unit -> unit -function step() = { - fault_pending = false; - event_delivered = false; - rep_trap_rf = false; - // Data breakpoints hit by a MOV SS/POP SS are delivered after the - // following instruction (SDM Vol.3B §20.3.1.2), so they survive one step. - if ss_shadow != 1 then { - pending_dbp = 0x0; - open_dbp = 0x0 - }; - - // Check for pending SMI before anything else. - // SDM §34.2: "The SMI takes precedence over [...] debug exceptions - // and external interrupts." SMIs are non-maskable (not blocked by IF). - if system_mode & ~(in_smm) & __check_pending_smi() then { - deliver_smi(); - return () - }; - - // Check for pending external interrupts before fetching. - // Only deliver if IF=1 (interrupts enabled) and in system mode, and not - // in the instruction following STI or MOV SS/POP SS (SDM Vol.3A - // §7.8.1 and §7.8.3). - if system_mode & IF_flag == 0b1 & ss_shadow == 0 & sti_shadow == 0 then { - let irq_vec = __check_pending_irq(); - if 0 <= irq_vec & irq_vec <= 255 then { - let vec : exception_vector = irq_vec; - // VMX: external interrupt exit (pin_based_controls bit 0) - if in_vmx_non_root & vmcs.pin_based_controls[0] == 0b1 then { - vmcs.exit_instr_length = 0x00000000; - // NMI exit (pin_based_controls bit 3) — vector 2 - if vec == 2 & vmcs.pin_based_controls[3] == 0b1 then { - complete_vm_exit(VMEXIT_EXCEPTION_NMI, 0x0000000000000202); - return () - }; - complete_vm_exit(VMEXIT_EXTERNAL_INT, zero_extend(to_bits(32, vec))); - return () - }; - try { - deliver_exception(vec, 0x00000000, EV_ExternalInt); - return () - } catch { - Fault(vec2, err2) => { - fault_pending = true; - fault_vector = vec2; - fault_error_code = err2; - return () - }, - VMExit(reason, qual) => { - complete_vm_exit(reason, qual); - return () - }, - } - } - }; - - // Instruction breakpoint (SDM Vol.3B §20.3.1.1): the highest-priority - // debug exception, a fault before the instruction. The check is skipped - // when RF is set (IRET restoring a handler's frame) and for the - // instruction after MOV SS/POP SS: "Any instruction breakpoint on the - // next instruction is suppressed (as if EFLAGS.RF were 1)" (SDM Vol.3A - // §7.8.3, p.7-8); the processor "does not allow external interrupts or - // debug exceptions to occur until the instruction immediately following - // the MOV SS or POP SS instruction completes execution" (APM Vol.2 - // §8.1.4, p.245). RF is then cleared, so it protects exactly one - // instruction. - if RF == 0b0 & ss_shadow != 1 then { - let lin = RIP + get_seg_base(CS); - let hits = insn_breakpoint_matches(lin, true); - if hits != 0x0 then { - raise_debug_exception(zero_extend(hits), insn_breakpoint_matches(lin, false)); - return () - } - }; - RF = 0b0; - - // Set decode position to current RIP - decode_pos = RIP; - insn_start = RIP; - rip_rel_pending = false; - next_rip = None(); - - // Save RSP and flags so we can restore them if the instruction faults. - // x86 guarantees that a faulting instruction leaves architectural state - // as if it never executed. RSP and flags are the registers most likely - // to be modified before a memory op that can fault (e.g. PUSH modifies - // RSP before the store; ALU-to-memory ops update flags before writeback). - // Other registers (x87, segments) are handled by reordering the - // individual instructions so that side effects follow memory ops. - let saved_rsp = GPR[RSP]; - let saved_rflags = read_rflags(); - - // TF is sampled before the instruction: the instruction that sets TF - // (POPF, IRET) is not trapped, the one that clears it still is. - let tf_at_start : bool = TF == 0b1; - - let faulted : bool = - try { - // VME faults before the instruction when a virtual interrupt is - // both enabled and pending (SDM Vol.3B §23.3.2), even at IOPL 3. - if cur_mode == Virtual8086Mode & CR4[0] == bitone & - VIF == bitone & VIP == bitone then raise_GP0(); - // Decode and execute one instruction - decode_execute(); - false - } catch { - Fault(vec, err) => { - GPR[RSP] = saved_rsp; - write_rflags(saved_rflags); - VIF = saved_rflags[19]; - VIP = saved_rflags[20]; - if system_mode then { - // In system mode, deliver faults through the IDT. - try { - deliver_exception(vec, err, EV_Exception); - // RIP already set to handler by deliver_exception; skip normal advance - return () - } catch { - // deliver_exception itself faulted — double/triple fault - Fault(vec2, err2) => { - fault_pending = true; - fault_vector = vec2; - fault_error_code = err2; - return () - }, - VMExit(_, _) => return (), - } - } else { - // RF as the pushed RFLAGS image would carry it (see - // deliver_exception): 1 for a fault-class exception, but the - // current value, cleared at the start of the instruction, for a - // software interrupt whatever its vector (SDM Vol.3B §20.3.1.1). - // INT n, INT3, INTO and INT1 set sw_return_rip before raising. - match sw_return_rip { - Some(_) => sw_return_rip = None(), - None() => if is_fault_class(vec) then RF = 0b1, - }; - fault_pending = true; - fault_vector = vec; - fault_error_code = err; - true - } - }, - // VMX: VM exit from VMX non-root operation. - // Save guest state, load host state, record exit info. - VMExit(reason, qual) => { - complete_vm_exit(reason, qual); - return () - }, - }; - - // Advance RIP unless we faulted or halted. - // Control-flow instructions set next_rip to the branch target; - // otherwise we fall through to the next instruction. - if ~(faulted) & system_state == SysRunning then - RIP = match next_rip { Some(t) => t, None() => decode_pos }; - - // Debug traps after the instruction, reported together in DR6: - // BS — single step (SDM Vol.3B §20.3.1.4): TF was set at the start, - // unless the instruction delivered an event through the IDT - // (INT n, INT3, INTO and INT1 clear TF as part of delivery); - // Bn — data breakpoints hit by the instruction's accesses (§20.3.1.2), - // which INT n does not discard. - // With BS the other B0-B3 are undefined: "When the BS flag is set, any of - // the other debug status bits also may be set" (§20.2.3 p.20-4); "Other - // status bits within the DR6 register can be set by the processor along - // with the BS bit" (APM Vol.2 §13.1.1.3 p.395). A fault loses them (the - // early return above), and after MOV SS/POP SS the single-step trap is - // suppressed and the data breakpoints wait for the following instruction - // (§7.8.3, §20.3.1.2). - if ~(faulted) & system_state == SysRunning & ss_shadow != 2 then { - let bs : qword = if tf_at_start & ~(event_delivered) then 0x0000000000004000 else zeros(); - let status : qword = bs | zero_extend(pending_dbp); - let open : bits(4) = (if bs != zeros() then 0xF else open_dbp) & ~(pending_dbp); - if status != zeros() then { - // RF in the image of a trap after a non-final iteration of a repeated - // string instruction is undefined. The SDM pushes 1: "For any - // trap-class exception generated by any iteration of a repeated - // string instruction but the last iteration, the value pushed for RF - // is 1" (§20.3.1.1 p.20-9). The APM sets it "when a string - // instruction is interrupted", "However, when a #DB exception occurs, - // the processor clears RFLAGS.RF to 0 in the rFLAGS image" (Vol.2 - // §8.2.2 p.250). - if rep_trap_rf then RF = undefined; - raise_debug_exception(status, open) - } - }; - - // The SS-load shadow lasts through the following instruction. - ss_shadow = match ss_shadow { 2 => 1, _ => 0 }; - sti_shadow = match sti_shadow { 2 => 1, _ => 0 } -} - -// Run instructions until a fault, halt, or step count reached. -val run : int -> unit -function run(max_steps) = { - var remaining : int = max_steps; - - while remaining > 0 & ~(fault_pending) & system_state == SysRunning do { - step(); - remaining = remaining - 1 - } -} - -// Dummy main function required by the Sail C++ backend. -val main : unit -> unit -function main() = () diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail deleted file mode 100644 index f17e17fd9..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_alu.sail +++ /dev/null @@ -1,100 +0,0 @@ -// x86-64 — ALU Helpers -// -// These helpers perform ALU operations on resolved values, handling -// flag updates and result write-back. They support both register and -// memory operands via the RM union. - -// Perform an ALU operation on two operand-sized values. -// Returns (result, should_write_back). CMP doesn't write back. -val alu_compute : forall 'os, 'os in {8, 16, 32, 64}. (ALUOp, bits('os), bits('os), int('os)) -> (bits('os), bool) -function alu_compute(op, a, b, os) = { - match op { - ALU_ADD => { - let result = a + b; - update_flags_add(result, a, b); - (result, true) - }, - ALU_OR => { - let result = a | b; - update_flags_logic(result); - (result, true) - }, - ALU_ADC => { - let result = a + b + zero_extend(CF); - update_flags_adc(result, a, b, CF); - (result, true) - }, - ALU_SBB => { - let result = a - b - zero_extend(CF); - update_flags_sbb(result, a, b, CF); - (result, true) - }, - ALU_AND => { - let result = a & b; - update_flags_logic(result); - (result, true) - }, - ALU_SUB => { - let result = a - b; - update_flags_sub(result, a, b); - (result, true) - }, - ALU_XOR => { - let result = a ^ b; - update_flags_logic(result); - (result, true) - }, - ALU_CMP => { - let result = a - b; - update_flags_sub(result, a, b); - (result, false) // CMP: don't write back - }, - } -} - -// Execute ALU: dst_rm OP= src_reg -val exec_alu_rm_reg : (ALUOp, RM, GPRRef, {8, 16, 32, 64}) -> unit -function exec_alu_rm_reg(op, dest, reg, os) = { - let a = if op == ALU_CMP then v(os, dest) else read_rmw(os, dest); - let b = v(os, reg); - let (result, wb) = alu_compute(op, a, b, os); - if wb then v(os, dest) = result -} - -// Execute ALU: dst_reg OP= src_rm -val exec_alu_reg_rm : (ALUOp, GPRRef, RM, {8, 16, 32, 64}) -> unit -function exec_alu_reg_rm(op, reg, src, os) = { - let a = v(os, reg); - let b = v(os, src); - let (result, wb) = alu_compute(op, a, b, os); - if wb then v(reg) = result -} - -// Execute ALU: AL/AX/EAX/RAX OP= imm (accumulator short forms) -val exec_alu_acc_imm : forall 'os, 'os in {8, 16, 32, 64}. (ALUOp, bits('os), int('os), Prefixes) -> unit -function exec_alu_acc_imm(op, imm, os, _) = { - let a = v(os, RAX); - let (result, wb) = alu_compute(op, a, imm, os); - if wb then v(RAX) = result -} - -// Execute ALU: dest OP= imm (Group 1: opcodes 80, 81, 83) -val exec_alu_rm_imm : forall 'os, 'os in {8, 16, 32, 64}. (ALUOp, RM, bits('os), int('os)) -> unit -function exec_alu_rm_imm(op, dest, imm, os) = { - let a = if op == ALU_CMP then v(os, dest) else read_rmw(os, dest); - let (result, wb) = alu_compute(op, a, imm, os); - if wb then v(os, dest) = result -} - -// Map Group 1 reg field (0-7) to ALUOp. -val group1_op : range(0, 7) -> ALUOp -function group1_op(reg) = match reg { - 0 => ALU_ADD, - 1 => ALU_OR, - 2 => ALU_ADC, - 3 => ALU_SBB, - 4 => ALU_AND, - 5 => ALU_SUB, - 6 => ALU_XOR, - 7 => ALU_CMP, -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail deleted file mode 100644 index 2af4f8eb2..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_baseline.sail +++ /dev/null @@ -1,2551 +0,0 @@ -// x86-64 — 2-Byte Opcode Map: Baseline Operations -// -// CMOVcc, Jcc, SETcc, BT/BTS/BTR/BTC, SHLD/SHRD, IMUL, MOVZX/MOVSX, -// BSF/BSR, POPCNT, CMPXCHG, XADD, BSWAP, CPUID, RDTSC, and more. - -// DR7.GD (SDM Vol.3B §20.2.4, §20.3.1.3): any MOV DR while GD is set raises -// #DB before the access, a fault with DR6.BD set and RF = 1 in the pushed -// image; the processor clears GD on the way to the handler so that the -// handler itself can use the debug registers. -val general_detect_check : unit -> unit -function general_detect_check() = { - if DR7[13] == bitone then { - DR7[13] = bitzero; - DR6 = (DR6 & 0xFFFFFFFFFFFFFFF0) | 0x0000000000002000; - RF = 0b1; - throw Fault(EXN_DB, 0x00000000) - } -} - -// A linear address is canonical when bits 63:N repeat bit N-1, with N = 48 -// under 4-level paging and 57 under 5-level paging (SDM Vol.1 §3.3.7.1, -// Vol.3A §4.5). SYSRET and SYSEXIT raise #GP(0) for a non-canonical target. -val is_canonical_linear : qword -> bool -function is_canonical_linear(addr) = - if CR4[12] == 0b1 then addr[63..56] == zeros() | addr[63..56] == ones() - else addr[63..47] == zeros() | addr[63..47] == ones() - -// LOCK is valid only on the lockable instructions and only where the -// destination is in memory (SDM Vol.2B LOCK): with a register operand, -// or on CMP (which does not write), it raises #UD. -val check_lock_rm : (Prefixes, RM, bool) -> unit -function check_lock_rm(pfx, dest, is_cmp) = { - if pfx.has_lock then { - match dest { - RM_reg(_) => raise_UD(), - RM_mem(_) => if is_cmp then raise_UD(), - } - } -} - -// XADD — Exchange and Add -val exec_xadd : (GPRRef, GPRRef, operand_size) -> unit -function exec_xadd(dst, src, os) = { - let a = v(os, dst); - let b = v(os, src); - update_flags_add(a + b, a, b); - v(src) = a; - v(dst) = a + b -} - -// Descriptor type validation for LAR in IA-32e mode (SDM Table 1-49). -// System segment types (S=0): valid = 2 (LDT), 9 (avail TSS), B (busy TSS), C (call gate). -// Code/data segments (S=1): all valid. -val lar_type_valid_64 : dword -> bool -function lar_type_valid_64(desc_hi) = { - let s_bit : bit = desc_hi[12]; - if s_bit == 0b1 then { - true - } else { - let typ : bits(4) = desc_hi[11..8]; - typ == 0x2 | typ == 0x9 | typ == 0xB | typ == 0xC - } -} - -// Descriptor type validation for LSL in IA-32e mode (SDM Table 1-53). -// System segment types (S=0): valid = 2 (LDT), 9 (avail TSS), B (busy TSS). -// Code/data segments (S=1): all valid. -val lsl_type_valid_64 : dword -> bool -function lsl_type_valid_64(desc_hi) = { - let s_bit : bit = desc_hi[12]; - if s_bit == 0b1 then { - true - } else { - let typ : bits(4) = desc_hi[11..8]; - typ == 0x2 | typ == 0x9 | typ == 0xB - } -} - -// Privilege check for non-conforming segments: CPL ≤ DPL and RPL ≤ DPL. -// Conforming code segments (S=1, type[3]=1, type[2]=1) bypass this check. -val desc_privilege_ok : (dword, word) -> bool -function desc_privilege_ok(desc_hi, selector) = { - let s_bit : bit = desc_hi[12]; - let is_conforming : bool = s_bit == 0b1 & desc_hi[11] == 0b1 & desc_hi[10] == 0b1; - if is_conforming then { - true - } else { - let dpl : range(0, 3) = unsigned(desc_hi[14..13]); - let rpl : range(0, 3) = unsigned(selector[1..0]); - cur_cpl <= dpl & rpl <= dpl - } -} - -// CPUID — returns (EAX, EBX, ECX, EDX) for a given leaf/subleaf. -// Feature-dependent leaves are built from has_* registers and XCR0. -val cpuid : (dword, dword) -> (dword, dword, dword, dword) -function cpuid(leaf, subleaf) = { - let leaf_val : range(0, 4294967295) = unsigned(leaf); - let sub_val : range(0, 4294967295) = unsigned(subleaf); - - match leaf_val { - // Leaf 0: Vendor string + max basic leaf (1EH with AMX, whose leaves - // 1DH and 1EH are valid only when MAX_LEAF reaches them). - // We report "GenuineIntel" because system libraries (e.g. glibc) - // select code paths based on the vendor string. Presenting as a - // genuine Intel CPU ensures the same feature negotiation that would - // happen on real hardware. - 0 => (if has_amx_tile then 0x0000001E else 0x00000016, 0x756E6547, 0x6C65746E, 0x49656E69), - - // Leaf 1: Family/Model/Stepping, feature bits - 1 => { - let eax : dword = 0x000506E3; // Family 6, Model 5E, Stepping 3 - let ebx : dword = 0x00010800; // CLFLUSH=8, max logical=1 - - // ECX: built dynamically from has_* flags and CR4/XCR0 - var ecx : dword = 0x00000000; - if has_sse3 then ecx = ecx | 0x00000001; // bit 0 (SSE3) - if has_pclmulqdq then ecx = ecx | 0x00000002; // bit 1 - if has_vmx then ecx = ecx | 0x00000020; // bit 5 (VMX) - if has_ssse3 then ecx = ecx | 0x00000200; // bit 9 (SSSE3) - if has_fma then ecx = ecx | 0x00001000; // bit 12 - if has_cx16 then ecx = ecx | 0x00002000; // bit 13 (CX16) - if has_sse4_1 then ecx = ecx | 0x00080000; // bit 19 (SSE4.1) - if has_sse4_2 then ecx = ecx | 0x00100000; // bit 20 (SSE4.2) - if has_movbe then ecx = ecx | 0x00400000; // bit 22 - if has_popcnt then ecx = ecx | 0x00800000; // bit 23 - if has_aesni then ecx = ecx | 0x02000000; // bit 25 - if has_xsave then ecx = ecx | 0x04000000; // bit 26 (XSAVE) - if CR4[18] == 0b1 then ecx = ecx | 0x08000000; // bit 27 (OSXSAVE) - if XCR0[2] == 0b1 then ecx = ecx | 0x10000000; // bit 28 (AVX) - if has_f16c then ecx = ecx | 0x20000000; // bit 29 - if has_rdrand then ecx = ecx | 0x40000000; // bit 30 - - // EDX: baseline features (FPU, VME, DE, PSE, TSC, MSR, PAE, MCE, CX8, - // APIC, SEP, MTRR, PGE, MCA, CMOV, PAT, PSE36, CLFLUSH, - // MMX, FXSR, SSE, SSE2) - let edx : dword = 0x078BFBFF; - (eax, ebx, ecx, edx) - }, - - // Leaf 2: Cache/TLB descriptors - 2 => (0x76036301, 0x00F0B5FF, 0x00000000, 0x00C30000), - - // Leaf 4: Deterministic cache parameters — no more caches - 4 => (0x00000000, 0x00000000, 0x00000000, 0x00000000), - - // Leaf 7: Structured extended feature flags - 7 => { - if sub_val == 0 then { - var ebx : dword = 0x00000000; - ebx = ebx | 0x00000200; // ERMS (bit 9) - if has_bmi1 then ebx = ebx | 0x00000008; // bit 3 - if XCR0[2] == 0b1 then ebx = ebx | 0x00000020; // AVX2 (bit 5) - if has_bmi2 then ebx = ebx | 0x00000100; // bit 8 - // AVX-512 (SDM Vol.1 Tables 21-19 to 21-22): each extension its - // own bit, from its own feature register (regs.sail). - if has_avx512f then ebx = ebx | 0x00010000; // bit 16 (AVX512F) - if has_avx512dq then ebx = ebx | 0x00020000; // bit 17 (AVX512DQ) - if has_avx512_ifma then ebx = ebx | 0x00200000; // bit 21 (AVX512_IFMA) - if has_avx512pf then ebx = ebx | 0x04000000; // bit 26 (AVX512PF) - if has_avx512er then ebx = ebx | 0x08000000; // bit 27 (AVX512ER) - if has_avx512cd then ebx = ebx | 0x10000000; // bit 28 (AVX512CD) - if has_avx512bw then ebx = ebx | 0x40000000; // bit 30 (AVX512BW) - if has_avx512vl then ebx = ebx | 0x80000000; // bit 31 (AVX512VL) - if has_rdseed then ebx = ebx | 0x00040000; // bit 18 - if has_adx then ebx = ebx | 0x00080000; // bit 19 - if has_smap then ebx = ebx | 0x00100000; // bit 20 (SMAP) - if has_ptwrite then ebx = ebx | 0x02000000; // bit 25 (Intel PT: leaf 14H) - if has_sha then ebx = ebx | 0x20000000; // bit 29 - // The x87 pointer rules (regs.sail): FDP_EXCPTN_ONLY (bit 6) and - // FCS_FDS_DEPRECATION (bit 13), reserved in the APM. - if has_fdp_excptn_only then ebx = ebx | 0x00000040; - if has_fcs_fds_deprecation then ebx = ebx | 0x00002000; - var ecx : dword = 0x00000000; - if has_avx512_vbmi then ecx = ecx | 0x00000002; // bit 1 (AVX512_VBMI) - if has_avx512_vbmi2 then ecx = ecx | 0x00000040; // bit 6 (AVX512_VBMI2) - if has_avx512_vnni then ecx = ecx | 0x00000800; // bit 11 (AVX512_VNNI) - if has_avx512_bitalg then ecx = ecx | 0x00001000; // bit 12 (AVX512_BITALG) - if has_avx512_vpopcntdq then ecx = ecx | 0x00004000; // bit 14 (AVX512_VPOPCNTDQ) - if has_waitpkg then ecx = ecx | 0x00000020; // bit 5 (WAITPKG) - if has_gfni then ecx = ecx | 0x00000100; // bit 8 (GFNI) - if has_vaes then ecx = ecx | 0x00000200; // bit 9 (VAES) - if has_vpclmulqdq then ecx = ecx | 0x00000400; // bit 10 (VPCLMULQDQ) - if has_la57 then ecx = ecx | 0x00010000; // bit 16 (LA57) - if has_rdpid then ecx = ecx | 0x00400000; // bit 22 (RDPID) - if has_cldemote then ecx = ecx | 0x02000000; // bit 25 (CLDEMOTE) - if has_movdiri then ecx = ecx | 0x08000000; // bit 27 - if has_movdir64b then ecx = ecx | 0x10000000; // bit 28 - if has_enqcmd then ecx = ecx | 0x20000000; // bit 29 (ENQCMD) - var edx : dword = 0x00000000; - if has_avx512_vp2intersect then edx = edx | 0x00000100; // bit 8 (AVX512_VP2INTERSECT) - if has_avx512_fp16 then edx = edx | 0x00800000; // bit 23 (AVX512_FP16) - if has_amx_bf16 then edx = edx | 0x00400000; // bit 22 (AMX-BF16) - if has_amx_tile then edx = edx | 0x01000000; // bit 24 (AMX-TILE) - if has_amx_int8 then edx = edx | 0x02000000; // bit 25 (AMX-INT8) - // EAX: maximum sub-leaf; sub-leaf 1 exists once something is in it - let max_sub : dword = if has_avx_vnni | has_avx512_bf16 then 0x00000001 else 0x00000000; - (max_sub, ebx, ecx, edx) - } else if sub_val == 1 then { - var eax : dword = 0x00000000; - if has_avx_vnni then eax = eax | 0x00000010; // bit 4 (AVX-VNNI) - if has_avx512_bf16 then eax = eax | 0x00000020; // bit 5 (AVX512_BF16) - (eax, 0x00000000, 0x00000000, 0x00000000) - } else { - (0x00000000, 0x00000000, 0x00000000, 0x00000000) - } - }, - - // Leaf 0xD: XSAVE state component info (SDM Table 21-36, Vol.1 §13.2) - 13 => match (has_xsave, sub_val) { - // EAX/EDX = XCR0_SUPPORTED - // EBX = standard size for currently enabled components (dynamic) - // ECX = max standard size for all supported components - (true, 0) => (XCR0_SUPPORTED[31..0], - xsave_area_size_standard(XCR0), - xsave_area_size_standard(XCR0_SUPPORTED), - XCR0_SUPPORTED[63..32]), - // EAX: XSAVEOPT(0), XSAVEC(1), XGETBV w/ ECX=1(2), XSAVES/XRSTORS(3), - // XFD(4) - // EBX = compacted size for XCR0 | IA32_XSS (dynamic), "If EAX[1] - // and EAX[3] are both enumerated as 0, EBX enumerates zero" - // ECX = supported IA32_XSS bits [31:0] (none) - // EDX = supported IA32_XSS bits [63:32] (none) - (true, 1) => { - var eax : dword = 0x00000000; - if has_xsaveopt then eax = eax | 0x00000001; - if has_xsavec then eax = eax | 0x00000002; - if has_xgetbv1 then eax = eax | 0x00000004; - if has_xsaves then eax = eax | 0x00000008; - if has_xfd then eax = eax | 0x00000010; - let ebx : dword = if has_xsavec | has_xsaves then xsave_area_size_compacted(XCR0) else 0x00000000; - (eax, ebx, 0x00000000, 0x00000000) - }, - // A user state component i of XCR0_SUPPORTED: EAX its size, EBX its - // standard-format offset, ECX[1] its 64-byte alignment in the - // compacted format and ECX[2] whether IA32_XFD can disable it (the - // model implements XFD for TILEDATA only). - (true, i) => if 2 <= i & i <= 18 then { - if XCR0_SUPPORTED[i] == bitone then { - let ecx : dword = (if xsave_comp_align[i] then 0x00000002 else 0x00000000) - | (if xfd_supported()[i] == bitone then 0x00000004 else 0x00000000); - (xsave_comp_size[i], xsave_comp_offset[i], ecx, 0x00000000) - } else (0x00000000, 0x00000000, 0x00000000, 0x00000000) - } else (0x00000000, 0x00000000, 0x00000000, 0x00000000), - _ => (0x00000000, 0x00000000, 0x00000000, 0x00000000) - }, - - // Leaf 0x1D: AMX tile information (SDM Table 21-65, 21-66). Sub-leaf 0 - // gives the highest palette, 1; sub-leaf 1 describes palette 1: 8192 - // bytes of tiles, 1024 per tile, 64 per row, 8 tile names, 16 rows. - 29 => match (has_amx_tile, sub_val) { - (true, 0) => (0x00000001, 0x00000000, 0x00000000, 0x00000000), - (true, 1) => (0x04002000, 0x00080040, 0x00000010, 0x00000000), - _ => (0x00000000, 0x00000000, 0x00000000, 0x00000000) - }, - - // Leaf 0x1E: TMUL information (SDM Table 21-67): tmul_maxk = 16 rows, - // tmul_maxn = 64 column bytes. - 30 => if has_amx_tile & sub_val == 0 then (0x00000000, 0x00004010, 0x00000000, 0x00000000) - else (0x00000000, 0x00000000, 0x00000000, 0x00000000), - - // Leaf 0x14: Intel PT (SDM Table 21-49), valid with CPUID.07H:EBX[25]. - // Sub-leaf 0: EAX the highest sub-leaf, EBX[4] PTWRITE; no trace - // output scheme (ECX = 0). - 20 => if has_ptwrite & sub_val == 0 then (0x00000000, 0x00000010, 0x00000000, 0x00000000) - else (0x00000000, 0x00000000, 0x00000000, 0x00000000), - - // Leaf 0x15: Time Stamp Counter / Core Crystal Clock - // EAX = denominator, EBX = numerator, ECX = crystal frequency (Hz) - // TSC freq = crystal_freq * numerator / denominator = 25MHz * 40 / 1 = 1GHz - 21 => (0x00000001, 0x00000028, 0x017D7840, 0x00000000), - - // Leaf 0x16: Processor Frequency Information (MHz) - // EAX = base freq, EBX = max freq, ECX = bus freq - 22 => (0x000003E8, 0x000003E8, 0x00000064, 0x00000000), - - // Leaf 0x80000000: Max extended leaf - 2147483648 => (0x80000008, 0x00000000, 0x00000000, 0x00000000), - - // Leaf 0x80000001: Extended feature bits - 2147483649 => { - // ECX: LAHF(0), conditionally LZCNT(5), SSE4A(6), MisAlignSse(7) - // and PREFETCHW(8) - var ecx : dword = 0x00000001; // LAHF - if has_lzcnt then ecx = ecx | 0x00000020; // bit 5 - if has_sse4a then ecx = ecx | 0x00000040; // bit 6 (AMD APM Vol.3 Appendix E) - if has_misalignsse then ecx = ecx | 0x00000080; // bit 7 (APM Vol.3 Appendix E) - if has_prefetchw then ecx = ecx | 0x00000100; // bit 8 - // EDX: SYSCALL(11), NX(20), LM(29) - let edx : dword = 0x20100800; - (0x00000000, 0x00000000, ecx, edx) - }, - - // Leaves 0x80000002-0x80000004: Processor brand string "Sail x86-64 Emulator" - 2147483650 => (0x6C696153, 0x36387820, 0x2034362D, 0x6C756D45), - 2147483651 => (0x726F7461, 0x00000000, 0x00000000, 0x00000000), - 2147483652 => (0x00000000, 0x00000000, 0x00000000, 0x00000000), - - // Leaf 0x80000007: Advanced power management — invariant TSC (bit 8) - 2147483655 => (0x00000000, 0x00000000, 0x00000000, 0x00000100), - - // Leaf 0x80000008: Address sizes - // EAX[7:0] = physical address bits (39), EAX[15:8] = virtual address bits - // Virtual: 57 with LA57, 48 without - // EBX[2] = RstrFpErrPtrs (has_rstr_fp_err_ptrs in regs.sail; reserved - // in the SDM) - 2147483656 => { - let virt_bits : dword = if has_la57 then 0x00003900 else 0x00003000; - let ebx : dword = if has_rstr_fp_err_ptrs then 0x00000004 else 0x00000000; - (virt_bits | 0x00000027, ebx, 0x00000000, 0x00000000) - }, - - // Unknown leaf: return zeros - _ => (0x00000000, 0x00000000, 0x00000000, 0x00000000), - } -} - -// SHLD — Double Precision Shift Left -// -// Shifts dst left by count, filling vacated bits from src (high bits). -// Equivalent to: result = upper_half(dst:src << count) -// If count=0, no operation. If count > operand_size, undefined. -// CF = last bit shifted out. SF, ZF, PF set from result. -// OF defined for count=1 (sign change). AF undefined. -val exec_shld : forall 'os, 'os in {16, 32, 64}. (implicit('os), bits('os), bits('os), byte) -> bits('os) -function exec_shld(os, d, s, count_raw) = { - let count : range(0, 63) = match os { - 64 => unsigned(count_raw) % 64, - _ => unsigned(count_raw) % 32, - }; - - let count_bv : bits(6) = to_bits(6, count); - let old_CF = CF; - let old_OF = OF; - let old_SF = SF; - let old_ZF = ZF; - let old_PF = PF; - let old_AF = AF; - - // Clamp count to [0, os] for valid computation; garbage for count > os is blended away - let clamped_bv : bits(7) = min_u(to_bits(7, count), to_bits(7, os)); - let clamped : range(0, 127) = unsigned(clamped_bv); - let cf_count = clamped + unsigned(is_zero(count_bv)); - assert(cf_count >= 1 & cf_count <= os); - let wide = d @ s; - let shifted = wide << clamped; - let r = shifted[(os * 2 - 1)..os]; - CF = wide[os * 2 - cf_count]; - update_SF_ZF_PF(r); - OF = r[os - 1] ^ d[os - 1]; - AF = undefined; - // OF defined only for count==1; undefined otherwise - OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); - - // count==0: restore old flags - let count_nz : bit = is_nonzero(count_bv); - CF = blend(old_CF, CF, count_nz); - OF = blend(old_OF, OF, count_nz); - SF = blend(old_SF, SF, count_nz); - ZF = blend(old_ZF, ZF, count_nz); - PF = blend(old_PF, PF, count_nz); - AF = blend(old_AF, AF, count_nz); - let result : bits('os) = blend(d, r, count_nz); - - // count > os: SDM says result and flags undefined - let count_gt_os : bit = is_gt_u(to_bits(7, count), to_bits(7, os)); - CF = blend(CF, undefined, count_gt_os); - OF = blend(OF, undefined, count_gt_os); - SF = blend(SF, undefined, count_gt_os); - ZF = blend(ZF, undefined, count_gt_os); - PF = blend(PF, undefined, count_gt_os); - AF = blend(AF, undefined, count_gt_os); - blend(result, undefined, count_gt_os) -} - -// SHRD — Double Precision Shift Right -// -// Shifts dst right by count, filling vacated bits from src (low bits). -// Equivalent to: result = lower_half(src:dst >> count) -// If count=0, no operation. If count > operand_size, undefined. -// CF = last bit shifted out. SF, ZF, PF set from result. -// OF defined for count=1 (sign change). AF undefined. -val exec_shrd : forall 'os, 'os in {16, 32, 64}. (implicit('os), bits('os), bits('os), byte) -> bits('os) -function exec_shrd(os, d, s, count_raw) = { - let count : range(0, 63) = match os { - 64 => unsigned(count_raw) % 64, - _ => unsigned(count_raw) % 32, - }; - - let count_bv : bits(6) = to_bits(6, count); - let old_CF = CF; - let old_OF = OF; - let old_SF = SF; - let old_ZF = ZF; - let old_PF = PF; - let old_AF = AF; - - // Clamp count to [0, os] for valid computation - let clamped_bv : bits(7) = min_u(to_bits(7, count), to_bits(7, os)); - let clamped : range(0, 127) = unsigned(clamped_bv); - let cf_count = clamped + unsigned(is_zero(count_bv)); - assert(cf_count >= 1 & cf_count <= 64); - let wide = s @ d; - let shifted = wide >> clamped; - let r = shifted[(os - 1)..0]; - let d_ext : bits(64) = zero_extend(d); - CF = d_ext[cf_count - 1]; - update_SF_ZF_PF(r); - OF = r[os - 1] ^ d[os - 1]; - AF = undefined; - // OF defined only for count==1; undefined otherwise - OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); - - // count==0: restore old flags - let count_nz : bit = is_nonzero(count_bv); - CF = blend(old_CF, CF, count_nz); - OF = blend(old_OF, OF, count_nz); - SF = blend(old_SF, SF, count_nz); - ZF = blend(old_ZF, ZF, count_nz); - PF = blend(old_PF, PF, count_nz); - AF = blend(old_AF, AF, count_nz); - let result : bits('os) = blend(d, r, count_nz); - - // count > os: SDM says result and flags undefined - let count_gt_os : bit = is_gt_u(to_bits(7, count), to_bits(7, os)); - CF = blend(CF, undefined, count_gt_os); - OF = blend(OF, undefined, count_gt_os); - SF = blend(SF, undefined, count_gt_os); - ZF = blend(ZF, undefined, count_gt_os); - PF = blend(PF, undefined, count_gt_os); - AF = blend(AF, undefined, count_gt_os); - blend(result, undefined, count_gt_os) -} - -// Adjust BT/BTS/BTR/BTC operands for memory bit string addressing. -// For register rm: bit index is masked to operand size (e.g., mod 64 for 64). -// For memory rm: the full signed bit offset indexes into an arbitrarily long -// bit string, so the effective address is displaced by (offset / op_bits) words. -// Returns (possibly-adjusted RM, bit number within the accessed word). -val bt_adjust : forall 'os, 'os in {16, 32, 64}. (implicit('os), RM, bits('os)) -> (RM, range(0, 'os - 1)) -function bt_adjust(os, rm, bit_idx) = { - match rm { - RM_reg(_) => { - let bit_num : range(0, 'os - 1) = unsigned(bit_idx) % os; - (rm, bit_num) - }, - RM_mem(m) => { - // Apply RIP-relative fixup first, before adding the bit string - // displacement. Otherwise fixup_addr would discard our adjustment. - let base_addr : qword = fixup_addr(m.addr); - rip_rel_pending = false; - - // For memory operands, the full signed bit offset indexes into a bit - // string starting at the effective address. Compute the word displacement - // (Euclidean: bit_num is always in [0, op_bits)). - let off = signed(bit_idx); - let r = rem_round_zero(off, os); - let q = quot_round_zero(off, os); - // Branchless Euclidean adjustment: sign = 0 when r >= 0, -1 when r < 0 - let r_bv : bits(7) = get_slice_int(7, r, 0); - let sign : int = negate(unsigned(r_bv[6])); - let byte_disp : int = (q + sign) * (os / 8); - let bit_num_int : int = r - sign * os; - let new_addr : qword = base_addr + get_slice_int(64, byte_disp, 0); - let bit_num : range(0, 63) = unsigned(get_slice_int(6, bit_num_int, 0)); - assert(bit_num < os); - (RM_mem(struct { seg = m.seg, addr = new_addr }), bit_num) - }, - } -} - -// TPAUSE r32, , (66 0F AE /6, mod = 11) and UMWAIT r32, , -// (F2 0F AE /6, mod = 11) — SDM Vol.2B; CPUID.07H.00H:ECX.WAITPKG[5]. -// The processor rests in the C0.1 or C0.2 state that bit 0 of the register -// selects until the TSC reaches EDX:EAX or, first, the limit the OS set in -// IA32_UMWAIT_CONTROL[31:2] (TSC quanta; 0 for no limit), and sets CF when -// the OS limit ended the wait; UMWAIT also wakes on a store to the UMONITOR -// range and does not rest at all when no monitor is armed. The model does -// not idle: a wait ends at once. "Other implementation-dependent events -// may also cause the processor to exit" (SDM Vol.2B UMWAIT p.4-739; TPAUSE -// lists NMI, SMI and the like, p.4-725) before the OS limit, so when the -// instruction would rest and the OS limit is the earlier deadline, CF is -// undefined; otherwise it is 0. AF, PF, SF, ZF and OF are cleared. -val exec_tpause_umwait : (GPRRef, bool) -> unit -function exec_tpause_umwait(r, is_umwait) = { - if ~(has_waitpkg) then raise_UD(); - let ctl : dword = v(32, r); - if ctl[31..1] != zeros() then raise_GP0(); - if CR4[2] == 0b1 & cur_cpl != 0 then raise_GP0(); - let limit : qword = zero_extend(__rdmsr(0x000000E1)[31..2] @ 0b00); - let tsc : qword = __rdtsc(); - let instr_deadline : qword = v(32, RDX) @ v(32, RAX); - let rests : bool = ~(is_umwait) | umonitor_armed; - let using_os_deadline : bool = limit != zeros() & (tsc + limit) <_u instr_deadline; - CF = if rests & using_os_deadline then undefined else 0b0; - OF = 0b0; - SF = 0b0; - ZF = 0b0; - AF = 0b0; - PF = 0b0; - if is_umwait then umonitor_armed = false -} - -// UMONITOR r16/r32/r64 (F3 0F AE /6, mod = 11): arm the monitor on the -// linear address of the effective address in the register, whose width is -// the address size; DS unless overridden. The SDM gives the instruction -// "the permission checking and faults associated with a byte load" -// (#GP(0) or #SS(0) for a non-canonical address, #PF), so the model reads -// a byte there; the monitored range itself is not tracked. -val exec_umonitor : (GPRRef, Prefixes) -> unit -function exec_umonitor(r, pfx) = { - if ~(has_waitpkg) then raise_UD(); - let ea : qword = match get_address_size(pfx) { - 16 => zero_extend(v(16, r)), - 32 => zero_extend(v(32, r)), - 64 => v(64, r), - }; - let _ : byte = read_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }); - umonitor_armed = true -} - -// The destination of MOVDIR64B, ENQCMD and ENQCMDS (66/F2/F3 0F 38 F8), -// translated for their 64-byte store. The register operand, at the -// address size, is an offset into ES, which no prefix overrides (SDM -// Vol.2B MOVDIR64B, Vol.2A ENQCMD). Segmentation checks the 64 bytes as -// any access (#GP(0) for a non-canonical address in 64-bit mode, beyond -// the ES limit outside it), the destination must be 64-byte aligned -// (#GP(0)), and the translation is a write's (#PF with W = 1), after a -// data breakpoint on writes has seen the access. MOVDIR64B is #GP(0) "If -// address in destination (register) operand is not aligned to a 64-byte -// boundary" (SDM Vol.2B 4-52; APM Vol.3 MOVDIR64B: "The destination -// operand was not 64-byte aligned"), the offset; ENQCMD and ENQCMDS "If -// destination linear address is not aligned" (SDM Vol.2A 3-290, 3-293), -// the ES base added: `linear_aligned` selects the second. The destination -// is not the ModR/M operand: a RIP-relative source's fixup in seg_linear -// must not move it. -val es_dest64_paddr : (Prefixes, GPRRef, bool) -> qword -function es_dest64_paddr(pfx, reg, linear_aligned) = { - rip_rel_pending = false; - let asz = get_address_size(pfx); - let offset : qword = zero_extend(v(asz, reg)); - let dst : MemRef = struct { seg = ES, addr = offset }; - let lin : qword = seg_linear(dst, 64); - let aligned : bits(6) = if linear_aligned then lin[5..0] else offset[5..0]; - if aligned != 0b000000 then raise_GP0(); - note_data_access(lin, 64, true); - translate_addr(lin, PT_Write) -} - -// MOVDIR64B r16/r32/r64, m512 (66 0F 38 F8 /r), mod != 11 — SDM Vol.2B; -// CPUID.07H.00H:ECX.MOVDIR64B[28]. It reads 64 bytes from the source, an -// ordinary load that need not be aligned, and writes them to the -// destination with one 64-byte direct store: "MOVDIR64B first reads -// 64-bytes from the source memory address. It then performs a 64-byte -// direct-store operation to the destination address" (SDM Vol.2B 4-51), -// so a fault on the source comes before one of the store (a non-canonical -// or unmapped destination). The exception lists give no order between a -// source fault and a misaligned destination, nor between that and the -// destination's translation; the model checks the alignment with the -// store, after the source is read and before the translation. -val exec_movdir64b : Prefixes -> unit -function exec_movdir64b(pfx) = { - if ~(has_movdir64b) then raise_UD(); - let (reg, src) = fetch_modrm(pfx); - let data : zmmword = rm_mem(src); - phys_write(es_dest64_paddr(pfx, reg, false), data) -} - -// ENQCMD r, m512 (F2 0F 38 F8 /r) and ENQCMDS r, m512 (F3 0F 38 F8 /r), -// mod != 11 — SDM Vol.2A; CPUID.07H.00H:ECX.ENQCMD[29]. Each reads 64 -// bytes of command data from the source (an ordinary load, no alignment) -// and sends a command built from them with an enqueue store to the -// destination, whose offset in ES (no override) is the register operand -// at the address size and whose linear address must be 64-byte aligned. -// ENQCMD requires a valid IA32_PASID and bits 31:0 of the source to be -// zero, in whose place the command gets the PASID and a privilege bit of -// 0 (user); ENQCMDS, CPL 0 only, requires bits 30:20 to be zero and sends -// the source as it is. The enqueue store returns a status in ZF: 0 when a -// device's enqueue register accepted the command, 1 (retry) otherwise, -// and "if the destination address was not an enqueue register (including -// the case of a memory address) ... the store is dropped and is written -// neither to MMIO nor to memory". The model has no device with an -// enqueue register, so a store that address translation lets through is -// dropped with ZF = 1; the other arithmetic flags are cleared. -// -// The order of the checks: ENQCMD reads the source only once IA32_PASID -// is valid ("IF IA32_PASID[31] = 0 THEN #GP; ELSE COMMAND := (SRC & ...", -// SDM Vol.2A 3-290, Operation), and in VMX non-root operation both -// instructions translate the PASID "only after checking for conditions -// that may result in general-protection exception (the check of -// IA32_PASID.Valid for ENQCMD; the privilege-level check for ENQCMDS), -// after loading the instruction's source operand from memory, and thus -// after any faults ... that the loading may cause", and "before the -// actual enqueue store and thus before any faults ... that it may cause" -// (SDM Vol.3C §28.3): the source's faults come before the store's. The -// rest the exception lists leave open, and the model chooses: ENQCMDS's -// CPL check before the source is read, the whole source read before its -// bits are checked, and the destination's alignment (with the store, as -// for MOVDIR64B) after the bits and before the translation, which is a -// write's (#PF with W = 1) and hits a data breakpoint on writes although -// the store is dropped. (The mod = 11 forms are URDMSR and UWRMSR with -// USER_MSR, CPUID.07H.01H:EDX[15], which the model does not implement: -// #UD.) -val exec_enqcmd : (Prefixes, bool) -> unit -function exec_enqcmd(pfx, supervisor) = { - if ~(has_enqcmd) then raise_UD(); - let (reg, src) = fetch_modrm(pfx); - let m : MemRef = match src { RM_mem(m) => m, RM_reg(_) => raise_UD() }; - if supervisor then { - if cur_cpl != 0 then raise_GP0() - } else { - if IA32_PASID[31] == bitzero then raise_GP0() - }; - let data : zmmword = read_mem(m); - if supervisor then { - if data[30..20] != zeros() then raise_GP0() - } else { - if data[31..0] != zeros() then raise_GP0() - }; - // COMMAND := (SRC & ~FFFFFFFFH) | (IA32_PASID & FFFFFH) for ENQCMD, - // DEST := SRC for ENQCMDS: the data a device's enqueue register would get. - let _command : zmmword = - if supervisor then data - else data[511..32] @ 0b000000000000 @ IA32_PASID[19..0]; - let _ = es_dest64_paddr(pfx, reg, true); - CF = 0b0; - PF = 0b0; - AF = 0b0; - ZF = 0b1; - SF = 0b0; - OF = 0b0 -} - -// CLFLUSH, CLFLUSHOPT and CLWB m8 change no architectural state, but each -// "is subject to all permission checking and faults associated with a byte -// load" and "like a load, ... sets the A bit but not the D bit" (SDM -// Vol.2A CLFLUSH, CLFLUSHOPT, CLWB): the segment and canonical checks of a -// byte at m, and the translation of a read. -val cache_line_access : MemRef -> unit -function cache_line_access(m) = { - let _ = translate_addr(seg_linear(m, 1), PT_Read); - () -} - -// ========================================================================= -// Fast system calls: SYSCALL, SYSRET, SYSENTER and SYSEXIT -// -// The manuals define them in different modes. The SDM defines SYSCALL and -// SYSRET in 64-bit mode only ("not recognized" elsewhere, #UD) and SYSENTER -// and SYSEXIT in every protected mode; the APM defines SYSCALL and SYSRET -// in every mode and SYSENTER and SYSEXIT outside long mode only (#UD in -// it). The model executes each instruction wherever a manual defines it, -// as that manual gives it, and where both define it but give different -// values, the value is undefined: either manual's, `if (undefined : bool) -// then else `, of which the emulator, whose -// undefined values are false and zeros, takes the SDM's. -// ========================================================================= - -// The flat segments the fast system calls load into the CS and SS -// descriptor caches in place of the descriptors their selectors name: base -// 0, a 4-GByte limit, execute/read or read/write data, accessed, S = 1, -// P = 1, G = 1, and CS.L and CS.D for 64-bit or 32-bit code. -val fast_call_code : (range(0, 3), bool) -> SegDescCache -function fast_call_code(dpl, long) = struct { - seg_base = 0x0000000000000000, - seg_limit = 0xFFFFFFFF, - seg_type = 0xB, - seg_s = 0b1, - seg_dpl = dpl, - seg_present = 0b1, - seg_db = if long then 0b0 else 0b1, - seg_l = if long then 0b1 else 0b0, - seg_g = 0b1, -} - -val fast_call_stack : range(0, 3) -> SegDescCache -function fast_call_stack(dpl) = struct { - seg_base = 0x0000000000000000, - seg_limit = 0xFFFFFFFF, - seg_type = 0x3, - seg_s = 0b1, - seg_dpl = dpl, - seg_present = 0b1, - seg_db = 0b1, - seg_l = 0b0, - seg_g = 0b1, -} - -// SYSCALL in system mode, after the IA32_EFER.SCE check both manuals make -// first. In IA-32e mode, the APM's SYSCALL_LONG_MODE (Vol.3 SYSCALL -// p.486): RCX := the next RIP, R11 := RFLAGS, RFLAGS &= ~SFMASK, CS and SS -// from STAR[47:32] with fixed 64-bit code and stack at CPL 0, and RIP := -// LSTAR from 64-bit mode and CSTAR from compatibility mode ("temp_RIP.q = -// MSR_CSTAR", "Always switch to 64-bit mode in long mode"). The SDM's -// SYSCALL is the 64-bit-mode part of it (Vol.2B SYSCALL 4-698: "IF -// IA32_EFER.LMA = 0 OR CS.L = 0 ... THEN #UD"). Outside IA-32e mode, the -// APM's SYSCALL_LEGACY_MODE (p.487), in real, virtual-8086 and protected -// mode alike ("There are no permission checks based on the CPL, real -// mode, or virtual-8086 mode", p.484): "RCX.d = next_RIP; temp_RIP.d = -// MSR_STAR.EIP; CS.sel = MSR_STAR.SYSCALL_CS AND 0xFFFC; CS.attr = 32-bit -// code,dpl0 ... SS.sel = MSR_STAR.SYSCALL_CS + 8; SS.attr = 32-bit -// stack,dpl0 ... RFLAGS.VM,IF,RF=0; CPL = 0", with no R11 or SFMASK. -// RF is clear here already (the fetch clears it), as both leave it. -val exec_syscall : unit -> unit -function exec_syscall() = { - let star : qword = __rdmsr(0xC0000081); - let flags = read_rflags(); - write_segreg(CS, star[47..32] & 0xFFFC); - write_segreg(SS, star[47..32] + 0x0008); - SegCache[SS] = fast_call_stack(0); - cur_cpl = 0; - if EFER[10] == 0b1 then { - v(RCX) = decode_pos; - // RF in the saved RFLAGS, where the manuals differ: "R11 := RFLAGS" - // (SDM, 4-699), "R11.q = RFLAGS // with rf cleared" (APM, p.486). (The - // model's fetch clears RF before the instruction executes, so it is 0 - // in `flags`.) - v(R11) = if (undefined : bool) then flags & ~(0x0000000000010000) else flags; - let fmask : qword = __rdmsr(0xC0000084); - write_rflags(flags & ~(fmask)); - if fmask[19] == bitone then VIF = bitzero; - if fmask[20] == bitone then VIP = bitzero; - let target : qword = __rdmsr(if cur_mode == LongMode then 0xC0000082 else 0xC0000083); - SegCache[CS] = fast_call_code(0, true); - cur_mode = LongMode; - next_rip = Some(target) - } else { - v(32, RCX) = decode_pos[31..0]; - IF_flag = bitzero; - SegCache[CS] = fast_call_code(0, false); - if cur_mode == Virtual8086Mode then cur_mode = ProtectedMode; - next_rip = Some(zero_extend(star[31..0])) - } -} - -// SYSRET. The SDM (Vol.2B SYSRET 4-709) has #UD unless in 64-bit mode -// with IA32_EFER.SCE = 1, then "IF (CPL ≠ 0) THEN #GP(0)". The APM (Vol.3 -// SYSRET pp.493-495) has #UD for SCE = 0, then "IF ((!PROTECTED_MODE) || -// (CPL != 0)) EXCEPTION [#GP(0)]", and executes SYSRET_64BIT_MODE in -// 64-bit mode and SYSRET_NON_64BIT_MODE in legacy protected and -// compatibility mode. Where the SDM's #UD meets the APM's #GP(0), in real -// and virtual-8086 mode and at CPL > 0 outside 64-bit mode, the vectors -// differ; the model raises the APM's, as the manual that defines SYSRET -// there. -val exec_sysret : Prefixes -> unit -function exec_sysret(pfx) = { - if EFER[0] != 0b1 then raise_UD(); - if cur_mode == RealMode | cur_mode == Virtual8086Mode | cur_cpl != 0 then raise_GP0(); - let star : qword = __rdmsr(0xC0000081); - let sysret_cs : word = star[63..48]; - if cur_mode == LongMode then { - // With a 64-bit operand size RIP := RCX, else RIP := ECX. The SDM - // checks RCX first, "IF (RCX is not canonical) THEN #GP(0)"; the APM - // does not ("temp_RIP.q = RCX", p.494), and its processor returns to - // CPL 3 and faults on the fetch there: "Attempting to execute code - // ... at a non-canonical RIP" is #GP(0) (Vol.2 §8.2.14, Table 8-6, - // p.256). The model follows the APM, the fetch raising the #GP. - let new_rip : qword = if pfx.rex_w then v(RCX) else zero_extend(v(32, RCX)); - // "RFLAGS := (R11 & 3C7FD7H) | 2" (SDM), "RFLAGS.q = R11 // RF=0,VM=0" - // (APM): R11 but for RF, VM and the reserved bits, VIF and VIP included. - let r11 : qword = v(R11); - write_rflags((r11 & 0x00000000003C7FD7) | 0x0000000000000002); - VIF = r11[19]; - VIP = r11[20]; - // "CS.Selector := CS.Selector OR 3; (* RPL forced to 3 *)" (SDM), - // "CS.sel = (MSR_STAR.SYSRET_CS + 16) OR 3" or "MSR_STAR.SYSRET_CS OR - // 3" (APM), with fixed 64-bit or 32-bit code at DPL 3. - write_segreg(CS, (if pfx.rex_w then sysret_cs + 0x0010 else sysret_cs) | 0x0003); - SegCache[CS] = fast_call_code(3, pfx.rex_w); - // SS, where the manuals differ. The SDM forces the RPL to 3 and loads - // fixed values: "SS.Selector := (IA32_STAR[63:48]+8) OR 3; ... SS.Base - // := 0; SS.Limit := FFFFFH; SS.Type := 3; SS.S := 1; SS.DPL := 3; SS.P - // := 1; SS.B := 1; SS.G := 1". The APM loads the selector alone, - // "SS.sel = MSR_STAR.SYSRET_CS + 8 // SS selector is changed, // SS - // base, limit, attributes unchanged" (p.494), "and its RPL is not - // forced to 3" (p.492). - let apm_ss : bool = undefined; - write_segreg(SS, if apm_ss then sysret_cs + 0x0008 else (sysret_cs + 0x0008) | 0x0003); - if ~(apm_ss) then SegCache[SS] = fast_call_stack(3); - cur_cpl = 3; - set_mode(if pfx.rex_w then LongMode else CompatibilityMode); - next_rip = Some(new_rip) - } else { - // SYSRET_NON_64BIT_MODE (APM p.494): "CS.sel = MSR_STAR.SYSRET_CS OR 3 - // ... CS.attr = 32-bit code,dpl3; temp_RIP.d = RCX; SS.sel = - // MSR_STAR.SYSRET_CS + 8 // SS selector is changed. // SS base, limit, - // attributes unchanged. RFLAGS.IF = 1; CPL = 3". - write_segreg(CS, sysret_cs | 0x0003); - SegCache[CS] = fast_call_code(3, false); - write_segreg(SS, sysret_cs + 0x0008); - IF_flag = bitone; - cur_cpl = 3; - next_rip = Some(zero_extend(v(32, RCX))) - } -} - -// SYSENTER. SDM Vol.2B SYSENTER (4-702): "IF CR0.PE = 0 OR (... -// IA32_SYSENTER_CS[15:2] = 0) THEN #GP(0)", then "RFLAGS.VM := 0; -// RFLAGS.IF := 0", RSP := IA32_SYSENTER_ESP and RIP := IA32_SYSENTER_EIP -// (bits 31:0 outside IA-32e mode), CS := IA32_SYSENTER_CS[15:0] AND FFFCH -// and SS := CS + 8 with fixed code and stack at CPL 0, and 64-bit mode in -// IA-32e mode ("When executed in IA-32e mode, the SYSENTER instruction -// transitions the logical processor to 64-bit mode; otherwise, the logical -// processor remains in protected mode", 4-701). The APM gives the same -// outside long mode (Vol.3 SYSENTER pp.488-489: "If SYSENTER is used in -// real mode, a #GP is raised", #GP if "MSR_SYSENTER_CS was a null -// selector", VM and IF cleared) and makes SYSENTER #UD in long mode ("An -// invalid-opcode exception occurs if this instruction is used in long -// mode"), where the model executes the SDM's. -val exec_sysenter : unit -> unit -function exec_sysenter() = { - let sysenter_cs : qword = __rdmsr(0x00000174); - if CR0[0] == 0b0 | sysenter_cs[15..2] == zeros() then raise_GP0(); - let ia32e : bool = EFER[10] == 0b1; - // The selectors outside long mode, where the manuals differ: the SDM - // forces the RPL to 0, "CS.Selector := IA32_SYSENTER_CS[15:0] AND FFFCH" - // and "SS.Selector := CS.Selector + 8"; the APM takes "MSR_SYSENTER_CS: - // Contains the CS selector of the called procedure. The SS selector is - // set to MSR_SYSENTER_CS + 8" (p.488). - let cs_sel : word = if ~(ia32e) & (undefined : bool) then sysenter_cs[15..0] - else sysenter_cs[15..0] & 0xFFFC; - write_segreg(CS, cs_sel); - SegCache[CS] = fast_call_code(0, ia32e); - write_segreg(SS, cs_sel + 0x0008); - SegCache[SS] = fast_call_stack(0); - cur_cpl = 0; - // Leaving virtual-8086 mode clears VM. - cur_mode = if ia32e then LongMode else ProtectedMode; - IF_flag = 0b0; - let sysenter_esp : qword = __rdmsr(0x00000175); - let sysenter_eip : qword = __rdmsr(0x00000176); - v(RSP) = if ia32e then sysenter_esp else zero_extend(sysenter_esp[31..0]); - next_rip = Some(if ia32e then sysenter_eip else zero_extend(sysenter_eip[31..0])) -} - -// SYSEXIT. SDM Vol.2B SYSEXIT (4-706): "IF IA32_SYSENTER_CS[15:2] = 0 OR -// CR0.PE = 0 OR CPL ≠ 0 THEN #GP(0)", which in virtual-8086 mode, at CPL -// 3, is "#GP(0) The SYSEXIT instruction is not recognized in virtual-8086 -// mode" (4-707); with a 64-bit operand size also "If RCX or RDX contains a -// non-canonical address" (64-Bit Mode Exceptions). Then RSP := RCX and -// RIP := RDX (ECX and EDX without REX.W), CS := IA32_SYSENTER_CS + 32 (64- -// bit operand size) or + 16, RPL forced to 3, and SS := CS + 8, with fixed -// code and stack at CPL 3; 64-bit mode with REX.W, else compatibility mode -// in IA-32e mode and protected mode outside it. The APM's exception table -// (Vol.3 SYSEXIT p.491) has the same #GP cases outside long mode ("This -// instruction is only recognized in protected mode" for real and -// virtual-8086 mode, "CPL was not 0", "MSR_SYSENTER_CS was a null -// selector") and #UD in long mode, where the model executes the SDM's. -// -// The SDM's 64-bit-mode list has "#GP(0) If IA32_SYSENTER_CS = 0" where -// its Operation section has bits 15:2: for IA32_SYSENTER_CS from 1 to 3 in -// 64-bit mode the SDM gives both a #GP(0) and the return. The model -// follows the Operation section, the instruction's definition. -val exec_sysexit : Prefixes -> unit -function exec_sysexit(pfx) = { - let sysenter_cs : qword = __rdmsr(0x00000174); - if sysenter_cs[15..2] == zeros() | CR0[0] == 0b0 | cur_cpl != 0 then raise_GP0(); - if pfx.rex_w & ~(is_canonical_linear(v(64, RCX)) & is_canonical_linear(v(64, RDX))) then raise_GP0(); - // The selectors outside long mode, where the manuals differ: the SDM - // forces the RPL to 3, "CS.Selector := CS.Selector OR 3" and - // "SS.Selector := CS.Selector + 8"; the APM gives them as "MSR - // SYSENTER_CS+16" and "MSR SYSENTER_CS+24" (p.490). - let base : word = sysenter_cs[15..0] + (if pfx.rex_w then 0x0020 else 0x0010); - let cs_sel : word = if EFER[10] == 0b0 & (undefined : bool) then base else base | 0x0003; - write_segreg(CS, cs_sel); - SegCache[CS] = fast_call_code(3, pfx.rex_w); - write_segreg(SS, cs_sel + 0x0008); - SegCache[SS] = fast_call_stack(3); - cur_cpl = 3; - if pfx.rex_w then { - cur_mode = LongMode; - v(RSP) = v(64, RCX); - next_rip = Some(v(64, RDX)) - } else { - set_mode(if EFER[10] == 0b1 then CompatibilityMode else ProtectedMode); - v(32, RSP) = v(32, RCX); - next_rip = Some(zero_extend(v(32, RDX))) - } -} - -val dispatch_2byte_gpr : (range(0, 255), Prefixes) -> unit -function dispatch_2byte_gpr(op, pfx) = { - // Descriptor-query/task-register instructions are not recognized in - // virtual-8086 mode (SDM Vol.2 SLDT/STR/LLDT/LTR/VERR/VERW/LAR/LSL). - if cur_mode == Virtual8086Mode & (op == 0 | op == 2 | op == 3) then raise_UD(); - match op { - // 0F 00: Group 6 (SLDT, STR, LLDT, LTR, VERR, VERW) - 0 => { - let modrm = fetch(1); - let reg_field : range(0, 7) = unsigned(modrm[5..3]); - match reg_field { - // 0F 00 /0: SLDT r/m16 — Store LDTR - 0 => { - let dest = modrm_rm(modrm, pfx); - match dest { - RM_reg(r) => v(r) = LDTR, - RM_mem(m) => v(m) = LDTR, - } - }, - - // 0F 00 /1: STR r/m16 — Store Task Register - 1 => { - let dest = modrm_rm(modrm, pfx); - match dest { - RM_reg(r) => v(r) = TR, - RM_mem(m) => v(m) = TR, - } - }, - - // 0F 00 /2: LLDT r/m16 — Load LDT Register (requires CPL=0) - 2 => { - if cur_mode == RealMode then raise_UD(); - if cur_cpl != 0 then raise_GP0(); - let src = modrm_rm(modrm, pfx); - let sel : word = v(src); - if sel[15..2] == zeros() then { - LDTR = sel; - LDTR_valid = false - } else { - let err = selector_error_code(sel); - let off : qword = zero_extend(sel & 0xFFF8); - let size : int = if EFER[10] == 0b1 then 16 else 8; - if sel[2] == 0b1 | unsigned(off) + size - 1 > unsigned(GDTR_limit) then raise_GP(err); - let lo : dword = read_mem_implicit(GDTR_base + off); - let hi : dword = read_mem_implicit(GDTR_base + off + 4); - let desc = parse_seg_descriptor(lo, hi); - if desc.seg_s == 0b1 | desc.seg_type != 0x2 then raise_GP(err); - if desc.seg_present == 0b0 then throw Fault(EXN_NP, err); - var base = desc.seg_base; - if EFER[10] == 0b1 then { - let upper : dword = read_mem_implicit(GDTR_base + off + 8); - base = upper @ base[31..0] - }; - LDTR = sel; - LDTR_base = base; - LDTR_limit = desc.seg_limit; - LDTR_valid = true - } - }, - - // 0F 00 /3: LTR r/m16 — Load Task Register (SDM Vol.2A LTR) - 3 => { - // Not recognized in real-address mode; CPL must be 0. - if cur_mode == RealMode then raise_UD(); - if cur_cpl != 0 then raise_GP0(); - let src = modrm_rm(modrm, pfx); - let sel : word = v(src); - // Operation: a null selector is #GP(0); an LDT selector or an - // index beyond the GDT limit is #GP(selector), before the - // descriptor is read. In 64-bit mode the TSS descriptor is - // 16 bytes. - if (sel & 0xFFFC) == zeros() then raise_GP0(); - let err : dword = selector_error_code(sel); - if sel[2] == 0b1 then raise_GP(err); - let desc_off : qword = zero_extend(sel & 0xFFF8); - let desc_size : int = if cur_mode == LongMode then 16 else 8; - if unsigned(desc_off) + desc_size - 1 > unsigned(GDTR_limit) then raise_GP(err); - // Implicit supervisor reads of the descriptor. - let desc_addr : qword = GDTR_base + desc_off; - let desc_lo : dword = read_mem_implicit(desc_addr); - let desc_hi : dword = read_mem_implicit(desc_addr + 4); - // An available TSS is a system descriptor (S = 0) of type 1001B - // (32/64-bit) or, in protected mode only, 0001B (16-bit); a - // busy TSS or any other descriptor is #GP(selector), and a - // descriptor that is not present is #NP(selector). - let typ : bits(4) = desc_hi[11..8]; - let available_tss : bool = - desc_hi[12] == 0b0 & (typ == 0x9 | (typ == 0x1 & cur_mode == ProtectedMode)); - if ~(available_tss) then raise_GP(err); - if desc_hi[15] == 0b0 then throw Fault(EXN_NP, err); - // Base = desc[63:56] @ desc[39:32] @ desc[31:16], extended by the - // upper 8 bytes in 64-bit mode, whose type field must be zero. - var base : qword = zero_extend(desc_hi[31..24] @ desc_hi[7..0] @ desc_lo[31..16]); - if cur_mode == LongMode then { - let ext_lo : dword = read_mem_implicit(desc_addr + 8); - let ext_hi : dword = read_mem_implicit(desc_addr + 12); - if ext_hi[12..8] != 0b00000 then raise_GP(err); - base = ext_lo @ base[31..0] - }; - // Limit = desc[51:48] @ desc[15:0] (with granularity) - let raw_limit : bits(20) = desc_hi[19..16] @ desc_lo[15..0]; - let limit : dword = if desc_hi[23] == 0b1 then zero_extend(raw_limit) @ 0xFFF - else zero_extend(raw_limit); - // TSSsegmentDescriptor(busy) := 1: type bit 1 of the descriptor in - // memory, then the task register itself. - write_mem_linear(desc_addr + 4, desc_hi | 0x00000200); - TR = sel; - TR_base = base; - TR_limit = limit; - TR_type = typ | 0x2 - }, - - // 0F 00 /4: VERR r/m16 — Verify segment readable, set ZF - 4 => { - let src = modrm_rm(modrm, pfx); - let selector : word = v(src); - if (selector & 0xFFFC) == zeros() then { - ZF = 0b0 - } else { - let desc_addr = descriptor_address(selector); - if ~(descriptor_in_bounds(selector)) then { - ZF = 0b0 - } else { - let desc_hi : dword = read_mem_implicit(desc_addr + 4); - let present : bit = desc_hi[15]; - let s_bit : bit = desc_hi[12]; - // Readable: data segments always readable; code readable if R bit set - let is_code : bit = desc_hi[11]; - let readable : bit = desc_hi[9] | ~(is_code); - if present == 0b0 | s_bit == 0b0 | readable == 0b0 - | ~(desc_privilege_ok(desc_hi, selector)) then { - ZF = 0b0 - } else { - ZF = 0b1 - } - } - } - }, - - // 0F 00 /5: VERW r/m16 — Verify segment writable, set ZF - 5 => { - let src = modrm_rm(modrm, pfx); - let selector : word = v(src); - if (selector & 0xFFFC) == zeros() then { - ZF = 0b0 - } else { - let desc_addr = descriptor_address(selector); - if ~(descriptor_in_bounds(selector)) then { - ZF = 0b0 - } else { - let desc_hi : dword = read_mem_implicit(desc_addr + 4); - let present : bit = desc_hi[15]; - let s_bit : bit = desc_hi[12]; - let is_code : bit = desc_hi[11]; - // Writable: only data segments with W bit set - let writable : bit = desc_hi[9] & ~(is_code); - if present == 0b0 | s_bit == 0b0 | writable == 0b0 - | ~(desc_privilege_ok(desc_hi, selector)) then { - ZF = 0b0 - } else { - ZF = 0b1 - } - } - } - }, - _ => raise_UD(), - } - }, - - // 0F 01: Group 7 (privileged/system instructions) - 1 => { - let modrm = fetch(1); - let modrm_val : range(0, 255) = unsigned(modrm); - let reg_field : range(0, 7) = unsigned(modrm[5..3]); - let mod_field : range(0, 3) = unsigned(modrm[7..6]); - - match modrm_val { - // 0F 01 D1: XSETBV — Write XCR (ECX selects register, EDX:EAX = value) - // SDM: #GP(0) if CPL > 0; #GP(0) if ECX != 0 (only XCR0 exists); - // #GP(0) if attempting to set unsupported bits or violating constraints. - // Unconditional VM exit in non-root (SDM §26.1.2), after the #UD of - // the XSAVE feature set ("invalid-opcode exceptions" "have priority - // over VM exits", Vol.3C §28.1.1 p.28-1). - 209 => { - check_xsave_enabled(true); - vmx_exit_xsetbv(); - if cur_cpl != 0 then raise_GP0(); - let ecx_val : dword = v(RCX); - if ecx_val != 0x00000000 then raise_GP0(); - let new_xcr0 : qword = v(32, RDX) @ v(32, RAX); - // Any bit set that is not in XCR0_SUPPORTED → #GP - if (new_xcr0 & ~(XCR0_SUPPORTED)) != zeros() then raise_GP0(); - // Bit 0 (x87) must always be 1 - if new_xcr0[0] == 0b0 then raise_GP0(); - // Can't set AVX (bit 2) without SSE (bit 1) - if new_xcr0[2..1] == 0b10 then raise_GP0(); - // Bits 7:5 (AVX-512) must be all-or-nothing, and require bits 2:1 - let avx512_bits : bits(3) = new_xcr0[7..5]; - if avx512_bits != 0b000 & avx512_bits != 0b111 then raise_GP0(); - if avx512_bits == 0b111 & (new_xcr0[2] == 0b0 | new_xcr0[1] == 0b0) then raise_GP0(); - // Bits 18:17 (AMX) must be both-or-neither - if new_xcr0[17] != new_xcr0[18] then raise_GP0(); - XCR0 = new_xcr0 - }, - - // 0F 01 D0: XGETBV — Read XCR0. ECX = 1 (CPUID.(0DH,1):EAX[2]) - // returns "the logical-AND of XCR0 and the current value of the - // XINUSE state-component bitmap" (SDM XGETBV; APM Vol.4 XGETBV - // p.1763). The SDM's "always sets EAX[1] to 1 if XCR0[1] = 1 and - // MXCSR does not have its RESET value of 1F80H" (Vol.1 §13.6 - // p.13-18) the APM does not have, so EAX[1] is undefined then - // (XINUSE[1] or 1), and the emulator takes the SDM's 1. Any other - // ECX is #GP(0), which "includes ECX = 1 if - // CPUID.0DH.01H:EAX.XGETBV1[2] = 0". - 208 => { - check_xsave_enabled(true); - let ecx_val : dword = v(RCX); - if ecx_val == 0x00000000 | (ecx_val == 0x00000001 & has_xgetbv1) then { - var xcr : qword = XCR0; - if ecx_val == 0x00000001 then { - xcr = XCR0 & xinuse(); - if XCR0[1] == bitone & __stmxcsr() != 0x00001F80 then - xcr[1] = if (undefined : bool) then xcr[1] else bitone - }; - v(RAX) = xcr[31..0]; - v(RDX) = xcr[63..32] - } else { - raise_GP0() - } - }, - - // 0F 01 CA: CLAC — Clear AC flag (SMAP). With F2 the encoding is - // ERETS and with F3 ERETU (SDM Vol.2A: FRED event returns), which - // the model does not implement: #UD, as on a processor without FRED. - // CLAC and STAC are #UD "If the CPL > 0", "If - // CPUID.07H.00H:EBX.SMAP[20] = 0", and in virtual-8086 mode, "not - // recognized" there (SDM Vol.2A CLAC 3-139, Vol.2B STAC 4-670); the - // APM has the same three (Vol.3 CLAC p.381, STAC p.477: "Instruction - // not supported by CPUID", "Instruction is not supported in virtual - // mode", "CPL was not 0"). - 202 => { - if pfx.has_rep | pfx.has_repne then raise_UD(); - if ~(has_smap) | cur_mode == Virtual8086Mode | cur_cpl != 0 then raise_UD(); - AC_flag = 0b0 - }, - - // 0F 01 CB: STAC — Set AC flag (SMAP) - 203 => { - if ~(has_smap) | cur_mode == Virtual8086Mode | cur_cpl != 0 then raise_UD(); - AC_flag = 0b1 - }, - - // 0F 01 E8: SERIALIZE — NOP in sequential interpreter - 232 => (), - - // 0F 01 EE: RDPKRU — Read Protection Key Rights (ECX must be 0) - // Returns PKRU in EAX, 0 in EDX. We don't implement PKU, so - // return 0 (all access allowed). F3 0F 01 EE is CLUI (SDM - // Vol.2A: "#UD if CPUID.07H.00H:EDX.UINTR[5] = 0"), not implemented. - 238 => { - if pfx.has_rep then raise_UD(); - v(RAX) = 0x00000000; - v(RDX) = 0x00000000 - }, - - // 0F 01 EF: WRPKRU — Write Protection Key Rights (NOP, no PKU). - // F3 0F 01 EF is STUI (UINTR), not implemented: #UD. - 239 => { - if pfx.has_rep then raise_UD() - }, - - // 0F 01 F9: RDTSCP — Read TSC and IA32_TSC_AUX - // SDM: #GP(0) if CR4.TSD (bit 2) = 1 and CPL > 0 - 249 => { - if CR4[2] == 0b1 & cur_cpl != 0 then raise_GP0(); - vmx_exit_if_rdtscp(); - let tsc = __rdtsc(); - v(RAX) = tsc[31..0]; - v(RDX) = tsc[63..32]; - v(RCX) = __rdmsr(0xC0000103)[31..0] - }, - - // 0F 01 C1: VMCALL (SDM Vol.3C §31.2.6) - 193 => exec_vmcall(), - - // 0F 01 C2: VMLAUNCH (SDM Vol.3C §31.2.7) - 194 => exec_vmlaunch(), - - // 0F 01 C3: VMRESUME (SDM Vol.3C §31.2.7) - 195 => exec_vmresume(), - - // 0F 01 C4: VMXOFF (SDM Vol.3C §31.2.2) - 196 => { - vmx_exit_vmx_insn(VMEXIT_VMXOFF); - exec_vmxoff() - }, - - // 0F 01 F8: SWAPGS, in 64-bit mode at CPL 0: "IF CS.L ≠ 1 (* Not - // in 64-Bit Mode *) ... THEN #UD; FI; IF CPL ≠ 0 THEN #GP(0)" (SDM - // Vol.2B SWAPGS 4-696); "Executing SWAPGS in any other mode - // generates an undefined opcode exception" (APM Vol.3 SWAPGS p.482). - 248 => { - if cur_mode != LongMode then raise_UD(); - if cur_cpl != 0 then raise_GP0(); - let tmp = SegCache[GS].seg_base; - SegCache[GS].seg_base = KERNEL_GS_BASE; - KERNEL_GS_BASE = tmp - }, - - _ => { - // Group 7: dispatch by reg_field, then check memory vs register - let dest = modrm_rm(modrm, pfx); - match reg_field { - // 0F 01 /0: SGDT m — Store GDTR (memory only) - // Non-64-bit: 6 bytes (2 limit + 4 base). - // 64-bit: 10 bytes (2 limit + 8 base). SDM Vol.2A LGDT/LIDT. - 0 => match dest { - RM_mem(m) => { - if cur_mode == LongMode then - write_mem(80, m, GDTR_base @ GDTR_limit) - else - write_mem(48, m, GDTR_base[31..0] @ GDTR_limit) - }, - RM_reg(_) => raise_UD(), - }, - - // 0F 01 /1: SIDT m — Store IDTR (memory only) - 1 => match dest { - RM_mem(m) => { - if cur_mode == LongMode then - write_mem(80, m, IDTR_base @ IDTR_limit) - else - write_mem(48, m, IDTR_base[31..0] @ IDTR_limit) - }, - RM_reg(_) => raise_UD(), - }, - - // 0F 01 /2: LGDT m — Load GDTR (memory only, requires CPL=0) - // SDM Vol.2A §LGDT Operation: - // 16: Limit := SRC[0:15]; Base := SRC[16:47] AND 00FFFFFFH; - // 32: Limit := SRC[0:15]; Base := SRC[16:47]; - // 64: Limit := SRC[0:15]; Base := SRC[16:79]; - // 16 and 32 both read 6 bytes (2 limit + 4 base); 16 - // masks the base to 24 bits. 64 reads 10 bytes (2 + 8). - // In 64-bit mode, the operand size is forced to 64-bit - // regardless of REX.W (SDM: "In 64-bit mode, the instruction's - // operand size is fixed at 8+2 bytes"). - 2 => { - if cur_cpl != 0 then raise_GP0(); - match dest { - RM_mem(m) => { - if cur_mode == LongMode then { - let d : bits(80) = read_mem(m); - GDTR_base = d[79..16]; - GDTR_limit = d[15..0] - } else { - let d : bits(48) = read_mem(m); - GDTR_base = if opsize(pfx) == 16 - then zero_extend(d[39..16]) - else zero_extend(d[47..16]); - GDTR_limit = d[15..0] - } - }, - RM_reg(_) => raise_UD(), - } - }, - - // 0F 01 /3: LIDT m — Load IDTR (memory only, requires CPL=0) - // Same operand-size semantics as LGDT. - 3 => { - if cur_cpl != 0 then raise_GP0(); - match dest { - RM_mem(m) => { - if cur_mode == LongMode then { - let d : bits(80) = read_mem(m); - IDTR_base = d[79..16]; - IDTR_limit = d[15..0] - } else { - let d : bits(48) = read_mem(m); - IDTR_base = if opsize(pfx) == 16 - then zero_extend(d[39..16]) - else zero_extend(d[47..16]); - IDTR_limit = d[15..0] - } - }, - RM_reg(_) => raise_UD(), - } - }, - - // 0F 01 /4: SMSW r/m16 — Store Machine Status Word - // No privilege check required (accessible from any CPL). - // SDM: stores low 16 bits of CR0 to r/m16. With 32-bit - // register operand, stores low 32 bits; with 64-bit, all 64. - // Outside 64-bit mode "when the destination operand is a - // 32-bit register, the low-order 16 bits of register CR0 are - // copied into the low-order 16 bits of the register and the - // high-order 16 bits are undefined" (SDM Vol.2B SMSW p.4-658), - // where the APM stores "the low 32 bits of CR0" (Vol.3 SMSW - // p.476). - 4 => match dest { - RM_reg(r) => { - let os = opsize(pfx); - if os == 32 & cur_mode != LongMode then - v(r) = (undefined : word) @ CR0[15..0] - else - v(r) = CR0[(os - 1) .. 0] - }, - RM_mem(m) => v(m) = CR0[15..0], - }, - - // 0F 01 /6: LMSW r/m16 — Load Machine Status Word (requires CPL=0) - 6 => { - if cur_cpl != 0 then raise_GP0(); - let msw : word = v(dest); - // LMSW sets low 4 bits of CR0; only PE (bit 0) is sticky - // (cannot clear PE once set). MP/EM/TS are freely assignable. - var new_cr0 = CR0; - new_cr0[3..1] = msw[3..1]; - new_cr0[0] = msw[0] | CR0[0]; - CR0 = new_cr0; - // SDM Vol.2A LMSW: setting PE enters protected mode. Retain - // segment caches until reloaded (Vol.3A 12.9.1, step 9). - if cur_mode == RealMode & new_cr0[0] == 0b1 then - cur_mode = ProtectedMode - }, - - // 0F 01 /7: INVLPG m — Invalidate TLB Entry (memory only, requires CPL=0) - 7 => { - if cur_cpl != 0 then raise_GP0(); - match dest { - RM_mem(m) => { - vmx_exit_if_invlpg(seg_linear(m, 1)); - __tlb_flush() - }, - RM_reg(_) => raise_UD(), - } - }, - _ => raise_UD(), - } - }, - } - }, - - // 0F 02: LAR r, r/m16 — Load Access Rights Byte - // Reads descriptor from GDT, validates type and privilege, loads access rights. - 2 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - let selector : word = v(src); - if (selector & 0xFFFC) == zeros() then { - ZF = 0b0 - } else { - let desc_addr = descriptor_address(selector); - if ~(descriptor_in_bounds(selector)) then { - ZF = 0b0 - } else { - let desc_hi : dword = read_mem_implicit(desc_addr + 4); - if ~(lar_type_valid_64(desc_hi)) | ~(desc_privilege_ok(desc_hi, selector)) then { - ZF = 0b0 - } else { - let ar : qword = zero_extend(zero_extend(desc_hi[23..0]) & 0x00FFFF00 : dword); - v(reg) = ar[(os - 1) .. 0]; - ZF = 0b1 - } - } - } - }, - - // 0F 03: LSL r, r/m16 — Load Segment Limit - // Reads descriptor from GDT, validates type and privilege, loads segment limit. - 3 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - let selector : word = v(src); - if (selector & 0xFFFC) == zeros() then { - ZF = 0b0 - } else { - let desc_addr = descriptor_address(selector); - if ~(descriptor_in_bounds(selector)) then { - ZF = 0b0 - } else { - let desc_lo : dword = read_mem_implicit(desc_addr); - let desc_hi : dword = read_mem_implicit(desc_addr + 4); - if ~(lsl_type_valid_64(desc_hi)) | ~(desc_privilege_ok(desc_hi, selector)) then { - ZF = 0b0 - } else { - let limit_lo : word = desc_lo[15..0]; - let limit_hi : bits(4) = desc_hi[19..16]; - let granularity : bit = desc_hi[23]; - let limit : dword = zero_extend(limit_hi @ limit_lo); - let fl_ext : qword = zero_extend(if granularity == 0b1 - then (limit << 12) | 0x00000FFF - else limit); - v(reg) = fl_ext[(os - 1) .. 0]; - ZF = 0b1 - } - } - } - }, - - // 0F 05: SYSCALL. #UD if IA32_EFER.SCE = 0, in either manual and - // whatever the mode (SDM Vol.2B SYSCALL 4-699; APM Vol.3 SYSCALL - // p.486); then exec_syscall. - 5 => { - if EFER[0] != 0b1 then raise_UD(); - if system_mode then exec_syscall() - else __syscall(RIP, read_rflags()) - }, - - // 0F 06: CLTS — Clear TS flag in CR0 (requires CPL=0) - 6 => { - if cur_cpl != 0 then raise_GP0(); - CR0[3] = 0b0 // TS = bit 3 - }, - - // 0F 07: SYSRET (exec_sysret) - 7 => exec_sysret(pfx), - - // 0F 09: WBINVD — Write Back and Invalidate Cache (NOP, requires CPL=0) - // 0F 08: INVD — Invalidate Internal Caches (requires CPL=0) - // SDM: Flush(InternalCaches); SignalFlush(ExternalCaches); Continue - // Destructive: dirty cache lines discarded (not written back). - 8 => { - if cur_cpl != 0 then raise_GP0(); - vmx_exit_invd() - }, - - // 0F 09: WBINVD — Write Back and Invalidate Cache (requires CPL=0) - 9 => { - if cur_cpl != 0 then raise_GP0(); - vmx_exit_if_wbinvd() - }, - - // 0F 0B: UD2 - 11 => raise_UD(), - - // 0F 1F: Multi-byte NOP r/m (prefetch hint) - 31 => { - let modrm = fetch(1); - let _ = modrm_rm(modrm, pfx) // consume ModR/M + SIB + disp - }, - - // 0F 20: MOV reg, CRn — Read control register (requires CPL=0) - // REX.R extends reg field to access CR8 - 32 => { - if cur_cpl != 0 then raise_GP0(); - let modrm = fetch(1); - let rex_r_eff : bit = if pfx.has_rex then pfx.rex_r else 0b0; - let cr_idx : range(0, 15) = unsigned(rex_r_eff @ modrm[5..3]); - let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); - let cr_val : qword = match vmx_cr_read_shadow(cr_idx) { - Some(shadow_val) => shadow_val, - None() => match cr_idx { - 0 => CR0, - 2 => CR2, - 3 => CR3, - 4 => CR4, - 8 => zero_extend(__read_cr8()), - _ => raise_UD(), - }, - }; - v(rm_idx) = cr_val; - finish_system_register_move() - }, - - // 0F 22: MOV CRn, reg — Write control register (requires CPL=0) - // REX.R extends reg field to access CR8 - 34 => { - if cur_cpl != 0 then raise_GP0(); - let modrm = fetch(1); - let rex_r_eff : bit = if pfx.has_rex then pfx.rex_r else 0b0; - let cr_idx : range(0, 15) = unsigned(rex_r_eff @ modrm[5..3]); - let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); - let cr_val : qword = v(rm_idx); - vmx_exit_if_cr_write(cr_idx, cr_val); - match cr_idx { - 0 => { - // SDM Vol.2B MOV to CR: setting a reserved bit in CR0[63:32] is - // #GP(0), setting one in CR0[31:0] is ignored. Reserved: all but - // PE MP EM TS ET NE (5:0), WP (16), AM (18), NW CD PG (31:29). - if cr_val[63..32] != zeros() then raise_GP0(); - let cr_val : qword = cr_val & 0x00000000E005003F; - // #GP(0) on invalid combinations: PG = 1 with PE = 0, or CD = 0 - // with NW = 1; and in 64-bit mode on clearing PG. - if cr_val[31] == 0b1 & cr_val[0] == 0b0 then raise_GP0(); - if cr_val[29] == 0b1 & cr_val[30] == 0b0 then raise_GP0(); - if cur_mode == LongMode & cr_val[31] == 0b0 then raise_GP0(); - CR0 = cr_val; - // EFER.LMA = EFER.LME & CR0.PG (SDM Vol.3 §4.1.1) - let lme = EFER[8]; - let pg = cr_val[31]; - EFER[10] = lme & pg; // Update LMA - if lme == 0b1 & pg == 0b1 then { - // IA-32e mode: 64-bit if CS.L=1, compatibility if CS.L=0 - if SegCache[CS].seg_l == 0b1 then - cur_mode = LongMode - else - cur_mode = CompatibilityMode - } else if cr_val[0] == 0b1 then { - cur_mode = ProtectedMode - } else { - cur_mode = RealMode - } - }, - 2 => CR2 = cr_val, - 3 => { CR3 = cr_val; __tlb_flush() }, - 4 => { - // SDM Vol.2B MOV to CR: #GP(0) on setting a reserved bit in CR4. - // Vol.3A §2.5 defines bits 14:0, 25:16, 27, 28 and 32; the rest - // (15, 26, 31:29, 63:33) are reserved. - if (cr_val & 0xFFFFFFFEE4008000) != zeros() then raise_GP0(); - // #GP(0) on leaving IA-32e mode by clearing CR4.PAE - if EFER[10] == 0b1 & cr_val[5] == 0b0 then raise_GP0(); - // SDM: #GP(0) if changing CR4.LA57 (bit 12) while paging is enabled - if CR0[31] == 0b1 & cr_val[12] != CR4[12] then raise_GP0(); - CR4 = cr_val - }, - 8 => { - // SDM Vol.2B MOV to CR: #GP(0) on setting a reserved bit in CR8; - // only the TPR field, bits 3:0, is defined (Vol.3A §2.5). - if cr_val[63..4] != zeros() then raise_GP0(); - CR8 = cr_val[3..0]; - __write_cr8(CR8) - }, - _ => raise_UD(), - }; - finish_system_register_move() - }, - - // 0F 21: MOV reg, DRn — Read debug register (requires CPL=0) - // SDM MOV DR: CR4.DE=1 and DR4/DR5 → #UD; otherwise DR4/5 alias DR6/7; - // CPL > 0 → #GP(0); DR7.GD → #DB before the access (§20.3.1.3). - // Outside 64-bit mode the read returns the low 32 bits (§20.2.6). - 33 => { - let modrm = fetch(1); - let dr_idx : range(0, 7) = unsigned(modrm[5..3]); - if (dr_idx == 4 | dr_idx == 5) & CR4[3] == 0b1 then raise_UD(); - if cur_cpl != 0 then raise_GP0(); - general_detect_check(); - vmx_exit_if_dr_access(); - let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); - let dr_val : qword = match dr_idx { - 0 => DR0, - 1 => DR1, - 2 => DR2, - 3 => DR3, - 4 => DR6, // alias when CR4.DE=0 - 5 => DR7, // alias when CR4.DE=0 - 6 => DR6, - 7 => DR7, - }; - if cur_mode == LongMode then v(rm_idx) = dr_val - else v(32, rm_idx) = dr_val[31..0]; - finish_system_register_move() - }, - - // 0F 23: MOV DRn, reg — Write debug register (requires CPL=0) - // Same checks as the read. In 64-bit mode a 1 in bits 63:32 of the - // value for DR6 or DR7 is #GP(0) (§20.2.6); outside it the upper 32 - // bits are filled with zeros. DR6 keeps only its status bits (B0-B3, - // BD, BS, BT) over fixed reserved bits; DR7 keeps its enable and - // condition fields, bit 10 reads as 1 and the other reserved bits as 0. - 35 => { - let modrm = fetch(1); - let dr_idx : range(0, 7) = unsigned(modrm[5..3]); - if (dr_idx == 4 | dr_idx == 5) & CR4[3] == 0b1 then raise_UD(); - if cur_cpl != 0 then raise_GP0(); - general_detect_check(); - vmx_exit_if_dr_access(); - let rm_idx : gpr_idx = unsigned(pfx.rex_b @ modrm[2..0]); - let dr_val : qword = if cur_mode == LongMode then v(rm_idx) else zero_extend(v(32, rm_idx)); - let status_reg : bool = dr_idx >= 4; - if status_reg & dr_val[63..32] != zeros() then raise_GP0(); - match dr_idx { - 0 => DR0 = dr_val, - 1 => DR1 = dr_val, - 2 => DR2 = dr_val, - 3 => DR3 = dr_val, - 4 => DR6 = (dr_val & 0x000000000000E00F) | 0x00000000FFFF0FF0, // alias when CR4.DE=0 - 5 => DR7 = (dr_val & 0x00000000FFFF2BFF) | 0x0000000000000400, // alias when CR4.DE=0 - 6 => DR6 = (dr_val & 0x000000000000E00F) | 0x00000000FFFF0FF0, - 7 => DR7 = (dr_val & 0x00000000FFFF2BFF) | 0x0000000000000400, - }; - finish_system_register_move() - }, - - // 0F 30: WRMSR — Write MSR (requires CPL=0) - 48 => { - if cur_cpl != 0 then raise_GP0(); - vmx_exit_if_wrmsr(); - let ecx : dword = v(RCX); - let msr_val : qword = v(32, RDX) @ v(32, RAX); - - // Handle EFER specially since it has a Sail register - if ecx == 0xC0000080 then { - EFER = msr_val - } else if ecx == 0x0000003A then { - // IA32_FEATURE_CONTROL: #GP(0) if lock bit (bit 0) is already set - if ia32_feature_control[0] == 0b1 then raise_GP0(); - ia32_feature_control = msr_val - } else if ecx == 0xC0000100 then { - SegCache[FS].seg_base = msr_val - } else if ecx == 0xC0000101 then { - SegCache[GS].seg_base = msr_val - } else if ecx == 0xC0000102 then { - KERNEL_GS_BASE = msr_val - } else if ecx == 0x00000DA0 then { - // IA32_XSS (0xDA0): supervisor state components for XSAVES/XRSTORS. - // It exists with XSAVES (SDM Vol.1 §13.2 p.13-4), and "A bit can - // be set in the IA32_XSS MSR if and only if the corresponding bit - // is set in" CPUID.0DH.01H:EDX:ECX, which has none. - if ~(has_xsaves) then raise_GP0(); - if msr_val != zeros() then raise_GP0() - } else if ecx == 0x000000E1 then { - // IA32_UMWAIT_CONTROL (0xE1, SDM Vol.2B TPAUSE/UMWAIT): the OS - // limit on a wait in bits 31:2 and the C0.2 disable in bit 0; bit - // 1 and bits 63:32 are reserved. Exists with WAITPKG. - if ~(has_waitpkg) then raise_GP0(); - if msr_val[63..32] != zeros() | msr_val[1] == bitone then raise_GP0(); - __wrmsr(ecx, msr_val) - } else if ecx == 0x000001C4 | ecx == 0x000001C5 then { - // IA32_XFD (1C4H) and IA32_XFD_ERR (1C5H), SDM Vol.1 §13.14 - // p.13-27: exist with XFD (CPUID.0DH.01H:EAX[4]); "Bit i of either - // MSR can be set to 1 only if CPUID.0DH.i:ECX[2] is enumerated as - // 1", and WRMSR of another bit is #GP. - if ~(has_xfd) then raise_GP0(); - if (msr_val & ~(xfd_supported())) != zeros() then raise_GP0(); - if ecx == 0x000001C4 then IA32_XFD = msr_val else IA32_XFD_ERR = msr_val - } else if ecx == 0x00000D93 then { - // IA32_PASID (D93H): exists with ENQCMD; bits 19:0 (PASID) and - // 31 (valid) are writable, and a value that sets a reserved bit, - // 30:20 or 63:32, is #GP(0) (SDM WRMSR). - if ~(has_enqcmd) then raise_GP0(); - if (msr_val & ~(0x00000000800FFFFF : qword)) != zeros() then raise_GP0(); - IA32_PASID = msr_val - } else if ecx >=_u 0x00000480 & ecx <=_u 0x00000491 then { - // VMX capability MSRs are read-only — #GP(0) on write - raise_GP0() - } else { - __wrmsr(ecx, msr_val) - } - }, - - // 0F 0D: PREFETCHW m8 (/1; SDM Vol.2B) and the reserved NOPs of the - // opcode's other forms. Every 0F 0D encoding is decoded with a ModR/M - // byte and behaves as NOP (SDM Vol.3B §25.15, "Reserved NOP"): the - // hint moves no architectural state and takes no memory fault. The - // APM defines the opcode as PREFETCH/PREFETCHW, where "only the memory - // form of ModRM is valid. The register form of ModRM causes an - // invalid-opcode exception" (Vol.3 PREFETCH, p.293-294), a #UD of one - // manual only, which the model does not raise. - 13 => { - let modrm = fetch(1); - let _ = modrm_rm(modrm, pfx) - }, - - // 0F 18-1E: PREFETCHh, CLDEMOTE (0F 1C /0) and the reserved NOPs. - // These all consume ModR/M and do nothing. - op if 24 <= op & op <= 30 => { - let modrm = fetch(1); - let _ = modrm_rm(modrm, pfx) - }, - - // 0F 31: RDTSC - // SDM: #GP(0) if CR4.TSD (bit 2) = 1 and CPL > 0 - 49 => { - if CR4[2] == 0b1 & cur_cpl != 0 then raise_GP0(); - vmx_exit_if_rdtsc(); - let tsc = __rdtsc(); - v(RAX) = tsc[31..0]; - v(RDX) = tsc[63..32] - }, - - // 0F 33: RDPMC — Read Performance-Monitoring Counter - // SDM pseudocode: - // IF (((CR4.PCE = 1) or (CPL = 0)) and (ECX indicates a supported counter)) - // THEN EAX := counter[31:0]; EDX := ZeroExtend(counter[MSCB:32]); - // ELSE #GP(0); - // FI; - // No performance counters are modeled, so ECX always indicates an - // unsupported counter → unconditional #GP(0). - 51 => raise_GP0(), - - // 0F 34: SYSENTER (exec_sysenter) - 52 => exec_sysenter(), - - // 0F 35: SYSEXIT (exec_sysexit) - 53 => exec_sysexit(pfx), - - // 0F 32: RDMSR — Read MSR (requires CPL=0) - 50 => { - if cur_cpl != 0 then raise_GP0(); - vmx_exit_if_rdmsr(); - let ecx : dword = v(RCX); - // Handle registers with Sail state specially - let msr : qword = match ecx { - 0xC0000080 => EFER, - 0x0000003A => ia32_feature_control, - // IA32_XSS exists with XSAVES and is always 0 (no supervisor state - // components supported) - 0x00000DA0 => { if ~(has_xsaves) then raise_GP0(); zeros() }, - // IA32_UMWAIT_CONTROL exists with WAITPKG; the value written, 0 at reset - 0x000000E1 => { if ~(has_waitpkg) then raise_GP0(); __rdmsr(ecx) }, - // IA32_XFD and IA32_XFD_ERR exist with XFD - 0x000001C4 => { if ~(has_xfd) then raise_GP0(); IA32_XFD }, - 0x000001C5 => { if ~(has_xfd) then raise_GP0(); IA32_XFD_ERR }, - // IA32_PASID exists with ENQCMD - 0x00000D93 => { if ~(has_enqcmd) then raise_GP0(); IA32_PASID }, - 0xC0000100 => SegCache[FS].seg_base, - 0xC0000101 => SegCache[GS].seg_base, - 0xC0000102 => KERNEL_GS_BASE, - // VMX Capability MSRs (SDM Appendix A) — read-only - 0x00000480 => 0x0098040000000001, // VMX_BASIC: rev=1, size=1024, WB, TRUE controls - 0x00000481 => 0x0000003F00000016, // VMX_PINBASED_CTLS - 0x00000482 => 0xFFF9FFFE0401E172, // VMX_PROCBASED_CTLS - 0x00000483 => 0x003FFFFF00036DFF, // VMX_EXIT_CTLS - 0x00000484 => 0x0000F3FF000011FF, // VMX_ENTRY_CTLS - 0x00000485 => 0x0000000000000020, // VMX_MISC - 0x00000486 => 0x0000000080000021, // VMX_CR0_FIXED0: PE+NE+PG must be 1 - 0x00000487 => 0x00000000FFFFFFFF, // VMX_CR0_FIXED1: all allowed - 0x00000488 => 0x0000000000002000, // VMX_CR4_FIXED0: VMXE must be 1 - 0x00000489 => 0x00000000FFFFFFFF, // VMX_CR4_FIXED1: all bits allowed - 0x0000048A => 0x000000000000002E, // VMX_VMCS_ENUM - 0x0000048B => 0x001010EA00000000, // VMX_PROCBASED_CTLS2: EPT, unrestricted guest, RDTSCP, WBINVD, INVPCID, XSAVES - 0x0000048C => 0x0000000006134141, // VMX_EPT_VPID_CAP: exec-only, 4-level walk, UC, WB, 2MB, 1GB, INVEPT - 0x0000048D => 0x0000003F00000000, // VMX_TRUE_PINBASED_CTLS - 0x0000048E => 0xFFF9FFFE04006172, // VMX_TRUE_PROCBASED_CTLS - 0x0000048F => 0x003FFFFF00036DFB, // VMX_TRUE_EXIT_CTLS - 0x00000490 => 0x0000F3FF000011FB, // VMX_TRUE_ENTRY_CTLS - 0x00000491 => 0x0000000000000000, // VMX_VMFUNC: no VM functions - 0x00000492 => 0x0000000000000000, // VMX_PROCBASED_CTLS3: no tertiary controls - _ => __rdmsr(ecx), - }; - v(RAX) = msr[31..0]; - v(RDX) = msr[63..32] - }, - - // 0F 40-4F: CMOVcc r, r/m - op if 64 <= op & op <= 79 => { - let cc : cc_idx = op - 64; - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - v(reg) = blend(v(os, reg), v(os, src), eval_cc(cc)) - }, - - // 0F 77: EMMS — set x87 tag word to all empty. NP 0F 77 (SDM Vol.2A - // EMMS): 66, F2 or F3 leaves it undefined; then #UD if CR0.EM = 1 and - // #NM if CR0.TS = 1, as for MMX. - 119 => { - if get_mandatory_prefix(pfx) != MP_NONE then raise_UD(); - check_cr0_sse(); - x87_tw = 0xFFFF; - x87_mmx_last = true - }, - - // 0F 80-8F: Jcc rel16/rel32 (forced64) - op if 128 <= op & op <= 143 => { - let cc : cc_idx = op - 128; - let rs = opsize_rel(pfx); - let offset : qword = sign_extend(fetch(rs / 8)); - if eval_cc(cc) == 0b1 then { - let os = opsize_forced64(pfx); - next_rip = Some(zero_extend((decode_pos + offset)[(os - 1) .. 0])); - } - }, - - // 0F 90-9F: SETcc r/m8 - op if 144 <= op & op <= 159 => { - let cc : cc_idx = op - 144; - let modrm = fetch(1); - let dest = modrm_rm(modrm, pfx); - v(dest) = zero_extend(8, eval_cc(cc)) - }, - - // 0F AE: Group 15 — FXSAVE/FXRSTOR/LDMXCSR/STMXCSR/XSAVE/XRSTOR/ - // LFENCE/MFENCE/SFENCE/RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE - 174 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - // The forms the SDM Vol.2 opcode tables define, by mandatory prefix - // (FXSAVE, FXRSTOR, LDMXCSR, STMXCSR, XSAVE, XRSTOR, XSAVEOPT and - // CLFLUSH are NP, as are LFENCE, MFENCE and SFENCE); any other is #UD. - // PTWRITE (F3 /4) is #UD with 66h or without CPUID.(14H,0):EBX[4] - // (SDM Vol.2B PTWRITE). Not implemented: F3 /5 reg INCSSP (CET - // shadow stacks, #UD while CR4.CET = 0). - let is_reg : bool = match dest { RM_reg(_) => true, RM_mem(_) => false }; - let ptwrite : bool = reg_field == 4 & has_ptwrite & ~(pfx.has_opsize); - let defined : bool = match (get_mandatory_prefix(pfx), is_reg) { - // FXSAVE ... CLFLUSH m8 - (MP_NONE, false) => true, - // LFENCE, MFENCE, SFENCE - (MP_NONE, true) => reg_field >= 5, - // CLWB m8, CLFLUSHOPT m8 - (MP_66, false) => reg_field >= 6, - // TPAUSE r32 - (MP_66, true) => reg_field == 6, - // RDFSBASE, RDGSBASE, WRFSBASE, WRGSBASE; UMONITOR; PTWRITE r32/r64 - (MP_F3, true) => reg_field <= 3 | reg_field == 6 | ptwrite, - // PTWRITE m32/m64 - (MP_F3, false) => ptwrite, - // UMWAIT r32 - (MP_F2, true) => reg_field == 6, - _ => false, - }; - if ~(defined) then raise_UD(); - if ptwrite & pfx.has_rep then { - // PTWRITE r/m32, r/m64 (REX.W): the operand goes to a PTW packet - // when Intel PT traces it (SDM Vol.2B PTWRITE). The model has no - // processor trace, so only the read, and its faults, remain. - let _ = if pfx.rex_w then zero_extend(64, v(64, dest)) else zero_extend(64, v(32, dest)); - return () - }; - // F3 prefix with mod=11 and reg_field 0-3: FSGSBASE instructions - // SDM: #UD if CR4.FSGSBASE (bit 16) = 0 - if pfx.has_rep & reg_field <= 3 then { - if CR4[16] != 0b1 then raise_UD(); - match dest { - RM_reg(r) => match (reg_field, pfx.rex_w) { - // F3 0F AE /0 mod=11: RDFSBASE r32/r64 - (0, true) => v(r) = SegCache[FS].seg_base, - (0, false) => v(r) = SegCache[FS].seg_base[31..0], - // F3 0F AE /1 mod=11: RDGSBASE r32/r64 - (1, true) => v(r) = SegCache[GS].seg_base, - (1, false) => v(r) = SegCache[GS].seg_base[31..0], - // F3 0F AE /2 mod=11: WRFSBASE r32/r64 - (2, true) => SegCache[FS].seg_base = v(64, r), - (2, false) => SegCache[FS].seg_base = zero_extend(v(32, r)), - // F3 0F AE /3 mod=11: WRGSBASE r32/r64 - (3, true) => SegCache[GS].seg_base = v(64, r), - (3, false) => SegCache[GS].seg_base = zero_extend(v(32, r)), - _ => raise_UD(), - }, - RM_mem(_) => raise_UD(), - } - } else match reg_field { - // FXSAVE m512byte (SDM Vol.2A FXSAVE): #NM if CR0.EM or CR0.TS is - // set (check_cr0_x87), then #GP(0) unless the operand is aligned on - // a 16-byte boundary. - 0 => match dest { - RM_mem(m) => { - check_cr0_x87(); - check_alignment(m, 16); - exec_fxsave(seg_linear(m, 512), pfx.rex_w) - }, - _ => raise_UD(), - }, - - // FXRSTOR m512byte (SDM Vol.2A FXRSTOR): #NM as FXSAVE, then - // #GP(0) unless the operand is 16-byte aligned, and for an image - // whose MXCSR sets a reserved bit (exec_fxrstor). - 1 => match dest { - RM_mem(m) => { - check_cr0_x87(); - check_alignment(m, 16); - exec_fxrstor(seg_linear(m, 512), pfx.rex_w) - }, - _ => raise_UD(), - }, - - // LDMXCSR m32 and STMXCSR m32 (SDM Vol.2A LDMXCSR and Vol.2B - // STMXCSR: exception class 5) - 2 => { check_cr0_sse(); load_mxcsr(rm_mem(dest)) }, - 3 => { check_cr0_sse(); rm_mem(dest) = __stmxcsr() }, - - // XSAVE m (#NM if CR0.TS = 1, whatever CR0.EM, as for the whole - // XSAVE family: SDM Vol.2D XSAVE) - 4 => match dest { - RM_mem(m) => { - check_xsave_enabled(true); - check_cr0_ts(); - let mask : qword = v(32, RDX) @ v(32, RAX); - exec_xsave(seg_linear(m, 576), mask, pfx.rex_w) - }, - RM_reg(_) => raise_UD(), - }, - - 5 => match dest { - RM_mem(m) => { - // /5 mem: XRSTOR m - check_xsave_enabled(true); - check_cr0_ts(); - let mask : qword = v(32, RDX) @ v(32, RAX); - exec_xrstor(seg_linear(m, 576), mask, pfx.rex_w) - }, - RM_reg(_) => { - // /5 mod=11: LFENCE - () - }, - }, - - // /6: XSAVEOPT (NP, mem) / CLWB (66, mem) / MFENCE (NP, reg), and - // with mod=11 the WAITPKG instructions TPAUSE (66), UMONITOR (F3) - // and UMWAIT (F2) (SDM Vol.2B; CPUID.07H.00H:ECX.WAITPKG[5]). - 6 => match dest { - RM_mem(m) => { - if pfx.has_opsize then { - cache_line_access(m) // CLWB - } else { - // XSAVEOPT: architecturally equivalent to XSAVE - check_xsave_enabled(has_xsaveopt); - check_cr0_ts(); - let mask : qword = v(32, RDX) @ v(32, RAX); - exec_xsaveopt(seg_linear(m, 576), mask, pfx.rex_w) - } - }, - RM_reg(r) => match get_mandatory_prefix(pfx) { - // MFENCE - MP_NONE => (), - // TPAUSE r32, , - MP_66 => exec_tpause_umwait(r, false), - // UMWAIT r32, , - MP_F2 => exec_tpause_umwait(r, true), - // UMONITOR r16/r32/r64 - MP_F3 => exec_umonitor(r, pfx), - }, - }, - - // /7: CLFLUSH (NP, mem) / CLFLUSHOPT (66, mem) / SFENCE (reg) - 7 => match dest { - RM_mem(m) => cache_line_access(m), - RM_reg(_) => (), - }, - } - }, - - // 0F A2: CPUID — unconditional VM exit in non-root (SDM §26.1.2) - 162 => { - vmx_exit_cpuid(); - let leaf : dword = v(RAX); - let subleaf : dword = v(RCX); - let (eax, ebx, ecx, edx) = cpuid(leaf, subleaf); - v(RAX) = eax; - v(RBX) = ebx; - v(RCX) = ecx; - v(RDX) = edx - }, - - // 0F A0: PUSH FS (d64) - // SDM: pushes FS selector. d64 = default 64 in long mode. - // Non-64-bit mode: operand size from CS.D and 66h prefix. - 160 => push_segreg(opsize_default64(pfx), FS), - - // 0F A1: POP FS (d64) - 161 => { - let os = opsize_default64(pfx); - load_data_segment_register(FS, match os { - 16 => pop(16), - 32 => pop(32)[15..0], - 64 => pop(64)[15..0], - }) - }, - - // 0F A3: BT r/m, r - 163 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - let bit_idx = v(os, reg); - let (adj_rm, bit_num) = bt_adjust(src, bit_idx); - CF = v(os, adj_rm)[bit_num]; - OF = undefined; - SF = undefined; - AF = undefined; - PF = undefined - }, - - // 0F A4: SHLD r/m, r, imm8 - 164 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - let count = fetch(1); - // SDM SHLD/SHRD: every operand access uses the decoded width. - // An inferred qword write would overwrite adjacent memory on r/m16/32. - v(os, dest) = exec_shld(os, read_rmw(os, dest), v(os, reg), count) - }, - - // 0F A5: SHLD r/m, r, CL - 165 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - let count : byte = v(RCX); - v(os, dest) = exec_shld(os, read_rmw(os, dest), v(os, reg), count) - }, - - // 0F A8: PUSH GS (d64) - 168 => push_segreg(opsize_default64(pfx), GS), - - // 0F A9: POP GS (d64) - 169 => { - let os = opsize_default64(pfx); - load_data_segment_register(GS, match os { - 16 => pop(16), - 32 => pop(32)[15..0], - 64 => pop(64)[15..0], - }) - }, - - // 0F AA: RSM — Resume from System Management Mode - // SDM Vol.2B §RSM: #UD if not in SMM. Restores processor state from - // SMRAM and returns to the mode active before the SMI. - 170 => exec_rsm(), - - // 0F AB: BTS r/m, r - 171 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - let bit_idx = v(os, reg); - let (adj_rm, bit_num) = bt_adjust(dest, bit_idx); - var x = read_rmw(os, adj_rm); - CF = x[bit_num]; - x[bit_num] = 0b1; - v(adj_rm) = x; - OF = undefined; - SF = undefined; - AF = undefined; - PF = undefined - }, - - // 0F AC: SHRD r/m, r, imm8 - 172 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - let count = fetch(1); - v(os, dest) = exec_shrd(os, read_rmw(os, dest), v(os, reg), count) - }, - - // 0F AD: SHRD r/m, r, CL - 173 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - let count : byte = v(RCX); - v(os, dest) = exec_shrd(os, read_rmw(os, dest), v(os, reg), count) - }, - - // 0F AF: IMUL r, r/m (2-operand) - // SDM: SF, ZF, AF, PF are undefined after IMUL. - 175 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - let a = v(os, reg); - let b = v(os, src); - let product : int = signed(sign_extend(a) : qword) * signed(sign_extend(b) : qword); - let result : qword = to_bits_truncate(product); - let w = to_bits_truncate(os * 2, product); - CF = is_nonzero(w[os * 2 - 1 .. os] ^ sign_extend(w[os - 1])); - OF = CF; - SF = undefined; - ZF = undefined; - AF = undefined; - PF = undefined; - v(reg) = to_bits_truncate(os, product) - }, - - // 0F B3: BTR r/m, r - 179 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - let bit_idx = v(os, reg); - let (adj_rm, bit_num) = bt_adjust(dest, bit_idx); - var x = read_rmw(os, adj_rm); - CF = x[bit_num]; - x[bit_num] = 0b0; - v(os, adj_rm) = x; - OF = undefined; - SF = undefined; - AF = undefined; - PF = undefined - }, - - // 0F B2: LSS r, m16:16/32/64 — Load far pointer into SS - // 0F B4: LFS r, m16:16/32/64 — Load far pointer into FS - // 0F B5: LGS r, m16:16/32/64 — Load far pointer into GS - // Memory format: [offset (16/32/64-bit)][selector (16-bit)] - // Register operand only (memory source); #UD for register source. - // With REX.W the SDM has "REX.W + 0F B2 /r LSS r64,m16:64" (Vol.2A - // LDS/LES/LFS/LGS/LSS p.3-540), the only definition of the form: the - // APM lists only mem16:16 and mem16:32, "A 64-bit operand is not - // supported" (Vol.3 LDS-LSS p.216), without saying what REX.W then - // does. The model loads the SDM's m16:64. - op if op == 178 | op == 180 | op == 181 => { - let os : {16, 32, 64} = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - match src { - RM_mem(m) => { - let (far_offset, selector) = read_far_pointer(os, m); - let seg : segreg_idx = match op { - 178 => SS, - 180 => FS, - 181 => GS, - }; - load_data_segment_register(seg, selector); - // The destination width follows the operand size, not the qword - // used by read_far_pointer to represent the offset. - v(reg) = far_offset[os - 1 .. 0] - }, - RM_reg(_) => raise_UD(), - } - }, - - // 0F B0: CMPXCHG r/m8, r8 - 176 => { - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - let dest_val = read_rmw(8, dest); - let acc : byte = v(RAX); - let src : byte = v(reg); - let cmp_result = acc - dest_val; - update_flags_sub(cmp_result, acc, dest_val); - // SDM Vol.2A CMPXCHG, Operation: equal loads DEST from SRC and leaves - // the accumulator alone; only the unequal case writes the accumulator. - v(dest) = blend(dest_val, src, ZF); - if ZF == 0b0 then v(RAX) = dest_val - }, - - // 0F B1: CMPXCHG r/m, r - 177 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - let dest_val = read_rmw(os, dest); - let acc = v(os, RAX); - let src = v(os, reg); - let cmp_result = acc - dest_val; - update_flags_sub(cmp_result, acc, dest_val); - // As for the byte form: the accumulator is written only when unequal. - v(os, dest) = blend(dest_val, src, ZF); - if ZF == 0b0 then v(RAX) = dest_val - }, - - // 0F B6: MOVZX r, r/m8 - 182 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - v(reg) = zero_extend(os, v(8, src)) - }, - - // 0F B7: MOVZX r, r/m16 - 183 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - v(reg) = zero_extend(os, v(16, src)) - }, - - // 0F BA: Group 8 — BT/BTS/BTR/BTC r/m, imm8 - 186 => { - let os = opsize(pfx); - let (reg_field, dest) = fetch_modrm_raw(pfx); - // LOCK valid only for BTS (/5), BTR (/6), BTC (/7) with memory - if pfx.has_lock & reg_field == 4 then raise_UD(); - check_lock_rm(pfx, dest, false); - // /0-/3 are reserved: #UD before the operand is accessed. - if reg_field < 4 then raise_UD(); - let imm = fetch(1); - var x = if reg_field == 4 then v(os, dest) else read_rmw(os, dest); - let bit_num : range(0, 63) = unsigned(imm) % os; - assert(bit_num < os); - CF = x[bit_num]; - match reg_field { - // BT — just test, no modification - 4 => (), - // BTS — set bit - 5 => { - x[bit_num] = 0b1; - v(dest) = x - }, - // BTR — reset bit - 6 => { - x[bit_num] = 0b0; - v(dest) = x - }, - // BTC — complement bit - 7 => { - x[bit_num] = ~(x[bit_num]); - v(dest) = x - }, - _ => raise_UD(), - }; - OF = undefined; - SF = undefined; - AF = undefined; - PF = undefined - }, - - // 0F BB: BTC r/m, r - 187 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - let bit_idx = v(os, reg); - let (adj_rm, bit_num) = bt_adjust(dest, bit_idx); - var x = read_rmw(os, adj_rm); - CF = x[bit_num]; - x[bit_num] = ~(x[bit_num]); - v(os, adj_rm) = x; - OF = undefined; - SF = undefined; - AF = undefined; - PF = undefined - }, - - // 0F BC: BSF r, r/m (or TZCNT with F3 prefix) - 188 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - if pfx.has_rep & has_bmi1 then { - // TZCNT r16/r32/r64, r/m16/r/m32/r/m64. "On processors that do - // not support TZCNT, the instruction byte encoding is executed as - // BSF" (SDM Vol.2B TZCNT p.4-727; APM Vol.3 TZCNT p.362: "treated - // as the BSF instruction"). - let src_val = v(os, src); - let count = ctz(src_val); - let result : qword = to_bits_truncate(count); - v(reg) = result[(os - 1) .. 0]; - CF = is_zero(src_val); - ZF = src_val[0]; - OF = undefined; - SF = undefined; - AF = undefined; - PF = undefined - } else { - // BSF r16/r32/r64, r/m16/r/m32/r/m64 - // ZF is set for a zero source and cleared otherwise. The other - // flags are undefined: the SDM sets PF from the source's parity and - // clears CF, OF, SF and AF, but "On some older processors, the CF, - // OF, SF, AF, and PF flags are unmodified" (Vol.2A BSF p.3-107, - // footnote 2), and the APM marks all five U (Vol.3 BSF p.123). - // For a zero source "the destination operand is unmodified", but - // "on some older processors, use of a 32-bit operand size may clear - // the upper 32 bits of a 64-bit destination while leaving the lower - // 32 bits unmodified" (SDM, footnote 1); the APM "does not change - // the contents of the destination register". So the register - // stays, except bits 63:32 after a 32-bit BSF, which are undefined. - // Linux's ffs(), fls() and fls64() (arch/x86/include/asm/bitops.h) - // preload -1 and rely only on the low 32 bits surviving. - let src_val = v(os, src); - let zf : bit = is_zero(src_val); - let idx = ctz(src_val); - let result : qword = to_bits_truncate(idx); - CF = undefined; - OF = undefined; - SF = undefined; - AF = undefined; - ZF = zf; - PF = undefined; - let old : qword = GPR[reg.gpr_idx]; - let kept : qword = if os == 32 then (undefined : dword) @ old[31..0] else old; - v(reg) = result[(os - 1) .. 0]; - GPR[reg.gpr_idx] = blend(GPR[reg.gpr_idx], kept, zf) - } - }, - - // 0F BD: BSR r, r/m (or LZCNT with F3 prefix) - 189 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - if pfx.has_rep & has_lzcnt then { - // LZCNT r16/r32/r64, r/m16/r/m32/r/m64. "On processors that do - // not support LZCNT, the instruction byte encoding is executed as - // BSR" (SDM Vol.2A LZCNT p.3-578; APM Vol.3 LZCNT p.234: - // "interpreted as the BSR instruction"). - let src_val = v(os, src); - let count = clz(src_val); - let result : qword = to_bits_truncate(count); - v(reg) = result[(os - 1) .. 0]; - CF = is_zero(src_val); - ZF = src_val[os - 1]; - OF = undefined; - SF = undefined; - AF = undefined; - PF = undefined - } else { - // BSR r16/r32/r64, r/m16/r/m32/r/m64 - // The flag and destination rules of BSF above, in the same words - // (SDM Vol.2A BSR p.3-109 and its footnotes; APM Vol.3 BSR p.124). - let src_val = v(os, src); - let zf : bit = is_zero(src_val); - // Sentinel bit 0 ensures bsr gets nonzero input; result ignored when zf=1 - let idx : range(0, 63) = bsr(zero_extend(src_val) | 0x0000000000000001); - let result : qword = to_bits_truncate(idx); - CF = undefined; - OF = undefined; - SF = undefined; - AF = undefined; - ZF = zf; - PF = undefined; - let old : qword = GPR[reg.gpr_idx]; - let kept : qword = if os == 32 then (undefined : dword) @ old[31..0] else old; - v(reg) = result[(os - 1) .. 0]; - GPR[reg.gpr_idx] = blend(GPR[reg.gpr_idx], kept, zf) - } - }, - - // 0F BE: MOVSX r, r/m8 - 190 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - let sx : qword = sign_extend(v(8, src)); - v(reg) = sx[(os - 1) .. 0] - }, - - // 0F BF: MOVSX r, r/m16 - 191 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - let sx : qword = sign_extend(v(16, src)); - v(reg) = sx[(os - 1) .. 0] - }, - - // 0F C0: XADD r/m8, r8 - 192 => { - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - match dest { - RM_reg(dst) => exec_xadd(dst, reg, 8), - RM_mem(m) => { - // Memory operand: read, exchange, add, write back - let mem_val : byte = read_rmw_mem(m); - let reg_val : byte = v(reg); - let sum : byte = mem_val + reg_val; - // A write fault must leave SRC unchanged for restart (SDM - // Vol.3A 7.5; Vol.2D XADD). Commit memory before register state. - v(m) = sum; - v(reg) = mem_val; - update_flags_add(sum, mem_val, reg_val) - }, - } - }, - - // 0F C1: XADD r/m, r - 193 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - match dest { - RM_reg(dst) => exec_xadd(dst, reg, os), - RM_mem(_) => { - let mem_val = read_rmw(os, dest); - let reg_val = v(os, reg); - let sum = mem_val + reg_val; - v(os, dest) = sum; - v(reg) = mem_val; - update_flags_add(sum, mem_val, reg_val) - }, - } - }, - - // 0F B8: POPCNT r, r/m (F3 prefix) - 184 => { - let mp = get_mandatory_prefix(pfx); - if mp != MP_F3 then raise_UD(); - if ~(has_popcnt) then raise_UD(); - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - let src_val = v(os, src); - let count : range(0, 64) = popcount(zero_extend(src_val) : qword); - OF = 0b0; - SF = 0b0; - AF = 0b0; - CF = 0b0; - PF = 0b0; - ZF = is_zero(src_val); - let result : qword = to_bits_truncate(count); - v(reg) = result[(os - 1) .. 0] - }, - - // 0F C3: MOVNTI m32/64, r — NP 0F C3 (SDM Vol.2B MOVNTI): 66, F2 or F3 - // leaves it undefined. - 195 => { - if get_mandatory_prefix(pfx) != MP_NONE then raise_UD(); - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - rm_mem(dest) = v(os, reg) - }, - - // 0F C7: Group 9 - 199 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - // The forms the SDM Vol.2 opcode tables define, by mandatory prefix; - // any other is #UD. NFx (RDRAND, RDSEED) excludes F2 and F3 (SDM - // Vol.2A §3.1.1.1); F3 /6 reg is SENDUIPI (UINTR, not implemented). - // Of Group 9 only CMPXCHG8B/16B takes LOCK (SDM Vol.2B LOCK). - let mp = get_mandatory_prefix(pfx); - let is_reg : bool = match dest { RM_reg(_) => true, RM_mem(_) => false }; - let defined : bool = match (reg_field, is_reg) { - // CMPXCHG8B m64, CMPXCHG16B m128 - (1, false) => true, - // XRSTORS, XSAVEC, XSAVES (NP) - (r, false) if 3 <= r & r <= 5 => mp == MP_NONE, - // VMPTRLD (NP), VMCLEAR (66), VMXON (F3) - (6, false) => mp != MP_F2, - // RDRAND (NFx) - (6, true) => mp == MP_NONE | mp == MP_66, - // VMPTRST (NP) - (7, false) => mp == MP_NONE, - // RDSEED (NFx), RDPID (F3) - (7, true) => mp != MP_F2, - _ => false, - }; - if ~(defined) | (pfx.has_lock & reg_field != 1) then raise_UD(); - match reg_field { - // CMPXCHG8B/CMPXCHG16B m64/m128. SDM Vol.2A CMPXCHG8B/CMPXCHG16B, - // Operation: the destination is written either way, with - // RCX:RBX when equal and with its own value when not; #GP(0) if - // the CMPXCHG16B operand is not aligned on a 16-byte boundary. - 1 => match dest { - RM_mem(m) => { - if pfx.rex_w then { - if ~(has_cx16) then raise_UD(); - check_alignment(m, 16); - let mem_val : bits(128) = read_rmw_mem(m); - let mem_lo : qword = mem_val[63..0]; - let mem_hi : qword = mem_val[127..64]; - let eq : bit = is_eq(v(64, RAX), mem_lo) & is_eq(v(64, RDX), mem_hi); - write_mem(128, m, blend(mem_val, v(64, RCX) @ v(64, RBX), eq)); - ZF = eq; - v(RAX) = blend(mem_lo, v(64, RAX), eq); - v(RDX) = blend(mem_hi, v(64, RDX), eq) - } else { - let mem_val : qword = read_rmw_mem(m); - let mem_lo : dword = mem_val[31..0]; - let mem_hi : dword = mem_val[63..32]; - let eq : bit = is_eq(v(32, RAX), mem_lo) & is_eq(v(32, RDX), mem_hi); - v(m) = blend(mem_val, v(32, RCX) @ v(32, RBX), eq); - ZF = eq; - v(RAX) = blend(mem_lo, v(32, RAX), eq); - v(RDX) = blend(mem_hi, v(32, RDX), eq) - } - }, - RM_reg(_) => raise_UD(), - }, - // /3 mem: XRSTORS — restore extended state (supervisor, requires - // CPL=0). The #NM of CR0.TS, a fault from decoding the instruction, - // comes ahead of the #GP of CPL (SDM Vol.3A §7.9), here and in - // XSAVES. - 3 => match dest { - RM_mem(m) => { - check_xsave_enabled(has_xsaves); - check_cr0_ts(); - if cur_cpl != 0 then raise_GP0(); - let mask : qword = v(32, RDX) @ v(32, RAX); - exec_xrstors(seg_linear(m, 576), mask, pfx.rex_w) - }, - _ => raise_UD(), - }, - // /4 mem: XSAVEC — save extended state with compaction - 4 => match dest { - RM_mem(m) => { - check_xsave_enabled(has_xsavec); - check_cr0_ts(); - let mask : qword = v(32, RDX) @ v(32, RAX); - exec_xsavec(seg_linear(m, 576), mask, pfx.rex_w) - }, - _ => raise_UD(), - }, - // /5 mem: XSAVES — save extended state (supervisor, requires CPL=0) - 5 => match dest { - RM_mem(m) => { - check_xsave_enabled(has_xsaves); - check_cr0_ts(); - if cur_cpl != 0 then raise_GP0(); - let mask : qword = v(32, RDX) @ v(32, RAX); - exec_xsaves(seg_linear(m, 576), mask, pfx.rex_w) - }, - _ => raise_UD(), - }, - // /6: RDRAND (mod=11) or VMX (mod!=11) - 6 => match dest { - RM_reg(r) => { - // /6 mod=11: NFx RDRAND r16/r32/r64 - if ~(has_rdrand) then raise_UD(); - let os = opsize(pfx); - let (rnd, cf_val) = __rdrand64(); - v(r) = rnd[(os - 1) .. 0] & sign_extend(cf_val); - CF = cf_val; - OF = 0b0; - SF = 0b0; - ZF = 0b0; - AF = 0b0; - PF = 0b0 - }, - RM_mem(m) => { - // /6 mem: VMX instructions discriminated by prefix - // NP 0F C7 /6 mem → VMPTRLD - // 66 0F C7 /6 mem → VMCLEAR - // F3 0F C7 /6 mem → VMXON - if pfx.has_rep then - vmx_exit_vmx_insn(VMEXIT_VMXON) - else if pfx.has_opsize then - vmx_exit_vmx_insn(VMEXIT_VMCLEAR) - else - vmx_exit_vmx_insn(VMEXIT_VMPTRLD); - let addr = seg_linear(m, 8); - if pfx.has_rep then - exec_vmxon(addr) - else if pfx.has_opsize then - exec_vmclear(addr) - else - exec_vmptrld(addr) - }, - }, - // /7: RDSEED or RDPID (mod=11) or VMPTRST (mod!=11) - 7 => match dest { - RM_reg(r) => { - if pfx.has_rep then { - // F3 0F C7 /7: RDPID r32/r64 (SDM Vol.2B RDPID): DEST := - // IA32_TSC_AUX. "The value of CS.D and operand-size prefixes - // (66H and REX.W) do not affect the behavior", so the - // destination is r64 in 64-bit mode and r32 otherwise. - if ~(has_rdpid) then raise_UD(); - let aux : dword = __rdmsr(0xC0000103)[31..0]; - if cur_mode == LongMode then v(r) = zero_extend(64, aux) else v(r) = aux - } else { - // /7 mod=11: NFx RDSEED r16/r32/r64 - if ~(has_rdseed) then raise_UD(); - let os = opsize(pfx); - let (rnd, cf_val) = __rdseed64(); - v(r) = rnd[(os - 1) .. 0] & sign_extend(cf_val); - CF = cf_val; - OF = 0b0; - SF = 0b0; - ZF = 0b0; - AF = 0b0; - PF = 0b0 - } - }, - RM_mem(m) => { - // /7 mem: VMPTRST — store current VMCS pointer - vmx_exit_vmx_insn(VMEXIT_VMPTRST); - exec_vmptrst(seg_linear(m, 8)) - }, - }, - _ => raise_UD(), - } - }, - - // 0F C8-CF: BSWAP r32/r64 (register in opcode) - op if 200 <= op & op <= 207 => { - let reg_field : range(0, 7) = op - 200; - let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); - let os = opsize(pfx); - if os == 16 then { - // SDM: the result is undefined for a 16-bit operand. - v(reg) = undefined : word - } else { - v(os, reg) = bswap(v(os, reg)) - } - }, - - // 66/F2 0F 78 and 0F 79 with SSE4A: EXTRQ and INSERTQ (exec_sse4a) - op if (op == 120 | op == 121) & has_sse4a - & (get_mandatory_prefix(pfx) == MP_66 | get_mandatory_prefix(pfx) == MP_F2) => - exec_sse4a(op, pfx), - - // 0F 78: VMREAD r/m64, r64 (SDM Vol.3C §31.2.4) - // In 64-bit mode, operand size is always 64 bits. - 120 => { - vmx_exit_vmx_insn(VMEXIT_VMREAD); - let (reg, dest) = fetch_modrm(pfx); - exec_vmread(pfx, dest, reg.gpr_idx) - }, - - // 0F 79: VMWRITE r64, r/m64 (SDM Vol.3C §31.2.5) - 121 => { - vmx_exit_vmx_insn(VMEXIT_VMWRITE); - let (reg, src) = fetch_modrm(pfx); - exec_vmwrite(pfx, src, reg.gpr_idx) - }, - - _ => raise_UD(), - } -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail deleted file mode 100644 index ff1cf2490..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_dispatch.sail +++ /dev/null @@ -1,2358 +0,0 @@ -// x86-64 — Opcode Dispatch -// -// Central dispatch for 1-byte, 2-byte (0F xx), and 3-byte (0F 38/3A xx) -// opcode maps. Routes to category-specific handlers. - -// XCHG — Exchange Register/Memory with Register -val exec_xchg_reg_reg : (gpr_idx, gpr_idx, operand_size) -> unit -function exec_xchg_reg_reg(a, b, os) = { - let temp = v(os, a); - v(a) = v(os, b); - v(b) = temp -} - -// IN — Input from Port -val exec_in : (word, operand_size) -> unit -function exec_in(port, os) = { - check_io_permission(port, if os == 64 then 4 else os / 8); - note_io_access(port, if os == 64 then 4 else os / 8); - match os { - 8 => v(RAX) = __port_in8(port), - 16 => v(RAX) = __port_in16(port), - 32 => v(RAX) = __port_in32(port), - 64 => v(RAX) = __port_in32(port) - } -} - -// OUT — Output to Port -val exec_out : (word, operand_size) -> unit -function exec_out(port, os) = { - check_io_permission(port, if os == 64 then 4 else os / 8); - note_io_access(port, if os == 64 then 4 else os / 8); - match os { - 8 => __port_out8(port, v(RAX)), - 16 => __port_out16(port, v(RAX)), - 32 => __port_out32(port, v(RAX)), - 64 => __port_out32(port, v(RAX)) - } -} - -// JMP near relative: RIP := decode_pos + sign-extended offset - -// POP — Pop a Value from the Stack -val exec_pop_reg : (gpr_idx, {16, 32, 64}) -> unit -function exec_pop_reg(dst, os) = { - match os { - 16 => v(dst) = pop(16), - 32 => v(dst) = if cur_mode == LongMode then pop(64)[31..0] else pop(32), - 64 => v(dst) = pop(64), - } -} - -// LOOP/LOOPcc — Loop According to ECX Counter -enum LoopVariant = { LOOP_always, LOOP_e, LOOP_ne } - -// os is the operand size of the near branch (opsize_forced64), which -// truncates the target: "IF OperandSize = 16 THEN tempEIP := tempEIP AND -// 0000FFFFH" (SDM Vol.2A LOOP/LOOPcc). -val exec_loop : (byte, LoopVariant, address_size, {16, 32, 64}) -> unit -function exec_loop(rel8, variant, asz, os) = { - v(RCX) = v(asz, RCX) - 1; - let count_nonzero : bool = v(asz, RCX) != zeros(); - let take_branch : bool = match variant { - LOOP_always => count_nonzero, - LOOP_e => if count_nonzero then ZF == 0b1 else false, - LOOP_ne => if count_nonzero then ZF == 0b0 else false, - }; - if take_branch then { - next_rip = Some(zero_extend((decode_pos + sign_extend(rel8))[(os - 1) .. 0])); - } -} - -// Map rows 00-3F to ALU operation. Each operation occupies 8 opcodes. -val opcode_to_alu : range(0, 63) -> ALUOp -function opcode_to_alu(op) = { - let row : range(0, 7) = unsigned(to_bits_truncate(3, op / 8)); - match row { - 0 => ALU_ADD, - 1 => ALU_OR, - 2 => ALU_ADC, - 3 => ALU_SBB, - 4 => ALU_AND, - 5 => ALU_SUB, - 6 => ALU_XOR, - 7 => ALU_CMP, - } -} - -// ALU dispatch for opcodes 00-3F (columns 0-5). -val dispatch_alu_opcode : (range(0, 63), Prefixes) -> unit -function dispatch_alu_opcode(op, pfx) = { - let alu_op = opcode_to_alu(op); - let col : range(0, 7) = op % 8; - // LOCK is only valid on columns 0-1 (r/m destination), not CMP, and only with memory - if pfx.has_lock & col >= 2 then raise_UD(); - match col { - // OP r/m8, r8 - 0 => { - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, alu_op == ALU_CMP); - exec_alu_rm_reg(alu_op, dest, reg, 8) - }, - // OP r/m, r (word/dword/qword) - 1 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, alu_op == ALU_CMP); - exec_alu_rm_reg(alu_op, dest, reg, os) - }, - // OP r8, r/m8 - 2 => { - let (reg, src) = fetch_modrm(pfx); - exec_alu_reg_rm(alu_op, reg, src, 8) - }, - // OP r, r/m (word/dword/qword) - 3 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - exec_alu_reg_rm(alu_op, reg, src, os) - }, - // OP AL, imm8 - 4 => { - let imm : byte = fetch(1); - exec_alu_acc_imm(alu_op, imm, 8, pfx) - }, - // OP rAX, imm (Iz: 16 or 32 bit, sign-extended) - 5 => { - let os = opsize(pfx); - let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); - exec_alu_acc_imm(alu_op, imm[(os - 1) .. 0], os, pfx) - }, - _ => raise_UD(), // unreachable - } -} - -// ========================================================================= -// String Operations (MOVS, STOS, LODS, SCAS, CMPS, INS, OUTS, REP) -// ========================================================================= - -// INS — Input from port DX to ES:[RDI] -val exec_ins : (operand_size, address_size) -> unit -function exec_ins(os_in, asz) = { - // SDM: INS only supports 8/16/32-bit I/O; REX.W is ignored. - let os : {8, 16, 32} = if os_in == 64 then 32 else os_in; - let port : word = v(RDX); - check_io_permission(port, os / 8); - let off : qword = zero_extend(v(asz, RDI)); - // INS destination is always ES:DI (not overridable). - let dst : MemRef = struct { seg = ES, addr = off }; - note_io_access(port, os / 8); - match os { - 8 => v(dst) = __port_in8(port), - 16 => v(dst) = __port_in16(port), - 32 => v(dst) = __port_in32(port), - }; - let step = (1 - 2 * unsigned(DF)) * (os / 8); - v(RDI) = (off + step)[asz - 1 .. 0] -} - -// OUTS — Output from DS:[RSI] to port DX -// SDM Vol.2B §OUTS: Source is DS:(E)SI, DS segment may be overridden. -val exec_outs : (operand_size, address_size, Prefixes) -> unit -function exec_outs(os_in, asz, pfx) = { - // SDM: OUTS only supports 8/16/32-bit I/O; REX.W is ignored. - let os : {8, 16, 32} = if os_in == 64 then 32 else os_in; - let port : word = v(RDX); - check_io_permission(port, os / 8); - let off : qword = zero_extend(v(asz, RSI)); - let src_seg : segreg_idx = match pfx.seg_override { - Some(s) => s, - None() => DS, - }; - let src : MemRef = struct { seg = src_seg, addr = off }; - note_io_access(port, os / 8); - match os { - 8 => __port_out8(port, v(src)), - 16 => __port_out16(port, v(src)), - 32 => __port_out32(port, v(src)), - }; - let step = (1 - 2 * unsigned(DF)) * (os / 8); - v(RSI) = (off + step)[asz - 1 .. 0] -} - -val exec_movs : (operand_size, address_size, Prefixes) -> unit -function exec_movs(os, asz, pfx) = { - let src_off : qword = zero_extend(v(asz, RSI)); - let dst_off : qword = zero_extend(v(asz, RDI)); - // MOVS source is DS:SI (overridable), destination is always ES:DI. - let src_seg : segreg_idx = match pfx.seg_override { - Some(s) => s, - None() => DS, - }; - let src : MemRef = struct { seg = src_seg, addr = src_off }; - let dst : MemRef = struct { seg = ES, addr = dst_off }; - v(dst) = v(os, src); - let step = (1 - 2 * unsigned(DF)) * (os / 8); - v(RSI) = (src_off + step)[asz - 1 .. 0]; - v(RDI) = (dst_off + step)[asz - 1 .. 0]; -} - -val exec_stos : (operand_size, address_size) -> unit -function exec_stos(os, asz) = { - let off : qword = zero_extend(v(asz, RDI)); - // STOS destination is always ES:DI (not overridable). - let dst : MemRef = struct { seg = ES, addr = off }; - v(dst) = v(os, RAX); - let step = (1 - 2 * unsigned(DF)) * (os / 8); - v(RDI) = (off + step)[asz - 1 .. 0] -} - -val exec_lods : (operand_size, address_size, Prefixes) -> unit -function exec_lods(os, asz, pfx) = { - let off : qword = zero_extend(v(asz, RSI)); - // LODS source is DS:SI (overridable). - let src_seg : segreg_idx = match pfx.seg_override { - Some(s) => s, - None() => DS, - }; - let src : MemRef = struct { seg = src_seg, addr = off }; - v(RAX) = v(os, src); - let step = (1 - 2 * unsigned(DF)) * (os / 8); - v(RSI) = (off + step)[asz - 1 .. 0] -} - -val exec_scas : (operand_size, address_size) -> unit -function exec_scas(os, asz) = { - let off : qword = zero_extend(v(asz, RDI)); - // SCAS destination is always ES:DI (not overridable). - let dst : MemRef = struct { seg = ES, addr = off }; - let a = v(os, RAX); - let b = v(os, dst); - update_flags_sub(a - b, a, b); - let step = (1 - 2 * unsigned(DF)) * (os / 8); - v(RDI) = (off + step)[asz - 1 .. 0] -} - -val exec_cmps : (operand_size, address_size, Prefixes) -> unit -function exec_cmps(os, asz, pfx) = { - let src_off : qword = zero_extend(v(asz, RSI)); - let dst_off : qword = zero_extend(v(asz, RDI)); - // CMPS source is DS:SI (overridable), destination is ES:DI. - let src_seg : segreg_idx = match pfx.seg_override { - Some(s) => s, - None() => DS, - }; - let src : MemRef = struct { seg = src_seg, addr = src_off }; - let dst : MemRef = struct { seg = ES, addr = dst_off }; - let a = v(os, src); - let b = v(os, dst); - update_flags_sub(a - b, a, b); - let step = (1 - 2 * unsigned(DF)) * (os / 8); - v(RSI) = (src_off + step)[asz - 1 .. 0]; - v(RDI) = (dst_off + step)[asz - 1 .. 0] -} - -enum RepPrefix = { REP_none, REP_rep, REP_repe, REP_repne } - -// SDM Vol.2A 2.1.1: F2 and F3 repeat string and I/O instructions. -// The ZF termination conditions apply only to CMPS/SCAS (Vol.1 7.3.9.2). -// What F2 does to MOVS, STOS, LODS, INS and OUTS neither manual says: "The -// REPE/REPZ and REPNE/REPNZ prefixes are used only with the CMPS and SCAS -// instructions" (SDM Vol.1 §7.3.9.2, p.7-19), and REPNE "can only be used -// with the CMPSx and SCASx instructions" (APM Vol.1 §3.5.1.4, p.79). The -// model repeats them by the count alone, as for F3, on both vendors. -enum StringOp = { STR_movs, STR_stos, STR_lods, STR_cmps, STR_scas, STR_ins, STR_outs } - -val exec_rep : (RepPrefix, StringOp, operand_size, address_size, Prefixes) -> unit -function exec_rep(prefix, op, os, asz, pfx) = { - while v(asz, RCX) != zeros() do { - match op { - STR_movs => exec_movs(os, asz, pfx), - STR_stos => exec_stos(os, asz), - STR_lods => exec_lods(os, asz, pfx), - STR_cmps => exec_cmps(os, asz, pfx), - STR_scas => exec_scas(os, asz), - STR_ins => exec_ins(os, asz), - STR_outs => exec_outs(os, asz, pfx), - }; - v(RCX) = v(asz, RCX) - 1; - if prefix == REP_repe & ZF == 0b0 then return (); - if prefix == REP_repne & ZF == 0b1 then return (); - // A data breakpoint hit by this iteration, or single-step, is reported - // after the iteration: the instruction resumes for the remaining count - // (RIP back at its first byte; SDM Vol.3B §20.3.1.1, §20.3.1.2). A - // data breakpoint may wait for later iterations: with fast-string - // operation "the processor recognizes interrupts and data breakpoints - // only on boundaries between these groups", whose size is - // implementation-specific (SDM Vol.1 §7.3.9.3 p.7-19), and "All - // breakpoint conditions, except certain string operations preceded by - // a repeat prefix, are exact" (APM Vol.2 §13.1.1.4 p.397). So whether - // the group goes on is undefined. - let group_continues : bool = undefined; - if (pending_dbp != 0x0 & ~(group_continues) | TF == 0b1) & v(asz, RCX) != zeros() then { - next_rip = Some(insn_start); - rep_trap_rf = true; - return () - } - } -} - -// ========================================================================= -// 2-Byte Opcode Map (0F xx) Dispatch -// ========================================================================= - -// Check if a 2-byte opcode (0F xx) is lockable. -// Lockable: BTS (0F AB), BTR (0F B3), BTC (0F BB), -// CMPXCHG (0F B0, 0F B1), XADD (0F C0, 0F C1), CMPXCHG8B/16B (0F C7) -val is_lockable_2byte : range(0, 255) -> bool -function is_lockable_2byte(op) = match op { - 171 => true, // 0F AB: BTS - 176 => true, // 0F B0: CMPXCHG - 177 => true, // 0F B1: CMPXCHG - 179 => true, // 0F B3: BTR - 186 => true, // 0F BA: Group 8 (BTS/BTR/BTC imm, not BT) - 187 => true, // 0F BB: BTC - 192 => true, // 0F C0: XADD - 193 => true, // 0F C1: XADD - 199 => true, // 0F C7: CMPXCHG8B/16B - _ => false, -} - -// What one mandatory prefix lets a legacy-encoded SIMD opcode take in -// ModR/M.rm: nothing (the opcode is undefined with that prefix), only a -// register, only memory, or either. -enum RMForms = { RMF_None, RMF_Reg, RMF_Mem, RMF_Any } - -// rm_forms(mp, NP, 66, F3, F2): the entry of an opcode's row for prefix mp. -val rm_forms : (MandatoryPrefix, RMForms, RMForms, RMForms, RMForms) -> RMForms -function rm_forms(mp, np, p66, f3, f2) = match mp { - MP_NONE => np, - MP_66 => p66, - MP_F3 => f3, - MP_F2 => f2, -} - -// The forms of an instruction of a CPUID feature: none on a processor -// without the feature, whose encodings are undefined there. -val with_feature : (bool, RMForms) -> RMForms -function with_feature(present, forms) = if present then forms else RMF_None - -// The SIMD opcodes of the 0F map (those dispatch_2byte_sse_fp, -// dispatch_2byte_sse_int and dispatch_mmx implement) by mandatory prefix, -// F2/F3 taking precedence over 66 (get_mandatory_prefix), as the opcode -// tables of the SDM Vol.2 instruction pages give them. A prefix that an -// opcode's table does not list leaves it undefined (#UD): the MMX forms -// are "NP", which allows no 66, F2 or F3 (SDM Vol.2 §3.1.1.1). An r/m -// operand the table writes m64, m128 or mem is memory only, and one it -// writes mm, xmm or reg alone a register only. reg is ModR/M.reg, the -// opcode extension of the 0F 71-73 groups. Every form is SSE, SSE2 or -// MMX, which an x86-64 processor has, but for the SSE3 ones. -val simd_0f_forms : (range(0, 255), MandatoryPrefix, range(0, 7)) -> RMForms -function simd_0f_forms(op, mp, reg) = match op { - // MOVUPS, MOVUPD, MOVSS, MOVSD (load and store) - op if op == 16 | op == 17 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // MOVLPS xmm, m64 or MOVHLPS xmm, xmm; MOVLPD xmm, m64; MOVSLDUP; MOVDDUP - 18 => rm_forms(mp, RMF_Any, RMF_Mem, with_feature(has_sse3, RMF_Any), - with_feature(has_sse3, RMF_Any)), - // MOVLPS m64, xmm; MOVLPD m64, xmm - 19 => rm_forms(mp, RMF_Mem, RMF_Mem, RMF_None, RMF_None), - // UNPCKLPS, UNPCKLPD; UNPCKHPS, UNPCKHPD - op if op == 20 | op == 21 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // MOVHPS xmm, m64 or MOVLHPS xmm, xmm; MOVHPD xmm, m64; MOVSHDUP - 22 => rm_forms(mp, RMF_Any, RMF_Mem, with_feature(has_sse3, RMF_Any), RMF_None), - // MOVHPS m64, xmm; MOVHPD m64, xmm - 23 => rm_forms(mp, RMF_Mem, RMF_Mem, RMF_None, RMF_None), - // MOVAPS, MOVAPD (load and store) - op if op == 40 | op == 41 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // CVTPI2PS, CVTPI2PD, CVTSI2SS, CVTSI2SD - 42 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // MOVNTPS m128, xmm; MOVNTPD m128, xmm; and the SSE4A MOVNTSS mem32, xmm - // and MOVNTSD mem64, xmm (AMD APM Vol.4), which the SDM leaves undefined - 43 => rm_forms(mp, RMF_Mem, RMF_Mem, with_feature(has_sse4a, RMF_Mem), - with_feature(has_sse4a, RMF_Mem)), - // CVT(T)PS2PI, CVT(T)PD2PI, CVT(T)SS2SI, CVT(T)SD2SI - op if op == 44 | op == 45 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // UCOMISS, UCOMISD; COMISS, COMISD - op if op == 46 | op == 47 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // MOVMSKPS reg, xmm; MOVMSKPD reg, xmm - 80 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), - // SQRTPS, SQRTPD, SQRTSS, SQRTSD - 81 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // RSQRTPS, RSQRTSS; RCPPS, RCPSS - op if op == 82 | op == 83 => rm_forms(mp, RMF_Any, RMF_None, RMF_Any, RMF_None), - // ANDPS/PD, ANDNPS/PD, ORPS/PD, XORPS/PD - op if 84 <= op & op <= 87 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // ADD, MUL, CVTPS2PD/CVTPD2PS/CVTSS2SD/CVTSD2SS (PS, PD, SS, SD) - op if 88 <= op & op <= 90 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // CVTDQ2PS, CVTPS2DQ, CVTTPS2DQ - 91 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), - // SUB, MIN, DIV, MAX (PS, PD, SS, SD) - op if 92 <= op & op <= 95 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // PUNPCKL*, PACKSSWB, PCMPGT*, PACKUSWB, PUNPCKH*, PACKSSDW (mm, xmm) - op if 96 <= op & op <= 107 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // PUNPCKLQDQ, PUNPCKHQDQ - op if op == 108 | op == 109 => rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_None), - // MOVD/MOVQ mm, r/m; MOVD/MOVQ xmm, r/m - 110 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // MOVQ mm, mm/m64; MOVDQA; MOVDQU (load) - 111 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), - // PSHUFW, PSHUFD, PSHUFHW, PSHUFLW - 112 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // Groups 12 and 13: PSRLW/D /2, PSRAW/D /4, PSLLW/D /6 (mm, xmm) - op if op == 113 | op == 114 => - if reg == 2 | reg == 4 | reg == 6 - then rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None) - else RMF_None, - // Group 14: PSRLQ /2, PSLLQ /6 (mm, xmm); PSRLDQ /3, PSLLDQ /7 (xmm) - 115 => - if reg == 2 | reg == 6 - then rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None) - else if reg == 3 | reg == 7 - then rm_forms(mp, RMF_None, RMF_Reg, RMF_None, RMF_None) - else RMF_None, - // PCMPEQB, PCMPEQW, PCMPEQD (mm, xmm) - op if 116 <= op & op <= 118 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // HADDPD, HADDPS; HSUBPD, HSUBPS - op if op == 124 | op == 125 => - with_feature(has_sse3, rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_Any)), - // MOVD/MOVQ r/m, mm; MOVD/MOVQ r/m, xmm; MOVQ xmm, xmm/m64 - 126 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), - // MOVQ mm/m64, mm; MOVDQA; MOVDQU (store) - 127 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_None), - // CMPPS, CMPPD, CMPSS, CMPSD - 194 => rm_forms(mp, RMF_Any, RMF_Any, RMF_Any, RMF_Any), - // PINSRW mm, r32/m16; PINSRW xmm, r32/m16 - 196 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // PEXTRW reg, mm; PEXTRW reg, xmm - 197 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), - // SHUFPS, SHUFPD - 198 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // ADDSUBPD, ADDSUBPS - 208 => with_feature(has_sse3, rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_Any)), - // PSRLW, PSRLD, PSRLQ, PADDQ, PMULLW (mm, xmm) - op if 209 <= op & op <= 213 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // MOVQ xmm/m64, xmm; MOVQ2DQ xmm, mm; MOVDQ2Q mm, xmm - 214 => rm_forms(mp, RMF_None, RMF_Any, RMF_Reg, RMF_Reg), - // PMOVMSKB reg, mm; PMOVMSKB reg, xmm - 215 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), - // PSUBUS*, PMINUB, PAND, PADDUS*, PMAXUB, PANDN, PAVGB, PSRAW, PSRAD, - // PAVGW, PMULHUW, PMULHW (mm, xmm) - op if 216 <= op & op <= 229 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // CVTTPD2DQ, CVTDQ2PD, CVTPD2DQ - 230 => rm_forms(mp, RMF_None, RMF_Any, RMF_Any, RMF_Any), - // MOVNTQ m64, mm; MOVNTDQ m128, xmm - 231 => rm_forms(mp, RMF_Mem, RMF_Mem, RMF_None, RMF_None), - // PSUBS*, PMINSW, POR, PADDS*, PMAXSW, PXOR (mm, xmm) - op if 232 <= op & op <= 239 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // LDDQU xmm, mem - 240 => with_feature(has_sse3, rm_forms(mp, RMF_None, RMF_None, RMF_None, RMF_Mem)), - // PSLLW, PSLLD, PSLLQ, PMULUDQ, PMADDWD, PSADBW (mm, xmm) - op if 241 <= op & op <= 246 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - // MASKMOVQ mm, mm; MASKMOVDQU xmm, xmm - 247 => rm_forms(mp, RMF_Reg, RMF_Reg, RMF_None, RMF_None), - // PSUBB/W/D/Q, PADDB/W/D (mm, xmm) - op if 248 <= op & op <= 254 => rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None), - _ => RMF_None, -} - -// The SIMD opcodes of the 0F 38 map, as simd_0f_forms gives those of the -// 0F map: the SSSE3 forms with no prefix (MMX registers) or 66 (XMM -// registers), the 66 forms of SSE4.1, SSE4.2, GFNI and AES-NI, and the NP -// forms of SHA. The general-purpose instructions of the map (MOVBE, -// CRC32, ADCX, ADOX, INVEPT, INVPCID, MOVDIRI, MOVDIR64B, ENQCMD and -// ENQCMDS) are decoded ahead of these. -val simd_0f38_forms : (range(0, 255), MandatoryPrefix) -> RMForms -function simd_0f38_forms(op, mp) = { - let p66 : RMForms = rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_None); - match op { - // PSHUFB, PHADDW/D, PHADDSW, PMADDUBSW, PHSUBW/D, PHSUBSW, PSIGNB/W/D, - // PMULHRSW; PABSB/W/D (mm, xmm) - op if op <= 11 | (28 <= op & op <= 30) => - with_feature(has_ssse3, rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None)), - // PBLENDVB, BLENDVPS, BLENDVPD, PTEST; PMOVSX*; PMULDQ, PCMPEQQ, - // PACKUSDW; PMOVZX*; PMINSB ... PMULLD, PHMINPOSUW - op if op == 16 | op == 20 | op == 21 | op == 23 | (32 <= op & op <= 37) - | op == 40 | op == 41 | op == 43 | (48 <= op & op <= 53) - | (56 <= op & op <= 65) => with_feature(has_sse4_1, p66), - // MOVNTDQA xmm, m128 - 42 => with_feature(has_sse4_1, rm_forms(mp, RMF_None, RMF_Mem, RMF_None, RMF_None)), - // PCMPGTQ - 55 => with_feature(has_sse4_2, p66), - // SHA1NEXTE, SHA1MSG1, SHA1MSG2, SHA256RNDS2, SHA256MSG1, SHA256MSG2 - op if 200 <= op & op <= 205 => - with_feature(has_sha, rm_forms(mp, RMF_Any, RMF_None, RMF_None, RMF_None)), - // GF2P8MULB - 207 => with_feature(has_gfni, p66), - // AESIMC, AESENC, AESENCLAST, AESDEC, AESDECLAST - op if 219 <= op & op <= 223 => with_feature(has_aesni, p66), - _ => RMF_None, - } -} - -// The opcodes of the 0F 3A map, all SIMD: the 66 forms of SSE4.1, SSE4.2, -// PCLMULQDQ, GFNI and AES-NI, PALIGNR (SSSE3) with no prefix or 66, and -// the NP SHA1RNDS4. -val simd_0f3a_forms : (range(0, 255), MandatoryPrefix) -> RMForms -function simd_0f3a_forms(op, mp) = { - let p66 : RMForms = rm_forms(mp, RMF_None, RMF_Any, RMF_None, RMF_None); - match op { - // ROUNDPS/PD/SS/SD, BLENDPS/PD, PBLENDW - op if 8 <= op & op <= 14 => with_feature(has_sse4_1, p66), - // PALIGNR (mm, xmm) - 15 => with_feature(has_ssse3, rm_forms(mp, RMF_Any, RMF_Any, RMF_None, RMF_None)), - // PEXTRB, PEXTRW, PEXTRD/Q, EXTRACTPS; PINSRB, INSERTPS, PINSRD/Q; - // DPPS, DPPD, MPSADBW - op if (20 <= op & op <= 23) | (32 <= op & op <= 34) | (64 <= op & op <= 66) => - with_feature(has_sse4_1, p66), - // PCLMULQDQ - 68 => with_feature(has_pclmulqdq, p66), - // PCMPESTRM, PCMPESTRI, PCMPISTRM, PCMPISTRI - op if 96 <= op & op <= 99 => with_feature(has_sse4_2, p66), - // SHA1RNDS4 - 204 => with_feature(has_sha, rm_forms(mp, RMF_Any, RMF_None, RMF_None, RMF_None)), - // GF2P8AFFINEQB, GF2P8AFFINEINVQB - op if op == 206 | op == 207 => with_feature(has_gfni, p66), - // AESKEYGENASSIST - 223 => with_feature(has_aesni, p66), - _ => RMF_None, - } -} - -// The checks of a legacy-encoded SIMD instruction (MMX or SSE) of opcode -// op in map 1 (0F), 2 (0F 38) or 3 (0F 3A), made once its opcode is -// fetched and before its handler fetches and reads its operands: #UD for a -// mandatory prefix that leaves the opcode undefined, an r/m form it does -// not take, or a CPUID feature the processor lacks, all of which are -// decided on the opcode and the ModR/M byte; then the #UD of CR0.EM and -// the #NM of CR0.TS (check_cr0_sse). These are faults from decoding the -// instruction (SDM Vol.3A §7.9, Table 7-2), so they come ahead of the #GP, -// #PF or #AC of an operand access, which arise only as the instruction -// executes. Of the #UD and #NM, the manuals give no order; the model -// raises the #UD of the encoding first (exceptions.sail). -val check_legacy_simd : (range(1, 3), range(0, 255), Prefixes) -> unit -function check_legacy_simd(map, op, pfx) = { - let modrm = peek_modrm(); - let is_reg : bool = modrm[7..6] == 0b11; - let mp = get_mandatory_prefix(pfx); - let forms : RMForms = match map { - 1 => simd_0f_forms(op, mp, unsigned(modrm[5..3])), - 2 => simd_0f38_forms(op, mp), - 3 => simd_0f3a_forms(op, mp), - }; - match forms { - RMF_None => raise_UD(), - RMF_Reg => if ~(is_reg) then raise_UD(), - RMF_Mem => if is_reg then raise_UD(), - RMF_Any => (), - }; - check_cr0_sse() -} - -val dispatch_opcode_2byte : (byte, Prefixes) -> unit -function dispatch_opcode_2byte(opcode, pfx) = { - let op : range(0, 255) = unsigned(opcode); - // LOCK prefix is only valid on specific 2-byte opcodes; #UD otherwise. - if pfx.has_lock & ~(is_lockable_2byte(op)) then raise_UD(); - match op { - // 0F 38: 3-byte escape (SSSE3/SSE4/AES-NI) - 56 => { - let opcode3 = fetch(1); - let op3 : range(0, 255) = unsigned(opcode3); - if op3 == 246 then { - // ADCX (66) / ADOX (F3) - // The 66/F3 prefix is a mandatory prefix, NOT an operand size override. - // Operand size is determined by REX.W only: W=1 → 64-bit, else 32-bit. - if ~(has_adx) then raise_UD(); - let mp = get_mandatory_prefix(pfx); - let os : {32, 64} = if pfx.rex_w then 64 else 32; - let (reg, src) = fetch_modrm(pfx); - let src_val = v(os, src); - if mp == MP_66 then { - let a = v(os, reg); - let result = a + src_val + zero_extend(CF); - let w = (0b0 @ a) + (0b0 @ src_val) + zero_extend(CF); - CF = w[os]; - v(reg) = result - } else if mp == MP_F3 then { - let a = v(os, reg); - let result = a + src_val + zero_extend(OF); - let w = (0b0 @ a) + (0b0 @ src_val) + zero_extend(OF); - OF = w[os]; - v(reg) = result - } else { - raise_UD() - } - } else if op3 == 128 & get_mandatory_prefix(pfx) == MP_66 then { - // 66 0F 38 80: INVEPT r64, m128 — Invalidate EPT TLB - if cur_cpl != 0 then raise_GP0(); - if ~(in_vmx_root) & ~(in_vmx_non_root) then raise_UD(); - if in_vmx_non_root then { - vmcs.exit_instr_length = (decode_pos - insn_start)[31..0]; - throw VMExit(VMEXIT_INVEPT, 0x0000000000000000) - }; - let (reg, src) = fetch_modrm(pfx); - let _ : xmmword = rm_mem(src); // consume operand - __tlb_flush(); - vmx_succeed() - } else if op3 == 130 & get_mandatory_prefix(pfx) == MP_66 then { - // 66 0F 38 82: INVPCID r64, m128 — Invalidate TLB by PCID. The - // register form is undefined, a decode-time #UD ahead of the - // privilege check (SDM Vol.3A §7.9). - let (reg, src) = fetch_modrm(pfx); - let m : MemRef = match src { RM_mem(m) => m, RM_reg(_) => raise_UD() }; - if cur_cpl != 0 then raise_GP0(); - let desc : xmmword = read_mem(m); - let inv_type : qword = v(reg); - if unsigned(inv_type) > 3 then raise_GP0(); - let reserved : bits(52) = desc[63..12]; - let pcid : bits(12) = desc[11..0]; - // The bits of the linear address that are all equal when it is - // canonical: 63:47, or 63:56 with 5-level paging (CR4.LA57), as in - // seg_linear. - let top17 : bits(17) = - if CR4[12] == 0b1 then sign_extend(desc[127..120]) else desc[127..111]; - // SDM INVPCID, 64-bit mode #GP(0): bits 63:12 of the descriptor - // are not all zero (any type); CR4.PCIDE = 0, type 0 or 1, and a - // nonzero PCID; type 0 and a non-canonical linear address. - let is_type_01 : bit = ~(inv_type[1]); - let is_type_0 : bit = ~(inv_type[1] | inv_type[0]); - let bad_reserved : bit = ~(((0b0 @ reserved) - 1)[52]); - let bad_pcid : bit = ~(((0b0 @ pcid) - 1)[12]) & ~(CR4[17]); // CR4.PCIDE - let diff : bits(17) = top17 ^ sign_extend(top17[16]); - let non_canonical : bit = ~(((0b0 @ diff) - 1)[17]); - let fault : bit = bad_reserved | (is_type_01 & bad_pcid) | (is_type_0 & non_canonical); - if fault == 0b1 then raise_GP0(); - __tlb_flush() - } else if (op3 == 240 | op3 == 241) then { - // MOVBE (0F 38 F0/F1) or CRC32 (F2 0F 38 F0/F1) - let mp = get_mandatory_prefix(pfx); - if mp == MP_F2 then { - if ~(has_crc32) then raise_UD(); - let (reg, src) = fetch_modrm(pfx); - let os = if op3 == 240 then 8 else opsize(pfx); - let src_val = v(os, src); - let result : bits(32) = crc32c(v(32, reg), src_val); - if pfx.rex_w then { - v(reg) = zero_extend(64, result) - } else { - v(reg) = result - } - } else { - // MOVBE (0F 38 F0/F1) — load/store with byte swap. The opcode - // is defined with no prefix, 66 (16-bit operands) and F2 (CRC32) - // only (SDM Vol.2B MOVBE, CRC32): F3 is #UD. - if mp == MP_F3 then raise_UD(); - if ~(has_movbe) then raise_UD(); - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - if op3 == 240 then { - v(os, reg) = bswap(rm_mem(os, dest)) - } else { - rm_mem(dest) = bswap(v(os, reg)) - } - } - } else if op3 == 249 & get_mandatory_prefix(pfx) == MP_NONE then { - // MOVDIRI m32/m64, r32/r64 (NP 0F 38 F9) - if ~(has_movdiri) then raise_UD(); - let (reg, dest) = fetch_modrm(pfx); - let os = if pfx.rex_w then 64 else 32; - rm_mem(dest) = v(os, reg) - } else if op3 == 248 & get_mandatory_prefix(pfx) == MP_66 then { - // MOVDIR64B r, m512 (66 0F 38 F8) - exec_movdir64b(pfx) - } else if op3 == 248 & (get_mandatory_prefix(pfx) == MP_F2 - | get_mandatory_prefix(pfx) == MP_F3) then { - // ENQCMD r, m512 (F2 0F 38 F8) and ENQCMDS r, m512 (F3 0F 38 F8) - exec_enqcmd(pfx, get_mandatory_prefix(pfx) == MP_F3) - } else { - // The SIMD opcodes (simd_0f38_forms) - check_legacy_simd(2, op3, pfx); - match op3 { - // BLENDVPS or BLENDVPD - op3 if op3 == 20 | op3 == 21 => dispatch_3byte_38_sse_fp(opcode3, pfx), - // SHA extensions (NP 0F 38 C8-CD) - op3 if 200 <= op3 & op3 <= 205 => { - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let src_xmm : xmmword = decode_xmm_src(src); - match op3 { - // SHA1NEXTE xmm1, xmm2/m128 - 200 => ZMM[xreg][127..0] = sha1nexte(read_simd(xreg), src_xmm), - // SHA1MSG1 xmm1, xmm2/m128 - 201 => ZMM[xreg][127..0] = sha1msg1(read_simd(xreg), src_xmm), - // SHA1MSG2 xmm1, xmm2/m128 - 202 => ZMM[xreg][127..0] = sha1msg2(read_simd(xreg), src_xmm), - // SHA256RNDS2 xmm1, xmm2/m128, - 203 => ZMM[xreg][127..0] = sha256rnds2(read_simd(xreg), src_xmm, read_simd(0)), - // SHA256MSG1 xmm1, xmm2/m128 - 204 => ZMM[xreg][127..0] = sha256msg1(read_simd(xreg), src_xmm), - // SHA256MSG2 xmm1, xmm2/m128 - 205 => ZMM[xreg][127..0] = sha256msg2(read_simd(xreg), src_xmm), - _ => raise_UD(), - } - }, - _ => dispatch_3byte_38_sse_int(opcode3, pfx), - } - } - }, - // 0F 3A: 3-byte escape (SSE4/AES-NI with imm8), all SIMD (simd_0f3a_forms) - 58 => { - let opcode3 = fetch(1); - let op3 : range(0, 255) = unsigned(opcode3); - check_legacy_simd(3, op3, pfx); - match op3 { - // SSE4.1 FP: ROUNDPS/PD/SS/SD, BLENDPS/PD, PEXTRW, EXTRACTPS, INSERTPS, DPPS, DPPD - op3 if (8 <= op3 & op3 <= 13) | op3 == 21 | op3 == 23 | op3 == 33 | op3 == 64 | op3 == 65 => - dispatch_3byte_3a_sse_fp(opcode3, pfx), - 204 => { - // SHA1RNDS4 xmm1, xmm2/m128, imm8 (NP 0F 3A CC /r ib) - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let imm : byte = fetch(1); - let src_xmm : xmmword = decode_xmm_src(src); - ZMM[xreg][127..0] = sha1rnds4(read_simd(xreg), src_xmm, imm) - }, - _ => dispatch_3byte_3a_sse_int(opcode3, pfx), - } - }, - - // SSE floating-point (data movement, arithmetic, conversion, comparison) - op if (16 <= op & op <= 23) | (40 <= op & op <= 47) | (80 <= op & op <= 95) - | op == 124 | op == 125 | op == 194 | op == 198 - | op == 208 | op == 214 | op == 230 => { - check_legacy_simd(1, op, pfx); - dispatch_2byte_sse_fp(op, pfx) - }, - - // SSE integer (packed integer arithmetic, logical, shift, pack/unpack) - // and, without a mandatory prefix, MMX (dispatch_mmx) - op if (96 <= op & op <= 118) | op == 126 | op == 127 | op == 196 | op == 197 - | (209 <= op & op <= 213) | (215 <= op & op <= 229) - | (231 <= op & op <= 255) => { - check_legacy_simd(1, op, pfx); - dispatch_2byte_sse_int(op, pfx) - }, - - // GPR and system operations (everything else) - _ => dispatch_2byte_gpr(op, pfx), - } -} - -// ========================================================================= -// 1-Byte Opcode Map Dispatch -// ========================================================================= - -// Check if a 1-byte opcode is lockable (LOCK prefix valid with memory dest). -// Lockable: ALU cols 0-1 (00-3F), 80-83 (ALU imm), 86-87 (XCHG), -// F6/F7 (NOT /2, NEG /3), FE/FF (INC /0, DEC /1) -val is_lockable_1byte : range(0, 255) -> bool -function is_lockable_1byte(op) = { - match op { - op if op <= 63 & (op % 8 == 0 | op % 8 == 1) => true, // ALU r/m, r - op if 128 <= op & op <= 131 => true, // 80-83: ALU r/m, imm - op if 134 <= op & op <= 135 => true, // 86-87: XCHG - op if 246 <= op & op <= 247 => true, // F6-F7: TEST/NOT/NEG/MUL/DIV - op if 254 <= op & op <= 255 => true, // FE-FF: INC/DEC - _ => false, - } -} - -// IRET uses the privilege before the return to decide which flags can -// change (SDM Vol.2A, RETURN-TO-SAME/OUTER-PRIVILEGE-LEVEL, pp.3-493, -// 3-495). In particular a ring-3 IRET cannot clear or raise IOPL. -val restore_iret_flags : ({16, 32, 64}, qword, cpl_t, bool) -> unit -function restore_iret_flags(os, image, old_cpl, protected_return) = { - var flags : qword = image; - if protected_return then { - if old_cpl > unsigned(IOPL) then flags[9] = IF_flag; - if old_cpl != 0 then flags[13..12] = IOPL - }; - if os == 16 then - write_rflags((read_rflags() & 0xFFFFFFFFFFFF0000) | zero_extend(flags[15..0])) - else { - write_rflags(flags); - RF = flags[16]; - if protected_return & old_cpl == 0 then { - VIF = flags[19]; - VIP = flags[20] - } - } -} - -// Legacy protected-mode RETF. SDM Vol.2B RET, Protected Mode and -// RETURN-TO-SAME/OUTER-PRIVILEGE-LEVEL, pp.4-571--4-575. In particular, -// a not-present return CS must fault before its descriptor is installed. -val exec_legacy_retf : ({16, 32}, option(word)) -> unit -function exec_legacy_retf(os, maybe_imm) = { - let sas = stack_addr_size(); - let old_sp : qword = zero_extend(v(sas, RSP)); - let adjustment : word = match maybe_imm { Some(i) => i, None() => 0x0000 }; - check_seg_limit(SS, old_sp, 2 * (os / 8)); - let (ip, cs) = pop_far_pointer(os); - if cs[15..2] == zeros() then raise_GP0(); - let code = read_descriptor(cs); - let rpl : cpl_t = unsigned(cs[1..0]); - let err = selector_error_code(cs); - if code.seg_s == 0b0 | code.seg_type[3] == 0b0 | rpl < cur_cpl then - throw Fault(EXN_GP, err); - if (code.seg_type[2] == 0b1 & code.seg_dpl > rpl) | - (code.seg_type[2] == 0b0 & code.seg_dpl != rpl) then - throw Fault(EXN_GP, err); - if code.seg_present == 0b0 then throw Fault(EXN_NP, err); - var accessed_code = code; - - if rpl > cur_cpl then { - check_seg_limit(SS, old_sp, 4 * (os / 8) + unsigned(adjustment)); - v(sas, RSP) = v(sas, RSP) + zero_extend(adjustment); - let (sp, ss) = pop_far_pointer(os); - if ss[15..2] == zeros() then raise_GP0(); - let stack = read_descriptor(ss); - let ss_err = selector_error_code(ss); - if unsigned(ss[1..0]) != rpl | stack.seg_dpl != rpl | - stack.seg_s == 0b0 | stack.seg_type[3] == 0b1 | - stack.seg_type[1] == 0b0 then throw Fault(EXN_GP, ss_err); - if stack.seg_present == 0b0 then throw Fault(EXN_SS, ss_err); - if unsigned(ip) > unsigned(code.seg_limit) then raise_GP0(); - // All faulting checks precede architectural segment/CPL changes. - accessed_code = access_segment_descriptor(cs, code); - let accessed_stack = access_segment_descriptor(ss, stack); - write_segreg(SS, ss); - SegCache[SS] = accessed_stack; - v(RSP) = sp; - cur_cpl = rpl; - foreach (seg from 0 to 5) { - if seg != CS & seg != SS then { - let desc = SegCache[seg]; - if read_segreg(seg)[15..2] == zeros() | - (desc.seg_dpl < rpl & - (desc.seg_type[3] == 0b0 | desc.seg_type[2] == 0b0)) then - write_segreg(seg, 0x0000) - } - }; - let new_sas = stack_addr_size(); - v(new_sas, RSP) = v(new_sas, RSP) + zero_extend(adjustment) - } else { - if unsigned(ip) > unsigned(code.seg_limit) then raise_GP0(); - accessed_code = access_segment_descriptor(cs, code); - v(sas, RSP) = v(sas, RSP) + zero_extend(adjustment) - }; - write_segreg(CS, cs); - SegCache[CS] = accessed_code; - next_rip = Some(ip) -} - -// RETF — Far return (opcodes CA, CB). -// In 64-bit mode, default operand size is 32; REX.W makes it 64. -// Same-privilege: pop RIP, CS. -// Outer-privilege (RPL > CPL): also pop RSP, SS, then set CPL = RPL. -// SDM Vol.2 RET — IA-32e Mode Operation. -val exec_retf : (Prefixes, option(word)) -> unit -function exec_retf(pfx, maybe_imm) = { - if cur_mode == ProtectedMode & EFER[10] == 0b0 then { - exec_legacy_retf(if opsize(pfx) == 32 then 32 else 16, maybe_imm); - return () - }; - // Operand size: in 64-bit mode, default is 32, REX.W → 64, 66h → 16. - // In non-64-bit mode, determined by CS.D and 66h prefix. - let os : {16, 32, 64} = if cur_mode == LongMode then { - if pfx.rex_w then 64 - else if pfx.has_opsize then 16 - else 32 - } else { - opsize(pfx) - }; - - // Pop return RIP and CS as a single operation. - let (new_rip, new_cs) = pop_far_pointer(os); - - // In protected/long mode, null CS selector is invalid. - // In real mode, CS=0x0000 is a valid segment (linear address 0). - let protected_return = cur_mode != RealMode & cur_mode != Virtual8086Mode; - if cur_mode == Virtual8086Mode & unsigned(new_rip) > 65535 then raise_GP0(); - if protected_return & new_cs == 0x0000 then { - throw Fault(EXN_GP, 0x00000000) - }; - - let return_rpl : cpl_t = unsigned(new_cs[1..0]); - - // RPL must not be less than current CPL (not applicable in real mode) - if protected_return & return_rpl < cur_cpl then { - throw Fault(EXN_GP, selector_error_code(new_cs)) - }; - - // In real mode, far return simply pops IP and CS — no privilege checks, - // no SS/RSP pop (SDM Vol.2B RET, "Real-address mode or virtual-8086 mode"). - // In protected/long mode, check RPL for inter-privilege return. - if protected_return & return_rpl > cur_cpl then { - // Outer-privilege return (SDM Vol.2B RET — IA-32e Mode): - // First release callee's parameters (RSP += imm16), then pop outer RSP/SS. - match maybe_imm { - Some(imm) => v(RSP) = v(64, RSP) + zero_extend(imm), - None() => (), - }; - let (new_rsp, new_ss) = pop_far_pointer(os); - v(RSP) = new_rsp; - load_segment_register(SS, new_ss); - } else { - // Same-privilege (or real mode): adjust RSP for imm16 if present - match maybe_imm { - Some(imm) => v(RSP) = v(64, RSP) + zero_extend(imm), - None() => (), - } - }; - - // Load new CS (selector + descriptor cache) and set CPL - load_segment_register(CS, new_cs); - // Update cur_mode: in IA-32e mode, CS.L determines 64-bit vs compatibility - if EFER[10] == 0b1 then { - set_mode(if SegCache[CS].seg_l == 0b1 then LongMode else CompatibilityMode) - }; - // In real mode, CPL is always 0 (no privilege levels). - if protected_return then cur_cpl = return_rpl; - - // Set RIP to return address - next_rip = Some(new_rip) -} - -val decode_execute : unit -> unit -function decode_execute() = { - let (pfx, opcode) = scan_prefixes(); - let op : range(0, 255) = unsigned(opcode); - - // LOCK prefix is only valid on specific opcodes; #UD otherwise. - // (Per-instruction checks for register vs memory are done later.) - if pfx.has_lock & ~(is_lockable_1byte(op)) & op != 15 then raise_UD(); - if op <= 63 & op % 8 <= 5 then { - // ALU instructions 00-3F (regular pattern, columns 0-5 only) - dispatch_alu_opcode(op, pfx) - } else { - match op { - // 06: PUSH ES — Push ES selector onto stack (SDM Vol.2B PUSH) - // Invalid in 64-bit mode. The operand size determines the push - // width (push_segreg). - 6 => { - if cur_mode == LongMode then raise_UD(); - push_segreg(opsize(pfx), ES) - }, - - // 07: POP ES — Pop stack into ES (SDM Vol.2B POP) - // Invalid in 64-bit mode. Pops operand-size value, loads low 16 bits - // into ES and updates descriptor cache (load_segment_register). - 7 => { - if cur_mode == LongMode then raise_UD(); - let os = opsize(pfx); - let x : word = match os { - 32 => pop(32)[15..0], - _ => pop(16), - }; - load_data_segment_register(ES, x) - }, - - // 0E: PUSH CS — Push CS selector onto stack (SDM Vol.2B PUSH) - // Invalid in 64-bit mode. - 14 => { - if cur_mode == LongMode then raise_UD(); - push_segreg(opsize(pfx), CS) - }, - - // 0F: Two-byte escape - 15 => { - let opcode2 = fetch(1); - dispatch_opcode_2byte(opcode2, pfx) - }, - - // 16: PUSH SS — Push SS selector onto stack (SDM Vol.2B PUSH) - // Invalid in 64-bit mode. - 22 => { - if cur_mode == LongMode then raise_UD(); - push_segreg(opsize(pfx), SS) - }, - - // 17: POP SS — Pop stack into SS (SDM Vol.2B POP) - // Invalid in 64-bit mode. Loading SS inhibits interrupts and the - // single-step trap until after the next instruction (SDM Vol.3A §7.8.3). - 23 => { - if cur_mode == LongMode then raise_UD(); - let os = opsize(pfx); - let x : word = match os { - 32 => pop(32)[15..0], - _ => pop(16), - }; - load_data_segment_register(SS, x); - ss_shadow = 2 - }, - - // 1E: PUSH DS — Push DS selector onto stack (SDM Vol.2B PUSH) - // Invalid in 64-bit mode. - 30 => { - if cur_mode == LongMode then raise_UD(); - push_segreg(opsize(pfx), DS) - }, - - // 1F: POP DS — Pop stack into DS (SDM Vol.2B POP) - // Invalid in 64-bit mode. - 31 => { - if cur_mode == LongMode then raise_UD(); - let os = opsize(pfx); - let x : word = match os { - 32 => pop(32)[15..0], - _ => pop(16), - }; - load_data_segment_register(DS, x) - }, - - // 27: DAA — Decimal Adjust AL After Addition (SDM Vol.2A) - // #UD in 64-bit mode. Adjusts packed BCD result in AL after ADD. - 39 => { - if cur_mode == LongMode then raise_UD(); - let old_al : byte = v(RAX); - let old_cf = CF; - let lo : bits(4) = old_al[3..0]; - let cond1 : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; - let al1 : byte = old_al + (0x06 & sign_extend(cond1)); - AF = cond1[0]; - let cond2 : bits(1) = ~(((0b0 @ old_al) - 0b0_1001_1010)[8]) | old_cf; - let al_final : byte = al1 + (0x60 & sign_extend(cond2)); - CF = cond2[0]; - v(RAX) = al_final; - update_SF_ZF_PF(al_final); - OF = undefined - }, - - // 2F: DAS — Decimal Adjust AL After Subtraction (SDM Vol.2A) - // #UD in 64-bit mode. Adjusts packed BCD result in AL after SUB. - 47 => { - if cur_mode == LongMode then raise_UD(); - let old_al : byte = v(RAX); - let old_cf = CF; - let lo : bits(4) = old_al[3..0]; - let cond1 : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; - let al1 : byte = old_al - (0x06 & sign_extend(cond1)); - let borrow1 : bits(5) = (0b0 @ lo) - (0b0 @ 0b0110); - AF = cond1[0]; - let cond2 : bits(1) = ~(((0b0 @ old_al) - 0b0_1001_1010)[8]) | old_cf; - let al_final : byte = al1 - (0x60 & sign_extend(cond2)); - CF = (cond2 | (cond1 & (old_cf | borrow1[4])))[0]; - v(RAX) = al_final; - update_SF_ZF_PF(al_final); - OF = undefined - }, - - // 37: AAA — ASCII Adjust After Addition (SDM Vol.2A) - // #UD in 64-bit mode. Adjusts unpacked BCD result in AL/AH. - 55 => { - if cur_mode == LongMode then raise_UD(); - let lo : bits(4) = v(8, RAX)[3..0]; - let cond : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; - let new_ax : word = v(RAX) + (0x0106 & sign_extend(cond)); - v(RAX) = new_ax; - AF = cond[0]; - CF = cond[0]; - v(RAX) = new_ax[7..0] & 0x0F; - OF = undefined; - SF = undefined; - ZF = undefined; - PF = undefined; - }, - - // 3F: AAS — ASCII Adjust AL After Subtraction (SDM Vol.2A) - // #UD in 64-bit mode. Adjusts unpacked BCD result in AL/AH. - 63 => { - if cur_mode == LongMode then raise_UD(); - let lo : bits(4) = v(8, RAX)[3..0]; - let cond : bits(1) = (lo[3] & (lo[2] | lo[1])) | AF; - let new_ax : word = v(RAX) - (0x0106 & sign_extend(cond)); - v(RAX) = new_ax; - AF = cond[0]; - CF = cond[0]; - v(RAX) = new_ax[7..0] & 0x0F; - OF = undefined; - SF = undefined; - ZF = undefined; - PF = undefined; - }, - - // 40-47: INC r32/r16 (compat/protected mode only; REX prefix in 64-bit) - op if 64 <= op & op <= 71 => { - let reg : range(0, 7) = op - 64; - let os = opsize(pfx); - v(reg) = exec_inc(v(os, reg)) - }, - - // 48-4F: DEC r32/r16 (compat/protected mode only; REX prefix in 64-bit) - op if 72 <= op & op <= 79 => { - let reg : range(0, 7) = op - 72; - let os = opsize(pfx); - v(reg) = exec_dec(v(os, reg)) - }, - - // 50-57: PUSH reg (default64) - op if 80 <= op & op <= 87 => { - let reg_field : range(0, 7) = op - 80; - let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); - let os = opsize_default64(pfx); - match os { - 16 => push(16, v(reg)), - 32 => if cur_mode == LongMode - then push(64, zero_extend(v(32, reg))) - else push(32, v(reg)), - 64 => push(64, v(reg)), - } - }, - - // 58-5F: POP reg (default64) - op if 88 <= op & op <= 95 => { - let reg_field : range(0, 7) = op - 88; - let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); - let os = opsize_default64(pfx); - exec_pop_reg(reg, os) - }, - - // 60: PUSHA/PUSHAD — Push All General-Purpose Registers - // #UD in 64-bit mode. Pushes AX..DI (16) or EAX..EDI (32). - // Push order: AX, CX, DX, BX, original SP, BP, SI, DI. - 96 => { - if cur_mode == LongMode then raise_UD(); - let os = opsize(pfx); - match os { - 32 => push(256, v(32, RAX) @ v(32, RCX) @ v(32, RDX) @ v(32, RBX) @ - v(32, RSP) @ v(32, RBP) @ v(32, RSI) @ v(32, RDI)), - _ => push(128, v(16, RAX) @ v(16, RCX) @ v(16, RDX) @ v(16, RBX) @ - v(16, RSP) @ v(16, RBP) @ v(16, RSI) @ v(16, RDI)), - } - }, - - // 61: POPA/POPAD — Pop All General-Purpose Registers - // #UD in 64-bit mode. Pops DI..AX (16) or EDI..EAX (32). - // Pop order: EDI, ESI, EBP, skip ESP slot, EBX, EDX, ECX, EAX. - 97 => { - if cur_mode == LongMode then raise_UD(); - let os = opsize(pfx); - match os { - 32 => { - // Pop all 8 dwords; the ESP slot is discarded. - v(RDI) = pop(32); - v(RSI) = pop(32); - v(RBP) = pop(32); - let _ = pop(32); // skip ESP - v(RBX) = pop(32); - v(RDX) = pop(32); - v(RCX) = pop(32); - v(RAX) = pop(32) - }, - _ => { - // Pop all 8 words; the SP slot is discarded. - v(RDI) = pop(16); - v(RSI) = pop(16); - v(RBP) = pop(16); - let _ = pop(16); // skip SP - v(RBX) = pop(16); - v(RDX) = pop(16); - v(RCX) = pop(16); - v(RAX) = pop(16) - }, - } - }, - - // 62: EVEX prefix, or BOUND (in 16/32-bit mode). - // SDM Vol.2 §2.7.11.2, opcode-independent: in non-64-bit modes the - // byte after 62h decodes as EVEX iff its top two bits (EVEX.R̄X̄) - // are 11b; any other value makes it BOUND's ModR/M, which is then - // necessarily a memory form (mod=11b would have meant EVEX) — - // the same peek-and-disambiguate structure as C4/C5 VEX-vs-LES/LDS. - // In 64-bit mode, 0x62 is always the EVEX prefix. - 98 => { - if cur_mode == LongMode then { - if vex_after_legacy_prefix(pfx) then raise_UD(); - dispatch_evex(pfx) - } else { - let byte2 = fetch(1); - if byte2[7..6] == 0b11 then { - if vex_after_legacy_prefix(pfx) then raise_UD(); - dispatch_evex_with_p0(byte2, pfx) - } else { - // BOUND r16/r32, m16&16/m32&32: #BR if index out of bounds. - let modrm = byte2; - let src = modrm_rm(modrm, pfx); - match src { - RM_reg(_) => raise_UD(), // unreachable: mod=11 is EVEX - RM_mem(m) => { - let os = opsize(pfx); - assert(os <= 32); - let reg = modrm_reg(modrm, pfx); - let index = signed(v(os, reg)); - // BOUND reads two consecutive os-bit values (lower, upper bounds) - let d = v(os * 2, m); - if index < signed(d[os - 1 .. 0]) | signed(d[os * 2 - 1 .. os]) < index then - raise_BR(); - }, - } - } - } - }, - - // 63: MOVSXD r64, r/m32 in 64-bit mode; ARPL r/m16, r16 in protected - // and compatibility mode (SDM Vol.2A ARPL: "not encodable in 64-bit - // mode", #UD in real-address mode) - 99 => { - if cur_mode == LongMode then { - let (reg, src) = fetch_modrm(pfx); - if pfx.rex_w then { - v(reg) = sign_extend(64, v(32, src)) - } else { - let os = opsize(pfx); - v(reg) = v(os, src) - } - } else if cur_mode == RealMode | cur_mode == Virtual8086Mode then { - raise_UD() - } else { - // IF DEST[RPL] < SRC[RPL] THEN ZF := 1; DEST[RPL] := SRC[RPL] - // ELSE ZF := 0. Only ZF is affected. - let (reg, dest) = fetch_modrm(pfx); - let d : word = v(16, dest); - let s : word = v(16, reg); - if unsigned(d[1..0]) < unsigned(s[1..0]) then { - ZF = 0b1; - v(dest) = d[15..2] @ s[1..0] - } else { - ZF = 0b0 - } - } - }, - - // 68: PUSH imm16/32 (d64, Iz) - 104 => { - let os = opsize_default64(pfx); - let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); - exec_push_imm(imm[(os - 1) .. 0]) - }, - - // 69: IMUL r, r/m, imm (3-operand, Iz) - 105 => { - let 'os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - // Fetch imm BEFORE reading src so decode_pos is final for RIP-relative fixup - let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); - let src_val = v(os, src); - let product : int = signed(src_val[os - 1 .. 0]) * signed(imm[os - 1 .. 0]); - let result : qword = to_bits_truncate(product); - let w : bits('os * 2) = to_bits_truncate(product); - CF = is_nonzero(w['os * 2 - 1 .. 'os] ^ sign_extend(w['os - 1])); - OF = CF; - // SDM: SF, ZF, AF, PF are undefined after IMUL. - SF = undefined; - ZF = undefined; - AF = undefined; - PF = undefined; - v(reg) = result[(os - 1) .. 0] - }, - - // 6A: PUSH imm8 (d64, sign-extended) - 106 => { - let os = opsize_default64(pfx); - let imm : qword = sign_extend(fetch(1)); - exec_push_imm(imm[(os - 1) .. 0]) - }, - - // 6B: IMUL r, r/m, imm8 (3-operand, Ib sign-extended) - 107 => { - let 'os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - // Fetch imm BEFORE reading src so decode_pos is final for RIP-relative fixup - let imm : qword = sign_extend(fetch(1)); - let src_val = v(os, src); - let product : int = signed(src_val[os - 1 .. 0]) * signed(imm[os - 1 .. 0]); - let result : qword = to_bits_truncate(product); - let w : bits('os * 2) = to_bits_truncate(product); - CF = is_nonzero(w['os * 2 - 1 .. 'os] ^ sign_extend(w['os - 1])); - OF = CF; - // SDM: SF, ZF, AF, PF are undefined after IMUL. - SF = undefined; - ZF = undefined; - AF = undefined; - PF = undefined; - v(reg) = result[(os - 1) .. 0] - }, - - // 6C: INSB — Input byte from port DX to ES:[RDI] - 108 => { - vmx_exit_if_io(v(RDX), 8, true); - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_ins, 8, asz, pfx) - else exec_ins(8, asz) - }, - // 6D: INSW/INSD — Input word/dword from port DX to ES:[RDI] - 109 => { - let os = opsize(pfx); - vmx_exit_if_io(v(RDX), os, true); - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_ins, os, asz, pfx) - else exec_ins(os, asz) - }, - // 6E: OUTSB — Output byte from DS:[RSI] to port DX - 110 => { - vmx_exit_if_io(v(RDX), 8, false); - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_outs, 8, asz, pfx) - else exec_outs(8, asz, pfx) - }, - // 6F: OUTSW/OUTSD — Output word/dword from DS:[RSI] to port DX - 111 => { - let os = opsize(pfx); - vmx_exit_if_io(v(RDX), os, false); - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_outs, os, asz, pfx) - else exec_outs(os, asz, pfx) - }, - - // 70-7F: Jcc rel8 (forced64) - op if 112 <= op & op <= 127 => { - let cc : cc_idx = op - 112; - let offset : qword = sign_extend(fetch(1)); - if eval_cc(cc) == 0b1 then { - let os = opsize_forced64(pfx); - next_rip = Some(zero_extend((decode_pos + offset)[(os - 1) .. 0])); - } - }, - - // 80/82: Group 1 — ALU r/m8, imm8. SDM Vol.3B 25.15 - // defines 82h as the 80h alias outside 64-bit mode only. - // (A guard rather than an or-pattern: the official Sail parser - // does not accept `128 | 130 =>`.) - op if op == 128 | op == 130 => { - if op == 130 & cur_mode == LongMode then raise_UD(); - let (reg_field, dest) = fetch_modrm_raw(pfx); - let imm : byte = fetch(1); - let alu_op = group1_op(reg_field); - check_lock_rm(pfx, dest, alu_op == ALU_CMP); - exec_alu_rm_imm(alu_op, dest, imm, 8) - }, - - // 81: Group 1 — ALU r/m, imm (Iz) - 129 => { - let os = opsize(pfx); - let (reg_field, dest) = fetch_modrm_raw(pfx); - let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); - let alu_op = group1_op(reg_field); - check_lock_rm(pfx, dest, alu_op == ALU_CMP); - exec_alu_rm_imm(alu_op, dest, imm[(os - 1) .. 0], os) - }, - - // 83: Group 1 — ALU r/m, imm8 (sign-extended) - 131 => { - let os = opsize(pfx); - let (reg_field, dest) = fetch_modrm_raw(pfx); - let imm : qword = sign_extend(fetch(1)); - let alu_op = group1_op(reg_field); - check_lock_rm(pfx, dest, alu_op == ALU_CMP); - exec_alu_rm_imm(alu_op, dest, imm[(os - 1) .. 0], os) - }, - - // 84: TEST r/m8, r8 - 132 => { - let (reg, src) = fetch_modrm(pfx); - update_flags_logic(v(8, src) & v(8, reg)) - }, - - // 85: TEST r/m, r - 133 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - update_flags_logic(v(os, src) & v(os, reg)) - }, - - // 86: XCHG r/m8, r8 - 134 => { - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - let tmp : byte = read_rmw(dest); - v(dest) = v(8, reg); - v(reg) = tmp - }, - - // 87: XCHG r/m, r - 135 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - check_lock_rm(pfx, dest, false); - let tmp = read_rmw(os, dest); - v(dest) = v(os, reg); - v(reg) = tmp - }, - - // 88: MOV r/m8, r8 - 136 => { - let (reg, dest) = fetch_modrm(pfx); - v(dest) = v(8, reg) - }, - - // 89: MOV r/m, r - 137 => { - let os = opsize(pfx); - let (reg, dest) = fetch_modrm(pfx); - v(dest) = v(os, reg) - }, - - // 8A: MOV r8, r/m8 - 138 => { - let (reg, src) = fetch_modrm(pfx); - v(reg) = v(8, src) - }, - - // 8B: MOV r, r/m - 139 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - v(reg) = v(os, src) - }, - - // 8C: MOV r/m16, sreg - 140 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - if reg_field > 5 then raise_UD(); - assert(reg_field <= 5); - let seg : segreg_idx = reg_field; - match dest { - RM_reg(r) => { - let os = opsize(pfx); - v(r) = zero_extend(os, read_segreg(seg)) - }, - RM_mem(m) => v(m) = read_segreg(seg), - } - }, - - // 8D: LEA r, m - 141 => { - let os = opsize(pfx); - let (reg, src) = fetch_modrm(pfx); - match src { - RM_mem(m) => v(reg) = m.addr[(os - 1) .. 0], - RM_reg(_) => raise_UD(), - } - }, - - // 8E: MOV sreg, r/m16 - 142 => { - let (reg_field, src) = fetch_modrm_raw(pfx); - if reg_field > 5 then raise_UD(); - assert(reg_field <= 5); - let seg : segreg_idx = reg_field; - if seg == CS then raise_UD(); - load_data_segment_register(seg, v(src)); - // Loading SS starts the one-instruction shadow that holds interrupts - // and the single-step trap (SDM Vol.3A §7.8.3); LSS does not. - if seg == SS then ss_shadow = 2 - }, - - // 8F /0: POP r/m (default64) - // SDM: "If the RSP register is used as a base register for addressing - // a destination operand in memory, the POP instruction computes the - // effective address of the operand after it increments the RSP register." - 143 => { - let modrm = fetch(1); - let reg_field : range(0, 7) = unsigned(modrm[5..3]); - if reg_field != 0 then raise_UD(); - let os = opsize_default64(pfx); - let mod_field : range(0, 3) = unsigned(modrm[7..6]); - if mod_field == 3 then { - // Register destination — no address computation issue - let idx = unsigned(pfx.rex_b @ modrm[2..0]); - exec_pop_reg(idx, os) - } else { - // Memory destination: pop first, THEN compute effective address - // (SDM requires RSP-relative addresses use the post-pop RSP). - // We pop first so that modrm_rm sees the updated RSP. - let a : qword = zero_extend(pop(os)); - let dest = modrm_rm(modrm, pfx); - match dest { - RM_mem(m) => v(m) = a[(os - 1) .. 0], - _ => raise_UD(), - } - } - }, - - // 90: NOP / PAUSE (F3 90) / XCHG R8D,EAX (REX.B). REX.B selects R8 - // for 90 on both XCHG pages (SDM Vol.2D XCHG, 90+rd; APM Vol.3 XCHG: - // "Opcode 90h can still be used to exchange rAX and r8 if the - // appropriate REX prefix is used"), and PAUSE is F3 90 alone (SDM - // Vol.2B PAUSE). F3 on the XCHG is a repeat prefix on a non-string - // instruction, which the model ignores (scan_prefixes). - 144 => { - if pfx.rex_b == 0b1 then { - let os = opsize(pfx); - exec_xchg_reg_reg(RAX, R8, os) - } else { - if pfx.has_rep then vmx_exit_if_pause() - } - }, - - // 91-97: XCHG rAX, r - op if 145 <= op & op <= 151 => { - let reg_field : range(0, 7) = op - 144; - let reg = unsigned(pfx.rex_b @ to_bits(3, reg_field)); - let os = opsize(pfx); - exec_xchg_reg_reg(RAX, reg, os) - }, - - // 98: CBW/CWDE/CDQE - 152 => { - let os = opsize(pfx); - v(RAX) = sign_extend(os, v(os / 2, RAX)) - }, - - // 99: CWD/CDQ/CQO - 153 => { - let os = opsize(pfx); - v(RDX) = sign_extend(os, v(os, RAX)[os - 1]) - }, - - // 9A: CALL ptr16:16/ptr16:32 — Far call, immediate - // Invalid in 64-bit mode. Encoding: offset (16/32 bits) then selector (16 bits). - 154 => { - if cur_mode == LongMode then raise_UD(); - let os = opsize(pfx); - assert(os <= 32); - let offset : qword = zero_extend(fetch(if os == 16 then 2 else 4)); - let selector : word = fetch(2); - match cur_mode { - RealMode => { - // Push old CS:IP/EIP - push(zero_extend(os, read_segreg(CS)) @ decode_pos[os - 1 .. 0]); - load_segment_register(CS, selector); - let target : qword = zero_extend(offset[os - 1 .. 0]); - next_rip = Some(target) - }, - _ => exec_far_call(selector, offset, os), - } - }, - - // 9B: FWAIT/WAIT: #NM if CR0.MP and CR0.TS are both set, whatever - // CR0.EM (SDM Vol.3A §2.5, Table 2-2) - 155 => { - if CR0[1] == 0b1 & CR0[3] == 0b1 then raise_NM(); - __wait(); - x87_undefine_cc(0x4700) - }, - - // 9C: PUSHF (default64) - // SDM: push(RFLAGS AND 00FCFFFFH) — RF (bit 16) and VM (bit 17) cleared. - 156 => { - let os = opsize_default64(pfx); - var flags = read_rflags() & 0x0000000000FCFFFF; - if cur_mode == Virtual8086Mode & IOPL != 0b11 then { - if CR4[0] == bitzero | os != 16 then raise_GP0(); - flags[9] = VIF; - flags[13..12] = 0b11 - }; - exec_push_imm(flags[(os - 1) .. 0]) - }, - - // 9D: POPF (default64) - // At CPL 0: all flags except RF, VIP, VIF, VM modifiable. - // RF is always cleared (cleared at start of every instruction). - // For 16-bit: only lower 16 bits affect flags (IOPL modifiable at CPL 0, - // but AC/ID are above bit 15 and are NOT modified). - 157 => { - let os = opsize_default64(pfx); - let virtualize = cur_mode == Virtual8086Mode & IOPL != 0b11; - if virtualize & (CR4[0] == bitzero | os != 16) then raise_GP0(); - var v : qword = zero_extend(pop(os)); - if virtualize then { - if v[8] == bitone | (VIP == bitone & v[9] == bitone) then raise_GP0(); - VIF = v[9] - }; - let cpl2 = to_bits(2, cur_cpl); - v[13..12] = blend(IOPL, v[13..12], is_eq(cpl2, 0b00)); - v[9] = blend(IF_flag, v[9], is_le_u(cpl2, v[13..12])); - match os { - 16 => { v[18] = AC_flag; v[21] = ID; write_rflags(v) }, - 32 => write_rflags(v), - 64 => { write_rflags(v); RF = 0b0 }, - } - }, - - // 9E: SAHF - 158 => { - let ah = GPR[RAX][15..8]; - CF = ah[0]; - PF = ah[2]; - AF = ah[4]; - ZF = ah[6]; - SF = ah[7] - }, - - // 9F: LAHF — AH := RFLAGS[7:0] = SF:ZF:0:AF:0:PF:1:CF - 159 => GPR[RAX][15..8] = SF @ ZF @ 0b0 @ AF @ 0b0 @ PF @ 0b1 @ CF, - - // A0: MOV AL, moffs8 - 160 => { - let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); - let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; - v(RAX) = read_mem(8, addr); - }, - - // A1: MOV rAX, moffs - 161 => { - let os = opsize(pfx); - let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); - let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; - v(RAX) = read_mem(os, addr) - }, - - // A2: MOV moffs8, AL - 162 => { - let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); - let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; - write_mem(addr, v(8, RAX)) - }, - - // A3: MOV moffs, rAX - 163 => { - let os = opsize(pfx); - let moffs : qword = zero_extend(fetch(get_address_size(pfx) / 8)); - let addr : MemRef = struct { seg = resolve_seg(pfx, DS), addr = moffs }; - write_mem(addr, v(os, RAX)) - }, - - // A4: MOVSB - 164 => { - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_movs, 8, asz, pfx) - else exec_movs(8, asz, pfx) - }, - - // A5: MOVSW/MOVSD/MOVSQ - 165 => { - let os = opsize(pfx); - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_movs, os, asz, pfx) - else exec_movs(os, asz, pfx) - }, - - // A6: CMPSB - 166 => { - let asz = get_address_size(pfx); - if pfx.has_rep then exec_rep(REP_repe, STR_cmps, 8, asz, pfx) - else if pfx.has_repne then exec_rep(REP_repne, STR_cmps, 8, asz, pfx) - else exec_cmps(8, asz, pfx) - }, - - // A7: CMPSW/CMPSD/CMPSQ - 167 => { - let os = opsize(pfx); - let asz = get_address_size(pfx); - if pfx.has_rep then exec_rep(REP_repe, STR_cmps, os, asz, pfx) - else if pfx.has_repne then exec_rep(REP_repne, STR_cmps, os, asz, pfx) - else exec_cmps(os, asz, pfx) - }, - - // A8: TEST AL, imm8 - 168 => { - let imm : qword = zero_extend(fetch(1)); - let a : qword = zero_extend(v(8, RAX)); - let result = a & imm; - update_flags_logic(result[7..0]) - }, - - // A9: TEST rAX, imm (Iz) - 169 => { - let os = opsize(pfx); - let imm = sign_extend(os, fetch(if os == 16 then 2 else 4)); - let a = v(os, RAX); - let result = a & imm; - update_flags_logic(result) - }, - - // AA: STOSB - 170 => { - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_stos, 8, asz, pfx) - else exec_stos(8, asz) - }, - - // AB: STOSW/STOSD/STOSQ - 171 => { - let os = opsize(pfx); - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_stos, os, asz, pfx) - else exec_stos(os, asz) - }, - - // AC: LODSB - 172 => { - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_lods, 8, asz, pfx) - else exec_lods(8, asz, pfx) - }, - - // AD: LODSW/LODSD/LODSQ - 173 => { - let os = opsize(pfx); - let asz = get_address_size(pfx); - if pfx.has_rep | pfx.has_repne then exec_rep(REP_rep, STR_lods, os, asz, pfx) - else exec_lods(os, asz, pfx) - }, - - // AE: SCASB - 174 => { - let asz = get_address_size(pfx); - if pfx.has_rep then exec_rep(REP_repe, STR_scas, 8, asz, pfx) - else if pfx.has_repne then exec_rep(REP_repne, STR_scas, 8, asz, pfx) - else exec_scas(8, asz) - }, - - // AF: SCASW/SCASD/SCASQ - 175 => { - let os = opsize(pfx); - let asz = get_address_size(pfx); - if pfx.has_rep then exec_rep(REP_repe, STR_scas, os, asz, pfx) - else if pfx.has_repne then exec_rep(REP_repne, STR_scas, os, asz, pfx) - else exec_scas(os, asz) - }, - - // B0-B7: MOV r8, imm8 - op if 176 <= op & op <= 183 => { - // Without REX, registers 4-7 map to AH/CH/DH/BH (high byte). - let gpr_idx = unsigned(pfx.rex_b @ to_bits(3, op - 176)); - let reg : GPRRef = struct { gpr_idx = gpr_idx, has_rex = pfx.has_rex }; - v(reg) = fetch(1) - }, - - // B8-BF: MOV r, imm (Iv) - op if 184 <= op & op <= 191 => { - let reg = unsigned(pfx.rex_b @ to_bits(3, op - 184)); - let os = opsize(pfx); - v(reg) = fetch(os / 8) - }, - - // C0: Group 2 — shift r/m8 by imm8 - 192 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - let count = fetch(1); - exec_shift_rm(reg_field, dest, count, 8) - }, - - // C1: Group 2 — shift r/m by imm8 - 193 => { - let os = opsize(pfx); - let (reg_field, dest) = fetch_modrm_raw(pfx); - let count = fetch(1); - exec_shift_rm(reg_field, dest, count, os) - }, - - // C2: RET near imm16, at the operand size of a near branch - // (opsize_forced64). - 194 => { - let imm = fetch(2); - let os = opsize_forced64(pfx); - next_rip = Some(zero_extend(pop(os))); - v(64, RSP) = v(RSP) + zero_extend(imm) - }, - - // C3: RET near, at the operand size of a near branch - // (opsize_forced64). - 195 => next_rip = Some(zero_extend(pop(opsize_forced64(pfx)))), - - // C4: LES r, m16:16/32 (non-64-bit) or 3-byte VEX prefix - // SDM Vol.2A §2.3.5: In non-64-bit mode, if the second byte has - // bit 7 set (mod=11 in ModRM terms), it is a VEX prefix, not LES. - // This works because LES requires a memory operand (mod≠11), - // so mod=11 is an otherwise-invalid encoding reused for VEX. - 196 => { - if cur_mode == LongMode then { - if vex_after_legacy_prefix(pfx) then raise_UD(); - dispatch_vex(0xC4, pfx) - } else { - // Peek at second byte to distinguish VEX from LES. - // SDM Vol.2A §2.3.5: VEX requires mod=11 (bits 7:6 both set). - // mod≠11 (memory operand) is a valid LES encoding. - let byte2 = fetch(1); - if byte2[7..6] == 0b11 then { - // mod=11: VEX prefix in non-64-bit mode - if vex_after_legacy_prefix(pfx) then raise_UD(); - dispatch_vex_with_byte2(0xC4, byte2, pfx) - } else { - // mod≠11: LES r, m16:16/32 - let os = opsize(pfx); - let reg = modrm_reg(byte2, pfx); - let src = modrm_rm(byte2, pfx); - match src { - RM_mem(m) => { - let (far_offset, selector) = read_far_pointer(os, m); - load_data_segment_register(ES, selector); - // SDM LDS/LES/LFS/LGS/LSS: commit only the operand-sized - // offset after validating the selector (r16 preserves high bits). - v(reg) = far_offset[os - 1 .. 0] - }, - RM_reg(_) => raise_UD(), // unreachable: mod=11 handled above - } - } - } - }, - - // C5: LDS r, m16:16/32 (non-64-bit) or 2-byte VEX prefix - // Same VEX/LDS distinction as C4/LES above. - 197 => { - if cur_mode == LongMode then { - if vex_after_legacy_prefix(pfx) then raise_UD(); - dispatch_vex(0xC5, pfx) - } else { - let byte2 = fetch(1); - if byte2[7..6] == 0b11 then { - if vex_after_legacy_prefix(pfx) then raise_UD(); - dispatch_vex_with_byte2(0xC5, byte2, pfx) - } else { - let os = opsize(pfx); - let reg = modrm_reg(byte2, pfx); - let src = modrm_rm(byte2, pfx); - match src { - RM_mem(m) => { - let (far_offset, selector) = read_far_pointer(os, m); - load_data_segment_register(DS, selector); - v(reg) = far_offset[os - 1 .. 0] - }, - RM_reg(_) => raise_UD(), - } - } - } - }, - - // C6 /0: MOV r/m8, imm8 - 198 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - if reg_field != 0 then raise_UD(); - v(dest) = fetch(1) - }, - - // C7 /0: MOV r/m, imm (Iz) - 199 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - if reg_field != 0 then raise_UD(); - let os = opsize(pfx); - v(dest) = sign_extend(os, fetch(if os == 16 then 2 else 4)) - }, - - // C8: ENTER imm16, imm8 (SDM Vol.2A ENTER, Operation). The frame - // pointers of the outer levels are read through SS at rBP minus - // multiples of the operand size, rBP being as wide as the stack - // address size ("RBP := RBP - 2; Push([RBP])" for a 16-bit operand - // in 64-bit mode). RBP itself is written once, at the end, so that - // a fault leaves it unchanged (step() restores RSP). - 200 => { - let size = fetch(2); - let level = fetch(1); - let os = opsize_default64(pfx); - let 'sas = stack_addr_size(); - let nesting : range(0, 31) = unsigned(level) % 32; - push(v(os, RBP)); - let frame_temp = v(os, RSP); - if nesting > 1 then { - var fp : bits('sas) = v(sas, RBP); - foreach (i from 1 to (nesting - 1)) { - fp = fp - os / 8; - let m : MemRef = struct { seg = SS, addr = zero_extend(fp) }; - push(read_mem(os, m)) - } - }; - if nesting >= 1 then push(frame_temp); - // "The ENTER instruction causes a page fault whenever a write - // using the final value of the stack pointer (within the current - // stack segment) would do so" (SDM Vol.2A ENTER p.3-295), which - // gives neither the size of that write nor its place among the - // pushes. The APM's Operation gives both: after the pushes, - // "WRITE_MEM.v [SS:RSP.s] = temp_unused // ENTER finishes with a - // memory write check on the final stack pointer, but no write - // actually occurs" (Vol.3 ENTER p.183); the model follows it on - // both vendors. Neither manual says whether the pushes stay in - // memory when the check faults; in the model they do. - let final_sp : bits('sas) = v(sas, RSP) - zero_extend(size); - let m : MemRef = struct { seg = SS, addr = zero_extend(final_sp) }; - check_crossing_pages(seg_linear(m, os / 8), os / 8, PT_Write); - v(RBP) = frame_temp; - v(RSP) = final_sp - }, - - // C9: LEAVE — RSP := RBP, then POP RBP - // StackAddrSize determines which portion of RBP is used for the - // stack pointer assignment: 64-bit in long mode, 32/16 otherwise. - // OperandSize (16/32/64) controls the width of the POP. - 201 => { - let os = opsize_default64(pfx); - let sas = stack_addr_size(); - v(RSP) = v(sas, RBP); - v(RBP) = pop(os) - }, - - // CA: RETF imm16 — Far return with stack adjustment - // CB: RETF — Far return - // In 64-bit mode, default operand size for far RET is 32; REX.W makes it 64. - // Same-privilege: pop RIP, CS only. - // Outer-privilege (RPL of new CS > CPL): also pop RSP, SS. (SDM Vol.2 RET) - 202 => exec_retf(pfx, Some(fetch(2))), - 203 => exec_retf(pfx, None()), - - // CC: INT 3 — trap (saved RIP points past the INT3 byte) - // SDM: software interrupt, no error code pushed, gate DPL check applies. - // Without an IDT (user mode) the fault is reported with RIP already - // past the instruction, as the pushed return address would be. - 204 => { - if system_mode then { - sw_return_rip = Some(decode_pos); - deliver_exception(3, 0x00000000, EV_SoftwareInt); - next_rip = Some(RIP) // deliver_exception set RIP to handler - } else { - RIP = decode_pos; - sw_return_rip = Some(decode_pos); - __software_interrupt(0x03) - } - }, - - // CD: INT imm8 - // SDM: software interrupt, no error code pushed, gate DPL check applies. - 205 => { - let imm = fetch(1); - if redirect_vm86_interrupt(unsigned(imm), decode_pos) then return (); - if system_mode then { - sw_return_rip = Some(decode_pos); - deliver_exception(unsigned(imm), 0x00000000, EV_SoftwareInt); - next_rip = Some(RIP) // deliver_exception set RIP to handler - } else { - RIP = decode_pos; - sw_return_rip = Some(decode_pos); - __software_interrupt(imm) - } - }, - - // CE: INTO — Interrupt on Overflow (SDM Vol.2A INT n/INTO/INT3/INT1) - // #UD in 64-bit mode. If OF=1, generates #OF (vector 4). - 206 => { - if cur_mode == LongMode then raise_UD(); - if OF == 0b1 then { - if system_mode then { - sw_return_rip = Some(decode_pos); - deliver_exception(EXN_OF, 0x00000000, EV_SoftwareInt); - next_rip = Some(RIP) - } else { - RIP = decode_pos; - sw_return_rip = Some(decode_pos); - __software_interrupt(0x04) - } - } - }, - - // CF: IRET/IRETD/IRETQ — Interrupt Return - // Real mode: pop IP, CS, FLAGS (3 words, no SP/SS). - // Protected mode same-privilege: pop EIP, CS, EFLAGS (no ESP/SS). - // Protected mode outer-privilege: also pop ESP, SS. - // 64-bit mode: always pop RIP, CS, RFLAGS, RSP, SS (SDM Vol.2 IRET). - 207 => { - let os = opsize(pfx); - let iret_cpl = cur_cpl; - let protected_return = cur_mode != RealMode; - if cur_mode == Virtual8086Mode then { - assert(os == 16 | os == 32); - iret_in_vm86(os); - return () - }; - if NT == 0b1 & cur_mode != RealMode then raise_GP0(); - if os == 16 | os == 32 then { - // IRET/IRETD (16/32-bit operand size) - let new_ip = pop(os); - let new_cs = pop(os); - let new_flags = pop(os); - if os == 32 & cur_cpl == 0 & cur_mode != RealMode & zero_extend(64, new_flags)[17] == bitone then { - iret_to_vm86(zero_extend(new_ip), new_cs[15..0], zero_extend(new_flags)); - return () - }; - let return_rpl : cpl_t = unsigned(new_cs[1..0]); - - // Prepare an outer stack descriptor before changing CS: its - // accessed-bit write may #PF and must leave the old segments intact. - let outer_return = cur_mode != RealMode & return_rpl > cur_cpl; - var outer_sp : qword = 0x0000000000000000; - var outer_ss : word = 0x0000; - if outer_return then { - outer_sp = zero_extend(pop(os)); - let ss_image = pop(os); - outer_ss = ss_image[15..0]; - let _ = access_segment_descriptor(outer_ss, read_descriptor(outer_ss)) - }; - next_rip = Some(zero_extend(new_ip)); - load_segment_register(CS, new_cs[15..0]); - if outer_return then { - v(RSP) = outer_sp; - load_segment_register(SS, outer_ss) - }; - - // In real mode, CPL is always 0 (no privilege levels). - // In protected mode, set CPL from the return CS selector RPL. - if cur_mode != RealMode then cur_cpl = return_rpl; - // 16-bit IRET only modifies lower 16 flags bits; 32-bit replaces all, - // RF included (SDM IRET: "EFLAGS(RF, AC, ID) := tempEFLAGS"), which - // is how a debug handler resumes past an instruction breakpoint. - restore_iret_flags(os, zero_extend(new_flags), iret_cpl, protected_return) - } else { - let new_rip = pop(os); - let new_cs = pop(os); - let new_rflags = pop(os); - let new_rsp = pop(os); - let new_ss = pop(os); - next_rip = Some(new_rip); - - // Load CS selector and descriptor cache from GDT. - // Implicit supervisor access (SDM Vol.3A §4.6). - let sel_offset : qword = zero_extend(new_cs[15..3] @ 0b000); - let desc_lo : dword = read_mem_implicit(GDTR_base + sel_offset); - let desc_hi : dword = read_mem_implicit(GDTR_base + sel_offset + 4); - let code_desc = access_segment_descriptor(new_cs[15..0], parse_seg_descriptor(desc_lo, desc_hi)); - let ss_sel_offset : qword = zero_extend(new_ss[15..3] @ 0b000); - let ss_desc_lo : dword = read_mem_implicit(GDTR_base + ss_sel_offset); - let ss_desc_hi : dword = read_mem_implicit(GDTR_base + ss_sel_offset + 4); - let stack_desc = access_segment_descriptor(new_ss[15..0], parse_seg_descriptor(ss_desc_lo, ss_desc_hi)); - write_segreg(CS, new_cs[15..0]); - SegCache[CS] = code_desc; - set_mode(if SegCache[CS].seg_l == 0b1 then LongMode else CompatibilityMode); - - cur_cpl = unsigned(new_cs[1..0]); - restore_iret_flags(os, new_rflags, iret_cpl, protected_return); - v(RSP) = new_rsp; - // Load SS selector *and* descriptor cache from the GDT (SDM Vol.2 - // IRET: on return to outer privilege the hidden part of SS — - // including D/B for stack address size — must be reloaded, not - // just the visible selector). Without this, IRETQ from a 64-bit - // kernel to a 32-bit compat-mode process leaves SegCache[SS].seg_db - // at whatever stale value it held, so user-mode POP/PUSH read from - // (ESP & 0xFFFF) instead of ESP. - write_segreg(SS, new_ss[15..0]); - SegCache[SS] = stack_desc; - } - }, - - // D0: Group 2 — shift r/m8 by 1 - 208 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - exec_shift_rm(reg_field, dest, 0x01, 8) - }, - - // D1: Group 2 — shift r/m by 1 - 209 => { - let os = opsize(pfx); - let (reg_field, dest) = fetch_modrm_raw(pfx); - exec_shift_rm(reg_field, dest, 0x01, os) - }, - - // D2: Group 2 — shift r/m8 by CL - 210 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - let count : byte = v(RCX); - exec_shift_rm(reg_field, dest, count, 8) - }, - - // D3: Group 2 — shift r/m by CL - 211 => { - let os = opsize(pfx); - let (reg_field, dest) = fetch_modrm_raw(pfx); - let count : byte = v(RCX); - exec_shift_rm(reg_field, dest, count, os) - }, - - // D4: AAM — ASCII Adjust AX After Multiply (SDM Vol.2A) - // #UD in 64-bit mode. D4 ib: AH := AL / imm8; AL := AL MOD imm8. - // #DE if imm8 == 0. - 212 => { - if cur_mode == LongMode then raise_UD(); - let imm = fetch(1); - if imm == 0x00 then raise_DE(); - let temp_al : byte = v(RAX); - let divisor = unsigned(imm); - assert(divisor > 0); - v(RAX) = to_bits(8, unsigned(temp_al) / divisor) @ to_bits(8, unsigned(temp_al) % divisor); - update_SF_ZF_PF(v(8, RAX)); - OF = undefined; - AF = undefined; - CF = undefined - }, - - // D5: AAD — ASCII Adjust AX Before Division (SDM Vol.2A) - // #UD in 64-bit mode. D5 ib: AL := (AL + AH * imm8) AND FFH; AH := 0. - 213 => { - if cur_mode == LongMode then raise_UD(); - let imm = fetch(1); - let temp_al = v(8, RAX); - let temp_ah = v(16, RAX)[15..8]; - let result : byte = to_bits(8, (unsigned(temp_al) + unsigned(temp_ah) * unsigned(imm)) % 256); - v(RAX) = 0x00 @ result; - update_SF_ZF_PF(result); - OF = undefined; - AF = undefined; - CF = undefined - }, - - // D6: SALC — Set AL to Carry Flag (undocumented, invalid in 64-bit mode) - // AL := 0 - CF (0xFF if CF=1, 0x00 if CF=0). No flags affected. - 214 => { - if cur_mode == LongMode then raise_UD(); - v(RAX) = sign_extend(8, CF); - }, - - // D7: XLAT/XLATB - 215 => { - // SDM Vol.2D, XLAT: DS:(E)BX + unsigned AL, with segment - // override support. Truncate the effective offset to address size - // before adding the segment base (Vol.1, address calculations). - let asz = get_address_size(pfx); - let al : qword = zero_extend(v(8, RAX)); - let sum : qword = zero_extend(v(asz, RBX)) + al; - let seg : segreg_idx = match pfx.seg_override { - Some(s) => s, - None() => DS, - }; - let src : MemRef = struct { seg = seg, addr = zero_extend(sum[asz - 1 .. 0]) }; - v(RAX) = read_mem(8, src) - }, - - // D8-DF: x87 FPU - op if 216 <= op & op <= 223 => dispatch_x87(opcode, pfx), - - // E0: LOOPNE/LOOPNZ rel8 - 224 => { - let rel = fetch(1); - let asz = get_address_size(pfx); - exec_loop(rel, LOOP_ne, asz, opsize_forced64(pfx)) - }, - - // E1: LOOPE/LOOPZ rel8 - 225 => { - let rel = fetch(1); - let asz = get_address_size(pfx); - exec_loop(rel, LOOP_e, asz, opsize_forced64(pfx)) - }, - - // E2: LOOP rel8 - 226 => { - let rel = fetch(1); - let asz = get_address_size(pfx); - exec_loop(rel, LOOP_always, asz, opsize_forced64(pfx)) - }, - - // E3: JCXZ/JECXZ/JRCXZ rel8 - // Address size selects CX (16), ECX (32), or RCX (64). - 227 => { - let rel : qword = sign_extend(fetch(1)); - let count_reg = v(get_address_size(pfx), RCX); - if count_reg == zeros() then { - let os = opsize_forced64(pfx); - next_rip = Some(zero_extend((decode_pos + rel)[(os - 1) .. 0])) - } - }, - - // E4: IN AL, imm8 - 228 => { - let port : word = zero_extend(fetch(1)); - vmx_exit_if_io(port, 8, true); - exec_in(port, 8) - }, - - // E5: IN eAX, imm8 - 229 => { - let port : word = zero_extend(fetch(1)); - let os = opsize(pfx); - vmx_exit_if_io(port, os, true); - exec_in(port, os) - }, - - // E6: OUT imm8, AL - 230 => { - let port : word = zero_extend(fetch(1)); - vmx_exit_if_io(port, 8, false); - exec_out(port, 8) - }, - - // E7: OUT imm8, eAX - 231 => { - let port : word = zero_extend(fetch(1)); - let os = opsize(pfx); - vmx_exit_if_io(port, os, false); - exec_out(port, os) - }, - - // E8: CALL rel16/rel32 (forced64) - 232 => { - let rs = opsize_rel(pfx); - let offset : qword = sign_extend(fetch(rs / 8)); - let os = opsize_forced64(pfx); - let return_addr = decode_pos; - match os { - 16 => push(16, return_addr[15..0]), - 32 => if cur_mode == LongMode - then push(64, zero_extend(return_addr[31..0])) - else push(32, return_addr[31..0]), - 64 => push(64, return_addr), - }; - next_rip = Some(zero_extend((return_addr + offset)[(os - 1) .. 0])) - }, - - // E9: JMP rel16/rel32 (forced64) - 233 => { - let os = opsize_forced64(pfx); - let rs = opsize_rel(pfx); - let offset : qword = sign_extend(fetch(rs / 8)); - next_rip = Some(zero_extend((decode_pos + offset)[(os - 1) .. 0])) - }, - - // EA: JMP ptr16:16/ptr16:32 — Far jump, immediate - // Invalid in 64-bit mode. Encoding: offset (16/32 bits) then selector (16 bits). - 234 => { - if cur_mode == LongMode then raise_UD(); - let os = opsize(pfx); - let offset : qword = zero_extend(fetch(if os == 16 then 2 else 4)); - let selector : word = fetch(2); - match cur_mode { - RealMode => { - load_segment_register(CS, selector); - let target : qword = match os { - 16 => zero_extend(offset[15..0]), - _ => zero_extend(offset[31..0]), - }; - next_rip = Some(target) - }, - _ => exec_far_jmp(selector, offset, os), - } - }, - - // EB: JMP rel8 (forced64) - 235 => { - let os = opsize_forced64(pfx); - let rel : qword = sign_extend(fetch(1)); - next_rip = Some(zero_extend((decode_pos + rel)[(os - 1) .. 0])) - }, - - // EC: IN AL, DX - 236 => { - let port : word = v(RDX); - vmx_exit_if_io(port, 8, true); - exec_in(port, 8) - }, - - // ED: IN eAX, DX - 237 => { - let port : word = v(RDX); - let os = opsize(pfx); - vmx_exit_if_io(port, os, true); - exec_in(port, os) - }, - - // EE: OUT DX, AL - 238 => { - let port : word = v(RDX); - vmx_exit_if_io(port, 8, false); - exec_out(port, 8) - }, - - // EF: OUT DX, eAX - 239 => { - let port : word = v(RDX); - let os = opsize(pfx); - vmx_exit_if_io(port, os, false); - exec_out(port, os) - }, - - // F1: INT1 / ICEBP — #DB (vector 1) as a trap: the saved RIP points - // past the instruction, DR6 is not modified, no error code, and unlike - // INT n the gate's DPL is not checked (SDM Vol.2A INT n/INTO/INT3/INT1). - 241 => { - if system_mode then { - sw_return_rip = Some(decode_pos); - deliver_exception(EXN_DB, 0x00000000, EV_Exception); - next_rip = Some(RIP) - } else { - RIP = decode_pos; - sw_return_rip = Some(decode_pos); - __software_interrupt(0x01) - } - }, - - // F4: HLT — SDM: #GP(0) if CPL > 0 - 244 => { - if cur_cpl != 0 then raise_GP0(); - vmx_exit_if_hlt(); - // HLT completes before the halt state is entered: execution resumes - // at the following instruction (and SMM saves the post-HLT RIP, - // SDM Vol.3 §34.10). step() skips its RIP commit once - // system_state != SysRunning, so commit the new RIP here. - RIP = decode_pos; - system_state = SysHalted - }, - - // F5: CMC - 245 => CF = ~(CF), - - // F6: Group 3 — unary byte operations - 246 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - // LOCK valid only for NOT (/2) and NEG (/3) with memory destination - if pfx.has_lock & (reg_field != 2 & reg_field != 3) then raise_UD(); - check_lock_rm(pfx, dest, false); - dispatch_group3_byte(reg_field, dest) - }, - - // F7: Group 3 — unary word/dword/qword operations - 247 => { - let os = opsize(pfx); - let (reg_field, dest) = fetch_modrm_raw(pfx); - // LOCK valid only for NOT (/2) and NEG (/3) with memory destination - if pfx.has_lock & (reg_field != 2 & reg_field != 3) then raise_UD(); - check_lock_rm(pfx, dest, false); - dispatch_group3(reg_field, dest, os) - }, - - // F8: CLC - 248 => CF = 0b0, - - // F9: STC - 249 => CF = 0b1, - - // FA: CLI - 250 => exec_interrupt_flag(false), - - // FB: STI - // SDM Vol.2B STI: inhibit only when IF was clear (a second STI with - // IF already set does not extend the inhibition); exec_interrupt_flag - // sets the shadow and handles VIF under VME/PVI. - 251 => exec_interrupt_flag(true), - - // FC: CLD - 252 => DF = 0b0, - - // FD: STD - 253 => DF = 0b1, - - // FE: Group 4 — INC/DEC r/m8 - 254 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - // LOCK valid only for INC (/0) and DEC (/1) with memory - if pfx.has_lock & reg_field >= 2 then raise_UD(); - check_lock_rm(pfx, dest, false); - match reg_field { - 0 => v(dest) = exec_inc(read_rmw(8, dest)), - 1 => v(dest) = exec_dec(read_rmw(8, dest)), - _ => raise_UD(), - } - }, - - // FF: Group 5 — INC/DEC/CALL/JMP/PUSH r/m - 255 => { - let (reg_field, dest) = fetch_modrm_raw(pfx); - // LOCK valid only for INC (/0) and DEC (/1) with memory - if pfx.has_lock & reg_field >= 2 then raise_UD(); - check_lock_rm(pfx, dest, false); - dispatch_group5(reg_field, dest, pfx) - }, - - // Unhandled opcode - _ => raise_UD(), - } - } -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail deleted file mode 100644 index a8e969924..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_groups.sail +++ /dev/null @@ -1,501 +0,0 @@ -// x86-64 — Group Instruction Helpers (INC/DEC, shifts, MUL/DIV, etc.) -// -// Computes dest := dest + 1. Updates OF, SF, ZF, AF, PF. CF unchanged. - -val exec_inc : forall 'os, 'os in {8, 16, 32, 64}. (bits('os)) -> bits('os) -function exec_inc(a) = { - update_flags_add_no_cf(a + 1, a, zero_extend(0b1)); - a + 1 -} - -// DEC — Decrement by 1 -// -// Computes dest := dest - 1. Updates OF, SF, ZF, AF, PF. CF unchanged. -val exec_dec : forall 'os, 'os in {8, 16, 32, 64}. (bits('os)) -> bits('os) -function exec_dec(a) = { - update_flags_sub_no_cf(a - 1, a, zero_extend(0b1)); - a - 1 -} - -// MUL — Unsigned Multiply -// SDM: SF, ZF, AF, PF are undefined after MUL. -val exec_mul : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit -function exec_mul(os, src) = { - let product : int = unsigned(v(os, RAX)) * unsigned(src); - let result : bits('os * 2) = to_bits_truncate(product); - if os == 8 then { - v(RAX) = result; - } else { - v(RAX) = result[(os - 1)..0]; - v(RDX) = result[(os * 2 - 1)..os]; - }; - CF = is_nonzero(result[(os * 2 - 1)..os]); - OF = CF; - SF = undefined; - ZF = undefined; - AF = undefined; - PF = undefined -} - -// DIV — Unsigned Divide -// SDM: CF, OF, SF, ZF, AF, PF are undefined after DIV. -val exec_div : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit -function exec_div(os, src) = { - let divisor = unsigned(src); - if divisor == 0 then raise_DE(); - assert(divisor > 0); - let dividend = if os == 8 - then unsigned(v(16, RAX)) - else unsigned(v(os, RDX) @ v(os, RAX)); - let quotient = dividend / divisor; - let remainder = dividend - quotient * divisor; - if quotient >= pow2(os) then raise_DE(); - let q_bits = to_bits_truncate(os, quotient); - let r_bits = to_bits_truncate(os, remainder); - if os == 8 then { - v(RAX) = r_bits @ q_bits - } else { - v(RAX) = q_bits; - v(RDX) = r_bits - }; - CF = undefined; - OF = undefined; - SF = undefined; - ZF = undefined; - AF = undefined; - PF = undefined -} - -// IDIV — Signed Divide -// SDM: CF, OF, SF, ZF, AF, PF are undefined after IDIV. -val exec_idiv : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit -function exec_idiv(os, src) = { - let divisor = signed(src); - if divisor == 0 then raise_DE(); - assert(divisor != 0); - let dividend = if os == 8 - then signed(v(16, RAX)) - else signed(v(os, RDX) @ v(os, RAX)); - let quotient = quot_round_zero(dividend, divisor); - let remainder = rem_round_zero(dividend, divisor); - if quotient < -pow2(os - 1) | (pow2(os - 1) - 1) < quotient then raise_DE(); - let q_bits = to_bits_truncate(os, quotient); - let r_bits = to_bits_truncate(os, remainder); - if os == 8 then { - v(RAX) = r_bits @ q_bits - } else { - v(RAX) = q_bits; - v(RDX) = r_bits - }; - CF = undefined; - OF = undefined; - SF = undefined; - ZF = undefined; - AF = undefined; - PF = undefined -} - -// IMUL — Signed Multiply (one-operand form) -// SDM: SF, ZF, AF, PF are undefined after IMUL. -val exec_imul_1 : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), bits('os)) -> unit -function exec_imul_1(os, src) = { - let product : int = signed(v(os, RAX)) * signed(src); - let result : bits('os * 2) = to_bits_truncate(product); - if os == 8 then { - v(RAX) = result; - } else { - v(RAX) = result[(os - 1)..0]; - v(RDX) = result[(os * 2 - 1)..os]; - }; - CF = is_nonzero(result[(os * 2 - 1)..os] ^ sign_extend(result[os - 1])); - OF = CF; - SF = undefined; - ZF = undefined; - AF = undefined; - PF = undefined -} - -// PUSH imm -val exec_push_imm : forall 'os, 'os in {16, 32, 64}. (implicit('os), bits('os)) -> unit -function exec_push_imm(os, imm) = { - match os { - 16 => push(16, imm), - 32 => if cur_mode == LongMode then push(64, sign_extend(imm)) else push(32, imm), - 64 => push(64, imm), - } -} - -// ========================================================================= -// Group 3 (F6): Unary byte operations -// ========================================================================= - -val dispatch_group3_byte : (range(0, 7), RM) -> unit -function dispatch_group3_byte(reg_field, dest) = { - if reg_field == 0 | reg_field == 1 then { - // TEST r/m8, imm8 - // Fetch imm BEFORE reading dest so decode_pos is final for RIP-relative fixup - let imm : byte = fetch(1); - update_flags_logic(v(8, dest) & imm) - } else { - // NOT and NEG write their operand back; MUL and DIV only read it. - let x = if reg_field <= 3 then read_rmw(8, dest) else v(8, dest); - match reg_field { - // NOT r/m8 - 2 => v(dest) = x ^ 0xFF, - // NEG r/m8 - 3 => { - update_flags_sub(zeros() - x, zeros(), x); - v(dest) = zeros() - x - }, - 4 => exec_mul(x), - 5 => exec_imul_1(x), - 6 => exec_div(x), - 7 => exec_idiv(x), - } - } -} - -// ========================================================================= -// Group 3 (F7): Unary word/dword/qword operations -// ========================================================================= - -val dispatch_group3 : (range(0, 7), RM, {16, 32, 64}) -> unit -function dispatch_group3(reg_field, dest, os) = { - if reg_field == 0 | reg_field == 1 then { - // TEST r/m, imm (Iz) - // Fetch imm BEFORE reading dest so decode_pos is final for RIP-relative fixup - let imm : qword = sign_extend(fetch(if os == 16 then 2 else 4)); - update_flags_logic(v(os, dest) & imm[(os - 1) .. 0]) - } else { - // NOT and NEG write their operand back; MUL and DIV only read it. - let x = if reg_field <= 3 then read_rmw(os, dest) else v(os, dest); - match reg_field { - // NOT r/m - 2 => v(dest) = ~(x), - // NEG r/m - 3 => { - update_flags_sub(zeros() - x, zeros(), x); - v(os, dest) = zeros() - x - }, - 4 => exec_mul(x), - 5 => exec_imul_1(x), - 6 => exec_div(x), - 7 => exec_idiv(x), - } - } -} - -// ========================================================================= -// Group 5 (FF): INC/DEC/CALL/JMP/PUSH -// ========================================================================= - -// The width of the offset in the far pointer of FF /3 and FF /5 at -// operand size os. With REX.W the manuals give the encoding different -// meanings, so the model follows the vendor register (regs.sail): "REX.W -// FF /3 CALL m16:64" and "REX.W FF /5 JMP m16:64" (SDM Vol.2A CALL, JMP), -// where "If the operand-size is 32 or 64 bits, the operand is a 32-bit -// offset followed by a 16-bit selector" (APM Vol.3 CALL (Far) p.139; JMP -// (Far) p.210, "a 16-bit selector followed by a 32-bit offset"). The -// operand size still sets the width of the pushes. -val far_pointer_offset_size : {16, 32, 64} -> {16, 32, 64} -function far_pointer_offset_size(os) = if os == 64 & vendor == Vendor_AMD then 32 else os - -val dispatch_group5 : (range(0, 7), RM, Prefixes) -> unit -function dispatch_group5(reg_field, dest, pfx) = { - match reg_field { - // INC r/m - 0 => { - let os = opsize(pfx); - v(dest) = exec_inc(read_rmw(os, dest)) - }, - - // DEC r/m - 1 => { - let os = opsize(pfx); - v(dest) = exec_dec(read_rmw(os, dest)) - }, - - // CALL near indirect, at the operand size of a near branch - // (opsize_forced64). - 2 => { - let os = opsize_forced64(pfx); - let target : qword = zero_extend(v(os, dest)); - let return_addr : qword = decode_pos; - push(return_addr[os - 1 .. 0]); - next_rip = Some(target) - }, - - // CALL far indirect m16:16/m16:32/m16:64 - // Memory operand contains offset (16/32/64 bits) then selector (16 bits). - // Register form is #UD. - 3 => { - match dest { - RM_reg(_) => raise_UD(), - RM_mem(m) => { - let os = opsize(pfx); - let (far_offset, far_selector) = read_far_pointer(far_pointer_offset_size(os), m); - exec_far_call(far_selector, far_offset, os) - }, - } - }, - - // JMP near indirect, at the operand size of a near branch - // (opsize_forced64). - 4 => next_rip = Some(zero_extend(v(opsize_forced64(pfx), dest))), - - // JMP far indirect m16:16/m16:32/m16:64 - // Memory operand contains offset (16/32/64 bits) then selector (16 bits). - // Register form is #UD. - 5 => { - match dest { - RM_reg(_) => raise_UD(), - RM_mem(m) => { - let os = opsize(pfx); - let (far_offset, far_selector) = read_far_pointer(far_pointer_offset_size(os), m); - exec_far_jmp(far_selector, far_offset, os) - }, - } - }, - - // PUSH r/m (d64) - 6 => { - let os = opsize_default64(pfx); - exec_push_imm(v(os, dest)) - }, - - // 7: reserved - 7 => raise_UD(), - } -} - -// SHL/SAL — Shift Left -// -// Shifts dest left by count bits. CF = last bit shifted out. -// If count=0, flags unchanged. If count=1, OF = MSB(result) XOR CF. -// SF, ZF, PF set from result. AF undefined for count != 0. -val exec_shl : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) -function exec_shl(a, count_raw) = { - let count : range(0, 63) = match 'os { - 64 => unsigned(count_raw) % 64, - _ => unsigned(count_raw) % 32, - }; - let count_bv : bits(6) = to_bits(6, count); - let old_CF = CF; let old_OF = OF; let old_SF = SF; - let old_ZF = ZF; let old_PF = PF; let old_AF = AF; - let result : bits('os) = a << count; - let cf_count : range(0, 64) = count + unsigned(is_zero(count_bv)); - let cf_idx : range(0, 63) = ('os + 64 - cf_count) % 64; - let a_ext : bits(64) = zero_extend(a); - - CF = a_ext[cf_idx]; - update_SF_ZF_PF(result); - OF = result['os - 1] ^ CF; - AF = undefined; - // OF defined only for count==1; undefined otherwise - OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); - // CF undefined when count >= operand size (possible for 8/16-bit) - CF = blend(CF, undefined, is_ge_u(to_bits(7, count), to_bits(7, 'os))); - - // When count==0: restore all flags and return original value - let count_nz : bit = is_nonzero(count_bv); - CF = blend(old_CF, CF, count_nz); - OF = blend(old_OF, OF, count_nz); - SF = blend(old_SF, SF, count_nz); - ZF = blend(old_ZF, ZF, count_nz); - PF = blend(old_PF, PF, count_nz); - AF = blend(old_AF, AF, count_nz); - blend(a, result, count_nz) -} - -// SHR — Shift Right (Logical) -// -// Shifts dest right by count bits, filling with zeros. -// CF = last bit shifted out. If count=1, OF = MSB(original). -// SF, ZF, PF set from result. AF undefined for count != 0. -val exec_shr : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) -function exec_shr(a, count_raw) = { - let mod_val : range(32, 64) = if 'os == 64 then 64 else 32; - let count : range(0, 63) = unsigned(count_raw) % mod_val; - let count_bv : bits(6) = to_bits(6, count); - let old_CF = CF; let old_OF = OF; let old_SF = SF; - let old_ZF = ZF; let old_PF = PF; let old_AF = AF; - let result : bits('os) = a >> count; - let cf_count : range(0, 64) = count + unsigned(is_zero(count_bv)); - assert(cf_count >= 1); - let a_ext : bits(64) = zero_extend(a); - - CF = a_ext[cf_count - 1]; - update_SF_ZF_PF(result); - OF = a['os - 1]; - AF = undefined; - // OF defined only for count==1; undefined otherwise - OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); - // CF undefined when count >= operand size (possible for 8/16-bit) - CF = blend(CF, undefined, is_ge_u(to_bits(7, count), to_bits(7, 'os))); - - let count_nz : bit = is_nonzero(count_bv); - CF = blend(old_CF, CF, count_nz); - OF = blend(old_OF, OF, count_nz); - SF = blend(old_SF, SF, count_nz); - ZF = blend(old_ZF, ZF, count_nz); - PF = blend(old_PF, PF, count_nz); - AF = blend(old_AF, AF, count_nz); - blend(a, result, count_nz) -} - -// SAR — Shift Right (Arithmetic) -// -// Shifts dest right by count bits, preserving sign bit. -// CF = last bit shifted out. OF cleared for count=1. -// SF, ZF, PF set from result. AF undefined for count != 0. -val exec_sar : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) -function exec_sar(a, count_raw) = { - let mod_val : range(32, 64) = if 'os == 64 then 64 else 32; - let count : range(0, 63) = unsigned(count_raw) % mod_val; - let count_bv : bits(6) = to_bits(6, count); - let old_CF = CF; let old_OF = OF; let old_SF = SF; - let old_ZF = ZF; let old_PF = PF; let old_AF = AF; - let cf_count : range(0, 64) = count + unsigned(is_zero(count_bv)); - assert(cf_count >= 1); - let cf_idx_bv : bits(7) = min_u(to_bits(7, cf_count - 1), to_bits(7, 'os - 1)); - let cf_idx = unsigned(cf_idx_bv); - assert(cf_idx < 'os); - - CF = a[cf_idx]; - let result : bits('os) = a >>> count; - update_SF_ZF_PF(result); - OF = 0b0; - AF = undefined; - // OF defined only for count==1; undefined otherwise - OF = blend(undefined, OF, is_eq(count_bv, 0b000001)); - - let count_nz : bit = is_nonzero(count_bv); - CF = blend(old_CF, CF, count_nz); - OF = blend(old_OF, OF, count_nz); - SF = blend(old_SF, SF, count_nz); - ZF = blend(old_ZF, ZF, count_nz); - PF = blend(old_PF, PF, count_nz); - AF = blend(old_AF, AF, count_nz); - blend(a, result, count_nz) -} - -// ROL — Rotate Left -// ROR — Rotate Right -// -// ROL: Rotates bits left. CF = LSB(result) after rotate. -// ROR: Rotates bits right. CF = MSB(result) after rotate. -// OF defined only for count=1. SF, ZF, AF, PF unaffected. -// Count is masked to 5 bits (6 bits for 64-bit operands). -val exec_rol : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) -function exec_rol(a, count_raw) = { - let count : range(0, 63) = match 'os { - 64 => unsigned(count_raw) % 64, - _ => unsigned(count_raw) % 32, - }; - let old_CF = CF; let old_OF = OF; - let result : bits('os) = rotl(a, count % 'os); - - CF = result[0]; - OF = result['os - 1] ^ CF; - // OF defined only for count==1; undefined otherwise - OF = blend(undefined, OF, is_eq(to_bits(6, count), 0b000001)); - - let count_nz : bit = is_nonzero(to_bits(6, count)); - CF = blend(old_CF, CF, count_nz); - OF = blend(old_OF, OF, count_nz); - blend(a, result, count_nz) -} - -val exec_ror : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) -function exec_ror(a, count_raw) = { - let count : range(0, 63) = match 'os { - 64 => unsigned(count_raw) % 64, - _ => unsigned(count_raw) % 32, - }; - let old_CF = CF; let old_OF = OF; - let result : bits('os) = rotr(a, count % 'os); - - CF = result['os - 1]; - OF = result['os - 1] ^ result['os - 2]; - // OF defined only for count==1; undefined otherwise - OF = blend(undefined, OF, is_eq(to_bits(6, count), 0b000001)); - - let count_nz : bit = is_nonzero(to_bits(6, count)); - CF = blend(old_CF, CF, count_nz); - OF = blend(old_OF, OF, count_nz); - blend(a, result, count_nz) -} - -// RCL — Rotate Through Carry Left -// RCR — Rotate Through Carry Right -// -// RCL: Rotates (n+1)-bit value (CF:dest) left by count. -// RCR: Rotates (n+1)-bit value (CF:dest) right by count. -// OF defined only for count=1. Count masked to 5 bits (6 for 64-bit). -val exec_rcl : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) -function exec_rcl(a, count_raw) = { - let masked : range(0, 63) = match 'os { - 64 => unsigned(count_raw) % 64, - _ => unsigned(count_raw) % 32, - }; - let c = masked % ('os + 1); - let old_CF = CF; let old_OF = OF; - let wide = a @ CF; - let rotated = rotl(wide, c); - - CF = rotated[0]; - OF = rotated['os] ^ rotated[0]; - // OF defined only for masked==1; undefined otherwise - OF = blend(undefined, OF, is_eq(to_bits(6, masked), 0b000001)); - - let c_nz : bit = is_nonzero(to_bits(6, c)); - CF = blend(old_CF, CF, c_nz); - OF = blend(old_OF, OF, c_nz); - blend(a, rotated['os..1], c_nz) -} - -val exec_rcr : forall 'os, 'os in {8, 16, 32, 64}. (bits('os), byte) -> bits('os) -function exec_rcr(a, count_raw) = { - let masked : range(0, 63) = match 'os { - 64 => unsigned(count_raw) % 64, - _ => unsigned(count_raw) % 32, - }; - let c = masked % ('os + 1); - let old_CF = CF; let old_OF = OF; - - // OF is set from original value before rotation for RCR - OF = a['os - 1] ^ CF; - // OF defined only for masked==1; undefined otherwise - OF = blend(undefined, OF, is_eq(to_bits(6, masked), 0b000001)); - let wide = a @ CF; - let rotated = rotr(wide, c); - CF = rotated[0]; - - let c_nz : bit = is_nonzero(to_bits(6, c)); - CF = blend(old_CF, CF, c_nz); - OF = blend(old_OF, OF, c_nz); - blend(a, rotated['os..1], c_nz) -} - -// ========================================================================= -// Generic shift/rotate handler for Group 2 -// -// For register operands, delegates to existing exec_ functions. -// For memory operands, reads/shifts/writes back inline. -// ========================================================================= -val exec_shift_rm : forall 'os, 'os in {8, 16, 32, 64}. (range(0, 7), RM, byte, int('os)) -> unit -function exec_shift_rm(shift_op, dest, count_raw, os) = { - // exec_* functions handle count==0 via blend (return original, flags preserved). - let src_val = read_rmw(os, dest); - let new_val : bits('os) = match shift_op { - 0 => exec_rol(src_val, count_raw), - 1 => exec_ror(src_val, count_raw), - 2 => exec_rcl(src_val, count_raw), - 3 => exec_rcr(src_val, count_raw), - 4 => exec_shl(src_val, count_raw), - 5 => exec_shr(src_val, count_raw), - 6 => exec_shl(src_val, count_raw), // SAL = SHL - 7 => exec_sar(src_val, count_raw), - }; - v(os, dest) = new_val -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail deleted file mode 100644 index 794de75ef..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_modrm.sail +++ /dev/null @@ -1,496 +0,0 @@ -// x86-64 — ModR/M and SIB Decoding -// -// Decodes the ModR/M byte, optional SIB byte, and displacement to -// produce either a register operand or an effective memory address. -// -// In 64-bit mode: -// - mod=00, r/m=101 => [RIP + disp32] -// - r/m=100 (with mod!=11) => SIB byte follows -// - SIB base=101 with mod=00 => disp32 only (no base register) - -// Decode SIB byte and compute effective address. -// Returns the memory address. -val decode_sib : (byte, range(0, 2), Prefixes) -> qword -function decode_sib(sib, modbits, pfx) = { - let scale : range(0, 3) = unsigned(sib[7..6]); - - // Base and index registers (extended by REX.B / REX.X) - let base_idx : gpr_idx = unsigned(pfx.rex_b @ sib[2..0]); - let index_idx : gpr_idx = unsigned(pfx.rex_x @ sib[5..3]); - - // Compute base component - let base_val : qword = - if sib[2..0] == 0b101 & modbits == 0 then { - // mod=00, base=101: no base register, disp32 follows - sign_extend(fetch(4)) - } else if sib[2..0] == 0b101 & modbits == 1 then { - // mod=01, base=101: [RBP/R13] + disp8 - v(64, base_idx) + sign_extend(fetch(1)) - } else if sib[2..0] == 0b101 & modbits == 2 then { - // mod=10, base=101: [RBP/R13] + disp32 - v(64, base_idx) + sign_extend(fetch(4)) - } else { - // Normal base register with displacement handled by caller - if modbits == 0 then - v(64, base_idx) - else if modbits == 1 then { - v(64, base_idx) + sign_extend(fetch(1)) - } else { - v(64, base_idx) + sign_extend(fetch(4)) - } - }; - - // Compute index component: index=100 (RSP without REX.X) means no index - let index_val : qword = - if sib[5..3] == 0b100 & pfx.rex_x == 0b0 then { - 0x0000000000000000 - } else { - let idx_reg = v(64, index_idx); - match scale { - 0 => idx_reg, - 1 => idx_reg << 1, - 2 => idx_reg << 2, - 3 => idx_reg << 3, - } - }; - - base_val + index_val -} - -// Apply segment base to a memory address (SDM Vol.3A §3.4). -// Linear address = segment base + effective address. -// If there's an explicit segment override prefix, use that segment; -// otherwise use the default segment (DS for most, SS for BP/SP-based). -// Resolve the effective segment for a memory operand, considering -// any explicit segment override prefix and the default segment. -val resolve_seg : (Prefixes, segreg_idx) -> segreg_idx -function resolve_seg(pfx, default_seg) = match pfx.seg_override { - Some(s) => s, - None() => default_seg, -} - -// The default segment of a 32- or 64-bit memory operand with the base -// register field base (ModR/M.rm, or SIB.base after rm = 100b): SS for an -// rSP or rBP base, DS otherwise ("When the ESP or EBP register is used as -// the base, the SS segment is the default segment. In all other cases, -// the DS segment is the default segment", SDM Vol.1 §3.7.5 p.3-23; in -// 64-bit mode "instructions using RSP/RBP as base registers", §3.3.7.1 -// p.3-10). R12 and R13, whose encodings are rSP's and rBP's with REX.B -// (VEX.B̄, EVEX.B̄ clear), are other registers: DS, so a non-canonical -// [r13+0] is #GP(0), not #SS(0). SIB.base = 101b with mod = 00b names no -// base. -val base_default_seg : (bits(3), range(0, 3), Prefixes) -> segreg_idx -function base_default_seg(base, modbits, pfx) = - if pfx.rex_b == 0b0 & (base == 0b100 | base == 0b101 & modbits != 0) then SS else DS - -// Byte i of the destination of MASKMOVQ, MASKMOVDQU and VMASKMOVDQU: "the -// effective address in the DI/EDI/RDI register (the default segment -// register is DS, but this may be overridden with a segment-override -// prefix) ... (The size of the store address depends on the address-size -// attribute.)" (SDM Vol.2B MASKMOVDQU, MASKMOVQ). -val maskmov_dest : (Prefixes, range(0, 15)) -> MemRef -function maskmov_dest(pfx, i) = { - let ea : qword = v(64, RDI) + to_bits(64, i); - let addr : qword = match get_address_size(pfx) { - 16 => zero_extend(ea[15..0]), - 32 => zero_extend(ea[31..0]), - 64 => ea, - }; - struct { seg = resolve_seg(pfx, DS), addr = addr } -} - -// Compute EVEX compressed displacement scale factor for "Full" tuple type. -// Without broadcast: N = vector size in bytes. With broadcast: N = element size. -val evex_full_disp_n : Prefixes -> range(4, 64) -function evex_full_disp_n(pfx) = - if pfx.evex_b then - (if pfx.vex_w then 8 else 4) - else match pfx.evex_ll { - 0 => 16, - 1 => 32, - 2 => 64, - 3 => raise_UD(), - } - -// The scale for the "Half" tuple type (SDM Vol.2 §2.7.5, Table 2-34): the -// memory operand is half a vector, VL/16 bytes, or with EVEX.b one 32-bit -// element. Half is the type of the widening conversions from 32-bit -// elements (VCVTDQ2PD, VCVTUDQ2PD, VCVTPS2PD, VCVT[T]PS2[U]QQ), all W0. -val evex_half_disp_n : Prefixes -> range(4, 32) -function evex_half_disp_n(pfx) = - if pfx.evex_b then 4 - else match pfx.evex_ll { - 0 => 8, - 1 => 16, - 2 => 32, - 3 => raise_UD(), - } - -// The same for opcodes whose F3/F2 forms are scalar (SS/SD: Tuple1 Scalar, -// N = element size) and whose NP/66 forms are Full (PS/PD): 0F 10/11/51/ -// 58-5F/C2. -val evex_fp_disp_n : (MandatoryPrefix, Prefixes) -> range(4, 64) -function evex_fp_disp_n(mp, pfx) = match mp { - MP_F3 => 4, - MP_F2 => 8, - _ => evex_full_disp_n(pfx), -} - -// Decode SIB with EVEX compressed disp8. -val decode_sib_evex : (byte, range(0, 2), Prefixes, range(1, 64)) -> qword -function decode_sib_evex(sib, modbits, pfx, disp_n) = { - let scale : range(0, 3) = unsigned(sib[7..6]); - - let base_idx : gpr_idx = unsigned(pfx.rex_b @ sib[2..0]); - let index_idx : gpr_idx = unsigned(pfx.rex_x @ sib[5..3]); - - let base_val : qword = - if sib[2..0] == 0b101 & modbits == 0 then { - sign_extend(fetch(4)) - } else if sib[2..0] == 0b101 & modbits == 1 then { - let d8 : byte = fetch(1); - let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); - v(64, base_idx) + scaled_disp - } else if sib[2..0] == 0b101 & modbits == 2 then { - v(64, base_idx) + sign_extend(fetch(4)) - } else { - if modbits == 0 then - v(64, base_idx) - else if modbits == 1 then { - let d8 : byte = fetch(1); - let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); - v(64, base_idx) + scaled_disp - } else { - v(64, base_idx) + sign_extend(fetch(4)) - } - }; - - let index_val : qword = - if sib[5..3] == 0b100 & pfx.rex_x == 0b0 then { - 0x0000000000000000 - } else { - let idx_reg = v(64, index_idx); - match scale { - 0 => idx_reg, - 1 => idx_reg << 1, - 2 => idx_reg << 2, - 3 => idx_reg << 3, - } - }; - - base_val + index_val -} - -// The segment and address size of a VSIB memory operand, as for any other -// memory operand (modrm_rm): the segment of the base register -// (base_default_seg) unless a prefix overrides it, and 32-bit addresses -// with 67h in 64-bit mode. "VSIB memory addressing requires 32-bit or -// 64-bit effective address. In 32-bit mode, VSIB addressing is not -// supported when address size attribute is overridden to 16 bits", which -// is #UD (Vol.2A §2.3.12). Returns the segment and whether the addresses -// are 64 bits. -val vsib_seg_asize : (byte, range(0, 3), Prefixes) -> (segreg_idx, bool) -function vsib_seg_asize(sib, modbits, pfx) = { - let asz = get_address_size(pfx); - if asz == 16 then raise_UD(); - (resolve_seg(pfx, base_default_seg(sib[2..0], modbits, pfx)), asz == 64) -} - -// Decode VSIB for gather/scatter instructions. -// Returns base address (GPR + displacement), vector index register, scale, -// segment and address size. -// The SIB byte's index field references a vector register (extended by EVEX.V'/X). -val decode_vsib_evex : (byte, Prefixes, range(1, 64)) -> VSIB -function decode_vsib_evex(modrm, pfx, disp_n) = { - let modbits : range(0, 3) = unsigned(modrm[7..6]); - // VSIB always has rm=100 (SIB present), mod != 11 (evex_check_form). - let sib : byte = fetch(1); - let scale : range(0, 3) = unsigned(sib[7..6]); - let (seg, addr64) = vsib_seg_asize(sib, modbits, pfx); - - // Base register uses EVEX.B extension (same as normal SIB) - let base_idx : gpr_idx = unsigned(pfx.rex_b @ sib[2..0]); - - // Index is a vector register: VIDX = {EVEX.V', EVEX.X, sib.index} (SDM - // Vol.2A Table 1-33). V' is folded into bit 4 of evex_vvvvv; R' extends - // modrm.reg, not the index. - let v_prime : bits(1) = if pfx.evex_vvvvv >= 16 then 0b1 else 0b0; - let vidx : simd_idx = unsigned(v_prime @ pfx.rex_x @ sib[5..3]); - - let base_val : qword = - if sib[2..0] == 0b101 & modbits == 0 then { - sign_extend(fetch(4)) - } else if modbits == 0 then { - v(64, base_idx) - } else if modbits == 1 then { - let d8 : byte = fetch(1); - let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); - v(64, base_idx) + scaled_disp - } else { - v(64, base_idx) + sign_extend(fetch(4)) - }; - - struct { vsib_base = base_val, vsib_vidx = vidx, vsib_scale = scale, - vsib_seg = seg, vsib_addr64 = addr64 } -} - -// Decode ModR/M with EVEX compressed disp8. disp_n is the scale factor. -val modrm_rm_evex : (byte, Prefixes, range(1, 64)) -> RM -function modrm_rm_evex(modrm, pfx, disp_n) = { - let modbits : range(0, 3) = unsigned(modrm[7..6]); - let rm_raw : bits(3) = modrm[2..0]; - - if modbits == 3 then { - RM_reg(struct { gpr_idx = unsigned(pfx.rex_b @ rm_raw), has_rex = pfx.has_rex }) - } else if modbits == 0 & rm_raw == 0b101 then { - let disp : qword = sign_extend(fetch(4)); - if cur_mode == LongMode then { - // RIP-relative: [RIP + disp32] (no compression for disp32) - rip_rel_pending = true; - rip_rel_disp = disp; - let ea : qword = decode_pos + disp; - let ad_keep : qword = sign_extend(~(pfx.has_adsize)); - let ea : qword = ea & (ad_keep | 0x00000000FFFFFFFF); - RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) - } else { - // Compat/protected mode: [disp32] absolute - let ea : qword = disp & 0x00000000FFFFFFFF; - RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) - } - } else { - let asz = get_address_size(pfx); - var default_seg : segreg_idx = base_default_seg(rm_raw, modbits, pfx); - let addr : qword = - if rm_raw == 0b100 then { - let sib : byte = fetch(1); - default_seg = base_default_seg(sib[2..0], modbits, pfx); - decode_sib_evex(sib, modbits, pfx, disp_n) - } else if modbits == 0 then { - v(64, unsigned(pfx.rex_b @ rm_raw)) - } else { - if modbits == 1 then { - // disp8 * N - let d8 : byte = fetch(1); - let scaled_disp : qword = get_slice_int(64, signed(d8) * disp_n, 0); - v(64, unsigned(pfx.rex_b @ rm_raw)) + scaled_disp - } else { - // disp32 (no compression) - v(64, unsigned(pfx.rex_b @ rm_raw)) + sign_extend(fetch(4)) - } - }; - let addr : qword = match asz { - 16 => addr & 0x000000000000FFFF, - 32 => addr & 0x00000000FFFFFFFF, - 64 => addr, - }; - RM_mem(struct { seg = resolve_seg(pfx, default_seg), addr = addr }) - } -} - -// Decode ModR/M with 16-bit addressing (SDM Vol.2 Table 2-1). -// No SIB byte, no REX extension. Register pairs for effective address: -// rm=0: [BX+SI], 1: [BX+DI], 2: [BP+SI], 3: [BP+DI], -// 4: [SI], 5: [DI], 6: [disp16] (mod=00) or [BP], 7: [BX] -// Default segment: BP-based → SS, others → DS. -val modrm_rm_16 : (byte, Prefixes) -> RM -function modrm_rm_16(modrm, pfx) = { - let modbits : range(0, 3) = unsigned(modrm[7..6]); - let rm_raw : range(0, 7) = unsigned(modrm[2..0]); - - if modbits == 3 then { - RM_reg(struct { gpr_idx = unsigned(modrm[2..0]), has_rex = false }) - } else { - // Compute base address from register pair - let base : word = match rm_raw { - 0 => v(16, RBX) + v(16, RSI), - 1 => v(16, RBX) + v(16, RDI), - 2 => v(16, RBP) + v(16, RSI), - 3 => v(16, RBP) + v(16, RDI), - 4 => v(16, RSI), - 5 => v(16, RDI), - 6 => if modbits == 0 then 0x0000 else v(16, RBP), - 7 => v(16, RBX), - }; - // Add displacement - let ea : word = if modbits == 0 & rm_raw == 6 then { - // mod=00, rm=110: [disp16] absolute - fetch(2) - } else if modbits == 0 then { - base - } else if modbits == 1 then { - // + sign-extended disp8 - base + sign_extend(fetch(1)) - } else { - // modbits == 2: + disp16 - base + fetch(2) - }; - // Default segment: BP-based → SS, others → DS - let default_seg : segreg_idx = - if rm_raw == 2 | rm_raw == 3 then SS // [BP+SI], [BP+DI] - else if rm_raw == 6 & modbits != 0 then SS // [BP]+disp - else DS; - RM_mem(struct { seg = resolve_seg(pfx, default_seg), addr = zero_extend(ea) }) - } -} - -// Decode ModR/M byte and return the r/m operand (register or memory address). -// The reg field is decoded separately by the caller via modrm_reg(). -// The modrm byte has already been fetched by the caller. -val modrm_rm : (byte, Prefixes) -> RM -function modrm_rm(modrm, pfx) = { - // 16-bit addressing uses a completely different table (SDM Table 2-1) - if get_address_size(pfx) == 16 then { - return modrm_rm_16(modrm, pfx) - }; - - let modbits : range(0, 3) = unsigned(modrm[7..6]); - let rm_raw : bits(3) = modrm[2..0]; - - if modbits == 3 then { - // Register direct — no segment override - RM_reg(struct { gpr_idx = unsigned(pfx.rex_b @ rm_raw), has_rex = pfx.has_rex }) - } else if modbits == 0 & rm_raw == 0b101 then { - let disp : qword = sign_extend(fetch(4)); - if cur_mode == LongMode then { - // RIP-relative: [RIP + disp32] - // With 67h prefix, uses EIP + disp32 (truncated to 32 bits). - // If the instruction has trailing bytes (imm8/imm32), - // fixup_addr() will adjust by the delta at use time. - rip_rel_pending = true; - rip_rel_disp = disp; - let ea : qword = decode_pos + disp; - let ad_keep : qword = sign_extend(~(pfx.has_adsize)); - let ea : qword = ea & (ad_keep | 0x00000000FFFFFFFF); - RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) - } else { - // Compat/protected mode: [disp32] absolute (no RIP-relative) - let ea : qword = disp & 0x00000000FFFFFFFF; - RM_mem(struct { seg = resolve_seg(pfx, DS), addr = ea }) - } - } else { - // Memory operand — compute address then apply segment - let asz = get_address_size(pfx); - // Default segment: BP/SP-based → SS, otherwise → DS (base_default_seg) - var default_seg : segreg_idx = base_default_seg(rm_raw, modbits, pfx); - let addr : qword = - if rm_raw == 0b100 then { - // SIB byte follows - let sib : byte = fetch(1); - default_seg = base_default_seg(sib[2..0], modbits, pfx); - decode_sib(sib, modbits, pfx) - } else if modbits == 0 then { - // [reg] no displacement - v(64, unsigned(pfx.rex_b @ rm_raw)) - } else { - if modbits == 1 then { - // [reg] + disp8 - v(64, unsigned(pfx.rex_b @ rm_raw)) + sign_extend(fetch(1)) - } else { - // modbits == 2: [reg] + disp32 - v(64, unsigned(pfx.rex_b @ rm_raw)) + sign_extend(fetch(4)) - } - }; - // Truncate address based on address size - let addr : qword = match asz { - 16 => addr & 0x000000000000FFFF, - 32 => addr & 0x00000000FFFFFFFF, - 64 => addr, - }; - RM_mem(struct { seg = resolve_seg(pfx, default_seg), addr = addr }) - } -} - -// Decode ModR/M r/m as a SIMD register-or-memory operand. -val modrm_xrm : (byte, Prefixes) -> XRM -function modrm_xrm(modrm, pfx) = match modrm_rm(modrm, pfx) { - RM_reg(_) => XRM_reg(unsigned(pfx.rex_b @ modrm[2..0])), - RM_mem(m) => XRM_mem(m), -} - -// Fetch and decode ModR/M byte, returning GPRRef reg and RM operand. -val fetch_modrm : Prefixes -> (GPRRef, RM) -function fetch_modrm(pfx) = { - let modrm : byte = fetch(1); - (modrm_reg(modrm, pfx), modrm_rm(modrm, pfx)) -} - -// Fetch and decode ModR/M byte, returning raw reg field and RM operand. -// Use for group opcodes and segment register instructions. -val fetch_modrm_raw : Prefixes -> (range(0, 7), RM) -function fetch_modrm_raw(pfx) = { - let modrm : byte = fetch(1); - let reg_field : range(0, 7) = unsigned(modrm[5..3]); - (reg_field, modrm_rm(modrm, pfx)) -} - -// The 16-byte alignment of the m128 source of a legacy SSE load/execute -// instruction: #GP(0) if misaligned, unless MXCSR.MM (bit 17) is 1. "AMD -// processors that support Misaligned SSE Mode may be programmed to disable -// this exception behavior for legacy load/execute SSE instructions"; "If -// MXCSR.MM is set, the #GP is inhibited and the exception behavior depends -// on the alignment checking mechanism" (APM Vol.1 §4.3.2 p.120-121), whose -// #AC the model implements for no instruction. MM can be 1 only on a -// machine whose MXCSR_MASK has bit 17, one with MisAlignSse -// (has_misalignsse). The instructions that "do not support misaligned -// accesses" use decode_xmm_src_aligned. -val check_sse_src_alignment : MemRef -> unit -function check_sse_src_alignment(m) = - if __stmxcsr()[17] == bitzero then check_alignment(m, 16) - -// Helper: decode XMM src operand value (read from register or memory). -// Enforces 16-byte alignment for memory operands (legacy SSE default). -val decode_xmm_src : XRM -> xmmword -function decode_xmm_src(src) = match src { - XRM_reg(xi) => read_simd(xi), - XRM_mem(m) => { check_sse_src_alignment(m); read_mem(m) }, -} - -// The loads of MOVAPS, MOVAPD, MOVDQA and MOVNTDQA, #GP(0) for a -// misaligned operand whatever MXCSR.MM: "The FXSAVE, FXRSTOR, (V)MOVAPD, -// (V)MOVAPS, and (V)MOVDQA, (V)MOVNTDQ, (V)MOVNTPD and (V)MOVNTPS -// instructions do not support misaligned accesses" (APM Vol.1 §4.3.2 -// p.121), and the pages of these and of MOVNTDQA give the #GP with no MM -// condition (APM Vol.4 pp.283, 286, 296, 321). For MOVNTDQA, APM Vol.1 -// p.152 says instead that the read "causes a #GP or invokes the alignment -// checking mechanism depending on the setting of the MXCSR[MM] bit"; the -// model follows its instruction page. -val decode_xmm_src_aligned : XRM -> xmmword -function decode_xmm_src_aligned(src) = match src { - XRM_reg(xi) => read_simd(xi), - XRM_mem(m) => { check_alignment(m, 16); read_mem(m) }, -} - -// Unaligned variant: no alignment check (for MOVDQU, PCMPxSTRx, etc.). -val decode_xmm_src_u : XRM -> xmmword -function decode_xmm_src_u(src) = match src { - XRM_reg(xi) => read_simd(xi), - XRM_mem(m) => read_mem(m), -} - -// SSE FP source: scalar reads 32/64 bits, packed reads 128 bits. -// F3 (SS) → 32-bit memory read; F2 (SD) → 64-bit; NP/66 (PS/PD) → 128-bit. -// Packed path enforces 16-byte alignment; scalar paths do not. -val decode_sse_fp_src : (XRM, MandatoryPrefix) -> xmmword -function decode_sse_fp_src(src, mp) = match src { - XRM_reg(xi) => read_simd(xi), - XRM_mem(m) => match mp { - MP_F3 => zero_extend(read_mem(32, m)), - MP_F2 => zero_extend(read_mem(64, m)), - _ => { check_sse_src_alignment(m); read_mem(m) }, - }, -} - -// Scalar FP source: reads low 'eb bits from XMM register or 'eb bits from memory. -val decode_scalar_src : forall 'eb, 'eb in {8, 16, 32, 64}. (implicit('eb), XRM) -> bits('eb) -function decode_scalar_src(eb, src) = match src { - XRM_reg(xi) => ZMM[xi][('eb - 1) .. 0], - XRM_mem(m) => read_mem(m), -} - -// Partial XMM source: reads low 'n bits from XMM register or 'n bits from memory. -// No alignment check (used for PMOVSX/PMOVZX which read m16/m32/m64). -val decode_xmm_partial_src : forall 'n, 'n in {16, 32, 64}. (implicit('n), XRM) -> bits('n) -function decode_xmm_partial_src(n, src) = match src { - XRM_reg(xi) => ZMM[xi][('n - 1) .. 0], - XRM_mem(m) => read_mem(m), -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail deleted file mode 100644 index 82c65ff15..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_prefixes.sail +++ /dev/null @@ -1,112 +0,0 @@ -// x86-64 — Prefix Scanning -// -// Scans legacy prefixes and REX prefix from the instruction stream. -// In 64-bit mode, bytes 40-4F are REX prefixes (not INC/DEC). -// REX must be the last prefix before the opcode byte. - -val scan_prefixes : unit -> (Prefixes, byte) -function scan_prefixes() = { - var pfx : Prefixes = default_prefixes(); - var opcode : byte = 0x00; - var done : bool = false; - - // Loop scanning prefix bytes. The 15-byte instruction length limit is - // enforced by fetch(1), which raises #GP(0) if exceeded. - while ~(done) do { - let b : byte = fetch(1); - let bv : range(0, 255) = unsigned(b); - - // Clear REX state on any legacy prefix (REX must be last) - match bv { - // F0 = LOCK - 240 => pfx = {pfx with has_lock = true, has_rex = false, - rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // F2 = REPNE / mandatory prefix. F2 and F3 repeat the string and I/O - // instructions (exec_rep) and form the opcodes the opcode tables - // list with them (get_mandatory_prefix). Any other instruction - // ignores them, on both vendors. The APM defines that: "Repeat - // Prefixes—These prefixes affect only certain string instructions" - // (Vol.3 §1.2.1, p.6), and "The following prefixes are ignored by x87 - // instructions: REP—The F3h and F2h prefixes" (Vol.1 §6.6.2, p.327). - // The SDM leaves it open: "Use of repeat prefixes and/or undefined - // opcodes with other Intel 64 or IA-32 instructions is reserved; such - // use may cause unpredictable behavior" (Vol.2A §2.1.1, p.2-2), but - // for NOP, "NP 90", where other prefixes "will either cause an - // invalid-opcode exception (#UD) or result in the encoding for a - // different instruction" (Vol.2A §3.1.1.1, p.3-2): F2 90 is no - // instruction, and the model runs the NOP, as the APM has it. - // Where the APM's opcode maps form the opcode with F2 or F3 and list - // no instruction, "cells shaded gray represent reserved opcodes" - // (Vol.3 §A.1, p.524), #UD: the model raises it in the SSE, 0F 38 - // and 0F 3A maps and Groups 9 and 15, but not for 0F BA, 0F BB, MOVSX - // and CMPXCHG8B with either, nor BSF and BSR with F2 (Table A-4, - // p.532, Table A-7, p.536), which it runs as without the prefix. - 242 => pfx = {pfx with has_repne = true, has_rep = false, has_rex = false, - rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // F3 = REP / mandatory prefix - 243 => pfx = {pfx with has_rep = true, has_repne = false, has_rex = false, - rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 26 = ES override. In 64-bit mode, "the CS, DS, ES, and SS - // segment-override prefixes have no effect" and "are treated as null - // prefixes" (AMD64 APM Vol.3 §1.2.4): they leave the segment, and an - // FS or GS override before them, as they are. So does the SDM: - // "Other segment override prefixes (CS, DS, ES, and SS) are ignored" - // (Vol.1 §3.3.7.1 p.3-10), and a non-canonical ds:[rbp] is #SS(0), - // as without the prefix. - 38 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(ES), - has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 2E = CS override - 46 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(CS), - has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 36 = SS override - 54 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(SS), - has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 3E = DS override - 62 => pfx = {pfx with seg_override = if cur_mode == LongMode then pfx.seg_override else Some(DS), - has_rex = false, rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 64 = FS override - 100 => pfx = {pfx with seg_override = Some(FS), has_rex = false, - rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 65 = GS override - 101 => pfx = {pfx with seg_override = Some(GS), has_rex = false, - rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 66 = operand size override - 102 => pfx = {pfx with has_opsize = true, has_rex = false, - rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 67 = address size override - 103 => pfx = {pfx with has_adsize = 0b1, has_rex = false, - rex_w = false, rex_r = 0b0, rex_x = 0b0, rex_b = 0b0}, - // 40-4F = REX prefix (64-bit mode only; INC/DEC in 32-bit mode) - bv if 64 <= bv & bv <= 79 & cur_mode == LongMode => - pfx = {pfx with - has_rex = true, - rex_w = b[3] == 0b1, - rex_r = b[2], - rex_x = b[1], - rex_b = b[0], - }, - _ => { - // Not a prefix — this is the opcode byte - opcode = b; - done = true; - }, - } - }; - (pfx, opcode) -} - -// Determine the mandatory prefix for 2-byte/3-byte opcode interpretation. -// F2/F3 take priority over 66. Last F2/F3 wins (handled in scan_prefixes). -val get_mandatory_prefix : Prefixes -> MandatoryPrefix -function get_mandatory_prefix(pfx) = - if pfx.has_repne then MP_F2 - else if pfx.has_rep then MP_F3 - else if pfx.has_opsize then MP_66 - else MP_NONE - -// VEX and EVEX are #UD after a LOCK, 66h, F2h or F3h prefix, or after a REX -// prefix (one followed by the escape byte; scan_prefixes forgets a REX -// that another prefix follows) (SDM Vol.2 §2.3.2, §2.7.11.1). -val vex_after_legacy_prefix : Prefixes -> bool -function vex_after_legacy_prefix(pfx) = - pfx.has_lock | pfx.has_opsize | pfx.has_repne | pfx.has_rep | pfx.has_rex diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail deleted file mode 100644 index 2021f7e4a..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_simd.sail +++ /dev/null @@ -1,698 +0,0 @@ -// x86-64 — Shared SIMD Helpers -// -// Generic packed element-wise operations and vector-width helper functions -// shared across legacy SSE, VEX, and EVEX instruction files. - -// ========================================================================= -// Broadcast: replicate an element to fill a vector. -// ========================================================================= - -val broadcast : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (implicit('vl), bits('eb)) -> bits('vl) -function broadcast(vl, v) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - r[(lo + 'eb - 1)..lo] = v - }; - r -} - -// ========================================================================= -// Generic packed element-wise operations -// ========================================================================= - -// Generic packed unary operation (element-wise, one source). -enum PackedUnaryOp = { - PU_Abs, PU_Popcnt, PU_Lzcnt, PU_FSqrt, PU_FRsqrt, PU_FRcp, - PU_CvtDQ2PS, PU_CvtPS2DQ, PU_CvtTPS2DQ, - PU_CvtPS2UDQ, PU_CvtTPS2UDQ, - PU_CvtUDQ2PS, - PU_CvtPD2QQ, PU_CvtTPD2QQ, - PU_CvtPD2UQQ, PU_CvtTPD2UQQ, - PU_CvtQQ2PD, PU_CvtUQQ2PD, - PU_CvtPH2W, PU_CvtPH2UW, PU_CvtTPH2W, PU_CvtTPH2UW, - PU_CvtW2PH, PU_CvtUW2PH, - PU_FPGetexp, PU_FPRcp14, PU_FPRsqrt14, PU_FPRcp28, PU_FPRsqrt28, PU_FPExp2 -} - -val packed_unary_elem : forall 'eb, 'eb in {8, 16, 32, 64}. - (PackedUnaryOp, bits('eb)) -> bits('eb) -function packed_unary_elem(op, a) = match op { - PU_Abs => abs(a), - PU_Popcnt => to_bits(popcount(a)), - PU_Lzcnt => to_bits(clz(a)), - PU_FSqrt => fp_sqrt(a), - PU_FRsqrt => fp_rsqrt(a), - PU_FRcp => fp_rcp(a), - PU_CvtDQ2PS => { assert('eb == 32); __int32_to_f32(a) }, - PU_CvtPS2DQ => { assert('eb == 32); __f32_to_int32(a) }, - PU_CvtTPS2DQ => { assert('eb == 32); __f32_to_int32_trunc(a) }, - PU_CvtPS2UDQ => { assert('eb == 32); __f32_to_uint32(a) }, - PU_CvtTPS2UDQ => { assert('eb == 32); __f32_to_uint32_trunc(a) }, - PU_CvtUDQ2PS => { assert('eb == 32); __uint32_to_f32(a) }, - PU_CvtPD2QQ => { assert('eb == 64); __f64_to_int64(a) }, - PU_CvtTPD2QQ => { assert('eb == 64); __f64_to_int64_trunc(a) }, - PU_CvtPD2UQQ => { assert('eb == 64); __f64_to_uint64(a) }, - PU_CvtTPD2UQQ => { assert('eb == 64); __f64_to_uint64_trunc(a) }, - PU_CvtQQ2PD => { assert('eb == 64); __int64_to_f64(a) }, - PU_CvtUQQ2PD => { assert('eb == 64); __uint64_to_f64(a) }, - PU_CvtPH2W => { assert('eb == 16); __f16_to_int16(a) }, - PU_CvtPH2UW => { assert('eb == 16); __f16_to_uint16(a) }, - PU_CvtTPH2W => { assert('eb == 16); __f16_to_int16_trunc(a) }, - PU_CvtTPH2UW => { assert('eb == 16); __f16_to_uint16_trunc(a) }, - PU_CvtW2PH => { assert('eb == 16); __int16_to_f16(a) }, - PU_CvtUW2PH => { assert('eb == 16); __uint16_to_f16(a) }, - PU_FPGetexp => fp_getexp(a), - PU_FPRcp14 => fp_rcp14(a), - PU_FPRsqrt14 => fp_rsqrt14(a), - PU_FPRcp28 => fp_rcp28(a), - PU_FPRsqrt28 => fp_rsqrt28(a), - PU_FPExp2 => fp_exp2(a), -} - -val packed_unop : forall 'vl 'eb, 'vl in {64, 128, 256, 512} & 'eb in {8, 16, 32, 64}. - (PackedUnaryOp, int('eb), bits('vl)) -> bits('vl) -function packed_unop(op, eb, a) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - r[(lo + 'eb - 1)..lo] = packed_unary_elem(op, velem('eb, a, i)) - }; - r -} - -// Generic packed binary operation (element-wise, two sources). -enum PackedBinOp = { - PB_Add, PB_Sub, - PB_SatAddS, PB_SatSubS, PB_SatAddU, PB_SatSubU, - PB_MinU, PB_MaxU, PB_MinS, PB_MaxS, - PB_Avg, - PB_Srl, PB_Sra, PB_Sll, - PB_MulLow, PB_MulHighS, PB_MulHighU, PB_MulHRS, - PB_Ror, PB_Rol, - PB_CmpEq, PB_CmpGt, - PB_PSign, - PB_FAdd, PB_FSub, PB_FMul, PB_FDiv, PB_FMin, PB_FMax, - PB_FPScalef, - PB_Psadbw, PB_Pmaddubsw, PB_Pmaddwd, PB_Pmuludq, PB_Pmuldq, PB_Pshufb, - PB_HorizAddW, PB_HorizAddD, PB_HorizSatAddW, - PB_HorizSubW, PB_HorizSubD, PB_HorizSatSubW, - PB_HorizFAddS, PB_HorizFAddD, PB_HorizFSubS, PB_HorizFSubD, - PB_FAddSubS, PB_FAddSubD, - PB_And, PB_Or, PB_Xor, PB_Andn, -} - -// PMADDWD per-pair: signed * signed + signed * signed -val pmaddwd_pair : (word, word, word, word) -> dword -function pmaddwd_pair(a, b, c, d) = - to_bits_truncate(signed(a) * signed(b) + signed(c) * signed(d)) - -// Forward declaration — defined after packed_elem_op. -val packed_horiz : forall 'ew, 'ew in {16, 32, 64}. - (PackedBinOp, int('ew), bits(128)) -> bits(64) - -// Per-element dispatch: applies the operation to one pair of elements. -// Most ops work at eb in {8,16,32,64}; lane ops (PB_Pshufb etc.) work at eb=128. -val packed_elem_op : forall 'eb, 'eb in {8, 16, 32, 64, 128}. - (PackedBinOp, bits('eb), bits('eb)) -> bits('eb) -function packed_elem_op(op, a, b) = match op { - PB_Add => a + b, - PB_Sub => a - b, - PB_SatAddS => { assert('eb <= 64); sat_add_s(a, b) }, - PB_SatSubS => { assert('eb <= 64); sat_sub_s(a, b) }, - PB_SatAddU => { assert('eb <= 64); sat_add_u(a, b) }, - PB_SatSubU => { assert('eb <= 64); sat_sub_u(a, b) }, - PB_MinU => { assert('eb <= 64); min_u(a, b) }, - PB_MaxU => { assert('eb <= 64); max_u(a, b) }, - PB_MinS => { assert('eb <= 64); min_s(a, b) }, - PB_MaxS => { assert('eb <= 64); max_s(a, b) }, - PB_Avg => { assert('eb <= 64); avg(a, b) }, - // Per-element shift counts (VPSRLV*, VPSRAV*, VPSLLV*; SDM Vol.2C): a - // count of at least the element width leaves 0, or for the arithmetic - // shift every bit equal to the sign bit. Shifting by the raw lane value - // would build an intermediate as wide as the count. - PB_Srl => if unsigned(b) >= 'eb then zeros() else a >> unsigned(b), - PB_Sra => if unsigned(b) >= 'eb then (if a['eb - 1] == bitone then ones() else zeros()) - else a >>> unsigned(b), - PB_Sll => if unsigned(b) >= 'eb then zeros() else a << unsigned(b), - PB_MulLow => to_bits_truncate(signed(a) * signed(b)), - PB_MulHighS => get_slice_int('eb, signed(a) * signed(b), 'eb), - PB_MulHighU => get_slice_int('eb, unsigned(a) * unsigned(b), 'eb), - PB_MulHRS => { assert('eb <= 64); mulhrs(a, b) }, - PB_Ror => { assert('eb <= 64); rotr(a, unsigned(b) % 'eb) }, - PB_Rol => { assert('eb <= 64); rotl(a, unsigned(b) % 'eb) }, - PB_CmpEq => { assert('eb <= 64); cmp_eq(a, b) }, - PB_CmpGt => { assert('eb <= 64); cmp_gt(a, b) }, - PB_PSign => { assert('eb <= 64); psign(a, b) }, - PB_FAdd => { assert('eb <= 64); fp_add(a, b) }, - PB_FSub => { assert('eb <= 64); fp_sub(a, b) }, - PB_FMul => { assert('eb <= 64); fp_mul(a, b) }, - PB_FDiv => { assert('eb <= 64); fp_div(a, b) }, - PB_FMin => { assert('eb <= 64); fp_min(a, b) }, - PB_FMax => { assert('eb <= 64); fp_max(a, b) }, - PB_FPScalef => { assert('eb <= 64); fp_scalef(a, b) }, - PB_And => a & b, - PB_Or => a | b, - PB_Xor => a ^ b, - PB_Andn => ~(a) & b, - - // Ops with internal sub-element structure - PB_Pmaddubsw => { assert('eb == 16); pmaddubsw_pair(a[7..0], b[7..0], a[15..8], b[15..8]) }, - PB_Pmaddwd => { assert('eb == 32); pmaddwd_pair(a[15..0], b[15..0], a[31..16], b[31..16]) }, - PB_Pmuludq => { assert('eb == 64); to_bits(64, unsigned(a[31..0]) * unsigned(b[31..0])) }, - PB_Pmuldq => { assert('eb == 64); to_bits_truncate(signed(a[31..0]) * signed(b[31..0])) }, - PB_Psadbw => { assert('eb == 64); psadbw(a, b) }, - PB_Pshufb => { assert('eb == 128); pshufb(a, b) }, - PB_HorizAddW => { assert('eb == 128); packed_horiz(PB_Add, 16, b) @ packed_horiz(PB_Add, 16, a) }, - PB_HorizAddD => { assert('eb == 128); packed_horiz(PB_Add, 32, b) @ packed_horiz(PB_Add, 32, a) }, - PB_HorizSatAddW => { assert('eb == 128); packed_horiz(PB_SatAddS, 16, b) @ packed_horiz(PB_SatAddS, 16, a) }, - PB_HorizSubW => { assert('eb == 128); packed_horiz(PB_Sub, 16, b) @ packed_horiz(PB_Sub, 16, a) }, - PB_HorizSubD => { assert('eb == 128); packed_horiz(PB_Sub, 32, b) @ packed_horiz(PB_Sub, 32, a) }, - PB_HorizSatSubW => { assert('eb == 128); packed_horiz(PB_SatSubS, 16, b) @ packed_horiz(PB_SatSubS, 16, a) }, - PB_HorizFAddS => { assert('eb == 128); packed_horiz(PB_FAdd, 32, b) @ packed_horiz(PB_FAdd, 32, a) }, - PB_HorizFAddD => { assert('eb == 128); packed_horiz(PB_FAdd, 64, b) @ packed_horiz(PB_FAdd, 64, a) }, - PB_HorizFSubS => { assert('eb == 128); packed_horiz(PB_FSub, 32, b) @ packed_horiz(PB_FSub, 32, a) }, - PB_HorizFSubD => { assert('eb == 128); packed_horiz(PB_FSub, 64, b) @ packed_horiz(PB_FSub, 64, a) }, - // ADDSUBPS: even dwords use SUB, odd dwords use ADD - PB_FAddSubS => { assert('eb == 128); fp_add(a[127..96], b[127..96]) @ fp_sub(a[95..64], b[95..64]) @ - fp_add(a[63..32], b[63..32]) @ fp_sub(a[31..0], b[31..0]) }, - // ADDSUBPD: low qword uses SUB, high qword uses ADD - PB_FAddSubD => { assert('eb == 128); fp_add(a[127..64], b[127..64]) @ fp_sub(a[63..0], b[63..0]) }, -} - -// Reduce adjacent ew-bit element pairs within a 128-bit vector, producing 64 bits. -function packed_horiz(op, ew, src) = { - var r : bits(64) = zeros(); - foreach (i from 0 to (64 / ew - 1)) { - let s = i * 2 * ew; - let d = i * ew; - r[(d + ew - 1)..d] = packed_elem_op(op, src[(s + ew - 1)..s], src[(s + 2 * ew - 1)..(s + ew)]); - }; - r -} - -// Apply a packed binary operation element-wise across a vector. -val packed_binop : forall 'vl 'eb, 'vl in {64, 128, 256, 512} & 'eb in {8, 16, 32, 64, 128}. - (PackedBinOp, int('eb), bits('vl), bits('vl)) -> bits('vl) -function packed_binop(op, eb, a, b) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - r[(lo + 'eb - 1)..lo] = packed_elem_op(op, velem('eb, a, i), velem('eb, b, i)) - }; - r -} - -// Per-lane unary-with-immediate operations (PSHUFD, PSHUFHW, PSHUFLW). -enum PackedLaneImmOp = { PLI_Pshufd, PLI_Pshufhw, PLI_Pshuflw } - -val packed_lane_imm_elem : (PackedLaneImmOp, bits(128), byte) -> bits(128) -function packed_lane_imm_elem(op, src, imm) = match op { - PLI_Pshufd => { - var r : bits(128) = zeros(); - foreach (i from 0 to 3) { - let sel : range(0, 3) = unsigned(imm[(i * 2 + 1)..(i * 2)]); - let lo = i * 32; - r[(lo + 31)..lo] = velem(32, src, sel) - }; - r - }, - PLI_Pshufhw => { - var r : bits(128) = zeros(); - r[63..0] = src[63..0]; - foreach (i from 0 to 3) { - let sel : range(0, 3) = unsigned(imm[(i * 2 + 1)..(i * 2)]); - let lo = i * 16 + 64; - r[(lo + 15)..lo] = velem(16, src, sel + 4) - }; - r - }, - PLI_Pshuflw => { - var r : bits(128) = zeros(); - r[127..64] = src[127..64]; - foreach (i from 0 to 3) { - let sel : range(0, 3) = unsigned(imm[(i * 2 + 1)..(i * 2)]); - let lo = i * 16; - r[(lo + 15)..lo] = velem(16, src, sel) - }; - r - }, -} - -val packed_lane_imm_op : forall 'vl, 'vl in {128, 256, 512}. - (PackedLaneImmOp, bits('vl), byte) -> bits('vl) -function packed_lane_imm_op(op, src, imm) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 128 - 1)) { - let lo = i * 128; - r[(lo + 127)..lo] = packed_lane_imm_elem(op, velem(128, src, i), imm) - }; - r -} - -// Uniform packed shift: apply a scalar shift count to all elements. -enum PackedShiftOp = { PS_Srl, PS_Sra, PS_Sll } - -val packed_uniform_shift : forall 'vl 'eb, 'vl in {64, 128, 256, 512} & 'eb in {16, 32, 64, 128}. - (PackedShiftOp, int('eb), bits('vl), nat) -> bits('vl) -function packed_uniform_shift(op, eb, src, count) = { - // A count greater than the element width leaves all 0s (PSRL*, PSLL*) or - // the sign bit in every position (PSRA*): SDM PSRLW/PSRLD/PSRLQ, - // PSLLW/PSLLD/PSLLQ, PSRAW/PSRAD/PSRAQ, Description. Shifting by the - // width itself gives the same result, so clamp the count there; the - // 64-bit register count can otherwise exceed what the bitvector shift - // accepts. - let c : nat = if count > eb then eb else count; - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - let e = velem('eb, src, i); - r[(lo + 'eb - 1)..lo] = match op { - PS_Srl => e >> c, - PS_Sra => e >>> c, - PS_Sll => e << c, - } - }; - r -} - -// Interleave elements from two sources (PUNPCKLBW/WD/DQ/QDQ, PUNPCKHBW/WD/DQ/QDQ). -// Within each 128-bit lane, takes elements from the low (half=0) or high (half=64) -// half of a and b, and interleaves them: r[2i]=a[half+i], r[2i+1]=b[half+i]. -val packed_unpack : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (int('eb), {0, 64}, bits('vl), bits('vl)) -> bits('vl) -function packed_unpack(eb, half, a, b) = { - var r : bits('vl) = zeros(); - let elems_per_half = 64 / eb; - foreach (j from 0 to ('vl / 128 - 1)) { - let lbase = j * 128; - foreach (i from 0 to (elems_per_half - 1)) { - let src_lo = lbase + half + i * eb; - let dst_lo = lbase + i * 2 * eb; - r[(dst_lo + eb - 1)..dst_lo] = a[(src_lo + eb - 1)..src_lo]; - r[(dst_lo + 2 * eb - 1)..(dst_lo + eb)] = b[(src_lo + eb - 1)..src_lo]; - } - }; - r -} - -// Generic packed narrowing unary operation (each element shrinks). -// BF16 conversion: FP32 → BFloat16 (RNE, denormals flush to zero) -val convert_fp32_to_bf16 : dword -> word -function convert_fp32_to_bf16(x) = { - let exp : byte = x[30..23]; - let mant : bits(23) = x[22..0]; - let exp_zero : bit = is_zero(exp); - let exp_all : bit = is_zero(~(exp)); - let mant_nz : bit = is_nonzero(mant); - let r_zero : word = x[31] @ zeros(15); - let r_nan : word = x[31..16] | 0x0040; - let r_inf : word = x[31..16]; - let r_normal : word = (x + 0x00007FFF + zero_extend(x[16]))[31..16]; - let r1 : word = blend(r_normal, r_zero, exp_zero); - let r2 : word = blend(r1, r_inf, exp_all & ~(mant_nz)); - blend(r2, r_nan, exp_all & mant_nz) -} - -enum PackedNarrowOp = { PN_Trunc, PN_SatU, PN_SatS, PN_SatSU, PN_FP32toBF16 } - -val packed_narrow_elem : forall 'src 'dst, 'src in {16, 32, 64} & 'dst in {8, 16, 32} & 'src > 'dst. - (PackedNarrowOp, int('dst), bits('src)) -> bits('dst) -function packed_narrow_elem(op, dst, a) = match op { - PN_Trunc => a[('dst - 1)..0], - PN_SatU => sat_u(a), - PN_SatS => sat_s(a), - PN_SatSU => sat_su(a), - PN_FP32toBF16 => { assert('src == 32 & 'dst == 16); convert_fp32_to_bf16(a) }, -} - -val packed_narrow_unop : forall 'vl 'src 'dst, - 'vl in {128, 256, 512} & 'src in {16, 32, 64} & 'dst in {8, 16, 32} & 'src > 'dst. - (PackedNarrowOp, int('src), int('dst), bits('vl)) -> bits(div('vl * 'dst, 'src)) -function packed_narrow_unop(op, src_eb, dst_eb, a) = { - var r : bits(div('vl * 'dst, 'src)) = zeros(); - foreach (i from 0 to ('vl / 'src - 1)) { - let slo = i * 'src; - let dlo = i * 'dst; - r[(dlo + 'dst - 1)..dlo] = packed_narrow_elem(op, dst_eb, a[(slo + 'src - 1)..slo]) - }; - r -} - -// Two-source narrowing pack: within each 128-bit lane, narrow elements from a -// into the lower half and from b into the upper half, applying saturation. -// Covers PACKSSWB (PN_SatS, 16→8), PACKSSDW (PN_SatS, 32→16), -// PACKUSWB (PN_SatSU, 16→8), PACKUSDW (PN_SatSU, 32→16). -val packed_pack : forall 'vl 'src 'dst, - 'vl in {128, 256, 512} & 'src in {16, 32} & 'dst in {8, 16} & 'src == 'dst * 2. - (PackedNarrowOp, int('src), int('dst), bits('vl), bits('vl)) -> bits('vl) -function packed_pack(op, src, dst, a, b) = { - var r : bits('vl) = zeros(); - let elems = 128 / src; - foreach (j from 0 to ('vl / 128 - 1)) { - let lbase = j * 128; - foreach (i from 0 to (elems - 1)) { - let slo = lbase + i * src; - let a_lo = lbase + i * dst; - let b_lo = lbase + 64 + i * dst; - r[(a_lo + dst - 1)..a_lo] = packed_narrow_elem(op, dst, a[(slo + src - 1)..slo]); - r[(b_lo + dst - 1)..b_lo] = packed_narrow_elem(op, dst, b[(slo + src - 1)..slo]); - } - }; - r -} - -// Generic packed widening unary operation (each element expands). -enum PackedWidenOp = { PW_SignExtend, PW_ZeroExtend } - -val packed_widen_unop : forall 'vl 'n 'src 'dst, - 'vl in {128, 256, 512} & 'src in {8, 16, 32} & 'dst in {16, 32, 64} & 'dst > 'src & - 'n > 0 & 'n * 'dst == 'vl * 'src. - (implicit('vl), PackedWidenOp, int('src), int('dst), bits('n)) -> bits('vl) -function packed_widen_unop(vl, op, src_eb, dst_eb, a) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'dst - 1)) { - let slo = i * 'src; - let dlo = i * 'dst; - let elem = a[(slo + 'src - 1)..slo]; - r[(dlo + 'dst - 1)..dlo] = match op { - PW_SignExtend => sign_extend(dst_eb, elem), - PW_ZeroExtend => zero_extend(dst_eb, elem), - } - }; - r -} - -// Generic packed ternary operation (element-wise, three sources). -enum PackedTernaryOp = { - PT_FMAdd, PT_FMSub, PT_FNMAdd, PT_FNMSub, - PT_FunnelShl, PT_FunnelShr, - PT_DPBusd, PT_DPBusds, PT_DPWssd, PT_DPWssds, -} - -val packed_ternary_elem : forall 'eb, 'eb in {8, 16, 32, 64}. - (PackedTernaryOp, bits('eb), bits('eb), bits('eb)) -> bits('eb) -function packed_ternary_elem(op, a, b, c) = match op { - PT_FMAdd => fp_fmadd(a, b, c), - PT_FMSub => fp_fmsub(a, b, c), - PT_FNMAdd => fp_fnmadd(a, b, c), - PT_FNMSub => fp_fnmsub(a, b, c), - PT_FunnelShl => velem('eb, (a @ b) << (unsigned(c) % 'eb), 1), - PT_FunnelShr => velem('eb, (b @ a) >> (unsigned(c) % 'eb), 0), - - PT_DPBusd => { - assert('eb == 32); - to_bits_truncate(32, signed(a) - + unsigned(b[7..0]) * signed(c[7..0]) - + unsigned(b[15..8]) * signed(c[15..8]) - + unsigned(b[23..16]) * signed(c[23..16]) - + unsigned(b[31..24]) * signed(c[31..24])) - }, - PT_DPBusds => { - assert('eb == 32); - sat_s(to_bits_truncate(33, signed(a) - + unsigned(b[7..0]) * signed(c[7..0]) - + unsigned(b[15..8]) * signed(c[15..8]) - + unsigned(b[23..16]) * signed(c[23..16]) - + unsigned(b[31..24]) * signed(c[31..24]))) - }, - PT_DPWssd => { - assert('eb == 32); - to_bits_truncate(32, signed(a) - + signed(b[15..0]) * signed(c[15..0]) - + signed(b[31..16]) * signed(c[31..16])) - }, - PT_DPWssds => { - assert('eb == 32); - sat_s(to_bits_truncate(33, signed(a) - + signed(b[15..0]) * signed(c[15..0]) - + signed(b[31..16]) * signed(c[31..16]))) - }, -} - -val packed_ternop : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (PackedTernaryOp, int('eb), bits('vl), bits('vl), bits('vl)) -> bits('vl) -function packed_ternop(op, eb, a, b, c) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - r[(lo + 'eb - 1)..lo] = packed_ternary_elem(op, velem('eb, a, i), velem('eb, b, i), velem('eb, c, i)) - }; - r -} - -// ========================================================================= -// FP16 <-> FP32 packed conversion -// ========================================================================= - -val avx_vcvtph2ps : forall 'n, 'n in {64, 128, 256}. bits('n) -> bits('n * 2) -function avx_vcvtph2ps(src) = { - var r : bits('n * 2) = zeros(); - foreach (i from 0 to ('n / 16 - 1)) { - let lo = i * 32; - r[(lo + 31)..lo] = fp16_to_fp32(velem(16, src, i)); - }; - r -} - -val avx_vcvtps2ph : forall 'n, 'n in {128, 256, 512}. (bits('n), bits(2)) -> bits(div('n, 2)) -function avx_vcvtps2ph(src, rc) = { - var r : bits(div('n, 2)) = zeros(); - foreach (i from 0 to ('n / 32 - 1)) { - let lo = i * 16; - r[(lo + 15)..lo] = fp32_to_fp16(velem(32, src, i), rc); - }; - r -} - -// ========================================================================= -// GFNI vector operations -// ========================================================================= - -val avx_gf2p8mulb : forall 'vl, 'vl in {128, 256, 512}. - (bits('vl), bits('vl)) -> bits('vl) -function avx_gf2p8mulb(src1, src2) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 8 - 1)) { - let lo = i * 8; - r[(lo + 7)..lo] = gf2p8_mul(velem(8, src1, i), velem(8, src2, i)); - }; - r -} - -// Per-byte affine transform; each byte uses the 8x8 matrix from its 64-bit lane. -val avx_gf2p8affineqb : forall 'vl, 'vl in {128, 256, 512}. - (bits('vl), bits('vl), byte) -> bits('vl) -function avx_gf2p8affineqb(src1, src2, imm8) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 8 - 1)) { - let lo = i * 8; - r[(lo + 7)..lo] = gf2p8_affine(velem(8, src1, i), velem(64, src2, i / 8), imm8); - }; - r -} - -// Same but first applies GF(2^8) inverse on each src1 byte. -val avx_gf2p8affineinvqb : forall 'vl, 'vl in {128, 256, 512}. - (bits('vl), bits('vl), byte) -> bits('vl) -function avx_gf2p8affineinvqb(src1, src2, imm8) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 8 - 1)) { - let lo = i * 8; - r[(lo + 7)..lo] = gf2p8_affine(gf2p8_inv(velem(8, src1, i)), velem(64, src2, i / 8), imm8); - }; - r -} - -// ========================================================================= -// VP2INTERSECTD/Q: intersection of two element sets as position masks -// ========================================================================= - -// Bit i of the first mask is set when src1 element i occurs anywhere in -// src2; bit j of the second when src2 element j occurs anywhere in src1. -val vp2intersect : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {32, 64}. - (int('eb), bits('vl), bits('vl)) -> (qword, qword) -function vp2intersect(eb, src1, src2) = { - var m1 : qword = zeros(); - var m2 : qword = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - foreach (j from 0 to ('vl / 'eb - 1)) { - if velem('eb, src1, i) == velem('eb, src2, j) then { - m1[i] = bitone; - m2[j] = bitone - } - } - }; - (m1, m2) -} - -// ========================================================================= -// AES rounds on every 128-bit lane (VEX.256 and EVEX forms, VAES) -// ========================================================================= - -enum AesRound = { AES_Enc, AES_EncLast, AES_Dec, AES_DecLast } - -// The four rounds occupy opcodes 0F38 DC-DF in every encoding. -val aes_round_of_opcode : range(0, 255) -> AesRound -function aes_round_of_opcode(op) = match op { - 220 => AES_Enc, - 221 => AES_EncLast, - 222 => AES_Dec, - _ => AES_DecLast, -} - -val aes_round : (AesRound, xmmword, xmmword) -> xmmword -function aes_round(op, state, key) = match op { - AES_Enc => aesenc(state, key), - AES_EncLast => aesenclast(state, key), - AES_Dec => aesdec(state, key), - AES_DecLast => aesdeclast(state, key), -} - -// One round per 128-bit lane, each lane with its own state and round key. -val avx_aes_round : forall 'vl, 'vl in {128, 256, 512}. - (AesRound, bits('vl), bits('vl)) -> bits('vl) -function avx_aes_round(op, state, key) = { - var r : bits('vl) = zeros(); - foreach (lane from 0 to ('vl / 128 - 1)) { - let lo = lane * 128; - r[(lo + 127)..lo] = aes_round(op, velem(128, state, lane), velem(128, key, lane)); - }; - r -} - -// ========================================================================= -// Cross-lane permute (1-source and 2-source) -// ========================================================================= - -// 1-source permute: for each element i, result[i] = src[idx[i] % n_elems]. -val packed_permute : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (int('eb), bits('vl), bits('vl)) -> bits('vl) -function packed_permute(eb, src, idx) = { - var r : bits('vl) = zeros(); - let n = 'vl / 'eb; - foreach (i from 0 to (n - 1)) { - let j = unsigned(velem('eb, idx, i)) % n; - let lo = i * 'eb; - r[(lo + 'eb - 1)..lo] = velem('eb, src, j) - }; - r -} - -// 2-source permute: for each element i, result[i] = concat(t1,t2)[idx[i] % (2*n_elems)]. -val packed_permute2 : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (int('eb), bits('vl), bits('vl), bits('vl)) -> bits('vl) -function packed_permute2(eb, t1, t2, idx) = { - var r : bits('vl) = zeros(); - let n = 'vl / 'eb; - foreach (i from 0 to (n - 1)) { - let j = unsigned(velem('eb, idx, i)) % (2 * n); - let k = j % n; - let sel : bit = bool_to_bit(j >= n); - let lo = i * 'eb; - r[(lo + 'eb - 1)..lo] = blend(velem('eb, t1, k), velem('eb, t2, k), sel) - }; - r -} - -// ========================================================================= -// Expand/compress: mask-driven scatter/gather within a vector -// ========================================================================= - -// Count set bits in mask below position 'upto'. -val popcount_mask : forall 'n, 0 < 'n & 'n <= 64. (bits('n), int) -> int -function popcount_mask(v, upto) = { - assert(upto >= 0); - let w : qword = zero_extend(v); - popcount(w & ((0x0000000000000001 << upto) - 1)) -} - -// Packed funnel shift with immediate count (VPSHLD/VPSHRD imm forms). -val packed_funnel_shl_imm : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {16, 32, 64}. - (int('eb), bits('vl), bits('vl), nat) -> bits('vl) -function packed_funnel_shl_imm(eb, src1, src2, cnt) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - let a = velem('eb, src1, i); - let b = velem('eb, src2, i); - r[(lo + 'eb - 1)..lo] = velem('eb, (a @ b) << (cnt % 'eb), 1) - }; - r -} - -val packed_funnel_shr_imm : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {16, 32, 64}. - (int('eb), bits('vl), bits('vl), nat) -> bits('vl) -function packed_funnel_shr_imm(eb, src1, src2, cnt) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - let a = velem('eb, src1, i); - let b = velem('eb, src2, i); - r[(lo + 'eb - 1)..lo] = velem('eb, (b @ a) >> (cnt % 'eb), 0) - }; - r -} - -// Expand: for each dest element i, if mask[i] is set, copy from the next -// contiguous source element (indexed by popcount of lower mask bits). -val packed_expand : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (int('eb), bits('vl), qword) -> bits('vl) -function packed_expand(eb, src, mask) = { - var result : bits('vl) = zeros(); - let n = 'vl / 'eb; - foreach (i from 0 to (n - 1)) { - let j = popcount_mask(mask, i); - assert(j >= 0); - let lo = i * 'eb; - let src_elem : bits('eb) = get_slice_int('eb, unsigned(src), j * 'eb); - let lane_mask : bits('eb) = sign_extend(mask[i..i]); - result[(lo + 'eb - 1)..lo] = src_elem & lane_mask; - }; - result -} - -// Compress: for each source element i, if mask[i] is set, pack it into the -// next contiguous dest position (indexed by popcount of lower mask bits). -val packed_compress : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (int('eb), bits('vl), qword) -> bits('vl) -function packed_compress(eb, src, mask) = { - var result : bits('vl) = zeros(); - let n = 'vl / 'eb; - foreach (i from 0 to (n - 1)) { - let j = popcount_mask(mask, i); - assert(j >= 0); - let src_elem : bits('eb) = get_slice_int('eb, unsigned(src), i * 'eb); - let lane_mask : bits('eb) = sign_extend(mask[i..i]); - result = result | (zero_extend(src_elem & lane_mask) << (j * 'eb)); - }; - result -} - -// Compress to memory: compress, then write only the populated bytes. -val packed_compress_mem : forall 'vl 'eb, 'vl in {128, 256, 512} & 'eb in {8, 16, 32, 64}. - (int('eb), qword, bits('vl), qword) -> unit -function packed_compress_mem(eb, addr, src, mask) = { - let result = packed_compress(eb, src, mask); - let nbits = popcount_mask(mask, 'vl / 'eb) * 'eb; - assert(nbits >= 0 & nbits <= 'vl); - if nbits > 0 then - write_mem_linear(addr, truncate(result, nbits)); -} - -// ========================================================================= -// FP compare → EFLAGS helper (UCOMISS/SD/SH, COMISS/SD/SH, FUCOMI, etc.) -// Sets ZF/PF/CF from comparison result, clears OF/SF/AF. -// ========================================================================= - -val set_eflags_fp_compare : forall 'n, 'n in {16, 32, 64, 80}. (bits('n), bits('n)) -> unit -function set_eflags_fp_compare(a, b) = { - match fp_compare(a, b) { - FP_UNORDERED => { ZF = 0b1; PF = 0b1; CF = 0b1 }, - FP_GT => { ZF = 0b0; PF = 0b0; CF = 0b0 }, - FP_LT => { ZF = 0b0; PF = 0b0; CF = 0b1 }, - FP_EQ => { ZF = 0b1; PF = 0b0; CF = 0b0 }, - }; - OF = 0b0; SF = 0b0; AF = 0b0 -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail deleted file mode 100644 index 9b46b9c04..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/insn_sse_fp.sail +++ /dev/null @@ -1,893 +0,0 @@ -// x86-64 — SSE Floating-Point Operations -// -// SSE/SSE2/SSE3 data movement, arithmetic, conversion, and comparison. - -// ========================================================================= -// SSE FP dispatch helpers — all-prefix binop/unop (PS/PD/SS/SD) -// ========================================================================= - -// SSE FP binary: MP_NONE=PS(32), MP_66=PD(64), MP_F3=SS, MP_F2=SD -val sse_exec_fp_binop : (PackedBinOp, simd_idx, xmmword, MandatoryPrefix) -> unit -function sse_exec_fp_binop(op, xreg, src_xmm, mp) = match mp { - MP_NONE => ZMM[xreg][127..0] = packed_binop(op, 32, read_simd(xreg), src_xmm), - MP_66 => ZMM[xreg][127..0] = packed_binop(op, 64, read_simd(xreg), src_xmm), - MP_F3 => ZMM[xreg][31..0] = packed_elem_op(op, ZMM[xreg][31..0], src_xmm[31..0]), - MP_F2 => ZMM[xreg][63..0] = packed_elem_op(op, ZMM[xreg][63..0], src_xmm[63..0]), -} - -// SSE FP unary: MP_NONE=PS(32), MP_66=PD(64), MP_F3=SS, MP_F2=SD -val sse_exec_fp_unop : (PackedUnaryOp, simd_idx, xmmword, MandatoryPrefix) -> unit -function sse_exec_fp_unop(op, xreg, src_xmm, mp) = match mp { - MP_NONE => ZMM[xreg][127..0] = packed_unop(op, 32, src_xmm), - MP_66 => ZMM[xreg][127..0] = packed_unop(op, 64, src_xmm), - MP_F3 => ZMM[xreg][31..0] = packed_unary_elem(op, src_xmm[31..0]), - MP_F2 => ZMM[xreg][63..0] = packed_unary_elem(op, src_xmm[63..0]), -} - -// ========================================================================= -// SSE floating-point dispatch -// ========================================================================= - -// FP comparison predicate helpers (used by CMPPS/CMPPD/CMPSS/CMPSD and -// EVEX VCMPPS/PD/SS/SD). SDM defines 32 predicates (imm8[4:0]). -// Predicates 16-31 repeat 0-15 with signaling/quiet flipped (same results). -// -// eval_fp_predicate: shared predicate logic on a comparison result. -// Returns 1 bit. Used by both SSE (sign-extended to mask) and EVEX (bit to kmask). -val eval_fp_predicate : (FPCompareResult, bits(4)) -> bit -function eval_fp_predicate(r, pred) = { - let unord : bit = match r { FP_UNORDERED => 0b1, _ => 0b0 }; - let eq : bit = match r { FP_EQ => 0b1, _ => 0b0 }; - let lt : bit = match r { FP_LT => 0b1, _ => 0b0 }; - let gt : bit = match r { FP_GT => 0b1, _ => 0b0 }; - let le : bit = lt | eq; - match pred { - 0x0 => eq, // EQ_OQ - 0x1 => lt, // LT_OS - 0x2 => le, // LE_OS - 0x3 => unord, // UNORD_Q - 0x4 => ~(eq), // NEQ_UQ (true for NaN) - 0x5 => ~(lt), // NLT_US (true for NaN) - 0x6 => ~(le), // NLE_US (true for NaN) - 0x7 => ~(unord), // ORD_Q - 0x8 => eq | unord, // EQ_UQ (true for NaN) - 0x9 => lt | unord, // NGE_US (true for NaN) - 0xA => le | unord, // NGT_US - 0xB => 0b0, // FALSE_OQ - 0xC => ~(eq) & ~(unord), // NEQ_OQ (false for NaN) - 0xD => ~(lt) & ~(unord), // GE_OS (false for NaN) - 0xE => gt, // GT_OS (false for NaN) - 0xF => 0b1, // TRUE_UQ - } -} - -// SSE CMPPS/CMPPD: returns full-width mask (all-ones or all-zeros per element) -val cmp_pred : forall 'n, 'n in {32, 64}. (bits('n), bits('n), bits(5)) -> bits('n) -function cmp_pred(a, b, pred) = - match('n) { - 32 => sign_extend(eval_fp_predicate(fp_compare(a, b), pred[3..0])), - 64 => sign_extend(eval_fp_predicate(fp_compare(a, b), pred[3..0])), - } - -// EVEX VCMPPS/VCMPPD: returns 1 bit per element (for kmask) -// pred[3:0] selects comparison; pred[4] only affects signaling (not modeled). -val cmp_pred5 : forall 'n, 'n in {32, 64}. (bits('n), bits('n), range(0, 31)) -> bit -function cmp_pred5(a, b, pred) = - match 'n { - 32 => eval_fp_predicate(fp_compare(a, b), to_bits(4, pred % 16)), - 64 => eval_fp_predicate(fp_compare(a, b), to_bits(4, pred % 16)), - } - -// Packed FP compare with predicate: element-wise CMPPS/CMPPD -val packed_cmp_pred : forall 'vl 'eb, 'vl in {128, 256} & 'eb in {32, 64}. - (int('eb), bits('vl), bits('vl), bits(5)) -> bits('vl) -function packed_cmp_pred(eb, a, b, pred) = { - var r : bits('vl) = zeros(); - foreach (i from 0 to ('vl / 'eb - 1)) { - let lo = i * 'eb; - r[(lo + 'eb - 1)..lo] = cmp_pred(velem('eb, a, i), velem('eb, b, i), pred) - }; - r -} - -val dispatch_2byte_sse_fp : (range(0, 255), Prefixes) -> unit -function dispatch_2byte_sse_fp(op, pfx) = { - match op { - // 0F 10: MOVUPS/MOVUPD/MOVSD/MOVSS xmm, xmm/m - 16 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - match mp { - // MOVUPS/MOVUPD xmm1, xmm2/m128 - MP_NONE => ZMM[xreg][127..0] = decode_xmm_src_u(src), - MP_66 => ZMM[xreg][127..0] = decode_xmm_src_u(src), - MP_F3 => { - // MOVSS xmm1, xmm2/m32 - match src { - XRM_reg(xi) => ZMM[xreg][31..0] = ZMM[xi][31..0], - XRM_mem(m) => ZMM[xreg][127..0] = zero_extend(v(32, m)), - } - }, - MP_F2 => { - // MOVSD xmm1, xmm2/m64 - match src { - XRM_reg(xi) => ZMM[xreg][63..0] = ZMM[xi][63..0], - XRM_mem(m) => ZMM[xreg][127..0] = zero_extend(v(64, m)), - } - }, - } - }, - // 0F 11: MOVUPS/MOVUPD/MOVSD/MOVSS xmm/m, xmm - 17 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let dest = modrm_xrm(modrm, pfx); - match mp { - // MOVUPS/MOVUPD xmm2/m128, xmm1 - MP_NONE => match dest { - XRM_reg(xi) => ZMM[xi][127..0] = read_simd(xreg), - XRM_mem(m) => write_mem(m, read_simd(128, xreg)), - }, - MP_66 => match dest { - XRM_reg(xi) => ZMM[xi][127..0] = read_simd(xreg), - XRM_mem(m) => write_mem(m, read_simd(128, xreg)), - }, - MP_F3 => { - // MOVSS m32, xmm1 - match dest { - XRM_reg(xi) => ZMM[xi][31..0] = ZMM[xreg][31..0], - XRM_mem(m) => v(m) = ZMM[xreg][31..0], - } - }, - MP_F2 => { - // MOVSD m64, xmm1 - match dest { - XRM_reg(xi) => ZMM[xi][63..0] = ZMM[xreg][63..0], - XRM_mem(m) => v(m) = ZMM[xreg][63..0], - } - }, - } - }, - // 0F 12: MOVLPS/MOVLPD/MOVSLDUP/MOVDDUP - 18 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - match mp { - MP_NONE => { - // MOVLPS xmm, m64 or MOVHLPS xmm, xmm - match src { - XRM_reg(xi) => { - let src : xmmword = read_simd(xi); - ZMM[xreg][127..0] = read_simd(128, xreg)[127..64] @ src[127..64] - }, - XRM_mem(m) => ZMM[xreg][63..0] = v(m), - } - }, - // MOVLPD xmm, m64 - MP_66 => match src { - XRM_reg(_) => raise_UD(), - XRM_mem(m) => ZMM[xreg][63..0] = v(m), - }, - MP_F3 => { - // MOVSLDUP xmm1, xmm2/m128 (SSE3) - let d : xmmword = decode_xmm_src(src); - ZMM[xreg][127..0] = d[95..64] @ d[95..64] @ d[31..0] @ d[31..0] - }, - MP_F2 => { - // MOVDDUP xmm1, xmm2/m64 (SSE3) - let lo : qword = decode_scalar_src(src); - ZMM[xreg][127..0] = lo @ lo - }, - } - }, - // 0F 13: MOVLPS/MOVLPD m64, xmm - 19 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let dest = modrm_rm(modrm, pfx); - rm_mem(64, dest) = read_simd(128, xreg)[63..0] - }, - // 0F 14: UNPCKLPS/UNPCKLPD - 20 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let src_xmm : xmmword = decode_xmm_src(src); - match mp { - MP_NONE => ZMM[xreg][127..0] = packed_unpack(32, 0, read_simd(xreg), src_xmm), - MP_66 => ZMM[xreg][127..0] = packed_unpack(64, 0, read_simd(xreg), src_xmm), - _ => raise_UD(), - } - }, - // 0F 15: UNPCKHPS/UNPCKHPD - 21 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let src_xmm : xmmword = decode_xmm_src(src); - match mp { - MP_NONE => ZMM[xreg][127..0] = packed_unpack(32, 64, read_simd(xreg), src_xmm), - MP_66 => ZMM[xreg][127..0] = packed_unpack(64, 64, read_simd(xreg), src_xmm), - _ => raise_UD(), - } - }, - // 0F 16: MOVHPS/MOVHPD/MOVSHDUP - 22 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - match mp { - MP_NONE => { - match src { - XRM_reg(xi) => { - let src : xmmword = read_simd(xi); - ZMM[xreg][127..0] = src[63..0] @ read_simd(128, xreg)[63..0] - }, - XRM_mem(m) => ZMM[xreg][127..64] = v(m), - } - }, - // MOVHPD xmm, m64 - MP_66 => match src { - XRM_reg(_) => raise_UD(), - XRM_mem(m) => ZMM[xreg][127..64] = v(m), - }, - MP_F3 => { - // MOVSHDUP xmm1, xmm2/m128 (SSE3) - let d : xmmword = decode_xmm_src(src); - ZMM[xreg][127..0] = d[127..96] @ d[127..96] @ d[63..32] @ d[63..32]; - }, - _ => raise_UD(), - } - }, - // 0F 17: MOVHPS/MOVHPD m64, xmm - 23 => { - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let dest = modrm_rm(modrm, pfx); - rm_mem(64, dest) = read_simd(128, xreg)[127..64] - }, - // 0F 28: MOVAPS/MOVAPD xmm, xmm/m128 - 40 => { - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - ZMM[xreg][127..0] = decode_xmm_src_aligned(modrm_xrm(modrm, pfx)) - }, - // 0F 29: MOVAPS/MOVAPD xmm/m128, xmm - 41 => { - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let dest = modrm_xrm(modrm, pfx); - match dest { - XRM_reg(xi) => ZMM[xi][127..0] = read_simd(xreg), - XRM_mem(m) => { check_alignment(m, 16); write_mem(m, read_simd(128, xreg)) }, - } - }, - // 0F 2A: CVTSI2SS/CVTSI2SD - 42 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_rm(modrm, pfx); - // The integer source is r/m32, or r/m64 with REX.W (SDM Vol.2A - // CVTSI2SS, CVTSI2SD); there is no 16-bit form. A 66h beside the F2h - // or F3h is "Other use of the 66H prefix", which "is reserved; such - // use may cause unpredictable behavior" (SDM Vol.2A §2.1.1, p.2-2); - // the model ignores it, as F2h and F3h take precedence over 66h for - // every legacy SIMD opcode (get_mandatory_prefix). - let rex_w = pfx.rex_w; - match mp { - // CVTSI2SS xmm, r/m32/64 (F3 prefix) - MP_F3 => ZMM[xreg][31..0] = - if rex_w then __int64_to_f32(v(64, src)) else __int32_to_f32(v(32, src)), - // CVTSI2SD xmm, r/m32/64 (F2 prefix) - MP_F2 => ZMM[xreg][63..0] = - if rex_w then __int64_to_f64(v(64, src)) else __int32_to_f64(v(32, src)), - // CVTPI2PS xmm, mm/m64 (NP) — SDM: DEST[31:0] := cvt(SRC[31:0]); DEST[63:32] := cvt(SRC[63:32]) - // High quadword unchanged. - MP_NONE => { - let mm_src : qword = match src { - RM_reg(_) => { mmx_touch(); x87_ST[unsigned(modrm[2..0])][63..0] }, - RM_mem(m) => v(m), - }; - ZMM[xreg][31..0] = __int32_to_f32(mm_src[31..0]); - ZMM[xreg][63..32] = __int32_to_f32(mm_src[63..32]) - }, - // CVTPI2PD xmm, mm/m64 (66 prefix) — SDM: full XMM write - MP_66 => { - let mm_src : qword = match src { - RM_reg(_) => { mmx_touch(); x87_ST[unsigned(modrm[2..0])][63..0] }, - RM_mem(m) => v(m), - }; - let lo : qword = __int32_to_f64(mm_src[31..0]); - let hi : qword = __int32_to_f64(mm_src[63..32]); - ZMM[xreg][127..0] = hi @ lo - }, - } - }, - // 0F 2C: CVTTSS2SI/CVTTSD2SI - 44 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let src = modrm_xrm(modrm, pfx); - match mp { - // CVTTSS2SI r, xmm/m32 (F3) - MP_F3 => { - let reg = modrm_reg(modrm, pfx); - let os = opsize(pfx); - let src_val : dword = decode_scalar_src(src); - match os { - 64 => v(reg) = __f32_to_int64_trunc(src_val), - _ => v(reg) = __f32_to_int32_trunc(src_val), - } - }, - // CVTTSD2SI r, xmm/m64 (F2) - MP_F2 => { - let reg = modrm_reg(modrm, pfx); - let os = opsize(pfx); - let src_val : qword = decode_scalar_src(src); - match os { - 64 => v(reg) = __f64_to_int64_trunc(src_val), - _ => v(reg) = __f64_to_int32_trunc(src_val), - } - }, - // CVTTPS2PI mm, xmm/m64 (NP) - MP_NONE => { - let src_val : qword = decode_scalar_src(src); - mmx_touch(); - let mm_dst : range(0, 7) = unsigned(modrm[5..3]); - x87_ST[mm_dst] = ones(16) @ (__f32_to_int32_trunc(src_val[63..32]) @ __f32_to_int32_trunc(src_val[31..0])) - }, - // CVTTPD2PI mm, xmm/m128 (66) - MP_66 => { - let src_xmm : xmmword = decode_xmm_src(src); - mmx_touch(); - let mm_dst : range(0, 7) = unsigned(modrm[5..3]); - x87_ST[mm_dst] = ones(16) @ (__f64_to_int32_trunc(src_xmm[127..64]) @ __f64_to_int32_trunc(src_xmm[63..0])) - }, - } - }, - // 0F 2D: CVTSS2SI/CVTSD2SI - 45 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let src = modrm_xrm(modrm, pfx); - match mp { - // CVTSS2SI r, xmm/m32 (F3) - MP_F3 => { - let reg = modrm_reg(modrm, pfx); - let os = opsize(pfx); - let src_val : dword = decode_scalar_src(src); - match os { - 64 => v(reg) = __f32_to_int64(src_val), - _ => v(reg) = __f32_to_int32(src_val), - } - }, - // CVTSD2SI r, xmm/m64 (F2) - MP_F2 => { - let reg = modrm_reg(modrm, pfx); - let os = opsize(pfx); - let src_val : qword = decode_scalar_src(src); - match os { - 64 => v(reg) = __f64_to_int64(src_val), - _ => v(reg) = __f64_to_int32(src_val), - } - }, - // CVTPS2PI mm, xmm/m64 (NP) - MP_NONE => { - let src_val : qword = decode_scalar_src(src); - mmx_touch(); - let mm_dst : range(0, 7) = unsigned(modrm[5..3]); - x87_ST[mm_dst] = ones(16) @ (__f32_to_int32(src_val[63..32]) @ __f32_to_int32(src_val[31..0])) - }, - // CVTPD2PI mm, xmm/m128 (66) - MP_66 => { - let src_xmm : xmmword = decode_xmm_src(src); - mmx_touch(); - let mm_dst : range(0, 7) = unsigned(modrm[5..3]); - x87_ST[mm_dst] = ones(16) @ (__f64_to_int32(src_xmm[127..64]) @ __f64_to_int32(src_xmm[63..0])) - }, - } - }, - // 0F 2E: UCOMISS/UCOMISD - 46 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - if mp == MP_NONE - then set_eflags_fp_compare(read_simd(128, xreg)[31..0] : dword, decode_scalar_src(src)) - else set_eflags_fp_compare(read_simd(128, xreg)[63..0] : qword, decode_scalar_src(src)) - }, - // 0F 2F: COMISS/COMISD - 47 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - if mp == MP_NONE - then set_eflags_fp_compare(read_simd(128, xreg)[31..0] : dword, decode_scalar_src(src)) - else set_eflags_fp_compare(read_simd(128, xreg)[63..0] : qword, decode_scalar_src(src)) - }, - // 0F 50: MOVMSKPS/MOVMSKPD - 80 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let reg = modrm_reg(modrm, pfx); - let xi = xrm_reg(modrm_xrm(modrm, pfx)); - let src_xmm : xmmword = read_simd(xi); - match mp { - MP_NONE => { - let mask : bits(4) = src_xmm[127] @ src_xmm[95] @ src_xmm[63] @ src_xmm[31]; - v(reg) = zero_extend(32, mask) - }, - MP_66 => { - let mask : bits(2) = src_xmm[127] @ src_xmm[63]; - v(reg) = zero_extend(32, mask) - }, - _ => raise_UD(), - } - }, - // 0F 51-5F: SSE/SSE2 scalar/packed arithmetic - // These follow a pattern based on mandatory prefix: - // NONE=PS, 66=PD, F3=SS, F2=SD - op if 81 <= op & op <= 95 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let arith_op : range(0, 15) = op - 80; - // CVTPS2PD (0F 5A, NP) reads xmm/m64, not xmm/m128 - let src_xmm : xmmword = if arith_op == 10 & mp == MP_NONE then - zero_extend(decode_xmm_partial_src(64, src)) - else - decode_sse_fp_src(src, mp); - match arith_op { - // 0F 51: SQRT - 1 => sse_exec_fp_unop(PU_FSqrt, xreg, src_xmm, mp), - // 0F 54: ANDPS/ANDPD - 4 => ZMM[xreg][127..0] = read_simd(xreg) & src_xmm, - // 0F 55: ANDNPS/ANDNPD - 5 => ZMM[xreg][127..0] = ~(read_simd(xreg)) & src_xmm, - // 0F 56: ORPS/ORPD - 6 => ZMM[xreg][127..0] = read_simd(xreg) | src_xmm, - // 0F 57: XORPS/XORPD - 7 => ZMM[xreg][127..0] = read_simd(xreg) ^ src_xmm, - // 0F 58: ADD - 8 => sse_exec_fp_binop(PB_FAdd, xreg, src_xmm, mp), - // 0F 59: MUL - 9 => sse_exec_fp_binop(PB_FMul, xreg, src_xmm, mp), - // 0F 5A: CVTPS2PD/CVTPD2PS/CVTSS2SD/CVTSD2SS - 10 => { - match mp { - // CVTPS2PD: reads xmm/m64 (already decoded above) - MP_NONE => { - let r : xmmword = __f32_to_f64(src_xmm[63..32]) @ __f32_to_f64(src_xmm[31..0]); - ZMM[xreg][127..0] = r - }, - // CVTPD2PS: reads xmm/m128 - MP_66 => { - let r : xmmword = zeros(64) @ __f64_to_f32(src_xmm[127..64]) @ __f64_to_f32(src_xmm[63..0]); - ZMM[xreg][127..0] = r - }, - // CVTSS2SD: reads xmm/m32 - MP_F3 => ZMM[xreg][63..0] = __f32_to_f64(src_xmm[31..0]), - // CVTSD2SS: reads xmm/m64 - MP_F2 => ZMM[xreg][31..0] = __f64_to_f32(src_xmm[63..0]), - } - }, - // 0F 5B: CVTDQ2PS/CVTPS2DQ/CVTTPS2DQ — all packed (F3 is NOT scalar) - 11 => { - let s : xmmword = if mp == MP_F3 then decode_xmm_src(src) else src_xmm; - match mp { - MP_NONE => ZMM[xreg][127..0] = packed_unop(PU_CvtDQ2PS, 32, s), - MP_66 => ZMM[xreg][127..0] = packed_unop(PU_CvtPS2DQ, 32, s), - MP_F3 => ZMM[xreg][127..0] = packed_unop(PU_CvtTPS2DQ, 32, s), - _ => raise_UD(), - } - }, - // 0F 5C: SUB - 12 => sse_exec_fp_binop(PB_FSub, xreg, src_xmm, mp), - // 0F 5D: MIN - 13 => sse_exec_fp_binop(PB_FMin, xreg, src_xmm, mp), - // 0F 5E: DIV - 14 => sse_exec_fp_binop(PB_FDiv, xreg, src_xmm, mp), - // 0F 5F: MAX - 15 => sse_exec_fp_binop(PB_FMax, xreg, src_xmm, mp), - // 0F 52: RSQRTPS/RSQRTSS - 2 => match mp { - MP_NONE => ZMM[xreg][127..0] = packed_unop(PU_FRsqrt, 32, src_xmm), - MP_F3 => ZMM[xreg][31..0] = fp_rsqrt(src_xmm[31..0]), - _ => raise_UD(), - }, - // 0F 53: RCPPS/RCPSS - 3 => match mp { - MP_NONE => ZMM[xreg][127..0] = packed_unop(PU_FRcp, 32, src_xmm), - MP_F3 => ZMM[xreg][31..0] = fp_rcp(src_xmm[31..0]), - _ => raise_UD(), - }, - _ => raise_UD(), - } - }, - // 0F C6: SHUFPS/SHUFPD xmm, xmm/m128, imm8 - 198 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let imm = fetch(1); - // SDM Vol.2A §2.2.1.6: RIP-relative addresses use the next - // instruction's RIP, including this trailing immediate byte. - let src_xmm : xmmword = decode_xmm_src(src); - match mp { - MP_NONE => { - let d : xmmword = read_simd(xreg); - let d0 : dword = velem(32, d, imm[1..0]); - let d1 : dword = velem(32, d, imm[3..2]); - let d2 : dword = velem(32, src_xmm, imm[5..4]); - let d3 : dword = velem(32, src_xmm, imm[7..6]); - ZMM[xreg][127..0] = d3 @ d2 @ d1 @ d0 - }, - MP_66 => { - let d : xmmword = read_simd(xreg); - let low : qword = blend(d[63..0], d[127..64], imm[0]); - let high : qword = blend(src_xmm[63..0], src_xmm[127..64], imm[1]); - ZMM[xreg][127..0] = high @ low - }, - _ => raise_UD(), - } - }, - // 0F D6: MOVQ xmm/m64, xmm (66 prefix) - 214 => { - let mp = get_mandatory_prefix(pfx); - match mp { - // 66 0F D6: MOVQ xmm1/m64, xmm2 — store low 64 bits - MP_66 => { - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let dest = modrm_xrm(modrm, pfx); - let data : xmmword = read_simd(xreg); - match dest { - XRM_reg(xi) => ZMM[xi][127..0] = zero_extend(data[63..0]), - XRM_mem(m) => v(m) = data[63..0], - } - }, - // F2 0F D6: MOVDQ2Q mm, xmm — SDM: DEST := SRC[63:0] - MP_F2 => { - let modrm = fetch(1); - let xi = xrm_reg(modrm_xrm(modrm, pfx)); - let mm_dst : range(0, 7) = unsigned(modrm[5..3]); - mmx_touch(); - x87_ST[mm_dst] = ones(16) @ (read_simd(128, xi)[63..0]) - }, - // F3 0F D6: MOVQ2DQ xmm, mm — SDM: DEST[63:0] := SRC; DEST[127:64] := 0, - // with the transition to MMX operation (TOP := 0, all tags valid) - MP_F3 => { - let modrm = fetch(1); - let _ = modrm_rm(modrm, pfx); - let dst_xmm = modrm_xreg(modrm, pfx); - let mm_src : range(0, 7) = unsigned(modrm[2..0]); - mmx_touch(); - ZMM[dst_xmm][127..0] = zero_extend(x87_ST[mm_src][63..0]) - }, - _ => raise_UD(), - } - }, - // 0F E6: CVTDQ2PD/CVTPD2DQ/CVTTPD2DQ - 230 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - match mp { - // CVTDQ2PD: reads only 64 bits (two dwords), no alignment required - MP_F3 => { - let lo64 : qword = decode_xmm_partial_src(64, src); - let r : xmmword = __int32_to_f64(lo64[63..32]) @ __int32_to_f64(lo64[31..0]); - ZMM[xreg][127..0] = r - }, - // CVTPD2DQ: reads 128 bits, 16-byte alignment required - MP_F2 => { - let src_xmm : xmmword = decode_xmm_src(src); - let r : xmmword = zeros(64) @ __f64_to_int32(src_xmm[127..64]) @ __f64_to_int32(src_xmm[63..0]); - ZMM[xreg][127..0] = r - }, - // CVTTPD2DQ: reads 128 bits, 16-byte alignment required - MP_66 => { - let src_xmm : xmmword = decode_xmm_src(src); - let lo : dword = __f64_to_int32_trunc(src_xmm[63..0]); - let hi : dword = __f64_to_int32_trunc(src_xmm[127..64]); - let r : xmmword = zeros(64) @ hi @ lo; - ZMM[xreg][127..0] = r - }, - _ => raise_UD(), - } - }, - // 0F 2B: MOVNTPS/MOVNTPD m128, xmm (requires 16-byte alignment); on AMD - // also MOVNTSS m32, xmm (F3) and MOVNTSD m64, xmm (F2), the low element - // with no alignment requirement (AMD APM Vol.4 MOVNTSS, MOVNTSD) - 43 => { - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let dest = modrm_rm(modrm, pfx); - match get_mandatory_prefix(pfx) { - MP_F3 => rm_mem(dest) = read_simd(128, xreg)[31..0], - MP_F2 => rm_mem(dest) = read_simd(128, xreg)[63..0], - _ => { - check_alignment(dest, 16); - rm_mem(dest) = read_simd(128, xreg) - }, - } - }, - // 0F 7C: HADDPS/HADDPD (SSE3) - 124 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let src_xmm : xmmword = decode_xmm_src(src); - match mp { - MP_F2 => ZMM[xreg][127..0] = packed_binop(PB_HorizFAddS, 128, read_simd(xreg), src_xmm), - MP_66 => ZMM[xreg][127..0] = packed_binop(PB_HorizFAddD, 128, read_simd(xreg), src_xmm), - _ => raise_UD(), - } - }, - // 0F 7D: HSUBPS/HSUBPD (SSE3) - 125 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let src_xmm : xmmword = decode_xmm_src(src); - match mp { - MP_F2 => ZMM[xreg][127..0] = packed_binop(PB_HorizFSubS, 128, read_simd(xreg), src_xmm), - MP_66 => ZMM[xreg][127..0] = packed_binop(PB_HorizFSubD, 128, read_simd(xreg), src_xmm), - _ => raise_UD(), - } - }, - // 0F C2: CMPPS/CMPPD/CMPSS/CMPSD xmm, xmm/m, imm8 - 194 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let imm = fetch(1); - let src_xmm : xmmword = decode_sse_fp_src(src, mp); - let a : xmmword = read_simd(xreg); - let pred : bits(5) = zero_extend(imm[2..0]); - match mp { - MP_NONE => ZMM[xreg][127..0] = packed_cmp_pred(32, a, src_xmm, pred), - MP_66 => ZMM[xreg][127..0] = packed_cmp_pred(64, a, src_xmm, pred), - MP_F3 => ZMM[xreg][127..0] = a[127..32] @ cmp_pred(a[31..0], src_xmm[31..0], pred), - MP_F2 => ZMM[xreg][127..0] = a[127..64] @ cmp_pred(a[63..0], src_xmm[63..0], pred), - } - }, - // 0F D0: ADDSUBPS/ADDSUBPD (SSE3) - 208 => { - let mp = get_mandatory_prefix(pfx); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let src_xmm : xmmword = decode_xmm_src(src); - match mp { - MP_F2 => ZMM[xreg][127..0] = packed_binop(PB_FAddSubS, 128, read_simd(xreg), src_xmm), - MP_66 => ZMM[xreg][127..0] = packed_binop(PB_FAddSubD, 128, read_simd(xreg), src_xmm), - _ => raise_UD(), - } - }, - _ => raise_UD(), - } -} - -// INSERTPS — Insert Scalar Single-Precision FP Value (SSE4.1) -val exec_insertps : (simd_idx, xmmword, byte) -> unit -function exec_insertps(dst, src, imm8) = { - let a : xmmword = read_simd(dst); - let b : xmmword = src; - // Select source float using imm8[7:6] - let src_sel : range(0, 3) = unsigned(imm8[7..6]); - let src_float : dword = b[(src_sel * 32 + 31) .. (src_sel * 32)]; - // Insert at destination position using imm8[5:4] - let sel = imm8[5..4]; - let m0 : dword = sign_extend(~(sel[1] | sel[0])); - let x1 : bits(2) = sel ^ 0b01; - let m1 : dword = sign_extend(~(x1[1] | x1[0])); - let x2 : bits(2) = sel ^ 0b10; - let m2 : dword = sign_extend(~(x2[1] | x2[0])); - let x3 : bits(2) = sel ^ 0b11; - let m3 : dword = sign_extend(~(x3[1] | x3[0])); - let t0 : dword = (src_float & m0) | (a[31..0] & ~(m0)); - let t1 : dword = (src_float & m1) | (a[63..32] & ~(m1)); - let t2 : dword = (src_float & m2) | (a[95..64] & ~(m2)); - let t3 : dword = (src_float & m3) | (a[127..96] & ~(m3)); - // Zero lanes indicated by imm8[3:0] (branchless) - ZMM[dst][127..0] = (t3 & sign_extend(~(imm8[3]))) @ - (t2 & sign_extend(~(imm8[2]))) @ - (t1 & sign_extend(~(imm8[1]))) @ - (t0 & sign_extend(~(imm8[0]))) -} - -// ========================================================================= -// 3-Byte Opcode Map: SSE Floating-Point Operations -// ========================================================================= - -// 0F 38 xx — SSE FP operations (BLENDVPS, BLENDVPD) -val dispatch_3byte_38_sse_fp : (byte, Prefixes) -> unit -function dispatch_3byte_38_sse_fp(opcode, pfx) = { - let op : range(0, 255) = unsigned(opcode); - let mp = get_mandatory_prefix(pfx); - if mp != MP_66 then raise_UD(); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - let src_xmm : xmmword = decode_xmm_src(src); - match op { - // BLENDVPS xmm1, xmm2/m128, - 20 => { - let a : xmmword = read_simd(xreg); - let m : xmmword = read_simd(0); - var r : xmmword = zeros(); - foreach (i from 0 to 3) { - let lo = i * 32; - r[(lo + 31)..lo] = blend(velem(32, a, i), velem(32, src_xmm, i), m[lo + 31]) - }; - ZMM[xreg][127..0] = r - }, - // BLENDVPD xmm1, xmm2/m128, - 21 => { - let a : xmmword = read_simd(xreg); - let m : xmmword = read_simd(0); - var r : xmmword = zeros(); - foreach (i from 0 to 1) { - let lo = i * 64; - r[(lo + 63)..lo] = blend(velem(64, a, i), velem(64, src_xmm, i), m[lo + 63]) - }; - ZMM[xreg][127..0] = r - }, - _ => raise_UD(), - } -} - -// 0F 3A xx — SSE FP operations (ROUND*, BLEND*, DP*, EXTRACTPS, INSERTPS) -val dispatch_3byte_3a_sse_fp : (byte, Prefixes) -> unit -function dispatch_3byte_3a_sse_fp(opcode, pfx) = { - let op : range(0, 255) = unsigned(opcode); - let mp = get_mandatory_prefix(pfx); - if mp != MP_66 then raise_UD(); - let modrm = fetch(1); - let xreg = modrm_xreg(modrm, pfx); - let src = modrm_xrm(modrm, pfx); - // Every 0F 3A instruction ends with an imm8. Fetch it before any operand - // is accessed: a RIP-relative operand is relative to the end of the - // instruction (see fixup_addr). - let imm = fetch(1); - match op { - // SSE4.1 — ROUNDPS xmm1, xmm2/m128, imm8 - 8 => { - let src_xmm = decode_xmm_src(src); - var r : xmmword = zeros(); - foreach (i from 0 to 3) { - let lo = i * 32; - r[(lo + 31)..lo] = fp_round(velem(32, src_xmm, i), imm) - }; - ZMM[xreg][127..0] = r - }, - // ROUNDPD xmm1, xmm2/m128, imm8 - 9 => { - let src_xmm = decode_xmm_src(src); - var r : xmmword = zeros(); - foreach (i from 0 to 1) { - let lo = i * 64; - r[(lo + 63)..lo] = fp_round(velem(64, src_xmm, i), imm) - }; - ZMM[xreg][127..0] = r - }, - // ROUNDSS: reads 32 bits from memory, no alignment required - 10 => { - let src32 : dword = decode_scalar_src(src); - let a : xmmword = read_simd(xreg); - let lo : dword = fp_round(src32, imm); - ZMM[xreg][127..0] = a[127..32] @ lo - }, - // ROUNDSD: reads 64 bits from memory, no alignment required - 11 => { - let src64 : qword = decode_scalar_src(src); - let a : xmmword = read_simd(xreg); - let lo : qword = fp_round(src64, imm); - ZMM[xreg][127..0] = a[127..64] @ lo - }, - - // SSE4.1 — BLENDPS xmm1, xmm2/m128, imm8 - 12 => { - let src_xmm = decode_xmm_src(src); - let a : xmmword = read_simd(xreg); - var r : xmmword = zeros(); - foreach (i from 0 to 3) { - let lo = i * 32; - r[(lo + 31)..lo] = blend(velem(32, a, i), velem(32, src_xmm, i), imm[i]) - }; - ZMM[xreg][127..0] = r - }, - // BLENDPD xmm1, xmm2/m128, imm8 - 13 => { - let src_xmm = decode_xmm_src(src); - let a : xmmword = read_simd(xreg); - var r : xmmword = zeros(); - foreach (i from 0 to 1) { - let lo = i * 64; - r[(lo + 63)..lo] = blend(velem(64, a, i), velem(64, src_xmm, i), imm[i]) - }; - ZMM[xreg][127..0] = r - }, - - // PEXTRW r/m16, xmm, imm8 (SSE4.1, 66 0F 3A 15) - // SDM: ModRM:reg = source XMM, ModRM:r/m = dest (reg: zero-extend to 32, mem: 16 bits) - 21 => { - let sel : range(0, 7) = unsigned(imm[2..0]); - let w : word = velem(16, ZMM[xreg], sel); - match src { - XRM_reg(_) => v(modrm_rm_reg(modrm, pfx)) = zero_extend(32, w), - XRM_mem(m) => v(m) = w, - } - }, - - // EXTRACTPS r/m32, xmm, imm8 - 23 => { - let data = velem(32, ZMM[xreg], imm[1..0]); - match src { - XRM_reg(_) => v(modrm_rm_reg(modrm, pfx)) = data, - XRM_mem(m) => v(m) = data, - } - }, - - // INSERTPS xmm, xmm/m32, imm8 - // Memory form: reads 32 bits, imm8[7:6] forced to 0 (count_s ignored). - 33 => { - match src { - XRM_reg(xi) => exec_insertps(xreg, read_simd(xi), imm), - XRM_mem(m) => { - let src_val : xmmword = zero_extend(v(32, m)); - exec_insertps(xreg, src_val, imm & 0x3F) - }, - } - }, - - // SSE4.1 — dot product - 64 => { - let src_xmm = decode_xmm_src(src); - let a : xmmword = read_simd(xreg); - let temp0 : dword = fp_mul(a[31..0], src_xmm[31..0]) & sign_extend(imm[4]); - let temp1 : dword = fp_mul(a[63..32], src_xmm[63..32]) & sign_extend(imm[5]); - let temp2 : dword = fp_mul(a[95..64], src_xmm[95..64]) & sign_extend(imm[6]); - let temp3 : dword = fp_mul(a[127..96], src_xmm[127..96]) & sign_extend(imm[7]); - let sum01 : dword = fp_add(temp0, temp1); - let sum23 : dword = fp_add(temp2, temp3); - let sum : dword = fp_add(sum01, sum23); - ZMM[xreg][127..0] = - (sum & sign_extend(imm[3])) @ - (sum & sign_extend(imm[2])) @ - (sum & sign_extend(imm[1])) @ - (sum & sign_extend(imm[0])) - }, - 65 => { - let src_xmm = decode_xmm_src(src); - let a : xmmword = read_simd(xreg); - let temp0 : qword = fp_mul(a[63..0], src_xmm[63..0]) & sign_extend(imm[4]); - let temp1 : qword = fp_mul(a[127..64], src_xmm[127..64]) & sign_extend(imm[5]); - let sum : qword = fp_add(temp0, temp1); - ZMM[xreg][127..0] = - (sum & sign_extend(imm[1])) @ - (sum & sign_extend(imm[0])) - }, - - _ => raise_UD(), - } -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail deleted file mode 100644 index f83a79f2f..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/mem.sail +++ /dev/null @@ -1,755 +0,0 @@ -// x86-64 — Memory Interface -// -// Two-layer memory model following the sail-riscv pattern: -// read_mem/write_mem (virtual) → translate_addr → phys_read/phys_write -// -// When paging is disabled (CR0.PG=0, user-mode emulation), translate_addr -// returns the address unchanged, so all existing instruction code works -// without modification. -// -// Physical memory primitives (__read_mem, __write_mem, phys_read, phys_write) -// and the address translation function (translate_addr) are defined in -// paging.sail, which is compiled before this file. - -// Forward declarations so that the read_mem/write_mem overloads are -// available to all functions in this file (including stack operations). -// Size parameter 'n is in bits. -val read_mem_linear : forall 'n, 'n > 0. (implicit('n), qword, PTAccess) -> bits('n) -val read_mem_data : forall 'n, 'n > 0. (implicit('n), qword) -> bits('n) -val read_mem_implicit : forall 'n, 'n > 0. (implicit('n), qword) -> bits('n) -val write_mem_linear : forall 'n, 'n > 0. (implicit('n), qword, bits('n)) -> unit -val read_mem_ref : forall 'n, 'n > 0. (implicit('n), MemRef) -> bits('n) -val write_mem_ref : forall 'n, 'n > 0. (implicit('n), MemRef, bits('n)) -> unit - -overload read_mem = {read_mem_data, read_mem_ref} -overload write_mem = {write_mem_linear, write_mem_ref} - -// Records that an access matches breakpoint n: a hit in pending_dbp when -// Ln or Gn enables it, otherwise a match in open_dbp. LENn = 10b is eight -// bytes in long mode: "Breakpoint conditions for 8-byte memory read/writes -// are supported in all modes" (SDM Vol.3B §20.2.6 p.20-7), "8 byte ... -// (Long mode only; otherwise undefined.)" (APM Vol.2 §13.1.1.4 p.397). -// Outside long mode such a breakpoint matches only within the eight bytes, -// and whether it hits is undefined. -val note_breakpoint_match : (range(0, 3), bool) -> unit -function note_breakpoint_match(n, len8) = { - let long_mode : bool = cur_mode == LongMode | cur_mode == CompatibilityMode; - if DR7[2 * n] == bitone | DR7[2 * n + 1] == bitone then { - if ~(len8) | long_mode | (undefined : bool) then pending_dbp[n] = bitone - } else open_dbp[n] = bitone -} - -// Data breakpoints (SDM Vol.3B §20.2.5, §20.3.1.2): an access matches DRn -// when R/Wn is 01 (writes) or 11 (reads and writes) and any byte of the -// access lies in the LENn-byte range at DRn, whose low address bits LENn -// masks (1, 2, 8 and 4 bytes for 00, 01, 10 and 11). Instruction fetches -// and the processor's own descriptor-table reads do not count. Hits -// accumulate in pending_dbp for the trap that step() raises after the -// instruction. -val note_data_access : (qword, int, bool) -> unit -function note_data_access(lin, nbytes, is_write) = { - foreach (n from 0 to 3) { - let rw : bits(2) = DR7[(17 + 4 * n) .. (16 + 4 * n)]; - let len_field : bits(2) = DR7[(19 + 4 * n) .. (18 + 4 * n)]; - let len : range(1, 8) = match len_field { - 0b00 => 1, 0b01 => 2, 0b10 => 8, _ => 4 - }; - let dr : qword = match n { 0 => DR0, 1 => DR1, 2 => DR2, _ => DR3 }; - let base : int = unsigned(dr & ~(to_bits(64, len - 1))); - let applies : bool = (rw == 0b01 & is_write) | rw == 0b11; - if applies & unsigned(lin) < base + len & base < unsigned(lin) + nbytes then - note_breakpoint_match(n, len_field == 0b10) - } -} - -// I/O breakpoints (SDM Vol.3B §20.2.4, §20.2.5): with CR4.DE set, R/Wn = 10 -// makes DRn an I/O breakpoint; the port address is zero-extended and -// compared with the LENn-byte range at DRn like a data breakpoint. Hits -// join pending_dbp. Without CR4.DE the encoding is undefined and ignored. -val note_io_access : (word, int) -> unit -function note_io_access(port, nbytes) = { - if CR4[3] == bitone then { - foreach (n from 0 to 3) { - let rw : bits(2) = DR7[(17 + 4 * n) .. (16 + 4 * n)]; - let len_field : bits(2) = DR7[(19 + 4 * n) .. (18 + 4 * n)]; - let len : range(1, 8) = match len_field { - 0b00 => 1, 0b01 => 2, 0b10 => 8, _ => 4 - }; - let dr : qword = match n { 0 => DR0, 1 => DR1, 2 => DR2, _ => DR3 }; - let base : int = unsigned(dr & ~(to_bits(64, len - 1))); - let p : int = unsigned(port); - if rw == 0b10 & p < base + len & base < p + nbytes then - note_breakpoint_match(n, len_field == 0b10) - } - } -} - -// Validate every page before a crossing access enters the external byte-copy -// helper. Keep faulting translations in Sail: an external callback into -// translate_addr cannot propagate a Sail exception through every backend's -// foreign-call ABI. In particular, an instruction fetch must not consume -// bytes from a failed translation. SDM Vol.3A §§7.5–7.6 and Interrupt 14: -// #PF preserves the faulting instruction for restart; CR2 identifies its -// failing linear address. Checking all pages also avoids partial MOV stores. -val check_crossing_pages : (qword, int, PTAccess) -> unit -function check_crossing_pages(addr, nbytes, access) = { - let _ = translate_addr(addr, access); - // Walk the following page starts while they lie inside the access. - // (Bitvector arithmetic: the official type checker cannot bound an - // integer offset converted with to_bits here.) - var page : qword = (addr & 0xFFFFFFFFFFFFF000) + 0x0000000000001000; - while unsigned(page - addr) < nbytes do { - let _ = translate_addr(page, access); - page = page + 0x0000000000001000 - } -} - -// Read 'n bits from memory at the given virtual address. -// Goes through address translation when paging is enabled. -// If the access crosses a 4KB page boundary, each byte is translated -// separately to handle non-contiguous physical pages. -function read_mem_linear(n, addr, access) = { - if access == PT_Read then note_data_access(addr, n / 8, false); - let page_offset = unsigned(addr & 0x0000000000000FFF); - if page_offset + n / 8 <= 4096 then { - let paddr = translate_addr(addr, access); - phys_read(n, paddr) - } else { - check_crossing_pages(addr, n / 8, access); - __mem_read_crossing(addr, n, access) - } -} - -// Data-read wrapper: read_mem_linear with PT_Read access. -function read_mem_data(n, addr) = read_mem_linear(addr, PT_Read) - -// Implicit-read wrapper for descriptor-table accesses (GDT/LDT/IDT/TSS). -// SDM Vol.3A §4.6: these reads the CPU itself performs always execute -// at supervisor regardless of the current CPL and bypass the U/S page -// check, so user-mode instructions (e.g. `MOV GS, sel` at CPL=3) can -// load a descriptor out of a kernel-mapped GDT without a #PF. -function read_mem_implicit(n, addr) = read_mem_linear(addr, PT_Implicit) - -// Write 'n bits to memory at the given virtual address. -// Same page-crossing logic as mem_read. -function write_mem_linear(n, addr, data) = { - note_data_access(addr, n / 8, true); - let page_offset = unsigned(addr & 0x0000000000000FFF); - if page_offset + n / 8 <= 4096 then { - let paddr = translate_addr(addr, PT_Write); - phys_write(n, paddr, data) - } else { - check_crossing_pages(addr, n / 8, PT_Write); - __mem_write_crossing(addr, n, data) - } -} - -// Stack operations. -// In long mode, uses RSP directly (SS base is 0). -// In non-long mode, linear address = SS base + ESP/SP (SDM Vol.3A §3.4). -// Stack pointer width depends on SS.B: if SS.B=1 then ESP (32-bit), -// if SS.B=0 then SP (16-bit). In long mode, always RSP (64-bit). - -// Stack address size: 64 in long mode, 32 if SS.B=1, 16 if SS.B=0. -val stack_addr_size : unit -> {16, 32, 64} -function stack_addr_size() = - if cur_mode == LongMode then 64 - else if SegCache[SS].seg_db == 0b1 then 32 - else 16 - -// Stack push helper: decrement SP by the value's byte width, write -// the value at the new SP, then commit the SP update — all as a -// single logical operation. Because SP is written only after the -// store succeeds, a fault during write_mem leaves SP unchanged. -// -// In non-64-bit modes with SS.B=0, SP is 16-bit and wraps at 0xFFFF. -// Without wrapping, SP=2 minus 4 would produce linear address SS.base-2, -// which is below the segment — wrong. It should wrap to SS.base+0xFFFE. -val push : forall 'n, 8 <= 'n & 'n <= 512. (implicit('n), bits('n)) -> unit -val check_seg_limit : (segreg_idx, qword, int) -> unit -function push(n, v) = { - let sas = stack_addr_size(); - let new_sp = v(sas, RSP) - n / 8; - if cur_mode == Virtual8086Mode then check_seg_limit(SS, zero_extend(new_sp), n / 8); - write_mem(get_seg_base(SS) + zero_extend(new_sp), v); - v(RSP) = new_sp -} - -// Stack pop helper: read 'n bits from SP, then advance SP — again -// as a single logical operation. -val pop : forall 'n, 8 <= 'n & 'n <= 512. (implicit('n)) -> bits('n) -function pop(n) = { - let sas = stack_addr_size(); - let sp = v(sas, RSP); - if cur_mode == Virtual8086Mode then check_seg_limit(SS, zero_extend(sp), n / 8); - let x : bits('n) = read_mem(get_seg_base(SS) + zero_extend(sp)); - v(RSP) = sp + n / 8; - x -} - -// PUSH of a segment register: "if the operand size is 64-bits, a -// zero-extended value is pushed on the stack; if the operand size is -// 32-bits, either a zero-extended value is pushed on the stack or the -// segment selector is written on the stack using a 16-bit move", which -// leaves "the upper portion of the stack location unmodified" (SDM Vol.2B -// PUSH p.4-522). The APM says only that the operand size "determines the -// number of bytes pushed" (Vol.3 PUSH). So with a 32-bit operand size the -// upper two bytes of the slot are undefined. -val push_segreg : ({16, 32, 64}, segreg_idx) -> unit -function push_segreg(os, idx) = { - let sel = read_segreg(idx); - match os { - 16 => push(16, sel), - 32 => push(32, (undefined : word) @ sel), - 64 => push(64, zero_extend(sel)), - } -} - -// ========================================================================= -// Segment register loading -// ========================================================================= - -// The TI bit selects the cached LDT or GDT (SDM Vol.3A sections 3.4.2, -// 3.5.1; LLDT caches the LDT descriptor, not its constituent descriptors). -val descriptor_address : word -> qword -function descriptor_address(sel) = - (if sel[2] == 0b1 then LDTR_base else GDTR_base) + zero_extend(sel & 0xFFF8) - -val descriptor_in_bounds : word -> bool -function descriptor_in_bounds(sel) = { - let limit : dword = if sel[2] == 0b1 then LDTR_limit else zero_extend(GDTR_limit); - (sel[2] == 0b0 | LDTR_valid) & unsigned(sel & 0xFFF8) + 7 <= unsigned(limit) -} - -// Load a segment register with a selector, updating both the visible -// selector and the hidden descriptor cache (SDM Vol.3A §3.4.5). -// In real mode: base = selector << 4; limit and attributes are NOT changed. -// This preserves "unreal mode" / "big real mode" behavior where a segment -// retains its large limit from a prior protected-mode descriptor load. -// (SDM Vol.3A §3.4.5: "Every segment register has a 'visible' part and -// a 'hidden' part... in real-address mode, only the base is updated.") -// In protected/compat mode: read 8-byte descriptor from GDT/LDT. -// In long mode: just store the selector (FS/GS base set via MSR). -// Virtual-8086 segment loads ignore descriptor tables, including selectors -// whose low bits look like an RPL or TI. All six caches describe writable -// 64-KByte segments at selector * 16 with DPL 3 (SDM Vol.3B §23.2). -val load_vm86_segment : (segreg_idx, word) -> unit -function load_vm86_segment(idx, selector) = { - write_segreg(idx, selector); - SegCache[idx] = {default_seg_desc_cache() with - seg_base = zero_extend(selector) << 4, seg_dpl = 3} -} - -// SDM Vol.3A 3.4.5.1: every load of a code/data selector sets A in -// its descriptor. This is an implicit supervisor write, subject to WP; -// do it before committing the visible selector or hidden cache. -val access_segment_descriptor : (word, SegDescCache) -> SegDescCache -function access_segment_descriptor(selector, desc) = { - if selector[15..2] != zeros() & desc.seg_s == 0b1 & desc.seg_type[0] == 0b0 then { - let addr = descriptor_address(selector) + 5; - let access_byte : byte = read_mem_implicit(addr); - let paddr = translate_addr(addr, PT_ImplicitWrite); - phys_write(paddr, access_byte | 0x01); - {desc with seg_type = desc.seg_type | 0x1} - } else desc -} - -val load_segment_register : (segreg_idx, word) -> unit -function load_segment_register(idx, selector) = { - // Do memory reads (GDT lookup) before writing the segment register, - // so that a fault during the GDT read leaves the segment unchanged. - match cur_mode { - Virtual8086Mode => load_vm86_segment(idx, selector), - RealMode => { - write_segreg(idx, selector); - SegCache[idx].seg_base = zero_extend(selector) << 4 - }, - _ => { - // SDM §3.4.4: In all modes (including 64-bit), segment loads read the - // GDT/LDT and populate the hidden descriptor cache. For DS/ES/SS in - // 64-bit mode, the cached values are ignored during address calculation - // (handled by get_seg_base). For FS/GS, the 32-bit base is loaded - // (upper bits cleared); WRMSR can then set the full 64-bit base. - if selector[2] == 0b1 & ~(LDTR_valid) then - throw Fault(EXN_GP, zero_extend(selector & 0xFFFC)); - let desc_addr = descriptor_address(selector); - // Implicit supervisor access: the CPU's own GDT/LDT reads bypass - // U/S so a CPL=3 `MOV GS, sel` can load a descriptor out of a - // kernel-mapped GDT. - let desc_lo : dword = read_mem_implicit(desc_addr); - let desc_hi : dword = read_mem_implicit(desc_addr + 4); - let desc = access_segment_descriptor(selector, parse_seg_descriptor(desc_lo, desc_hi)); - write_segreg(idx, selector); - SegCache[idx] = desc - }, - } -} - -// Error code of a fault attributed to a segment selector (SDM Vol.3A §7.13, -// Figure 7-7): the selector's index and TI bit; bits 1:0 are the IDT and -// EXT flags, both clear for a selector referenced by an instruction. -val selector_error_code : word -> dword -function selector_error_code(selector) = zero_extend(selector & 0xFFFC) - -// ========================================================================= -// Segment limit checking (SDM Vol.3A §6.3) -// ========================================================================= - -// Check that an access at the given offset with the given size is within -// the segment limit. Raises #GP(0) for non-SS segments, #SS(0) for SS. -// Only checks in non-long mode; 64-bit mode disables limit checking for -// CS/DS/ES/SS (SDM Vol.3A §6.3.1). -// For expand-up segments: offset + size - 1 <= effective_limit. -// For expand-down data segments: limit < offset, and the last byte must -// not exceed FFFFH (B=0) or FFFFFFFFH (B=1), per SDM Vol.3A section 6.3. -function check_seg_limit(seg, offset, access_size) = { - if cur_mode != LongMode then { - let desc = SegCache[seg]; - let limit : dword = desc.seg_limit; - let expand_down = desc.seg_s == 0b1 & desc.seg_type[3..2] == 0b01; - let last = unsigned(offset) + access_size - 1; - // Written with a plain boolean variable and an integer bound: the - // official type checker cannot unify the refinement types of the - // two branches otherwise, and 0xFFFFFFFF/0xFFFF differ in width. - var invalid : bool = false; - if expand_down then { - let upper : int = if desc.seg_db == 0b1 then 4294967295 else 65535; - invalid = unsigned(offset) <= unsigned(limit) | last > upper - } else { - invalid = last > unsigned(limit) - }; - if invalid then { - if seg == SS then throw Fault(EXN_SS, 0x00000000) - else throw Fault(EXN_GP, 0x00000000) - } - } -} - -// ========================================================================= -// Segment-aware memory access (SDM Vol.3A §3.4) -// -// Translates a logical address (segment, offset) to a linear address: -// 1. Check offset against segment limit (§6.3) -// 2. Linear address = segment base + offset -// Then passes the linear address through paging (translate_addr). -// ========================================================================= - -// Translate a logical (segment, offset) pair to a linear address, -// performing segment limit checking with the given access size. -// Also applies the RIP-relative fixup if pending. -// -// Linear address width (SDM Vol.1 §3.3.3): -// Long mode: 64-bit canonical linear addresses. -// Compatibility: 32-bit linear address space — (seg_base + offset) -// is computed mod 2^32. This matters for FS/GS -// accesses with negative 32-bit displacements: -// glibc's 32-bit TLS code reads %gs:-44 expecting -// the 32-bit wrap (GS.base + 0xFFFFFFD4 = -// GS.base-44 mod 2^32). Without the truncation the -// 64-bit sum overflows past 4GB into unmapped -// territory and every TLS load #PFs. -// Real/protected: 32-bit linear — same truncation. -val seg_linear : (MemRef, int) -> qword -function seg_linear(m, access_size) = { - // Apply RIP-relative fixup if pending (only in LongMode, where - // mod=00 rm=101 means [RIP+disp32]) - let offset = if rip_rel_pending then decode_pos + rip_rel_disp else m.addr; - check_seg_limit(m.seg, offset, access_size); - let linear : qword = offset + get_seg_base(m.seg); - if cur_mode == LongMode then { - // A data access through a non-canonical linear address is #GP(0), - // or #SS(0) when the SS segment is used (SDM Vol.1 §3.3.7.1; the - // "64-Bit Mode Exceptions" of every memory instruction). Canonical: - // bits 63:47 all equal, or 63:56 with 5-level paging (CR4.LA57). - let high : bits(17) = if CR4[12] == 0b1 then sign_extend(linear[63..56]) else linear[63..47]; - if high != zeros() & high != ones() then { - if m.seg == SS then raise_SS0() else raise_GP0() - }; - linear - } else { - zero_extend(linear[31..0]) - } -} - -// Segmented memory read/write via MemRef (n is in bits; seg_linear takes bytes). -function read_mem_ref(n, m) = read_mem_linear(seg_linear(m, n / 8), PT_Read) -function write_mem_ref(n, m, v) = write_mem_linear(seg_linear(m, n / 8), v) - -// Read a far pointer (selector:offset) from memory. -// Memory layout: [offset (os bits)][selector (16 bits)]. -// Returns (zero-extended offset, selector). -val read_far_pointer : forall 'os, 'os in {16, 32, 64}. (int('os), MemRef) -> (qword, word) -function read_far_pointer(os, m) = { - let d : bits('os + 16) = read_mem(m); - (zero_extend(d['os - 1 .. 0]), d['os + 15 .. 'os]) -} - -// Pop a far pointer (selector:offset) from the stack. -// Each element occupies a full operand-size slot, so the frame is 2*os bits. -// This differs from read_far_pointer (compact os+16 layout for memory -// operands) because CALL FAR pushes each element as a separate os-wide -// push, and RETF pops them the same way. -val pop_far_pointer : forall 'os, 'os in {16, 32, 64}. int('os) -> (qword, word) -function pop_far_pointer(os) = { - let offset = pop(os); - let selector = pop(os); - (zero_extend(offset), selector[15..0]) -} - -// ========================================================================= -// Protected-mode far transfer helpers (SDM Vol.2A JMP/CALL — Protected Mode) -// ========================================================================= - -// Read a segment descriptor from the GDT or cached LDT. -// Returns the parsed descriptor cache entry. -// Raises #GP(selector) if the selector index is beyond the table limit. -val read_descriptor : word -> SegDescCache -function read_descriptor(selector) = { - // Descriptor must fit within the table limit (offset + 7 <= limit) - if ~(descriptor_in_bounds(selector)) then { - throw Fault(EXN_GP, selector_error_code(selector)) - }; - // Implicit supervisor access (SDM Vol.3A §4.6): descriptor-table reads - // bypass U/S regardless of CPL. - let desc_addr = descriptor_address(selector); - let desc_lo : dword = read_mem_implicit(desc_addr); - let desc_hi : dword = read_mem_implicit(desc_addr + 4); - parse_seg_descriptor(desc_lo, desc_hi) -} - -// Load SS, DS, ES, FS or GS on behalf of MOV Sreg, POP Sreg and the LxS -// instructions, with the checks of the SDM's Operation sections (Vol.2B -// MOV, "Loading a segment register while in protected mode results in -// special checks and actions"; Vol.2B POP; Vol.2A LDS/LES/LFS/LGS/LSS): -// SS: null selector -> #GP(0); index beyond the table limit, RPL != CPL, -// not a writable data segment, or DPL != CPL -> #GP(selector); -// not present -> #SS(selector). In 64-bit mode a null SS loads at -// CPL < 3. The SDM also faults when its RPL is not CPL ("#GP(0) If -// an attempt is made to load SS register with NULL segment selector -// when CPL < 3 and CPL ≠ RPL", MOV, 64-Bit Mode Exceptions), a fault -// of one manual only, which the model does not raise: the APM has no -// RPL condition, "A #GP occurs if software attempts to ... load the -// SS register with a null selector in non 64-bit mode or at CPL 3" -// (Vol.2 §4.5.1, p.79; Vol.3 MOV p.242 and LSS p.217, "in -// non-64-bit mode or while CPL = 3"). -// DS/ES/FS/GS with a non-null selector: index beyond the table limit, -// neither a data nor a readable code segment, or a data or -// nonconforming code segment with RPL > DPL or CPL > DPL -// -> #GP(selector); not present -> #NP(selector). -// DS/ES/FS/GS with a null selector: loaded without checks. -// Real mode loads the base from the selector. CS is never loaded here: -// far transfers have their own checks. -val load_data_segment_register : (segreg_idx, word) -> unit -function load_data_segment_register(idx, selector) = { - if cur_mode == RealMode | cur_mode == Virtual8086Mode then load_segment_register(idx, selector) - else { - let rpl : range(0, 3) = unsigned(selector[1..0]); - let null_selector : bool = selector[15..2] == zeros(); - if idx == SS then { - if null_selector then { - if cur_mode == LongMode & cur_cpl < 3 then - load_segment_register(idx, selector) - else - raise_GP0() - } else { - let desc = read_descriptor(selector); - let writable_data : bool = desc.seg_s == 0b1 & desc.seg_type[3] == 0b0 - & desc.seg_type[1] == 0b1; - if rpl != cur_cpl | ~(writable_data) | desc.seg_dpl != cur_cpl then { - throw Fault(EXN_GP, selector_error_code(selector)) - }; - if desc.seg_present == 0b0 then { - throw Fault(EXN_SS, selector_error_code(selector)) - }; - load_segment_register(idx, selector) - } - } else if null_selector then { - load_segment_register(idx, selector) - } else { - let desc = read_descriptor(selector); - let data : bool = desc.seg_type[3] == 0b0; - let readable_code : bool = desc.seg_type[3] == 0b1 & desc.seg_type[1] == 0b1; - let conforming_code : bool = desc.seg_type[3] == 0b1 & desc.seg_type[2] == 0b1; - if desc.seg_s == 0b0 | ~(data | readable_code) then { - throw Fault(EXN_GP, selector_error_code(selector)) - }; - if ~(conforming_code) & (rpl > desc.seg_dpl | cur_cpl > desc.seg_dpl) then { - throw Fault(EXN_GP, selector_error_code(selector)) - }; - if desc.seg_present == 0b0 then { - throw Fault(EXN_NP, selector_error_code(selector)) - }; - load_segment_register(idx, selector) - } - } -} - -// Validate and load CS for a far JMP in protected mode (same-privilege, -// code segment only — no call gates or task switches). -// SDM Vol.2A JMP — Protected Mode, non-64-bit: -// 1. Selector must not be null (#GP(0)) -// 2. Selector index must be within GDT/LDT limits (#GP(selector)) -// 3. Descriptor must be a code segment (S=1, type bit 3 set) (#GP(selector)) -// 4. Non-conforming: DPL = CPL and RPL <= CPL (#GP(selector)) -// Conforming: DPL <= CPL (#GP(selector)) -// 5. Segment must be present (#NP(selector)) -// 6. Load CS, set RPL = CPL -val validate_far_jmp_cs : word -> SegDescCache -function validate_far_jmp_cs(selector) = { - // Null selector check - if selector[15..2] == zeros() then { - throw Fault(EXN_GP, 0x00000000) - }; - - let desc = read_descriptor(selector); - - // Must be a code/data segment (S=1), not a system descriptor - if desc.seg_s == 0b0 then { - throw Fault(EXN_GP, selector_error_code(selector)) - }; - // Must be a code segment (type bit 3 set) - if desc.seg_type[3] == 0b0 then { - throw Fault(EXN_GP, selector_error_code(selector)) - }; - - let rpl : range(0, 3) = unsigned(selector[1..0]); - let conforming : bool = desc.seg_type[2] == 0b1; - - if conforming then { - // Conforming: DPL must be <= CPL - if desc.seg_dpl > cur_cpl then { - throw Fault(EXN_GP, selector_error_code(selector)) - } - } else { - // Non-conforming: DPL must equal CPL, RPL must be <= CPL - if desc.seg_dpl != cur_cpl then { - throw Fault(EXN_GP, selector_error_code(selector)) - }; - if rpl > cur_cpl then { - throw Fault(EXN_GP, selector_error_code(selector)) - } - }; - - // Segment must be present - if desc.seg_present == 0b0 then { - throw Fault(EXN_NP, selector_error_code(selector)) - }; - - desc -} - -// Complete a far transfer in protected mode: load CS from a validated -// descriptor, update execution mode, and set RIP. -// Shared by exec_far_jmp and exec_far_call. -val finish_far_transfer : (SegDescCache, word, qword, {16, 32, 64}) -> unit -function finish_far_transfer(desc, selector, offset, os) = { - let desc = access_segment_descriptor(selector, desc); - let adj_sel : word = (selector & 0xFFFC) | zero_extend(to_bits(2, cur_cpl)); - write_segreg(CS, adj_sel); - SegCache[CS] = desc; - if EFER[10] == 0b1 then { - set_mode(if desc.seg_l == 0b1 then LongMode else CompatibilityMode) - }; - next_rip = Some(match os { - 16 => zero_extend(offset[15..0]), - 32 => zero_extend(offset[31..0]), - _ => offset, - }) -} - -// Execute far JMP: load CS:RIP from selector:offset. -val exec_far_jmp : (word, qword, {16, 32, 64}) -> unit -function exec_far_jmp(selector, offset, os) = match cur_mode { - m if m == RealMode | m == Virtual8086Mode => { - if cur_mode == Virtual8086Mode & os == 32 & unsigned(offset[31..0]) > 65535 then raise_GP0(); - load_segment_register(CS, selector); - next_rip = Some(match os { - 16 => zero_extend(offset[15..0]), - _ => zero_extend(offset[31..0]), - }) - }, - _ => { - if selector[15..2] == zeros() then raise_GP0(); - let desc = read_descriptor(selector); - if EFER[10] == 0b0 & desc.seg_s == 0b0 & - (desc.seg_type == 0x4 | desc.seg_type == 0xC) then { - // SDM Vol.2A JMP, CALL-GATE: unlike CALL, JMP cannot enter a - // more-privileged nonconforming segment and never changes stacks. - let err = selector_error_code(selector); - if desc.seg_dpl < cur_cpl | unsigned(selector[1..0]) > desc.seg_dpl then raise_GP(err); - if desc.seg_present == 0b0 then throw Fault(EXN_NP, err); - let gate : qword = read_mem_implicit(descriptor_address(selector)); - let target_sel : word = gate[31..16]; - if target_sel[15..2] == zeros() then raise_GP0(); - let target = read_descriptor(target_sel); - let target_err = selector_error_code(target_sel); - if target.seg_s == 0b0 | target.seg_type[3] == 0b0 | - (target.seg_type[2] == 0b1 & target.seg_dpl > cur_cpl) | - (target.seg_type[2] == 0b0 & target.seg_dpl != cur_cpl) then raise_GP(target_err); - if target.seg_present == 0b0 then throw Fault(EXN_NP, target_err); - let width : {16, 32} = if desc.seg_type == 0x4 then 16 else 32; - let dest : qword = if width == 16 then zero_extend(gate[15..0]) - else zero_extend(gate[63..48] @ gate[15..0]); - if unsigned(dest) > unsigned(target.seg_limit) then raise_GP0(); - finish_far_transfer(target, target_sel, dest, width) - } else finish_far_transfer(validate_far_jmp_cs(selector), selector, offset, os) - }, -} - -// Execute far CALL: push CS:RIP, then load CS:RIP from selector:offset. -// In protected mode, the descriptor is validated before pushing so that -// a fault does not modify the stack. -// Stack selection for a legacy inter-privilege transfer. SDM Vol.2A CALL, -// MORE-PRIVILEGE; Vol.3A section 10.6, Figure 10-10 (16-bit TSS). -val read_privilege_stack : cpl_t -> (qword, word) -function read_privilege_stack(level) = { - let is32 : bool = TR_type[3] == 0b1; - let off : qword = to_bits(64, if is32 then level * 8 + 4 else level * 4 + 2); - let last : int = if is32 then 5 else 3; - if unsigned(off) + last > unsigned(TR_limit) then - throw Fault(EXN_TS, selector_error_code(TR)); - if is32 then { - let sp : dword = read_mem_implicit(TR_base + off); - let ss : word = read_mem_implicit(TR_base + off + 4); - (zero_extend(sp), ss) - } else { - let sp : word = read_mem_implicit(TR_base + off); - let ss : word = read_mem_implicit(TR_base + off + 2); - (zero_extend(sp), ss) - } -} - -val validate_privilege_stack : (word, cpl_t) -> SegDescCache -function validate_privilege_stack(sel, level) = { - let err = selector_error_code(sel); - if sel[15..2] == zeros() then throw Fault(EXN_TS, err); - let desc : SegDescCache = try { read_descriptor(sel) } catch { - Fault(v, e) => { - if v == EXN_GP then throw Fault(EXN_TS, err) else throw Fault(v, e); - exit() - }, - e => throw e, - }; - if unsigned(sel[1..0]) != level | desc.seg_dpl != level | - desc.seg_s == 0b0 | desc.seg_type[3] == 0b1 | desc.seg_type[1] == 0b0 then - throw Fault(EXN_TS, err); - if desc.seg_present == 0b0 then throw Fault(EXN_SS, err); - desc -} - -// Write a checked legacy transfer frame without changing segment registers. -// The complete destination range is validated before the first write. -val write_legacy_frame : (SegDescCache, qword, vector(35, dword), range(1, 35), {16, 32}, cpl_t, dword) -> qword -function write_legacy_frame(desc, sp, frame, count, width, level, err) = { - let sas : {16, 32} = if desc.seg_db == 0b1 then 32 else 16; - let top = unsigned(sp[sas - 1 .. 0]); - let size = count * (width / 8); - let bottom = top - size; - let expand_down : bool = desc.seg_type[2] == 0b1; - if bottom < 0 | (expand_down & bottom <= unsigned(desc.seg_limit)) | - (~(expand_down) & top - 1 > unsigned(desc.seg_limit)) then throw Fault(EXN_SS, err); - let addr = desc.seg_base + to_bits(64, bottom); - let old_cpl = cur_cpl; - cur_cpl = level; - try { - foreach (i from 0 to size - 1) { - let _ = translate_addr(addr + to_bits(64, i), PT_Write); - () - }; - foreach (i from 0 to count - 1) { - write_mem_linear(width, addr + to_bits(64, i * (width / 8)), frame[i][width - 1 .. 0]) - } - } catch { e => { cur_cpl = old_cpl; throw e } }; - cur_cpl = old_cpl; - to_bits(64, bottom) -} - -// Legacy 16/32-bit call gates (SDM Vol.2A CALL, CALL-GATE, -// MORE-PRIVILEGE and SAME-PRIVILEGE). The operand's offset is ignored. -val exec_legacy_call_gate : (word, SegDescCache) -> unit -function exec_legacy_call_gate(selector, gate_desc) = { - let err = selector_error_code(selector); - if gate_desc.seg_dpl < cur_cpl | unsigned(selector[1..0]) > gate_desc.seg_dpl then raise_GP(err); - if gate_desc.seg_present == 0b0 then throw Fault(EXN_NP, err); - let gate : qword = read_mem_implicit(descriptor_address(selector)); - let target_sel : word = gate[31..16]; - if target_sel[15..2] == zeros() then raise_GP0(); - let target = read_descriptor(target_sel); - if target.seg_s == 0b0 | target.seg_type[3] == 0b0 | target.seg_dpl > cur_cpl then - raise_GP(selector_error_code(target_sel)); - if target.seg_present == 0b0 then throw Fault(EXN_NP, selector_error_code(target_sel)); - let width : {16, 32} = if gate_desc.seg_type == 0x4 then 16 else 32; - let offset : qword = if width == 16 then zero_extend(gate[15..0]) else zero_extend(gate[63..48] @ gate[15..0]); - if unsigned(offset) > unsigned(target.seg_limit) then raise_GP0(); - let inward : bool = target.seg_type[2] == 0b0 & target.seg_dpl < cur_cpl; - let level : cpl_t = if inward then target.seg_dpl else cur_cpl; - let old_sp : qword = zero_extend(v(stack_addr_size(), RSP)); - var stack_desc = SegCache[SS]; - var stack_sel = read_segreg(SS); - var stack_sp = old_sp; - let params : range(0, 31) = if inward then unsigned(gate[36..32]) else 0; - var frame : vector(35, dword) = [ - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 - ]; - frame[0] = decode_pos[31..0]; - frame[1] = zero_extend(read_segreg(CS)); - if inward then { - let (new_sp, new_ss) = read_privilege_stack(level); - stack_desc = validate_privilege_stack(new_ss, level); - stack_sel = new_ss; - stack_sp = new_sp; - foreach (i from 0 to params - 1) { - let src : MemRef = struct { seg = SS, addr = old_sp + to_bits(64, i * (width / 8)) }; - frame[i + 2] = zero_extend(read_mem(width, src)) - }; - frame[params + 2] = old_sp[31..0]; - frame[params + 3] = zero_extend(read_segreg(SS)) - }; - let count : range(1, 35) = if inward then params + 4 else 2; - let new_sp = write_legacy_frame(stack_desc, stack_sp, frame, count, width, level, - if inward then selector_error_code(stack_sel) else 0x00000000); - let accessed_target = access_segment_descriptor(target_sel, target); - if inward then { - let accessed_stack = access_segment_descriptor(stack_sel, stack_desc); - write_segreg(SS, stack_sel); - SegCache[SS] = accessed_stack; - v(32, RSP) = new_sp[31..0] - } else { - let sas = stack_addr_size(); - v(RSP) = new_sp[sas - 1 .. 0] - }; - cur_cpl = level; - finish_far_transfer(accessed_target, target_sel, offset, width) -} - -val exec_far_call : (word, qword, {16, 32, 64}) -> unit -function exec_far_call(selector, offset, os) = match cur_mode { - m if m == RealMode | m == Virtual8086Mode => { - if cur_mode == Virtual8086Mode & os == 32 & unsigned(offset[31..0]) > 65535 then raise_GP0(); - match os { - 16 => push(32, read_segreg(CS) @ decode_pos[15..0]), - _ => push(64, zero_extend(32, read_segreg(CS)) @ decode_pos[31..0]), - }; - exec_far_jmp(selector, offset, os) - }, - _ => { - if cur_mode == ProtectedMode & selector[15..2] != zeros() then { - let gate = read_descriptor(selector); - if gate.seg_s == 0b0 & (gate.seg_type == 0x4 | gate.seg_type == 0xC) then { - exec_legacy_call_gate(selector, gate); - return () - } - }; - let desc = validate_far_jmp_cs(selector); - match os { - 16 => push(32, read_segreg(CS) @ decode_pos[15..0]), - 32 => push(64, zero_extend(32, read_segreg(CS)) @ decode_pos[31..0]), - 64 => push(128, zero_extend(64, read_segreg(CS)) @ decode_pos), - }; - finish_far_transfer(desc, selector, offset, os) - }, -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail deleted file mode 100644 index 27e816d91..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/operands.sail +++ /dev/null @@ -1,418 +0,0 @@ -// x86-64 — Operand types, decode helpers, and operand accessors - -// ========================================================================= -// Prefix state accumulated during prefix scanning -// ========================================================================= - -struct Prefixes = { - has_lock : bool, - has_repne : bool, // F2 - has_rep : bool, // F3 - seg_override : option(segreg_idx), - has_opsize : bool, // 66 - has_adsize : bit, // 67 - rex_w : bool, - rex_r : bit, - rex_x : bit, - rex_b : bit, - has_rex : bool, // any REX present (changes byte reg encoding) - // VEX prefix fields - vex_present : bool, // VEX prefix was decoded - vex_l : bool, // vector length: false=128, true=256 - vex_vvvv : simd_idx, // extra register operand (already complemented) - vex_w : bool, // VEX.W (like REX.W for some instructions) - // EVEX prefix fields - evex_present : bool, // EVEX prefix was decoded - evex_ll : range(0, 3),// vector length: 0=128, 1=256, 2=512 - evex_vvvvv : simd_idx,// 5-bit source register (vvvv + V') - evex_aaa : kreg_idx, // opmask register index (k0-k7) - evex_z : bit, // zeroing (1) vs merging (0) - evex_b : bool, // broadcast / rounding control - evex_rr : bit, // R' (extends reg to 5 bits) -} - -val default_prefixes : unit -> Prefixes -function default_prefixes() = struct { - has_lock = false, - has_repne = false, - has_rep = false, - seg_override = None(), - has_opsize = false, - has_adsize = 0b0, - rex_w = false, - rex_r = 0b0, - rex_x = 0b0, - rex_b = 0b0, - has_rex = false, - vex_present = false, - vex_l = false, - vex_vvvv = 0, - vex_w = false, - evex_present = false, - evex_ll = 0, - evex_vvvvv = 0, - evex_aaa = 0, - evex_z = 0b0, - evex_b = false, - evex_rr = 0b0, -} - -// ========================================================================= -// Resolved ModR/M operand — either a register or memory address -// ========================================================================= - -// A resolved ModR/M operand: either a register index or a logical memory -// address (segment + effective address/offset). Per SDM Vol.3A §3.4, the -// processor translates a logical address to a linear address by: -// 1. checking the offset against the segment limit (§6.3) -// 2. adding the segment base to the offset -// Both steps happen at memory-access time, not during decode. -union RM = { - RM_reg : GPRRef, - RM_mem : MemRef, -} - -// SIMD register-or-memory operand (XMM/YMM/ZMM). -// Unlike RM (which carries a GPRRef), XRM carries a simd_idx directly. -union XRM = { - XRM_reg : simd_idx, - XRM_mem : MemRef, -} - -// Extract simd_idx from XRM, raising #UD if it's a memory operand. -// Use for register-only SIMD instructions. -val xrm_reg : XRM -> simd_idx -function xrm_reg(xm) = match xm { - XRM_reg(xi) => xi, - XRM_mem(_) => { raise_UD(); 0 }, -} - -// RIP-relative fixup for effective addresses. When rip_rel_pending is true, -// the offset was computed with an intermediate decode_pos (before trailing -// imm bytes were fetched). seg_linear() handles this automatically, so -// instruction code rarely needs to call this directly. -val fixup_addr : qword -> qword -function fixup_addr(addr) = - if rip_rel_pending then decode_pos + rip_rel_disp - else addr - -// ========================================================================= -// ALU operation codes (for the regular 00-3F pattern + Group 1) -// ========================================================================= - -enum ALUOp = { - ALU_ADD, - ALU_OR, - ALU_ADC, - ALU_SBB, - ALU_AND, - ALU_SUB, - ALU_XOR, - ALU_CMP, -} - -// ========================================================================= -// Shift/rotate operation codes (for Group 2) -// ========================================================================= - -// ========================================================================= -// Mandatory prefix classification (for 2-byte+ opcodes) -// ========================================================================= - -enum MandatoryPrefix = { - MP_NONE, - MP_66, - MP_F2, - MP_F3, -} - -// ========================================================================= -// Decode state — mutable position tracking during fetch -// (decode_pos is defined in regs.sail so instruction implementations -// can access it for control-flow instructions) -// ========================================================================= - -// Fetch n bytes from the instruction stream. Returns bits(8*n). -// Uses PT_Execute access type for paging permission checks (NX bit). -// x86 instructions are at most 15 bytes; raises #GP(0) if exceeded. -val fetch : forall 'n, 'n > 0. int('n) -> bits(8 * 'n) -function fetch(n) = { - if unsigned(decode_pos) - unsigned(insn_start) + n > 15 then { - throw(Fault(EXN_GP, 0x00000000)) - }; - if cur_mode == Virtual8086Mode then check_seg_limit(CS, decode_pos, n); - let linear : qword = decode_pos + get_seg_base(CS); - // "Attempting to execute code ... at a non-canonical RIP" is #GP(0) - // (APM Vol.2 §8.2.14, Table 8-6), where an AMD SYSRET can leave RIP. - // The control transfers check their targets themselves. - if cur_mode == LongMode then { - let high : bits(17) = if CR4[12] == 0b1 then sign_extend(linear[63..56]) else linear[63..47]; - if high != zeros() & high != ones() then throw(Fault(EXN_GP, 0x00000000)) - }; - // SDM Vol.3A sections 3.4 and 5.1.1: outside 64-bit mode the - // segment-base addition produces a 32-bit linear address. Instruction - // fetch needs the same truncation as segmented data accesses. - let addr = if cur_mode == LongMode then linear else zero_extend(linear[31..0]); - let result : bits(8 * 'n) = read_mem_linear(addr, PT_Execute); - decode_pos = decode_pos + n; - result -} - -// The next instruction byte, left in the stream: the ModR/M byte of an -// opcode whose validity depends on it, checked before the instruction -// decodes its operands (check_legacy_simd). -val peek_modrm : unit -> byte -function peek_modrm() = { - let modrm : byte = fetch(1); - decode_pos = decode_pos - 1; - modrm -} - -// The byte after the ModR/M byte, left in the stream like it: the SIB byte -// of a VSIB operand, whose registers decide whether a gather is valid -// (vex_check_form, evex_check_form). -val peek_sib : unit -> byte -function peek_sib() = { - let _ : byte = fetch(1); - let sib : byte = fetch(1); - decode_pos = decode_pos - 2; - sib -} - -// ========================================================================= -// Operand size determination -// ========================================================================= - -// Standard operand size (SDM Vol.1 §3.6). -// LongMode: default OS32, REX.W → OS64, 66h → OS16. -// Non-LongMode, CS.D=1: default OS32, 66h → OS16. -// Non-LongMode, CS.D=0: default OS16, 66h → OS32. -val opsize : Prefixes -> {16, 32, 64} -function opsize(pfx) = - if pfx.rex_w then { - 64 - } else if cur_mode == LongMode then { - if pfx.has_opsize then 16 else 32 - } else if get_cs_db() == 0b1 then { - if pfx.has_opsize then 16 else 32 - } else { - if pfx.has_opsize then 32 else 16 - } - -// Operand size for instructions that default to 64-bit (PUSH, POP). -// LongMode: default OS64, 66h → OS16 (OS32 not encodable), REX.W → OS64 -// with or without 66h ("setting REX.W takes precedence over the operand- -// size prefix (66H) when both are used", SDM Vol.1 §3.6.1 p.3-19; "if a -// 66H prefix is used with prefix (REX.W = 1), 66H is ignored", Vol.2A -// §2.2.1.2 p.2-8). -// Non-LongMode, CS.D=1: default OS32, 66h → OS16. -// Non-LongMode, CS.D=0: default OS16, 66h → OS32. -val opsize_default64 : Prefixes -> {16, 32, 64} -function opsize_default64(pfx) = - if pfx.rex_w then { - 64 - } else if cur_mode == LongMode then { - if pfx.has_opsize then 16 else 64 - } else if get_cs_db() == 0b1 then { - if pfx.has_opsize then 16 else 32 - } else { - if pfx.has_opsize then 32 else 16 - } - -// Operand size of the near branches: CALL, RET, Jcc, JrCXZ, JMP, LOOP and -// LOOPcc. It sets the truncation of the new instruction pointer, the size -// of CALL's push and RET's pop, and the indirect-branch operand size. -// Outside 64-bit mode it is the operand size (CS.D and 66h). In 64-bit -// mode the manuals give 66h different meanings, so the model follows the -// vendor register (regs.sail): "all of the above actions are forced to 64 -// bits regardless of operand size prefixes (operand size prefixes are -// silently ignored)" (SDM Vol.1 §6.4.7 p.6-12; "f64", Vol.2D Table A-1), -// where on AMD "The operand size for near branches can be overridden to -// 16 bits in 64-bit mode" (APM Vol.2 §2.5.6 p.32; Vol.1 §3.7.9.1 Table -// 3-9 p.90; Vol.3 Table B-1, note 6), and REX.W, which takes precedence -// over 66h (Vol.3 §1.2.2 p.8), keeps it at 64. -val opsize_forced64 : Prefixes -> {16, 32, 64} -function opsize_forced64(pfx) = - if cur_mode == LongMode then { - if pfx.has_opsize & ~(pfx.rex_w) & vendor == Vendor_AMD then 16 else 64 - } else if get_cs_db() == 0b1 then { - if pfx.has_opsize then 16 else 32 - } else { - if pfx.has_opsize then 32 else 16 - } - -// Displacement size of CALL rel, JMP rel and Jcc rel (E8, E9, 0F 80-8F): -// the operand size outside 64-bit mode, and in 64-bit mode 32 bits ("the -// displacement field for relative branches is still limited to 32 bits", -// SDM Vol.1 §6.4.7 p.6-12), but 16 bits where 66h makes the operand size -// 16 on AMD (opsize_forced64): "CALL rel16off E8 iw", "JMP rel16off E9 -// cw", "JO rel16off 0F 80 cw" (APM Vol.3 CALL (Near), JMP (Near), Jcc). -val opsize_rel : Prefixes -> {16, 32} -function opsize_rel(pfx) = if opsize_forced64(pfx) == 16 then 16 else 32 - -// ========================================================================= -// Register index helpers (extending 3-bit fields with REX bits) -// ========================================================================= - -// Decode the ModR/M reg field (bits 5:3) with REX.R. -val modrm_reg : (byte, Prefixes) -> GPRRef -function modrm_reg(modrm, pfx) = - struct { gpr_idx = unsigned(pfx.rex_r @ modrm[5..3]), has_rex = pfx.has_rex } - -// Decode the ModR/M r/m field (bits 2:0) with REX.B. -val modrm_rm_reg : (byte, Prefixes) -> gpr_idx -function modrm_rm_reg(modrm, pfx) = - unsigned(pfx.rex_b @ modrm[2..0]) - -// ========================================================================= -// Generic operand read/write through RM union -// ========================================================================= - -val read_rm_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM) -> bits('os) -function read_rm_val(os, rm) = - match rm { - RM_reg(r) => read_gpr_ref(r), - RM_mem(m) => read_mem(m), - } - -val write_rm_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM, bits('os)) -> unit -function write_rm_val(os, rm, v) = - match rm { - RM_reg(r) => write_gpr_ref(r) = v, - RM_mem(m) => write_mem(m,v), - } - -// The memory destination of a read-modify-write instruction (ADD, ADC, -// SUB, SBB, AND, OR, XOR, INC, DEC, NOT, NEG, the shifts and rotates, -// SHLD/SHRD, BTS/BTR/BTC, XCHG, XADD, CMPXCHG, CMPXCHG8B/16B) is read with -// write intent: the read already needs write access to every page of the -// operand. The W/R bit of a page fault is 1 "if the access causing the -// page-fault exception was a write" (SDM Vol.3A §5.7 p.5-39; APM Vol.2 -// §8.4.2 p.264), and neither manual says whether the read of a -// read-modify-write is one. The model reports it as a write, as the SDM -// does for EPT: "An EPT violation that occurs during as a result of -// execution of a read-modify-write operation sets bit 1 (data write)" -// (Vol.3C §30.2.1 p.30-8). CMPXCHG writes in any case: "the destination -// operand receives a write cycle without regard to the result of the -// comparison" (SDM Vol.2A CMPXCHG p.3-194), "CMPXCHG always does a -// read-modify-write on the memory operand" (APM Vol.3 CMPXCHG p.167). Of -// a shift or rotate by 0 the manuals give only the flags ("If the count is -// 0, the flags are not affected", SDM Vol.2B SAL/SAR/SHL/SHR p.4-606; "If -// the shift count is 0, no flags are modified", APM Vol.3 SAL p.325), not -// whether it accesses its memory operand; in the model it is an RMW like -// any other count. -val read_rmw_mem : forall 'n, 'n > 0. (implicit('n), MemRef) -> bits('n) -function read_rmw_mem(n, m) = read_mem_linear(seg_linear(m, n / 8), PT_Write) - -val read_rmw : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM) -> bits('os) -function read_rmw(os, rm) = - match rm { - RM_reg(r) => read_gpr_ref(r), - RM_mem(m) => read_rmw_mem(m), - } - -// Memory-only RM read/write: raise #UD if register operand. -// Size parameter 'n is in bits. -val read_mem_rm : forall 'n, 'n > 0. (implicit('n), RM) -> bits('n) -function read_mem_rm(n, rm) = - match rm { - RM_reg(_) => raise_UD(), - RM_mem(m) => read_mem(m), - } - -val write_mem_rm : forall 'n, 'n > 0. (implicit('n), RM, bits('n)) -> unit -function write_mem_rm(n, rm, v) = - match rm { - RM_reg(_) => raise_UD(), - RM_mem(m) => write_mem(m,v), - } - -// Register-only RM read/write: raise #UD if memory operand. -val read_reg_rm : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM) -> bits('os) -function read_reg_rm(os, rm) = - match rm { - RM_reg(r) => read_gpr_ref(r), - RM_mem(_) => raise_UD(), - } - -val write_reg_rm : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), RM, bits('os)) -> unit -function write_reg_rm(os, rm, v) = - match rm { - RM_reg(r) => write_gpr_ref(r) = v, - RM_mem(_) => raise_UD(), - } - -overload rm = {read_rm_val, write_rm_val} -overload rm_mem = {read_mem_rm, write_mem_rm} -overload rm_reg = {read_reg_rm, write_reg_rm} - -// Alignment check: raises #GP(0) if linear address is not aligned. -// No-op for register operands. -val check_memref_alignment : forall 'a, 'a in {16, 32, 64}. (MemRef, int('a)) -> unit -function check_memref_alignment(m, align) = - if unsigned(seg_linear(m, 0)) % align != 0 then raise_GP0() - -val check_rm_alignment : forall 'a, 'a in {16, 32, 64}. (RM, int('a)) -> unit -function check_rm_alignment(rm, align) = match rm { - RM_mem(m) => check_memref_alignment(m, align), - RM_reg(_) => (), -} - -overload check_alignment = {check_memref_alignment, check_rm_alignment} - -// ========================================================================= -// Universal operand accessor v() -// ========================================================================= -// -// Mirrors SDM pseudocode style: v(dest) = v(src) + v(dest) -// Works uniformly on gpr_idx, GPRRef, RM, and MemRef operands. -val read_memref_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), MemRef) -> bits('os) -function read_memref_val(os, m) = read_mem(m) - -val write_memref_val : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), MemRef, bits('os)) -> unit -function write_memref_val(os, m, x) = write_mem(m, x) - -overload v = {read_memref_val, write_memref_val, read_rm_val, write_rm_val} - -// ========================================================================= -// Address size determination (for string ops, LOOP, XLAT, etc.) -// ========================================================================= - -// Address size (SDM Vol.1 §3.6). -// LongMode: default 64, 67h → 32. -// Non-LongMode, CS.D=1: default 32, 67h → 16. -// Non-LongMode, CS.D=0: default 16, 67h → 32. -val get_address_size : Prefixes -> address_size -function get_address_size(pfx) = - if cur_mode == LongMode then { - if pfx.has_adsize == 0b1 then 32 else 64 - } else if get_cs_db() == 0b1 then { - if pfx.has_adsize == 0b1 then 16 else 32 - } else { - if pfx.has_adsize == 0b1 then 32 else 16 - } - -// ========================================================================= -// SIMD element extraction -// ========================================================================= - -// Extract the i-th element of width 'eb from a bitvector. -// velem(32, src, 2) returns src[95..64] — the third dword. -// Index can be nat or bitvector. -val velem_nat : forall 'vl 'eb, 'vl > 0 & 'eb > 0 & 'vl >= 'eb. - (int('eb), bits('vl), nat) -> bits('eb) -function velem_nat(eb, v, i) = (v >> (i * eb))[('eb - 1) .. 0] - -val velem_bits : forall 'vl 'eb 'ib, 'vl > 0 & 'eb > 0 & 'vl >= 'eb & 'ib > 0. - (int('eb), bits('vl), bits('ib)) -> bits('eb) -function velem_bits(eb, v, i) = (v >> (unsigned(i) * eb))[('eb - 1) .. 0] - -overload velem = {velem_nat, velem_bits} - -// ========================================================================= -// SIMD register index helpers (extending 3-bit fields with REX bits) -// ========================================================================= - -val modrm_xreg : (byte, Prefixes) -> simd_idx -function modrm_xreg(modrm, pfx) = - unsigned(pfx.rex_r @ modrm[5..3]) diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail deleted file mode 100644 index 8d1752608..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/paging.sail +++ /dev/null @@ -1,481 +0,0 @@ -// x86-64 — 4-Level and 5-Level Paging (Long Mode) -// -// Implements the IA-32e paging mechanism: -// 4-level (default): Virtual address → PML4 → PDPT → PD → PT → Physical address -// 5-level (CR4.LA57): Virtual address → PML5 → PML4 → PDPT → PD → PT → Physical address -// -// Page table walks use phys_read to avoid recursion through mem_read. -// Follows the sail-riscv pattern: translate_addr() returns physical address -// or throws Fault(EXN_PF, error_code) on failure. - -// Apply A20 gate masking: when A20 is disabled, bit 20 of the physical -// address is forced to zero, wrapping the address space at 1MB. -val a20_mask : qword -> qword -function a20_mask(addr) = - if ~(a20_enabled) & system_mode then addr & 0xFFFFFFFFFFEFFFFF - else addr - -// ========================================================================= -// EPT (Extended Page Tables) Translation — SDM Vol.3C §29.3 -// -// When in VMX non-root with EPT enabled (secondary proc controls bit 1), -// guest-physical addresses go through a second translation layer: -// Guest Physical Address (GPA) → EPT walk → Host Physical Address (HPA) -// -// The EPT page table format mirrors the standard 4-level paging: -// EPT PML4 → EPT PDPT → EPT PD → EPT PT -// Entries use R/W/X permission bits (bits 2:0) instead of P/R-W/U-S. -// The EPT root pointer is in vmcs.ept_pointer[51:12]. -// ========================================================================= - -// Check if EPT is active (fast path: just read the cached register). -// ept_active is declared in regs.sail, set by vm_entry/complete_vm_exit. -val ept_enabled : unit -> bool -function ept_enabled() = ept_active - -// Build EPT violation exit qualification -val ept_violation_qual : (PTAccess, bool) -> qword -function ept_violation_qual(access, present) = { - var qual : qword = zeros(); - // Descriptor reads and writes retain their access direction at EPT. - if access == PT_Read | access == PT_Implicit then qual[0] = 0b1; - if (access == PT_Write | access == PT_ImplicitWrite) then qual[1] = 0b1; - if access == PT_Execute then qual[2] = 0b1; - if present then { - qual[3] = 0b1; - qual[4] = 0b1; - qual[5] = 0b1 - }; - qual -} - -// Walk the EPT page table hierarchy. Uses __read_mem directly (not phys_read) -// to avoid recursion since phys_read calls ept_translate. -// On violation, throws VMExit(VMEXIT_EPT_VIOLATION, qualification). -val ept_walk : (qword, PTAccess, qword, range(0, 3)) -> qword -function ept_walk(gpa, access, table_base, level) = { - let index : qword = match level { - 3 => zero_extend((gpa[47..39]) : bits(9)), // PML4 - 2 => zero_extend((gpa[38..30]) : bits(9)), // PDPT - 1 => zero_extend((gpa[29..21]) : bits(9)), // PD - 0 => zero_extend((gpa[20..12]) : bits(9)), // PT - }; - let epte_addr : qword = table_base + (index << 3); - let epte : qword = __read_mem(epte_addr, 64); - - // Check R/W/X permissions (bits 2:0). If all zero, entry not present. - let r = epte[0]; - let w = epte[1]; - let x = epte[2]; - if (r | w | x) == 0b0 then { - // EPT violation: not present - let qual : qword = ept_violation_qual(access, false); - vmcs.guest_physical_address = gpa; - vmcs.exit_instr_length = 0x00000000; - throw VMExit(VMEXIT_EPT_VIOLATION, qual) - }; - - // Check for large page (PS bit = bit 7) - let is_leaf : bool = if level == 0 then true - else if (level == 1 | level == 2) & epte[7] == 0b1 then true - else false; - - if is_leaf then { - // Permission check. Implicit (descriptor-table) accesses are reads - // at the EPT level — R must be set on the leaf EPTE. - let denied : bool = match access { - PT_Read => r == 0b0, - PT_Write => w == 0b0, - PT_Execute => x == 0b0, - PT_Implicit => r == 0b0, - PT_ImplicitWrite => w == 0b0, - }; - if denied then { - let qual : qword = ept_violation_qual(access, true); - vmcs.guest_physical_address = gpa; - vmcs.exit_instr_length = 0x00000000; - throw VMExit(VMEXIT_EPT_VIOLATION, qual) - }; - - // Compute host physical address - let ppn : qword = epte & 0x000FFFFFFFFFF000; - match level { - 0 => ppn | (gpa & 0x0000000000000FFF), // 4KB - 1 => (ppn & 0x000FFFFFFFE00000) | (gpa & 0x00000000001FFFFF), // 2MB - _ => (ppn & 0x000FFFFFC0000000) | (gpa & 0x000000003FFFFFFF), // 1GB - } - } else if level > 0 then { - let next_base : qword = epte & 0x000FFFFFFFFFF000; - ept_walk(gpa, access, next_base, level - 1) - } else { - // Unreachable: level==0 is always a leaf - vmcs.guest_physical_address = gpa; - throw VMExit(VMEXIT_EPT_VIOLATION, ept_violation_qual(access, false)) - } -} -termination_measure ept_walk(_, _, _, level) = level - -// EPT-translate a guest physical address to host physical address. -// Only active when EPT is enabled; otherwise returns gpa unchanged. -val ept_translate : (qword, PTAccess) -> qword -function ept_translate(gpa, access) = { - if ept_enabled() then { - let ept_root : qword = vmcs.ept_pointer & 0x000FFFFFFFFFF000; - ept_walk(gpa, access, ept_root, 3) - } else { - gpa - } -} - -// Physical memory access (bypass virtual address translation). -// Used by page table walks and by mem_read/mem_write when paging is off. -// When EPT is active, translates guest-physical to host-physical first. -// Size parameter 'n is in bits. -val phys_read : forall 'n, 'n > 0. (implicit('n), qword) -> bits('n) -function phys_read(n, addr) = { - let pa = a20_mask(addr); - if ept_active then __read_mem(ept_translate(pa, PT_Read), n) - else __read_mem(pa, n) -} - -val phys_write : forall 'n, 'n > 0. (implicit('n), qword, bits('n)) -> unit -function phys_write(n, addr, data) = { - let pa = a20_mask(addr); - if ept_active then __write_mem(ept_translate(pa, PT_Write), n, data) - else __write_mem(pa, n, data) -} - -// Build a #PF error code from access type and fault cause. -val mk_pf_error : (PTAccess, bool, bool) -> dword -function mk_pf_error(access, present, reserved) = { - var ec : dword = 0x00000000; - // Bit 0: P — page was present (permission violation vs not-present) - if present then ec[0] = 0b1; - // Bit 1: W/R — write access caused the fault - if (access == PT_Write | access == PT_ImplicitWrite) then ec[1] = 0b1; - // Bit 2: U/S — user-mode access caused the fault. - // Implicit (descriptor-table) accesses are supervisor regardless of CPL. - if cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite) then ec[2] = 0b1; - // Bit 3: RSVD — reserved bit set in PTE - if reserved then ec[3] = 0b1; - // Bit 4: I/D — instruction fetch caused the fault. Hardware sets it - // only when the paging mode can express execute permission: CR4.SMEP=1, - // or NXE-capable paging (PAE/4-level/5-level, i.e. CR4.PAE=1) with - // IA32_EFER.NXE=1 (SDM Vol.3A §4.7). - if access == PT_Execute & - (CR4[20] == 0b1 | (CR4[5] == 0b1 & EFER[11] == 0b1)) - then ec[4] = 0b1; - ec -} - -// Check permissions on a leaf PTE. Returns true if access is allowed. -val check_pte_permissions : (qword, PTAccess) -> bool -function check_pte_permissions(pte, access) = { - let rw = pte[1]; // Read/Write bit - let us = pte[2]; // User/Supervisor bit - let xd = pte[63]; // Execute-Disable bit (if EFER.NXE=1) - - // Implicit accesses (GDT/LDT/IDT/TSS reads by the CPU itself) always - // execute at supervisor privilege regardless of CPL, and don't cause - // an NX fault (they're not instruction fetches). Writes of this class - // (e.g. A/D-bit updates, TSS busy-bit set) still respect WP. - if access == PT_Implicit then true - else if access == PT_ImplicitWrite then rw == 0b1 | CR0[16] == 0b0 - // User-mode access to supervisor page: always denied - else if cur_cpl == 3 & us == 0b0 then false - // Write to read-only page: - // - In user mode: always denied - // - In kernel mode: denied if CR0.WP=1, allowed if WP=0 - else if (access == PT_Write | access == PT_ImplicitWrite) & rw == 0b0 then { - if cur_cpl == 3 then false - else CR0[16] == 0b0 // WP=0 → allowed, WP=1 → denied - } - // Execute from XD page: denied if EFER.NXE=1 - else if access == PT_Execute & xd == 0b1 & EFER[11] == 0b1 then - false - else - true -} - -// Update Accessed and Dirty bits in the PTE if needed. -val update_accessed_dirty : (qword, qword, PTAccess) -> unit -function update_accessed_dirty(pte_addr, pte, access) = { - var new_pte = pte; - var changed : bool = false; - // Set Accessed bit if not already set - if pte[5] == 0b0 then { - new_pte[5] = 0b1; - changed = true - }; - // Set Dirty bit for writes if not already set - if (access == PT_Write | access == PT_ImplicitWrite) & pte[6] == 0b0 then { - new_pte[6] = 0b1; - changed = true - }; - if changed then phys_write(pte_addr, new_pte) -} - -// Page table walk. -// Walks PML5 → PML4 → PDPT → PD → PT to translate a 64-bit linear address. -// On success, returns the physical address. -// On failure, throws Fault(EXN_PF, error_code). -// -// The `level` parameter counts down: -// 4=PML5 (5-level only), 3=PML4, 2=PDPT, 1=PD, 0=PT. -val pt_walk : (qword, PTAccess, qword, range(0, 4)) -> qword -function pt_walk(linear, access, table_base, level) = { - // 1. Compute index: 9 bits per level - // PML5: bits[56:48], PML4: bits[47:39], PDPT: bits[38:30], - // PD: bits[29:21], PT: bits[20:12] - let index : qword = match level { - 4 => zero_extend((linear[56..48]) : bits(9)), // PML5 index - 3 => zero_extend((linear[47..39]) : bits(9)), // PML4 index - 2 => zero_extend((linear[38..30]) : bits(9)), // PDPT index - 1 => zero_extend((linear[29..21]) : bits(9)), // PD index - 0 => zero_extend((linear[20..12]) : bits(9)), // PT index - }; - let pte_addr : qword = table_base + (index << 3); - - // 2. Read PTE from physical memory (bypasses translation) - let pte : qword = phys_read(pte_addr); - - // 3. Check Present bit - if pte[0] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, false, false)) - }; - - // 4. Check reserved bits - // PML5E and PML4E: PS (bit 7) must be 0 (reserved) - // PDPTE/PDE: PS=1 allowed for huge pages - if (level == 4 | level == 3) & pte[7] == 0b1 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, true)) - }; - - // 5. Check if this is a leaf entry - let is_leaf : bool = if level == 0 then true - else if 1 <= level & level <= 2 & pte[7] == 0b1 then true // PS=1 - else false; - - if is_leaf then { - // 6. Permission check - if ~(check_pte_permissions(pte, access)) then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, false)) - }; - - // 7. Update A/D bits - update_accessed_dirty(pte_addr, pte, access); - - // 8. Compute physical address - let ppn : qword = pte & 0x000FFFFFFFFFF000; // bits[51:12] - match level { - // 4KB page: PPN[51:12] | offset[11:0] - 0 => ppn | (linear & 0x0000000000000FFF), - // 2MB page: PPN[51:21] | offset[20:0] - 1 => (ppn & 0x000FFFFFFFE00000) | (linear & 0x00000000001FFFFF), - // 1GB page: PPN[51:30] | offset[29:0] - _ => (ppn & 0x000FFFFFC0000000) | (linear & 0x000000003FFFFFFF), - } - } else if level > 0 then { - // 9. Non-leaf: recurse to next level - let next_base : qword = pte & 0x000FFFFFFFFFF000; - // Update Accessed bit on non-leaf entries too - if pte[5] == 0b0 then phys_write(pte_addr, pte | 0x0000000000000020); - pt_walk(linear, access, next_base, level - 1) - } else { - // level 0 non-leaf = impossible (always leaf) - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, true)) - } -} -termination_measure pt_walk(_, _, _, level) = level - -// ========================================================================= -// 32-bit non-PAE paging (SDM Vol.3A §4.3) -// -// 2-level walk: CR3 → Page Directory (1024 × 4-byte PDEs) → Page Table -// Linear address split: [31:22]=PDE index, [21:12]=PTE index, [11:0]=offset -// CR4.PSE=1 enables 4MB pages when PDE.PS=1. -// ========================================================================= - -val pt_walk_32 : (qword, PTAccess) -> qword -function pt_walk_32(linear, access) = { - let pd_base : qword = CR3 & 0x00000000FFFFF000; - - // 1. PDE lookup: index = linear[31:22] - let pde_index : qword = zero_extend((linear[31..22]) : bits(10)); - let pde_addr : qword = pd_base + (pde_index << 2); - let pde : dword = phys_read(pde_addr); - - // Check present - if pde[0] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, false, false)) - }; - - // Check permissions (R/W, U/S). Implicit (descriptor-table) accesses - // run at supervisor and bypass the U/S check regardless of CPL. - if (access == PT_Write | access == PT_ImplicitWrite) & pde[1] == 0b0 then { - if (cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite)) | CR0[16] == 0b1 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, false)) - } - }; - if cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite) & pde[2] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, false)) - }; - - // 4MB page (CR4.PSE=1 and PDE.PS=1) - if CR4[4] == 0b1 & pde[7] == 0b1 then { - // Update A/D bits - var new_pde = pde; - var changed : bool = false; - if pde[5] == 0b0 then { new_pde[5] = 0b1; changed = true }; - if (access == PT_Write | access == PT_ImplicitWrite) & pde[6] == 0b0 then { - new_pde[6] = 0b1; changed = true - }; - if changed then phys_write(pde_addr, new_pde); - // Physical address: PDE[31:22] @ linear[21:0] - let ppn : dword = pde & 0xFFC00000; - zero_extend(ppn | zero_extend(linear[21..0])) - } else { - // 2. PTE lookup: index = linear[21:12] - let pt_base : qword = zero_extend(pde & 0xFFFFF000); - let pte_index : qword = zero_extend((linear[21..12]) : bits(10)); - let pte_addr : qword = pt_base + (pte_index << 2); - let pte : dword = phys_read(pte_addr); - - // Check present - if pte[0] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, false, false)) - }; - - // Check permissions. Implicit (descriptor-table) accesses bypass U/S. - if (access == PT_Write | access == PT_ImplicitWrite) & pte[1] == 0b0 then { - if (cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite)) | CR0[16] == 0b1 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, false)) - } - }; - if cur_cpl == 3 & (access != PT_Implicit & access != PT_ImplicitWrite) & pte[2] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, false)) - }; - - // Update A/D bits on PDE and PTE - if pde[5] == 0b0 then phys_write(pde_addr, pde | 0x00000020); - var new_pte = pte; - var pte_changed : bool = false; - if pte[5] == 0b0 then { new_pte[5] = 0b1; pte_changed = true }; - if (access == PT_Write | access == PT_ImplicitWrite) & pte[6] == 0b0 then { - new_pte[6] = 0b1; pte_changed = true - }; - if pte_changed then phys_write(pte_addr, new_pte); - - // Physical address: PTE[31:12] @ linear[11:0] - zero_extend((pte & 0xFFFFF000) | zero_extend(linear[11..0])) - } -} - -// ========================================================================= -// PAE paging (SDM Vol.3A §4.4) -// -// 3-level walk: CR3 → PDPT (4 × 64-bit entries) → PD → PT -// Linear address split: [31:30]=PDPTE, [29:21]=PDE, [20:12]=PTE, [11:0]=offset -// PDE/PTE are 64-bit. Supports 2MB pages when PDE.PS=1. -// ========================================================================= - -val pt_walk_pae : (qword, PTAccess) -> qword -function pt_walk_pae(linear, access) = { - // 1. PDPTE lookup: index = linear[31:30] (2 bits, 4 entries) - let pdpt_base : qword = CR3 & 0x00000000FFFFFFE0; - let pdpte_index : qword = zero_extend((linear[31..30]) : bits(2)); - let pdpte_addr : qword = pdpt_base + (pdpte_index << 3); - let pdpte : qword = phys_read(pdpte_addr); - - if pdpte[0] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, false, false)) - }; - - // 2. PDE lookup: index = linear[29:21] - let pd_base : qword = pdpte & 0x000FFFFFFFFFF000; - let pde_index : qword = zero_extend((linear[29..21]) : bits(9)); - let pde_addr : qword = pd_base + (pde_index << 3); - let pde : qword = phys_read(pde_addr); - - if pde[0] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, false, false)) - }; - - // Permission checks - if ~(check_pte_permissions(pde, access)) then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, false)) - }; - - // 2MB page (PDE.PS=1) - if pde[7] == 0b1 then { - update_accessed_dirty(pde_addr, pde, access); - let ppn : qword = pde & 0x000FFFFFFFE00000; - ppn | zero_extend(linear[20..0]) - } else { - // 3. PTE lookup: index = linear[20:12] - let pt_base : qword = pde & 0x000FFFFFFFFFF000; - let pte_index : qword = zero_extend((linear[20..12]) : bits(9)); - let pte_addr : qword = pt_base + (pte_index << 3); - let pte : qword = phys_read(pte_addr); - - if pte[0] == 0b0 then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, false, false)) - }; - - if ~(check_pte_permissions(pte, access)) then { - CR2 = linear; - throw Fault(EXN_PF, mk_pf_error(access, true, false)) - }; - - // Update A/D on PDE and PTE - if pde[5] == 0b0 then phys_write(pde_addr, pde | 0x0000000000000020); - update_accessed_dirty(pte_addr, pte, access); - - let ppn : qword = pte & 0x000FFFFFFFFFF000; - ppn | zero_extend(linear[11..0]) - } -} - -// Top-level address translation. -// Dispatches to the appropriate paging mode based on CR0.PG, EFER.LMA, -// and CR4.PAE (SDM Vol.3A §4.1.1). -val translate_addr : (qword, PTAccess) -> qword -function translate_addr(linear, access) = { - if CR0[31] == 0b0 then { - linear // Paging disabled: linear = physical - } else if EFER[10] == 0b1 then { - // IA-32e mode (long mode): 4-level or 5-level paging - let is_write = (access == PT_Write | access == PT_ImplicitWrite); - match (if access == PT_ImplicitWrite then None() else __tlb_lookup(linear, is_write)) { - Some(paddr) => paddr, - None() => { - let table_base : qword = CR3 & 0x000FFFFFFFFFF000; - let start_level : range(0, 4) = - if CR4[12] == 0b1 then 4 else 3; - let paddr = pt_walk(linear, access, table_base, start_level); - if access != PT_ImplicitWrite then __tlb_insert(linear, paddr, is_write); - paddr - }, - } - } else if CR4[5] == 0b1 then { - // PAE paging (CR4.PAE=1, EFER.LMA=0) - pt_walk_pae(linear, access) - } else { - // 32-bit non-PAE paging - pt_walk_32(linear, access) - } -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail deleted file mode 100644 index 538999453..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/prelude.sail +++ /dev/null @@ -1,126 +0,0 @@ -// x86-64 — Prelude - -default Order dec - -$include -$include -$include -$include -$include -$include -$include -$include -$include - -val unreachable : forall ('a : Type). unit -> 'a -function unreachable() = { - print_endline("unreachable"); - exit() -} - -overload ~ = {not_bool, not_vec} -overload operator & = {and_vec} -overload operator | = {or_vec} -overload operator ^ = {xor_vec} - -val sub_vec = pure {c: "sub_bits", cpp: "sub_bits", _: "sub_vec"} : forall 'n. (bits('n), bits('n)) -> bits('n) -val sub_vec_int = pure {c: "sub_bits_int", cpp: "sub_bits_int", _: "sub_vec_int"} : forall 'n. (bits('n), int) -> bits('n) -overload operator - = {sub_vec, sub_vec_int} -overload operator * = {mult_atom, mult_int} - -val quot_positive_round_zero = pure {interpreter: "quot_round_zero", lem: "hardware_quot", c: "tdiv_int", cpp: "tdiv_int"} - : forall 'n 'm, 'n >= 0 & 'm > 0. (int('n), int('m)) -> int(div('n, 'm)) - -val rem_positive_round_zero = pure {interpreter: "rem_round_zero", lem: "hardware_mod", c: "tmod_int", cpp: "tmod_int"} - : forall 'n 'm, 'n >= 0 & 'm > 0. (int('n), int('m)) -> int(mod('n, 'm)) - -val quot_round_zero = pure {interpreter: "quot_round_zero", lem: "hardware_quot", c: "tdiv_int", cpp: "tdiv_int"} - : forall 'm, 'm != 0. (int, int('m)) -> int - -val rem_round_zero = pure {interpreter: "rem_round_zero", lem: "hardware_mod", c: "tmod_int", cpp: "tmod_int"} - : forall 'm, 'm != 0. (int, int('m)) -> int - -overload operator / = {quot_positive_round_zero} -overload operator % = {rem_positive_round_zero} - -val sign_extend : forall 'n 'm, 'm >= 'n. (implicit('m), bits('n)) -> bits('m) -val zero_extend : forall 'n 'm, 'm >= 'n. (implicit('m), bits('n)) -> bits('m) -function sign_extend(m, v) = sail_sign_extend(v, m) -function zero_extend(m, v) = sail_zero_extend(v, m) - -val zeros : forall 'n, 'n >= 0. implicit('n) -> bits('n) -function zeros(n) = sail_zeros(n) - -val ones : forall 'n, 'n >= 0. implicit('n) -> bits('n) -function ones(n) = sail_ones(n) - -val trunc : forall 'm 'n, 'm >= 0 & 'm <= 'n. (implicit('m), bits('n)) -> bits('m) -function trunc(m, v) = truncate(v, m) - -infix 4 <_s -infix 4 >_s -infix 4 <=_s -infix 4 >=_s -infix 4 <_u -infix 4 >_u -infix 4 <=_u -infix 4 >=_u - -val operator <_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool -val operator >_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool -val operator <=_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool -val operator >=_s : forall 'n, 'n > 0. (bits('n), bits('n)) -> bool -val operator <_u : forall 'n. (bits('n), bits('n)) -> bool -val operator >_u : forall 'n. (bits('n), bits('n)) -> bool -val operator <=_u : forall 'n. (bits('n), bits('n)) -> bool -val operator >=_u : forall 'n. (bits('n), bits('n)) -> bool - -function operator <_s (x, y) = signed(x) < signed(y) -function operator >_s (x, y) = signed(x) > signed(y) -function operator <=_s (x, y) = signed(x) <= signed(y) -function operator >=_s (x, y) = signed(x) >= signed(y) -function operator <_u (x, y) = unsigned(x) < unsigned(y) -function operator >_u (x, y) = unsigned(x) > unsigned(y) -function operator <=_u (x, y) = unsigned(x) <= unsigned(y) -function operator >=_u (x, y) = unsigned(x) >= unsigned(y) - -infix 7 >> -infix 7 >>> -infix 7 << - -val "shift_bits_right" : forall 'n 'm. (bits('n), bits('m)) -> bits('n) -val "shift_bits_right_arith" : forall 'n 'm. (bits('n), bits('m)) -> bits('n) -val "shift_bits_left" : forall 'n 'm. (bits('n), bits('m)) -> bits('n) -val "shiftl" : forall 'm 'n, 'n >= 0. (bits('m), int('n)) -> bits('m) -val "shiftr" : forall 'm 'n, 'n >= 0. (bits('m), int('n)) -> bits('m) - -overload operator >> = {shift_bits_right, shiftr} -overload operator << = {shift_bits_left, shiftl} - -// Arithmetic right shift without allocating a vector of width n + shift. -// Complement negative values before a logical shift, then complement back. -// This also sign-fills when the count is greater than or equal to the width. -val operator >>> : forall 'n 'm, 'n >= 1 & 'm >= 0. (bits('n), int('m)) -> bits('n) -function operator >>>(value, shift) = { - let sign : bits('n) = sign_extend(value[('n - 1)..('n - 1)]); - // The SMT backend sizes shift counts to the shifted vector. Widen by a - // fixed amount so a full 64-bit x86 count is not truncated for small lanes. - let shifted : bits('n + 64) = zero_extend('n + 64, value ^ sign) >> shift; - shifted[('n - 1)..0] ^ sign -} - -mapping bool_bit : bool <-> bit = { - true <-> 0b1, - false <-> 0b0, -} - -function bool_to_bit(x : bool) -> bit = bool_bit(x) - -val to_bits : forall 'l 'x, 'l >= 0 & 0 <= 'x < 2 ^ 'l. (implicit('l), int('x)) -> bits('l) -function to_bits(l, n) = get_slice_int(l, n, 0) - -val to_bits_truncate : forall 'l, 'l >= 0. (implicit('l), int) -> bits('l) -function to_bits_truncate(l, n) = get_slice_int(l, n, 0) - -val print_log = pure {c: "print_endline", cpp: "print_endline", _: "print_endline"} : string -> unit -val trace_log = pure {c: "trace_stderr", cpp: "trace_stderr", _: "print_endline"} : string -> unit diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail deleted file mode 100644 index c2704c867..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/regs.sail +++ /dev/null @@ -1,1184 +0,0 @@ -// x86-64 — Register Definitions - -// ========================================================================= -// Instruction pointer -// ========================================================================= - -register RIP : qword - -// Branch target set by control-flow instructions (JMP, CALL, RET, Jcc). -// When Some, step() uses this instead of decode_pos to update RIP. -register next_rip : option(qword) = None() - -// ========================================================================= -// Processor mode and privilege -// ========================================================================= - -register cur_mode : ProcessorMode -register cur_cpl : cpl_t - -// ========================================================================= -// General-purpose registers -// -// x86-64 has 16 64-bit GPRs. Sub-register access (e.g. AL, AX, EAX) -// is handled by the read/write functions below. -// ========================================================================= - -register GPR : vector(16, qword) - -// Polymorphic GPR read by operand size. -val read_gpr : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), gpr_idx) -> bits('os) -function read_gpr(os, idx) = match os { - 8 => GPR[idx][7..0], - 16 => GPR[idx][15..0], - 32 => GPR[idx][31..0], - 64 => GPR[idx] -} - -// Polymorphic GPR write by operand size. A 32-bit result is zero-extended -// to 64 bits in 64-bit mode (SDM Vol.1 §3.4.1.1). Outside it "the upper -// 32 bits of 64-bit general-purpose registers are undefined" (SDM Vol.1 -// §3.4.1.1, p.3-13; APM Vol.1 §3.4.5, p.74: "undefined and not accessible -// to software"), and a 32-bit write leaves them so. An 8- or 16-bit -// write keeps the rest of the register. -val write_gpr : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), gpr_idx, bits('os)) -> unit -function write_gpr(os, idx, v) = match os { - 8 => GPR[idx] = GPR[idx][63..8] @ v, - 16 => GPR[idx] = GPR[idx][63..16] @ v, - 32 => GPR[idx] = if cur_mode == LongMode then zero_extend(v) else (undefined : dword) @ v, - 64 => GPR[idx] = v -} - -// Polymorphic GPR read via GPRRef. -// In byte mode without REX, indices 4-7 mean AH/CH/DH/BH (high byte of -// GPR 0-3). With any REX prefix, they mean SPL/BPL/SIL/DIL. -val read_gpr_ref : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), GPRRef) -> bits('os) -function read_gpr_ref(os, r) = { - let idx = r.gpr_idx; - if os == 8 then { - if ~(r.has_rex) & 4 <= idx & idx <= 7 then - GPR[idx - 4][15..8] - else - GPR[idx][7..0] - } else { - read_gpr(idx) - } -} - -// Polymorphic GPR write via GPRRef. -val write_gpr_ref : forall 'os, 'os in {8, 16, 32, 64}. (implicit('os), GPRRef, bits('os)) -> unit -function write_gpr_ref(os, r, v) = { - let idx = r.gpr_idx; - if os == 8 then { - if ~(r.has_rex) & 4 <= idx & idx <= 7 then - GPR[idx - 4][15..8] = v - else - GPR[idx][7..0] = v - } else { - write_gpr(idx, v) - } -} - -overload v = {read_gpr, write_gpr, read_gpr_ref, write_gpr_ref} - -// A change of processor mode: "the upper 32 bits of any general-purpose -// register are not preserved when switching from 64-bit mode to a 32-bit -// mode (to protected mode or compatibility mode)" (SDM Vol.1 §3.4.1.1, -// p.3-13); "The processor does not preserve the upper 32 bits of the -// 64-bit GPRs across changes from 64-bit mode to compatibility or legacy -// modes" (APM Vol.1 §3.4.5, p.74). Those of RAX-RDI become undefined. -// R8-R15, which a 32-bit mode cannot reach, "are preserved across -// transitions from 64-bit mode into compatibility mode then back into -// 64-bit mode" (SDM, ibid.). -val set_mode : ProcessorMode -> unit -function set_mode(m) = { - if cur_mode == LongMode & m != LongMode then { - foreach (i from 0 to 7) { - GPR[i] = (undefined : dword) @ GPR[i][31..0] - } - }; - cur_mode = m -} - -// Named GPR indices for readability. -let RAX : gpr_idx = 0 -let RCX : gpr_idx = 1 -let RDX : gpr_idx = 2 -let RBX : gpr_idx = 3 -let RSP : gpr_idx = 4 -let RBP : gpr_idx = 5 -let RSI : gpr_idx = 6 -let RDI : gpr_idx = 7 -let R8 : gpr_idx = 8 -let R9 : gpr_idx = 9 -let R10 : gpr_idx = 10 -let R11 : gpr_idx = 11 -let R12 : gpr_idx = 12 -let R13 : gpr_idx = 13 -let R14 : gpr_idx = 14 -let R15 : gpr_idx = 15 - -// The vendor whose manual the model follows where the SDM and the APM give -// one encoding different meanings that no undefined value can express: -// 66h on the near branches in 64-bit mode, which changes the instruction's -// length, its stack width and the truncation of RIP (opsize_forced64 and -// opsize_rel, operands.sail), and far CALL and JMP with REX.W, which read -// an m16:64 or an m16:32 pointer (far_pointer_offset_size, -// insn_groups.sail). It does not change the CPUID vendor string. The KVM -// differential harness sets it from the host; the emulators keep the Intel -// default. -enum Vendor = { Vendor_Intel, Vendor_AMD } -register vendor : Vendor = Vendor_Intel - -// ========================================================================= -// x87 FPU Register State -// -// The x87 FPU has an 8-register stack of 80-bit extended precision values. -// Registers are accessed relative to the TOP pointer in the status word. -// The full state includes the control word, status word, and tag word. -// ========================================================================= - -register x87_ST : vector(8, fp80) -register x87_cw : word // control word (default 0x037F) -register x87_sw : word // status word (default 0x0000) -register x87_tw : word // tag word (default 0xFFFF = all empty) -// The last non-control x87 instruction's address, CS selector and opcode, -// and its memory operand's offset and segment selector (SDM Vol.1 §8.1.8, -// §8.1.9). x87_record_last says when each is recorded. -register x87_fip : qword -register x87_fcs : word -register x87_fop : bits(11) -register x87_fdp : qword -register x87_fds : word -// Whether MMX instructions ran after the last x87 instruction: FXSAVE and -// XSAVE then save "the MMX technology registers", and "the high 16 bits -// of the field are reserved" (SDM Vol.2A FXSAVE, Field Definitions -// p.3-414). mmx_touch and EMMS set it, and dispatch_x87 clears it. -register x87_mmx_last : bool = false - -val x87_top : unit -> range(0, 7) -function x87_top() = unsigned(x87_sw[13..11]) - -val x87_set_top : int -> unit -function x87_set_top(t) = { - x87_sw[13..11] = to_bits_truncate(3, t) -} - -val x87_physical : int -> range(0, 7) -function x87_physical(i) = unsigned(to_bits_truncate(3, x87_top() + i)) - -// Tag word helpers: each register has a 2-bit tag at bits [2*phys+1 .. 2*phys]. -// Tag value 3 = empty, anything else = valid. -val x87_mark_valid : range(0, 7) -> unit -function x87_mark_valid(phys) = { - let shift_amt = 2 * phys; - let mask : word = ~(0x0003 << shift_amt); - x87_tw = x87_tw & mask -} - -val x87_mark_empty : range(0, 7) -> unit -function x87_mark_empty(phys) = { - let shift_amt = 2 * phys; - let bits : word = 0x0003 << shift_amt; - x87_tw = x87_tw | bits -} - -// Read ST(i) — the i-th register from the top of the x87 stack. -val x87_read_st : int -> fp80 -function x87_read_st(i) = x87_ST[x87_physical(i)] - -// Write a value to ST(i). The register then holds a number, so it is no -// longer tagged empty (SDM Vol.1 §8.1.7: the tag indicates whether a -// register contains a valid number, zero, a special value, or is empty). -val x87_write_st : (int, fp80) -> unit -function x87_write_st(i, v) = { - let phys = x87_physical(i); - x87_ST[phys] = v; - x87_mark_valid(phys) -} - -// Tag of a non-empty register from its contents (SDM Vol.1 §8.1.7, Figure -// 8-7): 00 valid, 01 zero, 10 special (NaN, unsupported, infinity, denormal). -val x87_class_tag : fp80 -> bits(2) -function x87_class_tag(v) = { - let exp : bits(15) = v[78..64]; - let mant : qword = v[63..0]; - if exp == zeros() then (if mant == zeros() then 0b01 else 0b10) - else if exp == ones() then 0b10 - else if mant[63] == bitzero then 0b10 - else 0b00 -} - -// The tag word as FSTENV and FSAVE store it: registers tagged empty stay -// empty, the others are classified from their contents. -val x87_tag_word : unit -> word -function x87_tag_word() = { - var tw : word = x87_tw; - foreach (i from 0 to 7) { - let tag : bits(2) = (tw >> (2 * i))[1..0]; - if tag != 0b11 then { - let cleared : word = tw & ~(0x0003 << (2 * i)); - tw = cleared | (zero_extend(x87_class_tag(x87_ST[i])) << (2 * i)) - } - }; - tw -} - -// Push a value onto the x87 stack (decrement TOP, write to new ST(0)). -val x87_push : fp80 -> unit -function x87_push(v) = { - let new_top = x87_physical(-1); - x87_set_top(new_top); - x87_ST[new_top] = v; - x87_mark_valid(new_top) -} - -// Pop the top of the x87 stack (read ST(0), increment TOP). -val x87_pop : unit -> fp80 -function x87_pop() = { - let cur_top = x87_top(); - let result = x87_ST[cur_top]; - x87_mark_empty(cur_top); - x87_set_top(x87_physical(1)); - result -} - -// Mark ST(i) as empty (used by FFREE). -val x87_free : int -> unit -function x87_free(i) = x87_mark_empty(x87_physical(i)) - -// Whether ST(i) is tagged empty. -val x87_is_empty : int -> bool -function x87_is_empty(i) = (x87_tw >> (2 * x87_physical(i)))[1..0] == 0b11 - -// The real indefinite, a QNaN with the sign set and the significand -// 1100...0 (SDM Vol.1 §4.8.3.7, Table 4-3): the masked response of an -// x87 invalid operation. The packed BCD indefinite has the same bits. -let x87_indefinite : fp80 = 0xFFFFC000000000000000 - -// Decrement TOP (used by FDECSTP). -val x87_dec_top : unit -> unit -function x87_dec_top() = x87_set_top(x87_physical(-1)) - -// Increment TOP (used by FINCSTP). -val x87_inc_top : unit -> unit -function x87_inc_top() = x87_set_top(x87_physical(1)) - -// Initialize x87 state (used by FINIT/FNINIT). -val x87_init : unit -> unit -function x87_init() = { - x87_cw = 0x037F; - x87_sw = 0x0000; - x87_tw = 0xFFFF; - x87_fip = zeros(); - x87_fcs = zeros(); - x87_fop = zeros(); - x87_fdp = zeros(); - x87_fds = zeros(); - foreach (i from 0 to 7) { - x87_ST[i] = zeros() - } -} - -// FSW.ES (bit 7, error summary) and FSW.B (bit 15) are set exactly when an -// exception flag is set whose mask bit is clear. Loading either word -// recomputes them, as does unmasking a set flag (FLDCW). -val x87_update_es : unit -> unit -function x87_update_es() = { - let pending : bit = if (x87_sw[5..0] & ~(x87_cw[5..0])) != 0b000000 then bitone else bitzero; - x87_sw[7] = pending; - x87_sw[15] = pending -} - -// FCW bits 15:13 and 7:6 are reserved (SDM Vol.1 Figure 8-6 p.8-7; APM -// Vol.1 Figure 6-4 p.293, §6.2.3: "All bits, except reserved bits, can be -// read and written"), and neither manual says what they read after a -// load, so a load leaves them undefined. FNINIT and FNSAVE set the whole -// word to 037FH (SDM §8.1.5; x87_init). -val x87_set_cw : word -> unit -function x87_set_cw(cw) = { - x87_cw = (cw & 0x1F3F) | ((undefined : word) & 0xE0C0); - x87_update_es() -} - -val x87_set_sw : word -> unit -function x87_set_sw(sw) = { - x87_sw = sw; - x87_update_es() -} - -// The CPUID bits that select how the x87 pointers are kept and saved, each -// enumerated by one manual and reserved (0) in the other, and so three -// independent parameters: CPUID.(EAX=07H,ECX=0):EBX[6] FDP_EXCPTN_ONLY, "If -// 1, the x87 FPU Data Pointer is updated only on x87 exceptions", and -// EBX[13] FCS_FDS_DEPRECATION, "If 1, deprecates FPU CS and FPU DS values" -// (SDM Vol.1 Table 21-19 p.21-27, §8.1.8 p.8-9), and CPUID Fn8000_0008_EBX[2] -// RstrFpErrPtrs, "FP Error Pointers Restored by XRSTOR" (APM Vol.3 -// Appendix E p.659, Vol.2 §11.5.10 p.361). CPUID reports them as they are -// set, and x87_record_last, xsave_x87 and xrstor_x87 follow them; where a -// bit is 0, the value the other manual's rule then gives is open as well. -// The defaults are those of the processor the CPUID identifies -// ("GenuineIntel"); the KVM harness sets each from its host. -register has_fdp_excptn_only : bool = true -register has_fcs_fds_deprecation : bool = true -register has_rstr_fp_err_ptrs : bool = false - -// The FCS or FDS that FNSTENV, FNSAVE, FXSAVE and XSAVE write: "If -// CPUID.07H.00H:EBX[13] = 1, the processor deprecates FCS and FDS; it -// saves each as 0000H" (SDM Vol.1 §8.1.8). The loads take both from the -// image either way. -val x87_saved_selector : word -> word -function x87_saved_selector(sel) = if has_fcs_fds_deprecation then 0x0000 else sel - -// ========================================================================= -// MMX register access -// -// MMX registers MM0-MM7 alias the low 64 bits of the x87 physical registers -// ST(0)-ST(7), accessed by physical index (not relative to TOP). -// Writing an MMX register sets bits [79:64] to all ones and marks the tag -// as valid. All MMX instructions also set TOS (TOP) to 0 and mark all -// tag bits as valid (tag word = 0x0000). -// ========================================================================= - -// Called on any MMX instruction: set TOS=0, all tags=valid. -val mmx_touch : unit -> unit -function mmx_touch() = { - x87_sw[13..11] = 0b000; // TOP = 0 - x87_tw = 0x0000; // all valid - x87_mmx_last = true -} - -// Save the 28-byte x87 environment in the 32-bit protected-mode format -// (SDM Vol.1 Figure 8-9 p.8-11; APM Vol.2 Figure 11-4 p.352) as -// bits(224): FCW, FSW and FTW in the low halves of three doublewords, -// then FIP[31:0], FCS with FOP in bits 26:16 and 00000b above it, -// FDP[31:0], and FDS. The high halves of the FCW, FSW, FTW and FDS -// doublewords are reserved ("Reserved, IGN" in the APM) with no value -// given, so they are written undefined. -val x87_save_env : unit -> bits(224) -function x87_save_env() = { - var buf : bits(224) = zeros(); - buf[15..0] = x87_cw; - buf[31..16] = (undefined : word); - buf[47..32] = x87_sw; - buf[63..48] = (undefined : word); - buf[79..64] = x87_tag_word(); - buf[95..80] = (undefined : word); - buf[127..96] = x87_fip[31..0]; - buf[143..128] = x87_saved_selector(x87_fcs); - buf[154..144] = x87_fop; - buf[191..160] = x87_fdp[31..0]; - buf[207..192] = x87_saved_selector(x87_fds); - buf[223..208] = (undefined : word); - buf -} - -// Load the 28-byte x87 environment from bits(224), the inverse of -// x87_save_env. FCW is loaded first, so that FSW.ES reflects its masks. -val x87_load_env : bits(224) -> unit -function x87_load_env(buf) = { - x87_set_cw(buf[15..0]); - x87_set_sw(buf[47..32]); - x87_tw = buf[79..64]; - x87_fip = zero_extend(buf[127..96]); - x87_fcs = buf[143..128]; - x87_fop = buf[154..144]; - x87_fdp = zero_extend(buf[191..160]); - x87_fds = buf[207..192] -} - -// The 14-byte environment of a 16-bit operand size in protected mode -// (SDM Vol.1 §8.1.10, Figure 8-11 p.8-12; APM Vol.2 Figure 11-6 p.354): -// FCW, FSW, FTW, FIP[15:0], FCS, FDP[15:0] and FDS, without FOP. Loading -// it clears bits 63:32 of the two offsets ("loads the lower 32 bits from -// memory and clears the upper 32 bits", §8.1.8), of whose lower 32 the -// image holds 16. Neither manual gives bits 31:16 of the offsets, nor -// FOP, which the image does not have, a value: both are undefined. -val x87_save_env16 : unit -> bits(112) -function x87_save_env16() = - x87_saved_selector(x87_fds) @ x87_fdp[15..0] @ x87_saved_selector(x87_fcs) @ x87_fip[15..0] - @ x87_tag_word() @ x87_sw @ x87_cw - -val x87_load_env16 : bits(112) -> unit -function x87_load_env16(buf) = { - x87_set_cw(buf[15..0]); - x87_set_sw(buf[31..16]); - x87_tw = buf[47..32]; - x87_fip = zero_extend((undefined : word) @ buf[63..48]); - x87_fcs = buf[79..64]; - x87_fop = undefined; - x87_fdp = zero_extend((undefined : word) @ buf[95..80]); - x87_fds = buf[111..96] -} - -// The eight registers that follow the environment in an FSAVE image, in -// stack order: DEST[ST(i)] := ST(i) (SDM Vol.2A FSAVE/FNSAVE, Operation). -val x87_save_regs : unit -> bits(640) -function x87_save_regs() = { - var buf : bits(640) = zeros(); - foreach (i from 0 to 7) { - buf[(i * 80 + 79) .. (i * 80)] = x87_read_st(i) - }; - buf -} - -// ST(i) := SRC[ST(i)] (SDM Vol.2A FRSTOR, Operation), relative to the TOP -// of the environment loaded first. -val x87_load_regs : bits(640) -> unit -function x87_load_regs(buf) = { - foreach (i from 0 to 7) { - x87_ST[x87_physical(i)] = buf[(i * 80 + 79) .. (i * 80)] - } -} - -// ========================================================================= -// SIMD registers (XMM/YMM/ZMM) -// -// We model the full 512-bit ZMM registers. XMM and YMM access the -// low 128 and 256 bits respectively. -// x86-64 has 16 registers (0-15), AVX-512 extends to 32. -// ========================================================================= - -type simd_idx = range(0, 31) - -register ZMM : vector(32, zmmword) - -// Polymorphic SIMD read by vector length. -val read_simd : forall 'vl, 'vl in {128, 256, 512}. (implicit('vl), simd_idx) -> bits('vl) -function read_simd(vl, idx) = match vl { - 128 => ZMM[idx][127..0], - 256 => ZMM[idx][255..0], - 512 => ZMM[idx] -} - -// Polymorphic SIMD write by vector length (zeros upper bits). -val write_simd : forall 'vl, 'vl in {128, 256, 512}. (implicit('vl), simd_idx, bits('vl)) -> unit -function write_simd(vl, idx, v) = match vl { - 128 => { ZMM[idx][511..128] = zeros(); ZMM[idx][127..0] = v }, - 256 => { ZMM[idx][511..256] = zeros(); ZMM[idx][255..0] = v }, - 512 => ZMM[idx] = v -} - -// ========================================================================= -// AVX-512 Opmask registers (k0-k7) -// -// k0 is special: when used as a writemask, it means "no masking" (all 1s). -// k1-k7 are general-purpose mask registers. -// ========================================================================= - -type kreg_idx = range(0, 7) - -register KREG : vector(8, qword) - -val read_kreg : kreg_idx -> qword -function read_kreg(idx) = KREG[idx] - -val write_kreg : (kreg_idx, qword) -> unit -function write_kreg(idx, v) = KREG[idx] = v - -// ========================================================================= -// Segment registers -// ========================================================================= - -register SegReg : vector(6, word) - -// Segment descriptor caches (hidden part of each segment register). -// Per SDM Vol.3A §3.4.3, loaded from GDT/LDT on segment register write. -register SegCache : vector(6, SegDescCache) - -val read_segreg : segreg_idx -> word -function read_segreg(idx) = SegReg[idx] - -val write_segreg : (segreg_idx, word) -> unit -function write_segreg(idx, v) = SegReg[idx] = v - -// Kernel GS base (shadow register swapped with SegCache[GS].seg_base by SWAPGS). -register KERNEL_GS_BASE : qword - -// ========================================================================= -// Descriptor table registers -// ========================================================================= - -register GDTR_base : qword -register GDTR_limit : word -register IDTR_base : qword -register IDTR_limit : word -register LDTR : word // LDT selector -register LDTR_base : qword -register LDTR_limit : dword -register LDTR_valid : bool = false -register TR : word // Task register selector - -// TSS base and limit (loaded from GDT when LTR executes) -register TR_base : qword -register TR_limit : dword -// Hidden TSS descriptor type, retained by LTR (SDM Vol.3A section 10.2.4). -register TR_type : bits(4) = 0xB - -// ========================================================================= -// Segment descriptor cache helpers -// ========================================================================= - -// Get the linear base address of a segment. -// In LongMode, ES/CS/SS/DS are treated as base 0 (SDM Vol.3A §3.4.4); -// FS and GS bases are stored in SegCache (set via MSR or descriptor load). -// In other modes, all segment bases come from the descriptor cache. -val get_seg_base : segreg_idx -> qword -function get_seg_base(seg) = - if cur_mode == LongMode & seg != FS & seg != GS - then 0x0000000000000000 - else SegCache[seg].seg_base - -// Get the CS.D bit (default operation size). -// Returns 0b1 when CS.D=1 (32-bit default), 0b0 when CS.D=0 (16-bit). -val get_cs_db : unit -> bit -function get_cs_db() = SegCache[CS].seg_db - -// Parse an 8-byte segment descriptor into a SegDescCache (SDM Vol.3A §3.4.5). -// lo = descriptor bytes [3:0], hi = descriptor bytes [7:4]. -val parse_seg_descriptor : (dword, dword) -> SegDescCache -function parse_seg_descriptor(lo, hi) = { - // Base address: hi[31:24] @ hi[7:0] @ lo[31:16] - let base : dword = hi[31..24] @ hi[7..0] @ lo[31..16]; - // Limit: hi[19:16] @ lo[15:0] (20-bit raw limit) - let raw_limit : bits(20) = hi[19..16] @ lo[15..0]; - // Granularity: if G=1, scale limit by 4KB (shift left 12, fill low bits) - let g : bit = hi[23]; - let limit : dword = if g == 0b1 then zero_extend(raw_limit) @ 0xFFF - else zero_extend(raw_limit); - struct { - seg_base = zero_extend(base), - seg_limit = limit, - seg_type = hi[11..8], - seg_s = hi[12], - seg_dpl = unsigned(hi[14..13]), - seg_present = hi[15], - seg_db = hi[22], - seg_l = hi[21], - seg_g = g, - } -} - -// load_segment_register is defined in mem.sail (needs mem_read32). - -// ========================================================================= -// Decode position -// -// Tracks the current position in the instruction stream during decoding. -// Placed here (rather than in decode/) so instruction implementations -// can access it for control-flow instructions (CALL, JMP, RET, Jcc). -// ========================================================================= - -register decode_pos : qword - -// Start of current instruction (set to RIP at beginning of step()). -// Used to enforce the 15-byte maximum instruction length. -register insn_start : qword - -// Instruction buffer for Isla symbolic execution. -// Holds up to 15 instruction bytes (120 bits) in little-endian order: -// bits [7..0] = byte at offset 0, bits [15..8] = byte at offset 1, etc. -// The splice file overrides fetch() to read from this register -// instead of memory, because Isla's symbolic memory model does not -// connect writes to subsequent reads at the same address. -register insn_buf : bits(120) = zeros() - -// Output register for ISLA equivalence proofs. -register Final_result : bits(128) = zeros() - -// Symbolic data-memory window for ISLA equivalence proofs: 256 bytes at -// 0x7000. The splice file routes phys_read/phys_write here so that a -// load at a concrete address is a shared symbolic input. Unused by the -// emulator. -register mem_window : bits(2048) - -// RIP-relative fixup state: when modrm_rm sees mod=00 rm=101 (RIP+disp32), -// it saves decode_pos after consuming the displacement bytes. If the -// instruction has trailing bytes (imm8, imm32), decode_pos will advance -// further. The fixup delta (decode_pos - rip_rel_saved_pos) is added to -// the preliminary RM_mem address at use time. -register rip_rel_pending : bool -register rip_rel_disp : qword - -// VSIB (Vector SIB) addressing info for gather/scatter -struct VSIB = { - vsib_base : qword, // base address (GPR + displacement) - vsib_vidx : simd_idx, // vector register containing indices - vsib_scale : range(0, 3), // scale factor (0=1, 1=2, 2=4, 3=8) - vsib_seg : segreg_idx, // segment of the accesses - vsib_addr64 : bool, // 64-bit addresses (else 32-bit) -} - -// ========================================================================= -// Control registers (system-level) -// ========================================================================= - -register CR0 : qword // PE, PG, WP, etc. -register CR2 : qword // Page Fault Linear Address -register CR3 : qword // Page table base -register CR4 : qword // PAE, PSE, OSFXSR, OSXSAVE, etc. -register CR8 : bits(4) // Task Priority Register (TPR), bits 3:0 -register EFER : qword // Extended Feature Enable Register - -// Debug registers -// Default values are specified by SDM -register DR0 : qword = 0x0000000000000000 // Linear breakpoint address 0 -register DR1 : qword = 0x0000000000000000 // Linear breakpoint address 1 -register DR2 : qword = 0x0000000000000000 // Linear breakpoint address 2 -register DR3 : qword = 0x0000000000000000 // Linear breakpoint address 3 -register DR6 : qword = 0x00000000FFFF0FF0 // Debug status -register DR7 : qword = 0x0000000000000400 // Debug control - -// Single-step bookkeeping, maintained by step() and deliver_exception -// (SDM Vol.3B §20.3.1.4, Vol.3A §7.8.3): -// event_delivered — an exception or interrupt went through the IDT during -// the current instruction (INT n, INT3, INTO, INT1, a -// fault); such an instruction gets no single-step trap. -// ss_shadow — 2 right after MOV SS/POP SS, 1 through the following -// instruction, 0 otherwise: suppresses the trap after the -// SS load and holds external interrupts until after the -// next instruction. -register event_delivered : bool = false -register ss_shadow : range(0, 2) = 0 -// STI delays maskable interrupts through the following instruction, but -// unlike MOV SS it does not suppress debug traps. -register sti_shadow : range(0, 2) = 0 - -// Data-breakpoint bookkeeping (SDM Vol.3B §20.3.1.2), maintained by the -// memory interface, exec_rep and step(): -// pending_dbp — Bn of the data breakpoints hit by the current -// instruction's accesses; reported as a trap after it, -// kept across a MOV SS/POP SS and delivered after the -// following instruction, lost on a fault. -// open_dbp — Bn of the breakpoints the accesses match although -// neither Ln nor Gn enables them: "They may or may not be -// set if the breakpoint is not enabled" (§20.2.3 p.20-4), -// where the APM clears them (Vol.2 §13.1.1.3 p.394), so -// they are undefined in the DR6 of the trap. -// rep_trap_rf — a repeated string instruction stopped after an -// iteration that is not its last (data breakpoint or single -// step): RF in the trap's RFLAGS image is undefined (see -// step()). -register pending_dbp : bits(4) = 0x0 -register open_dbp : bits(4) = 0x0 -register rep_trap_rf : bool = false - -// CR0 bit positions -let CR0_PE : int = 0 // Protection Enable -let CR0_MP : int = 1 // Monitor Coprocessor -let CR0_EM : int = 2 // Emulation -let CR0_TS : int = 3 // Task Switched -let CR0_ET : int = 4 // Extension Type -let CR0_NE : int = 5 // Numeric Error -let CR0_WP : int = 16 // Write Protect -let CR0_AM : int = 18 // Alignment Mask -let CR0_NW : int = 29 // Not Write-through -let CR0_CD : int = 30 // Cache Disable -let CR0_PG : int = 31 // Paging - -// CR4 bit positions -let CR4_VME : int = 0 // Virtual-8086 Mode Extensions -let CR4_PVI : int = 1 // Protected-Mode Virtual Interrupts -let CR4_TSD : int = 2 // Time Stamp Disable -let CR4_DE : int = 3 // Debugging Extensions -let CR4_PSE : int = 4 // Page Size Extensions -let CR4_PAE : int = 5 // Physical Address Extension -let CR4_MCE : int = 6 // Machine-Check Enable -let CR4_PGE : int = 7 // Page Global Enable -let CR4_PCE : int = 8 // Performance-Monitoring Counter Enable -let CR4_OSFXSR : int = 9 // OS Support for FXSAVE/FXRSTOR -let CR4_OSXMMEXCPT : int = 10 // OS Support for Unmasked SIMD FP Exceptions -let CR4_LA57 : int = 12 // 5-Level Paging -let CR4_FSGSBASE : int = 16 // FSGSBASE Enable -let CR4_PCIDE : int = 17 // PCID Enable -let CR4_VMXE : int = 13 // VMX Enable -let CR4_OSXSAVE : int = 18 // XSAVE and Processor Extended States Enable - -// EFER bit positions -let EFER_SCE : int = 0 // SYSCALL Enable -let EFER_LME : int = 8 // Long Mode Enable -let EFER_LMA : int = 10 // Long Mode Active -let EFER_NXE : int = 11 // No-Execute Enable - -// ========================================================================= -// Extended Control Register 0 (XCR0) and CPUID feature flags -// -// XCR0 controls OS-level enabling of XSAVE-managed state components. -// XCR0_SUPPORTED defines the hardware (silicon) mask; XCR0 <= XCR0_SUPPORTED. -// CPUID feature flags model silicon-fixed features (BMI, POPCNT, etc.). -// All are set at init time; Isla treats them as constants. -// ========================================================================= - -register XCR0 : qword // Extended Control Register 0 (OS-enabled state) -register XCR0_SUPPORTED : qword // Which XCR0 bits this "CPU" supports (silicon mask) - -// XCR0 bit position constants (SDM Table 13-1) -let XCR0_X87 : int = 0 -let XCR0_SSE : int = 1 -let XCR0_AVX : int = 2 -let XCR0_OPMASK : int = 5 -let XCR0_ZMM_HI256 : int = 6 -let XCR0_HI16_ZMM : int = 7 -let XCR0_TILECFG : int = 17 -let XCR0_TILEDATA : int = 18 - -// CPUID feature flag registers (concrete booleans, set at init) -register has_sse3 : bool // CPUID.01H:ECX[0] -register has_ssse3 : bool // CPUID.01H:ECX[9] -register has_sse4_1 : bool // CPUID.01H:ECX[19] -register has_sse4_2 : bool // CPUID.01H:ECX[20] -register has_cx16 : bool // CPUID.01H:ECX[13] — CMPXCHG16B -register has_popcnt : bool -register has_lzcnt : bool -register has_bmi1 : bool -register has_bmi2 : bool -register has_fma : bool -register has_aesni : bool -register has_pclmulqdq : bool -register has_vpclmulqdq : bool // CPUID.07H:ECX[10] — VEX.256 and EVEX VPCLMULQDQ -register has_vaes : bool // CPUID.07H:ECX[9] — VEX.256 and EVEX VAESENC/VAESENCLAST/VAESDEC/VAESDECLAST -register has_gfni : bool // CPUID.07H:ECX[8] — GF2P8AFFINEQB/GF2P8AFFINEINVQB/GF2P8MULB in every encoding -register has_avx_vnni : bool // CPUID.(07H,1):EAX[4] — VEX VPDPBUSD/VPDPBUSDS/VPDPWSSD/VPDPWSSDS -register has_f16c : bool -register has_movbe : bool -register has_adx : bool -register has_sha : bool -register has_rdrand : bool -register has_rdseed : bool -register has_rdpid : bool // CPUID.07H:ECX[22] — RDPID (F3 0F C7 /7) -register has_crc32 : bool -register has_movdiri : bool -register has_movdir64b : bool -register has_enqcmd : bool // CPUID.07H:ECX[29] — ENQCMD, ENQCMDS and IA32_PASID -register has_xsave : bool // XSAVE/XRSTOR, XSETBV/XGETBV, XCR0 (CPUID.01H:ECX[26]) -// The AVX-512 extensions, each its own CPUID bit (SDM Vol.1 Tables 21-19 -// to 21-22, pp. 21-27 to 21-30), which the model reports in leaf 7 and -// whose instructions are #UD without it ("If any corresponding CPUID -// feature flag is '0'", Vol.2A Table 2-46 and the other EVEX exception -// classes; "If relevant CPUID feature flag is '0'", Tables 2-65 and 2-66 -// of the opmask instructions). evex_extension in insn_evex_forms.sail -// gives each EVEX form its extension; AVX512VL adds the 128- and 256-bit -// forms of the instructions that have a 512-bit form. -register has_avx512f : bool // CPUID.07H:EBX[16] -register has_avx512dq : bool // CPUID.07H:EBX[17] -register has_avx512_ifma : bool // CPUID.07H:EBX[21] -register has_avx512pf : bool // CPUID.07H:EBX[26] — VGATHERPF*, VSCATTERPF* (Xeon Phi) -register has_avx512er : bool // CPUID.07H:EBX[27] — VEXP2*, VRCP28*, VRSQRT28* (Xeon Phi) -register has_avx512cd : bool // CPUID.07H:EBX[28] -register has_avx512bw : bool // CPUID.07H:EBX[30] -register has_avx512vl : bool // CPUID.07H:EBX[31] -register has_avx512_vbmi : bool // CPUID.07H:ECX[1] -register has_avx512_vbmi2 : bool // CPUID.07H:ECX[6] -register has_avx512_vnni : bool // CPUID.07H:ECX[11] — EVEX VPDPBUSD/VPDPBUSDS/VPDPWSSD/VPDPWSSDS -register has_avx512_bitalg : bool // CPUID.07H:ECX[12] -register has_avx512_vpopcntdq : bool // CPUID.07H:ECX[14] -register has_avx512_vp2intersect : bool // CPUID.07H:EDX[8] -// The XSAVE extensions of CPUID.(0DH,1):EAX (SDM Vol.1 §13.2 p.13-3, -// Table 21-35): "If EAX[0] = 0, execution of XSAVEOPT causes an -// invalid-opcode exception (#UD)"; EAX[1], "the compacted format", XSAVEC -// and "the compacted form of XRSTOR"; EAX[2], XGETBV with ECX = 1; EAX[3], -// XSAVES, XRSTORS and IA32_XSS ("an attempt to access the IA32_XSS MSR -// using RDMSR or WRMSR causes a general-protection exception (#GP)" -// without it); EAX[4], extended feature disable (§13.14: IA32_XFD and -// IA32_XFD_ERR). -register has_xsaveopt : bool -register has_xsavec : bool -register has_xgetbv1 : bool -register has_xsaves : bool -register has_xfd : bool -register has_avx512_fp16 : bool // CPUID.07H:EDX[23] — AVX512-FP16 (EVEX maps 5 and 6, and 0F3A forms) -register has_avx512_bf16 : bool // CPUID.(07H,1):EAX[5] -register has_la57 : bool // CPUID.07H:ECX[16] — 5-Level Paging -register has_vmx : bool // CPUID.01H:ECX[5] — VMX support -register has_amx_tile : bool // CPUID.07H:EDX[24] — AMX tile architecture (LDTILECFG, TILELOADD, ...) -register has_amx_int8 : bool // CPUID.07H:EDX[25] — TDPBSSD/TDPBSUD/TDPBUSD/TDPBUUD -register has_amx_bf16 : bool // CPUID.07H:EDX[22] — TDPBF16PS -register has_prefetchw : bool // CPUID.80000001H:ECX[8] — PREFETCHW (0F 0D /1; a NOP either way) -register has_cldemote : bool // CPUID.07H:ECX[25] — CLDEMOTE (0F 1C /0; a NOP either way) -register has_waitpkg : bool // CPUID.07H:ECX[5] — TPAUSE, UMONITOR, UMWAIT and IA32_UMWAIT_CONTROL -// SMAP (CPUID.07H:EBX[20]): CLAC and STAC are #UD without it (SDM Vol.2A -// CLAC, Vol.2B STAC; APM Vol.3 CLAC, STAC). The model has the -// instructions but not CR4.SMAP's access checks, so no profile sets it; -// the KVM harness gives it the guest's value. -register has_smap : bool -// PTWRITE (F3 0F AE /4) is #UD unless CPUID.(14H,0):EBX[4] = 1 (SDM Vol.2B -// PTWRITE), a leaf of Intel PT, which CPUID.07H:EBX[25] reports (SDM -// §36.3.1). The model has no processor trace (no IA32_RTIT_* MSRs), so -// no profile sets it; the KVM harness gives it the host's value, as the -// guest executes PTWRITE natively. -register has_ptwrite : bool -// AMD SSE4A (EXTRQ, INSERTQ, MOVNTSS, MOVNTSD) is #UD unless CPUID -// Fn8000_0001_ECX[SSE4A] (bit 6) = 1 (AMD APM Vol.4 EXTRQ, INSERTQ, -// MOVNTSD, MOVNTSS). The profiles describe the "GenuineIntel" processor -// the CPUID presents, so none sets it; the KVM harness gives it the -// host's value. -register has_sse4a : bool -// AMD Misaligned SSE mode, CPUID Fn8000_0001_ECX[MisAlignSse] (bit 7; -// APM Vol.3 Appendix E p.649): MXCSR.MM (bit 17) then exists and masks the -// #GP of a misaligned legacy SSE memory operand (check_sse_src_alignment -// in insn_modrm.sail; APM Vol.1 §4.2.2 p.118, §4.3.2 p.120). "The -// corresponding MXCSR_MASK bit (17) is 1", so a machine with it reports -// that bit in MXCSR_MASK as well. No enable_features_* profile sets it; -// the KVM harness sets it, and MXCSR_MASK, from the host. -register has_misalignsse : bool - -// MXCSR_MASK, the value FXSAVE and XSAVE store at bytes 31:28 of the -// legacy region: "All bits set to 0 in the MXCSR_MASK value indicate -// reserved bits in the MXCSR register", which LDMXCSR, FXRSTOR and XRSTOR -// may not set (#GP(0)), and "If the value of the MXCSR_MASK field is -// 00000000H, then the MXCSR_MASK value is the default value of 0000FFBFH" -// (SDM Vol.1 §11.6.6 p.11-21; APM Vol.2 §11.5.10 p.364). The value is the -// implementation's, which software reads from an FXSAVE image; the KVM -// harness sets the host's. The default is bits 15:0, DAZ included. -register MXCSR_MASK : dword = 0x0000FFFF - -// The XSAVE layout of the user state components the model implements: -// 2 (AVX), 5-7 (AVX-512) and 17-18 (AMX). For each, CPUID.(0DH,i) "EAX -// enumerates the size (in bytes) required for state component i", "EBX -// enumerates the offset (in bytes, from the base of the XSAVE area) of the -// section used for state component i" in the standard format, and "If -// ECX[1] returns 1, state component i is located on the next 64-byte -// boundary following the preceding state component" in the compacted one -// (SDM Vol.1 §13.2 p.13-4, §13.4.3; APM Vol.2 §11.5.3, Table 11-6). -// Neither manual fixes the offsets or the alignment, so they are the -// implementation's; the KVM harness sets the host's. Indexed by -// component; a component the processor does not support has size 0. -register xsave_comp_size : vector(19, dword) -register xsave_comp_offset : vector(19, dword) -register xsave_comp_align : vector(19, bool) - -val set_xsave_component : (range(0, 18), int, int, bool) -> unit -function set_xsave_component(i, size, offset, align) = { - xsave_comp_size[i] = get_slice_int(32, size, 0); - xsave_comp_offset[i] = get_slice_int(32, offset, 0); - xsave_comp_align[i] = align -} - -// The user-level monitor of UMONITOR/UMWAIT (SDM Vol.2B): armed by -// UMONITOR, consumed by UMWAIT. Stores to the monitored range are not -// tracked; UMWAIT is taken to run to its deadline, which the SDM allows. -register umonitor_armed : bool = false - -// IA32_PASID (D93H; SDM Vol.2A ENQCMD, and Vol.4 Table 2-2): bits 19:0 -// hold the process address space identifier that ENQCMD puts in bits 19:0 -// of its command, bit 31 whether it is valid (ENQCMD is #GP(0) while it is -// 0); bits 30:20 and 63:32 are reserved. The MSR exists with ENQCMD. The -// model starts it at 0, no valid PASID, as a thread that was given none -// has it (a KVM guest, which cannot write it, runs with that value). -// XSAVES and XRSTORS manage it as supervisor state component 10, PASID -// state (CPUID.0DH.01H:ECX[10]), which the model does not implement: -// IA32_XSS supports no component. -register IA32_PASID : qword = zeros() - -// ========================================================================= -// Intel AMX tile state (SDM Vol.1 Chapter 19) -// -// Palette 1, the only non-INIT palette, has eight tiles of at most 16 rows -// by 64 bytes (CPUID.1DH.01H). TILECFG holds the palette, the restart row -// of an interrupted tile load or store, and each tile's shape; a tile whose -// rows and colsb are both zero is not valid. TMM holds the rows, tile t -// row r at index 16 * t + r. TILES_CONFIGURED of the SDM is -// tilecfg_palette != 0. XSAVE manages TILECFG as component 17 and the -// 8 KB of tile data as component 18. -// ========================================================================= - -register tilecfg_palette : byte = 0x00 -register tilecfg_start_row : byte = 0x00 -register tilecfg_colsb : vector(8, word) -register tilecfg_rows : vector(8, byte) -register TMM : vector(128, zmmword) - -// Extended feature disable (SDM Vol.1 §13.14; CPUID.0DH.01H:EAX[4]): -// IA32_XFD (1C4H) disables the state components whose bits it and XCR0 -// both have, and IA32_XFD_ERR (1C5H) names the components an instruction -// faulted on (#NM). Only bit 18 (TILEDATA) can be set (xfd_supported in -// insn_xsave.sail); both reset to zero. -register IA32_XFD : qword = zeros() -register IA32_XFD_ERR : qword = zeros() - -// zero_all_tile_data of the SDM. -val amx_zero_all_tiles : unit -> unit -function amx_zero_all_tiles() = { - foreach (i from 0 to 127) { - TMM[i] = zeros() - } -} - -// TILECFG in its INIT state: palette 0, TILES_CONFIGURED = 0. -val amx_init_tilecfg : unit -> unit -function amx_init_tilecfg() = { - tilecfg_palette = 0x00; - tilecfg_start_row = 0x00; - foreach (n from 0 to 7) { - tilecfg_colsb[n] = 0x0000; - tilecfg_rows[n] = 0x00 - } -} - -// ========================================================================= -// XCR0 / feature check helpers -// ========================================================================= - -// AVX enabled: CR4.OSXSAVE(bit 18)=1 and XCR0.SSE(bit 1)=1, AVX(bit 2)=1 -val avx_enabled : unit -> bool -function avx_enabled() = - CR4[18] == 0b1 & XCR0[2] == 0b1 & XCR0[1] == 0b1 - -// The state requirement of the AVX-512 instructions, the EVEX-encoded and -// the opmask ones: "software can execute Intel AVX-512 instructions only -// if CR4.OSXSAVE = 1 and XCR0[7:5] = 111b. Otherwise, any execution of an -// Intel AVX-512 instruction causes an invalid-opcode exception (#UD)" -// (SDM Vol.1 §13.3, p. 13-5; Vol.2A Table 2-39: "111xx111b", and -// "111xxx11b" for the opmask instructions, a difference XSETBV leaves no -// room for: it allows XCR0[7:5] = 111b only with XCR0[2:1] = 11b, §13.3). -// Their CPUID features are checked per instruction (evex_check_form, -// vex_check_form). -val avx512_enabled : unit -> bool -function avx512_enabled() = - avx_enabled() & XCR0[5] == 0b1 & XCR0[6] == 0b1 & XCR0[7] == 0b1 - -// ========================================================================= -// Convenience functions: configure features by processor level -// ========================================================================= - -// x86-64-v1: Baseline 64-bit (SSE2 only, no extensions) -val enable_features_v1 : unit -> unit -function enable_features_v1() = { - // CR0: clear EM, set MP - CR0 = (CR0 & 0xFFFFFFFFFFFFFFFB) | 0x0000000000000002; - // CR4: OSFXSR + OSXMMEXCPT - CR4 = CR4 | 0x0000000000000600; - XCR0_SUPPORTED = 0x0000000000000003; // x87 + SSE - XCR0 = 0x0000000000000003; - // All CPUID features off - has_sse3 = false; - has_ssse3 = false; - has_sse4_1 = false; - has_sse4_2 = false; - has_cx16 = false; - has_popcnt = false; - has_lzcnt = false; - has_bmi1 = false; - has_bmi2 = false; - has_fma = false; - has_aesni = false; - has_pclmulqdq = false; - has_vpclmulqdq = false; - has_vaes = false; - has_gfni = false; - has_avx_vnni = false; - has_f16c = false; - has_movbe = false; - has_adx = false; - has_sha = false; - has_rdrand = false; - has_rdseed = false; - has_rdpid = false; - has_crc32 = false; - has_movdiri = false; - has_movdir64b = false; - has_enqcmd = false; - has_xsave = false; - has_avx512f = false; - has_avx512dq = false; - has_avx512_ifma = false; - has_avx512pf = false; - has_avx512er = false; - has_avx512cd = false; - has_avx512bw = false; - has_avx512vl = false; - has_avx512_vbmi = false; - has_avx512_vbmi2 = false; - has_avx512_vnni = false; - has_avx512_bitalg = false; - has_avx512_vpopcntdq = false; - has_avx512_vp2intersect = false; - has_xsaveopt = false; - has_xsavec = false; - has_xgetbv1 = false; - has_xsaves = false; - has_xfd = false; - has_avx512_fp16 = false; - has_avx512_bf16 = false; - has_vmx = false; - has_la57 = false; - has_amx_tile = false; - has_amx_int8 = false; - has_amx_bf16 = false; - has_prefetchw = false; - has_cldemote = false; - has_ptwrite = false; - has_sse4a = false; - has_misalignsse = false; - has_waitpkg = false; - MXCSR_MASK = 0x0000FFFF; - // No extended state component: x87 and SSE are in the legacy region. - foreach (i from 0 to 18) { - set_xsave_component(i, 0, 0, false) - } -} - -// x86-64-v2: Nehalem+ (SSE4.2, POPCNT, CMPXCHG16B) -val enable_features_v2 : unit -> unit -function enable_features_v2() = { - enable_features_v1(); - has_sse3 = true; - has_ssse3 = true; - has_sse4_1 = true; - has_sse4_2 = true; - has_cx16 = true; - has_xsave = true; - has_xsaveopt = true; - has_xsavec = true; - has_xgetbv1 = true; - has_xsaves = true; - has_popcnt = true; - has_crc32 = true; - has_pclmulqdq = true; - has_vmx = true -} - -// x86-64-v3: Haswell+ (AVX2, FMA, BMI1/2, MOVBE, F16C) -val enable_features_v3 : unit -> unit -function enable_features_v3() = { - enable_features_v2(); - CR4 = CR4 | 0x0000000000040000; // OSXSAVE - XCR0_SUPPORTED = 0x0000000000000007; // x87 + SSE + AVX - XCR0 = 0x0000000000000007; - // The extended region starts right after the 64-byte header. - set_xsave_component(2, 256, 576, false); - has_bmi1 = true; - has_bmi2 = true; - has_fma = true; - has_lzcnt = true; - has_f16c = true; - has_movbe = true; - has_rdrand = true; - has_aesni = true; - has_adx = true; - has_prefetchw = true // Broadwell and later -} - -// x86-64-v4 and everything above it that the model implements: AVX-512 -// (F/CD/BW/DQ/VL, IFMA, VBMI, VBMI2, VNNI, BITALG, VPOPCNTDQ, -// VP2INTERSECT, FP16, BF16), SHA, RDSEED, GFNI, VAES, VPCLMULQDQ, AVX-VNNI -val enable_features_v4 : unit -> unit -function enable_features_v4() = { - enable_features_v3(); - XCR0_SUPPORTED = 0x00000000000000E7; // + opmask + ZMM_Hi256 + Hi16_ZMM - XCR0 = 0x00000000000000E7; - // The places of the MPX components 3 and 4 (960 and 1024, 64 bytes - // each) stay unused. - set_xsave_component(5, 64, 1088, false); - set_xsave_component(6, 512, 1152, false); - set_xsave_component(7, 1024, 1664, false); - has_avx512f = true; - has_avx512dq = true; - has_avx512_ifma = true; - has_avx512cd = true; - has_avx512bw = true; - has_avx512vl = true; - has_avx512_vbmi = true; - has_avx512_vbmi2 = true; - has_avx512_vnni = true; - has_avx512_bitalg = true; - has_avx512_vpopcntdq = true; - has_avx512_vp2intersect = true; - has_avx512_fp16 = true; - has_avx512_bf16 = true; - has_rdseed = true; - has_rdpid = true; - has_sha = true; - has_vpclmulqdq = true; - has_vaes = true; - has_gfni = true; - has_avx_vnni = true -} - -// Everything the model implements: x86-64-v4 plus Intel AMX (AMX-TILE, -// AMX-INT8, AMX-BF16), whose tile state XCR0 bits 17 and 18 enable, and -// AVX512ER and AVX512PF, the extensions of the Xeon Phi processors only -// (SDM Vol.1 Table 21-19). -val enable_features_all : unit -> unit -function enable_features_all() = { - enable_features_v4(); - XCR0_SUPPORTED = XCR0_SUPPORTED | 0x0000000000060000; // + TILECFG + TILEDATA - XCR0 = XCR0 | 0x0000000000060000; - has_avx512er = true; - has_avx512pf = true; - // After the PKRU component (9, 2688, 8 bytes), each 64-byte aligned in - // the compacted format. - set_xsave_component(17, 64, 2752, true); - set_xsave_component(18, 8192, 2816, true); - has_xfd = true; - has_amx_tile = true; - has_amx_int8 = true; - has_amx_bf16 = true; - has_cldemote = true; - has_waitpkg = true; - has_enqcmd = true -} - -// ========================================================================= -// System mode flag -// -// When true, faults are delivered via IDT (system-level emulation). -// When false, faults return to the C++ harness (user-mode emulation). -// ========================================================================= - -register system_mode : bool - -// Exception delivery nesting depth (0 = normal, 1 = delivering, 2 = double fault) -// Used to detect double fault and triple fault conditions. -register exception_depth : range(0, 3) - -// Class of the exception currently being delivered (for escalation decisions). -register delivering_exc_class : ExceptionClass - -// ========================================================================= -// System Management Mode (SMM) — SDM Vol.3C Chapter 34 -// -// in_smm: true when the processor is in SMM. RSM is only valid in SMM. -// smbase: base physical address of SMRAM. Default 0x30000 after reset. -// Updated from SMRAM state save area (offset 7EF8h) on each RSM. -// ========================================================================= - -register in_smm : bool = false -register smbase : dword = 0x00030000 - -// ========================================================================= -// VMX (VT-x) State — SDM Vol.3C Chapter 24 -// -// in_vmx_root: true when in VMX root operation (hypervisor) -// in_vmx_non_root: true when in VMX non-root operation (guest) -// vmcs_ptr: physical address of the current VMCS (None if no current VMCS) -// vmxon_region_pa: physical address of the VMXON region -// vmcs: cached VMCS data (serialized to memory by VMCLEAR) -// ========================================================================= - -register in_vmx_root : bool = false -register in_vmx_non_root : bool = false -register vmcs_ptr : option(qword) = None() -register vmxon_region_pa : qword = zeros() -register vmcs : VMCS_data = default_vmcs() - -// IA32_FEATURE_CONTROL MSR (0x3A) -// Bit 0: Lock — once set, WRMSR to this MSR causes #GP(0) -// Bit 1: Enable VMX in SMX operation -// Bit 2: Enable VMX outside SMX operation -// Default: locked + VMX-outside-SMX enabled (bits 0 and 2) -register ia32_feature_control : qword = 0x0000000000000005 - -// Cached EPT-active flag. Set by vm_entry(), cleared by complete_vm_exit(). -// Avoids re-reading VMCS control bits on every phys_read/phys_write. -register ept_active : bool = false - -// ========================================================================= -// A20 gate -// -// When disabled, physical address bit 20 is forced to zero, causing -// the 1MB address space to wrap around (real-mode compatibility). -// On reset, A20 is disabled. Enabled via port 0x92 or keyboard controller. -// ========================================================================= - -register a20_enabled : bool = false diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail b/crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail deleted file mode 100644 index 530361b0d..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/rflags.sail +++ /dev/null @@ -1,222 +0,0 @@ -// x86-64 — RFLAGS Register and Flag Computation - -// RFLAGS register. We model individual flags as separate registers -// for clarity, since different instructions update different subsets. - -register CF : bit // Carry Flag -register PF : bit // Parity Flag -register AF : bit // Auxiliary Carry Flag -register ZF : bit // Zero Flag -register SF : bit // Sign Flag -register OF : bit // Overflow Flag -register DF : bit // Direction Flag -register IF_flag : bit // Interrupt Enable Flag (IF is a Sail keyword) -register TF : bit // Trap Flag -register IOPL : bits(2) // I/O Privilege Level -register NT : bit // Nested Task -register RF : bit // Resume Flag -register VIF : bit = 0b0 // Virtual Interrupt Flag -register VIP : bit = 0b0 // Virtual Interrupt Pending -register ID : bit // ID Flag (CPUID available if toggleable) -register AC_flag : bit // Alignment Check flag - -// Pack individual flags into a 64-bit RFLAGS value. -// Bits: 0=CF, 1=1(reserved), 2=PF, 4=AF, 6=ZF, 7=SF, 8=TF, 9=IF, 10=DF, -// 11=OF, 13:12=IOPL, 14=NT, 16=RF, 17=VM, 18=AC, 19=VIF, 20=VIP, 21=ID -val read_rflags : unit -> qword -function read_rflags() = { - var r : qword = zeros(); - r[0] = CF; - r[1] = 0b1; // reserved, always 1 - r[2] = PF; - r[4] = AF; - r[6] = ZF; - r[7] = SF; - r[8] = TF; - r[9] = IF_flag; - r[10] = DF; - r[11] = OF; - r[13..12] = IOPL; - r[14] = NT; - r[16] = RF; - r[17] = if cur_mode == Virtual8086Mode then bitone else bitzero; - r[18] = AC_flag; - r[19] = VIF; - r[20] = VIP; - r[21] = ID; - r -} - -// Write all individual flags from a packed RFLAGS value. -// This sets CF, PF, AF, ZF, SF, TF, IF, DF, OF, IOPL, NT, AC, ID. -// RF, VM, VIF and VIP are NOT set (they have special handling). -val write_rflags : qword -> unit -function write_rflags(v) = { - CF = v[0]; - PF = v[2]; - AF = v[4]; - ZF = v[6]; - SF = v[7]; - TF = v[8]; - IF_flag = v[9]; - DF = v[10]; - OF = v[11]; - IOPL = v[13..12]; - NT = v[14]; - AC_flag = v[18]; - ID = v[21]; -} - -// MOV to/from CRn and DRn: "The OF, SF, ZF, AF, PF, and CF flags are -// undefined" (SDM Vol.2B MOV—Move to/from Control Registers, 4-33; -// MOV—Move to/from Debug Registers, 4-35), where the APM has "rFLAGS -// Affected: None" (Vol.3 MOV CRn p.427, MOV DRn p.428), one of the values -// the SDM allows. Call only after the access succeeds, so faults retain -// the original flags. -val finish_system_register_move : unit -> unit -function finish_system_register_move() = { - CF = undefined; - PF = undefined; - AF = undefined; - ZF = undefined; - SF = undefined; - OF = undefined -} - -// Compute the parity of the low 8 bits of a value. -// PF is set if the number of set bits in the low byte is even. -val compute_PF : byte -> bit -function compute_PF(val8) = { - let r4 : bits(4) = val8[7..4] ^ val8[3..0]; - let r2 : bits(2) = r4[3..2] ^ r4[1..0]; - let r1 : bits(1) = r2[1] ^ r2[0]; - // PF=1 means even parity, so invert - (~(r1))[0] -} - -// Update SF, ZF, PF based on a result value. -// These three flags are set identically by most arithmetic/logic instructions. -val update_SF_ZF_PF : forall 'n, 'n >= 8. bits('n) -> unit -function update_SF_ZF_PF(result) = { - SF = result['n - 1]; - let zf_wide : bits('n + 1) = (0b0 @ result) - 1; - ZF = zf_wide['n]; - PF = compute_PF(result[7..0]) -} - -// Compute OF, AF, SF, ZF, PF for addition without modifying CF. -// Used by INC which must preserve CF. -val update_flags_add_no_cf : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit -function update_flags_add_no_cf(result, a, b) = { - OF = (~(a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; - let af_wide : bits(5) = (0b0 @ a[3..0]) + (0b0 @ b[3..0]); - AF = af_wide[4]; - update_SF_ZF_PF(result) -} - -// Compute OF, AF, SF, ZF, PF for subtraction without modifying CF. -// Used by DEC which must preserve CF. -val update_flags_sub_no_cf : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit -function update_flags_sub_no_cf(result, a, b) = { - OF = ((a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; - let af_wide : bits(5) = (0b0 @ a[3..0]) - (0b0 @ b[3..0]); - AF = af_wide[4]; - update_SF_ZF_PF(result) -} - -// Compute CF and OF for addition: dest = a + b. -val update_flags_add : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit -function update_flags_add(result, a, b) = { - // CF: carry bit from wide addition - let cf_wide : bits('n + 1) = (0b0 @ a) + (0b0 @ b); - CF = cf_wide['n]; - // OF: signed overflow — same sign inputs, different sign result - OF = (~(a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; - // AF: carry out of bit 3 - let af_wide : bits(5) = (0b0 @ a[3..0]) + (0b0 @ b[3..0]); - AF = af_wide[4]; - update_SF_ZF_PF(result) -} - -// Compute CF and OF for subtraction: dest = a - b. -val update_flags_sub : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n)) -> unit -function update_flags_sub(result, a, b) = { - // CF: borrow bit from wide subtraction - let cf_wide : bits('n + 1) = (0b0 @ a) - (0b0 @ b); - CF = cf_wide['n]; - // OF: signed overflow — different sign inputs, result sign differs from a - OF = ((a['n - 1 .. 'n - 1] ^ b['n - 1 .. 'n - 1]) & (result['n - 1 .. 'n - 1] ^ a['n - 1 .. 'n - 1]))[0]; - // AF: borrow out of bit 3 - let af_wide : bits(5) = (0b0 @ a[3..0]) - (0b0 @ b[3..0]); - AF = af_wide[4]; - update_SF_ZF_PF(result) -} - -// Compute CF and OF for addition with carry: dest = a + b + carry_in. -val update_flags_adc : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n), bit) -> unit -function update_flags_adc(result, a, b, carry_in) = { - // CF: carry bit from wide addition with carry_in - let cf_wide : bits('n + 1) = (0b0 @ a) + (0b0 @ b) + zero_extend(carry_in); - CF = cf_wide['n]; - // OF: signed overflow from wide signed addition - let of_wide : bits('n + 1) = sign_extend(a) + sign_extend(b) + zero_extend(carry_in); - OF = (of_wide['n .. 'n] ^ of_wide['n - 1 .. 'n - 1])[0]; - // AF: nibble carry with carry_in - let af_wide : bits(5) = (0b0 @ a[3..0]) + (0b0 @ b[3..0]) + zero_extend(carry_in); - AF = af_wide[4]; - update_SF_ZF_PF(result) -} - -// Compute CF and OF for subtraction with borrow: dest = a - b - borrow_in. -val update_flags_sbb : forall 'n, 'n >= 8. (bits('n), bits('n), bits('n), bit) -> unit -function update_flags_sbb(result, a, b, borrow_in) = { - // CF: borrow bit from wide subtraction with borrow_in - let cf_wide : bits('n + 1) = (0b0 @ a) - (0b0 @ b) - zero_extend(borrow_in); - CF = cf_wide['n]; - // OF: signed overflow from wide signed subtraction - let of_wide : bits('n + 1) = sign_extend(a) - sign_extend(b) - zero_extend(borrow_in); - OF = (of_wide['n .. 'n] ^ of_wide['n - 1 .. 'n - 1])[0]; - // AF: nibble borrow with borrow_in - let af_wide : bits(5) = (0b0 @ a[3..0]) - (0b0 @ b[3..0]) - zero_extend(borrow_in); - AF = af_wide[4]; - update_SF_ZF_PF(result) -} - -// Evaluate an x86 condition code (4-bit, from Jcc/CMOVcc/SETcc opcodes). -// The condition codes correspond to the low 4 bits of the opcode: -// 0=O 1=NO 2=B 3=AE 4=E 5=NE 6=BE 7=A -// 8=S 9=NS A=P B=NP C=L D=GE E=LE F=G -type cc_idx = range(0, 15) - -val eval_cc : cc_idx -> bit -function eval_cc(cc) = { - let sf_ne_of : bits(1) = SF ^ OF; - let results : bits(16) = - (~(ZF) & ~(sf_ne_of)) @ // F: G/NLE - (ZF | sf_ne_of) @ // E: LE/NG - (~(sf_ne_of)) @ // D: GE/NL - sf_ne_of @ // C: L/NGE - (~(PF)) @ // B: NP/PO - PF @ // A: P/PE - (~(SF)) @ // 9: NS - SF @ // 8: S - (~(CF) & ~(ZF)) @ // 7: A/NBE - (CF | ZF) @ // 6: BE/NA - (~(ZF)) @ // 5: NE/NZ - ZF @ // 4: E/Z - (~(CF)) @ // 3: AE/NB/NC - CF @ // 2: B/C/NAE - (~(OF)) @ // 1: NO - OF; // 0: O - results[cc] -} - -// Update flags for logical operations (AND, OR, XOR). -// CF and OF are cleared; AF is undefined per SDM. -val update_flags_logic : forall 'n, 'n >= 8. bits('n) -> unit -function update_flags_logic(result) = { - CF = 0b0; - OF = 0b0; - AF = undefined; - update_SF_ZF_PF(result) -} diff --git a/crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project b/crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project deleted file mode 100644 index 1a82f420a..000000000 --- a/crates/clazel-x64/tests/data/sail-x86-shina/model/x86.sail_project +++ /dev/null @@ -1,66 +0,0 @@ -prelude { - files - prelude.sail, -} - -core { - requires prelude - - files - core_types.sail, - extern.sail, - vmx_types.sail, - regs.sail, - rflags.sail, - exceptions.sail, - paging.sail, - mem.sail, - interrupts.sail, - vm86.sail, - vmx_vmcs.sail, -} - -decode { - requires prelude, core - - files - operands.sail, - branchless.sail, - crypto.sail, - insn_simd.sail, - insn_prefixes.sail, - insn_modrm.sail, - smm.sail, - vmx.sail, - insn_vmx.sail, - insn_alu.sail, - insn_x87.sail, - insn_sse_fp.sail, - insn_sse_int.sail, - insn_mmx.sail, - insn_xsave.sail, - insn_baseline.sail, - insn_groups.sail, - insn_fma.sail, - insn_sse4_helpers.sail, - insn_vex.sail, - insn_vex_imm.sail, - insn_vex_fp.sail, - insn_vex_int.sail, - insn_vex_fma.sail, - insn_vex_arith.sail, - insn_amx.sail, - insn_vex_dispatch.sail, - insn_evex.sail, - insn_evex_fp.sail, - insn_evex_int.sail, - insn_evex_fma.sail, - insn_evex_perm.sail, - insn_evex_arith.sail, - insn_evex_fp16.sail, - insn_evex_imm.sail, - insn_evex_forms.sail, - insn_evex_dispatch.sail, - insn_dispatch.sail, - fetch_execute.sail, -} diff --git a/crates/clazel-x64/tests/generated/sail_x86_shina.rs b/crates/clazel-x64/tests/generated/sail_x86_shina.rs deleted file mode 100644 index 7b01b4bf4..000000000 --- a/crates/clazel-x64/tests/generated/sail_x86_shina.rs +++ /dev/null @@ -1,46 +0,0 @@ -// @generated by `cargo xtask testdata` from tests/data/sail-x86-shina/. -// Do not edit: `cargo xtask verify` fails if this differs from what the -// converter (xtask/src/testdata/isa.rs) produces. -// Source, commit and license: tests/data/sail-x86-shina/SOURCE.md. -// -// Sail x86 model written from the Intel manuals (jit.md item J.2), the candidate second source. -// 23 files, 577218 bytes. Nothing here is parsed yet; see the converter's -// header for why. Paths are relative to tests/data/sail-x86-shina/. - -/// One vendored file. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct File { - /// Its path under the suite directory, with `/` separators. - pub path: &'static str, - /// Its size in bytes. - pub size: u64, - /// Its SHA-256, in lower-case hex. - pub sha256: &'static str, -} - -/// Every vendored file, sorted by path. -pub const FILES: &[File] = &[ - File { path: "LICENSE.md", size: 1067, sha256: "e65ecb752d534b9cb7b16b601a944dae24bca8dcda44a18c300d0cd6d9144d58" }, - File { path: "README.md", size: 3742, sha256: "5da3d30fcbd5ac032ea0f1f7af71760e74fcd32513922b7cbf0ce8c3df596474" }, - File { path: "docs/x86-64-completeness-checklist.md", size: 77631, sha256: "652a87d6840977385904caf03cb23af52acad18c35abd8f16f6753122686aedf" }, - File { path: "model/branchless.sail", size: 16415, sha256: "8a1ac92bd9790ea6604f13674ff60337ab5f36f2964b9fe2b5310a897ed10f2e" }, - File { path: "model/core_types.sail", size: 5017, sha256: "fb3d14b45577a51f016a14c320c67830327d88bf0e7c3e729ccbbfb44c71f289" }, - File { path: "model/exceptions.sail", size: 6410, sha256: "f927ca47a0b02f65caa2f0eb3657e23245728b3f027b8d2aafab2d1a58dac565" }, - File { path: "model/extern.sail", size: 18555, sha256: "d37f9127074f48c63a1777670b13cdc4dcbbc39f5cd6f145a2252c5b28e814d1" }, - File { path: "model/fetch_execute.sail", size: 10680, sha256: "40dd44e213864e37d80a7ab0695496d5cef34057518ec9ef69ce05fec7151a88" }, - File { path: "model/insn_alu.sail", size: 2957, sha256: "5fdc1dff9e642c311a34a0b8150d39122d6edbd24b3ce1b4fcfc3e55a875ec2d" }, - File { path: "model/insn_baseline.sail", size: 107247, sha256: "cc02f5b1712cea47182436b8f8dee34aa59b68e0ddffd1eab4bda2e6d47b80e8" }, - File { path: "model/insn_dispatch.sail", size: 90511, sha256: "cd5ef19df0c6684733d09450a110ede3671a4ea0d2ef446f0ed98befc7a8aa2b" }, - File { path: "model/insn_groups.sail", size: 17156, sha256: "986bd93d642c9f788fab960e7fd54f391cdf25a78b19dea95012d56d56b2a768" }, - File { path: "model/insn_modrm.sail", size: 19571, sha256: "6a056df43aaf88b1deaa4323d0bc328ca851816b9cd298a93fa64d884f5fcf7d" }, - File { path: "model/insn_prefixes.sail", size: 5826, sha256: "f81da5829b55ef596ca38f4b451e5a3e67471a2a2223dd57f9970e3c3c4d4203" }, - File { path: "model/insn_simd.sail", size: 27867, sha256: "52f8dd8664f41a8f8192d18b2ba8c8547b944aa8e4c59d4fa4aa379cfcf89599" }, - File { path: "model/insn_sse_fp.sail", size: 33900, sha256: "72e09025d51b424e3ea8806a99bc6556f7391fe22828802276d4552123e68649" }, - File { path: "model/mem.sail", size: 34839, sha256: "18c521e8677447bed0c6d0d96ced9dad9f06f34b1e278adaba4bb361deeec3f8" }, - File { path: "model/operands.sail", size: 16630, sha256: "8308eed94cc7b1e864092bf0a3bafb1acfe1a55593bafdfcb052798f6d45ef2b" }, - File { path: "model/paging.sail", size: 18548, sha256: "13f5caa064cb383928ff3cc872c643dce2ee6c888da8274b53185eb2a6222bea" }, - File { path: "model/prelude.sail", size: 5068, sha256: "3c5ef7a17b04fbf3ac361eb4f71b7e29a86d7782cd4a02063cd02a8851504c33" }, - File { path: "model/regs.sail", size: 48159, sha256: "18902f88eefe8bdc2c81274a66832f2a0fecd37084c6dfbe4072102bf79f8abe" }, - File { path: "model/rflags.sail", size: 8242, sha256: "3c098ce4cac15e3bb0e5b0d0b8ae6f2c7b8918f7073af0ab9ebcf5b89bc6686f" }, - File { path: "model/x86.sail_project", size: 1180, sha256: "a677b09cc51906ddabe6c92da52f91ea36dd20e51f6f6b88101b5867934ab9fd" }, -]; diff --git a/crates/clazel-x64/tests/vendored_sources.rs b/crates/clazel-x64/tests/vendored_sources.rs index cd5bf9de0..92bf3b1ed 100644 --- a/crates/clazel-x64/tests/vendored_sources.rs +++ b/crates/clazel-x64/tests/vendored_sources.rs @@ -11,9 +11,6 @@ mod acl2_x86isa { mod sail_x86_from_acl2 { include!("generated/sail_x86_from_acl2.rs"); } -mod sail_x86_shina { - include!("generated/sail_x86_shina.rs"); -} mod intel_sdm { include!("generated/intel_sdm.rs"); } @@ -48,15 +45,6 @@ fn sail_x86_from_acl2_files_have_their_listed_sizes() { check("sail-x86-from-acl2", &files); } -#[test] -fn sail_x86_shina_files_have_their_listed_sizes() { - let files: Vec<_> = sail_x86_shina::FILES - .iter() - .map(|f| (f.path, f.size)) - .collect(); - check("sail-x86-shina", &files); -} - #[test] fn the_sdm_is_pinned_and_not_vendored() { assert_eq!(intel_sdm::PINS.len(), 1); diff --git a/docs/phases/jit.md b/docs/phases/jit.md index 9de104c70..9b9b8b6d9 100644 --- a/docs/phases/jit.md +++ b/docs/phases/jit.md @@ -377,22 +377,29 @@ code. - ACL2 `x86isa` (acl2/acl2 at 33b05575, BSD-3-Clause, 2.6 MB); - the Sail x86 model translated from it (rems-project/sail-x86-from-acl2 at 0c6c023d, 0.8 MB); - - a Sail x86 model written from the Intel manuals (shina-lab/sail-x86 at - 1829cb6e, MIT, 0.6 MB); - Intel's SDM volume 2, version 093, **pinned by URL and SHA-256 only**: Intel's terms forbid redistribution; + - the Arm Architecture Reference Manual for A-profile (DDI 0487), issue + M.d (Arm's early-access label), **pinned by URL, size (129 MB) and + SHA-256 only**: Arm's terms forbid copying it; - the Sail Armv9.4-A model (rems-project/sail-arm at 5416ef6b, BSD-3-Clause-Clear, 3.9 MB); - Arm's machine-readable specification (BSD-3-Clause, so it may be redistributed), release 2026-09: the licence and README are vendored, and `Instructions.json` (116 MB, over the size budget) is pinned by SHA-256. -- **Not independent, as the pins show:** the Sail x86 model that this item - names is a mechanical translation of the ACL2 model, and the Sail Arm model - is a translation of Arm's own ASL, the same text as the machine-readable - specification. So J.3's and J.4's "second source" is not independent unless - a person accepts `shina-lab/sail-x86` for x86-64, and for A64 no second - formal source was found. See the two READMEs. +- **The two formal models are not independent, as the pins show:** the Sail + x86 model this item names is a mechanical translation of the ACL2 model, + and the Sail Arm model is a translation of Arm's own ASL, the same text as + the machine-readable specification. **Decision (2026-11-16), by the user:** + the second transcription comes from the vendor's manual, not from another + formal model (see the notes under J.3 and J.4). The Sail x86 translation is + kept only as a check on our reading of ACL2, and **it is not independent of + ACL2**. See the two crate READMEs. +- **Considered and rejected:** `shina-lab/sail-x86`, a Sail x86 model written + from the Intel manuals, as the second x86-64 source. It has a single + author, no review, and leaves floating-point arithmetic external + (`extern`, supplied by its emulator). It is not pinned or vendored. - **Reference disassemblers:** `iced-x86` 1.22.0 (with `lazy_static`) and `yaxpeax-arm` 0.5.0 (with `yaxpeax-arch`, `bitvec` and four small packages), each a `test` row in DEPENDENCIES.md, dev-dependencies of the new @@ -446,6 +453,18 @@ code. subset. - Hardware differential tests on the Linux and Windows runners. +*Later note (2026-11-16):* the sources, decided by the user. +- The **primary spec** is transcribed from the ACL2 `x86isa` model. +- The **independent transcription** is made from Intel's SDM, its prose and + pseudocode (volume 2, pinned in J.2), not from another formal model. +- A **different session** writes the independent transcription, and it does + not read the primary transcription. +- The **hardware differential tests** are the further check against both. +- The Sail x86 translation (`sail-x86-from-acl2`) is kept only as a check on + our reading of ACL2. It is a machine translation of ACL2, so **it is not + independent of it** and does not count as a second source. The crate header + says so. + ### J.4 `clazel-a64` (L) As J.3. The subset is integer ALU, compare and conditional select, loads and @@ -454,6 +473,17 @@ stores with register base and scaled register or immediate offset, `b`, has fixed 4-byte words and no prefixes. Hardware tests run on the macOS runner. +*Later note (2026-11-16):* the sources, decided by the user. +- The **primary spec** is transcribed from the Sail Arm model and Arm's ASL, + which are one source: the Sail model is a translation of the ASL, which + Arm's machine-readable specification also carries. +- The **independent transcription** is made from the Arm Architecture + Reference Manual's prose (DDI 0487, pinned in J.2), not from another formal + model. +- A **different session** writes the independent transcription, and it does + not read the primary transcription. +- The **hardware differential tests** are the further check against both. + ### J.5 `clazel-lir`: syntax, typing, semantics (M) - Structured control flow, typed values, region-tagged loads and stores @@ -571,8 +601,9 @@ validator is at tier 2. - **x86-64's semantics is large, and its two public formal models may share ancestry.** This is the assumption the safety claim rests on. Mitigations: - keep the subset small, with canonical encodings only; - - check the independence of the two sources in J.2, and record it in the - crate header if they are not independent; + - the two formal models are not independent (J.2), so the second + transcription comes from Intel's SDM, written by a different session + (J.3's note); - hardware differential tests on two OSes; - a decoder differential over every accepted encoding. - **The code process is new trusted code with a powerful handle.** It is diff --git a/xtask/src/testdata.rs b/xtask/src/testdata.rs index 3c6536380..502571186 100644 --- a/xtask/src/testdata.rs +++ b/xtask/src/testdata.rs @@ -207,10 +207,10 @@ const CONVERTERS: &[(&str, Convert, &[&str])] = &[ // JIT item J.2: instruction-set sources (see isa.rs). ("acl2-x86isa", isa::convert_acl2_x86isa, &[]), ("sail-x86-from-acl2", isa::convert_sail_x86_from_acl2, &[]), - ("sail-x86-shina", isa::convert_sail_x86_shina, &[]), ("intel-sdm", isa::convert_intel_sdm, &[]), ("sail-arm", isa::convert_sail_arm, &[]), ("arm-mrs", isa::convert_arm_mrs, &[]), + ("arm-arm", isa::convert_arm_arm, &[]), ]; /// Suites whose directory is a tree of upstream paths, not a flat list: the @@ -223,7 +223,6 @@ const TREE_SUITES: &[&str] = &[ "test262", "acl2-x86isa", "sail-x86-from-acl2", - "sail-x86-shina", "sail-arm", "arm-mrs", ]; diff --git a/xtask/src/testdata/isa.rs b/xtask/src/testdata/isa.rs index 4e900015b..4f27d95e9 100644 --- a/xtask/src/testdata/isa.rs +++ b/xtask/src/testdata/isa.rs @@ -13,9 +13,8 @@ //! - `sail-x86-from-acl2` (`clazel-x64`): the Sail model that is a //! mechanical translation of the one above (see the crate's README: it is //! not independent of it). -//! - `sail-x86-shina` (`clazel-x64`): a Sail model written from the Intel -//! manuals, the candidate second source. -//! - `intel-sdm` (`clazel-x64`): Intel's SDM volume 2, pinned only. +//! - `intel-sdm` (`clazel-x64`) and `arm-arm` (`clazel-a64`): the vendors' +//! manuals, pinned only (their terms do not allow redistribution). //! - `sail-arm` (`clazel-a64`): the Sail Arm model, the A64 base //! instructions and the shared pseudocode they call. //! - `arm-mrs` (`clazel-a64`): Arm's machine-readable specification, the @@ -30,8 +29,6 @@ use super::inventory::{inventory, listed_hashes, render}; pub const ACL2_X86ISA_ROOTS: &[&str] = &["README", "portcullis", "utils", "machine"]; /// The translated Sail model's roots. pub const SAIL_X86_FROM_ACL2_ROOTS: &[&str] = &["README.md", "LICENCE", "model"]; -/// The Intel-manual-based Sail model's roots. -pub const SAIL_X86_SHINA_ROOTS: &[&str] = &["README.md", "docs", "model"]; /// The Sail Arm model's roots. pub const SAIL_ARM_ROOTS: &[&str] = &["README.md", "src"]; /// The files of Arm's package that are vendored. @@ -69,16 +66,6 @@ pub fn convert_sail_x86_from_acl2(dir: &Path) -> Result { ) } -/// `sail-x86-shina`. -pub fn convert_sail_x86_shina(dir: &Path) -> Result { - tree( - dir, - "sail-x86-shina", - SAIL_X86_SHINA_ROOTS, - "Sail x86 model written from the Intel manuals (jit.md item J.2), the candidate second source.", - ) -} - /// `sail-arm`. pub fn convert_sail_arm(dir: &Path) -> Result { tree( @@ -188,6 +175,19 @@ pub fn convert_intel_sdm(dir: &Path) -> Result { ) } +/// `arm-arm`: Arm Architecture Reference Manual for A-profile, nothing +/// vendored, one pin (or, until a person fills it in, a placeholder: see the +/// suite's `SOURCE.md`). +pub fn convert_arm_arm(dir: &Path) -> Result { + let pins = pins(dir)?; + render_pins( + "arm-arm", + "Arm Architecture Reference Manual for A-profile (DDI 0487), pinned by URL and SHA-256 (Arm's terms do not allow redistribution).", + &pins, + true, + ) +} + /// `arm-mrs`: the licence notice and README as an inventory, and the /// `Instructions.json` the notice covers as a pin. pub fn convert_arm_mrs(dir: &Path) -> Result { From 2ee58b270745b1a7c0b5c7d0233e120509479be7 Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Mon, 16 Nov 2026 22:55:39 +0000 Subject: [PATCH 6/8] Vendor the RTL library and fp/logical.lisp the x86-64 spec reads (J.2) The J.3 transcription found the floating-point instructions defined with Russinoff's RTL library (books/rtl/rel11/lib), and ucomisd in machine/instructions/fp/logical.lisp, neither of which J.2 vendored. Both come from the same acl2/acl2 commit, 33b05575. The library is a new suite, acl2-rtl (0.3 MB, BSD-3-Clause), since its paths are relative to books/rtl/rel11, not books/projects/x86isa. Co-Authored-By: Claude Opus 5.5 --- crates/clazel-x64/README.md | 1 + .../clazel-x64/tests/data/acl2-rtl/LICENSE.md | 41 + .../clazel-x64/tests/data/acl2-rtl/SOURCE.md | 25 + .../tests/data/acl2-rtl/lib/add.lisp | 615 +++++ .../tests/data/acl2-rtl/lib/basic.lisp | 585 +++++ .../tests/data/acl2-rtl/lib/bits.lisp | 1140 +++++++++ .../tests/data/acl2-rtl/lib/defs.lisp | 542 +++++ .../tests/data/acl2-rtl/lib/div.lisp | 345 +++ .../tests/data/acl2-rtl/lib/doc.lisp | 241 ++ .../tests/data/acl2-rtl/lib/excps.lisp | 1095 +++++++++ .../tests/data/acl2-rtl/lib/float.lisp | 507 ++++ .../tests/data/acl2-rtl/lib/gl.lisp | 88 + .../tests/data/acl2-rtl/lib/log.lisp | 545 +++++ .../tests/data/acl2-rtl/lib/mult.lisp | 632 +++++ .../tests/data/acl2-rtl/lib/rac.lisp | 275 +++ .../tests/data/acl2-rtl/lib/rcp.lisp | 61 + .../tests/data/acl2-rtl/lib/reps.lisp | 506 ++++ .../tests/data/acl2-rtl/lib/round.lisp | 2096 +++++++++++++++++ .../tests/data/acl2-rtl/lib/sqrt.lisp | 334 +++ .../tests/data/acl2-rtl/lib/srt.lisp | 629 +++++ .../tests/data/acl2-rtl/lib/top-alt.lisp | 79 + .../tests/data/acl2-rtl/lib/top-doc.lisp | 46 + .../tests/data/acl2-rtl/lib/top.lisp | 79 + .../tests/data/acl2-rtl/lib/util.lisp | 197 ++ .../tests/data/acl2-rtl/package.lsp | 37 + .../tests/data/acl2-rtl/portcullis.lisp | 7 + .../tests/data/acl2-x86isa/SOURCE.md | 5 +- .../machine/instructions/fp/logical.lisp | 560 +++++ crates/clazel-x64/tests/generated/acl2_rtl.rs | 47 + .../clazel-x64/tests/generated/acl2_x86isa.rs | 3 +- crates/clazel-x64/tests/vendored_sources.rs | 9 + docs/phases/jit.md | 2 + xtask/src/testdata.rs | 2 + xtask/src/testdata/isa.rs | 14 + 34 files changed, 11388 insertions(+), 2 deletions(-) create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/LICENSE.md create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/SOURCE.md create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/add.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/basic.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/bits.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/defs.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/div.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/doc.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/excps.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/float.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/gl.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/log.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/mult.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/rac.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/rcp.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/reps.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/round.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/sqrt.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/srt.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/top-alt.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/top-doc.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/top.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/lib/util.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/package.lsp create mode 100644 crates/clazel-x64/tests/data/acl2-rtl/portcullis.lisp create mode 100644 crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/logical.lisp create mode 100644 crates/clazel-x64/tests/generated/acl2_rtl.rs diff --git a/crates/clazel-x64/README.md b/crates/clazel-x64/README.md index 808d9fe78..321f50c37 100644 --- a/crates/clazel-x64/README.md +++ b/crates/clazel-x64/README.md @@ -1,3 +1,4 @@ +| `acl2-rtl` | Russinoff's RTL library (BSD-3-Clause), the floating-point definitions the x86isa SSE books use | 0.3 MB, vendored | # clazel-x64 Part of [Clazel](../../README.md). The x86-64 subset the JIT emits: its diff --git a/crates/clazel-x64/tests/data/acl2-rtl/LICENSE.md b/crates/clazel-x64/tests/data/acl2-rtl/LICENSE.md new file mode 100644 index 000000000..c970bbaac --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/LICENSE.md @@ -0,0 +1,41 @@ +RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +Copyright (C) 1995-2013 Advanced Mirco Devices, Inc. +All rights reserved. + +Contact: + David Russinoff + 1106 W 9th St., Austin, TX 78703 + http://www.russsinoff.com/ + +Author: David M. Russinoff (david@russinoff.com) + +NOTE: This license file applies to all materials residing under this +directory (and its subdirectories, etc.), except that license +information in specific files has precedence over this file. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +o Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +o Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +o Neither the name of the copyright holder nor the names of + its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/clazel-x64/tests/data/acl2-rtl/SOURCE.md b/crates/clazel-x64/tests/data/acl2-rtl/SOURCE.md new file mode 100644 index 000000000..b19212445 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/SOURCE.md @@ -0,0 +1,25 @@ +# Russinoff's RTL library, the floating-point definitions the ACL2 x86isa model uses + +Upstream: https://github.com/acl2/acl2/tree/33b05575eaf9f54734bf36e6f4bd8ee094ff2ee1/books/rtl/rel11 +Commit: 33b05575eaf9f54734bf36e6f4bd8ee094ff2ee1 +License: BSD-3-Clause. `LICENSE.md` is `books/rtl/rel11/license.txt` at this commit, copied unchanged (Advanced Micro Devices, 1995-2013; David M. Russinoff). Files with their own licence header (`portcullis.lisp`: ForrestHunt, Inc., BSD-3-Clause) keep it. + +The same acl2/acl2 commit as `acl2-x86isa`. The x86isa SSE books +(`machine/instructions/fp/`) define `addsd`, `subsd`, `mulsd`, `divsd`, +`sqrtsd` and the conversions with this library's functions (`rtl::rnd`, +`rtl::decode`, the `excps.lisp` exception rules), so the J.3 spec of the +floating-point instructions is read from these files. Copied byte for byte, +with the paths relative to `books/rtl/rel11/` kept: + +- `package.lsp`, `portcullis.lisp`: the `RTL` package; +- `lib/`: every `.lisp` file, the library's whole interface. The J.3 spec + reads `defs.lisp`, `reps.lisp`, `round.lisp` and `excps.lisp`; the others + (`basic`, `bits`, `log`, `float` and the rest) define what those use. + +Not vendored: `support/` (the proofs behind `lib/`), `rel9-rtl-pkg/`, the +`.acl2` certification files and the `.sys` caches. + +To update, copy the files from a newer acl2/acl2 commit (keeping it equal to +`acl2-x86isa`'s), change the commit above, and run `cargo xtask testdata`. +`xtask/src/testdata/isa.rs` writes `tests/generated/acl2_rtl.rs`, the +inventory of paths, sizes and hashes. diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/add.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/add.lisp new file mode 100644 index 000000000..41dd546d1 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/add.lisp @@ -0,0 +1,615 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; Bit Vector Addition +;;;********************************************************************** + +(defsection-rtl |Bit Vector Addition| |Addition| + +(defthm half-adder + (implies (and (bvecp u 1) + (bvecp v 1)) + (equal (+ u v) + (cat (logand u v) 1 (logxor u v) 1))) + :rule-classes ()) + +(defthm add-2 + (implies (and (integerp x) (integerp y)) + (equal (+ x y) + (+ (logxor x y) + (* 2 (logand x y))))) + :rule-classes ()) + +(defthm full-adder + (implies (and (bvecp u 1) + (bvecp v 1) + (bvecp w 1)) + (equal (+ u v w) + (cat (logior (logand u v) (logior (logand u w) (logand v w))) 1 + (logxor u (logxor v w)) 1))) + :rule-classes ()) + +(defthm add-3 + (implies (and (integerp x) + (integerp y) + (integerp z)) + (= (+ x y z) + (+ (logxor x (logxor y z)) + (* 2 (logior (logand x y) + (logior (logand x z) + (logand y z))))))) + :rule-classes ()) + +(defthmd plus-logior-logand + (implies (and (integerp x) + (integerp y)) + (equal (+ x y) + (- (* 2 (logior x y)) + (logxor x y))))) + +(defthmd lutz-lemma + (implies (and (integerp x) (integerp y) (natp n)) + (and (iff (= (bits (+ x y) (1- n) 0) (1- (expt 2 n))) + (= (bits (logxor x y) (1- n) 0) (1- (expt 2 n)))) + (iff (= (bits (+ x y) (1- n) 0) (1- (expt 2 n))) + (= (+ (bits x (1- n) 0) (bits y (1- n) 0)) (1- (expt 2 n))))))) + +(defund cbit (x y cin k) + (if (zp k) + cin + (logior (logand (bitn x (1- k)) (bitn y (1- k))) + (logior (logand (bitn x (1- k)) (cbit x y cin (1- k))) + (logand (bitn y (1- k)) (cbit x y cin (1- k))))))) + +(defthmd ripple-carry-lemma + (implies (and (integerp x) + (integerp y) + (bitp cin) + (natp i)) + (equal (bitn (+ x y cin) i) + (logxor (logxor (bitn x i) (bitn y i)) + (cbit x y cin i))))) + + +;;;********************************************************************** +;;; Parallel Prefix Adders +;;;********************************************************************** + +(defun gen (x y i j) + (declare (xargs :measure (nfix (1+ i)) + :guard (and (integerp x) + (integerp y)))) + (if (and (natp i) (natp j) (>= i j)) + (if (= (bitn x i) (bitn y i)) + (bitn x i) + (gen x y (1- i) j)) + 0)) + +(defun prop (x y i j) + (declare (xargs :measure (nfix (1+ i)) + :guard (and (integerp x) + (integerp y)))) + (if (and (natp i) (natp j) (>= i j)) + (if (= (bitn x i) (bitn y i)) + 0 + (prop x y (1- i) j)) + 1)) + +(defthm bvecp-1-gen + (bvecp (gen x y i j) 1) + :rule-classes (:rewrite + (:forward-chaining :trigger-terms ((gen x y i j))))) + +(defthm bvecp-1-prop + (bvecp (prop x y i j) 1) + :rule-classes (:rewrite + (:forward-chaining :trigger-terms ((prop x y i j))))) + +(defthmd gen-i-i + (implies (and (integerp x) + (integerp y) + (natp i)) + (equal (gen x y i i) + (logand (bitn x i) (bitn y i)))) + :hints (("Goal" :in-theory (enable gen) :use ((:instance bitn-0-1 (n i)) (:instance bitn-0-1 (x y) (n i)))))) + +(defthmd prop-i-i + (implies (and (integerp x) + (integerp y) + (natp i)) + (equal (prop x y i i) + (logxor (bitn x i) (bitn y i)))) + :hints (("Goal" :expand ((prop x y i i)) + :use ((:instance bitn-0-1 (n i)) (:instance bitn-0-1 (x y) (n i)))))) + +(defthmd gen-val + (implies (natp j) + (equal (gen x y i j) + (if (>= (+ (bits x i j) (bits y i j)) + (expt 2 (1+ (- i j)))) + 1 + 0)))) + +(defthm bits-sum + (implies (and (integerp x) (integerp y)) + (equal (bits (+ x y) i j) + (bits (+ (bits x i j) + (bits y i j) + (gen x y (1- j) 0)) + (- i j) 0))) + :rule-classes ()) + +(defthmd prop-val + (implies (and (integerp i) (natp j) (>= i j)) + (equal (prop x y i j) + (if (= (+ (bits x i j) (bits y i j)) + (1- (expt 2 (1+ (- i j))))) + 1 + 0)))) + +(defund gp (x y i j) + (cons (gen x y i j) (prop x y i j))) + +(defund gp0 (x y i) + (gp x y i i)) + +(defund fco (gp1 gp2) + (cons (logior (car gp1) (logand (cdr gp1) (car gp2))) + (logand (cdr gp1) (cdr gp2)))) + +(defthmd fco-assoc + (implies (and (bitp g1) (bitp p1) + (bitp g2) (bitp p2) + (bitp g3) (bitp p3)) + (equal (fco (fco (cons g1 p1) (cons g2 p2)) + (cons g3 p3)) + (fco (cons g1 p1) + (fco (cons g2 p2) (cons g3 p3)))))) + +(defthmd gp-decomp + (implies (and (integerp x) + (integerp y) + (natp j) + (natp i) + (natp k) + (<= j k) + (< k i)) + (equal (fco (gp x y i (1+ k)) (gp x y k j)) + (gp x y i j)))) + +(defthmd cbit-rewrite + (implies (and (integerp x) + (integerp y) + (bitp cin) + (natp i)) + (equal (cbit x y cin (1+ i)) + (logior (gen x y i 0) + (logand (prop x y i 0) cin))))) + +(defun rc (x y i) + (if (zp i) + (gp0 x y 0) + (fco (gp0 x y i) (rc x y (1- i))))) + +(defthmd rc-correct + (implies (and (integerp x) + (integerp y) + (natp i)) + (equal (rc x y i) + (gp x y i 0)))) + +(defun lf (x y i d) + (if (zp d) + (gp0 x y i) + (if (< (mod i (expt 2 d)) (expt 2 (1- d))) + (lf x y i (1- d)) + (fco (lf x y i (1- d)) + (lf x y + (+ (chop i (- d)) (expt 2 (1- d)) -1) + (1- d)))))) + +(defthmd lf-correct-gen + (implies (and (integerp x) + (integerp y) + (natp i) + (natp d)) + (equal (lf x y i d) + (gp x y i (chop i (- d)))))) + +(defthmd lf-correct + (implies (and (integerp x) + (integerp y) + (natp n) + (bvecp i n)) + (equal (lf x y i n) + (gp x y i 0)))) + +(defund ks (x y i d) + (if (zp d) + (gp0 x y i) + (if (< i (expt 2 (1- d))) + (ks x y i (1- d)) + (fco (ks x y i (1- d)) + (ks x y (- i (expt 2 (1- d))) (1- d)))))) + +(defthmd ks-correct-gen + (implies (and (integerp x) + (integerp y) + (natp i) + (natp d)) + (equal (ks x y i d) + (gp x y i (max 0 (1+ (- i (expt 2 d)))))))) + +(defthmd ks-correct + (implies (and (integerp x) + (integerp y) + (natp n) + (bvecp i n)) + (equal (ks x y i n) + (gp x y i 0)))) + +(defund pi2 (k) + (if (zp k) + 0 + (if (integerp (/ k 2)) + (1+ (pi2 (/ k 2))) + 0))) + +(defthmd pi2-upper + (implies (not (zp k)) + (<= (expt 2 (pi2 k)) k))) + +(defthmd pi2-lemma + (implies (and (not (zp k)) (integerp p)) + (iff (integerp (/ k (expt 2 p))) + (<= p (pi2 k))))) + +(defund bk0 (x y i d) + (if (zp d) + (gp0 x y i) + (if (< (pi2 (1+ i)) d) + (bk0 x y i (1- d)) + (fco (bk0 x y i (1- d)) + (bk0 x y (- i (expt 2 (1- d))) (1- d)))))) + +(defund bk (x y i n) + (declare (xargs :hints (("Goal" :use ((:instance pi2-upper (k (1+ i)))))))) + (let ((p (pi2 (1+ i)))) + (if (or (zp n) (not (bvecp i n)) (= i (1- (expt 2 p)))) + (bk0 x y i n) + (fco (bk0 x y i n) + (bk x y (- i (expt 2 p)) n))))) + +(defthmd bk0-correct-gen + (implies (and (integerp x) + (integerp y) + (natp i) + (natp d)) + (equal (bk0 x y i d) + (gp x y i (1+ (- i (expt 2 (min (pi2 (1+ i)) d)))))))) + +(defthmd bk0-correct + (implies (and (integerp x) + (integerp y) + (natp n) + (bvecp i n)) + (equal (bk0 x y i n) + (gp x y i (1+ (- i (expt 2 (pi2 (1+ i))))))))) + +(defthmd bk-correct + (implies (and (integerp x) + (integerp y) + (natp n) + (bvecp i n)) + (equal (bk x y i n) + (gp x y i 0)))) + +(defund hc0 (x y i k d) + (let ((p (pi2 (1+ i)))) + (if (or (zp d) (< p k)) + (bk0 x y i k) + (if (< i (expt 2 (+ k d -1))) + (hc0 x y i k (1- d)) + (fco (hc0 x y i k (1- d)) + (hc0 x y (- i (expt 2 (+ k d -1))) k (1- d))))))) + +(defund hc (x y i k n) + (declare (xargs :hints (("Goal" :use ((:instance pi2-upper (k (1+ i)))))))) + (let ((p (pi2 (1+ i)))) + (if (or (zp n) (not (bvecp i n)) (>= (pi2 (1+ i)) k) (= i (1- (expt 2 p)))) + (hc0 x y i k (- n k)) + (fco (hc0 x y i k (- n k)) + (hc x y (- i (expt 2 p)) k n))))) + +(defthmd hc0-correct-gen + (implies (and (integerp x) + (integerp y) + (natp i) + (natp k) + (natp d) + (>= (pi2 (1+ i)) k)) + (let ((m (max 0 (- (1+ i) (expt 2 (+ k d)))))) + (equal (hc0 x y i k d) + (gp x y i m))))) + +(defthmd hc0-correct + (implies (and (integerp x) + (integerp y) + (natp n) + (natp k) + (<= k n) + (bvecp i n) + (integerp (/ (1+ i) (expt 2 k)))) + (equal (hc0 x y i k (- n k)) + (gp x y i 0)))) + +(defthmd hc-correct + (implies (and (integerp x) + (integerp y) + (natp n) + (natp k) + (<= k n) + (bvecp i n)) + (equal (hc x y i k n) + (gp x y i 0)))) +) + +;;;********************************************************************** +;;; Leading One Prediction +;;;********************************************************************** + +(defsection-rtl |Leading One Prediction| |Addition| + +(defund u0 (x y n) + (bits (logior x (lognot y)) (- n 2) 0)) + +(defthmd lza-thm-0-a + (implies (and (natp n) + (> n 1) + (natp x) + (natp y) + (= (expo x) (1- n)) + (= (expo y) (- n 2))) + (iff (equal (- x y) 1) + (equal (u0 x y n) 0)))) + +(defthmd lza-thm-0-b + (implies (and (natp n) + (> n 1) + (natp x) + (natp y) + (= (expo x) (1- n)) + (= (expo y) (- n 2)) + (not (= (u0 x y n) 0))) + (and (<= (expo (u0 x y n)) (expo (- x y))) + (<= (expo (- x y)) (1+ (expo (u0 x y n))))))) + +(defund p0 (a b) + (declare (xargs :guard (and (integerp a) + (integerp b)))) + (logxor a b)) + +(defund g0 (a b) + (declare (xargs :guard (and (integerp a) + (integerp b)))) + (logand a b)) + +(defund k0 (a b n) + (declare (xargs :guard (and (integerp a) + (integerp b) + (integerp n)))) + (logand (bits (lognot a) (1- n) 0) (bits (lognot b) (1- n) 0))) + +(defund w0 (a b n) + (declare (xargs :guard (and (integerp a) + (integerp b) + (integerp n)))) + (bits (lognot (logxor (p0 a b) (* 2 (k0 a b n)))) (1- n) 0)) + +(defthmd p0-rewrite + (implies (and (integerp a) + (integerp b) + (integerp j)) + (equal (bitn (p0 a b) j) + (if (= (bitn a j) (bitn b j)) + 0 1)))) + +(defthmd g0-rewrite + (implies (and (integerp a) + (integerp b) + (integerp j)) + (equal (bitn (g0 a b) j) + (if (and (= (bitn a j) 1) (= (bitn b j) 1)) + 1 0)))) + +(defthmd k0-rewrite + (implies (and (integerp a) + (integerp b) + (natp j) + (natp n) + (< j n)) + (equal (bitn (k0 a b n) j) + (if (and (= (bitn a j) 0) (= (bitn b j) 0)) + 1 0)))) + +(defthmd w0-rewrite + (implies (and (integerp a) + (integerp b) + (not (zp n)) + (not (zp j)) + (< j n)) + (equal (bitn (w0 a b n) j) + (if (= (bitn (p0 a b) j) (bitn (k0 a b n) (1- j))) + 1 0)))) + +(defthmd lza-thm-1-case-1 + (implies (and (not (zp n)) + (bvecp a n) + (bvecp b n) + (= (+ a b) (expt 2 n))) + (equal (w0 a b n) + 1))) + +(defthm lza-thm-1-case-2 + (implies (and (not (zp n)) + (bvecp a n) + (bvecp b n) + (> (+ a b) (expt 2 n))) + (and (>= (w0 a b n) 2) + (or (= (expo (bits (+ a b) (1- n) 0)) (expo (w0 a b n))) + (= (expo (bits (+ a b) (1- n) 0)) (1- (expo (w0 a b n))))) + (or (= (expo (bits (+ a b 1) (1- n) 0)) (expo (w0 a b n))) + (= (expo (bits (+ a b 1) (1- n) 0)) (1- (expo (w0 a b n))))))) + :rule-classes ()) + +(defund z1 (a b n) + (declare (xargs :guard (and (integerp a) + (integerp b) + (integerp n)))) + (logior (logand (logxor (bits (p0 a b) n 1) (k0 a b n)) + (logxor (p0 a b) (* 2 (k0 a b n)))) + (logand (logxor (bits (p0 a b) n 1) (g0 a b)) + (logxor (p0 a b) (* 2 (g0 a b)))))) + +(defund w1 (a b n) + (declare (xargs :guard (and (integerp a) + (integerp b) + (integerp n)))) + (bits (lognot (z1 a b n)) (- n 2) 0)) + +(defthmd w1-rewrite + (implies (and (integerp a) + (integerp b) + (not (zp n)) + (not (zp j)) + (< j (1- n))) + (equal (bitn (w1 a b n) j) + (if (and (or (= (bitn (p0 a b) (1+ j)) (bitn (k0 a b n) j)) + (= (bitn (p0 a b) j) (bitn (k0 a b n) (1- j)))) + (or (= (bitn (p0 a b) (1+ j)) (bitn (g0 a b) j)) + (= (bitn (p0 a b) j) (bitn (g0 a b) (1- j))))) + 1 0)))) + +(defthmd lza-thm-2-case-1 + (implies (and (not (zp n)) + (bvecp a n) + (bvecp b n) + (= (+ a b) (1- (expt 2 n))) + (natp i)) + (equal (w1 a b n) 0))) + +(defthmd lza-thm-2-case-2 + (implies (and (natp n) + (> n 1) + (bvecp a n) + (bvecp b n) + (or (= (+ a b) (expt 2 n)) + (= (+ a b) (- (expt 2 n) 2)))) + (equal (w1 a b n) + 1))) + +(defthm lza-thm-2-case-3 + (implies (and (not (zp n)) + (bvecp a n) + (bvecp b n) + (= (bitn (p0 a b) (1- n)) 1) + (> (+ a b) (expt 2 n))) + (and (>= (w1 a b n) 2) + (or (= (expo (bits (+ a b) (1- n) 0)) (expo (w1 a b n))) + (= (expo (bits (+ a b) (1- n) 0)) (1- (expo (w1 a b n))))) + (or (= (expo (bits (+ a b 1) (1- n) 0)) (expo (w1 a b n))) + (= (expo (bits (+ a b 1) (1- n) 0)) (1- (expo (w1 a b n))))))) + :rule-classes ()) + +(defthm lza-thm-2-case-4 + (implies (and (not (zp n)) + (bvecp a n) + (bvecp b n) + (= (bitn (p0 a b) (1- n)) 1) + (< (+ a b) (- (expt 2 n) 2))) + (and (>= (w1 a b n) 2) + (or (= (expo (bits (lognot (+ a b)) (1- n) 0)) (expo (w1 a b n))) + (= (expo (bits (lognot (+ a b)) (1- n) 0)) (1- (expo (w1 a b n))))) + (or (= (expo (bits (lognot (+ a b 1)) (1- n) 0)) (expo (w1 a b n))) + (= (expo (bits (lognot (+ a b 1)) (1- n) 0)) (1- (expo (w1 a b n))))))) + :rule-classes ()) + + +;; Leading zero counter: + +(defund zseg (x k i) + (if (zp k) + (if (= (bitn x i) 0) + 1 + 0) + (if (and (= (zseg x (1- k) (1+ (* 2 i))) 1) + (= (zseg x (1- k) (* 2 i)) 1)) + 1 + 0))) + +(defund zcount (x k i) + (if (zp k) + 0 + (if (= (zseg x (1- k) (1+ (* 2 i))) 1) + (logior (expt 2 (1- k)) (zcount x (1- k) (* 2 i))) + (zcount x (1- k) (1+ (* 2 i)))))) + +(defund clz (x n) + (zcount x n 0)) + +(defthmd clz-thm + (implies (and (natp n) + (bvecp x (expt 2 n)) + (> x 0)) + (equal (clz x n) + (- (1- (expt 2 n)) (expo x))))) + +) + +;;;********************************************************************** +;;; Trailing One Prediction +;;;********************************************************************** + +(defsection-rtl |Trailing One Prediction| |Addition| + +(defthm top-thm-1 + (implies (and (natp k) + (integerp a) + (integerp b)) + (equal (equal (bits (+ a b 1) k 0) 0) + (equal (bits (lognot (logxor a b)) k 0) 0))) + :rule-classes ()) + +(defthm top-thm-2 + (implies (and (natp n) + (integerp a) + (integerp b) + (natp k) + (< k n) + (or (equal c 0) (equal c 1))) + (equal (equal (bits (+ a b c) k 0) 0) + (equal (bits (logxor (logxor a b) + (cat (logior a b) n c 1)) + k 0) + 0))) + :rule-classes ()) +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/basic.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/basic.lisp new file mode 100644 index 000000000..f776afbf8 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/basic.lisp @@ -0,0 +1,585 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +;;;********************************************************************** +;;; FLOOR and CEILING +;;;********************************************************************** + +(defsection-rtl |Floor and Ceiling| |Basic Arithmetic Functions| + +(defund fl (x) + (declare (xargs :guard (real/rationalp x))) + (floor x 1)) + +(defthm fl-def + (and (integerp (fl x)) + (implies (case-split (rationalp x)) + (and (<= (fl x) x) + (< x (1+ (fl x)))))) + :rule-classes ((:linear :corollary + (implies (case-split (rationalp x)) + (and (<= (fl x) x) + (< x (1+ (fl x)))))) + (:type-prescription :corollary + (integerp (fl x))))) + +(defthm fl-unique + (implies (and (rationalp x) + (integerp n) + (<= n x) + (< x (1+ n))) + (equal (fl x) n)) + :rule-classes ()) + +(defthm fl-integerp + (equal (equal (fl x) x) + (integerp x))) + +(defthm integerp-fl + (implies (integerp x) + (equal (fl x) x))) + +(defthm quot-bnd + (implies (and (<= 0 x) + (<= 0 y) + (rationalp x) + (rationalp y)) + (<= (* y (fl (/ x y))) + x)) + :rule-classes :linear) + +(defthm fl-monotone-linear + (implies (and (<= x y) + (rationalp x) + (rationalp y)) + (<= (fl x) (fl y))) + :rule-classes :linear) + +(defthm n<=fl-linear + (implies (and (<= n x) + (rationalp x) + (integerp n)) + (<= n (fl x))) + :rule-classes :linear) + +(defthm fl+int-rewrite + (implies (and (integerp n) + (real/rationalp x)) + (and (equal (fl (+ x n)) (+ (fl x) n)) + (equal (fl (+ n x)) (+ n (fl x)))))) + +(defthm fl/int-rewrite + (implies (and (integerp n) + (<= 0 n) + (rationalp x)) + (equal (fl (* (fl x) (/ n))) + (fl (/ x n))))) + +(defthm fl/int-rewrite-alt + (implies (and (integerp n) + (<= 0 n) + (rationalp x)) + (equal (fl (* (/ n) (fl x))) + (fl (/ x n))))) + +(defthm fl*1/int-rewrite + (implies (and (integerp (/ n)) + (<= 0 n) + (real/rationalp x)) + (equal (fl (* (fl x) n)) + (fl (* x n))))) + +(defthm fl*1/int-rewrite-alt + (implies (and (integerp (/ n)) + (<= 0 n) + (real/rationalp x)) + (equal (fl (* n (fl x))) + (fl (* x n))))) + +(defthm fl-half-int + (implies (and (integerp n) + (not (= n 0)) + (not (= n -1))) + (< (abs (fl (/ n 2))) (abs n))) + :rule-classes ()) + +(defthmd minus-fl + (implies (rationalp x) + (equal (fl (- x)) + (if (integerp x) + (- x) + (1- (- (fl x))))))) + +(defthm fl-m-n + (implies (and (< 0 n) + (integerp m) + (integerp n)) + (= (fl (- (/ m n))) + (1- (- (fl (/ (1- m) n)))))) + :rule-classes ()) + +(defund cg (x) + (declare (xargs :guard (real/rationalp x))) + (- (fl (- x)))) + +(defthm cg-def + (and (integerp (cg x)) + (implies (case-split (rationalp x)) + (and (>= (cg x) x) + (> (1+ x) (cg x))))) + :rule-classes ((:linear :corollary + (implies (case-split (rationalp x)) + (and (>= (cg x) x) + (> (1+ x) (cg x))))) + (:type-prescription :corollary + (integerp (cg x))))) + +(defthm cg-unique + (implies (and (rationalp x) + (integerp n) + (>= n x) + (> (1+ x) n)) + (equal (cg x) n)) + :rule-classes ()) + +(defthm cg-integerp + (implies (rationalp x) + (equal (equal (cg x) x) + (integerp x)))) + +(defthm cg-monotone-linear + (implies (and (rationalp x) + (rationalp y) + (<= x y)) + (<= (cg x) (cg y))) + :rule-classes :linear) + +(defthm n>=cg-linear + (implies (and (>= n x) + (rationalp x) + (integerp n)) + (>= n (cg x))) + :rule-classes :linear) + +(defthm cg+int-rewrite + (implies (and (integerp n) + (rationalp x)) + (equal (cg (+ x n)) (+ (cg x) n)))) + +(defthm cg/int-rewrite + (implies (and (integerp n) + (> n 0) + (rationalp x)) + (equal (cg (* (cg x) (/ n))) + (cg (/ x n))))) + +(defthm cg/int-rewrite-alt + (implies (and (integerp n) + (> n 0) + (rationalp x)) + (equal (cg (* (/ n) (cg x))) + (cg (/ x n))))) + +(defthm fl-cg + (implies (rationalp x) + (equal (cg x) + (if (integerp x) + (fl x) + (1+ (fl x))))) + :rule-classes ()) +) + +;;;********************************************************************** +;;; MOD +;;;********************************************************************** + +(defsection-rtl |Modulus| |Basic Arithmetic Functions| + +(in-theory (disable mod)) + +(defthm mod-def + (implies (case-split (acl2-numberp x)) + (equal (mod x y) + (- x (* y (fl (/ x y)))))) + :rule-classes ()) + +(defthm mod-0 + (and (equal (mod 0 y) + 0) + (equal (mod x 0) + (fix x)))) + +(defthm rationalp-mod + (implies (rationalp x) + (rationalp (mod x y))) + :rule-classes (:rewrite :type-prescription)) + +(defthm integerp-mod + (implies (and (integerp m) (integerp n)) + (integerp (mod m n))) + :rule-classes (:rewrite :type-prescription)) + +(defthm natp-mod + (implies (and (natp m) + (natp n)) + (natp (mod m n))) + :rule-classes ((:type-prescription :typed-term (mod m n)))) + +(defthm natp-mod-2 + (implies (and (integerp m) + (integerp n) + (> n 0)) + (natp (mod m n))) + :rule-classes ((:type-prescription :typed-term (mod m n)))) + +(defthm mod-bnd-1 + (implies (and (case-split (< 0 n)) + (case-split (not (complex-rationalp m))) + (case-split (not (complex-rationalp n)))) + (< (mod m n) n)) + :rule-classes :linear) + +(defthm mod-by-1 + (implies (integerp m) + (equal (mod m 1) + 0))) + +(defthm mod-bnd-2 + (implies (and (<= 0 m) + (case-split (rationalp m))) + (<= (mod m n) m)) + :rule-classes :linear) + +(defthm mod-does-nothing + (implies (and (< m n) + (<= 0 m) + (case-split (rationalp m))) + (equal (mod m n) + m))) + +(defthm mod-0-fl + (implies (acl2-numberp m) + (iff (= (mod m n) 0) + (= m (* (fl (/ m n)) n)))) + :rule-classes ()) + +(defthm mod-0-int + (implies (and (integerp m) + (integerp n) + (not (= n 0))) + (iff (= (mod m n) 0) + (integerp (/ m n)))) + :rule-classes ()) + +(defthm mod-mult-n + (equal (mod (* a n) n) + (* n (mod a 1)))) + +(defthm mod-mult-n-alt + (equal (mod (* n a) n) + (* n (mod a 1)))) + +(defthm mod-squeeze + (implies (and (= (mod m n) 0) + (< m (* (1+ a) n)) + (< (* (1- a) n) m) + (integerp a) + (integerp m) + (integerp n)) + (= m (* a n))) + :rule-classes ()) + +(defthm mod-must-be-n + (implies (and (= (mod m n) 0) + (< m (* 2 n)) + (< 0 m) + (rationalp m) + (rationalp n)) + (= m n)) + :rule-classes ()) + +(defthmd fl-mod + (implies (not (zp m)) + (equal (fl (/ (mod a (* m n)) n)) + (mod (fl (/ a n)) m)))) + +(defthm mod-0-0 + (implies (and (integerp p) + (rationalp m) + (rationalp n)) + (iff (= (mod m (* n p)) 0) + (and (= (mod m n) 0) + (= (mod (fl (/ m n)) p) 0)))) + :rule-classes ()) + +(defthm mod-equal-int + (implies (and (= (mod a n) (mod b n)) + (rationalp a) + (rationalp b)) + (integerp (/ (- a b) n))) + :rule-classes ()) + +(defthm mod-equal-int-reverse + (implies (and (integerp (/ (- a b) n)) + (rationalp a) + (rationalp b) + (rationalp n) + (< 0 n)) + (= (mod a n) (mod b n))) + :rule-classes ()) + +(defthm mod-force-equal + (implies (and (< (abs (- a b)) n) + (rationalp a) + (rationalp b) + (integerp n)) + (iff (= (mod a n) (mod b n)) + (= a b))) + :rule-classes ()) + +(defund congruent (a b n) + (declare (xargs :guard (and (real/rationalp a) + (real/rationalp b) + (real/rationalp n) + (not (= n 0))))) + (equal (mod a n) (mod b n))) + +(defthmd mod-mult + (implies (and (integerp a) + (rationalp m) + (rationalp n)) + (equal (mod (+ m (* a n)) n) + (mod m n)))) + +(defthm mod-force + (implies (and (<= (* a n) m) + (< m (* (1+ a) n)) + (integerp a) + (rationalp m) + (rationalp n)) + (= (mod m n) (- m (* a n)))) + :rule-classes ()) + +(defthm mod-bnd-3 + (implies (and (< m (+ (* a n) r)) + (<= (* a n) m) + (integerp a) + (case-split (rationalp m)) + (case-split (rationalp n))) + (< (mod m n) r)) + :rule-classes :linear) + +(defthmd mod-sum + (implies (and (rationalp a) + (rationalp b)) + (equal (mod (+ a (mod b n)) n) + (mod (+ a b) n)))) + +(defthmd mod-diff + (implies (and (case-split (rationalp a)) + (case-split (rationalp b))) + (equal (mod (- a (mod b n)) n) + (mod (- a b) n)))) + +(defthmd mod-of-mod + (implies (and (case-split (natp k)) + (case-split (natp n))) + (equal (mod (mod x (* k n)) n) + (mod x n)))) + +(defthmd mod-of-mod-cor + (implies (and (<= b a) + (case-split (integerp b)) + (case-split (integerp a))) + (equal (mod (mod x (expt 2 a)) (expt 2 b)) + (mod x (expt 2 b))))) + +(defthmd mod-prod + (implies (and (rationalp m) + (rationalp n) + (rationalp k)) + (equal (mod (* k m) (* k n)) + (* k (mod m n))))) + +(defthm mod-mod-times + (implies (and (integerp a) + (integerp b) + (integerp n) + (> n 0)) + (= (mod (* (mod a n) b) n) + (mod (* a b) n))) + :rule-classes ()) + +(defthm mod-plus-mod-iff + (implies (and (integerp a) + (integerp b) + (integerp c) + (not (zp n))) + (iff (= (mod a n) (mod b n)) + (= (mod (+ a c) n) (mod (+ b c) n)))) + :rule-classes ()) + +(defthm mod-times-mod + (implies (and (integerp a) + (integerp b) + (integerp c) + (not (zp n)) + (= (mod a n) (mod b n))) + (= (mod (* a c) n) (mod (* b c) n))) + :rule-classes ()) + +(defthm mod012 + (implies (integerp m) + (or (equal (mod m 2) 0) + (equal (mod m 2) 1))) + :rule-classes ()) + +(defthm mod-plus-mod-2 + (implies (and (integerp a) + (integerp b)) + (iff (= (mod (+ a b) 2) (mod a 2)) + (= (mod b 2) 0))) + :rule-classes ()) + +(defthm mod-mod-2-not-equal + (implies (acl2-numberp m) + (not (= (mod m 2) (mod (1+ m) 2)))) + :rule-classes ()) + +(defthm mod-2*m+1-rewrite + (implies (integerp m) + (equal (mod (1+ (* 2 m)) 2) 1))) + +(defthmd mod-neg + (implies (and (posp n) (integerp m)) + (equal (mod (- m) n) + (- (1- n) (mod (1- m) n))))) +) + +;;;********************************************************************** +;;; CHOP +;;;********************************************************************** + +(defsection-rtl |Chop| |Basic Arithmetic Functions| + +(defund chop (x k) + (declare (xargs :guard (and (real/rationalp x) + (integerp k)))) + (/ (fl (* (expt 2 k) x)) (expt 2 k))) + +(defthmd chop-mod + (implies (and (rationalp x) + (integerp k)) + (equal (chop x k) + (- x (mod x (expt 2 (- k))))))) + +(defthm chop-down + (implies (and (rationalp x) + (integerp n)) + (<= (chop x n) x)) + :rule-classes ()) + +(defthm chop-monotone + (implies (and (rationalp x) + (rationalp y) + (integerp n) + (<= x y)) + (<= (chop x n) (chop y n))) + :rule-classes ()) + +(defthmd chop-chop + (implies (and (rationalp x) + (integerp k) + (integerp m) + (<= k m)) + (and (equal (chop (chop x m) k) + (chop x k)) + (equal (chop (chop x k) m) + (chop x k)) + (<= (chop x k) (chop x m))))) + +(defthmd chop-plus + (implies (and (rationalp x) + (rationalp y) + (integerp k)) + (and (equal (chop (+ x (chop y k)) k) + (+ (chop x k) (chop y k))) + (equal (chop (+ (chop x k) (chop y k)) k) + (+ (chop x k) (chop y k))) + (equal (chop (- x (chop y k)) k) + (- (chop x k) (chop y k))) + (equal (chop (- (chop x k) (chop y k)) k) + (- (chop x k) (chop y k)))))) + +(defthmd chop-shift + (implies (and (rationalp x) + (integerp k) + (integerp m)) + (equal (chop (* (expt 2 k) x) m) + (* (expt 2 k) (chop x (+ k m)))))) + + + +(defthm chop-bound + (implies (and (rationalp x) + (integerp n) + (natp m)) + (iff (<= n x) (<= n (chop x m)))) + :rule-classes ()) + +(defthmd chop-small + (implies (and (rationalp x) + (integerp m) + (< x (expt 2 (- m))) + (<= (- (expt 2 (- m))) x)) + (equal (chop x m) + (if (>= x 0) + 0 + (- (expt 2 (- m))))))) + +(defthm chop-0 + (implies (and (rationalp x) + (integerp m) + (< (abs (chop x m)) (expt 2 (- m)))) + (equal (chop x m) 0))) + +(defthm chop-int-bounds + (implies (and (natp k) + (natp n) + (rationalp x)) + (and (<= (chop (fl (/ x (expt 2 n))) (- k)) + (/ (chop x (- k)) (expt 2 n))) + (<= (/ (+ (chop x (- k)) (expt 2 k)) + (expt 2 n)) + (+ (chop (fl (/ x (expt 2 n))) (- k)) + (expt 2 k))))) + :rule-classes ()) + +(defthmd chop-int-neg + (implies (and (natp k) + (natp n) + (rationalp x) + (rationalp y) + (= (fl (/ x (expt 2 k))) + (fl (/ y (expt 2 k)))) + (not (integerp (/ x (expt 2 k))))) + (equal (chop (1- (- (fl (/ y (expt 2 n))))) (- k)) + (chop (- (/ x (expt 2 n))) (- k))))) + +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/bits.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/bits.lisp new file mode 100644 index 000000000..d29ca8088 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/bits.lisp @@ -0,0 +1,1140 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; BVECP +;;;********************************************************************** + +(defsection-rtl |Recognizing Bit Vectors| |Bit Vectors| + +(defund bvecp (x k) + (declare (xargs :guard (integerp k))) + (and (integerp x) + (<= 0 x) + (< x (expt 2 k)))) + +(defthm bvecp-forward + (implies (bvecp x k) + (and (integerp x) + (<= 0 x) + (< x (expt 2 k)))) + :rule-classes :forward-chaining) + +(defun nats (n) + (declare (xargs :guard (natp n))) + (if (zp n) () (cons (1- n) (nats (1- n))))) + +(defthm bvecp-member + (implies (and (natp n) + (bvecp x n)) + (member x (nats (expt 2 n)))) + :rule-classes ()) + +(defthmd bvecp-monotone + (implies (and (bvecp x n) + (<= n m) + (case-split (integerp m))) + (bvecp x m))) + +(defthmd bvecp-shift-down + (implies (and (bvecp x n) + (natp n) + (natp k)) + (bvecp (fl (/ x (expt 2 k))) (- n k)))) + +(defthmd bvecp-shift-up + (implies (and (bvecp x (- n k)) + (natp k) + (integerp n)) + (bvecp (* x (expt 2 k)) n))) + +(defthm bvecp-product + (implies (and (bvecp x m) + (bvecp y n)) + (bvecp (* x y) (+ m n))) + :rule-classes ()) + +(defthm bvecp-1-0 + (implies (and (bvecp x 1) + (not (equal x 1))) + (equal x 0)) + :rule-classes :forward-chaining) + +(defthm bvecp-0-1 + (implies (and (bvecp x 1) + (not (equal x 0))) + (equal x 1)) + :rule-classes :forward-chaining) +) + +;;;********************************************************************** +;;; BITS +;;;********************************************************************** + +(defsection-rtl |Bit Slices| |Bit Vectors| + +(defund bits (x i j) + (declare (xargs :guard (and (integerp x) + (integerp i) + (integerp j)))) + (mbe :logic (if (or (not (integerp i)) + (not (integerp j))) + 0 + (fl (/ (mod x (expt 2 (1+ i))) (expt 2 j)))) + :exec (if (< i j) + 0 + (logand (ash x (- j)) (1- (ash 1 (1+ (- i j)))))))) + +(defthm bits-nonnegative-integerp-type + (and (<= 0 (bits x i j)) + (integerp (bits x i j))) + :rule-classes (:type-prescription)) + +(in-theory (disable (:type-prescription bits))) + +(defthm bits-bvecp + (implies (and (<= (+ 1 i (- j)) k) + (case-split (integerp k))) + (bvecp (bits x i j) k))) + +;;Here is a variation of bits-bvecp that is less general but does not +;;require an integerp hypothesis: + +(defthm bits-bvecp-simple + (implies (equal k (+ 1 i (* -1 j))) + (bvecp (bits x i j) k))) + +(defthm bits-bounds + (implies (and (integerp i) + (integerp j)) + (and (natp (bits x i j)) + (< (bits x i j) (expt 2 (1+ (- i j)))))) + :rule-classes()) + +(defthmd bits-upper-bound + (implies (and (integerp i) + (integerp j)) + (< (bits x i j) + (expt 2 (1+ (- i j))))) + :rule-classes :linear) + +(defthm mod-bits-equal + (implies (= (mod x (expt 2 (1+ i))) + (mod y (expt 2 (1+ i)))) + (= (bits x i j) (bits y i j))) + :rule-classes ()) + +(defthmd mod-bits-equal-cor + (implies (and (integerp x) + (integerp n) + (integerp i) + (integerp j) + (< i n)) + (equal (bits (mod x (expt 2 n)) i j) + (bits x i j)))) + +(defthmd bits-mod + (implies (and (case-split (integerp x)) + (case-split (integerp i))) + (equal (bits x i 0) + (mod x (expt 2 (1+ i)))))) + +(defthm bits-diff-equal + (implies (and (natp n) + (integerp x) + (integerp y) + (< (abs (- x y)) (expt 2 n))) + (iff (= x y) + (= (bits (- x y) (1- n) 0) 0))) + :rule-classes ()) + +(defthm bits-tail + (implies (and (bvecp x (1+ i)) + (case-split (acl2-numberp i))) + (equal (bits x i 0) x))) + +(defthm bits-tail-gen + (implies (and (integerp x) + (natp i) + (< x (expt 2 i)) + (>= x (- (expt 2 (+ 1 i))))) + (equal (bits x i 0) + (if (>= x 0) + x + (+ x (expt 2 (+ 1 i))))))) + +(defthmd neg-bits-1 + (implies (and (integerp x) + (natp i) + (natp j) + (< x 0) + (>= x (- (expt 2 j))) + (>= i j)) + (equal (bits x i j) + (1- (expt 2 (1+ (- i j))))))) + +(defthmd bits-top-ones + (implies (and (natp i) + (natp j) + (>= i j) + (natp x) + (< x (expt 2 (1+ i))) + (>= x (- (expt 2 (1+ i)) (expt 2 j)))) + (equal (bits x i j) + (1- (expt 2 (- (1+ i) j)))))) + +(defthm bits-bits-sum + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j) + (integerp k) + (>= j 0) + (>= k i)) + (equal (bits (+ (bits x k 0) y) i j) + (bits (+ x y) i j)))) + +(defthm bits-bits-sum-alt + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j) + (integerp k) + (>= j 0) + (>= k i)) + (equal (bits (+ x (bits y k 0)) i j) + (bits (+ x y) i j)))) + +(defthmd bits-bits-diff + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j) + (integerp k) + (>= j 0) + (>= k i)) + (equal (bits (+ x (- (bits y k 0))) i j) + (bits (- x y) i j)))) + +(defthmd bits-bits-prod + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j) + (integerp k) + (>= j 0) + (>= k i)) + (equal (bits (* x (bits y k 0)) i j) + (bits (* x y) i j)))) + + +(defthm bits-fl-diff + (implies (and (integerp x) + (integerp i) + (integerp j) + (>= i j)) + (equal (bits x (1- i) j) + (- (fl (/ x (expt 2 j))) + (* (expt 2 (- i j)) + (fl (/ x (expt 2 i))))))) + :rule-classes ()) + +(defthmd bits-fl-diff-alt + (implies (and (integerp x) + (integerp i) + (integerp j) + (>= i (1- j))) + (equal (bits x i j) + (- (fl (/ x (expt 2 j))) + (* (expt 2 (- (1+ i) j)) + (fl (/ x (expt 2 (1+ i))))))))) + +(defthm bits-mod-fl + (implies (and (integerp i) + (integerp j)) + (equal (bits x (1- i) j) + (mod (fl (/ x (expt 2 j))) + (expt 2 (- i j))))) + :rule-classes ()) + +(defthm bits-neg-indices + (implies (and (< i 0) + (integerp x)) + (equal (bits x i j) 0))) + +(defthm bits-reverse-indices + (implies (< i j) + (equal (bits x i j) + 0))) + +(defthmd bvecp-bits-0 + (implies (bvecp x j) + (equal (bits x i j) 0))) + +(defthm bits-0 + (equal (bits 0 i j) 0)) + +(defthmd bits-shift-down-1 + (implies (and (<= 0 j) + (integerp i) + (integerp j) + (integerp k)) + (equal (bits (fl (/ x (expt 2 k))) i j) + (bits x (+ i k) (+ j k))))) + +(defthmd bits-shift-down-2 + (implies (and (integerp x) + (natp i) + (natp k)) + (equal (fl (/ (bits x (+ i k) 0) (expt 2 k))) + (bits (fl (/ x (expt 2 k))) i 0)))) + +(defthmd bits-shift-up-1 + (implies (and (integerp k) + (integerp i) + (integerp j)) + (equal (bits (* (expt 2 k) x) i j) + (bits x (- i k) (- j k))))) + +(defthmd bits-shift-up-2 + (implies (and (integerp x) + (natp k) + (integerp i)) + (equal (* (expt 2 k) (bits x i 0)) + (bits (* (expt 2 k) x) (+ i k) 0)))) + +(defthmd bits-plus-mult-1 + (implies (and (bvecp x k) + (<= k m) + (integerp y) + (case-split (integerp m)) + (case-split (integerp n)) + (case-split (integerp k))) + (equal (bits (+ x (* y (expt 2 k))) n m) + (bits y (- n k) (- m k))))) + +(defthmd bits-plus-mult-2 + (implies (and (< n k) + (integerp y) + (integerp k)) + (equal (bits (+ x (* y (expt 2 k))) n m) + (bits x n m)))) + +(defthmd bits-plus-mult-2-rewrite + (implies (and (syntaxp (quotep c)) + (equal (mod c (expt 2 (1+ n))) 0)) + (equal (bits (+ c x) n m) + (bits x n m)))) + +(defthm bits-plus-bits + (implies (and (integerp m) + (integerp p) + (integerp n) + (<= m p) + (<= p n)) + (= (bits x n m) + (+ (bits x (1- p) m) + (* (expt 2 (- p m)) (bits x n p))))) + :rule-classes ()) + +(defthm bits-bits + (implies (and (case-split (<= 0 l)) + (case-split (integerp i)) + (case-split (integerp j)) + (case-split (integerp k)) + (case-split (integerp l))) + (equal (bits (bits x i j) k l) + (if (<= k (- i j)) + (bits x (+ k j) (+ l j)) + (bits x i (+ l j)))))) + +;;bits-match can prove things like this: +;;(thm (implies (equal 12 (bits x 15 6)) +;; (equal 4 (bits x 8 6)))) + +(defthmd bits-match + (implies (and (syntaxp (and (quotep i) + (quotep j) + (quotep k))) + (equal (bits x i2 j2) k2) ;i2, j2, and k2 are free variables + (syntaxp (and (quotep i2) + (quotep j2) + (quotep k2))) + (<= j2 j) (<= j i) (<= i i2) + (equal k (bits k2 (+ i (- j2)) (+ (- j2) j))) + (<= 0 i) (<= 0 j) (<= 0 k) (<= 0 i2) (<= 0 j2) (<= 0 k2) + (integerp i) (integerp j) (integerp k) (integerp i2) (integerp j2) (integerp k2)) + (equal (equal k (bits x i j)) + t))) + +;;bits-dont-match can prove things like this: +;;(thm (implies (equal 7 (bits x 8 6)) +;; (not (equal 4 (bits x 15 6))))) + +(defthmd bits-dont-match + (implies (and (syntaxp (and (quotep i) + (quotep j) + (quotep k))) + (equal (bits x i2 j2) k2) ;i2, j2, and k2 are free vars + (syntaxp (and (quotep i2) + (quotep j2) + (quotep k2))) + (<= j2 j) (<= j i) (<= i i2) + (not (equal k (bits k2 (+ i (- j2)) (+ (- j2) j)))) + (<= 0 i) (<= 0 j) (<= 0 k) (<= 0 i2) (<= 0 j2) (<= 0 k2) + (integerp i) (integerp j) (integerp k) (integerp i2) (integerp j2) (integerp k2)) + (equal (equal k (bits x i j)) + nil))) +) + +;;;********************************************************************** +;;; BITN +;;;********************************************************************** + +(defsection-rtl |Bit Extraction| |Bit Vectors| + +(defund bitn (x n) + (declare (xargs :guard (and (integerp x) + (integerp n)))) + (mbe :logic (bits x n n) + :exec (if (evenp (ash x (- n))) 0 1))) + +(defthm bitn-nonnegative-integer + (and (integerp (bitn x n)) + (<= 0 (bitn x n))) + :rule-classes (:type-prescription)) + +(in-theory (disable (:type-prescription bitn))) + +(defthm bits-n-n-rewrite + (equal (bits x n n) + (bitn x n))) + +(defthmd bitn-def + (implies (case-split (integerp n)) + (equal (bitn x n) + (mod (fl (/ x (expt 2 n))) 2)))) + +;;A recursive formulation: + +(defthmd bitn-rec-0 + (implies (integerp x) + (equal (bitn x 0) (mod x 2)))) + +(defthmd bitn-rec-pos + (implies (< 0 n) + (equal (bitn x n) + (bitn (fl (/ x 2)) (1- n)))) + :rule-classes ((:definition :controller-alist ((bitn t t))))) + +;;Use this to induce case-splitting: + +(defthm bitn-0-1 + (or (equal (bitn x n) 0) + (equal (bitn x n) 1)) + :rule-classes ()) + +(defthm bitn-bvecp + (implies (and (<= 1 k) + (case-split (integerp k))) + (bvecp (bitn x n) k))) + +;;The following is a special case of bitn-bvecp. +;;It is useful as a :forward-chaining rule in concert with bvecp-0-1 and +;;bvecp-1-0. + +(defthm bitn-bvecp-forward + (bvecp (bitn x n) 1) + :rule-classes ((:forward-chaining :trigger-terms ((bitn x n))))) + +(defthm bitn-neg + (implies (and (< n 0) + (integerp x)) + (equal (bitn x n) 0))) + +(defthm bitn-0 + (equal (bitn 0 k) 0)) + +(defthm bitn-bvecp-1 + (implies (bvecp x 1) + (equal (bitn x 0) x))) + +(defthm bitn-bitn-0 + (equal (bitn (bitn x n) 0) + (bitn x n))) + +(defthmd bitn-mod + (implies (and (< k n) + (integerp n) + (integerp k)) + (equal (bitn (mod x (expt 2 n)) k) + (bitn x k)))) + +(defthm bvecp-bitn-0 + (implies (bvecp x n) + (equal (bitn x n) 0))) + +(defthm neg-bitn-1 + (implies (and (integerp x) + (integerp n) + (< x 0) + (>= x (- (expt 2 n)))) + (equal (bitn x n) 1))) + +(defthmd bitn-minus-1 + (implies (natp i) + (equal (bitn -1 i) 1))) + +;; The rewrite rule neg-bitn-2 has the hypotheses (integerp n) and (< x (- (expt 2 k) (expt 2 n))), +;; where n does not occur in the lhs. When n is bound to a large integer, (expt 2 n) blows up. + +(defthmd neg-bitn-2 + (implies (and (integerp x) + (integerp n) + (integerp k) + (< k n) + (< x (- (expt 2 k) (expt 2 n))) + (>= x (- (expt 2 n)))) + (equal (bitn x k) 0))) + +(defthm neg-bitn-0 + (implies (and (integerp x) + (natp n) + (< x (- (expt 2 n))) + (>= x (- (expt 2 (1+ n))))) + (equal (bitn x n) 0))) + +(defthmd bitn-shift-up + (implies (and (integerp n) + (integerp k)) + (equal (bitn (* x (expt 2 k)) (+ n k)) + (bitn x n)))) + +(defthmd bitn-shift-down + (implies (and (natp i) + (integerp k)) + (equal (bitn (fl (/ x (expt 2 k))) i) + (bitn x (+ i k))))) + +(defthmd bitn-bits + (implies (and (<= k (- i j)) + (case-split (<= 0 k)) + (case-split (integerp i)) + (case-split (integerp j)) + (case-split (integerp k))) + (equal (bitn (bits x i j) k) + (bitn x (+ j k))))) + +(defthm bitn-plus-bits + (implies (and (<= m n) + (integerp m) + (integerp n)) + (= (bits x n m) + (+ (* (bitn x n) (expt 2 (- n m))) + (bits x (1- n) m)))) + :rule-classes ()) + +(defthm bits-plus-bitn + (implies (and (<= m n) + (integerp m) + (integerp n)) + (= (bits x n m) + (+ (bitn x m) + (* 2 (bits x n (1+ m)))))) + :rule-classes ()) + +(defun sumbits (x n) + (declare (xargs :guard (and (integerp x) + (natp n)))) + (if (zp n) + 0 + (+ (* (expt 2 (1- n)) (bitn x (1- n))) + (sumbits x (1- n))))) + +(defthmd sumbits-bits + (implies (and (integerp x) + (natp n) + (> n 0)) + (equal (sumbits x n) + (bits x (1- n) 0)))) + +(defthmd sumbits-thm + (implies (and (bvecp x n) + (natp n) + (> n 0)) + (equal (sumbits x n) + x))) + +(defnd all-bits-p (b k) + (if (posp k) + (and (consp b) + (all-bits-p (cdr b) (1- k)) + (or (equal (car b) 0) + (equal (car b) 1))) + (and (true-listp b) + (equal k 0)))) + +(defun sum-b (b k) + (declare (xargs :guard (all-bits-p b k))) + (if (zp k) + 0 + (+ (* (expt 2 (1- k)) (nth (1- k) b)) + (sum-b b (1- k))))) + +(defthmd sum-bitn + (implies (and (all-bits-p b n) + (natp k) + (< k n)) + (equal (bitn (sum-b b n) k) + (nth k b)))) + +;; The next lemma can be used to prove equality of two bit vectors by +;; proving that they have the same value at bit n for all n. + +(defn bit-diff (x y) + (declare (xargs :measure (:? x y))) + (if (or (not (integerp x)) + (not (integerp y)) + (= x y)) + () + (if (= (bitn x 0) (bitn y 0)) + (1+ (bit-diff (fl (/ x 2)) (fl (/ y 2)))) + 0))) + +(defthm bit-diff-diff + (implies (and (integerp x) + (integerp y) + (not (= x y))) + (let ((n (bit-diff x y))) + (and (natp n) + (not (= (bitn x n) (bitn y n)))))) + :rule-classes ()) + +(defthmd bvecp-bitn-1 + (implies (and (bvecp x (1+ n)) + (<= (expt 2 n) x) + (natp n)) + (equal (bitn x n) 1))) + +(defthmd bvecp-bitn-2 + (implies (and (bvecp x n) + (< k n) + (<= (- (expt 2 n) (expt 2 k)) x) + (integerp n) + (integerp k)) + (equal (bitn x k) 1)) + :rule-classes ((:rewrite :match-free :all))) + +(defthmd bitn-expt + (implies (case-split (integerp n)) + (equal (bitn (expt 2 n) n) + 1))) + +(defthmd bitn-expt-0 + (implies (and (not (equal i n)) + (case-split (integerp i))) + (equal (bitn (expt 2 i) n) + 0))) + +(defthm bitn-plus-expt-1 + (implies (and (rationalp x) + (integerp n)) + (not (equal (bitn (+ x (expt 2 n)) n) + (bitn x n)))) + :rule-classes ()) + +(defthmd bitn-plus-mult + (implies (and (< n m) + (integerp m) + (integerp k)) + (equal (bitn (+ x (* k (expt 2 m))) n) + (bitn x n)))) + +(defthmd bitn-plus-mult-rewrite + (implies (and (syntaxp (quotep c)) + (equal (mod c (expt 2 (1+ n))) 0)) + (equal (bitn (+ c x) n) + (bitn x n)))) +) + +;;;********************************************************************** +;;; CAT +;;;********************************************************************** + +(defsection-rtl |Concatenation| |Bit Vectors| + +(defund binary-cat (x m y n) + (declare (xargs :guard (and (integerp x) + (integerp y) + (natp m) + (natp n)))) + (if (and (natp m) (natp n)) + (+ (* (expt 2 n) (bits x (1- m) 0)) + (bits y (1- n) 0)) + 0)) + +;; We define a macro, CAT, that takes a list of alternating data values and +;; sizes. CAT-SIZE returns the formal sum of the sizes. The list must contain +;; at least 1 data/size pair, but we do not need to specify this in the guard, +;; and leaving it out of the guard simplifies the guard proof. + +(defn formal-+ (x y) + (if (and (acl2-numberp x) (acl2-numberp y)) + (+ x y) + (list '+ x y))) + +(defun cat-size (x) + (declare (xargs :guard (and (true-listp x) + (evenp (length x))))) + (if (endp (cddr x)) + (cadr x) + (formal-+ (cadr x) + (cat-size (cddr x))))) + +(defmacro cat (&rest x) + (declare (xargs :guard (and x (true-listp x) (evenp (length x))))) + (cond ((endp (cddr x)) + `(bits ,(car x) ,(formal-+ -1 (cadr x)) 0)) + ((endp (cddddr x)) + `(binary-cat ,@x)) + (t + `(binary-cat ,(car x) + ,(cadr x) + (cat ,@(cddr x)) + ,(cat-size (cddr x)))))) + +(defthm cat-nonnegative-integer-type + (and (integerp (cat x m y n)) + (<= 0 (cat x m y n))) + :rule-classes (:type-prescription)) + +(in-theory (disable (:type-prescription binary-cat))) + +(defthm cat-bvecp + (implies (and (<= (+ m n) k) + (case-split (integerp k))) + (bvecp (cat x m y n) k))) + +(defthm cat-with-n-0 + (equal (binary-cat x m y 0) + (bits x (1- m) 0))) + +(defthm cat-with-m-0 + (equal (binary-cat x 0 y n) + (bits y (1- n) 0))) + +(defthmd cat-0 + (implies (and (case-split (bvecp y n)) + (case-split (integerp n)) + (case-split (integerp m)) + (case-split (<= 0 m))) + (equal (cat 0 m y n) y))) + +(defthmd cat-bits-1 + (equal (cat (bits x (1- m) 0) m y n) + (cat x m y n))) + +(defthmd cat-bits-2 + (equal (cat x m (bits y (1- n) 0) n) + (cat x m y n))) + +(defthm cat-bits-3 + (implies (and (integerp i) (integerp m) (>= i (1- m))) + (equal (cat (bits x i 0) m y n) + (cat x m y n)))) + +(defthm cat-bits-4 + (implies (and (integerp i) (integerp n) (>= i (1- n))) + (equal (cat x m (bits y i 0) n) + (cat x m y n)))) + +(defthm cat-associative + (implies (and (case-split (<= (+ m n) p)) + (case-split (<= 0 m)) + (case-split (<= 0 n)) + (case-split (<= 0 q)) + (case-split (integerp m)) + (case-split (integerp n)) + (case-split (integerp p)) + (case-split (integerp q))) + (equal (cat (cat x m y n) p z q) + (cat x m (cat y n z q) (+ n q))))) + +(defthmd cat-equal-constant + (implies (and (syntaxp (and (quotep k) + (quotep m) + (quotep n))) + (case-split (bvecp y n)) + (case-split (bvecp x m)) + (case-split (< k (expt 2 (+ m n)))) ;not a problem hyp, since k, m and n are constants + (case-split (integerp k)) + (case-split (<= 0 k)) + (case-split (integerp m)) + (case-split (<= 0 m)) + (case-split (integerp n)) + (case-split (<= 0 n))) + (equal (equal k (cat x m y n)) + (and (equal y (bits k (1- n) 0)) + (equal x (bits k (+ -1 m n) n)))))) + +(defthmd cat-equal-rewrite + (implies (and (case-split (bvecp x1 m)) + (case-split (bvecp y1 n)) + (case-split (bvecp x2 m)) + (case-split (bvecp y2 n)) + (case-split (integerp n)) + (case-split (<= 0 n)) + (case-split (integerp m)) + (case-split (<= 0 m))) + (equal (equal (cat x1 m y1 n) + (cat x2 m y2 n)) + (and (equal x1 x2) + (equal y1 y2))))) + +(defthm cat-bits-bits + (implies (and (equal j (1+ k)) + (equal n (+ 1 (- l) k)) + (case-split (<= (+ 1 (- j) i) m)) + (case-split (<= j i)) + (case-split (<= l k)) + (case-split (integerp i)) + (case-split (integerp k)) + (case-split (integerp l)) + (case-split (integerp m))) + (equal (cat (bits x i j) m (bits x k l) n) + (bits x i l)))) + +(defthm cat-bitn-bits + (implies (and (equal j (1+ k)) + (equal n (+ 1 (- l) k)) + (case-split (<= 1 m)) + (case-split (<= l k)) + (case-split (integerp j)) + (case-split (integerp k)) + (case-split (integerp l)) + (case-split (integerp m))) + (equal (cat (bitn x j) m (bits x k l) n) + (bits x j l)))) + +(defthm cat-bits-bitn + (implies (and (equal j (1+ k)) + (case-split (<= (+ 1 (- j) i) m)) + (case-split (<= j i)) + (case-split (integerp i)) + (case-split (integerp j)) + (case-split (integerp k)) + (case-split (integerp m))) + (equal (cat (bits x i j) m (bitn x k) 1) + (bits x i k)))) + +(defthm cat-bitn-bitn + (implies (and (equal i (1+ j)) + (case-split (integerp i)) + (case-split (integerp j))) + (equal (cat (bitn x i) 1 (bitn x j) 1) + (bits x i j)))) + +(defthmd bits-cat + (implies (and (case-split (natp n)) + (case-split (natp m)) + (case-split (natp i)) + (case-split (natp j))) + (equal (bits (cat x m y n) i j) + (if (< i n) + (bits y i j) + (if (>= j n) + (bits x (if (< i (+ m n)) + (- i n) + (1- m)) + (- j n)) + (cat (bits x (if (< i (+ m n)) + (- i n) + (1- m)) 0) + (1+ (- i n)) + (bits y (1- n) j) + (- n j))))))) + +(defthm bits-cat-constants + (implies (and (syntaxp (quotep n)) + (syntaxp (quotep m)) + (syntaxp (quotep i)) + (syntaxp (quotep j)) + (natp n) + (natp m) + (natp i) + (natp j)) + (equal (bits (cat x m y n) i j) + (if (< i n) + (bits y i j) + (if (>= j n) + (bits x (if (< i (+ m n)) + (- i n) + (1- m)) + (- j n)) + (cat (bits x (if (< i (+ m n)) + (- i n) + (1- m)) 0) + (1+ (- i n)) + (bits y (1- n) j) + (- n j))))))) + +(defthmd bitn-cat + (implies (and (case-split (natp n)) + (case-split (natp m)) + (case-split (natp i))) + (equal (bitn (cat x m y n) i) + (if (< i n) + (bitn y i) + (if (< i (+ m n)) + (bitn x (- i n)) + 0))))) + +(defthm bitn-cat-constants + (implies (and (syntaxp (quotep n)) + (syntaxp (quotep m)) + (syntaxp (quotep i)) + (natp n) + (natp m) + (natp i)) + (equal (bitn (cat x m y n) i) + (if (< i n) + (bitn y i) + (if (< i (+ m n)) + (bitn x (- i n)) + 0))))) + +(defund mulcat (l n x) + (declare (xargs :guard (and (natp l) + (natp n) + (natp x)))) + (if (and (integerp n) (> n 0)) + (cat (mulcat l (1- n) x) + (* l (1- n)) + x + l) + 0)) + +(defthm mulcat-nonnegative-integer-type + (and (integerp (mulcat l n x)) + (<= 0 (mulcat l n x))) + :rule-classes (:type-prescription)) + +(in-theory (disable (:type-prescription mulcat))) + +(defthmd mulcat-bits + (implies (and (integerp l) + (integerp x)) + (equal (mulcat l n (bits x (1- l) 0)) + (mulcat l n x)))) + +(defthm mulcat-bvecp + (implies (and (>= p (* l n)) + (case-split (integerp p)) + (case-split (natp l))) + (bvecp (mulcat l n x) p))) + +(defthm mulcat-1 + (implies (natp l) + (equal (mulcat l 1 x) + (bits x (1- l) 0)))) + +(defthm mulcat-0 + (equal (mulcat l n 0) 0)) + +(defthm mulcat-n-1 + (implies (case-split (<= 0 n)) + (equal (mulcat 1 n 1) + (1- (expt 2 n))))) + +(defthm bitn-mulcat-1 + (implies (and (< m n) + (case-split (bvecp x 1)) + (case-split (natp m)) + (case-split (integerp n))) + (equal (bitn (mulcat 1 n x) m) + x))) +) + +;;;********************************************************************** +;;; Signed Integer and Fixed-Point Encodings +;;;********************************************************************** + +(defsection-rtl |Signed Integer Formats| |Bit Vectors| + +(defnd ui (r) r) + +(defund si (r n) + (declare (xargs :guard (and (integerp r) + (natp n)))) + (if (= (bitn r (1- n)) 1) + (- r (expt 2 n)) + r)) + +(defthm int-si + (implies (and (integerp r) + (natp n)) + (integerp (si r n))) + :rule-classes (:type-prescription :rewrite)) + +(defthm si-bits + (implies (and (integerp x) + (natp n) + (< x (expt 2 (1- n))) + (>= x (- (expt 2 (1- n))))) + (= (si (bits x (1- n) 0) n) + x)) + :rule-classes ()) + +(defthmd bits-si + (implies (and (integerp n) + (< i n)) + (equal (bits (si r n) i j) + (bits r i j)))) + +(defthmd si-shift + (implies (and (natp n) + (natp k) + (bvecp r n)) + (equal (si (* (expt 2 k) r) (+ k n)) + (* (expt 2 k) (si r n))))) + +(defund sextend (m n r) + (declare (xargs :guard (and (natp m) + (natp n) + (integerp r)))) + (bits (si r n) (1- m) 0)) + +(defthmd si-sextend + (implies (and (natp n) + (natp m) + (<= n m) + (bvecp r n)) + (equal (si (sextend m n r) m) + (si r n)))) + +(defthmd si-approx + (implies (and (not (zp n)) + (integerp x) + (integerp y) + (< (abs (si (mod x (expt 2 n)) n)) + (- (expt 2 (1- n)) (abs (- x y))))) + (equal (- (si (mod x (expt 2 n)) n) + (si (mod y (expt 2 n)) n)) + (- x y)))) + +(defthmd si-to-fl-mod + (implies (and (rationalp x) + (integerp m) + (integerp n) + (< m n)) + (equal (si x n) + (+ (* (expt 2 m) + (si (fl (/ x (expt 2 m))) + (- n m))) + (mod x (expt 2 m)))))) + +;;;********************************************************************** +;;; Fixed-Point Registers +;;;********************************************************************** + +(defund uf (r n m) + (declare (xargs :guard (and (natp r) + (natp n) + (natp m)))) + (* (expt 2 (- m n)) (ui r))) + +(defund sf (r n m) + (declare (xargs :guard (and (integerp r) + (natp n) + (natp m)))) + (* (expt 2 (- m n)) (si r n))) + +(defthmd bits-uf + (let ((x (uf r n m)) + (f (- n m))) + (implies (and (natp n) + (natp m) + (<= m n) + (bvecp r n) + (natp i) + (natp j) + (<= j i)) + (equal (bits r i j) + (* (expt 2 (- f j)) + (- (chop x (- f j)) + (chop x (- f (1+ i))))))))) + +(defthmd bits-sf + (let ((x (sf r n m)) + (f (- n m))) + (implies (and (natp n) + (natp m) + (<= m n) + (bvecp r n) + (natp i) + (natp j) + (<= j i) + (< i n)) + (equal (bits r i j) + (* (expt 2 (- f j)) + (- (chop x (- f j)) + (chop x (- f (1+ i))))))))) + +(defthm chop-uf + (let ((x (uf r n m)) + (f (- n m))) + (implies (and (natp n) + (natp m) + (<= m n) + (bvecp r n) + (integerp k) + (<= (- f n) k) + (< k f)) + (iff (= (chop x k) x) + (= (bits r (1- (- f k)) 0) 0)))) + :rule-classes ()) + +(defthm chop-sf + (let ((x (sf r n m)) + (f (- n m))) + (implies (and (natp n) + (natp m) + (<= m n) + (bvecp r n) + (integerp k) + (<= (- f n) k) + (< k f)) + (iff (= (chop x k) x) + (= (bits r (1- (- f k)) 0) 0)))) + :rule-classes ()) + +(defthmd sf-val + (implies (and (natp n) + (natp m) + (<= m n) + (bvecp r n) + (integerp y) + (= (mod y (expt 2 n)) r) + (<= (- (expt 2 (1- n))) y) + (< y (expt 2 (1- n)))) + (equal (sf r n m) + (* (expt 2 (- m n)) y)))) +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/defs.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/defs.lisp new file mode 100644 index 000000000..dc227c08b --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/defs.lisp @@ -0,0 +1,542 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com +; +; See license file books/rtl/rel11/license.txt. +; + +;; This file contains definitions that are shared between books of lib. + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(defund fl (x) + (declare (xargs :guard (real/rationalp x))) + (floor x 1)) + +(defund cg (x) + (declare (xargs :guard (real/rationalp x))) + (- (fl (- x)))) + +(defund congruent (a b n) + (declare (xargs :guard (and (real/rationalp a) + (real/rationalp b) + (real/rationalp n) + (not (= n 0))))) + (equal (mod a n) (mod b n))) + +(defund chop (x k) + (declare (xargs :guard (and (real/rationalp x) + (integerp k)))) + (/ (fl (* (expt 2 k) x)) (expt 2 k))) + + + +(defund bvecp (x k) + (declare (xargs :guard (integerp k))) + (and (integerp x) + (<= 0 x) + (< x (expt 2 k)))) + +(defund bits (x i j) + (declare (xargs :guard (and (integerp x) + (integerp i) + (integerp j)))) + (mbe :logic (if (or (not (integerp i)) + (not (integerp j))) + 0 + (fl (/ (mod x (expt 2 (1+ i))) (expt 2 j)))) + :exec (if (< i j) + 0 + (logand (ash x (- j)) (1- (ash 1 (1+ (- i j)))))))) + +(defund bitn (x n) + (declare (xargs :guard (and (integerp x) + (integerp n)))) + (mbe :logic (bits x n n) + :exec (if (evenp (ash x (- n))) 0 1))) + +(defund binary-cat (x m y n) + (declare (xargs :guard (and (integerp x) + (integerp y) + (natp m) + (natp n)))) + (if (and (natp m) (natp n)) + (+ (* (expt 2 n) (bits x (1- m) 0)) + (bits y (1- n) 0)) + 0)) + +(defn formal-+ (x y) + (if (and (acl2-numberp x) (acl2-numberp y)) + (+ x y) + (list '+ x y))) + +(defun cat-size (x) + (declare (xargs :guard (and (true-listp x) + (evenp (length x))))) + (if (endp (cddr x)) + (cadr x) + (formal-+ (cadr x) + (cat-size (cddr x))))) + +(defmacro cat (&rest x) + (declare (xargs :guard (and x (true-listp x) (evenp (length x))))) + (cond ((endp (cddr x)) + `(bits ,(car x) ,(formal-+ -1 (cadr x)) 0)) + ((endp (cddddr x)) + `(binary-cat ,@x)) + (t + `(binary-cat ,(car x) + ,(cadr x) + (cat ,@(cddr x)) + ,(cat-size (cddr x)))))) + +(defund mulcat (l n x) + (declare (xargs :guard (and (natp l) + (natp n) + (natp x)))) + (if (and (integerp n) (> n 0)) + (cat (mulcat l (1- n) x) + (* l (1- n)) + x + l) + 0)) + +(defnd ui (r) r) + +(defund si (r n) + (declare (xargs :guard (and (integerp r) + (natp n)))) + (if (= (bitn r (1- n)) 1) + (- r (expt 2 n)) + r)) + +(defund sextend (m n r) + (declare (xargs :guard (and (natp m) + (natp n) + (integerp r)))) + (bits (si r n) (1- m) 0)) + +(defund uf (r n m) + (declare (xargs :guard (and (natp r) + (natp n) + (natp m)))) + (* (expt 2 (- m n)) (ui r))) + +(defund sf (r n m) + (declare (xargs :guard (and (integerp r) + (natp n) + (natp m)))) + (* (expt 2 (- m n)) (si r n))) + +(defnd sgn (x) + (if (or (not (rationalp x)) (equal x 0)) + 0 + (if (< x 0) -1 +1))) + +; Matt K. addition: needed for e0-ord-< just below +(include-book "ordinals/e0-ordinal" :dir :system) + +(defnd expo (x) + (declare (xargs :measure (:? x) +; Matt K. addition after bug fix to require well-founded relations to match for +; a redundant definition: + :well-founded-relation e0-ord-<)) + (mbe :logic (cond ((or (not (rationalp x)) (equal x 0)) 0) + ((< x 0) (expo (- x))) + ((< x 1) (1- (expo (* 2 x)))) + ((< x 2) 0) + (t (1+ (expo (/ x 2))))) + :exec (if (rationalp x) + (let* ((n (abs (numerator x))) + (d (denominator x)) + (ln (integer-length n)) + (ld (integer-length d)) + (l (- ln ld))) + (if (>= ln ld) + (if (>= (ash n (- l)) d) l (1- l)) + (if (> ln 1) + (if (> n (ash d l)) l (1- l)) + (- (integer-length (1- d)))))) + 0))) + +(defnd sig (x) + (if (rationalp x) + (if (< x 0) + (- (* x (expt 2 (- (expo x))))) + (* x (expt 2 (- (expo x))))) + 0)) + +(defund exactp (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (integerp (* (sig x) (expt 2 (1- n))))) + +(defnd formatp (f) + (and (consp f) + (consp (cdr f)) + (consp (cddr f)) + (natp (cadr f)) + (> (cadr f) 1) + (natp (caddr f)) + (> (caddr f) 1))) + +(defund explicitp (f) + (declare (xargs :guard (formatp f))) + (car f)) + +(defund prec (f) + (declare (xargs :guard (formatp f))) + (cadr f)) + +(defund expw (f) + (declare (xargs :guard (formatp f))) + (caddr f)) + +(defund sigw (f) + (declare (xargs :guard (formatp f))) + (if (explicitp f) + (prec f) + (1- (prec f)))) + +(defnd encodingp (x f) + (and (formatp f) (bvecp x (+ 1 (expw f) (sigw f))))) + +(defnd hp () '(nil 11 5)) + +(defnd sp () '(nil 24 8)) + +(defnd dp () '(nil 53 11)) + +(defnd ep () '(t 64 15)) + +(defnd bf () '(nil 8 8)) + +(in-theory (disable (sp) (dp) (ep) (bf))) + +(defund sgnf (x f) + (declare (xargs :guard (encodingp x f))) + (bitn x (+ (expw f) (sigw f)))) + +(defund expf (x f) + (declare (xargs :guard (encodingp x f))) + (bits x (1- (+ (expw f) (sigw f))) (sigw f))) + +(defund sigf (x f) + (declare (xargs :guard (encodingp x f))) + (bits x (1- (sigw f)) 0)) + +(defund manf (x f) + (declare (xargs :guard (encodingp x f))) + (bits x (- (prec f) 2) 0)) + +(defund bias (f) + (declare (xargs :guard (formatp f))) + (- (expt 2 (- (expw f) 1)) 1)) + +(defund normp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (< 0 (expf x f)) + (< (expf x f) (1- (expt 2 (expw f)))) + (implies (explicitp f) (= (bitn x (1- (prec f))) 1)))) + +(defund unsupp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (explicitp f) + (< 0 (expf x f)) + (= (bitn x (1- (prec f))) 0))) + +(defund ndecode (x f) + (declare (xargs :guard (encodingp x f))) + (* (if (= (sgnf x f) 0) 1 -1) + (expt 2 (- (expf x f) (bias f))) + (1+ (* (manf x f) (expt 2 (- 1 (prec f))))))) + +(defnd nrepp (x f) + (and (rationalp x) + (formatp f) + (not (= x 0)) + (< 0 (+ (expo x) (bias f))) + (< (+ (expo x) (bias f)) (1- (expt 2 (expw f)))) + (exactp x (prec f)))) + +(defund nencode (x f) + (declare (xargs :guard (and (rationalp x) + (formatp f) + (exactp x (prec f))))) + (cat (if (= (sgn x) 1) 0 1) + 1 + (+ (expo x) (bias f)) + (expw f) + (* (sig x) (expt 2 (1- (prec f)))) + (sigw f))) + +(defund spn (f) + (declare (xargs :guard (formatp f))) + (expt 2 (- 1 (bias f)))) + +(defund lpn (f) + (declare (xargs :guard (formatp f))) + (* (expt 2 (- (expt 2 (expw f)) (+ 2 (bias f)))) + (- 2 (expt 2 (- 1 (prec f)))))) + +(defund zerp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) 0) + (= (sigf x f) 0))) + +(defund zencode (sgn f) + (declare (xargs :guard (and (bvecp sgn 1) + (formatp f)))) + (cat sgn 1 0 (+ (sigw f) (expw f)))) + +(defund denormp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) 0) + (not (= (sigf x f) 0)) + (implies (explicitp f) (= (bitn x (1- (prec f))) 0)))) + +(defund pseudop (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (explicitp f) + (= (expf x f) 0) + (= (bitn x (1- (prec f))) 1))) + +(defund ddecode (x f) + (declare (xargs :guard (encodingp x f))) + (* (if (= (sgnf x f) 0) 1 -1) + (sigf x f) + (expt 2 (+ 2 (- (bias f)) (- (prec f)))))) + +(defund decode (x f) + (declare (xargs :guard (encodingp x f))) + (if (= (expf x f) 0) + (ddecode x f) + (ndecode x f))) + +(defnd drepp (x f) + (and (rationalp x) + (formatp f) + (not (= x 0)) + (<= (- 2 (prec f)) (+ (expo x) (bias f))) + (<= (+ (expo x) (bias f)) 0) + (exactp x (+ (1- (prec f)) (bias f) (expo x))))) + +(defund dencode (x f) + (declare (xargs :guard (drepp x f))) + (cat (if (= (sgn x) 1) 0 1) + 1 + 0 + (expw f) + (* (sig x) (expt 2 (+ -2 (prec f) (expo x) (bias f)))) + (sigw f))) + +(defund spd (f) + (declare (xargs :guard (formatp f))) + (expt 2 (+ 2 (- (bias f)) (- (prec f))))) + +(defund infp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) (1- (expt 2 (expw f)))) + (not (unsupp x f)) + (= (manf x f) 0))) + +(defun iencode (sgn f) + (declare (xargs :guard (and (bvecp sgn 1) + (formatp f)))) + (if (explicitp f) + (cat sgn 1 (1- (expt 2 (expw f))) (expw f) 1 1 0 (1- (sigw f))) + (cat sgn 1 (1- (expt 2 (expw f))) (expw f) 0 (sigw f)))) + +(defund nanp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) (1- (expt 2 (expw f)))) + (not (unsupp x f)) + (not (= (manf x f) 0)))) + +(defund qnanp (x f) + (declare (xargs :guard (encodingp x f))) + (and (nanp x f) (= (bitn x (- (prec f) 2)) 1))) + +(defund snanp (x f) + (declare (xargs :guard (encodingp x f))) + (and (nanp x f) (= (bitn x (- (prec f) 2)) 0))) + +(defund qnanize (x f) + (declare (xargs :guard (encodingp x f))) + (logior x (expt 2 (- (prec f) 2)))) + +(defund indef (f) + (declare (xargs :guard (formatp f))) + (if (explicitp f) + (cat (1- (expt 2 (+ (expw f) 2))) + (+ (expw f) 2) + 0 + (- (sigw f) 2)) + (cat (1- (expt 2 (+ (expw f) 1))) + (+ (expw f) 1) + 0 + (1- (sigw f))))) + +(defund rebias (expo old new) + (declare (xargs :guard (and (integerp expo) + (posp old) + (posp new)))) + (+ expo (- (expt 2 (1- new)) (expt 2 (1- old))))) + +(defund rtz (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (* (sgn x) + (fl (* (expt 2 (1- n)) (sig x))) + (expt 2 (- (1+ (expo x)) n)))) + +(defund raz (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (* (sgn x) + (cg (* (expt 2 (1- n)) (sig x))) + (expt 2 (- (1+ (expo x)) n)))) + +(defun re (x) + (declare (xargs :guard (real/rationalp x))) + (- x (fl x))) + +(defund rne (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (let ((z (fl (* (expt 2 (1- n)) (sig x)))) + (f (re (* (expt 2 (1- n)) (sig x))))) + (if (< f 1/2) + (rtz x n) + (if (> f 1/2) + (raz x n) + (if (evenp z) + (rtz x n) + (raz x n)))))) + +(defund rna (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (< (re (* (expt 2 (1- n)) (sig x))) + 1/2) + (rtz x n) + (raz x n))) + +(defund rto (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (exactp x (1- n)) + x + (+ (rtz x (1- n)) + (* (sgn x) (expt 2 (1+ (- (expo x) n))))))) + +(defun rup (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (>= x 0) + (raz x n) + (rtz x n))) + +(defun rdn (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (>= x 0) + (rtz x n) + (raz x n))) + +(defnd IEEE-rounding-mode-p (mode) + (member mode '(rtz rup rdn rne))) + +(defnd common-mode-p (mode) + (or (IEEE-rounding-mode-p mode) (equal mode 'raz) (equal mode 'rna))) + +(defund rnd (x mode n) + (declare (xargs :guard (and (real/rationalp x) + (common-mode-p mode) + (integerp n)))) + (case mode + (raz (raz x n)) + (rna (rna x n)) + (rtz (rtz x n)) + (rup (rup x n)) + (rdn (rdn x n)) + (rne (rne x n)) + (otherwise 0))) + +(defund flip-mode (m) + (declare (xargs :guard (common-mode-p m))) + (case m + (rup 'rdn) + (rdn 'rup) + (t m))) + +(defun rnd-const (e mode n) + (declare (xargs :guard (and (integerp e) + (common-mode-p mode) + (integerp n)))) + (case mode + ((rne rna) (expt 2 (- e n))) + ((rup raz) (1- (expt 2 (1+ (- e n))))) + (otherwise 0))) + +(defund drnd (x mode f) + (declare (xargs :guard (and (real/rationalp x) + (common-mode-p mode) + (formatp f)))) + (rnd x mode (+ (prec f) (expo x) (- (expo (spn f)))))) + +(defund rtz-sqrt (x n) + (declare (xargs :guard (and (real/rationalp x) + (natp n)))) + (if (zp n) + 0 + (let* ((lower (rtz-sqrt x (1- n))) + (upper (+ lower (expt 2 (- n))))) + (if (<= (* upper upper) x) + upper + lower)))) + +(defund rto-sqrt (x n) + (declare (xargs :guard (and (real/rationalp x) + (posp n)))) + (let ((trunc (rtz-sqrt x (1- n)))) + (if (< (* trunc trunc) x) + (+ trunc (expt 2 (- n))) + trunc))) + +(defund qsqrt (x n) + (declare (xargs :guard (and (real/rationalp x) + (posp n)))) + (let ((e (1+ (fl (/ (expo x) 2))))) + (* (expt 2 e) + (rto-sqrt (/ x (expt 2 (* 2 e))) n)))) + +(defun fp+ (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (+ x (expt 2 (- (1+ (expo x)) n)))) + +(defun fp- (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (= x (expt 2 (expo x))) + (- x (expt 2 (- (expo x) n))) + (- x (expt 2 (- (1+ (expo x)) n))))) + diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/div.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/div.lisp new file mode 100644 index 000000000..c19c14628 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/div.lisp @@ -0,0 +1,345 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/div")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; Quotient Refinement +;;;********************************************************************** + +(defsection-rtl |Quotient Refinement| |FMA-Based Division| + +(defthm init-approx + (implies (and (rationalp a) + (rationalp b) + (rationalp y) + (rationalp ep) + (not (zp p)) + (> a 0) + (> b 0) + (<= (abs (- 1 (* b y))) ep)) + (<= (abs (- 1 (* (/ b a) (rne (* a y) p)))) + (+ ep (* (expt 2 (- p)) (1+ ep))))) + :rule-classes ()) + +(defthm r-exactp + (implies (and (rationalp a) + (rationalp b) + (integerp p) + (> p 1) + (exactp a p) + (exactp b p) + (<= 1 a) + (< a 2) + (<= 1 b) + (< b 2) + (rationalp q) + (exactp q p) + (< (abs (- (/ a b) q)) (expt 2 (- (1+ (if (> a b) 0 -1)) p)))) + (exactp (- a (* b q)) p)) + :rule-classes ()) + +(defthm markstein-lemma + (let ((e (if (> a b) 0 -1)) + (r (- a (* b q)))) + (implies (and (rationalp a) + (rationalp b) + (rationalp q) + (rationalp y) + (integerp p) + (<= 1 a) + (< a 2) + (<= 1 b) + (< b 2) + (> p 1) + (exactp a p) + (exactp b p) + (exactp q p) + (< (abs (- 1 (* b y))) (/ (expt 2 p))) + (< (abs (- (/ a b) q)) (expt 2 (- (1+ e) p))) + (ieee-rounding-mode-p mode)) + (= (rnd (+ q (* r y)) mode p) + (rnd (/ a b) mode p)))) + :rule-classes ()) + +(defthm quotient-refinement-1 + (implies (and (rationalp a) + (rationalp b) + (rationalp y) + (rationalp q0) + (rationalp ep) + (rationalp de) + (not (zp p)) + (<= 1 a) + (< a 2) + (<= 1 b) + (< b 2) + (<= (abs (- 1 (* b y))) ep) + (<= (abs (- 1 (* (/ b a) q0))) de)) + (let* ((r (rne (- a (* b q0)) p)) + (q (rne (+ q0 (* r y)) p))) + (<= (abs (- q (/ a b))) + (* (/ a b) + (+ (expt 2 (- p)) + (* (1+ (expt 2 (- p))) de ep) + (* (expt 2 (- p)) de (1+ ep)) + (* (expt 2 (- (* 2 p))) de (1+ ep))))))) + :rule-classes ()) + +(defthm quotient-refinement-2 + (implies (and (rationalp a) + (rationalp b) + (rationalp y) + (rationalp q0) + (rationalp ep) + (rationalp de) + (not (zp p)) + (<= 1 a) + (< a 2) + (<= 1 b) + (< b 2) + (<= (abs (- 1 (* b y))) ep) + (<= (abs (- 1 (* (/ b a) q0))) de) + (< (+ (* ep de) (* (expt 2 (- p)) de (1+ ep))) (expt 2 (- (1+ p))))) + (let* ((r (rne (- a (* b q0)) p)) + (q (rne (+ q0 (* r y)) p)) + (e (if (> a b) 0 -1))) + (< (abs (- q (/ a b))) + (expt 2 (- (1+ e) p))))) + :rule-classes ()) +) + +;;;********************************************************************** +;;; Reciprocal Refinement +;;;********************************************************************** + +(defsection-rtl |Reciprocal Refinement| |FMA-Based Division| + +(defthm recip-refinement-1 + (let* ((e1 (rne (- 1 (* b y1)) p)) + (y3p (+ y1 (* e1 y2))) + (ep3p (* ep1 (+ ep2 (* (expt 2 (- p)) (1+ ep2)))))) + (implies (and (rationalp y1) + (rationalp y2) + (rationalp b) + (rationalp ep1) + (rationalp ep2) + (integerp p) + (> p 0) + (<= (abs (- 1 (* b y1))) ep1) + (<= (abs (- 1 (* b y2))) ep2)) + (<= (abs (- 1 (* b y3p))) + ep3p))) + :rule-classes ()) + +(defthm recip-refinement-2 + (let* ((e1 (rne (- 1 (* b y1)) p)) + (y3p (+ y1 (* e1 y2))) + (y3 (rne y3p p)) + (ep3p (* ep1 (+ ep2 (* (expt 2 (- p)) (1+ ep2))))) + (ep3 (+ ep3p (* (expt 2 (- p)) (1+ ep3p))))) + (implies (and (rationalp y1) + (rationalp y2) + (rationalp b) + (rationalp ep1) + (rationalp ep2) + (integerp p) + (> p 0) + (<= (abs (- 1 (* b y1))) ep1) + (<= (abs (- 1 (* b y2))) ep2)) + (<= (abs (- 1 (* b y3))) + ep3))) + :rule-classes ()) + +(defund h-excps (d p) + (if (zp d) + () + (cons (- 2 (* (expt 2 (- 1 p)) d)) + (h-excps (1- d) p)))) + +(defthm harrison-lemma + (let ((y (rne yp p)) + (d (cg (* (expt 2 (* 2 p)) ep)))) + (implies (and (rationalp b) + (rationalp yp) + (rationalp ep) + (integerp p) + (> p 1) + (<= 1 b) + (< b 2) + (exactp b p) + (not (member b (h-excps d p))) + (< ep (expt 2 (- (1+ p)))) + (<= (abs (- 1 (* b yp))) ep)) + (< (abs (- 1 (* b y))) (expt 2 (- p))))) + :rule-classes ()) +) + +;;;********************************************************************** +;;; Examples +;;;********************************************************************** + +(defsection-rtl |Examples| |FMA-Based Division| + +(defun rcp0 () '(134217725 133177280 132152840 131144040 130150521 + 129171946 128207980 127258288 126322566 125400505 124491806 + 123596178 122713348 121843044 120984994 120138944 119304646 + 118481854 117670336 116869856 116080194 115301132 114532460 + 113773968 113025454 112286728 111557592 110837866 110127368 + 109425916 108733350 108049488 107374182 106707262 106048574 + 105397968 104755298 104120420 103493188 102873470 102261126 + 101656030 101058054 100467072 99882960 99305602 98734878 98170678 + 97612894 97061406 96516116 95976924 95443718 94916402 94394884 + 93879066 93368852 92864160 92364888 91870956 91382282 90898780 + 90420364 89946956 89478486 89014868 88556026 88101890 87652394 + 87207458 86767016 86331002 85899346 85471986 85048856 84629897 + 84215046 83804240 83397422 82994534 82595524 82200330 81808902 + 81421180 81037118 80656663 80279762 79906366 79536432 79169904 + 78806738 78446892 78090313 77736964 77386800 77039774 76695844 + 76354973 76017120 75682240 75350304 75021262 74695082 74371728 + 74051160 73733342 73418242 73105826 72796056 72488900 72184324 + 71882297 71582788 71285764 70991194 70699052 70409300 70121914 + 69836868 69554126 69273666 68995460 68719478 68445694 68174084 + 67904624 67637280 67372036)) + +(defun rcp1 () '(131067 129044 127066 125134 123244 121398 119594 117828 + 116102 114414 112762 111144 109562 108014 106498 105014 103560 + 102136 100742 99376 98038 96726 95442 94182 92946 91736 90548 89384 + 88242 87120 86022 84942 83884 82846 81826 80824 79842 78878 77930 + 77000 76086 75188 74306 73440 72588 71752 70928 70120 69326 68544 + 67776 67022 66280 65548 64830 64124 63428 62746 62072 61410 60758 + 60118 59486 58864 58254 57652 57058 56474 55900 55334 54776 54228 + 53686 53154 52628 52111 51602 51100 50604 50116 49636 49162 48696 + 48234 47780 47333 46892 46456 46028 45604 45186 44776 44368 43968 + 43574 43184 42798 42419 42044 41674 41310 40950 40594 40244 39898 + 39556 39218 38886 38557 38232 37912 37595 37282 36974 36668 36368 + 36070 35776 35486 35200 34916 34636 34360 34086 33816 33550 33286 + 33026)) + +(defun rcp2 () '(4047 3956 3864 3780 3690 3608 3532 3452 3378 3307 3236 + 3164 3096 3032 2968 2908 2844 2784 2728 2676 2624 2568 2524 2472 + 2420 2376 2328 2288 2244 2196 2160 2116 2076 2040 2004 1960 1928 + 1896 1860 1828 1796 1764 1732 1704 1672 1648 1612 1588 1560 1532 + 1508 1484 1464 1432 1412 1392 1364 1348 1324 1304 1280 1264 1240 + 1220 1208 1188 1164 1148 1132 1116 1096 1084 1064 1052 1032 1018 + 1004 992 972 960 948 932 924 904 892 882 872 856 848 832 820 816 798 + 788 784 772 756 750 736 728 720 712 700 692 684 676 664 660 650 640 + 636 626 616 612 600 596 588 580 572 572 560 552 548 540 532 528 524 + 520)) + +(defun rcp24 (b) + (let* ((i (fl (* (expt 2 7) (1- b)))) + (x (- b (1+ (* (expt 2 -7) i)))) + (c0 (* (expt 2 -27) (nth i (rcp0)))) + (c1 (- (* (expt 2 -17) (nth i (rcp1))))) + (c2 (* (expt 2 -12) (nth i (rcp2))))) + (rne (+ c0 (* c1 x) (* c2 x x)) 24))) + +(defthm rcp24-spec + (implies (and (rationalp b) + (exactp b 24) + (<= 1 b) + (< b 2)) + (and (exactp (rcp24 b) 24) + (<= 1/2 (rcp24 b)) + (<= (rcp24 b) 1) + (< (abs (- 1 (* b (rcp24 b)))) (expt 2 -23)))) + :rule-classes ()) + +(defund divsp (a b mode) + (let* ((y0 (rcp24 b)) + (q0 (rne (* a y0) 24)) + (e0 (rne (- 1 (* b y0)) 24)) + (r0 (rne (- a (* b q0)) 24)) + (y1 (rne (+ y0 (* e0 y0)) 24)) + (q1 (rne (+ q0 (* r0 y1)) 24)) + (r1 (rne (- a (* b q1)) 24))) + (rnd (+ q1 (* r1 y1)) mode 24))) + +(defthm divsp-small-cases + (implies (and (not (zp k)) + (<= k 7)) + (let* ((b (- 2 (* (expt 2 -23) k))) + (y0 (rcp24 b)) + (e0 (rne (- 1 (* b y0)) 24)) + (y1 (rne (+ y0 (* e0 y0)) 24))) + (< (abs (- 1 (* b y1))) + (expt 2 -24)))) + :rule-classes ()) + +(defthm divsp-correct + (implies (and (rationalp a) + (rationalp b) + (<= 1 a) + (< a 2) + (<= 1 b) + (< b 2) + (exactp a 24) + (exactp b 24) + (ieee-rounding-mode-p mode)) + (= (divsp a b mode) (rnd (/ a b) mode 24))) + :rule-classes ()) + +(defthm rcp24-rtz-error + (implies (and (rationalp b) + (<= 1 b) + (< b 2)) + (<= (abs (- 1 (* b (rcp24 (rtz b 24))))) (expt 2 -22))) + :rule-classes ()) + +(defund divdp (a b mode) + (let* ((y0 (rcp24 (rtz b 24))) + (q0 (rne (* a y0) 53)) + (e0 (rne (- 1 (* b y0)) 53)) + (r0 (rne (- a (* b q0)) 53)) + (y1 (rne (+ y0 (* e0 y0)) 53)) + (e1 (rne (- 1 (* b y1)) 53)) + (y2 (rne (+ y0 (* e0 y1)) 53)) + (q1 (rne (+ q0 (* r0 y1)) 53)) + (y3 (rne (+ y1 (* e1 y2)) 53)) + (r1 (rne (- a (* b q1)) 53))) + (rnd (+ q1 (* r1 y3)) mode 53))) + +(defthm divdp-small-cases + (implies (and (not (zp k)) + (<= k 1027)) + (let* ((b (- 2 (* (expt 2 -52) k))) + (y0 (rcp24 (rtz b 24))) + (e0 (rne (- 1 (* b y0)) 53)) + (y1 (rne (+ y0 (* e0 y0)) 53)) + (e1 (rne (- 1 (* b y1)) 53)) + (y2 (rne (+ y0 (* e0 y1)) 53)) + (y3 (rne (+ y1 (* e1 y2)) 53))) + (< (abs (- 1 (* b y3))) + (expt 2 -53)))) + :rule-classes ()) + +(defthm divdp-correct + (implies (and (rationalp a) + (rationalp b) + (<= 1 a) + (< a 2) + (<= 1 b) + (< b 2) + (exactp a 53) + (exactp b 53) + (ieee-rounding-mode-p mode)) + (= (divdp a b mode) (rnd (/ a b) mode 53))) + :rule-classes ()) +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/doc.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/doc.lisp new file mode 100644 index 000000000..102733e1a --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/doc.lisp @@ -0,0 +1,241 @@ +; Copyright (C) 2014, Regents of the University of Texas +; Written by Matt Kaufmann (original date February, 2014) +; License: A 3-clause BSD license. See the LICENSE file distributed with ACL2. + +; Description: + +; This file formerly connected xdoc with David Russinoff's online rtl manual. +; That manual has been replaced by a book, "Formal Verification of +; Floating-Point Hardware Design: A Mathematical Approach" by +; David M. Russinoff, at: +; https://www.springer.com/us/book/9783319955124 + +(in-package "RTL") + +(defconst *rtl-node-tree* + +; Nodes from mousing over topics at (the now defunct) +; http://russinoff.com/libman/top.html, with spaces replaced by underscores and +; commas deleted. These are organized to match the hierarchy on that page. + +; We use "/" rather than ":" as a separator so that ACL2-Doc can include the +; node, since ACL2-Doc ignores names that ACL2 prints using vertical bars. +; Also, Jared Davis points out that the std libraries use "/" as a separator, +; so we follow that convention. + + '((|Register-Transfer Logic| + (|Basic Arithmetic Functions| ; basic.lisp + |Floor and Ceiling| + |Modulus| + |Chop|) + (|Bit Vectors| ; bits.lisp + |Recognizing Bit Vectors| + |Bit Slices| + |Bit Extraction| + |Concatenation| + |Signed Integer Formats|) + (|Logical Operations| ; log.lisp + |Binary Operations| + |Complementation| + |Algebraic Properties|)) + (|Floating-Point Arithmetic| + (|Floating-Point Numbers| ; float.lisp + |Floating-Point Decomposition| + |Exactness|) + (|Floating-Point Formats| ; reps.lisp + |Classification of Formats| + |Normal Encodings| + |Denormals and Zeroes| + |Infinities and NaNs| + |Rebiasing Exponents|) + (|Rounding| ; round.lisp + |Truncation| + |Rounding Away from Zero| + |Unbiased Rounding| + |Odd Rounding| + |IEEE Rounding| + |Denormal Rounding|)) + (|Floating-Point Exceptions and Specification of Elementary Arithmetic Instructions| ; exps.lisp + (|IEEE-Compliant Square Root| ; sqrt.lisp + |Truncated Square Root| + |Odd-Rounded Square Root| + |IEEE-Rounded Square Root|) + |SSE Floating-Point Instructions| + |x87 Instructions| + |ARM AArch32 Floating-Point Instructions| + ;; |ARM AArch64 Floating-Point Instructions| + ) + (|Implementation of Elementary Operations| + (|Addition| ; add.lisp + |Bit Vector Addition| + |Leading One Prediction| + |Trailing One Prediction|) + (|Multiplication| ; mult.lisp + |Radix-4 Booth Encoding| + |Statically Encoded Multiplier Arrays| + |Encoding Redundant Representations| + |Radix-8 Booth Encoding|) + (|FMA-Based Division| ; div.lisp + |Quotient Refinement| + |Reciprocal Refinement| + |Examples|) + (|SRT Division and Square Root| ; srt.lisp + |SRT Division and Quotient Digit Selection| + |SRT Square Root Extraction|)) + |Modeling Algorithms in C++ and ACL2| ; rac.lisp + |Bibliography|)) + +(defun rtl-node-name-basic (sym) + sym) + +(defun rtl-node-alist1 (sym global-index) + (list sym + (rtl-node-name-basic sym) + (concatenate 'string + "http://russinoff.com/libman/text/node" + (coerce (explode-nonnegative-integer + global-index 10 nil) + 'string) + ".html"))) + +(defun rtl-node-alist (flg tree global-index) + +; Return a list of entries (original-name doc-topic-name url). Flg is nil for +; a single tree, t for a list of trees. + + (declare (xargs :mode :program)) + (cond (flg ; list of child trees + (assert$ + (true-listp tree) + (cond ((atom tree) nil) + (t (let* ((alist (rtl-node-alist nil (car tree) global-index)) + (len-alist (length alist))) + (append alist + (rtl-node-alist t + (cdr tree) + (+ global-index len-alist)))))))) + ((atom tree) + (assert$ + (symbolp tree) + (list (rtl-node-alist1 tree global-index)))) + (t (assert$ + (and (true-listp tree) + tree + (symbolp (car tree))) + (cons (rtl-node-alist1 (car tree) global-index) + (rtl-node-alist t + (cdr tree) + (1+ global-index))))))) + +(defconst *rtl-node-alist* + (rtl-node-alist t *rtl-node-tree* 4)) + +(defun defsection-rtl-defs1 (events acc) + (declare (xargs :mode :program)) + (cond ((endp events) (reverse acc)) + (t (defsection-rtl-defs1 + (cdr events) + (let ((ev (car events))) + (case-match ev + ((& name . &) + +; Based on the definition of formula-info-to-defs1 from xdoc/top.lisp. + + (cond ((symbolp name) + (cons (concatenate 'string + "@(def " + (xdoc::full-escape-symbol name) + ")") + acc)) + (t acc))) + (& acc))))))) + +(defun defsection-rtl-defs (events) + (declare (xargs :mode :program)) + (cond ((endp events) "") + (t (concatenate + 'string + +; Based on formula-info-to-defs in xdoc/top.lisp: + + "

Definitions and Theorems

" + (string-append-lst (defsection-rtl-defs1 events nil)))))) + +(defun rtl-node-entry (name) + (or (assoc-eq name *rtl-node-alist*) + (er hard 'defsection-rtl + "Unknown rtl node name, ~x0" + name))) + +(defmacro defsection-rtl (name parent &rest events) + (let* ((entry (rtl-node-entry name)) + (section-name (cadr entry)) + ;; (url (caddr entry)) ; no longer used + ) + `(defsection ,section-name + :parents (,(if (eq parent 'rtl) 'rtl (cadr (rtl-node-entry parent)))) + :short ,(symbol-name name) + :long ,(defsection-rtl-defs events) + (deflabel ,(intern-in-package-of-symbol + (concatenate 'string (symbol-name name) "$SECTION") + name)) + ,@events))) + +(defun rtl-node-name (name) + (cond ((eq name 'rtl) name) + ((consp name) + (rtl-node-name (car name))) + (t (cadr (rtl-node-entry name))))) + +(defun rtl-node-name-lst (trees) + (cond ((endp trees) nil) + (t (cons (rtl-node-name (car trees)) + (rtl-node-name-lst (cdr trees)))))) + +(defmacro rtl-order-subtopics (parent children) + `(xdoc::order-subtopics ,(rtl-node-name parent) + ,(rtl-node-name-lst children))) + +(defxdoc rtl + :parents (acl2::bit-vectors acl2::hardware-verification) + :short "A library of register-transfer logic and computer arithmetic" + :long "

This @(see documentation) is based on the directory @('rtl') of the + ACL2 @(see community-books). For a more thorough treatment, see \"Formal Verification + of Floating-Point Hardware Design: A Mathematical Approach\" by David + M. Russinoff. See file @('rtl/README') for additional information about this + library and its connection to this book.

") + +(rtl-order-subtopics rtl (|Register-Transfer Logic| + |Floating-Point Arithmetic| + |Floating-Point Exceptions and Specification of Elementary Arithmetic Instructions| + |Implementation of Elementary Operations| + |Modeling Algorithms in C++ and ACL2| + |Bibliography|)) + +(defun defsection-rtl-list-for-tree (parent trees) + +; Trees is a tail of the children of parent in *rtl-node-tree*. + + (declare (xargs :mode :program)) + (cond ((endp trees) nil) + ((atom (car trees)) + +; Then defsection-rtl will be given explicitly for each tree in trees. + + nil) + (t ; (car trees) is (topic . children) + (list* `(defsection-rtl ,(caar trees) ,parent) + `(rtl-order-subtopics ,(caar trees) ,(cdar trees)) + (append (defsection-rtl-list-for-tree (caar trees) (cdar trees)) + (defsection-rtl-list-for-tree parent (cdr trees))))))) + +(defmacro defsection-rtl-list () + (cons 'progn (defsection-rtl-list-for-tree 'rtl *rtl-node-tree*))) + +(defsection-rtl-list) + +; Handle top-level leaves: + +(defsection-rtl |Bibliography| rtl) +(defsection-rtl |Modeling Algorithms in C++ and ACL2| rtl) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/excps.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/excps.lisp new file mode 100644 index 000000000..f62050ab0 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/excps.lisp @@ -0,0 +1,1095 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;*************************************************************** +;;; SSE Operations +;;;*************************************************************** + +(defsection-rtl |SSE Floating-Point Instructions| + |Floating-Point Exceptions and Specification of Elementary Arithmetic Instructions| + + ;; Exception flag bits (indices shared by SSE and x87): + +(defnd ibit () 0) +(defnd dbit () 1) +(defnd zbit () 2) +(defnd obit () 3) +(defnd ubit () 4) +(defnd pbit () 5) + +(in-theory (disable (ibit) (dbit) (zbit) (obit) (ubit) (pbit))) + +;; Other MXCSR bits: + +(defnd daz () 6) +(defnd imsk () 7) +(defnd dmsk () 8) +(defnd zmsk () 9) +(defnd omsk () 10) +(defnd umsk () 11) +(defnd pmsk () 12) +(defnd ftz () 15) + +(in-theory (disable (daz) (imsk) (dmsk) (zmsk) (omsk) (umsk) (pmsk) (ftz))) + +(defund mxcsr-masks (mxcsr) + (declare (xargs :guard (natp mxcsr))) + (bits mxcsr 12 7)) + +(defund mxcsr-rc (mxcsr) + (declare (xargs :guard (natp mxcsr))) + (case (bits mxcsr 14 13) + (0 'rne) + (1 'rdn) + (2 'rup) + (3 'rtz))) + +;;-------------------------------------------------------------------------------- + +;; This specification applies only to scalar SSE instructions. + +;; The arguments of SSE-BINARY-SPEC are an operation (add, sub, mul, or div), 2 data +;; inputs, the initial MXCSR register, and the significand and exponent widths. It +;; returns a data result, which is NIL in the event of an unmasked exception, and the +;; updated MXCSR. + +;; An implementation is correct if it returns the same MXCSR as SSE-BINARY-SPEC and, +;; in the event that SSE-BINARY-SPEC returns a non-NIL value, it returns the same value. + +;; SSE-BINARY-SPEC is based on two auxiliary functions, SSE-BINARY-PRE-COMP and +;; SSE-BINARY-COMP, each of which returns an optional value and a 6-bit vector +;; of exception flags, which are written to the MXCSR. + +;; SSE-BINARY-PRE-COMP calls SSE-BINARY-PRE-COMP-EXCP, which detects pre-computation +;; exceptions, and SSE-BINARY-PRE-COMP-VAL, which may compute a value. If an unmasked +;; exception occurs, the value is invalid and the operation is terminated. Otherwise, +;; if the value is NIL, then the computation proceeds by calling SSE-BINARY-COMP, and +;; if non-NIL, the operation is terminated and that value is returned. + +;; SSE-BINARY-COMP either returns an infinity or decodes the operands and computes the +;; unrounded result. If that result is 0, then it sets the sign according to the operand +;; signs and the rounding mode and returns. Otherwise, it calls SSE-POST-COMP, which detects +;; post-computation exceptions and computes the rounded result, which is invalid in the +;; event of an unmasked exception. + +(defund set-flag (b flags) + (declare (xargs :guard (and (natp b) + (natp flags)))) + (logior flags (expt 2 b))) + +(defund unmasked-excp-p (flags masks) + (declare (xargs :guard (and (natp flags) + (natp masks)))) + (or (and (= (bitn flags (ibit)) 1) (= (bitn masks (ibit)) 0)) + (and (= (bitn flags (dbit)) 1) (= (bitn masks (dbit)) 0)) + (and (= (bitn flags (zbit)) 1) (= (bitn masks (zbit)) 0)) + (and (= (bitn flags (obit)) 1) (= (bitn masks (obit)) 0)) + (and (= (bitn flags (ubit)) 1) (= (bitn masks (ubit)) 0)) + (and (= (bitn flags (pbit)) 1) (= (bitn masks (pbit)) 0)))) + +(defund dazify (x daz f) + (declare (xargs :guard (and (encodingp x f) + (natp daz)))) + (if (and (= daz 1) (denormp x f)) + (zencode (sgnf x f) f) + x)) + +(defund binary-undefined-p (op a af b bf) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a af) + (encodingp b bf)))) + (case op + (add (and (infp a af) (infp b bf) (not (= (sgnf a af) (sgnf b bf))))) + (sub (and (infp a af) (infp b bf) (= (sgnf a af) (sgnf b bf)))) + (mul (and (or (infp a af) (infp b bf)) + (or (zerp a af) (zerp b bf)))) + (div (or (and (infp a af) (infp b bf)) + (and (zerp a af) (zerp b bf)))))) + +(defund sse-binary-pre-comp-excp (op a b f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f)))) + (if (or (snanp a f) (snanp b f)) + (set-flag (ibit) 0) + (if (or (qnanp a f) (qnanp b f)) + 0 + (if (binary-undefined-p op a f b f) + (set-flag (ibit) 0) + (if (and (eql op 'div) (zerp b f) (not (infp a f))) + (set-flag (zbit) 0) + (if (or (denormp a f) (denormp b f)) + (set-flag (dbit) 0) + 0)))))) + +(defund sse-binary-pre-comp-val (op a b f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f)))) + (if (nanp a f) + (qnanize a f) + (if (nanp b f) + (qnanize b f) + (if (binary-undefined-p op a f b f) + (indef f) + ())))) + +(defund sse-binary-pre-comp (op a b mxcsr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp mxcsr)))) + (let* ((daz (bitn mxcsr (daz))) + (a (dazify a daz f)) + (b (dazify b daz f))) + (mv a b (sse-binary-pre-comp-val op a b f) (sse-binary-pre-comp-excp op a b f)))) + +(defund sse-post-comp (u mxcsr f) + (declare (xargs :guard (and (real/rationalp u) + (not (= u 0)) + (natp mxcsr) + (formatp f)))) + (let* ((rmode (mxcsr-rc mxcsr)) + (r (rnd u rmode (prec f))) + (rsgn (if (< r 0) 1 0)) + (flags (if (= r u) 0 (set-flag (pbit) 0)))) + (if (> (abs r) (lpn f)) + (let* ((flags (set-flag (obit) flags))) + (if (= (bitn mxcsr (omsk)) 1) + (let ((flags (set-flag (pbit) flags))) + (if (or (and (eql rmode 'rdn) (> r 0)) + (and (eql rmode 'rup) (< r 0)) + (eql rmode 'rtz)) + (mv (nencode (* (sgn r) (lpn f)) f) + flags) + (mv (iencode rsgn f) flags))) + (mv () flags))) + (if (< (abs r) (spn f)) + (if (= (bitn mxcsr (umsk)) 1) + (if (= (bitn mxcsr (ftz)) 1) + (mv (zencode rsgn f) (set-flag (pbit) (set-flag (ubit) flags))) + (let ((d (drnd u rmode f))) + (if (= d u) + (mv (dencode d f) flags) + (let ((flags (set-flag (pbit) (set-flag (ubit) flags)))) + (if (= d 0) + (mv (zencode rsgn f) flags) + (if (= (abs d) (spn f)) + (mv (nencode d f) flags) + (mv (dencode d f) flags))))))) + (mv () (set-flag (ubit) flags))) + (mv (nencode r f) flags))))) + +(defund binary-inf-sgn (op a af b bf) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a af) + (encodingp b bf)))) + (case op + (add (if (infp a af) (sgnf a af) (sgnf b bf))) + (sub (if (infp a af) (sgnf a af) (if (zerop (sgnf b bf)) 1 0))) + ((mul div) (logxor (sgnf a af) (sgnf b bf))))) + +(defund binary-zero-sgn (op asgn bsgn rmode) + (declare (xargs :guard (and (member op '(add sub mul div)) + (bvecp asgn 1) + (bvecp bsgn 1) + (IEEE-rounding-mode-p rmode)))) + (case op + (add (if (= asgn bsgn) asgn (if (eql rmode 'rdn) 1 0))) + (sub (if (not (= asgn bsgn)) asgn (if (eql rmode 'rdn) 1 0))) + ((mul div) (logxor asgn bsgn)))) + +(defund binary-eval (op aval bval) + (declare (xargs :guard (and (member op '(add sub mul div)) + (real/rationalp aval) + (real/rationalp bval) + (not (and (eql op 'div) (= bval 0)))))) + (case op + (add (+ aval bval)) + (sub (- aval bval)) + (mul (* aval bval)) + (div (/ aval bval)))) + +(defund sse-binary-comp (op a b mxcsr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp mxcsr)))) + (if (or (infp a f) (if (eql op 'div) (zerp b f) (infp b f))) + (mv (iencode (binary-inf-sgn op a f b f) f) 0) + (let* ((asgn (sgnf a f)) + (bsgn (sgnf b f)) + (aval (decode a f)) + (bval (decode b f)) + (u (binary-eval op aval bval))) + (if (or (and (eql op 'div) (infp b f)) (= u 0)) + (mv (zencode (binary-zero-sgn op asgn bsgn (mxcsr-rc mxcsr)) f) 0) + (sse-post-comp u mxcsr f))))) + +(defund sse-binary-spec (op a b mxcsr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp mxcsr)))) + (mv-let (adaz bdaz result pre-flags) (sse-binary-pre-comp op a b mxcsr f) + (if (unmasked-excp-p pre-flags (mxcsr-masks mxcsr)) + (mv () (logior mxcsr pre-flags)) + (if result + (mv result (logior mxcsr pre-flags)) + (mv-let (result post-flags) (sse-binary-comp op adaz bdaz mxcsr f) + (mv (and (not (unmasked-excp-p post-flags (mxcsr-masks mxcsr))) + result) + (logior (logior mxcsr pre-flags) post-flags))))))) + + +;;-------------------------------------------------------------------------------- + +;; The arguments of SSE-SQRT-SPEC are a data input, the initial MXCSR register, and +;; the significand and exponent widths. It returns a data result, which is NIL in +;; the event of an unmasked exception, and the updated MXCSR. + +(defund sse-sqrt-pre-comp-excp (a f) + (declare (xargs :guard (encodingp a f))) + (if (snanp a f) + (set-flag (ibit) 0) + (if (qnanp a f) + 0 + (if (and (not (zerp a f)) (= (sgnf a f) 1)) + (set-flag (ibit) 0) + (if (denormp a f) + (set-flag (dbit) 0) + 0))))) + +(defund sse-sqrt-pre-comp-val (a f) + (declare (xargs :guard (encodingp a f))) + (if (nanp a f) + (qnanize a f) + (if (and (not (zerp a f)) (= (sgnf a f) 1)) + (indef f) + ()))) + +(defund sse-sqrt-pre-comp (a mxcsr f) + (declare (xargs :guard (and (encodingp a f) + (natp mxcsr)))) + (let ((a (dazify a (bitn mxcsr (daz)) f))) + (mv a (sse-sqrt-pre-comp-val a f) (sse-sqrt-pre-comp-excp a f)))) + +(defund sse-sqrt-comp (a mxcsr f) + (declare (xargs :guard (and (encodingp a f) + (or (zerp a f) (= (sgnf a f) 0)) + (natp mxcsr)))) + (if (or (infp a f) (zerp a f)) + (mv a 0) + (sse-post-comp (qsqrt (decode a f) (+ (prec f) 2)) mxcsr f))) + +(defund sse-sqrt-spec (a mxcsr f) + (declare (xargs :guard (and (encodingp a f) + (natp mxcsr)))) + (mv-let (adaz result pre-flags) (sse-sqrt-pre-comp a mxcsr f) + (if (unmasked-excp-p pre-flags (mxcsr-masks mxcsr)) + (mv () (logior mxcsr pre-flags)) + (if result + (mv result (logior mxcsr pre-flags)) + (mv-let (result post-flags) (sse-sqrt-comp adaz mxcsr f) + (mv (and (not (unmasked-excp-p post-flags (mxcsr-masks mxcsr))) + result) + (logior (logior mxcsr pre-flags) post-flags))))))) + + +;;-------------------------------------------------------------------------------- + +;; The arguments of FMA-SPEC are three data inputs, the initial MXCSR register, and +;; the significand and exponent widths. It returns a data result, which is NIL in the +;; event of an unmasked exception, and the updated MXCSR. + +(defund fma-undefined-p (a b c f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f)))) + (and (or (infp a f) (infp b f)) + (or (zerp a f) + (zerp b f) + (and (not (nanp a f)) + (not (nanp b f)) + (infp c f) + (not (= (sgnf c f) + (logxor (sgnf a f) (sgnf b f)))))))) + +(defund sse-fma-pre-comp-excp (a b c f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f)))) + (if (or (snanp a f) (snanp b f) (snanp c f)) + (set-flag (ibit) 0) + (if (or (qnanp a f) (qnanp b f) (qnanp c f)) + 0 + (if (fma-undefined-p a b c f) + (set-flag (ibit) 0) + (if (or (denormp a f) (denormp b f) (denormp c f)) + (set-flag (dbit) 0) + 0))))) + +(defund sse-fma-pre-comp-val (a b c f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f)))) + (if (nanp a f) + (qnanize a f) + (if (nanp b f) + (qnanize b f) + (if (nanp c f) + (qnanize c f) + (if (fma-undefined-p a b c f) + (indef f) + ()))))) + +(defund sse-fma-pre-comp (a b c mxcsr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp mxcsr)))) + (let* ((daz (bitn mxcsr (daz))) + (a (dazify a daz f)) + (b (dazify b daz f)) + (c (dazify c daz f))) + (mv a b c (sse-fma-pre-comp-val a b c f) (sse-fma-pre-comp-excp a b c f)))) + +(defund sse-fma-comp (a b c mxcsr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp mxcsr)))) + (let* ((asgn (sgnf a f)) + (bsgn (sgnf b f)) + (csgn (sgnf c f)) + (aval (decode a f)) + (bval (decode b f)) + (cval (decode c f)) + (u (+ (* aval bval) cval))) + (if (or (infp a f) (infp b f)) + (mv (iencode (logxor asgn bsgn) f) 0) + (if (infp c f) + (mv c 0) + (if (= u 0) + (mv (zencode (if (= (logxor asgn bsgn) csgn) + csgn + (if (eql (mxcsr-rc mxcsr) 'rdn) 1 0)) + f) + 0) + (sse-post-comp u mxcsr f)))))) + +(defund sse-fma-spec (a b c mxcsr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp mxcsr)))) + (mv-let (adaz bdaz cdaz result pre-flags) (sse-fma-pre-comp a b c mxcsr f) + (if (unmasked-excp-p pre-flags (mxcsr-masks mxcsr)) + (mv () (logior mxcsr pre-flags)) + (if result + (mv result (logior mxcsr pre-flags)) + (mv-let (result post-flags) (sse-fma-comp adaz bdaz cdaz mxcsr f) + (mv (and (not (unmasked-excp-p post-flags (mxcsr-masks mxcsr))) + result) + (logior (logior mxcsr pre-flags) post-flags))))))) + +) +;;;*************************************************************** +;;; x87 Operations +;;;*************************************************************** + +(defsection-rtl |x87 Instructions| + |Floating-Point Exceptions and Specification of Elementary Arithmetic Instructions| + +;; Rounding and precision control in FCW + +(defund fcw-rc (fcw) + (declare (xargs :guard (natp fcw))) + (case (bits fcw 11 10) + (0 'rne) + (1 'rdn) + (2 'rup) + (3 'rtz))) + +(defund fcw-pc (fcw) + (declare (xargs :guard (natp fcw))) + (case (bits fcw 9 8) + ((0 1) 24) + (2 53) + (3 64))) + +;; Additional FSW status bits that are set by x87 instructions: + +(defnd es () 7) +(defnd bb () 15) +(defnd c1 () 9) + +(in-theory (disable (es) (bb) (c1))) + +;; Whenever ES (FSW[7]) is set, so is B (FSW[15]): + +(defund set-es (fsw) + (declare (xargs :guard (natp fsw))) + (set-flag (bb) (set-flag (es) fsw))) + +;; C1 is cleared by default: + +(defund clear-c1 (fsw) + (declare (xargs :guard (natp fsw))) + (logand fsw #xfdff)) + +;; The arguments of X87-BINARY-SPEC are two data inputs, their formats, and the initial +;; FCW and FSW registers. It returns a data result, which is NIL in the event of an +;; unmasked pre-computation exception, and the updated FSW. + +(defund x87-binary-pre-comp-excp (op a af b bf) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a af) + (encodingp b bf)))) + (if (or (snanp a af) (unsupp a af) (snanp b bf) (unsupp b bf)) + (set-flag (ibit) 0) + (if (or (qnanp a af) (qnanp b bf)) + 0 + (if (binary-undefined-p op a af b bf) + (set-flag (ibit) 0) + (if (and (eql op 'div) (zerp b bf) (not (infp a af))) + (set-flag (zbit) 0) + (if (or (denormp a af) (pseudop a af) (denormp b bf) (pseudop b bf)) + (set-flag (dbit) 0) + 0)))))) + +(defund convert-nan-to-ep (x f) + (declare (xargs :guard (and (encodingp x f) + (<= (prec f) 64)))) + (cat (sgnf x f) + 1 + (1- (expt 2 15)) + 15 + 1 + 1 + (manf x f) + (1- (prec f)) + 0 + (- 64 (prec f)))) + +(defund x87-binary-pre-comp-val (op a af b bf) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a af) + (encodingp b bf) + (<= (prec af) 64) + (<= (prec bf) 64)))) + (let ((aep (convert-nan-to-ep a af)) + (bep (convert-nan-to-ep b bf))) + (if (nanp a af) + (if (nanp b bf) + (if (> (sigf aep (ep)) (sigf bep (ep))) + (qnanize aep (ep)) + (if (< (sigf aep (ep)) (sigf bep (ep))) + (qnanize bep (ep)) + (if (= (sgnf aep (ep)) 0) + (qnanize (convert-nan-to-ep a af) (ep)) + (qnanize (convert-nan-to-ep b bf) (ep))))) + (qnanize aep (ep))) + (if (nanp b bf) + (qnanize bep (ep)) + (if (binary-undefined-p op a af b bf) + (indef (ep)) + ()))))) + +(defund x87-binary-pre-comp (op a af b bf) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a af) + (encodingp b bf) + (<= (prec af) 64) + (<= (prec bf) 64)))) + (mv (x87-binary-pre-comp-val op a af b bf) (x87-binary-pre-comp-excp op a af b bf))) + +(defund x87-post-comp (u fcw) + (declare (xargs :guard (and (real/rationalp u) + (not (= u 0)) + (natp fcw)))) + (let* ((rmode (fcw-rc fcw)) + (r (rnd u rmode (fcw-pc fcw))) + (rsgn (if (< r 0) 1 0)) + (flags (if (= r u) 0 (set-flag (pbit) 0)))) + (if (> (abs r) (lpn (ep))) + (let ((flags (set-flag (obit) flags))) + (if (= (bitn fcw (obit)) 1) + (let ((flags (set-flag (pbit) flags))) + (if (or (and (eql rmode 'rdn) (> r 0)) + (and (eql rmode 'rup) (< r 0)) + (eql rmode 'rtz)) + (mv (nencode (* (sgn r) (lpn (ep))) (ep)) flags) + (mv (iencode rsgn (ep)) (set-flag (c1) flags)))) + (let ((s (* r (expt 2 (- (* 3 (expt 2 13))))))) + (if (> (abs s) (lpn (ep))) + (mv (iencode rsgn (ep)) + (set-flag (c1) (set-flag (pbit) flags))) + (mv (nencode s (ep)) + (if (> (abs r) (abs u)) (set-flag (c1) flags) flags)))))) + (if (< (abs r) (spn (ep))) + (if (= (bitn fcw (ubit)) 1) + (let ((d (drnd u rmode (ep)))) + (if (= d u) + (mv (dencode d (ep)) flags) + (let ((flags (set-flag (pbit) (set-flag (ubit) flags)))) + (if (= d 0) + (mv (zencode rsgn (ep)) flags) + (if (= (abs d) (spn (ep))) + (mv (nencode d (ep)) (set-flag (c1) flags)) + (mv (dencode d (ep)) (if (> (abs d) (abs u)) (set-flag (c1) flags) flags))))))) + (let ((flags (set-flag (ubit) flags)) + (s (* r (expt 2 (* 3 (expt 2 13)))))) + (if (< (abs s) (spn (ep))) + (mv (zencode rsgn (ep)) (set-flag (pbit) flags)) + (mv (nencode s (ep)) (if (> (abs r) (abs u)) (set-flag (c1) flags) flags))))) + (mv (nencode r (ep)) (if (> (abs r) (abs u)) (set-flag (c1) flags) flags)))))) + +(defund x87-binary-comp (op a af b bf fcw) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a af) + (encodingp b bf) + (natp fcw)))) + (if (or (infp a af) (if (eql op 'div) (zerp b bf) (infp b bf))) + (mv (iencode (binary-inf-sgn op a af b bf) (ep)) 0) + (let* ((asgn (sgnf a af)) + (bsgn (sgnf b bf)) + (aval (decode a af)) + (bval (decode b bf)) + (u (binary-eval op aval bval))) + (if (or (and (eql op 'div) (infp b bf)) (= u 0)) + (mv (zencode (binary-zero-sgn op asgn bsgn (fcw-rc fcw)) (ep)) 0) + (x87-post-comp u fcw))))) + +(defund x87-binary-spec (op a af b bf fcw fsw) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a af) + (encodingp b bf) + (<= (prec af) 64) + (<= (prec bf) 64) + (natp fcw) + (natp fsw)))) + (let ((fsw (clear-c1 fsw))) + (mv-let (result pre-flags) (x87-binary-pre-comp op a af b bf) + (if (unmasked-excp-p pre-flags fcw) + (mv () (set-es (logior fsw pre-flags))) + (if result + (mv result (logior fsw pre-flags)) + (mv-let (result post-flags) (x87-binary-comp op a af b bf fcw) + (mv result + (if (unmasked-excp-p post-flags fcw) + (set-es (logior (logior fsw pre-flags) post-flags)) + (logior (logior fsw pre-flags) post-flags))))))))) + + +;;-------------------------------------------------------------------------------- + +;; The arguments of X87-SQRT-SPEC are a data input, its format, and the initial FCW +;; and FSW registers. It returns a data result, which is NIL in the event of an +;; unmasked pre-computation exception, and the updated FSW. + +(defund x87-sqrt-pre-comp-excp (a f) + (declare (xargs :guard (encodingp a f))) + (if (or (unsupp a f) (snanp a f)) + (set-flag (ibit) 0) + (if (qnanp a f) + 0 + (if (and (not (zerp a f)) (= (sgnf a f) 1)) + (set-flag (ibit) 0) + (if (or (denormp a f) (pseudop a f)) + (set-flag (dbit) 0) + 0))))) + +(defund x87-sqrt-pre-comp-val (a f) + (declare (xargs :guard (and (encodingp a f) + (<= (prec f) 64)))) + (if (nanp a f) + (qnanize (convert-nan-to-ep a f) (ep)) + (if (and (not (zerp a f)) (= (sgnf a f) 1)) + (indef (ep)) + ()))) + +(defund x87-sqrt-pre-comp (a f) + (declare (xargs :guard (and (encodingp a f) + (<= (prec f) 64)))) + (mv (x87-sqrt-pre-comp-val a f) (x87-sqrt-pre-comp-excp a f))) + +(defund x87-sqrt-comp (a f fcw) + (declare (xargs :guard (and (encodingp a f) + (or (zerp a f) (= (sgnf a f) 0)) + (<= (prec f) 64) + (natp fcw)))) + (if (or (infp a f) (zerp a f)) + (mv a 0) + (x87-post-comp (qsqrt (decode a f) 66) fcw))) + +(defund x87-sqrt-spec (a f fcw fsw) + (declare (xargs :guard (and (encodingp a f) + (<= (prec f) 64) + (natp fcw) + (natp fsw)))) + (let ((fsw (clear-c1 fsw))) + (mv-let (result pre-flags) (x87-sqrt-pre-comp a f) + (if (unmasked-excp-p pre-flags fcw) + (mv () (set-es (logior fsw pre-flags))) + (if result + (mv result (logior fsw pre-flags)) + (mv-let (result post-flags) (x87-sqrt-comp a f fcw) + (mv result + (if (unmasked-excp-p post-flags fcw) + (set-es (logior (logior fsw pre-flags) post-flags)) + (logior (logior fsw pre-flags) post-flags))))))))) +) + +;;;*************************************************************** +;;; ARM Instructions +;;;*************************************************************** + +(defsection-rtl |ARM AArch32 Floating-Point Instructions| + |Floating-Point Exceptions and Specification of Elementary Arithmetic Instructions| + +;; FPSCR bits: + +(defn ioc () 0) ; exception flags +(defn dzc () 1) +(defn ofc () 2) +(defn ufc () 3) +(defn ixc () 4) +(defn idc () 7) + +(defund fpscr-rc (fpscr) ; rounding mode + (declare (xargs :guard (natp fpscr))) + (case (bits fpscr 23 22) + (0 'rne) + (1 'rup) + (2 'rdn) + (3 'rtz))) + +(defn fz () 24) ; force-to-zero mode + +(defn dn () 25) ; default NaN mode + +;; When a NaN is to be returned and DN is set, the default is used: + +(defun process-nan (x fpscr f) + (declare (xargs :guard (and (encodingp x f) + (natp fpscr)))) + (if (= (bitn fpscr (dn)) 1) + (indef f) + (qnanize x f))) + +;;-------------------------------------------------------------------------------- + +;; The arguments of ARM-BINARY-SPEC are an operation (add, sub, mul, or div), 2 data +;; inputs, the initial FPSCR register, and a floating-point format. It returns a data +;; result and the updated FPSCR. + +;; ARM-BINARY-SPEC is based on two auxiliary functions: ARM-BINARY-PRE-COMP returns +;; an optional value and an updated FPSCR, and ARM-BINARY-COMP returns a value +;; and an updated FPSCR. + +;; ARM-BINARY-PRE-COMP calls ARM-BINARY-PRE-COMP-EXCP, which detects pre-computation +;; exceptions, and ARM-BINARY-PRE-COMP-VAL, which may compute a value. If the value +;; is NIL, then the computation proceeds by calling ARM-BINARY-COMP, and if non-NIL, +;; the operation is terminated and that value is returned. + +;; ARM-BINARY-COMP either returns an infinity or decodes the operands and computes the +;; unrounded result. If that result is 0, then it sets the sign according to the operand +;; signs and the rounding mode and returns. Otherwise, it calls ARM-POST-COMP, which detects +;; post-computation exceptions and computes the rounded result. + +(defun arm-binary-pre-comp-excp (op a b fpscr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp fpscr)))) + (if (or (snanp a f) (snanp b f)) + (set-flag (ioc) fpscr) + (if (or (qnanp a f) (qnanp b f)) + fpscr + (if (binary-undefined-p op a f b f) + (set-flag (ioc) fpscr) + (if (and (eql op 'div) (zerp b f) (not (infp a f))) + (set-flag (dzc) fpscr) + fpscr))))) + +(defun arm-binary-pre-comp-val (op a b fpscr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp fpscr)))) + (if (snanp a f) + (process-nan a fpscr f) + (if (snanp b f) + (process-nan b fpscr f) + (if (qnanp a f) + (process-nan a fpscr f) + (if (qnanp b f) + (process-nan b fpscr f) + (if (binary-undefined-p op a f b f) + (indef f) + ())))))) + +(defun arm-binary-pre-comp (op a b fpscr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp fpscr)))) + (mv-let (a b fpscr) + (if (= (bitn fpscr (fz)) 1) + (mv (if (denormp a f) + (zencode (sgnf a f) f) + a) + (if (denormp b f) + (zencode (sgnf b f) f) + b) + (if (and (or (denormp a f) (denormp b f)) + (not (equal f (hp)))) + (set-flag (idc) fpscr) + fpscr)) + (mv a b fpscr)) + (mv a b + (arm-binary-pre-comp-val op a b fpscr f) + (arm-binary-pre-comp-excp op a b fpscr f)))) + +(defun arm-post-comp (u fpscr f) + (declare (xargs :guard (and (real/rationalp u) + (not (= u 0)) + (natp fpscr) + (formatp f)))) + (let* ((rmode (fpscr-rc fpscr)) + (r (rnd u rmode (prec f))) + (sgn (if (< u 0) 1 0))) + (if (> (abs r) (lpn f)) + (let ((fpscr (set-flag (ofc) (set-flag (ixc) fpscr)))) + (if (or (and (eql rmode 'rdn) (> r 0)) + (and (eql rmode 'rup) (< r 0)) + (eql rmode 'rtz)) + (mv (nencode (* (sgn r) (lpn f)) f) + fpscr) + (mv (iencode sgn f) fpscr))) + (if (< (abs u) (spn f)) + (if (= (bitn fpscr (fz)) 1) + (mv (zencode sgn f) (set-flag (ufc) fpscr)) + (let ((d (drnd u rmode f))) + (if (= d u) + (mv (dencode d f) fpscr) + (let ((fpscr (set-flag (ixc) (set-flag (ufc) fpscr)))) + (if (= d 0) + (mv (zencode sgn f) fpscr) + (if (= (abs d) (spn f)) + (mv (nencode d f) fpscr) + (mv (dencode d f) fpscr))))))) + (mv (nencode r f) + (if (= r u) fpscr (set-flag (ixc) fpscr))))))) + +(defun arm-binary-comp (op a b fpscr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp fpscr)))) + (if (or (infp a f) (if (eql op 'div) (zerp b f) (infp b f))) + (mv (iencode (binary-inf-sgn op a f b f) f) fpscr) + (let* ((asgn (sgnf a f)) + (bsgn (sgnf b f)) + (aval (decode a f)) + (bval (decode b f)) + (u (binary-eval op aval bval))) + (if (or (and (eql op 'div) (infp b f)) (= u 0)) + (mv (zencode (binary-zero-sgn op asgn bsgn (fpscr-rc fpscr)) f) fpscr) + (arm-post-comp u fpscr f))))) + +(defun arm-binary-spec (op a b fpscr f) + (declare (xargs :guard (and (member op '(add sub mul div)) + (encodingp a f) + (encodingp b f) + (natp fpscr)))) + (mv-let (a b result fpscr) (arm-binary-pre-comp op a b fpscr f) + (if result + (mv result fpscr) + (arm-binary-comp op a b fpscr f)))) + + +;;-------------------------------------------------------------------------------- + +;; The arguments of ARM-SQRT-SPEC are a data input, the initial FPSCR register, and +;; a floating-point formay. It returns a data result and the updated MXCSR. + +(defun arm-sqrt-pre-comp-excp (a fpscr f) + (declare (xargs :guard (and (encodingp a f) + (natp fpscr)))) + (if (snanp a f) + (set-flag (ioc) fpscr) + (if (qnanp a f) + fpscr + (if (and (not (zerp a f)) (= (sgnf a f) 1)) + (set-flag (ioc) fpscr) + fpscr)))) + +(defun arm-sqrt-pre-comp-val (a fpscr f) + (declare (xargs :guard (and (encodingp a f) + (natp fpscr)))) + (if (nanp a f) + (process-nan a fpscr f) + (if (and (not (zerp a f)) (= (sgnf a f) 1)) + (indef f) + ()))) + +(defun arm-sqrt-pre-comp (a fpscr f) + (declare (xargs :guard (and (encodingp a f) + (natp fpscr)))) + (mv-let (a fpscr) + (if (and (denormp a f) (= (bitn fpscr (fz)) 1)) + (mv (zencode (sgnf a f) f) + (if (not (equal f (hp))) + (set-flag (idc) fpscr) + fpscr)) + (mv a fpscr)) + (mv a (arm-sqrt-pre-comp-val a fpscr f) (arm-sqrt-pre-comp-excp a fpscr f)))) + +(defun arm-sqrt-comp (a fpscr f) + (declare (xargs :guard (and (encodingp a f) + (or (zerp a f) (= (sgnf a f) 0)) + (natp fpscr)))) + (if (or (infp a f) (zerp a f)) + (mv a fpscr) + (arm-post-comp (qsqrt (decode a f) (+ (prec f) 2)) fpscr f))) + +(defun arm-sqrt-spec (a fpscr f) + (declare (xargs :guard (and (encodingp a f) + (natp fpscr)))) + (mv-let (a result fpscr) (arm-sqrt-pre-comp a fpscr f) + (if result + (mv result fpscr) + (arm-sqrt-comp a fpscr f)))) + + +;;-------------------------------------------------------------------------------- + +;; The arguments of ARM-FMA-SPEC are three data inputs, the initial FPSCR register, and +;; a floating-point format. It returns a data result and the updated FPSCR. +;; Note that this instruction computes A + B * C. + +(defun arm-fma-pre-comp-excp (a b c fpscr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp fpscr)))) + (if (or (snanp a f) (snanp b f) (snanp c f) + (fma-undefined-p b c a f)) + (set-flag (ioc) fpscr) + fpscr)) + +(defun arm-fma-pre-comp-val (a b c fpscr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp fpscr)))) + (if (snanp a f) + (process-nan a fpscr f) + (if (snanp b f) + (process-nan b fpscr f) + (if (snanp c f) + (process-nan c fpscr f) + (if (fma-undefined-p b c a f) + (indef f) + (if (qnanp a f) + (process-nan a fpscr f) + (if (qnanp b f) + (process-nan b fpscr f) + (if (qnanp c f) + (process-nan c fpscr f) + ())))))))) + +(defun arm-fma-pre-comp (a b c fpscr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp fpscr)))) + (mv-let (a b c fpscr) + (if (= (bitn fpscr (fz)) 1) + (mv (if (denormp a f) + (zencode (sgnf a f) f) + a) + (if (denormp b f) + (zencode (sgnf b f) f) + b) + (if (denormp c f) + (zencode (sgnf c f) f) + c) + (if (and (or (denormp a f) (denormp b f) (denormp c f)) + (not (equal f (hp)))) + (set-flag (idc) fpscr) + fpscr)) + (mv a b c fpscr)) + (mv a b c + (arm-fma-pre-comp-val a b c fpscr f) + (arm-fma-pre-comp-excp a b c fpscr f)))) + +(defun arm-fma-comp (a b c fpscr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp fpscr)))) + (let* ((asgn (sgnf a f)) + (bsgn (sgnf b f)) + (csgn (sgnf c f)) + (aval (decode a f)) + (bval (decode b f)) + (cval (decode c f)) + (u (+ aval (* bval cval)))) + (if (or (infp b f) (infp c f)) + (mv (iencode (logxor bsgn csgn) f) fpscr) + (if (infp a f) + (mv a fpscr) + (if (= u 0) + (mv (zencode (if (= (logxor bsgn csgn) asgn) + asgn + (if (eql (fpscr-rc fpscr) 'rdn) 1 0)) + f) + fpscr) + (arm-post-comp u fpscr f)))))) + +(defun arm-fma-spec (a b c fpscr f) + (declare (xargs :guard (and (encodingp a f) + (encodingp b f) + (encodingp c f) + (natp fpscr)))) + (mv-let (a b c result fpscr) (arm-fma-pre-comp a b c fpscr f) + (if result + (mv result fpscr) + (arm-fma-comp a b c fpscr f)))) + +;;-------------------------------------------------------------------------------- + +;; The operands of FSCALE are a floating-point encoding A and a signed integer +;; encoding B. The exponent of A is incremented by the value of B. +;; The arguments of ARM-FSCALE-SPEC are these two operands, the initial FPSCR +;; register, and a floating-point format. It returns a data result and the updated +;; FPSCR. + +(defun arm-fscale-pre-comp (a fpscr f) + (declare (xargs :guard (and (encodingp a f) + (natp fpscr)))) + (mv-let (a fpscr) + (if (and (= (bitn fpscr (fz)) 1) + (denormp a f)) + (mv (zencode (sgnf a f) f) + (set-flag (idc) fpscr)) + (mv a fpscr)) + (mv a + (if (nanp a f) + (process-nan a fpscr f) + ()) + (if (snanp a f) + (set-flag (ioc) fpscr) + fpscr)))) + +(defun arm-fscale-comp (a b fpscr f) + (declare (xargs :guard (and (encodingp a f) + (natp b) + (natp fpscr)) + :guard-hints (("Goal" :in-theory (enable decode-0))))) + (if (or (zerp a f) (infp a f)) + (mv a fpscr) + (let* ((fwidth (+ 1 (expw f) (sigw f))) + (aval (decode a f)) + (bval (si b fwidth)) + (u (* aval (expt 2 bval)))) + (arm-post-comp u fpscr f)))) + +(defun arm-fscale-spec (a b fpscr f) + (declare (xargs :guard (and (encodingp a f) + (natp b) + (natp fpscr)))) + (mv-let (a result fpscr) (arm-fscale-pre-comp a fpscr f) + (if result + (mv result fpscr) + (arm-fscale-comp a b fpscr f)))) + +;;-------------------------------------------------------------------------------- + +;; We include specifications of two operations in support of the Arm BFloat16 +;; instructions, which are based on the 16-bit BF format (8-bit exponent, 7-bit +;; mantissa). These instructions do not access FPSCR or set exception flags, +;; but assume DN = FZ = 1, return infinity of overflow, and use round-to-odd. + +;; Odd-round a non-zero value u and encode in the SP format, with overflow +;; resulting in an infinity and underflow resulting in a zero: + +(defund bf-post-comp (u) + (declare (xargs :guard (and (real/rationalp u) + (not (= u 0))))) + (let ((sgnf (if (< u 0) 1 0)) + (r (rto u 24))) + (if (> (abs r) (lpn (sp))) + (iencode sgnf (sp)) + (if (< (abs u) (spn (sp))) + (zencode sgnf (sp)) + (nencode r (sp)))))) + +;; SP product of 2 BF operands. Note that in the case of a normal result, +;; the product is 16-exact so no rounding is required: + +(defund bfmul16-spec (a b) + (declare (xargs :guard (and (encodingp a (bf)) + (encodingp b (bf))))) + (let ((sgnr (logxor (sgnf a (bf)) (sgnf b (bf))))) + (if (or (nanp a (bf)) + (nanp b (bf)) + (and (infp a (bf)) + (or (zerp b (bf)) (denormp b (bf)))) + (and (infp b (bf)) + (or (zerp a (bf)) (denormp a (bf))))) + (indef (sp)) + (if (or (infp a (bf)) (infp b (bf))) + (iencode sgnr (sp)) + (if (or (zerp a (bf)) (denormp a (bf)) + (zerp b (bf)) (denormp b (bf))) + (zencode sgnr (sp)) + (bf-post-comp (* (ndecode a (bf)) (ndecode b (bf))))))))) + +;; SP sum of 2 SP operands: + +(defund bfadd32-spec (a b) + (declare (xargs :guard (and (encodingp a (sp)) + (encodingp b (sp))))) + (let* ((sgna (sgnf a (sp))) + (sgnb (sgnf b (sp))) + (aval (if (or (zerp a (sp)) (denormp a (sp))) 0 (ndecode a (sp)))) + (bval (if (or (zerp b (sp)) (denormp b (sp))) 0 (ndecode b (sp)))) + (u (+ aval bval))) + (if (or (nanp a (sp)) + (nanp b (sp)) + (and (infp a (sp)) (infp b (sp)) (not (= sgna sgnb)))) + (indef (sp)) + (if (infp a (sp)) + a + (if (infp b (sp)) + b + (if (= u 0) + (if (= sgna sgnb) + (zencode sgna (sp)) + (zencode 0 (sp))) + (bf-post-comp u))))))) + +) + diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/float.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/float.lisp new file mode 100644 index 000000000..ff9ab673e --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/float.lisp @@ -0,0 +1,507 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; Sign, Significand, and Exponent +;;;********************************************************************** + +(defsection-rtl |Floating-Point Decomposition| |Floating-Point Numbers| + +(defnd sgn (x) + (if (or (not (rationalp x)) (equal x 0)) + 0 + (if (< x 0) -1 +1))) + +(defnd expo (x) + (declare (xargs :measure (:? x) +; Matt K. addition after bug fix to require well-founded relations to match for +; a redundant definition: + :well-founded-relation e0-ord-<)) + (mbe :logic (cond ((or (not (rationalp x)) (equal x 0)) 0) + ((< x 0) (expo (- x))) + ((< x 1) (1- (expo (* 2 x)))) + ((< x 2) 0) + (t (1+ (expo (/ x 2))))) + :exec (if (rationalp x) + (let* ((n (abs (numerator x))) + (d (denominator x)) + (ln (integer-length n)) + (ld (integer-length d)) + (l (- ln ld))) + (if (>= ln ld) + (if (>= (ash n (- l)) d) l (1- l)) + (if (> ln 1) + (if (> n (ash d l)) l (1- l)) + (- (integer-length (1- d)))))) + 0))) + +(defnd sig (x) + (if (rationalp x) + (if (< x 0) + (- (* x (expt 2 (- (expo x))))) + (* x (expt 2 (- (expo x))))) + 0)) + +(defthm expo-minus + (implies (rationalp x) + (equal (expo (- x)) (expo x)))) + +(defthm sig-minus + (implies (rationalp x) + (equal (sig (- x)) (sig x)))) + +(defthmd expo-lower-bound + (implies (and (rationalp x) + (not (equal x 0))) + (<= (expt 2 (expo x)) (abs x))) + :rule-classes :linear) + +(defthmd expo-upper-bound + (implies (and (rationalp x)) + (< (abs x) (expt 2 (1+ (expo x))))) + :rule-classes :linear) + +(defthm expo-unique + (implies (and (<= (expt 2 n) (abs x)) + (< (abs x) (expt 2 (1+ n))) + (rationalp x) + (integerp n)) + (equal n (expo x))) + :rule-classes ()) + +(defthm fp-rep + (implies (rationalp x) + (equal x (* (sgn x) (sig x) (expt 2 (expo x))))) + :rule-classes ()) + +(defthm fp-abs + (implies (rationalp x) + (equal (abs x) (* (sig x) (expt 2 (expo x))))) + :rule-classes ()) + +(defthmd expo>= + (implies (and (<= (expt 2 n) x) + (rationalp x) + (integerp n)) + (<= n (expo x))) + :rule-classes :linear) + +(defthmd expo<= + (implies (and (< x (* 2 (expt 2 n))) + (< 0 x) + (rationalp x) + (integerp n)) + (<= (expo x) n)) + :rule-classes :linear) + +(defthm expo-2**n + (implies (integerp n) + (equal (expo (expt 2 n)) + n))) + +(defthmd bitn-expo + (implies (not (zp x)) + (equal (bitn x (expo x)) 1))) + +(defthmd expo-monotone + (implies (and (<= (abs x) (abs y)) + (case-split (rationalp x)) + (case-split (not (equal x 0))) + (case-split (rationalp y))) + (<= (expo x) (expo y))) + :rule-classes :linear) + +(defthmd bvecp-expo + (implies (case-split (natp x)) + (bvecp x (1+ (expo x))))) + +(defthmd mod-expo + (implies (and (< 0 x) + (rationalp x)) + (equal (mod x (expt 2 (expo x))) + (- x (expt 2 (expo x)))))) + +(defthmd sig-lower-bound + (implies (and (rationalp x) + (not (equal x 0))) + (<= 1 (sig x))) + :rule-classes (:rewrite :linear)) + +(defthmd sig-upper-bound + (< (sig x) 2) + :rule-classes (:rewrite :linear)) + +(defthm expo-sig + (implies (rationalp x) + (equal (expo (sig x)) 0))) + +(defthmd sig-self + (implies (and (rationalp x) + (<= 1 x) + (< x 2)) + (equal (sig x) x))) + +(defthm sig-sig + (equal (sig (sig x)) + (sig x))) + +(defthm fp-rep-unique + (implies (and (rationalp x) + (rationalp m) + (<= 1 m) + (< m 2) + (integerp e) + (= (abs x) (* m (expt 2 e)))) + (and (= m (sig x)) + (= e (expo x)))) + :rule-classes ()) + +(defthmd sgn-shift + (equal (sgn (* x (expt 2 k))) + (sgn x))) + +(defthmd expo-shift + (implies (and (rationalp x) + (not (equal x 0)) + (integerp n)) + (equal (expo (* (expt 2 n) x)) + (+ n (expo x))))) + +(defthmd sig-shift + (equal (sig (* (expt 2 n) x)) + (sig x))) + +(defthmd sgn-prod + (implies (and (case-split (rationalp x)) + (case-split (rationalp y))) + (equal (sgn (* x y)) + (* (sgn x) (sgn y))))) + +(defthmd expo-prod + (implies (and (rationalp x) + (not (= x 0)) + (rationalp y) + (not (= y 0))) + (equal (expo (* x y)) + (if (< (* (sig x) (sig y)) 2) + (+ (expo x) (expo y)) + (+ 1 (expo x) (expo y)))))) + +(defthmd expo-prod-lower + (implies (and (rationalp x) + (not (= x 0)) + (rationalp y) + (not (= y 0))) + (<= (+ (expo x) (expo y)) (expo (* x y)))) + :rule-classes :linear) + +(defthmd expo-prod-upper + (implies (and (rationalp x) + (not (= x 0)) + (rationalp y) + (not (= y 0))) + (>= (+ (expo x) (expo y) 1) (expo (* x y)))) + :rule-classes :linear) + +(defthmd sig-prod + (implies (and (rationalp x) + (not (= x 0)) + (rationalp y) + (not (= y 0))) + (equal (sig (* x y)) + (if (< (* (sig x) (sig y)) 2) + (* (sig x) (sig y)) + (* 1/2 (sig x) (sig y)))))) + +(defthmd expo-fl + (implies (and (rationalp x) + (>= x 1)) + (equal (expo (fl x)) (expo x)))) + +(defthmd expo-logior + (implies (and (natp x) + (natp y) + (<= (expo x) (expo y))) + (equal (expo (logior x y)) + (expo y)))) +) + +;;;********************************************************************** +;;; Exactness +;;;********************************************************************** + +(defsection-rtl |Exactness| |Floating-Point Numbers| + +(defund exactp (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (integerp (* (sig x) (expt 2 (1- n))))) + +(defthmd exactp2 + (implies (and (rationalp x) + (integerp n)) + (equal (exactp x n) + (integerp (* x (expt 2 (- (1- n) (expo x)))))))) + +(defthm exactp-sig + (equal (exactp (sig x) n) + (exactp x n))) + +(defthm minus-exactp + (equal (exactp (- x) n) + (exactp x n))) + +(defthm exactp-abs + (equal (exactp (abs x) n) + (exactp x n))) + +(defthmd exactp-shift + (implies (and (rationalp x) + (integerp k) + (integerp n)) + (equal (exactp (* (expt 2 k) x) n) + (exactp x n)))) + +(defthmd exactp-<= + (implies (and (exactp x m) + (<= m n) + (rationalp x) + (integerp n) + (integerp m)) + (exactp x n))) + +(defthmd exactp-2**n + (implies (and (case-split (integerp m)) + (case-split (> m 0))) + (exactp (expt 2 n) m))) + +(defthm bvecp-exactp + (implies (bvecp x n) + (exactp x n))) + +(defthm exactp-prod + (implies (and (rationalp x) + (rationalp y) + (integerp m) + (integerp n) + (exactp x m) + (exactp y n)) + (exactp (* x y) (+ m n))) + :rule-classes ()) + +(defthm exactp-x2 + (implies (and (rationalp x) + (integerp n) + (exactp (* x x) (* 2 n))) + (exactp x n)) + :rule-classes ()) + +(defthm exactp-factors + (implies (and (rationalp x) + (rationalp y) + (integerp k) + (integerp n) + (not (zerop x)) + (not (zerop y)) + (exactp x k) + (exactp y k) + (exactp (* x y) n)) + (exactp x n)) + :rule-classes ()) + +(defthm exact-bits-1 + (implies (and (equal (expo x) (1- n)) + (rationalp x) + (integerp k)) + (equal (integerp (/ x (expt 2 k))) + (exactp x (- n k)))) + :rule-classes ()) + +(defthm exact-bits-2 + (implies (and (equal (expo x) (1- n)) + (rationalp x) + (<= 0 x) + (integerp k) + ) + (equal (integerp (/ x (expt 2 k))) + (equal (bits x (1- n) k) + (/ x (expt 2 k))))) + :rule-classes ()) + +(defthm exact-bits-3 + (implies (integerp x) + (equal (integerp (/ x (expt 2 k))) + (equal (bits x (1- k) 0) + 0))) + :rule-classes ()) + +(defthm exact-k+1 + (implies (and (natp n) + (natp x) + (= (expo x) (1- n)) + (natp k) + (< k (1- n)) + (exactp x (- n k))) + (iff (exactp x (1- (- n k))) + (= (bitn x k) 0))) + :rule-classes ()) + +(defthm exactp-diff + (implies (and (rationalp x) + (rationalp y) + (integerp k) + (integerp n) + (> n 0) + (> n k) + (exactp x n) + (exactp y n) + (<= (+ k (expo (- x y))) (expo x)) + (<= (+ k (expo (- x y))) (expo y))) + (exactp (- x y) (- n k))) + :rule-classes ()) + +(defthm exactp-diff-cor + (implies (and (rationalp x) + (rationalp y) + (integerp n) + (> n 0) + (exactp x n) + (exactp y n) + (<= (abs (- x y)) (abs x)) + (<= (abs (- x y)) (abs y))) + (exactp (- x y) n)) + :rule-classes ()) + +(defun fp+ (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (+ x (expt 2 (- (1+ (expo x)) n)))) + +(defthm fp+-positive + (implies (<= 0 x) + (< 0 (fp+ x n))) + :rule-classes :type-prescription) + +(defthm fp+1 + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0) + (exactp x n)) + (exactp (fp+ x n) n)) + :rule-classes ()) + +(defthm fp+2 + (implies (and (rationalp x) + (> x 0) + (rationalp y) + (> y x) + (integerp n) + (> n 0) + (exactp x n) + (exactp y n)) + (>= y (fp+ x n))) + :rule-classes ()) + +(defthm fp+expo + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0) + (exactp x n) + (not (= (expo (fp+ x n)) (expo x)))) + (equal (fp+ x n) (expt 2 (1+ (expo x))))) + :rule-classes ()) + +(defthm expo-diff-min + (implies (and (rationalp x) + (rationalp y) + (integerp n) + (> n 0) + (exactp x n) + (exactp y n) + (not (= y x))) + (>= (expo (- y x)) (- (1+ (min (expo x) (expo y))) n))) + :rule-classes ()) + +(defun fp- (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (= x (expt 2 (expo x))) + (- x (expt 2 (- (expo x) n))) + (- x (expt 2 (- (1+ (expo x)) n))))) + +(defthm fp--non-negative + (implies (and (rationalp x) + (integerp n) + (> n 0) + (> x 0)) + (and (rationalp (fp- x n)) + (< 0 (fp- x n)))) + :rule-classes :type-prescription) + +(defthm exactp-fp- + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0) + (exactp x n)) + (exactp (fp- x n) n))) + +(defthm fp+- + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0) + (exactp x n)) + (equal (fp+ (fp- x n) n) + x))) + +(defthm fp-+ + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0) + (exactp x n)) + (equal (fp- (fp+ x n) n) + x))) + +(defthm fp-2 + (implies (and (rationalp x) + (rationalp y) + (> y 0) + (> x y) + (integerp n) + (> n 0) + (exactp x n) + (exactp y n)) + (<= y (fp- x n))) + :rule-classes ()) + + (defthmd expo-fp- + (implies (and (rationalp x) + (> x 0) + (not (= x (expt 2 (expo x)))) + (integerp n) + (> n 0) + (exactp x n)) + (equal (expo (fp- x n)) (expo x)))) +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/gl.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/gl.lisp new file mode 100644 index 000000000..f3e0c797f --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/gl.lisp @@ -0,0 +1,88 @@ +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(include-book "centaur/gl/gl" :dir :system) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") +(include-book "rac") + +;;;********************************************************************** + +(defrule bits-for-gl + (equal (bits x i j) + (if (and (integerp x) + (integerp i) + (integerp j)) + (if (< i j) + 0 + (logand (ash x (- j)) + (1- (ash 1 (1+ (- i j)))))) + (let ((msg (cw "WARNING: guard violation for the function BITS during a GL proof:~%(BITS ~x0 ~x1 ~x2)~%" x i j))) + ;(let ((msg (cw "WARNING: guard violation for the function BITS during a GL proof.~%"))) + (declare (ignore msg)) + (if (or (not (integerp i)) + (not (integerp j))) + 0 + (fl (/ (mod x (expt 2 (1+ i))) (expt 2 j))))))) + :rule-classes ()) + +(gl::set-preferred-def bits bits-for-gl) + +(defthm bitn-for-gl + (equal (bitn x n) + (if (and (integerp x) + (integerp n)) + (if (< n 0) + 0 + (if (logbitp n x) 1 0)) + (let ((msg (cw "WARNING: guard violation for the function BITN during a GL proof:~%(BITN ~x0 ~x1)~%" x n))) + ;(let ((msg (cw "WARNING: guard violation for the function BITN during a GL proof.~%"))) + (declare (ignore msg)) + (if (not (integerp n)) + 0 + (fl (/ (mod x (expt 2 (1+ n))) (expt 2 n))))))) + :rule-classes ()) + +(gl::set-preferred-def bitn bitn-for-gl) + +(defthm binary-cat-for-gl + (equal (binary-cat x m y n) + (if (and (natp m) + (natp n)) + (logior (ash (BITS X (1- M) 0) n) + (BITS Y (1- N) 0)) + 0)) + :rule-classes ()) + +(gl::set-preferred-def binary-cat binary-cat-for-gl) + +(defthm expo-for-gl + (equal (expo x) + (if (integerp x) + (if (= x 0) + 0 + (1- (integer-length (abs x)))) + (let ((msg (cw "WARNING: guard violation for the function EXPO during a GL proof.~%"))) + (declare (ignore msg)) + (expo x)))) + :rule-classes ()) + +(gl::set-preferred-def expo expo-for-gl) + +(gl::def-gl-rewrite ag-of-as + (equal (ag a (as wa v r)) + (if (equal a wa) v (ag a r)))) + +(gl::def-gl-rewrite ag-of-nil + (equal (ag a nil) (default-get-valu))) + +(gl::gl-set-uninterpreted ag) + +(gl::gl-set-uninterpreted as) + diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/log.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/log.lisp new file mode 100644 index 000000000..058bdf4c1 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/log.lisp @@ -0,0 +1,545 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) ; for some reason, acl2 4.3 complains about logand-natp + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; LOGAND, LOGIOR, and LOGXOR +;;;********************************************************************** + +(defsection-rtl |Binary Operations| |Logical Operations| + +(in-theory (disable logand logior logxor)) + +(defthmd logand-def + (equal (logand x y) + (if (or (zip x) (zip y)) + 0 + (if (= x y) + x + (+ (* 2 (logand (fl (/ x 2)) (fl (/ y 2)))) + (logand (mod x 2) (mod y 2)))))) + :rule-classes ((:definition :controller-alist ((binary-logand t t))))) + +(defthmd logior-def + (implies (and (integerp x) (integerp y)) + (equal (logior x y) + (if (or (zip x) (= x y)) + y + (if (zip y) + x + (+ (* 2 (logior (fl (/ x 2)) (fl (/ y 2)))) + (logior (mod x 2) (mod y 2))))))) + :rule-classes ((:definition :controller-alist ((binary-logior t t))))) + +(defthmd logxor-def + (implies (and (integerp x) (integerp y)) + (equal (logxor x y) + (if (zip x) + y + (if (zip y) + x + (if (= x y) + 0 + (+ (* 2 (logxor (fl (/ x 2)) (fl (/ y 2)))) + (logxor (mod x 2) (mod y 2)))))))) + :rule-classes ((:definition :controller-alist ((binary-logxor t t))))) + +(defun log-induct (x y) + (declare (xargs :measure (abs (* (ifix x) (ifix y))))) + (if (or (not (integerp x)) (not (integerp y)) (= x 0) (= y 0) (= x y)) + (+ x y) + (log-induct (fl (/ x 2)) (fl (/ y 2))))) + +(defthm logand-bvecp + (implies (and (natp n) + (bvecp x n) + (integerp y)) + (bvecp (logand x y) n))) + +(defthm logior-bvecp + (implies (and (bvecp x n) + (bvecp y n)) + (bvecp (logior x y) n))) + +(defthm logxor-bvecp + (implies (and (bvecp x n) + (bvecp y n) + (natp n)) + (bvecp (logxor x y) n))) + +(defthmd logand-plus-logxor + (implies (and (integerp x) + (integerp y)) + (equal (+ (logand x y) (logxor x y)) + (logior x y)))) + +(defthmd logand-mod + (implies (and (integerp x) + (integerp y) + (integerp n)) + (equal (mod (logand x y) (expt 2 n)) + (logand (mod x (expt 2 n)) + (mod y (expt 2 n)))))) + +(defthmd logior-mod + (implies (and (integerp x) + (integerp y) + (integerp n)) + (equal (mod (logior x y) (expt 2 n)) + (logior (mod x (expt 2 n)) + (mod y (expt 2 n)))))) + +(defthmd logxor-mod + (implies (and (integerp x) + (integerp y) + (integerp n)) + (equal (mod (logxor x y) (expt 2 n)) + (logxor (mod x (expt 2 n)) + (mod y (expt 2 n)))))) + +(defthmd fl-logand + (implies (and (integerp x) + (integerp y) + (natp n)) + (equal (fl (* (expt 2 (- n)) (logand x y))) + (logand (fl (* (expt 2 (- n)) x)) (fl (* (expt 2 (- n)) y)))))) + +(defthmd fl-logior + (implies (and (integerp x) + (integerp y) + (natp n)) + (equal (fl (* (expt 2 (- n)) (logior x y))) + (logior (fl (* (expt 2 (- n)) x)) (fl (* (expt 2 (- n)) y)))))) + +(defthmd fl-logxor + (implies (and (integerp x) + (integerp y) + (natp n)) + (equal (fl (* (expt 2 (- n)) (logxor x y))) + (logxor (fl (* (expt 2 (- n)) x)) (fl (* (expt 2 (- n)) y)))))) + + +(defthmd logand-cat + (implies (and (case-split (integerp x1)) + (case-split (integerp y1)) + (case-split (integerp x2)) + (case-split (integerp y2)) + (case-split (natp n)) + (case-split (natp m))) + (equal (logand (cat x1 m y1 n) (cat x2 m y2 n)) + (cat (logand x1 x2) m (logand y1 y2) n)))) + +(defthmd logior-cat + (implies (and (case-split (integerp x1)) + (case-split (integerp y1)) + (case-split (integerp x2)) + (case-split (integerp y2)) + (case-split (natp n)) + (case-split (natp m))) + (equal (logior (cat x1 m y1 n) (cat x2 m y2 n)) + (cat (logior x1 x2) m (logior y1 y2) n)))) + +(defthmd logxor-cat + (implies (and (case-split (integerp x1)) + (case-split (integerp y1)) + (case-split (integerp x2)) + (case-split (integerp y2)) + (case-split (natp n)) + (case-split (natp m))) + (equal (logxor (cat x1 m y1 n) (cat x2 m y2 n)) + (cat (logxor x1 x2) m (logxor y1 y2) n)))) + +(defthmd logand-shift + (implies (and (integerp x) + (integerp y) + (natp k)) + (equal (logand (* (expt 2 k) x) + (* (expt 2 k) y)) + (* (expt 2 k) (logand x y))))) + +(defthmd logior-shift + (implies (and (integerp x) + (integerp y) + (natp k)) + (equal (logior (* (expt 2 k) x) + (* (expt 2 k) y)) + (* (expt 2 k) (logior x y))))) + +(defthmd logxor-shift + (implies (and (integerp x) + (integerp y) + (natp k)) + (equal (logxor (* (expt 2 k) x) + (* (expt 2 k) y)) + (* (expt 2 k) (logxor x y))))) + +(defthmd logand-expt + (implies (and (integerp x) + (integerp y) + (natp n)) + (equal (logand (* (expt 2 n) x) y) + (* (expt 2 n) (logand x (fl (/ y (expt 2 n)))))))) + +(defthmd logior-expt + (implies (and (integerp x) + (integerp y) + (natp n)) + (equal (logior (* (expt 2 n) x) y) + (+ (* (expt 2 n) (logior x (fl (/ y (expt 2 n))))) + (mod y (expt 2 n)))))) + +(defthmd logxor-expt + (implies (and (integerp x) + (integerp y) + (natp n)) + (equal (logxor (* (expt 2 n) x) y) + (+ (* (expt 2 n) (logxor x (fl (/ y (expt 2 n))))) + (mod y (expt 2 n)))))) + +(defthmd logior-expt-cor + (implies (and (natp n) + (integerp x) + (bvecp y n)) + (equal (logior (* (expt 2 n) x) y) + (+ (* (expt 2 n) x) y)))) + +(defthmd logior-2**n + (implies (and (natp n) + (integerp x)) + (equal (logior (expt 2 n) x) + (if (= (bitn x n) 1) + x + (+ x (expt 2 n)))))) + +(defthmd logand-bits + (implies (and (integerp x) + (natp n) + (natp k) + (< k n)) + (equal (logand x (- (expt 2 n) (expt 2 k))) + (* (expt 2 k) (bits x (1- n) k))))) + +(defthmd logand-bit + (implies (and (integerp x) + (natp n)) + (equal (logand x (expt 2 n)) + (* (expt 2 n) (bitn x n))))) + +(defthmd bits-logand + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j)) + (equal (bits (logand x y) i j) + (logand (bits x i j) (bits y i j))))) + +(defthmd bits-logior + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j)) + (equal (bits (logior x y) i j) + (logior (bits x i j) (bits y i j))))) + +(defthmd bits-logxor + (implies (and (integerp x) + (integerp y) + (integerp i) + (integerp j)) + (equal (bits (logxor x y) i j) + (logxor (bits x i j) (bits y i j))))) + +(defthmd bitn-logand + (implies (and (integerp x) + (integerp y) + (integerp n)) + (equal (bitn (logand x y) n) + (logand (bitn x n) (bitn y n))))) + +(defthmd bitn-logior + (implies (and (integerp x) + (integerp y) + (integerp n)) + (equal (bitn (logior x y) n) + (logior (bitn x n) (bitn y n))))) + +(defthmd bitn-logxor + (implies (and (case-split (integerp x)) + (case-split (integerp y)) + (case-split (integerp n))) + (equal (bitn (logxor x y) n) + (logxor (bitn x n) (bitn y n))))) +) + +;;;********************************************************************** +;;; LOGNOT +;;;********************************************************************** + +(defsection-rtl |Complementation| |Logical Operations| + +(in-theory (disable lognot)) + +(defthmd lognot-def + (implies (integerp x) + (equal (lognot x) + (1- (- x))))) + +(defthmd lognot-shift + (implies (and (integerp x) + (natp k)) + (equal (lognot (* (expt 2 k) x)) + (+ (* (expt 2 k) (lognot x)) + (1- (expt 2 k)))))) + +(defthmd lognot-fl + (implies (and (integerp x) + (not (zp n))) + (equal (lognot (fl (/ x n))) + (fl (/ (lognot x) n))))) + +(defthmd mod-lognot + (implies (and (integerp x) + (natp n)) + (equal (mod (lognot x) (expt 2 n)) + (1- (- (expt 2 n) (mod x (expt 2 n))))))) + +(defthmd bits-lognot + (implies (and (natp i) + (natp j) + (<= j i) + (integerp x)) + (equal (bits (lognot x) i j) + (- (1- (expt 2 (- (1+ i) j))) (bits x i j))))) + +(defthm bitn-lognot + (implies (and (integerp x) + (natp n)) + (not (equal (bitn (lognot x) n) + (bitn x n)))) + :rule-classes ()) + +(defthmd bits-lognot-bits + (implies (and (integerp x) + (natp i) + (natp j) + (natp k) + (natp l) + (<= l k) + (<= k (- i j))) + (equal (bits (lognot (bits x i j)) k l) + (bits (lognot x) (+ k j) (+ l j))))) + +(defthmd bits-lognot-bits-lognot + (implies (and (integerp x) + (natp i) + (natp j) + (natp k) + (natp l) + (<= l k) + (<= k (- i j))) + (equal (bits (lognot (bits (lognot x) i j)) k l) + (bits x (+ k j) (+ l j))))) + +(defthmd logand-bits-lognot + (implies (and (integerp x) + (integerp n) + (bvecp y n)) + (equal (logand y (bits (lognot x) (1- n) 0)) + (logand y (lognot (bits x (1- n) 0)))))) +) + +;;;********************************************************************** +;;; Algebraic Properties +;;;********************************************************************** + +(defsection-rtl |Algebraic Properties| |Logical Operations| + +(defthm logand-x-0 + (equal (logand x 0) 0)) + +(defthm logand-0-y + (equal (logand 0 y) 0)) + +(defthm logior-x-0 + (implies (integerp x) + (equal (logior x 0) x))) + +(defthm logior-0-y + (implies (integerp y) + (equal (logior 0 y) y))) + +(defthm logxor-x-0 + (implies (integerp x) + (equal (logxor x 0) x))) + +(defthm logxor-0-y + (implies (integerp y) + (equal (logxor 0 y) y))) + +(defthm logand-self + (implies (case-split (integerp x)) + (equal (logand x x) x))) + +(defthm logior-self + (implies (case-split (integerp x)) + (equal (logior x x) x))) + +(defthm logxor-self + (equal (logxor x x) 0)) + +(defthm lognot-lognot + (implies (case-split (integerp i)) + (equal (lognot (lognot i)) + i))) + +(defthmd logior-not-0 + (implies (and (integerp x) + (integerp y)) + (iff (equal (logior x y) 0) + (and (= x 0) (= y 0))))) + +(defthmd logxor-not-0 + (implies (and (integerp x) + (integerp y)) + (iff (equal (logxor x y) 0) + (= x y)))) + +(defthm logand-x-1 + (implies (bvecp x 1) + (equal (logand x 1) x))) + +(defthm logand-1-x + (implies (bvecp x 1) + (equal (logand 1 x) x))) + +(defthm logior-1-x + (implies (bvecp x 1) + (equal (logior 1 x) 1))) + +(defthm logior-x-1 + (implies (bvecp x 1) + (equal (logior x 1) 1))) + +(defthm logand-x-m1 + (implies (integerp x) + (equal (logand x -1) x))) + +(defthm logand-m1-y + (implies (integerp y) + (equal (logand -1 y) y))) + +(defthm logior-x-m1 + (implies (integerp x) + (equal (logior x -1) -1))) + +(defthm logior-m1-y + (implies (integerp y) + (equal (logior -1 y) -1))) + +(defthm logxor-x-m1 + (implies (integerp x) + (equal (logxor x -1) + (lognot x)))) + +(defthm logxor-m1-x + (implies (integerp x) + (equal (logxor -1 x) + (lognot x)))) + +(defthm logand-commutative + (equal (logand y x) (logand x y))) + +(defthm logior-commutative + (equal (logior y x) (logior x y))) + +(defthm logxor-commutative + (equal (logxor y x) (logxor x y))) + +(defthm logand-commutative-2 + (equal (logand y x z) + (logand x y z))) + +(defthm logior-commutative-2 + (equal (logior y x z) + (logior x y z))) + +(defthm logxor-commutative-2 + (equal (logxor y x z) + (logxor x y z))) + +(defthm logand-associative + (equal (logand (logand x y) z) + (logand x (logand y z)))) + +(defthm logior-associative + (equal (logior (logior x y) z) + (logior x (logior y z)))) + +(defthm logxor-associative + (equal (logxor (logxor x y) z) + (logxor x (logxor y z)))) + +(defthmd logior-logand + (implies (and (integerp x) + (integerp y) + (integerp z)) + (equal (logior x (logand y z)) + (logand (logior x y) (logior x z))))) + +(defthmd logior-logand-1 + (implies (and (integerp x) + (integerp y)) + (equal (logior x (logand x y)) + x))) + +(defthmd logand-logior + (implies (and (integerp x) + (integerp y) + (integerp z)) + (equal (logand x (logior y z)) + (logior (logand x y) (logand x z))))) + +(defthmd logior-logand-2 + (implies (and (integerp x) + (integerp y) + (integerp z)) + (equal (logand (logior y z) x) + (logior (logand y x) (logand z x))))) + +(defthmd log3 + (implies (and (integerp x) + (integerp y) + (integerp z)) + (equal (logior (logand x y) (logior (logand x z) (logand y z))) + (logior (logand x y) (logand (logxor x y) z))))) + +(defthmd logxor-rewrite + (implies (and (integerp x) + (integerp y)) + (equal (logxor x y) + (logior (logand x (lognot y)) + (logand y (lognot x)))))) + +(defthmd lognot-logxor + (and (equal (logxor (lognot x) y) + (lognot (logxor x y))) + (equal (logxor y (lognot x)) + (lognot (logxor x y))))) +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/mult.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/mult.lisp new file mode 100644 index 000000000..a339f65d8 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/mult.lisp @@ -0,0 +1,632 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") +(local (in-theory nil)) + +(include-book "defs") +(include-book "rac") + +;;;********************************************************************** +;;; Radix-4 Booth Encoding +;;;********************************************************************** + +(defsection-rtl |Radix-4 Booth Encoding| |Multiplication| + +(defun theta (i y) + (+ (bitn y (1- (* 2 i))) + (bitn y (* 2 i)) + (* -2 (bitn y (1+ (* 2 i)))))) + +(defthm theta-bounds + (and (<= -2 (theta i y)) + (<= (theta i y) 2)) + :rule-classes :linear) + +(defun sum-theta (m y) + (if (zp m) + 0 + (+ (* (expt 2 (* 2 (1- m))) (theta (1- m) y)) + (sum-theta (1- m) y)))) + +;; Signed version + +(defthmd sum-theta-lemma-signed + (implies (and (posp m) + (bvecp y (* 2 m))) + (equal (sum-theta m y) + (si y (* 2 m))))) + +(defund bmux4signed (zeta x n) + (case zeta + (1 x) + (-1 (bits (lognot x) (1- n) 0)) + (2 (bits (* 2 x) (1- n) 0)) + (-2 (bits (lognot (* 2 x)) (1- n) 0)) + (0 0))) + +(defthm bvecp-bmux4signed + (implies (and (integerp zeta) + (<= -2 zeta) + (<= zeta 2) + (integerp n) + (bvecp x n)) + (bvecp (bmux4signed zeta x n) + n)) + :hints (("Goal" :in-theory (enable bmux4signed bvecp))) + :rule-classes + ((:rewrite + :corollary + (implies (and (integerp zeta) + (<= -2 zeta) + (<= zeta 2) + (bvecp x n) + (integerp n)) + (bvecp (bmux4signed zeta x n) + n))) + (:type-prescription + :corollary + (implies (and (integerp zeta) + (<= -2 zeta) + (<= zeta 2) + (bvecp x n) + (integerp n)) + (natp (bmux4signed zeta x n)))) + (:linear + :corollary + (implies (and (integerp zeta) + (<= -2 zeta) + (<= zeta 2) + (bvecp x n) + (integerp n)) + (< (bmux4signed zeta x n) + (expt 2 n)))))) + +(defund tau (zeta sign) + (if (equal zeta 0) + 0 + (if (< 0 zeta) + sign + (lognot1 sign)))) + +(defun neg (x) (if (< x 0) 1 0)) + +(defund pp4signed-theta (i x y n) + (if (zerop i) + (cat 1 1 + (lognot1 (tau (theta i y) + (bitn x (1- n)))) + 1 + (bmux4signed (theta i y) x n) + n) + (cat 1 1 + (lognot1 (tau (theta i y) + (bitn x (1- n)))) + 1 + (bmux4signed (theta i y) x n) + n + 0 1 + (neg (theta (1- i) y)) + 1 + 0 (* 2 (1- i))))) + +(defun sum-pp4signed-theta (x y m n) + (if (zp m) + 0 + (+ (pp4signed-theta (1- m) x y n) + (sum-pp4signed-theta x y (1- m) n)))) + +(defthmd booth4signed-corollary + (implies (and (posp m) + (posp n) + (bvecp x n) + (bvecp y (* 2 m))) + (equal (sum-pp4signed-theta x y m n) + (+ (- (expt 2 n)) + (- (* (expt 2 (* 2 (1- m))) + (neg (theta (1- m) y)))) + (expt 2 (+ n (* 2 m))) + (* (si x n) (si y (* 2 m))))))) + +(defthmd booth4signed-corollary-alt + (implies (and (posp m) + (posp n) + (bvecp x n) + (bvecp y (* 2 m))) + (equal (+ (expt 2 n) + (* (expt 2 (* 2 (1- m))) + (neg (theta (1- m) y))) + (sum-pp4signed-theta x y m n)) + (+ (expt 2 (+ n (* 2 m))) + (* (si x n) (si y (* 2 m))))))) + +;; Unsigned versions + +(defthm sum-theta-lemma + (implies (and (not (zp m)) + (bvecp y (1- (* 2 m)))) + (equal y (sum-theta m y))) + :rule-classes ()) + +(defun bmux4 (zeta x n) + (case zeta + (1 x) + (-1 (bits (lognot x) (1- n) 0)) + (2 (* 2 x)) + (-2 (bits (lognot (* 2 x)) (1- n) 0)) + (0 0))) + +(defun pp4-theta (i x y n) + (if (zerop i) + (cat 1 1 + (bitn (lognot (neg (theta i y))) 0) 1 + (bmux4 (theta i y) x n) n) + (cat 1 1 + (bitn (lognot (neg (theta i y))) 0) 1 + (bmux4 (theta i y) x n) n + 0 1 + (neg (theta (1- i) y)) 1 + 0 (* 2 (1- i))))) + +(defun sum-pp4-theta (x y m n) + (if (zp m) + 0 + (+ (pp4-theta (1- m) x y n) + (sum-pp4-theta x y (1- m) n)))) + +(defthm booth4-corollary-1 + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (1- n)) + (bvecp y (1- (* 2 m)))) + (= (+ (expt 2 n) + (sum-pp4-theta x y m n)) + (+ (expt 2 (+ n (* 2 m))) + (* x y)))) + :rule-classes ()) + +;;------------------------------------------------------------------------------------------------ + +(defun pp4p-theta (i x y n) + (if (zerop i) + (cat (bitn (lognot (neg (theta i y))) 0) 1 + (neg (theta i y)) 1 + (neg (theta i y)) 1 + (bmux4 (theta i y) x n) n) + (cat 1 1 + (bitn (lognot (neg (theta i y))) 0) 1 + (bmux4 (theta i y) x n) n + 0 1 + (neg (theta (1- i) y)) 1 + 0 (* 2 (1- i))))) + +(defun sum-pp4p-theta (x y m n) + (if (zp m) + 0 + (+ (pp4p-theta (1- m) x y n) + (sum-pp4p-theta x y (1- m) n)))) + +(defthm booth4-corollary-2 + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (1- n)) + (bvecp y (1- (* 2 m)))) + (= (bits (sum-pp4p-theta x y m n) (1- (+ n (* 2 m))) 0) + (* x y))) + :rule-classes ()) + +;;------------------------------------------------------------------------------------------------ + +(defund mag (i y) + (if (member (bits y (1+ (* 2 i)) (1- (* 2 i))) '(3 4)) + 2 + (if (member (bits y (* 2 i) (1- (* 2 i))) '(1 2)) + 1 + 0))) + +(defund nbit (i y) + (bitn y (1+ (* 2 i)))) + +(defthmd theta-rewrite + (implies (and (natp y) (natp i)) + (equal (theta i y) + (if (= (nbit i y) 1) + (- (mag i y)) + (mag i y))))) + +(defund bmux4p (i x y n) + (if (= (nbit i y) 1) + (bits (lognot (* (mag i y) x)) (1- n) 0) + (* (mag i y) x))) + +(defthmd bvecp-bmux4p + (implies (and (not (zp n)) + (bvecp x (1- n))) + (bvecp (bmux4p i x y n) n))) + +(defthmd bmux4p-rewrite + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (1- n)) + (bvecp y (1- (* 2 m))) + (natp i) + (< i m)) + (equal (bmux4p i x y n) + (+ (* (theta i y) x) + (* (1- (expt 2 n)) (nbit i y)))))) + +(defund pp4p (i x y n) + (if (zerop i) + (cat (if (= (nbit 0 y) 0) 1 0) 1 + (nbit 0 y) 1 + (nbit 0 y) 1 + (bmux4p 0 x y n) n) + (cat 1 1 + (lognot (nbit i y)) 1 + (bmux4p i x y n) n + 0 1 + (nbit (1- i) y) 1 + 0 (* 2 (1- i))))) + +(defthmd pp4p0-rewrite + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (1- n)) + (bvecp y (1- (* 2 m)))) + (equal (pp4p 0 x y n) + (+ (expt 2 (+ n 2)) + (* (theta 0 y) x) + (- (nbit 0 y)))))) + +(defthmd pp4p-rewrite + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (1- n)) + (bvecp y (1- (* 2 m))) + (not (zp i)) + (< i m)) + (equal (pp4p i x y n) + (+ (expt 2 (+ n (* 2 i) 1)) + (expt 2 (+ n (* 2 i))) + (* (expt 2 (* 2 i)) (theta i y) x) + (* (expt 2 (* 2 (1- i))) (nbit (1- i) y)) + (- (* (expt 2 (* 2 i)) (nbit i y))))))) + +(defun sum-pp4p (x y m n) + (if (zp m) + 0 + (+ (pp4p (1- m) x y n) + (sum-pp4p x y (1- m) n)))) + +(defthmd booth4-corollary-3 + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (1- n)) + (bvecp y (1- (* 2 m)))) + (equal (sum-pp4p x y m n) + (+ (* x y) (expt 2 (+ n (* 2 m))))))) + +) +;;;********************************************************************** +;;; Statically Encoded Multiplier Arrays +;;;********************************************************************** + +(defsection-rtl |Statically Encoded Multiplier Arrays| |Multiplication| + +(defun m-mu-chi (i mode) + (cond ((equal mode 'mu) + (if (zp i) 1 + (cons (cons 1 i) 1))) + ((equal mode 'chi) + (if (zp i) 0 + (cons (cons 1 i) 0))))) + +(mutual-recursion + (defun mu (i y) + (declare (xargs :measure (m-mu-chi i 'mu))) + (+ (bits y (1+ (* 2 i)) (* 2 i)) (chi i y))) + + (defun chi (i y) + (declare (xargs :measure (m-mu-chi i 'chi))) + (if (zp i) + 0 + (if (>= (mu (1- i) y) 3) + 1 + 0)))) + +(defun phi (i y) + (if (= (bits (mu i y) 1 0) 3) + -1 + (bits (mu i y) 1 0))) + +(defthm phi-bnd + (member (phi i y) '(-1 0 1 2))) + +(defun sum-odd-powers-of-2 (m) + (if (zp m) + 0 + (+ (expt 2 (1- (* 2 m))) + (sum-odd-powers-of-2 (1- m))))) + +(defthm chi-m + (implies (and (natp m) + (natp y) + (<= y (sum-odd-powers-of-2 m))) + (equal (chi m y) 0)) + :rule-classes()) + +(defthm phi-m-1 + (implies (and (natp m) + (natp y) + (<= y (sum-odd-powers-of-2 m))) + (>= (phi (1- m) y) 0)) + :rule-classes()) + +(defun sum-phi (m y) + (if (zp m) + 0 + (+ (* (expt 2 (* 2 (1- m))) (phi (1- m) y)) + (sum-phi (1- m) y)))) + +(defthm sum-phi-lemma + (implies (and (natp m) + (natp y) + (<= y (sum-odd-powers-of-2 m))) + (equal y (sum-phi m y))) + :rule-classes ()) + +(defun pp4-phi (i x y n) + (if (zerop i) + (cat 1 1 + (bitn (lognot (neg (phi i y))) 0) 1 + (bmux4 (phi i y) x n) n) + (cat 1 1 + (bitn (lognot (neg (phi i y))) 0) 1 + (bmux4 (phi i y) x n) n + 0 1 + (neg (phi (1- i) y)) 1 + 0 (* 2 (1- i))))) + +(defun sum-pp4-phi (x y m n) + (if (zp m) + 0 + (+ (pp4-phi (1- m) x y n) + (sum-pp4-phi x y (1- m) n)))) + +(defthm static-booth + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (1- n)) + (natp y) + (<= y (sum-odd-powers-of-2 m))) + (= (+ (expt 2 n) + (sum-pp4-phi x y m n)) + (+ (expt 2 (+ n (* 2 m))) + (* x y)))) + :rule-classes ()) + +) +;;;********************************************************************** +;;; Encoding Redundant Representations +;;;********************************************************************** + +(defsection-rtl |Encoding Redundant Representations| |Multiplication| + +(defun gamma (i a b c) + (if (zp i) + (bitn c 0) + (logior (bitn a (+ -1 (* 2 i))) + (bitn b (+ -1 (* 2 i)))))) + +(defun delta (i a b c d) + (if (zp i) + (bitn d 0) + (logand (logior (logand (bitn a (+ -2 (* 2 i))) + (bitn b (+ -2 (* 2 i)))) + (logior (logand (bitn a (+ -2 (* 2 i))) + (gamma (1- i) a b c)) + (logand (bitn b (+ -2 (* 2 i))) + (gamma (1- i) a b c)))) + (lognot (logxor (bitn a (1- (* 2 i))) + (bitn b (1- (* 2 i)))))))) + +(defun psi (i a b c d) + (if (not (natp i)) + 0 + (+ (bits a (1+ (* 2 i)) (* 2 i)) + (bits b (1+ (* 2 i)) (* 2 i)) + (gamma i a b c) + (delta i a b c d) + (* -4 (+ (gamma (1+ i) a b c) + (delta (1+ i) a b c d)))))) + +(defthm psi-m-1 + (implies (and (natp m) + (>= m 1) + (bvecp a (- (* 2 m) 2)) + (bvecp b (- (* 2 m) 2)) + (bvecp c 1) + (bvecp d 1)) + (and (equal (gamma m a b c) 0) + (equal (delta m a b c d) 0) + (>= (psi (1- m) a b c d) 0))) + :rule-classes ()) + +(defun sum-psi (m a b c d) + (if (zp m) + 0 + (+ (* (expt 2 (* 2 (1- m))) (psi (1- m) a b c d)) + (sum-psi (1- m) a b c d)))) + +(defthm sum-psi-lemma + (implies (and (natp m) + (<= 1 M) ;; add + (bvecp a (- (* 2 m) 2)) + (bvecp b (- (* 2 m) 2)) + (bvecp c 1) + (bvecp d 1)) + (equal (+ a b c d) (sum-psi m a b c d))) + :rule-classes ()) + +(defthmd psi-bnd + (and (integerp (psi i a b c d)) + (<= (psi i a b c d) 2) + (>= (psi i a b c d) -2))) + +(defun pp4-psi (i x a b c d n) + (if (zerop i) + (cat 1 1 + (bitn (lognot (neg (psi i a b c d))) 0) 1 + (bmux4 (psi i a b c d) x n) n) + (cat 1 1 + (bitn (lognot (neg (psi i a b c d))) 0) 1 + (bmux4 (psi i a b c d) x n) n + 0 1 + (neg (psi (1- i) a b c d)) 1 + 0 (* 2 (1- i))))) + +(defun sum-pp4-psi (x a b c d m n) + (if (zp m) + 0 + (+ (pp4-psi (1- m) x a b c d n) + (sum-pp4-psi x a b c d (1- m) n)))) + +(defthm redundant-booth + (implies (and (natp m) + (<= 1 m) + (not (zp n)) + (bvecp x (1- n)) + (bvecp a (- (* 2 m) 2)) + (bvecp b (- (* 2 m) 2)) + (bvecp c 1) + (bvecp d 1) + (= y (+ a b c d))) + (= (+ (expt 2 n) + (sum-pp4-psi x a b c d m n)) + (+ (expt 2 (+ n (* 2 m))) + (* x y)))) + :rule-classes ()) +) + +;;;********************************************************************** +;;; Radix-8 Booth Encoding +;;;********************************************************************** + +(defsection-rtl |Radix-8 Booth Encoding| |Multiplication| + +(defun eta (i y) + (+ (bitn y (1- (* 3 i))) + (bitn y (* 3 i)) + (* 2 (bitn y (1+ (* 3 i)))) + (* -4 (bitn y (+ 2 (* 3 i)))))) + +(defun sum-eta (m y) + (if (zp m) + 0 + (+ (* (expt 2 (* 3 (1- m))) (eta (1- m) y)) + (sum-eta (1- m) y)))) + +(defthm sum-eta-lemma + (implies (and (not (zp m)) + (bvecp y (1- (* 3 m)))) + (equal y (sum-eta m y))) + :rule-classes ()) + +(defun bmux8 (zeta x n) + (case zeta + (1 x) + (-1 (bits (lognot x) (1- n) 0)) + (2 (* 2 x)) + (-2 (bits (lognot (* 2 x)) (1- n) 0)) + (3 (* 3 x)) + (-3 (bits (lognot (* 3 x)) (1- n) 0)) + (4 (* 4 x)) + (-4 (bits (lognot (* 4 x)) (1- n) 0)) + (0 0))) + +(encapsulate ((xi (i) t)) + (local (defun xi (i) (declare (ignore i)) 0)) + (defthm xi-bnd + (and (integerp (xi i)) + (<= (xi i) 4) + (>= (xi i) -4)))) + +(defun pp8 (i x n) + (if (zerop i) + (cat 3 2 + (bitn (lognot (neg (xi i))) 0) 1 + (bmux8 (xi i) x n) n) + (cat 3 2 + (bitn (lognot (neg (xi i))) 0) 1 + (bmux8 (xi i) x n) n + 0 2 + (neg (xi (1- i))) 1 + 0 (* 3 (1- i))))) + +(defun sum-xi (m) + (if (zp m) + 0 + (+ (* (expt 2 (* 3 (1- m))) (xi (1- m))) + (sum-xi (1- m))))) + +(defun sum-pp8 (x m n) + (if (zp m) + 0 + (+ (pp8 (1- m) x n) + (sum-pp8 x (1- m) n)))) + + +(defthm booth8-thm + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (- n 2))) + (= (+ (expt 2 n) + (sum-pp8 x m n)) + (+ (expt 2 (+ n (* 3 m))) + (* x (sum-xi m)) + (- (* (expt 2 (* 3 (1- m))) (neg (xi (1- m)))))))) + :rule-classes ()) + +(defun pp8-eta (i x y n) + (if (zerop i) + (cat 3 2 + (bitn (lognot (neg (eta i y))) 0) 1 + (bmux8 (eta i y) x n) n) + (cat 3 2 + (bitn (lognot (neg (eta i y))) 0) 1 + (bmux8 (eta i y) x n) n + 0 2 + (neg (eta (1- i) y)) 1 + 0 (* 3 (1- i))))) + +(defun sum-pp8-eta (x y m n) + (if (zp m) + 0 + (+ (pp8-eta (1- m) x y n) + (sum-pp8-eta x y (1- m) n)))) + +(defthm booth8-corollary + (implies (and (not (zp n)) + (not (zp m)) + (bvecp x (- n 2)) + (bvecp y (1- (* 3 m)))) + (= (+ (expt 2 n) + (sum-pp8-eta x y m n)) + (+ (expt 2 (+ n (* 3 m))) + (* x y)))) + :rule-classes ()) + +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/rac.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/rac.lisp new file mode 100644 index 000000000..07565ad83 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/rac.lisp @@ -0,0 +1,275 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; Copyright (C) 1995-2013 Advanced Mirco Devices, Inc. +; +; Contact: +; David Russinoff +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; +; Author: David M. Russinoff (david@russinoff.com) + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; Bit Manipulation +;;;********************************************************************** + +;Allows things like (in-theory (disable cat)) to refer to binary-cat. +(add-macro-alias cat binary-cat) + +(defun setbits (x w i j y) + (declare (xargs :guard (and (natp x) + (integerp y) + (integerp i) + (integerp j) + (<= 0 j) + (<= j i) + (integerp w) + (< i w)))) + (mbe :logic (cat (bits x (1- w) (1+ i)) + (+ -1 w (- i)) + (cat (bits y (+ i (- j)) 0) + (+ 1 i (- j)) + (bits x (1- j) 0) + j) + (1+ i)) + :exec (cond ((int= j 0) + (cond ((int= (1+ i) w) + (bits y (+ i (- j)) 0)) + (t + (cat (bits x (1- w) (1+ i)) + (+ -1 w (- i)) + (bits y (+ i (- j)) 0) + (1+ i))))) + ((int= (1+ i) w) + (cat (bits y (+ i (- j)) 0) + (+ 1 i (- j)) + (bits x (1- j) 0) + j)) + (t + (cat (bits x (1- w) (1+ i)) + (+ -1 w (- i)) + (cat (bits y (+ i (- j)) 0) + (+ 1 i (- j)) + (bits x (1- j) 0) + j) + (1+ i)))))) + +(defun setbitn (x w n y) + (declare (xargs :guard (and (natp x) + (integerp y) + (integerp n) + (<= 0 n) + (integerp w) + (< n w)))) + (setbits x w n n y)) + +;; These help in dealing with calls to ash and rem generated by the translator: + +(defthm ash-rewrite + (equal (ash i c) + (fl (* (ifix i) (expt 2 c)))) + :hints (("Goal" :in-theory (enable floor fl ash)))) + +(defthm rem-mod + (implies (and (natp m) (posp n)) + (equal (rem m n) (mod m n)))) + +;;;********************************************************************** +;;; Boolean Functions +;;;********************************************************************** + +(defun log= (x y) + (declare (xargs :guard t)) + (if (equal x y) 1 0)) + +(defun log<> (x y) + (declare (xargs :guard t)) + (if (equal x y) 0 1)) + +(defun log< (x y) + (declare (xargs :guard (and (rationalp x) (rationalp y)))) + (if (< x y) 1 0)) + +(defun log<= (x y) + (declare (xargs :guard (and (rationalp x) (rationalp y)))) + (if (<= x y) 1 0)) + +(defun log> (x y) + (declare (xargs :guard (and (rationalp x) (rationalp y)))) + (if (> x y) 1 0)) + +(defun log>= (x y) + (declare (xargs :guard (and (rationalp x) (rationalp y)))) + (if (>= x y) 1 0)) + +(defun logior1 (x y) + (if (and (equal x 0) (equal y 0)) 0 1)) + +(defun logand1 (x y) + (if (or (equal x 0) (equal y 0)) 0 1)) + +(defun lognot1 (x) + (if (equal x 0) 1 0)) + +(defun true$ () 1) + +(defun false$ () 0) + +(defmacro if1 (x y z) `(if (eql ,x 0) ,z ,y)) + +;;;********************************************************************** +;;; Miscellaneous Macros +;;;********************************************************************** + +(defmacro in-function (fn term) + `(if1 ,term () (er hard ',fn "Assertion ~x0 failed" ',term))) + +;;;********************************************************************** +;;; Arrays +;;;********************************************************************** + +(include-book "misc/total-order" :dir :system) + +(defmacro default-get-valu () 0) + +(defun arcdp (x) + (declare (xargs :guard t)) + (or (null x) + (and (consp x) + (consp (car x)) + (arcdp (cdr x)) + (not (equal (cdar x) + (default-get-valu))) + (or (null (cdr x)) + (acl2::<< (caar x) (caadr x)))))) + +(defthm arcdp-implies-alistp + (implies (arcdp x) (alistp x))) + +(defmacro aifrp-tag () + ''unlikely-to-ever-occur-in-an-executable-counterpart) + +(defun aifrp (x) ;; ill-formed rcdp + (declare (xargs :guard t)) + (or (not (arcdp x)) + (and (consp x) + (null (cdr x)) + (consp (car x)) + (equal (cdar x) (aifrp-tag)) + (aifrp (caar x))))) + +(defun acl2->arcd (x) ;; function mapping acl2 objects to well-formed records. + (declare (xargs :guard t)) + (if (aifrp x) (list (cons x (aifrp-tag))) x)) + +(defun arcd->acl2 (r) ;; inverse of acl2->rcd. + (declare (xargs :guard (arcdp r))) + (if (aifrp r) (caar r) r)) + +(defun ag-aux (a r) ;; record g(et) when r is a well-formed record. + (declare (xargs :guard (arcdp r))) + (cond ((or (endp r) + (acl2::<< a (caar r))) + (default-get-valu)) + ((equal a (caar r)) + (cdar r)) + (t + (ag-aux a (cdr r))))) + +(defun ag (a x) ;; the generic record g(et) which works on any ACL2 object. + (declare (xargs :guard t)) + (ag-aux a (acl2->arcd x))) + +(defun acons-if (a v r) + (declare (xargs :guard (arcdp r))) + (if (equal v (default-get-valu)) r (acons a v r))) + +(defun as-aux (a v r) ;; record s(et) when x is a well-formed record. + (declare (xargs :guard (arcdp r))) + (cond ((or (endp r) + (acl2::<< a (caar r))) + (acons-if a v r)) + ((equal a (caar r)) + (acons-if a v (cdr r))) + (t + (cons (car r) (as-aux a v (cdr r)))))) + +(defun as (a v x) ;; the generic record s(et) which works on any ACL2 object. + (declare (xargs :guard t)) + (arcd->acl2 (as-aux a v (acl2->arcd x)))) + +(defun ainit (l) + (declare (xargs :guard t)) + (if (consp l) + (if (consp (car l)) + (as (caar l) (cdar l) (ainit (cdr l))) + (ainit (cdr l))) + nil)) + +;;Basic properties of arrays: + +(defthm ag-same-as + (equal (ag a (as a v r)) + v)) + +(defthm ag-diff-as + (implies (not (equal a b)) + (equal (ag a (as b v r)) + (ag a r)))) + +;;;; NOTE: The following can be used instead of the above rules to force ACL2 +;;;; to do a case-split. We disable this rule by default since it can lead to +;;;; an expensive case explosion, but in many cases, this rule may be more +;;;; effective than two rules above and should be enabled. + +(defthm ag-of-as-redux + (equal (ag a (as b v r)) + (if (equal a b) v (ag a r)))) + +(in-theory (disable ag-of-as-redux)) + +(defthm as-same-ag + (equal (as a (ag a r) r) + r)) + +(defthm as-same-as + (equal (as a y (as a x r)) + (as a y r))) + +(defthm as-diff-as + (implies (not (equal a b)) + (equal (as b y (as a x r)) + (as a x (as b y r)))) + :rule-classes ((:rewrite :loop-stopper ((b a as))))) + +;; the following theorems are less relevant but have been useful in dealing +;; with a default record of NIL. + +(defthm ag-of-nil-is-default + (equal (ag a nil) (default-get-valu))) + +(defthm as-non-default-cannot-be-nil + (implies (not (equal v (default-get-valu))) + (as a v r))) + +(defthm non-nil-if-ag-not-default + (implies (not (equal (ag a r) + (default-get-valu))) + r) + :rule-classes :forward-chaining) + +;;We disable as and ag, assuming the rules proved in this book are +;;sufficient to manipulate any record terms that are encountered. + +(in-theory (disable as ag)) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/rcp.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/rcp.lisp new file mode 100644 index 000000000..e64c18874 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/rcp.lisp @@ -0,0 +1,61 @@ +(in-package "RTL") + +(INCLUDE-BOOK "rac") + +(defun rcp0 () '(134217725 133177280 132152840 131144040 130150521 + 129171946 128207980 127258288 126322566 125400505 124491806 + 123596178 122713348 121843044 120984994 120138944 119304646 + 118481854 117670336 116869856 116080194 115301132 114532460 + 113773968 113025454 112286728 111557592 110837866 110127368 + 109425916 108733350 108049488 107374182 106707262 106048574 + 105397968 104755298 104120420 103493188 102873470 102261126 + 101656030 101058054 100467072 99882960 99305602 98734878 98170678 + 97612894 97061406 96516116 95976924 95443718 94916402 94394884 + 93879066 93368852 92864160 92364888 91870956 91382282 90898780 + 90420364 89946956 89478486 89014868 88556026 88101890 87652394 + 87207458 86767016 86331002 85899346 85471986 85048856 84629897 + 84215046 83804240 83397422 82994534 82595524 82200330 81808902 + 81421180 81037118 80656663 80279762 79906366 79536432 79169904 + 78806738 78446892 78090313 77736964 77386800 77039774 76695844 + 76354973 76017120 75682240 75350304 75021262 74695082 74371728 + 74051160 73733342 73418242 73105826 72796056 72488900 72184324 + 71882297 71582788 71285764 70991194 70699052 70409300 70121914 + 69836868 69554126 69273666 68995460 68719478 68445694 68174084 + 67904624 67637280 67372036)) + +(defun rcp1 () '(131067 129044 127066 125134 123244 121398 119594 117828 + 116102 114414 112762 111144 109562 108014 106498 105014 103560 + 102136 100742 99376 98038 96726 95442 94182 92946 91736 90548 89384 + 88242 87120 86022 84942 83884 82846 81826 80824 79842 78878 77930 + 77000 76086 75188 74306 73440 72588 71752 70928 70120 69326 68544 + 67776 67022 66280 65548 64830 64124 63428 62746 62072 61410 60758 + 60118 59486 58864 58254 57652 57058 56474 55900 55334 54776 54228 + 53686 53154 52628 52111 51602 51100 50604 50116 49636 49162 48696 + 48234 47780 47333 46892 46456 46028 45604 45186 44776 44368 43968 + 43574 43184 42798 42419 42044 41674 41310 40950 40594 40244 39898 + 39556 39218 38886 38557 38232 37912 37595 37282 36974 36668 36368 + 36070 35776 35486 35200 34916 34636 34360 34086 33816 33550 33286 + 33026)) + +(defun rcp2 () '(4047 3956 3864 3780 3690 3608 3532 3452 3378 3307 3236 + 3164 3096 3032 2968 2908 2844 2784 2728 2676 2624 2568 2524 2472 + 2420 2376 2328 2288 2244 2196 2160 2116 2076 2040 2004 1960 1928 + 1896 1860 1828 1796 1764 1732 1704 1672 1648 1612 1588 1560 1532 + 1508 1484 1464 1432 1412 1392 1364 1348 1324 1304 1280 1264 1240 + 1220 1208 1188 1164 1148 1132 1116 1096 1084 1064 1052 1032 1018 + 1004 992 972 960 948 932 924 904 892 882 872 856 848 832 820 816 798 + 788 784 772 756 750 736 728 720 712 700 692 684 676 664 660 650 640 + 636 626 616 612 600 596 588 580 572 572 560 552 548 540 532 528 524 + 520)) + +(defun rcp24 (b) + (let* ((i (fl (* (expt 2 7) (1- b)))) + (x (- b (1+ (* (expt 2 -7) i)))) + (c0 (* (expt 2 -27) (nth i (rcp0)))) + (c1 (- (* (expt 2 -17) (nth i (rcp1))))) + (c2 (* (expt 2 -12) (nth i (rcp2))))) + (rne (+ c0 (* c1 x) (* c2 x x)) 24))) + + + + diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/reps.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/reps.lisp new file mode 100644 index 000000000..e87a466df --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/reps.lisp @@ -0,0 +1,506 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;*************************************************************** +;;; Classification of Formats +;;;*************************************************************** + +(defsection-rtl |Classification of Formats| |Floating-Point Formats| + +;;Format parameters: + +(defnd formatp (f) + (and (consp f) + (consp (cdr f)) + (consp (cddr f)) + (natp (cadr f)) + (> (cadr f) 1) + (natp (caddr f)) + (> (caddr f) 1))) + +(defund explicitp (f) (declare (xargs :guard (formatp f))) (car f)) + +(defund prec (f) (declare (xargs :guard (formatp f))) (cadr f)) + +(defund expw (f) (declare (xargs :guard (formatp f))) (caddr f)) + +(defund sigw (f) + (declare (xargs :guard (formatp f))) + (if (explicitp f) + (prec f) + (1- (prec f)))) + +(defnd encodingp (x f) + (and (formatp f) (bvecp x (+ 1 (expw f) (sigw f))))) + +;;Examples: + +(defnd hp () '(nil 11 5)) + +(defnd sp () '(nil 24 8)) + +(defnd dp () '(nil 53 11)) + +(defnd bf () '(nil 8 8)) + +(defnd ep () '(t 64 15)) + +(in-theory (disable (sp) (dp) (hp) (bf) (ep))) + +(defthm formatp-sp + (formatp (sp))) + +(defthm formatp-dp + (formatp (dp))) + +(defthm formatp-hp + (formatp (hp))) + +(defthm formatp-ep + (formatp (ep))) + +;;Field extractors: + +(defund sgnf (x f) + (declare (xargs :guard (encodingp x f))) + (bitn x (+ (expw f) (sigw f)))) + +(defund expf (x f) + (declare (xargs :guard (encodingp x f))) + (bits x (1- (+ (expw f) (sigw f))) (sigw f))) + +(defund sigf (x f) + (declare (xargs :guard (encodingp x f))) + (bits x (1- (sigw f)) 0)) + +(defund manf (x f) + (declare (xargs :guard (encodingp x f))) + (bits x (- (prec f) 2) 0)) + +;;Exponent bias: + +(defund bias (f) (declare (xargs :guard (formatp f))) (- (expt 2 (- (expw f) 1)) 1)) + +) +;;;*************************************************************** +;;; Normal Encodings +;;;*************************************************************** + +(defsection-rtl |Normal Encodings| |Floating-Point Formats| + +(defund normp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (< 0 (expf x f)) + (< (expf x f) (1- (expt 2 (expw f)))) + (implies (explicitp f) (= (bitn x (1- (prec f))) 1)))) + +(defund unsupp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (explicitp f) + (< 0 (expf x f)) + (= (bitn x (1- (prec f))) 0))) + +;;Decoding function: + +(defund ndecode (x f) + (declare (xargs :guard (encodingp x f))) + (* (if (= (sgnf x f) 0) 1 -1) + (expt 2 (- (expf x f) (bias f))) + (1+ (* (manf x f) (expt 2 (- 1 (prec f))))))) + +(defthmd sgn-ndecode + (implies (normp x f) + (equal (sgn (ndecode x f)) + (if (= (sgnf x f) 0) 1 -1)))) + +(defthmd expo-ndecode + (implies (normp x f) + (equal (expo (ndecode x f)) + (- (expf x f) (bias f))))) + +(defthmd sig-ndecode + (implies (normp x f) + (equal (sig (ndecode x f)) + (+ 1 (/ (manf x f) (expt 2 (1- (prec f)))))))) + + +;;Representable normals: + +(defnd nrepp (x f) + (and (rationalp x) + (formatp f) + (not (= x 0)) + (< 0 (+ (expo x) (bias f))) + (< (+ (expo x) (bias f)) (1- (expt 2 (expw f)))) + (exactp x (prec f)))) + +;;Encoding function: + +(defund nencode (x f) + (declare (xargs :guard (and (rationalp x) + (formatp f) + (exactp x (prec f))))) + (cat (if (= (sgn x) 1) 0 1) + 1 + (+ (expo x) (bias f)) + (expw f) + (* (sig x) (expt 2 (1- (prec f)))) + (sigw f))) + +;;Inversions: + +(defthm nrepp-ndecode + (implies (normp x f) + (nrepp (ndecode x f) f))) + +(defthm nencode-ndecode + (implies (normp x f) + (equal (nencode (ndecode x f) f) + x))) + +(defthm normp-nencode + (implies (nrepp x f) + (normp (nencode x f) f))) + +(defthm ndecode-nencode + (implies (nrepp x f) + (equal (ndecode (nencode x f) f) + x))) + +;; Smallest positive normal: + +(defund spn (f) + (declare (xargs :guard (formatp f))) + (expt 2 (- 1 (bias f)))) + +(defthmd positive-spn + (> (spn f) 0) + :rule-classes ( :linear)) + +(defthmd expo-spn + (implies (formatp f) + (equal (expo (spn f)) + (- 1 (bias f))))) + +(defthmd nrepp-spn + (implies (formatp f) + (nrepp (spn f) f))) + +(defthmd smallest-spn + (implies (nrepp x f) + (>= (abs x) (spn f))) + :rule-classes + ((:rewrite :match-free :once))) + +;; Largest positive normal: + +(defund lpn (f) + (declare (xargs :guard (formatp f))) + (* (expt 2 (- (expt 2 (expw f)) (+ 2 (bias f)))) + (- 2 (expt 2 (- 1 (prec f)))))) + +(defthmd positive-lpn + (implies (formatp f) + (> (lpn f) 0)) + :rule-classes ( :linear)) + +(defthmd expo-lpn + (implies (formatp f) + (equal (expo (lpn f)) + (- (expt 2 (expw f)) (+ 2 (bias f)))))) + +(defthmd sig-lpn + (implies (formatp f) + (equal (sig (lpn f)) + (- 2 (expt 2 (- 1 (prec f))))))) + +(defthmd nrepp-lpn + (implies (formatp f) + (nrepp (lpn f) f))) + +(defthmd largest-lpn + (implies (nrepp x f) + (<= x (lpn f))) + :rule-classes + ((:rewrite :match-free :once))) +) + +;;;*************************************************************** +;;; Denormals and Zeroes +;;;*************************************************************** + +(defsection-rtl |Denormals and Zeroes| |Floating-Point Formats| + +(defund zerp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) 0) + (= (sigf x f) 0))) + +(defund zencode (sgn f) + (declare (xargs :guard (and (bvecp sgn 1) + (formatp f)))) + (cat sgn 1 0 (+ (sigw f) (expw f)))) + +(defund denormp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) 0) + (not (= (sigf x f) 0)) + (implies (explicitp f) (= (bitn x (1- (prec f))) 0)))) + +(defund pseudop (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (explicitp f) + (= (expf x f) 0) + (= (bitn x (1- (prec f))) 1))) + +(defund ddecode (x f) + (declare (xargs :guard (encodingp x f))) + (* (if (= (sgnf x f) 0) 1 -1) + (sigf x f) + (expt 2 (+ 2 (- (bias f)) (- (prec f)))))) + +(defund decode (x f) + (declare (xargs :guard (encodingp x f))) + (if (= (expf x f) 0) + (ddecode x f) + (ndecode x f))) + +(defthm sgn-ddecode + (implies (or (denormp x f) (pseudop x f)) + (equal (sgn (ddecode x f)) + (if (= (sgnf x f) 0) 1 -1)))) + +(defthm expo-ddecode + (implies (or (denormp x f) (pseudop x f)) + (equal (expo (ddecode x f)) + (+ 2 (- (prec f)) (- (bias f)) (expo (sigf x f)))))) + +(defthm sig-ddecode + (implies (or (denormp x f) (pseudop x f)) + (equal (sig (ddecode x f)) + (sig (sigf x f))))) + +(defnd drepp (x f) + (and (rationalp x) + (formatp f) + (not (= x 0)) + (<= (- 2 (prec f)) (+ (expo x) (bias f))) + (<= (+ (expo x) (bias f)) 0) + (exactp x (+ (1- (prec f)) (bias f) (expo x))))) + +(defthmd drepp-exactp + (implies (drepp x f) + (exactp x (prec f)))) + +(defund dencode (x f) + (declare (xargs :guard (drepp x f))) + (cat (if (= (sgn x) 1) 0 1) + 1 + 0 + (expw f) + (* (sig x) (expt 2 (+ -2 (prec f) (expo x) (bias f)))) + (sigw f))) + +(defthm drepp-ddecode + (implies (denormp x f) + (drepp (ddecode x f) f))) + +(defthm dencode-ddecode + (implies (denormp x f) + (equal (dencode (ddecode x f) f) + x))) + +(defthm denormp-dencode + (implies (drepp x f) + (denormp (dencode x f) f))) + +(defthm ddecode-dencode + (implies (drepp x f) + (equal (ddecode (dencode x f) f) + x))) + +(defthmd drepp (spd f) 0)) + :rule-classes :linear) + +(defthmd drepp-spd + (implies (formatp f) + (drepp (spd f) f))) + +(defthmd smallest-spd + (implies (drepp r f) + (>= (abs r) (spd f)))) + +(defthmd spd-mult + (implies (and (formatp f) + (> r 0) + (= m (/ r (spd f)))) + (iff (drepp r f) + (and (natp m) + (<= 1 m) + (< m (expt 2 (1- (prec f)))))))) + +) +;;;*************************************************************** +;;; Infinities and NaNs +;;;*************************************************************** + +(defsection-rtl |Infinities and NaNs| |Floating-Point Formats| + +(defund infp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) (1- (expt 2 (expw f)))) + (not (unsupp x f)) + (= (manf x f) 0))) + +(defun iencode (sgn f) + (declare (xargs :guard (and (bvecp sgn 1) + (formatp f)))) + (if (explicitp f) + (cat sgn 1 (1- (expt 2 (expw f))) (expw f) 1 1 0 (1- (sigw f))) + (cat sgn 1 (1- (expt 2 (expw f))) (expw f) 0 (sigw f)))) + +(defund nanp (x f) + (declare (xargs :guard (encodingp x f))) + (and (mbt (encodingp x f)) + (= (expf x f) (1- (expt 2 (expw f)))) + (not (unsupp x f)) + (not (= (manf x f) 0)))) + +(defund qnanp (x f) + (declare (xargs :guard (encodingp x f))) + (and (nanp x f) (= (bitn x (- (prec f) 2)) 1))) + +(defund snanp (x f) + (declare (xargs :guard (encodingp x f))) + (and (nanp x f) (= (bitn x (- (prec f) 2)) 0))) + +(defund qnanize (x f) + (declare (xargs :guard (encodingp x f))) + (logior x (expt 2 (- (prec f) 2)))) + +(defund indef (f) + (declare (xargs :guard (formatp f))) + (if (explicitp f) + (cat (1- (expt 2 (+ (expw f) 2))) + (+ (expw f) 2) + 0 + (- (sigw f) 2)) + (cat (1- (expt 2 (+ (expw f) 1))) + (+ (expw f) 1) + 0 + (1- (sigw f))))) + +) +;;;*************************************************************** +;;; Rebiasing Exponents +;;;*************************************************************** + +(defsection-rtl |Rebiasing Exponents| |Floating-Point Formats| + +(defund rebias (expo old new) + (declare (xargs :guard (and (integerp expo) + (posp old) + (posp new)))) + (+ expo (- (expt 2 (1- new)) (expt 2 (1- old))))) + +(defthm natp-rebias-up + (implies (and (natp n) + (natp m) + (< 0 m) + (<= m n) + (bvecp x m)) + (natp (rebias x m n)))) + +(defthm natp-rebias-down + (implies (and (natp n) + (natp m) + (< 0 m) + (<= m n) + (bvecp x n) + (< x (+ (expt 2 (1- n)) (expt 2 (1- m)))) + (>= x (- (expt 2 (1- n)) (expt 2 (1- m))))) + (natp (rebias x n m)))) + +(defthm bvecp-rebias-up + (implies (and (natp n) + (natp m) + (< 0 m) + (<= m n) + (bvecp x m)) + (bvecp (rebias x m n) n))) + +(defthm bvecp-rebias-down + (implies (and (natp n) + (natp m) + (< 0 m) + (<= m n) + (bvecp x n) + (< x (+ (expt 2 (1- n)) (expt 2 (1- m)))) + (>= x (- (expt 2 (1- n)) (expt 2 (1- m))))) + (bvecp (rebias x n m) m))) + +(defthmd rebias-lower + (implies (and (natp n) + (natp m) + (> n m) + (> m 1) + (bvecp x n) + (< x (+ (expt 2 (1- n)) (expt 2 (1- m)))) + (>= x (- (expt 2 (1- n)) (expt 2 (1- m))))) + (equal (rebias x n m) + (cat (bitn x (1- n)) + 1 + (bits x (- m 2) 0) + (1- m))))) + +(defthmd rebias-higher + (implies (and (natp n) + (natp m) + (> n m) + (> m 1) + (bvecp x m)) + (equal (rebias x m n) + (cat (cat (bitn x (1- m)) + 1 + (mulcat 1 (- n m) (bitn (lognot x) (1- m))) + (- n m)) + (1+ (- n m)) + (bits x (- m 2) 0) + (1- m))))) +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/round.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/round.lisp new file mode 100644 index 000000000..b056546ae --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/round.lisp @@ -0,0 +1,2096 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; Truncation +;;;********************************************************************** + +(defsection-rtl |Truncation| |Rounding| + +(defund rtz (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (* (sgn x) + (fl (* (expt 2 (1- n)) (sig x))) + (expt 2 (- (1+ (expo x)) n)))) + +(defthmd rtz-rewrite + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (equal (rtz x n) + (* (sgn x) + (fl (* (expt 2 (- (1- n) (expo x))) (abs x))) + (expt 2 (- (1+ (expo x)) n)))))) + +(defthm rtz-integer-type-prescription + (implies (and (>= (expo x) n) + (case-split (integerp n))) + (integerp (rtz x n))) + :rule-classes :type-prescription) + +(defthm rtz-neg-bits + (implies (and (integerp n) + (<= n 0)) + (equal (rtz x n) 0))) + +(defthmd sgn-rtz + (implies (and (< 0 n) + (rationalp x) + (integerp n)) + (equal (sgn (rtz x n)) + (sgn x)))) + +(defthm rtz-positive + (implies (and (< 0 x) + (case-split (rationalp x)) + (case-split (integerp n)) + (case-split (< 0 n))) + (< 0 (rtz x n))) + :rule-classes (:rewrite :linear)) + +(defthm rtz-negative + (implies (and (< x 0) + (case-split (rationalp x)) + (case-split (integerp n)) + (case-split (< 0 n))) + (< (rtz x n) 0)) + :rule-classes (:rewrite :linear)) + +(defthm rtz-0 + (equal (rtz 0 n) 0)) + +(defthmd abs-rtz + (equal (abs (rtz x n)) + (* (fl (* (expt 2 (1- n)) (sig x))) (expt 2 (- (1+ (expo x)) n))))) + +(defthmd rtz-minus + (equal (rtz (- x) n) (- (rtz x n)))) + +(defthmd rtz-shift + (implies (integerp n) + (equal (rtz (* x (expt 2 k)) n) + (* (rtz x n) (expt 2 k))))) + +(defthmd rtz-upper-bound + (implies (and (rationalp x) + (integerp n)) + (<= (abs (rtz x n)) (abs x))) + :rule-classes :linear) + +(defthmd rtz-upper-pos + (implies (and (<= 0 x) + (rationalp x) + (integerp n)) + (<= (rtz x n) x)) + :rule-classes :linear) + +(defthm expo-rtz + (implies (and (< 0 n) + (rationalp x) + (integerp n)) + (equal (expo (rtz x n)) + (expo x)))) + +(defthmd rtz-lower-bound + (implies (and (rationalp x) + (integerp n)) + (> (abs (rtz x n)) (- (abs x) (expt 2 (- (1+ (expo x)) n))))) + :rule-classes :linear) + +(defthm rtz-diff + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (< (abs (- x (rtz x n))) (expt 2 (- (1+ (expo x)) n)))) + :rule-classes ()) + +(defthm rtz-exactp-a + (exactp (rtz x n) n)) + +(defthmd rtz-exactp-b + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (iff (exactp x n) + (= x (rtz x n))))) + +(defthm rtz-exactp-c + (implies (and (exactp a n) + (<= a x) + (rationalp x) + (integerp n) + (rationalp a)) + (<= a (rtz x n))) + :rule-classes ()) + +(defthmd rtz-squeeze + (implies (and (rationalp x) + (rationalp a) + (>= x a) + (> a 0) + (not (zp n)) + (exactp a n) + (< x (fp+ a n))) + (equal (rtz x n) a))) + +(defthmd rtz-monotone + (implies (and (<= x y) + (rationalp x) + (rationalp y) + (integerp n)) + (<= (rtz x n) (rtz y n))) + :rule-classes :linear) + +(defthmd rtz-midpoint + (implies (and (natp n) + (rationalp x) (> x 0) + (exactp x (1+ n)) + (not (exactp x n))) + (equal (rtz x n) + (- x (expt 2 (- (expo x) n)))))) + +(defthm rtz-rtz + (implies (and (>= n m) + (integerp n) + (integerp m)) + (equal (rtz (rtz x n) m) + (rtz x m)))) + +(defthm plus-rtz + (implies (and (rationalp x) + (>= x 0) + (rationalp y) + (>= y 0) + (integerp k) + (exactp x (+ k (- (expo x) (expo y))))) + (= (+ x (rtz y k)) + (rtz (+ x y) (+ k (- (expo (+ x y)) (expo y)))))) + :rule-classes ()) + +(defthm minus-rtz + (implies (and (rationalp x) + (> x 0) + (rationalp y) + (> y 0) + (< x y) + (integerp k) + (> k 0) + (> (+ k (- (expo (- x y)) (expo y))) 0) + (exactp x (+ k (- (expo x) (expo y))))) + (= (- x (rtz y k)) + (- (rtz (- y x) (+ k (- (expo (- x y)) (expo y))))))) + :rule-classes ()) + +(defthmd bits-rtz + (implies (and (= n (1+ (expo x))) + (>= x 0) + (integerp k) + (> k 0)) + (equal (rtz x k) + (* (expt 2 (- n k)) + (bits x (1- n) (- n k)))))) + +(defthmd bits-rtz-bits + (implies (and (rationalp x) + (>= x 0) + (integerp k) + (integerp i) + (integerp j) + (> k 0) + (>= (expo x) i) + (>= j (- (1+ (expo x)) k))) + (equal (bits (rtz x k) i j) + (bits x i j)))) + +(defthmd rtz-split + (implies (and (= n (1+ (expo x))) + (>= x 0) + (integerp m) + (> m k) + (integerp k) + (> k 0)) + (equal (rtz x m) + (+ (rtz x k) + (* (expt 2 (- n m)) + (bits x (1- (- n k)) (- n m))))))) + +(defthmd rtz-logand + (implies (and (>= x (expt 2 (1- n))) + (< x (expt 2 n)) + (integerp x) + (integerp m) (>= m n) + (integerp n) (> n k) + (integerp k) (> k 0)) + (equal (rtz x k) + (logand x (- (expt 2 m) (expt 2 (- n k))))))) +) + +;;;********************************************************************** +;;; Rounding Away from Zero +;;;********************************************************************** + +(defsection-rtl |Rounding Away from Zero| |Rounding| + +(defund raz (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (* (sgn x) + (cg (* (expt 2 (1- n)) (sig x))) + (expt 2 (- (1+ (expo x)) n)))) + +(defthmd raz-rewrite + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (equal (raz x n) + (* (sgn x) + (cg (* (expt 2 (- (1- n) (expo x))) (abs x))) + (expt 2 (- (1+ (expo x)) n)))))) + +(defthmd abs-raz + (implies (and (rationalp x) + (integerp n)) + (equal (abs (raz x n)) + (* (cg (* (expt 2 (1- n)) (sig x))) (expt 2 (- (1+ (expo x)) n)))))) + +(defthm raz-integer-type-prescription + (implies (and (>= (expo x) n) + (case-split (integerp n))) + (integerp (raz x n))) + :rule-classes :type-prescription) + +(defthmd sgn-raz + (equal (sgn (raz x n)) + (sgn x))) + +(defthm raz-positive + (implies (and (< 0 x) + (case-split (rationalp x))) + (< 0 (raz x n))) + :rule-classes (:rewrite :linear)) + +(defthm raz-negative + (implies (and (< x 0) + (case-split (rationalp x))) + (< (raz x n) 0)) + :rule-classes (:rewrite :linear)) + +(defthm raz-0 + (equal (raz 0 n) 0)) + +(defthmd raz-minus + (equal (raz (- x) n) (- (raz x n)))) + +(defthm raz-shift + (implies (integerp n) + (= (raz (* x (expt 2 k)) n) + (* (raz x n) (expt 2 k)))) + :rule-classes ()) + +(defthm raz-neg-bits + (implies (and (<= n 0) + (rationalp x) + (integerp n)) + (equal (raz x n) + (* (sgn x) (expt 2 (+ 1 (expo x) (- n))))))) + +(defthmd raz-lower-bound + (implies (and (case-split (rationalp x)) + (case-split (integerp n))) + (>= (abs (raz x n)) (abs x))) + :rule-classes :linear) + +(defthmd raz-lower-pos + (implies (and (>= x 0) + (case-split (rationalp x)) + (case-split (integerp n))) + (>= (raz x n) x)) + :rule-classes :linear) + +(defthmd raz-upper-bound + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (< (abs (raz x n)) (+ (abs x) (expt 2 (- (1+ (expo x)) n))))) + :rule-classes :linear) + +(defthmd raz-diff + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (< (abs (- (raz x n) x)) (expt 2 (- (1+ (expo x)) n)))) + :rule-classes :linear) + +(defthm raz-expo-upper + (implies (and (rationalp x) + (not (= x 0)) + (natp n)) + (<= (abs (raz x n)) (expt 2 (1+ (expo x))))) + :rule-classes ()) + +(defthmd expo-raz-upper-bound + (implies (and (rationalp x) + (natp n)) + (<= (expo (raz x n)) (1+ (expo x)))) + :rule-classes :linear) + +(defthmd expo-raz-lower-bound + (implies (and (rationalp x) + (natp n)) + (>= (expo (raz x n)) (expo x))) + :rule-classes :linear) + +(defthmd expo-raz + (implies (and (rationalp x) + (natp n) + (not (= (abs (raz x n)) (expt 2 (1+ (expo x)))))) + (equal (expo (raz x n)) + (expo x)))) + +(defthm raz-exactp-a + (implies (case-split (< 0 n)) + (exactp (raz x n) n))) + +(defthmd raz-exactp-b + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (iff (exactp x n) + (= x (raz x n))))) + +(defthm raz-exactp-c + (implies (and (exactp a n) + (>= a x) + (rationalp x) + (integerp n) + (> n 0) + (rationalp a)) + (>= a (raz x n))) + :rule-classes ()) + +(defthmd raz-squeeze + (implies (and (rationalp x) + (rationalp a) + (> x a) + (> a 0) + (not (zp n)) + (exactp a n) + (<= x (fp+ a n))) + (equal (raz x n) (fp+ a n)))) + +(defthmd raz-up + (implies (and (rationalp x) + (integerp k) + (not (zp n)) + (not (zp m)) + (< m n) + (< (abs x) (expt 2 k)) + (= (abs (raz x n)) (expt 2 k))) + (equal (abs (raz x m)) (expt 2 k)))) + +(defthmd raz-monotone + (implies (and (rationalp x) + (rationalp y) + (integerp n) + (<= x y)) + (<= (raz x n) (raz y n))) + :rule-classes :linear) + +(defthmd rtz-raz + (implies (and (rationalp x) (> x 0) + (integerp n) (> n 0) + (not (exactp x n))) + (equal (raz x n) + (+ (rtz x n) + (expt 2 (+ (expo x) 1 (- n))))))) + +(defthmd raz-midpoint + (implies (and (natp n) + (rationalp x) (> x 0) + (exactp x (1+ n)) + (not (exactp x n))) + (equal (raz x n) + (+ x (expt 2 (- (expo x) n)))))) + +(defthmd raz-raz + (implies (and (rationalp x) + (>= x 0) + (integerp n) + (integerp m) + (> m 0) + (>= n m)) + (equal (raz (raz x n) m) + (raz x m)))) + +(defthm plus-raz + (implies (and (exactp x (+ k (- (expo x) (expo y)))) + (rationalp x) + (>= x 0) + (rationalp y) + (>= y 0) + (integerp k)) + (= (+ x (raz y k)) + (raz (+ x y) + (+ k (- (expo (+ x y)) (expo y)))))) + :rule-classes ()) + +(defthm minus-rtz-raz + (implies (and (rationalp x) + (> x 0) + (rationalp y) + (> y 0) + (< y x) + (integerp k) + (> k 0) + (> (+ k (- (expo (- x y)) (expo y))) 0) + (exactp x (+ k (- (expo x) (expo y))))) + (= (- x (rtz y k)) + (raz (- x y) (+ k (- (expo (- x y)) (expo y)))))) + :rule-classes ()) + +(defthm rtz-plus-minus + (implies (and (rationalp x) + (rationalp y) + (not (= x 0)) + (not (= y 0)) + (not (= (+ x y) 0)) + (integerp k) + (> k 0) + (= k1 (+ k (- (expo x) (expo y)))) + (= k2 (+ k (expo (+ x y)) (- (expo y)))) + (exactp x k1) + (> k2 0)) + (= (+ x (rtz y k)) + (if (= (sgn (+ x y)) (sgn y)) + (rtz (+ x y) k2) + (raz (+ x y) k2)))) + :rule-classes ()) + +(defthmd raz-impl + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0) + (integerp m) + (>= m n) + (exactp x m)) + (equal (raz x n) + (rtz (+ x + (expt 2 (- (1+ (expo x)) n)) + (- (expt 2 (- (1+ (expo x)) m)))) + n)))) +) + +;;;********************************************************************** +;;; Unbiased Rounding +;;;********************************************************************** + +(defsection-rtl |Unbiased Rounding| |Rounding| + +(defun re (x) + (declare (xargs :guard (real/rationalp x))) + (- x (fl x))) + +(defund rne (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (let ((z (fl (* (expt 2 (1- n)) (sig x)))) + (f (re (* (expt 2 (1- n)) (sig x))))) + (if (< f 1/2) + (rtz x n) + (if (> f 1/2) + (raz x n) + (if (evenp z) + (rtz x n) + (raz x n)))))) + +(defthm rne-choice + (or (= (rne x n) (rtz x n)) + (= (rne x n) (raz x n))) + :rule-classes ()) + +(defthmd sgn-rne + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (equal (sgn (rne x n)) + (sgn x)))) + +(defthm rne-positive + (implies (and (< 0 x) + (< 0 n) + (rationalp x) + (integerp n)) + (< 0 (rne x n))) + :rule-classes (:type-prescription :linear)) + +(defthmd rne-negative + (implies (and (< x 0) + (< 0 n) + (rationalp x) + (integerp n)) + (< (rne x n) 0)) + :rule-classes (:type-prescription :linear)) + +(defthm rne-0 + (equal (rne 0 n) 0)) + +(defthm rne-exactp-a + (implies (< 0 n) + (exactp (rne x n) n))) + +(defthmd rne-exactp-b + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (iff (exactp x n) + (= x (rne x n))))) + +(defthm rne-exactp-c + (implies (and (exactp a n) + (>= a x) + (rationalp x) + (integerp n) + (> n 0) + (rationalp a)) + (>= a (rne x n))) + :rule-classes ()) + +(defthm rne-exactp-d + (implies (and (rationalp x) + (integerp n) + (> n 0) + (rationalp a) + (exactp a n) + (<= a x)) + (<= a (rne x n))) + :rule-classes ()) + +(defthm expo-rne + (implies (and (rationalp x) + (> n 0) + (integerp n) + (not (= (abs (rne x n)) (expt 2 (1+ (expo x)))))) + (equal (expo (rne x n)) + (expo x)))) + +(defthm rne<=raz + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0)) + (<= (rne x n) (raz x n))) + :rule-classes ()) + +(defthm rne>=rtz + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0)) + (>= (rne x n) (rtz x n))) + :rule-classes ()) + +(defthm rne-shift + (implies (and (rationalp x) + (integerp n) + (integerp k)) + (= (rne (* x (expt 2 k)) n) + (* (rne x n) (expt 2 k)))) + :rule-classes ()) + +(defthmd rne-minus + (equal (rne (- x) n) (- (rne x n)))) + +(defthmd rne-rtz + (implies (and (< (abs (- x (rtz x n))) + (abs (- (raz x n) x))) + (rationalp x) + (integerp n)) + (equal (rne x n) + (rtz x n)))) + +(defthmd rne-raz + (implies (and (> (abs (- x (rtz x n))) + (abs (- (raz x n) x))) + (rationalp x) + (integerp n)) + (equal (rne x n) + (raz x n)))) + +(defthmd rne-down + (implies (and (rationalp x) + (rationalp a) + (>= x a) + (> a 0) + (not (zp n)) + (exactp a n) + (< x (+ a (expt 2 (- (expo a) n))))) + (equal (rne x n) a))) + +(defthmd rne-up + (implies (and (rationalp x) + (rationalp a) + (> a 0) + (not (zp n)) + (exactp a n) + (< x (fp+ a n)) + (> x (+ a (expt 2 (- (expo a) n))))) + (equal (rne x n) (fp+ a n)))) + +(defthmd rne-up-2 + (implies (and (rationalp x) + (integerp k) + (not (zp n)) + (not (zp m)) + (< m n) + (< (abs x) (expt 2 k)) + (= (abs (rne x n)) (expt 2 k))) + (equal (abs (rne x m)) (expt 2 k)))) + +(defthm rne-nearest + (implies (and (exactp y n) + (rationalp x) + (rationalp y) + (integerp n) + (> n 0)) + (>= (abs (- x y)) (abs (- x (rne x n))))) + :rule-classes ()) + +(defthm rne-diff + (implies (and (integerp n) + (> n 0) + (rationalp x)) + (<= (abs (- x (rne x n))) + (expt 2 (- (expo x) n)))) + :rule-classes ()) + +(defthm rne-diff-cor + (implies (and (integerp n) + (> n 0) + (rationalp x)) + (<= (abs (- x (rne x n))) + (* (abs x) (expt 2 (- n))))) + :rule-classes ()) + +(defthm rne-force + (implies (and (integerp n) + (> n 0) + (rationalp x) + (not (= x 0)) + (rationalp y) + (exactp y n) + (< (abs (- x y)) (expt 2 (- (expo x) n)))) + (= y (rne x n))) + :rule-classes ()) + +(defthm rne-monotone + (implies (and (<= x y) + (rationalp x) + (rationalp y) + (integerp n) + (> n 0)) + (<= (rne x n) (rne y n))) + :rule-classes ()) + +(defund rne-witness (x y n) + (if (= (expo x) (expo y)) + (/ (+ (rne x n) (rne y n)) 2) + (expt 2 (expo y)))) + +(defthm rne-rne-lemma + (implies (and (rationalp x) + (rationalp y) + (< 0 x) + (< x y) + (integerp n) + (> n 0) + (not (= (rne x n) (rne y n)))) + (and (<= x (rne-witness x y n)) + (<= (rne-witness x y n) y) + (exactp (rne-witness x y n) (1+ n)))) + :rule-classes ()) + +(defthm rne-rne + (implies (and (rationalp x) + (rationalp y) + (rationalp a) + (integerp n) + (integerp k) + (> k 0) + (>= n k) + (< 0 a) + (< a x) + (< 0 y) + (< y (fp+ a (1+ n))) + (exactp a (1+ n))) + (<= (rne y k) (rne x k))) + :rule-classes ()) + +(defthm rne-boundary + (implies (and (rationalp x) + (rationalp y) + (rationalp a) + (< 0 x) + (< x a) + (< a y) + (integerp n) + (> n 0) + (exactp a (1+ n)) + (not (exactp a n))) + (< (rne x n) (rne y n))) + :rule-classes ()) + +(defthm rne-midpoint + (implies (and (rationalp x) + (integerp n) + (> n 1) + (exactp x (1+ n)) + (not (exactp x n))) + (exactp (rne x n) (1- n))) + :rule-classes ()) + +(defund xfp (k m x0) + (+ x0 (* (expt 2 (- (1+ (expo x0)) m)) k))) + +(defund err-rne (k m n x0) + (- (rne (xfp k m x0) n) (xfp k m x0))) + +(defund sum-err-rne (i j m n x0) + (declare (xargs :measure (nfix (1+ (- j i))))) + (if (and (natp i) (natp j) (<= i j)) + (+ (sum-err-rne i (1- j) m n x0) + (err-rne j m n x0)) + 0)) + +(defthmd rne-unbiased + (implies (and (natp m) + (natp n) + (< 1 n) + (< n m) + (rationalp x0) + (> x0 0) + (exactp x0 (1- n))) + (equal (sum-err-rne 0 (1- (expt 2 (- (1+ m) n))) m n x0) + 0))) + +(defund rna (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (< (re (* (expt 2 (1- n)) (sig x))) + 1/2) + (rtz x n) + (raz x n))) + +(defthm rna-choice + (or (= (rna x n) (rtz x n)) + (= (rna x n) (raz x n))) + :rule-classes ()) + +(defthm sgn-rna + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (equal (sgn (rna x n)) + (sgn x)))) + +(defthm rna-positive + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0)) + (> (rna x n) 0)) + :rule-classes :linear) + +(defthm rna-negative + (implies (and (< x 0) + (rationalp x) + (integerp n) + (> n 0)) + (< (rna x n) 0)) + :rule-classes :linear) + +(defthm rna-0 + (equal (rna 0 n) 0)) + +(defthm rna-exactp-a + (implies (> n 0) + (exactp (rna x n) n))) + +(defthmd rna-exactp-b + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (iff (exactp x n) + (= x (rna x n))))) + +(defthm rna-exactp-c + (implies (and (rationalp x) + (integerp n) + (> n 0) + (rationalp a) + (exactp a n) + (>= a x)) + (>= a (rna x n))) + :rule-classes ()) + +(defthm rna-exactp-d + (implies (and (rationalp x) + (integerp n) + (> n 0) + (rationalp a) + (exactp a n) + (<= a x)) + (<= a (rna x n))) + :rule-classes ()) + +(defthmd expo-rna + (implies (and (rationalp x) + (natp n) + (not (= (abs (rna x n)) (expt 2 (1+ (expo x)))))) + (equal (expo (rna x n)) + (expo x)))) + +(defthm rna<=raz + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0)) + (<= (rna x n) (raz x n))) + :rule-classes ()) + +(defthm rna>=rtz + (implies (and (rationalp x) + (> x 0) + (integerp n) + (> n 0)) + (>= (rna x n) (rtz x n))) + :rule-classes ()) + +(defthm rna-shift + (implies (and (rationalp x) + (integerp n) + (integerp k)) + (= (rna (* x (expt 2 k)) n) + (* (rna x n) (expt 2 k)))) + :rule-classes ()) + +(defthmd rna-minus + (equal (rna (- x) n) (- (rna x n)))) + +(defthmd rna-rtz + (implies (and (rationalp x) + (integerp n) + (< (abs (- x (rtz x n))) + (abs (- (raz x n) x)))) + (equal (rna x n) (rtz x n)))) + +(defthmd rna-raz + (implies (and (rationalp x) + (integerp n) + (> (abs (- x (rtz x n))) + (abs (- (raz x n) x)))) + (equal (rna x n) (raz x n)))) + +(defthmd rna-down + (implies (and (rationalp x) + (rationalp a) + (>= x a) + (> a 0) + (not (zp n)) + (exactp a n) + (< x (+ a (expt 2 (- (expo a) n))))) + (equal (rna x n) a)) + :hints (("Goal" :use (near+-down)))) + +(defthmd rna-up + (implies (and (rationalp x) + (rationalp a) + (> a 0) + (not (zp n)) + (exactp a n) + (< x (fp+ a n)) + (> x (+ a (expt 2 (- (expo a) n))))) + (equal (rna x n) (fp+ a n)))) + +(defthmd rna-up-2 + (implies (and (rationalp x) + (integerp k) + (not (zp n)) + (not (zp m)) + (< m n) + (< (abs x) (expt 2 k)) + (= (abs (rna x n)) (expt 2 k))) + (equal (abs (rna x m)) (expt 2 k)))) + +(defthm rna-nearest + (implies (and (exactp y n) + (rationalp x) + (rationalp y) + (integerp n) + (> n 0)) + (>= (abs (- x y)) (abs (- x (rna x n))))) + :rule-classes ()) + +(defthm rna-force + (implies (and (integerp n) + (> n 0) + (rationalp x) + (not (= x 0)) + (rationalp y) + (exactp y n) + (< (abs (- x y)) (expt 2 (- (expo x) n)))) + (= y (rna x n))) + :rule-classes ()) + +(defthm rna-diff + (implies (and (integerp n) + (> n 0) + (rationalp x)) + (<= (abs (- x (rna x n))) + (expt 2 (- (expo x) n)))) + :rule-classes ()) + +(defthm rna-monotone + (implies (and (<= x y) + (rationalp x) + (rationalp y) + (natp n)) + (<= (rna x n) (rna y n))) + :rule-classes ()) + +(defund rna-witness (x y n) + (if (= (expo x) (expo y)) + (/ (+ (rna x n) (rna y n)) 2) + (expt 2 (expo y)))) + +(defthm rna-rna-lemma + (implies (and (rationalp x) + (rationalp y) + (< 0 x) + (< x y) + (integerp n) + (> n 0) + (not (= (rna x n) (rna y n)))) + (and (<= x (rna-witness x y n)) + (<= (rna-witness x y n) y) + (exactp (rna-witness x y n) (1+ n)))) + :rule-classes ()) + +(defthm rna-rna + (implies (and (rationalp x) + (rationalp y) + (rationalp a) + (integerp n) + (integerp k) + (> k 0) + (>= n k) + (< 0 a) + (< a x) + (< 0 y) + (< y (fp+ a (1+ n))) + (exactp a (1+ n))) + (<= (rna y k) (rna x k))) + :rule-classes ()) + +(defthmd rna-midpoint + (implies (and (rationalp x) + (integerp n) + (exactp x (1+ n)) + (not (exactp x n))) + (equal (rna x n) (raz x n)))) + +(defthm rne-pow-2 + (implies (and (rationalp x) (> x 0) + (not (zp n)) + (>= (+ x (expt 2 (- (expo x) n))) + (expt 2 (1+ (expo x))))) + (= (rne x n) + (expt 2 (1+ (expo x))))) + :rule-classes ()) + +(defthm rtz-pow-2 + (implies (and (rationalp x) (> x 0) + (not (zp n)) + (>= (+ x (expt 2 (- (expo x) n))) + (expt 2 (1+ (expo x))))) + (= (rtz (+ x (expt 2 (- (expo x) n))) n) + (expt 2 (1+ (expo x))))) + :rule-classes ()) + +(defthm rna-pow-2 + (implies (and (rationalp x) (> x 0) + (not (zp n)) + (>= (+ x (expt 2 (- (expo x) n))) + (expt 2 (1+ (expo x))))) + (= (rna x n) + (expt 2 (1+ (expo x))))) + :rule-classes ()) + +(defthm plus-rne + (implies (and (exactp x (1- (+ k (- (expo x) (expo y))))) + (rationalp x) + (>= x 0) + (rationalp y) + (>= y 0) + (integerp k)) + (= (+ x (rne y k)) + (rne (+ x y) + (+ k (- (expo (+ x y)) (expo y)))))) + :rule-classes ()) + +(defthm plus-rna + (implies (and (exactp x (+ k (- (expo x) (expo y)))) + (rationalp x) + (>= x 0) + (rationalp y) + (>= y 0) + (integerp k)) + (= (+ x (rna y k)) + (rna (+ x y) + (+ k (- (expo (+ x y)) (expo y)))))) + :rule-classes ()) + +(defthmd rne-impl + (implies (and (rationalp x) (> x 0) + (not (zp n))) + (equal (rne x n) + (if (and (> n 1) (exactp x (1+ n)) (not (exactp x n))) + (rtz (+ x (expt 2 (- (expo x) n))) (1- n)) + (rtz (+ x (expt 2 (- (expo x) n))) n))))) + +(defthmd rna-impl + (implies (and (rationalp x) (> x 0) + (not (zp n))) + (equal (rna x n) + (rtz (+ x (expt 2 (- (expo x) n))) n)))) + +(defthmd rna-imp-cor + (implies (and (rationalp x) + (integerp m) + (integerp n) + (> n m) + (> m 0)) + (equal (rna (rtz x n) m) + (rna x m)))) +) + +;;;********************************************************************** +;;; Odd Rounding +;;;********************************************************************** + +(defsection-rtl |Odd Rounding| |Rounding| + +(defund rto (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (exactp x (1- n)) + x + (+ (rtz x (1- n)) + (* (sgn x) (expt 2 (1+ (- (expo x) n))))))) + +(defthm sgn-rto + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (equal (sgn (rto x n)) + (sgn x)))) + +(defthmd rto-positive + (implies (and (< 0 x) + (rationalp x) + (integerp n) + (> n 0)) + (> (rto x n) 0)) + :rule-classes :linear) + +(defthmd rto-negative + (implies (and (< x 0) + (rationalp x) + (integerp n) + (> n 0)) + (< (rto x n) 0)) + :rule-classes :linear) + +(defthm rto-0 + (equal (rto 0 n) 0)) + +(defthmd rto-minus + (equal (rto (- x) n) (- (rto x n)))) + +(defthm rto-shift + (implies (and (rationalp x) + (integerp n) (> n 0) + (integerp k)) + (= (rto (* (expt 2 k) x) n) + (* (expt 2 k) (rto x n)))) + :rule-classes ()) + +(defund err-rto (k m n x0) + (- (rto (xfp k m x0) n) (xfp k m x0))) + +(defund sum-err-rto (i j m n x0) + (declare (xargs :measure (nfix (1+ (- j i))))) + (if (and (natp i) (natp j) (<= i j)) + (+ (sum-err-rto i (1- j) m n x0) + (err-rto j m n x0)) + 0)) + +(defthm rto-unbiased + (implies (and (natp m) + (natp n) + (< 1 n) + (< n m) + (rationalp x0) + (> x0 0) + (exactp x0 (1- n))) + (equal (sum-err-rto 0 (1- (expt 2 (- (1+ m) n))) m n x0) + 0))) + +(defthm expo-rto + (implies (and (rationalp x) ;; (> x 0) + (integerp n) (> n 0)) + (equal (expo (rto x n)) + (expo x)))) + +(defthm rto-exactp-a + (implies (and (rationalp x) + (integerp n) (> n 0)) + (exactp (rto x n) n))) + +(defthmd rto-exactp-b + (implies (and (rationalp x) + (integerp n) + (> n 0)) + (iff (exactp x n) + (= x (rto x n))))) + +(defthmd rto-monotone + (implies (and (<= x y) + (rationalp x) + (rationalp y) + (natp n)) + (<= (rto x n) (rto y n))) + :rule-classes :linear) + +(defthm rto-exactp-c + (implies (and (rationalp x) + (integerp m) + (integerp n) + (> n m) + (> m 0)) + (iff (exactp (rto x n) m) + (exactp x m)))) + +(defthm rtz-rto + (implies (and (rationalp x) + (integerp m) (> m 0) + (integerp n) (> n m)) + (equal (rtz (rto x n) m) + (rtz x m)))) + +(defthm raz-rto + (implies (and (rationalp x) + (integerp m) (> m 0) + (integerp n) (> n m)) + (equal (raz (rto x n) m) + (raz x m)))) + +(defthm rne-rto + (implies (and (rationalp x) + (integerp m) (> m 0) + (integerp n) (> n (1+ m))) + (equal (rne (rto x n) m) + (rne x m)))) + +(defthm rna-rto + (implies (and (rationalp x) + (integerp m) (> m 0) + (integerp n) (> n (1+ m))) + (equal (rna (rto x n) m) + (rna x m)))) + +(defthm rto-rto + (implies (and (rationalp x) + (integerp m) + (> m 1) + (integerp n) + (>= n m)) + (equal (rto (rto x n) m) + (rto x m)))) + +(defthm rto-plus + (implies (and (rationalp x) + (rationalp y) + (not (= y 0)) + (not (= (+ x y) 0)) + (integerp k) + (= k1 (+ k (- (expo x) (expo y)))) + (= k2 (+ k (- (expo (+ x y)) (expo y)))) + (> k 1) + (> k1 1) + (> k2 1) + (exactp x (1- k1))) + (= (+ x (rto y k)) + (rto (+ x y) k2))) + :rule-classes ()) +) + +;;;********************************************************************** +;;; IEEE Rounding +;;;********************************************************************** + +(defsection-rtl |IEEE Rounding| |Rounding| + +(defun rup (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (>= x 0) + (raz x n) + (rtz x n))) + +(defun rdn (x n) + (declare (xargs :guard (and (real/rationalp x) + (integerp n)))) + (if (>= x 0) + (rtz x n) + (raz x n))) + +(defthmd rup-lower-bound + (implies (and (case-split (rationalp x)) + (case-split (integerp n))) + (>= (rup x n) x)) + :rule-classes :linear) + +(defthmd rdn-upper-bound + (implies (and (case-split (rationalp x)) + (case-split (integerp n))) + (<= (rdn x n) x)) + :rule-classes :linear) + +(defnd IEEE-rounding-mode-p (mode) + (member mode '(rtz rup rdn rne))) + +(defnd common-mode-p (mode) + (or (IEEE-rounding-mode-p mode) (equal mode 'raz) (equal mode 'rna))) + +(defthm ieee-mode-is-common-mode + (implies (IEEE-rounding-mode-p mode) + (common-mode-p mode))) + +(defund rnd (x mode n) + (declare (xargs :guard (and (real/rationalp x) + (common-mode-p mode) + (integerp n)))) + (case mode + (raz (raz x n)) + (rna (rna x n)) + (rtz (rtz x n)) + (rup (rup x n)) + (rdn (rdn x n)) + (rne (rne x n)) + (otherwise 0))) + +(defthm rationalp-rnd + (rationalp (rnd x mode n)) + :rule-classes (:type-prescription)) + +(defthm rnd-choice + (implies (and (rationalp x) + (integerp n) + (common-mode-p mode)) + (or (= (rnd x mode n) (rtz x n)) + (= (rnd x mode n) (raz x n)))) + :rule-classes ()) + +(defthmd sgn-rnd + (implies (and (common-mode-p mode) + (integerp n) + (> n 0)) + (equal (sgn (rnd x mode n)) + (sgn x)))) + +(defthm rnd-positive + (implies (and (< 0 x) + (rationalp x) + (integerp n) + (> n 0) + (common-mode-p mode)) + (> (rnd x mode n) 0)) + :rule-classes (:type-prescription)) + +(defthm rnd-negative + (implies (and (< x 0) + (rationalp x) + (integerp n) + (> n 0) + (common-mode-p mode)) + (< (rnd x mode n) 0)) + :rule-classes (:type-prescription)) + +(defthm rnd-0 + (equal (rnd 0 mode n) 0)) + +(defthm rnd-non-pos + (implies (<= x 0) + (<= (rnd x mode n) 0)) + :rule-classes (:rewrite :type-prescription :linear)) + +(defthm rnd-non-neg + (implies (<= 0 x) + (<= 0 (rnd x mode n))) + :rule-classes (:rewrite :type-prescription :linear)) + +(defund flip-mode (m) + (declare (xargs :guard (common-mode-p m))) + (case m + (rup 'rdn) + (rdn 'rup) + (t m))) + +(defthm ieee-rounding-mode-p-flip-mode + (implies (ieee-rounding-mode-p m) + (ieee-rounding-mode-p (flip-mode m)))) + +(defthm common-mode-p-flip-mode + (implies (common-mode-p m) + (common-mode-p (flip-mode m)))) + +(defthmd rnd-minus + (equal (rnd (- x) mode n) + (- (rnd x (flip-mode mode) n)))) + +(defthm rnd-exactp-a + (implies (< 0 n) + (exactp (rnd x mode n) n))) + +(defthmd rnd-exactp-b + (implies (and (rationalp x) + (common-mode-p mode) + (integerp n) + (> n 0)) + (equal (exactp x n) + (equal x (rnd x mode n))))) + +(defthm rnd-exactp-c + (implies (and (rationalp x) + (common-mode-p mode) + (integerp n) + (> n 0) + (rationalp a) + (exactp a n) + (>= a x)) + (>= a (rnd x mode n))) + :rule-classes ()) + +(defthm rnd-exactp-d + (implies (and (rationalp x) + (common-mode-p mode) + (integerp n) + (> n 0) + (rationalp a) + (exactp a n) + (<= a x)) + (<= a (rnd x mode n))) + :rule-classes ()) + +(defthm rnd<=raz + (implies (and (rationalp x) + (>= x 0) + (common-mode-p mode) + (natp n)) + (<= (rnd x mode n) (raz x n))) + :rule-classes ()) + +(defthm rnd>=rtz + (implies (and (rationalp x) + (> x 0) ;; + (common-mode-p mode) + (integerp n) + (> n 0)) + (>= (rnd x mode n) (rtz x n))) + :rule-classes ()) + +(defthm rnd n 0) + (> x 0) + (not (exactp x (1+ n))) + (< (rtz x (1+ n)) y) + (< y x)) + (= (rnd y mode n) (rnd x mode n))) + :rule-classes ()) + +(defthm rnd>equal + (implies (and (rationalp x) + (rationalp y) + (natp n) + (common-mode-p mode) + (> n 0) + (> x 0) + (not (exactp x (1+ n))) + (> (raz x (1+ n)) y) + (> y x)) + (= (rnd y mode n) (rnd x mode n))) + :rule-classes ()) + +(defthm rnd-near-equal + (implies (and (rationalp x) + (rationalp y) + (natp n) + (common-mode-p mode) + (> n 0) + (> x 0) + (not (exactp x (1+ n)))) + (let ((d (min (- x (rtz x (1+ n))) (- (raz x (1+ n)) x)))) + (and (> d 0) + (implies (< (abs (- x y)) d) + (= (rnd y mode n) (rnd x mode n)))))) + :rule-classes ()) + +(defthmd expo-rnd + (implies (and (rationalp x) + (integerp n) + (> n 0) + (common-mode-p mode) + (not (= (abs (rnd x mode n)) + (expt 2 (1+ (expo x)))))) + (equal (expo (rnd x mode n)) + (expo x)))) + +(defthm rnd-monotone + (implies (and (<= x y) + (rationalp x) + (rationalp y) + (common-mode-p mode) + (integerp n) + (> n 0)) + (<= (rnd x mode n) (rnd y mode n))) + :rule-classes ()) + +(defthm rnd-shift + (implies (and (rationalp x) + (integerp n) + (common-mode-p mode) + (integerp k)) + (= (rnd (* x (expt 2 k)) mode n) + (* (rnd x mode n) (expt 2 k)))) + :rule-classes ()) + +(defthm plus-rnd + (implies (and (rationalp x) + (>= x 0) + (rationalp y) + (>= y 0) + (integerp k) + (exactp x (+ -1 k (- (expo x) (expo y)))) + (common-mode-p mode)) + (= (+ x (rnd y mode k)) + (rnd (+ x y) + mode + (+ k (- (expo (+ x y)) (expo y)))))) + :rule-classes ()) + +(defthmd rnd-rto + (implies (and (common-mode-p mode) + (rationalp x) + (integerp m) + (> m 0) + (integerp n) + (>= n (+ m 2))) + (equal (rnd (rto x n) mode m) + (rnd x mode m)))) + +(defthmd rnd-up + (implies (and (rationalp x) + (integerp k) + (not (zp n)) + (not (zp m)) + (< m n) + (< (abs x) (expt 2 k)) + (common-mode-p mode) + (= (abs (rnd x mode n)) (expt 2 k))) + (equal (abs (rnd x mode m)) (expt 2 k)))) + +(defun rnd-const (e mode n) + (declare (xargs :guard (and (integerp e) + (common-mode-p mode) + (integerp n)))) + (case mode + ((rne rna) (expt 2 (- e n))) + ((rup raz) (1- (expt 2 (1+ (- e n))))) + (otherwise 0))) + +(defthmd rnd-const-lemma + (implies (and (common-mode-p mode) + (not (zp n)) + (not (zp x)) + (implies (or (= mode 'raz) (= mode 'rup)) + (>= (expo x) (1- n)))) + (equal (rnd x mode n) + (if (and (eql mode 'rne) + (> n 1) + (exactp x (1+ n)) + (not (exactp x n))) + (rtz (+ x (rnd-const (expo x) mode n)) (1- n)) + (rtz (+ x (rnd-const (expo x) mode n)) n))))) + +(defund roundup-pos (x e sticky mode n) + (declare (xargs :guard (and (integerp x) + (integerp e) + (integerp sticky) + (common-mode-p mode) + (integerp n)))) + (case mode + ((rup raz) (or (not (= (bits x (- e n) 0) 0)) + (= sticky 1))) + (rna (= (bitn x (- e n)) 1)) + (rne (and (= (bitn x (- e n)) 1) + (or (not (= (bits x (- e (1+ n)) 0) 0)) + (= sticky 1) + (= (bitn x (- (1+ e) n)) 1)))) + (otherwise ()))) + +(defthmd rnd-const-cor-a + (implies (and (common-mode-p mode) + (posp n) + (posp m) + (> (expo m) n)) + (let* ((e (expo m)) + (sum (+ m (rnd-const e mode n))) + (sh (bits sum (1+ e) (1+ (- e n)))) + (sl (bits sum (- e n) 0))) + (equal (rnd m mode n) + (if (and (= mode 'rne) (= sl 0)) + (* (expt 2 (+ 2 (- e n))) (bits sh n 1)) + (* (expt 2 (1+ (- e n))) sh)))))) + +(defthmd rnd-const-cor-b + (implies (and (common-mode-p mode) + (posp n) + (posp m) + (> (expo m) n)) + (let* ((e (expo m)) + (c (rnd-const e mode n)) + (sum (+ m c)) + (sl (bits sum (- e n) 0))) + (iff (= m (rnd m mode n)) + (= sl c))))) + +(defthmd roundup-pos-thm-1 + (implies (and (rationalp z) + (not (zp n)) + (<= (expt 2 n) z)) + (let ((x (fl z))) + (iff (exactp z n) + (and (integerp z) (= (bits x (- (expo x) n) 0) 0)))))) + +(defthmd roundup-pos-thm-2 + (implies (and (common-mode-p mode) + (rationalp z) + (not (zp n)) + (<= (expt 2 n) z)) + (let ((x (fl z)) + (sticky (if (integerp z) 0 1))) + (equal (rnd z mode n) + (if (roundup-pos x (expo x) sticky mode n) + (fp+ (rtz x n) n) + (rtz x n)))))) + +(defthmd roundup-pos-thm + (implies (and (common-mode-p mode) + (rationalp z) + (not (zp n)) + (<= (expt 2 n) z)) + (let ((x (fl z)) + (sticky (if (integerp z) 0 1))) + (and (iff (exactp z n) + (and (integerp z) (= (bits x (- (expo x) n) 0) 0))) + (equal (rnd z mode n) + (if (roundup-pos x (expo x) sticky mode n) + (fp+ (rtz x n) n) + (rtz x n))))))) + +(defund roundup-neg (x e sticky mode n) + (declare (xargs :guard (and (integerp x) + (integerp e) + (integerp sticky) + (common-mode-p mode) + (integerp n)))) + (case mode + ((rdn raz) t) + ((rup rtz) (and (= (bits x (- e n) 0) 0) + (= sticky 0))) + (rna (or (= (bitn x (- e n)) 0) + (and (= (bits x (- e (1+ n)) 0) 0) + (= sticky 0)))) + (rne (or (= (bitn x (- e n)) 0) + (and (= (bitn x (- (1+ e) n)) 0) + (= (bits x (- e (1+ n)) 0) 0) + (= sticky 0)))) + (otherwise ()))) + +(defthm roundup-neg-thm + (implies (and (common-mode-p mode) + (rationalp z) + (not (zp n)) + (natp k) + (< n k) + (<= (- (expt 2 k)) z) + (< z (- (expt 2 n)))) + (let* ((x (+ (fl z) (expt 2 k))) + (xc (1- (- (expt 2 k) x))) + (e (expo xc)) + (sticky (if (integerp z) 0 1))) + (and (implies (not (= (expo z) e)) + (= z (- (expt 2 (1+ e))))) + (iff (exactp z n) + (and (integerp z) (= (bits x (- (expo xc) n) 0) 0))) + (equal (abs (rnd z mode n)) + (if (roundup-neg x (expo xc) sticky mode n) + (fp+ (rtz xc n) n) + (rtz xc n)))))) + :rule-classes ()) +) +;;;********************************************************************** +;;; Denormal Rounding +;;;********************************************************************** + +(defsection-rtl |Denormal Rounding| |Rounding| + +(defund drnd (x mode f) + (declare (xargs :guard (and (real/rationalp x) + (common-mode-p mode) + (formatp f)))) + (rnd x mode (+ (prec f) (expo x) (- (expo (spn f)))))) + +(defthmd drnd-minus + (equal (drnd (- x) mode f) + (- (drnd x (flip-mode mode) f)))) + +(defthmd drnd-pos + (implies (and (formatp f) + (rationalp x) + (>= x 0) + (<= x (spn f)) + (common-mode-p mode)) + (>= (drnd x mode f) 0))) + +(defthmd drnd-rewrite + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f)) + (common-mode-p mode)) + (equal (drnd x mode f) + (- (rnd (+ x (* (sgn x) (spn f))) mode (prec f)) + (* (sgn x) (spn f)))))) + +(defthm drnd-exactp-a + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f)) + (common-mode-p mode)) + (or (drepp (drnd x mode f) f) + (= (drnd x mode f) 0) + (= (drnd x mode f) (* (sgn x) (spn f))))) + :rule-classes ()) + +(defthmd drnd-exactp-b + (implies (and (formatp f) + (rationalp x) + (drepp x f) + (common-mode-p mode)) + (equal (drnd x mode f) + x))) + +(defthmd drnd-exactp-c + (implies (and (formatp f) + (rationalp x) + (<= (expo x) (- (bias f))) + (>= (expo x) (+ 2 (- (bias f)) (- (prec f)))) + (common-mode-p mode)) + (iff (equal x (drnd x mode f)) + (exactp x (+ (1- (prec f)) (bias f) (expo x)))))) + +(defthm drnd-exactp-d + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f)) + (rationalp a) + (drepp a f) + (>= a x) + (common-mode-p mode)) + (>= a (drnd x mode f))) + :rule-classes ()) + +(defthm drnd-exactp-e + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f)) + (rationalp a) + (drepp a f) + (<= a x) + (common-mode-p mode)) + (<= a (drnd x mode f))) + :rule-classes ()) + +(defthm drnd-rtz + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f))) + (<= (abs (drnd x 'rtz f)) + (abs x))) + :rule-classes ()) + +(defthm drnd-raz + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f))) + (>= (abs (drnd x 'raz f)) + (abs x))) + :rule-classes ()) + +(defthm drnd-rdn + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f))) + (<= (drnd x 'rdn f) + x)) + :rule-classes ()) + +(defthm drnd-rup + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f))) + (>= (drnd x 'rup f) + x)) + :rule-classes ()) + +(defthm drnd-diff + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f)) + (common-mode-p mode)) + (< (abs (- x (drnd x mode f))) (spd f))) + :rule-classes ()) + +(defthm drnd-rne-diff + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f)) + (drepp a f)) + (>= (abs (- x a)) (abs (- x (drnd x 'rne f))))) + :rule-classes ()) + +(defthm drnd-rna-diff + (implies (and (formatp f) + (rationalp x) + (<= (abs x) (spn f)) + (drepp a f)) + (>= (abs (- x a)) (abs (- x (drnd x 'rna f))))) + :rule-classes ()) + +(defthmd drnd-rto + (implies (and (formatp f) + (common-mode-p mode) + (rationalp x) + (<= (abs x) (spn f)) + (natp n) + (>= n (+ (prec f) (expo x) (- (expo (spn f))) 2))) + (equal (drnd (rto x n) mode f) + (drnd x mode f)))) + +(defthmd rnd-drnd-exactp + (implies (and (formatp f) + (rationalp x) + (< (abs x) (spn f)) + (common-mode-p mode) + (= (drnd x mode f) x)) + (equal (rnd x mode (prec f)) x))) + +(defthmd drnd-tiny-a + (implies (and (formatp f) + (common-mode-p mode) + (rationalp x) + (< 0 x) + (< x (/ (spd f) 2))) + (equal (drnd x mode f) + (if (member mode '(raz rup)) + (spd f) + 0)))) + +(defthmd drnd-tiny-b + (implies (and (formatp f) + (common-mode-p mode)) + (equal (drnd (/ (spd f) 2) mode f) + (if (member mode '(raz rup rna)) + (spd f) + 0)))) + +(defthmd drnd-tiny-c + (implies (and (formatp f) + (common-mode-p mode) + (rationalp x) + (< (/ (spd f) 2) x) + (< x (spd f))) + (equal (drnd x mode f) + (if (member mode '(rtz rdn)) + 0 + (spd f))))) + +(defthm drnd-tiny-equal + (implies (and (formatp f) + (common-mode-p mode) + (rationalp x) + (< 0 x) + (< (abs x) (/ (spd f) 2)) + (rationalp y) + (< 0 y) + (< (abs y) (/ (spd f) 2))) + (equal (drnd x mode f) + (drnd y mode f))) + :rule-classes ()) + +;;;********************************************************************** +;;; Detecting Underflow +;;;********************************************************************** + +(defthmd rnd-drnd + (implies (and (formatp f) + (> (prec f) 2) + (rationalp m) + (< 0 m) + (< m 1) + (common-mode-p mode)) + (let* ((x (* (spn f) m)) + (p (prec f)) + (r (rnd x mode p)) + (d (drnd x mode f))) + (case mode + ((rdn rtz) (and (< r (spn f)) (< d (spn f)))) + ((rup raz) (and (iff (< r (spn f)) (<= m (- 1 (expt 2 (- p))))) + (iff (< d (spn f)) (<= m (- 1 (expt 2 (- 1 p))))))) + ((rne rna) (and (iff (< r (spn f)) (< m (- 1 (expt 2 (- (1+ p)))))) + (iff (< d (spn f)) (< m (- 1 (expt 2 (- p))))))))))) + +(defthmd rnd-drnd-up + (implies (and (formatp f) + (rationalp x) + (< (abs x) (spn f)) + (common-mode-p mode) + (= (abs (rnd x mode (prec f))) (spn f))) + (equal (abs (drnd x mode f)) (spn f)))) + +(defthmd rnd-drnd-inject-a + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (sum (+ m (rnd-const (1- k) mode p))) + (sl (bits sum (1- (- k p)) 0)) + (sh (bits sum k (- k p)))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (< (expo m) (- k p))) + (equal (drnd x mode f) + (if (and (= mode 'rne) (= sl 0)) + (* (expt 2 (- 2 p)) s (bits sh p 1)) + (* (expt 2 (- 1 p)) s sh)))))) + +(defthmd rnd-drnd-inject-b + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sl (bits sum (1- (- k p)) 0))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m)) + (iff (= x (drnd x mode f)) + (= sl c))))) + +(defthmd rnd-drnd-inject-c + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sh (bits sum k (- k p)))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (> sh (expt 2 (1- p)))) + (and (>= x s) + (>= (rnd x mode p) s))))) + +(defthmd rnd-drnd-inject-d + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sh (bits sum k (- k p)))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (< sh (expt 2 (1- p)))) + (and (< x s) + (< (rnd x mode p) s))))) + +(defthmd rnd-drnd-inject-e + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sh (bits sum k (- k p)))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (= sh (expt 2 (1- p))) + (or (= mode 'rtz) (= mode 'rdn))) + (and (>= x s) + (>= (rnd x mode p) s))))) + +(defthmd rnd-drnd-inject-f-i + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sh (bits sum k (- k p))) + (sl (bits sum (1- (- k p)) 0))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (= sh (expt 2 (1- p))) + (or (= mode 'raz) (= mode 'rup))) + (iff (< x s) + (not (= sl c)))))) + +(defthmd rnd-drnd-inject-f-ii + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sh (bits sum k (- k p))) + (g (bitn sum (1- (- k p))))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (= sh (expt 2 (1- p))) + (or (= mode 'raz) (= mode 'rup))) + (iff (< (rnd x mode p) s) + (= g 0))))) + +(defthmd rnd-drnd-inject-g-i + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sh (bits sum k (- k p))) + (g (bitn sum (1- (- k p))))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (= sh (expt 2 (1- p))) + (or (= mode 'rne) (= mode 'rna))) + (iff (< x s) + (= g 0))))) + +(defthmd rnd-drnd-inject-g-ii + (let* ((p (prec f)) + (s (spn f)) + (x (* s z)) + (m (* (expt 2 (1- k)) z)) + (c (rnd-const (1- k) mode p)) + (sum (+ m c)) + (sh (bits sum k (- k p))) + (g (bitn sum (1- (- k p)))) + (r (bitn sum (- (- k p) 2)))) + (implies (and (formatp f) + (rationalp z) + (< 0 z) + (< z 2) + (common-mode-p mode) + (natp k) + (>= k (+ p 2)) + (natp m) + (= sh (expt 2 (1- p))) + (or (= mode 'rne) (= mode 'rna))) + (iff (< (rnd x mode p) s) + (and (= g 0) (= r 0)))))) + +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/sqrt.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/sqrt.lisp new file mode 100644 index 000000000..436b451d1 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/sqrt.lisp @@ -0,0 +1,334 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;;********************************************************************** +;;; RTZ-SQRT +;;;********************************************************************** + +(defsection-rtl |Truncated Square Root| |IEEE-Compliant Square Root| + +(defund rtz-sqrt (x n) + (declare (xargs :guard (and (real/rationalp x) + (natp n)))) + (if (zp n) + 0 + (let* ((lower (rtz-sqrt x (1- n))) + (upper (+ lower (expt 2 (- n))))) + (if (<= (* upper upper) x) + upper + lower)))) + +(defthm rtz-sqrt-bounds + (implies (and (rationalp x) + (<= 1/4 x) + (not (zp n))) + (and (<= 1/2 (rtz-sqrt x n)) + (<= (rtz-sqrt x n) (- 1 (expt 2 (- n)))))) + :rule-classes ()) + + +(defthm expo-rtz-sqrt + (implies (and (rationalp x) + (<= 1/4 x) + (not (zp n))) + (equal (expo (rtz-sqrt x n)) + -1))) + +(defthm exactp-rtz-sqrt + (implies (and (rationalp x) + (<= 1/4 x) + (not (zp n))) + (exactp (rtz-sqrt x n) + n)) + :rule-classes ()) + +(defthm rtz-sqrt-square-bounds + (implies (and (not (zp n)) + (rationalp x) + (<= 1/4 x) + (< x 1)) + (and (<= (* (rtz-sqrt x n) + (rtz-sqrt x n)) + x) + (< x + (* (+ (rtz-sqrt x n) (expt 2 (- n))) + (+ (rtz-sqrt x n) (expt 2 (- n))))))) + :rule-classes ()) + +(defthm rtz-sqrt-unique + (implies (and (not (zp n)) + (rationalp x) + (<= 1/4 x) + (< x 1) + (rationalp a) + (exactp a n) + (>= a 1/2) + (<= (* a a) x) + (< x (* (+ a (expt 2 (- n))) (+ a (expt 2 (- n)))))) + (= a (rtz-sqrt x n))) + :rule-classes ()) + +(defthmd rtz-rtz-sqrt + (implies (and (rationalp x) + (<= 1/4 x) + (not (zp m)) + (natp n) + (>= n m)) + (equal (rtz (rtz-sqrt x n) m) + (rtz-sqrt x m)))) +) + +;;;********************************************************************** +;;; RTO-SQRT +;;;********************************************************************** + +(defsection-rtl |Odd-Rounded Square Root| |IEEE-Compliant Square Root| + +(defund rto-sqrt (x n) + (declare (xargs :guard (and (real/rationalp x) + (posp n)))) + (let ((trunc (rtz-sqrt x (1- n)))) + (if (< (* trunc trunc) x) + (+ trunc (expt 2 (- n))) + trunc))) + +(defthm rto-sqrt-bounds + (implies (and (rationalp x) + (<= 1/4 x) + (natp n) + (>= n 2)) + (and (<= 1/2 (rto-sqrt x n)) + (< (rto-sqrt x n) 1))) + :rule-classes ()) + +(defthm expo-rto-sqrt + (implies (and (rationalp x) + (<= 1/4 x) + (natp n) + (>= n 2)) + (equal (expo (rto-sqrt x n)) + -1))) + +(defthmd exactp-rto-sqrt + (implies (and (rationalp x) + (<= 1/4 x) + (natp n) + (>= n 2)) + (exactp (rto-sqrt x n) n))) + +(defthmd rto-rto-sqrt + (implies (and (natp n) + (>= n 2) + (natp m) + (>= m n) + (rationalp x) + (<= 1/4 x) + (< x 1)) + (equal (rto (rto-sqrt x m) n) + (rto-sqrt x n)))) + +(defthm rnd-rto-sqrt + (implies (and (not (zp k)) + (natp n) + (>= n (+ k 2)) + (natp m) + (>= m n) + (common-mode-p mode) + (rationalp x) + (<= 1/4 x) + (< x 1)) + (= (rnd (rto-sqrt x m) mode k) + (rnd (rto-sqrt x n) mode k))) + :rule-classes ()) + +(defthmd rtz-rto-sqrt + (implies (and (natp n) + (>= n 2) + (natp m) + (> m n) + (rationalp x) + (<= 1/4 x) + (< x 1)) + (equal (rtz (rto-sqrt x m) n) + (rtz-sqrt x n)))) + +(defthm rtz-rtz-rto + (implies (and (natp n) + (>= n 2) + (natp m) + (> m n) + (rationalp x) + (<= 1/4 x) + (< x 1)) + (iff (= (* (rtz-sqrt x n) (rtz-sqrt x n)) x) + (= (rto-sqrt x m) (rtz-sqrt x n)))) + :rule-classes ()) + +(defthm rto-sqrt-lower + (implies (and (natp n) + (>= n 2) + (rationalp x) + (<= 1/4 x) + (< x 1) + (rationalp l) + (<= (* l l) x)) + (<= (rto l n) + (rto-sqrt x n))) + :rule-classes ()) + +(defthm rto-sqrt-upper + (implies (and (natp n) + (>= n 2) + (rationalp x) + (<= 1/4 x) + (< x 1) + (rationalp h) + (>= h 0) + (>= (* h h) x)) + (>= (rto h n) + (rto-sqrt x n))) + :rule-classes ()) + +(defthm exactp-cmp-rto-sqrt + (implies (and (rationalp x) (>= x 1/4) (< x 1) + (rationalp q) (> q 0) + (integerp n) (> n 1) + (exactp q (1- n))) + (and (iff (< (* q q) x) (< q (rto-sqrt x n))) + (iff (> (* q q) x) (> q (rto-sqrt x n))))) + :rule-classes ()) +) + +;;;********************************************************************** +;;; QSQRT +;;;********************************************************************** + +(defsection-rtl |IEEE-Rounded Square Root| |IEEE-Compliant Square Root| + +(defund qsqrt (x n) + (declare (xargs :guard (and (real/rationalp x) + (posp n)))) + (let ((e (1+ (fl (/ (expo x) 2))))) + (* (expt 2 e) + (rto-sqrt (/ x (expt 2 (* 2 e))) n)))) + +(defthm qsqrt-expo + (implies (and (rationalp x) + (> x 0)) + (let* ((e (1+ (fl (/ (expo x) 2)))) + (xp (/ x (expt 2 (* 2 e))))) + (and (<= 1/4 xp) + (< xp 1)))) + :rule-classes ()) + +(defthmd qsqrt-rto-sqrt + (implies (and (rationalp x) + (<= 1/4 x) + (< x 1) + (integerp n) + (> n 1)) + (equal (qsqrt x n) + (rto-sqrt x n)))) + +(defthmd qsqrt-pos + (implies (and (rationalp x) + (> x 0)) + (> (qsqrt x n) 0))) + +(defthmd qsqrt-shift + (implies (and (rationalp x) + (> x 0) + (integerp k) + (integerp n) + (> n 1)) + (equal (qsqrt (* (expt 2 (* 2 k)) x) n) + (* (expt 2 k) (qsqrt x n))))) + +(defthm rnd-qsqrt-equal + (implies (and (rationalp x) + (> x 0) + (not (zp k)) + (natp n) + (>= n (+ k 2)) + (natp m) + (>= m n) + (common-mode-p mode)) + (equal (rnd (qsqrt x m) mode k) + (rnd (qsqrt x n) mode k))) + :rule-classes ()) + +(defthm qsqrt-lower + (implies (and (rationalp x) + (> x 0) + (rationalp l) + (<= (* l l) x) + (common-mode-p mode) + (not (zp k)) + (integerp n) + (>= n (+ k 2))) + (<= (rnd l mode k) + (rnd (qsqrt x n) mode k))) + :rule-classes ()) + +(defthm qsqrt-upper + (implies (and (rationalp x) + (> x 0) + (rationalp h) + (>= h 0) + (>= (* h h) x) + (common-mode-p mode) + (not (zp k)) + (integerp n) + (>= n (+ k 2))) + (>= (rnd h mode k) + (rnd (qsqrt x n) mode k))) + :rule-classes ()) + +(defthm exactp-cmp-qsqrt + (implies (and (rationalp x) (> x 0) + (rationalp q) (> q 0) + (integerp n) (> n 1) + (exactp q (1- n))) + (and (iff (< (* q q) x) (< q (qsqrt x n))) + (iff (> (* q q) x) (> q (qsqrt x n))) + (iff (= (* q q) x) (= q (qsqrt x n))))) + :rule-classes ()) + +(defthmd qsqrt-sqrt + (implies (and (rationalp x) (> x 0) + (integerp n) (> n 1) + (exactp (qsqrt x n) (1- n))) + (equal (* (qsqrt x n) (qsqrt x n)) + x))) + +(defthm qsqrt-exact-equal + (implies (and (rationalp x) + (> x 0) + (not (zp k)) + (natp n) + (> n k) + (natp m) + (> m k) + (exactp (qsqrt x n) k)) + (equal (qsqrt x n) (qsqrt x m))) + :rule-classes ()) + +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/srt.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/srt.lisp new file mode 100644 index 000000000..b8976a9da --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/srt.lisp @@ -0,0 +1,629 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; +; Contact: +; David M. Russinoff +; david@russinoff.com +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(set-inhibit-warnings "theory") ; avoid warning in the next event +(local (in-theory nil)) + +(include-book "defs") + +;;********************************************************************************** +;; SRT Division +;;********************************************************************************** + +(defsection-rtl |SRT Division and Quotient Digit Selection| + |SRT Division and Square Root| + +(encapsulate (((e$) => *) ((d$) => *) ((x$) => *) ((a$) => *) ((q$ *) => *)) + (local (defun e$ () 2)) + (local (defun d$ () 1/2)) + (local (defun x$ () 1/2)) + (local (defun a$ () 2)) + (local (defun q$ (j) (declare (ignore j)) 0)) + (defund r$ () (expt 2 (e$))) + (defund rho$ () (/ (a$) (1- (r$)))) + (defthmd e$-constraint + (not (zp (e$)))) + (defthmd d$-constraint + (and (rationalp (d$)) + (> (d$) 0))) + (defthmd x$-constraint + (and (rationalp (x$)) + (> (x$) 0) + (< (x$) (* 2 (d$))))) + (defthmd a$-constraint + (not (zp (a$)))) + (defthm q$-constraint + (implies (not (zp j)) + (and (integerp (q$ j)) + (<= (abs (q$ j)) (a$)))) + :rule-classes + ((:type-prescription + :corollary + (implies (not (zp j)) + (integerp (q$ j)))) + (:linear + :corollary + (implies (not (zp j)) + (and (<= (- (a$)) (q$ j)) + (<= (q$ j) (a$))))))) + (defthmd rho$-constraint + (and (< 1/2 (rho$)) + (<= (rho$) 1)))) + +(defund quot$ (j) + (if (zp j) + 0 + (+ (quot$ (1- j)) + (* (q$ j) (expt (r$) (- 1 j)))))) + +(defund rem$ (j) + (* (expt (r$) (1- j)) + (- (x$) (* (d$) (quot$ j))))) + +(defthmd rem0-div-rewrite + (equal (rem$ 0) (/ (x$) (r$)))) + +(defthmd rem-div-recurrence + (implies (natp j) + (equal (rem$ (+ 1 j)) + (- (* (r$) (rem$ j)) + (* (q$ (1+ j)) (d$)))))) + +(defthmd rem0-div-bound + (< (abs (rem$ 0)) (* (rho$) (d$)))) + +(defund sel-upper-div (k d) (* (+ k (rho$)) d)) + +(defund sel-lower-div (k d) (* (- k (rho$)) d)) + +(defthmd rem-div-bnd-next + (implies (and (natp j) + (<= (sel-lower-div (q$ (1+ j)) (d$)) (* (r$) (rem$ j))) + (>= (sel-upper-div (q$ (1+ j)) (d$)) (* (r$) (rem$ j)))) + (<= (abs (rem$ (1+ j))) (* (rho$) (d$))))) + +(defthm select-overlap + (implies (integerp k) + (and (< (sel-lower-div k (d$)) (sel-lower-div (1+ k) (d$))) + (< (sel-lower-div (1+ k) (d$)) (sel-upper-div k (d$))) + (< (sel-upper-div k (d$)) (sel-upper-div (1+ k) (d$))) + (<= (sel-upper-div k (d$)) (sel-lower-div (+ k 2) (d$)))))) + +(defthmd div-containment + (and (equal (sel-upper-div (a$) (d$)) (* (r$) (rho$) (d$))) + (equal (sel-lower-div (- (a$)) (d$)) (- (* (r$) (rho$)(d$)))))) + +;;------------------------------------------------------------------------------------------------------------------ +;; Minimally Redundant Radix-4 Division +;;------------------------------------------------------------------------------------------------------------------ + +(defun md4 (k) + (case k (2 13/8) (1 4/8) (0 -3/8) (-1 -12/8))) + +(defund select-digit-d4 (a) + (cond ((<= (md4 2) a) 2) + ((<= (md4 1) a) 1) + ((<= (md4 0) a) 0) + ((<= (md4 -1) a) -1) + (t -2))) + +(defthmd sel-limits-4 + (implies (and (<= 63/64 (d$)) + (<= (d$) 9/8) + (= (r$) 4) + (= (a$) 2) + (member k '(-2 -1 0 1 2))) + (and (<= (sel-lower-div k (d$)) + (max (sel-lower-div k 63/64) + (sel-lower-div k 9/8))) + (>= (sel-upper-div k (d$)) + (min (sel-upper-div k 63/64) + (sel-upper-div k 9/8)))))) + +(defthmd sel-limits-check-4 + (implies (and (<= 63/64 (d$)) + (<= (d$) 9/8) + (= (r$) 4) + (= (a$) 2) + (member k '(-1 0 1 2))) + (and (<= (+ (max (sel-lower-div k 63/64) (sel-lower-div k 9/8)) 1/8) + (md4 k)) + (>= (min (sel-upper-div k 63/64) (sel-upper-div k 9/8)) + (md4 k))))) + +(defthmd md4-k-bounds + (implies (and (<= 63/64 (d$)) + (<= (d$) 9/8) + (= (r$) 4) + (= (a$) 2)) + (and (implies (member k '(-1 0 1 2)) + (<= (+ (sel-lower-div k (d$)) 1/8) + (md4 k))) + (implies (member k '(-2 -1 0 1)) + (>= (sel-upper-div k (d$)) + (md4 (1+ k))))))) + +(defthmd srt-div-rad-4 + (implies (and (= (r$) 4) + (= (a$) 2) + (<= 63/64 (d$)) + (<= (d$) 9/8) + (natp j) + (<= (abs (rem$ j)) (* 2/3 (d$))) + (rationalp approx) + (integerp (* 8 approx)) + (< (abs (- approx (* 4 (rem$ j)))) 1/8) + (= (q$ (1+ j)) (select-digit-d4 approx))) + (<= (abs (rem$ (1+ j))) (* 2/3 (d$))))) + +;;------------------------------------------------------------------------------------------------------------------ +;; Minimally Redundant Radix-8 Division +;;------------------------------------------------------------------------------------------------------------------ + +(defun md8*64 (k i) + (case (fl (/ i 2)) + (0 (case k (4 (if (= i 0) 113 115)) (3 82) (2 50) (1 16) (0 -16) (-1 -48) (-2 -81) (-3 (if (= i 0) -112 -114)))) + (1 (case k (4 (if (= i 2) 117 118)) (3 84) (2 50) (1 16) (0 -16) (-1 -50) (-2 -83) (-3 (if (= i 2) -116 -117)))) + (2 (case k (4 121) (3 86) (2 52) (1 16) (0 -16) (-1 -52) (-2 -86) (-3 -120))) + (3 (case k (4 125) (3 90) (2 54) (1 18) (0 -18) (-1 -54) (-2 -88) (-3 -124))) + (4 (case k (4 128) (3 92) (2 54) (1 18) (0 -18) (-1 -54) (-2 -90) (-3 -127))) + (5 (case k (4 132) (3 94) (2 56) (1 18) (0 -18) (-1 -56) (-2 -94) (-3 -131))) + (6 (case k (4 135) (3 96) (2 58) (1 18) (0 -18) (-1 -58) (-2 -96) (-3 -134))) + (7 (case k (4 139) (3 100) (2 60) (1 20) (0 -20) (-1 -60) (-2 -98) (-3 -138))) + (8 (case k (4 142) (3 102) (2 60) (1 20) (0 -20) (-1 -60) (-2 -100) (-3 -141))) + (9 (case k (4 146) (3 104) (2 62) (1 20) (0 -20) (-1 -62) (-2 -104) (-3 -144))) + (10 (case k (4 150) (3 106) (2 64) (1 20) (0 -20) (-1 -64) (-2 -106) (-3 -148))) + (11 (case k (4 152) (3 108) (2 64) (1 20) (0 -20) (-1 -64) (-2 -108) (-3 -152))) + (12 (case k (4 156) (3 112) (2 66) (1 22) (0 -22) (-1 -66) (-2 -112) (-3 -156))) + (13 (case k (4 160) (3 114) (2 68) (1 22) (0 -22) (-1 -68) (-2 -114) (-3 -158))) + (14 (case k (4 164) (3 116) (2 70) (1 24) (0 -24) (-1 -70) (-2 -116) (-3 -162))) + (15 (case k (4 166) (3 118) (2 70) (1 24) (0 -24) (-1 -70) (-2 -118) (-3 -166))) + (16 (case k (4 170) (3 120) (2 72) (1 24) (0 -24) (-1 -72) (-2 -120) (-3 -170))) + (17 (case k (4 173) (3 124) (2 73) (1 24) (0 -24) (-1 -72) (-2 -124) (-3 -172))) + (18 (case k (4 176) (3 126) (2 76) (1 24) (0 -24) (-1 -76) (-2 -124) (-3 -176))) + (19 (case k (4 180) (3 128) (2 76) (1 24) (0 -24) (-1 -76) (-2 -128) (-3 -180))) + (20 (case k (4 184) (3 132) (2 78) (1 24) (0 -24) (-1 -78) (-2 -132) (-3 -184))) + (21 (case k (4 188) (3 134) (2 80) (1 28) (0 -28) (-1 -80) (-2 -134) (-3 -188))) + (22 (case k (4 190) (3 136) (2 82) (1 28) (0 -28) (-1 -82) (-2 -136) (-3 -190))) + (23 (case k (4 194) (3 138) (2 82) (1 28) (0 -28) (-1 -82) (-2 -138) (-3 -194))) + (24 (case k (4 198) (3 140) (2 84) (1 28) (0 -28) (-1 -84) (-2 -140) (-3 -198))) + (25 (case k (4 200) (3 142) (2 84) (1 28) (0 -28) (-1 -84) (-2 -142) (-3 -200))) + (26 (case k (4 204) (3 146) (2 86) (1 28) (0 -28) (-1 -86) (-2 -146) (-3 -204))) + (27 (case k (4 208) (3 148) (2 88) (1 28) (0 -28) (-1 -88) (-2 -148) (-3 -208))) + (28 (case k (4 212) (3 152) (2 90) (1 28) (0 -28) (-1 -90) (-2 -152) (-3 -212))) + (29 (case k (4 214) (3 152) (2 90) (1 28) (0 -28) (-1 -90) (-2 -152) (-3 -214))) + (30 (case k (4 218) (3 154) (2 94) (1 28) (0 -28) (-1 -94) (-2 -154) (-3 -218))) + (31 (case k (4 222) (3 158) (2 94) (1 32) (0 -32) (-1 -94) (-2 -158) (-3 -222))))) + +(defund md8 (k i) + (/ (md8*64 k i) 64)) + +(defund max-lower (i k) + (max (sel-lower-div k (+ 1/2 (/ i 128))) + (sel-lower-div k (+ 1/2 (/ (1+ i) 128))))) + +(defund min-upper (i k) + (min (sel-upper-div k (+ 1/2 (/ i 128))) + (sel-upper-div k (+ 1/2 (/ (1+ i) 128))))) + +(defthmd sel-limits-check-8 + (implies (and (= (r$) 8) + (= (a$) 4) + (bvecp i 6) + (member k '(-3 -2 -1 0 1 2 3 4))) + (and (<= (+ (max-lower i k) 1/64) + (md8 k i)) + (>= (min-upper i (1- k)) + (md8 k i))))) + +(defund i64 (d) (fl (* 128 (- d 1/2)))) + +(defthmd sel-limits-8 + (implies (and (= (r$) 8) + (= (a$) 4) + (<= 1/2 (d$)) + (< (d$) 1) + (member k '(-4 -3 -2 -1 0 1 2 3 4))) + (and (<= (sel-lower-div k (d$)) + (max-lower (i64 (d$)) k)) + (>= (sel-upper-div k (d$)) + (min-upper (i64 (d$)) k))))) + +(defthmd md8-k-bounds + (implies (and (= (r$) 8) + (= (a$) 4) + (<= 1/2 (d$)) + (< (d$) 1)) + (and (implies (member k '(-3 -2 -1 0 1 2 3 4)) + (<= (+ (sel-lower-div k (d$)) 1/64) + (md8 k (i64 (d$))))) + (implies (member k '(-4 -3 -2 -1 0 1 2 3)) + (>= (sel-upper-div k (d$)) + (md8 (1+ k) (i64 (d$)))))))) + +(defund select-digit-d8 (a i) + (cond ((<= (md8 4 i) a) 4) + ((<= (md8 3 i) a) 3) + ((<= (md8 2 i) a) 2) + ((<= (md8 1 i) a) 1) + ((<= (md8 0 i) a) 0) + ((<= (md8 -1 i) a) -1) + ((<= (md8 -2 i) a) -2) + ((<= (md8 -3 i) a) -3) + (t -4))) + +(defthmd srt-div-rad-8 + (implies (and (= (r$) 8) + (= (a$) 4) + (<= 1/2 (d$)) + (< (d$) 1) + (natp j) + (<= (abs (rem$ j)) (* 4/7 (d$))) + (rationalp approx) + (integerp (* 64 approx)) + (< (abs (- approx (* 8 (rem$ j)))) 1/64) + (= (q$ (1+ j)) (select-digit-d8 approx (i64 (d$))))) + (<= (abs (rem$ (1+ j))) (* 4/7 (d$))))) + +) + +;;********************************************************************************** +;; SRT Square Root Extraction +;;********************************************************************************** + +(defsection-rtl |SRT Square Root Extraction| |SRT Division and Square Root| + +(encapsulate (((e%) => *) ((x%) => *) ((a%) => *) ((q% *) => *)) + (local (defun e% () 2)) + (local (defun x% () 1/2)) + (local (defun a% () 2)) + (local (defun q% (j) (declare (ignore j)) 0)) + (defund r% () (expt 2 (e%))) + (defund rho% () (/ (a%) (1- (r%)))) + (defthmd e%-constraint + (not (zp (e%)))) + (defthmd x%-constraint + (and (rationalp (x%)) + (<= 1/4 (x%)) + (< (x%) 1))) + (defthmd a%-constraint + (not (zp (a%)))) + (defthm q%-constraint + (implies (not (zp j)) + (and (integerp (q% j)) + (<= (abs (q% j)) (a%)))) + :rule-classes + ((:type-prescription + :corollary + (implies (not (zp j)) + (integerp (q% j)))) + (:linear + :corollary + (implies (not (zp j)) + (and (<= (- (a%)) (q% j)) + (<= (q% j) (a%))))))) + (defthmd rho%-constraint + (and (< 1/2 (rho%)) + (<= (rho%) 1)))) + +(defund quot% (j) + (if (zp j) + 1 + (+ (quot% (1- j)) + (* (q% j) (expt (r%) (- j)))))) + +(defund rem% (j) + (* (expt (r%) j) + (- (x%) (* (quot% j) (quot% j))))) + +(defthmd int-quot-sqrt + (implies (natp j) + (integerp (* (expt (r%) j) (quot% j))))) + +(defthmd rem0-sqrt-rewrite + (equal (rem% 0) (1- (x%)))) + +(defthmd rem-sqrt-recurrence + (implies (natp j) + (equal (rem% (+ 1 j)) + (- (* (r%) (rem% j)) + (* (q% (1+ j)) + (+ (* 2 (quot% j)) + (* (expt (r%) (- (1+ j))) + (q% (1+ j))))))))) + +(defund blo% (j) + (+ (* -2 (rho%) (quot% j)) + (* (rho%) (rho%) (expt (r%) (- j))))) + +(defund bhi% (j) + (+ (* 2 (rho%) (quot% j)) + (* (rho%) (rho%) (expt (r%) (- j))))) + +(defthm blohi + (implies (natp j) + (iff (and (<= (expt (- (quot% j) (* (rho%) (expt (r%) (- j)))) 2) + (x%)) + (>= (expt (+ (quot% j) (* (rho%) (expt (r%) (- j)))) 2) + (x%))) + (and (<= (blo% j) (rem% j)) + (>= (bhi% j) (rem% j))))) + :rule-classes ()) + +(defthmd rem0-sqrt-bounds + (and (<= (blo% 0) (rem% 0)) + (>= (bhi% 0) (rem% 0)))) + +(defund sel-upper-sqrt (k j) + (+ (* 2 (+ k (rho%)) (quot% j)) + (* (+ k (rho%)) (+ k (rho%)) (expt (r%) (- (1+ j)))))) + +(defund sel-lower-sqrt (k j) + (+ (* 2 (- k (rho%)) (quot% j)) + (* (- k (rho%)) (- k (rho%)) (expt (r%) (- (1+ j)))))) + +(defthm rem-sqrt-bnds-next + (implies (and (natp j) + (<= (sel-lower-sqrt (q% (1+ j)) j) + (* (r%) (rem% j))) + (>= (sel-upper-sqrt (q% (1+ j)) j) + (* (r%) (rem% j)))) + (and (<= (blo% (1+ j)) + (rem% (1+ j))) + (>= (bhi% (1+ j)) + (rem% (1+ j))))) + :rule-classes ()) + +(defthmd sqrt-containment + (implies (natp j) + (and (equal (sel-upper-sqrt (a%) j) (* (r%) (bhi% j))) + (equal (sel-lower-sqrt (- (a%)) j) (* (r%) (blo% j)))))) + +;;------------------------------------------------------------------------------------------------------------------ +;; Minimally Redundant Radix-4 Square Root +;;------------------------------------------------------------------------------------------------------------------ + +(defun ms4*8 (i j k) + (case i + (0 (case k + (2 12) + (1 4) + (0 -4) + (-1 (if (= j 1) -11 -12)))) + (1 (case k + (2 (if (= j 2) 15 13)) + (1 4) + (0 -4) + (-1 -13))) + (2 (case k + (2 15) + (1 4) + (0 -4) + (-1 -15))) + (3 (case k + (2 16) + (1 6) + (0 -6) + (-1 -16))) + (4 (case k + (2 18) + (1 6) + (0 -6) + (-1 -18))) + (5 (case k + (2 20) + (1 8) + (0 -6) + (-1 -20))) + (6 (case k + (2 20) + (1 8) + (0 -8) + (-1 -20))) + (7 (case k + (2 22) + (1 8) + (0 -8) + (-1 -22))) + (8 (case k + (2 24) + (1 8) + (0 -8) + (-1 (if (= j 0) -20 -24)))))) + +(defund ms4 (i j k) + (/ (ms4*8 i j k) 8)) + +(defund i% (j) + (* 16 (- (quot% (min (nfix j) 2)) 1/2))) + +(defund select-digit-s4 (a i j) + (cond ((<= (ms4 i j 2) a) 2) + ((<= (ms4 i j 1) a) 1) + ((<= (ms4 i j 0) a) 0) + ((<= (ms4 i j -1) a) -1) + (t -2))) + +(defund quot%-bnds-inv (j) + (and (<= 1/2 (quot% j)) + (>= 1 (quot% j)))) + +(defund rem%-bnds-inv (j) + (and (<= (blo% j) (rem% j)) + (>= (bhi% j) (rem% j)))) + +(encapsulate (((approx% *) => *)) + (local (defun approx% (j) (* 4 (rem% j)))) + (defthm ratp-approx% + (rationalp (approx% j)) + :rule-classes (:type-prescription :rewrite))) + +(defund approx%-bounds (j k) + (and (implies (< (approx% j) (ms4 (i% j) j k)) + (< (* 4 (rem% j)) (ms4 (i% j) j k))) + (implies (>= (approx% j) (ms4 (i% j) j k)) + (> (* 4 (rem% j)) (- (ms4 (i% j) j k) 1/32))))) + +(defund approx%-inv (j) + (and (= (q% (1+ j)) (select-digit-s4 (approx% j) (i% j) j)) + (approx%-bounds j 2) + (approx%-bounds j 1) + (approx%-bounds j 0) + (approx%-bounds j -1))) + +(defund s4-inv (j) + (and (quot%-bnds-inv j) + (rem%-bnds-inv j) + (approx%-inv j))) + +(defund s4-hyp (j) + (if (zp j) + (s4-inv 0) + (and (s4-inv j) + (s4-hyp (1- j))))) + +(defthmd srt-sqrt-rad-4 + (implies (and (= (r%) 4) + (= (a%) 2) + (natp j) + (s4-hyp j)) + (and (quot%-bnds-inv (1+ j)) + (rem%-bnds-inv (1+ j))))) + +;;------------------------------------------------------------------------------------------------------------------ + +(defun ms8-0 (k) + (nth (- 1 k) '(0 -64 -176 -272 -352))) + +(defun ms8-1 (i k) + (nth (- 4 k) (nth (/ i 8) '((236 166 96 31 -32 -92 -152 -212) + (291 206 121 41 -42 -122 -192 -267) + (351 241 141 46 -47 -142 -232 -322) + (406 281 171 61 -62 -172 -277 -377) + (461 326 191 61 -62 -192 -317 -442))))) + +(defun ms8-2 (i k) + (nth (- 4 k) (nth i '((226 161 97 32 -32 -97 -161 -226) + (231 165 99 33 -33 -99 -165 -231) + (238 170 102 34 -34 -102 -170 -238) + (245 175 105 35 -35 -105 -175 -245) + (252 180 108 36 -36 -108 -180 -252) + (259 185 112 37 -37 -112 -185 -259) + (266 190 114 38 -38 -114 -190 -266) + (273 195 117 39 -39 -117 -195 -273) + (280 200 120 40 -40 -120 -200 -280) + (287 205 123 41 -41 -123 -205 -287) + (294 210 128 42 -42 -128 -210 -294) + (301 215 129 43 -43 -129 -215 -301) + (308 220 132 44 -44 -132 -220 -308) + (315 225 135 45 -45 -135 -225 -315) + (322 230 138 48 -48 -138 -230 -322) + (329 235 141 48 -48 -141 -235 -329) + (336 240 144 48 -48 -144 -240 -336) + (343 245 147 49 -49 -147 -245 -343) + (350 250 150 50 -50 -150 -250 -350) + (357 255 153 51 -51 -153 -255 -357) + (364 260 156 52 -52 -156 -260 -364) + (371 265 160 53 -53 -160 -265 -371) + (378 270 162 54 -54 -162 -270 -378) + (385 275 165 55 -55 -165 -275 -385) + (392 280 168 56 -56 -168 -280 -392) + (398 285 171 57 -57 -171 -285 -398) + (406 290 174 58 -58 -174 -290 -406) + (413 295 177 59 -59 -177 -295 -413) + (420 300 180 60 -60 -180 -300 -420) + (427 305 183 61 -61 -183 -305 -427) + (434 310 186 62 -62 -186 -310 -434) + (441 315 189 64 -64 -189 -315 -441) + (447 319 191 64 -64 -191 -319 -447))))) + +(defun ms8*64 (i j k) + (case j + (0 (ms8-0 k)) + (1 (ms8-1 i k)) + (t (ms8-2 i k)))) + +(defund ms8 (i j k) + (/ (ms8*64 i j k) 64)) + +(defund select-digit-s8 (a i j) + (cond ((<= (ms8 i j 4) a) 4) + ((<= (ms8 i j 3) a) 3) + ((<= (ms8 i j 2) a) 2) + ((<= (ms8 i j 1) a) 1) + ((<= (ms8 i j 0) a) 0) + ((<= (ms8 i j -1) a) -1) + ((<= (ms8 i j -2) a) -2) + ((<= (ms8 i j -3) a) -3) + (t -4))) + +(defund i8% (j) + (* 64 (- (quot% (min (nfix j) 2)) 1/2))) + +(defund quot%-bnds-inv (j) + (and (<= 1/2 (quot% j)) + (>= 1 (quot% j)))) + +(defund rem%-bnds-inv (j) + (and (<= (blo% j) (rem% j)) + (>= (bhi% j) (rem% j)))) + +(encapsulate (((approx8% *) => *)) + (local (defun approx8% (j) (* 8 (rem% j)))) + (defthm ratp-approx8% + (rationalp (approx8% j)) + :rule-classes (:type-prescription :rewrite)) + (defthm approx8%-0 + (equal (approx8% 0) (* 8 (rem% 0))))) + +(defund approx8%-bounds (j k) + (and (implies (< (approx8% j) (ms8 (i8% j) j k)) + (< (* 8 (rem% j)) (ms8 (i8% j) j k))) + (implies (>= (approx8% j) (ms8 (i8% j) j k)) + (> (* 8 (rem% j)) (- (ms8 (i8% j) j k) 1/128))))) + +(defund approx8%-inv (j) + (and (= (q% (1+ j)) (select-digit-s8 (approx8% j) (i8% j) j)) + (approx8%-bounds j 4) + (approx8%-bounds j 3) + (approx8%-bounds j 2) + (approx8%-bounds j 1) + (approx8%-bounds j 0) + (approx8%-bounds j -1) + (approx8%-bounds j -2) + (approx8%-bounds j -3))) + +(defund s8-inv (j) + (and (quot%-bnds-inv j) + (rem%-bnds-inv j) + (approx8%-inv j))) + +(defund s8-hyp (j) + (if (zp j) + (s8-inv 0) + (and (s8-inv j) + (s8-hyp (1- j))))) + +(defthmd srt-sqrt-rad-8 + (implies (and (= (r%) 8) + (= (a%) 4) + (natp j) + (s8-hyp j)) + (and (quot%-bnds-inv (1+ j)) + (rem%-bnds-inv (1+ j)))) + :hints (("Goal" :use (rem%-8-bnds quot8%-bnds)))) + +) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/top-alt.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/top-alt.lisp new file mode 100644 index 000000000..76565ad5f --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/top-alt.lisp @@ -0,0 +1,79 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; Copyright (C) 1995-2013 Advanced Mirco Devices, Inc. +; +; Contact: +; David Russinoff +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; +; Author: David M. Russinoff (david@russinoff.com) + +(in-package "RTL") + +(set-enforce-redundancy t) + +; Optionally, one may wish to consider: +; (include-book "../../../misc/rtl-untranslate") +; to inhibit expansion of macros in proof output. + +(include-book "doc") + +;; These books are useful for most floating-point applications: + +(include-book "basic") ;basic arithmetic functions: floor, ceiling, and mod + +(include-book "bits") ;bit vectors + +(include-book "log") ;logical operations + +(include-book "float") ;floating-point numbers + +(include-book "reps") ;floating-point formats and representations + +(include-book "round") ;floating-point rounding + +;; Special-purpose theories: + +(include-book "sqrt") ;approximation to square root + +(include-book "add") ;support for reasoning about addition + +(include-book "mult") ;integer multiplication + +(include-book "srt") ;SRT division and square root + +(include-book "div") ;Newton-Raphson division + +(include-book "excps") ;specifications of elementary arithmetic operastions (SSE, x87, Arm) + +;; Miscellaneous helpful stuff including a few macros; + +(include-book "util") + +;; This is relevant to code derived from C++: + +(include-book "rac") + +;; This must be included to use GL with this library: + +(include-book "gl") + +;; We can't do much without some arithmetic book. Currently, the best choice +;; is probably this: + +;;(include-book "arithmetic-5/top" :dir :system) + +;; Unfortunately, there are some conflicts between arithmetic-5 and this library +;; (especially the "basic" book) that can severely slow down some proofs. Much of +;; this can be avoided by disabling the following lemmas: + +;; (in-theory #!acl2(disable |(mod (+ x y) z) where (<= 0 z)| |(mod (+ x (- (mod a b))) y)| +;; |(mod (mod x y) z)| |(mod (+ x (mod a b)) y)| mod-cancel-*-const +;; cancel-mod-+ reduce-additive-constant-< ash-to-floor |(floor x 2)| +;; |(equal x (if a b c))| |(equal (if a b c) x)| |(logior 1 x)| +;; mod-theorem-one-b |(mod (- x) y)|)) + + + + diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/top-doc.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/top-doc.lisp new file mode 100644 index 000000000..0522f0864 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/top-doc.lisp @@ -0,0 +1,46 @@ +; Copyright (C) 2018 Centaur Technology +; +; Contact: +; Centaur Technology Formal Verification Group +; 7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA. +; http://www.centtech.com/ +; +; License: (An MIT/X11-style license) +; +; Permission is hereby granted, free of charge, to any person obtaining a +; copy of this software and associated documentation files (the "Software"), +; to deal in the Software without restriction, including without limitation +; the rights to use, copy, modify, merge, publish, distribute, sublicense, +; and/or sell copies of the Software, and to permit persons to whom the +; Software is furnished to do so, subject to the following conditions: +; +; The above copyright notice and this permission notice shall be included in +; all copies or substantial portions of the Software. +; +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +; DEALINGS IN THE SOFTWARE. +; +; Original author (this file): Sol Swords + +(in-package "RTL") + +(include-book "xdoc/archive-matching-topics" :dir :system) + +(local + (progn + (include-book "rtl/rel11/lib/top" :dir :system) +; And books not included in lib/top: + (include-book "rtl/rel11/lib/add" :dir :system) + (include-book "rtl/rel11/lib/mult" :dir :system) + (include-book "rtl/rel11/lib/div" :dir :system) + (include-book "rtl/rel11/lib/srt" :dir :system) + (include-book "rtl/rel11/lib/sqrt" :dir :system))) + +(xdoc::archive-matching-topics + (str::strprefixp "rtl/" (cdr (assoc :from x)))) + diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/top.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/top.lisp new file mode 100644 index 000000000..c250fe6a0 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/top.lisp @@ -0,0 +1,79 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; Copyright (C) 1995-2013 Advanced Mirco Devices, Inc. +; +; Contact: +; David Russinoff +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; +; Author: David M. Russinoff (david@russinoff.com) + +(in-package "RTL") + +(set-enforce-redundancy t) + +; Optionally, one may wish to consider: +; (include-book "../../../misc/rtl-untranslate") +; to inhibit expansion of macros in proof output. + +(include-book "doc") + +;; These books are useful for most floating-point applications: + +(include-book "basic") ;basic arithmetic functions: floor, ceiling, and mod + +(include-book "bits") ;bit vectors + +(include-book "log") ;logical operations + +(include-book "float") ;floating-point numbers + +(include-book "reps") ;floating-point formats and representations + +(include-book "round") ;floating-point rounding + +;; Special-purpose theories: + +(include-book "sqrt") ;approximation to square root + +(include-book "add") ;support for reasoning about addition + +(include-book "mult") ;integer multiplication + +(include-book "srt") ;SRT division and square root + +(include-book "div") ;Newton-Raphson division + +(include-book "excps") ;specifications of elementary arithmetic operations (SSE, x87, Arm) + +;; Miscellaneous helpful stuff including a few macros; + +(include-book "util") + +;; This is relevant to code derived from C++: + +(include-book "rac") + +;; This must be included to use GL with this library: + +(include-book "gl") + +;; We can't do much without some arithmetic book. Currently, the best choice +;; is probably this: + +(include-book "arithmetic-5/top" :dir :system) + +;; Unfortunately, there are some conflicts between arithmetic-5 and this library +;; (especially the "basic" book) that can severely slow down some proofs. Much of +;; this can be avoided by disabling the following lemmas: + +(in-theory #!acl2(disable |(mod (+ x y) z) where (<= 0 z)| |(mod (+ x (- (mod a b))) y)| + |(mod (mod x y) z)| |(mod (+ x (mod a b)) y)| mod-cancel-*-const + cancel-mod-+ reduce-additive-constant-< ash-to-floor |(floor x 2)| + |(equal x (if a b c))| |(equal (if a b c) x)| |(logior 1 x)| + mod-theorem-one-b |(mod (- x) y)|)) + + + + diff --git a/crates/clazel-x64/tests/data/acl2-rtl/lib/util.lisp b/crates/clazel-x64/tests/data/acl2-rtl/lib/util.lisp new file mode 100644 index 000000000..526de184e --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/lib/util.lisp @@ -0,0 +1,197 @@ +; RTL - A Formal Theory of Register-Transfer Logic and Computer Arithmetic +; Copyright (C) 1995-2013 Advanced Mirco Devices, Inc. +; +; Contact: +; David Russinoff +; http://www.russinoff.com/ +; +; See license file books/rtl/rel11/license.txt. +; +; Author: David M. Russinoff (david@russinoff.com) + +(in-package "RTL") + +(set-enforce-redundancy t) + +(local (include-book "../support/top")) + +(include-book "../localize-macros") + +(defmacro defbvecp (name formals width &key thm-name hyp hints) + (let* ((thm-name + (or thm-name + (intern-in-package-of-symbol + (concatenate 'string + (if (consp width) + "BV-ARRP$" + "BVECP$") + (symbol-name name)) + name))) + (x (cons name formals)) + (typed-term (if (consp width) + (list 'ag 'index x) + x)) + (bvecp-concl (if (consp width) + (list 'bv-arrp x (car (last width))) + (list 'bvecp x width))) + (concl (list 'and + (list 'integerp typed-term) + (list '<= 0 typed-term)))) + (list* 'defthm thm-name + (if hyp + (list 'implies hyp bvecp-concl) + bvecp-concl) + :rule-classes + (list + :rewrite + (list :forward-chaining :trigger-terms (list x)) + (list :type-prescription + :corollary + (if hyp + (list 'implies hyp concl) + concl) + :typed-term typed-term + ;; hints for the corollary + :hints + (if (consp width) + '(("Goal" + :in-theory + '(implies bvecp + bv-arrp-implies-nonnegative-integerp))) + '(("Goal" + :in-theory + '(implies bvecp)))))) + (if hints (list :hints hints) nil)))) + +(defun sub1-induction (n) + (if (zp n) + n + (sub1-induction (1- n)))) + +; These will be the functions to disable in acl2 proofs about signal bodies. +; We use this in the compiler. + +(defconst *rtl-operators-after-macro-expansion* + '(log= log<> + log< log<= log> log>= + comp2< comp2<= comp2> comp2>= + land lior lxor lnot + logand1 logior1 logxor1 + shft + cat mulcat + bits bitn setbits setbitn + ag as + * + ; from macroexpansion of mod* or mod+ + ;mod- ;now a macro! + floor rem decode encode + ;; bind ; handled specially in fixup-term + ;; if1 ; a macro, so we don't disable it + ;; quote, n!, arr0 ; handled specially in fixup-term + natp1 ; doesn't matter, only occurs in for-loop defuns (must be enabled in those proofs anyway) + mk-bvarr mk-bvec + )) + +; Macro fast-and puts conjunctions in a tree form, which can avoid stack +; overflows by ACL2's translate functions. + +(defun split-list (lst lo hi) + (cond ((endp lst) + (mv lo hi)) + ((endp (cdr lst)) + (mv (cons (car lst) lo) hi)) + (t + (split-list (cddr lst) + (cons (car lst) lo) + (cons (cadr lst) hi))))) + +(defun fast-and-fn (conjuncts) + (declare (xargs :mode :program)) + (cond ((endp conjuncts) ''t) + ((endp (cdr conjuncts)) (car conjuncts)) + (t + (mv-let (hi lo) + (split-list conjuncts () ()) + (list 'if + (fast-and-fn hi) + (fast-and-fn lo) + 'nil))))) + +(defmacro fast-and (&rest conjuncts) + (fast-and-fn conjuncts)) + +(defmacro defsig (name param body) + (declare (ignore param)) + (let ((realname (intern-in-package-of-symbol + (concatenate 'string + (symbol-name name) + "$") + name))) + `(progn (defund ,realname (n $path) + ,body) + (defmacro ,name (n) + (list ',realname n '$path)) + (add-macro-alias ,name ,realname)))) + +(defmacro defsigd (name params body) + (let ((realname (intern-in-package-of-symbol + (concatenate 'string (symbol-name name) "$") + name))) + `(progn (defund ,realname (,@params $path) + ,body) + (defmacro ,name ,params + (list ',realname ,@params '$path)) + (add-macro-alias ,name ,realname)))) + +(defmacro defthm-nl (&rest thm) + (declare (xargs :guard (and (true-listp thm) + (symbolp (car thm))))) + `(encapsulate + () + + (local (set-default-hints + '((nonlinearp-default-hint stable-under-simplificationp + hist pspv)))) + + (defthm ,@thm))) + +(defmacro defthmd-nl (&rest thm) + (declare (xargs :guard (and (true-listp thm) + (symbolp (car thm))))) + `(encapsulate + () + + (local (set-default-hints + '((nonlinearp-default-hint stable-under-simplificationp + hist pspv)))) + + (defthmd ,@thm))) + +(defmacro defthm-nl++ (&rest thm) + (declare (xargs :guard (and (true-listp thm) + (symbolp (car thm))))) + `(encapsulate + () + + (local + (set-default-hints + '((nonlinearp-default-hint++ id + stable-under-simplificationp + hist + nil)))) + + (defthm ,@thm))) + +(defmacro defthmd-nl++ (&rest thm) + (declare (xargs :guard (and (true-listp thm) + (symbolp (car thm))))) + `(encapsulate + () + + (local + (set-default-hints + '((nonlinearp-default-hint++ id + stable-under-simplificationp + hist + nil)))) + + (defthmd ,@thm))) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/package.lsp b/crates/clazel-x64/tests/data/acl2-rtl/package.lsp new file mode 100644 index 000000000..2a310f4a6 --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/package.lsp @@ -0,0 +1,37 @@ +; Copyright (C) 2015, ForrestHunt, Inc. +; Written by Matt Kaufmann, March, 2015 +; License: A 3-clause BSD license. See the LICENSE file distributed with ACL2. + +(in-package "ACL2") + +(include-book "std/portcullis" :dir :system) + +(defpkg "RTL" + (union-eq + (set-difference-eq *acl2-exports* +; Matt K. mod: sum$ is defined in books/projects/curve25519/. + '(sum$)) + *common-lisp-symbols-from-main-lisp-package* + STD::*std-exports* + '(local-defun local-defund local-defthm local-defthmd local-in-theory + defxdoc defsection + rtl ; simplifies dealing with this xdoc topic name + *default-step-limit* ; should perhaps be in *acl2-exports* + binary-logand binary-logior binary-logxor binary-logeqv ; used in lib/log.lisp + b* + const-fns-gen + expand-reduce-cp + alt-const-fns-gen + def-gl-rule + def-gl-thm + defundd + find-lemmas + loop-fns-gen + nonlinearp-default-hint + nonlinearp-default-hint++ + proof-by-arith + a b c d e f g h i j k l m n o p q r s t u v w x y z + a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 + n1 o1 p1 q1 r1 s1 t1 u1 v1 w1 x1 y1 z1 + a2 b2 c2 d2 e2 f2 g2 h2 i2 j2 k2 l2 m2 + n2 o2 p2 q2 r2 s2 t2 u2 v2 w2 x2 y2 z2))) diff --git a/crates/clazel-x64/tests/data/acl2-rtl/portcullis.lisp b/crates/clazel-x64/tests/data/acl2-rtl/portcullis.lisp new file mode 100644 index 000000000..91e0e5d1a --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-rtl/portcullis.lisp @@ -0,0 +1,7 @@ +; Copyright (C) 2015, ForrestHunt, Inc. +; Written by Matt Kaufmann, March, 2015 +; License: A 3-clause BSD license. See the LICENSE file distributed with ACL2. + +(in-package "ACL2") + +; See portcullis.acl2. diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md b/crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md index 6f37e4bbe..9436a4155 100644 --- a/crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md +++ b/crates/clazel-x64/tests/data/acl2-x86isa/SOURCE.md @@ -21,7 +21,10 @@ byte, with the paths relative to `books/projects/x86isa/` kept: `conditional` (`jcc`, `cmovcc`, `setcc`), `jump-and-loop` (`jmp`), `move`, `move-sse` (`movq`), `subroutine` (`ret`), `signextend`, `flags`; - `machine/instructions/fp/`: the SSE2 floating-point books (`addsd`, - `subsd`, `mulsd`, `divsd`, `sqrtsd`, `ucomisd` and the conversions). + `subsd`, `mulsd`, `divsd`, `sqrtsd`, `ucomisd` and the conversions), and + `logical.lisp`, which holds the `comisd`/`ucomisd` instruction + (`x86-comis?/ucomis?-Op/En-RM`). The arithmetic books call Russinoff's RTL + library, which is the suite `acl2-rtl`. Not vendored: the proofs (`proofs/`, 12.8 MB), the Linux and virtualization projects, the `.sys` caches, the x87, SSE integer, MMX, string, segmentation, diff --git a/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/logical.lisp b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/logical.lisp new file mode 100644 index 000000000..12228e2ea --- /dev/null +++ b/crates/clazel-x64/tests/data/acl2-x86isa/machine/instructions/fp/logical.lisp @@ -0,0 +1,560 @@ +; X86ISA Library + +; Note: The license below is based on the template at: +; http://opensource.org/licenses/BSD-3-Clause + +; Copyright (C) 2015, Regents of the University of Texas +; Copyright (C) 2018, Kestrel Technology, LLC +; All rights reserved. + +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: + +; o Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. + +; o Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. + +; o Neither the name of the copyright holders nor the names of its +; contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. + +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +; Original Author(s): +; Cuong Chau +; Contributing Author(s): +; Alessandro Coglio (www.alessandrocoglio.info) + +(in-package "X86ISA") + +;; ====================================================================== + +(include-book "../../decoding-and-spec-utils") +(include-book "cmp-spec") +(include-book "centaur/bitops/merge" :dir :system) + +(local (include-book "centaur/bitops/ihs-extensions" :dir :system)) + +(local + (defthm lemma-1 + (implies (and (unsigned-byte-p 128 x) + (unsigned-byte-p 128 y)) + (< (logxor x y) + (expt 2 128))) + :hints (("Goal" + :in-theory (disable unsigned-byte-p-of-logxor) + :use (:instance unsigned-byte-p-of-logxor + (n 128) (i x) (j y)))) + :rule-classes :linear)) + +;; ====================================================================== +;; INSTRUCTION: SSE/SSE2 Comparison Instructions +;; ====================================================================== + +(def-inst x86-cmpss/cmpsd-Op/En-RMI + + :parents (two-byte-opcodes fp-opcodes) + + :short "Compare scalar single/double precision floating-point values" + + :long + "

Op/En = RMI: \[OP XMM, XMM/M, IMM\]

+ F3 0F C2: CMPSS xmm1, xmm2/m32, imm8
+ F2 0F C2: CMPSD xmm1, xmm2/m64, imm8
" + + :sp/dp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) operand-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + (xmm (xmmi-size operand-size xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 3 + t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 1 ;; One-byte immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ((mv flg1 (the (unsigned-byte 8) imm) x86) + (rme-size-opt proc-mode 1 temp-rip #.*cs* :x nil x86 :mem-ptr? nil)) + ((when flg1) + (!!ms-fresh :imm-rme-size-error flg1)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg2 result (the (unsigned-byte 32) mxcsr)) + (if (equal sp/dp #.*OP-DP*) + (dp-sse-cmp (n03 imm) xmm xmm/mem (mxcsr x86)) + (sp-sse-cmp (n03 imm) xmm xmm/mem (mxcsr x86)))) + + ((when flg2) + (if (equal sp/dp #.*OP-DP*) + (!!ms-fresh :dp-sse-cmp flg2) + (!!ms-fresh :sp-sse-cmp flg2))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size operand-size xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86) + + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p))))) + +(def-inst x86-cmpps-Op/En-RMI + + :parents (two-byte-opcodes fp-opcodes) + + :short "Compare packed single-precision floating-point values" + + :long + "

Op/En = RMI: \[OP XMM, XMM/M, IMM\]

+ 0F C2: CMPPS xmm1, xmm2/m128, imm8
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 2 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 1 ;; One-byte immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ((mv flg1 (the (unsigned-byte 8) imm) x86) + (rme-size-opt proc-mode 1 + (the (signed-byte #.*max-linear-address-size*) temp-rip) + #.*cs* :x nil x86 :mem-ptr? nil)) + ((when flg1) + (!!ms-fresh :imm-rme-size-error flg1)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (xmm0 (mbe :logic (part-select xmm :low 0 :high 31) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF xmm)))) + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 31) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF xmm/mem)))) + + (xmm1 (mbe :logic (part-select xmm :low 32 :high 63) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm -32))))) + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 32 :high 63) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm/mem -32))))) + + (xmm2 (mbe :logic (part-select xmm :low 64 :high 95) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm -64))))) + (xmm/mem2 (mbe :logic (part-select xmm/mem :low 64 :high 95) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm/mem -64))))) + + (xmm3 (mbe :logic (part-select xmm :low 96 :high 127) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm -96))))) + (xmm/mem3 (mbe :logic (part-select xmm/mem :low 96 :high 127) + :exec (the (unsigned-byte 32) + (logand #uxFFFF_FFFF (ash xmm/mem -96))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + (operation (the (unsigned-byte 3) (n03 imm))) + + ((mv flg2 + (the (unsigned-byte 32) result0) + (the (unsigned-byte 32) mxcsr0)) + (sp-sse-cmp operation xmm0 xmm/mem0 mxcsr)) + + ((when flg2) + (!!ms-fresh :sp-sse-cmp flg2)) + + ((mv flg3 + (the (unsigned-byte 32) result1) + (the (unsigned-byte 32) mxcsr1)) + (sp-sse-cmp operation xmm1 xmm/mem1 mxcsr)) + + ((when flg3) + (!!ms-fresh :sp-sse-cmp flg3)) + + ((mv flg4 + (the (unsigned-byte 32) result2) + (the (unsigned-byte 32) mxcsr2)) + (sp-sse-cmp operation xmm2 xmm/mem2 mxcsr)) + + ((when flg4) + (!!ms-fresh :sp-sse-cmp flg4)) + + ((mv flg5 + (the (unsigned-byte 32) result3) + (the (unsigned-byte 32) mxcsr3)) + (sp-sse-cmp operation xmm3 xmm/mem3 mxcsr)) + + ((when flg5) + (!!ms-fresh :sp-sse-cmp flg5)) + + (result (merge-4-u32s result3 result2 result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1 mxcsr2 mxcsr3))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86) + + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p))))) + +(def-inst x86-cmppd-Op/En-RMI + + :parents (two-byte-opcodes fp-opcodes) + + :short "Compare packed double-precision floating-point values" + + :long + "

Op/En = RMI: \[OP XMM, XMM/M, IMM\]

+ 66 0F C2: CMPPD xmm1, xmm2/m128, imm8
" + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + + ((the (unsigned-byte 128) xmm) + (xmmi-size 16 xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 2 + nil) + ((mv flg0 + (the (unsigned-byte 128) xmm/mem) + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + 16 + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 1 ;; One-byte immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + ((mv flg1 (the (unsigned-byte 8) imm) x86) + (rme-size-opt proc-mode 1 + (the (signed-byte #.*max-linear-address-size*) temp-rip) + #.*cs* :x nil x86 :mem-ptr? nil)) + ((when flg1) + (!!ms-fresh :imm-rme-size-error flg1)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip 1 x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ;; Raise an error if addr is not 16-byte aligned. + ;; In case the second operand is an XMM register, addr = 0. + ((when (not (eql (mod addr 16) 0))) + (!!ms-fresh :memory-address-is-not-16-byte-aligned addr)) + + (xmm0 (mbe :logic (part-select xmm :low 0 :high 63) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF xmm)))) + (xmm/mem0 (mbe :logic (part-select xmm/mem :low 0 :high 63) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF xmm/mem)))) + + (xmm1 (mbe :logic (part-select xmm :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF (ash xmm -64))))) + (xmm/mem1 (mbe :logic (part-select xmm/mem :low 64 :high 127) + :exec (the (unsigned-byte 64) + (logand #uxFFFF_FFFF_FFFF_FFFF (ash xmm/mem -64))))) + + (mxcsr (the (unsigned-byte 32) (mxcsr x86))) + + (operation (the (unsigned-byte 3) (n03 imm))) + + ((mv flg2 + (the (unsigned-byte 64) result0) + (the (unsigned-byte 32) mxcsr0)) + (dp-sse-cmp operation xmm0 xmm/mem0 mxcsr)) + + ((when flg2) + (!!ms-fresh :dp-sse-cmp flg2)) + + ((mv flg3 + (the (unsigned-byte 64) result1) + (the (unsigned-byte 32) mxcsr1)) + (dp-sse-cmp operation xmm1 xmm/mem1 mxcsr)) + + ((when flg3) + (!!ms-fresh :dp-sse-cmp flg3)) + + (result (merge-2-u64s result1 result0)) + + (mxcsr (the (unsigned-byte 32) + (logior mxcsr0 mxcsr1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + (x86 (!xmmi-size 16 xmm-index result x86)) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86) + + :guard-hints (("Goal" :in-theory (e/d () (unsigned-byte-p))))) + +(def-inst x86-comis?/ucomis?-Op/En-RM + + :parents (two-byte-opcodes fp-opcodes) + + :short "Order/Unordered compare scalar single/double precision floating-point + values and set EFLAGS" + + :long + "

Op/En = RM: \[OP XMM, XMM/M\]

+ 0F 2E: UCOMISS xmm1, xmm2/m32
+ 0F 2F: COMISS xmm1, xmm2/m32
+ + 66 0F 2E: UCOMISD xmm1, xmm2/m64
+ 66 0F 2F: COMISD xmm1, xmm2/m64
" + + :operation t + + :sp/dp t + + :returns (x86 x86p :hyp (x86p x86)) + + :modr/m t + + :body + + (b* (((the (integer 4 8) operand-size) + (if (equal sp/dp #.*OP-DP*) 8 4)) + + ((the (unsigned-byte 4) xmm-index) + (reg-index reg rex-byte #.*r*)) + (xmm (xmmi-size operand-size xmm-index x86)) + + (p2 (prefixes->seg prefixes)) + (p4? (eql #.*addr-size-override* + (prefixes->adr prefixes))) + + (seg-reg (select-segment-register proc-mode p2 p4? mod r/m sib x86)) + + (inst-ac? ;; Exceptions Type 3 + t) + ((mv flg0 + xmm/mem + (the (integer 0 4) increment-RIP-by) + (the (signed-byte 64) ?v-addr) + x86) + (x86-operand-from-modr/m-and-sib-bytes proc-mode + #.*xmm-access* + operand-size + inst-ac? + nil ;; Not a memory pointer operand + seg-reg + p4? + temp-rip + rex-byte + r/m + mod + sib + 0 ;; No immediate operand + x86)) + ((when flg0) + (!!ms-fresh :x86-operand-from-modr/m-and-sib-bytes flg0)) + + ((mv flg (the (signed-byte #.*max-linear-address-size*) temp-rip)) + (add-to-*ip proc-mode temp-rip increment-RIP-by x86)) + ((when flg) (!!ms-fresh :rip-increment-error flg)) + + (badlength? (check-instruction-length start-rip temp-rip 0)) + ((when badlength?) + (!!fault-fresh :gp 0 :instruction-length badlength?)) ;; #GP(0) + + ((mv flg1 result (the (unsigned-byte 32) mxcsr)) + (if (equal sp/dp #.*OP-DP*) + (dp-sse-cmp operation xmm xmm/mem (mxcsr x86)) + (sp-sse-cmp operation xmm xmm/mem (mxcsr x86)))) + + ((when flg1) + (if (equal sp/dp #.*OP-DP*) + (!!ms-fresh :dp-sse-cmp flg1) + (!!ms-fresh :sp-sse-cmp flg1))) + + ;; Update the x86 state: + (x86 (!mxcsr mxcsr x86)) + + ;; Set ZF, PF, CF flags according to the comis?/ucomis? result. + (x86 + (case result + (0 (let* ((x86 (!flgi :cf 0 x86)) + (x86 (!flgi :pf 0 x86)) + (x86 (!flgi :zf 0 x86)) + (x86 (!flgi :af 0 x86)) + (x86 (!flgi :sf 0 x86)) + (x86 (!flgi :of 0 x86))) + x86)) + (1 (let* ((x86 (!flgi :cf 1 x86)) + (x86 (!flgi :pf 0 x86)) + (x86 (!flgi :zf 0 x86)) + (x86 (!flgi :af 0 x86)) + (x86 (!flgi :sf 0 x86)) + (x86 (!flgi :of 0 x86))) + x86)) + (7 (let* ((x86 (!flgi :cf 1 x86)) + (x86 (!flgi :pf 1 x86)) + (x86 (!flgi :zf 1 x86)) + (x86 (!flgi :af 0 x86)) + (x86 (!flgi :sf 0 x86)) + (x86 (!flgi :of 0 x86))) + x86)) + (otherwise ;; Must only be 4. + (let* ((x86 (!flgi :cf 0 x86)) + (x86 (!flgi :pf 0 x86)) + (x86 (!flgi :zf 1 x86)) + (x86 (!flgi :af 0 x86)) + (x86 (!flgi :sf 0 x86)) + (x86 (!flgi :of 0 x86))) + x86)))) + + (x86 (write-*ip proc-mode temp-rip x86))) + x86)) + +;; ====================================================================== diff --git a/crates/clazel-x64/tests/generated/acl2_rtl.rs b/crates/clazel-x64/tests/generated/acl2_rtl.rs new file mode 100644 index 000000000..32e4c3f7a --- /dev/null +++ b/crates/clazel-x64/tests/generated/acl2_rtl.rs @@ -0,0 +1,47 @@ +// @generated by `cargo xtask testdata` from tests/data/acl2-rtl/. +// Do not edit: `cargo xtask verify` fails if this differs from what the +// converter (xtask/src/testdata/isa.rs) produces. +// Source, commit and license: tests/data/acl2-rtl/SOURCE.md. +// +// Russinoff's RTL library, the floating-point definitions acl2-x86isa's SSE books call. +// 24 files, 301839 bytes. Nothing here is parsed yet; see the converter's +// header for why. Paths are relative to tests/data/acl2-rtl/. + +/// One vendored file. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct File { + /// Its path under the suite directory, with `/` separators. + pub path: &'static str, + /// Its size in bytes. + pub size: u64, + /// Its SHA-256, in lower-case hex. + pub sha256: &'static str, +} + +/// Every vendored file, sorted by path. +pub const FILES: &[File] = &[ + File { path: "LICENSE.md", size: 1920, sha256: "8ea177065a9bb96c5d0d566df2df39c42735787f1b4e9d378f98390d38e85c62" }, + File { path: "lib/add.lisp", size: 16271, sha256: "608a232c3cb4a122f4a3bd7d9887e357416f51a539c3ca2266eb68c9ad3f6498" }, + File { path: "lib/basic.lisp", size: 15187, sha256: "e89679fa551119c1f1fc3c8af41f8c64bd22979c9f2ea7a2d0753a4a0d0b492e" }, + File { path: "lib/bits.lisp", size: 28564, sha256: "e39da3728e6e2190815366e09f6bd49c33fb0818ebc86c01d94b0358aa3f216e" }, + File { path: "lib/defs.lisp", size: 14485, sha256: "fed508ebeb9fe6f89c368d49eb217fb0decb29de7ebc8f403e4c7c18d5600c95" }, + File { path: "lib/div.lisp", size: 12028, sha256: "9a5c01091d87ab874ad31aa1cbcb97a7a6ab23c481d221aea75fb41d2fab92c1" }, + File { path: "lib/doc.lisp", size: 8622, sha256: "0b0fb8891b6fc4e1a51c6ae758c0e5e9672fd0dbb8d2674359574ddd3e340dee" }, + File { path: "lib/excps.lisp", size: 40527, sha256: "f056ae5f00365b8174893fdcb7f16ab92e990138c5466998dfbbf4fa98134089" }, + File { path: "lib/float.lisp", size: 12252, sha256: "cb08592bc754f16aef537440c6a048a00713d36ca5f9522d21d653cadc47ef3f" }, + File { path: "lib/gl.lisp", size: 2605, sha256: "bd53925cffdd34fbccbdba3cfd2e388bfcf755dfa17b93b054e162594ba879c5" }, + File { path: "lib/log.lisp", size: 14485, sha256: "6446ff07ed2992300f2b9d6df55d734fdc213fbc0095c46fbc12d29efd826533" }, + File { path: "lib/mult.lisp", size: 15348, sha256: "21ab2f30f8e96fd8df8ba5056b1b76559955d142666728ccee493401dc136715" }, + File { path: "lib/rac.lisp", size: 8124, sha256: "d6acfc66d5a8d1f4127948fe44346d7c0b3f825c844f587f19b3902cebb11630" }, + File { path: "lib/rcp.lisp", size: 3042, sha256: "3b68bd732bbca50e8ea1c305f9f58c59a97528e14e6b3a2ed92d406b86e25cb3" }, + File { path: "lib/reps.lisp", size: 12024, sha256: "69f4cf258f089ffb3d16bcebe7f46cfd076efae66c51913dd516ae5d01a2c69a" }, + File { path: "lib/round.lisp", size: 52711, sha256: "1e60cbc7104ae3c34dec23ef39302a4a2193afc5b77c39413398b9357e06c0cf" }, + File { path: "lib/sqrt.lisp", size: 9040, sha256: "cd3d7b6d15a5cf5334959e5983c259c3a014fa7d306bca56f6785028b0f7205b" }, + File { path: "lib/srt.lisp", size: 20694, sha256: "e68edc24714e83b982fe3c58b29c730603329972261414089c8e67c2f3d9bdd0" }, + File { path: "lib/top-alt.lisp", size: 2248, sha256: "1431955c1787a3f9a36d7fd072920063f13e4d22ad2436690091f97d67501749" }, + File { path: "lib/top-doc.lisp", size: 1924, sha256: "bd6d660a676538e74f5411d52364b95bb714229a655525cba886033591bee916" }, + File { path: "lib/top.lisp", size: 2230, sha256: "f0c380dc4dccb0dc894c39c66aeb936023089430371b545faf180d7308e0792f" }, + File { path: "lib/util.lisp", size: 6058, sha256: "1d5a6fbe2c31f1de776cfb24c8de904ff3430483898a8c9cd5aebf85026350a1" }, + File { path: "package.lsp", size: 1245, sha256: "314a89c56a1f8339447bde0bb0693a008a88308f75978d15056e8f556368afcb" }, + File { path: "portcullis.lisp", size: 205, sha256: "4b366f262eb4d507d26b0a05d27506ec7a9922ff0b82a8e778e702aa99849188" }, +]; diff --git a/crates/clazel-x64/tests/generated/acl2_x86isa.rs b/crates/clazel-x64/tests/generated/acl2_x86isa.rs index add76bc18..0a2e55f88 100644 --- a/crates/clazel-x64/tests/generated/acl2_x86isa.rs +++ b/crates/clazel-x64/tests/generated/acl2_x86isa.rs @@ -4,7 +4,7 @@ // Source, commit and license: tests/data/acl2-x86isa/SOURCE.md. // // ACL2 x86isa model files for the subset of jit.md item J.3. -// 63 files, 2498309 bytes. Nothing here is parsed yet; see the converter's +// 64 files, 2518719 bytes. Nothing here is parsed yet; see the converter's // header for why. Paths are relative to tests/data/acl2-x86isa/. /// One vendored file. @@ -43,6 +43,7 @@ pub const FILES: &[File] = &[ File { path: "machine/instructions/fp/cmp-spec.lisp", size: 12052, sha256: "0d54f6ec2fec0c03c9571f53cedc62b93926e461193a7f44b18b2e62a31893da" }, File { path: "machine/instructions/fp/convert.lisp", size: 18745, sha256: "869f6ed9a170bd0b4690dcc2766888aabd18e1908901fd03b2a00a637e714cef" }, File { path: "machine/instructions/fp/cvt-spec.lisp", size: 22086, sha256: "64e02b07965a80fcd786df9a95087fba93c4d7e617755f2e0eb263d067f720bb" }, + File { path: "machine/instructions/fp/logical.lisp", size: 20410, sha256: "01ff6c7a41457cf9676da0969667c28349f30ab5ae224e22ef99aaef2c20dd47" }, File { path: "machine/instructions/fp/mxcsr.lisp", size: 5562, sha256: "7aee2ad7b72525572bfcebd3ec892af0650a312b784c490ad394a4e2e6b26597" }, File { path: "machine/instructions/fp/sqrt-spec.lisp", size: 5998, sha256: "3c82aa74064b48cc4d235e11fbaa3b6a391cf4491041f0ff8f93be8383db5282" }, File { path: "machine/instructions/fp/top.lisp", size: 3663, sha256: "1d35633b80b9d1bdb88bac6f747c388dfab0ed1c5adc5e307a2f965b209734d6" }, diff --git a/crates/clazel-x64/tests/vendored_sources.rs b/crates/clazel-x64/tests/vendored_sources.rs index 92bf3b1ed..b9c3d1b94 100644 --- a/crates/clazel-x64/tests/vendored_sources.rs +++ b/crates/clazel-x64/tests/vendored_sources.rs @@ -8,6 +8,9 @@ use std::path::Path; mod acl2_x86isa { include!("generated/acl2_x86isa.rs"); } +mod acl2_rtl { + include!("generated/acl2_rtl.rs"); +} mod sail_x86_from_acl2 { include!("generated/sail_x86_from_acl2.rs"); } @@ -36,6 +39,12 @@ fn acl2_x86isa_files_have_their_listed_sizes() { check("acl2-x86isa", &files); } +#[test] +fn acl2_rtl_files_have_their_listed_sizes() { + let files: Vec<_> = acl2_rtl::FILES.iter().map(|f| (f.path, f.size)).collect(); + check("acl2-rtl", &files); +} + #[test] fn sail_x86_from_acl2_files_have_their_listed_sizes() { let files: Vec<_> = sail_x86_from_acl2::FILES diff --git a/docs/phases/jit.md b/docs/phases/jit.md index 9b9b8b6d9..a736e82ff 100644 --- a/docs/phases/jit.md +++ b/docs/phases/jit.md @@ -375,6 +375,8 @@ code. `xtask` converter (`xtask/src/testdata/isa.rs`). The crate READMEs record what the pins show: - ACL2 `x86isa` (acl2/acl2 at 33b05575, BSD-3-Clause, 2.6 MB); + - Russinoff's RTL library at the same commit (`books/rtl/rel11`, 0.3 MB), + which the x86isa floating-point books are defined with; - the Sail x86 model translated from it (rems-project/sail-x86-from-acl2 at 0c6c023d, 0.8 MB); - Intel's SDM volume 2, version 093, **pinned by URL and SHA-256 only**: diff --git a/xtask/src/testdata.rs b/xtask/src/testdata.rs index 502571186..e1528260a 100644 --- a/xtask/src/testdata.rs +++ b/xtask/src/testdata.rs @@ -206,6 +206,7 @@ const CONVERTERS: &[(&str, Convert, &[&str])] = &[ ("ucd-regexp", inventory::convert_ucd, inventory::UCD_FILES), // JIT item J.2: instruction-set sources (see isa.rs). ("acl2-x86isa", isa::convert_acl2_x86isa, &[]), + ("acl2-rtl", isa::convert_acl2_rtl, &[]), ("sail-x86-from-acl2", isa::convert_sail_x86_from_acl2, &[]), ("intel-sdm", isa::convert_intel_sdm, &[]), ("sail-arm", isa::convert_sail_arm, &[]), @@ -222,6 +223,7 @@ const TREE_SUITES: &[&str] = &[ "todomvc", "test262", "acl2-x86isa", + "acl2-rtl", "sail-x86-from-acl2", "sail-arm", "arm-mrs", diff --git a/xtask/src/testdata/isa.rs b/xtask/src/testdata/isa.rs index 4f27d95e9..8267fcaf7 100644 --- a/xtask/src/testdata/isa.rs +++ b/xtask/src/testdata/isa.rs @@ -10,6 +10,8 @@ //! //! - `acl2-x86isa` (`clazel-x64`): the ACL2 x86isa model, the files the //! subset of item J.3 reads. +//! - `acl2-rtl` (`clazel-x64`): Russinoff's RTL library at the same ACL2 +//! commit, which the x86isa floating-point books are defined with. //! - `sail-x86-from-acl2` (`clazel-x64`): the Sail model that is a //! mechanical translation of the one above (see the crate's README: it is //! not independent of it). @@ -27,6 +29,8 @@ use super::inventory::{inventory, listed_hashes, render}; /// The ACL2 checkout's `books/projects/x86isa` paths vendored. pub const ACL2_X86ISA_ROOTS: &[&str] = &["README", "portcullis", "utils", "machine"]; +/// The ACL2 checkout's `books/rtl/rel11` paths vendored. +pub const ACL2_RTL_ROOTS: &[&str] = &["package.lsp", "portcullis.lisp", "lib"]; /// The translated Sail model's roots. pub const SAIL_X86_FROM_ACL2_ROOTS: &[&str] = &["README.md", "LICENCE", "model"]; /// The Sail Arm model's roots. @@ -56,6 +60,16 @@ pub fn convert_acl2_x86isa(dir: &Path) -> Result { ) } +/// `acl2-rtl`. +pub fn convert_acl2_rtl(dir: &Path) -> Result { + tree( + dir, + "acl2-rtl", + ACL2_RTL_ROOTS, + "Russinoff's RTL library, the floating-point definitions acl2-x86isa's SSE books call.", + ) +} + /// `sail-x86-from-acl2`. pub fn convert_sail_x86_from_acl2(dir: &Path) -> Result { tree( From 4a772b76f3aaec629cba97fd2c6f7ce2a4ea20b9 Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Mon, 16 Nov 2026 23:12:55 +0000 Subject: [PATCH 7/8] clazel-x64, clazel-a64: skip the vendored-file tests under Miri, which forbids file access Co-Authored-By: Claude Opus 5.5 --- crates/clazel-a64/tests/vendored_sources.rs | 4 ++++ crates/clazel-x64/tests/vendored_sources.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/crates/clazel-a64/tests/vendored_sources.rs b/crates/clazel-a64/tests/vendored_sources.rs index 1531a2ea9..a10637526 100644 --- a/crates/clazel-a64/tests/vendored_sources.rs +++ b/crates/clazel-a64/tests/vendored_sources.rs @@ -16,6 +16,7 @@ mod arm_arm { } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn the_arm_arm_is_pinned_and_not_vendored() { assert_eq!(arm_arm::PINS.len(), 1); for p in arm_arm::PINS { @@ -52,18 +53,21 @@ fn check(suite: &str, files: &[(&str, u64)]) { } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn sail_arm_files_have_their_listed_sizes() { let files: Vec<_> = sail_arm::FILES.iter().map(|f| (f.path, f.size)).collect(); check("sail-arm", &files); } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn arm_mrs_files_have_their_listed_sizes() { let files: Vec<_> = arm_mrs::FILES.iter().map(|f| (f.path, f.size)).collect(); check("arm-mrs", &files); } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn instructions_json_is_pinned_and_not_vendored() { assert_eq!(arm_mrs::PINS.len(), 1); for p in arm_mrs::PINS { diff --git a/crates/clazel-x64/tests/vendored_sources.rs b/crates/clazel-x64/tests/vendored_sources.rs index b9c3d1b94..42a23c51a 100644 --- a/crates/clazel-x64/tests/vendored_sources.rs +++ b/crates/clazel-x64/tests/vendored_sources.rs @@ -31,6 +31,7 @@ fn check(suite: &str, files: &[(&str, u64)]) { } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn acl2_x86isa_files_have_their_listed_sizes() { let files: Vec<_> = acl2_x86isa::FILES .iter() @@ -40,12 +41,14 @@ fn acl2_x86isa_files_have_their_listed_sizes() { } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn acl2_rtl_files_have_their_listed_sizes() { let files: Vec<_> = acl2_rtl::FILES.iter().map(|f| (f.path, f.size)).collect(); check("acl2-rtl", &files); } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn sail_x86_from_acl2_files_have_their_listed_sizes() { let files: Vec<_> = sail_x86_from_acl2::FILES .iter() @@ -55,6 +58,7 @@ fn sail_x86_from_acl2_files_have_their_listed_sizes() { } #[test] +#[cfg_attr(miri, ignore = "reads the vendored files")] fn the_sdm_is_pinned_and_not_vendored() { assert_eq!(intel_sdm::PINS.len(), 1); for p in intel_sdm::PINS { From 50a56fa94f5f16111d7a5fead08eefc03e9c4790 Mon Sep 17 00:00:00 2001 From: Alex Tiernan-Berry Date: Tue, 17 Nov 2026 07:55:05 +0000 Subject: [PATCH 8/8] clazel-x64: use yaxpeax-x86 as the reference disassembler, not iced-x86 Miri (Stacked Borrows) reports undefined behaviour in iced-x86 1.22.0's decoder (decoder/handlers/legacy.rs:2006), which failed CI's Miri job. yaxpeax-x86 2.2.1 (0BSD) passes the same tests under Miri. It is used without features: its std would turn on yaxpeax-arch's, which yaxpeax-arm 0.5.0 does not build with. iced-x86 and lazy_static leave the allowlist; yaxpeax-x86 joins it, and its other dependencies are already listed. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 29 ++++++++--------- crates/clazel-x64/Cargo.toml | 3 +- .../tests/reference_disassembler.rs | 31 ++++++++++++------- docs/DEPENDENCIES.md | 5 ++- docs/phases/jit.md | 11 ++++--- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08903694e..43f71205e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -633,7 +633,8 @@ dependencies = [ name = "clazel-x64" version = "0.0.0" dependencies = [ - "iced-x86", + "yaxpeax-arch", + "yaxpeax-x86", ] [[package]] @@ -1078,15 +1079,6 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" -[[package]] -name = "iced-x86" -version = "1.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c23ad4d19dca41180e835ef6fbd2c1ee655777eca086ad80dd517e0513322879" -dependencies = [ - "lazy_static", -] - [[package]] name = "idna" version = "1.1.0" @@ -1160,12 +1152,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.190" @@ -2538,6 +2524,17 @@ dependencies = [ "yaxpeax-arch", ] +[[package]] +name = "yaxpeax-x86" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9d20d93c5efc168a0f0576ad0a5e8fc7826aa5f41c37ede54527d655e0625d" +dependencies = [ + "cfg-if", + "num-traits", + "yaxpeax-arch", +] + [[package]] name = "zerocopy" version = "0.8.63" diff --git a/crates/clazel-x64/Cargo.toml b/crates/clazel-x64/Cargo.toml index 9f1e74121..240c0154e 100644 --- a/crates/clazel-x64/Cargo.toml +++ b/crates/clazel-x64/Cargo.toml @@ -21,4 +21,5 @@ target-tier = 2 workspace = true [dev-dependencies] -iced-x86 = { version = "=1.22.0", default-features = false, features = ["std", "decoder", "encoder", "instr_info", "intel"] } +yaxpeax-x86 = { version = "=2.2.1", default-features = false } +yaxpeax-arch = { version = "=0.3.3", default-features = false } diff --git a/crates/clazel-x64/tests/reference_disassembler.rs b/crates/clazel-x64/tests/reference_disassembler.rs index 89d08cf5a..058db5314 100644 --- a/crates/clazel-x64/tests/reference_disassembler.rs +++ b/crates/clazel-x64/tests/reference_disassembler.rs @@ -1,38 +1,45 @@ //! The reference disassembler builds and decodes (docs/phases/jit.md item J.2). //! -//! `iced-x86` is a test dependency only (class `test` in +//! `yaxpeax-x86` is a test dependency only (class `test` in //! docs/DEPENDENCIES.md). Item J.3's decoder differential will compare it with //! `clazel-x64` on every encoding of the subset; this test only shows that it //! is wired in and answers for one instruction of each kind the subset has. +//! It replaced `iced-x86`, whose decoder Miri reports as undefined behaviour +//! under Stacked Borrows (iced-x86 1.22.0, `decoder/handlers/legacy.rs:2006`). -use iced_x86::{Code, Decoder, DecoderOptions, Mnemonic}; +use yaxpeax_arch::{Decoder, LengthedInstruction, U8Reader}; +use yaxpeax_x86::long_mode::{InstDecoder, Opcode}; -fn decode(bytes: &[u8]) -> (Mnemonic, usize) { - let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE); - let inst = decoder.decode(); - (inst.mnemonic(), inst.len()) +fn decode(bytes: &[u8]) -> Option<(Opcode, u64)> { + let mut reader = U8Reader::new(bytes); + InstDecoder::default() + .decode(&mut reader) + .ok() + .map(|inst| (inst.opcode(), inst.len().to_const())) } #[test] fn add_rax_rbx() { // REX.W 01 /r: add r/m64, r64. - assert_eq!(decode(&[0x48, 0x01, 0xd8]), (Mnemonic::Add, 3)); + assert_eq!(decode(&[0x48, 0x01, 0xd8]), Some((Opcode::ADD, 3))); } #[test] fn jmp_rel32_and_ret() { - assert_eq!(decode(&[0xe9, 0x10, 0x00, 0x00, 0x00]), (Mnemonic::Jmp, 5)); - assert_eq!(decode(&[0xc3]), (Mnemonic::Ret, 1)); + assert_eq!( + decode(&[0xe9, 0x10, 0x00, 0x00, 0x00]), + Some((Opcode::JMP, 5)) + ); + assert_eq!(decode(&[0xc3]), Some((Opcode::RETURN, 1))); } #[test] fn addsd_xmm0_xmm1() { // F2 0F 58 /r: addsd xmm1, xmm2/m64. - assert_eq!(decode(&[0xf2, 0x0f, 0x58, 0xc1]), (Mnemonic::Addsd, 4)); + assert_eq!(decode(&[0xf2, 0x0f, 0x58, 0xc1]), Some((Opcode::ADDSD, 4))); } #[test] fn syscall_is_outside_the_subset_but_decodes() { - let mut decoder = Decoder::new(64, &[0x0f, 0x05], DecoderOptions::NONE); - assert_eq!(decoder.decode().code(), Code::Syscall); + assert_eq!(decode(&[0x0f, 0x05]), Some((Opcode::SYSCALL, 2))); } diff --git a/docs/DEPENDENCIES.md b/docs/DEPENDENCIES.md index 9f6e17fdb..208f3bf60 100644 --- a/docs/DEPENDENCIES.md +++ b/docs/DEPENDENCIES.md @@ -245,10 +245,9 @@ Changing a row is a reviewable act. Adding one means saying why below. | unicode-properties | 0.1.5 | test | Unicode General_Category (the only feature `rustybuzz` enables), required by `rustybuzz`. No dependencies. | | unicode-script | 0.5.9 | test | The Unicode Script property, required by `rustybuzz`. No dependencies. | | ab_glyph_rasterizer | 0.1.10 | test | Alex Butler's coverage rasterizer (used by `ab_glyph`, `glyph_brush` and `wgpu_glyph`), a descendant of `font-rs`: the reference engine in `clazel-glyph-mask`'s differential test (`tests/conformance_masks.rs`, phase-5.md item 5.17), the same signed-area accumulation in `f32` written by another author. Used without default features but with `std`, which is its only default; `cargo tree` shows no dependencies (`libm` is optional and off). It has `unsafe` only to call its line function through a pointer chosen by CPU feature detection (all variants are the same scalar code). Pinned to 0.1.10, its latest release. | -| iced-x86 | 1.22.0 | test | A fast x86/x64 decoder, encoder and disassembler (icedland/iced, MIT): the reference in `clazel-x64`'s decoder and encoder differential tests (jit.md items J.2 and J.3, exit criterion 3). Used without default features, with `std`, `decoder`, `encoder`, `instr_info` and `intel` (its `no_std` build needs `lazy_static`'s spin feature, one more package); its only dependency is `lazy_static`. | -| lazy_static | 1.5.0 | test | Lazily initialised statics (MIT OR Apache-2.0), required by `iced-x86`'s `std` feature. No dependencies. | +| yaxpeax-x86 | 2.2.1 | test | An x86 decoder (yaxpeax project, 0BSD): the reference in `clazel-x64`'s decoder differential test (jit.md items J.2 and J.3, exit criterion 3). Used without any features (its `std` would turn on `yaxpeax-arch`'s, which `yaxpeax-arm` 0.5.0 does not build with); it needs `yaxpeax-arch`, `cfg-if` and `num-traits`, all listed. It replaced `iced-x86` 1.22.0, whose decoder Miri reports as undefined behaviour under Stacked Borrows. | | yaxpeax-arm | 0.5.0 | test | An ARM decoder (yaxpeax project, 0BSD): the reference in `clazel-a64`'s decoder differential test (jit.md items J.2 and J.4, exit criterion 3). Used without default features (no `serde`) and with `fmt`; it needs `bitvec` and `yaxpeax-arch`. | -| yaxpeax-arch | 0.3.3 | test | The architecture traits of the yaxpeax project (0BSD), required by `yaxpeax-arm`. Used without default features; its only dependency is `num-traits`, which the table lists under `shipped` (the stricter class, as it is locked under libcrux's `cfg(hax)`). | +| yaxpeax-arch | 0.3.3 | test | The architecture traits of the yaxpeax project (0BSD), required by `yaxpeax-arm` and `yaxpeax-x86`. Used without default features; its only dependency is `num-traits`, which the table lists under `shipped` (the stricter class, as it is locked under libcrux's `cfg(hax)`). | | bitvec | 1.1.1 | test | Bit-level views of memory (MIT), required by `yaxpeax-arm`. It needs the four packages in the rows below. | | funty | 2.0.0 | test | Fundamental-type traits (MIT), required by `bitvec`. No dependencies. | | radium | 0.7.0 | test | Atomic and non-atomic cell abstraction (MIT), required by `bitvec`. No dependencies. | diff --git a/docs/phases/jit.md b/docs/phases/jit.md index a736e82ff..8d37ab02e 100644 --- a/docs/phases/jit.md +++ b/docs/phases/jit.md @@ -365,7 +365,7 @@ code. to each other must be read before they count as independent; Intel's SDM volume 2 for the encoding tables; - A64: Arm's machine-readable specification and the Sail Arm model. -- Pin reference disassemblers for tests only (for example `iced-x86` and +- Pin reference disassemblers for tests only (for example `yaxpeax-x86` and `yaxpeax-arm`), each a `test` row in DEPENDENCIES.md. - Pin the benchmark set, and record the JIT-off numbers. @@ -402,10 +402,11 @@ code. from the Intel manuals, as the second x86-64 source. It has a single author, no review, and leaves floating-point arithmetic external (`extern`, supplied by its emulator). It is not pinned or vendored. -- **Reference disassemblers:** `iced-x86` 1.22.0 (with `lazy_static`) and - `yaxpeax-arm` 0.5.0 (with `yaxpeax-arch`, `bitvec` and four small - packages), each a `test` row in DEPENDENCIES.md, dev-dependencies of the new - crates only. +- **Reference disassemblers:** `yaxpeax-x86` 2.2.1 and `yaxpeax-arm` 0.5.0 + (with `yaxpeax-arch`, `bitvec` and four small packages), each a `test` row + in DEPENDENCIES.md, dev-dependencies of the new crates only. On + 2026-11-17 `yaxpeax-x86` replaced `iced-x86` 1.22.0, whose decoder Miri + reports as undefined behaviour under Stacked Borrows. - **Proposed benchmark set** (a proposal, for a person to accept): the compute-bound programs of Octane 2.0, from `chromium/octane` (archived; BSD-3-Clause for the harness, each benchmark file with its own licence