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

[HLSL] Default literal floating point types to float #85714

Closed
Tracked by #67692
llvm-beanz opened this issue Mar 18, 2024 · 3 comments · Fixed by #91015
Closed
Tracked by #67692

[HLSL] Default literal floating point types to float #85714

llvm-beanz opened this issue Mar 18, 2024 · 3 comments · Fixed by #91015
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support

Comments

@llvm-beanz
Copy link
Collaborator

llvm-beanz commented Mar 18, 2024

In C/C++ literal floating point values default as double. In HLSL the behavior is a bit more complicated.

In DXC, literal types were given their own type which was then preserved through instantiation of builtin functions. This ends up being extremely complicated and fragile as templates and other type inference were added to the language.

For Clang, we can accomplish a comparable source-compatible implementation by having the default type for floating point literals resolve to the smallest supported type (i.e. 32-bits by default or 16-bit if 16-bit types are enabled).

This implementation will prevent some bugs that exist in DXC today like the bugs described in this issue or this one, which incorrectly emit 64-bit types instead of 32-bit.

It also is a way simpler approach to the problem that will not collide with template type deduction or other language features that rely on type inference.

Acceptance Criteria

  • HLSL 202x spec is accepted
  • the literal is updated to use float
  • A set of tests that demonstrate floating point literal values resolving to the smallest appropriate floating point type and code generation verifying correctness.
@llvm-beanz llvm-beanz added the HLSL HLSL Language Support label Mar 18, 2024
@llvm-beanz llvm-beanz changed the title [HLSL] Default literal floating point types to smallest supported type [HLSL] Default literal floating point types to float Mar 20, 2024
@llvm-beanz
Copy link
Collaborator Author

Spec PR: microsoft/hlsl-specs#175

@damyanp
Copy link
Contributor

damyanp commented Apr 8, 2024

Blocked on spec being approved and agreed upon.

llvm-beanz added a commit to llvm-beanz/llvm-project that referenced this issue May 3, 2024
This implements the HLSL 202x conforming literals feature.

The feature proposal is available here:
https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conform
ing-literals.md

The language specification for this behavior is available in (poorly
rendered) HTML or PDF:
https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Lex.Literal.Float
https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf

The main implementation details are:
1) Unsuffixed floating literals are `float`.
2) The integer `ll` suffix specifies `int64_t (aka long)` which is
64-bit because HLSL has no defined `long` keyword or `long long` type.

Resolves llvm#85714
llvm-beanz added a commit that referenced this issue May 6, 2024
This implements the HLSL 202x conforming literals feature.

The feature proposal is available here:

https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conforming-literals.md

The language specification for this behavior is available in (poorly
rendered) HTML or PDF:
https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Lex.Literal.Float
https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf

The main implementation details are:
1) Unsuffixed floating literals are `float`.
2) The integer `ll` suffix specifies `int64_t (aka long)` which is
64-bit because HLSL has no defined `long` keyword or `long long` type.

Resolves #85714
@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label May 6, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 6, 2024

@llvm/issue-subscribers-clang-frontend

Author: Chris B (llvm-beanz)

In C/C++ literal floating point values default as double. In HLSL the behavior is a bit more complicated.

In DXC, literal types were given their own type which was then preserved through instantiation of builtin functions. This ends up being extremely complicated and fragile as templates and other type inference were added to the language.

For Clang, we can accomplish a comparable source-compatible implementation by having the default type for floating point literals resolve to the smallest supported type (i.e. 32-bits by default or 16-bit if 16-bit types are enabled).

This implementation will prevent some bugs that exist in DXC today like the bugs described in this issue or this one, which incorrectly emit 64-bit types instead of 32-bit.

It also is a way simpler approach to the problem that will not collide with template type deduction or other language features that rely on type inference.

Acceptance Criteria

  • HLSL 202x spec is accepted
  • the literal is updated to use float
  • A set of tests that demonstrate floating point literal values resolving to the smallest appropriate floating point type and code generation verifying correctness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants