Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
	(1) Its Recipients shall ensure that this Notice is
43
	(1) Its Recipients shall ensure that this Notice is
14
	reproduced upon any copies or amended versions of it;
44
	reproduced upon any copies or amended versions of it;
15
    
45
 
16
	(2) Any amended version of it shall be clearly marked to
46
	(2) Any amended version of it shall be clearly marked to
17
	show both the nature of and the organisation responsible
47
	show both the nature of and the organisation responsible
18
	for the relevant amendment or amendments;
48
	for the relevant amendment or amendments;
19
    
49
 
20
	(3) Its onward transfer from a recipient to another
50
	(3) Its onward transfer from a recipient to another
21
	party shall be deemed to be that party's acceptance of
51
	party shall be deemed to be that party's acceptance of
22
	these conditions;
52
	these conditions;
23
    
53
 
24
	(4) DERA gives no warranty or assurance as to its
54
	(4) DERA gives no warranty or assurance as to its
25
	quality or suitability for any purpose and DERA accepts
55
	quality or suitability for any purpose and DERA accepts
26
	no liability whatsoever in relation to any use to which
56
	no liability whatsoever in relation to any use to which
27
	it may be put.
57
	it may be put.
28
*/
58
*/
Line 43... Line 73...
43
 *
73
 *
44
 * Revision 5.0  1995/08/25  13:42:58  wfs
74
 * Revision 5.0  1995/08/25  13:42:58  wfs
45
 * Preperation for August 25 Glue release
75
 * Preperation for August 25 Glue release
46
 *
76
 *
47
 * Revision 3.4  1995/08/25  10:41:19  wfs
77
 * Revision 3.4  1995/08/25  10:41:19  wfs
48
 * A few refinements necessary for 3.1 and 4.0 compatability.
78
 * A few refinements necessary for 3.1 and 4.0 compatability.
49
 *
79
 *
50
 * Revision 3.4  1995/08/25  10:41:19  wfs
80
 * Revision 3.4  1995/08/25  10:41:19  wfs
51
 * A few refinements necessary for 3.1 and 4.0 compatability.
81
 * A few refinements necessary for 3.1 and 4.0 compatability.
52
 *
82
 *
53
 * Revision 3.1  95/04/10  16:28:41  16:28:41  wfs (William Simmonds)
83
 * Revision 3.1  95/04/10  16:28:41  16:28:41  wfs (William Simmonds)
54
 * Apr95 tape version.
84
 * Apr95 tape version.
55
 * 
85
 *
56
 * Revision 3.0  95/03/30  11:19:16  11:19:16  wfs (William Simmonds)
86
 * Revision 3.0  95/03/30  11:19:16  11:19:16  wfs (William Simmonds)
57
 * Mar95 tape version with CRCR95_178 bug fix.
87
 * Mar95 tape version with CRCR95_178 bug fix.
58
 * 
88
 *
59
 * Revision 2.0  95/03/15  15:29:06  15:29:06  wfs (William Simmonds)
89
 * Revision 2.0  95/03/15  15:29:06  15:29:06  wfs (William Simmonds)
60
 * spec 3.1 changes implemented, tests outstanding.
90
 * spec 3.1 changes implemented, tests outstanding.
61
 * 
91
 *
62
 * Revision 1.1  95/01/11  13:19:42  13:19:42  wfs (William Simmonds)
92
 * Revision 1.1  95/01/11  13:19:42  13:19:42  wfs (William Simmonds)
63
 * Initial revision
93
 * Initial revision
64
 * 
94
 *
65
*/
95
*/
66
 
96
 
67
 
97
 
68
#define HPPATRANS_CODE
98
#define HPPATRANS_CODE
69
/******************************************************************
99
/******************************************************************
Line 128... Line 158...
128
};
158
};
129
 
159
 
130
/* NB scale, throughout,  should be a float but mips cc V2.10 compiles calls and
160
/* NB scale, throughout,  should be a float but mips cc V2.10 compiles calls and
131
		proc body inconsistently !! */
161
		proc body inconsistently !! */
132
 
162
 
133
weights weightsv PROTO_S ( ( double, exp ) ) ;
163
weights weightsv(double, exp);
134
 
164
 
135
weights add_weights 
165
weights add_weights
136
    PROTO_N ( ( w1, w2 ) )
-
 
137
    PROTO_T ( weights * w1 X weights * w2 )
166
(weights * w1, weights * w2)
138
{
167
{
139
  /* sum of weights */
168
  /* sum of weights */
140
  weights r;
169
  weights r;
141
  long i;
170
  long i;
142
 
171
 
143
  for (i = 0; i < wfixno; ++i)
172
  for (i = 0; i < wfixno; ++i)
144
  {
173
  {
145
    (r.fix)[i] = (w1->fix)[i] + (w2->fix)[i];
174
   (r.fix)[i] = (w1->fix)[i] + (w2->fix)[i];
146
  };
175
  };
147
  for (i = 0; i < wfloatno; ++i)
176
  for (i = 0; i < wfloatno; ++i)
148
  {
177
  {
149
    (r.floating)[i] = (w1->floating)[i] + (w2->floating)[i];
178
   (r.floating)[i] = (w1->floating)[i] + (w2->floating)[i];
150
  };
179
  };
151
  return (r);
180
  return(r);
152
}
181
}
153
 
