@@ -2029,44 +2029,40 @@ class StubGenerator: public StubCodeGenerator {
20292029
20302030 __ enter ();
20312031
2032- Label L_fill_elements, L_exit1 ;
2032+ Label L_fill_elements;
20332033
20342034 int shift = -1 ;
20352035 switch (t) {
20362036 case T_BYTE:
20372037 shift = 0 ;
2038+ // Short arrays (< 8 bytes) fill by element
2039+ __ mv (tmp_reg, 8 >> shift);
2040+ __ bltu (count, tmp_reg, L_fill_elements);
20382041
20392042 // Zero extend value
20402043 // 8 bit -> 16 bit
20412044 __ zext (value, value, 8 );
2042- __ mv (tmp_reg, value);
2043- __ slli (tmp_reg, tmp_reg, 8 );
2045+ __ slli (tmp_reg, value, 8 );
20442046 __ orr (value, value, tmp_reg);
20452047
20462048 // 16 bit -> 32 bit
2047- __ mv (tmp_reg, value);
2048- __ slli (tmp_reg, tmp_reg, 16 );
2049+ __ slli (tmp_reg, value, 16 );
20492050 __ orr (value, value, tmp_reg);
2050-
2051- __ mv (tmp_reg, 8 >> shift); // Short arrays (< 8 bytes) fill by element
2052- __ bltu (count, tmp_reg, L_fill_elements);
20532051 break ;
20542052 case T_SHORT:
20552053 shift = 1 ;
2054+ // Short arrays (< 8 bytes) fill by element
2055+ __ mv (tmp_reg, 8 >> shift);
2056+ __ bltu (count, tmp_reg, L_fill_elements);
2057+
20562058 // Zero extend value
20572059 // 16 bit -> 32 bit
20582060 __ zext (value, value, 16 );
2059- __ mv (tmp_reg, value);
2060- __ slli (tmp_reg, tmp_reg, 16 );
2061+ __ slli (tmp_reg, value, 16 );
20612062 __ orr (value, value, tmp_reg);
2062-
2063- // Short arrays (< 8 bytes) fill by element
2064- __ mv (tmp_reg, 8 >> shift);
2065- __ bltu (count, tmp_reg, L_fill_elements);
20662063 break ;
20672064 case T_INT:
20682065 shift = 2 ;
2069-
20702066 // Short arrays (< 8 bytes) fill by element
20712067 __ mv (tmp_reg, 8 >> shift);
20722068 __ bltu (count, tmp_reg, L_fill_elements);
@@ -2125,20 +2121,8 @@ class StubGenerator: public StubCodeGenerator {
21252121 __ fill_words (to, cnt_words, value);
21262122 }
21272123
2128- // Remaining count is less than 8 bytes. Fill it by a single store.
2129- // Note that the total length is no less than 8 bytes.
2130- if (!AvoidUnalignedAccesses && (t == T_BYTE || t == T_SHORT)) {
2131- __ beqz (count, L_exit1);
2132- __ shadd (to, count, to, tmp_reg, shift); // points to the end
2133- __ sd (value, Address (to, -8 )); // overwrite some elements
2134- __ bind (L_exit1);
2135- __ leave ();
2136- __ ret ();
2137- }
2138-
2139- // Handle copies less than 8 bytes.
2140- Label L_fill_2, L_fill_4, L_exit2;
2141- __ bind (L_fill_elements);
2124+ // Remaining count is less than 8 bytes and address is heapword aligned.
2125+ Label L_fill_2, L_fill_4, L_exit1;
21422126 switch (t) {
21432127 case T_BYTE:
21442128 __ test_bit (t0, count, 0 );
@@ -2152,7 +2136,7 @@ class StubGenerator: public StubCodeGenerator {
21522136 __ addi (to, to, 2 );
21532137 __ bind (L_fill_4);
21542138 __ test_bit (t0, count, 2 );
2155- __ beqz (t0, L_exit2 );
2139+ __ beqz (t0, L_exit1 );
21562140 __ sw (value, Address (to, 0 ));
21572141 break ;
21582142 case T_SHORT:
@@ -2162,18 +2146,47 @@ class StubGenerator: public StubCodeGenerator {
21622146 __ addi (to, to, 2 );
21632147 __ bind (L_fill_4);
21642148 __ test_bit (t0, count, 1 );
2165- __ beqz (t0, L_exit2 );
2149+ __ beqz (t0, L_exit1 );
21662150 __ sw (value, Address (to, 0 ));
21672151 break ;
21682152 case T_INT:
2169- __ beqz (count, L_exit2);
2153+ __ beqz (count, L_exit1);
2154+ __ sw (value, Address (to, 0 ));
2155+ break ;
2156+ default : ShouldNotReachHere ();
2157+ }
2158+ __ bind (L_exit1);
2159+ __ leave ();
2160+ __ ret ();
2161+
2162+ // Handle copies less than 8 bytes.
2163+ Label L_loop1, L_loop2, L_exit2;
2164+ __ bind (L_fill_elements);
2165+ __ beqz (count, L_exit2);
2166+ switch (t) {
2167+ case T_BYTE:
2168+ __ bind (L_loop1);
2169+ __ sb (value, Address (to, 0 ));
2170+ __ addi (to, to, 1 );
2171+ __ subiw (count, count, 1 );
2172+ __ bnez (count, L_loop1);
2173+ break ;
2174+ case T_SHORT:
2175+ __ bind (L_loop2);
2176+ __ sh (value, Address (to, 0 ));
2177+ __ addi (to, to, 2 );
2178+ __ subiw (count, count, 2 >> shift);
2179+ __ bnez (count, L_loop2);
2180+ break ;
2181+ case T_INT:
21702182 __ sw (value, Address (to, 0 ));
21712183 break ;
21722184 default : ShouldNotReachHere ();
21732185 }
21742186 __ bind (L_exit2);
21752187 __ leave ();
21762188 __ ret ();
2189+
21772190 return start;
21782191 }
21792192
0 commit comments