MLX
 
Loading...
Searching...
No Matches
base_simd.h File Reference
#include <stdint.h>
#include <algorithm>
#include <cmath>
#include <complex>
#include <functional>

Go to the source code of this file.

Classes

struct  mlx::core::simd::Simd< T, 1 >
 

Namespaces

namespace  mlx
 
namespace  mlx::core
 
namespace  mlx::core::simd
 

Macros

#define DEFAULT_UNARY(name, op)
 
#define DEFAULT_BINARY(OP)
 
#define DEFAULT_COMPARISONS(OP)
 
#define DEFAULT_REDUCTION(name, type)
 

Functions

template<typename T, int N>
Simd< T, Nmlx::core::simd::load (const T *x)
 
template<typename T, int N>
void mlx::core::simd::store (T *dst, Simd< T, N > x)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::rint (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::rsqrt (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::recip (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::operator- (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::operator! (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::abs (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::acos (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::acosh (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::asin (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::asinh (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::atan (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::atanh (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::ceil (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::conj (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::cosh (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::expm1 (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::floor (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::log (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::log2 (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::log10 (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::log1p (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::sinh (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::sqrt (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::tan (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::tanh (Simd< T, 1 > in)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::operator~ (Simd< T, 1 > in)
 
template<typename T>
auto mlx::core::simd::real (Simd< T, 1 > in) -> Simd< decltype(std::real(in.value)), 1 >
 
template<typename T>
auto mlx::core::simd::imag (Simd< T, 1 > in) -> Simd< decltype(std::imag(in.value)), 1 >
 
template<typename T>
Simd< bool, 1 > mlx::core::simd::isnan (Simd< T, 1 > in)
 
template<typename T1, typename T2>
auto mlx::core::simd::operator+ (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value+b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator+ (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a+b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator+ (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value+b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator- (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value - b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator- (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a - b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator- (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value - b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator* (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value *b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator* (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a *b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator* (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value *b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator/ (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value/b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator/ (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a/b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator/ (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value/b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator<< (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value<< b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator<< (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a<< b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator<< (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value<< b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator>> (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value > > b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator>> (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a > > b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator>> (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value > > b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator| (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value|b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator| (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a|b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator| (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value|b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator^ (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value ^ b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator^ (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a ^ b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator^ (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value ^ b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator& (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value &b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator& (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a &b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator& (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value &b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator&& (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value &&b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator&& (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a &&b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator&& (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value &&b), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator|| (Simd< T1, 1 > a, Simd< T2, 1 > b) -> Simd< decltype(a.value||b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator|| (T1 a, Simd< T2, 1 > b) -> Simd< decltype(a||b.value), 1 >
 
template<typename T1, typename T2>
auto mlx::core::simd::operator|| (Simd< T1, 1 > a, T2 b) -> Simd< decltype(a.value||b), 1 >
 
template<typename T>
Simd< T, 1 > mlx::core::simd::remainder (Simd< T, 1 > a_, Simd< T, 1 > b_)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::maximum (Simd< T, 1 > a_, Simd< T, 1 > b_)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::minimum (Simd< T, 1 > a_, Simd< T, 1 > b_)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::pow (Simd< T, 1 > a, Simd< T, 1 > b)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::atan2 (Simd< T, 1 > a, Simd< T, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator> (Simd< T1, 1 > a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator> (T1 a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator> (Simd< T1, 1 > a, T2 b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator< (Simd< T1, 1 > a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator< (T1 a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator< (Simd< T1, 1 > a, T2 b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator>= (Simd< T1, 1 > a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator>= (T1 a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator>= (Simd< T1, 1 > a, T2 b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator<= (Simd< T1, 1 > a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator<= (T1 a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator<= (Simd< T1, 1 > a, T2 b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator== (Simd< T1, 1 > a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator== (T1 a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator== (Simd< T1, 1 > a, T2 b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator!= (Simd< T1, 1 > a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator!= (T1 a, Simd< T2, 1 > b)
 
template<typename T1, typename T2>
Simd< bool, 1 > mlx::core::simd::operator!= (Simd< T1, 1 > a, T2 b)
 
template<typename MaskT, typename T>
Simd< T, 1 > mlx::core::simd::select (Simd< MaskT, 1 > mask, Simd< T, 1 > x, Simd< T, 1 > y)
 
template<typename T>
Simd< T, 1 > mlx::core::simd::clamp (Simd< T, 1 > v, Simd< T, 1 > min, Simd< T, 1 > max)
 
template<typename T, typename U>
Simd< T, 1 > mlx::core::simd::fma (Simd< T, 1 > x, Simd< T, 1 > y, U z)
 
template<typename T>
mlx::core::simd::max (Simd< T, 1 > x)
 
template<typename T>
mlx::core::simd::min (Simd< T, 1 > x)
 
template<typename T>
mlx::core::simd::sum (Simd< T, 1 > x)
 
template<typename T>
mlx::core::simd::prod (Simd< T, 1 > x)
 
template<typename T>
bool mlx::core::simd::any (Simd< T, 1 > x)
 
template<typename T>
bool mlx::core::simd::all (Simd< T, 1 > x)
 

Variables

template<typename T>
static constexpr int mlx::core::simd::max_size = 1
 
template<typename, typename = void>
constexpr bool mlx::core::simd::is_complex = false
 
template<typename T>
constexpr bool mlx::core::simd::is_complex< T, std::void_t< decltype(std::declval< T >().real())> >
 

Macro Definition Documentation

◆ DEFAULT_BINARY

#define DEFAULT_BINARY ( OP)
Value:
template <typename T1, typename T2> \
auto operator OP(Simd<T1, 1> a, Simd<T2, 1> b) \
->Simd<decltype(a.value OP b.value), 1> { \
return a.value OP b.value; \
} \
template <typename T1, typename T2> \
auto operator OP(T1 a, Simd<T2, 1> b)->Simd<decltype(a OP b.value), 1> { \
return a OP b.value; \
} \
template <typename T1, typename T2> \
auto operator OP(Simd<T1, 1> a, T2 b)->Simd<decltype(a.value OP b), 1> { \
return a.value OP b; \
}

◆ DEFAULT_COMPARISONS

#define DEFAULT_COMPARISONS ( OP)
Value:
template <typename T1, typename T2> \
Simd<bool, 1> operator OP(Simd<T1, 1> a, Simd<T2, 1> b) { \
return a.value OP b.value; \
} \
template <typename T1, typename T2> \
Simd<bool, 1> operator OP(T1 a, Simd<T2, 1> b) { \
return a OP b.value; \
} \
template <typename T1, typename T2> \
Simd<bool, 1> operator OP(Simd<T1, 1> a, T2 b) { \
return a.value OP b; \
}

◆ DEFAULT_REDUCTION

#define DEFAULT_REDUCTION ( name,
type )
Value:
template <typename T> \
type name(Simd<T, 1> x) { \
return x.value; \
}

◆ DEFAULT_UNARY

#define DEFAULT_UNARY ( name,
op )
Value:
template <typename T> \
Simd<T, 1> name(Simd<T, 1> in) { \
return op(in.value); \
}