From 4f42305e71e8b4c2294e9cb2becb0566f306d268 Mon Sep 17 00:00:00 2001 From: Chen Feng Date: Mon, 16 Mar 2015 10:53:47 +0800 Subject: [PATCH 1/3] Delete math_neon.h remove GPL code --- source/src/lib/third_party/math_neon.h | 75 -------------------------- 1 file changed, 75 deletions(-) delete mode 100644 source/src/lib/third_party/math_neon.h diff --git a/source/src/lib/third_party/math_neon.h b/source/src/lib/third_party/math_neon.h deleted file mode 100644 index cc5012c..0000000 --- a/source/src/lib/third_party/math_neon.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -Math-NEON: Neon Optimised Math Library based on cmath -Contact: lachlan.ts@gmail.com -Copyright (C) 2009 Lachlan Tychsen - Smith aka Adventus - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifndef __MATH_NEON_H__ -#define __MATH_NEON_H__ - -#if !defined(__i386__) && defined(__arm__) -//if defined neon ASM routines are used, otherwise all calls to *_neon -//functions are rerouted to their equivalent *_c function. -#define __MATH_NEON - -//Default Floating Point value ABI: 0=softfp, 1=hardfp. Only effects *_neon routines. -//You can access the hardfp versions directly via the *_hard suffix. -//You can access the softfp versions directly via the *_soft suffix. -#define __MATH_FPABI 1 - -#endif - -#ifdef GCC -#define ALIGN(A) __attribute__ ((aligned (A)) -#else -#define ALIGN(A) -#endif - -#ifndef _MATH_H -#define M_PI 3.14159265358979323846 /* pi */ -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#define M_PI_4 0.78539816339744830962 /* pi/4 */ -#define M_E 2.7182818284590452354 /* e */ -#define M_LOG2E 1.4426950408889634074 /* log_2 e */ -#define M_LOG10E 0.43429448190325182765 /* log_10 e */ -#define M_LN2 0.69314718055994530942 /* log_e 2 */ -#define M_LN10 2.30258509299404568402 /* log_e 10 */ -#define M_1_PI 0.31830988618379067154 /* 1/pi */ -#define M_2_PI 0.63661977236758134308 /* 2/pi */ -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ -#endif - -#if __MATH_FPABI == 1 -#define powf_neon powf_neon_hfp -#else -#define powf_neon powf_neon_sfp -#endif - - -/* -function: powf -return: x raised to the power of n, x ** n. -expression: r = x ** y -notes: computed using e ** (y * ln(x)) -*/ -float powf_c(float x, float n); -float powf_neon_sfp(float x, float n); -float powf_neon_hfp(float x, float n); - -#endif From 5e1e0ad9ac9e93d6e74d6cc0e6627ef0598d3c78 Mon Sep 17 00:00:00 2001 From: Chen Feng Date: Mon, 16 Mar 2015 10:54:07 +0800 Subject: [PATCH 2/3] Delete math_powf.cpp remove GPL code --- source/src/lib/third_party/math_powf.cpp | 178 ----------------------- 1 file changed, 178 deletions(-) delete mode 100644 source/src/lib/third_party/math_powf.cpp diff --git a/source/src/lib/third_party/math_powf.cpp b/source/src/lib/third_party/math_powf.cpp deleted file mode 100644 index cb88ba5..0000000 --- a/source/src/lib/third_party/math_powf.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* -Math-NEON: Neon Optimised Math Library based on cmath -Contact: lachlan.ts@gmail.com -Copyright (C) 2009 Lachlan Tychsen - Smith aka Adventus - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -/* -Based on x ^ n = exp(n * log(x)) - -Test func : powf(x, n) -Test Range: (1,1) < (x, n) < (10, 10) -Peak Error: ~0.0010% -RMS Error: ~0.0002% -*/ - -#include "math.h" -#include "math_neon.h" - -const float __powf_rng[2] = { - 1.442695041f, - 0.693147180f -}; - -const float __powf_lut[16] = { - -2.295614848256274, //p0 log - -2.470711633419806, //p4 - -5.686926051100417, //p2 - -0.165253547131978, //p6 - +5.175912446351073, //p1 - +0.844006986174912, //p5 - +4.584458825456749, //p3 - +0.014127821926000, //p7 - 0.9999999916728642, //p0 exp - 0.04165989275009526, //p4 - 0.5000006143673624, //p2 - 0.0014122663401803872, //p6 - 1.000000059694879, //p1 - 0.008336936973260111, //p5 - 0.16666570253074878, //p3 - 0.00019578093328483123 //p7 -}; - -float powf_c(float x, float n) -{ - float a, b, c, d, xx; - int m; - - union { - float f; - int i; - } r; - - //extract exponent - r.f = x; - m = (r.i >> 23); - m = m - 127; - r.i = r.i - (m << 23); - - //Taylor Polynomial (Estrins) - xx = r.f * r.f; - a = (__powf_lut[4] * r.f) + (__powf_lut[0]); - b = (__powf_lut[6] * r.f) + (__powf_lut[2]); - c = (__powf_lut[5] * r.f) + (__powf_lut[1]); - d = (__powf_lut[7] * r.f) + (__powf_lut[3]); - a = a + b * xx; - c = c + d * xx; - xx = xx * xx; - r.f = a + c * xx; - - //add exponent - r.f = r.f + ((float) m) * __powf_rng[1]; - - r.f = r.f * n; - - - //Range Reduction: - m = (int) (r.f * __powf_rng[0]); - r.f = r.f - ((float) m) * __powf_rng[1]; - - //Taylor Polynomial (Estrins) - a = (__powf_lut[12] * r.f) + (__powf_lut[8]); - b = (__powf_lut[14] * r.f) + (__powf_lut[10]); - c = (__powf_lut[13] * r.f) + (__powf_lut[9]); - d = (__powf_lut[15] * r.f) + (__powf_lut[11]); - xx = r.f * r.f; - a = a + b * xx; - c = c + d * xx; - xx = xx* xx; - r.f = a + c * xx; - - //multiply by 2 ^ m - m = m << 23; - r.i = r.i + m; - - return r.f; -} - -float powf_neon_hfp(float x, float n) -{ -#ifdef __MATH_NEON - asm volatile ( - - "vdup.f32 d16, d0[1] \n\t" //d16 = {y,y}; - "vdup.f32 d0, d0[0] \n\t" //d0 = {x,x}; - - //extract exponent - "vmov.i32 d2, #127 \n\t" //d2 = 127; - "vshr.u32 d6, d0, #23 \n\t" //d6 = d0 >> 23; - "vsub.i32 d6, d6, d2 \n\t" //d6 = d6 - d2; - "vshl.u32 d1, d6, #23 \n\t" //d1 = d6 << 23; - "vsub.i32 d0, d0, d1 \n\t" //d0 = d0 + d1; - - //polynomial: - "vmul.f32 d1, d0, d0 \n\t" //d1 = d0*d0 = {x^2, x^2} - "vld1.32 {d2, d3, d4, d5}, [%1]! \n\t" //q1 = {p0, p4, p2, p6}, q2 = {p1, p5, p3, p7} ; - "vmla.f32 q1, q2, d0[0] \n\t" //q1 = q1 + q2 * d0[0] - "vmla.f32 d2, d3, d1[0] \n\t" //d2 = d2 + d3 * d1[0] - "vmul.f32 d1, d1, d1 \n\t" //d1 = d1 * d1 = {x^4, x^4} - "vmla.f32 d2, d1, d2[1] \n\t" //d2 = d2 + d1 * d2[1] - - //add exponent - "vld1.32 d7, [%0] \n\t" //d7 = {invrange, range} - "vcvt.f32.s32 d6, d6 \n\t" //d6 = (float) d6 - "vmla.f32 d2, d6, d7[1] \n\t" //d2 = d2 + d6 * d7[1] - - "vdup.f32 d0, d2[0] \n\t" //d0 = d2[0] - "vmul.f32 d0, d0, d16 \n\t" //d0 = d0 * d16 - - //Range Reduction: - "vmul.f32 d6, d0, d7[0] \n\t" //d6 = d0 * d7[0] - "vcvt.u32.f32 d6, d6 \n\t" //d6 = (int) d6 - "vcvt.f32.u32 d1, d6 \n\t" //d1 = (float) d6 - "vmls.f32 d0, d1, d7[1] \n\t" //d0 = d0 - d1 * d7[1] - - //polynomial: - "vmul.f32 d1, d0, d0 \n\t" //d1 = d0*d0 = {x^2, x^2} - "vld1.32 {d2, d3, d4, d5}, [%1] \n\t" //q1 = {p0, p4, p2, p6}, q2 = {p1, p5, p3, p7} ; - "vmla.f32 q1, q2, d0[0] \n\t" //q1 = q1 + q2 * d0[0] - "vmla.f32 d2, d3, d1[0] \n\t" //d2 = d2 + d3 * d1[0] - "vmul.f32 d1, d1, d1 \n\t" //d1 = d1 * d1 = {x^4, x^4} - "vmla.f32 d2, d1, d2[1] \n\t" //d2 = d2 + d1 * d2[1] - - //multiply by 2 ^ m - "vshl.i32 d6, d6, #23 \n\t" //d6 = d6 << 23 - "vadd.i32 d0, d2, d6 \n\t" //d0 = d2 + d6 - - - :: "r"(__powf_rng), "r"(__powf_lut) - : "d0", "d1", "d2","d3", "d4", "d5", "d6", "d7" - ); -#endif -} - -float powf_neon_sfp(float x, float n) -{ -#ifdef __MATH_NEON - asm volatile ("vmov.f32 s0, r0 \n\t"); - asm volatile ("vmov.f32 s1, r1 \n\t"); - powf_neon_hfp(x, n); - asm volatile ("vmov.f32 r0, s0 \n\t"); -#else - return powf_c(x, n); -#endif -}; From ad9ec06b144b121bec6ee35ed276658fbf8691e6 Mon Sep 17 00:00:00 2001 From: Chen Feng Date: Mon, 16 Mar 2015 10:55:23 +0800 Subject: [PATCH 3/3] Update matrix_local_response.cpp remove GPL code --- source/src/lib/math/matrix_local_response.cpp | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/source/src/lib/math/matrix_local_response.cpp b/source/src/lib/math/matrix_local_response.cpp index 0c930c3..b097a08 100644 --- a/source/src/lib/math/matrix_local_response.cpp +++ b/source/src/lib/math/matrix_local_response.cpp @@ -26,9 +26,6 @@ #include #endif // USE_MKL_GEMM -#ifdef USE_NEON -#include -#endif #include "buffer.h" @@ -112,19 +109,6 @@ Buffer* matrix_local_response(Buffer* input, int windowSize, jpfloat_t k, jpfloa vsPow(elementCount, magnitudeData, repeatedBeta, outputData); free(repeatedBeta); vsMul(elementCount, inputData, outputData, outputData); -#elif defined(USE_NEON) - while (inputData < inputDataEnd) { - - const jpfloat_t inputValue = *inputData; - const jpfloat_t magnitudeValue = *magnitudeData; - - jpfloat_t outputValue = (powf_neon(magnitudeValue, -beta) * inputValue); - *outputData = outputValue; - - inputData += 1; - magnitudeData += 1; - outputData += 1; - } #else // USE_ACCELERATE_GEMM while (inputData < inputDataEnd) { @@ -148,4 +132,4 @@ Buffer* matrix_local_response(Buffer* input, int windowSize, jpfloat_t k, jpfloa #endif // DO_LOG_OPERATIONS return output; -} \ No newline at end of file +}