Skip to content

Commit

Permalink
Updates from HISSTools_Library and corresponding enum class updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHarker committed Dec 2, 2021
1 parent 02ad9bc commit 5e0d44c
Show file tree
Hide file tree
Showing 25 changed files with 249 additions and 204 deletions.
1 change: 0 additions & 1 deletion FrameLib_Dependencies/Allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ using malloc_allocator = function_allocator<malloc, free>;

struct aligned_allocator
{

template <typename T>
T* allocate(size_t size) { return allocate_aligned<T>(size); }

Expand Down
24 changes: 12 additions & 12 deletions FrameLib_Dependencies/HISSTools_FFT/HISSTools_FFT_Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,30 @@ struct FloatSetup : public Setup<float> {};

namespace hisstools_fft_impl{

template<class T> struct SIMDLimits { static const int max_size = 1;};
template<class T> struct SIMDLimits { static constexpr int max_size = 1;};

#if defined(__AVX512F__)

template<> struct SIMDLimits<double> { static const int max_size = 8; };
template<> struct SIMDLimits<float> { static const int max_size = 16; };
template<> struct SIMDLimits<double> { static constexpr int max_size = 8; };
template<> struct SIMDLimits<float> { static constexpr int max_size = 16; };

#elif defined(__AVX__)

template<> struct SIMDLimits<double> { static const int max_size = 4; };
template<> struct SIMDLimits<float> { static const int max_size = 8; };
template<> struct SIMDLimits<double> { static constexpr int max_size = 4; };
template<> struct SIMDLimits<float> { static constexpr int max_size = 8; };

#elif defined(__SSE__)

template<> struct SIMDLimits<double> { static const int max_size = 2; };
template<> struct SIMDLimits<float> { static const int max_size = 4; };
template<> struct SIMDLimits<double> { static constexpr int max_size = 2; };
template<> struct SIMDLimits<float> { static constexpr int max_size = 4; };

#elif defined(__arm__) || defined(__arm64__)

template<> struct SIMDLimits<float> { static const int max_size = 4; };
template<> struct SIMDLimits<float> { static constexpr int max_size = 4; };

#endif

static const int alignment_size = SIMDLimits<float>::max_size * sizeof(float);
static constexpr int alignment_size = SIMDLimits<float>::max_size * sizeof(float);

// Aligned Allocation

Expand Down Expand Up @@ -115,7 +115,7 @@ namespace hisstools_fft_impl{

// Offset for Table

static const uintptr_t trig_table_offset = 3;
static constexpr uintptr_t trig_table_offset = 3;

// Data Type Definitions

Expand All @@ -124,7 +124,7 @@ namespace hisstools_fft_impl{
template <class T, class U, int vec_size>
struct SIMDVectorBase
{
static const int size = vec_size;
static constexpr int size = vec_size;

SIMDVectorBase() {}
SIMDVectorBase(U a) : mVal(a) {}
Expand Down Expand Up @@ -348,7 +348,7 @@ namespace hisstools_fft_impl{
struct Vector4x
{
typedef SIMDVector<T, vec_size> ArrayType;
static const int array_size = 4 / vec_size;
static constexpr int array_size = 4 / vec_size;

Vector4x() {}
Vector4x(const Vector4x *ptr) { *this = *ptr; }
Expand Down
2 changes: 1 addition & 1 deletion FrameLib_Dependencies/Interpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Enumeration of interpolation types

enum InterpType { kInterpNone, kInterpLinear, kInterpCubicHermite, kInterpCubicLagrange, kInterpCubicBSpline };
enum class InterpType { None, Linear, CubicHermite, CubicLagrange, CubicBSpline };

// Linear

Expand Down
33 changes: 16 additions & 17 deletions FrameLib_Dependencies/KernelSmoother.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ class kernel_smoother : private spectral_processor<T, Allocator>
using in_ptr = typename processor::in_ptr;

using Split = typename FFTTypes<T>::Split;
using EdgeMode = typename processor::EdgeMode;

template <bool B>
using enable_if_t = typename std::enable_if<B, int>::type;

enum Ends { kEndsZero, kEndsNonZero, kEndsSymZero, kEndsSymNonZero };
enum class Ends { Zero, NonZero, SymZero, SymNonZero };

public:

enum EdgeType { kZeroPad, kExtend, kWrap, kFold, kMirror };
enum class EdgeMode { ZeroPad, Extend, Wrap, Fold, Mirror };

template <typename U = Allocator, enable_if_t<std::is_default_constructible<U>::value> = 0>
kernel_smoother(uintptr_t max_fft_size = 1 << 18)
Expand All @@ -53,7 +52,7 @@ class kernel_smoother : private spectral_processor<T, Allocator>

uintptr_t max_fft_size() { return processor::max_fft_size(); }

void smooth(T *out, const T *in, const T *kernel, uintptr_t length, uintptr_t kernel_length, double width_lo, double width_hi, bool symmetric, EdgeType edges)
void smooth(T *out, const T *in, const T *kernel, uintptr_t length, uintptr_t kernel_length, double width_lo, double width_hi, bool symmetric, EdgeMode edges)
{
if (!length || !kernel_length)
return;
Expand All @@ -77,7 +76,7 @@ class kernel_smoother : private spectral_processor<T, Allocator>
uintptr_t max_per_filter = static_cast<uintptr_t>(width_mul ? (2.0 / width_mul) + 1.0 : length);
uintptr_t data_width = max_per_filter + (filter_full - 1);

op_sizes sizes(data_width, filter_full, EdgeMode::kEdgeLinear);
op_sizes sizes(data_width, filter_full, processor::EdgeMode::Linear);

if (auto_resize_fft && processor::max_fft_size() < sizes.fft())
set_max_fft_size(sizes.fft());
Expand All @@ -90,7 +89,7 @@ class kernel_smoother : private spectral_processor<T, Allocator>
T *filter = ptr + (fft_size << 1);
T *padded = filter + filter_full;

Ends ends = kEndsNonZero;
Ends ends = Ends::NonZero;

if (kernel_length)
{
Expand All @@ -100,34 +99,34 @@ class kernel_smoother : private spectral_processor<T, Allocator>
const T epsilon = std::numeric_limits<T>::epsilon();

if ((symmetric || test_value_1 < epsilon) && test_value_2 < epsilon)
ends = symmetric ? kEndsSymZero : kEndsZero;
ends = symmetric ? Ends::SymZero : Ends::Zero;
}

// Copy data

switch (edges)
{
case kZeroPad:
case EdgeMode::ZeroPad:
std::fill_n(padded, filter_size, 0.0);
std::copy_n(in, length, padded + filter_size);
std::fill_n(padded + filter_size + length, filter_size, 0.0);
break;

case kExtend:
case EdgeMode::Extend:
std::fill_n(padded, filter_size, in[0]);
std::copy_n(in, length, padded + filter_size);
std::fill_n(padded + filter_size + length, filter_size, in[length - 1]);
break;

case kWrap:
case EdgeMode::Wrap:
copy_edges<table_fetcher_wrap>(in, padded, length, filter_size);
break;

case kFold:
case EdgeMode::Fold:
copy_edges<table_fetcher_fold>(in, padded, length, filter_size);
break;

case kMirror:
case EdgeMode::Mirror:
copy_edges<table_fetcher_mirror>(in, padded, length, filter_size);
break;
}
Expand Down Expand Up @@ -263,12 +262,12 @@ class kernel_smoother : private spectral_processor<T, Allocator>
return filter[0] * width;
}

const double width_adjust = (ends == kEndsNonZero) ? -1.0 : (ends == kEndsSymZero ? 0.0 : 1.0);
const double width_adjust = (ends == Ends::NonZero) ? -1.0 : (ends == Ends::SymZero ? 0.0 : 1.0);
const double scale_width = std::max(1.0, width + width_adjust);
const double width_normalise = static_cast<double>(kernel_length - 1) / scale_width;

uintptr_t offset = ends == kEndsZero ? 1 : 0;
uintptr_t loop_size = ends == kEndsNonZero ? width - 1 : width;
uintptr_t offset = ends == Ends::Zero ? 1 : 0;
uintptr_t loop_size = ends == Ends::NonZero ? width - 1 : width;

T filter_sum(0);

Expand All @@ -278,7 +277,7 @@ class kernel_smoother : private spectral_processor<T, Allocator>
filter_sum += filter[j];
}

if (ends == kEndsNonZero)
if (ends == Ends::NonZero)
{
filter[width - 1] = kernel[kernel_length - 1];
filter_sum += filter[width - 1];
Expand Down Expand Up @@ -318,7 +317,7 @@ class kernel_smoother : private spectral_processor<T, Allocator>
void apply_filter_fft(T *out, const T *data, const T *filter, Split& io, Split& temp, uintptr_t width, uintptr_t n, T gain)
{
uintptr_t data_width = n + width - 1;
op_sizes sizes(data_width, width, EdgeMode::kEdgeLinear);
op_sizes sizes(data_width, width, processor::EdgeMode::Linear);
in_ptr data_in(data, data_width);
in_ptr filter_in(filter, width);

Expand Down
50 changes: 25 additions & 25 deletions FrameLib_Dependencies/SIMDSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
template<class T>
struct SIMDLimits
{
static const int max_size = 1;
static const int byte_width = sizeof(T);
static constexpr int max_size = 1;
static constexpr int byte_width = sizeof(T);
};

#if defined(__AVX512F__)
Expand All @@ -51,15 +51,15 @@ struct SIMDLimits
template<>
struct SIMDLimits<double>
{
static const int max_size = 8;
static const int byte_width = 64;
static constexpr int max_size = 8;
static constexpr int byte_width = 64;
};

template<>
struct SIMDLimits<float>
{
static const int max_size = 16;
static const int byte_width = 64;
static constexpr int max_size = 16;
static constexpr int byte_width = 64;
};

#elif defined(__AVX__)
Expand All @@ -68,15 +68,15 @@ struct SIMDLimits<float>
template<>
struct SIMDLimits<double>
{
static const int max_size = 4;
static const int byte_width = 32;
static constexpr int max_size = 4;
static constexpr int byte_width = 32;
};

template<>
struct SIMDLimits<float>
{
static const int max_size = 8;
static const int byte_width = 32;
static constexpr int max_size = 8;
static constexpr int byte_width = 32;
};

#elif defined(__SSE__) || defined(__arm__) || defined(__arm64)
Expand All @@ -86,16 +86,16 @@ struct SIMDLimits<float>
template<>
struct SIMDLimits<double>
{
static const int max_size = 2;
static const int byte_width = 16;
static constexpr int max_size = 2;
static constexpr int byte_width = 16;
};
#endif

template<>
struct SIMDLimits<float>
{
static const int max_size = 4;
static const int byte_width = 16;
static constexpr int max_size = 4;
static constexpr int byte_width = 16;
};

#else
Expand Down Expand Up @@ -155,7 +155,7 @@ void deallocate_aligned(T *ptr)
template <class T, class U, int vec_size>
struct SIMDVector
{
static const int size = vec_size;
static constexpr int size = vec_size;
typedef T scalar_type;

SIMDVector() {}
Expand All @@ -174,8 +174,8 @@ struct SizedVector
{
using SV = SizedVector;
using VecType = SIMDType<T, vec_size>;
static const int size = final_size;
static const int array_size = final_size / vec_size;
static constexpr int size = final_size;
static constexpr int array_size = final_size / vec_size;

SizedVector() {}
SizedVector(const T& a) { static_iterate<>().set(*this, a); }
Expand Down Expand Up @@ -295,7 +295,7 @@ struct SizedVector
template<>
struct SIMDType<double, 1>
{
static const int size = 1;
static constexpr int size = 1;
typedef double scalar_type;

SIMDType() {}
Expand Down Expand Up @@ -336,7 +336,7 @@ struct SIMDType<double, 1>
template<>
struct SIMDType<float, 1>
{
static const int size = 1;
static constexpr int size = 1;
typedef float scalar_type;

SIMDType() {}
Expand Down Expand Up @@ -381,7 +381,7 @@ struct SIMDType<float, 1>
template<>
struct SIMDType<float, 2>
{
static const int size = 1;
static constexpr int size = 1;
typedef float scalar_type;

SIMDType() {}
Expand Down Expand Up @@ -995,15 +995,15 @@ T select(const SIMDType<T, N>& a, const SIMDType<T, N>& b, const SIMDType<T, N>&

static inline SIMDType<double, 1> abs(const SIMDType<double, 1> a)
{
const static uint64_t bit_mask_64 = 0x7FFFFFFFFFFFFFFFU;
constexpr uint64_t bit_mask_64 = 0x7FFFFFFFFFFFFFFFU;

uint64_t temp = *(reinterpret_cast<const uint64_t *>(&a)) & bit_mask_64;
return *(reinterpret_cast<double *>(&temp));
}

static inline SIMDType<float, 1> abs(const SIMDType<float, 1> a)
{
const static uint32_t bit_mask_32 = 0x7FFFFFFFU;
constexpr uint32_t bit_mask_32 = 0x7FFFFFFFU;

uint32_t temp = *(reinterpret_cast<const uint32_t *>(&a)) & bit_mask_32;
return *(reinterpret_cast<float *>(&temp));
Expand All @@ -1012,7 +1012,7 @@ static inline SIMDType<float, 1> abs(const SIMDType<float, 1> a)
template <int N>
SIMDType<double, N> abs(const SIMDType<double, N> a)
{
const static uint64_t bit_mask_64 = 0x7FFFFFFFFFFFFFFFU;
constexpr uint64_t bit_mask_64 = 0x7FFFFFFFFFFFFFFFU;
const double bit_mask_64d = *(reinterpret_cast<const double *>(&bit_mask_64));

return a & SIMDType<double, N>(bit_mask_64d);
Expand All @@ -1021,8 +1021,8 @@ SIMDType<double, N> abs(const SIMDType<double, N> a)
template <int N>
SIMDType<float, N> abs(const SIMDType<float, N> a)
{
const static uint32_t bit_mask_32 = 0x7FFFFFFFU;
const float bit_mask_32f = *(reinterpret_cast<const double *>(&bit_mask_32));
constexpr uint32_t bit_mask_32 = 0x7FFFFFFFU;
const float bit_mask_32f = *(reinterpret_cast<const float *>(&bit_mask_32));

return a & SIMDType<float, N>(bit_mask_32f);
}
Expand Down
Loading

0 comments on commit 5e0d44c

Please sign in to comment.