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