1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// generated source. do not edit.
#![allow(non_upper_case_globals, unused_macros, unused_imports)]
use crate::low::macros::*;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT-0
// ----------------------------------------------------------------------------
// Test bignums for equality, x = y
// Inputs x[m], y[n]; output function return
//
// extern uint64_t bignum_eq(uint64_t m, const uint64_t *x, uint64_t n,
// const uint64_t *y);
//
// Standard ARM ABI: X0 = m, X1 = x, X2 = n, X3 = y, returns X0
// ----------------------------------------------------------------------------
macro_rules! m {
() => {
"x0"
};
}
macro_rules! x {
() => {
"x1"
};
}
macro_rules! n {
() => {
"x2"
};
}
macro_rules! y {
() => {
"x3"
};
}
macro_rules! a {
() => {
"x4"
};
}
macro_rules! c {
() => {
"x5"
};
}
// We can re-use n for this, not needed when d appears
macro_rules! d {
() => {
"x2"
};
}
/// Test bignums for equality, x = y
///
/// Inputs x[m], y[n]; output function return
pub(crate) fn bignum_eq(x: &[u64], y: &[u64]) -> bool {
let ret: u64;
// SAFETY: inline assembly. see [crate::low::inline_assembly_safety] for safety info.
unsafe {
core::arch::asm!(
// Initialize the accumulated OR of differences to zero
Q!(" mov " c!() ", xzr"),
// If m >= n jump into the m > n loop at the final equality test
// This will drop through for m = n
Q!(" cmp " m!() ", " n!()),
Q!(" bcs " Label!("bignum_eq_mtest", 2, After)),
// Toploop for the case n > m
Q!(Label!("bignum_eq_nloop", 3) ":"),
Q!(" sub " n!() ", " n!() ", #1"),
Q!(" ldr " a!() ", [" y!() ", " n!() ", lsl #3]"),
Q!(" orr " c!() ", " c!() ", " a!()),
Q!(" cmp " m!() ", " n!()),
Q!(" bne " Label!("bignum_eq_nloop", 3, Before)),
Q!(" b " Label!("bignum_eq_mmain", 4, After)),
// Toploop for the case m > n (or n = m which enters at "mtest")
Q!(Label!("bignum_eq_mloop", 5) ":"),
Q!(" sub " m!() ", " m!() ", #1"),
Q!(" ldr " a!() ", [" x!() ", " m!() ", lsl #3]"),
Q!(" orr " c!() ", " c!() ", " a!()),
Q!(" cmp " m!() ", " n!()),
Q!(Label!("bignum_eq_mtest", 2) ":"),
Q!(" bne " Label!("bignum_eq_mloop", 5, Before)),
// Combined main loop for the min(m,n) lower words
Q!(Label!("bignum_eq_mmain", 4) ":"),
Q!(" cbz " m!() ", " Label!("bignum_eq_end", 6, After)),
Q!(Label!("bignum_eq_loop", 7) ":"),
Q!(" sub " m!() ", " m!() ", #1"),
Q!(" ldr " a!() ", [" x!() ", " m!() ", lsl #3]"),
Q!(" ldr " d!() ", [" y!() ", " m!() ", lsl #3]"),
Q!(" eor " a!() ", " a!() ", " d!()),
Q!(" orr " c!() ", " c!() ", " a!()),
Q!(" cbnz " m!() ", " Label!("bignum_eq_loop", 7, Before)),
Q!(Label!("bignum_eq_end", 6) ":"),
Q!(" cmp " c!() ", xzr"),
Q!(" cset " "x0, eq"),
inout("x0") x.len() => ret,
inout("x1") x.as_ptr() => _,
inout("x2") y.len() => _,
inout("x3") y.as_ptr() => _,
// clobbers
out("x4") _,
out("x5") _,
)
};
ret > 0
}