77 Commits

Author SHA1 Message Date
Alexander Myltsev
c87860217e [bug] Fixed missing header files in install target 2025-12-13 15:32:29 +01:00
kobalicek
b56f4176cb Codebase update and improvements, instruction DB update
* Denested src folder to root, renamed testing to asmjit-testing

  * Refactored how headers are included into <asmjit/...> form. This
    is necessary as compilers would never simplify a path once a ..
    appears in include directory - then paths such as ../core/../core
    appeared in asserts, which was ugly

  * Moved support utilities into asmjit/support/... (still included
    by asmjit/core.h for convenience and compatibility)

  * Added CMakePresets.json for making it easy to develop AsmJit

  * Reworked CMakeLists to be shorter and use CMake option(),
    etc... This simplifies it and makes it using more standard
    features

  * ASMJIT_EMBED now creates asmjit_embed INTERFACE library,
    which is accessible via asmjit::asmjit target - this simplifies
    embedding and makes it the same as library targets from a CMake
    perspective

  * Removed ASMJIT_DEPS - this is now provided by cmake target
    aliases - 'asmjit::asmjit' so users should not need this variable

  * Changed meaning of ASMJIT_LIBS - this now contains only AsmJit
    dependencies without asmjit::asmjit target alias. Don't rely on
    ASMJIT_LIBS anymore as it's only used internally

  * Removed ASMJIT_NO_DEPRECATED option - AsmJit is not going
    to provide controllable deprecations in the future

  * Removed ASMJIT_NO_VALIDATION in favor of ASMJIT_NO_INTROSPECTION,
    which now controls query, features, and validation API presence

  * Removed ASMJIT_DIR option - it was never really needed

  * Removed AMX_TRANSPOSE feature from instruction database (X86).
    Intel has removed it as well, so it's a feature that won't
    be siliconized
2025-11-02 22:31:46 +01:00
kobalicek
cdc4eacbb1 [abi] Added more functionality to ujit
* Renamed round to round_even
  * Added round_half_up intrinsic
  * Added floating-point mod
  * Added a scalar version of floating-point abs and neg
  * Added a behavior enum to specify how float to int conversion
    handles out-of-range and NaN cases
  * Updated some APX stuff in instruction database
2025-10-05 17:31:24 +02:00
Golubev Alexander
13eb299dda [bug] Install missing header: core/span.h (cmake)
* The header was added recently, but it was missing in cmake, thus it was not installed.
2025-09-08 09:28:22 +02:00
kobalicek
7596c6d035 [abi] AsmJit v1.18 - performance and memory footprint improvements
* Refactored the whole codebase to use snake_case convention to
    name functions and variables, including member variables.
    Class naming is unchanged and each starts with upper-case
    character. The intention of this change is to make the source
    code more readable and consistent across multiple projects
    where AsmJit is currently used.

  * Refactored support.h to make it more shareable across projects.

  * x86::Vec now inherits from UniVec

  * minor changes in JitAllocator and WriteScope in order to make
    the size of WriteScope smaller

  * added ZoneStatistics and Zone::statistics() getter

  * improved x86::EmitHelper to use tables instead of choose() and
    other mechanisms to pick between SSE and AVX instructions

  * Refactored the whole codebase to use snake_case convention for
    for functions names, function parameter names, struct members,
    and variables

  * Added a non-owning asmjit::Span<T> type and use into public API
    to hide the usage of ZoneVector in CodeHolder, Builder, and
    Compiler. Users now only get Span (with data and size), which
    doesn't require users to know about ZoneVector

  * Removed RAWorkId from RATiedReg in favor of RAWorkReg*

  * Removed GEN from LiveInfo as it's not needed by CFG construction
    to save memory (GEN was merged with LIVE-IN bits). The remaining
    LIVE-IN, LIVE-OUT, and KILL bits are enough, however KILL bits may
    be removed in the future as KILL bits are not needed after LIVE-IN
    and LIVE-OUT converged

  * Optimized the representation of LIVE-IN, LIVE-OUT, and KILL bits
    per block. Now only registers that live across multiple basic
    blocks are included here, which means that virtual registers that
    only live in a single block are not included and won't be overhead
    during liveness analysis. This optimization alone can make liveness
    analysis 90% faster depending on the code generated (more virtual
    registers that only live in a single basic block -> more gains)

  * Optimized building liveness information bits per block. The new
    code uses an optimized algorithm to prevent too many traversals
    and uses a more optimized code for a case in which not too many
    registers are used (it avoids array operations if the number of
    all virtual registers within the function fits a single BitWord)

  * Optimized code that computes which virtual register is only used
    in a single basic block - this aims to optimize register allocator
    in the future by using a designed code path for allocating regs
    only used in a single basic block

  * Reduced the information required for each live-span, which is used
    by bin-packing. Now the struct is 8 bytes, which is good for a lot
    of optimizations C++ compiler can do

  * Added UniCompiler (ujit) which can be used to share code paths
    between X86, X86_64, and AArch64 code generation (experimental).
