Skip to content

Commit c9194d3

Browse files
committed
support max/min for Mask
1 parent 29c4ade commit c9194d3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/llvm_intrin/masks.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,3 +1019,9 @@ end
10191019
b ? max_mask(Val(W)) : zero_mask(Val(W))
10201020
@inline vconvert(::Type{EVLMask{W}}, b::Bool) where {W} =
10211021
b ? max_mask(Val(W)) : zero_mask(Val(W))
1022+
1023+
@inline Base.max(x::AbstractMask, y::AbstractMask) = x | y
1024+
@inline Base.min(x::AbstractMask, y::AbstractMask) = x & y
1025+
@inline Base.FastMath.max_fast(x::AbstractMask, y::AbstractMask) = x | y
1026+
@inline Base.FastMath.min_fast(x::AbstractMask, y::AbstractMask) = x & y
1027+

test/runtests.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,10 +2062,14 @@ include("testsetup.jl")
20622062

20632063
@time @testset "vmax/vmin Bool" begin
20642064
t, f = Vec{4,Bool}(true, true, false, false), Vec{4,Bool}(true, false, true, false)
2065-
@test VectorizationBase.vmax_fast(t, f) === Vec{4,Bool}(true, true, true, false)
2066-
@test VectorizationBase.vmin_fast(t, f) === Vec{4,Bool}(true, false, false, false)
2067-
@test VectorizationBase.vmax(t, f) === Vec{4,Bool}(true, true, true, false)
2068-
@test VectorizationBase.vmin(t, f) === Vec{4,Bool}(true, false, false, false)
2065+
@test VectorizationBase.vmax_fast(t, f) === @fastmath(max(t, f)) === Vec{4,Bool}(true, true, true, false)
2066+
@test VectorizationBase.vmin_fast(t, f) === @fastmath(min(t, f)) ===Vec{4,Bool}(true, false, false, false)
2067+
@test VectorizationBase.vmax(t, f) === max(t, f) === Vec{4,Bool}(true, true, true, false)
2068+
@test VectorizationBase.vmin(t, f) === min(t, f) === Vec{4,Bool}(true, false, false, false)
2069+
2070+
tm = Mask{4}(0xc); fm = Mask{4}(0xa)
2071+
@test @fastmath(max(tm, fm)) === max(tm, fm) === Mask{4}(0xe)
2072+
@test @fastmath(min(tm, fm)) === min(tm, fm) === Mask{4}(0x8)
20692073
end
20702074

20712075
@time @testset "Generic strided pointer" begin

0 commit comments

Comments
 (0)