182
 
154
wp max_weights 
183
wp max_weights
155
    PROTO_N ( ( loc, ws, fix ) )
-
 
156
    PROTO_T ( double loc X weights * ws X bool fix )
184
(double loc, weights * ws, bool fix)
157
{
185
{
158
 
186
 
159
  /*
187
  /*
160
   * loc is the usage count of a tag, ws is the weights computed for the scope
188
   * loc is the usage count of a tag, ws is the weights computed for the scope
161
   * of the tag and fix distinguishes between fix and float. This computes the
189
   * of the tag and fix distinguishes between fix and float. This computes the
Line 168... Line 196...
168
  long bk = wfixno + 1;
196
  long bk = wfixno + 1;
169
  long i;
197
  long i;
170
  float *w = (ws->fix);
198
  float *w = (ws->fix);
171
  /* w[i] = greatest usage of (i+1) inner fixed tags  */
199
  /* w[i] = greatest usage of (i+1) inner fixed tags  */
172
  wp res;
200
  wp res;
173
  float *pw = &(((res.wp_weights).fix)[0]);
201
  float *pw = & (((res.wp_weights).fix)[0]);
174
 
202
 
175
  if (fix)
203
  if (fix)
176
  {
204
  {
177
    for (i = 0; i < wfixno; ++i)
205
    for (i = 0; i < wfixno; ++i)
178
    {
206
    {
Line 226... Line 254...
226
  res.fix_break = bk;
254
  res.fix_break = bk;
227
#endif
255
#endif
228
 
256
 
229
  bk = wfloatno + 1;
257
  bk = wfloatno + 1;
230
  w = (ws->floating);
258
  w = (ws->floating);
231
  pw = &(((res.wp_weights).floating)[0]);
259
  pw = & (((res.wp_weights).floating)[0]);
232
  if (!fix)
260
  if (!fix)
233
  {				/* same algorithm for float regs as fixed regs */
261
  {				/* same algorithm for float regs as fixed regs */
234
    for (i = 0; i < wfloatno; ++i)
262
    for (i = 0; i < wfloatno; ++i)
235
    {
263
    {
236
      if (i == 0)
264
      if (i == 0)
Line 266... Line 294...
266
 
294
 
267
  res.float_break = bk;
295
  res.float_break = bk;
268
  return res;
296
  return res;
269
}
297
}
270
 
298
 
271
weights mult_weights 
299
weights mult_weights
272
    PROTO_N ( ( m, ws ) )
-
 
273
    PROTO_T ( double m X weights * ws )
300
(double m, weights * ws)
274
{
301
{
275
 
302
 
276
  /*
303
  /*
277
   * multiply weights by scalar - non overflowing
304
   * multiply weights by scalar - non overflowing
278
   */
305
   */
279
  weights res;
306
  weights res;
280
  float *r = &(res.fix)[0];
307
  float *r = & (res.fix)[0];
281
  float *w = ws->fix;
308
  float *w = ws->fix;
282
  long i;
309
  long i;
283
 
310
 
284
  for (i = 0; i < wfixno; ++i)
311
  for (i = 0; i < wfixno; ++i)
285
  {
312
  {
286
    r[i] = w[i] * m;
313
    r[i] = w[i]* m;
287
  };
314
  };
288
 
315
 
289
  r = &(res.floating)[0];
316
  r = & (res.floating)[0];
290
  w = ws->floating;
317
  w = ws->floating;
291
  for (i = 0; i < wfloatno; ++i)
318
  for (i = 0; i < wfloatno; ++i)
292
  {
319
  {
293
    r[i] = w[i] * m;
320
    r[i] = w[i]* m;
294
  };
321
  };
295
  return (res);
322
  return(res);
296
}
323
}
297
 
324
 
298
weights add_wlist 
325
weights add_wlist
299
    PROTO_N ( ( scale, re ) )
-
 
300
    PROTO_T ( double scale X exp re )
326
(double scale, exp re)
301
{				/* sum of  weights of list re */
327
{				/* sum of  weights of list re */
302
  weights w, w1;
328
  weights w, w1;
303
  exp r = re;
329
  exp r = re;
304
 
330
 
305
  if (r == nilexp)
331
  if (r == nilexp)
306
  {
332
  {
307
    return zeroweights;
333
    return zeroweights;
308
  }
334
  }
309
  else if (last(r))
335
  else if (last(r))
310
  {
336
  {
311
    return (weightsv(scale, r));
337
    return(weightsv(scale, r));
312
  }
338
  }
313
  else
339
  else
314
  {
340
  {
315
    w = weightsv(scale, r);
341
    w = weightsv(scale, r);
316
    do
342
    do
Line 334... Line 360...
334
inside 'for' loops for example. The procedure reg_alloc in reg_alloc.c
360
inside 'for' loops for example. The procedure reg_alloc in reg_alloc.c
335
finally determines the actual choice of s reg and recodes the number
361
finally determines the actual choice of s reg and recodes the number
336
field of an ident.
362
field of an ident.
337
 
363
 
338
******************************************************************/
364
******************************************************************/
339
weights weightsv 
365
weights weightsv
340
    PROTO_N ( ( scale, e ) )
-
 
341
    PROTO_T ( double scale X exp e )
366
(double scale, exp e)
342
{
367
{
343
  unsigned char n;
368
  unsigned char n;
344
 
369
 
345
  tailrecurse:
370
  tailrecurse:
346
  n = name(e);
371
  n = name(e);
Line 352... Line 377...
352
    {
377
    {
353
      exp s = son(e);
378
      exp s = son(e);
354
 
379
 
355
      if (name(s) == ident_tag && !isglob(s))
380
      if (name(s) == ident_tag && !isglob(s))
356
      {
381
      {
357
	if (is_floating(name(sh(e))) && name(sh(e)) != shrealhd)
382
	if (is_floating(name(sh(e))) && name(sh(e))!= shrealhd)
358
	{
383
	{
359
	  fno(s) += scale * 2.0;
384
	  fno(s) += scale * 2.0;
360
	}
385
	}
361
	else
386
	else
362
	  fno(s) += scale;
387
	  fno(s) += scale;
Line 365... Line 390...
365
      return zeroweights;
390
      return zeroweights;
366
    };
391
    };
367
 
392
 
368
  case ident_tag:
393
  case ident_tag:
369
    {
394
    {
370
      if (son(e) != nilexp)
395
      if (son(e)!= nilexp)
371
      {
396
      {
372
	weights wdef;
397
	weights wdef;
373
	bool wdef_set;
398
	bool wdef_set;
374
	weights wbody;
399
	weights wbody;
375
	long noe = no(e) /* set by scan */ ;
400
	long noe = no(e) /* set by scan */ ;
Line 390... Line 415...
390
	  wdef_set = 0;
415
	  wdef_set = 0;
391
	}
416
	}
392
	else
417
	else
393
	{
418
	{
394
	  /* maybe needs a store to initialise */
419
	  /* maybe needs a store to initialise */
395
	  if (is_floating(name(sh(son(e)))) && name(sh(son(e))) != shrealhd)
420
	  if (is_floating(name(sh(son(e)))) && name(sh(son(e)))!= shrealhd)
396
	  {
421
	  {
397
	    fno(e) = scale * 2.0;
422
	    fno(e) = scale * 2.0;
398
	  }
423
	  }
399
	  else
424
	  else
400
	    fno(e) = scale;
425
	    fno(e) = scale;
Line 414... Line 439...
414
 
439
 
415
	  if ((name(t) == val_tag) || (name(t) == real_tag)) /* +++ string_tag too */
440
	  if ((name(t) == val_tag) || (name(t) == real_tag)) /* +++ string_tag too */
416
	  {
441
	  {
417
	    return wbody;
442
	    return wbody;
418
	  }
443
	  }
419
	  while (name(t) != name_tag)
444
	  while (name(t)!= name_tag)
420
	  {
445
	  {
421
	    t = son(t);
446
	    t = son(t);
422
	  }
447
	  }
423
 
448
 
424
	  s = son(t);
449
	  s = son(t);
Line 483... Line 508...
483
      goto tailrecurse;
508
      goto tailrecurse;
484
    };
509
    };
485
 
510
 
486
  case labst_tag:
511
  case labst_tag:
487
    {
512
    {
488
      scale = fno(e) * scale;
513
      scale = fno(e)* scale;
489
      e = bro(son(e));
514
      e = bro(son(e));
490
      goto tailrecurse;
515
      goto tailrecurse;
491
    }
516
    }
492
 
517
 
493
 
518
 
Line 496... Line 521...
496
      return zeroweights;
521
      return zeroweights;
497
    };
522
    };
498
 
523
 
499
  case ncopies_tag:
524
  case ncopies_tag:
500
    {
525
    {
501
      scale = no(e) * scale;
526
      scale = no(e)* scale;
502
      e = son(e);
527
      e = son(e);
503
      goto tailrecurse;
528
      goto tailrecurse;
504
    }
529
    }
505
 
530
 
506
 
531
 
507
 
532
 
508
 
533
 
509
  default:
534
  default:
510
    {
535
    {
511
      if (son(e) == nilexp || n == env_offset_tag
536
      if (son(e) == nilexp || n == env_offset_tag
512
			   || n == general_env_offset_tag )
537
			   || n == general_env_offset_tag)
513
      {
538
      {
514
	return zeroweights;
539
	return zeroweights;
515
      }
540
      }
516
      if (last(son(e)))
541
      if (last(son(e)))
517
      {
542
      {
518
	e = son(e);
543
	e = son(e);
519
	goto tailrecurse;
544
	goto tailrecurse;
520
      }
545
      }
521
      return (add_wlist(scale, son(e)));
546
      return(add_wlist(scale, son(e)));
522
    }
547
    }
523
  }
548
  }
524
}
549
}
525
 
550
 
526
 
551