-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8318218: RISC-V: C2 CompressBits #16481
Conversation
👋 Welcome back mli! A progress list of the required criteria for merging this PR into |
@Hamlin-Li The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
I made a mistake, UseRVVForCompressBitsIntrinsics is only defined in riscv global.hpp. |
Maybe jdk/src/hotspot/cpu/riscv/riscv.ad Lines 1896 to 1897 in c788160
|
Personally I'm against these 'micro' options .e.g. UseRVVForXX. |
Indeed. We already can turn on and off individual intrinsics. |
…; move code to riscv_v.ad and C2_MacroAssembler
Thanks @feilongjiang for pointing at the postion. @robehn @theRealAph I agree, thanks for discussion |
src/hotspot/cpu/riscv/riscv_v.ad
Outdated
// CompressBits of Long & Integer | ||
|
||
instruct compressBitsI(iRegINoSp dst, iRegIorL2I src, iRegIorL2I mask, iRegPNoSp tmp, vRegMask_V0 v0, vReg_V4 v4, vReg_V8 v8) %{ | ||
predicate(UseRVV && (MaxVectorSize >= 16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simply remote the (MaxVectorSize >= 16)
condition as that has already been ensured on JVM startup?
src/hotspot/cpu/riscv/riscv_v.ad
Outdated
%} | ||
|
||
instruct compressBitsL(iRegLNoSp dst, iRegL src, iRegL mask, iRegPNoSp tmp, vRegMask_V0 v0, vReg_V4 v4, vReg_V8 v8) %{ | ||
predicate(UseRVV && (MaxVectorSize >= 16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, seems it's redundant to check it here again, as we already have a check in Matcher::match_rule_supported where it's necessary to avoid silent failure in case restrictions on MaxVectorSize is changed in the future.
It's removed here.
@@ -1681,6 +1681,44 @@ void C2_MacroAssembler::signum_fp(FloatRegister dst, FloatRegister src, FloatReg | |||
bind(done); | |||
} | |||
|
|||
void C2_MacroAssembler::compress_bits_v(Register dst, Register src, Register mask, Register tmp, bool is_long) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that this is quite similar to the implementation of CompressM
node in riscv_v.ad
[1] which I think should be more efficient. The only difference is that we only need to move src
into a vector register beforehand and change to perform vcpop_m
under the given mask
. Please consider.
[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/riscv_v.ad#L3506-L3518
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see the difference now. The active 0 bits are still kept back here in this case [1].
[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/intrinsicnode.cpp#L300-L310
vsetivli(x0, 1, sew, lmul); | ||
vmv_s_x(v0, src); | ||
// reset the src data(in bytes) to zero. | ||
mv(tmp, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use scratch register t0
instead of tmp
in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@Hamlin-Li : Thanks for the update. But I am still not satisfied with current approach. The issue is that we will be wasting vector registers when running on hardwares equipped with RVV registers of bigger width, say 256-bits. We are reserving more vector registers than needed in that case, which might mean some extra vector register spilling/reloading under high register pressure. We should consider this issue. |
Yes, that's the potential possible issues. |
long len = is_long ? 64 : 32; | ||
|
||
// load the src data(in bits) to be compressed. | ||
vsetivli(x0, 1, sew, lmul); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A default lmul
of m1
is enough to perform the succeeding vmv_s_x
instuction as specified by the RVV spec.
The integer scalar read/write instructions transfer a single value between a scalar x register and element 0 of a vector
register. The instructions ignore LMUL and vector register groups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems it make no difference at run time, as The instructions ignore LMUL and vector register groups.
.
But it makes sense to modify it as you suggested, it's more clear.
vmv_v_i(v8, 0); | ||
// load the mask data(in bits). | ||
vsetivli(x0, 1, sew, lmul); | ||
vmv_v_x(v0, mask); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be vmv_s_x(v0, mask)
instead of vmv_v_x(v0, mask)
? The vcompress.vm
instruction is expecting a vector mask register. Also the preceding vsetivli
should be changed to use a default lmul
of m1
at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
// convert the dst data from bytes to bits. | ||
vmseq_vi(v0, v8, 1); | ||
// store result back. | ||
vsetivli(x0, 1, sew, lmul); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar here. This vsetivli
instruction should be changed to use a default lmul of m1
I see chip vendors are shipping products with RVV VLEN of 128 bits. So I think it's more reasonable to go with the current implementation for now. While it seems that this would win in respect of number if instruction executed compared with the scalar version, we still need to revisit/bechmark this change when we have access to the real RVV hardware. |
@@ -1700,14 +1700,14 @@ void C2_MacroAssembler::compress_bits_v(Register dst, Register src, Register mas | |||
vmv_v_i(v8, 0); | |||
// load the mask data(in bits). | |||
vsetivli(x0, 1, sew, lmul); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also change line into "vsetivli(x0, 1, sew, Assembler::m1)" for consistency. Otherwise LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ... We still have two copy-paste issues.
src/hotspot/cpu/riscv/riscv_v.ad
Outdated
// CompressBits of Long & Integer | ||
|
||
instruct compressBitsI(iRegINoSp dst, iRegIorL2I src, iRegIorL2I mask, vRegMask_V0 v0, | ||
vReg_V4 v4, vReg_V4 v5, vReg_V8 v8, vReg_V4 v9) %{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that this should be vReg_V4 v4, vReg_V5 v5, vReg_V8 v8, vReg_V9 v9
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, thanks for catching these typos!
src/hotspot/cpu/riscv/riscv_v.ad
Outdated
|
||
instruct compressBitsL(iRegLNoSp dst, iRegL src, iRegL mask, vRegMask_V0 v0, | ||
vReg_V4 v4, vReg_V4 v5, vReg_V4 v6, vReg_V4 v7, | ||
vReg_V8 v8, vReg_V4 v9, vReg_V4 v10, vReg_V4 v11) %{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar issue here for v5-v7 and v9-v11.
@Hamlin-Li This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 77 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Thanks everyone for your review and discussion! /integrate |
Going to push as commit cb7875d.
Your commit was automatically rebased without conflicts. |
@Hamlin-Li Pushed as commit cb7875d. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Hi,
Can you review the change to add intrinsic for CompressBits for Long & Integer?
Thanks!
## Test
pass jtreg test:
test/jdk/java/lang/CompressExpand*.java
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16481/head:pull/16481
$ git checkout pull/16481
Update a local copy of the PR:
$ git checkout pull/16481
$ git pull https://git.openjdk.org/jdk.git pull/16481/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16481
View PR using the GUI difftool:
$ git pr show -t 16481
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16481.diff
Webrev
Link to Webrev Comment