1 dnl ARM Neon mpn_lshiftc.
3 dnl Contributed to the GNU project by Torbjörn Granlund.
5 dnl Copyright
2013 Free Software Foundation
, Inc.
7 dnl
This file is part of the GNU MP Library.
9 dnl The GNU MP Library is free software
; you can redistribute it and/or modify
10 dnl it under the terms of
either:
12 dnl
* the GNU Lesser General
Public License as published by the Free
13 dnl Software Foundation
; either version 3 of the License, or (at your
14 dnl option
) any later version.
18 dnl
* the GNU General
Public License as published by the Free Software
19 dnl Foundation
; either version 2 of the License, or (at your option) any
22 dnl
or both
in parallel
, as here.
24 dnl The GNU MP Library is distributed
in the hope that it will be useful
, but
25 dnl WITHOUT ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY
26 dnl
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License
29 dnl You should have received copies of the GNU General
Public License
and the
30 dnl GNU Lesser General
Public License along with the GNU MP Library. If
not,
31 dnl see
https://www.gnu.
org/licenses
/.
33 include(`..
/config.m4
')
35 C cycles/limb cycles/limb cycles/limb good
36 C aligned unaligned best seen for cpu?
42 C Cortex-A15 1.75 1.75 Y
45 C We read 64 bits at a time at 32-bit aligned addresses, and except for the
46 C first and last store, we write using 64-bit aligned addresses. All shifting
47 C is done on 64-bit words in 'extension
' registers.
49 C It should be possible to read also using 64-bit alignment, by manipulating
50 C the shift count for unaligned operands. Not done, since it does not seem to
51 C matter for A9 or A15.
53 C This will not work in big-endian mode.
56 C * Try using 128-bit operations. Note that Neon lacks pure 128-bit shifts,
57 C which might make it tricky.
58 C * Clean up and simplify.
59 C * Consider sharing most of the code for lshift and rshift, since the feed-in
60 C code, the loop, and most of the wind-down code are identical.
61 C * Replace the basecase code with code using 'extension
' registers.
62 C * Optimise. It is not clear that this loop insn permutation is optimal for
75 define(`func',`mpn_lshiftc
')
76 define(`OPERATION_lshiftc',1)
82 IFLSH
(`
mov r12
, n
, lsl #
2 ')
83 IFLSH(` add rp, rp, r12 ')
84 IFLSH
(`
add ap
, ap
, r12
')
86 cmp n, #4 C SIMD code n limit
89 ifdef(`OPERATION_lshiftc',`
90 vdup
.32 d6
, r3 C left shift count is positive
91 sub r3
, r3
, #
64 C right shift count is negative
93 mov r12
, #
-8') C lshift pointer update offset
94 ifdef(`OPERATION_rshift',`
95 rsb r3
, r3
, #
0 C right shift count is negative
97 add r3
, r3
, #
64 C left shift count is positive
99 mov r12
, #
8') C rshift pointer update offset
101 IFLSH(` sub ap, ap, #8 ')
102 vld1.32
{d19}, [ap
], r12 C load initial
2 limbs
103 vshl.u64 d18
, d19
, d7 C retval
105 tst rp
, #
4 C is rp
64-bit aligned already
?
106 beq L
(rp_aligned
) C yes
, skip
108 IFLSH
(`
add ap
, ap
, #
4 ') C move back ap pointer
109 IFRSH(` sub ap, ap, #4 ') C move back ap pointer
111 sub n
, n
, #
1 C first limb handled
112 IFLSH
(`
sub rp
, rp
, #
4 ')
113 vst1.32 {d4[Y]}, [rp]IFRSH(!) C store first limb, rp gets aligned
114 vld1.32 {d19}, [ap], r12 C load ap[1] and ap[2]
117 IFLSH(` sub rp, rp, #8 ')
120 blt L
(two_or_three_more
)
124 L
(1): vld1.32
{d17}, [ap
], r12
127 vld1.32
{d16}, [ap
], r12
133 L
(2): vld1.32
{d16}, [ap
], r12
136 vld1.32
{d17}, [ap
], r12
142 L
(top
): vmvn d17
, d17
143 vld1.32
{d16}, [ap
], r12
147 vst1.32
{d2}, [rp:64], r12
148 L
(mid
): vmvn d16
, d16
149 vld1.32
{d17}, [ap
], r12
153 vst1.32
{d3}, [rp:64], r12
161 vst1.32
{d2}, [rp:64], r12
164 L
(evn
): vmvn d17
, d17
168 vst1.32
{d2}, [rp:64], r12
175 C Load last
2 - 3 limbs
, store last
4 - 5 limbs
176 L
(two_or_three_more
):
180 L
(l3
): vshl.u64 d5
, d19
, d6
181 vld1.32
{d17}, [ap
], r12
182 L
(cj1
): vmov.u8 d16
, #
0
183 IFLSH
(`
add ap
, ap
, #
4 ')
185 vld1.32 {d16[Y]}, [ap], r12
192 vst1.32 {d3}, [rp:64], r12
194 vst1.32 {d2}, [rp:64], r12
195 IFLSH(` add rp, rp, #4 ')
196 vst1.32
{d5[Y]}, [rp
]
200 L
(l2
): vld1.32
{d16}, [ap
], r12
209 L
(cj2
): vst1.32
{d2}, [rp:64], r12
217 push {r4, r6, r7, r8}
232 L
(ev
): ldr r6
, [ap
, #
-4]!
237 L
(tp
): ldr r8
, [ap
, #
-4]!
238 orr r7
, r7
, r6
, lsr tnc
242 L
(md
): ldr r6
, [ap
, #
-4]!
243 orr r7
, r7
, r8
, lsr tnc
248 L
(ed
): orr r7
, r7
, r6
, lsr tnc
252 orr r7
, r7
, r6
, lsr tnc