2019-06-03 03:09:33 +02:00
|
|
|
########################################################################
|
|
|
|
# Copyright(c) 2019 Arm Corporation All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in
|
|
|
|
# the documentation and/or other materials provided with the
|
|
|
|
# distribution.
|
|
|
|
# * Neither the name of Arm Corporation nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#########################################################################
|
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
#include "crc_common_pmull.h"
|
|
|
|
|
2019-06-03 03:09:33 +02:00
|
|
|
.macro crc32_norm_func name:req
|
2019-10-10 19:15:52 +02:00
|
|
|
.arch armv8-a+crypto
|
2019-06-03 03:09:33 +02:00
|
|
|
.text
|
|
|
|
.align 3
|
2020-11-21 17:51:37 +01:00
|
|
|
.global cdecl(\name)
|
|
|
|
#ifndef __APPLE__
|
2019-06-03 03:09:33 +02:00
|
|
|
.type \name, %function
|
2020-11-21 17:51:37 +01:00
|
|
|
#endif
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
/* uint32_t crc32_norm_func(uint32_t seed, uint8_t * buf, uint64_t len) */
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2020-11-21 17:51:37 +01:00
|
|
|
cdecl(\name\()):
|
2019-06-03 03:09:33 +02:00
|
|
|
mvn w_seed, w_seed
|
2019-10-10 19:15:52 +02:00
|
|
|
mov x_counter, 0
|
2019-06-03 03:09:33 +02:00
|
|
|
cmp x_len, (FOLD_SIZE - 1)
|
2019-10-10 19:15:52 +02:00
|
|
|
bhi .crc_clmul_pre
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
.crc_tab_pre:
|
|
|
|
cmp x_len, x_counter
|
2019-06-03 03:09:33 +02:00
|
|
|
bls .done
|
|
|
|
|
2020-11-21 17:51:37 +01:00
|
|
|
#ifndef __APPLE__
|
2019-10-10 19:15:52 +02:00
|
|
|
adrp x_tmp, .lanchor_crc_tab
|
|
|
|
add x_buf_iter, x_buf, x_counter
|
|
|
|
add x_buf, x_buf, x_len
|
|
|
|
add x_crc_tab_addr, x_tmp, :lo12:.lanchor_crc_tab
|
2020-11-21 17:51:37 +01:00
|
|
|
#else
|
|
|
|
adrp x_tmp, .lanchor_crc_tab@PAGE
|
|
|
|
add x_buf_iter, x_buf, x_counter
|
|
|
|
add x_buf, x_buf, x_len
|
|
|
|
add x_crc_tab_addr, x_tmp, .lanchor_crc_tab@PAGEOFF
|
|
|
|
#endif
|
2019-06-03 03:09:33 +02:00
|
|
|
|
|
|
|
.align 3
|
2019-10-10 19:15:52 +02:00
|
|
|
.loop_crc_tab:
|
|
|
|
ldrb w_tmp, [x_buf_iter], 1
|
|
|
|
cmp x_buf, x_buf_iter
|
|
|
|
eor w_tmp, w_tmp, w_seed, lsr 24
|
|
|
|
ldr w_tmp, [x_crc_tab_addr, w_tmp, uxtw 2]
|
|
|
|
eor w_seed, w_tmp, w_seed, lsl 8
|
|
|
|
bhi .loop_crc_tab
|
2019-06-03 03:09:33 +02:00
|
|
|
|
|
|
|
.done:
|
2019-10-10 19:15:52 +02:00
|
|
|
mvn w_crc_ret, w_seed
|
2019-06-03 03:09:33 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.align 2
|
2019-10-10 19:15:52 +02:00
|
|
|
.crc_clmul_pre:
|
2019-06-03 03:09:33 +02:00
|
|
|
lsl x_seed, x_seed, 32
|
2019-10-10 19:15:52 +02:00
|
|
|
movi v_x0.2s, 0
|
|
|
|
fmov v_x0.d[1], x_seed // save crc to v_x0
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
crc_norm_load_first_block
|
2019-06-03 03:09:33 +02:00
|
|
|
|
|
|
|
bls .clmul_loop_end
|
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
crc32_load_p4
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
// 1024bit --> 512bit loop
|
|
|
|
// merge x0, x1, x2, x3, y0, y1, y2, y3 => x0, x1, x2, x3 (uint64x2_t)
|
|
|
|
crc_norm_loop
|
2019-06-03 03:09:33 +02:00
|
|
|
|
|
|
|
.clmul_loop_end:
|
|
|
|
// folding 512bit --> 128bit
|
2019-10-10 19:15:52 +02:00
|
|
|
crc32_fold_512b_to_128b
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
// folding 128bit --> 64bit
|
|
|
|
mov x_tmp, p0_high_b0
|
|
|
|
movk x_tmp, p0_high_b1, lsl 16
|
|
|
|
fmov d_p0_high, x_tmp
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
mov x_tmp2, p0_low_b0
|
|
|
|
movk x_tmp2, p0_low_b1, lsl 16
|
|
|
|
fmov d_p0_high2, x_tmp2
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
mov d_tmp_high, v_x3.d[0]
|
|
|
|
ext v_tmp_high.16b, v_tmp_high.16b, v_tmp_high.16b, #12
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
pmull2 v_x3.1q, v_x3.2d, v_p0.2d
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
eor v_tmp_high.16b, v_tmp_high.16b, v_x3.16b
|
|
|
|
pmull2 v_x3.1q, v_tmp_high.2d, v_p02.2d
|
2019-06-03 03:09:33 +02:00
|
|
|
|
|
|
|
// barrett reduction
|
2019-10-10 19:15:52 +02:00
|
|
|
mov x_tmp2, br_high_b0
|
|
|
|
movk x_tmp2, br_high_b1, lsl 16
|
|
|
|
movk x_tmp2, br_high_b2, lsl 32
|
|
|
|
fmov d_br_high, x_tmp2
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
mov x_tmp, br_low_b0
|
|
|
|
movk x_tmp, br_low_b1, lsl 16
|
|
|
|
movk x_tmp, br_low_b2, lsl 32
|
|
|
|
fmov d_br_low, x_tmp
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
eor v_tmp_high.16b, v_tmp_high.16b, v_x3.16b
|
|
|
|
mov s_x3, v_tmp_high.s[1]
|
|
|
|
pmull v_x3.1q, v_x3.1d, v_br_low.1d
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
mov s_x3, v_x3.s[1]
|
|
|
|
pmull v_x3.1q, v_x3.1d, v_br_high.1d
|
|
|
|
eor v_tmp_high.8b, v_tmp_high.8b, v_x3.8b
|
|
|
|
umov w_seed, v_tmp_high.s[0]
|
2019-06-03 03:09:33 +02:00
|
|
|
|
2019-10-10 19:15:52 +02:00
|
|
|
b .crc_tab_pre
|
2020-11-21 17:51:37 +01:00
|
|
|
#ifndef __APPLE__
|
2019-06-03 03:09:33 +02:00
|
|
|
.size \name, .-\name
|
2019-10-10 19:15:52 +02:00
|
|
|
.section .rodata.cst16,"aM",@progbits,16
|
2020-11-21 17:51:37 +01:00
|
|
|
#else
|
|
|
|
.section __TEXT,__const
|
|
|
|
#endif
|
2019-06-03 03:09:33 +02:00
|
|
|
.align 4
|
2019-10-10 19:15:52 +02:00
|
|
|
.shuffle_data:
|
2019-06-03 03:09:33 +02:00
|
|
|
.byte 15, 14, 13, 12, 11, 10, 9
|
|
|
|
.byte 8, 7, 6, 5, 4, 3, 2, 1, 0
|
|
|
|
.endm
|