Skip to content

Commit

Permalink
Merge pull request #41 from tkf/literal_pow
Browse files Browse the repository at this point in the history
Implement literal_pow for Vec
  • Loading branch information
eschnett authored Jan 7, 2019
2 parents 89ca5b4 + c6b0f84 commit bb5adc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/SIMD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,12 @@ end
@inline Base.flipsign(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:FloatingTypes} =
vifelse(signbit(v2), -v1, v1)

# Do what Base does for HWNumber:
@inline Base.literal_pow(::typeof(^), x::Vec, ::Val{0}) = one(typeof(x))
@inline Base.literal_pow(::typeof(^), x::Vec, ::Val{1}) = x
@inline Base.literal_pow(::typeof(^), x::Vec, ::Val{2}) = x*x
@inline Base.literal_pow(::typeof(^), x::Vec, ::Val{3}) = x*x*x

for op in (:fma, :muladd)
@eval begin
@inline function Base.$op(v1::Vec{N,T},
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ llvm_ir(f, args) = sprint(code_llvm, f, Base.typesof(args...))
@test Tuple(op(V8I32(v8i32), -3)) === map(x->op(x,-3), v8i32)
@test Tuple(op(V8I32(v8i32), V8I32(v8i32))) === map(op, v8i32, v8i32)
end

@test Tuple(V8I32(v8i32)^0) === v8i32.^0
@test Tuple(V8I32(v8i32)^1) === v8i32.^1
@test Tuple(V8I32(v8i32)^2) === v8i32.^2
@test Tuple(V8I32(v8i32)^3) === v8i32.^3
end

@testset "Floating point arithmetic functions" begin
Expand Down Expand Up @@ -207,6 +212,11 @@ llvm_ir(f, args) = sprint(code_llvm, f, Base.typesof(args...))
@test Tuple(op(V4F64(v4f64), V4F64(v4f64b))) === map(op, v4f64, v4f64b)
end

@test Tuple(V4F64(v4f64)^0) === v4f64.^0
@test Tuple(V4F64(v4f64)^1) === v4f64.^1
@test Tuple(V4F64(v4f64)^2) === v4f64.^2
@test Tuple(V4F64(v4f64)^3) === v4f64.^3

for op in (fma, vifelsebool, muladd)
@test Tuple(op(V4F64(v4f64), V4F64(v4f64b), V4F64(v4f64c))) ===
map(op, v4f64, v4f64b, v4f64c)
Expand Down

0 comments on commit bb5adc9

Please sign in to comment.