* $(HOST_PREFIX_1)errors.o, $(HOST_PREFIX_1)ggc-none.o,
[official-gcc.git] / libchill / powerset.h
blobe40303a2eeb1fc9c5403fd044d19e74074ce95b5
1 /* Common macros for POWERSET runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
3 Author: Wilfried Moser, et al
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
29 #ifndef _POWERSET_H
30 #define _POWERSET_H
32 /* Do not set these to anything other than character types without fixing
33 their uses in andps.c and other files which implement bit sets operations.
35 The uses in those files will violate ANSI/ISO C aliasing rules as they
36 are currently written. */
37 #define SET_WORD unsigned char
38 #define SET_CHAR unsigned char
39 #define SET_SHORT unsigned char
41 #define SET_WORD_SIZE (sizeof (char) * sizeof (SET_WORD))
42 #define SET_SHORT_SIZE (sizeof (char) * sizeof (SET_SHORT))
43 #define SET_CHAR_SIZE sizeof (char)
45 /* Powersets and bit strings are stored as arrays of SET_WORD.
46 if they are a word or longer. Powersets and bit strings whic
47 fit in a byte or short are stored that way by the compiler.
49 The order of the bits follows native bit order:
50 If BITS_BIG_ENDIAN, bit 0 is the most significant bit (i.e. 0x80..00);
51 otherwise, bit 0 is the least significant bit (i.e. 0x1).
53 MASK_UNUSED_BITS masks out unused bits in powersets and bitstrings.
54 GET_BIT_IN_WORD(W,B) yields 1 (or 0) if the B'th bit if W is set (cleared).
57 #if BITS_BIG_ENDIAN
58 #define GET_BIT_IN_WORD(w,b) (((w) >> (SET_WORD_SIZE - 1 - (b))) & 1)
59 #define GET_BIT_IN_SHORT(w,b) (((w) >> (SET_SHORT_SIZE - 1 - (b))) & 1)
60 #define GET_BIT_IN_CHAR(w,b) (((w) >> (SET_CHAR_SIZE - 1 - (b))) & 1)
62 #define SET_BIT_IN_WORD(w,b) ((w) |= 1 << ((SET_WORD_SIZE) - 1 - (b)))
63 #define SET_BIT_IN_SHORT(w,b) ((w) |= 1 << ((SET_SHORT_SIZE) - 1 - (b)))
64 #define SET_BIT_IN_CHAR(w,b) ((w) |= 1 << ((SET_CHAR_SIZE) - 1 - (b)))
66 #define CLEAR_BIT_IN_WORD(w,b) ((w) &= ~(1 << ((SET_WORD_SIZE) - 1 - (b))))
67 #define CLEAR_BIT_IN_SHORT(w,b) ((w) &= ~(1 << ((SET_SHORT_SIZE) - 1 - (b))))
68 #define CLEAR_BIT_IN_CHAR(w,b) ((w) &= ~(1 << ((SET_CHAR_SIZE) - 1 - (b))))
69 #define MASK_UNUSED_WORD_BITS(p,b) \
70 { if (b) *(p) &= (~0) << (SET_WORD_SIZE - (b)); }
71 #define MASK_UNUSED_SHORT_BITS(p,b) \
72 { if (b) *(p) &= (~0) << (SET_SHORT_SIZE - (b)); }
73 #define MASK_UNUSED_CHAR_BITS(p,b) \
74 { if (b) *(p) &= (~0) << (SET_CHAR_SIZE - (b)); }
76 #else /* !BITS_BIG_ENDIAN */
78 #define GET_BIT_IN_WORD(w,b) (((w) >> (b)) & 1)
79 #define GET_BIT_IN_SHORT(w,b) GET_BIT_IN_WORD(w,b)
80 #define GET_BIT_IN_CHAR(w,b) GET_BIT_IN_WORD(w,b)
82 #define SET_BIT_IN_WORD(w,b) ((w) |= 1 << (b))
83 #define SET_BIT_IN_SHORT(w,b) SET_BIT_IN_WORD(w,b)
84 #define SET_BIT_IN_CHAR(w,b) SET_BIT_IN_WORD(w,b)
86 #define CLEAR_BIT_IN_WORD(w,b) ((w) &= ~(1 << (b)))
87 #define CLEAR_BIT_IN_SHORT(w,b) CLEAR_BIT_IN_WORD(w,b)
88 #define CLEAR_BIT_IN_CHAR(w,b) CLEAR_BIT_IN_WORD(w,b)
90 #define MASK_UNUSED_WORD_BITS(p,b) \
91 { if (b) *(p) &= ~((~0) << (b)); }
92 #define MASK_UNUSED_SHORT_BITS(p,b) MASK_UNUSED_WORD_BITS(p,b)
93 #define MASK_UNUSED_CHAR_BITS(p,b) MASK_UNUSED_WORD_BITS(p,b)
95 #endif
98 /* Number of words needed for a bitstring/powerset of size BITLENGTH.
99 This definition handles the (BITLENGTH==0) by yielding 0. */
101 #define BITS_TO_WORDS(BITLENGTH) \
102 (((BITLENGTH) + (SET_WORD_SIZE-1)) / SET_WORD_SIZE)
103 #define BITS_TO_CHARS(BITLENGTH) \
104 (((BITLENGTH) + (SET_CHAR_SIZE-1)) / SET_CHAR_SIZE)
106 #endif