Skip to content

Improve isAlphaNum#8588

Merged
dlang-bot merged 1 commit intodlang:masterfrom
deadalnix:isalphanum
Oct 12, 2022
Merged

Improve isAlphaNum#8588
dlang-bot merged 1 commit intodlang:masterfrom
deadalnix:isalphanum

Conversation

@deadalnix
Copy link
Contributor

Using recent version of LDC, here are the codegen I get:

        lea     eax, [rdi - 48]
        cmp     eax, 74
        ja      .LBB2_1
        lea     ecx, [rdi - 97]
        mov     al, 1
        cmp     ecx, -39
        jb      .LBB2_4
        add     edi, -65
        cmp     edi, 26
        setb    al
.LBB2_4:
        ret
.LBB2_1:
        xor     eax, eax
        ret

And now:

        lea     eax, [rdi - 48]
        cmp     eax, 9
        setb    cl
        or      edi, 32
        add     edi, -97
        cmp     edi, 26
        setb    al
        or      al, cl
        ret

Which is much better all around: less instructions, no branches, etc...

I will note that doing isDigit(c) || isAlpha(c) also gives me good codegen using LDC, but I chose against it as DMD fails to inline properly and the end result is pretty bad.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @deadalnix! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#8588"

@deadalnix
Copy link
Contributor Author

What is required to unblock this?

@thewilsonator
Copy link
Contributor

What is required to unblock this?

Try rebasing.

@deadalnix
Copy link
Contributor Author

@thewilsonator this is on top of master already.

@thewilsonator
Copy link
Contributor

then just force-push to restart the CIs

Using recent version of LDC, here are the codegen I get:
```
        lea     eax, [rdi - 48]
        cmp     eax, 74
        ja      .LBB2_1
        lea     ecx, [rdi - 97]
        mov     al, 1
        cmp     ecx, -39
        jb      .LBB2_4
        add     edi, -65
        cmp     edi, 26
        setb    al
.LBB2_4:
        ret
.LBB2_1:
        xor     eax, eax
        ret
```

And now:
```
        lea     eax, [rdi - 48]
        cmp     eax, 9
        setb    cl
        or      edi, 32
        add     edi, -97
        cmp     edi, 26
        setb    al
        or      al, cl
        ret
```

Which is much better all around: less instructions, no branches, etc...

I will note that doing `isDigit(c) || isAlpha(c)` also gives me good codegen using LDC, but I chose against it as DMD fails to inline properly and the end result is pretty bad.
@dlang-bot dlang-bot merged commit ab74cf6 into dlang:master Oct 12, 2022
@deadalnix deadalnix deleted the isalphanum branch October 12, 2022 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants