blob: e1554766fe1dc015ce96eb7af9617d2d533e03b9 [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001dnl SPARC mpn_rshift -- Shift a number right.
2
3dnl Copyright 1995, 1996, 2000 Free Software Foundation, Inc.
4
5dnl This file is part of the GNU MP Library.
6dnl
7dnl The GNU MP Library is free software; you can redistribute it and/or modify
8dnl it under the terms of either:
9dnl
10dnl * the GNU Lesser General Public License as published by the Free
11dnl Software Foundation; either version 3 of the License, or (at your
12dnl option) any later version.
13dnl
14dnl or
15dnl
16dnl * the GNU General Public License as published by the Free Software
17dnl Foundation; either version 2 of the License, or (at your option) any
18dnl later version.
19dnl
20dnl or both in parallel, as here.
21dnl
22dnl The GNU MP Library is distributed in the hope that it will be useful, but
23dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25dnl for more details.
26dnl
27dnl You should have received copies of the GNU General Public License and the
28dnl GNU Lesser General Public License along with the GNU MP Library. If not,
29dnl see https://www.gnu.org/licenses/.
30
31
32include(`../config.m4')
33
34C INPUT PARAMETERS
35C res_ptr %o0
36C src_ptr %o1
37C size %o2
38C cnt %o3
39
40ASM_START()
41PROLOGUE(mpn_rshift)
42 ld [%o1],%g2 C load first limb
43 sub %g0,%o3,%o5 C negate shift count
44 add %o2,-1,%o2
45 andcc %o2,4-1,%g4 C number of limbs in first loop
46 sll %g2,%o5,%g1 C compute function result
47 be L(0) C if multiple of 4 limbs, skip first loop
48 st %g1,[%sp+80]
49
50 sub %o2,%g4,%o2 C adjust count for main loop
51
52L(loop0):
53 ld [%o1+4],%g3
54 add %o0,4,%o0
55 add %o1,4,%o1
56 addcc %g4,-1,%g4
57 srl %g2,%o3,%o4
58 sll %g3,%o5,%g1
59 mov %g3,%g2
60 or %o4,%g1,%o4
61 bne L(loop0)
62 st %o4,[%o0-4]
63
64L(0): tst %o2
65 be L(end)
66 nop
67
68L(loop):
69 ld [%o1+4],%g3
70 add %o0,16,%o0
71 addcc %o2,-4,%o2
72 srl %g2,%o3,%o4
73 sll %g3,%o5,%g1
74
75 ld [%o1+8],%g2
76 srl %g3,%o3,%g4
77 or %o4,%g1,%o4
78 st %o4,[%o0-16]
79 sll %g2,%o5,%g1
80
81 ld [%o1+12],%g3
82 srl %g2,%o3,%o4
83 or %g4,%g1,%g4
84 st %g4,[%o0-12]
85 sll %g3,%o5,%g1
86
87 ld [%o1+16],%g2
88 srl %g3,%o3,%g4
89 or %o4,%g1,%o4
90 st %o4,[%o0-8]
91 sll %g2,%o5,%g1
92
93 add %o1,16,%o1
94 or %g4,%g1,%g4
95 bne L(loop)
96 st %g4,[%o0-4]
97
98L(end): srl %g2,%o3,%g2
99 st %g2,[%o0-0]
100 retl
101 ld [%sp+80],%o0
102EPILOGUE(mpn_rshift)