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

Make ptr range iterable #91000

Closed
wants to merge 7 commits into from
Closed

Make ptr range iterable #91000

wants to merge 7 commits into from

Commits on Nov 18, 2021

  1. Make ptr range iterable

    dtolnay committed Nov 18, 2021
    Configuration menu
    Copy the full SHA
    88150bd View commit details
    Browse the repository at this point in the history
  2. More ptr range test cases

    dtolnay committed Nov 18, 2021
    Configuration menu
    Copy the full SHA
    7ac5ca3 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    1f15e73 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    f6db190 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    47c8646 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    4cb6151 View commit details
    Browse the repository at this point in the history
  7. Produce better machine code for a loop over ptr range

    Test code:
    
        extern "C" {
            fn foreign(ptr: *const i32);
        }
    
        pub fn forloop(start: *const i32, end: *const i32) {
            for ptr in start..end {
                unsafe { foreign(ptr) }
            }
        }
    
    Before:
    
        asm::forloop:
          push    r15
          push    r14
          push    rbx
          cmp     rdi, rsi
          jae     .LBB0_3
          mov     r15, rsi
          mov     r14, qword, ptr, [rip, +, foreign@GOTPCREL]
        .LBB0_2:
          lea     rax, [rdi, +, 4]
          cmp     rax, r15
          mov     rbx, r15
          cmovb   rbx, rax
          cmp     rdi, rax
          cmova   rbx, r15
          call    r14
          mov     rdi, rbx
          cmp     rbx, r15
          jb      .LBB0_2
        .LBB0_3:
          pop     rbx
          pop     r14
          pop     r15
          ret
    
    After:
    
        asm::forloop:
          push    r15
          push    r14
          push    rbx
          cmp     rdi, rsi
          jae     .LBB0_3
          mov     r15, rsi
          mov     r14, qword, ptr, [rip, +, foreign@GOTPCREL]
        .LBB0_2:
          mov     rax, r15
          sub     rax, rdi
          lea     rbx, [rdi, +, 4]
          cmp     rax, 4
          cmovb   rbx, r15
          call    r14
          mov     rdi, rbx
          cmp     rbx, r15
          jb      .LBB0_2
        .LBB0_3:
          pop     rbx
          pop     r14
          pop     r15
          ret
    dtolnay committed Nov 18, 2021
    Configuration menu
    Copy the full SHA
    81d29d4 View commit details
    Browse the repository at this point in the history