Add minimal as/dis support for TOSA.001000.1 extended instruction set (#6183)

* Add minimal as/dis support for TOSA.001000.1 extended instruction set

Change-Id: Ieefcd9c9a46dc3021c1600c02f9be96c49641aa9
Signed-off-by: Kevin Petit <kevin.petit@arm.com>

* pick up headers

Change-Id: Ie0d1c5258367774451373f7d81e231e2fc674937

* attempt to fix Bazel builds

Change-Id: I34fbf54545ecb58a3bacdf1f711e22547e8b5666

* Revert changes to BUILD.gn

This reverts commit d4496b744a295a9fc98292c4d76256dc9e127987.

* update headers

Change-Id: I368598d93f94bc39ff71db56269bf1baeedf37c8

* BUILD.bazel: add dependency on spirv_common_headers when building tests

Change-Id: I265b9622ce86f3d86b68a523ccf849a0134b890b

* attempt to fix table generation in Bazel builds

Change-Id: Ifa2a94af00af09fbd5aa1ae48eeac0603aa5b5f0

* another attempt

Change-Id: I411737a0544187c0c01d9628df9a7b556490750e

---------

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
diff --git a/BUILD.bazel b/BUILD.bazel
index 5724279..0c0bfe9 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -52,6 +52,7 @@
         ExtInst("opencl.std.100", target="spirv_opencl_grammar_unified1"),
         ExtInst("opencl.debuginfo.100", prefix="CLDEBUG100_"),
         ExtInst("nonsemantic.shader.debuginfo.100", prefix="SHDEBUG100_"),
+        ExtInst("tosa.001000.1", target="spirv_ext_inst_tosa_001000_1", prefix="TOSA_"),
     ] + [ExtInst(e) for e in [
             "spv-amd-shader-explicit-vertex-parameter",
             "spv-amd-shader-trinary-minmax",
@@ -431,6 +432,7 @@
         ":tools_io",
         "@googletest//:gtest",
         "@googletest//:gtest_main",
+        "@spirv_headers//:spirv_common_headers",
     ],
 ) for f in glob(
     [
diff --git a/DEPS b/DEPS
index b933939..0cbd750 100644
--- a/DEPS
+++ b/DEPS
@@ -14,7 +14,7 @@
 
   're2_revision': 'c84a140c93352cdabbfb547c531be34515b12228',
 
-  'spirv_headers_revision': '50daff941d88609b4d2ad076eae558e727f8e5cd',
+  'spirv_headers_revision': '2a611a970fdbc41ac2e3e328802aed9985352dca',
 }
 
 deps = {
diff --git a/include/spirv-tools/libspirv.h b/include/spirv-tools/libspirv.h
index 823475f..a2a032a 100644
--- a/include/spirv-tools/libspirv.h
+++ b/include/spirv-tools/libspirv.h
@@ -369,6 +369,7 @@
   SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
   SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100,
   SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION,
+  SPV_EXT_INST_TYPE_TOSA_001000_1,
 
   // Multiple distinct extended instruction set types could return this
   // value, if they are prefixed with NonSemantic. and are otherwise
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 58fd815..f822ada 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -31,6 +31,7 @@
 set(EI_ns_debuginfo "${GRAMMAR_DIR}/extinst.nonsemantic.shader.debuginfo.100.grammar.json")
 set(EI_ns_clspvreflect "${GRAMMAR_DIR}/extinst.nonsemantic.clspvreflection.grammar.json")
 set(EI_ns_vkspreflect "${GRAMMAR_DIR}/extinst.nonsemantic.vkspreflection.grammar.json")
+set(EI_tosa_001000_1 "${GRAMMAR_DIR}/extinst.tosa.001000.1.grammar.json")
 
 set(CORE_TABLES_BODY_INC_FILE ${spirv-tools_BINARY_DIR}/core_tables_body.inc)
 set(CORE_TABLES_HEADER_INC_FILE ${spirv-tools_BINARY_DIR}/core_tables_header.inc)
@@ -50,6 +51,7 @@
       --extinst=,${EI_debuginfo}
       --extinst=,${EI_ns_clspvreflect}
       --extinst=,${EI_ns_vkspreflect}
+      --extinst=TOSA_,${EI_tosa_001000_1}
     DEPENDS ${GGT_SCRIPT}
             ${SPIRV_CORE_GRAMMAR_JSON_FILE}
 	    ${EI_glsl}
@@ -63,6 +65,7 @@
 	    ${EI_debuginfo}
 	    ${EI_ns_clspvreflect}
 	    ${EI_ns_vkspreflect}
+            ${EI_tosa_001000_1}
     COMMENT "Generate grammar tables")
 add_custom_target(spirv-tools-tables DEPENDS ${CORE_TABLES_BODY_INC_FILE} ${CORE_TABLES_HEADER_INC_FILE})
 
diff --git a/source/ext_inst.cpp b/source/ext_inst.cpp
index c8fe8bb..761b8d2 100644
--- a/source/ext_inst.cpp
+++ b/source/ext_inst.cpp
@@ -55,6 +55,9 @@
   if (!strncmp("NonSemantic.VkspReflection.", name, 27)) {
     return SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION;
   }
+  if (!strcmp("TOSA.001000.1", name)) {
+    return SPV_EXT_INST_TYPE_TOSA_001000_1;
+  }
   // ensure to add any known non-semantic extended instruction sets
   // above this point, and update spvExtInstIsNonSemantic()
   if (!strncmp("NonSemantic.", name, 12)) {
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 68ce4ef..acd5116 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -108,6 +108,7 @@
   ext_inst.glsl_test.cpp
   ext_inst.non_semantic_test.cpp
   ext_inst.opencl_test.cpp
+  ext_inst.tosa_test.cpp
   ext_inst_lookup_test.cpp
   fix_word_test.cpp
   generator_magic_number_test.cpp
diff --git a/test/ext_inst.tosa_test.cpp b/test/ext_inst.tosa_test.cpp
new file mode 100644
index 0000000..2a506bd
--- /dev/null
+++ b/test/ext_inst.tosa_test.cpp
@@ -0,0 +1,57 @@
+// Copyright (c) 2024-2025 Arm Ltd.
+//
+// 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.
+
+#include <string>
+
+#include "gmock/gmock.h"
+#include "source/util/string_utils.h"
+#include "spirv/unified1/TOSA.001000.1.h"
+#include "test/test_fixture.h"
+#include "test/unit_spirv.h"
+
+namespace spvtools {
+namespace {
+
+using spvtest::Concatenate;
+using spvtest::MakeInstruction;
+using spvtest::TextToBinaryTest;
+using testing::Eq;
+using utils::MakeVector;
+
+TEST_F(TextToBinaryTest, TOSAImportTest) {
+  const std::string src = "%1 = OpExtInstImport \"TOSA.001000.1\"";
+  EXPECT_THAT(CompiledInstructions(src),
+              Eq(MakeInstruction(spv::Op::OpExtInstImport, {1},
+                                 MakeVector("TOSA.001000.1"))));
+}
+
+TEST_F(TextToBinaryTest, TOSAInstructionSmokeTest) {
+  const std::string src =
+      "%1 = OpExtInstImport \"TOSA.001000.1\"\n"
+      "%3 = OpExtInst %2 %1 ARGMAX %4 %5 %6\n";
+
+  // First make sure it assembles correctly.
+  EXPECT_THAT(
+      CompiledInstructions(src),
+      Eq(Concatenate({MakeInstruction(spv::Op::OpExtInstImport, {1},
+                                      MakeVector("TOSA.001000.1")),
+                      MakeInstruction(spv::Op::OpExtInst,
+                                      {2, 3, 1, TOSAARGMAX, 4, 5, 6})})))
+      << src;
+  // Now check the round trip through the disassembler.
+  EXPECT_THAT(EncodeAndDecodeSuccessfully(src), src) << src;
+}
+
+}  // namespace
+}  // namespace spvtools