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

Add intptr_t abs/min/max operations for CPU & CUDA targets #6160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

juliusikkala
Copy link
Contributor

This PR allows using abs/min/max with uintptr_t & intptr_t (= size_t as well).

This only covers the CPU and CUDA targets because they use the same code path, where this is easy to implement. For the rest of the targets, there seems to be many more obstacles, so I didn't do those in this PR (Slang::getIntTypeInfo() can't handle these types, so there's quite a few contexts where they don't work, it's not just these builtins)

Previously, e.g.

export __extern_cpp int main()
{
    size_t a = 1;
    size_t b = 2;

    printf("%lu\n", max(a, b));
    return 0;
}

would result in

(0): error 99999: Slang compilation aborted due to an exception of N5Slang13InternalErrorE: unexpected: unexpected type in intrinsic definition

@juliusikkala juliusikkala requested a review from a team as a code owner January 22, 2025 23:33
csyonghe
csyonghe previously approved these changes Jan 23, 2025
Copy link
Collaborator

@csyonghe csyonghe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@csyonghe csyonghe added the pr: non-breaking PRs without breaking changes label Jan 23, 2025
@juliusikkala
Copy link
Contributor Author

juliusikkala commented Jan 23, 2025

So apparently NVRTC doesn't have intptr_t & uintptr_t. I defined them with ptrdiff_t & size_t for now (they should be the same on modern platforms). If that's not OK, I guess these abs/min/max operations can't be supported for the CUDA target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants