2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief intel 80x86 implementation of bitsets
25 #ifndef _BITSET_IA32_H
26 #define _BITSET_IA32_H
28 #undef _bitset_inside_clear
29 #undef _bitset_inside_set
30 #undef _bitset_inside_flip
32 #define _bitset_inside_set(unit, bit) \
33 __asm__ __volatile__( "btsl %1,%0" :"=m" (*unit) : "Ir" (bit) : "cc")
35 #define _bitset_inside_clear(unit, bit) \
36 __asm__ __volatile__( "btrl %1,%0" :"=m" (*unit) : "Ir" (bit) : "cc")
38 #define _bitset_inside_flip(unit, bit) \
39 __asm__ __volatile__( "btcl %1,%0" :"=m" (*unit) : "Ir" (bit) : "cc")
41 #undef _bitset_inside_is_set
42 #undef _bitset_inside_nlz
43 #undef _bitset_inside_ntz
44 #undef _bitset_inside_ntz_value
46 #define _bitset_inside_is_set(unit, bit) _bitset_ia32_inside_is_set(unit, bit)
47 #define _bitset_inside_nlz(unit) _bitset_ia32_inside_nlz(unit)
48 #define _bitset_inside_ntz(unit) _bitset_ia32_inside_ntz(unit)
49 #define _bitset_inside_ntz_value(unit) _bitset_ia32_inside_ntz_value(unit)
51 static inline int _bitset_ia32_inside_is_set(bitset_unit_t *unit, unsigned bit)
54 __asm__("bt %2, %1\n\t"
58 : "m" (*unit), "Ir" (bit)
63 static inline unsigned _bitset_ia32_inside_nlz(bitset_unit_t *unit)
66 __asm__("bsr %1, %0\n\t"
71 : "m" (*unit), "r" (-1)
76 static inline unsigned _bitset_ia32_inside_ntz(bitset_unit_t *unit) {
78 __asm__("bsfl %1, %0\n\t"
81 : "m" (*unit), "r" (32)
86 static inline unsigned _bitset_ia32_inside_ntz_value(bitset_unit_t unit) {
88 __asm__("bsfl %1, %0\n\t"
91 : "r" (unit), "r" (32)