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
// 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
// ----------------------------------------------------------------------------
// Multiplex/select z := x (if p nonzero) or z := y (if p zero)
// Inputs p, x[k], y[k]; output z[k]
//
// extern void bignum_mux(uint64_t p, uint64_t k, uint64_t *z, const uint64_t *x,
// const uint64_t *y);
//
// It is assumed that all numbers x, y and z have the same size k digits.
//
// Standard ARM ABI: X0 = p, X1 = k, X2 = z, X3 = x, X4 = y
// ----------------------------------------------------------------------------
macro_rules! b {
() => {
"x0"
};
}
macro_rules! k {
() => {
"x1"
};
}
macro_rules! z {
() => {
"x2"
};
}
macro_rules! x {
() => {
"x3"
};
}
macro_rules! y {
() => {
"x4"
};
}
macro_rules! a {
() => {
"x5"
};
}
/// Multiplex/select z := x (if p nonzero) or z := y (if p zero)
///
/// Inputs p, x[k], y[k]; output z[k]
///
/// It is assumed that all numbers x, y and z have the same size k digits.
pub(crate) fn bignum_mux(p: u64, z: &mut [u64], x_if_p: &[u64], y_if_not_p: &[u64]) {
debug_assert!(z.len() == x_if_p.len());
debug_assert!(z.len() == y_if_not_p.len());
// SAFETY: inline assembly. see [crate::low::inline_assembly_safety] for safety info.
unsafe {
core::arch::asm!(
Q!(" cbz " k!() ", " Label!("bignum_mux_end", 2, After)),
Q!(" cmp " b!() ", #0"),
// We've set cc's from b once and for all and can now re-use "b" as a temporary
Q!(Label!("bignum_mux_loop", 3) ":"),
Q!(" sub " k!() ", " k!() ", #1"),
Q!(" ldr " a!() ", [" x!() ", " k!() ", lsl #3]"),
Q!(" ldr " b!() ", [" y!() ", " k!() ", lsl #3]"),
Q!(" csel " a!() ", " a!() ", " b!() ", ne"),
Q!(" str " a!() ", [" z!() ", " k!() ", lsl #3]"),
Q!(" cbnz " k!() ", " Label!("bignum_mux_loop", 3, Before)),
Q!(Label!("bignum_mux_end", 2) ":"),
inout("x0") p => _,
inout("x1") z.len() => _,
inout("x2") z.as_mut_ptr() => _,
inout("x3") x_if_p.as_ptr() => _,
inout("x4") y_if_not_p.as_ptr() => _,
// clobbers
out("x5") _,
)
};
}