OSDN Git Service

* Chill runtime moved into toplevel libchill.
[pf3gnuchains/gcc-fork.git] / libchill / copyps.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 /*
28  * function __powerset_copy
29  *    This is more general than __psslice, since it
30  *    can be told where in the destination powerset (DOFFSET
31  *    parameter) to start storing the slice.
32  *
33  * parameters:
34  *      dps             dest powerset
35  *      dbl             destination bit length
36  *      doffset         offset bit number (zero origin)
37  *      sps             sourcepowerset
38  *      sbl             source powerset length in bits
39  *      start           starting bit number
40  *      end             ending bit number
41  *
42  * exceptions:
43  *  none
44  *
45  * abstract:
46  *  Extract into a powerset a slice of another powerset.
47  *
48  */
49 void
50 __pscpy (dps, dbl, doffset, sps, sbl, start, length)
51      SET_WORD      *dps;
52      unsigned long  dbl;
53      unsigned long  doffset;
54      const SET_WORD*sps;
55      unsigned long  sbl;
56      unsigned long  start;
57      unsigned long  length;
58 {
59   unsigned long end = start + length - 1;
60   unsigned long src, dst;
61
62   /* assert end >= start;
63      assert end - start + 1 <= dbl;
64      assert "the sets don't overlap in memory" */
65
66   /* assert doffset >= 0 and < dbl */
67
68   for (src = start, dst = doffset; src <= end; src++, dst++)
69     {
70       char tmp;
71
72       if (sbl <= SET_CHAR_SIZE)                /* fetch a bit */
73         tmp = GET_BIT_IN_CHAR (*((SET_CHAR *)sps), src);
74       else if (sbl <= SET_SHORT_SIZE)
75         tmp = GET_BIT_IN_SHORT (*((SET_SHORT *)sps), src);
76       else
77         tmp = GET_BIT_IN_WORD (sps[src / SET_WORD_SIZE], src % SET_WORD_SIZE);
78
79       if (tmp & 1)
80         {
81           if (dbl <= SET_CHAR_SIZE)            /* store a 1-bit */
82             SET_BIT_IN_CHAR (*((SET_CHAR *)dps), dst);
83           else if (dbl <= SET_SHORT_SIZE)
84             SET_BIT_IN_SHORT (*((SET_SHORT *)dps), dst);
85           else
86             SET_BIT_IN_WORD (dps[dst / SET_WORD_SIZE], dst % SET_WORD_SIZE);
87         }
88       else
89         {
90           if (dbl <= SET_CHAR_SIZE)            /* store a 0-bit */
91             CLEAR_BIT_IN_CHAR (*((SET_CHAR *)dps), dst);
92           else if (dbl <= SET_SHORT_SIZE)
93             CLEAR_BIT_IN_SHORT (*((SET_SHORT *)dps), dst);
94           else
95             CLEAR_BIT_IN_WORD (dps[dst / SET_WORD_SIZE], dst % SET_WORD_SIZE);
96         }
97     }
98   if (dbl <= SET_CHAR_SIZE)         /* clear unused bits in output bitstring */
99     {
100       MASK_UNUSED_CHAR_BITS ((SET_CHAR *)dps, dbl);
101     }
102   else if (dbl <= SET_SHORT_SIZE)
103     {
104       MASK_UNUSED_SHORT_BITS ((SET_SHORT *)dps, dbl);
105     }
106   else
107     {
108       MASK_UNUSED_WORD_BITS ((SET_WORD *)(dps + (dbl/SET_WORD_SIZE)), 
109                              dbl % SET_WORD_SIZE);
110     }
111 }