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

Implement the and HLSL Function #125604

Closed
5 tasks
Tracked by #99235 ...
farzonl opened this issue Feb 4, 2025 · 3 comments · Fixed by #127098
Closed
5 tasks
Tracked by #99235 ...

Implement the and HLSL Function #125604

farzonl opened this issue Feb 4, 2025 · 3 comments · Fixed by #127098
Assignees
Labels
bot:HLSL clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Feb 4, 2025

  • Implement the and api in hlsl_intrinsics.h
    - [ ] Investigate to see if we can use __builtin_reduce_and
  • If a clang builtin is needed add sema checks for and to CheckHLSLBuiltinFunctionCall in SemaHLSL.cpp
  • If codegen is needed, add codegen for and to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/and.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/and-errors.hlsl

DirectX

There were no DXIL opcodes found for and.

SPIR-V

There were no SPIR-V opcodes found for and.

Test Case(s)

Example 1

//dxc and_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool4 fn(bool4 p1, bool4 p2) {
    return and(p1, p2);
}

HLSL:

Logically ands a vector and produces a bool vector output

Syntax

bool<> and(bool<> x, bool<> y);

Type Description

Name Template Type Component Type Size
ret scalar, vector, or matrix bool any
x scalar, vector, or matrix bool any
y scalar, vector, or matrix bool any

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
All Shader Models with HLSL 2021 Language Mode yes

Shader Stages

All Shader Stages

Remarks

In HLSL 2021 and(X, Y); is a replacement for

int3 X = {1, 1, 1};
int3 Y = {0, 0, 0};
bool3 Cond = X && Y;

See also

@farzonl farzonl added bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Feb 4, 2025
@Icohedron
Copy link
Contributor

I'll implement it!

@farzonl farzonl moved this to Planning in HLSL Support Feb 4, 2025
@damyanp damyanp moved this from Planning to Active in HLSL Support Feb 11, 2025
@Icohedron Icohedron moved this from Active to Needs Review in HLSL Support Feb 13, 2025
@bogner bogner linked a pull request Feb 19, 2025 that will close this issue
bogner pushed a commit that referenced this issue Feb 19, 2025
Addresses #125604 

- Implements `and` as an HLSL builtin function
- The `and` HLSL builtin function gets lowered to the the LLVM `and`
instruction
@github-project-automation github-project-automation bot moved this from Needs Review to Closed in HLSL Support Feb 19, 2025
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. labels Feb 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

- [ ] Implement the `and` api in `hlsl_intrinsics.h` ~~- [ ] Investigate to see if we can use `__builtin_reduce_and`~~ - [ ] If a clang builtin is needed add sema checks for `and` to `CheckHLSLBuiltinFunctionCall` in `SemaHLSL.cpp` - [ ] If codegen is needed, add codegen for `and` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/and.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/and-errors.hlsl`

DirectX

There were no DXIL opcodes found for and.

SPIR-V

There were no SPIR-V opcodes found for and.

Test Case(s)

Example 1

//dxc and_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool4 fn(bool4 p1, bool4 p2) {
    return and(p1, p2);
}

HLSL:

Logically ands a vector and produces a bool vector output

Syntax

bool&lt;&gt; and(bool&lt;&gt; x, bool&lt;&gt; y);

Type Description

Name Template Type Component Type Size
ret scalar, vector, or matrix bool any
x scalar, vector, or matrix bool any
y scalar, vector, or matrix bool any

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
All Shader Models with HLSL 2021 Language Mode yes

Shader Stages

All Shader Stages

Remarks

In HLSL 2021 and(X, Y); is a replacement for

int3 X = {1, 1, 1};
int3 Y = {0, 0, 0};
bool3 Cond = X &amp;&amp; Y;

See also

@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

@llvm/issue-subscribers-clang-frontend

Author: Farzon Lotfi (farzonl)

- [ ] Implement the `and` api in `hlsl_intrinsics.h` ~~- [ ] Investigate to see if we can use `__builtin_reduce_and`~~ - [ ] If a clang builtin is needed add sema checks for `and` to `CheckHLSLBuiltinFunctionCall` in `SemaHLSL.cpp` - [ ] If codegen is needed, add codegen for `and` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/and.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/and-errors.hlsl`

DirectX

There were no DXIL opcodes found for and.

SPIR-V

There were no SPIR-V opcodes found for and.

Test Case(s)

Example 1

//dxc and_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool4 fn(bool4 p1, bool4 p2) {
    return and(p1, p2);
}

HLSL:

Logically ands a vector and produces a bool vector output

Syntax

bool&lt;&gt; and(bool&lt;&gt; x, bool&lt;&gt; y);

Type Description

Name Template Type Component Type Size
ret scalar, vector, or matrix bool any
x scalar, vector, or matrix bool any
y scalar, vector, or matrix bool any

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
All Shader Models with HLSL 2021 Language Mode yes

Shader Stages

All Shader Stages

Remarks

In HLSL 2021 and(X, Y); is a replacement for

int3 X = {1, 1, 1};
int3 Y = {0, 0, 0};
bool3 Cond = X &amp;&amp; Y;

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:HLSL clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

4 participants