Skip to content

Commit fc0b45a

Browse files
committed
test broadcasted integer division
1 parent 8bcbf99 commit fc0b45a

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LoopVectorization"
22
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
33
authors = ["Chris Elrod <[email protected]>"]
4-
version = "0.12.62"
4+
version = "0.12.63"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/broadcast.jl

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,9 @@ end
408408
storeop = add_simple_store!(ls, :destination, ArrayReference(:dest, loopsyms), elementbytes)
409409
doaddref!(ls, storeop)
410410
resize!(ls.loop_order, num_loops(ls)) # num_loops may be greater than N, eg Product
411-
# return ls
412411
sc = setup_call(ls, :(Base.Broadcast.materialize!(dest, bc)), LineNumberNode(0), inline, false, u₁, u₂, v, threads%Int, warncheckarg)
413-
# return sc
414412
Expr(:block, Expr(:meta,:inline), sc, :dest)
413+
# setup_call_debug(ls)
415414
end
416415
@generated function vmaterialize!(
417416
dest′::Union{Adjoint{T,A},Transpose{T,A}}, bc::BC, ::Val{Mod}, ::Val{UNROLL}
@@ -434,31 +433,31 @@ end
434433
end
435434
# these are marked `@inline` so the `@turbo` itself can choose whether or not to inline.
436435
@generated function vmaterialize!(
437-
dest::AbstractArray{T,N}, bc::Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(identity),Tuple{T2}}, ::Val{Mod}, ::Val{UNROLL}
438-
) where {T <: NativeTypes, N, T2 <: Number, Mod, UNROLL}
436+
dest::AbstractArray{T,N}, bc::Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(identity),Tuple{T2}}, ::Val{Mod}, ::Val{UNROLL}
437+
) where {T <: NativeTypes, N, T2 <: Number, Mod, UNROLL}
439438
inline, u₁, u₂, v, isbroadcast, W, rs, rc, cls, l1, l2, l3, threads = UNROLL
440-
quote
441-
$(Expr(:meta,:inline))
442-
arg = T(first(bc.args))
443-
@turbo inline=$inline unroll=($u₁,$u₂) thread=$threads vectorize=$v for i eachindex(dest)
444-
dest[i] = arg
445-
end
446-
dest
439+
quote
440+
$(Expr(:meta,:inline))
441+
arg = T(first(bc.args))
442+
@turbo inline=$inline unroll=($u₁,$u₂) thread=$threads vectorize=$v for i eachindex(dest)
443+
dest[i] = arg
447444
end
445+
dest
446+
end
448447
end
449448
@generated function vmaterialize!(
450-
dest′::Union{Adjoint{T,A},Transpose{T,A}}, bc::Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(identity),Tuple{T2}}, ::Val{Mod}, ::Val{UNROLL}
451-
) where {T <: NativeTypes, N, A <: AbstractArray{T,N}, T2 <: Number, Mod, UNROLL}
452-
inline, u₁, u₂, v, isbroadcast, W, rs, rc, cls, l1, l2, l3, threads = UNROLL
453-
quote
454-
$(Expr(:meta,:inline))
455-
arg = T(first(bc.args))
456-
dest = parent(dest′)
457-
@turbo inline=$inline unroll=($u₁,$u₂) thread=$threads vectorize=$v for i eachindex(dest)
458-
dest[i] = arg
459-
end
460-
dest′
449+
dest′::Union{Adjoint{T,A},Transpose{T,A}}, bc::Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(identity),Tuple{T2}}, ::Val{Mod}, ::Val{UNROLL}
450+
) where {T <: NativeTypes, N, A <: AbstractArray{T,N}, T2 <: Number, Mod, UNROLL}
451+
inline, u₁, u₂, v, isbroadcast, W, rs, rc, cls, l1, l2, l3, threads = UNROLL
452+
quote
453+
$(Expr(:meta,:inline))
454+
arg = T(first(bc.args))
455+
dest = parent(dest′)
456+
@turbo inline=$inline unroll=($u₁,$u₂) thread=$threads vectorize=$v for i eachindex(dest)
457+
dest[i] = arg
461458
end
459+
dest′
460+
end
462461
end
463462

464463
@inline function vmaterialize(

src/modeling/costs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ const FUNCTIONSYMBOLS = IdDict{Type{<:Function},Instruction}(
595595
typeof(Base.ifelse) => :ifelse,
596596
typeof(ifelse) => :ifelse,
597597
typeof(identity) => :identity,
598-
typeof(conj) => :identity#conj
598+
typeof(conj) => :identity,#conj,
599+
typeof(÷) => :div_fast
599600
# typeof(zero) => :zero,
600601
# typeof(one) => :one,
601602
# typeof(axes) => :axes,

test/broadcast.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ function test_broadcast(::Type{T}) where {T}
130130
@test D1 D2
131131
D2 = @outline @turbo @. C + A *ˡ (b + x');
132132
@test D1 D2
133+
if T === Int64
134+
xd = rand(-1_000_000_000_000:1_000_000_000_000,89);
135+
elseif T === Int32
136+
xd = rand(-Int32(10_000_000):Int32(10_000_000),89);
137+
else
138+
xd = rand(R,89);
139+
end;
140+
yd = rand(R,89);
141+
yd[yd .== 0] .= 77;
142+
@test xd yd == @turbo xd yd
133143

134144
if T <: Union{Float32,Float64}
135145
D3 = cos.(B');

0 commit comments

Comments
 (0)