2025-09-06 13:44:34 +02:00
kobalicek
2ff454d415 [abi] AsmJit v1.17 - cumulative & breaking changes
* Reworked register operands - all vector registers are now
    platform::Vec deriving from UniVec (universal vector operand),
    additionally, there is no platform::Reg, instead asmjit::Reg
    provides all necessary features to make it a base register for
    each target architecture
  * Reworked casting between registers - now architecture agnostic
    names are preferred - use Gp32 instead of Gpd or GpW, Gp64
    instead of Gpq and GpX, etc...
  * Reworked vector registers and their names - architecture
    agnostic naming is now preferred Vec32, Vec64, Vec128, etc...
  * Reworked naming conventions used across AsmJit - for clarity
    Identifiers are now prefixed with the type, like sectionId(),
    labelId(), etc...
  * Reworked how Zone and ZoneAllocator are used across AsmJit,
    prefering Zone in most cases and ZoneAllocator only for
    containers - this change alone achieves around 5% better
    performance of Builder and Compiler
  * Reworked LabelEntry - decreased the size of the base entry
    to 16 bytes for anonymous and unnamed labels. Avoided an
    indirection when using labelEntries() - LabelEntry is now
    a value and not a pointer
  * Renamed LabelLink to Fixup
  * Added a new header <asmjit/host.h> which would include
    <asmjit/core.h> + target tools for the host architecture,
    if enabled and supported
  * Added new AArch64 instructions (BTI, CSSC, CHKFEAT)
  * Added a mvn_ alternative of mvn instruction (fix for Windows
    ARM64 SDK)
  * Added more AArch64 CPU features to CpuInfo
  * Added better support for Apple CPU detection (Apple M3, M4)
  * Added a new benchmarking tool asmjit_bench_overhead, which
    benchmarks the overhead of CodeHolder::init()/reset() and
    creating/attaching emitters to it. Thanks to the benchmark the
    most common code-paths were optimized
  * Added a new benchmarking tool asmjit_bench_regalloc, which
    aims to benchmark the cost and complexity of register allocation.
  * Renamed asmjit_test_perf to asmjit_bench_codegen to make it
    clear what is a test and what is a benchmark
2025-06-15 16:45:37 +02:00
kobalicek
c993fd9bfc Reworked asmjit_environment_info 2025-05-30 15:07:32 +02:00
kobalicek
ea9ae96653 Added asmjit_environment_info executable 2025-05-25 18:05:56 +02:00
kobalicek
356dddbc55 [abi] Switched to C++17 2025-05-24 19:21:17 +02:00
kobalicek
e7239626b8 Updated minimum cmake version to 3.19
* The latest cmake versions started showing warnings about the
    minimum version supported as there are possibly some breaking
    changes not affecting us
  * Reworked some bits in CMakeLists.txt to take advantage of the
    raised version
  * Removed the use of policies that are now enabled by cmake by
    default
  * Removed deprecated build options
