1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arch/arm/include/asm/xor.h
5 * Copyright (C) 2001 Russell King
7 #include <linux/hardirq.h>
8 #include <asm-generic/xor.h>
12 #define __XOR(a1, a2) a1 ^= a2
14 #define GET_BLOCK_2(dst) \
15 __asm__("ldmia %0, {%1, %2}" \
16 : "=r" (dst), "=r" (a1), "=r" (a2) \
19 #define GET_BLOCK_4(dst) \
20 __asm__("ldmia %0, {%1, %2, %3, %4}" \
21 : "=r" (dst), "=r" (a1), "=r" (a2), "=r" (a3), "=r" (a4) \
24 #define XOR_BLOCK_2(src) \
25 __asm__("ldmia %0!, {%1, %2}" \
26 : "=r" (src), "=r" (b1), "=r" (b2) \
28 __XOR(a1, b1); __XOR(a2, b2);
30 #define XOR_BLOCK_4(src) \
31 __asm__("ldmia %0!, {%1, %2, %3, %4}" \
32 : "=r" (src), "=r" (b1), "=r" (b2), "=r" (b3), "=r" (b4) \
34 __XOR(a1, b1); __XOR(a2, b2); __XOR(a3, b3); __XOR(a4, b4)
36 #define PUT_BLOCK_2(dst) \
37 __asm__ __volatile__("stmia %0!, {%2, %3}" \
39 : "0" (dst), "r" (a1), "r" (a2))
41 #define PUT_BLOCK_4(dst) \
42 __asm__ __volatile__("stmia %0!, {%2, %3, %4, %5}" \
44 : "0" (dst), "r" (a1), "r" (a2), "r" (a3), "r" (a4))
47 xor_arm4regs_2(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
)
49 unsigned int lines
= bytes
/ sizeof(unsigned long) / 4;
50 register unsigned int a1
__asm__("r4");
51 register unsigned int a2
__asm__("r5");
52 register unsigned int a3
__asm__("r6");
53 register unsigned int a4
__asm__("r7");
54 register unsigned int b1
__asm__("r8");
55 register unsigned int b2
__asm__("r9");
56 register unsigned int b3
__asm__("ip");
57 register unsigned int b4
__asm__("lr");
67 xor_arm4regs_3(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
70 unsigned int lines
= bytes
/ sizeof(unsigned long) / 4;
71 register unsigned int a1
__asm__("r4");
72 register unsigned int a2
__asm__("r5");
73 register unsigned int a3
__asm__("r6");
74 register unsigned int a4
__asm__("r7");
75 register unsigned int b1
__asm__("r8");
76 register unsigned int b2
__asm__("r9");
77 register unsigned int b3
__asm__("ip");
78 register unsigned int b4
__asm__("lr");
89 xor_arm4regs_4(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
90 unsigned long *p3
, unsigned long *p4
)
92 unsigned int lines
= bytes
/ sizeof(unsigned long) / 2;
93 register unsigned int a1
__asm__("r8");
94 register unsigned int a2
__asm__("r9");
95 register unsigned int b1
__asm__("ip");
96 register unsigned int b2
__asm__("lr");
108 xor_arm4regs_5(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
109 unsigned long *p3
, unsigned long *p4
, unsigned long *p5
)
111 unsigned int lines
= bytes
/ sizeof(unsigned long) / 2;
112 register unsigned int a1
__asm__("r8");
113 register unsigned int a2
__asm__("r9");
114 register unsigned int b1
__asm__("ip");
115 register unsigned int b2
__asm__("lr");
127 static struct xor_block_template xor_block_arm4regs
= {
129 .do_2
= xor_arm4regs_2
,
130 .do_3
= xor_arm4regs_3
,
131 .do_4
= xor_arm4regs_4
,
132 .do_5
= xor_arm4regs_5
,
135 #undef XOR_TRY_TEMPLATES
136 #define XOR_TRY_TEMPLATES \
138 xor_speed(&xor_block_arm4regs); \
139 xor_speed(&xor_block_8regs); \
140 xor_speed(&xor_block_32regs); \
144 #ifdef CONFIG_KERNEL_MODE_NEON
146 extern struct xor_block_template
const xor_block_neon_inner
;
149 xor_neon_2(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
)
151 if (in_interrupt()) {
152 xor_arm4regs_2(bytes
, p1
, p2
);
155 xor_block_neon_inner
.do_2(bytes
, p1
, p2
);
161 xor_neon_3(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
164 if (in_interrupt()) {
165 xor_arm4regs_3(bytes
, p1
, p2
, p3
);
168 xor_block_neon_inner
.do_3(bytes
, p1
, p2
, p3
);
174 xor_neon_4(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
175 unsigned long *p3
, unsigned long *p4
)
177 if (in_interrupt()) {
178 xor_arm4regs_4(bytes
, p1
, p2
, p3
, p4
);
181 xor_block_neon_inner
.do_4(bytes
, p1
, p2
, p3
, p4
);
187 xor_neon_5(unsigned long bytes
, unsigned long *p1
, unsigned long *p2
,
188 unsigned long *p3
, unsigned long *p4
, unsigned long *p5
)
190 if (in_interrupt()) {
191 xor_arm4regs_5(bytes
, p1
, p2
, p3
, p4
, p5
);
194 xor_block_neon_inner
.do_5(bytes
, p1
, p2
, p3
, p4
, p5
);
199 static struct xor_block_template xor_block_neon
= {
207 #define NEON_TEMPLATES \
208 do { if (cpu_has_neon()) xor_speed(&xor_block_neon); } while (0)
210 #define NEON_TEMPLATES