Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
	(1) Its Recipients shall ensure that this Notice is
14
	reproduced upon any copies or amended versions of it;
15
 
16
	(2) Any amended version of it shall be clearly marked to
17
	show both the nature of and the organisation responsible
18
	for the relevant amendment or amendments;
19
 
20
	(3) Its onward transfer from a recipient to another
21
	party shall be deemed to be that party's acceptance of
22
	these conditions;
23
 
24
	(4) DERA gives no warranty or assurance as to its
25
	quality or suitability for any purpose and DERA accepts
26
	no liability whatsoever in relation to any use to which
27
	it may be put.
28
*/
29
 
30
 
31
/*
32
$Log: getregs.c,v $
33
 * Revision 1.1.1.1  1998/01/17  15:56:02  release
34
 * First version to be checked into rolling release.
35
 *
36
 * Revision 1.2  1995/12/18  13:11:23  wfs
37
 * Put hppatrans uder cvs control. Major Changes made since last release
38
 * include:
39
 * (i) PIC code generation.
40
 * (ii) Profiling.
41
 * (iii) Dynamic Initialization.
42
 * (iv) Debugging of Exception Handling and Diagnostics.
43
 *
44
 * Revision 5.0  1995/08/25  13:42:58  wfs
45
 * Preperation for August 25 Glue release
46
 *
47
 * Revision 3.4  1995/08/25  09:26:59  wfs
48
 * register synonyms changed. some code removed which had become
49
 * superfluous after changes to the way registers were allocated
50
 *
51
 * Revision 3.4  1995/08/25  09:26:59  wfs
52
 * register synonyms changed. some code removed which had become
53
 * superfluous after changes to the way registers were allocated
54
 *
55
 * Revision 3.1  95/04/10  16:26:30  16:26:30  wfs (William Simmonds)
56
 * Apr95 tape version.
57
 * 
58
 * Revision 3.0  95/03/30  11:17:11  11:17:11  wfs (William Simmonds)
59
 * Mar95 tape version with CRCR95_178 bug fix.
60
 * 
61
 * Revision 2.0  95/03/15  15:26:57  15:26:57  wfs (William Simmonds)
62
 * spec 3.1 changes implemented, tests outstanding.
63
 * 
64
 * Revision 1.1  95/01/11  13:07:36  13:07:36  wfs (William Simmonds)
65
 * Initial revision
66
 * 
67
*/
68
 
69
#define HPPATRANS_CODE
70
/******************************************************************
71
		getregs.c
72
 
73
	Routines for choosing temporary registers. The next free
74
register is chosen cyclically from available t regs.
75
 
76
	The parameter is usually taken from a value of type space
77
(which has bits for fixed and floating regs).  A clear bit indicates
78
that the corresponding register is free for use.
79
 
80
******************************************************************/
81
 
82
#include "config.h"
83
#include "myassert.h"
84
#include "regmacs.h"
85
#include "proctypes.h"
86
#include "exptypes.h"
87
#include "procrec.h"
88
#include "expmacs.h"
89
#include "exp.h"
90
#include "addrtypes.h"
91
#include "regexps.h"
92
#include "tags.h"
93
#include "expmacs.h"
94
#include "bitsmacs.h"
95
#include "getregs.h"
96
 
97
 
98
/* next fixed reg to be allocated */
99
static int currentfix = R_FIRST;
100
static long choosefix = RMASK(R_FIRST);
101
 
102
/* next float reg to be allocated */
103
static int currentfloat = R_FLT_FIRST;
104
static long choosefloat = RMASK(R_FLT_FIRST);
105
 
106
 
107
/* reset getreg() and getfreg() back to start of sequence for proc 'tg' */
108
/* (help register numbers be backward compatible). */
109
void settempregs 
110
    PROTO_N ( ( tg ) )
111
    PROTO_T ( exp tg )
112
{
113
  /*ARGSUSED*/
114
  currentfix = GR2;
115
  choosefix = RMASK(currentfix);
116
 
117
  currentfloat = 1;
118
  choosefloat = RMASK(currentfloat);
119
 
120
}
121
 
122
/* get a free temporary fixed pt reg */
123
int getreg
124
    PROTO_N ( ( fixed ) )
