wpleonardo commented on code in PR #1375:
URL: https://github.com/apache/orc/pull/1375#discussion_r1169459975


##########
c++/src/BpackingAvx512.cc:
##########
@@ -0,0 +1,2694 @@
+/**
+ * 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.
+ */
+
+#include "BpackingAvx512.hh"
+#include "BitUnpackerAvx512.hh"
+#include "CpuInfoUtil.hh"
+#include "RLEv2.hh"
+
+namespace orc {
+  UnpackAvx512::UnpackAvx512(RleDecoderV2* dec) : decoder(dec), 
unpackDefault(UnpackDefault(dec)) {
+    // PASS
+  }
+
+  UnpackAvx512::~UnpackAvx512() {
+    // PASS
+  }
+
+  inline void UnpackAvx512::alignHeaderBoundary(const uint32_t bitWidth, const 
uint32_t bitMaxSize,
+                                                uint64_t& startBit, uint64_t& 
bufMoveByteLen,
+                                                uint64_t& bufRestByteLen,
+                                                uint64_t& remainingNumElements,
+                                                uint64_t& tailBitLen, 
uint32_t& backupByteLen,
+                                                uint64_t& numElements, bool& 
resetBuf,
+                                                const uint8_t*& srcPtr, 
int64_t*& dstPtr) {
+    if (startBit != 0) {
+      bufMoveByteLen +=
+          moveByteLen(remainingNumElements * bitWidth + startBit - 
ORC_VECTOR_BYTE_WIDTH);
+    } else {
+      bufMoveByteLen += moveByteLen(remainingNumElements * bitWidth);
+    }
+
+    if (bufMoveByteLen <= bufRestByteLen) {
+      numElements = remainingNumElements;
+      resetBuf = false;
+      remainingNumElements = 0;
+    } else {
+      uint64_t leadingBits = 0;
+      if (startBit != 0) leadingBits = ORC_VECTOR_BYTE_WIDTH - startBit;
+      uint64_t bufRestBitLen = bufRestByteLen * ORC_VECTOR_BYTE_WIDTH + 
leadingBits;
+      numElements = bufRestBitLen / bitWidth;
+      remainingNumElements -= numElements;
+      tailBitLen = fmod(bufRestBitLen, bitWidth);
+      resetBuf = true;
+    }
+
+    if (tailBitLen != 0) {
+      backupByteLen = tailBitLen / ORC_VECTOR_BYTE_WIDTH;
+      tailBitLen = 0;
+    }
+
+    if (startBit > 0) {
+      uint32_t align = getAlign(startBit, bitWidth, bitMaxSize);
+      if (align > numElements) {
+        align = numElements;
+      }
+      if (align != 0) {
+        bufMoveByteLen -= moveByteLen(align * bitWidth + startBit - 
ORC_VECTOR_BYTE_WIDTH);
+        plainUnpackLongs(dstPtr, 0, align, bitWidth, startBit);
+        srcPtr = reinterpret_cast<const uint8_t*>(decoder->bufferStart);
+        bufRestByteLen = decoder->bufferEnd - decoder->bufferStart;
+        dstPtr += align;
+        numElements -= align;
+      }
+    }
+  }
+
+  inline void UnpackAvx512::alignTailerBoundary(const uint32_t bitWidth, 
uint64_t& startBit,
+                                                uint64_t& bufMoveByteLen, 
uint64_t& bufRestByteLen,
+                                                uint64_t& remainingNumElements,
+                                                uint32_t& backupByteLen, 
uint64_t& numElements,
+                                                bool& resetBuf, const 
uint8_t*& srcPtr,
+                                                int64_t*& dstPtr) {
+    if (numElements > 0) {
+      if (startBit != 0) {
+        bufMoveByteLen -= moveByteLen(numElements * bitWidth + startBit - 
ORC_VECTOR_BYTE_WIDTH);
+      } else {
+        bufMoveByteLen -= moveByteLen(numElements * bitWidth);
+      }
+      plainUnpackLongs(dstPtr, 0, numElements, bitWidth, startBit);
+      srcPtr = reinterpret_cast<const uint8_t*>(decoder->bufferStart);
+      dstPtr += numElements;
+      bufRestByteLen = decoder->bufferEnd - decoder->bufferStart;
+    }
+
+    if (bufMoveByteLen <= bufRestByteLen) {
+      decoder->resetBufferStart(&decoder->bufferStart, &decoder->bufferEnd, 
bufMoveByteLen,
+                                resetBuf, backupByteLen);
+      return;
+    }
+
+    if (backupByteLen != 0) {
+      decoder->resetBufferStart(&decoder->bufferStart, &decoder->bufferEnd, 
bufRestByteLen,
+                                resetBuf, backupByteLen);
+      plainUnpackLongs(dstPtr, 0, 1, bitWidth, startBit);
+      dstPtr++;
+      backupByteLen = 0;
+      remainingNumElements--;
+    } else {
+      decoder->resetBufferStart(&decoder->bufferStart, &decoder->bufferEnd, 
bufRestByteLen,
+                                resetBuf, backupByteLen);

Review Comment:
   Fixed



##########
c++/src/RLEv2.hh:
##########
@@ -220,17 +221,36 @@ namespace orc {
 
     const std::unique_ptr<SeekableInputStream> inputStream;
     const bool isSigned;
-
     unsigned char firstByte;
-    uint64_t runLength;  // Length of the current run
-    uint64_t runRead;    // Number of returned values of the current run
-    const char* bufferStart;
-    const char* bufferEnd;
-    uint32_t bitsLeft;                  // Used by readLongs when bitSize < 8
-    uint32_t curByte;                   // Used by anything that uses readLongs
+    uint64_t runLength;                 // Length of the current run
+    uint64_t runRead;                   // Number of returned values of the 
current run
     DataBuffer<int64_t> unpackedPatch;  // Used by PATCHED_BASE
     DataBuffer<int64_t> literals;       // Values of the current run
   };
+
+  inline void RleDecoderV2::resetBufferStart(char** bufStart, char** bufEnd, 
uint64_t len,
+                                             bool resetBuf, uint32_t 
backupByteLen) {
+    uint64_t remainingLen = *bufEnd - *bufStart;
+    int bufferLength = 0;
+    const void* bufferPointer = nullptr;
+
+    if (backupByteLen != 0) {
+      inputStream->BackUp(backupByteLen);
+    }
+
+    if (len >= remainingLen && resetBuf == true) {

Review Comment:
   fixed



-- 
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]

Reply via email to