guiyanakuang commented on a change in pull request #917:
URL: https://github.com/apache/orc/pull/917#discussion_r717197131



##########
File path: c++/src/Statistics.hh
##########
@@ -964,7 +964,23 @@ namespace orc {
       _stats.setSum(sum);
     }
 
-    void update(int64_t value, int repetitions);
+    void update(int64_t value, int repetitions) {
+      _stats.updateMinMax(value);
+
+      if (_stats.hasSum()) {
+        if (repetitions > 1) {
+          _stats.setHasSum(__builtin_mul_overflow(value, repetitions, &value) 
== 0);

Review comment:
       @wgtmac Sorry, I'm still a C++ novice. Let me see how compatible

##########
File path: c++/src/Statistics.hh
##########
@@ -964,7 +964,23 @@ namespace orc {
       _stats.setSum(sum);
     }
 
-    void update(int64_t value, int repetitions);
+    void update(int64_t value, int repetitions) {
+      _stats.updateMinMax(value);
+
+      if (_stats.hasSum()) {
+        if (repetitions > 1) {
+          _stats.setHasSum(__builtin_mul_overflow(value, repetitions, &value) 
== 0);

Review comment:
       
https://docs.microsoft.com/en-us/windows/win32/api/intsafe/nf-intsafe-longadd
   
https://docs.microsoft.com/en-us/windows/win32/api/intsafe/nf-intsafe-longmult
   ```c++
   #define __builtin_mul_overflow LongMult
   #define __builtin_add_overflow LongAdd
   ```
   @wgtmac Can you give me some advice, I have very little practice in C++. I 
don't have a Win machine to hand, so I can't verify if this is possible at the 
moment.

##########
File path: c++/src/Statistics.hh
##########
@@ -964,7 +964,23 @@ namespace orc {
       _stats.setSum(sum);
     }
 
-    void update(int64_t value, int repetitions);
+    void update(int64_t value, int repetitions) {
+      _stats.updateMinMax(value);
+
+      if (_stats.hasSum()) {
+        if (repetitions > 1) {
+          _stats.setHasSum(__builtin_mul_overflow(value, repetitions, &value) 
== 0);

Review comment:
       @wgtmac I made some attempts, compatibility with various compilers 
seemed difficult and I switched to rewriting to C++ following the JDK's 
algorithm.

##########
File path: c++/include/orc/orc-config.hh.in
##########
@@ -75,4 +75,38 @@
   }
 #endif
 
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
+  namespace orc {
+    /**
+     * Compute value * repetitions, return false if overflow, return true 
otherwise
+     * and save the result at the address pointed to by result
+     * imitates the jdk Math.multiplyExact implementation
+     * but this method makes the assumption that repetitions > 1
+     */
+    static bool multiplyExact(int64_t value, int64_t repetitions, int64_t* 
result) {
+      int64_t r = value * repetitions;
+      if (((value < 0 ? -value : value) | repetitions) >> 31 != 0 && r / 
repetitions != value) {
+        return false;
+      }
+      *result = r;
+      return true;
+    }

Review comment:
       Hi @dongjoon-hyun @wgtmac. Finally passed the test. But it needs a 
strict review.
   The window environment overflow check I've mimicked the JDK implementation. 
If there is a better way, please let me know.
   In fact it doesn't work well on clang (the compiler has some unknown 
behaviour that I don't know about)




-- 
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: dev-unsubscr...@orc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to