Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/algol60/src/installers/alpha/common/operators.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | 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
/* 	$Id: operators.c,v 1.1.1.1 1998/01/17 15:56:01 release Exp $	 */
32
 
33
#ifndef lint
34
static char vcid[] = "$Id: operators.c,v 1.1.1.1 1998/01/17 15:56:01 release Exp $";
35
#endif /* lint */
36
 
37
/* 
38
   operators.c
39
   produces code for common operations
40
 
41
   to do : add support for VAX floating types.
42
*/
43
 
44
/*
45
$Log: operators.c,v $
46
 * Revision 1.1.1.1  1998/01/17  15:56:01  release
47
 * First version to be checked into rolling release.
48
 *
49
 * Revision 1.6  1996/06/19  15:15:03  john
50
 * Fix for discarded operations
51
 *
52
 * Revision 1.5  1995/09/29  07:55:05  john
53
 * Fixed condition for setting Has_no_vcallers
54
 *
55
 * Revision 1.4  1995/08/21  08:46:01  john
56
 * Changed include files
57
 *
58
 * Revision 1.3  1995/06/21  14:25:32  john
59
 * Reformatting
60
 *
61
 * Revision 1.2  1995/05/16  10:54:12  john
62
 * Cosmetic change
63
 *
64
 * Revision 1.1.1.1  1995/03/23  10:39:15  john
65
 * Entered into CVS
66
 *
67
 * Revision 1.9  1995/01/26  13:45:57  john
68
 * Removed unused variable
69
 *
70
 * Revision 1.8  1995/01/12  15:12:36  john
71
 * Removed dead code
72
 *
73
*/
74
 
75
#include "config.h"
76
#include "code_here.h"
77
#include "expmacs.h"
78
#include "addresstypes.h"
79
#include "inst_fmt.h"
80
#include "move.h"
81
#include "maxminmacs.h"
82
#include "getregs.h"
83
#include "guard.h"
84
#include "tags.h"
85
#include "shapemacs.h"
86
#include "bitsmacs.h"
87
#include "common_types.h"
88
#include "alpha_ins.h"
89
#include "f64.h"
90
#include "reg_defs.h"
91
#include "cross.h"
92
#include "operators.h"
93
bool testover = 0;		/* always 0 for C */
94
 
95
void tidyshort
96
    PROTO_N ( ( r, s ) )
97
    PROTO_T ( int r X shape s )
98
{
99
  /* corrects possible overflows of chars
100
     and shorts in reg r */
101
  if (name (s) == ucharhd) {
102
    operate_fmt_immediate (i_and, r,255,r);
103
  }
104
  else
105
    if (name (s) == uwordhd) {
106
      operate_fmt_immediate (i_and, r,0xffff,r);
107
    }
108
}
109
 
110
 
111
/* 
112
   given a list of expressions seq which
113
   contains one whose value is in 
114
   register reg, removes that exp from seq
115
   and delivers 1; otherwise delivers 0 
116
*/
117
bool regremoved
118
    PROTO_N ( ( seq, reg ) )
119
    PROTO_T ( exp *seq X int reg )
120
{
121
  exp s = *seq;
122
  exp t = bro (s);
123
  if (abs (regofval (s)) == reg) {
124
    (*seq) = t;
125
    return 1;
126
  }
127
  for (;;) {
128
    if (abs (regofval (t)) == reg) {
129
      bro (s) = bro (t);
130
      if (last (t))
131
	setlast (s);
132
      return 1;
133
    }
134
    if (last (t)) {
135
      return 0;
136
    }
137
    s = t;
138
    t = bro (t);
139
  }
140
}
141
 
142
 
143
void do_comm
144
    PROTO_N ( ( seq, sp, final, rins ) )
145
    PROTO_T ( exp seq X space sp X int final X instruction rins )
146
{
147
  int   r = 0;
148
  space nsp;
149
  int   a1;
150
  int   a2;
151
  a1 = reg_operand (seq, sp);
152
  /* evaluate 1st operand into a1 */
153
  for (;;) {
154
    nsp = guardreg (a1, sp);
155
    seq = bro (seq);
156
    if (name (seq) == val_tag) {/* next operand is a constant */
157
      if (last (seq)) {
158
	if(isbigval(seq)){
159
	  int ov;
160
	  flt64 res;
161
	  INT64 ires;
162
	  res = flt_to_f64(no(seq),is_signed(sh(seq)),&ov);
163
	  ires = flt64_to_INT64(res);
164
	  operate_fmt_big_immediate(rins,a1,ires,final);
165
	}
166
	else
167
	  operate_fmt_immediate (rins,a1,no(seq),final);
168
	return;
169
      }
170
      else {
171
	if (r == 0)
172
	  r = getreg (sp.fixed);
173
	if(isbigval(seq)){
174
	  int ov;
175
	  flt64 res;
176
	  INT64 ires;
177
	  res = flt_to_f64(no(seq),is_signed(sh(seq)),&ov);
178
	  ires = flt64_to_INT64(res);
179
	  operate_fmt_big_immediate(rins,a1,ires,r);
180
	}
181
	else
182
	  operate_fmt_immediate(rins,a1,no(seq),r);
183
      }
184
    }
185
    else {
186
      exp sq = seq;
187
      instruction ins = rins;
188
      a2 = reg_operand (sq, nsp);
189
      /* evaluate next operand */
190
      if (last (seq)) {
191
	operate_fmt(ins,a1,a2,final);
192
	return;
193
      }
194
      else {
195
	if (r == 0)
196
	  r = getreg (sp.fixed);
197
	operate_fmt (ins,a1, a2,r);
198
      }
199
    }
200
    a1 = r;
201
  }
202
  return;
203
}
204
 
