~ubuntu-branches/ubuntu/natty/pd-zexy/natty

« back to all changes in this revision

Viewing changes to src/0x7c0x7c0x7e.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
 *
 
3
 * zexy - implementation file
 
4
 *
 
5
 * copyleft (c) IOhannes m zm�lnig
 
6
 *
 
7
 *   1999:forum::f�r::uml�ute:2004
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
/*
 
18
        finally :: some of the missing binops for signals :: ||~
 
19
 
 
20
        1302:forum::f�r::uml�ute:2000
 
21
*/
 
22
 
 
23
#include "zexySIMD.h"
 
24
 
 
25
/* ----------------------------- oror_tilde ----------------------------- */
 
26
static t_class *oror_tilde_class, *scalaroror_tilde_class;
 
27
 
 
28
typedef struct _oror_tilde
 
29
{
 
30
  t_object x_obj;
 
31
  t_float x_f;
 
32
} t_oror_tilde;
 
33
 
 
34
typedef struct _scalaroror_tilde
 
35
{
 
36
  t_object x_obj;
 
37
  t_float x_f;
 
38
  t_float x_g;              /* inlet value */
 
39
} t_scalaroror_tilde;
 
40
 
 
41
static void *oror_tilde_new(t_symbol *s, int argc, t_atom *argv)
 
42
{
 
43
  ZEXY_USEVAR(s);
 
44
  if (argc > 1) post("||~: extra arguments ignored");
 
45
  if (argc) 
 
46
    {
 
47
      t_scalaroror_tilde *x = (t_scalaroror_tilde *)pd_new(scalaroror_tilde_class);
 
48
      floatinlet_new(&x->x_obj, &x->x_g);
 
49
      x->x_g = atom_getfloatarg(0, argc, argv);
 
50
      outlet_new(&x->x_obj, &s_signal);
 
51
      x->x_f = 0;
 
52
      return (x);
 
53
    }
 
54
  else
 
55
    {
 
56
      t_oror_tilde *x = (t_oror_tilde *)pd_new(oror_tilde_class);
 
57
      inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
 
58
      outlet_new(&x->x_obj, &s_signal);
 
59
      x->x_f = 0;
 
60
      return (x);
 
61
    }
 
62
}
 
63
 
 
64
static t_int *oror_tilde_perform(t_int *w)
 
65
{
 
66
  t_float *in1 = (t_float *)(w[1]);
 
67
  t_float *in2 = (t_float *)(w[2]);
 
68
  t_float *out = (t_float *)(w[3]);
 
69
  int n = (int)(w[4]);
 
70
  while (n--) *out++ = (int)*in1++ || (int)*in2++; 
 
71
  return (w+5);
 
72
}
 
73
 
 
74
static t_int *oror_tilde_perf8(t_int *w)
 
75
{
 
76
  t_float *in1 = (t_float *)(w[1]);
 
77
  t_float *in2 = (t_float *)(w[2]);
 
78
  t_float *out = (t_float *)(w[3]);
 
79
  int n = (int)(w[4]);
 
80
  for (; n; n -= 8, in1 += 8, in2 += 8, out += 8)
 
81
    {
 
82
      int f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3];
 
83
      int f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7];
 
84
 
 
85
      int g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3];
 
86
      int g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7];
 
87
 
 
88
      out[0] = f0 || g0; out[1] = f1 || g1; out[2] = f2 || g2; out[3] = f3 || g3;
 
89
      out[4] = f4 || g4; out[5] = f5 || g5; out[6] = f6 || g6; out[7] = f7 || g7;
 
90
    }
 
91
  return (w+5);
 
92
}
 
93
 
 
94
static t_int *scalaroror_tilde_perform(t_int *w)
 
95
{
 
96
  t_float *in = (t_float *)(w[1]);
 
97
  int f = *(t_float *)(w[2]);
 
98
  t_float *out = (t_float *)(w[3]);
 
99
  int n = (int)(w[4]);
 
100
  while (n--) *out++ = (int)*in++ || f; 
 
101
  return (w+5);
 
102
}
 
103
 
 
104
static t_int *scalaroror_tilde_perf8(t_int *w)
 
105
{
 
106
  t_float *in = (t_float *)(w[1]);
 
107
  int g = *(t_float *)(w[2]);
 
108
  t_float *out = (t_float *)(w[3]);
 
109
  int n = (int)(w[4]);
 
110
  for (; n; n -= 8, in += 8, out += 8)
 
111
    {
 
112
      int f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3];
 
113
      int f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7];
 
