Files
wgpu/naga/tests/out/spv/collatz.spvasm
T

192 lines
4.4 KiB
Plaintext

; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 78
OpCapability Shader
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %67 "main" %64
OpExecutionMode %67 LocalSize 1 1 1
%3 = OpString "collatz.wgsl"
OpSource Unknown 0 %3 "struct PrimeIndices {
data: array<u32>
} // this is used as both input and output for convenience
@group(0) @binding(0)
var<storage,read_write> v_indices: PrimeIndices;
// The Collatz Conjecture states that for any integer n:
// If n is even, n = n/2
// If n is odd, n = 3n+1
// And repeat this process for each new n, you will always eventually reach 1.
// Though the conjecture has not been proven, no counterexample has ever been found.
// This function returns how many times this recurrence needs to be applied to reach 1.
fn collatz_iterations(n_base: u32) -> u32 {
var n = n_base;
var i: u32 = 0u;
while n > 1u {
if n % 2u == 0u {
n = n / 2u;
}
else {
n = 3u * n + 1u;
}
i = i + 1u;
}
return i;
}
@compute @workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
}
"
OpMemberName %6 0 "data"
OpName %6 "PrimeIndices"
OpName %8 "v_indices"
OpName %10 "naga_mod"
OpName %12 "lhs"
OpName %13 "rhs"
OpName %21 "naga_div"
OpName %22 "lhs"
OpName %23 "rhs"
OpName %29 "n_base"
OpName %30 "collatz_iterations"
OpName %34 "n"
OpName %37 "i"
OpName %64 "global_id"
OpName %67 "main"
OpDecorate %5 ArrayStride 4
OpMemberDecorate %6 0 Offset 0
OpDecorate %6 Block
OpDecorate %8 DescriptorSet 0
OpDecorate %8 Binding 0
OpDecorate %64 BuiltIn GlobalInvocationId
%2 = OpTypeVoid
%4 = OpTypeInt 32 0
%5 = OpTypeRuntimeArray %4
%6 = OpTypeStruct %5
%7 = OpTypeVector %4 3
%9 = OpTypePointer StorageBuffer %6
%8 = OpVariable %9 StorageBuffer
%11 = OpTypeFunction %4 %4 %4
%15 = OpTypeBool
%16 = OpConstant %4 0
%18 = OpConstant %4 1
%31 = OpTypeFunction %4 %4
%32 = OpConstant %4 2
%33 = OpConstant %4 3
%35 = OpTypePointer Function %4
%36 = OpConstantNull %4
%65 = OpTypePointer Input %7
%64 = OpVariable %65 Input
%68 = OpTypeFunction %2
%70 = OpTypePointer StorageBuffer %5
%72 = OpTypePointer StorageBuffer %4
%10 = OpFunction %4 None %11
%12 = OpFunctionParameter %4
%13 = OpFunctionParameter %4
%14 = OpLabel
%17 = OpIEqual %15 %13 %16
%19 = OpSelect %4 %17 %18 %13
%20 = OpUMod %4 %12 %19
OpReturnValue %20
OpFunctionEnd
%21 = OpFunction %4 None %11
%22 = OpFunctionParameter %4
%23 = OpFunctionParameter %4
%24 = OpLabel
%25 = OpIEqual %15 %23 %16
%26 = OpSelect %4 %25 %18 %23
%27 = OpUDiv %4 %22 %26
OpReturnValue %27
OpFunctionEnd
%30 = OpFunction %4 None %31
%29 = OpFunctionParameter %4
%28 = OpLabel
%34 = OpVariable %35 Function %36
%37 = OpVariable %35 Function %16
OpBranch %38
%38 = OpLabel
OpLine %3 15 5
OpStore %34 %29
OpBranch %39
%39 = OpLabel
OpLine %3 17 5
OpLoopMerge %40 %42 None
OpBranch %41
%41 = OpLabel
OpLine %3 1 1
%43 = OpLoad %4 %34
OpLine %3 17 11
%44 = OpUGreaterThan %15 %43 %18
OpLine %3 17 10
OpSelectionMerge %45 None
OpBranchConditional %44 %45 %46
%46 = OpLabel
OpBranch %40
%45 = OpLabel
OpBranch %47
%47 = OpLabel
OpLine %3 1 1
%49 = OpLoad %4 %34
OpLine %3 18 12
%50 = OpFunctionCall %4 %10 %49 %32
OpLine %3 18 12
%51 = OpIEqual %15 %50 %16
OpLine %3 18 9
OpSelectionMerge %52 None
OpBranchConditional %51 %53 %54
%53 = OpLabel
OpLine %3 1 1
%55 = OpLoad %4 %34
OpLine %3 19 17
%56 = OpFunctionCall %4 %21 %55 %32
OpLine %3 19 13
OpStore %34 %56
OpBranch %52
%54 = OpLabel
OpLine %3 22 17
%57 = OpLoad %4 %34
%58 = OpIMul %4 %33 %57
OpLine %3 22 17
%59 = OpIAdd %4 %58 %18
OpLine %3 22 13
OpStore %34 %59
OpBranch %52
%52 = OpLabel
OpLine %3 1 1
%60 = OpLoad %4 %37
OpLine %3 24 13
%61 = OpIAdd %4 %60 %18
OpLine %3 24 9
OpStore %37 %61
OpBranch %48
%48 = OpLabel
OpBranch %42
%42 = OpLabel
OpBranch %39
%40 = OpLabel
OpLine %3 1 1
%62 = OpLoad %4 %37
OpReturnValue %62
OpFunctionEnd
%67 = OpFunction %2 None %68
%63 = OpLabel
%66 = OpLoad %7 %64
OpBranch %69
%69 = OpLabel
OpLine %3 31 5
%71 = OpCompositeExtract %4 %66 0
OpLine %3 31 54
%73 = OpCompositeExtract %4 %66 0
%74 = OpAccessChain %72 %8 %16 %73
%75 = OpLoad %4 %74
OpLine %3 31 35
%76 = OpFunctionCall %4 %30 %75
OpLine %3 31 5
%77 = OpAccessChain %72 %8 %16 %71
OpStore %77 %76
OpReturn
OpFunctionEnd