]>
Commit | Line | Data |
---|---|---|
b79f73df JL |
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 | /* | |
28 | * function __ltpowerset | |
29 | * | |
30 | * parameters: | |
31 | * left powerset | |
32 | * right powerset | |
33 | * bitlength length of powerset | |
34 | * | |
35 | * returns: | |
36 | * int 1 .. left is proper subset of right | |
37 | * (excludes case where left == right) | |
38 | * 0 .. not | |
39 | * | |
40 | * abstract: | |
41 | * check if one powerset is included in another | |
42 | * | |
43 | */ | |
44 | int | |
45 | __ltpowerset (left, right, bitlength) | |
46 | SET_WORD *left; | |
47 | SET_WORD *right; | |
48 | unsigned long bitlength; | |
49 | { | |
50 | if (bitlength <= SET_CHAR_SIZE) | |
51 | { | |
52 | if ((*((SET_CHAR *)left) & *((SET_CHAR *)right)) | |
53 | != *((SET_CHAR *)left)) | |
54 | return 0; | |
55 | if (*((SET_CHAR *)left) != *((SET_CHAR *)right)) | |
56 | return 1; | |
57 | return 0; | |
58 | } | |
59 | else if (bitlength <= SET_SHORT_SIZE) | |
60 | { | |
61 | if ((*((SET_SHORT *)left) & *((SET_SHORT *)right)) | |
62 | != *((SET_SHORT *)left)) | |
63 | return 0; | |
64 | if (*((SET_SHORT *)left) != *((SET_SHORT *)right)) | |
65 | return 1; | |
66 | return 0; | |
67 | } | |
68 | else | |
69 | { | |
70 | SET_WORD *endp = left + BITS_TO_WORDS(bitlength); | |
71 | int all_equal = 1; /* assume all bits are equal */ | |
72 | ||
73 | while (left < endp) | |
74 | { | |
75 | if ((*right & *left) != *left) | |
76 | return 0; | |
77 | if (*left != *right) | |
78 | all_equal = 0; | |
79 | left++; | |
80 | right++; | |
81 | } | |
82 | if (left == endp && all_equal) /* exclude TRUE return for == case */ | |
83 | return 0; | |
84 | return 1; | |
85 | } | |
86 | } |