File: val_extension_spv_intel_inline_assembly.cpp

package info (click to toggle)
spirv-tools 2026.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 28,900 kB
  • sloc: cpp: 477,281; javascript: 5,908; python: 3,326; ansic: 488; sh: 450; ruby: 88; makefile: 18; lisp: 9
file content (109 lines) | stat: -rw-r--r-- 3,450 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2025 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Tests for SPV_INTEL_inline_assembly

#include <string>

#include "gmock/gmock.h"
#include "test/val/val_fixtures.h"

namespace spvtools {
namespace val {
namespace {

using ::testing::HasSubstr;

using ValidateSpvINTELInlineAssembly = spvtest::ValidateBase<bool>;

TEST_F(ValidateSpvINTELInlineAssembly, Valid) {
  const std::string str = R"(
         OpCapability Kernel
         OpCapability Addresses
         OpCapability Linkage
         OpCapability AsmINTEL
         OpExtension "SPV_INTEL_inline_assembly"
         OpMemoryModel Physical32 OpenCL
         OpDecorate %1 SideEffectsINTEL
    %2 = OpTypeVoid
    %3 = OpTypeFunction %2
    %4 = OpAsmTargetINTEL "spirv64-unknown-unknown"
    %1 = OpAsmINTEL %2 %3 %4 "nop" ""
    %5 = OpFunction %2 None %3
    %6 = OpLabel
    %7 = OpAsmCallINTEL %2 %1
         OpReturn
         OpFunctionEnd
  )";
  CompileSuccessfully(str.c_str());
  EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}

TEST_F(ValidateSpvINTELInlineAssembly, RequiresExtension) {
  const std::string str = R"(
         OpCapability Kernel
         OpCapability Addresses
         OpCapability Linkage
         OpCapability AsmINTEL
         OpMemoryModel Physical32 OpenCL
         OpDecorate %1 SideEffectsINTEL
    %2 = OpTypeVoid
    %3 = OpTypeFunction %2
    %4 = OpAsmTargetINTEL "spirv64-unknown-unknown"
    %1 = OpAsmINTEL %2 %3 %4 "nop" ""
    %5 = OpFunction %2 None %3
    %6 = OpLabel
    %7 = OpAsmCallINTEL %2 %1
         OpReturn
         OpFunctionEnd
  )";
  CompileSuccessfully(str.c_str());
  EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
  const std::string diag = getDiagnosticString();
  EXPECT_THAT(
      diag,
      HasSubstr("1st operand of Capability: operand AsmINTEL(5606) requires "
                "one of these extensions: SPV_INTEL_inline_assembly"));
  EXPECT_THAT(diag, HasSubstr("OpCapability AsmINTEL"));
}

TEST_F(ValidateSpvINTELInlineAssembly, RequiresCapability) {
  const std::string str = R"(
         OpCapability Kernel
         OpCapability Addresses
         OpCapability Linkage
         OpExtension "SPV_INTEL_inline_assembly"
         OpMemoryModel Physical32 OpenCL
         OpDecorate %1 SideEffectsINTEL
    %2 = OpTypeVoid
    %3 = OpTypeFunction %2
    %4 = OpAsmTargetINTEL "spirv64-unknown-unknown"
    %1 = OpAsmINTEL %2 %3 %4 "nop" ""
    %5 = OpFunction %2 None %3
    %6 = OpLabel
    %7 = OpAsmCallINTEL %2 %1
         OpReturn
         OpFunctionEnd
)";
  CompileSuccessfully(str.c_str());
  EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
  const std::string diag = getDiagnosticString();
  EXPECT_THAT(diag, HasSubstr("Operand 2 of Decorate requires one of these "
                              "capabilities: AsmINTEL"));
  EXPECT_THAT(diag, HasSubstr("OpDecorate %1 SideEffectsINTEL"));
}

}  // namespace
}  // namespace val
}  // namespace spvtools