ashldi3.S revision 1.3 1 /* $NetBSD: ashldi3.S,v 1.3 2020/08/22 10:12:29 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
35 ASENTRY_NOPROFILE(__ashldi3)
36 moveml %sp@(4),%d0-%d1/%a0 | %d0:%d1 = quad value
37 | %a0 = shift count
38 jbra start
39 loop:
40 addl %d1,%d1 | X:%d1 <<= 1
41 addxl %d0,%d0 | %d0:X <<= 1
42 start:
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
62 ASENTRY_NOPROFILE(selftest_ashldi3)
63 moveml %d2-%d7/%a2-%a6,%sp@-
64 PRINT %pc@(msg_testname)
65
66 TEST test0
67 TEST test1
68 TEST test2
69 TEST test63
70
71 PRINT %pc@(msg_crlf)
72 moveml %sp@+,%d2-%d7/%a2-%a6
73 rts
74
75 test:
76 moveml %a2@+,%d0-%d2 | %d0:%d1 = value
77 | %d2 = count
78 moveml %d0-%d2,%sp@-
79 jbsr __ashldi3
80 leal %sp@(12),%sp
81
82 cmpl %a2@+,%d0 | compare high word
83 jne fail
84 cmpl %a2@+,%d1 | compare low word
85 jne fail
86 PRINT %pc@(msg_ok)
87 rts
88 fail:
89 PRINT %pc@(msg_fail)
90 rts
91
92 test0: | count = 0
93 .long 0x11223344, 0x55667788
94 .long 0
95 .long 0x11223344, 0x55667788
96
97 test1: | count = 1
98 .long 0x11223344, 0x55667788
99 .long 1
100 .long 0x22446688, 0xaaccef10
101
102 test2: | count = 2
103 .long 0x11223344, 0x55667788
104 .long 2
105 .long 0x4488cd11, 0x5599de20
106
107 test63: | count = 63
108 .long 0x11223344, 0x55667789
109 .long 63
110 .long 0x80000000, 0x00000000
111
112 msg_testname:
113 .asciz "__ashldi3"
114 msg_ok:
115 .asciz " ok"
116 msg_fail:
117 .asciz " fail"
118 msg_crlf:
119 .asciz "\r\n"
120
121 #endif
122