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)
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #define SET_WORD unsigned char
29 #define SET_CHAR unsigned char
30 #define SET_SHORT unsigned char
35 #define SET_WORD unsigned int
37 #define SET_CHAR unsigned char
38 #define SET_SHORT unsigned short
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).
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)
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)