* Add library exception clause to the copyright notice for all
[gcc.git] / libchill / ltps.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 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
27
28 #define __CHILL_LIB__
29
30 #include <stdio.h>
31 #include "powerset.h"
32
33 /*
34 * function __ltpowerset
35 *
36 * parameters:
37 * left powerset
38 * right powerset
39 * bitlength length of powerset
40 *
41 * returns:
42 * int 1 .. left is proper subset of right
43 * (excludes case where left == right)
44 * 0 .. not
45 *
46 * abstract:
47 * check if one powerset is included in another
48 *
49 */
50 int
51 __ltpowerset (left, right, bitlength)
52 SET_WORD *left;
53 SET_WORD *right;
54 unsigned long bitlength;
55 {
56 if (bitlength <= SET_CHAR_SIZE)
57 {
58 if ((*((SET_CHAR *)left) & *((SET_CHAR *)right))
59 != *((SET_CHAR *)left))
60 return 0;
61 if (*((SET_CHAR *)left) != *((SET_CHAR *)right))
62 return 1;
63 return 0;
64 }
65 else if (bitlength <= SET_SHORT_SIZE)
66 {
67 if ((*((SET_SHORT *)left) & *((SET_SHORT *)right))
68 != *((SET_SHORT *)left))
69 return 0;
70 if (*((SET_SHORT *)left) != *((SET_SHORT *)right))
71 return 1;
72 return 0;
73 }
74 else
75 {
76 SET_WORD *endp = left + BITS_TO_WORDS(bitlength);
77 int all_equal = 1; /* assume all bits are equal */
78
79 while (left < endp)
80 {
81 if ((*right & *left) != *left)
82 return 0;
83 if (*left != *right)
84 all_equal = 0;
85 left++;
86 right++;
87 }
88 if (left == endp && all_equal) /* exclude TRUE return for == case */
89 return 0;
90 return 1;
91 }
92 }