Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

86 lines
2.9 KiB
C++

// Copyright Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <rocRoller/Expression.hpp>
#include "CustomMatchers.hpp"
#include "CustomSections.hpp"
#include "ExpressionMatchers.hpp"
#include "TestContext.hpp"
#include "TestKernels.hpp"
#include <common/TestValues.hpp>
#include <common/WidenAddrExprTo64bit.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("WidenAddrExprTo64bit ExpressionTransformation works",
"[expression][expression-transformation]")
{
using namespace rocRoller;
using namespace Expression;
auto context = TestContext::ForDefaultTarget();
// Top-level expression should be in 64bit as the expression is for address calculation.
SECTION("addr expression only")
{
auto one = literal(1);
CHECK_THROWS_AS(rocRollerTest::widenAddrExprTo64bit(one), FatalError);
}
// When the datatype is in already 64-bit, no extra convert is added.
SECTION("No Extra Convert")
{
int64_t two = 2;
auto r64bit = Register::Value::Placeholder(
context.get(), Register::Type::Vector, DataType::Int64, 1);
r64bit->allocateNow();
auto v64bit = r64bit->expression();
CHECK_THAT(rocRollerTest::widenAddrExprTo64bit(-literal(two)), IdenticalTo(-literal(two)));
CHECK(toString(
rocRollerTest::widenAddrExprTo64bit(rocRollerTest::widenAddrExprTo64bit(v64bit)))
== toString(v64bit));
}
SECTION("Widen")
{
auto a = literal(33);
auto r0 = Register::Value::Placeholder(
context.get(), Register::Type::Vector, DataType::UInt32, 1);
r0->allocateNow();
auto v0 = r0->expression();
auto r1 = Register::Value::Placeholder(
context.get(), Register::Type::Vector, DataType::UInt32, 1);
r1->allocateNow();
auto v1 = r1->expression();
auto mul = a * v0;
uint64_t x = 100;
auto add = mul + literal(x);
CHECK(toString(add) == "Add(Multiply(33:I, v0:U32)U32, 100:U64)U64");
CHECK(toString(rocRollerTest::widenAddrExprTo64bit(add))
== "Add(Multiply(Convert(33:I)I64, Convert(v0:U32)U64)U64, 100:U64)U64");
uint64_t u64val = 0xFF;
CommandArgumentValue ca = u64val; //static_cast<uint64_t>()
auto d1 = v0 / literal(16);
auto mod = d1 % literal(uint32_t(4));
auto mul32 = v1 * literal(4);
auto expr = (mod + mul32) * literal(u64val);
CHECK(toString(expr)
== "Multiply(Add(Modulo(Divide(v0:U32, 16:I)U32, 4:U32)U32, Multiply(v1:U32, "
"4:I)U32)U32, 255:U64)U64");
CHECK(toString(rocRollerTest::widenAddrExprTo64bit(expr))
== "Multiply(Add(Modulo(Divide(Convert(v0:U32)U64, 16:I)U64, 4:U32)U64, "
"Multiply(Convert(v1:U32)U64, Convert(4:I)I64)U64)U64, 255:U64)U64");
}
}