-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPIRV] Implement log10 for logical SPIR-V (#66921)
There is no log10 instruction in the GLSL Extended Instruction Set so to implement the HLSL log10 intrinsic when targeting Vulkan this change adds the logic to derive the result using the following formula: ``` log10(x) = log2(x) * (1 / log2(10)) = log2(x) * 0.30103 ```
- Loading branch information
1 parent
469b9cb
commit 0a2aaab
Showing
4 changed files
with
116 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s | ||
|
||
; CHECK: %[[#extinst:]] = OpExtInstImport "GLSL.std.450" | ||
|
||
; CHECK: %[[#float:]] = OpTypeFloat 32 | ||
; CHECK: %[[#v4float:]] = OpTypeVector %[[#float]] 4 | ||
; CHECK: %[[#float_0_30103001:]] = OpConstant %[[#float]] 0.30103000998497009 | ||
; CHECK: %[[#_ptr_Function_v4float:]] = OpTypePointer Function %[[#v4float]] | ||
; CHECK: %[[#_ptr_Function_float:]] = OpTypePointer Function %[[#float]] | ||
|
||
define void @main() { | ||
entry: | ||
; CHECK: %[[#f:]] = OpVariable %[[#_ptr_Function_float]] Function | ||
; CHECK: %[[#logf:]] = OpVariable %[[#_ptr_Function_float]] Function | ||
; CHECK: %[[#f4:]] = OpVariable %[[#_ptr_Function_v4float]] Function | ||
; CHECK: %[[#logf4:]] = OpVariable %[[#_ptr_Function_v4float]] Function | ||
%f = alloca float, align 4 | ||
%logf = alloca float, align 4 | ||
%f4 = alloca <4 x float>, align 16 | ||
%logf4 = alloca <4 x float>, align 16 | ||
|
||
; CHECK: %[[#load:]] = OpLoad %[[#float]] %[[#f]] Aligned 4 | ||
; CHECK: %[[#log2:]] = OpExtInst %[[#float]] %[[#extinst]] Log2 %[[#load]] | ||
; CHECK: %[[#res:]] = OpFMul %[[#float]] %[[#log2]] %[[#float_0_30103001]] | ||
; CHECK: OpStore %[[#logf]] %[[#res]] Aligned 4 | ||
%0 = load float, ptr %f, align 4 | ||
%elt.log10 = call float @llvm.log10.f32(float %0) | ||
store float %elt.log10, ptr %logf, align 4 | ||
|
||
; CHECK: %[[#load:]] = OpLoad %[[#v4float]] %[[#f4]] Aligned 16 | ||
; CHECK: %[[#log2:]] = OpExtInst %[[#v4float]] %[[#extinst]] Log2 %[[#load]] | ||
; CHECK: %[[#res:]] = OpVectorTimesScalar %[[#v4float]] %[[#log2]] %[[#float_0_30103001]] | ||
; CHECK: OpStore %[[#logf4]] %[[#res]] Aligned 16 | ||
%1 = load <4 x float>, ptr %f4, align 16 | ||
%elt.log101 = call <4 x float> @llvm.log10.v4f32(<4 x float> %1) | ||
store <4 x float> %elt.log101, ptr %logf4, align 16 | ||
|
||
ret void | ||
} | ||
|
||
declare float @llvm.log10.f32(float) | ||
declare <4 x float> @llvm.log10.v4f32(<4 x float>) |