205
/* 
206
   evaluate commutative operation rrins given by e into d, using 
207
   sp to get t-regs 
208
*/
209
int comm_op
210
    PROTO_N ( ( e, sp, d, rrins ) )
211
    PROTO_T ( exp e X space sp X where d X instruction rrins )
212
{
213
  instruction rins = rrins;
214
  switch (d.answhere.discrim) {
215
    case inreg: {
216
      int   dest = regalt (d.answhere);
217
      bool usesdest = regremoved (&son (e), dest);
218
      exp seq = son (e);
219
      if(dest == NO_REG) {
220
	dest = getreg(sp.fixed);
221
      }
222
 
223
      /* the destination is in a register; take care that 
224
	 we dont alter it before possible use as an operand .... */
225
      if (usesdest && last (seq)) {
226
	/* ...it was used, but there is only one
227
	   other operand */
228
	if (name (seq) == val_tag) {
229
	  operate_fmt_immediate (rins, dest, no (seq),dest);
230
	}
231
	else {
232
	  operate_fmt (rins, dest,reg_operand (seq, sp),dest);
233
	}
234
	tidyshort (dest, sh (e));
235
	return dest;
236
      }
237
      else if (usesdest) {	/* ... it was used so ... */
238
        int   r = getreg (sp.fixed);
239
	do_comm (seq, sp, r, rins);
240
	/* ... evaluate the remainder of the expression into r... */
241
	operate_fmt (rins, dest, r,dest);
242
	/* ... and do dest = dest rins r */
243
	tidyshort (dest, sh (e));
244
	return dest;
245
      }
246
      else {		/* ... it wasn't used */
247
	do_comm (seq, sp, dest, rins);
248
	tidyshort (dest, sh (e));
249
	return dest;
250
      }	
251
    }					/* end inreg */
252
    default:{
253
      ans a;
254
      int   r = getreg (sp.fixed);
255
      space nsp;
256
      setregalt (a, r);
257
      do_comm (son (e), sp, r, rins);
258
      /* evaluate the expression into r ... */
259
      tidyshort (r, sh (e));
260
      nsp = guardreg (r, sp);
261
      move (a, d, nsp, 1);
262
      /* ... and move into a */
263
      return r;
264
    }				/* notinreg */
265
  }	      			/* end switch */
266
}
267
 
268
 
269
 
270
int non_comm_op
271
    PROTO_N ( ( e, sp, dest, rins ) )
272
    PROTO_T ( exp e X space sp X where dest X instruction rins )
273
{
274
  /* evalate binary operation e with rins
275
     into dest */
276
  exp l = son (e);
277
  exp r = bro (l);
278
  int   a1 = reg_operand (l, sp);
279
  space nsp;
280
  int   a2;
281
  instruction ins = rins;
282
  nsp = guardreg (a1, sp);
283
  a2 = reg_operand (r, nsp);
284
  /* regs a1 and a2 contain the operands */
285
  switch (dest.answhere.discrim) {
286
    case inreg: {
287
      int   d = regalt (dest.answhere);
288
      if(d!=NO_REG){
289
	operate_fmt(ins,a1,a2,d);
290
	tidyshort (d, sh (e));
291
      }
292
      return d;
293
    }
294
    default:{
295
      ans a;
296
      int   r1 = getreg (nsp.fixed);
297
      setregalt (a, r1);
298
      operate_fmt (ins, a1,a2,r1);
299
      tidyshort (r1, sh (e));
300
      nsp = guardreg (r1, sp);
301
      move (a, dest, nsp, 1);
302
      return r1;
303
    }
304
  }
305
}
306
 
307
 
308
 
309
/* evaluate floating dyadic operation e using ins into dest */
310
int fop
311
    PROTO_N ( ( e, sp, dest, ins ) )
312
    PROTO_T ( exp e X space sp X where dest X instruction ins )
313
{
314
  exp l = son (e);
315
  exp r = bro (l);
316
  int   a1;
317
  space nsp;
318
  int   a2;
319
 
320
  if (IsRev(e)) {
321
    a2 = freg_operand (r, sp);
322
    nsp = guardfreg (a2, sp);
323
    a1 = freg_operand(l, nsp);
324
  }
325
  else {
326
    a1 = freg_operand (l, sp);
327
    nsp = guardfreg (a1, sp);
328
    a2 = freg_operand(r, nsp);
329
  }
330
  switch (dest.answhere.discrim) {
331
    case infreg:{ 		/* dest in register */
332
      freg fr;
333
      fr = fregalt (dest.answhere);
334
      float_op(ins,a1,a2,fr.fr);
335
      return((fr.type==IEEE_double)?-(fr.fr+32):(fr.fr+32));
336
    }
337
    default:{ 			/* destination elsewhere */
338
      ans a;
339
      freg fr;
340
      int   r1 = getfreg (nsp.flt);
341
      fr.fr = r1;
342
      if(dest.ashwhere.ashsize==64)
343
	fr.type=IEEE_double;
344
      else
345
	fr.type=IEEE_single;
346
      setfregalt (a, fr);
347
 
348
      float_op(ins,a1,a2,r1);
349
#if 1
350
      if(dest.answhere.discrim == insomefreg){
351
	*dest.answhere.val.somefregans.fr = r1;
352
	dest.answhere.val.somefregans.type = fr.type;
353
      }
354
      else{
355
#endif
356
	move (a, dest, sp, 1);
357
#if 1
358
      }
359
#endif
360
      return ((fr.type==IEEE_double)?-(fr.fr+32):(fr.fr+32));
361
    }
362
  }
363
}
364
 
365
 
366
 
367
 
368
 
369