Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/add.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ impl MakeAdd<Reg32, Reg32, Reg32> for Add<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Add);
define_arith_fallible!(Add);

define_arith_shift!(Add, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Add, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/adds.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeAdds<Reg32, Reg32, Reg32> for Adds<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Adds);
define_arith_fallible!(Adds);

define_arith_shift!(Adds, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Adds, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/macros.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
macro_rules! define_arith_faillible {
macro_rules! define_arith_fallible {
($name:ident) => {
::paste::paste! {
impl<Dst, RealDst, Src1, RealSrc1, Src2, Err> [<Make $name>]<Dst, Src1, Result<Src2, Err>>
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/sub.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ impl MakeSub<Reg32, Reg32, Reg32> for Sub<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Sub);
define_arith_fallible!(Sub);

define_arith_shift!(Sub, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Sub, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/arith/subs.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ impl MakeSubs<Reg32, Reg32, Reg32> for Subs<Reg32, Reg32, Reg32> {
}
}

define_arith_faillible!(Subs);
define_arith_fallible!(Subs);

define_arith_shift!(Subs, 32, addsub, RegOrZero32, Reg32);
define_arith_shift!(Subs, 64, addsub, RegOrZero64, Reg64);
Expand Down
2 changes: 1 addition & 1 deletion harm/src/instructions/dpimm/pcreladdr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -172,7 +172,7 @@ b0800007 adrp x7, .-0xfffff000
test_adrp_plus_max, adrp(X8, SBitValue::new_i64(MAX_ADRP_OFFSET).unwrap()), "adrp x8, .+0xfffff000";
test_adrp_minus_max, adrp(X7, SBitValue::new_i64(-MAX_ADRP_OFFSET).unwrap()), "adrp x7, .-0xfffff000";

test_adr_0x12345_faillible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adr_0x12345_fallible, adr(X28, 0x12345).unwrap(), "adr x28, .+0x12345";
test_adrp_0x12345_fallible, adrp(X9, 0x12345 << 12).unwrap(), "adrp x9, .+0x12345000";
}
}
4 changes: 4 additions & 0 deletions harm/src/instructions/ldst.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ pub(crate) mod macros;
mod increment;
mod shift_extend;

mod ldnp;
mod ldp;
mod ldpsw;
mod ldr;
Expand All@@ -23,6 +24,7 @@ mod ldurh;
mod ldursb;
mod ldursh;
mod ldursw;
mod stnp;
mod stp;
mod str;
mod strb;
Expand All@@ -32,6 +34,7 @@ mod sturb;
mod sturh;

pub use self::increment::*;
pub use self::ldnp::*;
pub use self::ldp::*;
pub use self::ldpsw::*;
pub use self::ldr::*;
Expand All@@ -47,6 +50,7 @@ pub use self::ldursb::*;
pub use self::ldursh::*;
pub use self::ldursw::*;
pub use self::shift_extend::*;
pub use self::stnp::*;
pub use self::stp::*;
pub use self::str::*;
pub use self::strb::*;
Expand Down
206 changes: 206 additions & 0 deletions harm/src/instructions/ldst/ldnp.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
/* Copyright (C) 2026 Ivan Boldyrev
*
* This document is licensed under the BSD 3-clause license.
*/

use aarchmrs_instructions::A64::ldst::ldstnapair_offs::{
LDNP_32_ldstnapair_offs::LDNP_32_ldstnapair_offs,
LDNP_64_ldstnapair_offs::LDNP_64_ldstnapair_offs,
};

use crate::bits::BitError;
use crate::register::{IntoReg, RegOrSp64, RegOrZero32, RegOrZero64, Register};
use crate::sealed::Sealed;

use super::{LdpStpOffset32, LdpStpOffset64};

/// A `ldnp` instruction with a destination and an address.
pub struct Ldnp<Rt, Addr> {
rt: (Rt, Rt),
addr: Addr,
}

impl<Rt, Addr> Ldnp<Rt, Addr> {
pub fn rt(&self) -> &(Rt, Rt) {
&self.rt
}

pub fn addr(&self) -> &Addr {
&self.addr
}
}

impl<Rt, Addr> Sealed for Ldnp<Rt, Addr> {}

/// Defines possible ways to construct a `ldnp` instruction.
pub trait MakeLdnp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
}

pub fn ldnp<DestInp1, DestInp2, TargetOut, AddrInp, AddrOut>(
d1: DestInp1,
d2: DestInp2,
addr: AddrInp,
) -> <Ldnp<TargetOut, AddrOut> as MakeLdnp<DestInp1, DestInp2, AddrInp>>::Output
where
Ldnp<TargetOut, AddrOut>: MakeLdnp<DestInp1, DestInp2, AddrInp>,
{
Ldnp::new((d1, d2), addr)
}

define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero32,
"32",
LdpStpOffset32,
"ldstnapair_offs"
);
define_simple_pair_imm_offset_rules!(
Ldnp,
MakeLdnp,
LDNP,
RegOrZero64,
"64",
LdpStpOffset64,
"ldstnapair_offs"
);
define_pair_fallible_rules!(LDNP, Ldnp, MakeLdnp);

