aboutsummaryrefslogtreecommitdiff
path: root/plugins/gpu_neon/psx_gpu/vector_ops.h
blob: c11955d050ebcba733d8e57c1eebeac4ca69e24d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
/*
 * Copyright (C) 2011 Gilead Kutnick "Exophase" <exophase@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * 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.
 */

#ifndef VECTOR_OPS
#define VECTOR_OPS

#define build_vector_type_pair(sign, size, count, count_x2)                    \
typedef struct                                                                 \
{                                                                              \
  sign##size e[count];                                                         \
} vec_##count##x##size##sign;                                                  \
                                                                               \
typedef struct                                                                 \
{                                                                              \
  union                                                                        \
  {                                                                            \
    sign##size e[count_x2];                                                    \
    struct                                                                     \
    {                                                                          \
      vec_##count##x##size##sign low;                                          \
      vec_##count##x##size##sign high;                                         \
    };                                                                         \
  };                                                                           \
} vec_##count_x2##x##size##sign                                                \

#define build_vector_types(sign)                                               \
  build_vector_type_pair(sign, 8, 8, 16);                                      \
  build_vector_type_pair(sign, 16, 4, 8);                                      \
  build_vector_type_pair(sign, 32, 2, 4);                                      \
  build_vector_type_pair(sign, 64, 1, 2)                                       \

build_vector_types(u);
build_vector_types(s);


#define foreach_element(iterations, operation)                                 \
{                                                                              \
  u32 _i;                                                                      \
  for(_i = 0; _i < iterations; _i++)                                           \
  {                                                                            \
    operation;                                                                 \
  }                                                                            \
}                                                                              \

#define load_64b(dest, source)                                                 \
 *((u64 *)(dest).e) = *((u64 *)(source))                                       \

#define load_128b(dest, source)                                                \
 *((u64 *)(dest).e) = *((u64 *)(source));                                      \
 *((u64 *)(dest).e + 1) = *(((u64 *)(source)) + 1)                             \

#define load_8x16b(dest, source)                                               \
  foreach_element(8, (dest).e[_i] = ((u16 *)(source))[_i])                     \

#define store_64b(source, dest)                                                \
 *((u64 *)(dest)) = *((u64 *)(source).e)                                       \

#define store_128b(source, dest)                                               \
 *((u64 *)(dest)) = *((u64 *)(source).e);                                      \
 *(((u64 *)(dest)) + 1) = *((u64 *)(source).e + 1)                             \

#define store_8x16b(source, dest)                                              \
  foreach_element(8, ((u16 *)dest)[_i] = (source).e[_i])                       \


#define split_8x16b(dest, source)                                              \
  foreach_element(8,                                                           \
  {                                                                            \
    (dest).e[_i * 2] = (source).e[_i];                                         \
    (dest).e[(_i * 2) + 1] = (source).e[_i] >> 8;                              \
  })                                                                           \

#define merge_16x8b(dest, source)                                              \
  foreach_element(8,                                                           \
    (dest).e[_i] = (source).e[_i * 2] | ((source).e[(_i * 2) + 1] << 8))       \

#define vector_cast(vec_to, source)                                            \
  (*((volatile vec_to *)(&(source))))                                          \

#define vector_cast_high(vec_to, source)                                       \
  (*((volatile vec_to *)((u8 *)source.e + (sizeof(source.e) / 2))))            \


#define dup_8x8b(dest, value)                                                  \
  foreach_element(8, (dest).e[_i] = value)                                     \

#define dup_16x8b(dest, value)                                                 \
  foreach_element(16, (dest).e[_i] = value)                                    \

#define dup_4x16b(dest, value)                                                 \
  foreach_element(4, (dest).e[_i] = value)                                     \

#define dup_8x16b(dest, value)                                                 \
  foreach_element(8, (dest).e[_i] = value)                                     \

#define dup_2x32b(dest, value)                                                 \
  foreach_element(2, (dest).e[_i] = value)                                     \

