Skip to content

Commit 78d0dc7

Browse files
committed
8357460: RISC-V: Optimize array fill stub for small size
Reviewed-by: wenanjian, fyang
1 parent 37d04a1 commit 78d0dc7

File tree

1 file changed

+34
-52
lines changed

1 file changed

+34
-52
lines changed

src/hotspot/cpu/riscv/stubGenerator_riscv.cpp

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, 2025, Red Hat Inc. All rights reserved.
4-
* Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved.
4+
* Copyright (c) 2020, 2025, Huawei Technologies Co., Ltd. All rights reserved.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66
*
77
* This code is free software; you can redistribute it and/or modify it
@@ -2196,26 +2196,26 @@ class StubGenerator: public StubCodeGenerator {
21962196
switch (t) {
21972197
case T_BYTE:
21982198
// One byte misalignment happens only for byte arrays.
2199-
__ test_bit(t0, to, 0);
2200-
__ beqz(t0, L_skip_align1);
2199+
__ test_bit(tmp_reg, to, 0);
2200+
__ beqz(tmp_reg, L_skip_align1);
22012201
__ sb(value, Address(to, 0));
22022202
__ addi(to, to, 1);
22032203
__ subiw(count, count, 1);
22042204
__ bind(L_skip_align1);
22052205
// Fallthrough
22062206
case T_SHORT:
22072207
// Two bytes misalignment happens only for byte and short (char) arrays.
2208-
__ test_bit(t0, to, 1);
2209-
__ beqz(t0, L_skip_align2);
2208+
__ test_bit(tmp_reg, to, 1);
2209+
__ beqz(tmp_reg, L_skip_align2);
22102210
__ sh(value, Address(to, 0));
22112211
__ addi(to, to, 2);
22122212
__ subiw(count, count, 2 >> shift);
22132213
__ bind(L_skip_align2);
22142214
// Fallthrough
22152215
case T_INT:
22162216
// Align to 8 bytes, we know we are 4 byte aligned to start.
2217-
__ test_bit(t0, to, 2);
2218-
__ beqz(t0, L_skip_align4);
2217+
__ test_bit(tmp_reg, to, 2);
2218+
__ beqz(tmp_reg, L_skip_align4);
22192219
__ sw(value, Address(to, 0));
22202220
__ addi(to, to, 4);
22212221
__ subiw(count, count, 4 >> shift);
@@ -2241,69 +2241,51 @@ class StubGenerator: public StubCodeGenerator {
22412241
__ fill_words(to, cnt_words, value);
22422242
}
22432243

2244-
// Remaining count is less than 8 bytes and address is heapword aligned.
2245-
Label L_fill_1, L_fill_2, L_exit1;
2244+
// Handle copies less than 8 bytes.
2245+
// Address may not be heapword aligned.
2246+
Label L_fill_1, L_fill_2, L_exit;
2247+
__ bind(L_fill_elements);
22462248
switch (t) {
22472249
case T_BYTE:
2248-
__ test_bit(t0, count, 2);
2249-
__ beqz(t0, L_fill_2);
2250-
__ sw(value, Address(to, 0));
2250+
__ test_bit(tmp_reg, count, 2);
2251+
__ beqz(tmp_reg, L_fill_2);
2252+
__ sb(value, Address(to, 0));
2253+
__ sb(value, Address(to, 1));
2254+
__ sb(value, Address(to, 2));
2255+
__ sb(value, Address(to, 3));
22512256
__ addi(to, to, 4);
2257+
22522258
__ bind(L_fill_2);
2253-
__ test_bit(t0, count, 1);
2254-
__ beqz(t0, L_fill_1);
2255-
__ sh(value, Address(to, 0));
2259+
__ test_bit(tmp_reg, count, 1);
2260+
__ beqz(tmp_reg, L_fill_1);
2261+
__ sb(value, Address(to, 0));
2262+
__ sb(value, Address(to, 1));
22562263
__ addi(to, to, 2);
2264+
22572265
__ bind(L_fill_1);
2258-
__ test_bit(t0, count, 0);
2259-
__ beqz(t0, L_exit1);
2266+
__ test_bit(tmp_reg, count, 0);
2267+
__ beqz(tmp_reg, L_exit);
22602268
__ sb(value, Address(to, 0));
22612269
break;
22622270
case T_SHORT:
2263-
__ test_bit(t0, count, 1);
2264-
__ beqz(t0, L_fill_2);
2265-
__ sw(value, Address(to, 0));
2266-
__ addi(to, to, 4);
2267-
__ bind(L_fill_2);
2268-
__ test_bit(t0, count, 0);
2269-
__ beqz(t0, L_exit1);
2271+
__ test_bit(tmp_reg, count, 1);
2272+
__ beqz(tmp_reg, L_fill_2);
22702273
__ sh(value, Address(to, 0));
2271-
break;
2272-
case T_INT:
2273-
__ beqz(count, L_exit1);
2274-
__ sw(value, Address(to, 0));
2275-
break;
2276-
default: ShouldNotReachHere();
2277-
}
2278-
__ bind(L_exit1);
2279-
__ leave();
2280-
__ ret();
2274+
__ sh(value, Address(to, 2));
2275+
__ addi(to, to, 4);
22812276

2282-
// Handle copies less than 8 bytes.
2283-
Label L_loop1, L_loop2, L_exit2;
2284-
__ bind(L_fill_elements);
2285-
__ beqz(count, L_exit2);
2286-
switch (t) {
2287-
case T_BYTE:
2288-
__ bind(L_loop1);
2289-
__ sb(value, Address(to, 0));
2290-
__ addi(to, to, 1);
2291-
__ subiw(count, count, 1);
2292-
__ bnez(count, L_loop1);
2293-
break;
2294-
case T_SHORT:
2295-
__ bind(L_loop2);
2277+
__ bind(L_fill_2);
2278+
__ test_bit(tmp_reg, count, 0);
2279+
__ beqz(tmp_reg, L_exit);
22962280
__ sh(value, Address(to, 0));
2297-
__ addi(to, to, 2);
2298-
__ subiw(count, count, 2 >> shift);
2299-
__ bnez(count, L_loop2);
23002281
break;
23012282
case T_INT:
2283+
__ beqz(count, L_exit);
23022284
__ sw(value, Address(to, 0));
23032285
break;
23042286
default: ShouldNotReachHere();
23052287
}
2306-
__ bind(L_exit2);
2288+
__ bind(L_exit);
23072289
__ leave();
23082290
__ ret();
23092291

0 commit comments

Comments
 (0)