1;   Copyright (C) 2012-2020 Free Software Foundation, Inc.
2;   Contributed by Red Hat.
3;
4; This file is free software; you can redistribute it and/or modify it
5; under the terms of the GNU General Public License as published by the
6; Free Software Foundation; either version 3, or (at your option) any
7; later version.
8;
9; This file is distributed in the hope that it will be useful, but
10; WITHOUT ANY WARRANTY; without even the implied warranty of
11; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12; General Public License for more details.
13;
14; Under Section 7 of GPL version 3, you are granted additional
15; permissions described in the GCC Runtime Library Exception, version
16; 3.1, as published by the Free Software Foundation.
17;
18; You should have received a copy of the GNU General Public License and
19; a copy of the GCC Runtime Library Exception along with this program;
20; see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21; <http://www.gnu.org/licenses/>.
22
23	.text
24
25	.section	.text.__mspabi_srli_n
26	.macro	_srli n
27	.global __mspabi_srli_\n
28__mspabi_srli_\n:
29	CLRC
30	RRC.W	R12
31	.endm
32
33/* Logical Right Shift - R12 -> R12.  */
34	_srli	15
35	_srli	14
36	_srli	13
37	_srli	12
38	_srli	11
39	_srli	10
40	_srli	9
41	_srli	8
42	_srli	7
43	_srli	6
44	_srli	5
45	_srli	4
46	_srli	3
47	_srli	2
48	_srli	1
49#ifdef __MSP430X_LARGE__
50	RETA
51#else
52	RET
53#endif
54
55	.section	.text.__mspabi_srli
561:	ADD.W	#-1,R13
57	CLRC
58	RRC.W	R12,R12
59	.global	__mspabi_srli
60__mspabi_srli:
61	CMP	#0,R13
62	JNZ	1b
63#ifdef __MSP430X_LARGE__
64	RETA
65#else
66	RET
67#endif
68
69/* Logical Right Shift - R12:R13 -> R12:R13.  */
70
71	.section	.text.__mspabi_srll_n
72	.macro	_srll	n
73	.global	__mspabi_srll_\n
74__mspabi_srll_\n:
75	CLRC
76	RRC.W	R13
77	RRC.W	R12
78	.endm
79
80	_srll	15
81	_srll	14
82	_srll	13
83	_srll	12
84	_srll	11
85	_srll	10
86	_srll	9
87	_srll	8
88	_srll	7
89	_srll	6
90	_srll	5
91	_srll	4
92	_srll	3
93	_srll	2
94	_srll	1
95#ifdef __MSP430X_LARGE__
96	RETA
97#else
98	RET
99#endif
100
101	.section	.text.__mspabi_srll
1021:	ADD.W	#-1,R14
103	CLRC
104	RRC.W	R13
105	RRC.W	R12
106	.global	__mspabi_srll
107__mspabi_srll:
108	CMP	#0,R14
109	JNZ	1b
110#ifdef __MSP430X_LARGE__
111	RETA
112#else
113	RET
114#endif
115
116/* Logical Right Shift - R8:R11 -> R12:R15
117   A 64-bit argument would normally be passed in R12:R15, but __mspabi_srlll has
118   special conventions, so the 64-bit value to shift is passed in R8:R11.
119   According to the MSPABI, the shift amount is a 64-bit value in R12:R15, but
120   we only use the low word in R12.  */
121
122	.section	.text.__mspabi_srlll
123	.global __mspabi_srlll
124__mspabi_srlll:
125	MOV R11, R15 ; Free up R11 first
126	MOV R12, R11 ; Save the shift amount in R11
127	MOV R10, R14
128	MOV R9, R13
129	MOV R8, R12
130	CMP #0,R11
131	JNZ 1f
132#ifdef __MSP430X_LARGE__
133	RETA
134#else
135	RET
136#endif
1371:
138	CLRC
139	RRC R15
140	RRC R14
141	RRC R13
142	RRC R12
143	ADD #-1,R11
144	JNZ 1b
145#ifdef __MSP430X_LARGE__
146	RETA
147#else
148	RET
149#endif
150