xref: /netbsd-src/sys/arch/x68k/stand/xxboot/ashrdi3.S (revision 7e73c3a86c7acd948a7e0f539969e328d81b0229)
1/*	$NetBSD: ashrdi3.S,v 1.1 2020/08/16 06:43:43 isaki Exp $	*/
2
3/*
4 * Copyright (C) 2020 Tetsuya Isaki. All rights reserved.
5 * Copyright (C) 2020 Y.Sugahara (moveccr). All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29/*
30 * Size optimized version for primary bootloader.
31 */
32
33#include <machine/asm.h>
34
35ASENTRY_NOPROFILE(__ashrdi3)
36		moveml	%sp@(4),%d0-%d1/%a0	| %d0:%d1 = quad value
37						| %a0     = shift count
38		jbra	start
39loop:
40		asrl	#1,%d0			| %d0:X >>>= 1
41		roxrl	#1,%d1			| X:%d1 >>= 1
42start:
43		subql	#1,%a0			| sub %a0 doesn't affect ccr,
44		tstl	%a0			|  but this extra TST op is
45						|  smaller than push/pop %d2.
46		jpl	loop
47		rts
48
49
50#if defined(SELFTEST)
51#include "iocscall.h"
52		.macro	PRINT	msg
53		leal	\msg,%a1
54		IOCS(__B_PRINT)
55		.endm
56
57		.macro	TEST	name
58		leal	\name,%a2
59		jbsr	test
60		.endm
61
62ASENTRY_NOPROFILE(selftest_ashrdi3)
63		moveml	%d2-%d7/%a2-%a6,%sp@-
64		PRINT	%pc@(msg_testname)
65
66		TEST	test0
67		TEST	test1p
68		TEST	test1m
69		TEST	test4p
70		TEST	test4m
71		TEST	test63p
72		TEST	test63m
73
74		PRINT	%pc@(msg_crlf)
75		moveml	%sp@+,%d2-%d7/%a2-%a6
76		rts
77
78test:
79		moveml	%a2@+,%d0-%d2		| %d0:%d1 = value
80						| %d2     = count
81		moveml	%d0-%d2,%sp@-
82		jbsr	__ashrdi3
83		leal	%sp@(12),%sp
84
85		cmpl	%a2@+,%d0		| compare high word
86		jne	fail
87		cmpl	%a2@+,%d1		| compare low word
88		jne	fail
89		PRINT	%pc@(msg_ok)
90		rts
91fail:
92		PRINT	%pc@(msg_fail)
93		rts
94
95test0:		| count = 0
96		.long	0x11223344, 0x55667788
97		.long	0
98		.long	0x11223344, 0x55667788
99
100test1p:		| count = 1
101		.long	0x11223344, 0x55667788
102		.long	1
103		.long	0x089119a2, 0x2ab33bc4
104
105test1m:		| count = 1 (negative value)
106		.long	0x91223344, 0x55667788
107		.long	1
108		.long	0xc89119a2, 0x2ab33bc4
109
110test4p:		| count = 4
111		.long	0x11223344, 0x55667788
112		.long	4
113		.long	0x01122334, 0x45566778
114
115test4m:		| count = 4 (negative value)
116		.long	0x91223344, 0x55667788
117		.long	4
118		.long	0xf9122334, 0x45566778
119
120test63p:	| count = 63
121		.long	0x41223344, 0x55667788
122		.long	63
123		.long	0x00000000, 0x00000000
124
125test63m:	| count = 63 (negative value)
126		.long	0x91223344, 0x55667788
127		.long	63
128		.long	0xffffffff, 0xffffffff
129
130msg_testname:
131		.asciz	"__ashrdi3"
132msg_ok:
133		.asciz	" ok"
134msg_fail:
135		.asciz	" fail"
136msg_crlf:
137		.asciz	"\r\n"
138
139#endif
140