Skip to content

Commit

Permalink
Merge pull request eclipse#936 from liqunl/ibyteswap
Browse files Browse the repository at this point in the history
Add opcode ibyteswap and X86 evaluator
  • Loading branch information
vijaysun-omr committed Mar 31, 2017
2 parents 024b135 + 296a66c commit ce78c84
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/arm/codegen/TreeEvaluatorTable.hpp
Expand Up @@ -917,4 +917,6 @@
TR::TreeEvaluator::longNumberOfTrailingZeros,
TR::TreeEvaluator::longBitCount,

TR::TreeEvaluator::unImpOpEvaluator, // TR::ibyteswap

TR::TreeEvaluator::NOPEvaluator, // Temporarily using for TR::Prefetch
15 changes: 15 additions & 0 deletions compiler/codegen/OMRCodeGenerator.cpp
Expand Up @@ -1038,6 +1038,21 @@ OMR::CodeGenerator::getSupportsTLE()
return self()->getSupportsTM();
}

/** \brief
* A query about whether ibyteswap is supported
*
* \return
* True if ibyteswap is supported in codegen
*
* \note
* Override the query on the platform where ibyteswap is implemented
*/
bool
OMR::CodeGenerator::getSupportsIbyteswap()
{
return false;
}

bool
OMR::CodeGenerator::getSupportsConstantOffsetInAddressing(int64_t value)
{
Expand Down
2 changes: 2 additions & 0 deletions compiler/codegen/OMRCodeGenerator.hpp
Expand Up @@ -1533,6 +1533,8 @@ class OMR_EXTENSIBLE CodeGenerator

virtual bool getSupportsTLE();

virtual bool getSupportsIbyteswap();

bool getSupportsAutoSIMD() { return _flags4.testAny(SupportsAutoSIMD);}
void setSupportsAutoSIMD() { _flags4.set(SupportsAutoSIMD);}

Expand Down
15 changes: 15 additions & 0 deletions compiler/il/ILOpCodeProperties.hpp
Expand Up @@ -10936,6 +10936,21 @@
/* .ifCompareOpCode = */ TR::BadILOp,
},

{
/* .opcode = */ TR::ibyteswap,
/* .name = */ "ibyteswap",
/* .properties1 = */ 0,
/* .properties2 = */ ILProp2::ValueNumberShare | ILProp2::SupportedForPRE | ILProp2::ByteSwap,
/* .properties3 = */ 0,
/* .properties4 = */ 0,
/* .dataType = */ TR::Int32,
/* .typeProperties = */ ILTypeProp::Size_4 | ILTypeProp::Integer,
/* .swapChildrenOpCode = */ TR::BadILOp,
/* .reverseBranchOpCode = */ TR::BadILOp,
/* .booleanCompareOpCode = */ TR::BadILOp,
/* .ifCompareOpCode = */ TR::BadILOp,
},

{
/* .opcode = */ TR::Prefetch,
/* .name = */ "Prefetch",
Expand Down
2 changes: 1 addition & 1 deletion compiler/il/ILProps.hpp
Expand Up @@ -119,7 +119,7 @@ namespace ILProp2
New = 0x00800000, // object allocation opcodes
ZeroExtension = 0x01000000,
SignExtension = 0x02000000,
// Available = 0x04000000,
ByteSwap = 0x04000000,
// Available = 0x08000000,
// Available = 0x10000000,
// Available = 0x20000000,
Expand Down
2 changes: 2 additions & 0 deletions compiler/il/OMRILOpCodesEnum.hpp
Expand Up @@ -822,6 +822,8 @@
lnotz,
lpopcnt,

ibyteswap,// swap bytes in an integer

Prefetch, // Prefetch


Expand Down
3 changes: 3 additions & 0 deletions compiler/optimizer/OMRSimplifierTableEnum.hpp
Expand Up @@ -114,6 +114,7 @@
bnegSimplifier, // TR::bneg
snegSimplifier, // TR::sneg


iabsSimplifier, // TR::iabs
labsSimplifier, // TR::labs
dftSimplifier, // TR::fabs todo
Expand Down Expand Up @@ -797,6 +798,8 @@
dftSimplifier, //TR::lnotz
dftSimplifier, //TR::lpopcnt

dftSimplifier, // TR::ibyteswap

dftSimplifier, // TR::Prefetch

#endif
2 changes: 2 additions & 0 deletions compiler/optimizer/ValuePropagationTable.hpp
Expand Up @@ -938,6 +938,8 @@ const ValuePropagationPtr constraintHandlers[] =
constrainLongNumberOfTrailingZeros,
constrainLongBitCount,

constrainChildren, // TR::ibyteswap

constrainChildren, // TR::Prefetch

#ifdef J9_PROJECT_SPECIFIC
Expand Down
1 change: 1 addition & 0 deletions compiler/p/codegen/TreeEvaluatorTable.hpp
Expand Up @@ -747,4 +747,5 @@
TR::TreeEvaluator::longNumberOfLeadingZeros, // TR::lnolz (J9)
TR::TreeEvaluator::longNumberOfTrailingZeros, // TR::lnotz (J9)
TR::TreeEvaluator::longBitCount, // TR::lpopcnt (J9)
TR::TreeEvaluator::unImpOpEvaluator, // TR::ibyteswap
TR::TreeEvaluator::PrefetchEvaluator, // TR::Prefetch
1 change: 1 addition & 0 deletions compiler/x/amd64/codegen/TreeEvaluatorTable.hpp
Expand Up @@ -746,4 +746,5 @@
TR::TreeEvaluator::badILOpEvaluator, // TR::lnolz (J9)
TR::TreeEvaluator::badILOpEvaluator, // TR::lnotz (J9)
TR::TreeEvaluator::badILOpEvaluator, // TR::lpopcnt (J9)
TR::TreeEvaluator::ibyteswapEvaluator, // TR::ibyteswap
TR::TreeEvaluator::PrefetchEvaluator, // TR::Prefetch
6 changes: 6 additions & 0 deletions compiler/x/codegen/OMRCodeGenerator.cpp
Expand Up @@ -1024,6 +1024,12 @@ OMR::X86::CodeGenerator::getSupportsEncodeUtf16BigWithSurrogateTest()
!self()->comp()->getOptions()->getOption(TR_DisableSIMDUTF16BEEncoder);
}

