Skip to content

Commit

Permalink
Merge pull request #16 from OFFTKP/xth
Browse files Browse the repository at this point in the history
assembler: Add XTheadCondMov support
  • Loading branch information
lioncash authored Nov 8, 2024
2 parents ce1e82f + 2b1929e commit c86bf13
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 44 deletions.
89 changes: 45 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,51 @@ to how [Xbyak](https://github.com/herumi/xbyak) allows for runtime code generati

Includes both 32-bit and 64-bit instructions in the following:

| Feature | Version |
|:----------|:-------:|
| A | 2.1 |
| B | 1.0 |
| C | 2.0 |
| D | 2.2 |
| F | 2.2 |
| H | 1.0 |
| K | 1.0.1 |
| M | 2.0 |
| N | 1.1 |
| Q | 2.2 |
| RV32I | 2.1 |
| RV64I | 2.1 |
| S | 1.12 |
| V | 1.0 |
| Ssctr | 1.0 rc6 |
| Sstc | 0.5.4 |
| Zabha | 1.0 |
| Zacas | 1.0 |
| Zawrs | 1.01 |
| Zcb | 1.0.4 |
| Zclsd | 0.10 |
| Zcmp | 1.0.4 |
| Zcmt | 1.0.4 |
| Zfa | 1.0 |
| Zfbfmin | 1.0 |
| Zfh | 1.0 |
| Zfhmin | 1.0 |
| Zicbom | 1.0 |
| Zicbop | 1.0 |
| Zicboz | 1.0 |
| Zicfilp | 1.0 |
| Zicfiss | 1.0 |
| Zicond | 1.0.1 |
| Zicsr | 2.0 |
| Zifencei | 2.0 |
| Zihintntl | 1.0 |
| Zilsd | 0.10 |
| Zvbb | 1.0 |
| Zvbc | 1.0 |
| Zvfbfmin | 1.0 |
| Zvfbfwma | 1.0 |
| Zvkn | 1.0 |
| Feature | Version |
|:--------------|:-------:|
| A | 2.1 |
| B | 1.0 |
| C | 2.0 |
| D | 2.2 |
| F | 2.2 |
| H | 1.0 |
| K | 1.0.1 |
| M | 2.0 |
| N | 1.1 |
| Q | 2.2 |
| RV32I | 2.1 |
| RV64I | 2.1 |
| S | 1.12 |
| V | 1.0 |
| Ssctr | 1.0 rc6 |
| Sstc | 0.5.4 |
| XTheadCondMov | 1.0 |
| Zabha | 1.0 |
| Zacas | 1.0 |
| Zawrs | 1.01 |
| Zcb | 1.0.4 |
| Zclsd | 0.10 |
| Zcmp | 1.0.4 |
| Zcmt | 1.0.4 |
| Zfa | 1.0 |
| Zfbfmin | 1.0 |
| Zfh | 1.0 |
| Zfhmin | 1.0 |
| Zicbom | 1.0 |
| Zicbop | 1.0 |
| Zicboz | 1.0 |
| Zicfilp | 1.0 |
| Zicfiss | 1.0 |
| Zicond | 1.0.1 |
| Zicsr | 2.0 |
| Zifencei | 2.0 |
| Zihintntl | 1.0 |
| Zilsd | 0.10 |
| Zvbb | 1.0 |
| Zvbc | 1.0 |
| Zvfbfmin | 1.0 |
| Zvfbfwma | 1.0 |
| Zvkn | 1.0 |

Note that usually only extensions considered ratified will be implemented
as non-ratified documents are considerably more likely to have
Expand Down
5 changes: 5 additions & 0 deletions include/biscuit/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ class Assembler {
void CZERO_EQZ(GPR rd, GPR value, GPR condition) noexcept;
void CZERO_NEZ(GPR rd, GPR value, GPR condition) noexcept;


// XTheadCondMov Extension Instructions
void TH_MVEQZ(GPR rd, GPR value, GPR condition) noexcept;
void TH_MVNEZ(GPR rd, GPR value, GPR condition) noexcept;

// Zicsr Extension Instructions

void CSRRC(GPR rd, CSR csr, GPR rs) noexcept;
Expand Down
10 changes: 10 additions & 0 deletions src/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,16 @@ void Assembler::CZERO_NEZ(GPR rd, GPR value, GPR condition) noexcept {
EmitRType(m_buffer, 0b0000111, condition, value, 0b111, rd, 0b0110011);
}

// XTheadCondMov Extension Instructions

void Assembler::TH_MVEQZ(GPR rd, GPR value, GPR condition) noexcept {
EmitRType(m_buffer, 0b0100000, condition, value, 0b001, rd, 0b0001011);
}

void Assembler::TH_MVNEZ(GPR rd, GPR value, GPR condition) noexcept {
EmitRType(m_buffer, 0b0100001, condition, value, 0b001, rd, 0b0001011);
}

// Zicsr Extension Instructions

void Assembler::CSRRC(GPR rd, CSR csr, GPR rs) noexcept {
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_executable(${PROJECT_NAME}
src/assembler_rvq_tests.cpp
src/assembler_rvv_tests.cpp
src/assembler_vector_crypto_tests.cpp
src/assembler_xthead_tests.cpp
src/assembler_zabha_tests.cpp
src/assembler_zacas_tests.cpp
src/assembler_zawrs_tests.cpp
Expand Down
33 changes: 33 additions & 0 deletions tests/src/assembler_xthead_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <catch/catch.hpp>

#include <biscuit/assembler.hpp>

#include "assembler_test_utils.hpp"

using namespace biscuit;

TEST_CASE("TH.MVEQZ", "[XThead]") {
uint32_t value = 0;
auto as = MakeAssembler64(value);

as.TH_MVEQZ(x31, x30, x29);
REQUIRE(value == 0x41DF1F8B);

as.RewindBuffer();

as.TH_MVEQZ(x1, x2, x3);
REQUIRE(value == 0x4031108B);
}

TEST_CASE("TH.MVNEZ", "[XThead]") {
uint32_t value = 0;
auto as = MakeAssembler64(value);

as.TH_MVNEZ(x31, x30, x29);
REQUIRE(value == 0x43DF1F8B);

as.RewindBuffer();

as.TH_MVNEZ(x1, x2, x3);
REQUIRE(value == 0x4231108B);
}

0 comments on commit c86bf13

Please sign in to comment.