1
/******************************************************
3
* zexy - implementation file
5
* copyleft (c) IOhannes m zm�lnig
7
* 1999:forum::f�r::uml�ute:2004
9
* institute of electronic music and acoustics (iem)
11
******************************************************
13
* license: GNU General Public License v.2
15
******************************************************/
18
finally :: some of the missing binops for signals :: <~
20
1302:forum::f�r::uml�ute:2000
25
/* ------------------------ relational~ ----------------------------- */
28
/* ----------------------------- lt_tilde ----------------------------- */
29
static t_class *lt_tilde_class, *scalarlt_tilde_class;
31
typedef struct _lt_tilde
37
typedef struct _scalarlt_tilde
41
t_float x_g; /* inlet value */
44
static void *lt_tilde_new(t_symbol *s, int argc, t_atom *argv)
47
if (argc > 1) post("<~: extra arguments ignored");
50
t_scalarlt_tilde *x = (t_scalarlt_tilde *)pd_new(scalarlt_tilde_class);
51
floatinlet_new(&x->x_obj, &x->x_g);
52
x->x_g = atom_getfloatarg(0, argc, argv);
53
outlet_new(&x->x_obj, &s_signal);
59
t_lt_tilde *x = (t_lt_tilde *)pd_new(lt_tilde_class);
60
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
61
outlet_new(&x->x_obj, &s_signal);
67
static t_int *lt_tilde_perform(t_int *w)
69
t_sample *in1 = (t_sample *)(w[1]);
70
t_sample *in2 = (t_sample *)(w[2]);
71
t_sample *out = (t_sample *)(w[3]);
73
while (n--) *out++ = *in1++ < *in2++;
77
static t_int *lt_tilde_perf8(t_int *w)
79
t_sample *in1 = (t_sample *)(w[1]);
80
t_sample *in2 = (t_sample *)(w[2]);
81
t_sample *out = (t_sample *)(w[3]);
83
for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
85
t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
86
t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
88
t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
89
t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
91
out[0] = f0 < g0; out[1] = f1 < g1; out[2] = f2 < g2; out[3] = f3 < g3;
92
out[4] = f4 < g4; out[5] = f5 < g5; out[6] = f6 < g6; out[7] = f7 < g7;
97
static t_int *scalarlt_tilde_perform(t_int *w)
99
t_sample *in = (t_sample *)(w[1]);
100
t_sample f = *(t_float *)(w[2]);
101
t_sample *out = (t_sample *)(w[3]);
103
while (n--) *out++ = *in++ < f;
107
static t_int *scalarlt_tilde_perf8(t_int *w)
109
t_sample *in = (t_sample *)(w[1]);
110
t_sample g = *(t_float *)(w[2]);
111
t_sample *out = (t_sample *)(w[3]);
113
for (; n; n -= 8, in += 8, out += 8)
115
t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
116
t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
118
out[0] = f0 < g; out[1] = f1 < g; out[2] = f2 < g; out[3] = f3 < g;
119
out[4] = f4 < g; out[5] = f5 < g; out[6] = f6 < g; out[7] = f7 < g;
124
static t_int *lt_tilde_performSSE(t_int *w)
126
__m128 *in1 = (__m128 *)(w[1]);
127
__m128 *in2 = (__m128 *)(w[2]);
128
__m128 *out = (__m128 *)(w[3]);
129
int n = (int)(w[4])>>4;
130
const __m128 one = _mm_set1_ps(1.f);
134
xmm0 = _mm_cmplt_ps(in1[0], in2[0]);
135
out[0] = _mm_and_ps (xmm0 , one);
137
xmm1 = _mm_cmplt_ps(in1[1], in2[1]);
138
out[1] = _mm_and_ps (xmm1 , one);
140
xmm0 = _mm_cmplt_ps(in1[2], in2[2]);
141
out[2] = _mm_and_ps (xmm0 , one);
143
xmm1 = _mm_cmplt_ps(in1[3], in2[3]);
144
out[3] = _mm_and_ps (xmm1 , one);
153
static t_int *scalarlt_tilde_performSSE(t_int *w)
155
__m128 *in = (__m128 *)(w[1]);
156
__m128 *out = (__m128 *)(w[3]);
157
float f = *(t_float *)(w[2]);
158
__m128 scalar = _mm_set1_ps(f);
159
int n = (int)(w[4])>>4;
160
const __m128 one = _mm_set1_ps(1.f);
164
xmm0 = _mm_cmplt_ps (in[0], scalar);
165
out[0] = _mm_and_ps (xmm0, one);
167
xmm1 = _mm_cmplt_ps (in[1], scalar);
168
out[1] = _mm_and_ps (xmm1, one);
170
xmm0 = _mm_cmplt_ps (in[2], scalar);
171
out[2] = _mm_and_ps (xmm0, one);
173
xmm1 = _mm_cmplt_ps (in[3], scalar);
174
out[3] = _mm_and_ps (xmm1, one);
183
static void lt_tilde_dsp(t_lt_tilde *x, t_signal **sp)
185
t_sample*in1=sp[0]->s_vec;
186
t_sample*in2=sp[1]->s_vec;
187
t_sample*out=sp[2]->s_vec;
193
Z_SIMD_CHKBLOCKSIZE(n)&&
194
Z_SIMD_CHKALIGN(in1)&&
195
Z_SIMD_CHKALIGN(in2)&&
196
Z_SIMD_CHKALIGN(out)&&
197
ZEXY_TYPE_EQUAL(t_sample, float)
200
dsp_add(lt_tilde_performSSE, 4, in1, in2, out, n);
204
dsp_add(lt_tilde_perform, 4, in1, in2, out, n);
206
dsp_add(lt_tilde_perf8, 4, in1, in2, out, n);
209
static void scalarlt_tilde_dsp(t_scalarlt_tilde *x, t_signal **sp)
211
t_sample*in =sp[0]->s_vec;
212
t_sample*out=sp[1]->s_vec;
217
Z_SIMD_CHKBLOCKSIZE(n)&&
218
Z_SIMD_CHKALIGN(in)&&
219
Z_SIMD_CHKALIGN(out)&&
220
ZEXY_TYPE_EQUAL(t_sample, float)
223
dsp_add(scalarlt_tilde_performSSE, 4, in, &x->x_g, out, n);
227
dsp_add(scalarlt_tilde_perform, 4, in, &x->x_g, out, n);
229
dsp_add(scalarlt_tilde_perf8, 4, in, &x->x_g, out, n);
231
static void lt_tilde_help(t_object*x)
233
post("\n%c <~\t\t:: compare 2 signals", HEARTSYMBOL);
236
void setup_0x3c0x7e(void)
238
lt_tilde_class = class_new(gensym("<~"), (t_newmethod)lt_tilde_new, 0,
239
sizeof(t_lt_tilde), 0, A_GIMME, 0);
240
class_addmethod(lt_tilde_class, (t_method)lt_tilde_dsp, gensym("dsp"), 0);
241
CLASS_MAINSIGNALIN(lt_tilde_class, t_lt_tilde, x_f);
242
class_addmethod (lt_tilde_class, (t_method)lt_tilde_help, gensym("help"), A_NULL);
243
class_sethelpsymbol(lt_tilde_class, gensym("zigbinops"));
245
scalarlt_tilde_class = class_new(gensym("<~"), 0, 0,
246
sizeof(t_scalarlt_tilde), 0, 0);
247
CLASS_MAINSIGNALIN(scalarlt_tilde_class, t_scalarlt_tilde, x_f);
248
class_addmethod(scalarlt_tilde_class, (t_method)scalarlt_tilde_dsp, gensym("dsp"),
250
class_addmethod (scalarlt_tilde_class, (t_method)lt_tilde_help, gensym("help"), A_NULL);
251
class_sethelpsymbol(scalarlt_tilde_class, gensym("zigbinops"));