[tint] Add u64 type class
This will be used in the MSL backend.
Bug: 394291739
Change-Id: I8ba27d2c1f2afb8c7042a07231f22b2465114aee
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/224594
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/core/type/BUILD.bazel b/src/tint/lang/core/type/BUILD.bazel
index 72511fa..7846814 100644
--- a/src/tint/lang/core/type/BUILD.bazel
+++ b/src/tint/lang/core/type/BUILD.bazel
@@ -76,6 +76,7 @@
"texture_dimension.cc",
"type.cc",
"u32.cc",
+ "u64.cc",
"u8.cc",
"unique_node.cc",
"vector.cc",
@@ -120,6 +121,7 @@
"texture_dimension.h",
"type.h",
"u32.h",
+ "u64.h",
"u8.h",
"unique_node.h",
"vector.h",
@@ -173,6 +175,7 @@
"texture_test.cc",
"type_test.cc",
"u32_test.cc",
+ "u64_test.cc",
"u8_test.cc",
"vector_test.cc",
],
diff --git a/src/tint/lang/core/type/BUILD.cmake b/src/tint/lang/core/type/BUILD.cmake
index c9a604b..5cb38228 100644
--- a/src/tint/lang/core/type/BUILD.cmake
+++ b/src/tint/lang/core/type/BUILD.cmake
@@ -114,6 +114,8 @@
lang/core/type/type.h
lang/core/type/u32.cc
lang/core/type/u32.h
+ lang/core/type/u64.cc
+ lang/core/type/u64.h
lang/core/type/u8.cc
lang/core/type/u8.h
lang/core/type/unique_node.cc
@@ -174,6 +176,7 @@
lang/core/type/texture_test.cc
lang/core/type/type_test.cc
lang/core/type/u32_test.cc
+ lang/core/type/u64_test.cc
lang/core/type/u8_test.cc
lang/core/type/vector_test.cc
)
diff --git a/src/tint/lang/core/type/BUILD.gn b/src/tint/lang/core/type/BUILD.gn
index aef93d5..fa4c95e 100644
--- a/src/tint/lang/core/type/BUILD.gn
+++ b/src/tint/lang/core/type/BUILD.gn
@@ -120,6 +120,8 @@
"type.h",
"u32.cc",
"u32.h",
+ "u64.cc",
+ "u64.h",
"u8.cc",
"u8.h",
"unique_node.cc",
@@ -174,6 +176,7 @@
"texture_test.cc",
"type_test.cc",
"u32_test.cc",
+ "u64_test.cc",
"u8_test.cc",
"vector_test.cc",
]
diff --git a/src/tint/lang/core/type/u64.cc b/src/tint/lang/core/type/u64.cc
new file mode 100644
index 0000000..cffb248
--- /dev/null
+++ b/src/tint/lang/core/type/u64.cc
@@ -0,0 +1,50 @@
+// Copyright 2025 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "src/tint/lang/core/type/u64.h"
+
+#include "src/tint/lang/core/type/manager.h"
+
+TINT_INSTANTIATE_TYPEINFO(tint::core::type::U64);
+
+namespace tint::core::type {
+
+U64::U64()
+ : Base(static_cast<size_t>(tint::TypeCode::Of<U64>().bits),
+ core::type::Flags{
+ Flag::kConstructable,
+ Flag::kCreationFixedFootprint,
+ Flag::kFixedFootprint,
+ }) {}
+
+U64::~U64() = default;
+
+U64* U64::Clone(CloneContext& ctx) const {
+ return ctx.dst.mgr->Get<U64>();
+}
+
+} // namespace tint::core::type
diff --git a/src/tint/lang/core/type/u64.h b/src/tint/lang/core/type/u64.h
new file mode 100644
index 0000000..474bd22
--- /dev/null
+++ b/src/tint/lang/core/type/u64.h
@@ -0,0 +1,62 @@
+// Copyright 2025 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef SRC_TINT_LANG_CORE_TYPE_U64_H_
+#define SRC_TINT_LANG_CORE_TYPE_U64_H_
+
+#include <string>
+
+#include "src/tint/lang/core/type/numeric_scalar.h"
+
+namespace tint::core::type {
+
+/// An unsigned 64-bit integer type.
+class U64 final : public Castable<U64, NumericScalar> {
+ public:
+ /// Constructor
+ U64();
+
+ /// Destructor
+ ~U64() override;
+
+ /// @returns the name for this type that closely resembles how it would be declared in WGSL.
+ std::string FriendlyName() const override { return "u64"; }
+
+ /// @returns the size in bytes of the type.
+ uint32_t Size() const override { return 8; }
+
+ /// @returns the alignment in bytes of the type.
+ uint32_t Align() const override { return 8; }
+
+ /// @param ctx the clone context
+ /// @returns a clone of this type
+ U64* Clone(CloneContext& ctx) const override;
+};
+
+} // namespace tint::core::type
+
+#endif // SRC_TINT_LANG_CORE_TYPE_U64_H_
diff --git a/src/tint/lang/core/type/u64_test.cc b/src/tint/lang/core/type/u64_test.cc
new file mode 100644
index 0000000..90dde6e
--- /dev/null
+++ b/src/tint/lang/core/type/u64_test.cc
@@ -0,0 +1,79 @@
+// Copyright 2025 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "src/tint/lang/core/type/u64.h"
+
+#include "src/tint/lang/core/type/helper_test.h"
+#include "src/tint/lang/core/type/u32.h"
+
+namespace tint::core::type {
+namespace {
+
+using U64Test = TestHelper;
+
+TEST_F(U64Test, Creation) {
+ auto* a = create<U64>();
+ EXPECT_TRUE(a->Is<U64>());
+}
+
+TEST_F(U64Test, SizeAndAlign) {
+ auto* a = create<U64>();
+ EXPECT_EQ(a->Size(), 8u);
+ EXPECT_EQ(a->Align(), 8u);
+}
+
+TEST_F(U64Test, Hash) {
+ auto* a = create<U64>();
+ auto* b = create<U64>();
+ EXPECT_EQ(a->unique_hash, b->unique_hash);
+}
+
+TEST_F(U64Test, Equals) {
+ auto* a = create<U64>();
+ auto* b = create<U64>();
+ auto* c = create<U32>();
+ EXPECT_TRUE(a->Equals(*b));
+ EXPECT_FALSE(a->Equals(*c));
+}
+
+TEST_F(U64Test, FriendlyName) {
+ U64 i;
+ EXPECT_EQ(i.FriendlyName(), "u64");
+}
+
+TEST_F(U64Test, Clone) {
+ auto* a = create<U64>();
+
+ core::type::Manager mgr;
+ core::type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
+
+ auto* b = a->Clone(ctx);
+ ASSERT_TRUE(b->Is<U64>());
+}
+
+} // namespace
+} // namespace tint::core::type