You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/17 09:22:43 UTC

[GitHub] [arrow] cyb70289 commented on a diff in pull request #13393: ARROW-16849: [C++][compute] Replace If-Else branch with bitwise operators in aggregate_basic_internal

cyb70289 commented on code in PR #13393:
URL: https://github.com/apache/arrow/pull/13393#discussion_r899939657


##########
cpp/src/arrow/compute/kernels/aggregate_basic_internal.h:
##########
@@ -186,11 +186,8 @@ struct MeanImpl : public SumImpl<ArrowType, SimdLevel> {
       // Round the decimal result based on the remainder
       remainder.Abs();
       if (remainder * 2 >= this->count) {
-        if (this->sum >= 0) {
-          quotient += 1;
-        } else {
-          quotient -= 1;
-        }
+        auto flag = this->sum >= 0;
+        quotient = quotient + (1 & flag) - (1 & (!flag));

Review Comment:
   My gut feeling is compiler should be able to do necessary optimization of this code pattern. It may be better to keep current more readable code.
   Do you have benchmark result? Or can you write a short test code and compare the machine code on godblot?



-- 
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: github-unsubscribe@arrow.apache.org

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