sonatype-lift[bot] commented on a change in pull request #562: URL: https://github.com/apache/lucene/pull/562#discussion_r774484808
########## File path: lucene/core/src/java/org/apache/lucene/util/packed/ForUtil.java ########## @@ -0,0 +1,3329 @@ +// This file has been automatically generated, DO NOT EDIT + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.util.packed; + +import java.io.IOException; +import org.apache.lucene.store.DataInput; +import org.apache.lucene.store.DataOutput; +import org.apache.lucene.util.MathUtil; + +// Inspired from https://fulmicoton.com/posts/bitpacking/ +// Encodes multiple integers in a long to get SIMD-like speedups. +// If bitsPerValue <= 8 then we pack 8 ints per long +// else if bitsPerValue <= 16 we pack 4 ints per long +// else we pack 2 ints per long +final class ForUtil { + + static final int BLOCK_SIZE = 128; + static final int BLOCK_SIZE_LOG2 = MathUtil.log(BLOCK_SIZE, 2); + private static final int BLOCK_SIZE_DIV_2 = BLOCK_SIZE >> 1; + private static final int BLOCK_SIZE_DIV_4 = BLOCK_SIZE >> 2; + static final int BLOCK_SIZE_DIV_8 = BLOCK_SIZE >> 3; + private static final int BLOCK_SIZE_DIV_64 = BLOCK_SIZE >> 6; + private static final int BLOCK_SIZE_DIV_8_MUL_1 = BLOCK_SIZE_DIV_8; + private static final int BLOCK_SIZE_DIV_8_MUL_2 = BLOCK_SIZE_DIV_8 * 2; + private static final int BLOCK_SIZE_DIV_8_MUL_3 = BLOCK_SIZE_DIV_8 * 3; + private static final int BLOCK_SIZE_DIV_8_MUL_4 = BLOCK_SIZE_DIV_8 * 4; + private static final int BLOCK_SIZE_DIV_8_MUL_5 = BLOCK_SIZE_DIV_8 * 5; + private static final int BLOCK_SIZE_DIV_8_MUL_6 = BLOCK_SIZE_DIV_8 * 6; + private static final int BLOCK_SIZE_DIV_8_MUL_7 = BLOCK_SIZE_DIV_8 * 7; + private static final int BLOCK_SIZE_LOG2_MIN_3 = BLOCK_SIZE_LOG2 - 3; + + private static long expandMask32(long mask32) { + return mask32 | (mask32 << 32); + } + + private static long expandMask16(long mask16) { + return expandMask32(mask16 | (mask16 << 16)); + } + + private static long expandMask8(long mask8) { + return expandMask16(mask8 | (mask8 << 8)); + } + + private static long mask32(int bitsPerValue) { + return expandMask32((1L << bitsPerValue) - 1); + } + + private static long mask64(int bitsPerValue) { + return (1L << bitsPerValue) - 1; + } + + private static long mask16(int bitsPerValue) { + return expandMask16((1L << bitsPerValue) - 1); + } + + private static long mask8(int bitsPerValue) { + return expandMask8((1L << bitsPerValue) - 1); + } + + private static void expand8(long[] arr) { + for (int i = 0; i < BLOCK_SIZE_DIV_8; ++i) { + long l = arr[i]; + arr[i] = (l >>> 56) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_1 + i] = (l >>> 48) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_2 + i] = (l >>> 40) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_3 + i] = (l >>> 32) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_4 + i] = (l >>> 24) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_5 + i] = (l >>> 16) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_6 + i] = (l >>> 8) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_7 + i] = l & 0xFFL; + } + } + + private static void expand8To32(long[] arr) { + for (int i = 0; i < BLOCK_SIZE_DIV_8; ++i) { + long l = arr[i]; + arr[i] = (l >>> 24) & 0x000000FF000000FFL; + arr[BLOCK_SIZE_DIV_8_MUL_1 + i] = (l >>> 16) & 0x000000FF000000FFL; + arr[BLOCK_SIZE_DIV_8_MUL_2 + i] = (l >>> 8) & 0x000000FF000000FFL; + arr[BLOCK_SIZE_DIV_8_MUL_3 + i] = l & 0x000000FF000000FFL; + } + } + + private static void collapse8(long[] arr) { + for (int i = 0; i < BLOCK_SIZE_DIV_8; ++i) { + arr[i] = + (arr[i] << 56) + | (arr[BLOCK_SIZE_DIV_8_MUL_1 + i] << 48) + | (arr[BLOCK_SIZE_DIV_8_MUL_2 + i] << 40) + | (arr[BLOCK_SIZE_DIV_8_MUL_3 + i] << 32) + | (arr[BLOCK_SIZE_DIV_8_MUL_4 + i] << 24) + | (arr[BLOCK_SIZE_DIV_8_MUL_5 + i] << 16) + | (arr[BLOCK_SIZE_DIV_8_MUL_6 + i] << 8) + | arr[BLOCK_SIZE_DIV_8_MUL_7 + i]; + } + } + + private static void expand16(long[] arr) { + for (int i = 0; i < BLOCK_SIZE_DIV_4; ++i) { + long l = arr[i]; + arr[i] = (l >>> 48) & 0xFFFFL; + arr[BLOCK_SIZE_DIV_8_MUL_2 + i] = (l >>> 32) & 0xFFFFL; + arr[BLOCK_SIZE_DIV_8_MUL_4 + i] = (l >>> 16) & 0xFFFFL; + arr[BLOCK_SIZE_DIV_8_MUL_6 + i] = l & 0xFFFFL; + } + } + + private static void expand16To32(long[] arr) { Review comment: *UnusedMethod:* Private method 'expand16To32' is never used. [(details)](https://errorprone.info/bugpattern/UnusedMethod) (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`) ########## File path: lucene/core/src/java/org/apache/lucene/util/packed/ForUtil.java ########## @@ -0,0 +1,3329 @@ +// This file has been automatically generated, DO NOT EDIT + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.util.packed; + +import java.io.IOException; +import org.apache.lucene.store.DataInput; +import org.apache.lucene.store.DataOutput; +import org.apache.lucene.util.MathUtil; + +// Inspired from https://fulmicoton.com/posts/bitpacking/ +// Encodes multiple integers in a long to get SIMD-like speedups. +// If bitsPerValue <= 8 then we pack 8 ints per long +// else if bitsPerValue <= 16 we pack 4 ints per long +// else we pack 2 ints per long +final class ForUtil { + + static final int BLOCK_SIZE = 128; + static final int BLOCK_SIZE_LOG2 = MathUtil.log(BLOCK_SIZE, 2); + private static final int BLOCK_SIZE_DIV_2 = BLOCK_SIZE >> 1; + private static final int BLOCK_SIZE_DIV_4 = BLOCK_SIZE >> 2; + static final int BLOCK_SIZE_DIV_8 = BLOCK_SIZE >> 3; + private static final int BLOCK_SIZE_DIV_64 = BLOCK_SIZE >> 6; + private static final int BLOCK_SIZE_DIV_8_MUL_1 = BLOCK_SIZE_DIV_8; + private static final int BLOCK_SIZE_DIV_8_MUL_2 = BLOCK_SIZE_DIV_8 * 2; + private static final int BLOCK_SIZE_DIV_8_MUL_3 = BLOCK_SIZE_DIV_8 * 3; + private static final int BLOCK_SIZE_DIV_8_MUL_4 = BLOCK_SIZE_DIV_8 * 4; + private static final int BLOCK_SIZE_DIV_8_MUL_5 = BLOCK_SIZE_DIV_8 * 5; + private static final int BLOCK_SIZE_DIV_8_MUL_6 = BLOCK_SIZE_DIV_8 * 6; + private static final int BLOCK_SIZE_DIV_8_MUL_7 = BLOCK_SIZE_DIV_8 * 7; + private static final int BLOCK_SIZE_LOG2_MIN_3 = BLOCK_SIZE_LOG2 - 3; + + private static long expandMask32(long mask32) { + return mask32 | (mask32 << 32); + } + + private static long expandMask16(long mask16) { + return expandMask32(mask16 | (mask16 << 16)); + } + + private static long expandMask8(long mask8) { + return expandMask16(mask8 | (mask8 << 8)); + } + + private static long mask32(int bitsPerValue) { + return expandMask32((1L << bitsPerValue) - 1); + } + + private static long mask64(int bitsPerValue) { + return (1L << bitsPerValue) - 1; + } + + private static long mask16(int bitsPerValue) { + return expandMask16((1L << bitsPerValue) - 1); + } + + private static long mask8(int bitsPerValue) { + return expandMask8((1L << bitsPerValue) - 1); + } + + private static void expand8(long[] arr) { + for (int i = 0; i < BLOCK_SIZE_DIV_8; ++i) { + long l = arr[i]; + arr[i] = (l >>> 56) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_1 + i] = (l >>> 48) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_2 + i] = (l >>> 40) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_3 + i] = (l >>> 32) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_4 + i] = (l >>> 24) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_5 + i] = (l >>> 16) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_6 + i] = (l >>> 8) & 0xFFL; + arr[BLOCK_SIZE_DIV_8_MUL_7 + i] = l & 0xFFL; + } + } + + private static void expand8To32(long[] arr) { Review comment: *UnusedMethod:* Private method 'expand8To32' is never used. [(details)](https://errorprone.info/bugpattern/UnusedMethod) (at-me [in a reply](https://help.sonatype.com/lift/talking-to-lift) with `help` or `ignore`) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
