More Travis.

Fixed bug in IntUtil::isInt32().
Added possibility to disable instruction names (for static compiling).
Added ASMJIT_... wrappers also to winremoteruntime.
Fixed some instructions (wrong order in enum and x86inst.cpp).
This commit is contained in:
kobalicek
2014-06-06 22:05:52 +02:00
parent 95e9fe41d2
commit c05f11ce5c
13 changed files with 110 additions and 46 deletions

View File

@@ -4,6 +4,11 @@ compiler:
- clang - clang
- gcc - gcc
before_install:
- sudo add-apt-repository ppa:kubuntu-ppa/backports -y
- sudo apt-get update -qq
- sudo apt-get install -qq cmake
before_script: before_script:
- mkdir build - mkdir build
- cd build - cd build

View File

@@ -55,7 +55,6 @@ ASMJIT_ENUM(kInstOptions) {
//! to large displacement, in such case an error happens and the whole //! to large displacement, in such case an error happens and the whole
//! assembler/compiler stream is unusable. //! assembler/compiler stream is unusable.
kInstOptionShortForm = 0x01, kInstOptionShortForm = 0x01,
//! Emit long form of the instruction. //! Emit long form of the instruction.
//! //!
//! X86/X64: //! X86/X64:
@@ -65,9 +64,9 @@ ASMJIT_ENUM(kInstOptions) {
//! supporting both 8-bit and 32-bit immediates. //! supporting both 8-bit and 32-bit immediates.
kInstOptionLongForm = 0x02, kInstOptionLongForm = 0x02,
//! Condition is likely to be taken (instruction). //! Condition is likely to be taken.
kInstOptionTaken = 0x04, kInstOptionTaken = 0x04,
//! Condition is unlikely to be taken (instruction). //! Condition is unlikely to be taken.
kInstOptionNotTaken = 0x08 kInstOptionNotTaken = 0x08
}; };

View File

