Skip to content

Commit

Permalink
Cleanup the TernaryLogic lowering code
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Jul 8, 2024
1 parent d08dcb4 commit 2c93a18
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 212 deletions.
79 changes: 0 additions & 79 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29710,85 +29710,6 @@ unsigned GenTreeHWIntrinsic::GetResultOpNumForRmwIntrinsic(GenTree* use, GenTree

return 0;
}

//------------------------------------------------------------------------
// GetTernaryControlByte: calculate the value of the control byte for ternary node
// with given logic nodes on the input.
//
// Return value: the value of the ternary control byte.
uint8_t GenTreeHWIntrinsic::GetTernaryControlByte(GenTreeHWIntrinsic* second) const
{
// we assume we have a structure like:
/*
/- A
+- B
t1 = binary logical op1

/- C
+- t1
t2 = binary logical op2
*/

// To calculate the control byte value:
// The way the constants work is we have three keys:
// * A: 0xF0
// * B: 0xCC
// * C: 0xAA
//
// To compute the correct control byte, you simply perform the corresponding operation on these keys. So, if you
// wanted to do (A & B) ^ C, you would compute (0xF0 & 0xCC) ^ 0xAA or 0x6A.
assert(second->Op(1) == this || second->Op(2) == this);
const uint8_t A = 0xF0;
const uint8_t B = 0xCC;
const uint8_t C = 0xAA;

bool isScalar = false;

genTreeOps firstOper = GetOperForHWIntrinsicId(&isScalar);
assert(!isScalar);

genTreeOps secondOper = second->GetOperForHWIntrinsicId(&isScalar);
assert(!isScalar);

uint8_t AB = 0;
uint8_t ABC = 0;

if (firstOper == GT_AND)
{
AB = A & B;
}
else if (firstOper == GT_OR)
{
AB = A | B;
}
else if (firstOper == GT_XOR)
{
AB = A ^ B;
}
else
{
unreached();
}

if (secondOper == GT_AND)
{
ABC = AB & C;
}
else if (secondOper == GT_OR)
{
ABC = AB | C;
}
else if (secondOper == GT_XOR)
{
ABC = AB ^ C;
}
else
{
unreached();
}

return ABC;
}
#endif // TARGET_XARCH && FEATURE_HW_INTRINSICS

unsigned GenTreeLclFld::GetSize() const
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6534,7 +6534,6 @@ struct GenTreeHWIntrinsic : public GenTreeJitIntrinsic
bool OperRequiresGlobRefFlag() const;

unsigned GetResultOpNumForRmwIntrinsic(GenTree* use, GenTree* op1, GenTree* op2, GenTree* op3);
uint8_t GetTernaryControlByte(GenTreeHWIntrinsic* second) const;

ClassLayout* GetLayout(Compiler* compiler) const;

Expand Down
31 changes: 31 additions & 0 deletions src/coreclr/jit/hwintrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,37 @@ const TernaryLogicInfo& TernaryLogicInfo::lookup(uint8_t control)

return ternaryLogicFlags[control];
}

uint8_t TernaryLogicInfo::GetTernaryControlByte(genTreeOps oper, uint8_t op1, uint8_t op2)
{
switch (oper)
{
case GT_AND:
{
return static_cast<uint8_t>(op1 & op2);
}

case GT_AND_NOT:
{
return static_cast<uint8_t>(~op1 & op2);
}

case GT_OR:
{
return static_cast<uint8_t>(op1 & op2);
}

case GT_XOR:
{
return static_cast<uint8_t>(op1 & op2);
}

default:
{
unreached();
}
}
}
#endif // TARGET_XARCH

//------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/hwintrinsic.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ struct TernaryLogicInfo
TernaryLogicUseFlags oper3Use : 3;

static const TernaryLogicInfo& lookup(uint8_t control);
static uint8_t GetTernaryControlByte(genTreeOps oper, uint8_t op1, uint8_t op2);

TernaryLogicUseFlags GetAllUseFlags() const
{
Expand Down
Loading

0 comments on commit 2c93a18

Please sign in to comment.