2024-10-21 00:20:22 +02:00
kobalicek
d401bdb580 Added gpz() and gpSignature() to all emitters 2024-05-16 22:11:10 +02:00
kobalicek
7ff9c2a545 [CI] Minor changes in CMakeLists.txt, disable arm/v7 because of CI 2024-03-09 08:26:46 +01:00
kobalicek
a63d41e80b Added support for mach_vm_remap() for dual mapping
mach_vm_remap() allows to create a dual mapping without having to
use a file descriptor, which has to open a file or shm memory. The
problem is that the recent macos version started displaying a popup
message when such file is opened and that annoyed a lot of users.

Thus, the initial code-path is no longer used, and mach_vm_remap()
is used instead.

This change only applies for x86 macs. Apple silicon doesn't allow
dual mapping and instead uses MAP_JIT.
2024-01-25 22:23:13 +01:00
kobalicek
b4b2ff3109 Hardened runtime detection enhancements
A new HardenedRuntimeFlags::kDualMapping flag has been introduced to
detect whether dual mapping is provided by the target platform. This
flag can be set even when hardened runtime is not enforced in cases,
in which dual mapping is not available.

This fixes running unit tests on Apple hardware where dual mapping
is not available, but MAP_JIT is (AArch64 hardware).

Additionally, this changeset fixes using -msse2 flag on non-x86
targets, where compiler don't mind "-msse2" flag, but warns about
it. This makes the build 100% clean.
2024-01-20 12:23:11 +01:00
kobalicek
b25df5554d [ABI] Updated instruction DB, operands, and minor API changes
This changeset contains an updated instruction database that brings
ARM32 instructions for the first time. It also updates instruction
database tooling especially for ARM64, which will also be used by
ARM32 generator.

Additionally, new operan has been added, which represents a register
list as used by ARM32 instruction set.

Other minor changes are related to ARM - some stuff had to be moved
to a64 namespace from arm namespace as it's incompatible between
32-bit and 64-bit ISA.
2023-12-26 23:28:40 +01:00
kobalicek
1a81158e8b Build related improvements (CMake 3.8 now required)
* CMake 3.8 as a baseline means no "IF"s in a cmake build script
2023-12-07 22:00:05 +01:00
kobalicek
e731f57975 Build related improvements (additional) 2023-12-01 23:20:00 +01:00
kobalicek
803712f111 Build related improvements, better ASMJIT_NO_STDCXX support
* Added more cmake options to control features to be built
  * Added a detection whether to link to libpthread (if not part of libc)
  * Added a detection whether to link to librt (if not part of libc)
  * Removed pure virtual functions as this collides with -nostdlib
  * As a result the support for ASMJIT_NO_STDCXX has improved
2023-12-01 16:22:58 +01:00
kobalicek
46bdb67262 Fixed -fno-semantic-interposition warning with apple-clang 2023-09-11 10:47:10 +02:00
kobalicek
e4e61c4f15 [ABI] Completely reworked instruction DB and generators
* Instruction database is now part of asmjit to keep it in sync
  * X86/X64 ISA data has been reworked, now in a proper JSON format
  * ARM32 ISA data has been added (currently only DB, support later)
  * ARM64 ISA data has been added
  * ARM features detection has been updated
