1/* Implement POWERSET runtime actions for CHILL. 2 Copyright (C) 1992,1993 Free Software Foundation, Inc. 3 Author: Wilfried Moser, et al 4 5This file is part of GNU CC. 6 7GNU CC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GNU CC is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GNU CC; see the file COPYING. If not, write to 19the Free Software Foundation, 59 Temple Place - Suite 330, 20Boston, MA 02111-1307, USA. */ 21 22/* As a special exception, if you link this library with other files, 23 some of which are compiled with GCC, to produce an executable, 24 this library does not by itself cause the resulting executable 25 to be covered by the GNU General Public License. 26 This exception does not however invalidate any other reasons why 27 the executable file might be covered by the GNU General Public License. */ 28 29#define __CHILL_LIB__ 30 31#include <stdio.h> 32#include "powerset.h" 33 34/* 35 * function __powerset_copy 36 * This is more general than __psslice, since it 37 * can be told where in the destination powerset (DOFFSET 38 * parameter) to start storing the slice. 39 * 40 * parameters: 41 * dps dest powerset 42 * dbl destination bit length 43 * doffset offset bit number (zero origin) 44 * sps sourcepowerset 45 * sbl source powerset length in bits 46 * start starting bit number 47 * end ending bit number 48 * 49 * exceptions: 50 * none 51 * 52 * abstract: 53 * Extract into a powerset a slice of another powerset. 54 * 55 */ 56void 57__pscpy (dps, dbl, doffset, sps, sbl, start, length) 58 SET_WORD *dps; 59 unsigned long dbl; 60 unsigned long doffset; 61 const SET_WORD*sps; 62 unsigned long sbl; 63 unsigned long start; 64 unsigned long length; 65{ 66 unsigned long end = start + length - 1; 67 unsigned long src, dst; 68 69 /* assert end >= start; 70 assert end - start + 1 <= dbl; 71 assert "the sets don't overlap in memory" */ 72 73 /* assert doffset >= 0 and < dbl */ 74 75 for (src = start, dst = doffset; src <= end; src++, dst++) 76 { 77 char tmp; 78 79 if (sbl <= SET_CHAR_SIZE) /* fetch a bit */ 80 tmp = GET_BIT_IN_CHAR (*((SET_CHAR *)sps), src); 81 else if (sbl <= SET_SHORT_SIZE) 82 tmp = GET_BIT_IN_SHORT (*((SET_SHORT *)sps), src); 83 else 84 tmp = GET_BIT_IN_WORD (sps[src / SET_WORD_SIZE], src % SET_WORD_SIZE); 85 86 if (tmp & 1) 87 { 88 if (dbl <= SET_CHAR_SIZE) /* store a 1-bit */ 89 SET_BIT_IN_CHAR (*((SET_CHAR *)dps), dst); 90 else if (dbl <= SET_SHORT_SIZE) 91 SET_BIT_IN_SHORT (*((SET_SHORT *)dps), dst); 92 else 93 SET_BIT_IN_WORD (dps[dst / SET_WORD_SIZE], dst % SET_WORD_SIZE); 94 } 95 else 96 { 97 if (dbl <= SET_CHAR_SIZE) /* store a 0-bit */ 98 CLEAR_BIT_IN_CHAR (*((SET_CHAR *)dps), dst); 99 else if (dbl <= SET_SHORT_SIZE) 100 CLEAR_BIT_IN_SHORT (*((SET_SHORT *)dps), dst); 101 else 102 CLEAR_BIT_IN_WORD (dps[dst / SET_WORD_SIZE], dst % SET_WORD_SIZE); 103 } 104 } 105 if (dbl <= SET_CHAR_SIZE) /* clear unused bits in output bitstring */ 106 { 107 MASK_UNUSED_CHAR_BITS ((SET_CHAR *)dps, dbl); 108 } 109 else if (dbl <= SET_SHORT_SIZE) 110 { 111 MASK_UNUSED_SHORT_BITS ((SET_SHORT *)dps, dbl); 112 } 113 else 114 { 115 MASK_UNUSED_WORD_BITS ((SET_WORD *)(dps + (dbl/SET_WORD_SIZE)), 116 dbl % SET_WORD_SIZE); 117 } 118} 119