#define dup_4x32b(dest, value)                                                 \
  foreach_element(4, (dest).e[_i] = value)                                     \

#define shr_narrow_8x16b(dest, source, shift)                                  \
  foreach_element(8, (dest).e[_i] = (u16)(source).e[_i] >> (shift))            \

#define shr_narrow_2x64b(dest, source, shift)                                  \
  foreach_element(2, (dest).e[_i] = (source).e[_i] >> (shift))                 \

#define shr_8x8b(dest, source, shift)                                          \
  foreach_element(8, (dest).e[_i] = (u8)(source).e[_i] >> (shift))             \

#define shl_8x8b(dest, source, shift)                                          \
  foreach_element(8, (dest).e[_i] = (source).e[_i] << (shift))                 \

#define shr_8x16b(dest, source, shift)                                         \
  foreach_element(8, (dest).e[_i] = (u16)(source).e[_i] >> (shift))            \

#define shr_2x32b(dest, source, shift)                                         \
  foreach_element(2, (dest).e[_i] = (u32)(source).e[_i] >> (shift))            \

#define shr_4x16b(dest, source, shift)                                         \
  foreach_element(4, (dest).e[_i] = (source).e[_i] >> (shift))                 \

#define shl_4x16b(dest, source, shift)                                         \
  foreach_element(4, (dest).e[_i] = (u32)(source).e[_i] << (shift))            \

#define shr_4x32b(dest, source, shift)                                         \
  foreach_element(4, (dest).e[_i] = (u32)(source).e[_i] >> (shift))            \

#define shr_narrow_4x32b(dest, source, shift)                                  \
  foreach_element(4, (dest).e[_i] = (u32)(source).e[_i] >> (shift))            \

#define shl_8x16b(dest, source, shift)                                         \
  foreach_element(8, (dest).e[_i] = (source).e[_i] << (shift))                 \

#define shl_4x32b(dest, source, shift)                                         \
  foreach_element(4, (dest).e[_i] = (source).e[_i] << (shift))                 \

#define shl_2x32b(dest, source, shift)                                         \
  foreach_element(2, (dest).e[_i] = (source).e[_i] << (shift))                 \

#define shl_1x64b(dest, source, shift)                                         \
  ((dest).e[0] = (source).e[0] << (shift))                                     \

#define shl_2x64b(dest, source, shift)                                         \
  foreach_element(2, (dest).e[_i] = (source).e[_i] << (shift))                 \

#define shl_variable_2x64b(dest, source_a, source_b)                           \
  foreach_element(2,                                                           \
   (dest).e[_i] = (source_a).e[_i] << ((source_b).e[_i] & 0xFF))               \

#define shl_variable_8x16b(dest, source_a, source_b)                           \
  foreach_element(8,                                                           \
   (dest).e[_i] = (source_a).e[_i] << ((source_b).e[_i] & 0xFF))               \

#define shl_variable_4x16b(dest, source_a, source_b)                           \
  foreach_element(4,                                                           \
   (dest).e[_i] = (source_a).e[_i] << ((source_b).e[_i] & 0xFF))               \

#define shr_1x64b(dest, source, shift)                                         \
  ((dest).e[0] = (source).e[0] >> (shift))                                     \

#define shl_long_8x8b(dest, source, shift)                                     \
  foreach_element(8, (dest).e[_i] = (source).e[_i] << (shift))                 \

#define shl_long_4x16b(dest, source, shift)                                    \
  foreach_element(4, (dest).e[_i] = (source).e[_i] << (shift))                 \

