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: is_worth.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.2 1995/09/12 10:59:28 currie
|
|
|
40 |
* gcc pedanttry
|
|
|
41 |
*
|
|
|
42 |
* Revision 1.1 1995/04/13 09:08:06 currie
|
|
|
43 |
* Initial revision
|
|
|
44 |
*
|
|
|
45 |
***********************************************************************/
|
|
|
46 |
|
|
|
47 |
#include "config.h"
|
|
|
48 |
#include "common_types.h"
|
|
|
49 |
#include "tags.h"
|
|
|
50 |
#include "expmacs.h"
|
|
|
51 |
#include "exp.h"
|
|
|
52 |
#include "shapemacs.h"
|
|
|
53 |
#include "is_worth.h"
|
|
|
54 |
|
|
|
55 |
#define true 1
|
|
|
56 |
#define false 0
|
|
|
57 |
|
|
|
58 |
int is_worth
|
|
|
59 |
PROTO_N ( (c) )
|
|
|
60 |
PROTO_T ( exp c )
|
|
|
61 |
{ /* decide if constant c is worth declaring
|
|
|
62 |
separately */
|
|
|
63 |
unsigned char cnam = name (c);
|
|
|
64 |
bool isflt = is_floating(name(sh(c)));
|
|
|
65 |
|
|
|
66 |
if (name (sh (c)) == ptrhd && al1(sh(c))==1 )
|
|
|
67 |
return 0; /* ptr bits */
|
|
|
68 |
if (cnam == real_tag) return true;
|
|
|
69 |
if (cnam == cont_tag && isflt && (name(son(c)) != name_tag || isglob(son(son(c))) )) {
|
|
|
70 |
return true;
|
|
|
71 |
}
|
|
|
72 |
if (cnam == cont_tag && name (son (c)) == name_tag && isglob (son (son (c)))) {
|
|
|
73 |
return true;
|
|
|
74 |
}
|
|
|
75 |
if (cnam == val_tag) { /* it is sometimes worthwhile extracting
|
|
|
76 |
big constants from loops ... */
|
|
|
77 |
long n = no (c);
|
|
|
78 |
exp dad;
|
|
|
79 |
if (n == 0 || bro(c)==nilexp) {
|
|
|
80 |
return false;
|
|
|
81 |
}
|
|
|
82 |
dad = father (c);
|
|
|
83 |
if (dad==nilexp) return false;
|
|
|
84 |
switch (name (dad)) {
|
|
|
85 |
case and_tag:
|
|
|
86 |
{
|
|
|
87 |
exp grandad = father (dad);
|
|
|
88 |
if ( grandad != nilexp &&
|
|
|
89 |
name (grandad) == test_tag && (n & (n - 1)) == 0 &&
|
|
|
90 |
(props (grandad) == 5 || props (grandad) == 6) &&
|
|
|
91 |
((name (bro (son (grandad))) == val_tag && no (bro (son (grandad))) == 0)
|
|
|
92 |
|| (name (son (grandad)) == val_tag && no (son (grandad)) == 0))
|
|
|
93 |
) { /* a & 2^n == 0 is transformed later to
|
|
|
94 |
shift and test negative */
|
|
|
95 |
return 0;
|
|
|
96 |
}
|
|
|
97 |
/* else next case */
|
|
|
98 |
}
|
|
|
99 |
case or_tag:
|
|
|
100 |
case xor_tag:
|
|
|
101 |
|
|
|
102 |
{
|
|
|
103 |
return (n < 0 || n >= 0xffff);/* short literal operands */
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
case test_tag: return 1;
|
|
|
107 |
case mult_tag: case offset_mult_tag:
|
|
|
108 |
{
|
|
|
109 |
if (n <= 0x7fff && n > -0x8000)
|
|
|
110 |
return 0; /* short literal operands */
|
|
|
111 |
/* a*2^n and a*2^(n+-1) are transformed later to shifts and adds
|
|
|
112 |
*/
|
|
|
113 |
return ((n & (n - 1)) != 0 && (n & (n + 1)) != 0 && ((n - 1) & (n - 2)) != 0);
|
|
|
114 |
}
|
|
|
115 |
case div1_tag:
|
|
|
116 |
case div2_tag:
|
|
|
117 |
case rem2_tag:
|
|
|
118 |
{
|
|
|
119 |
if (n <= 0x7fff && n > -0x8000)
|
|
|
120 |
return 0 /* short literal operands */ ;
|
|
|
121 |
/* a/2^n transformed later to shift */
|
|
|
122 |
return ((n & (n - 1)) != 0);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
default:
|
|
|
126 |
{
|
|
|
127 |
return (n > 0x7fff || n < -0x8000) /* short literal operands */ ;
|
|
|
128 |
}
|
|
|
129 |
} /* end sw */
|
|
|
130 |
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
return ((!is_o (cnam) && cnam != clear_tag) ||
|
|
|
134 |
/* ignore simple things unless ... */
|
|
|
135 |
(cnam == cont_tag && name (son (c)) == cont_tag &&
|
|
|
136 |
name (son (son (c))) == name_tag)
|
|
|
137 |
);
|
|
|
138 |
|
|
|
139 |
}
|