Debian Codegraph @

test/ext_inst.arm_motion_engine_test.cpp

raw
1 // Copyright (c) 2024-2025 Arm Ltd.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <string>
16
17 #include "gmock/gmock.h"
18 #include "source/util/string_utils.h"
19 #include "spirv/unified1/ArmMotionEngine.100.h"
20 #include "test/test_fixture.h"
21 #include "test/unit_spirv.h"
22
23 namespace spvtools {
24 namespace {
25
26 using spvtest::Concatenate;
27 using spvtest::MakeInstruction;
28 using spvtest::TextToBinaryTest;
29 using testing::Eq;
30 using utils::MakeVector;
31
32 TEST_F(TextToBinaryTest, ArmMotionEngineImportTest) {
33 const std::string src = "%1 = OpExtInstImport \"Arm.MotionEngine.100\"";
34 EXPECT_THAT(CompiledInstructions(src),
35 Eq(MakeInstruction(spv::Op::OpExtInstImport, {1},
36 MakeVector("Arm.MotionEngine.100"))));
37 }
38
39 TEST_F(TextToBinaryTest, ArmMotionEngineInstructionMIN_SAD) {
40 const std::string src =
41 "%1 = OpExtInstImport \"Arm.MotionEngine.100\"\n"
42 "%3 = OpExtInst %2 %1 MIN_SAD %4 %5 %6 %7 %8 %9 %10 %11 %12\n";
43
44 // First make sure it assembles correctly.
45 EXPECT_THAT(
46 CompiledInstructions(src),
47 Eq(Concatenate({MakeInstruction(spv::Op::OpExtInstImport, {1},
48 MakeVector("Arm.MotionEngine.100")),
49 MakeInstruction(spv::Op::OpExtInst,
50 {2, 3, 1, ArmMotionEngineMIN_SAD, 4, 5, 6,
51 7, 8, 9, 10, 11, 12})})))
52 << src;
53 // Now check the round trip through the disassembler.
54 EXPECT_THAT(EncodeAndDecodeSuccessfully(src), src) << src;
55 }
56
57 TEST_F(TextToBinaryTest, ArmMotionEngineInstructionMIN_SAD_COST) {
58 const std::string src =
59 "%1 = OpExtInstImport \"Arm.MotionEngine.100\"\n"
60 "%3 = OpExtInst %2 %1 MIN_SAD_COST %4 %5 %6 %7 %8 %9 %10 %11 %12\n";
61
62 // First make sure it assembles correctly.
63 EXPECT_THAT(
64 CompiledInstructions(src),
65 Eq(Concatenate({MakeInstruction(spv::Op::OpExtInstImport, {1},
66 MakeVector("Arm.MotionEngine.100")),
67 MakeInstruction(spv::Op::OpExtInst,
68 {2, 3, 1, ArmMotionEngineMIN_SAD_COST, 4,
69 5, 6, 7, 8, 9, 10, 11, 12})})))
70 << src;
71 // Now check the round trip through the disassembler.
72 EXPECT_THAT(EncodeAndDecodeSuccessfully(src), src) << src;
73 }
74
75 TEST_F(TextToBinaryTest, ArmMotionEngineInstructionRAW_SAD) {
76 const std::string src =
77 "%1 = OpExtInstImport \"Arm.MotionEngine.100\"\n"
78 "%3 = OpExtInst %2 %1 RAW_SAD %4 %5 %6 %7 %8 %9 %10 %11\n";
79
80 // First make sure it assembles correctly.
81 EXPECT_THAT(
82 CompiledInstructions(src),
83 Eq(Concatenate(
84 {MakeInstruction(spv::Op::OpExtInstImport, {1},
85 MakeVector("Arm.MotionEngine.100")),
86 MakeInstruction(spv::Op::OpExtInst, {2, 3, 1, ArmMotionEngineRAW_SAD,
87 4, 5, 6, 7, 8, 9, 10, 11})})))
88 << src;
89 // Now check the round trip through the disassembler.
90 EXPECT_THAT(EncodeAndDecodeSuccessfully(src), src) << src;
91 }
92
93 } // namespace
94 } // namespace spvtools