aboutsummaryrefslogtreecommitdiff
path: root/src/absgn~.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/absgn~.c')
-rw-r--r--src/absgn~.c78
1 files changed, 41 insertions, 37 deletions
diff --git a/src/absgn~.c b/src/absgn~.c
index a134aa5..65bff49 100644
--- a/src/absgn~.c
+++ b/src/absgn~.c
@@ -1,4 +1,4 @@
-/*
+/*
* absgn~: combined absolute value and sign of a signal
*
* (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem)
@@ -7,20 +7,19 @@
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program 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 General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "zexySIMD.h"
-typedef struct _absgn
-{
+typedef struct _absgn {
t_object x_obj;
t_float x_f;
} t_absgn;
@@ -36,38 +35,41 @@ static t_int *sigABSGN_perform(t_int *w)
t_sample *out = (t_sample *)(w[2]);
t_sample *out2 = (t_sample *)(w[3]);
int n = (int)(w[4]);
-
- while (n--)
- {
- t_sample val = *in++;
- *out++ = fabsf(val);
-
- if (val>0.) *out2++=1.;
- else if (val<0.) *out2++=-1.;
- else *out2++=0.;
+
+ while (n--) {
+ t_sample val = *in++;
+ *out++ = fabsf(val);
+
+ if (val>0.) {
+ *out2++=1.;
+ } else if (val<0.) {
+ *out2++=-1.;
+ } else {
+ *out2++=0.;
}
+ }
+
-
return (w+5);
}
#ifdef __SSE__
-static int l_bitmask[] ={0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
-static int l_sgnbitmask[]={0x80000000, 0x80000000, 0x80000000, 0x80000000};
+static int l_bitmask[] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
+static int l_sgnbitmask[]= {0x80000000, 0x80000000, 0x80000000, 0x80000000};
static t_int *sigABSGN_performSSE(t_int *w)
{
__m128 *in = (__m128 *)(w[1]);
__m128 *out1 = (__m128 *)(w[2]);
__m128 *out2 = (__m128 *)(w[3]);
int n = (int)(w[4])>>3;
-
+
const __m128 bitmask= _mm_loadu_ps((float*)l_bitmask);
const __m128 sgnmask= _mm_loadu_ps((float*)l_sgnbitmask);
const __m128 zero = _mm_setzero_ps();
const __m128 one = _mm_set1_ps(1.f);
-
+
do {
- __m128 val, val2, xmm0, xmm1, xmm2, xmm3;
+ __m128 val, val2, xmm0, xmm1, xmm2, xmm3;
val=in[0];
xmm0 = _mm_cmpneq_ps(val, zero); /* mask for non-zeros */
xmm1 = _mm_and_ps (val, sgnmask);/* sign (without value) */
@@ -85,8 +87,7 @@ static t_int *sigABSGN_performSSE(t_int *w)
in +=2;
out1+=2;
out2+=2;
- }
- while (--n);
+ } while (--n);
return (w+5);
}
@@ -96,20 +97,22 @@ static void sigABSGN_dsp(t_absgn* UNUSED(x), t_signal **sp)
{
#ifdef __SSE__
if(
- ZEXY_TYPE_EQUAL(t_sample, float) && /* currently SSE2 code is only for float (not for double) */
- Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) &&
- Z_SIMD_CHKALIGN(sp[0]->s_vec) &&
- Z_SIMD_CHKALIGN(sp[1]->s_vec) &&
- Z_SIMD_CHKALIGN(sp[2]->s_vec) &&
- zexy_testSSE(sigABSGN_perform, sigABSGN_performSSE, 1, 2)
- )
- {
- dsp_add(sigABSGN_performSSE, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
- } else
+ ZEXY_TYPE_EQUAL(t_sample, float)
+ && /* currently SSE2 code is only for float (not for double) */
+ Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) &&
+ Z_SIMD_CHKALIGN(sp[0]->s_vec) &&
+ Z_SIMD_CHKALIGN(sp[1]->s_vec) &&
+ Z_SIMD_CHKALIGN(sp[2]->s_vec) &&
+ zexy_testSSE(sigABSGN_perform, sigABSGN_performSSE, 1, 2)
+ ) {
+ dsp_add(sigABSGN_performSSE, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
+ sp[0]->s_n);
+ } else
#endif
- {
- dsp_add(sigABSGN_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n);
- }
+ {
+ dsp_add(sigABSGN_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec,
+ sp[0]->s_n);
+ }
}
static void sigABSGN_helper(void)
@@ -135,8 +138,9 @@ void absgn_tilde_setup(void)
sizeof(t_absgn), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(sigABSGN_class, t_absgn, x_f);
class_addmethod(sigABSGN_class, (t_method)sigABSGN_dsp, gensym("dsp"), 0);
-
- class_addmethod(sigABSGN_class, (t_method)sigABSGN_helper, gensym("help"), 0);
+
+ class_addmethod(sigABSGN_class, (t_method)sigABSGN_helper, gensym("help"),
+ 0);
class_sethelpsymbol(sigABSGN_class, gensym("zigbinops"));
zexy_register("absgn~");