Fix for PR1654 - implement "movstrsi" pattern to copy simple blocks of memory.
[official-gcc.git] / libchill / copyps.c
blobf22cde527cb8e4e2fee7a4d9032445e06a1ace08
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)
10 any later version.
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. */
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. */
28 #define __CHILL_LIB__
30 #include <stdio.h>
31 #include "powerset.h"
34 * function __powerset_copy
35 * This is more general than __psslice, since it
36 * can be told where in the destination powerset (DOFFSET
37 * parameter) to start storing the slice.
39 * parameters:
40 * dps dest powerset
41 * dbl destination bit length
42 * doffset offset bit number (zero origin)
43 * sps sourcepowerset
44 * sbl source powerset length in bits
45 * start starting bit number
46 * end ending bit number
48 * exceptions:
49 * none
51 * abstract:
52 * Extract into a powerset a slice of another powerset.
55 void
56 __pscpy (dps, dbl, doffset, sps, sbl, start, length)
57 SET_WORD *dps;
58 unsigned long dbl;
59 unsigned long doffset;
60 const SET_WORD*sps;
61 unsigned long sbl;
62 unsigned long start;
63 unsigned long length;
65 unsigned long end = start + length - 1;
66 unsigned long src, dst;
68 /* assert end >= start;
69 assert end - start + 1 <= dbl;
70 assert "the sets don't overlap in memory" */
72 /* assert doffset >= 0 and < dbl */
74 for (src = start, dst = doffset; src <= end; src++, dst++)
76 char tmp;
78 if (sbl <= SET_CHAR_SIZE) /* fetch a bit */
79 tmp = GET_BIT_IN_CHAR (*((SET_CHAR *)sps), src);
80 else if (sbl <= SET_SHORT_SIZE)
81 tmp = GET_BIT_IN_SHORT (*((SET_SHORT *)sps), src);
82 else
83 tmp = GET_BIT_IN_WORD (sps[src / SET_WORD_SIZE], src % SET_WORD_SIZE);
85 if (tmp & 1)
87 if (dbl <= SET_CHAR_SIZE) /* store a 1-bit */
88 SET_BIT_IN_CHAR (*((SET_CHAR *)dps), dst);
89 else if (dbl <= SET_SHORT_SIZE)
90 SET_BIT_IN_SHORT (*((SET_SHORT *)dps), dst);
91 else
92 SET_BIT_IN_WORD (dps[dst / SET_WORD_SIZE], dst % SET_WORD_SIZE);
94 else
96 if (dbl <= SET_CHAR_SIZE) /* store a 0-bit */
97 CLEAR_BIT_IN_CHAR (*((SET_CHAR *)dps), dst);
98 else if (dbl <= SET_SHORT_SIZE)
99 CLEAR_BIT_IN_SHORT (*((SET_SHORT *)dps), dst);
100 else
101 CLEAR_BIT_IN_WORD (dps[dst / SET_WORD_SIZE], dst % SET_WORD_SIZE);
104 if (dbl <= SET_CHAR_SIZE) /* clear unused bits in output bitstring */
106 MASK_UNUSED_CHAR_BITS ((SET_CHAR *)dps, dbl);
108 else if (dbl <= SET_SHORT_SIZE)
110 MASK_UNUSED_SHORT_BITS ((SET_SHORT *)dps, dbl);
112 else
114 MASK_UNUSED_WORD_BITS ((SET_WORD *)(dps + (dbl/SET_WORD_SIZE)),
115 dbl % SET_WORD_SIZE);