#define shrq_narrow_signed_8x16b(dest, source, shift)                          \
  foreach_element(8,                                                           \
  {                                                                            \
    s32 result = ((s16)(source).e[_i]) >> shift;                               \
    if(result < 0)                                                             \
      result = 0;                                                              \
    if(result > 0xFF)                                                          \
      result = 0xFF;                                                           \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define shl_reg_4x32b(dest, source_a, source_b)                                \
  foreach_element(4,                                                           \
  {                                                                            \
    s8 shift  = (source_b).e[_i];                                              \
    if(shift < 0)                                                              \
      dest.e[_i] = (source_a).e[_i] >> (-shift);                               \
    else                                                                       \
      dest.e[_i] = (source_a).e[_i] << shift;                                  \
  })                                                                           \

#define shl_reg_2x32b(dest, source_a, source_b)                                \
  foreach_element(2,                                                           \
  {                                                                            \
    s8 shift  = (source_b).e[_i];                                              \
    if(shift < 0)                                                              \
      dest.e[_i] = (source_a).e[_i] >> (-shift);                               \
    else                                                                       \
      dest.e[_i] = (source_a).e[_i] << shift;                                  \
  })                                                                           \

#define shl_reg_2x64b(dest, source_a, source_b)                                \
  foreach_element(2,                                                           \
  {                                                                            \
    s8 shift  = (source_b).e[_i];                                              \
    if(shift < 0)                                                              \
      dest.e[_i] = (source_a).e[_i] >> (-shift);                               \
    else                                                                       \
      dest.e[_i] = (source_a).e[_i] << shift;                                  \
  })                                                                           \


#define sri_8x8b(dest, source, shift)                                          \
  foreach_element(8, (dest).e[_i] = ((dest).e[_i] & ~(0xFF >> (shift))) |      \
   ((u8)(source).e[_i] >> (shift)))                                            \

#define sli_8x8b(dest, source, shift)                                          \
  foreach_element(8, (dest).e[_i] = ((dest).e[_i] & ~(0xFF << (shift))) |      \
   ((source).e[_i] << (shift)))                                                \



#define mov_narrow_8x16b(dest, source)                                         \
  foreach_element(8, (dest).e[_i] = (source).e[_i])                            \

#define mov_narrow_4x32b(dest, source)                                         \
  foreach_element(4, (dest).e[_i] = (source).e[_i])                            \

#define mov_narrow_2x64b(dest, source)                                         \
  foreach_element(2, (dest).e[_i] = (source).e[_i])                            \

#define mov_wide_8x8b(dest, source)                                            \
  foreach_element(8, (dest).e[_i] = (source).e[_i])                            \

#define mov_wide_2x32b(dest, source)                                           \
  foreach_element(2, (dest).e[_i] = (source).e[_i])                            \

#define mvn_4x16b(dest, source)                                                \
  foreach_element(4, (dest).e[_i] = ~((source).e[_i]))                         \

#define add_4x16b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define add_4x32b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define add_2x32b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define add_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define add_16x8b(dest, source_a, source_b)                                    \
  foreach_element(16, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])      \

#define add_8x8b(dest, source_a, source_b)                                     \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define add_1x64b(dest, source_a, source_b)                                    \
  (dest).e[0] = (source_a).e[0] + (source_b).e[0]                              \

#define add_2x64b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define add_high_narrow_2x64b(dest, source_a, source_b)                        \
  foreach_element(2,                                                           \
   ((dest).e[_i] = (source_a).e[_i] + (source_b).e[_i]) >> 32)                 \

#define add_high_narrow_4x32b(dest, source_a, source_b)                        \
  foreach_element(4,                                                           \
   ((dest).e[_i] = ((source_a).e[_i] + (source_b).e[_i]) >> 16))               \

#define sub_4x16b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] - (source_b).e[_i])       \

#define sub_4x32b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] - (source_b).e[_i])       \

#define sub_2x32b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] = (source_a).e[_i] - (source_b).e[_i])       \

#define sub_wide_8x8b(dest, source_a, source_b)                                \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] - (source_b).e[_i])       \

#define add_wide_8x8b(dest, source_a, source_b)                                \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define add_wide_2x32b(dest, source_a, source_b)                               \
  foreach_element(2, (dest).e[_i] = (source_a).e[_i] + (source_b).e[_i])       \

#define addq_8x8b(dest, source_a, source_b)                                    \
  foreach_element(8,                                                           \
  {                                                                            \
    u32 result = (source_a).e[_i] + (source_b).e[_i];                          \
    if(result > 0xFF)                                                          \
      result = 0xFF;                                                           \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define subq_8x8b(dest, source_a, source_b)                                    \
  foreach_element(8,                                                           \
  {                                                                            \
    u32 result = (source_a).e[_i] - (source_b).e[_i];                          \
    if(result > 0xFF)                                                          \
      result = 0;                                                              \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define subs_long_8x8b(dest, source_a, source_b)                               \
  subs_8x8b(dest, source_a, source_b)                                          \

#define subs_16x8b(dest, source_a, source_b)                                   \
  foreach_element(16,                                                          \
  {                                                                            \
    u32 result = (source_a).e[_i] - (source_b).e[_i];                          \
    if(result > 0xFF)                                                          \
      result = 0;                                                              \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define subs_8x16b(dest, source_a, source_b)                                   \
  foreach_element(8,                                                           \
  {                                                                            \
    s32 result = (source_a).e[_i] - (source_b).e[_i];                          \
    if(result < 0)                                                             \
      result = 0;                                                              \
                                                                               \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define sub_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] - (source_b).e[_i])       \

#define sub_16x8b(dest, source_a, source_b)                                    \
  foreach_element(16, (dest).e[_i] = (source_a).e[_i] - (source_b).e[_i])      \

#define orn_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] | ~((source_b).e[_i]))    \

#define and_4x16b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] & (source_b).e[_i])       \

#define and_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] & (source_b).e[_i])       \

#define and_4x32b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] & (source_b).e[_i])       \

#define and_16x8b(dest, source_a, source_b)                                    \
  foreach_element(16, (dest).e[_i] = (source_a).e[_i] & (source_b).e[_i])      \

#define and_8x8b(dest, source_a, source_b)                                     \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] & (source_b).e[_i])       \

#define and_2x32b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] = (source_a).e[_i] & (source_b).e[_i])       \

#define bic_8x8b(dest, source_a, source_b)                                     \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] & ~((source_b).e[_i]))    \

#define bic_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] & ~((source_b).e[_i]))    \

#define bic_immediate_4x16b(dest, value)                                       \
  foreach_element(4, (dest).e[_i] = (dest).e[_i] & ~(value))                   \

#define bic_immediate_8x16b(dest, value)                                       \
  foreach_element(8, (dest).e[_i] = (dest).e[_i] & ~(value))                   \

#define or_8x16b(dest, source_a, source_b)                                     \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] | (source_b).e[_i])       \

#define or_immediate_8x16b(dest, source_a, value)                              \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] | (value))                \

#define eor_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] ^ (source_b).e[_i])       \

#define eor_4x32b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] ^ (source_b).e[_i])       \

#define eor_2x32b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] = (source_a).e[_i] ^ (source_b).e[_i])       \

#define zip_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] =                                            \
   (u8)(source_a).e[_i] | ((u8)(source_b).e[_i] << 8))                         \

#define zip_2x64b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] =                                            \
   (u64)(source_a).e[_i] | ((u64)(source_b).e[_i] << 32))                      \

#define unzip_8x8b(dest_a, dest_b, source)                                     \
  foreach_element(8,                                                           \
  {                                                                            \
    (dest_a).e[_i] = (source).e[_i];                                           \
    (dest_b).e[_i] = ((source).e[_i]) >> 8;                                    \
  })                                                                           \

#define unzip_16x8b(dest_a, dest_b, source_a, source_b)                        \
  foreach_element(8,                                                           \
  {                                                                            \
    (dest_a).e[_i] = (source_a).e[_i];                                         \
    (dest_b).e[_i] = (source_a).e[_i] >> 8;                                    \
  });                                                                          \
  foreach_element(8,                                                           \
  {                                                                            \
    (dest_a).e[_i + 8] = (source_b).e[_i];                                     \
    (dest_b).e[_i + 8] = (source_b).e[_i] >> 8;                                \
  })                                                                           \

#define tbl_16(dest, indexes, table)                                           \
  foreach_element(8,                                                           \
  {                                                                            \
    u32 index = indexes.e[_i];                                                 \
    if(index < 16)                                                             \
      (dest).e[_i] = table.e[index];                                           \
    else                                                                       \
      (dest).e[_i] = 0;                                                        \
  })                                                                           \

#define cmpeqz_8x16b(dest, source)                                             \
  foreach_element(8, (dest).e[_i] = ~(((source).e[_i] == 0) - 1))              \

#define cmpltz_8x16b(dest, source)                                             \
  foreach_element(8, (dest).e[_i] = ((s16)(source).e[_i] >> 15))               \

#define cmpltz_4x32b(dest, source)                                             \
  foreach_element(4, (dest).e[_i] = ((s32)(source).e[_i] >> 31))               \

#define cmpltz_2x32b(dest, source)                                             \
  foreach_element(2, (dest).e[_i] = ((s32)(source).e[_i] >> 31))               \

#define cmplte_4x16b(dest, source_a, source_b)                                 \
  foreach_element(4, (dest).e[_i] = ~((source_a.e[_i] <= source_b.e[_i]) - 1)) \

#define cmplt_4x16b(dest, source_a, source_b)                                  \
  foreach_element(4, (dest).e[_i] = ~((source_a.e[_i] < source_b.e[_i]) - 1))  \

#define cmpgt_4x16b(dest, source_a, source_b)                                  \
  foreach_element(4, (dest).e[_i] = ~((source_a.e[_i] > source_b.e[_i]) - 1))  \

#define tst_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8,                                                           \
   (dest).e[_i] = ~(((source_a.e[_i] & source_b.e[_i]) != 0) - 1))             \

#define andi_8x8b(dest, source_a, value)                                       \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] & value)                  \

#define average_8x16b(dest, source_a, source_b)                                \
  foreach_element(8,                                                           \
   (dest).e[_i] = ((source_a).e[_i] + (source_b).e[_i]) >> 1)                  \


#define mul_8x8b(dest, source_a, source_b)                                     \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] * (source_b).e[_i])       \

#define mul_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] * (source_b).e[_i])       \

#define mul_2x32b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] = (source_a).e[_i] * (source_b).e[_i])       \

#define mul_4x32b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] * (source_b).e[_i])       \

#define mul_long_8x8b(dest, source_a, source_b)                                \
  foreach_element(8, (dest).e[_i] = (source_a).e[_i] * (source_b).e[_i])       \

#define mul_long_4x16b(dest, source_a, source_b)                               \
  foreach_element(4, (dest).e[_i] = (source_a).e[_i] * (source_b).e[_i])       \

#define mul_long_2x32b(dest, source_a, source_b)                               \
  foreach_element(2,                                                           \
   (dest).e[_i] = (source_a).e[_i] * (s64)((source_b).e[_i]))                  \

#define mul_scalar_2x32b(dest, source, value)                                  \
  foreach_element(2, (dest).e[_i] = (source).e[_i] * value)                    \

#define mul_scalar_long_8x16b(dest, source, value)                             \
  foreach_element(8, (dest).e[_i] = (source).e[_i] * value)                    \

#define mul_scalar_long_2x32b(dest, source, value)                             \
  foreach_element(2, (dest).e[_i] = (source).e[_i] * value)                    \

#define mla_2x32b(dest, source_a, source_b)                                    \
  foreach_element(2, (dest).e[_i] += (source_a).e[_i] * (source_b).e[_i])      \

#define mla_4x32b(dest, source_a, source_b)                                    \
  foreach_element(4, (dest).e[_i] += (source_a).e[_i] * (source_b).e[_i])      \

#define mla_scalar_long_2x32b(dest, source, value)                             \
  foreach_element(2, (dest).e[_i] += (source).e[_i] * value)                   \

#define mla_long_8x8b(dest, source_a, source_b)                                \
  foreach_element(8, (dest).e[_i] += (source_a).e[_i] * (source_b).e[_i])      \

#define mla_long_2x32b(dest, source_a, source_b)                               \
  foreach_element(2, (dest).e[_i] += (source_a).e[_i] * (s64)(source_b).e[_i]) \

#define mla_scalar_4x32b(dest, source, value)                                  \
  foreach_element(4, (dest).e[_i] += (source).e[_i] * value)                   \

#define mla_scalar_2x32b(dest, source, value)                                  \
  foreach_element(2, (dest).e[_i] += (source).e[_i] * value)                   \

#define mls_scalar_4x32b(dest, source, value)                                  \
  foreach_element(4, (dest).e[_i] -= (source).e[_i] * value)                   \

#define mls_scalar_2x32b(dest, source, value)                                  \
  foreach_element(2, (dest).e[_i] -= (source).e[_i] * value)                   \

#define mls_scalar_long_2x32b(dest, source, value)                             \
  foreach_element(2, (dest).e[_i] -= (source).e[_i] * value)                   \

#define rev_2x32b(dest, source)                                                \
{                                                                              \
  u32 tmp = source.e[1];                                                       \
  (dest).e[1] = source.e[0];                                                   \
  (dest).e[0] = tmp;                                                           \
}                                                                              \

#define abs_4x32b(dest, source)                                                \
  foreach_element(4, (dest).e[_i] = abs(source.e[_i]))                         \

#define abs_2x32b(dest, source)                                                \
  foreach_element(2, (dest).e[_i] = abs(source.e[_i]))                         \

#define neg_2x32b(dest, source)                                                \
  foreach_element(2, (dest).e[_i] = -((source).e[_i]))                         \


#define shrq_narrow_8x16b(dest, source, shift)                                 \
  foreach_element(8,                                                           \
  {                                                                            \
    u32 result = ((source).e[_i]) >> shift;                                    \
    if(result > 0xFF)                                                          \
      result = 0xFF;                                                           \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define min_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8,                                                           \
  {                                                                            \
    s32 result = (source_a).e[_i];                                             \
    if((source_b).e[_i] < result)                                              \
      result = (source_b).e[_i];                                               \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define min_8x8b(dest, source_a, source_b)                                     \
  foreach_element(8,                                                           \
  {                                                                            \
    u32 result = (source_a).e[_i];                                             \
    if((source_b).e[_i] < result)                                              \
      result = (source_b).e[_i];                                               \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define min_16x8b(dest, source_a, source_b)                                    \
  foreach_element(16,                                                          \
  {                                                                            \
    u32 result = (source_a).e[_i];                                             \
    if((source_b).e[_i] < result)                                              \
      result = (source_b).e[_i];                                               \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define max_8x16b(dest, source_a, source_b)                                    \
  foreach_element(8,                                                           \
  {                                                                            \
    s32 result = (source_a).e[_i];                                             \
    if((source_b).e[_i] > result)                                              \
      result = (source_b).e[_i];                                               \
    (dest).e[_i] = result;                                                     \
  })                                                                           \

#define bsl_8x16b(dest_mask, source_a, source_b)                               \
  foreach_element(8, dest_mask.e[_i] = ((source_a).e[_i] & dest_mask.e[_i]) |  \
   ((source_b).e[_i] & ~(dest_mask.e[_i])))                                    \

#define bif_8x16b(dest, source, mask)                                          \
  foreach_element(8, dest.e[_i] = ((source).e[_i] & ~(mask.e[_i])) |           \
   ((dest).e[_i] & mask.e[_i]))                                                \

#define bsl_4x32b(dest_mask, source_a, source_b)                               \
  foreach_element(4, dest_mask.e[_i] = ((source_a).e[_i] & dest_mask.e[_i]) |  \
   ((source_b).e[_i] & ~(dest_mask.e[_i])))                                    \

#define bit_4x16b(dest, source, mask)                                          \
  foreach_element(4, dest.e[_i] = ((source).e[_i] & mask.e[_i]) |              \
   ((dest).e[_i] & ~(mask.e[_i])))                                             \

#endif