Enable wasm32 as a target architecture for the SIMD feature (#324)
* Add wasm32 as target_arch for simd
Signed-off-by: roee88 <roee88@gmail.com>
* Allow wasm32 as a target arch for SIMD
Signed-off-by: roee88 <roee88@gmail.com>
diff --git a/arrow/Cargo.toml b/arrow/Cargo.toml
index 7781584..39481a7 100644
--- a/arrow/Cargo.toml
+++ b/arrow/Cargo.toml
@@ -70,7 +70,6 @@
tempfile = "3"
[build-dependencies]
-cfg_aliases = "0.1"
[[bench]]
name = "aggregate_kernels"
diff --git a/arrow/build.rs b/arrow/build.rs
deleted file mode 100644
index 2e3a711..0000000
--- a/arrow/build.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-
-use cfg_aliases::cfg_aliases;
-
-fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- // Setup cfg aliases
- cfg_aliases! {
- simd: { all(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"), feature = "simd") },
- }
-}
diff --git a/arrow/src/buffer/ops.rs b/arrow/src/buffer/ops.rs
index fbcb951..9d88149 100644
--- a/arrow/src/buffer/ops.rs
+++ b/arrow/src/buffer/ops.rs
@@ -33,7 +33,7 @@
/// and the `scalar_op` gets applied to remaining bytes.
/// Contrary to the non-simd version `bitwise_bin_op_helper`, the offset and length is specified in bytes
/// and this version does not support operations starting at arbitrary bit offsets.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
pub fn bitwise_bin_op_simd_helper<F_SIMD, F_SCALAR>(
left: &Buffer,
left_offset: usize,
@@ -82,7 +82,7 @@
/// and the `scalar_op` gets applied to remaining bytes.
/// Contrary to the non-simd version `bitwise_unary_op_helper`, the offset and length is specified in bytes
/// and this version does not support operations starting at arbitrary bit offsets.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
pub fn bitwise_unary_op_simd_helper<F_SIMD, F_SCALAR>(
left: &Buffer,
left_offset: usize,
@@ -411,7 +411,7 @@
len_in_bits: usize,
) -> Buffer {
// SIMD implementation if available and byte-aligned
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
if offset_in_bits % 8 == 0 && len_in_bits % 8 == 0 {
return bitwise_unary_op_simd_helper(
&left,
diff --git a/arrow/src/compute/kernels/aggregate.rs b/arrow/src/compute/kernels/aggregate.rs
index a01b29e..2dd19c4 100644
--- a/arrow/src/compute/kernels/aggregate.rs
+++ b/arrow/src/compute/kernels/aggregate.rs
@@ -69,7 +69,7 @@
/// Returns the minimum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
-#[cfg(not(simd))]
+#[cfg(not(feature = "simd"))]
pub fn min<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T: ArrowNumericType,
@@ -80,7 +80,7 @@
/// Returns the maximum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
-#[cfg(not(simd))]
+#[cfg(not(feature = "simd"))]
pub fn max<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T: ArrowNumericType,
@@ -193,7 +193,7 @@
/// Returns the sum of values in the array.
///
/// Returns `None` if the array is empty or only contains null values.
-#[cfg(not(simd))]
+#[cfg(not(feature = "simd"))]
pub fn sum<T>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T: ArrowNumericType,
@@ -247,7 +247,7 @@
}
}
-#[cfg(simd)]
+#[cfg(feature = "simd")]
mod simd {
use super::is_nan;
use crate::array::{Array, PrimitiveArray};
@@ -592,7 +592,7 @@
/// Returns the sum of values in the array.
///
/// Returns `None` if the array is empty or only contains null values.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
pub fn sum<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T::Native: Add<Output = T::Native>,
@@ -602,7 +602,7 @@
simd::simd_aggregation::<T, SumAggregate<T>>(&array)
}
-#[cfg(simd)]
+#[cfg(feature = "simd")]
/// Returns the minimum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
pub fn min<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
@@ -614,7 +614,7 @@
simd::simd_aggregation::<T, MinAggregate<T>>(&array)
}
-#[cfg(simd)]
+#[cfg(feature = "simd")]
/// Returns the maximum value in the array, according to the natural order.
/// For floating point arrays any NaN values are considered to be greater than any other non-null value
pub fn max<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
diff --git a/arrow/src/compute/kernels/arithmetic.rs b/arrow/src/compute/kernels/arithmetic.rs
index d7aadf1..0c46d61 100644
--- a/arrow/src/compute/kernels/arithmetic.rs
+++ b/arrow/src/compute/kernels/arithmetic.rs
@@ -27,9 +27,9 @@
use num::{One, Zero};
use crate::buffer::Buffer;
-#[cfg(simd)]
+#[cfg(feature = "simd")]
use crate::buffer::MutableBuffer;
-#[cfg(not(simd))]
+#[cfg(not(feature = "simd"))]
use crate::compute::kernels::arity::unary;
use crate::compute::util::combine_option_bitmap;
use crate::datatypes;
@@ -37,13 +37,13 @@
use crate::error::{ArrowError, Result};
use crate::{array::*, util::bit_util};
use num::traits::Pow;
-#[cfg(simd)]
+#[cfg(feature = "simd")]
use std::borrow::BorrowMut;
-#[cfg(simd)]
+#[cfg(feature = "simd")]
use std::slice::{ChunksExact, ChunksExactMut};
/// SIMD vectorized version of `unary_math_op` above specialized for signed numerical values.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
fn simd_signed_unary_math_op<T, SIMD_OP, SCALAR_OP>(
array: &PrimitiveArray<T>,
simd_op: SIMD_OP,
@@ -91,7 +91,7 @@
Ok(PrimitiveArray::<T>::from(data))
}
-#[cfg(simd)]
+#[cfg(feature = "simd")]
fn simd_float_unary_math_op<T, SIMD_OP, SCALAR_OP>(
array: &PrimitiveArray<T>,
simd_op: SIMD_OP,
@@ -286,7 +286,7 @@
}
/// SIMD vectorized version of `math_op` above.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
fn simd_math_op<T, SIMD_OP, SCALAR_OP>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
@@ -351,7 +351,7 @@
/// SIMD vectorized implementation of `left / right`.
/// If any of the lanes marked as valid in `valid_mask` are `0` then an `ArrowError::DivideByZero`
/// is returned. The contents of no-valid lanes are undefined.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
#[inline]
fn simd_checked_divide<T: ArrowNumericType>(
valid_mask: Option<u64>,
@@ -384,7 +384,7 @@
/// Scalar implementation of `left / right` for the remainder elements after complete chunks have been processed using SIMD.
/// If any of the values marked as valid in `valid_mask` are `0` then an `ArrowError::DivideByZero` is returned.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
#[inline]
fn simd_checked_divide_remainder<T: ArrowNumericType>(
valid_mask: Option<u64>,
@@ -417,7 +417,7 @@
}
/// Scalar-divisor version of `simd_checked_divide_remainder`.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
#[inline]
fn simd_checked_divide_scalar_remainder<T: ArrowNumericType>(
array_chunks: ChunksExact<T::Native>,
@@ -448,7 +448,7 @@
///
/// The divide kernels need their own implementation as there is a need to handle situations
/// where a divide by `0` occurs. This is complicated by `NULL` slots and padding.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
fn simd_divide<T>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
@@ -565,7 +565,7 @@
}
/// SIMD vectorized version of `divide_scalar`.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
fn simd_divide_scalar<T>(
array: &PrimitiveArray<T>,
divisor: T::Native,
@@ -624,9 +624,9 @@
+ Div<Output = T::Native>
+ Zero,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_math_op(&left, &right, |a, b| a + b, |a, b| a + b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return math_op(left, right, |a, b| a + b);
}
@@ -644,9 +644,9 @@
+ Div<Output = T::Native>
+ Zero,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_math_op(&left, &right, |a, b| a - b, |a, b| a - b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return math_op(left, right, |a, b| a - b);
}
@@ -656,9 +656,9 @@
T: datatypes::ArrowSignedNumericType,
T::Native: Neg<Output = T::Native>,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_signed_unary_math_op(array, |x| -x, |x| -x);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return Ok(unary(array, |x| -x));
}
@@ -671,7 +671,7 @@
T: datatypes::ArrowFloatNumericType,
T::Native: Pow<T::Native, Output = T::Native>,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
{
let raise_vector = T::init(raise);
return simd_float_unary_math_op(
@@ -680,7 +680,7 @@
|x| x.pow(raise),
);
}
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return Ok(unary(array, |x| x.pow(raise)));
}
@@ -698,9 +698,9 @@
+ Div<Output = T::Native>
+ Zero,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_math_op(&left, &right, |a, b| a * b, |a, b| a * b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return math_op(left, right, |a, b| a * b);
}
@@ -720,9 +720,9 @@
+ Zero
+ One,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_divide(&left, &right);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return math_divide(&left, &right);
}
@@ -742,9 +742,9 @@
+ Zero
+ One,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_divide_scalar(&array, divisor);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return math_divide_scalar(&array, divisor);
}
diff --git a/arrow/src/compute/kernels/comparison.rs b/arrow/src/compute/kernels/comparison.rs
index a770ede..8e5da22 100644
--- a/arrow/src/compute/kernels/comparison.rs
+++ b/arrow/src/compute/kernels/comparison.rs
@@ -543,7 +543,7 @@
/// Helper function to perform boolean lambda function on values from two arrays using
/// SIMD.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
fn simd_compare_op<T, SIMD_OP, SCALAR_OP>(
left: &PrimitiveArray<T>,
right: &PrimitiveArray<T>,
@@ -633,7 +633,7 @@
/// Helper function to perform boolean lambda function on values from an array and a scalar value using
/// SIMD.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
fn simd_compare_op_scalar<T, SIMD_OP, SCALAR_OP>(
left: &PrimitiveArray<T>,
right: T::Native,
@@ -719,9 +719,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op(left, right, T::eq, |a, b| a == b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op!(left, right, |a, b| a == b);
}
@@ -730,9 +730,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op_scalar(left, right, T::eq, |a, b| a == b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op_scalar!(left, right, |a, b| a == b);
}
@@ -741,9 +741,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op(left, right, T::ne, |a, b| a != b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op!(left, right, |a, b| a != b);
}
@@ -752,9 +752,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op_scalar(left, right, T::ne, |a, b| a != b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op_scalar!(left, right, |a, b| a != b);
}
@@ -764,9 +764,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op(left, right, T::lt, |a, b| a < b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op!(left, right, |a, b| a < b);
}
@@ -776,9 +776,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op_scalar(left, right, T::lt, |a, b| a < b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op_scalar!(left, right, |a, b| a < b);
}
@@ -791,9 +791,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op(left, right, T::le, |a, b| a <= b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op!(left, right, |a, b| a <= b);
}
@@ -803,9 +803,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op_scalar(left, right, T::le, |a, b| a <= b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op_scalar!(left, right, |a, b| a <= b);
}
@@ -815,9 +815,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op(left, right, T::gt, |a, b| a > b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op!(left, right, |a, b| a > b);
}
@@ -827,9 +827,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op_scalar(left, right, T::gt, |a, b| a > b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op_scalar!(left, right, |a, b| a > b);
}
@@ -842,9 +842,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op(left, right, T::ge, |a, b| a >= b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op!(left, right, |a, b| a >= b);
}
@@ -854,9 +854,9 @@
where
T: ArrowNumericType,
{
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
return simd_compare_op_scalar(left, right, T::ge, |a, b| a >= b);
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
return compare_op_scalar!(left, right, |a, b| a >= b);
}
diff --git a/arrow/src/datatypes/numeric.rs b/arrow/src/datatypes/numeric.rs
index 0046398..61f8d88 100644
--- a/arrow/src/datatypes/numeric.rs
+++ b/arrow/src/datatypes/numeric.rs
@@ -25,7 +25,7 @@
/// A subtype of primitive type that represents numeric values.
///
/// SIMD operations are defined in this trait if available on the target system.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
pub trait ArrowNumericType: ArrowPrimitiveType
where
Self::Simd: Add<Output = Self::Simd>
@@ -109,12 +109,12 @@
fn unary_op<F: Fn(Self::Simd) -> Self::Simd>(a: Self::Simd, op: F) -> Self::Simd;
}
-#[cfg(not(simd))]
+#[cfg(not(feature = "simd"))]
pub trait ArrowNumericType: ArrowPrimitiveType {}
macro_rules! make_numeric_type {
($impl_ty:ty, $native_ty:ty, $simd_ty:ident, $simd_mask_ty:ident) => {
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
impl ArrowNumericType for $impl_ty {
type Simd = $simd_ty;
@@ -318,7 +318,7 @@
}
}
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
impl ArrowNumericType for $impl_ty {}
};
}
@@ -354,7 +354,7 @@
/// A subtype of primitive type that represents signed numeric values.
///
/// SIMD operations are defined in this trait if available on the target system.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
pub trait ArrowSignedNumericType: ArrowNumericType
where
Self::SignedSimd: Neg<Output = Self::SignedSimd>,
@@ -375,7 +375,7 @@
fn write_signed(simd_result: Self::SignedSimd, slice: &mut [Self::Native]);
}
-#[cfg(not(simd))]
+#[cfg(not(feature = "simd"))]
pub trait ArrowSignedNumericType: ArrowNumericType
where
Self::Native: std::ops::Neg<Output = Self::Native>,
@@ -384,7 +384,7 @@
macro_rules! make_signed_numeric_type {
($impl_ty:ty, $simd_ty:ident) => {
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
impl ArrowSignedNumericType for $impl_ty {
type SignedSimd = $simd_ty;
@@ -407,7 +407,7 @@
}
}
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
impl ArrowSignedNumericType for $impl_ty {}
};
}
@@ -419,17 +419,17 @@
make_signed_numeric_type!(Float32Type, f32x16);
make_signed_numeric_type!(Float64Type, f64x8);
-#[cfg(simd)]
+#[cfg(feature = "simd")]
pub trait ArrowFloatNumericType: ArrowNumericType {
fn pow(base: Self::Simd, raise: Self::Simd) -> Self::Simd;
}
-#[cfg(not(simd))]
+#[cfg(not(feature = "simd"))]
pub trait ArrowFloatNumericType: ArrowNumericType {}
macro_rules! make_float_numeric_type {
($impl_ty:ty, $simd_ty:ident) => {
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
impl ArrowFloatNumericType for $impl_ty {
#[inline]
fn pow(base: Self::Simd, raise: Self::Simd) -> Self::Simd {
@@ -437,7 +437,7 @@
}
}
- #[cfg(not(simd))]
+ #[cfg(not(feature = "simd"))]
impl ArrowFloatNumericType for $impl_ty {}
};
}
diff --git a/arrow/src/util/bit_util.rs b/arrow/src/util/bit_util.rs
index 9fa8813..4cfa816 100644
--- a/arrow/src/util/bit_util.rs
+++ b/arrow/src/util/bit_util.rs
@@ -114,7 +114,7 @@
/// Note that each slice should be 64 bytes and it is the callers responsibility to ensure
/// that this is the case. If passed slices larger than 64 bytes the operation will only
/// be performed on the first 64 bytes. Slices less than 64 bytes will panic.
-#[cfg(simd)]
+#[cfg(feature = "simd")]
pub unsafe fn bitwise_bin_op_simd<F>(left: &[u8], right: &[u8], result: &mut [u8], op: F)
where
F: Fn(u8x64, u8x64) -> u8x64,
@@ -297,7 +297,7 @@
}
#[test]
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
fn test_bitwise_and_simd() {
let buf1 = [0b00110011u8; 64];
let buf2 = [0b11110000u8; 64];
@@ -309,7 +309,7 @@
}
#[test]
- #[cfg(simd)]
+ #[cfg(feature = "simd")]
fn test_bitwise_or_simd() {
let buf1 = [0b00110011u8; 64];
let buf2 = [0b11110000u8; 64];