Subversion Repositories tendra.SVN

Rev

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
 
32
 
33
/*
34
			    VERSION INFORMATION
35
			    ===================
36
 
37
--------------------------------------------------------------------------
38
$Header: /u/g/release/CVSROOT/Source/src/installers/sparc/common/is_worth.c,v 1.1.1.1 1998/01/17 15:55:54 release Exp $
39
--------------------------------------------------------------------------
40
$Log: is_worth.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:55:54  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.2  1995/12/15  11:12:14  john
45
 * Change for 64 bit values
46
 *
47
 * Revision 1.1.1.1  1995/03/13  10:18:40  john
48
 * Entered into CVS
49
 *
50
 * Revision 1.4  1994/07/07  16:11:33  djch
51
 * Jul94 tape
52
 *
53
 * Revision 1.3  1994/06/22  09:50:43  djch
54
 * added check for val_tag to avoid derefing father if nil - jmf may not have
55
 * connected the bro field, and we read it to get operator name.
56
 *
57
 * Revision 1.2  1994/05/13  12:33:17  djch
58
 * Incorporates improvements from expt version
59
 * Added bracket to make structure clearer
60
 *
61
 * Revision 1.1  1994/05/03  14:49:39  djch
62
 * Initial revision
63
 *
64
 * Revision 1.5  94/02/21  16:11:11  16:11:11  ra (Robert Andrews)
65
 * is_worth now returns an int, not a bool.
66
 * 
67
 * Revision 1.4  93/11/19  16:29:18  16:29:18  ra (Robert Andrews)
68
 * Never remove constant multiplicand from loops - it introduces a call
69
 * when we could get away with shifts and adds.
70
 * 
71
 * Revision 1.3  93/08/27  11:29:07  11:29:07  ra (Robert Andrews)
72
 * Added a couple of explicit integer casts.
73
 * 
74
 * Revision 1.2  93/07/14  11:18:46  11:18:46  ra (Robert Andrews)
75
 * Reformatted.  Changed cont_tag case to deal with reff_0's (because
76
 * remove_zero_offsets is 0 they are not being removed by check).
77
 * 
78
 * Revision 1.1  93/06/24  14:58:31  14:58:31  ra (Robert Andrews)
79
 * Initial revision
80
 * 
81
--------------------------------------------------------------------------
82
*/
83
 
84
 
85
#define SPARCTRANS_CODE
86
#include "config.h"
87
#include "common_types.h"
88
#include "tags.h"
89
#include "expmacs.h"
90
#include "exp.h"
91
#include "shapemacs.h"
92
#include "sparcins.h"
93
#include "is_worth.h"
94
 
95
 
96
/*
97
    BOOLEAN VALUES
98
*/
99
 
100
#define true 1
101
#define false 0
102
 
103
 
104
/*
105
    IS THE EXPRESSION c WORTH EXTRACTING FROM A LOOP?
106
 
107
    This is called from mc_list.
108
*/
109
 
110
int is_worth 
111
    PROTO_N ( ( c ) )
112
    PROTO_T ( exp c )
113
{
114
    unsigned char cnam = name ( c ) ;
115
    bool isflt = ( bool ) is_floating ( name ( sh ( c ) ) ) ;
116
 
117
    if ( name ( sh ( c ) ) == ptrhd && al1 ( sh ( c ) ) == 1 ) {
118
	/* Pointers to bits aren't */
119
	return ( false ) ;
120
    }
121
 
122
    if ( cnam == real_tag ) {
123
	/* Real constants are */
124
	return ( true ) ;
125
    }
126
 
127
    if ( cnam == goto_tag ) {
128
	/* Extracting gotos messes things up */
129
	return ( false ) ;
130
    }
131
 
132
    if ( cnam == cont_tag ) {
133
	exp s = son ( c ) ;
134
	if ( isflt && ( name ( s ) != name_tag || isglob ( son ( s ) ) ) ) {
135
	    return ( true ) ;
136
	}
137
	if ( name ( s ) == reff_tag && no ( s ) == 0 ) s = son ( s ) ;
138
	if ( name ( s ) == name_tag && isglob ( son ( s ) ) ) {
139
	    return ( true ) ;
140
	}
141
	if ( name ( s ) == cont_tag ) {
142
	   exp ss = son ( s ) ;
143
	   if ( name ( ss ) == reff_tag && no ( ss ) == 0 ) ss = son ( ss ) ;
144
	   if ( name ( ss ) == name_tag ) return ( true ) ;
145
	}
146
	return ( false ) ;
147
    }
148
 
149
    if ( cnam == val_tag ) {
150
	/* It is sometimes worth extracting large integer constants */
151
	exp dad ;
152
	long n = no ( c ) ;
153
	if ( n == 0 ) return ( false ) ;
154
	if(name(sh(c)) == u64hd || name(sh(c)) == s64hd) return (false);
155
	dad = father ( c ) ;
156
 
157
	if (dad == nilexp)
158
	{
159
	  if ( SIMM13_SIZE ( n ) ) return ( false ) ;
160
	  return ( true ) ;
161
	}
162
 
163
	switch ( name ( dad ) ) {
164
 
165
	    case and_tag : {
166
		exp grandad = father ( dad ) ;
167
		if ( (name ( grandad ) == test_tag && ( n & ( n - 1 ) ) == 0
168
		     && ( props ( grandad ) == 5 || props ( grandad ) == 6 )
169
		     && ( name ( bro ( son ( grandad ) ) ) == val_tag
170
		     && no ( bro ( son ( grandad ) ) ) == 0 ))
171
		     || ( name ( son ( grandad ) ) == val_tag
172
		     && no ( son ( grandad ) ) == 0 ) ) {
173
			/* a & 2^n == 0 is transformed into a shift */
174
			return ( false ) ;
175
		}
176
		/* FALL THROUGH */
177
	    }
178
 
179
	    case or_tag :
180
	    case xor_tag :
181
	    case test_tag : {
182
		/* Large or negative constants are worth extracting */
183
		return ( ( int ) ( n < 0 || !SIMM13_SIZE ( n ) ) ) ;
184
	    }
185
 
186
	    case mult_tag :
187
	    case offset_mult_tag : {
188
#if 0
189
		/* Is this necessarily true? */
190
		if ( SIMM13_SIZE ( n ) ) return ( false ) ;
191
		return ( ( int ) ( ( n & ( n - 1 ) ) != 0 &&
192
				    ( n & ( n + 1 ) ) != 0 &&
193
				    ( ( n - 1 ) & ( n - 2 ) ) != 0 ) ) ;
194
#endif
195
		return ( false ) ;
196
	    }
197
 
198
	    case div1_tag :
199
	    case div2_tag :
200
	    case rem2_tag : {
201
#if 0
202
		/* Is this necessarily true? */
203
		if ( SIMM13_SIZE ( n ) ) return ( false ) ;
204
#endif
205
		return ( ( int ) ( ( n & ( n - 1 ) ) != 0 ) ) ; /* LINT */
206
	    }
207
 
208
	    default : {
209
		/* Extract large constants */
210
		if ( SIMM13_SIZE ( n ) ) return ( false ) ;
211
		return ( true ) ;
212
	    }
213
	}
214
    }
215
 
216
    if ( is_o ( cnam ) || cnam == clear_tag ) return ( false ) ;
217
    return ( true ) ;
218
}