Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize for LLVM 17 #11

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/FindFirstFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,37 @@
Note that this differs from `searchsortedfirst` by returning `nothing` when absent.
"""
function findfirstsortedequal(var::Int64, vars::DenseVector{Int64},
::Val{basecase}=Val(128)) where {basecase}
::Val{basecase}=Base.libllvm_version >= v"17" ? Val(8) : Val(128)) where {basecase}
len = length(vars)
offset = 0
@inbounds while len > basecase
half = len >>> 1 # half on left, len - half on right
offset = ifelse(vars[offset+half+1] <= var, half + offset, offset)
if Base.libllvm_version >= v"17"

Check warning on line 91 in src/FindFirstFunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/FindFirstFunctions.jl#L91

Added line #L91 was not covered by tests
# TODO: check if this works
# I'm worried the `!unpredictable` metadata will be stripped
offset = Base.llvmcall(("""

Check warning on line 94 in src/FindFirstFunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/FindFirstFunctions.jl#L94

Added line #L94 was not covered by tests
define i64 @entry(i8 %0, i64 %1, i64 %2) #0 {
top:
%b = trunc i8 %0 to i1
%s = select i1 %b, i64 %1, i64 %2, !unpredictable !0
ret i64 %s
}
attributes #0 = { alwaysinline }
!0 = !{}
""", "entry"), Int64, Tuple{Bool,Int64,Int64}, vars[offset+half+1] <= var, half + offset, offset)
else
offset = ifelse(vars[offset+half+1] <= var, half + offset, offset)

Check warning on line 105 in src/FindFirstFunctions.jl

View check run for this annotation

Codecov / codecov/patch

src/FindFirstFunctions.jl#L105

Added line #L105 was not covered by tests
end
len = len - half
end
# maybe occurs in vars[offset+1:offset+len]
GC.@preserve vars begin
ret = _findfirstequal(var, pointer(vars) + 8offset, len)
end
# return ret
ret < 0 ? nothing : ret + offset + 1
end


"""
bracketstrictlymontonic(v, x, guess; lt=<comparison>, by=<transform>, rev=false)

Expand Down
Loading