aboutsummaryrefslogtreecommitdiff
path: root/gcc/ch/runtime/powerset.h
blob: 3ceb77675f26ab3b6617c643c60760ac1fe0e858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Common macros for POWERSET runtime actions for CHILL.
   Copyright (C) 1992,1993 Free Software Foundation, Inc.
   Author: Wilfried Moser, et al

This file is part of GNU CC.

GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */

#ifndef _POWERSET_H
#define _POWERSET_H

#define USE_CHARS

#ifdef USE_CHARS

#define SET_WORD unsigned char
#define SET_CHAR  unsigned char
#define SET_SHORT unsigned char

#else

#ifndef SET_WORD
#define SET_WORD unsigned int
#endif
#define SET_CHAR  unsigned char
#define SET_SHORT unsigned short
#endif

#define SET_WORD_SIZE (BITS_PER_UNIT * sizeof (SET_WORD))
#define SET_SHORT_SIZE (BITS_PER_UNIT * sizeof (SET_SHORT))
#define SET_CHAR_SIZE BITS_PER_UNIT

/* Powersets and bit strings are stored as arrays of SET_WORD.
   if they are a word or longer.  Powersets and bit strings whic
   fit in a byte or short are stored that way by the compiler.

   The order of the bits follows native bit order:
   If BITS_BIG_ENDIAN, bit 0 is the most significant bit (i.e. 0x80..00);
   otherwise, bit 0 is the least significant bit (i.e. 0x1).

   MASK_UNUSED_BITS masks out unused bits in powersets and bitstrings.
   GET_BIT_IN_WORD(W,B) yields 1 (or 0) if the B'th bit if W is set (cleared).
*/

#if BITS_BIG_ENDIAN
#define GET_BIT_IN_WORD(w,b) (((w) >> (SET_WORD_SIZE - 1 - (b))) & 1)
#define GET_BIT_IN_SHORT(w,b) (((w) >> (SET_SHORT_SIZE - 1 - (b))) & 1)
#define GET_BIT_IN_CHAR(w,b) (((w) >> (SET_CHAR_SIZE - 1 - (b))) & 1)

#define SET_BIT_IN_WORD(w,b) ((w) |= 1 << ((SET_WORD_SIZE) - 1 - (b)))
#define SET_BIT_IN_SHORT(w,b) ((w) |= 1 << ((SET_SHORT_SIZE) - 1 - (b)))
#define SET_BIT_IN_CHAR(w,b) ((w) |= 1 << ((SET_CHAR_SIZE) - 1 - (b)))

#define CLEAR_BIT_IN_WORD(w,b) ((w) &= ~(1 << ((SET_WORD_SIZE) - 1 - (b))))
#define CLEAR_BIT_IN_SHORT(w,b) ((w) &= ~(1 << ((SET_SHORT_SIZE) - 1 - (b))))
#define CLEAR_BIT_IN_CHAR(w,b) ((w) &= ~(1 << ((SET_CHAR_SIZE) - 1 - (b))))
#define MASK_UNUSED_WORD_BITS(p,b)		   \
{ if (b) *(p) &= (~0) << (SET_WORD_SIZE - (b)); }
#define MASK_UNUSED_SHORT_BITS(p,b)		   \
{ if (b) *(p) &= (~0) << (SET_SHORT_SIZE - (b)); }
#define MASK_UNUSED_CHAR_BITS(p,b)                 \
{ if (b) *(p) &= (~0) << (SET_CHAR_SIZE - (b)); }

#else /* !BITS_BIG_ENDIAN */

#define GET_BIT_IN_WORD(w,b) (((w) >> (b)) & 1)
#define GET_BIT_IN_SHORT(w,b) GET_BIT_IN_WORD(w,b)
#define GET_BIT_IN_CHAR(w,b) GET_BIT_IN_WORD(w,b)

#define SET_BIT_IN_WORD(w,b) ((w) |= 1 << (b))
#define SET_BIT_IN_SHORT(w,b) SET_BIT_IN_WORD(w,b)
#define SET_BIT_IN_CHAR(w,b) SET_BIT_IN_WORD(w,b)

#define CLEAR_BIT_IN_WORD(w,b) ((w) &= ~(1 << (b)))
#define CLEAR_BIT_IN_SHORT(w,b) CLEAR_BIT_IN_WORD(w,b)
#define CLEAR_BIT_IN_CHAR(w,b) CLEAR_BIT_IN_WORD(w,b)

#define MASK_UNUSED_WORD_BITS(p,b)  \
{ if (b) *(p) &= ~((~0) << (b)); }
#define MASK_UNUSED_SHORT_BITS(p,b) MASK_UNUSED_WORD_BITS(p,b)
#define MASK_UNUSED_CHAR_BITS(p,b) MASK_UNUSED_WORD_BITS(p,b)

#endif


/* Number of words needed for a bitstring/powerset of size BITLENGTH.
   This definition handles the (BITLENGTH==0) by yielding 0. */

#define BITS_TO_WORDS(BITLENGTH) \
  (((BITLENGTH) + (SET_WORD_SIZE-1)) / SET_WORD_SIZE)
#define BITS_TO_CHARS(BITLENGTH) \
  (((BITLENGTH) + (SET_CHAR_SIZE-1)) / SET_CHAR_SIZE)

#endif