forked from ethereum/aleth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VMSIMD.cpp
executable file
·729 lines (678 loc) · 24.9 KB
/
VMSIMD.cpp
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
/*
This file is part of cpp-ethereum.
cpp-ethereum 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 3 of the License, or
(at your option) any later version.
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libethereum/ExtVM.h>
#include "VMConfig.h"
#include "VM.h"
#if EIP_616
namespace dev
{
namespace eth
{
// conversion functions to overlay vectors on storage for u256 stack slots
// a dirty trick but it keeps the SIMD types from polluting the rest of the VM
// so at least assert there's room for the trick, and use wrappers for some safety
static_assert(sizeof(uint64_t[4]) <= sizeof(u256), "stack slot too narrow for SIMD");
using a64x4 = uint64_t[4];
using a32x8 = uint32_t[8];
using a16x16 = uint16_t[16];
using a8x32 = uint8_t [32];
inline a64x4 & v64x4 (u256 & _stackItem) { return (a64x4&) *(a64x4*) &_stackItem; }
inline a32x8 & v32x8 (u256 & _stackItem) { return (a32x8&) *(a32x8*) &_stackItem; }
inline a16x16 & v16x16(u256 & _stackItem) { return (a16x16&)*(a16x16*)&_stackItem; }
inline a8x32 & v8x32 (u256 & _stackItem) { return (a8x32&) *(a8x32*) &_stackItem; }
inline a64x4 const& v64x4 (u256 const& _stackItem) { return (a64x4&) *(a64x4*) &_stackItem; }
inline a32x8 const& v32x8 (u256 const& _stackItem) { return (a32x8&) *(a32x8*) &_stackItem; }
inline a16x16 const& v16x16(u256 const& _stackItem) { return (a16x16&)*(a16x16*)&_stackItem; }
inline a8x32 const& v8x32 (u256 const& _stackItem) { return (a8x32&) *(a8x32*) &_stackItem; }
enum { Bits8, Bits16, Bits32, Bits64 };
// tried using template template functions, gave up fighting the compiler after a day
#define EVALXOPS(OP, _type) EVALXOP(OP, int8_t, int16_t, int32_t, int64_t, _type)
#define EVALXOPU(OP, _type) EVALXOP(OP, uint8_t, uint16_t, uint32_t, uint64_t, _type)
#define EVALXOP(OP, T8, T16, T32, T64, _type) \
{ \
uint8_t const t = (_type) & 0xf; \
m_SPP[0] = 0; \
switch (t) \
{ \
case Bits8: \
for (int i = 0; i < 32; ++i) \
v8x32(m_SPP[0])[i] = (uint8_t) OP((T8) v8x32(m_SP[0])[i], (T8) v8x32(m_SP[1])[i]); \
break; \
case Bits16: \
for (int i = 0; i < 16; ++i) \
v16x16(m_SPP[0])[i] = (uint16_t)OP((T16)v16x16(m_SP[0])[i], (T16)v16x16(m_SP[1])[i]); \
break; \
case Bits32: \
for (int i = 0; i < 8; ++i) \
v32x8(m_SPP[0])[i] = (uint32_t)OP((T32)v32x8(m_SP[0])[i], (T32)v32x8(m_SP[1])[i]); \
break; \
case Bits64: \
for (int i = 0; i < 4; ++i) \
v64x4(m_SPP[0])[i] = (uint64_t)OP((T64)v64x4(m_SP[0])[i], (T64)v64x4(m_SP[1])[i]); \
break; \
default: throwBadInstruction(); \
} \
}
#define ADD( x1, x2) ((x1) + (x2))
#define MUL( x1, x2) ((x1) * (x2))
#define SUB( x1, x2) ((x1) - (x2))
#define DIV( x1, x2) ((x1) / (x2))
#define MOD( x1, x2) ((x1) % (x2))
#define LT( x1, x2) ((x1) < (x2))
#define GT( x1, x2) ((x1) > (x2))
#define EQ( x1, x2) ((x1) == (x2))
#define ZERO(x1, x2) ((x1) == 0)
#define AND( x1, x2) ((x1) & (x2))
#define OR( x1, x2) ((x1) | (x2))
#define XOR( x1, x2) ((x1) ^ (x2))
#define NOT( x1, x2) (~(x1))
#define SHR( x1, x2) ((x1) >> (x2))
#define SHL( x1, x2) ((x1) << (x2))
#define ROL( x1, x2) (((x1) << (x2))|((x1) >> (sizeof(x1) * 8 - (x2))))
#define ROR( x1, x2) (((x1) >> (x2))|((x1) << (sizeof(x1) * 8 - (x2))))
void VM::xadd (uint8_t _type) { EVALXOPU(ADD, _type); }
void VM::xmul (uint8_t _type) { EVALXOPU(MUL, _type); }
void VM::xsub (uint8_t _type) { EVALXOPU(SUB, _type); }
void VM::xdiv (uint8_t _type) { EVALXOPU(DIV, _type); }
void VM::xsdiv(uint8_t _type) { EVALXOPS(DIV, _type); }
void VM::xmod (uint8_t _type) { EVALXOPU(MOD, _type); }
void VM::xsmod(uint8_t _type) { EVALXOPS(MOD, _type); }
void VM::xlt (uint8_t _type) { EVALXOPU(LT, _type); }
void VM::xslt (uint8_t _type) { EVALXOPS(LT, _type); }
void VM::xgt (uint8_t _type) { EVALXOPU(GT, _type); }
void VM::xsgt (uint8_t _type) { EVALXOPS(GT, _type); }
void VM::xeq (uint8_t _type) { EVALXOPU(EQ, _type); }
void VM::xzero(uint8_t _type) { EVALXOPU(ZERO,_type); }
void VM::xand (uint8_t _type) { EVALXOPU(AND, _type); }
void VM::xoor (uint8_t _type) { EVALXOPU(OR, _type); }
void VM::xxor (uint8_t _type) { EVALXOPU(XOR, _type); }
void VM::xnot (uint8_t _type) { EVALXOPU(NOT, _type); }
void VM::xshr (uint8_t _type) { EVALXOPU(SHR, _type); }
void VM::xsar (uint8_t _type) { EVALXOPS(SHR, _type); }
void VM::xshl (uint8_t _type) { EVALXOPU(SHL, _type); }
void VM::xrol (uint8_t _type) { EVALXOPU(ROL, _type); }
void VM::xror (uint8_t _type) { EVALXOPU(ROR, _type); }
// SIMD type encodes log base 2 of lane width and count - one in each nibble
//
inline uint8_t pow2N(uint8_t _n)
{
static uint8_t exp[6] = { 1, 2, 4, 8, 16, 32 };
return exp[_n];
}
inline uint8_t laneCount(uint8_t _type)
{
return pow2N(_type & 0xf);
}
inline uint8_t laneWidth(uint8_t _type)
{
return pow2N(_type >> 4);
}
// in must be by reference because it is really just memory for a vector
u256 VM::vtow(uint8_t _type, const u256& _in)
{
u256 out;
uint8_t const count = laneCount(_type);
uint8_t const width = laneWidth(_type);
switch (width)
{
case Bits8:
for (int i = count - 1; 0 <= i; --i)
{
out << 8;
out |= v8x32(_in) [i];
}
break;
case Bits16:
for (int i = count - 1; 0 <= i; --i)
{
out << 16;
out |= v16x16(_in)[i];
}
break;
case Bits32:
for (int i = count - 1; 0 <= i; --i)
{
out << 32;
out |= v32x8(_in) [i];
}
break;
case Bits64:
for (int i = count - 1; 0 <= i; --i)
{
out << 64;
out |= v64x4(_in) [i];
}
break;
default:
throwBadInstruction();
}
return out;
}
// out must be by reference because it is really just memory for a vector
void VM::wtov(uint8_t _type, u256 _in, u256& o_out)
{
uint8_t const count = laneCount(_type);
uint8_t const width = laneWidth(_type);
switch (width)
{
case Bits8:
for (int i = count - 1; 0 <= i; --i)
{
v8x32(o_out) [i] = (uint8_t )(_in & 0xff);
_in >>= 8;
}
break;
case Bits16:
for (int i = count - 1; 0 <= i; --i)
{
v16x16(o_out)[i] = (uint16_t)(_in & 0xffff);
_in >>= 16;
}
break;
case Bits32:
for (int i = count - 1; 0 <= i; --i)
{
v32x8(o_out) [i] = (uint32_t)(_in & 0xffffff);
_in >>= 32;
}
break;
case Bits64:
for (int i = count - 1; 0 <= i; --i)
{
v64x4(o_out) [i] = (uint64_t)(_in & 0xffffffff);
_in >>= 64;
}
break;
default:
throwBadInstruction();
}
}
void VM::xmload (uint8_t _type)
{
// goes onto stack element by element, LSB first
uint8_t const* vecData = m_mem.data() + toInt15(m_SP[0]);
uint8_t const count = laneCount(_type);
uint8_t const width = laneWidth(_type);
switch (width)
{
case Bits8:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 0;
v |= vecData[--j];
v8x32(m_SPP[0])[i] = v;
}
break;
case Bits16:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 0;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v16x16(m_SPP[0])[i] = v;
}
break;
case Bits32:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 0;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v32x8(m_SPP[0])[i] = v;
}
break;
case Bits64:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 0;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v <<= 8;
v |= vecData[--j];
v64x4(m_SPP[0])[i] = v;
}
break;
default:
throwBadInstruction();
}
}
void VM::xmstore(uint8_t _type)
{
// n bytes of type t elements in stack vector
// goes onto memory by element, LSB first
uint8_t* vecData = m_mem.data() + toInt15(m_SP[0]);
uint8_t const count = laneCount(_type);
uint8_t const width = laneWidth(_type);
switch (width)
{
case Bits8:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 0;
v = v8x32(m_SPP[0])[i];
vecData[--j] = (uint8_t)v;
}
break;
case Bits16:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 2;
v = v16x16(m_SPP[0])[i];
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
}
break;
case Bits32:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 4;
v = v32x8(m_SPP[0])[i];
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
}
break;
case Bits64:
for (int j = count, i = count - 1; 0 <= i; --i)
{
int v = 0;
v = v64x4(m_SPP[0])[i];
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
v >>= 8;
vecData[--j] = (uint8_t)v;
}
break;
default:
throwBadInstruction();
}
}
void VM::xsload(uint8_t _type)
{
u256 w = m_ext->store(m_SP[0]);
wtov(_type, w, m_SPP[0]);
}
void VM::xsstore(uint8_t _type)
{
u256 w = vtow(_type, m_SP[1]);
m_ext->setStore(m_SP[0], w);
}
void VM::xvtowide(uint8_t _type)
{
m_SPP[0] = vtow(_type, m_SP[0]);
}
void VM::xwidetov(uint8_t _type)
{
wtov(_type, m_SP[0], m_SPP[0]);
}
void VM::xpush(uint8_t _type)
{
uint8_t const count = laneCount(_type);
uint8_t const width = laneWidth(_type);
// Construct a vector out of n bytes following XPUSH.
// This requires the code has been copied and extended by 32 zero
// bytes to handle "out of code" push data here.
// given the type of the vector
// mask and shift in the inline bytes
m_SPP[0] = 0;
switch (width)
{
case Bits8:
for (int i = 0; i < count ; ++i)
{
v8x32(m_SPP[0])[i] = m_code[++m_PC];
}
break;
case Bits16:
for (int i = 0; i < count; ++i)
{
uint16_t v = m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v16x16(m_SPP[0])[i] = v;
}
break;
case Bits32:
for (int i = 0; i < count; ++i)
{
uint32_t v = m_code[m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v32x8(m_SPP[0])[i] = v;
}
break;
case Bits64:
for (int i = 0; i < count; ++i)
{
uint64_t v = m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v = (v << 8) | m_code[++m_PC];
v64x4(m_SPP[0])[i] = v;
}
break;
default:
throwBadInstruction();
}
}
void VM::xget(uint8_t _srcType, uint8_t _idxType)
{
uint8_t const srcWidth = laneWidth(_srcType);
uint8_t const idxCount = laneCount(_idxType);
uint8_t const idxWidth = laneWidth(_idxType);
// given the type of the source and index
// for every element of the index get the indexed element from the source
switch (srcWidth)
{
case Bits8:
switch (idxWidth)
{
case Bits8:
for (int i = 0; i < idxCount; ++i)
v8x32 (m_SPP[1])[i] = v8x32(m_SP[0])[v8x32 (m_SP[1])[i] % idxCount];
break;
case Bits16:
for (int i = 0; i< idxCount; ++i)
v16x16(m_SPP[1])[i] = v8x32(m_SP[0])[v16x16(m_SP[1])[i] % idxCount];
break;
case Bits32:
for (int i = 0; i< idxCount; ++i)
v32x8 (m_SPP[1])[i] = v8x32(m_SP[0])[v32x8 (m_SP[1])[i] % idxCount];
break;
case Bits64:
for (int i = 0; i< idxCount; ++i)
v64x4 (m_SPP[1])[i] = v8x32(m_SP[0])[v64x4 (m_SP[1])[i] % idxCount];
break;
default:
throwBadInstruction();
}
case Bits16:
switch (idxWidth)
{
case Bits8:
for (int i = 0; i < idxCount; ++i)
v8x32 (m_SPP[0])[i] = v16x16(m_SP[1])[v8x32 (m_SP[0])[i] % idxCount];
break;
case Bits16:
for (int i = 0; i < idxCount; ++i)
v16x16(m_SPP[0])[i] = v16x16(m_SP[1])[v16x16(m_SP[0])[i] % idxCount];
break;
case Bits32:
for (int i = 0; i < idxCount; ++i)
v32x8 (m_SPP[0])[i] = v16x16(m_SP[1])[v32x8 (m_SP[0])[i] % idxCount];
break;
case Bits64:
for (int i = 0; i < idxCount; ++i)
v64x4 (m_SPP[0])[i] = v16x16(m_SP[1])[v64x4 (m_SP[0])[i] % idxCount];
break;
default:
throwBadInstruction();
}
case Bits32:
switch (idxWidth)
{
case Bits8:
for (int i = 0; i < idxCount; ++i)
v8x32 (m_SPP[0])[i] = v32x8(m_SP[1])[v8x32 (m_SP[0])[i] % idxCount];
break;
case Bits16:
for (int i = 0; i < idxCount; ++i)
v16x16(m_SPP[0])[i] = v32x8(m_SP[1])[v16x16(m_SP[0])[i] % idxCount];
break;
case Bits32:
for (int i = 0; i < idxCount; ++i)
v32x8 (m_SPP[0])[i] = v32x8(m_SP[1])[v32x8 (m_SP[0])[i] % idxCount];
break;
case Bits64:
for (int i = 0; i < idxCount; ++i)
v64x4 (m_SPP[0])[i] = v32x8(m_SP[1])[v64x4 (m_SP[0])[i] % idxCount];
break;
default:
throwBadInstruction();
}
case Bits64:
switch (idxWidth)
{
case Bits8:
for (int i = 0; i < idxCount; ++i)
v8x32 (m_SPP[0])[i] = v64x4(m_SP[1])[v8x32 (m_SP[0])[i] % idxCount];
break;
case Bits16:
for (int i = 0; i < idxCount; ++i)
v16x16(m_SPP[0])[i] = v64x4(m_SP[1])[v16x16(m_SP[0])[i] % idxCount];
break;
case Bits32:
for (int i = 0; i < idxCount; ++i)
v32x8 (m_SPP[0])[i] = v64x4(m_SP[1])[v32x8 (m_SP[0])[i] % idxCount];
break;
case Bits64:
for (int i = 0; i < idxCount; ++i)
v64x4 (m_SPP[0])[i] = v64x4(m_SP[1])[v64x4 (m_SP[0])[i] % idxCount];
break;
default:
throwBadInstruction();
}
default:
throwBadInstruction();
}
}
void VM::xput(uint8_t _srcType, uint8_t _dstType)
{
uint8_t const srcWidth = laneWidth(_srcType);
uint8_t const dstCount = laneCount(_dstType);
uint8_t const dstWidth = laneWidth(_dstType);
// given the type of the source, destination and index
// for every element of the index put the indexed replacement in the destination
switch (srcWidth)
{
case Bits8:
switch (dstWidth)
{
case Bits8:
for (int i = 0; i < dstCount; ++i)
v8x32 (m_SPP[0])[v8x32(m_SP[1])[i] % 32] = v8x32(m_SP[0])[i];
break;
case Bits16:
for (int i = 0; i < dstCount; ++i)
v16x16(m_SPP[0])[v8x32(m_SP[1])[i] % 16] = v8x32(m_SP[0])[i];
break;
case Bits32:
for (int i = 0; i < dstCount; ++i)
v32x8 (m_SPP[0])[v8x32(m_SP[1])[i] % 8] = v8x32(m_SP[0])[i];
break;
case Bits64:
for (int i = 0; i < dstCount; ++i)
v64x4 (m_SPP[0])[v8x32(m_SP[1])[i] % 4] = v8x32(m_SP[0])[i];
break;
default:
throwBadInstruction();
}
case Bits16:
switch (dstWidth)
{
case Bits8:
for (int i = 0; i < dstCount; ++i)
v8x32 (m_SPP[0])[v16x16(m_SP[1])[i] % 32] = v16x16(m_SP[0])[i];
break;
case Bits16:
for (int i = 0; i < dstCount; ++i)
v16x16(m_SPP[0])[v16x16(m_SP[1])[i] % 16] = v16x16(m_SP[0])[i];
break;
case Bits32:
for (int i = 0; i < dstCount; ++i)
v32x8(m_SPP[0])[v16x16(m_SP[1])[i] % 8] = v16x16(m_SP[0])[i];
break;
case Bits64:
for (int i = 0; i < dstCount; ++i)
v64x4(m_SPP[0])[v16x16(m_SP[1])[i] % 4] = v16x16(m_SP[0])[i];
break;
default:
throwBadInstruction();
}
case Bits32:
switch (dstWidth)
{
case Bits8:
for (int i = 0; i < dstCount; ++i)
v8x32 (m_SPP[0])[v32x8(m_SP[1])[i] % 32] = v32x8(m_SP[0])[i];
break;
case Bits16:
for (int i = 0; i < dstCount; ++i)
v16x16(m_SPP[0])[v32x8(m_SP[1])[i] % 16] = v32x8(m_SP[0])[i];
break;
case Bits32:
for (int i = 0; i < dstCount; ++i)
v32x8 (m_SPP[0])[v32x8(m_SP[1])[i] % 8] = v32x8(m_SP[0])[i];
break;
case Bits64:
for (int i = 0; i < dstCount; ++i)
v64x4 (m_SPP[0])[v32x8(m_SP[1])[i] % 4] = v32x8(m_SP[0])[i];
break;
default:
throwBadInstruction();
}
case Bits64:
switch (dstWidth)
{
case Bits8:
for (int i = 0; i < dstCount; ++i)
v8x32 (m_SPP[0])[v64x4(m_SP[1])[i] % 32] = v64x4(m_SP[0])[i];
break;
case Bits16:
for (int i = 0; i < dstCount; ++i)
v16x16(m_SPP[0])[v64x4(m_SP[1])[i] % 16] = v64x4(m_SP[0])[i];
break;
case Bits32:
for (int i = 0; i < dstCount; ++i)
v32x8 (m_SPP[0])[v64x4(m_SP[1])[i] % 8] = v64x4(m_SP[0])[i];
break;
case Bits64:
for (int i = 0; i < dstCount; ++i)
v64x4 (m_SPP[0])[v64x4(m_SP[1])[i] % 4] = v64x4(m_SP[0])[i];
break;
default:
throwBadInstruction();
}
default:
throwBadInstruction();
}
}
void VM::xswizzle(uint8_t _type)
{
uint8_t const count = laneCount(_type);
uint8_t const width = laneWidth(_type);
// given the type of the source and mask
// for every index in the mask copy out the indexed value in the source
switch (width)
{
case Bits8:
for (int i = 0; i < count; ++i)
v8x32 (m_SPP[0])[i] = v8x32(m_SP[1]) [v8x32 (m_SP[0])[i] % count];
break;
case Bits16:
for (int i = 0; i < count; ++i)
v16x16(m_SPP[0])[i] = v16x16(m_SP[1])[v16x16(m_SP[0])[i] % count];
break;
case Bits32:
for (int i = 0; i < count; ++i)
v32x8 (m_SPP[0])[i] = v32x8(m_SP[1]) [v32x8 (m_SP[0])[i] % count];
break;
case Bits64:
for (int i = 0; i < count; ++i)
v64x4 (m_SPP[0])[i] = v64x4(m_SP[1]) [v64x4 (m_SP[0])[i] % count];
break;
default:
throwBadInstruction();
}
}
void VM::xshuffle(uint8_t _type)
{
// n type t elements in source and mask vectors
uint8_t const count = laneCount(_type);
uint8_t const width = laneWidth(_type);
// given the type of the sources and mask
// for every index in the mask copy out the indexed value in one of the sources
switch (width)
{
case Bits8:
for (int i = 0; i < count; ++i)
{
int j = v8x32(m_SP[0]) [i];
v8x32 (m_SPP[0])[i] = j < count ? v8x32(m_SP[1]) [j] : v8x32 (m_SP[2])[(j - count) % count];
}
break;
case Bits16:
for (int i = 0; i < count; ++i)
{
int j = v16x16(m_SP[0])[i];
v16x16(m_SPP[0])[i] = j < count ? v16x16(m_SP[1])[j] : v16x16(m_SP[2])[(j - count) % count];
}
break;
case Bits32:
for (int i = 0; i < count; ++i)
{
int j = v32x8(m_SP[0]) [i];
v32x8 (m_SPP[0])[i] = j < count ? v32x8(m_SP[1]) [j] : v32x8 (m_SP[2])[(j - count) % count];
}
break;
case Bits64:
for (int i = 0; i < count; ++i)
{
int j = v64x4(m_SP[0]) [i];
v64x4 (m_SPP[0])[i] = j < count ? v64x4(m_SP[1]) [j] : v64x4 (m_SP[2])[(j - count) % count];
}
break;
default:
throwBadInstruction();
}
}
}}
#endif