xref: /openbmc/linux/arch/arm64/lib/crc32.S (revision 5d331b7f)
1/*
2 * Accelerated CRC32(C) using AArch64 CRC instructions
3 *
4 * Copyright (C) 2016 - 2018 Linaro Ltd <ard.biesheuvel@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/linkage.h>
12#include <asm/alternative.h>
13#include <asm/assembler.h>
14
15	.cpu		generic+crc
16
17	.macro		__crc32, c
180:	subs		x2, x2, #16
19	b.mi		8f
20	ldp		x3, x4, [x1], #16
21CPU_BE(	rev		x3, x3		)
22CPU_BE(	rev		x4, x4		)
23	crc32\c\()x	w0, w0, x3
24	crc32\c\()x	w0, w0, x4
25	b.ne		0b
26	ret
27
288:	tbz		x2, #3, 4f
29	ldr		x3, [x1], #8
30CPU_BE(	rev		x3, x3		)
31	crc32\c\()x	w0, w0, x3
324:	tbz		x2, #2, 2f
33	ldr		w3, [x1], #4
34CPU_BE(	rev		w3, w3		)
35	crc32\c\()w	w0, w0, w3
362:	tbz		x2, #1, 1f
37	ldrh		w3, [x1], #2
38CPU_BE(	rev16		w3, w3		)
39	crc32\c\()h	w0, w0, w3
401:	tbz		x2, #0, 0f
41	ldrb		w3, [x1]
42	crc32\c\()b	w0, w0, w3
430:	ret
44	.endm
45
46	.align		5
47ENTRY(crc32_le)
48alternative_if_not ARM64_HAS_CRC32
49	b		crc32_le_base
50alternative_else_nop_endif
51	__crc32
52ENDPROC(crc32_le)
53
54	.align		5
55ENTRY(__crc32c_le)
56alternative_if_not ARM64_HAS_CRC32
57	b		__crc32c_le_base
58alternative_else_nop_endif
59	__crc32		c
60ENDPROC(__crc32c_le)
61