Rework to use Eigen

This commit is contained in:
Connor Olding 2015-12-10 07:25:23 -08:00
parent fbf8ea3858
commit 2db13e6fc2
12 changed files with 167 additions and 319 deletions

2
.gitignore vendored Executable file
View File

@ -0,0 +1,2 @@
Eigen
eigen-*.tar.gz

View File

@ -42,7 +42,7 @@ LADSPA_FLAGS =
VST_FLAGS = -Wno-write-strings -Wno-narrowing
VST_FLAGS += -I $(VST_SDK_DIR) -DBUILDING_DLL=1
OPT_FLAGS = -Ofast -march=core2 -mfpmath=sse
OPT_FLAGS = -Ofast -march=core2 -DNDEBUG
OBJCOPY ?= objcopy

View File

@ -24,6 +24,15 @@ crap Leveller | crap\_level | `0xAAAAAAAA` | an early prototype of a heavy level
## build notes
### dependencies
crap is now dependent on [the Eigen header library.][eigen]
for your convenience, a `get_eigen` bash script is provided.
this script simply downloads and extracts the Eigen header files
required to build crap.
[eigen]: http://eigen.tuxfamily.org/
### clang is strongly recommended
gcc can potentially produce significantly slower code,
@ -54,7 +63,6 @@ other targets:
* LV2 support
* automatically generate markdown table based on crap contents
* rename plugins (fix capitalization consistency and such)
* fix code style; particularily braces in method definitions and spaces in casts
* scrap overly-complex makefile for a shell script
* support for CPUs without SSE/NEON
* don't mix CamelCase with underscores (only done for legacy reasons)
* compressor plugin

View File

@ -12,14 +12,14 @@ set vstsrc=%vst2x%audioeffect.cpp %vst2x%audioeffectx.cpp %vst2x%vstplugmain.cpp
set wall=/Wall /wd4100 /wd4668 /wd4820 /wd4514 /wd4365 /wd4711 /wd4996 /wd4127
REM the warning disabled below is function-not-inlined
set common_c=/LD /I"../" /I"../include/" %wall% /wd4710
set release_c=%common_c% /O2 /Oy- /GL /EHsc /fp:fast /analyze- /nologo
set release_c=%common_c% /O2 /Oy- /GL /EHsc /fp:fast /analyze- /nologo /DNDEBUG
set release_ld=
call:compile delay_test
call:compile eq
call:compile eq_const
call:compile eq_const_T420
REM call:compile eq_const_T420_svf
call:compile eq_const_T420_svf
call:compile level
call:compile mugi4
call:compile noise

21
cacert.pem Executable file
View File

@ -0,0 +1,21 @@
DigiCert High Assurance EV Root CA
==================================
-----BEGIN CERTIFICATE-----
MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu
Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS
OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3
MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQ
NAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUe
h10aUAsgEsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMB
Af8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaAFLE+w2kD+L9HAdSY
JhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3NecnzyIZgYIVyHbIUf4KmeqvxgydkAQ
V8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFp
myPInngiK3BD41VHMWEZ71jFhS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkK
mNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K
-----END CERTIFICATE-----

18
get_eigen Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
a='eigen-eigen-b30b87236a1b'
gz="${a}.tar.gz"
url='https://bitbucket.org/eigen/eigen/get/3.2.7.tar.gz'
SRCDIR="$(readlink -f "$(dirname "$0")" )"
cd "$SRCDIR"
# specifically use -o instead of >
# because cygwin/msys will attempt to convert EOLs
# which is obviously invalid for a binary file
[ -s "$gz" ] || curl -LSs --cacert cacert.pem "$url" -o "$gz"
tar xzf "$gz"
[ -d Eigen ] && rm -r Eigen
mv "$a/Eigen" Eigen
rm -r "$a"

View File