125
    PROTO_T ( long fixed )
126
{
127
 
128
  /*
129
   * Choose reg from set 'fixed'. Chosen in a cyclic order, to give good
130
   * chance for peep-hole optimiser finding something useful lying around. Bit
131
   * set in set 'fixed' means it is unavailable, we search for 0 bit.
132
   */
133
  int reg = -1;
134
  long start = choosefix;
135
 
136
 
137
  FULLCOMMENT3("getreg: from %#x, choosefix=%#x currentfix=%d", fixed, choosefix, currentfix);
138
 
139
  /* currentfix and choosefix are in step, one the reg number, one the mask */
140
  assert(choosefix == RMASK(currentfix));
141
 
142
  for (;;)
143
  {
144
    if ((choosefix & fixed) == 0)
145
      reg = currentfix;
146
 
147
    assert(reg != GR0); 	/* hard wired to 0, shouldn't be in set */
148
    assert(reg != GR1);	       /* ad-hoc temporary                     */
149
    assert(reg != DP);        /* %dp must not be changed              */
150
    assert(reg != SP);       /* %sp must not be changed              */
151
 
152
    if (currentfix == R_LAST)
153
    {
154
       /* back to start */
155
       currentfix = R_FIRST;
156
       choosefix = RMASK(R_FIRST);
157
    }
158
    else
159
    {
160
       /* next reg */
161
       currentfix++;
162
       choosefix = choosefix << 1;
163
    }
164
 
165
    if (reg != -1)
166
    {
167
       FULLCOMMENT1("getreg: allocating %d", reg);
168
       assert(IS_TREG(reg));
169
       return reg;
170
    }
171
    if (choosefix == start)
172
    {
173
       fail("getreg: too many regs required");
174
       return GR0;
175
    }
176
  }
177
  /* NOTREACHED */
178
}
179
 
180
 
181
int getfreg 
182
    PROTO_N ( ( fl ) )
183
    PROTO_T ( long fl ) /* get a free temporary floating reg */
184
{
185
 
186
  /*
187
   * Choose reg from set 'fl'. Chosen in a cyclic order, to give good chance
188
   * for peep-hole optimiser finding something useful lying around. Bit set in
189
   * set 'float' means it is unavailable, we search for 0 bit.
190
   */
191
  int reg = -1;
192
  long start = choosefloat;
193
 
194
  FULLCOMMENT3("getfreg: from %#x, choosefloat=%#x currentfloat=%d", fl, choosefloat, currentfloat);
195
 
196
  /*
197
   * currentfloat and choosefloat are in step, one the reg number, one the
198
   * mask
199
   */
200
  assert(choosefloat == RMASK(currentfloat));
201
 
202
  for (;;)
203
  {
204
    if (((choosefloat & fl) == 0) && IS_FLT_TREG(currentfloat))
205
       reg = currentfloat;
206
 
207
    if (currentfloat == R_FLT_LAST)
208
    {
209
      /* back to start */
210
      currentfloat = R_FLT_FIRST;
211
      choosefloat = RMASK(R_FLT_FIRST);
212
    }
213
    else
214
    {
215
      /* next reg */
216
      currentfloat++;
217
      choosefloat = choosefloat << 1;
218
    }
219
 
220
    if (reg != -1)
221
    {
222
      FULLCOMMENT1("getfreg: allocating %d", reg);
223
      assert(IS_FLT_TREG(reg));
224
      return reg;
225
    }
226
 
227
    if (choosefloat == start)
228
    {
229
      fail("getfreg: too many floating point regs required");
230
      return 0;
231
    }
232
  }
233
}
234
 
235
 
236
 
237
 
238
 
239
 
240
 
241
 
242
 
243
 
244
 
245
 
246
 
247
 
248
 
249
 
250
 
251
 
252
 
253
 
254
 
255
 
256
 
257
 
258
 
259
 
260
 
261
 
262
 
263
 
264
 
265
 
266
 
267
 
268
 
269
 
270
 
271
 
272
 
273
 
274
 
275
 
276
 
277
 
278
 
279
 
280
 
281
 
282
 
283
 
284
 
285
 
286