forked from SacBase/Stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayArith.xsac
More file actions
191 lines (152 loc) · 8.31 KB
/
ArrayArith.xsac
File metadata and controls
191 lines (152 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#pragma safe
module ArrayArith;
export all;
#include "builtin.mac"
#include "templates.mac"
/******************************************************************************
*
* Array-extensions for binary monary ops.
*
* Calls of these are created when using the macros provided in "templates.mac"
* such as MAP_ARI_OPS, MAP_INT_OPS, MAP_REL_OPS.
*
* NB: These could be defined in a way that they are applicable to all (not
* just built-in) types! All that would have to be done is using "sel" and "+"
* etc. instead of _sel_VxA_ and _add_SxS_. However, this is not done here for
* efficiency reasons. Using the more general version would cause inlining
* problems (->dkr).
*
******************************************************************************/
/******************************************************************************
*
* We now define the result shape of a dyadic scalar function as being the shape
* of the right (second) argument. The idea here is that in a composition such
* as X + (Y * Z), if the result shape of + is driven off the shape of (Y * Z),
* then we should nearly always be able to WLF the composition. If the result
* shape is driven off shape(X), then we need other semantic information to
* prove that the argument shapes match.
*
* This change made about a factor of two improvement in the performance of
* apex/ipbb/ipbb.sac and the Livermore Loop loop09.sac (the latter using the
* abstract vector-matrix multiply algorithm).
*
******************************************************************************/
#define MAP_BIN_AxA(name, op, a, b, adef, bdef) \
inline \
b[d>0:shp] name(a[d>0:shp] A, a[d>0:shp] B) \
{ \
return { iv -> op(_sel_VxA_(iv, A), _sel_VxA_(iv, B)) | iv < shp; \
iv -> bdef | iv < shp }; \
}
#define MAP_BIN_AxS(name, op, a, b, adef, bdef) \
inline \
b[d>0:shp] name(a[d>0:shp] A, a B) \
{ \
return { iv -> op(_sel_VxA_(iv, A), B) | iv < shp; \
iv -> bdef | iv < shp }; \
}
#define MAP_BIN_SxA(name, op, a, b, adef, bdef) \
inline \
b[d>0:shp] name(a A, a[d>0:shp] B) \
{ \
return { iv -> op(A, _sel_VxA_(iv, B)) | iv < shp; \
iv -> bdef | iv < shp }; \
}
/******************************************************************************/
#define MAP_BIN_INT_VxV(name, op) \
inline \
int[n] name(int[n] A, int[n] B) \
{ \
return _##op##_VxV_(A, B); \
}
#define MAP_BIN_INT_VxS(name, op) \
inline \
int[n] name(int[n] A, int B) \
{ \
return _##op##_VxS_(A, B); \
}
#define MAP_BIN_INT_SxV(name, op) \
inline \
int[n] name(int A, int[n] B) \
{ \
return _##op##_SxV_(A, B); \
}
/******************************************************************************
*
* Array-extensions for monadic ops.
*
******************************************************************************/
#define MAP_MON_AxA(name, op, a, b, adef, bdef) \
inline \
b[d>0:shp] name(a[d>0:shp] A) \
{ \
return { iv -> op(_sel_VxA_(iv, A)) | iv < shp; \
iv -> bdef | iv < shp }; \
}
#define MAP_MON_AxS(name, op, a, b, adef, bdef)
#define MAP_MON_SxA(name, op, a, b, adef, bdef)
/******************************************************************************
*
* AriOPS on arrays (see templates.mac for details).
*
******************************************************************************/
#define ARI_OPS_A(typ, _postfix, _fmt, _zval, _oval) \
MAP_ARI_OPS(AxA, typ, _zval) \
MAP_ARI_OPS(AxS, typ, _zval) \
MAP_ARI_OPS(SxA, typ, _zval)
NUM(ARI_OPS_A)
/******************************************************************************/
#define ABS_OP_A(type, _postfix, _fmt, _zval, _oval) \
MAP_ABS_OP(AxA, type, _zval) \
MAP_ABS_OP(AxS, type, _zval) \
MAP_ABS_OP(SxA, type, _zval)
#define ABS_NOOP_A(type, _postfix, _fmt, _zval, _oval) \
MAP_ABS_NOOP(AxA, type, _zval) \
MAP_ABS_NOOP(AxS, type, _zval) \
MAP_ABS_NOOP(SxA, type, _zval)
SIGNED_NUM(ABS_OP_A)
// abs is noop on unsigned numbers
UNSIGNED_INT_NUM(ABS_NOOP_A)
/******************************************************************************/
#define NEG_OP_A(typ, _postfix, _fmt, _zval, _oval) \
MAP_NEG_OP(AxA, typ, _zval) \
MAP_NEG_OP(AxS, typ, _zval) \
MAP_NEG_OP(SxA, typ, _zval)
SIGNED_NUM(NEG_OP_A)
/******************************************************************************/
#define INT_OPS_A(typ, _postfix, _fmt, _zval, _oval) \
MAP_INT_OPS(AxA, typ, _zval) \
MAP_INT_OPS(AxS, typ, _zval) \
MAP_INT_OPS(SxA, typ, _zval)
INT_NUM(INT_OPS_A)
/******************************************************************************
*
* RelOPS on arrays (see templates.mac for details).
*
******************************************************************************/
#define REL_OPS_A(typ, _postfix, _fmt, _zval, _oval) \
MAP_REL_OPS(AxA, typ, _zval) \
MAP_REL_OPS(AxS, typ, _zval) \
MAP_REL_OPS(SxA, typ, _zval)
BUILT_IN(REL_OPS_A)
/******************************************************************************
*
* LogOPS on scalars (see templates.mac for details).
*
******************************************************************************/
MAP_LOG_OPS(AxA)
MAP_LOG_OPS(AxS)
MAP_LOG_OPS(SxA)
/******************************************************************************
*
* ConvOPS on scalars (see templates.mac for details).
*
******************************************************************************/
#define BOOL_CONV_OP_A(typ, _postfix, _fmt, _zval, _oval) \
MAP_BOOL_CONV_OP(AxA, typ, _zval)
NUM(BOOL_CONV_OP_A)
BOOL(BOOL_CONV_OP_A)
/******************************************************************************/
#define NUM_CONV_OPS_A(typ, _postfix, _fmt, _zval, _oval) \
MAP_NUM_CONV_OPS(AxA, typ, _zval)
BUILT_IN(NUM_CONV_OPS_A)