bool
OMR::X86::CodeGenerator::getSupportsIbyteswap()
{
return true;
}

bool
OMR::X86::CodeGenerator::supportsMergingOfHCRGuards()
{
Expand Down
2 changes: 2 additions & 0 deletions compiler/x/codegen/OMRCodeGenerator.hpp
Expand Up @@ -293,6 +293,8 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator
bool getSupportsEncodeUtf16LittleWithSurrogateTest();
bool getSupportsEncodeUtf16BigWithSurrogateTest();

virtual bool getSupportsIbyteswap();

bool supportsMergingOfHCRGuards();

bool supportsAtomicAdd() {return true;}
Expand Down
13 changes: 13 additions & 0 deletions compiler/x/codegen/OMRTreeEvaluator.cpp
Expand Up @@ -5240,3 +5240,16 @@ OMR::X86::TreeEvaluator::VMifArrayCmpEvaluator(TR::Node*, TR::CodeGenerator*)
{
return 0;
}

TR::Register *
OMR::X86::TreeEvaluator::ibyteswapEvaluator(TR::Node *node, TR::CodeGenerator *cg)
{
TR_ASSERT(node->getNumChildren() == 1, "Wrong number of children in byteswapEvaluator");
TR::Node *child = node->getFirstChild();
bool nodeIs64Bit = TR::TreeEvaluator::getNodeIs64Bit(child, cg);
TR::Register *target = TR::TreeEvaluator::intOrLongClobberEvaluate(child, nodeIs64Bit, cg);
generateRegInstruction(BSWAPReg(nodeIs64Bit), node, target, cg);
node->setRegister(target);
cg->decReferenceCount(child);
return target;
}
1 change: 1 addition & 0 deletions compiler/x/codegen/OMRTreeEvaluator.hpp
Expand Up @@ -230,6 +230,7 @@ class OMR_EXTENSIBLE TreeEvaluator: public OMR::TreeEvaluator
static TR::Register *compressStringEvaluator(TR::Node *node, TR::CodeGenerator *cg, bool japaneseMethod);
static TR::Register *compressStringNoCheckEvaluator(TR::Node *node, TR::CodeGenerator *cg, bool japaneseMethod);
static TR::Register *andORStringEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *ibyteswapEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *PrefetchEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *BBStartEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *BBEndEvaluator(TR::Node *node, TR::CodeGenerator *cg);
Expand Down
1 change: 1 addition & 0 deletions compiler/x/i386/codegen/TreeEvaluatorTable.hpp
Expand Up @@ -749,4 +749,5 @@
TR::TreeEvaluator::badILOpEvaluator, // TR::lnolz (J9)
TR::TreeEvaluator::badILOpEvaluator, // TR::lnotz (J9)
TR::TreeEvaluator::badILOpEvaluator, // TR::lpopcnt (J9)
TR::TreeEvaluator::ibyteswapEvaluator, // TR::ibyteswap
TR::TreeEvaluator::PrefetchEvaluator, // TR::Prefetch
2 changes: 2 additions & 0 deletions compiler/z/codegen/TreeEvaluatorTable.hpp
Expand Up @@ -803,5 +803,7 @@
TR::TreeEvaluator::longNumberOfTrailingZeros, // TR::lnotz (J9)
TR::TreeEvaluator::longBitCount, // TR::lpopcnt

TR::TreeEvaluator::unImpOpEvaluator, // TR::ibyteswap

TR::TreeEvaluator::PrefetchEvaluator, // TR::Prefetch

1 change: 1 addition & 0 deletions fvtest/compilertest/tests/OpCodesTest.cpp
Expand Up @@ -158,6 +158,7 @@ TR::DataType OpCodesTest::_argTypesBinaryAddressFloat[_numberOfBinaryArgs] = {TR
TR::DataType OpCodesTest::_argTypesBinaryAddressDouble[_numberOfBinaryArgs] = {TR::Address, TR::Double};
TR::DataType OpCodesTest::_argTypesBinaryAddressAddress[_numberOfBinaryArgs] = {TR::Address, TR::Address};

signatureCharI_I_testMethodType * OpCodesTest::_iByteswap = 0;
//Neg
signatureCharB_B_testMethodType * OpCodesTest::_bNeg = 0;
signatureCharS_S_testMethodType * OpCodesTest::_sNeg = 0;
Expand Down
8 changes: 8 additions & 0 deletions fvtest/compilertest/tests/OpCodesTest.hpp
Expand Up @@ -290,6 +290,7 @@ class OpCodesTest : public TestDriver
static const uintptrj_t ADDRESS_PLACEHOLDER_3;

protected:
static signatureCharI_I_testMethodType *_iByteswap;
//Neg
static signatureCharB_B_testMethodType *_bNeg;
static signatureCharS_S_testMethodType *_sNeg;
Expand Down Expand Up @@ -692,6 +693,13 @@ class OpCodesTest : public TestDriver
static TR::DataType _argTypesBinaryAddressAddress[_numberOfBinaryArgs];

// straight C(++) implementations of testMethodType for initial test validation purposes
uint16_t byteswap(uint16_t a) { return (((a & 0xff) << 8) | ((a & 0xff00) >> 8));}
uint32_t byteswap(uint32_t a) { return (uint32_t)byteswap(uint16_t(a & 0xffff)) << 16 | (uint32_t)byteswap(uint16_t((a >> 16) & 0xffff)); }
uint64_t byteswap(uint64_t a) { return (uint64_t)byteswap(uint32_t(a & 0xffffffff)) << 32 | (uint64_t)byteswap(uint32_t((a >> 32) & 0xffffffff)); }
int16_t byteswap(int16_t a) { return byteswap((uint16_t)a); }
int32_t byteswap(int32_t a) { return byteswap((uint32_t)a); }
int64_t byteswap(int64_t a) { return byteswap((uint64_t)a); }

template <typename T> static T neg(T a) { return -a;}
template <typename T> static T abs(T a) { return a >= (T) 0 ? a : -a;}

Expand Down
13 changes: 13 additions & 0 deletions fvtest/compilertest/tests/X86OpCodesTest.cpp
Expand Up @@ -135,6 +135,7 @@ X86OpCodesTest::compileUnaryTestMethods()
_su2l = (unsignedSignatureCharS_J_testMethodType *) (compileOpCodeMethod(_numberOfUnaryArgs, TR::su2l, "su2l", _argTypesUnaryShort, TR::Int64, rc));
_su2f = (unsignedSignatureCharS_F_testMethodType *) (compileOpCodeMethod(_numberOfUnaryArgs, TR::su2f, "su2f", _argTypesUnaryShort, TR::Float, rc));
_su2d = (unsignedSignatureCharS_D_testMethodType *) (compileOpCodeMethod(_numberOfUnaryArgs, TR::su2d, "su2d", _argTypesUnaryShort, TR::Double, rc));
_iByteswap = (signatureCharI_I_testMethodType *) (compileOpCodeMethod(_numberOfUnaryArgs, TR::ibyteswap, "iByteswap", _argTypesUnaryInt, TR::Int32, rc));
}

void
Expand Down Expand Up @@ -1730,6 +1731,7 @@ X86OpCodesTest::invokeUnaryTests()
uint32_t testCaseNum = 0;
char resolvedMethodName [RESOLVED_METHOD_NAME_LENGTH];

signatureCharI_I_testMethodType * iUnaryCons = 0;
signatureCharS_S_testMethodType * sUnaryCons = 0;
signatureCharB_B_testMethodType * bUnaryCons = 0;
signatureCharJ_J_testMethodType *lUnaryCons = 0;
Expand Down Expand Up @@ -2130,6 +2132,17 @@ X86OpCodesTest::invokeUnaryTests()
resolvedMethodName, _argTypesUnaryInt, TR::Int64, rc, 2, 1, &uintDataArray[i]));
OMR_CT_EXPECT_EQ(iu2lConst, convert(uintDataArray[i], LONG_POS), iu2lConst(INT_PLACEHOLDER_1));
}

//ibyteswap
testCaseNum = sizeof(intDataArray) / sizeof(intDataArray[0]);
for (uint32_t i = 0; i < testCaseNum; ++i)
{
OMR_CT_EXPECT_EQ(_iByteswap, byteswap(intDataArray[i]), _iByteswap(intDataArray[i]));
sprintf(resolvedMethodName, "iByteswapConst%d", i + 1);
iUnaryCons = (signatureCharI_I_testMethodType *) (compileOpCodeMethod(_numberOfUnaryArgs, TR::ibyteswap,
resolvedMethodName, _argTypesUnaryInt, TR::Int32, rc, 2, 1, &intDataArray[i]));
OMR_CT_EXPECT_EQ(iUnaryCons, byteswap(intDataArray[i]), iUnaryCons(INT_PLACEHOLDER_1));
}
}

void
Expand Down

0 comments on commit ce78c84

Please sign in to comment.