#[cfg(test)]
mod tests {
use harm_test_utils::test_cases;

use super::*;
use crate::instructions::InstructionSeq;
use crate::register::Reg32::*;
use crate::register::Reg64::*;
use RegOrSp64::SP;
use RegOrZero32::WZR;
use RegOrZero64::XZR;

const LDNP_DB: &str = "
a87f8c41 ldnp x1, x3, [x2, -8]
a8408c41 ldnp x1, x3, [x2, 8]
a85f8c41 ldnp x1, x3, [x2, 504]
a8700c41 ldnp x1, x3, [x2, -256]
a8400c41 ldnp x1, x3, [x2, 0]
a8400c41 ldnp x1, x3, [x2]
a87f8fe1 ldnp x1, x3, [sp, -8]
a8408fe1 ldnp x1, x3, [sp, 8]
a85f8fe1 ldnp x1, x3, [sp, 504]
a8700fe1 ldnp x1, x3, [sp, -256]
a8400fe1 ldnp x1, x3, [sp, 0]
287f8c41 ldnp w1, w3, [x2, -4]
28408c41 ldnp w1, w3, [x2, 4]
285f8c41 ldnp w1, w3, [x2, 252]
28600c41 ldnp w1, w3, [x2, -256]
28400c41 ldnp w1, w3, [x2, 0]
287f8fe1 ldnp w1, w3, [sp, -4]
28408fe1 ldnp w1, w3, [sp, 4]
285f8fe1 ldnp w1, w3, [sp, 252]
28600fe1 ldnp w1, w3, [sp, -256]
28400fe1 ldnp w1, w3, [sp, 0]
a87f8c5f ldnp xzr, x3, [x2, -8]
a8408c5f ldnp xzr, x3, [x2, 8]
a85f8c5f ldnp xzr, x3, [x2, 504]
a8700c5f ldnp xzr, x3, [x2, -256]
a8400c5f ldnp xzr, x3, [x2, 0]
a87f8fff ldnp xzr, x3, [sp, -8]
a8408fff ldnp xzr, x3, [sp, 8]
a85f8fff ldnp xzr, x3, [sp, 504]
a8700fff ldnp xzr, x3, [sp, -256]
a8400fff ldnp xzr, x3, [sp, 0]
287f8c5f ldnp wzr, w3, [x2, -4]
28408c5f ldnp wzr, w3, [x2, 4]
285f8c5f ldnp wzr, w3, [x2, 252]
28600c5f ldnp wzr, w3, [x2, -256]
28400c5f ldnp wzr, w3, [x2, 0]
287f8fff ldnp wzr, w3, [sp, -4]
28408fff ldnp wzr, w3, [sp, 4]
285f8fff ldnp wzr, w3, [sp, 252]
28600fff ldnp wzr, w3, [sp, -256]
28400fff ldnp wzr, w3, [sp, 0]
";

test_cases! {
LDNP_DB, untested_ldnp_cases;
test_ldnp_x1_x2_m8, ldnp(X1, X3, (X2, -8i32)).unwrap(), "ldnp x1, x3, [x2, -8]";
test_ldnp_x1_x2_8, ldnp(X1, X3, (X2, 8i32)).unwrap(), "ldnp x1, x3, [x2, 8]";
test_ldnp_x1_x2_504, ldnp(X1, X3, (X2, 504i32)).unwrap(), "ldnp x1, x3, [x2, 504]";
test_ldnp_x1_x2_m256, ldnp(X1, X3, (X2, -256i32)).unwrap(), "ldnp x1, x3, [x2, -256]";
test_ldnp_x1_x2_0, ldnp(X1, X3, (X2, 0i32)).unwrap(), "ldnp x1, x3, [x2, 0]";
test_ldnp_x1_x2_simple, ldnp(X1, X3, (X2,)), "ldnp x1, x3, [x2]";
test_ldnp_x1_sp_m8, ldnp(X1, X3, (SP, -8i32)).unwrap(), "ldnp x1, x3, [sp, -8]";
test_ldnp_x1_sp_8, ldnp(X1, X3, (SP, 8i32)).unwrap(), "ldnp x1, x3, [sp, 8]";
test_ldnp_x1_sp_504, ldnp(X1, X3, (SP, 504i32)).unwrap(), "ldnp x1, x3, [sp, 504]";
test_ldnp_x1_sp_m256, ldnp(X1, X3, (SP, -256i32)).unwrap(), "ldnp x1, x3, [sp, -256]";
test_ldnp_x1_sp_0, ldnp(X1, X3, (SP, 0i32)).unwrap(), "ldnp x1, x3, [sp, 0]";
test_ldnp_w1_x2_m4, ldnp(W1, W3, (X2, -4i32)).unwrap(), "ldnp w1, w3, [x2, -4]";
test_ldnp_w1_x2_4, ldnp(W1, W3, (X2, 4i32)).unwrap(), "ldnp w1, w3, [x2, 4]";
test_ldnp_w1_x2_252, ldnp(W1, W3, (X2, 252i32)).unwrap(), "ldnp w1, w3, [x2, 252]";
test_ldnp_w1_x2_m256, ldnp(W1, W3, (X2, -256i32)).unwrap(), "ldnp w1, w3, [x2, -256]";
test_ldnp_w1_x2_0, ldnp(W1, W3, (X2, 0i32)).unwrap(), "ldnp w1, w3, [x2, 0]";
test_ldnp_w1_sp_m4, ldnp(W1, W3, (SP, -4i32)).unwrap(), "ldnp w1, w3, [sp, -4]";
test_ldnp_w1_sp_4, ldnp(W1, W3, (SP, 4i32)).unwrap(), "ldnp w1, w3, [sp, 4]";
test_ldnp_w1_sp_252, ldnp(W1, W3, (SP, 252i32)).unwrap(), "ldnp w1, w3, [sp, 252]";
test_ldnp_w1_sp_m256, ldnp(W1, W3, (SP, -256i32)).unwrap(), "ldnp w1, w3, [sp, -256]";
test_ldnp_w1_sp_0, ldnp(W1, W3, (SP, 0i32)).unwrap(), "ldnp w1, w3, [sp, 0]";
test_ldnp_xzr_x2_m8, ldnp(XZR, X3, (X2, -8i32)).unwrap(), "ldnp xzr, x3, [x2, -8]";
test_ldnp_xzr_x2_8, ldnp(XZR, X3, (X2, 8i32)).unwrap(), "ldnp xzr, x3, [x2, 8]";
test_ldnp_xzr_x2_504, ldnp(XZR, X3, (X2, 504i32)).unwrap(), "ldnp xzr, x3, [x2, 504]";
test_ldnp_xzr_x2_m256, ldnp(XZR, X3, (X2, -256i32)).unwrap(), "ldnp xzr, x3, [x2, -256]";
test_ldnp_xzr_x2_0, ldnp(XZR, X3, (X2, 0i32)).unwrap(), "ldnp xzr, x3, [x2, 0]";
test_ldnp_xzr_sp_m8, ldnp(XZR, X3, (SP, -8i32)).unwrap(), "ldnp xzr, x3, [sp, -8]";
test_ldnp_xzr_sp_8, ldnp(XZR, X3, (SP, 8i32)).unwrap(), "ldnp xzr, x3, [sp, 8]";
test_ldnp_xzr_sp_504, ldnp(XZR, X3, (SP, 504i32)).unwrap(), "ldnp xzr, x3, [sp, 504]";
test_ldnp_xzr_sp_m256, ldnp(XZR, X3, (SP, -256i32)).unwrap(), "ldnp xzr, x3, [sp, -256]";
test_ldnp_xzr_sp_0, ldnp(XZR, X3, (SP, 0i32)).unwrap(), "ldnp xzr, x3, [sp, 0]";
test_ldnp_wzr_x2_m4, ldnp(WZR, W3, (X2, -4i32)).unwrap(), "ldnp wzr, w3, [x2, -4]";
test_ldnp_wzr_x2_4, ldnp(WZR, W3, (X2, 4i32)).unwrap(), "ldnp wzr, w3, [x2, 4]";
test_ldnp_wzr_x2_252, ldnp(WZR, W3, (X2, 252i32)).unwrap(), "ldnp wzr, w3, [x2, 252]";
test_ldnp_wzr_x2_m256, ldnp(WZR, W3, (X2, -256i32)).unwrap(), "ldnp wzr, w3, [x2, -256]";
test_ldnp_wzr_x2_0, ldnp(WZR, W3, (X2, 0i32)).unwrap(), "ldnp wzr, w3, [x2, 0]";
test_ldnp_wzr_sp_m4, ldnp(WZR, W3, (SP, -4i32)).unwrap(), "ldnp wzr, w3, [sp, -4]";
test_ldnp_wzr_sp_4, ldnp(WZR, W3, (SP, 4i32)).unwrap(), "ldnp wzr, w3, [sp, 4]";
test_ldnp_wzr_sp_252, ldnp(WZR, W3, (SP, 252i32)).unwrap(), "ldnp wzr, w3, [sp, 252]";
test_ldnp_wzr_sp_m256, ldnp(WZR, W3, (SP, -256i32)).unwrap(), "ldnp wzr, w3, [sp, -256]";
test_ldnp_wzr_sp_0, ldnp(WZR, W3, (SP, 0i32)).unwrap(), "ldnp wzr, w3, [sp, 0]";
}

#[test]
fn test_ldnp_r64_offset_underflow() {
assert!(ldnp(X1, X2, (X3, -0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x200i32)).is_ok());
assert!(ldnp(X1, X2, (X3, -0x204i32)).is_err());
assert!(ldnp(X1, X2, (X3, -0x208i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_underflow() {
assert!(ldnp(W1, W2, (X3, -0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x100i32)).is_ok());
assert!(ldnp(W1, W2, (X3, -0x102i32)).is_err());
assert!(ldnp(W1, W2, (X3, -0x104i32)).is_err());
}

#[test]
fn test_ldnp_r64_offset_overflow() {
assert!(ldnp(X1, X2, (X3, 0x1f4i32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x1f8i32)).is_ok());
assert!(ldnp(X1, X2, (X3, 0x1fci32)).is_err());
assert!(ldnp(X1, X2, (X3, 0x200i32)).is_err());
}

#[test]
fn test_ldnp_r32_offset_overflow() {
assert!(ldnp(W1, W2, (X3, 0xfai32)).is_err());
assert!(ldnp(W1, W2, (X3, 0xfci32)).is_ok());
assert!(ldnp(W1, W2, (X3, 0xfei32)).is_err());
assert!(ldnp(W1, W2, (X3, 0x100i32)).is_err());
}
}
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldp.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,9 +38,9 @@ impl<Rt, Addr> Ldp<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldp<Rt, Addr> {}

/// Defines possible was to construct a `ldp` instruction.
/// Defines possible ways to construct a `ldp` instruction.
pub trait MakeLdp<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
4 changes: 2 additions & 2 deletions harm/src/instructions/ldst/ldpsw.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,9 +32,9 @@ impl<Rt, Addr> Ldpsw<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldpsw<Rt, Addr> {}

/// Defines possible was to construct a `ldpsw` instruction.
/// Defines possible ways to construct a `ldpsw` instruction.
pub trait MakeLdpsw<Rt1, Rt2, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;

fn new(rt: (Rt1, Rt2), addr: Addr) -> Self::Output;
Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldr.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,9 +144,9 @@ impl<Rt, Addr> Ldr<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldr<Rt, Addr> {}

/// Defines possible was to construct a `ldr` instruction.
/// Defines possible ways to construct a `ldr` instruction.
pub trait MakeLdr<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand DownExpand Up@@ -183,7 +183,7 @@ define_pc_offset_rules!(
);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDR, Ldr, MakeLdr);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,9 +100,9 @@ impl<Rt, Addr> Ldrb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrb<Rt, Addr> {}

/// Defines possible was to construct a `ldrb` instruction.
/// Defines possible ways to construct a `ldrb` instruction.
pub trait MakeLdrb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -118,7 +118,7 @@ define_reg_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32B", ByteShift);
define_imm_offset_rules!(Ldrb, MakeLdrb, LDRB, RegOrZero32, "32", ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRB, Ldrb, MakeLdrb);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrh.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,9 +102,9 @@ impl<Rt, Addr> Ldrh<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrh<Rt, Addr> {}

/// Defines possible was to construct a `LDRH` instruction.
/// Defines possible ways to construct a `LDRH` instruction.
pub trait MakeLdrh<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -120,7 +120,7 @@ define_reg_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", HalfShift);
define_imm_offset_rules!(Ldrh, MakeLdrh, LDRH, RegOrZero32, "32", ScaledOffset16);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRH, Ldrh, MakeLdrh);

Expand Down
6 changes: 3 additions & 3 deletions harm/src/instructions/ldst/ldrsb.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,9 +112,9 @@ impl<Rt, Addr> Ldrsb<Rt, Addr> {

impl<Rt, Addr> Sealed for Ldrsb<Rt, Addr> {}

/// Defines possible was to construct a `Ldrsb` instruction.
/// Defines possible ways to construct a `Ldrsb` instruction.
pub trait MakeLdrsb<Rt, Addr>: Sealed {
/// Allows defining both faillible and infallible constructors.
/// Allows defining both fallible and infallible constructors.
type Output;
fn new(rt: Rt, addr: Addr) -> Self::Output;
}
Expand All@@ -131,7 +131,7 @@ define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero64, 64, ScaledOffset8
define_imm_offset_rules!(Ldrsb, MakeLdrsb, LDRSB, RegOrZero32, 32, ScaledOffset8);

//
// ## Faillible
// ## Fallible
//
define_fallible_rules!(LDRSB, Ldrsb, MakeLdrsb);

Expand Down
Loading