mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 20:44:37 +03:00
Minor - Put assembler/compiler options to a macro.
Dummy - cleanup.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef void (*MyFunc)(void);
|
||||
typedef int (*MyFunc)(void);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
using namespace asmjit;
|
||||
@@ -27,40 +27,12 @@ int main(int argc, char* argv[]) {
|
||||
Compiler c(&runtime);
|
||||
c.setLogger(&logger);
|
||||
|
||||
c.addFunc(kFuncConvHost, FuncBuilder0<void>());
|
||||
|
||||
Label L_1(c);
|
||||
Label L_2(c);
|
||||
Label L_3(c);
|
||||
Label L_4(c);
|
||||
Label L_5(c);
|
||||
Label L_6(c);
|
||||
Label L_7(c);
|
||||
|
||||
GpVar v1(c);
|
||||
GpVar v2(c);
|
||||
|
||||
c.bind(L_2);
|
||||
c.bind(L_3);
|
||||
|
||||
c.jmp(L_1);
|
||||
c.bind(L_5);
|
||||
c.mov(v1, 0);
|
||||
c.bind(L_6);
|
||||
c.jmp(L_3);
|
||||
c.mov(v2, 1);
|
||||
c.jmp(L_1);
|
||||
c.bind(L_4);
|
||||
c.jmp(L_2);
|
||||
c.bind(L_7);
|
||||
c.add(v1, v2);
|
||||
|
||||
c.bind(L_1);
|
||||
c.ret();
|
||||
c.addFunc(kFuncConvHost, FuncBuilder0<int>());
|
||||
c.endFunc();
|
||||
|
||||
MyFunc func = asmjit_cast<MyFunc>(c.make());
|
||||
runtime.release((void*)func);
|
||||
func();
|
||||
|
||||
runtime.release((void*)func);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -235,6 +235,49 @@ namespace x86x64 {
|
||||
return emit(_Code_, o0, o1, o2, o3); \
|
||||
}
|
||||
|
||||
#define ASMJIT_X86X64_EMIT_OPTIONS(_Class_) \
|
||||
/*! @brief Force short form of jmp/jcc instruction. */ \
|
||||
ASMJIT_INLINE _Class_& short_() { \
|
||||
_options |= kInstOptionShortForm; \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
/*! @brief Force long form of jmp/jcc instruction. */ \
|
||||
ASMJIT_INLINE _Class_& long_() { \
|
||||
_options |= kInstOptionLongForm; \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
/*! @brief Condition is likely to be taken (has only benefit on P4). */ \
|
||||
ASMJIT_INLINE _Class_& taken() { \
|
||||
_options |= kInstOptionTaken; \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
/*! @brief Condition is unlikely to be taken (has only benefit on P4). */ \
|
||||
ASMJIT_INLINE _Class_& notTaken() { \
|
||||
_options |= kInstOptionNotTaken; \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
/*! @brief Use LOCK prefix. */ \
|
||||
ASMJIT_INLINE _Class_& lock() { \
|
||||
_options |= kInstOptionLock; \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
/*! @brief Force REX prefix. */ \
|
||||
ASMJIT_INLINE _Class_& rex() { \
|
||||
_options |= kInstOptionRex; \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
/*! @brief Force 3-byte VEX prefix. */ \
|
||||
ASMJIT_INLINE _Class_& vex3() { \
|
||||
_options |= kInstOptionVex3; \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// [asmjit::x86x64::X86X64Assembler]
|
||||
// ============================================================================
|
||||
@@ -586,25 +629,7 @@ struct X86X64Assembler : public BaseAssembler {
|
||||
// [Options]
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
//! @brief Force short form of jmp/jcc/other instruction.
|
||||
ASMJIT_INLINE X86X64Assembler& short_()
|
||||
{ _options |= kInstOptionShortForm; return *this; }
|
||||
|
||||
//! @brief Force long form of jmp/jcc/other instruction.
|
||||
ASMJIT_INLINE X86X64Assembler& long_()
|
||||
{ _options |= kInstOptionLongForm; return *this; }
|
||||
|
||||
//! @brief Condition is likely to be taken.
|
||||
ASMJIT_INLINE X86X64Assembler& taken()
|
||||
{ _options |= kInstOptionTaken; return *this; }
|
||||
|
||||
//! @brief Condition is unlikely to be taken.
|
||||
ASMJIT_INLINE X86X64Assembler& notTaken()
|
||||
{ _options |= kInstOptionNotTaken; return *this; }
|
||||
|
||||
//! @brief Lock prefix.
|
||||
ASMJIT_INLINE X86X64Assembler& lock()
|
||||
{ _options |= kInstOptionLock; return *this; }
|
||||
ASMJIT_X86X64_EMIT_OPTIONS(X86X64Assembler)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// [Base Instructions]
|
||||
@@ -5169,29 +5194,7 @@ struct Assembler : public X86X64Assembler {
|
||||
// [Options]
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& short_()
|
||||
{ _options |= kInstOptionShortForm; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& long_()
|
||||
{ _options |= kInstOptionLongForm; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& taken()
|
||||
{ _options |= kInstOptionTaken; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& notTaken()
|
||||
{ _options |= kInstOptionNotTaken; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& lock()
|
||||
{ _options |= kInstOptionLock; return *this; }
|
||||
|
||||
//! @brief Force rex prefix.
|
||||
ASMJIT_INLINE Assembler& vex3()
|
||||
{ _options |= kInstOptionVex3; return *this; }
|
||||
ASMJIT_X86X64_EMIT_OPTIONS(Assembler)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// [X86-Only Instructions]
|
||||
@@ -5202,10 +5205,9 @@ struct Assembler : public X86X64Assembler {
|
||||
//! @brief Decimal adjust AL after subtraction (32-bit).
|
||||
INST_0x(das, kInstDas)
|
||||
|
||||
//! @brief Pop all Gp registers (EDI|ESI|EBP|EBX|EDX|ECX|EAX).
|
||||
//! @brief Pop all Gp registers - EDI|ESI|EBP|Ign|EBX|EDX|ECX|EAX.
|
||||
INST_0x(popa, kInstPopa)
|
||||
|
||||
//! @brief Push all Gp registers (EAX|ECX|EDX|EBX|original ESP|EBP|ESI|EDI).
|
||||
//! @brief Push all Gp registers - EAX|ECX|EDX|EBX|ESP|EBP|ESI|EDI.
|
||||
INST_0x(pusha, kInstPusha)
|
||||
};
|
||||
|
||||
@@ -5255,33 +5257,7 @@ struct Assembler : public X86X64Assembler {
|
||||
// [Options]
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& short_()
|
||||
{ _options |= kInstOptionShortForm; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& long_()
|
||||
{ _options |= kInstOptionLongForm; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& taken()
|
||||
{ _options |= kInstOptionTaken; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& notTaken()
|
||||
{ _options |= kInstOptionNotTaken; return *this; }
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Assembler& lock()
|
||||
{ _options |= kInstOptionLock; return *this; }
|
||||
|
||||
//! @brief Force rex prefix.
|
||||
ASMJIT_INLINE Assembler& rex()
|
||||
{ _options |= kInstOptionRex; return *this; }
|
||||
|
||||
//! @brief Force rex prefix.
|
||||
ASMJIT_INLINE Assembler& vex3()
|
||||
{ _options |= kInstOptionVex3; return *this; }
|
||||
ASMJIT_X86X64_EMIT_OPTIONS(Assembler)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// [X64-Only Instructions]
|
||||
@@ -5300,24 +5276,20 @@ struct Assembler : public X86X64Assembler {
|
||||
//! @overload
|
||||
INST_2x(movsxd, kInstMovsxd, GpReg, Mem)
|
||||
|
||||
//! @brief Load ECX/RCX qwords from DS:[ESI/RSI] to RAX.
|
||||
//! @brief Load ECX/RCX QWORDs from DS:[ESI/RSI] to RAX.
|
||||
INST_0x(rep_lodsq, kInstRepLodsq)
|
||||
|
||||
//! @brief Move ECX/RCX qwords from DS:[ESI/RSI] to ES:[EDI/RDI].
|
||||
//! @brief Move ECX/RCX QWORDs from DS:[ESI/RSI] to ES:[EDI/RDI].
|
||||
INST_0x(rep_movsq, kInstRepMovsq)
|
||||
|
||||
//! @brief Fill ECX/RCX qwords at ES:[EDI/RDI] with RAX.
|
||||
//! @brief Fill ECX/RCX QWORDs at ES:[EDI/RDI] with RAX.
|
||||
INST_0x(rep_stosq, kInstRepStosq)
|
||||
|
||||
//! @brief Repeated find nonmatching qwords in ES:[EDI/RDI] and DS:[ESI/RDI].
|
||||
//! @brief Repeated find nonmatching QWORDs in ES:[EDI/RDI] and DS:[ESI/RDI].
|
||||
INST_0x(repe_cmpsq, kInstRepeCmpsq)
|
||||
|
||||
//! @brief Find non-rax qword starting at ES:[EDI/RDI].
|
||||
//! @brief Find non-rax QWORD starting at ES:[EDI/RDI].
|
||||
INST_0x(repe_scasq, kInstRepeScasq)
|
||||
|
||||
//! @brief Repeated find nonmatching qwords in ES:[EDI/RDI] and DS:[ESI/RDI].
|
||||
//! @brief Repeated find nonmatching QWORDs in ES:[EDI/RDI] and DS:[ESI/RDI].
|
||||
INST_0x(repne_cmpsq, kInstRepneCmpsq)
|
||||
|
||||
//! @brief Find RAX, starting at ES:[EDI/RDI].
|
||||
INST_0x(repne_scasq, kInstRepneScasq)
|
||||
|
||||
|
||||
@@ -1564,35 +1564,7 @@ struct X86X64Compiler : public BaseCompiler {
|
||||
// [Options]
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
//! @brief Force short form of jmp/jcc/other instruction.
|
||||
ASMJIT_INLINE X86X64Compiler& short_() {
|
||||
_options |= kInstOptionShortForm;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Force long form of jmp/jcc/other instruction.
|
||||
ASMJIT_INLINE X86X64Compiler& long_() {
|
||||
_options |= kInstOptionLongForm;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Condition is likely to be taken.
|
||||
ASMJIT_INLINE X86X64Compiler& taken() {
|
||||
_options |= kInstOptionTaken;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Condition is unlikely to be taken.
|
||||
ASMJIT_INLINE X86X64Compiler& notTaken() {
|
||||
_options |= kInstOptionNotTaken;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Lock prefix.
|
||||
ASMJIT_INLINE X86X64Compiler& lock() {
|
||||
_options |= kInstOptionLock;
|
||||
return *this;
|
||||
}
|
||||
ASMJIT_X86X64_EMIT_OPTIONS(X86X64Compiler)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// [X86 Instructions]
|
||||
@@ -4061,35 +4033,7 @@ struct Compiler : public X86X64Compiler {
|
||||
// [Options]
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& short_() {
|
||||
_options |= kInstOptionShortForm;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& long_() {
|
||||
_options |= kInstOptionLongForm;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& taken() {
|
||||
_options |= kInstOptionTaken;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& notTaken() {
|
||||
_options |= kInstOptionNotTaken;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& lock() {
|
||||
_options |= kInstOptionLock;
|
||||
return *this;
|
||||
}
|
||||
ASMJIT_X86X64_EMIT_OPTIONS(Compiler)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// [X86-Only Instructions]
|
||||
@@ -4142,41 +4086,7 @@ struct Compiler : public X86X64Compiler {
|
||||
// [Options]
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& short_() {
|
||||
_options |= kInstOptionShortForm;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& long_() {
|
||||
_options |= kInstOptionLongForm;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& taken() {
|
||||
_options |= kInstOptionTaken;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& notTaken() {
|
||||
_options |= kInstOptionNotTaken;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @overload
|
||||
ASMJIT_INLINE Compiler& lock() {
|
||||
_options |= kInstOptionLock;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! @brief Force rex prefix.
|
||||
ASMJIT_INLINE Compiler& rex() {
|
||||
_options |= kInstOptionRex;
|
||||
return *this;
|
||||
}
|
||||
ASMJIT_X86X64_EMIT_OPTIONS(Compiler)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// [X64-Only Instructions]
|
||||
@@ -4201,24 +4111,20 @@ struct Compiler : public X86X64Compiler {
|
||||
//! @overload
|
||||
INST_2x(movsxd, kInstMovsxd, GpVar, Mem)
|
||||
|
||||
//! @brief Load ECX/RCX Qdwords from DS:[ESI/RSI] to RAX.
|
||||
//! @brief Load ECX/RCX QWORDs from DS:[ESI/RSI] to RAX.
|
||||
INST_3x_(rep_lodsq, kInstRepLodsq, GpVar, GpVar, GpVar, o0.getId() != o1.getId() && o1.getId() != o2.getId())
|
||||
|
||||
//! @brief Move ECX/RCX Qdwords from DS:[ESI/RSI] to ES:[EDI/RDI].
|
||||
//! @brief Move ECX/RCX QWORDs from DS:[ESI/RSI] to ES:[EDI/RDI].
|
||||
INST_3x_(rep_movsq, kInstRepMovsq, GpVar, GpVar, GpVar, o0.getId() != o1.getId() && o1.getId() != o2.getId())
|
||||
|
||||
//! @brief Fill ECX/RCX Qdwords at ES:[EDI/RDI] with RAX.
|
||||
//! @brief Fill ECX/RCX QWORDs at ES:[EDI/RDI] with RAX.
|
||||
INST_3x_(rep_stosq, kInstRepStosq, GpVar, GpVar, GpVar, o0.getId() != o1.getId() && o1.getId() != o2.getId())
|
||||
|
||||
//! @brief Repeated find nonmatching Qdwords in ES:[EDI/RDI] and DS:[ESI/RDI].
|
||||
//! @brief Repeated find nonmatching QWORDs in ES:[EDI/RDI] and DS:[ESI/RDI].
|
||||
INST_3x_(repe_cmpsq, kInstRepeCmpsq, GpVar, GpVar, GpVar, o0.getId() != o1.getId() && o1.getId() != o2.getId())
|
||||
|
||||
//! @brief Find non-RAX QWORD starting at ES:[EDI/RDI].
|
||||
INST_3x_(repe_scasq, kInstRepeScasq, GpVar, GpVar, GpVar, o0.getId() != o1.getId() && o1.getId() != o2.getId())
|
||||
|
||||
//! @brief Find matching Qdwords in [RDI] and [RSI].
|
||||
//! @brief Find matching QWORDs in [RDI] and [RSI].
|
||||
INST_3x_(repne_cmpsq, kInstRepneCmpsq, GpVar, GpVar, GpVar, o0.getId() != o1.getId() && o1.getId() != o2.getId())
|
||||
|
||||
//! @brief Find RAX, starting at ES:[EDI/RDI].
|
||||
INST_3x_(repne_scasq, kInstRepneScasq, GpVar, GpVar, GpVar, o0.getId() != o1.getId() && o1.getId() != o2.getId())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user