Skip to content

Commit

Permalink
Merge pull request #137 from eschnett/eschnett/bswap
Browse files Browse the repository at this point in the history
Correct bswap for 1-byte types
  • Loading branch information
eschnett authored Jan 8, 2025
2 parents 53c9476 + 1e61e85 commit 2196b14
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ jobs:
include:
- arch: "x64"
os: "ubuntu-latest"
version: "1.10"
version: "1.11"
- arch: "x64"
os: "windows-latest"
version: "1.10"
version: "1.11"
- arch: "x64"
os: "macOS-latest"
version: "1.10"
version: "1.11"
- arch: "x86"
os: "ubuntu-latest"
version: "1.11"
- arch: "x64"
os: "ubuntu-latest"
version: "1.10"
- arch: "x64"
Expand Down Expand Up @@ -59,7 +62,7 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: 82aae245-ad5c-41ac-9e30-b64617ce25b0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_julia_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: 82aae245-ad5c-41ac-9e30-b64617ce25b0
with:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SIMD"
uuid = "fdea26ae-647d-5447-a871-4b548cad5224"
authors = ["Erik Schnetter <[email protected]>", "Kristoffer Carlsson <[email protected]>"]
version = "3.7.0"
version = "3.7.1"

[deps]
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Expand Down
4 changes: 4 additions & 0 deletions src/simdvec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ for (op, constraint, llvmop) in UNARY_OPS
Vec($(llvmop)(x.data))
end

# Fix up bswap (see <https://github.com/eschnett/SIMD.jl/issues/122>):
# bswap for 1-byte types is a no-op
Base.bswap(x::Vec{<:Any, <:Union{Int8,UInt8}}) = x

Base.:+(v::Vec{<:Any, <:ScalarTypes}) = v
Base.:-(v::Vec{<:Any, <:IntegerTypes}) = zero(v) - v
Base.:-(v::Vec{<:Any, <:FloatingTypes}) = Vec(Intrinsics.fneg(v.data))
Expand Down
11 changes: 10 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ llvm_ir(f, args) = sprint(code_llvm, f, Base.typesof(args...))

notbool(x) = !(x>=typeof(x)(0))
for op in (~, +, -, abs, abs2, notbool, sign, signbit, count_ones, count_zeros,
leading_ones, leading_zeros, conj, real, imag, trailing_ones, trailing_zeros)
leading_ones, leading_zeros, conj, real, imag, trailing_ones, trailing_zeros,
bswap)
@test Tuple(op(V8I32(v8i32))) == map(op, v8i32)
end

Expand Down Expand Up @@ -142,6 +143,14 @@ llvm_ir(f, args) = sprint(code_llvm, f, Base.typesof(args...))
@test Tuple(V8I32(v8i32)^3) === v8i32.^3
end

@testset "bswap" begin
for sz in [1, 2, 4, 8, 16, 32]
VszI8 = Vec{sz,Int8}
vszi8 = ntuple(i->Int8(ifelse(isodd(i), i, -i)), sz)
@test Tuple(bswap(VszI8(vszi8))) == map(bswap, vszi8)
end
end

@testset "saturation" begin
v = Vec{4, UInt8}(UInt8.((150, 250, 125, 0)))
@test SIMD.add_saturate(v, UInt8(50)) === Vec{4, UInt8}(UInt8.((200, 255, 175, 50)))
Expand Down

0 comments on commit 2196b14

Please sign in to comment.