OSDN Git Service

Fix FSF address in copyright header.
[pf3gnuchains/gcc-fork.git] / libchill / powerset.h
1 /* Common macros for POWERSET runtime actions for CHILL.
2    Copyright (C) 1992,1993 Free Software Foundation, Inc.
3    Author: Wilfried Moser, et al
4
5 This file is part of GNU CC.
6
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.
11
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.
16
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.  */
21
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.  */
28
29 #ifndef _POWERSET_H
30 #define _POWERSET_H
31
32 #define USE_CHARS
33
34 #ifdef USE_CHARS
35
36 #define SET_WORD unsigned char
37 #define SET_CHAR  unsigned char
38 #define SET_SHORT unsigned char
39
40 #else
41
42 #ifndef SET_WORD
43 #define SET_WORD unsigned int
44 #endif
45 #define SET_CHAR  unsigned char
46 #define SET_SHORT unsigned short
47 #endif
48
49 #define SET_WORD_SIZE (sizeof (char) * sizeof (SET_WORD))
50 #define SET_SHORT_SIZE (sizeof (char) * sizeof (SET_SHORT))
51 #define SET_CHAR_SIZE sizeof (char)
52
53 /* Powersets and bit strings are stored as arrays of SET_WORD.
54    if they are a word or longer.  Powersets and bit strings whic
55    fit in a byte or short are stored that way by the compiler.
56
57    The order of the bits follows native bit order:
58    If BITS_BIG_ENDIAN, bit 0 is the most significant bit (i.e. 0x80..00);
59    otherwise, bit 0 is the least significant bit (i.e. 0x1).
60
61    MASK_UNUSED_BITS masks out unused bits in powersets and bitstrings.
62    GET_BIT_IN_WORD(W,B) yields 1 (or 0) if the B'th bit if W is set (cleared).
63 */
64
65 #if BITS_BIG_ENDIAN
66 #define GET_BIT_IN_WORD(w,b) (((w) >> (SET_WORD_SIZE - 1 - (b))) & 1)
67 #define GET_BIT_IN_SHORT(w,b) (((w) >> (SET_SHORT_SIZE - 1 - (b))) & 1)
68 #define GET_BIT_IN_CHAR(w,b) (((w) >> (SET_CHAR_SIZE - 1 - (b))) & 1)
69
70 #define SET_BIT_IN_WORD(w,b) ((w) |= 1 << ((SET_WORD_SIZE) - 1 - (b)))
71 #define SET_BIT_IN_SHORT(w,b) ((w) |= 1 << ((SET_SHORT_SIZE) - 1 - (b)))
72 #define SET_BIT_IN_CHAR(w,b) ((w) |= 1 << ((SET_CHAR_SIZE) - 1 - (b)))
73
74 #define CLEAR_BIT_IN_WORD(w,b) ((w) &= ~(1 << ((SET_WORD_SIZE) - 1 - (b))))
75 #define CLEAR_BIT_IN_SHORT(w,b) ((w) &= ~(1 << ((SET_SHORT_SIZE) - 1 - (b))))
76 #define CLEAR_BIT_IN_CHAR(w,b) ((w) &= ~(1 << ((SET_CHAR_SIZE) - 1 - (b))))
77 #define MASK_UNUSED_WORD_BITS(p,b)                 \
78 { if (b) *(p) &= (~0) << (SET_WORD_SIZE - (b)); }
79 #define MASK_UNUSED_SHORT_BITS(p,b)                \
80 { if (b) *(p) &= (~0) << (SET_SHORT_SIZE - (b)); }
81 #define MASK_UNUSED_CHAR_BITS(p,b)                 \
82 { if (b) *(p) &= (~0) << (SET_CHAR_SIZE - (b)); }
83
84 #else /* !BITS_BIG_ENDIAN */
85
86 #define GET_BIT_IN_WORD(w,b) (((w) >> (b)) & 1)
87 #define GET_BIT_IN_SHORT(w,b) GET_BIT_IN_WORD(w,b)
88 #define GET_BIT_IN_CHAR(w,b) GET_BIT_IN_WORD(w,b)
89
90 #define SET_BIT_IN_WORD(w,b) ((w) |= 1 << (b))
91 #define SET_BIT_IN_SHORT(w,b) SET_BIT_IN_WORD(w,b)
92 #define SET_BIT_IN_CHAR(w,b) SET_BIT_IN_WORD(w,b)
93
94 #define CLEAR_BIT_IN_WORD(w,b) ((w) &= ~(1 << (b)))
95 #define CLEAR_BIT_IN_SHORT(w,b) CLEAR_BIT_IN_WORD(w,b)
96 #define CLEAR_BIT_IN_CHAR(w,b) CLEAR_BIT_IN_WORD(w,b)
97
98 #define MASK_UNUSED_WORD_BITS(p,b)  \
99 { if (b) *(p) &= ~((~0) << (b)); }
100 #define MASK_UNUSED_SHORT_BITS(p,b) MASK_UNUSED_WORD_BITS(p,b)
101 #define MASK_UNUSED_CHAR_BITS(p,b) MASK_UNUSED_WORD_BITS(p,b)
102
103 #endif
104
105
106 /* Number of words needed for a bitstring/powerset of size BITLENGTH.
107    This definition handles the (BITLENGTH==0) by yielding 0. */
108
109 #define BITS_TO_WORDS(BITLENGTH) \
110   (((BITLENGTH) + (SET_WORD_SIZE-1)) / SET_WORD_SIZE)
111 #define BITS_TO_CHARS(BITLENGTH) \
112   (((BITLENGTH) + (SET_CHAR_SIZE-1)) / SET_CHAR_SIZE)
113
114 #endif