* Chill runtime moved into toplevel libchill.
[gcc.git] / libchill / setbits.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 __setbits
31 *
32 * parameters:
33 * out result
34 * bitlength length of bitstring in bits
35 * startbit starting bitnumber
36 * endbit ending bitnumber
37 *
38 * returns:
39 * void
40 *
41 * exceptions:
42 * rangefail
43 *
44 * abstract:
45 * set all bits from starting bitnumber to ending bitnumber
46 * in a powerset
47 *
48 */
49 void
50 __setbits (out, bitlength, startbit, endbit)
51 SET_WORD *out;
52 unsigned long bitlength;
53 long startbit;
54 long endbit;
55 {
56 unsigned long i;
57
58 if (out == NULL
59 || startbit < 0
60 || startbit >= bitlength
61 || endbit < 0
62 || endbit >= bitlength
63 || endbit < startbit)
64 __cause_ex1 ("rangefail", "__setbits", __LINE__);
65
66 if (bitlength <= SET_CHAR_SIZE)
67 for (i = startbit; i <= endbit; i++)
68 SET_BIT_IN_CHAR (*((SET_CHAR *)out), i);
69 else if (bitlength <= SET_SHORT_SIZE)
70 for (i = startbit; i <= endbit; i++)
71 SET_BIT_IN_SHORT (*((SET_SHORT *)out), i);
72 else
73 {
74 SET_WORD *p;
75 unsigned long bitnr;
76
77 /* FIXME - this is inefficient! */
78 for (i = startbit; i <= endbit; i++)
79 {
80 p = out + (i / SET_WORD_SIZE);
81 bitnr = i % SET_WORD_SIZE;
82 SET_BIT_IN_WORD (*p, bitnr);
83 }
84 }
85 }