xref: /titanic_41/usr/src/uts/intel/asm/bitmap.h (revision 59ac0c1669407488b67ae9e273667a340dccc611)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _ASM_BITMAP_H
28 #define	_ASM_BITMAP_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #if !defined(__lint) && defined(__GNUC__)
39 
40 extern __inline__ int
41 highbit(ulong_t i)
42 {
43 	long __value = -1l;
44 
45 #if defined(__amd64)
46 	__asm__(
47 		"bsrq	%1,%0"
48 		: "+r" (__value)
49 		: "r" (i)
50 		: "cc");
51 #elif defined(__i386)
52 	__asm__(
53 		"bsrl	%1,%0"
54 		: "+r" (__value)
55 		: "r" (i)
56 		: "cc");
57 #else
58 #error	"port me"
59 #endif
60 	return ((int)(__value + 1));
61 }
62 
63 extern __inline__ int
64 lowbit(ulong_t i)
65 {
66 	long __value = -1l;
67 
68 #if defined(__amd64)
69 	__asm__(
70 		"bsfq	%1,%0"
71 		: "+r" (__value)
72 		: "r" (i)
73 		: "cc");
74 #elif defined(__i386)
75 	__asm__(
76 		"bsfl	%1,%0"
77 		: "+r" (__value)
78 		: "r" (i)
79 		: "cc");
80 #else
81 #error	"port me"
82 #endif
83 	return ((int)(__value + 1));
84 }
85 
86 extern __inline__ uint_t
87 atomic_btr32(uint32_t *memory, uint_t bitnum)
88 {
89 	uint8_t __value;
90 
91 #if defined(__amd64)
92 	__asm__ __volatile__(
93 		"lock;"
94 		"btrl %2, (%0);"
95 		"setc %1"
96 		: "+r" (memory), "+r" (__value)
97 		: "ir" (bitnum)
98 		: "cc");
99 #elif defined(__i386)
100 	__asm__ __volatile__(
101 		"lock;"
102 		"btrl %2, (%0);"
103 		"setc %1"
104 		: "+r" (memory), "=r" (__value)
105 		: "ir" (bitnum)
106 		: "cc");
107 #else
108 #error	"port me"
109 #endif
110 	return ((uint_t)__value);
111 }
112 
113 #endif	/* !__lint && __GNUC__ */
114 
115 #ifdef	__cplusplus
116 }
117 #endif
118 
119 #endif	/* _ASM_BITMAP_H */
120