1d7f27102SMichael Tuexen/*- 2d7f27102SMichael Tuexen * Copyright (c) 2017 Michael Tuexen 3d7f27102SMichael Tuexen * All rights reserved. 4d7f27102SMichael Tuexen * 5d7f27102SMichael Tuexen * Redistribution and use in source and binary forms, with or without 6d7f27102SMichael Tuexen * modification, are permitted provided that the following conditions 7d7f27102SMichael Tuexen * are met: 8d7f27102SMichael Tuexen * 1. Redistributions of source code must retain the above copyright 9d7f27102SMichael Tuexen * notice, this list of conditions and the following disclaimer. 10d7f27102SMichael Tuexen * 2. Redistributions in binary form must reproduce the above copyright 11d7f27102SMichael Tuexen * notice, this list of conditions and the following disclaimer in the 12d7f27102SMichael Tuexen * documentation and/or other materials provided with the distribution. 13d7f27102SMichael Tuexen * 14d7f27102SMichael Tuexen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15d7f27102SMichael Tuexen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16d7f27102SMichael Tuexen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17d7f27102SMichael Tuexen * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18d7f27102SMichael Tuexen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19d7f27102SMichael Tuexen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20d7f27102SMichael Tuexen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21d7f27102SMichael Tuexen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22d7f27102SMichael Tuexen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23d7f27102SMichael Tuexen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24d7f27102SMichael Tuexen * SUCH DAMAGE. 25d7f27102SMichael Tuexen * 26d7f27102SMichael Tuexen */ 27d7f27102SMichael Tuexen 28d7f27102SMichael Tuexen#include <machine/asm.h> 29*25d0310eSAndrew Turner#include <sys/elf_common.h> 30*25d0310eSAndrew Turner 310ec3e991SAndrew Turner.arch_extension crc 32d7f27102SMichael Tuexen 33d7f27102SMichael Tuexen/* 34d7f27102SMichael Tuexen * uint32_t 35d7f27102SMichael Tuexen * armv8_crc32c(uint32_t crc, const unsigned char *buf, unsigned int len) 36d7f27102SMichael Tuexen */ 37d7f27102SMichael Tuexen 38d7f27102SMichael TuexenENTRY(armv8_crc32c) 39d7f27102SMichael Tuexen cbz w2, end 40d7f27102SMichael Tuexen tbz x1, #0x0, half_word_aligned 41d7f27102SMichael Tuexen sub w2, w2, 0x1 42d7f27102SMichael Tuexen ldr w10, [x1], #0x1 43d7f27102SMichael Tuexen crc32cb w0, w0, w10 44d7f27102SMichael Tuexenhalf_word_aligned: 45d7f27102SMichael Tuexen cmp w2, #0x2 46d7f27102SMichael Tuexen b.lo last_byte 47d7f27102SMichael Tuexen tbz x1, #0x1, word_aligned 48d7f27102SMichael Tuexen sub w2, w2, 0x2 49d7f27102SMichael Tuexen ldr w10, [x1], #0x2 50d7f27102SMichael Tuexen crc32ch w0, w0, w10 51d7f27102SMichael Tuexenword_aligned: 52d7f27102SMichael Tuexen cmp w2, #0x4 53d7f27102SMichael Tuexen b.lo last_half_word 54d7f27102SMichael Tuexen tbz x1, #0x2, double_word_aligned 55d7f27102SMichael Tuexen sub w2, w2, 0x4 56d7f27102SMichael Tuexen ldr w10, [x1], #0x4 57d7f27102SMichael Tuexen crc32cw w0, w0, w10 58d7f27102SMichael Tuexendouble_word_aligned: 59d7f27102SMichael Tuexen lsr w9, w2, #0x3 60d7f27102SMichael Tuexen cbz w9, last_word 61d7f27102SMichael Tuexenloop: 62d7f27102SMichael Tuexen ldr x10, [x1], #0x8 63d7f27102SMichael Tuexen crc32cx w0, w0, x10 64d7f27102SMichael Tuexen subs w9, w9, #1 65d7f27102SMichael Tuexen b.ne loop 66d7f27102SMichael Tuexenlast_word: 67d7f27102SMichael Tuexen tbz w2, #0x2, last_half_word 68d7f27102SMichael Tuexen ldr w10, [x1], #0x4 69d7f27102SMichael Tuexen crc32cw w0, w0, w10 70d7f27102SMichael Tuexenlast_half_word: 71d7f27102SMichael Tuexen tbz w2, #0x1, last_byte 72d7f27102SMichael Tuexen ldr w10, [x1], #0x2 73d7f27102SMichael Tuexen crc32ch w0, w0, w10 74d7f27102SMichael Tuexenlast_byte: 75d7f27102SMichael Tuexen tbz w2, #0x0, end 76d7f27102SMichael Tuexen ldr w10, [x1], #0x1 77d7f27102SMichael Tuexen crc32cb w0, w0, w10 78d7f27102SMichael Tuexenend: 79d7f27102SMichael Tuexen ret 80d7f27102SMichael TuexenEND(armv8_crc32c) 81*25d0310eSAndrew Turner 82*25d0310eSAndrew TurnerGNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) 83