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_srai_n
26	.macro	_srai n
27	.global __mspabi_srai_\n
28__mspabi_srai_\n:
29	RRA.W	R12
30	.endm
31
32/* Arithmetic Right Shift - R12 -> R12.  */
33	_srai	15
34	_srai	14
35	_srai	13
36	_srai	12
37	_srai	11
38	_srai	10
39	_srai	9
40	_srai	8
41	_srai	7
42	_srai	6
43	_srai	5
44	_srai	4
45	_srai	3
46	_srai	2
47	_srai	1
48#ifdef __MSP430X_LARGE__
49	RETA
50#else
51	RET
52#endif
53
54	.section	.text.__mspabi_srai
551:	ADD.W	#-1,R13
56	RRA.W	R12,R12
57	.global	__mspabi_srai
58__mspabi_srai:
59	CMP	#0,R13
60	JNZ	1b
61#ifdef __MSP430X_LARGE__
62	RETA
63#else
64	RET
65#endif
66
67/* Arithmetic Right Shift - R12:R13 -> R12:R13.  */
68
69	.section	.text.__mspabi_sral_n
70	.macro	_sral	n
71	.global	__mspabi_sral_\n
72__mspabi_sral_\n:
73	RRA.W	R13
74	RRC.W	R12
75	.endm
76
77	_sral	15
78	_sral	14
79	_sral	13
80	_sral	12
81	_sral	11
82	_sral	10
83	_sral	9
84	_sral	8
85	_sral	7
86	_sral	6
87	_sral	5
88	_sral	4
89	_sral	3
90	_sral	2
91	_sral	1
92#ifdef __MSP430X_LARGE__
93	RETA
94#else
95	RET
96#endif
97
98	.section	.text.__mspabi_sral
991:	ADD.W	#-1,R14
100	RRA.W	R13
101	RRC.W	R12
102	.global	__mspabi_sral
103__mspabi_sral:
104	CMP	#0,R14
105	JNZ	1b
106#ifdef __MSP430X_LARGE__
107	RETA
108#else
109	RET
110#endif
111
112/* Arithmetic Right Shift - R8:R11 -> R12:R15
113   A 64-bit argument would normally be passed in R12:R15, but __mspabi_srall has
114   special conventions, so the 64-bit value to shift is passed in R8:R11.
115   According to the MSPABI, the shift amount is a 64-bit value in R12:R15, but
116   we only use the low word in R12.  */
117
118	.section	.text.__mspabi_srall
119	.global __mspabi_srall
120__mspabi_srall:
121	MOV R11, R15 ; Free up R11 first
122	MOV R12, R11 ; Save the shift amount in R11
123	MOV R10, R14
124	MOV R9, R13
125	MOV R8, R12
126	CMP #0, R11
127	JNZ 1f
128#ifdef __MSP430X_LARGE__
129	RETA
130#else
131	RET
132#endif
1331:
134	RRA R15
135	RRC R14
136	RRC R13
137	RRC R12
138	ADD #-1,R11
139	JNZ 1b
140#ifdef __MSP430X_LARGE__
141	RETA
142#else
143	RET
144#endif
145