| 1 |
//+build !noasm |
| 2 |
//+build !appengine |
| 3 |
//+build !gccgo |
| 4 |
//+build !nopshufb |
| 5 |
|
| 6 |
// Copyright 2015, Klaus Post, see LICENSE for details. |
| 7 |
// Copyright 2017, Minio, Inc. |
| 8 |
|
| 9 |
#include "textflag.h" |
| 10 |
|
| 11 |
#define LOAD(LO1, LO2, HI1, HI2) \ |
| 12 |
VLD1.P 32(R1), [LO1.B16, LO2.B16] \ |
| 13 |
\ |
| 14 |
\ // Get low input and high input |
| 15 |
VUSHR $4, LO1.B16, HI1.B16 \ |
| 16 |
VUSHR $4, LO2.B16, HI2.B16 \ |
| 17 |
VAND V8.B16, LO1.B16, LO1.B16 \ |
| 18 |
VAND V8.B16, LO2.B16, LO2.B16 |
| 19 |
|
| 20 |
#define GALOIS_MUL(MUL_LO, MUL_HI, OUT1, OUT2, TMP1, TMP2) \ |
| 21 |
\ // Mul low part and mul high part |
| 22 |
VTBL V0.B16, [MUL_LO.B16], OUT1.B16 \ |
| 23 |
VTBL V10.B16, [MUL_HI.B16], OUT2.B16 \ |
| 24 |
VTBL V1.B16, [MUL_LO.B16], TMP1.B16 \ |
| 25 |
VTBL V11.B16, [MUL_HI.B16], TMP2.B16 \ |
| 26 |
\ |
| 27 |
\ // Combine results |
| 28 |
VEOR OUT2.B16, OUT1.B16, OUT1.B16 \ |
| 29 |
VEOR TMP2.B16, TMP1.B16, OUT2.B16 |
| 30 |
|
| 31 |
// func galMulNEON(low, high, in, out []byte) |
| 32 |
TEXT ·galMulNEON(SB), 7, $0 |
| 33 |
MOVD in_base+48(FP), R1 |
| 34 |
MOVD in_len+56(FP), R2 // length of message |
| 35 |
MOVD out_base+72(FP), R5 |
| 36 |
SUBS $32, R2 |
| 37 |
BMI complete |
| 38 |
|
| 39 |
MOVD low+0(FP), R10 // R10: &low |
| 40 |
MOVD high+24(FP), R11 // R11: &high |
| 41 |
VLD1 (R10), [V6.B16] |
| 42 |
VLD1 (R11), [V7.B16] |
| 43 |
|
| 44 |
// |
| 45 |
// Use an extra instruction below since `VDUP R3, V8.B16` generates assembler error |
| 46 |
// WORD $0x4e010c68 // dup v8.16b, w3 |
| 47 |
// |
| 48 |
MOVD $0x0f, R3 |
| 49 |
VMOV R3, V8.B[0] |
| 50 |
VDUP V8.B[0], V8.B16 |
| 51 |
|
| 52 |
loop: |
| 53 |
// Main loop |
| 54 |
LOAD(V0, V1, V10, V11) |
| 55 |
GALOIS_MUL(V6, V7, V4, V5, V14, V15) |
| 56 |
|
| 57 |
// Store result |
| 58 |
VST1.P [V4.D2, V5.D2], 32(R5) |
| 59 |
|
| 60 |
SUBS $32, R2 |
| 61 |
BPL loop |
| 62 |
|
| 63 |
complete: |
| 64 |
RET |
| 65 |
|
| 66 |
// func galMulXorNEON(low, high, in, out []byte) |
| 67 |
TEXT ·galMulXorNEON(SB), 7, $0 |
| 68 |
MOVD in_base+48(FP), R1 |
| 69 |
MOVD in_len+56(FP), R2 // length of message |
| 70 |
MOVD out_base+72(FP), R5 |
| 71 |
SUBS $32, R2 |
| 72 |
BMI completeXor |
| 73 |
|
| 74 |
MOVD low+0(FP), R10 // R10: &low |
| 75 |
MOVD high+24(FP), R11 // R11: &high |
| 76 |
VLD1 (R10), [V6.B16] |
| 77 |
VLD1 (R11), [V7.B16] |
| 78 |
|
| 79 |
// |
| 80 |
// Use an extra instruction below since `VDUP R3, V8.B16` generates assembler error |
| 81 |
// WORD $0x4e010c68 // dup v8.16b, w3 |
| 82 |
// |
| 83 |
MOVD $0x0f, R3 |
| 84 |
VMOV R3, V8.B[0] |
| 85 |
VDUP V8.B[0], V8.B16 |
| 86 |
|
| 87 |
loopXor: |
| 88 |
// Main loop |
| 89 |
VLD1 (R5), [V20.B16, V21.B16] |
| 90 |
|
| 91 |
LOAD(V0, V1, V10, V11) |
| 92 |
GALOIS_MUL(V6, V7, V4, V5, V14, V15) |
| 93 |
|
| 94 |
VEOR V20.B16, V4.B16, V4.B16 |
| 95 |
VEOR V21.B16, V5.B16, V5.B16 |
| 96 |
|
| 97 |
// Store result |
| 98 |
VST1.P [V4.D2, V5.D2], 32(R5) |
| 99 |
|
| 100 |
SUBS $32, R2 |
| 101 |
BPL loopXor |
| 102 |
|
| 103 |
completeXor: |
| 104 |
RET |
| 105 |
|
| 106 |
TEXT ·getVectorLength(SB), NOSPLIT, $0 |
| 107 |
WORD $0xd2800002 // mov x2, #0 |
| 108 |
WORD $0x04225022 // addvl x2, x2, #1 |
| 109 |
WORD $0xd37df042 // lsl x2, x2, #3 |
| 110 |
WORD $0xd2800003 // mov x3, #0 |
| 111 |
WORD $0x04635023 // addpl x3, x3, #1 |
| 112 |
WORD $0xd37df063 // lsl x3, x3, #3 |
| 113 |
MOVD R2, vl+0(FP) |
| 114 |
MOVD R3, pl+8(FP) |
| 115 |
RET |