dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / uts / intel / asm / bitmap.h
blob64468b3168857f2ae4df58a881a394e5744cdc99
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
28 #ifndef _ASM_BITMAP_H
29 #define _ASM_BITMAP_H
31 #include <sys/ccompile.h>
32 #include <sys/types.h>
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
39 #if defined(__amd64)
40 #define __SUF "q"
41 #elif defined(__i386)
42 #define __SUF "l"
43 #else
44 #error "port me"
45 #endif
47 extern __GNU_INLINE int
48 highbit(ulong_t i)
50 long value;
51 uint8_t zf;
53 __asm__(
54 "bsr" __SUF " %2,%0;"
55 "setz %1"
56 : "=r" (value), "=q" (zf)
57 : "mr" (i)
58 : "cc");
60 return (zf ? 0 : (value + 1));
63 extern __GNU_INLINE int
64 lowbit(ulong_t i)
66 long value;
67 uint8_t zf;
69 __asm__(
70 "bsf" __SUF " %2,%0;"
71 "setz %1"
72 : "=r" (value), "=q" (zf)
73 : "mr" (i)
74 : "cc");
76 return (zf ? 0 : (value + 1));
79 extern __GNU_INLINE uint_t
80 atomic_btr32(uint32_t *memory, uint_t bitnum)
82 uint8_t value;
84 __asm__ __volatile__(
85 "lock;"
86 "btrl %2,%0;"
87 "setc %1"
88 : "+m" (*memory), "=r" (value)
89 : "ir" (bitnum)
90 : "cc");
92 return ((uint_t)value);
95 #undef __SUF
98 #ifdef __cplusplus
100 #endif
102 #endif /* _ASM_BITMAP_H */