2023-09-10 09:55:17 +02:00
kobalicek
8e2f4de484 [ABI] Reworked JitAllocator to alloc spans and to use explicit write API 2023-09-10 09:55:00 +02:00
kobalicek
3502a8fe0d [Build] Changed CMAKE_CXX_SIMULATE_ID to CMAKE_CXX_COMPILER_FRONTEND_VARIANT as that seems to be the valid variable for detecting a MSVC frontend 2022-07-24 13:51:53 +02:00
kobalicek
a4e1e88374 [Bug] Do not link to pthread library on Android (there is no such library) 2022-02-20 17:38:27 +01:00
kobalicek
23ddf56b00 [ABI] Initial AArch64 support 2022-02-09 17:08:40 +01:00
kobalicek
996deae327 [ABI] Refactored AsmJit to use strong-typed enums, this breaks both API and ABI
[ABI] Added ABI version as an inline namespace, which forms asmjit::_abi_MAJOR_MINOR
[ABI] Added support for AVX512_FP16, 16-bit broadcast, and AVX512_FP16 tests
[ABI] Added initial support for consecutive registers into instruction database and register allocator
[ABI] Added a possibility to use temporary memory in CodeHolder's zone
[ABI] Compiler::setArg() is now deprecated, use FuncNode::setArg()
[Bug] Fixed correct RW information of instructions that only support implicit zeroing with {k}
[Bug] Fixed broadcast to be able to broadcast bcst16 operands
2021-12-13 19:34:56 +01:00
kobalicek
a4dd0b2d8b [ABI] Build improvements - replaced ASMJIT_BUIlD_X86 with ASMJIT_NO_X86 and other changes... 2021-03-21 14:42:47 +01:00
kobalicek
7836449c30 Added asmjit_test_perf, which replaces asmjit_bench and provides much better performance overview
Removed asmjit_test_opcode (not needed anymore as we have asmjit_test_assembler and asmjit_test_perf)
2021-03-13 23:05:48 +01:00
kobalicek
c9cebc67bc Split assembler tests so they can compile much faster with GCC 2021-03-13 14:28:05 +01:00
kobalicek
58b6c025f2 [ABI] Added more AVX_VNNI instructions, added MOVABS for explicit Imm64 encodings, added more assembler tests 2021-01-26 01:00:29 +01:00
kobalicek
cb13f69983 Support for using <windows.h> even without NOMINMAX 2020-10-26 20:22:33 +01:00
kobalicek
a281426ca6 [CMake] Include GNUInstallDirs after project() 2020-10-07 16:50:42 +02:00
David CARLIER
3c4415d729 [Bug] NetBSD build needs librt (#305) 2020-09-29 00:57:40 +02:00
kobalicek
cd44f41d9b Preparation for AArch64 support 2020-09-12 18:19:04 +02:00
kobalicek
d1b7543488 Added an initial cmake export support so users can find installed asmjit (Fixes #290) 2020-08-31 20:33:29 +02:00
kobalicek
f986f7fc44 AsmJit cleanup and refactoring 2020-05-31 23:39:13 +02:00
kobalicek
e78bba83da Added a support for indirect jumps within a function (Compiler) (#286) 2020-05-09 01:00:18 +02:00
kobalicek
80645e66a8 Improved natvis support 2020-05-03 22:38:56 +02:00
kobalicek
fc7eed5304 Build improvements (improved CMakeLists.txt, added proper support for testing) 2020-05-01 12:50:08 +02:00
kobalicek
9057aa30b6 Improved AsmJit public API to not depend on <windows.h> header 2020-04-29 20:19:17 +02:00
kobalicek
967dde0fc4 Use relative displacement in mov [abs], ax if base-address is known and the displacement encodable (#275) 2020-02-23 00:05:36 +01:00
kobalicek
5437d20dbb Added support for MAP_JIT (OSX, IOS), build system and CI improvements 2020-01-26 01:58:00 +01:00
Jianyu Huang
3d510b3540 Downgraded CMake version requirement to 3.5 for better compatibility (#252) 2019-08-08 23:37:57 +02:00
Petr Kobalicek
5d40561d14 Refactored register allocator asm Compiler. (#249)
Refactored build system macros (ASMJIT_BUILD_STATIC -> ASMJIT_STATIC)
Refactored AVX512 broadcast {1toN} - moved to operand from instruction.
Refactored naming - renamed getters to not use get prefix.
Refactored code structure - move arch-specific stuff into x86 namespace.
Refactored some compiler/arch-specific macros, respect rel/abs option in mov REG, [ADDR].
Refactored StringBuilder (Renamed to String, added small string optimization).
Refactored LabelId<->LabelEntry mapping, force label offset to 64-bits on all archs.
Renamed Runtime to Target (JitRuntime kept for now).
Renamed VirtMemManager to JitAllocator.
Renamed VirtMem to JitUtils.
Renamed FuncSignatureX to FuncSignatureBuilder.
Fixed xchg [mem], rex-lo, refactored RelocEntry.
Fixed Logger to always show abs|rel when formatting a memory operand
Fixed Logger to prefix HEX numbers with 0x prefix
Fixed Support::ctzGeneric to always return uint32_t, T doesn't matter.
Fixed LightCall to not save MMX and K registers
Fixed CpuInfo constructor to propagate NoInit (#243)
Added VAES, AVX512_VBMI2, AVX512_VNNI, and AVX512_BITALG cpu-features and instructions.
Added emscripten support (asmjit can be now compiled by emscripten).
Added asmjit.natvis for better MSVC experience
Added x86::ptr_abs|ptr_rel
Added support for multibyte nop r/m (#135)
Added support for 32-bit to 64-bit zero-extended addresses, improved validation of memory addresses, and removed wrt address type as this will be reworked
Added support for multiple sections, reworked address table support (previously known as trampolines)
Added the following x86 modifiers to the x86::Emitter - xacquire(), xrelease(), and k(kreg)
Added a possibility to use REP prefix with RET instruction
Added a possibility to relocate [rel addr] during relocate()
Added a variadic function-call support (Compiler), argument duplication (Compiler), better /dev/shm vs /tmp shared memory handling (VirtMem).
Removed imm_u imm_ptr helpers, imm() can now accept any integer and pointer.
Changed the default behavior of optimizing instructions to disabled with a possibility to enable that feature through kOptionOptimizedForSize
Use default copy construction / assignment to prevent new kind of warnings introduced by GCC 9
2019-07-16 01:24:22 +02:00
Nils Gladitz
02d24af4c0 Replace incorrect CMake CACHE variable type BOOLEAN with BOOL (#238) 2019-03-20 09:38:43 +01:00
kobalicek
c2f50e6fc5 Incorporated changes from pull requests 187, 202, and 212 2018-11-17 05:43:49 +01:00
kobalicek
e8a80ea958 Moved logic from x86inst.cpp to x86instimpl.cpp, moved some instruction methods to Inst from X86Inst, added Inst::checkFeatures() for retrieving which CPU features are required to run a given instruction, minor reorganization and asmdb update 2017-03-09 16:57:54 +01:00
kobalicek
35ba2ad83a Minor changes to cmake files 2017-03-04 20:37:42 +01:00
kobalicek
f589e7165a Fixed encoding of 'CRC32 r64, r8/m8' instruction
Fixed encoding of 'POPCNT|TZCNT|LZCNT r16, r16/m16' instruction
Fixed encoding of EVEX instructions that don't provide VEX prefix equivalent
Added 'LOCK MOV CR8' extension used by AMD processors in 32-bit mode and 'ALTMOVCR8' CPU feature
Renamed some CPU features to respect their names used in X86/X64 architecture manuals
Added validation of immediate operands (correct size, correct sign/zero extension)
Added validation of explicit/implicit size of memory operands
Added validation of LOCK/REP/REPNZ prefixes to x86 validator
Reorganized some X86 instruction tables, removed family specific tables, introduced OperationData
Improved instruction tables generator to automatically generate instruction flags
Regenerated all instruction tables to respect the current state of 'asmdb.x86data'
2017-02-25 19:36:28 +01:00
kobalicek
1e47f7999c Fixed some warnings 2017-02-19 19:36:36 +01:00
Petr Kobalicek
b7f6d1e369 Merged asmjit:next branch (#149) 2017-01-26 15:55:03 +01:00