Skip to content

Commit 2c93a18

Browse files
committed
Cleanup the TernaryLogic lowering code
1 parent d08dcb4 commit 2c93a18

File tree

5 files changed

+169
-212
lines changed

5 files changed

+169
-212
lines changed

src/coreclr/jit/gentree.cpp

-79
Original file line numberDiff line numberDiff line change
@@ -29710,85 +29710,6 @@ unsigned GenTreeHWIntrinsic::GetResultOpNumForRmwIntrinsic(GenTree* use, GenTree
2971029710

2971129711
return 0;
2971229712
}
29713-
29714-
//------------------------------------------------------------------------
29715-
// GetTernaryControlByte: calculate the value of the control byte for ternary node
29716-
// with given logic nodes on the input.
29717-
//
29718-
// Return value: the value of the ternary control byte.
29719-
uint8_t GenTreeHWIntrinsic::GetTernaryControlByte(GenTreeHWIntrinsic* second) const
29720-
{
29721-
// we assume we have a structure like:
29722-
/*
29723-
/- A
29724-
+- B
29725-
t1 = binary logical op1
29726-
29727-
/- C
29728-
+- t1
29729-
t2 = binary logical op2
29730-
*/
29731-
29732-
// To calculate the control byte value:
29733-
// The way the constants work is we have three keys:
29734-
// * A: 0xF0
29735-
// * B: 0xCC
29736-
// * C: 0xAA
29737-
//
29738-
// To compute the correct control byte, you simply perform the corresponding operation on these keys. So, if you
29739-
// wanted to do (A & B) ^ C, you would compute (0xF0 & 0xCC) ^ 0xAA or 0x6A.
29740-
assert(second->Op(1) == this || second->Op(2) == this);
29741-
const uint8_t A = 0xF0;
29742-
const uint8_t B = 0xCC;
29743-
const uint8_t C = 0xAA;
29744-
29745-
bool isScalar = false;
29746-
29747-
genTreeOps firstOper = GetOperForHWIntrinsicId(&isScalar);
29748-
assert(!isScalar);
29749-
29750-
genTreeOps secondOper = second->GetOperForHWIntrinsicId(&isScalar);
29751-
assert(!isScalar);
29752-
29753-
uint8_t AB = 0;
29754-
uint8_t ABC = 0;
29755-
29756-
if (firstOper == GT_AND)
29757-
{
29758-
AB = A & B;
29759-
}
29760-
else if (firstOper == GT_OR)
29761-
{
29762-
AB = A | B;
29763-
}
29764-
else if (firstOper == GT_XOR)
29765-
{
29766-
AB = A ^ B;
29767-
}
29768-
else
29769-
{
29770-
unreached();
29771-
}
29772-
29773-
if (secondOper == GT_AND)
29774-
{
29775-
ABC = AB & C;
29776-
}
29777-
else if (secondOper == GT_OR)
29778-
{
29779-
ABC = AB | C;
29780-
}
29781-
else if (secondOper == GT_XOR)
29782-
{
29783-
ABC = AB ^ C;
29784-
}
29785-
else
29786-
{
29787-
unreached();
29788-
}
29789-
29790-
return ABC;
29791-
}
2979229713
#endif // TARGET_XARCH && FEATURE_HW_INTRINSICS
2979329714

2979429715
unsigned GenTreeLclFld::GetSize() const

src/coreclr/jit/gentree.h

-1
Original file line numberDiff line numberDiff line change
@@ -6534,7 +6534,6 @@ struct GenTreeHWIntrinsic : public GenTreeJitIntrinsic
65346534
bool OperRequiresGlobRefFlag() const;
65356535

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

65396538
ClassLayout* GetLayout(Compiler* compiler) const;
65406539

src/coreclr/jit/hwintrinsic.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,37 @@ const TernaryLogicInfo& TernaryLogicInfo::lookup(uint8_t control)
352352

353353
return ternaryLogicFlags[control];
354354
}
355+
356+
uint8_t TernaryLogicInfo::GetTernaryControlByte(genTreeOps oper, uint8_t op1, uint8_t op2)
357+
{
358+
switch (oper)
359+
{
360+
case GT_AND:
361+
{
362+
return static_cast<uint8_t>(op1 & op2);
363+
}
364+
365+
case GT_AND_NOT:
366+
{
367+
return static_cast<uint8_t>(~op1 & op2);
368+
}
369+
370+
case GT_OR:
371+
{
372+
return static_cast<uint8_t>(op1 & op2);
373+
}
374+
375+
case GT_XOR:
376+
{
377+
return static_cast<uint8_t>(op1 & op2);
378+
}
379+
380+
default:
381+
{
382+
unreached();
383+
}
384+
}
385+
}
355386
#endif // TARGET_XARCH
356387

357388
//------------------------------------------------------------------------

src/coreclr/jit/hwintrinsic.h

+1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ struct TernaryLogicInfo
480480
TernaryLogicUseFlags oper3Use : 3;
481481

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

484485
TernaryLogicUseFlags GetAllUseFlags() const
485486
{

0 commit comments

Comments
 (0)