macros.h revision 1.4 1 1.4 ragge /* $NetBSD: macros.h,v 1.4 1995/07/05 08:22:21 ragge Exp $ */
2 1.2 cgd
3 1.1 ragge /*
4 1.1 ragge * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
5 1.1 ragge * All rights reserved.
6 1.1 ragge *
7 1.1 ragge * Redistribution and use in source and binary forms, with or without
8 1.1 ragge * modification, are permitted provided that the following conditions
9 1.1 ragge * are met:
10 1.1 ragge * 1. Redistributions of source code must retain the above copyright
11 1.1 ragge * notice, this list of conditions and the following disclaimer.
12 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ragge * notice, this list of conditions and the following disclaimer in the
14 1.1 ragge * documentation and/or other materials provided with the distribution.
15 1.1 ragge * 3. All advertising materials mentioning features or use of this software
16 1.1 ragge * must display the following acknowledgement:
17 1.1 ragge * This product includes software developed at Ludd, University of Lule}.
18 1.1 ragge * 4. The name of the author may not be used to endorse or promote products
19 1.1 ragge * derived from this software without specific prior written permission
20 1.1 ragge *
21 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 ragge */
32 1.1 ragge
33 1.1 ragge /* All bugs are subject to removal without further notice */
34 1.3 ragge
35 1.4 ragge #if !defined(_VAX_MACROS_H_)&&!defined(ASSEMBLER)&&defined(_VAX_INLINE_)
36 1.3 ragge #define _VAX_MACROS_H_
37 1.1 ragge
38 1.1 ragge /* Here general macros are supposed to be stored */
39 1.1 ragge
40 1.3 ragge static __inline__ int ffs(int reg){
41 1.3 ragge register int val;
42 1.3 ragge
43 1.3 ragge asm __volatile ("ffs $0,$32,%1,%0
44 1.3 ragge bneq 1f
45 1.3 ragge mnegl $1,%0
46 1.3 ragge 1: incl %0"
47 1.3 ragge : "&=r" (val)
48 1.3 ragge : "r" (reg) );
49 1.3 ragge return val;
50 1.3 ragge }
51 1.3 ragge
52 1.3 ragge static __inline__ void _remque(void*p){
53 1.3 ragge asm __volatile ("remque (%0),%0;clrl 4(%0)"
54 1.3 ragge :
55 1.3 ragge : "r" (p)
56 1.3 ragge : "memory" );
57 1.3 ragge }
58 1.3 ragge
59 1.3 ragge static __inline__ void _insque(void*p, void*q) {
60 1.3 ragge asm __volatile ("insque (%0), (%1)"
61 1.3 ragge :
62 1.3 ragge : "r" (p),"r" (q)
63 1.3 ragge : "memory" );
64 1.3 ragge }
65 1.3 ragge
66 1.3 ragge #define bitset(bitnr,var) \
67 1.3 ragge ({ asm __volatile ("bbss %0,%1,1f;1:;" \
68 1.3 ragge : \
69 1.3 ragge : "g" (bitnr), "g" (var)); \
70 1.3 ragge })
71 1.3 ragge
72 1.3 ragge #define bitclear(bitnr,var) \
73 1.3 ragge ({ asm __volatile ("bbsc %0,%1,1f;1:;" \
74 1.3 ragge : \
75 1.3 ragge : "g" (bitnr), "g" (var)); \
76 1.3 ragge })
77 1.3 ragge
78 1.3 ragge #define bitisset(bitnr,var) \
79 1.3 ragge ({ \
80 1.3 ragge register int val; \
81 1.3 ragge asm __volatile ("clrl %0;bbc %1,%2,1f;incl %0;1:;" \
82 1.3 ragge : "=g" (val) \
83 1.3 ragge : "g" (bitnr), "g" (var)); \
84 1.3 ragge val; \
85 1.3 ragge })
86 1.3 ragge
87 1.3 ragge #define bitisclear(bitnr,var) \
88 1.3 ragge ({ \
89 1.3 ragge register int val; \
90 1.3 ragge asm __volatile ("clrl %0;bbs %1,%2,1f;incl %0;1:;" \
91 1.3 ragge : "=g" (val) \
92 1.3 ragge : "g" (bitnr), "g" (var)); \
93 1.3 ragge val; \
94 1.3 ragge })
95 1.3 ragge static __inline__ void bcopy(const void*from, void*toe, u_int len) {
96 1.3 ragge asm __volatile ("movc3 %0,(%1),(%2)"
97 1.3 ragge :
98 1.3 ragge : "r" (len),"r" (from),"r"(toe)
99 1.3 ragge :"r0","r1","r2","r3","r4","r5");
100 1.3 ragge }
101 1.3 ragge
102 1.3 ragge static __inline__ void bzero(void*block, u_int len){
103 1.3 ragge asm __volatile ("movc5 $0,(%0),$0,%1,(%0)"
104 1.3 ragge :
105 1.3 ragge : "r" (block), "r" (len)
106 1.3 ragge :"r0","r1","r2","r3","r4","r5");
107 1.3 ragge }
108 1.3 ragge
109 1.3 ragge static __inline__ int bcmp(const void *b1, const void *b2, size_t len){
110 1.3 ragge register ret;
111 1.3 ragge
112 1.3 ragge asm __volatile("cmpc3 %3,(%1),(%2);movl r0,%0"
113 1.3 ragge : "=r" (ret)
114 1.3 ragge : "r" (b1), "r" (b2), "r" (len)
115 1.3 ragge : "r0","r1","r2","r3" );
116 1.3 ragge return ret;
117 1.3 ragge }
118 1.3 ragge
119 1.3 ragge static __inline__ int locc(int mask, char *cp,u_int size){
120 1.3 ragge register ret;
121 1.3 ragge
122 1.3 ragge asm __volatile("locc %1,%2,(%3);movl r0,%0"
123 1.3 ragge : "=r" (ret)
124 1.3 ragge : "r" (mask),"r"(size),"r"(cp)
125 1.3 ragge : "r0","r1" );
126 1.3 ragge return ret;
127 1.3 ragge }
128 1.3 ragge
129 1.3 ragge static __inline__ int scanc(u_int size, u_char *cp,u_char *table, int mask){
130 1.3 ragge register ret;
131 1.3 ragge
132 1.3 ragge asm __volatile("scanc %1,(%2),(%3),%4;movl r0,%0"
133 1.3 ragge : "=g"(ret)
134 1.3 ragge : "r"(size),"r"(cp),"r"(table),"r"(mask)
135 1.3 ragge : "r0","r1","r2","r3" );
136 1.3 ragge return ret;
137 1.3 ragge }
138 1.3 ragge
139 1.3 ragge static __inline__ int skpc(int mask, int size, char *cp){
140 1.3 ragge register ret;
141 1.3 ragge
142 1.3 ragge asm __volatile("skpc %1,%2,(%3);movl r0,%0"
143 1.3 ragge : "=g"(ret)
144 1.3 ragge : "r"(mask),"r"(size),"r"(cp)
145 1.3 ragge : "r0","r1" );
146 1.3 ragge return ret;
147 1.3 ragge }
148 1.3 ragge #if 0
149 1.3 ragge static __inline__ int imin(int a, int b){
150 1.3 ragge asm __volatile("cmpl %0,%2;bleq 1f;movl %2,%0;1:"
151 1.3 ragge : "=r"(a)
152 1.3 ragge : "r"(a),"r"(b) );
153 1.3 ragge return a;
154 1.3 ragge }
155 1.3 ragge
156 1.3 ragge static __inline__ int imax(int a, int b){
157 1.3 ragge asm __volatile("cmpl %0,%2;bgeq 1f;movl %2,%0;1:"
158 1.3 ragge : "=r"(a)
159 1.3 ragge : "r"(a),"r"(b) );
160 1.3 ragge return a;
161 1.3 ragge }
162 1.3 ragge
163 1.3 ragge static __inline__ int min(int a, int b){
164 1.3 ragge asm __volatile("cmpl %0,%2;bleq 1f;movl %2,%0;1:"
165 1.3 ragge : "=r"(a)
166 1.3 ragge : "r"(a),"r"(b) );
167 1.3 ragge return a;
168 1.3 ragge }
169 1.3 ragge
170 1.3 ragge static __inline__ int max(int a, int b){
171 1.3 ragge asm __volatile("cmpl %0,%2;bgeq 1f;movl %2,%0;1:"
172 1.3 ragge : "=r"(a)
173 1.3 ragge : "r"(a),"r"(b) );
174 1.3 ragge return a;
175 1.3 ragge }
176 1.3 ragge #endif
177 1.3 ragge
178 1.3 ragge #define waitabit(tid) \
179 1.3 ragge ({ \
180 1.3 ragge asm __volatile ("mfpr $27,r0;addl2 %0,r0;1:;mfpr $27,r1; \
181 1.3 ragge cmpl r0,r1;bneq 1b;" \
182 1.3 ragge : \
183 1.3 ragge : "g"(tid) \
184 1.3 ragge : "r0","r1"); \
185 1.3 ragge })
186 1.3 ragge
187 1.3 ragge static __inline__ void blkcpy(const void*from, void*to, u_int len) {
188 1.3 ragge asm __volatile("
189 1.3 ragge movl %0,r1
190 1.3 ragge movl %1,r3
191 1.3 ragge movl %2,r6
192 1.3 ragge jbr 2f
193 1.3 ragge 1: subl2 r0,r6
194 1.3 ragge movc3 r0,(r1),(r3)
195 1.3 ragge 2: movzwl $65535,r0
196 1.3 ragge cmpl r6,r0
197 1.3 ragge jgtr 1b
198 1.3 ragge movc3 r6,(r1),(r3)"
199 1.3 ragge :
200 1.3 ragge : "g" (from), "g" (to), "g" (len)
201 1.3 ragge : "r0","r1","r2","r3","r4","r5", "r6" );
202 1.3 ragge }
203 1.3 ragge
204 1.3 ragge static __inline__ void blkclr(void *blk, int len) {
205 1.3 ragge asm __volatile("
206 1.3 ragge movl %0, r3
207 1.3 ragge movl %1, r6
208 1.3 ragge jbr 2f
209 1.3 ragge 1: subl2 r0, r6
210 1.3 ragge movc5 $0,(r3),$0,r0,(r3)
211 1.3 ragge 2: movzwl $65535,r0
212 1.3 ragge cmpl r6, r0
213 1.3 ragge jgtr 1b
214 1.3 ragge movc5 $0,(r3),$0,r6,(r3)"
215 1.3 ragge :
216 1.3 ragge : "g" (blk), "g" (len)
217 1.3 ragge : "r0","r1","r2","r3","r4","r5", "r6" );
218 1.3 ragge }
219 1.3 ragge
220 1.3 ragge #endif /* _VAX_MACROS_H_ */
221