@@ -156,108 +156,58 @@ const COST = Dict{Instruction,InstructionCost}(
156
156
# COST[Symbol("typeof(", lower(k), ")")] = v
157
157
# end
158
158
159
- const CORRESPONDING_REDUCTION = Dict {Instruction,Instruction} (
160
- Instruction (:+ ) => Instruction (:vsum ),
161
- Instruction (:- ) => Instruction (:vsum ),
162
- Instruction (:* ) => Instruction (:vprod ),
163
- Instruction (:vadd ) => Instruction (:vsum ),
164
- Instruction (:vsub ) => Instruction (:vsum ),
165
- Instruction (:vmul ) => Instruction (:vprod ),
166
- Instruction (:evadd ) => Instruction (:vsum ),
167
- Instruction (:evsub ) => Instruction (:vsum ),
168
- Instruction (:evmul ) => Instruction (:vprod ),
169
- Instruction (:& ) => Instruction (:vall ),
170
- Instruction (:| ) => Instruction (:vany ),
171
- Instruction (:muladd ) => Instruction (:vsum ),
172
- Instruction (:fma ) => Instruction (:vsum ),
173
- Instruction (:vmuladd ) => Instruction (:vsum ),
174
- Instruction (:vfma ) => Instruction (:vsum ),
175
- Instruction (:vfmadd ) => Instruction (:vsum ),
176
- Instruction (:vfmsub ) => Instruction (:vsum ),
177
- Instruction (:vfnmadd ) => Instruction (:vsum ),
178
- Instruction (:vfnmsub ) => Instruction (:vsum ),
179
- Instruction (:vfmadd_fast ) => Instruction (:vsum ),
180
- Instruction (:vfmsub_fast ) => Instruction (:vsum ),
181
- Instruction (:vfnmadd_fast ) => Instruction (:vsum ),
182
- Instruction (:vfnmsub_fast ) => Instruction (:vsum )
183
- )
184
- const REDUCTION_TRANSLATION = Dict {Instruction,Instruction} (
185
- Instruction (:+ ) => Instruction (:evadd ),
186
- Instruction (:vadd ) => Instruction (:evadd ),
187
- Instruction (:* ) => Instruction (:evmul ),
188
- Instruction (:vmul ) => Instruction (:evmul ),
189
- Instruction (:- ) => Instruction (:evadd ),
190
- Instruction (:vsub ) => Instruction (:evadd ),
191
- Instruction (:/ ) => Instruction (:evmul ),
192
- Instruction (:vfdiv ) => Instruction (:evmul ),
193
- Instruction (:muladd ) => Instruction (:evadd ),
194
- Instruction (:fma ) => Instruction (:evadd ),
195
- Instruction (:vmuladd ) => Instruction (:evadd ),
196
- Instruction (:vfma ) => Instruction (:evadd ),
197
- Instruction (:vfmadd ) => Instruction (:evadd ),
198
- Instruction (:vfmsub ) => Instruction (:evadd ),
199
- Instruction (:vfnmadd ) => Instruction (:evadd ),
200
- Instruction (:vfnmsub ) => Instruction (:evadd ),
201
- Instruction (:vfmadd_fast ) => Instruction (:evadd ),
202
- Instruction (:vfmsub_fast ) => Instruction (:evadd ),
203
- Instruction (:vfnmadd_fast ) => Instruction (:evadd ),
204
- Instruction (:vfnmsub_fast ) => Instruction (:evadd )
205
- )
206
- const REDUCTION_ZERO = Dict {Instruction,Symbol} (
207
- Instruction (:+ ) => :zero ,
208
- Instruction (:vadd ) => :zero ,
209
- Instruction (:evadd ) => :zero ,
210
- Instruction (:* ) => :one ,
211
- Instruction (:vmul ) => :one ,
212
- Instruction (:evmul ) => :one ,
213
- Instruction (:- ) => :zero ,
214
- Instruction (:vsub ) => :zero ,
215
- Instruction (:evsub ) => :zero ,
216
- Instruction (:/ ) => :one ,
217
- Instruction (:vfdiv ) => :one ,
218
- Instruction (:evfdiv ) => :one ,
219
- Instruction (:muladd ) => :zero ,
220
- Instruction (:fma ) => :zero ,
221
- Instruction (:vmuladd ) => :zero ,
222
- Instruction (:vfma ) => :zero ,
223
- Instruction (:vfmadd ) => :zero ,
224
- Instruction (:vfmsub ) => :zero ,
225
- Instruction (:vfnmadd ) => :zero ,
226
- Instruction (:vfnmsub ) => :zero ,
227
- Instruction (:vfmadd_fast ) => :zero ,
228
- Instruction (:vfmsub_fast ) => :zero ,
229
- Instruction (:vfnmadd_fast ) => :zero ,
230
- Instruction (:vfnmsub_fast ) => :zero
231
- )
159
+ const ADDITIVE_IN_REDUCTIONS = 1.0
160
+ const MULTIPLICATIVE_IN_REDUCTIONS = 2.0
161
+ const ANY = 3.0
162
+ const ALL = 4.0
232
163
233
- const LVGETPROP = @static VERSION < v " 1.3" ? Expr : GlobalRef
234
- # Fast functions, because common pattern is
235
- const REDUCTION_SCALAR_COMBINE = Dict {Instruction,LVGETPROP} (
236
- Instruction (:+ ) => lv (:reduced_add ),
237
- Instruction (:vadd ) => lv (:reduced_add ),
238
- Instruction (:* ) => lv (:reduced_prod ),
239
- Instruction (:vmul ) => lv (:reduced_prod ),
240
- Instruction (:- ) => lv (:reduced_add ),
241
- Instruction (:vsub ) => lv (:reduced_add ),
242
- Instruction (:/ ) => lv (:reduced_prod ),
243
- Instruction (:vfdiv ) => lv (:reduced_prod ),
244
- Instruction (:muladd ) => lv (:reduced_add ),
245
- Instruction (:fma ) => lv (:reduced_add ),
246
- Instruction (:vmuladd ) => lv (:reduced_add ),
247
- Instruction (:vfma ) => lv (:reduced_add ),
248
- Instruction (:vfmadd ) => lv (:reduced_add ),
249
- Instruction (:vfmsub ) => lv (:reduced_add ),
250
- Instruction (:vfnmadd ) => lv (:reduced_add ),
251
- Instruction (:vfnmsub ) => lv (:reduced_add ),
252
- Instruction (:vfmadd_fast ) => lv (:reduced_add ),
253
- Instruction (:vfmsub_fast ) => lv (:reduced_add ),
254
- Instruction (:vfnmadd_fast ) => lv (:reduced_add ),
255
- Instruction (:vfnmsub_fast ) => lv (:reduced_add )
256
- )
257
- const REDUCTION_COMBINETO = Dict {Symbol,Symbol} (
258
- :reduced_add => :reduce_to_add ,
259
- :reduced_prod => :reduce_to_prod
164
+ const REDUCTION_CLASS = Dict {Instruction,Float64} (
165
+ Instruction (:+ ) => ADDITIVE_IN_REDUCTIONS,
166
+ Instruction (:- ) => ADDITIVE_IN_REDUCTIONS,
167
+ Instruction (:* ) => MULTIPLICATIVE_IN_REDUCTIONS,
168
+ Instruction (:vadd ) => ADDITIVE_IN_REDUCTIONS,
169
+ Instruction (:vsub ) => ADDITIVE_IN_REDUCTIONS,
170
+ Instruction (:vmul ) => MULTIPLICATIVE_IN_REDUCTIONS,
171
+ Instruction (:evadd ) => ADDITIVE_IN_REDUCTIONS,
172
+ Instruction (:evsub ) => ADDITIVE_IN_REDUCTIONS,
173
+ Instruction (:evmul ) => MULTIPLICATIVE_IN_REDUCTIONS,
174
+ Instruction (:& ) => ALL,
175
+ Instruction (:| ) => ANY,
176
+ Instruction (:muladd ) => ADDITIVE_IN_REDUCTIONS,
177
+ Instruction (:fma ) => ADDITIVE_IN_REDUCTIONS,
178
+ Instruction (:vmuladd ) => ADDITIVE_IN_REDUCTIONS,
179
+ Instruction (:vfma ) => ADDITIVE_IN_REDUCTIONS,
180
+ Instruction (:vfmadd ) => ADDITIVE_IN_REDUCTIONS,
181
+ Instruction (:vfmsub ) => ADDITIVE_IN_REDUCTIONS,
182
+ Instruction (:vfnmadd ) => ADDITIVE_IN_REDUCTIONS,
183
+ Instruction (:vfnmsub ) => ADDITIVE_IN_REDUCTIONS,
184
+ Instruction (:vfmadd_fast ) => ADDITIVE_IN_REDUCTIONS,
185
+ Instruction (:vfmsub_fast ) => ADDITIVE_IN_REDUCTIONS,
186
+ Instruction (:vfnmadd_fast ) => ADDITIVE_IN_REDUCTIONS,
187
+ Instruction (:vfnmsub_fast ) => ADDITIVE_IN_REDUCTIONS
260
188
)
189
+ reduction_instruction_class (instr:: Symbol ) = get (REDUCTION_CLASS, Instruction (instr), NaN )
190
+ reduction_instruction_class (instr:: Instruction ) = get (REDUCTION_CLASS, instr, NaN )
191
+ function reduction_to_single_vector (x:: Float64 )
192
+ x == 1.0 ? :evadd : x == 2.0 ? :evmul : x == 3.0 ? :vand : x == 4.0 ? :vor : throw (" Reduction not found." )
193
+ end
194
+ reduction_to_single_vector (x) = reduction_to_single_vector (reduction_instruction_class (x))
195
+ function reduction_to_scalar (x:: Float64 )
196
+ x == 1.0 ? :vsum : x == 2.0 ? :vprod : x == 3.0 ? :vany : x == 4.0 ? :vall : throw (" Reduction not found." )
197
+ end
198
+ reduction_to_scalar (x) = reduction_to_scalar (reduction_instruction_class (x))
199
+ function reduction_scalar_combine (x:: Float64 )
200
+ x == 1.0 ? :reduced_add : x == 2.0 ? :reduced_prod : x == 3.0 ? :reduced_any : x == 4.0 ? :reduced_all : throw (" Reduction not found." )
201
+ end
202
+ reduction_scalar_combine (x) = reduction_scalar_combine (reduction_instruction_class (x))
203
+ function reduction_combine_to (x:: Float64 )
204
+ x == 1.0 ? :reduce_to_add : x == 2.0 ? :reduce_to_prod : x == 3.0 ? :reduce_to_any : x == 4.0 ? :reduce_to_all : throw (" Reduction not found." )
205
+ end
206
+ reduction_combine_to (x) = reduction_combine_to (reduction_instruction_class (x))
207
+ function reduction_zero (x:: Float64 )
208
+ x == 1.0 ? :zero : x == 2.0 ? :one : x == 3.0 ? :false : x == 4.0 ? :true : throw (" Reduction not found." )
209
+ end
210
+ reduction_zero (x) = reduction_zero (reduction_instruction_class (x))
261
211
262
212
const FUNCTIONSYMBOLS = Dict {Type{<:Function},Instruction} (
263
213
typeof (+ ) => :(+ ),
0 commit comments