Skip to content

Add Zilsd/Zclsd Support #765

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add Zilsd/Zclsd Support #765

wants to merge 2 commits into from

Conversation

trdthg
Copy link
Contributor

@trdthg trdthg commented Mar 4, 2025

spec: https://github.com/riscv/riscv-zilsd/blob/main/zilsd.adoc#insns-sd

function clause extensionEnabled(Ext_Zclsd) = true & xxx is a placeholder, waiting for config system

Copy link

github-actions bot commented Mar 4, 2025

Test Results

398 tests  ±0   398 ✅ ±0   1m 45s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 179b3be. ± Comparison against base commit 513a705.

♻️ This comment has been updated with latest results.

Comment on lines 27 to 35
match ext_data_get_addr(rs1, offset, Read(Data), width_bytes) {
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); RETIRE_FAIL },
Ext_DataAddr_OK(vaddr) =>
if check_misaligned(vaddr, width)
then { handle_mem_exception(vaddr, E_Load_Addr_Align()); RETIRE_FAIL }
else match translateAddr(vaddr, Read(Data)) {
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
TR_Address(paddr, _) =>
match mem_read(Read(Data), paddr, 8, false, false, false) {
Ok(result) => {
X(rd) = result[31..0];
X(rd + 1) = result[63..32];
RETIRE_SUCCESS
},
Err(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
},
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious, wouldn't it make more sense to replace LOAD_RV32 (and STORE_RV32) with two sequential 32-bit load/store operations instead of one 64-bit load/store operation?

Most 32-bit systems have a 32-bit memory bus, so performing two 32-bit accesses would be more realistic than a single 64-bit access on such hardware.

This implementation would also allow us to test the more interesting case where interrupts could occur between the two operations, as explicitly permitted by the Zilsd specification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's definitely a good idea, I didn't think of that

@trdthg trdthg force-pushed the zilsd branch 2 times, most recently from a979234 to a28bd1b Compare March 5, 2025 01:02
@jordancarlin jordancarlin added the extension Adds support for a RISC-V extension label Mar 5, 2025
/* SPDX-License-Identifier: BSD-2-Clause */
/*=======================================================================================*/

function clause extensionEnabled(Ext_Zclsd) = true & extensionEnabled(Ext_Zilsd) & extensionEnabled(Ext_Zca) & not(extensionEnabled(Ext_Zcf)) & xlen == 32
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to create a mutual cycle between extensionEnabled(Ext_Zclsd) and extensionEnabled(Ext_Zcf).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After the configuration system merged, update to config extensions.Zclsd.enabled should resolve the issue.

function clause extensionEnabled(Ext_Zilsd) = true & xlen == 32

/* ****************************************************************** */
union clause ast = LOAD_RV32 : (bits(12), regidx, regidx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

LOAD_DOUBLE might be a better name for the AST constructor than LOAD_RV32. It's unfortunate that the spec re-uses LOAD. (Could we ask the spec authors to change this before ratification?) Similarly for STORE_RV32.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw your reply at riscv/riscv-zilsd#64, so I update it to the format of EXT_INST(ZILSD_LD...).


function clause execute LOAD_RV32(imm, rs1, rd) = {
// Use of misaligned (odd-numbered) registers is reserved.
assert(regidx_to_regno(rd) % 2 == 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of asserting here, it would be better to put this constraint on rd in the encdec clause. Similarly for rs2 in the store instruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@christian-herber-nxp
Copy link

how does this relate to #490?

@trdthg
Copy link
Contributor Author

trdthg commented Mar 10, 2025

how does this relate to #490?

I didn't see it before. Currently, the code mainly has the following differences

@trdthg trdthg force-pushed the zilsd branch 2 times, most recently from d6533f5 to d70a272 Compare March 10, 2025 01:30
@pmundkur pmundkur added the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Mar 10, 2025
@pmundkur
Copy link
Collaborator

@trdthg Could you check with @christian-herber-nxp to make sure we're not missing anything from #490 and we get the appropriate co-authors?

@christian-herber-nxp
Copy link

the author of the original PR should be clear from that, it is @simonacostinescu

@trdthg trdthg force-pushed the zilsd branch 2 times, most recently from c1bff11 to ea18ab9 Compare March 24, 2025 02:43
@trdthg
Copy link
Contributor Author

trdthg commented Mar 24, 2025

Update

I am trying to run act tests (there is already a PR, not merged yet), but encountered a few problems

I think you could review this after I finished those tests.

Co-authored-by already added

@jordancarlin jordancarlin removed the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Apr 7, 2025
jordancarlin and others added 2 commits April 8, 2025 15:49
One of the tricky parts with this extension is that it is designed to have its instructions overridden by other extensions (like `Zicfiss`). This will be handled by relying on file order to override instructions.

This is a little fragile with the current compilation method, where all `.sail` files are passed to the compiler. In future we will use a Sail project file which allows enforcing file order more robustly.
Co-authored-by:	Simona Costinescu <[email protected]>
function clause execute ZILSD_LD(imm, rs1, rd) = {
if rd != zreg then {
let base_val = X(rs1);
let _ = load_imm(imm, base_val, rd, WORD);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't this cause issues if the first load fails? I think you need to check what it returns so that we get the RETIRE_FAIL if the first load fails.

Right now if the first load fails but the second one succeeds (like if it is right on some memory region boundary) this instruction will act like it succeeded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension Adds support for a RISC-V extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants