Skip to content

Commit aaa36cc

Browse files
committed
8274242: Implement fast-path for ASCII-compatible CharsetEncoders on x86
Reviewed-by: naoto, thartmann
1 parent c4d1157 commit aaa36cc

File tree

28 files changed

+428
-391
lines changed

28 files changed

+428
-391
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16864,6 +16864,7 @@ instruct encode_iso_array(iRegP_R2 src, iRegP_R1 dst, iRegI_R3 len,
1686416864
vRegD_V2 Vtmp3, vRegD_V3 Vtmp4,
1686516865
iRegI_R0 result, rFlagsReg cr)
1686616866
%{
16867+
predicate(!((EncodeISOArrayNode*)n)->is_ascii());
1686716868
match(Set result (EncodeISOArray src (Binary dst len)));
1686816869
effect(USE_KILL src, USE_KILL dst, USE_KILL len,
1686916870
KILL Vtmp1, KILL Vtmp2, KILL Vtmp3, KILL Vtmp4, KILL cr);

src/hotspot/cpu/aarch64/matcher_aarch64.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,7 @@
163163
return true;
164164
}
165165

166+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
167+
static const bool supports_encode_ascii_array = false;
168+
166169
#endif // CPU_AARCH64_MATCHER_AARCH64_HPP

src/hotspot/cpu/arm/matcher_arm.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,7 @@
155155
return false;
156156
}
157157

158+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
159+
static const bool supports_encode_ascii_array = false;
160+
158161
#endif // CPU_ARM_MATCHER_ARM_HPP

src/hotspot/cpu/ppc/matcher_ppc.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,7 @@
164164
return VM_Version::has_fcfids();
165165
}
166166

167+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
168+
static const bool supports_encode_ascii_array = false;
167169

168170
#endif // CPU_PPC_MATCHER_PPC_HPP

