From 557f80ae70127dc2cd9c054fd303d56d2b4c7bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Wed, 12 Apr 2017 15:43:08 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@340 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- main.cpp | 16 +++++++++++----- src/containers/pideque.h | 12 ++++++++++++ src/core/pibase.h | 17 +++++++++++++++++ src/math/pimathbase.h | 4 ++-- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 019f70e3..12de35b0 100644 --- a/main.cpp +++ b/main.cpp @@ -41,13 +41,19 @@ int asize(ssize_t s, size_t pid_rsize) { return (1 << t); } int main(int argc, char *argv[]) { - PIFFTWf fft; - PIVector in; + PIDeque in; + for (int i = 0; i < 5; ++i) + in << i%10; + /*PIFFTWd fft; + fft.preparePlan(50, PIFFTWd::foReal); + PIVector out = fft.calcFFT(in);*/ + piCout << in.data(); + in.align(); + piCout << in.data(); + in = PIDeque(); for (int i = 0; i < 50; ++i) in << i%10; - fft.preparePlan(50, PIFFTWf::foReal); - PIVector out = fft.calcFFT(in); - piCout << out; + piCout << in.data(); /*for (int i = 0; i < 16; ++i) { piCout << asize(i, 100); } diff --git a/src/containers/pideque.h b/src/containers/pideque.h index 79c96f2c..49a19246 100755 --- a/src/containers/pideque.h +++ b/src/containers/pideque.h @@ -217,6 +217,18 @@ public: pid_size = os; return *this; } + PIDeque & align() { + //printf("align %p\n", pid_data); + if (!pid_data) return *this; + T * p_d = (T*)(amalloc(pid_rsize*sizeof(T))); + //printf("alloc %p\n", p_d); + assert(p_d); + memcpy(p_d, pid_data, pid_size*sizeof(T)); + free((uchar*)pid_data); + pid_data = p_d; + //printf("%p\n", p_d); + return *this; + } PIDeque & insert(size_t index, const T & v = T()) { bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false); diff --git a/src/core/pibase.h b/src/core/pibase.h index 9e413a1f..54762930 100644 --- a/src/core/pibase.h +++ b/src/core/pibase.h @@ -93,10 +93,12 @@ #include #include +#include #ifdef WINDOWS # include # include # include +# include # ifdef CC_VC # define SHUT_RDWR 2 # pragma comment(lib, "Ws2_32.lib") @@ -112,6 +114,21 @@ inline int random() {return rand();} #endif +#ifndef PIP_MEMALIGN_BYTES +# define PIP_MEMALIGN_BYTES (sizeof(void*)*4) +#endif +#ifdef WINDOWS +# ifdef CC_GCC +# define amalloc(s) __mingw_aligned_malloc(s, PIP_MEMALIGN_BYTES) +# else +# ifdef CC_VC +# define amalloc(s) _aligned_malloc(s, PIP_MEMALIGN_BYTES) +# endif +# endif +#else +# define amalloc(s) aligned_alloc(PIP_MEMALIGN_BYTES, s) +#endif + #ifdef ANDROID # define tcdrain(fd) ioctl(fd, TCSBRK, 1) //inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;} diff --git a/src/math/pimathbase.h b/src/math/pimathbase.h index 6361baef..2dd91972 100644 --- a/src/math/pimathbase.h +++ b/src/math/pimathbase.h @@ -121,8 +121,8 @@ inline int sign(const float & x) {return (x < 0.) ? -1 : (x > 0. ? 1 : 0);} inline int sign(const double & x) {return (x < 0.) ? -1 : (x > 0. ? 1 : 0);} inline complexd sign(const complexd & x) {return complexd(sign(x.real()), sign(x.imag()));} inline int pow2(const int p) {return 1 << p;} -inline double sqr(const int v) {return v * v;} -inline double sqr(const float & v) {return v * v;} +inline int sqr(const int v) {return v * v;} +inline float sqr(const float & v) {return v * v;} inline double sqr(const double & v) {return v * v;} inline double sinc(const double & v) {if (v == 0.) return 1.; double t = M_PI * v; return sin(t) / t;} inline complexd round(const complexd & c) {return complexd(piRound(c.real()), piRound(c.imag()));}