1b8021494Sopenharmony_ciVIXL: ARMv8 Runtime Code Generation Library 7.0.0 2b8021494Sopenharmony_ci================================================= 3b8021494Sopenharmony_ci 4b8021494Sopenharmony_ciContents: 5b8021494Sopenharmony_ci 6b8021494Sopenharmony_ci * Overview 7b8021494Sopenharmony_ci * Licence 8b8021494Sopenharmony_ci * Requirements 9b8021494Sopenharmony_ci * Known limitations 10b8021494Sopenharmony_ci * Bug reports 11b8021494Sopenharmony_ci * Usage 12b8021494Sopenharmony_ci 13b8021494Sopenharmony_ci 14b8021494Sopenharmony_ciOverview 15b8021494Sopenharmony_ci======== 16b8021494Sopenharmony_ci 17b8021494Sopenharmony_ciVIXL contains three components. 18b8021494Sopenharmony_ci 19b8021494Sopenharmony_ci 1. Programmatic **assemblers** to generate A64, A32 or T32 code at runtime. The 20b8021494Sopenharmony_ci assemblers abstract some of the constraints of each ISA; for example, most 21b8021494Sopenharmony_ci instructions support any immediate. 22b8021494Sopenharmony_ci 2. **Disassemblers** that can print any instruction emitted by the assemblers. 23b8021494Sopenharmony_ci 3. A **simulator** that can simulate any instruction emitted by the A64 24b8021494Sopenharmony_ci assembler. The simulator allows generated code to be run on another 25b8021494Sopenharmony_ci architecture without the need for a full ISA model. 26b8021494Sopenharmony_ci 27b8021494Sopenharmony_ciThe VIXL git repository can be found [on GitHub][vixl]. 28b8021494Sopenharmony_ci 29b8021494Sopenharmony_ciBuild and Test Status 30b8021494Sopenharmony_ci--------------------- 31b8021494Sopenharmony_ci 32b8021494Sopenharmony_ci * [](https://ci.linaro.org/job/linaro-art-vixlpresubmit/) Simulator 33b8021494Sopenharmony_ci * [](https://ci.linaro.org/job/linaro-art-vixlpresubmit-native-armv8/) Native 34b8021494Sopenharmony_ci * [](https://ci.linaro.org/job/linaro-art-vixlpresubmit-macos/) MacOS 35b8021494Sopenharmony_ci 36b8021494Sopenharmony_ci 37b8021494Sopenharmony_ciLicence 38b8021494Sopenharmony_ci======= 39b8021494Sopenharmony_ci 40b8021494Sopenharmony_ciThis software is covered by the licence described in the [LICENCE](LICENCE) 41b8021494Sopenharmony_cifile. 42b8021494Sopenharmony_ci 43b8021494Sopenharmony_ciContributions, as pull requests or via other means, are accepted under the terms 44b8021494Sopenharmony_ciof the same [LICENCE](LICENCE). 45b8021494Sopenharmony_ci 46b8021494Sopenharmony_ciRequirements 47b8021494Sopenharmony_ci============ 48b8021494Sopenharmony_ci 49b8021494Sopenharmony_ciTo build VIXL the following software is required: 50b8021494Sopenharmony_ci 51b8021494Sopenharmony_ci 1. Python 3.5+ 52b8021494Sopenharmony_ci 2. SCons 2.0 53b8021494Sopenharmony_ci 3. GCC 4.8+ or Clang 4.0+ 54b8021494Sopenharmony_ci 55b8021494Sopenharmony_ciA 64-bit host machine is required, implementing an LP64 data model. VIXL has 56b8021494Sopenharmony_cibeen tested using GCC on AArch64 Debian, GCC and Clang on amd64 Ubuntu 57b8021494Sopenharmony_cisystems. 58b8021494Sopenharmony_ci 59b8021494Sopenharmony_ciTo run the linter and code formatting stages of the tests, the following 60b8021494Sopenharmony_cisoftware is also required: 61b8021494Sopenharmony_ci 62b8021494Sopenharmony_ci 1. Git 63b8021494Sopenharmony_ci 2. [Google's `cpplint.py`][cpplint] 64b8021494Sopenharmony_ci 3. clang-format 11+ 65b8021494Sopenharmony_ci 4. clang-tidy 11+ 66b8021494Sopenharmony_ci 67b8021494Sopenharmony_ciRefer to the 'Usage' section for details. 68b8021494Sopenharmony_ci 69b8021494Sopenharmony_ciNote that in Ubuntu 18.04, clang-tidy-4.0 will only work if the clang-4.0 70b8021494Sopenharmony_cipackage is also installed. 71b8021494Sopenharmony_ci 72b8021494Sopenharmony_ciSupported Arm Architecture Features 73b8021494Sopenharmony_ci=================================== 74b8021494Sopenharmony_ci 75b8021494Sopenharmony_ci| Feature | VIXL CPUFeatures Flag | Notes | 76b8021494Sopenharmony_ci|------------|-----------------------|---------------------------------| 77b8021494Sopenharmony_ci| BTI | kBTI | Per-page enabling not supported | 78b8021494Sopenharmony_ci| DotProd | kDotProduct | | 79b8021494Sopenharmony_ci| FCMA | kFcma | | 80b8021494Sopenharmony_ci| FHM | kFHM | | 81b8021494Sopenharmony_ci| FP16 | kFPHalf, kNEONHalf | | 82b8021494Sopenharmony_ci| FRINTTS | kFrintToFixedSizedInt | | 83b8021494Sopenharmony_ci| FlagM | kFlagM | | 84b8021494Sopenharmony_ci| FlagM2 | kAXFlag | | 85b8021494Sopenharmony_ci| I8MM | kI8MM | | 86b8021494Sopenharmony_ci| JSCVT | kJSCVT | | 87b8021494Sopenharmony_ci| LOR | kLORegions | | 88b8021494Sopenharmony_ci| LRCPC | kRCpc | | 89b8021494Sopenharmony_ci| LRCPC2 | kRCpcImm | | 90b8021494Sopenharmony_ci| LSE | kAtomics | | 91b8021494Sopenharmony_ci| PAuth | kPAuth, kPAuthGeneric | Not ERETAA, ERETAB | 92b8021494Sopenharmony_ci| RAS | kRAS | | 93b8021494Sopenharmony_ci| RDM | kRDM | | 94b8021494Sopenharmony_ci| SVE | kSVE | | 95b8021494Sopenharmony_ci| SVE2 | kSVE2 | | 96b8021494Sopenharmony_ci| SVEBitPerm | kSVEBitPerm | | 97b8021494Sopenharmony_ci| SVEF32MM | kSVEF32MM | | 98b8021494Sopenharmony_ci| SVEF64MM | kSVEF64MM | | 99b8021494Sopenharmony_ci| SVEI8MM | kSVEI8MM | | 100b8021494Sopenharmony_ci 101b8021494Sopenharmony_ciEnable generating code for an architecture feature by combining a flag with 102b8021494Sopenharmony_cithe MacroAssembler's defaults. For example, to generate code for SVE, use 103b8021494Sopenharmony_ci`masm.GetCPUFeatures()->Combine(CPUFeatures::kSVE);`. 104b8021494Sopenharmony_ci 105b8021494Sopenharmony_ciSee [the cpu features header file](src/cpu-features.h) for more information. 106b8021494Sopenharmony_ci 107b8021494Sopenharmony_ci 108b8021494Sopenharmony_ciKnown Limitations 109b8021494Sopenharmony_ci================= 110b8021494Sopenharmony_ci 111b8021494Sopenharmony_ciVIXL was developed for JavaScript engines so a number of features from A64 were 112b8021494Sopenharmony_cideemed unnecessary: 113b8021494Sopenharmony_ci 114b8021494Sopenharmony_ci * Limited rounding mode support for floating point. 115b8021494Sopenharmony_ci * Limited support for synchronisation instructions. 116b8021494Sopenharmony_ci * Limited support for system instructions. 117b8021494Sopenharmony_ci * A few miscellaneous integer and floating point instructions are missing. 118b8021494Sopenharmony_ci 119b8021494Sopenharmony_ciThe VIXL simulator supports only those instructions that the VIXL assembler can 120b8021494Sopenharmony_cigenerate. The `doc` directory contains a 121b8021494Sopenharmony_ci[list of supported A64 instructions](doc/aarch64/supported-instructions-aarch64.md). 122b8021494Sopenharmony_ci 123b8021494Sopenharmony_ciThe VIXL simulator was developed to run on 64-bit amd64 platforms. Whilst it 124b8021494Sopenharmony_cibuilds and mostly works for 32-bit x86 platforms, there are a number of 125b8021494Sopenharmony_cifloating-point operations which do not work correctly, and a number of tests 126b8021494Sopenharmony_cifail as a result. 127b8021494Sopenharmony_ci 128b8021494Sopenharmony_ciDebug Builds 129b8021494Sopenharmony_ci------------ 130b8021494Sopenharmony_ci 131b8021494Sopenharmony_ciYour project's build system must define `VIXL_DEBUG` (eg. `-DVIXL_DEBUG`) 132b8021494Sopenharmony_ciwhen using a VIXL library that has been built with debug enabled. 133b8021494Sopenharmony_ci 134b8021494Sopenharmony_ciSome classes defined in VIXL header files contain fields that are only present 135b8021494Sopenharmony_ciin debug builds, so if `VIXL_DEBUG` is defined when the library is built, but 136b8021494Sopenharmony_cinot defined for the header files included in your project, you will see runtime 137b8021494Sopenharmony_cifailures. 138b8021494Sopenharmony_ci 139b8021494Sopenharmony_ciExclusive-Access Instructions 140b8021494Sopenharmony_ci----------------------------- 141b8021494Sopenharmony_ci 142b8021494Sopenharmony_ciAll exclusive-access instructions are supported, but the simulator cannot 143b8021494Sopenharmony_ciaccurately simulate their behaviour as described in the ARMv8 Architecture 144b8021494Sopenharmony_ciReference Manual. 145b8021494Sopenharmony_ci 146b8021494Sopenharmony_ci * A local monitor is simulated, so simulated exclusive loads and stores execute 147b8021494Sopenharmony_ci as expected in a single-threaded environment. 148b8021494Sopenharmony_ci * The global monitor is simulated by occasionally causing exclusive-access 149b8021494Sopenharmony_ci instructions to fail regardless of the local monitor state. 150b8021494Sopenharmony_ci * Load-acquire, store-release semantics are approximated by issuing a host 151b8021494Sopenharmony_ci memory barrier after loads or before stores. The built-in 152b8021494Sopenharmony_ci `__sync_synchronize()` is used for this purpose. 153b8021494Sopenharmony_ci 154b8021494Sopenharmony_ciThe simulator tries to be strict, and implements the following restrictions that 155b8021494Sopenharmony_cithe ARMv8 ARM allows: 156b8021494Sopenharmony_ci 157b8021494Sopenharmony_ci * A pair of load-/store-exclusive instructions will only succeed if they have 158b8021494Sopenharmony_ci the same address and access size. 159b8021494Sopenharmony_ci * Most of the time, cache-maintenance operations or explicit memory accesses 160b8021494Sopenharmony_ci will clear the exclusive monitor. 161b8021494Sopenharmony_ci * To ensure that simulated code does not depend on this behaviour, the 162b8021494Sopenharmony_ci exclusive monitor will sometimes be left intact after these instructions. 163b8021494Sopenharmony_ci 164b8021494Sopenharmony_ciInstructions affected by these limitations: 165b8021494Sopenharmony_ci `stxrb`, `stxrh`, `stxr`, `ldxrb`, `ldxrh`, `ldxr`, `stxp`, `ldxp`, `stlxrb`, 166b8021494Sopenharmony_ci `stlxrh`, `stlxr`, `ldaxrb`, `ldaxrh`, `ldaxr`, `stlxp`, `ldaxp`, `stlrb`, 167b8021494Sopenharmony_ci `stlrh`, `stlr`, `ldarb`, `ldarh`, `ldar`, `clrex`. 168b8021494Sopenharmony_ci 169b8021494Sopenharmony_ciSecurity Considerations 170b8021494Sopenharmony_ci----------------------- 171b8021494Sopenharmony_ci 172b8021494Sopenharmony_ciVIXL allows callers to generate any code they want. The generated code is 173b8021494Sopenharmony_ciarbitrary, and can therefore call back into any other component in the process. 174b8021494Sopenharmony_ciAs with any self-modifying code, vulnerabilities in the client or in VIXL itself 175b8021494Sopenharmony_cicould lead to arbitrary code generation. 176b8021494Sopenharmony_ci 177b8021494Sopenharmony_ciFor performance reasons, VIXL's Assembler only performs debug-mode checking of 178b8021494Sopenharmony_ciinstruction operands (such as immediate field encodability). This can minimise 179b8021494Sopenharmony_cicode-generation overheads for advanced compilers that already model instructions 180b8021494Sopenharmony_ciaccurately, and might consider the Assembler's checks to be redundant. The 181b8021494Sopenharmony_ciAssembler should only be used directly where encodability is independently 182b8021494Sopenharmony_cichecked, and where fine control over all generated code is required. 183b8021494Sopenharmony_ci 184b8021494Sopenharmony_ciThe MacroAssembler synthesises multiple-instruction sequences to support _some_ 185b8021494Sopenharmony_ciunencodable operand combinations. The MacroAssembler can provide a useful safety 186b8021494Sopenharmony_cicheck in cases where the Assembler's precision is not required; an unexpected 187b8021494Sopenharmony_ciunencodable operand should result in a macro with the correct behaviour, rather 188b8021494Sopenharmony_cithan an invalid instruction. 189b8021494Sopenharmony_ci 190b8021494Sopenharmony_ciIn general, the MacroAssembler handles operands which are likely to vary with 191b8021494Sopenharmony_ciuser-supplied data, but does not usually handle inputs which are likely to be 192b8021494Sopenharmony_cieasily covered by tests. For example, move-immediate arguments are likely to be 193b8021494Sopenharmony_cidata-dependent, but register types (e.g. `x` vs `w`) are not. 194b8021494Sopenharmony_ci 195b8021494Sopenharmony_ciWe recommend that _all_ users use the MacroAssembler, using `ExactAssemblyScope` 196b8021494Sopenharmony_cito invoke the Assembler when specific instruction sequences are required. This 197b8021494Sopenharmony_ciapproach is recommended even in cases where a compiler can model the 198b8021494Sopenharmony_ciinstructions precisely, because, subject to the limitations described above, it 199b8021494Sopenharmony_cioffers an additional layer of protection against logic bugs in instruction 200b8021494Sopenharmony_ciselection. 201b8021494Sopenharmony_ci 202b8021494Sopenharmony_ciBug reports 203b8021494Sopenharmony_ci=========== 204b8021494Sopenharmony_ci 205b8021494Sopenharmony_ciBug reports may be made in the Issues section of GitHub, or sent to 206b8021494Sopenharmony_civixl@arm.com. Please provide any steps required to recreate a bug, along with 207b8021494Sopenharmony_cibuild environment and host system information. 208b8021494Sopenharmony_ci 209b8021494Sopenharmony_ciUsage 210b8021494Sopenharmony_ci===== 211b8021494Sopenharmony_ci 212b8021494Sopenharmony_ciRunning all Tests 213b8021494Sopenharmony_ci----------------- 214b8021494Sopenharmony_ci 215b8021494Sopenharmony_ciThe helper script `tools/test.py` will build and run every test that is provided 216b8021494Sopenharmony_ciwith VIXL, in both release and debug mode. It is a useful script for verifying 217b8021494Sopenharmony_cithat all of VIXL's dependencies are in place and that VIXL is working as it 218b8021494Sopenharmony_cishould. 219b8021494Sopenharmony_ci 220b8021494Sopenharmony_ciBy default, the `tools/test.py` script runs a linter to check that the source 221b8021494Sopenharmony_cicode conforms with the code style guide, and to detect several common errors 222b8021494Sopenharmony_cithat the compiler may not warn about. This is most useful for VIXL developers. 223b8021494Sopenharmony_ciThe linter has the following dependencies: 224b8021494Sopenharmony_ci 225b8021494Sopenharmony_ci 1. Git must be installed, and the VIXL project must be in a valid Git 226b8021494Sopenharmony_ci repository, such as one produced using `git clone`. 227b8021494Sopenharmony_ci 2. `cpplint.py`, [as provided by Google][cpplint], must be available (and 228b8021494Sopenharmony_ci executable) on the `PATH`. 229b8021494Sopenharmony_ci 230b8021494Sopenharmony_ciIt is possible to tell `tools/test.py` to skip the linter stage by passing 231b8021494Sopenharmony_ci`--nolint`. This removes the dependency on `cpplint.py` and Git. The `--nolint` 232b8021494Sopenharmony_cioption is implied if the VIXL project is a snapshot (with no `.git` directory). 233b8021494Sopenharmony_ci 234b8021494Sopenharmony_ciAdditionally, `tools/test.py` tests code formatting using `clang-format-4.0`, 235b8021494Sopenharmony_ciand performs static analysis using `clang-tidy-4.0`. If you don't have these 236b8021494Sopenharmony_citools, disable the test using `--noclang-format` or `--noclang-tidy`, 237b8021494Sopenharmony_cirespectively. 238b8021494Sopenharmony_ci 239b8021494Sopenharmony_ciAlso note that the tests for the tracing features depend upon external `diff` 240b8021494Sopenharmony_ciand `sed` tools. If these tools are not available in `PATH`, these tests will 241b8021494Sopenharmony_cifail. 242b8021494Sopenharmony_ci 243b8021494Sopenharmony_ciGetting Started 244b8021494Sopenharmony_ci--------------- 245b8021494Sopenharmony_ci 246b8021494Sopenharmony_ciWe have separate guides for introducing VIXL, depending on what architecture you 247b8021494Sopenharmony_ciare targeting. A guide for working with AArch32 can be found 248b8021494Sopenharmony_ci[here][getting-started-aarch32], while the AArch64 guide is 249b8021494Sopenharmony_ci[here][getting-started-aarch64]. Example source code is provided in the 250b8021494Sopenharmony_ci[examples](examples) directory. You can build examples with either `scons 251b8021494Sopenharmony_ciaarch32_examples` or `scons aarch64_examples` from the root directory, or use 252b8021494Sopenharmony_ci`scons --help` to get a detailed list of available build targets. 253b8021494Sopenharmony_ci 254b8021494Sopenharmony_ci 255b8021494Sopenharmony_ci 256b8021494Sopenharmony_ci 257b8021494Sopenharmony_ci[cpplint]: https://github.com/google/styleguide/tree/gh-pages/cpplint 258b8021494Sopenharmony_ci "Google's cpplint.py script." 259b8021494Sopenharmony_ci 260b8021494Sopenharmony_ci[vixl]: https://github.com/Linaro/vixl 261b8021494Sopenharmony_ci "The VIXL repository on GitHub." 262b8021494Sopenharmony_ci 263b8021494Sopenharmony_ci[getting-started-aarch32]: doc/aarch32/getting-started-aarch32.md 264b8021494Sopenharmony_ci "Introduction to VIXL for AArch32." 265b8021494Sopenharmony_ci 266b8021494Sopenharmony_ci[getting-started-aarch64]: doc/aarch64/getting-started-aarch64.md 267b8021494Sopenharmony_ci "Introduction to VIXL for AArch64." 268