158a5686c8f706929b2cb7eecbc951f4da0175ab
[platform/upstream/nettle.git] / arm / neon / umac-nh.asm
1 C arm/neon/umac-nh.asm
2
3 ifelse(<
4    Copyright (C) 2013 Niels Möller
5
6    This file is part of GNU Nettle.
7
8    GNU Nettle is free software: you can redistribute it and/or
9    modify it under the terms of either:
10
11      * the GNU Lesser General Public License as published by the Free
12        Software Foundation; either version 3 of the License, or (at your
13        option) any later version.
14
15    or
16
17      * the GNU General Public License as published by the Free
18        Software Foundation; either version 2 of the License, or (at your
19        option) any later version.
20
21    or both in parallel, as here.
22
23    GNU Nettle is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26    General Public License for more details.
27
28    You should have received copies of the GNU General Public License and
29    the GNU Lesser General Public License along with this program.  If
30    not, see http://www.gnu.org/licenses/.
31 >) 
32
33         .file "umac-nh.asm"
34         .fpu    neon
35
36 define(<KEY>, <r0>)
37 define(<LENGTH>, <r1>)
38 define(<MSG>, <r2>)
39 define(<SHIFT>, <r3>)
40
41 define(<QA>, <q0>)
42 define(<QB>, <q1>)
43 define(<DM>, <d16>)
44 define(<QLEFT>, <q9>)
45 define(<QRIGHT>, <q10>)
46 define(<QY>, <q11>)
47 define(<QT0>, <q12>)
48 define(<QT1>, <q13>)
49 define(<QK0>, <q14>)
50 define(<QK1>, <q15>)
51
52         .text
53         .align  3
54         
55 PROLOGUE(_nettle_umac_nh)
56         C Setup for 64-bit aligned reads
57         ands    SHIFT, MSG, #7
58         and     MSG, MSG, #-8
59         vld1.8  {DM}, [MSG :64]
60         addne   MSG, MSG, #8
61         addeq   SHIFT, SHIFT, #8
62
63         C FIXME: Combine as rsb ?
64         lsl     SHIFT, SHIFT, #3
65         neg     SHIFT, SHIFT
66
67         C Right shift in QRIGHT (both halves)
68         vmov.i32 D0REG(QRIGHT)[0], SHIFT
69         vmov.32  D1REG(QRIGHT), D0REG(QRIGHT)
70         add     SHIFT, SHIFT, #64
71         
72         vmov.i32 D0REG(QLEFT)[0], SHIFT
73         vmov.32  D1REG(QLEFT), D0REG(QLEFT)
74
75         vmov.i64 QY, #0
76
77         vshl.u64 DM, DM, D0REG(QRIGHT)
78 .Loop:
79         C Set m[i] <-- m[i-1] >> RSHIFT + m[i] << LSHIFT
80         vld1.8 {QA, QB}, [MSG :64]!
81         vshl.u64 QT0, QA, QRIGHT
82         vshl.u64 QT1, QB, QRIGHT
83         vshl.u64 QA, QA, QLEFT
84         vshl.u64 QB, QB, QLEFT
85         veor    D0REG(QA), D0REG(QA), DM
86         veor    D1REG(QA), D1REG(QA), D0REG(QT0)
87         veor    D0REG(QB), D0REG(QB), D1REG(QT0)
88         veor    D1REG(QB), D1REG(QB), D0REG(QT1)
89         vmov    DM, D1REG(QT1)
90
91         vld1.i32 {QK0, QK1}, [KEY]!
92         vadd.i32 QA, QA, QK0
93         vadd.i32 QB, QB, QK1
94         subs    LENGTH, LENGTH, #32
95         vmlal.u32 QY, D0REG(QA), D0REG(QB)
96         vmlal.u32 QY, D1REG(QA), D1REG(QB)
97         bhi     .Loop
98
99         vadd.i64 D0REG(QY), D0REG(QY), D1REG(QY)
100         vmov    r0, r1, D0REG(QY)
101         bx      lr
102 EPILOGUE(_nettle_umac_nh)