1 /* Implement 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. */
27 * function __flsetclrpowerset
31 * bitlength length of powerset
34 * int -1 .. nothing found
35 * >= 0 .. index of last set bit
40 * Find last bit set in a powerset and return the corresponding value
41 * in *out and clear this bit. Return 0 for no more found, else 1.
45 __flsetclrpowerset (ps, bitlength, first_bit)
47 unsigned long bitlength;
53 if (bitlength <= SET_CHAR_SIZE)
55 for (bitno = bitlength - 1; bitno >= first_bit; bitno--)
56 if (GET_BIT_IN_CHAR (*((SET_CHAR *)ps), bitno))
58 return bitno < first_bit ? -1 : bitno;
60 else if (bitlength <= SET_SHORT_SIZE)
62 for (bitno = bitlength - 1; bitno >= first_bit; bitno--)
63 if (GET_BIT_IN_SHORT (*((SET_SHORT *)ps), bitno))
65 return bitno < first_bit ? -1 : bitno;
71 bitno = bitlength - 1;
72 if (bitno < first_bit)
74 p = &ps[(unsigned) bitno / SET_WORD_SIZE];
76 if (((unsigned) bitlength % SET_WORD_SIZE) != 0)
77 MASK_UNUSED_WORD_BITS(&c, (unsigned) bitlength % SET_WORD_SIZE);
81 bitno -= ((unsigned) bitno % SET_WORD_SIZE) + 1;
82 while (bitno >= first_bit)
87 bitno -= SET_WORD_SIZE;
91 for (; bitno >= first_bit; bitno--)
93 if (GET_BIT_IN_WORD (c, (unsigned) bitno % SET_WORD_SIZE))