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


##########
go/arrow/compute/internal/kernels/_lib/base_arithmetic.cc:
##########
@@ -0,0 +1,175 @@
+// 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 <arch.h>
+#include <stdint.h>
+#include "types.h"
+#include "vendored/safe-math.h"
+
+// Corresponds to equivalent ArithmeticOp enum in base_arithmetic.go
+// for passing across which operation to perform. This allows simpler
+// implementation at the cost of having to pass the extra int8 and
+// perform a switch.
+//
+// In cases of small arrays, this is completely negligible. In cases
+// of large arrays, the time saved by using SIMD here is significantly
+// worth the cost.
+enum class optype : int8_t {
+    ADD,
+    SUB, 
+
+    // this impl doesn't actually perform any overflow checks as we need
+    // to only run overflow checks on non-null entries
+    ADD_CHECKED,
+    SUB_CHECKED, 
+};
+
+struct Add {
+    template <typename T, typename Arg0, typename Arg1>
+    static constexpr T Call(Arg0 left, Arg1 right) {
+        if constexpr (is_arithmetic_v<T>)
+            return left + right;
+    }    
+};
+
+struct Sub {
+    template <typename T, typename Arg0, typename Arg1>
+    static constexpr T Call(Arg0 left, Arg1 right) {
+        if constexpr (is_arithmetic_v<T>)
+            return left - right;
+    }
+};
+
+struct AddChecked {
+    template <typename T, typename Arg0, typename Arg1>
+    static constexpr T Call(Arg0 left, Arg1 right) {
+        static_assert(is_same<T, Arg0>::value && is_same<T, Arg1>::value, "");
+        if constexpr(is_arithmetic_v<T>) {
+            return left + right;
+        }

Review Comment:
   (Sorry I missed it in last review)
   No overflow checking in `AddChecked`?
   And `is_arithmetic_v` looks not necessary as this function must be 
instantiated with arithmetic types.



##########
go/arrow/compute/internal/kernels/_lib/types.h:
##########
@@ -0,0 +1,368 @@
+// 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.
+
+// corresponds to datatype.go's arrow.Type
+enum class arrtype : int {
+    NULL,
+    BOOL,
+    UINT8,
+    INT8,
+    UINT16,
+    INT16,
+    UINT32,
+    INT32,
+    UINT64,
+    INT64,
+    FLOAT16,
+    FLOAT32,
+    FLOAT64
+};
+
+
+#define _LIBCPP_TEMPLATE_VIS
+#define _LIBCPP_CONSTEXPR constexpr
+#define _LIBCPP_INLINE_VISIBILITY
+#define _LIBCPP_STD_VER 17
+#define _LIBCPP_NODEBUG
+#define _LIBCPP_HAS_NO_CHAR8_T
+#define _NOEXCEPT noexcept
+#define _NOEXCEPT_(x) noexcept(x)
+
+// copied from libcxx/include/__type_traits/integral_constant.h

Review Comment:
   Thanks for the explanation. Sounds reasonable.



-- 
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-unsubscr...@arrow.apache.org

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

Reply via email to