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
// 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
// ----------------------------------------------------------------------------
// Return size of bignum in digits (64-bit word)
// Input x[k]; output function return
//
// extern uint64_t bignum_digitsize(uint64_t k, const uint64_t *x);
//
// In the case of a zero bignum as input the result is 0
//
// Standard ARM ABI: X0 = k, X1 = x, returns X0
// ----------------------------------------------------------------------------
macro_rules! k {
() => {
"x0"
};
}
macro_rules! x {
() => {
"x1"
};
}
macro_rules! i {
() => {
"x2"
};
}
macro_rules! a {
() => {
"x3"
};
}
macro_rules! j {
() => {
"x4"
};
}
/// Return size of bignum in digits (64-bit word)
///
/// Input x[k]; output function return
///
/// In the case of a zero bignum as input the result is 0
pub(crate) fn bignum_digitsize(z: &[u64]) -> usize {
let ret: u64;
// SAFETY: inline assembly. see [crate::low::inline_assembly_safety] for safety info.
unsafe {
core::arch::asm!(
// If the bignum is zero-length, x0 is already the right answer of 0
Q!(" cbz " k!() ", " Label!("bignum_digitsize_end", 2, After)),
// Run over the words j = 0..i-1, and set i := j + 1 when hitting nonzero a[j]
Q!(" mov " i!() ", xzr"),
Q!(" mov " j!() ", xzr"),
Q!(Label!("bignum_digitsize_loop", 3) ":"),
Q!(" ldr " a!() ", [" x!() ", " j!() ", lsl #3]"),
Q!(" add " j!() ", " j!() ", #1"),
Q!(" cmp " a!() ", #0"),
Q!(" csel " i!() ", " j!() ", " i!() ", ne"),
Q!(" cmp " j!() ", " k!()),
Q!(" bne " Label!("bignum_digitsize_loop", 3, Before)),
Q!(" mov " "x0, " i!()),
Q!(Label!("bignum_digitsize_end", 2) ":"),
inout("x0") z.len() => ret,
inout("x1") z.as_ptr() => _,
// clobbers
out("x2") _,
out("x3") _,
out("x4") _,
)
};
ret as usize
}