Skip to content

Commit 14a1f2a

Browse files
committed
8274242: Implement fast-path for ASCII-compatible CharsetEncoders on x86
Backport-of: aaa36cc0069043e34b47e89769eb9eba39e5362a
1 parent 670d73e commit 14a1f2a

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
@@ -16830,6 +16830,7 @@ instruct encode_iso_array(iRegP_R2 src, iRegP_R1 dst, iRegI_R3 len,
1683016830
vRegD_V2 Vtmp3, vRegD_V3 Vtmp4,
1683116831
iRegI_R0 result, rFlagsReg cr)
1683216832
%{
16833+
predicate(!((EncodeISOArrayNode*)n)->is_ascii());
1683316834
match(Set result (EncodeISOArray src (Binary dst len)));
1683416835
effect(USE_KILL src, USE_KILL dst, USE_KILL len,
1683516836
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
@@ -155,4 +155,7 @@
155155
return true;
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_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
@@ -147,4 +147,7 @@
147147
return false;
148148
}
149149

150+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
151+
static const bool supports_encode_ascii_array = false;
152+
150153
#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
@@ -156,5 +156,7 @@
156156
return VM_Version::has_fcfids();
157157
}
158158

159+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
160+
static const bool supports_encode_ascii_array = false;
159161

160162
#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
@@ -12793,6 +12793,7 @@ instruct has_negatives(rarg1RegP ary1, iRegIsrc len, iRegIdst result, iRegLdst t
1279312793
// encode char[] to byte[] in ISO_8859_1
1279412794
instruct encode_iso_array(rarg1RegP src, rarg2RegP dst, iRegIsrc len, iRegIdst result, iRegLdst tmp1,
1279512795
iRegLdst tmp2, iRegLdst tmp3, iRegLdst tmp4, iRegLdst tmp5, regCTR ctr, flagsRegCR0 cr0) %{
12796+
predicate(!((EncodeISOArrayNode*)n)->is_ascii());
1279612797
match(Set result (EncodeISOArray src (Binary dst len)));
1279712798
effect(TEMP_DEF result, TEMP tmp1, TEMP tmp2, TEMP tmp3, TEMP tmp4, TEMP tmp5,
1279812799
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
@@ -144,4 +144,7 @@
144144
return true;
145145
}
146146

147+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
148+
static const bool supports_encode_ascii_array = false;
149+
147150
#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
@@ -10277,6 +10277,7 @@ instruct has_negatives(rarg5RegP ary1, iRegI len, iRegI result, roddRegI oddReg,
1027710277

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

src/hotspot/cpu/x86/macroAssembler_x86.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5614,7 +5614,7 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
56145614
BIND(L_exit);
56155615
}
56165616

5617-
// encode char[] to byte[] in ISO_8859_1
5617+
// encode char[] to byte[] in ISO_8859_1 or ASCII
56185618
//@IntrinsicCandidate
56195619
//private static int implEncodeISOArray(byte[] sa, int sp,
56205620
//byte[] da, int dp, int len) {
@@ -5627,10 +5627,23 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
56275627
// }
56285628
// return i;
56295629
//}
5630+
//
5631+
//@IntrinsicCandidate
5632+
//private static int implEncodeAsciiArray(char[] sa, int sp,
5633+
// byte[] da, int dp, int len) {
5634+
// int i = 0;
5635+
// for (; i < len; i++) {
5636+
// char c = sa[sp++];
5637+
// if (c >= '\u0080')
5638+
// break;
5639+
// da[dp++] = (byte)c;
5640+
// }
5641+
// return i;
5642+
//}
56305643
void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
56315644
XMMRegister tmp1Reg, XMMRegister tmp2Reg,
56325645
XMMRegister tmp3Reg, XMMRegister tmp4Reg,
5633-
Register tmp5, Register result) {
5646+
Register tmp5, Register result, bool ascii) {
56345647

56355648
// rsi: src
56365649
// rdi: dst
@@ -5641,6 +5654,9 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
56415654
assert_different_registers(src, dst, len, tmp5, result);
56425655
Label L_done, L_copy_1_char, L_copy_1_char_exit;
56435656

5657+
int mask = ascii ? 0xff80ff80 : 0xff00ff00;
5658+
int short_mask = ascii ? 0xff80 : 0xff00;
5659+
56445660
// set result
56455661
xorl(result, result);
56465662
// check for zero length
@@ -5660,7 +5676,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
56605676

56615677
if (UseAVX >= 2) {
56625678
Label L_chars_32_check, L_copy_32_chars, L_copy_32_chars_exit;
5663-
movl(tmp5, 0xff00ff00); // create mask to test for Unicode chars in vector
5679+
movl(tmp5, mask); // create mask to test for Unicode or non-ASCII chars in vector
56645680
movdl(tmp1Reg, tmp5);
56655681
vpbroadcastd(tmp1Reg, tmp1Reg, Assembler::AVX_256bit);
56665682
jmp(L_chars_32_check);
@@ -5669,7 +5685,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
56695685
vmovdqu(tmp3Reg, Address(src, len, Address::times_2, -64));
56705686
vmovdqu(tmp4Reg, Address(src, len, Address::times_2, -32));
56715687
vpor(tmp2Reg, tmp3Reg, tmp4Reg, /* vector_len */ 1);
5672-
vptest(tmp2Reg, tmp1Reg); // check for Unicode chars in vector
5688+
vptest(tmp2Reg, tmp1Reg); // check for Unicode or non-ASCII chars in vector
56735689
jccb(Assembler::notZero, L_copy_32_chars_exit);
56745690
vpackuswb(tmp3Reg, tmp3Reg, tmp4Reg, /* vector_len */ 1);
56755691
vpermq(tmp4Reg, tmp3Reg, 0xD8, /* vector_len */ 1);
@@ -5684,7 +5700,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
56845700
jccb(Assembler::greater, L_copy_16_chars_exit);
56855701

56865702
} else if (UseSSE42Intrinsics) {
5687-
movl(tmp5, 0xff00ff00); // create mask to test for Unicode chars in vector
5703+
movl(tmp5, mask); // create mask to test for Unicode or non-ASCII chars in vector
56885704
movdl(tmp1Reg, tmp5);
56895705
pshufd(tmp1Reg, tmp1Reg, 0);
56905706
jmpb(L_chars_16_check);
@@ -5708,7 +5724,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
57085724
movdqu(tmp4Reg, Address(src, len, Address::times_2, -16));
57095725
por(tmp2Reg, tmp4Reg);
57105726
}
5711-
ptest(tmp2Reg, tmp1Reg); // check for Unicode chars in vector
5727+
ptest(tmp2Reg, tmp1Reg); // check for Unicode or non-ASCII chars in vector
57125728
jccb(Assembler::notZero, L_copy_16_chars_exit);
57135729
packuswb(tmp3Reg, tmp4Reg);
57145730
}
@@ -5746,7 +5762,7 @@ void MacroAssembler::encode_iso_array(Register src, Register dst, Register len,
57465762

57475763
bind(L_copy_1_char);
57485764
load_unsigned_short(tmp5, Address(src, len, Address::times_2, 0));
5749-
testl(tmp5, 0xff00); // check if Unicode char
5765+
testl(tmp5, short_mask); // check if Unicode or non-ASCII char
57505766
jccb(Assembler::notZero, L_copy_1_char_exit);
57515767
movb(Address(dst, len, Address::times_1, 0), tmp5);
57525768
addptr(len, 1);

src/hotspot/cpu/x86/macroAssembler_x86.hpp

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

17351735
void encode_iso_array(Register src, Register dst, Register len,
17361736
XMMRegister tmp1, XMMRegister tmp2, XMMRegister tmp3,
1737-
XMMRegister tmp4, Register tmp5, Register result);
1737+
XMMRegister tmp4, Register tmp5, Register result, bool ascii);
17381738

17391739
#ifdef _LP64
17401740
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
@@ -191,4 +191,7 @@
191191
return true;
192192
}
193193

194+
// Implements a variant of EncodeISOArrayNode that encode ASCII only
195+
static const bool supports_encode_ascii_array = true;
196+
194197
#endif // CPU_X86_MATCHER_X86_HPP

0 commit comments

Comments
 (0)