src/hotspot/cpu/ppc/ppc.ad

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12789,6 +12789,7 @@ instruct has_negatives(rarg1RegP ary1, iRegIsrc len, iRegIdst result, iRegLdst t
1278912789
// encode char[] to byte[] in ISO_8859_1
1279012790
instruct encode_iso_array(rarg1RegP src, rarg2RegP dst, iRegIsrc len, iRegIdst result, iRegLdst tmp1,
1279112791
iRegLdst tmp2, iRegLdst tmp3, iRegLdst tmp4, iRegLdst tmp5, regCTR ctr, flagsRegCR0 cr0) %{
12792+
predicate(!((EncodeISOArrayNode*)n)->is_ascii());
1279212793
match(Set result (EncodeISOArray src (Binary dst len)));
1279312794
effect(TEMP_DEF result, TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, TEMP tmp5,
1279412795
USE_KILL src, USE_KILL dst, KILL ctr, KILL cr0);

src/hotspot/cpu/s390/matcher_s390.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,7 @@
152152
return true;
153153
}
154154

155+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
156+
static const bool supports_encode_ascii_array = false;
157+
155158
#endif // CPU_S390_MATCHER_S390_HPP

src/hotspot/cpu/s390/s390.ad

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10282,6 +10282,7 @@ instruct has_negatives(rarg5RegP ary1, iRegI len, iRegI result, roddRegI oddReg,
1028210282

1028310283
// encode char[] to byte[] in ISO_8859_1
1028410284
instruct encode_iso_array(iRegP src, iRegP dst, iRegI result, iRegI len, iRegI tmp, flagsReg cr) %{
10285+
predicate(!((EncodeISOArrayNode*)n)->is_ascii());
1028510286
match(Set result (EncodeISOArray src (Binary dst len)));
1028610287
effect(TEMP_DEF result, TEMP tmp, KILL cr); // R0, R1 are killed, too.
1028710288
ins_cost(300);

src/hotspot/cpu/x86/macroAssembler_x86.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5423,7 +5423,7 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
54235423
BIND(L_exit);
54245424
}
54255425

5426-
// encode char[] to byte[] in ISO_8859_1
5426+
// encode char[] to byte[] in ISO_8859_1 or ASCII
54275427
//@IntrinsicCandidate
54285428
//private static int implEncodeISOArray(byte[] sa, int sp,
54295429
//byte[] da, int dp, int len) {
@@ -5436,10 +5436,23 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
54365436
// }
54375437
// return i;
54385438
//}
5439+
//
5440+
//@IntrinsicCandidate
5441+
//private static int implEncodeAsciiArray(char[] sa, int sp,
5442+
// byte[] da, int dp, int len) {
5443+
// int i = 0;
5444+
// for (; i < len; i++) {
5445+
// char c = sa[sp++];
5446+
// if (c >= '\u0080')
5447+
// break;
5448+
// da[dp++] = (byte)c;
5449+
// }
5450+
// return i;
5451+
//}
54395452
void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
54405453
XMMRegister tmp1Reg, XMMRegister tmp2Reg,
54415454
XMMRegister tmp3Reg, XMMRegister tmp4Reg,
5442-
Register tmp5, Register result) {
5455+
Register tmp5, Register result, bool ascii) {
54435456

54445457
// rsi: src
54455458
// rdi: dst
@@ -5450,6 +5463,9 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
54505463
assert_different_registers(src, dst, len, tmp5, result);
54515464
Label L_done, L_copy_1_char, L_copy_1_char_exit;
54525465

5466+
int mask = ascii ? 0xff80ff80 : 0xff00ff00;
5467+
int short_mask = ascii ? 0xff80 : 0xff00;
5468+
54535469
// set result
54545470
xorl(result, result);
54555471
// check for zero length
@@ -5469,7 +5485,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
54695485

54705486
if (UseAVX >= 2) {
54715487
Label L_chars_32_check, L_copy_32_chars, L_copy_32_chars_exit;
5472-
movl(tmp5, 0xff00ff00); // create mask to test for Unicode chars in vector
5488+
movl(tmp5, mask); // create mask to test for Unicode or non-ASCII chars in vector
54735489
movdl(tmp1Reg, tmp5);
54745490
vpbroadcastd(tmp1Reg, tmp1Reg, Assembler::AVX_256bit);
54755491
jmp(L_chars_32_check);
@@ -5478,7 +5494,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
54785494
vmovdqu(tmp3Reg, Address(src, len, Address::times_2, -64));
54795495
vmovdqu(tmp4Reg, Address(src, len, Address::times_2, -32));
54805496
vpor(tmp2Reg, tmp3Reg, tmp4Reg, /* vector_len */ 1);
5481-
vptest(tmp2Reg, tmp1Reg); // check for Unicode chars in vector
5497+
vptest(tmp2Reg, tmp1Reg); // check for Unicode or non-ASCII chars in vector
54825498
jccb(Assembler::notZero, L_copy_32_chars_exit);
54835499
vpackuswb(tmp3Reg, tmp3Reg, tmp4Reg, /* vector_len */ 1);
54845500
vpermq(tmp4Reg, tmp3Reg, 0xD8, /* vector_len */ 1);
@@ -5493,7 +5509,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
54935509
jccb(Assembler::greater, L_copy_16_chars_exit);
54945510

54955511
} else if (UseSSE42Intrinsics) {
5496-
movl(tmp5, 0xff00ff00); // create mask to test for Unicode chars in vector
5512+
movl(tmp5, mask); // create mask to test for Unicode or non-ASCII chars in vector
54975513
movdl(tmp1Reg, tmp5);
54985514
pshufd(tmp1Reg, tmp1Reg, 0);
54995515
jmpb(L_chars_16_check);
@@ -5517,7 +5533,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
55175533
movdqu(tmp4Reg, Address(src, len, Address::times_2, -16));
55185534
por(tmp2Reg, tmp4Reg);
55195535
}
5520-
ptest(tmp2Reg, tmp1Reg); // check for Unicode chars in vector
5536+
ptest(tmp2Reg, tmp1Reg); // check for Unicode or non-ASCII chars in vector
55215537
jccb(Assembler::notZero, L_copy_16_chars_exit);
55225538
packuswb(tmp3Reg, tmp4Reg);
55235539
}
@@ -5555,7 +5571,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
55555571

55565572
bind(L_copy_1_char);
55575573
load_unsigned_short(tmp5, Address(src, len, Address::times_2, 0));
5558-
testl(tmp5, 0xff00); // check if Unicode char
5574+
testl(tmp5, short_mask); // check if Unicode or non-ASCII char
55595575
jccb(Assembler::notZero, L_copy_1_char_exit);
55605576
movb(Address(dst, len, Address::times_1, 0), tmp5);
55615577
addptr(len, 1);

src/hotspot/cpu/x86/macroAssembler_x86.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ class MacroAssembler: public Assembler {
17251725

17261726
void encode_iso_array(Register src, Register dst, Register len,
17271727
XMMRegister tmp1, XMMRegister tmp2, XMMRegister tmp3,
1728-
XMMRegister tmp4, Register tmp5, Register result);
1728+
XMMRegister tmp4, Register tmp5, Register result, bool ascii);
17291729

17301730
#ifdef _LP64
17311731
void add2_with_carry(Register dest_hi, Register dest_lo, Register src1, Register src2);

src/hotspot/cpu/x86/matcher_x86.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,7 @@
195195
return true;
196196
}
197197

198+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
199+
static const bool supports_encode_ascii_array = true;
200+
198201
#endif // CPU_X86_MATCHER_X86_HPP

0 commit comments

Comments
 (0)