Skip to content

Commit 7c60b9c

Browse files
author
Sandhya Viswanathan
committedFeb 17, 2023
8302358: Behavior of adler32 changes after JDK-8300208
Reviewed-by: kvn, jbhateja
1 parent 86b9fce commit 7c60b9c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed
 

‎src/hotspot/cpu/x86/stubGenerator_x86_64_adler.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ address StubGenerator::generate_updateBytesAdler32() {
110110
const XMMRegister xtmp4 = xmm9;
111111
const XMMRegister xtmp5 = xmm10;
112112

113-
Label SLOOP1, SPRELOOP1A_AVX2, SLOOP1A_AVX2, SLOOP1A_AVX3, AVX3_REDUCE, SKIP_LOOP_1A;
113+
Label SLOOP1, SLOOP1A_AVX2, SLOOP1A_AVX3, AVX3_REDUCE, SKIP_LOOP_1A;
114114
Label SKIP_LOOP_1A_AVX3, FINISH, LT64, DO_FINAL, FINAL_LOOP, ZERO_SIZE, END;
115115

116116
__ enter(); // required for proper stackwalking of RuntimeStub frame
@@ -133,6 +133,7 @@ address StubGenerator::generate_updateBytesAdler32() {
133133
__ movdl(xa, init_d); //vmovd - 32bit
134134

135135
__ bind(SLOOP1);
136+
__ vpxor(yb, yb, yb, VM_Version::supports_avx512vl() ? Assembler::AVX_512bit : Assembler::AVX_256bit);
136137
__ movl(s, LIMIT);
137138
__ cmpl(s, size);
138139
__ cmovl(Assembler::above, s, size); // s = min(size, LIMIT)
@@ -144,10 +145,8 @@ address StubGenerator::generate_updateBytesAdler32() {
144145
if (VM_Version::supports_avx512vl()) {
145146
// AVX2 performs better for smaller inputs because of leaner post loop reduction sequence..
146147
__ cmpl(s, MAX2(128, VM_Version::avx3_threshold()));
147-
__ jcc(Assembler::belowEqual, SPRELOOP1A_AVX2);
148-
148+
__ jcc(Assembler::belowEqual, SLOOP1A_AVX2);
149149
__ lea(end, Address(s, data, Address::times_1, - (2*CHUNKSIZE -1)));
150-
__ vpxor(yb, yb, yb, Assembler::AVX_512bit);
151150

152151
// Some notes on vectorized main loop algorithm.
153152
// Additions are performed in slices of 16 bytes in the main loop.
@@ -164,8 +163,8 @@ address StubGenerator::generate_updateBytesAdler32() {
164163
// Since addition was performed in chunks of 16 bytes, thus to match the scalar implementation
165164
// Oth lane element must be repeatedly added 16 times, 1st element 15 times and so on so forth.
166165
// Thus we first multiply yb by 16 followed by subtracting appropriately scaled ya value.
167-
// yb = 16 x yb - [0 - 15] x ya
168-
// = 64 x [0 - 15] + 48 x [16 - 31] + 32 x [32 - 47] + 16 x [48 - 63] - [0 - 15] x ya
166+
// yb = 16 x yb - [a0 - a15] x ya
167+
// = 64 x [a0 - a15] + 48 x [a16 - a31] + 32 x [a32 - a47] + 16 x [a48 - a63] - [a0 - a15] x ya
169168
// = 64 x a0 + 63 x a1 + 62 x a2 ...... + a63
170169
__ bind(SLOOP1A_AVX3);
171170
__ evpmovzxbd(ydata0, Address(data, 0), Assembler::AVX_512bit);
@@ -220,8 +219,6 @@ address StubGenerator::generate_updateBytesAdler32() {
220219
}
221220

222221
__ align32();
223-
__ bind(SPRELOOP1A_AVX2);
224-
__ vpxor(yb, yb, yb, Assembler::AVX_256bit);
225222
__ bind(SLOOP1A_AVX2);
226223
__ vbroadcastf128(ydata, Address(data, 0), Assembler::AVX_256bit);
227224
__ addptr(data, CHUNKSIZE);

‎test/hotspot/jtreg/compiler/intrinsics/zip/TestAdler32.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -146,7 +146,7 @@ private static boolean check(Checksum adler0, Checksum adler1) {
146146
if (adler0.getValue() != adler1.getValue()) {
147147
System.err.printf("ERROR: adler0 = %08x, adler1 = %08x\n",
148148
adler0.getValue(), adler1.getValue());
149-
throw new AssertionError("TEST FAILED", null);
149+
return false;
150150
}
151151
return true;
152152
}
@@ -166,6 +166,7 @@ private static void test_multi(int iters) {
166166
int len1 = 8; // the 8B/iteration loop
167167
int len2 = 32; // the 32B/iteration loop
168168
int len3 = 4096; // the 4KB/iteration loop
169+
int len4 = 5552; // the adler limit
169170

170171
byte[] b = initializedBytes(len3*16, 0);
171172
int[] offsets = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 256, 512 };
@@ -176,6 +177,8 @@ private static void test_multi(int iters) {
176177
len2*2, len2*4, len2*8, len2*16, len2*32, len2*64,
177178
len3, len3+1, len3+3, len3+5, len3+7,
178179
len3*2, len3*4, len3*8,
180+
len4, len4+1, len4+3, len4+5, len4+7, len4+len1, len4+len2, len4+len3,
181+
len4*2, len4*4, len4*2+1, len4*4+4,
179182
len1+len2, len1+len2+1, len1+len2+3, len1+len2+5, len1+len2+7,
180183
len1+len3, len1+len3+1, len1+len3+3, len1+len3+5, len1+len3+7,
181184
len2+len3, len2+len3+1, len2+len3+3, len2+len3+5, len2+len3+7,
@@ -214,8 +217,9 @@ private static void test_multi(int iters) {
214217
for (i = 0; i < offsets.length; i++) {
215218
for (j = 0; j < sizes.length; j++) {
216219
if (!check(adler0[i*sizes.length + j], adler1[i*sizes.length + j])) {
217-
System.out.printf("offsets[%d] = %d", i, offsets[i]);
218-
System.out.printf("\tsizes[%d] = %d\n", j, sizes[j]);
220+
System.out.printf("Failed at: offsets[%d] = %d", i, offsets[i]);
221+
System.out.printf(", sizes[%d] = %d\n", j, sizes[j]);
222+
throw new AssertionError("TEST FAILED", null);
219223
}
220224
}
221225
}

0 commit comments

Comments
 (0)
Please sign in to comment.