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

Support isless for CartesianIndex #16054

Merged
merged 1 commit into from
Apr 26, 2016
Merged

Support isless for CartesianIndex #16054

merged 1 commit into from
Apr 26, 2016

Conversation

timholy
Copy link
Member

@timholy timholy commented Apr 26, 2016

isless(I1, I2) returns true if I1 would be visited before I2 during CartesianRange iteration.

julia> isless(CartesianIndex((5,4)), CartesianIndex((3,7)))
true

Also nicely efficient:

julia> @code_llvm isless(CartesianIndex((5,4)), CartesianIndex((3,7)))

define i1 @julia_isless_53462(%CartesianIndex*, %CartesianIndex*) #0 {
top:
  %2 = getelementptr inbounds %CartesianIndex, %CartesianIndex* %0, i64 0, i32 0, i64 1
  %3 = getelementptr inbounds %CartesianIndex, %CartesianIndex* %1, i64 0, i32 0, i64 1
  %4 = load i64, i64* %2, align 8
  %5 = load i64, i64* %3, align 8
  %6 = icmp sge i64 %4, %5
  %7 = icmp ne i64 %4, %5
  %8 = sext i1 %7 to i64
  %9 = select i1 %6, i64 %8, i64 1
  %10 = getelementptr inbounds %CartesianIndex, %CartesianIndex* %0, i64 0, i32 0, i64 0
  %11 = getelementptr inbounds %CartesianIndex, %CartesianIndex* %1, i64 0, i32 0, i64 0
  %12 = icmp ne i64 %9, 0
  %13 = load i64, i64* %10, align 8
  %14 = load i64, i64* %11, align 8
  %15 = icmp sge i64 %13, %14
  %16 = icmp ne i64 %13, %14
  %17 = sext i1 %16 to i64
  %18 = select i1 %15, i64 %17, i64 1
  %19 = select i1 %12, i64 %9, i64 %18
  %not. = icmp eq i64 %19, 1
  ret i1 %not.
}

@timholy timholy merged commit 893f7e3 into master Apr 26, 2016
@timholy timholy deleted the teh/cartindx_order branch April 26, 2016 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant