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/11/09 05:58:11 UTC

[GitHub] [arrow] cyb70289 commented on a diff in pull request #14605: ARROW-18109: [Go] Initial Unary Arithmetic

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


##########
go/arrow/compute/internal/kernels/_lib/base_arithmetic.cc:
##########
@@ -125,6 +133,69 @@ struct MultiplyChecked {
     }
 };
 
+struct AbsoluteValue {
+    template <typename T, typename Arg>
+    static constexpr T Call(Arg input) {
+        if constexpr(is_same_v<Arg, float>) {
+            *(((int*)&input)+0) &= 0x7fffffff;
+            return input;
+        } else if constexpr(is_same_v<Arg, double>) {
+            *(((int*)&input)+1) &= 0x7fffffff;

Review Comment:
   Manipulating the sign bit looks hacking. Type punning is not safe and prohibits optimizations (have to move data between floating point and general purpose registers back and forth).
   https://godbolt.org/z/srd3jjvMj
   
   Also, I'm surprised s390x CI passed, looks this code should break on big-endian machines.



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