114
 
 
115
      out[0] = f0 || g; out[1] = f1 || g; out[2] = f2 || g; out[3] = f3 || g;
 
116
      out[4] = f4 || g; out[5] = f5 || g; out[6] = f6 || g; out[7] = f7 || g;
 
117
    }
 
118
  return (w+5);
 
119
}
 
120
 
 
121
#ifdef __SSE__
 
122
static t_int *oror_tilde_performSSE(t_int *w)
 
123
{
 
124
  __m128 *in1 = (__m128 *)(w[1]);
 
125
  __m128 *in2 = (__m128 *)(w[2]);
 
126
  __m128 *out = (__m128 *)(w[3]);
 
127
  int n = (int)(w[4])>>4;
 
128
  const __m128 one    = _mm_set1_ps(1.f);
 
129
  const __m128 zero   = _mm_setzero_ps();
 
130
 
 
131
  while (n--) {
 
132
    __m128 xmm0, xmm1, xmm2;
 
133
    xmm0   = _mm_cmpneq_ps(in1[0], zero);
 
134
    xmm1   = _mm_cmpneq_ps(in2[0], zero);
 
135
    xmm2   = _mm_or_ps    (xmm0 , xmm1);
 
136
    out[0] = _mm_and_ps   (xmm2 , one);
 
137
 
 
138
    xmm0   = _mm_cmpneq_ps(in1[1], zero);
 
139
    xmm1   = _mm_cmpneq_ps(in2[1], zero);
 
140
    xmm2   = _mm_or_ps    (xmm0 , xmm1);
 
141
    out[1] = _mm_and_ps   (xmm2 , one);
 
142
 
 
143
    xmm0   = _mm_cmpneq_ps(in1[2], zero);
 
144
    xmm1   = _mm_cmpneq_ps(in2[2], zero);
 
145
    xmm2   = _mm_or_ps    (xmm0 , xmm1);
 
146
    out[2] = _mm_and_ps   (xmm2 , one);
 
147
 
 
148
    xmm0   = _mm_cmpneq_ps(in1[3], zero);
 
149
    xmm1   = _mm_cmpneq_ps(in2[3], zero);
 
150
    xmm2   = _mm_or_ps    (xmm0 , xmm1);
 
151
    out[3] = _mm_and_ps   (xmm2 , one);
 
152
 
 
153
    in1+=4;
 
154
    in2+=4;
 
155
    out+=4;
 
156
  }  
 
157
 
 
158
  return (w+5);
 
159
}
 
160
static t_int *scalaroror_tilde_performSSE(t_int *w)
 
161
{
 
162
  __m128 *in = (__m128 *)(w[1]);
 
163
  __m128 *out = (__m128 *)(w[3]);
 
164
  t_float f = *(t_float *)(w[2]);
 
165
  __m128 scalar = _mm_set1_ps(f);
 
166
  int n = (int)(w[4])>>4;
 
167
  const __m128 one    = _mm_set1_ps(1.f);
 
168
  const __m128 zero   = _mm_setzero_ps();
 
169
 
 
170
  scalar   = _mm_cmpneq_ps(scalar, zero);
 
171
  while (n--) {
 
172
    __m128 xmm0, xmm1;
 
173
    xmm0   = _mm_cmpneq_ps(in[0], zero);
 
174
    xmm1   = _mm_or_ps    (xmm0 , scalar);
 
175
    out[0] = _mm_and_ps   (xmm1 , one);
 
176
 
 
177
    xmm0   = _mm_cmpneq_ps(in[1], zero);
 
178
    xmm1   = _mm_or_ps    (xmm0 , scalar);
 
179
    out[1] = _mm_and_ps   (xmm1 , one);
 
180
 
 
181
    xmm0   = _mm_cmpneq_ps(in[2], zero);
 
182
    xmm1   = _mm_or_ps    (xmm0 , scalar);
 
183
    out[2] = _mm_and_ps   (xmm1 , one);
 
184
 
 
185
    xmm0   = _mm_cmpneq_ps(in[3], zero);
 
186
    xmm1   = _mm_or_ps    (xmm0 , scalar);
 
187
    out[3] = _mm_and_ps   (xmm1 , one);
 
188
 
 
189
 
 
190
    in +=4;
 
191
    out+=4;
 
192
  }
 
193
  return (w+5);
 
194
}
 
