1;   Copyright (C) 2012-2014 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#include "vregs.h"
24
25START_FUNC	___clzhi2
26	;; Argument is in [SP+4], return in R8.
27	movw	ax, [SP+4]
28
29	.global __clzhi2_internal
30__clzhi2_internal:
31	movw	r8, #16
32	cmpw	ax, #0
33	bz	$clzhi2_is_zero
34	mov	e, #0xff
351:
36	inc	e
37	shlw	ax, 1
38	bnc	$1b
39	mov	a, e
40	mov	r8, a
41clzhi2_is_zero:
42	ret
43END_FUNC	___clzhi2
44
45
46START_FUNC	___clzsi2
47	;; Argument is in [SP+6]:[SP+4], return in R8.
48	movw	ax, [SP+6]
49	cmpw	ax, #0
50	bnz	$__clzhi2_internal
51	movw	ax, [SP+4]
52	call	!__clzhi2_internal
53	movw	ax, r8
54	addw	ax, #16
55	movw	r8, ax
56	ret
57END_FUNC	___clzsi2
58
59
60START_FUNC	___ctzhi2
61	;; Argument is in [SP+4], return in R8.
62	movw	ax, [SP+4]
63
64	.global __ctzhi2_internal
65__ctzhi2_internal:
66	movw	r8, #16
67	cmpw	ax, #0
68	bz	$ctzhi2_is_zero
69	mov	e, #0xff
701:
71	inc	e
72	shrw	ax, 1
73	bnc	$1b
74	mov	a, e
75	mov	r8, a
76ctzhi2_is_zero:
77	ret
78END_FUNC	___ctzhi2
79
80
81START_FUNC	___ctzsi2
82	;; Argument is in [SP+6]:[SP+4], return in R8.
83	movw	ax, [SP+4]
84	cmpw	ax, #0
85	bnz	$__ctzhi2_internal
86	movw	ax, [SP+6]
87	call	!__ctzhi2_internal
88	movw	ax, r8
89	addw	ax, #16
90	movw	r8, ax
91	ret
92END_FUNC	___ctzsi2
93
94
95START_FUNC	___ffshi2
96	;; Argument is in [SP+4], return in R8.
97	movw	ax, [SP+4]
98
99	.global __ffshi2_internal
100__ffshi2_internal:
101	movw	r8, #0
102	cmpw	ax, #0
103	bz	$ffshi2_is_zero
104	mov	e, #0
1051:
106	inc	e
107	shrw	ax, 1
108	bnc	$1b
109	mov	a, e
110	mov	r8, a
111ffshi2_is_zero:
112	ret
113END_FUNC	___ffshi2
114
115
116START_FUNC	___ffssi2
117	;; Argument is in [SP+6]:[SP+4], return in R8.
118	movw	ax, [SP+4]
119	cmpw	ax, #0
120	bnz	$__ffshi2_internal
121	movw	ax, [SP+6]
122	cmpw	ax, #0
123	bz	$1f
124	call	!__ffshi2_internal
125	movw	ax, r8
126	addw	ax, #16
1271:
128	movw	r8, ax
129	ret
130END_FUNC	___ffssi2
131
132
133START_FUNC	___parityqi_internal
134	mov1	cy, a.0
135	xor1	cy, a.1
136	xor1	cy, a.2
137	xor1	cy, a.3
138	xor1	cy, a.4
139	xor1	cy, a.5
140	xor1	cy, a.6
141	xor1	cy, a.7
142	movw	ax, #0
143	bnc	$1f
144	incw	ax
1451:
146	movw	r8, ax
147	ret
148END_FUNC	___parityqi_internal
149
150
151START_FUNC	___parityhi2
152	;; Argument is in [SP+4], return in R8.
153	movw	ax, [SP+4]
154	xor	a, x
155	br	$___parityqi_internal
156END_FUNC	___parityhi2
157
158
159START_FUNC	___paritysi2
160	;; Argument is in [SP+6]:[SP+4], return in R8.
161	movw	ax, [SP+4]
162	xor	a, x
163	mov	b, a
164	movw	ax, [SP+6]
165	xor	a, x
166	xor	a, b
167	br	$___parityqi_internal
168END_FUNC	___paritysi2
169
170
171
172START_FUNC	___popcounthi2
173	;; Argument is in [SP+4], return in R8.
174	mov	d, #2
175	br	$___popcountqi_internal
176END_FUNC	___popcounthi2
177
178
179START_FUNC	___popcountsi2
180	;; Argument is in [SP+6]:[SP+4], return in R8.
181	mov	d, #4
182	br	$___popcountqi_internal
183END_FUNC	___popcountsi2
184
185
186START_FUNC	___popcountqi_internal
187	;; There are D bytes starting at [HL]
188	;; store count in R8.
189
190	movw	ax, sp
191	addw	ax, #4
192	movw	hl, ax
193	mov	a, #0
1941:
195	xch	a, b
196	mov	a, [hl]
197	xch	a, b
198	mov	e, #8
1992:
200	shl	b,1
201	addc	a, #0
202	dec	e
203	bnz	$2b
204
205	incw	hl
206	dec	d
207	bnz	$1b
208
209	mov	x, a
210	mov	a, #0
211	movw	r8, ax
212	ret
213END_FUNC	___popcountqi_internal
214