Skip to content

Fix rvp#2310

Open
chihminchao wants to merge 12 commits into
riscv-software-src:masterfrom
chihminchao:fix-rvp
Open

Fix rvp#2310
chihminchao wants to merge 12 commits into
riscv-software-src:masterfrom
chihminchao:fix-rvp

Conversation

@chihminchao

Copy link
Copy Markdown
Contributor

Fix implementation by riscv-software-src/riscv-tests#648

Comment thread riscv/csrs.cc Outdated
Comment thread riscv/insns/sshlr.h Outdated
Comment thread riscv/insns/sshlr.h Outdated
Comment thread riscv/insns/sshlr.h Outdated
Comment thread riscv/insns/sshl.h Outdated
Comment thread riscv/insns/sshl.h Outdated
Comment thread riscv/insns/sshlr.h Outdated
Comment thread riscv/insns/sshl.h
Comment thread riscv/insns/shlr.h Outdated
Comment thread riscv/insns/shlr.h Outdated
Comment thread riscv/insns/pssha_dhs.h Outdated

@aswaterman aswaterman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is moving in the right direction. Thanks!

I will do a second round of review once all of the unusual shift instructions are rewritten how I suggested. It's much easier to spot the bugs with fewer special cases.

@chihminchao

Copy link
Copy Markdown
Contributor Author

Extra change

  1. I have apply the std::min for other sshl/sshlr instructions
  2. replace magic constants by standard UINTXX_T/INTXX_T definition.

@chihminchao chihminchao force-pushed the fix-rvp branch 3 times, most recently from 489ca0f to c383e01 Compare June 9, 2026 10:05
Comment thread riscv/insns/ssha.h Outdated
WRITE_RD((RS1 & 0x80000000) ? sext32(0xffffffff) : 0);
else
WRITE_RD(sshamt >= 0 ? P_SAT(32, static_cast<sreg_t> (RS1) << sshamt) : (RS1 >> -sshamt)); No newline at end of file
WRITE_RD(sshamt >= 0 ? P_SAT(32, static_cast<sreg_t> (RS1) << sshamt) : (RS1 >> -sshamt));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks incorrect: it needs an sext32, too.

I recommend only having the WRITE_RD(sext32(result)) in one place, with the result being written in each of the if-statement cases. And please do the same thing in all of the instructions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

follow the suggestion to simplify writing path

Comment thread riscv/insns/nclipu.h
Comment thread riscv/insns/nclipru.h
Comment thread riscv/insns/nclipriu.h
Comment thread riscv/insns/nclipiu.h
Comment thread riscv/insns/mulqr.h
WRITE_RD(sext32((((RS1 * RS2) >> 30) + 1) >> 1));
} else {
WRITE_RD(INT32_MAX);
P.set_vxsat();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread riscv/insns/mulq.h

@aswaterman aswaterman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks much better, thanks @chihminchao. Ping me once my remaining issues are resolved and I'll merge it.

Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
chihminchao and others added 11 commits July 6, 2026 07:42
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
also refine writing path to RD

Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Corrects shift amount for extracting bits [47:16] from 48-bit
multiply-accumulate products. Implementation used 32-bit shift
but spec requires 16-bit shift to extract high portion.

Fixed instructions:
- MHACC.H0: P-ext spec
- MHACC.H1: P-ext spec
- MHACCSU.H0: P-ext spec
- MHACCSU.H1: P-ext spec

Changed: mres >> 32  →  mres >> 16

Signed-off-by: Max Chou <max.chou@sifive.com>
Corrects swapped add/subtract operators in packed 2-way multiply
loop. Spec requires (p0 - p1) but implementation computed (p1 - p0).
Even elements should add, odd elements should subtract.

Fixed instructions:
- PM2WSUB.H: P-ext spec
- PM2WSUBA.H: P-ext spec

Changed: Swapped += and -= for (j & 1) conditional

Signed-off-by: Max Chou <max.chou@sifive.com>
Use 5-bit mask (0x1F) for shift amount instead of 8-bit field
extraction. Spec defines rs2[4:0] as shift amount. Also removes
incorrect >= 32 check that zeroed result.

Fixed instruction:
- PSLL.DWS: P-ext spec

Changed: P_FIELD(RS2, 0, 8) with >= 32 check  →  RS2 & 0x1F

Signed-off-by: Max Chou <max.chou@sifive.com>
Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
@chihminchao

Copy link
Copy Markdown
Contributor Author

Update: 2026/07/06
1 simplify writing path to RD
2.fix more signed-extension issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants