summaryrefslogtreecommitdiff
path: root/mpn/a29k/rshift.s
blob: fe53b71e2467738289579f7c3aade9b47da05a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
; 29000 __mpn_rshift --

; Copyright (C) 1992, 1994 Free Software Foundation, Inc.

; This file is part of the GNU MP Library.

; The GNU MP Library is free software; you can redistribute it and/or modify
; it under the terms of the GNU Library General Public License as published by
; the Free Software Foundation; either version 2 of the License, or (at your
; option) any later version.

; The GNU MP Library is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
; License for more details.

; You should have received a copy of the GNU Library General Public License
; along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
; MA 02111-1307, USA.


; INPUT PARAMETERS
; res_ptr	lr2
; s1_ptr	lr3
; s2_ptr	lr4
; size		lr5

; We use the loadm/storem instructions and operate on chunks of 8
; limbs/per iteration, until less than 8 limbs remain.

	.sect .lit,lit
	.text
	.align	4
	.global	___mpn_rshift
	.word	0x60000
___mpn_rshift:
	load	0,0,gr119,lr3
	add	lr3,lr3,4

	subr	gr116,lr5,32
	sll	gr96,gr119,gr116	; return value
	sub	lr4,lr4,1		; actual loop count is SIZE - 1

	srl	gr117,lr4,3		; chuck count = (actual count) / 8
	cpeq	gr118,gr117,0
	jmpt	gr118,Ltail
	 mtsr	fc,gr116

	sub	gr117,gr117,2		; count for jmpfdec

; Main loop working 8 limbs/iteration.
Loop:	mtsrim	cr,(8-1)
	loadm	0,0,gr100,lr3
	add	lr3,lr3,32

	extract	gr98,gr100,gr119
	extract	gr99,gr101,gr100
	extract	gr100,gr102,gr101
	extract	gr101,gr103,gr102
	extract	gr102,gr104,gr103
	extract	gr103,gr105,gr104
	extract	gr104,gr106,gr105
	extract	gr105,gr107,gr106

	mtsrim	cr,(8-1)
	storem	0,0,gr98,lr2
	add	lr2,lr2,32
	jmpfdec	gr117,Loop
	 or	gr119,gr107,0

; Code for the last up-to-7 limbs.

	and	lr4,lr4,(8-1)
Ltail:	cpeq	gr118,lr4,0
	jmpt	gr118,Lend
	 sub	lr4,lr4,2		; count for jmpfdec

Loop2:	load	0,0,gr100,lr3
	add	lr3,lr3,4
	extract	gr117,gr100,gr119
	store	0,0,gr117,lr2
	add	lr2,lr2,4
	jmpfdec	lr4,Loop2
	 or	gr119,gr100,0

Lend:	srl	gr117,gr119,lr5
	jmpi	lr0
	 store	0,0,gr117,lr2