* Chill runtime moved into toplevel libchill.
[gcc.git] / libchill / inbitstr.c
1 /* Implement 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #define __CHILL_LIB__
22
23 #include "config.h"
24 #include <stdio.h>
25 #include "powerset.h"
26
27 extern void __cause_ex1 (char *exname, char *file, int lineno);
28
29 /*
30 * function __inbitstring
31 *
32 * parameters:
33 * bitno bit number within set
34 * powerset the powerset
35 * bitlength length of powerset in bits
36 * minval number of lowest bit stored
37 * fname filename of caller
38 * lineno linenumber of caller
39 *
40 * returns:
41 * int 1 .. found
42 * 0 .. not found
43 *
44 * exceptions:
45 * rangefail
46 *
47 * abstract:
48 * checks if a given value is included in a bitstring
49 *
50 */
51 int
52 __inbitstring (bitno, powerset, bitlength, minval, fname, lineno)
53 unsigned long bitno;
54 SET_WORD *powerset;
55 unsigned long bitlength;
56 long minval;
57 char *fname;
58 int lineno;
59
60 {
61 if (powerset == NULL
62 || bitno < minval
63 || (bitno - minval) >= bitlength)
64 __cause_ex1 ("rangefail", fname, lineno);
65
66 bitno -= minval;
67 if (bitlength <= SET_CHAR_SIZE)
68 return GET_BIT_IN_CHAR (*((SET_CHAR *)powerset), bitno);
69 else if (bitlength <= SET_SHORT_SIZE)
70 return GET_BIT_IN_SHORT (*((SET_SHORT *)powerset), bitno);
71 else
72 return GET_BIT_IN_WORD (powerset[bitno / SET_WORD_SIZE],
73 bitno % SET_WORD_SIZE);
74 }