Debian Codegraph @

debian/rust-vendor/md-5/src/compress/loongarch64_asm.rs

raw
1 //! LoongArch64 assembly backend
2
3 macro_rules! c {
4 ($($l:expr)*) => {
5 concat!($($l ,)*)
6 };
7 }
8
9 macro_rules! round0 {
10 ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => {
11 c!(
12 "xor $t4," $c "," $d ";"
13 "and $t4, $t4," $b ";"
14 "xor $t4, $t4," $d ";"
15 roundtail!($a, $b, $k, $s, $i)
16 )
17 }
18 }
19
20 macro_rules! round1 {
21 ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => {
22 c!(
23 "andn $t4," $c "," $d ";"
24 "and $t5," $d "," $b ";"
25 "or $t4, $t4, $t5;"
26 roundtail!($a, $b, $k, $s, $i)
27 )
28 }
29 }
30
31 macro_rules! round2 {
32 ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => {
33 c!(
34 "xor $t4," $c "," $d ";"
35 "xor $t4, $t4," $b ";"
36 roundtail!($a, $b, $k, $s, $i)
37 )
38 }
39 }
40
41 macro_rules! round3 {
42 ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => {
43 c!(
44 "orn $t4," $b "," $d ";"
45 "xor $t4, $t4," $c ";"
46 roundtail!($a, $b, $k, $s, $i)
47 )
48 }
49 }
50
51 macro_rules! roundtail {
52 ($a:literal, $b:literal, $k:literal, $s:literal, $i:literal) => {
53 c!(
54 "ld.w $t5, $a3," $i " * 4;"
55 "ld.w $t6, $a1," $k " * 4;"
56 "add.w " $a "," $a ", $t5;"
57 "add.w " $a "," $a ", $t6;"
58 "add.w " $a "," $a ", $t4;"
59 "rotri.w " $a "," $a ", 32 -" $s ";"
60 "add.w " $a "," $a "," $b ";"
61 )
62 }
63 }
64
65 pub(super) fn compress(state: &mut [u32; 4], blocks: &[[u8; 64]]) {
66 if blocks.is_empty() {
67 return;
68 }
69
70 unsafe {
71 core::arch::asm!(
72 "42:",
73
74 "move $t0, $a4",
75 "move $t1, $a5",
76 "move $t2, $a6",
77 "move $t3, $a7",
78
79 /* 64 rounds of hashing */
80 round0!("$t0", "$t1", "$t2", "$t3", 0, 7, 0),
81 round0!("$t3", "$t0", "$t1", "$t2", 1, 12, 1),
82 round0!("$t2", "$t3", "$t0", "$t1", 2, 17, 2),
83 round0!("$t1", "$t2", "$t3", "$t0", 3, 22, 3),
84 round0!("$t0", "$t1", "$t2", "$t3", 4, 7, 4),
85 round0!("$t3", "$t0", "$t1", "$t2", 5, 12, 5),
86 round0!("$t2", "$t3", "$t0", "$t1", 6, 17, 6),
87 round0!("$t1", "$t2", "$t3", "$t0", 7, 22, 7),
88 round0!("$t0", "$t1", "$t2", "$t3", 8, 7, 8),
89 round0!("$t3", "$t0", "$t1", "$t2", 9, 12, 9),
90 round0!("$t2", "$t3", "$t0", "$t1", 10, 17, 10),
91 round0!("$t1", "$t2", "$t3", "$t0", 11, 22, 11),
92 round0!("$t0", "$t1", "$t2", "$t3", 12, 7, 12),
93 round0!("$t3", "$t0", "$t1", "$t2", 13, 12, 13),
94 round0!("$t2", "$t3", "$t0", "$t1", 14, 17, 14),
95 round0!("$t1", "$t2", "$t3", "$t0", 15, 22, 15),
96
97 round1!("$t0", "$t1", "$t2", "$t3", 1, 5, 16),
98 round1!("$t3", "$t0", "$t1", "$t2", 6, 9, 17),
99 round1!("$t2", "$t3", "$t0", "$t1", 11, 14, 18),
100 round1!("$t1", "$t2", "$t3", "$t0", 0, 20, 19),
101 round1!("$t0", "$t1", "$t2", "$t3", 5, 5, 20),
102 round1!("$t3", "$t0", "$t1", "$t2", 10, 9, 21),
103 round1!("$t2", "$t3", "$t0", "$t1", 15, 14, 22),
104 round1!("$t1", "$t2", "$t3", "$t0", 4, 20, 23),
105 round1!("$t0", "$t1", "$t2", "$t3", 9, 5, 24),
106 round1!("$t3", "$t0", "$t1", "$t2", 14, 9, 25),
107 round1!("$t2", "$t3", "$t0", "$t1", 3, 14, 26),
108 round1!("$t1", "$t2", "$t3", "$t0", 8, 20, 27),
109 round1!("$t0", "$t1", "$t2", "$t3", 13, 5, 28),
110 round1!("$t3", "$t0", "$t1", "$t2", 2, 9, 29),
111 round1!("$t2", "$t3", "$t0", "$t1", 7, 14, 30),
112
113 round1!("$t1", "$t2", "$t3", "$t0", 12, 20, 31),
114 round2!("$t0", "$t1", "$t2", "$t3", 5, 4, 32),
115 round2!("$t3", "$t0", "$t1", "$t2", 8, 11, 33),
116 round2!("$t2", "$t3", "$t0", "$t1", 11, 16, 34),
117 round2!("$t1", "$t2", "$t3", "$t0", 14, 23, 35),
118 round2!("$t0", "$t1", "$t2", "$t3", 1, 4, 36),
119 round2!("$t3", "$t0", "$t1", "$t2", 4, 11, 37),
120 round2!("$t2", "$t3", "$t0", "$t1", 7, 16, 38),
121 round2!("$t1", "$t2", "$t3", "$t0", 10, 23, 39),
122 round2!("$t0", "$t1", "$t2", "$t3", 13, 4, 40),
123 round2!("$t3", "$t0", "$t1", "$t2", 0, 11, 41),
124 round2!("$t2", "$t3", "$t0", "$t1", 3, 16, 42),
125 round2!("$t1", "$t2", "$t3", "$t0", 6, 23, 43),
126 round2!("$t0", "$t1", "$t2", "$t3", 9, 4, 44),
127 round2!("$t3", "$t0", "$t1", "$t2", 12, 11, 45),
128 round2!("$t2", "$t3", "$t0", "$t1", 15, 16, 46),
129 round2!("$t1", "$t2", "$t3", "$t0", 2, 23, 47),
130
131 round3!("$t0", "$t1", "$t2", "$t3", 0, 6, 48),
132 round3!("$t3", "$t0", "$t1", "$t2", 7, 10, 49),
133 round3!("$t2", "$t3", "$t0", "$t1", 14, 15, 50),
134 round3!("$t1", "$t2", "$t3", "$t0", 5, 21, 51),
135 round3!("$t0", "$t1", "$t2", "$t3", 12, 6, 52),
136 round3!("$t3", "$t0", "$t1", "$t2", 3, 10, 53),
137 round3!("$t2", "$t3", "$t0", "$t1", 10, 15, 54),
138 round3!("$t1", "$t2", "$t3", "$t0", 1, 21, 55),
139 round3!("$t0", "$t1", "$t2", "$t3", 8, 6, 56),
140 round3!("$t3", "$t0", "$t1", "$t2", 15, 10, 57),
141 round3!("$t2", "$t3", "$t0", "$t1", 6, 15, 58),
142 round3!("$t1", "$t2", "$t3", "$t0", 13, 21, 59),
143 round3!("$t0", "$t1", "$t2", "$t3", 4, 6, 60),
144 round3!("$t3", "$t0", "$t1", "$t2", 11, 10, 61),
145 round3!("$t2", "$t3", "$t0", "$t1", 2, 15, 62),
146 round3!("$t1", "$t2", "$t3", "$t0", 9, 21, 63),
147
148 "add.w $a4, $a4, $t0",
149 "add.w $a5, $a5, $t1",
150 "add.w $a6, $a6, $t2",
151 "add.w $a7, $a7, $t3",
152
153 // Looping over blocks
154 "addi.d $a1, $a1, 64",
155 "addi.d $a2, $a2, -1",
156 "bnez $a2, 42b",
157
158 inout("$a1") blocks.as_ptr() => _,
159 inout("$a2") blocks.len() => _,
160 in("$a3") crate::consts::RC.as_ptr(),
161 inout("$a4") state[0],
162 inout("$a5") state[1],
163 inout("$a6") state[2],
164 inout("$a7") state[3],
165
166 // Clobbers
167 out("$t0") _,
168 out("$t1") _,
169 out("$t2") _,
170 out("$t3") _,
171 out("$t4") _,
172 out("$t5") _,
173 out("$t6") _,
174
175 options(preserves_flags, readonly, pure, nostack),
176 );
177 }
178 }