Commit 01da1b51 authored by peastman's avatar peastman
Browse files

Updated to latest asmjit, which supports 32 bit mode

parent 26790496
......@@ -274,14 +274,12 @@ ELSE (ANDROID OR PNACL)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/libraries/sfmt/src/SFMT.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_SSE2=1")
ENDIF(ANDROID OR PNACL)
IF (NOT (ANDROID OR PNACL))
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
FILE(GLOB src_files ${CMAKE_CURRENT_SOURCE_DIR}/libraries/asmjit/*/*.cpp)
FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/libraries/asmjit/*.h)
SET(SOURCE_FILES ${SOURCE_FILES} ${src_files})
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/libraries/asmjit")
SET(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DLEPTON_USE_JIT")
ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 8)
ENDIF (NOT (ANDROID OR PNACL))
# If API wrappers are being generated, and add them to the build.
......
......@@ -4,12 +4,38 @@
// [License]
// Zlib - See LICENSE.md file in the package.
// [Dependencies - AsmJit]
#if !defined(_ASMJIT_BUILD_H)
#include "build.h"
#endif // !_ASMJIT_BUILD_H
// [Guard]
#if !defined(ASMJIT_API_SCOPE)
# define ASMJIT_API_SCOPE
#else
# error "AsmJit - Api-Scope is already active, previous scope not closed by apiend.h?"
#endif // ASMJIT_API_SCOPE
// ============================================================================
// [MSVC]
// [Override]
// ============================================================================
#if !defined(ASMJIT_CC_HAS_OVERRIDE) && !defined(override)
# define override
# define ASMJIT_UNDEF_OVERRIDE
#endif // !ASMJIT_CC_HAS_OVERRIDE && !override
// ============================================================================
// [NoExcept]
// ============================================================================
#if !defined(ASMJIT_CC_HAS_NOEXCEPT) && !defined(noexcept)
# define noexcept ASMJIT_NOEXCEPT
# define ASMJIT_UNDEF_NOEXCEPT
#endif // !ASMJIT_CC_HAS_NOEXCEPT && !noexcept
// ============================================================================
// [MSC]
// ============================================================================
#if defined(_MSC_VER)
......@@ -29,21 +55,30 @@
// Rename symbols.
# if !defined(vsnprintf)
# define ASMJIT_DEFINED_VSNPRINTF
# define ASMJIT_UNDEF_VSNPRINTF
# define vsnprintf _vsnprintf
# endif // !vsnprintf
# if !defined(snprintf)
# define ASMJIT_DEFINED_SNPRINTF
# define ASMJIT_UNDEF_SNPRINTF
# define snprintf _snprintf
# endif // !snprintf
#endif // _MSC_VER
// ============================================================================
// [GNUC]
// [CLang]
// ============================================================================
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunnamed-type-template-args"
#endif // __clang__
// ============================================================================
// [GCC]
// ============================================================================
#if defined(__GNUC__) && !defined(__clang__)
# if __GNUC__ >= 4 && !defined(__MINGW32__)
# pragma GCC visibility push(hidden)
# endif // __GNUC__ >= 4
# endif // GCC 4+
#endif // __GNUC__
......@@ -4,30 +4,64 @@
// [License]
// Zlib - See LICENSE.md file in the package.
// [Guard]
#if defined(ASMJIT_API_SCOPE)
# undef ASMJIT_API_SCOPE
#else
# error "AsmJit - Api-Scope not active, forgot to include apibegin.h?"
#endif // ASMJIT_API_SCOPE
// ============================================================================
// [Override]
// ============================================================================
#if defined(ASMJIT_UNDEF_OVERRIDE)
# undef override
# undef ASMJIT_UNDEF_OVERRIDE
#endif // ASMJIT_UNDEF_OVERRIDE
// ============================================================================
// [NoExcept]
// ============================================================================
#if defined(ASMJIT_UNDEF_NOEXCEPT)
# undef noexcept
# undef ASMJIT_UNDEF_NOEXCEPT
#endif // ASMJIT_UNDEF_NOEXCEPT
// ============================================================================
// [MSVC]
// [MSC]
// ============================================================================
#if defined(_MSC_VER)
// Pop disabled warnings by ApiBegin.h
# pragma warning(pop)
// Rename symbols back.
# if defined(ASMJIT_DEFINED_VSNPRINTF)
# undef ASMJIT_DEFINED_VSNPRINTF
# if defined(ASMJIT_UNDEF_VSNPRINTF)
# undef vsnprintf
# endif // ASMJIT_DEFINED_VSNPRINTF
# if defined(ASMJIT_DEFINED_SNPRINTF)
# undef ASMJIT_DEFINED_SNPRINTF
# undef ASMJIT_UNDEF_VSNPRINTF
# endif // ASMJIT_UNDEF_VSNPRINTF
# if defined(ASMJIT_UNDEF_SNPRINTF)
# undef snprintf
# endif // ASMJIT_DEFINED_SNPRINTF
# undef ASMJIT_UNDEF_SNPRINTF
# endif // ASMJIT_UNDEF_SNPRINTF
#endif // _MSC_VER
// ============================================================================
// [GNUC]
// [CLang]
// ============================================================================
#if defined(__clang__)
# pragma clang diagnostic pop
#endif // __clang__
// ============================================================================
// [GCC]
// ============================================================================
#if defined(__GNUC__) && !defined(__clang__)
# if __GNUC__ >= 4 && !defined(__MINGW32__)
# pragma GCC visibility pop
# endif // __GNUC__ >= 4
# endif // GCC 4+
#endif // __GNUC__
......@@ -235,15 +235,15 @@
//! `BaseMem` class. These functions are used to make operands that represents
//! memory addresses:
//!
//! - `asmjit::ptr()`
//! - `asmjit::byte_ptr()`
//! - `asmjit::word_ptr()`
//! - `asmjit::dword_ptr()`
//! - `asmjit::qword_ptr()`
//! - `asmjit::tword_ptr()`
//! - `asmjit::oword_ptr()`
//! - `asmjit::yword_ptr()`
//! - `asmjit::zword_ptr()`
//! - `asmjit::ptr()` - Address size not specified.
//! - `asmjit::byte_ptr()` - 1 byte.
//! - `asmjit::word_ptr()` - 2 bytes (Gpw size).
//! - `asmjit::dword_ptr()` - 4 bytes (Gpd size).
//! - `asmjit::qword_ptr()` - 8 bytes (Gpq/Mm size).
//! - `asmjit::tword_ptr()` - 10 bytes (FPU).
//! - `asmjit::oword_ptr()` - 16 bytes (Xmm size).
//! - `asmjit::yword_ptr()` - 32 bytes (Ymm size).
//! - `asmjit::zword_ptr()` - 64 bytes (Zmm size).
//!
//! Most useful function to make pointer should be `asmjit::ptr()`. It creates
//! pointer to the target with unspecified size. Unspecified size works in all
......@@ -298,10 +298,10 @@
//! // Get `X86CpuInfo` global instance.
//! const X86CpuInfo* cpuInfo = X86CpuInfo::getHost();
//!
//! if (cpuInfo->hasFeature(kX86CpuFeatureSse2)) {
//! if (cpuInfo->hasFeature(kX86CpuFeatureSSE2)) {
//! // Processor has SSE2.
//! }
//! else if (cpuInfo->hasFeature(kX86CpuFeatureMmx)) {
//! else if (cpuInfo->hasFeature(kX86CpuFeatureMMX)) {
//! // Processor doesn't have SSE2, but has MMX.
//! }
//! else {
......
......@@ -340,43 +340,35 @@ Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const
}
Error Assembler::emit(uint32_t code, int o0) {
Imm imm(o0);
return _emit(code, imm, NA, NA, NA);
return _emit(code, Imm(o0), NA, NA, NA);
}
Error Assembler::emit(uint32_t code, uint64_t o0) {
Imm imm(o0);
return _emit(code, imm, NA, NA, NA);
Error Assembler::emit(uint32_t code, const Operand& o0, int o1) {
return _emit(code, o0, Imm(o1), NA, NA);
}
Error Assembler::emit(uint32_t code, const Operand& o0, int o1) {
Imm imm(o1);
return _emit(code, o0, imm, NA, NA);
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, int o2) {
return _emit(code, o0, o1, Imm(o2), NA);
}
Error Assembler::emit(uint32_t code, const Operand& o0, uint64_t o1) {
Imm imm(o1);
return _emit(code, o0, imm, NA, NA);
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, int o3) {
return _emit(code, o0, o1, o2, Imm(o3));
}
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, int o2) {
Imm imm(o2);
return _emit(code, o0, o1, imm, NA);
Error Assembler::emit(uint32_t code, int64_t o0) {
return _emit(code, Imm(o0), NA, NA, NA);
}
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, uint64_t o2) {
Imm imm(o2);
return _emit(code, o0, o1, imm, NA);
Error Assembler::emit(uint32_t code, const Operand& o0, int64_t o1) {
return _emit(code, o0, Imm(o1), NA, NA);
}
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, int o3) {
Imm imm(o3);
return _emit(code, o0, o1, o2, imm);
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, int64_t o2) {
return _emit(code, o0, o1, Imm(o2), NA);
}
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, uint64_t o3) {
Imm imm(o3);
return _emit(code, o0, o1, o2, imm);
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, int64_t o3) {
return _emit(code, o0, o1, o2, Imm(o3));
}
#undef NA
......
......@@ -26,23 +26,23 @@ namespace asmjit {
//! \{
// ============================================================================
// [asmjit::kInstId]
// [asmjit::InstId]
// ============================================================================
//! Instruction codes (stub).
ASMJIT_ENUM(kInstId) {
ASMJIT_ENUM(InstId) {
//! No instruction.
kInstIdNone = 0
};
// ============================================================================
// [asmjit::kInstOptions]
// [asmjit::InstOptions]
// ============================================================================
//! Instruction options (stub).
ASMJIT_ENUM(kInstOptions) {
//! Instruction options.
ASMJIT_ENUM(InstOptions) {
//! No instruction options.
kInstOptionNone = 0x00,
kInstOptionNone = 0x00000000,
//! Emit short form of the instruction.
//!
......@@ -53,7 +53,8 @@ ASMJIT_ENUM(kInstOptions) {
//! can be dangerous if the short jmp/jcc is required, but not encodable due
//! to large displacement, in such case an error happens and the whole
//! assembler/compiler stream is unusable.
kInstOptionShortForm = 0x01,
kInstOptionShortForm = 0x00000001,
//! Emit long form of the instruction.
//!
//! X86/X64:
......@@ -61,12 +62,13 @@ ASMJIT_ENUM(kInstOptions) {
//! Long form is mosrlt related to jmp and jcc instructions, but like the
//! `kInstOptionShortForm` option it can be used by other instructions
//! supporting both 8-bit and 32-bit immediates.
kInstOptionLongForm = 0x02,
kInstOptionLongForm = 0x00000002,
//! Condition is likely to be taken.
kInstOptionTaken = 0x04,
kInstOptionTaken = 0x00000004,
//! Condition is unlikely to be taken.
kInstOptionNotTaken = 0x08
kInstOptionNotTaken = 0x00000008
};
// ============================================================================
......@@ -474,19 +476,20 @@ struct ASMJIT_VCLASS Assembler : public CodeGen {
//! Emit an instruction with integer immediate operand.
ASMJIT_API Error emit(uint32_t code, int o0);
//! \overload
ASMJIT_API Error emit(uint32_t code, uint64_t o0);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, int o1);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, uint64_t o1);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, const Operand& o1, int o2);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, const Operand& o1, uint64_t o2);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, int o3);
//! \overload
ASMJIT_API Error emit(uint32_t code, int64_t o0);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, int64_t o1);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, const Operand& o1, int64_t o2);
//! \overload
ASMJIT_API Error emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, uint64_t o3);
ASMJIT_API Error emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, int64_t o3);
//! Emit an instruction (virtual).
virtual Error _emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, const Operand& o3) = 0;
......
......@@ -23,11 +23,11 @@ namespace asmjit {
//! \{
// ============================================================================
// [asmjit::kCodeGen]
// [asmjit::CodeGenFeatures]
// ============================================================================
//! Features of \ref CodeGen.
ASMJIT_ENUM(kCodeGen) {
ASMJIT_ENUM(CodeGenFeatures) {
//! Emit optimized code-alignment sequences (`Assembler` and `Compiler`).
//!
//! Default `true`.
......@@ -80,11 +80,11 @@ ASMJIT_ENUM(kCodeGen) {
};
// ============================================================================
// [asmjit::kAlignMode]
// [asmjit::AlignMode]
// ============================================================================
//! Code aligning mode.
ASMJIT_ENUM(kAlignMode) {
ASMJIT_ENUM(AlignMode) {
//! Align by emitting a sequence that can be executed (code).
kAlignCode = 0,
//! Align by emitting sequence that shouldn't be executed (data).
......@@ -92,11 +92,11 @@ ASMJIT_ENUM(kAlignMode) {
};
// ============================================================================
// [asmjit::kRelocMode]
// [asmjit::RelocMode]
// ============================================================================
//! Relocation mode.
ASMJIT_ENUM(kRelocMode) {
ASMJIT_ENUM(RelocMode) {
//! Relocate an absolute address to an absolute address.
kRelocAbsToAbs = 0,
//! Relocate a relative address to an absolute address.
......
......@@ -40,11 +40,11 @@ enum { kBaseCompilerDefaultLookAhead = 64 };
Compiler::Compiler(Runtime* runtime) :
CodeGen(runtime),
_assembler(NULL),
_nodeFlowId(0),
_nodeFlags(0),
_maxLookAhead(kBaseCompilerDefaultLookAhead),
_targetVarMapping(NULL),
_assembler(NULL),
_firstNode(NULL),
_lastNode(NULL),
_cursor(NULL),
......@@ -482,7 +482,7 @@ VarData* Compiler::_newVd(uint32_t type, uint32_t size, uint32_t c, const char*
vd->_flags = 0;
vd->_priority = 10;
vd->_state = kVarStateUnused;
vd->_state = kVarStateNone;
vd->_regIndex = kInvalidReg;
vd->_isStack = false;
vd->_isMemArg = false;
......
This diff is collapsed.
......@@ -162,19 +162,6 @@ void ConstPool::reset() {
// [asmjit::ConstPool - Ops]
// ============================================================================
static ASMJIT_INLINE size_t ConstPool_getGapIndex(size_t size) {
if (size <= 1)
return ConstPool::kIndex1;
else if (size <= 3)
return ConstPool::kIndex2;
else if (size <= 7)
return ConstPool::kIndex4;
else if (size <= 15)
return ConstPool::kIndex8;
else
return ConstPool::kIndex16;
}
static ASMJIT_INLINE ConstPoolGap* ConstPool_allocGap(ConstPool* self) {
ConstPoolGap* gap = self->_gapPool;
if (gap == NULL)
......@@ -396,7 +383,7 @@ UNIT(base_constpool) {
EXPECT(prevOffset + 8 == curOffset,
"pool.add() - Returned incorrect curOffset.");
EXPECT(pool.getSize() == (i + 1) * 8,
"pool.getSize() - Reports incorrect size.");
"pool.getSize() - Reported incorrect size.");
prevOffset = curOffset;
}
......@@ -481,7 +468,6 @@ UNIT(base_constpool) {
INFO("Checking pool alignment when combined constants are added.");
{
uint8_t bytes[32] = { 0 };
uint64_t c = 0;
size_t offset;
pool.add(bytes, 1, offset);
......
......@@ -128,9 +128,12 @@ struct ConstPoolTree {
if (link != NULL) {
ASMJIT_ASSERT(top != kHeightLimit);
stack[top++] = node;
node = link;
continue;
}
_Visit:
visitor.visit(node);
link = node->_link[1];
......@@ -143,6 +146,7 @@ struct ConstPoolTree {
break;
node = stack[--top];
goto _Visit;
}
}
......
......@@ -26,8 +26,8 @@ namespace asmjit {
Context::Context(Compiler* compiler) :
_compiler(compiler),
_varMapToVaListOffset(0),
_baseZone(8192 - kZoneOverhead) {
_baseZone(8192 - kZoneOverhead),
_varMapToVaListOffset(0) {
Context::reset();
}
......@@ -217,7 +217,7 @@ Error Context::resolveCellOffsets() {
// Vars - Allocated according to alignment/width.
while (varCell != NULL) {
uint32_t size = varCell->getSize();
uint32_t offset;
uint32_t offset = 0;
switch (size) {
case 1: offset = pos1 ; pos1 += 1 ; break;
......@@ -234,13 +234,13 @@ Error Context::resolveCellOffsets() {
varCell = varCell->_next;
}
// Stack - Allocated according to alignment and width.
// Stack - Allocated according to alignment/width.
while (stackCell != NULL) {
uint32_t size = stackCell->getSize();
uint32_t alignment = stackCell->getAlignment();
uint32_t offset;
// Try to fill the gap between variables / stack first.
// Try to fill the gap between variables/stack first.
if (size <= gapSize && alignment <= gapAlignment) {
offset = gapPos;
......
......@@ -10,11 +10,11 @@
// [Dependencies - AsmJit]
#include "../base/cpuinfo.h"
#if defined(ASMJIT_HOST_X86) || defined(ASMJIT_HOST_X64)
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
#include "../x86/x86cpuinfo.h"
#else
// ?
#endif // ASMJIT_HOST || ASMJIT_HOST_X64
#endif
// [Dependencies - Posix]
#if defined(ASMJIT_OS_POSIX)
......@@ -54,7 +54,7 @@ uint32_t CpuInfo::detectHwThreadsCount() {
// [asmjit::CpuInfo - GetHost]
// ============================================================================
#if defined(ASMJIT_HOST_X86) || defined(ASMJIT_HOST_X64)
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
struct AutoX86CpuInfo : public X86CpuInfo {
ASMJIT_INLINE AutoX86CpuInfo() : X86CpuInfo() {
X86CpuUtil::detect(this);
......@@ -62,14 +62,14 @@ struct AutoX86CpuInfo : public X86CpuInfo {
};
#else
#error "AsmJit - Unsupported CPU."
#endif // ASMJIT_HOST || ASMJIT_HOST_X64
#endif
const CpuInfo* CpuInfo::getHost() {
#if defined(ASMJIT_HOST_X86) || defined(ASMJIT_HOST_X64)
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
static AutoX86CpuInfo cpuInfo;
#else
#error "AsmJit - Unsupported CPU."
#endif // ASMJIT_HOST || ASMJIT_HOST_X64
#endif
return &cpuInfo;
}
......
......@@ -20,7 +20,7 @@ namespace asmjit {
//! \{
// ============================================================================
// [asmjit::kCpuVendor]
// [asmjit::CpuVendor]
// ============================================================================
//! Cpu vendor ID.
......@@ -30,7 +30,7 @@ namespace asmjit {
//! calls. Some manufacturers changed their vendor strings and AsmJit is aware
//! of that - it checks multiple combinations and decides which vendor ID should
//! be used.
ASMJIT_ENUM(kCpuVendor) {
ASMJIT_ENUM(CpuVendor) {
//! No/Unknown vendor.
kCpuVendorNone = 0,
......@@ -59,7 +59,7 @@ struct CpuInfo {
// [Construction / Destruction]
// --------------------------------------------------------------------------
ASMJIT_INLINE CpuInfo(uint32_t size = sizeof(CpuInfo)) : _size(size) {}
ASMJIT_INLINE CpuInfo(uint32_t size) : _size(size) {}
// --------------------------------------------------------------------------
// [Accessors]
......@@ -120,7 +120,7 @@ struct CpuInfo {
//! Cpu long vendor string (brand).
char _brandString[64];
//! Cpu vendor id, see `asmjit::kCpuVendor`.
//! Cpu vendor id, see \ref CpuVendor.
uint32_t _vendorId;
//! Cpu family ID.
uint32_t _family;
......
......@@ -24,7 +24,7 @@
// [Dependencies - Windows]
#if defined(ASMJIT_OS_WINDOWS)
// `_InterlockedCompareExchange` is only available as intrinsic (MS Compiler).
# if defined(_MSC_VER)
# if defined(_MSC_VER) && _MSC_VER >= 1400
# include <intrin.h>
# pragma intrinsic(_InterlockedCompareExchange)
# else
......
......@@ -64,7 +64,9 @@ static const char* findPackedString(const char* p, uint32_t id, uint32_t maxId)
while (i < id) {
while (p[0])
p++;
p++;
i++;
}
return p;
......
......@@ -8,23 +8,23 @@
#ifndef _ASMJIT_BASE_ERROR_H
#define _ASMJIT_BASE_ERROR_H
// [Api-Begin]
#include "../apibegin.h"
// [Dependencies - AsmJit]
#include "../base/globals.h"
// [Api-Begin]
#include "../apibegin.h"
namespace asmjit {
//! \addtogroup asmjit_base_general
//! \{
// ============================================================================
// [asmjit::kError]
// [asmjit::ErrorCode]
// ============================================================================
//! AsmJit error codes.
ASMJIT_ENUM(kError) {
ASMJIT_ENUM(ErrorCode) {
//! No error (success).
//!
//! This is default state and state you want.
......@@ -188,7 +188,7 @@ struct ASMJIT_VCLASS ErrorHandler {
//! Error utilities.
struct ErrorUtil {
#if !defined(ASMJIT_DISABLE_NAMES)
//! Get printable version of AsmJit `kError` code.
//! Get a printable version of AsmJit `Error` code.
static ASMJIT_API const char* asString(Error code);
#endif // ASMJIT_DISABLE_NAMES
};
......
......@@ -34,7 +34,7 @@ typedef uint64_t Ptr;
typedef int64_t SignedPtr;
// ============================================================================
// [asmjit::kGlobals]
// [asmjit::GlobalDefs]
// ============================================================================
//! Invalid index
......@@ -48,7 +48,7 @@ static const size_t kInvalidIndex = ~static_cast<size_t>(0);
static const Ptr kNoBaseAddress = static_cast<Ptr>(static_cast<SignedPtr>(-1));
//! Global constants.
ASMJIT_ENUM(kGlobals) {
ASMJIT_ENUM(GlobalDefs) {
//! Invalid value or operand id.
kInvalidValue = 0xFFFFFFFF,
......@@ -74,11 +74,11 @@ ASMJIT_ENUM(kGlobals) {
};
// ============================================================================
// [asmjit::kArch]
// [asmjit::ArchId]
// ============================================================================
//! Architecture.
ASMJIT_ENUM(kArch) {
//! CPU architecture identifier.
ASMJIT_ENUM(ArchId) {
//! No/Unknown architecture.
kArchNone = 0,
......@@ -90,17 +90,17 @@ ASMJIT_ENUM(kArch) {
//! Arm architecture.
kArchArm = 4,
#if defined(ASMJIT_HOST_X86)
#if defined(ASMJIT_ARCH_X86)
kArchHost = kArchX86,
#endif // ASMJIT_HOST_X86
#endif // ASMJIT_ARCH_X86
#if defined(ASMJIT_HOST_X64)
#if defined(ASMJIT_ARCH_X64)
kArchHost = kArchX64,
#endif // ASMJIT_HOST_X64
#endif // ASMJIT_ARCH_X64
#if defined(ASMJIT_HOST_ARM)
#if defined(ASMJIT_ARCH_ARM)
kArchHost = kArchArm,
#endif // ASMJIT_HOST_ARM
#endif // ASMJIT_ARCH_ARM
//! Whether the host is 64-bit.
kArchHost64Bit = sizeof(intptr_t) >= 8
......
......@@ -11,8 +11,9 @@
// [Dependencies - AsmJit]
#include "../base/globals.h"
#if defined(_MSC_VER)
#pragma intrinsic(_BitScanForward)
#if defined(_MSC_VER) && _MSC_VER >= 1400
# include <intrin.h>
# pragma intrinsic(_BitScanForward)
#endif // ASMJIT_OS_WINDOWS
// [Api-Begin]
......@@ -43,6 +44,31 @@ struct IntTraits {
};
};
// \internal
template<size_t Size, int IsSigned>
struct AsInt_ { typedef int64_t Int; };
template<> struct AsInt_<1, 0> { typedef int Int; };
template<> struct AsInt_<1, 1> { typedef int Int; };
template<> struct AsInt_<2, 0> { typedef int Int; };
template<> struct AsInt_<2, 1> { typedef int Int; };
template<> struct AsInt_<4, 1> { typedef int Int; };
// \internal
//
// Map an integer `T` to an `int` or `int64_t`, depending on the type. Used
// internally by AsmJit to dispatch an argument of arbitrary integer type into
// a function that accepts either `int` or `int64_t`.
template<typename T>
struct AsInt {
typedef typename AsInt_<sizeof(T), IntTraits<T>::kIsSigned>::Int Int;
};
template<typename T>
ASMJIT_INLINE typename AsInt<T>::Int asInt(T value) {
return static_cast<typename AsInt<T>::Int>(value);
}
// ============================================================================
// [asmjit::IntUtil]
// ============================================================================
......@@ -82,29 +108,29 @@ struct IntUtil {
//! Pack two 8-bit integer and one 16-bit integer into a 32-bit integer as it
//! is an array of `{u0,u1,w2}`.
static ASMJIT_INLINE uint32_t pack32_2x8_1x16(uint32_t u0, uint32_t u1, uint32_t w2) {
#if defined(ASMJIT_HOST_LE)
#if defined(ASMJIT_ARCH_LE)
return u0 + (u1 << 8) + (w2 << 16);
#else
return (u0 << 24) + (u1 << 16) + (w2);
#endif // ASMJIT_HOST
#endif
}
//! Pack four 8-bit integer into a 32-bit integer as it is an array of `{u0,u1,u2,u3}`.
static ASMJIT_INLINE uint32_t pack32_4x8(uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) {
#if defined(ASMJIT_HOST_LE)
#if defined(ASMJIT_ARCH_LE)
return u0 + (u1 << 8) + (u2 << 16) + (u3 << 24);
#else
return (u0 << 24) + (u1 << 16) + (u2 << 8) + u3;
#endif // ASMJIT_HOST
#endif
}
//! Pack two 32-bit integer into a 64-bit integer as it is an array of `{u0,u1}`.
static ASMJIT_INLINE uint64_t pack64_2x32(uint32_t u0, uint32_t u1) {
#if defined(ASMJIT_HOST_LE)
#if defined(ASMJIT_ARCH_LE)
return (static_cast<uint64_t>(u1) << 32) + u0;
#else
return (static_cast<uint64_t>(u0) << 32) + u1;
#endif // ASMJIT_HOST
#endif
}
// --------------------------------------------------------------------------
......@@ -336,7 +362,7 @@ struct IntUtil {
//! Find a first bit in `mask`.
static ASMJIT_INLINE uint32_t findFirstBit(uint32_t mask) {
#if defined(_MSC_VER)
#if defined(_MSC_VER) && _MSC_VER >= 1400
DWORD i;
if (_BitScanForward(&i, mask)) {
ASMJIT_ASSERT(findFirstBitSlow(mask) == i);
......@@ -566,6 +592,26 @@ union UInt64 {
return *this;
}
// --------------------------------------------------------------------------
// [AndNot]
// --------------------------------------------------------------------------
ASMJIT_INLINE UInt64& andNot(uint64_t val) {
u64 &= ~val;
return *this;
}
ASMJIT_INLINE UInt64& andNot(const UInt64& val) {
if (kArchHost64Bit) {
u64 &= ~val.u64;
}
else {
u32[0] &= ~val.u32[0];
u32[1] &= ~val.u32[1];
}
return *this;
}
// --------------------------------------------------------------------------
// [Or]
// --------------------------------------------------------------------------
......@@ -606,26 +652,6 @@ union UInt64 {
return *this;
}
// --------------------------------------------------------------------------
// [Del]
// --------------------------------------------------------------------------
ASMJIT_INLINE UInt64& del(uint64_t val) {
u64 &= ~val;
return *this;
}
ASMJIT_INLINE UInt64& del(const UInt64& val) {
if (kArchHost64Bit) {
u64 &= ~val.u64;
}
else {
u32[0] &= ~val.u32[0];
u32[1] &= ~val.u32[1];
}
return *this;
}
// --------------------------------------------------------------------------
// [Eq]
// --------------------------------------------------------------------------
......@@ -694,11 +720,11 @@ union UInt64 {
uint8_t u8[8];
struct {
#if defined(ASMJIT_HOST_LE)
#if defined(ASMJIT_ARCH_LE)
uint32_t lo, hi;
#else
uint32_t hi, lo;
#endif // ASMJIT_HOST_LE
#endif // ASMJIT_ARCH_LE
};
};
......
......@@ -45,9 +45,12 @@ void Logger::logFormat(uint32_t style, const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
len = vsnprintf(buf, 1023, fmt, ap);
len = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (len >= sizeof(buf))
len = sizeof(buf) - 1;
logString(style, buf, len);
}
......@@ -120,15 +123,6 @@ FileLogger::FileLogger(FILE* stream) : _stream(NULL) {
FileLogger::~FileLogger() {}
// ============================================================================
// [asmjit::FileLogger - Accessors]
// ============================================================================
//! Set file stream.
void FileLogger::setStream(FILE* stream) {
_stream = stream;
}
// ============================================================================
// [asmjit::FileLogger - Logging]
// ============================================================================
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment