Skip to content

Cannot bit shift vec of bool #53

@sjkelly

Description

@sjkelly

Julia scalar:

julia> typeof(true)
Bool

julia> true << 0x03
8

SIMD.jl:

julia> using SIMD

julia> Vec((true,true,false,true)) << Vec((0x01,0x02,0x03,0x04))
ERROR: InexactError: Bool(8)
Stacktrace:
 [1] Type at ./float.jl:73 [inlined]
 [2] llvmconst(::Int64, ::Type{Bool}, ::Int64) at /home/steve/.julia/dev/SIMD/src/SIMD.jl:277
 [3] #s17#41 at /home/steve/.julia/dev/SIMD/src/SIMD.jl:859 [inlined]
 [4] #s17#41(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) at ./none:0
 [5] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:524
 [6] <<(::Vec{4,Bool}, ::Vec{4,UInt8}) at /home/steve/.julia/dev/SIMD/src/SIMD.jl:1030
 [7] top-level scope at REPL[20]:1

I have tried this with all Int types and it does not seem to work. It does however work when converting, but this generates less than ideal code.

I am just starting to look at the code here and I do not know if this is related:

llvmtype(::Type{Bool}) = "i8" # Julia represents Tuple{Bool} as [1 x i8]

It seems that the shift operator calls this llvmconst where it is initialized as i1 rather than i8 where julia uses i8 for Bool.

SIMD.jl/src/SIMD.jl

Lines 266 to 270 in 1245797

function llvmconst(::Type{Bool}, val)
Bool(val) === false && return "zeroinitializer"
typ = "i1"
"$typ $(Int(val))"
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions