Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AArch64 Capstone Update / SME2 support #429

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open

Conversation

FinnWilkinson
Copy link
Contributor

@FinnWilkinson FinnWilkinson commented Sep 4, 2024

This PR updates SimEng to work with a newer release of Capstone who's AArch64 engine is based on LLVM18, hence allowing SME2 support.

The reccommended version of LLVM has also been changed to 18.1.8 and the test suite has been updated to work with this version in order to dissassemble new AArch64 instructions.

Closes Issue #349

There have been large changes to Capstone internally for AArch64, some of the main ones which effect our current development / usage include:

  • A writeback from a pre/post index load/store is now included as an implicit destination. Hence, in instruction_execute the updated base address register is resuts[0] rather than results[1] (for example).

  • Post index immediate operands are now included as part of the memory operand in mem.disp. Post indexing with a register however is added as an additional operand.

  • Aliasing can be dissabled for auto-sync architectures, and has been done for AArch64. This means expected registers for the operand are now correct and allows us to remove revertalias() from instruction_metadata completely! The only oddity is the mnemonic and operandStr are still that of the alias. This means exceptions or debugging print statements may be confusing. To indicate aliases better, an isAlias bool has been added to the metadata and exception print out.

  • Get automatic LLVM download and install working for version 18.1.8

  • Add AArch64 multi-vector operand enum decoding logic to instruction_decode

    • No longer required as multi-vector operands already give each register individually rather than using the multi-register enums

@FinnWilkinson FinnWilkinson added the enhancement New feature or request label Sep 4, 2024
@FinnWilkinson FinnWilkinson self-assigned this Sep 4, 2024
@FinnWilkinson FinnWilkinson marked this pull request as ready for review September 17, 2024 17:08
@FinnWilkinson FinnWilkinson added the 0.9.7 Part of SimEng Release 0.9.7 label Sep 17, 2024
@@ -149,14 +140,17 @@ if(SIMENG_ENABLE_TESTS)
find_package(LLVM REQUIRED CONFIG NO_CMAKE_BUILDS_PATH)

