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
101 lines
4.1 KiB
C++
101 lines
4.1 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <rocRoller/CodeGen/Arithmetic/ArithmeticGenerator.hpp>
|
|
#include <rocRoller/CodeGen/Arithmetic/ArithmeticShiftR.hpp>
|
|
#include <rocRoller/DataTypes/DataTypes.hpp>
|
|
#include <rocRoller/Utilities/Component.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
template <>
|
|
std::shared_ptr<BinaryArithmeticGenerator<Expression::ArithmeticShiftR>>
|
|
GetGenerator<Expression::ArithmeticShiftR>(Register::ValuePtr dst,
|
|
Register::ValuePtr lhs,
|
|
Register::ValuePtr rhs,
|
|
Expression::ArithmeticShiftR const&)
|
|
{
|
|
return Component::Get<BinaryArithmeticGenerator<Expression::ArithmeticShiftR>>(
|
|
getContextFromValues(dst, lhs, rhs), dst->regType(), dst->variableType().dataType);
|
|
}
|
|
|
|
Generator<Instruction> ArithmeticShiftRGenerator::generate(Register::ValuePtr dest,
|
|
Register::ValuePtr value,
|
|
Register::ValuePtr shiftAmount,
|
|
Expression::ArithmeticShiftR const&)
|
|
{
|
|
AssertFatal(value != nullptr);
|
|
AssertFatal(shiftAmount != nullptr);
|
|
|
|
if(!DataTypeInfo::Get(value->variableType().getArithmeticType()).isSigned)
|
|
{
|
|
// NOTE: Do not generate arithmetic shift instructions for unsigned variables
|
|
co_yield generateOp<Expression::LogicalShiftR>(dest, value, shiftAmount);
|
|
co_return;
|
|
}
|
|
|
|
auto toShift = shiftAmount->regType() == Register::Type::Literal ? shiftAmount
|
|
: shiftAmount->subset({0});
|
|
|
|
auto resultSize = dest->variableType().getElementSize();
|
|
auto inputSize = value->variableType().getElementSize();
|
|
|
|
auto resultDWords = CeilDivide(resultSize, 4ul);
|
|
auto inputDWords = CeilDivide(inputSize, 4ul);
|
|
|
|
// We only want to do this conversion if there are more DWords in the output than the
|
|
// input. For example if we are using the shift to convert between Halfx2 and Half, both
|
|
// use only 1 DWord.
|
|
|
|
AssertFatal(resultDWords >= inputDWords,
|
|
ShowValue(dest->variableType()),
|
|
ShowValue(value->variableType()));
|
|
|
|
if(resultDWords > inputDWords)
|
|
{
|
|
AssertFatal(!dest->intersects(shiftAmount),
|
|
"Destination intersecting with shift amount not yet supported.");
|
|
co_yield generateConvertOp(dest->variableType().getArithmeticType(), dest, value);
|
|
value = dest;
|
|
}
|
|
|
|
if(dest->regType() == Register::Type::Scalar)
|
|
{
|
|
if(resultSize == 4)
|
|
{
|
|
co_yield_(Instruction("s_ashr_i32", {dest}, {value, toShift}, {}, ""));
|
|
}
|
|
else if(resultSize == 8)
|
|
{
|
|
co_yield_(Instruction("s_ashr_i64", {dest}, {value, toShift}, {}, ""));
|
|
}
|
|
else
|
|
{
|
|
Throw<FatalError>("Unsupported datatype for arithmetic shift right operation: ",
|
|
ShowValue(dest));
|
|
}
|
|
}
|
|
else if(dest->regType() == Register::Type::Vector)
|
|
{
|
|
if(resultSize == 4)
|
|
{
|
|
co_yield_(Instruction("v_ashrrev_i32", {dest}, {toShift, value}, {}, ""));
|
|
}
|
|
else if(resultSize == 8)
|
|
{
|
|
co_yield_(Instruction("v_ashrrev_i64", {dest}, {toShift, value}, {}, ""));
|
|
}
|
|
else
|
|
{
|
|
Throw<FatalError>("Unsupported datatype for arithmetic shift right operation: ",
|
|
ShowValue(dest));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Throw<FatalError>("Unsupported register type for arithmetic shift right operation: ",
|
|
ShowValue(dest));
|
|
}
|
|
}
|
|
}
|