@@ -11,42 +11,32 @@ function mulexprcost(@nospecialize(x::ProdArg))::Int
1111 return base + length (ex. args)
1212 end
1313end
14- function mul_fast_expr (args:: SubArray{Any, 1, Vector{Any}, Tuple{UnitRange{Int64}}, true} ):: Expr
14+ function mul_fast_expr (
15+ args:: SubArray{Any,1,Vector{Any},Tuple{UnitRange{Int64}},true}
16+ ):: Expr
1517 b = Expr (:call , :mul_fast )
1618 for i ∈ 2 : length (args)
1719 push! (b. args, args[i])
1820 end
1921 b
2022end
21- function mulexpr (mulexargs:: SubArray{Any, 1, Vector{Any}, Tuple{UnitRange{Int64}}, true} ):: Tuple{ProdArg,ProdArg}
23+ function mulexpr (
24+ mulexargs:: SubArray{Any,1,Vector{Any},Tuple{UnitRange{Int64}},true}
25+ ):: Tuple{ProdArg,ProdArg}
2226 a = (mulexargs[1 ]):: ProdArg
23- if length (mulexargs) == 2
24- return (a, mulexargs[2 ]:: ProdArg )
25- elseif length (mulexargs) == 3
26- # We'll calc the product between the guesstimated cheaper two args first, for better out of order execution
27- b = (mulexargs[2 ]):: ProdArg
28- c = (mulexargs[3 ]):: ProdArg
29- ac = mulexprcost (a)
30- bc = mulexprcost (b)
31- cc = mulexprcost (c)
32- maxc = max (ac, bc, cc)
33- if ac == maxc
34- return (a, Expr (:call , :mul_fast , b, c))
35- elseif bc == maxc
36- return (b, Expr (:call , :mul_fast , a, c))
37- else
38- return (c, Expr (:call , :mul_fast , a, b))
39- end
40- else
41- return (a, mul_fast_expr (mulexargs))
42- end
43- a = (mulexargs[1 ]):: Union{Symbol,Expr,Number}
44- b = if length (mulexargs) == 2 # two arg mul
45- (mulexargs[2 ]):: Union{Symbol,Expr,Number}
46- else
47- mul_fast_expr (mulexargs)
48- end
49- a, b
27+ Nexpr = length (mulexargs)
28+ Nexpr == 2 && (a, mulexargs[2 ]:: ProdArg )
29+ Nexpr != 3 && (a, mul_fast_expr (mulexargs))
30+ # We'll calc the product between the guesstimated cheaper two args first, for better out of order execution
31+ b = (mulexargs[2 ]):: ProdArg
32+ c = (mulexargs[3 ]):: ProdArg
33+ ac = mulexprcost (a)
34+ bc = mulexprcost (b)
35+ cc = mulexprcost (c)
36+ maxc = max (ac, bc, cc)
37+ ac == maxc && return (a, Expr (:call , :mul_fast , b, c))
38+ bc == maxc && return (b, Expr (:call , :mul_fast , c, a))
39+ return (c, Expr (:call , :mul_fast , a, b))
5040end
5141function append_args_skip! (call, args, i, mod)
5242 for j ∈ eachindex (args)
@@ -228,7 +218,8 @@ function capture_a_muladd(ex::Expr, mod)
228218 end
229219 true , call
230220end
231- capture_muladd (ex:: Expr , mod) = while true
221+ capture_muladd (ex:: Expr , mod) =
222+ while true
232223 ex. head === :ref && return ex
233224 if Meta. isexpr (ex, :call , 2 )
234225 if (ex. args[1 ] === :(- ))
0 commit comments