# Check LLVM version
if ((${LLVM_PACKAGE_VERSION} VERSION_LESS "8.0") OR (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "14.1"))
message(FATAL_ERROR "LLVM version must be >= 8.0 and <= 14.0")
if ((${LLVM_PACKAGE_VERSION} VERSION_LESS "8.0") OR (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "18.2"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the if statement checks for >= 18.2, but the message says can be <= 18.2. Is 18.2 itself okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently updating how we build LLVM in CMake so will see if this comment is still relevant then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an outcome for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are still in place so I will update them inline with Alex's initial comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated message

inline uint8_t getDataSize(cs_aarch64_op op) {
// No V-register enum identifiers exist. Instead, depending on whether a full
// or half vector is accessed, a Q or D register is used instead.
// A `is_vreg` bool in `op` defines if we are using v-vecotr registers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: 'vector'

@@ -658,8 +658,17 @@ bool ExceptionHandler::init() {
if (metadata.opcode == Opcode::AArch64_MSR) {
newSVCR = instruction_.getSourceOperands()[0].get<uint64_t>();
} else if (metadata.opcode == Opcode::AArch64_MSRpstatesvcrImm1) {
// Enusre operand metadata is as expected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo -- 'Ensure'

sourceRegisters_[sourceRegisterCount_] = csRegToRegister(op.reg);
sourceRegisterCount_++;
sourceOperandsPending_++;

// TODO checking of the shift type is a temporary fix to help reduce the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this todo become actionable by the capstone update?

@@ -370,8 +370,7 @@ void ModelConfig::setExpectations(bool isDefault) {
expectations_["Core"].addChild(ExpectationNode::createExpectation<uint64_t>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we know that the maximum value for this is 2048, do we need to use unit64_t? Elsewhere we have gone for the smallest suitable datatype. Not sure if there is a technical advantage to using a smaller int type, but if there is then it might apply here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point / spot - changing to uint16_t

@FinnWilkinson FinnWilkinson changed the title [WIP] AArch64 Capstone Update / SME2 support AArch64 Capstone Update / SME2 support Oct 2, 2024
@FinnWilkinson FinnWilkinson linked an issue Oct 24, 2024 that may be closed by this pull request
Copy link
Contributor

@jj16791 jj16791 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fair few comments but there's a lot of work done here so expected. Great job on this, a significant amount of effort done!

CMakeLists.txt Outdated Show resolved Hide resolved
@@ -149,14 +140,17 @@ if(SIMENG_ENABLE_TESTS)
find_package(LLVM REQUIRED CONFIG NO_CMAKE_BUILDS_PATH)

# Check LLVM version
if ((${LLVM_PACKAGE_VERSION} VERSION_LESS "8.0") OR (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "14.1"))
message(FATAL_ERROR "LLVM version must be >= 8.0 and <= 14.0")
if ((${LLVM_PACKAGE_VERSION} VERSION_LESS "8.0") OR (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "18.2"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an outcome for this?

docs/sphinx/developer/arch/index.rst Outdated Show resolved Hide resolved
docs/sphinx/developer/arch/supported/aarch64.rst Outdated Show resolved Hide resolved
docs/sphinx/developer/arch/supported/aarch64.rst Outdated Show resolved Hide resolved
src/lib/arch/aarch64/Instruction_decode.cc Show resolved Hide resolved
src/lib/arch/aarch64/Instruction_decode.cc Outdated Show resolved Hide resolved
if (((Opcode::AArch64_FMOVD0 <= metadata_.opcode &&
metadata_.opcode <= Opcode::AArch64_FMOVS0) ||
(Opcode::AArch64_FMOVDXHighr <= metadata_.opcode &&
metadata_.opcode <= Opcode::AArch64_FMOVv8f16_ns)) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't the _ns instructions moving immediates into vector registers? (and thus aren't "move to general instructions")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I replaced the numbers with Opcodes (and referred to the previous Capstone version to make sure they aligned). If this is the case then we can remove the _ns ones from this catch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checked and we should remove _ns from this catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated catch

src/lib/arch/aarch64/Instruction_decode.cc Outdated Show resolved Hide resolved
src/lib/arch/aarch64/Instruction_decode.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@dANW34V3R dANW34V3R left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much to add on top of the others' comments. Will approve once theirs have been resolved

@@ -41,7 +41,7 @@ With this configuration, the build files will be generated in a directory called
More information about the LLVM_DIR value can be found `here <https://llvm.org/docs/CMake.html#embedding-llvm-in-your-project>`_.

.. Note::
LLVM versions greater than 14 or less than 8 are not supported. We'd recommend using LLVM 14.0.5 where possible as this has been verified by us to work correctly.
LLVM versions greater than 18 or less than 8 are not supported. We'd recommend using LLVM 18.1.8 where possible as this has been verified by us to work correctly for the most recent version of SimEng.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do lower versions of LLVM not support SME? If so that would be worth mentioning here (or at least somewhere in the docs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Versions from ~14 do support SME. Can add something to this

docs/sphinx/user/configuring_simeng.rst Outdated Show resolved Hide resolved
src/include/simeng/arch/aarch64/helpers/sve.hh Outdated Show resolved Hide resolved
src/lib/arch/aarch64/Architecture.cc Show resolved Hide resolved
src/lib/arch/riscv/InstructionMetadata.cc Show resolved Hide resolved
// Check from top of the range downwards
* `aarch64_reg` enum. Updates to the Capstone library version may cause this to
* break.
* TODO: Add multi-register enum decoding.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this TODO be removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.9.7 Part of SimEng Release 0.9.7 enhancement New feature or request
Projects
Status: Changes Requested
Development

Successfully merging this pull request may close these issues.

Add SME2 support
5 participants