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 fmod HLSL Function #99118

Open
12 tasks
Tracked by #99235 ...
farzonl opened this issue Jul 16, 2024 · 3 comments
Open
12 tasks
Tracked by #99235 ...

Implement the fmod HLSL Function #99118

farzonl opened this issue Jul 16, 2024 · 3 comments
Assignees
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • Implement fmod clang builtin,
  • Link fmod clang builtin with hlsl_intrinsics.h
  • Add sema checks for fmod to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for fmod to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/fmod.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl
  • Create the int_dx_fmod intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_fmod to 6 in DXIL.td
  • Create the fmod.ll and fmod_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_fmod intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the fmod lowering and map it to int_spv_fmod in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmod.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
6 FAbs 6.0 ()

SPIR-V

OpFRem:

Description:

The floating-point remainder whose sign matches the sign
of Operand 1.

Result Type must be a scalar or vector of floating-point
type
.

The types of Operand 1 and Operand 2 both must be the same as
Result Type.

Results are computed per component. The resulting value is undefined if
Operand 2 is 0. Otherwise, the result is the remainder
r of Operand 1 divided by Operand 2 where if r ≠ 0, the sign of
r is the same as the sign of Operand 1.

Word Count Opcode Results Operands

5

140

<id>
Result Type

Result <id>

<id>
Operand 1

<id>
Operand 2

Test Case(s)

Example 1

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

export float4 fn(float4 p1, float4 p2) {
    return fmod(p1, p2);
}

HLSL:

Returns the floating-point remainder of x/y.

ret fmod(x, y)

Parameters

Item Description
x
[in] The floating-point dividend.
y
[in] The floating-point divisor.

Return Value

The floating-point remainder of the x parameter divided by the y parameter.

Remarks

The floating-point remainder is calculated such that x = i * y + f, where i is an integer, f has the same sign as x, and the absolute value of f is less than the absolute value of y.

Type Description

Name Template Type Component Type Size
x scalar, vector, or matrix float any
y same as input x float same dimension(s) as input x
ret same as input x float same dimension(s) as input x

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 2 (DirectX HLSL) and higher shader models yes
Shader Model 1 (DirectX HLSL) vs_1_1

Requirements

Requirement Value
Header
Corecrt_math.h

See also

Intrinsic Functions (DirectX HLSL)

@farzonl
Copy link
Member Author

farzonl commented Aug 17, 2024

Note to implementer it is very likely we don't need to create int_dx_fmod and int_spv_fmod target specific intrinsics if we can use frem

@lizhengxing
Copy link
Contributor

I'll work on this task.

lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 16, 2024
This change implements the frontend for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - add the builtin to DirectX intrinsic mapping
hlsl_intrinsics.h     - add the fmod api
SemaHLSL.cpp          - add type checks for builtin
IntrinsicsDirectX.td  - add the fmod DirectX intrinsic
@pow2clk pow2clk moved this to Active in HLSL Support Sep 23, 2024
lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 24, 2024
This change implements the frontend for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaHLSL.cpp          - add type checks for builtin

clang/docs/LanguageExtensions.rst  - add the builtin in *Elementwise Builtins*
lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 24, 2024
This change implements the frontend for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaHLSL.cpp          - add type checks for builtin

clang/docs/LanguageExtensions.rst  - add the builtin in *Elementwise Builtins*
lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 24, 2024
This change implements the frontend for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaHLSL.cpp          - add type checks for builtin

clang/docs/LanguageExtensions.rst  - add the builtin in *Elementwise Builtins*
clang/docs/ReleaseNotes.rst        - announce the builtin
lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 26, 2024
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaChecking.cpp      - add type checks for builtin
SemaHLSL.cpp          - add HLSL type checks for builtin

clang/docs/LanguageExtensions.rst  - add the builtin in *Elementwise Builtins*
clang/docs/ReleaseNotes.rst        - announce the builtin
lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 26, 2024
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaChecking.cpp      - add type checks for builtin
SemaHLSL.cpp          - add HLSL type checks for builtin

clang/docs/LanguageExtensions.rst  - add the builtin in *Elementwise Builtins*
clang/docs/ReleaseNotes.rst        - announce the builtin
lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 26, 2024
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaChecking.cpp      - add type checks for builtin
SemaHLSL.cpp          - add HLSL type checks for builtin

clang/docs/LanguageExtensions.rst  - add the builtin in *Elementwise Builtins*
clang/docs/ReleaseNotes.rst        - announce the builtin
lizhengxing added a commit to lizhengxing/llvm-project that referenced this issue Sep 27, 2024
This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for llvm#99118
Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaChecking.cpp      - add type checks for builtin
SemaHLSL.cpp          - add HLSL type checks for builtin

clang/docs/LanguageExtensions.rst  - add the builtin in *Elementwise Builtins*
clang/docs/ReleaseNotes.rst        - announce the builtin
farzonl pushed a commit that referenced this issue Sep 27, 2024
This change add the elementwise fmod builtin to support HLSL function
'fmod' in clang for #99118

Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaChecking.cpp      - add type checks for builtin
SemaHLSL.cpp          - add HLSL type checks for builtin

clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise
Builtins*
clang/docs/ReleaseNotes.rst        - announce the builtin
xgupta pushed a commit to xgupta/llvm-project that referenced this issue Oct 4, 2024
This change add the elementwise fmod builtin to support HLSL function
'fmod' in clang for llvm#99118

Builtins.td           - add the fmod builtin
CGBuiltin.cpp         - lower the builtin to llvm FRem instruction
hlsl_intrinsics.h     - add the fmod api
SemaChecking.cpp      - add type checks for builtin
SemaHLSL.cpp          - add HLSL type checks for builtin

clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise
Builtins*
clang/docs/ReleaseNotes.rst        - announce the builtin
@damyanp
Copy link
Contributor

damyanp commented Oct 21, 2024

We want to decide llvm/wg-hlsl#86 before we continue with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Active
Development

No branches or pull requests

3 participants