195
#endif /* __SSE__ */
 
196
 
 
197
static void oror_tilde_dsp(t_oror_tilde *x, t_signal **sp)
 
198
{
 
199
  t_sample*in1=sp[0]->s_vec;
 
200
  t_sample*in2=sp[1]->s_vec;
 
201
  t_sample*out=sp[2]->s_vec;
 
202
 
 
203
  int n=sp[0]->s_n;
 
204
 
 
205
  ZEXY_USEVAR(x);
 
206
 
 
207
#ifdef __SSE__
 
208
  if(
 
209
     0 && /* disabled for now since SSE2 code not compatible with [||] */
 
210
     Z_SIMD_CHKBLOCKSIZE(n)&&
 
211
     Z_SIMD_CHKALIGN(in1)&&
 
212
     Z_SIMD_CHKALIGN(in2)&&
 
213
     Z_SIMD_CHKALIGN(out)&&
 
214
     ZEXY_TYPE_EQUAL(t_sample, float)
 
215
     )
 
216
    {
 
217
      dsp_add(oror_tilde_performSSE, 4, in1, in2, out, n);
 
218
    } else
 
219
#endif
 
220
  if(n&7)
 
221
    dsp_add(oror_tilde_perform, 4, in1, in2, out, n);
 
222
  else  
 
223
    dsp_add(oror_tilde_perf8, 4, in1, in2, out, n);
 
224
}
 
225
 
 
226
static void scalaroror_tilde_dsp(t_scalaroror_tilde *x, t_signal **sp)
 
227
{
 
228
  t_sample*in =sp[0]->s_vec;
 
229
  t_sample*out=sp[1]->s_vec;
 
230
  int n       =sp[0]->s_n;
 
231
 
 
232
#ifdef __SSE__
 
233
  if(
 
234
     Z_SIMD_CHKBLOCKSIZE(n)&&
 
235
     Z_SIMD_CHKALIGN(in)&&
 
236
     Z_SIMD_CHKALIGN(out)&&
 
237
     ZEXY_TYPE_EQUAL(t_sample, float)
 
238
     )
 
239
    {
 
240
      dsp_add(scalaroror_tilde_performSSE, 4, in, &x->x_g, out, n);
 
241
    } else
 
242
#endif
 
243
  if (n&7)
 
244
    dsp_add(scalaroror_tilde_perform, 4, in, &x->x_g, out, n);
 
245
  else  
 
246
    dsp_add(scalaroror_tilde_perf8, 4, in, &x->x_g, out, n);
 
247
}
 
248
 
 
249
static void oror_tilde_help(t_object*x)
 
250
{
 
251
  post("\n%c &&~\t\t:: logical OR operation on 2 signals", HEARTSYMBOL);
 
252
}
 
253
 
 
254
void setup_0x7c0x7c0x7e(void)
 
255
{
 
256
  oror_tilde_class = class_new(gensym("||~"), (t_newmethod)oror_tilde_new, 0,
 
257
                          sizeof(t_oror_tilde), 0, A_GIMME, 0);
 
258
  class_addmethod(oror_tilde_class, (t_method)oror_tilde_dsp, gensym("dsp"), 0);
 
259
  CLASS_MAINSIGNALIN(oror_tilde_class, t_oror_tilde, x_f);
 
260
  class_addmethod  (oror_tilde_class, (t_method)oror_tilde_help, gensym("help"), A_NULL);
 
261
  class_sethelpsymbol(oror_tilde_class, gensym("zigbinops"));
 
262
 
 
263
  scalaroror_tilde_class = class_new(gensym("||~"), 0, 0,
 
264
                                sizeof(t_scalaroror_tilde), 0, 0);
 
265
  CLASS_MAINSIGNALIN(scalaroror_tilde_class, t_scalaroror_tilde, x_f);
 
266
  class_addmethod(scalaroror_tilde_class, (t_method)scalaroror_tilde_dsp, gensym("dsp"),
 
267
                  0);
 
268
  class_addmethod  (scalaroror_tilde_class, (t_method)oror_tilde_help, gensym("help"), A_NULL);
 
269
  class_sethelpsymbol(scalaroror_tilde_class, gensym("zigbinops"));
 
270
 
 
271
  zexy_register("||~");
 
272
}