@ -1,38 +0,0 @@
#ifndef _MSC_VER
// http://stackoverflow.com/a/18137117
struct Aligned {
static void*
operator new(size_t sz) {
const size_t extra = sizeof(void *);
void *mem = new char[sz + extra + 15];
void *aligned = (void *)(
((uintptr_t)(mem) + extra + 15) & ~15
);
void **ptr = (void **)(aligned);
ptr[-1] = mem;
return aligned;
}
static void
operator delete(void* aligned, size_t sz)
{
void **ptr = (void **) aligned;
char *mem = (char *)(ptr[-1]);
delete[] mem;
}
};
#else
#include <malloc.h>
struct Aligned {
static void*
operator new(size_t sz) {
return _aligned_malloc(sz, 16);
}
static void
operator delete(void* aligned, size_t sz)
{
_aligned_free(aligned);
}
};
#endif

View File

@ -1,5 +1,3 @@
#include "Aligned.hpp"
struct Crap : public Aligned {
virtual inline
~Crap() {}

View File

@ -1,91 +0,0 @@
// Presenting: Dumber, the dumb number
// this is just some C++ bloat-i-mean-boilerplate
// for inheritance in vector types.
TEMPLATE
struct DumberBase {
T v;
inline
DumberBase()
{}
inline
DumberBase(T v2)
{ v = v2; }
inline
DumberBase(const DumberBase &x)
{ v = x.v; }
friend inline DumberBase
operator-(const DumberBase &a)
{ return -a.v; }
friend inline DumberBase
operator+(const DumberBase &a, const DumberBase &b)
{ return a.v + b.v; }
friend inline DumberBase
operator-(const DumberBase &a, const DumberBase &b)
{ return a.v - b.v; }
friend inline DumberBase
operator*(const DumberBase &a, const DumberBase &b)
{ return a.v*b.v; }
friend inline DumberBase
operator/(const DumberBase &a, const DumberBase &b)
{ return a.v/b.v; }
inline DumberBase &
operator+=(const DumberBase &a)
{ v += a.v; return *this; }
inline DumberBase &
operator-=(const DumberBase &a)
{ v -= a.v; return *this; }
inline DumberBase &
operator*=(const DumberBase &a)
{ v *= a.v; return *this; }
inline DumberBase &
operator/=(const DumberBase &a)
{ v /= a.v; return *this; }
friend inline DumberBase
operator&(const DumberBase &a, const DumberBase &b)
{ return a.v & b.v; }
friend inline DumberBase
operator|(const DumberBase &a, const DumberBase &b)
{ return a.v | b.v; }
friend inline DumberBase
operator^(const DumberBase &a, const DumberBase &b)
{ return a.v ^ b.v; }
friend inline DumberBase
operator<(const DumberBase &a, const DumberBase &b)
{ return a.v < b.v; }
friend inline DumberBase
operator>(const DumberBase &a, const DumberBase &b)
{ return a.v > b.v; }
friend inline DumberBase
operator==(const DumberBase &a, const DumberBase &b)
{ return a.v == b.v; }
};
TEMPLATE
struct Dumber : public DumberBase<T> {
inline
Dumber()
{}
inline
Dumber(DumberBase<T> v2) : DumberBase<T>(v2)
{}
};

View File

@ -2,6 +2,12 @@
#include <math.h>
#include <stdint.h>
#include <Eigen/Core>
struct Aligned {
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
#ifndef M_PI
#define M_PI 3.14159265358979323846
#define M_SQRT2 1.41421356237309504880
@ -30,12 +36,7 @@ typedef unsigned long ulong; // __attribute((aligned(16)));
#define BLOCK_SIZE 256
#endif
#ifdef _MSC_VER
#include "vectors_simple.hpp"
#else
#include "Dumber.hpp"
#include "vectors.hpp"
#endif
#ifdef FORCE_SINGLE
#define v2df v2sf

View File

@ -1,90 +1,119 @@
// all of this is just so i can:
// v2df(0.5)
typedef Eigen::Vector2d _v2df;
typedef Eigen::Vector2f _v2sf;
typedef Eigen::Vector4f _v4sf;
typedef double _v2df __attribute__((vector_size(16), aligned(16)));
typedef float _v2sf __attribute__((vector_size(8), aligned(8)));
typedef float _v4sf __attribute__((vector_size(16), aligned(16)));
template<typename T, typename Base>
struct Vector : public Aligned {
T v;
template<>
struct Dumber<_v2df> : public DumberBase<_v2df> {
inline Dumber() {}
inline Dumber(DumberBase<_v2df> v2) : DumberBase<_v2df>(v2) {}
Vector()
{}
template<typename T1, typename T2>
inline
Dumber(T1 x, T2 y)
{ v = (_v2df){double(x), double(y)}; }
Vector(const Base &d)
{ v.setConstant(d); }
TEMPLATE inline
Dumber(T x)
{ v = (_v2df){double(x), double(x)}; }
Vector(const Base &d0, const Base &d1)
{ v[0] = d0; v[1] = d1; }
inline double &
Vector(const Base &d0, const Base &d1, const Base &d2, const Base &d3)
{ v[0] = d0; v[1] = d1; v[2] = d2; v[3] = d3; }
template<typename Derived>
Vector(const Eigen::ArrayBase<Derived> &v2)
//{ v = v2.cast<Base>(); } // FIXME
{ v = v2; }
template<typename Derived>
Vector(const Eigen::MatrixBase<Derived> &v2)
{ v = v2; }
friend inline Vector
operator-(const Vector &a)
{ return -a.v.array(); }
friend inline Vector
operator+(const Vector &a, const Vector &b)
{ return a.v.array() + b.v.array(); }
friend inline Vector
operator-(const Vector &a, const Vector &b)
{ return a.v.array() - b.v.array(); }
friend inline Vector
operator*(const Vector &a, const Vector &b)
{ return a.v.array() * b.v.array(); }
friend inline Vector
operator/(const Vector &a, const Vector &b)
{ return a.v.array() / b.v.array(); }
friend inline Vector
sqrt(const Vector &a)
{ return a.v.cwiseSqrt(); }
inline Vector &
operator+=(const Vector &a)
{ v.array() += a.v.array(); return *this; }
inline Vector &
operator-=(const Vector &a)
{ v.array() -= a.v.array(); return *this; }
inline Vector &
operator*=(const Vector &a)
{ v.array() *= a.v.array(); return *this; }
inline Vector &
operator/=(const Vector &a)
{ v.array() /= a.v.array(); return *this; }
/* unimplemented for now
friend inline Vector
operator&(const Vector &a, const Vector &b)
{}
friend inline Vector
operator|(const Vector &a, const Vector &b)
{}
friend inline Vector
operator^(const Vector &a, const Vector &b)
{}
friend inline Vector
andnot(const Vector &a, const Vector &b)
{}
*/
/*
friend inline Vector
operator<(const Vector &a, const Vector &b)
{ return a.v.array() < b.v.array(); }
friend inline Vector
operator>(const Vector &a, const Vector &b)
{ return a.v.array() > b.v.array(); }
friend inline Vector
operator==(const Vector &a, const Vector &b)
{ return a.v.array() == b.v.array(); }
*/
friend inline Vector
max(const Vector &a, const Vector &b)
{ return a.v.cwiseMax(b.v); }
inline Base &
operator[](int index) {
return ((double *)&v)[index];
return v[index];
}
inline const double &
inline const Base &
operator[](int index) const {
return ((double *)&v)[index];
return v[index];
}
};
template<>
struct Dumber<_v2sf> : public DumberBase<_v2sf> {
inline Dumber() {}
inline Dumber(DumberBase<_v2sf> v2) : DumberBase<_v2sf>(v2) {}
template<typename T1, typename T2>
inline
Dumber(T1 x, T2 y)
{ v = (_v2sf){float(x), float(y)}; }
TEMPLATE inline
Dumber(T x)
{ v = (_v2sf){float(x), float(x)}; }
inline float &
operator[](int index) {
return ((float *)&v)[index];
}
inline const float &
operator[](int index) const {
return ((float *)&v)[index];
}
};
template<>
struct Dumber<_v4sf> : public DumberBase<_v4sf> {
inline Dumber() {}
inline Dumber(DumberBase<_v4sf> v2) : DumberBase<_v4sf>(v2) {}
template<typename T1, typename T2, typename T3, typename T4>
inline
Dumber(T1 x, T2 y, T3 z, T4 w)
{ v = (_v4sf){float(x), float(y), float(z), float(w)}; }
template<typename T1, typename T2>
inline
Dumber(T1 x, T2 y)
{ v = (_v4sf){float(x), float(y), float(x), float(y)}; }
TEMPLATE inline
Dumber(T x)
{ v = (_v4sf){float(x), float(x), float(x), float(x)}; }
inline float &
operator[](int index) {
return ((float *)&v)[index];
}
inline const float &
operator[](int index) const {
return ((float *)&v)[index];
}
};
typedef Dumber<_v2df> v2df;
typedef Dumber<_v2sf> v2sf;
typedef Dumber<_v4sf> v4sf;
typedef Vector<_v2df,double> v2df;
typedef Vector<_v2sf,float> v2sf;
typedef Vector<_v4sf,float> v4sf;

View File

@ -1,100 +0,0 @@
// mostly via http://charm.cs.uiuc.edu/doxygen/charm/SSE-Double_8h-source.shtml
#include <emmintrin.h>
typedef __m128d _v2df;
typedef __m64 _v2sf;
typedef __m128 _v4sf;
struct v2df {
_v2df v;
v2df()
{}
v2df(double d)
{ v = _mm_set1_pd(d); }
v2df(double d0, double d1)
{ v = _mm_setr_pd(d0,d1); }
friend inline v2df
operator-(const v2df &a)
{ v2df c; c.v =_mm_sub_pd(_mm_setzero_pd(),a.v); return c; }
friend inline v2df
operator+(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_add_pd(a.v,b.v); return c; }
friend inline v2df
operator-(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_sub_pd(a.v,b.v); return c; }
friend inline v2df
operator*(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_mul_pd(a.v,b.v); return c; }
friend inline v2df
operator/(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_div_pd(a.v,b.v); return c; }
friend inline v2df
sqrt(const v2df &a)
{ v2df c; c.v = _mm_sqrt_pd(a.v); return c; }
inline v2df &
operator+=(const v2df &a)
{ v = _mm_add_pd(v,a.v); return *this; }
inline v2df &
operator-=(const v2df &a)
{ v = _mm_sub_pd(v,a.v); return *this; }
inline v2df &
operator*=(const v2df &a)
{ v = _mm_mul_pd(v,a.v); return *this; }
inline v2df &
operator/=(const v2df &a)
{ v = _mm_div_pd(v,a.v); return *this; }
friend inline v2df
operator&(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_and_pd(a.v,b.v); return c; }
friend inline v2df
operator|(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_or_pd(a.v,b.v); return c; }
friend inline v2df
operator^(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_xor_pd(a.v,b.v); return c; }
friend inline v2df
andnot(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_andnot_pd(a.v,b.v); return c; }
friend inline v2df
operator<(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_cmplt_pd(a.v,b.v); return c; }
friend inline v2df
operator>(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_cmpgt_pd(a.v,b.v); return c; }
friend inline v2df
operator==(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_cmpeq_pd(a.v,b.v); return c; }
friend inline v2df
max(const v2df &a, const v2df &b)
{ v2df c; c.v = _mm_max_pd(a.v,b.v); return c; }
inline double &
operator[](int index) {
return ((double *)&v)[index];
}
inline const double &
operator[](int index) const {
return ((double *)&v)[index];
}
};