uschindler commented on code in PR #12417: URL: https://github.com/apache/lucene/pull/12417#discussion_r1253370894
########## lucene/core/src/java/org/apache/lucene/internal/vectorization/DefaultForUtil90.java: ########## @@ -0,0 +1,135 @@ +// 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.internal.vectorization; + +import java.io.IOException; +import org.apache.lucene.store.DataInput; +import org.apache.lucene.store.DataOutput; + +final class DefaultForUtil90 implements ForUtil90 { + private final int[] tmp = new int[BLOCK_SIZE]; + + private static final int totalBits = 32; + + /** Encode 128 integers from {@code longs} into {@code out}. */ + public void encode(int[] input, int bitsPerValue, DataOutput out) throws IOException { + int MASK = (1 << bitsPerValue) - 1; + int cur = 0; + int bitsRemaining = totalBits; + tmp[0] = 0; + tmp[1] = 0; + tmp[2] = 0; + tmp[3] = 0; + for (int i = 0; i < input.length; i += 4) { + tmp[cur] |= (input[i] & MASK) << (totalBits - bitsRemaining); + tmp[cur + 1] |= (input[i + 1] & MASK) << (totalBits - bitsRemaining); + tmp[cur + 2] |= (input[i + 2] & MASK) << (totalBits - bitsRemaining); + tmp[cur + 3] |= (input[i + 3] & MASK) << (totalBits - bitsRemaining); + + bitsRemaining -= bitsPerValue; + + if (bitsRemaining < 0) { + cur += 4; + tmp[cur] = 0; + tmp[cur + 1] = 0; + tmp[cur + 2] = 0; + tmp[cur + 3] = 0; + tmp[cur] |= ((input[i] & MASK) >>> (bitsPerValue + bitsRemaining)); + tmp[cur + 1] |= ((input[i + 1] & MASK) >>> (bitsPerValue + bitsRemaining)); + tmp[cur + 2] |= ((input[i + 2] & MASK) >>> (bitsPerValue + bitsRemaining)); + tmp[cur + 3] |= ((input[i + 3] & MASK) >>> (bitsPerValue + bitsRemaining)); + bitsRemaining += totalBits; + } + + if (bitsRemaining == 0) { + cur += 4; + tmp[cur] = 0; + tmp[cur + 1] = 0; + tmp[cur + 2] = 0; + tmp[cur + 3] = 0; + bitsRemaining = totalBits; + } + } + + for (int i = 0; i < 4 * bitsPerValue; ++i) { + out.writeInt(tmp[i]); + } + } + + /** Decode 128 integers into {@code longs}. */ + public void decode(int bitsPerValue, DataInput in, int[] output) throws IOException { + for (int i = 0; i < 4 * bitsPerValue; ++i) { + tmp[i] = in.readInt(); Review Comment: We can use readInts() here ########## lucene/core/src/java/org/apache/lucene/internal/vectorization/DefaultForUtil90.java: ########## @@ -0,0 +1,135 @@ +// 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.internal.vectorization; + +import java.io.IOException; +import org.apache.lucene.store.DataInput; +import org.apache.lucene.store.DataOutput; + +final class DefaultForUtil90 implements ForUtil90 { + private final int[] tmp = new int[BLOCK_SIZE]; + + private static final int totalBits = 32; + + /** Encode 128 integers from {@code longs} into {@code out}. */ + public void encode(int[] input, int bitsPerValue, DataOutput out) throws IOException { + int MASK = (1 << bitsPerValue) - 1; + int cur = 0; + int bitsRemaining = totalBits; + tmp[0] = 0; + tmp[1] = 0; + tmp[2] = 0; + tmp[3] = 0; + for (int i = 0; i < input.length; i += 4) { + tmp[cur] |= (input[i] & MASK) << (totalBits - bitsRemaining); + tmp[cur + 1] |= (input[i + 1] & MASK) << (totalBits - bitsRemaining); + tmp[cur + 2] |= (input[i + 2] & MASK) << (totalBits - bitsRemaining); + tmp[cur + 3] |= (input[i + 3] & MASK) << (totalBits - bitsRemaining); + + bitsRemaining -= bitsPerValue; + + if (bitsRemaining < 0) { + cur += 4; + tmp[cur] = 0; + tmp[cur + 1] = 0; + tmp[cur + 2] = 0; + tmp[cur + 3] = 0; + tmp[cur] |= ((input[i] & MASK) >>> (bitsPerValue + bitsRemaining)); + tmp[cur + 1] |= ((input[i + 1] & MASK) >>> (bitsPerValue + bitsRemaining)); + tmp[cur + 2] |= ((input[i + 2] & MASK) >>> (bitsPerValue + bitsRemaining)); + tmp[cur + 3] |= ((input[i + 3] & MASK) >>> (bitsPerValue + bitsRemaining)); + bitsRemaining += totalBits; + } + + if (bitsRemaining == 0) { + cur += 4; + tmp[cur] = 0; + tmp[cur + 1] = 0; + tmp[cur + 2] = 0; + tmp[cur + 3] = 0; + bitsRemaining = totalBits; + } + } + + for (int i = 0; i < 4 * bitsPerValue; ++i) { + out.writeInt(tmp[i]); + } + } + + /** Decode 128 integers into {@code longs}. */ Review Comment: comment wrong -- 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]
