|
1 | 1 |
|
2 |
| -mulexprcost(::Number) = 0 |
3 |
| -mulexprcost(::Symbol) = 1 |
4 |
| -function mulexprcost(ex::Expr) |
5 |
| - base = ex.head === :call ? 10 : 1 |
6 |
| - base + length(ex.args) |
| 2 | +const ProdArg = Union{Symbol,Expr,Number} |
| 3 | +function mulexprcost(@nospecialize(x::ProdArg))::Int |
| 4 | + if x isa Number |
| 5 | + return 0 |
| 6 | + elseif x isa Symbol |
| 7 | + return 1 |
| 8 | + else |
| 9 | + ex = x::Expr |
| 10 | + base = ex.head === :call ? 10 : 1 |
| 11 | + return base + length(ex.args) |
| 12 | + end |
7 | 13 | end
|
8 |
| -function mul_fast_expr(args) |
| 14 | +function mul_fast_expr(args::SubArray{Any, 1, Vector{Any}, Tuple{UnitRange{Int64}}, true})::Expr |
9 | 15 | b = Expr(:call, :mul_fast)
|
10 | 16 | for i ∈ 2:length(args)
|
11 | 17 | push!(b.args, args[i])
|
12 | 18 | end
|
13 | 19 | b
|
14 | 20 | end
|
15 |
| -function mulexpr(mulexargs) |
16 |
| - a = (mulexargs[1])::Union{Symbol,Expr,Number} |
| 21 | +function mulexpr(mulexargs::SubArray{Any, 1, Vector{Any}, Tuple{UnitRange{Int64}}, true})::Tuple{ProdArg,ProdArg} |
| 22 | + a = (mulexargs[1])::ProdArg |
17 | 23 | if length(mulexargs) == 2
|
18 |
| - return (a, mulexargs[2]::Union{Symbol,Expr,Number}) |
| 24 | + return (a, mulexargs[2]::ProdArg) |
19 | 25 | elseif length(mulexargs) == 3
|
20 | 26 | # We'll calc the product between the guesstimated cheaper two args first, for better out of order execution
|
21 |
| - b = (mulexargs[2])::Union{Symbol,Expr,Number} |
22 |
| - c = (mulexargs[3])::Union{Symbol,Expr,Number} |
| 27 | + b = (mulexargs[2])::ProdArg |
| 28 | + c = (mulexargs[3])::ProdArg |
23 | 29 | ac = mulexprcost(a)
|
24 | 30 | bc = mulexprcost(b)
|
25 | 31 | cc = mulexprcost(c)
|
|
0 commit comments