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
168 lines
5.7 KiB
C++
168 lines
5.7 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <rocRoller/CodeGen/Arithmetic/Subtract.hpp>
|
|
#include <rocRoller/CodeGen/SubInstruction.hpp>
|
|
#include <rocRoller/Utilities/Component.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
template <>
|
|
std::shared_ptr<BinaryArithmeticGenerator<Expression::Subtract>>
|
|
GetGenerator<Expression::Subtract>(Register::ValuePtr dst,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
AssertFatal(dst != nullptr, "Null destination");
|
|
// Choose the proper generator, based on the context, register type
|
|
// and datatype.
|
|
return Component::Get<BinaryArithmeticGenerator<Expression::Subtract>>(
|
|
getContextFromValues(dst, lhs, rhs),
|
|
promoteRegisterType(dst, lhs, rhs),
|
|
promoteDataType(dst, lhs, rhs));
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Scalar, DataType::Int32>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
AssertFatal(lhs != nullptr);
|
|
AssertFatal(rhs != nullptr);
|
|
|
|
co_yield ScalarSubInt32(m_context, dest, lhs, rhs);
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Vector, DataType::Int32>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
AssertFatal(lhs != nullptr);
|
|
AssertFatal(rhs != nullptr);
|
|
|
|
auto const& gpu = m_context->targetArchitecture().target();
|
|
if(gpu.isCDNAGPU())
|
|
{
|
|
co_yield_(Instruction("v_sub_i32", {dest}, {lhs, rhs}, {}, ""));
|
|
}
|
|
else if(gpu.isRDNAGPU())
|
|
{
|
|
co_yield_(Instruction("v_sub_nc_i32", {dest}, {lhs, rhs}, {}, ""));
|
|
}
|
|
else
|
|
{
|
|
Throw<FatalError>(fmt::format("SubtractGenerator<{}, {}> not implemented for {}\n",
|
|
toString(Register::Type::Vector),
|
|
toString(DataType::Int32),
|
|
gpu.toString()));
|
|
}
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Scalar, DataType::UInt32>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
AssertFatal(lhs != nullptr);
|
|
AssertFatal(rhs != nullptr);
|
|
|
|
co_yield ScalarSubUInt32(m_context, dest, lhs, rhs);
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Vector, DataType::UInt32>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
AssertFatal(lhs != nullptr);
|
|
AssertFatal(rhs != nullptr);
|
|
|
|
co_yield VectorSubUInt32(m_context, dest, lhs, rhs);
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Scalar, DataType::Int64>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
co_yield describeOpArgs("dest", dest, "lhs", lhs, "rhs", rhs);
|
|
Register::ValuePtr l0, l1, r0, r1;
|
|
co_yield get2DwordsScalar(l0, l1, lhs);
|
|
co_yield get2DwordsScalar(r0, r1, rhs);
|
|
|
|
co_yield(Instruction::Lock(Scheduling::Dependency::SCC, "Start of Int64 sub, locking SCC"));
|
|
|
|
co_yield ScalarSubUInt32(
|
|
m_context, dest->subset({0}), l0, r0, "least significant half; sets scc");
|
|
co_yield ScalarSubUInt32CarryInOut(
|
|
m_context, dest->subset({1}), l1, r1, "most significant half; uses scc");
|
|
|
|
co_yield(Instruction::Unlock("End of Int64 sub, unlocking SCC"));
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Vector, DataType::Int64>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
co_yield describeOpArgs("dest", dest, "lhs", lhs, "rhs", rhs);
|
|
|
|
Register::ValuePtr l0, l1, r0, r1;
|
|
co_yield get2DwordsVector(l0, l1, lhs);
|
|
co_yield get2DwordsVector(r0, r1, rhs);
|
|
|
|
auto borrow = m_context->getVCC();
|
|
|
|
co_yield VectorSubUInt32CarryOut(
|
|
m_context, dest->subset({0}), l0, r0, "least significant half")
|
|
.lock(Scheduling::Dependency::VCC, "Start of Int64 sub, locking VCC");
|
|
|
|
co_yield VectorSubUInt32CarryInOut(
|
|
m_context, dest->subset({1}), l1, r1, "most significant half")
|
|
.unlock("End of Int64 sub, unlocking VCC");
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Vector, DataType::Float>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
AssertFatal(lhs != nullptr);
|
|
AssertFatal(rhs != nullptr);
|
|
|
|
co_yield_(Instruction("v_sub_f32", {dest}, {lhs, rhs}, {}, ""));
|
|
}
|
|
|
|
template <>
|
|
Generator<Instruction> SubtractGenerator<Register::Type::Vector, DataType::Double>::generate(
|
|
Register::ValuePtr dest,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::Subtract const&)
|
|
{
|
|
AssertFatal(lhs != nullptr);
|
|
AssertFatal(rhs != nullptr);
|
|
|
|
auto nrhs = rhs->negate();
|
|
|
|
co_yield_(Instruction("v_add_f64", {dest}, {lhs, nrhs}, {}, ""));
|
|
}
|
|
|
|
}
|