Files
TheRock/rocm-libraries/shared/rocroller/lib/source/CodeGen/Arithmetic/BitwiseAnd.cpp
T
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

94 lines
3.6 KiB
C++

// Copyright Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <rocRoller/CodeGen/Arithmetic/ArithmeticGenerator.hpp>
#include <rocRoller/CodeGen/Arithmetic/BitwiseAnd.hpp>
#include <rocRoller/CodeGen/Arithmetic/Utility.hpp>
#include <rocRoller/CodeGen/CopyGenerator.hpp>
#include <rocRoller/Utilities/Component.hpp>
namespace rocRoller
{
template <>
std::shared_ptr<BinaryArithmeticGenerator<Expression::BitwiseAnd>>
GetGenerator<Expression::BitwiseAnd>(Register::ValuePtr dst,
Register::ValuePtr lhs,
Register::ValuePtr rhs,
Expression::BitwiseAnd const&)
{
return Component::Get<BinaryArithmeticGenerator<Expression::BitwiseAnd>>(
getContextFromValues(dst, lhs, rhs), dst->regType(), dst->variableType().dataType);
}
Generator<Instruction> BitwiseAndGenerator::generate(Register::ValuePtr dest,
Register::ValuePtr lhs,
Register::ValuePtr rhs,
Expression::BitwiseAnd const&)
{
AssertFatal(lhs != nullptr);
AssertFatal(rhs != nullptr);
auto destNumBits = DataTypeInfo::Get(dest->variableType()).elementBits;
auto lhsNumBits = DataTypeInfo::Get(lhs->variableType()).elementBits;
auto rhsNumBits = DataTypeInfo::Get(rhs->variableType()).elementBits;
auto elementBits = std::max({destNumBits, lhsNumBits, rhsNumBits});
if(dest->regType() == Register::Type::Scalar)
{
if(elementBits <= 32u)
{
co_yield_(Instruction("s_and_b32", {dest}, {lhs, rhs}, {}, ""));
}
else if(elementBits == 64u)
{
co_yield_(Instruction("s_and_b64", {dest}, {lhs, rhs}, {}, ""));
}
else
{
Throw<FatalError>("Unsupported elementBits for bitwiseAnd operation:: ",
ShowValue(elementBits));
}
}
else if(dest->regType() == Register::Type::Vector)
{
co_yield m_context->copier()->ensureTypeCommutative(
{Register::Type::Vector, Register::Type::Literal},
lhs,
{Register::Type::Vector},
rhs);
if(elementBits <= 32u)
{
co_yield_(Instruction("v_and_b32", {dest}, {lhs, rhs}, {}, ""));
}
else if(elementBits == 64u)
{
Register::ValuePtr l0, l1, r0, r1;
if(lhs->regType() == Register::Type::Scalar)
{
co_yield get2DwordsScalar(l0, l1, lhs);
}
else
{
co_yield get2DwordsVector(l0, l1, lhs);
}
co_yield get2DwordsVector(r0, r1, rhs);
co_yield_(Instruction("v_and_b32", {dest->subset({0})}, {l0, r0}, {}, ""));
co_yield_(Instruction("v_and_b32", {dest->subset({1})}, {l1, r1}, {}, ""));
}
else
{
Throw<FatalError>("Unsupported elementBits for bitwiseAnd operation:: ",
ShowValue(elementBits));
}
}
else
{
Throw<FatalError>("Unsupported register type for bitwiseAnd operation: ",
ShowValue(dest->regType()));
}
}
}