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
$Author: release $
33
$Date: 1998/01/17 15:56:05 $
34
$Revision: 1.1.1.1 $
35
$Log: getregs.c,v $
36
 * Revision 1.1.1.1  1998/01/17  15:56:05  release
37
 * First version to be checked into rolling release.
38
 *
39
 * Revision 1.1  1995/04/13  09:08:06  currie
40
 * Initial revision
41
 *
42
***********************************************************************/
43
/******************************************************************
44
		getregs.c
45
 
46
	Routines for choosing temporary registers. The next free
47
register is chosen cyclically from the registers 8-15, 24 and 25 for
48
fixed point and 4-10 and 16-18 in floating point (a factor of 2 is involved here) by examining the bit pattern of the parameter. If the current proc allows it, regs 4-7 may also be used as t-regs - this is the function of chooseafter25 etc. The parameter is usuallytaken from a value of type
49
 space (which has bits for fixed and floating regs).
50
A clear bit indicates that the corresponding register is free for use.
51
 
52
******************************************************************/
53
#include "config.h"
54
#include "common_types.h"
55
#include "procrectypes.h"
56
#include "exptypes.h"
57
#include "expmacs.h"
58
#include "exp.h"
59
#include "regexps.h"
60
#include "tags.h"
61
#include "expmacs.h"
62
#include "bitsmacs.h"
63
#include "flags.h"
64
#include "getregs.h"
65
#include "basicread.h"
66
 
67
extern  procrec * procrecs;
68
static long useable_fixed;
69
static long useable_float;
70
 
71
#define for8  0x100		/* bit pattern for $8,  bit 9 is set */
72
#define for15    0x8000		/* bit pattern for $15, bit 16 is set */
73
#define for24 0x1000000		/* etc ... */
74
#define for25 0x2000000
75
 
76
#define for0  0x1
77
#define for4  0x10
78
#define for5  0x20
79
#define for9  0x200
80
 
81
 
82
long  choosefix = for8;		/* first fixed reg to be allocated */
83
long  choosefloat = for0;	/* first float reg to be allocated */
84
 
85
int   currentfix = 8;
86
int   currentfloat = 2;
87
static int   maxfixed;
88
static int   maxfloat = 9;
89
static int minfixed;
90
static long formin;
91
 
92
 
93
void settempregs
94
    PROTO_N ( (tg) )
95
    PROTO_T ( exp tg )
96
{
97
				/* tg is a proc; sets up useable_fixed etc
98
				   depending on how the proc treats its
99
				   parameters; if they are destined for
100
				   store or s-registers we can use some of
101
				    regs 4-7 */
102
  procrec * pr = &procrecs[no(tg)];
103
  bool leaf = ((pr->needsproc).propsneeds & anyproccall)==0;
104
  exp stg = son(tg);
105
  currentfix = 8;
106
  currentfloat = 0;
107
  choosefix = for8;
108
  choosefloat = for0;
109
  useable_fixed = 0x8300fffc;
110
	/* r31 (lnk) /r24-25/ r8-r15/ r4-r7 (pars) /r2-r3*/
111
  useable_float = 0x3ff;	/* f0-f2 (resreg) f4-f10 f12-f14 (pars)
112
  					f16-f18*/
113
  if (leaf) {
114
  	useable_fixed &= ~0x80000000;
115
  	maxfixed = 25;
116
  }
117
  else maxfixed = 31;
118
 
119
  if (PIC_code) {
120
	useable_fixed &= ~0x02000000;
121
	if (maxfixed==25) maxfixed = 24;
122
  }
123
 
124
  if (((pr->needsproc).propsneeds & uses2_bit) != 0) {
125
	useable_fixed &= ~0x4;
126
	minfixed = 3;
127
	formin = 0x8;
128
  }
129
  else {
130
	minfixed = 2;
131
	formin = 0x4;
132
  }
133
 
134
  while (name(stg)==ident_tag && isparam(stg)) {
135
  	if ((props(stg) & inreg_bits) !=0 ) {
136
  		useable_fixed &= ~ (1<<no(stg));
137
  	}
138
  	else
139
  	if ((props(stg) & infreg_bits) != 0) {
140
  		useable_float &= ~(1<<no(stg));
141
  	}
142
  	stg = bro(son(stg));
143
  }
144
 
145
}
146
 
147
int   getreg
148
    PROTO_N ( (fixed) )
149
    PROTO_T ( long fixed )
150
{	/* get a free temporary fixed pt reg */
151
  int   reg = -1;
152
  long  start = choosefix;
153
 
154
 
155
  for (;;) {
156
    if ((choosefix & fixed) == 0) {
157
      reg = currentfix;
158
    }
159
  cycle:
160
    if (currentfix >= maxfixed) {
161
    	currentfix = minfixed;
162
    	choosefix = formin;
163
    }
164
    else {
165
      currentfix +=1;
166
      choosefix <<= 1;
167
    }
168
 
169
    if ((choosefix & useable_fixed) != 0) {
170
    	if (reg >=0) break;
171
    	else continue;
172
    }
173
    if (choosefix == start) {
174
    	failer("Too many fixed regs required");
175
    		break;
176
    }
177
    goto cycle;
178
  }
179
  return reg;
180
}
181
 
182
 
183
int   getfreg
184
    PROTO_N ( (fl) )
185
    PROTO_T ( long fl )
186
{	/* get a free temporary floating reg */
187
  int   reg = -1;
188
  long  start = choosefloat;
189
 
190
  for (;;) {
191
    if ((choosefloat & fl) == 0) {
192
      reg = currentfloat;
193
    }
194
  cycle:
195
    if (currentfloat >= maxfloat) {
196
    	currentfloat = 0;
197
    	choosefloat = for0;
198
    }
199
    else {
200
      currentfloat +=1;
201
      choosefloat <<= 1;
202
    }
203
 
204
    if ((choosefloat & useable_float) != 0) {
205
    	if (reg >=0) break;
206
    	else continue;
207
    }
208
    if (choosefloat == start) {
209
    	failer("Too many float regs required");
210
    		break;
211
    }
212
    goto cycle;
213
  }
214
  return reg;
215
}