@@ -71,29 +71,61 @@ UNIT(base_intutil) {
EXPECT(IntUtil::inInterval<int>(101, 10, 20) == false, EXPECT(IntUtil::inInterval<int>(101, 10, 20) == false,
"IntUtil::inInterval<int> should return false if outside."); "IntUtil::inInterval<int> should return false if outside.");
INFO("IntUtil::isInt?()."); INFO("IntUtil::isInt8().");
EXPECT(IntUtil::isInt8<int>(-128) == true, EXPECT(IntUtil::isInt8(-128) == true,
"IntUtil::isInt8<int> should return true if >= -128."); "IntUtil::isInt8<> should return true if inside.");
EXPECT(IntUtil::isInt8<int>(127) == true, EXPECT(IntUtil::isInt8(127) == true,
"IntUtil::isInt8<int> should return true if <= 127."); "IntUtil::isInt8<> should return true if inside.");
EXPECT(IntUtil::isInt8<int>(-129) == false, EXPECT(IntUtil::isInt8(-129) == false,
"IntUtil::isInt8<int> should return false if < -128."); "IntUtil::isInt8<> should return false if outside.");
EXPECT(IntUtil::isInt8<int>(128) == false, EXPECT(IntUtil::isInt8(128) == false,
"IntUtil::isInt8<int> should return false if > 127."); "IntUtil::isInt8<> should return false if outside.");
EXPECT(IntUtil::isInt16<int>(-32768) == true, INFO("IntUtil::isUInt8().");
"IntUtil::isInt16<int> should return true if >= -32768."); EXPECT(IntUtil::isUInt8(255) == true,
EXPECT(IntUtil::isInt16<int>(32767) == true, "IntUtil::isUInt8<> should return true if inside.");
"IntUtil::isInt16<int> should return true if <= 32767."); EXPECT(IntUtil::isUInt8(256) == false,
EXPECT(IntUtil::isInt16<int>(-32769) == false, "IntUtil::isUInt8<> should return false if outside.");
"IntUtil::isInt16<int> should return false if < -32768."); EXPECT(IntUtil::isUInt8(-1) == false,
EXPECT(IntUtil::isInt16<int>(32768) == false, "IntUtil::isUInt8<> should return false if negative.");
"IntUtil::isInt16<int> should return false if > 32767.");
EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0x100000000)) == false, INFO("IntUtil::isInt16().");
EXPECT(IntUtil::isInt16(-32768) == true,
"IntUtil::isInt16<> should return true if inside.");
EXPECT(IntUtil::isInt16(32767) == true,
"IntUtil::isInt16<> should return true if inside.");
EXPECT(IntUtil::isInt16(-32769) == false,
"IntUtil::isInt16<> should return false if outside.");
EXPECT(IntUtil::isInt16(32768) == false,
"IntUtil::isInt16<> should return false if outside.");
INFO("IntUtil::isUInt16().");
EXPECT(IntUtil::isUInt16(65535) == true,
"IntUtil::isUInt16<> should return true if inside.");
EXPECT(IntUtil::isUInt16(65536) == false,
"IntUtil::isUInt16<> should return false if outside.");
EXPECT(IntUtil::isUInt16(-1) == false,
"IntUtil::isUInt16<> should return false if negative.");
INFO("IntUtil::isInt32().");
EXPECT(IntUtil::isInt32(2147483647) == true,
"IntUtil::isInt32<int> should return true if inside.");
EXPECT(IntUtil::isInt32(-2147483647 - 1) == true,
"IntUtil::isInt32<int> should return true if inside.");
EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(2147483648)) == false,
"IntUtil::isInt32<int> should return false if outside."); "IntUtil::isInt32<int> should return false if outside.");
EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0x100000000)) == false, EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0xFFFFFFFF)) == false,
"IntUtil::isInt32<int> should return false if outside."); "IntUtil::isInt32<int> should return false if outside.");
EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0xFFFFFFFF) + 1) == false,
"IntUtil::isInt32<int> should return false if outside.");
INFO("IntUtil::isUInt32().");
EXPECT(IntUtil::isUInt32(ASMJIT_UINT64_C(0xFFFFFFFF)) == true,
"IntUtil::isUInt32<int> should return true if inside.");
EXPECT(IntUtil::isUInt32(ASMJIT_UINT64_C(0xFFFFFFFF) + 1) == false,
"IntUtil::isUInt32<int> should return false if outside.");
EXPECT(IntUtil::isUInt32(-1) == false,
"IntUtil::isUInt32<int> should return false if negative.");
INFO("IntUtil::isPower2()."); INFO("IntUtil::isPower2().");
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {

View File

@@ -184,7 +184,7 @@ struct IntUtil {
template<typename T> template<typename T>
static ASMJIT_INLINE bool isInt32(T x) { static ASMJIT_INLINE bool isInt32(T x) {
if (IntTraits<T>::kIsSigned) if (IntTraits<T>::kIsSigned)
return sizeof(T) <= sizeof(int32_t) ? true : x >= T(-32768) && x <= T(32767); return sizeof(T) <= sizeof(int32_t) ? true : x >= T(-2147483647) - 1 && x <= T(2147483647);
else else
return x >= T(0) && (sizeof(T) <= sizeof(int32_t) ? true : x <= T(2147483647)); return x >= T(0) && (sizeof(T) <= sizeof(int32_t) ? true : x <= T(2147483647));
} }

View File

@@ -726,6 +726,7 @@ struct BaseMem : public Operand {
// [asmjit::BaseVar] // [asmjit::BaseVar]
// ============================================================================ // ============================================================================
#if !defined(ASMJIT_DISABLE_COMPILER)
//! Base class for all variables. //! Base class for all variables.
struct BaseVar : public Operand { struct BaseVar : public Operand {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@@ -763,6 +764,7 @@ struct BaseVar : public Operand {
ASMJIT_INLINE bool operator==(const BaseVar& other) const { return _packed[0] == other._packed[0]; } ASMJIT_INLINE bool operator==(const BaseVar& other) const { return _packed[0] == other._packed[0]; }
ASMJIT_INLINE bool operator!=(const BaseVar& other) const { return !operator==(other); } ASMJIT_INLINE bool operator!=(const BaseVar& other) const { return !operator==(other); }
}; };
#endif // !ASMJIT_DISABLE_COMPILER
// ============================================================================ // ============================================================================
// [asmjit::Imm] // [asmjit::Imm]

View File

@@ -31,6 +31,14 @@
// [Dependencies - C++] // [Dependencies - C++]
#include <new> #include <new>
// ============================================================================
// [asmjit::build - Sanity]
// ============================================================================
#if defined(ASMJIT_DISABLE_INST_NAMES) && !defined(ASMJIT_DISABLE_LOGGER)
# error "ASMJIT_DISABLE_INST_NAMES requires ASMJIT_DISABLE_LOGGER to be defined."
#endif // ASMJIT_DISABLE_INST_NAMES && !ASMJIT_DISABLE_LOGGER
// ============================================================================ // ============================================================================
// [asmjit::build - OS] // [asmjit::build - OS]
// ============================================================================ // ============================================================================

View File

@@ -40,6 +40,7 @@
// #define ASMJIT_DISABLE_COMPILER // Disable Compiler. // #define ASMJIT_DISABLE_COMPILER // Disable Compiler.
// #define ASMJIT_DISABLE_LOGGER // Disable Logger (completely). // #define ASMJIT_DISABLE_LOGGER // Disable Logger (completely).
// #define ASMJIT_DISABLE_INST_NAMES // Disable Instruction names (and API).
// [Guard] // [Guard]
#endif // _ASMJIT_CONFIG_H #endif // _ASMJIT_CONFIG_H

View File

@@ -44,7 +44,7 @@ uint32_t WinRemoteRuntime::add(void** dest, BaseAssembler* assembler) {
} }
// Allocate temporary memory where the code will be stored and relocated. // Allocate temporary memory where the code will be stored and relocated.
void* codeData = ::malloc(codeSize); void* codeData = ASMJIT_ALLOC(codeSize);
if (codeData == NULL) { if (codeData == NULL) {
*dest = NULL; *dest = NULL;
@@ -55,7 +55,7 @@ uint32_t WinRemoteRuntime::add(void** dest, BaseAssembler* assembler) {
void* processMemPtr = _memMgr.alloc(codeSize, kVMemAllocPermanent); void* processMemPtr = _memMgr.alloc(codeSize, kVMemAllocPermanent);
if (processMemPtr == NULL) { if (processMemPtr == NULL) {
::free(codeData); ASMJIT_FREE(codeData);
*dest = NULL; *dest = NULL;
return kErrorNoVirtualMemory; return kErrorNoVirtualMemory;
} }
@@ -64,7 +64,7 @@ uint32_t WinRemoteRuntime::add(void** dest, BaseAssembler* assembler) {
assembler->relocCode(codeData, (uintptr_t)processMemPtr); assembler->relocCode(codeData, (uintptr_t)processMemPtr);
::WriteProcessMemory(getProcessHandle(), processMemPtr, codeData, codeSize, NULL); ::WriteProcessMemory(getProcessHandle(), processMemPtr, codeData, codeSize, NULL);
::free(codeData); ASMJIT_FREE(codeData);
*dest = processMemPtr; *dest = processMemPtr;
return kErrorOk; return kErrorOk;

View File

@@ -130,7 +130,6 @@ static void dumpSizeOf() {
INFO("SizeOf Base:"); INFO("SizeOf Base:");
DUMP_SIZE(asmjit::CodeGen); DUMP_SIZE(asmjit::CodeGen);
DUMP_SIZE(asmjit::ConstPool); DUMP_SIZE(asmjit::ConstPool);
DUMP_SIZE(asmjit::Logger);
DUMP_SIZE(asmjit::Runtime); DUMP_SIZE(asmjit::Runtime);
DUMP_SIZE(asmjit::Zone); DUMP_SIZE(asmjit::Zone);
INFO(""); INFO("");
@@ -150,6 +149,7 @@ static void dumpSizeOf() {
DUMP_SIZE(asmjit::RelocData); DUMP_SIZE(asmjit::RelocData);
INFO(""); INFO("");
#if !defined(ASMJIT_DISABLE_COMPILER)
INFO("SizeOf Compiler:"); INFO("SizeOf Compiler:");
DUMP_SIZE(asmjit::BaseCompiler); DUMP_SIZE(asmjit::BaseCompiler);
DUMP_SIZE(asmjit::Node); DUMP_SIZE(asmjit::Node);
@@ -170,6 +170,7 @@ static void dumpSizeOf() {
DUMP_SIZE(asmjit::BaseVarInst); DUMP_SIZE(asmjit::BaseVarInst);
DUMP_SIZE(asmjit::BaseVarState); DUMP_SIZE(asmjit::BaseVarState);
INFO(""); INFO("");
#endif // !ASMJIT_DISABLE_COMPILER
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// [X86/X64] // [X86/X64]

View File

@@ -24,6 +24,7 @@ namespace x86x64 {
// [asmjit::x86x64::Inst] // [asmjit::x86x64::Inst]
// ============================================================================ // ============================================================================
#if !defined(ASMJIT_DISABLE_INST_NAMES)
// Autogenerated by src-gendefs.js: // Autogenerated by src-gendefs.js:
// //
// ${kInstData:Begin} // ${kInstData:Begin}
@@ -2127,9 +2128,16 @@ enum kInstData_NameIndex {
kInstXorps_NameIndex = 8133 kInstXorps_NameIndex = 8133
}; };
// ${kInstData:End} // ${kInstData:End}
#endif // !ASMJIT_DISABLE_INST_NAMES
#if !defined(ASMJIT_DISABLE_INST_NAMES)
# define INST_NAME_INDEX(_Code_) _Code_##_NameIndex
#else
# define INST_NAME_INDEX(_Code_) 0
#endif
#define INST(_Code_, _Name_, _Group_, _Flags_, _MoveSize_, _OpFlags0_, _OpFlags1_, _OpFlags2_, _OpFlags3_, _OpCode0_, _OpCode1_) \ #define INST(_Code_, _Name_, _Group_, _Flags_, _MoveSize_, _OpFlags0_, _OpFlags1_, _OpFlags2_, _OpFlags3_, _OpCode0_, _OpCode1_) \
{ _Code_##_NameIndex, _Flags_, _Group_, _MoveSize_, { 0, 0 }, { _OpFlags0_, _OpFlags1_, _OpFlags2_, _OpFlags3_ }, { _OpCode0_, _OpCode1_ } } { INST_NAME_INDEX(_Code_), _Flags_, _Group_, _MoveSize_, { 0, 0 }, { _OpFlags0_, _OpFlags1_, _OpFlags2_, _OpFlags3_ }, { _OpCode0_, _OpCode1_ } }
#define G(_Group_) kInstGroup##_Group_ #define G(_Group_) kInstGroup##_Group_
#define F(_Flags_) kInstFlag##_Flags_ #define F(_Flags_) kInstFlag##_Flags_
@@ -3247,6 +3255,7 @@ const InstInfo _instInfo[] = {
// [asmjit::x86x64::X86Util] // [asmjit::x86x64::X86Util]
// ============================================================================ // ============================================================================
#if !defined(ASMJIT_DISABLE_INST_NAMES)
// Compare two instruction names. // Compare two instruction names.
// //
// `a` is null terminated instruction name from `_instName[]` table. // `a` is null terminated instruction name from `_instName[]` table.
@@ -3323,12 +3332,13 @@ uint32_t X86InstUtil::getInstIdByName(const char* name, size_t len) {
return kInstNone; return kInstNone;
} }
#endif // ASMJIT_DISABLE_INST_NAMES
// ============================================================================ // ============================================================================
// [asmjit::x86x64::X86Util - Test] // [asmjit::x86x64::X86Util - Test]
// ============================================================================ // ============================================================================
#if defined(ASMJIT_TEST) #if defined(ASMJIT_TEST) && !defined(ASMJIT_DISABLE_INST_NAMES)
UNIT(x86_inst_name) { UNIT(x86_inst_name) {
// All known instructions should be matched. // All known instructions should be matched.
for (uint32_t a = 0; a < _kInstCount; a++) { for (uint32_t a = 0; a < _kInstCount; a++) {
@@ -3353,7 +3363,7 @@ UNIT(x86_inst_name) {
EXPECT(X86InstUtil::getInstIdByName("123xyz") == kInstNone, EXPECT(X86InstUtil::getInstIdByName("123xyz") == kInstNone,
"Should return kInstNone for unknown instruction."); "Should return kInstNone for unknown instruction.");
} }
#endif // ASMJIT_TEST #endif // ASMJIT_TEST && !ASMJIT_DISABLE_INST_NAMES
} // x86x64 namespace } // x86x64 namespace
} // asmjit namespace } // asmjit namespace

View File

@@ -35,10 +35,12 @@ struct InstInfo;
// [asmjit::x86x64::Inst/Cond - Globals] // [asmjit::x86x64::Inst/Cond - Globals]
// ============================================================================ // ============================================================================
#if !defined(ASMJIT_DISABLE_INST_NAMES)
//! \internal //! \internal
//! //!
//! X86/X64 instructions' names. //! X86/X64 instructions' names.
ASMJIT_VAR const char _instName[]; ASMJIT_VAR const char _instName[];
#endif // !ASMJIT_DISABLE_INST_NAMES
//! \internal //! \internal
//! //!
@@ -725,14 +727,14 @@ ASMJIT_ENUM(kInstCode) {
kInstVfmaddps, // FMA4 kInstVfmaddps, // FMA4
kInstVfmaddsd, // FMA4 kInstVfmaddsd, // FMA4
kInstVfmaddss, // FMA4 kInstVfmaddss, // FMA4
kInstVfmaddsubpd, // FMA4
kInstVfmaddsubps, // FMA4
kInstVfmaddsub132pd, // FMA3 kInstVfmaddsub132pd, // FMA3
kInstVfmaddsub132ps, // FMA3 kInstVfmaddsub132ps, // FMA3
kInstVfmaddsub213pd, // FMA3 kInstVfmaddsub213pd, // FMA3
kInstVfmaddsub213ps, // FMA3 kInstVfmaddsub213ps, // FMA3
kInstVfmaddsub231pd, // FMA3 kInstVfmaddsub231pd, // FMA3
kInstVfmaddsub231ps, // FMA3 kInstVfmaddsub231ps, // FMA3
kInstVfmaddsubpd, // FMA4
kInstVfmaddsubps, // FMA4
kInstVfmsub132pd, // FMA3 kInstVfmsub132pd, // FMA3
kInstVfmsub132ps, // FMA3 kInstVfmsub132ps, // FMA3
kInstVfmsub132sd, // FMA3 kInstVfmsub132sd, // FMA3
@@ -745,14 +747,14 @@ ASMJIT_ENUM(kInstCode) {
kInstVfmsub231ps, // FMA3 kInstVfmsub231ps, // FMA3
kInstVfmsub231sd, // FMA3 kInstVfmsub231sd, // FMA3
kInstVfmsub231ss, // FMA3 kInstVfmsub231ss, // FMA3
kInstVfmsubaddpd, // FMA4
kInstVfmsubaddps, // FMA4
kInstVfmsubadd132pd, // FMA3 kInstVfmsubadd132pd, // FMA3
kInstVfmsubadd132ps, // FMA3 kInstVfmsubadd132ps, // FMA3
kInstVfmsubadd213pd, // FMA3 kInstVfmsubadd213pd, // FMA3
kInstVfmsubadd213ps, // FMA3 kInstVfmsubadd213ps, // FMA3
kInstVfmsubadd231pd, // FMA3 kInstVfmsubadd231pd, // FMA3
kInstVfmsubadd231ps, // FMA3 kInstVfmsubadd231ps, // FMA3
kInstVfmsubaddpd, // FMA4
kInstVfmsubaddps, // FMA4
kInstVfmsubpd, // FMA4 kInstVfmsubpd, // FMA4
kInstVfmsubps, // FMA4 kInstVfmsubps, // FMA4
kInstVfmsubsd, // FMA4 kInstVfmsubsd, // FMA4
@@ -1383,7 +1385,7 @@ ASMJIT_ENUM(kInstOpCode) {
kInstOpCode_PP_66 = 0x01U << kInstOpCode_PP_Shift, kInstOpCode_PP_66 = 0x01U << kInstOpCode_PP_Shift,
kInstOpCode_PP_F3 = 0x02U << kInstOpCode_PP_Shift, kInstOpCode_PP_F3 = 0x02U << kInstOpCode_PP_Shift,
kInstOpCode_PP_F2 = 0x03U << kInstOpCode_PP_Shift, kInstOpCode_PP_F2 = 0x03U << kInstOpCode_PP_Shift,
kInstOpCode_PP_9B = 0x07U << kInstOpCode_PP_Shift, //Ext/Not part of AVX. kInstOpCode_PP_9B = 0x07U << kInstOpCode_PP_Shift, // Ext/Not part of AVX.
// 'L' field in AVX/XOP instruction. // 'L' field in AVX/XOP instruction.
kInstOpCode_L_Shift = 24, kInstOpCode_L_Shift = 24,
@@ -1706,6 +1708,7 @@ struct InstInfo {
// [Accessors] // [Accessors]
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#if !defined(ASMJIT_DISABLE_INST_NAMES)
//! Get instruction name string (null terminated). //! Get instruction name string (null terminated).
ASMJIT_INLINE const char* getName() const { ASMJIT_INLINE const char* getName() const {
return _instName + static_cast<uint32_t>(_nameIndex); return _instName + static_cast<uint32_t>(_nameIndex);
@@ -1715,6 +1718,7 @@ struct InstInfo {
ASMJIT_INLINE uint32_t _getNameIndex() const { ASMJIT_INLINE uint32_t _getNameIndex() const {
return _nameIndex; return _nameIndex;
} }
#endif // !ASMJIT_DISABLE_INST_NAMES
//! Get instruction group, see `kInstGroup`. //! Get instruction group, see `kInstGroup`.
ASMJIT_INLINE uint32_t getGroup() const { ASMJIT_INLINE uint32_t getGroup() const {
@@ -1828,6 +1832,7 @@ struct InstInfo {
// ============================================================================ // ============================================================================
struct X86InstUtil { struct X86InstUtil {
#if !defined(ASMJIT_DISABLE_INST_NAMES)
//! Get an instruction ID from a given instruction `name`. //! Get an instruction ID from a given instruction `name`.
//! //!
//! If there is an exact match the instruction id is returned, otherwise //! If there is an exact match the instruction id is returned, otherwise
@@ -1836,6 +1841,7 @@ struct X86InstUtil {
//! The given `name` doesn't have to be null-terminated if `len` is provided. //! The given `name` doesn't have to be null-terminated if `len` is provided.
ASMJIT_API static uint32_t getInstIdByName( ASMJIT_API static uint32_t getInstIdByName(
const char* name, size_t len = kInvalidIndex); const char* name, size_t len = kInvalidIndex);
#endif // !ASMJIT_DISABLE_INST_NAMES
}; };
//! \} //! \}

View File

@@ -938,7 +938,7 @@ struct X86Var : public BaseVar {
// [Memory Cast] // [Memory Cast]
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
//! Cast this variable to memory operand. //! Cast this variable to a memory operand.
//! //!
//! \note Size of operand depends on native variable type, you can use other //! \note Size of operand depends on native variable type, you can use other
//! variants if you want specific one. //! variants if you want specific one.